<!-- #include file="include/onlogin.asp" -->
<!-- #include file="include/conn.asp" -->
<%
dim sqladd,pageurl,nummer,page,rssum,thepages,viewpage,nid,types,keyword,sea_type,d_id,p_id,username,ddim,pro_var,left_true
pro_var="host:虚拟空间|domain:国际域名|csk3000v:csk3000V|website:网站建设"
left_true="no":sqladd="":pageurl="?action="&action&"&"
nummer=15:rssum=0:thepages=0:viewpage=1
types=trim(request.querystring("types"))
if not(isnumeric(types)) then types=0
if int(types)>3 or int(types)<0 then types=1
types=int(types)
keyword=code_admin(request.querystring("keyword"))
sea_type=code_admin(request.querystring("sea_type"))
d_id=trim(request.querystring("d_id"))
p_id=trim(request.querystring("p_id"))
username=code_admin(request.querystring("username"))
tit="<a href='?'>客户管理</a> ┋ " & _
    "<a href='?action=product_list'>产品列表</a> ┋ " & _
    "<a href='?action=add&types="&types&"'>添加新客户</a>"
response.write header(10,tit)

if trim(request.querystring("del_ok"))="data" or trim(request.querystring("del_ok"))="product" then call del_select(trim(request.form("del_id")),trim(request.querystring("del_ok")))
sub del_select(delid,ddata)
  dim del_i,del_num,del_dim
  if delid<>"" and not isnull(delid) then
    delid=replace(delid," ",""):del_dim=split(delid,",")
    del_num=UBound(del_dim)
    for del_i=0 to del_num
      if ddata="data" then
        conn.execute("delete from client_"&ddata&" where d_id="&del_dim(del_i))
        conn.execute("delete from client_product where username='"&username&"'")
      elseif ddata="product" then
        conn.execute("delete from client_"&ddata&" where username='"&username&"' and p_id="&del_dim(del_i))
      end if
    next
    Erase del_dim
    response.write "<script language=javascript>alert(""共删除了 "&del_num+1&" 条记录！"");</script>"
  end if
end sub

if action="hidden" and isnumeric(d_id) then call client_hidden()
sub client_hidden()
  dim d_hidden
  sql="select d_hidden from client_data where d_id="&d_id
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then rs.close:set rs=nothing:exit sub
  d_hidden=rs("d_hidden")
  sql="update client_data set d_hidden="
  if d_hidden=true then
    sql=sql&"0"
  else
    sql=sql&"1"
  end if
  sql=sql&" where d_id="&d_id
  conn.execute(sql)
end sub

select case action
case "add"
  if types<>2 and types<>3 then types=1
  call client_add()
case "edit"
  call client_edit()
case "product_list"
  call client_product_list()
case "view"
  call client_view()
case "product"
  call client_product()
case "product_add"
  call client_product_add()
case "product_edit"
  call client_product_edit()
case "product_view"
  call client_product_view()
case else
  call client_main()
end select

call close_conn()
response.write ender()

sub client_product_list()
  dim d_name,p_name
  if len(keyword)>0 and len(sea_type)>0 then
    pageurl="sea_type="&server.urlencode(sea_type)&"&keyword="&server.urlencode(keyword)&"&"
    select case sea_type
    case "username","d_name","d_serial"
      sqladd=" where client_data."&sea_type&" like '%"&keyword&"%'"
    case "p_name","p_serial","p_price"
      sqladd=" where client_product."&sea_type&" like '%"&keyword&"%'"
    case else
      pageurl="":sqladd=""
    end select
  end if
  sql="select client_data.username,client_data.d_name,client_data.d_serial,client_product.p_id,client_product.p_name,client_product.p_serial,client_product.p_price " & _
      "from client_data inner join client_product on client_data.username=client_product.username" & _
      sqladd&" order by client_product.p_id desc"
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,1,1
  if not(rs.eof and rs.bof) then rssum=int(rs.recordcount)
  call format_pagecute()
%>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr bgcolor=<%response.write color2%>>
  <td colspan=3>&nbsp;浏览客户产品列表&nbsp;&nbsp;&nbsp;&nbsp;<%response.write go_back%></td>
  <td colspan=4 align=center>
    <table border=0 cellspacing=0 cellpadding=0><form action='?'>
    <tr><td>搜索：</td><input type=hidden name=action value='product_list'>
    <td align=center>&nbsp;<select name=sea_type>
<option value='d_name'>按客户名称</option>
<option value='d_serial'>按客户标识</option>
<option value='username'>按注册用户</option>
<option value='p_name'>按产品名称</option>
<option value='p_serial'>按产品标识</option>
<option value='p_price'>按产品价格</option>
</select></td>
    <td align=center>&nbsp;<input type=text name=keyword value='<%response.write keyword%>' size=12 maxlength=20></td>
    <td align=center>&nbsp;<input type=submit value='开始搜索'></td></tr>
    </form></table>
  </td>
  </tr>
  <tr align=center bgcolor=<%response.write color3%>>
  <td width='6%'>序号</td>
  <td width='16%'>注册用户</td>
  <td width='18%'>客户名称</td>
  <td width='16%'>客户标识</td>
  <td width='22%'>产品名称</td>
  <td width='12%'>产品标识</td>
  <td width='10%'>价格</td>
  </tr>
<%
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  for i=1 to nummer
    if rs.eof then exit for
    d_name=rs("d_name"):p_name=rs("p_name"):username=rs("username")
