<!--#include file=../conn.asp-->
<!-- #include file="inc/const.asp" -->
<%Head()
	dim admin_flag
	admin_flag=",10,"
	if not master or instr(","&session("flag")&",",admin_flag)=0 then
		Errmsg=ErrMsg + "<BR><li>本页面为管理员专用，请<a href=../"&LoginUrl&" target=_top>登录</a>后进入。<br><li>您没有管理本页面的权限。"
		Call Ms_error()
	End If
		Main(1)
		Select Case Request("action")
		Case "search"''读取数据列表
		call search()
		Case "add"
		call add()
		Case "addsave"
		call addsave()
		Case "edit"
		call edit()
		Case "Toset"''批量操作
		call ToSet()
		Case "editsave"
		call editsave()
		Case Else
		call SIndex()''搜索表单
		End Select
		Main(0)
		Footer()

sub main(Str)
if Str=1 then%>
<table width="95%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
  <tr> 
    <th height="23" colspan="5" class="tableHeaderText">模板管理中心</th>
  </tr>
  <tr> 
    <td width="16%" height="24" align="right" class="forumrow">说明：</td>
    <td width="84%" height="24" class="forumrow" colspan=4>
	<li>模板管理中心可修改、增加、删除新模板；</li>
<li>{$Utitle(1,1,1)$}：窗口标题说明；{$Uphoto(1,120,150,0)$}：照片标签；{$Upersonal(1,300)$}：自我介绍标签；</li>
<li>{$UDiary(0,1,10,20,0,0,1,0,1)$}：过程变量UDiary_show我的日记；{$Ustat(1,1,1)$}：用户在线情况；</li>
<li>{$Uinfo(20)$}：用户资料；{$Uconet(18)$}：联系方式；{$Uctrl(18)$}：用户菜单；</li>
<li>{$Ujihui(0,0,10,12,0,0,1,0,1)$}：网友聚会；{$Uvote(1)$}：用户投票</li>
<li>更详细说明请见安装说明文件</li>
<li>请注意系统模板必须有一个默认的模板等级为0</li>
	</td>
  </tr>
  <tr> 
    <td height="30" colspan=5 class="forumrow">快捷方式：<a href=?action=search&t=1>所有模板</a> | <a href=?action=add>增加模板</a></td>
  </tr>
  <script language = 'JavaScript'>
function selectPaginationType(){
  document.theForm.PaginationType.value=2;
}
function CheckForm(){
  var CurrentMode=editor.CurrentMode;
  if (CurrentMode==0){
    document.theForm.Content.value=editor.HtmlEdit.document.body.innerHTML; 
  }
  else if(CurrentMode==1){
   document.theForm.Content.value=editor.HtmlEdit.document.body.innerText;
  }
  else{
    alert('预览状态不能保存！请先回到编辑状态后再保存');
    editor.HtmlEdit.focus();
     return false;
  }
if (document.theForm.Tempname.value==''){
     alert('模板名称不能为空！');
     document.theForm.Tempname.focus();
     return false;
  }
    if (document.theForm.Content.value==''){
      alert('文章内容不能为空！');
      editor.HtmlEdit.focus();
      return false;
    }
}
</script>
<%
	Else
%>
</table>
<p></p>

<%end if
end sub

sub search()
strFileName="template.asp?action="&Request("action") & "&t="&request("t")&""
call tumppages()
dim sql
sql = " ID,Tempname,Template,Levels "%>
<tr>
<th colspan=5 align=left height=23>所有模板列表</th>
</tr>
<FORM METHOD=POST ACTION="?action=Toset">
<tr align=center height=23>
<td class=forumRowHighlight width="18%"><B>模板ID</B></td>
<td class=forumRowHighlight width="50%"><B>模板名称</B></td>
<td class=forumRowHighlight width="8%"><B>模板等级</B></td>
<td class=forumRowHighlight><B>操作</B></td>
</tr>
<%dim sqlstr
set rs=server.createobject("adodb.recordset")
Select Case Request("t")
	Case 1
		Sql = "SELECT " & sql & " from Ms_Template ORDER BY ID DESC"
	case else
		Response.Write "<tr><td colspan=8 class=forumrow>错误的参数。</td></tr>"
		Response.End
	End Select
	rs.Open sql,conn,1,1
