56 $this->stored_trees = array
57 (
"ilrepositorygui",
"ilpersonaldesktopgui",
58 "illmpresentationgui",
"illmeditorgui",
59 "iladministrationgui");
65 $this->
debug[] = $str;
78 $this->transit = array();
79 $this->forward = array();
81 $this->parent = array();
82 $this->save_parameter = array();
83 $this->parameter = array();
85 $this->location = array();
87 $this->current_node = 0;
88 $this->module_dir =
"";
89 $this->service_dir =
"";
90 $this->call_node = array();
91 $this->root_class =
"";
107 $baseClass = strtolower(
$_GET[
"baseClass"]);
110 $q =
"SELECT * FROM module_class WHERE LOWER(class) = ".
111 $ilDB->quote($baseClass);
112 $mc_set = $ilDB->query($q);
114 $module = $mc_rec[
"module"];
115 $class = $mc_rec[
"class"];
116 $class_dir = $mc_rec[
"dir"];
121 $q =
"SELECT * FROM il_component WHERE name = ".
122 $ilDB->quote($module);
124 $m_set = $ilDB->query($q);
126 $this->module_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
127 include_once $this->module_dir.
"/".$class_dir.
"/class.".$class.
".php";
132 $q =
"SELECT * FROM service_class WHERE LOWER(class) = ".
133 $ilDB->quote($baseClass);
135 $mc_set = $ilDB->query($q);
137 $service = $mc_rec[
"service"];
138 $class = $mc_rec[
"class"];
139 $class_dir = $mc_rec[
"dir"];
143 echo
"Could not find entry in modules.xml or services.xml for".
149 $q =
"SELECT * FROM il_component WHERE name = ".
150 $ilDB->quote($service);
152 $m_set = $ilDB->query($q);
154 $this->service_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
156 include_once $this->service_dir.
"/".$class_dir.
"/class.".$class.
".php";;
161 $base_class_gui =&
new $class();
170 return $this->module_dir;
186 $class = strtolower(get_class($a_gui_object));
191 $current_node = $this->current_node;
193 $this->current_node = $nr;
197 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
198 "mode" =>
"execComm",
"cmd" => $this->
getCmd());
201 $html = $a_gui_object->executeCommand();
204 $this->current_node = $current_node;
209 echo
"ERROR: Can't forward to class $class.";
exit;
224 $class = strtolower(get_class($a_gui_object));
229 $current_node = $this->current_node;
232 $this->current_node = $nr;
236 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
237 "mode" =>
"getHtml",
"cmd" => $this->
getCmd());
241 $html = $a_gui_object->getHTML();
244 $this->current_node = $current_node;
249 echo
"ERROR: Can't getHTML from class $class.";
exit;
255 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
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;
270 return $this->context_obj_id;
280 return $this->context_obj_type;
290 return $this->context_sub_obj_id;
300 return $this->context_sub_obj_type;
326 $class = strtolower($a_class);
329 if ($class == $this->call_node[$a_par_node][
"class"])
335 foreach($this->call_node as $nr => $node)
337 if (($node[
"parent"] == $a_par_node) &&
338 ($node[
"class"] == $class))
345 $par = $this->call_node[$a_par_node][
"parent"];
348 foreach($this->call_node as $nr => $node)
350 if (($node[
"parent"] == $par) &&
351 ($node[
"class"] == $class))
361 if ($this->call_node[$par][
"class"] == $class)
365 $par = $this->call_node[$par][
"parent"];
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"].
")");
384 echo
"<pre>".$e->getTraceAsString().
"</pre>";
398 return $_GET[
"cmdNode"];
408 function addLocation($a_title, $a_link, $a_target =
"", $a_ref_id = 0)
410 $this->location[] = array(
"title" => $a_title,
411 "link" => $a_link,
"target" => $a_target,
"ref_id" => $a_ref_id);
432 function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
434 $a_class = strtolower($a_class);
436 $this->tab[] = array(
"lang_var" => $a_lang_var,
437 "link" => $a_link,
"cmd" => $a_cmd,
"class" => $a_class);
478 global $ilDB,
$ilLog, $ilUser;
480 $a_class = strtolower($a_class);
482 if (in_array($a_class, $this->stored_trees))
484 $q =
"SELECT * FROM ctrl_structure WHERE root_class = ".
485 $ilDB->quote($a_class);
486 $set = $ilDB->query($q);
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;
499 if (
$_GET[
"cmdNode"] > 0)
501 if (strtolower($this->call_node[
$_GET[
"cmdNode"]][
"class"]) !=
502 strtolower($_GET[
"cmdClass"]))
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"].
"'.");
512 if (is_object($ilLog))
514 if (is_object($ilUser))
516 $user_str =
"User: ".$ilUser->getLogin().
" (".$ilUser->getId().
"), ";
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"]);
521 ilUtil::sendInfo(
"Sorry, but the request includes invalid parameters." ,
true);
536 $q =
"DELETE FROM ctrl_structure";
539 foreach ($this->stored_trees as $root_gui_class)
541 $this->call_node = array();
542 $this->forward = array();
543 $this->parent = array();
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)).
")";
561 $a_class = strtolower($a_class);
566 $this->call_node[$a_nr] = array(
"class" => $a_class,
"parent" => $a_parent);
569 $q =
"SELECT * FROM ctrl_calls WHERE parent=".
570 $ilDB->quote(strtolower($a_class)).
573 $call_set = $ilDB->query($q);
579 $forw[] = $call_rec[
"child"];
587 $this->root_class = $a_class;
602 $a_from_class = strtolower($a_from_class);
604 if (is_array($a_to_class))
606 foreach($a_to_class as $to_class)
608 $this->forward[$a_from_class][] = strtolower($to_class);
609 $this->parent[strtolower($to_class)][] = $a_from_class;
614 if (is_object($a_obj))
616 $this->forward[strtolower(get_class($a_obj))][] = strtolower($a_to_class);
617 $this->parent[strtolower($a_to_class)][] = strtolower(get_class($a_obj));
649 if (is_array($a_parameter))
651 foreach($a_parameter as $parameter)
653 $this->save_parameter[strtolower($a_class)][] = $parameter;
658 $this->save_parameter[strtolower($a_class)][] = $a_parameter;
689 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
704 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
727 $this->parameter[strtolower($a_class)] = array();
748 if ($this->current_node == $cmdNode)
756 $path = $this->
getPathNew($this->current_node, $cmdNode);
758 return $this->call_node[$path[1]][
"class"];
772 $a_class_name = strtolower($a_class_name);
774 $q =
"SELECT * FROM ctrl_classfile WHERE class = ".$ilDB->quote($a_class_name);
776 $class_set = $ilDB->query($q);
779 return $class_rec[
"file"];
792 $path = pathinfo($a_class_path);
793 $file = $path[
"basename"];
794 $class = substr(
$file, 6, strlen(
$file) - 10);
811 $c_target = $a_target_node;
812 while ($a_source_node != $c_target)
814 $path_rev[] = $c_target;
815 $c_target = $this->call_node[$c_target][
"parent"];
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"].
")";
825 if ($a_source_node == $c_target)
827 $path_rev[] = $c_target;
830 for ($i=0; $i<count($path_rev); $i++)
832 $path[] = $path_rev[count($path_rev) - ($i + 1)];
835 foreach($path as $node)
850 $this->target_script = $a_target_script;
873 $_GET[
"baseClass"] = $a_base_class;
875 $_GET[
"cmdClass"] =
"";
876 $_GET[
"cmdNode"] =
"";
887 function getCmd($a_default_cmd =
"", $a_safe_commands =
"")
892 if (is_array($_POST[
"cmd"]))
894 reset($_POST[
"cmd"]);
896 $cmd = @key($_POST[
"cmd"]);
899 if ($this->verified_cmd !=
"")
901 return $this->verified_cmd;
906 (!is_array($a_safe_commands) || !in_array(
$cmd, $a_safe_commands)))
908 return $a_default_cmd;
912 $this->verified_cmd =
$cmd;
914 if(
$cmd ==
"" && isset($_POST[
"select_cmd"]))
916 $cmd = $_POST[
"selected_cmd"];
917 $this->verified_cmd =
$cmd;
922 $this->verified_cmd =
$cmd;
927 $cmd = $a_default_cmd;
944 $_GET[
"cmd"] = $a_cmd;
959 $a_cmd_class = strtolower($a_cmd_class);
961 $_GET[
"cmdClass"] = $a_cmd_class;
962 $_GET[
"cmdNode"] = $nr;
970 return strtolower(
$_GET[
"cmdClass"]);
981 function getFormAction(&$a_gui_obj, $a_fallback_cmd =
"", $a_anchor =
"", $a_asynch =
false)
984 $a_fallback_cmd, $a_anchor, $a_asynch);
995 $a_class = strtolower($a_class);
1001 if ($a_fallback_cmd !=
"")
1006 if ($a_anchor !=
"")
1008 $script = $script.
"#".$a_anchor;
1030 global $ilDB, $ilUser;
1032 if ($this->rtoken !=
"")
1034 return $this->rtoken;
1038 if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1039 $ilUser->getId() != ANONYMOUS_USER_ID)
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);
1046 if ($rec[
"token"] !=
"")
1048 return $rec[
"token"];
1051 $this->rtoken = md5(uniqid(rand(),
true));
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;
1072 global $ilDB, $ilUser;
1074 if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1075 $ilUser->getId() != ANONYMOUS_USER_ID)
1077 if (
$_GET[
"rtoken"] ==
"")
1079 echo
"ilCtrl::No Request Token Given!";
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)
1096 $ilDB->query(
"DELETE FROM il_request_token WHERE ".
1097 " user_id = ".$ilDB->quote($ilUser->getId()).
" AND ".
1098 " session != ".$ilDB->quote(session_id()));
1114 $to_remove = array();
1117 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1119 if (time() - $time > $sec)
1121 $to_remove[] = $tok;
1124 foreach($to_remove as $tok)
1142 function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"")
1148 if (is_object($ilBench))
1152 if ($a_anchor !=
"")
1154 $script = $script.
"#".$a_anchor;
1179 if (
$_GET[
"cmdMode"] ==
"asynch")
1198 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false)
1201 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch);
1227 $script.=
"&cmdMode=asynch";
1230 if ($a_anchor !=
"")
1232 $script = $script.
"#".$a_anchor;
1244 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1246 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1255 $a_class = strtolower($a_class);
1260 $this->
return[strtolower($a_class)] = $script;
1271 "redirectSource=".strtolower(get_class($a_gui_obj)));
1273 "cmdMode=".
$_GET[
"cmdMode"]);
1274 if ($a_anchor !=
"")
1276 $script = $script.
"#".$a_anchor;
1289 return $_GET[
"redirectSource"];
1303 $a_class = strtolower($a_class);
1309 return $this->
return[$ret_class];
1319 $a_class = strtolower($a_class);
1324 for($i = count($path)-2; $i>=0; $i--)
1328 if ($this->
return[$this->call_node[$path[$i]][
"class"]] !=
"")
1330 return $this->call_node[$path[$i]][
"class"];
1344 foreach ($params as $par => $value)
1357 if (is_array(
$_GET[
"cmdTransit"]))
1359 reset(
$_GET[
"cmdTransit"]);
1360 foreach (
$_GET[
"cmdTransit"] as $transit)
1370 $trans_arr = array();
1371 if (is_array(
$_GET[
"cmdTransit"]))
1373 reset(
$_GET[
"cmdTransit"]);
1374 foreach (
$_GET[
"cmdTransit"] as $key => $transit)
1376 $trans_arr[
"cmdTransit[".$key.
"]"] = $transit;
1384 $a_class = strtolower($a_class);
1385 $_GET[
"cmdTransit"][] = $a_class;
1407 if (!is_array($a_class))
1409 $a_class = array($a_class);
1412 $nr = $this->current_node;
1413 foreach ($a_class as $class)
1416 $class = strtolower($class);
1418 $target_class = $class;
1426 foreach($path as $node_id)
1428 $class = $this->call_node[$node_id][
"class"];
1429 if (is_array($this->save_parameter[$class]))
1431 foreach($this->save_parameter[$class] as $par)
1433 $params[$par] =
$_GET[$par];
1437 if (is_array($this->parameter[$class]))
1439 foreach($this->parameter[$class] as $par => $value)
1441 $params[$par] = $value;
1448 $params[
"cmd"] = $a_cmd;
1451 $params[
"cmdClass"] = $target_class;
1452 $params[
"cmdNode"] = $nr;
1453 $params[
"baseClass"] =
$_GET[
"baseClass"];