38 $this->stored_trees = array
39 (
"ilrepositorygui",
"ilpersonaldesktopgui",
40 "illmpresentationgui",
"illmeditorgui",
41 "iladministrationgui");
51 $this->
debug[] = $str;
69 $this->transit = array();
70 $this->forward = array();
72 $this->parent = array();
73 $this->save_parameter = array();
74 $this->parameter = array();
76 $this->location = array();
78 $this->current_node = 0;
79 $this->module_dir =
"";
80 $this->service_dir =
"";
81 $this->call_node = array();
82 $this->root_class =
"";
95 $baseClass = strtolower(
$_GET[
"baseClass"]);
98 $mc_set = $ilDB->query(
"SELECT * FROM module_class WHERE LOWER(class) = ".
99 $ilDB->quote($baseClass,
"text"));
100 $mc_rec = $ilDB->fetchAssoc($mc_set);
101 $module = $mc_rec[
"module"];
102 $class = $mc_rec[
"class"];
103 $class_dir = $mc_rec[
"dir"];
107 $m_set = $ilDB->query(
"SELECT * FROM il_component WHERE name = ".
108 $ilDB->quote($module,
"text"));
109 $m_rec = $ilDB->fetchAssoc($m_set);
110 $this->module_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
111 include_once $this->module_dir.
"/".$class_dir.
"/class.".$class.
".php";
115 $mc_set = $ilDB->query(
"SELECT * FROM service_class WHERE LOWER(class) = ".
116 $ilDB->quote($baseClass,
"text"));
117 $mc_rec = $ilDB->fetchAssoc($mc_set);
119 $service = $mc_rec[
"service"];
120 $class = $mc_rec[
"class"];
121 $class_dir = $mc_rec[
"dir"];
125 echo
"Could not find entry in modules.xml or services.xml for ".
126 $baseClass.
" <br/>".str_replace(
"&",
"<br />&", htmlentities($_SERVER[
"REQUEST_URI"]));
131 $m_set = $ilDB->query(
"SELECT * FROM il_component WHERE name = ".
132 $ilDB->quote($service,
"text"));
133 $m_rec = $ilDB->fetchAssoc($m_set);
134 $this->service_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
136 include_once $this->service_dir.
"/".$class_dir.
"/class.".$class.
".php";;
141 $base_class_gui =&
new $class();
150 return $this->module_dir;
164 $class = strtolower(get_class($a_gui_object));
169 $current_node = $this->current_node;
171 $this->current_node = $nr;
175 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
176 "mode" =>
"execComm",
"cmd" => $this->
getCmd());
179 $html = $a_gui_object->executeCommand();
182 $this->current_node = $current_node;
187 echo
"ERROR: Can't forward to class $class.";
exit;
199 $class = strtolower(get_class($a_gui_object));
204 $current_node = $this->current_node;
207 $this->current_node = $nr;
211 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
212 "mode" =>
"getHtml",
"cmd" => $this->
getCmd());
216 $html = $a_gui_object->getHTML();
219 $this->current_node = $current_node;
224 echo
"ERROR: Can't getHTML from class $class.";
exit;
236 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
238 $this->context_obj_id = $a_obj_id;
239 $this->context_obj_type = $a_obj_type;
240 $this->context_sub_obj_id = $a_sub_obj_id;
241 $this->context_sub_obj_type = $a_sub_obj_type;
251 return $this->context_obj_id;
261 return $this->context_obj_type;
271 return $this->context_sub_obj_id;
281 return $this->context_sub_obj_type;
304 $class = strtolower($a_class);
307 if ($a_par_node === 0 || $a_par_node ==
"")
326 in_array($a_class, $this->calls[$this->
getClassForCid($node_cid)]))
336 in_array($a_class, $this->calls[$this->
getClassForCid($par_cid)]))
344 while($temp_node !=
"")
362 echo
"ERROR: Can't find target class $a_class for node $a_par_node ".
364 error_log(
"ERROR: Can't find target class $a_class for node $a_par_node ".
375 echo
"<pre>".$e->getTraceAsString().
"</pre>";
390 if (!is_array($a_class))
392 $a_class = array($a_class);
395 $nr = $this->current_node;
396 foreach ($a_class as $class)
398 $class = strtolower($class);
421 return $_GET[
"cmdNode"];
431 function addLocation($a_title, $a_link, $a_target =
"", $a_ref_id = 0)
433 $this->location[] = array(
"title" => $a_title,
434 "link" => $a_link,
"target" => $a_target,
"ref_id" => $a_ref_id);
455 function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
457 $a_class = strtolower($a_class);
459 $this->tab[] = array(
"lang_var" => $a_lang_var,
460 "link" => $a_link,
"cmd" => $a_cmd,
"class" => $a_class);
537 $a_class = strtolower($a_class);
542 $this->call_node[$a_nr] = array(
"class" => $a_class,
"parent" => $a_parent);
545 $call_set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE parent = ".
546 $ilDB->quote(strtolower($a_class),
"text").
547 " ORDER BY child", array(
"text"));
549 while ($call_rec = $ilDB->fetchAssoc($call_set))
552 $forw[] = $call_rec[
"child"];
560 $this->root_class = $a_class;
571 private function forwards($a_from_class, $a_to_class)
573 $a_from_class = strtolower($a_from_class);
575 if (is_array($a_to_class))
577 foreach($a_to_class as $to_class)
579 if ($a_from_class !=
"" && $to_class !=
"")
581 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
583 $this->forward[$a_from_class][] = strtolower($to_class);
585 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
587 $this->parent[strtolower($to_class)][] = $a_from_class;
594 $to_class = $a_to_class;
595 if ($a_from_class !=
"" && $to_class !=
"")
597 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
599 $this->forward[$a_from_class][] = strtolower($to_class);
601 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
603 $this->parent[strtolower($to_class)][] = $a_from_class;
631 if (is_object($a_obj))
645 if (is_array($a_parameter))
647 foreach($a_parameter as $parameter)
649 $this->save_parameter[strtolower($a_class)][] = $parameter;
654 $this->save_parameter[strtolower($a_class)][] = $a_parameter;
683 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
696 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
719 $this->parameter[strtolower($a_class)] = array();
740 if ($this->current_node == $cmdNode)
767 $a_class_name = strtolower($a_class_name);
769 $class_set = $ilDB->query(
"SELECT * FROM ctrl_classfile WHERE class = ".
770 $ilDB->quote($a_class_name,
"text"));
771 $class_rec = $ilDB->fetchAssoc($class_set);
773 if ($class_rec[
"plugin_path"] !=
"")
775 return $class_rec[
"plugin_path"].
"/".$class_rec[
"filename"];
779 return $class_rec[
"filename"];
793 $path = pathinfo($a_class_path);
795 $class = substr(
$file, 6, strlen(
$file) - 10);
811 if ($a_source_node ==
"1")
815 if (substr($a_target_node, 0, strlen($a_source_node)) != $a_source_node)
817 echo
"ERROR: Path not found. Source:".$a_source_node.
818 ", Target:".$a_target_node;
822 $temp_node = $a_source_node;
825 if ($a_source_node !=
"")
827 $path = array($a_source_node);
830 $diffstart = ($a_source_node ==
"")
832 : strlen($a_source_node) + 1;
833 $diff = substr($a_target_node, $diffstart);
835 $diff_arr = explode(
":", $diff);
836 foreach($diff_arr as $cid)
838 if ($temp_node !=
"")
843 $path[] = $temp_node;
857 $this->target_script = $a_target_script;
882 $_GET[
"baseClass"] = $a_base_class;
884 $_GET[
"cmdClass"] =
"";
885 $_GET[
"cmdNode"] =
"";
896 public function getCmd($a_default_cmd =
"", $a_safe_commands =
"")
899 if (isset(
$_GET[
"cmd"]))
912 if ($this->verified_cmd !=
"")
914 return $this->verified_cmd;
919 (!is_array($a_safe_commands) || !in_array(
$cmd, $a_safe_commands)))
921 return $a_default_cmd;
925 $this->verified_cmd =
$cmd;
926 if(
$cmd ==
"" && isset(
$_POST[
"table_top_cmd"]))
929 $this->verified_cmd =
$cmd;
932 if(
$cmd ==
"" && isset(
$_POST[
"select_cmd2"]))
935 $this->verified_cmd =
$cmd;
940 $this->verified_cmd =
$cmd;
945 $this->verified_cmd =
$cmd;
950 $cmd = $a_default_cmd;
967 $_GET[
"cmd"] = $a_cmd;
982 $a_cmd_class = strtolower($a_cmd_class);
984 $_GET[
"cmdClass"] = $a_cmd_class;
985 $_GET[
"cmdNode"] = $nr;
995 return strtolower(
$_GET[
"cmdClass"]);
1008 function getFormAction(&$a_gui_obj, $a_fallback_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1012 $a_fallback_cmd, $a_anchor, $a_asynch, $xml_style);
1029 $a_class = strtolower($a_class);
1039 if ($a_fallback_cmd !=
"")
1045 if ($a_anchor !=
"")
1047 $script = $script.
"#".$a_anchor;
1072 global
$ilDB, $ilUser;
1074 if ($this->rtoken !=
"")
1080 if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1081 $ilUser->getId() != ANONYMOUS_USER_ID)
1083 $res = $ilDB->query(
"SELECT token FROM il_request_token WHERE user_id = ".
1084 $ilDB->quote($ilUser->getId(),
"integer").
1085 " AND session_id = ".$ilDB->quote(session_id(),
"text"));
1086 $rec = $ilDB->fetchAssoc(
$res);
1088 if ($rec[
"token"] !=
"")
1090 return $rec[
"token"];
1093 $this->rtoken = md5(uniqid(rand(),
true));
1096 if (rand(1, 200) == 2)
1100 $dq =
"DELETE FROM il_request_token WHERE ".
1102 $ilDB->manipulate($dq);
1109 $ilDB->manipulate(
"INSERT INTO il_request_token (user_id, token, stamp, session_id) VALUES ".
1111 $ilDB->quote($ilUser->getId(),
"integer").
",".
1112 $ilDB->quote($this->rtoken,
"text").
",".
1114 $ilDB->quote(session_id(),
"text").
")");
1129 global
$ilDB, $ilUser;
1131 if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1132 $ilUser->getId() != ANONYMOUS_USER_ID)
1134 if (
$_GET[
"rtoken"] ==
"")
1136 echo
"ilCtrl::No Request Token Given!";
1140 $set = $ilDB->query(
"SELECT * FROM il_request_token WHERE ".
1141 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1142 " token = ".$ilDB->quote(
$_GET[self::IL_RTOKEN_NAME]),
"text");
1143 if ($ilDB->numRows($set) > 0)
1153 $ilDB->manipulate(
"DELETE FROM il_request_token WHERE ".
1154 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1155 " session_id != ".$ilDB->quote(session_id(),
"text"));
1171 $to_remove = array();
1174 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1176 if (time() - $time > $sec)
1178 $to_remove[] = $tok;
1181 foreach($to_remove as $tok)
1206 public function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"")
1212 if (is_object($ilBench))
1216 if ($a_anchor !=
"")
1218 $script = $script.
"#".$a_anchor;
1243 if (isset(
$_GET[
"cmdMode"]) &&
$_GET[
"cmdMode"] ==
"asynch")
1265 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1268 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch,
1306 $script.= $amp.
"cmdMode=asynch";
1309 if ($a_anchor !=
"")
1311 $script = $script.
"#".$a_anchor;
1323 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1325 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1334 $a_class = strtolower($a_class);
1339 $this->
return[strtolower($a_class)] = $script;
1350 "redirectSource=".strtolower(get_class($a_gui_obj)));
1352 "cmdMode=".
$_GET[
"cmdMode"]);
1353 if ($a_anchor !=
"")
1355 $script = $script.
"#".$a_anchor;
1369 return $_GET[
"redirectSource"];
1386 $a_class = strtolower($a_class);
1392 return $this->
return[$ret_class];
1401 $a_class = strtolower($a_class);
1404 $n_arr = explode(
":", $node);
1405 for($i = count($n_arr)-2; $i>=0; $i--)
1426 foreach ($params as $par => $value)
1461 if (!is_array($a_class))
1463 $a_class = array($a_class);
1466 $nr = $this->current_node;
1467 foreach ($a_class as $class)
1469 $class = strtolower($class);
1471 $target_class = $class;
1478 foreach(
$path as $node_id)
1480 $class = ($node_id ==
"")
1481 ? strtolower(
$_GET[
"baseClass"])
1483 if (isset($this->save_parameter[$class]) && is_array($this->save_parameter[$class]))
1485 foreach($this->save_parameter[$class] as $par)
1487 if (isset(
$_GET[$par]))
1489 $params[$par] =
$_GET[$par];
1494 if (isset($this->parameter[$class]) && is_array($this->parameter[$class]))
1496 foreach($this->parameter[$class] as $par => $value)
1498 $params[$par] = $value;
1505 $params[
"cmd"] = $a_cmd;
1508 $params[
"cmdClass"] = $target_class;
1509 $params[
"cmdNode"] = $nr;
1510 $params[
"baseClass"] =
$_GET[
"baseClass"];
1520 if ($this->class_cid[$a_class] ==
"")
1524 if ($this->class_cid[$a_class] ==
"")
1532 $add =
"<br><br>Please make sure your GUI class name ends with 'GUI' and that the filename is 'class.[YourClassName].php'. In exceptional cases you
1533 may solve the issue by putting an empty * @ilCtrl_Calls [YourClassName]: into your class header.".
1534 " In both cases you need to reload the control structure in the setup.";
1536 die(
"Cannot find cid for class ".$a_class.
".".$add);
1538 return $this->class_cid[$a_class];
1546 if ($this->cid_class[$a_cid] ==
"")
1550 if ($this->cid_class[$a_cid] ==
"")
1552 die(
"Cannot find class for cid ".$a_cid.
".");
1554 return $this->cid_class[$a_cid];
1566 if (isset($this->info_read_cid[$a_cid]))
1570 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1571 " WHERE cid = ".$ilDB->quote($a_cid,
"text")
1573 if ($rec = $ilDB->fetchAssoc($set))
1575 $this->cid_class[$a_cid] = $rec[
"class"];
1576 $this->class_cid[$rec[
"class"]] = $a_cid;
1578 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1579 " WHERE parent = ".$ilDB->quote($rec[
"class"],
"text")
1581 while ($rec2 = $ilDB->fetchAssoc($set))
1583 if (!isset($this->calls[$rec[
"class"]]) || !is_array($this->calls[$rec[
"class"]]) || !in_array($rec2[
"child"], $this->calls[$rec[
"class"]]))
1585 if ($rec2[
"child"] !=
"")
1587 $this->calls[$rec[
"class"]][] = $rec2[
"child"];
1591 $this->info_read_class[$rec[
"class"]] =
true;
1594 $this->info_read_cid[$a_cid] =
true;
1604 $n_arr = explode(
":", $a_node);
1605 foreach ($n_arr as $cid)
1620 $a_class = strtolower($a_class);
1621 if (isset($this->info_read_class[$a_class]))
1625 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1626 " WHERE class = ".$ilDB->quote($a_class,
"text")
1628 if ($rec = $ilDB->fetchAssoc($set))
1630 $this->cid_class[$rec[
"cid"]] = $a_class;
1631 $this->class_cid[$a_class] = $rec[
"cid"];
1634 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1635 " WHERE parent = ".$ilDB->quote($a_class,
"text")
1637 while ($rec = $ilDB->fetchAssoc($set))
1639 if (!isset($this->calls[$a_class]) || !is_array($this->calls[$a_class]) || !in_array($rec[
"child"], $this->calls[$a_class]))
1641 if ($rec[
"child"] !=
"")
1643 $this->calls[$a_class][] = $rec[
"child"];
1648 $this->info_read_class[$a_class] =
true;
1649 $this->info_read_cid[$this->class_cid[$a_class]] =
true;
1657 $n_arr = explode(
":", $a_node);
1658 return $n_arr[count($n_arr) - 2];
1666 $lpos = strrpos($a_node,
":");
1667 return substr($a_node, 0, $lpos);
1675 $n_arr = explode(
":", $a_node);
1676 return $n_arr[count($n_arr) - 1];
1689 $a_parent = strtolower($a_parent);
1690 $a_child = strtolower($a_child);
1691 $a_comp_prefix = strtolower($a_comp_prefix);
1693 $set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE ".
1694 " parent = ".$ilDB->quote($a_parent,
"text").
" AND ".
1695 " child = ".$ilDB->quote($a_child,
"text").
" AND ".
1696 " comp_prefix = ".$ilDB->quote($a_comp_prefix,
"text")
1698 if ($rec = $ilDB->fetchAssoc($set))
1702 $ilDB->manipulate(
"INSERT INTO ctrl_calls ".
1703 "(parent, child, comp_prefix) VALUES (".
1704 $ilDB->quote($a_parent,
"text").
",".
1705 $ilDB->quote($a_child,
"text").
",".
1706 $ilDB->quote($a_comp_prefix,
"text").