<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<%
dim action,iPage,sGuide
Action=trim(request("Action"))
iPage=12
If Action="modiconfig" Or Action="modiviceconfig" Then oblog.MakeEditorJs
%>
<style type="text/css">
<!--
html {overflow:hidden;}
-->
</style>
</head>
<body style="overflow:hidden;" class="user_iframe">
<%
'设置每页模板显示显示数目
G_P_FileName="user_template.asp?page="	
G_P_PerMax=12
'模板显示顺序,1:倒序,最新的在最前面;2:顺序,最老的在最前面
Const P_USER_TEMPLATE_ORDERBY=1
%>
<%

select case Action
	case "saveconfig"
		call saveconfig()
	case "modiconfig"
		call modiconfig()
	case "savedefault"
		call savedefault()
	case "modiviceconfig"
		call modiviceconfig()
	case "saveviceconfig"
		call saveviceconfig()
	case "bakskin"
		call bakskin()
	case "good"
		call good()
	case Else
		call showconfig()
End select
%>
	</div>

  </div>
</div>
</body>
</html>
<script language=javascript>
function VerIfySubmit()
{
	If (document.oblogform.myTextArea.value == "")
     {
        alert("请输入模板内容!");
	return false;
     }	
	return true;
}
function setbak()
{
	document.bakform.bak.value='bak';
}
function setrestore()
{
	document.bakform.bak.value='restore';
}

function skin_help(action){
	if (action==0){
		var str="<div style='height:200px;overflow:auto'>主模版标签<hr />$show_log$ 重要，此标记显示日志主体部分，包括评论等信息。<br />$show_placard$ 此标记显示用户公告。 <br />$show_calendar$ 此标记显示日历。 <br />$show_newblog$ 此标记显示最新日志列表。 <br />$show_comment$ 此标记显示最新回复列表。<br />$show_subject$ 此标记显示专题分类。 <br />$show_subject_l$ 此标记横向显示专题分类。<br />$show_newblog$ 此标记显示最新日志列表。<br />$show_newmessage$ 此标记显示最新留言列表。<br />$show_info$ 此标记显示Blog名称，统计信息等。 <br />$show_login$ 此标记显示登陆窗口 <br />$show_links$ 此标记显示链接信息。<br />$show_blogname$ 此标记显示用户blog名称，若名称为空则显示用户id。<br />$show_search$ 此标记显示搜索表单。<br />$show_xml$ 此标记显示rss连接标志。<br />$show_blogurl$ 此标记显示博客链接。<br />$show_myfriend$ 此标签显示我的好友。<br />$show_mygroups$ 此标签显示我加入的群组。<br />$show_photo$ 此标签调用相册。</div>";
	}else{
		var str="<div style='height:150px;overflow:auto'>副模版标签<hr /> $show_topic$ 此标记显示日志题目。 <br />$show_loginfo$ 此标记显示日志作者，发表时间等信息。 <br />$show_logtext$ 此标记显示日志正文。 <br />$show_more$ 此标记显示阅读全文，引用等链接。 <br />$show_emot$ 此标记仅显示显示表情图标。<br />$show_author$ 此标记仅显示作者名。<br />$show_addtime$ 此标记仅显示发表时间。<br />$show_topictxt$ 此标记仅显示日志标题。</div>";		
	}
	var oDialog = new dialog("<%=blogurl%>");
	oDialog.init();
	oDialog.event(str,'');
	oDialog.button('dialogOk',"");	
	document.getElementById("ob_boxface").style.display="none"; 
}

