36 $this->stored_trees = array
37 (
"ilrepositorygui",
"ilpersonaldesktopgui",
38 "illmpresentationgui",
"illmeditorgui",
39 "iladministrationgui");
45 $this->
debug[] = $str;
58 $this->transit = array();
59 $this->forward = array();
61 $this->parent = array();
62 $this->save_parameter = array();
63 $this->parameter = array();
65 $this->location = array();
67 $this->current_node = 0;
68 $this->module_dir =
"";
69 $this->service_dir =
"";
70 $this->call_node = array();
71 $this->root_class =
"";
87 $baseClass = strtolower(
$_GET[
"baseClass"]);
90 $mc_set = $ilDB->query(
"SELECT * FROM module_class WHERE LOWER(class) = ".
91 $ilDB->quote($baseClass,
"text"));
92 $mc_rec = $ilDB->fetchAssoc($mc_set);
93 $module = $mc_rec[
"module"];
94 $class = $mc_rec[
"class"];
95 $class_dir = $mc_rec[
"dir"];
99 $m_set = $ilDB->query(
"SELECT * FROM il_component WHERE name = ".
100 $ilDB->quote($module,
"text"));
101 $m_rec = $ilDB->fetchAssoc($m_set);
102 $this->module_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
103 include_once $this->module_dir.
"/".$class_dir.
"/class.".$class.
".php";
107 $mc_set = $ilDB->query(
"SELECT * FROM service_class WHERE LOWER(class) = ".
108 $ilDB->quote($baseClass,
"text"));
109 $mc_rec = $ilDB->fetchAssoc($mc_set);
111 $service = $mc_rec[
"service"];
112 $class = $mc_rec[
"class"];
113 $class_dir = $mc_rec[
"dir"];
117 echo
"Could not find entry in modules.xml or services.xml for".
123 $m_set = $ilDB->query(
"SELECT * FROM il_component WHERE name = ".
124 $ilDB->quote($service,
"text"));
125 $m_rec = $ilDB->fetchAssoc($m_set);
126 $this->service_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
128 include_once $this->service_dir.
"/".$class_dir.
"/class.".$class.
".php";;
133 $base_class_gui =&
new $class();
142 return $this->module_dir;
158 $class = strtolower(get_class($a_gui_object));
163 $current_node = $this->current_node;
165 $this->current_node = $nr;
169 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
170 "mode" =>
"execComm",
"cmd" => $this->
getCmd());
173 $html = $a_gui_object->executeCommand();
176 $this->current_node = $current_node;
181 echo
"ERROR: Can't forward to class $class.";
exit;
196 $class = strtolower(get_class($a_gui_object));
201 $current_node = $this->current_node;
204 $this->current_node = $nr;
208 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
209 "mode" =>
"getHtml",
"cmd" => $this->
getCmd());
213 $html = $a_gui_object->getHTML();
216 $this->current_node = $current_node;
221 echo
"ERROR: Can't getHTML from class $class.";
exit;
227 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
229 $this->context_obj_id = $a_obj_id;
230 $this->context_obj_type = $a_obj_type;
231 $this->context_sub_obj_id = $a_sub_obj_id;
232 $this->context_sub_obj_type = $a_sub_obj_type;
242 return $this->context_obj_id;
252 return $this->context_obj_type;
262 return $this->context_sub_obj_id;
272 return $this->context_sub_obj_type;
298 $class = strtolower($a_class);
301 if ($class == $this->call_node[$a_par_node][
"class"])
307 foreach($this->call_node as $nr => $node)
309 if (($node[
"parent"] == $a_par_node) &&
310 ($node[
"class"] == $class))
317 $par = $this->call_node[$a_par_node][
"parent"];
320 foreach($this->call_node as $nr => $node)
322 if (($node[
"parent"] == $par) &&
323 ($node[
"class"] == $class))
333 if ($this->call_node[$par][
"class"] == $class)
337 $par = $this->call_node[$par][
"parent"];
343 echo
"ERROR: Can't find target class $a_class for node $a_par_node ".
344 "(".$this->call_node[$a_par_node][
"class"].
").<br>";
345 error_log(
"ERROR: Can't find target class $a_class for node $a_par_node ".
346 "(".$this->call_node[$a_par_node][
"class"].
")");
356 echo
"<pre>".$e->getTraceAsString().
"</pre>";
370 return $_GET[
"cmdNode"];
380 function addLocation($a_title, $a_link, $a_target =
"", $a_ref_id = 0)
382 $this->location[] = array(
"title" => $a_title,
383 "link" => $a_link,
"target" => $a_target,
"ref_id" => $a_ref_id);
404 function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
406 $a_class = strtolower($a_class);
408 $this->tab[] = array(
"lang_var" => $a_lang_var,
409 "link" => $a_link,
"cmd" => $a_cmd,
"class" => $a_class);
452 $a_class = strtolower($a_class);
454 if (in_array($a_class, $this->stored_trees))
457 $set = $ilDB->query(
"SELECT * FROM ctrl_structure WHERE root_class = ".
458 $ilDB->quote($a_class,
"text"));
459 $rec = $ilDB->fetchAssoc($set);
460 $this->call_node = unserialize($rec[
"call_node"]);
461 $this->forward = unserialize($rec[
"forward"]);
462 $this->parent = unserialize($rec[
"parent"]);
463 $this->root_class = $a_class;
474 if (
$_GET[
"cmdNode"] > 0)
476 if (strtolower($this->call_node[
$_GET[
"cmdNode"]][
"class"]) !=
477 strtolower($_GET[
"cmdClass"]))
481 die (
"Internal Error: ilCtrl Node Error. cmdClass: '".$_GET[
"cmdClass"]
482 .
"', cmdNode: '".$_GET[
"cmdNode"].
"' . Internally cmdNode is assigned to ".
483 "class '".$this->call_node[$_GET[
"cmdNode"]][
"class"].
"'.");
487 if (is_object($ilLog))
489 if (is_object($ilUser))
491 $user_str =
"User: ".$ilUser->getLogin().
" (".$ilUser->getId().
"), ";
493 $ilLog->write(
"Invalid Request (class ilCtrl). Possible attack or Control Structure broken (see Setup). ".
494 $user_str.
"IP: ".$_SERVER[
"REMOTE_ADDR"].
", URI: ".$_SERVER[
"REQUEST_URI"]);
511 $ilDB->manipulate(
"DELETE FROM ctrl_structure");
513 foreach ($this->stored_trees as $root_gui_class)
515 $this->call_node = array();
516 $this->forward = array();
517 $this->parent = array();
525 $ilDB->insert(
"ctrl_structure", array(
526 "root_class" => array(
"text", $root_gui_class),
527 "call_node" => array(
"text", serialize($this->call_node)),
528 "forward" => array(
"text", serialize($this->forward)),
529 "parent" => array(
"clob", serialize($this->parent))));
540 $a_class = strtolower($a_class);
545 $this->call_node[$a_nr] = array(
"class" => $a_class,
"parent" => $a_parent);
548 $call_set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE parent = ".
549 $ilDB->quote(strtolower($a_class),
"text").
550 " ORDER BY child", array(
"text"));
552 while ($call_rec = $ilDB->fetchAssoc($call_set))
555 $forw[] = $call_rec[
"child"];
563 $this->root_class = $a_class;
578 $a_from_class = strtolower($a_from_class);
580 if (is_array($a_to_class))
582 foreach($a_to_class as $to_class)
584 if ($a_from_class !=
"" && $to_class !=
"")
586 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
588 $this->forward[$a_from_class][] = strtolower($to_class);
590 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
592 $this->parent[strtolower($to_class)][] = $a_from_class;
599 $to_class = $a_to_class;
600 if ($a_from_class !=
"" && $to_class !=
"")
602 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
604 $this->forward[$a_from_class][] = strtolower($to_class);
606 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
608 $this->parent[strtolower($to_class)][] = $a_from_class;
636 if (is_object($a_obj))
644 if (is_array($a_parameter))
646 foreach($a_parameter as $parameter)
648 $this->save_parameter[strtolower($a_class)][] = $parameter;
653 $this->save_parameter[strtolower($a_class)][] = $a_parameter;
684 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
699 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
722 $this->parameter[strtolower($a_class)] = array();
743 if ($this->current_node == $cmdNode)
751 $path = $this->
getPathNew($this->current_node, $cmdNode);
754 return $this->call_node[$path[1]][
"class"];
768 $a_class_name = strtolower($a_class_name);
770 $class_set = $ilDB->query(
"SELECT * FROM ctrl_classfile WHERE class = ".
771 $ilDB->quote($a_class_name,
"text"));
772 $class_rec = $ilDB->fetchAssoc($class_set);
774 if ($class_rec[
"plugin_path"] !=
"")
776 return $class_rec[
"plugin_path"].
"/".$class_rec[
"filename"];
780 return $class_rec[
"filename"];
794 $path = pathinfo($a_class_path);
795 $file = $path[
"basename"];
796 $class = substr(
$file, 6, strlen(
$file) - 10);
813 $c_target = $a_target_node;
814 while ($a_source_node != $c_target)
816 $path_rev[] = $c_target;
817 $c_target = $this->call_node[$c_target][
"parent"];
820 echo
"ERROR: Path not found. Source:".$a_source_node.
821 " (".$this->call_node[$a_source_node][
"class"].
")".
822 ", Target:".$a_target_node.
823 " (".$this->call_node[$a_target_node][
"class"].
")";
827 if ($a_source_node == $c_target)
829 $path_rev[] = $c_target;
832 for ($i=0; $i<count($path_rev); $i++)
834 $path[] = $path_rev[count($path_rev) - ($i + 1)];
849 $this->target_script = $a_target_script;
872 $_GET[
"baseClass"] = $a_base_class;
874 $_GET[
"cmdClass"] =
"";
875 $_GET[
"cmdNode"] =
"";
886 function getCmd($a_default_cmd =
"", $a_safe_commands =
"")
891 if (is_array(
$_POST[
"cmd"]))
898 if ($this->verified_cmd !=
"")
900 return $this->verified_cmd;
905 (!is_array($a_safe_commands) || !in_array(
$cmd, $a_safe_commands)))
907 return $a_default_cmd;
911 $this->verified_cmd =
$cmd;
912 if(
$cmd ==
"" && isset(
$_POST[
"select_cmd2"]))
915 $this->verified_cmd =
$cmd;
920 $this->verified_cmd =
$cmd;
925 $this->verified_cmd =
$cmd;
930 $cmd = $a_default_cmd;
947 $_GET[
"cmd"] = $a_cmd;
962 $a_cmd_class = strtolower($a_cmd_class);
964 $_GET[
"cmdClass"] = $a_cmd_class;
965 $_GET[
"cmdNode"] = $nr;
973 return strtolower(
$_GET[
"cmdClass"]);
984 function getFormAction(&$a_gui_obj, $a_fallback_cmd =
"", $a_anchor =
"", $a_asynch =
false)
987 $a_fallback_cmd, $a_anchor, $a_asynch);
998 $a_class = strtolower($a_class);
1004 if ($a_fallback_cmd !=
"")
1009 if ($a_anchor !=
"")
1011 $script = $script.
"#".$a_anchor;
1033 global
$ilDB, $ilUser;
1035 if ($this->rtoken !=
"")
1037 return $this->rtoken;
1041 if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1042 $ilUser->getId() != ANONYMOUS_USER_ID)
1044 $res = $ilDB->query(
"SELECT token FROM il_request_token WHERE user_id = ".
1045 $ilDB->quote($ilUser->getId(),
"integer").
1046 " AND session_id = ".$ilDB->quote(session_id(),
"text"));
1047 $rec = $ilDB->fetchAssoc(
$res);
1049 if ($rec[
"token"] !=
"")
1051 return $rec[
"token"];
1054 $this->rtoken = md5(uniqid(rand(),
true));
1060 $ilDB->manipulate(
"INSERT INTO il_request_token (user_id, token, stamp, session_id) VALUES ".
1062 $ilDB->quote($ilUser->getId(),
"integer").
",".
1063 $ilDB->quote($this->rtoken,
"text").
",".
1065 $ilDB->quote(session_id(),
"text").
")");
1066 return $this->rtoken;
1078 global
$ilDB, $ilUser;
1080 if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1081 $ilUser->getId() != ANONYMOUS_USER_ID)
1083 if (
$_GET[
"rtoken"] ==
"")
1085 echo
"ilCtrl::No Request Token Given!";
1089 $set = $ilDB->query(
"SELECT * FROM il_request_token WHERE ".
1090 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1091 " token = ".$ilDB->quote(
$_GET[self::IL_RTOKEN_NAME]),
"text");
1092 if ($ilDB->numRows($set) > 0)
1102 $ilDB->manipulate(
"DELETE FROM il_request_token WHERE ".
1103 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1104 " session_id != ".$ilDB->quote(session_id(),
"text"));
1120 $to_remove = array();
1123 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1125 if (time() - $time > $sec)
1127 $to_remove[] = $tok;
1130 foreach($to_remove as $tok)
1148 function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"")
1155 if (is_object($ilBench))
1159 if ($a_anchor !=
"")
1161 $script = $script.
"#".$a_anchor;
1186 if (
$_GET[
"cmdMode"] ==
"asynch")
1205 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false)
1208 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch);
1234 $script.=
"&cmdMode=asynch";
1237 if ($a_anchor !=
"")
1239 $script = $script.
"#".$a_anchor;
1251 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1253 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1262 $a_class = strtolower($a_class);
1267 $this->
return[strtolower($a_class)] = $script;
1278 "redirectSource=".strtolower(get_class($a_gui_obj)));
1280 "cmdMode=".
$_GET[
"cmdMode"]);
1281 if ($a_anchor !=
"")
1283 $script = $script.
"#".$a_anchor;
1297 return $_GET[
"redirectSource"];
1311 $a_class = strtolower($a_class);
1317 return $this->
return[$ret_class];
1326 $a_class = strtolower($a_class);
1331 for($i = count($path)-2; $i>=0; $i--)
1335 if ($this->
return[$this->call_node[$path[$i]][
"class"]] !=
"")
1337 return $this->call_node[$path[$i]][
"class"];
1351 foreach (
$params as $par => $value)
1364 if (is_array(
$_GET[
"cmdTransit"]))
1366 reset(
$_GET[
"cmdTransit"]);
1367 foreach (
$_GET[
"cmdTransit"] as $transit)
1377 $trans_arr = array();
1378 if (is_array(
$_GET[
"cmdTransit"]))
1380 reset(
$_GET[
"cmdTransit"]);
1381 foreach (
$_GET[
"cmdTransit"] as
$key => $transit)
1383 $trans_arr[
"cmdTransit[".$key.
"]"] = $transit;
1391 $a_class = strtolower($a_class);
1392 $_GET[
"cmdTransit"][] = $a_class;
1414 if (!is_array($a_class))
1416 $a_class = array($a_class);
1419 $nr = $this->current_node;
1420 foreach ($a_class as $class)
1423 $class = strtolower($class);
1425 $target_class = $class;
1435 foreach($path as $node_id)
1437 $class = $this->call_node[$node_id][
"class"];
1438 if (is_array($this->save_parameter[$class]))
1440 foreach($this->save_parameter[$class] as $par)
1446 if (is_array($this->parameter[$class]))
1448 foreach($this->parameter[$class] as $par => $value)
1460 $params[
"cmdClass"] = $target_class;