From 024c5ff2e2d1fd84f0ad850d1f1cd845f047e8e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philip=20H=C3=A4usler?=
Date: Sun, 11 Sep 2011 23:01:39 +0200
Subject: [PATCH] #5 preview for shifts to be created
---
includes/pages/admin_shifts.php | 80 +++++++++++++++++++++++++++++-
templates/admin_shift_preview.html | 17 +++++++
templates/admin_shifts.html | 2 +-
3 files changed, 97 insertions(+), 2 deletions(-)
create mode 100644 templates/admin_shift_preview.html
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 .= '' . date("Y-m-d H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . ' ' . $room_array[$shift['RID']] . ' | ';
+ $shifts_table .= '' . $shift['name'] . ' |
';
+ }
+ 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 @@
+Vorschau:
+
+
+
+
+ Timeslot
+ |
+
+ Entries
+ |
+
+
+
+ %shifts_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 @@
-
+
Benötigte Engel: