ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilBookingObjectGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Object/classes/class.ilObjectGUI.php";
5
13{
14 protected $ref_id; // [int]
15 protected $pool_id; // [int]
16 protected $pool_has_schedule; // [bool]
17 protected $pool_overall_limit; // [int]
18
23 function __construct($a_parent_obj)
24 {
25 $this->ref_id = $a_parent_obj->ref_id;
26 $this->pool_id = $a_parent_obj->object->getId();
27 $this->pool_has_schedule =
28 ($a_parent_obj->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE);
29 $this->pool_overall_limit = $this->pool_has_schedule
30 ? null
31 : $a_parent_obj->object->getOverallLimit();
32 }
33
37 function executeCommand()
38 {
39 global $ilCtrl;
40
41 $next_class = $ilCtrl->getNextClass($this);
42
43 switch($next_class)
44 {
45 default:
46 $cmd = $ilCtrl->getCmd("render");
47 $this->$cmd();
48 break;
49 }
50 return true;
51 }
52
58 function render()
59 {
60 global $tpl, $ilCtrl, $lng, $ilAccess;
61
62 if ($ilAccess->checkAccess('write', '', $this->ref_id))
63 {
64 include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
65 $bar = new ilToolbarGUI;
66 $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
67 $bar = $bar->getHTML();
68 }
69
70 $tpl->setPermanentLink('book', $this->ref_id);
71
72 include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
73 $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule, $this->pool_overall_limit);
74 $tpl->setContent($bar.$table->getHTML());
75 }
76
80 function create()
81 {
82 global $ilCtrl, $tpl, $lng, $ilTabs;
83
84 $ilTabs->clearTargets();
85 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
86
87 $form = $this->initForm();
88 $tpl->setContent($form->getHTML());
89 }
90
94 function edit()
95 {
96 global $tpl, $ilCtrl, $ilTabs, $lng;
97
98 $ilTabs->clearTargets();
99 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
100
101 $form = $this->initForm('edit', (int)$_GET['object_id']);
102 $tpl->setContent($form->getHTML());
103 }
104
111 function initForm($a_mode = "create", $id = NULL)
112 {
113 global $lng, $ilCtrl, $ilObjDataCache;
114
115 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
116
117 $form_gui = new ilPropertyFormGUI();
118
119 $title = new ilTextInputGUI($lng->txt("title"), "title");
120 $title->setRequired(true);
121 $title->setSize(40);
122 $title->setMaxLength(120);
123 $form_gui->addItem($title);
124
125 $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
126 $desc->setCols(70);
127 $desc->setRows(15);
128 $form_gui->addItem($desc);
129
130 $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
131 $file->setALlowDeletion(true);
132 $form_gui->addItem($file);
133
134 $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
135 $nr->setRequired(true);
136 $nr->setSize(3);
137 $nr->setMaxLength(3);
138 $form_gui->addItem($nr);
139
140 if($this->pool_has_schedule)
141 {
142 $options = array();
143 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
144 foreach(ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->ref_id)) as $schedule)
145 {
146 $options[$schedule["booking_schedule_id"]] = $schedule["title"];
147 }
148 $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
149 $schedule->setRequired(true);
150 $schedule->setOptions($options);
151 $form_gui->addItem($schedule);
152 }
153
154 $post = new ilFormSectionHeaderGUI();
155 $post->setTitle($lng->txt("book_post_booking_information"));
156 $form_gui->addItem($post);
157
158 $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
159 $pdesc->setCols(70);
160 $pdesc->setRows(15);
161 $pdesc->setInfo($lng->txt("book_post_booking_text_info"));
162 $form_gui->addItem($pdesc);
163
164 $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
165 $pfile->setALlowDeletion(true);
166 $form_gui->addItem($pfile);
167
168 if ($a_mode == "edit")
169 {
170 $form_gui->setTitle($lng->txt("book_edit_object"));
171
172 $item = new ilHiddenInputGUI('object_id');
173 $item->setValue($id);
174 $form_gui->addItem($item);
175
176 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
177 $obj = new ilBookingObject($id);
178 $title->setValue($obj->getTitle());
179 $desc->setValue($obj->getDescription());
180 $nr->setValue($obj->getNrOfItems());
181 $pdesc->setValue($obj->getPostText());
182 $file->setValue($obj->getFile());
183 $pfile->setValue($obj->getPostFile());
184
185 if(isset($schedule))
186 {
187 $schedule->setValue($obj->getScheduleId());
188 }
189
190 $form_gui->addCommandButton("update", $lng->txt("save"));
191 }
192 else
193 {
194 $form_gui->setTitle($lng->txt("book_add_object"));
195 $form_gui->addCommandButton("save", $lng->txt("save"));
196 $form_gui->addCommandButton("render", $lng->txt("cancel"));
197 }
198 $form_gui->setFormAction($ilCtrl->getFormAction($this));
199
200 return $form_gui;
201 }
202
206 function save()
207 {
208 global $ilCtrl, $tpl, $lng, $ilTabs;
209
210 $form = $this->initForm();
211 if($form->checkInput())
212 {
213 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
214 $obj = new ilBookingObject;
215 $obj->setPoolId($this->pool_id);
216 $obj->setTitle($form->getInput("title"));
217 $obj->setDescription($form->getInput("desc"));
218 $obj->setNrOfItems($form->getInput("items"));
219 $obj->setPostText($form->getInput("post_text"));
220
221 if($this->pool_has_schedule)
222 {
223 $obj->setScheduleId($form->getInput("schedule"));
224 }
225
226 $obj->save();
227
228 $file = $form->getItemByPostVar("file");
229 if($_FILES["file"]["tmp_name"])
230 {
231 $obj->uploadFile($_FILES["file"]);
232 }
233 else if($file->getDeletionFlag())
234 {
235 $obj->deleteFile();
236 }
237
238 $pfile = $form->getItemByPostVar("post_file");
239 if($_FILES["post_file"]["tmp_name"])
240 {
241 $obj->uploadPostFile($_FILES["post_file"]);
242 }
243 else if($pfile->getDeletionFlag())
244 {
245 $obj->deletePostFile();
246 }
247
248 $obj->update();
249
250 ilUtil::sendSuccess($lng->txt("book_object_added"));
251 $this->render();
252 }
253 else
254 {
255 $ilTabs->clearTargets();
256 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
257
258 $form->setValuesByPost();
259 $tpl->setContent($form->getHTML());
260 }
261 }
262
266 function update()
267 {
268 global $tpl, $lng;
269
270 $form = $this->initForm('edit', (int)$_POST['object_id']);
271 if($form->checkInput())
272 {
273 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
274 $obj = new ilBookingObject((int)$_POST['object_id']);
275 $obj->setTitle($form->getInput("title"));
276 $obj->setDescription($form->getInput("desc"));
277 $obj->setNrOfItems($form->getInput("items"));
278 $obj->setPostText($form->getInput("post_text"));
279
280 $file = $form->getItemByPostVar("file");
281 if($_FILES["file"]["tmp_name"])
282 {
283 $obj->uploadFile($_FILES["file"]);
284 }
285 else if($file->getDeletionFlag())
286 {
287 $obj->deleteFile();
288 }
289
290 $pfile = $form->getItemByPostVar("post_file");
291 if($_FILES["post_file"]["tmp_name"])
292 {
293 $obj->uploadPostFile($_FILES["post_file"]);
294 }
295 else if($pfile->getDeletionFlag())
296 {
297 $obj->deletePostFile();
298 }
299
300 if($this->pool_has_schedule)
301 {
302 $obj->setScheduleId($form->getInput("schedule"));
303 }
304
305 $obj->update();
306
307 ilUtil::sendSuccess($lng->txt("book_object_updated"));
308 $this->render();
309 }
310 else
311 {
312 $form->setValuesByPost();
313 $tpl->setContent($form->getHTML());
314 }
315 }
316
320 function confirmDelete()
321 {
322 global $ilCtrl, $lng, $tpl, $ilTabs;
323
324 $ilTabs->clearTargets();
325 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
326
327 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
328 $conf = new ilConfirmationGUI();
329 $conf->setFormAction($ilCtrl->getFormAction($this));
330 $conf->setHeaderText($lng->txt('book_confirm_delete'));
331
332 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
333 $type = new ilBookingObject((int)$_GET['object_id']);
334 $conf->addItem('object_id', (int)$_GET['object_id'], $type->getTitle());
335 $conf->setConfirm($lng->txt('delete'), 'delete');
336 $conf->setCancel($lng->txt('cancel'), 'render');
337
338 $tpl->setContent($conf->getHTML());
339 }
340
344 function delete()
345 {
346 global $ilCtrl, $lng;
347
348 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
349 $obj = new ilBookingObject((int)$_POST['object_id']);
350 $obj->delete();
351
352 ilUtil::sendSuccess($lng->txt('book_object_deleted'), true);
353 $ilCtrl->redirect($this, 'render');
354 }
355
357 {
358 global $ilCtrl, $lng, $tpl;
359
360 $id = (int)$_GET["object_id"];
361 if(!$id)
362 {
363 return;
364 }
365
366 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
367 $conf = new ilConfirmationGUI();
368 $conf->setFormAction($ilCtrl->getFormAction($this));
369 $conf->setHeaderText($lng->txt('book_confirm_cancel'));
370
371 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
372 $type = new ilBookingObject($id);
373 $conf->addItem('object_id', $id, $type->getTitle());
374 $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancelUser');
375 $conf->setCancel($lng->txt('cancel'), 'render');
376
377 $tpl->setContent($conf->getHTML());
378 }
379
380 function rsvCancelUser()
381 {
382 global $ilCtrl, $ilUser, $lng;
383
384 $id = (int)$_REQUEST["object_id"];
385 if(!$id)
386 {
387 return;
388 }
389
390 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
392 $obj = new ilBookingReservation($id);
393 if ($obj->getUserId() != $ilUser->getId())
394 {
395 ilUtil::sendFailure($lng->txt('permission_denied'), true);
396 $ilCtrl->redirect($this, 'render');
397 }
398
400 $obj->update();
401
402 ilUtil::sendSuccess($lng->txt('settings_saved'));
403 $ilCtrl->redirect($this, 'render');
404 }
405
406 function deliverInfo()
407 {
408 $id = (int)$_GET["object_id"];
409 if(!$id)
410 {
411 return;
412 }
413
414 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
415 $obj = new ilBookingObject($id);
416 $file = $obj->getFileFullPath();
417 if($file)
418 {
419 ilUtil::deliverFile($file, $obj->getFile());
420 }
421 }
422
423 public function displayPostInfo()
424 {
425 global $tpl, $ilUser, $lng, $ilCtrl;
426
427 $id = (int)$_GET["object_id"];
428 if(!$id)
429 {
430 return;
431 }
432
433
434 // placeholder
435
436 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
437 $book_ids = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId(), true);
438 $tmp = array();
439 $rsv_ids = explode(";", $_GET["rsv_ids"]);
440 foreach($book_ids as $book_id)
441 {
442 if(in_array($book_id, $rsv_ids))
443 {
444 $obj = new ilBookingReservation($book_id);
445 $from = $obj->getFrom();
446 $to = $obj->getTo();
447 if($from > time())
448 {
449 $tmp[$from."-".$to]++;
450 }
451 }
452 }
453
456
457 $period = array();
458 ksort($tmp);
459 foreach($tmp as $time => $counter)
460 {
461 $time = explode("-", $time);
463 new ilDateTime($time[0], IL_CAL_UNIX),
464 new ilDateTime($time[1], IL_CAL_UNIX));
465 if($counter > 1)
466 {
467 $time .= " (".$counter.")";
468 }
469 $period[] = $time;
470 }
471 $book_id = array_shift($book_ids);
472
474
475
476 $obj = new ilBookingReservation($book_id);
477 if ($obj->getUserId() != $ilUser->getId())
478 {
479 return;
480 }
481
482 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
483 $obj = new ilBookingObject($id);
484 $pfile = $obj->getPostFile();
485 $ptext = $obj->getPostText();
486
487 $mytpl = new ilTemplate('tpl.booking_reservation_post.html', true, true, 'Modules/BookingManager');
488 $mytpl->setVariable("TITLE", $lng->txt('book_post_booking_information'));
489
490 if($ptext)
491 {
492 // placeholder
493 $ptext = str_replace("[OBJECT]", $obj->getTitle(), $ptext);
494 $ptext = str_replace("[PERIOD]", implode("<br />", $period), $ptext);
495
496 $mytpl->setVariable("POST_TEXT", nl2br($ptext));
497 }
498
499 if($pfile)
500 {
501 $ilCtrl->setParameter($this, "object_id", $obj->getId());
502 $url = $ilCtrl->getLinkTarget($this, 'deliverPostFile');
503 $ilCtrl->setParameter($this, "object_id", "");
504
505 $mytpl->setVariable("DOWNLOAD", $lng->txt('download'));
506 $mytpl->setVariable("URL_FILE", $url);
507 $mytpl->setVariable("TXT_FILE", $pfile);
508 }
509
510 $mytpl->setVariable("TXT_SUBMIT", $lng->txt('ok'));
511 $mytpl->setVariable("URL_SUBMIT", $ilCtrl->getLinkTargetByClass('ilobjbookingpoolgui', 'render'));
512
513 $tpl->setContent($mytpl->get());
514 }
515
516 public function deliverPostFile()
517 {
518 global $ilUser;
519
520 $id = (int)$_GET["object_id"];
521 if(!$id)
522 {
523 return;
524 }
525
526 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
528 $obj = new ilBookingReservation($book_id);
529 if ($obj->getUserId() != $ilUser->getId())
530 {
531 return;
532 }
533
534 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
535 $obj = new ilBookingObject($id);
536 $file = $obj->getPostFileFullPath();
537 if($file)
538 {
539 ilUtil::deliverFile($file, $obj->getPostFile());
540 }
541 }
542}
543
544?>
print $file
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
const IL_CAL_UNIX
Class ilBookingObjectGUI.
update()
Update object dataset.
initForm($a_mode="create", $id=NULL)
Build property form.
render()
Render list of booking objects.
__construct($a_parent_obj)
Constructor.
save()
Create new object dataset.
create()
Render creation form.
a bookable ressource
setPoolId($a_pool_id)
Set booking pool id.
List booking objects (for booking type)
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
static getList($a_pool_id)
Get list of booking objects for given pool.
Confirmation screen class.
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
This class represents a file property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
This class represents a property form user interface.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
addButton($a_txt, $a_cmd, $a_target="", $a_acc_key="", $a_additional_attrs='', $a_id="", $a_class='submit')
Add button to toolbar.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15