%>
  <tr align=center<%response.write mtr%>>
  <td><%response.write (viewpage-1)*nummer+i%>.</td>
  <td><%response.write format_user_view(rs("username"),1,"")%>　</td>
  <td><a href='?action=product&username=<%response.write server.urlencode(username)%>'><%response.write objv7.code_html(d_name,1,0)%></a>　</td>
  <td><%response.write objv7.code_html(rs("d_serial"),1,0)%>　</td>
  <td><a href='?action=product_view&username=<%response.write server.urlencode(username)%>&p_id=<%response.write rs("p_id")%>'><%response.write objv7.code_html(p_name,1,0)%></a>　</td>
  <td><%response.write objv7.code_html(rs("p_serial"),1,0)%>　</td>
  <td><%response.write objv7.code_html(rs("p_price"),1,0)%>　</td>
  </tr>
<%
    rs.movenext
  next
  if rssum=0 then response.write "<tr><td colspan=7 align=center height=50 class=gray>暂时没有客户产品</td></tr>"
%>
  <tr><td colspan=7>&nbsp;共<font class=red><%response.write rssum%></font>条&nbsp;&nbsp;页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font> 分页：<%response.write objv7.jk_pagecute(nummer,thepages,viewpage,pageurl,6,"#ff0000")%></td></tr>
  </table>
<%
  rs.close:set rs=nothing
end sub

sub client_view()
  call client_product_left()
  dim d_url
  sql="select * from client_data where username='"&username&"'"
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then rs.close:set rs=nothing:call client_main():exit sub
  d_url=rs("d_url")
%>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr><td colspan=2 bgcolor=<%response.write color2%>>&nbsp;浏览客户详细信息&nbsp;&nbsp;&nbsp;&nbsp;<a href='?action=edit&types=<%response.write rs("d_type")%>&d_id=<%response.write rs("d_id")%>'>编辑该客户的信息</a>&nbsp;&nbsp;&nbsp;&nbsp;<%response.write go_back%></td></tr>
  <tr><td width='20%'>注册用户：</td><td width='80%'><%response.write objv7.code_html(rs("username"),1,0)%>　</td></tr>
  <tr><td>公司名称：</td><td><%response.write objv7.code_html(rs("d_company"),1,0)%>　</td></tr>
  <tr><td>客户地址：</td><td><%response.write objv7.code_html(rs("d_address"),1,0)%>　</td></tr>
  <tr><td>联系电话：</td><td><%response.write objv7.code_html(rs("d_phone"),1,0)%>　</td></tr>
  <tr><td>电子邮件：</td><td><%response.write objv7.code_html(rs("d_email"),1,0)%>　</td></tr>
  <tr><td>网站地址：</td><td><a href='<%response.write objv7.code_html(d_url,1,0)%>' target=_blank><%response.write objv7.code_html(d_url,1,0)%></a>　</td></tr>
  <tr><td>QQ 妮称：</td><td><%response.write objv7.code_html(rs("d_qq"),1,0)%>　</td></tr>
  <tr><td>用户备注：</td><td><%response.write objv7.code_html(rs("d_remark1"),2,0)%>　</td></tr>
  <tr><td>管理备注：</td><td><%response.write objv7.code_html(rs("d_remark2"),2,0)%>　</td></tr>
  </table>
</td></tr>
</table>
<%
  rs.close:set rs=nothing
end sub

sub client_product_view()
  call client_product_left()
  dim p_tim_start,p_tim_end,p_url
  if not(isnumeric(p_id)) then call client_product():exit sub
  sql="select * from client_product where username='"&username&"' and p_id="&p_id
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then
    rs.close:set rs=nothing
    call client_product():exit sub
  end if
  p_url=rs("p_url"):p_tim_start=rs("p_tim_start"):p_tim_end=rs("p_tim_end")
%>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr><td colspan=2 bgcolor=<%response.write color2%>>&nbsp;浏览客户产品信息&nbsp;&nbsp;&nbsp;&nbsp;<a href='<%response.write pageurl%>action=product_edit&p_id=<%response.write p_id%>'>编辑该产品信息</a>&nbsp;&nbsp;&nbsp;&nbsp;<%response.write go_back%></td></tr>
  <tr><td width='20%'>产品类型：</td><td width='80%'><font class=red_3><%response.write pro_var_type(rs("p_sort"),1)%></font>&nbsp;&nbsp;&nbsp;&nbsp;产品价格：<font class=red><%response.write objv7.code_html(rs("p_price"),1,0)%></font></td></tr>
  <tr><td>产品名称：</td><td><font class=blue><%response.write objv7.code_html(rs("p_name"),1,0)%></font>&nbsp;&nbsp;&nbsp;&nbsp;产品标识：<font class=blue><%response.write objv7.code_html(rs("p_serial"),1,0)%></font></td></tr>
  <tr><td>开始时间：</td><td><%response.write objv7.time_type(p_tim_start,33)%>&nbsp;&nbsp;&nbsp;&nbsp;结束时间：<%response.write objv7.time_type(p_tim_end,33)%></td></tr>
  <tr><td>相关网址：</td><td><a href='<%response.write objv7.code_html(p_url,1,0)%>' target=_blank><%response.write objv7.code_html(p_url,1,0)%></a>　</td></tr>
  <tr><td>FTP 地址：</td><td><%response.write objv7.code_html(rs("p_ftp"),1,0)%>　</td></tr>
  <tr><td>FTP 用户：</td><td><%response.write objv7.code_html(rs("p_username"),1,0)%>&nbsp;&nbsp;&nbsp;&nbsp;FTP 密码：<%response.write objv7.code_html(rs("p_password"),1,0)%></td></tr>
  <tr><td>用户备注：</td><td><%response.write objv7.code_html(rs("p_remark1"),2,0)%>　</td></tr>
  <tr><td>管理备注：</td><td><%response.write objv7.code_html(rs("p_remark2"),2,0)%>　</td></tr>
  </table>
