Location: PHPKode > projects > CoreAsset > coreasset/install_old.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"); 

	// Creatin asset_asset table
   if(!mysql_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,
  `asset_model` 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,
  `issued_userid` int(100) NOT NULL,
  `create_date` date NOT NULL,
  PRIMARY KEY  (`asset_tag`)
) "))
		{
			echo mysql_error();
		}
 
 
// Creatin asset_category table
if(!mysql_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`)
) "))
 
		{
			echo mysql_error();
		}
 
 
 // Creatin asset_equipment table
	if(!mysql_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,
  `create_date` date NOT NULL,
  PRIMARY KEY  (`equipment_id`)
) "))
 
		{
			echo mysql_error();
		} 
 
// Creatin asset_purchase_order table
   if(!mysql_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,
  `create_date` date NOT NULL,
  PRIMARY KEY  (`po_no`)
) "))
  		{
			echo mysql_error();
		}
 
 
// Creatin asset_serial_number table
   if(!mysql_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,
  PRIMARY KEY  (`serial_id`)
) "))
  		{
			echo mysql_error();
		}
 
 // creating asset_book table 
if(! mysql_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',
  PRIMARY KEY  (`book_id`)
) "))
  		{
			echo mysql_error();
		}
 
 // Creatin asset_users table
	if(!mysql_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',
  PRIMARY KEY  (`user_id`)
) "))
  		{
			echo mysql_error();
		}
 
 // Creatin asset_vendor table
 if(!mysql_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`)
) "))
  		{
			echo mysql_error();
		}

$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')");
 
 // 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);
	//$setting=implode("\n",$setting);
	
	$pw = base64_decode($pwd);

	$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 : ".$pw."
	
	Regarding
	Corelynx Solutions Pvt Ltd.";

	@mail($to, $subject, $message, "From: CSPL Asset Management System");

 echo "<script language='JavaScript' >location='rdirect.php';</script>";
 }
 $smarty->display('install.tpl');
?>
Return current item: CoreAsset