<?php
if (!defined('ROOT')) exit('Can\'t Access !'); 
class mod_tools extends module_class{
 	function main(){

	}
	
 	function upload(){
	    $json = new Services_JSON();
		$ImgPath = $_POST['ImgPath'] ? $_POST['ImgPath'] : $_GET['ImgPath'];
		$filedate = formattime(time(),"Y-m-d");
        $uploadpath = PATH.config::get('uploadpath').'/'.$ImgPath.'/'.$filedate.'/';
		$filepath = config::get("siteurl").config::get('uploadpath').'/'.$ImgPath.'/'.$filedate.'/';
        $upload = new upload($uploadpath,array('gif','jpg','jpge'));
        $file = $upload->getfile();
        if($upload->errno!=15&&$upload->errno!=0) {
			$msg = $json->encode(array('error' => 1, 'message' => $upload->errmsg()));
		}else{
			$msg = $json->encode(array('error' => 0, 'url' => $filepath.$file[0][saveName], 'trueurl' => $upload->returninfo['name']));	
		}
        echo $msg;
		exit;
	}
	
    function filemanager(){
        $uploadpath = PATH.config::get('uploadpath');
		$filepath = config::get("siteurl").config::get('uploadpath').'/';
        if(empty($_GET['path'])) {
	       $current_path = realpath($uploadpath) . '/';
	       $current_url = $filepath;
	       $current_dir_path = '';
	       $moveup_dir_path = '';
        }else{
	       $current_path = realpath($uploadpath) . '/' . $_GET['path'];
	       $current_url = $filepath . $_GET['path'];
	       $current_dir_path = $_GET['path'];
	       $moveup_dir_path = preg_replace('/(.*?)[^\/]+\/$/', '$1', $current_dir_path);
        }

        if (preg_match('/\.\./', $current_path)){
	       echo 'Access is not allowed.';
	       exit;
        }
        if (!preg_match('/\/$/', $current_path)) {
	       echo 'Parameter is not valid.';
	       exit;
        }
        if (!file_exists($current_path) || !is_dir($current_path)) {
	       echo 'Directory does not exist.';
	       exit;
        }
		$filelist = dirpath($current_path);
		usort($filelist, 'cmp_func');
        $result = array();
        $result['moveup_dir_path'] = $moveup_dir_path;
        $result['current_dir_path'] = $current_dir_path;
        $result['current_url'] = $current_url;
        $result['total_count'] = count($filelist);
        $result['file_list'] = $filelist;
        $json = new Services_JSON();
        echo $json->encode($result);
        exit;
	}
	
	
	function seccode(){
		include_once PATH.'library/seccode_class.php';
        $seccode = new ValidationCode('60','20','4');
        $seccode->outImg();
	}	
	function _getmoney(){
	  $money = $_GET['money'];
      $arr['money'] = formatnum($money/$_GET['number']);
	  $arr['error'] = '0';
	  if($money>0===false){
		$arr['error'] = '请输入要分红的金额';
	    echo json($arr);
	    exit;
	  }
	  if($arr['money']>0===false){
		$arr['error'] = '要分红的金额太少';
	    echo json($arr);
	    exit;
	  }
	  echo json($arr);
	  exit;
	}
	function swfupload(){
		$ftype = str_replace('.','*.',config::get('filetype'));
		$ftype = str_replace('|',';',$ftype);
		$fsize = config::get('filesize')/1024;
		$this->ftype = '图片('.$ftype.')';
		$this->fsize = "{$fsize}MB";
		$this->fcount = config::get('filecount');		
	}
	function ajax(){
		if($_GET['do']=='seccode'){
		   echo $_GET['seccode']==$_SESSION['seccode'] ? 'yes' : 'no';
		   exit;
		}elseif($_GET['do']=='chkusername'){
		   echo $this->user->checkusername($_GET['username']) ? "" : "ok";
		   exit;
	    }elseif($_GET['do']=='chkemail'){
		   echo $this->user->checkemail($_GET['email']) ? "" : "ok";
		   exit;
	    }elseif($_GET['do']=='checkidcard'){
		   $uid = $_GET['uid'] ? $_GET['uid'] : $this->member['uid'];
		   echo $this->user->checkidcard($_GET['idcard'],$uid) ? "" : "ok";
		   exit;
	    }elseif($_GET['do']=='authemail'){
		   echo $this->user->authemail($_GET['email'],$this->member[uid]);
		   exit;
	    }elseif($_GET['do']=='checkuserphone'){
		   echo $this->user->checkuserphone($_GET['userphone']) ? "" : "ok";
		   exit;
	    }elseif($_GET['do']=='chkpassword'){
		   echo $this->user->password($_GET['password'],$this->member[salt]) != $this->member[password] ? "" : "ok";
		   exit;
	    }elseif($_GET['do']=='user'){
		   echo $this->member[$_GET['key']];
		   exit;
	    }elseif($_GET['do']=='chkrepass'){
		   echo $this->user->password($_GET['password'],$this->member[salt]) != $this->member[repass] ? "" : "ok";
		   exit;
	    }elseif($_GET['do']=='chkjsr'){
		   echo $this->user->checkusername($_GET['username']) ? "ok" : "";
		   exit;
	    }elseif($_GET['do']=='chkstore'){
		   $val = $this->user->sql($_GET['username'],'username');
		   if(is_array($val)){
			  $truename = $val['truename']=='' ? '该会员未完善实名资料' : '姓名：'.$val['truename']; 
		   }else{
			  $truename = '';   
		   }
		   echo $truename;
		   exit;
	    }elseif($_GET['do']=='chkdls'){
		   $sql = "select * from {$this->pre}user where groupid='2' and s_province='$_GET[s_province]' and s_city='$_GET[s_city]'";
		   $user = $this->mysql->select_one($sql." and s_county='$_GET[s_county]' and status>0");
		   echo is_array($user) ? "" : "ok";
		   exit;
	    }elseif($_GET['do']=='money'){
		   $yfmoney = $_GET['money']*config::get('shsf');
		   echo $yfmoney;
		   exit;
	    }elseif($_GET['do']=='resendcode'){
		   if(time()-$this->member['mtime']>180){
			 $arr['msalt'] = mt_rand(1000,9999);
			 $arr['mtime'] = time();
  		     $this->user->update($arr,$this->member['uid']);
             @sendsms("你获得的手机验证码：".$arr['msalt']."。【".config::get("sitename")."】",$this->member['userphone']);
		   }
		   exit;
	    }
	}
}
?>