</td></tr>
</table>
<%
  rs.close:set rs=nothing
end sub

sub client_product_edit()
  call client_product_left()
  dim p_sort,p_price,p_name,p_serial,p_tim_start,p_tim_end
  if not(isnumeric(p_id)) then call client_product():exit sub
  sql="select * from client_product where username='"&username&"' and p_id="&p_id
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then
    rs.close:set rs=nothing
    call client_product():exit sub
  end if
%>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr><td colspan=2 bgcolor=<%response.write color2%>>&nbsp;修改客户产品信息&nbsp;&nbsp;&nbsp;&nbsp;<%response.write go_back%></td></tr>
<%
  if request.querystring("chk")="yes" then
    p_sort=code_admin(request.form("p_sort"))
    p_price=code_admin(request.form("p_price"))
    p_name=code_admin(request.form("p_name"))
    p_serial=code_admin(request.form("p_serial"))
    p_tim_start=trim(request.form("start_y"))&"-"&trim(request.form("start_m"))&"-"&trim(request.form("start_d"))
    p_tim_end=trim(request.form("end_y"))&"-"&trim(request.form("end_m"))&"-"&trim(request.form("end_d"))
    if len(p_sort)<1 or len(p_price)<1 or len(p_name)<1 or len(p_serial)<1 then
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red_2><font class=blue>产品类型</font>、<font class=blue>产品价格</font>、<font class=blue>产品名称</font> 和 <font class=blue>产品标识</font> 不能为空！</font><br><br>
请返回重新填写。<%response.write go_back%>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
    end if
    if not(isdate(p_tim_start)) or not(isdate(p_tim_end)) then
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red_2><font class=blue>开始时间</font> 和 <font class=blue>结束时间</font> 不能为空且格式应为：YYYY-MM-DD！</font><br><br>
请返回重新填写。<%response.write go_back%>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
    end if
    sql="update client_product set username='"&username&"',p_sort='"&p_sort&"',p_name='"&p_name&"'," & _
	"p_serial='"&p_serial&"',p_price='"&p_price&"',p_url='"&code_admin(request.form("p_url"))&"',p_ftp='"&code_admin(request.form("p_ftp"))&"'," & _
	"p_username='"&code_admin(request.form("p_username"))&"',p_password='"&code_admin(request.form("p_password"))&"'," & _
	"p_remark1='"&left(code_admin(request.form("p_remark1")),250)&"',p_remark2='"&left(code_admin(request.form("p_remark2")),250)&"'," & _
	"p_tim_start='"&p_tim_start&"',p_tim_end='"&p_tim_end&"' where p_id="&p_id
    conn.execute(sql)
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red>成功修改一个客户产品信息！</font><br><br><a href='<%response.write pageurl%>action=product'>点击返回</a>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
  end if
%>
  <form action='<%response.write pageurl%>action=product_edit&p_id=<%response.write p_id%>&chk=yes' method=post>
  <tr><td>注册用户：</td><td class=gray><input type=text name=username value='<%response.write username%>' disabled size=20 maxlength=20><%response.write redx%>&nbsp;网站里的注册名称</td></tr>
  <tr><td>产品类型：</td><td><select name=p_sort size=1><%
  p_sort=rs("p_sort"):ddim=split(pro_var,"|")
  for i=0 to ubound(ddim)
    response.write vbcrlf&"<option value='"&left(ddim(i),instr(1,ddim(i),":")-1)&"'"
    if p_sort=left(ddim(i),instr(1,ddim(i),":")-1) then response.write " selected"
    response.write ">"&right(ddim(i),len(ddim(i))-instr(1,ddim(i),":"))&"</option>"
  next
  erase ddim
%></select>&nbsp;&nbsp;&nbsp;产品价格：<input type=text name=p_price value='<%response.write rs("p_price")%>' size=16 maxlength=20><%response.write redx%></td></tr>
  <tr><td>产品名称：</td><td><input type=text name=p_name value='<%response.write rs("p_name")%>' size=20 maxlength=20><%response.write redx%>&nbsp;&nbsp;产品标识：<input type=text name=p_serial value='<%response.write rs("p_serial")%>' size=12 maxlength=20><%response.write redx%></td></tr>
  <tr><td>开始时间：</td><td><select name=start_y size=1><%
  p_tim_start=rs("p_tim_start")
  for i=year(p_tim_start)-2 to year(p_tim_start)+5
    response.write vbcrlf&"<option"
    if i=year(p_tim_start) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>年&nbsp;<select name=start_m size=1><%
  for i=1 to 12
    response.write vbcrlf&"<option"
    if i=month(p_tim_start) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>月&nbsp;<select name=start_d size=1><%
  for i=1 to 31
    response.write vbcrlf&"<option"
    if i=day(p_tim_start) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>日<%response.write redx%></td></tr>
  <tr><td>结束时间：</td><td><select name=end_y size=1><%
  p_tim_end=rs("p_tim_end")
  for i=year(p_tim_end)-2 to year(p_tim_end)+5
    response.write vbcrlf&"<option"
    if i=year(p_tim_end) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>年&nbsp;<select name=end_m size=1><%
  for i=1 to 12
    response.write vbcrlf&"<option"
    if i=month(p_tim_end) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>月&nbsp;<select name=end_d size=1><%
  for i=1 to 31
    response.write vbcrlf&"<option"
    if i=day(p_tim_end) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>日<%response.write redx%><font class=gray>不限可与开始时间相同</font></td></tr>
  <tr><td>相关网址：</td><td><input type=text name=p_url value='<%response.write rs("p_url")%>' size=40 maxlength=100></td></tr>
  <tr><td>FTP 地址：</td><td><input type=text name=p_ftp value='<%response.write rs("p_ftp")%>' size=40 maxlength=50></td></tr>
  <tr><td>FTP 用户：</td><td><input type=text name=p_username value='<%response.write rs("p_username")%>' size=18 maxlength=20>&nbsp;&nbsp;&nbsp;FTP 密码：<input type=text name=p_password value='<%response.write rs("p_password")%>' size=18 maxlength=20></td></tr>
  <tr><td valign=top><br>用户备注：<br><br><=250字</td><td><textarea name=p_remark1 rows=4 cols=50><%response.write rs("p_remark1")%></textarea></td></tr>
  <tr><td valign=top><br>管理备注：<br><br><=250字</td><td><textarea name=p_remark2 rows=4 cols=50><%response.write rs("p_remark2")%></textarea></td></tr>
  <tr><td colspan=2 align=center height=30><input type=submit value='提 交 修 改'>　　<input type=reset value='重新填写'></td></tr>
  </form></table>
