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());
216 $html = $a_gui_object->getHTML();
219 $this->current_node = $current_node;
224 echo
"ERROR: Can't getHTML from class $class.";
exit;
236 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
238 $this->context_obj_id = $a_obj_id;
239 $this->context_obj_type = $a_obj_type;
240 $this->context_sub_obj_id = $a_sub_obj_id;
241 $this->context_sub_obj_type = $a_sub_obj_type;
251 return $this->context_obj_id;
261 return $this->context_obj_type;
271 return $this->context_sub_obj_id;
281 return $this->context_sub_obj_type;
304 $class = strtolower($a_class);
307 if ($a_par_node === 0 || $a_par_node ==
"")
326 in_array($a_class, $this->calls[$this->
getClassForCid($node_cid)]))
336 in_array($a_class, $this->calls[$this->
getClassForCid($par_cid)]))
344 while($temp_node !=
"")
362 echo
"ERROR: Can't find target class $a_class for node $a_par_node ".
364 error_log(
"ERROR: Can't find target class $a_class for node $a_par_node ".
375 echo
"<pre>".$e->getTraceAsString().
"</pre>";
390 if (!is_array($a_class))
392 $a_class = array($a_class);
395 $nr = $this->current_node;
396 foreach ($a_class as $class)
398 $class = strtolower($class);
421 return $_GET[
"cmdNode"];
431 function addLocation($a_title, $a_link, $a_target =
"", $a_ref_id = 0)
433 $this->location[] = array(
"title" => $a_title,
434 "link" => $a_link,
"target" => $a_target,
"ref_id" => $a_ref_id);
455 function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
457 $a_class = strtolower($a_class);
459 $this->tab[] = array(
"lang_var" => $a_lang_var,
460 "link" => $a_link,
"cmd" => $a_cmd,
"class" => $a_class);
537 $a_class = strtolower($a_class);
542 $this->call_node[$a_nr] = array(
"class" => $a_class,
"parent" => $a_parent);
545 $call_set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE parent = ".
546 $ilDB->quote(strtolower($a_class),
"text").
547 " ORDER BY child", array(
"text"));
549 while ($call_rec = $ilDB->fetchAssoc($call_set))
552 $forw[] = $call_rec[
"child"];
560 $this->root_class = $a_class;
571 private function forwards($a_from_class, $a_to_class)
573 $a_from_class = strtolower($a_from_class);
575 if (is_array($a_to_class))
577 foreach($a_to_class as $to_class)
579 if ($a_from_class !=
"" && $to_class !=
"")
581 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
583 $this->forward[$a_from_class][] = strtolower($to_class);
585 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
587 $this->parent[strtolower($to_class)][] = $a_from_class;
594 $to_class = $a_to_class;
595 if ($a_from_class !=
"" && $to_class !=
"")
597 if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class]))
599 $this->forward[$a_from_class][] = strtolower($to_class);
601 if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)]))
603 $this->parent[strtolower($to_class)][] = $a_from_class;
631 if (is_object($a_obj))
645 if (is_array($a_parameter))
647 foreach($a_parameter as $parameter)
649 $this->save_parameter[strtolower($a_class)][] = $parameter;
654 $this->save_parameter[strtolower($a_class)][] = $a_parameter;
683 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
696 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
719 $this->parameter[strtolower($a_class)] = array();
740 if ($this->current_node == $cmdNode)
767 $a_class_name = strtolower($a_class_name);
769 $class_set = $ilDB->query(
"SELECT * FROM ctrl_classfile WHERE class = ".
770 $ilDB->quote($a_class_name,
"text"));
771 $class_rec = $ilDB->fetchAssoc($class_set);
773 if ($class_rec[
"plugin_path"] !=
"")
775 return $class_rec[
"plugin_path"].
"/".$class_rec[
"filename"];
779 return $class_rec[
"filename"];
793 $path = pathinfo($a_class_path);
795 $class = substr(
$file, 6, strlen(
$file) - 10);
811 if ($a_source_node ==
"1")
815 if (substr($a_target_node, 0, strlen($a_source_node)) != $a_source_node)
817 echo
"ERROR: Path not found. Source:".$a_source_node.
818 ", Target:".$a_target_node;
822 $temp_node = $a_source_node;
825 if ($a_source_node !=
"")
827 $path = array($a_source_node);
830 $diffstart = ($a_source_node ==
"")
832 : strlen($a_source_node) + 1;
833 $diff = substr($a_target_node, $diffstart);
835 $diff_arr = explode(
":",
$diff);
836 foreach($diff_arr as $cid)
838 if ($temp_node !=
"")
843 $path[] = $temp_node;
857 $this->target_script = $a_target_script;
882 $_GET[
"baseClass"] = $a_base_class;
884 $_GET[
"cmdClass"] =
"";
885 $_GET[
"cmdNode"] =
"";
896 public function getCmd($a_default_cmd =
"", $a_safe_commands =
"")
899 if (isset(
$_GET[
"cmd"]))
912 if ($this->verified_cmd !=
"")
914 return $this->verified_cmd;
919 (!is_array($a_safe_commands) || !in_array(
$cmd, $a_safe_commands)))
925 $this->verified_cmd =
$cmd;
926 if(
$cmd ==
"" && isset(
$_POST[
"table_top_cmd"]))
929 $this->verified_cmd =
$cmd;
932 if(
$cmd ==
"" && isset(
$_POST[
"select_cmd2"]))
935 $this->verified_cmd =
$cmd;
940 $this->verified_cmd =
$cmd;
945 $this->verified_cmd =
$cmd;
950 $cmd = $a_default_cmd;
967 $_GET[
"cmd"] = $a_cmd;
982 $a_cmd_class = strtolower($a_cmd_class);
984 $_GET[
"cmdClass"] = $a_cmd_class;
985 $_GET[
"cmdNode"] = $nr;
995 return strtolower(
$_GET[
"cmdClass"]);
1008 function getFormAction(&$a_gui_obj, $a_fallback_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1012 $a_fallback_cmd, $a_anchor, $a_asynch, $xml_style);
1029 $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 return $rec[
"token"];
1093 $this->rtoken = md5(uniqid(rand(),
true));
1096 if (rand(1, 50) == 2)
1100 $dq =
"DELETE FROM il_request_token WHERE ".
1102 $ilDB->manipulate($dq);
1108 $ilDB->manipulate(
"INSERT INTO il_request_token (user_id, token, stamp, session_id) VALUES ".
1110 $ilDB->quote($ilUser->getId(),
"integer").
",".
1111 $ilDB->quote($this->rtoken,
"text").
",".
1113 $ilDB->quote(session_id(),
"text").
")");
1128 global
$ilDB, $ilUser;
1130 if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1131 $ilUser->getId() != ANONYMOUS_USER_ID)
1133 if (
$_GET[
"rtoken"] ==
"")
1135 echo
"ilCtrl::No Request Token Given!";
1139 $set = $ilDB->query(
"SELECT * FROM il_request_token WHERE ".
1140 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1141 " token = ".$ilDB->quote(
$_GET[self::IL_RTOKEN_NAME]),
"text");
1142 if ($ilDB->numRows($set) > 0)
1152 $ilDB->manipulate(
"DELETE FROM il_request_token WHERE ".
1153 " user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
" AND ".
1154 " session_id != ".$ilDB->quote(session_id(),
"text"));
1170 $to_remove = array();
1173 foreach(
$_SESSION[
"rtokens"] as $tok => $time)
1175 if (time() - $time > $sec)
1177 $to_remove[] = $tok;
1180 foreach($to_remove as $tok)
1205 public function redirect(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"")
1211 if (is_object($ilBench))
1215 if ($a_anchor !=
"")
1217 $script = $script.
"#".$a_anchor;
1242 if (isset(
$_GET[
"cmdMode"]) &&
$_GET[
"cmdMode"] ==
"asynch")
1264 function getLinkTarget(&$a_gui_obj, $a_cmd =
"", $a_anchor =
"", $a_asynch =
false,
1267 $script = $this->
getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch,
1305 $script.= $amp.
"cmdMode=asynch";
1308 if ($a_anchor !=
"")
1310 $script = $script.
"#".$a_anchor;
1322 $script = $this->
getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1324 $this->
return[strtolower(get_class($a_gui_obj))] = $script;
1333 $a_class = strtolower($a_class);
1338 $this->
return[strtolower($a_class)] = $script;
1349 "redirectSource=".strtolower(get_class($a_gui_obj)));
1351 "cmdMode=".
$_GET[
"cmdMode"]);
1352 if ($a_anchor !=
"")
1354 $script = $script.
"#".$a_anchor;
1368 return $_GET[
"redirectSource"];
1385 $a_class = strtolower($a_class);
1391 return $this->
return[$ret_class];
1400 $a_class = strtolower($a_class);
1403 $n_arr = explode(
":", $node);
1404 for($i = count($n_arr)-2; $i>=0; $i--)
1425 foreach ($params as $par => $value)
1460 if (!is_array($a_class))
1462 $a_class = array($a_class);
1465 $nr = $this->current_node;
1466 foreach ($a_class as $class)
1468 $class = strtolower($class);
1470 $target_class = $class;
1477 foreach(
$path as $node_id)
1479 $class = ($node_id ==
"")
1480 ? strtolower(
$_GET[
"baseClass"])
1482 if (isset($this->save_parameter[$class]) && is_array($this->save_parameter[$class]))
1484 foreach($this->save_parameter[$class] as $par)
1486 if (isset(
$_GET[$par]))
1488 $params[$par] =
$_GET[$par];
1493 if (isset($this->parameter[$class]) && is_array($this->parameter[$class]))
1495 foreach($this->parameter[$class] as $par => $value)
1497 $params[$par] = $value;
1504 $params[
"cmd"] = $a_cmd;
1507 $params[
"cmdClass"] = $target_class;
1508 $params[
"cmdNode"] = $nr;
1509 $params[
"baseClass"] =
$_GET[
"baseClass"];
1519 if ($this->class_cid[$a_class] ==
"")
1523 if ($this->class_cid[$a_class] ==
"")
1531 $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
1532 may solve the issue by putting an empty * @ilCtrl_Calls [YourClassName]: into your class header.".
1533 " In both cases you need to reload the control structure in the setup.";
1535 die(
"Cannot find cid for class ".$a_class.
".".$add);
1537 return $this->class_cid[$a_class];
1545 if ($this->cid_class[$a_cid] ==
"")
1549 if ($this->cid_class[$a_cid] ==
"")
1551 die(
"Cannot find class for cid ".$a_cid.
".");
1553 return $this->cid_class[$a_cid];
1565 if (isset($this->info_read_cid[$a_cid]))
1569 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1570 " WHERE cid = ".$ilDB->quote($a_cid,
"text")
1572 if ($rec = $ilDB->fetchAssoc($set))
1574 $this->cid_class[$a_cid] = $rec[
"class"];
1575 $this->class_cid[$rec[
"class"]] = $a_cid;
1577 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1578 " WHERE parent = ".$ilDB->quote($rec[
"class"],
"text")
1580 while ($rec2 = $ilDB->fetchAssoc($set))
1582 if (!isset($this->calls[$rec[
"class"]]) || !is_array($this->calls[$rec[
"class"]]) || !in_array($rec2[
"child"], $this->calls[$rec[
"class"]]))
1584 if ($rec2[
"child"] !=
"")
1586 $this->calls[$rec[
"class"]][] = $rec2[
"child"];
1590 $this->info_read_class[$rec[
"class"]] =
true;
1593 $this->info_read_cid[$a_cid] =
true;
1603 $n_arr = explode(
":", $a_node);
1604 foreach ($n_arr as $cid)
1619 $a_class = strtolower($a_class);
1620 if (isset($this->info_read_class[$a_class]))
1624 $set = $ilDB->query(
"SELECT * FROM ctrl_classfile ".
1625 " WHERE class = ".$ilDB->quote($a_class,
"text")
1627 if ($rec = $ilDB->fetchAssoc($set))
1629 $this->cid_class[$rec[
"cid"]] = $a_class;
1630 $this->class_cid[$a_class] = $rec[
"cid"];
1633 $set = $ilDB->query(
"SELECT * FROM ctrl_calls ".
1634 " WHERE parent = ".$ilDB->quote($a_class,
"text")
1636 while ($rec = $ilDB->fetchAssoc($set))
1638 if (!isset($this->calls[$a_class]) || !is_array($this->calls[$a_class]) || !in_array($rec[
"child"], $this->calls[$a_class]))
1640 if ($rec[
"child"] !=
"")
1642 $this->calls[$a_class][] = $rec[
"child"];
1647 $this->info_read_class[$a_class] =
true;
1648 $this->info_read_cid[$this->class_cid[$a_class]] =
true;
1656 $n_arr = explode(
":", $a_node);
1657 return $n_arr[count($n_arr) - 2];
1665 $lpos = strrpos($a_node,
":");
1666 return substr($a_node, 0, $lpos);
1674 $n_arr = explode(
":", $a_node);
1675 return $n_arr[count($n_arr) - 1];
1688 $a_parent = strtolower($a_parent);
1689 $a_child = strtolower($a_child);
1690 $a_comp_prefix = strtolower($a_comp_prefix);
1692 $set = $ilDB->query(
"SELECT * FROM ctrl_calls WHERE ".
1693 " parent = ".$ilDB->quote($a_parent,
"text").
" AND ".
1694 " child = ".$ilDB->quote($a_child,
"text").
" AND ".
1695 " comp_prefix = ".$ilDB->quote($a_comp_prefix,
"text")
1697 if ($rec = $ilDB->fetchAssoc($set))
1701 $ilDB->manipulate(
"INSERT INTO ctrl_calls ".
1702 "(parent, child, comp_prefix) VALUES (".
1703 $ilDB->quote($a_parent,
"text").
",".
1704 $ilDB->quote($a_child,
"text").
",".
1705 $ilDB->quote($a_comp_prefix,
"text").