<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//echo $this->agent->referrer();
?>

      <div class="main my-0">
        <div class="row mt-3 mx-0">
          <div class="col-md-6">
            <h3><?php echo $pgheading;?></h3>
          </div>
          <div class="col-md-5 text-right">
            &nbsp;
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmgeneral" method="post" action="account/<?php echo $mgmtname;?>/managedata" enctype="multipart/form-data" >
		<input type="hidden" name="rsrcid" value="<?php echo $rsrcid;?>">                
		<input type="hidden" name="currurl" value="<?php echo $this->agent->referrer();?>">                
        <table class="webforms mt-0 table-responsive-sm">
         <tr>
          <td width="20%"><label>Product Type:</label></td>
          <td width="80%">
		  <select name="prodtype" id="prodtype" required class="js-example-basic-single">
		  <option value="">Select Product Type</option>
						<?php
							if(is_array($prodtypes))
							{
								foreach($prodtypes as $kvalue)
								{
									$sel_pt ="";
									if($info4edit->fld_type==$kvalue->fld_type)
									{
										$sel_pt = 'selected="selected"';
									}				
										?>
												<option value="<?php echo $kvalue->fld_type;?>" <?php echo $sel_pt;?>><?php echo $kvalue->fld_type;?></option>
										<?php
								}
							}
						?> 
		  </select>
		  </td>
         </tr>
         <tr>
          <td width="20%"><label>Category:</label></td>
          <td width="80%">
		  <select name="catid" id="catid" required class="js-example-basic-single">
		  <option value="">Select Category</option>
						<?php
						if(is_array($catlist) && count(array_filter($catlist))>0)
						{

							foreach($catlist as $mcatrow)
							{
								$sel_mcat ="";
								if($info4edit->fld_catid==$mcatrow->fld_id)
								{
									$sel_mcat = 'selected="selected"';
								}				
									?>
											<option value="<?php echo $mcatrow->fld_id;?>" <?php echo $sel_mcat;?>><?php echo $mcatrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>
         </tr> 
		<tr>
          <td width="20%"><label>Brand:</label></td>
          <td width="80%">
		  <select name="brandid" id="brandid" required onchange="newbrandoption()" class="js-example-basic-single">
		  <option value="">Select Brand</option>
						<?php
						if(is_array($brandlist) && count(array_filter($brandlist))>0)
						{

							foreach($brandlist as $brandrow)
							{
								$sel_brand ="";
								if($info4edit->fld_brandid==$brandrow->fld_id)
								{
									$sel_brand = 'selected="selected"';
								}				
									?>
											<option value="<?php echo $brandrow->fld_id;?>" <?php echo $sel_brand;?>><?php echo $brandrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
						<option value="other">Other</option>
		  </select>
		  </td>
         </tr>
         <tr id="addnewbrand" style="display:none;">
          <td width="20%"><label>Add New Brand:</label></td>
          <td width="80%"><input type="text" name="newbrandname" id="newbrandname" ></td>
         </tr> 
		 
         <tr>
          <td width="20%"><label>Name:</label></td>
          <td width="80%"><input type="text" name="name" id="name" value="<?php if($info4edit) { echo $info4edit->fld_name; }?>" required></td>
         </tr> 
         <tr>
          <td width="20%"><label>Barcode:</label></td>
          <td width="80%"><input type="text" name="barcode" id="barcode" value="<?php if($info4edit) { echo $info4edit->fld_barcode; }?>"></td>
         </tr>
         <tr>
          <td width="20%"><label>Barcode 02:</label></td>
          <td width="80%"><input type="text" name="barcode02" id="barcode02" value="<?php if($info4edit) { echo $info4edit->fld_barcode02; }?>" ></td>
         </tr>
         <tr>
          <td width="20%"><label>Barcode 03:</label></td>
          <td width="80%"><input type="text" name="barcode03" id="barcode03" value="<?php if($info4edit) { echo $info4edit->fld_barcode03; }?>" ></td>
         </tr>
         <tr>
          <td width="20%"><label>Barcode 04:</label></td>
          <td width="80%"><input type="text" name="barcode04" id="barcode04" value="<?php if($info4edit) { echo $info4edit->fld_barcode04; }?>" ></td>
         </tr>		 
		 
         <tr>
          <td width="20%"><label>No. Of Bottles In Case:</label></td>
          <td width="80%"><input type="number" name="noofbottlesincase" id="noofbottlesincase" value="<?php if($info4edit) { echo $info4edit->fld_noofbottlesincase; }?>" required></td>
         </tr> 
         <tr>
          <td width="20%"><label>Minimum Stock Label:</label></td>
          <td width="80%"><input type="number" name="minstockvalue" id="minstockvalue" value="<?php if($info4edit) { echo $info4edit->fld_minstockvalue; } else{  echo '0'; }?>" required></td>
         </tr>
         <tr>
          <td>Short Description:</td>
          <td colspan="3">
			  <textarea name="shortdesc" id="shortdesc" rows="4" cols="50"><?php if($info4edit) { echo $info4edit->fld_shortdesc; }?></textarea>			  
          </td>
          </tr>         
		 <tr>
             <td></td>
             <td><button class="btn btn-danger">Submit</button></td>
         </tr>
         </table>
         </form> 
	         <div class="clearfix"></div>          
        </div>
       </div>
<script>
		function newbrandoption()
		{
			var brandid = $("#brandid").val();
			if(brandid=='other')
			{
				$("#addnewbrand").show();
				$('#newbrandname').attr('required', true);
			}
			else
			{
				$("#addnewbrand").hide();
				$('#newbrandname').attr('required', false);
			}
		}

		setTimeout(function(){
			
			newbrandoption();
		},3000);
</script>
