<?php

/**
 * EmailController
 * Feel free to delete the methods and replace them with your own code.
 *
 * @author JieRen
 */
class EmailController extends DooController {
	
	public $data;
	
	public $email_task;
	
	/**
	 * 构造函数
	 */
	function __construct() {

		session_start();

		$this->data ['rootUrl'] = Doo::conf ()->APP_URL;
		
		Load::logic ( 'Email' );
		
		$this->email_task = new EmailLogic ();
	}
	
	/**
	 * 进入邮件管理
	 */
	public function manage_Email() {
		if (empty($_SESSION['main'])) {
			return Doo::conf()->APP_URL . 'm';
		}
//		$url='http://sendcloud.sohu.com/webapi/list.create.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org&name=sso';
//			$result = file_get_contents($url);
//			$rs=json_decode($result,true);
		
		Doo::loadModel ( 'users' );
		$Users = new Users();
		
		$count=$Users->count(array('asArray'=>true));
		
		$url='http://sendcloud.sohu.com/webapi/list.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org';
		$result = file_get_contents($url);
		$rs=json_decode($result,true);
//		print_r($rs);
//		die();
		$this->data['count2']=0;
		if (!empty($rs['count']))
			$this->data['count2']=$rs['lists'][0]['members_count'];
			
		$this->data['count1']=$count;
		$d=date("Y-m-d");
		$url='http://sendcloud.sohu.com/webapi/stats.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&start_date='.$d.'&end_date='.$d;
		$result = file_get_contents($url);
		$rs=json_decode($result,true);
		$this->data['count']=50000-$rs['stats'][0]['request'];
		$this->data['selectemail'] = true;
		$this->render ( 'admin/mailListCreate', $this->data, TRUE );
	}
	
