<!-- #include file="config.asp" -->
<!-- #include file="jk_encrypt.asp" -->
<%

dim web_width,user_ip,user_sys,cookies_true,head_js,skin_dir,iframe,page_load,login_is_abate,is_refur_true
web_width=""
user_ip=joekoe_cms.ip_sys(0)
user_sys=joekoe_cms.code_form(left(joekoe_cms.ip_sys(1),250))
skin_dir=joekoe_cms.web_dir_skin
iframe=false
page_load=false
is_refur_true=true
cookies_true=true
if trim(request.cookies(joekoe_cms.web_cookies)("cookies_true"))<>"yes" then
  response.cookies(joekoe_cms.web_cookies).path=joekoe_cms.web_dir
  response.cookies(joekoe_cms.web_cookies)("cookies_true")="yes"
  cookies_true=false
end if

call web_is_open()
call web_ip_shield()

dim dim_menu
dim_menu=split(web_dim(20),"|")

sub web_head_tit()
  tit=joekoe_cms.code_form(tit)
  tit_fir=joekoe_cms.code_form(tit_fir)
  joekoe_cms.web_tit=tit
  call skin_load()
  call joekoe_cms.web_title()
  if iframe then
    response.write vbcrlf&"<iframe width=0 height=0 src=''id=hiddenframe name=hiddenframe></iframe>"
  end if
end sub

sub web_ads(atype,avar,ak)
  if avar="" then
    response.write vbcrlf&"web_ads("&atype&",'"&avar&"');"
  else
    call web_js_type(2)
    response.write vbcrlf&"<script language=javascript src='ads/ads_"&avar&".js'></script>"
    call web_js_type(1)
  end if
  if ak=1 then response.write vbcrlf&"document.write (ukong);"
end sub

sub day_initialize(today_tim)
  dim price_head
  price_head="#"
  call joekoe_cms.exec("update configs set num_new=0,today_tim='"&today_tim&"'",0)
  application.lock
  application(joekoe_cms.web_cookies&"_configs_new_num")=0
  application(joekoe_cms.web_cookies&"_configs_today_tim")=today_tim
  application.unlock
  call joekoe_cms.exec("update bbs_forum set forum_new_num=0",0)
  sql="update user_data set abate=1 where estate=1 and otim<"&price_head&today_tim&price_head
  call joekoe_cms.exec(sql,0)
end sub

