<!--<?php print <<<EOT
-->
<link rel="stylesheet" href="$pwModeImg/style.css?{$GLOBALS['wind_repair']}" />
<script type="text/javascript" src="js/date.js"></script>
<form method="post" id="mainForm" name="FORM" action="{$basename}q=post" enctype = "multipart/form-data" onsubmit="return checkpost(document.FORM);">
<input type="hidden" name="verify" value="$verifyhash" />
<input type="hidden" name="step" value="2" />
<input type="hidden" name="action" value="$action" />
<input type="hidden" name="id" value="$id" />
<input type="hidden" name="page" value="$page" />
<input type="hidden" name="ajax" value="1" />
<input type="hidden" name="iscontinue" value="0" />
<!--
EOT;
if (!$hasSource) {
print <<<EOT
-->
<input type="hidden" name="cms_sourcetype" value="$articleModule->sourceType" />
<input type="hidden" name="cms_sourceid" value="$articleModule->sourceId" />
<!--
EOT;
}
$postTitle = $action == 'edit' ? '編輯文章' : '發表文章';
$_sourceTitle = $action == 'edit' ? '內容關聯' : '內容獲取';
$_sourceTip = $action == 'edit' ? '(關聯ID後，可以引導用戶進入原帖子或日志)' : '(輸入帖子ID或者日志ID後，可以自動獲取內容)';
print <<<EOT
-->
<div id="breadCrumb">
	<img align="absmiddle" src="images/wind/thread/home.gif" alt="forumlist" class="breadHome" /><em class="breadEm"></em>$pagePosition<em>&gt;</em>{$postTitle}
</div>
<div class="t">
	<div class="h b" style="border-top:0;">$postTitle</div>
	<div class="p20">
<!--
EOT;
if ($hasSource) {print <<<EOT
-->
		<div class="mb15">
			<span class="f12 fn"><!--{$_sourceTitle}︰-->
					<select id="sourcetype" name="cms_sourcetype" class="mr10" style="width:120px;">
<!--
EOT;
foreach ($articleModule->getSourceTypeConfig() as $key=>$value) {
$selected = $articleModule->sourceType == $key ? 'selected="selected"' : '';
print <<<EOT
-->
						<option value="$key" $selected>$value</option>
<!--
EOT;
}print <<<EOT
-->
					</select>
<!--
EOT;
if (!$action) {print <<<EOT
-->
<input name="cms_sourceid" class="input" type="text" onfocus="resetFormOnSubmit(true)"   onkeydown="getSourceDataByEnter(event,this.value)" onBlur="getSourceData(this.value)" value="{$articleModule->sourceId}">
<!--
EOT;
}else{print <<<EOT
-->
					<input name="cms_sourceid" class="input input_wa" type="text" value="{$articleModule->sourceId}">
<!--
EOT;
}print <<<EOT
-->
					<span class="bt2"><span><button type="button">{$_sourceTitle}</button></span></span></span>
		</div>
<!--
EOT;
}print <<<EOT
-->
		<div class="mb15"><select name="cid" style="width:120px;" class="mr10">
						<option value="0">請選擇欄目</option>
<!--
EOT;
foreach ($columns as $key=>$value) {
$value[name] = $value[level] ? ($value[level]==1 ? '&nbsp;|-'.$value[name]:'&nbsp;&nbsp;|-'.$value[name]) : $value[name];
$selected = $value['column_id'] == $articleModule->columnId ? 'selected="selected"' : '';
print <<<EOT
-->
						<option value="$value[column_id]" $selected>$value[name]</option>
<!--
EOT;
}print <<<EOT
-->
					</select>
					<input name="cms_subject" value="{$articleModule->subject}" class="input input_wb" type="text">
		</div>
<!--
EOT;
if ($action=='edit') {print <<<EOT
-->
			<div class="mb15 cc"><span class="mr20 fl">$pages</span><span class="fl mr10">操作︰</span>
					<a href="{$cmsBaseUrl}q=post&action=edit&id=$id&page=add" class="s4 mr10">添加分頁</a>
					<a href="{$cmsBaseUrl}q=post&action=edit&id=$id&page=all" class="s4 mr10">編輯全部</a><!--
EOT;
if ($page && $pages && $page!='add' && $page!='all') {print <<<EOT
--><span class="mr10 gray">|</span><a href="javascript:;" onclick="showDialog('confirm','刪除後不可恢復，是否確認刪除','5',deletePage);return false;" class="s4 mr5">刪除本頁</a>
<!--
EOT;
}print <<<EOT
-->
			</div>
<!--
EOT;
}print <<<EOT
-->
		<!--編輯器開始-->
		<div class="mb10">
