summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2011-09-11 23:01:39 +0200
committerPhilip Häusler <msquare@notrademark.de>2011-09-11 23:01:39 +0200
commit024c5ff2e2d1fd84f0ad850d1f1cd845f047e8e1 (patch)
treee1aa64e2474cdaa14539d25f541c6ef92872f3a0
parent4303b05d08ba3754bb82dfa728cae31317a6aeb8 (diff)
#5 preview for shifts to be created
-rw-r--r--includes/pages/admin_shifts.php80
-rw-r--r--templates/admin_shift_preview.html17
-rw-r--r--templates/admin_shifts.html2
3 files changed, 97 insertions, 2 deletions
diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php
index d1981b5c..970996d7 100644
--- a/includes/pages/admin_shifts.php
+++ b/includes/pages/admin_shifts.php
@@ -76,7 +76,7 @@ function admin_shifts() {
}
}
elseif ($_REQUEST['mode'] == 'variable') {
- if (isset ($_REQUEST['change_hours']) && preg_match("/^([0-9]+(,|$))/", trim(str_replace(" ", "", $_REQUEST['change_hours'])))) {
+ if (isset ($_REQUEST['change_hours']) && preg_match("/^([0-9]{2}(,|$))/", trim(str_replace(" ", "", $_REQUEST['change_hours'])))) {
$mode = 'variable';
$change_hours = explode(",", $_REQUEST['change_hours']);
} else {
@@ -107,6 +107,84 @@ function admin_shifts() {
$msg .= error("Bitte Wähle einen Modus für die benötigten Engel.");
}
}
+
+ // Alle Eingaben in Ordnung
+ if ($ok) {
+ $shifts = array ();
+ if ($mode == 'single') {
+ $shifts[] = array (
+ 'start' => $start,
+ 'end' => $end,
+ 'RID' => $rid,
+ 'name' => $name
+ );
+ }
+ elseif ($mode == 'multi') {
+ $shift_start = $start;
+ do {
+ $shift_end = $shift_start + $length * 60;
+
+ if ($shift_end > $end)
+ $shift_end = $end;
+ if ($shift_start >= $shift_end)
+ break;
+
+ $shifts[] = array (
+ 'start' => $shift_start,
+ 'end' => $shift_end,
+ 'RID' => $rid,
+ 'name' => $name
+ );
+
+ $shift_start = $shift_end;
+ } while ($shift_end < $end);
+ }
+ elseif ($mode == 'variable') {
+ sort($change_hours);
+ $day = DateTime :: createFromFormat("Y-m-d H:i", date("Y-m-d", $start) . " 00:00")->getTimestamp();
+ $change_index = 0;
+ // Ersten/nächsten passenden Schichtwechsel suchen
+ foreach ($change_hours as $i => $change_hour) {
+ if ($start < $day + $change_hour * 60 * 60)
+ $change_index = $i;
+ elseif ($start == $day + $change_hour * 60 * 60) {
+ // Start trifft Schichtwechsel
+ $change_index = ($i +1) % count($change_hours);
+ break;
+ } else
+ break;
+ }
+
+ $shift_start = $start;
+ do {
+ $day = DateTime :: createFromFormat("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00")->getTimestamp();
+ $shift_end = $day + $change_hours[$change_index] * 60 * 60;
+
+ if ($shift_end > $end)
+ $shift_end = $end;
+ if ($shift_start >= $shift_end)
+ $shift_end += 24 * 60 * 60;
+
+ $shifts[] = array (
+ 'start' => $shift_start,
+ 'end' => $shift_end,
+ 'RID' => $rid,
+ 'name' => $name
+ );
+
+ $shift_start = $shift_end;
+ $change_index = ($change_index +1) % count($change_hours);
+ } while ($shift_end < $end);
+ }
+ $shifts_table = "";
+ foreach ($shifts as $shift) {
+ $shifts_table .= '<tr><td>' . date("Y-m-d H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . '<br />' . $room_array[$shift['RID']] . '</td>';
+ $shifts_table .= '<td>' . $shift['name'] . '</td></tr>';
+ }
+ return template_render('../templates/admin_shift_preview.html', array (
+ 'shifts_table' => $shifts_table
+ ));
+ }
}
$room_select = html_select_key('rid', $room_array, '');
diff --git a/templates/admin_shift_preview.html b/templates/admin_shift_preview.html
new file mode 100644
index 00000000..053191c4
--- /dev/null
+++ b/templates/admin_shift_preview.html
@@ -0,0 +1,17 @@
+<h3>Vorschau:</h3>
+<table>
+ <thead>
+ <tr>
+ <th>
+ Timeslot
+ </th>
+ <th>
+ Entries
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ %shifts_table%
+ </tbody>
+</table>
+
diff --git a/templates/admin_shifts.html b/templates/admin_shifts.html
index a79bd571..1fb62bcd 100644
--- a/templates/admin_shifts.html
+++ b/templates/admin_shifts.html
@@ -52,7 +52,7 @@
<label>
Schichtwechsel-Stunden:
</label>
- <input type="text" name="change_hours" value="00, 04, 08, 10, 12, 14, 16, 18, 20, 22" />
+ <input type="text" name="change_hours" style="width: 300px;" value="00, 04, 08, 10, 12, 14, 16, 18, 20, 22" />
</p><h2>Benötigte Engel:</h2>
<p>
<label>