ILIAS  Release_4_2_x_branch Revision 61807
 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 "./classes/class.ilObjectGUI.php";
5 
16 {
21  function __construct($a_parent_obj)
22  {
23  $this->ref_id = $a_parent_obj->ref_id;
24  }
25 
29  function executeCommand()
30  {
31  global $tpl, $ilTabs, $ilCtrl;
32 
33  $next_class = $ilCtrl->getNextClass($this);
34 
35  switch($next_class)
36  {
37  default:
38  $cmd = $ilCtrl->getCmd("render");
39  $this->$cmd();
40  break;
41  }
42  return true;
43  }
44 
50  function render()
51  {
52  global $tpl, $ilCtrl, $ilTabs, $lng, $ilAccess;
53 
54  $ilTabs->clearTargets();
55  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTargetByClass('ilBookingTypeGUI', 'render'));
56 
57  $ilCtrl->setParameter($this, 'type_id', (int)$_GET['type_id']);
58 
59  if ($ilAccess->checkAccess('write', '', $this->ref_id))
60  {
61  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
62  $bar = new ilToolbarGUI;
63  $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
64  $bar = $bar->getHTML();
65  }
66 
67  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
68  $table = new ilBookingObjectsTableGUI($this, 'listItems', $this->ref_id, (int)$_GET['type_id']);
69  $tpl->setContent($bar.$table->getHTML());
70  }
71 
75  function create()
76  {
77  global $ilCtrl, $tpl, $lng, $ilTabs;
78 
79  $ilCtrl->setParameter($this, 'type_id', (int)$_REQUEST['type_id']);
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  $ilCtrl->setParameter($this, 'type_id', (int)$_REQUEST['type_id']);
96 
97  $ilTabs->clearTargets();
98  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
99 
100  $form = $this->initForm('edit', (int)$_GET['object_id']);
101  $tpl->setContent($form->getHTML());
102  }
103 
110  function initForm($a_mode = "create", $id = NULL)
111  {
112  global $lng, $ilCtrl, $ilObjDataCache;
113 
114  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
115 
116  $form_gui = new ilPropertyFormGUI();
117 
118  $title = new ilTextInputGUI($lng->txt("title"), "title");
119  $title->setRequired(true);
120  $title->setSize(40);
121  $title->setMaxLength(120);
122  $form_gui->addItem($title);
123 
124  include_once 'Modules/BookingManager/classes/class.ilBookingType.php';
125  $type = new ilBookingType((int)$_REQUEST['type_id']);
126  if(!$type->getScheduleId())
127  {
128  $options = array();
129  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
130  foreach(ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->ref_id)) as $schedule)
131  {
132  $options[$schedule["booking_schedule_id"]] = $schedule["title"];
133  }
134 
135  $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
136  $schedule->setRequired(true);
137  $schedule->setOptions($options);
138  $form_gui->addItem($schedule);
139  }
140 
141  if ($a_mode == "edit")
142  {
143  $form_gui->setTitle($lng->txt("book_edit_object").": ".$type->getTitle());
144 
145  $item = new ilHiddenInputGUI('object_id');
146  $item->setValue($id);
147  $form_gui->addItem($item);
148 
149  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
150  $type = new ilBookingObject($id);
151  $title->setValue($type->getTitle());
152 
153  if(isset($schedule))
154  {
155  $schedule->setValue($type->getScheduleId());
156  }
157 
158  $form_gui->addCommandButton("update", $lng->txt("save"));
159  }
160  else
161  {
162  $form_gui->setTitle($lng->txt("book_add_object").": ".$type->getTitle());
163  $form_gui->addCommandButton("save", $lng->txt("save"));
164  $form_gui->addCommandButton("render", $lng->txt("cancel"));
165  }
166  $form_gui->setFormAction($ilCtrl->getFormAction($this));
167 
168  return $form_gui;
169  }
170 
174  function save()
175  {
176  global $ilCtrl, $tpl, $lng, $ilTabs;
177 
178  $form = $this->initForm();
179  if($form->checkInput())
180  {
181  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
182  $obj = new ilBookingObject;
183  $obj->setTitle($form->getInput("title"));
184  $obj->setTypeId((int)$_REQUEST["type_id"]);
185  $obj->setScheduleId($form->getInput("schedule"));
186  $obj->save();
187 
188  ilUtil::sendSuccess($lng->txt("book_object_added"));
189  $this->render();
190  }
191  else
192  {
193  $ilCtrl->setParameter($this, 'type_id', (int)$_REQUEST['type_id']);
194 
195  $ilTabs->clearTargets();
196  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
197 
198  $form->setValuesByPost();
199  $tpl->setContent($form->getHTML());
200  }
201  }
202 
206  function update()
207  {
208  global $tpl, $ilObjDataCache, $lng;
209 
210  $form = $this->initForm('edit', (int)$_POST['object_id']);
211  if($form->checkInput())
212  {
213  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
214  $obj = new ilBookingObject((int)$_POST['object_id']);
215  $obj->setTitle($form->getInput("title"));
216  $obj->setTypeId((int)$_REQUEST['type_id']);
217  $obj->setScheduleId($form->getInput("schedule"));
218  $obj->update();
219 
220  ilUtil::sendSuccess($lng->txt("book_object_updated"));
221  $this->render();
222  }
223  else
224  {
225  $form->setValuesByPost();
226  $tpl->setContent($form->getHTML());
227  }
228  }
229 
233  function confirmDelete()
234  {
235  global $ilCtrl, $lng, $tpl, $ilTabs;
236 
237  $ilCtrl->setParameter($this, 'type_id', (int)$_REQUEST['type_id']);
238 
239  $ilTabs->clearTargets();
240  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
241 
242  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
243  $conf = new ilConfirmationGUI();
244  $conf->setFormAction($ilCtrl->getFormAction($this));
245  $conf->setHeaderText($lng->txt('book_confirm_delete'));
246 
247  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
248  $type = new ilBookingObject((int)$_GET['object_id']);
249  $conf->addItem('object_id', (int)$_GET['object_id'], $type->getTitle());
250  $conf->setConfirm($lng->txt('delete'), 'delete');
251  $conf->setCancel($lng->txt('cancel'), 'render');
252 
253  $tpl->setContent($conf->getHTML());
254  }
255 
259  function delete()
260  {
261  global $ilCtrl, $lng;
262 
263  $ilCtrl->setParameter($this, 'type_id', (int)$_REQUEST['type_id']);
264 
265  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
266  $obj = new ilBookingObject((int)$_POST['object_id']);
267  $obj->delete();
268 
269  ilUtil::sendSuccess($lng->txt('book_object_deleted'), true);
270  $ilCtrl->redirect($this, 'render');
271  }
272 }
273 
274 ?>