ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectGUI.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 
14 {
16 
22  var $ilias;
23 
30 
36  var $tpl;
37 
43  var $tree;
44 
50  var $lng;
51 
57  var $data;
58 
64  var $object;
65  var $ref_id;
66  var $obj_id;
67  var $maxcount; // contains number of child objects
68  var $formaction; // special formation (array "cmd" => "formaction")
69  var $return_location; // special return location (array "cmd" => "location")
70  var $target_frame; // special target frame (array "cmd" => "location")
71 
73  var $actions;
75  var $omit_locator = false;
76 
84  function ilObjectGUI($a_data, $a_id = 0, $a_call_by_reference = true, $a_prepare_output = true)
85  {
86  global $ilias, $objDefinition, $tpl, $tree, $ilCtrl, $ilErr, $lng, $ilTabs;
87 
88  $this->tabs_gui =& $ilTabs;
89 
90  if (!isset($ilErr))
91  {
92  $ilErr = new ilErrorHandling();
93  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
94  }
95  else
96  {
97  $this->ilErr =& $ilErr;
98  }
99 
100  $this->ilias =& $ilias;
101  $this->objDefinition =& $objDefinition;
102  $this->tpl =& $tpl;
103  $this->html = "";
104  $this->ctrl =& $ilCtrl;
105 
106  $params = array("ref_id");
107 
108  if (!$a_call_by_reference)
109  {
110  $params = array("ref_id","obj_id");
111  }
112 
113  $this->ctrl->saveParameter($this, $params);
114 
115  $this->lng =& $lng;
116  $this->tree =& $tree;
117  $this->formaction = array();
118  $this->return_location = array();
119  $this->target_frame = array();
120  $this->actions = "";
121  $this->sub_objects = "";
122 
123  $this->data = $a_data;
124  $this->id = $a_id;
125  $this->call_by_reference = $a_call_by_reference;
126  $this->prepare_output = $a_prepare_output;
127  $this->creation_mode = false;
128 
129  $this->ref_id = ($this->call_by_reference) ? $this->id : $_GET["ref_id"];
130  $this->obj_id = ($this->call_by_reference) ? $_GET["obj_id"] : $this->id;
131 
132  if ($this->id != 0)
133  {
134  $this->link_params = "ref_id=".$this->ref_id;
135  }
136 
137  // get the object
138  $this->assignObject();
139 
140  // set context
141  if (is_object($this->object))
142  {
143  if ($this->call_by_reference && $this->ref_id = $_GET["ref_id"])
144  {
145  $this->ctrl->setContext($this->object->getId(),
146  $this->object->getType());
147  }
148  }
149 
150  // use global $lng instead, when creating new objects object is not available
151  //$this->lng =& $this->object->lng;
152 
153  //prepare output
154  if ($a_prepare_output)
155  {
156  $this->prepareOutput();
157  }
158  }
159 
160 
164  function &executeCommand()
165  {
166  global $rbacsystem;
167 
168  $next_class = $this->ctrl->getNextClass($this);
169  $cmd = $this->ctrl->getCmd();
170 
171  switch($next_class)
172  {
173  default:
174  $this->prepareOutput();
175  if(!$cmd)
176  {
177  $cmd = "view";
178  }
179  $cmd .= "Object";
180  $this->$cmd();
181 
182  break;
183  }
184 
185  return true;
186  }
187 
188 
192  public function withReferences()
193  {
194  return $this->call_by_reference;
195  }
196 
203  public function setCreationMode($a_mode = true)
204  {
205  $this->creation_mode = $a_mode;
206  }
207 
211  public function getCreationMode()
212  {
213  return $this->creation_mode;
214  }
215 
216  protected function assignObject()
217  {
218  // TODO: it seems that we always have to pass only the ref_id
219 //echo "<br>ilObjectGUIassign:".get_class($this).":".$this->id.":<br>";
220  if ($this->id != 0)
221  {
222  if ($this->call_by_reference)
223  {
224  $this->object = ilObjectFactory::getInstanceByRefId($this->id);
225  }
226  else
227  {
228  $this->object = ilObjectFactory::getInstanceByObjId($this->id);
229  }
230  }
231  }
232 
236  protected function prepareOutput()
237  {
238  global $ilLocator, $tpl, $ilUser;
239 
240  $this->tpl->getStandardTemplate();
241  // administration prepare output
242  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
243  {
244  $this->addAdminLocatorItems();
245  $tpl->setLocator();
246 
247 // ilUtil::sendInfo();
249 
250  $this->setTitleAndDescription();
251 
252  if ($this->getCreationMode() != true)
253  {
254  $this->setAdminTabs();
255  $this->showUpperIcon();
256  }
257 
258  return false;
259  }
260  // set locator
261  $this->setLocator();
262  // catch feedback message
263 // ilUtil::sendInfo();
265 
266  // in creation mode (parent) object and gui object
267  // do not fit
268  if ($this->getCreationMode() == true)
269  {
270  // get gui class of parent and call their title and description method
271  $obj_type = ilObject::_lookupType($_GET["ref_id"],true);
272  $class_name = $this->objDefinition->getClassName($obj_type);
273  $class = strtolower("ilObj".$class_name."GUI");
274  $class_path = $this->ctrl->lookupClassPath($class);
275  include_once($class_path);
276  $class_name = $this->ctrl->getClassForClasspath($class_path);
277 //echo "<br>instantiating parent for title and description";
278  $this->parent_gui_obj = new $class_name("", $_GET["ref_id"], true, false);
279  $this->parent_gui_obj->setTitleAndDescription();
280  }
281  else
282  {
283  // set title and description and title icon
284  $this->setTitleAndDescription();
285 
286  // set tabs
287  $this->setTabs();
288  $this->showUpperIcon();
289 
290  // BEGIN WebDAV: Display Mount Webfolder icon.
291  require_once 'Services/WebDAV/classes/class.ilDAVServer.php';
292  if (ilDAVServer::_isActive() &&
293  $ilUser->getId() != ANONYMOUS_USER_ID)
294  {
295  $this->showMountWebfolderIcon();
296  }
297  // END WebDAV: Display Mount Webfolder icon.
298  }
299 
300  return true;
301  }
302 
303 
307  protected function setTitleAndDescription()
308  {
309  $this->tpl->setTitle($this->object->getPresentationTitle());
310  $this->tpl->setDescription($this->object->getLongDescription());
311  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
312  {
313  // alt text would be same as heading -> empty alt text
314  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"),
315  "");
316  }
317  else
318  {
319  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"),
320  $this->lng->txt("obj_" . $this->object->getType()));
321  }
322  }
323 
324  protected function showUpperIcon()
325  {
326  global $tree, $tpl, $objDefinition;
327 
328  if ($this->object->getRefId() == "")
329  {
330  return;
331  }
332 
333  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
334  {
335  if ($this->object->getRefId() != ROOT_FOLDER_ID &&
336  $this->object->getRefId() != SYSTEM_FOLDER_ID)
337  {
338  $par_id = $tree->getParentId($this->object->getRefId());
339  $obj_type = ilObject::_lookupType($par_id,true);
340  $class_name = $objDefinition->getClassName($obj_type);
341  $class = strtolower("ilObj".$class_name."GUI");
342  $this->ctrl->setParameterByClass($class, "ref_id", $par_id);
343  $tpl->setUpperIcon($this->ctrl->getLinkTargetByClass($class, "view"));
344  $this->ctrl->clearParametersByClass($class);
345  }
346  // link repository admin to admin settings
347  else if ($this->object->getRefId() == ROOT_FOLDER_ID)
348  {
349  $this->ctrl->setParameterByClass("iladministrationgui", "ref_id", "");
350  $this->ctrl->setParameterByClass("iladministrationgui", "admin_mode", "settings");
351  $tpl->setUpperIcon($this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
352  ilFrameTargetInfo::_getFrame("MainContent"));
353  $this->ctrl->clearParametersByClass("iladministrationgui");
354  }
355  }
356  else
357  {
358  if ($this->object->getRefId() != ROOT_FOLDER_ID &&
359  $this->object->getRefId() != SYSTEM_FOLDER_ID &&
360  $_GET["obj_id"] == "")
361  {
362  if (defined("ILIAS_MODULE"))
363  {
364  $prefix = "../";
365  }
366  $par_id = $tree->getParentId($this->object->getRefId());
367  $tpl->setUpperIcon($prefix."repository.php?cmd=frameset&ref_id=".$par_id,
368  ilFrameTargetInfo::_getFrame("MainContent"));
369  }
370  }
371  }
372  // BEGIN WebDAV: Show Mount Webfolder Icon.
373  final private function showMountWebfolderIcon()
374  {
375  global $tree, $tpl, $objDefinition;
376 
377  if ($this->object->getRefId() == "")
378  {
379  return;
380  }
381 
382  $tpl->setMountWebfolderIcon($this->object->getRefId());
383  }
384  // END WebDAV: Show Mount Webfolder Icon.
385 
386 
391  protected function setTabs()
392  {
393  $this->getTabs($this->tabs_gui);
394  }
395 
400  protected final function setAdminTabs()
401  {
402  $this->getAdminTabs($this->tabs_gui);
403  }
404 
408  function getAdminTabs(&$tabs_gui)
409  {
410  global $rbacsystem, $tree;
411 
412  if ($_GET["admin_mode"] == "repository")
413  {
414  $this->ctrl->setParameterByClass("iladministrationgui", "admin_mode", "settings");
415  $tabs_gui->setBackTarget($this->lng->txt("administration"),
416  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
417  ilFrameTargetInfo::_getFrame("MainContent"));
418  $this->ctrl->setParameterByClass("iladministrationgui", "admin_mode", "repository");
419  }
420 
421  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
422  {
423  $tabs_gui->addTarget("view",
424  $this->ctrl->getLinkTarget($this, "view"), array("", "view"), get_class($this));
425  }
426 
427  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
428  {
429  $tabs_gui->addTarget("perm_settings",
430  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), "", "ilpermissiongui");
431  }
432 
433  if ($tree->getSavedNodeData($this->object->getRefId()))
434  {
435  $tabs_gui->addTarget("trash",
436  $this->ctrl->getLinkTarget($this, "trash"), "trash", get_class($this));
437  }
438  }
439 
440 
441  function getHTML()
442  {
443  return $this->html;
444  }
445 
446 
453  final private function setActions($a_actions = "")
454  {
455  if (is_array($a_actions))
456  {
457  foreach ($a_actions as $name => $lng)
458  {
459  $this->actions[$name] = array("name" => $name, "lng" => $lng);
460  }
461  }
462  else
463  {
464  $this->actions = "";
465  }
466  }
467 
474  final private function setSubObjects($a_sub_objects = "")
475  {
476  if (is_array($a_sub_objects))
477  {
478  foreach ($a_sub_objects as $name => $options)
479  {
480  $this->sub_objects[$name] = array("name" => $name, "max" => $options["max"]);
481  }
482  }
483  else
484  {
485  $this->sub_objects = "";
486  }
487  }
488 
497  protected function setLocator()
498  {
499  global $ilLocator, $tpl;
500 
501  if ($this->omit_locator)
502  {
503  return;
504  }
505 
506  // todo: admin workaround
507  // in the future, objectgui classes should not be called in
508  // admin section anymore (rbac/trash handling in own classes)
509  $ref_id = ($_GET["ref_id"] != "")
510  ? $_GET["ref_id"]
511  : $this->object->getRefId();
512  $ilLocator->addRepositoryItems($ref_id);
513 
514  if(!$this->creation_mode)
515  {
516  $this->addLocatorItems();
517  }
518 
519  // not so nice workaround: todo: handle $ilLocator as tabs in ilTemplate
520  if ($_GET["admin_mode"] == "" &&
521  strtolower($this->ctrl->getCmdClass()) == "ilobjrolegui")
522  {
523  $this->ctrl->setParameterByClass("ilobjrolegui",
524  "rolf_ref_id", $_GET["rolf_ref_id"]);
525  $this->ctrl->setParameterByClass("ilobjrolegui",
526  "obj_id", $_GET["obj_id"]);
527  $ilLocator->addItem($this->lng->txt("role"),
528  $this->ctrl->getLinkTargetByClass(array("ilpermissiongui",
529  "ilobjrolegui"), "perm"));
530  }
531 
532  $tpl->setLocator();
533  }
534 
539  protected function addLocatorItems()
540  {
541  }
542 
543  protected function omitLocator($a_omit = true)
544  {
545  $this->omit_locator = $a_omit;
546  }
547 
552  protected function addAdminLocatorItems()
553  {
554  global $ilLocator;
555 
556  if ($_GET["admin_mode"] == "settings") // system settings
557  {
558  $ilLocator->addItem($this->lng->txt("administration"),
559  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
560  ilFrameTargetInfo::_getFrame("MainContent"));
561  if ($this->object->getRefId() != SYSTEM_FOLDER_ID)
562  {
563  $ilLocator->addItem($this->object->getTitle(),
564  $this->ctrl->getLinkTarget($this, "view"));
565  }
566  }
567  else // repository administration
568  {
569  $this->ctrl->setParameterByClass("iladministrationgui",
570  "ref_id", "");
571  $this->ctrl->setParameterByClass("iladministrationgui",
572  "admin_mode", "settings");
573  //$ilLocator->addItem($this->lng->txt("administration"),
574  // $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
575  // ilFrameTargetInfo::_getFrame("MainContent"));
576  $this->ctrl->clearParametersByClass("iladministrationgui");
577  $ilLocator->addAdministrationItems();
578  }
579 
580  }
581 
585  public function undeleteObject()
586  {
587  include_once("./Services/Repository/classes/class.ilRepUtilGUI.php");
588  $ru = new ilRepUtilGUI($this);
589  $ru->restoreObjects($_GET["ref_id"], $_POST["trash_id"]);
590  $this->ctrl->redirect($this, "trash");
591  }
592 
597  public function confirmedDeleteObject()
598  {
599  global $ilSetting, $lng;
600 
601  include_once("./Services/Repository/classes/class.ilRepUtilGUI.php");
602  $ru = new ilRepUtilGUI($this);
603  $ru->deleteObjects($_GET["ref_id"], $_SESSION["saved_post"]);
604  session_unregister("saved_post");
605  $this->ctrl->returnToParent($this);
606  }
607 
613  public function cancelDeleteObject()
614  {
615  session_unregister("saved_post");
616  $this->ctrl->returnToParent($this);
617  }
618 
624  public function removeFromSystemObject()
625  {
626  global $rbacsystem, $log, $ilAppEventHandler, $lng;
627 
628  include_once("./Services/Repository/classes/class.ilRepUtilGUI.php");
629  $ru = new ilRepUtilGUI($this);
630  $ru->removeObjectsFromSystem($_POST["trash_id"]);
631  $this->ctrl->redirect($this, "trash");
632  }
633 
639  public function createObject()
640  {
641  global $rbacsystem;
642 
643  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
644 
645  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
646  {
647  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
648  }
649  else
650  {
651  // fill in saved values in case of error
652  $data = array();
653  $data["fields"] = array();
654  $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
655  $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
656 
657  $this->getTemplateFile("edit",$new_type);
658 
659  // show obj type image
660  $this->tpl->setCurrentBlock("img");
661  $this->tpl->setVariable("TYPE_IMG",
662  ilUtil::getImagePath("icon_".$new_type.".gif"));
663  $this->tpl->setVariable("ALT_IMG",
664  $this->lng->txt("obj_".$new_type));
665  $this->tpl->parseCurrentBlock();
666 
667  foreach ($data["fields"] as $key => $val)
668  {
669  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
670  $this->tpl->setVariable(strtoupper($key), $val);
671 
672  if ($this->prepare_output)
673  {
674  $this->tpl->parseCurrentBlock();
675  }
676  }
677  $this->ctrl->setParameter($this, "new_type", $new_type);
678  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "save"));
679  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
680  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
681  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
682  $this->tpl->setVariable("CMD_SUBMIT", "save");
683  $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
684  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
685  }
686  }
687 
688 
694  public function cancelObject($in_rep = false)
695  {
696  session_unregister("saved_post");
697 
698  $this->ctrl->returnToParent($this);
699  }
700 
706  public function saveObject()
707  {
708  global $rbacsystem, $objDefinition, $rbacreview;
709 
710  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
711 
712  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
713  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
714  {
715  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
716  }
717 //echo ":".$_GET["new_type"].":".$_POST["new_type"].":";
718  $location = $objDefinition->getLocation($new_type);
719 
720  // create and insert object in objecttree
721  $class_name = "ilObj".$objDefinition->getClassName($new_type);
722  include_once($location."/class.".$class_name.".php");
723  $newObj = new $class_name();
724  $newObj->setType($new_type);
725  $newObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
726  $newObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
727  $newObj->create();
728  $newObj->createReference();
729  $newObj->putInTree($_GET["ref_id"]);
730  $newObj->setPermissions($_GET["ref_id"]);
731  //$newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
732 
733  // rbac log
734  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
735  $rbac_log_roles = $rbacreview->getParentRoleIds($newObj->getRefId(), false);
736  $rbac_log = ilRbacLog::gatherFaPa($newObj->getRefId(), array_keys($rbac_log_roles));
737  ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $newObj->getRefId(), $rbac_log);
738 
739  return $newObj;
740  }
741 
747  public function editObject()
748  {
749  global $rbacsystem;
750 
751  if (!$rbacsystem->checkAccess("write", $this->ref_id))
752  {
753  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
754  }
755 
756  $fields = array();
757 
758  if ($_SESSION["error_post_vars"])
759  {
760  // fill in saved values in case of error
761  $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
762  $fields["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
763  }
764  else
765  {
766  $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
767  $fields["desc"] = ilUtil::stripSlashes($this->object->getLongDescription());
768  }
769 
770  $this->displayEditForm($fields);
771  }
772 
779  protected function displayEditForm($fields)
780  {
781  $this->getTemplateFile("edit");
782 
783  foreach ($fields as $key => $val)
784  {
785  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
786  $this->tpl->setVariable(strtoupper($key), $val);
787 // $this->tpl->parseCurrentBlock();
788  }
789 
790  //$obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
791  if (!$this->call_by_reference)
792  {
793  $this->ctrl->setParameter($this, "obj_id", $this->obj_id);
794  }
795 
796  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "update"));
797  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
798  $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
799  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
800  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
801  $this->tpl->setVariable("CMD_SUBMIT", "update");
802  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
803 
804  }
805 
806 
812  public function updateObject()
813  {
814  $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
815  $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
816  $this->update = $this->object->update();
817 
818  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
819 
820  $this->afterUpdate();
821  }
822 
823  protected function afterUpdate()
824  {
825  $this->ctrl->redirect($this);
826  }
827 
828 
837  public function getFormAction($a_cmd, $a_formaction = "")
838  {
839  if ($this->formaction[$a_cmd] != "")
840  {
841  return $this->formaction[$a_cmd];
842  }
843  else
844  {
845  return $a_formaction;
846  }
847  }
848 
857  protected function setFormAction($a_cmd, $a_formaction)
858  {
859  $this->formaction[$a_cmd] = $a_formaction;
860  }
861 
869  protected function getReturnLocation($a_cmd, $a_location ="")
870  {
871  if ($this->return_location[$a_cmd] != "")
872  {
873  return $this->return_location[$a_cmd];
874  }
875  else
876  {
877  return $a_location;
878  }
879  }
880 
888  protected function setReturnLocation($a_cmd, $a_location)
889  {
890 //echo "-".$a_cmd."-".$a_location."-";
891  $this->return_location[$a_cmd] = $a_location;
892  }
893 
901  protected function getTargetFrame($a_cmd, $a_target_frame = "")
902  {
903  if ($this->target_frame[$a_cmd] != "")
904  {
905  return $this->target_frame[$a_cmd];
906  }
907  elseif (!empty($a_target_frame))
908  {
909  return "target=\"".$a_target_frame."\"";
910  }
911  else
912  {
913  return;
914  }
915  }
916 
924  protected function setTargetFrame($a_cmd, $a_target_frame)
925  {
926  $this->target_frame[$a_cmd] = "target=\"".$a_target_frame."\"";
927  }
928 
929  // BEGIN Security: Hide objects which aren't accessible by the user.
930  public function isVisible($a_ref_id,$a_type)
931  {
932  global $rbacsystem, $ilBench;
933 
934  $ilBench->start("Explorer", "setOutput_isVisible");
935  $visible = $rbacsystem->checkAccess('visible,read',$a_ref_id);
936 
937  if ($visible && $a_type == 'crs') {
938  global $tree;
939  if($crs_id = $tree->checkForParentType($a_ref_id,'crs'))
940  {
941  if(!$rbacsystem->checkAccess('write',$crs_id))
942  {
943  // Show only activated courses
944  $tmp_obj =& ilObjectFactory::getInstanceByRefId($crs_id,false);
945 
946  if(!$tmp_obj->isActivated())
947  {
948  unset($tmp_obj);
949  $visible = false;
950  }
951  if(($crs_id != $a_ref_id) and $tmp_obj->isArchived())
952  {
953  $visible = false;
954  }
955  // Show only activated course items
956  include_once "./course/classes/class.ilCourseItems.php";
957 
958  if(($crs_id != $a_ref_id) and (!ilCourseItems::_isActivated($a_ref_id)))
959  {
960  $visible = false;
961  }
962  }
963  }
964  }
965 
966  $ilBench->stop("Explorer", "setOutput_isVisible");
967 
968  return $visible;
969  }
970  // END Security: Hide objects which aren't accessible by the user.
971 
977  public function viewObject()
978  {
979  global $rbacsystem, $tpl;
980 
981  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
982  {
983  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
984  }
985  // BEGIN ChangeEvent: record read event.
986  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
988  {
989  global $ilUser;
991  $this->object->getType(),
992  $this->object->getRefId(),
993  $this->object->getId(), $ilUser->getId());
994  }
995  // END ChangeEvent: record read event.
996 
997  include_once("./Services/Repository/classes/class.ilAdminSubItemsTableGUI.php");
998  if (!$this->call_by_reference)
999  {
1000  $this->ctrl->setParameter($this, "obj_id", $this->obj_id);
1001  }
1002  $itab = new ilAdminSubItemsTableGUI($this, "view", $_GET["ref_id"]);
1003 
1004  $tpl->setContent($itab->getHTML());
1005  }
1006 
1014  public function deleteObject($a_error = false)
1015  {
1016  global $tpl, $ilCtrl;
1017 
1018  if ($_GET["item_ref_id"] != "")
1019  {
1020  $_POST["id"] = array($_GET["item_ref_id"]);
1021  }
1022 
1023  // SAVE POST VALUES (get rid of this
1024  $_SESSION["saved_post"] = $_POST["id"];
1025 
1026  include_once("./Services/Repository/classes/class.ilRepUtilGUI.php");
1027  $ru = new ilRepUtilGUI($this);
1028  if (!$ru->showDeleteConfirmation($_POST["id"], $a_error))
1029  {
1030  $ilCtrl->returnToParent($this);
1031  }
1032  }
1033 
1039  public function trashObject()
1040  {
1041  global $tpl;
1042 
1043  include_once("./Services/Repository/classes/class.ilRepUtilGUI.php");
1044  $ru = new ilRepUtilGUI($this);
1045  $ru->showTrashTable($_GET["ref_id"]);
1046  }
1047 
1053  protected function showPossibleSubObjects()
1054  {
1055  if ($this->sub_objects == "")
1056  {
1057  $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
1058  }
1059  else
1060  {
1062  }
1063 
1064  $import = false;
1065 
1066  if (count($d) > 0)
1067  {
1068  foreach ($d as $row)
1069  {
1070  $count = 0;
1071 
1072  if ($row["max"] > 0)
1073  {
1074  //how many elements are present?
1075  for ($i=0; $i<count($this->data["ctrl"]); $i++)
1076  {
1077  if ($this->data["ctrl"][$i]["type"] == $row["name"])
1078  {
1079  $count++;
1080  }
1081  }
1082  }
1083 
1084  if ($row["max"] == "" || $count < $row["max"])
1085  {
1086  $subobj[] = $row["name"];
1087  }
1088  }
1089  }
1090 
1091  if (is_array($subobj))
1092  {
1093 
1094  //build form
1095  $opts = ilUtil::formSelect(12,"new_type",$subobj);
1096  $this->tpl->setCurrentBlock("add_object");
1097  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
1098  $this->tpl->setVariable("BTN_NAME", "create");
1099  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
1100  $this->tpl->parseCurrentBlock();
1101  }
1102  }
1103 
1112  public function getTemplateFile($a_cmd,$a_type = "")
1113  {
1114  if (!$a_type)
1115  {
1116  $a_type = $this->type;
1117  }
1118 
1119  $template = "tpl.".$a_type."_".$a_cmd.".html";
1120 
1121  if (!$this->tpl->fileExists($template) &&
1122  !file_exists("./templates/default/".$template))
1123  {
1124  $template = "tpl.obj_".$a_cmd.".html";
1125  }
1126  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", $template,$a_in_module);
1127  }
1128 
1137  protected function getTitlesByRefId($a_ref_ids)
1138  {
1139  foreach ($a_ref_ids as $id)
1140  {
1141  // GET OBJECT TITLE
1142  $tmp_obj =& $this->ilias->obj_factory->getInstanceByRefId($id);
1143  $title[] = $tmp_obj->getTitle();
1144  unset($tmp_obj);
1145  }
1146 
1147  return $title ? $title : array();
1148  }
1149 
1157  protected function getTabs(&$tabs_gui)
1158  {
1159  // please define your tabs here
1160 
1161  }
1162 
1163  // PROTECTED
1164  protected function __showButton($a_cmd,$a_text,$a_target = '')
1165  {
1166  global $ilToolbar;
1167 
1168  $ilToolbar->addButton($a_text, $this->ctrl->getLinkTarget($this, $a_cmd), $a_target);
1169  }
1170 
1171  protected function hitsperpageObject()
1172  {
1173  $_SESSION["tbl_limit"] = $_POST["hitsperpage"];
1174  $_GET["limit"] = $_POST["hitsperpage"];
1175  }
1176 
1177 
1178  protected function &__initTableGUI()
1179  {
1180  include_once "./Services/Table/classes/class.ilTableGUI.php";
1181 
1182  return new ilTableGUI(0,false);
1183  }
1184 
1190  protected function __setTableGUIBasicData(&$tbl,&$result_set,$a_from = "")
1191  {
1192  switch ($a_from)
1193  {
1194  case "clipboardObject":
1195  $offset = $_GET["offset"];
1196  $order = $_GET["sort_by"];
1197  $direction = $_GET["sort_order"];
1198  $tbl->disable("footer");
1199  break;
1200 
1201  default:
1202  $offset = $_GET["offset"];
1203  $order = $_GET["sort_by"];
1204  $direction = $_GET["sort_order"];
1205  break;
1206  }
1207 
1208  $tbl->setOrderColumn($order);
1209  $tbl->setOrderDirection($direction);
1210  $tbl->setOffset($offset);
1211  $tbl->setLimit($_GET["limit"]);
1212  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1213  $tbl->setData($result_set);
1214  }
1215 
1216  protected function __showClipboardTable($a_result_set,$a_from = "")
1217  {
1218  global $ilCtrl;
1219 
1220  $tbl =& $this->__initTableGUI();
1221  $tpl =& $tbl->getTemplateObject();
1222 
1223  $tpl->setCurrentBlock("tbl_form_header");
1224  $tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
1225  $tpl->parseCurrentBlock();
1226 
1227  $tpl->setCurrentBlock("tbl_action_btn");
1228  $tpl->setVariable("BTN_NAME","paste");
1229  $tpl->setVariable("BTN_VALUE",$this->lng->txt("insert_object_here"));
1230  $tpl->parseCurrentBlock();
1231 
1232  $tpl->setCurrentBlock("tbl_action_btn");
1233  $tpl->setVariable("BTN_NAME","clear");
1234  $tpl->setVariable("BTN_VALUE",$this->lng->txt("clear_clipboard"));
1235  $tpl->parseCurrentBlock();
1236 
1237  $tpl->setCurrentBlock("tbl_action_row");
1238  $tpl->setVariable("COLUMN_COUNTS",3);
1239  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("spacer.gif"));
1240  $tpl->parseCurrentBlock();
1241 
1242  $tbl->setTitle($this->lng->txt("clipboard"),"icon_typ_b.gif",$this->lng->txt("clipboard"));
1243  $tbl->setHeaderNames(array($this->lng->txt('obj_type'),
1244  $this->lng->txt('title'),
1245  $this->lng->txt('action')));
1246  $tbl->setHeaderVars(array('type',
1247  'title',
1248  'act'),
1249  array('ref_id' => $this->object->getRefId(),
1250  'cmd' => 'clipboard',
1251  'cmdClass' => $_GET['cmdClass'],
1252  'cmdNode' => $_GET['cmdNode']));
1253 
1254  $tbl->setColumnWidth(array("","80%","19%"));
1255 
1256 
1257  $this->__setTableGUIBasicData($tbl,$a_result_set,$a_from);
1258  $tbl->render();
1259 
1260  $this->tpl->setVariable("RESULT_TABLE",$tbl->tpl->get());
1261 
1262  return true;
1263  }
1264 
1274  protected function redirectToRefId($a_ref_id, $a_cmd = "")
1275  {
1276  $obj_type = ilObject::_lookupType($a_ref_id,true);
1277  $class_name = $this->objDefinition->getClassName($obj_type);
1278  $class = strtolower("ilObj".$class_name."GUI");
1279  $this->ctrl->redirectByClass(array("ilrepositorygui", $class), $a_cmd);
1280  }
1281 
1282  // Object Cloning
1292  protected function fillCloneTemplate($a_tpl_varname,$a_type)
1293  {
1294 
1295  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
1296  $cp = new ilObjectCopyGUI($this);
1297  $cp->setType($a_type);
1298  $cp->setTarget($_GET['ref_id']);
1299  $cp->showSourceSearch($a_tpl_varname);
1300  return;
1301  }
1302 
1303 
1304 
1311  public function cloneAllObject()
1312  {
1313  include_once('classes/class.ilLink.php');
1314  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1315 
1316  global $ilAccess,$ilErr,$rbacsystem,$ilUser;
1317 
1318  $new_type = $_REQUEST['new_type'];
1319  if(!$rbacsystem->checkAccess('create',(int) $_GET['ref_id'],$new_type))
1320  {
1321  $ilErr->raiseError($this->lng->txt('permission_denied'));
1322  }
1323  if(!(int) $_REQUEST['clone_source'])
1324  {
1325  ilUtil::sendFailure($this->lng->txt('select_one'));
1326  $this->createObject();
1327  return false;
1328  }
1329  if(!$ilAccess->checkAccess('write','',(int) $_REQUEST['clone_source'],$new_type))
1330  {
1331  $ilErr->raiseError($this->lng->txt('permission_denied'));
1332  }
1333 
1334  // Save wizard options
1336  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
1337  $wizard_options->saveOwner($ilUser->getId());
1338  $wizard_options->saveRoot((int) $_REQUEST['clone_source']);
1339 
1340  $options = $_POST['cp_options'] ? $_POST['cp_options'] : array();
1341  foreach($options as $source_id => $option)
1342  {
1343  $wizard_options->addEntry($source_id,$option);
1344  }
1345  $wizard_options->read();
1346 
1347  $orig = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['clone_source']);
1348  $new_obj = $orig->cloneObject((int) $_GET['ref_id'],$copy_id);
1349 
1350  // Delete wizard options
1351  $wizard_options->deleteAll();
1352 
1353  ilUtil::sendSuccess($this->lng->txt("object_duplicated"),true);
1354  ilUtil::redirect(ilLink::_getLink($new_obj->getRefId()));
1355  }
1356 
1364  public function copyWizardHasOptions($a_mode)
1365  {
1366  return false;
1367  }
1368 
1372  protected function getCenterColumnHTML()
1373  {
1374  global $ilCtrl, $ilAccess;
1375 
1376  include_once("Services/Block/classes/class.ilColumnGUI.php");
1377 
1378  $obj_id = ilObject::_lookupObjId($this->object->getRefId());
1379  $obj_type = ilObject::_lookupType($obj_id);
1380 
1381  if ($ilCtrl->getNextClass() != "ilcolumngui")
1382  {
1383  // normal command processing
1384  return $this->getContent();
1385  }
1386  else
1387  {
1388  if (!$ilCtrl->isAsynch())
1389  {
1390  //if ($column_gui->getScreenMode() != IL_SCREEN_SIDE)
1392  {
1393  // right column wants center
1395  {
1396  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
1397  $this->setColumnSettings($column_gui);
1398  $this->html = $ilCtrl->forwardCommand($column_gui);
1399  }
1400  // left column wants center
1402  {
1403  $column_gui = new ilColumnGUI($obj_type, IL_COL_LEFT);
1404  $this->setColumnSettings($column_gui);
1405  $this->html = $ilCtrl->forwardCommand($column_gui);
1406  }
1407  }
1408  else
1409  {
1410  // normal command processing
1411  return $this->getContent();
1412  }
1413  }
1414  }
1415  }
1416 
1420  protected function getRightColumnHTML()
1421  {
1422  global $ilUser, $lng, $ilCtrl, $ilAccess;
1423 
1424  $obj_id = ilObject::_lookupObjId($this->object->getRefId());
1425  $obj_type = ilObject::_lookupType($obj_id);
1426 
1427  include_once("Services/Block/classes/class.ilColumnGUI.php");
1428  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
1429 
1430  if ($column_gui->getScreenMode() == IL_SCREEN_FULL)
1431  {
1432  return "";
1433  }
1434 
1435  $this->setColumnSettings($column_gui);
1436 
1437  if ($ilCtrl->getNextClass() == "ilcolumngui" &&
1438  $column_gui->getCmdSide() == IL_COL_RIGHT &&
1439  $column_gui->getScreenMode() == IL_SCREEN_SIDE)
1440  {
1441  $html = $ilCtrl->forwardCommand($column_gui);
1442  }
1443  else
1444  {
1445  if (!$ilCtrl->isAsynch())
1446  {
1447  $html = $ilCtrl->getHTML($column_gui);
1448  }
1449  }
1450 
1451  return $html;
1452  }
1453 
1457  protected function setColumnSettings($column_gui)
1458  {
1459  global $ilAccess;
1460 
1461  $column_gui->setRepositoryMode(true);
1462  $column_gui->setEnableEdit(false);
1463  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1464  {
1465  $column_gui->setEnableEdit(true);
1466  }
1467  }
1468 
1469  protected function checkPermission($a_perm, $a_cmd = "")
1470  {
1471  global $ilAccess, $lng, $PHP_SELF;
1472 
1473  if (!is_object($this->object))
1474  {
1475  return;
1476  }
1477 
1478  if (!$ilAccess->checkAccess($a_perm, $a_cmd, $this->object->getRefId()))
1479  {
1480  $_SESSION["il_rep_ref_id"] = "";
1481  ilUtil::sendFailure($lng->txt("permission_denied"), true);
1482 
1483  if (!is_int(strpos($PHP_SELF, "goto.php")))
1484  {
1485  ilUtil::redirect("goto.php?target=".$this->object->getType()."_".
1486  $this->object->getRefId());
1487  }
1488  else // we should never be here
1489  {
1490  die("Permission Denied.");
1491  }
1492  }
1493  }
1494 
1495 } // END class.ilObjectGUI (3.10: 2896 loc)
1496 ?>