<?php

/**
 * 前台 城市地标 模块 Controller
 * ============================================================================
 * ZhunaCMS 住哪网酒店分销联盟程序php版　BY Tmac PHP MVC framework
 * $Author: zhaojianjun $  <zwttmac@qq.com>
 * $Id: lable.php 124 2012-01-11 16:45:32Z zhaojianjun $
 * http://union.zhuna.cn；
 */
class lableAction extends Action
{

    private $tmp_model;
    private $common_model;
    private $hotel_left_model;

    public function _init()
    {                       
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->assign('method',$_GET['TMAC_CONTROLLER']);
        $this->tmp_model = Tmac::model('lable');
        $this->common_model = Tmac::model('common');
        $this->hotel_left_model = Tmac::model('hotelLeft');
        //搜索块默认值
        $Searchinfo = $this->hotel_left_model->setLeftSearch();
        //设置SearchCookies$Searchinfo
        $sk_array = $this->hotel_left_model->getSearchCookies($Searchinfo);
        //取cityinfo
        $this->cityinfo = $this->hotel_left_model->getCityinfo();

        //footer里的相关设置
        $config_footer = $this->common_model->footer();
        $this->assign($config_footer);
        $this->assign('sk_array', $sk_array);
        $this->assign('cityinfo', $this->cityinfo);
    }

    public function index()
    {    
        $pid = empty($_GET['pid']) ? '0' : intval($_GET['pid']);  //pid
        $classid = empty($_GET['classid']) ? '0' : intval($_GET['classid']);  //classid
        //根据pid取city_ary
        $city_ary = array();
        if ($pid != 0) {
            $city_ary = $this->tmp_model->getCity('c', $pid);
        }              
        //title keywords description k_page(lable)
        $keywords_info = $this->hotel_left_model->getKeywordsInfo(8);
        $keywords_array = $keywords_info[1];
        $keywords_search = array('{doname}', '{cityname}');
        $keywords_replace = array("$keywords_info[0]", $this->cityinfo['cityname']);
        $keywords_array = str_replace($keywords_search, $keywords_replace, $keywords_array);
        $this->assign('keywords_array', $keywords_array);
        
        $this->assign('pid', $pid);
        $this->assign('classid', $classid);
        $this->assign('city_ary', $city_ary);        
        $this->V('lable');                
    }

    /**
     * ajax根据省pid 取下级city list
     */
    public function getCity()
    {
        $pid = empty($_POST['pid']) ? '0' : $_POST['pid'];  //pid
        $type = !empty($_POST['type']) ? $_POST['type'] : 'yes';

        if ($pid == 0) {
            $city_ary = array(
                array('cityid' => 53, 'cityname' => '北京'),
                array('cityid' => 321, 'cityname' => '上海'),
                array('cityid' => 343, 'cityname' => '天津'),
                array('cityid' => 394, 'cityname' => '重庆')
            );
        } else {
            $city_ary = $this->tmp_model->getCity('c', $pid);
        }
        //把缩写和名字组合在一起
        $city_array = array();
        foreach ($city_ary AS $k => $v) {
            $cityid = $v['cityid'];
            $cityname = $v['cityname'];
            $city_array[] = array('cityid' => $cityid, 'cityname' => $cityname);
        }
        $rs = json_encode($city_array);
        exit($rs);
    }

}