ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilRepositoryGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
6include_once("./Services/Table/classes/class.ilTableGUI.php");
7
8
35{
39 protected $objDefinition;
40
44 protected $log;
45
49 protected $user;
50
54 protected $settings;
55
59 protected $help;
60
64 protected $error;
65
69 protected $access;
73 protected $tool_context;
74
75 public $lng;
76 public $tpl;
77 public $tree;
80 public $cmd;
81 public $mode;
82 public $ctrl;
83 private $http;
84
89 public function __construct()
90 {
91 global $DIC;
92
93 $this->log = $DIC["ilLog"];
94 $this->user = $DIC->user();
95 $this->settings = $DIC->settings();
96 $this->help = $DIC["ilHelp"];
97 $this->error = $DIC["ilErr"];
98 $this->access = $DIC->access();
99 $lng = $DIC->language();
100 $tpl = $DIC["tpl"];
101 $tree = $DIC->repositoryTree();
102 $rbacsystem = $DIC->rbac()->system();
103 $objDefinition = $DIC["objDefinition"];
104 $ilCtrl = $DIC->ctrl();
105 $ilLog = $DIC["ilLog"];
106 $ilUser = $DIC->user();
107 $ilSetting = $DIC->settings();
108 $this->tool_context = $DIC->globalScreen()->tool()->context();
109 $this->http = $DIC->http();
110
111 $this->lng = $lng;
112 $this->tpl = $tpl;
113 $this->tree = $tree;
114 $this->rbacsystem = $rbacsystem;
115 $this->objDefinition = $objDefinition;
116
117 $this->ctrl = $ilCtrl;
118
119 $this->creation_mode = false;
120
121 $this->ctrl->saveParameter($this, array("ref_id"));
122 if (!ilUtil::isAPICall()) {
123 $this->ctrl->setReturn($this, "");
124 }
125
126 // determine current ref id and mode
127 if (!empty($_GET["ref_id"]) || $this->ctrl->getCmd() == "showTree") {
128 $this->cur_ref_id = $_GET["ref_id"];
129 } else {
130 //echo "1-".$_SESSION["il_rep_ref_id"]."-";
131 if (!empty($_SESSION["il_rep_ref_id"]) && !empty($_GET["getlast"])) {
132 $this->cur_ref_id = $_SESSION["il_rep_ref_id"];
133 //echo "2-".$this->cur_ref_id."-";
134 } else {
135 $this->cur_ref_id = $this->tree->getRootId();
136
137 if ($_GET["cmd"] != "" && $_GET["cmd"] != "frameset") {
138 //echo "hhh";
139 $get_str = $post_str = "";
140 foreach ($_GET as $key => $value) {
141 $get_str .= "-$key:$value";
142 }
143 foreach ($_POST as $key => $value) {
144 $post_str .= "-$key:$value";
145 }
146 $ilLog->write("Repository: command called without ref_id." .
147 "GET:" . $get_str . "-POST:" . $post_str, $ilLog->WARNING);
148 }
149 // #10033
150 $_GET = array("baseClass" => "ilRepositoryGUI");
151 $_POST = array();
152 $this->ctrl->setCmd("frameset");
153 }
154 }
155 //echo "<br>+".$_GET["ref_id"]."+";
156 if (!$tree->isInTree($this->cur_ref_id) && $this->ctrl->getCmd() != "showTree") {
157 $this->cur_ref_id = $this->tree->getRootId();
158
159 // check wether command has been called with
160 // item that is not in tree
161 if ($_GET["cmd"] != "" && $_GET["cmd"] != "frameset") {
162 $get_str = $post_str = "";
163 foreach ($_GET as $key => $value) {
164 $get_str .= "-$key:$value";
165 }
166 foreach ($_POST as $key => $value) {
167 $post_str .= "-$key:$value";
168 }
169 $ilLog->write("Repository: command called with ref_id that is not in tree." .
170 "GET:" . $get_str . "-POST:" . $post_str, $ilLog->WARNING);
171 }
172 $_GET = array();
173 $_POST = array();
174 $this->ctrl->setCmd("frameset");
175 }
176
177 // set current repository view mode
178 if (!empty($_GET["set_mode"])) {
179 $_SESSION["il_rep_mode"] = $_GET["set_mode"];
180 if ($ilUser->getId() != ANONYMOUS_USER_ID) {
181 $ilUser->writePref("il_rep_mode", $_GET["set_mode"]);
182 }
183 }
184
185 // get user setting
186 if ($_SESSION["il_rep_mode"] == "") {
187 if ($ilUser->getId() != ANONYMOUS_USER_ID) {
188 $_SESSION["il_rep_mode"] = $ilUser->getPref("il_rep_mode");
189 }
190 }
191
192 // if nothing set, get default view
193 if ($_SESSION["il_rep_mode"] == "") {
194 $_SESSION["il_rep_mode"] = $ilSetting->get("default_repository_view");
195 }
196
197 $this->mode = ($_SESSION["il_rep_mode"] != "")
198 ? $_SESSION["il_rep_mode"]
199 : "flat";
200
201 // store current ref id
202 if ($this->ctrl->getCmd() != "showTree" &&
203 $rbacsystem->checkAccess("read", $this->cur_ref_id)) {
204 $type = ilObject::_lookupType($this->cur_ref_id, true);
205 if ($type == "cat" || $type == "grp" || $type == "crs"
206 || $type == "root") {
207 $_SESSION["il_rep_ref_id"] = $this->cur_ref_id;
208 }
209 }
210
211 $_GET["ref_id"] = $this->cur_ref_id;
212 }
213
214
218 public function executeCommand()
219 {
222 $ilCtrl = $this->ctrl;
223 $ilHelp = $this->help;
225
226 if (
227 ($this->user->isAnonymous() || !($this->user->getId() >= 1)) &&
228 !ilPublicSectionSettings::getInstance()->isEnabledForDomain(
229 $this->http->request()->getServerParams()['SERVER_NAME']
230 )
231 ) {
232 $this->ctrl->redirectToURL('./login.php?cmd=force_login');
233 }
234
235 $this->tool_context->claim()->repository();
236 $show_tree = ($_SESSION["il_rep_mode"] == "flat")
237 ? true
238 : false;
239
240 // check creation mode
241 // determined by "new_type" parameter
242 $new_type = ($_POST["new_type"] != "" && $ilCtrl->getCmd() == "create")
243 ? $_POST["new_type"]
244 : $_GET["new_type"];
245
246 if ($new_type != "" && $new_type != "sty") {
247 $this->creation_mode = true;
248 $ilHelp->setScreenIdComponent($new_type);
249 $ilHelp->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, "create");
250 }
251
252 // handle frameset command
253 $cmd = $this->ctrl->getCmd();
254 if (($cmd == "frameset" || $_GET["rep_frame"] == 1) && $_SESSION["il_rep_mode"] == "tree") {
255 $next_class = "";
256 $cmd = "frameset";
257 } elseif ($cmd == "frameset" && $_SESSION["il_rep_mode"] != "tree") {
258 $this->ctrl->setCmd("");
259 $cmd = "";
260 }
261
262
263 // determine next class
264 if ($cmd != "frameset") {
265 if ($this->creation_mode) {
266 $obj_type = $new_type;
267 $class_name = $this->objDefinition->getClassName($obj_type);
268 if (strtolower($class_name) != "user") {
269 $next_class = strtolower("ilObj" . $class_name . "GUI");
270 } else {
271 $next_class = $this->ctrl->getNextClass();
272 }
273 // Only set the fixed cmdClass if the next class is different to
274 // the GUI class of the new object.
275 // An example:
276 // Copy Category uses this call structure:
277 // RespositoryGUI -> CategoryGUI -> ilObjectCopyGUI
278 // Without this fix, the cmdClass ilObjectCopyGUI would never be reached
279
280 ilLoggerFactory::getLogger('obj')->debug($this->ctrl->getNextClass() . ' <-> ' . $class_name);
281
282 if ($this->ctrl->getNextClass() != strtolower('ilObj' . $class_name . 'GUI')) {
283 $this->ctrl->setCmdClass($next_class);
284 }
285 } elseif ((($next_class = $this->ctrl->getNextClass($this)) == "")
286 || ($next_class == "ilrepositorygui" && $this->ctrl->getCmd() == "return")) {
287 if ($cmd != "frameset" && $cmd != "showTree") {
288 // get GUI of current object
289 $obj_type = ilObject::_lookupType($this->cur_ref_id, true);
290 $class_name = $this->objDefinition->getClassName($obj_type);
291 $next_class = strtolower("ilObj" . $class_name . "GUI");
292
293 $this->ctrl->setCmdClass($next_class);
294 if ($this->ctrl->getCmd() == "return") {
295 $this->ctrl->setCmd("");
296 }
297 }
298 }
299 }
300
301 // commands that are always handled by repository gui
302 // to do: move to container
303 if ($cmd == "showRepTree") {
304 $next_class = "";
305 }
306
307 switch ($next_class) {
308 default:
309 // forward all other classes to gui commands
310 if ($next_class != "" && $next_class != "ilrepositorygui") {
311 $class_path = $this->ctrl->lookupClassPath($next_class);
312 // get gui class instance
313 require_once($class_path);
314 $class_name = $this->ctrl->getClassForClasspath($class_path);
315 if (!$this->creation_mode) {
316 if (is_subclass_of($class_name, "ilObject2GUI")) {
317 $this->gui_obj = new $class_name($this->cur_ref_id, ilObject2GUI::REPOSITORY_NODE_ID);
318 } else {
319 $this->gui_obj = new $class_name("", $this->cur_ref_id, true, false);
320 }
321 } else {
322 if (is_subclass_of($class_name, "ilObject2GUI")) {
323 $this->gui_obj = new $class_name(null, ilObject2GUI::REPOSITORY_NODE_ID, $this->cur_ref_id);
324 } else {
325 $this->gui_obj = new $class_name("", 0, true, false);
326 }
327 }
328 //$this->gui_obj = new $class_name("", $this->cur_ref_id, true, false);
329
330
331 $tabs_out = ($new_type == "")
332 ? true
333 : false;
334 $this->gui_obj->setCreationMode($this->creation_mode);
335 $this->ctrl->setReturn($this, "return");
336
337 $this->show();
338 } else { //
339 // process repository frameset
340 if ($cmd == "frameset") {
341 if ($_SESSION["il_rep_mode"] == "tree") {
342 $this->frameset();
343 return;
344 }
345 $cmd = "";
346 $this->ctrl->setCmd("");
347 }
348
349 // process tree command
350 if ($cmd == "showTree") {
351 $this->showTree();
352 return;
353 }
354
355 $cmd = $this->ctrl->getCmd("");
356
357 // check read access for category
358 if ($this->cur_ref_id > 0 && !$rbacsystem->checkAccess("read", $this->cur_ref_id) && $cmd != "showRepTree") {
359 $_SESSION["il_rep_ref_id"] = "";
360 $ilErr->raiseError($lng->txt("permission_denied"), $ilErr->MESSAGE);
361 $this->tpl->printToStdout();
362 } else {
363 $this->cmd = $cmd;
364 $this->$cmd();
365 }
366 }
367 break;
368 }
369 }
370
371
372 public function show()
373 {
374 // normal command processing
375 $ret = $this->ctrl->forwardCommand($this->gui_obj);
376 $this->tpl->setVariable("OBJECTS", $this->gui_obj->getHTML());
377 $this->tpl->printToStdout();
378 }
379
383 public function frameset()
384 {
386 $ilCtrl = $this->ctrl;
387 $ilAccess = $this->access;
388
389 $ilCtrl->redirectByClass("ilrepositorygui", "");
390 }
391
392
396 public function showTree()
397 {
398 $ilCtrl = $this->ctrl;
402
403 $ilCtrl->setParameter($this, "active_node", $_GET["active_node"]);
404
405 $this->tpl = new ilGlobalTemplate("tpl.main.html", true, true);
406 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
407
408 $this->tpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
409
410 include_once("./Services/Repository/classes/class.ilRepositoryExplorer.php");
411
412 $active_node = ($_GET["active_node"] > 1)
413 ? $_GET["active_node"]
414 : (($_GET["ref_id"] > 1)
415 ? $_GET["ref_id"]
416 : 0);
417 $top_node = 0;
418 if ($ilSetting->get("rep_tree_limit_grp_crs") && $active_node > 0) {
419 $path = $tree->getPathId($active_node);
420 foreach ($path as $n) {
421 if ($top_node > 0) {
422 break;
423 }
424 if (in_array(
426 array("crs", "grp")
427 )) {
428 $top_node = $n;
429 }
430 }
431 }
432
433 $exp = new ilRepositoryExplorer("ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto", $top_node);
434 $exp->setUseStandardFrame(false);
435 $exp->setExpandTarget($ilCtrl->getLinkTarget($this, "showTree"));
436 $exp->setFrameUpdater("tree", "updater");
437 $exp->setTargetGet("ref_id");
438
439 if ($_GET["repexpand"] == "") {
440 $expanded = $this->tree->readRootId();
441 } else {
442 $expanded = $_GET["repexpand"];
443 }
444
445 $exp->setExpand($expanded);
446
447 if ($active_node > 0) {
448 $path = $tree->getPathId($active_node);
449 if ($top_node > 0) {
450 $exp->setForceOpenPath($path);
451 $exp->setExpand($expanded);
452 } else {
453 $exp->setForceOpenPath($path + array($top_node));
454 }
455 $exp->highlightNode($active_node);
456 }
457
458 // build html-output
459 if ($top_node > 0) {
460 $head_tpl = new ilTemplate(
461 "tpl.cont_tree_head.html",
462 true,
463 true,
464 "Services/Repository"
465 );
466 $path = ilObject::_getIcon(ROOT_FOLDER_ID, "tiny", "root");
467 $nd = $tree->getNodeData(ROOT_FOLDER_ID);
468 $title = $nd["title"];
469 if ($title == "ILIAS") {
470 $title = $lng->txt("repository");
471 }
472 $head_tpl->setVariable("IMG_SRC", $path);
473 $head_tpl->setVariable("ALT_IMG", $lng->txt("icon") . " " . $title);
474 $head_tpl->setVariable("LINK_TXT", $title);
475 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", "1");
476 $head_tpl->setVariable(
477 "LINK_HREF",
478 $ilCtrl->getLinkTargetByClass("ilrepositorygui", "frameset")
479 );
480 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
481 $exp->setTreeLead($head_tpl->get());
482
483 $exp->initItemCounter(1);
484 $exp->setOutput(
485 $tree->getParentId($top_node),
486 1,
487 ilObject::_lookupObjId($tree->getParentId($top_node))
488 );
489 } else {
490 $exp->setOutput(0);
491 }
492 $output = $exp->getOutput(false);
493
494 //if ($GLOBALS["ilUser"]->getLogin() == "alex") echo "topnode:$top_node:activenode:$active_node:";
495
496
497 // asynchronous output
498 if ($ilCtrl->isAsynch()) {
499 echo $output;
500 exit;
501 }
502
503 $this->tpl->setCurrentBlock("content");
504 $this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("overview"));
505 $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
506 $this->tpl->setVariable("EXPLORER", $output);
507 $ilCtrl->setParameter($this, "repexpand", $_GET["repexpand"]);
508 $this->tpl->setVariable("ACTION", $ilCtrl->getLinkTarget($this, "showTree", "", false, false));
509 $this->tpl->parseCurrentBlock();
510
511 include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
512 iljQueryUtil::initjQuery($this->tpl);
513
514 $this->tpl->printToStdout(false);
515 exit;
516 }
517
521 public function showRepTree()
522 {
523 $exp = new ilRepositoryExplorerGUI($this, "showRepTree");
524 // root node should be skipped, see #26787
525 $exp->setSkipRootNode(true);
526 $exp->handleCommand();
527 exit;
528 }
529} // END class.ilRepository
user()
Definition: user.php:4
$n
Definition: RandomTest.php:85
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
special template class to simplify handling of ITX/PEAR
const ID_PART_SCREEN
static getLogger($a_component_id)
Get component logger.
static _lookupObjId($a_id)
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _lookupType($a_id, $a_reference=false)
lookup object type
Repository explorer GUI class.
Class ilRepositoryGUI.
frameset()
output tree frameset
__construct()
Constructor @access public.
executeCommand()
execute command
showTree()
display tree view
special template class to simplify handling of ITX/PEAR
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static isAPICall()
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
const ANONYMOUS_USER_ID
Definition: constants.php:25
const ROOT_FOLDER_ID
Definition: constants.php:30
$nd
Definition: error.php:12
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$ilUser
Definition: imgupload.php:18
exit
Definition: login.php:29
static http()
Fetches the global http state from ILIAS.
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
$type
$ilErr
Definition: raiseError.php:18
settings()
Definition: settings.php:2