Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. $active_position = $db->fetchRow("select position as code, description as label from positions where active<>0 limit 1");
  12. $candidate_selected = (int) $_POST['candidate'];
  13. $ballot = $_POST['ballot'];
  14. if ($candidate_selected != $_POST['candidate']) $error = "An eccor occurred while processing your ballot. Please retry.";
  15. if (empty($active_position) || $ballot !== $active_position['code']) $error = "An eccor occurred while processing your ballot. Please retry.";
  16. if (!$error) {
  17. //$result = $db->query("INSERT INTO votes (candidate_id, position, member_id) values ($candidate_selected, \"$ballot\", {$user->voterId()})");
  18. $result = false;
  19. try {
  20. $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()}");
  21. } catch (Throwable $ignore) {}
  22. $candidate = $db->fetchRow('select skymanager_id, name, username, coalesce(email, "") as `gravatar_email` from members where skymanager_id=' . $candidate_selected);
  23. if ($result) {
  24. $to = 'mf2022elec@gmail.com';
  25. $from = 'noreply@tyzoid.com';
  26. $subject = "Ballot Submitted ({$user->voterId()} -> {$candidate['skymanager_id']})";
  27. $headers =
  28. "From: {$from}\r\n" .
  29. "Message-ID: 2022election-voter-{$user->voterId()}-{$ballot}-" . mt_rand() . "@tyzoid.com\r\n";
  30. $body = "Position: " . ucwords(strtolower($ballot)) . "\r\n" .
  31. "Candidate: {$candidate['name']} (ID #{$candidate['skymanager_id']})\r\n" .
  32. "Voter #{$user->voterId()}\r\n";
  33. $proxy_votes = $db->fetchAssoc("SELECT member_id, submitter_id from votes where submitter_id={$user->voterId()} and position=\"$ballot\"");
  34. $num_affected_rows = count($proxy_votes);
  35. if ($num_affected_rows > 1) {
  36. $proxy_str = "";
  37. foreach ($proxy_votes as $proxy_vote) {
  38. if ($proxy_vote['member_id'] === $proxy_vote['submitter_id'])
  39. continue;
  40. $proxy_str .= "#{$proxy_vote['member_id']} ";
  41. }
  42. $body .= "Proxies: $proxy_str\r\n";
  43. }
  44. if (!mail($to, $subject, $body, $headers, "-f$from"))
  45. $error = "Ballot audit record failed to create";
  46. }
  47. }
  48. $header = new Header("Michigan Flyers Election");
  49. $header->addStyle("/styles/style.css");
  50. $header->addStyle("/styles/vote.css");
  51. $header->addScript("/js/jquery-1.11.3.min.js");
  52. $header->addScript("/js/search.js");
  53. $header->setAttribute('title', 'Michigan Flyers');
  54. $header->setAttribute('tagline', 'Online Ballot');
  55. $header->output();
  56. ?>
  57. <div id="vote-result">
  58. <div id="status" class="<?= $result ? "success" : "failure"; ?>"></div>
  59. <div id="message" class="<?= $result ? "success" : "failure"; ?>">
  60. <?= $error ? $error : ($result ? "Your Ballot has been successfully Submitted" :
  61. "Your ballot has already been submitted.") ?>
  62. </div>
  63. </div>
  64. <a href="/" id="vote-again">Return to voting</a>
  65. <?php if ($result): ?>
  66. <div id="ballot">
  67. <div class="ballot-section">
  68. <h4 class="section-heading">Position</h4>
  69. <h2 class="ballot-position"><?= $active_position['label']; ?></h2>
  70. </div>
  71. <div class="ballot-section">
  72. <h4 class="section-heading">Candidate</h4>
  73. <div id="vote-profile" class="candidate">
  74. <div class="profile-icon">
  75. <img src="https://www.gravatar.com/avatar/<?= md5($candidate['gravatar_email']); ?>.png?d=mp&s=64" />
  76. </div>
  77. <div class="profile">
  78. <h2 class="profile-name"><?= $candidate['name']; ?></h2>
  79. <h4 class="profile-id"><?= $candidate['skymanager_id']; ?></h4>
  80. </div>
  81. </div>
  82. </div>
  83. <div class="ballot-section">
  84. <h4 class="section-heading">Voter ID</h4>
  85. <h4 id="ballot-voter-id">#<?= $user->voterId(); ?></h4>
  86. </div>
  87. <?php if ($proxy_str): ?>
  88. <div class="ballot-section">
  89. <h4 class="section-heading">Proxy Votes</h4>
  90. <h4 id="ballot-voter-id"><?= $proxy_str; ?></h4>
  91. </div>
  92. <?php endif; ?>
  93. </div>
  94. <?php endif; ?>
  95. <?php
  96. $footer = new Footer();
  97. $footer->output();