<? include("header.php");



$id=$_REQUEST['id'];

include "checksession.php";

include ("include/db-connect.php");

if(isset($_REQUEST['submit']))
 {
	 //ANSWER OPTION 
	 
	   $sub_sub_cat_id=$_REQUEST['sub_sub_cat'];
	   if(is_numeric($sub_sub_cat_id))
	   {
       $sqlzdfsdf="SELECT * FROM sub_sub_category WHERE id = '$sub_sub_cat_id'"; 
	   $resultasdasd = mysql_query($sqlzdfsdf);
	   $rowffff = mysql_fetch_array($resultasdasd);
	   
	   $cat=$rowffff['cat'];
	   $sub_cat=$rowffff['sub_cat'];
	   $sub_sub_cat=$rowffff['sub_sub_cat'];
	   } 
	   else 
	   { 
	   $cat=$_REQUEST['category'];
	   $sub_cat=$_REQUEST['sub_cat'];
	   $sub_sub_cat=$_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);
	 
	  
	   $category=$_REQUEST['category'];
	   $sub_category=$_REQUEST['sub_cat'];
	   $name=$_REQUEST['name'];
	   $tname=$_REQUEST['tname'];
	   $product_id=$_REQUEST['pro_id'];
	   $quantity=$_REQUEST['qnty'];
	   $description=$_REQUEST['description'];
	   
	   $pur_price=$_REQUEST['pur_price'];
	   $pri=$_REQUEST['price'];
	   $details=$_REQUEST['details'];
	   $sale_tax= $_REQUEST['sale_tax'];
	
       $tax=$sale_tax*$pri;
		
	   $price=$tax+$pri;
       $tot_tax=$tax*$quantity;
	   
//---------------------Small photo Png  edit coding start------------------------------	
	  $small_jpg=$_FILES['small_jpg']['name'];
/*$supported_image = array(
    'gif',
    'jpg',
    'jpeg',
    'png'
);
$src_file_name = $small_jpg;
$ext = strtolower(pathinfo($src_file_name, PATHINFO_EXTENSION)); // Using strtolower to overcome case sensitive
if (in_array($ext, $supported_image)) 
{*/
       $viewid="select * from ".$PRODUCT." where `serial`='$id'";
       $resultid=mysql_query($viewid);
	   $rowid= mysql_fetch_row($resultid);
	   
	        
			   
	       $id1=$rowid[0]; 
		 
		   $photo_1=$rowid[12]; 
	
	 
	   
	        $filename=$id1.$small_jpg; 
		
	 
			  
  $uploaddir='sample/';
  $uploadfile=$uploaddir.$filename;
 

move_uploaded_file($_FILES['small_jpg']['tmp_name'],$uploadfile);
	
 if($small_jpg==NULL)
		  {
		  
   $imag_photo=$photo_1;
}
else
{

   $imag_photo=$uploadfile; 
 	
	}
	   
//---------------------Small photo Png edit coding end------------------------------		 
			 
		
  $upd_qur="UPDATE ".$PRODUCT." SET tname='$tname',category='$cat',sub_category='$sub_cat',sub_sub_cat='$sub_sub_cat',name='$name',product_id='$product_id',quantity='$quantity',description='$description',pur_price='$pur_price',in_price='$pri',price='$price',org_price='$price',org_price='$price',offper='0',tax_percen='$sale_tax',sale_tax='$tax',details='$details',small_jpg='$imag_photo',medium_jpg='$imag_photo1',large_jpg='$imag_phot2' WHERE serial='$id'";
		

$exce=mysql_query($upd_qur);
?><script>window.location="view_pro.php?edit=success&&id=<? echo $id; ?>";</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>


 
<div id="content">
  <div class="breadcrumb">
       <!-- <a href="http://amarasudhan.com/admin/index.php?route=common/home&amp;token=b735cc089ec2d51abb9a8e1901f501fb">Home</a>-->
      </div>
              <div class="box">
    <div class="heading">
      <h1><img src="view/image/home.png" alt="" /> Edit  Products</h1>
    </div>
    <div class="content" >
      <div class="overview" style="width:70%; margin-left:200px;" >
        <div class="dashboard-heading"><? echo $array['menu'] ?> Products</div>
        <div class="dashboard-content">
        
 <?php 
 $sel="select * from ".$PRODUCT." where serial=$id";
 $run=mysql_query($sel);
 $array=mysql_fetch_array($run);
  
 ?>
  <form action="" method="post" enctype="multipart/form-data" id="question" >
 <!-- <script type="text/javascript" src="../prototype.js"></script>
  <script type="text/javascript" src="../validation.js"></script>
  <script src="../ckeditor.js"></script>-->
  
       <?php
if($_REQUEST['add'] == 'success') {echo $result= '<h4 class="alert_success">Product Added Successfully </h4>';}

elseif($_REQUEST['add'] == 'fail'){echo $result= '<h4 class="alert_error">Product Already Exit</h4>';}
if($_REQUEST['edit'] == 'no') {echo $result= '<h4 class="alert_error">Upload Image File Only</h4>';}

?>	
		<div class="add_row" style="margin-top:20px"><div id="wrapper">
		<div class="wrap_box">
        
                       
                            <div style="float:left;width:200px;">Category Name&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <select name="category" onChange="showstate(this.value)" class="required">
                            <option value="<?php echo $array['category']; ?>"><?php echo $array['category']; ?></option>
						<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 &nbsp;<font color="#FF0000">*</font>	</div> 
							<div id="txtHintstate" style="margin-left:200px;">
                            <select  name="sub_cat"  onChange="showcity(this.value)" class="required">
                            <option value="<?php echo $array['sub_category']; ?>"><?php echo $array['sub_category']; ?></option>
                            </select>
                            </div><div class="spacer"></div>
                        <br />
                        
                        <? $categoryrr=$array['category'];
						$subcategoryddd=$array['sub_category']; ?>
                        <div style="float:left;width:200px;">Sub-Sub-Category </div> 
							<div id="txtHintcity" style="margin-left:200px;">
                            <select  name="sub_sub_cat"  style="width:195px;" class="required">
                            <option value="<?php echo $array['sub_sub_cat']; ?>" hidden=""><?php echo $array['sub_sub_cat']; ?></option>
                            <? $slec_sub_sub_cat=mysql_query("select * from `sub_sub_category` where `cat`='$categoryrr' and `sub_cat`='$subcategoryddd'");
							while($fetch_sub_sub_cat=mysql_fetch_array($slec_sub_sub_cat)){ ?>
                            <option value="<? echo $fetch_sub_sub_cat['sub_sub_cat']; ?>"><? echo $fetch_sub_sub_cat['sub_sub_cat']; ?></option>
                            <? } ?>
                            </select>
                            </div>
                            <div class="spacer"></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;">
                            <input  type="text"  name="pro_id"  class="required" value="<?php echo $array['product_id']; ?>">
                            </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"  class="required" value="<?php echo $array['name']; ?>">
                            </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"  name="tname" class="required" value="<?php echo $array['tname']; ?>">
                            </div><div class="spacer"></div> <br />--->
                            
                            <div style="float:left;width:200px;">Quantity&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <input  type="text"  name="qnty" class="required" value="<?php echo $array['quantity']; ?>">
                            </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" class="required" value="<?php echo $array['pur_price']; ?>">
                            </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" class="required" value="<?php echo $array['in_price']; ?>">
                            </div><div class="spacer"></div> <br />
                            
                            <div style="float:left;width:200px;">Tax&nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
                            <?php if($array['tax_percen']=='0') { ?>
                			<input type="radio" name="sale_tax" value="0" checked >0%<br>
                			<?php } else { ?>
                			<input type="radio" name="sale_tax" value="0" >0%<br>
                			<?php }
							if($array['tax_percen']=='0.05') {?>
							<input type="radio" name="sale_tax" value="0.05" checked >5%<br>
                			<?php } else { ?>
                			<input type="radio" name="sale_tax" value="0.05" >5%<br>
                			<?php }
							if($array['tax_percen']=='0.08') {?>
                			<input type="radio" name="sale_tax" value="0.08" checked >8%<br>
                			<?php } else { ?>
                			<input type="radio" name="sale_tax" value="0.08" >8%<br>
                			<?php }
							if($array['tax_percen']=='0.145') {?>
               				<input type="radio" name="sale_tax" value="0.145" checked >14.5%
                			<?php } else { ?>
                			<input type="radio" name="sale_tax" value="0.145" >14.5%
                			<?php } ?>
                            </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" class="required" value="<?php echo $array['description']; ?>">
                            </div><div class="spacer"></div>
                            <br />
                            <?php $cnt=$array['details']; ?>
                            <div style="float:left;width:200px;">Image &nbsp;<font color="#FF0000">*</font>	</div> 
							<div style="margin-left:200px;">
							  <input  type="file"  name="small_jpg">
			  				</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="submit" 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"); ?>