<?php
class Address
{
	function Address()
	{
		$GLOBALS['Helpe']-> get_usermenu();
		
		$getmenu = $GLOBALS['Helpe']->get_menu();
		$GLOBALS['Templ']->assign('getmenu',$getmenu);
		
		$getlink = $GLOBALS['Helpe']->get_link();
		$GLOBALS['Templ']->assign('getlink',$getlink);
		
		$getuserlink = $GLOBALS['WebSe']->getuserlink();
		$GLOBALS['Templ']->assign('getuserlink',$getuserlink);
		
		//$userdetail = $this -> userdetail();

		$webtitle = '收货人信息 - 用户中心';
		//处理你现在的位置
		$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 收货人信息';
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);

	}
	
	function infolist()
	{
		$this -> userAddress();
		
		$webtitle = '收货人信息 - 用户中心';
		//处理你现在的位置
		$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 收货人信息';
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);

		//$GLOBALS['Templ'] -> assign('actUrl',BASE_WEBURL."/user/index.php?load=user&act=updateuser");
		
		$GLOBALS['Templ'] -> assign('actUrl',BASE_WEBURL."/user/?load=address&act=addaddress");
		
		$GLOBALS['Templ']-> display('address_tpl.html');
	}
	
	function addaddress()
	{
		$use_idval 				= $_SESSION["webUser"]["use_id"];
		$add_nameval 			= $GLOBALS['Reque'] -> funpost("add_name");
		$add_provinceval 		= $GLOBALS['Reque'] -> funpost("idprovince");
		$add_cityval 			= $GLOBALS['Reque'] -> funpost("idcity");
		$add_districtval 		= $GLOBALS['Reque'] -> funpost("iddistrict");
		$add_pcdallval			= $GLOBALS['Reque'] -> funpost("hiprovince").$GLOBALS['Reque'] -> funpost("hicity").$GLOBALS['Reque'] -> funpost("hidistrict");
		
		
		$add_addressval 		= $GLOBALS['Reque'] -> funpost("add_address");
		$add_postalcodeval 		= $GLOBALS['Reque'] -> funpost("add_postalcode");
		$add_mobileval 			= $GLOBALS['Reque'] -> funpost("add_mobile");
		
		$add_phoneval 			= $GLOBALS['Reque'] -> funpost("add_phone");
		
		$add_emailval 			= $GLOBALS['Reque'] -> funpost("add_email");
		$add_signval 			= $GLOBALS['Reque'] -> funpost("add_sign");
		$add_sendtimeval 		= $GLOBALS['Reque'] -> funpost("add_sendtime");
		

		
		
		$insertsql = "INSERT INTO `".SQL_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_postalcode` , `add_email` , `add_sign` , `add_sendtime` , `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_postalcodeval', '$add_emailval', '$add_signval', '$add_sendtimeval', '$add_enabledval', '0')";
		
		$GLOBALS['MySql'] -> querySql( $insertsql );
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_addsusse"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=address&act=infolist");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
	
	}

 

	function userAddress()
	{
		$webuse_id = $_SESSION["webUser"]["use_id"] ;
		
		$sqladdress = " SELECT *  FROM  ".SQL_PREFIX."address  WHERE use_id = ".$webuse_id."  GROUP BY add_id ORDER BY `add_id` LIMIT 0 , 1000";
		
		$AddressInfo = $GLOBALS['MySql'] -> selectInfo( $sqladdress );
				
		$GLOBALS['Templ'] -> assign('AddressInfo',$AddressInfo);

	}
	
	function info(  )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];

		$sqlQuery = " SELECT * FROM ".SQL_PREFIX."address   WHERE add_id =  ".$infoid." and use_id = ".$_SESSION["webUser"]["use_id"] ;
		
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);

		$GLOBALS['Templ']->assign('actUrl',BASE_WEBURL."/user/index.php?load=address&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('addressedit_tpl.html');
	
	}
	
	function editinfo()
	{
		
		$add_idval 				= $GLOBALS['Reque'] -> funpost("add_id");

		$use_idval 				= $_SESSION["webUser"]["use_id"];
		$add_nameval 			= $GLOBALS['Reque'] -> funpost("add_name");
		$add_provinceval 		= $GLOBALS['Reque'] -> funpost("idprovince");
		$add_cityval 			= $GLOBALS['Reque'] -> funpost("idcity");
		$add_districtval 		= $GLOBALS['Reque'] -> funpost("iddistrict");
		
		if($GLOBALS['Reque'] -> funpost("hiprovince")=='' and $GLOBALS['Reque'] -> funpost("hicity") =='' and $GLOBALS['Reque'] -> funpost("hidistrict") =='')
		{
			$add_pcdallval			= $GLOBALS['Reque'] -> funpost("add_pcdall");
		}else{
			$add_pcdallval			= $GLOBALS['Reque'] -> funpost("hiprovince").$GLOBALS['Reque'] -> funpost("hicity").$GLOBALS['Reque'] -> funpost("hidistrict");
		}
		$add_addressval 		= $GLOBALS['Reque'] -> funpost("add_address");
		$add_postalcodeval 		= $GLOBALS['Reque'] -> funpost("add_postalcode");
		$add_mobileval 			= $GLOBALS['Reque'] -> funpost("add_mobile");
		$add_phoneval 			= $GLOBALS['Reque'] -> funpost("add_phone");
		$add_emailval 			= $GLOBALS['Reque'] -> funpost("add_email");
		$add_signval 			= $GLOBALS['Reque'] -> funpost("add_sign");
		$add_sendtimeval 		= $GLOBALS['Reque'] -> funpost("add_sendtime");


		if($use_idval)
		{
			$updatesql = "UPDATE `".SQL_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_postalcode = '".$add_postalcodeval."' , add_mobile = '".$add_mobileval."' , add_phone = '".$add_phoneval."' , add_email = '".$add_emailval."' , add_sign = '".$add_signval."' , add_sendtime = '".$add_sendtimeval."'  WHERE  add_id = '".$add_idval."'  and use_id =  '".$use_idval."'";
			
			$GLOBALS['MySql'] -> querySql( $updatesql );
		}
	
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_editsusse"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=address&act=infolist");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
		
	}
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$insertip 	= "  DELETE FROM `".SQL_PREFIX."address` WHERE `add_id` in ( $infoid ) and use_id = ".$_SESSION["webUser"]["use_id"] ;
		$GLOBALS['MySql'] -> querySql($insertip);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=address&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
}

$Address = new Address();
?>