| |
# $row[0] is nomination_id
# $row[1] is name
# $row[2] is class_year
# $row[3] is position
# $row[4] is extension
# $row[5] is email
# $row[6] is ID
# $row[7] is statement
# $row[8] is status
$action = $_REQUEST['action'];
$submit = $_POST['submit'];
$nomination_id = $_REQUEST['nomination_id'];
$username = $_POST['username'];
$password = $_POST['password'];
$statement = $_POST['statement'];
include ("voting_connect.php");
voting_connect ()
or exit ();
$today_date = date("Ym");
$today_year = substr($today_date,0,4);
$today_month = substr($today_date,4,2);
if ($today_month < 07) {}
else {$today_year += 1;}
$senior_year = $today_year;
$junior_year = $today_year + 1;
$sophomore_year = $today_year +2;
$firstyear_year = $today_year +3;
if ($submit == "Submit Your Statement")
{
if ((!$username) || (!$password))
{
echo "| You must enter a username and password. |
";
edit_statement($nomination_id);
}
else
{
update_statement($username,$password,$nomination_id,$statement);
}
}
elseif (!$nomination_id)
{
$query = "select * from nominations where status = 'Y' order by class_year='firstyear' ASC, class_year='sophomore' ASC, class_year='junior' ASC, class_year='senior' ASC, class_year='ada' ASC, position ASC";
$query_result = mysql_query ($query);
$query_numrows = mysql_num_rows ($query_result);
if ($query_numrows < 1)
{
echo "| There are currently no approved candidates. |
";
}
else
{
echo "To view a candidate's statement, click on the candidate's name. Candidates can click on the \"Add/Edit Statement\" link next to their name to add or update their statement. Statements need to be text-only without formatting or images. |
";
echo "| |
";
echo "| Class Year | | Position | | Name | Candidates Only |
";
while ($row = mysql_fetch_row ($query_result))
{
if ($row[2] == "ada") {$class = "Ada Class";}
if ($row[2] == "firstyear") {$class = "Class of $firstyear_year";}
if ($row[2] == "sophomore") {$class = "Class of $sophomore_year";}
if ($row[2] == "junior") {$class = "Class of $junior_year";}
if ($row[2] == "senior") {$class = "Class of $senior_year";}
if ($row[7] == "")
{
$position_list .= "| $class | | $row[3] | | $row[1] | Add/Edit Statement |
\n";
}
else
{
$position_list .= "| $class | | $row[3] | | $row[1] | Add/Edit Statement |
\n";
}
}
echo "$position_list";
}
}
else
{
if (!$action)
{
echo "| Candidate Statements |
";
$query = "select * from nominations where status = 'Y' AND nomination_id = '$nomination_id'";
$query_result = mysql_query ($query);
while ($row = mysql_fetch_row ($query_result))
{
if ($row[2] == "ada") {$class = "Ada Class";}
if ($row[2] == "firstyear") {$class = "Class of $firstyear_year";}
if ($row[2] == "sophomore") {$class = "Class of $sophomore_year";}
if ($row[2] == "junior") {$class = "Class of $junior_year";}
if ($row[2] == "senior") {$class = "Class of $senior_year";}
$statement = nl2br($row[7]);
$candidate_info .= "| Class: $class |
| Position: $row[3] |
| Name: $row[1] |
| Statement: $statement |
";
}
echo "$candidate_info";
}
else
{
if ($action == "edit")
{
edit_statement($nomination_id);
}
}
}
function update_statement($username,$password,$nomination_id,$statement)
{
# 1. Use LDAP to check their username/password
include ("ldap_check.php");
if ($check == "true")
{
# 2. Check that their username matches the email address on the submission
$query_email = "select email from nominations where nomination_id = \"$nomination_id\"";
$query_email_result = mysql_query ($query_email);
$row = mysql_fetch_row ($query_email_result);
//$email = $row[0];
$email = substr($row[0], 0, strpos($row[0], "@"));
if ($email == $username)
{
# 3. update the entry
$query_text = "update nominations set
statement = \"$statement\"
where nomination_id = \"$nomination_id\"";
// print ("$query_text");
$result = mysql_query ($query_text)
or exit (mysql_error());
if (!$result)
{
print("| There was an error updating your statement. |
\n");
}
else
{
echo "Your statement has been updated\n |
";
}
}
else
{
echo "Your Groupwise username must match the email address username you signed up with. Example: Email: jdoe@email.smith.edu / Groupwise Username: jdoe |
";
edit_statement($nomination_id);
}
}
else
{
echo"| Your Groupwise username and password were not in the system. Please check that you typed them in correctly and try again. |
";
edit_statement($nomination_id);
}
}
function edit_statement($nomination_id)
{
$today_date = date("Ym");
$today_year = substr($today_date,0,4);
$today_month = substr($today_date,4,2);
if ($today_month < 07) {}
else {$today_year += 1;}
$senior_year = $today_year;
$junior_year = $today_year + 1;
$sophomore_year = $today_year +2;
$firstyear_year = $today_year +3;
$query_text = "select name, email, class_year, position, statement from nominations where nomination_id = \"$nomination_id\"";
$query_result = mysql_query ($query_text);
while ($row = mysql_fetch_row ($query_result))
{
$name = $row[0];
$email = $row[1];
$email_username = substr($email, 0, strpos($email, "@"));
$class_year = $row[2];
$position = $row[3];
$statement = $row[4];
}
if ($class_year == "ada") {$class = "Ada Class";}
if ($class_year == "firstyear") {$class = "Class of $firstyear_year";}
if ($class_year == "sophomore") {$class = "Class of $sophomore_year";}
if ($class_year == "junior") {$class = "Class of $junior_year";}
if ($class_year == "senior") {$class = "Class of $senior_year";}
echo "| Candidate Statement Update Form |
";
echo "$name $email $class $position |
";
echo "| |
";
echo "";
}
?>