<!--{template 'head'}-->
<!--{if !AJAX}-->
<script language="JavaScript">
setSubject("门户数据维护");
function showPortalData(pid){
	var obj = $('item-'+pid);
	if($('portal_data') != null){
		if($('portal_data').rowIndex == obj.rowIndex+1){
			$('portal').deleteRow($('portal_data').rowIndex);
			if(arguments.length != 3) return false;
		}else{
			$('portal').deleteRow($('portal_data').rowIndex);
		}
	}
	var tr = $('portal').insertRow(obj.rowIndex+1);
	tr.id = 'portal_data';
	var td = tr.insertCell(0);
	td.className = 'tablerow';
	var td = tr.insertCell(1);
	td.className = 'tablerow';
	td.colSpan = '6';
	td.innerHTML = "<p class='loading_portal'>数据加载中...</p>";
	Ajax.get("system.php?sys=portal&action=data&pid="+pid+"&ordering="+(arguments.length == 1 ? 0 : arguments[1]), function(resp){
		$('portal_data').cells[1].innerHTML = resp;
	});
	return false;
};
function changePortalOrdering(id, obj){
	obj.value = obj.value.trim().replace(/[^\d]/g,'');
	clearTimeout(obj.timer);
	obj.timer = setTimeout(function(){
		var v = obj.value.trim();
		if(v.length == 0 || isNaN(parseInt(v))) return false;
		if(parseInt(v) == parseInt(obj.getAttribute('rel').trim())) return false;
		obj.style.background = "#fff url(images/loading.gif) no-repeat center center";
		Ajax.get("system.php?sys=portal&action=ordering&id="+id+"&val="+obj.value.trim(), function(resp){
			obj.style.backgroundImage = "none";
			obj.style.border = "2px solid #ddd";
			obj.setAttribute('rel', v);
		});
	},500);
};
function portalShowPic(thumb, obj){
	if(!thumb) return;
	var offset = fetchOffset(obj);
	var ele = $('show-pic');
	ele.innerHTML = "<img src='"+thumb+"' />";
	ele.style.left = offset.left + obj.offsetWidth + 'px';
	ele.style.top = offset.top + 'px';
	ele.style.display = 'block';
}
function portalHiddenPic(){
	$('show-pic').style.display = 'none';
}
</script>
<table cellpadding="0" cellspacing="0" border="0" align=center width=100% class="tableborder mt5" >
  <tr>
     <td class="tablerow"><b>管理选项：</b><a href="system.php?sys=portal&action=manage">数据块管理</a> | <a href="system.php?sys=portal&action=add">添加数据块</a></td>
  </tr>
</table>
<!--{/if}-->
<!--{if $action == 'manage'}-->
<table cellpadding="0" cellspacing="1" class="tableborder border mt5" id="portal">
	<tr align="center">
		<td width="40" class="tablerowhighlight">ID</td>
		<td class="tablerowhighlight">名称</td>
		<td width="80" class="tablerowhighlight">类型</td>
		<td width="60" class="tablerowhighlight">状态</td>
		<td width="100" class="tablerowhighlight">创建人</td>
		<td width="120" class="tablerowhighlight">创建时间</td>
		<td width="200" class="tablerowhighlight">操作</td>
	</tr>
	<!--{if $data}-->
	<!--{loop $data $val}-->
	<tr class="item" height=27 id="item-{$val[pid]}">
		<td class="tablerowl">{$val['pid']}</a></td>
		<td style="padding-left:5px;"><a href="javascript:void(0)" onclick="return showPortalData({$val['pid']})">{$val['p_title']}</a></td>
		<td align="center"><!--{if $val['p_type']}-->数据集<!--{else}-->HTML代码<!--{/if}--></td>
		<td align="center"><!--{if $val['p_status']}-->开放<!--{else}-->关闭<!--{/if}--></td>
		<td align="center">{$val[p_username]}</td>
		<td align="center"><!--{echo qbase::formatTime('Y-n-d H:i', $val['p_dateline'])}--></td>
		<td align="center">
			<!--{if $val['p_uid'] == $admin_info['uid']}-->
				<a href="system.php?sys=portal&action=delete&pid={$val['pid']}" onclick="return makeSure()">删除</a> | 
				<a href="system.php?sys=portal&action=edit&pid={$val['pid']}">修改</a> | 
			<!--{/if}-->
			<a href="javascript:void(0)" onclick="return showPortalData({$val['pid']})">数据管理</a> | 
			<a href="system.php?sys=portal&action=add_item&pid={$val['pid']}">添加数据</a>
		</td>
	</tr>
	<!--{/loop}-->
	<!--{else}-->
	<tr class="item" height=27>
		<td align="center" colspan="7">
			<p style="padding:12px;">没有找到相关数据</p>
		</td>
	</tr>
	<!--{/if}-->