</script>
<%
sub showconfig()
	Dim rs,SkinStrings,defaultskin,rst,sql,sClasses,sqlclass,classid
	Dim bookmark,sOrderby
	Set rs=Server.CreateObject("Adodb.Recordset")
	classid=Request("classid")
	If classid<>"" Then classid=Int(classid)
	If classid=0 Then classid=""
	'取默认模板
	rs.Open "select defaultskin from [oblog_user] where userid="&oblog.l_uid,conn,1,3		
	defaultskin=rs(0)
	rs.Close
	If classid<>"" Then sqlclass=" And classid=" & classid:G_P_FileName="user_template.asp?classid="&classid&"&page="	
	'取该用户可用分类
	If OB_IIF(oblog.l_Group(13,0),"")="" Then
		sql="select * from oblog_userskin where ispass=1 "  & sqlclass & " Order By Id"
		Set rst=oblog.Execute("Select * From oblog_skinclass Where itype=0 And icount>0")
	Else
		sql="select * from oblog_userskin where ispass=1 And classid in (" & oblog.l_Group(13,0) &") "  & sqlclass & " Order By Id"
		Set rst=oblog.Execute("Select * From oblog_skinclass Where itype=0 And classid in (" & oblog.l_Group(13,0) &")  And icount>0")
	End If
	Do While Not rst.Eof
		sClasses=sClasses & "<option value=" & rst("classid") & ">" & rst("classname")& "(有" & rst("icount") &"个模板)</option>"
		rst.Movenext
	Loop
	
%>

<body>
<ul id="user_page_top">
<form name="formclass" method="post" action="user_template.asp">
<%
If defaultskin=0 Then
	Response.Write "你当前还没有选择任何模板"
Else
	Set rst=oblog.Execute("Select * From oblog_userskin Where id=" & defaultskin)
	If Not rst.Eof Then
		Response.Write "你当前选择的模板是：<a href='showskin.asp?id=" & rst("id") & "' target=_blank>" & "<font>" & rst("userskinname") &"</font></a>"
	End If
	Set rst=Nothing
End If

%>
	<select name="classid">
	<option value=0>---显示全部可用模板--</option>
	<%=sClasses	%>
	</select>
	<input type="submit" value="过滤">
	</h1>
</form>
</ul>
<%
Dim lPage,lAll,lPages
If P_USER_TEMPLATE_ORDERBY=1 Then sOrderby=" Desc"
rs.Open sql & sOrderby,conn,1,3
lAll=INT(rs.recordcount)
    If lAll=0 Then    	
    	rs.Close
    	Set rs=Nothing
    	%>
    	<div id="user_page_content">
		   <div id="content_li">
		   	<ul class="content_li_conten">
		   		<li class="t1"></li>
		   		<li class="t3">&nbsp;</li>
		   	</ul>
		   	<ul class="content_li_conten">
		   		<li class="t1"></li>
		   		<li class="t3"><%=sGuide & " 没有相关纪录" %></li></ul>
		  	</div>
		  </div>
    	<%
    	Exit Sub
    End If

	'分页
	If Request("page") = "" Or Request("page") ="0" then
		lPage = 1
	Else
		lPage = Int(Request("page"))
	End If
	
	'设置缓存大小 = 每页需显示的记录数目
	rs.CacheSize = iPage
	rs.PageSize = iPage
	rs.movefirst		
	lPages = rs.PageCount
	If lPage>lPages Then lPage=lPages
	rs.AbsolutePage = lPage
%>
<style type="text/css">
<!--
.dvhdr1 {width:auto;font-weight:400;}
.dvbdy1 {display:none;}
-->
</style>
<div id="showpage">
	  <%=MakeMiniPageBar(lAll,iPage,lPage,G_P_FileName)%>
</div>
<div id="user_template">
<%
		SkinStrings="<ul>" & VBCRLF
		
	SkinStrings = SkinStrings & GetSkinList(rs,defaultskin)
	rs.Close
	set rs=Nothing	
	SkinStrings = SkinStrings & "</ul>" & VBCRLF	
	Response.Write SkinStrings
	SkinStrings=""
	%>	
	<ul class="list_bot">
	<input type="hidden" value="<%=request("u")%>">
	</ul>
</div>
</div>
<%
	set rs=nothing
End sub

