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)
1217 $ilDB->manipulate(
"DELETE FROM il_request_token WHERE ".
1218 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1219 " session_id != ".$ilDB->quote(session_id(),
"text"));
1235 $to_remove = array();
1238 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1240 if (time() - $time > $sec)
1242 $to_remove[] = $tok;
1245 foreach($to_remove as $tok)
1270 public function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false)
1275 "", $a_asynch,
false);
1276 if (is_object($ilBench))
1280 if ($a_anchor !=
"")
1282 $script = $script.
"#".$a_anchor;
1297 if ($a_anchor !=
"")
1299 $script = $script.
"#".$a_anchor;
1311 if (isset(
$_GET[
"cmdMode"]) &&
$_GET[
"cmdMode"] ==
"asynch")
1333 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1336 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch,
1374 $script.= $amp.
"cmdMode=asynch";
1377 if ($a_anchor !=
"")
1379 $script = $script.
"#".$a_anchor;
1391 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1393 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1402 $a_class = strtolower($a_class);
1407 $this->
return[strtolower($a_class)] = $script;
1418 "redirectSource=".strtolower(get_class($a_gui_obj)));
1420 "cmdMode=".
$_GET[
"cmdMode"]);
1421 if ($a_anchor !=
"")
1423 $script = $script.
"#".$a_anchor;
1437 return $_GET[
"redirectSource"];
1454 $a_class = strtolower($a_class);
1460 return $this->
return[$ret_class];
1472 if (is_object($a_class))
1474 $class = strtolower(get_class($a_class));
1478 $class = strtolower($a_class);
1489 $a_class = strtolower($a_class);
1492 $node = $node[
"node_id"];
1493 $n_arr = explode(
":", $node);
1494 for($i = count($n_arr)-2; $i>=0; $i--)
1515 foreach ($params as $par => $value)
1517 if (strlen((
string) $value))
1550 if (!is_array($a_class))
1552 $a_class = array($a_class);
1555 $nr = $this->current_node;
1556 foreach ($a_class as $class)
1558 $class = strtolower($class);
1560 if ($nr[
"base_class"] !=
"")
1562 $new_baseclass = $nr[
"base_class"];
1564 $nr = $nr[
"node_id"];
1565 $target_class = $class;
1572 foreach(
$path as $node_id)
1574 $class = ($node_id ==
"")
1575 ? strtolower(
$_GET[
"baseClass"])
1577 if (isset($this->save_parameter[$class]) && is_array($this->save_parameter[$class]))
1579 foreach($this->save_parameter[$class] as $par)
1581 if (isset(
$_GET[$par]))
1583 $params[$par] =
$_GET[$par];
1585 else if (isset(
$_POST[$par]))
1587 $params[$par] =
$_POST[$par];
1592 if (isset($this->parameter[$class]) && is_array($this->parameter[$class]))
1594 foreach($this->parameter[$class] as $par => $value)
1596 $params[$par] = $value;
1603 $params[
"cmd"] = $a_cmd;
1606 $params[
"cmdClass"] = $target_class;
1607 $params[
"cmdNode"] = $nr;
1608 if($new_baseclass ==
"")
1610 $params[
"baseClass"] =
$_GET[
"baseClass"];
1614 $params[
"baseClass"] = $new_baseclass;
1625 if ($this->class_cid[$a_class] ==
"")
1629 if ($this->class_cid[$a_class] ==
"")
1637 $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
1638 may solve the issue by putting an empty * @ilCtrl_Calls [YourClassName]: into your class header.".
1639 " In both cases you need to reload the control structure in the setup.";
1641 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
1642 throw new ilCtrlException(
"Cannot find cid for class ".$a_class.
".".$add);
1644 return $this->class_cid[$a_class];
1652 if ($this->cid_class[$a_cid] ==
"")
1656 if ($this->cid_class[$a_cid] ==
"")
1658 include_once(
"./Services/UICore/exceptions/class.ilCtrlException.php");
1661 return $this->cid_class[$a_cid];
1673 if (isset($this->info_read_cid[$a_cid]))
1677 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1678 " WHERE cid = ".$ilDB->quote($a_cid,
"text")
1680 if ($rec = $ilDB->fetchAssoc($set))
1682 $this->cid_class[$a_cid] = $rec[
"class"];
1683 $this->class_cid[$rec[
"class"]] = $a_cid;
1685 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1686 " WHERE parent = ".$ilDB->quote($rec[
"class"],
"text")
1688 while ($rec2 = $ilDB->fetchAssoc($set))
1690 if (!isset($this->calls[$rec[
"class"]]) || !is_array($this->calls[$rec[
"class"]]) || !in_array($rec2[
"child"], $this->calls[$rec[
"class"]]))
1692 if ($rec2[
"child"] !=
"")
1694 $this->calls[$rec[
"class"]][] = $rec2[
"child"];
1698 $this->info_read_class[$rec[
"class"]] =
true;
1701 $this->info_read_cid[$a_cid] =
true;
1711 $n_arr = explode(
":", $a_node);
1712 foreach ($n_arr as $cid)
1727 $a_class = strtolower($a_class);
1728 if (isset($this->info_read_class[$a_class]))
1732 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1733 " WHERE class = ".$ilDB->quote($a_class,
"text")
1735 if ($rec = $ilDB->fetchAssoc($set))
1737 $this->cid_class[$rec[
"cid"]] = $a_class;
1738 $this->class_cid[$a_class] = $rec[
"cid"];
1741 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1742 " WHERE parent = ".$ilDB->quote($a_class,
"text")
1744 while ($rec = $ilDB->fetchAssoc($set))
1746 if (!isset($this->calls[$a_class]) || !is_array($this->calls[$a_class]) || !in_array($rec[
"child"], $this->calls[$a_class]))
1748 if ($rec[
"child"] !=
"")
1750 $this->calls[$a_class][] = $rec[
"child"];
1755 $this->info_read_class[$a_class] =
true;
1756 $this->info_read_cid[$this->class_cid[$a_class]] =
true;
1764 $n_arr = explode(
":", $a_node);
1765 return $n_arr[count($n_arr) - 2];
1773 $lpos = strrpos($a_node,
":");
1774 return substr($a_node, 0, $lpos);
1782 $n_arr = explode(
":", $a_node);
1783 return $n_arr[count($n_arr) - 1];
1796 $a_parent = strtolower($a_parent);
1797 $a_child = strtolower($a_child);
1798 $a_comp_prefix = strtolower($a_comp_prefix);
1800 $set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE ".
1801 " parent = ".$ilDB->quote($a_parent,
"text").
" AND ".
1802 " child = ".$ilDB->quote($a_child,
"text").
" AND ".
1803 " comp_prefix = ".$ilDB->quote($a_comp_prefix,
"text")
1805 if ($rec = $ilDB->fetchAssoc($set))
1809 $ilDB->manipulate(
"INSERT INTO ctrl_calls ".
1810 "(parent, child, comp_prefix) VALUES (".
1811 $ilDB->quote($a_parent,
"text").
",".
1812 $ilDB->quote($a_child,
"text").
",".
1813 $ilDB->quote($a_comp_prefix,
"text").