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

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

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

  if (isset($_GET['departmentid'])) {

    $departmentid = mysqli_real_escape_string($db,$_GET['departmentid']);

    $sqlDeleteDepartment = "
    DELETE FROM
    departments
    WHERE departmentid = $departmentid;";

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

      $positionUpdate = "User deleted department ";

      logEvent($db,"Department Deleted",$positionUpdate,$last_id);
      
      header("location: departments.php");

      } else {
         echo "Error: " . mysqli_error($db);
    }

    } else {
    echo "Department not selected!!!";
   }
 
}

?>