ILIAS  eassessment Revision 61809
 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 {
29  protected $creation_forms = array();
30  const CFORM_NEW = "new";
31  const CFORM_CLONE = "clone";
32  const CFORM_IMPORT = "import";
33 
37  function __construct($a_id = 0, $a_call_by_reference = true)
38  {
39  global $objDefinition, $tpl, $ilCtrl, $ilErr, $lng, $ilTabs;
40 
41  $this->creation_forms = array(
45  );
46 
47  $this->type = $this->getType();
48 
49  $this->tabs_gui =& $ilTabs;
50 
51  if (!isset($ilErr))
52  {
53  $ilErr = new ilErrorHandling();
54  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
55  }
56  else
57  {
58  $this->ilErr =& $ilErr;
59  }
60 
61  $this->objDefinition = $objDefinition;
62  $this->tpl = $tpl;
63  $this->html = "";
64  $this->ctrl = $ilCtrl;
65 
66  $params = array("ref_id");
67 
68  if (!$a_call_by_reference)
69  {
70  $params = array("ref_id","obj_id");
71  }
72 
73  $this->ctrl->saveParameter($this, $params);
74 
75  $this->id = $a_id;
76 
77  $this->call_by_reference = $a_call_by_reference;
78  $this->creation_mode = false;
79  $this->ref_id = ($this->call_by_reference) ? $this->id : $_GET["ref_id"];
80  $this->obj_id = ($this->call_by_reference) ? $_GET["obj_id"] : $this->id;
81  $this->lng = $lng;
82 
83  $this->assignObject();
84 
85  // set context
86  if (is_object($this->object))
87  {
88  if ($this->call_by_reference && $this->ref_id = $_GET["ref_id"])
89  {
90  $this->ctrl->setContext($this->object->getId(),
91  $this->object->getType());
92  }
93  }
94  $this->afterConstructor();
95  }
96 
100  protected function afterConstructor()
101  {
102  }
103 
107  function &executeCommand()
108  {
109  global $rbacsystem;
110 
111  $next_class = $this->ctrl->getNextClass($this);
112  $cmd = $this->ctrl->getCmd();
113 
114  switch($next_class)
115  {
116  default:
117  if(!$cmd)
118  {
119  $cmd = "view";
120  }
121  return $this->performCommand($cmd);
122  break;
123  }
124 
125  return true;
126  }
127 
132  {
133 /* switch ($cmd)
134  {
135  case ...:
136  $this->checkPermission();
137  return $this->$cmd();
138  break;
139  }*/
140  }
141 
142 
146  final public function withReferences() { return parent::withReferences(); }
147  final public function setCreationMode($a_mode = true) { return parent::setCreationMode($a_mode); }
148  final public function getCreationMode() { return parent::getCreationMode(); }
149  final protected function assignObject() { return parent::assignObject(); }
150  final protected function prepareOutput() { return parent::prepareOutput(); }
151  final protected function setTitleAndDescription() { return parent::setTitleAndDescription(); }
152  final protected function showUpperIcon() { return parent::showUpperIcon(); }
153 // final private function showMountWebfolderIcon() { return parent::showMountWebfolderIcon(); }
154  final public function getHTML() { return parent::getHTML(); }
155  final protected function setLocator() { return parent::setLocator(); }
156  final protected function omitLocator($a_omit = true) { return parent::omitLocator($a_omit); }
157  final protected function getTargetFrame() { return parent::getTargetFrame(); }
158  final protected function setTargetFrame($a_cmd, $a_target_frame) { return parent::setTargetFrame($a_cmd, $a_target_frame); }
159  final public function isVisible() { return parent::isVisible(); }
160  final protected function getCenterColumnHTML() { return parent::getCenterColumnHTML(); }
161  final protected function getRightColumnHTML() { return parent::getRightColumnHTML(); }
162  final protected function setColumnSettings($column_gui) { return parent::setColumnSettings($column_gui); }
163  final protected function checkPermission($a_perm, $a_cmd = "") { return parent::checkPermission($a_perm, $a_cmd); }
164 
165  // -> ilContainerGUI
166  final protected function showPossibleSubObjects() { return parent::showPossibleSubObjects(); }
167  // -> ilRepUtilGUI
168  final public function deleteObject() { return parent::deleteObject(); } // done
169  final public function trashObject() { return parent::trashObject(); } // done
170  // -> ilRepUtil
171  final public function undeleteObject() { return parent::undeleteObject(); } // done
172  final public function confirmedDeleteObject() { return parent::confirmedDeleteObject(); } // done
173  final public function cancelDeleteObject() { return parent::cancelDeleteObject(); } // ok
174  final public function removeFromSystemObject() { return parent::removeFromSystemObject(); } // done
175  final protected function redirectToRefId() { return parent::redirectToRefId(); } // ok
176 
177  // -> stefan
178  final protected function fillCloneTemplate($a_tpl_varname,$a_type) { return parent::fillCloneTemplate($a_tpl_varname,$a_type); }
179  final protected function fillCloneSearchTemplate($a_tpl_varname,$a_type) { return parent::fillCloneSearchTemplate($a_tpl_varname,$a_type); }
180  final protected function searchCloneSourceObject() { return parent::searchCloneSourceObject(); }
181  final public function cloneAllObject() { return parent::cloneAllObject(); }
182  final protected function buildCloneSelect($existing_objs) { return parent::buildCloneSelect($existing_objs); }
183 
184  // -> ilAdministration
185  final private function displayList() { return parent::displayList(); }
186  final public function viewObject() { return parent::viewObject(); }
187 // final private function setAdminTabs() { return parent::setAdminTabs(); }
188  final public function getAdminTabs($a) { return parent::getAdminTabs($a); }
189  final protected function addAdminLocatorItems() { return parent::addAdminLocatorItems(); }
190 
194 // final private function setSubObjects() { die("ilObject2GUI::setSubObjects() is deprecated."); }
195 // final public function getFormAction() { die("ilObject2GUI::getFormAction() is deprecated."); }
196 // final protected function setFormAction() { die("ilObject2GUI::setFormAction() is deprecated."); }
197  final protected function getReturnLocation() { die("ilObject2GUI::getReturnLocation() is deprecated."); }
198  final protected function setReturnLocation() { die("ilObject2GUI::setReturnLocation() is deprecated."); }
199  final protected function showActions() { die("ilObject2GUI::showActions() is deprecated."); }
200  final public function getTemplateFile() {mk(); die("ilObject2GUI::getTemplateFile() is deprecated."); }
201  final protected function getTitlesByRefId() { die("ilObject2GUI::getTitlesByRefId() is deprecated."); }
202  final protected function getTabs() {nj(); die("ilObject2GUI::getTabs() is deprecated."); }
203  final protected function __showButton() { die("ilObject2GUI::__showButton() is deprecated."); }
204  final protected function hitsperpageObject() { die("ilObject2GUI::hitsperpageObject() is deprecated."); }
205  final protected function __initTableGUI() { die("ilObject2GUI::__initTableGUI() is deprecated."); }
206  final protected function __setTableGUIBasicData() { die("ilObject2GUI::__setTableGUIBasicData() is deprecated."); }
207  final protected function __showClipboardTable() { die("ilObject2GUI::__showClipboardTable() is deprecated."); }
208 
212  protected function addLocatorItems() {}
213  public function copyWizardHasOptions($a_mode) { return false; }
214  protected function setTabs() { }
215 
219  abstract function getType();
220 
224 // final private function permObject() { parent::permObject(); }
225 // final private function permSaveObject() { parent::permSaveObject(); }
226 // final private function infoObject() { parent::infoObject(); }
227 // final private function __buildRoleFilterSelect() { parent::__buildRoleFilterSelect(); }
228 // final private function __filterRoles() { parent::__filterRoles(); }
229 // final private function ownerObject() { parent::ownerObject(); }
230 // final private function changeOwnerObject() { parent::changeOwnerObject(); }
231 // final private function addRoleObject() { parent::addRoleObject(); }
232 // final private function setActions() { die("ilObject2GUI::setActions() is deprecated."); }
233 // final protected function getActions() { die("ilObject2GUI::getActions() is deprecated."); }
234 
241  function deactivateCreationForm($a_type)
242  {
243  foreach ($this->creation_forms as $k => $v)
244  {
245  if ($v == $a_type)
246  {
247  unset($this->creation_forms[$k]);
248  break;
249  }
250  }
251  }
252 
258  function addCreationForm($a_header, $a_form)
259  {
260  $this->creation_forms[] = array("header" => $a_header,
261  "form" => $a_form);
262  }
263 
269  function create()
270  {
271  global $rbacsystem, $tpl, $ilCtrl;
272 
273  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
274  $ilCtrl->setParameter($this, "new_type", $new_type);
275  $this->initCreationForms();
276 
277  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
278  {
279  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
280  }
281  else
282  {
283  $tpl->setContent($this->getCreationFormsHTML());
284 // $this->ctrl->setParameter($this, "new_type", $new_type);
285 // $this->initEditForm("create", $new_type);
286 // $tpl->setContent($this->form->getHTML());
287 
288 // if ($new_type != "mep") // bad hack, should be removed (implemented!)
289 // {
290 // $clone_html = $this->fillCloneTemplate('', $new_type);
291 // }
292 
293 // $tpl->setContent($this->form->getHTML().$clone_html);
294  }
295  }
296 
300  protected function initCreationForms()
301  {
302  }
303 
308  {
309  global $lng;
310 
311  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
312 
313  $lng->loadLanguageModule($new_type);
314  if (count($this->creation_forms) == 1)
315  {
316  $cf = $this->creation_forms[0];
317  if (is_array($cf))
318  {
319  return $cf["form"]->getHTML();
320  }
321  else if ($cf == ilObject2GUI::CFORM_NEW)
322  {
323  $this->initEditForm("create", $new_type);
324  return $this->form->getHTML();
325  }
326  else if ($cf == ilObject2GUI::CFORM_CLONE)
327  {
328 return "";
329  return $this->fillCloneTemplate('', $new_type);
330  }
331  else if($cf == ilObject2GUI::CFORM_IMPORT)
332  {
333  $this->initImportForm($new_type);
334  return $this->form->getHTML();
335  }
336  }
337  else if (count($this->creation_forms) > 1)
338  {
339  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
340 
341  $html = "";
342 // $acc = new ilAccordionGUI();
343 // $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
344  $cnt = 1;
345  foreach ($this->creation_forms as $cf)
346  {
347 // $htpl = new ilTemplate("tpl.creation_acc_head.html", true, true, "Services/Object");
348 // $htpl->setVariable("IMG_ARROW", ilUtil::getImagePath("accordion_arrow.gif"));
349 
350 // $ot = $lng->txt("option")." ".$cnt.": ";
351  if (is_array($cf))
352  {
353 // $htpl->setVariable("TITLE", $ot.$cf["header"]);
354 // $acc->addItem($htpl->get(), $cf["form"]->getHTML());
355 $html.= $cf["form"]->getHTML()."<br />";
356  }
357  else if ($cf == ilObject2GUI::CFORM_NEW)
358  {
359  $this->initEditForm("create", $new_type);
360 // $htpl->setVariable("TITLE", $ot.$lng->txt($new_type."_create"));
361 // $acc->addItem($htpl->get(), $this->form->getHTML());
362 $html.= $this->form->getHTML()."<br />";
363  }
364  else if ($cf == ilObject2GUI::CFORM_CLONE)
365  {
366 // $clone_html = $this->fillCloneTemplate('', $new_type);
367 // $htpl->setVariable("TITLE", $ot.$lng->txt($new_type."_clone"));
368 // $acc->addItem($htpl->get(), $clone_html);
369  }
370  else if($cf == ilObject2GUI::CFORM_IMPORT)
371  {
372  $this->initImportForm($new_type);
373 // $htpl->setVariable("TITLE", $ot.$lng->txt($new_type."_import"));
374 // $acc->addItem($htpl->get(), $this->form->getHTML());
375 $html.= $this->form->getHTML()."<br />";
376  }
377  $cnt++;
378  }
379 
380 // return $acc->getHTML();
381  return $html;
382  }
383  }
384 
385 
391  function save()
392  {
393  global $rbacsystem, $objDefinition, $tpl, $lng;
394 
395  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
396 
397  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
398  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
399  {
400  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
401  }
402  $this->ctrl->setParameter($this, "new_type", $new_type);
403  $this->initEditForm("create", $new_type);
404  if ($this->form->checkInput())
405  {
406 
407  $location = $objDefinition->getLocation($new_type);
408 
409  // create and insert object in objecttree
410  $class_name = "ilObj".$objDefinition->getClassName($new_type);
411  include_once($location."/class.".$class_name.".php");
412  $newObj = new $class_name();
413  $newObj->setType($new_type);
414  $newObj->setTitle(ilUtil::stripSlashes($_POST["title"]));
415  $newObj->setDescription(ilUtil::stripSlashes($_POST["desc"]));
416  $newObj->create();
417  $newObj->createReference();
418  $newObj->putInTree($_GET["ref_id"]);
419  $newObj->setPermissions($_GET["ref_id"]);
420  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
421  $this->afterSave($newObj);
422  return;
423  }
424 
425  $this->form->setValuesByPost();
426  $tpl->setContent($this->form->getHtml());
427  }
428 
434  public function initEditForm($a_mode = "edit", $a_new_type = "")
435  {
436  global $lng, $ilCtrl;
437 
438  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
439  $this->form = new ilPropertyFormGUI();
440  $this->form->setTarget("_top");
441 
442  // title
443  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
444  $ti->setMaxLength(128);
445  $ti->setSize(40);
446  $ti->setRequired(true);
447  $this->form->addItem($ti);
448 
449  // description
450  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
451  $ta->setCols(40);
452  $ta->setRows(2);
453  $this->form->addItem($ta);
454 
455  // save and cancel commands
456  if ($a_mode == "create")
457  {
458  $this->form->addCommandButton("save", $lng->txt($a_new_type."_add"));
459  $this->form->addCommandButton("cancelCreation", $lng->txt("cancel"));
460  $this->form->setTitle($lng->txt($a_new_type."_new"));
461  }
462  else
463  {
464  $this->form->addCommandButton("update", $lng->txt("save"));
465  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
466  $this->form->setTitle($lng->txt("edit"));
467  }
468 
469  $this->form->setFormAction($ilCtrl->getFormAction($this));
470 
471  }
472 
476  function getEditFormValues()
477  {
478  $values["title"] = $this->object->getTitle();
479  $values["desc"] = $this->object->getDescription();
480  $this->form->setValuesByArray($values);
481  }
482 
488  protected function cancel()
489  {
490  $this->ctrl->returnToParent($this);
491  }
492 
498  final function cancelCreation($in_rep = false)
499  {
500  ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
501  }
502 
508  function editObject()
509  {
510  global $tpl;
511 
512  $this->initEditForm("edit");
513  $this->getEditFormValues();
514  $tpl->setContent($this->form->getHTML());
515  }
516 
522  final function cancelUpdate()
523  {
524  $this->ctrl->redirect($this);
525  }
526 
532  function updateObject()
533  {
534  global $lng, $tpl;
535 
536  $this->initEditForm("edit");
537  if ($this->form->checkInput())
538  {
539  $this->object->setTitle($_POST["title"]);
540  $this->object->setDescription($_POST["desc"]);
541  $this->update = $this->object->update();
542  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
543  $this->afterUpdate();
544  return;
545  }
546  $this->form->setValuesByPost();
547  $tpl->setContent($this->form->getHtml());
548  }
549 
550  function afterUpdate()
551  {
552  $this->ctrl->redirect($this);
553  }
554 
560  public function initImportForm($a_new_type = "")
561  {
562  global $lng, $ilCtrl;
563 
564  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
565  $this->form = new ilPropertyFormGUI();
566  $this->form->setTarget("_top");
567 
568  // Import file
569  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
570  $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
571  $fi->setSuffixes(array("zip"));
572  $this->form->addItem($fi);
573 
574  $this->form->addCommandButton("importFile", $lng->txt("import"));
575  $this->form->addCommandButton("cancelCreation", $lng->txt("cancel"));
576  $this->form->setTitle($lng->txt($a_new_type."_import"));
577 
578  $this->form->setFormAction($ilCtrl->getFormAction($this));
579  }
580 
586  function importFile()
587  {
588  global $rbacsystem, $objDefinition, $tpl, $lng;
589 
590  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
591 
592  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
593  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
594  {
595  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
596  }
597  $this->ctrl->setParameter($this, "new_type", $new_type);
598  $this->initImportForm($new_type);
599  if ($this->form->checkInput())
600  {
601  // todo: make some check on manifest file
602  include_once("./Services/Export/classes/class.ilImport.php");
603  $imp = new ilImport((int) $_GET['ref_id']);
604  $new_id = $imp->importObject($newObj, $_FILES["importfile"]["tmp_name"],
605  $_FILES["importfile"]["name"], $new_type);
606 
607  // put new object id into tree
608  if ($new_id > 0)
609  {
610  $newObj = ilObjectFactory::getInstanceByObjId($new_id);
611  $newObj->createReference();
612  $newObj->putInTree($_GET["ref_id"]);
613  $newObj->setPermissions($_GET["ref_id"]);
614  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
615  $this->afterSave($newObj);
616  }
617  return;
618  }
619 
620  $this->form->setValuesByPost();
621  $tpl->setContent($this->form->getHtml());
622  }
623 
624 }