</table>
<script type="text/javascript">
domReady(function(){
	var pid = {$pid};
	var obj = $('item-' + pid);
	if(obj == null) return;
	window.scrollTo(0, fetchOffset(obj).top);
	showPortalData(pid);
});
</script>
<!--{elseif $action == 'add' || $action == 'edit'}-->
<script type="text/javascript">
function selectAdmin(obj){
	var ele = $('editor');
	var admin = [];
	for(var i=0;i<ele.options.length;i++){
		admin.push(ele.options[i].value);
	}
	for(var i=0;i<obj.options.length;i++){
		if(obj.options[i].selected == true){
			if(!admin.inArray(obj.options[i].value)) ele.options.add(new Option(obj.options[i].text, obj.options[i].value));
			obj.options[i] = null;
			i--;
		}
	}
};
function removeAdmin(obj){
	var ele = $('admins');
	var admin = [];
	for(var i=0;i<ele.options.length;i++){
		admin.push(ele.options[i].value);
	}
	for(var i=0;i<obj.options.length;i++){
		if(obj.options[i].selected == true){
			if(!admin.inArray(obj.options[i].value)) ele.options.add(new Option(obj.options[i].text, obj.options[i].value));
			obj.options[i] = null;
			i--;
		}
	}
};
function checkPortal(){
	if(!$('p_title').value.trim()){
		$('p_title').focus();
		return false;
	}
	var ele = $('editor');
	for(var i=0;i<ele.options.length;i++){
		ele.options[i].selected = true;
	}
	return true;
}
</script>
<form method="post" id="myForm" name="myForm" action="system.php?sys=portal&action={$action}&pid={$pid}" onsubmit="return checkPortal()">
<table cellpadding="0" cellspacing="1" class="tableborder border mt5">
	<tr>
		<th colspan="2">添加/修改数据块</th>
	</tr>
	<tr>
		<td class="tablerowl" width="160">标题说明</td>
		<td class="tablerow">
			<input type="text" class="f-text" size="50" name="p_title" id="p_title" value="{$item['p_title']}" />
		</td>
	</tr>
	<tr>
		<td class="tablerowl">数据类型</td>
		<td class="tablerow">
			<!--{if $action == 'add'}-->
			<input name="p_type" type="radio" value="0" id="type_0" checked /><label for="type_0">自定义数据集</label>
			<input name="p_type" type="radio" value="1" id="type_1" /><label for="type_1">HTML代码</label>
			<!--{else}-->
			<input name="p_type" type="radio" value="0" id="type_0" <!--{if $item['p_type'] == 0}--> checked<!--{/if}--> /><label for="type_0">自定义数据集</label>
			<input name="p_type" type="radio" value="1" id="type_1" <!--{if $item['p_type'] == 1}--> checked<!--{/if}-->/><label for="type_1">HTML代码</label>
			<!--{/if}-->
			<p style="color:green">自定义数据集：可以添加多条含有标题，描述，封面等的数据</p>
			<p style="color:green;padding-left:14px;">HTML代码：就是一段自定义个html代码</p>
		</td>
	</tr>
	<tr>
		<td class="tablerowl">状态</td>
		<td class="tablerow">
			<!--{if $action == 'add'}-->
			<input name="p_status" type="radio" value="1" id="status_1" checked /><label for="status_1">开放</label>
			<input name="p_status" type="radio" value="0" id="status_0" /><label for="status_0">关闭</label>
			<!--{else}-->
			<input name="p_status" type="radio" value="1" id="status_1" <!--{if $item['p_status'] == 1}--> checked<!--{/if}--> /><label for="status_1">开放</label>
			<input name="p_status" type="radio" value="0" id="status_0" <!--{if $item['p_status'] == 0}--> checked<!--{/if}--> /><label for="status_0">关闭</label>
			<!--{/if}-->
			<p style="color:green">关闭后，将不允许再维护其所属的数据</p>
		</td>
	</tr>
	<tr>
		<td class="tablerowl">维护人员</td>
		<td class="tablerow">
			<select size="10" id="admins" multiple style="height:200px;width:160px" onclick="selectAdmin(this)">
				<!--{loop $admins $val}-->
				<option value="{$val['uid']}">{$val['username']}</option>
				<!--{/loop}-->
			</select>
			=>
			<select size="10" id="editor" name="editor[]" multiple  style="height:200px;width:160px" onclick="removeAdmin(this)">
				<!--{loop $editor $val}-->
				<option value="{$val['uid']}">{$val['username']}</option>
				<!--{/loop}-->
			</select>
		</td>
	</tr>
	<tr>
		<td class="tablerowl">HTML代码</td>
		<td class="tablerow">
			<textarea name="p_html" class="f-text" style="width:500px;height:120px;">{$item['p_html']}</textarea>
			<p style="color:green">只有在数据类型使用HTML代码的形式，这个才需要填写</p>
		</td>
	</tr>
	<tr>
		<td colspan="2" style="padding-left:180px;">
			<input type="submit" value=" 确定操作 " class="f-button" />
			<input type="hidden" name="myFormAc" value="update" />
		</td>
	</tr>