</td></tr>
</table>
<%
  rs.close:set rs=nothing
end sub

sub client_product_add()
  call client_product_left()
  dim p_sort,p_price,p_name,p_serial,p_tim_start,p_tim_end
%>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr><td colspan=2 bgcolor=<%response.write color2%>>&nbsp;添加新的产品&nbsp;&nbsp;&nbsp;&nbsp;<%response.write go_back%></td></tr>
<%
  if request.querystring("chk")="yes" then
    p_sort=code_admin(request.form("p_sort"))
    p_price=code_admin(request.form("p_price"))
    p_name=code_admin(request.form("p_name"))
    p_serial=code_admin(request.form("p_serial"))
    p_tim_start=trim(request.form("start_y"))&"-"&trim(request.form("start_m"))&"-"&trim(request.form("start_d"))
    p_tim_end=trim(request.form("end_y"))&"-"&trim(request.form("end_m"))&"-"&trim(request.form("end_d"))
    if len(p_sort)<1 or len(p_price)<1 or len(p_name)<1 or len(p_serial)<1 then
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red_2><font class=blue>产品类型</font>、<font class=blue>产品价格</font>、<font class=blue>产品名称</font> 和 <font class=blue>产品标识</font> 不能为空！</font><br><br>
请返回重新填写。<%response.write go_back%>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
    end if
    if not(isdate(p_tim_start)) or not(isdate(p_tim_end)) then
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red_2><font class=blue>开始时间</font> 和 <font class=blue>结束时间</font> 不能为空且格式应为：YYYY-MM-DD！</font><br><br>
请返回重新填写。<%response.write go_back%>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
    end if
    sql="insert into client_product(username,p_sort,p_name,p_serial,p_price,p_url,p_ftp,p_username,p_password,p_remark1,p_remark2,p_tim_start,p_tim_end) " & _
	"values('"&username&"','"&p_sort&"','"&p_name&"','"&p_serial&"','"&p_price&"','"&code_admin(request.form("p_url"))&"','"&code_admin(request.form("p_ftp"))&"','"&code_admin(request.form("p_username"))&"','"&code_admin(request.form("p_password"))&"','"&left(code_admin(request.form("p_remark1")),250)&"','"&left(code_admin(request.form("p_remark2")),250)&"','"&p_tim_start&"','"&p_tim_end&"')"
    conn.execute(sql)
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red>成功增加一个客户产品信息！</font><a href='<%response.write pageurl%>action=product'>点击返回</a><br><br>
<a href='<%response.write pageurl%>action=product_add'>继续添加</a>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
  end if
%>
  <form action='<%response.write pageurl%>action=product_add&chk=yes' method=post>
  <tr><td>注册用户：</td><td class=gray><input type=text name=username value='<%response.write username%>' disabled size=20 maxlength=20><%response.write redx%>&nbsp;网站里的注册名称</td></tr>
  <tr><td>产品类型：</td><td><select name=p_sort size=1><%
  ddim=split(pro_var,"|")
  for i=0 to ubound(ddim)
    response.write vbcrlf&"<option value='"&left(ddim(i),instr(1,ddim(i),":")-1)&"'>"&right(ddim(i),len(ddim(i))-instr(1,ddim(i),":"))&"</option>"
  next
  erase ddim
%></select>&nbsp;&nbsp;&nbsp;产品价格：<input type=text name=p_price value='元' size=16 maxlength=20><%response.write redx%></td></tr>
  <tr><td>产品名称：</td><td><input type=text name=p_name size=20 maxlength=20><%response.write redx%>&nbsp;&nbsp;产品标识：<input type=text name=p_serial value='<%response.write objv7.rand_num(4)%>' size=12 maxlength=20><%response.write redx%></td></tr>
  <tr><td>开始时间：</td><td><select name=start_y size=1><%
  for i=year(now_time)-2 to year(now_time)+5
    response.write vbcrlf&"<option"
    if i=year(now_time) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>年&nbsp;<select name=start_m size=1><%
  for i=1 to 12
    response.write vbcrlf&"<option"
    if i=month(now_time) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>月&nbsp;<select name=start_d size=1><%
  for i=1 to 31
    response.write vbcrlf&"<option"
    if i=day(now_time) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>日<%response.write redx%></td></tr>
  <tr><td>结束时间：</td><td><select name=end_y size=1><%
  for i=year(now_time)-2 to year(now_time)+5
    response.write vbcrlf&"<option"
    if i=year(now_time) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>年&nbsp;<select name=end_m size=1><%
  for i=1 to 12
    response.write vbcrlf&"<option"
    if i=month(now_time) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>月&nbsp;<select name=end_d size=1><%
  for i=1 to 31
    response.write vbcrlf&"<option"
    if i=day(now_time) then response.write " selected"
    response.write ">"&i&"</option>"
  next
