<!--#include file=conn.asp-->
<%if session(hxCacheName&"_admin")<>"OK" then
    response.redirect("admin_login.asp")
    end if
 %>
<%
'-------------------------------------
'功能：申请友情链接
'天天智能友情链接管理系统
'天天DV网制作 http://www.ttdv.cn
'博大网址库http://www.ip126.com

'可自由传播和免费使用，但必须保留此完整版权信息
'本程序撷取了ITlearner、博大网址库智能友情链接系统、飞
'越智能友情链接系统等优秀程序中的源代码，对他们的作者表示感谢
'-------------------------------------
dim action
%>
<!--#include file="../md5.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>添加友情链接_<%=WebName & ChannelName%> - Powered By ttdv</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../style.css">
</head>
<!--#include file="top.asp"-->
<script language=javascript src=../images/mouse_on_title.js></script>
<script LANGUAGE=JavaScript>
  function textLimitCheck(thisArea, maxLength){
    if (thisArea.value.length > maxLength){
      alert(maxLength + ' 个字限制. \r超出的将自动去除.');
      thisArea.value = thisArea.value.substring(0, maxLength);
      thisArea.focus();
    }
    /*回写span的值，当前填写文字的数量*/
    messageCount.innerText = thisArea.value.length;
  }
</script>
<BODY background="../images/back.gif">


<div class="bt<%=skin%>"><br>
  <%
if request("action")="addlink" then
call addlink
else
call showaddform
end if
sub showaddform
%>
  <p>添加友情链接</p>
  <form id="applyform" method="post" action="?action=addlink">
  <table width="90%" border="0" cellpadding="3" cellspacing="1" bgcolor="#000000" align="center">
      <tr class="tr<%=skin%>">
        <td width="100" align="center">用 户 名：</td>
        <td><input name="username" type="text" id="username" size="12" maxlength="12">&nbsp;&nbsp; <img src=../images/memo.gif alt="不能超过12个字符（6个汉字）"></td>
      </tr>
      <tr class="tr<%=skin%>">
        <td align="center">网站名称：</td>
        <td><input name="ttname" type="text" id="ttname" size="12" maxlength="30">&nbsp;&nbsp; <img src=../images/memo.gif alt="不能超过30个字符（15个汉字）"></td>
      </tr>
      <tr class="tr<%=skin%>">
        <td align="center">网站地址：</td>
        <td><input name="tturl" type="text" id="tturl" size="50" maxlength="100">&nbsp;&nbsp; <img src=../images/memo.gif alt="不能超过100个字符"><br>如果您站也使用类似友情链接管理系统，请先在贵站给本站注册一个ID号，再将链接代码填入此栏</td>
      </tr>
      <tr class="tr<%=skin%>">
        <td align="center">图片地址：</td>
        <td><input name="ttlogo" type="text" id="ttlogo" size="50" maxlength="100">&nbsp;&nbsp; <img src=../images/memo.gif alt="可选项，不能超过100个字符 （图片大小尺寸为:88*31，如果暂时没有，请留空）"></td>
      </tr>
      <tr class="tr<%=skin%>">
        <td align="center">网站类型：</td>
        <td><select name="webtype" size="1" id="webtype">
            <%call hx.listwebtype(0,0)%>
          </select>&nbsp;&nbsp; <img src=../images/memo.gif alt="请正确选择您网站的类型"></td>
      </tr>
      <tr class="tr<%=skin%>">
        <td align="center">密　　码：</td>
        <td><input name="password" type="password" id="password" size="12" maxlength="12">&nbsp;&nbsp; <img src=../images/memo.gif alt="4~12个字符"></td>
      </tr>
      <tr class="tr<%=skin%>">
        <td align="center">密码确认：</td>
        <td><input name="pwdconfirm" type="password" id="pwdconfirm" size="12" maxlength="12">&nbsp;&nbsp; <img src=../images/memo.gif alt="请再输一遍确认"></td>
      </tr>            
      <tr class="tr<%=skin%>">
        <td align="center">联系邮箱：</td>
        <td><input type="text" name="email" size="30" maxlength="50" value="ttxxxx@ttxxxx.com">&nbsp;&nbsp; <img src=../images/memo.gif alt="请输入有效的邮件地址<br>不能超过50个字符认"></td>
      </tr>
      <tr class="tr<%=skin%>">
        <td align="center">通知对方：</td>
        <td><input type="radio" name="inform" value="1" id="inform" >
                通知&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="inform" value="0" id="inform" checked>
                不通知&nbsp;&nbsp; <img src=../images/memo.gif alt="添加链接的同时是否<br>同时发送邮件通知对方网站主"></td>
      </tr>         
      <tr class="tr<%=skin%>">
        <td align="center">网站简介：</td>
        <td valign="middle"><textarea name="ttinfo" cols="70" rows="4" id="ttinfo" onkeyUp="textLimitCheck(this, 100);"></textarea>&nbsp;&nbsp; <img src=../images/memo.gif alt="不能超过100个字符（50个汉字）"><br>限 100 个字符 已输入 <font color="#CC0000"><span id="messageCount">0</span></font> 个字</td>
      </tr>
      <tr class="tr<%=skin%>">
        <td colspan="2" align="center" class="td"><input type="submit" value=" 确 定 " name="yes">
          <input name="reset" type="reset" 
