<!--<?php
include_once PrintEot('left');
if($action == 'add' || $action == 'edit'){
print <<<EOT
-->
<div class="mb10 nav3">
<ul id="basictype" class="cc">
	<li><a href="$basename">廣告管理</a></li>
	<li class="current"><a href="$basename&action=add">添加廣告</a></li>
</ul>
</div>
<script type="text/javascript">
function getObj(id){
	return document.getElementById(id);
}
function showSelHtml(d,s) {
	if(s) getObj(d).innerHTML = getObj(s).innerHTML;
	else getObj(d).innerHTML = '';
}
</script>
<script type="text/javascript" src="js/date.js"></script>
<script type="text/javascript" src="js/color_picker.js" ></script>
<form method="post" name="FORM" action="$basename&action=save&">
<input type="hidden" name="id" value="$id">
<h2 class="h1">添加廣告</h2>
<div class="admin_table mb10">
<table width="100%" cellspacing="0" cellpadding="0">
	<tr class="tr1 vt">
		<td class="td1">選擇表現方式</td>
		<td class="td2">
			<ul class="list_A list_80">
				<li><input type="radio" name="config[type]" value="txt" onclick="showSelHtml('adSet','adtxt')" $type_txt /> 文字</li>
				<li><input type="radio" name="config[type]" value="img" onclick="showSelHtml('adSet','adimg')" $type_img /> 圖片</li>
			</ul>
		</td>
	</tr>
	<tr class="tr1 vt">
		<td class="td2" colspan="2" style="padding:0;border-bottom:0;"><div id='adSet'></div></td>
	</tr>
	<tr class="tr1 vt">
		<td class="td1">廣告描述</td>
		<td class="td2"><input type="text" class="input input_wa" size="70" name="advert[descrip]" value="$advert[descrip]"></td>
	</tr>
	<tr class="tr1 vt">
		<td class="td1">選擇廣告位</td>
		<td class="td2">
			<select class="select_wa" id="advert_ckey" name="advert[ckey]" onchange="showSelCate(this.options[this.selectedIndex].value)">$optCates</select>
			<span class="gray" id="cateDescrip"></span>
		</td>
	</tr>
	<tr>
		<td colspan="2"><div id="winSet" style="padding-left:3em;"></div></td>
	</tr>
	<tr class="tr1 vt">
		<td class="td1">&nbsp;</td>
		<td class="td2"><span>廣告展示的位置由廣告位和所設置的廣告範圍決定,‘Ctrl’或‘Shift’鍵進行多選</span><br />
			<div id="pageSet" style="float:left;margin-right:1em;"></div>
			<div id="forumSet" style="float:left;margin-right:1em;"></div>
		</td>
	</tr>
	<tr class="tr1 vt">
		<td class="td1">顯示順序</td>
		<td class="td2"><input type="text" class="input input_wc" name="advert[orderby]" value="$advert[orderby]" size="5">
			<span class="gray">默認順序為“0”</span>
		</td>
	</tr>
	<tr class="tr1 vt">
		<td class="td1">是否上架</td>
		<td class="td2"><div class="list_A list_80">
			<ul class="cc"><li><input type="radio" name="advert[ifshow]" value="1" $ifshow_Y >是</li>
			<li><input type="radio" name="advert[ifshow]" value="0" $ifshow_N >否</li></ul>
			<span class="gray">上架後,廣告位同時被開啟</span></div>
		</td>
	</tr>
	<tr class="tr1 vt">
		<td class="td1">有效時間</td>
        <td class="td2">
        	<div class="input_img">
        	<i class="input_time">選擇時間</i>
        	<input type="text" name="advert[stime]" id="starttime" value="$advert[stime]" onClick="setAdvert.initDate(this.id);" /></div>
			至
			<div class="input_img"><i class="input_time">選擇時間</i><input type="text" name="advert[etime]" id="endtime" value="$advert[etime]" onClick="setAdvert.initDate(this.id);" /></div>
			<span class="gray">格式︰yyyy-mm-dd</span>
		</td>
	</tr>
</table>
</div>
<div class="mb10 tac"><span class="btn"><span><button type="submit">提 交</button></span></span></div>
</form><br />
<div style="display:none;" id="c_page" >
<select name="pages[]" size="16" style="margin:2px;" multiple>
	<option value="page" $selThread_page >&nbsp;&gt;&gt;所有頁面 </option>
	<option value="" disabled></option>
	<option value="index" $selThread_index >&nbsp;&raquo; WAP首頁</option>
	<option value="thread" $selThread_thread >&nbsp;&raquo; 主題列表</option>
	<option value="read" $selThread_read >&nbsp;&raquo; 帖子頁面</option>
</select></div>
<div style="display:none;" id="c_forum" >
<select name="fids[]" size="16" style="margin:2px;" multiple>
	<option value="-1" $selFids_all>&nbsp;&gt;&gt;所有版塊</option>
	<option value="" disabled></option>
	$forumcache
</select></div>
<div id="adtxt" style="display:none;">
	<h2 class="h1" style="border-top:0 none;">文字廣告</h2>
	<table width="100%" cellspacing="0" cellpadding="0">
		<tr class="tr1 vt">
			<td class="td1">文字內容<span style="color:red">*</span></td>
			<td class="td2"><input type="text" class="input input_wa" name="config[title]" value="$config[title]"></td>
		</tr>
		<tr class="tr1 vt">
			<td class="td1">文字鏈接<span style="color:red">*</span></td>
			<td class="td2"><input type="text" class="input input_wa" name="config[link]" value="$config[link]"> <span class="gray">外鏈以http://開頭</span></td>
		</tr>
		<tr class="tr1 vt">
			<td class="td1">文字顏色</td>
			<td class="td2">
			<div class="input_img fl mr5"><i title="選擇顏色" class="input_color" onclick="showColorPicker(this,'color',function(){pickReback('color_s',color_picker)})">選擇顏色</i>
			<input type="text" name="config[color]" value="$config[color]" id="color"></div>
			<span id='color_s' style="background:$bgcolor;width:50px;height:22px;border:1px solid #aaa;" class="fl"></span>
			</td>
		</tr>
	</table>
</div>
<div id="adimg" style="display:none;">
	<script src="js/desktop/adminadvert.js"></script>
	<h2 class="h1" style="border-top:0 none;">圖片廣告</h2>
	<table width="100%" cellspacing="0" cellpadding="0" id="imglist">
		<tr class="tr1 vt">
			<td class="td1">圖片地址<span style="color:red">*</span> </td>
			<td class="td2"><input type="text" class="input input_wa" name="config[url][1]" value="$config[url]"> <span class="gray">外鏈以http://開頭</span></td>
		</tr>
		<tr class="tr1 vt">
			<td class="td1">圖片鏈接<span style="color:red">*</span> </td>
			<td class="td2"><input type="text" class="input input_wa" name="config[link][1]" value="$config[link]"> <span class="gray">外鏈以http://開頭</span></td>
		</tr>
		<tr class="tr1 vt">
			<td class="td1">圖片大小</td>
			<td class="td2">
				寬︰<input type="text" class="input input_wc" name="config[width]" value="$config[width]" />
				高︰<input type="text" class="input input_wc" name="config[height]" value="$config[height]" /> <span class="gray">例如: 98% 或 120像素</span>
			</td>
		</tr>
	</table>
</div>
<script src="js/pw_ajax.js"></script>
<script type="text/javascript">
function showSelCate(ckey) {
	ckey=ckey.toLowerCase();
	showSelHtml('pageSet','');
	showSelHtml('forumSet','');
	if (ckey) {
		cateDescrip(ckey);
		if (ckey.indexOf('wap.read') != -1) {
			showSelHtml('forumSet','c_forum');
		}else if (ckey.indexOf('wap.') != -1) {
			showSelHtml('pageSet','c_page');
			showSelHtml('forumSet','c_forum');
		}
	}
}
function cateDescrip(ckey) {
	var descrip = JSONParse('$cateDescrip');
	if (typeof descrip[ckey] != 'undefined')
		getObj('cateDescrip').innerHTML = descrip[ckey];
	else
		getObj('cateDescrip').innerHTML = '';
}
var setAdvert = {
    handler : '',
    //init
    initDate : function(id){
        ShowCalendar(id);
        setAdvert.handler = setInterval(function(){
            setAdvert.checkDate(setAdvert.handler);
        },1000);
    },

    checkDate : function(){
        var starttime = getObj("starttime").value;
        var endtime = getObj("endtime").value;
        if(endtime == "" || starttime == ""){
            return false;
        }
        var startD  = new Date(Date.parse(starttime.replace(/-/g,"/")));
        var endD = new Date(Date.parse(endtime.replace(/-/g,"/")));
        if(startD-endD>0){
            getObj("endtime").value = "";
            alert("抱歉，結束時間不能小于開始時間");
            return false;
        }
        var startArray = starttime.split("-");
        var endArray = endtime.split("-");
        //not the same year
        if(startArray[0]<endArray[0]){
            return false;
        }
        //two month
        if(endArray[1]-startArray[1] <=2){
            var dateRange = setAdvert.getDateRange(starttime,endtime);
            //setAdvert.disableDate(dateRange.days);
            //setAdvert.disableWeek(dateRange.weeks);
        }
        if(endArray[1]==startArray[1] && endArray[2]==startArray[2]){
            //
        }
        showddate(starttime,endtime);
        clearInterval(setAdvert.handler);
    },

    getDateRange : function(starttime,endtime){
        var unit_day = 86400*1000;
        var startT = Date.parse(starttime.replace(/-/g,"/"));
        var endT = Date.parse(endtime.replace(/-/g,"/"));
        var startN = startT+unit_day;
        var dateArray = [];
        var weekArray = [];
        for(i=startT;i<=endT;i+=unit_day){
            var startND = new Date(i);
            var td = startND.getDate();
            var wd = startND.getDay();
            dateArray.push(td);
            weekArray.push(wd);
        }
        return {days:dateArray,weeks:weekArray};
    },

    disableDate : function(valids){
        var ddate = getObj("ddate_id").getElementsByTagName("input");
        for(i=0;i<ddate.length;i++){
            var value = ddate[i].value;
            if(valids.indexOf(value) == -1){
                ddate[i].disabled = "disabled";
            }
        }
    },

    disableWeek : function(valids){
        var dweek = getObj("dweek_id").getElementsByTagName("input");
        for(i=0;i<dweek.length;i++){
            var value = dweek[i].value;
            if(valids.indexOf(value) != -1){
                dweek[i].disabled = "disabled";
            }
        }
    },

    disableTime : function(valids){
        var dtime = getObj("dtime_id").getElementsByTagName("option");
        for(i=0;i<dtime.length;i++){
             var value = dtime[i].value;
             if(valids.indexOf(value) != -1){
                dtime[i].disabled = "disabled";
             }
        }
    }

}
showSelHtml('adSet','ad{$config[type]}');
showSelCate(getObj('advert_ckey').value);
</script>
<!--
EOT;
}
elseif(empty($action) || $action == 'search'){
${'_advertype_'.$advertype} = in_array($advertype,$advertypes) ? 'selected' : '';
${'_state_'.$state} = in_array($state,array('0','1')) ? 'selected' : '';
print <<<EOT
-->
<div class="mb10 nav3">
<ul id="basictype" class="cc">
	<li class="current"><a href="$basename">廣告管理</a></li>
	<li><a href="$basename&action=add">添加廣告</a></li>
</ul>
</div>
<h2 class="h1">搜索</h2>
<div class="admin_table mb10">
<form action="$basename" method="post">
<table width="100%" cellspacing="0" cellpadding="0">
<tr class="tr3">
	<td><select name="ckey" class="select_wa mr10"><option value="">廣告位</option>$optCates</select><select name="advertype" class="select_wa mr10"><option value="">類型</option><option value="img" $_advertype_img>圖片</option><option value="txt" $_advertype_txt>文字</option></select><select name="state" class="select_wa mr10"><option value="">狀態</option><option value="1" $_state_1>上架</option><option value="0" $_state_0>下架</option></select>關鍵字︰<input type="text" class="input input_wa mr10" name="keyword" value="$keyword"/><span class="btn2"><span><button type="submit">搜 索</button></span></span></td>
</tr>
</table>
</form>
</div>
<div class="c"></div>
<h2 class="h1">廣告管理</h2>
<div class="admin_table mb10">
<form name="listform" action="$basename" method="post">
<table width="100%" cellspacing="0" cellpadding="0">
	<tr class="tr2">
		<td width="5%" class="tac"><a onclick="CheckAll(document.listform)" style="cursor:pointer;">全選</a></td>
		<td width="5%" class="tac">順序</td>
		<td>描述</td>
		<td width="7%">類型</td>
		<td width="15%">廣告位</td>
		<td width="12%">結束時間</td>
		<td width="10%">狀態</td>
		<td style="60">操作</td>
	</tr>

<!--
EOT;
if($adverts){
foreach ($adverts as $value){
print <<<EOT
-->
	<tr class="tr1 vt">
		<td class="td2 tac"><input type="checkbox" name="selid[]" value="$value[id]" /></td>
		<td class="td2 tac">{$value['orderby']}</td>
		<td class="td2"><a href="$basename&job=edit&id=$value[id]">{$value['descrip']}</a></td>
		<td class="td2">
<!--
EOT;
if($value['config']['type'] == 'txt'){print <<<EOT
-->
		文字
<!--
EOT;
}elseif($value['config']['type'] == 'img'){print <<<EOT
-->
		圖片
<!--
EOT;
}print <<<EOT
-->
		</td>
		<td class="td2">
<!--
EOT;
if (!isset($cates[$value['ckey']])) {print <<<EOT
-->
		<font color=red>廣告位不存在</font>
<!--
EOT;
}else{print <<<EOT
-->

		<a href="$basename&ckey={$value['ckey']}" >{$cates[$value['ckey']]['name']}</a>
<!--
EOT;
}print <<<EOT
-->
		</td>
		<td class="td2">{$value['etime']}</td>
		<td class="td2">
<!--
EOT;
if(!$cates[$value['ckey']]['ifshow']){print <<<EOT
-->
			廣告位關閉
<!--
EOT;
}elseif($value['ifshow'] == 1){print <<<EOT
-->
			已上架
<!--
EOT;
}elseif($value['uid'] && $value['ifshow'] == -1){print <<<EOT
-->
			<font color=red>未驗證</font>
<!--
EOT;
}else{print <<<EOT
-->
			已下架
<!--
EOT;
}if ($value['uid']) {print <<<EOT
-->
		<!-- 	<font color=blue>[租]</font> -->
<!--
EOT;
}print <<<EOT
-->
		</td>
		<td class="td2">
			<a class="fourm-two" href="$basename&action=edit&id=$value[id]" title="編輯">[編輯]</a>
			<a class="fourm-two" href="$basename&action=del&selid=$value[id]" onclick="if(!confirm('您確認要刪除該廣告嗎?'))return false;" title="刪除">[刪除]</a>
		</td>
	</tr>
<!--
EOT;
}}else{print <<<EOT
-->
<tr>
   <td colspan="8" class="p10"><div class="admin_tips">啊哦，沒有你要的信息！</div></td>

</tr>
<!--
EOT;
}print <<<EOT
-->
</table>
<script type="text/javascript">
function ifcheck(name){
	var obj = document.getElementsByName(name);
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked){
			return confirm('確認要進行此操作嗎？')
		}
	}
	alert("請選擇要進行操作的項");
	return false;
}
</script>
<div class="mb10">$pages</div>
<div class="mb10 tac">
	<p><span>選中操作︰</span>
	<label class="mr10"><input type="radio" name="action" value="show" checked/>上架</label>
	<label class="mr10"><input type="radio" name="action" value="hide"/>下架</label>
	<label><input type="radio" name="action" value="del"/>刪除</label></p><br>
	<p><span class="bt"><span><button type="button" onclick="CheckAll(this.form)">全 選</button></span></span>
	<span class="btn"><span><button type="submit" onclick="return ifcheck('selid[]')">提 交</button></span></span>
	</p>
</div>
</form>
</div>
<!--
EOT;
}include_once PrintEot('adminbottom');
?>-->