ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
190  $schedule = new ilBookingSchedule($id);
191  }
192 
193  $av = new ilFormSectionHeaderGUI();
194  $av->setTitle($lng->txt("obj_activation_list_gui"));
195  $form_gui->addItem($av);
196 
197  // #18221
198  $lng->loadLanguageModule('rep');
199 
200  $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
201  $from->enableDateActivation("", "from_tgl", $schedule ? is_object($schedule->getAvailabilityFrom()) : false);
202  $from->setShowTime(true);
203  $form_gui->addItem($from);
204 
205  $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
206  $to->enableDateActivation("", "to_tgl", $schedule ? is_object($schedule->getAvailabilityTo()) : false);
207  $to->setShowTime(true);
208  $form_gui->addItem($to);
209 
210  if ($a_mode == "edit")
211  {
212  $form_gui->setTitle($lng->txt("book_edit_schedule"));
213 
214  $item = new ilHiddenInputGUI('schedule_id');
215  $item->setValue($id);
216  $form_gui->addItem($item);
217 
218  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
219  $schedule = new ilBookingSchedule($id);
220  $title->setValue($schedule->getTitle());
221  $deadline->setValue($schedule->getDeadline());
222  $from->setDate($schedule->getAvailabilityFrom());
223  $to->setDate($schedule->getAvailabilityTo());
224 
225  /*
226  if($schedule->getRaster())
227  {
228  $type->setValue("flexible");
229  $raster->setValue($schedule->getRaster());
230  $rent_min->setValue($schedule->getMinRental());
231  $rent_max->setValue($schedule->getMaxRental());
232  $break->setValue($schedule->getAutoBreak());
233  }
234  else
235  {
236  $type->setValue("fix");
237  }
238  */
239 
240  $definition->setValue($schedule->getDefinitionBySlots());
241 
242  $form_gui->addCommandButton("update", $lng->txt("save"));
243  }
244  else
245  {
246  $form_gui->setTitle($lng->txt("book_add_schedule"));
247  $form_gui->addCommandButton("save", $lng->txt("save"));
248  $form_gui->addCommandButton("render", $lng->txt("cancel"));
249  }
250  $form_gui->setFormAction($ilCtrl->getFormAction($this));
251 
252  return $form_gui;
253  }
254 
258  function save()
259  {
260  global $tpl, $lng;
261 
262  $form = $this->initForm();
263  if($form->checkInput())
264  {
265  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
266  $obj = new ilBookingSchedule;
267  $this->formToObject($form, $obj);
268  $obj->save();
269 
270  ilUtil::sendSuccess($lng->txt("book_schedule_added"));
271  $this->render();
272  }
273  else
274  {
275  $form->setValuesByPost();
276  $this->setDefinitionFromPost($form);
277  $tpl->setContent($form->getHTML());
278  }
279  }
280 
284  function update()
285  {
286  global $tpl, $lng;
287 
288  $form = $this->initForm('edit', (int)$_POST['schedule_id']);
289  if($form->checkInput())
290  {
291  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
292  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
293  $this->formToObject($form, $obj);
294  $obj->update();
295 
296  ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
297  $this->render();
298  }
299  else
300  {
301  $form->setValuesByPost();
302  $this->setDefinitionFromPost($form);
303  $tpl->setContent($form->getHTML());
304  }
305  }
306 
312  protected function setDefinitionFromPost(ilPropertyFormGUI $form)
313  {
314  $days = $form->getInput("days");
315  if($days)
316  {
317  $days_group = $form->getItemByPostVar("days");
318  foreach($days_group->getOptions() as $option)
319  {
320  $days_fields[$option->getValue()] = $option;
321  }
322 
323  foreach($days as $day)
324  {
325  $slot = $form->getInput($day."_slot");
326  $subs = $days_fields[$day]->getSubItems();
327  if($slot[0])
328  {
329  $subs[0]->setValue($slot[0]);
330  }
331  if($slot[1])
332  {
333  $subs[1]->setValue($slot[1]);
334  }
335  }
336  }
337  }
338 
344  protected function formToObject($form, $schedule)
345  {
346  global $ilObjDataCache;
347 
348  $schedule->setTitle($form->getInput("title"));
349  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
350  $schedule->setDeadline($form->getInput("deadline"));
351 
352  $from = $form->getItemByPostVar("from");
353  $from_tgl = $from->getActivationPostVar();
354  $schedule->setAvailabilityFrom($_POST[$from_tgl] ? $from->getDate(): null);
355 
356  $to = $form->getItemByPostVar("to");
357  $to_tgl = $to->getActivationPostVar();
358  $schedule->setAvailabilityTo($_POST[$to_tgl] ? $to->getDate(): null);
359 
360  /*
361  if($form->getInput("type") == "flexible")
362  {
363  $schedule->setRaster($form->getInput("raster"));
364  $schedule->setMinRental($form->getInput("rent_min"));
365  $schedule->setMaxRental($form->getInput("rent_max"));
366  $schedule->setAutoBreak($form->getInput("break"));
367  }
368  else
369  {
370  $schedule->setRaster(NULL);
371  $schedule->setMinRental(NULL);
372  $schedule->setMaxRental(NULL);
373  $schedule->setAutoBreak(NULL);
374  }
375  */
376 
377  $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
378  }
379 
383  function confirmDelete()
384  {
385  global $ilCtrl, $lng, $tpl, $ilTabs, $ilHelp;
386 
387  $ilHelp->setSubScreenId("delete");
388 
389 
390  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
391  $conf = new ilConfirmationGUI();
392  $conf->setFormAction($ilCtrl->getFormAction($this));
393  $conf->setHeaderText($lng->txt('book_confirm_delete'));
394 
395  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
396  $type = new ilBookingSchedule((int)$_GET['schedule_id']);
397  $conf->addItem('schedule_id', (int)$_GET['schedule_id'], $type->getTitle());
398  $conf->setConfirm($lng->txt('delete'), 'delete');
399  $conf->setCancel($lng->txt('cancel'), 'render');
400 
401  $tpl->setContent($conf->getHTML());
402  }
403 
407  function delete()
408  {
409  global $ilCtrl, $lng;
410 
411  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
412  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
413  $obj->delete();
414 
415  ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
416  $ilCtrl->redirect($this, 'render');
417  }
418 }
419 
420 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$_POST['username']
Definition: cron.php:12
getItemByPostVar($a_post_var)
Get Item by POST variable.
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
This class represents a property form user interface.
__construct($a_parent_obj)
Constructor.
$_GET["client_id"]
This class represents a section header 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.
schedule for booking ressource
$cmd
Definition: sahs_server.php:35
This class represents a text property in a property form.
List booking schedules (for booking pool)
This class represents a date/time property in a property form.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
static _lookupObjId($a_id)
This class represents a text property in a property form.
initForm($a_mode="create", $id=NULL)
Build property form.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static getPostData($a_post_var, $a_remove_invalid=true)
create()
Render creation form.
enableDateActivation($a_title, $a_postvar, $a_checked=true)
Enable date activation.
formToObject($form, $schedule)
Convert incoming form data to schedule object.
Class ilBookingScheduleGUI.
global $lng
Definition: privfeed.php:40
render()
Render list of booking schedules.
setDefinitionFromPost(ilPropertyFormGUI $form)
Reload definition values from post data.
setRequired($a_required)
Set Required.
Confirmation screen class.