<!-- #include file="include/admin_onlogin.asp" -->
<%
'****************************************************
' 阳光情缘 2006V3.0      Power by sdsun.com.cn
' Email: 27072320@qq.com  , sdsun163@163.com
' Web: http://www.sdsun.com.cn
' Copyright (C) 2006 sdsun.com.cn All Rights Reserved.
'****************************************************


dim dim_sort(3,1),dim_n,sort
dim_n=3
dim_sort(0,0)="fir"
dim_sort(0,1)="首页"
dim_sort(1,0)="sec"
dim_sort(1,1)="内页"
dim_sort(2,0)="forum"
dim_sort(2,1)="论坛"
dim_sort(3,0)="txt"
dim_sort(3,1)="文字"
sort=trim(request.querystring("sort"))
select case sort
case "fir"
  ntit="首页"
case "sec"
  ntit="内页"
case "forum"
  ntit="论坛"
case "txt"
  ntit="文字"
case else
  sort=""
  ntit="所有"
end select
del_user_true=false
index_url="links"
call admin_master(0,0)
call admin_header(0,0)

function link_sort_type(nsort)
  select case nsort
  case "fir","sec","forum","txt"
    link_sort_type=nsort
  case else
    link_sort_type=""
  end select
end function
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?'><%response.write tit%></a></td>
  <td width=10></td>
  <td><a href='?sort=fir'<%if sort="fir" then response.write " class=red"%>>首页<%response.write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?sort=sec'<%if sort="sec" then response.write " class=red"%>>内页<%response.write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?sort=forum'<%if sort="forum" then response.write " class=red"%>>论坛<%response.write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?sort=txt'<%if sort="txt" then response.write " class=red"%>>文字<%response.write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?action=add'>添加新<%response.write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?action=list'>重新排序</a></td>
  <td width=10></td>
  <td><a href='?action=js'>JS 生成</a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
call admin_table(1)
if action="handle" then call joekoe_go_handle()
if action="order" then call joekoe_chk_order()

select case action
case "list"
  call joekoe_chk_list()
case "js"
  call joekoe_chk_js()
case "add"
  call joekoe_chk_add()
case "edit"
  call joekoe_chk_edit()
case else
  call joekoe_chk_main()
end select

erase dim_sort
call admin_ender(1)

sub joekoe_chk_js()
  dim filetype,file_name
  file_name="style/data_link.js"
  filetype=links_fso("fir",8)
  call create_file(file_name,filetype)
  
  file_name="style/data_link_fir.js"
  filetype=links_fso("fir",5)
  call create_file(file_name,filetype)
  
  file_name="style/data_link_sec.js"
  filetype=links_fso("sec",5)
  call create_file(file_name,filetype)
  
  file_name="style/data_link_forum_main.js"
  filetype=links_fso("forum",8)
  call create_file(file_name,filetype)
  
  file_name="style/data_link_forum.js"
  filetype=links_fso("forum",5)
  call create_file(file_name,filetype)
  
  file_name="style/data_link_txt.js"
  filetype=links_fso("txt",5)
  call create_file(file_name,filetype)
  
  call admin_msg("生成 JS 成功！","?",1)
end sub

function links_fso(lt,nummer)
  dim temp1,nname,topic
  temp1="document.write (""<table border=0 width='100%' cellspacing=2 cellpadding=2>"");"
  sql="select * from links where sort='"&lt&"' and hidden=1 order by orders"
  set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    temp1=temp1&vbcrlf&"document.write (""<tr align=center>"");"
    for i=1 to nummer
      if rs.eof then exit for
      temp1=temp1&vbcrlf&"document.write (""<td><a href='"&rs("url")&"' target=_blank>"
      if lt="txt" then
        temp1=temp1&joekoe_cms.code_js(joekoe_cms.code_html(rs("nname"),1,0),1)
      else
        temp1=temp1&"<img src='"&rs("pic")&"' border=0 width=88 height=31 alt='"&joekoe_cms.code_js(rs("nname"),1)&"'>"
      end if
      temp1=temp1&"</a></td>"");"
      rs.movenext
    next
    temp1=temp1&vbcrlf&"document.write (""</tr>"");"
  loop
  rs.close
  temp1=temp1&vbcrlf&"document.write (""</table>"");"
  links_fso=temp1
end function

