| $result = $db->query("update members set checkedin=true where voting_id=$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/style.css"); | ||||
| $header->addStyle("/styles/admin.css"); | $header->addStyle("/styles/admin.css"); | ||||
| $header->addStyle("/styles/vote.css"); | $header->addStyle("/styles/vote.css"); | ||||
| $header->addScript("/js/jquery-1.11.3.min.js"); | $header->addScript("/js/jquery-1.11.3.min.js"); | ||||
| $header->addScript("/js/admin-search.js"); | $header->addScript("/js/admin-search.js"); | ||||
| $header->setAttribute('title', 'Michigan Flyers'); | $header->setAttribute('title', 'Michigan Flyers'); | ||||
| $header->setAttribute('tagline', '2021 Election Administration'); | |||||
| $header->setAttribute('tagline', '2022 Election Administration'); | |||||
| $header->output(); | $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'); | $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'); |
| if ($candidate_selected != $_POST['candidate']) $error = "An eccor occurred while processing your ballot. Please retry."; | 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 ($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)) { | 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"); | $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"); | ||||
| } | } | ||||
| } | } | ||||
| $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/style.css"); | ||||
| $header->addStyle("/styles/admin.css"); | $header->addStyle("/styles/admin.css"); | ||||
| $header->addStyle("/styles/vote.css"); | $header->addStyle("/styles/vote.css"); | ||||
| $header->addScript("/js/search.js"); | $header->addScript("/js/search.js"); | ||||
| $header->addScript("/js/admin-search.js"); | $header->addScript("/js/admin-search.js"); | ||||
| $header->setAttribute('title', 'Michigan Flyers'); | $header->setAttribute('title', 'Michigan Flyers'); | ||||
| $header->setAttribute('tagline', '2021 Election Administration'); | |||||
| $header->setAttribute('tagline', '2022 Election Administration'); | |||||
| $header->output(); | $header->output(); | ||||
| $candidates = $db->fetchAssoc('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where voting_id is not null'); | $candidates = $db->fetchAssoc('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where voting_id is not null'); | ||||
| <div class="form-row"> | <div class="form-row"> | ||||
| <div class="selector"> | <div class="selector"> | ||||
| <label class="radio"> | <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> | ||||
| <label class="radio"> | <label class="radio"> | ||||
| <input type="radio" id="vote-director" name="ballot" value="DIRECTOR" /> | <input type="radio" id="vote-director" name="ballot" value="DIRECTOR" /> | ||||
| <div id="ballot"> | <div id="ballot"> | ||||
| <div class="ballot-section"> | <div class="ballot-section"> | ||||
| <h4 class="section-heading">Position</h4> | <h4 class="section-heading">Position</h4> | ||||
| <h2 class="ballot-position"><?= ucwords(strtolower($ballot)); ?></h2> | |||||
| <h2 class="ballot-position"><?= $positions[$ballot]; ?></h2> | |||||
| </div> | </div> | ||||
| <div class="ballot-section"> | <div class="ballot-section"> | ||||
| <h4 class="section-heading">Candidate</h4> | <h4 class="section-heading">Candidate</h4> |
| $result = $db->query("update members set checkedin=true where voting_id=$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/style.css"); | ||||
| $header->addStyle("/styles/admin.css"); | $header->addStyle("/styles/admin.css"); | ||||
| $header->addStyle("/styles/vote.css"); | $header->addStyle("/styles/vote.css"); | ||||
| $header->addScript("/js/jquery-1.11.3.min.js"); | $header->addScript("/js/jquery-1.11.3.min.js"); | ||||
| $header->addScript("/js/admin-search.js"); | $header->addScript("/js/admin-search.js"); | ||||
| $header->setAttribute('title', 'Michigan Flyers'); | $header->setAttribute('title', 'Michigan Flyers'); | ||||
| $header->setAttribute('tagline', '2021 Election Administration'); | |||||
| $header->setAttribute('tagline', '2022 Election Administration'); | |||||
| $header->output(); | $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'); | $members = $db->fetchRow('select count(*) as `count` from members where voting_id is not null'); | ||||
| $count = $members['count']; | $count = $members['count']; | ||||
| } | } | ||||
| } | } | ||||
| $db = new DBHandler('localhost', '2021mfelection', 'SHa9SGdAlNmafLvJSWjZ', '2021mfelection'); | |||||
| $db = new DBHandler('localhost', '2022mfelection', '<password>', '2022mfelection'); |
| // Get voter ID | // 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)); | $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) | if ($result) | ||||
| $this->voterId = $result['voting_id']; | $this->voterId = $result['voting_id']; | ||||
| else | else | ||||
| $this->voterId = null; | $this->voterId = null; | ||||
| if ($admincheck) | |||||
| $this->role = $admincheck['pollworker']; | |||||
| else | |||||
| $this->role = 0; | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| public function getRole(){ | public function getRole(){ | ||||
| return $this->username === 'tyzoid' ? 'admin' : 'voter'; | |||||
| return $this->role ? 'admin' : 'voter'; | |||||
| //return $this->role; | //return $this->role; | ||||
| } | } | ||||
| die(); | die(); | ||||
| } | } | ||||
| $header = new Header("2021 Michigan Flyers Election"); | |||||
| $header = new Header("2022 Michigan Flyers Election"); | |||||
| $header->addStyle("/styles/style.css"); | $header->addStyle("/styles/style.css"); | ||||
| $header->addScript("/js/jquery-1.11.3.min.js"); | $header->addScript("/js/jquery-1.11.3.min.js"); | ||||
| $header->addScript("/js/search.js"); | $header->addScript("/js/search.js"); | ||||
| $header->setAttribute('title', 'Michigan Flyers'); | $header->setAttribute('title', 'Michigan Flyers'); | ||||
| $header->setAttribute('tagline', '2021 Online Ballot'); | |||||
| $header->setAttribute('tagline', '2022 Online Ballot'); | |||||
| $header->output(); | $header->output(); | ||||
| $candidates = $db->fetchAssoc('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where voting_id is not null'); | $candidates = $db->fetchAssoc('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where voting_id is not null'); | ||||
| } | } | ||||
| unset($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); | $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"> | <script type="text/javascript"> | ||||
| var candidates = <?= json_encode($candidates); ?>; | var candidates = <?= json_encode($candidates); ?>; | ||||
| <div class="form-row"> | <div class="form-row"> | ||||
| <div class="selector"> | <div class="selector"> | ||||
| <label class="radio"> | <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; ?> | <?php endif; ?> | ||||
| </label> | </label> | ||||
| <label class="radio"> | <label class="radio"> | ||||
| <input type="radio" id="vote-director" name="ballot" | <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> | <span class="radio-button-label">Director-At-Large</span> | ||||
| <?php if ($director_disabled_reason): ?> | <?php if ($director_disabled_reason): ?> | ||||
| <div class="hover-tooltip"><?= $director_disabled_reason; ?></div> | <div class="hover-tooltip"><?= $director_disabled_reason; ?></div> |
| $header = new Header("Login Required"); | $header = new Header("Login Required"); | ||||
| $header->addStyle("/styles/style.css"); | $header->addStyle("/styles/style.css"); | ||||
| $header->setAttribute('title', 'Michigan Flyers'); | $header->setAttribute('title', 'Michigan Flyers'); | ||||
| $header->setAttribute('tagline', '2021 Online Ballot'); | |||||
| $header->setAttribute('tagline', '2022 Online Ballot'); | |||||
| $header->output(); | $header->output(); | ||||
| ?> | ?> | ||||
| <h3 id="login-help">Sign in with your Skymanager Account</h3> | <h3 id="login-help">Sign in with your Skymanager Account</h3> |
| $ballot = $_POST['ballot']; | $ballot = $_POST['ballot']; | ||||
| if ($candidate_selected != $_POST['candidate']) $error = "An eccor occurred while processing your ballot. Please retry."; | 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) { | 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) 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()}"); | $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); | $candidate = $db->fetchRow('select skymanager_id, name, username, md5(coalesce(email, "")) as `gravatar_hash` from members where skymanager_id=' . $candidate_selected); | ||||
| if ($result) { | if ($result) { | ||||
| $to = 'mf2021elec@gmail.com'; | |||||
| $to = 'mf2022elec@gmail.com'; | |||||
| $from = 'noreply@tyzoid.com'; | $from = 'noreply@tyzoid.com'; | ||||
| $subject = "Ballot Submitted ({$user->voterId()} -> {$candidate['skymanager_id']})"; | $subject = "Ballot Submitted ({$user->voterId()} -> {$candidate['skymanager_id']})"; | ||||
| $headers = | $headers = | ||||
| "From: {$from}\r\n" . | "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" . | $body = "Position: " . ucwords(strtolower($ballot)) . "\r\n" . | ||||
| "Candidate: {$candidate['name']} (ID #{$candidate['skymanager_id']})\r\n" . | "Candidate: {$candidate['name']} (ID #{$candidate['skymanager_id']})\r\n" . | ||||
| } | } | ||||
| unset($vote); | unset($vote); | ||||
| $positions = [ | |||||
| 'VICEPRESIDENT' => 'Vice President', | |||||
| 'SECRETARY' => 'Secretary', | |||||
| 'DIRECTOR' => 'Director' | |||||
| ]; | |||||
| $voteFor = null; | $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/style.css"); | ||||
| $header->addStyle("/styles/vote.css"); | $header->addStyle("/styles/vote.css"); | ||||
| $header->addScript("/js/jquery-1.11.3.min.js"); | $header->addScript("/js/jquery-1.11.3.min.js"); | ||||
| $header->addScript("/js/search.js"); | $header->addScript("/js/search.js"); | ||||
| $header->setAttribute('title', 'Michigan Flyers'); | $header->setAttribute('title', 'Michigan Flyers'); | ||||
| $header->setAttribute('tagline', '2021 Online Ballot'); | |||||
| $header->setAttribute('tagline', '2022 Online Ballot'); | |||||
| $header->output(); | $header->output(); | ||||
| ?> | ?> | ||||
| <div id="vote-result"> | <div id="vote-result"> | ||||
| <?php if ($result): ?> | <?php if ($result): ?> | ||||
| <div id="ballot"> | <div id="ballot"> | ||||
| <div class="ballot-section"> | <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> | ||||
| <div class="ballot-section"> | <div class="ballot-section"> | ||||
| <h4 class="section-heading">Candidate</h4> | <h4 class="section-heading">Candidate</h4> |