sub savedefault()
	dim rs,rsskin,isdefaultID
	isdefaultID=clng(trim(request("radiobutton")))
	set rsskin=oblog.execute("select skinmain,skinshowlog from oblog_userskin where id="&isdefaultID)
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select user_skin_main,user_skin_showlog,defaultskin from [oblog_user] where userid="&oblog.l_uid,conn,1,3
	rs(0)=rsskin(0)
	rs(1)=rsskin(1)
	rs(2)=isdefaultID
	set rsskin=nothing
	rs.update
	rs.close
	set rs=nothing
	'如果是新手模式
	If oblog.l_uNewbie=1 Then
		'清空Session，防止选择后无法即时生效
		Session ("CheckUserLogined") = ""
		'创建新的用户目录
		If  C_Reg_AutoCreate = 0 Then oblog.CreateUserDir oblog.l_uname, 1
		oblog.execute "Update oblog_user Set newbie=0 Where userid=" & oblog.l_uid
		updateindex()	
		oblog.showok "模板选择成功！",""
	Else
		updateindex()	
		oblog.showok "修改成功,首页已经更新，其他页面请手动更新！",""
	End If
	
End sub

sub saveconfig()
	dim rs,sql,sContent,iChk
	If oblog.l_Group(14,0)=0 Then
		oblog.showok "你所在的组不允许修改模板！","user_template.asp"
		Exit Sub
	End If
	set rs=server.CreateObject("adodb.recordset")
	sql="select user_skin_main from [oblog_user] where userid="&oblog.l_uid
	rs.open sql,conn,1,3
	sContent=oblog.filtpath(oblog.filt_badword(trim(request("myTextArea"))))
	'内容检查
	iChk=oblog.chk_badword(sContent)
	If iChk>0 Then
		oblog.showok "模板中存在系统禁止的字符!",""
		Response.End
	End If
	'脚本过滤
	If Int(oblog.l_Group(15,0))=0 Then 	rs(0)=oblog.CheckScript(sContent)
	rs(0)=sContent
	rs.update
	rs.close
	set rs=nothing
	sContent=""
	updateindex()
	oblog.showok "修改成功,首页已经更新，其他页面请手动更新！","user_template.asp"
End sub

sub saveviceconfig()
	dim rs,sql,sContent
	Dim iChk
	If oblog.l_Group(14,0)=0 Then
		oblog.showok "你所在的组不允许修改模板！",""
		Exit Sub
	End If
	set rs=server.CreateObject("adodb.recordset")
	sql="select user_skin_showlog from [oblog_user] where userid="&oblog.l_uid
	rs.open sql,conn,1,3
	sContent=oblog.filtpath(oblog.filt_badword(trim(request("myTextArea"))))
	'内容检查
	iChk=oblog.chk_badword(sContent)
	If iChk>0 Then
		oblog.showok "模板中存在系统禁止的字符!",""
		Response.End
	End If
	'脚本过滤
	If Int(oblog.l_Group(15,0))=0 Then 	rs(0)=oblog.CheckScript(sContent)
	rs(0)=sContent
	rs.update
	rs.close
	set rs=nothing
	sContent=""
	updateindex()
	oblog.showok "修改成功,首页已经更新，其他页面请手动更新！",""
End sub

sub modiconfig()
	If oblog.l_Group(14,0)=0 Then
		oblog.showok "你所在的组不允许修改模板！","user_template.asp"
		Exit Sub
	End If
	dim rs,rsshowlog
	set rs=oblog.execute("select user_skin_main,defaultskin from [oblog_user] where userid="&oblog.l_uid)
	If rs("defaultskin")=0  or rs("defaultskin")="" Then
		set rs=nothing
		oblog.adderrstr("请先选择一个默认模板！")
		oblog.showusererr
		exit sub		
	End If
%>
<ul id="user_page_top">
	主模板决定页面整体风格，<a href="#" onclick="skin_help(0);">点击这里可以查看模板标签说明</a>，建议修改前先<a href="user_template.asp?action=bakskin">备份模板</a>。<br />
	点击编辑器“全屏幕”编辑按扭会方便很多。
</ul>
	<form method="POST" action="user_template.asp" id="oblogform" name="oblogform">
	<ul style=" margin:10px;">
	<span id="loadedit" style="font-size:12px"><img src='images/loading.gif' align='absbottom'> 正在载入编辑器...</span>
	<textarea id="myTextArea" name="myTextArea" style="width:98%;height:380px; 	display:none"><%=Server.HtmlEncode(rs(0))%></textarea >
	</ul>
    <ul class="list_edit" style="margin:15px">
	<input name="Action" type="hidden" id="Action" value="saveconfig" />
	<input name="cmdSave" type="submit" id="cmdSave" value=" 保存修改 " style="height:30px;" />
	</ul>
	</form>