value=" 重 写 ">
        </td>
      </tr>
  </table>
  </form>
  <%end sub%>
  <%sub addlink
dim username,ttname,tturl,ttlogo,email,password,pwdconfirm,webtype,ttinfo,inform
username=hx.checkstr(request.form("username"),12)
ttname=hx.checkstr(request.form("ttname"),30)
tturl=hx.checkstr(request.form("tturl"),100)
ttlogo=hx.checkstr(request.form("ttlogo"),100)
email=hx.checkstr(request.form("email"),50)
password=hx.checkstr(request.form("password"),12)
pwdconfirm=hx.checkstr(request.form("pwdconfirm"),12)
webtype=request.form("webtype")
ttinfo=hx.checkstr(request.form("ttinfo"),100)

dim blnerror,strerror
blnerror=false
if username="" or ttname="" or tturl="" or password="" or email="" then
	blnerror=true
	strerror="<li>请检查是否有必填信息没有填写！</li>"
end if

if blnerror=false then
if hx.blnfilter(ttname,1) then
	blnerror = true
	strerror = strerror & "<li>网站名称不能包含某些特殊关键词！</li>"
end if
if hx.blnfilter(ttinfo,1) then
	blnerror = true
	strerror = strerror & "<li>网站简介不能包含某些特殊关键词！</li>"
end if
if hx.blnfilter(tturl,2) then
	blnerror = true
	strerror = strerror & "<li>此域名已经被屏蔽！</li>"
end if

if ttlogo="" then
ttlogo="" &WebUrl & "link/images/wu.gif"
end if
if left(ttlogo,7)<>"http://" then ttlogo="http://" & ttlogo
if left(tturl,7)<>"http://" then tturl="http://" & tturl
'增强邮箱和网址的判断
if email<>"" and not CheckEmail(email) then
	blnerror = true
	strerror = strerror & "<li>联系邮箱不正确！</li>"
end if
'if not CheckUrl(tturl) then   '取消网址判断，否则使用类似链接系统的用户无法互相申请
'	blnerror = true
'	strerror = strerror & "<li>网址不正确！</li>"
'end if
if not isnumeric(webtype) then
	blnerror=true
	strerror=strerror & "<li>请正确选择网站类型！</li>"
end if
if len(password)<4 then 
	blnerror=true
	strerror=strerror & "<li>您的密码太短了！</li>"
end if
if password<>pwdconfirm then
	blnerror=true
	strerror=strerror & "<li>两次密码不相同！</li>"
end if


end if

if blnerror=false then
	dim rs,sql
	set rs=hx.execute("select username from tt_Link where username='"&username&"'")
	if not rs.eof then
		blnerror=true
		strerror=strerror & "<li>抱歉，用户名已经存在，请重新选择一个用户名</li>"		
	end if
	set rs=nothing	
end if

if blnerror=false then
'检测是否是同一域名 V1.6新增 051104
if IsDomainLimit = 1 then
	dim domain
	domain = mid(tturl,8)
	if instr(domain,"/")>0 then
	domain = left(domain,instr(domain,"/"))
	end if
	set rs=hx.execute("select username from tt_Link where tturl like '%"&domain&"%'")
	if not rs.eof then
		blnerror=true
		strerror=strerror & "<li>抱歉，此域名已经存在，系统限制一个域名只能注册一次。</li>"		
	end if
	set rs=nothing		
end if
end if


if blnerror=true then
	response.write strerror
	response.write "<p><< <a href=""javascript:history.go(-1)"">返回上一页 </a></p>"
