<?php
require_once("../config/config.php");
$getid=base64_decode($_REQUEST['id']);
////// get details of selected product////
$res_locdet=mysqli_query($link1,"SELECT * FROM product_master where id='".$getid."'")or die(mysqli_error($link1));
$row=mysqli_fetch_array($res_locdet);
////// final submit form ////
if($_POST[Submit]=="Update"){
	$color=strtoupper($_POST[color]);
	$category=strtoupper($_POST[category]);
	 ///////// explode hsn post values /////////////////////
	 $hsnvalue = explode("~",$_POST['hs_code']);
	 ////////////  explode hsncode ////////////////////////////
	 $hsncode = explode("_",$hsnvalue[0]);
	 
	if(mysqli_query($link1,"update product_master set productname='$_POST[pro_name]',productcode='$_POST[productcode]',productcolor='$color',productdesc='$_POST[pro_desc]',status='$_POST[status]',warranty_days='".$_POST['warranty_days']."',warranty_terms='".$_POST['warranty_terms']."',eol='".$_POST['eol']."',updatedate='$datetime',sim_slot='$_POST[model_type]',software_ver='$_POST[software_version]',type_id='$pad',hsn_code='".$_POST['hs_code']."' where id='$getid' ")or die("ER1".mysqli_error($link1)))
{
	////// insert in activity table////
	dailyActivity($_SESSION['userid'],$row['productcode'],"PRODUCT","UPDATE",$ip,$link1,"");
	//return message
	$msg="You have successfully updated details of reference ".$row['productcode'] ;
   }else{
	////// return message
	$msg="Something went wrong. Please try again.";
   }
	///// move to parent page
    header("Location:model_master.php?msg=".$msg."".$pagenav);
	exit;
}
?>
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title><?=siteTitle?></title>
 <script src="../js/jquery.js"></script>
 <link href="../css/font-awesome.min.css" rel="stylesheet">
 <link href="../css/abc.css" rel="stylesheet">
 <script src="../js/bootstrap.min.js"></script>
 <link href="../css/abc2.css" rel="stylesheet">
 <link rel="stylesheet" href="../css/bootstrap.min.css">
 <link rel="stylesheet" href="../css/jquery.dataTables.min.css">
 <script type="text/javascript" src="../js/jquery.dataTables.min.js"></script>
 <script>
$(document).ready(function(){
        $("#frm1").validate();
    });
	$(document).ready(function() {
		$('#eol').datepicker({
			format: "yyyy-mm-dd",
			todayHighlight: true,
			startDate: "<?=$todayt?>",
			autoclose: true
		});
	});
 </script>
 
<style>
.red_small{
	color:red;
}
</style>
<script type="text/javascript" src="../js/jquery.validate.js"></script>
<link rel="stylesheet" href="../css/datepicker.css">
 <script src="../js/bootstrap-datepicker.js"></script>
