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 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
126 throw new ilCtrlException(
"Could not find entry in modules.xml or services.xml for ".
127 $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));
167 $nr = $nr[
"node_id"];
170 $current_node = $this->current_node;
172 $this->current_node = $nr;
176 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
177 "mode" =>
"execComm",
"cmd" => $this->
getCmd());
180 $html = $a_gui_object->executeCommand();
183 $this->current_node = $current_node;
189 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
202 $class = strtolower(get_class($a_gui_object));
205 $nr = $nr[
"node_id"];
208 $current_node = $this->current_node;
211 $this->current_node = $nr;
215 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
216 "mode" =>
"getHtml",
"cmd" => $this->
getCmd());
219 $html = $a_gui_object->getHTML();
222 $this->current_node = $current_node;
228 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
242 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
244 $this->context_obj_id = $a_obj_id;
245 $this->context_obj_type = $a_obj_type;
246 $this->context_sub_obj_id = $a_sub_obj_id;
247 $this->context_sub_obj_type = $a_sub_obj_type;
257 return $this->context_obj_id;
267 return $this->context_obj_type;
277 return $this->context_sub_obj_id;
287 return $this->context_sub_obj_type;
310 $class = strtolower($a_class);
313 if ($a_par_node === 0 || $a_par_node ==
"")
326 return array(
"node_id" => $a_par_node,
333 in_array($a_class, $this->calls[$this->
getClassForCid($node_cid)]))
335 return array(
"node_id" => $a_par_node.
":".$this->getCidForClass($class),
344 in_array($a_class, $this->calls[$this->
getClassForCid($par_cid)]))
346 return array(
"node_id" =>
354 while($temp_node !=
"")
359 return array(
"node_id" => $temp_node,
372 $mc_set = $ilDB->query(
"SELECT * FROM module_class WHERE LOWER(class) = ".
373 $ilDB->quote($class,
"text"));
374 $mc_rec = $ilDB->fetchAssoc($mc_set);
375 $n_class = strtolower($mc_rec[
"class"]);
379 $mc_set = $ilDB->query(
"SELECT * FROM service_class WHERE LOWER(class) = ".
380 $ilDB->quote($class,
"text"));
381 $mc_rec = $ilDB->fetchAssoc($mc_set);
382 $n_class = strtolower($mc_rec[
"class"]);
389 "base_class" => $class);
404 error_log(
"ERROR: Can't find target class $a_class for node $a_par_node ".
412 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
413 throw new ilCtrlException(
"ERROR: Can't find target class $a_class for node $a_par_node ".
425 if (!is_array($a_class))
427 $a_class = array($a_class);
430 $nr = $this->current_node;
431 foreach ($a_class as $class)
433 $class = strtolower($class);
441 $nr = $nr[
"node_id"];
457 return $_GET[
"cmdNode"];
467 function addLocation($a_title, $a_link, $a_target =
"", $a_ref_id = 0)
469 $this->location[] = array(
"title" => $a_title,
470 "link" => $a_link,
"target" => $a_target,
"ref_id" => $a_ref_id);
491 function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
493 $a_class = strtolower($a_class);
495 $this->tab[] = array(
"lang_var" => $a_lang_var,
496 "link" => $a_link,
"cmd" => $a_cmd,
"class" => $a_class);
573 $a_class = strtolower($a_class);
578 $this->call_node[$a_nr] = array(
"class" => $a_class,
"parent" => $a_parent);
581 $call_set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE parent = ".
582 $ilDB->quote(strtolower($a_class),
"text").
583 " ORDER BY child", array(
"text"));
585 while ($call_rec = $ilDB->fetchAssoc($call_set))
588 $forw[] = $call_rec[
"child"];
596 $this->root_class = $a_class;
607 private function forwards($a_from_class, $a_to_class)
609 $a_from_class = strtolower($a_from_class);
611 if (is_array($a_to_class))
613 foreach($a_to_class as $to_class)
615 if ($a_from_class !=
"" && $to_class !=
"")
617 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
619 $this->forward[$a_from_class][] = strtolower($to_class);
621 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
623 $this->parent[strtolower($to_class)][] = $a_from_class;
630 $to_class = $a_to_class;
631 if ($a_from_class !=
"" && $to_class !=
"")
633 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
635 $this->forward[$a_from_class][] = strtolower($to_class);
637 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
639 $this->parent[strtolower($to_class)][] = $a_from_class;
667 if (is_object($a_obj))
681 if (is_array($a_parameter))
683 foreach($a_parameter as $parameter)
685 $this->save_parameter[strtolower($a_class)][] = $parameter;
690 $this->save_parameter[strtolower($a_class)][] = $a_parameter;
719 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
732 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
755 $this->parameter[strtolower($a_class)] = array();
776 if ($this->current_node == $cmdNode)
803 $a_class_name = strtolower($a_class_name);
805 $class_set = $ilDB->query(
"SELECT * FROM ctrl_classfile WHERE class = ".
806 $ilDB->quote($a_class_name,
"text"));
807 $class_rec = $ilDB->fetchAssoc($class_set);
809 if ($class_rec[
"plugin_path"] !=
"")
811 return $class_rec[
"plugin_path"].
"/".$class_rec[
"filename"];
815 return $class_rec[
"filename"];
829 $path = pathinfo($a_class_path);
831 $class = substr(
$file, 6, strlen(
$file) - 10);
847 if ($a_source_node ==
"1")
851 if (substr($a_target_node, 0, strlen($a_source_node)) != $a_source_node)
853 $failure =
"ERROR: Path not found. Source:".$a_source_node.
854 ", Target:".$a_target_node;
857 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
864 $temp_node = $a_source_node;
867 if ($a_source_node !=
"")
869 $path = array($a_source_node);
872 $diffstart = ($a_source_node ==
"")
874 : strlen($a_source_node) + 1;
875 $diff = substr($a_target_node, $diffstart);
877 $diff_arr = explode(
":", $diff);
878 foreach($diff_arr as $cid)
880 if ($temp_node !=
"")
885 $path[] = $temp_node;
899 $this->target_script = $a_target_script;
924 $_GET[
"baseClass"] = $a_base_class;
926 $_GET[
"cmdClass"] =
"";
927 $_GET[
"cmdNode"] =
"";
938 public function getCmd($a_default_cmd =
"", $a_safe_commands =
"")
941 if (isset(
$_GET[
"cmd"]))
954 if ($this->verified_cmd !=
"")
956 return $this->verified_cmd;
961 (!is_array($a_safe_commands) || !in_array(
$cmd, $a_safe_commands)))
963 return $a_default_cmd;
967 $this->verified_cmd =
$cmd;
968 if(
$cmd ==
"" && isset(
$_POST[
"table_top_cmd"]))
971 $this->verified_cmd =
$cmd;
974 if(
$cmd ==
"" && isset(
$_POST[
"select_cmd2"]))
976 if(isset(
$_POST[
"select_cmd_all2"]))
982 $_POST[
"select_cmd_all"] =
$_POST[
"select_cmd_all2"] = null;
985 $this->verified_cmd =
$cmd;
989 if(isset(
$_POST[
"select_cmd_all"]))
995 $_POST[
"select_cmd_all"] =
$_POST[
"select_cmd_all2"] = null;
998 $this->verified_cmd =
$cmd;
1003 $this->verified_cmd =
$cmd;
1008 $cmd = $a_default_cmd;
1025 $_GET[
"cmd"] = $a_cmd;
1040 $a_cmd_class = strtolower($a_cmd_class);
1042 $nr = $nr[
"node_id"];
1043 $_GET[
"cmdClass"] = $a_cmd_class;
1044 $_GET[
"cmdNode"] = $nr;
1054 return strtolower(
$_GET[
"cmdClass"]);
1067 function getFormAction(&$a_gui_obj, $a_fallback_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1071 $a_fallback_cmd, $a_anchor, $a_asynch, $xml_style);
1088 if(!is_array($a_class))
1090 $a_class = strtolower($a_class);
1101 if ($a_fallback_cmd !=
"")
1107 if ($a_anchor !=
"")
1109 $script = $script.
"#".$a_anchor;
1136 if ($this->rtoken !=
"")
1142 if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1143 $ilUser->getId() != ANONYMOUS_USER_ID)
1145 $res = $ilDB->query(
"SELECT token FROM il_request_token WHERE user_id = ".
1146 $ilDB->quote($ilUser->getId(),
"integer").
1147 " AND session_id = ".$ilDB->quote(session_id(),
"text"));
1148 $rec = $ilDB->fetchAssoc(
$res);
1150 if ($rec[
"token"] !=
"")
1152 $this->rtoken = $rec[
"token"];
1153 return $rec[
"token"];
1156 $this->rtoken = md5(uniqid(rand(),
true));
1159 if (rand(1, 200) == 2)
1164 $dq =
"DELETE FROM il_request_token WHERE ".
1166 $ilDB->manipulate($dq);
1173 $ilDB->manipulate(
"INSERT INTO il_request_token (user_id, token, stamp, session_id) VALUES ".
1175 $ilDB->quote($ilUser->getId(),
"integer").
",".
1176 $ilDB->quote($this->rtoken,
"text").
",".
1178 $ilDB->quote(session_id(),
"text").
")");
1195 if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1196 $ilUser->getId() != ANONYMOUS_USER_ID)
1198 if (
$_GET[
"rtoken"] ==
"")
1200 #echo "ilCtrl::No Request Token Given!"; // for debugging, maybe changed later
1204 $set = $ilDB->query(
"SELECT * FROM il_request_token WHERE ".
1205 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1206 " token = ".$ilDB->quote(
$_GET[self::IL_RTOKEN_NAME]),
"text");
1207 if ($ilDB->numRows($set) > 0)
1226 $ilDB->manipulate(
"DELETE FROM il_request_token WHERE ".
1227 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1228 " session_id != ".$ilDB->quote(session_id(),
"text").
" AND ".
1245 $to_remove = array();
1248 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1250 if (time() - $time > $sec)
1252 $to_remove[] = $tok;
1255 foreach($to_remove as $tok)
1280 public function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false)
1285 "", $a_asynch,
false);
1286 if (is_object($ilBench))
1290 if ($a_anchor !=
"")
1292 $script = $script.
"#".$a_anchor;
1307 if ($a_anchor !=
"")
1309 $script = $script.
"#".$a_anchor;
1321 if (isset(
$_GET[
"cmdMode"]) &&
$_GET[
"cmdMode"] ==
"asynch")
1343 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1346 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch,
1384 $script.= $amp.
"cmdMode=asynch";
1387 if ($a_anchor !=
"")
1389 $script = $script.
"#".$a_anchor;
1401 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1403 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1412 $a_class = strtolower($a_class);
1417 $this->
return[strtolower($a_class)] = $script;
1428 "redirectSource=".strtolower(get_class($a_gui_obj)));
1430 "cmdMode=".
$_GET[
"cmdMode"]);
1431 if ($a_anchor !=
"")
1433 $script = $script.
"#".$a_anchor;
1447 return $_GET[
"redirectSource"];
1464 $a_class = strtolower($a_class);
1470 return $this->
return[$ret_class];
1482 if (is_object($a_class))
1484 $class = strtolower(get_class($a_class));
1488 $class = strtolower($a_class);
1499 $a_class = strtolower($a_class);
1502 $node = $node[
"node_id"];
1503 $n_arr = explode(
":", $node);
1504 for($i = count($n_arr)-2; $i>=0; $i--)
1525 foreach ($params as $par => $value)
1527 if (strlen((
string) $value))
1560 if (!is_array($a_class))
1562 $a_class = array($a_class);
1565 $nr = $this->current_node;
1566 foreach ($a_class as $class)
1568 $class = strtolower($class);
1570 if ($nr[
"base_class"] !=
"")
1572 $new_baseclass = $nr[
"base_class"];
1574 $nr = $nr[
"node_id"];
1575 $target_class = $class;
1582 foreach(
$path as $node_id)
1584 $class = ($node_id ==
"")
1585 ? strtolower(
$_GET[
"baseClass"])
1587 if (isset($this->save_parameter[$class]) && is_array($this->save_parameter[$class]))
1589 foreach($this->save_parameter[$class] as $par)
1591 if (isset(
$_GET[$par]))
1593 $params[$par] =
$_GET[$par];
1595 else if (isset(
$_POST[$par]))
1597 $params[$par] =
$_POST[$par];
1602 if (isset($this->parameter[$class]) && is_array($this->parameter[$class]))
1604 foreach($this->parameter[$class] as $par => $value)
1606 $params[$par] = $value;
1613 $params[
"cmd"] = $a_cmd;
1616 $params[
"cmdClass"] = $target_class;
1617 $params[
"cmdNode"] = $nr;
1618 if($new_baseclass ==
"")
1620 $params[
"baseClass"] =
$_GET[
"baseClass"];
1624 $params[
"baseClass"] = $new_baseclass;
1635 if ($this->class_cid[$a_class] ==
"")
1639 if ($this->class_cid[$a_class] ==
"")
1647 $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
1648 may solve the issue by putting an empty * @ilCtrl_Calls [YourClassName]: into your class header.".
1649 " In both cases you need to reload the control structure in the setup.";
1651 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
1652 throw new ilCtrlException(
"Cannot find cid for class ".$a_class.
".".$add);
1654 return $this->class_cid[$a_class];
1662 if ($this->cid_class[$a_cid] ==
"")
1666 if ($this->cid_class[$a_cid] ==
"")
1668 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
1671 return $this->cid_class[$a_cid];
1683 if (isset($this->info_read_cid[$a_cid]))
1687 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1688 " WHERE cid = ".$ilDB->quote($a_cid,
"text")
1690 if ($rec = $ilDB->fetchAssoc($set))
1692 $this->cid_class[$a_cid] = $rec[
"class"];
1693 $this->class_cid[$rec[
"class"]] = $a_cid;
1695 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1696 " WHERE parent = ".$ilDB->quote($rec[
"class"],
"text")
1698 while ($rec2 = $ilDB->fetchAssoc($set))
1700 if (!isset($this->calls[$rec[
"class"]]) || !is_array($this->calls[$rec[
"class"]]) || !in_array($rec2[
"child"], $this->calls[$rec[
"class"]]))
1702 if ($rec2[
"child"] !=
"")
1704 $this->calls[$rec[
"class"]][] = $rec2[
"child"];
1708 $this->info_read_class[$rec[
"class"]] =
true;
1711 $this->info_read_cid[$a_cid] =
true;
1721 $n_arr = explode(
":", $a_node);
1722 foreach ($n_arr as $cid)
1737 $a_class = strtolower($a_class);
1738 if (isset($this->info_read_class[$a_class]))
1742 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1743 " WHERE class = ".$ilDB->quote($a_class,
"text")
1745 if ($rec = $ilDB->fetchAssoc($set))
1747 $this->cid_class[$rec[
"cid"]] = $a_class;
1748 $this->class_cid[$a_class] = $rec[
"cid"];
1751 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1752 " WHERE parent = ".$ilDB->quote($a_class,
"text")
1754 while ($rec = $ilDB->fetchAssoc($set))
1756 if (!isset($this->calls[$a_class]) || !is_array($this->calls[$a_class]) || !in_array($rec[
"child"], $this->calls[$a_class]))
1758 if ($rec[
"child"] !=
"")
1760 $this->calls[$a_class][] = $rec[
"child"];
1765 $this->info_read_class[$a_class] =
true;
1766 $this->info_read_cid[$this->class_cid[$a_class]] =
true;
1774 $n_arr = explode(
":", $a_node);
1775 return $n_arr[count($n_arr) - 2];
1783 $lpos = strrpos($a_node,
":");
1784 return substr($a_node, 0, $lpos);
1792 $n_arr = explode(
":", $a_node);
1793 return $n_arr[count($n_arr) - 1];
1806 $a_parent = strtolower($a_parent);
1807 $a_child = strtolower($a_child);
1808 $a_comp_prefix = strtolower($a_comp_prefix);
1810 $set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE ".
1811 " parent = ".$ilDB->quote($a_parent,
"text").
" AND ".
1812 " child = ".$ilDB->quote($a_child,
"text").
" AND ".
1813 " comp_prefix = ".$ilDB->quote($a_comp_prefix,
"text")
1815 if ($rec = $ilDB->fetchAssoc($set))
1819 $ilDB->manipulate(
"INSERT INTO ctrl_calls ".
1820 "(parent, child, comp_prefix) VALUES (".
1821 $ilDB->quote($a_parent,
"text").
",".
1822 $ilDB->quote($a_child,
"text").
",".
1823 $ilDB->quote($a_comp_prefix,
"text").