<!--
EOT;
require cmsTemplate::printEot('wysiwyg_editor_cms');
print <<<EOT
-->
		</div>
		<!--編輯器結束-->
		<div>
			<ul class="postInfo mb10 cc">
				<li><em>原作者</em><input name="cms_author" value="{$articleModule->author}" type="text" class="input input_wb"></li>	
				<li><em>來源網址</em><input name="cms_fromurl" value="{$articleModule->fromUrl}" type="text" class="input input_wb"></li>
				<li><em>信息來源</em><input name="cms_frominfo" value="{$articleModule->fromInfo}" type="text" class="input input_wb"></li>
<!--
EOT;
if(checkEditPurview($windid)){
print <<<EOT
-->
				<li class="cc"><em class="fl">跳轉鏈接</em><input name="cms_jumpurl" value="{$articleModule->jumpUrl}" type="text" class="input input_wb fl mr10"><a class="wy_tips" href="javascript:;"><img src="u/images/help_a.png" /><i style="margin-left:-230px;">添加後，點擊文章標題將跳轉到這個鏈接。</i></a></li>
<!--
EOT;
}print <<<EOT
-->
<!--
EOT;
if(checkEditPurview($windid)){
print <<<EOT
-->
				<li><em>發布時間</em><input class="input input_wb" value="$postdate" type="text" name="cms_timelimit" size="16" id="cms_timelimit" onclick="ShowCalendar(this.id,1);" /></li>
<!--
EOT;
}print <<<EOT
-->
				<li><em>文章摘要</em><textarea name="cms_descrip" class="textareaA">{$articleModule->descrip}</textarea></li>
				<li class="cc"><em class="fl" style="padding-top:3px;">相關閱讀</em>
				<table width="770" class="fl">
					<tbody id="mode" style="display:none"><tr>
						<td><input name="cms_relate[subject][]" type="text" class="input"></td>
						<td><input name="cms_relate[url][]" type="text" class="input input_wb" value="http://"></td>
						<td><a href="#" onclick="removecols(this);return false;" class="s4">[刪除]</a></td>
					</tr>
					</tbody>
					<tr>
						<td width="140">標題</td>
						<td width="350">鏈接</td>
						<td><a href="javascript:;" onclick="addcols('mode','relate');return false;" class="s2 mr5">[添加]</a></td>
					</tr>
					<tbody id="relate">
<!--
EOT;
foreach ($articleModule->relate as $value) {print <<<EOT
-->
					<tr>
						<td><input name="cms_relate[subject][]" value="$value[subject]" type="text" class="input"></td>
						<td><input name="cms_relate[url][]" value="$value[url]" type="text" class="input input_wb"></td>
						<td><a href="javascript:;" onclick="removecols(this);return false;" class="s4">[刪除]</a></td>
					</tr>
<!--
EOT;
}print <<<EOT
-->
					<tr>
						<td><input name="cms_relate[subject][]" type="text" class="input"></td>
						<td><input name="cms_relate[url][]" type="text" class="input input_wb" value="http://"></td>
						<td><a href="javascript:;" onclick="removecols(this);return false;" class="s4">[刪除]</a></td>
					</tr>
					</tbody>
				</table>
				</li>
			</ul>
		</div>
		<div class="mb20"><span class="mr20"><span class="btn"><span><button name="Submit" type="submit">發布</button></span></span></span><label><input name="addnewpage" type="checkbox" value="1">&nbsp;保存後繼續編輯新分頁內容</label></div>
		<div class="c" >&nbsp;</div>
		<div id="divload"></div>
</div>
</div>
</form>


