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

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

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

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

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

    $sqlAddPosition = "INSERT INTO positions (
      departmentid,
      positionname
      ) VALUES (
      '$departmentid',
      '$position_name');";


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

      $departmentUpdate = "User added position ";

      logEvent($db,"Department updated",$departmentUpdate,$last_id);
      
      header("location: viewdepartment.php?departmentid=$departmentid");

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

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

?>