	function sendUP(){
		/*
		$url='http://sendcloud.sohu.com/webapi/list.delete.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org';
		$result = file_get_contents($url);
		die;
		*/
		
		$url='http://sendcloud.sohu.com/webapi/list.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org';
		$result = file_get_contents($url);
		$rs=json_decode($result,true);
		
		if (empty($rs['count'])){
			$url='http://sendcloud.sohu.com/webapi/list.create.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org&name=sso';
			$result = file_get_contents($url);
			$rs=json_decode($result,true);
		}
		
		 $Path = "./global/sso.json";
		 
		 //不存在文件创建
		if(!file_exists($Path)){
		    file_put_contents($Path,0);
		} 
		 
		$id=file_get_contents($Path);
		
		Doo::loadModel ( 'users' );
		$Users = new Users();
		
		$start=$id;
		//$end=$id+1500;
		$end=500;
		
		$userList=$Users->find(array('limit'=>$start.','.$end,'asArray'=>true));
		
		/*
		foreach ($userList as $key=>$value){
			$userList[$key]['useremail']='cpthought@vip.qq.com';
		}
		//print_r($userList);
		//die;
		*/
		
		$ul=array();$i=0;$pa=array();
		foreach ($userList as $key=>$value){
			array_push($pa, $value['useremail']);
			$falg=true;
			if ($i==99){
				array_push($ul, $pa);
				$i=0;$pa=array();
				$falg=false;
			}
			if ($falg)
				$i++;
		}
		
		$url = 'http://sendcloud.sohu.com/webapi/list_member.add.json';
		foreach ($ul as $value){
			$userT=implode(';', $value);
			
			$param = array('api_user' => 'postmaster@zhzd.sendcloud.org',
			     	'api_key' => 'cDO1GjtY1seH',
			   		'mail_list_addr'=>'sso@maillist.sendcloud.org',
			        'upsert' =>'true',
			     
			        'member_addr' => $userT
				 );

			$post_data = http_build_query($param);
	
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_URL,$url);
			curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
			curl_setopt($ch, CURLOPT_NOBODY, false);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
			
			$result =curl_exec($ch);
			curl_close($ch);
			
			$rs=json_decode($result,true);
			if ($rs['message']=='success'){
				$id=file_get_contents($Path);
				file_put_contents($Path,$id+100);
			}
		
		}
		return '/m/email';
	}
	
	public function createEmail(){
		if (empty($_SESSION['main'])) {
			return Doo::conf()->APP_URL . 'm';
		}
		$title = $this->get_args ( "title" );
		//$content = $_POST[ "content" ];
		$stype = $this->get_args ( "stype" );
		if(!empty($title)&&$stype==1){
			Doo::loadModel ( 'users' );
			$Users = new Users();
			Doo::loadModel('/m/emailList');
			$emailList = new emailList();
			
//			$list=$Users->find(array('select'=>'useremail','asArray'=>true));
//			$size=floor(count($list)/5);
//			
//			$list=array_chunk($list,$size);
//			$emailJson=array();
//			foreach ($list as $value){
//				$em=array();
//				foreach ($value as $v){
//					array_push($em, $v['useremail']);
//				}
//				array_push($emailJson, $em);
//			}
			
			$emailList->title=$title;
			//$emailList->content=$content;
//			$emailList->Email1=json_encode($emailJson[0]);
//			$emailList->Email2=json_encode($emailJson[1]);
//			$emailList->Email3=json_encode($emailJson[2]);
//			$emailList->Email4=json_encode($emailJson[3]);
//			$emailList->Email5=json_encode($emailJson[4]);
			$emailList->time=date("Y-m-d");
			$emailList->insert();
			return '/m/mailList';
		}elseif(!empty($title)&&$stype==2){
			/*
			$url='https://sendcloud.sohu.com/webapi/list_member.delete.xml?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&mail_list_addr=websoft1@zhzd.sendcloud.org';
			$result = @file_get_contents($url, false);
			
			$url='https://sendcloud.sohu.com/webapi/list_member.delete.xml?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&mail_list_addr=websoft2@zhzd.sendcloud.org';
			$result = @file_get_contents($url, false);
			$url='https://sendcloud.sohu.com/webapi/list_member.delete.xml?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&mail_list_addr=websoft3@zhzd.sendcloud.org';
			$result = @file_get_contents($url, false);
			
			
			//print_r($list);
			
			$sitePath=Doo::conf()->SITE_PATH.'protected/class/';
			$s1=file_get_contents($sitePath."20000.php", false); 
			$s2=file_get_contents($sitePath."40000.php", false); 
			$s3=file_get_contents($sitePath."60000.php", false); 
			*/
			
			Doo::loadModel('/m/emailList');
			$emailList = new emailList();
			
			$emailList->title=$title;
			//$emailList->content=$content;
			$emailList->stype=2;
			//$emailList->Email1=$s1;
			//$emailList->Email2=$s2;
			//$emailList->Email3=$s3;
			$emailList->time=date("Y-m-d");
			$emailList->insert();
			
			/*
			https://sendcloud.sohu.com/webapi/list_member.add.xml?api_user=username&api_key=password&mail_list_addr=developers@sendcloud.org
				&member_addr=john@sendcloud.org;to2@126.com&name=约翰;林肯&vars={"money": "1000"};{"money": "200"}&upsert=true
				*/
			return '/m/mailList';
		}
		return '/m/email';
	}
	
	/*
	 * 生成用户
	 * 
	 
	 		$sitePath=Doo::conf()->SITE_PATH.'protected/controller/m/';
			$user=file_get_contents($sitePath."60000.txt", false); 
			//readfile();
			
			$user=str_replace("\r\n",",",$user);
			$userList=explode(',',$user);
			
			$list=array();
			foreach ($userList as $value){
				$s=strpos($value,'<');
				$e=strpos($value,'>');
				
				$value=substr($value,$s);
				$value=substr($value,0,$e);
				
				$value=str_replace("<","",$value);
				$value=str_replace(">","",$value);
				array_push($list, $value);
			}
			
			$userList=json_encode($list);
			file_put_contents("60000.php", $userList);
	 
	 */
	
	
	function viewMail(){
		if (empty($_SESSION['main'])) {
			return Doo::conf()->APP_URL . 'm';
		}
		$eid = $this->params[ "eid" ];
		
		Doo::loadModel('/m/emailList');
		$emailList = new emailList();
		
		$eMailList=$emailList->getOne(array('where'=>'eid ='.$eid,'asArray'=>true));
		
		$this->data['eMailList']=$eMailList;
		$this->data['selectemail'] = true;
		
		$this->render ( 'admin/mailListView', $this->data, TRUE );
	}
	
	function mailList(){
		if (empty($_SESSION['main'])) {
			return Doo::conf()->APP_URL . 'm';
		}
		Doo::loadModel('/m/emailList');
		$emailList = new emailList();
		
		$list=$emailList->find(array('desc'=>'eid','asArray'=>true));
		
		$d=date("Y-m-d");
		$url='http://sendcloud.sohu.com/webapi/stats.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&start_date='.$d.'&end_date='.$d;
		$result = @file_get_contents($url, false);
		$rs=json_decode($result,true);
		$this->data['count']=50000-$rs['stats'][0]['request'];
		
		$this->data['list']=$list;
		$this->data['selectemail'] = true;
//		$this->data['adminArray'] = $_SESSION['userArray'];
		$this->render ( 'admin/mailList', $this->data, TRUE );
	}
	
	
	function postEmail(){
		if (empty($_SESSION['main'])) {
			return Doo::conf()->APP_URL . 'm';
		}
		Doo::loadModel('/m/emailList');
		$eMList = new emailList();
		
		$eid=isset($this->params['eid'])?$this->params['eid']:0;
		$es=isset($this->params['es'])?$this->params['es']:0;
		
		if (!empty($eid)&&!empty($es)){
			$eMailList=$eMList->getOne(array('where'=>'eid ='.$eid.' and EmailName'.$es.'=""','asArray'=>true));
			//防止2次点击
			$sql = "update `zh_emailList` set EmailName".$es."='1' where eid = '" . $eid."'";
			Doo::db ()->query ( $sql );
			
			$toFormatMail=array();$sub=array();
			
			$toMail=json_decode($eMailList['Email'.$es],true);
			
			if ($eMailList['stype']==1){
				
				//'api_user=***&api_key=***&from=test@test.com&fromname=来自测试发送&subject=测试&template_invoke_name=ifaxin_bill&replyto=reply@test.com&label=16800&resp_email_id=true&use_maillist=true&to=users@maillist.sendcloud.org' http://sendcloud.sohu.com/webapi/mail.send_template.json
				
				$urlST='http://sendcloud.sohu.com/webapi/mail.send_template.json';
				
				$param = array('api_user' => 'postmaster@zhzd.sendcloud.org',
			     	'api_key' => 'cDO1GjtY1seH',
					'from' =>'postmaster@zhzd.sendcloud.org',
			        'fromname' => '123',
					'template_invoke_name'=>'sso_mail',
					
					//'subject' => $eMailList['title'],
					'labelId'=>'5787',
					'use_maillist'=>TRUE,
					'to'=>'sso@maillist.sendcloud.org',
			       
				 );

				$post_data = http_build_query($param);
				$post_data='api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&from=postmaster@zhzd.sendcloud.org&fromname=纵横软件&template_invoke_name=sso_mail&use_maillist=true&to=sso@maillist.sendcloud.org';
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_POST, 1);
				curl_setopt($ch, CURLOPT_URL,$urlST);
				//curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
				//curl_setopt($ch, CURLOPT_NOBODY, false);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
				
				$result =curl_exec($ch);
				curl_close($ch);
				
				
				return '/m/mailList';
				die;
			}
			
			
			
			if($eMailList['stype']==2){
				$sitePath=Doo::conf()->SITE_PATH.'protected/class/';
				if($es==1)
					$toMail=file_get_contents($sitePath."20000.php", false);
				if($es==2)
					$toMail=file_get_contents($sitePath."40000.php", false);
				if($es==3)
					$toMail=file_get_contents($sitePath."60000.php", false); 
				$toMail=json_decode($toMail,true);
			}
			$chunkMail=array_chunk($toMail,80);
			
			foreach ($chunkMail as $key=>$value){
				$l=$con=array();
				$toFormatMail['to']=$value;
				
				//for ($cn=1;$cn<=count($value);$cn++){
				//	array_push($l, $eMailList['title']);
					
					//array_push($con, $eMailList['content']);
				//}
				//$sub['%eTitle%']=$l;
				//$sub['%content%']=$con;
				
				//$toFormatMail['sub']=$sub;
				//print_r($toFormatMail);die;
				$url = 'http://sendcloud.sohu.com/webapi/mail.send_template.xml';
			    
				$fromname='纵横软件';
				if($eMailList['stype']==2)
					$fromname='网络版';
				
			    $param = array('api_user' => 'postmaster@zhzd.sendcloud.org',
			            'api_key' => 'cDO1GjtY1seH',
			    		'template_invoke_name'=>'sso_mail',
			            'from' =>'postmaster@zhzd.sendcloud.org',// 'postmaster@zhzd.sendcloud.org',
			            'fromname' => $fromname,
			    		'labelId'=>'5787',
			            'subject' => $eMailList['title'],
			            'substitution_vars' => json_encode($toFormatMail));
			
			    $options = array('http' => array('method'  => 'POST',"Content-type: application/x-www-form-urlencoded ",'content' => http_build_query($param)));
			    $context  = stream_context_create($options);
			    if (!empty($toFormatMail['to'])){
			    	$result = file_get_contents($url, false, $context);
			    }
				
			   
			    
			    
			    //if($result=='success'){
	//		    	$eM=new eMailList();
	//		    	$eM->status='2';
	//		    	$eM->update(array('where'=>'elid=?','param'=>array($elid)));
			   // }
			}
			
		  return '/m/mailList';
		}
	}
	
	
	
	/**
	 * 添加邮件任务
	 */
	function manage_add_email_task() {
		
		$data ['email_title'] = $this->get_args ( "email_title" );
		
		$data ['email_content'] = $this->get_args ( "email_content" );
		
		if (empty ( $data ['email_title'] ) || empty ( $data ['email_content'] )) {
			echo "email_title is empty or email_content is empty";
			die ();
		}
		
		$id = $this->email_task->add_email_task ( $data );
	}
	
	/**
	 * 发送邮件任务
	 */
	function manage_send_email_task() {
		
		$tid = $this->check_params ( 'tid' );
		
		$tid = is_numeric ( $tid ) ? $tid : 0;
		
		if ($tid == 0) {
			echo "plase input tid";
			die ();
		}
		
		$e_task = $this->email_task->get_email_task_by_tid ( $tid );
		
		$i = 0;
		
		$faild_count = 0;
		
		$error_email = "";
		
		$faild_email = "";
		
		//		foreach ( $e_task ['user_list'] as $key => $value ) {
		//			
		//			//邮件是否正确
		//			if (filter_var ( $value ['useremail'], FILTER_VALIDATE_EMAIL )) {
		//				//$value ['useremail'];
		//				//邮件是否发送成功
		//				$is_send = $this->email_task->send_email ( "cpthought@vip.qq.com",$e_task['email_title'],$e_task['email_content'] );
		//				
		//				if (! $is_send) {
		//					
		//					$faild_email .= $value ['useremail'] . ",";
		//					
		//					$faild_count ++;
		//				}
		//				$i ++;
		//			} else {
		//				
		//				$error_email .= "邮箱不正确用户：" . $value ['username'] . "<br/>";
		//			}
		//			usleep(500000);
		//		}
		

		//		$this->data ['send_count'] = $e_task ['send_count'];
		//		
		//		$this->data ['is_send_count'] = $e_task ['is_send_count'] + $i;
		//		
		//		$percent = $this->data ['is_send_count'] / $e_task ['send_count'] * 100;
		//		
		//		$this->data ['percent'] = round ( $percent, 2 ) . "%";
		//		
		//		$this->data ['error_email'] = $error_email;
		//		
		//		$this->data ['faild_count'] = $faild_count;
		

		$this->data ['send_count'] = $e_task ['send_count'];
		
		$this->data ['is_send_count'] = 0;
		
		$this->data ['percent'] = "0%";
		
		$this->data ['error_email'] = "";
		
		$this->data ['faild_count'] = 0;
		
		$this->data ['tid'] = $tid;
		
		//更新邮件进度
		//		$this->email_task->update_email_task_by_tid ( $tid, $this->data ['is_send_count'], $faild_email );
		//		
		//		if($this->data ['is_send_count']>=$this->data ['send_count']){
		//			
		//			$this->email_task->update_email_task_by_faild_email($tid);
		//		}
		

		$this->render ( 'admin/issendMail', $this->data, TRUE );
	}
	
	/**
	 * ajax发送邮件任务
	 */
	function manage_ajax_send_email_task() {
		
		$tid = $this->check_params ( 'tid' );
		
		$tid = is_numeric ( $tid ) ? $tid : 0;
		
		if ($tid == 0) {
			echo "plase input tid";
			die ();
		}
		
		$e_task = $this->email_task->get_email_task_by_tid ( $tid );
		
		//群发邮件已完成
		if ($e_task ['status'] == 3 || $e_task ['status'] == 4) {
			$data_list ['is_over'] = 2;
			
			$json = json_encode ( $data_list );
			
			echo $json;
			
			return false;
		}
		
		$i = 0;
		
		$faild_count = 0;
		
		$error_email = "";
		
		$faild_email = "";
		
		if (! empty ( $e_task )) {
			
			require_once './protected/config/email_stmp.conf.php';
			
			$stmp_i = 0;
			
			foreach ( $e_task ['user_list'] as $key => $value ) {
				
				//邮件是否正确
				if (filter_var ( $value ['useremail'], FILTER_VALIDATE_EMAIL )) {
					
					//邮件是否发送成功  "cpthought@vip.qq.com"$value ['useremail'] 914630468@qq.com
					

					$is_send = $this->email_task->send_email ( $value ['useremail'], $e_task ['email_title'], $e_task ['email_content'], $stmp [$stmp_i] ['host'], $stmp [$stmp_i] ['port'], $stmp [$stmp_i] ['username'], $stmp [$stmp_i] ['password'], $stmp [$stmp_i] ['form'] );
					
					if (! $is_send) {
						
						$faild_email .= $value ['useremail'] . ",";
						
						$faild_count ++;
					}
					$stmp_i ++;
					
					if ($stmp_i == 30)
						$stmp_i = 0;
					
					$i ++;
				} else {
					
					$error_email .= "邮箱不正确用户：" . $value ['username'] . "<br/>";
				}
				usleep ( 50000 );
			}
			
			$data_list = array ();
			
			$data_list ['send_count'] = $e_task ['send_count'];
			
			$data_list ['is_send_count'] = $e_task ['is_send_count'] + $i;
			
			$percent = $data_list ['is_send_count'] / $e_task ['send_count'] * 100;
			
			$data_list ['percent'] = round ( $percent, 2 ) . "%";
			
			$data_list ['error_email'] = $error_email;
			
			$data_list ['faild_count'] = $faild_count;
			
			$data_list ['tid'] = $tid;
			
			$data_list ['is_over'] = 1;
			
			//更新邮件进度
			$this->email_task->update_email_task_by_tid ( $tid, $data_list ['is_send_count'], $faild_email );
		}
		if ($data_list ['is_send_count'] >= $data_list ['send_count']) {
			$data_list ['is_over'] = 2;
			
			$this->email_task->update_email_task_by_faild_email ( $tid );
		}
		
		$json = json_encode ( $data_list );
		
		echo $json;
	}
	
	
