<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
</head>
<body scroll="no" style="overflow:auto!important;overflow:hidden;background:#fff;">

<%
Dim rs, sql, blog
Dim id, action
action = Trim(request("action"))
id = Int(request("id"))
Select Case action
    Case "addurl"
    Call addurl
    Case "del"
    Call delurl
    Case "modify"
    Call modifyurl
    Case "savemodi"
    Call savemodify
    Case "order"
    Call order
    Case Else
    Call main
End Select
Set rs = Nothing
%>
</body>
</html>
<%


Sub addurl()
    Call uporder
    Dim urlname,url,logourl, rs, ordernum,urltype
    urlname = Trim(request.Form("urlname"))
	url = Trim(request.Form("url"))
	logourl = Trim(request.Form("logourl"))
	urltype = cint(Trim(request.Form("urltype")))
    If urlname = "" Or oblog.strLength(urlname) > 50 Then oblog.adderrstr ("友情连接名不能为空且不能大于50字符)！")
    If oblog.chk_badword(urlname) > 0 Then oblog.adderrstr ("友情连接名中含有系统不允许的字符！")
	If url="http://" or url="" Or oblog.strLength(url) > 250 Then oblog.adderrstr ("友情连接地址不能为空且不能大于250字符)！")
    If oblog.chk_badword(url) > 0 Then oblog.adderrstr ("友情连接地址中含有系统不允许的字符！")
	if urltype=1 then
		If logourl="http://" or logourl="" Or oblog.strLength(logourl) > 250 Then oblog.adderrstr ("图片连接地址不能为空且不能大于250字符)！")
		If oblog.chk_badword(url) > 0 Then oblog.adderrstr ("图片连接地址中含有系统不允许的字符！")
	end if
	if oblog.errstr<>"" then
		oblog.showusererr
		exit sub
	end if
    Set rs = oblog.execute("select max(ordernum) from oblog_friendurl where userid=" & oblog.l_uid)
    If Not IsNull(rs(0)) Then
        ordernum = rs(0) + 1
    Else
        ordernum = 1
    End If
    Set rs = server.CreateObject("adodb.recordset")
    rs.open "select top 1 * from [oblog_friendurl] Where 1=0", conn, 1, 3
    rs.addnew
    rs("urlname") = urlname
    rs("userid") = oblog.l_uid
    rs("ordernum") = ordernum
    rs("urltype") = urltype
	rs("logo")=logourl
	rs("urlname")=urlname
	rs("url")=url
    rs.Update
    rs.Close
    Set rs = Nothing
	update_links()
    oblog.showok "添加友情连接成功!", "user_friendurl.asp?t=" & t
End Sub

Sub delurl()
    Dim id
    id = CLng(request.QueryString("id"))
    oblog.execute("delete  from [oblog_friendurl] where urlid="&id&" and userid="&oblog.l_uid)
    Call uporder
	update_links()
    oblog.showok "删除友情连接成功!", ""
End Sub

Sub savemodify()
    Dim urlname,url,logourl, rs, ordernum,urltype
    urlname = Trim(request.Form("urlname"))
	url = Trim(request.Form("url"))
	logourl = Trim(request.Form("logourl"))
	urltype = cint(Trim(request.Form("urltype")))
    If urlname = "" Or oblog.strLength(urlname) > 50 Then oblog.adderrstr ("友情连接名不能为空且不能大于50字符)！")
    If oblog.chk_badword(urlname) > 0 Then oblog.adderrstr ("友情连接名中含有系统不允许的字符！")
	If url="http://" or url="" Or oblog.strLength(url) > 250 Then oblog.adderrstr ("友情连接地址不能为空且不能大于250字符)！")
    If oblog.chk_badword(url) > 0 Then oblog.adderrstr ("友情连接地址中含有系统不允许的字符！")
	if urltype=1 then
		If logourl="http://" or logourl="" Or oblog.strLength(logourl) > 250 Then oblog.adderrstr ("图片连接地址不能为空且不能大于250字符)！")
		If oblog.chk_badword(url) > 0 Then oblog.adderrstr ("图片连接地址中含有系统不允许的字符！")
	end if
	if oblog.errstr<>"" then
		oblog.showok replace(oblog.errstr,"_","\n"),""
		exit sub
	end if
    Set rs = server.CreateObject("adodb.recordset")
    rs.open "select * from [oblog_friendurl] where urlid="&id&" and userid="&oblog.l_uid,conn,1,3
    If Not rs.EOF Then
        rs("urlname") = urlname
		rs("userid") = oblog.l_uid
		rs("urltype") = urltype
		rs("logo")=logourl
		rs("urlname")=urlname
		rs("url")=url
		rs.update
    End If
    rs.Close
    Set rs = Nothing
	update_links()
    %>
    <script language="javascript">
    	parent.location.href="user_friendurl.asp";
  	</script>
    <%
