<? include("header.php");
//session_start();
error_reporting(0);
include "checksession.php";
include ("include/db-connect.php");

if(isset($_REQUEST['edit']))
{
	   $sub_sub_cat_id=$_REQUEST['sub_sub_cat'];
	   $sqlzdfsdf="SELECT * FROM `sub_sub_category` WHERE `id`='$sub_sub_cat_id'"; 
	   $resultasdasd = mysql_query($sqlzdfsdf);
	   $rowffff = mysql_fetch_array($resultasdasd);
	   $sub_cat=$rowffff['sub_cat'];
	   $sub_sub_cat=$rowffff['sub_sub_cat'];
	   
	   $cat=$_REQUEST['cat_name'];
	   $name=$_REQUEST['name'];
	   $tname=$_REQUEST['tname'];
	   $product_id=$_REQUEST['pid'];
	   $quantity=$_REQUEST['qnty'];
	   
	   $pur_price=$_REQUEST['pur_price'];
	   $description=$_REQUEST['description'];
	   $pri=$_REQUEST['price'];
	   $details=$_REQUEST['details'];
	   $sale_tax= $_REQUEST['sale_tax'];
	   
       $tax=$sale_tax*$pri;
	   $price=$tax+$pri;
       $tot_tax=$tax*$quantity;
	   
	   //upload file1
	   $small_jpg=$_FILES['small_jpg']['name'];
	   $viewid="select * from ".$PRODUCT." order by `serial` desc";
       $resultid=mysql_query($viewid);
	   $rowid= mysql_fetch_row($resultid);
	    $id=$rowid[0];
		if(!id)
		{
		$id=$id;
		}
		else
		{
		$id=$id+1;
		}
	$filename=$id.$small_jpg;
    $uploaddir = 'sample/';
    $uploadfile = $uploaddir . $filename;
	move_uploaded_file($_FILES['small_jpg']['tmp_name'], $uploadfile);
	 //end  
	
	$selct_countproduct=mysql_query("select count(*) as num from `products` where `name`='$name'");
	$fetch_countproduct=mysql_fetch_array($selct_countproduct);
	if($fetch_countproduct['num']==0)
	{
		
$insert=("insert into ".$PRODUCT."(`category`,`sub_category`,`sub_sub_cat`,`name`,`tname`,`product_id`,`quantity`,`description`,`in_price`,`price`,`pur_price`,`details`,`tax_percen`,`sale_tax`,`tot_tax`,`small_jpg`,`medium_jpg`,`large_jpg`)
 values('$cat','$sub_cat','$sub_sub_cat','$name','$tname','$product_id','$quantity','$description','$pri','$price','$pur_price','$details','$sale_tax','$tax','$tot_tax','$uploadfile','$uploadfile1','$uploadfile2')");

    $exce=mysql_query($insert);
	?><script>window.location="add_product2.php?add=success";</script><?
	} else {
		
		?><script>window.location="add_product2.php?al=ex";</script><?
		
		
	}
}
?>
<?php	
$sqlCountry="select id,category_name from ".$CAT." where code='1'  order by category_name asc ";
$resCountry=mysql_query($sqlCountry);
$checkCountry=mysql_num_rows($resCountry); 
?>  
<link rel="stylesheet" type="text/css" href="acco/css/style.css" />  
<script type="text/javascript">
function showstate(str){
if (str==""){
document.getElementById("txtHint").innerHTML="";return;}
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("txtHintstate").innerHTML=xmlhttp.responseText;}}
xmlhttp.open("GET","loadData.php?q="+str,true);
xmlhttp.send();}
function showcity(str){
if (str==""){
document.getElementById("txtHint").innerHTML="";
return;}
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("txtHintcity").innerHTML=xmlhttp.responseText;}}
xmlhttp.open("GET","city_ajax.php?q="+str,true);
xmlhttp.send();}
</script>

