• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilCtrl.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00032 class ilCtrl
00033 {
00034         var $target_script;
00035         var $forward;                   // forward array
00036         var $parent;                    // parent array (reverse forward)
00037         var $save_parameter;    // save parameter array
00038         var $return;                    // return commmands
00039 
00043         function ilCtrl()
00044         {
00045                 global $ilBench;
00046 
00047                 $this->bench =& $ilBench;
00048                 $this->transit = array();
00049 
00050                 $this->location = array();
00051                 $this->tab = array();
00052                 $this->current_node = 0;
00053 
00054         }
00055 
00065         function callBaseClass()
00066         {
00067                 global $ilDB;
00068                 
00069                 $baseClass = $_GET["baseClass"];
00070                 
00071                 // get class information
00072                 $q = "SELECT * FROM module_class WHERE LOWER(class) = ".
00073                         $ilDB->quote($baseClass);
00074                 $mc_set = $ilDB->query($q);
00075                 $mc_rec = $mc_set->fetchRow(DB_FETCHMODE_ASSOC);
00076                 $module = $mc_rec["module"];
00077                 $class = $mc_rec["class"];
00078                 $class_dir = $mc_rec["dir"];
00079                 
00080                 // get module information
00081                 $q = "SELECT * FROM module WHERE name = ".
00082                         $ilDB->quote($module);
00083 
00084                 $m_set = $ilDB->query($q);
00085                 $m_rec = $m_set->fetchRow(DB_FETCHMODE_ASSOC);
00086                 $this->module_dir = $m_rec["dir"];
00087                 
00088                 // forward processing to base class
00089                 include_once $this->module_dir."/".$class_dir."/class.".$class.".php";;
00090                 $this->getCallStructure(strtolower($baseClass));
00091                 $base_class_gui =& new $class();
00092                 $this->forwardCommand($base_class_gui);
00093         }
00094 
00098         function getModuleDir()
00099         {
00100                 return $this->module_dir;
00101         }
00102         
00114         function &forwardCommand(&$a_gui_object)
00115         {
00116                 $class = strtolower(get_class($a_gui_object));
00117 //echo "<br>forwarding to: -$class-";
00118                 $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
00119                 if ($nr > 0)
00120                 {
00121                         $this->current_node = $nr;
00122                         return $a_gui_object->executeCommand();
00123                 }
00124                 echo "ERROR: Can't forward to class $class."; exit;
00125 //echo "end forward<br>";
00126         }
00127 
00128 
00150         function getNodeIdForTargetClass($a_par_node, $a_class)
00151         {
00152                 $class = strtolower($a_class);
00153 
00154                 // target class is class of current node id
00155                 if ($class == $this->call_node[$a_par_node]["class"])
00156                 {
00157                         return $a_par_node;
00158                 }
00159 
00160                 // target class is child of current node id
00161                 foreach($this->call_node as $nr => $node)
00162                 {
00163                         if (($node["parent"] == $a_par_node) &&
00164                                 ($node["class"] == $class))
00165                         {
00166                                 return $nr;
00167                         }
00168                 }
00169 
00170                 // target class is sibling
00171                 $par = $this->call_node[$a_par_node]["parent"];
00172                 if ($par != 0)
00173                 {
00174                         foreach($this->call_node as $nr => $node)
00175                         {
00176                                 if (($node["parent"] == $par) &&
00177                                         ($node["class"] == $class))
00178                                 {
00179                                         return $nr;
00180                                 }
00181                         }
00182                 }
00183 
00184                 // target class is parent
00185                 while($par != 0)
00186                 {
00187                         if ($this->call_node[$par]["class"] == $class)
00188                         {
00189                                 return $par;
00190                         }
00191                         $par = $this->call_node[$par]["parent"];
00192                 }
00193 
00194                 echo "ERROR: Can't find target class $a_class for node $a_par_node ".
00195                         "(".$this->call_node[$a_par_node]["class"].").<br>"; exit;
00196         }
00197 
00203         function getCmdNode()
00204         {
00205                 return $_GET["cmdNode"];
00206         }
00207 
00215         function addLocation($a_title, $a_link, $a_target = "")
00216         {
00217                 $this->location[] = array("title" => $a_title,
00218                         "link" => $a_link, "target" => $a_target);
00219         }
00220 
00226         function getLocations()
00227         {
00228                 return $this->location;
00229         }
00230 
00239         function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
00240         {
00241                 $a_class = strtolower($a_class);
00242 
00243                 $this->tab[] = array("lang_var" => $a_lang_var,
00244                         "link" => $a_link, "cmd" => $a_cmd, "class" => $a_class);
00245         }
00246 
00252         function getTabs()
00253         {
00254                 return $this->tab;
00255         }
00256 
00257 
00276         function getCallStructure($a_class, $a_nr = 0, $a_parent = 0)
00277         {
00278                 global $ilDB;
00279 
00280                 $a_class = strtolower($a_class);
00281 
00282                 $a_nr++;
00283                 $this->call_node[$a_nr] = array("class" => $a_class, "parent" => $a_parent);
00284 //echo "nr:$a_nr:class:$a_class:parent:$a_parent:<br>";
00285                 $q = "SELECT * FROM ctrl_calls WHERE parent=".
00286                         $ilDB->quote(strtolower($a_class)).
00287                         " ORDER BY child";
00288 
00289                 $call_set = $ilDB->query($q);
00290                 //$forw = array();
00291                 $a_parent = $a_nr;
00292                 while($call_rec = $call_set->fetchRow(DB_FETCHMODE_ASSOC))
00293                 {
00294                         $a_nr = $this->getCallStructure($call_rec["child"], $a_nr, $a_parent);
00295                         $forw[] = $call_rec["child"];
00296                 }
00297                 $this->forwards($a_class, $forw);
00298 //echo "<br><br>forwards:".$a_class."<br>"; var_dump($forw);
00299 
00300                 $this->root_class = $a_class;
00301                 return $a_nr;
00302         }
00303 
00304 
00313         function forwards($a_from_class, $a_to_class)
00314         {
00315                 $a_from_class = strtolower($a_from_class);
00316 
00317                 if (is_array($a_to_class))
00318                 {
00319                         foreach($a_to_class as $to_class)
00320                         {
00321                                 $this->forward[$a_from_class][] = strtolower($to_class);
00322                                 $this->parent[strtolower($to_class)][] = $a_from_class;
00323                         }
00324                 }
00325                 else
00326                 {
00327                         $this->forward[strtolower(get_class($a_obj))][] = strtolower($a_to_class);
00328                         $this->parent[strtolower($a_to_class)][] = strtolower(get_class($a_obj));
00329                 }
00330         }
00331 
00332 
00352         function saveParameter(&$a_obj, $a_parameter)
00353         {
00354                 if (is_array($a_parameter))
00355                 {
00356                         foreach($a_parameter as $parameter)
00357                         {
00358                                 $this->save_parameter[strtolower(get_class($a_obj))][] = $parameter;
00359                         }
00360                 }
00361                 else
00362                 {
00363                         $this->save_parameter[strtolower(get_class($a_obj))][] = $a_parameter;
00364                 }
00365         }
00366 
00367 
00392         function setParameter(&$a_obj, $a_parameter, $a_value)
00393         {
00394                 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
00395         }
00396 
00397 
00407         function setParameterByClass($a_class, $a_parameter, $a_value)
00408         {
00409                 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
00410         }
00411 
00412 
00421         function getNextClass()
00422         {
00423 //echo "getNextClass:";
00424                 $cmdNode = $this->getCmdNode();
00425                 if ($cmdNode == "")
00426                 {
00427                         return false;
00428                 }
00429                 else
00430                 {
00431                         if ($this->current_node == $cmdNode)
00432                         {
00433 //echo "1:".$this->call_node[$cmdNode]["class"]."<br>";
00434                                 //return $this->call_node[$cmdNode]["class"];
00435                                 return "";
00436                         }
00437                         else
00438                         {
00439                                 $path = $this->getPathNew($this->current_node, $cmdNode);
00440 //echo "2:".$this->call_node[$path[1]]["class"]."<br>";
00441                                 return $this->call_node[$path[1]]["class"];
00442                         }
00443                 }
00444         }
00445 
00452         function lookupClassPath($a_class_name)
00453         {
00454                 global $ilDB;
00455                 $a_class_name = strtolower($a_class_name);
00456 
00457                 $q = "SELECT * FROM ctrl_classfile WHERE class = ".$ilDB->quote($a_class_name);
00458 
00459                 $class_set = $ilDB->query($q);
00460                 $class_rec = $class_set->fetchRow(DB_FETCHMODE_ASSOC);
00461 
00462                 return $class_rec["file"];
00463         }
00464 
00473         function getClassForClasspath($a_class_path)
00474         {
00475                 $path = pathinfo($a_class_path);
00476                 $file = $path["basename"];
00477                 $class = substr($file, 6, strlen($file) - 10);
00478 
00479                 return $class;
00480         }
00481 
00490         function getPathNew($a_source_node, $a_target_node)
00491         {
00492 //echo "-".$a_source_node."-";
00493                 $path_rev = array();
00494                 $c_target = $a_target_node;
00495                 while ($a_source_node != $c_target)
00496                 {
00497                         $path_rev[] = $c_target;
00498                         $c_target = $this->call_node[$c_target]["parent"];
00499                         if(!($c_target > 0))
00500                         {
00501                                 echo "ERROR: Path not found. Source:".$a_source_node.
00502                                         ", Target:".$a_target_node; exit;
00503                         }
00504                 }
00505                 if ($a_source_node == $c_target)
00506                 {
00507                         $path_rev[] = $c_target;
00508                 }
00509                 $path = array();
00510                 for ($i=0; $i<count($path_rev); $i++)
00511                 {
00512                         $path[] = $path_rev[count($path_rev) - ($i + 1)];
00513                 }
00514 
00515                 foreach($path as $node)
00516                 {
00517 //echo "<br>-->".$node.":".$this->call_node[$node]["class"];
00518                 }
00519                 return $path;
00520         }
00521 
00522 
00528         function setTargetScript($a_target_script)
00529         {
00530                 $this->target_script = $a_target_script;
00531         }
00532 
00533 
00539         function getTargetScript()
00540         {
00541                 return $this->target_script;
00542         }
00543 
00544 
00548         function getCmd($a_default_cmd = "")
00549         {
00550                 $cmd = $_GET["cmd"];
00551                 if($cmd == "post")
00552                 {
00553                         $cmd = @key($_POST["cmd"]);
00554                 }
00555                 if($cmd == "")
00556                 {
00557                         $cmd = $a_default_cmd;
00558                 }
00559 
00560                 return $cmd;
00561         }
00562 
00573         function setCmd($a_cmd)
00574         {
00575                 $_GET["cmd"] = $a_cmd;
00576         }
00577 
00588         function setCmdClass($a_cmd_class)
00589         {
00590                 $a_cmd_class = strtolower($a_cmd_class);
00591 
00592                 $nr = $this->getNodeIdForTargetClass($this->current_node, $a_cmd_class);
00593                 $_GET["cmdClass"] = $a_cmd_class;
00594                 $_GET["cmdNode"] = $nr;
00595         }
00596 
00600         function getCmdClass()
00601         {
00602                 return strtolower($_GET["cmdClass"]);
00603         }
00604 
00610         function getFormAction(&$a_gui_obj)
00611         {
00612                 $script =  $this->getFormActionByClass(strtolower(get_class($a_gui_obj)));
00613                 return $script;
00614         }
00615 
00621         function getFormActionByClass($a_class)
00622         {
00623                 $a_class = strtolower($a_class);
00624 
00625                 $script = $this->getLinkTargetByClass($a_class, "post");
00626                 return $script;
00627         }
00628 
00629         function redirect(&$a_gui_obj, $a_cmd = "")
00630         {
00631 //echo "<br>class:".get_class($a_gui_obj).":";
00632                 $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd);
00633 //echo "<br>script:$script:";
00634                 ilUtil::redirect($script);
00635         }
00636 
00637 
00644         function redirectByClass($a_class, $a_cmd = "")
00645         {
00646                 // $a_class may be an array
00647                 //$a_class = strtolower($a_class);
00648 
00649 //echo "<br>class:".get_class($a_gui_obj).":";
00650                 $script = $this->getLinkTargetByClass($a_class, $a_cmd);
00651 //echo "<br>script:$script:";
00652                 ilUtil::redirect($script);
00653         }
00654 
00655 
00664         function getLinkTarget(&$a_gui_obj, $a_cmd = "")
00665         {
00666 //echo "<br>getLinkTarget";
00667                 $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd);
00668                 return $script;
00669         }
00670 
00671 
00681         function getLinkTargetByClass($a_class, $a_cmd  = "", $a_transits = "", $a_prepend_transits = false)
00682         {
00683                 // note: $a_class may be an array
00684                 //$a_class = strtolower($a_class);
00685 
00686 //echo "<br>getLinkTargetByClass";
00687                 $script = $this->getTargetScript();
00688                 $script = $this->getUrlParameters($a_class, $script, $a_cmd, $transits);
00689 
00690                 return $script;
00691         }
00692 
00696         function setReturn(&$a_gui_obj, $a_cmd)
00697         {
00698                 $script = $this->getTargetScript();
00699                 $script = $this->getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
00700 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
00701                 $this->return[strtolower(get_class($a_gui_obj))] = $script;
00702         }
00703 
00707         function setReturnByClass($a_class, $a_cmd)
00708         {
00709                 // may not be an array!
00710                 $a_class = strtolower($a_class);
00711 
00712                 $script = $this->getTargetScript();
00713                 $script = $this->getUrlParameters($a_class, $script, $a_cmd);
00714 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
00715                 $this->return[strtolower($a_class)] = $script;
00716         }
00717 
00721         function returnToParent(&$a_gui_obj, $a_anchor = "")
00722         {
00723                 $script = $this->getParentReturn($a_gui_obj);
00724                 $script = ilUtil::appendUrlParameterString($script,
00725                         "redirectSource=".strtolower(get_class($a_gui_obj)));
00726                 if ($a_anchor != "")
00727                 {
00728                  $script = $script."#".$a_anchor;
00729                 }
00730                 ilUtil::redirect($script);
00731         }
00732 
00733 
00739         function getRedirectSource()
00740         {
00741                 return $_GET["redirectSource"];
00742         }
00743 
00747         function getParentReturn(&$a_gui_obj)
00748         {
00749                 return $this->getParentReturnByClass(strtolower(get_class($a_gui_obj)));
00750         }
00751 
00752 
00753         function getParentReturnByClass($a_class)
00754         {
00755                 $a_class = strtolower($a_class);
00756                 $ret_class = $this->searchReturnClass($a_class);
00757 //echo ":$ret_class:";
00758                 if($ret_class)
00759                 {
00760 //echo ":".$this->return[$ret_class].":";
00761                         return $this->return[$ret_class];
00762                 }
00763         }
00764 
00768         function searchReturnClass($a_class)
00769         {
00770 //echo "<br>searchReturnClass".$a_class;
00771                 $a_class = strtolower($a_class);
00772 
00773                 $nr = $this->getNodeIdForTargetClass($this->current_node, $a_class);
00774                 $path = $this->getPathNew(1, $nr);
00775 //var_dump($path);
00776                 for($i = count($path)-2; $i>=0; $i--)
00777                 {
00778 //echo "<br>:$i:".$path[$i].":".$this->call_node[$path[$i]]["class"]
00779 //             .":".$this->return[$this->call_node[$path[$i]]["class"]].":";
00780                         if ($this->return[$this->call_node[$path[$i]]["class"]] != "")
00781                         {
00782                                 return $this->call_node[$path[$i]]["class"];
00783                         }
00784                 }
00785 
00786                 return false;
00787         }
00788 
00789         function getUrlParameters($a_class, $a_str, $a_cmd = "", $a_transits = "")
00790         {
00791                 // note: $a_class may be an array!
00792                 //$a_class = strtolower($a_class);
00793 
00794                 $params = $this->getParameterArrayByClass($a_class, $a_cmd, $a_transits);
00795 
00796                 foreach ($params as $par => $value)
00797                 {
00798                         $a_str = ilUtil::appendUrlParameterString($a_str, $par."=".$value);
00799                 }
00800 
00801                 return $a_str;
00802         }
00803 
00804         function appendTransitClasses($a_str)
00805         {
00806                 if (is_array($_GET["cmdTransit"]))
00807                 {
00808                         reset($_GET["cmdTransit"]);
00809                         foreach ($_GET["cmdTransit"] as $transit)
00810                         {
00811                                 $a_str = ilUtil::appendUrlParameterString($a_str, "cmdTransit[]=".$transit);
00812                         }
00813                 }
00814                 return $a_str;
00815         }
00816 
00817         function getTransitArray()
00818         {
00819                 $trans_arr = array();
00820                 if (is_array($_GET["cmdTransit"]))
00821                 {
00822                         reset($_GET["cmdTransit"]);
00823                         foreach ($_GET["cmdTransit"] as $key => $transit)
00824                         {
00825                                 $trans_arr["cmdTransit[".$key."]"] = $transit;
00826                         }
00827                 }
00828                 return $trans_arr;
00829         }
00830 
00831         function addTransit($a_class)
00832         {
00833                 $a_class = strtolower($a_class);
00834                 $_GET["cmdTransit"][] = $a_class;
00835         }
00836 
00837         function getParameterArray(&$a_gui_obj, $a_cmd = "", $a_incl_transit = true)
00838         {
00839                 $par_arr = $this->getParameterArrayByClass(strtolower(get_class($a_gui_obj)), $a_cmd,
00840                         $trans_arr);
00841 
00842                 return $par_arr;
00843         }
00844 
00848         function getParameterArrayByClass($a_class, $a_cmd = "", $a_transits = "")
00849         {
00850 //echo "<br>getparameter for $a_class";
00851                 if ($a_class == "")
00852                 {
00853                         return array();
00854                 }
00855 
00856                 if (!is_array($a_class))
00857                 {
00858                         $a_class = array($a_class);
00859                 }
00860 
00861                 $nr = $this->current_node;
00862                 foreach ($a_class as $class)
00863                 {
00864 //echo "<br>-$class-";
00865                         $class = strtolower($class);
00866                         $nr = $this->getNodeIdForTargetClass($nr, $class);
00867                         $target_class = $class;
00868 //echo "-$nr-";
00869                 }
00870 
00871                 $path = $this->getPathNew(1, $nr);
00872                 $params = array();
00873 
00874                 // append parameters of parent classes
00875                 foreach($path as $node_id)
00876                 {
00877                         $class = $this->call_node[$node_id]["class"];
00878                         if (is_array($this->save_parameter[$class]))
00879                         {
00880                                 foreach($this->save_parameter[$class] as $par)
00881                                 {
00882                                         $params[$par] = $_GET[$par];
00883                                 }
00884                         }
00885 
00886                         if (is_array($this->parameter[$class]))
00887                         {
00888                                 foreach($this->parameter[$class] as $par => $value)
00889                                 {
00890                                         $params[$par] = $value;
00891                                 }
00892                         }
00893                 }
00894 
00895                 if ($a_cmd != "")
00896                 {
00897                         $params["cmd"] = $a_cmd;
00898                 }
00899 
00900                 $params["cmdClass"] = $target_class;
00901                 $params["cmdNode"] = $nr;
00902                 $params["baseClass"] = $_GET["baseClass"];
00903 
00904                 return $params;
00905         }
00906 
00907 
00908 } // END class.ilCtrl
00909 ?>

Generated on Fri Dec 13 2013 10:18:26 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1