End Sub

Sub order()
    Dim ordernum, modi, rs
    ordernum = CLng(request.QueryString("ordernum"))
    modi = request.QueryString("modi")
    Select Case modi
        Case "up"
            If ordernum - 1 > 0 Then
                oblog.execute("update [oblog_friendurl] set ordernum=9999999 where ordernum="&ordernum-1&" and userid="&oblog.l_uid )
                oblog.execute("update [oblog_friendurl] set ordernum=ordernum-1 where ordernum="&ordernum&" and userid="&oblog.l_uid)
                oblog.execute("update [oblog_friendurl] set ordernum="&ordernum&" where ordernum=9999999"&" and userid="&oblog.l_uid)
            End If
        Case "down"
            Set rs = oblog.execute("select max(ordernum) from oblog_friendurl where userid=" & oblog.l_uid)
            If ordernum < rs(0) Then
                oblog.execute("update [oblog_friendurl] set ordernum=9999999 where ordernum="&ordernum+1&" and userid="&oblog.l_uid )
                oblog.execute("update [oblog_friendurl] set ordernum=ordernum+1 where ordernum="&ordernum&" and userid="&oblog.l_uid )
                oblog.execute("update [oblog_friendurl] set ordernum="&ordernum&" where ordernum=9999999 and userid=" & oblog.l_uid )
            End If
            Set rs = Nothing
    End Select
    'uporder()
	update_links()
    response.Redirect "user_friendurl.asp" 
End Sub

Sub uporder()
    Dim rs, i, n
    n = 0
    Set rs = oblog.execute("select count(urlid) from [oblog_friendurl] where userid=" & oblog.l_uid )
    ReDim ordernum(rs(0))
    Set rs = oblog.execute("select urlid from [oblog_friendurl] where userid=" & oblog.l_uid &" order by ordernum")
    While Not rs.EOF
        ordernum(n) = rs(0)
        n = n + 1
        rs.movenext
    Wend
    i = 1
    For n = 0 To UBound(ordernum)
        oblog.execute("update oblog_friendurl set ordernum="&i&" where urlid="&clng(ordernum(n)))
        i = i + 1
        'response.Write(i)
    Next
    Set rs = Nothing
End Sub

Sub main()
%>
<script language="javascript">
	/* 发表页面弹出窗口 */
function doMenu1(MenuName,URL){
//	alert("测试 ");
	document.getElementById("chgClass").src=URL;
	document.getElementById(MenuName).style.display = "block";
//	alert("测试2 ");
//	if(document.getElementById(MenuName).style.display == "block"){
//		document.getElementById(MenuName).style.display = "none";
//	}
//	else{
//		document.getElementById(MenuName).style.display == "block";
//		}
	}
