summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2011-09-12 18:32:45 +0200
committerPhilip Häusler <msquare@notrademark.de>2011-09-12 18:32:45 +0200
commitddf309717b7c2cc996e4b9107abb2bdd3eff3e4e (patch)
tree0e73f7a288dcd1538cd871a029b523e66c83e690
parentd63e7e9aad407f59364d20eb2d9f123ad1985f82 (diff)
#5 delete shifts
-rw-r--r--includes/pages/user_shifts.php37
-rw-r--r--templates/user_shifts_admin_delete.html6
2 files changed, 40 insertions, 3 deletions
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 = '<tr><td>' . date(($id == 0 ? "Y-m-d " : "") . "H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ($id == 0 ? "<br />" . $shift['Name'] : "") . '</td><td>' . $shift['name'] . '<br />';
+ $shift_row = '<tr><td>' . date(($id == 0 ? "Y-m-d " : "") . "H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ($id == 0 ? "<br />" . $shift['Name'] : "") . '</td><td>' . $shift['name'];
+ if (in_array('admin_shifts', $privileges))
+ $shift_row .= ' <a href="?p=user_shifts&delete_shift=' . $shift['SID'] . '">[x]</a>';
+ $shift_row .= '<br />';
$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 @@
+<p class="error">
+ Die Schicht %name% von %start% - %end% wird mitsamt allen Einträgen gelöscht.
+</p>
+<p>
+ <a href="?p=user_shifts&delete_shift=%id%&delete">Fortfahren &raquo;</a>
+</p>