<!--#include file="../../../../p_inc/Include_func.asp"-->
<!--#include file="../../../../p_inc/openconn.asp"-->
<!--#include file="../../../../Members/config.asp"-->

<%
IF Not ChkPost() Then
	'response.Redirect G_error_page_1
	'response.End()
End IF
Response.Buffer=True
response.contenttype="text/html;charset=gb2312"
v=request("v")
IF v="get1" Then '首页加载的内容
	Pstr="{""list"":["
	Pstr2=""
	Set Rs=Server.CreateObject(G_RS)
	sql="Select top 6 * From qingtiandy_notebook Where Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And note_important=0 Order By note_date Desc,Id Desc"
	rs.open sql,conn,1,1
	Do While Not rs.Eof
		id=Rs("id")
		note_title=Str4Js(Rs("note_title"))
		note_content=Str4Js(Rs("note_content"))
		note_icon=Rs("note_icon")	
		note_background=Rs("note_background")
		note_important=Rs("note_important")
		uid=Rs("uid")
		note_date=DateDiff("s","1970-01-01 08:00:00",Rs("note_date"))
		Pstr2=Pstr2&"{""nid"":"""&id&""",""title"":"""&note_title&""",""content"":"""&note_content&""",""icon"":"""&note_icon&""",""background"":"""&note_background&""",""important"":"""&note_important&""",""time"":"""&note_date&"""},"		
		rs.MoveNext
	Loop
	IF Pstr2<>"" Then
		Pstr2=mid(Pstr2,1,len(Pstr2)-1)
		Pstr=Pstr&Pstr2
	End IF	
	
	Pstr=Pstr&"],""impor"":["
	Pstr2=""
	Set Rs=Server.CreateObject(G_RS)
	sql="Select top 6 * From qingtiandy_notebook Where Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And note_important=1 Order By note_date Desc,Id Desc"
	rs.open sql,conn,1,1
	Do While Not rs.Eof
		id=Rs("id")
		note_title=Str4Js(Rs("note_title"))
		note_content=Str4Js(Rs("note_content"))
		note_icon=Rs("note_icon")	
		note_background=Rs("note_background")
		note_important=Rs("note_important")
		uid=Rs("uid")
		note_date=DateDiff("s","1970-01-01 08:00:00",Rs("note_date"))
		Pstr2=Pstr2&"{""nid"":"""&id&""",""title"":"""&note_title&""",""content"":"""&note_content&""",""icon"":"""&note_icon&""",""background"":"""&note_background&""",""important"":"""&note_important&""",""time"":"""&note_date&"""},"		
		rs.MoveNext
	Loop
	IF Pstr2<>"" Then
		Pstr2=mid(Pstr2,1,len(Pstr2)-1)
		Pstr=Pstr&Pstr2
	End IF		
	
	Pstr=Pstr&"],""opt"":{""view"":""summ"",""pagesize"":12,""order"":""createtime"",""hmsj"":0,""autosave"":0,""_email"":"""",""_emailLimit"":{""date"":19700116,""note"":0,""attach"":0}}}"
	Response.Write Pstr
	'Response.Write "{""list"":[{""nid"":""62321"",""title"":""dwdwdwddwdwdwdwdwdw"",""time"":""1306461555""},{""nid"":""62319"",""title"":""11111111111111111"",""time"":""1306461210""},{""nid"":""62298"",""title"":""dwdwdw"",""time"":""1306458338""},{""nid"":""62219"",""title"":""11111\n2323\n434\n545455\n<script><\/script>"",""time"":""1306421544""},{""nid"":""62215"",""title"":""fef"",""time"":""1306421248""}],""impor"":[{""nid"":""62319"",""title"":""11111111111111111"",""time"":""1306461210""}],""opt"":{""view"":""summ"",""pagesize"":12,""order"":""createtime"",""hmsj"":0,""autosave"":1,""_email"":"""",""_emailLimit"":{""date"":19700116,""note"":0,""attach"":0}}}"
