ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_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  global $ilAccess;
26 
27  $this->access = $ilAccess;
28 
29  $this->ref_id = $a_parent_obj->ref_id;
30  $this->pool_id = $a_parent_obj->object->getId();
31  $this->pool_has_schedule =
32  ($a_parent_obj->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE);
33  $this->pool_overall_limit = $this->pool_has_schedule
34  ? null
35  : $a_parent_obj->object->getOverallLimit();
36  }
37 
41  function executeCommand()
42  {
43  global $ilCtrl;
44 
45  $next_class = $ilCtrl->getNextClass($this);
46 
47  switch($next_class)
48  {
49  default:
50  $cmd = $ilCtrl->getCmd("render");
51  $this->$cmd();
52  break;
53  }
54  return true;
55  }
56 
62  function render()
63  {
64  global $tpl, $ilCtrl, $lng, $ilAccess;
65 
66  if ($ilAccess->checkAccess('write', '', $this->ref_id))
67  {
68  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
69  $bar = new ilToolbarGUI;
70  $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
71  $bar = $bar->getHTML();
72  }
73 
74  $tpl->setPermanentLink('book', $this->ref_id);
75 
76  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
77  $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule, $this->pool_overall_limit);
78  $tpl->setContent($bar.$table->getHTML());
79  }
80 
81  function applyFilter()
82  {
83  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
84  $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule, $this->pool_overall_limit, $this->repo_parent, $this->repo_parent_call);
85  $table->resetOffset();
86  $table->writeFilterToSession();
87  $this->render();
88  }
89 
90  function resetFilter()
91  {
92  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
93  $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule, $this->pool_overall_limit, $this->repo_parent, $this->repo_parent_call);
94  $table->resetOffset();
95  $table->resetFilter();
96  $this->render();
97  }
98 
102  function create(ilPropertyFormGUI $a_form = null)
103  {
104  global $ilCtrl, $tpl, $lng, $ilTabs;
105 
106  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
107  return;
108  }
109 
110 
111  $ilTabs->clearTargets();
112  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
113 
114  $this->setHelpId('create');
115 
116  if(!$a_form)
117  {
118  $a_form = $this->initForm();
119  }
120  $tpl->setContent($a_form->getHTML());
121  }
122 
126  function edit(ilPropertyFormGUI $a_form = null)
127  {
128  global $tpl, $ilCtrl, $ilTabs, $lng;
129 
130  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
131  return;
132  }
133 
134  $ilTabs->clearTargets();
135  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
136 
137  $this->setHelpId('edit');
138 
139  if(!$a_form)
140  {
141  $a_form = $this->initForm('edit', (int)$_GET['object_id']);
142  }
143  $tpl->setContent($a_form->getHTML());
144  }
145 
146  protected function setHelpId($a_id)
147  {
148  global $ilHelp;
149 
150  $object_subtype = $this->pool_has_schedule
151  ? '-schedule'
152  : '-nonschedule';
153 
154  $ilHelp->setScreenIdComponent('book');
155  $ilHelp->setScreenId('object'.$object_subtype);
156  $ilHelp->setSubScreenId($a_id);
157  }
158 
165  function initForm($a_mode = "create", $id = NULL)
166  {
167  global $lng, $ilCtrl, $ilObjDataCache;
168 
169  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
170 
171  $form_gui = new ilPropertyFormGUI();
172 
173  $title = new ilTextInputGUI($lng->txt("title"), "title");
174  $title->setRequired(true);
175  $title->setSize(40);
176  $title->setMaxLength(120);
177  $form_gui->addItem($title);
178 
179  $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
180  $desc->setCols(70);
181  $desc->setRows(15);
182  $form_gui->addItem($desc);
183 
184  $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
185  $file->setALlowDeletion(true);
186  $form_gui->addItem($file);
187 
188  $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
189  $nr->setRequired(true);
190  $nr->setSize(3);
191  $nr->setMaxLength(3);
192  $form_gui->addItem($nr);
193 
194  if($this->pool_has_schedule)
195  {
196  $options = array();
197  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
198  foreach(ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->ref_id)) as $schedule)
199  {
200  $options[$schedule["booking_schedule_id"]] = $schedule["title"];
201  }
202  $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
203  $schedule->setRequired(true);
204  $schedule->setOptions($options);
205  $form_gui->addItem($schedule);
206  }
207 
208  $post = new ilFormSectionHeaderGUI();
209  $post->setTitle($lng->txt("book_post_booking_information"));
210  $form_gui->addItem($post);
211 
212  $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
213  $pdesc->setCols(70);
214  $pdesc->setRows(15);
215  $pdesc->setInfo($lng->txt("book_post_booking_text_info"));
216  $form_gui->addItem($pdesc);
217 
218  $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
219  $pfile->setALlowDeletion(true);
220  $form_gui->addItem($pfile);
221 
222  // #18214 - should also work for new objects
223  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
224  $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_EDITOR, "book", $this->pool_id, "bobj", $id);
225  $this->record_gui->setPropertyForm($form_gui);
226  $this->record_gui->parse();
227 
228  if ($a_mode == "edit")
229  {
230  $form_gui->setTitle($lng->txt("book_edit_object"));
231 
232  $item = new ilHiddenInputGUI('object_id');
233  $item->setValue($id);
234  $form_gui->addItem($item);
235 
236  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
237  $obj = new ilBookingObject($id);
238  $title->setValue($obj->getTitle());
239  $desc->setValue($obj->getDescription());
240  $nr->setValue($obj->getNrOfItems());
241  $pdesc->setValue($obj->getPostText());
242  $file->setValue($obj->getFile());
243  $pfile->setValue($obj->getPostFile());
244 
245  if(isset($schedule))
246  {
247  $schedule->setValue($obj->getScheduleId());
248  }
249 
250  $form_gui->addCommandButton("update", $lng->txt("save"));
251  }
252  else
253  {
254  $form_gui->setTitle($lng->txt("book_add_object"));
255  $form_gui->addCommandButton("save", $lng->txt("save"));
256  $form_gui->addCommandButton("render", $lng->txt("cancel"));
257  }
258  $form_gui->setFormAction($ilCtrl->getFormAction($this));
259 
260  return $form_gui;
261  }
262 
266  function save()
267  {
268  global $ilCtrl, $lng;
269 
270  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
271  return;
272  }
273 
274  $form = $this->initForm();
275  if($form->checkInput())
276  {
277  $valid = true;
278  if($this->record_gui &&
279  !$this->record_gui->importEditFormPostValues())
280  {
281  $valid = false;
282  }
283 
284  if($valid)
285  {
286  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
287  $obj = new ilBookingObject;
288  $obj->setPoolId($this->pool_id);
289  $obj->setTitle($form->getInput("title"));
290  $obj->setDescription($form->getInput("desc"));
291  $obj->setNrOfItems($form->getInput("items"));
292  $obj->setPostText($form->getInput("post_text"));
293 
294  if($this->pool_has_schedule)
295  {
296  $obj->setScheduleId($form->getInput("schedule"));
297  }
298 
299  $obj->save();
300 
301  $file = $form->getItemByPostVar("file");
302  if($_FILES["file"]["tmp_name"])
303  {
304  $obj->uploadFile($_FILES["file"]);
305  }
306  else if($file->getDeletionFlag())
307  {
308  $obj->deleteFile();
309  }
310 
311  $pfile = $form->getItemByPostVar("post_file");
312  if($_FILES["post_file"]["tmp_name"])
313  {
314  $obj->uploadPostFile($_FILES["post_file"]);
315  }
316  else if($pfile->getDeletionFlag())
317  {
318  $obj->deletePostFile();
319  }
320 
321  $obj->update();
322 
323  if($this->record_gui)
324  {
325  $this->record_gui->writeEditForm(null, $obj->getId());
326  }
327 
328  ilUtil::sendSuccess($lng->txt("book_object_added"), true);
329  $ilCtrl->redirect($this, "render");
330  }
331  }
332 
333  $form->setValuesByPost();
334  $this->create($form);
335  }
336 
340  function update()
341  {
342  global $lng, $ilCtrl;
343 
344  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
345  return;
346  }
347 
348  $form = $this->initForm('edit', (int)$_POST['object_id']);
349  if($form->checkInput())
350  {
351  $valid = true;
352  if($this->record_gui &&
353  !$this->record_gui->importEditFormPostValues())
354  {
355  $valid = false;
356  }
357 
358  if($valid)
359  {
360  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
361  $obj = new ilBookingObject((int)$_POST['object_id']);
362  $obj->setTitle($form->getInput("title"));
363  $obj->setDescription($form->getInput("desc"));
364  $obj->setNrOfItems($form->getInput("items"));
365  $obj->setPostText($form->getInput("post_text"));
366 
367  $file = $form->getItemByPostVar("file");
368  if($_FILES["file"]["tmp_name"])
369  {
370  $obj->uploadFile($_FILES["file"]);
371  }
372  else if($file->getDeletionFlag())
373  {
374  $obj->deleteFile();
375  }
376 
377  $pfile = $form->getItemByPostVar("post_file");
378  if($_FILES["post_file"]["tmp_name"])
379  {
380  $obj->uploadPostFile($_FILES["post_file"]);
381  }
382  else if($pfile->getDeletionFlag())
383  {
384  $obj->deletePostFile();
385  }
386 
387  if($this->pool_has_schedule)
388  {
389  $obj->setScheduleId($form->getInput("schedule"));
390  }
391 
392  $obj->update();
393 
394  if($this->record_gui)
395  {
396  $this->record_gui->writeEditForm();
397  }
398 
399  ilUtil::sendSuccess($lng->txt("book_object_updated"), true);
400  $ilCtrl->redirect($this, "render");
401  }
402  }
403 
404  $form->setValuesByPost();
405  $this->edit($form);
406  }
407 
411  function confirmDelete()
412  {
413  global $ilCtrl, $lng, $tpl, $ilTabs;
414  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
415  return;
416  }
417 
418 
419  $ilTabs->clearTargets();
420  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
421 
422  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
423  $conf = new ilConfirmationGUI();
424  $conf->setFormAction($ilCtrl->getFormAction($this));
425  $conf->setHeaderText($lng->txt('book_confirm_delete'));
426 
427  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
428  $type = new ilBookingObject((int)$_GET['object_id']);
429  $conf->addItem('object_id', (int)$_GET['object_id'], $type->getTitle());
430  $conf->setConfirm($lng->txt('delete'), 'delete');
431  $conf->setCancel($lng->txt('cancel'), 'render');
432 
433  $tpl->setContent($conf->getHTML());
434  }
435 
439  function delete()
440  {
441  global $ilCtrl, $lng;
442 
443  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
444  return;
445  }
446 
447  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
448  $obj = new ilBookingObject((int)$_POST['object_id']);
449  $obj->delete();
450 
451  ilUtil::sendSuccess($lng->txt('book_object_deleted'), true);
452  $ilCtrl->redirect($this, 'render');
453  }
454 
456  {
457  global $ilCtrl, $lng, $tpl;
458 
459  $id = (int)$_GET["object_id"];
460  if(!$id)
461  {
462  return;
463  }
464 
465  $this->setHelpId("cancel_booking");
466 
467  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
468  $conf = new ilConfirmationGUI();
469  $conf->setFormAction($ilCtrl->getFormAction($this));
470  $conf->setHeaderText($lng->txt('book_confirm_cancel'));
471 
472  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
473  $type = new ilBookingObject($id);
474  $conf->addItem('object_id', $id, $type->getTitle());
475  $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancelUser');
476  $conf->setCancel($lng->txt('cancel'), 'render');
477 
478  $tpl->setContent($conf->getHTML());
479  }
480 
481  function rsvCancelUser()
482  {
483  global $ilCtrl, $ilUser, $lng;
484 
485  $id = (int)$_REQUEST["object_id"];
486  if(!$id)
487  {
488  return;
489  }
490 
491  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
492  $id = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId());
493  $obj = new ilBookingReservation($id);
494  if ($obj->getUserId() != $ilUser->getId())
495  {
496  ilUtil::sendFailure($lng->txt('permission_denied'), true);
497  $ilCtrl->redirect($this, 'render');
498  }
499 
501  $obj->update();
502 
503  ilUtil::sendSuccess($lng->txt('settings_saved'));
504  $ilCtrl->redirect($this, 'render');
505  }
506 
507  function deliverInfo()
508  {
509  $id = (int)$_GET["object_id"];
510  if(!$id)
511  {
512  return;
513  }
514 
515  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
516  $obj = new ilBookingObject($id);
517  $file = $obj->getFileFullPath();
518  if($file)
519  {
520  ilUtil::deliverFile($file, $obj->getFile());
521  }
522  }
523 
524  public function displayPostInfo()
525  {
526  global $tpl, $ilUser, $lng, $ilCtrl;
527 
528  $id = (int)$_GET["object_id"];
529  if(!$id)
530  {
531  return;
532  }
533 
534 
535  // placeholder
536 
537  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
538  $book_ids = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId(), true);
539  $tmp = array();
540  $rsv_ids = explode(";", $_GET["rsv_ids"]);
541  foreach($book_ids as $book_id)
542  {
543  if(in_array($book_id, $rsv_ids))
544  {
545  $obj = new ilBookingReservation($book_id);
546  $from = $obj->getFrom();
547  $to = $obj->getTo();
548  if($from > time())
549  {
550  $tmp[$from."-".$to]++;
551  }
552  }
553  }
554 
557 
558  $period = array();
559  ksort($tmp);
560  foreach($tmp as $time => $counter)
561  {
562  $time = explode("-", $time);
564  new ilDateTime($time[0], IL_CAL_UNIX),
565  new ilDateTime($time[1], IL_CAL_UNIX));
566  if($counter > 1)
567  {
568  $time .= " (".$counter.")";
569  }
570  $period[] = $time;
571  }
572  $book_id = array_shift($book_ids);
573 
575 
576 
577  $obj = new ilBookingReservation($book_id);
578  if ($obj->getUserId() != $ilUser->getId())
579  {
580  return;
581  }
582 
583  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
584  $obj = new ilBookingObject($id);
585  $pfile = $obj->getPostFile();
586  $ptext = $obj->getPostText();
587 
588  $mytpl = new ilTemplate('tpl.booking_reservation_post.html', true, true, 'Modules/BookingManager');
589  $mytpl->setVariable("TITLE", $lng->txt('book_post_booking_information'));
590 
591  if($ptext)
592  {
593  // placeholder
594  $ptext = str_replace("[OBJECT]", $obj->getTitle(), $ptext);
595  $ptext = str_replace("[PERIOD]", implode("<br />", $period), $ptext);
596 
597  $mytpl->setVariable("POST_TEXT", nl2br($ptext));
598  }
599 
600  if($pfile)
601  {
602  $ilCtrl->setParameter($this, "object_id", $obj->getId());
603  $url = $ilCtrl->getLinkTarget($this, 'deliverPostFile');
604  $ilCtrl->setParameter($this, "object_id", "");
605 
606  $mytpl->setVariable("DOWNLOAD", $lng->txt('download'));
607  $mytpl->setVariable("URL_FILE", $url);
608  $mytpl->setVariable("TXT_FILE", $pfile);
609  }
610 
611  $mytpl->setVariable("TXT_SUBMIT", $lng->txt('ok'));
612  $mytpl->setVariable("URL_SUBMIT", $ilCtrl->getLinkTargetByClass('ilobjbookingpoolgui', 'render'));
613 
614  $tpl->setContent($mytpl->get());
615  }
616 
617  public function deliverPostFile()
618  {
619  global $ilUser;
620 
621  $id = (int)$_GET["object_id"];
622  if(!$id)
623  {
624  return;
625  }
626 
627  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
628  $book_id = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId());
629  $obj = new ilBookingReservation($book_id);
630  if ($obj->getUserId() != $ilUser->getId())
631  {
632  return;
633  }
634 
635  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
636  $obj = new ilBookingObject($id);
637  $file = $obj->getPostFileFullPath();
638  if($file)
639  {
640  ilUtil::deliverFile($file, $obj->getPostFile());
641  }
642  }
643 }
644 
645 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
a bookable ressource
update()
Update object dataset.
This class represents a selection list property in a property form.
This class represents a property form user interface.
$_GET["client_id"]
setALlowDeletion($a_val)
Set allow deletion.
This class represents a section header in a property form.
This class represents a file 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.
edit(ilPropertyFormGUI $a_form=null)
Render edit form.
$valid
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
$cmd
Definition: sahs_server.php:35
static setUseRelativeDates($a_status)
set use relative dates
$url
Definition: shib_logout.php:72
const IL_CAL_UNIX
confirmDelete()
Confirm delete.
static useRelativeDates()
check if relative dates are used
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
create(ilPropertyFormGUI $a_form=null)
Render creation form.
$counter
This class represents a hidden form property in a property form.
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
Class ilBookingObjectGUI.
if(!is_array($argv)) $options
This class represents a number property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
Date and time handling
$ilUser
Definition: imgupload.php:18
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
List booking objects (for booking type)
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
initForm($a_mode="create", $id=NULL)
Build property form.
render()
Render list of booking objects.
save()
Create new object dataset.
global $lng
Definition: privfeed.php:17
This class represents a text area property in a property form.
setPoolId($a_pool_id)
Set booking pool id.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static getList($a_pool_id)
Get list of booking objects for given pool.
$_POST["username"]
setRequired($a_required)
Set Required.
Confirmation screen class.
__construct($a_parent_obj)
Constructor.