<?php
$this->load->view('includes/top');

$pcatID = ($this->uri->segment(4) > 0) ? $this->uri->segment(4) : "0";
$pcatID = (int) $pcatID;
$selcatID = ($this->input->post('category_id') != '') ? $this->input->post('category_id') : $pcatID;
$selcatID = (int) $selcatID;

$media1 = (isset($media_res[0]['media'])) ? $media_res[0]['media'] : '';
$media2 = (isset($media_res[1]['media'])) ? $media_res[1]['media'] : '';
$media3 = (isset($media_res[2]['media'])) ? $media_res[2]['media'] : '';
$media4 = (isset($media_res[3]['media'])) ? $media_res[3]['media'] : '';
$media5 = (isset($media_res[4]['media'])) ? $media_res[4]['media'] : '';
$media6 = (isset($media_res[5]['media'])) ? $media_res[5]['media'] : '';
$media7 = (isset($media_res[6]['media'])) ? $media_res[6]['media'] : '';
$media8 = (isset($media_res[7]['media'])) ? $media_res[7]['media'] : '';
?>

<!--  BEGIN MAIN CONTAINER  -->

<link rel="stylesheet" type="text/css" href="<?php echo admin_url(); ?>assets/css/forms/switches.css">

<link rel="stylesheet" type="text/css" href="<?php echo admin_url(); ?>plugins/editors/markdown/simplemde.min.css">

