ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseItemAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
37 {
38  var $container_obj;
39  var $tpl;
40  var $ctrl;
41  var $lng;
42 
48  {
49  global $tpl,$ilCtrl,$lng,$ilObjDataCache,$ilErr,$ilTabs;
50 
51  $this->tpl =& $tpl;
52  $this->ctrl =& $ilCtrl;
53  $this->lng =& $lng;
54  $this->lng->loadLanguageModule('crs');
55  $this->err =& $ilErr;
56  $this->tabs_gui =& $ilTabs;
57 
58  $this->container_obj =& $container_obj;
59 
60  $this->item_id = $a_item_id;
61  $this->ctrl->saveParameter($this,'item_id');
62 
63  $this->__initItem();
64  }
65 
66  function &executeCommand()
67  {
68  global $ilTabs;
69 
70  $this->__setTabs();
71 
72  $cmd = $this->ctrl->getCmd();
73 
74  // Check if item id is given and valid
75  if(!$this->__checkItemId())
76  {
77  ilUtil::sendFailure($this->lng->txt("crs_no_item_id_given"),true);
78  $this->ctrl->returnToParent($this);
79  }
80 
81  switch($this->ctrl->getNextClass($this))
82  {
83 
84  case 'ilconditionhandlerinterface':
85 
86  // preconditions for single course items
87  include_once './classes/class.ilConditionHandlerInterface.php';
88  $this->ctrl->saveParameter($this,'item_id',$_GET['item_id']);
89  $new_gui =& new ilConditionHandlerInterface($this,(int) $_GET['item_id']);
90  $this->ctrl->forwardCommand($new_gui);
91  $this->tabs_gui->setTabActive('preconditions');
92  break;
93 
94  default:
95  $this->tabs_gui->setTabActive('timings');
96  if(!$cmd)
97  {
98  $cmd = 'edit';
99  }
100  $this->$cmd();
101  $this->tabs_gui->setTabActive('timings');
102  break;
103  }
104  }
105 
106  function getItemId()
107  {
108  return $this->item_id;
109  }
110 
111  function cancel()
112  {
113  $this->ctrl->returnToParent($this);
114  }
115 
122  public function edit()
123  {
124  global $ilErr,$ilAccess,$ilObjDataCache,$tpl;
125 
126  if(!$ilAccess->checkAccess('write','',$this->container_obj->getRefId()))
127  {
128  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
129  }
130 
131  $this->initFormEdit();
132  $this->getValues();
133 
134  $tpl->setContent($this->form->getHTML());
135  }
136 
143  protected function initFormEdit()
144  {
145  $item_data = $this->items_obj->getItem($this->getItemId());
146 
147  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
148  $this->form = new ilPropertyFormGUI();
149  $this->form->setFormAction($this->ctrl->getFormAction($this));
150 
151  $title = ilObject::_lookupTitle($item_data['obj_id']);
152  $this->form->setTitle($title.': '.$this->lng->txt('crs_edit_timings'));
153  $this->form->setTitleIcon(ilUtil::getImagePath("icon_".$item_data['type']."_s.gif"));
154 
155  $timings = new ilRadioGroupInputGUI($this->lng->txt('timings'),'timing_type');
156 
157  // opt deactivated
158  $dea = new ilRadioOption($this->lng->txt('crs_timings_disabled'),IL_CRS_TIMINGS_DEACTIVATED);
159  $dea->setInfo($this->lng->txt('crs_timings_disabled_info'));
160  $timings->addOption($dea);
161 
162  // Visiblity
163  $vis = new ilRadioOption($this->lng->txt('crs_timings_availability_enabled'),IL_CRS_TIMINGS_ACTIVATION);
164  #$vis->setInfo($this->lng->txt('crs_timings_visibility'));
165 
166  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_start'),'timing_start');
167  $start->setShowTime(true);
168  #$start->setMinuteStepSize(5);
169  $vis->addSubItem($start);
170 
171  $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_end'),'timing_end');
172  $end->setShowTime(true);
173  #$end->setMinuteStepSize(5);
174  $vis->addSubItem($end);
175 
176  $isv = new ilCheckboxInputGUI($this->lng->txt('crs_timings_visibility_short'),'visible');
177  $isv->setInfo($this->lng->txt('crs_timings_visibility'));
178  $isv->setValue(1);
179  $vis->addSubItem($isv);
180 
181  $timings->addOption($vis);
182 
183  // Timings
184  $tim = new ilRadioOption($this->lng->txt('crs_timings_presetting'),IL_CRS_TIMINGS_PRESETTING);
185  $tim->setInfo($this->lng->txt('crs_item_presetting_info'));
186 
187  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_sug_begin'),'sug_start');
188  $tim->addSubItem($start);
189 
190  $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_sug_end'),'sug_end');
191  $tim->addSubItem($end);
192 
193  $cha = new ilCheckboxInputGUI($this->lng->txt('crs_timings_changeable'),'changeable');
194  $tim->addSubItem($cha);
195 
196  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_early_begin'),'early_start');
197  $cha->addSubItem($start);
198 
199  $late = new ilDateTimeInputGUI($this->lng->txt('crs_timings_short_limit_start_end'),'late_end');
200  $cha->addSubItem($late);
201 
202 
203  $timings->addOption($tim);
204 
205  $this->form->addItem($timings);
206 
207  $this->form->addCommandButton('update',$this->lng->txt('save'));
208  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
209  }
210 
217  protected function getValues()
218  {
219  global $ilUser;
220 
221  $item_data = $this->items_obj->getItem($this->getItemId());
222 
223  $data['timing_type'] = $item_data['timing_type'];
224  $data['visible'] = $item_data['visible'];
225  $data['changeable'] = $item_data['changeable'];
226 
227  $start = new ilDateTime($item_data['timing_start'],IL_CAL_UNIX);
228  $data['timing_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
229  $data['timing_start']['time'] = $start->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
230 
231  $end = new ilDateTime($item_data['timing_end'],IL_CAL_UNIX);
232  $data['timing_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
233  $data['timing_end']['time'] = $end->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
234 
235  $start = new ilDate(date('Y-m-d',$item_data['suggestion_start']),IL_CAL_DATE);
236  $data['sug_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
237 
238  $end = new ilDate(date('Y-m-d',$item_data['suggestion_end']),IL_CAL_DATE);
239  $data['sug_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
240 
241  $start = new ilDate(date('Y-m-d',$item_data['earliest_start']),IL_CAL_DATE);
242  $data['early_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
243 
244  $end = new ilDate(date('Y-m-d',$item_data['latest_end']),IL_CAL_DATE);
245  $data['late_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
246 
247  $this->form->setValuesByArray($data);
248  }
249 
256  public function update()
257  {
258  global $ilErr,$ilAccess,$ilObjDataCache,$tpl,$ilUser;
259 
260  if(!$ilAccess->checkAccess('write','',$this->container_obj->getRefId()))
261  {
262  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
263  }
264  $this->initFormEdit();
265  if($this->form->checkInput())
266  {
267  $this->items_obj->setTimingType($this->form->getInput('timing_type'));
268 
269  $date = $this->form->getInput('timing_start');
270  $date = new ilDateTime($date['date'].' '.$date['time'],IL_CAL_DATETIME,$ilUser->getTimeZone());
271  $this->items_obj->setTimingStart($date->get(IL_CAL_UNIX));
272 
273  $date = $this->form->getInput('timing_end');
274  $date = new ilDateTime($date['date'].' '.$date['time'],IL_CAL_DATETIME,$ilUser->getTimeZone());
275  $this->items_obj->setTimingEnd($date->get(IL_CAL_UNIX));
276 
277  $date = $this->form->getInput('sug_start');
278  $date = new ilDate($date['date'],IL_CAL_DATE);
279  $this->items_obj->setSuggestionStart($date->get(IL_CAL_UNIX));
280 
281  $date = $this->form->getInput('sug_end');
282  $date = new ilDate($date['date'],IL_CAL_DATE);
283  $this->items_obj->setSuggestionEnd($date->get(IL_CAL_UNIX));
284 
285  $date = $this->form->getInput('early_start');
286  $date = new ilDate($date['date'],IL_CAL_DATE);
287  $this->items_obj->setEarliestStart($date->get(IL_CAL_UNIX));
288 
289  $date = $this->form->getInput('late_end');
290  $date = new ilDate($date['date'],IL_CAL_DATE);
291  $this->items_obj->setLatestEnd($date->get(IL_CAL_UNIX));
292 
293  $this->items_obj->toggleVisible((bool) $this->form->getInput('visible'));
294  $this->items_obj->toggleChangeable((bool) $this->form->getInput('changeable'));
295 
296  if(!$this->items_obj->validateActivation())
297  {
298  ilUtil::sendFailure($ilErr->getMessage());
299  $this->form->setValuesByPost();
300  $tpl->setContent($this->form->getHTML());
301  return false;
302  }
303  else
304  {
305  $this->items_obj->update($this->getItemId());
306  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
307  $this->edit();
308  }
309  }
310  else
311  {
312  $this->form->setValuesByPost();
313  $tpl->setContent($this->form->getHTML());
314  }
315 
316  }
317 
318 
319 
320  function moveUp()
321  {
322  global $ilErr,$ilAccess,$ilObjDataCache;
323 
324  if(!$ilAccess->checkAccess('write','',$this->container_obj->getRefId()))
325  {
326  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
327  }
328 
329  $this->items_obj->moveUp((int) $this->getItemId());
330  ilUtil::sendSuccess($this->lng->txt("crs_moved_item"),true);
331 
332  $this->ctrl->returnToParent($this);
333  return true;
334  }
335 
336  function moveDown()
337  {
338  global $ilErr,$ilAccess,$ilObjDataCache;
339 
340  if(!$ilAccess->checkAccess('write','',$this->container_obj->getRefId()))
341  {
342  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
343  }
344 
345  $this->items_obj->moveDown((int) $this->getItemId());
346  ilUtil::sendSuccess($this->lng->txt("crs_moved_item"),true);
347 
348  $this->ctrl->returnToParent($this);
349  return true;
350  }
351 
352 
353  function __checkItemId()
354  {
355  global $tree;
356 
357  if(!$this->getItemId())
358  {
359  return false;
360  }
361  // Item has to be within course
362  if(!$tree->checkForParentType($this->getItemId(),'crs'))
363  {
364  return false;
365  }
366  return true;
367  }
368 
369  function __initItem()
370  {
371  global $ilObjDataCache,$tree;
372 
373  include_once "./Modules/Course/classes/class.ilCourseItems.php";
374 
375  if(!is_object($this->items_obj))
376  {
377  $parent_ref = $tree->getParentId($this->item_id);
378  $cont_obj = ilObjectFactory::getInstanceByRefId($parent_ref,false);
379 
380  if($cont_obj->getType() == 'crs')
381  {
382  $this->items_obj =& new ilCourseItems($cont_obj,$cont_obj->getRefId());
383  }
384  else
385  {
386  // lookup crs_obj
387  $crs_ref_id = $tree->checkForParentType($cont_obj->getRefId(),'crs');
388  $crs_obj = ilObjectFactory::getInstanceByRefId($crs_ref_id);
389 
390  $this->items_obj =& new ilCourseItems($crs_obj,$cont_obj->getRefId());
391  }
392  /*
393  if($ilObjDataCache->lookupType($this->container_obj->getId()) == 'crs')
394  {
395  $this->items_obj =& new ilCourseItems($this->container_obj,$this->container_obj->getRefId());
396  }
397  else
398  {
399  // lookup crs_obj
400  $crs_ref_id = $tree->checkForParentType($this->container_obj->getRefId(),'crs');
401  $crs_obj = ilObjectFactory::getInstanceByRefId($crs_ref_id);
402 
403  $this->items_obj =& new ilCourseItems($crs_obj,$this->container_obj->getRefId());
404  }
405  */
406  }
407  return true;
408  }
409 
410  function __setTabs()
411  {
412  global $rbacsystem,$ilUser;
413 
414  $this->tabs_gui->clearTargets();
415 
416  $this->tabs_gui->setBackTarget($this->lng->txt('back_to_'.$this->container_obj->getType().'_content'),
417  'repository.php?ref_id='.$this->container_obj->getRefId());
418  $this->tabs_gui->addTarget("timings",
419  $this->ctrl->getLinkTarget($this,'edit'),
420  "edit", get_class($this));
421  $this->ctrl->setParameterByClass('ilconditionhandlerinterface','item_id',(int) $_GET['item_id']);
422  $this->tabs_gui->addTarget("preconditions",
423  $this->ctrl->getLinkTargetByClass('ilConditionHandlerInterface','listConditions'),
424  "", "ilConditionHandlerInterface");
425  return true;
426  }
427 
428 } // END class.ilCourseItemAdminsitration
429 ?>