ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
4 include_once("./Services/Table/classes/class.ilTableGUI.php");
5 include_once("Services/Payment/classes/class.ilPaymentObject.php");
6 
7 
30 {
31  var $lng;
32  var $ilias;
33  var $tpl;
34  var $tree;
37  var $cmd;
38  var $mode;
39  var $ctrl;
40 
45  function ilRepositoryGUI()
46  {
47  global $lng, $ilias, $tpl, $tree, $rbacsystem, $objDefinition,
48  $_GET, $ilCtrl, $ilLog;;
49 //var_dump($_SESSION['il_rep_clipboard']);
50  $this->lng =& $lng;
51  $this->ilias =& $ilias;
52  $this->tpl =& $tpl;
53  $this->tree =& $tree;
54  $this->rbacsystem =& $rbacsystem;
55  $this->objDefinition =& $objDefinition;
56 
57  $this->ctrl =& $ilCtrl;
58 
59  $this->creation_mode = false;
60 
61  $this->ctrl->saveParameter($this, array("ref_id"));
62  if (!ilUtil::isAPICall())
63  $this->ctrl->setReturn($this,"");
64 
65  // determine current ref id and mode
66  if (!empty($_GET["ref_id"]) || $this->ctrl->getCmd() == "showTree")
67  {
68  $this->cur_ref_id = $_GET["ref_id"];
69  }
70  else
71  {
72 //echo "1-".$_SESSION["il_rep_ref_id"]."-";
73  if (!empty($_SESSION["il_rep_ref_id"]) && !empty($_GET["getlast"]))
74  {
75  $this->cur_ref_id = $_SESSION["il_rep_ref_id"];
76 //echo "2-".$this->cur_ref_id."-";
77  }
78  else
79  {
80  $this->cur_ref_id = $this->tree->getRootId();
81 
82  if ($_GET["cmd"] != "" && $_GET["cmd"] != "frameset")
83  {
84 //echo "hhh";
85  $get_str = $post_str = "";
86  foreach($_GET as $key => $value)
87  {
88  $get_str.= "-$key:$value";
89  }
90  foreach($_POST as $key => $value)
91  {
92  $post_str.= "-$key:$value";
93  }
94  $ilLog->write("Repository: command called without ref_id.".
95  "GET:".$get_str."-POST:".$post_str, $ilLog->WARNING);
96  }
97  // #10033
98  $_GET = array("baseClass"=>"ilRepositoryGUI");
99  $_POST = array();
100  $this->ctrl->setCmd("frameset");
101  }
102  }
103 //echo "<br>+".$_GET["ref_id"]."+";
104  if (!$tree->isInTree($this->cur_ref_id) && $this->ctrl->getCmd() != "showTree")
105  {
106  $this->cur_ref_id = $this->tree->getRootId();
107 
108  // check wether command has been called with
109  // item that is not in tree
110  if ($_GET["cmd"] != "" && $_GET["cmd"] != "frameset")
111  {
112  $get_str = $post_str = "";
113  foreach($_GET as $key => $value)
114  {
115  $get_str.= "-$key:$value";
116  }
117  foreach($_POST as $key => $value)
118  {
119  $post_str.= "-$key:$value";
120  }
121  $ilLog->write("Repository: command called with ref_id that is not in tree.".
122  "GET:".$get_str."-POST:".$post_str, $ilLog->WARNING);
123  }
124  $_GET = array();
125  $_POST = array();
126  $this->ctrl->setCmd("frameset");
127  }
128 
129  // set current repository view mode
130  if (!empty($_GET["set_mode"]))
131  {
132  $_SESSION["il_rep_mode"] = $_GET["set_mode"];
133  if ($this->ilias->account->getId() != ANONYMOUS_USER_ID)
134  {
135  $this->ilias->account->writePref("il_rep_mode", $_GET["set_mode"]);
136  }
137  }
138 
139  // get user setting
140  if ($_SESSION["il_rep_mode"] == "")
141  {
142  if ($this->ilias->account->getId() != ANONYMOUS_USER_ID)
143  {
144  $_SESSION["il_rep_mode"] = $this->ilias->account->getPref("il_rep_mode");
145  }
146  }
147 
148  // if nothing set, get default view
149  if ($_SESSION["il_rep_mode"] == "")
150  {
151  $_SESSION["il_rep_mode"] = $this->ilias->getSetting("default_repository_view");
152  }
153 
154  $this->mode = ($_SESSION["il_rep_mode"] != "")
155  ? $_SESSION["il_rep_mode"]
156  : "flat";
157 
158  // store current ref id
159  if ($this->ctrl->getCmd() != "showTree" &&
160  $rbacsystem->checkAccess("read", $this->cur_ref_id))
161  {
162  $type = ilObject::_lookupType($this->cur_ref_id, true);
163  if ($type == "cat" || $type == "grp" || $type == "crs"
164  || $type == "root")
165  {
166  $_SESSION["il_rep_ref_id"] = $this->cur_ref_id;
167  }
168  }
169 
170  $_GET["ref_id"] = $this->cur_ref_id;
171 
172  }
173 
174 
178  function &executeCommand()
179  {
180  global $rbacsystem, $ilias, $lng, $ilCtrl, $ilHelp;
181 
182  // check creation mode
183  // determined by "new_type" parameter
184  $new_type = ($_POST["new_type"] != "" && $ilCtrl->getCmd() == "create")
185  ? $_POST["new_type"]
186  : $_GET["new_type"];
187 
188  if ($new_type != "" && $new_type != "sty")
189  {
190  $this->creation_mode = true;
191  $ilHelp->setScreenIdComponent($new_type);
192  $ilHelp->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, "create");
193  }
194 
195  // handle frameset command
196  $cmd = $this->ctrl->getCmd();
197  if (($cmd == "frameset" || $_GET["rep_frame"] == 1) && $_SESSION["il_rep_mode"] == "tree")
198  {
199  $next_class = "";
200  $cmd = "frameset";
201  }
202  else if ($cmd == "frameset" && $_SESSION["il_rep_mode"] != "tree")
203  {
204  $this->ctrl->setCmd("");
205  $cmd = "";
206  }
207 
208  // determine next class
209  if ($cmd != "frameset")
210  {
211  if ($this->creation_mode)
212  {
213  $obj_type = $new_type;
214  $class_name = $this->objDefinition->getClassName($obj_type);
215  if (strtolower($class_name) != "user")
216  {
217  $next_class = strtolower("ilObj".$class_name."GUI");
218  }
219  else
220  {
221  $next_class = $this->ctrl->getNextClass();
222  }
223  // Only set the fixed cmdClass if the next class is different to
224  // the GUI class of the new object.
225  // An example:
226  // Copy Category uses this call structure:
227  // RespositoryGUI -> CategoryGUI -> ilObjectCopyGUI
228  // Without this fix, the cmdClass ilObjectCopyGUI would never be reached
229 
230  ilLoggerFactory::getLogger('obj')->debug($this->ctrl->getNextClass().' <-> '. $class_name);
231 
232  if($this->ctrl->getNextClass() != strtolower('ilObj'.$class_name.'GUI'))
233  {
234  $this->ctrl->setCmdClass($next_class);
235  }
236  }
237  else if ((($next_class = $this->ctrl->getNextClass($this)) == "")
238  || ($next_class == "ilrepositorygui" && $this->ctrl->getCmd() == "return"))
239  {
240  if ($cmd != "frameset" && $cmd != "showTree")
241  {
242  // get GUI of current object
243  $obj_type = ilObject::_lookupType($this->cur_ref_id,true);
244  $class_name = $this->objDefinition->getClassName($obj_type);
245  $next_class = strtolower("ilObj".$class_name."GUI");
246 
247  $this->ctrl->setCmdClass($next_class);
248  if ($this->ctrl->getCmd() == "return")
249  {
250  $this->ctrl->setCmd("");
251  }
252  }
253  }
254  }
255 
256  // commands that are always handled by repository gui
257  // to do: move to container
258  //if ($cmd == "showTree" || $cmd == "linkSelector" || $cmd == "linkChilds")
259  if ($cmd == "showTree")
260  {
261  $next_class = "";
262  }
263 
264  switch ($next_class)
265  {
266  default:
267  // forward all other classes to gui commands
268  if ($next_class != "" && $next_class != "ilrepositorygui")
269  {
270  $class_path = $this->ctrl->lookupClassPath($next_class);
271  // get gui class instance
272  require_once($class_path);
273  $class_name = $this->ctrl->getClassForClasspath($class_path);
274  if (!$this->creation_mode)
275  {
276  if(is_subclass_of($class_name, "ilObject2GUI"))
277  {
278  $this->gui_obj = new $class_name($this->cur_ref_id, ilObject2GUI::REPOSITORY_NODE_ID);
279  }
280  else
281  {
282  $this->gui_obj = new $class_name("", $this->cur_ref_id, true, false);
283  }
284  }
285  else
286  {
287  if(is_subclass_of($class_name, "ilObject2GUI"))
288  {
289  $this->gui_obj = new $class_name(null, ilObject2GUI::REPOSITORY_NODE_ID, $this->cur_ref_id);
290  }
291  else
292  {
293  $this->gui_obj = new $class_name("", 0, true, false);
294  }
295  }
296  //$this->gui_obj = new $class_name("", $this->cur_ref_id, true, false);
297 
298 
299  $tabs_out = ($new_type == "")
300  ? true
301  : false;
302  $this->gui_obj->setCreationMode($this->creation_mode);
303  $this->ctrl->setReturn($this, "return");
304 
305  $this->show();
306  }
307  else //
308  {
309  // process repository frameset
310  if ($cmd == "frameset")
311  {
312  if ($_SESSION["il_rep_mode"] == "tree")
313  {
314  $this->frameset();
315  return;
316  }
317  $cmd = "";
318  $this->ctrl->setCmd("");
319  }
320 
321  // process tree command
322  if ($cmd == "showTree")
323  {
324  $this->showTree();
325  return;
326  }
327 
328  $cmd = $this->ctrl->getCmd("");
329 
330  // check read access for category
331  if ($this->cur_ref_id > 0 && !$rbacsystem->checkAccess("read", $this->cur_ref_id))
332  {
333  $_SESSION["il_rep_ref_id"] = "";
334  $ilias->raiseError($lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
335  $this->tpl->show();
336  }
337  else
338  {
339  $this->cmd = $cmd;
340  $this->$cmd();
341  }
342  }
343  break;
344  }
345  }
346 
347 
348  function show()
349  {
350  // normal command processing
351  $ret =& $this->ctrl->forwardCommand($this->gui_obj);
352  $this->tpl->setVariable("OBJECTS", $this->gui_obj->getHTML());
353 
354  $this->tpl->show();
355  }
356 
360  function frameset()
361  {
362  global $lng, $ilCtrl, $ilAccess;
363 
364 $ilCtrl->redirectByClass("ilrepositorygui", "");
365 
366  include_once("Services/Frameset/classes/class.ilFramesetGUI.php");
367  $fs_gui = new ilFramesetGUI();
368 
369  if ($_GET["rep_frame"] == 1)
370  {
371  // workaround for passing anchors (e.g. used in ilNoteGUI)
372  $anchor = ($_GET["anchor"] != "")
373  ? "#".$_GET["anchor"]
374  : "";
375  $fs_gui->setMainFrameSource(
376  str_replace("rep_frame", "rep_frame_done", $_SERVER["REQUEST_URI"]).$anchor);
377  }
378  else
379  {
380  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->cur_ref_id);
381  $ilCtrl->setParameterByClass("ilrepositorygui", "getlast", "true");
382  if ($ilAccess->checkAccess("read", "", $this->cur_ref_id))
383  {
384  $fs_gui->setMainFrameSource(
385  $ilCtrl->getLinkTargetByClass("ilrepositorygui", ""));
386  }
387  else
388  {
389  // if no read permission is given, do not display frameset
390  // see bug http://www.ilias.de/mantis/view.php?id=10305
391  $ilCtrl->redirectByClass("ilrepositorygui", "");
392  }
393  $ilCtrl->clearParametersByClass("ilrepositorygui");
394  }
395  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->cur_ref_id);
396  $fs_gui->setSideFrameSource(
397  $ilCtrl->getLinkTargetByClass("ilrepositorygui", "showTree"));
398  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
399 
400  $fs_gui->setSideFrameName("tree");
401  $fs_gui->setMainFrameName("rep_content");
402  $fs_gui->setFramesetTitle($this->lng->txt("repository"));
403  $fs_gui->show();
404  exit;
405  }
406 
407 
411  function showTree()
412  {
413  global $ilCtrl, $tree, $ilSetting, $lng;
414 
415  $ilCtrl->setParameter($this, "active_node", $_GET["active_node"]);
416 
417  $this->tpl = new ilTemplate("tpl.main.html", true, true);
418  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
419 
420  $this->tpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
421 
422  include_once ("./Services/Repository/classes/class.ilRepositoryExplorer.php");
423 
424  $active_node = ($_GET["active_node"] > 1)
425  ? $_GET["active_node"]
426  : ($_GET["ref_id"] > 1)
427  ? $_GET["ref_id"]
428  : 0;
429  $top_node = 0;
430  if ($ilSetting->get("rep_tree_limit_grp_crs") && $active_node > 0)
431  {
432  $path = $tree->getPathId($active_node);
433  foreach ($path as $n)
434  {
435  if ($top_node > 0)
436  {
437  break;
438  }
440  array("crs", "grp")))
441  {
442  $top_node = $n;
443  }
444  }
445  }
446 
447  $exp = new ilRepositoryExplorer("ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto", $top_node);
448  $exp->setUseStandardFrame(false);
449  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, "showTree"));
450  $exp->setFrameUpdater("tree", "updater");
451  $exp->setTargetGet("ref_id");
452 
453  if ($_GET["repexpand"] == "")
454  {
455  $expanded = $this->tree->readRootId();
456  }
457  else
458  {
459  $expanded = $_GET["repexpand"];
460  }
461 
462  $exp->setExpand($expanded);
463 
464  if ($active_node > 0)
465  {
466  $path = $tree->getPathId($active_node);
467  if ($top_node > 0)
468  {
469  $exp->setForceOpenPath($path);
470  $exp->setExpand($expanded);
471  }
472  else
473  {
474  $exp->setForceOpenPath($path + array($top_node));
475  }
476  $exp->highlightNode($active_node);
477  }
478 
479  // build html-output
480  if ($top_node > 0)
481  {
482  $head_tpl = new ilTemplate("tpl.cont_tree_head.html", true, true,
483  "Services/Repository");
484  $path = ilObject::_getIcon(ROOT_FOLDER_ID, "tiny", "root");
485  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
486  $title = $nd["title"];
487  if ($title == "ILIAS")
488  {
489  $title = $lng->txt("repository");
490  }
491  $head_tpl->setVariable("IMG_SRC", $path);
492  $head_tpl->setVariable("ALT_IMG", $lng->txt("icon")." ".$title);
493  $head_tpl->setVariable("LINK_TXT", $title);
494  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", "1");
495  $head_tpl->setVariable("LINK_HREF",
496  $ilCtrl->getLinkTargetByClass("ilrepositorygui", "frameset"));
497  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
498  $exp->setTreeLead($head_tpl->get());
499 
500  $exp->initItemCounter(1);
501  $exp->setOutput($tree->getParentId($top_node), 1,
502  ilObject::_lookupObjId($tree->getParentId($top_node)));
503  }
504  else
505  {
506  $exp->setOutput(0);
507  }
508  $output = $exp->getOutput(false);
509 
510 //if ($GLOBALS["ilUser"]->getLogin() == "alex") echo "topnode:$top_node:activenode:$active_node:";
511 
512 
513  // asynchronous output
514  if ($ilCtrl->isAsynch())
515  {
516  echo $output; exit;
517  }
518 
519  $this->tpl->setCurrentBlock("content");
520  $this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("overview"));
521  $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
522  $this->tpl->setVariable("EXPLORER",$output);
523  $ilCtrl->setParameter($this, "repexpand", $_GET["repexpand"]);
524  $this->tpl->setVariable("ACTION", $ilCtrl->getLinkTarget($this, "showTree", "", false, false));
525  $this->tpl->parseCurrentBlock();
526 
527  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
528  iljQueryUtil::initjQuery($this->tpl);
529 
530  $this->tpl->show(false);
531  exit;
532  }
533 
534 } // END class.ilRepository
535 
536 
537 ?>
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
exit
Definition: login.php:54
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$_POST['username']
Definition: cron.php:12
$_SESSION["AccountId"]
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
Class ilRepositoryGUI.
& executeCommand()
execute command
global $ilCtrl
Definition: ilias.php:18
$nd
Definition: error.php:11
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
redirection script todo: (a better solution should control the processing via a xml file) ...
$n
Definition: RandomTest.php:80
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilSetting
Definition: privfeed.php:40
$path
Definition: index.php:22
ilRepositoryGUI()
Constructor public.
static initjQuery($a_tpl=null)
Init jQuery.
static getLogger($a_component_id)
Get component logger.
showTree()
display tree view
const ID_PART_SCREEN
frameset()
output tree frameset
static isAPICall()
Class ilFramesetGUI.