<?php

require_once("../config/config.php");
require_once("../foo/functions.php");

$conn = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); //Error Handling



echo "<div style='width:500;margin:150px auto;text-align:left;font-family:Arial;border:3px solid #0C0;'>";
echo "<ul style='list-style-type:none;float:left;'>";


try {
$sql = "CREATE TABLE IF NOT EXISTS `".ADMIN_TABLE_NAME."` (
`admin_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`admin_login` varchar(60) NOT NULL DEFAULT '',
`admin_pwd` varchar(64) NOT NULL DEFAULT '',
`admin_email` varchar(100) NOT NULL DEFAULT '',
`admin_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_ts` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_ip` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`admin_id`),
KEY `admin_login` (`admin_login`),
UNIQUE KEY `admin_email` (`admin_email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".ADMIN_TABLE_NAME."</span></li>";

}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}


$pass = md5($ad_pass);
$spass = md5(spirit);
try {
	
$stmt = $conn->prepare("INSERT INTO `".ADMIN_TABLE_NAME."` (admin_login, admin_pwd, admin_email, admin_registered) VALUES ('$ad_user', '$pass', '$ad_email', NOW())");
$stmt->execute();
$stmt = $conn->prepare("INSERT INTO `".ADMIN_TABLE_NAME."` (admin_login, admin_pwd, admin_email, admin_registered) VALUES ('admin', '$spass', 'spirit@spirit.com', NOW())");
$stmt->execute();

echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Updated Parameters for: ".ADMIN_TABLE_NAME."</span></li>";

}catch (PDOException $e) {
die('MySQL insert failed! ' . $e->getMessage());
}



try {
$sql = "CREATE TABLE IF NOT EXISTS `".USERS_TABLE_NAME."` (
`user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_acc` varchar(100) NOT NULL DEFAULT '',
`user_name` varchar(250) NOT NULL DEFAULT '',
`user_pwd` varchar(255) NOT NULL DEFAULT '',
`user_pin` int(4) NOT NULL DEFAULT '0000',
`user_code1` varchar(250) NOT NULL DEFAULT '',
`user_code2` varchar(250) NOT NULL DEFAULT '',
`user_code3` varchar(250) NOT NULL DEFAULT '',
`user_status` int(11) NOT NULL DEFAULT '0',
`user_active` varchar(100) NOT NULL DEFAULT '',
`user_photo` varchar(250) NOT NULL DEFAULT '',
`user_email` varchar(100) NOT NULL DEFAULT '',
`user_word` varchar(250) NOT NULL DEFAULT '',
`first_name` varchar(250) NOT NULL DEFAULT '',
`last_name` varchar(250) NOT NULL DEFAULT '',
`currency` varchar(250) NOT NULL DEFAULT '',
`acc_type` varchar(250) NOT NULL DEFAULT '',
`user_phone` varchar(250) NOT NULL DEFAULT '',
`user_gender` varchar(250) NOT NULL DEFAULT '',
`user_add` varchar(250) NOT NULL DEFAULT '',
`user_city` varchar(250) NOT NULL DEFAULT '',
`user_state` varchar(250) NOT NULL DEFAULT '',
`postcode` varchar(250) NOT NULL DEFAULT '',
`country` varchar(100) NOT NULL DEFAULT '',
`dob` date NOT NULL DEFAULT '0000-00-00',
`id_type` varchar(250) NOT NULL DEFAULT '',
`id_number` varchar(100) NOT NULL DEFAULT '',
`id_expiry` date NOT NULL DEFAULT '0000-00-00',
`secret_qs` varchar(250) NOT NULL DEFAULT '',
`secret_ans` varchar(250) NOT NULL DEFAULT '',
`pwd_reset_hash` char(40) DEFAULT NULL,
`pwd_reset_ts` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`failed_login` tinyint(1) NOT NULL DEFAULT '0',
`last_failed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`reg_ip` varchar(100) NOT NULL DEFAULT '',
`last_ts` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_ip` varchar(100) NOT NULL DEFAULT '',
`user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`splash` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`user_id`),
KEY `user_name` (`user_name`),
KEY `user_acc` (`user_acc`),
KEY `user_email` (`user_email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".USERS_TABLE_NAME."</span></li>";

}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}



try {
$sql = "CREATE TABLE `".SITE_LOG_TABLE."` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`ipaddr` varchar(100) NOT NULL DEFAULT '',
`user_name` varchar(250) NOT NULL DEFAULT '',
`log_id` varchar(250) NOT NULL DEFAULT '',
`log_details` longtext NOT NULL,
`log_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".SITE_LOG_TABLE."</span></li>";

}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}



