Location: PHPKode > projects > CoreAsset > coreasset/install.php
<?php
	require 'libs/Smarty.class.php';
	session_start();
	$fname="status.txt";
	$fp=fopen($fname,"r");
	if($fp)
	 {
	  $stat=fgets($fp);
	  if($stat=="true")
	       	echo "<script language='Javascript'>location='index.php';</script>";
	}
	$smarty = new Smarty;
	$smarty->compile_check = true;
	$smarty->debugging = false;
	$title	  ="::: Installation :::";
	$smarty->assign('title',$title);
	// Date & Time to be dispalyed on the header 
$date_time	= date("h:i:s A")." ".date("d-m-Y");
$smarty->assign('date_time',$date_time);
// Done
	$smarty->assign('val',$_SESSION);
	if(isset($_REQUEST['err_no']))
	{
	  $err_no=$_REQUEST['err_no'];
	  $msg=array("1","1","1","1");	  
		switch ($err_no)
    	  {
     		case 1:
				$msg[0]="0";$msg[1]="0";$msg[2]="0";
				break;
			case 2:
				$msg[1]="0";$msg[2]="0";
				break;
			case 3:
				$msg[2]="0";
				break;	
			
		   }	
	   
	   $flag=0;
	 	
	}
	else
	{
		  $msg=array("1","1","1","1");
		  $flag=1;	  

	}
	$smarty->assign('flag',$flag);
	$smarty->assign('msg',$msg);
	foreach($_SESSION as $n=>$v)
	{
	  $$n=$v;
	}
	
	
	if(isset($_REQUEST['set']))
	{	
	 $link = mysql_connect($db_host, $db_userid, $db_pwd);
     if (!$link)
     {
        die('Not connected : ' . mysql_error());
     }
     $db_selected = mysql_select_db($db_name, $link);
     if (!$db_selected)
     {
         die ('DB ERROR : ' . mysql_error());
     }
		
	
	// Dropping All Tables
	mysql_query("DROP TABLE asset_assets");
	mysql_query("DROP TABLE asset_category");
	mysql_query("DROP TABLE asset_equipment"); 
	mysql_query("DROP TABLE asset_purchase_order"); 
	mysql_query("DROP TABLE asset_serial_number"); 
	mysql_query("DROP TABLE asset_users"); 
	mysql_query("DROP TABLE asset_vendor"); 
	mysql_query("DROP TABLE asset_books"); 
	mysql_query("DROP TABLE asset_history"); 
	mysql_query("DROP TABLE asset_book_history"); 
	
	
	// Creatin asset_asset table
   
   $table_query[]="CREATE TABLE `asset_assets` (
  `asset_tag` int(100) NOT NULL auto_increment,
  `category_id` int(100) NOT NULL,
  `asset_nickname` varchar(100)  NOT NULL,
  `po_no` int(100) NOT NULL,
  `vendor_id` int(100) NOT NULL,
  `asset_price` double(10,2) NOT NULL,
  `equipment_id` varchar(100)  NOT NULL,
  `asset_description` text  NOT NULL,
  `receive_date` date NOT NULL,
  `create_date` date NOT NULL,
  `attachment_name` varchar(100)  NOT NULL,
  PRIMARY KEY  (`asset_tag`))";
 
 
// Creatin asset_category table
	$table_query[]= "CREATE TABLE `asset_category` (
  `category_id` int(100) NOT NULL auto_increment,
  `category_name` varchar(100)  NOT NULL,
  `category_description` text  NOT NULL,
  `create_date` date NOT NULL,
  PRIMARY KEY  (`category_id`))";
 
 
 
 // Creatin asset_equipment table
	$table_query[]= "CREATE TABLE `asset_equipment` (
  `equipment_id` int(100) NOT NULL auto_increment,
  `category_id` int(100) NOT NULL,
  `equipment_name` varchar(100)  NOT NULL,
  `equipment_model` varchar(100)  NOT NULL,
  `create_date` date NOT NULL,
  `status` int(100) default '0',
  PRIMARY KEY  (`equipment_id`))";
 
 
 
// Creatin asset_purchase_order table
	$table_query[]= "CREATE TABLE `asset_purchase_order` (
  `po_no` int(100) NOT NULL auto_increment,
  `po_date` date NOT NULL,
  `vendor_id` int(100) NOT NULL,
  `category_id` int(100) NOT NULL,
  `equipment_id` varchar(100)  NOT NULL,
  `no_pcs` varchar(100)  NOT NULL,
  `create_date` date NOT NULL,
  PRIMARY KEY  (`po_no`))";
 
 