<? if($_REQUEST['add'] == 'success') { ?><div style="font-size:18px;color:#060;margin-top:10px;margin-bottom:10px;" align="center">Product Added Successfully.</div><? } ?>
<? if($_REQUEST['al'] == 'ex') { ?><div style="font-size:18px;color:#F00;margin-top:10px;margin-bottom:10px;" align="center">This Product Name Already Exists.</div><? } ?>
	
 <div id="content">
  <div class="breadcrumb">
      </div>
              <div class="box">
    <div class="heading">
      <h1><img src="view/image/home.png" alt="" /> Add Product</h1>
    </div>
    <div class="content" >
      <div class="overview" style="width:70%; margin-left:200px;" >
        <div class="dashboard-heading"><? echo $array['menu'] ?> Page</div>
        <div class="dashboard-content">
  <form action="" method="post" enctype="multipart/form-data" id="question" >
  
		<div class="add_row" style="margin-top:20px"><div id="wrapper">
		<div class="wrap_box" style="margin-left:100px;">
                
                	    <div style="float:left; width:200px;">Category Name&nbsp;<font color="#FF0000">*</font>	</div> 
                        <div class="wrap_box" style="margin-left:200px;">
              			<select name="cat_name" onChange="showstate(this.value)" style="width:195px;" required="required">
						<option value="" hidden="">Select Category</option>
						<?php while($rowCountry=mysql_fetch_array($resCountry)){?>
						<option value="<?php echo $rowCountry['category_name']?>"><?php echo $rowCountry['category_name']?></option>
						<?php }?>
						</select>
						</div>
                        <div class="spacer"></div>
                    	<br />
                    
                            <!--<div style="float:left;width:200px;">Sub-Category</div> 
							<div id="txtHintstate" style="margin-left:200px;">
                            <select  name="sub_cat"  onChange="showcity(this.value)" style="width:195px;" class="required">
                            <option hidden="">Select Sub-Category</option>
                            </select>
                            </div>
                            <div class="spacer"></div>
                            <br />-->
                              
                            <!--<div style="float:left;width:200px;">Sub-Sub-Category </div> 
							<div id="txtHintcity" style="margin-left:200px;">
                            <select  name="sub_cat"  onChange="showcity(this.value)" style="width:195px;" class="required">
                            <option hidden="">Select Sub-Sub-Category</option>
                            </select>
                            </div>
                            <div class="spacer"></div>
                              <br />-->
				        
                            <div style="float:left;width:200px;">Product Name&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input  type="text"  name="name" size="23" required="required">
                            </div><div class="spacer"></div>
                              <br />
                              
                           <!-- <div style="float:left;width:200px;">Backend Name&nbsp;<font color="#FF0000">*</font>	</div> 
							<div id="txtHintstate" style="margin-left:200px;">
                            <input  type="text" id="cat_tamil"  name="tname" size="23" class="required">
                            </div><div class="spacer"></div>
                              <br />-->
                              
                            <div style="float:left;width:200px;">Product ID&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <?php
								$sel="SELECT * FROM products ORDER BY serial DESC LIMIT 1";
								 $run=mysql_query($sel);
								 $array=mysql_fetch_array($run);
								 $pid=$array['serial'];
							 $pid1=$pid+1; 
							 $format_num = str_pad($pid1, 3, '0', STR_PAD_LEFT);
							 $pid1234="PR".$format_num."";
 							?>		
                            <input  type="text"  name="pid" size="19" required="required" value="<?php echo $pid1234; ?>" readonly="readonly" style="background:#CCC;">                            
                            </div><div class="spacer"></div>
                              <br />
                            <?php
 include_once 'ckeditor/ckeditor.php';
 ?>
                            <div style="float:left;width:200px;">Quantity&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input  type="text"  name="qnty" size="19" required="required">
                            </div><div class="spacer"></div>
                              <br />
                            <div style="float:left;width:200px;">Tax&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input type="radio" name="sale_tax" value="0" checked="checked">0%
				  			<input type="radio" name="sale_tax" value="0.05">5%
                 			<input type="radio" name="sale_tax" value="0.08">8%
                  			<input type="radio" name="sale_tax" value="0.145">14.5%
                            </div><div class="spacer"></div>
                                   <br />
                            <div style="float:left;width:200px;">Description&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input  type="text"  name="description" size="19" required="required">
                            </div><div class="spacer"></div>
                              <br />
                            <div style="float:left;width:200px;">Purchase Price&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input  type="text"  name="pur_price" size="19" required="required">
                            </div><div class="spacer"></div>
                              <br />
                              <div style="float:left;width:200px;">Sales Price&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input  type="text"  name="price" size="19" required="required">
                            </div><div class="spacer"></div>
                              <br />
                            <div style="float:left;width:200px;">Image &nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input  type="file"  name="small_jpg" size="55" required="required">
                            <font style="font-size:16px;"><!--(Only gif,jpg,jpeg,png are Acceptable)--></font>
                            </div><div class="spacer"></div>
    <br />
                           <div class="spacer"></div>
			   Content:
			   <br><br>
						<?php
 include_once 'ckeditor/ckeditor.php';
 $ckeditor = new CKEditor();
 $ckeditor->basePath = 'ckeditor/';
 $ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
 $ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images';
 $ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
 $ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
 $ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
 $ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
 $ckeditor->editor('details',$cnt);
                             ?><br>
                            <!--<div style="float:left;width:200px;">Picture_Jpg&nbsp;<font color="#FF0000">*</font>	</div> 
							<div id="txtHintstate" style="margin-left:200px;">
                            <input  type="file"  name="picture_jpg" size="55" class="required">
                            </div><div class="spacer"></div>-->  
                            
                       <div class="add_row" style="margin-left:195px;">
                      <p><span class="maintextbox"> <input type="submit" name="edit" id="button" value="Submit" > </span></p>
            </div></div><!-- End option--></div><!-- End add_row-->
                      </div>
   </form>
        </div>
      </div>
    </div>
  </div>
</div>
</div>
<?  include("footer.php"); ?>