main
Philip Häusler 13 years ago
parent e0ffeb1005
commit 8259266297

@ -3,7 +3,7 @@ function admin_rooms() {
global $user;
$html = "";
$rooms = sql_select("SELECT * FROM `Room` ORDER BY `Number`, `Name`");
$rooms = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
if (!isset ($_REQUEST["action"])) {
$html .= "Hallo " . $user['Nick'] .
",<br />\nhier hast du die M&ouml;glichkeit, neue R&auml;ume f&uuml;r die Schichtpl&auml;ne einzutragen " .

@ -213,28 +213,33 @@ function user_shifts() {
$shifts = sql_select("SELECT COUNT(*) AS `count` FROM `Shifts` ORDER BY `start`");
$days = array ();
$rooms = array ();
if (!isset ($_SESSION['user_shifts']))
$_SESSION['user_shifts'] = array ();
if ($shifts[0]["count"] > 0) {
$days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) FROM `Shifts`");
$days = array_map('array_pop', $days);
$day = $days[0];
if (!isset ($_SESSION['user_shifts']['day']))
$_SESSION['user_shifts']['day'] = $days[0];
if (isset ($_REQUEST['day']))
$day = $_REQUEST['day'];
$_SESSION['user_shifts']['day'] = $_REQUEST['day'];
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
$id = 0;
if (!isset ($_SESSION['user_shifts']['id']))
$_SESSION['user_shifts']['id'] = 0;
if (isset ($_REQUEST['room_id']) && preg_match("/^[0-9]*$/", $_REQUEST['room_id']))
$id = $_REQUEST['room_id'];
$day_timestamp = DateTime :: createFromFormat("Y-m-d-Hi", $day . "-0000")->getTimestamp();
$_SESSION['user_shifts']['id'] = $_REQUEST['room_id'];
$day_timestamp = DateTime :: createFromFormat("Y-m-d-Hi", $_SESSION['user_shifts']['day'] . "-0000")->getTimestamp();
if ($id == 0)
if ($_SESSION['user_shifts']['id'] == 0)
$shifts = sql_select("SELECT * FROM `Shifts` JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `start` > " . sql_escape(time()) . " ORDER BY `start`");
else
$shifts = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($id) . " AND `start` >= " . sql_escape($day_timestamp) . " AND `start` < " . sql_escape($day_timestamp +24 * 60 * 60) . " ORDER BY `start`");
$shifts = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($_SESSION['user_shifts']['id']) . " AND `start` >= " . sql_escape($day_timestamp) . " AND `start` < " . sql_escape($day_timestamp +24 * 60 * 60) . " ORDER BY `start`");
$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'];
$shift_row = '<tr><td>' . date(($_SESSION['user_shifts']['id'] == 0 ? "Y-m-d " : "") . "H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ($_SESSION['user_shifts']['id'] == 0 ? "<br />" . $shift['Name'] : "") . '</td><td>' . $shift['name'];
if (in_array('admin_shifts', $privileges))
$shift_row .= ' <a href="?p=user_shifts&edit_shift=' . $shift['SID'] . '">[edit]</a> <a href="?p=user_shifts&delete_shift=' . $shift['SID'] . '">[x]</a>';
$shift_row .= '<br />';
@ -266,42 +271,34 @@ function user_shifts() {
$shift_row .= '<br />';
}
}
if ($id != 0 || ($show_shift && $row_count++ < 15))
if ($_SESSION['user_shifts']['id'] != 0 || ($show_shift && $row_count++ < 15))
$shifts_table .= $shift_row . '</td></tr>';
}
}
return template_render('../templates/user_shifts.html', array (
'room_select' => make_room_select($rooms, $id, $day),
'day_select' => make_day_select($days, $day, $id),
'room_select' => make_room_select($rooms, $_SESSION['user_shifts']['id'], $_SESSION['user_shifts']['day']),
'day_select' => make_day_select($days, $_SESSION['user_shifts']['day'], $_SESSION['user_shifts']['id']),
'shifts_table' => $shifts_table
));
}
}
function make_day_select($days, $day, $id) {
if ($id == 0)
return "";
$html = array ();
foreach ($days as $d) {
if ($day == $d && $id != 0)
$html[] = '<b>' . $d . '</b>';
else
$html[] = '<a href="' . page_link_to('user_shifts') . '&day=' . $d . '&room_id=' . $id . '">' . $d . '</a>';
}
return join(' | ', $html);
foreach ($days as $d)
$html[] = button(page_link_to('user_shifts') . '&day=' . $d, $d, $day == $d && $id != 0 ? 'on' : '');
return buttons($html);
}
function make_room_select($rooms, $id, $day) {
$html = array ();
foreach ($rooms as $room) {
if ($room['RID'] == $id)
$html[] = '<b>' . $room['Name'] . '</b>';
else
$html[] = '<a href="' . page_link_to('user_shifts') . '&room_id=' . $room['RID'] . '&day=' . $day . '">' . $room['Name'] . '</a>';
$html[] = button(page_link_to('user_shifts') . '&room_id=' . $room['RID'], $room['Name'], $room['RID'] == $id ? 'on' : '');
}
if ($id == 0)
$html[] = '<b>Nächste freie Schichten</b>';
else
$html[] = '<a href="' . page_link_to('user_shifts') . '&room_id=0">Nächste freie Schichten</a>';
return join(' | ', $html);
$html[] = button(page_link_to('user_shifts') . '&room_id=0', "Next free shifts.", $id == 0 ? 'on' : '');
return buttons($html);
}
?>

@ -147,7 +147,7 @@ function button($href, $label, $class = "") {
* Rendert eine Toolbar mit Knöpfen
*/
function buttons($buttons = array ()) {
return '<div class="toolbar">' . join($buttons) . '</div>';
return '<div class="toolbar">' . join(' ', $buttons) . '</div>';
}
// Load and render template

@ -276,19 +276,26 @@ tr:hover .hidden {
}
.toolbar {
margin: 5px 0 10px 0;
margin: 0 0 10px 0;
}
.button {
background: #f0f0f0;
border: 1px solid #888;
border-radius: 4px;
margin-right: 5px;
line-height: 25px;
padding: 2px 5px;
text-decoration: none;
white-space: nowrap;
}
.button.on {
color: #fff;
background: #444;
}
.button:hover {
color: #000;
background: #fff;
}

@ -1,9 +1,5 @@
<p>
Raum: %room_select%
</p>
<p>
Tag: %day_select%
</p>
%room_select%
%day_select%
<table>
<thead>
<tr>

Loading…
Cancel
Save