<?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'])) {

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

    $sqlUpdatePosition = "
    UPDATE positions
    SET positionname = '$position_name'
    WHERE positionid = $positionid;";


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

      $positionUpdate = "User updated position ";

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

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

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

?>