cleanup user myshifts

This commit is contained in:
Philip Häusler 2012-12-30 18:23:10 +01:00
parent f5f698a2a5
commit 8fd5ffb335
2 changed files with 32 additions and 80 deletions

View File

@ -15,12 +15,6 @@ function user_myshifts() {
list ($shifts_user) = sql_select("SELECT * FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1"); 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 (isset ($_REQUEST['reset'])) {
if ($_REQUEST['reset'] == "ack") { if ($_REQUEST['reset'] == "ack") {
user_reset_ical_key($user); 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`"); $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 = ""; $html = "";
$timesum = 0; $timesum = 0;
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
if (time() > $shift['end']) $shift_info = $shift['name'];
$html .= '<tr class="done">';
else
$html .= '<tr>';
$html .= '<td>' . date("Y-m-d", $shift['start']) . '</td>';
$html .= '<td>' . date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . '</td>';
$html .= '<td>' . $shift['Name'] . '</td>';
$html .= '<td>' . $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`"); $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) { foreach($needed_angel_types_source as $needed_angel_type) {
$html .= '<br><b>' . $needed_angel_type['name'] . ':</b> '; $shift_info .= '<br><b>' . $needed_angel_type['name'] . ':</b> ';
$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'])); $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(); $shift_entries = array();
@ -94,33 +81,44 @@ function user_myshifts() {
else else
$shift_entries[] = User_Nick_render($user_source); $shift_entries[] = User_Nick_render($user_source);
} }
$html .= join(", ", $shift_entries); $shift_info .= join(", ", $shift_entries);
} }
$html .= '</td>'; $myshift = array(
$html .= '<td>' . $shift['Comment'] . '</td>'; 'date' => date("Y-m-d", $shift['start']),
$html .= '<td>'; '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']) 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)) 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'); $myshift['actions'] .= img_button(page_link_to('user_myshifts') . (($id != $user['UID'])? '&id=' . $id : '') . '&cancel=' . $shift['id'], 'cross', 'sign_off');
$html .= '</td>';
$html .= '</tr>';
$timesum += $shift['end'] - $shift['start']; $timesum += $shift['end'] - $shift['start'];
$myshifts_table[] = $myshift;
} }
if ($html == "") if (count($shifts) == 0)
$html = '<tr><td>' . ucfirst(Get_Text('none')) . '...</td><td></td><td></td><td></td><td></td><td>' . sprintf(Get_Text('pub_myshifts_goto_shifts'), page_link_to('user_shifts')) . '</td></tr>'; $html = '<tr><td>' . ucfirst(Get_Text('none')) . '...</td><td></td><td></td><td></td><td></td><td>' . sprintf(Get_Text('pub_myshifts_goto_shifts'), page_link_to('user_shifts')) . '</td></tr>';
return page(array(
return msg().template_render('../templates/user_myshifts.html', array ( msg(),
'intro' => sprintf(Get_Text('pub_myshifts_intro'), $LETZTES_AUSTRAGEN), $id == $user['UID'] ? sprintf(Get_Text('pub_myshifts_intro'), $LETZTES_AUSTRAGEN) : '',
'shifts' => $html, $id != $user['UID'] ? info(sprintf("You are viewing %s's shifts.", $shifts_user['Nick']), true) : '',
'time_sum' => round($timesum / (60*60), 1), $id != $user['UID'] ? buttons(array(button(page_link_to('admin_user') . '&amp;id=' . $shifts_user['UID'], "Edit " . $shifts_user['Nick'], 'edit'))) : '',
'msg' => $msg, table(array(
'ical_text' => sprintf(Get_Text('inc_schicht_ical_text'), 'date' => "Tag",
page_link_to_absolute('ical') . '&key=' . $shifts_user['ical_key'], 'time' => "Zeit",
page_link_to('user_myshifts') . '&reset'), 'room' => "Ort",
'shift_info' => "Name &amp; 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) : '',
"<h2>iCal Export</h2>" . sprintf(Get_Text('inc_schicht_ical_text'), page_link_to_absolute('ical') . '&key=' . $shifts_user['ical_key'], page_link_to('user_myshifts') . '&reset')
)); ));
} }
?> ?>

View File

@ -1,46 +0,0 @@
<p>
%intro%
</p>
%msg%
<table>
<thead>
<tr>
<th>
Tag
</th>
<th>
Zeit
</th>
<th>
Ort
</th>
<th>
Name &amp; Kollegen
</th>
<th>
Kommentar
</th>
<th>
Aktion
</th>
</tr>
</thead>
<tbody>
%shifts%
</tbody>
<tfoot>
<tr>
<th>Summe</th>
<th>%time_sum% Stunden</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
<hr />
<h2>iCal Export</h2>
<p>
%ical_text%
</p>