Location: PHPKode > scripts > Encaps Gallery > encaps-2.3.22s/admin/catalog_db_install.php
<?php 
include("common.ini.php"); 
include("catalog_head.html");

if(@$config['demo']=='1'){
	echo '<h1>Read-only demo</h1>';
	return;
}
if(!is_writable("../rwx/"))
	Misc::_show_message_color("Directory [../rwx/] is not writable. Please do [chmod -R 777 ../rwx/] ","RED");
$cConfig = new Config('../config.ini.php','../');
$error = array("db_name"=>"","db_sup"=>"");
if (@$postget['action']=="config_update")
	$cConfig->config_update();
include('../config.ini.php');
// ------------------- check connection ------------------- //
if (@mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']))
{
	if (@mysql_select_db($config['db_name']))
	{
		if( @$_POST['action'] != 'install_submit')
		{
			?><form method="post" action="">
			<h2>Are you sure to install encaps database tables?</h2>
			<input type="submit" value="               Submit install               ">
			<input type="hidden" name="action" value="install_submit">
			</form><?php 
		}
		else
		{
			$db = new DB_sql(@$config["db_host"],@$config["db_user"],@$config["db_pass"],@$config["db_name"],1);


$sql[] = "
CREATE TABLE `".$config["db_prefix"]."base_items` (
  `id` int(11) NOT NULL auto_increment,
  `rank` int(11) default NULL,
  `is_visible` tinyint(4) default NULL,
  `title` varchar(255) default NULL,
  `description` text,
  `updated_at` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8 ;
"; 
$sql[] = "
CREATE TABLE `".$config["db_prefix"]."catalog_categs` (
  `id` int(11) NOT NULL auto_increment,
  `rank` int(11) default NULL,
  `is_enabled` tinyint(4) default NULL,
  `title` varchar(255) default NULL,
  `description` text,
  `updated_at` varchar(255) default NULL,
  `parent_id` int(11) default NULL,
  `img` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;
"; 
$sql[] = "
CREATE TABLE `".$config["db_prefix"]."catalog_items` (
  `id` int(11) NOT NULL auto_increment,
  `rank` int(11) default NULL,
  `is_enabled` tinyint(4) default NULL,
  `title` varchar(255) default NULL,
  `comment` text,
  `description` text,
  `updated_at` varchar(255) default NULL,
  `categ_id` int(11) default NULL,
  `file` varchar(255) default NULL,
  `file_width` int(11) default NULL,
  `file_height` int(11) default NULL,
  `file_align` varchar(255) default NULL,
  `file_thumb` varchar(255) default NULL,
  `file_thumb_align` varchar(255) default NULL,
  `price` float default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8 ;
"; 
$sql[] = "
CREATE TABLE `".$config["db_prefix"]."shopcart` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `payment_date` varchar(255) NOT NULL,
  `item_number` varchar(255) NOT NULL,
  `item_name` varchar(255) NOT NULL,
  `quantity` varchar(255) NOT NULL,
  `mc_gross` varchar(255) NOT NULL,
  `payer_email` varchar(255) NOT NULL,
  `payer_business_name` varchar(255) NOT NULL,
  `first_name` varchar(255) NOT NULL,
  `last_name` varchar(255) NOT NULL,
  `address_name` varchar(255) NOT NULL,
  `address_country` varchar(255) NOT NULL,
  `address_city` varchar(255) NOT NULL,
  `address_state` varchar(255) NOT NULL,
  `address_zip` varchar(255) NOT NULL,
  `address_street` varchar(255) NOT NULL,
  `payment_status` varchar(255) NOT NULL,
  `VERIFIED` varchar(255) NOT NULL,
  `updated_at` varchar(255) NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;
"; 
$sql[] = "
CREATE TABLE `".$config["db_prefix"]."test` (
  `test` text
) ENGINE = MYISAM ;
"; 
$sql[] = "
INSERT INTO `".$config["db_prefix"]."test` ( `test` )
VALUES (
'asdf'
);";
			$res_install = true;
			foreach($sql as $query)
				if(!$db->query($query))
					$res_install = false;
			if(!$res_install)
				Misc::_show_message_color("Error on installing new Encaps database tables","RED");
			else
				Misc::_show_message_color("Database is installed successfully","GREEN");
		}//if( @$_POST['action'] != 'install_submit')
	}//if (@mysql_select_db($config['db_name']))
	else 
	{
		$error['db_name'] = 1;
		Misc::_show_message_color("Unable to connect the database ".$config['db_name']."<br>".mysql_error(),"RED");
	}
}//if (@mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);)
else 
{
	$error['db_sup'] = 1;
	Misc::_show_message_color("Unable to connect the database host ".$config['db_host']." with username ".$config['db_user']." and password ".$config['db_pass']."<br>".mysql_error(),"RED");
}

if ($error['db_sup'] || $error['db_name'])
{
?>
<center>
<form action="" method="POST">
<table class="block">
	<tr>
	  <th align="center" colspan="2">Connect to the database:</th></tr>
	<tr>
		<td>Database host: </td>
		<td><input type="text" name="db_host" value="<?php echo $config['db_host'] ?>" <?php if (@$error['db_sup']) echo 'style="border: 1px solid red"'?>></td>
	</tr>	
	<tr>
		<td>Database user:</td>
		<td><input type="text" name="db_user" value="<?php echo $config['db_user'] ?>" <?php if (@$error['db_sup']) echo 'style="border: 1px solid red"'?>></td>
	</tr>
	<tr>
		<td>Database password:</td>
		<td><input type="password" name="db_pass" value="<?php echo $config['db_pass'] ?>" <?php if (@$error['db_sup']) echo 'style="border: 1px solid red"'?>></td>
	</tr>
	<tr>
		<td>Database name:</td>
		<td><input type="text" name="db_name" value="<?php echo $config['db_name'] ?>" <?php if (@$error['db_name']) echo 'style="border: 1px solid red"'?>></td>
	</tr>
	<tr>
		<td>Tables prefix (optional):</td>
		<td><input type="text" name="db_prefix" value="<?php echo $config['db_prefix'] ?>"></td>
	</tr>
	<tr>
		<td align="center" colspan="2"><center>
		<input type="hidden" name="action" value="config_update">
		  <input type="submit" name="submit" value="&nbsp;&nbsp;Submit&nbsp;&nbsp;">
		</center></td>
	</tr>
</table>
</form>
</center>
<?php
}
include("catalog_foot.html");
?>
Return current item: Encaps Gallery