<script src="//cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script>

<div class="clearfix"></div>

  <div class="content-wrapper">

    <div class="container-fluid">

      <!-- Breadcrumb-->

     <div class="row pt-2 pb-2">

        <div class="col-sm-9">

		    <h4 class="page-title">Add/Edit Product</h4>

	   </div>

     

     </div>

    <!-- End Breadcrumb-->

      <div class="row">

			<div class="col-md-12">

			   <?php if($this->session->flashdata("msg")){echo $this->session->flashdata("msg"); }?>

               <div class="card">

                    <div class="card-header">Product Details 

                    <!--<button class="btn btn-warning btn-sm pull-right" type="submit" id="submitbtn">Submit</button>--></div>

                    <div class="card-body">
                    
                    

                     <?php if($this->uri->segment(3)){//$colors=explode(",",$pro->sizes);?>



                       <form action="<?php echo base_url();?>admin/edit_product_submit" method="post" enctype="multipart/form-data">

            

                       <input type="hidden" name="proid" value="<?php echo $this->uri->segment(3);?>"/>

            

                                <div class="col-md-10 col-md-offset-1" style="background:#FFF; padding:5px;">

            

            

                                  <div class="row">

            

                                      <div class="col-md-8">

            

                                       <div class="row">

            

                                        <div class="form-group col-md-6">

            

                                            <label for="email">Select MainCategory</label>

            

                                            <select class="cat form-control" name="mcat" id="mcat" required>

            

                                                <option value="">Select MainCategory</option>

            

                                                <?php $mcat=$this->db->get("mcategory")->result();

            

                                                    foreach($mcat as $mcat){?>

            

                                                <option <?php if($mcat->mid==$pro->mid){echo 'selected';}?> value="<?php echo $mcat->mid;?>"><?php echo $mcat->mcat_name;?></option>

            

                                                <?php }?>

            

                                            </select>

            

                                        </div>


                                        

            <div class="form-group col-md-8">

            

                                                <label for="pwd">Title</label>

            

                                                <input type="text" name="title" value="<?php echo $pro->title;?>" class="form-control" required>

            

                                            </div>

                                            <div class="form-group col-md-4">

            

                                            <label for="pwd"> Brand</label>

            

                                             <input type="text" name="brand" class="form-control" value="<?php echo $pro->brand;?>" required>

            

                                        </div>

                                        

                                        </div>

            

                                        

            

                                            

            

                                            

            

                                            

            

                                                 

            

                                      

            

                                      <div class="row">

            

                                                <div class="col-md-12">

            

                                                

            

                                                    <label for="price">Gallery Images (Upload Size Chart, BackSide Image and Other)</label>

            

                                        <input type="file" class="form-control" id="tg-photogallery"  onchange="preview_images();" name="test11[]"  multiple />

            

                                        <input type="hidden" name="oldimgs" value="<?php echo $pro->extimgs;?>" id="oldimgs" />

            

                                                    <div class="row">

            

                                                        <?php if($pro->extimgs!=''){$imgs=explode(",",$pro->extimgs);

            

                                                        foreach($imgs as $img){?>

            

                                                        <div class="col-md-3 text-center">

            

                                                        <img width="100%" src="<?php echo base_url();?>assets/images/products/<?php echo $img;?>" alt="">

            

                                       <a class="btn btn-xs btn-danger removeimg" id="<?php echo $pro->pid;?>" href="<?php echo $img;?>">remove</a></div>

            

                                                        <?php }}?>

            

                                                        </div>

            

                                                    <div class="row" id="image_preview"></div>

            

                                                </div>

            

                                            </div>

            

                                      </div>

            

                                      <div class="form-group col-md-4">

            

                                        <div class="form-group">

            

                                            <label for="image">Upload Preview Image</label>

            

                                            <input type="file" class="form-control" id="fileUpload" name="profile_img"  />

            

                                            <input type="hidden" name="oldimg" value="<?php echo $pro->img;?>" />

            

                                            <div class="form-group" id="image-container">

            

                                           <img class="img img-responsive" width="100%" src="<?php echo base_url();?>assets/images/products/<?php echo $pro->img;?>" /> 

            

                                                    </div>

            

                                          

            

                                           </div>

            

                                           <div class="form-group">

            

                                            <label>Add Tags </label><br/>

                                            <input  type="text" name="tags" class="form-control" data-role="tagsinput" value="<?php echo $pro->tags;?>"/>

            

                                            

            

                                           </div>

            

                                      </div>

            

                                     </div>

            

                                      <div class="row">

            

                                     

            

                                       <div class="form-group col-md-12"> <h5>Add Product Description</h5>

            

                <textarea class="summernote"  name="editor1"><?php echo $pro->sdesc;?></textarea>

            

                                                        </div>

            

                                                        </div>

            

                                                        <div class="form-group">

            

                                            <label class="control-label">Meta Title</label>

            

                                            <input type="text" name="meta_title" value="<?php echo $pro->meta_title;?>" class="form-control">

            

                                        </div>   

            

                                        <div class="form-group">

            

                                            <label class="control-label">Meta Keywords</label>

            

                                            <textarea class="form-control" rows="2"  name="meta_key"><?php echo $pro->meta_key;?></textarea>

            

                                        </div>

            

                                        <div class="form-group">

            

                                            <label class="control-label">Meta Description</label>

            

                                            <textarea class="form-control" rows="5" name="meta_desc"><?php echo $pro->meta_desc;?></textarea>

            

                                        </div>

            

                                        <div class="form-group">

            

                                            <label class="control-label">Og:Title</label>

            

                                            <input type="text" name="og_title" value="<?php echo $pro->og_title;?>" class="form-control">

            

                                        </div>

            

                                        <div class="form-group">

            

                                            <label class="control-label">Og:Description</label>

            

                                            <textarea class="form-control" rows="4" name="og_desc"><?php echo $pro->og_desc;?></textarea>

            

                                        </div>

            

                                </div>

            <button class="btn btn-success" type="submit" id="submitbtn">Submit</button>

                                <script>

            

                                $(document).ready(function(){

            

                                    $(".remove_tr").click(function(e){e.preventDefault();

            

                                        $(this).closest("tr").remove();

            

                                    });

            

                                        var i=1;

            

                 $("#add_row").click(function(){

            

                  $('#addr'+i).html("<td><input name='pack[]' type='text' placeholder='1 kg' class='form-control input-md'  /> </td><td><input  name='price[]' type='text' placeholder='100'  class='form-control input-md'></td><td><input  name='oprice[]' type='text' placeholder='80'  class='form-control input-md'></td><td><input  name='qty[]' type='text' placeholder='10'  class='form-control input-md'></td><td></td>");

            

            

            

                  $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');

            

                  i++; 

            

              });

            

                 $("#delete_row").click(function(){

            

                     if(i>1){

            

                     $("#addr"+(i-1)).html('');

            

                     i--;

            

                     }

            

                 });

            

                                });

            

                                </script>

            

                                </form>

            

                       <?php }else{?>

            			<h5 class="text-danger">Product Excel Upload</h5>
                        <small><a href="<?php echo base_url().'assets/sample_products.csv';?>"  download><i class="fa fa-download"></i> Download Sample Sheet</a></small>
                        <form class="form-inline" action="<?php echo base_url();?>admin/upload_product_excel" method="post" enctype="multipart/form-data">
                          <div class="form-group">
                            <input type="file" class="form-control" name="pfile" required>
                          </div>
                          <button type="submit" class="btn btn-success">Upload</button>
                        </form>
						<hr/>
                      <form action="<?php echo base_url();?>admin/add_product_submit" method="post" enctype="multipart/form-data" id="proform">          

            

                                 <div class="row">

            

                                      <div class="col-md-8">

            

                                        <div class="row">

            

                                        <div class="form-group col-md-6">

            

                                            <label for="email">Select MainCategory<b style="color:#F30;">*</b></label>

            

                                            <select class="cat form-control" name="mcat" id="mcat" required>

            

                                                <option value="">Select MainCategory</option>

            

                                                <?php $mcat=$this->db->get("mcategory")->result();

            

                                                    foreach($mcat as $cat){?>

            

                                                <option value="<?php echo $cat->mid;?>"><?php echo $cat->mcat_name;?></option>

            

                                                <?php }?>

            

                                            </select>

            

                                        </div>

                                        
                                        

                                        

                                        <!--<div class="form-group col-md-6">

            

                                            <label for="email" class="text-warning">Select Vendor</label>

            

                                            <select class=" form-control" name="vendor">

            

                                                <option value="">Select Vendor</option>

            

                                                <?php //$vn=$this->db->get("vendors")->result();

            

                                                       // foreach($vn as $v){?>

            

                                                <option value="<?php //echo $v->vid;?>"><?php //echo $v->v_name;?></option>

            

                                                <?php //}?>

            

                                            </select>

            

                                        </div>-->

            

                                         <div class="form-group col-md-8">

            									<label for="pwd"><b>Product Title</b><b style="color:#F30;">*</b></label>

                                                <input type="text" name="title" class="form-control" required>

            

                                            </div>

                                            <div class="form-group col-md-4">

            

                                            <label for="pwd"> Brand<b style="color:#F30;">*</b></label>

            						
                                            <input type="text" name="brand" class="form-control" required>

                                           

                                        </div>

            

                                        </div>

            

                                       

            							

                                        

            								<div class="row">

                                            <div class="form-group col-md-4">

            

                                                <label>Pack/Price Type</label>

            

                                                <select class="form-control" required name="ptype" id="ptype">

            

                                                    <option value="">Pack/Price Type</option>

            

                                                    <option value="Normal" selected>Normal</option>

            

                                                    <option value="Variant">Variant</option>

            

                                                </select>

            

                                            </div>

                                            <div class="form-group col-md-4">

            

                                                <label>Product Type</label>

            

                                                <select class="form-control" required name="box_type" id="box_type">

            

                                                    <option value="">Type</option>

            

                                                    <option value="Single" selected>Single</option>

            

                                                    <option value="Pieces">Box/Packet</option>

            

                                                </select>

            

                                            </div>

                                            

                                            <div class="form-group col-md-4" style="display:none;" id="piece_div">

            

                                                <label>No of Pieces</label>

            

                                                <input type="number" name="no_of_pc" class="form-control">

            

                                            </div>

                                            

                                            </div>

            

                                            <div class="row" id="Normal">

            

                                                <div class="col-md-3">

            

                                                    <label for="price">MRP</label>

            

                                                    <input type="text" class="form-control" name="nprice"  />

            

                                                </div>

            

                                                <div class="col-md-3">

            

                                                    <label for="price">Unit Rate</label>

            

                                                    <input type="text" class="form-control" name="unit_rate" />

            

                                                </div>

            

                                                <div class="col-md-3">

            

                                                    <label for="price">Case Rate</label>

            

                                                    <input type="number" class="form-control" name="case_rate" />

            

                                                </div>

            

                                            </div>

            

                                            <div id="Variant" style="display:none;">

            

                                            <br/>

            

                                            <table class="table table-bordered table-hover" id="tab_logic">

            

                                                        <thead><tr><th>#</th><th>Packing</th><th>Pieces</th><th>MRP</th><th>Unit Rate</th><th>Case Rate</th></tr></thead>

            

                                                        <tbody>

            

                                                            <tr id='addr0'>

            

                                                                <td>1</td>

            

<td><input type="text" name='pack[]'  placeholder='1 kg' class="form-control"/></td>
<td><input type="text" name='pieces[]' placeholder='80' class="form-control"/></td>
<td><input type="text" name='price[]' placeholder='100' class="form-control"/></td>
<td><input type="text" name='unit_rate[]' placeholder='80' class="form-control"/></td>
<td><input type="text" name='case_rate[]' placeholder='80' class="form-control"/></td>

            

                                                                <!--<td><input type="text" name='qty[]' placeholder='10' class="form-control"/></td>-->

            

                                                            </tr>

            

                                                            <tr id='addr1'></tr>

            

                                                        </tbody>

            

                                                    </table>  

            

            <button type="button" id="add_row" class="btn btn-success btn-sm pull-left">Add Row</button>

            <button  type="button" id='delete_row' class="pull-right btn-sm btn btn-danger">Delete Row</button><hr/>

            

            </div>

            

                                            <div class="form-group">

            

                                             <label for="price">Gallery Images</label>

            

                                              <input type="file" class="form-control" id="tg-photogallery"  onchange="preview_images();" name="test11[]"  multiple />

            

                                          

            

                                           </div>

            

                                    <div class="row" id="image_preview"></div>

            

                                    <!--<div class="row">

            

                                        <div class="col-md-12">

            

                                            <label for="price">Gallery Images</label>

            

                                          <input type="file" class="form-control" id="tg-photogallery"  onchange="preview_images();" name="test1[]"  multiple />

            

                                            <div class="row" id="image_preview"></div>

            

                                        </div>

            

                                    </div>-->

            

                                      </div>

            

                                      <div class="form-group col-md-4">

            

                                        <div class="form-group">

            

                                            <label for="image">Upload Preview Image</label>

            

                                            <input type="file" class="form-control" id="tg-photogallery2" onchange="preview_images2();" name="profile_img"  />

            

                                            <div class="form-group" id="image_preview2">

            

                  <img class="img img-responsive" width="100%" src="<?php echo base_url();?>assets/images/products/default.jpg" /> 

            

                                            </div>

            

                                           </div>

            

                                           <div class="form-group">

            

                                            <label>Add Tags</label><br/>

            								<input  type="text" name="tags" class="form-control" data-role="tagsinput" value="Grocery,Kirana,biscuits"/>

                                            <!--<textarea name="tags" class="form-control" rows="4" /></textarea>-->

            

                                           </div>

            

                                        </div>

            

                                      

            

                                     </div>

            

                                      <div class="row">

            

                                     

            

                                       <div class="form-group col-md-12"> <h5>Add Product Description</h5>

            

                <textarea class="summernote"  name="editor1"></textarea>

            

                                                        </div>

            

                                                        </div>

            

                                        <div class="form-group">

        

                                        <label class="control-label">Meta Title</label>

        

                                        <input type="text"  name="meta_title" class="form-control">

            

                                        </div>   

            

                                        <div class="form-group">

            

                                            <label class="control-label">Meta Keywords</label>

            

                                            <textarea class="form-control" rows="2" name="meta_key"></textarea>

            

                                        </div>

            

                                        <div class="form-group">

            

                                            <label class="control-label">Meta Description</label>

            

                                            <textarea class="form-control" rows="5" name="meta_desc"></textarea>

            

                                        </div>

            

                                        <div class="form-group">

            

                                            <label class="control-label">Og:Title</label>

            

                                            <input type="text" name="og_title" class="form-control">

            

                                        </div>

            

                                        <div class="form-group">

            

                                            <label class="control-label">Og:Description</label>

            

                                            <textarea class="form-control" rows="4" name="og_desc"></textarea>

            

                                        </div>

                                        <button class="btn btn-success" type="submit" id="submitbtn">Submit</button>

            

                                <script>

            

                                $(document).ready(function(){

            

                                        var i=1;

            

                 $("#add_row").click(function(){

            

                  $('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='pack[]' type='text' placeholder='1 kg' class='form-control input-md'  /> </td><td><input  name='pieces[]' type='text' placeholder='80'  class='form-control input-md'></td><td><input  name='price[]' type='text' placeholder='100'  class='form-control input-md'></td><td><input type='text'' name='unit_rate[]' placeholder='80' class='form-control'/></td><td><input type='text' name='case_rate[]' placeholder='80' class='form-control'/></td>");

            

            

            

                  $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');

            

                  i++; 

            

              });

            

                 $("#delete_row").click(function(){

            

                     if(i>1){

            

                     $("#addr"+(i-1)).html('');

            

                     i--;

            

                     }

            

                 });

            

                                });

            

                                </script>

            

                                </form>

            

                       <?php }?>

                    </div>

               </div>                  

            </div>

            

            

        </div><!--End Row-->

	  

	  <!--End Row-->



    </div>

    <!-- End container-fluid-->

    

    </div><!--End content-wrapper-->

   <!--Start Back To Top Button-->

    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>

    <!--End Back To Top Button-->

	

	<!--Start footer-->

	<footer class="footer">

      <div class="container">

        <div class="text-center">

          Copyright © 2022

        </div>

      </div>

    </footer>

	<!--End footer-->

   

  </div><!--End wrapper-->





  <!-- Bootstrap core JavaScript-->

	

	<!-- simplebar js -->



     <script>



		CKEDITOR.replace( 'editor1' );



		$("#fileUpload").on('change', function() {







  if (typeof(FileReader) == "undefined") {



    alert("Your browser doesn't support HTML5, Please upgrade your browser");



  } else {







    var container = $("#image-container");







    //remove all previous selected files



    container.empty();







    //create instance of FileReader



    var reader = new FileReader();



    reader.onload = function(e) {



      $("<img width='100%' />", {



        "src": e.target.result,"style": 'width:200px;'



      }).appendTo(container);



    }



    



    reader.readAsDataURL($(this)[0].files[0]);



  }});



$("#box_type").change(function(){

	var v=$(this).val();

	var ptype=$("#ptype").val();

	if(v=="Pieces" && ptype=='Normal'){

		$("#piece_div").show();

	}else{

		$("#piece_div").hide();

	}

});

   			$("#mcat").change(function(){



				var cid=$(this).val();



				$.ajax({



				 type: "POST",



				 url: '<?php echo base_url();?>admin/ajax_mcat',



				 data: {cid:cid},



				 success: function(res){



				//alert(res);



				$("#cat").html(res);



				}



				 }); 



			});



			$(".cat").change(function(){



				var cid=$(this).val();



				$.ajax({



				 type: "POST",



				 url: '<?php echo base_url();?>admin/ajax_showsubcat1',



				 data: {cid:cid},



				 success: function(res){



				//alert(res);



				$(".subcat").html(res);



				}



				 }); 



			});



		$(document).ready(function(){



			



			$("#pack_type").change(function(){

				

				



									var p=$(this).val();



									if(p=="Box"){



										$(".typebox").show();



										$(".type_cylinder").hide();



									}else{



										$(".typebox").hide();



										$(".type_cylinder").show();



									}



								});



			$("#rrp").keyup(function(){



				var rrp=$(this).val();



				var maxap=parseInt(rrp)*5;



				var minap=parseInt(rrp)*3;



				$("#maxap").val(maxap);



				$("#minap").val(minap);



			});



		$("#diameter").keyup(function(){var tot=1;



			var h=$("#height").val();



			var d=$("#diameter").val();



			var newv=(h*d*d*250).toFixed(3);



			$(".calcr").val(newv);



		});



		$(".calc").keyup(function(){var tot=1;



			var pt=$("#pack_type").val();



			if(pt=="Box"){



			$('.calc').each(function(){



				var total_amt=$(this).val();



				if(total_amt!="" && parseFloat(total_amt)>0){



					tot = parseFloat(total_amt) * tot;



				}



			 });



			 var tt=(tot*250).toFixed(3);



			 $(".calcr").val(tt);



			}else{



			var h=$("#height").val();



			var d=$("#diameter").val();



			//console.log(h);



//			console.log(d);



//			return false;



			var newv=(h*d*d*250).toFixed(3);



			$(".calcr").val(newv);



			}



		});



		$("form#proform").submit(function(){



			$("#submitbtn").attr("disabled",true);



			$("#msgg").slideDown();



		});



		$("#ptype").change(function(){

			

			var v=$("#ptype").val();

			var ptype=$(this).val();

			

			if(v=="Pieces" && ptype=='Normal'){

				$("#piece_div").show();

			}else{

				$("#piece_div").hide();

			}





			if(ptype=="Normal"){



				$("#Normal").show();



				$("#Variant").hide();	



			}



			if(ptype=="Variant"){



				$("#Normal").hide();



				$("#Variant").show();	



			}



		});



$(".removeimg").click(function(e){e.preventDefault();



				var img=$(this).attr("href");



				var aid=$(this).attr("id");



				var oldimgs=$("#oldimgs").val();



				$(this).closest("div.text-center").remove();



				$.ajax({



				 type: "POST",



				 url: '<?php echo base_url();?>admin/ajax_remove_imgs',



				 data: {aid:aid,img:img,oldimgs:oldimgs},



				 success: function(res){



				 $("#oldimgs").val(res);



				}



				 }); 



			});



			$(".removecols").click(function(e){e.preventDefault();



				var aid=$(this).attr("id");



				var oldcols=$("#oldcols").val();



				var oldcolor=$("#oldcolor").val();



				var old=$(this).attr("href");



				//alert(oldcols);alert(oldcolor);return false;



				$(this).closest("tr").remove();



				$.ajax({



				 type: "POST",



				 url: '<?php echo base_url();?>admin/ajax_remove_colors',



				 data: {aid:aid,oldcols:oldcols,oldcolor:oldcolor,old:old},



				 success: function(res){



					 alert(res);



					var r=res.split('|');



					var r1=r[0];//alert(r[0]);alert(r[1]); 



					alert(r1);



				    $("#oldcols").val(r1);



				// $("#oldcolor").val(r[1]);



				}



				 }); 



			});



			});



</script>



<script type="text/javascript">



function preview_images() 



{



	$('#image_preview').html('');



 var total_file=document.getElementById("tg-photogallery").files.length;



 for(var i=0;i<total_file;i++)



 {



  $('#image_preview').append("<div class='col-md-3'><img class='img-responsive' width='100%' src='"+URL.createObjectURL(event.target.files[i])+"'></div>");



 }



}



function preview_images2() 



{



	$('#image_preview2').html('');

	

	 var total_file=document.getElementById("tg-photogallery2").files.length;



 for(var i=0;i<total_file;i++)



 {



  $('#image_preview2').append("<img class='img-responsive' width='100%' src='"+URL.createObjectURL(event.target.files[i])+"'>");

 }



}







$(window).load(function() 



{$('#input-autocomplete').tagsInput({



		width: 'auto',







	});



})



</script>

	

  <script src="<?php echo base_url();?>adminassets/js/sidebar-menu.js"></script>

  <!-- Custom scripts -->

  <script src="<?php echo base_url();?>adminassets/js/app-script.js"></script>

  

  <!-- Vector map JavaScript -->

  <!-- Index js -->

  <script src="<?php echo base_url();?>adminassets/js/index.js"></script>

  

 

</body>

</html>

