<link rel="stylesheet" href="css/style.css" type="text/css"/>
<?php 

	include("includes/config.php");
	include("includes/func.php");
	include("classes/safeSQL.class.php");
	
	if (($_SESSION['id'] == ""))
	{
		redirect("login");
	}	
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function get_category($cat_id)
{
	$Sql_Cat	=	"SELECT * FROM `category` where id = '$cat_id'";
	$Exe_Sql_Query	=	mysql_query($Sql_Cat);
	$Cat_Row	=	mysql_fetch_array($Exe_Sql_Query);
	return ($Cat_Row['desc']);	
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	$safeSQL 			= new safeSQL;
	
	if(isset($_POST['product_search']))
	{
		/*echo "<pre>";
			print_r($_POST);
		echo "</pre>";
		exit;*/
		
		$category_name 				= $safeSQL->$_POST['category_name'];
		$product_name 				= $safeSQL->$_POST['product_name'];
		$product_code 				= $safeSQL->$_POST['product_code'];
		$product_search 			= $safeSQL->$_POST['product_search'];
		
		$Add_Query	=	"And `producttitle` = '{$product_name}'";
		
		if($product_code != '')
		{
			$Add_Query	=	"And (`producttitle` = '{$product_name}' or `product_code` = '{$product_code}')";
		}
		
		/*if($product_code != '' && $product_name != '')
		{
			$Add_Query	=	"And (`producttitle` = $product_name or `product_code` = $product_code)";
		}*/
		
		$Add_Query	=	$Add_Query . "And `catid` = $category_name";
		
		$Query	=	"SELECT * FROM `product` where 1 = 1 $Add_Query";
		echo $Query;	exit;		
		/*
		Array
		(
			[category_name] => 1
			[product_name] => Hp Probook 4540s
			[product_code] => 142563
			[product_search] => Search Product
		)
		*/
		
		$sql=	"";
	}
?>
<script type="text/javascript">
</script>
<?php
if(isset($_POST['product_search']))
{
	$category_name = $_POST['category_name'];
	$product_name = $_POST['product_name'];
	$product_code = $_POST['product_code'];
}
?>    
<form name="search" id="search" action="" method="POST">
<h3 style="padding-left:10px">Product Search</h3>
<table width="100%" cellpadding="0" cellspacing="0" align="center" id="tabling1" border="0">
    <tr>
    	<td nowrap width="34%" align="right"><label>Category Name*</label></td>
        <td width="66%" nowrap>
        	<select name="category_name" id="category_name" class="textfield1">
            	<option value="">Select category</option>
                <?php
				$sql = "Select * from category";
				$results = mysql_query($sql);
				while($rows = mysql_fetch_array($results))
				{
					echo '<option value="'.$rows['id'].'">'.$rows['desc'].'</option>';
				}
            ?>
            </select>
        </td>
    </tr>
    
    <tr>
    	<td nowrap width="34%" align="right"><label>Product Name*</label></td>
        <td width="66%" nowrap><input type="text" name="product_name" class="textfield1" id="product_name" placeholder="Product Name"/></td>
    </tr>
    
    <tr>
    	<td nowrap width="34%" align="right"><label>Product Code</label></td>
        <td width="66%" nowrap><input type="text" name="product_code" class="textfield1" id="product_code" placeholder="Product Code"/></td>
    </tr>
    
    <tr>
    	<td nowrap width="34%" align="right"></td>
        <td width="66%" nowrap><input type="submit" name="product_search"  id="product_search" value="Search Product" class="form_button"/></td>
    </tr>
    
</table>
</form>


    <h3 style="padding-left:10px">Products</h3>
    <table width="100%" id="tabling" cellpadding="0" cellspacing="0">
    	<tr>
        	<td class="col2"><span class="blue">Category</span></td>
            <td class="col2"><span class="blue">Product</span></td>
            <td class="col2"><span class="blue">Product Code</span></td>
            <td class="col2"><span class="blue">Quanity Available</span></td>
            <td class="col2"><span class="blue">Thresh hold value</span></td>            
            <td class="col2"><span class="blue">Action</span></td>
        </tr>
        <tr>
        	<td class="col2">Category 1</td>
            <td class="col2">Product 1</td>
            <td class="col2">Product Code1</td>
            <td class="col2">23</td>
            <td class="col2">25</td>
            <td class="col2"><a class="form_button" href="#">Select Product</a></td>
        </tr>
       <tr>
        	<td class="col2">Category 2</td>
            <td class="col2">Product 2</td>
            <td class="col2">Product Code2</td>
            <td class="col2">23</td>
            <td class="col2">25</td>
            <td class="col2"><a class="form_button" href="#">Select Product</a></td>
        </tr>
    </table>