%></select>日<%response.write redx%><font class=gray>不限可与开始时间相同</font></td></tr>
  <tr><td>相关网址：</td><td><input type=text name=p_url value='http://' size=40 maxlength=100></td></tr>
  <tr><td>FTP 地址：</td><td><input type=text name=p_ftp size=40 maxlength=50></td></tr>
  <tr><td>FTP 用户：</td><td><input type=text name=p_username size=18 maxlength=20>&nbsp;&nbsp;&nbsp;FTP 密码：<input type=text name=p_password size=18 maxlength=20></td></tr>
  <tr><td valign=top><br>用户备注：<br><br><=250字</td><td><textarea name=p_remark1 rows=4 cols=50></textarea></td></tr>
  <tr><td valign=top><br>管理备注：<br><br><=250字</td><td><textarea name=p_remark2 rows=4 cols=50></textarea></td></tr>
  <tr><td colspan=2 align=center height=30><input type=submit value='提 交 添 加'>　　<input type=reset value='重新填写'></td></tr>
  </form></table>
</td></tr>
</table>
<%
end sub

function pro_var_type(vvar,vt)
  dim i,ddim,j:j=0
  ddim=split(pro_var,"|")
  for i=0 to ubound(ddim)
    if vvar=left(ddim(i),instr(1,ddim(i),":")-1) then j=i
  next
  if vt=1 then
    pro_var_type=right(ddim(j),len(ddim(j))-instr(1,ddim(j),":"))
  else
    pro_var_type=left(ddim(j),instr(1,ddim(j),":")-1)
  end if
end function

sub client_product()
  call client_product_left()
%>
  <table border=1 width='100%' cellspacing=0 cellpadding=1<%response.write table1%>>
  <tr><td colspan=6 height=22 bgcolor=<%response.write color2%>>&nbsp;客户产品列表&nbsp;&nbsp;&nbsp;&nbsp;<a href='<%response.write pageurl%>action=product_add'>添加新的产品</a></td></tr>
  <tr align=center bgcolor=<%response.write color3%>>
  <td width='8%'>序号</td>
  <td width='15%'>产品类型</td>
  <td width='30%'>产品名称</td>
  <td width='18%'>产品编号</td>
  <td width='14%'>价格</td>
  <td width='15%'>相关操作</td>
  </tr>
  <script language=javascript src='style/admin_del.js'></script>
  <form name=del_form action='<%response.write pageurl%>action=product&del_ok=product' method=post>
<%
  i=0
  sql="select p_id,p_sort,p_name,p_serial,p_price from client_product where username='"&username&"' order by p_id desc"
  set rs=conn.execute(sql)
  do while not rs.eof
    nid=rs("p_id")
%>
  <tr align=center>
  <td><%response.write i+1%>.</td>
  <td><%response.write pro_var_type(rs("p_sort"),1)%>　</td>
  <td><a href='<%response.write pageurl%>action=product_view&p_id=<%response.write nid%>'><%response.write rs("p_name")%></a>　</td>
  <td><%response.write rs("p_serial")%>　</td>
  <td><%response.write rs("p_price")%>　</td>
  <td><a href='<%response.write pageurl%>action=product_edit&p_id=<%response.write nid%>'>修改</a> <input type=checkbox name=del_id value='<%response.write nid%>'></td>
  </tr>
<%
    rs.movenext:i=i+1
  loop
  rs.close:set rs=nothing
  if i=0 then response.write "<tr><td height=50 colspan=6 align=center class=gray>暂时还没有产品&nbsp;&nbsp;&nbsp;&nbsp;<a href='"&pageurl&"action=product_add'>添加新的产品</a></td></tr>"
%>
  <tr><td height=30 colspan=6 align=center>该客户现有 <font class=red><%response.write rssum%></font> 个产品　
<input type=checkbox name=del_all value=1 onClick="javascript:selectall('<%response.write i%>');"> 选中所有　<input type=submit value='删除所选' onclick="return suredel('<%response.write i%>');"></td></tr>
  </table>
</td></tr>
</table>
<%
end sub

sub client_product_left()
  if len(username)<1 then call client_main():exit sub
  sql="select d_name,d_serial,d_type,d_hidden from client_data where username='"&username&"'"
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then rs.close:set rs=nothing:call client_main():exit sub
  pageurl="?username="&server.urlencode(username)&"&"
  if left_true="no" then
%>
<table border=0 width='100%'>
<tr align=center valign=top>
<td width='30%' height=300>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr><td colspan=2 bgcolor=<%response.write color2%>>&nbsp;客户基本信息</td></tr>
  <tr><td width='40%'>注册用户：</td><td width='60%'><%response.write format_user_view(username,1,"")%>　</td></tr>
  <tr><td>真实姓名：</td><td class=blue><%response.write rs("d_name")%>　</td></tr>
  <tr><td>客户标识：</td><td><%response.write rs("d_serial")%>　</td></tr>
  <tr><td>客户类型：</td><td><%response.write client_d_type(rs("d_type"),1)%>客户</td></tr>
  <tr><td>当前状态：</td><td><%
