ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
22  function __construct($a_parent_obj)
23  {
24  $this->ref_id = $a_parent_obj->ref_id;
25  $this->pool_id = $a_parent_obj->object->getId();
26  $this->pool_has_schedule =
27  ($a_parent_obj->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE);
28  }
29 
33  function executeCommand()
34  {
35  global $ilCtrl;
36 
37  $next_class = $ilCtrl->getNextClass($this);
38 
39  switch($next_class)
40  {
41  default:
42  $cmd = $ilCtrl->getCmd("render");
43  $this->$cmd();
44  break;
45  }
46  return true;
47  }
48 
54  function render()
55  {
56  global $tpl, $ilCtrl, $lng, $ilAccess;
57 
58  if ($ilAccess->checkAccess('write', '', $this->ref_id))
59  {
60  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
61  $bar = new ilToolbarGUI;
62  $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
63  $bar = $bar->getHTML();
64  }
65 
66  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
67  $plink = new ilPermanentLinkGUI('book', $this->ref_id);
68 
69  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
70  $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule);
71  $tpl->setContent($bar.$table->getHTML().$plink->getHTML());
72  }
73 
77  function create()
78  {
79  global $ilCtrl, $tpl, $lng, $ilTabs;
80 
81  $ilTabs->clearTargets();
82  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
83 
84  $form = $this->initForm();
85  $tpl->setContent($form->getHTML());
86  }
87 
91  function edit()
92  {
93  global $tpl, $ilCtrl, $ilTabs, $lng;
94 
95  $ilTabs->clearTargets();
96  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
97 
98  $form = $this->initForm('edit', (int)$_GET['object_id']);
99  $tpl->setContent($form->getHTML());
100  }
101 
108  function initForm($a_mode = "create", $id = NULL)
109  {
110  global $lng, $ilCtrl, $ilObjDataCache;
111 
112  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
113 
114  $form_gui = new ilPropertyFormGUI();
115 
116  $title = new ilTextInputGUI($lng->txt("title"), "title");
117  $title->setRequired(true);
118  $title->setSize(40);
119  $title->setMaxLength(120);
120  $form_gui->addItem($title);
121 
122  $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
123  $desc->setCols(70);
124  $desc->setRows(15);
125  $form_gui->addItem($desc);
126 
127  $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
128  $file->setALlowDeletion(true);
129  $form_gui->addItem($file);
130 
131  $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
132  $nr->setRequired(true);
133  $nr->setSize(3);
134  $nr->setMaxLength(3);
135  $form_gui->addItem($nr);
136 
137  if($this->pool_has_schedule)
138  {
139  $options = array();
140  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
141  foreach(ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->ref_id)) as $schedule)
142  {
143  $options[$schedule["booking_schedule_id"]] = $schedule["title"];
144  }
145  $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
146  $schedule->setRequired(true);
147  $schedule->setOptions($options);
148  $form_gui->addItem($schedule);
149  }
150 
151  $post = new ilFormSectionHeaderGUI();
152  $post->setTitle($lng->txt("book_post_booking_information"));
153  $form_gui->addItem($post);
154 
155  $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
156  $pdesc->setCols(70);
157  $pdesc->setRows(15);
158  $form_gui->addItem($pdesc);
159 
160  $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
161  $pfile->setALlowDeletion(true);
162  $form_gui->addItem($pfile);
163 
164  if ($a_mode == "edit")
165  {
166  $form_gui->setTitle($lng->txt("book_edit_object"));
167 
168  $item = new ilHiddenInputGUI('object_id');
169  $item->setValue($id);
170  $form_gui->addItem($item);
171 
172  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
173  $obj = new ilBookingObject($id);
174  $title->setValue($obj->getTitle());
175  $desc->setValue($obj->getDescription());
176  $nr->setValue($obj->getNrOfItems());
177  $pdesc->setValue($obj->getPostText());
178  $file->setValue($obj->getFile());
179  $pfile->setValue($obj->getPostFile());
180 
181  if(isset($schedule))
182  {
183  $schedule->setValue($obj->getScheduleId());
184  }
185 
186  $form_gui->addCommandButton("update", $lng->txt("save"));
187  }
188  else
189  {
190  $form_gui->setTitle($lng->txt("book_add_object"));
191  $form_gui->addCommandButton("save", $lng->txt("save"));
192  $form_gui->addCommandButton("render", $lng->txt("cancel"));
193  }
194  $form_gui->setFormAction($ilCtrl->getFormAction($this));
195 
196  return $form_gui;
197  }
198 
202  function save()
203  {
204  global $ilCtrl, $tpl, $lng, $ilTabs;
205 
206  $form = $this->initForm();
207  if($form->checkInput())
208  {
209  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
210  $obj = new ilBookingObject;
211  $obj->setPoolId($this->pool_id);
212  $obj->setTitle($form->getInput("title"));
213  $obj->setDescription($form->getInput("desc"));
214  $obj->setNrOfItems($form->getInput("items"));
215  $obj->setPostText($form->getInput("post_text"));
216 
217  if($this->pool_has_schedule)
218  {
219  $obj->setScheduleId($form->getInput("schedule"));
220  }
221 
222  $obj->save();
223 
224  $file = $form->getItemByPostVar("file");
225  if($_FILES["file"]["tmp_name"])
226  {
227  $obj->uploadFile($_FILES["file"]);
228  }
229  else if($file->getDeletionFlag())
230  {
231  $obj->deleteFile();
232  }
233 
234  $pfile = $form->getItemByPostVar("post_file");
235  if($_FILES["post_file"]["tmp_name"])
236  {
237  $obj->uploadPostFile($_FILES["post_file"]);
238  }
239  else if($pfile->getDeletionFlag())
240  {
241  $obj->deletePostFile();
242  }
243 
244  $obj->update();
245 
246  ilUtil::sendSuccess($lng->txt("book_object_added"));
247  $this->render();
248  }
249  else
250  {
251  $ilTabs->clearTargets();
252  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
253 
254  $form->setValuesByPost();
255  $tpl->setContent($form->getHTML());
256  }
257  }
258 
262  function update()
263  {
264  global $tpl, $lng;
265 
266  $form = $this->initForm('edit', (int)$_POST['object_id']);
267  if($form->checkInput())
268  {
269  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
270  $obj = new ilBookingObject((int)$_POST['object_id']);
271  $obj->setTitle($form->getInput("title"));
272  $obj->setDescription($form->getInput("desc"));
273  $obj->setNrOfItems($form->getInput("items"));
274  $obj->setPostText($form->getInput("post_text"));
275 
276  $file = $form->getItemByPostVar("file");
277  if($_FILES["file"]["tmp_name"])
278  {
279  $obj->uploadFile($_FILES["file"]);
280  }
281  else if($file->getDeletionFlag())
282  {
283  $obj->deleteFile();
284  }
285 
286  $pfile = $form->getItemByPostVar("post_file");
287  if($_FILES["post_file"]["tmp_name"])
288  {
289  $obj->uploadPostFile($_FILES["post_file"]);
290  }
291  else if($pfile->getDeletionFlag())
292  {
293  $obj->deletePostFile();
294  }
295 
296  if($this->pool_has_schedule)
297  {
298  $obj->setScheduleId($form->getInput("schedule"));
299  }
300 
301  $obj->update();
302 
303  ilUtil::sendSuccess($lng->txt("book_object_updated"));
304  $this->render();
305  }
306  else
307  {
308  $form->setValuesByPost();
309  $tpl->setContent($form->getHTML());
310  }
311  }
312 
316  function confirmDelete()
317  {
318  global $ilCtrl, $lng, $tpl, $ilTabs;
319 
320  $ilTabs->clearTargets();
321  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
322 
323  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
324  $conf = new ilConfirmationGUI();
325  $conf->setFormAction($ilCtrl->getFormAction($this));
326  $conf->setHeaderText($lng->txt('book_confirm_delete'));
327 
328  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
329  $type = new ilBookingObject((int)$_GET['object_id']);
330  $conf->addItem('object_id', (int)$_GET['object_id'], $type->getTitle());
331  $conf->setConfirm($lng->txt('delete'), 'delete');
332  $conf->setCancel($lng->txt('cancel'), 'render');
333 
334  $tpl->setContent($conf->getHTML());
335  }
336 
340  function delete()
341  {
342  global $ilCtrl, $lng;
343 
344  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
345  $obj = new ilBookingObject((int)$_POST['object_id']);
346  $obj->delete();
347 
348  ilUtil::sendSuccess($lng->txt('book_object_deleted'), true);
349  $ilCtrl->redirect($this, 'render');
350  }
351 
353  {
354  global $ilCtrl, $lng, $tpl;
355 
356  $id = (int)$_GET["object_id"];
357  if(!$id)
358  {
359  return;
360  }
361 
362  // #12310
363  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
364  $conf = new ilConfirmationGUI();
365  $conf->setFormAction($ilCtrl->getFormAction($this, 'rsvCancelUser'));
366  $conf->setHeaderText($lng->txt('book_confirm_cancel'));
367 
368  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
369  $type = new ilBookingObject((int)$_GET['object_id']);
370  $conf->addItem('object_id', (int)$_GET['object_id'], $type->getTitle());
371  $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancelUser');
372  $conf->setCancel($lng->txt('cancel'), 'render');
373 
374  $tpl->setContent($conf->getHTML());
375  }
376 
377  function rsvCancelUser()
378  {
379  global $ilCtrl, $ilUser, $lng;
380 
381  $id = (int)$_REQUEST["object_id"];
382  if(!$id)
383  {
384  return;
385  }
386 
387  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
388  $id = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId());
389  $obj = new ilBookingReservation($id);
390  if ($obj->getUserId() != $ilUser->getId())
391  {
392  ilUtil::sendFailure($lng->txt('permission_denied'), true);
393  $ilCtrl->redirect($this, 'render');
394  }
395 
397  $obj->update();
398 
399  ilUtil::sendSuccess($lng->txt('settings_saved'));
400  $ilCtrl->redirect($this, 'render');
401  }
402 
403  function deliverInfo()
404  {
405  $id = (int)$_GET["object_id"];
406  if(!$id)
407  {
408  return;
409  }
410 
411  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
412  $obj = new ilBookingObject($id);
413  $file = $obj->getFileFullPath();
414  if($file)
415  {
416  ilUtil::deliverFile($file, $obj->getFile());
417  }
418  }
419 
420  public function displayPostInfo()
421  {
422  global $tpl, $ilUser, $lng, $ilCtrl;
423 
424  $id = (int)$_GET["object_id"];
425  if(!$id)
426  {
427  return;
428  }
429 
430  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
431  $book_id = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId());
432  $obj = new ilBookingReservation($book_id);
433  if ($obj->getUserId() != $ilUser->getId())
434  {
435  return;
436  }
437 
438  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
439  $obj = new ilBookingObject($id);
440  $pfile = $obj->getPostFile();
441  $ptext = $obj->getPostText();
442 
443  $mytpl = new ilTemplate('tpl.booking_reservation_post.html', true, true, 'Modules/BookingManager');
444  $mytpl->setVariable("TITLE", $lng->txt('book_post_booking_information'));
445 
446  if($ptext)
447  {
448  $mytpl->setVariable("POST_TEXT", nl2br($ptext));
449  }
450 
451  if($pfile)
452  {
453  $ilCtrl->setParameter($this, "object_id", $obj->getId());
454  $url = $ilCtrl->getLinkTarget($this, 'deliverPostFile');
455  $ilCtrl->setParameter($this, "object_id", "");
456 
457  $mytpl->setVariable("DOWNLOAD", $lng->txt('download'));
458  $mytpl->setVariable("URL_FILE", $url);
459  $mytpl->setVariable("TXT_FILE", $pfile);
460  }
461 
462  $mytpl->setVariable("TXT_SUBMIT", $lng->txt('ok'));
463  $mytpl->setVariable("URL_SUBMIT", $ilCtrl->getLinkTargetByClass('ilobjbookingpoolgui', 'render'));
464 
465  $tpl->setContent($mytpl->get());
466  }
467 
468  public function deliverPostFile()
469  {
470  global $ilUser;
471 
472  $id = (int)$_GET["object_id"];
473  if(!$id)
474  {
475  return;
476  }
477 
478  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
479  $book_id = ilBookingReservation::getObjectReservationForUser($id, $ilUser->getId());
480  $obj = new ilBookingReservation($book_id);
481  if ($obj->getUserId() != $ilUser->getId())
482  {
483  return;
484  }
485 
486  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
487  $obj = new ilBookingObject($id);
488  $file = $obj->getPostFileFullPath();
489  if($file)
490  {
491  ilUtil::deliverFile($file, $obj->getPostFile());
492  }
493  }
494 }
495 
496 ?>