sub joekoe_chk_list()
  dim j
  for j=0 to dim_n
    rssum=0
    sql="select * from links where sort='"&dim_sort(j,0)&"' order by orders,id"
    call joekoe_cms.exec("",-1)
    rs.open sql,conn,1,3
    if not rs.eof then rssum=rs.recordcount
    for i=1 to rssum
      rs("orders")=i
      rs.update
      rs.movenext
    next
    rs.close
  next
  call admin_msg("已成功对所有"&tit_fir&"进行重新排序 ！","?",1)
end sub

function joekoe_chk_order()
  dim actions,tmp_id_1,tmp_id_2,tmp_order_1,tmp_order_2,update_ok
  actions=trim(request.querystring("actions"))
  update_ok="no"
  sql_add=""
  if actions="up" then sql_add=" desc"
  sql="select sort from links where id="&id
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then
    sort=link_sort_type(rs("sort"))
  end if
  rs.close
  if sort="" then call joekoe_chk_edit()
  
  sql="select * from links where sort='"&sort&"' order by orders"&sql_add
  set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    if int(rs("id"))=int(id) then
      tmp_id_1=id
      tmp_order_1=rs("orders")
      rs.movenext
      if not rs.eof then
        tmp_id_2=rs("id")
        tmp_order_2=rs("orders")
        update_ok="yes"
        exit do
      end if
      exit do
    end if
    rs.movenext
  loop
  rs.close
  
  if update_ok="yes" then
    sql="update links set orders="&tmp_order_2&" where id="&tmp_id_1
    call joekoe_cms.exec(sql,0)
    sql="update links set orders="&tmp_order_1&" where id="&tmp_id_2
    call joekoe_cms.exec(sql,0)
  end if
end function

sub joekoe_chk_edit()
  dim nname,orders,nsort,hidden
  call admin_td("编辑"&tit_fir)
  sql="select top 1 * from links where id="&id
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,3
  if rs.eof then
    rs.close
    call admin_msg(tit&"（"&id&"）不存在！","?sort="&sort,0)
    exit sub
  end if
  if chk() then
    nname=code_admin("nname",1,20)
    nsort=link_sort_type(code_admin("sort",1,0))
    hidden=true
    if trim(request.form("hidden"))="yes" then hidden=false
    if nname="" or nsort="" then
      rs.close
      call admin_error(tit_fir&"类型 和 网站名称 不能为空！")
      exit sub
    end if
    rs("sort")=nsort
    rs("nname")=nname
    rs("url")=code_admin("url",1,100)
    rs("pic")=code_admin("pic",1,100)
    rs("hidden")=hidden
    rs.update
    rs.close
    call admin_msg("成功编辑一项"&tit,"?sort="&sort,0)
    exit sub
  end if
  call form_first()
  nsort=rs("sort")
%>
<form action='?action=edit&sort=<%response.write sort%>&id=<%response.write id%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td><%response.write tit_fir%>类型：</td>
<td><input type=radio name=sort value='fir'<%if nsort="fir" then response.write " checked"%>>首页<%response.write tit_fir%>
<input type=radio name=sort value='sec'<%if nsort="sec" then response.write " checked"%>>内页<%response.write tit_fir%>
<input type=radio name=sort value='forum'<%if nsort="forum" then response.write " checked"%>>论坛<%response.write tit_fir%>
<input type=radio name=sort value='txt'<%if nsort="txt" then response.write " checked"%>>文字<%response.write tit_fir%></td>
</tr>
<tr>
<td>网站名称：</td>
<td><input type=text name=nname value='<%response.write rs("nname")%>' size=50 maxlength=20></td>
</tr>
<tr>
<td><%response.write tit_fir%>地址：</td>
<td><input type=text name=url value='<%response.write rs("url")%>' size=50 maxlength=100></td>
</tr>
<tr>
<td><%response.write tit_fir%>LOGO：</td>
<td><input type=text name=pic value='<%response.write rs("pic")%>' size=60 maxlength=100></td>
</tr>
<tr>
<td>是否隐藏：</td>
<td><input type=checkbox name=hidden value='yes'<%if rs("hidden")=false then response.write " checked"%>> 选择表示隐藏该<%response.write tit_fir%></td>
</tr>
<%
  call submit_edit()
  rs.close
end sub

