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