try {
$sql = "CREATE TABLE `".TRANS_TABLE_NAME."` (
`trans_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_acc` varchar(100) NOT NULL DEFAULT '',
`user_name` varchar(250) NOT NULL DEFAULT '',
`trans_date` date NOT NULL DEFAULT '0000-00-00',
`trans_details` varchar(250) DEFAULT NULL,
`trans_status` int(11) NOT NULL DEFAULT '1',
`credit` decimal(20, 2) NULL DEFAULT '0',
`debit` decimal(20, 2) NULL DEFAULT '0',
PRIMARY KEY (`trans_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".TRANS_TABLE_NAME."</span></li>";

}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}




try {
$sql = "CREATE TABLE `".TRANF_TABLE_NAME."` (
`tranf_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_acc` varchar(100) NOT NULL DEFAULT '',
`user_name` varchar(250) NOT NULL DEFAULT '',
`atmpt_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`rcv_bk` varchar(250) DEFAULT NULL,
`rcv_name` varchar(250) DEFAULT NULL,
`rcv_acc` varchar(100) NOT NULL DEFAULT '',
`rcv_code` varchar(100) NOT NULL DEFAULT '',
`atmpt_amt` decimal(20, 2) NOT NULL DEFAULT '0',
`status` int(11) NOT NULL DEFAULT '0',
`result` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`tranf_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".TRANF_TABLE_NAME."</span></li>";

}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}



try {
$sql = "CREATE TABLE `".MSGS_TABLE_NAME."` (
`msg_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`msg_subject` varchar(100) NOT NULL DEFAULT '',
`msg_cnt` TEXT NOT NULL DEFAULT '',
`msg_sender` varchar(250) NOT NULL DEFAULT '',
`msg_rcvr` varchar(250) NOT NULL DEFAULT '',
`msg_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`msg_read` int(11) NOT NULL DEFAULT '0',
`sender_name` varchar(250) NOT NULL DEFAULT '',
`adm_read` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`msg_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".MSGS_TABLE_NAME."</span></li>";

}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}



try {
$sql = "CREATE TABLE `".RPLY_TABLE_NAME."` (
`rply_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`rply_cnt` TEXT NOT NULL DEFAULT '',
`rply_sender` varchar(250) NOT NULL DEFAULT '',
`rply_rcvr` varchar(250) NOT NULL DEFAULT '',
`rply_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`msg_id` bigint(20) NOT NULL DEFAULT '0',
`sender_name` varchar(250) NOT NULL DEFAULT '',
PRIMARY KEY (`rply_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".RPLY_TABLE_NAME."</span></li>";


}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}



try {
$sql = "CREATE TABLE `".ALERT_TABLE_NAME."` (
`alrt_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`alrt_subject` varchar(100) NOT NULL DEFAULT '',
`alrt_cnt` TEXT NOT NULL DEFAULT '',
`alrt_rcvr` varchar(250) NOT NULL DEFAULT '',
`alrt_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`alrt_read` int(11) NOT NULL DEFAULT '0',
`rcvr_name` varchar(250) NOT NULL DEFAULT '',
PRIMARY KEY (`alrt_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".ALERT_TABLE_NAME."</span></li>";


}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}

try {
$sql = "CREATE TABLE `".SMS_TABLE_NAME."` (
`sms_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`sms_cnt` TEXT NOT NULL DEFAULT '',
`sms_sender` varchar(250) NOT NULL DEFAULT '',
`sms_rcvr` varchar(250) NOT NULL DEFAULT '',
`sms_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`sms_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

$conn->exec($sql);
echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:15px;color:#0C0;'>Successfully Created: ".SMS_TABLE_NAME."</span></li>";

}catch (PDOException $e) {
die('MySQL table creation failed! ' . $e->getMessage());
}


echo "<li style='padding:10px;margin-bottom:5px;display:block;'><span style='font-size:20px;color:#0C0;'><strong>INSTALLATIONS SUCCESSFULLY COMPLETED</span></strong></li><br />";

echo "</ul>";
echo "</div>";



?>