<?php
  include('common/header.php');
?>

<div id="messages" style="color: green;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
<div class="row">
  <section class="panel panel-default">
     <header class="panel-heading bg-info lt font-bold"><?php echo 'Search results'; ?></header>
    <form method="post" action="<?php echo base_url()?>index.php/<?php echo PRODUCT_CATEGORY;?>search_category">

    <div class="panel-body bs-example form-horizontal">
     <div class="col-sm-12" >
                        <div class="col-sm-6">
                          <div class="form-group">
                            <label for="client_code" class="col-sm-3 control-label required"><?php echo ' Category Type'?>:</label>
                              <div class="col-sm-7">
                                 <select name="product_type"  id="product_type"  onchange="get_cateogry(this.value);" style="width: 250px;">
                                    <option value="default">Select Category Type</option>
                                      <option value="Dispenser" <?php if ($category_type=='Dispenser') {
                                        echo 'selected="selected"';
                                      } ?>>Dispenser</option> 
                                      <option value="Refil" <?php if ($category_type=='Refil') {
                                        echo 'selected="selected"';
                                      } ?> >Refill</option>                                    
                                 </select>
                    
                              </div>  
                          </div>
                      </div>     
                     <div class="col-sm-6">
                          <div class="form-group">
                            <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Product Category'?>:</label>
                              <div class="col-sm-7">
                                 <select name="product_category_type" id="product_category_type"  style="width: 250px;">
                                    <option>Select Product Category</option>
                                                                        
                                 </select>
                    
                              </div>  
                          </div>
                      </div>
                       <input type="hidden" name="product_category_type_id" value="<?php echo $product_category_name; ?>" id="product_category_type_id">
        </div>
        <div class="col-sm-12" >
                          <div class="col-sm-6">
                            <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Main Category'; ?>:</label>
                              <div class="col-sm-7">
                                <input type="text" name="main_category" value="<?php echo $main_category; ?>" id="main_category" placeholder="Main Category" class="form-control" maxlength="200" /> 
                                
                              </div>
                            </div>
                          </div>

        </div>
    </div>
    <div class="clearfix form-actions">
      <div class="col-md-offset-5 col-md-5">
        <button class="btn btn-info" type="submit" value="search" name="search">
         Search
        </button>
      </div>
    </div>
</form>
  </section>
</div>

<div class="row">
  <div class="col-xs-12">
  <section class="panel panel-default">
        
        <div class="panel-body bs-example form-horizontal">
          <div class="table-responsive">
            <table  id="example" class="table table-bordered dataTable" cellspacing="0" width="100%">
             <thead>
        <tr>
          <th>Sr No</th>    
          <?php foreach($fields as $field_name => $field_display): ?>
            <th <?php if ($sort_by == $field_name) echo "class=\"sorting_$sort_order\"" ?>>
            <?php echo anchor("gc/product_category/list_product_category/$query_id/$field_name/" .
            (($sort_order == 'asc' && $sort_by == $field_name) ? 'desc' : 'asc') ,
            $field_display); ?>     </th>
          <?php endforeach; ?>      
        <!--   <th>Product Category</th>
          <th>Main Category</th> -->
          <th>Action</th>
        </tr> 
      </thead>
       <tbody>
          <?php 
        $icnt=0;
     $count=count($product_category);
     if ($count>0) {  
       foreach ($product_category as  $value) {
         
          $product_category_id = $value->product_category_id;
         // $id=$this->encrypt->encode($product_category_id);
          $id=encrypt_decrypt_parameters($product_category_id,'encrypt');
          $product_category_name=$value->product_category_name;
          $pi=$value->pi;
          $pn=$value->pn;
          $category_type=$value->category_type;
          $is_active=$value->is_active;
          $icnt++;
          $sr=$offset+$icnt;
          //$parent_category_id = $value['parent_category_id'];
       ?> 
        <tr>
          <td><?php echo $sr; ?></td>
           <td><?php echo $category_type; ?></td>
          <td><?php echo $product_category_name;?></td>
          <?php if($pi==0){?>
            <td><?php echo'-'?></td><?php }else{?> 
          <td><?php echo $pn;?></td><?php } ?>

          <td>
            <b><a href="<?php echo base_url();?>index.php/gc/product_category/view_product_category/<?php echo $id?>">View</a> | <a href="<?php echo base_url();?>index.php/gc/product_category/manage_product_category/<?php echo $id ?>"> Edit |
             <?php if($is_active==0) {?>
                 <a href="<?php echo base_url();?>index.php/gc/product_category/enable_product_category/<?php echo $id ?>">Enable</a></b><?php }else{?>
                 <a href="<?php echo base_url();?>index.php/gc/product_category/disable_product_category/<?php echo $id ?> " onclick="return confirm('Are you sure you want to Disable?')">Disable</a></b><?php } ?>

          </td>
        </tr>
    <?php 
        // $srno=$srno+1;
       }
          }else{?>
              <td colspan="5" class="text-center">no data found</td>
         <?php } ?>
        </tbody>
     
            </table>
          </div>
            <?php
     if($num_results > 0) { ?>
      <div class="block"> </div>
        <div class="clearfix">
        <div class="row">
          <?php 
            if (strlen($pagination)): 
              $label_disp="Product Category";
              $data['label_disp']=$label_disp;
              $data['count']=$count;
              $this->load->view('pagination_view.php',$data);
            endif; ?>
        </div>
        </div>
        <div class="block"> </div>
      <?php } ?>
        </div>
      </section>
    
     <div class="clearfix form-actions">
      <div class="col-md-offset-5 col-md-5">
        <button class="btn btn-info" type="button" onclick="javascript:window.location='<?php echo base_url();?>index.php/gc/product_category/manage_product_category'">
          Add Product Category
        </button>
      </div>
    </div>
  </div>
</div>
<div>
  <!-- /.page-row -->
    <!-- /.page-content --> 
</div>
<!-- /.main-content --> 
</div>
<!-- /#ace-settings-container --> 
</div>
<!-- /.main-container-inner --> 
<?php
  include('common/footer.php');
?>
<script>
  var product_category_type_id = $('#product_category_type_id').val();
  var product_type2 = $('#product_type').val();
     //var country_id = $('#country_id').val();
    if (product_category_type_id=='default' || product_category_type_id=='' || product_category_type_id>0) {
      get_cateogry();
    }

  function get_cateogry(){
  //var fetched_state = $('#fetched_state').val();

  var product_type1 = $('#product_type').val();
  var product_category_type_id = $('#product_category_type_id').val();
  if (product_category_type_id>0) {
    var product_category_type_ids =product_category_type_id;
  }

  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/product_category/fetch_cateogory_types",
    method:"POST",
    data:{
        cateogory_type:product_type1,
        product_category_type:product_category_type_ids
    },
    success:function(data)
    {
     $('#product_category_type').html(data);
    }
  });

  // });
}
</script>