<%oblog.MakeEditorText "myTextArea",1,"600","300"%>
<%
set rs=nothing
End sub

sub modiviceconfig()
	If oblog.l_Group(14,0)=0 Then
		oblog.showok "你所在的组不允许修改模板！","user_template.asp"
		Exit Sub
	End If
	dim rs,rsshowlog
	set rs=oblog.execute("select user_skin_showlog,defaultskin from [oblog_user] where userid="&oblog.l_uid)
	If rs("defaultskin")=0  or rs("defaultskin")="" Then
		set rs=nothing
		set rs=nothing
		oblog.adderrstr("请先选择一个默认模板！")
		oblog.showusererr
		exit sub		
	End If
%>
<ul id="user_page_top">
	
	副模板决定日志部分显示风格，<a href="#" onclick="skin_help(1);">点击这里可以查看模板标签说明</a>，建议修改前先<a href="user_template.asp?action=bakskin">备份模板</a>。<br />
	点击编辑器“全屏幕”编辑按扭会方便很多。
</ul>
	<form method="POST" action="user_template.asp?id=<%=clng(request.QueryString("id"))%>" id="oblogform" name="oblogform">
	<ul style="margin:10px">
	<span id="loadedit" style="font-size:12px"><img src='images/loading.gif' align='absbottom'> 正在载入编辑器...</span>
	<textarea id="myTextArea" name="myTextArea" style="width:95%;height:380px; display:none"><%=Server.HtmlEncode(rs(0))%></textarea >
	</ul>
	<ul class="list_edit" style="margin:15px">
	<input name="action" type="hidden" id="action" value="saveviceconfig" />
	<input type="submit"  value="保存修改"  style="height:30px;" />
	</ul>
	</form>
	<%oblog.MakeEditorText "myTextArea",1,"600","300"%>
<%
	set rs=nothing
End sub

sub bakskin()
	dim bak,rs
	bak=request("bak")
	If bak="bak" Then
		oblog.execute("update oblog_user set bak_skin1=user_skin_main,bak_skin2=user_skin_showlog where userid="&oblog.l_uid)
		oblog.showok "备份模板成功！",""
	ElseIf bak="restore" Then
		set rs=oblog.execute("select bak_skin1,bak_skin2 from oblog_user where userid="&oblog.l_uid)
		If rs(0)="" or rs(1)="" or isnull(rs(0)) or isnull(rs(1)) Then
			set rs=nothing
			oblog.adderrstr("所备份的模板为空，不允许恢复！")
			oblog.showusererr
		End If
		oblog.execute("update oblog_user set user_skin_main=bak_skin1,user_skin_showlog=bak_skin2 where userid="&oblog.l_uid)
		set rs=nothing
		oblog.showok "恢复模板成功！",""
	End If
%>
	<table class='win_update_table' align='center' border='0' cellpadding='0' cellspacing='1'>
		<tr>
			<td colspan='2' class='win_update_table_top'>备份模板</td>
		</tr>
		<tr>
			<td colspan='2'>建议修改或者更换模板前先备份模板，误操作以后可以随时恢复!</td>
		</tr>
		<tr>
			<td class='win_update_table_td'>备份现在使用的模板</td>
			<td><form name="bakform" method="post" action="user_template.asp?action=bakskin">
	<input type="hidden" name="bak" id="bak" value="" />
	<input type="submit" name="Submit" value="备份现在使用的模板" onclick="setbak();" /></td>
		</tr>
		<tr>
			<td class='win_update_table_td'>恢复模板(将覆盖使用中的模板)</td>
			<td><input type="submit" name="Submit2" value="恢复模板" onclick="setrestore();" /></td>
		</tr>
		<tr>
			<td class='win_update_table_td'>查看已经备份的模板</td>
			<td><input type="button" name="Submit1" value="查看已经备份的模板" onclick="window.open('showskin.asp?userid=<%=oblog.l_uid%>')" />
	</form></td>
		</tr>
	</table>


