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 echo
"Could not find entry in modules.xml or services.xml for ".
126 $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));
169 $current_node = $this->current_node;
171 $this->current_node = $nr;
175 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
176 "mode" =>
"execComm",
"cmd" => $this->
getCmd());
179 $html = $a_gui_object->executeCommand();
182 $this->current_node = $current_node;
187 echo
"ERROR: Can't forward to class $class.";
exit;
199 $class = strtolower(get_class($a_gui_object));
204 $current_node = $this->current_node;
207 $this->current_node = $nr;
211 $this->call_hist[] = array(
"class" => get_class($a_gui_object),
212 "mode" =>
"getHtml",
"cmd" => $this->
getCmd());
215 $html = $a_gui_object->getHTML();
218 $this->current_node = $current_node;
223 echo
"ERROR: Can't getHTML from class $class.";
exit;
235 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
237 $this->context_obj_id = $a_obj_id;
238 $this->context_obj_type = $a_obj_type;
239 $this->context_sub_obj_id = $a_sub_obj_id;
240 $this->context_sub_obj_type = $a_sub_obj_type;
250 return $this->context_obj_id;
260 return $this->context_obj_type;
270 return $this->context_sub_obj_id;
280 return $this->context_sub_obj_type;
303 $class = strtolower($a_class);
306 if ($a_par_node === 0 || $a_par_node ==
"")
325 in_array($a_class, $this->calls[$this->
getClassForCid($node_cid)]))
335 in_array($a_class, $this->calls[$this->
getClassForCid($par_cid)]))
343 while($temp_node !=
"")
361 echo
"ERROR: Can't find target class $a_class for node $a_par_node ".
363 error_log(
"ERROR: Can't find target class $a_class for node $a_par_node ".
382 if (!is_array($a_class))
384 $a_class = array($a_class);
387 $nr = $this->current_node;
388 foreach ($a_class as $class)
390 $class = strtolower($class);
413 return $_GET[
"cmdNode"];
423 function addLocation($a_title, $a_link, $a_target =
"", $a_ref_id = 0)
425 $this->location[] = array(
"title" => $a_title,
426 "link" => $a_link,
"target" => $a_target,
"ref_id" => $a_ref_id);
447 function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
449 $a_class = strtolower($a_class);
451 $this->tab[] = array(
"lang_var" => $a_lang_var,
452 "link" => $a_link,
"cmd" => $a_cmd,
"class" => $a_class);
529 $a_class = strtolower($a_class);
534 $this->call_node[$a_nr] = array(
"class" => $a_class,
"parent" => $a_parent);
537 $call_set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE parent = ".
538 $ilDB->quote(strtolower($a_class),
"text").
539 " ORDER BY child", array(
"text"));
541 while ($call_rec = $ilDB->fetchAssoc($call_set))
544 $forw[] = $call_rec[
"child"];
552 $this->root_class = $a_class;
563 private function forwards($a_from_class, $a_to_class)
565 $a_from_class = strtolower($a_from_class);
567 if (is_array($a_to_class))
569 foreach($a_to_class as $to_class)
571 if ($a_from_class !=
"" && $to_class !=
"")
573 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
575 $this->forward[$a_from_class][] = strtolower($to_class);
577 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
579 $this->parent[strtolower($to_class)][] = $a_from_class;
586 $to_class = $a_to_class;
587 if ($a_from_class !=
"" && $to_class !=
"")
589 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
591 $this->forward[$a_from_class][] = strtolower($to_class);
593 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
595 $this->parent[strtolower($to_class)][] = $a_from_class;
623 if (is_object($a_obj))
637 if (is_array($a_parameter))
639 foreach($a_parameter as $parameter)
641 $this->save_parameter[strtolower($a_class)][] = $parameter;
646 $this->save_parameter[strtolower($a_class)][] = $a_parameter;
675 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
688 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
711 $this->parameter[strtolower($a_class)] = array();
732 if ($this->current_node == $cmdNode)
759 $a_class_name = strtolower($a_class_name);
761 $class_set = $ilDB->query(
"SELECT * FROM ctrl_classfile WHERE class = ".
762 $ilDB->quote($a_class_name,
"text"));
763 $class_rec = $ilDB->fetchAssoc($class_set);
765 if ($class_rec[
"plugin_path"] !=
"")
767 return $class_rec[
"plugin_path"].
"/".$class_rec[
"filename"];
771 return $class_rec[
"filename"];
785 $path = pathinfo($a_class_path);
787 $class = substr(
$file, 6, strlen(
$file) - 10);
803 if ($a_source_node ==
"1")
807 if (substr($a_target_node, 0, strlen($a_source_node)) != $a_source_node)
809 echo
"ERROR: Path not found. Source:".$a_source_node.
810 ", Target:".$a_target_node;
819 $temp_node = $a_source_node;
822 if ($a_source_node !=
"")
824 $path = array($a_source_node);
827 $diffstart = ($a_source_node ==
"")
829 : strlen($a_source_node) + 1;
830 $diff = substr($a_target_node, $diffstart);
832 $diff_arr = explode(
":", $diff);
833 foreach($diff_arr as $cid)
835 if ($temp_node !=
"")
840 $path[] = $temp_node;
854 $this->target_script = $a_target_script;
879 $_GET[
"baseClass"] = $a_base_class;
881 $_GET[
"cmdClass"] =
"";
882 $_GET[
"cmdNode"] =
"";
893 public function getCmd($a_default_cmd =
"", $a_safe_commands =
"")
896 if (isset(
$_GET[
"cmd"]))
909 if ($this->verified_cmd !=
"")
911 return $this->verified_cmd;
916 (!is_array($a_safe_commands) || !in_array(
$cmd, $a_safe_commands)))
918 return $a_default_cmd;
922 $this->verified_cmd =
$cmd;
923 if(
$cmd ==
"" && isset(
$_POST[
"table_top_cmd"]))
926 $this->verified_cmd =
$cmd;
929 if(
$cmd ==
"" && isset(
$_POST[
"select_cmd2"]))
932 $this->verified_cmd =
$cmd;
937 $this->verified_cmd =
$cmd;
942 $this->verified_cmd =
$cmd;
947 $cmd = $a_default_cmd;
964 $_GET[
"cmd"] = $a_cmd;
979 $a_cmd_class = strtolower($a_cmd_class);
981 $_GET[
"cmdClass"] = $a_cmd_class;
982 $_GET[
"cmdNode"] = $nr;
992 return strtolower(
$_GET[
"cmdClass"]);
1005 function getFormAction(&$a_gui_obj, $a_fallback_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1009 $a_fallback_cmd, $a_anchor, $a_asynch, $xml_style);
1026 if(!is_array($a_class))
1028 $a_class = strtolower($a_class);
1039 if ($a_fallback_cmd !=
"")
1045 if ($a_anchor !=
"")
1047 $script = $script.
"#".$a_anchor;
1072 global
$ilDB, $ilUser;
1074 if ($this->rtoken !=
"")
1080 if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1081 $ilUser->getId() != ANONYMOUS_USER_ID)
1083 $res = $ilDB->query(
"SELECT token FROM il_request_token WHERE user_id = ".
1084 $ilDB->quote($ilUser->getId(),
"integer").
1085 " AND session_id = ".$ilDB->quote(session_id(),
"text"));
1086 $rec = $ilDB->fetchAssoc(
$res);
1088 if ($rec[
"token"] !=
"")
1090 $this->rtoken = $rec[
"token"];
1091 return $rec[
"token"];
1094 $this->rtoken = md5(uniqid(rand(),
true));
1097 if (rand(1, 200) == 2)
1102 $dq =
"DELETE FROM il_request_token WHERE ".
1104 $ilDB->manipulate($dq);
1111 $ilDB->manipulate(
"INSERT INTO il_request_token (user_id, token, stamp, session_id) VALUES ".
1113 $ilDB->quote($ilUser->getId(),
"integer").
",".
1114 $ilDB->quote($this->rtoken,
"text").
",".
1116 $ilDB->quote(session_id(),
"text").
")");
1131 global
$ilDB, $ilUser;
1133 if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1134 $ilUser->getId() != ANONYMOUS_USER_ID)
1136 if (
$_GET[
"rtoken"] ==
"")
1138 #echo "ilCtrl::No Request Token Given!"; // for debugging, maybe changed later
1142 $set = $ilDB->query(
"SELECT * FROM il_request_token WHERE ".
1143 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1144 " token = ".$ilDB->quote(
$_GET[self::IL_RTOKEN_NAME]),
"text");
1145 if ($ilDB->numRows($set) > 0)
1155 $ilDB->manipulate(
"DELETE FROM il_request_token WHERE ".
1156 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1157 " session_id != ".$ilDB->quote(session_id(),
"text"));
1173 $to_remove = array();
1176 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1178 if (time() - $time > $sec)
1180 $to_remove[] = $tok;
1183 foreach($to_remove as $tok)
1208 public function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false)
1213 "", $a_asynch,
false);
1214 if (is_object($ilBench))
1218 if ($a_anchor !=
"")
1220 $script = $script.
"#".$a_anchor;
1235 if ($a_anchor !=
"")
1237 $script = $script.
"#".$a_anchor;
1249 if (isset(
$_GET[
"cmdMode"]) &&
$_GET[
"cmdMode"] ==
"asynch")
1271 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1274 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch,
1312 $script.= $amp.
"cmdMode=asynch";
1315 if ($a_anchor !=
"")
1317 $script = $script.
"#".$a_anchor;
1329 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1331 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1340 $a_class = strtolower($a_class);
1345 $this->
return[strtolower($a_class)] = $script;
1356 "redirectSource=".strtolower(get_class($a_gui_obj)));
1358 "cmdMode=".
$_GET[
"cmdMode"]);
1359 if ($a_anchor !=
"")
1361 $script = $script.
"#".$a_anchor;
1375 return $_GET[
"redirectSource"];
1392 $a_class = strtolower($a_class);
1398 return $this->
return[$ret_class];
1410 if (is_object($a_class))
1412 $class = strtolower(get_class($a_class));
1416 $class = strtolower($a_class);
1427 $a_class = strtolower($a_class);
1430 $n_arr = explode(
":", $node);
1431 for($i = count($n_arr)-2; $i>=0; $i--)
1452 foreach ($params as $par => $value)
1454 if (strlen((
string) $value))
1487 if (!is_array($a_class))
1489 $a_class = array($a_class);
1492 $nr = $this->current_node;
1493 foreach ($a_class as $class)
1495 $class = strtolower($class);
1497 $target_class = $class;
1504 foreach(
$path as $node_id)
1506 $class = ($node_id ==
"")
1507 ? strtolower(
$_GET[
"baseClass"])
1509 if (isset($this->save_parameter[$class]) && is_array($this->save_parameter[$class]))
1511 foreach($this->save_parameter[$class] as $par)
1513 if (isset(
$_GET[$par]))
1515 $params[$par] =
$_GET[$par];
1517 else if (isset(
$_POST[$par]))
1519 $params[$par] =
$_POST[$par];
1524 if (isset($this->parameter[$class]) && is_array($this->parameter[$class]))
1526 foreach($this->parameter[$class] as $par => $value)
1528 $params[$par] = $value;
1535 $params[
"cmd"] = $a_cmd;
1538 $params[
"cmdClass"] = $target_class;
1539 $params[
"cmdNode"] = $nr;
1540 $params[
"baseClass"] =
$_GET[
"baseClass"];
1550 if ($this->class_cid[$a_class] ==
"")
1554 if ($this->class_cid[$a_class] ==
"")
1562 $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
1563 may solve the issue by putting an empty * @ilCtrl_Calls [YourClassName]: into your class header.".
1564 " In both cases you need to reload the control structure in the setup.";
1566 die(
"Cannot find cid for class ".$a_class.
".".$add);
1568 return $this->class_cid[$a_class];
1576 if ($this->cid_class[$a_cid] ==
"")
1580 if ($this->cid_class[$a_cid] ==
"")
1582 die(
"Cannot find class for cid ".$a_cid.
".");
1584 return $this->cid_class[$a_cid];
1596 if (isset($this->info_read_cid[$a_cid]))
1600 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1601 " WHERE cid = ".$ilDB->quote($a_cid,
"text")
1603 if ($rec = $ilDB->fetchAssoc($set))
1605 $this->cid_class[$a_cid] = $rec[
"class"];
1606 $this->class_cid[$rec[
"class"]] = $a_cid;
1608 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1609 " WHERE parent = ".$ilDB->quote($rec[
"class"],
"text")
1611 while ($rec2 = $ilDB->fetchAssoc($set))
1613 if (!isset($this->calls[$rec[
"class"]]) || !is_array($this->calls[$rec[
"class"]]) || !in_array($rec2[
"child"], $this->calls[$rec[
"class"]]))
1615 if ($rec2[
"child"] !=
"")
1617 $this->calls[$rec[
"class"]][] = $rec2[
"child"];
1621 $this->info_read_class[$rec[
"class"]] =
true;
1624 $this->info_read_cid[$a_cid] =
true;
1634 $n_arr = explode(
":", $a_node);
1635 foreach ($n_arr as $cid)
1650 $a_class = strtolower($a_class);
1651 if (isset($this->info_read_class[$a_class]))
1655 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1656 " WHERE class = ".$ilDB->quote($a_class,
"text")
1658 if ($rec = $ilDB->fetchAssoc($set))
1660 $this->cid_class[$rec[
"cid"]] = $a_class;
1661 $this->class_cid[$a_class] = $rec[
"cid"];
1664 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1665 " WHERE parent = ".$ilDB->quote($a_class,
"text")
1667 while ($rec = $ilDB->fetchAssoc($set))
1669 if (!isset($this->calls[$a_class]) || !is_array($this->calls[$a_class]) || !in_array($rec[
"child"], $this->calls[$a_class]))
1671 if ($rec[
"child"] !=
"")
1673 $this->calls[$a_class][] = $rec[
"child"];
1678 $this->info_read_class[$a_class] =
true;
1679 $this->info_read_cid[$this->class_cid[$a_class]] =
true;
1687 $n_arr = explode(
":", $a_node);
1688 return $n_arr[count($n_arr) - 2];
1696 $lpos = strrpos($a_node,
":");
1697 return substr($a_node, 0, $lpos);
1705 $n_arr = explode(
":", $a_node);
1706 return $n_arr[count($n_arr) - 1];
1719 $a_parent = strtolower($a_parent);
1720 $a_child = strtolower($a_child);
1721 $a_comp_prefix = strtolower($a_comp_prefix);
1723 $set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE ".
1724 " parent = ".$ilDB->quote($a_parent,
"text").
" AND ".
1725 " child = ".$ilDB->quote($a_child,
"text").
" AND ".
1726 " comp_prefix = ".$ilDB->quote($a_comp_prefix,
"text")
1728 if ($rec = $ilDB->fetchAssoc($set))
1732 $ilDB->manipulate(
"INSERT INTO ctrl_calls ".
1733 "(parent, child, comp_prefix) VALUES (".
1734 $ilDB->quote($a_parent,
"text").
",".
1735 $ilDB->quote($a_child,
"text").
",".
1736 $ilDB->quote($a_comp_prefix,
"text").