login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > ASP > Poll/Stem systemen > ASP Poll(zonder db)

ASP Poll(zonder db)

Auteur: tomk - 19 november 2004 - 15:28 - Gekeurd door: Dennisvb - Hits: 5084 - Aantal punten: 2.50 (9 stemmen)




ik heb een poll gemaakt met asp. Ik zal effe uitleggen hoe je het moet installeren.
Open eerst met dreamweaver of kladblok of een ander programma password.asp. Daar verander je het password wat er staat in je eigen password. ( standaart pass is : password). Creëer een geroepen omslag "poll" in de zelfde omslag van uw Webruimte zoals de pagina (s) waarop u de opiniepeiling wilt verschijnen. Bijvoorbeeld, als u de opiniepeiling op http://www.yourdomain.com wilt verschijnen toen riep de omslag "poll" http://www.mydomain.com/poll. uploaden de elk van ASP pagina's en GIF- beelddossiers in dit zip archief aan de geroepen omslag "poll" zal bedragen. Er is geen db voor nodig. Dus je kan hem bijv gewoon op brinkster draaien. Je moet style effe aanpassen en een afbeelding maken genaamd bar1.gif.
Als er nog vragen zijn moet je mij maar even een pm sturen

Code:
  1. +++Logout.asp+++
  2. <%
  3.  
  4. %><%
  5.  
  6. Response.Buffer = True
  7.  
  8. Session("loggedin") = "false"
  9.  
  10. Response.Redirect "default.asp"
  11.  
  12. %>
  13. +++pollstyle.css+++
  14. body {
  15. background-color : #ffffff;
  16. margin : 0px;
  17. }
  18. .titlebar {
  19. background-color : #5895d0;
  20. padding : 2px;
  21. border-bottom : 1px solid #303090;
  22. }
  23. .navbar {
  24. background-color : #5894d0;
  25. padding : 4px;
  26. border-bottom : 1px solid #303090;
  27. text-align : right;
  28. font-family : verdana, arial, helvetica, monaco, sans-serif;
  29. font-size : 12px;
  30. color : #ffffff;
  31. background-color : 5895d0;
  32. }
  33. a.nav {
  34. color : #ffffff;
  35. background-color : transparent;
  36. }
  37. a.nav:hover {
  38. font-family : verdana, arial, helvetica, monaco, sans-serif;
  39. font-size : 12px;
  40. color : #ffffff;
  41. background-color : transparent;
  42. text-decoration : underline;
  43. }
  44. .normal {
  45. font-family : verdana, arial, sans=serif;
  46. font-size : 12px;
  47. color : #000000;
  48. backgroud-color : transparent;
  49. margin : 8px;
  50. }
  51. .warning {
  52. font-family : verdana, arial, sans=serif;
  53. font-size : 12px;
  54. color : #d03030;
  55. backgroud-color : transparent;
  56. margin : 8px;
  57. }
  58. .header {
  59. font-family : trebuchet ms, verdana, arial, sans=serif;
  60. font-size : 20px;
  61. color : #303090;
  62. backgroud-color : transparent;
  63. margin : 8px;
  64. }
  65. a {
  66. color : #303090;
  67. background-color : transparent;
  68. }
  69. form {
  70. margin : 0px;
  71. }
  72. +++vote.asp+++
  73. <%
  74.  
  75. %><!--#include file ="variables.asp"-->
  76.  
  77. <%
  78. If Request.Cookies("voted") = question Then
  79.  
  80. 'find which is the largest number of votes
  81. Dim mostvotes
  82. mostvotes = 0
  83. For i = 1 to 8
  84. If mostvotes < votes(i) Then
  85. mostvotes = votes(i)
  86. End If
  87. Next
  88.  
  89. 'calculate the total number of votes
  90. Dim totalvotes
  91. totalvotes = 0
  92. For i = 1 to 8
  93. totalvotes = totalvotes + votes(i)
  94. %>
  95.  
  96. <div class="question"><% Response.Write(question) %></div>
  97.  
  98. <%
  99. For i = 1 to 8
  100. If responses(i) <> "" Then
  101. %>
  102.  
  103. <div class="responsetwo"><% Response.Write(responses(i)) %></div>
  104.  
  105. <div class="barline">
  106. <%
  107. If votes(i) <> 0 Then
  108. %>
  109. <img src="poll/bar1.gif" height="11" width="<%
  110. Response.Write(Round((votes(i) / mostvotes * 150),0))
  111. %>" alt="" />&nbsp;<%
  112. Response.Write(Round((votes(i) / totalvotes * 100),0) & "%")%>
  113.  
  114. <%
  115. Else
  116. %>0%
  117. <%
  118. End If
  119. %>
  120. </div>
  121.  
  122. <%
  123. End If
  124.  
  125. %>
  126.  
  127. <div class="responses">Total number of votes: <% Response.Write(totalvotes) %></div>
  128.  
  129. <%
  130. Else
  131. %>
  132.  
  133. <div class="question"><% Response.Write(question) %></div>
  134.  
  135. <form class="votingform" action="poll/processvote.asp" method="post">
  136.  
  137. <%
  138. For i = 1 to 8
  139. If responses(i) <> "" Then
  140. %>
  141. <div class="responses"><input type="radio" name="vote" value="<% Response.Write(i) %>" /> <% Response.Write(responses(i)) %></div>
  142. <%
  143. End If
  144. %>
  145.  
  146. <input type="hidden" name="referrer" value="<% Response.Write("http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")) %>" />
  147.  
  148. <div class="responses"><input type="submit" value="Vote" class="votebutton" />&nbsp;&nbsp;<a href="poll/results.asp" target="_blank">View Results</a></div>
  149.  
  150. </form>
  151.  
  152. <%
  153. End If
  154. %>
  155. +++default.asp+++(login en admin)
  156. <%
  157.  
  158. %><!--#include file="password.asp"--><%
  159.  
  160. ' check if page is being reloaded after password submit
  161. If Request.Form("password") <> "" Then
  162.  
  163. ' verify password
  164. If Request.Form("password") = password Then
  165.  
  166. Session("loggedin") = "true"
  167. Response.Redirect "newpoll.asp"
  168.  
  169. End If
  170.  
  171. End If
  172.  
  173. %>
  174. <html>
  175. <head>
  176. <title> - Log in</title>
  177. <link rel="stylesheet" type="text/css" href="pollbuddy.css" />
  178.  
  179. </head>
  180. <body>
  181. <div class="titlebar"><img src="pollbuddy.gif" width="142" height="33" border="0" align="middle" alt="PollBuddy" /></div>
  182.  
  183. <form action="default.asp" method="post">
  184. <div class="header">Log in</div>
  185. <div class="normal">Password: <input type="password" name="password" /> <input type="submit" value="Log in" /></div>
  186. </form>
  187.  
  188. <%
  189. If Request.Form("password") <> "" Then
  190. If Request.Form("password") <> password Then
  191. %>
  192. <div class="warning">The password you entered was incorrect.</div>
  193. <%
  194. End If
  195. End If
  196. %>
  197.  
  198. <div class="normal" align="right">Copyright &copy; 2002 <a href="http://www.blogtastic.com">Benjamin James</a></div>
  199.  
  200. </body>
  201. </html>
  202. +++newpoll.asp+++
  203. <%
  204.  
  205. %><%
  206.  
  207. 'check user is logged in
  208.  
  209. If Session("loggedin") = "true" Then
  210.  
  211. %>
  212. <html>
  213. <head>
  214. <title>PollBuddy - Create new poll</title>
  215. <link rel="stylesheet" type="text/css" href="pollbuddy.css" />
  216. </head>
  217. <body>
  218.  
  219. <table width="100%" cellpadding="0" cellspacing="0" border="0">
  220. <tr>
  221. <td class="titlebar"><img src="pollbuddy.gif" width="142" height="33" border="0" align="middle" alt="PollBuddy" /></td>
  222. <td class="navbar"><a href="results.asp" class="nav" target="_blank">view results</a> | <a href="logout.asp" class="nav">log out</a></td>
  223. </tr>
  224. </table>
  225.  
  226. <div class="header">Create new poll</div>
  227.  
  228. <%
  229.  
  230. ' check if pages is being reloaded after new poll form submit
  231. If Request.Form("question")<>"" Then
  232.  
  233. 'create a variable for the poll question
  234. Dim question
  235. question = Request.Form("question")
  236.  
  237. 'create an array for the response strings
  238. Dim responses(8)
  239.  
  240. 'add the response strings to the array
  241. responses(1) = Request.Form("response1")
  242. responses(2) = Request.Form("response2")
  243. responses(3) = Request.Form("response3")
  244. responses(4) = Request.Form("response4")
  245. responses(5) = Request.Form("response5")
  246. responses(6) = Request.Form("response6")
  247. responses(7) = Request.Form("response7")
  248. responses(8) = Request.Form("response8")
  249.  
  250. 'replace characters that might cause errors on the javascript voting form
  251. question = replace(question,"/","&#47;")
  252. question = replace(question,"'","&#39;")
  253. question = replace(question,"""","&#34;")
  254.  
  255. For i = 1 to 8
  256. responses(i) = replace(responses(i),"/","&#47;")
  257. responses(i) = replace(responses(i),"'","&#39;")
  258. responses(i) = replace(responses(i),"""","&#34;")
  259.  
  260. 'create an array for the number of votes
  261. Dim votes(8)
  262.  
  263. 'set all votes to zero
  264. For i = 1 to 8
  265. votes(i) = 0
  266.  
  267. 'open the file variables.asp
  268. Set FS=Server.CreateObject("Scripting.FileSystemObject")
  269. Set RS=FS.OpenTextFile(Server.MapPath("variables.asp"), 2, False)
  270.  
  271. 'write in the new variables
  272. RS.WriteLine("<" & "%")
  273. RS.WriteLine("Dim question, responses(8), votes(8)")
  274. RS.WriteLine("question = """ & question & """")
  275. For i = 1 to 8
  276. RS.WriteLine("responses(" & i & ") = """ & responses(i) & """")
  277. RS.WriteLine("votes(" & i & ") = " & votes(i))
  278. RS.WriteLine("%" & ">")
  279.  
  280. RS.Close
  281. Set RS=Nothing
  282. Set FS=Nothing
  283.  
  284. %>
  285.  
  286. <div class="normal">New poll created. The variables you entered are as follows:</div>
  287.  
  288. <div class="normal"><b><% Response.Write(question) %></b></div>
  289. <%
  290. For i = 1 to 8
  291. If responses(i) <> "" Then
  292. %>
  293. <div class="normal"><% Response.Write(responses(i)) %></div>
  294.  
  295. <%
  296. End if
  297. %>
  298. <br />
  299. <div class="normal"><a href="javascript:history.back()">Click here</a> to go back.</div>
  300.  
  301. <div class="normal" align="right">Copyright &copy; 2002 <a href="http://www.blogtastic.com">Benjamin James</a></div>
  302.  
  303. <%
  304. Else
  305. %>
  306.  
  307.  
  308. <form action="newpoll.asp" method="post">
  309. <table>
  310. <tr>
  311. <td align="right"><div class="normal"><b>Question:</b></div></td>
  312. <td><input type="text" name="question" /></td>
  313. </tr>
  314. <% For i = 1 to 8 %>
  315. <tr>
  316. <td align="right"><div class="normal">Response <% Response.Write(i) %>:</div></td>
  317. <td><input type="text" name="response<% Response.Write(i) %>" /></td>
  318. </tr>
  319. <% Next %>
  320. </table>
  321. <div class="normal"><input type="reset" value="Clear" /> <input type="submit" value="Create Poll" /></div>
  322. </form>
  323.  
  324. <div class="normal" align="right">Copyright &copy; 2002 <a href="http://www.blogtastic.com">Benjamin James</a></div>
  325.  
  326. </body>
  327. </html>
  328.  
  329. <%
  330. End If
  331.  
  332. Else
  333.  
  334. Response.Redirect "default.asp"
  335.  
  336. End If
  337.  
  338. %>
  339.  
  340. +++results.asp+++
  341. <html>
  342. <head>
  343. <title> - Results</title> Results</title>
  344. <style type="text/css">
  345. body {
  346. margin : 12px;
  347. color : #000000;
  348. background-color : #ffffff;
  349. }
  350. .question {
  351. font-family : arial, helvetica, monaco, sans-serif;
  352. font-size : 13px;
  353. font-weight : bold;
  354. color : #303090;
  355. background-color : transparent;
  356. margin-left : 0px;
  357. margin-right : 0px;
  358. margin-top : 8px;
  359. margin-bottom : 8px;
  360. }
  361. .responses {
  362. font-family : arial, helvetica, monaco, sans-serif;
  363. font-size : 12px;
  364. font-weight : bold;
  365. color : #000000;
  366. background-color : transparent;
  367. margin-left : 0px;
  368. margin-right : 0px;
  369. margin-top : 4px;
  370. margin-bottom : 4px;
  371. }
  372. .percent {
  373. font-family : arial, helvetica, monaco, sans-serif;
  374. font-size : 12px;
  375. color : #000000;
  376. background-color : transparent;
  377. margin-left : 0px;
  378. margin-right : 0px;
  379. margin-top : 4px;
  380. margin-bottom : 4px;
  381. }
  382. .totalvotes {
  383. font-family : arial, helvetica, monaco, sans-serif;
  384. font-size : 12px;
  385. color : #000000;
  386. background-color : transparent;
  387. margin-left : 0px;
  388. margin-right : 0px;
  389. margin-top : 8px;
  390. margin-bottom : 8px;
  391. }
  392. </style>
  393. <!--#include file ="variables.asp"-->
  394. <%
  395.  
  396. 'find which is the largest number of votes
  397. Dim mostvotes
  398. mostvotes = 0
  399. For i = 1 to 8
  400. If mostvotes < votes(i) Then
  401. mostvotes = votes(i)
  402. End If
  403. Next
  404.  
  405. 'calculate the total number of votes
  406. Dim totalvotes
  407. totalvotes = 0
  408. For i = 1 to 8
  409. totalvotes = totalvotes + votes(i)
  410. %>
  411. </head>
  412. <body>
  413. <div class="question"><% Response.Write(question) %></div>
  414. <table>
  415. <%
  416. For i = 1 to 8
  417. If responses(i) <> "" Then
  418. %>
  419. <tr>
  420. <td align="right"><div class="responses"><% Response.Write(responses(i)) %></div></td>
  421. <td>
  422. <div class="percent">
  423. <%
  424. If votes(i) <> 0 Then
  425. %>
  426. <img src="bar1.gif" height="11" width="<%
  427. Response.Write(Round((votes(i) / mostvotes * 150),0))
  428. %>" alt="" />&nbsp;<%
  429. Response.Write(Round((votes(i) / totalvotes * 100),0) & "%")
  430. Else
  431. %> 0%
  432. <%
  433. End If
  434. %>
  435. </div>
  436. </td>
  437. </tr>
  438. <%
  439. End If
  440. %>
  441. </table>
  442. <div class="totalvotes">Total number of votes: <% Response.Write(totalvotes) %></div>
  443. </body>
  444. </html>
  445. +++vote_js.asp+++
  446. <%
  447.  
  448. %><!--#include file ="variables.asp"-->
  449.  
  450. <%
  451. If Request.Cookies("voted") = question Then
  452.  
  453. 'find which is the largest number of votes
  454. Dim mostvotes
  455. mostvotes = 0
  456. For i = 1 to 8
  457. If mostvotes < votes(i) Then
  458. mostvotes = votes(i)
  459. End If
  460. Next
  461.  
  462. 'calculate the total number of votes
  463. Dim totalvotes
  464. totalvotes = 0
  465. For i = 1 to 8
  466. totalvotes = totalvotes + votes(i)
  467. %>
  468.  
  469. document.writeln('<div class="question"><% Response.Write(question) %><\/div>')
  470.  
  471. <%
  472. For i = 1 to 8
  473. If responses(i) <> "" Then
  474. %>
  475.  
  476. document.writeln('<div class="responsetwo"><% Response.Write(responses(i)) %><\/div>')
  477.  
  478. document.writeln('<div class="barline">')
  479. <%
  480. If votes(i) <> 0 Then
  481. %>
  482. document.writeln('<img src="poll\/bar1.gif" height="11" width="<%
  483. Response.Write(Round((votes(i) / mostvotes * 100),0))
  484. %>" alt="" \/>&nbsp;<%
  485. Response.Write(Round((votes(i) / totalvotes * 100),0) & "%")%>')
  486.  
  487. <%
  488. Else
  489. %> document.writeln('0%')
  490. <%
  491. End If
  492. %>
  493. document.writeln('<\/div>')
  494.  
  495. <%
  496. End If
  497.  
  498. %>
  499.  
  500. document.writeln('<div class="menutext">Total number of votes: <% Response.Write(totalvotes) %><\/div>')
  501.  
  502. <%
  503. Else
  504. %>
  505.  
  506. document.writeln('<div class="question"><% Response.Write(question) %><\/div>')
  507.  
  508. document.writeln('<form class="votingform" action="poll\/processvote.asp" method="post">')
  509.  
  510. <%
  511. For i = 1 to 8
  512. If responses(i) <> "" Then
  513. %>
  514. document.writeln('<div class="responses"><input type="radio" name="vote" value="<% Response.Write(i) %>" \/> <% Response.Write(responses(i)) %><\/div>')
  515. <%
  516. End If
  517.  
  518. %>
  519.  
  520. document.writeln('<input type="hidden" name="referrer" value="' + window.location + '" \/>')
  521.  
  522. document.writeln('<div class="responses"><input type="submit" value="Vote" class="votebutton" \/>&nbsp;&nbsp;<a href="poll\/results.asp" target="_blank">View Results</a><\/div>')
  523.  
  524. document.writeln('<\/form>')
  525.  
  526. <%
  527. End If
  528. %>
  529. +++password.asp+++
  530. <%
  531.  
  532. %><%
  533. Dim password
  534. password="password"
  535. %>
  536. +++processvote.asp+++
  537. <%
  538.  
  539. %><!--#include file="variables.asp"--><%
  540.  
  541. Dim vote
  542. vote = Request.Form("vote")
  543.  
  544. If Request.Cookies("voted") <> question Then
  545. If vote <> "" Then
  546.  
  547. 'set a cookie to stop multiple votes
  548. Response.Cookies("voted") = question
  549. Response.Cookies("voted").Expires = DateAdd("d",30,date())
  550.  
  551. votes(vote) = votes(vote) + 1
  552.  
  553. 'open the file variables.asp
  554. Set FS=Server.CreateObject("Scripting.FileSystemObject")
  555. Set RS=FS.OpenTextFile(Server.MapPath("variables.asp"), 2, False)
  556.  
  557. 'write in the new variables
  558. RS.WriteLine("<" & "%")
  559. RS.WriteLine("Dim question, responses(8), votes(8)")
  560. RS.WriteLine("question = """ & question & """")
  561. For i = 1 to 8
  562. RS.WriteLine("responses(" & i & ") = """ & responses(i) & """")
  563. RS.WriteLine("votes(" & i & ") = " & votes(i))
  564. Next
  565. RS.WriteLine("%" & ">")
  566.  
  567. RS.Close
  568. Set RS=Nothing
  569. Set FS=Nothing
  570.  
  571. End If
  572. End If
  573.  
  574. Dim redirectURL
  575. redirectURL = Request.Form("referrer")
  576.  
  577. If redirectURL <> "" Then
  578.  
  579. Response.Redirect(redirectURL)
  580.  
  581. End If
  582.  
  583. %>
  584. +++variables.asp+++
  585. <%
  586.  
  587. %><%
  588. Dim question, responses(8), votes(8)
  589. question = ""
  590. responses(1) = ""
  591. votes(1) = 0
  592. responses(2) = ""
  593. votes(2) = 0
  594. responses(3) = ""
  595. votes(3) = 0
  596. responses(4) = ""
  597. votes(4) = 0
  598. responses(5) = ""
  599. votes(5) = 0
  600. responses(6) = ""
  601. votes(6) = 0
  602. responses(7) = ""
  603. votes(7) = 0
  604. responses(8) = ""
  605. votes(8) = 0
  606. %>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (2)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.044s