<?php 
if(isset($_REQUEST['usrid'])){
    $aa=0;
    $Sql = $conn->prepare("SELECT * FROM tbl_user_accounts
    INNER JOIN tbl_role ON tbl_role.role_id = tbl_user_accounts.user_role
    INNER JOIN tbl_user_access ON tbl_user_access.last_acc = tbl_user_accounts.user_id
    WHERE tbl_user_accounts.user_id='".$_REQUEST['usrid']."' ");
    $Sql->execute();
    while($Get=$Sql->fetch()){
    $user_id = $Get['user_id'];
    $title_id = $Get['title_id'];
    $privilege_id = $Get['privilege_id'];
    $aa++;
    $status = $Get['status'];
    $gender = $Get['gender'];
   
    ########## RANK ###########
    $rankQue= $conn->prepare("SELECT * FROM tbl_rank where rank_id='".$Get['rank_id']."' ");
    $rankQue->execute();
    $rank1=$rankQue->fetch();
    ########## RANK ###########

?> 

<form id="" action="gate?b=mgeus" 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 
           <?php echo "<b>".$rank1['rank_name']."</b>"." ".$Get['family_name']." ".$Get['first_name'];?>.</b>
        </center>
        <br/>      

       
        <div class="form-group row">                
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">First Name<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">
                <input type="hidden" class="form-control" name="usr_id" value="<?php echo $Get['user_id']; ?>">
			    <input type="text" class="form-control" name="firstname" value="<?php echo $Get['first_name']; ?>" id="firstname" autocomplete="off">
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Last Name</label>
            <div class="col-3 col-lg-3">
               <input type="text" class="form-control" id="lastname" name="lastname" placeholder="Last Name"  value="<?php echo $Get['family_name']; ?>" required>
            </div>
        </div>
            
        <div class="form-group row">              
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Rank <span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="show-tick ms select2" name="rank_id" style="width: 100%" data-placeholder="~select rank~" required>
                    <option></option>
			        <?php
			            $selectrank= $conn->prepare("SELECT * FROM tbl_rank ");
                        $selectrank->execute();
                        while($row_1rank = $selectrank->fetch()) { 
                        if($rank1['rank_id']==$row_1rank['rank_id']){    
                        ?>
                        <option value="<?php echo $rank1['rank_id'];?>" selected><?php echo $row_1rank['rank_name']; ?></option>
                        <?php
                        }else{
                        ?>
                            <option value="<?php echo $row_1rank['rank_id']; ?>"><?php echo $row_1rank['rank_name']; ?></option>
                        <?php
                        }
                    }
			        ?>
                </select>
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Phone<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
            <input type="number" class="form-control" id="" name="phone" placeholder="tel: 07..." value="<?php echo $Get['mobile_no'];?>" required>
            </div>
        </div>

        <div class="form-group row">    
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Email<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <input type="email" class="form-control" id="" name="email" value="<?php echo $Get['user_email'];?>" placeholder="example@example.com">
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Department<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="show-tick ms select2" name="role" id="dept" style="width: 100%" data-placeholder="~department~"  onchange="getappoint(this.value)" required>
                    <option></option>
			        <?php
			            $select= $conn->prepare("SELECT * FROM tbl_role");
                        $select->execute();
                        while($row_1 = $select->fetch()) { 
                         if($Get['role_id']==$row_1['role_id']){ 
                        ?>
                        
                        <option value="<?php echo $Get['role_id'];?>" selected><?php echo $row_1['role_name']; ?></option>

                        <?php }else{?>

                        <option value = <?php echo $row_1['role_id']; ?>><?php echo $row_1['role_name']; ?></option>
                        <?php
                        }
                    }
			        ?>
			    </select>
            </div>
        </div>

        <div class="form-group row">    
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Appointment<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="show-tick ms select2" name="title_name" id="appointid" style="width: 100%" data-placeholder="~title~">
                <?php
                $sql= "SELECT * FROM tbl_title where department_id='".$Get['role_id']."' ";
                    $stmt = $conn->query($sql);                   
                    while ($row = $stmt->fetch()) { 
                    if($title_id==$row['title_id']){     
                ?>
                <option value="<?php echo $title_id;?>" selected><?php echo $row['title_name'];?></option>
                <?php }else{?>
                    <option value="<?php echo $row['title_id'];?>"><?php echo $row['title_name'];?></option>
                <?php 
                    }  
                }
                ?>
			    </select>
            </div>

            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">User privilege<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class=" show-tick ms select2" name="privilege" style="width: 100%" data-placeholder="~Privilege~">
                    <option></option>
			        <?php
			            $select1= $conn->prepare("SELECT * FROM tbl_privilege");
                        $select1->execute();
                        while($row_11 = $select1->fetch()) {
                        if($privilege_id==$row_11['privilege_id']){ 
                        ?>
                         <option value="<?php echo $privilege_id;?>" selected><?php echo $row_11['privilege']; ?></option>
                        <?php }else{?>
                            <option value="<?php echo $row_11['privilege_id'];?>"><?php echo $row_11['privilege']; ?></option>
                        <?php
                        }
                    }
			        ?>
			    </select>
            </div>
        </div>

        <div class="form-group row">    
            <label class="col-form-label col-2 col-lg-2 form-label text-lg-right">Gender<span class="required" style="color:red">*</span></label>
            <div class="col-3 col-lg-3">                  
                <select class="show-tick ms select2" name="gender" style="width: 100%" data-placeholder="-Gender-">
                    <?php 
                     if($gender == 'M'){
                    ?>
                    <option value = "M" selected>Male</option>
                    <?php
                    }elseif($gender == 'F'){
                    ?>                    
                    <option value = "F" selected>Female</option>
                    <?php
                    }else{
                      echo '<option value = "O" selected>Other</option>';
                    }
                    ?>
			    </select>
            </div>

      </div>


        <hr>
        <center>
            <a href="gate?b=mgeus" 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="btn-update" style="border-radius: 4px;font-weight: bold;">Save Changes</button>
        </center>
        <br>
    </div> <!--border -->
    </div>
  </div>
</form>

<?php 
}

}
?>
 
