<?php
	$db_name = "systems";
	$table_name = "sacTEST";
	$numkey = $_POST['numkey'];
	$auth = $_POST['authtext'];
	$selected = $_POST['selected'];

  $Early = $_POST['Early'];
  $Manuel = $_POST['Manuel'];
  $Hight = $_POST['Hight'];
  
  //echo"Early= $Early and Manuel = $Manuel and Hight = $Hight";
 
  $msgbody = " ";
  
 	//Create a connection
	$connection = @mysql_connect("libitdb.lang.uc.edu", "phpadmin", "25or624") 
	              or die("Couldn't connect to database server.");
  
	//Select a database
	$db = @mysql_select_db($db_name, $connection) 
	      or die("Couldn't select $db_name database ");

	//SQL statement
	$query = "UPDATE $table_name SET voted = \"yes\" WHERE (numkey = \"$numkey\")";

	//execute SQL query and get result
	$result = @mysql_query($query, $connection) or die ("Couldn't execute query. <p>$query</p>");

  $counter = 0;
  $echoed = 0;

  //Early
	if (!$Early or $counter >= 2){
    if ($counter >= 2){
      if ($echoed = 0){
        echo "There can be only two. \n";
        $echoed = $echoed + 1;
      }
    }
  //do nothing
  }
  else {
  $counter = $counter + 1;
  $msgbody = $msgbody . $Early . ", ";
	$query2 = "UPDATE $table_name SET votes = votes + 1 WHERE (LName = \"Early\")";
	$result2 = @mysql_query($query2, $connection) or die ("Couldn't execute query. <p>$query2</p>");
  }

  //Manuel 
	if (!$Manuel or $counter >= 2){
    if ($counter >= 2){
      if ($echoed = 0){
        echo "There can be only two. \n";
        $echoed = $echoed + 1;
      }
    }
  //do nothing
  }
  else {
  $counter = $counter + 1;
  $msgbody = $msgbody . $Manuel . ", ";
	$query3 = "UPDATE $table_name SET votes = votes + 1 WHERE (LName = \"Manuel\")";
	$result3 = @mysql_query($query3, $connection) or die ("Couldn't execute query. <p>$query3</p>");
  }
  
  //Hight
	if (!$Hight or $counter >= 2){
    if ($counter >= 2){
      if ($echoed = 0){
        echo "There can be only two. \n";
        $echoed = $echoed + 1;
      }
    }
  //do nothing
  }
  else {
  $counter = $counter + 1;
  $msgbody = $msgbody . $Hight . ", ";
	$query4 = "UPDATE $table_name SET votes = votes + 1 WHERE (LName = \"Hight\")";
	$result4 = @mysql_query($query4, $connection) or die ("Couldn't execute query. <p>$query4</p>");
  }
  
  
	// mail function 
  // notify the person responsible
  $mailTo = "scherztc@ucmail.uc.edu"; 
  $msgSubject = "SAC Ballot"; 
  $xHeaders = "From: SAC Ballot";
  // notify the requestor their vote has been received.
  // mail ($mailTo, $msgSubject, $msgbody, $xHeaders); 
		
	echo "
  <HTML>
  <HEAD>
  <TITLE>SAC Ballot</TITLE>
  </HEAD>
  <BODY>
  <center>
  <H1>Staff Advisory Committee Ballot Submitted</H1>
	<p>The results will be emailed to all staff during the week of November 14th through November 18th.</p>
  <p></p> 
  <p>Thank you for voting.</p>
  </center>
  </BODY>
  </HTML>
  ";
?>
