PageRenderTime 28ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/web/pollResult.jsp

https://bitbucket.org/NightFury_37/poll
JavaServer Pages | 141 lines | 138 code | 3 blank | 0 comment | 34 complexity | d82df7b466183e99ce87ddab1c35d484 MD5 | raw file
  1. <%--
  2. Document : pollResult
  3. Created on : 14 May, 2013, 11:07:41 AM
  4. Author : tpatil
  5. --%>
  6. <%@page import="com.ea.poll.Constants"%>
  7. <%@page import="com.ea.poll.model.User"%>
  8. <%@page import="com.ea.poll.model.Choice"%>
  9. <%@page import="com.ea.poll.storage.StorageHandler"%>
  10. <%@page import="com.ea.poll.model.Question"%>
  11. <%@page import="java.util.Vector"%>
  12. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  13. <%
  14. Vector<Question> questions = StorageHandler.readQuestions(Constants.QUESTIONS_STORAGE_FILE);
  15. Vector<Integer> questionIds = new Vector<Integer>();
  16. boolean flag = false;
  17. for (Question question : questions) {
  18. String action = request.getParameter(question.toString() + "Text");
  19. if (action != null) {
  20. if (!action.equals("")) {
  21. int choicesSize = question.getChoices().size();
  22. question.addChoice(new Choice(question, action).addUserVote(new User(request.getParameter("voterName"))));
  23. if (choicesSize == question.getChoices().size()) {
  24. for (Choice choice : question.getChoices()) {
  25. int usersSize = choice.getNumberOfUsers();
  26. if (action.trim().toLowerCase().equals(choice.toString().trim().toLowerCase())) {
  27. choice.addUserVote(new User(request.getParameter("voterName")));
  28. if (usersSize != choice.getNumberOfUsers()) {
  29. flag = true;
  30. questionIds.add(question.getId());
  31. }
  32. }
  33. }
  34. } else {
  35. flag = true;
  36. }
  37. } else {
  38. action = request.getParameter(question.toString());
  39. if (action != null) {
  40. for (Choice choice : question.getChoices()) {
  41. int usersSize = choice.getNumberOfUsers();
  42. if (action.equals(choice.toString())) {
  43. choice.addUserVote(new User(request.getParameter("voterName")));
  44. if (usersSize != choice.getNumberOfUsers()) {
  45. flag = true;
  46. questionIds.add(question.getId());
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. StorageHandler.writeQuestions(questions, Constants.QUESTIONS_STORAGE_FILE);
  55. %>
  56. <!DOCTYPE html>
  57. <html>
  58. <head>
  59. <link href="DisplayStyle.css" rel="stylesheet" type="text/css">
  60. <link rel = "shortcut icon" type = "image/x-icon" href = "resources/ea.ico">
  61. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  62. <style>
  63. a:link {color:#FFFFFF;} /* unvisited link */
  64. a:visited {color:#FFFFFF;} /* visited link */
  65. a:hover {color:#FFFFFF;} /* mouse over link */
  66. a:active {color:#FFFFFF;} /* selected link */
  67. </style>
  68. <title>Studio Poll</title>
  69. </head>
  70. <body>
  71. <div class="controlbar">
  72. <%
  73. boolean localFlag = false;
  74. if (session.getAttribute("authorized") != null) {
  75. if (session.getAttribute("authorized").toString().equals("yes")) {
  76. localFlag = true;
  77. }
  78. }
  79. if (localFlag) {%>
  80. <div class="loginbutton"><a href="administratorLogout.jsp">Administrator Logout</a></div>
  81. <div class="loginbutton"><a href="adminView.jsp">Back to administration...</a></div>
  82. <div class="loginbutton"><a href="index.jsp">Back to poll...</a></div>
  83. <div class="loginbutton"><b>Hello <%= session.getAttribute("userName")%></b></div>
  84. <% } else {%>
  85. <div class="loginbutton"><a href="administratorLogin.jsp">Administrator Login</a></div>
  86. <div class="loginbutton"><a href="index.jsp">Back to poll...</a></div>
  87. <% }
  88. %>
  89. </div>
  90. <div class="header">
  91. <div class="logo">
  92. <img src='resources/logo.jpg'/>
  93. </div>
  94. <div class="title">
  95. <% if (flag) {%>
  96. <h1>Thank you for your vote</h1>
  97. </div>
  98. </div>
  99. <div class="myform">
  100. <ol>
  101. <% overall:
  102. for (Question question : questions) {
  103. for (Integer id : questionIds) {
  104. if (id.intValue() == question.getId()) {
  105. break;
  106. } else {
  107. continue overall;
  108. }
  109. }%>
  110. <li>
  111. <div style="padding-left: 20px">
  112. <h3>
  113. <%= question%>
  114. </h3>
  115. </div>
  116. <div style="padding-left: 40px">
  117. <% for (Choice choice : question.getChoices()) {%>
  118. <div style="border: 1px #AAAAAA outset; margin-bottom: 10px; margin-right: 40px; padding: 5px; padding-left: 15px">
  119. <%= choice + " \t(" + choice.getNumberOfUsers() + ((choice.getNumberOfUsers() != 1) ? " votes)" : " vote)")%> <br><br>
  120. <% for (User user : choice.getUsers()) {%>
  121. <div style="float: left; margin: 10px; margin-top: 0px; padding: 10px; width: auto; height: 10px; background: #AAAAAA; color: #000000; line-height: 1em; border: 1px #EEEEEE inset">
  122. <%= user.getName()%>
  123. </div>
  124. <% }%>
  125. <div style="clear: both"></div>
  126. </div>
  127. <% }%>
  128. </li>
  129. <%
  130. }%>
  131. </ol>
  132. <% } else {%>
  133. <h1>Your vote was not accepted</h1>
  134. <% }%>
  135. </div>
  136. </div>
  137. </body>
  138. </html>