<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2010-2016 HuCart.COM，并保留所有权利。
 * 此程序是HuCart的一部分。  
 * 根据MIT许可证授权(在软件和软件的所有副本中都必须包含版权声明和许可声明。)
 * 官方网址:http://Www.HuCart.Com
 * 技术支持:http://Www.cheermi.com
 * 对于完整的版权和许可证信息，请参阅MIT-LICENSE.TXT
 * 程序的再发布必须保留以上版权声明。
 *
 *@author pgmk<pgmk@hucart.com>
 *@copyright pgmk<pgmk@hucart.com>
 *@link http://www.hucart.com
 *@license The MIT License.
 *----------------------------------------------------------------------------*
**/
class User_info extends HC_Controller
{
	//注意无须构造函数,使用了构造函数得重构父类 parent::__construct();
	function __construct()
	{
		parent::__construct();
		$this->load_lang('user/user_info');
		$this -> load('user'); 
		$this -> user -> online_user();
		$this -> load_db();
		
		$this -> load_model('web_config'); 	//加载模型
		$web_config = $this -> web_config_mod -> get_sys_config();
		//$this -> set_view_dir( $web_config['temp'] -> dir );
		$this -> view -> assign('web_config', $web_config);

		$this -> load('helper'); //加载辅助类
		$user_menu = $this -> web_config_mod ->  get_user_menu();
		$get_menu  = $this -> web_config_mod -> get_web_menu();
		$get_link  = $this -> web_config_mod -> get_link();
		$get_user_link = $this -> session->get_user_link( $this->lang['user_link'] );
		
		$this -> view -> assign('user_menu',$user_menu);
		$this -> view -> assign('get_menu',$get_menu);
		$this -> view -> assign('get_link',$get_link);
		$this -> view -> assign('get_user_link',$get_user_link);
	}
	
	public function info_list()
	{
		$webtitle = '基本信息 - 用户中心';
		//处理你现在的位置
		$now_address = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 基本信息';
		
		$this -> user_detail();
		
		$this -> view -> assign('webtitle',$webtitle);
		
		$this -> view -> assign('now_address',$now_address);
	

		$this -> view -> assign('act_url',BASE_WEBURL."/user/index.php?load=user_info&act=update_user");
		
		$this -> view -> display('user_info.tpl');
	}
	
	public function pwd()
	{
		$webtitle = '修改密码 - 用户中心';
		//处理你现在的位置
		$now_address = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 修改密码';
		
		$this -> view -> assign('webtitle',$webtitle);
		
		$this -> view -> assign('now_address',$now_address);

		$this -> view -> assign('act_url',BASE_WEBURL."/user/index.php?load=user_info&act=act_pwd");
		
		$this -> view -> display('user_pwd.tpl');
	}
	
	public function act_pwd()
	{
		//修改密码可以有特殊符号
		$oldpwdval  	= trim($_REQUEST["oldpwd"]);  
		$use_pwdval		= trim($_REQUEST["use_pwd"]);  
		$reuse_pwdval 	= trim($_REQUEST["reuse_pwd"]);  
		
		$use_idval 		= $_SESSION["user"]["use_id"];
		
		$sql = " SELECT use_id  FROM ".$this -> db -> prefix."users WHERE use_id= '".$use_idval."' AND  use_pwd = '".md5($oldpwdval)."' LIMIT 1 ";
		$User = $this -> db -> select_one($sql);
		
		if($User["use_id"]!='')
		{
			//修改成功！
			$sqlup = " UPDATE ".$this -> db -> prefix."users set  use_pwd = '".md5($use_pwdval)."'  WHERE  use_id= ".$use_idval;
			$this -> db -> query_sql($sqlup);
			$this -> view -> assign('info_title',$this->lang['pwd_edit_susse']);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/?load=user_info&act=pwd");
			$this -> view -> display('suggestion.tpl');
			//exit();
		}else{
			//修改有误!
			$this -> view -> assign('info_title',$this->lang['pwd_edit_error']);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/?load=user_info&act=pwd");	
			$this -> view -> display('suggestion.tpl');
			
		}
	}

	private function user_detail()
	{

		$sql_user  = " SELECT *  FROM  `".$this -> db -> prefix."user_detail`  WHERE use_id = '".$_SESSION["user"]["use_id"]."'  ";
		$user_info = $this -> db -> select_one($sql_user);
		$this -> view -> assign('user_info',$user_info);
	}
	
	public function update_user()
	{

		$use_idval 				= $_SESSION["user"]["use_id"];
		$usd_sexval 			= $this -> input -> req["usd_sex"];
		$usd_nickval 			= $this -> input -> req["usd_nick"];
		$usd_birthdayval 		= strtotime($this -> input -> req["usd_birthday"]);
		$usd_saltval 			= $this -> input -> req["usd_salt"];
		$usd_msnval 			= $this -> input -> req["usd_msn"];
		$usd_qqval 				= $this -> input -> req["usd_qq"];
		$usd_officephoneval 	= $this -> input -> req["usd_officephone"];
		$usd_homephoneval 		= $this -> input -> req["usd_homephone"];
		$usd_telval 			= $this -> input -> req["usd_tel"];
		
		$usd_provinceval 	= $this -> input -> req["province"];
		$usd_cityval 		= $this -> input -> req["city"];
		$usd_districtval 	= $this -> input -> req["district"];
		$usd_pcd_all		= $this -> input -> req["pcd_all"];
		
		//$usd_provinceval 		= $this -> input -> req["usd_province"];
		$usd_addressval 		= $this -> input -> req["usd_address"];
		$usd_truenameval 		= $this -> input -> req["usd_truename"];
		
		$usd_imageval 		= trim($_REQUEST["usd_image"]);
		
		if($use_idval)
		{
			$update_sql = "UPDATE `".$this -> db -> prefix."user_detail` SET  usd_sex = '".$usd_sexval."' , usd_nick = '".$usd_nickval."' , usd_birthday = '".$usd_birthdayval."' , usd_salt = '".$usd_saltval."' , usd_msn = '".$usd_msnval."' , usd_qq = '".$usd_qqval."' , usd_office_phone = '".$usd_officephoneval."' , usd_home_phone = '".$usd_homephoneval."' , usd_tel = '".$usd_telval."' , usd_province = '".$usd_provinceval."' ,usd_city = '".$usd_cityval."' ,usd_district = '".$usd_districtval."' ,usd_pcd_all = '".$usd_pcd_all."' , usd_address = '".$usd_addressval."' , usd_truename = '".$usd_truenameval."' ,`usd_image` = '$usd_imageval'  WHERE  use_id = '".$use_idval."' ";
			
			$this -> db -> query_sql( $update_sql );
		}
			$this -> view -> assign('info_title',$this->lang["editsusse"]);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=user_info&act=info_list");
			$this -> view -> display('suggestion.tpl');
		
	}
	

	
	
}