</script>
<style type="text/css">
<!--
	.content_li_top .t2 {width:118px;padding:0 0 0 10px;}
	.content_li_top .t3 {width:38%;text-align:left}
	.content_li_top .t4 {width:63px;padding:0 0 0 50px;text-align:left}
	.content_li_top .t5 {width:100px;text-align:left;}
	#content_li .content_li_conten .t2 {width:115px;margin:-2px 0 0 0;text-align:left}
	#content_li .content_li_conten .t3 {width:38%;line-height:1.5;margin:-2px 0 0 0;text-align:left;overflow:hidden;}
	#content_li .content_li_conten .t4 {width:130px;color:#888;text-align:center}
	#content_li .content_li_conten .t5 {width:180px;text-align:left}
-->
</style>
<ul class="user_setting_title" id="TabPage1">
    <li id="Tab11"><a href="user_setting.asp?action=0&div=11">站点设置</a></li>
    <li id="Tab12"><a href="user_setting.asp?action=userpassword&div=12">密码设置</a></li>
    <li id="Tab13"><a href="user_setting.asp?action=userinfo&div=13">个人资料</a></li>
    <li id="Tab14"><a href="user_setting.asp?action=blogpassword&div=14">加密整站</a></li>
    <li id="Tab15" class="Selected"><a href="user_friendurl.asp">友情连接</a></li>
    <li id="Tab16"><a href="user_setting.asp?action=placard&div=16">博客公告</a></li>
    <li id="Tab17"><a href="user_setting.asp?action=blogstar&div=17">博客之星</a></li>
</ul>

<ul id="user_page_top">
	<li id="p9"><a href="#" onClick="return doMenu('swin1');">添加友情连接</a></li>
	<li id="p9"><a href="user_setting.asp?action=links&div=15">高级编辑</a></li>
</ul>
<div id="user_page_content">
		<ul class="content_li_top">
			<li class="t1">排序</li>
			<li class="t2">友情连接名</li>
			<li class="t3">地址</li>
			<li class="t4">类型</li>
			<li class="t5">管理</li>
		</ul>
		<div id="content_li">
<%
Dim rs
Set rs = oblog.execute("select * from oblog_friendurl where userid=" & oblog.l_uid & " order by ordernum")
While Not rs.EOF
%>
			<ul class="content_li_conten">
				<li class="t1"><span><%=rs("ordernum")%></span></li>
				<li class="t2"><%="<a href='"&oblog.filt_html(rs("url"))&"' target='_blank'>"&oblog.filt_html(rs("urlname"))&"</a>"%></li>
				<li class="t3"><%="<a href='"&oblog.filt_html(rs("url"))&"' target='_blank'>"&oblog.filt_html(rs("url"))&"</a>"%></li>
				<li class="t4"><%if rs("urltype")=0 then response.Write("文字") else response.Write("图片")%></li>
				<li class="t5"><a onClick="return doMenu1('swin2','user_friendurl.asp?action=modify&id=<%=rs("urlid")%>&oldname=<%=rs("urlname")%>&t=<%=rs("urltype")%>');" href="#">修改</a> <a href="user_friendurl.asp?action=del&id=<%=rs("urlid")%>&t=<%=t%>" <%="onClick='return confirm(""确定要删除此友情连接吗(不可恢复)？"");'"%>>删除</a> <a href="user_friendurl.asp?action=order&modi=up&ordernum=<%=rs("ordernum")%>&t=<%=t%>">上移</a> <a href="user_friendurl.asp?action=order&modi=down&ordernum=<%=rs("ordernum")%>&t=<%=t%>">下移</a></li>
			</ul>
<%
rs.movenext
Wend
Set rs = Nothing
%>
		</div>
