<?php 
  include('common/header.php');
?>
<?php
 $stock_quantity='';
 $product_type='';
 $product_id='';
  if ($this->uri->segment(4)) {
   foreach ($product as  $value){
    $product_id=$value['product_id'];
    $product_category_id=$value['product_category_id'];
	  $stock_quantity=$value['stock_quantity'];
    $product_type=$value['product_type'];
   }
  }
 ?>
<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 PRODUCTS;?>add_products" onsubmit="return validateForm();" name="manage_client" id="manage_client">
                    <input type="hidden" value="<?php echo $product_id ?>" name="hidden" id="hidden">
                  <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" maxlength="75" 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" maxlength="75" 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" maxlength="75" 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" maxlength="75" 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'];?>" maxlength="10" 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" maxlength="10" 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 ($product_type=='dispenser') {
				$disabled_qty='';
				if($product_id!="")
				{
					$disabled_qty="disabled";
				}
				?>					
					<div class="col-sm-6" id="dispenser_quantity">    
						<div class="form-group">
						 <label for="client_code" class="col-sm-5 control-label required">Stock Quantity:<font style="color:red">*</font></label>
						  <div class="col-sm-7">
							<input type="text" name="stock_quantity" onkeypress="return RestrictSpace()" <?php echo $disabled_qty;?> value="<?php echo $stock_quantity;?>" maxlength="20" id="stock_quantity" placeholder="Stock Quantity" class="form-control"  />
							<!-- <span id="refill_duration1" class="text-danger font-weight-bold"></span>  -->
							 <?php echo form_error('stock_quantity');?>  
                <span id="stock_quantity1" class="text-danger font-weight-bold"></span>         
						  </div>
						</div>
											
					</div>
					
					<?php //}?>
            
<?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'];?>" onkeypress="CheckNumeric(event);" id="refill_duration_field" placeholder="Refill Duration" maxlength="10" class="form-control"  />
                                <span id="refill_duration1" class="text-danger font-weight-bold"></span> 
                                <label>Comma separated values can be added e.g. 30,45,60 etc</label>
                                 <?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"  onkeypress="CheckNumeric(event);" maxlength="10" placeholder="Refill Duration" class="form-control"  />

                                <span id="refill_duration1" class="text-danger font-weight-bold"></span> 
                                <label>Comma separated values can be added e.g. 30,45,60 etc</label>
                                 <?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> 
                         
                              <?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" name="description_refill" id="description_refill" value="<?php echo $value['description'];?>"></textarea> 
                        
                            <?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> 
                             
                                <?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" onkeypress="return RestrictSpace()" value="<?php echo $value['price'];?>" maxlength="10" 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" onkeypress="return RestrictSpace()" value="<?php echo $value['price'];?>" id="price_refill" placeholder="Price(in INR)" maxlength="10" 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="" onkeypress="return RestrictSpace()" id="price" maxlength="10" 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" onkeypress="return RestrictSpace()" value="" id="price_refill" maxlength="10" 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(){

 if(document.getElementById('dispenser_radio').checked) {
var error=false; 
  var product_category=$("#product_category").val();  
  if(product_category=='')
  {
    $("#product_category1").html("Please Select Product Category");
    error=true; 
  }
  else
  {
    $('#product_category1').html("");
      
  }

  var product_name_dispenser=$("#product_name_dispenser").val();  
  if(product_name_dispenser=='')
  {
    $("#dispenser_name1").html("Please Enter Product Name");
    error=true; 
  }
  else{
    $('#dispenser_name1').html("");
  }

  var product_prefix=$("#product_prefix").val();  
  if(product_prefix=='')
  {
    $("#product_prefix1").html("Please Enter Product Prefix");
    error=true; 
  }
  else{
    $('#product_prefix1').html("");
  }

  var stock_quantity=$("#stock_quantity").val();  
  if(stock_quantity=='')
  {
    $("#stock_quantity1").html("Please Enter Stock Quantity");
    error=true; 
  }else if(isNaN(stock_quantity)){
    $("#stock_quantity1").html("Must be in numbers");
    error=true; 
  }
  else{
    $('#stock_quantity1').html("");
  }
  var refill_duration_field=$("#refill_duration_field").val();  
  if(refill_duration_field=='')
  {
    $("#refill_duration1").html("Please Enter Refill Duration");
    error=true; 
  }else if(isNaN(refill_duration_field)){
    $("#refill_duration1").html("Must be in numbers");
    error=true; 
  }
  else{
    $('#refill_duration1').html("");
  }
  var description=$("#description").val();  
  if(description=='')
  {
    $("#description1").html("Please Enter Description");
    error=true; 
  }
  else{
    $('#description1').html("");
  }
  var price=$("#price").val();  
  if(price=='')
  {
    $("#price1").html("Please Enter Price");
    error=true; 
  }else  if(isNaN(price)){
    $("#price1").html("Price be in numbers");
    error=true;
  }
  else{
    $('#price1').html("");
  }
 
}else if(document.getElementById('refill_radio').checked) {
  
  var product_dispenser=$("#product_dispenser").val();  
  if(product_dispenser=='')
  {
    $("#product_dispenser1").html("Please Select Dispenser Name");
    error=true; 
  }
  else{
    $('#product_dispenser1').html("");
  } 
  var product_name_refill=$("#product_name_refill").val();  
  if(product_name_refill=='')
  {
    $("#product_name_refill1").html("Please Enter Refill Name");
    error=true; 
  }
  else{
    $('#product_name_refill1').html("");
  } 
  var description_refill=$("#description_refill").val();  
  if(description_refill=='')
  {
    $("#description_refill1").html("Please Enter Description");
    error=true; 
  }
  else{
    $('#description_refill1').html("");
  }  
  var price_refill=$("#price_refill").val();  
  if(price_refill=='')
  {
    $("#price_refill1").html("Please Enter Description");
    error=true; 
  }else if(isNaN(price_refill)){
    $("#price_refill1").html("Price must be in numbers");
    error=true; 
  }
  else{
    $('#price_refill1').html("");
  }
}
   var hidden=$("#hidden").val();
  if(error==true)
  {
    return false;
  }
  else
  {
  if(hidden==''){
      var r = confirm("Are you sure you want to create Product!");
      if (r==true) {return true;}else{return false;} 
    }else{
      var r = confirm("Are you sure you want to Edit Product!");
      if (r==true) {return true;}else{return false;} 
    }
  }     
}

  </script>
  <script>
       function RestrictSpace() {
    if (event.keyCode == 32) {
        return false;
    }
} 
  function CheckNumeric(e) {
        if (window.event) // IE
        {
            if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8 && e.keyCode != 44) {
                event.returnValue = false;
                return false;
            }
        }
        else { // Fire Fox
            if ((e.which < 48 || e.which > 57) & e.which != 8 && e.which != 44) {
                e.preventDefault();
                return false;
            }
        }
    }
  </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();
$('#dispenser_quantity').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();
$('#dispenser_quantity').hide();
}
</script>