/**
	 * 发送邮件任务
	 */
	function manage_faild_email_task() {
		
		$tid = $this->check_params ( 'tid' );
		
		$tid = is_numeric ( $tid ) ? $tid : 0;
		
		if ($tid == 0) {
			echo "plase input tid";
			die ();
		}
		
		$e_task = $this->email_task->get_faild_email_task_by_tid ( $tid );
		
		$faild_array = explode ( ",", $e_task ['faild_uid'] );
		
		$this->data ['send_count'] = count($faild_array);
		
		$this->data ['is_send_count'] = 0;
		
		$this->data ['tid'] = $tid;
		
		$this->render ( 'admin/isfaildMail', $this->data, TRUE );
	}
	
	
	/**
	 * 发送失败文件
	 */
	function manage_send_faild_email_task() {
		$tid = $this->check_params ( 'tid' );
		
		$tid = is_numeric ( $tid ) ? $tid : 0;
		
		if ($tid == 0) {
			echo "plase input tid";
			die ();
		}
		
		$e_task = $this->email_task->get_faild_email_task_by_tid ( $tid );
		
		$faild_email = "";
		
		$error_email="";
		
		if (! empty ( $e_task )) {
			
			//群发邮件已完成
			if ($e_task ['status'] != 3) {
				
				echo "send email is complate1";
				
				return false;
			}elseif(empty($e_task['faild_uid'])){
				
				$this->email_task->update_email_task_status_by_tid ( $tid, 4 );
				
				echo "send email is complate2";
				return false;
			}
			
			$faild_array = explode ( ",", $e_task ['faild_uid'] );
		
			require_once './protected/config/email_stmp.conf.php';
			
			$stmp_i = 0;
			
			$i=0;
			$k=$s="";
			
			foreach ($faild_array as $key=>$value){
				
					//邮件是否正确
					if (!empty($value)&&filter_var ( $value , FILTER_VALIDATE_EMAIL )) {
						
						//邮件是否发送成功  "cpthought@vip.qq.com" $value ['useremail'] 914630468@qq.com
						$is_send = $this->email_task->send_email ( $value , $e_task ['email_title'], $e_task ['email_content'], $stmp [$stmp_i] ['host'], $stmp [$stmp_i] ['port'], $stmp [$stmp_i] ['username'], $stmp [$stmp_i] ['password'], $stmp [$stmp_i] ['form'] );
						
						if (! $is_send) {
							
							$faild_email .= $value  . ",";
							$k.= $value. ",";
							unset($faild_array[$i]);
						}else{
							$s.= $value. ",";
							unset($faild_array[$i]);
						}
						$stmp_i ++;
						
						if ($stmp_i == 30)
							$stmp_i = 0;
						
					} else {
						
						$error_email .= "邮箱不正确用户：" . $value  . "<br/>";
					}
					
					usleep ( 50000 );
				
					if($i==28)
						break;
					$i++;
			}
			//
			$t=implode(",",$faild_array);	
			$this->email_task->update_faild_email_task_by_tid ( $tid, $t );
			$this->email_task->de_faild_email_task_by_tid ( $tid, $e_task['de_email'].$faild_email );
			
			$data_list = array ();
			
			$data_list ['send_count'] = count($faild_array);
			
			$data_list ['is_send_count'] = $i+1;
			
			$data_list ['tid'] = $tid;
			
			$data_list['error_email']=$k;
			
			$data_list ['is_over'] = 1;
			
			if (count($faild_array) <= 0) {
				$data_list ['is_over'] = 2;
			}
			
			$json = json_encode ( $data_list );
			
			echo $json;
			

		}

	}
	
	/**
	 * 删除邮件任务
	 */
	function manage_delete_email_task() {
		$tid = $this->check_params ( 'tid' );
		
		$tid = is_numeric ( $tid ) ? $tid : 0;
		
		if ($tid == 0) {
			echo "plase input tid";
			die ();
		}
		
		$e_task = $this->email_task->delete_email_task_by_tid ( $tid );
	}
	
	/**
	 * 获取get或者POST值
	 * @param string $name 属性名称
	 * @return fixed 值
	 */
	function get_args($name) {
		if (isset ( $_GET [$name] )) {
			if (is_array ( $_GET [$name] ))
				return $_GET [$name];
			else
				return addslashes ( $_GET [$name] );
		
		} elseif (isset ( $_POST [$name] )) {
			if (is_array ( $_POST [$name] ))
				return $_POST [$name];
			else
				return addslashes ( $_POST [$name] );
		} else {
			
			return false;
		}
	}
	
	/**
	 * 检测数据输入的非法字符和转义非法字符
	 */
	function check_params($name = "") {
		if (isset ( $this->params [$name] )) {
			
			return mysql_escape_string ( $this->params [$name] );
		} else {
			
			return false;
		}
	}
}

?>