From 8fd5ffb3352f28557187ae16aaabb4b245a22941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Sun, 30 Dec 2012 18:23:10 +0100 Subject: [PATCH] cleanup user myshifts --- includes/pages/user_myshifts.php | 66 ++++++++++++++++---------------- templates/user_myshifts.html | 46 ---------------------- 2 files changed, 32 insertions(+), 80 deletions(-) delete mode 100644 templates/user_myshifts.html diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 08e8e77f..346a74c0 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -15,12 +15,6 @@ function user_myshifts() { list ($shifts_user) = sql_select("SELECT * FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1"); - if ($id != $user['UID']) { - $msg .= info(sprintf("You are viewing %s's shifts.", $shifts_user['Nick']), true); - if(in_array('admin_user', $privileges)) - $msg .= buttons(array(button(page_link_to('admin_user') . '&id=' . $shifts_user['UID'], "Edit " . $shifts_user['Nick'], 'edit'))); - } - if (isset ($_REQUEST['reset'])) { if ($_REQUEST['reset'] == "ack") { user_reset_ical_key($user); @@ -70,21 +64,14 @@ function 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($shifts_user['UID']) . " ORDER BY `start`"); + $myshifts_table = array(); $html = ""; $timesum = 0; foreach ($shifts as $shift) { - if (time() > $shift['end']) - $html .= ''; - else - $html .= ''; - $html .= '' . date("Y-m-d", $shift['start']) . ''; - $html .= '' . date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ''; - $html .= '' . $shift['Name'] . ''; - $html .= '' . $shift['name']; - + $shift_info = $shift['name']; $needed_angel_types_source = sql_select("SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` WHERE `ShiftEntry`.`SID`=" . sql_escape($shift['SID']) . " ORDER BY `AngelTypes`.`name`"); foreach($needed_angel_types_source as $needed_angel_type) { - $html .= '
' . $needed_angel_type['name'] . ': '; + $shift_info .= '
' . $needed_angel_type['name'] . ': '; $users_source = sql_select("SELECT `User`.* FROM `ShiftEntry` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` WHERE `ShiftEntry`.`SID`=" . sql_escape($shift['SID']) . " AND `ShiftEntry`.`TID`=" . sql_escape($needed_angel_type['id'])); $shift_entries = array(); @@ -94,33 +81,44 @@ function user_myshifts() { else $shift_entries[] = User_Nick_render($user_source); } - $html .= join(", ", $shift_entries); + $shift_info .= join(", ", $shift_entries); } - $html .= ''; - $html .= '' . $shift['Comment'] . ''; - $html .= ''; + $myshift = array( + 'date' => date("Y-m-d", $shift['start']), + 'time' => date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']), + 'room' => $shift['Name'], + 'shift_info' => $shift_info, + 'comment' => $shift['Comment'] + ); + + $myshift['actions'] = ""; if ($id == $user['UID']) - $html .= img_button(page_link_to('user_myshifts') . '&edit=' . $shift['id'], 'pencil', 'edit'); + $myshift['actions'] .= img_button(page_link_to('user_myshifts') . '&edit=' . $shift['id'], 'pencil', 'edit'); if (($shift['start'] > time() + $LETZTES_AUSTRAGEN * 3600) || in_array('user_shifts_admin', $privileges)) - $html .= img_button(page_link_to('user_myshifts') . (($id != $user['UID'])? '&id=' . $id : '') . '&cancel=' . $shift['id'], 'cross', 'sign_off'); - $html .= ''; - $html .= ''; + $myshift['actions'] .= img_button(page_link_to('user_myshifts') . (($id != $user['UID'])? '&id=' . $id : '') . '&cancel=' . $shift['id'], 'cross', 'sign_off'); $timesum += $shift['end'] - $shift['start']; + $myshifts_table[] = $myshift; } - if ($html == "") + if (count($shifts) == 0) $html = '' . ucfirst(Get_Text('none')) . '...' . sprintf(Get_Text('pub_myshifts_goto_shifts'), page_link_to('user_shifts')) . ''; - - return msg().template_render('../templates/user_myshifts.html', array ( - 'intro' => sprintf(Get_Text('pub_myshifts_intro'), $LETZTES_AUSTRAGEN), - 'shifts' => $html, - 'time_sum' => round($timesum / (60*60), 1), - 'msg' => $msg, - 'ical_text' => sprintf(Get_Text('inc_schicht_ical_text'), - page_link_to_absolute('ical') . '&key=' . $shifts_user['ical_key'], - page_link_to('user_myshifts') . '&reset'), + return page(array( + msg(), + $id == $user['UID'] ? sprintf(Get_Text('pub_myshifts_intro'), $LETZTES_AUSTRAGEN) : '', + $id != $user['UID'] ? info(sprintf("You are viewing %s's shifts.", $shifts_user['Nick']), true) : '', + $id != $user['UID'] ? buttons(array(button(page_link_to('admin_user') . '&id=' . $shifts_user['UID'], "Edit " . $shifts_user['Nick'], 'edit'))) : '', + table(array( + 'date' => "Tag", + 'time' => "Zeit", + 'room' => "Ort", + 'shift_info' => "Name & Kollegen", + 'comment' => "Kommentar", + 'actions' => "Aktion" + ), $myshifts_table), + $id == $user['UID'] && count($shifts) == 0 ? error(sprintf(Get_Text('pub_myshifts_goto_shifts'), page_link_to('user_shifts')), true) : '', + "

iCal Export

" . sprintf(Get_Text('inc_schicht_ical_text'), page_link_to_absolute('ical') . '&key=' . $shifts_user['ical_key'], page_link_to('user_myshifts') . '&reset') )); } ?> diff --git a/templates/user_myshifts.html b/templates/user_myshifts.html deleted file mode 100644 index fdb1631a..00000000 --- a/templates/user_myshifts.html +++ /dev/null @@ -1,46 +0,0 @@ -

-%intro% -

-%msg% - - - - - - - - - - - - - %shifts% - - - - - - - - - - - -
- Tag - - Zeit - - Ort - - Name & Kollegen - - Kommentar - - Aktion -
Summe%time_sum% Stunden
-
-

iCal Export

-

- %ical_text% -