sub joekoe_chk_add()
  dim nname,orders,nsort,hidden
  call admin_td("添加"&tit_fir)
  if chk() then
    nname=code_admin("nname",1,20)
    nsort=link_sort_type(code_admin("sort",1,0))
    if nname="" or nsort="" then
      call admin_error(tit_fir&"类型 和 网站名称 不能为空！")
      exit sub
    end if
    orders=1
    sql="select top 1 orders from links where sort='"&nsort&"' order by orders desc"
    set rs=joekoe_cms.exec(sql,1)
    if not rs.eof then orders=int(rs("orders"))+1
    rs.close
    
    sql="select * from links"
    call joekoe_cms.exec("",-1)
    rs.open sql,conn,1,3
    rs.addnew
    rs("orders")=orders
    rs("sort")=nsort
    rs("nname")=nname
    rs("url")=code_admin("url",1,100)
    rs("pic")=code_admin("pic",1,100)
    rs("hidden")=true
    rs.update
    rs.close
    call admin_msg("成功添加一项新的"&tit,"?",0)
    exit sub
  end if
  call form_first()
%>
<form action='?action=add' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td><%response.write tit_fir%>类型：</td>
<td><input type=radio name=sort value='fir' checked>首页<%response.write tit_fir%>
<input type=radio name=sort value='sec'>内页<%response.write tit_fir%>
<input type=radio name=sort value='forum'>论坛<%response.write tit_fir%>
<input type=radio name=sort value='txt'>文字<%response.write tit_fir%></td>
</tr>
<tr>
<td>网站名称：</td>
<td><input type=text name=nname size=50 maxlength=20></td>
</tr>
<tr>
<td><%response.write tit_fir%>地址：</td>
<td><input type=text name=url value='http://' size=50 maxlength=100></td>
</tr>
<tr>
<td><%response.write tit_fir%>LOGO：</td>
<td><input type=text name=pic value='images/links/' size=60 maxlength=100></td>
</tr>
<tr>
<td>是否隐藏：</td>
<td><input type=checkbox name=hidden value='yes'> 选择表示隐藏该<%response.write tit_fir%></td>
</tr>
<%
  call submit_add()
end sub

sub joekoe_chk_main()
  dim url,nname
  nummer=10
  nums=nummer
%>
<form name=sel_form action='?jk_mod=<%response.write jk_mod%>&sort=<%response.write sort%>&action=handle' method=post>
<tr align=center>
<td class=td width='6%'>序号</td>
<td class=td width='20%'>LOGO</td>
<td class=td width='20%'>网站名称</td>
<td class=td width='30%'>网站地址</td>
<td class=td width='18%'>操作</td>
<td class=td width='6%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
</tr>
<%
  if sort<>"" then
    sql_add=" where sort='"&sort&"'"
    pageurl=pageurl&"sort="&sort&"&"
  end if
  sql="select count(id) from "&data_name&sql_add
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" order by orders,id"
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,1
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum)
  for i=1 to nums
    id=rs("id")
    nname=rs("nname")
    url=rs("url")
%>
<tr align=center>
<td class=tims><%response.write (viewpage-1)*nummer+i%></td>
<td><%
    if rs("sort")="txt" then
      response.write "文字"&tit_fir
    else
      response.write "<img src='"&rs("pic")&"' border=0>"
    end if
%></td>
<td><a href='<%response.write url%>' target=_blank><%response.write joekoe_cms.code_html(nname,1,0)%></a></td>
<td align=left><a href='<%response.write url%>' target=_blank><%response.write joekoe_cms.code_html(url,1,20+tnum)%></a></td>
<td><%response.write pro_edit("?jk_mod="&jk_mod&"&sort="&sort&"&action=edit&id="&id,"编辑该"&tit_fir) &"&nbsp;&nbsp;"& pro_hidden(rs("hidden"),1)%>
&nbsp;<a href='?sort=<%response.write sort%>&jk_mod=<%response.write jk_mod%>&id=<%response.write id%>&action=order&actions=up'><%response.write img_admin("up_2","向上移动此"&tit_fir)%></a>
&nbsp;<a href='?sort=<%response.write sort%>&jk_mod=<%response.write jk_mod%>&id=<%response.write id%>&action=order&actions=down'><%response.write img_admin("down_2","向下移动此"&tit_fir)%></a></td>
<td><input type=checkbox name=sel_id value='<%response.write id%>'></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=tr1>
<td colspan=4>
现有<font class=red><%response.write rssum%></font>个<%response.write tit_fir%>，
页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font>
分页：<%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
</td>
<td colspan=2 align=center>
执行
<select name=sel_type size=1>
<option value='审核'>显示</option>
<option value='待审核'>审核</option>
<option value='删除'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);">
</td>
</tr>
</form>
<%
end sub
'****************************************************
' 阳光情缘 2006V3.0      Power by sdsun.com.cn
' Email: 27072320@qq.com  , sdsun163@163.com
' Web: http://www.sdsun.com.cn
' Copyright (C) 2006 sdsun.com.cn All Rights Reserved.
'****************************************************


%>