<?php
/*
This file is needed only when all the tables are accidently deleted on the server. 
Each function can be compiled separately in order to create a table.  
*/
require_once("includes/mysql_login.php");
//create_table_post();
//create_table_comment();
//create_table_user();
//application();
table_officers();
table_event();
/*
This function create table name post with same columns as existing columns 
*/
function create_table_post()
{
			$create_table_user = 'CREATE TABLE `post`(`postid` int(6) auto_increment NOT NULL, 
											 					`title` varchar(200) NOT NULL,
											  					`category` varchar(200) NOT NULL,
																`post` longtext NOT NULL,
																`attachment` varchar(200),
											   					`identification` int NOT NULL, 
																`date_created` timestamp, PRIMARY KEY(`postid`)
																 )';  
			$create_table_user_query = mysql_query($create_table_user);
			if(!$create_table_user_query)
			{
		 	echo "Error on query". mysql_error();
		 	}
		 	else 
		 	{
		 	echo "Table post created successfully";
		 	}
}
/*
This function creates the table name comment with same columns as existing columsn. 
*/
function create_table_comment()
{
			$create_table_comment = 'CREATE TABLE `comment`(`commentid` int(6) auto_increment NOT NULL, 
														`subject` varchar(200) NOT NULL, 
														`body` longtext NOT NULL, 
														`identification` int NOT NULL, 
														`postid` int NOT NULL,
														`date_created` timestamp NOT NULL, 
														 PRIMARY KEY(`commentid`))';
			$create_table_result = mysql_query($create_table_comment);
				if(!$create_table_result)
				{
					echo "Error on creating table ". mysql_query();
				}
				else
				{
					echo "Table created successfully";
				}												
}
/*
This funciton creates the table name user with same columsn as existing columsn
*/
function create_table_user()
{
			$create_table_user = 'CREATE TABLE `user`(`identification` int(6) auto_increment NOT NULL, 
											 					`username` varchar(200) NOT NULL,
											  					`password` varchar(200) NOT NULL,
											   					`email` varchar(200) NOT NULL,
																 `name` varchar(200), 
																 `admin` tinyint NOT NULL, 
																`date_created` timestamp, PRIMARY KEY(`identification`)
																 )';  
				$table_user_result = mysql_query($create_table_user);
				if(!$table_user_result)
				{
					echo "Error: ".mysql_error();
				}														
}
/*
This funciton creates the table name application with same columsn as existing columsn. 
*/
function application()
{
$query = 'CREATE TABLE `application`(`applicationid` int(5) auto_increment NOT NULL, `first_name` varchar(100) NOT NULL, `last_name` varchar(100) NOT NULL,
								`email` varchar(100) NOT NULL, `major` varchar(100) NOT NULL, `other_major` varchar(100), `minor` varchar(100), `college_year` varchar(100) NOT NULL,
									`graduation_year` varchar(30), `comment` longtext,
									`date_applied` varchar(45) NOT NULL,
									PRIMARY KEY(`applicationid`))';
$application_query = mysql_query($query) or die (" Fatal Error". mysql_error());									
}
/*
This function creates the table name officers with the same coluns as existing columns. 
*/
function table_officers()
{
			$officers_query = '
			CREATE TABLE `officers`(`officersid` int(20) NOT NULL auto_increment, `first_name` varchar(100) NOT NULL, `last_name` varchar(100) NOT NULL,
											`position` varchar(100) NOT NULL, `email` varchar(100), `attachment` varchar(100), `initials` varchar(100), `date_submitted` varchar(50), 
											PRIMARY KEY (`officersid`)
			)
			';
		$officers_query_result = mysql_query($officers_query);
		if(!$officers_query_result)
		{
			echo "<br>Error on creating table" .mysql_error();	
		}
}
/*
This table creates the table name event with the same columns as exiting columns. 
*/
function table_event()
{
			$event_query = '
				CREATE TABLE `event`(`eventid` int(20) NOT NULL auto_increment, `date` varchar(15) NOT NULL, `time` varchar(10) NOT NULL,
											`location` varchar(10) NOT NULL, `details` longtext NOT NULL, `initials` varchar(20), `date_submitted` varchar(45), 
											PRIMARY KEY (`eventid`)
				)
				';
			$event_query_result = mysql_query($event_query);
			if(!$event_query_result)
			{
				echo "<br>Error on creating table" .mysql_error();	
			}
}
?>