<?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.
 *----------------------------------------------------------------------------*
**/
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Address extends HC_Controller
{
	//注意无须构造函数,使用了构造函数得重构父类 parent::__construct();
	function __construct()
	{
		parent::__construct();
		$this->load_lang('user/address');
		$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);
	}
	
 /*
	function Address()
	{
 
		
		//$this -> userdetail();
		$this -> userAddress();
		
		$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);

	}
*/
	
	function info_list()
	{

		$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);
		
		$address_info = $this ->get_address();

		$this -> view -> assign('address_info',$address_info);
		//$this -> view -> assign('act_url',BASE_WEBURL."/user/index.php?load=user&act=updateuser");
		
		$this -> view -> assign('act_url',BASE_WEBURL."/user/?load=address&act=add_address");
		
		$this -> view -> display('address.tpl');
	}
	
	function add_address()
	{
		$use_idval 				= $_SESSION["user"]["use_id"];
		$add_nameval 			= $this -> input -> req["add_name"];
		$add_provinceval 		= $this -> input -> req["province"];
		$add_cityval 			= $this -> input -> req["city"];
		$add_districtval 		= $this -> input -> req["district"];
		$add_pcdallval			= $this -> input -> req["pcd_all"];
		
		$add_addressval 		= $this -> input -> req["add_address"];
		$add_zip_codeval 		= $this -> input -> req["add_zip_code"];
		$add_mobileval 			= $this -> input -> req["add_mobile"];
		$add_phoneval 			= $this -> input -> req["add_phone"];
		$add_emailval 			= $this -> input -> req["add_email"];
		$add_signval 			= $this -> input -> req["add_sign"];
		$add_send_typeval 		= $this -> input -> req["add_send_type"];

		$insertsql = "INSERT INTO `".$this -> db -> prefix."address` (  `use_id` , `add_sex` , `add_birthday` , `add_phone` , `add_mobile` , `add_name` , `add_province` , `add_city` , `add_district` , `add_pcdall`,`add_address` , `add_zip_code` , `add_email` , `add_sign` , `add_send_type` , `add_enabled` , `add_type` )
VALUES ( $use_idval , '0', '', '$add_phoneval', '$add_mobileval', '$add_nameval' , '$add_provinceval', '$add_cityval', '$add_districtval', '$add_pcdallval', '$add_addressval' , '$add_zip_codeval', '$add_emailval', '$add_signval', '$add_send_typeval', '$add_enabledval', '0')";
		
		$this -> db -> query_sql( $insertsql );
		
			$this -> view -> assign('info_title',$this->lang["addsusse"]);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=address&act=info_list");
			$this -> view -> display('suggestion.tpl');	
	
	}

 

	private  function get_address()
	{
		//echo 'ddddddd';
		$webuse_id = $_SESSION["user"]["use_id"] ;
		
		$sqladdress = " SELECT *  FROM  ".$this -> db -> prefix."address  WHERE use_id = ".$webuse_id."  GROUP BY add_id ORDER BY `add_id` LIMIT 0 , 1000";
		
		return $this -> db -> select_info( $sqladdress );
	}
	
	function info(  )
	{
		$infoid = intval(trim($_REQUEST["id"]));

		$sql_query = " SELECT * FROM ".$this -> db -> prefix."address   WHERE add_id =  ".$infoid." and use_id = ".$_SESSION["user"]["use_id"] ;
		
		$info = $this -> db -> select_one($sql_query);

		$this -> view ->assign('act_url',BASE_WEBURL."/user/index.php?load=address&act=edit_info");
		$this -> view -> assign('info',$info);
		$this -> view -> display('address_edit.tpl');
	
	}
	
	function edit_info()
	{
		
		$add_idval 				= $this -> input -> req["add_id"];
		$use_idval 				= $_SESSION["user"]["use_id"];
		$add_nameval 			= $this -> input -> req["add_name"];
		
		$add_provinceval 		= $this -> input -> req["province"];
		$add_cityval 			= $this -> input -> req["city"];
		$add_districtval 		= $this -> input -> req["district"];
		
		$add_pcdallval			= $this -> input -> req["pcd_all"];

		$add_addressval 		= $this -> input -> req["add_address"];
		$add_zip_codeval 		= $this -> input -> req["add_zip_code"];
		$add_mobileval 			= $this -> input -> req["add_mobile"];
		$add_phoneval 			= $this -> input -> req["add_phone"];
		$add_emailval 			= $this -> input -> req["add_email"];
		$add_signval 			= $this -> input -> req["add_sign"];
		$add_send_typeval 		= $this -> input -> req["add_send_type"];


		if($use_idval)
		{
			$updatesql = "UPDATE `".$this -> db -> prefix."address` SET  add_name = '".$add_nameval."' , add_province = '".$add_provinceval."' , add_city = '".$add_cityval."' , add_district = '".$add_districtval."' , add_pcdall = '".$add_pcdallval."' , add_address = '".$add_addressval."' , add_zip_code = '".$add_zip_codeval."' , add_mobile = '".$add_mobileval."' , add_phone = '".$add_phoneval."' , add_email = '".$add_emailval."' , add_sign = '".$add_signval."' , add_send_type = '".$add_send_typeval."'  WHERE  add_id = '".$add_idval."'  and use_id =  '".$use_idval."'";
			
			$this -> db -> query_sql( $updatesql );
		}
	
			$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=address&act=info_list");
			$this -> view -> display('suggestion.tpl');
		
	}
	
	function del( )
	{
		$infoid = intval(trim($_REQUEST["id"]));
		
		$insertip 	= "  DELETE FROM `".$this -> db -> prefix."address` WHERE `add_id` in ( $infoid ) and use_id = ".$_SESSION["user"]["use_id"] ;
		$this -> db -> query_sql($insertip);
		$this -> view -> assign('info_title',$this->lang['delsusse']);
		$this -> view -> assign('URL_TIME',URL_TIME);
		$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=address&act=info_list");
		$this -> view -> display('suggestion.tpl');
	}
	
	
}