sub web_head(var1,var2,var3,var4,var5)
  if page_load then
    call format_redirect("page_load.asp")
  end if
  call web_head_tit()
  
  dim temp1,login_msg,online_num,ttt,num_topic,num_data,num_reg,new_username,counter,max_online,max_tim,start_tim,new_num,today_tim,stamp_num
  num_topic=0
  num_data=0
  num_reg=0
  new_username=""
  counter=0
  max_online=0
  max_tim=joekoe_cms.now_time
  start_tim=joekoe_cms.time_type(joekoe_cms.now_time,5)
  login_msg=0
  online_num=0
  new_num=0
  today_tim=joekoe_cms.time_type(joekoe_cms.now_time,4)
  tit=joekoe_cms.code_form(tit)
  stamp_num=format_mid_num(1)
  
  '-------------------------------------------------------------------------
  if not application(joekoe_cms.web_cookies&"_configs_true") then
    sql="select top 1 id,num_topic,num_data,num_reg,new_username,num_news,num_article,num_down,num_product,counter,max_online,max_tim,start_tim,num_new,today_tim from configs"
    set rs=joekoe_cms.exec(sql,1)
    if rs.eof then
      rs.close
      call joekoe_cms.exec("insert into configs(id,num_topic,num_data,num_reg,new_username,num_news,num_article,num_down,num_product,counter,max_online,max_tim,start_tim,num_new,today_tim) values(1,"&num_topic&","&num_data&","&num_reg&",'"&new_username&"',0,0,0,0,"&counter&","&max_online&",'"&max_tim&"','"&start_tim&"',0,'"&today_tim&"')",0)
      set rs=joekoe_cms.exec(sql,1)
    end if
    application.lock
    application(joekoe_cms.web_cookies&"_configs_true")=true
    application(joekoe_cms.web_cookies&"_configs_num_topic")=rs(1)
    application(joekoe_cms.web_cookies&"_configs_num_data")=rs(2)
    application(joekoe_cms.web_cookies&"_configs_num_reg")=rs(3)
    application(joekoe_cms.web_cookies&"_configs_new_username")=rs(4)
    application(joekoe_cms.web_cookies&"_configs_num_news")=rs(5)
    application(joekoe_cms.web_cookies&"_configs_num_article")=rs(6)
    application(joekoe_cms.web_cookies&"_configs_num_down")=rs(7)
    application(joekoe_cms.web_cookies&"_configs_num_product")=rs(8)
    application(joekoe_cms.web_cookies&"_configs_counter")=rs(9)
    application(joekoe_cms.web_cookies&"_configs_max_online")=rs(10)
    application(joekoe_cms.web_cookies&"_configs_max_tim")=rs(11)
    application(joekoe_cms.web_cookies&"_configs_start_tim")=rs(12)
    application(joekoe_cms.web_cookies&"_configs_new_num")=rs(13)
    application(joekoe_cms.web_cookies&"_configs_today_tim")=rs(14)
    application.unlock
    rs.close
  end if
  num_topic=application(joekoe_cms.web_cookies&"_configs_num_topic")
  num_data=application(joekoe_cms.web_cookies&"_configs_num_data")
  num_reg=application(joekoe_cms.web_cookies&"_configs_num_reg")
  new_username=application(joekoe_cms.web_cookies&"_configs_new_username")
  counter=application(joekoe_cms.web_cookies&"_configs_counter")
  max_online=application(joekoe_cms.web_cookies&"_configs_max_online")
  max_tim=application(joekoe_cms.web_cookies&"_configs_max_tim")
  start_tim=application(joekoe_cms.web_cookies&"_configs_start_tim")
  new_num=application(joekoe_cms.web_cookies&"_configs_new_num")
  
  if cstr(joekoe_cms.time_type(application(joekoe_cms.web_cookies&"_configs_today_tim"),4))<>cstr(joekoe_cms.time_type(today_tim,4)) then
    call day_initialize(today_tim)
    counter=counter+1
    new_num=0
  end if
  
  if cookies_true then
    call joekoe_cms.exec("delete from user_login where datediff('s',l_tim_end,'"&joekoe_cms.now_time&"')>"&dim_num(2)&"*60",0)
    login_password=jk_decrypt(login_password)
    if symbol_name(login_username)=false or symbol_ok(login_password)=false then
      call cookies_clear(0)
    else
      sql="select top 1 id,username,power,popedom,emoney,integral,last_tim,face,face_w,face_h,estate,otim from user_data where hidden=1 and abate=0 and username='"&login_username&"' and password='"&login_password&"'"
      call joekoe_cms.exec("",-1)
      rs.open sql,conn,1,3
      if rs.eof then
        call cookies_clear(0)
      else
        login_id=rs(0)
        login_username=rs(1)
        login_mode=rs(2)
        login_popedom=rs(3)
        login_emoney=rs(4)
        login_integral=rs(5)
        login_faces=rs(7)&"|"&rs(8)&"|"&rs(9)
        login_is_abate=rs(10)
        if int(login_is_abate)>0 then
          if int(dateDiff("d",today_tim,rs(11)))<1 then login_is_abate=0
        end if
        rs(6)=joekoe_cms.now_time
        rs.update
        login_modep=format_power(login_mode,2)
        response.cookies(joekoe_cms.web_cookies)("login_id")=login_id
        response.cookies(joekoe_cms.web_cookies)("login_password")=jk_encrypt(login_password)
      end if
      rs.close
    end if
    if is_refur_true=true then call time_load()

    '完整型,用户和游客都进行识别,这里识别游客
    if int(stamp_num)>1 and login_mode="" and cookies_true=true then
      ttt=trim(request.cookies(joekoe_cms.web_cookies)("guest_name"))
      ttt=joekoe_cms.code_html(ttt,1,0)
      if ttt="" then
        ttt="游客"&Session.SessionID
        response.cookies(joekoe_cms.web_cookies)("guest_name")=ttt
      end if
      sql="select top 1 l_id from user_login where l_username='"&ttt&"'"
      set rs=joekoe_cms.exec(sql,1)
      if rs.eof then
        call joekoe_cms.exec("insert into user_login(l_username,l_type,l_where,l_tim_login,l_tim_end,l_ip,l_sys) values('"&ttt&"',1,'"&left(tit,50)&"','"&joekoe_cms.now_time&"','"&joekoe_cms.now_time&"','"&user_ip&"','"&user_sys&"')",0)
        counter=counter+1
        call joekoe_cms.exec("update configs set counter=counter+1",0)
      else
        call joekoe_cms.exec("update user_login set l_where='"&left(tit,50)&"',l_tim_end='"&joekoe_cms.now_time&"' where l_id="&rs("l_id"),0)
        if format_mid_num(9)=1 then
          counter=counter+1
          call joekoe_cms.exec("update configs set counter=counter+1",0)
        end if
      end if
      rs.close
    end if
    
    if int(stamp_num)>0 and login_mode<>"" and cookies_true=true then
      sql="select count(id) from user_mail where accept_u='"&login_username&"' and types=1 and isread=0"
      set rs=joekoe_cms.exec(sql,1)
      login_msg=rs(0)
      rs.close
      sql="select top 1 l_id from user_login where l_username='"&login_username&"'"
      set rs=joekoe_cms.exec(sql,1)
      if rs.eof then
        call joekoe_cms.exec("insert into user_login(l_username,l_type,l_where,l_tim_login,l_tim_end,l_ip,l_sys) values('"&login_username&"',0,'"&left(tit,50)&"','"&joekoe_cms.now_time&"','"&joekoe_cms.now_time&"','"&user_ip&"','"&user_sys&"')",0)
        counter=counter+1
        call joekoe_cms.exec("update configs set counter=counter+1",0)
      else
        if format_mid_num(9)=1 then
          counter=counter+1
          call joekoe_cms.exec("update configs set counter=counter+1",0)
        end if      
        call joekoe_cms.exec("update user_login set l_where='"&left(tit,50)&"',l_tim_end='"&joekoe_cms.now_time&"' where l_username='"&login_username&"'",0)
      end if
      rs.close
    end if
  end if
  
  sql="select count(l_id) from user_login"
  set rs=joekoe_cms.exec(sql,1)
  online_num=rs(0)
  rs.close
  if int(online_num)>application(joekoe_cms.web_cookies&"_configs_max_online") then
    application.lock
    application(joekoe_cms.web_cookies&"_configs_max_online")=online_num
    application(joekoe_cms.web_cookies&"_configs_max_tim")=joekoe_cms.now_time
    application.unlock
    call joekoe_cms.exec("update configs set max_online="&online_num&",max_tim='"&joekoe_cms.now_time&"'",0)
  end if
  if int(counter)>application(joekoe_cms.web_cookies&"_configs_counter") then
    application.lock
    application(joekoe_cms.web_cookies&"_configs_counter")=counter
    application.unlock
    call joekoe_cms.exec("update configs set counter="&counter,0)
  end if
  
  if web_dim(7)<>joekoe_cms.web_skin then  temp1=temp1&vbcrlf&"web_skin="""&joekoe_cms.web_skin&""";"
  if web_width<>"" then temp1=temp1&vbcrlf&"web_wid="""&web_width&""";"
  response.write joekoe_cms.js_type("",1) & _
		 vbcrlf&"var lmenu_true=true;" & _
		 vbcrlf&"var stamp_num="&stamp_num&";" & _
		 vbcrlf&"var now_time='"&joekoe_cms.now_time&"';" & _
		 vbcrlf&"var login_id='"&login_id&"';" & _
		 vbcrlf&"var login_username='"&login_username&"';" & _
		 vbcrlf&"var login_mode='"&login_mode&"';" & _
		 vbcrlf&"var user_ip='"&user_ip&"';" & _
		 vbcrlf&"var user_sys='"&user_sys&"';" & _
		 vbcrlf&"var m_channel='"&index_url&"';" & _
		 vbcrlf&"var m_nsort='';" & _
		 vbcrlf&"var action='"&action&"';" & _
		 vbcrlf&"var tit='"&tit&"';" & _
		 vbcrlf&"var tit_fir='"&tit_fir&"';" & _
		 vbcrlf&"var web_counter='"&counter&"';" & _
		 vbcrlf&"var web_max_online='"&max_online&"';" & _
		 vbcrlf&"var web_max_tim='"&max_tim&"';" & _
		 vbcrlf&"var web_start_tim='"&start_tim&"';" & _
		 vbcrlf&"var web_new_num='"&new_num&"';" & _
		 vbcrlf&"var web_num_topic='"&num_topic&"';" & _
		 vbcrlf&"var web_num_data='"&num_data&"';" & _
		 vbcrlf&"var web_num_reg='"&num_reg&"';" & _
		 vbcrlf&"var web_new_username='"&new_username&"';" & _
		 vbcrlf&"var web_online_num="&online_num&";" & _
		 vbcrlf&"var num_rs=0;" & _
		 vbcrlf&"var pro_edition='';" & _
		 vbcrlf&"var exec_tim='';" & _
		 vbcrlf&"var login_message="&login_msg&";" & _
		 vbcrlf&"var time_now=new Date();" & _
		 vbcrlf&"var time_start=time_now.getTime();" & _
		 head_js & temp1 & _
		 joekoe_cms.js_type("",2)
  
  if page_power<>"" and instr("."&page_power&".","."&login_modep&".")<1 then call web_error("power")
  select case var1
  case 1
    if int(format_mid_num(8))=1 and login_mode="" then call my_login()
  case 2
    if login_mode="" then call my_login()
  end select
  if var2=1 and login_mode<>"" then
    if popedom_p(41)=1 then call web_error("locked")
  end if
  if var3=5 then exit sub
  call web_js(var3)
  if var3=4 then exit sub
  response.write web_left(var3)
end sub

function popedom_p(popedom_n)
  if cint(popedom_n)>len(login_popedom) or len(login_popedom)<>50 then
    popedom_p=0
    exit function
  end if
  popedom_p=int(mid(login_popedom,popedom_n,1))
end function

function web_left(lt)
  web_left=vbcrlf&"web_left("&lt&");"
end function

sub web_center(ct)
  response.write vbcrlf&"web_center("&ct&");"
end sub

function web_right()
  web_right=vbcrlf&"web_right();"
end function

sub web_end(var1,var2)
  response.write vbcrlf&"num_rs="&joekoe_cms.num_rs&";" & _
  		 vbcrlf&"pro_edition='"&joekoe_cms.pro_edition&"';" & _
		 vbcrlf&"exec_tim='"&FormatNumber((timer()-joekoe_cms.timer_start)*1000,3)&"';"
  if var2=0 then response.write web_right()&vbcrlf&"web_end("&var1&");"
  response.write joekoe_cms.js_type("",2)
  if var2=0 then call joekoe_cms.js_type("style/joekoe_lmenu.js",4)
  call web_clears(1)
end sub

sub web_branch(jst)
  response.write vbcrlf&"web_branch();"
  response.buffer
end sub

sub web_js_type(jtt)
  if joekoe_cms.js_mod then exit sub
  response.write joekoe_cms.js_type("",jtt)
end sub

sub web_js_msg(msg_type,msg_var,msg_url)
  call cookies_load()
  if msg_type=0 then
    response.write "alert("""&msg_var&""");location.href="""&msg_url&""";"
    exit sub
  end if
  response.write joekoe_cms.js_type("alert("""&msg_var&""");location.href="""&msg_url&""";",3)
end sub

sub cookies_load()
  response.cookies(joekoe_cms.web_cookies)("time_load")=dateadd("s",-5,joekoe_cms.now_time)
end sub

sub cookies_clear(tl)
  if tl=1 then call cookies_load()
  response.cookies(joekoe_cms.web_cookies)("login_username")=""
  response.cookies(joekoe_cms.web_cookies)("login_password")=""
  response.cookies(joekoe_cms.web_cookies)("login_id")=""
  login_mode=""
  login_username=""
  login_password=""
end sub

sub my_login()
  if login_mode<>"" then exit sub
  dim temp1
  temp1=trim(request.serverVariables("url"))&"?"&trim(request.serverVariables("QUERY_STRING"))
  temp1=server.urlencode(temp1)
  response.cookies(joekoe_cms.web_cookies)("time_load")=DateAdd("s",-5,joekoe_cms.now_time)
  response.cookies(joekoe_cms.web_cookies)("login_username")=""
  response.cookies(joekoe_cms.web_cookies)("login_password")=""
  response.cookies(joekoe_cms.web_cookies)("login_id")=""
  response.cookies(joekoe_cms.web_cookies)("iscookies")=""
  call format_redirect("login.asp?old_url="&temp1)
end sub

function format_menu(mvar)
  dim i
  format_menu=""
  for i=0 to ubound(dim_menu)
    if mvar=left(dim_menu(i),instr(dim_menu(i),":")-1) then
      format_menu=right(dim_menu(i),len(dim_menu(i))-instr(dim_menu(i),":"))
      exit for
    end if
  next
end function

sub skin_load()
  dim n_skin,n_wid
  n_skin=trim(request.cookies(joekoe_cms.web_cookies)("skin_var"))
  n_wid=trim(request.cookies(joekoe_cms.web_cookies)("skin_wid"))
  if n_skin<>"" and n_wid<>"" then
    joekoe_cms.web_skin=n_skin
    skin_dir=joekoe_cms.web_dir&"skin/"&n_skin&"/"
    joekoe_cms.web_dir_skin=skin_dir
    if web_width="" then web_width=n_wid
  end if
end sub

sub format_redirect(r_url)
  call web_clears(0)
  response.clear
  response.redirect r_url
  response.end
end sub

sub web_clears(c_end)
  erase dim_menu
  call web_clear(c_end)
end sub

sub web_js(var3)
  call joekoe_cms.js_type("style/functions.js",4)
  call joekoe_cms.js_type("style/mouse_on_title.js",4)
  'call joekoe_cms.js_type("style/joekoe_top_menu.js",4)
  call joekoe_cms.js_type("style/joekoe_menu.js",4)
  call joekoe_cms.js_type("style/joekoe_common.js",4)
  'call joekoe_cms.js_type("skin/"&joekoe_cms.web_skin&"/joekoe_common.js",4)
  response.write joekoe_cms.js_type("",1)
  response.write vbcrlf&"web_head("&var3&",'"&index_url&"');"
end sub

sub web_is_open()
  if web_dim(0)=0 then
    response.clear
    call web_head_tit()
    call joekoe_cms.js_type("style/no_open.js",4)
    call web_clear(1)
  end if
end sub

sub web_ip_shield()
  dim tmp
  tmp=true
  if web_dim(22)="" or user_ip="" then exit sub
  dim sdim,snum
  sdim=split(web_dim(22),"|")
  snum=ubound(sdim)
  for i=0 to snum
    if instr("$"&user_ip&".","$"&sdim(i)&".")>0 then
      erase sdim
      response.clear
      call web_head_tit()
      call joekoe_cms.js_type("style/no_ip.js",4)
      call web_clear(1)
    end if
  next
  erase sdim
end sub

sub web_error(etype)
  response.clear
  response.cookies(joekoe_cms.web_cookies)("time_load")=DateAdd("s",-5,joekoe_cms.now_time)
  response.cookies(joekoe_cms.web_cookies)("old_url")=request.servervariables("http_referer")
  response.cookies(joekoe_cms.web_cookies)("error_action")=etype
  call format_redirect("error.asp")
end sub

sub time_load()
  dim tim_s,var_s
  tim_s=int(dim_num(3))
  if int(tim_s)<1 then exit sub
  if login_mode=format_power2(1,1) then exit sub
  var_s=request.cookies(joekoe_cms.web_cookies)("time_load")
  if isdate(var_s) then
    if int(datediff("s",var_s,joekoe_cms.now_time))<=int(tim_s) then
      call web_error("time_load")
      exit sub
    end if
  end if
  response.cookies(joekoe_cms.web_cookies)("time_load")=joekoe_cms.now_time
end sub

sub time_lock()
  dim tt,tim1,tim2,nh,tl:tl=0
  tt=web_dim(10)
  if len(tt)<1 then tt="0:0"
  tim1=left(tt,instr(1,tt,":")-1)
  tim2=right(tt,len(tt)-instr(1,tt,":"))
  if not(isnumeric(tim1)) or not(isnumeric(tim2)) then exit sub
  tim1=int(tim1):tim2=int(tim2)
  if tim1=tim2 then exit sub
  if tim2=0 then tim2=24
  tim2=tim2-1
  nh=int(hour(joekoe_cms.now_time))
  if tim1>tim2 then
    if (nh>=tim1 and nh<=24) or (nh>=0 and nh<=tim2) then tl=1
  else
    if nh>=tim1 and nh<=tim2 then tl=1
  end if
  if tl=1 then
    call web_error("time_lock")
  end if
end sub

function frm_chk()
  frm_chk=false
  if trim(request.form("chk"))="yes" then
    frm_chk=joekoe_cms.post_chk()
  end if
end function

function post_tim()
  dim pt_var,pt_num
  post_tim=true
  pt_var=session("post_tim")
  if isdate(pt_var) then
    pt_num=datediff("s",pt_var,joekoe_cms.now_time)
    if int(dim_num(28))>0 and int(pt_num)<=int(dim_num(28)) then
      post_tim=false
    end if
  end if
  session("post_tim")=joekoe_cms.now_time
end function
%>