<?php 
if(isset($_REQUEST['itemid'])){
$sql = $conn->prepare("SELECT * FROM `tbl_items` WHERE item_id='".$_REQUEST['itemid']."'");
$sql->execute();
$fetch = $sql->fetch();
$iUnit=$fetch['iUnit'];
$itype=$fetch['itype'];
?> 

<form id="" action="gate?b=mat" method="POST" enctype="multipart/form-data" autocomplete="off">
  <br><br> 
    <div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10" style="background-image: url(../img/placeholders/inner-texture-bg.png); border-radius: 8px;">
      <div style='border-radius: 8px;border: 2px solid #7E9350;width:100%;margin-top:1%;margin-bottom:1%;'>
        <br/>
        <center>
           <b style="font-family: century gothic;font-size: 23px;"><i class="fa fa-edit"></i> Update Material.</b>
        </center>
        <br/>      

        <div class="form-group row">                
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Material Name<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">
                <textarea class="form-control" placeholder="material name..." name="mat_name_upd" required><?php echo $fetch['item_name'];?></textarea>
                <input type="hidden" class="form-control" name="mat_id_upd" value="<?php echo $fetch['item_id'];?>" required>
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Description</label>
            <div class="col-3 col-lg-3">
                <textarea class="form-control" name="desc" id="desc" placeholder="Description"><?php echo $fetch['dec_item'];;?></textarea>
            </div>
        </div>
            
        <div class="form-group row">              
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Price<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <input type="text" class="form-control" name="price" id="price" value="<?php echo $fetch['iPrice'];?>"
                oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" placeholder="0.0" required>
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Unit<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="select2 form-control w-100" name="unt" id="unt" data-placeholder="-select unit-" required>
                    <option></option>
                    <?php
                    $stmt = $db->query('SELECT *FROM tbl_units WHERE unit_status=1 ORDER BY unit_id ASC');
                    try
                    {
                        while ($rrr = $stmt->fetch(PDO::FETCH_ASSOC)) {
                            if($iUnit==$rrr['unit_id']){
                        ?>
                            <option value="<?php echo $iUnit; ?>" selected><?php echo $rrr['unit_name']; ?></option>
                        <?php
                        }else{
                    ?>
                        <option value="<?php echo $rrr['unit_id']; ?>"><?php echo $rrr['unit_name']; ?></option>
                    <?php        
                        }

                        }
                        }
                        catch (PDOException $ex) {
                        //Something went wrong rollback!
                        echo $ex->getMessage();
                    }
                    ?>	
                </select>
            </div>
        </div>

        <div class="form-group row">    
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Item Type<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="select2 form-control w-100" name="itype" id="itype" data-placeholder="-select type-" required>
                    <option></option>
                    <?php
                    $stmt = $db->query('SELECT *FROM tbl_typesitem WHERE sttype=1 ORDER BY item_type_id ASC');
                    try
                    {
                        while ($rrr = $stmt->fetch(PDO::FETCH_ASSOC)) {
                            if($itype==$rrr['item_type_id']){
                        ?>
                            <option value="<?php echo $itype; ?>" selected><?php echo $rrr['itypeName']; ?></option>
                        <?php
                        }else{
                    ?>
                        <option value="<?php echo $rrr['item_type_id']; ?>"><?php echo $rrr['itypeName']; ?></option>
                    <?php        
                        }

                        }
                        }
                        catch (PDOException $ex) {
                        //Something went wrong rollback!
                        echo $ex->getMessage();
                    }
                    ?>	
                </select>
            </div>
        </div>


        <hr>
        <center>
            <a href="gate?b=mat" class="btn btn-default btn-sm" style="border-radius: 4px;font-weight: bold;">Go back</a>
            <button type="submit" class="btn btn-primary btn-sm" name="btnUpdte" style="border-radius: 4px;font-weight: bold;">Save Changes</button>
        </center>
        <br>
    </div> <!--border -->
    </div>
  </div>
</form>

<?php 
}

?>
 