3 require_once(
'class.ilCachedCtrl.php');
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_rec = $module_class->lookupModuleClass($baseClass);
104 $module = $mc_rec[
"module"];
105 $class = $mc_rec[
"class"];
106 $class_dir = $mc_rec[
"dir"];
110 $m_set = $ilDB->query(
"SELECT * FROM il_component WHERE name = ".
111 $ilDB->quote($module,
"text"));
112 $m_rec = $ilDB->fetchAssoc($m_set);
113 $this->module_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
114 include_once $this->module_dir.
"/".$class_dir.
"/class.".$class.
".php";
122 $mc_rec = $module_class->lookupServiceClass($baseClass);
124 $service = $mc_rec[
"service"];
125 $class = $mc_rec[
"class"];
126 $class_dir = $mc_rec[
"dir"];
130 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
131 throw new ilCtrlException(
"Could not find entry in modules.xml or services.xml for ".
132 $baseClass.
" <br/>".str_replace(
"&",
"<br />&", htmlentities($_SERVER[
"REQUEST_URI"])));
142 $this->service_dir = $m_rec[
"type"].
"/".$m_rec[
"name"];
144 include_once $this->service_dir.
"/".$class_dir.
"/class.".$class.
".php";;
149 $base_class_gui =&
new $class();
158 return $this->module_dir;
172 $class = strtolower(get_class($a_gui_object));
175 $nr = $nr[
"node_id"];
178 $current_node = $this->current_node;
180 $this->current_node = $nr;
184 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
185 "mode" =>
"execComm",
"cmd" => $this->
getCmd());
188 $html = $a_gui_object->executeCommand();
191 $this->current_node = $current_node;
197 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
210 $class = strtolower(get_class($a_gui_object));
213 $nr = $nr[
"node_id"];
216 $current_node = $this->current_node;
219 $this->current_node = $nr;
223 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
224 "mode" =>
"getHtml",
"cmd" => $this->
getCmd());
227 $html = $a_gui_object->getHTML();
230 $this->current_node = $current_node;
236 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
250 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
252 $this->context_obj_id = $a_obj_id;
253 $this->context_obj_type = $a_obj_type;
254 $this->context_sub_obj_id = $a_sub_obj_id;
255 $this->context_sub_obj_type = $a_sub_obj_type;
265 return $this->context_obj_id;
275 return $this->context_obj_type;
285 return $this->context_sub_obj_id;
295 return $this->context_sub_obj_type;
318 $class = strtolower($a_class);
321 if ($a_par_node === 0 || $a_par_node ==
"")
334 return array(
"node_id" => $a_par_node,
341 in_array($a_class, $this->calls[$this->
getClassForCid($node_cid)]))
343 return array(
"node_id" => $a_par_node.
":".$this->getCidForClass($class),
352 in_array($a_class, $this->calls[$this->
getClassForCid($par_cid)]))
354 return array(
"node_id" =>
362 while($temp_node !=
"")
367 return array(
"node_id" => $temp_node,
378 $mc_rec = $module_class->lookupModuleClass($class);
379 $n_class = $mc_rec[
'lower_class'];
390 $mc_rec = $module_class->lookupServiceClass($class);
391 $n_class = $mc_rec[
'lower_class'];
404 "base_class" => $class);
419 error_log(
"ERROR: Can't find target class $a_class for node $a_par_node ".
427 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
428 throw new ilCtrlException(
"ERROR: Can't find target class $a_class for node $a_par_node ".
440 if (!is_array($a_class))
442 $a_class = array($a_class);
445 $nr = $this->current_node;
446 foreach ($a_class as $class)
448 $class = strtolower($class);
456 $nr = $nr[
"node_id"];
472 return $_GET[
"cmdNode"];
482 function addLocation($a_title, $a_link, $a_target =
"", $a_ref_id = 0)
484 $this->location[] = array(
"title" => $a_title,
485 "link" => $a_link,
"target" => $a_target,
"ref_id" => $a_ref_id);
506 function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
508 $a_class = strtolower($a_class);
510 $this->tab[] = array(
"lang_var" => $a_lang_var,
511 "link" => $a_link,
"cmd" => $a_cmd,
"class" => $a_class);
588 $a_class = strtolower($a_class);
593 $this->call_node[$a_nr] = array(
"class" => $a_class,
"parent" => $a_parent);
596 $call_set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE parent = ".
597 $ilDB->quote(strtolower($a_class),
"text").
598 " ORDER BY child", array(
"text"));
600 while ($call_rec = $ilDB->fetchAssoc($call_set))
603 $forw[] = $call_rec[
"child"];
611 $this->root_class = $a_class;
622 private function forwards($a_from_class, $a_to_class)
624 $a_from_class = strtolower($a_from_class);
626 if (is_array($a_to_class))
628 foreach($a_to_class as $to_class)
630 if ($a_from_class !=
"" && $to_class !=
"")
632 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
634 $this->forward[$a_from_class][] = strtolower($to_class);
636 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
638 $this->parent[strtolower($to_class)][] = $a_from_class;
645 $to_class = $a_to_class;
646 if ($a_from_class !=
"" && $to_class !=
"")
648 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
650 $this->forward[$a_from_class][] = strtolower($to_class);
652 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
654 $this->parent[strtolower($to_class)][] = $a_from_class;
682 if (is_object($a_obj))
696 if (is_array($a_parameter))
698 foreach($a_parameter as $parameter)
700 $this->save_parameter[strtolower($a_class)][] = $parameter;
705 $this->save_parameter[strtolower($a_class)][] = $a_parameter;
734 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
747 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
770 $this->parameter[strtolower($a_class)] = array();
791 if ($this->current_node == $cmdNode)
818 $a_class_name = strtolower($a_class_name);
821 $class_rec = $cached_ctrl->lookupClassFile($a_class_name);
827 if ($class_rec[
"plugin_path"] !=
"")
829 return $class_rec[
"plugin_path"].
"/".$class_rec[
"filename"];
833 return $class_rec[
"filename"];
847 $path = pathinfo($a_class_path);
849 $class = substr(
$file, 6, strlen(
$file) - 10);
865 if ($a_source_node ==
"1")
869 if (substr($a_target_node, 0, strlen($a_source_node)) != $a_source_node)
871 $failure =
"ERROR: Path not found. Source:".$a_source_node.
872 ", Target:".$a_target_node;
875 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
882 $temp_node = $a_source_node;
885 if ($a_source_node !=
"")
887 $path = array($a_source_node);
890 $diffstart = ($a_source_node ==
"")
892 : strlen($a_source_node) + 1;
893 $diff = substr($a_target_node, $diffstart);
895 $diff_arr = explode(
":", $diff);
896 foreach($diff_arr as $cid)
898 if ($temp_node !=
"")
903 $path[] = $temp_node;
917 $this->target_script = $a_target_script;
942 $_GET[
"baseClass"] = $a_base_class;
944 $_GET[
"cmdClass"] =
"";
945 $_GET[
"cmdNode"] =
"";
956 public function getCmd($a_default_cmd =
"", $a_safe_commands =
"")
959 if (isset(
$_GET[
"cmd"]))
972 if ($this->verified_cmd !=
"")
974 return $this->verified_cmd;
979 (!is_array($a_safe_commands) || !in_array(
$cmd, $a_safe_commands)))
981 return $a_default_cmd;
985 $this->verified_cmd =
$cmd;
986 if(
$cmd ==
"" && isset(
$_POST[
"table_top_cmd"]))
989 $this->verified_cmd =
$cmd;
992 if(
$cmd ==
"" && isset(
$_POST[
"select_cmd2"]))
994 if(isset(
$_POST[
"select_cmd_all2"]))
1000 $_POST[
"select_cmd_all"] =
$_POST[
"select_cmd_all2"] = null;
1003 $this->verified_cmd =
$cmd;
1005 if(
$cmd ==
"" && isset(
$_POST[
"select_cmd"]))
1007 if(isset(
$_POST[
"select_cmd_all"]))
1013 $_POST[
"select_cmd_all"] =
$_POST[
"select_cmd_all2"] = null;
1016 $this->verified_cmd =
$cmd;
1021 $this->verified_cmd =
$cmd;
1026 $cmd = $a_default_cmd;
1043 $_GET[
"cmd"] = $a_cmd;
1058 $a_cmd_class = strtolower($a_cmd_class);
1060 $nr = $nr[
"node_id"];
1061 $_GET[
"cmdClass"] = $a_cmd_class;
1062 $_GET[
"cmdNode"] = $nr;
1072 return strtolower(
$_GET[
"cmdClass"]);
1085 function getFormAction(&$a_gui_obj, $a_fallback_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1089 $a_fallback_cmd, $a_anchor, $a_asynch, $xml_style);
1106 if(!is_array($a_class))
1108 $a_class = strtolower($a_class);
1119 if ($a_fallback_cmd !=
"")
1125 if ($a_anchor !=
"")
1127 $script = $script.
"#".$a_anchor;
1154 if ($this->rtoken !=
"")
1160 if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1161 $ilUser->getId() != ANONYMOUS_USER_ID)
1163 $res = $ilDB->query(
"SELECT token FROM il_request_token WHERE user_id = ".
1164 $ilDB->quote($ilUser->getId(),
"integer").
1165 " AND session_id = ".$ilDB->quote(session_id(),
"text"));
1166 $rec = $ilDB->fetchAssoc(
$res);
1168 if ($rec[
"token"] !=
"")
1170 $this->rtoken = $rec[
"token"];
1171 return $rec[
"token"];
1174 $this->rtoken = md5(uniqid(rand(),
true));
1177 if (rand(1, 200) == 2)
1182 $dq =
"DELETE FROM il_request_token WHERE ".
1184 $ilDB->manipulate($dq);
1191 $ilDB->manipulate(
"INSERT INTO il_request_token (user_id, token, stamp, session_id) VALUES ".
1193 $ilDB->quote($ilUser->getId(),
"integer").
",".
1194 $ilDB->quote($this->rtoken,
"text").
",".
1196 $ilDB->quote(session_id(),
"text").
")");
1213 if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1214 $ilUser->getId() != ANONYMOUS_USER_ID)
1216 if (
$_GET[
"rtoken"] ==
"")
1218 #echo "ilCtrl::No Request Token Given!"; // for debugging, maybe changed later
1222 $set = $ilDB->query(
"SELECT * FROM il_request_token WHERE ".
1223 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1224 " token = ".$ilDB->quote(
$_GET[self::IL_RTOKEN_NAME]),
"text");
1225 if ($ilDB->numRows($set) > 0)
1244 $ilDB->manipulate(
"DELETE FROM il_request_token WHERE ".
1245 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1246 " session_id != ".$ilDB->quote(session_id(),
"text").
" AND ".
1263 $to_remove = array();
1266 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1268 if (time() - $time > $sec)
1270 $to_remove[] = $tok;
1273 foreach($to_remove as $tok)
1298 public function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false)
1303 "", $a_asynch,
false);
1304 if (is_object($ilBench))
1308 if ($a_anchor !=
"")
1310 $script = $script.
"#".$a_anchor;
1325 if ($a_anchor !=
"")
1327 $script = $script.
"#".$a_anchor;
1339 if (isset(
$_GET[
"cmdMode"]) &&
$_GET[
"cmdMode"] ==
"asynch")
1361 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1364 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch,
1402 $script.= $amp.
"cmdMode=asynch";
1405 if ($a_anchor !=
"")
1407 $script = $script.
"#".$a_anchor;
1419 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1421 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1430 $a_class = strtolower($a_class);
1435 $this->
return[strtolower($a_class)] = $script;
1446 "redirectSource=".strtolower(get_class($a_gui_obj)));
1448 "cmdMode=".
$_GET[
"cmdMode"]);
1449 if ($a_anchor !=
"")
1451 $script = $script.
"#".$a_anchor;
1465 return $_GET[
"redirectSource"];
1482 $a_class = strtolower($a_class);
1488 return $this->
return[$ret_class];
1500 if (is_object($a_class))
1502 $class = strtolower(get_class($a_class));
1506 $class = strtolower($a_class);
1517 $a_class = strtolower($a_class);
1520 $node = $node[
"node_id"];
1521 $n_arr = explode(
":", $node);
1522 for($i = count($n_arr)-2; $i>=0; $i--)
1543 foreach ($params as $par => $value)
1545 if (strlen((
string) $value))
1578 if (!is_array($a_class))
1580 $a_class = array($a_class);
1583 $nr = $this->current_node;
1584 foreach ($a_class as $class)
1586 $class = strtolower($class);
1588 if ($nr[
"base_class"] !=
"")
1590 $new_baseclass = $nr[
"base_class"];
1592 $nr = $nr[
"node_id"];
1593 $target_class = $class;
1600 foreach(
$path as $node_id)
1602 $class = ($node_id ==
"")
1603 ? strtolower(
$_GET[
"baseClass"])
1605 if (isset($this->save_parameter[$class]) && is_array($this->save_parameter[$class]))
1607 foreach($this->save_parameter[$class] as $par)
1609 if (isset(
$_GET[$par]))
1611 $params[$par] =
$_GET[$par];
1613 else if (isset(
$_POST[$par]))
1615 $params[$par] =
$_POST[$par];
1620 if (isset($this->parameter[$class]) && is_array($this->parameter[$class]))
1622 foreach($this->parameter[$class] as $par => $value)
1624 $params[$par] = $value;
1631 $params[
"cmd"] = $a_cmd;
1634 $params[
"cmdClass"] = $target_class;
1635 $params[
"cmdNode"] = $nr;
1636 if($new_baseclass ==
"")
1638 $params[
"baseClass"] =
$_GET[
"baseClass"];
1642 $params[
"baseClass"] = $new_baseclass;
1653 if ($this->class_cid[$a_class] ==
"")
1657 if ($this->class_cid[$a_class] ==
"")
1665 $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
1666 may solve the issue by putting an empty * @ilCtrl_Calls [YourClassName]: into your class header.".
1667 " In both cases you need to reload the control structure in the setup.";
1669 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
1670 throw new ilCtrlException(
"Cannot find cid for class ".$a_class.
".".$add);
1672 return $this->class_cid[$a_class];
1680 if ($this->cid_class[$a_cid] ==
"")
1684 if ($this->cid_class[$a_cid] ==
"")
1686 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
1689 return $this->cid_class[$a_cid];
1701 if (isset($this->info_read_cid[$a_cid]))
1707 $rec = $cached_ctrl->lookupCid($a_cid);
1715 $this->cid_class[$a_cid] = $rec[
"class"];
1716 $this->class_cid[$rec[
"class"]] = $a_cid;
1718 $calls = $cached_ctrl->lookupCall($rec[
"class"]);
1726 if (!isset($this->calls[$rec[
"class"]]) || !is_array($this->calls[$rec[
"class"]]) || !in_array($rec2[
"child"], $this->calls[$rec[
"class"]]))
1728 if ($rec2[
"child"] !=
"")
1730 $this->calls[$rec[
"class"]][] = $rec2[
"child"];
1734 $this->info_read_class[$rec[
"class"]] =
true;
1737 $this->info_read_cid[$a_cid] =
true;
1747 $n_arr = explode(
":", $a_node);
1748 foreach ($n_arr as $cid)
1763 $a_class = strtolower($a_class);
1764 if (isset($this->info_read_class[$a_class]))
1770 $rec = $cached_ctrl->lookupClassFile($a_class);
1779 $this->cid_class[$rec[
"cid"]] = $a_class;
1780 $this->class_cid[$a_class] = $rec[
"cid"];
1786 $recs = $cached_ctrl->lookupCall($a_class);
1788 foreach($recs as $rec)
1790 if (!isset($this->calls[$a_class]) || !is_array($this->calls[$a_class]) || !in_array($rec[
"child"], $this->calls[$a_class]))
1792 if ($rec[
"child"] !=
"")
1794 $this->calls[$a_class][] = $rec[
"child"];
1799 $this->info_read_class[$a_class] =
true;
1800 $this->info_read_cid[$this->class_cid[$a_class]] =
true;
1808 $n_arr = explode(
":", $a_node);
1809 return $n_arr[count($n_arr) - 2];
1817 $lpos = strrpos($a_node,
":");
1818 return substr($a_node, 0, $lpos);
1826 $n_arr = explode(
":", $a_node);
1827 return $n_arr[count($n_arr) - 1];
1840 $a_parent = strtolower($a_parent);
1841 $a_child = strtolower($a_child);
1842 $a_comp_prefix = strtolower($a_comp_prefix);
1844 $set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE ".
1845 " parent = ".$ilDB->quote($a_parent,
"text").
" AND ".
1846 " child = ".$ilDB->quote($a_child,
"text").
" AND ".
1847 " comp_prefix = ".$ilDB->quote($a_comp_prefix,
"text")
1849 if ($rec = $ilDB->fetchAssoc($set))
1853 $ilDB->manipulate(
"INSERT INTO ctrl_calls ".
1854 "(parent, child, comp_prefix) VALUES (".
1855 $ilDB->quote($a_parent,
"text").
",".
1856 $ilDB->quote($a_child,
"text").
",".
1857 $ilDB->quote($a_comp_prefix,
"text").