ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObject2GUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./classes/class.ilObjectGUI.php");
5 
27 abstract class ilObject2GUI extends ilObjectGUI
28 {
32  function __construct($a_id = 0, $a_call_by_reference = true)
33  {
34  global $objDefinition, $tpl, $ilCtrl, $ilErr, $lng, $ilTabs;
35 
36  $this->type = $this->getType();
37 
38  $this->tabs_gui =& $ilTabs;
39 
40  if (!isset($ilErr))
41  {
42  $ilErr = new ilErrorHandling();
43  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
44  }
45  else
46  {
47  $this->ilErr =& $ilErr;
48  }
49 
50  $this->objDefinition = $objDefinition;
51  $this->tpl = $tpl;
52  $this->html = "";
53  $this->ctrl = $ilCtrl;
54 
55  $params = array("ref_id");
56 
57  if (!$a_call_by_reference)
58  {
59  $params = array("ref_id","obj_id");
60  }
61 
62  $this->ctrl->saveParameter($this, $params);
63 
64  $this->id = $a_id;
65 
66  $this->call_by_reference = $a_call_by_reference;
67  $this->creation_mode = false;
68  $this->ref_id = ($this->call_by_reference) ? $this->id : $_GET["ref_id"];
69  $this->obj_id = ($this->call_by_reference) ? $_GET["obj_id"] : $this->id;
70  $this->lng = $lng;
71 
72  $this->assignObject();
73 
74  // set context
75  if (is_object($this->object))
76  {
77  if ($this->call_by_reference && $this->ref_id = $_GET["ref_id"])
78  {
79  $this->ctrl->setContext($this->object->getId(),
80  $this->object->getType());
81  }
82  }
83  $this->afterConstructor();
84  }
85 
89  protected function afterConstructor()
90  {
91  }
92 
96  function &executeCommand()
97  {
98  global $rbacsystem;
99 
100  $next_class = $this->ctrl->getNextClass($this);
101  $cmd = $this->ctrl->getCmd();
102 
103  switch($next_class)
104  {
105  default:
106  if(!$cmd)
107  {
108  $cmd = "view";
109  }
110  return $this->performCommand($cmd);
111  break;
112  }
113 
114  return true;
115  }
116 
121  {
122 /* switch ($cmd)
123  {
124  case ...:
125  $this->checkPermission();
126  return $this->$cmd();
127  break;
128  }*/
129  }
130 
131 
135  final public function withReferences() { return parent::withReferences(); }
136  final public function setCreationMode($a_mode = true) { return parent::setCreationMode($a_mode); }
137  final public function getCreationMode() { return parent::getCreationMode(); }
138  final protected function assignObject() { return parent::assignObject(); }
139  final protected function prepareOutput() { return parent::prepareOutput(); }
140  final protected function setTitleAndDescription() { return parent::setTitleAndDescription(); }
141  final protected function showUpperIcon() { return parent::showUpperIcon(); }
142 // final private function showMountWebfolderIcon() { return parent::showMountWebfolderIcon(); }
143  final public function getHTML() { return parent::getHTML(); }
144  final protected function setLocator() { return parent::setLocator(); }
145  final protected function omitLocator($a_omit = true) { return parent::omitLocator($a_omit); }
146  final protected function getTargetFrame() { return parent::getTargetFrame(); }
147  final protected function setTargetFrame($a_cmd, $a_target_frame) { return parent::setTargetFrame($a_cmd, $a_target_frame); }
148  final public function isVisible() { return parent::isVisible(); }
149  final protected function getCenterColumnHTML() { return parent::getCenterColumnHTML(); }
150  final protected function getRightColumnHTML() { return parent::getRightColumnHTML(); }
151  final protected function setColumnSettings($column_gui) { return parent::setColumnSettings($column_gui); }
152  final protected function checkPermission($a_perm, $a_cmd = "") { return parent::checkPermission($a_perm, $a_cmd); }
153 
154  // -> ilContainerGUI
155  final protected function showPossibleSubObjects() { return parent::showPossibleSubObjects(); }
156  // -> ilRepUtilGUI
157  final public function deleteObject() { return parent::deleteObject(); } // done
158  final public function trashObject() { return parent::trashObject(); } // done
159  // -> ilRepUtil
160  final public function undeleteObject() { return parent::undeleteObject(); } // done
161  final public function confirmedDeleteObject() { return parent::confirmedDeleteObject(); } // done
162  final public function cancelDeleteObject() { return parent::cancelDeleteObject(); } // ok
163  final public function removeFromSystemObject() { return parent::removeFromSystemObject(); } // done
164  final protected function redirectToRefId() { return parent::redirectToRefId(); } // ok
165 
166  // -> stefan
167  final protected function fillCloneTemplate($a_tpl_varname,$a_type) { return parent::fillCloneTemplate($a_tpl_varname,$a_type); }
168  final protected function fillCloneSearchTemplate($a_tpl_varname,$a_type) { return parent::fillCloneSearchTemplate($a_tpl_varname,$a_type); }
169  final protected function searchCloneSourceObject() { return parent::searchCloneSourceObject(); }
170  final public function cloneAllObject() { return parent::cloneAllObject(); }
171  final protected function buildCloneSelect($existing_objs) { return parent::buildCloneSelect($existing_objs); }
172 
173  // -> ilAdministration
174  final private function displayList() { return parent::displayList(); }
175  final public function viewObject() { return parent::viewObject(); }
176 // final private function setAdminTabs() { return parent::setAdminTabs(); }
177  final public function getAdminTabs($a) { return parent::getAdminTabs($a); }
178  final protected function addAdminLocatorItems() { return parent::addAdminLocatorItems(); }
179 
183 // final private function setSubObjects() { die("ilObject2GUI::setSubObjects() is deprecated."); }
184 // final public function getFormAction() { die("ilObject2GUI::getFormAction() is deprecated."); }
185 // final protected function setFormAction() { die("ilObject2GUI::setFormAction() is deprecated."); }
186  final protected function getReturnLocation() { die("ilObject2GUI::getReturnLocation() is deprecated."); }
187  final protected function setReturnLocation() { die("ilObject2GUI::setReturnLocation() is deprecated."); }
188  final protected function showActions() { die("ilObject2GUI::showActions() is deprecated."); }
189  final public function getTemplateFile() {mk(); die("ilObject2GUI::getTemplateFile() is deprecated."); }
190  final protected function getTitlesByRefId() { die("ilObject2GUI::getTitlesByRefId() is deprecated."); }
191  final protected function getTabs() {nj(); die("ilObject2GUI::getTabs() is deprecated."); }
192  final protected function __showButton() { die("ilObject2GUI::__showButton() is deprecated."); }
193  final protected function hitsperpageObject() { die("ilObject2GUI::hitsperpageObject() is deprecated."); }
194  final protected function __initTableGUI() { die("ilObject2GUI::__initTableGUI() is deprecated."); }
195  final protected function __setTableGUIBasicData() { die("ilObject2GUI::__setTableGUIBasicData() is deprecated."); }
196  final protected function __showClipboardTable() { die("ilObject2GUI::__showClipboardTable() is deprecated."); }
197 
201  protected function addLocatorItems() {}
202  public function copyWizardHasOptions($a_mode) { return false; }
203  protected function setTabs() { }
204 
208  abstract function getType();
209 
213 // final private function permObject() { parent::permObject(); }
214 // final private function permSaveObject() { parent::permSaveObject(); }
215 // final private function infoObject() { parent::infoObject(); }
216 // final private function __buildRoleFilterSelect() { parent::__buildRoleFilterSelect(); }
217 // final private function __filterRoles() { parent::__filterRoles(); }
218 // final private function ownerObject() { parent::ownerObject(); }
219 // final private function changeOwnerObject() { parent::changeOwnerObject(); }
220 // final private function addRoleObject() { parent::addRoleObject(); }
221 // final private function setActions() { die("ilObject2GUI::setActions() is deprecated."); }
222 // final protected function getActions() { die("ilObject2GUI::getActions() is deprecated."); }
223 
229  function create()
230  {
231  global $rbacsystem, $tpl;
232 
233  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
234 
235  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
236  {
237  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
238  }
239  else
240  {
241  $this->ctrl->setParameter($this, "new_type", $new_type);
242  $this->initEditForm("create", $new_type);
243  $tpl->setContent($this->form->getHTML());
244 
245  if ($new_type != "mep") // bad hack, should be removed (implemented!)
246  {
247  $clone_html = $this->fillCloneTemplate('', $new_type);
248  }
249 
250  $tpl->setContent($this->form->getHTML().$clone_html);
251  }
252  }
253 
254 
260  function save()
261  {
262  global $rbacsystem, $objDefinition, $tpl, $lng;
263 
264  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
265 
266  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
267  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
268  {
269  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
270  }
271  $this->ctrl->setParameter($this, "new_type", $new_type);
272  $this->initEditForm("create", $new_type);
273  if ($this->form->checkInput())
274  {
275 
276  $location = $objDefinition->getLocation($new_type);
277 
278  // create and insert object in objecttree
279  $class_name = "ilObj".$objDefinition->getClassName($new_type);
280  include_once($location."/class.".$class_name.".php");
281  $newObj = new $class_name();
282  $newObj->setType($new_type);
283  $newObj->setTitle(ilUtil::stripSlashes($_POST["title"]));
284  $newObj->setDescription(ilUtil::stripSlashes($_POST["desc"]));
285  $newObj->create();
286  $newObj->createReference();
287  $newObj->putInTree($_GET["ref_id"]);
288  $newObj->setPermissions($_GET["ref_id"]);
289  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
290  $this->afterSave($newObj);
291  return;
292  }
293 
294  $this->form->setValuesByPost();
295  $tpl->setContent($this->form->getHtml());
296  }
297 
303  public function initEditForm($a_mode = "edit", $a_new_type = "")
304  {
305  global $lng, $ilCtrl;
306 
307  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
308  $this->form = new ilPropertyFormGUI();
309  $this->form->setTarget("_top");
310 
311  // title
312  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
313  $ti->setMaxLength(128);
314  $ti->setSize(40);
315  $ti->setRequired(true);
316  $this->form->addItem($ti);
317 
318  // description
319  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
320  $ta->setCols(40);
321  $ta->setRows(2);
322  $this->form->addItem($ta);
323 
324  // save and cancel commands
325  if ($a_mode == "create")
326  {
327  $this->form->addCommandButton("save", $lng->txt($a_new_type."_add"));
328  $this->form->addCommandButton("cancelCreation", $lng->txt("cancel"));
329  $this->form->setTitle($lng->txt($a_new_type."_new"));
330  }
331  else
332  {
333  $this->form->addCommandButton("update", $lng->txt("save"));
334  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
335  $this->form->setTitle($lng->txt("edit"));
336  }
337 
338  $this->form->setFormAction($ilCtrl->getFormAction($this));
339 
340  }
341 
345  function getEditFormValues()
346  {
347  $values["title"] = $this->object->getTitle();
348  $values["desc"] = $this->object->getDescription();
349  $this->form->setValuesByArray($values);
350  }
351 
357  protected function cancel()
358  {
359  $this->ctrl->returnToParent($this);
360  }
361 
367  final function cancelCreation($in_rep = false)
368  {
369  ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
370  }
371 
377  function editObject()
378  {
379  global $tpl;
380 
381  $this->initEditForm("edit");
382  $this->getEditFormValues();
383  $tpl->setContent($this->form->getHTML());
384  }
385 
391  final function cancelUpdate()
392  {
393  $this->ctrl->redirect($this);
394  }
395 
401  function updateObject()
402  {
403  global $lng, $tpl;
404 
405  $this->initEditForm("edit");
406  if ($this->form->checkInput())
407  {
408  $this->object->setTitle($_POST["title"]);
409  $this->object->setDescription($_POST["desc"]);
410  $this->update = $this->object->update();
411  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
412  $this->afterUpdate();
413  return;
414  }
415  $this->form->setValuesByPost();
416  $tpl->setContent($this->form->getHtml());
417  }
418 
419  function afterUpdate()
420  {
421  $this->ctrl->redirect($this);
422  }
423 
424 }