ElseIF v="fm1" Then '添加成功，返回的内容
	'title=111&content=222&important=1&background=yl_green&icon=jsicon08&nid=0
	ouid=Bint(Request.Cookies(G_u_Cookies)("soojs_id"))
	IF ouid=0 Then
		Response.Write "error"
		Response.End()
	End IF
	stitle=Trim(Request("title"))
	scontent=Trim(Request("content"))
	IF stitle="" Then
		stitle=left(checkStr(scontent),50)
	Else
		stitle=left(checkStr(stitle),50)
	End IF
	simportant=Bint(Request("important"))
	sbackground=Trim(Request("background"))
	sicon=Trim(Request("icon"))
	snid=Bint(Request("nid"))
	Set oRs=Server.CreateObject(G_RS)
	IF snid=0 Then
		sql="Select * From qingtiandy_notebook Where 1<>1"
	Else
		sql="Select * From qingtiandy_notebook Where id="&snid&" And Uid="&Request.Cookies(G_u_Cookies)("soojs_id")
	End IF
	oRs.open sql,Conn,1,3
	IF oRs.Eof Then
		oRs.AddNew()
		oRs("note_date")=FormatDate(now(),55)
	End IF
	oRs("note_title")=stitle
	oRs("note_content")=scontent
	oRs("note_icon")=sicon
	oRs("note_background")=sbackground
	oRs("note_important")=simportant
	oRs("uid")=ouid
	oRs.Update()
	pid=oRs("id")
	oRs.close()
	Response.Write "{""createtime"":"""&DateDiff("s","1970-01-01 08:00:00",now())&""",""content"":"""&Str4Js(scontent)&""",""title"":"""&Str4Js(stitle)&""",""prev"":""0"",""next"":""1"",""nid"":"""&pid&""",""name"":""t2""}"
ElseIF v="fm2" Then '返回某一条记录的内容
	snid=Bint(Request("nid"))	
	Set oRs=Server.CreateObject(G_RS)
	IF snid=0 Then
		Response.End()
	Else
		sql="Select * From qingtiandy_notebook Where id="&snid&" And Uid="&Request.Cookies(G_u_Cookies)("soojs_id")
	End IF	
	oRs.open sql,Conn,1,1
	IF Not oRs.Eof Then
		stitle=oRs("note_title")
		scontent=oRs("note_content")
		sicon=oRs("note_icon")
		sbackground=oRs("note_background")
		simportant=oRs("note_important")
		ouid=oRs("uid")
		Set oRs1=Conn.Execute("Select Top 1 * From qingtiandy_notebook Where id>"&snid&" And Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" Order By id asc")
		IF Not oRs1.Eof Then
			sprev=oRs1("id")
		Else
			sprev=""
		End IF
		Set oRs1=Conn.Execute("Select Top 1 * From qingtiandy_notebook Where id<"&snid&" And Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" Order By id desc")
		IF Not oRs1.Eof Then
			snext=oRs1("id")
		Else
			snext=""
		End IF		
	End IF
	Response.Write "{""createtime"":"""&DateDiff("s","1970-01-01 08:00:00",now())&""",""content"":"""&Str4Js(scontent)&""",""title"":"""&Str4Js(stitle)&""",""prev"":"""&sprev&""",""next"":"""&snext&""",""nid"":"""&snid&""",""name"":""t2"",""icon"":"""&sicon&""",""background"":"""&sbackground&""",""important"":"""&simportant&"""}"
ElseiF v="del" Then '删除某一条记录	
	nids=FormatNumSerial(Request("nids"))
	Conn.Execute("Delete From qingtiandy_notebook Where Id in("&nids&")")
	Response.Write 1
ElseiF v="list" Then '加载全部记事本的内容
	's:开始记录比如 0 12 24 
	Pgsize=12
	page=Request("s")
	page=StayNub(page)
	IF page="" Then
		page=0
		pagen=1
	Else
		page=Clng(page)
		pagen=page/12+1
	ENd IF
	Set Rs=Server.CreateObject(G_RS)
	sql="Select * From qingtiandy_notebook Where Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" Order By note_date Desc,Id Desc"
	rs.open sql,conn,1,1
	mtotal=Rs.RecordCount
	Rs.pagesize=Pgsize
	
	If Not Rs.Eof then	
		Pstr=""
		Pstr2=""
		Pstr=Pstr&"{""total"":"""&mtotal&""",""list"":["
		Rs.AbsolutePage = pagen
		NN=0
		Do While Not Rs.Eof and NN<Pgsize
			id=Rs("id")
			note_title=Str4Js(Rs("note_title"))
			note_content=Str4Js(Rs("note_content"))
			note_icon=Rs("note_icon")	
			note_background=Rs("note_background")
			note_important=Rs("note_important")
			uid=Rs("uid")
			note_date=DateDiff("s","1970-01-01 08:00:00",Rs("note_date"))
			Pstr2=Pstr2&"{""nid"":"""&id&""",""title"":"""&note_title&""",""content"":"""&note_content&""",""icon"":"""&note_icon&""",""background"":"""&note_background&""",""important"":"""&note_important&""",""time"":"""&note_date&"""},"
			Rs.MoveNext
		Loop
		IF Pstr2<>"" Then
			Pstr2=mid(Pstr2,1,len(Pstr2)-1)
			Pstr=Pstr&Pstr2
		End IF
		Pstr=Pstr&"]}"
	Else
		Pstr=Pstr&"{""total"":""0"",""list"":["
		Pstr=Pstr&"]}"
	End IF
	Response.Write Pstr
	'Response.Write "{""total"":""16"",""list"":[{""nid"":""62363"",""title"":""222222"",""content"":""222222"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306468274""},{""nid"":""62358"",""title"":""qqqqqqqqqq"",""content"":""qqqqqqqqqq"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306467410""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""},{""nid"":""62215"",""title"":""fef"",""content"":""fef"",""icon"":"""",""background"":"""",""important"":""0"",""time"":""1306421248""}]}"
End IF
%>
