diff --git a/action.php b/action.php index 0a210f9..0788b18 100644 --- a/action.php +++ b/action.php @@ -120,6 +120,19 @@ switch ($VARS['action']) { } else { returnToSender("no_permission"); } + case "deleteshift": + if (!$database->has('shifts', ['shiftid' => $VARS['shiftid']])) { + returnToSender("invalid_shiftid"); + } + if (account_has_permission($_SESSION['username'], "QWIKCLOCK_ADMIN")) { + if ($database->has('assigned_shifts', ['shiftid' => $VARS['shiftid']])) { + returnToSender('shift_has_users'); + } + $database->delete('shifts', ['shiftid' => $VARS['shiftid']]); + returnToSender("shift_deleted"); + } else { + returnToSender("no_permission"); + } case "assignshift": if (!account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE")) { returnToSender("no_permission"); @@ -178,7 +191,7 @@ switch ($VARS['action']) { $resp = json_decode($response->getBody(), TRUE); if ($resp['status'] == "OK") { - if (!account_has_permission($_SESSION['username'], "ADMIN")) { + if (!account_has_permission($_SESSION['username'], "QWIKCLOCK_ADMIN")) { require_once __DIR__ . "/lib/userinfo.php"; $managed = getManagedUIDs($_SESSION['uid']); $result = $resp['result']; diff --git a/lang/en_us.php b/lang/en_us.php index 80cb082..047be84 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -66,6 +66,8 @@ define("STRINGS", [ "edit shift" => "Edit Shift", "shift added" => "Shift added.", "shift saved" => "Shift saved.", + "shift deleted" => "Shift deleted.", + "shift has users" => "Please un-assign all users before deleting the shift.", "invalid time format" => "Invalid time format. Please use HH:MM or HH:MM AM.", "shift name used" => "The shift name you gave is already in use. Use a different name or edit the existing shift.", "invalid shiftid" => "Invalid shift ID.", diff --git a/lang/messages.php b/lang/messages.php index c5e246b..5c24bc3 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -45,6 +45,14 @@ define("MESSAGES", [ "string" => "shift saved", "type" => "success" ], + "shift_deleted" => [ + "string" => "shift deleted", + "type" => "success" + ], + "shift_has_users" => [ + "string" => "shift has users", + "type" => "danger" + ], "shift_name_used" => [ "string" => "shift name used", "type" => "danger" diff --git a/pages/editshift.php b/pages/editshift.php index 02f44d5..500e193 100644 --- a/pages/editshift.php +++ b/pages/editshift.php @@ -111,6 +111,13 @@ if (isset($VARS['id']) && $database->has('shifts', ['shiftid' => $VARS['id']])) \ No newline at end of file