<?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 Ajax_area  extends HC_Controller
{
	//注意无须构造函数,使用了构造函数得重构父类 parent::__construct();
	function __construct()
	{
		parent::__construct();	
		$this -> load_lang('www/ajax_area');
		$this -> load('user'); 
		$this -> user -> online_user();
		$this -> load_db();

	}
	
	function province()
	{
		//var_dump($_REQUEST['obj_val']);
		$sel_val = trim($_REQUEST['sel_val']);
		$obj_val = trim($_REQUEST['obj_val']);
		
		$sql_area = " SELECT are_id,are_name  FROM  ".$this -> db -> prefix."area_dict   WHERE are_parent_id = 1  GROUP BY are_id  ";
				
		$areaDetail = $this -> db -> select_info($sql_area);
		
		$echoval  =  '<select class="form-control" name="province" id="province" onchange="get_area( this.value,   \'city\' );get_pcd_all(this,\'province\');" >';
		
		$echoval .= '<option value="" >'. $this->lang['txt_select'].'</option>';
		
		foreach($areaDetail as $akey => $aval)
		{
			if($sel_val==$aval["are_id"])
			{
				$echoval .= '<option value='.$aval["are_id"].' selected=\'selected\' >'.$aval["are_name"].'</option>';
				$selval = $aval["are_name"];
			}else{
				$echoval .= '<option value='.$aval["are_id"].' >'.$aval["are_name"].'</option>';
			}
		}
		
		$echoval .= '</select>';
		if($paval[2]==1)
		{
			echo $selval."&nbsp;";
		}else{
			echo $echoval;
		}
	}
	
	function city()
	{
		$obj_val = trim($_REQUEST['obj_val']);
		$sel_val = trim($_REQUEST['sel_val']);
		
		if( $obj_val!='' )
		{
			$sqlarea = " SELECT are_id,are_name  FROM  ".$this -> db -> prefix."area_dict  WHERE are_parent_id =  ".$obj_val."  GROUP BY are_id  ";
				
			$areaDetail = $this -> db -> select_info($sqlarea);
		}
		$echoval  = '<select class="form-control" name="city" id="city" onchange="get_area( this.value,  \'district\');get_pcd_all(this,\'city\');" >';
		
		$echoval .= '<option value="" >'. $this->lang['txt_select'].'</option>';
		if($areaDetail!=''){
			foreach($areaDetail as $akey => $aval)
			{
				if($sel_val==$aval["are_id"])
				{
					$echoval .= '<option value='.$aval["are_id"].' selected=\'selected\' >'.$aval["are_name"].'</option>';
					$selval = $aval["are_name"];
				}else{
					$echoval .= '<option value='.$aval["are_id"].' >'.$aval["are_name"].'</option>';
				}
			}
		}
		$echoval .= '</select>';
		if($caval[2]==1)
		{
			echo $selval."&nbsp;";
		}else{
			echo $echoval;
		}
	}
	
	function district()
	{
		$obj_val = trim($_REQUEST['obj_val']);
		$sel_val = trim($_REQUEST['sel_val']);
		
		
		if( $obj_val!='' )
		{
			$sqlarea = " SELECT are_id,are_name  FROM  ".$this -> db -> prefix."area_dict   WHERE are_parent_id = ".$obj_val."  GROUP BY are_id  ";	
			$areaDetail = $this -> db -> select_info($sqlarea);
		}
		$echoval  = '<select class="form-control" name="district" id="district" onchange="get_pcd_all(this,\'district\');" >';
		
		$echoval .= '<option value="" >'. $this->lang['txt_select'].'</option>';
		if($areaDetail!='')
		{
			foreach($areaDetail as $akey => $aval)
			{
				if($sel_val==$aval["are_id"])
				{
					$echoval .= '<option value='.$aval["are_id"].' selected=\'selected\' >'.$aval["are_name"].'</option>';
					$selval = $aval["are_name"];
				}else{
					$echoval .= '<option value='.$aval["are_id"].' >'.$aval["are_name"].'</option>';
				}
			}
		}
		$echoval .= '</select>';
		if($daval[2]==1)
		{
			echo $selval."&nbsp;";
		}else{
			echo $echoval;
		}
	}
}