</div>
<div id="swin1" style="display:none;position:absolute;top:41px;left:10px;z-index:100;">
	<form name="form1" method="post" action="user_friendurl.asp?action=addurl&t=<%=t%>">
	<table class='win_table' align='center' border='0' cellpadding='0' cellspacing='1'>
		<tr>
			<td colspan='2' align='center' class='win_table_top'>添加友情连接</td>
		</tr>
		<tr>
			<td class='win_table_td'>类型：</td>
			<td><input type="radio" name="urlType" value="0"  onClick="document.getElementById('logourl').disabled='disabled';" checked>&nbsp;文字链接&nbsp;&nbsp;<input name="urlType" type="radio" value="1"  onClick="document.getElementById('logourl').disabled='';" >&nbsp;图片链接</td>
		</tr>

		<tr>
			<td class='win_table_td'>友情链接名：</td>
			<td><input name="urlname" type="text" id="urlname" maxlength="50" /></td>
		</tr>
		<tr>
			<td class='win_table_td'>链接地址：</td>
			<td><input name="url" type="text" id="url" maxlength="255" size="40" value="http://" /></td>
		</tr>
		<tr>
			<td class='win_table_td'>图片地址：</td>
			<td><input name="logourl" type="text" id="logourl" maxlength="255" size="40" disabled="disabled" value="http://" /></td>
		</tr>

		<tr>
			<td colspan='2' class="win_table_end"> <input type="submit" value="添加" /> <input type="button" onClick="return doMenu('swin1');" value="关闭" title="关闭" /></td>
		</tr>
	</table>
	</form>
</div>
<div id="swin2" style="display:none;position:absolute;top:50px;left:50px;z-index:100;">
<iframe class="FrmID" id="chgClass"  style="width:400px;height:300px;" src="" frameborder="0" scrolling="auto" onunload="parent.location.href='user_friendurl.asp?t=<%=t%>'"></iframe>
</div>
<div id="swin3"></div>
<div id="swin4"></div>
<div id="swin5"></div>
<iframe id="DivShim" scrolling="no" frameborder="0" style="position:absolute;top:0px; left:0px;display:none"></iframe>
</div>
<%
End Sub

Sub modifyurl()
    Dim rs
    id = CLng(id)
    set rs=oblog.execute("select * from oblog_friendurl where urlid="&id&" and userid="&oblog.l_uid)
    If Not rs.EOF Then
	
%>
	<form name="form1" method="post" action="user_friendurl.asp?action=savemodi&id=<%=id%>">
	<table class='win_table' align='center' border='0' cellpadding='0' cellspacing='1'>
		<tr>
			<td colspan='2' align='center' class='win_table_top'>修改友情连接</td>
		</tr>
		<tr>
			<td class='win_table_td'>类型：</td>
			<td><input type="radio" name="urlType" value="0"  onClick="document.getElementById('logourl').disabled='disabled';" <%if rs("urltype")=0 then response.Write("checked")%>>&nbsp;文字链接&nbsp;&nbsp;<input name="urlType" type="radio" value="1"  onClick="document.getElementById('logourl').disabled='';" <%if rs("urltype")=1 then response.Write("checked")%>>&nbsp;图片链接</td>
		</tr>

		<tr>
			<td class='win_table_td'>友情链接名：</td>
			<td><input name="urlname" type="text" id="urlname" maxlength="50" value="<%=oblog.filt_html(rs("urlname"))%>" /></td>
		</tr>
		<tr>
			<td class='win_table_td'>链接地址：</td>
			<td><input name="url" type="text" id="url" maxlength="255" size="40" value="<%=oblog.filt_html(rs("url"))%>" /></td>
		</tr>
		<tr>
			<td class='win_table_td'>图片地址：</td>
			<td><input name="logourl" type="text" id="logourl" maxlength="255" size="40"  <%if rs("urltype")=0 then response.Write("disabled='disabled'")%> value="<%if oblog.filt_html(rs("logo"))="" then response.Write("http://") else response.Write(rs("logo"))%>" /></td>
		</tr>

		<tr>
			<td colspan='2' class="win_table_end"> <input type="submit" value="修改" /> <input type="button" onClick="return parent.doMenu('swin2');" value="关闭" title="关闭" /></td>
		</tr>
	</table>
	</form>
<%
    Set rs = Nothing
    End If
End Sub

sub update_links()
	dim blog
	set blog=new class_blog
	blog.userid=oblog.l_uid
	blog.update_links oblog.l_uid
	set blog=nothing
end sub

%>