• Main Page
  • Related Pages
  • Modules
  • 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 
00031 class ilCtrl
00032 {
00033         var $target_script;
00034         var $forward;                   // forward array
00035         var $parent;                    // parent array (reverse forward)
00036         var $save_parameter;    // save parameter array
00037         var $return;                    // return commmands
00038         var $call_hist = array();       // calling history
00039 
00043         function ilCtrl()
00044         {
00045                 global $ilBench;
00046 
00047                 $this->bench =& $ilBench;
00048                 
00049                 // initialisation
00050                 $this->init();
00051                 
00052                 // this information should go to xml files one day
00053                 $this->stored_trees = array
00054                         ("ilrepositorygui", "ilpersonaldesktopgui",
00055                         "illmpresentationgui", "illmeditorgui",
00056                         "iladministrationgui");
00057         }
00058         
00062         function init()
00063         {
00064                 $this->transit = array();
00065                 $this->forward = array();                       // forward array
00066                 $this->forwards = array();                      // forward array
00067                 $this->parent = array();                        // parent array (reverse forward)
00068                 $this->save_parameter = array();        // save parameter array
00069                 $this->parameter = array();                     // save parameter array
00070                 $this->return = "";                                     // return commmands
00071                 $this->location = array();
00072                 $this->tab = array();
00073                 $this->current_node = 0;
00074                 $this->module_dir = "";
00075                 $this->service_dir = "";
00076                 $this->call_node = array();
00077                 $this->root_class = "";
00078         }
00079 
00089         function callBaseClass()
00090         {
00091                 global $ilDB;
00092                 
00093                 $baseClass = strtolower($_GET["baseClass"]);
00094                 
00095                 // get class information
00096                 $q = "SELECT * FROM module_class WHERE LOWER(class) = ".
00097                         $ilDB->quote($baseClass);
00098                 $mc_set = $ilDB->query($q);
00099                 $mc_rec = $mc_set->fetchRow(DB_FETCHMODE_ASSOC);
00100                 $module = $mc_rec["module"];
00101                 $class = $mc_rec["class"];
00102                 $class_dir = $mc_rec["dir"];
00103                 
00104                 if ($module != "")
00105                 {
00106                         // get module information
00107                         $q = "SELECT * FROM module WHERE name = ".
00108                                 $ilDB->quote($module);
00109         
00110                         $m_set = $ilDB->query($q);
00111                         $m_rec = $m_set->fetchRow(DB_FETCHMODE_ASSOC);
00112                         $this->module_dir = $m_rec["dir"];
00113                         include_once $this->module_dir."/".$class_dir."/class.".$class.".php";
00114                 }
00115                 else            // check whether class belongs to a service
00116                 {
00117                         // get class information
00118                         $q = "SELECT * FROM service_class WHERE LOWER(class) = ".
00119                                 $ilDB->quote($baseClass);
00120 
00121                         $mc_set = $ilDB->query($q);
00122                         $mc_rec = $mc_set->fetchRow(DB_FETCHMODE_ASSOC);
00123                         $service = $mc_rec["service"];
00124                         $class = $mc_rec["class"];
00125                         $class_dir = $mc_rec["dir"];
00126                         
00127                         if ($service == "")
00128                         {
00129                                 echo "Could not find entry in modules.xml or services.xml for".
00130                                         $baseClass;
00131                                 exit;
00132                         }
00133 
00134                         // get service information
00135                         $q = "SELECT * FROM service WHERE name = ".
00136                                 $ilDB->quote($service);
00137         
00138                         $m_set = $ilDB->query($q);
00139                         $m_rec = $m_set->fetchRow(DB_FETCHMODE_ASSOC);
00140                         $this->service_dir = $m_rec["dir"];
00141                         
00142                         include_once $this->service_dir."/".$class_dir."/class.".$class.".php";;
00143                 }
00144                 
00145                 // forward processing to base class
00146                 $this->getCallStructure(strtolower($baseClass));
00147                 $base_class_gui =& new $class();
00148                 $this->forwardCommand($base_class_gui);
00149         }
00150 
00154         function getModuleDir()
00155         {
00156                 return $this->module_dir;
00157         }
00158         
00170         function &forwardCommand(&$a_gui_object)
00171         {
00172                 $class = strtolower(get_class($a_gui_object));
00173 //echo "<br>forwarding to: -$class-";
00174                 $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
00175                 if ($nr > 0)
00176                 {
00177                         $current_node = $this->current_node;
00178                         
00179                         $this->current_node = $nr;
00180 
00181                         if (DEVMODE == "1")
00182                         {
00183                                 $this->call_hist[] = get_class($a_gui_object);
00184                         }
00185                         
00186                         $html = $a_gui_object->executeCommand();
00187                         
00188                         // reset current node
00189                         $this->current_node = $current_node;
00190                         
00191                         return $html;
00192 
00193                 }
00194                 echo "ERROR: Can't forward to class $class."; exit;
00195 //echo "end forward<br>";
00196         }
00197 
00207         function &getHTML(&$a_gui_object)
00208         {
00209                 $class = strtolower(get_class($a_gui_object));
00210 
00211                 $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
00212                 if ($nr > 0)
00213                 {
00214                         $current_node = $this->current_node;
00215                         
00216                         // set current node to new gui class
00217                         $this->current_node = $nr;
00218                         
00219                         if (DEVMODE == "1")
00220                         {
00221                                 $this->call_hist[] = get_class($a_gui_object);
00222                         }
00223                         
00224                         // get block
00225                         $html = $a_gui_object->getHTML();
00226                         
00227                         // reset current node
00228                         $this->current_node = $current_node;
00229                         
00230                         // return block
00231                         return $html;
00232                 }
00233                 echo "ERROR: Can't getHTML from class $class."; exit;
00234         }
00235         
00239         function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = "")
00240         {
00241                 $this->context_obj_id = $a_obj_id;
00242                 $this->context_obj_type = $a_obj_type;
00243                 $this->context_sub_obj_id = $a_sub_obj_id;
00244                 $this->context_sub_obj_type = $a_sub_obj_type;
00245         }
00246 
00252         public function getContextObjId()
00253         {
00254                 return $this->context_obj_id;
00255         }
00256 
00262         public function getContextObjType()
00263         {
00264                 return $this->context_obj_type;
00265         }
00266 
00272         public function getContextSubObjId()
00273         {
00274                 return $this->context_sub_obj_id;
00275         }
00276 
00282         public function getContextSubObjType()
00283         {
00284                 return $this->context_sub_obj_type;
00285         }
00286 
00308         function getNodeIdForTargetClass($a_par_node, $a_class)
00309         {
00310                 $class = strtolower($a_class);
00311 
00312                 // target class is class of current node id
00313                 if ($class == $this->call_node[$a_par_node]["class"])
00314                 {
00315                         return $a_par_node;
00316                 }
00317 
00318                 // target class is child of current node id
00319                 foreach($this->call_node as $nr => $node)
00320                 {
00321                         if (($node["parent"] == $a_par_node) &&
00322                                 ($node["class"] == $class))
00323                         {
00324                                 return $nr;
00325                         }
00326                 }
00327 
00328                 // target class is sibling
00329                 $par = $this->call_node[$a_par_node]["parent"];
00330                 if ($par != 0)
00331                 {
00332                         foreach($this->call_node as $nr => $node)
00333                         {
00334                                 if (($node["parent"] == $par) &&
00335                                         ($node["class"] == $class))
00336                                 {
00337                                         return $nr;
00338                                 }
00339                         }
00340                 }
00341 
00342                 // target class is parent
00343                 while($par != 0)
00344                 {
00345                         if ($this->call_node[$par]["class"] == $class)
00346                         {
00347                                 return $par;
00348                         }
00349                         $par = $this->call_node[$par]["parent"];
00350                 }
00351 
00352                 echo "ERROR: Can't find target class $a_class for node $a_par_node ".
00353                         "(".$this->call_node[$a_par_node]["class"].").<br>";
00354                 exit;
00355         }
00356 
00362         function getCmdNode()
00363         {
00364                 return $_GET["cmdNode"];
00365         }
00366 
00374         function addLocation($a_title, $a_link, $a_target = "", $a_ref_id = 0)
00375         {
00376                 $this->location[] = array("title" => $a_title,
00377                         "link" => $a_link, "target" => $a_target, "ref_id" => $a_ref_id);
00378         }
00379 
00385         function getLocations()
00386         {
00387                 return $this->location;
00388         }
00389 
00398         function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
00399         {
00400                 $a_class = strtolower($a_class);
00401 
00402                 $this->tab[] = array("lang_var" => $a_lang_var,
00403                         "link" => $a_link, "cmd" => $a_cmd, "class" => $a_class);
00404         }
00405 
00411         function getTabs()
00412         {
00413                 return $this->tab;
00414         }
00415 
00419         function getCallHistory()
00420         {
00421                 return $this->call_hist;
00422         }
00423         
00442         function getCallStructure($a_class, $a_nr = 0, $a_parent = 0)
00443         {
00444                 global $ilDB, $ilLog, $ilUser;
00445                 
00446                 $a_class = strtolower($a_class);
00447                 
00448                 if (in_array($a_class, $this->stored_trees))
00449                 {
00450                         $q = "SELECT * FROM ctrl_structure WHERE root_class = ".
00451                                 $ilDB->quote($a_class);
00452                         $set = $ilDB->query($q);
00453                         $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00454                         $this->call_node = unserialize($rec["call_node"]);
00455                         $this->forward = unserialize($rec["forward"]);
00456                         $this->parent = unserialize($rec["parent"]);
00457                         $this->root_class = $a_class;
00458                 }
00459                 else
00460                 {
00461                         $this->readCallStructure($a_class, $a_nr, $a_parent);
00462                 }
00463                 
00464                 // check whether command node and command class fit together
00465                 if ($_GET["cmdNode"] > 0)
00466                 {
00467                         if (strtolower($this->call_node[$_GET["cmdNode"]]["class"]) !=
00468                                 strtolower($_GET["cmdClass"]))
00469                         {
00470                                 if (DEVMODE)
00471                                 {
00472                                         die ("Internal Error: ilCtrl Node Error.");
00473                                 }
00474                                 else
00475                                 {
00476                                         if (is_object($ilLog))
00477                                         {
00478                                                 if (is_object($ilUser))
00479                                                 {
00480                                                         $user_str = "User: ".$ilUser->getLogin()." (".$ilUser->getId()."), ";
00481                                                 }
00482                                                 $ilLog->write("Invalid Request (class ilCtrl). Possible attack or Control Structure broken (see Setup). ".
00483                                                         $user_str."IP: ".$_SERVER["REMOTE_ADDR"].", URI: ".$_SERVER["REQUEST_URI"]);
00484                                         }
00485                                         ilUtil::sendInfo("Sorry, but the request includes invalid parameters." ,true);
00486                                         ilUtil::redirect("repository.php?cmd=frameset");
00487                                 }
00488                         }
00489                 }
00490         }
00491 
00496         function storeCommonStructures()
00497         {
00498                 global $ilDB;
00499                 
00500                 $q = "DELETE FROM ctrl_structure";
00501                 $ilDB->query($q);
00502                 
00503                 foreach ($this->stored_trees as $root_gui_class)
00504                 {
00505                         $this->call_node = array();
00506                         $this->forward = array();
00507                         $this->parent = array();
00508                         $this->readCallStructure($root_gui_class);
00509                         $q = "INSERT INTO ctrl_structure (root_class, call_node, forward, parent) VALUES (".
00510                                 $ilDB->quote($root_gui_class).",".
00511                                 $ilDB->quote(serialize($this->call_node)).",".
00512                                 $ilDB->quote(serialize($this->forward)).",".
00513                                 $ilDB->quote(serialize($this->parent)).")";
00514                         $ilDB->query($q);
00515                 }
00516         }
00517         
00521         function readCallStructure($a_class, $a_nr = 0, $a_parent = 0)
00522         {
00523                 global $ilDB;
00524 
00525                 $a_class = strtolower($a_class);
00526 
00527                 $a_nr++;
00528                 
00529                 // determine call node structure
00530                 $this->call_node[$a_nr] = array("class" => $a_class, "parent" => $a_parent);
00531                 
00532 //echo "<br>nr:$a_nr:class:$a_class:parent:$a_parent:";
00533                 $q = "SELECT * FROM ctrl_calls WHERE parent=".
00534                         $ilDB->quote(strtolower($a_class)).
00535                         " ORDER BY child";
00536 
00537                 $call_set = $ilDB->query($q);
00538                 //$forw = array();
00539                 $a_parent = $a_nr;
00540                 while($call_rec = $call_set->fetchRow(DB_FETCHMODE_ASSOC))
00541                 {
00542                         $a_nr = $this->readCallStructure($call_rec["child"], $a_nr, $a_parent);
00543                         $forw[] = $call_rec["child"];
00544                 }
00545                 
00546                 // determin forward and parent array
00547                 $this->forwards($a_class, $forw);
00548 //echo "<br>forwards:".$a_class."<br>"; var_dump($forw);
00549 
00550                 // determine root class
00551                 $this->root_class = $a_class;
00552                 return $a_nr;
00553         }
00554 
00555 
00564         function forwards($a_from_class, $a_to_class)
00565         {
00566                 $a_from_class = strtolower($a_from_class);
00567 
00568                 if (is_array($a_to_class))
00569                 {
00570                         foreach($a_to_class as $to_class)
00571                         {
00572                                 $this->forward[$a_from_class][] = strtolower($to_class);
00573                                 $this->parent[strtolower($to_class)][] = $a_from_class;
00574                         }
00575                 }
00576                 else
00577                 {
00578                         $this->forward[strtolower(get_class($a_obj))][] = strtolower($a_to_class);
00579                         $this->parent[strtolower($a_to_class)][] = strtolower(get_class($a_obj));
00580                 }
00581         }
00582 
00583 
00603         function saveParameter(&$a_obj, $a_parameter)
00604         {
00605                 $this->saveParameterByClass(get_class($a_obj), $a_parameter);
00606         }
00607         
00608         function saveParameterByClass($a_class, $a_parameter)
00609         {
00610                 if (is_array($a_parameter))
00611                 {
00612                         foreach($a_parameter as $parameter)
00613                         {
00614                                 $this->save_parameter[strtolower($a_class)][] = $parameter;
00615                         }
00616                 }
00617                 else
00618                 {
00619                         $this->save_parameter[strtolower($a_class)][] = $a_parameter;
00620                 }
00621         }
00622 
00623 
00648         function setParameter(&$a_obj, $a_parameter, $a_value)
00649         {
00650                 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
00651         }
00652 
00653 
00663         function setParameterByClass($a_class, $a_parameter, $a_value)
00664         {
00665                 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
00666         }
00667         
00668         
00675         function clearParameters(&$a_obj)
00676         {
00677                 $this->clearParametersByClass(strtolower(get_class($a_obj)));
00678         }
00679 
00686         function clearParametersByClass($a_class)
00687         {
00688                 $this->parameter[strtolower($a_class)] = array();
00689         }
00690 
00699         function getNextClass()
00700         {
00701 //echo "getNextClass:";
00702                 $cmdNode = $this->getCmdNode();
00703                 if ($cmdNode == "")
00704                 {
00705                         return false;
00706                 }
00707                 else
00708                 {
00709                         if ($this->current_node == $cmdNode)
00710                         {
00711 //echo "1:".$this->call_node[$cmdNode]["class"]."<br>";
00712                                 //return $this->call_node[$cmdNode]["class"];
00713                                 return "";
00714                         }
00715                         else
00716                         {
00717                                 $path = $this->getPathNew($this->current_node, $cmdNode);
00718 //echo "2:".$this->call_node[$path[1]]["class"]."<br>";
00719                                 return $this->call_node[$path[1]]["class"];
00720                         }
00721                 }
00722         }
00723 
00730         function lookupClassPath($a_class_name)
00731         {
00732                 global $ilDB;
00733                 $a_class_name = strtolower($a_class_name);
00734 
00735                 $q = "SELECT * FROM ctrl_classfile WHERE class = ".$ilDB->quote($a_class_name);
00736 
00737                 $class_set = $ilDB->query($q);
00738                 $class_rec = $class_set->fetchRow(DB_FETCHMODE_ASSOC);
00739 
00740                 return $class_rec["file"];
00741         }
00742 
00751         function getClassForClasspath($a_class_path)
00752         {
00753                 $path = pathinfo($a_class_path);
00754                 $file = $path["basename"];
00755                 $class = substr($file, 6, strlen($file) - 10);
00756 
00757                 return $class;
00758         }
00759 
00768         function getPathNew($a_source_node, $a_target_node)
00769         {
00770 //echo "-".$a_source_node."-";
00771                 $path_rev = array();
00772                 $c_target = $a_target_node;
00773                 while ($a_source_node != $c_target)
00774                 {
00775                         $path_rev[] = $c_target;
00776                         $c_target = $this->call_node[$c_target]["parent"];
00777                         if(!($c_target > 0))
00778                         {
00779                                 echo "ERROR: Path not found. Source:".$a_source_node.
00780                                         " (".$this->call_node[$a_source_node]["class"].")".
00781                                         ", Target:".$a_target_node.
00782                                         " (".$this->call_node[$a_target_node]["class"].")";
00783                                 exit;
00784                         }
00785                 }
00786                 if ($a_source_node == $c_target)
00787                 {
00788                         $path_rev[] = $c_target;
00789                 }
00790                 $path = array();
00791                 for ($i=0; $i<count($path_rev); $i++)
00792                 {
00793                         $path[] = $path_rev[count($path_rev) - ($i + 1)];
00794                 }
00795 
00796                 foreach($path as $node)
00797                 {
00798 //echo "<br>-->".$node.":".$this->call_node[$node]["class"];
00799                 }
00800                 return $path;
00801         }
00802 
00803 
00809         function setTargetScript($a_target_script)
00810         {
00811                 $this->target_script = $a_target_script;
00812         }
00813 
00814 
00820         function getTargetScript()
00821         {
00822                 return $this->target_script;
00823         }
00824 
00825 
00832         function initBaseClass($a_base_class)
00833         {
00834                 $_GET["baseClass"] = $a_base_class;
00835                 $_GET["cmd"] = "";
00836                 $_GET["cmdClass"] = "";
00837                 $_GET["cmdNode"] = "";
00838                 $this->init();
00839         }
00840         
00844         function getCmd($a_default_cmd = "")
00845         {
00846                 $cmd = $_GET["cmd"];
00847                 if($cmd == "post")
00848                 {
00849                         if (is_array($_POST["cmd"]))
00850                         {
00851                                 reset($_POST["cmd"]);
00852                         }
00853                         $cmd = @key($_POST["cmd"]);
00854                         if($cmd == "" && isset($_POST["select_cmd"]))           // selected command in multi-list (table2)
00855                         {
00856                                 $cmd = $_POST["selected_cmd"];
00857                         }
00858                         if($cmd == "")
00859                         {
00860                                 $cmd = $_GET["fallbackCmd"];
00861                         }
00862                 }
00863                 if($cmd == "")
00864                 {
00865                         $cmd = $a_default_cmd;
00866                 }
00867                 return $cmd;
00868         }
00869 
00880         function setCmd($a_cmd)
00881         {
00882                 $_GET["cmd"] = $a_cmd;
00883         }
00884 
00895         function setCmdClass($a_cmd_class)
00896         {
00897                 $a_cmd_class = strtolower($a_cmd_class);
00898                 $nr = $this->getNodeIdForTargetClass($this->current_node, $a_cmd_class);
00899                 $_GET["cmdClass"] = $a_cmd_class;
00900                 $_GET["cmdNode"] = $nr;
00901         }
00902 
00906         function getCmdClass()
00907         {
00908                 return strtolower($_GET["cmdClass"]);
00909         }
00910 
00916         function getFormAction(&$a_gui_obj, $a_fallback_cmd = "")
00917         {
00918                 $script =  $this->getFormActionByClass(strtolower(get_class($a_gui_obj)),
00919                         $a_fallback_cmd);
00920                 return $script;
00921         }
00922 
00928         function getFormActionByClass($a_class, $a_fallback_cmd = "")
00929         {
00930                 $a_class = strtolower($a_class);
00931 
00932                 $script = $this->getLinkTargetByClass($a_class, "post");
00933                 if ($a_fallback_cmd != "")
00934                 {
00935                         $script = ilUtil::appendUrlParameterString($script, "fallbackCmd=".$a_fallback_cmd);
00936                 }
00937                 return $script;
00938         }
00939 
00940         function redirect(&$a_gui_obj, $a_cmd = "", $a_anchor = "")
00941         {
00942                 global $ilBench;
00943                 
00944 //echo "<br>class:".get_class($a_gui_obj).":";
00945                 $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd);
00946                 if  (is_object($ilBench))
00947                 {
00948                         $ilBench->save();
00949                 }
00950                 if ($a_anchor != "")
00951                 {
00952                         $script = $script."#".$a_anchor;
00953                 }
00954                 ilUtil::redirect($script);
00955         }
00956 
00957 
00964         function redirectByClass($a_class, $a_cmd = "")
00965         {
00966                 // $a_class may be an array
00967                 //$a_class = strtolower($a_class);
00968 
00969 //echo "<br>class:".get_class($a_gui_obj).":";
00970                 $script = $this->getLinkTargetByClass($a_class, $a_cmd);
00971 //echo "<br>script:$script:";
00972                 ilUtil::redirect($script);
00973         }
00974         
00975         function isAsynch()
00976         {
00977                 if ($_GET["cmdMode"] == "asynch")
00978                 {
00979                         return true;
00980                 }
00981                 else
00982                 {
00983                         return false;
00984                 }
00985         }
00986 
00987 
00996         function getLinkTarget(&$a_gui_obj, $a_cmd = "", $a_anchor = "", $a_asynch = false)
00997         {
00998 //echo "<br>getLinkTarget";
00999                 $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd, $a_anchor, $a_asynch);
01000                 return $script;
01001         }
01002 
01003 
01013         function getLinkTargetByClass($a_class, $a_cmd  = "", $a_anchor = "", $a_asynch = false)
01014         {
01015                 // note: $a_class may be an array
01016                 //$a_class = strtolower($a_class);
01017 
01018 //echo "<br>getLinkTargetByClass";
01019                 $script = $this->getTargetScript();
01020                 $script = $this->getUrlParameters($a_class, $script, $a_cmd);
01021 
01022                 if ($a_asynch)
01023                 {
01024                         $script.= "&cmdMode=asynch";
01025                 }
01026                 
01027                 if ($a_anchor != "")
01028                 {
01029                         $script = $script."#".$a_anchor;
01030                 }
01031 
01032                 return $script;
01033         }
01034 
01038         function setReturn(&$a_gui_obj, $a_cmd)
01039         {
01040                 $script = $this->getTargetScript();
01041                 $script = $this->getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
01042 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
01043                 $this->return[strtolower(get_class($a_gui_obj))] = $script;
01044         }
01045 
01049         function setReturnByClass($a_class, $a_cmd)
01050         {
01051                 // may not be an array!
01052                 $a_class = strtolower($a_class);
01053 
01054                 $script = $this->getTargetScript();
01055                 $script = $this->getUrlParameters($a_class, $script, $a_cmd);
01056 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
01057                 $this->return[strtolower($a_class)] = $script;
01058         }
01059 
01063         function returnToParent(&$a_gui_obj, $a_anchor = "")
01064         {
01065                 $script = $this->getParentReturn($a_gui_obj);
01066 
01067                 $script = ilUtil::appendUrlParameterString($script,
01068                         "redirectSource=".strtolower(get_class($a_gui_obj)));
01069                 if ($a_anchor != "")
01070                 {
01071                  $script = $script."#".$a_anchor;
01072                 }
01073                 ilUtil::redirect($script);
01074         }
01075 
01076 
01082         function getRedirectSource()
01083         {
01084                 return $_GET["redirectSource"];
01085         }
01086 
01090         function getParentReturn(&$a_gui_obj)
01091         {
01092                 return $this->getParentReturnByClass(strtolower(get_class($a_gui_obj)));
01093         }
01094 
01095 
01096         function getParentReturnByClass($a_class)
01097         {
01098                 $a_class = strtolower($a_class);
01099                 $ret_class = $this->searchReturnClass($a_class);
01100 //echo ":$ret_class:";
01101                 if($ret_class)
01102                 {
01103 //echo ":".$this->return[$ret_class].":";
01104                         return $this->return[$ret_class];
01105                 }
01106         }
01107 
01111         function searchReturnClass($a_class)
01112         {
01113 //echo "<br>searchReturnClass".$a_class;
01114                 $a_class = strtolower($a_class);
01115 
01116                 $nr = $this->getNodeIdForTargetClass($this->current_node, $a_class);
01117                 $path = $this->getPathNew(1, $nr);
01118 //var_dump($path);
01119                 for($i = count($path)-2; $i>=0; $i--)
01120                 {
01121 //echo "<br>:$i:".$path[$i].":".$this->call_node[$path[$i]]["class"]
01122 //             .":".$this->return[$this->call_node[$path[$i]]["class"]].":";
01123                         if ($this->return[$this->call_node[$path[$i]]["class"]] != "")
01124                         {
01125                                 return $this->call_node[$path[$i]]["class"];
01126                         }
01127                 }
01128 
01129                 return false;
01130         }
01131 
01132         function getUrlParameters($a_class, $a_str, $a_cmd = "", $a_transits = "")
01133         {
01134                 // note: $a_class may be an array!
01135                 //$a_class = strtolower($a_class);
01136 
01137                 $params = $this->getParameterArrayByClass($a_class, $a_cmd, $a_transits);
01138 
01139                 foreach ($params as $par => $value)
01140                 {
01141                         if (strlen($value))
01142                         {
01143                                 $a_str = ilUtil::appendUrlParameterString($a_str, $par."=".$value);
01144                         }
01145                 }
01146 
01147                 return $a_str;
01148         }
01149 
01150         function appendTransitClasses($a_str)
01151         {
01152                 if (is_array($_GET["cmdTransit"]))
01153                 {
01154                         reset($_GET["cmdTransit"]);
01155                         foreach ($_GET["cmdTransit"] as $transit)
01156                         {
01157                                 $a_str = ilUtil::appendUrlParameterString($a_str, "cmdTransit[]=".$transit);
01158                         }
01159                 }
01160                 return $a_str;
01161         }
01162 
01163         function getTransitArray()
01164         {
01165                 $trans_arr = array();
01166                 if (is_array($_GET["cmdTransit"]))
01167                 {
01168                         reset($_GET["cmdTransit"]);
01169                         foreach ($_GET["cmdTransit"] as $key => $transit)
01170                         {
01171                                 $trans_arr["cmdTransit[".$key."]"] = $transit;
01172                         }
01173                 }
01174                 return $trans_arr;
01175         }
01176 
01177         function addTransit($a_class)
01178         {
01179                 $a_class = strtolower($a_class);
01180                 $_GET["cmdTransit"][] = $a_class;
01181         }
01182 
01183         function getParameterArray(&$a_gui_obj, $a_cmd = "", $a_incl_transit = true)
01184         {
01185                 $par_arr = $this->getParameterArrayByClass(strtolower(get_class($a_gui_obj)), $a_cmd,
01186                         $trans_arr);
01187 
01188                 return $par_arr;
01189         }
01190 
01194         function getParameterArrayByClass($a_class, $a_cmd = "", $a_transits = "")
01195         {
01196 //echo "<br>getparameter for $a_class";
01197                 if ($a_class == "")
01198                 {
01199                         return array();
01200                 }
01201 
01202                 if (!is_array($a_class))
01203                 {
01204                         $a_class = array($a_class);
01205                 }
01206 
01207                 $nr = $this->current_node;
01208                 foreach ($a_class as $class)
01209                 {
01210 //echo "<br>-$class-";
01211                         $class = strtolower($class);
01212                         $nr = $this->getNodeIdForTargetClass($nr, $class);
01213                         $target_class = $class;
01214 //echo "-$nr-";
01215                 }
01216 
01217                 $path = $this->getPathNew(1, $nr);
01218                 $params = array();
01219 
01220                 // append parameters of parent classes
01221                 foreach($path as $node_id)
01222                 {
01223                         $class = $this->call_node[$node_id]["class"];
01224                         if (is_array($this->save_parameter[$class]))
01225                         {
01226                                 foreach($this->save_parameter[$class] as $par)
01227                                 {
01228                                         $params[$par] = $_GET[$par];
01229                                 }
01230                         }
01231 
01232                         if (is_array($this->parameter[$class]))
01233                         {
01234                                 foreach($this->parameter[$class] as $par => $value)
01235                                 {
01236                                         $params[$par] = $value;
01237                                 }
01238                         }
01239                 }
01240 
01241                 if ($a_cmd != "")
01242                 {
01243                         $params["cmd"] = $a_cmd;
01244                 }
01245 
01246                 $params["cmdClass"] = $target_class;
01247                 $params["cmdNode"] = $nr;
01248                 $params["baseClass"] = $_GET["baseClass"];
01249 
01250                 return $params;
01251         }
01252 
01253 
01254 } // END class.ilCtrl
01255 ?>

Generated on Fri Dec 13 2013 17:56:47 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1