<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 4
set sdcms=nothing
set sdcms_f=new sdcms_function
id=sdcms_f.Requestint(id)
classid=sdcms_f.Requestint(classid)
set sdcms_f=nothing
select case action
case "add":title="添加单页"
case "edit":title="修改单页"
case else:stype="main":title="单页面管理"
end select
sd_table="sd_other"
followid=trim(request("followid"))
ordnum=trim(request("ordnum"))
sdcms_head
%>

<div class="sdcms_notice"><span>管理操作：</span><a href="?action=add">添加单页面</a>　┊　<a href="?">单页面管理</a></div>
<br>
<ul id="sdcms_sub_title">
	<li class="sub"><%=title%></li><%if stype<>"main" then%><li class="unsub"><a href="javascript:void(0)" onclick="$('upfiles').style.visibility='inherit'">附件上传</a></li><%end if%>
</ul><div style="visibility:hidden;position:absolute;margin:0 0 0 88px;*margin:-27px 0 0 88px;border:1px solid #FCBA72;background:#fff;padding:5px 10px;width:300px;" id="upfiles"><img src="images/close.gif"  style="position:absolute;margin:10px 0 0 242px;cursor:pointer;" onclick="$('upfiles').style.visibility='hidden'" alt="关闭" /><%admin_upfile 3,"280","30",1%></div>
<div id="sdcms_right_b">
<%
select case action
case "add":add
case "edit":edit
case "save":save
case "up":up
case "down":down
case "makehtml":makehtml
case "del":del
case else:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b">
    <form name="add" action="?" method="post"  onSubmit="return confirm('确定要执行选定的操作吗？');">
	<tr>
	  <td class="title_bg">选择</td>
  
      <td width="120" class="title_bg">标题</td>
	  <td class="title_bg">排序</td>
      <td width="250" class="title_bg">调用</td>
      <td class="title_bg">管理</td>
    </tr>
	<%sdsort(0)%>
	<tr>
      <td colspan="5" class="tdbg" >
	 <input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox"> 全选 
              <select name="action">
			  <option>→操作</option>
			  <option value="makehtml">生成 </option>
			  </select> 
             
      <input type="submit" class="bnt01" value="执行"></td>
    </tr>
	</form>
  </table>

<%
end sub
sub add
check_info
set sdcms_f=new Sdcms_Function
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=add" onSubmit='return checkadd()'>
    <tr>
      <td width="12%" align="center" class="tdbg">标　题：      </td>
      <td class="tdbg"><input name="t0" type="text" class="input" id="t0" size="40"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">类　别：      </td>
      <td><select name="t1" >
          <option value='0' >无类别</option>
<%ssort 0%>
        </select></td>
    </tr>
  <tr class="tdbg">
      <td align="center">模　板：</td>
      <td>   <select name='t2'><option value='0'>默认模板</option>
	  <%set temprs=conn.execute("select id,title from sd_temp where classid=3 order by id desc")
while not temprs.eof
echo "<option value='"&temprs(0)&"'>"&temprs(1)&"</option>"
temprs.movenext
wend%></select>	  </td>
    </tr>
   <tr class="tdbg">
     <td align="center">目录名：</td>
     <td><input name="t6" type="text" class="input" /><span>可以为空,不支持多级目录</span></td>
   </tr>
   <tr class="tdbg">
     <td align="center">文件名：</td>
     <td><input name="t5" value="<%=sdcms_filename%>" type="text" class="input" /><%=sdcms_filetxt%> </td>
   </tr>
   <tr class="tdbg">
      <td align="center">内　容：</td>
      <td><%if sdcms_editor_type=0 then%><span id="loadedit" style="font-size:12px"><img src='../editor/loading.gif' align='absbottom'> 正在载入编辑器...</span><%elseif sdcms_editor_type=1 then
	sdcms_f.ewebEditor "t3","600","300"
	 end if%><textarea name="t3" id="t3" style="display:none"></textarea><br><input name="t4" id="t4" type="checkbox" value="1" /><label for="t4">保存远程图片</label></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="添 加">
        <input type="button" onClick="history.go(-1)" class="bnt" value="返 回"> <%if sdcms_editor_type=1 then%><input type="button" onClick="eWebEditor1.insertHTML('$show_page$')" class="bnt" value="插入分页"><%end if%></td>
    </tr>
	</form>
  </table>