</table>
</form>
<!--{elseif $action == 'data'}-->
<table cellpadding="0" cellspacing="1" class="tableborder border">
	<tr>
		<th width="60">排序<!--{if $ordering}--><img onclick="showPortalData({$pid}, 0, true)" style="margin-left:6px;cursor:pointer" width="7" height="7" border="0" src="{AW_P}images/sma/order_asc.gif" /><!--{else}--><img onclick="showPortalData({$pid}, 1, true)" style="margin-left:6px;cursor:pointer" width="7" height="7" border="0" src="{AW_P}images/sma/order_desc.gif" /><!--{/if}--></th>
		<th width="40">封面</th>
		<th>标题</th>
		<th width="100">操作</th>
	</tr>
	<!--{if $data}-->
	<!--{loop $data $val}-->
	<tr>
		<td class="tablerow" align="center"><input type="text" size="6" value="{$val['ordering']}" rel="{$val['ordering']}" style="text-align:center" onkeyup="changePortalOrdering({$val['id']}, this)" /></td>
		<td class="tablerow" align="center">
			<!--{if $val['thumb']}-->
			<img src="{AW_P}images/viewpic.gif" onmouseover="portalShowPic('{$val['thumb']}', this)" onmouseout="portalHiddenPic()" />
			<!--{else}-->
			<img src="{AW_P}images/viewpic_no.gif" />
			<!--{/if}-->
		</td>
		<td class="tablerow"><a href="{$val['url']}" target="_blank" title="{$val['url']}&#10;{$val['description']}" style="color:{$val['subject_color']}">{$val['subject']}</a></td>
		<td class="tablerow" align="center"><a href="system.php?sys=portal&action=edit_item&id={$val['id']}">修改</a> | <a href="" onclick="">删除</a></td>
	</tr>
	<!--{/loop}-->
	<!--{else}-->
	<tr>
		<td colspan="4" class="tablerow"><p style="padding:12px;text-align:center">还没有数据</p></td>
	</tr>
	<!--{/if}-->
</table>
<!--{elseif $action == 'add_item' || $action == 'edit_item'}-->
<script type="text/javascript">
function itemSubmit(id){
	document.forms[id].submit.disabled = true;
	Form.send(id, function(resp){
		var json = evaljson(resp);
		if(json['status'] != 200){
			alert(json['message']);
			document.forms[id].submit.disabled = false;
		}else{
			window.location.href = "system.php?sys=portal&action=manage&pid={$pid}";
		}
	})
	return false;
}
</script>
<form method="post" id="myForm" name="myForm" action="system.php?sys=portal&action={$action}&pid={$pid}&id={$id}" onsubmit="return itemSubmit(this.id)">
	<table cellpadding="0" cellspacing="1" class="tableborder border mt5" id="portal">
		<tr>
			<td class="tablerowl" width="200"><font color="red">数据标题</font></td>
			<td class="tablerow">
				<input type="text" class="f-text" name="subject" value="{$item['subject']}" size="50" id="subject" />
				<input type="text" class="f-text"	name='subject_color' onchange="this.style.backgroundColor=this.value" id='subject_color' value="{$item['subject_color']}" size="7" />
				<input type="button" onclick="return getColor(this, 'subject_color');" value="选择颜色" />
			</td>
		</tr>
		<tr>
			<td class="tablerowl"><font color="red">数据地址</font></td>
			<td class="tablerow"><input type="text" class="f-text" name="url" value="{$item['url']}" size="50" /></td>
		</tr>
		<tr>
			<td class="tablerowl">封面图片</td>
			<td class="tablerow">
				<input type="text" class="f-text" name="thumb" id="thumb" value="{$item['thumb']}" size="50" />
				<input type="button" onclick="qmeCms.dialogView.iframe('上传图片','system.php?sys=upload&id=thumb&channelid=0',{type:'abs'});" value="上传图片" />
			</td>
		</tr>
		<tr>
			<td class="tablerowl">描述</td>
			<td class="tablerow"><textarea class="f-text" name="description" style="width:366px;height:60px;">{$item['description']}</textarea></td>
		</tr>
		<tr>
			<td class="tablerowl">排序</td>
			<td class="tablerow">
				<input type="text" class="f-text" name="ordering" value="{$item['ordering']}" size="4" style="text-align:center" />
				<span style="color:green">排序方式由前台调用方式决定</span>
			</td>
		</tr>
		<tr>
			<td class="tablerowl">打开放式</td>
			<td class="tablerow">
				<select name="target">
					<option value="_self"<!--{if $item['target'] == '_self'}--> selected<!--{/if}-->>当前窗口</option>
					<option value="_blank"<!--{if $item['target'] == '_blank'}--> selected<!--{/if}-->>新窗口</option>
					<option value="_top"<!--{if $item['target'] == '_top'}--> selected<!--{/if}-->>父窗口</option>
				</select>
			</td>
		</tr>
		<tr>
			<td class="tablerow" style="padding-left:210px" colspan="2">
				<input type="submit" name="submit" value="确定操作" class="f-button" />
				<input type="hidden" name="myFormAc" value="update" />
			</td>
		</tr>
	</table>
</form>
<!--{/if}-->
<!--{template 'foot'}-->