Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

vote.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. include('inc/inc.php');
  3. if (!$user->loggedin()) {
  4. header('Location: /login.php');
  5. die();
  6. }
  7. if (!$user->voterId()) {
  8. header('Location: /login.php?denied');
  9. die();
  10. }
  11. $candidate_selected = (int) $_POST['candidate'];
  12. $ballot = $_POST['ballot'];
  13. if ($candidate_selected != $_POST['candidate']) $error = "An eccor occurred while processing your ballot. Please retry.";
  14. if ($ballot !== "PRESIDENT" && $ballot !== "DIRECTOR") $error = "An eccor occurred while processing your ballot. Please retry.";
  15. if (!$error) {
  16. //$result = $db->query("INSERT INTO votes (candidate_id, position, member_id) values ($candidate_selected, \"$ballot\", {$user->voterId()})");
  17. $result = $db->query("INSERT INTO votes (candidate_id, position, member_id, vote_type, submitter_id) SELECT $candidate_selected, \"$ballot\", {$user->voterId()}, 'ONLINE', {$user->voterId()} UNION SELECT $candidate_selected, \"$ballot\", voting_id, 'PROXY ONLINE', delegate_id from proxy where delegate_id={$user->voterId()}");
  18. $candidate = $db->fetchRow('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where skymanager_id=' . $candidate_selected);
  19. if ($result) {
  20. $to = 'mf2021elec@gmail.com';
  21. $from = 'noreply@tyzoid.com';
  22. $subject = "Ballot Submitted ({$user->voterId()} -> {$candidate['skymanager_id']})";
  23. $headers =
  24. "From: {$from}\r\n" .
  25. "Message-ID: 2021election-voter-{$user->voterId()}-{$ballot}-" . mt_rand() . "@tyzoid.com\r\n";
  26. $body = "Position: " . ucwords(strtolower($ballot)) . "\r\n" .
  27. "Candidate: {$candidate['name']} (ID #{$candidate['skymanager_id']})\r\n" .
  28. "Voter #{$user->voterId()}\r\n";
  29. $proxy_votes = $db->fetchAssoc("SELECT member_id, submitter_id from votes where submitter_id={$user->voterId()} and position=\"$ballot\"");
  30. $num_affected_rows = count($proxy_votes);
  31. if ($num_affected_rows > 1) {
  32. $proxy_str = "";
  33. foreach ($proxy_votes as $proxy_vote) {
  34. if ($proxy_vote['member_id'] === $proxy_vote['submitter_id'])
  35. continue;
  36. $proxy_str .= "#{$proxy_vote['member_id']} ";
  37. }
  38. $body .= "Proxies: $proxy_str\r\n";
  39. }
  40. if (!mail($to, $subject, $body, $headers, "-f$from"))
  41. $error = "Ballot audit record failed to create";
  42. }
  43. }
  44. $votes = $db->fetchAssoc("select position from votes where member_id={$user->voterId()}");
  45. foreach ($votes as &$vote) {
  46. $vote = $vote['position'];
  47. }
  48. unset($vote);
  49. $voteFor = null;
  50. if (count($votes) == 1) {
  51. $voteFor = $votes[0] == "PRESIDENT" ? "Director" : "President";
  52. }
  53. $header = new Header("2021 Michigan Flyers Election");
  54. $header->addStyle("/styles/style.css");
  55. $header->addStyle("/styles/vote.css");
  56. $header->addScript("/js/jquery-1.11.3.min.js");
  57. $header->addScript("/js/search.js");
  58. $header->setAttribute('title', 'Michigan Flyers');
  59. $header->setAttribute('tagline', '2021 Online Ballot');
  60. $header->output();
  61. ?>
  62. <div id="vote-result">
  63. <div id="status" class="<?= $result ? "success" : "failure"; ?>"></div>
  64. <div id="message" class="<?= $result ? "success" : "failure"; ?>">
  65. <?= $error ? $error : ($result ? "Your Ballot has been successfully Submitted" :
  66. "Your ballot has already been submitted.") ?>
  67. </div>
  68. </div>
  69. <?php if ($voteFor): ?>
  70. <a href="/" id="vote-again">Vote for <?= $voteFor; ?></a>
  71. <?php endif; ?>
  72. <?php if ($result): ?>
  73. <div id="ballot">
  74. <div class="ballot-section">
  75. <h4 class="section-heading">Position</h4>
  76. <h2 class="ballot-position"><?= ucwords(strtolower($ballot)); ?></h2>
  77. </div>
  78. <div class="ballot-section">
  79. <h4 class="section-heading">Candidate</h4>
  80. <div id="vote-profile" class="candidate">
  81. <div class="profile-icon">
  82. <img src="https://www.gravatar.com/avatar/<?= $candidate['gravatar_hash']; ?>.png?d=mp&s=64" />
  83. </div>
  84. <div class="profile">
  85. <h2 class="profile-name"><?= $candidate['name']; ?></h2>
  86. <h4 class="profile-id"><?= $candidate['skymanager_id']; ?></h4>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="ballot-section">
  91. <h4 class="section-heading">Voter ID</h4>
  92. <h4 id="ballot-voter-id">#<?= $user->voterId(); ?></h4>
  93. </div>
  94. <?php if ($proxy_str): ?>
  95. <div class="ballot-section">
  96. <h4 class="section-heading">Proxy Votes</h4>
  97. <h4 id="ballot-voter-id"><?= $proxy_str; ?></h4>
  98. </div>
  99. <?php endif; ?>
  100. </div>
  101. <?php endif; ?>
  102. <?php
  103. $footer = new Footer();
  104. $footer->output();