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

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

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

    $department_name = mysqli_real_escape_string($db,$_POST['department_name']);



    $sqlAddDepartment = "INSERT INTO departments (
      departmentname
      ) VALUES (
      '$department_name');";

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

      $employeeAdd = "User added department " . $departmentname;

      $last_id = mysqli_insert_id($db);

      logEvent($db,"Department Added",$employeeAdd,$last_id);
      
      header("location: departments.php");
      } else {
         echo "Error: " . mysqli_error($db);
    }
 
}

?>