From ddf309717b7c2cc996e4b9107abb2bdd3eff3e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Mon, 12 Sep 2011 18:32:45 +0200 Subject: [PATCH] #5 delete shifts --- includes/pages/user_shifts.php | 37 +++++++++++++++++++++++-- templates/user_shifts_admin_delete.html | 6 ++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 templates/user_shifts_admin_delete.html diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 081a2280..ecc11473 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -3,13 +3,41 @@ function user_shifts() { global $user, $privileges; if (isset ($_REQUEST['entry_id']) && in_array('user_shifts_admin', $privileges)) { if (isset ($_REQUEST['entry_id']) && preg_match("/^[0-9]*$/", $_REQUEST['entry_id'])) - $shift_id = $_REQUEST['entry_id']; + $entry_id = $_REQUEST['entry_id']; else header("Location: " . page_link_to('user_shifts')); - sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($shift_id) . " LIMIT 1"); + sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($entry_id) . " LIMIT 1"); return success("The shift entry has been deleted."); } + // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg) + elseif (isset ($_REQUEST['delete_shift']) && in_array('user_shifts_admin', $privileges)) { + if (isset ($_REQUEST['delete_shift']) && preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) + $shift_id = $_REQUEST['delete_shift']; + else + header("Location: " . page_link_to('user_shifts')); + + $shift = sql_select("SELECT * FROM `Shifts` JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `SID`=" . sql_escape($shift_id) . " LIMIT 1"); + if (count($shift) == 0) + header("Location: " . page_link_to('user_shifts')); + $shift = $shift[0]; + + // Schicht löschen bestätigt + if (isset ($_REQUEST['delete'])) { + sql_query("DELETE FROM `ShiftEntry` WHERE `SID`=" . sql_escape($shift_id)); + sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`=" . sql_escape($shift_id)); + sql_query("DELETE FROM `Shifts` WHERE `SID`=" . sql_escape($shift_id) . " LIMIT 1"); + + return success("Die Schicht wurde gelöscht."); + } + + return template_render('../templates/user_shifts_admin_delete.html', array ( + 'name' => $shift['name'], + 'start' => date("Y-m-d H:i", $shift['start']), + 'end' => date("H:i", $shift['end']), + 'id' => $shift_id + )); + } elseif (isset ($_REQUEST['shift_id'])) { if (isset ($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) $shift_id = $_REQUEST['shift_id']; @@ -96,7 +124,10 @@ function user_shifts() { $shifts_table = ""; $row_count = 0; foreach ($shifts as $shift) { - $shift_row = '' . date(($id == 0 ? "Y-m-d " : "") . "H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ($id == 0 ? "
" . $shift['Name'] : "") . '' . $shift['name'] . '
'; + $shift_row = '' . date(($id == 0 ? "Y-m-d " : "") . "H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ($id == 0 ? "
" . $shift['Name'] : "") . '' . $shift['name']; + if (in_array('admin_shifts', $privileges)) + $shift_row .= ' [x]'; + $shift_row .= '
'; $show_shift = false; $angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`TID`) WHERE `shift_id`=" . sql_escape($shift['SID']) . " AND `count` > 0 ORDER BY `AngelTypes`.`Name`"); if (count($angeltypes) == 0) diff --git a/templates/user_shifts_admin_delete.html b/templates/user_shifts_admin_delete.html new file mode 100644 index 00000000..278acca0 --- /dev/null +++ b/templates/user_shifts_admin_delete.html @@ -0,0 +1,6 @@ +

+ Die Schicht %name% von %start% - %end% wird mitsamt allen Einträgen gelöscht. +

+

+ Fortfahren » +