if rs("d_hidden")=true then
  response.write "正常"
else
  response.write "<font class=red_2>锁定</font>"
end if
%>　</td></tr>
  <tr><td colspan=2 align=center>
    <table border=0>
    <tr><td><%response.write img_small("jt1")%><a href='<%response.write pageurl%>action=product'>浏览该客户产品信息</a></td></tr>
    <tr><td><%response.write img_small("jt12")%><a href='<%response.write pageurl%>action=product_add'>添加该客户的新产品</a></td></tr>
    <tr><td><%response.write img_small("jt13")%><a href='<%response.write pageurl%>action=view'>浏览该客户详细信息</a></td></tr>
    </table>
  </td></tr>
  </table>
</td>
<td width='70%'>
<%
    left_true="yes"
  end if
  rs.close:set rs=nothing
end sub

sub client_edit()
  dim username,d_name,d_serial,d_hidden
  if not(isnumeric(d_id)) then call client_main():exit sub
  sql="select * from client_data where d_id="&d_id
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then rs.close:set rs=nothing:call client_main():exit sub
  call client_left()
%>
<table border=1 width=400 cellspacing=0 cellpadding=2<%response.write table1%>>
<tr bgcolor=<%response.write color3%>><td colspan=2 align=center height=30><font class=red>修改 <%response.write client_d_type(types,1)%>客户 信息</font></td></tr>
<%
  if request.querystring("chk")="yes" then
    rs.close:set rs=nothing
    types=code_admin(request.form("d_type"))
    if not(isnumeric(types)) then types=0
    if int(types)>3 or int(types)<1 then types=1
    username=code_admin(request.form("username"))
    d_name=code_admin(request.form("d_name"))
    d_serial=code_admin(request.form("d_serial"))
    if len(d_name)<1 or len(d_serial)<1 then
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red_2><font class=blue>真实姓名</font> 和 <font class=blue>客户标识</font> 不能为空！</font><br><br>
请返回重新填写。<%response.write go_back%>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
    end if
    sql="update client_data set username='"&username&"',d_type="&types&",d_name='"&d_name&"'," & _
	"d_serial='"&d_serial&"',d_company='"&code_admin(request.form("d_company"))&"',d_address='"&code_admin(request.form("d_address"))&"',d_phone='"&code_admin(request.form("d_phone"))&"'," & _
	"d_email='"&code_admin(request.form("d_email"))&"',d_url='"&code_admin(request.form("d_url"))&"',d_qq='"&code_admin(request.form("d_qq"))&"'," & _
	"d_remark1='"&left(code_admin(request.form("d_remark1")),250)&"',d_remark2='"&left(code_admin(request.form("d_remark2")),250)&"',d_hidden="&trim(request.form("d_hidden"))&" where d_id="&d_id
    conn.execute(sql)
    if code_admin(request.form("username2"))<>username and len(code_admin(request.form("username2")))>0 then
      conn.execute("update client_product set username='"&code_admin(request.form("username2"))&"' where username='"&username&"'")
    end if
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red>成功修改一个 <%response.write client_d_type(types,1)%>客户 的信息！</font><br><br>
<a href='?types=<%response.write types%>'>点击返回</a>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
  end if
  
  d_hidden=rs("d_hidden"):types=rs("d_type")
  if not(isnumeric(types)) then types=0
  if int(types)>3 or int(types)<1 then types=1
  types=int(types)
%>
<form action='<%response.write pageurl%>d_id=<%response.write d_id%>&chk=yes' method=post>
<tr><td>注册用户：</td><td class=gray><input type=text name=username value='<%response.write rs("username")%>' size=20 maxlength=20><%response.write redx%>&nbsp;网站里的注册名称</td></tr><input type=hidden name=username2 value='<%response.write rs("username")%>'>
<tr><td>客户类型：</td><td><input type=radio name=d_type value='1'<%if types=1 then response.write " checked"%>> 个人  <input type=radio name=d_type value='2'<%if types=2 then response.write " checked"%>> 企业  <input type=radio name=d_type value='3'<%if types=3 then response.write " checked"%>> 代理</td></tr>
<tr><td>真实姓名：</td><td><input type=text name=d_name value='<%response.write rs("d_name")%>' size=20 maxlength=20><%response.write redx%><input type=radio name=d_hidden value='1'<%if d_hidden=true then response.write " checked"%>> 正常  <input type=radio name=d_hidden value='0'<%if d_hidden=false then response.write " checked"%>> 锁定</td></tr>
<tr><td>客户标识：</td><td><input type=text name=d_serial value='<%response.write rs("d_serial")%>' size=20 maxlength=20><%response.write redx%></td></tr>
<tr><td>公司名称：</td><td><input type=text name=d_company value='<%response.write rs("d_company")%>' size=40 maxlength=50></td></tr>
<tr><td>客户地址：</td><td><input type=text name=d_address value='<%response.write rs("d_address")%>' size=40 maxlength=100></td></tr>
<tr><td>联系电话：</td><td><input type=text name=d_phone value='<%response.write rs("d_phone")%>' size=30 maxlength=30></td></tr>
<tr><td>电子邮件：</td><td><input type=text name=d_email value='<%response.write rs("d_email")%>' size=30 maxlength=50></td></tr>
<tr><td>网站地址：</td><td><input type=text name=d_url value='<%response.write rs("d_url")%>' size=40 maxlength=100></td></tr>
<tr><td>QQ 妮称：</td><td><input type=text name=d_qq value='<%response.write rs("d_qq")%>' size=30 maxlength=20></td></tr>
<tr><td valign=top><br>用户备注：<br><br><=250字</td><td><textarea name=d_remark1 rows=5 cols=40><%response.write rs("d_remark1")%></textarea></td></tr>
<tr><td valign=top><br>管理备注：<br><br><=250字</td><td><textarea name=d_remark2 rows=5 cols=40><%response.write rs("d_remark2")%></textarea></td></tr>
<tr><td colspan=2 align=center height=30><input type=submit value='提 交 修 改'>　　<input type=reset value='重新填写'></td></tr>
</form></table>
</td></tr></table>
<%
  rs.close:set rs=nothing
