ILIAS  eassessment Revision 61809
 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("classes/class.ilTabsGUI.php");
6 include_once("Services/Payment/classes/class.ilPaymentObject.php");
7 
8 
27 {
28  var $lng;
29  var $ilias;
30  var $tpl;
31  var $tree;
34  var $cmd;
35  var $mode;
36  var $ctrl;
37 
42  function ilRepositoryGUI()
43  {
44  global $lng, $ilias, $tpl, $tree, $rbacsystem, $objDefinition,
45  $_GET, $ilCtrl, $ilLog;;
46 //var_dump($_SESSION['il_rep_clipboard']);
47  $this->lng =& $lng;
48  $this->ilias =& $ilias;
49  $this->tpl =& $tpl;
50  $this->tree =& $tree;
51  $this->rbacsystem =& $rbacsystem;
52  $this->objDefinition =& $objDefinition;
53 
54  $this->ctrl =& $ilCtrl;
55 
56  $this->creation_mode = false;
57 
58  $this->ctrl->saveParameter($this, array("ref_id"));
59  if (!ilUtil::isAPICall())
60  $this->ctrl->setReturn($this,"");
61 
62  // determine current ref id and mode
63  if (!empty($_GET["ref_id"]) || $this->ctrl->getCmd() == "showTree")
64  {
65  $this->cur_ref_id = $_GET["ref_id"];
66  }
67  else
68  {
69 //echo "1-".$_SESSION["il_rep_ref_id"]."-";
70  if (!empty($_SESSION["il_rep_ref_id"]) && !empty($_GET["getlast"]))
71  {
72  $this->cur_ref_id = $_SESSION["il_rep_ref_id"];
73 //echo "2-".$this->cur_ref_id."-";
74  }
75  else
76  {
77  $this->cur_ref_id = $this->tree->getRootId();
78 
79  if ($_GET["cmd"] != "" && $_GET["cmd"] != "frameset")
80  {
81 //echo "hhh";
82  $get_str = $post_str = "";
83  foreach($_GET as $key => $value)
84  {
85  $get_str.= "-$key:$value";
86  }
87  foreach($_POST as $key => $value)
88  {
89  $post_str.= "-$key:$value";
90  }
91  $ilLog->write("Repository: command called without ref_id.".
92  "GET:".$get_str."-POST:".$post_str, $ilLog->WARNING);
93  }
94  $_GET = array();
95  $_POST = array();
96  $this->ctrl->setCmd("frameset");
97  }
98  }
99 //echo "<br>+".$_GET["ref_id"]."+";
100  if (!$tree->isInTree($this->cur_ref_id) && $this->ctrl->getCmd() != "showTree")
101  {
102  $this->cur_ref_id = $this->tree->getRootId();
103 
104  // check wether command has been called with
105  // item that is not in tree
106  if ($_GET["cmd"] != "" && $_GET["cmd"] != "frameset")
107  {
108  $get_str = $post_str = "";
109  foreach($_GET as $key => $value)
110  {
111  $get_str.= "-$key:$value";
112  }
113  foreach($_POST as $key => $value)
114  {
115  $post_str.= "-$key:$value";
116  }
117  $ilLog->write("Repository: command called with ref_id that is not in tree.".
118  "GET:".$get_str."-POST:".$post_str, $ilLog->WARNING);
119  }
120  $_GET = array();
121  $_POST = array();
122  $this->ctrl->setCmd("frameset");
123  }
124 
125  // set current repository view mode
126  if (!empty($_GET["set_mode"]))
127  {
128  $_SESSION["il_rep_mode"] = $_GET["set_mode"];
129  if ($this->ilias->account->getId() != ANONYMOUS_USER_ID)
130  {
131  $this->ilias->account->writePref("il_rep_mode", $_GET["set_mode"]);
132  }
133  }
134 
135  // get user setting
136  if ($_SESSION["il_rep_mode"] == "")
137  {
138  if ($this->ilias->account->getId() != ANONYMOUS_USER_ID)
139  {
140  $_SESSION["il_rep_mode"] = $this->ilias->account->getPref("il_rep_mode");
141  }
142  }
143 
144  // if nothing set, get default view
145  if ($_SESSION["il_rep_mode"] == "")
146  {
147  $_SESSION["il_rep_mode"] = $this->ilias->getSetting("default_repository_view");
148  }
149 
150  $this->mode = ($_SESSION["il_rep_mode"] != "")
151  ? $_SESSION["il_rep_mode"]
152  : "flat";
153 
154  // store current ref id
155  if ($this->ctrl->getCmd() != "showTree" &&
156  $rbacsystem->checkAccess("read", $this->cur_ref_id))
157  {
158  $type = ilObject::_lookupType($this->cur_ref_id, true);
159  if ($type == "cat" || $type == "grp" || $type == "crs"
160  || $type == "root")
161  {
162  $_SESSION["il_rep_ref_id"] = $this->cur_ref_id;
163  }
164  }
165 
166  $_GET["ref_id"] = $this->cur_ref_id;
167  }
168 
169 
173  function &executeCommand()
174  {
175  global $tree, $rbacsystem, $ilias, $lng, $objDefinition,$ilUser, $ilCtrl;
176 
177  // Check for incomplete profile
178  if($ilUser->getProfileIncomplete())
179  {
180  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
181  }
182 
183  // check whether password of user have to be changed
184  // due to first login or password of user is expired
185  if( $ilUser->isPasswordChangeDemanded() || $ilUser->isPasswordExpired() )
186  {
187  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
188  }
189 
190  // check creation mode
191  // determined by "new_type" parameter
192  $new_type = ($_POST["new_type"] != "" && $ilCtrl->getCmd() == "create")
193  ? $_POST["new_type"]
194  : $_GET["new_type"];
195 
196  if ($new_type != "" && $new_type != "sty")
197  {
198  $this->creation_mode = true;
199  }
200 
201  // handle frameset command
202  $cmd = $this->ctrl->getCmd();
203  if (($cmd == "frameset" || $_GET["rep_frame"] == 1) && $_SESSION["il_rep_mode"] == "tree")
204  {
205  $next_class = "";
206  $cmd = "frameset";
207  }
208  else if ($cmd == "frameset" && $_SESSION["il_rep_mode"] != "tree")
209  {
210  $this->ctrl->setCmd("");
211  $cmd = "";
212  }
213 
214  // determine next class
215  if ($cmd != "frameset")
216  {
217  if ($this->creation_mode)
218  {
219  $obj_type = $new_type;
220  $class_name = $this->objDefinition->getClassName($obj_type);
221  if (strtolower($class_name) != "user")
222  {
223  $next_class = strtolower("ilObj".$class_name."GUI");
224  }
225  else
226  {
227  $next_class = $this->ctrl->getNextClass();
228  }
229  // Only set the fixed cmdClass if the next class is different to
230  // the GUI class of the new object.
231  // An example:
232  // Copy Category uses this call structure:
233  // RespositoryGUI -> CategoryGUI -> ilObjectCopyGUI
234  // Without this fix, the cmdClass ilObjectCopyGUI would never be reached
235  if($this->ctrl->getNextClass() != strtolower('ilObj'.$class_name.'GUI'))
236  {
237  $this->ctrl->setCmdClass($next_class);
238  }
239  }
240  else if ((($next_class = $this->ctrl->getNextClass($this)) == "")
241  || ($next_class == "ilrepositorygui" && $this->ctrl->getCmd() == "return"))
242  {
243  if ($cmd != "frameset" && $cmd != "showTree")
244  {
245  // get GUI of current object
246  $obj_type = ilObject::_lookupType($this->cur_ref_id,true);
247  $class_name = $this->objDefinition->getClassName($obj_type);
248  $next_class = strtolower("ilObj".$class_name."GUI");
249 
250  $this->ctrl->setCmdClass($next_class);
251  if ($this->ctrl->getCmd() == "return")
252  {
253  $this->ctrl->setCmd("");
254  }
255  }
256  }
257  }
258 
259  // commands that are always handled by repository gui
260  // to do: move to container
261  //if ($cmd == "showTree" || $cmd == "linkSelector" || $cmd == "linkChilds")
262  if ($cmd == "showTree")
263  {
264  $next_class = "";
265  }
266 
267  switch ($next_class)
268  {
269 
270  default:
271  // forward all other classes to gui commands
272  if ($next_class != "" && $next_class != "ilrepositorygui")
273  {
274  $class_path = $this->ctrl->lookupClassPath($next_class);
275  // get gui class instance
276  include_once($class_path);
277  $class_name = $this->ctrl->getClassForClasspath($class_path);
278  if (!$this->creation_mode)
279  {
280  $this->gui_obj = new $class_name("", $this->cur_ref_id, true, false);
281  }
282  else
283  {
284  // dirty walkaround for ilinc classrooms which need passed the ref_id of the parent iLinc course
285  if ($class_name == 'ilObjiLincClassroomGUI')
286  {
287  $this->gui_obj = new $class_name("", $this->cur_ref_id, true, false);
288  }
289  else
290  {
291  $this->gui_obj = new $class_name("", 0, true, false);
292  }
293  }
294  //$this->gui_obj = new $class_name("", $this->cur_ref_id, true, false);
295 
296 
297  $tabs_out = ($new_type == "")
298  ? true
299  : false;
300 
301 
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;
363 
364  include_once("Services/Frameset/classes/class.ilFramesetGUI.php");
365  $fs_gui = new ilFramesetGUI();
366 
367  if ($_GET["rep_frame"] == 1)
368  {
369  // workaround for passing anchors (e.g. used in ilNoteGUI)
370  $anchor = ($_GET["anchor"] != "")
371  ? "#".$_GET["anchor"]
372  : "";
373  $fs_gui->setMainFrameSource(
374  str_replace("rep_frame", "rep_frame_done", $_SERVER["REQUEST_URI"]).$anchor);
375  }
376  else
377  {
378  $fs_gui->setMainFrameSource(
379  "repository.php?getlast=true&ref_id=".$this->cur_ref_id);
380  }
381  $fs_gui->setSideFrameSource(
382  "repository.php?cmd=showTree&ref_id=".$this->cur_ref_id);
383 
384  $fs_gui->setSideFrameName("tree");
385  $fs_gui->setMainFrameName("rep_content");
386  $fs_gui->setFramesetTitle($this->lng->txt("repository"));
387  $fs_gui->show();
388  exit;
389  }
390 
391 
395  function showTree()
396  {
397  global $ilCtrl, $tree, $ilSetting, $lng;
398 
399  $ilCtrl->setParameter($this, "active_node", $_GET["active_node"]);
400 
401  $this->tpl = new ilTemplate("tpl.main.html", true, true);
402  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
403 
404  $this->tpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
405 
406  include_once ("./Services/Repository/classes/class.ilRepositoryExplorer.php");
407 
408  $active_node = ($_GET["active_node"] > 1)
409  ? $_GET["active_node"]
410  : ($_GET["ref_id"] > 1)
411  ? $_GET["ref_id"]
412  : 0;
413  $top_node = 0;
414  if ($ilSetting->get("rep_tree_limit_grp_crs") && $active_node > 0)
415  {
416  $path = $tree->getPathId($active_node);
417  foreach ($path as $n)
418  {
419  if ($top_node > 0)
420  {
421  break;
422  }
424  array("crs", "grp")))
425  {
426  $top_node = $n;
427  }
428  }
429  }
430 
431  $exp = new ilRepositoryExplorer("repository.php?cmd=goto", $top_node);
432  $exp->setUseStandardFrame(false);
433  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, "showTree"));
434  $exp->setFrameUpdater("tree", "updater");
435  $exp->setTargetGet("ref_id");
436 
437  if ($_GET["repexpand"] == "")
438  {
439  $expanded = $this->tree->readRootId();
440  }
441  else
442  {
443  $expanded = $_GET["repexpand"];
444  }
445 
446  $exp->setExpand($expanded);
447 
448  if ($active_node > 0)
449  {
450  $path = $tree->getPathId($active_node);
451  if ($top_node > 0)
452  {
453  $exp->setForceOpenPath($path);
454  $exp->setExpand($expanded);
455  }
456  else
457  {
458  $exp->setForceOpenPath($path + array($top_node));
459  }
460  $exp->highlightNode($active_node);
461  }
462 
463  // build html-output
464  if ($top_node > 0)
465  {
466  $head_tpl = new ilTemplate("tpl.cont_tree_head.html", true, true,
467  "Services/Repository");
468  $path = ilObject::_getIcon(ROOT_FOLDER_ID, "tiny", "root");
469  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
470  $title = $nd["title"];
471  if ($title == "ILIAS")
472  {
473  $title = $lng->txt("repository");
474  }
475  $head_tpl->setVariable("IMG_SRC", $path);
476  $head_tpl->setVariable("ALT_IMG", $lng->txt("icon")." ".$title);
477  $head_tpl->setVariable("LINK_TXT", $title);
478  $head_tpl->setVariable("LINK_HREF", "repository.php?cmd=frameset&amp;ref_id=1");
479  $exp->setTreeLead($head_tpl->get());
480 
481  $exp->initItemCounter(1);
482  $exp->setOutput($tree->getParentId($top_node), 1,
483  ilObject::_lookupObjId($tree->getParentId($top_node)));
484  }
485  else
486  {
487  $exp->setOutput(0);
488  }
489  $output = $exp->getOutput(false);
490 
491 //if ($GLOBALS["ilUser"]->getLogin() == "alex") echo "topnode:$top_node:activenode:$active_node:";
492 
493 
494  // asynchronous output
495  if ($ilCtrl->isAsynch())
496  {
497  echo $output; exit;
498  }
499 
500  $this->tpl->setCurrentBlock("content");
501  $this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("overview"));
502  $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
503  $this->tpl->setVariable("EXPLORER",$output);
504  $ilCtrl->setParameter($this, "repexpand", $_GET["repexpand"]);
505  $this->tpl->setVariable("ACTION", $ilCtrl->getLinkTarget($this, "showTree", "", false, false));
506  $this->tpl->parseCurrentBlock();
507  $this->tpl->show(false);
508  exit;
509  }
510 
511 } // END class.ilRepository
512 
513 
514 ?>