<!-- #include file="common_video.asp" -->
<%
dim video_skin
set video_skin=new class_video
video_skin.CacheName=joekoe_cms.web_cookies&"_video"
video_skin.ReloadTime=14400

class class_video
	Public Reloadtime,CacheName,Main_PicUrl,Main_Html
	Private LocalCacheName,Cache_Data,PutHtml

	'默认全局变量
	private Sub Class_Initialize()
		Reloadtime=14400
		'取地址为缓存名称、COOKIES名
		CacheName=Replace(Replace(Replace(Server.MapPath("index.asp"),"index.asp",""),":",""),"\","")
	End Sub
	Public Property Let Name(ByVal vNewValue)
		LocalCacheName=LCase(vNewValue)
	End Property
	Public Property Let Value(ByVal vNewValue)
		If LocalCacheName<>"" Then
			ReDim Cache_Data(2)
			Cache_Data(0)=vNewValue
			Cache_Data(1)=Now()
			Application.Lock
			Application(CacheName & "_" & LocalCacheName) = Cache_Data
			Application.unLock
		Else
			Err.Raise vbObjectError + 1, "CacheServer", " Please Change The CacheName."
		End If
	End Property
	Public Property Get Value()
		If LocalCacheName<>"" Then
			Cache_Data=Application(CacheName & "_" & LocalCacheName)
			If IsArray(Cache_Data) Then
				Value=Cache_Data(0)
			Else
				Err.Raise vbObjectError + 1, "CacheServer", " The Cache_Data("&LocalCacheName&") Is Empty."
			End If
		Else
			Err.Raise vbObjectError + 1, "CacheServer", " Please Change The CacheName."
		End If
	End Property
	'------------缓存操作-------------
	'判断缓存是否存在、过期
	Public Function cache_chk()
		cache_chk=True
		Cache_Data=Application(CacheName & "_" & LocalCacheName)
		If Not IsArray(Cache_Data) Then Exit Function
		If Not IsDate(Cache_Data(1)) Then Exit Function
		If DateDiff("s",CDate(Cache_Data(1)),Now()) < (60*Reloadtime) Then cache_chk=False
	End Function
	'写缓存
	Public Sub cache_set(MyCaheName,CaheStr)
		Application.Lock
		Application(CacheName&"_"&MyCaheName)=CaheStr
		Application.unLock
	End Sub
	'取缓存
	Public Function cache_get(MyCaheName)
		cache_get=Application(CacheName&"_"&MyCaheName)
	End Function
	'删除缓存
	Public Sub cache_del(MyCaheName)
		Application.Lock
		Application.Contents.Remove(CacheName&"_"&MyCaheName)
		Application.unLock
	End Sub
	Public Sub video_skin_del()
	  cache_del("picurl")
	  cache_del("style")
	  cache_del("nsort")
	  cache_del("scroll")
	  cache_del("counter")
	End Sub
	'-----------取统计数据---------
	Public Sub CounterToCache()
		sql="select count(id) from [video]"
		set rs=joekoe_cms.exec(sql,1)
		if not rs.eof then value=rs(0)
		rs.close
	End Sub
	'-----------取分类数据---------
	Public Sub NsortToCache()
		sql="select c_id,c_name from jk_class where nsort='video' order by c_order,c_id"
		set rs=joekoe_cms.exec(sql,1)
		if not rs.eof then value=rs.getrows()
		rs.close
  	End Sub
	'-----------取滚动图片数据---------
	Public Sub ScrollToCache(Snum)
		dim TmpStr
		pic_w=96
		pic_h=72
		sql="select top "&Snum&" id,name,pic from video where pic<>'' order by id desc"
		call joekoe_cms.exec(sql,-1)
		rs.open sql,conn,1,3
		do while not rs.eof
			TmpStr=TmpStr&vbcrlf&"    <td><a href='video_view.asp?id="&rs(0)&"' title='影片名称："&joekoe_cms.code_html(rs(1),1,0)&"' target=_blank>"&pic_url(rs(2),1)&"</a></td>"
			rs.movenext
		loop
		rs.close
		value=TmpStr
  	End Sub
	'-----------取模板数据---------
	Private Sub ModToCache(mod_Fields)
		sql="select top 1 "&mod_Fields&" from [video_style] where isdef=true"
		set rs=joekoe_cms.exec(sql,1)
		if not rs.eof then value=rs(0)
		rs.close
	End Sub
	'-----------取全局模板-----------
	Public Sub Mod_Load()
		dim main_style
		Name="picurl"
		if cache_chk() then ModToCache ("picurl")
		Main_PicUrl=value
		Name="style"
		If cache_chk() Then ModToCache ("style")
		main_style=split(value,"@@@")
		Main_Html=Split(main_style(0),"|||")
	End Sub

	'----模板操作，打印页面 或 赋值
	Public Sub HtmlNums(Mnum)
		PutHtml=Main_Html(Mnum)
	End Sub
	Public Sub HtmlRcod(Mod_Str,View_Str)
		PutHtml=Replace(PutHtml,"{$"&Mod_Str&"}",View_Str)
	End Sub
	Public Sub HtmlView(Knum)
		PutHtml=Replace(PutHtml,"{$picurl}",Main_PicUrl)
		response.write VbCrlf&PutHtml
		If Knum=1 Then response.write vbcrlf & ukong
	End Sub
	Public Function HtmlGets(Knum)
		PutHtml=Replace(PutHtml,"{$picurl}",Main_PicUrl)
		HtmlGets=VbCrlf&PutHtml
		If Knum=1 Then HtmlGets=HtmlGets & vbcrlf & ukong
	End Function
	'-------常规操作----------
	Public Function code_str(strers)
    	dim strer
    	strer=strers
    	if strers="" then
    		code_str=""
    		exit function
    	end if
		strer=replace(strer,"'","''")
		code_str = strer
	End Function

	Public Function video_free()
		video_free=true
		if isfree then exit function
		if buy_true then exit function
		if free_ip then exit function
		if free_mode then exit function
		if free_username then exit function
		video_free=false
	End Function

	Public Function chk_user_power(ps,vs)
		if ps<>"" and instr("."&ps&".","."&login_modep&".")<1 then
			call video_error("nopower")
		end if
	End Function

	Public Function free_ip()
		dim ipdim,ipnum
		free_ip=false
		if video_dim(6)="" and isnull(video_dim(6)) then exit function
		ipdim=split(video_dim(6),"|")
		ipnum=ubound(ipdim)
		for i=0 to ipnum
			if instr(user_ip,ipdim(i))<>0 then
				free_ip=true
				erase ipdim
				exit function
			end if
		next
		erase ipdim
	End Function

	Public Function free_username()
		free_username=false
		if login_username="" and login_mode="" then exit function
		if video_dim(7)<>"" and not isnull(video_dim(7)) then
			if instr("|"&video_dim(7)&"|","|"&login_username&"|")<>0 then free_username=true
		end if
	End Function

	Public Function free_mode()
		free_mode=false
		if video_dim(4)<>"" and not isnull(video_dim(4)) then
			if instr("."&video_dim(4)&".","."&login_modep&".")<>0 then free_mode=true
		end if
	End Function

	Public Function buy_true()
		dim buytim,buytype
		sql="select top 1 tim,freetype from video_free where username='"&login_username&"' or userip='"&user_ip&"'"
		set rs=joekoe_cms.exec(sql,1)
		if rs.eof then
			rs.close
			buy_true=false
			exit function
		end if
		buytype=int(rs("freetype"))
		buytim=rs("tim")
		rs.close
		if fc_tim(buytim,buytype) then
			call joekoe_cms.exec("delete from video_free where username='"&login_username&"' or userip='"&user_ip&"'",0)
			response.write joekoe_cms.js_put("alert(""提示：\n\n您的 "&buy_types(buytype)&" 已经到期！请注意重新购买！"");",1)
			buy_true=false
			exit function
		end if
		buy_true=true
	End Function

	Public Function buy_money(bt)
		dim tmpmoney
		select case bt
		case 1
			tmpmoney=int(video_dim(0))
		case 2
			tmpmoney=int(video_dim(1))
		case else
			tmpmoney=int(video_dim(2))
		end select
		buy_money=int(tmpmoney)
	End Function

	Public Function buy_types(bt)
		select case bt
		case 1
			buy_types="月卡"
		case 2
			buy_types="季卡"
		case else
			buy_types="年卡"
		end select
	End Function

	Public Function fc_tim(btim,bt)
		dim tim_dim,tmptim
		fc_tim=false
		select case bt
		case 1
			tmptim=DATEADD("m",1,btim)
		case 2
			tmptim=DATEADD("m",3,btim)
		case else
			tmptim=DATEADD("yyyy",1,btim)
		end select
		tim_dim=DateDiff("s",tmptim,joekoe_cms.now_time)
		if int(tim_dim)>=0 then fc_tim=true
	End Function

	Public Function last_tim(btim,bt)
		select case bt
		case 1
			last_tim=DATEADD("m",1,btim)
		case 2
			last_tim=DATEADD("m",3,btim)
		case else
			last_tim=DATEADD("yyyy",1,btim)
		end select
	End Function

	Public Function video_server(snum,vtype,vurl)
		dim v_dim,v_num,vserver,dnum
		if left(vurl,1)="/" then vurl=right(vurl,len(vurl)-1)
		if snum=0 then
			video_server=vurl
			exit function
		end if
		v_dim=split(video_dim(5),"$")
		v_num=ubound(v_dim)
		dnum=int(snum-1)
		if dnum>v_num then
			erase v_dim
			call video_error("错误的视频服务器地址！")
			exit function
		end if
		vserver=v_dim(dnum)
		erase v_dim
		v_dim=split(vserver,"|")
		if ubound(v_dim)<>2 then
			erase v_dim
			video_server=""
			exit function
		end if
		video_server=v_dim(vtype)
		erase v_dim
		if right(video_server,1)<>"/" then video_server=video_server&"/"
		if left(video_server,1)="/" then video_server=right(video_server,len(video_server)-1)
		video_server=video_server&vurl
	End Function

	Public Function video_selsv(sels)
		dim tmp1
		tmp1="<option value=0>非本地服务器</option>"
		dim servername
		servername=split(video_dim(5),"$")
		for i=1 to ubound(servername)+1
			tmp1=tmp1&"<option value='"&i&"'"
			if sels=i then tmp1=tmp1&" selected"
			tmp1=tmp1&">"&split(servername(i-1),"|")(2)&"</option>"
		next
		erase servername
		video_selsv=tmp1
	End Function

	Public Function sel_type(seled,selstr)
		dim snum,sdim,temp1
		if selstr="" then exit function
		if instr(selstr,"|")<0 then
			sel_type="<option value='"&selstr&"'>"&selstr&"</option>"
			exit function
		end if
		sdim=split(selstr,"|")
		snum=ubound(sdim)
		for i=0 to snum
		  temp1=temp1&"<option value='"&sdim(i)&"'"
		  if (seled=sdim(i)) then temp1=temp1&" selected"
		  temp1=temp1&">"&sdim(i)&"</option>"
		next
		erase sdim
		sel_type=temp1
	End Function
End Class
%>
