<?php 
  include('common/header.php');
  error_reporting(E_ALL);
?>
<?php 
  if ($this->uri->segment(4)) {

   foreach ($product as  $value){
    $product_id=$value['product_id'];
    $product_category_id=$value['product_category_id'];
   }
  }
 ?>
<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-header header-color-grey">
          <h4 class="smaller">
            Products
          </h4>
        </div>
        <div class="widget-body">
          <div class="widget-main">
            <div class="row">
              <div class="col-sm-12">
                <?php if ($this->uri->segment(4)) {?>
                 <form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/<?php echo PRODUCTS;?>add_products/<?php echo $product_id ?>" onsubmit="return validateForm();" name="manage_client" id="manage_client"><?php }else{?>
                  <form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/<?php echo PRODUCTS;?>add_products" onsubmit="return validateForm();" name="manage_client" id="manage_client"><?php } ?>
                  <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold">Product Type</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="form-group">  
                    <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Product Type';?><font style="color:red">*</font></label>
                    <div class="col-sm-7">  
                      <?php if ($this->uri->segment(4)) {
                      if ($value['product_type']=='dispenser') { ?>
                         <label>
                               <input name="form-field-radio" type="radio" class="ace"  id="dispenser_radio" onchange="show()" value="<?php echo $value['product_type'];?>" required checked>
                            <span class="lbl"> Dispenser</span>
                          </label>
                          <label>
                              <input name="form-field-radio" type="radio" class="ace" id="refill_radio" onchange="hide()" value="refill" required disabled>
                            <span class="lbl"> Refill</span>
                          </label><?php }else if($value['product_type']=='refill'){?>
                            <label>
                                <input name="form-field-radio" type="radio" class="ace"  id="dispenser_radio" onchange="show()" value="dispenser" required disabled>
                            <span class="lbl"> Dispenser</span>
                          </label>
                          <label>
                              <input name="form-field-radio" type="radio" class="ace" id="refill_radio" onchange="hide()" value="<?php echo $value['product_type'];?>" required checked>
                            <span class="lbl"> Refill</span>
                          </label><?php }}else{?>
                            <label>
                               <input name="form-field-radio" type="radio" class="ace"  id="dispenser_radio" onchange="show()" value="dispenser" required>
                            <span class="lbl"> Dispenser</span>
                          </label>
                          <label>
                              <input name="form-field-radio" type="radio" class="ace" id="refill_radio" onchange="hide()" value="refill" required>
                            <span class="lbl"> Refill</span>
                          </label><?php } ?>
                    </div>

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

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

       <!-- customer contact start -->
<div id="whole">
    <section class="panel panel-default">
      <header class="panel-heading bg-info lt font-bold">Product Details</header>
       <div class="panel-body bs-example form-horizontal">
        <div class="">
          <div class="hr hr12 dotted"></div>
          <div class="">
            <div class="col-sm-12">

             

              <div class="col-sm-6" id="product_rcategory">  
                  <div class="form-group">  
                    <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Product Category';?><font style="color:red">*</font></label>
                    <div class="col-sm-7">  
                      <select name="product_category" id="product_category">
                        <option value="">Product Category</option>
                      <?php  
                                          foreach ($category as  $value1) {
                                           if ($product_category_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>
                      <span id="product_category1" class="text-danger font-weight-bold"></span>
                    </div>
                  </div>
              </div>
              <div class="col-sm-6" id="DN">
                

              <div class="form-group">  
                    <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Dispenser Name';?><font style="color:red">*</font></label>
                    <div class="col-sm-7">  
                      <select name="product_dispenser" id="product_dispenser">
                        <option value="">Dispenser Name</option>
                         <?php 
                        foreach ($dispenser as  $value2) {?>
                          <?php if ($this->uri->segment(4)) {?>
                          <option value="<?php echo $value2['product_id'] ?>"><?php echo $value2['product_name'] ; ?></option><?php }else{?>
                             <option value="<?php echo $value2['product_id'] ?>"><?php echo $value2['product_name'] ; ?></option><?php }} ?>
                                    
                      </select>
                      <span id="product_dispenser1" class="text-danger font-weight-bold"></span>
                    </div>
                  </div>
              </div>
 

           <?php 
         if ($this->uri->segment(4)) {
          if ($value['product_type']=='dispenser') { ?>

             <div class="col-sm-6" id="dispenser_name">
                              <div class="form-group">
                              <label for="client_code" class="col-sm-5 control-label required"> Dispenser Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                              
                                <input type="text" name="product_name_dispenser" value="<?php echo $value['product_name'];?>" id="product_name_dispenser" placeholder="Dispenser Name" class="form-control"  />
                      
                                <!-- <span id="dispenser_name1" class="text-danger font-weight-bold"></span> -->
                                <?php echo form_error('product_name_dispenser');?>              
                              </div>
                            </div>
                </div>
          <?php }else if($value['product_type']=='refill'){?>
             <div class="col-sm-6" id="refill_name">
                              <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required"> Refill Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                        
                                <input type="text" name="product_name_refill" value="<?php echo $value['product_name'];?>" id="product_name_refill" placeholder="Refill Name" class="form-control"  /> 
                                <!-- <span id="refill_name1" class="text-danger font-weight-bold"></span> -->
                                 <?php echo form_error('product_name_refill');?>            
                              </div>
                            </div>
                </div>
                <?php }}else{?>
                   <div class="col-sm-6" id="dispenser_name">
                              <div class="form-group">
                              <label for="client_code" class="col-sm-5 control-label required"> Dispenser Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
          
                              <input type="text" name="product_name_dispenser" value="" id="product_name_dispenser" placeholder="Dispenser Name" class="form-control"  />

                                <span id="dispenser_name1" class="text-danger font-weight-bold"></span>
                                <?php echo form_error('product_name_dispenser');?>              
                              </div>
                            </div>
                </div>

                <div class="col-sm-6" id="refill_name">
                              <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required"> Refill Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                  <input type="text" name="product_name_refill" value="" id="product_name_refill" placeholder="Refill Name" class="form-control"  />
                                <span id="product_name_refill1" class="text-danger font-weight-bold"></span>
                                 <?php echo form_error('product_name_refill');?>            
                              </div>
                            </div>
                </div>
                  <?php } ?>

<?php if ($this->uri->segment(4)){ 
  if ($value['product_type']=='dispenser') {?>
      <div class="col-sm-6" id="prefix_not">    

                <div class="form-group">
                              <label for="client_code" class="col-sm-5 control-label required">Product Prefix:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                
                                <input type="text" name="product_prefix" value="<?php echo $value['product_prefix'];?>" id="product_prefix" placeholder="Product Prefix" class="form-control"> 
                                  
                                <!-- <span id="product_prefix1" class="text-danger font-weight-bold"></span> -->
                                <?php echo form_error('product_prefix');?>                                             
                              </div>                                                                                                                  
                </div>
                                    
            </div>
  <?php }}else{?>
     <div class="col-sm-6" id="prefix_not">    

                <div class="form-group">
                              <label for="client_code" class="col-sm-5 control-label required">Product Prefix:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                
                                <input type="text" name="product_prefix" value="" id="product_prefix" placeholder="Product Prefix" class="form-control"> 
                                  
                                <span id="product_prefix1" class="text-danger font-weight-bold"></span>
                                <?php echo form_error('product_prefix');?>                                             
                              </div>                                                                                                                  
                </div>
                                    
            </div><?php } ?>



            
             <!-- col-ms-6 close -->

                                          
            </div> <!-- col-ms-6 close -->

            
<?php if ($this->uri->segment(4)){ 
  if ($value['product_type']=='dispenser') {?>
    <div class="col-sm-6" id="refill_duration">    
                <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required">Refill Duration:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="refill_duration" value="<?php echo $value['refill_duration'];?>" id="refill_duration_field" placeholder="Refill Duration" class="form-control"  />
                                <!-- <span id="refill_duration1" class="text-danger font-weight-bold"></span>  -->
                                 <?php echo form_error('refill_duration');?>           
                              </div>
                </div>
                                    
            </div>
  <?php }}else{?>
    <div class="col-sm-6" id="refill_duration">    

                <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required">Refill Duration:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                   <input type="text" name="refill_duration" value="" id="refill_duration_field" placeholder="Refill Duration" class="form-control"  />

                                <span id="refill_duration1" class="text-danger font-weight-bold"></span> 
                                 <?php echo form_error('refill_duration');?>           
                              </div>
                </div>
                                    
            </div><?php } ?>

              <!--  -->



                <?php 
     if ($this->uri->segment(4)) {
        if ($value['product_type']=='dispenser') {?>
                <div class="col-sm-6" id="dispenser_description">    
                  <div class="form-group">
                    <label for="client_code" class="col-sm-5 control-label required">Description:<font style="color:red">*</font></label>

                      <div class="col-sm-7">                            
                        <textarea class="form-control" rows="2" name="description" id="description" value="<?php echo $value['description'];?>"></textarea> 
                          <!-- <span id="description1" class="text-danger font-weight-bold"></span>  -->
                              <?php echo form_error('description');?>             
                      </div>
                   </div>
                </div>
  <?php }else if($value['product_type']=='refill'){?>
                <div class="col-sm-6" id="refill_description">    
                  <div class="form-group">
                   <label for="client_code" class="col-sm-5 control-label required">Description:<font style="color:red">*</font></label>
                    <div class="col-sm-7">                            
                      <textarea class="form-control" rows="2" id="comment" name="description_refill" id="description_refill" value="<?php echo $value['description'];?>"></textarea> 
                        <!-- <span id="description1" class="text-danger font-weight-bold"></span>  -->
                            <?php echo form_error('description');?>             
                    </div>
                  </div>
                </div>
              <?php }}else{?>                 
                <div  class="col-sm-6" id="dispenser_description">    
                  <div class="form-group">
                      <label for="client_code" class="col-sm-5 control-label required">Description:<font style="color:red">*</font></label>
                        <div class="col-sm-7">
                            <textarea class="form-control" rows="2" name="description" id="description" value=""></textarea> 
                              <span id="description1" class="text-danger font-weight-bold"></span> 
                                <?php echo form_error('description');?>             
                        </div>
                  </div>
                </div>

                <div class="col-sm-6" id="refill_description">    
                  <div class="form-group">
                      <label for="client_code" class="col-sm-5 control-label required">Description:<font style="color:red">*</font></label>
                          <div class="col-sm-7">
                             <textarea class="form-control" rows="2"  name="description_refill" id="description_refill" value=""></textarea> 
                                <span id="description_refill1" class="text-danger font-weight-bold"></span> 
                                  <?php echo form_error('description');?>             
                         </div>
                  </div>
                </div>
              <?php } ?>





     
          <?php 

   if ($this->uri->segment(4)) { 
    if ($value['product_type']=='dispenser') { ?>
      <div class="col-sm-6" id="dispenser_price">    

                <div class="form-group" >
                              <label for="client_code" class="col-sm-5 control-label required">Price(in INR):<font style="color:red">*</font></label>
                              <div class="col-sm-7">                               
                                <input type="text" name="price" value="<?php echo $value['price'];?>" id="price" placeholder="Price(in INR)" class="form-control">
                               <!--  <span id="price1" class="text-danger font-weight-bold"></span>  -->
                                <?php echo form_error('price');?>                                    
                              </div>                                                                                                                  
                </div>
                                    
            </div>

    <?php }elseif($value['product_type']=='refill'){?>
      <div class="col-sm-6" id="refill_price">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Price(in INR):<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="price_refill" value="<?php echo $value['price'];?>" id="price_refill" placeholder="Price(in INR)" class="form-control">                               
                                <!-- <span id="price1" class="text-danger font-weight-bold"></span>  -->
                                <?php echo form_error('price');?>                                    
                              </div>                                                                                                                  
                </div>
                                    
            </div>
    <?php }}else{?>
      <div class="col-sm-6" id="dispenser_price">    

                <div class="form-group" >
                              <label for="client_code" class="col-sm-5 control-label required">Price(in INR):<font style="color:red">*</font></label>
                              <div class="col-sm-7">                               
                                <input type="text" name="price" value="" id="price" placeholder="Price(in INR)" class="form-control">

                                <span id="price1" class="text-danger font-weight-bold"></span> <?php echo form_error('price');?>                                    
                              </div>                                                                                                                  
                </div>
                                    
            </div>
            <div class="col-sm-6" id="refill_price">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Price(in INR):<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="price_refill" value="" id="price_refill" placeholder="Price(in INR)" class="form-control">                               
                                 <span id="price_refill1" class="text-danger font-weight-bold"></span>
                                  <?php echo form_error('price');?>                                    
                              </div>                                                                                                                  
                </div>
                                    
            </div>
    <?php } ?>

           
             

          
            </div>
          </div>
        </div>
      <!-- </div> -->
    </section>
  </div> <!-- whole id close -->
    
              </div>
            </div>
          </div>  
        </div>
      </div>
    </div>
    <!-- /.col -->
  </div>
</div>
  <div class="clearfix form-actions">
    <div class="col-md-offset-5 col-md-5">
      
      <button class="btn btn-info" type="submit">
         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 dispenser_type = document.getElementById('dispenser_radio').value;
      // var refill_type = document.getElementById('refill_radio').value;
      if(document.getElementById('dispenser_radio').checked) {
        var product_category = document.getElementById('product_category').value;
        var product_name = document.getElementById('product_name_dispenser').value;
        var product_prefix = document.getElementById('product_prefix').value;
        var refill_duration= document.getElementById('refill_duration_field').value;
        var description = document.getElementById('description').value;
        var price= document.getElementById('price').value;
      if(product_category == ""){
        document.getElementById('product_category1').innerHTML =" ** Please select Product Category field";
        return false;
      }
      if(product_name == ""){
        document.getElementById('dispenser_name1').innerHTML =" ** Please Fill Product Name field";
        return false;
      } 
      if(product_prefix == "" ){
        document.getElementById('product_prefix1').innerHTML =" ** Please fill Product Prefix field";
        return false;
      }
      if(refill_duration == "" ){
        document.getElementById('refill_duration1').innerHTML =" ** Please Refill Duration field";
        return false;
      }
      if(description == "" ){
        document.getElementById('description1').innerHTML =" ** Please fill Description field";
        return false;
      }   
      if(price == "" ){
        document.getElementById('price1').innerHTML =" ** Please fill Price field";
        return false;
      }

      }else if(document.getElementById('refill_radio').checked) {
        var product_dispenser = document.getElementById('product_dispenser').value;
        var product_name_refill = document.getElementById('product_name_refill').value;
        var description_refill= document.getElementById('description_refill').value;
        var price_refill = document.getElementById('price_refill').value;

      if(product_dispenser == "" ){
        document.getElementById('product_dispenser1').innerHTML =" ** Please Select Dispenser Name field";
        return false;
      }
      if(product_name_refill == "" ){
        document.getElementById('product_name_refill1').innerHTML =" ** Please Fill Refill Name field";
        return false;
      }
      if(description_refill == "" ){
        document.getElementById('description_refill1').innerHTML =" ** Please Fill Discription  field";
        return false;
      }
      if(price_refill == "" ){
        document.getElementById('price_refill1').innerHTML =" ** Please fill Refill Price field";
        return false;
      }

      }
     
          
      
    }

  </script>
<script>
function hide()
{
  document.getElementById("admin_type_code").style.display="none";
}
function show()
{
  document.getElementById("admin_type_code").style.display="";
}
</script>
<script>
$(document).ready(function() {
   $('#expiry').hide();
   $('#whole').hide();  
  });
</script>
<script>
function show(){
$('#whole').show();
$('#DN').hide();
$('#expiry').show();
$('#product_rcategory').show();
$('#prefix_not').show();
$('#refill_duration').show();
$('#dispenser_name').show();
$('#refill_name').hide();
$('#refill_description').hide();
$('#refill_stock_quantity').hide();
$('#refill_price').hide();
$('#dispenser_description').show();
$('#dispenser_stock_quantity').show();
$('#dispenser_price').show();
 }
</script>
<script>
  $(document).ready(function(){

     var radioValue = $("input[name='form-field-radio']:checked").val();
     if (radioValue=='dispenser') {
      show();
     }else if(radioValue=='refill'){
      hide();
     }

});
</script>
<script>
function hide(){
$('#whole').show();
$('#DN').show();
$('#expiry').hide();
$('#product_rcategory').hide();
$('#prefix_not').hide();
$('#refill_duration').hide();
$('#dispenser_name').hide();
$('#dispenser_description').hide();
$('#dispenser_stock_quantity').hide();
$('#dispenser_price').hide();
$('#refill_name').show();
$('#refill_description').show();
$('#refill_stock_quantity').show();
$('#refill_price').show();
}
</script>