<!--#include file="admin_conn.asp"-->
<!--#include file="../inc/pinyin.asp"-->
<%
chkLogin
dim action : action = be("get","action")
session("upfolder") = "../upload/art"

select case action
	case "add","edit" : headAdmin "文章管理" : info
	case "save" : save
	case else : headAdmin "文章管理" : main
end select
dispseObj()

sub save
	dim a_id,a_title,a_subtitle,a_entitle,a_letter,a_from,a_type,a_content,a_author,a_color,a_hits,a_dayhits,a_weekhits,a_monthhits,a_hide,a_addtime,a_time,a_hitstime,a_pic,a_topic,a_level
	dim backurl,flag,uptime,rndhits
	
	a_id = be("post","a_id") : a_title = be("post","a_title") : a_subtitle = be("post","a_subtitle") : a_entitle = be("post","a_entitle")
	a_type = be("post","a_type") : a_content = request.Form("a_content") : a_author = be("post","a_author") : a_color = be("post","a_color")
	a_hits = be("post","a_hits") : a_dayhits = be("post","a_dayhits") : a_weekhits = be("post","a_weekhits") : a_monthhits = be("post","a_monthhits")
	a_hide = be("post","a_hide") : a_addtime = be("post","a_addtime") : a_time = be("post","a_time") : a_hitstime = be("post","a_hitstime")
	a_pic = be("post","pic") : a_from = be("post","a_from") : a_letter = be("post","a_letter") : a_topic = be("post","a_topic")
	a_level = be("post","a_level")
	
	backurl = be("post","backurl") : flag = be("post","flag") : uptime = be("post","uptime") : rndhits = be("post","rndhits")
	
	if isN(a_addtime) then a_addtime=now
	if (flag = "edit" and uptime="1") or (flag = "add") then a_time = Now
	if(rndhits="1") then a_hits = rndNum(1,1000)
	if isN(a_title) then writeE "标题不能为空"
	if not isNum(a_type) then writeE "分类不能为空"
	if not isNum(a_hits) then a_hits= 0
	if not isNum(a_topic) then a_topic= 0
	If not isNum(a_level) Then a_level = 0
	If not isNum(a_hide) then a_hide = 0
	If Not isNum(a_hits) Then d_hits = 0
    If Not isNum(a_dayhits) Then a_dayhits = 0
    If Not isNum(a_weekhits) Then a_weekhits = 0
    If Not isNum(a_monthhits) Then a_monthhits = 0
	if isN(a_entitle) then a_entitle = Hanzi2Pinyin(a_title)
	if isN(a_letter) then a_letter = UCase(left(a_entitle,1))
	
	if( instr(a_entitle,"*") or instr(a_entitle,":") or instr(a_entitle,"?") or instr(a_entitle,"""")  or instr(a_entitle,"<")  or instr(a_entitle,">")  or instr(a_entitle,"|") or instr(a_entitle,"\")) then
		writeE "名称和拼音名称中: 不能出现英文输入状态下的 * : ? "" < > | \ 等特殊符号"
	end if
	
	if flag="edit" then
		objdb.Update "{pre}art",Array("a_title","a_subtitle","a_entitle","a_letter","a_from","a_type","a_content","a_author","a_color","a_hits","a_dayhits","a_weekhits","a_monthhits","a_hide","a_time","a_pic","a_topic","a_level"),Array(a_title,a_subtitle,a_entitle,a_letter,a_from,a_type,a_content,a_author,a_color,a_hits,a_dayhits,a_weekhits,a_monthhits,a_hide,a_time,a_pic,a_topic,a_level),"a_id="&a_id
	else
		backurl="admin_art.asp?action=add"
		objdb.Add "{pre}art",Array("a_title","a_subtitle","a_entitle","a_letter","a_from","a_type","a_content","a_author","a_color","a_hits","a_dayhits","a_weekhits","a_monthhits","a_addtime","a_time","a_pic","a_topic","a_level"),Array(a_title,a_subtitle,a_entitle,a_letter,a_from,a_type,a_content,a_author,a_color,a_hits,a_dayhits,a_weekhits,a_monthhits,a_addtime,a_time,a_pic,a_topic,a_level)
	end if
	writeA "保存完毕"
end sub

sub main
	dim sql,rs,aWhere,keyword,stype,pagenum,order,topic,typearr,hide,repeat, repeatlen,level
	keyword = be("all","keyword") : stype = be("all","stype")
	order = be("all","order") :  topic = be("all","topic")
	pagenum = be("all","page") : hide = be("all", "hide")
	repeat = be("all", "repeat"):   repeatlen = be("all", "repeatlen")
	level = be("all","level")
	
	if not isNum(stype) then stype =0 else stype=clng(stype)
	if not isNum(topic) then topic =0 else topic=cint(topic)
	If Not isNum(hide) Then hide = -1 else hide=cint(hide)
	If Not isNum(level) Then level = 0 Else level = CInt(level)
	if Not isNum(repeatlen) then repeatlen=0
	if not isNum(pagenum) then pagenum = 1
	if pagenum < 1 then pagenum = 1
	pagenum = clng(pagenum)
	aWhere = " 1=1 "
	
	if not isN(keyword) then 
		aWhere = aWhere & " AND a_title LIKE '%"&keyword&"%' "
	end if
	
	if stype >0 then
		typearr = getValueByArray(cachearttype, stype)
	    if isarray(typearr) then
    		aWhere = aWhere & " AND a_type in( " & typearr(10) & ") "
    	else
    		aWhere = aWhere & " AND a_type=" & stype & " "
    	end if
	end if
	if stype =-1 then aWhere = aWhere & " AND a_type =0 "
	if topic >0 then aWhere = aWhere & " AND a_topic = "&topic&" "
	If level > 0 Then aWhere = aWhere & " AND a_level = " & level & " "
	If hide > -1 then
    	aWhere = aWhere & " AND a_hide= " & hide &" "
    end if
    If repeat = "ok" Then
        Dim repeatSearch: repeatSearch = " a_title "
        If app_dbtype = "access" And repeatlen > 0 Then
            repeatSearch = " LEFT(a_title," & repeatlen & ") "
        ElseIf app_dbtype = "mssql" And repeatlen > 0 Then
            repeatSearch = " SUBSTRING(a_title,0," & repeatlen & ") "
        End If
        aWhere = aWhere & " AND a_title IN (SELECT " & repeatSearch & " FROM {pre}art GROUP BY " & repeatSearch & " HAVING COUNT(*)>1) "
    End If
	if isN(order) then order = "a_addtime"
	
	sql = "SELECT a_id, a_title,a_subtitle, a_entitle, a_type,a_topic, a_content, a_author, a_color, a_addtime,a_time, a_hits,a_hide,a_level FROM {pre}art WHERE "  & aWhere & "ORDER BY "&order&" Desc"
	Set rs = objdb.DB(sql,"rs1")
%>
<script language="javascript">
$(document).ready(function(){
	$("#btnsearch").click(function(){
		$("#repeatok").val("");
		filter();
	});
	$("#btnrepeat").click(function(){
		var repeatlen = $("#repeatlen").val();
		var reg = /^\d+$/;
		var re = repeatlen.match(reg);
		if (repeatlen=="" || !re){ repeatlen=0; }
		if (repeatlen >10){ alert("长度最大10");$("#repeatlen").focus();return;}
		$("#repeatok").val("ok");
		filter();
	});
	$("#btnDel").click(function(){
			if(confirm('确定要删除吗')){
				$("#form1").attr("action","admin_ajax.asp?action=del&tab={pre}art");
				$("#form1").submit();
			}
			else{return false}
	});
	$("#plsc").click(function(){
		var ids="",rc=false;
		$("input[name='a_id']").each(function() {
			if(this.checked){
				if(rc)ids+=",";
				ids =  ids + this.value;
				rc=true;
			}
        });
		$("#form1").attr("action","admin_makehtml.asp?action=viewpl&flag=art&d_id="+ids);
		$("#form1").submit();
	});
});

function filter(){
	var url = "admin_art.asp?keyword="+encodeURI($("#keyword").val())+"&stype="+$("#stype").val()+"&level="+$("#level").val()+"&topic="+$("#topic").val()+"&order="+$("#order").val()+"&hide="+$("#hide").val()+"&repeat="+$("#repeatok").val()+"&repeatlen="+$("#repeatlen").val();
	window.location.href=url;
}
function gosyncpic(){
	if(confirm('确定要同步下载远程图片吗?数据不可恢复，请做好备份')){
		location.href='admin_pic.asp?action=syncartpic';
	}
}
</script>
<table class="tb">
    <tr>
	<td>
	<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1">
	<tr>
	<td colspan="2" >
	过滤条件：<select id="stype" name="stype">
	<option value="0">文章栏目</option>
	<option value="-1" <%if stype=-1 then%>selected <%end if%>>没有栏目</option>
	<%=makeSelectAll("{pre}art_type","t_id","t_name","t_pid","t_sort",0,"","&nbsp;|&nbsp;&nbsp;",stype)%>
	</select>
	&nbsp;<select id="topic" name="topic" >
	<option value="">请选择专题</option>
	<%=makeSelect("{pre}art_topic","t_id","t_name","t_sort","","&nbsp;|&nbsp;&nbsp;",topic)%>
	</select>
	&nbsp;
	<select id="order" name="order">
	<option value="a_time">文章排序</option>
	<option value="a_id" <%if order="a_id" then%>selected<%end if%>>文章编号</option>
	<option value="a_hits" <%if order="a_hits" then%>selected<%end if%>>文章人气</option>
	</select>
	&nbsp;
		<select id="level" name="level">
		<option value="0">文章推荐</option>
		<option value="1" <%if level=1 then%>selected <%end if%>>推荐1</option>
		<option value="2" <%if level=2 then%>selected <%end if%>>推荐2</option>
		<option value="3" <%if level=3 then%>selected <%end if%>>推荐3</option>
		<option value="4" <%if level=4 then%>selected <%end if%>>推荐4</option>
		<option value="5" <%if level=5 then%>selected <%end if%>>推荐5</option>
		</select>
	&nbsp;
	<select id="hide" name="hide">
		<option value="-1">文章显隐</option>
		<option value="0" <%if hide=0 then%>selected <%end if%>>显示</option>
		<option value="1" <%if hide=1 then%>selected <%end if%>>隐藏</option>
	</select>
	</td>
	</tr>
	<tr>
	<td>
	关键字：<input id="keyword" size="40" name="keyword" value="<%=keyword%>">
	<input class="input" type="button" value="搜索" id="btnsearch" >
	<% 
		if repeat<>"ok" then
			writeA "<span style=""display:none"">"
		else
			writeA "<span>"
		end if
	%>
	&nbsp; 检测名称长度：<input id="repeatlen" size="2" name="repeatlen" value="">
	<input type="hidden" id="repeatok" value="">
	&nbsp;<input class="input" type="button" value="检测重复数据" id="btnrepeat" >
	</span>
	</td>
	<td width="150">
	&nbsp;<span>【<a href="###" onclick="javascript:gosyncpic();"><font color="red"><strong>同步下载远程图片</strong></font></a>】</span>
	</td>
	</tr>
	</table>
	</td>
	</tr>
</table>
<form action="" method="post" id="form1" name="form1">
<table class="tb">
	<tr>
	<td width="4%">&nbsp;</td>
	<td>标题</td>
	<td width="9%">分类</td>
	<td width="6%">人气</td>
	<td width="5%">推荐</td>
	<td width="5%">专题</td>
	<td width="5%">浏览</td>
	<td width="15%">更新时间</td>
	<td width="15%">操作</td>
    </tr>
	<%
		if rs.eof then
	 %>
    <tr><td align="center" colspan="7">没有任何记录!</td></tr>
    <%
		else
		dim i,mlink,tname,tenname
		rs.PageSize = app_pagenum
	    rs.AbsolutePage = pagenum
	  	for i = 1 to rs.PageSize
	  		if rs.eof then exit for
	  		tname= "未知"
			tenname=""
	  		typearr = getValueByArray(cachearttype, rs("a_type"))
	    	if isarray(typearr) then
	  			tname= typearr(1)
				tenname=typearr(2)
	  		end if
	%>
    <tr>
	<td><input name="a_id" type="checkbox" id="a_id" value="<%=rs("a_id")%>" /></td>
	<td><%=getColorText(rs("a_title"),rs("a_color"),0)%>
	<%if rs("a_hide")=1 then%><%="<font color=""red"">[隐藏]</font>"%><%end if%>
	</td>
	<td><%=tname%></td>
	<td><%=rs("a_hits")%></td>
	<td id="tj<%=rs("a_id")%>">
	<%="<img src=""../images/icons/ico"&rs("a_level")&".gif"" border=""0"" style=""cursor: pointer;"" onClick=""setday('tj','"&rs("a_id")&"','art')""/>"%>
	</td>
	<td id="zt<%=rs("a_id")%>" >
	<%if rs("a_topic")=0 then%>
	<%="<img src=""../images/icons/icon_02.gif"" border=""0"" style=""cursor: pointer;"" onClick=""setday('zt','"&Rs("a_id")&"','art')""/>"%>
	<%else%>
	<%="<img src=""../images/icons/icon_01.gif"" border=""0"" style=""cursor: pointer;"" onClick=""ajaxdivdel('"&Rs("a_id")&"','zt','art')""/>"%>
	<%end if%>
	</td>
	<td>
	<%
		if rs("a_type") = 0 Then
			mlink = "#"
		else
	 		mlink = ".." & objTemplate.getArtLink(rs("a_id"),rs("a_title"),rs("a_entitle"),rs("a_type"),rs("a_addtime"),tname,tenname,true)
		end if
		mlink = replaceStr(mlink, ".." & app_installdir, "../")
		
		if right(mlink,1)="/" then mlink = mlink & "index." & app_artsuffix
		if app_artcontentviewtype = 2 then
		 if objFile.IsFileExists(mlink) then
		 	%>
		 	<a target="_blank" href="<%=mlink%>"><Img src="../images/icons/html_ok.gif" border="0" alt='浏览' /></a>
		 	<%
		 else
		 	%>
		 	<a  href="admin_makehtml.asp?action=viewpl&flag=art&d_id=<%=rs("a_id")%>"><Img src="../images/icons/html_no.gif" border="0" alt='生成' /></a>
		 	<%
		 end if
	 else
	 %>
	 <a target="_blank" href="<%=mlink%>"><Img src="../images/icons/html_ok.gif" border="0" alt='浏览' /></a>
	 <%
	 end if
	%>
	</td>
	<td><%=getColorDay(rs("a_time"))%></td>
	<td><A href="admin_art.asp?action=edit&a_id=<%=rs("a_id")%>">修改</a> | <a href="admin_ajax.asp?action=del&tab={pre}art&a_id=<%=rs("a_id")%>" onClick="return confirm('确定要删除吗?');">删除</a></td>
    </tr>
	<%
	rs.MoveNext
	next 
	end if
	%>
	<tr>
	<td colspan="9">
    全选<input name="chkall" type="checkbox" id="chkall" value="1" onClick="checkAll(this.checked,'a_id');"/>&nbsp;
	批量操作：<input type="button" id="btnDel" value="删除" class="input" />
	<input type="button" id="pltj" value="推荐" onClick="plset('pltj','art')" class="input">
	<input type="button" id="plfl" value="分类" onClick="plset('plfl','art')" class="input">
	<input type="button" id="plzt" value="专题" onClick="plset('plzt','art')" class="input">
	<input type="button" id="plrq" value="人气" onClick="plset('plrq','art')" class="input">
	<input type="button" id="plsc" value="生成" class="input">
	<input type="button" id="plyc" value="显隐" onClick="plset('plyc','art')" class="input">
	<span id="plmsg" name="plmsg"></span>
	</td></tr>
	<tr>
	<td align="center" colspan="8">   	<%=pagelist_manage(rs.PageCount,pagenum,rs.RecordCount,app_pagenum,"admin_art.asp?page={p}&stype="&stype&"&keyword="&keyword&"&order="&order&"&hide="&hide&"&topic="&topic&"&level="&level&"&repeat="&repeat&"&repeatlen="&repeatlen)%>
	</td>
    </tr>
</table>
</form>
<%
objdb.c(rs)
end sub

sub info
	dim rs,backurl
	dim a_id,a_title,a_subtitle,a_entitle,a_letter,a_from,a_type,a_content,a_author,a_color,a_hits,a_dayhits,a_weekhits,a_monthhits,a_hide,a_addtime,a_time,a_hitstime,a_pic,a_topic,a_level
	backurl = getReferer()
	if isN(backurl) or instr(backurl,"index.asp")>0 then backurl="admin_art.asp"
	if action="edit" then
		a_id = be("get","a_id")
		Set rs = objdb.DB("SELECT * FROM {pre}art WHERE a_id=" & a_id,"rs1")
		if rs.eof then objdb.c(rs): errmsg "系统信息","错误没有找到该数据"
		a_title=rs("a_title") : a_subtitle=rs("a_subtitle") : a_entitle=rs("a_entitle") : a_type=rs("a_type")
		a_content=rs("a_content") : a_author=rs("a_author") : a_color=rs("a_color") : a_hits=rs("a_hits")
		a_dayhits=rs("a_dayhits") : a_weekhits=rs("a_weekhits") : a_monthhits=rs("a_monthhits") : a_hide=rs("a_hide")
		a_addtime=rs("a_addtime") : a_time=rs("a_time") : a_hitstime=rs("a_hitstime") : a_pic=rs("a_pic")
		a_from=rs("a_from") : a_letter=rs("a_letter") : a_topic=rs("a_topic") : a_level=rs("a_level")
		objdb.c(rs)
	else
		a_from="本站"
		a_author=app_sitename
	end if
%>
<script language="javascript" src="editor/xheditor-zh-cn.min.js"></script>
<script language="javascript" src="editor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="../js/adm/jscolor.js"></script>
<script language="javascript">
var ac="<%=action%>"
$(document).ready(function(){
	$("#form1").validate({
		rules:{
			a_type:{
				required:true
			},
			a_title:{
				required:true,
				maxlength:128
			},
			a_letter:{
				maxlength:1
			},
			a_hits:{
				number:true
			}
		}
	});
	$('#form1').form({
		onSubmit:function(){
			if(!$("#form1").valid()) {return false;}
		},
	    success:function(data){
	        if (ac=="add"){
		        $.messager.defaults.ok = "确定";
				$.messager.defaults.cancel = "返回";
				$.messager.confirm('系统提示', '是否继续添加数据?', function(r){
					if(r==true){
						location.href = "admin_art.asp?action=add";
					}
					else{
		        		location.href = $("#backurl").val();
		        	}
		        });
	        }
	        else{
	        	location.href = $("#backurl").val();
	        }
	    }
	});
	$("#btnCancel").click(function(){
		location.href = $("#backurl").val();
	});
});
</script>
<div id="showpic" style="display:none;"><img name="showpic_img" id="showpic_img" width="120" height="160"></div>
<form action="?action=save" method="post" name="form1" id="form1">
<table class="tb">
	<input name="flag" type="hidden" value="<%=action%>">
	<input name="a_id" type="hidden" value="<%=a_id%>">
	<input name="a_addtime" type="hidden" value="<%=a_addtime%>">
	<input name="a_time" type="hidden" value="<%=a_time%>">
	<input id="backurl" name="backurl" type="hidden" value="<%=backurl%>">
	<tr>
	<td width="20%">文章标题：</td>
	<td>
	&nbsp;<select id="a_type" name="a_type" >
	<option value="">请选择分类</option>
	<%=makeSelectAll("{pre}art_type","t_id","t_name","t_pid","t_sort",0,"","&nbsp;|&nbsp;&nbsp;",a_type)%>
	</select>
	&nbsp;<select id="a_topic" name="a_topic" >
	<option value="">请选择专题</option>
	<%=makeSelect("{pre}art_topic","t_id","t_name","t_sort","","&nbsp;|&nbsp;&nbsp;",a_topic)%>
	</select>
	&nbsp;<select id="a_level" name="a_level" >
	<option value="">选择推荐值</option>
	<option value="1" <%if a_level = 1 then%> selected <%end if%>>推荐1</option>
	<option value="2" <%if a_level = 2 then%> selected <%end if%>>推荐2</option>
	<option value="3" <%if a_level = 3 then%> selected <%end if%>>推荐3</option>
	<option value="4" <%if a_level = 4 then%> selected <%end if%>>推荐4</option>
	<option value="5" <%if a_level = 5 then%> selected <%end if%>>推荐5</option>
	</select>
	&nbsp;<select id="a_hide" name="a_hide">
	<option value="0" <%if a_hide=0 then%>selected<%end if%>>显示</option>
	<option value="1" <%if a_hide=1 then%>selected<%end if%>>隐藏</option>
	</select>
	&nbsp;<input type="checkbox" name="uptime" value="1" checked>更新时间
	&nbsp;<input type="checkbox" name="rndhits" value="1" >随机人气
	</td>
	</tr>
	<tr>
	<td>文章标题：</td>
	<td>
	&nbsp;<input id="a_title" name="a_title" size=70 value="<%=a_title%>" >
	&nbsp;高亮颜色：<input id="a_color" name="a_color" type="text" size="5" class="color" value="<%=a_color%>" style="background-color:<%=a_color%>">
	</td>
	</tr>
	<tr>
	<td>文章副标：</td>
	<td>
	&nbsp;<input id="a_subtitle" name="a_subtitle" size=70 value="<%=a_subtitle%>" >
	</td>
	</tr>
	<tr>
	<td>拼音标题：</td>
	<td>
	&nbsp;<input id="a_entitle" name="a_entitle" size=70 value="<%=a_entitle%>" >
	&nbsp;首字母：<input id="a_letter" name="a_letter" size=4 value="<%=a_letter%>" >
	</td>
	</tr>
	<tr>
	<td>文章作者：</td>
	<td>
	&nbsp;<input id="a_author" name="a_author" size="40" value="<%=a_author%>" >
	&nbsp;文章来源：&nbsp;<input id="a_from" name="a_from" size="40" value="<%=a_from%>" >
	</td>
	</tr>
	<tr> 
    <td>图片：</td>
    <td>&nbsp;<input id="pic" name="pic" type="text" size="50" value="<%=a_pic%>" onMouseOver="showpic(event,this.value);" onMouseOut="hiddenpic();"/>&nbsp;<iframe src="editor/uploadshow.asp?action=art" scrolling="no" topmargin="0" width="320" height="24" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe></td>
	</tr>
	<tr>
	<td>其他：</td>
	<td>总人气：<input id="a_hits" name="a_hits" type="text" size="8" value="<%=a_hits%>">
	&nbsp;月人气：<input id="a_monthhits" name="a_monthhits" type="text" size="8" value="<%=a_monthhits%>">
	&nbsp;周人气：<input id="a_weekhits" name="a_weekhits" type="text" size="8" value="<%=a_weekhits%>">
	&nbsp;日人气：<input id="a_dayhits" name="a_dayhits" type="text" size="8" value="<%=a_dayhits%>">
	</td>
	</tr>
	<tr>
	<td>文章内容：<br>分页标示[artinfo:page]<br>模板中调用分页标签{maccms:page才解析分页 </td>
	<td>
<textarea name="a_content" id="a_content" class="xheditor {tools:'BtnBr,Cut,Copy,Paste,Pastetext,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,Align,List,Outdent,Indent,Link,Unlink,Img,Flash,Media,Table,Source,Fullscreen',width:'630',height:'250',upBtnText:'上传',html5Upload:false,upMultiple:1,upLinkUrl:'{editorRoot}upload.asp?action=xht',upImgUrl:'{editorRoot}upload.asp?action=xht'}"><%=a_content%></textarea>
      </td>
	</tr>
	<tr align="center">
	<td colspan="2"><input class="input" type="submit" value="保存" id="btnSave"> <input class="input" type="button" value="返回" id="btnCancel"> </td>
    </tr>
</table>
</form>
<%
end sub
%>
</body>
</html>