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