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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 !== "VICEPRESIDENT" && $ballot !== "SECRETARY" && $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 = 'mf2022elec@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: 2022election-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. $positions = [
  50. 'VICEPRESIDENT' => 'Vice President',
  51. 'SECRETARY' => 'Secretary',
  52. 'DIRECTOR' => 'Director'
  53. ];
  54. $voteFor = null;
  55. if (count($votes) < count($positions)) {
  56. $voteFor = array_values($positions)[count($votes)];
  57. }
  58. $header = new Header("2022 Michigan Flyers Election");
  59. $header->addStyle("/styles/style.css");
  60. $header->addStyle("/styles/vote.css");
  61. $header->addScript("/js/jquery-1.11.3.min.js");
  62. $header->addScript("/js/search.js");
  63. $header->setAttribute('title', 'Michigan Flyers');
  64. $header->setAttribute('tagline', '2022 Online Ballot');
  65. $header->output();
  66. ?>
  67. <div id="vote-result">
  68. <div id="status" class="<?= $result ? "success" : "failure"; ?>"></div>
  69. <div id="message" class="<?= $result ? "success" : "failure"; ?>">
  70. <?= $error ? $error : ($result ? "Your Ballot has been successfully Submitted" :
  71. "Your ballot has already been submitted.") ?>
  72. </div>
  73. </div>
  74. <?php if ($voteFor): ?>
  75. <a href="/" id="vote-again">Vote for <?= $voteFor; ?></a>
  76. <?php endif; ?>
  77. <?php if ($result): ?>
  78. <div id="ballot">
  79. <div class="ballot-section">
  80. <h4 class="section-heading">Vice Position</h4>
  81. <h2 class="ballot-position"><?= $positions[$ballot]; ?></h2>
  82. </div>
  83. <div class="ballot-section">
  84. <h4 class="section-heading">Candidate</h4>
  85. <div id="vote-profile" class="candidate">
  86. <div class="profile-icon">
  87. <img src="https://www.gravatar.com/avatar/<?= $candidate['gravatar_hash']; ?>.png?d=mp&s=64" />
  88. </div>
  89. <div class="profile">
  90. <h2 class="profile-name"><?= $candidate['name']; ?></h2>
  91. <h4 class="profile-id"><?= $candidate['skymanager_id']; ?></h4>
  92. </div>
  93. </div>
  94. </div>
  95. <div class="ballot-section">
  96. <h4 class="section-heading">Voter ID</h4>
  97. <h4 id="ballot-voter-id">#<?= $user->voterId(); ?></h4>
  98. </div>
  99. <?php if ($proxy_str): ?>
  100. <div class="ballot-section">
  101. <h4 class="section-heading">Proxy Votes</h4>
  102. <h4 id="ballot-voter-id"><?= $proxy_str; ?></h4>
  103. </div>
  104. <?php endif; ?>
  105. </div>
  106. <?php endif; ?>
  107. <?php
  108. $footer = new Footer();
  109. $footer->output();