<?php

require_once('init.php');
$pid = getParam('pid');
$cityid = getParam('cityid');
if (empty($pid))
    $pid = 3;
$sql = "SELECT * FROM #@__city WHERE pid = $pid";
$city_arr = $db->getAll($sql);
if (empty($cityid))
    $cityid = $city_arr[0]['CityID'];

$sql = "SELECT * FROM #@__city WHERE cityid = $cityid";
$city_info = $db->getRow($sql);
//$cityname = $city_arr[$pid];
//var_dump($rs);
$city_array = array(
    "3" => "北京",
    "27" => "天津",
    "25" => "上海",
    "32" => "重庆",
    "18" => "辽宁",
    "15" => "吉林",
    "12" => "黑龙江",
    "10" => "河北",
    "23" => "山西",
    "16" => "江苏",
    "31" => "浙江",
    "2" => "安徽",
    "4" => "福建",
    "7" => "广西",
    "28" => "西藏",
    "20" => "宁夏",
    "5" => "甘肃",
    "6" => "广东",
    "8" => "贵州",
    "11" => "河南",
    "13" => "湖北",
    "14" => "湖南",
    "17" => "江西",
    "19" => "内蒙古",
    "21" => "青海",
    "22" => "山东",
    "24" => "陕西",
    "26" => "四川",
    "29" => "新疆",
    "30" => "云南",
    "9" => "海南",
    "33" => "香港",
    "34" => "澳门",
    "35" => "台湾",
);

//取默认8条城市酒店
$sql = "SELECT hotel_id,hotelname,picture,min_price,haoping,tags FROM #@__hotel WHERE cityid=$cityid AND min_price>0 ORDER BY px_index DESC LIMIT 0,8";
$city_eight_array = $db->getAll($sql);

/**
 * 计算满意度
 * @param <type> $haoping
 */
function manyidu($haoping)
{
    $hp_array = explode('$', $haoping);
    $CountHaoping = array_sum($hp_array);
    $haoping_good = $hp_array[0] + $hp_array[1];
    if ($CountHaoping == 0) {
        $myd = '100';
    } else {
        $myd = (int) (($haoping_good * 100) / $CountHaoping);
    }
    return $myd;
}

function getLable($cityid)
{
    $api_url = "http://union.api.zhuna.cn/api/utf-8/lable.asp?cityid=$cityid&classid=82&pg=1";    
    $xml_root = THISROOT . DIRECTORY_SEPARATOR . "xml" . DIRECTORY_SEPARATOR;
    $xml_name = "comment_{$cityid}.xml";
    createXML($api_url, $xml_root, $xml_name, 604800);
    $xmlstring = $xml_root . $xml_name;

    $dom = new DomDocument;
    $dom_load = @$dom->load($xmlstring);
    if ($dom_load) {
        $lable = $dom->getElementsByTagName("lable");
        $lable_ary = array();
        if ($lable->length > 0) {
            foreach ($lable as $k => $basexml) {
                $lable_ary[$k]['key'] = $basexml->getAttribute('key');
                $lable_ary[$k]['urlkey'] = urlencode($basexml->getAttribute('key'));
                $lable_ary[$k]['cityid'] = $basexml->getAttribute('cityid');
                $lable_ary[$k]['cityname'] = $basexml->getAttribute('cityname');
                $lable_ary[$k]['classid'] = $basexml->getAttribute('classid');
                $lable_ary[$k]['classname'] = $basexml->getAttribute('classname');
            }
        } else {
            $nofind_lable = "暂无此城市地标列表!";
        }
    } else {
        $nofind_lable = "暂无此城市地标列表!";
    }
    return $lable_ary;
}

$lable_array = @getLable($cityid);

$domain = 'http://'.$_SERVER['HTTP_HOST'].'/';

include template('index');
?>