<!--<?php
require_once(uTemplate::printEot('header'));
require_once(uTemplate::printEot('user_appleft'));
print<<<EOT
-->
<div class="contUser">
    <div class="p15">
		<h4 class="site"><img src="u/images/module/lightbulb.png" align="absmiddle" class="mr10" /><span>孔明燈</span></h4>           	
        <div class="navC">
					<a href="apps.php?q=kmd&a=help" class="fr mr10">孔明燈幫助</a>
					<ul>
							<li $current[info]><a href="{$basename}a=info"  hidefocus="true">我的孔明燈</a></li>
							<li $current[records]><a href="{$basename}a=records" hidefocus="true">購買記錄</a></li>
					</ul>
					<span class="btn_add fl"><span><button onclick="window.location.href='{$basename}a=buy'">購買孔明燈</button></span></span>
        </div>
<!--
EOT;
if ($a == 'info') {
print<<<EOT
-->
<!--
EOT;
if (S::isArray($unPayedInfos)) {
print<<<EOT
-->
	<div style="padding-top:10px;">
		<div style="padding:10px 25px;"><span class="b s2 mr10 f14">未支付提醒</span><span class="gray">（7天未支付將自動取消該申請）</span></div>
		<div style="padding:0 10px;">
			<div style="background:#fffeee;border:1px solid #d1d1ca;padding:0 10px 10px;">
				<table width="100%">
					<tr class="tr3 s5">
						<td width="30">序號</td>
						<td>推廣套餐</td>
                        <td>推廣版塊</td>
						<td>申請時間</td>
						<td>操作</td>
					</tr>
<!--
EOT;
$unPayedNum = 0;
foreach ($unPayedInfos as $value) {
$unPayedNum++;
if($value['fid']){
	$forumService = L::loadClass('Forums', 'forum');
	$forum = $forumService->getForum($value['fid']);
}
$spreadForum = $forum['name'] ? $forum['name'] : '未知版塊';
$tmpDiscount = (0 < $value['discount'] && $value['discount'] < 10) ? "<span class=\"s2\">$value[discount]</span>折" : '無折扣';
$spreadName = $value['name'] . ' <span class="s2">' . $value['price'] . "</span>元" . '/<span class="s2">' . $value['day'] . "</span>天 {$tmpDiscount}";
$appliedTime = get_date($value['createtime'], 'Y-m-d');
$actionName = $value['type'] == KMD_PAY_TYPE_ALIPAY ? "<a href=\"{$basename}a=buy&action=pay&pid=$value[id]\" class=\"s2\">支付</a>" : '待確認';
print<<<EOT
-->
	<tr class="tr3">
		<td class="tac">$unPayedNum</td>
		<td>$spreadName</td>
        <td><a href="thread.php?fid={$value['fid']}" target="_blank">$spreadForum</a></td>
		<td width="160">$appliedTime</td>
		<td width="100">$actionName</td>
	</tr>
<!--
EOT;
}print<<<EOT
-->
				</table>
			</div>
		</div>
	</div>
<!--
EOT;
}if (S::isArray($kmdInfos)) {print<<<EOT
-->
	<div style="padding:10px">
		<table width="100%">
			<tr class="tr3 bgA">
				<td width="46" class="tac">序號</td>
				<td>推廣帖子</td>
				<td>推廣版塊</td>
				<td>推廣時間</td>
				<td>操作</td>
			</tr>
<!--
EOT;
$kmdNum = ($page - 1) * $db_perpage;
foreach ($kmdInfos as $value) {
$kmdNum++;
switch($value['status']){
	case KMD_THREAD_STATUS_CHECK:
		$kmdTitle = "<a href=\"read.php?tid=$value[tid]\" target=\"_blank\">" . substrs($value['subject'], 60) . '</a>' . ' <span class="s2">(審核中)</span>';
		break;
	case KMD_THREAD_STATUS_REJECT:
		$kmdTitle = '<span class="s1">帖子未通過審核，請重新添加</span>';
		break;
	case KMD_THREAD_STATUS_OK:
		$kmdTitle = "<a href=\"read.php?tid=$value[tid]\" target=\"_blank\">" . substrs($value['subject'], 60) . '</a>';
		break;
	default:
		$kmdTitle = '暫無推廣帖子，請添加';
}
$leftTime = $value['endtime'] - $timestamp;
$leftDay = floor($leftTime / 86400);
$leftHour = floor(($leftTime - $leftDay * 86400) / 3600);
$leftTimeTip = $leftTime > 0 ? "剩余︰<span class=\"s2\">{$leftDay}天{$leftHour}小時</span>" : '已過期';
print<<<EOT
-->
	<tr class="tr3">
		<td class="tac">$kmdNum</td>
		<td>$kmdTitle</td>
		<td><a href="thread.php?fid=$value[fid]" target="_blank">$value[forumname]</a></td>
		<td width="160">$leftTimeTip</td>
		<td width="100">
			<a href="{$basename}a=buy&action=renew&kid=$value[kid]" class="mr10">續費</a>
<!--
EOT;
	if ($leftTime > 0){print <<<EOT
-->
<!--
EOT;
if (S::inArray($value['status'], array(KMD_THREAD_STATUS_EMPTY, KMD_THREAD_STATUS_REJECT))) {
print<<<EOT
-->
	<a href="javascript:;" onclick="addThread('$value[kid]');" class="s3">添加帖子</a>
<!--
EOT;
} elseif (S::inArray($value['status'], array(KMD_THREAD_STATUS_OK, KMD_THREAD_STATUS_CHECK))) {
print<<<EOT
-->
	<a href="javascript:;" onclick="addThread('$value[kid]', 'changethread');">換個帖子</a>
<!--
EOT;
}
}
print<<<EOT
-->
		</td>
	</tr>
<!--
EOT;
}print<<<EOT
-->
		</table>
	<div class="p10">{$numofpages}</div>
	</div>
<script type="text/javascript">
function addThread(kid, actions) {
	if (!kid) return false;
	if (!actions) actions = '';
	ajax.send(basename + 'a=addthread', 'kid=' + kid + '&action=' + actions, function(){
		var rText = ajax.request.responseText.split('\t');
		if (rText[0] == 'error') {
			showDialog('error', rText[1], 2);
		}
		ajax.get();
	});
}
</script>
<!--
EOT;
}} elseif ($a == 'records') {print<<<EOT
-->
	<table width="100%">
	 <tr class="tr3">
		<td width="13">&nbsp;</td>
		<td width="24">序號</td>
		<td>推廣版塊</td>
		<td width="160">支付狀態</td>
		<td width="160">推廣費用</td>
		<td width="160">購買時間</td>
	</tr>
<!--
EOT;
$recordsCount = ($page - 1) * $db_perpage;
if (S::isArray($records)) {
foreach ($records as $value) {
$recordsCount++;
$buyTime = get_date($value['createtime'], 'Y-m-d');
print<<<EOT
-->
	<tr class="tr3">
		<td width="13">&nbsp;</td>
		<td class="tac">$recordsCount</td>
		<td><a href="thread.php?fid=$value[fid]" target="_blank">$value[forumname]</a></td>
		<td width="160">{$kmdService->payStatus[$value['status']]}</td>
		<td width="160"><span class="s2">$value[money] 元</span></td>
		<td width="160">$buyTime</td>
	</tr>
<!--
EOT;
}}print<<<EOT
-->
	</table>
	<div class="p10">{$numofpages}</div>
<!--
EOT;
} elseif ($a == 'buy') {
$action == 'pay' && $divInfo = 'display:none;';
(!$action || $action == 'renew') && $divPay = 'display:none;';
print<<<EOT
-->
	<form name="buykmd" action="{$basename}a=buy&action=save" method="post">
<!--
EOT;
if ($action == 'renew') {
print<<<EOT
-->
	<input type="hidden" name="kid" value="$kid" />
<!--
EOT;
} elseif ($action == 'pay') {print<<<EOT
-->
	<input type="hidden" name="pid" value="$pid" />
<!--
EOT;
}print<<<EOT
-->
	<div style="padding:0 20px; $divInfo " id="info">
		<div style="padding:20px 5px 10px;" class="bdA"><span class="b s4 mr10 f14">推廣信息</span></div>
		<table width="100%">
			<tr class="tr3">
				<td width="80">推廣版塊︰</td>
				<td><select name="fid" id="fid" onchange="kmd.getLeftKmdNum(this, true);" $disabled>$kmdForumsHtml</select></td>
				<td><input type="hidden" name="fidvalidate" data-error="1" id="fidvalidate" value="" /></td>
			</tr>
			<tr class="tr3">
				<td style="vertical-align:top;">推廣套餐︰</td>
				<td>
<!--
EOT;
$spreadsOptions = '';
$firstOption = 0;
foreach ($spreads as $value) {
	if(preg_match('/^(\d+)\.00$/',$value['price'],$m)){
		$value['price'] = $m[1];
	} else if (preg_match('/^(\d+\.\d)0$/',$value['price'],$m)){
		$value['price'] = $m[1];
	}
	if (preg_match('/(\d)\.0$/',$value['discount'],$m)){
		$value['discount'] = $m[1];
	}
	$defaultOption = ++$firstOption == 1 ? 'checked' : '';
	$discount = (0< $value['discount'] && $value['discount'] < 10) ? "<span class=\"s2\">$value[discount]</span>折" : '&nbsp;';
	$spreadsOptions .= "<p class=\"mb10\"><label class=\"mr20 w\"><input name=\"spread\" type=\"radio\" style=\"margin:-3px 4px 0 0;\" value=\"$value[sid]\" $defaultOption />$value[name] <span class=\"s2\">$value[price]</span>元/<span class=\"s2\">$value[day]</span>天 {$discount}</label></p>";
}print<<<EOT
-->
					$spreadsOptions
				</td>
				<td></td>
			</tr>
		</table>
		<div style="padding:20px 5px 10px;" class="bdA"><span class="b s4 mr10 f14">聯系資料</span></div>
		  <table width="100%">
			<tr class="tr3">
				<td width="80">真實姓名<span class="s1">*</span></td>
				<td width="200"><input name="realname" id="realname" type="text" value="$userBuyInfo[realname]" class="input mr5 input_wa"/></td>
				<td><span class="gray">用于孔明燈審核聯系使用，請務必填寫正確</span></td>
			</tr>
			<tr class="tr3">
				<td>手機號碼<span class="s1">*</span></td>
				<td><input name="phone" id="phone" type="text" value="$userBuyInfo[phone]" class="input mr5 input_wa"/></td>
				<td><span class="gray">用于孔明燈審核聯系使用，請務必填寫正確</span></td>
			</tr>
			<tr class="tr3">
				<td>發票抬頭</td>
				<td><input name="invoice" type="text" value="$userBuyInfo[invoice]" class="input mr5 input_wa"/></td>
				<td><span class="gray">公司填寫企業名稱，個人填寫姓名</span></td>
			</tr>
			<tr class="tr3">
				<td>聯系地址</td>
				<td><input name="address" type="text" value="$userBuyInfo[address]" class="input mr5 input_wa"/></td>
				<td><span class="gray">填寫正確的聯系地址，用于發票寄送</span></td>
			</tr>
		   </table>
		<div class="tac p10"><span class="btn"><span><button onclick="return kmd.submitInfo();">去付款</button></span></span></div>
	</div>
	<div style="padding:0 20px; $divPay " id="pay">
		<div style="padding:20px 5px 10px;" class="bdA"><span class="b s4 mr10 f14">推廣信息</span></div>
		<table width="100%">
			<tr class="tr3">
				<td width="80">推廣版塊︰</td>
				<td><span id="foruminfo">$tmpForumInfo</span></td>
			</tr>
			<tr class="tr3">
				<td style="vertical-align:top;">推廣費用︰</td>
				<td><span id="fee">$tmpSpreadInfo</span></td>
			</tr>
		</table>
		<div style="padding:20px 5px 10px;" class="bdA mb15"><span class="b s4 mr10 f14">支付方式</span></div>
<!--
EOT;
if ($ol_onlinepay && $ol_payto) {
print<<<EOT
-->
			<div class="bdB mb15" style="padding:0 5px;">
				<p class="mb5"><em style="display:inline-block;width:25px;"><input name="paytype" type="radio" id="paytype1" value="1" $alipayChecked /></em><span class="f14 b s5"><label for="paytype1">支付寶（推薦）</label></span></p>
				<p class="gray mb10"><em style="display:inline-block;width:25px;">&nbsp;</em>支付寶支付方式，可供個人支付寶及企業支付寶支付。</p>
				<div class="bgA boxA s5" style="padding:10px 0;margin-bottom:20px;">
					<p class="mb5" style="padding-left:25px;">支付寶賬戶︰$ol_payto </p>
				</div>
			</div>
<!--
EOT;
}if ($db_kmd_account && $db_kmd_bank) {print<<<EOT
-->
			<div class="bdB mb15">
				<p class="mb5"><em style="display:inline-block;width:25px;"><input name="paytype" type="radio" id="paytype2" value="2" $bankChecked /></em><span class="f14 b s5"><label for="paytype2">銀行轉帳</label></span></p>
				<p class="gray mb10"><em style="display:inline-block;width:25px;">&nbsp;</em>企業單位支付方式，僅限企業間的轉賬支付。</p>
				<div class="bgA boxA s5" style="padding:10px 0;margin-bottom:20px;">
					<p class="mb5" style="padding-left:25px;">開&nbsp;戶&nbsp;行︰$db_kmd_bank</p>
					<p class="mb5" style="padding-left:25px;">公司名稱︰$db_kmd_company</p>
					<p style="padding-left:25px;">銀行賬戶︰$db_kmd_account</p>
				</div>
			</div>
<!--
EOT;
}if ($db_kmd_address) {print<<<EOT
-->
			<div class="bdB mb15">
				<p class="mb5"><em style="display:inline-block;width:25px;"><input name="paytype" type="radio" id="paytype3" value="3" $cashChecked /></em><span class="f14 b s5"><label for="paytype3">現金</label></span></p>
				<p class="gray mb10"><em style="display:inline-block;width:25px;">&nbsp;</em>在以上2種方式都不能實現的情況下，攜帶現金到現場辦理手續。</p>
				<div class="bgA boxA s5" style="padding:10px 0;margin-bottom:20px;">
					<p style="padding-left:25px;">辦理地址︰$db_kmd_address</p>
				</div>
			</div>
<!--
EOT;
}
$db_kmd_phone && $db_kmd_phone = "聯系電話︰$db_kmd_phone";
$db_kmd_mobile && $db_kmd_mobile = "手機︰$db_kmd_mobile";
$db_kmd_aliww && $db_kmd_aliww = "旺旺︰$db_kmd_aliww";
$db_kmd_qq && $db_kmd_qq = "QQ︰$db_kmd_qq";
print<<<EOT
-->
			<div class="spaceTip s5 mb20" style="padding:10px 30px;line-height:1.8;">
				<p>支付成功後請電話聯系網站工作人員進行確認，確保您的申請及時受理。</p>
				<p> $db_kmd_phone $db_kmd_mobile $db_kmd_aliww $db_kmd_qq</p>
			</div>
<!--
EOT;
if ($action != 'pay') {
print<<<EOT
-->
			<div class="tac p10"><span class="bt"><span><button onclick="return kmd.init('info');">上一步</button></span></span><span class="btn"><span><button type="submit">提交</button></span></span></div>
<!--
EOT;
} else {print<<<EOT
-->
			<div class="tac p10"><span class="btn"><span><button type="submit">提交</button></span></span></div>
<!--
EOT;
}print<<<EOT
-->
		</div>
	</form>
<script type="text/javascript">
var action = '$action';
var basename = '$basename';
var jsonSpreads = JSONParse('$jsonSpreads');
var kmd = {
	'init' : function(type) {
		type = type || action;
		if (type == 'pay') {
			getObj('info').style.display = 'none';
			getObj('pay').style.display = '';
		} else {
			getObj('info').style.display = '';
			getObj('pay').style.display = 'none';
		}
		return false;
	},
	'getLeftKmdNum' : function(obj, show) {
		var fid = parseInt(obj.value);
		if (fid <= 0) return false;
		ajax.send(basename + 'a=ajax', 'fid=' + fid + '&action=' + action, function(){
			var rText = ajax.request.responseText.split('\t');
			if (rText[0] == 'error') {
				getObj('fidvalidate').value = rText[1];
				getObj('fidvalidate').setAttribute('data-error', 1);
				show && showDialog('error', rText[1], 2);
			} else if (rText[0] == 'success') {
				if (rText[1] == 0) {
					getObj('fidvalidate').value = '該版塊孔明燈已售完，請嘗試其他版塊！';
					getObj('fidvalidate').setAttribute('data-error', 1);
					show && showDialog('error', '該版塊孔明燈已售完，請嘗試其他版塊！', 2);
				} else {
					getObj('fidvalidate').setAttribute('data-error', 0);
					getObj('fidvalidate').value = rText[1];
				}
			}
		});
	},
	'submitInfo' : function() {
		var _this = this;
		var fidvalidate = getObj('fidvalidate');
		var fidValid = fidvalidate.getAttribute('data-error');
		if (fidValid == 1) {
			var info = fidvalidate.value;
			showDialog('error', info, 2);
			return false;
		}
		if (getObj('realname').value == '') {
			showDialog('error', '請填寫真實姓名', 2);
			return false;
		}
		if (getObj('phone').value == '') {
			showDialog('error', '請填寫手機號碼', 2);
			return false;
		} else if (!/^1\d{10}$/.test(getObj('phone').value)) {
			showDialog('error', '手機號碼格式不正確', 2);
			return false;
		}
		var forum = getObj('fid');
		var fname = fidvalidate.value;
		if (!fname || fname == 1) fname = this.getSelectedFname(forum);
		getObj('foruminfo').innerHTML = '<a href="thread.php' + '?fid=' + forum.value + '" target="_blank">' + fname + '</a>';
		var spread = _this.getSpread();
		var spreadInfo;
		for (var i in jsonSpreads) {
			if (jsonSpreads[i].sid == spread) {
				spreadInfo = jsonSpreads[i];
			}
		}
		if (spreadInfo) {
			var discount = (0 < spreadInfo.discount && spreadInfo.discount < 10) ? spreadInfo.discount + '折' : '無折扣';
			var money = (0 < spreadInfo.discount && spreadInfo.discount < 10) ? (spreadInfo.price * spreadInfo.discount / 10) : spreadInfo.price;
			money = Number(money).toFixed(2);
			getObj('fee').innerHTML = '原價 ' + spreadInfo.price + '元，<span class="s2">' + discount + '</span>，應付 <span class="s2">' + money + '元</span>';
		}
		_this.init('pay');
		return false;
	},
	'getSpread' : function() {
		var spread = document.buykmd.spread;
		for (var i = 0, len = spread.length; i < len; i++) {
			if (spread[i].checked) return spread[i].value;
		}
	},
	'getSelectedFname' : function(obj){
		for(var i=0; i<obj.length; i++){
			if (obj.value == obj[i].value){
				var fname = obj[i].text;
				fname = fname.replace('|-','');
				fname = fname.replace(/^\s+/ig,'');
				return fname;
			}
		}
		return '';
	}
};
setTimeout(function(){
	kmd.getLeftKmdNum(getObj('fid'), false);
}, 100);
</script>
<!--
EOT;
}print<<<EOT
-->
    </div>
</div>
<!--
EOT;
require_once(uTemplate::printEot('footer'));
?>