<?php
   include('session.php');
   include('connect.php');
   include('logging.php');

// start role specific 
$user_role = $_SESSION['role'];

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $username = mysqli_real_escape_string($db,$_POST['username']);
    $role = mysqli_real_escape_string($db,$_POST['role']);
    $password = mysqli_real_escape_string($db,$_POST['password']);
    $password = md5($password);

    $sqlAddUser = "INSERT INTO users (
      username, password, enabled, role
      ) VALUES ('$username','$password',1,'$role');";

    if(mysqli_query($db, $sqlAddUser)) {

      $userAdd = "User added user " . $username;

      logEvent($db,"User Added",$userAdd,$last_id);
      
      header("location: usersmanagement.php?updated=1");
      } else {
         echo "Error: " . mysqli_error($db);
    }
 
}

?>