if not (rs.eof and rs.bof) then
call rspages()
do while not rs.eof and page_count<Cint(MaxPerPage)%>
<tr align=center height=23>
<td class=forumrow><%=rs(0)%></td>
<td class=forumrow align="left"><a href=?action=edit&id=<%=rs(0)%>><%=rs(1)%></a> (<%if rs(0)=1 then
response.Write("<font color=red>系统默认</font>")
else
response.Write("<font color=blue>用户提交</font>")
end if%>)</td>
<td class=forumrow><%=rs(3)%></td>
<td class=forumrow><input type="checkbox" name="id" value="<%=rs(0)%>" <%if rs(0)=1 then response.write "disabled"%>></td>
</tr>
<%page_count=page_count+1
  rs.movenext
  loop
  else
  response.Write("<tr><td colspan=8 class=forumrow>暂时数据。</td></tr>")
  end if
  if totalrec>0 then%>
<tr align="center"> 
      <td height="24" colspan="5" class=forumrow><%
		  	call showpage(strFileName)
		  %></td>
    </tr>
<%end if%>
<tr align="center"> 
      <td height="24" colspan="5" class=forumrow align="right"><input type="radio" name="paction" value="1">删除记录
	  <input type="radio" name="paction" value="2">等级操作
	<select size=1 name="usergroups">
<option value="">请选择</option>
<%
set rs=Conn.Execute("select usergroupid,UserTitle,ParentGID from Ms_usergroups Where Not ParentGID=0 order by ParentGID,usergroupid")
do while not rs.eof
response.write "<option value="&rs(0)&">"&SysGroupName(Rs(2)) & rs(1)&"</option>"
rs.movenext
loop
rs.close
set rs=nothing
%>
</select>
	  全部选定<input type=checkbox value="on" name="chkall" onclick="CheckAll(this.form)"></td>
    </tr>
	<tr align="center"> 
      <td height="24" colspan="5" class=forumRowHighlight><input type=submit name=submit value="执行操作"  onclick="{if(confirm('确定执行操作吗?')){return true;}return false;}"></td>
    </tr>
</form>
<%end sub

sub ToSet()''执行操作
dim delid,fixid,Maxnum
response.write "<tr><th colspan=5 height=23 align=left>执行结果</th></tr>"
	if request("paction")="" then
		response.write "<tr><td colspan=5 class=forumrow>请指定相关参数。</td></tr>"
		founderr=true
	end if
	delid=replace(request.form("id"),"'","")
	delid=replace(delid,";","")
	delid=replace(delid,"--","")
	delid=replace(delid,")","")
	fixid=replace(delid,",","")
	fixid=Trim(replace(fixid," ",""))
if not founderr then
		if request("paction")=1 then''删除操作
			Conn.Execute("delete from Ms_Template where id in ("&delid&")")
			conn.execute("Update Ms_User set TemplateId=0 where TemplateId in ("&delid&")")
			response.write "<tr><td colspan=5 class=forumrow>删除模板成功。</td></tr>"
		elseif request("paction")=2 then''等级操作
			if request("usergroups")<>"" then
			Conn.Execute("update Ms_Template set Levels="&request("usergroups")&" where id in ("&delid&")")
			response.write "<tr><td colspan=5 class=forumrow>等级设置成功。</td></tr>"
			end if
		else
		response.write "<tr><td colspan=5 class=forumrow>错误的参数。</td></tr>"
		end if
end if
end sub

sub edit()
dim id
id=request("id")
sql="select * from [Ms_Template] where id="&id&""
set rs=conn.execute(sql)
if not (rs.eof and rs.bof) then%>
<form action="?action=editsave" method=post onSubmit='return CheckForm();' name="theForm">
<input name="id" type="hidden" value="<%=id%>">
<tr>
<th align=left colspan=5 height=23>模板修改中心</th>
</tr>
<tr>
<td width=20% class=forumrow>模板名称</td>
<td width=80% class=forumrow colspan=4><input name="Tempname" type="text" size="20" value="<%=rs("Tempname")%>"></td>
</tr>
<tr>
<td width=20% class=forumrow>模板等级</td>
<td width=80% class=forumrow colspan=7><select size=1 name="usergroups">
        <option value=0>请选择等级</option>
        <%dim rsl
