ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilContainerReferenceGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 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
24include_once('./Services/Object/classes/class.ilObjectGUI.php');
25
36{
38
39 const MODE_CREATE = 1;
40 const MODE_EDIT = 2;
41
42 protected $existing_objects = array();
43
49 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
50 {
51 global $lng;
52 parent::__construct($a_data, $a_id,$a_call_by_reference,$a_prepare_output);
53
54 $lng->loadLanguageModule('objref');
55 }
56
61 protected function addLocatorItems()
62 {
63 global $ilLocator;
64
65 if($this->object instanceof ilObject)
66 {
67 $ilLocator->addItem($this->object->getPresentationTitle(),$this->ctrl->getLinkTarget($this));
68 }
69 }
70
76 public function redirectObject()
77 {
78 global $ilCtrl;
79
80 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->object->getTargetRefId());
81 $ilCtrl->redirectByClass("ilrepositorygui", "");
82 }
83
89 public function createObject()
90 {
91 global $ilUser,$ilAccess,$ilErr,$ilSetting;
92
93 $new_type = $_REQUEST["new_type"];
94 if(!$ilAccess->checkAccess("create_".$this->getReferenceType(),'',$_GET["ref_id"], $new_type))
95 {
96 $ilErr->raiseError($this->lng->txt("permission_denied"),$ilErr->MESSAGE);
97 }
98
99 $this->initTargetSelection(self::MODE_CREATE);
100 ilUtil::sendInfo($this->lng->txt($this->getReferenceType().'_edit_info'));
101 }
102
103
111 public function saveObject()
112 {
113 global $ilAccess;
114
115 if(!(int) $_REQUEST['target_id'])
116 {
117 ilUtil::sendFailure($this->lng->txt('select_one'));
118 $this->createObject();
119 return false;
120 }
121 if(!$ilAccess->checkAccess('visible','',(int) $_REQUEST['target_id']))
122 {
123 ilUtil::sendFailure($this->lng->txt('permission_denied'));
124 $this->createObject();
125 return false;
126 }
127
128 parent::saveObject();
129 }
130
131 protected function initCreateForm($a_new_type)
132 {
133 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
134 $form = new ilPropertyFormGUI();
135 return $form;
136 }
137
138 protected function afterSave(ilObject $a_new_object)
139 {
140 $target_obj_id = ilObject::_lookupObjId((int) $_REQUEST['target_id']);
141 $a_new_object->setTargetId($target_obj_id);
142 $a_new_object->update();
143
144 ilUtil::sendSuccess($this->lng->txt("object_added"), true);
145 $this->ctrl->setParameter($this,'ref_id',$a_new_object->getRefId());
146 $this->ctrl->redirect($this,'firstEdit');
147 }
148
152 protected function firstEditObject()
153 {
154 $this->editObject(false);
155 }
156
157
165 public function editObject($a_show_info_message = true)
166 {
167 global $ilUser,$ilSetting,$ilTabs;
168
169 $ilTabs->setTabActive('edit');
170 $ilTabs->addSubTab('edit',$this->lng->txt('objref_edit_ref'),$this->ctrl->getLinkTarget($this,'edit'));
171 $ilTabs->addSubTab('editTitle',$this->lng->txt('objref_edit_title'),$this->ctrl->getLinkTarget($this,'editTitle'));
172 $ilTabs->setTabActive('edit');
173 $ilTabs->activateSubTab('edit');
174 $this->initTargetSelection(self::MODE_EDIT);
175
176 if($a_show_info_message)
177 {
178 ilUtil::sendInfo($this->lng->txt($this->getReferenceType().'_edit_info'));
179 }
180 }
181
182 public function editReferenceObject()
183 {
184 $this->editObject();
185 }
186
190 protected function editTitleObject(ilPropertyFormGUI $form = null)
191 {
192 global $ilTabs;
193
194 $ilTabs->addSubTab('edit',$this->lng->txt('objref_edit_ref'),$this->ctrl->getLinkTarget($this,'edit'));
195 $ilTabs->addSubTab('editTitle',$this->lng->txt('objref_edit_title'),$this->ctrl->getLinkTarget($this,'editTitle'));
196 $ilTabs->setTabActive('edit');
197 $ilTabs->activateSubTab('editTitle');
198
199 if(!$form instanceof ilPropertyFormGUI)
200 {
201 $form = $this->initFormTitle();
202 }
203 $GLOBALS['tpl']->setContent($form->getHTML());
204 }
205
210 protected function initFormTitle()
211 {
212 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
213 $form = new ilPropertyFormGUI();
214 $form->setTitle($this->lng->txt('objref_title_settings'));
215 $form->setFormAction($this->ctrl->getFormAction($this));
216 $form->addCommandButton('updateTitle', $this->lng->txt('save'));
217
218 // title type
219 $ttype = new ilRadioGroupInputGUI($this->lng->txt('title'), 'title_type');
220 $ttype->setValue($this->object->getTitleType());
221 $reuse = new ilRadioOption($this->lng->txt('objref_reuse_title'));
223 $ttype->addOption($reuse);
224
225 $custom = new ilRadioOption($this->lng->txt('objref_custom_title'));
227
228 // title
229 $title = new ilTextInputGUI($this->lng->txt('title'),'title');
230 $title->setSize(min(40, ilObject::TITLE_LENGTH));
231 $title->setMaxLength(ilObject::TITLE_LENGTH);
232 $title->setRequired(true);
233 $title->setValue($this->object->getTitle());
234 $custom->addSubItem($title);
235
236 $ttype->addOption($custom);
237
238 $form->addItem($ttype);
239
240 return $form;
241 }
242
246 protected function updateTitleObject()
247 {
248 $form = $this->initFormTitle();
249 if($form->checkInput())
250 {
251 $this->object->setTitleType($form->getInput('title_type'));
252 if($form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM)
253 {
254 $this->object->setTitle($form->getInput('title'));
255 }
256 $this->object->update();
257 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
258 $this->ctrl->redirect($this,'editTitle');
259 }
260 $form->setValuesByPost();
261 ilUtil::sendFailure($this->lng->txt('err_check_input'));
262 $this->editTitleObject($form);
263 }
264
272 public function updateObject()
273 {
274 global $ilAccess;
275
276 if(!(int) $_REQUEST['target_id'])
277 {
278 ilUtil::sendFailure($this->lng->txt('select_one'));
279 $this->editObject();
280 return false;
281 }
282 if(!$ilAccess->checkAccess('visible','',(int) $_REQUEST['target_id']))
283 {
284 ilUtil::sendFailure($this->lng->txt('permission_denied'));
285 $this->editObject();
286 return false;
287 }
288 $this->checkPermission('write');
289
290 $target_obj_id = ilObject::_lookupObjId((int) $_REQUEST['target_id']);
291 $this->object->setTargetId($target_obj_id);
292 $this->object->update();
293
294 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
295 $this->ctrl->redirect($this,'edit');
296 }
297
298
305 protected function showSelection()
306 {
307 $this->initFormSelection();
308 $this->tpl->setContent($this->form->getHTML());
309 return true;
310 }
311
318 protected function initFormSelection()
319 {
320 if(is_object($this->form))
321 {
322 return true;
323 }
324 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
325 $this->form = new ilPropertyFormGUI();
326 $this->ctrl->setParameter($this,'new_type',$this->getReferenceType());
327 $this->form->setFormAction($this->ctrl->getFormAction($this));
328 $this->form->setTitle($this->lng->txt($this->getReferenceType().'_new'));
329 $this->form->setTitleIcon(ilUtil::getImagePath('icon_'.$this->getReferenceType().'.svg'));
330
331 // Show selection
332 $select = new ilSelectInputGUI($this->lng->txt('objs_'.$this->getTargetType()),'target_id');
333 $select->setOptions(self::_prepareSelection($this->existing_objects,$this->getTargetType()));
334 $select->setInfo($this->lng->txt($_POST['new_type'].'_edit_info'));
335 $this->form->addItem($select);
336
337 $this->form->addCommandButton('save',$this->lng->txt('save'));
338 $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
339 }
340
347 protected function initFormEditSelection()
348 {
349 if(is_object($this->form))
350 {
351 return true;
352 }
353 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
354 $this->form = new ilPropertyFormGUI();
355 $this->form->setFormAction($this->ctrl->getFormAction($this));
356 $this->form->setTitle($this->lng->txt($this->getReferenceType().'_edit'));
357 $this->form->setTitleIcon(ilUtil::getImagePath('icon_'.$this->getReferenceType().'.svg'));
358
359 // Show selection
360 $select = new ilSelectInputGUI($this->lng->txt('objs_'.$this->getTargetType()),'target_id');
361 $select->setValue($this->object->getTargetRefId());
362 $select->setOptions(self::_prepareSelection($this->existing_objects,$this->getTargetType()));
363 $select->setInfo($this->lng->txt($this->object->getType().'_edit_info'));
364 $this->form->addItem($select);
365
366 $this->form->addCommandButton('update',$this->lng->txt('save'));
367 #$this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
368 }
369
370
378 public function getTargetType()
379 {
380 return $this->target_type;
381 }
382
390 public function getReferenceType()
391 {
392 return $this->reference_type;
393 }
394
403 public static function _prepareSelection($a_ref_ids,$a_target_type)
404 {
405 global $ilDB,$lng;
406
407 $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree ".
408 "JOIN object_reference obj_ref ON child = obj_ref.ref_id ".
409 "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id ".
410 "JOIN object_reference path_ref ON parent = path_ref.ref_id ".
411 "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id ".
412 "WHERE ".$ilDB->in('child',$a_ref_ids,false,'integer').' '.
413 "ORDER BY obj_data.title ";
414 $res = $ilDB->query($query);
415
416 $options[0] = $lng->txt('obj_'.$a_target_type.'_select');
417 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
418 {
419 if(strlen($title = $row->obj_title) > 40)
420 {
421 $title = substr($title,0,40).'...';
422 }
423 if(strlen($path = $row->path_title) > 40)
424 {
425 $path = substr($path,0,40).'...';
426 }
427 $options[$row->child] = ($title.' ('.$lng->txt('path').': '.$path.')');
428 }
429 return $options ? $options : array();
430 }
431
436 protected function initTargetSelection($a_mode = self::MODE_CREATE)
437 {
438 global $ilCtrl, $tree;
439
440 // empty session on init
441 $_SESSION['ref_repexpand'] = array();
442
443 // copy opened nodes from repository explorer
444 $_SESSION['ref_repexpand'] = is_array($_SESSION['repexpand']) ? $_SESSION['repexpand'] : array();
445
446 // open current position
447
448 if($a_mode == self::MODE_CREATE)
449 {
450 $target = (int) $_GET['ref_id'];
451 }
452 else
453 {
454 $target = (int) $this->object->getTargetRefId();
455 }
456
457 $path = $tree->getPathId($target);
458 foreach((array) $path as $node_id)
459 {
460 if(!in_array($node_id, $_SESSION['ref_repexpand']))
461 {
462 $_SESSION['ref_repexpand'][] = $node_id;
463 }
464 }
465
466 $_SESSION['ref_mode'] = $a_mode;
467
469 }
470
476 {
477 global $ilTabs, $ilToolbar, $ilCtrl, $tree, $tpl, $objDefinition;
478
479 include_once './Services/ContainerReference/classes/class.ilContainerSelectionExplorer.php';
480
481 if($_SESSION['ref_mode'] == self::MODE_CREATE)
482 {
483 $ilToolbar->addButton($this->lng->txt('back'), $ilCtrl->getLinkTarget($this,'cancel'));
484 $this->ctrl->setParameter($this,'new_type',$this->getReferenceType());
485 $cmd = 'save';
486 }
487 else
488 {
489 $ilTabs->setTabActive('edit');
490 $cmd = 'update';
491 }
492 $explorer = new ilContainerSelectionExplorer($this->ctrl->getLinkTarget($this,$cmd));
493
494 if(isset($_GET['ref_repexpand']))
495 {
496 $explorer->setExpand((int) $_GET['ref_repexpand']);
497 }
498 else
499 {
500 $explorer->setExpand(ROOT_FOLDER_ID);
501 }
502 $explorer->setFrameTarget('_self');
503 $explorer->setExpandTarget($this->ctrl->getLinkTarget($this,'showTargetSelectionTree'));
504 $explorer->setTargetGet('target_id');
505 $explorer->setTargetType($this->getTargetType());
506 $explorer->setOutput(0);
507 $this->tpl->setContent($explorer->getOutput());
508 }
509}
510?>
$_GET["client_id"]
$_SESSION["AccountId"]
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
initTargetSelection($a_mode=self::MODE_CREATE)
Init copy from repository/search list commands.
firstEditObject()
show edit screen without info message
showTargetSelectionTreeObject()
Show target selection.
editObject($a_show_info_message=true)
edit object
addLocatorItems()
Add locator item @global type $ilLocator.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Constructor.
showSelection()
show selection of containers
editTitleObject(ilPropertyFormGUI $form=null)
edit title
afterSave(ilObject $a_new_object)
Post (successful) object creation hook.
static _prepareSelection($a_ref_ids, $a_target_type)
Prepare selection of target objects.
initCreateForm($a_new_type)
Init object creation form.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
editObject()
edit object
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
const TITLE_LENGTH
max length of object title
update()
update object in db
getRefId()
get reference id @access public
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$_POST['username']
Definition: cron.php:12
$target_type
Definition: goto.php:87
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
$path
Definition: index.php:22
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilDB
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15