<?php
define('DOCUMENT_ROOT_CLASS','');
define('DOCUMENT_ROOT_INC_FOLDER','');
include 'inc/header.php';
Session::CheckSession(); 
$msg = Session::get('msg');
Session::set("msg", NULL);
?>

<?php if (isset($_GET['id'])) {
  $userid = preg_replace('/[^a-zA-Z0-9-]/', '', (int)$_GET['id']);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['update'])) {
  $msg1 = $users->updateUserByIdInfo($userid, $_POST);
}?>

  <!-- Page-Title -->
  <div class="row">
      <div class="col-sm-12">
          <div class="page-title-box">
              <div class="row">
                  <div class="col">
                      <h4 class="page-title">Setting</h4>
                      <ol class="breadcrumb">
                          <li class="breadcrumb-item"><a href="javascript:void(0);">Setting</a></li>
                          <li class="breadcrumb-item"><a href="javascript:void(0);">Manage Users</a></li>
                          <li class="breadcrumb-item"><a href="javascript:void(0);">Profile</a></li>
                      </ol>
                  </div><!--end col-->
                  <div class="col-auto align-self-center">
                      <a href="#" class="btn btn-sm btn-outline-primary" id="Dash_Date">
                          <span class="day-name" id="Day_Name">Today:</span>&nbsp;
                          <span class="" id="Select_date">Jan 11</span>
                          <i data-feather="calendar" class="align-self-center icon-xs ml-1"></i>
                      </a>
                      <a href="#" class="btn btn-sm btn-outline-primary">
                          <i data-feather="download" class="align-self-center icon-xs"></i>
                      </a>
                  </div><!--end col-->  
              </div><!--end row-->                                                              
          </div><!--end page-title-box-->
      </div><!--end col-->
  </div><!--end row-->
  <!-- end page title end breadcrumb -->
  <div class="row">
      <div class="col-12">
          <div class="card">
            <div class="card-header">
              <h4 class="card-title"> User Profile </h4>
              <?php echo !empty($msg)?$msg:''; ?>        
              <?php echo !empty($msg1)?$msg1:''; ?>        
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="main-card mb-3 card">
                            <div class="card-body">
                                <?php $getUinfo = $users->getUserInfoById($userid);
                                if ($getUinfo) { ?>
                                  <div style="width:600px; margin:0px auto">
                                    <form class="" action="" method="POST">
                                      <div class="form-group">
                                        <label for="name">Your name</label>
                                        <input type="text" name="name" value="<?php echo $getUinfo->name; ?>" class="form-control">
                                      </div>
                                      <div class="form-group">
                                        <label for="username">Your username</label>
                                        <input type="text" name="username" value="<?php echo $getUinfo->username; ?>" class="form-control">
                                      </div>
                                      <div class="form-group">
                                        <label for="email">Email address</label>
                                        <input type="email" id="email" name="email" value="<?php echo $getUinfo->email; ?>" class="form-control">
                                      </div>
                                      <div class="form-group">
                                        <label for="mobile">Mobile Number</label>
                                        <input type="text" id="mobile" name="mobile" value="<?php echo $getUinfo->mobile; ?>" class="form-control">
                                      </div>
                                      <?php if (Session::get("roleid") == '1') { ?>
                                        <div class="form-group <?php if (Session::get("roleid") == '1' && Session::get("id") == $getUinfo->id) { echo "d-none"; } ?>">
                                          <div class="form-group">
                                            <label for="sel1">Select user Role</label>
                                            <?php $optionData = $commonFunctions->getData('sys_erp_adm_user_roles',' WHERE isActive = 0 '); ?>
                                            <select class="form-control" name="roleid" id="roleid">
                                              <?php foreach ($optionData as $key) { ?>
                                                <option value="<?php echo $key['id'];?>" <?php echo (!empty($getUinfo->roleid) and $getUinfo->roleid == $key['id'])?"selected":"";?> ><?php echo $key['role'];?></option>
                                              <?php } ?>
                                            </select>
                                          </div>
                                        </div>
                                      <?php }else{?>
                                        <input type="hidden" name="roleid" value="<?php echo $getUinfo->roleid; ?>">
                                      <?php } if (Session::get("id") == $getUinfo->id) { ?>
                                        <div class="form-group">
                                          <button type="submit" name="update" class="btn btn-success">Update</button>
                                          <a class="btn btn-primary" href="changepass.php?id=<?php echo $getUinfo->id;?>">Password change</a>
                                        </div>
                                      <?php } elseif(Session::get("roleid") == '1') {?>
                                        <div class="form-group">
                                          <button type="submit" name="update" class="btn btn-success">Update</button>
                                          <a class="btn btn-primary" href="changepass.php?id=<?php echo $getUinfo->id;?>">Password change</a>
                                        </div>
                                      <?php } elseif(Session::get("roleid") == '2') {?>
                                        <div class="form-group">
                                          <button type="submit" name="update" class="btn btn-success">Update</button>
                                        </div>
                                      <?php   }else{ ?>
                                        <div class="form-group">
                                          <a class="btn btn-primary" href="index.php">Ok</a>
                                        </div>
                                      <?php } ?>
                                    </form>  
                                  </div>
                                <?php }else{ header('Location:manage-users.php'); } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
          </div>
      </div> <!-- end col -->
  </div> <!-- end row -->
  
  <?php include 'inc/footer.php'; ?>