<script type="text/javascript" src="js/lang/zh_cn.js"></script>
<script type="text/javascript" src="js/post.js"></script>
<script type="text/javascript">
var maxLength=200;
function wordlength(target)
{
	var val = target.value;
	var n = 2*val.length-val.replace(/[\u4e00-\u9fa5]/g,'').length;
	var val=target.value;
	while(n>maxLength)
	{
		var key = val.substr(-1);
		target.value=val.substr(0,val.length-1);
		val = target.value;
		n -= /[\u4e00-\u9fa5]/.test(key)?2:1;
	}
	str='('+n+'/'+maxLength+')';
	var next = target.nextSibling;
	next.innerHTML=str;
	if(n==maxLength){
		next.className='s3';
		target.maxLength = val.length;
	}else{
		next.className="s6";
		target.maxLength = maxLength;
	}
}
document.FORM.Submit.disabled = false;
var cnt = 0;
function checkpost(obj) {
	var subjectTemp = obj.cms_subject.value.replace( /^\s*/, '');
	var atc_contentTemp = obj.atc_content.value.replace( /^\s*/, '');
	if (obj.cms_subject.value == "" || subjectTemp == "") {
		showDialog("error","文章<span class='s1'>標題</span>不能為空",2);
		obj.cms_subject.focus();
		return false;
	} else if (strlen(obj.cms_subject.value) > 80) {
		showDialog("error","文章<span class='s1'>標題</span>不能大于長度 <span class='s1'>80 </span>個字節",2);
		obj.cms_subject.focus();
		return false;
	}
	if (strlen(obj.atc_content.value) < 0 || atc_contentTemp == "") {
		showDialog({
			type: "error",
			message: "文章<span class='s1'>內容</span>不能為空",
			autoHide:2,
			onClose : function(){
				editor.focus();
			}
		});
		return false;
	} else if (strlen(obj.atc_content.value) > 50000) {
		showDialog("error","文章<span class='s1'>內容</span>不能大于 50000 個字節",2);
		editor.focus();
		return false;
	}
	var pattern = /\[url=(\d+)\]/gmi;
	var str = obj.atc_content.value;
	var res;
	while( (res = pattern.exec(str))!=null )
	{
		if(getObj('attachment_'+a[1]).value==''){
			str=str.replace(new RegExp('\\\\[url='+a[i]+'\]','gm'),'');
		}
	}
	obj.atc_content.value = str;
	SubmitAjax(obj);
	return false;
}
//ajax提交數據 
function SubmitAjax(obj) {
	document.FORM.Submit.disabled = true;
	getObj('divload').innerHTML = showLoading();
	cnt++;
	ajax.send("{$cmsBaseUrl}q=post", obj, function(){
		
		if(undefined == ajax.request.responseText || ajax.request.responseText.length > 500){
			showDialog({
				type: 'error',
				message: '<span class=\'s1\'>附件</span> 太大或網絡原因，請求超時，請稍後再試!'
			});
			document.FORM.Submit.disabled = false;
			getObj('divload').innerHTML = "";
			return false;
		}
		var rText = ajax.request.responseText.split('\t');
		if (rText[0] == 'success') {
			window.onbeforeunload = function(){};
			window.location =  rText[1];
		} else {
			showDialog('error', rText[0]);
		}
		cnt = 0;
		document.FORM.Submit.disabled = false;
		getObj('divload').innerHTML = "";
		return false;
	});
}
function showLoading(){
	return "<div id=\"loading\" style=\"padding:20px;width:80%;text-align:center\"><img src=\""+imgpath+"/loading.gif\" align=\"absbottom\" alt=\"loading\" /> 正在加載數據...</div>";
}
function addcols(mode,ft){
	var s = getObj(mode).firstChild.cloneNode(true);
	getObj(ft).appendChild(s);
}
function removecols(obj){
	var o = obj.parentNode.parentNode;
	o.parentNode.removeChild(o);
}

function deletePage() {
	var url = "{$basename}q=post&action=deletepage&id=$id&page=$page";
	window.location.href = url;
}

function getSourceData(id) {
	id = parseInt(id) - 0;
	if (!id || id == "NaN") {
		resetFormOnSubmit(false);
		return false;
	}
	var sourceType = getObj('sourcetype').value;
	window.location.href = "{$basename}q=post&sourcetype="+sourceType+"&sourceid="+id+"&cid={$cid}";
}

function resetFormOnSubmit(status){
	var aform = document.FORM;
	if(aform == null) return false;
	if(status==true) {
		aform.onsubmit = function(){return false};
	}else{
		aform.onsubmit = function() {return checkpost(document.FORM);};
	}
}

function getSourceDataByEnter(event,id){
	event = event ? event : (window.event ? window.event : null);
	if(event.keyCode == '13'){
		getSourceData(id);
	}
}
</script>
<!--
EOT;
?>-->