ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookingScheduleGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
18  function __construct($a_parent_obj)
19  {
20  $this->ref_id = $a_parent_obj->ref_id;
21  }
22 
26  function executeCommand()
27  {
28  global $tpl, $ilTabs, $ilCtrl;
29 
30  $next_class = $ilCtrl->getNextClass($this);
31 
32  switch($next_class)
33  {
34  default:
35  $cmd = $ilCtrl->getCmd("render");
36  $this->$cmd();
37  break;
38  }
39  return true;
40  }
41 
47  function render()
48  {
49  global $tpl, $lng, $ilCtrl, $ilAccess;
50 
51  include_once 'Modules/BookingManager/classes/class.ilBookingSchedulesTableGUI.php';
52  $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
53 
54  if ($ilAccess->checkAccess('write', '', $this->ref_id))
55  {
56  // if we have schedules but no objects - show info
57  if(sizeof($table->getData()))
58  {
59  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
60  if(!sizeof(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id))))
61  {
62  ilUtil::sendInfo($lng->txt("book_type_warning"));
63  }
64  }
65 
66  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
67  $bar = new ilToolbarGUI;
68  $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
69  $bar = $bar->getHTML();
70  }
71 
72  $tpl->setContent($bar.$table->getHTML());
73  }
74 
78  function create()
79  {
80  global $tpl, $ilCtrl, $ilTabs, $lng, $ilHelp;
81 
82  $ilTabs->clearTargets();
83  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
84  $ilHelp->setScreenIdComponent("book");
85  $ilHelp->setScreenId("schedules");
86  $ilHelp->setSubScreenId("create");
87 
88  $form = $this->initForm();
89  $tpl->setContent($form->getHTML());
90  }
91 
95  function edit()
96  {
97  global $tpl, $ilCtrl, $ilTabs, $lng, $ilHelp;
98 
99  $ilTabs->clearTargets();
100  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
101  $ilHelp->setScreenIdComponent("book");
102  $ilHelp->setScreenId("schedules");
103  $ilHelp->setSubScreenId("edit");
104 
105  $form = $this->initForm('edit', (int)$_GET['schedule_id']);
106  $tpl->setContent($form->getHTML());
107  }
108 
115  function initForm($a_mode = "create", $id = NULL)
116  {
117  global $lng, $ilCtrl;
118 
119  $lng->loadLanguageModule("dateplaner");
120 
121  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
122 
123  $form_gui = new ilPropertyFormGUI();
124 
125  $title = new ilTextInputGUI($lng->txt("title"), "title");
126  $title->setRequired(true);
127  $title->setSize(40);
128  $title->setMaxLength(120);
129  $form_gui->addItem($title);
130 
131  /*
132  $type = new ilRadioGroupInputGUI($lng->txt("book_schedule_type"), "type");
133  $type->setRequired(true);
134  $form_gui->addItem($type);
135  $fix = new ilRadioOption($lng->txt("book_schedule_type_fix"), "fix");
136  $fix->setInfo($lng->txt("book_schedule_type_fix_info"));
137  $type->addOption($fix);
138  $flex = new ilRadioOption($lng->txt("book_schedule_type_flexible"), "flexible");
139  $flex->setInfo($lng->txt("book_schedule_type_flexible_info"));
140  $type->addOption($flex);
141 
142  $raster = new ilNumberInputGUI($lng->txt("book_schedule_raster"), "raster");
143  $raster->setRequired(true);
144  $raster->setInfo($lng->txt("book_schedule_raster_info"));
145  $raster->setMinValue(1);
146  $raster->setSize(3);
147  $raster->setMaxLength(3);
148  $raster->setSuffix($lng->txt("book_minutes"));
149  $flex->addSubItem($raster);
150 
151  $rent_min = new ilNumberInputGUI($lng->txt("book_schedule_rent_min"), "rent_min");
152  $rent_min->setInfo($lng->txt("book_schedule_rent_info"));
153  $rent_min->setMinValue(1);
154  $rent_min->setSize(3);
155  $rent_min->setMaxLength(3);
156  $flex->addSubItem($rent_min);
157 
158  $rent_max = new ilNumberInputGUI($lng->txt("book_schedule_rent_max"), "rent_max");
159  $rent_max->setInfo($lng->txt("book_schedule_rent_info"));
160  $rent_max->setMinValue(1);
161  $rent_max->setSize(3);
162  $rent_max->setMaxLength(3);
163  $flex->addSubItem($rent_max);
164 
165  $break = new ilNumberInputGUI($lng->txt("book_schedule_break"), "break");
166  $break->setInfo($lng->txt("book_schedule_break_info"));
167  $break->setMinValue(1);
168  $break->setSize(3);
169  $break->setMaxLength(3);
170  $flex->addSubItem($break);
171  */
172 
173  include_once "Modules/BookingManager/classes/class.ilScheduleInputGUI.php";
174  $definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
175  $definition->setInfo($lng->txt("book_schedule_days_info"));
176  $definition->setRequired(true);
177  $form_gui->addItem($definition);
178 
179  $deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
180  $deadline->setInfo($lng->txt("book_deadline_info"));
181  $deadline->setSuffix($lng->txt("book_hours"));
182  $deadline->setMinValue(0);
183  $deadline->setSize(3);
184  $deadline->setMaxLength(3);
185  $form_gui->addItem($deadline);
186 
187  if ($a_mode == "edit")
188  {
189  $form_gui->setTitle($lng->txt("book_edit_schedule"));
190 
191  $item = new ilHiddenInputGUI('schedule_id');
192  $item->setValue($id);
193  $form_gui->addItem($item);
194 
195  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
196  $schedule = new ilBookingSchedule($id);
197  $title->setValue($schedule->getTitle());
198  $deadline->setValue($schedule->getDeadline());
199 
200  /*
201  if($schedule->getRaster())
202  {
203  $type->setValue("flexible");
204  $raster->setValue($schedule->getRaster());
205  $rent_min->setValue($schedule->getMinRental());
206  $rent_max->setValue($schedule->getMaxRental());
207  $break->setValue($schedule->getAutoBreak());
208  }
209  else
210  {
211  $type->setValue("fix");
212  }
213  */
214 
215  $definition->setValue($schedule->getDefinitionBySlots());
216 
217  $form_gui->addCommandButton("update", $lng->txt("save"));
218  }
219  else
220  {
221  $form_gui->setTitle($lng->txt("book_add_schedule"));
222  $form_gui->addCommandButton("save", $lng->txt("save"));
223  $form_gui->addCommandButton("render", $lng->txt("cancel"));
224  }
225  $form_gui->setFormAction($ilCtrl->getFormAction($this));
226 
227  return $form_gui;
228  }
229 
233  function save()
234  {
235  global $tpl, $lng;
236 
237  $form = $this->initForm();
238  if($form->checkInput())
239  {
240  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
241  $obj = new ilBookingSchedule;
242  $this->formToObject($form, $obj);
243  $obj->save();
244 
245  ilUtil::sendSuccess($lng->txt("book_schedule_added"));
246  $this->render();
247  }
248  else
249  {
250  $form->setValuesByPost();
251  $this->setDefinitionFromPost($form);
252  $tpl->setContent($form->getHTML());
253  }
254  }
255 
259  function update()
260  {
261  global $tpl, $lng;
262 
263  $form = $this->initForm('edit', (int)$_POST['schedule_id']);
264  if($form->checkInput())
265  {
266  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
267  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
268  $this->formToObject($form, $obj);
269  $obj->update();
270 
271  ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
272  $this->render();
273  }
274  else
275  {
276  $form->setValuesByPost();
277  $this->setDefinitionFromPost($form);
278  $tpl->setContent($form->getHTML());
279  }
280  }
281 
287  protected function setDefinitionFromPost(ilPropertyFormGUI $form)
288  {
289  $days = $form->getInput("days");
290  if($days)
291  {
292  $days_group = $form->getItemByPostVar("days");
293  foreach($days_group->getOptions() as $option)
294  {
295  $days_fields[$option->getValue()] = $option;
296  }
297 
298  foreach($days as $day)
299  {
300  $slot = $form->getInput($day."_slot");
301  $subs = $days_fields[$day]->getSubItems();
302  if($slot[0])
303  {
304  $subs[0]->setValue($slot[0]);
305  }
306  if($slot[1])
307  {
308  $subs[1]->setValue($slot[1]);
309  }
310  }
311  }
312  }
313 
319  protected function formToObject($form, $schedule)
320  {
321  global $ilObjDataCache;
322 
323  $schedule->setTitle($form->getInput("title"));
324  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
325  $schedule->setDeadline($form->getInput("deadline"));
326 
327  /*
328  if($form->getInput("type") == "flexible")
329  {
330  $schedule->setRaster($form->getInput("raster"));
331  $schedule->setMinRental($form->getInput("rent_min"));
332  $schedule->setMaxRental($form->getInput("rent_max"));
333  $schedule->setAutoBreak($form->getInput("break"));
334  }
335  else
336  {
337  $schedule->setRaster(NULL);
338  $schedule->setMinRental(NULL);
339  $schedule->setMaxRental(NULL);
340  $schedule->setAutoBreak(NULL);
341  }
342  */
343 
344  $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
345  }
346 
350  function confirmDelete()
351  {
352  global $ilCtrl, $lng, $tpl, $ilTabs, $ilHelp;
353 
354  $ilHelp->setSubScreenId("delete");
355 
356 
357  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
358  $conf = new ilConfirmationGUI();
359  $conf->setFormAction($ilCtrl->getFormAction($this));
360  $conf->setHeaderText($lng->txt('book_confirm_delete'));
361 
362  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
363  $type = new ilBookingSchedule((int)$_GET['schedule_id']);
364  $conf->addItem('schedule_id', (int)$_GET['schedule_id'], $type->getTitle());
365  $conf->setConfirm($lng->txt('delete'), 'delete');
366  $conf->setCancel($lng->txt('cancel'), 'render');
367 
368  $tpl->setContent($conf->getHTML());
369  }
370 
374  function delete()
375  {
376  global $ilCtrl, $lng;
377 
378  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
379  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
380  $obj->delete();
381 
382  ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
383  $ilCtrl->redirect($this, 'render');
384  }
385 }
386 
387 ?>