<?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'];
$ictgid=$fetch['icateg_id'];
?> 

<form id="" action="gate?b=itm" 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">Item Name<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">
                <textarea class="form-control" placeholder="item 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">Category<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="select2 form-control w-100" name="ictg" id="ictg" data-placeholder="-select type-" required>
                    <option></option>
                    <?php
                    $stmt = $db->query('SELECT *FROM tbl_ictgs WHERE ictg_sts=1 ORDER BY ctgi_name ASC');
                    try
                    {
                        while ($rrr = $stmt->fetch(PDO::FETCH_ASSOC)) {
                            if($ictgid==$rrr['ictg_id']){
                        ?>
                            <option value="<?php echo $itype; ?>" selected><?php echo $rrr['ctgi_name']; ?></option>
                        <?php
                        }else{
                    ?>
                        <option value="<?php echo $rrr['ictg_id']; ?>"><?php echo $rrr['ctgi_name']; ?></option>
                    <?php        
                        }

                        }
                        }
                        catch (PDOException $ex) {
                        //Something went wrong rollback!
                        echo $ex->getMessage();
                    }
                    ?>	
                </select>
            </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>

        <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 
}

?>
 