ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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  $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 
77  function applyFilter()
78  {
79  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
80  $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);
81  $table->resetOffset();
82  $table->writeFilterToSession();
83  $this->render();
84  }
85 
86  function resetFilter()
87  {
88  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
89  $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);
90  $table->resetOffset();
91  $table->resetFilter();
92  $this->render();
93  }
94 
98  function create()
99  {
100  global $ilCtrl, $tpl, $lng, $ilTabs;
101 
102  $ilTabs->clearTargets();
103  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
104 
105  $this->setHelpId('create');
106 
107  $form = $this->initForm();
108  $tpl->setContent($form->getHTML());
109  }
110 
114  function edit()
115  {
116  global $tpl, $ilCtrl, $ilTabs, $lng;
117 
118  $ilTabs->clearTargets();
119  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
120 
121  $this->setHelpId('edit');
122 
123  $form = $this->initForm('edit', (int)$_GET['object_id']);
124  $tpl->setContent($form->getHTML());
125  }
126 
127  protected function setHelpId($a_id)
128  {
129  global $ilHelp;
130 
131  $object_subtype = $this->pool_has_schedule
132  ? '-schedule'
133  : '-nonschedule';
134 
135  $ilHelp->setScreenIdComponent('book');
136  $ilHelp->setScreenId('object'.$object_subtype);
137  $ilHelp->setSubScreenId($a_id);
138  }
139 
146  function initForm($a_mode = "create", $id = NULL)
147  {
148  global $lng, $ilCtrl, $ilObjDataCache;
149 
150  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
151 
152  $form_gui = new ilPropertyFormGUI();
153 
154  $title = new ilTextInputGUI($lng->txt("title"), "title");
155  $title->setRequired(true);
156  $title->setSize(40);
157  $title->setMaxLength(120);
158  $form_gui->addItem($title);
159 
160  $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
161  $desc->setCols(70);
162  $desc->setRows(15);
163  $form_gui->addItem($desc);
164 
165  $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
166  $file->setALlowDeletion(true);
167  $form_gui->addItem($file);
168 
169  $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
170  $nr->setRequired(true);
171  $nr->setSize(3);
172  $nr->setMaxLength(3);
173  $form_gui->addItem($nr);
174 
175  if($this->pool_has_schedule)
176  {
177  $options = array();
178  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
179  foreach(ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->ref_id)) as $schedule)
180  {
181  $options[$schedule["booking_schedule_id"]] = $schedule["title"];
182  }
183  $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
184  $schedule->setRequired(true);
185  $schedule->setOptions($options);
186  $form_gui->addItem($schedule);
187  }
188 
189  $post = new ilFormSectionHeaderGUI();
190  $post->setTitle($lng->txt("book_post_booking_information"));
191  $form_gui->addItem($post);
192 
193  $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
194  $pdesc->setCols(70);
195  $pdesc->setRows(15);
196  $pdesc->setInfo($lng->txt("book_post_booking_text_info"));
197  $form_gui->addItem($pdesc);
198 
199  $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
200  $pfile->setALlowDeletion(true);
201  $form_gui->addItem($pfile);
202 
203  if ($a_mode == "edit")
204  {
205  $form_gui->setTitle($lng->txt("book_edit_object"));
206 
207  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
208  $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_EDITOR, "book", $this->pool_id, "bobj", $id);
209  $this->record_gui->setPropertyForm($form_gui);
210  $this->record_gui->parse();
211 
212  $item = new ilHiddenInputGUI('object_id');
213  $item->setValue($id);
214  $form_gui->addItem($item);
215 
216  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
217  $obj = new ilBookingObject($id);
218  $title->setValue($obj->getTitle());
219  $desc->setValue($obj->getDescription());
220  $nr->setValue($obj->getNrOfItems());
221  $pdesc->setValue($obj->getPostText());
222  $file->setValue($obj->getFile());
223  $pfile->setValue($obj->getPostFile());
224 
225  if(isset($schedule))
226  {
227  $schedule->setValue($obj->getScheduleId());
228  }
229 
230  $form_gui->addCommandButton("update", $lng->txt("save"));
231  }
232  else
233  {
234  $form_gui->setTitle($lng->txt("book_add_object"));
235  $form_gui->addCommandButton("save", $lng->txt("save"));
236  $form_gui->addCommandButton("render", $lng->txt("cancel"));
237  }
238  $form_gui->setFormAction($ilCtrl->getFormAction($this));
239 
240  return $form_gui;
241  }
242 
246  function save()
247  {
248  global $ilCtrl, $tpl, $lng, $ilTabs;
249 
250  $form = $this->initForm();
251  if($form->checkInput())
252  {
253  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
254  $obj = new ilBookingObject;
255  $obj->setPoolId($this->pool_id);
256  $obj->setTitle($form->getInput("title"));
257  $obj->setDescription($form->getInput("desc"));
258  $obj->setNrOfItems($form->getInput("items"));
259  $obj->setPostText($form->getInput("post_text"));
260 
261  if($this->pool_has_schedule)
262  {
263  $obj->setScheduleId($form->getInput("schedule"));
264  }
265 
266  $obj->save();
267 
268  $file = $form->getItemByPostVar("file");
269  if($_FILES["file"]["tmp_name"])
270  {
271  $obj->uploadFile($_FILES["file"]);
272  }
273  else if($file->getDeletionFlag())
274  {
275  $obj->deleteFile();
276  }
277 
278  $pfile = $form->getItemByPostVar("post_file");
279  if($_FILES["post_file"]["tmp_name"])
280  {
281  $obj->uploadPostFile($_FILES["post_file"]);
282  }
283  else if($pfile->getDeletionFlag())
284  {
285  $obj->deletePostFile();
286  }
287 
288  $obj->update();
289 
290  ilUtil::sendSuccess($lng->txt("book_object_added"));
291  $this->render();
292  }
293  else
294  {
295  $ilTabs->clearTargets();
296  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
297 
298  $form->setValuesByPost();
299  $tpl->setContent($form->getHTML());
300  }
301  }
302 
306  function update()
307  {
308  global $tpl, $lng;
309 
310  $form = $this->initForm('edit', (int)$_POST['object_id']);
311  if($form->checkInput())
312  {
313  $valid = true;
314  if($this->record_gui &&
315  !$this->record_gui->importEditFormPostValues())
316  {
317  $valid = false;
318  }
319 
320  if($valid)
321  {
322  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
323  $obj = new ilBookingObject((int)$_POST['object_id']);
324  $obj->setTitle($form->getInput("title"));
325  $obj->setDescription($form->getInput("desc"));
326  $obj->setNrOfItems($form->getInput("items"));
327  $obj->setPostText($form->getInput("post_text"));
328 
329  $file = $form->getItemByPostVar("file");
330  if($_FILES["file"]["tmp_name"])
331  {
332  $obj->uploadFile($_FILES["file"]);
333  }
334  else if($file->getDeletionFlag())
335  {
336  $obj->deleteFile();
337  }
338 
339  $pfile = $form->getItemByPostVar("post_file");
340  if($_FILES["post_file"]["tmp_name"])
341  {
342  $obj->uploadPostFile($_FILES["post_file"]);
343  }
344  else if($pfile->getDeletionFlag())
345  {
346  $obj->deletePostFile();
347  }
348 
349  if($this->pool_has_schedule)
350  {
351  $obj->setScheduleId($form->getInput("schedule"));
352  }
353 
354  $obj->update();
355 
356  if($this->record_gui)
357  {
358  $this->record_gui->writeEditForm();
359  }
360 
361  ilUtil::sendSuccess($lng->txt("book_object_updated"));
362  $this->render();
363  }
364  }
365 
366  $form->setValuesByPost();
367  $tpl->setContent($form->getHTML());
368  }
369 
373  function confirmDelete()
374  {
375  global $ilCtrl, $lng, $tpl, $ilTabs;
376 
377  $ilTabs->clearTargets();
378  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
379 
380  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
381  $conf = new ilConfirmationGUI();
382  $conf->setFormAction($ilCtrl->getFormAction($this));
383  $conf->setHeaderText($lng->txt('book_confirm_delete'));
384 
385  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
386  $type = new ilBookingObject((int)$_GET['object_id']);
387  $conf->addItem('object_id', (int)$_GET['object_id'], $type->getTitle());
388  $conf->setConfirm($lng->txt('delete'), 'delete');
389  $conf->setCancel($lng->txt('cancel'), 'render');
390 
391  $tpl->setContent($conf->getHTML());
392  }
393 
397  function delete()
398  {
399  global $ilCtrl, $lng;
400 
401  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
402  $obj = new ilBookingObject((int)$_POST['object_id']);
403  $obj->delete();
404 
405  ilUtil::sendSuccess($lng->txt('book_object_deleted'), true);
406  $ilCtrl->redirect($this, 'render');
407  }
408 
410  {
411  global $ilCtrl, $lng, $tpl;
412 
413  $id = (int)$_GET["object_id"];
414  if(!$id)
415  {
416  return;
417  }
418 
419  $this->setHelpId("cancel_booking");
420 
421  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
422  $conf = new ilConfirmationGUI();
423  $conf->setFormAction($ilCtrl->getFormAction($this));
424  $conf->setHeaderText($lng->txt('book_confirm_cancel'));
425 
426  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
427  $type = new ilBookingObject($id);
428  $conf->addItem('object_id', $id, $type->getTitle());
429  $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancelUser');
430  $conf->setCancel($lng->txt('cancel'), 'render');
431 
432  $tpl->setContent($conf->getHTML());
433  }
434 
435  function rsvCancelUser()
436  {
437  global $ilCtrl, $ilUser, $lng;
438 
439  $id = (int)$_REQUEST["object_id"];
440  if(!$id)
441  {
442  return;
443  }
444 
445  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
446  $id = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId());
447  $obj = new ilBookingReservation($id);
448  if ($obj->getUserId() != $ilUser->getId())
449  {
450  ilUtil::sendFailure($lng->txt('permission_denied'), true);
451  $ilCtrl->redirect($this, 'render');
452  }
453 
455  $obj->update();
456 
457  ilUtil::sendSuccess($lng->txt('settings_saved'));
458  $ilCtrl->redirect($this, 'render');
459  }
460 
461  function deliverInfo()
462  {
463  $id = (int)$_GET["object_id"];
464  if(!$id)
465  {
466  return;
467  }
468 
469  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
470  $obj = new ilBookingObject($id);
471  $file = $obj->getFileFullPath();
472  if($file)
473  {
474  ilUtil::deliverFile($file, $obj->getFile());
475  }
476  }
477 
478  public function displayPostInfo()
479  {
480  global $tpl, $ilUser, $lng, $ilCtrl;
481 
482  $id = (int)$_GET["object_id"];
483  if(!$id)
484  {
485  return;
486  }
487 
488 
489  // placeholder
490 
491  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
492  $book_ids = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId(), true);
493  $tmp = array();
494  $rsv_ids = explode(";", $_GET["rsv_ids"]);
495  foreach($book_ids as $book_id)
496  {
497  if(in_array($book_id, $rsv_ids))
498  {
499  $obj = new ilBookingReservation($book_id);
500  $from = $obj->getFrom();
501  $to = $obj->getTo();
502  if($from > time())
503  {
504  $tmp[$from."-".$to]++;
505  }
506  }
507  }
508 
511 
512  $period = array();
513  ksort($tmp);
514  foreach($tmp as $time => $counter)
515  {
516  $time = explode("-", $time);
518  new ilDateTime($time[0], IL_CAL_UNIX),
519  new ilDateTime($time[1], IL_CAL_UNIX));
520  if($counter > 1)
521  {
522  $time .= " (".$counter.")";
523  }
524  $period[] = $time;
525  }
526  $book_id = array_shift($book_ids);
527 
529 
530 
531  $obj = new ilBookingReservation($book_id);
532  if ($obj->getUserId() != $ilUser->getId())
533  {
534  return;
535  }
536 
537  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
538  $obj = new ilBookingObject($id);
539  $pfile = $obj->getPostFile();
540  $ptext = $obj->getPostText();
541 
542  $mytpl = new ilTemplate('tpl.booking_reservation_post.html', true, true, 'Modules/BookingManager');
543  $mytpl->setVariable("TITLE", $lng->txt('book_post_booking_information'));
544 
545  if($ptext)
546  {
547  // placeholder
548  $ptext = str_replace("[OBJECT]", $obj->getTitle(), $ptext);
549  $ptext = str_replace("[PERIOD]", implode("<br />", $period), $ptext);
550 
551  $mytpl->setVariable("POST_TEXT", nl2br($ptext));
552  }
553 
554  if($pfile)
555  {
556  $ilCtrl->setParameter($this, "object_id", $obj->getId());
557  $url = $ilCtrl->getLinkTarget($this, 'deliverPostFile');
558  $ilCtrl->setParameter($this, "object_id", "");
559 
560  $mytpl->setVariable("DOWNLOAD", $lng->txt('download'));
561  $mytpl->setVariable("URL_FILE", $url);
562  $mytpl->setVariable("TXT_FILE", $pfile);
563  }
564 
565  $mytpl->setVariable("TXT_SUBMIT", $lng->txt('ok'));
566  $mytpl->setVariable("URL_SUBMIT", $ilCtrl->getLinkTargetByClass('ilobjbookingpoolgui', 'render'));
567 
568  $tpl->setContent($mytpl->get());
569  }
570 
571  public function deliverPostFile()
572  {
573  global $ilUser;
574 
575  $id = (int)$_GET["object_id"];
576  if(!$id)
577  {
578  return;
579  }
580 
581  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
582  $book_id = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId());
583  $obj = new ilBookingReservation($book_id);
584  if ($obj->getUserId() != $ilUser->getId())
585  {
586  return;
587  }
588 
589  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
590  $obj = new ilBookingObject($id);
591  $file = $obj->getPostFileFullPath();
592  if($file)
593  {
594  ilUtil::deliverFile($file, $obj->getPostFile());
595  }
596  }
597 }
598 
599 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
a bookable ressource
print $file
$_POST['username']
Definition: cron.php:12
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.
$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
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
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)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
create()
Render creation form.
initForm($a_mode="create", $id=NULL)
Build property form.
render()
Render list of booking objects.
save()
Create new object dataset.
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
This class represents a text area property in a property form.
setPoolId($a_pool_id)
Set booking pool id.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
static getList($a_pool_id)
Get list of booking objects for given pool.
setRequired($a_required)
Set Required.
Confirmation screen class.
__construct($a_parent_obj)
Constructor.