<?php
  include('common/header.php');
  $value['product_category_name']="";
   $product_category_id="";
   $id='';
   $product_category_name='';
   $pc_Product_Category_Name = $this->_page_data['pc_Product_Category_Name'];
   $pc_Parent_Category_Name = $this->_page_data['pc_Parent_Category_Name'];
?>
<?php  
   if($this->uri->segment(4)){
   foreach ($product_category as  $value){
    $product_category_id=$value['product_category_id'];
    $id=$value['pi'];
    $product_category_name = $value['product_category_name']; 
   }
   }
 ?>
 <div id="messages" style="color: red;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
  <div class="">
    <div class="col-xm-12">
      <div class="widget-box light-border">
        
        <div class="widget-body">
          <div class="widget-main">
            <div class="row">
              <div class="col-sm-12">
                  <form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/<?php echo PRODUCT_CATEGORY;?>add_product_category" onsubmit="return validateForm()" name="manage_client" id="manage_client">
                    <input type="hidden" value="<?php echo $product_category_id ?>" name="hidden" id="hidden">
                  <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold">Category Details</header>
                  <!-- panel body start -->
                  <div class="panel-body bs-example form-horizontal">
                    <div class="">
                     <div class="hr hr12 dotted"></div>
                       <div class="">
                        <!-- main col-sm-12 -->
                      <div class="col-sm-12"> 

                        
                          <div class="col-sm-6">
                            <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $pc_Product_Category_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="product_category_name" value="<?php echo $product_category_name; ?>" id="product_category_name" placeholder="Product Category Name" class="form-control"  /> 
                                <span id="product_category_name1" maxlength="75" class="text-danger font-weight-bold"></span>
                                <?php echo form_error('product_category_name');?>    
                              </div>
                               
                            </div>
                          </div>
                       

                         <div class="col-sm-6">
                           <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required"><?php echo $pc_Parent_Category_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                 <select name="parent_category_name" id="parent_category_name">
                                  <!--<option value="default">Select Parent Category Name </option>-->
                                  <option <?php if($id==''){?> selected <?php }?> value="0">Main</option>
                                      <?php  
                                          foreach ($category as  $value1) {
                                           if ($id == $value1['product_category_id']) {?>
                                            <option value="<?php echo $value1['product_category_id'] ?>"selected><?php echo $value1['product_category_name'] ; ?></option>
                                            <?php
                                           }else{?>
                                           <option value="<?php echo $value1['product_category_id'] ?>"><?php echo $value1['product_category_name'] ; ?></option><?php 
                                          
                                          } 
                                        }
                                         
                                      ?>
                                           
                                  </select> 
                                  <div>
                                  <span id="parent_category_name1" class="text-danger font-weight-bold"></span>
                                <?php echo form_error('parent_category_name');?> 
                                </div>          
                              </div>
                            </div>
                          </div>
                            
 </div>


                    
                      

                        


                         <!-- </div> -->
                         <!-- main col-sm-12  close-->
                       </div> <!-- blank close -->
        </div><!-- blank close -->
      </div>   <!-- panel body close -->
    </section> <!-- section close -->

       <!-- customer contact start -->
   


    <!-- customer location start -->
    
              </div>
            </div>
          </div>  
        </div>
      </div>
    </div>
   
    <!-- /.col -->
  </div>
  <div class="clearfix form-actions">
    <div class="col-md-offset-5 col-md-5">
      
      <button class="btn btn-info" type="submit"  id="pc" >
         Submit
      </button>
    </div>
  </div>
   </form>
  <div class="space-4"></div>
    <!-- /.page-row -->
        <!-- /.page-content --> 
    </div>
    <!-- /.main-content --> 
  </div>
    <!-- /#ace-settings-container --> 
  </div>
  <!-- /.main-container-inner --> 
<?php
  include('common/footer.php');
?>
 
<script type="text/javascript">
    

function validateForm(){
  var error=false; 
  var product_category_name=$("#product_category_name").val();  
  if(product_category_name=='')
  {
    $("#product_category_name1").html("Please Enter Product Category Name");
    error=true; 
  }
  else
  {
    $('#product_category_name1').html("");
      
  }
  var parent_category_name=$("#parent_category_name").val();  
  if(parent_category_name=='default')
  {
    $("#parent_category_name1").html("Please Select Parent Category");
    error=true; 
  }
  else{
    $('#parent_category_name1').html("");
  }
  var hidden=$("#hidden").val();
   if(error==true)
  {
    return false;
  }
  else
  {
   if(hidden==''){
      var r = confirm("Are you sure you want to create Product Category!");
      if (r==true) {return true;}else{return false;} 
    }else{
      var r = confirm("Are you sure you want to Edit Product Category!");
      if (r==true) {return true;}else{return false;} 
    }
  }
    
}

  </script>