<?
session_start();
require_once "../init.php";
require_once "../authority.inc.php";
if($_GET['pay_code'])
{
	$pay_code = $_GET['pay_code'];
}
else
{
	$pay_code = $_POST['pay_code'];
}
$pay_name = $_POST['pay_name'];
$pay_order = $_POST['pay_order'];
$pay_selected = $_POST['pay_selected'];
$status = $_POST['status'];
$RClassID = $_POST['RClassID'];
$pay_desc = $_POST['pay_desc'];

if($_POST['cfg_value']){
	/* 取得配置信息 */
    $pay_config = array();
    if (isset($_POST['cfg_value']) && is_array($_POST['cfg_value']))
    {
        for ($i = 0; $i < count($_POST['cfg_value']); $i++)
        {
            $pay_config[] = array('name'  => trim($_POST['cfg_name'][$i]),
                                  'type'  => trim($_POST['cfg_type'][$i]),
                                  'value' => trim($_POST['cfg_value'][$i])
            );
        }
    }
    $pay_config = serialize($pay_config);
	/* 编辑 */
    $sql = "UPDATE payment_type " .
		   "SET pay_name = '$_POST[pay_name]'," .
		   "    pay_desc = '$_POST[pay_desc]'," .
		   "    pay_config = '$pay_config', " .
		   "    pay_order    =  '$pay_order', pay_selected='$pay_selected', status='$status' ".
		   "WHERE pay_code = '$_POST[pay_code]' LIMIT 1";
	$db->query($sql);
	$db->close();
	header("Location: payment_setting.php?pay_code=".$_POST[pay_code]);
}else{
	$sql="update payment_type set pay_name='$pay_name',
			pay_order='$pay_order',pay_selected='$pay_selected',status='$status'
			where pay_code='$pay_code' LIMIT 1";
	$db->query($sql);
	$db->close();
	header("Location: ./payment_list.php");
}


?>