</head>
<body>
<div class="container-fluid">
  <div class="row content">
	<?php 
    include("../includes/leftnav2.php");
    ?>
    <div class="col-sm-9">
      <h2 align="center"><i class="fa fa-tablet"></i>&nbsp;&nbsp;View/Edit Product</h2><br/><br/>
      
      <div class="form-group"  id="page-wrap" style="margin-left:10px;" >
          <form  name="frm1" id="frm1" class="form-horizontal" action="" method="post">
		  
		  <div class="form-group">
            <div class="col-md-6"><label class="col-md-5 control-label">Product Category</label>
              <div class="col-md-5">
                <input type="text"  name="pcategory"    value="<?php echo getAnyDetails($row['productcategory'],"cat_name","catid" ,"product_cat_master"  ,$link1); ?>" class="form-control  " id="productcode" readonly />
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-5 control-label">Product SubCategory</label>
              <div class="col-md-5">
                <input type="text"  name="psubcat"  id="psubcat" value="<?php echo getAnyDetails($row['productsubcat'],"prod_sub_cat","psubcatid" ,"product_sub_category"  ,$link1);?>" class="form-control  "  readonly  />
              </div>
            </div>
          </div>
		  
		  
          <div class="form-group">
            <div class="col-md-6"><label class="col-md-5 control-label">Product Code<span class="red_small">*</span></label>
              <div class="col-md-5">
            <input type="text"  name="productcode"  value="<?php echo $row['productcode']; ?>" class="form-control required required" id="productcode" required />
			<input type="hidden"  name="productcode1" id="productcode1"  value="<?php echo $row['productcode']; ?>" >
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-5 control-label">HSN Code<span class="red_small">*</span></label>
              <div class="col-md-5">
              <select name="hs_code" id= "hs_code" class="form-control required"  required>
				 <option value="">--Please Select--</option>
	           <?php
                  $hsn=mysqli_query($link1,"Select distinct(hsn_code) from tax_hsn_master where status ='Active'");
				  while($row_gp=mysqli_fetch_array($hsn)){
				  ?>
                  <option value="<?=$row_gp['hsn_code']?>" <?php if($row['hsn_id']==$row_gp['id']){echo "selected";}?>>
                  <?=$row_gp['hsn_code']?>
                  </option>
                  <?php
				  }
                  ?>
                </select>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-md-6"><label class="col-md-5 control-label">Product Name<span class="red_small">*</span></label>
              <div class="col-md-5">
               <input type="text" name="pro_name" class="form-control mastername required" id="pro_name"  value="<?php echo $row[productname]; ?>"/> 
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-5 control-label">Product Color<span class="red_small">*</span></label>
              <div class="col-md-5">
                  <select name="color" class="form-control"  required>
				 <option value="">Please Select</option>
	           <?php
                  $color=mysqli_query($link1,"Select *  from colour_master");
				  while($row_gp=mysqli_fetch_array($color)){
				  ?>
                  <option value="<?=($row_gp[color])?>"<?php if($row[productcolor]==strtoupper($row_gp[color])){echo "selected";}?>>
                  <?=$row_gp[color]?>
                  </option>
                  <?php
				  }
                  ?>
                  <option value="NONE"<?php if($row[productcolor]=="NONE"){echo "selected";}?>>NONE</option>
                </select>
              </div>
            </div>
          </div>
          
          
          <div class="form-group">
            <div class="col-md-6"><label class="col-md-5 control-label">Brand<span class="red_small">*</span></label>
              <div class="col-md-5">
			  <input type="text" name="brand" class="form-control" id="brand" readonly value="<?php echo   getAnyDetails($row['brand'],"make","id" ,"make_master"  ,$link1); ?>"/> 
                  
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-5 control-label">Product Description<span class="red_small">*</span></label>
              <div class="col-md-5">
              <textarea name="pro_desc"  class="form-control addressfield required"  id="pro_desc" size="30" style="resize:vertical" required><?php echo $row[productdesc]; ?></textarea>
              </div>
            </div>
          </div>
		  <div class="form-group">
            <div class="col-md-6"><label class="col-md-5 control-label">Warranty Days</label>
              <div class="col-md-5">
                <input name="warranty_days" id="warranty_days" class="form-control number" type="text" value="<?=$row["warranty_days"];?>"/>
              </div>
            </div>
			<div class="col-md-6"><label class="col-md-5 control-label">EOL</label>
              <div class="col-md-5 input-append date">
                    <div style="display:inline-block;float:left;">
                        <input type="text" class="form-control span2" name="eol"  id="eol" style="width:160px;" value="<?=$row["eol"]?>">
                    </div>
                    <div style="display:inline-block;float:right;">&nbsp;<i class="fa fa-calendar fa-lg"></i></div>
                </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-md-6"><label class="col-md-5 control-label">Warranty Terms</label>
              <div class="col-md-5">
                <textarea name="warranty_terms" type="text" class="form-control addressfield" id="warranty_terms" size="30" value="" style="resize:vertical"><?php echo $row["warranty_terms"]; ?></textarea>  
              </div>
            </div>
			<div class="col-md-6"><label class="col-md-5 control-label">Status<span class="red_small">*</span></label>
              <div class="col-md-5">
              <select name="status"  class="form-control required" required >
				 <option value="">Plaese Select</option>
	           <option value="Active"<?php if($row['status']=="Active"){ echo "selected";}?>>Active</option>
	           <option value="Deactive"<?php if($row['status']=="Deactive"){ echo "selected";}?>>Deactive</option>
	           
            </select>
              </div>
            </div>
            
          </div> 
		
		   
          <div class="form-group">
            <div class="col-md-12" align="center">
              
            <input type="submit" class="btn btn-primary" name="Submit" id="" value="Update">
			
        <input title="Back" type="button" class="btn btn-primary" value="Back" onClick="window.location.href='model_master.php?<?=$pagenav?>'">
      
            </div>
			
          </div>
    </form>
      </div>

    </div>
    
  </div>
</div>
<?php
include("../includes/footer.php");
include("../includes/connection_close.php");
?>
</body>
</html>