<script>
		$(document).ready(function(){
			$(".editzip").click(function(){
			var id=$(this).attr("id");
			$.ajax({
							 type: "POST",
							 dataType:"json",
							 url: '<?php echo base_url();?>admin/ajax_editzip',
							 data: {id:id},
							 success: function(response){
								 //alert(response);
								$("#width").val(response.width);
								$("#height").val(response.height);
								$("#stitch").val(response.stitch);
								$("#price").val(response.price);
							 	$("#oldzip").val(response.zip);
								$("#zid").val(response.zid);
								$("#exts").val(response.unzip);
							 }
							 });
			});
			
			$("form#updateform").submit(function(e){
								var sid=$("#sid").val();
								//alert(sid);
								e.preventDefault();
								$.ajax({
								url: "<?php echo base_url();?>admin/update_prozip", // Url to which the request is send
								type: "POST",             // Type of request to be send, called as method
								data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
								contentType: false,       // The content type used when sending data to the server.
								cache: false,             // To unable request pages to be cached
								processData:false,        // To send DOMDocument or non processed data file it is set to false
								success: function(data)   // A function to be called if request succeeds
								{
									alert(data);
									//window.location.href = '<?php echo base_url();?>admin/subcategory';
								//$("#tr"+sid+":first-child").text(data.subcat_name);
								//$("#respond").html(data);
								//$("#myModal").modal('toggle'); 
								//$("#cancelmodal").trigger("click");
								}
								});
		});
			
			
			
			 var next = 0;
  
			
			
			$("#noprice").click(function(){
				$("#price").slideToggle();
				$("#pr").val(0);$("#offerpr").val(0);
			});
			$("#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 />", {
        "src": e.target.result,"style": 'width:200px;'
      }).appendTo(container);
    }
    
    reader.readAsDataURL($(this)[0].files[0]);
  }});
			$(".cat").change(function(){
				var cid=$(this).val();
				$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/ajax_showsubcat',
				 data: {cid:cid},
				 success: function(res){
				//alert(res);
				$(".subcat").html(res);
				}
				 }); 
			});
		});
	</script>
<div class="vd_content-wrapper">
      <div class="vd_container">
        <div class="vd_content clearfix">
          <div class="vd_head-section clearfix">
            <div class="vd_panel-header">
              <ul class="breadcrumb">
                <li><a href="<?php echo base_url();?>admin">Home</a> </li>
                <li class="active">Add/Edit Product</li>
              </ul>
              
 
            </div>
          </div>
          <!-- vd_head-section -->
          <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog modal-sm">
              <!-- Modal content-->
              <div class="modal-content">
                <div class="modal-header vd_bg-blue vd_white">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
                  <h4 class="modal-title" id="myModalLabel">Update Variants</h4>
                </div>
                <div class="modal-body">
                  <form action="" method="post" enctype="multipart/form-data" id="updateform">
                  <input type="hidden" id="zid" name="zid" value="" />
                  <div class="row">
                      <div class="form-group col-md-6">
                        <label for="email">Width</label>
                        <input type="text"  class="form-control" name="width" id="width">
                      </div>
                      <div class="form-group col-md-6">
                        <label for="email">Height</label>
                        <input type="text"  class="form-control" name="height" id="height">
                      </div>
                  </div>
                  <div class="form-group">
                    <label for="email">Stitch Count</label>
                    <input type="text"  class="form-control" name="stitch" id="stitch">
                  </div>
                  <div class="form-group">
                    <label for="email">Price</label>
                    <input type="text"  class="form-control" name="price" id="price">
                  </div>
                  <div class="form-group">
                    <label for="email">Zip</label>
                    <input type="file"  class="form-control" name="img" id="zip">
                    <input type="hidden" name="oldzip" id="oldzip" /> 
                    <input type="hidden" name="exts" id="exts" /> 
                  </div>
                  <br/>
                  <button type="submit" class="btn btn-primary" name="submit">Update</button>
                  <button type="button" class="btn btn-default" data-dismiss="modal" id="cancelmodal">Cancel</button>
                </form>
                
                </div>
                
              </div>
              
            </div>
  		</div>
          <div class="vd_title-section clearfix">
            <div class="vd_panel-header">
              <h1>Add/Edit Product</h1>
              
