alert(\"Returned from Session Check\")";
if(isset($trace)) echo "
RETURNED FROM SESSION_CHECK";
$Logid = $_SESSION['Userid'] ;
$MemberNumber = $_SESSION['MemberNumber'];
if(isset($trace)) echo(" User is logged in as $Logid / Member# $MemberNumber. ");
// ########################## Catch the two Honorary members #####################
if (($Logid == "K3RF" or $Logid == "AA7BQ") ) {
echo"
Sorry, only current Full-Members may vote.
";
Exit;
}
// ###################################################################################
// ########################## Catch the two Honorary members #####################
// $trace = "y";
// $Maintenance = "ON";
/*
#############################################################
### Is TODAY before, during, or after election time #####
#############################################################
*/
date_default_timezone_set('America/Chicago'); //central time
$now = time();
// $now = strtotime('11:59:59pm 04/07/2023');
$start_date = strtotime('12:00:01am 04/06/2023');
$end_date = strtotime('11:59:59pm 04/15/2023');
if(isset($trace)) echo "Start is $start_date Now is $now End is $end_date";
if ($now < $start_date ) {
?>
The election period begins on April 6th.
The virtual voting booths are not open yet.
Getting default variables");
require_once("inc_prof_variables.php");
if(isset($trace)) echo(" Returned from inc_prof_variables.");
date_default_timezone_set('America/Chicago');
$today = date("D M j G:i:s T Y");
$Poll_Name="ElectionPoll";
$ID_Table = $Poll_Name."_ID_Tbl";
$VotesTable = $Poll_Name."_Votes_Tbl";
$logfile=$Poll_Name."_logfile.txt";
//$dbname="inc_".$Poll_Name."_DB.php";
if(isset($trace)) {
echo"Poll name is.... $Poll_Name ID_Table is .....$ID_Table VotesTable is ..$VotesTable Logfile is .....$logfile";
}
$question1="The President will preside over all RVRN Membership and Board meetings. The President will represent the RVRN at any public presence unless he/she delegates to another individual. All board members will keep the President apprised of their efforts and results in their area of responsibility.";
$candidateP1 = "N3YRZ - Michelle Sack";
$candidateP2 = "K4HM - Hank Montgomery";
$question2="The Vice President will work very closely with the President on a day-to-day basis to keep up to date on all affairs of the RVRN. The Vice President must be able to pick up the responsibility at any time the President is unavailable. ";
$candidateV1 = "W8TJT - Dwight Bonifield";
$candidateV2 = "W1IK - Jim Wickstrom";
$question3="The Secretary shall record the proceedings of all meetings of the Board of Directors. He/she shall promptly furnish copies of the minutes to the Board of Directors. ";
$candidateS1 = "KG4RMT - Selene Montgomery";
$candidateS2 = "Vacant";
$question4="The Treasurer is responsible for all financial tractions on behalf of the RV Radio Network. He/she will maintain a bank account with joint access for the President. He/she will collect membership dues and coordinate them with the Membership Chair. ";
$candidateT1 = "AC0F - Alan Beebe";
$candidateT2 = "Vacant";
$question5 ="The RV Radio Network is governed by an 8 member Board of Directors consisting of the immediate past president, 4 elected officers, and 3 directors at large.";
$candidateD1 = "KA2HPG - Fred Koch";
$candidateD2 = "W3TOM - Tom Abernethy";
$candidateD3 = "K5TGS - Tim Staley";
$candidateD4 = "Vacant";
$candidateD5 = "Vacant";
//*******************************************************************************************
//*** And lastly, set up some functions ***
//*******************************************************************************************
function query_db($query) {
global $trace, $link, $query ;
if(isset($trace)) echo "\$query = [ $query ] ";
open_db();
/* send the query */
if(! mysqli_query($link,$query)) {
echo " ERROR UPDATING DATABASE Please notify the webmaster. ";
echo "Failed query was [$query] ";
exit;
}
mysqli_close($link);
}
function read_pollsID_Tbl() {
global $trace, $link,$query, $Logid , $MemberNumber, $match_results;
open_db();
if ($trace) {echo "read_pollsID - query = [ $query ] ";}
if($query_results=mysqli_query($link, $query)) {
$match_results=mysqli_num_rows($query_results);
if ($trace) {
printf("Select returned %d rows.\n", mysqli_num_rows($query_results));
}
if(isset($trace)) echo " found $match_results matches ";
$row=mysqli_fetch_array($query_results);
/* free result set */
// mysqli_free_result($result);
}
}
function get_count() {
open_db();
global $trace, $link,$query, $Logid , $MemberNumber, $match_results;
if ($trace) {echo "get_count - query = [ $query ] ";}
if($query_results=mysqli_query($link, $query)) {
$match_results=mysqli_num_rows($query_results);
}
}
/*
#####################################################################################
################## HAS USER ALREADY TAKEN THE POLL #################
#####################################################################################
*/
// $Logid = "KG4RMT"; // TESTING
if(isset($trace)) echo"Checking to see if member [$Logid] has already voted.";
// $query= "select * from $ID_Table where LoginID = '" .$Logid. "' ";
// $query= "select * from $ID_Table where MemberNumber = '" .$MemberNumber. "' ";
$query= "select * from $ID_Table where LoginID = '" .$Logid. "' and MemberNumber = '" .$MemberNumber. "' ";
// read_pollsID_Tbl();
//$trace="y";
if(isset($trace)) Echo "Reading record from $ID_Table .... ";
open_db();
if($query_results=mysqli_query($link, $query)) {
$match_results=mysqli_num_rows($query_results);
if(isset($trace)) echo (" Found $match_results previous vote from $Logid");
if($match_results > 0) {
//echo "Sorry, $Logid - Member Number $MemberNumber, has already voted on ";
$row=mysqli_fetch_array($query_results);
//echo $row['ChangedDate'] ;
//$ChangedDate= $row['ChangedDate'] ;
echo ("
\" ");
echo ("
We're Sorry, each RVRN member may vote only once.
$Logid - Member# $MemberNumber voted at ".$row['ChangedDate']." Pacific time ");
echo (" Whatch for the election results to be posted after the polls close. ");
echo (" Go to RVRN Home Page
");
echo ("
");
exit;
}
}
/*
###############################################################################
######### IF USER HAS ENTERED DATA TO BE PROCESSED #############
###############################################################################
*/
if(isset($mode)) { // HOUSTON - WE HAVE DATA
if(isset($trace)) echo"Form was submitted - now processing data ";
if(isset($trace)) $logfile= "Test".$logfile;
$ip_addr=$USR_IP=getenv("REMOTE_ADDR");
if(isset($trace)) {echo ("\$logfile = [$logfile] | \$ip_addr = [$ip_addr]"); }
$outfile = fopen($logfile, 'a') ;
fwrite($outfile,"\n\n===== $today from IP address: $ip_addr ====\n");
$logtext="$A1 | $A2 | $A3 | $A4 | $AD1 | $AD2 | $AD3 | $AD4";
fwrite($outfile,"$logtext\n" ) ;
fclose($outfile);
if(isset($trace)) echo "[$logtext] has been written to logfile ";
/* ###### Update the poll participants DATABASE ###### */
$query = "insert into $ID_Table (MemberNumber, LoginID) values ('$MemberNumber', '$Logid') ";
if(isset($trace)) {
echo "\$query = [ $query ] ";
// exit;
}
open_db();
/* send the query */
if(! mysqli_query($link,$query)) {
$outfile = fopen($logfile, 'a') ;
fwrite($outfile,"===== Database Insert Error ====\n");
fwrite($outfile,"Query was $query\n");
fwrite($outfile,"Error description: " . mysqli_error($link) ."\n");
fwrite($outfile,"===== Exiting program ====\n");
fclose($outfile);
echo " ERROR UPDATING THE VOTERS TABLE Please notify the webmaster.";
echo " #############################################################";
echo(" Error description: " . mysqli_error($link)) ;
echo " Can Not Continue - Please Notify Webmaster.";
echo " #############################################################";
if(isset($trace)) echo "Failed query was [$query] ";
exit;
}
if(isset($trace)) echo "pollsID_Tbl update successful ";
// #######################################################################################
// ###### Update the poll votes DATABASE ######
// ###### THIS DOES NOT WORK! ######
// ###### $description1 = mysql_real_escape_string($_POST[description1]); ######
// ###### INSERT INTO orders (description1) VALUES ('$description1'); ######
// ###### ######
// ############################################################################$$#########
// ########################################################################################
// ###### THIS DOES WORK ######
// ###### from https://www.w3schools.com/php/func_mysqli_real_escape_string.asp ######
// ###### ######
// ########################################################################################
/*
$con = mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
// Escape special characters, if any
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$age = mysqli_real_escape_string($con, $_POST['age']);
$sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$firstname', '$lastname', '$age')";
if (!mysqli_query($con, $sql)) {
printf("%d Row inserted.\n", mysqli_affected_rows($con));
}
mysqli_close($con);
*/
// #############################################################
open_db();
// $Comments = mysqli_real_escape_string($link, $Comments);
$query = "insert into $VotesTable (A1, A2, A3, A4, AD1, AD2, AD3, AD4) values ('$A1', '$A2', '$A3', '$A4', '$AD1', '$AD2', '$AD3','$AD4') ";
if(isset($trace)) echo "\$query = [ $query ] ";
//open_db();
/* send the query */
if(! mysqli_query($link,$query)) {
$outfile = fopen($logfile, 'a') ;
fwrite($outfile,"===== Database Insert Error ====\n");
fwrite($outfile,"Query was $query\n");
fwrite($outfile,"===== Attempting Backout of VoterID ====\n");
fclose($outfile);
if(isset($trace)) echo "Query [$query] failed. Report was written to logfile ";
echo " ERROR UPDATING VOTES TABLE Please notify the webmaster.";
$query = "delete from $ID_Table where LoginID = \"$Logid\" and MemberNumber = $MemberNumber limit 1";
echo("query = [ $query ] ");
open_db();
if(! mysqli_query($link,$query)) {
$outfile = fopen($logfile, 'a') ;
fwrite($outfile,"===== Backout of VoterID $logid failed ====\n");
fwrite($outfile,"Query was $query\n");
fwrite($outfile,"============================================\n");
fclose($outfile);
echo " ERROR UPDATING THE VOTERS TABLE Please notify the webmaster.";
exit;
}
$outfile = fopen($logfile, 'a') ;
fwrite($outfile,"===== Back out of VoterID succeeded ====\n");
fwrite($outfile,"============================================\n");
fclose($outfile);
echo "Backout Successful";
echo " This error is sometimes caused by use of the browser \"BACK\" or \"Refresh\" function";
echo "Return to Poll -or- Return to Main Page";
exit;
}
?>
RVRN Election Poll Booth
Thank you for exercising your right to vote in RVRN elections!
Go to RVRN Home Page
RVRN Election Poll Booth
// FROM https://www.w3resource.com/php/function-reference/mysqli_error.php
// Example of procedural style:
//
//
//
// Output:
//
// Errormessage: Unknown system variable 'a'
//
// Example:
//
//