<?
/* Database Interface
 * 
 * Interacts with whatever database the election is using
 */

	/* db_connect($database_server, $username, $password)
	 *
	 * db_connect takes the database server name, user name and password
	 *  and connects to the appropriate database
	 *
	 * In: String $database_server - The name of the database server
	 * In: String $username - The user name to use when connecting to the server
	 * In: String $password - The password to use when connecting to the server
	 * Return: boolean - true on success, false on failure
	 */
	 
	function db_connect($database_server, $username, $password){
		// Make sure these are all strings?  
		// Figure out how to do that!
		
		$link = mysql_connect($database_server, $username, $password);
		return $link;
	}

	/* db_wipeDatabase()
	 *
	 * Clears the database so that a new election can be stored there.
	 *
	 * Input: none
	 *
	 * Output: a boolean indicating success (true) or failure (false)
	 */
	function db_wipeDatabase(){

	}

	/* db_createTable($tablename, $field_names) 
	 *
	 * Creates a new table in the database
	 *
	 * In: String $tablename - The name of the table to create
	 * In: Array $field_names - The details of the fields to create 
	 *     in the table.  Each entry in the array will be an array with the
	 *     following keys and values:
	 *  		Key: 'field_name' Value: String - the name of the field
	 *  		Key: 'type' Value: String - the type of the field (see mysql
	 *  		      commands for more information about allowed types)
	 *  		Key: 'initial_value' Value: String - the initial value of the
	 *  			  entry in the database (NOT NULL for example)
	 *  		Key: 'special' Value: String - any special things
	 *  			  associated with the entry (AUTO_INCREMENT for example).  If
	 *  			  there are multiple additional things associated with the entry
	 *  			  they will be in one string, seperated by spaces.  This is
	 *  			  optional!
	 * Return: boolean - the result of the query to create the database.  False
	 *   on a failure, and true on success.
	 */
	 
	function db_createTable($tablename, $field_names){

	}
	
	/* db_insertIntoTable($tablename, $field_names_and_values_array)
	 *
	 * This function inserts the given information into a row in the table of
	 * name $tablename, in the database
	 *
	 * In: String $tablename - The name of the table to insert data into
	 * In: Array $field_names_values_array - An array in which the keys are the
	 *     names of the fields for the given table, and the corresponding value of
	 *     each key is the value to insert into the table for that key.
	 * Return: boolean - the result of the query to create the database.  False
	 *   on a failure, and true on success.
	 */
	 
	function db_insertIntoTable($tablename, $field_names_and_values_array){

	}
	
	 /* db_insertVote($voter, $voting_info)
	  *
	  * This function takes a string (the ID of the voter) and an array of
	  * voting information (an array of question answers). If the voter hasn't
	  * voted before, puts the answers into a row in the database table. Also
	  * puts the voter's ID in a separate table so that we can keep track of
	  * who has already voted.
	  *
	  * Input: String $voter - the ID of the voter, purely for the purpose of
	  *                        making sure people vote only once.
	  *        Array $voting_info - An array of answers to ballot questions,
	  *                             where the keys are the question names and
	  *                             the values are strings representing the
	  *                             voter's answers.
	  * 
	  * Output: An int: 0 if successful,
	  *                 1 if the voter has already voted
	  *                 2 if table input fails
	  *                 (there will be constants for this soon)
	  */
	 function db_insertVote($voter, $voting_info){

	 }

	 /* db_getQuestionTypes()
	  *
	  * This function returns the contents of the question types table in the
	  * database as an array, mapping question number to question type.
	  *
	  * Input: none
	  *
	  * Output: resource - on a success, return an array mapping question
	  *                    number to question type (the keys are question
	  *                    names, the values are strings indicating question
	  *                    type).
	  *         NULL - return null on a failure.
	  */
	 function db_getQuestionTypes(){

	 }

	 /* db_getCurrentElecResults()
	  *
	  * This function returns the current results of the election in the form
	  * of a two-dimensional array. Essentially, it is an array of voter
	  * responses. Each entry in the array consists of one of the arrays
	  * entered into the database with db_insertVote($voter, $voting_info).
	  *
	  * See also: db_insertVote($voter, $voting info)
	  *
	  * Input: None
	  *
	  * Output: resource - on a success, return a two-dimensional array
	  *                    consisting of all ballot responses (the keys in
	  *                    the array just represent which vote this was --
	  *                    there's no specific indexing system. The values are
	  *                    themselves arrays. These internal arrays' keys are
	  *                    question names and the values are strings
	  *                    representing ballot answers).
	  *         NULL - return null on a failure.
	  */
	 function db_getCurrentElecResults(){
	 
	 }
?>
