Example #1
0
 //collect pin
 $election_pin = $_POST['pin'];
 //get the election corresponding to the pin
 $election = getAllMembers("election", ["*"], ["election_pin", "=", $election_pin]);
 if (count($election) != 0) {
     $election = $election[0];
     //get openness
     $openness = substr($election["privacy"], 1, 1);
     //get user_id
     $user_id = user_id($myemail);
     //check if user is in anyway attached to the election
     if (concluded($election["election_end_date"], $election["election_time_to"], 0)) {
         echo 'This election has been concluded.';
     } elseif ($openness == 1 && concluded($election["election_start_date"], $election["election_time_from"], 0)) {
         echo 'Voting for this election has commenced.';
     } elseif ($openness == 1 && concluded($election["election_start_date"], $election["election_time_from"], 3600)) {
         echo 'Voting for this election will commence in less an hour.Therefore your request cannot be processed.';
     } elseif (attached("request", $user_id, $election["election_id"]) === "request") {
         echo 'You have already sent a request to the admin of this election.Just hold on till your request is granted.Thank you.';
     } elseif (attached("election", $user_id, $election["election_id"]) == "election") {
         echo 'You are the admin of this election.You cannot send a request to yourself.';
     } elseif (attached("invites", $user_id, $election["election_id"]) === "invites") {
         echo 'You are already invited for this election.';
     } elseif (attached("joined", $user_id, $election["election_id"]) === "joined") {
         echo '<span >You have joined this election.There is no need to send request.Thank you.</span>';
     } else {
         #if open,add to joined. if closed,add to request
         $election_id = $election["election_id"];
         if ($openness == 1) {
             $query = "INSERT INTO request (user_id,election_id) VALUES ('{$user_id}','{$election_id}')";
             $success_message = '<p style="color: #008000">Request has been passed  to the admin successfully.</p>';
Example #2
0
            }
        }
        // $users[$row]['picture_name'] = ($user['picture_name'] && file_exists(IMAGE_PATH . $user['picture_name'])) ? IMAGE_PATH . $user['picture_name'] : DEFAULT_IMG_PATH . 'voting1.jpg';
        $i++;
    }
}
$time_query = "SELECT election_start_date, election_time_from FROM election WHERE election_id = :id";
$smd = $connection1->prepare($time_query);
$smd->bindValue('id', $election_id);
$smd->execute();
$result = $smd->fetchAll(PDO::FETCH_ASSOC);
$election_start = $result[0]['election_start_date'] . ' ' . $result[0]['election_time_from'];
$date_diff = strtotime($election_start) - strtotime("now");
$privacy_status = getAllMembers('election', array('privacy'), array('election_id', '=', $election_id), 1);
$success_message = '';
if (!concluded($result[0]["election_start_date"], $result[0]["election_time_from"], 3600)) {
    $display_style = 'block';
    $display_cell = 'table-cell';
} else {
    $display_style = 'none';
    $display_cell = 'none';
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //get needed election details in case you need to send mail
    $admin_query = "SELECT\r\n                          election.election_name,users.fname AS admin_fname,users.lname AS admin_lname\r\n                    FROM\r\n                          election\r\n                    LEFT JOIN\r\n                          users\r\n                    ON\r\n                          election.user_id = users.user_id\r\n                    WHERE\r\n                          election_id = {$election_id}";
    $admin = $connection1->prepare($admin_query);
    $admin->execute();
    $admin->setFetchMode(PDO::FETCH_ASSOC);
    $admin = $admin->fetchAll()[0];
    $election_name = $admin['election_name'];
    $sender_name = strtoupper($admin['admin_fname']) . " " . $admin['admin_lname'];
$result5 = $sql6->fetchAll();
$election_start = $result5[0]["election_start_date"];
$sql2 = $connection1->prepare("SELECT post_id, post, post_key FROM  posts WHERE election_id='{$contestant_election_id}'");
$sql2->execute();
$result2 = $sql2->setFetchMode(PDO::FETCH_ASSOC);
$result2 = $sql2->fetchAll();
//Declaring variables to be used
$allPost = $nick_name = $no_manifesto_points = $contestant_post = $contestant_pin = $errors = $contestant_post_temp = $contestant_pin_temp = "";
$uploadErr = $nick_nameErr = $contestant_postErr = $contestant_pinErr = $no_manifesto_pointsErr = $uploadCitationErr = "";
$success = $successC = $contestant_picture_name = $contestant_citation_name = $imageFileType = $citationFileType = "";
$last_contestant_id = 0;
$last_manifesto_id = 0;
$registration_message = "";
if (concluded($result5[0]['election_end_date'], $result5[0]['election_time_to'], 0)) {
    $registration_message = "This election has already been concluded therefore your request cannot be processed.";
} elseif (concluded($election_start, $result5[0]['election_time_from'], 3600)) {
    $registration_message = "Contestant registration has closed for this election.";
} else {
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        //Nick name validation
        if (empty($_POST["nick_name"])) {
            $nick_nameErr = "Nick name(political name) cannot be empty";
        } elseif (!preg_match("/^[a-zA-Z0-9 ]*\$/", $_POST["nick_name"])) {
            $nick_nameErr = "Nick name with only letters and numbers are allowed";
        } else {
            $nick_name = trim($_POST["nick_name"]);
        }
        //contestants post and pin validation
        if (empty($_POST["contestant_post"])) {
            $contestant_postErr = "The contestants post field cannot be empty";
        } else {
Example #4
0
include_once '../php/connection.php';
include_once '../php/function.php';
include_once '../php/database.php';
//this script should execute at every hour
date_default_timezone_set("Africa/Lagos");
$to_remind = $remind_ready = [];
$remind_ready_num = 0;
$main_body = "We will like to remind you that, at <a href='http://evoting.oauife.edu.ng'>OAU E-voting system</a>, it\n                is our responsibility to provide a reliable and trustworthy one-man-one-vote online voting system for\n                you always. Thank you. <a href='http://evoting.oauife.edu.ng'>Login into your account.</a>";
//get all elections yet to receive reminder
$to_remind = getAllMembers("election", ["*"], ["reminder_sent", "=", 0]);
$to_remind_num = count($to_remind);
//extract those that will start in at least an hour time and yet to start (2 step authentication which may not be necessary)
for ($i = 0; $i < $to_remind_num; $i++) {
    $start_date = $to_remind[$i]["election_start_date"];
    $start_time = $to_remind[$i]["election_time_from"];
    if (concluded($start_date, $start_time, 3600) && !concluded($start_date, $start_time, 0)) {
        //send reminder to the admin
        $admin_id = $to_remind[$i]["user_id"];
        $subject = "Remember to cast your vote in " . $to_remind[$i]["election_name"] . ".";
        $admin_details = getAllMembers("users", ["*"], ["user_id", "=", $admin_id])[0];
        $recipient_name = strtoupper($admin_details["fname"]) . " " . $admin_details["lname"];
        $body = "Hello " . $admin_details["username"] . ".<br>\n                This is to bring to your notice that the aforementioned election will commence in less than an hour from\n                the time this remainder was received by you. You are being reminded of this as regards to the fact that\n                you are the administrator of this election.<br><br>" . $main_body;
        $recipient_address = $admin_details["email"];
        sendEmail($recipient_address, $recipient_name, $subject, $body);
        //check if there is at least a voter in the election
        $id = $to_remind[$i]["election_id"];
        $has_voter = getAllMembers("joined", ["*"], ["election_id", "=", $id]);
        if (count($has_voter) > 0) {
            //get all the ready election into an array
            $remind_ready[$remind_ready_num] = $to_remind[$i];
            $remind_ready_num++;
//extract all fully public elections from $public elections
for ($current = 0; $current < count($public_elections); $current++) {
    $privacy = substr($public_elections[$current]["privacy"], 1, 1);
    $totally = publicDisplayable($user_id, $public_elections[$current]['election_id']);
    if ($totally !== 'partially') {
        if ($privacy == 1) {
            #election is closed
            $lag = 3900;
            if (!concluded($public_elections[$current]["election_start_date"], $public_elections[$current]["election_time_from"], $lag)) {
                $fully_public[$fully] = $public_elections[$current];
                $fully++;
            }
        } else {
            #election is open
            $lag = -300;
            if (!concluded($public_elections[$current]["election_end_date"], $public_elections[$current]["election_time_to"], $lag)) {
                $fully_public[$fully] = $public_elections[$current];
                $fully++;
            }
        }
    }
}
//check if there is at least one fully public election left
if (count($fully_public) > 0) {
    $public_elections_displayed = "<table id='table_1' class='table table-striped table-bordered' cellspacing='0'>\n                                <thead class='success'>\n                                    <tr>\n                                        <th>Name</th>\n                                        <th>Start Date</th>\n                                        <th>Start Time</th>\n                                        <th>End Date</th>\n                                        <th>End Time</th>\n                                        <th>Pin</th>\n                                        <th></th>\n                                    </tr>\n                                </thead><tbody>";
    $public_index = array('election_name', 'election_start_date', 'election_time_from', 'election_end_date', 'election_time_to', 'election_pin');
    $public_index_number = count($public_index);
    for ($move = 0; $move < count($fully_public); $move++) {
        $public_elections_displayed .= "<tr>";
        for ($index = 0; $index < $public_index_number; $index++) {
            if (count(explode("_", $public_index[$index])) === 3) {
     if ($connection1->query($sql)) {
         //Invite the signed up user for an election he has been invited
         $output = "<span style='color: #008000'>Account created successfully. Check Your email For verification.</span>";
         $electionId = $election_start = $election_time = $invite_message = "";
         $invite_query = $connection1->prepare("SELECT * FROM ignored WHERE email='{$email}'");
         $invite_query->execute();
         $invite_result = $invite_query->setFetchMode(PDO::FETCH_ASSOC);
         $invite_result = $invite_query->fetchAll();
         if (!empty($invite_result)) {
             for ($i = 0; $i < count($invite_result); $i++) {
                 $electionId = $invite_result[$i]['election_id'];
                 $electionDetails = getElectionDetails($electionId);
                 $election_start = $electionDetails[0]['election_start_date'];
                 $election_time = $electionDetails[0]['election_time_from'];
                 $invite_date = $invite_result[$i]["ignored_date"];
                 if (!concluded($election_start, $election_time, 7200)) {
                     $insertQuery = "INSERT INTO invites (user_id, election_id, invite_date) VALUES ('{$last_id}', '{$electionId}', '{$invite_date}')";
                     if ($connection1->query($insertQuery)) {
                         $deleteQuery = "DELETE FROM ignored WHERE email='{$email}' AND election_id='{$electionId}'";
                         $connection1->query($deleteQuery);
                     }
                 }
             }
         }
         //                    header("Location:../html/index.php?key=".$output);
         $fname = $lname = $email = $username = $phone = $password1 = $password2 = $sex = "";
     } else {
         $mainError = "Account creation unsuccessful";
         /*header("Location:../html/signup.php#register");*/
     }
 } else {
Example #7
0
include_once '../php/function.php';
include_once '../php/database.php';
date_default_timezone_set("Africa/Lagos");
//this script should execute every 2 hours
$result_send = $result_ready = [];
$result_ready_num = 0;
//get all elections yet to receive result as mail
$result_send = getAllMembers("election", ["*"], ["result_mail_sent", "=", 0]);
$result_send_num = count($result_send);
//extract the ones that are ready to be mailed
for ($i = 0; $i < $result_send_num; $i++) {
    $end_date = $result_send[$i]["election_end_date"];
    $end_time = $result_send[$i]["election_time_to"];
    $election_id = $result_send[$i]["election_id"];
    $admin_id = $result_send[$i]["user_id"];
    if (concluded($end_date, $end_time, 0) && !concluded($end_date, $end_time, 7200)) {
        //send result to admin
        $admin_details = getAllMembers("users", ["*"], ["user_id", "=", $admin_id])[0];
        $recipient_name = strtoupper($admin_details["fname"]) . " " . $admin_details["lname"];
        $recipient_address = $admin_details["email"];
        $subject = "Election Result - " . $result_send[$i]["election_name"] . ".";
        $body = "Hello " . $admin_details["username"] . ".<br> Actually the mail body is yet to be composed.Thanks.";
        //sent the mail
        //check if there exists at least a voter in the election
        $has_voter = getAllMembers("joined", ["*"], ["election_id", "=", $election_id]);
        if (count($has_voter) > 0) {
            //get the election into one place
            $result_ready[$result_ready_num] = $result_send[$i];
            $result_ready_num++;
        } else {
            //set result_mail_sent to 1
';">
                                          </div>
                                        </div>
                                    </form>
                            </div>
                        </fieldset>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
//lets use php to determine if the vote_link should be active
<?php 
$activate_vote = 0;
if (concluded($result5[0]["election_start_date"], $result5[0]["election_time_from"], 0) && !concluded($result5[0]["election_end_date"], $result5[0]["election_time_to"], 0) && hasvoted($user_id, $contestant_election_id) == 0) {
    $activate_vote = 1;
}
?>
//lets do the script
<script type="text/javascript">
    var activate_vote = 0;
     activate_vote =<?php 
echo $activate_vote;
?>
 ;
    if( activate_vote == 1 )
    {
        var vote_link = $('#vote_link');
        vote_link.attr({'href':'voting.php'});
    }
Example #9
0
<?php

include 'connection.php';
include_once 'database.php';
include_once 'function.php';
//echo base64_decode("Ni");
//function subme($a, $b)
//{
//    return $a-$b;
//}
$election = getElectionDetails(1)[0];
if (concluded($election["election_end_date"], $election["election_time_to"], 0) && $election["result_mail_sent"] == 0) {
    //make all variable declaration
    $all_member = $members = $participants = [];
    //all member needs to be mailed
    $all_member = getAllMembers("joined", ["user_id"], ["election_id", "=", $election["election_id"]]);
    //add admin to member
    array_push($all_member, ["user_id" => $election["user_id"]]);
    //reduce the array to a one dimensional array
    for ($head = 0; $head < count($all_member); $head++) {
        array_push($members, $all_member[$head]["user_id"]);
    }
    //shuffle array for the case when the admin is also a voter
    $participants = array_unique($members);
    print_r($participants);
    //    echo("concluded");
} else {
    echo "on point";
}
    array_push($old_posts, ucwords($post_pin[$i]["post"]));
    $post_id = $post_pin[$i]["post_id"];
    $post_string .= $post_pin[$i]["post"] . '<br>';
    $pin_string .= $post_pin[$i]["post_key"] . '<br>';
}
$post_string .= '</div>';
$pin_string .= '</div>';
//get current date and current time
$now_date = convert_date(date("Y-m-d"));
$now_time = convert_date(date("H:i:s"));
//check if election has not started
if (concluded($this_election["election_end_date"], $this_election["election_time_to"], 0)) {
    $messaging = "This election has already been concluded. No changes will thus be processed.";
} elseif (concluded($this_election["election_start_date"], $this_election["election_time_from"], 0)) {
    $messaging = "Voting has commenced. Your update cannot be processed.";
} elseif (concluded($this_election["election_start_date"], $this_election["election_time_from"], 7200)) {
    $messaging = "Voting will start in less than 2hours. Your update cannot be processed.";
}
//election status
$status = $this_election["privacy"];
$privacy = substr($status, 0, 1);
$openness = substr($status, 1, 1);
$display = $this_election["result_display"];
//get string to display status changing woreva
$status_string = '<div class="row form-group" >
                    <div class="col-xs-12 col-md-12">
                    <label>Do you want your election to be visible to all users?</label> <br>
                    <input type="radio" name="privacy" value="1" required';
if ($privacy == 1) {
    $status_string .= ' checked';
}
<?php

//get user_id and election_id
require_once "function.php";
include_once 'connection.php';
include_once 'database.php';
$id = $_POST["id"];
$id = explode(" ", $id)[1];
$sender_id = explode("_", $id)[0];
$election_id = explode("_", $id)[1];
//check if voting has not started
$election = getElectionDetails($election_id)[0];
$starting_date = $election["election_start_date"];
$starting_time = $election["election_time_from"];
if (!concluded($starting_date, $starting_time, 0) && isset($_POST)) {
    //get needed election details in case you need to send mail
    $admin_query = "SELECT\n                          election.election_name,users.fname AS admin_fname,users.lname AS admin_lname\n                FROM\n                          election\n                LEFT JOIN\n                          users\n                ON\n                          election.user_id = users.user_id\n                WHERE\n                          election_id = {$election_id}";
    $admin = $connection1->prepare($admin_query);
    $admin->execute();
    $admin->setFetchMode(PDO::FETCH_ASSOC);
    $admin = $admin->fetchAll()[0];
    $election_name = $admin['election_name'];
    $sender_name = strtoupper($admin['admin_fname']) . " " . $admin['admin_lname'];
    //get recipient
    $recipient = getAllMembers('users', ['*'], ['user_id', '=', $sender_id])[0];
    $recipient_address = $recipient['email'];
    $recipient_name = strtoupper($recipient['fname']) . " " . $recipient['lname'];
    $mail_subject = "Your request to join " . $election_name . " has been ";
    //delete request
    $delete_request_query = "DELETE FROM request WHERE user_id='{$sender_id}' AND election_id='{$election_id}'";
    if ($connection1->query($delete_request_query)) {
Example #12
0
for ($i = 0; $i < $no_of_manifesto_point; $i++) {
    $id = "\"dem{$i}\"";
    $edit_manifestos = "\"{$manifestos[$i]}\"";
    $edit_manifestos_nameatt = "\"manifesto{$i}\"";
    echo "<input type='text' name='manifesto" . $i . "' value='" . $manifestos[$i] . "' >";
}
?>

                                        </small>
                                    </div>
                                </div>
                               </div>

                            </div>
                            <?php 
if (!concluded($election_start, $election_start_time, 3600)) {
    echo '<div class="row">
                                        <div class="col-md-8" style="text-align: center;">
                                            <input class="btn btn-danger" value="Step Down" type="submit" name="delete">
                                            <button type="button" class="toggleEdit editField btn btn-primary">Edit</button>
                                            <input class="editField btn btn-primary hide" value="Save" type="submit" name="submit">
                                            <input class="toggleEdit editField btn btn-default hide" onclick="window.location = location.href;" value="Cancel" type="reset">
                                        </div>
                                    </div>';
}
?>
<!--                            <div class="row">-->
<!--                                <div class="col-md-8" style="text-align: center;">-->
<!--                                    <input class="btn btn-danger" value="Step Down" type="submit" name="delete">-->
<!--                                    <button type="button" class="toggleEdit editField btn btn-primary">Edit</button>-->
<!--                                    <input class="editField btn btn-primary hide" value="Save" type="submit" name="submit">-->