<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
/**
 *----------------------------------------------------------------------------
 * 版权所有 2010-2016 HuCart.COM，并保留所有权利。
 * 网站地址: http://Www.HuCart.Com；
 * 作者: HuCart.COM
**/
class Ajax_area  extends HC_Controller
{
	//注意无须构造函数,使用了构造函数得重构父类 parent::__construct();
 
	function __construct()
	{
		parent::__construct();	
		$this -> load_lang('adminsys/ajax_area');
		//$this -> view -> assign('master_act', $this -> master_act);
		//$this -> view -> assign('info_prefix',	$this -> info_prefix);
		$this -> load('admin');
		$this -> admin -> online_admin();
		$this -> load_db();
		//$this -> load('helper');     //加载辅助类
		//$this -> load_model('sort'); //加载分类模型
	}
	
	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;
		}
	}
}