set rsl=Conn.Execute("select usergroupid,UserTitle,ParentGID from Ms_usergroups Where Not ParentGID=0 order by ParentGID,usergroupid")
do while not rsl.eof
if rsl(0)=rs("Levels") then
response.write "<option value="&rsl(0)&" selected>"&SysGroupName(Rsl(2)) & rsl(1)&"</option>"
else
response.write "<option value="&rsl(0)&">"&SysGroupName(Rsl(2)) & rsl(1)&"</option>"
end if
rsl.movenext
loop
rsl.close
set rsl=nothing
%>
      </select></td>
</tr>
<tr>
<td width=20% class=forumrow>模板内容</td>
<td width=80% class=forumrow colspan=7>
<textarea name='Content' style='display:none'><%=rs("Template")%></textarea> 
              <iframe id='editor' src='../editor.asp' frameborder=0 scrolling=no width='520' height='405'></iframe> 
</td>
</tr>
<tr>
<td width=100% class=forumrow align=center colspan=8><input name="submit" type=submit value="   更 新   "></td>
</tr>
</form>
<%end if
rs.close
end sub

sub editsave()
dim id
id=checkStr(request("id"))
if id="" or not isnumeric(id) then
Errmsg=ErrMsg + "<BR><li>参数错误。"
founderr=true
end if
if request("Tempname")="" or strLength(request("Tempname"))>100 then
Errmsg=ErrMsg + "<BR><li>模板名称不为空长度不大于100个字符。"
founderr=true
end if
if request("Content")="" then
Errmsg=ErrMsg + "<BR><li>模板内容不为空。"
founderr=true
end if
if founderr=true then Ms_error()
set rs=server.createobject("adodb.recordset")
  sql="select * from Ms_Template where id="&id&""
rs.Open sql,conn,1,3
if not (rs.eof and rs.bof) then
rs("Tempname")=request("Tempname")
rs("Template")=request("Content")
rs("Levels")=request("usergroups")
rs.update
rs.close
else
response.write "<tr><td colspan=5 class=forumrow>更新错误。</td></tr>"
end if
Ms_suc("更新模板成功！")
end sub

sub add()%>
<form action="?action=addsave" method=post onSubmit='return CheckForm();' name="theForm">
<tr>
<th align=left colspan=5 height=23>模板增加中心</th>
</tr>
<tr>
<td width=20% class=forumrow>模板名称</td>
<td width=80% class=forumrow colspan=4><input name="Tempname" type="text" size="20"></td>
</tr>
<tr>
<td width=20% class=forumrow>模板等级</td>
<td width=80% class=forumrow colspan=7><select size=1 name="usergroups">
        <option value=0>请选择等级</option>
        <%dim rsl
set rsl=Conn.Execute("select usergroupid,UserTitle,ParentGID from Ms_usergroups Where Not ParentGID=0 order by ParentGID,usergroupid")
do while not rsl.eof
response.write "<option value="&rsl(0)&">"&SysGroupName(Rsl(2)) & rsl(1)&"</option>"
rsl.movenext
loop
rsl.close
set rsl=nothing
%>
      </select></td>
</tr>
<tr>
<td width=20% class=forumrow>模板内容</td>
<td width=80% class=forumrow colspan=7>
<textarea name='Content' style='display:none'></textarea> 
              <iframe id='editor' src='../editor.asp' frameborder=0 scrolling=no width='520' height='405'></iframe> 
</td>
</tr>
<tr>
<td width=100% class=forumrow align=center colspan=8><input name="submit" type=submit value="  增 加  "></td>
</tr>
</form>
<%end sub

sub addsave()
if request("Tempname")="" or strLength(request("Tempname"))>100 then
Errmsg=ErrMsg + "<BR><li>模板名称不为空长度不大于100个字符。"
founderr=true
end if
if request("Content")="" then
Errmsg=ErrMsg + "<BR><li>模板内容不为空。"
founderr=true
end if
if founderr=true then Ms_error()
sql="Insert into Ms_Template (Tempname,Template,Levels) VALUES ('"&request("Tempname")&"','"&request("Content")&"',"&request("usergroups")&")"
Ms_suc("添加模板成功！")
end sub%>