#44 shiftplan
This commit is contained in:
parent
e0ffeb1005
commit
8259266297
|
@ -3,7 +3,7 @@ function admin_rooms() {
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
$html = "";
|
$html = "";
|
||||||
$rooms = sql_select("SELECT * FROM `Room` ORDER BY `Number`, `Name`");
|
$rooms = sql_select("SELECT * FROM `Room` ORDER BY `Name`");
|
||||||
if (!isset ($_REQUEST["action"])) {
|
if (!isset ($_REQUEST["action"])) {
|
||||||
$html .= "Hallo " . $user['Nick'] .
|
$html .= "Hallo " . $user['Nick'] .
|
||||||
",<br />\nhier hast du die Möglichkeit, neue Räume für die Schichtpläne einzutragen " .
|
",<br />\nhier hast du die Möglichkeit, neue Räume für die Schichtpläne einzutragen " .
|
||||||
|
|
|
@ -213,28 +213,33 @@ function user_shifts() {
|
||||||
$shifts = sql_select("SELECT COUNT(*) AS `count` FROM `Shifts` ORDER BY `start`");
|
$shifts = sql_select("SELECT COUNT(*) AS `count` FROM `Shifts` ORDER BY `start`");
|
||||||
$days = array ();
|
$days = array ();
|
||||||
$rooms = array ();
|
$rooms = array ();
|
||||||
|
if (!isset ($_SESSION['user_shifts']))
|
||||||
|
$_SESSION['user_shifts'] = array ();
|
||||||
|
|
||||||
if ($shifts[0]["count"] > 0) {
|
if ($shifts[0]["count"] > 0) {
|
||||||
$days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) FROM `Shifts`");
|
$days = sql_select("SELECT DISTINCT DATE(FROM_UNIXTIME(`start`)) FROM `Shifts`");
|
||||||
$days = array_map('array_pop', $days);
|
$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']))
|
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`");
|
$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']))
|
if (isset ($_REQUEST['room_id']) && preg_match("/^[0-9]*$/", $_REQUEST['room_id']))
|
||||||
$id = $_REQUEST['room_id'];
|
$_SESSION['user_shifts']['id'] = $_REQUEST['room_id'];
|
||||||
$day_timestamp = DateTime :: createFromFormat("Y-m-d-Hi", $day . "-0000")->getTimestamp();
|
$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`");
|
$shifts = sql_select("SELECT * FROM `Shifts` JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`) WHERE `start` > " . sql_escape(time()) . " ORDER BY `start`");
|
||||||
else
|
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 = "";
|
$shifts_table = "";
|
||||||
$row_count = 0;
|
$row_count = 0;
|
||||||
foreach ($shifts as $shift) {
|
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))
|
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 .= ' <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 />';
|
$shift_row .= '<br />';
|
||||||
|
@ -266,42 +271,34 @@ function user_shifts() {
|
||||||
$shift_row .= '<br />';
|
$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>';
|
$shifts_table .= $shift_row . '</td></tr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return template_render('../templates/user_shifts.html', array (
|
return template_render('../templates/user_shifts.html', array (
|
||||||
'room_select' => make_room_select($rooms, $id, $day),
|
'room_select' => make_room_select($rooms, $_SESSION['user_shifts']['id'], $_SESSION['user_shifts']['day']),
|
||||||
'day_select' => make_day_select($days, $day, $id),
|
'day_select' => make_day_select($days, $_SESSION['user_shifts']['day'], $_SESSION['user_shifts']['id']),
|
||||||
'shifts_table' => $shifts_table
|
'shifts_table' => $shifts_table
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_day_select($days, $day, $id) {
|
function make_day_select($days, $day, $id) {
|
||||||
|
if ($id == 0)
|
||||||
|
return "";
|
||||||
$html = array ();
|
$html = array ();
|
||||||
foreach ($days as $d) {
|
foreach ($days as $d)
|
||||||
if ($day == $d && $id != 0)
|
$html[] = button(page_link_to('user_shifts') . '&day=' . $d, $d, $day == $d && $id != 0 ? 'on' : '');
|
||||||
$html[] = '<b>' . $d . '</b>';
|
return buttons($html);
|
||||||
else
|
|
||||||
$html[] = '<a href="' . page_link_to('user_shifts') . '&day=' . $d . '&room_id=' . $id . '">' . $d . '</a>';
|
|
||||||
}
|
|
||||||
return join(' | ', $html);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_room_select($rooms, $id, $day) {
|
function make_room_select($rooms, $id, $day) {
|
||||||
$html = array ();
|
$html = array ();
|
||||||
foreach ($rooms as $room) {
|
foreach ($rooms as $room) {
|
||||||
if ($room['RID'] == $id)
|
$html[] = button(page_link_to('user_shifts') . '&room_id=' . $room['RID'], $room['Name'], $room['RID'] == $id ? 'on' : '');
|
||||||
$html[] = '<b>' . $room['Name'] . '</b>';
|
|
||||||
else
|
|
||||||
$html[] = '<a href="' . page_link_to('user_shifts') . '&room_id=' . $room['RID'] . '&day=' . $day . '">' . $room['Name'] . '</a>';
|
|
||||||
}
|
}
|
||||||
if ($id == 0)
|
$html[] = button(page_link_to('user_shifts') . '&room_id=0', "Next free shifts.", $id == 0 ? 'on' : '');
|
||||||
$html[] = '<b>Nächste freie Schichten</b>';
|
return buttons($html);
|
||||||
else
|
|
||||||
$html[] = '<a href="' . page_link_to('user_shifts') . '&room_id=0">Nächste freie Schichten</a>';
|
|
||||||
return join(' | ', $html);
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -147,7 +147,7 @@ function button($href, $label, $class = "") {
|
||||||
* Rendert eine Toolbar mit Knöpfen
|
* Rendert eine Toolbar mit Knöpfen
|
||||||
*/
|
*/
|
||||||
function buttons($buttons = array ()) {
|
function buttons($buttons = array ()) {
|
||||||
return '<div class="toolbar">' . join($buttons) . '</div>';
|
return '<div class="toolbar">' . join(' ', $buttons) . '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load and render template
|
// Load and render template
|
||||||
|
|
|
@ -276,19 +276,26 @@ tr:hover .hidden {
|
||||||
}
|
}
|
||||||
|
|
||||||
.toolbar {
|
.toolbar {
|
||||||
margin: 5px 0 10px 0;
|
margin: 0 0 10px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
background: #f0f0f0;
|
background: #f0f0f0;
|
||||||
border: 1px solid #888;
|
border: 1px solid #888;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin-right: 5px;
|
line-height: 25px;
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.on {
|
||||||
|
color: #fff;
|
||||||
|
background: #444;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:hover {
|
.button:hover {
|
||||||
|
color: #000;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
<p>
|
%room_select%
|
||||||
Raum: %room_select%
|
%day_select%
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Tag: %day_select%
|
|
||||||
</p>
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in New Issue