norhusna / Change-Request

Phoenix - Online Food Ordering (Ah Kong Restaurant)
0 stars 0 forks source link

CR6 - MANAGE STAFF FOR ADMIN #6

Closed norhusna closed 3 years ago

norhusna commented 3 years ago

To provide easy access for admin to manage staff of the restaurant

puterinorliana commented 3 years ago

image

puterinorliana commented 3 years ago

<?php include("../functions.php");

if((!isset($_SESSION['uid']) && !isset($_SESSION['username']) && isset($_SESSION['user_level'])) ) header("Location: login.php");

if($_SESSION['user_level'] != "admin") header("Location: login.php");

if (!empty($_POST['role'])) { $role = $sqlconnection->real_escape_string($_POST['role']); $staffID = $sqlconnection->real_escape_string($_POST['staffID']);

$updateRoleQuery = "UPDATE tbl_staff SET role = '{$role}'  WHERE staffID = {$staffID}  ";

  if ($sqlconnection->query($updateRoleQuery) === TRUE) {
    echo "";
  } 

  else {
    //handle
    echo "someting wong";
    echo $sqlconnection->error;
  }

} ?>

<!DOCTYPE html>

Staff Management - FOS Admin

Staff Management


Manage current staff that avalaible.

Current Staff List
query($displayStaffQuery)) { if ($result->num_rows == 0) { echo ""; } $staffno = 1; while($staff = $result->fetch_array(MYSQLI_ASSOC)) { ?> Online"; } if ($staff['status'] == "Offline") { echo ""; } ?> error; echo "Something wrong."; } ?>
# Username Status Role Option
There are currently no staff.
Offline
Delete
Add new staff
puterinorliana commented 3 years ago

ADD STAFF

<?php include("../functions.php");

if((!isset($_SESSION['uid']) && !isset($_SESSION['username']) && isset($_SESSION['user_level'])) ) 
    header("Location: login.php");

if($_SESSION['user_level'] != "admin")
    header("Location: login.php");

if (isset($_POST['addstaff'])) {
    if (!empty($_POST['staffname']) && !empty($_POST['staffrole'])) {
        $staffUsername = $sqlconnection->real_escape_string($_POST['staffname']);
        $staffRole = $sqlconnection->real_escape_string($_POST['staffrole']);

        $addStaffQuery = "INSERT INTO tbl_staff (username ,password ,status ,role) VALUES ('{$staffUsername}' ,'abc123' ,'Offline' ,'{$staffRole}') ";

        if ($sqlconnection->query($addStaffQuery) === TRUE) {
                echo "added.";
                header("Location: staff.php"); 
                exit();

            } 

            else {
                //handle
                echo "someting wong";
                echo $sqlconnection->error;
            }
    }
}

?>

puterinorliana commented 3 years ago

DELETE STAFF

<?php

include("../functions.php");

if((!isset($_SESSION['uid']) && !isset($_SESSION['username']) && isset($_SESSION['user_level'])) ) 
    header("Location: login.php");

if($_SESSION['user_level'] != "admin")
    header("Location: login.php");

//Deleting Item
if (isset($_GET['staffID'])) {

    $del_staffID = $sqlconnection->real_escape_string($_GET['staffID']);

    $deleteStaffQuery = "DELETE FROM tbl_staff WHERE staffID = {$del_staffID}";

    if ($sqlconnection->query($deleteStaffQuery) === TRUE) {
            echo "deleted.";
            header("Location: staff.php"); 
            exit();
        } 

    else {
            //handle
            echo "someting wrong";
            echo $sqlconnection->error;

    }
    //echo "<script>alert('{$del_menuID} & {$del_itemID}')</script>";
}

?>

norhusna commented 3 years ago

change request approved!