<?php
	require_once("init.php");
	require_once("HttpClient.class.php");

	libxml_use_internal_errors(true); // Disable libxml errors and allow user to fetch error information as needed
	
	$client = new HttpClient($apihost);
	$client->max_redirects = 50;

	//加载商店配置
	$url	= 'http://b2b.dong24.com/api/dw/custInfo.jsp?custId=122137';
	
	if ( ! $client->get($url)) {
		redir('/'. $base_api_dir .'/', '服务器错误！');
		exit();
	}
	try{
		$shopconfig	= new SimpleXMLElement($client->getContent());
	} catch (Exception $e){
		redir('/'. $base_api_dir .'/', '文件解析失败');
		exit();
	}

	// 默认按照销量排序
	$url	= $prefix_dir . '/list.jsp?custId='.$cust_id.'&apikey='.$apikey.'&pageNum=10&orderBy=2';
	if ( ! $client->get($url)) {
		redir('/'. $base_api_dir .'/', '服务器错误！');
		exit();
	}

	try{
		$proXml = new SimpleXMLElement($client->getContent());
	} catch (Exception $e){
		redir('/'. $base_api_dir .'/', '文件解析失败');
		exit();
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?php echo $shopconfig->cust->siteName ?></title>
	<link href="/public/css/header.css" type="text/css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" media="screen" href="./css/mp-gl.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="./css/holiday.css" />
	<link rel="shortcut icon" href="/favicon.ico" />
	<script type="text/javascript" src="/public/js/jquery.js"></script>
	<script type="text/javascript" src="/public/js/dsport.core.js"></script>
    <script type="text/javascript" src="/public/js/jquery.fancybox.js"></script>
	<script src="./js/area.js" type="text/javascript"></script>
	<style type="text/css">
		table td span {float: left};
	</style>
</head>
<body>
	<!-- 头部:S -->
		<?php echo $shopconfig->cust->siteHead ?>
	<!-- 头部:E -->
	
	<!-- 面包屑:S -->
		<div class="mp-bread">
			<p class="mp-recom">当前位置：门票</p>
		</div>
	<!-- 面包屑:E -->

	<div class="mp-wrap">
			<div class="mp-col-left">
				<div class="mp-box-default">
					<div class="t">
						<h2 class="mp-fb">我要门票</h2>
						<b>目前<?php echo $mp_site_name ?>已有全国各地景点门票可以优惠预订，门票折扣二折起！</b>
					</div>
					<div class="c" style="padding:7px 5px;overflow: hidden;">
						<form action="list.php" method="get" name="f1" id="f1">
							<table width="100%" border="0" cellpadding="0" cellspacing="3" class="mp-tbl-search">
								<tr>
									<td width="5%">&nbsp;</td>
									<td width="25%">省份</td>
									<td width="25%">城市</td>
									<td width="35%">产品搜索</td>
									<td width="18%">&nbsp;</td>
									<td width="5%">&nbsp;</td>
								</tr>
								<tr>
									<td>&nbsp;</td>
									<td>
										<div class="sel138">
											<select id="provid" onchange="changearea(this.value,document.getElementById('cityid'));document.getElementById('prov_id').value=this.value;">
												<option>=省份=</option>
											</select>
										</div>
									</td>
									<td>
										<div class="sel138">
											<select id="cityid" onchange="document.getElementById('prov_id').value=this.value;">
												<option value="">=地区=</option>
											</select>
										</div>
									</td>
									<td>
										<div class="field273">
											<input name="keyWrod" type="text" id="keyword" value="<?php echo isset($_GET['keyWrod']) ? $_GET['keyWrod'] : '' ?>" hover="产品名称、景区名称">
										</div>
									</td>
									<td align="left">
										<input name="Input" class="fast" type="button" value="" onclick="sub();">
										<input type="hidden" name="cityName" id="prov_id" value="<?php echo isset($_GET['lid']) ? $_GET['lid'] : '' ?>">
									</td>
									<td align="left">&nbsp;</td>
								</tr>
							</table>
						</form>
						<div class="mp-cp">
							<div class="mp-tbl-cp-s">
								<table border="0" cellspacing="0" cellpadding="0">
									<tr>
										<td width="10%" align="right"><strong class="c9">热门地区：</strong></td>
										<td colspan="2">
											<?php
												$url = '/api/city.jsp?&custId='.$cust_id.'&apikey='.$apikey.'&pageNo=1&pageNum=15';
												if ( ! $client->get($url) ){
													echo '服务器错误！';
													exit();
												}
												try{
													$xmlDom = new SimpleXMLElement($client->getContent()); // sometimes don't forget to trim xml blank
												} catch (Exception $e){
													echo '文件解析失败';
													exit();
												}

												foreach($xmlDom->citys->city as $city){
													echo '<span class="h_city"><a href="list.php?cityName='.$city->cityName.'&lid='.$city->cityId.'">'.$city->cityName.'</a>['.$city->ticketNum.']</span>';
												}

											?>
										</td>
									</tr>
									<tr>
										<td width="76" align="right"><strong class="c9">热门分类：</strong></td>
										<td colspan="2">
											<?php
												$url = '/api/tag.jsp?custId='.$cust_id.'&apikey='.$apikey;
												if ( ! $client->get($url) ){
													echo '服务器错误！';
													exit();
												}
												try{
													$xmlDom = new SimpleXMLElement($client->getContent()); // sometimes don't forget to trim xml blank
												} catch (Exception $e){
													echo '文件解析失败';
													exit();
												}

												echo '<span><a class="bc" href="list.php">全部</a></span>';
												$counter = 0;
												foreach($xmlDom->tags->tag as $tag){
													if ($counter > 200)
														break;
													$counter ++;
													echo '<span><a href="list.php?tagIds='.$tag->tagId.'">'.$tag->tagName.'</a></span>';
												}
											?>
										</td>
									</tr>
									<tr>
										<td width="10%" align="right"><strong>支付方式：</strong></td>
										<td width="550">
											<a class="bc" href="list.php">全部</a><a href="list.php?isPay=1">在线支付</a><a href="list.php?isPay=0">售票窗口现付模式</a>
										</td>
										<td width="60">&nbsp;</td>
									</tr>
								</table>
							</div>
						</div>
					</div>
				</div>
				<div class="mp-box-list">
					<div class="t">
						<h2>热销门票</h2>
						<b><a href="list.php">更多&gt;</a></b>
					</div>
					<div style="padding:0;" class="c">
						<ul class="mp-search-list">
							<?php foreach($proXml->products->product as $product){ ?>
								<li>
									<div class="left mp-list-img-c" style="height:100%;overflow:hidden">
										<dl>
											<dt>
												<a href="" target="_blank">
													<img width="145" height="88" alt="<?php echo $product->productName ?>" src="<?php echo check_default_img($product->img) ?>" style="display: inline;">
												</a>
											</dt>
											<dd style="height:100%;overflow: hidden;padding:5px 0;">
												<div style="width:70px; ">
													￥
													<span style="font-size:16px ; color:#FF6600; font-weight:600;">
														<?php echo $product->salePrice ?>
													</span>
												</div>
												<div>折扣：<span style="color:#FF6633"><?php echo getZK($product->marketPrice, $product->salePrice) ?></span>折</div>
												<div style="width:70px;"><span style="text-decoration:line-through; color:#999;">￥<?php echo $product->marketPrice ?></span></div>
												<div>直降：￥<span style="color:#009933;"><?php echo ($product->marketPrice - $product->salePrice) ?></span></div>
											</dd>
										</dl>
									</div>
									<div class="right">
										<a href="<?php echo $server_url ?>/order.php?info_id=<?php echo $product->productNo.'&user_id='.$user_id ?>" target="_blank" class="mp2_btna normal_mp" title=""></a>
										<h5 class="mp2_h">
											<a class="mp-f-14 c004fb1" title="<?php echo $product->productName ?>" target="_blank" href="<?php echo '/piao/'.$product->productNo.'.html' ?>">
												<?php echo $product->productName ?>
											</a>
										</h5>
										<p class="mp2_p">
											<span class="c6">已成功预订：</span>
											<span class="red"><?php echo $product->ticketCount + $product->attentCount ?></span>张 <br />
											配送方式：<span class="c6 mp2_ico1"><?php echo $product->express ?></span><br />
											预订说明：<?php echo $product->orderDesc ?><br />
										</p>
									</div>
								</li>
							<?php
								}
							?>
						</ul>
					</div>
				</div>
			</div>
			<div class="mp-col-right">
				<div class="mp-sep-block">
					<div class="t">
						<h2>门票订单查询</h2>
					</div>
					<div class="c" style="padding:10px; border-top:none">
						<form action="http://www.dongsport.com/128457/complete.php" name="f2" id="f2">
							<table width="100%" cellspacing="0" cellpadding="0" border="0">
								<tbody>
									<tr>
										<td width="42">订单号</td>
										<td width="105"><input type="text" id="order_id" name="order_id"></td>
										<td width="71" align="right" rowspan="3"><a href="javascript:;" onclick="subOrder();"><img width="49" height="48" src="images/sorder.gif"></a></td>
									</tr>
									<tr>
										<td height="5" colspan="2"></td>
										</tr>
									<tr>
										<td>手&nbsp;&nbsp;&nbsp;机</td>
										<td><input type="text" id="phone" name="phone"></td>
										</tr>
								</tbody>
							</table>
						</form>
					</div>
				</div>
				<div class="mp-sep-block">
					<div class="t">
						<h2>精品门票大超市</h2>
					</div>
					<div class="c">
						<?php
							$url = $prefix_dir . '/list.jsp?custId='.$cust_id.'&apikey='.$apikey.'&pageNum=6&pageNo=1&type=1';
							if ( ! $client->get($url) ){
								redir('/'. $base_api_dir .'/', '服务器错误！');
								exit();
							}
							try{
								$proXml = new SimpleXMLElement($client->getContent()); // sometimes don't forget to trim xml blank
							} catch (Exception $e){
								redir('/'. $base_api_dir .'/', '文件解析失败');
								exit();
							}

							if($proXml->totalNum > 0 ){
								echo '<div class="mp-b-m">
										<div class="h">
											<div class="left cc60">好礼赠送</div>
										</div>
										<div class="n" style="padding-top:0; padding-bottom:0">
											<ul class="mp-pro-l">';
											foreach($proXml->products->product as $product){
												echo'<li><a class="c004fb1 mp-f12" href="/piao/'.$product->productNo.'.html" target="_blank">'.$product->productName.'</a> <span class="price cf60"> <span class="fht">¥</span>'.$product->salePrice.'</span></li>';
											}
											echo'
											</ul>
										</div>
									</div>';
							}
						?>
					</div>
				</div>
			</div>
		</div>

	<!-- 底部:S -->
		<?php echo $shopconfig->cust->siteFoot ?>
	<!-- 底部:E -->
	
	<script type="text/javascript">
		function checkLogin() {
			$.ajax({ url: '/sync/login/checkIn',data: '',dataType: 'html',
				success: function(data) {
					$("#loginbar").append(data).find('.cklinit').remove();
					$("a[rel=login]").unbind('click').fancybox({
						'width': '40',
						'height': '30',
						'padding': '0',
						'type': 'iframe',
						'autoDimensions': false,
						'scrolling': 'no'
					});
				}
			});
		}
		function locate() {
			$.ajax({url: '/sync/city/locate',data: '',dataType: 'html',success: function(data) {
					if (data !== '') {
						$("#citylocate").html(data);
					}
				}
			});
		}
	</script>
	<script language="javascript" type="text/javascript">
		checkLogin();
	</script>
	<script type="text/javascript">
		$(function(){
			var provobj=document.getElementById('provid');
			for (i=0; i<proary.length; i++)
			{
				provobj.options[provobj.length] = new Option(proary[i][1], proary[i][0]);
			}
			if ($('#prov_id').val() != ''){
				if($.trim($('#prov_id').val()).length > 5)
				{
					provobj.value = $('#prov_id').val().substring(0,5);
					changearea($('#prov_id').val().substring(0,5),document.getElementById('cityid'));
					$('#cityid').val($('#prov_id').val());
				}
				else
				{
					provobj.value=$('#prov_id').val();
					changearea($('#prov_id').val(),document.getElementById('cityid'));
				}
			}
		})

		function sub(){
			if($('#keyWrod').val()=='产品名称、景区名称'){
				$('#keyWrod').val('');
			}

			var lid = ''; // city location id
			var ln  = ''; // city name
			var provid = $("#provid").val();
			if ($("#provid").val())
			{
				lid = provid;
				if (lid)
				{
					ln = $("#provid").children("option:selected").text();
					console.log(ln);
				}
			}
			var cityid = $("#cityid").val();
			if (cityid)
			{
				lid = cityid;
				if (lid)
				{
					ln = $("#cityid").children("option:selected").text();
					console.log(ln);
				}
			}
			if ( ! /^[\d]{5,7}$/.test(lid))
			{
				lid = '';
			}
			$('<input type="hidden">').attr({name:'lid', value:lid}).appendTo($("#f1"));

			$("#prov_id").val(ln);
			$('#f1').submit();
		}
		function subOrder(){
			if($('#order_id').val()==''){
				alert('订单号不能为空');
				return;
			}
			if($('#phone').val()==''){
				alert('手机号码不能为空');
				return;
			}
			$('#f2').submit();
		}
		$(function (){
			$(".city-bottom").bind({'mouseover':function(){  
				$('.cityLine').show();
			}, 'mouseout':function(){
				$('.cityLine').hide();
			}});
		});
	</script>
	<script type="text/javascript">
		var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
		document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F81abdadfb5d3537c41730c6e6e304eff' type='text/javascript'%3E%3C/script%3E"));
	</script>

</body>
</html>