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