end sub

sub client_add()
  dim username,d_name,d_serial
  call client_left()
%>
<table border=1 width=400 cellspacing=0 cellpadding=2<%response.write table1%>>
<tr bgcolor=<%response.write color3%>><td colspan=2 align=center height=30><font class=red>添加新 <%response.write client_d_type(types,1)%>客户 信息</font></td></tr>
<%
  if request.querystring("chk")="yes" then
    types=code_admin(request.form("d_type"))
    if not(isnumeric(types)) then types=0
    if int(types)>3 or int(types)<1 then types=1
    username=code_admin(request.form("username"))
    d_name=code_admin(request.form("d_name"))
    d_serial=code_admin(request.form("d_serial"))
    if len(d_name)<1 or len(d_serial)<1 then
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red_2><font class=blue>真实姓名</font> 和 <font class=blue>客户标识</font> 不能为空！</font><br><br>
请返回重新填写。<%response.write go_back%>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
    end if
    sql="insert into client_data(username,d_type,d_name,d_serial,d_company,d_address,d_phone,d_email,d_url,d_qq,d_remark1,d_remark2,d_hidden) " & _
	"values('"&username&"',"&types&",'"&d_name&"','"&d_serial&"','"&code_admin(request.form("d_company"))&"','"&code_admin(request.form("d_address"))&"','"&code_admin(request.form("d_phone"))&"','"&code_admin(request.form("d_email"))&"','"&code_admin(request.form("d_url"))&"','"&code_admin(request.form("d_qq"))&"','"&left(code_admin(request.form("d_remark1")),250)&"','"&left(code_admin(request.form("d_remark2")),250)&"',"&trim(request.form("d_hidden"))&")"
    conn.execute(sql)
%>
<tr><td colspan=2 align=center height=150>
提示信息：<font class=red>成功增加一个 <%response.write client_d_type(types,1)%>客户 的信息！</font><a href='?types=<%response.write types%>'>点击返回</a><br><br>
<a href='?action=add&types=<%response.write types%>'>继续添加</a>
</td></tr>
<table>
</td></tr></table>
</td></tr></table>
<%
      exit sub
  end if
%>
<form action='<%response.write pageurl%>chk=yes' method=post>
<tr><td>注册用户：</td><td class=gray><input type=text name=username size=20 maxlength=20><%response.write redx%>&nbsp;网站里的注册名称</td></tr>
<tr><td>客户类型：</td><td><input type=radio name=d_type value='1'<%if types=1 then response.write " checked"%>> 个人  <input type=radio name=d_type value='2'<%if types=2 then response.write " checked"%>> 企业  <input type=radio name=d_type value='3'<%if types=3 then response.write " checked"%>> 代理</td></tr>
<tr><td>真实姓名：</td><td><input type=text name=d_name size=20 maxlength=20><%response.write redx%><input type=radio name=d_hidden value='1' checked> 正常  <input type=radio name=d_hidden value='0'> 锁定</td></tr>
<tr><td>客户标识：</td><td><input type=text name=d_serial size=20 maxlength=20><%response.write redx%></td></tr>
<tr><td>公司名称：</td><td><input type=text name=d_company size=40 maxlength=50></td></tr>
<tr><td>客户地址：</td><td><input type=text name=d_address size=40 maxlength=100></td></tr>
<tr><td>联系电话：</td><td><input type=text name=d_phone size=30 maxlength=30></td></tr>
<tr><td>电子邮件：</td><td><input type=text name=d_email size=30 maxlength=50></td></tr>
<tr><td>网站地址：</td><td><input type=text name=d_url value='http://' size=40 maxlength=100></td></tr>
<tr><td>QQ 妮称：</td><td><input type=text name=d_qq size=30 maxlength=20></td></tr>
<tr><td valign=top><br>用户备注：<br><br><=250字</td><td><textarea name=d_remark1 rows=5 cols=40></textarea></td></tr>
<tr><td valign=top><br>管理备注：<br><br><=250字</td><td><textarea name=d_remark2 rows=5 cols=40></textarea></td></tr>
<tr><td colspan=2 align=center height=30><input type=submit value='提 交 添 加'>　　<input type=reset value='重新填写'></td></tr>
</form></table>
</td></tr></table>
<%
end sub

