<!--<?php
if (!defined('AJAX')){
include_once PrintEot('left');
}print<<<EOT
-->
<style type="text/css">
.cate_search{}
.cate_search span{float:left;height:30px;line-height:30px;margin-right:10px;}
.cate_search span input{ vertical-align:middle;margin:0 3px;}
.cate_search span select{margin:0 3px;}
</style>
<!--
EOT;
if (empty($action)) {print <<<EOT
-->
<div class="nav3 mb10">
    <ul class="cc">
        <li class="current"><a href="$basename">行業分類主題管理</a></li>
        <li><a href="$basename&action=topic">分類內容管理</a></li>
    </ul>
</div>
<div class="admin_info mb10">
    <h3 class="h1">提示信息</h3>
    <div class="legend">
        <ol>
            <li>本功能必須與版塊綁定使用，否則會員將不能看到分類信息。請到 <a href="javascript:;" onclick="parent.PW.Dialog({id:'setforum',url:'$admin_file?adminjob=setforum',name:'管理版塊'});">管理版塊</a> 中進行關聯綁定</li>
            <li>本功能必須由會員權限支持，否則會員將不能發分類信息帖。請到 <a href="javascript:;" onclick="parent.PW.Dialog({id:'level',url:'$admin_file?adminjob=level',name:'會員組權限'});">會員組權限</a> 限中設定</li>
        </ol>
    </div>
</div>
<form action="$basename" method="post">
<input type="hidden" name="action" value="topiclist" />
<h2 class="h1 cc"><span class="fl mr10">主題管理</span><a href="javascript:;" onclick="sendmsg('$ajax_basename_add','',this.id);" id="addtopic" class="btn_add fl"><i>添加分類主題</i></a></h2>
<div class="admin_table mb10">
<table cellpadding="0" cellspacing="0" width="100%">
	<tr class="tr2">
		<td width="24" class="tac">啟用</td>
		<td style="width:80px;">順序</td>
		<td style="width:80px;">主題名稱</td>
		<td>所屬版塊</td>
		<td style="width:340px;">操作</td>
	</tr>
<!--
EOT;
foreach($topiccatedb as $key => $value){
$ifable = $ajax_basename_edittopic = '';
if ($value[ifable]) $ifable = 'checked';
$ajax_basename_edittopic = EncodeUrl($basename."&action=edittopic&cateid=$key");
$ajax_basename_addmodelname = EncodeUrl($basename."&action=addmodelname&cateid=$key");
$ajax_basename_editmodelname = EncodeUrl($basename."&action=editmodelname&cateid=$key");
print <<<EOT
-->
	<tr class="tr1 vt">
		<td class="td2"><input type="checkbox" name="selid[$value[cateid]]" value="$value[ifable]" $ifable></td>
		<td class="td2"><input type="text" class="input input_wc" name="vieworder[$value[cateid]]" value="$value[vieworder]"></td>
		<td class="td2"><input name="name[$value[cateid]]" type="text" class="input input_wc" value="$value[name]" /></td>
		<td class="td2">$value[forum]</td>
		<td class="td2">
            <a href="javascript:;" onclick="sendmsg('$ajax_basename_edittopic','',this.id);" id="edittopic$value[cateid]" class="mr20">[編輯主題]</a>
            <a href="javascript:;" onclick="sendmsg('$ajax_basename_addmodelname','',this.id);" id="addmodelname$value[cateid]" class="mr20">[添加模板]</a>
			<a href="javascript:;" onclick="sendmsg('$ajax_basename_editmodelname','',this.id);" id="editmodelname$value[cateid]" class="mr20">[編輯模板]</a>
<!--
EOT;
if(!$value[ifdel]){print<<<EOT
-->
            <a href="$basename&action=deltopic&cateid=$value[cateid]" onclick="if(!confirm('刪除主題將刪除所有關聯的模板、變量及其他信息')){return false;}" class="mr20">[刪除]</a>
<!--
EOT;
}print<<<EOT
-->
        </td>
	</tr>
<!--
EOT;
}print <<<EOT
-->
</table>
</div>
<div class="mb10 tac"><span class="btn"><span><button type="submit">提 交</button></span></span></div>
</form>
<script type="text/javascript">
var ajax_basename_delmodel = '$ajax_basename_delmodel';
function delmodel(modelid){
	if(confirm('刪除該模板後將清空該模板下的所有信息，包括帖子信息！是否確認刪除該模板？')){
		ajax.send(ajax_basename_delmodel,'modelid='+modelid,function(){
				var str = ajax.request.responseText.split("\t");
				if (str[0] == 'success'){
					showDialog('success','模板刪除成功!');
					window.location.href = basename;
				} else {
					ajax.guide();
				}
			}
		);
	}
}
</script>
<!--
EOT;
} elseif ($action == 'topic') {print <<<EOT
-->
<div class="nav3 mb10">
    <ul class="cc">
        <li><a href="$basename">行業分類主題管理</a></li>
        <li class="current"><a href="$basename&action=topic">分類內容管理</a></li>
    </ul>
</div>
<h2 class="h1 mb10"><span class="mr20">選擇分類模板</span><span class="linka"><select name="modelid" onchange="totopic(this.value)" class="select_wa">
<!--
EOT;
foreach($topiccatedb as $value){
print<<<EOT
-->
	<optgroup label="$value[name]">
<!--
EOT;
foreach($newmodeldb[$value[cateid]] as $val){
$selected = '';
$val[modelid] == $modelid && $selected = 'selected';
print<<<EOT
-->
	<option value="$val[modelid]" $selected>|--$val[name]</option>
<!--
EOT;
}print<<<EOT
-->
	</optgroup>
<!--
EOT;
}print <<<EOT
-->
</select></span>
</h2>
<script type="text/javascript">
function totopic(modelid) {
	window.location.href = '$admin_file?adminjob=topiccate&action=topic&modelid='+modelid;
}
</script>
<!--
EOT;
if($modelid){print<<<EOT
-->
<!--
EOT;
if($searchhtml || $asearchhtml){print<<<EOT
-->
<form action="$basename" method="post">
<input type="hidden" name="action" value="topic" />
<input type="hidden" name="step" value="search" />
<input type="hidden" name="modelid" value="$modelid" />
<input type="hidden" name="tids" value="$tids" />
<h2 class="h1">搜索內容</h2>
<div class="cc mb10 p10 cate_search">$searchhtml<b id="asearch" style="display:none;font-weight:normal;">$asearchhtml</b></div>
<div class="mb10 tac">
    <span class="btn"><span><button type="submit">提 交</button></span></span>
    <a id="show" href="javascript:;" onclick="showasearch()">高級搜索</a>
</div>
</form>
<script type="text/javascript">
function showasearch(id){
	if (getObj('asearch').style.display == 'none') {
		getObj('asearch').style.display = '';
	} else {
		getObj('asearch').style.display = 'none';
	}
}
</script>
<!--
EOT;
}print<<<EOT
-->
<!--
EOT;
}print<<<EOT
-->
<h2 class="h1">搜索結果</h2>
<form action="$basename" method="post">
<input type="hidden" name="action" value="delthreads" />
<input type="hidden" name="alltids" value="$alltids" />
<input type="hidden" name="modelid" value="$modelid" />
<div class="admin_table mb10">
<table cellpadding="0" cellspacing="0" width="100%" style="table-layout:auto;">
	<tr class="tr2">
		<td>全選</td>
		<td>名稱</td>
		<td>關聯模板</td>
		<td>所屬版塊</td>
		<td>發布者</td>
		<td>發布時間</td>
		<td>操作</td>
	</tr>
<!--
EOT;
foreach($topicdb as $key => $value){
print <<<EOT
-->
	<tr class="tr1 vt">
		<td class="td2"><input type="checkbox" name="selid[]" value="$value[tid]"></td>
		<td class="td2"><a href="read.php?tid=$value[tid]" target="_blank" class="unline">$value[subject]</a></td>
		<td class="td2">{$topicmodeldb[$modelid][name]}</td>
		<td class="td2"><a href="thread.php?fid=$value[fid]" target="blank">{$forum[$value[fid]][name]}</a></td>
		<td class="td2"><a href="{$db_userurl}$value[authorid]" target="_blank" class="unline">$value[author]</a></td>
		<td class="td2">$value[postdate]</td>
		<td class="td2"><a href="$basename&action=delthreads&selid=$value[tid]&modelid=$modelid" onclick="if(!confirm('是否確認刪除該帖子？')){return false;}" class="unline">刪除</a></td>
	</tr>
<!--
EOT;
}print <<<EOT
-->
</table>
</div>
<div class="mb10 tac">
	<input type="button" onclick='CheckAll(this.form)' value="全 選" class="bt3" />
	<input type="submit" onclick="return hasChecked(this.form);" value="刪 除" class="bt3" />
	<input type="submit" name="sendmsg" value="群發消息" class="btn3" />
    <!--span class="btn"><span><button type="button" onclick='CheckAll(this.form)'></button></span></span>
    <span class="bt"><span><button type="submit" >刪 除</button></span></span>
    <span class="bt"><span><button type="submit" name="sendmsg" value="1">群發消息</button></span></span-->
</div>
</form>
<script>
function hasChecked(obj) {
	var flag = false;
	for (var i=0; i<obj.elements.length-1; i++){
		var e = obj.elements[i];
		if(e.type=='checkbox' && e.checked == true) flag = true;
	}
	if (flag == false) {
		showDialog('error', '沒有選擇操作對象', 2);
		return false;
	} else {
		return confirm('是否確認刪除帖子？');
	}
}
</script>
<!--
EOT;
}elseif($_POST['sendmsg']){print<<<EOT
-->
<div class="nav3 mb10">
    <ul class="cc">
        <li><a href="$basename">行業分類主題管理</a></li>
        <li><a href="$basename&action=topic">分類內容管理</a></li>
        <li class="current"><a href="javascript:;">群發消息</a></li>
    </ul>
</div>
<form name='FORM' onreset="mreset()" action="$basename" method="post">
<input type="hidden" name="action" value="sendmsg" />
<input type="hidden" name="step" value="2" />
<input type="hidden" name="uids" value="$uids" />
<h2 class="h1">消息群發</h2>
<div class="admin_table mb10">
<table cellpadding="0" cellspacing="0" width="100%">
	<tr class="tr1 vt">
		<td width="80" class="td1">主題</td>
		<td class="td2"><input type="text" class="input input_wb" name="subject" /></td>
	</tr>
	<tr class="tr1 vt">
		<td class="td1">內容</td>
		<td class="td2">
<!--
EOT;
require_once PrintEot('wysiwyg_editor_common');
print <<<EOT
-->
		</td>
	</tr>
</table>
</div>

<script type="text/javascript" src="js/pw_ajax.js"></script>
<script type="text/javascript" src="js/post.js"></script>
<script type="text/javascript" src="js/global.js"></script>

<div id="menu_face" class="menu" style="display:none;"></div>
<div id="menu_generalface" class="menu" style="display:none;"></div>

<div class="mb10 tac">
    <span class="btn"><span><button type="submit">提 交</button></span></span>
    <span class="bt"><span><button type="reset" value="">重 置</button></span></span>
</div>
</form>
<script type="text/javascript">
function mreset(){
	editor.textarea.value='';
	editor.doc.body.innerHTML='';
	return true;
}
</script>
<!--
EOT;
}elseif(in_array($action,array('addtopic','edittopic'))){print<<<EOT
-->
<form name="form" method="post" action="$ajax_basename_add&" onsubmit="return false;">
<input type="hidden" name="cateid" value="$cateid">
<input type="hidden" name="step" value="2">
<h2 class="h1" style="cursor:move" onmousedown="read.move(event);">
<!--
EOT;
if($action == 'addtopic'){print<<<EOT
-->
	添加主題
<!--
EOT;
}elseif($action == 'edittopic'){print<<<EOT
-->
	編輯主題
<!--
EOT;
}print<<<EOT
-->
</h2>
<div class="admin_table mb10">
<table cellpadding="0" cellspacing="0" width="100%" style="table-layout:auto;">
	<tr class="tr1 vt">
		<td class="td2" style="width:75px;">分類主題名稱</td>
		<td class="td2"><input name="name" id="cate_name" class="input input_wa" value="$topic[name]">&nbsp;最多14個字節</td>
	</tr>
	<tr class="tr1 vt">
		<td class="td2">模板啟用</td>
		<td class="td2">
			<ul class="cc list_80 list_A">

<!--
EOT;
if($action == 'addtopic'){print<<<EOT
-->
				<li><input type="checkbox" name="modelid" value="1" checked disabled>&nbsp;默認模板</span></li>
<!--
EOT;
}elseif($action == 'edittopic'){print<<<EOT
-->
				$selectmodel
<!--
EOT;
}print<<<EOT
-->
			</ul>
		</td>
	</tr>
	<tr class="tr1 vt">
		<td class="td2">開啟分類主題</td>
		<td class="td2">
       		<ul class="cc list_80 list_A mr10">
                <li><input type="radio" name="ifable" value="1" $ifable_Y> 開啟</li>
                <li><input type="radio" name="ifable" value="0" $ifable_N> 關閉</li>
            </ul>
		</td>
	</tr>
	<tr class="tr1 vt">
		<td class="td2">順序</td>
		<td class="td2"><input name="vieworder" class="input input_wa" value="$topic[vieworder]"></td>
	</tr>
</table>
</div>
<div class="tac mb10">
<!--
EOT;
if($action == 'addtopic'){print<<<EOT
-->
	<span class="btn2"><span><button type="button" onclick="ajax.submit(this.form,ajax.guide)">進入模板編輯頁</button></span></span>
	<span class="bt2"><span><button type="button" onclick="closep();">取 消</button></span></span>
<!--
EOT;
}elseif($action == 'edittopic'){print<<<EOT
-->
	<span class="btn2"><span><button type="button" onclick="ajax.submit(this.form,ajax.guide)">提 交</button></span></span>
	<span class="bt2"><span><button type="button" onclick="closep();">取 消</button></span></span>
<!--
EOT;
}print<<<EOT
-->
</div>
</form>
<!--
EOT;
}elseif($action == 'editmodel'){print<<<EOT
-->
<div class="nav3 mb10">
    <ul class="cc">
        <li class="current"><a href="$basename">行業分類主題管理</a></li>
        <li><a href="$basename&action=topic">分類內容管理</a></li>
    </ul>
</div>
<div class="admin_info mb10">
    <h3 class="h1">提示信息</h3>
    <div class="legend">
        <ol>
            <li>編輯字段時，可以在名稱中加入{#}（兩個花括號加上一個井號），表示發表和閱讀帖子時，標記前後的文字可以分別顯示在字段的前後</li>
            <li>當顯示順序數字相同且不為0時，發表和閱讀帖子時也會在同一行顯示 </li>
            <li>結合以上兩點，可以靈活的編輯字段顯示格式。比如“戶型:*室*廳*衛*陽台”，可以編輯成相同順序的4個字段，字段名稱分別為“戶型:{#}室”、“{#}廳”、“{#}衛”、“{#}陽台”</li>
            <li>如果字段通過前台發帖存在數據，將無法編輯變量</li>
            <li>上傳（upload）類型必填限制無效</li>
        </ol>
    </div>
</div>
<h3 class="h1"><span class="fl mr10">修改 <span class="s2">{$modelname}</span> 字段</span><a href="javascript:;" onclick="sendmsg('$ajax_basename_add','modelid=$modelid&cateid=$cateid',this.id);" id="addfield" class="btn_add fl"><i>添加字段</i></a></h3>
<script type="text/javascript" src="js/global.js"></script>
<script type="text/javascript" src="js/pw_ajax.js"></script>
<!--
EOT;
if(empty($step)){print<<<EOT
-->
<form method="post" action="$basename&">
<input name="action" type="hidden" value="editmodel">
<input name="cateid" id="cateid" type="hidden" value="$cateid">
<input name="modelid" id="modelid" type="hidden" value="$modelid">
<input name="step" type="hidden" value="2">
<div class="admin_table mb10">
<table cellpadding="0" cellspacing="0" width="100%" style="table-layout:auto;">
	<tr class="tr2">
		<td width="25">啟用</td>
		<td width="65">順序</td>
		<td>名稱</td>
		<td width="50">默認查詢</td>
		<td width="50">高級查詢</td>
		<td width="50">列表顯示</td>
		<td width="50">是否必須</td>
		<td width="80">框體顯示長度</td>
		<td width="200">操作</td>
	</tr>
<!--
EOT;
foreach($fielddb as $k=>$v){print <<<EOT
-->
	<tr id="col_$k"  class="vt tr1">
        <td class="td2"><input type="checkbox" name="ifable[$k]" id="ifable[$k]" value="1" $v[ifable_checked] ></td>
        <td class="td2"><input name="vieworder[$k]" id="vieworder[$k]" value="$v[vieworder]" class="input input_wc"></td>
        <td class="td2">$v[name1]
<!--
EOT;
if($v[name2]){print<<<EOT
-->
		/ $v[name2]
<!--
EOT;
}print<<<EOT
-->
        <!--<p class="gray">$v[descrip]</p>-->
        </td>
        <td class="td2"><input type="checkbox" name="ifsearch[$k]" value="1" $v[ifsearch_checked]></td>
        <td class="td2"><input type="checkbox" name="ifasearch[$k]" value="1" $v[ifasearch_checked]></td>
        <td class="td2"><input type="checkbox" name="threadshow[$k]" value="1" $v[threadshow_checked]></td>
        <td class="td2"><input type="checkbox" name="ifmust[$k]" value="1" $v[ifmust_checked]></td>
		<td class="td2">
<!--
EOT;
if(in_array($v['type'],array('number','text','textarea','calendar','email','url','img','upload'))){print<<<EOT
-->
        <input type="text" name="textsize[$k]" value="$v[textsize]" size="5" class="input">
<!--
EOT;
}print<<<EOT
-->
		</td>
        <td class="td2">
            <a href="javascript:;" class="mr20" onclick="sendmsg('$ajax_basename_edit','fieldid=$k&modelid=$modelid&cateid=$cateid',this.id);" id="editfield_$k">[編輯]</a>
            <a href="javascript:;" onclick="delfield($k);return false;" class="mr20">[刪除]</a>
<!--
EOT;
if($v['indexstate'] == 1){print<<<EOT
-->
            <a href="javascript:;" onclick="editIndex($modelid,$k,'del');return false;">[刪除索引]</a>
<!--
EOT;
}elseif($v['indexstate'] == 0 && $v['ifindex']){print<<<EOT
-->
            <a href="javascript:;" onclick="editIndex($modelid,$k,'add');return false;">[添加索引]</a>
<!--
EOT;
}else{print<<<EOT
-->
        <span></span>
<!--
EOT;
}print<<<EOT
-->
	</tr>
<!--
EOT;
}print<<<EOT
-->
</table>
<a name="cols"></a>
</div>
<div class="mb10 tac">
    <!-- <span class="bt"><span><button type="button" oonclick="CheckIfable(this.form,'ifable[')">全 選</button></span></span> -->
    <span class="btn"><span><button type="submit">提 交</button></span></span>
	<span class="bt"><span><button type="button" onclick="window.location.href = '$basename'+'&action=editmodel&step=3&cateid='+'$cateid'+'&modelid='+'$modelid'">預覽</button></span></span>
</div>
</form>
<!--
EOT;
}elseif($step==3){print<<<EOT
-->
<div class="admin_table mb10">
<table cellpadding="0" cellspacing="0" width="100%">
$topichtml
</table>
</div>
<div class="mb10 tac">
	 <span class="btn"><span><button type="button" onclick="window.location.href = '$basename'+'&action=editmodel&step=&cateid='+'$cateid'+'&modelid='+'$modelid'">返回編輯</button></span></span>
</div>
<!--
EOT;
}print<<<EOT
-->
<script type="text/javascript">
var basename = '$basename';
var ajax_basename_edit = '$ajax_basename_edit';
var ajax_basename_add = '$ajax_basename_add';
var ajax_basename_showfield = '$ajax_basename_showfield';
var ajax_basename_delfield = '$ajax_basename_delfield';
var ajax_basename_editindex = '$ajax_basename_editindex';

function CheckIfable(form,cname){
	var ifcheck = null;
	for (var i=0;i<form.elements.length-2;i++){
		var e = form.elements[i];
		if(e.type=='checkbox' && e.name.indexOf(cname) != -1){
			if (ifcheck === null) ifcheck = !e.checked;
			e.checked = ifcheck;
			if (typeof e.onclick == 'function') e.onclick();
		}
	}
	return ifcheck;
}
/*
function editFieldResponse(){
	var str = ajax.request.responseText.split("\t");

	if (str[0] == 'success'){
		var fielddb = JSONParse(str[5]);

		var tr = elementBind('tr','col_' + str[1],'tr3');
		var td_ifable = elementBind('td');
		var input_ifable = elementBind('input');
		input_ifable.type = 'checkbox';
		input_ifable.name = 'ifable['+str[1]+']';
		input_ifable.value = 1;
		input_ifable.checked = str[6] ? true : false;
		td_ifable.appendChild(input_ifable);
		var td_vieworder = elementBind('td');
		var input_vieworder = elementBind('input');
		input_vieworder.name = 'vieworder['+str[1]+']';
		input_vieworder.size = 2;
		input_vieworder.value = str[7];
		td_vieworder.appendChild(input_vieworder);

		var td_type = elementBind('td');
		td_type.innerHTML = str[3];

		var td_field = elementBind('td');
		var name_span = elementBind('span');
		name_span.innerHTML = str[4]+'︰';
		if (str[2] == 'select') {
			var selobj = elementBind('select');
			for (var temp in fielddb){
				selobj.options.add(new Option(fielddb[temp],''));
			}
			td_field.appendChild(name_span);
			td_field.appendChild(selobj);
		} else if (str[2] == 'radio'){

			td_field.appendChild(name_span);
			for (var temp in fielddb){
				var radioobj = elementBind('input');
				radioobj.type = 'radio';
				td_field.appendChild(radioobj);
				var radiotext = elementBind('span');
				radiotext.innerHTML = fielddb[temp];
				td_field.appendChild(radiotext);
			}
		} else if (str[2] == 'checkbox'){

			td_field.appendChild(name_span);
			for (var temp in fielddb){
				var checkboxobj = elementBind('input');
				checkboxobj.type = 'checkbox';
				td_field.appendChild(checkboxobj);
				var checkboxtext = elementBind('span');
				checkboxtext.innerHTML = fielddb[temp];
				td_field.appendChild(checkboxtext);
			}
		} else if (str[2] == 'upload'){
			var upload = elementBind('input');
			upload.type = 'file';
			td_field.appendChild(name_span);
			td_field.appendChild(upload);
		} else {
			var input = elementBind('input');
			td_field.appendChild(name_span);
			td_field.appendChild(input);
		}
		var td_ifsearch = elementBind('td');
		var input_ifsearch = elementBind('input');
		input_ifsearch.type = 'checkbox';
		input_ifsearch.name = 'ifsearch['+str[1]+']';
		input_ifsearch.value = 1;
		str[8] = parseInt(str[8]);
		input_ifsearch.checked = str[8] ? true : false;
		td_ifsearch.appendChild(input_ifsearch);


		var td_ifasearch = elementBind('td');
		var input_ifasearch = elementBind('input');
		input_ifasearch.type = 'checkbox';
		input_ifasearch.name = 'ifasearch['+str[1]+']';
		input_ifasearch.value = 1;
		str[9] = parseInt(str[9]);
		input_ifasearch.checked = str[9] ? true : false;
		td_ifasearch.appendChild(input_ifasearch);

		var td_threadshow = elementBind('td');
		var input_threadshow = elementBind('input');
		input_threadshow.type = 'checkbox';
		input_threadshow.name = 'threadshow['+str[1]+']';
		input_threadshow.value = 1;
		str[10] = parseInt(str[10]);
		input_threadshow.checked = str[10] ? true : false;
		td_threadshow.appendChild(input_threadshow);

		var td_ifmust = elementBind('td');
		var input_ifmust = elementBind('input');
		input_ifmust.type = 'checkbox';
		input_ifmust.name = 'ifmust['+str[1]+']';
		input_ifmust.value = 1;
		input_ifmust.checked = str[11] ? true : false;
		td_ifmust.appendChild(input_ifmust);

		var td_del = elementBind('td');
		var del_a = elementBind('a');
		//var del_a.href = 'javascript:;';
		del_a.onclick=function(){
			delfield(str[1]);
		}
		del_a.innerHTML = '刪除'

		var modelid = getObj('modelid').value;
		var addindex_a = elementBind('a');
		//var addindex_a.href = 'javascript:;';
		addindex_a.onclick=function(){
			editIndex(modelid,str[1],'add');
		}
		addindex_a.innerHTML = '添加索引';

		var br = elementBind('br');
		td_del.appendChild(del_a);
		td_del.appendChild(br);
		td_del.appendChild(addindex_a);

		tr.appendChild(td_ifable);
		tr.appendChild(td_vieworder);
		tr.appendChild(td_type);
		tr.appendChild(td_field);
		tr.appendChild(td_ifsearch);
		tr.appendChild(td_ifasearch);
		tr.appendChild(td_threadshow);
		tr.appendChild(td_ifmust);
		tr.appendChild(td_del);

		if (IsElement('col_'+str[1])){
			var replacenode = getObj('col_'+str[1]);
			replacenode.parentNode.replaceChild(tr,replacenode);
		} else {
			getObj('s_table').appendChild(tr);
			tr.focus();
		}
	} else {
		ajax.guide();
	}
}

*/

function delfield(id) {
	if(confirm('刪除字段將同時刪除帖子關聯數據，確認刪除？')) {
		ajax.send(ajax_basename_delfield,'fieldid='+id,function(){
				var str = ajax.request.responseText.split("\t");
				if (str[0] == 'success'){
					//delElement('col_'+id);
					showDialog('success','刪除字段成功!');
					window.location.href = basename+'&action=editmodel&cateid=$cateid&modelid='+str[1];
				} else {
					showDialog('error','刪除失敗');
				}
			}
		);
	}
}

function editIndex(modelid,fieldid,type) {
	if (confirm('添加索引可以提交分類信息帖子的查詢速度，但如果添加索引的字段過多，效果會下降。建議將常用查詢建立索引。確認添加？')){
		ajax.send(ajax_basename_editindex,'modelid='+modelid+'&fieldid='+fieldid+'&type='+type,function(){
				var str = ajax.request.responseText.split("\t");
				if (str[0] == 'success'){
					showDialog('success','索引操作成功！');
					window.location.href = basename+'&action=editmodel&cateid='+str[1]+'&modelid='+str[2];
				} else {
					ajax.guide();
				}
			}
		);
	}
}

function ShowType(id){
	try {
		if(id == 'radio' || id == 'checkbox' || id == 'select') {
			getObj('content_des').innerHTML = '在“選項內容”中設置選項，一個選項一行，格式為“1=***” ，“=”後為要顯示的內容，確保“=”前的數字不是相同的';
		} else if(id == 'number') {
			getObj('content_des').innerHTML = '數值範圍表示發表帖子時，輸入框中填寫的數字必須在此設置的範圍內，留空則不限制';
		} else if(id == 'calendar') {
			getObj('content_des').innerHTML = '發帖和搜索時彈出日期選擇框';
		} else if(id == 'text') {
			getObj('content_des').innerHTML = '輸入框，最大字節長度為255';
		} else if(id == 'url') {
			getObj('content_des').innerHTML = '該字段內容瀏覽時會顯示成超鏈接，最大字節長度為255';
		} else if(id == 'email') {
			getObj('content_des').innerHTML = '可以控制輸入內容符合電子郵件格式，最大字節長度為255';
		} else if(id == 'textarea') {
			getObj('content_des').innerHTML = '文本輸入框，最大字節長度為6500';
		} else if (id == 'img') {
			getObj('content_des').innerHTML = '可以輸入圖片鏈接，瀏覽時將在圖片播放器中顯示，最大字節長度為255';
		} else if (id == 'upload') {
			getObj('content_des').innerHTML = '可上傳圖片，瀏覽時將在圖片播放器中顯示';
		} else if(id == 'range') {
			getObj('content_des').innerHTML = '發帖時表現形式為文本框，但搜索時顯示為兩個文本框，輸入最大值和最小值後，可以搜索出範圍內的記錄。比如發帖時輸入100，搜索時輸入“1-150”可以查詢到結果';
		}

		getObj('content_box').style.display = '';

		if (id == 'radio' || id == 'checkbox' || id == 'select'){
			getObj('content_rules').style.display = '';
			getObj('content_number').style.display = 'none';
		} else if (id == 'number'){
			getObj('content_rules').style.display = 'none';
			getObj('content_number').style.display = '';
		} else {
			getObj('content_rules').style.display = 'none';
			getObj('content_number').style.display = 'none';
		}

		for (var i=0;i<getObj('fieldtype').options.length ; i++ ){
			if(id==getObj('fieldtype').options[i].value) {
				getObj('fieldtype').options[i].selected = true;
			}
		}
	} catch(e){}
}

</script>
<!--
EOT;
}elseif($action == 'editmodelname'){print<<<EOT
-->
<form method="post" action="$ajax_basename"  onsubmit="return false;">
<input type="hidden" name="step" value="2">
<input type="hidden" name="cateid" value="$cateid">
<input type="hidden" name="modelid" value="$modelid">
<h2 class="h1" style="cursor:move" onmousedown="read.move(event);">編輯模板名稱</h2>
<div style="max-height:260px;_height:260px;overflow:hidden;overflow-y:auto;_width:384px;margin-bottom:5px;">
    <div class="admin_table mb10">
    <table cellpadding="0" cellspacing="0" width="100%">
        <tr class="tr2 vt">
            <td width="30" class="tac">順序</td>
            <td width="120">模板名稱</td>
            <td>操作</td>
        </tr>
<!--
EOT;
foreach($modeldb as $key => $value) {print<<<EOT
-->
        <tr class="tr1">
            <td class="td2 tac"><input name="vieworder[$key]" value="$value[vieworder]" size="3" class="input"></td>
            <td class="td2"><input class="input" name="name[$key]" value="$value[name]"></td>
            <td class="td2"><a href="$basename&action=editmodel&cateid=$cateid&modelid=$key" class="mr20">編輯</a><a href="javascript:;" onclick="delmodel($key);return false;" class="mr20">刪除</a></td>
        </tr>
<!--
EOT;
}print<<<EOT
-->
    </table>
    </div>
</div>
    <div class="mb10 tac">
        <span class="btn2"><span><button type="button" onclick="ajax.submit(this.form,modeNameEditResponse);">修 改</button></span></span>
        <span class="bt2"><span><button type="button" onclick="closep();">取 消</button></span></span>
    </div>
</form>
<script type="text/javascript">
var basename = '$basename';
function modeNameEditResponse(){
	str = ajax.request.responseText.split("\t");
	if (str[0] == 'success'){
		showDialog('success','模板修改成功!');
		window.location.href = basename;
	}else{
		showDialog('error','修改失敗');
	}
}
</script>
<!--
EOT;
}elseif($action == 'addmodelname'){print<<<EOT
-->
<form method="post" action="$ajax_basename"  onsubmit="return false;">
<input type="hidden" name="step" value="2">
<input type="hidden" name="cateid" value="$cateid">
<input type="hidden" name="modelid" value="$modelid">
<h2 class="h1" style="cursor:move" onmousedown="read.move(event);">添加模板</h2>
<div class="admin_table mb10">
<table cellpadding="0" cellpadding="0" width="300">
	<tr class="tr1 vt">
		<td class="td2">模板名稱:</td>
		<td class="td2" style="width:170px"><input type="text" class="input input_wa" name="modename" value=""></td>
	</tr>
</table>
</div>
<div class="tac mb10">
    <span class="btn2"><span><button type="button" onclick="ajax.submit(this.form,modeNameAddResponse);">提 交</button></span></span>
    <span class="bt2"><span><button type="button" onclick="closep();">取 消</button></span></span>
</div>
</form>
<script type="text/javascript">
var basename = '$basename';
function modeNameAddResponse(){
	str = ajax.request.responseText.split("\t");
	if (str[0] == 'success'){
		window.location.href = basename+'&action=editmodel&cateid='+str[1]+'&modelid='+str[2];
	}else if (str[0] == 'mode_name_too_long'){
		showDialog('error','名稱長度超過30個字節！',2);
	}else if (str[0] == 'samename'){
		showDialog('error','同個主題分類下不能存在相同的模板名稱',2);
	}else{
		showDialog('error','添加失敗',2);
	}
}
</script>
<!--
EOT;
}elseif($action == 'addfield'){print<<<EOT
-->
<div id="add_field_box">
<form method="post" action="$ajax_basename_add"  onsubmit="return false;">
<input type="hidden" name="step" value="2">
<input type="hidden" name="modelid" value="$modelid">
<input type="hidden" name="cateid" value="$cateid">
<h2 class="h1">
    <div class="tab_A linka" style="margin-top:3px;">
        <ul class="cc">
            <li class="current" style="cursor:move" onmousedown="read.move(event);"><a href="javascript:;">添加字段</a></li>
            <li onclick="changeAddCopyBox('copy_field_box');"><a href="javascript:;">其他模板導入</a></li>
        </ul>
    </div>
</h2>
<div class="admin_table mb10" style="width:350px;">
	<table width="100%">
		<tr class="tr1 vt">
			<td style="width:80px;" class="td2">名稱</td>
			<td class="td2">
				<input class="input input_wa" type="text" name="name" id="name"/>
			</td>
		</tr>
		<tr class="tr1 vt">
			<td class="td2">描述</td>
			<td class="td2">
				<textarea name="descrip"  id="descrip" class="textarea" style="width:153px;"></textarea>
			</td>
		</tr>
		<tr class="tr1 vt">
			<td class="td2">&nbsp;</td>
			<td class="td2">
				<select name="fieldtype" id="fieldtype" onchange="ShowType(this.value);" class="select_wa">
					<option value="0">選擇字段類型</option>
					<option value="number">數字（number）</option>
					<option value="text">字串（text）</option>
					<option value="radio">單選（radio）</option>
					<option value="checkbox">多選（checkbox）</option>
					<option value="textarea">文本（textarea）</option>
					<option value="select">選擇（select）</option>
					<option value="calendar">日歷（calendar）</option>
					<option value="email">電子郵件（email）</option>
					<option value="url">超鏈接（url）</option>
					<option value="img">圖片（img）</option>
					<option value="upload">上傳（upload）</option>
					<option value="range">取值範圍（range）</option>
				</select>
			</td>
		</tr>
		<tr class="tr1 vt" id="content_number"  style="display:none;">
			<td class="td2">數值範圍</td>
			<td class="td2">
				<input type="text" name="rule_min" id="rule_min" class="input input_wc" value=""> - <input type="text" name="rule_max" id="rule_max" class="input input_wc" value="">
			</td>
		</tr>
		<tr class="tr1 vt" id="content_rules"  style="display:none;">
			<td class="td2">選項內容</td>
			<td class="td2">
				<textarea name="rules" class="textarea" style="width:153px;"></textarea>
			</td>
		</tr>
		<tr class="tr1 vt" id="content_box" style="display:none;">
			<td class="td2">提示信息</td>
			<td class="td2"><div id="content_des"></div></td>
		</tr>
	</table>
</div>
<div class="tac mb10">
    <span class="btn2"><span><button type="button" onclick="ajax.submit(this.form,ajax.guide)">添 加</button></span></span>
    <span class="bt2"><span><button type="button" onclick="closep();">取 消</button></span></span>
</div>
</form>
</div>
<div id="copy_field_box" style="display:none;">
<form method="post" action="$ajax_basename_copy"  onsubmit="return false;">
<input type="hidden" name="modelid" value="$modelid">
<input type="hidden" name="cateid" value="$cateid">
<h2 class="h1">
    <div class="tab_A linka" style="margin-top:3px;">
        <ul class="cc">
            <li onclick="changeAddCopyBox('add_field_box');"><a href="javascript:;">添加字段</a></li>
            <li class="current" style="cursor:move;"><a href="javascript:;">其他模板導入</a></li>
        </ul>
    </div>
</h2>
<div class="admin_table mb10" style="width:350px;">
	<table width="100%">
		<tr class="tr1 vt">
			<td style="width:80px;" class="td2">選擇模板</td>
			<td class="td2">
                <select onchange="selectFieldsByMode(this.value)" class="select_wa">
                <option value="">--</option>
<!--
EOT;
foreach($select_catedb as $key => $value){print<<<EOT
-->
				<optgroup label="$value[name]">
<!--
EOT;
foreach ($select_modeldb as $k => $v){
if($v['cateid'] != $key) continue;
print<<<EOT
-->
				<option value="$v[modelid]">$v[name]</option>
<!--
EOT;
}print<<<EOT
-->
				</optgroup>
<!--
EOT;
}print<<<EOT
-->
				</select>
           	</td>
		</tr>
        <tr class="tr1 vt">
        	<td class="td2" colspan="2"><div class="add_list"><div id="fieldlist"></div></div></td>
        </tr>
	</table>
</div>
<div class="tac mb10">
	<span class="bt2"><span><button type="button" name="chkall" onclick="CheckIfable(this.form,'copyfield[')">全 選</button></span></span>
    <span class="btn2"><span><button type="button" onclick="ajax.submit(this.form,ajax.guide)">導 入</button></span></span>
    <span class="bt2"><span><button type="button" onclick="closep();">取 消</button></span></span>
</div>
</form>
</div>
<script type="text/javascript">
var ajax_basename_showfield = '$ajax_basename_showfield';
function changeAddCopyBox(id){
	if(id == 'add_field_box') {
		getObj(id).style.display = '';
		getObj('copy_field_box').style.display = 'none';
	} else if (id == 'copy_field_box'){
		getObj(id).style.display = '';
		getObj('add_field_box').style.display = 'none';
	}
}

function selectFieldsByMode(value){

	var currentmodelid = getObj('modelid').value;
	ajax.send(ajax_basename_showfield,'modelid='+value+'&currentmodelid='+currentmodelid,showFiledsList);
}

function showFiledsList(){

	var str = ajax.request.responseText.split("\t");
	var ul = elementBind('ul','ul_fieldlist');
	var ofieldlist = getObj('fieldlist');
	if (str[0] == 'success'){
		if(IsElement('ul_fieldlist')){delElement('ul_fieldlist');}
		if(IsElement('copyfieldbutton')){delElement('copyfieldbutton');}
		var fielddb = JSONParse(str[1]);
		for (var temp in fielddb){
			var check_box = elementBind('input');
			check_box.type = 'checkbox';
			check_box.name = 'copyfield[]';
			check_box.value = temp;
			var check_name = elementBind('span');
			check_name.innerHTML = fielddb[temp];
			var check_li = elementBind('li');
			check_li.appendChild(check_box);
			check_li.appendChild(check_name);
			ul.appendChild(check_li);
		}
	} else {
		var check_li = elementBind('li');
		ul.appendChild(check_li);
		check_li.innerHTML = '該模板沒有字段';
	}
	ofieldlist.appendChild(ul);
}
</script>
<!--
EOT;
}elseif($action == 'editfield'){print<<<EOT
-->
<form method="post" action="$ajax_basename_edit"  onsubmit="return false;">
<input type="hidden" name="step" value="2">
<input type="hidden" name="fieldid" value="$fieldid">
<input type="hidden" name="cateid" value="$cateid">
<input type="hidden" name="modelid" value="$modelid">
<h2 class="h1" style="cursor:move" onmousedown="read.move(event);">編輯字段</h2>
<div class="admin_table mb10" style="width:350px;">
	<table width="100%">
		<tr class="tr1 vt">
			<td style="width:80px;" class="td2">名稱</td>
			<td class="td2">
				<input class="input input_wa" type="text" name="name" id="name" value="$fielddb[name]"/>
			</td>
		</tr>
		<tr class="tr1 vt">
			<td class="td2">描述</td>
			<td class="td2">
				<textarea name="descrip" id="descrip" class="textarea" style="width:153px;">$fielddb[descrip]</textarea>
			</td>
		</tr>
<!--
EOT;
if($ifhidden==1){
$selectdb = array(
	'number'=>'數字（number）',
	'text'=>'字串（text）',
	'radio'=>'單選（radio）',
	'checkbox'=>'多選（checkbox）',
	'textarea'=>'文本（textarea）',
	'select'=>'選擇（select）',
	'calendar'=>'日歷（calendar）',
	'email'=>'電子郵件（email）',
	'url'=>'超鏈接（url）',
	'img'=>'圖片（img）',
	'upload'=>'上傳（upload）',
	'range'=>'取值範圍（range）'
);
print<<<EOT
-->
		<tr class="tr1 vt">
			<td class="td2">&nbsp;</td>
			<td class="td2">
				<input type="hidden" name="fieldtype" value="$fielddb[type]">
				<select id="fieldtype" onchange="ShowType(this.value);" class="select_wa">
					<option>{$selectdb[$fielddb[type]]}</option>
				</select>
			</td>
		</tr>
<!--
EOT;
}else{print<<<EOT
-->
		<tr class="tr1 vt">
			<td class="td2">&nbsp;</td>
			<td class="td2">
				<select name="fieldtype" id="fieldtype" onchange="ShowType(this.value);" class="select_wa">
					<option value="0">選擇字段類型</option>
					<option value="number">數字（number）</option>
					<option value="text">字串（text）</option>
					<option value="radio">單選（radio）</option>
					<option value="checkbox">多選（checkbox）</option>
					<option value="textarea">文本（textarea）</option>
					<option value="select">選擇（select）</option>
					<option value="calendar">日歷（calendar）</option>
					<option value="email">電子郵件（email）</option>
					<option value="url">超鏈接（url）</option>
					<option value="img">圖片（img）</option>
					<option value="upload">上傳（upload）</option>
					<option value="range">取值範圍（range）</option>
				</select>
			</td>
		</tr>
<!--
EOT;
}print<<<EOT
-->
		<tr id="content_number" class="tr1 vt" style="display:none;">
			<td class="td2">數值範圍:</td>
			<td class="td2">
				<input type="text" name="rule_min" id="rule_min" class="input input_wc" value="$minnum"> - <input type="text" name="rule_max" id="rule_max" class="input input_wc" value="$maxnum">
			</td>
		</tr>
		<tr id="content_rules" class="tr1 vt" style="display:none;">
			<td class="td2">選項內容:</td>
			<td class="td2">
				<textarea name="rules" class="textarea" style="width:153px;">$rule_content</textarea>
			</td>
		</tr>
		<tr id="content_box" class="tr1 vt" style="display:none;">
			<td class="td2">提示信息:</td>
			<td class="td2"><div id="content_des"></div></td>
		</tr>
	</table>
</div>
<div class="tac mb10">
    <span class="btn2"><span><button type="button" onclick="ajax.submit(this.form,ajax.guide)">修 改</button></span></span>
    <span class="bt2"><span><button type="button" onclick="closep();">取 消</button></span></span>
</div>
</form>
<script type="text/javascript">
var type = '$type';
setTimeout(function(){ShowType(type);},300);
</script>
<!--
EOT;
}if(!defined('AJAX')){
include_once PrintEot('adminbottom');
}
?>-->