<div class="main-container" id="container">

  <div class="overlay"></div>

  <div class="search-overlay"></div>

  <?php $this->load->view('includes/left'); ?>

  <!--  BEGIN CONTENT AREA  -->

  <div id="content" class="main-content">

    <div class="layout-px-spacing">

      <div class="row layout-top-spacing layout-spacing">

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

          <div class="statbox widget box box-shadow">

            <?php
            echo form_open_multipart(current_url_query_string(), 'id="data_form"');
            echo success_message();
            validation_message();
            error_message();
            ?>

            <div class="widget-header">

              <div class="row">

                <div class="col-xl-6 col-md-6 col-sm-6 col-6">

                  <h4><?php echo $headingTitle; ?></h4>

                </div>

                <div class="col-xl-6 col-md-6 col-sm-6 col-6 text-right">

                  <h4>

                    <a href="<?php echo base_url(); ?>wps-admin/products/index/" class="btn btn-danger btn-sm mb-2"><i class="fa fa-exclamation-circle"></i> Cancel</a>

                    <button type="submit" class="btn btn-primary btn-sm mb-2"><i class="fa fa-plus"></i> Save</button>

                    <!-- <button type="submit" class="btn btn-info btn-sm mb-2"><i class="fa fa-plus-square"></i> Save & New</button>

                    <button type="submit" class="btn btn-secondary btn-sm mb-2"><i class="fa fa-plus-square"></i> Save & Close</button> -->

                  </h4>

                </div>

              </div>

            </div>

            <div class="widget-content widget-content-area">

              <div class="table-responsive mb-4">

                <!--  <div class="form-group row  mb-4">
                     <label class="col-sm-3 col-form-label col-form-label-sm" for="category_id">Category <span class="red">*</span></label>
                     <div class="col-sm-6">
                     <select name="category_id[]" multiple="multiple" size="15" class="form-control" required>
                <?php echo get_nested_dropdown_menu(0, $res['category_id']); ?>
                   </select>
                <?php echo form_error('category_id[]'); ?>
                     </div>
                 </div> -->

                <div class="form-group row  mb-4">
                  <label class="col-sm-3 col-form-label col-form-label-sm" for="category_id">Category <span class="red">*</span></label>
                  <div class="col-sm-9">
                    <div style="max-height: 150px; overflow-y: scroll; border: 1px solid #e1e1e1; padding: 5px;">
                      <div class="col-md-12">
                        <?php echo get_nested_dropdown_menu(0, $res['category_id']); ?>
                      </div>
                    </div>
                    <?php echo form_error('category_id[]'); ?>
                  </div>
                </div>


                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="product_name">Product Name<span class="red">*</span></label>

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

                    <input type="text" class="url_creator form-control" id="product_name" name="product_name" value="<?php echo set_value('product_name', $res['product_name']); ?>" placeholder="Product Name" required /><?php echo form_error('product_name'); ?>

                    <span id="error_url_creator" class="red"></span>

                  </div>

                </div>

                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="friendlyUrl">Friendly Url <span class="red">*</span></label>

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

                    <input type="text" class="seo_friendly_url form-control" id="friendlyUrl" name="friendly_url" value="<?php echo set_value('friendlyUrl', $res['friendly_url']); ?>" required /><?php echo form_error('friendlyUrl'); ?>

                    <span id="error_friendly_url" class="red"></span>

                  </div>

                </div>

                <div class="form-group row  mb-4">
                  <label class="col-md-3 col-xs-12 control-label">Product Images</label>
                  <div class="col-md-2">
                    <div class="">
                      <img src="<?php echo get_image('products', $media1, '75', '125', 'R'); ?>" id="pic1" class="profile_picture" width="125" height="125"  /><div class="clearfix"></div>
                      <a href="javascript:void(0);" onclick="$('#img1').trigger('click');"  class="profile_picture">Add Image</a>
                      <?php
                      if ($media1) {
                        ?>
                        | <a href="javascript:void(0);" style="color:red;" data-mediaId="<?php echo $media_res[0]['id']; ?>" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>

                    <input id="img1" name="img1" type="file" onchange="document.getElementById('pic1').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />

                  </div>

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

                    <div class="">

                      <img src="<?php echo get_image('products', $media2, '75', '125', 'R'); ?>" id="pic2" class="profile_picture" width="125" height="125" /><div class="clearfix"></div>

                      <a href="javascript:void(0);" onclick="$('#img2').trigger('click');" class="profile_picture">Add Image</a>
                      <?php
                      if ($media2) {
                        ?>
                        | <a href="javascript:void(0);" style="color:red;"  data-mediaId="<?php echo $media_res[1]['id']; ?>" style="color:red;" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>

                    <input id="img2" name="img2" type="file" onchange="document.getElementById('pic2').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />

                  </div>

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

                    <div class="">

                      <img src="<?php echo get_image('products', $media3, '75', '125', 'R'); ?>" id="pic3" class="profile_picture" width="125" height="125" /><div class="clearfix"></div>

                      <a href="javascript:void(0);" onclick="$('#img3').trigger('click');" class="profile_picture">Add Image</a>
                      <?php
                      if ($media3) {
                        ?>
                        | <a href="javascript:void(0);" style="color:red;"  data-mediaId="<?php echo $media_res[2]['id']; ?>" style="color:red;" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>

                    <input id="img3" name="img3" type="file" onchange="document.getElementById('pic3').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />

                  </div>

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

                    <div class="">

                      <img src="<?php echo get_image('products', $media4, '75', '125', 'R'); ?>" id="pic4" class="profile_picture" width="125" height="125" /><div class="clearfix"></div>

                      <a href="javascript:void(0);" onclick="$('#img4').trigger('click');" class="profile_picture">Add Image</a>
                      <?php
                      if ($media4) {
                        ?>
                        | <a href="javascript:void(0);" style="color:red;" data-mediaId="<?php echo $media_res[3]['id']; ?>" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>

                    <input id="img4" name="img4" type="file" onchange="document.getElementById('pic4').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />

                  </div>
                  <label class="col-md-3 col-xs-12 control-label">&nbsp;</label>
                  <div class="col-md-2">
                    <div class="">
                      <img src="<?php echo get_image('products', $media5, '75', '125', 'R'); ?>" id="pic5" class="profile_picture" width="125" height="125" /><div class="clearfix"></div>
                      <a href="javascript:void(0);" onclick="$('#img5').trigger('click');" class="profile_picture">Add Image</a>
                      <?php
                      if ($media5) {
                        ?>
                        | <a href="javascript:void(0);" data-mediaId="<?php echo $media_res[4]['id']; ?>" style="color:red;" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>
                    <input id="img5" name="img5" type="file" onchange="document.getElementById('pic5').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />
                  </div>

                  <div class="col-md-2">
                    <div class="">
                      <img src="<?php echo get_image('products', $media6, '75', '125', 'R'); ?>" id="pic6" class="profile_picture" width="125" height="125" /><div class="clearfix"></div>
                      <a href="javascript:void(0);" onclick="$('#img6').trigger('click');" class="profile_picture">Add Image</a>
                      <?php
                      if ($media6) {
                        ?>
                        | <a href="javascript:void(0);" data-mediaId="<?php echo $media_res[5]['id']; ?>" style="color:red;" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>
                    <input id="img6" name="img6" type="file" onchange="document.getElementById('pic6').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />
                  </div>

                  <div class="col-md-2">
                    <div class="">
                      <img src="<?php echo get_image('products', $media7, '75', '125', 'R'); ?>" id="pic7" class="profile_picture" width="125" height="125" /><div class="clearfix"></div>
                      <a href="javascript:void(0);" onclick="$('#img7').trigger('click');" class="profile_picture">Add Image</a>
                      <?php
                      if ($media7) {
                        ?>
                        | <a href="javascript:void(0);" data-mediaId="<?php echo $media_res[6]['id']; ?>" style="color:red;" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>
                    <input id="img7" name="img7" type="file" onchange="document.getElementById('pic7').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />
                  </div>

                  <div class="col-md-2">
                    <div class="">
                      <img src="<?php echo get_image('products', $media8, '75', '125', 'R'); ?>" id="pic8" class="profile_picture" width="125" height="125" /><div class="clearfix"></div>
                      <a href="javascript:void(0);" onclick="$('#img8').trigger('click');" class="profile_picture">Add Image</a>
                      <?php
                      if ($media8) {
                        ?>
                        | <a href="javascript:void(0);" data-mediaId="<?php echo $media_res[7]['id']; ?>" style="color:red;" class="deleteImage">Delete</a>
                        <?php
                      }
                      ?>
                    </div>
                    <input id="img8" name="img8" type="file" onchange="document.getElementById('pic8').src = window.URL.createObjectURL(this.files[0])" class="validate" style="display: none;" />
                  </div>
                </div>
                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="product_price">Product Price <span class="red">*</span></label>

                  <div class="col-sm-6 row">

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

                      <input id="product_price" name="product_price" value="<?php echo set_value('product_price', $res['product_price']); ?>" type="text" required class="form-control"><?php echo form_error('product_price'); ?>

                      <label for="product_code"><span class="required">*</span>Product Price</label>

                    </div>

                    <!-- <div class="col-sm-6">

                      <input id="unit_value" name="discounted_price" value="<?php echo set_value('discounted_price', $res['product_discounted_price']); ?>" type="text" required class="form-control"><?php echo form_error('discounted_price'); ?>

                      <label for="product_code"><span class="required">*</span>Discounted Price</label> 

                    </div> -->

                  </div>

                </div>





                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="product_code">Product Additional Information <span class="red">*</span></label>

                  <div class="col-sm-6 row">

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

                      <input id="product_code" name="product_code" value="<?php echo set_value('product_code', $res['product_code']); ?>" type="text" class="form-control"><?php echo form_error('product_code'); ?>

                      <label for="product_code"><span class="required">*</span>Product Code</label>

                    </div>

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

                      <input id="product_qty" name="product_qty" value="<?php echo set_value('product_qty', $res['product_qty']); ?>" type="text" class="form-control"><?php echo form_error('product_qty'); ?>

                      <label for="product_qty"><span class="required">*</span>Product Qty</label>

                    </div>

                  </div>

                </div>

               <!-- <div class="form-group row  mb-4">
                  <label class="col-sm-3 col-form-label col-form-label-sm" for="youtube_id">Color </label>
                  <div class="col-sm-8">
                    <div class="" style="max-height: 150px; overflow: scroll; border: 1px solid #e1e1e1; padding: 5px;">
                      <div class="row">
                        <?php
                        $posted_color_arr = explode(',', $res['color_ids']);
                        if (is_array($colors) && !empty($colors)) {
                          foreach ($colors as $val) {
                            ?>
                            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-6">
                              <input type="checkbox" name="color_id[]" value="<?php echo $val['color_id']; ?>" <?php echo (in_array($val['color_id'], $posted_color_arr)) ? ' checked' : ''; ?>  /> <?php echo $val['color_name']; ?>
                            </div>
                            <?php
                          }
                        }
                        ?>
                      </div>
                    </div>
                    <?php echo form_error('color_id[]'); ?>
                  </div>
                </div>


                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="size">Quantity </label>

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

                    <div class="" style="max-height: 150px; border: 1px solid #e1e1e1; padding: 5px;">

                      <div class="row">

                        <?php
                        $posted_size_arr = explode(',', $res['size_ids']);

                        if (is_array($sizes) && !empty($sizes)) {

                          foreach ($sizes as $val) {
                            ?>

                            <div class="col-md-4 col-lg-4 col-sm-4 col-xs-6">

                              <input type="checkbox" name="size_id[]" value="<?php echo $val['size_id']; ?>" <?php echo (in_array($val['size_id'], $posted_size_arr)) ? ' checked' : ''; ?>  /> <?php echo $val['size_name']; ?>

                            </div>

                            <?php
                          }
                        }
                        ?>

                      </div>

                    </div>

                    <?php echo form_error('size_id[]'); ?>

                  </div>

                </div>





                <div class="form-group row  mb-4">
 
                   <label class="col-sm-3 col-form-label col-form-label-sm" for="youtube_id">Style</label>
 
                   <div class="col-sm-8">
 
                     <div class="" style="max-height: 150px; border: 1px solid #e1e1e1; padding: 5px;">
 
                       <div class="row">
 
                <?php
                $posted_style_arr = explode(',', $res['style_id']);

                if (is_array($styles) && !empty($styles)) {

                  foreach ($styles as $val) {
                    ?>
             
                                         <div class="col-md-4 col-lg-4 col-sm-4 col-xs-6">
             
                                           <input type="checkbox" name="style_id[]" value="<?php echo $val['style_id']; ?>" <?php echo (in_array($val['style_id'], $posted_style_arr)) ? ' checked' : ''; ?>  /> <?php echo $val['style_name']; ?>
             
                                         </div>
             
                    <?php
                  }
                }
                ?>
 
                       </div>
 
                     </div>
 
                <?php echo form_error('style_id[]'); ?>
 
                   </div>
 
                  </div>
 -->



                <!--div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="youtube_id">Rooms</label>

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

                    <div class="" style="max-height: 150px; border: 1px solid #e1e1e1; padding: 5px;">

                      <div class="row">

                <?php
                $posted_room_arr = explode(',', $res['room_id']);

                if (is_array($rooms) && !empty($rooms)) {

                  foreach ($rooms as $val) {
                    ?>

                                        <div class="col-md-4 col-lg-4 col-sm-4 col-xs-6">

                                          <input type="checkbox" name="room_id[]" value="<?php echo $val['room_id']; ?>" <?php echo (in_array($val['room_id'], $posted_room_arr)) ? ' checked' : ''; ?>  /> <?php echo $val['room_name']; ?>

                                        </div>

                    <?php
                  }
                }
                ?>

                      </div>

                    </div>

                <?php echo form_error('room_id[]'); ?>

                  </div>

                </div-->



                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="short_desc">Short Description </label>

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

                    <textarea name="short_desc" rows="5" cols="50" id="short_desc" ><?php echo set_value('short_desc', $res['short_desc']); ?></textarea> <?php echo form_error('short_desc'); ?>

                  </div>

                </div>



                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="description">Description <span class="red">*</span></label>

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

                    <textarea name="description" rows="5" cols="50" id="description" ><?php echo set_value('description', $res['products_description']); ?></textarea> <?php echo display_ckeditor($ckeditor1); ?><?php echo form_error('description'); ?>

                  </div>

                </div>



                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="specification">Specification </label>

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

                    <textarea name="specification" rows="5" cols="50" id="specification" ><?php echo set_value('specification', $res['specification']); ?></textarea> <?php echo display_ckeditor($ckeditor2); ?><?php echo form_error('specification'); ?>

                  </div>

                </div>





                <div class="">

                  <h6 class="" style="background-color: #e9e8e8; padding: 12px 10px 10px 20px;margin-bottom: 20px;">SEO Parameters</h6>

                </div>

                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="metaTitle">Meta Title</label>

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

                    <input type="text" class="form-control" id="metaTitle" name="metaTitle" value="<?php echo set_value('metaTitle', $metaDets['meta_title']); ?>" placeholder="Meta Title" /><?php echo form_error('title'); ?>

                  </div>

                </div>

                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="metaDescription">Meta Description</label>

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

                    <textarea class="form-control" id="description" name="metaDescription"><?php echo set_value('metaDescription', $metaDets['meta_description']); ?></textarea><?php echo form_error('metaDescription'); ?>

                  </div>

                </div>

                <div class="form-group row  mb-4">

                  <label class="col-sm-3 col-form-label col-form-label-sm" for="metaKeyword">Meta Keyword</label>

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

                    <input type="text" class="form-control" id="metaKeyword" name="metaKeyword" placeholder="Meta Keyword" value="<?php echo set_value('metaKeyword', $metaDets['meta_keyword']); ?>" /><?php echo form_error('metaKeyword'); ?>

                  </div>

                </div>



                <div class="widget-header">

                  <div class="row">

                    <div class="col-xl-6 col-md-6 col-sm-6 col-6">&nbsp;</div>

                    <div class="col-xl-6 col-md-6 col-sm-6 col-6 text-right">

                      <h4>

                        <a href="<?php echo base_url(); ?>wps-admin/products" class="btn btn-danger btn-sm mb-2"><i class="fa fa-exclamation-circle"></i> Cancel</a>

                        <input type="hidden" name="products_id" id="pg_recid" value="<?php echo $res['products_id']; ?>">

                        <button type="submit" class="btn btn-primary btn-sm mb-2"><i class="fa fa-plus"></i> Save</button>

                      <!-- <button type="submit" class="btn btn-info btn-sm mb-2"><i class="fa fa-plus-square"></i> Save & New</button>

                      <button type="submit" class="btn btn-secondary btn-sm mb-2"><i class="fa fa-plus-square"></i> Save & Close</button> -->

                      </h4>

                    </div>

                  </div>

                </div>

                <?php echo form_close(); ?>

              </div>

            </div>

          </div>

        </div>

        <div class="footer-wrapper">

          <div class="footer-section f-section-1">

            <p class="terms-conditions">All Rights Reserved. Powered By <a href="https://www.webpulseindia.com/" target="_blank">Webpulse</a></p>

          </div>

          <div class="footer-section f-section-2">

            <p class="">Coded with <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-heart"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path></svg></p>

          </div>

        </div>

      </div>

      <!--  END CONTENT AREA  -->

    </div>

    <!-- END MAIN CONTAINER -->

    <?php $this->load->view('includes/bottom'); ?>
    <script>
      $('.deleteImage').click(function () {
        var mid = $(this).attr('data-mediaId');
        $.post('<?php echo site_url(); ?>admin/products/deleteImage', {id: mid}, function (data) {
          alert(data);
          window.location.reload();
        });
      });
    </script>
    <?php die(); ?>