<%
if sdcms_editor_type=0 then
	sdcms_f.HtmlEditor 1,"t3","600","260",0
end if
set sdcms_f=nothing
end sub
sub edit
set rs=conn.execute("select id,title,followid,tempid,content,htmlname,pagedir from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
check_info
set sdcms_f=new Sdcms_Function
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=save&id=<%=id%>" onSubmit='return checkadd()'>
    <tr>
      <td width="12%" align="center" class="tdbg">标　题：      </td>
      <td class="tdbg"><input name="t0" type="text" class="input" value="<%=rs(1)%>" id="t0" size="30"></td>
    </tr>
     <tr class="tdbg">
      <td align="center">类　别：      </td>
      <td><select name="t1" >
          <option value='0'>无类别</option>
          <%ssort 0%>
        </select></td>
    </tr>
  <tr class="tdbg">
      <td align="center">模　板：</td>
      <td>   <select name='t2'><option value='0'>默认模板</option>
	  <%set temprs=conn.execute("select id,title from sd_temp where classid=3 order by id desc")
while not temprs.eof
echo "<option value='"&temprs(0)&"' "&w_select(rs(3),temprs(0))&">"&temprs(1)&"</option>"
temprs.movenext
wend%></select>
	  </td>
    </tr>
	<tr class="tdbg">
     <td align="center">目录名：</td>
     <td><input name="t6" value="<%=dir_check(rs(6))%>" type="text" class="input" /><span>可以为空,不支持多级目录</span></td>
   </tr>
   <tr class="tdbg">
     <td align="center">文件名：</td>
     <td><input name="t5" value="<%=rs(5)%>"  type="text" class="input" /><%=sdcms_filetxt%> </td>
   </tr>
   <tr class="tdbg">
      <td align="center">内　容：</td>
      <td><%if sdcms_editor_type=0 then%><span id="loadedit" style="font-size:12px"><img src='../editor/loading.gif' align='absbottom'> 正在载入编辑器...</span><%elseif sdcms_editor_type=1 then
	sdcms_f.ewebEditor "t3","600","300"
	 end if%><textarea name="t3" id="t3" style="display:none"><%=sdcms_f.TempEncode(rs(4))%></textarea><br><input name="t4" id="t4" type="checkbox" value="1" /><label for="t4">保存远程图片</label></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input type="button" onClick="history.go(-1)" class="bnt" value="返 回"> <%if sdcms_editor_type=1 then%><input type="button" onClick="eWebEditor1.insertHTML('$show_page$')" class="bnt" value="插入分页"><%end if%></td>
    </tr>
	</form>
  </table>
<%
if sdcms_editor_type=0 then
	sdcms_f.HtmlEditor 1,"t3","600","260",0
end if
set sdcms_f=nothing
end sub
sub save

t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=trim(request("t3"))
t4=trim(request("t4"))
t5=dir_check(trim(request("t5")))
t6=dir_check(trim(request("t6")))&"/"
if t6<>"/" then t6="/"&t6

if t6="/" then
	t5=Replace_filename(t5,0)
else
	t5=Replace_filename(t5,1)
end if

if t4<>"" then t3=ReplaceRemoteUrl(t3)
if act="save" then
	if id=t1 then
		echo "类别选择错误":Died
	end if
end if
set rs=server.CreateObject("adodb.recordset")
sql="select title,followid,tempid,content,id,ordnum,htmlname,pagedir from "&sd_table&""
if act="save" then 
 sql=sql&" where id="&id&""
end if
rs.open sql,conn,1,3

if act="add" then 
  rs.addnew
else
  rs.update
end if
rs(0)=left(t0,255)
rs(1)=t1
rs(2)=t2
rs(3)=t3
if act="add" then
if t1<>0 then
    set rs2=conn.execute("select top 1 ordnum from "&sd_table&" where followid="&t1&" order by ordnum desc")
      if rs2.eof and rs2.bof then
		  ordnum1=1
      else
        if rs2(0)<>"" then
			ordnum1=rs2(0)+1
        else
			ordnum1=1
      end if
  end if
rs(5)=ordnum1
 else
    set rs1=conn.execute("select top 1 ordnum from "&sd_table&" where followid=0 order by ordnum desc")
     if rs1.eof then
		 ordnum1=1
     else
       if rs1(0)<>"" then
		   ordnum1=rs1(0)+1
       else
		   ordnum1=1
       end if
     end if
rs(5)=ordnum1
  end if
end if
if act="save" then

	if t5<>rs(6) or t6<>rs(7) then
		set sdcms=new sdcms_function
			sdcms.DelHtml rs(7)&rs(6)&sdcms_filetxt
		set sdcms=nothing
	end if
end if
rs(6)=left(t5,50)
rs(7)=left(t6,50)
rs.update
id=rs(4)
if instr(t5,"{id}")>0 then
	conn.execute("update "&sd_table&" set htmlname='"&replace(t5,"{id}",id)&"' where id="&id&"")
end if
if act="add" then 
	conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','添加单页："&rs(0)&"')")
else
	conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','修改单页："&rs(0)&"')")
end if
set sdcms_c=new sdcms_create
	sdcms_c.Create_other id
set sdcms_f=nothing
  response.Redirect("?")
end sub

sub del
if request("id")<>"" then
	conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除单页：编号为"&request("id")&"')")
	counts=conn.execute("select count(id) from "&sd_table&" where followid="&id&" ")(0)
	if counts>0 then
	echo "不能删除有下级页面的页面":Died
	end if
	set sdcms=new sdcms_function
	sdcms.DelHtml sdcms.LoadRecord("pagedir",sd_table,id)&sdcms.LoadRecord("htmlname",sd_table,id)&sdcms_filetxt
	set sdcms=nothing
	conn.execute("delete from "&sd_table&" where id="&id&"")
end if
response.Redirect("?")
end sub

sub makehtml
if request("id")<>"" then
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','生成单页：编号为"&request("id")&"')")
	if instr(request("id"),", ")>0 then
	id=split(request("id"),", ")
		for i=0 to ubound(id)
		  set sdcms=new sdcms_create
		  sdcms.Create_other id(i)
		  set sdcms=nothing
		Next
	Else
		set sdcms=new sdcms_create
		sdcms.Create_other id
		set sdcms=nothing
	End if
else
  response.Redirect("?")
end if
end sub

sub up
sql="select top 1 id,ordnum from "&sd_table&" where followid="&followid&"   and ordnum>"&ordnum&" order by ordnum"
set rs=conn.execute(sql)
if not rs.eof then
conn.execute("update "&sd_table&" set ordnum="&rs(1)&" where id="&id&"")
conn.execute("update "&sd_table&" set ordnum="&rs(1)&"-1 where id="&rs(0)&"")
end if
response.redirect("?")
end sub

sub down
sql="select top 1 id,ordnum from "&sd_table&" where followid="&followid&"   and ordnum<"&ordnum&" order by ordnum desc"
set rs=conn.execute(sql)
if not rs.eof then
conn.execute("update "&sd_table&" set ordnum="&rs(1)&" where id="&id&"")
conn.execute("update "&sd_table&" set ordnum="&rs(1)&"+1 where id="&rs(0)&"")
end if
response.redirect("?")
end sub

dim ii
ii=0
sub sdsort(selec)
with response

sql="Select id,title,ordnum,followid,htmlname,pagedir From ["&sd_table&"] where followid="&selec&"  order by ordnum desc"

Set Rs1=Conn.Execute(sql)
do while not rs1.eof

.write(" <tr  onmouseover=this.bgColor='#EBFFDC'; onmouseout=this.bgColor='#ffffff';  bgcolor='#ffffff'>")
.write("<td align=""center""><input name=""id""  type=""checkbox"" onClick=""unselectall()""   value="""&rs1(0)&"""></td>")
.write("      <td >&nbsp;")
if selec<>0 then
.write(""&string(ii,"　")&" ")
set rsn=conn.execute("select max(ordnum),min(ordnum) from "&sd_table&" where followid="&Rs1(3)&"")
if rs1(2)=rsn(0) and rs1(2)=rsn(1) then
.write(" └")
elseif rs1(2)=rsn(0) and rs1(2)>rsn(1) then
.write(" ├")
elseif rs1(2)<rsn(0) and rs1(2)=rsn(1) then
.write(" └")
elseif rs1(2)<rsn(0) and rs1(2)>rsn(1) then
.write(" ├")
rsn.close
end if
end if
.write("&nbsp;<a href="&rs1(5)&rs1(4)&""&sdcms_filetxt&" target=""_blank"">"&rs1(1)&"</a>")
.write("	  </td>")
.write("      <td>"&string(ii,"　")&"<a href='?action=up&id="&rs1(0)&"&ordnum="&rs1(2)&"&followid="&rs1(3)&"'>上升</a> <a href='?action=down&id="&rs1(0)&"&ordnum="&rs1(2)&"&followid="&rs1(3)&"'>下降</a></td>")

.write("      <td align='center'><input class=""input"" value=""<a href="&rs1(5)&rs1(4)&sdcms_filetxt&">"&rs1(1)&"</a>"" size=""40""></td>")
.write("      <td align='center'>")
if selec=0 then 
.write("<a href='?action=add&classid="&rs1(0)&"'>添加下级页面</a>")
else
.write("　　　　　　")
end if

.write("　<a href='?action=edit&id="&rs1(0)&"'>编辑</a>　<a href='?action=del&id="&rs1(0)&"' onclick='return confirm(""真的要删除?不可恢复!"");'>删除</a>　<a href='?action=makehtml&id="&rs1(0)&"'>生成</a></td>")
.write("</tr>")
ii=ii+1
sdsort rs1(0)
ii=ii-1
rs1.Movenext

loop
Set Rs1 = Nothing
end with
end sub

dim iii,rs
iii=0
sub ssort(t)
with response
if id<>0  then tj="and  id<>"&id&""
sql="Select id,title,ordnum,followid From "&sd_table&" where  followid=0 "&tj&"  order by ordnum desc"
Set rs1=Conn.Execute(sql)
do while not rs1.eof
.write("<option value='"&rs1(0)&"' ")
if clng(classid)=rs1(0) then
.write("selected")
end if
if action="edit"  then
if rs(2)=rs1(0) then
.write("selected")
end if
end if
.write(">")
if t<>0 then
.write(""&string(iii,"　")&"")
set rsn=conn.execute("select max(ordnum),min(ordnum) from "&sd_table&" where followid="&Rs1(3)&"")
if rs1(2)=rsn(0) and rs1(2)=rsn(1) then
.write("└")
elseif rs1(2)=rsn(0) and rs1(2)>rsn(1) then
.write("├")
elseif rs1(2)<rsn(0) and rs1(2)=rsn(1) then
.write("└")
elseif rs1(2)<rsn(0) and rs1(2)>rsn(1) then
.write("├")
rsn.close
end if
end if
.write(" "&rs1(1)&"</option>")
iii=iii+1

rs1.Movenext
loop
Set Rs1 = Nothing
end with
end sub

sub check_info
with response
.write("	<script>")
.write("	function checkadd()")
if sdcms_editor_type=0 then
.write("	{document.add.elements.t3.value =oEdit1.getHTMLBody();")
elseif sdcms_editor_type=1 then
.write("	{document.add.elements.t3.value =eWebEditor1.getHTML();")
end if
.write("	if (document.add.t0.value=='')")
.write("	{")
.write("	alert('标题不能为空');")
.write("	document.add.t0.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.elements.t3.value =='')")
.write("	{")
.write("	alert('内容不能为空');")
.write("	document.add.t3.focus;")
.write("	return false")
.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>