ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCtrl.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once('class.ilCachedCtrl.php');
11 class ilCtrl
12 {
16  protected $db;
17 
18 
22  protected $plugin_admin;
23 
24  const IL_RTOKEN_NAME = 'rtoken';
25 
27  public $forward; // forward array
28  public $parent; // parent array (reverse forward)
29  public $save_parameter; // save parameter array
30  public $return; // return commmands
31  public $call_hist = array(); // calling history
32  public $debug = array();
33  public $calls = array();
34  public $rtoken = false;
35 
39  public function __construct()
40  {
41  // initialisation
42  $this->init();
43 
44  // this information should go to xml files one day
45  $this->stored_trees = array("ilrepositorygui", "ilpersonaldesktopgui",
46  "illmpresentationgui", "illmeditorgui",
47  "iladministrationgui");
48  }
49 
55  public function debug($str)
56  {
57  $this->debug[] = $str;
58  }
59 
65  public function getDebug()
66  {
67  return $this->debug;
68  }
69 
73  public function init()
74  {
75  $this->transit = array();
76  $this->forward = array(); // forward array
77  $this->forwards = array(); // forward array
78  $this->parent = array(); // parent array (reverse forward)
79  $this->save_parameter = array(); // save parameter array
80  $this->parameter = array(); // save parameter array
81  $this->return = array(); // return commmands
82  $this->location = array();
83  $this->tab = array();
84  $this->current_node = 0;
85  $this->module_dir = "";
86  $this->service_dir = "";
87  $this->call_node = array();
88  $this->root_class = "";
89  }
90 
97  public function callBaseClass()
98  {
99  global $DIC;
100 
101  $ilDB = $DIC->database();
102 
103  $baseClass = strtolower($_GET["baseClass"]);
104 
105  $module_class = ilCachedCtrl::getInstance();
106  $mc_rec = $module_class->lookupModuleClass($baseClass);
107  // get class information
108  // $mc_set = $ilDB->query("SELECT * FROM module_class WHERE LOWER(class) = ".
109  // $ilDB->quote($baseClass, "text"));
110  // $mc_rec = $ilDB->fetchAssoc($mc_set);
111 
112  $module = $mc_rec["module"];
113  $class = $mc_rec["class"];
114  $class_dir = $mc_rec["dir"];
115 
116  if ($module != "") {
117  $m_set = $ilDB->query("SELECT * FROM il_component WHERE name = " .
118  $ilDB->quote($module, "text"));
119  $m_rec = $ilDB->fetchAssoc($m_set);
120  $this->module_dir = $m_rec["type"] . "/" . $m_rec["name"];
121  include_once $this->module_dir . "/" . $class_dir . "/class." . $class . ".php";
122  } else { // check whether class belongs to a service
123  // $mc_set = $ilDB->query("SELECT * FROM service_class WHERE LOWER(class) = ".
124  // $ilDB->quote($baseClass, "text"));
125  // $mc_rec = $ilDB->fetchAssoc($mc_set);
126 
127  $mc_rec = $module_class->lookupServiceClass($baseClass);
128 
129  $service = $mc_rec["service"];
130  $class = $mc_rec["class"];
131  $class_dir = $mc_rec["dir"];
132 
133  if ($service == "") {
134  include_once("./Services/UICore/exceptions/class.ilCtrlException.php");
135  throw new ilCtrlException("Could not find entry in modules.xml or services.xml for " .
136  $baseClass . " <br/>" . str_replace("&", "<br />&", htmlentities($_SERVER["REQUEST_URI"])));
137  }
138 
139  // get service information
140  // $m_set = $ilDB->query("SELECT * FROM il_component WHERE name = ".
141  // $ilDB->quote($service, "text"));
142  // $m_rec = $ilDB->fetchAssoc($m_set);
143 
144  $m_rec = ilComponent::getComponentInfo('Services', $service);
145 
146  $this->service_dir = $m_rec["type"] . "/" . $m_rec["name"];
147 
148  include_once $this->service_dir . "/" . $class_dir . "/class." . $class . ".php";
149  ;
150  }
151 
152  // forward processing to base class
153  $this->getCallStructure(strtolower($baseClass));
154  $base_class_gui = new $class();
155  $this->forwardCommand($base_class_gui);
156  }
157 
161  public function getModuleDir()
162  {
163  return $this->module_dir;
164  }
165 
175  public function forwardCommand($a_gui_object)
176  {
177  $class = strtolower(get_class($a_gui_object));
178  //echo "<br>class:".$class.":";
179  $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
180  $nr = $nr["node_id"];
181  if ($nr != "") {
182  $current_node = $this->current_node;
183 
184  $this->current_node = $nr;
185 
186  // always populate the call history
187  // it will only be displayed in DEVMODE but is needed for UI plugins, too
188  $this->call_hist[] = array("class" => get_class($a_gui_object),
189  "mode" => "execComm", "cmd" => $this->getCmd());
190 
191  //echo "<br>class:".get_class($a_gui_object).":";
192  $html = $a_gui_object->executeCommand();
193 
194  // reset current node
195  $this->current_node = $current_node;
196 
197  return $html;
198  }
199 
200  include_once("./Services/UICore/exceptions/class.ilCtrlException.php");
201  throw new ilCtrlException("ERROR: Can't forward to class $class.");
202  }
203 
211  public function getHTML($a_gui_object)
212  {
213  $class = strtolower(get_class($a_gui_object));
214 
215  $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
216  $nr = $nr["node_id"];
217  if ($nr != "") {
218  $current_node = $this->current_node;
219 
220  // set current node to new gui class
221  $this->current_node = $nr;
222 
223  // always populate the call history
224  // it will only be displayed in DEVMODE but is needed for UI plugins, too
225  $this->call_hist[] = array("class" => get_class($a_gui_object),
226  "mode" => "getHtml", "cmd" => $this->getCmd());
227 
228  // get block
229  $html = $a_gui_object->getHTML();
230 
231  // reset current node
232  $this->current_node = $current_node;
233 
234  // return block
235  return $html;
236  }
237 
238  include_once("./Services/UICore/exceptions/class.ilCtrlException.php");
239  throw new ilCtrlException("ERROR: Can't getHTML from class $class.");
240  }
241 
251  public function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = "")
252  {
253  $this->context_obj_id = $a_obj_id;
254  $this->context_obj_type = $a_obj_type;
255  $this->context_sub_obj_id = $a_sub_obj_id;
256  $this->context_sub_obj_type = $a_sub_obj_type;
257  }
258 
264  public function getContextObjId()
265  {
266  return $this->context_obj_id;
267  }
268 
274  public function getContextObjType()
275  {
276  return $this->context_obj_type;
277  }
278 
284  public function getContextSubObjId()
285  {
286  return $this->context_sub_obj_id;
287  }
288 
294  public function getContextSubObjType()
295  {
296  return $this->context_sub_obj_type;
297  }
298 
317  private function getNodeIdForTargetClass($a_par_node, $a_class, $a_check = false)
318  {
319  $class = strtolower($a_class);
320  $this->readClassInfo($class);
321 
322  if ($a_par_node === 0 || $a_par_node == "") {
323  return array("node_id" => $this->getCidForClass($class),
324  "base_class" => "");
325  }
326 
327  $this->readNodeInfo($a_par_node);
328 
329  $node_cid = $this->getCurrentCidOfNode($a_par_node);
330 
331  // target class is class of current node id
332  if ($class == $this->getClassForCid($node_cid)) {
333  return array("node_id" => $a_par_node,
334  "base_class" => "");
335  }
336 
337  // target class is child of current node id
338  if (isset($this->calls[$this->getClassForCid($node_cid)]) &&
339  is_array($this->calls[$this->getClassForCid($node_cid)]) &&
340  in_array($a_class, $this->calls[$this->getClassForCid($node_cid)])) {
341  return array("node_id" => $a_par_node . ":" . $this->getCidForClass($class),
342  "base_class" => "");
343  }
344 
345  // target class is sibling
346  $par_cid = $this->getParentCidOfNode($a_par_node);
347  if ($par_cid != "") {
348  if (is_array($this->calls[$this->getClassForCid($par_cid)]) &&
349  in_array($a_class, $this->calls[$this->getClassForCid($par_cid)])) {
350  return array("node_id" =>
351  $this->removeLastCid($a_par_node) . ":" . $this->getCidForClass($class),
352  "base_class" => "");
353  }
354  }
355 
356  // target class is parent
357  $temp_node = $this->removeLastCid($a_par_node);
358  while ($temp_node != "") {
359  $temp_cid = $this->getCurrentCidOfNode($temp_node);
360  if ($this->getClassForCid($temp_cid) == $a_class) {
361  return array("node_id" => $temp_node,
362  "base_class" => "");
363  }
364  $temp_node = $this->removeLastCid($temp_node);
365  }
366 
367  // target class is another base class
368  $n_class = "";
369  if ($a_class != "") {
370  $module_class = ilCachedCtrl::getInstance();
371  $mc_rec = $module_class->lookupModuleClass($class);
372  $n_class = $mc_rec['lower_class'];
373  // global $ilDB;
374 //
375  // get class information
376  // $mc_set = $ilDB->query("SELECT * FROM module_class WHERE LOWER(class) = ".
377  // $ilDB->quote($class, "text"));
378  // $mc_rec = $ilDB->fetchAssoc($mc_set);
379  // $n_class = strtolower($mc_rec["class"]);
380 
381  if ($n_class == "") {
382  $mc_rec = $module_class->lookupServiceClass($class);
383  $n_class = $mc_rec['lower_class'];
384 
385  // $mc_set = $ilDB->query("SELECT * FROM service_class WHERE LOWER(class) = ".
386 // $ilDB->quote($class, "text"));
387 // $mc_rec = $ilDB->fetchAssoc($mc_set);
388 // $n_class = strtolower($mc_rec["class"]);
389  }
390 
391  if ($n_class != "") {
392  $this->getCallStructure($n_class);
393  return array("node_id" => $this->getCidForClass($n_class),
394  "base_class" => $class);
395  }
396  }
397 
398  if ($a_check) {
399  return false;
400  }
401 
402  // Please do NOT change these lines.
403  // Developers must be aware, if they use classes unknown to the controller
404  // otherwise certain problem will be extremely hard to track down...
405 
406  // echo "ERROR: Can't find target class $a_class for node $a_par_node ".
407  // "(".$this->cid_class[$this->getParentCidOfNode($a_par_node)].").<br>";
408  error_log("ERROR: Can't find target class $a_class for node $a_par_node " .
409  "(" . $this->cid_class[$this->getParentCidOfNode($a_par_node)] . ")");
410 
411  if (DEVMODE == 1) {
412  // ilUtil::printBacktrace();
413  }
414 
415  include_once("./Services/UICore/exceptions/class.ilCtrlException.php");
416  throw new ilCtrlException("ERROR: Can't find target class $a_class for node $a_par_node " .
417  "(" . $this->cid_class[$this->getParentCidOfNode($a_par_node)] . ").");
418  }
419 
426  public function checkTargetClass($a_class)
427  {
428  if (!is_array($a_class)) {
429  $a_class = array($a_class);
430  }
431 
432  $nr = $this->current_node;
433  foreach ($a_class as $class) {
434  $class = strtolower($class);
435 
436  if (!$this->getCidForClass($class, true)) {
437  return false;
438  }
439 
440  $nr = $this->getNodeIdForTargetClass($nr, $class, true);
441  $nr = $nr["node_id"];
442  if ($nr === false) {
443  return false;
444  }
445  }
446  return true;
447  }
448 
454  public function getCmdNode()
455  {
456  return $_GET["cmdNode"];
457  }
458 
466  public function addLocation($a_title, $a_link, $a_target = "", $a_ref_id = 0)
467  {
468  $this->location[] = array("title" => $a_title,
469  "link" => $a_link, "target" => $a_target, "ref_id" => $a_ref_id);
470  }
471 
477  public function getLocations()
478  {
479  return $this->location;
480  }
481 
490  public function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
491  {
492  $a_class = strtolower($a_class);
493 
494  $this->tab[] = array("lang_var" => $a_lang_var,
495  "link" => $a_link, "cmd" => $a_cmd, "class" => $a_class);
496  }
497 
503  public function getTabs()
504  {
505  return $this->tab;
506  }
507 
514  public function getCallHistory()
515  {
516  return $this->call_hist;
517  }
518 
535  public function getCallStructure($a_class)
536  {
537  $this->readClassInfo($a_class);
538  }
539 
544  /* function storeCommonStructures()
545  {
546  global $ilDB;
547 
548  $ilDB->manipulate("DELETE FROM ctrl_structure");
549 
550  foreach ($this->stored_trees as $root_gui_class)
551  {
552  $this->call_node = array();
553  $this->forward = array();
554  $this->parent = array();
555  $this->readCallStructure($root_gui_class);
556  $ilDB->insert("ctrl_structure", array(
557  "root_class" => array("text", $root_gui_class),
558  "call_node" => array("text", serialize($this->call_node)),
559  "forward" => array("text", serialize($this->forward)),
560  "parent" => array("clob", serialize($this->parent))));
561  }
562  }
563  */
564 
568  public function readCallStructure($a_class, $a_nr = 0, $a_parent = 0)
569  {
570  global $DIC;
571 
572  $ilDB = $DIC->database();
573 
574  $a_class = strtolower($a_class);
575 
576  $a_nr++;
577 
578  // determine call node structure
579  $this->call_node[$a_nr] = array("class" => $a_class, "parent" => $a_parent);
580 
581  //echo "<br>nr:$a_nr:class:$a_class:parent:$a_parent:";
582  $call_set = $ilDB->query("SELECT * FROM ctrl_calls WHERE parent = " .
583  $ilDB->quote(strtolower($a_class), "text") .
584  " ORDER BY child", array("text"));
585  $a_parent = $a_nr;
586  while ($call_rec = $ilDB->fetchAssoc($call_set)) {
587  $a_nr = $this->readCallStructure($call_rec["child"], $a_nr, $a_parent);
588  $forw[] = $call_rec["child"];
589  }
590 
591  // determin forward and parent array
592  $this->forwards($a_class, $forw);
593  //echo "<br>forwards:".$a_class."<br>"; var_dump($forw);
594 
595  // determine root class
596  $this->root_class = $a_class;
597  return $a_nr;
598  }
599 
600 
607  private function forwards($a_from_class, $a_to_class)
608  {
609  $a_from_class = strtolower($a_from_class);
610 
611  if (is_array($a_to_class)) {
612  foreach ($a_to_class as $to_class) {
613  if ($a_from_class != "" && $to_class != "") {
614  if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class])) {
615  $this->forward[$a_from_class][] = strtolower($to_class);
616  }
617  if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)])) {
618  $this->parent[strtolower($to_class)][] = $a_from_class;
619  }
620  }
621  }
622  } else {
623  $to_class = $a_to_class;
624  if ($a_from_class != "" && $to_class != "") {
625  if (!is_array($this->forward[$a_from_class]) || !in_array(strtolower($to_class), $this->forward[$a_from_class])) {
626  $this->forward[$a_from_class][] = strtolower($to_class);
627  }
628  if (!is_array($this->parent[strtolower($to_class)]) || !in_array($a_from_class, $this->parent[strtolower($to_class)])) {
629  $this->parent[strtolower($to_class)][] = $a_from_class;
630  }
631  }
632  }
633  }
634 
635 
655  public function saveParameter($a_obj, $a_parameter)
656  {
657  if (is_object($a_obj)) {
658  $this->saveParameterByClass(get_class($a_obj), $a_parameter);
659  }
660  }
661 
668  public function saveParameterByClass($a_class, $a_parameter)
669  {
670  if (is_array($a_parameter)) {
671  foreach ($a_parameter as $parameter) {
672  $this->save_parameter[strtolower($a_class)][] = $parameter;
673  }
674  } else {
675  $this->save_parameter[strtolower($a_class)][] = $a_parameter;
676  }
677  }
678 
679 
702  public function setParameter($a_obj, $a_parameter, $a_value)
703  {
704  $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
705  }
706 
707 
715  public function setParameterByClass($a_class, $a_parameter, $a_value)
716  {
717  $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
718  }
719 
727  public function clearParameterByClass($a_class, $a_parameter)
728  {
729  unset($this->parameter[strtolower($a_class)][$a_parameter]);
730  }
731 
738  public function clearParameters($a_obj)
739  {
740  $this->clearParametersByClass(strtolower(get_class($a_obj)));
741  }
742 
749  public function clearParametersByClass($a_class)
750  {
751  $this->parameter[strtolower($a_class)] = array();
752  }
753 
754  protected function checkLPSettingsForward($a_gui_obj, $a_cmd_node)
755  {
756  global $DIC;
757 
758  $objDefinition = $DIC["objDefinition"];
759 
760  // forward to learning progress settings if possible and accessible
761  if ($_GET["gotolp"] &&
762  $a_gui_obj) {
763  $ref_id = $_GET["ref_id"];
764  if (!$ref_id) {
765  $ref_id = $_REQUEST["ref_id"];
766  }
767 
768  $gui_class = get_class($a_gui_obj);
769 
770  if ($gui_class == "ilSAHSEditGUI") {
771  // #1625 - because of scorm "sub-types" this is all very special
772  include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
773  $obj_id = ilObject::_lookupObjectId($ref_id);
774  switch (ilObjSAHSLearningModule::_lookupSubType($obj_id)) {
775  case "scorm2004":
776  $class = "ilObjSCORM2004LearningModuleGUI";
777  break;
778 
779  case "scorm":
780  $class = "ilObjSCORMLearningModuleGUI";
781  break;
782 
783  case "aicc":
784  $class = "ilObjAICCLearningModuleGUI";
785  break;
786 
787  case "hacp":
788  $class = "ilObjHACPLearningModuleGUI";
789  break;
790  }
791  if ($GLOBALS["ilAccess"]->checkAccess("edit_learning_progress", "", $ref_id)) {
792  $this->redirectByClass(array($gui_class, $class, "illearningprogressgui", "illplistofsettingsgui"), "");
793  }
794  }
795  // special case: cannot use any presentation GUIs
796  elseif ($gui_class == "ilLMPresentationGUI") {
797  $this->setParameterByClass("ilObjLearningModuleGUI", "gotolp", 1);
798  $this->redirectByClass(array("ilLMEditorGUI", "ilObjLearningModuleGUI"), "");
799  }
800 
801  include_once "Services/Object/classes/class.ilObjectLP.php";
802  $type = ilObject::_lookupType($ref_id, true);
803  $class = "ilObj" . $objDefinition->getClassName($type) . "GUI";
804 
805  if ($gui_class == $class &&
807  $GLOBALS["ilAccess"]->checkAccess("edit_learning_progress", "", $ref_id)) {
808  // add path to repository object gui if missing from cmdNode
809  if (!$a_cmd_node) {
810  $repo_node = $this->getNodeIdForTargetClass(null, "ilrepositorygui");
811  $obj_node = $this->getNodeIdForTargetClass($repo_node["node_id"], $gui_class);
812  $a_cmd_node = $obj_node["node_id"];
813  }
814  // find path to lp settings
815  $lp_node = $this->getNodeIdForTargetClass($a_cmd_node, "illearningprogressgui");
816  $lp_settings_node = $this->getNodeIdForTargetClass($lp_node["node_id"], "illplistofsettingsgui");
817  $_GET["cmdNode"] = $lp_settings_node["node_id"];
818  $_GET["cmdClass"] = "ilLPListOfSettingsGUI";
819  $_GET["cmd"] = "";
820  return "illearningprogressgui";
821  }
822  }
823  }
824 
833  public function getNextClass($a_gui_class = null)
834  {
835  $cmdNode = $this->getCmdNode();
836  //echo "<br>getNextClass (current node: ".$this->current_node."; cmd node: ".$cmdNode.") ";
837  if ($cmdNode == "") {
838  return ($class = $this->checkLPSettingsForward($a_gui_class, $cmdNode))
839  ? $class
840  : false;
841  } else {
842  if ($this->current_node == $cmdNode) {
843  //echo "1:".$this->call_node[$cmdNode]["class"]."<br>";
844  //return $this->call_node[$cmdNode]["class"];
845  return ($class = $this->checkLPSettingsForward($a_gui_class, $cmdNode))
846  ? $class
847  : "";
848  } else {
849  $path = $this->getPathNew($this->current_node, $cmdNode);
850  //var_dump($path);
851  //echo " - Next Node: ".$path[1];
852  $this->readCidInfo($this->getCurrentCidOfNode($path[1]));
853  //echo ":".$this->cid_class[$this->getCurrentCidOfNode($path[1])].":".$this->getCurrentCidOfNode($path[1]).":";
854  return $this->cid_class[$this->getCurrentCidOfNode($path[1])];
855  }
856  }
857  }
858 
865  public function lookupClassPath($a_class_name)
866  {
867  $a_class_name = strtolower($a_class_name);
868 
869  $cached_ctrl = ilCachedCtrl::getInstance();
870  $class_rec = $cached_ctrl->lookupClassFile($a_class_name);
871 
872  //$class_set = $ilDB->query("SELECT * FROM ctrl_classfile WHERE class = ".
873  // $ilDB->quote($a_class_name, "text"));
874  //$class_rec = $ilDB->fetchAssoc($class_set);
875 
876  if ($class_rec["plugin_path"] != "") {
877  return $class_rec["plugin_path"] . "/" . $class_rec["filename"];
878  } else {
879  return $class_rec["filename"];
880  }
881  }
882 
891  public function getClassForClasspath($a_class_path)
892  {
893  $path = pathinfo($a_class_path);
894  $file = $path["basename"];
895  $class = substr($file, 6, strlen($file) - 10);
896 
897  return $class;
898  }
899 
906  private function getPathNew($a_source_node, $a_target_node)
907  {
908  //if ($this->getCmdClass() == "ilmailfoldergui") echo "-".$a_source_node."-".$a_target_node."-";
909  //echo "-".$a_source_node."-".$a_target_node."-";
910  //echo "<br>:::$a_source_node:::";
911  if ($a_source_node == "1") {
912  $a_source_node = "";
913  }
914  if (substr($a_target_node, 0, strlen($a_source_node)) != $a_source_node) {
915  $failure = "ERROR: Path not found. Source:" . $a_source_node .
916  ", Target:" . $a_target_node;
917  if (DEVMODE == 1) {
918  include_once("./Services/UICore/exceptions/class.ilCtrlException.php");
919  throw new ilCtrlException($failure);
920  }
921  $GLOBALS['ilLog']->write(__METHOD__ . ' ' . $failure);
922  $this->redirectToURL('./ilias.php?baseClass=ilRepositoryGUI');
923  }
924  //echo "<br>:::$a_source_node:::";
925  $temp_node = $a_source_node;
926 
927  $path = array();
928  if ($a_source_node != "") {
929  $path = array($a_source_node);
930  }
931 
932  $diffstart = ($a_source_node == "")
933  ? 0
934  : strlen($a_source_node) + 1;
935  $diff = substr($a_target_node, $diffstart);
936  //echo "=$diff=$diffstart=";
937  $diff_arr = explode(":", $diff);
938  foreach ($diff_arr as $cid) {
939  if ($temp_node != "") {
940  $temp_node.= ":";
941  }
942  $temp_node.= $cid;
943  $path[] = $temp_node;
944  }
945  //if ($this->getCmdClass() == "ilmailfoldergui") var_dump($path);
946  //var_dump($path);
947  return $path;
948  }
949 
955  public function setTargetScript($a_target_script)
956  {
957  $this->target_script = $a_target_script;
958  }
959 
960 
966  public function getTargetScript()
967  {
968  return $this->target_script;
969  }
970 
971 
980  public function initBaseClass($a_base_class)
981  {
982  $_GET["baseClass"] = $a_base_class;
983  $_GET["cmd"] = "";
984  $_GET["cmdClass"] = "";
985  $_GET["cmdNode"] = "";
986  $this->init();
987  }
988 
996  public function getCmd($a_default_cmd = "", $a_safe_commands = "")
997  {
998  $cmd = "";
999  if (isset($_GET["cmd"])) {
1000  $cmd = $_GET["cmd"];
1001  }
1002  if ($cmd == "post") {
1003  if (isset($_POST["cmd"]) && is_array($_POST["cmd"])) {
1004  reset($_POST["cmd"]);
1005  }
1006  $cmd = @key($_POST["cmd"]);
1007 
1008  // verify command
1009  if ($this->verified_cmd != "") {
1010  return $this->verified_cmd;
1011  } else {
1012  if (!$this->verifyToken() &&
1013  (!is_array($a_safe_commands) || !in_array($cmd, $a_safe_commands))) {
1014  return $a_default_cmd;
1015  }
1016  }
1017 
1018  $this->verified_cmd = $cmd;
1019  if ($cmd == "" && isset($_POST["table_top_cmd"])) { // selected command in multi-list (table2)
1020  $cmd = @key($_POST["table_top_cmd"]);
1021  $this->verified_cmd = $cmd;
1022  $_POST[$_POST["cmd_sv"][$cmd]] = $_POST[$_POST["cmd_sv"][$cmd] . "_2"];
1023  }
1024  if ($cmd == "" && isset($_POST["select_cmd2"])) { // selected command in multi-list (table2)
1025  if (isset($_POST["select_cmd_all2"])) {
1026  $_POST["select_cmd_all"] = $_POST["select_cmd_all2"];
1027  } else {
1028  $_POST["select_cmd_all"] = $_POST["select_cmd_all2"] = null;
1029  }
1030  $cmd = $_POST["selected_cmd2"];
1031  $this->verified_cmd = $cmd;
1032  }
1033  if ($cmd == "" && isset($_POST["select_cmd"])) { // selected command in multi-list (table2)
1034  if (isset($_POST["select_cmd_all"])) {
1035  $_POST["select_cmd_all2"] = $_POST["select_cmd_all"];
1036  } else {
1037  $_POST["select_cmd_all"] = $_POST["select_cmd_all2"] = null;
1038  }
1039  $cmd = $_POST["selected_cmd"];
1040  $this->verified_cmd = $cmd;
1041  }
1042  if ($cmd == "") {
1043  $cmd = $_GET["fallbackCmd"];
1044  $this->verified_cmd = $cmd;
1045  }
1046  }
1047  if ($cmd == "") {
1048  $cmd = $a_default_cmd;
1049  }
1050  return $cmd;
1051  }
1052 
1063  public function setCmd($a_cmd)
1064  {
1065  $_GET["cmd"] = $a_cmd;
1066  }
1067 
1078  public function setCmdClass($a_cmd_class)
1079  {
1080  $a_cmd_class = strtolower($a_cmd_class);
1081  $nr = $this->getNodeIdForTargetClass($this->current_node, $a_cmd_class);
1082  $nr = $nr["node_id"];
1083  $_GET["cmdClass"] = $a_cmd_class;
1084  $_GET["cmdNode"] = $nr;
1085  }
1086 
1092  public function getCmdClass()
1093  {
1094  return strtolower($_GET["cmdClass"]);
1095  }
1096 
1107  public function getFormAction(
1108  $a_gui_obj,
1109  $a_fallback_cmd = "",
1110  $a_anchor = "",
1111  $a_asynch = false,
1112  $xml_style = true
1113  ) {
1114  $script = $this->getFormActionByClass(
1115  strtolower(get_class($a_gui_obj)),
1116  $a_fallback_cmd,
1117  $a_anchor,
1118  $a_asynch,
1119  $xml_style
1120  );
1121  return $script;
1122  }
1123 
1134  public function getFormActionByClass(
1135  $a_class,
1136  $a_fallback_cmd = "",
1137  $a_anchor = "",
1138  $a_asynch = false,
1139  $xml_style = true
1140  ) {
1141  if (!is_array($a_class)) {
1142  $a_class = strtolower($a_class);
1143  }
1144 
1145  $tok = $this->getRequestToken();
1146 
1147  if ($a_asynch) {
1148  $xml_style = false;
1149  }
1150 
1151  $script = $this->getLinkTargetByClass($a_class, "post", "", $a_asynch);
1152  if ($a_fallback_cmd != "") {
1153  $script = ilUtil::appendUrlParameterString($script, "fallbackCmd=" . $a_fallback_cmd, $xml_style);
1154  }
1156  $script,
1157  self::IL_RTOKEN_NAME . '=' . $this->getRequestToken(),
1158  $xml_style
1159  );
1160  if ($a_anchor != "") {
1161  $script = $script . "#" . $a_anchor;
1162  }
1163 
1164  return $script;
1165  }
1166 
1173  public function appendRequestTokenParameterString($a_url, $xml_style = true)
1174  {
1176  $a_url,
1177  self::IL_RTOKEN_NAME . '=' . $this->getRequestToken(),
1178  $xml_style
1179  );
1180  }
1181 
1187  public function getRequestToken()
1188  {
1189  global $DIC;
1190 
1191  $ilUser = $DIC["ilUser"];
1192  $ilDB = $DIC->database();
1193 
1194 
1195  if ($this->rtoken != "") {
1196  return $this->rtoken;
1197  } else {
1198  if (is_object($ilDB) && is_object($ilUser) && $ilUser->getId() > 0 &&
1199  $ilUser->getId() != ANONYMOUS_USER_ID) {
1200  $res = $ilDB->query("SELECT token FROM il_request_token WHERE user_id = " .
1201  $ilDB->quote($ilUser->getId(), "integer") .
1202  " AND session_id = " . $ilDB->quote(session_id(), "text"));
1203  $rec = $ilDB->fetchAssoc($res);
1204  //echo session_id();
1205  if ($rec["token"] != "") {
1206  $this->rtoken = $rec["token"];
1207  return $rec["token"];
1208  }
1209  //echo "new rtoken, new entry for :".$ilUser->getId().":".session_id().":"; exit;
1210  $random = new \ilRandom();
1211  $this->rtoken = md5(uniqid($random->int(), true));
1212 
1213  // delete entries older than one and a half days
1214  if ($random->int(1, 200) == 2) {
1215  $dt = new ilDateTime(time(), IL_CAL_UNIX);
1216  $dt->increment(IL_CAL_DAY, -1);
1217  $dt->increment(IL_CAL_HOUR, -12);
1218  $dq = "DELETE FROM il_request_token WHERE " .
1219  " stamp < " . $ilDB->quote($dt->get(IL_CAL_DATETIME), "timestamp");
1220  $ilDB->manipulate($dq);
1221  }
1222 
1223  // IMPORTANT: Please do NOT try to move this implementation to a
1224  // session basis. This will fail due to framesets that are used
1225  // occasionally in ILIAS, e.g. in the chat, where multiple
1226  // forms are loaded in different frames.
1227  $ilDB->manipulate("INSERT INTO il_request_token (user_id, token, stamp, session_id) VALUES " .
1228  "(" .
1229  $ilDB->quote($ilUser->getId(), "integer") . "," .
1230  $ilDB->quote($this->rtoken, "text") . "," .
1231  $ilDB->now() . "," .
1232  $ilDB->quote(session_id(), "text") . ")");
1233  return $this->rtoken;
1234  }
1235  //$this->rtoken = md5(uniqid(rand(), true));
1236  }
1237  return "";
1238  }
1239 
1245  private function verifyToken()
1246  {
1247  global $DIC;
1248 
1249  $ilUser = $DIC["ilUser"];
1250 
1251  $ilDB = $DIC->database();
1252  ;
1253 
1254  if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 &&
1255  $ilUser->getId() != ANONYMOUS_USER_ID) {
1256  if ($_GET["rtoken"] == "") {
1257  #echo "ilCtrl::No Request Token Given!"; // for debugging, maybe changed later
1258  return false;
1259  }
1260 
1261  $set = $ilDB->query("SELECT * FROM il_request_token WHERE " .
1262  " user_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " .
1263  " token = " . $ilDB->quote($_GET[self::IL_RTOKEN_NAME]), "text");
1264  if ($ilDB->numRows($set) > 0) {
1265  // remove used token
1266  /*
1267  $ilDB->query("DELETE FROM il_request_token WHERE ".
1268  " user_id = ".$ilDB->quote($ilUser->getId())." AND ".
1269  " token = ".$ilDB->quote($_GET[self::IL_RTOKEN_NAME]));
1270  */
1271 
1272  // remove tokens from older sessions
1273  // if we do this immediately, working with multiple windows does not work:
1274  // - window one: open form (with token a)
1275  // - window two: open form (with token b)
1276  // - submit window one: a is verified, but b must not be deleted immediately, otherwise
1277  // - window two: submit results in invalid token
1278  // see also bug #13551
1279  $dt = new ilDateTime(time(), IL_CAL_UNIX);
1280  $dt->increment(IL_CAL_DAY, -1);
1281  $dt->increment(IL_CAL_HOUR, -12);
1282  $ilDB->manipulate("DELETE FROM il_request_token WHERE " .
1283  " user_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " .
1284  " session_id != " . $ilDB->quote(session_id(), "text") . " AND " .
1285  " stamp < " . $ilDB->quote($dt->get(IL_CAL_DATETIME), "timestamp"));
1286  return true;
1287  } else {
1288  return false;
1289  }
1290 
1291  if ($_SESSION["rtokens"][$_GET[self::IL_RTOKEN_NAME]] != "") {
1292  // remove used token
1293  unset($_SESSION["rtokens"][$_GET[self::IL_RTOKEN_NAME]]);
1294 
1295  // remove old tokens
1296  if (count($_SESSION["rtokens"]) > 100) {
1297  $to_remove = array();
1298  $sec = 7200; // two hours
1299 
1300  foreach ($_SESSION["rtokens"] as $tok => $time) {
1301  if (time() - $time > $sec) {
1302  $to_remove[] = $tok;
1303  }
1304  }
1305  foreach ($to_remove as $tok) {
1306  unset($_SESSION["rtokens"][$tok]);
1307  }
1308  }
1309 
1310  return true;
1311  }
1312  return false;
1313  } else {
1314  return true; // do not verify, if user or db object is missing
1315  }
1316 
1317  return false;
1318  }
1319 
1327  public function redirect($a_gui_obj, $a_cmd = "", $a_anchor = "", $a_asynch = false)
1328  {
1329  $script = $this->getLinkTargetByClass(
1330  strtolower(get_class($a_gui_obj)),
1331  $a_cmd,
1332  "",
1333  $a_asynch,
1334  false
1335  );
1336  if ($a_anchor != "") {
1337  $script = $script . "#" . $a_anchor;
1338  }
1339  $this->redirectToURL($script);
1340  }
1341 
1342 
1346  public function redirectToURL($a_script)
1347  {
1348  global $DIC;
1349 
1350  $ilPluginAdmin = null;
1351  if (isset($DIC["ilPluginAdmin"])) {
1352  $ilPluginAdmin = $DIC["ilPluginAdmin"];
1353  }
1354 
1355  if (!is_int(strpos($a_script, "://"))) {
1356  if (substr($a_script, 0, 1) != "/" && defined("ILIAS_HTTP_PATH")) {
1357  if (is_int(strpos($_SERVER["PHP_SELF"], "/setup/"))) {
1358  $a_script = "setup/" . $a_script;
1359  }
1360  $a_script = ILIAS_HTTP_PATH . "/" . $a_script;
1361  }
1362  }
1363 
1364  // include the user interface hook
1365  if (is_object($ilPluginAdmin)) {
1366  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
1367  foreach ($pl_names as $pl) {
1368  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
1369  $gui_class = $ui_plugin->getUIClassInstance();
1370  $resp = $gui_class->getHTML("Services/Utilities", "redirect", array( "html" => $a_script ));
1371  if ($resp["mode"] != ilUIHookPluginGUI::KEEP) {
1372  $a_script = $gui_class->modifyHTML($a_script, $resp);
1373  }
1374  }
1375  }
1376 
1377  // Manually trigger to write and close the session. This has the advantage that if an exception is thrown
1378  // during the writing of the session (ILIAS writes the session into the database by default) we get an exception
1379  // if the session_write_close() is triggered by exit() then the exception will be dismissed but the session
1380  // is never written, which is a nightmare to develop with.
1381  session_write_close();
1382 
1383  global $DIC;
1384  $http = $DIC->http();
1385  switch ($http->request()->getHeaderLine('Accept')) {
1386  case 'application/json':
1388  'success' => true,
1389  'message' => 'Called redirect after async fileupload request',
1390  "redirect_url" => $a_script,
1391  ]));
1392  $http->saveResponse($http->response()->withBody($stream));
1393  break;
1394  default:
1395  $http->saveResponse($http->response()->withAddedHeader("Location", $a_script));
1396  break;
1397  }
1398  $http->sendResponse();
1399  exit;
1400  }
1401 
1402 
1409  public function redirectByClass($a_class, $a_cmd = "", $a_anchor = "", $a_asynch = false)
1410  {
1411  $script = $this->getLinkTargetByClass($a_class, $a_cmd, "", $a_asynch, false);
1412  if ($a_anchor != "") {
1413  $script = $script . "#" . $a_anchor;
1414  }
1415  $this->redirectToURL($script);
1416  }
1417 
1423  public function isAsynch()
1424  {
1425  if (isset($_GET["cmdMode"]) && $_GET["cmdMode"] == "asynch") {
1426  return true;
1427  } else {
1428  return false;
1429  }
1430  }
1431 
1432 
1444  public function getLinkTarget(
1445  $a_gui_obj,
1446  $a_cmd = "",
1447  $a_anchor = "",
1448  $a_asynch = false,
1449  $xml_style = true
1450  ) {
1451  $script = $this->getLinkTargetByClass(
1452  strtolower(get_class($a_gui_obj)),
1453  $a_cmd,
1454  $a_anchor,
1455  $a_asynch,
1456  $xml_style
1457  );
1458  return $script;
1459  }
1460 
1461 
1473  public function getLinkTargetByClass(
1474  $a_class,
1475  $a_cmd = "",
1476  $a_anchor = "",
1477  $a_asynch = false,
1478  $xml_style = true
1479  ) {
1480  if ($a_asynch) {
1481  $xml_style = false;
1482  }
1483 
1484  // note: $a_class may be an array
1485  //$a_class = strtolower($a_class);
1486 
1487  //echo "<br>getLinkTargetByClass";
1488  $script = $this->getTargetScript();
1489  $script = $this->getUrlParameters($a_class, $script, $a_cmd, $xml_style);
1490 
1491  if ($a_asynch) {
1492  //$amp = $xml_style
1493  // ? "&amp;"
1494  // : "&";
1495  $amp = "&";
1496  $script.= $amp . "cmdMode=asynch";
1497  }
1498 
1499  if ($a_anchor != "") {
1500  $script = $script . "#" . $a_anchor;
1501  }
1502 
1503  return $script;
1504  }
1505 
1509  public function setReturn($a_gui_obj, $a_cmd)
1510  {
1511  $script = $this->getTargetScript();
1512  $script = $this->getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
1513  //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
1514  $this->return[strtolower(get_class($a_gui_obj))] = $script;
1515  }
1516 
1520  public function setReturnByClass($a_class, $a_cmd)
1521  {
1522  // may not be an array!
1523  $a_class = strtolower($a_class);
1524 
1525  $script = $this->getTargetScript();
1526  $script = $this->getUrlParameters($a_class, $script, $a_cmd);
1527  //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
1528  $this->return[strtolower($a_class)] = $script;
1529  }
1530 
1534  public function returnToParent($a_gui_obj, $a_anchor = "")
1535  {
1536  $script = $this->getParentReturn($a_gui_obj);
1537 
1539  $script,
1540  "redirectSource=" . strtolower(get_class($a_gui_obj))
1541  );
1543  $script,
1544  "cmdMode=" . $_GET["cmdMode"]
1545  );
1546  if ($a_anchor != "") {
1547  $script = $script . "#" . $a_anchor;
1548  }
1549 
1550  $this->redirectToURL($script);
1551  }
1552 
1553 
1559  public function getRedirectSource()
1560  {
1561  return $_GET["redirectSource"];
1562  }
1563 
1567  public function getParentReturn($a_gui_obj)
1568  {
1569  return $this->getParentReturnByClass(strtolower(get_class($a_gui_obj)));
1570  }
1571 
1572 
1576  public function getParentReturnByClass($a_class)
1577  {
1578  $a_class = strtolower($a_class);
1579  $ret_class = $this->searchReturnClass($a_class);
1580  //echo ":$ret_class:";
1581  if ($ret_class) {
1582  //echo ":".$this->return[$ret_class].":";
1583  return $this->return[$ret_class];
1584  }
1585  }
1586 
1593  public function getReturnClass($a_class)
1594  {
1595  if (is_object($a_class)) {
1596  $class = strtolower(get_class($a_class));
1597  } else {
1598  $class = strtolower($a_class);
1599  }
1600  return $this->searchReturnClass($class);
1601  }
1602 
1603 
1607  private function searchReturnClass($a_class)
1608  {
1609  $a_class = strtolower($a_class);
1610 
1611  $node = $this->getNodeIdForTargetClass($this->current_node, $a_class);
1612  $node = $node["node_id"];
1613  $n_arr = explode(":", $node);
1614  for ($i = count($n_arr)-2; $i>=0; $i--) {
1615  if ($this->return[$this->getClassForCid($n_arr[$i])] != "") {
1616  return $this->getClassForCid($n_arr[$i]);
1617  }
1618  }
1619 
1620  return false;
1621  }
1622 
1626  public function getUrlParameters($a_class, $a_str, $a_cmd = "", $xml_style = false)
1627  {
1628  // note: $a_class may be an array!
1629  //$a_class = strtolower($a_class);
1630 
1631  $params = $this->getParameterArrayByClass($a_class, $a_cmd);
1632 
1633  foreach ($params as $par => $value) {
1634  if (strlen((string) $value)) {
1635  $a_str = ilUtil::appendUrlParameterString($a_str, $par . "=" . $value, $xml_style);
1636  }
1637  }
1638 
1639  return $a_str;
1640  }
1641 
1645  public function getParameterArray($a_gui_obj, $a_cmd = "")
1646  {
1647  $par_arr = $this->getParameterArrayByClass(strtolower(get_class($a_gui_obj)), $a_cmd);
1648 
1649  return $par_arr;
1650  }
1651 
1659  public function getParameterArrayByClass($a_class, $a_cmd = "")
1660  {
1661  if ($a_class == "") {
1662  return array();
1663  }
1664 
1665  if (!is_array($a_class)) {
1666  $a_class = array($a_class);
1667  }
1668 
1669  $nr = $this->current_node;
1670  foreach ($a_class as $class) {
1671  $class = strtolower($class);
1672  $nr = $this->getNodeIdForTargetClass($nr, $class);
1673  if ($nr["base_class"] != "") {
1674  $new_baseclass = $nr["base_class"];
1675  }
1676  $nr = $nr["node_id"];
1677  $target_class = $class;
1678  }
1679 
1680  $path = $this->getPathNew(1, $nr);
1681  $params = array();
1682 
1683  // append parameters of parent classes
1684  foreach ($path as $node_id) {
1685  $class = ($node_id == "")
1686  ? strtolower($_GET["baseClass"])
1687  : $this->getClassForCid($this->getCurrentCidOfNode($node_id));
1688  if (isset($this->save_parameter[$class]) && is_array($this->save_parameter[$class])) {
1689  foreach ($this->save_parameter[$class] as $par) {
1690  if (isset($_GET[$par])) {
1691  $params[$par] = $_GET[$par];
1692  } elseif (isset($_POST[$par])) {
1694  }
1695  }
1696  }
1697 
1698  if (isset($this->parameter[$class]) && is_array($this->parameter[$class])) {
1699  foreach ($this->parameter[$class] as $par => $value) {
1700  $params[$par] = $value;
1701  }
1702  }
1703  }
1704 
1705  if ($a_cmd != "") {
1706  $params["cmd"] = $a_cmd;
1707  }
1708 
1709  $params["cmdClass"] = $target_class;
1710  $params["cmdNode"] = $nr;
1711  if ($new_baseclass == "") {
1712  $params["baseClass"] = $_GET["baseClass"];
1713  } else {
1714  $params["baseClass"] = $new_baseclass;
1715  }
1716 
1717  return $params;
1718  }
1719 
1723  private function getCidForClass($a_class, $a_check = false)
1724  {
1725  if ($this->class_cid[$a_class] == "") {
1726  $this->readClassInfo($a_class);
1727  }
1728  if ($this->class_cid[$a_class] == "") {
1729  if ($a_check) {
1730  return false;
1731  }
1732  if (DEVMODE == 1) {
1733  $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
1734  may solve the issue by putting an empty * @ilCtrl_Calls [YourClassName]: into your class header." .
1735  " In both cases you need to reload the control structure in the setup.";
1736  }
1737  include_once("./Services/UICore/exceptions/class.ilCtrlException.php");
1738  throw new ilCtrlException("Cannot find cid for class " . $a_class . "." . $add);
1739  }
1740  return $this->class_cid[$a_class];
1741  }
1742 
1746  private function getClassForCid($a_cid)
1747  {
1748  if ($this->cid_class[$a_cid] == "") {
1749  $this->readCidInfo($a_cid);
1750  }
1751  if ($this->cid_class[$a_cid] == "") {
1752  include_once("./Services/UICore/exceptions/class.ilCtrlException.php");
1753  throw new ilCtrlException("Cannot find class for cid " . $a_cid . ".");
1754  }
1755  return $this->cid_class[$a_cid];
1756  }
1757 
1763  private function readCidInfo($a_cid)
1764  {
1765  if (isset($this->info_read_cid[$a_cid])) {
1766  return;
1767  }
1768 
1769  $cached_ctrl = ilCachedCtrl::getInstance();
1770  $rec = $cached_ctrl->lookupCid($a_cid);
1771 
1772  if ($rec) {
1773  $this->cid_class[$a_cid] = $rec["class"];
1774  $this->class_cid[$rec["class"]] = $a_cid;
1775 
1776  $calls = $cached_ctrl->lookupCall($rec["class"]);
1777 
1778  foreach ($calls as $rec2) {
1779  if (!isset($this->calls[$rec["class"]]) || !is_array($this->calls[$rec["class"]]) || !in_array($rec2["child"], $this->calls[$rec["class"]])) {
1780  if ($rec2["child"] != "") {
1781  $this->calls[$rec["class"]][] = $rec2["child"];
1782  }
1783  }
1784  }
1785  $this->info_read_class[$rec["class"]] = true;
1786  }
1787 
1788  $this->info_read_cid[$a_cid] = true;
1789  }
1790 
1796  private function readNodeInfo($a_node)
1797  {
1798  $n_arr = explode(":", $a_node);
1799  foreach ($n_arr as $cid) {
1800  $this->readCidInfo($cid);
1801  }
1802  }
1803 
1809  private function readClassInfo($a_class)
1810  {
1811  $a_class = strtolower($a_class);
1812  if (isset($this->info_read_class[$a_class])) {
1813  return;
1814  }
1815 
1816  $cached_ctrl = ilCachedCtrl::getInstance();
1817  $rec = $cached_ctrl->lookupClassFile($a_class);
1818 
1819 
1820  // $set = $ilDB->query("SELECT * FROM ctrl_classfile ".
1821  // " WHERE class = ".$ilDB->quote($a_class, "text")
1822  // );
1823  // if ($rec = $ilDB->fetchAssoc($set))
1824  if ($rec) {
1825  $this->cid_class[$rec["cid"]] = $a_class;
1826  $this->class_cid[$a_class] = $rec["cid"];
1827  }
1828 
1829  // $set = $ilDB->query("SELECT * FROM ctrl_calls ".
1830  // " WHERE parent = ".$ilDB->quote($a_class, "text")
1831  // );
1832  $recs = $cached_ctrl->lookupCall($a_class);
1833  // while ($rec = $ilDB->fetchAssoc($set))
1834  foreach ($recs as $rec) {
1835  if (!isset($this->calls[$a_class]) || !is_array($this->calls[$a_class]) || !in_array($rec["child"], $this->calls[$a_class])) {
1836  if ($rec["child"] != "") {
1837  $this->calls[$a_class][] = $rec["child"];
1838  }
1839  }
1840  }
1841 
1842  $this->info_read_class[$a_class] = true;
1843  $this->info_read_cid[$this->class_cid[$a_class]] = true;
1844  }
1845 
1849  private function getParentCidOfNode($a_node)
1850  {
1851  $n_arr = explode(":", $a_node);
1852  return $n_arr[count($n_arr) - 2];
1853  }
1854 
1858  private function removeLastCid($a_node)
1859  {
1860  $lpos = strrpos($a_node, ":");
1861  return substr($a_node, 0, $lpos);
1862  }
1863 
1867  private function getCurrentCidOfNode($a_node)
1868  {
1869  $n_arr = explode(":", $a_node);
1870  return $n_arr[count($n_arr) - 1];
1871  }
1872 
1879  public function insertCtrlCalls($a_parent, $a_child, $a_comp_prefix)
1880  {
1881  global $DIC;
1882 
1883  $ilDB = $DIC->database();
1884  ;
1885 
1886  $a_parent = strtolower($a_parent);
1887  $a_child = strtolower($a_child);
1888  $a_comp_prefix = strtolower($a_comp_prefix);
1889 
1890  $set = $ilDB->query(
1891  "SELECT * FROM ctrl_calls WHERE " .
1892  " parent = " . $ilDB->quote($a_parent, "text") . " AND " .
1893  " child = " . $ilDB->quote($a_child, "text") . " AND " .
1894  " comp_prefix = " . $ilDB->quote($a_comp_prefix, "text")
1895  );
1896  if ($rec = $ilDB->fetchAssoc($set)) {
1897  return;
1898  }
1899  $ilDB->manipulate("INSERT INTO ctrl_calls " .
1900  "(parent, child, comp_prefix) VALUES (" .
1901  $ilDB->quote($a_parent, "text") . "," .
1902  $ilDB->quote($a_child, "text") . "," .
1903  $ilDB->quote($a_comp_prefix, "text") .
1904  ")");
1905  }
1906 
1914  public function checkCurrentPathForClass($gui_class)
1915  {
1916  foreach (explode(":", $this->getCmdNode()) as $cid) {
1917  if ($cid != "" && strtolower($this->getClassForCid($cid)) == strtolower($gui_class)) {
1918  return true;
1919  }
1920  }
1921  return false;
1922  }
1923 }
getCurrentCidOfNode($a_node)
Get last cid of node id.
removeLastCid($a_node)
Remove last cid of node.
$params
Definition: disable.php:11
getReturnClass($a_class)
Get return class.
setParameter($a_obj, $a_parameter, $a_value)
Set parameters that should be passed a form and link of a gui class.
$failure
getContextObjId()
Get context object id.
This class provides processing control methods.
redirectToURL($a_script)
setReturn($a_gui_obj, $a_cmd)
Set return command.
getTabs()
Get tabs array (.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
getLinkTarget( $a_gui_obj, $a_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get link target for command using gui object.
getCmdNode()
Get command target node.
getFormActionByClass( $a_class, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get form action url for gui class name.
const IL_CAL_DATETIME
lookupClassPath($a_class_name)
Get class path that can be used in include statements for a given class name.
$_SESSION["AccountId"]
getCmdClass()
Determines class that should execute the current command.
$type
global $DIC
Definition: saml.php:7
getDebug()
Get debug message string (.
getParentCidOfNode($a_node)
Get last but one cid of node id.
$_GET["client_id"]
$location
Definition: buildRTE.php:44
const IL_CAL_HOUR
getClassForClasspath($a_class_path)
this method assumes that the class path has the format "dir/class.<class_name>.php" ...
setCmdClass($a_cmd_class)
Set the current command class.
getRequestToken()
Get request token.
checkLPSettingsForward($a_gui_obj, $a_cmd_node)
static isSupportedObjectType($a_type)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
initBaseClass($a_base_class)
Initialises new base class.
getNodeIdForTargetClass($a_par_node, $a_class, $a_check=false)
Searchs a node for a given class ($a_class) "near" the another node ($a_par_node).
checkTargetClass($a_class)
Check whether target is valid.
getParameterArrayByClass($a_class, $a_cmd="")
Get all set/save parameters using gui class name.
$service
Definition: login.php:15
const IL_CAL_UNIX
getClassForCid($a_cid)
Get class for cid.
searchReturnClass($a_class)
Determine current return class.
checkCurrentPathForClass($gui_class)
Check if current path contains a certain gui class.
static _lookupSubType($a_obj_id)
lookup subtype id (scorm, )
$stream
PHP stream implementation.
addLocation($a_title, $a_link, $a_target="", $a_ref_id=0)
Add a location to the locator array (.
getRedirectSource()
Get current redirect source.
getCallStructure($a_class)
Get call structure of class context.
getContextSubObjType()
Get context subobject type.
saveParameterByClass($a_class, $a_parameter)
Save parameter for a class.
if($modEnd===false) $module
Definition: module.php:59
setCmd($a_cmd)
Set the current command.
appendRequestTokenParameterString($a_url, $xml_style=true)
Append request token as url parameter.
static _lookupObjectId($a_ref_id)
lookup object id
const IL_RTOKEN_NAME
$time
Definition: cron.php:21
getContextSubObjId()
Get context subobject id.
const IL_CAL_DAY
isAsynch()
Is current command an asynchronous command?
setReturnByClass($a_class, $a_cmd)
Set return command.
getCidForClass($a_class, $a_check=false)
Get Cid for Class.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
readCidInfo($a_cid)
Read information of class per cid.
getNextClass($a_gui_class=null)
Get next class in the control path from the current class to the target command class.
foreach($_POST as $key=> $value) $res
setContext($a_obj_id, $a_obj_type, $a_sub_obj_id=0, $a_sub_obj_type="")
Set context of current user interface.
getParameterArray($a_gui_obj, $a_cmd="")
Get all set/save parameters for a gui object.
redirectByClass($a_class, $a_cmd="", $a_anchor="", $a_asynch=false)
Redirect to other gui class using class name.
clearParameters($a_obj)
Clears all parameters that have been set via setParameter for a GUI class.
clearParametersByClass($a_class)
Clears all parameters that have been set via setParameter for a GUI class.
debug($str)
Collect debugging strings (.
insertCtrlCalls($a_parent, $a_child, $a_comp_prefix)
Insert ctrl calls record.
getPathNew($a_source_node, $a_target_node)
Get path in call structure.
getCmd($a_default_cmd="", $a_safe_commands="")
Determines current get/post command.
getUrlParameters($a_class, $a_str, $a_cmd="", $xml_style=false)
Get URL parameters for a class and append them to a string.
forwards($a_from_class, $a_to_class)
Stores which classes forwards commands to which other classes.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
readClassInfo($a_class)
Read info of class.
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:29
Date and time handling
$ilUser
Definition: imgupload.php:18
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
getTargetScript()
Get target script name.
$http
Definition: raiseError.php:7
verifyToken()
Verify Token.
saveParameter($a_obj, $a_parameter)
Set parameters that should be passed in every form and link of a gui class.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
readNodeInfo($a_node)
Read info of node.
getLinkTargetByClass( $a_class, $a_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get link target for command using gui class name.
ilCtrl exceptions
getParentReturn($a_gui_obj)
Get return script url.
getModuleDir()
get directory of current module
clearParameterByClass($a_class, $a_parameter)
Same as setParameterByClass, except that a class name is passed.
setParameterByClass($a_class, $a_parameter, $a_value)
Same as setParameterByClass, except that a class name is passed.
getCallHistory()
Get controller call history.
callBaseClass()
Calls base class of current request.
returnToParent($a_gui_obj, $a_anchor="")
Redirects to next parent class that used setReturn.
global $ilDB
$i
Definition: disco.tpl.php:19
getParentReturnByClass($a_class)
Get return script url.
getLocations()
Get locations array (.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
readCallStructure($a_class, $a_nr=0, $a_parent=0)
stores often used common call structures (called from db_update script!!!)
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
init()
initialisation
$_POST["username"]
$html
Definition: example_001.php:87
forwardCommand($a_gui_object)
Forward flow of control to next gui class this invokes the executeCommand() method of the gui object ...
const IL_COMP_SERVICE
getHTML($a_gui_object)
Gets an HTML output from another GUI class and returns the flow of control to the calling class...
setTargetScript($a_target_script)
set target script name
redirect($a_gui_obj, $a_cmd="", $a_anchor="", $a_asynch=false)
Redirect to another command.
getContextObjType()
Get context object type.
__construct()
control class constructor
static getComponentInfo($a_type, $a_name)
addTab($a_lang_var, $a_link, $a_cmd, $a_class)
Add a tab to tabs array (.
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get form action url for gui class object.