 <?php
	if (! defined ( 'APP_PATH' ) || ! defined ( 'I_PATH' )) {
		exit ( 'Access Denied' );
	}
	
	class ld_payment extends controllerBase {
		function __construct() {
			parent::__construct ();
			$this->Get_c = 'ld_payment';
			$this->a = $this->sysParams ( 'a', 1 );
			
			//require (APP_PATH . "/config.php");
			$payments = syDB ( 'payment' )->findall ();
			$this->lists = $payments;
			//print_r($this->lists);die;
			//$this->lists = $iConfig ['payment']; //	print_r($iConfig);
		}
		
		function index() {
			
			$this->toptxt = '支付方式';
			$this->display ( "payment_list.html" );
		}
		
		function edit() {
			/*
			$type = $this->sysParams ( 'type', 1 );
			if ($this->sysParams ( 'run' ) == 1) {
				$configfile = 'config.php';
				$fp_tp = @fopen ( $configfile, "r" );
				$fp_txt = @fread ( $fp_tp, filesize ( $configfile ) );
				@fclose ( $fp_tp );
				foreach ( $this->lists as $pay ) {
					if ($pay ['type'] == $type) {
						foreach ( $pay as $k => $v ) {
							$value=$this->sysParams($k,1);
							if($k=='pay_fee' || $k=='alipay_pay_method')
							{
								$value=$this->sysParams($k);
							}
							$t= str_replace('(', '\(', $v);
							$t=str_replace("\\","\\\\", $t);
							$t=str_replace("/","\\/", $t);
							$fp_txt=preg_replace("/'".$k."' => '$t',/","'".$k."' => '".$value."',",$fp_txt);
						}
					}
				}
				$fpt_tpl = @fopen ( $configfile, "w" );
				@fwrite ( $fpt_tpl, $fp_txt );
				@fclose ( $fpt_tpl );
				message_a ( "支付方式修改成功", '?c=ld_payment' );
			}
			foreach ( $this->lists as $v ) {
				if ($v ['type'] == $type) {
					$this->d = $v;
					break;
				}
			}*/
			$pay_id = $this->sysParams ( 'pay_id', 1 );
			$payments = syDB ( 'payment' )->findall ("pay_id =".$pay_id);			
			$this->d = $payments[0];	
			if($this->sysParams('run')==1){
			$row= array();
			$row['pay_name'] = $_POST['pay_name'];
			$row['pay_desc'] = $_POST['pay_desc'];
			$row['pay_fee'] = $_POST['pay_fee'];
			$row['enabled'] = $_POST['enabled'];
		
			//支付宝
			if($_POST['pay_code']=='alipay'){
			$row['seller_email'] = $_POST['seller_email'];
			$row['pay_key'] = $_POST['pay_key'];
			$row['partner'] = $_POST['partner'];
			$row['pay_type'] = $_POST['pay_type'];
		
			}
			//财付通
			if($_POST['pay_code']=='tenpay'){
			$row['partner'] = $_POST['partner'];
			$row['pay_key'] = $_POST['pay_key'];
			}
			syDB ( 'payment' )->update ( array ('pay_id' => $pay_id ), $row );
			message_a ("修改成功",'?c=ld_payment&a=edit&pay_id='.$pay_id);
			$this->display ("payment_edit.html");
			}
			syDB("sysconfig")->update(array('code'=>set_payment),array('value'=>1));//1代表已经设置完支付方式方式
			$this->postgo = 'edit';
			$this->display ("payment_edit.html");
			
			
			
		}
	}	