<?php
  require_once("../../session_check.php");
  require_once("../../../classes/main_classes.php");

    //OBJECTS
    $retrieveObj=new RETRIEVE();

    //get roles
    $get_roles=$retrieveObj->retriever("user_role","*","fetchAll");
?>

<h4 class="page-title">
  <span class="la la-users"></span>
  Users
</h4>
<p><a href="#" class="bold" onclick="users_view()">Users</a> <span class="fas fa-angle-right"></span> Add users</p>
<div class="content-wrapper ">
    <div class="row">
        <div class="col-md-12">
          <div class="mx-auto card p-2" style="max-width: 400px">
            <p class="text-center lead">Add user</p>
            <form id="add_user_form">
              <div class="my-2">
                <input class="form-control" type="text" name="firstname" placeholder="Firstname">
              </div>
              <div class="my-2">
                <input class="form-control" type="text" name="lastname" placeholder="Lastname">
              </div>
              <div class="my-2">
                <input class="form-control" type="text" name="username" placeholder="Username">
              </div>
              <div class="my-2">
                <input class="form-control" type="text" name="email" placeholder="Email">
              </div>
              <div class="my-2">
                <select class="form-control" name="user_role">
                  <?php
                    if($get_roles!="1020"){
                      $role_selected_status="";

                      foreach ($get_roles as $role) {
                        if($role->user_role=="admin"){
                          $role_selected_status="selected";
                        }else{
                          $role_selected_status="";
                        }
                        echo "<option $role_selected_status value='".$role->role_id."' >".$role->user_role."</option>";
                      }
                    }
                  ?>
                </select>
              </div>
              <div class="my-2">
                <input class="form-control" type="password" name="password" placeholder="Password">
              </div>
              <div class="my-2">
                <input class="form-control" type="password" name="rpassword" placeholder="Repeat password">
              </div>
              <div class="my-2" id="add_user_response">
                
              </div>
              <div class="my-2">
                <input type="hidden" name="add_user_note">
                <button type="submit" class="btn btn-primary btn-block enter-btn" onclick="add_user()">Add</button>
              </div>
            </form>
          </div>
        </div>
    </div>
</div>