From e8c035e166a6a42be519d09ca8b1953e7b244c42 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Tue, 19 Jul 2011 19:56:15 +0200 Subject: #6 edit my shift comment --- includes/pages/user_myshifts.php | 36 ++++++++++++++++++++++++++++++------ includes/pages/user_shifts.php | 3 ++- 2 files changed, 32 insertions(+), 7 deletions(-) (limited to 'includes') diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 88d78254..9d5b25d6 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -7,9 +7,32 @@ function user_myshifts() { global $user, $privileges; $msg = ""; - if (isset ($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) { + if (isset ($_REQUEST['edit']) && preg_match("/^[0-9]*$/", $_REQUEST['edit'])) { + $id = $_REQUEST['edit']; + $shift = sql_select("SELECT `ShiftEntry`.`Comment`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`Name` as `angel_type` FROM `ShiftEntry` JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`TID`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `id`=" . sql_escape($id) . " AND `UID`=" . sql_escape($user['UID']) . " LIMIT 1"); + if (count($shift) > 0) { + $shift = $shift[0]; + + if (isset ($_REQUEST['submit'])) { + $comment = strip_request_item_nl('comment'); + sql_query("UPDATE `ShiftEntry` SET `Comment`='" . sql_escape($comment) . "' WHERE `id`=" . sql_escape($id) . " LIMIT 1"); + header("Location: " . page_link_to('user_myshifts')); + } + + return template_render('../templates/user_shifts_add.html', array ( + 'angel' => $user['Nick'], + 'date' => date("Y-m-d H:i", $shift['start']) . ', ' . date("H", $shift['end'] - $shift['start']) . ' h', + 'location' => $shift['Name'], + 'title' => $shift['name'], + 'type' => $shift['angel_type'], + 'comment' => $shift['Comment'] + )); + } else + header("Location: " . page_link_to('user_myshifts')); + } + elseif (isset ($_REQUEST['cancel']) && preg_match("/^[0-9]*$/", $_REQUEST['cancel'])) { $id = $_REQUEST['cancel']; - $shift = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`=" . sql_escape($id) . " LIMIT 1"); + $shift = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`=" . sql_escape($id) . " AND `UID`=" . sql_escape($user['UID']) . " LIMIT 1"); if (count($shift) > 0) { $shift = $shift[0]; if (($shift['start'] - time() < $LETZTES_AUSTRAGEN * 60) || in_array('user_shifts_admin', $privileges)) { @@ -20,7 +43,7 @@ function user_myshifts() { } else header("Location: " . page_link_to('user_myshifts')); } - $shifts = sql_select("SELECT * FROM `ShiftEntry` JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `UID`=" . sql_escape($user['UID'])." ORDER BY `start`"); + $shifts = sql_select("SELECT * FROM `ShiftEntry` JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `UID`=" . sql_escape($user['UID']) . " ORDER BY `start`"); $html = ""; foreach ($shifts as $shift) { if (time() > $shift['end']) @@ -32,10 +55,11 @@ function user_myshifts() { $html .= '' . $shift['Name'] . ''; $html .= '' . $shift['name'] . ''; $html .= '' . $shift['Comment'] . ''; + $html .= ''; + $html .= 'edit'; if ($shift['start'] - time() > $LETZTES_AUSTRAGEN * 60) - $html .= 'Cancel'; - else - $html .= ''; + $html .= ' | cancel'; + $html .= ''; $html .= ''; } if ($html == "") diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 64fcbac5..f4542703 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -69,7 +69,8 @@ function user_shifts() { 'title' => $shift['name'], 'location' => $shift['Name'], 'angel' => $user_text, - 'type' => $type['Name'] + 'type' => $type['Name'], + 'comment' => "" )); } else { $shifts = sql_select("SELECT * FROM `Shifts` ORDER BY `start`"); -- cgit v1.2.3-54-g00ecf