ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCtrl.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
31 class ilCtrl
32 {
33  const IL_RTOKEN_NAME = 'rtoken';
34 
36  var $forward; // forward array
37  var $parent; // parent array (reverse forward)
38  var $save_parameter; // save parameter array
39  var $return; // return commmands
40  var $call_hist = array(); // calling history
41  var $debug = array();
42 
46  function ilCtrl()
47  {
48  global $ilBench;
49 
50  $this->bench =& $ilBench;
51 
52  // initialisation
53  $this->init();
54 
55  // this information should go to xml files one day
56  $this->stored_trees = array
57  ("ilrepositorygui", "ilpersonaldesktopgui",
58  "illmpresentationgui", "illmeditorgui",
59  "iladministrationgui");
60  }
61 
62  function debug($str)
63  {
64 //echo "<br>".$str;
65  $this->debug[] = $str;
66  }
67 
68  function getDebug()
69  {
70  return $this->debug;
71  }
72 
76  function init()
77  {
78  $this->transit = array();
79  $this->forward = array(); // forward array
80  $this->forwards = array(); // forward array
81  $this->parent = array(); // parent array (reverse forward)
82  $this->save_parameter = array(); // save parameter array
83  $this->parameter = array(); // save parameter array
84  $this->return = ""; // return commmands
85  $this->location = array();
86  $this->tab = array();
87  $this->current_node = 0;
88  $this->module_dir = "";
89  $this->service_dir = "";
90  $this->call_node = array();
91  $this->root_class = "";
92  }
93 
103  function callBaseClass()
104  {
105  global $ilDB;
106 
107  $baseClass = strtolower($_GET["baseClass"]);
108 
109  // get class information
110  $q = "SELECT * FROM module_class WHERE LOWER(class) = ".
111  $ilDB->quote($baseClass);
112  $mc_set = $ilDB->query($q);
113  $mc_rec = $mc_set->fetchRow(DB_FETCHMODE_ASSOC);
114  $module = $mc_rec["module"];
115  $class = $mc_rec["class"];
116  $class_dir = $mc_rec["dir"];
117 
118  if ($module != "")
119  {
120  // get module information
121  $q = "SELECT * FROM il_component WHERE name = ".
122  $ilDB->quote($module);
123 
124  $m_set = $ilDB->query($q);
125  $m_rec = $m_set->fetchRow(DB_FETCHMODE_ASSOC);
126  $this->module_dir = $m_rec["type"]."/".$m_rec["name"];
127  include_once $this->module_dir."/".$class_dir."/class.".$class.".php";
128  }
129  else // check whether class belongs to a service
130  {
131  // get class information
132  $q = "SELECT * FROM service_class WHERE LOWER(class) = ".
133  $ilDB->quote($baseClass);
134 
135  $mc_set = $ilDB->query($q);
136  $mc_rec = $mc_set->fetchRow(DB_FETCHMODE_ASSOC);
137  $service = $mc_rec["service"];
138  $class = $mc_rec["class"];
139  $class_dir = $mc_rec["dir"];
140 
141  if ($service == "")
142  {
143  echo "Could not find entry in modules.xml or services.xml for".
144  $baseClass;
145  exit;
146  }
147 
148  // get service information
149  $q = "SELECT * FROM il_component WHERE name = ".
150  $ilDB->quote($service);
151 
152  $m_set = $ilDB->query($q);
153  $m_rec = $m_set->fetchRow(DB_FETCHMODE_ASSOC);
154  $this->service_dir = $m_rec["type"]."/".$m_rec["name"];
155 
156  include_once $this->service_dir."/".$class_dir."/class.".$class.".php";;
157  }
158 
159  // forward processing to base class
160  $this->getCallStructure(strtolower($baseClass));
161  $base_class_gui =& new $class();
162  $this->forwardCommand($base_class_gui);
163  }
164 
168  function getModuleDir()
169  {
170  return $this->module_dir;
171  }
172 
184  function &forwardCommand(&$a_gui_object)
185  {
186  $class = strtolower(get_class($a_gui_object));
187 
188  $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
189  if ($nr > 0)
190  {
191  $current_node = $this->current_node;
192 
193  $this->current_node = $nr;
194 
195  if (DEVMODE == "1")
196  {
197  $this->call_hist[] = array("class" => get_class($a_gui_object),
198  "mode" => "execComm", "cmd" => $this->getCmd());
199  }
200 
201  $html = $a_gui_object->executeCommand();
202 
203  // reset current node
204  $this->current_node = $current_node;
205 
206  return $html;
207 
208  }
209  echo "ERROR: Can't forward to class $class."; exit;
210 //echo "end forward<br>";
211  }
212 
222  function &getHTML(&$a_gui_object)
223  {
224  $class = strtolower(get_class($a_gui_object));
225 
226  $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
227  if ($nr > 0)
228  {
229  $current_node = $this->current_node;
230 
231  // set current node to new gui class
232  $this->current_node = $nr;
233 
234  if (DEVMODE == "1")
235  {
236  $this->call_hist[] = array("class" => get_class($a_gui_object),
237  "mode" => "getHtml", "cmd" => $this->getCmd());
238  }
239 
240  // get block
241  $html = $a_gui_object->getHTML();
242 
243  // reset current node
244  $this->current_node = $current_node;
245 
246  // return block
247  return $html;
248  }
249  echo "ERROR: Can't getHTML from class $class."; exit;
250  }
251 
255  function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = "")
256  {
257  $this->context_obj_id = $a_obj_id;
258  $this->context_obj_type = $a_obj_type;
259  $this->context_sub_obj_id = $a_sub_obj_id;
260  $this->context_sub_obj_type = $a_sub_obj_type;
261  }
262 
268  public function getContextObjId()
269  {
270  return $this->context_obj_id;
271  }
272 
278  public function getContextObjType()
279  {
280  return $this->context_obj_type;
281  }
282 
288  public function getContextSubObjId()
289  {
290  return $this->context_sub_obj_id;
291  }
292 
298  public function getContextSubObjType()
299  {
300  return $this->context_sub_obj_type;
301  }
302 
324  function getNodeIdForTargetClass($a_par_node, $a_class)
325  {
326  $class = strtolower($a_class);
327 
328  // target class is class of current node id
329  if ($class == $this->call_node[$a_par_node]["class"])
330  {
331  return $a_par_node;
332  }
333 
334  // target class is child of current node id
335  foreach($this->call_node as $nr => $node)
336  {
337  if (($node["parent"] == $a_par_node) &&
338  ($node["class"] == $class))
339  {
340  return $nr;
341  }
342  }
343 
344  // target class is sibling
345  $par = $this->call_node[$a_par_node]["parent"];
346  if ($par != 0)
347  {
348  foreach($this->call_node as $nr => $node)
349  {
350  if (($node["parent"] == $par) &&
351  ($node["class"] == $class))
352  {
353  return $nr;
354  }
355  }
356  }
357 
358  // target class is parent
359  while($par != 0)
360  {
361  if ($this->call_node[$par]["class"] == $class)
362  {
363  return $par;
364  }
365  $par = $this->call_node[$par]["parent"];
366  }
367 
368  // Please do NOT change these lines.
369  // Developers must be aware, if they use classes unknown to the controller
370  // otherwise certain problem will be extremely hard to track down...
371  echo "ERROR: Can't find target class $a_class for node $a_par_node ".
372  "(".$this->call_node[$a_par_node]["class"].").<br>";
373  error_log( "ERROR: Can't find target class $a_class for node $a_par_node ".
374  "(".$this->call_node[$a_par_node]["class"].")");
375 
376  if (DEVMODE == 1)
377  {
378  try
379  {
380  throw new Exception("");
381  }
382  catch(Exception $e)
383  {
384  echo "<pre>".$e->getTraceAsString()."</pre>";
385  }
386  }
387 
388  exit;
389  }
390 
396  function getCmdNode()
397  {
398  return $_GET["cmdNode"];
399  }
400 
408  function addLocation($a_title, $a_link, $a_target = "", $a_ref_id = 0)
409  {
410  $this->location[] = array("title" => $a_title,
411  "link" => $a_link, "target" => $a_target, "ref_id" => $a_ref_id);
412  }
413 
419  function getLocations()
420  {
421  return $this->location;
422  }
423 
432  function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
433  {
434  $a_class = strtolower($a_class);
435 
436  $this->tab[] = array("lang_var" => $a_lang_var,
437  "link" => $a_link, "cmd" => $a_cmd, "class" => $a_class);
438  }
439 
445  function getTabs()
446  {
447  return $this->tab;
448  }
449 
453  function getCallHistory()
454  {
455  return $this->call_hist;
456  }
457 
476  function getCallStructure($a_class, $a_nr = 0, $a_parent = 0)
477  {
478  global $ilDB, $ilLog, $ilUser;
479 
480  $a_class = strtolower($a_class);
481 
482  if (in_array($a_class, $this->stored_trees))
483  {
484  $q = "SELECT * FROM ctrl_structure WHERE root_class = ".
485  $ilDB->quote($a_class);
486  $set = $ilDB->query($q);
487  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
488  $this->call_node = unserialize($rec["call_node"]);
489  $this->forward = unserialize($rec["forward"]);
490  $this->parent = unserialize($rec["parent"]);
491  $this->root_class = $a_class;
492  }
493  else
494  {
495  $this->readCallStructure($a_class, $a_nr, $a_parent);
496  }
497 
498  // check whether command node and command class fit together
499  if ($_GET["cmdNode"] > 0)
500  {
501  if (strtolower($this->call_node[$_GET["cmdNode"]]["class"]) !=
502  strtolower($_GET["cmdClass"]))
503  {
504  if (DEVMODE)
505  {
506  die ("Internal Error: ilCtrl Node Error. cmdClass: '".$_GET["cmdClass"]
507  ."', cmdNode: '".$_GET["cmdNode"]."' . Internally cmdNode is assigned to ".
508  "class '".$this->call_node[$_GET["cmdNode"]]["class"]."'.");
509  }
510  else
511  {
512  if (is_object($ilLog))
513  {
514  if (is_object($ilUser))
515  {
516  $user_str = "User: ".$ilUser->getLogin()." (".$ilUser->getId()."), ";
517  }
518  $ilLog->write("Invalid Request (class ilCtrl). Possible attack or Control Structure broken (see Setup). ".
519  $user_str."IP: ".$_SERVER["REMOTE_ADDR"].", URI: ".$_SERVER["REQUEST_URI"]);
520  }
521  ilUtil::sendInfo("Sorry, but the request includes invalid parameters." ,true);
522  ilUtil::redirect("repository.php?cmd=frameset");
523  }
524  }
525  }
526  }
527 
533  {
534  global $ilDB;
535 
536  $q = "DELETE FROM ctrl_structure";
537  $ilDB->query($q);
538 
539  foreach ($this->stored_trees as $root_gui_class)
540  {
541  $this->call_node = array();
542  $this->forward = array();
543  $this->parent = array();
544  $this->readCallStructure($root_gui_class);
545  $q = "INSERT INTO ctrl_structure (root_class, call_node, forward, parent) VALUES (".
546  $ilDB->quote($root_gui_class).",".
547  $ilDB->quote(serialize($this->call_node)).",".
548  $ilDB->quote(serialize($this->forward)).",".
549  $ilDB->quote(serialize($this->parent)).")";
550  $ilDB->query($q);
551  }
552  }
553 
557  function readCallStructure($a_class, $a_nr = 0, $a_parent = 0)
558  {
559  global $ilDB;
560 
561  $a_class = strtolower($a_class);
562 
563  $a_nr++;
564 
565  // determine call node structure
566  $this->call_node[$a_nr] = array("class" => $a_class, "parent" => $a_parent);
567 
568 //echo "<br>nr:$a_nr:class:$a_class:parent:$a_parent:";
569  $q = "SELECT * FROM ctrl_calls WHERE parent=".
570  $ilDB->quote(strtolower($a_class)).
571  " ORDER BY child";
572 
573  $call_set = $ilDB->query($q);
574  //$forw = array();
575  $a_parent = $a_nr;
576  while($call_rec = $call_set->fetchRow(DB_FETCHMODE_ASSOC))
577  {
578  $a_nr = $this->readCallStructure($call_rec["child"], $a_nr, $a_parent);
579  $forw[] = $call_rec["child"];
580  }
581 
582  // determin forward and parent array
583  $this->forwards($a_class, $forw);
584 //echo "<br>forwards:".$a_class."<br>"; var_dump($forw);
585 
586  // determine root class
587  $this->root_class = $a_class;
588  return $a_nr;
589  }
590 
591 
600  function forwards($a_from_class, $a_to_class)
601  {
602  $a_from_class = strtolower($a_from_class);
603 
604  if (is_array($a_to_class))
605  {
606  foreach($a_to_class as $to_class)
607  {
608  $this->forward[$a_from_class][] = strtolower($to_class);
609  $this->parent[strtolower($to_class)][] = $a_from_class;
610  }
611  }
612  else
613  {
614  if (is_object($a_obj))
615  {
616  $this->forward[strtolower(get_class($a_obj))][] = strtolower($a_to_class);
617  $this->parent[strtolower($a_to_class)][] = strtolower(get_class($a_obj));
618  }
619  }
620  }
621 
622 
642  function saveParameter(&$a_obj, $a_parameter)
643  {
644  $this->saveParameterByClass(get_class($a_obj), $a_parameter);
645  }
646 
647  function saveParameterByClass($a_class, $a_parameter)
648  {
649  if (is_array($a_parameter))
650  {
651  foreach($a_parameter as $parameter)
652  {
653  $this->save_parameter[strtolower($a_class)][] = $parameter;
654  }
655  }
656  else
657  {
658  $this->save_parameter[strtolower($a_class)][] = $a_parameter;
659  }
660  }
661 
662 
687  function setParameter(&$a_obj, $a_parameter, $a_value)
688  {
689  $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
690  }
691 
692 
702  function setParameterByClass($a_class, $a_parameter, $a_value)
703  {
704  $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
705  }
706 
707 
714  function clearParameters(&$a_obj)
715  {
716  $this->clearParametersByClass(strtolower(get_class($a_obj)));
717  }
718 
725  function clearParametersByClass($a_class)
726  {
727  $this->parameter[strtolower($a_class)] = array();
728  }
729 
738  function getNextClass()
739  {
740 //echo "getNextClass:";
741  $cmdNode = $this->getCmdNode();
742  if ($cmdNode == "")
743  {
744  return false;
745  }
746  else
747  {
748  if ($this->current_node == $cmdNode)
749  {
750 //echo "1:".$this->call_node[$cmdNode]["class"]."<br>";
751  //return $this->call_node[$cmdNode]["class"];
752  return "";
753  }
754  else
755  {
756  $path = $this->getPathNew($this->current_node, $cmdNode);
757 //echo "2:".$this->call_node[$path[1]]["class"]."<br>";
758  return $this->call_node[$path[1]]["class"];
759  }
760  }
761  }
762 
769  function lookupClassPath($a_class_name)
770  {
771  global $ilDB;
772  $a_class_name = strtolower($a_class_name);
773 
774  $q = "SELECT * FROM ctrl_classfile WHERE class = ".$ilDB->quote($a_class_name);
775 
776  $class_set = $ilDB->query($q);
777  $class_rec = $class_set->fetchRow(DB_FETCHMODE_ASSOC);
778 
779  return $class_rec["file"];
780  }
781 
790  function getClassForClasspath($a_class_path)
791  {
792  $path = pathinfo($a_class_path);
793  $file = $path["basename"];
794  $class = substr($file, 6, strlen($file) - 10);
795 
796  return $class;
797  }
798 
807  function getPathNew($a_source_node, $a_target_node)
808  {
809 //echo "-".$a_source_node."-";
810  $path_rev = array();
811  $c_target = $a_target_node;
812  while ($a_source_node != $c_target)
813  {
814  $path_rev[] = $c_target;
815  $c_target = $this->call_node[$c_target]["parent"];
816  if(!($c_target > 0))
817  {
818  echo "ERROR: Path not found. Source:".$a_source_node.
819  " (".$this->call_node[$a_source_node]["class"].")".
820  ", Target:".$a_target_node.
821  " (".$this->call_node[$a_target_node]["class"].")";
822  exit;
823  }
824  }
825  if ($a_source_node == $c_target)
826  {
827  $path_rev[] = $c_target;
828  }
829  $path = array();
830  for ($i=0; $i<count($path_rev); $i++)
831  {
832  $path[] = $path_rev[count($path_rev) - ($i + 1)];
833  }
834 
835  foreach($path as $node)
836  {
837 //echo "<br>-->".$node.":".$this->call_node[$node]["class"];
838  }
839  return $path;
840  }
841 
842 
848  function setTargetScript($a_target_script)
849  {
850  $this->target_script = $a_target_script;
851  }
852 
853 
859  function getTargetScript()
860  {
861  return $this->target_script;
862  }
863 
864 
871  function initBaseClass($a_base_class)
872  {
873  $_GET["baseClass"] = $a_base_class;
874  $_GET["cmd"] = "";
875  $_GET["cmdClass"] = "";
876  $_GET["cmdNode"] = "";
877  $this->init();
878  }
879 
887  function getCmd($a_default_cmd = "", $a_safe_commands = "")
888  {
889  $cmd = $_GET["cmd"];
890  if($cmd == "post")
891  {
892  if (is_array($_POST["cmd"]))
893  {
894  reset($_POST["cmd"]);
895  }
896  $cmd = @key($_POST["cmd"]);
897 
898  // verify command
899  if ($this->verified_cmd != "")
900  {
901  return $this->verified_cmd;
902  }
903  else
904  {
905  if (!$this->verifyToken() &&
906  (!is_array($a_safe_commands) || !in_array($cmd, $a_safe_commands)))
907  {
908  return $a_default_cmd;
909  }
910  }
911 
912  $this->verified_cmd = $cmd;
913 
914  if($cmd == "" && isset($_POST["select_cmd"])) // selected command in multi-list (table2)
915  {
916  $cmd = $_POST["selected_cmd"];
917  $this->verified_cmd = $cmd;
918  }
919  if($cmd == "")
920  {
921  $cmd = $_GET["fallbackCmd"];
922  $this->verified_cmd = $cmd;
923  }
924  }
925  if($cmd == "")
926  {
927  $cmd = $a_default_cmd;
928  }
929  return $cmd;
930  }
931 
942  function setCmd($a_cmd)
943  {
944  $_GET["cmd"] = $a_cmd;
945  }
946 
957  function setCmdClass($a_cmd_class)
958  {
959  $a_cmd_class = strtolower($a_cmd_class);
960  $nr = $this->getNodeIdForTargetClass($this->current_node, $a_cmd_class);
961  $_GET["cmdClass"] = $a_cmd_class;
962  $_GET["cmdNode"] = $nr;
963  }
964 
968  function getCmdClass()
969  {
970  return strtolower($_GET["cmdClass"]);
971  }
972 
981  function getFormAction(&$a_gui_obj, $a_fallback_cmd = "", $a_anchor = "", $a_asynch = false)
982  {
983  $script = $this->getFormActionByClass(strtolower(get_class($a_gui_obj)),
984  $a_fallback_cmd, $a_anchor, $a_asynch);
985  return $script;
986  }
987 
993  function getFormActionByClass($a_class, $a_fallback_cmd = "", $a_anchor = "", $a_asynch = false)
994  {
995  $a_class = strtolower($a_class);
996 
997  $tok = $this->getRequestToken();
998 //echo "-$tok-";
999 
1000  $script = $this->getLinkTargetByClass($a_class, "post", "", $a_asynch);
1001  if ($a_fallback_cmd != "")
1002  {
1003  $script = ilUtil::appendUrlParameterString($script, "fallbackCmd=".$a_fallback_cmd);
1004  }
1005  $script = ilUtil::appendUrlParameterString($script, self::IL_RTOKEN_NAME.'='.$this->getRequestToken());
1006  if ($a_anchor != "")
1007  {
1008  $script = $script."#".$a_anchor;
1009  }
1010 
1011  return $script;
1012  }
1013 
1020  public function appendRequestTokenParameterString($a_url)
1021  {
1022  return ilUtil::appendUrlParameterString($a_url, self::IL_RTOKEN_NAME.'='.$this->getRequestToken());
1023  }
1024 
1028  function getRequestToken()
1029  {
1030  global $ilDB, $ilUser;
1031 
1032  if ($this->rtoken != "")
1033  {
1034  return $this->rtoken;
1035  }
1036  else
1037  {
1038  if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1039  $ilUser->getId() != ANONYMOUS_USER_ID)
1040  {
1041  $st = $ilDB->prepare("SELECT token FROM il_request_token WHERE user_id = ? AND session = ?",
1042  array("integer", "text"));
1043  $res =$ilDB->execute($st, array($ilUser->getId(), session_id()));
1044  $rec = $ilDB->fetchAssoc($res);
1045 
1046  if ($rec["token"] != "")
1047  {
1048  return $rec["token"];
1049  }
1050 
1051  $this->rtoken = md5(uniqid(rand(), true));
1052 
1053  // IMPORTANT: Please do NOT try to move this implementation to a
1054  // session basis. This will fail due to framesets that are used
1055  // occasionally in ILIAS, e.g. in the chat, where multiple
1056  // forms are loaded in different frames.
1057  $ilDB->query("INSERT INTO il_request_token (user_id, token, session) VALUES ".
1058  "(".$ilDB->quote($ilUser->getId()).",".$ilDB->quote($this->rtoken).
1059  ",".$ilDB->quote(session_id()).")");
1060  return $this->rtoken;
1061  }
1062  //$this->rtoken = md5(uniqid(rand(), true));
1063  }
1064  return "";
1065  }
1066 
1070  function verifyToken()
1071  {
1072  global $ilDB, $ilUser;
1073 
1074  if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1075  $ilUser->getId() != ANONYMOUS_USER_ID)
1076  {
1077  if ($_GET["rtoken"] == "")
1078  {
1079  echo "ilCtrl::No Request Token Given!"; // for debugging, maybe changed later
1080  return false;
1081  }
1082 
1083  $set = $ilDB->query("SELECT * FROM il_request_token WHERE ".
1084  " user_id = ".$ilDB->quote($ilUser->getId())." AND ".
1085  " token = ".$ilDB->quote($_GET[self::IL_RTOKEN_NAME]));
1086  if ($set->numRows() > 0)
1087  {
1088  // remove used token
1089  /*
1090  $ilDB->query("DELETE FROM il_request_token WHERE ".
1091  " user_id = ".$ilDB->quote($ilUser->getId())." AND ".
1092  " token = ".$ilDB->quote($_GET[self::IL_RTOKEN_NAME]));
1093  */
1094 
1095  // remove tokens from older sessions
1096  $ilDB->query("DELETE FROM il_request_token WHERE ".
1097  " user_id = ".$ilDB->quote($ilUser->getId())." AND ".
1098  " session != ".$ilDB->quote(session_id()));
1099  return true;
1100  }
1101  else
1102  {
1103  return false;
1104  }
1105 
1106  if ($_SESSION["rtokens"][$_GET[self::IL_RTOKEN_NAME]] != "")
1107  {
1108  // remove used token
1109  unset($_SESSION["rtokens"][$_GET[self::IL_RTOKEN_NAME]]);
1110 
1111  // remove old tokens
1112  if (count($_SESSION["rtokens"]) > 100)
1113  {
1114  $to_remove = array();
1115  $sec = 7200; // two hours
1116 
1117  foreach($_SESSION["rtokens"] as $tok => $time)
1118  {
1119  if (time() - $time > $sec)
1120  {
1121  $to_remove[] = $tok;
1122  }
1123  }
1124  foreach($to_remove as $tok)
1125  {
1126  unset($_SESSION["rtokens"][$tok]);
1127  }
1128  }
1129 
1130  return true;
1131  }
1132  return false;
1133  }
1134  else
1135  {
1136  return true; // do not verify, if user or db object is missing
1137  }
1138 
1139  return false;
1140  }
1141 
1142  function redirect(&$a_gui_obj, $a_cmd = "", $a_anchor = "")
1143  {
1144  global $ilBench;
1145 
1146 //echo "<br>class:".get_class($a_gui_obj).":";
1147  $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd);
1148  if (is_object($ilBench))
1149  {
1150  $ilBench->save();
1151  }
1152  if ($a_anchor != "")
1153  {
1154  $script = $script."#".$a_anchor;
1155  }
1156  ilUtil::redirect($script);
1157  }
1158 
1159 
1166  function redirectByClass($a_class, $a_cmd = "")
1167  {
1168  // $a_class may be an array
1169  //$a_class = strtolower($a_class);
1170 
1171 //echo "<br>class:".get_class($a_gui_obj).":";
1172  $script = $this->getLinkTargetByClass($a_class, $a_cmd);
1173 //echo "<br>script:$script:";
1174  ilUtil::redirect($script);
1175  }
1176 
1177  function isAsynch()
1178  {
1179  if ($_GET["cmdMode"] == "asynch")
1180  {
1181  return true;
1182  }
1183  else
1184  {
1185  return false;
1186  }
1187  }
1188 
1189 
1198  function getLinkTarget(&$a_gui_obj, $a_cmd = "", $a_anchor = "", $a_asynch = false)
1199  {
1200 //echo "<br>getLinkTarget";
1201  $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch);
1202  return $script;
1203  }
1204 
1205 
1216  function getLinkTargetByClass($a_class, $a_cmd = "", $a_anchor = "", $a_asynch = false)
1217  {
1218  // note: $a_class may be an array
1219  //$a_class = strtolower($a_class);
1220 
1221 //echo "<br>getLinkTargetByClass";
1222  $script = $this->getTargetScript();
1223  $script = $this->getUrlParameters($a_class, $script, $a_cmd);
1224 
1225  if ($a_asynch)
1226  {
1227  $script.= "&cmdMode=asynch";
1228  }
1229 
1230  if ($a_anchor != "")
1231  {
1232  $script = $script."#".$a_anchor;
1233  }
1234 
1235  return $script;
1236  }
1237 
1241  function setReturn(&$a_gui_obj, $a_cmd)
1242  {
1243  $script = $this->getTargetScript();
1244  $script = $this->getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1245 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
1246  $this->return[strtolower(get_class($a_gui_obj))] = $script;
1247  }
1248 
1252  function setReturnByClass($a_class, $a_cmd)
1253  {
1254  // may not be an array!
1255  $a_class = strtolower($a_class);
1256 
1257  $script = $this->getTargetScript();
1258  $script = $this->getUrlParameters($a_class, $script, $a_cmd);
1259 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
1260  $this->return[strtolower($a_class)] = $script;
1261  }
1262 
1266  function returnToParent(&$a_gui_obj, $a_anchor = "")
1267  {
1268  $script = $this->getParentReturn($a_gui_obj);
1269 
1270  $script = ilUtil::appendUrlParameterString($script,
1271  "redirectSource=".strtolower(get_class($a_gui_obj)));
1272  $script = ilUtil::appendUrlParameterString($script,
1273  "cmdMode=".$_GET["cmdMode"]);
1274  if ($a_anchor != "")
1275  {
1276  $script = $script."#".$a_anchor;
1277  }
1278  ilUtil::redirect($script);
1279  }
1280 
1281 
1288  {
1289  return $_GET["redirectSource"];
1290  }
1291 
1295  function getParentReturn(&$a_gui_obj)
1296  {
1297  return $this->getParentReturnByClass(strtolower(get_class($a_gui_obj)));
1298  }
1299 
1300 
1301  function getParentReturnByClass($a_class)
1302  {
1303  $a_class = strtolower($a_class);
1304  $ret_class = $this->searchReturnClass($a_class);
1305 //echo ":$ret_class:";
1306  if($ret_class)
1307  {
1308 //echo ":".$this->return[$ret_class].":";
1309  return $this->return[$ret_class];
1310  }
1311  }
1312 
1316  function searchReturnClass($a_class)
1317  {
1318 //echo "<br>searchReturnClass".$a_class;
1319  $a_class = strtolower($a_class);
1320 
1321  $nr = $this->getNodeIdForTargetClass($this->current_node, $a_class);
1322  $path = $this->getPathNew(1, $nr);
1323 //var_dump($path);
1324  for($i = count($path)-2; $i>=0; $i--)
1325  {
1326 //echo "<br>:$i:".$path[$i].":".$this->call_node[$path[$i]]["class"]
1327 // .":".$this->return[$this->call_node[$path[$i]]["class"]].":";
1328  if ($this->return[$this->call_node[$path[$i]]["class"]] != "")
1329  {
1330  return $this->call_node[$path[$i]]["class"];
1331  }
1332  }
1333 
1334  return false;
1335  }
1336 
1337  function getUrlParameters($a_class, $a_str, $a_cmd = "", $a_transits = "")
1338  {
1339  // note: $a_class may be an array!
1340  //$a_class = strtolower($a_class);
1341 
1342  $params = $this->getParameterArrayByClass($a_class, $a_cmd, $a_transits);
1343 
1344  foreach ($params as $par => $value)
1345  {
1346  if (strlen($value))
1347  {
1348  $a_str = ilUtil::appendUrlParameterString($a_str, $par."=".$value);
1349  }
1350  }
1351 
1352  return $a_str;
1353  }
1354 
1355  function appendTransitClasses($a_str)
1356  {
1357  if (is_array($_GET["cmdTransit"]))
1358  {
1359  reset($_GET["cmdTransit"]);
1360  foreach ($_GET["cmdTransit"] as $transit)
1361  {
1362  $a_str = ilUtil::appendUrlParameterString($a_str, "cmdTransit[]=".$transit);
1363  }
1364  }
1365  return $a_str;
1366  }
1367 
1368  function getTransitArray()
1369  {
1370  $trans_arr = array();
1371  if (is_array($_GET["cmdTransit"]))
1372  {
1373  reset($_GET["cmdTransit"]);
1374  foreach ($_GET["cmdTransit"] as $key => $transit)
1375  {
1376  $trans_arr["cmdTransit[".$key."]"] = $transit;
1377  }
1378  }
1379  return $trans_arr;
1380  }
1381 
1382  function addTransit($a_class)
1383  {
1384  $a_class = strtolower($a_class);
1385  $_GET["cmdTransit"][] = $a_class;
1386  }
1387 
1388  function getParameterArray(&$a_gui_obj, $a_cmd = "", $a_incl_transit = true)
1389  {
1390  $par_arr = $this->getParameterArrayByClass(strtolower(get_class($a_gui_obj)), $a_cmd,
1391  $trans_arr);
1392 
1393  return $par_arr;
1394  }
1395 
1399  function getParameterArrayByClass($a_class, $a_cmd = "", $a_transits = "")
1400  {
1401 //echo "<br>getparameter for $a_class";
1402  if ($a_class == "")
1403  {
1404  return array();
1405  }
1406 
1407  if (!is_array($a_class))
1408  {
1409  $a_class = array($a_class);
1410  }
1411 
1412  $nr = $this->current_node;
1413  foreach ($a_class as $class)
1414  {
1415 //echo "<br>-$class-";
1416  $class = strtolower($class);
1417  $nr = $this->getNodeIdForTargetClass($nr, $class);
1418  $target_class = $class;
1419 //echo "-$nr-";
1420  }
1421 
1422  $path = $this->getPathNew(1, $nr);
1423  $params = array();
1424 
1425  // append parameters of parent classes
1426  foreach($path as $node_id)
1427  {
1428  $class = $this->call_node[$node_id]["class"];
1429  if (is_array($this->save_parameter[$class]))
1430  {
1431  foreach($this->save_parameter[$class] as $par)
1432  {
1433  $params[$par] = $_GET[$par];
1434  }
1435  }
1436 
1437  if (is_array($this->parameter[$class]))
1438  {
1439  foreach($this->parameter[$class] as $par => $value)
1440  {
1441  $params[$par] = $value;
1442  }
1443  }
1444  }
1445 
1446  if ($a_cmd != "")
1447  {
1448  $params["cmd"] = $a_cmd;
1449  }
1450 
1451  $params["cmdClass"] = $target_class;
1452  $params["cmdNode"] = $nr;
1453  $params["baseClass"] = $_GET["baseClass"];
1454 
1455  return $params;
1456  }
1457 
1458 
1459 } // END class.ilCtrl
1460 ?>