<%End sub


sub good()
	dim good,rs,rsu,skinname
	good=request("good")
	If good="save" Then
		skinname=request("skinname")
		If skinname="" or oblog.strLength(skinname)>50  Then oblog.adderrstr("用户名不能为空(不能大于50)！")
		If oblog.errstr<>"" Then oblog.showusererr:exit sub
		set rsu=oblog.execute("select user_skin_main,user_skin_showlog from oblog_user where userid="&oblog.l_uid)
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select top 1 * from [oblog_userskin]",conn,1,3
		rs.addnew
		rs("userskinname")=skinname
		rs("skinmain")=rsu(0)
		rs("skinshowlog")=rsu(1)
		rs("skinauthor")=oblog.l_uname
		rs("skinauthorurl")=oblog.l_udir&"/"&oblog.l_uid&"/index."&f_ext
		rs.update
		rs.close
		set rsu=nothing
		set rs=nothing		
		oblog.showok "推荐成功，请等待管理员审核！",""
	End If
%>
	<table class='win_update_table' align='center' border='0' cellpadding='0' cellspacing='1'>
		<tr>
			<td colspan='2' class='win_update_table_top'>推荐我的模板</td>
		</tr>
		<tr>
			<td colspan='2'>	如果你的模板很漂亮，推荐给管理员，可以放在模板数据库里，让更多人使用哦!<br />模板会注明作者和你的blog连接。请不要提交已经存在的用户模板！</td>
		</tr>
		<tr>
			<td class='win_update_table_td'>给我的模板取个名字：</td>
			<td><form name="good" action="user_template.asp?action=good&good=save" method="post"><input name="skinname"   type="text" value="" size="30" maxlength="20" /><input type="submit" value="推荐" /></form></td>
		</tr>
	</table>
<%End sub


sub updateindex()
	dim blog
	set blog=new class_blog
	blog.userid=oblog.l_uid
	blog.update_index 0
	blog.update_message 0
	blog.CreateFunctionPage
	set blog=nothing
End sub

Function GetSkinList(byref rst,byval defaultskin)
	Dim strSkins,ustr,iCount	
	iCount=0
	strSkins=""
	Do While Not rst.eof
		strSkins = strSkins & "<div class=""skinpic"">" & VBCRLF
		strSkins = strSkins & "<a href='showskin.asp?id=" & rst("id") & "' target=_blank>" & VBCRLF

		If rst("skinpic")="" or isnull(rst("skinpic")) Then
			strSkins = strSkins & "<img src=""images/nopic.gIf"" title=""对不起,该模板没有预览图"" width=200 height=122 border=""0"" />" & VBCRLF
		Else
			strSkins = strSkins & "<img src="""&oblog.filt_html(rst("skinpic"))&""" title=""点击预览"" width=200 height=122 border=""0"" />" & VBCRLF
		End If
		strSkins = strSkins & "</a><span title="""
		strSkins = strSkins & "模板：" & rst("userskinname") & VBCRLF
		strSkins = strSkins & "作者：" & rst("skinauthor")
		strSkins = strSkins & """>" & VBCRLF
		If rst("skinauthorurl")<>"" Then
			ustr="<a href="""&rst("skinauthorurl")&""" target=""_blank"">"&rst("skinauthor")&"</a>"
		Else
			ustr=rst("skinauthor")
		End If				
		strSkins = strSkins & "" & rst("userskinname") & ""
		strSkins = strSkins & "&nbsp;by:" & ustr & VBCRLF
		strSkins = strSkins & "</span><div class=""skin_used""><a href=""user_template.asp?action=savedefault&radiobutton=" & rst("id") & """ >应用此模板</a></div>"
		strSkins = strSkins & "</div>	" & VBCRLF & VBCRLF
		
		iCount = iCount+1
		if iCount >=iPage then exit do
		rst.movenext
	Loop
	GetSkinList = strSkins
End Function
%>