0e1de6ed2fdd7c08f21d7e3a6a2d98fb19aa10e5
[iserv-mod-room-reservation.git] / src / index.php
1 <?php
2 /**
3 * @file index.php
4 * Main page
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
6 * @date 25.02.2008
7 *
8 * Copyright © 2007 Roland Hieber
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * THE SOFTWARE.
27 */
28
29 require_once("mod_room-reservation/globals.inc");
30 require_once("mod_room-reservation/mod_roomReservationBookingPage.inc");
31 $page = new mod_roomReservationBookingPage($g_rrCfg, $g_rrRm, $g_rrBm);
32 $page->setTitle(_c("room-reservation:Schedule of room bookings"));
33 $page->show();
34
35 /**
36 require_once("sec/secure.inc");
37 require_once("mod_rooms.inc");
38 TestConfig();
39
40 // Ist der User berechtigt?
41 $bAllowAccess = false;
42 foreach($user[groups] as $group)
43 {
44 foreach($cfgRooms["AllowedGroups"] as $allowed)
45 {
46 $bAllowAccess |= (($group == $allowed) == true);
47 }
48 }
49 if(!$bAllowAccess and $cfgRooms["RestrictAccess"] == true)
50 die_nice("Fehler: Sie sind nicht berechtigt, diese Seite zu benutzen. Wenden Sie sich an einen Administrator.");
51
52 $bookings = new AllBookings(false);
53
54 // Zeitstunden in Schulstunden umrechnen
55 $lessons_begin = array_flip($cfgRooms["TimeslicesBegin"]);
56 $lessons_end = array_flip($cfgRooms["TimeslicesEnd"]);
57
58 $action = $_GET["action"];
59 $room = isset($_GET["room"]) ? $_GET["room"] : $cfgRooms["Rooms"][0];
60 $start = isset($_GET["start"]) ? $_GET["start"] : Monday();
61 $act = $user[act];
62 $id = isset($_POST["id"]) ? $_POST["id"] : $_GET["id"];
63 $class = isset($_POST["class"]) ? $_POST["class"] : $_GET["class"];
64 $room_form = isset($_POST["room_form"]) ? $_POST["room_form"] : $_GET["room"];
65 $date = isset($_POST["date"]) ? $_POST["date"] : $_GET["date"];
66 $timebegin = isset($_POST["timebegin"]) ? $_POST["timebegin"] : $_GET["timebegin"];
67 $timeend = isset($_POST["timeend"]) ? $_POST["timeend"] : (isset($_GET["timeend"]) ? $_GET["timeend"] : $cfgRooms["TimeslicesEnd"][$lessons_begin[$timebegin]]); // Standardmäßig auf einen Zeitraum später als Anfangszeit
68 $reason = isset($_POST["reason"]) ? $_POST["reason"] : $_GET["reason"];
69 $submit = $_POST["submit"];
70 $cancel = $_POST["cancel"];
71
72 PageBlue("Raumbelegungsplan", "rooms_index");
73
74 // Formular anzeigen
75 function ShowForm()
76 {
77 global $cfgRooms;
78 global $act, $class, $room_form, $date, $timebegin, $timeend, $reason, $user;
79
80 Title("Einen Raum buchen");
81 $form = "<p>Füllen Sie das Formular aus und klicken Sie dann auf die Schaltfläche &bdquo;Raum buchen&ldquo;.</p>
82 <form action='?action=insert' method='post'>
83 <input type='hidden' name='id' value='$id' />
84 <table><tr>
85 <td>Ihr Name:</td><td colspan='4'>{$user[name]}</td>
86 </tr>";
87
88 // Klasse nur anzeigen, wenn angeschaltet
89 if($cfgRooms["ShowClassEdit"])
90 $form .= "<tr>\n <td>".q(stripslashes($cfgRooms["ClassEditText"])).":</td><td colspan='4'><input type='edit' style='width:100%' name='class' value='".q(stripslashes($class))."' /></td>\n</tr>";
91
92 $form .= "<tr>\n <td>Raum:</td><td colspan='4'><select style='width:100%' name='room_form'>";
93 foreach($cfgRooms["Rooms"] as $rm)
94 {
95 if($rm == $room_form)
96 $form .= "<option selected='selected'>".q(stripslashes($rm))."</option>";
97 else
98 $form .= "<option>".q(stripslashes($rm))."</option>";
99 }
100 $form .= "</select></td>\n</tr><tr>\n";
101 $form .= " <td>Datum:</td><td colspan='4'><input type='text' style='width:100%' name='date' value='".q(stripslashes($date))."' /></td>\n</tr><tr>\n";
102 $form .= " <td>Zeit:</td><td>von</td><td><select style='width:60pt' name='timebegin'>";
103 foreach($cfgRooms["TimeslicesBegin"] as $time)
104 {
105 if($time == $timebegin)
106 $form .= "<option selected='selected'>".q(stripslashes($time))."</option>";
107 else
108 $form .= "<option>".q(stripslashes($time))."</option>";
109 }
110 $form .= "</select></td><td>bis</td><td><select style='width:60pt' name='timeend'>";
111 foreach($cfgRooms["TimeslicesEnd"] as $time)
112 {
113 if($time == $timeend)
114 $form .= "<option selected='selected'>".q(stripslashes($time))."</option>";
115 else
116 $form .= "<option>".q(stripslashes($time))."</option>";
117 }
118 $form .= "</select></td>\n</tr><tr>\n";
119 $form .= " <td>Grund für die Belegung:</td><td colspan='4'><input type='text' style='width:100%' name='reason' value='".q(stripslashes($reason))."' /></td>\n</tr><tr>\n";
120 $form .= " <td><input type='submit' class='stdbtn submit' name='submit' value='Raum buchen' />&nbsp;&nbsp;<input type='submit' class='stdbtn submit' name='cancel' value='Abbrechen' /></td>\n</tr></table></form>";
121
122 echo $form;
123 }
124
125
126 if($action == "book")
127 {
128 ShowForm();
129 }
130 // ...oder Buchung löschen?
131 else if($action == "delete")
132 {
133 // Rausfinden, wo unsere gewünschte ID im Array steht
134 for($n = 0; isset($bookings->objBookings[$n]->sqlData->id) and ($id != $bookings->objBookings[$n]->sqlData->id); $n++);
135
136 // Auf Besitz oder Admin prüfen
137 $bAdminMode = FALSE;
138 $bAdminMode |= ($bookings->objBookings[$n]->UserIsOwner() and !$bookings->objBookings[$n]->rawData->fixed); // Benutzer dürfen keine festen Buchungen löschen
139 $bAdminMode |= $bookings->UserIsAdmin();
140
141 if(!$bAdminMode)
142 echo "<div class='err'>Sie sind nicht berechtigt, diese Buchung zu löschen!</div>\n";
143 else
144 {
145 if($_POST["surely_delete"] == "Löschen" && $_POST["surely_delete_fixed"] == "true")
146 {
147 $bookings->Delete($id);
148 echo "<div class='err'>Ihre Buchung wurde gelöscht.</div>\n";
149 }
150 else
151 {
152 echo "<h1>Eine Buchung löschen</h1>\n";
153 if($bookings->objBookings[$n]->rawData->fixed and $_POST["surely_delete_fixed"] == "false")
154 echo "<p class='err'>Sie müssen bestätigen, dass Sie die Warnung über das Löschen von festen Buchungen zur Kenntnis genommen haben.</p>\n";
155 // Formular zur Bestätigung anzeigen
156 echo "<p>Wollen Sie diese Buchung löschen?<p>\n";
157 $bookings->PrintBooking($id);
158 echo "<br />\n";
159 echo "<form action='?action=delete&amp;id=$id' method='post'>\n";
160 if($bookings->objBookings[$n]->rawData->fixed)
161 // Bestätigungsfeld für feste Buchungen
162 echo "<p>".icona("dlg-warn", 16)."<b>Achtung:</b> Diese Buchung ist eine feste Buchung. Wenn sie gelöscht wird, wird der Zeitraum nicht in dieser Woche, sondern in <b>allen Wochen</b> wieder freigegeben.</p>\n<p><input type='hidden' name='surely_delete_fixed' value='false' /><$smlchk name='surely_delete_fixed' value='true' /><label for='surely_delete_fixed'>Ich habe diese Warnung zur Kenntnis genommen.</label></p>\n";
163 else
164 echo "<input type='hidden' name='surely_delete_fixed' value='true' />\n";
165 echo "<$stdbtn name='surely_delete' value='Löschen' /></form>\n";
166 }
167 }
168
169 // Zurück-Link anzeigen
170 Option(_("Back"), "", "href='?room=$room&amp;start=$start'", "back");
171 }
172
173 // ... oder alle Buchungen anzeigen / Buchung eintragen?
174 else
175 {
176 if($action == "insert" and $submit == "Raum buchen")
177 {
178 $err = $bookings->Insert(null, $room_form, $date, $timebegin, $timeend, $act, $class, $reason, false);
179 if(!$err)
180 {
181 switch($bookings->lastError)
182 {
183 case ALLBOOKINGS_SQL_ERROR:
184 ReportError("\$booking->Insert", $booking->lastError, __FILE__, __LINE__);
185 default:
186 }
187 ShowForm();
188 die_nice();
189 }
190 else
191 {
192 // Log-Eintrag, wenn erwünscht
193 if($cfgRooms["LogOnInsert"])
194 InsertLog("Raum $room_form am $date von $timebegin bis $timeend gebucht. Begründung: $reason");
195
196 // Passenderweise gleich die Woche mit der eingetragenen Buchung anzeigen
197 $tmp = explode(".", $date);
198 $start = Monday(strtotime($tmp[2]."-".$tmp[1]."-".$tmp[0]));
199 $room = $room_form;
200 Title("Raumbelegungen für den Raum $room in Woche ".date("W", $start));
201 echo "<p class='err'>".icona("dlg-info", 16, "bl")."Ihre Buchung wurde eingetragen.</p>\n";
202 }
203 }
204 else
205 {
206 Title("Raumbelegungen für den Raum $room in Woche ".date("W", $start));
207 }
208
209 $nPrevWeek = strtotime("last monday", Monday($start)); // der Montag vor dem Montag in der Startwoche
210 $nFirstWeek = Monday(); // der Montag in der aktuellen Woche
211 $nLastWeek = strtotime("last monday", Monday($bookings->GetLastBookingDate()));
212 $nNextWeek = strtotime("next monday", Monday($start)); // der Montag nach dem Montag der Startwoche
213
214 echo "<form action=''>
215 Raum: <select onchange='window.location.href=\"{$_SERVER["PHP_SELF"]}?start=$start&amp;room=\" + this.options[this.options.selectedIndex].text;' width='250'>\n";
216 foreach($cfgRooms["Rooms"] as $opt)
217 {
218 echo " <option";
219 if($opt == $room)
220 echo " selected='selected'";
221 echo ">".q(stripslashes($opt))."</option>\n";
222 }
223 echo "</select></form></p>";
224
225 // Navigation für die Wochen ausgeben
226 echo "<p><a href='?start=$nPrevWeek&amp;room=".qu(stripslashes($room))."' title='Zur vorherigen Woche blättern'>Vorherige Woche</a> | <a href='?start=$nFirstWeek&amp;room=".qu(stripslashes($room))."' title='Zur aktuellen Woche blättern'>Aktuelle Woche</a> | ";
227 // Fünf Wochen zur direkten Anwahl anbieten
228 for($i = 1; $i <= 5; $i++)
229 {
230 $nCurWeek = Monday(strtotime("$i week", $start));
231 echo "<a href='?start=$nCurWeek&amp;room=".qu(stripslashes($room))."' title='Zu Woche ".date("W", $nCurWeek)." blättern'>Woche ".date("W", $nCurWeek)."</a> | ";
232 }
233 echo "<a href='?start=$nLastWeek&amp;room=".qu(stripslashes($room))."' title='Zur Woche mit der letzen Buchung blättern'>Letzte Buchung</a> | <a href='?start=$nNextWeek&amp;room=".qu(stripslashes($room))."' title='Zur nächsten Woche blättern'>Nächste Woche</a></p>";
234 echo "<p><ul>
235 <li>Um eine Buchung vorzunehmen dort auf &bdquo;Ab hier buchen&ldquo; klicken, wo die Buchung beginnen soll.</li>
236 <li><b>Neu:</b> Eigene Buchungen (au&szlig;er den wiederkehrenden Buchungen in dunkelblau) können gelöscht werden, indem auf den Link &bdquo;Buchung löschen&ldquo; geklickt wird.</li>
237 <li>Mit Klick auf den Benutzernamen kann eine E-Mail an den Benutzer geschrieben werden.</li>
238 </ul></p>\n";
239
240 $bookings->PrintTimeTable($start, $room);
241
242 echo "<br />";
243 }
244
245 _PageBlue();
246 */
247 ?>
This page took 0.062357 seconds and 3 git commands to generate.