| @@ -16,14 +16,14 @@ if (!empty($_POST['voter']) && ((int) $_POST['voter']) == $_POST['voter']) { | |||
| $result = $db->query("update members set checkedin=true where voting_id=$voter"); | |||
| } | |||
| $header = new Header("2021 Michigan Flyers Election : Poll Worker"); | |||
| $header = new Header("2022 Michigan Flyers Election : Poll Worker"); | |||
| $header->addStyle("/styles/style.css"); | |||
| $header->addStyle("/styles/admin.css"); | |||
| $header->addStyle("/styles/vote.css"); | |||
| $header->addScript("/js/jquery-1.11.3.min.js"); | |||
| $header->addScript("/js/admin-search.js"); | |||
| $header->setAttribute('title', 'Michigan Flyers'); | |||
| $header->setAttribute('tagline', '2021 Election Administration'); | |||
| $header->setAttribute('tagline', '2022 Election Administration'); | |||
| $header->output(); | |||
| $voters = $db->fetchAssoc('select ANY_VALUE(skymanager_id) as `skymanager_id`, ANY_VALUE(members.voting_id) as `voting_id`, ANY_VALUE(name) as `name`, ANY_VALUE(username) as `username`, group_concat(proxy.voting_id) as `proxies`, ANY_VALUE(upstream_proxy.delegate_id) as `delegate`, md5(coalesce(ANY_VALUE(email), "")) as `gravatar_hash` from members left join proxy on (members.voting_id=proxy.delegate_id) left join proxy as upstream_proxy on (upstream_proxy.voting_id=members.voting_id) where members.voting_id is not null group by members.voting_id UNION select skymanager_id, voting_id, name, username, NULL as `proxies`, NULL as `delegate`, md5(coalesce(email, "")) as `gravatar_hash` from members where members.voting_id is null'); | |||
| @@ -18,7 +18,7 @@ if (!empty($_POST['ballot']) && !empty($_POST['candidate'])) { | |||
| if ($candidate_selected != $_POST['candidate']) $error = "An eccor occurred while processing your ballot. Please retry."; | |||
| if ($voter_selected != $_POST['voter']) $error = "An eccor occurred while processing your ballot. Please retry."; | |||
| if ($ballot !== "PRESIDENT" && $ballot !== "DIRECTOR") $error = "An eccor occurred while processing your ballot. Please retry."; | |||
| if ($ballot !== "VICEPRESIDENT" && $ballot !== "SECRETARY" && $ballot !== "DIRECTOR") $error = "An eccor occurred while processing your ballot. Please retry."; | |||
| if (empty($error)) { | |||
| $result = $db->query("INSERT INTO votes (candidate_id, position, member_id, vote_type, submitter_id) SELECT $candidate_selected, \"$ballot\", $voter_selected, 'IN PERSON', $voter_selected UNION SELECT $candidate_selected, \"$ballot\", voting_id, 'PROXY IN PERSON', delegate_id from proxy where delegate_id=$voter_selected"); | |||
| @@ -40,7 +40,13 @@ if (!empty($_POST['ballot']) && !empty($_POST['candidate'])) { | |||
| } | |||
| } | |||
| $header = new Header("2021 Michigan Flyers Election : Poll Worker"); | |||
| $positions = [ | |||
| 'VICEPRESIDENT' => 'Vice President', | |||
| 'SECRETARY' => 'Secretary', | |||
| 'DIRECTOR' => 'Director' | |||
| ]; | |||
| $header = new Header("2022 Michigan Flyers Election : Poll Worker"); | |||
| $header->addStyle("/styles/style.css"); | |||
| $header->addStyle("/styles/admin.css"); | |||
| $header->addStyle("/styles/vote.css"); | |||
| @@ -48,7 +54,7 @@ $header->addScript("/js/jquery-1.11.3.min.js"); | |||
| $header->addScript("/js/search.js"); | |||
| $header->addScript("/js/admin-search.js"); | |||
| $header->setAttribute('title', 'Michigan Flyers'); | |||
| $header->setAttribute('tagline', '2021 Election Administration'); | |||
| $header->setAttribute('tagline', '2022 Election Administration'); | |||
| $header->output(); | |||
| $candidates = $db->fetchAssoc('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where voting_id is not null'); | |||
| @@ -78,8 +84,12 @@ var candidates = <?= json_encode($candidates); ?>; | |||
| <div class="form-row"> | |||
| <div class="selector"> | |||
| <label class="radio"> | |||
| <input type="radio" id="vote-president" name="ballot" value="PRESIDENT" checked /> | |||
| <span class="radio-button-label">President</span> | |||
| <input type="radio" id="vote-vicepresident" name="ballot" value="VICEPRESIDENT" checked /> | |||
| <span class="radio-button-label">Vice President</span> | |||
| </label> | |||
| <label class="radio"> | |||
| <input type="radio" id="vote-secretary" name="ballot" value="SECRETARY" checked /> | |||
| <span class="radio-button-label">Secretary</span> | |||
| </label> | |||
| <label class="radio"> | |||
| <input type="radio" id="vote-director" name="ballot" value="DIRECTOR" /> | |||
| @@ -120,7 +130,7 @@ var candidates = <?= json_encode($candidates); ?>; | |||
| <div id="ballot"> | |||
| <div class="ballot-section"> | |||
| <h4 class="section-heading">Position</h4> | |||
| <h2 class="ballot-position"><?= ucwords(strtolower($ballot)); ?></h2> | |||
| <h2 class="ballot-position"><?= $positions[$ballot]; ?></h2> | |||
| </div> | |||
| <div class="ballot-section"> | |||
| <h4 class="section-heading">Candidate</h4> | |||
| @@ -16,17 +16,17 @@ if (!empty($_POST['voter']) && ((int) $_POST['voter']) == $_POST['voter']) { | |||
| $result = $db->query("update members set checkedin=true where voting_id=$voter"); | |||
| } | |||
| $header = new Header("2021 Michigan Flyers Election : Poll Worker"); | |||
| $header = new Header("2022 Michigan Flyers Election : Poll Worker"); | |||
| $header->addStyle("/styles/style.css"); | |||
| $header->addStyle("/styles/admin.css"); | |||
| $header->addStyle("/styles/vote.css"); | |||
| $header->addScript("/js/jquery-1.11.3.min.js"); | |||
| $header->addScript("/js/admin-search.js"); | |||
| $header->setAttribute('title', 'Michigan Flyers'); | |||
| $header->setAttribute('tagline', '2021 Election Administration'); | |||
| $header->setAttribute('tagline', '2022 Election Administration'); | |||
| $header->output(); | |||
| $checkedin = $db->fetchAssoc('select name, username, voting_id, NULL as `proxy` from members where checkedin=true UNION select voter.name, voter.username, voter.voting_id, members.voting_id as `proxy` from members left join proxy on (proxy.delegate_id=members.voting_id) left join members as `voter` on (voter.voting_id=proxy.voting_id) where members.checkedin = true'); | |||
| $checkedin = $db->fetchAssoc('select name, username, voting_id, NULL as `proxy` from members where checkedin=true UNION select voter.name, voter.username, voter.voting_id, members.voting_id as `proxy` from members inner join proxy on (proxy.delegate_id=members.voting_id) left join members as `voter` on (voter.voting_id=proxy.voting_id) where members.checkedin = true'); | |||
| $members = $db->fetchRow('select count(*) as `count` from members where voting_id is not null'); | |||
| $count = $members['count']; | |||
| @@ -78,4 +78,4 @@ class DBHandler{ | |||
| } | |||
| } | |||
| $db = new DBHandler('localhost', '2021mfelection', 'SHa9SGdAlNmafLvJSWjZ', '2021mfelection'); | |||
| $db = new DBHandler('localhost', '2022mfelection', '<password>', '2022mfelection'); | |||
| @@ -60,11 +60,17 @@ class User{ | |||
| // Get voter ID | |||
| $result = $db->fetchRow('select members.voting_id from members left join proxy on (members.voting_id=proxy.voting_id) where proxy.delegate_id is null and skymanager_id=' . ((int) $this->uid)); | |||
| $admincheck = $db->fetchRow('select members.pollworker from members where skymanager_id=' . ((int) $this->uid)); | |||
| if ($result) | |||
| $this->voterId = $result['voting_id']; | |||
| else | |||
| $this->voterId = null; | |||
| if ($admincheck) | |||
| $this->role = $admincheck['pollworker']; | |||
| else | |||
| $this->role = 0; | |||
| return true; | |||
| } | |||
| @@ -93,7 +99,7 @@ class User{ | |||
| } | |||
| public function getRole(){ | |||
| return $this->username === 'tyzoid' ? 'admin' : 'voter'; | |||
| return $this->role ? 'admin' : 'voter'; | |||
| //return $this->role; | |||
| } | |||
| @@ -11,12 +11,12 @@ if (!$user->voterId()) { | |||
| die(); | |||
| } | |||
| $header = new Header("2021 Michigan Flyers Election"); | |||
| $header = new Header("2022 Michigan Flyers Election"); | |||
| $header->addStyle("/styles/style.css"); | |||
| $header->addScript("/js/jquery-1.11.3.min.js"); | |||
| $header->addScript("/js/search.js"); | |||
| $header->setAttribute('title', 'Michigan Flyers'); | |||
| $header->setAttribute('tagline', '2021 Online Ballot'); | |||
| $header->setAttribute('tagline', '2022 Online Ballot'); | |||
| $header->output(); | |||
| $candidates = $db->fetchAssoc('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where voting_id is not null'); | |||
| @@ -27,14 +27,17 @@ foreach ($votes as &$vote) { | |||
| } | |||
| unset($vote); | |||
| $president_voted = in_array("PRESIDENT", $votes); | |||
| $vicepresident_voted = in_array("VICEPRESIDENT", $votes); | |||
| $secretary_voted = in_array("SECRETARY", $votes); | |||
| $director_voted = in_array("DIRECTOR", $votes); | |||
| $president_disabled = $president_voted; | |||
| $director_disabled = $director_voted || !$president_voted; | |||
| $vicepresident_disabled = $vicepresident_voted; | |||
| $secretary_disabled = $secretary_voted || !$vicepresident_voted; | |||
| $director_disabled = $director_voted || !$secretary_voted || !$vicepresident_voted; | |||
| $president_disabled_reason = $president_voted ? "You have already voted for President." : ""; | |||
| $director_disabled_reason = $director_disabled ? ($director_voted ? "You have already voted for Director." : "You must vote for President first.") : ""; | |||
| $vicepresident_disabled_reason = $vicepresident_voted ? "You have already voted for Vice President." : ""; | |||
| $secretary_disabled_reason = $secretary_disabled ? ($secretary_voted ? "You have already voted for Secretary." : "You must vote for Vice President first.") : ""; | |||
| $director_disabled_reason = $director_disabled ? ($director_voted ? "You have already voted for Director." : "You must vote for Vice President and Secretary first.") : ""; | |||
| ?> | |||
| <script type="text/javascript"> | |||
| var candidates = <?= json_encode($candidates); ?>; | |||
| @@ -43,16 +46,24 @@ var candidates = <?= json_encode($candidates); ?>; | |||
| <div class="form-row"> | |||
| <div class="selector"> | |||
| <label class="radio"> | |||
| <input type="radio" id="vote-president" name="ballot" | |||
| value="PRESIDENT" <?= $president_disabled ? "disabled" : "checked"; ?> /> | |||
| <span class="radio-button-label">President</span> | |||
| <?php if ($president_disabled_reason): ?> | |||
| <div class="hover-tooltip"><?= $president_disabled_reason; ?></div> | |||
| <input type="radio" id="vote-vicepresident" name="ballot" | |||
| value="VICEPRESIDENT" <?= $vicepresident_disabled ? "disabled" : "checked"; ?> /> | |||
| <span class="radio-button-label">Vice President</span> | |||
| <?php if ($vicepresident_disabled_reason): ?> | |||
| <div class="hover-tooltip"><?= $vicepresident_disabled_reason; ?></div> | |||
| <?php endif; ?> | |||
| </label> | |||
| <label class="radio"> | |||
| <input type="radio" id="vote-director" name="ballot" | |||
| value="DIRECTOR" <?= $director_disabled ? "disabled" : ($president_disabled ? "checked" : ""); ?> /> | |||
| value="SECRETARY" <?= $secretary_disabled ? "disabled" : ($vicepresident_disabled ? "checked" : ""); ?> /> | |||
| <span class="radio-button-label">Secretary</span> | |||
| <?php if ($secretary_disabled_reason): ?> | |||
| <div class="hover-tooltip"><?= $secretary_disabled_reason; ?></div> | |||
| <?php endif; ?> | |||
| </label> | |||
| <label class="radio"> | |||
| <input type="radio" id="vote-director" name="ballot" | |||
| value="DIRECTOR" <?= $director_disabled ? "disabled" : ($vicepresident_disabled && $secretary_disabled ? "checked" : ""); ?> /> | |||
| <span class="radio-button-label">Director-At-Large</span> | |||
| <?php if ($director_disabled_reason): ?> | |||
| <div class="hover-tooltip"><?= $director_disabled_reason; ?></div> | |||
| @@ -25,7 +25,7 @@ if (isset($_GET['denied'])) { | |||
| $header = new Header("Login Required"); | |||
| $header->addStyle("/styles/style.css"); | |||
| $header->setAttribute('title', 'Michigan Flyers'); | |||
| $header->setAttribute('tagline', '2021 Online Ballot'); | |||
| $header->setAttribute('tagline', '2022 Online Ballot'); | |||
| $header->output(); | |||
| ?> | |||
| <h3 id="login-help">Sign in with your Skymanager Account</h3> | |||
| @@ -15,19 +15,19 @@ $candidate_selected = (int) $_POST['candidate']; | |||
| $ballot = $_POST['ballot']; | |||
| if ($candidate_selected != $_POST['candidate']) $error = "An eccor occurred while processing your ballot. Please retry."; | |||
| if ($ballot !== "PRESIDENT" && $ballot !== "DIRECTOR") $error = "An eccor occurred while processing your ballot. Please retry."; | |||
| if ($ballot !== "VICEPRESIDENT" && $ballot !== "SECRETARY" && $ballot !== "DIRECTOR") $error = "An eccor occurred while processing your ballot. Please retry."; | |||
| if (!$error) { | |||
| //$result = $db->query("INSERT INTO votes (candidate_id, position, member_id) values ($candidate_selected, \"$ballot\", {$user->voterId()})"); | |||
| $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()}"); | |||
| $candidate = $db->fetchRow('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where skymanager_id=' . $candidate_selected); | |||
| if ($result) { | |||
| $to = 'mf2021elec@gmail.com'; | |||
| $to = 'mf2022elec@gmail.com'; | |||
| $from = 'noreply@tyzoid.com'; | |||
| $subject = "Ballot Submitted ({$user->voterId()} -> {$candidate['skymanager_id']})"; | |||
| $headers = | |||
| "From: {$from}\r\n" . | |||
| "Message-ID: 2021election-voter-{$user->voterId()}-{$ballot}-" . mt_rand() . "@tyzoid.com\r\n"; | |||
| "Message-ID: 2022election-voter-{$user->voterId()}-{$ballot}-" . mt_rand() . "@tyzoid.com\r\n"; | |||
| $body = "Position: " . ucwords(strtolower($ballot)) . "\r\n" . | |||
| "Candidate: {$candidate['name']} (ID #{$candidate['skymanager_id']})\r\n" . | |||
| @@ -59,18 +59,24 @@ foreach ($votes as &$vote) { | |||
| } | |||
| unset($vote); | |||
| $positions = [ | |||
| 'VICEPRESIDENT' => 'Vice President', | |||
| 'SECRETARY' => 'Secretary', | |||
| 'DIRECTOR' => 'Director' | |||
| ]; | |||
| $voteFor = null; | |||
| if (count($votes) == 1) { | |||
| $voteFor = $votes[0] == "PRESIDENT" ? "Director" : "President"; | |||
| if (count($votes) < count($positions)) { | |||
| $voteFor = array_values($positions)[count($votes)]; | |||
| } | |||
| $header = new Header("2021 Michigan Flyers Election"); | |||
| $header = new Header("2022 Michigan Flyers Election"); | |||
| $header->addStyle("/styles/style.css"); | |||
| $header->addStyle("/styles/vote.css"); | |||
| $header->addScript("/js/jquery-1.11.3.min.js"); | |||
| $header->addScript("/js/search.js"); | |||
| $header->setAttribute('title', 'Michigan Flyers'); | |||
| $header->setAttribute('tagline', '2021 Online Ballot'); | |||
| $header->setAttribute('tagline', '2022 Online Ballot'); | |||
| $header->output(); | |||
| ?> | |||
| <div id="vote-result"> | |||
| @@ -86,8 +92,8 @@ $header->output(); | |||
| <?php if ($result): ?> | |||
| <div id="ballot"> | |||
| <div class="ballot-section"> | |||
| <h4 class="section-heading">Position</h4> | |||
| <h2 class="ballot-position"><?= ucwords(strtolower($ballot)); ?></h2> | |||
| <h4 class="section-heading">Vice Position</h4> | |||
| <h2 class="ballot-position"><?= $positions[$ballot]; ?></h2> | |||
| </div> | |||
| <div class="ballot-section"> | |||
| <h4 class="section-heading">Candidate</h4> | |||