<!-- Main Content -->

<div class="page-wrapper">

    <div class="container-fluid pt-25">

    	 <div class="row">

            <div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >

                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>

                <?php echo $this->session->flashdata('message'); ?>

            </div>

            <div class="alert alert-warning alert-dismissible" role="alert" <?php if($this->session->flashdata('emessage')==''){ ?> style="display:none" <?php } ?> >

                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>

                <?php echo $this->session->flashdata('emessage'); ?>

            </div>

        </div>

		<!-- Row -->

		<div class="row">

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

				<div class="panel panel-default card-view">

					<div class="panel-heading">

						<div class="pull-left">

							<h6 class="panel-title txt-dark">Edit Product</h6>

						</div>

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

					</div>

					<div class="panel-wrapper collapse in">

						<div class="panel-body">

							<div class="form-wrap">

								<form id="addProductFrom" class="form-horizontal" action="<?php echo base_url(A."/editProduct"); ?>" enctype="multipart/form-data" method='post'>

									<input type="hidden" name="productid" value="<?php echo $product['productid']; ?>" />
									<input type="hidden" name="url" value="<?php echo uri_string(); ?>" />
									<div class="row">

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

											<div class="form-group">

				                                <label class="col-sm-12">Product Title:</label>

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

				                                    <input type="text" name="product_name" class="form-control" placeholder="Enter Product Title" value="<?php echo $product['product_name']; ?>">

				                                </div>

				                            </div>

				                            <!-- <div class="form-group">

				                                <label class="col-sm-12">Product Slug:</label>

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

				                                    <input type="text" name="product_slug" class="form-control" placeholder="Enter Product Slug" value="<?php //echo $product['product_slug']; ?>">

				                                </div>

				                            </div> -->

				                            <div class="form-group">
				                                <label class="col-sm-12">Serial No:</label>
				                                <div class="col-sm-12">
				                                    <input type="text" name="product_sku" class="form-control" placeholder="Enter Serial No." value="<?php echo $product['product_sku']; ?>">
				                                </div>
				                            </div>
				                            <div class="form-group">
				                                <label class="col-sm-12">Product Price:</label>
				                                <div class="col-sm-12">
				                                    <input type="text" name="product_price" class="form-control" placeholder="Enter Product Price" value="<?php echo $product['product_price']; ?>">
				                                </div>
				                            </div>
				                            <div class="form-group">
				                                <label class="col-sm-12">Product Sale Price:</label>
				                                <div class="col-sm-12">
				                                    <input type="text" name="product_sale_price" class="form-control" placeholder="Enter Sale Price" value="<?php echo $product['product_sale_price']; ?>">
				                                </div>
				                            </div>
				                            <!-- <div class="form-group">
				                                <label class="col-sm-12">Unit Label:</label>
				                                <div class="col-sm-12">
				                                    <input type="text" name="unit_label" class="form-control" placeholder="Ex. - PK5" value="<?php //echo $product['unit_label']; ?>">
				                                </div>
				                            </div> -->
				                            <div class="form-group">
				                                <label class="col-sm-12">Product Stock:</label>
				                                <div class="col-sm-12">
				                                    <input type="text" name="product_stock" class="form-control" placeholder="Enter Product Stock" value="<?php echo $product['product_stock']; ?>">
				                                </div>
				                            </div>

				                            <div class="form-group">
				                                <label class="col-sm-12">Product Description:</label>
				                                <!-- <div class="col-sm-12">
				                                    <div class="fileUpload btn btn-default">
				                                       <span>Add Media</span>
				                                       <input id="file_1" type="file" name="" class="upload" />
				                                    </div>
				                                    <textarea name="product_description" class="ckeditor_full" id="ckeditor_full_1" placeholder="Enter Description"><?php //echo $product['product_description']; ?></textarea>
				                                </div> -->
				                                <div class="col-sm-12">
				                                    <textarea name="product_description" class="tinymce" placeholder="Enter Product Description"><?php echo $product['product_description']; ?></textarea>
				                                </div>
				                            </div>

				                            <div class="form-group">
				                                <label class="col-sm-12">Additional Information:</label>
				                                <div class="col-sm-12">
				                                    <textarea name="product_specification" class="tinymce" placeholder="Enter Product Specification"><?php echo $product['product_specification']; ?></textarea>
				                                </div>
				                            </div>

				                            <!-- <div class="form-group">
				                                <label class="col-sm-12">DIMENSIONS:</label>
				                                <div class="col-sm-12">
				                                    <textarea name="product_dimensions" class="tinymce" placeholder="Enter DIMENSIONS"><?php //echo $product['product_dimensions']; ?></textarea>
				                                </div>
				                            </div> -->

										</div>

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

				                            <?php 
				                            	$gcount = 0;
				                            	$gallery = $this->common->getData('product_media',array('product_id'=>$product['productid']));

				                            	if(isset($gallery) && !empty($gallery)){ 
				                            		$gcount = 1;
				                            ?>

				                            <div class="form-group">

				                            	<div class="row">

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

				                            			<?php foreach ($gallery as $key => $value) { 

			                                                if($value['product_image'] !==''){

			                                            ?>

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

			                                                    <div class="thumbnail count-thumb">

			                                                        <img src="<?php echo base_url($value['product_image']); ?>" style="width:100px; height:100px;">
			                                                        <span style="font-size:12px;"><input type="radio" class="showProductThumb" name="isThumb" data-id="<?php echo $product['productid']; ?>" value="<?php echo $value['id']; ?>" <?php echo($value['isThumb']==1)?'checked':''; ?> /> Show Thumbnail</span>

			                                                        <a href="javascript:void(0)" class="delete_productMedia" data-id="<?php echo $value['id'];?>" style="color:red;"><i class="fa fa-trash"></i></a>

			                                                    </div>

			                                                </div>

			                                            <?php } } ?>				                            			

				                            		</div>

				                            	</div>

				                            </div>

				                            <?php } ?>

				                            <div class="form-group">

				                                <label class="col-sm-12">Product Images (Size : 500x500 px) :</label>

				                                <div class="col-sm-12">
				                                    <input id="pimages" type="file" class="form-control" name="product_photos[]" <?php echo($gcount>0)?'':'required'; ?> multiple style="border:2px solid #9CCC65;">
				                                    <p id="imageError"></p>

				                                </div>

				                            </div>

				                            <?php /* $brand = $this->common->getData('brand'); ?>
				                            <div class="form-group">
				                                <label class="col-sm-12">Brand:</label>
				                                <div class="col-sm-12">
				                                    <select class="form-control" name="brandid">
				                                    	<option value="">Select Brand</option>
				                                    	<?php if(isset($brand) && !empty($brand)){ foreach($brand as $key=>$value) : ?>
				                                    		<option <?php echo($product['brandid']==$value['brandid'])?'selected':''; ?> value="<?php echo $value['brandid']; ?>"><?php echo $value['brand_name']; ?></option>
				                                    	<?php endforeach; } ?>
				                                    </select>
				                                </div>
				                            </div>
				                            <?php */ ?>

				                            <div class="form-group col-md-12">
				                            	<div class="thumbnail col-md-12">
					                            	<label class="col-sm-12">Select Category</label>
					                            	<div class="col-sm-12" style="overflow:scroll; height:400px;"><br>
						                            	<ul class="tristate" style="list-style-type:disc;margin-left:20px;line-height: 35px;">
								                            <?php if(!empty($category)){ 
								                            	echo editPostMenu($category,$product['product_category']);
								                            } ?>
								                        </ul>
								                    </div>
								                </div>
				                            </div>
				                            <!-- <div class="form-group col-md-12">
				                            	<div class="col-sm-12">
					                            	<p><input type="checkbox" name="new_arrival" value="1" <?php //echo($product['new_arrival']==1)?'checked':''; ?>> New</p>
					                            	<p><input type="checkbox" name="shop_rewards" value="1" <?php //echo($product['shop_rewards']==1)?'checked':''; ?>> Top</p>
					                            	<p><input type="checkbox" name="best_selling" value="1" <?php //echo($product['best_selling']==1)?'checked':''; ?>> Sale</p>
					                            </div>
				                            </div> -->

				                            <!-- <div class="form-group">
				                                <label class="col-sm-12">Front:</label>
				                                <div class="col-sm-12">
				                                    <textarea name="key_features" class="tinymce" placeholder="Enter DIMENSIONS"><?php //echo $product['key_features']; ?></textarea>
				                                </div>
				                            </div> -->

				                            <div class="form-group mb-0"> 

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

												  <button id="validBtn" type="submit" name="addcategory" class="btn btn-success btn-anim pull-right"><i class="icon-rocket"></i><span class="btn-text">Update Product</span></button>

												</div>

											</div>

										</div>

									</div>									

								</form>

							</div>

						</div>

					</div>

				</div>

			</div>

		</div>	

		<!-- /Row -->

	</div>

	<style type="text/css">

		label{color:#000;}

		.delete_productMedia{color: red;position: absolute;top: 0;right: 21px;}

	</style>

<script type="text/javascript">

	var site_url = "<?php echo base_url(); ?>";

	var urlLink = "<?php echo A; ?>";



    $(".delete_productMedia").on("click",function(){

        var id = $(this).attr("data-id");

        

        var result = confirm("Do you Want to delete?");

        if(result) {

            $.ajax({

                url: site_url+urlLink+"/deleteproductMultiMedia",

                type: "POST",

                data: "id="+id,

                success: function(result){

                    if(result==1)

                    {

                        location.reload();

                    }

                }

            });

        }

    });

</script>


<script type="text/javascript">
    $("#pimages").on("change", function(){
        var cthumb = $(".count-thumb").length;
        var uplaodFile = $("input[type='file']")[0].files.length;
        var items = $("input[type='file']")[0].files;
        if(cthumb !=8 && cthumb<=8){
        	if(cthumb ==4){
                 if(uplaodFile > 1) {
                 		alert('You can select only 1 images');
                        $("#imageError").html('<p style="color:red;">You can select only 1 images</p>');
                        $("#validBtn").prop("disabled",true);
                        $("#pimages").val('');
                 } else {
                        $("#imageError").html('');
                        $("#validBtn").prop("disabled",false);
                 }
            }else if(cthumb ==3){
                 if(uplaodFile > 2) {
                 		alert('You can select only 2 images');
                        $("#imageError").html('<p style="color:red;">You can select only 2 images</p>');
                        $("#validBtn").prop("disabled",true);
                        $("#pimages").val('');
                 } else {
                        $("#imageError").html('');
                        $("#validBtn").prop("disabled",false);
                 }
            }else if(cthumb ==2){
                 if(uplaodFile > 3) {
                 		alert('You can select only 3 images');
                        $("#imageError").html('<p style="color:red;">You can select only 3 images</p>');
                        $("#validBtn").prop("disabled",true);
                        $("#pimages").val('');
                 } else {
                        $("#imageError").html('');
                        $("#validBtn").prop("disabled",false);
                 }
            }else if (cthumb ==1){
               if(uplaodFile > 4) {
               			alert('You can select only 4 images');
                        $("#imageError").html('<p style="color:red;">You can select only 4 images</p>');
                        $("#validBtn").prop("disabled",true);
                        $("#pimages").val('');
                 } else {
                        $("#imageError").html('');
                        $("#validBtn").prop("disabled",false);
                 } 
            }else if (cthumb ==0){
                if(uplaodFile > 5) {
                		alert('You can select only 5 images');
                        $("#imageError").html('<p style="color:red;">You can select only 5 images</p>');
                        $("#validBtn").prop("disabled",true);
                        $("#pimages").val('');
                 } else {
                        $("#imageError").html('');
                        $("#validBtn").prop("disabled",false);
                 } 
            }
        }else{
        	alert('Already Uploaded 8 Images');
            $("#imageError").html('<p style="color:red;">Already Uploaded 8 Images.</p>');
            $("#pimages").val('');
        }
    });
</script>
<script>
	$('.showProductThumb').on('click', function () {
		var pid = $(this).attr('data-id');
		var id = $(this).val();
		var site_url = '<?php echo base_url(A); ?>';
		$.ajax({
			url: site_url+"/setProductImageThumb",
			type: "POST",
			data: "pid="+pid+"&id="+id,
			success: function(result){
				alert('Product Image Thumbnail Change');
			}
		});
	});
</script>
<script type="text/javascript">
   $(".add_fields").on("click", function(){
      var html = $(this).closest('.comments_html').clone();
      html.find("input").val("");
      html.find(".no-copy").html("");
      html.find(".add_fields").removeClass("add_fields btn-success").addClass("remove_fields btn-danger");
      html.find(".fa-plus").removeClass("fa-plus").addClass("fa-trash").closest('.comments_html');
      $(this).closest('.row').append(html);
   });
   $("body").on("click", ".remove_fields", function(){
      $(this).closest('.comments_html').remove();
   });
</script>
<script>
	$('.bget1').on('keyup', function () {
		var val = $(this).val();
		if(val){
			$('.bd').attr('disabled',true);
		}else{
			$('.bd').attr('disabled',false);
		}
	});
	$('.bd1').on('keyup', function () {
		var val = $(this).val();
		if(val){
			$('.bget').attr('disabled',true);
		}else{
			$('.bget').attr('disabled',false);
		}
	});
</script>
<style>
	input[type=number]::-webkit-inner-spin-button, 
	input[type=number]::-webkit-outer-spin-button { 
	  -webkit-appearance: none; 
	}

	input[type=number] {
	  -moz-appearance: textfield;
	}
</style>

<script src="<?php echo base_url("assets/admin/vendors/ckeditor/ckeditor.js"); ?>"></script>
<script src="<?php echo base_url("assets/admin/vendors/ckeditor/adapters/jquery.js"); ?>"></script>
<style type="text/css">
   #cke_1_contents{height:300px !important;}
   label{color:#000;}
   .fileUpload {
   position: relative;
   overflow: hidden;
   margin: 10px;
   }
   .fileUpload input.upload {
   position: absolute;
   top: 0;
   right: 0;
   margin: 0;
   padding: 0;
   font-size: 20px;
   cursor: pointer;
   opacity: 0;
   filter: alpha(opacity=0);
   }
</style>
<script type="text/javascript">
   $(function() {
        $('textarea.ckeditor_full' ).ckeditor({
            toolbarGroups: [
                     /*{ name: "document",    groups: [ "mode", "document" ] },            // Displays document group with its two subgroups.
                     { name: "basicstyles", groups: [ "basicstyles", "cleanup" ] },
                     { name: 'insert', groups: [ 'insert' ] },
                     { name: "links" },
                     { name: 'colors' },
                     { name: 'tools' },*/

              // { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },

              // { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },

              { name: 'links' },

              { name: 'insert' },

              // { name: 'forms' },

              // { name: 'tools' },

              // { name: 'document',       groups: [ 'mode', 'document', 'doctools' ] },

              { name: 'others' },

              // '/',

              { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },

              { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },

              { name: 'styles' },

              { name: 'colors' },

              { name: 'about' }
            ]
        });
    });
  	var site_url = "<?php echo base_url(); ?>";
  	var urlLink = "<?php echo A; ?>";
   	$("#file_1").on("change",function(){
   	    var file_data = $("#file_1").prop('files')[0];
   	    var form_data = new FormData();
   	    form_data.append('file', file_data);
   	    $.ajax({
   	        url: site_url+urlLink+"/uploadPostImage",
   	        dataType: 'text',
   	        cache: false,
   	        contentType: false,
   	        processData: false,
   	        data: form_data,
   	        type: 'post',
   	        success: function(result){
   	            var html='<img src="'+site_url+'assets/post-image/'+result+'" style="width:200px;">';
   	            CKEDITOR.instances['ckeditor_full_1'].insertHtml(html);
   	        }
   	    });
   	});
</script>
<script>
	$('body').on('click','.checkone', function () {
		var parent = $(this).attr('data-parent');
		$('#check'+parent).attr('checked',true);
	});
</script>
<style>
	li 
	{
		list-style: none!important;
	}
</style>