sub client_main()
  dim d_hidden,del_temp
  if int(types)>0 then sqladd=" where d_type="&types
  if len(keyword)>0 and len(sea_type)>0 then
    if len(sqladd)>0 then
      sqladd=sqladd&" and "&sea_type&" like '%"&keyword&"%'"
    else
      sqladd=" where "&sea_type&" like '%"&keyword&"%'"
    end if
    pageurl="sea_type="&server.urlencode(sea_type)&"&keyword="&server.urlencode(keyword)&"&"
  end if
  set rs=server.createobject("adodb.recordset")
  sql="select d_id,username,d_type,d_name,d_serial,d_hidden from client_data"&sqladd&" order by d_id desc"
  rs.open sql,conn,1,1
  if not(rs.eof and rs.bof) then rssum=int(rs.recordcount)
  call format_pagecute()
  del_temp=nummer
  if rssum=0 then del_temp=0
  if int(page)=int(thepages) then del_temp=rssum-nummer*(thepages-1)
  call client_left()
%>
  <table border=1 width='100%' cellspacing=0 cellpadding=1<%response.write table1%>>
  <script language=javascript src='style/admin_del.js'></script>
  <form name=del_form action='<%response.write pageurl%>del_ok=data' method=post>
  <tr align=center height=30>
  <td colspan=3>现有 <font class=red><%response.write rssum%></font> 位 <font class=blue><%response.write client_d_type(types,1)%>客户</font> 　 每页 <font class=red><%response.write nummer%></font> 位</td>
  <td colspan=4><input type=checkbox name=del_all value=1 onClick="javascript:selectall('<%response.write del_temp%>');"> 选中所有　<input type=submit value='删除所选' onclick="return suredel('<%response.write del_temp%>');"></td>
  </tr>
  <tr align=center bgcolor=<%response.write color2%>>
  <td width='8%'>序号</td>
  <td width='22%'>客户名称</td>
  <td width='22%'>客户标识</td>
  <td width='20%'>注册用户</td>
  <td width='8%'>类型</td>
  <td width='8%'>状态</td>
  <td width='12%'>操作</td>
  </tr>
<%
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  for i=1 to nummer
    if rs.eof then exit for
    nid=rs("d_id"):username=rs("username"):d_hidden=rs("d_hidden"):types=rs("d_type")
%>
  <tr<%response.write mtr%>>
  <td><%response.write (viewpage-1)*nummer+i%>.</td>
  <td><a href='?action=product&username=<%response.write server.urlencode(username)%>'><%response.write objv7.code_html(rs("d_name"),1,0)%></a>　</td>
  <td><%response.write objv7.code_html(rs("d_serial"),1,0)%>　</td>
  <td><%response.write format_user_view(rs("username"),1,"")%>　</td>
  <td align=center><%response.write client_d_type(types,1)%>　</td>
  <td align=center>
  <a href='?types=<%response.write types%>&action=hidden&d_id=<%response.write nid%><%if d_hidden=true then  response.write "'>正常"else  response.write "' class=red_2>锁定"end if%>&lt;/td&gt;  &lt;td align=center&gt;&lt;a href='?action=edit&types=<%response.write types%>&d_id=<%response.write nid%>'>修改</a><input type=checkbox name=del_id value='<%response.write nid%>' class=bg_1></td>
  </tr>
<%
    rs.movenext
  next
  rs.close:set rs=nothing
%>
  <tr><td colspan=7> 页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font> 分页：<%response.write objv7.jk_pagecute(nummer,thepages,viewpage,pageurl,6,"#ff0000")%></td></tr>
  </form></table>
</td>
</tr>
</table>
<%
end sub

sub client_left()
%>
<table border=0 width='100%'>
<tr align=center valign=top>
<td width='20%' height=300>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr><td bgcolor=<%response.write color2%>>&nbsp;客户类型</td></tr>
  <tr><td align=center class=htd><a href='?types=1'<%if types=1 then response.write " class=red_3"%>><%response.write client_d_type(1,1)%>客户</a><br>
<a href='?types=2'<%if types=2 then response.write " class=red_3"%>><%response.write client_d_type(2,1)%>客户</a><br>
<a href='?types=3'<%if types=3 then response.write " class=red_3"%>><%response.write client_d_type(3,1)%>客户</a></td></tr>
  <tr><td align=center height=30><a href='?action=add&types=<%response.write types%>'>添加新客户</a></td></tr>
  </table>
  <%response.write kong%>
  <table border=1 width='100%' cellspacing=0 cellpadding=2<%response.write table1%>>
  <tr><td bgcolor=<%response.write color2%>>&nbsp;客户搜索</td></tr>
  <tr><td align=center>
    <table border=0><form action='?'>
    <tr><td align=center><select name=sea_type>
<option value='d_name'>按客户名称</option>
<option value='d_serial'>按客户标识</option>
<option value='username'>按注册用户</option>
<option value='d_qq'>按 QQ 号码</option>
</select></td></tr>
    <tr><td align=center><input type=checkbox name=types value='<%response.write types%>'>搜索当前类型</td></tr>
    <tr><td align=center><input type=text name=keyword value='<%response.write keyword%>' size=12 maxlength=20></td></tr>
    <tr><td align=center><input type=submit value='开始搜索'></td></tr>
    </form></table>
  </td></tr>
  </table>
</td>
<td width='80%'>
<%
end sub

function client_d_type(dv,dt)
  select case int(dt)
  case 1
    if not(isnumeric(dv)) then dv=1
    select case int(dv)
    case 1
      client_d_type="个人":exit function
    case 2
      client_d_type="企业":exit function
    case 3
      client_d_type="代理":exit function
    case else
      client_d_type="所有":exit function
    end select
  case 2
    select case dv
    case "企业"
      client_d_type=2:exit function
    case "代理"
      client_d_type=3:exit function
    case "个人"
      client_d_type=1:exit function
    end select
  end select
end function
%>