else
	sql="select top 1 * from tt_Link"
	set rs=server.CreateObject("adodb.recordset")
	rs.open sql,conn,1,2
	rs.AddNew
	rs("username")=username
	rs("email")=email
	rs("ttname")=ttname
	rs("webtype")=webtype
	rs("password")=md5(password)	
	rs("tturl")=tturl
	if ttinfo="" then
	rs("ttinfo")=ttname
	else
	rs("ttinfo")=ttinfo
	end if
	rs("ttlogo")=ttlogo
	rs("isverify")=1
	rs.Update
	rs.close
	set rs=nothing	

if email<>"ttxxxx@ttxxxx.com" and emailkg=1 and request.form("inform")=1 then
'获得信息发送邮件
dim welcome,mailbody,tmpt,jmail,ErrStr
welcome= ""&ttname&"在【"&webname&"】申请的友情链接代码"
mailbody = "恭喜您，贵站－"&ttname&"在【"&webname&"】申请的友情链接成功！谢谢您的信任和支持，本站将尽快审核！请及时将友情链接代码加在您站上，并点击进入本站一次，以免耽误审核时间。<br><b>本站链接代码：</b><br>站名：<font color=#FF6600>"&webname&"</font><br>网址：<font color=red>http://"&hx.BaseUrl&"ttindex.asp?id="&username&"</font><br>LOGO：http://"&hx.BaseUrl&"images/logo.gif<br>简介：<font color=red>"&WebAlt&"</font>"

'jmail邮件组件发送邮件开始，下面的值要先取得
Set jmail = Server.CreateObject("JMail.Message") 
jmail.silent = true '屏蔽例外错误，返回FALSE跟TRUE两值
jmail.Logging = true '启用邮件日志
jmail.Charset = "gb2312"  '邮件的文字编码为国标
jmail.ContentType = "text/html"    '邮件的格式为HTML格式
jmail.MailServerUserName = servemail '输入smtp服务器验证登陆名 （邮局中任何一个用户的Email地址） 
jmail.MailServerPassword = servekey '输入smtp服务器验证密码 （用户Email帐号对应的密码） 
jmail.From = webemail '发信人信箱，因有的服务器反垃圾邮件，此信箱最好与发信服务器同域用户的信箱！ 
jmail.FromName = webname '发件人姓名或公司名 
jmail.AddRecipient email '收件人Email 
jmail.Subject = welcome '邮件的标题 
jmail.Body = mailbody '邮件的内容
 'jmail.Prority = 1      '邮件的紧急程序,必须服务器支持，1 为最快，5 为最慢， 3 为默认值 
jmail.Send (servesmtp) '执行邮件发送smtp服务器地址（企业邮局地址）
ErrStr =jmail.errormessage '允许错误 
set jmail = nothing '关闭对象
'邮件发送结束
if ErrStr = "" then
response.Write "<script language=javascript>alert('恭喜！申请友情链接成功,请尽快把链接代码放上您站，并点击进入本站一次。系统已发送一封邮件到您的信箱。');</script>"	
else
response.Write "<script language=javascript>alert('申请成功！等待审核。请尽快把链接代码放上您站，并点击进入本站一次。');</script>"
end if	'发送结果判断结束 
else
'response.Write "<script language=javascript>setTimeout(""location.replace('admin_addlink.asp')"",0)</script>"
end if
response.Write "<script language=javascript>alert('添加成功!');location.replace('admin_addlink.asp');</script>"
%>
  
 
  <%
end if
end sub


'邮箱验证
Function CheckEmail(str)
		Dim re,a
		Set re = New RegExp
		re.IgnoreCase = True
		re.Global = True
		re.Pattern = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
		a = re.Test(str)
		If a then 
			CheckEmail = True
		Else
			CheckEmail = False	
  End If	
end function
'网址验证
Function CheckUrl(str)
  Dim re,a
  Set re = New RegExp
  re.Pattern = "^https?:\/\/[\u4E00-\u9FA5a-zA-Z\.\/0-9]{3,}[\u4E00-\u9FA5a-zA-Z\/0-9]{2,}$" 
  re.IgnoreCase = False 
  a = re.Test(str)
  If a Then
    CheckUrl = true
  Else
    CheckUrl = false
  End If
End Function
%>
</div>
<!--#include file="../under.asp"-->
<%set hx=nothing%>
</body>
</html>
