moved db_user calls from includes to actual script, buggy when included from navigation
[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
32 db_user("roomreservation");
33
34 $page = new mod_roomReservationBookingPage($g_rrCfg, $g_rrRm, $g_rrBm);
35 $page->setTitle(_c("room-reservation:Schedule of room bookings"));
36 $page->show();
37
38 /**
39 require_once("sec/secure.inc");
40 require_once("mod_rooms.inc");
41 TestConfig();
42
43 // Ist der User berechtigt?
44 $bAllowAccess = false;
45 foreach($user[groups] as $group)
46 {
47 foreach($cfgRooms["AllowedGroups"] as $allowed)
48 {
49 $bAllowAccess |= (($group == $allowed) == true);
50 }
51 }
52 if(!$bAllowAccess and $cfgRooms["RestrictAccess"] == true)
53 die_nice("Fehler: Sie sind nicht berechtigt, diese Seite zu benutzen. Wenden Sie sich an einen Administrator.");
54
55 $bookings = new AllBookings(false);
56
57 // Zeitstunden in Schulstunden umrechnen
58 $lessons_begin = array_flip($cfgRooms["TimeslicesBegin"]);
59 $lessons_end = array_flip($cfgRooms["TimeslicesEnd"]);
60
61 $action = $_GET["action"];
62 $room = isset($_GET["room"]) ? $_GET["room"] : $cfgRooms["Rooms"][0];
63 $start = isset($_GET["start"]) ? $_GET["start"] : Monday();
64 $act = $user[act];
65 $id = isset($_POST["id"]) ? $_POST["id"] : $_GET["id"];
66 $class = isset($_POST["class"]) ? $_POST["class"] : $_GET["class"];
67 $room_form = isset($_POST["room_form"]) ? $_POST["room_form"] : $_GET["room"];
68 $date = isset($_POST["date"]) ? $_POST["date"] : $_GET["date"];
69 $timebegin = isset($_POST["timebegin"]) ? $_POST["timebegin"] : $_GET["timebegin"];
70 $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
71 $reason = isset($_POST["reason"]) ? $_POST["reason"] : $_GET["reason"];
72 $submit = $_POST["submit"];
73 $cancel = $_POST["cancel"];
74
75 PageBlue("Raumbelegungsplan", "rooms_index");
76
77 // Formular anzeigen
78 function ShowForm()
79 {
80 global $cfgRooms;
81 global $act, $class, $room_form, $date, $timebegin, $timeend, $reason, $user;
82
83 Title("Einen Raum buchen");
84 $form = "<p>Füllen Sie das Formular aus und klicken Sie dann auf die Schaltfläche &bdquo;Raum buchen&ldquo;.</p>
85 <form action='?action=insert' method='post'>
86 <input type='hidden' name='id' value='$id' />
87 <table><tr>
88 <td>Ihr Name:</td><td colspan='4'>{$user[name]}</td>
89 </tr>";
90
91 // Klasse nur anzeigen, wenn angeschaltet
92 if($cfgRooms["ShowClassEdit"])
93 $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>";
94
95 $form .= "<tr>\n <td>Raum:</td><td colspan='4'><select style='width:100%' name='room_form'>";
96 foreach($cfgRooms["Rooms"] as $rm)
97 {
98 if($rm == $room_form)
99 $form .= "<option selected='selected'>".q(stripslashes($rm))."</option>";
100 else
101 $form .= "<option>".q(stripslashes($rm))."</option>";
102 }
103 $form .= "</select></td>\n</tr><tr>\n";
104 $form .= " <td>Datum:</td><td colspan='4'><input type='text' style='width:100%' name='date' value='".q(stripslashes($date))."' /></td>\n</tr><tr>\n";
105 $form .= " <td>Zeit:</td><td>von</td><td><select style='width:60pt' name='timebegin'>";
106 foreach($cfgRooms["TimeslicesBegin"] as $time)
107 {
108 if($time == $timebegin)
109 $form .= "<option selected='selected'>".q(stripslashes($time))."</option>";
110 else
111 $form .= "<option>".q(stripslashes($time))."</option>";
112 }
113 $form .= "</select></td><td>bis</td><td><select style='width:60pt' name='timeend'>";
114 foreach($cfgRooms["TimeslicesEnd"] as $time)
115 {
116 if($time == $timeend)
117 $form .= "<option selected='selected'>".q(stripslashes($time))."</option>";
118 else
119 $form .= "<option>".q(stripslashes($time))."</option>";
120 }
121 $form .= "</select></td>\n</tr><tr>\n";
122 $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";
123 $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>";
124
125 echo $form;
126 }
127
128
129 if($action == "book")
130 {
131 ShowForm();
132 }
133 // ...oder Buchung löschen?
134 else if($action == "delete")
135 {
136 // Rausfinden, wo unsere gewünschte ID im Array steht
137 for($n = 0; isset($bookings->objBookings[$n]->sqlData->id) and ($id != $bookings->objBookings[$n]->sqlData->id); $n++);
138
139 // Auf Besitz oder Admin prüfen
140 $bAdminMode = FALSE;
141 $bAdminMode |= ($bookings->objBookings[$n]->UserIsOwner() and !$bookings->objBookings[$n]->rawData->fixed); // Benutzer dürfen keine festen Buchungen löschen
142 $bAdminMode |= $bookings->UserIsAdmin();
143
144 if(!$bAdminMode)
145 echo "<div class='err'>Sie sind nicht berechtigt, diese Buchung zu löschen!</div>\n";
146 else
147 {
148 if($_POST["surely_delete"] == "Löschen" && $_POST["surely_delete_fixed"] == "true")
149 {
150 $bookings->Delete($id);
151 echo "<div class='err'>Ihre Buchung wurde gelöscht.</div>\n";
152 }
153 else
154 {
155 echo "<h1>Eine Buchung löschen</h1>\n";
156 if($bookings->objBookings[$n]->rawData->fixed and $_POST["surely_delete_fixed"] == "false")
157 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";
158 // Formular zur Bestätigung anzeigen
159 echo "<p>Wollen Sie diese Buchung löschen?<p>\n";
160 $bookings->PrintBooking($id);
161 echo "<br />\n";
162 echo "<form action='?action=delete&amp;id=$id' method='post'>\n";
163 if($bookings->objBookings[$n]->rawData->fixed)
164 // Bestätigungsfeld für feste Buchungen
165 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";
166 else
167 echo "<input type='hidden' name='surely_delete_fixed' value='true' />\n";
168 echo "<$stdbtn name='surely_delete' value='Löschen' /></form>\n";
169 }
170 }
171
172 // Zurück-Link anzeigen
173 Option(_("Back"), "", "href='?room=$room&amp;start=$start'", "back");
174 }
175
176 // ... oder alle Buchungen anzeigen / Buchung eintragen?
177 else
178 {
179 if($action == "insert" and $submit == "Raum buchen")
180 {
181 $err = $bookings->Insert(null, $room_form, $date, $timebegin, $timeend, $act, $class, $reason, false);
182 if(!$err)
183 {
184 switch($bookings->lastError)
185 {
186 case ALLBOOKINGS_SQL_ERROR:
187 ReportError("\$booking->Insert", $booking->lastError, __FILE__, __LINE__);
188 default:
189 }
190 ShowForm();
191 die_nice();
192 }
193 else
194 {
195 // Log-Eintrag, wenn erwünscht
196 if($cfgRooms["LogOnInsert"])
197 InsertLog("Raum $room_form am $date von $timebegin bis $timeend gebucht. Begründung: $reason");
198
199 // Passenderweise gleich die Woche mit der eingetragenen Buchung anzeigen
200 $tmp = explode(".", $date);
201 $start = Monday(strtotime($tmp[2]."-".$tmp[1]."-".$tmp[0]));
202 $room = $room_form;
203 Title("Raumbelegungen für den Raum $room in Woche ".date("W", $start));
204 echo "<p class='err'>".icona("dlg-info", 16, "bl")."Ihre Buchung wurde eingetragen.</p>\n";
205 }
206 }
207 else
208 {
209 Title("Raumbelegungen für den Raum $room in Woche ".date("W", $start));
210 }
211
212 $nPrevWeek = strtotime("last monday", Monday($start)); // der Montag vor dem Montag in der Startwoche
213 $nFirstWeek = Monday(); // der Montag in der aktuellen Woche
214 $nLastWeek = strtotime("last monday", Monday($bookings->GetLastBookingDate()));
215 $nNextWeek = strtotime("next monday", Monday($start)); // der Montag nach dem Montag der Startwoche
216
217 echo "<form action=''>
218 Raum: <select onchange='window.location.href=\"{$_SERVER["PHP_SELF"]}?start=$start&amp;room=\" + this.options[this.options.selectedIndex].text;' width='250'>\n";
219 foreach($cfgRooms["Rooms"] as $opt)
220 {
221 echo " <option";
222 if($opt == $room)
223 echo " selected='selected'";
224 echo ">".q(stripslashes($opt))."</option>\n";
225 }
226 echo "</select></form></p>";
227
228 // Navigation für die Wochen ausgeben
229 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> | ";
230 // Fünf Wochen zur direkten Anwahl anbieten
231 for($i = 1; $i <= 5; $i++)
232 {
233 $nCurWeek = Monday(strtotime("$i week", $start));
234 echo "<a href='?start=$nCurWeek&amp;room=".qu(stripslashes($room))."' title='Zu Woche ".date("W", $nCurWeek)." blättern'>Woche ".date("W", $nCurWeek)."</a> | ";
235 }
236 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>";
237 echo "<p><ul>
238 <li>Um eine Buchung vorzunehmen dort auf &bdquo;Ab hier buchen&ldquo; klicken, wo die Buchung beginnen soll.</li>
239 <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>
240 <li>Mit Klick auf den Benutzernamen kann eine E-Mail an den Benutzer geschrieben werden.</li>
241 </ul></p>\n";
242
243 $bookings->PrintTimeTable($start, $room);
244
245 echo "<br />";
246 }
247
248 _PageBlue();
249 */
250 ?>
This page took 0.069705 seconds and 5 git commands to generate.