<!-- vd_panel-menu --> 
            </div>
            <!-- vd_panel-header --> 
          </div>
          <!-- vd_title-section -->
          
          <div class="vd_content-section clearfix">
           <?php if($this->uri->segment(3)){$colors=explode(",",$pro->colors);?>
           <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;">
                    <?php if($this->session->flashdata("msg")!==""){echo $this->session->flashdata("msg"); }?>
                    <ul class="nav nav-tabs">
                      <li class="active"><a href="#tab21" data-toggle="tab"><strong>Product Info</strong></a></li>
                      <li><a href="#tab22" data-toggle="tab"><strong>Seo Details</strong></a></li>
                      <li class="pull-right">
                      <button class="btn btn-success" type="submit">Update Design</button></li>
                      
                    </ul>
                    <div class="tab-content  mgbt-xs-20">
                      <div class="tab-pane active col-md-10" id="tab21"><br/>
                      	<div class="row">
                          <div class="col-md-8">
                          <div class="row">
                          	<div class="form-group col-md-6">
                                <label for="email">Select Category</label>
                                <select class="cat form-control" name="cat" id="cat">
                                                <option value="">Select Category</option>
                                                <?php foreach($cats as $cat){?>
                        <option <?php if($pro->cid==$cat->cid){echo 'selected';}?> value="<?php echo $cat->cid;?>"><?php echo $cat->cat_name;?></option>
                                                <?php }?>
                                            </select>
                            
                            </div>
                            <div class="form-group col-md-6">
                                <label for="pwd">Select Subcategory</label>
                               <select class="subcat form-control" id="subcat" name="subcat">
                                                 <?php $subc=$this->db->get_where("subcategory",array("cid"=>$pro->cid))->result();
												 		foreach($subc as $sub){?>
                        <option value="<?php echo $sub->sid;?>" <?php if($pro->sid==$sub->sid){echo 'selected';}?>><?php echo $sub->subcat_name;?></option><?php }?>
                                            </select>
                            </div> 
                            </div>
							<div class="row">
                                <div class="form-group col-md-7">
                                    <label for="pwd">Title</label>
                                    <input type="text" name="title" value="<?php echo $pro->title;?>" class="form-control" required>
                                </div>
                                <div class="col-md-5">
                                 <label for="pwd">For Gender</label>
                                    <div class="vd_radio radio-success">
                                    <input type="radio" name="gender" id="optionsRadios3" value="Male" <?php if($pro->gender=="Male"){echo "checked";}?>>
                                    <label  for="optionsRadios3"> Male </label>
                                    <input type="radio" name="gender" id="optionsRadios4" <?php if($pro->gender=="Female"){echo "checked";}?> value="Female">
                                    <label  for="optionsRadios4"> Female </label>
                                    </div>
                                 </div>
                                </div>
                                <div class="row">
                                	<div class="col-md-6">
                                    	<label for="price">Price</label>
                                        <input type="number" class="form-control" required name="price" value="<?php echo $pro->price;?>"  />
                                    </div>
                                    <div class="col-md-6">
                                    	<label for="price">Offer Price</label>
                                        <input type="number" class="form-control" name="oprice" value="<?php echo $pro->oprice;?>" />
                                    </div>
                                </div>	
                                <div class="vd_checkbox checkbox-danger">
        <input type="checkbox" value="Black" name="formats[]" id="checkbox-1" <?php if(in_array("Black",$colors)){echo "checked";}?> >
        <label for="checkbox-1"> Black </label>
        <input type="checkbox" value="White" name="formats[]" id="checkbox-2" <?php if(in_array("White",$colors)){echo "checked";}?> >
        <label for="checkbox-2"> White  </label>
        <input type="checkbox" value="Green" name="formats[]" id="checkbox-3" <?php if(in_array("Green",$colors)){echo "checked";}?>>
        <label for="checkbox-3"> Green  </label>
        <input type="checkbox" value="Yellow" name="formats[]" id="checkbox-4" <?php if(in_array("Yellow",$colors)){echo "checked";}?>>
        <label for="checkbox-4"> Yellow  </label>
        <input type="checkbox" value="Blue" name="formats[]" id="checkbox-5" <?php if(in_array("Blue",$colors)){echo "checked";}?>>
        <label for="checkbox-5"> Blue  </label>
        <input type="checkbox" value="Orange" name="formats[]" id="checkbox-6" <?php if(in_array("Orange",$colors)){echo "checked";}?>>
        <label for="checkbox-6"> Orange  </label>
        <input type="checkbox" value="Purple" name="formats[]" id="checkbox-7" <?php if(in_array("Purple",$colors)){echo "checked";}?>>
        <label for="checkbox-7"> Purple  </label>
        <input type="checkbox" value="Pink" name="formats[]" id="checkbox-8" <?php if(in_array("Pink",$colors)){echo "checked";}?>>
        <label for="checkbox-8"> Pink   </label>
        <input type="checkbox" value="Brown" name="formats[]" id="checkbox-9" <?php if(in_array("Brown",$colors)){echo "checked";}?>>
        <label for="checkbox-9"> Brown   </label>
        <input type="checkbox" value="Grey" name="formats[]" id="checkbox-0" <?php if(in_array("Grey",$colors)){echo "checked";}?>>
        <label for="checkbox-0"> Grey </label>
        <input type="checkbox" value="Red" name="formats[]" id="checkbox-10" <?php if(in_array("Red",$colors)){echo "checked";}?>>
        <label for="checkbox-10"> Red </label>
        <input type="checkbox" value="Golden" name="formats[]" id="checkbox-11" <?php if(in_array("Golden",$colors)){echo "checked";}?>>
        <label for="checkbox-11"> Golden </label>
        <input type="checkbox" value="Peach" name="formats[]" id="checkbox-12" <?php if(in_array("Peach",$colors)){echo "checked";}?>>
        <label for="checkbox-12"> Peach </label>
                          </div>
                          		<div class="row">
                                	<div class="col-md-12">
                                    <div class="row">
                                            <?php $imgs=explode(",",$pro->gallery);
											foreach($imgs as $img){?>
                                            <div class="col-md-3 text-center">
                                            <img 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>
                                    	<label for="price">Gallery Images</label>
                            <input type="file" class="form-control" id="tg-photogallery"  onchange="preview_images();" name="test1[]"  multiple />
                            <input type="hidden" name="oldimgs" value="<?php echo $pro->gallery;?>" id="oldimgs" />
                            <input type="hidden" name="proid" value="<?php echo $pro->pid;?>" />
                                        <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" src="<?php echo base_url();?>assets/images/products/<?php echo $pro->img;?>" /> 
                                        </div>
                              
                               </div>
                                <label for="image">Product Tags</label>
                               <input id="input-autocomplete"  type="text" class="tags" value="<?php echo $pro->tags;?>" name="tags" placeholder="Add tags and hit Enter" /> 
                          </div>
                         </div>
                          
                      </div>
                      <div class="tab-pane col-md-10" id="tab22"><br/>
                            <div class="form-group">
                                <label class="control-label">Meta Title</label>
                                <input type="text" required 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" value="<?php echo $pro->meta_key;?>" 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"><?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" value="<?php echo $pro->og_desc;?>" name="og_desc"></textarea>
                            </div>
                      </div>
                      <div class="tab-pane" id="tab23"> Tab 3 </div>
                    </div>
                    </div></form>
           
           <?php }else{?>
          <form action="<?php echo base_url();?>admin/add_product_submit" method="post" enctype="multipart/form-data">
                    <div class="col-md-10 col-md-offset-1" style="background:#FFF; padding:5px;">
                    <?php if($this->session->flashdata("msg")!==""){echo $this->session->flashdata("msg"); }?>
                    <ul class="nav nav-tabs">
                      <li class="active"><a href="#tab21" data-toggle="tab"><strong>Product Info</strong></a></li>
                      <li><a href="#tab22" data-toggle="tab"><strong>Seo Details</strong></a></li>
                      <li class="pull-right">
                      <button class="btn btn-success" type="submit">Add Design</button></li>
                      
                    </ul>
                    <div class="tab-content  mgbt-xs-20">
                      <div class="tab-pane active col-md-10" id="tab21"><br/>
                      	<div class="row">
                          <div class="col-md-8">
                          <div class="row">
                          	<div class="form-group col-md-6">
                                <label for="email">Select Category</label>
                                <select class="cat form-control" name="cat" id="cat" required>
                                    <option value="">Select Category</option>
                                    <?php foreach($cats as $cat){?>
                                    <option value="<?php echo $cat->cid;?>"><?php echo $cat->cat_name;?></option>
                                    <?php }?>
                                </select>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="pwd">Select Subcategory</label>
                                <select class="subcat form-control" id="subcat" name="subcat" required>
                                    <option value="">Select Subcategory</option>
                                </select>
                            </div> 
                            </div>
							<div class="row">
                                <div class="form-group col-md-7">
                                    <label for="pwd">Title</label>
                                    <input type="text" name="title" class="form-control" required>
                                </div>
                                <div class="col-md-5">
                                 <label for="pwd">For Gender</label>
                                    <div class="vd_radio radio-success">
                                    <input type="radio" name="gender" id="optionsRadios3" value="Male" checked>
                                    <label  for="optionsRadios3"> Male </label>
                                    <input type="radio" name="gender" id="optionsRadios4" value="Female">
                                    <label  for="optionsRadios4"> Female </label>
                                    </div>
                                 </div>
                                </div>
                                <div class="row">
                                	<div class="col-md-6">
                                    	<label for="price">Price</label>
                                        <input type="number" class="form-control" required name="price"  />
                                    </div>
                                    <div class="col-md-6">
                                    	<label for="price">Offer Price</label>
                                        <input type="number" class="form-control" name="oprice" />
                                    </div>
                                </div>	
                                <div class="vd_checkbox checkbox-danger">
                            <input type="checkbox" value="Black" name="formats[]" id="checkbox-1" >
                            <label for="checkbox-1"> Black </label>
                            <input type="checkbox" value="White" name="formats[]" id="checkbox-2" >
                            <label for="checkbox-2"> White  </label>
                            <input type="checkbox" value="Green" name="formats[]" id="checkbox-3" >
                            <label for="checkbox-3"> Green  </label>
                            <input type="checkbox" value="Yellow" name="formats[]" id="checkbox-4" >
                            <label for="checkbox-4"> Yellow  </label>
                            <input type="checkbox" value="Blue" name="formats[]" id="checkbox-5" >
                            <label for="checkbox-5"> Blue  </label>
                            <input type="checkbox" value="Orange" name="formats[]" id="checkbox-6" >
                            <label for="checkbox-6"> Orange  </label>
                            <input type="checkbox" value="Purple" name="formats[]" id="checkbox-7" >
                            <label for="checkbox-7"> Purple  </label>
                            <input type="checkbox" value="Pink" name="formats[]" id="checkbox-8" >
                            <label for="checkbox-8"> Pink   </label>
                            <input type="checkbox" value="Brown" name="formats[]" id="checkbox-9" >
                            <label for="checkbox-9"> Brown   </label>
                            <input type="checkbox" value="Grey" name="formats[]" id="checkbox-0" >
                            <label for="checkbox-0"> Grey </label>
                            <input type="checkbox" value="Red" name="formats[]" id="checkbox-10" >
                            <label for="checkbox-10"> Red </label>
                            <input type="checkbox" value="Golden" name="formats[]" id="checkbox-11" >
                            <label for="checkbox-11"> Golden </label>
                            <input type="checkbox" value="Peach" name="formats[]" id="checkbox-12" >
                            <label for="checkbox-12"> Peach </label>
                          </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="fileUpload" name="profile_img"  />
                                <div class="form-group" id="image-container">
                               <img class="img img-responsive" src="<?php echo base_url();?>assets/images/products/default.jpg" /> 
                                        </div>
                              
                               </div>
                               <label for="image">Product Tags</label>
                               <input id="input-autocomplete"  type="text" class="tags" name="tags" placeholder="Add tags and hit Enter" /> 
                          </div>
                         </div>
                          
                      </div>
                      <div class="tab-pane col-md-10" id="tab22"><br/>
                            <div class="form-group">
                                <label class="control-label">Meta Title</label>
                                <input type="text" required 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>
                      </div>
                      <div class="tab-pane" id="tab23"> Tab 3 </div>
                    </div>
                    </div></form>
           <?php }?>
          </div>
          <!-- .vd_content-section --> 
          
        </div>
        <!-- .vd_content --> 
      </div>
      <!-- .vd_container --> 
    </div>
    <!-- .vd_content-wrapper --> 
    
    <!-- Middle Content End --> 
    
  </div>
  <!-- .container --> 
</div>
<!-- .content -->

<!-- Footer Start -->
  <footer class="footer-1"  id="footer">      
    <div class="vd_bottom ">
        <div class="container">
            <div class="row">
              <div class=" col-xs-12">
                <div class="copyright">
                  	Copyright &copy;2018 HadesIndia. All Rights Reserved 
                </div>
              </div>
            </div><!-- row -->
        </div><!-- container -->
    </div>
  </footer>
<!-- Footer END -->
  

</div>

<!-- .vd_body END  -->
<a id="back-top" href="#" data-action="backtop" class="vd_back-top visible"> <i class="fa  fa-angle-up"> </i> </a>

<!--
<a class="back-top" href="#" id="back-top"> <i class="icon-chevron-up icon-white"> </i> </a> -->

<!-- Javascript =============================================== --> 
<!-- Placed at the end of the document so the pages load faster --> 

<script type="text/javascript" src='<?php echo base_url();?>adminassets/plugins/jquery-ui/jquery-ui.custom.min.js'></script>
<script>
$(".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);
				}
				 }); 
			});
</script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>

<script type="text/javascript" src="<?php echo base_url();?>adminassets/js/caroufredsel.js"></script> 
<script type="text/javascript" src="<?php echo base_url();?>adminassets/js/plugins.js"></script>

<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/breakpoints/breakpoints.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/dataTables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/prettyPhoto-plugin/js/jquery.prettyPhoto.js"></script> 
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/tagsInput/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/tagsInput/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/bootstrap-switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/blockUI/jquery.blockUI.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/plugins/pnotify/js/jquery.pnotify.min.js"></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-4'><img class='img-responsive' src='"+URL.createObjectURL(event.target.files[i])+"'></div>");
 }
}

$(window).load(function() 
{$('#input-autocomplete').tagsInput({
		width: 'auto',

	});
})
</script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/js/theme.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>adminassets/custom/custom.js"></script>


</body>
</html>