// Creatin asset_serial_number table
	$table_query[]= "CREATE TABLE `asset_serial_number` (
  `serial_id` int(100) NOT NULL auto_increment,
  `category_id` int(100) NOT NULL,
  `po_no` int(100) NOT NULL,
  `asset_id` varchar(100)  NOT NULL,
  `equipment_id` int(100) NOT NULL,
  `serial_no` varchar(100)  NOT NULL,
  `manufacturer` varchar(100)  NOT NULL,
  `user_id` int(100) NOT NULL,
  `created_on` date NOT NULL,
  `expiry_date` date NOT NULL,
  `equip_price` int(100) NOT NULL,
  `status` int(4) default '1',
  `reason` text  NOT NULL,
  `issud_userid` int(100) NOT NULL,
  PRIMARY KEY  (`serial_id`))";
 
 // creating asset_book table 
 $table_query[]="CREATE TABLE `asset_books` (
  `book_id` int(11) NOT NULL auto_increment,
  `book_name` varchar(100)  NOT NULL,
  `author` varchar(100)  NOT NULL,
  `publisher` varchar(100)  NOT NULL,
  `isbn_no` varchar(100)  NOT NULL,
  `receive_date` date NOT NULL,
  `price` varchar(10)  NOT NULL,
  `issued_user` int(100) NOT NULL default '0',
  `issued_date` date NOT NULL,
  `status` int(5) default '0',
  `return_date` date NOT NULL,
  `issued_by` int(100) default NULL,
  PRIMARY KEY  (`book_id`))";
 
 // Creatin asset_users table
  $table_query[]= "CREATE TABLE `asset_users` (
  `user_id` int(100) NOT NULL auto_increment,
  `login` varchar(100)  NOT NULL,
  `password` varchar(100)  NOT NULL,
  `full_name` varchar(100)  NOT NULL,
  `email` varchar(100)  NOT NULL,
  `status` int(50) NOT NULL,
  `created_on` date NOT NULL default '0000-00-00',
  `updated_on` date NOT NULL default '0000-00-00',
  `created_by` int(100) default NULL,
  `updated_by` int(100) default NULL,
  `comments` text NOT NULL,
  `last_login` datetime NOT NULL,
  `last_logout` datetime NOT NULL,
  `login_status` int(3) NOT NULL default '0',
  PRIMARY KEY  (`user_id`))";

 
 // Creatin asset_vendor table
 $table_query[]= "CREATE TABLE `asset_vendor` (
  `vendor_id` int(100) NOT NULL auto_increment,
  `vendor_name` varchar(100)  NOT NULL,
  `vendor_address` text  NOT NULL,
  `vendor_email` varchar(100)  NOT NULL,
  `vendor_phone` varchar(25)  NOT NULL,
  `vendor_zip` varchar(10)  NOT NULL,
  `vendor_country` varchar(20)  NOT NULL,
  `vendor_state` varchar(30)  NOT NULL,
  `vendor_description` text  NOT NULL,
  `create_date` date NOT NULL,
  PRIMARY KEY  (`vendor_id`))";
  
  //creating asset_history table
  $table_query[]="CREATE TABLE `asset_history` (
  `history_id` int(11) NOT NULL auto_increment,
  `asset_tag` int(100) NOT NULL,
  `serial_id` int(100) NOT NULL,
  `equipment_id` int(100) NOT NULL,
  `old_status` int(100) NOT NULL,
  `new_status` int(100) NOT NULL,
  `reason` text  NOT NULL,
  `change_date` date NOT NULL,
  `user_id` int(100) NOT NULL default '0',
  PRIMARY KEY  (`history_id`))";

  //creating asset_book_history table
  $table_query[]="CREATE TABLE `asset_book_history` (
  `book_hist_id` int(100) NOT NULL auto_increment,
  `asset_tag` int(100) NOT NULL,
  `po_no` int(100) NOT NULL,
  `book_id` int(100) NOT NULL,
  `assigned_userid` int(11) NOT NULL default '0',
  `issued_on` date NOT NULL,
  `return_date` date NOT NULL,
  `change_date` date NOT NULL,
  PRIMARY KEY  (`book_hist_id`))";

	$install_status	=0;
 	$no_of_tables=count($table_query);

   for($i=0 ; $i < $no_of_tables ; $i++)
   {
    	mysql_query($table_query[$i]);
		   if(mysql_error())
		    {
		   	  $install_status=1;
//			  echo mysql_error();
//			  break;
			}
   }
if($install_status == 0)
	{
	$date=date("Y-m-d");
	$pwd=base64_encode($admin_pwd);
	 mysql_query("insert into asset_users (login, password, full_name, email, status, created_on) values ('$admin_id', '$pwd', '$admin_name', '$admin_email',1, '$date')");

	 mysql_query("INSERT INTO `asset_category` VALUES (1, 'Hardware', '', NOW())");	 
 	 mysql_query("INSERT INTO `asset_category` VALUES (2, 'Book', '', NOW())");	 

	 // Making the status true
		$fname="status.txt";
		$fp=fopen($fname,"w+");
		if($fp)
		 {
		  fwrite($fp,"true");
		 } 
		 fclose($fp);
	// Creating Configuration file
		$setting=array($db_host,$db_userid,$db_pwd,$db_name);
		
		
		$fname="gkjd78xh5843w98mnj.cams";
		$fp=fopen($fname,"w+");
		if($fp)
		 {
		  fwrite($fp,base64_encode($db_host));fwrite($fp,"\t");
		  fwrite($fp,base64_encode($db_userid));fwrite($fp,"\t");
		  fwrite($fp,base64_encode($db_pwd));fwrite($fp,"\t");
		  fwrite($fp,base64_encode($db_name));
		 } 
		fclose($fp);
	
		$subject	= "Administrator Account Information";
		$to			= $admin_email;
	//	$from		= "CSPL Asset Management System";
		$message	= "Thank you for Using our Asset Management System. Your Account infomaion is as follows :
		
		Admin User ID : ".$admin_id."
		Admin Password : ".base64_decode($pwd)."
		
		Regarding
		Corelynx Solutions Pvt Ltd.";
	
		@mail($to, $subject, $message, "From: CSPL Asset Management System");
	
	echo "<script language='JavaScript' >location='rdirect.php?status=1';</script>";
	 
}
else
 {
 	echo "<script language='JavaScript' >location='rdirect.php?status=0';</script>";
 }
 }
 $smarty->display('install.tpl');
?>
Return current item: CoreAsset