• 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 
00056 
00067         function &forwardCommand(&$a_gui_object)
00068         {
00069                 $class = strtolower(get_class($a_gui_object));
00070 
00071                 $nr = $this->getNodeIdForTargetClass($this->current_node, $class);
00072                 if ($nr > 0)
00073                 {
00074                         $this->current_node = $nr;
00075                         return $a_gui_object->executeCommand();
00076                 }
00077                 echo "ERROR: Can't forward to class $class."; exit;
00078 //echo "end forward<br>";
00079         }
00080 
00081 
00103         function getNodeIdForTargetClass($a_par_node, $a_class)
00104         {
00105                 $class = strtolower($a_class);
00106 
00107                 // target class is class of current node id
00108                 if ($class == $this->call_node[$a_par_node]["class"])
00109                 {
00110                         return $a_par_node;
00111                 }
00112 
00113                 // target class is child of current node id
00114                 foreach($this->call_node as $nr => $node)
00115                 {
00116                         if (($node["parent"] == $a_par_node) &&
00117                                 ($node["class"] == $class))
00118                         {
00119                                 return $nr;
00120                         }
00121                 }
00122 
00123                 // target class is sibling
00124                 $par = $this->call_node[$a_par_node]["parent"];
00125                 if ($par != 0)
00126                 {
00127                         foreach($this->call_node as $nr => $node)
00128                         {
00129                                 if (($node["parent"] == $par) &&
00130                                         ($node["class"] == $class))
00131                                 {
00132                                         return $nr;
00133                                 }
00134                         }
00135                 }
00136 
00137                 // target class is parent
00138                 while($par != 0)
00139                 {
00140                         if ($this->call_node[$par]["class"] == $class)
00141                         {
00142                                 return $par;
00143                         }
00144                         $par = $this->call_node[$par]["parent"];
00145                 }
00146 
00147                 echo "ERROR: Can't find target class $a_class for node $a_par_node.<br>"; exit;
00148         }
00149 
00155         function getCmdNode()
00156         {
00157                 return $_GET["cmdNode"];
00158         }
00159 
00167         function addLocation($a_title, $a_link, $a_target = "")
00168         {
00169                 $this->location[] = array("title" => $a_title,
00170                         "link" => $a_link, "target" => $a_target);
00171         }
00172 
00178         function getLocations()
00179         {
00180                 return $this->location;
00181         }
00182 
00191         function addTab($a_lang_var, $a_link, $a_cmd, $a_class)
00192         {
00193                 $a_class = strtolower($a_class);
00194 
00195                 $this->tab[] = array("lang_var" => $a_lang_var,
00196                         "link" => $a_link, "cmd" => $a_cmd, "class" => $a_class);
00197         }
00198 
00204         function getTabs()
00205         {
00206                 return $this->tab;
00207         }
00208 
00209 
00213         function getCallStructure($a_class, $a_nr = 0, $a_parent = 0)
00214         {
00215                 global $ilDB;
00216 
00217                 $a_class = strtolower($a_class);
00218 
00219                 $a_nr++;
00220                 $this->call_node[$a_nr] = array("class" => $a_class, "parent" => $a_parent);
00221 //echo "nr:$a_nr:class:$a_class:parent:$a_parent:<br>";
00222                 $q = "SELECT * FROM ctrl_calls WHERE parent=".
00223                         $ilDB->quote(strtolower($a_class)).
00224                         " ORDER BY child";
00225 
00226                 $call_set = $ilDB->query($q);
00227                 //$forw = array();
00228                 $a_parent = $a_nr;
00229                 while($call_rec = $call_set->fetchRow(DB_FETCHMODE_ASSOC))
00230                 {
00231                         $a_nr = $this->getCallStructure($call_rec["child"], $a_nr, $a_parent);
00232                         $forw[] = $call_rec["child"];
00233                 }
00234                 $this->forwards($a_class, $forw);
00235 //echo "<br><br>forwards:".$a_class."<br>"; var_dump($forw);
00236 
00237                 $this->root_class = $a_class;
00238                 return $a_nr;
00239         }
00240 
00244         function forwards($a_from_class, $a_to_class)
00245         {
00246                 $a_from_class = strtolower($a_from_class);
00247 
00248                 if (is_array($a_to_class))
00249                 {
00250                         foreach($a_to_class as $to_class)
00251                         {
00252                                 $this->forward[$a_from_class][] = strtolower($to_class);
00253                                 $this->parent[strtolower($to_class)][] = $a_from_class;
00254                         }
00255                 }
00256                 else
00257                 {
00258                         $this->forward[strtolower(get_class($a_obj))][] = strtolower($a_to_class);
00259                         $this->parent[strtolower($a_to_class)][] = strtolower(get_class($a_obj));
00260                 }
00261         }
00262 
00271         function saveParameter(&$a_obj, $a_parameter)
00272         {
00273                 if (is_array($a_parameter))
00274                 {
00275                         foreach($a_parameter as $parameter)
00276                         {
00277                                 $this->save_parameter[strtolower(get_class($a_obj))][] = $parameter;
00278                         }
00279                 }
00280                 else
00281                 {
00282                         $this->save_parameter[strtolower(get_class($a_obj))][] = $a_parameter;
00283                 }
00284         }
00285 
00290         function setParameter(&$a_obj, $a_parameter, $a_value)
00291         {
00292                 $this->parameter[strtolower(get_class($a_obj))][$a_parameter] = $a_value;
00293         }
00294 
00299         function setParameterByClass($a_class, $a_parameter, $a_value)
00300         {
00301                 $this->parameter[strtolower($a_class)][$a_parameter] = $a_value;
00302         }
00303 
00304 
00313         function getNextClass()
00314         {
00315 //echo "getNextClass:";
00316                 $cmdNode = $this->getCmdNode();
00317                 if ($cmdNode == "")
00318                 {
00319                         return false;
00320                 }
00321                 else
00322                 {
00323                         if ($this->current_node == $cmdNode)
00324                         {
00325 //echo "1:".$this->call_node[$cmdNode]["class"]."<br>";
00326                                 //return $this->call_node[$cmdNode]["class"];
00327                                 return "";
00328                         }
00329                         else
00330                         {
00331                                 $path = $this->getPathNew($this->current_node, $cmdNode);
00332 //echo "2:".$this->call_node[$path[1]]["class"]."<br>";
00333                                 return $this->call_node[$path[1]]["class"];
00334                         }
00335                 }
00336         }
00337 
00338 
00347         function getPathNew($a_source_node, $a_target_node)
00348         {
00349 //echo "-".$a_source_node."-";
00350                 $path_rev = array();
00351                 $c_target = $a_target_node;
00352                 while ($a_source_node != $c_target)
00353                 {
00354                         $path_rev[] = $c_target;
00355                         $c_target = $this->call_node[$c_target]["parent"];
00356                         if(!($c_target > 0))
00357                         {
00358                                 echo "ERROR: Path not found. Source:".$a_source_node.
00359                                         ", Target:".$a_target_node; exit;
00360                         }
00361                 }
00362                 if ($a_source_node == $c_target)
00363                 {
00364                         $path_rev[] = $c_target;
00365                 }
00366                 $path = array();
00367                 for ($i=0; $i<count($path_rev); $i++)
00368                 {
00369                         $path[] = $path_rev[count($path_rev) - ($i + 1)];
00370                 }
00371 
00372                 foreach($path as $node)
00373                 {
00374 //echo "<br>-->".$node.":".$this->call_node[$node]["class"];
00375                 }
00376                 return $path;
00377         }
00378 
00379         /*
00380         function getPath(&$path, $a_class, $a_target_class = "", $a_transits = "")
00381         {
00382 
00383                 // new path
00384                 if(!empty($this->call_node))
00385                 {
00386                         //$path = $this->getPathNew($a_class, $a_target_class);
00387                 }
00388 
00389                 $this->call_node[$nr] = array("class" => $a_class, "parent" => $a_parent);
00390 
00391                 $this->bench->start("GUIControl", "getPath");
00392 //echo "<br>"; var_dump($a_transits);
00393                 if ($a_target_class == "")
00394                 {
00395                         $a_target_class = $this->getCmdClass();
00396                 }
00397                 if ($a_target_class == "")
00398                 {
00399 //echo "1:$a_class<br>";
00400                         $path = array($a_class);
00401                         return;
00402                 }
00403 //echo "<br><b>FROM:".$a_class.":TO:".$a_target_class.":</b>";
00404 //echo "1";
00405                 $this->store_transit = $this->transit;
00406                 if (is_array($a_transits))
00407                 {
00408                         $this->transit = $a_transits;
00409                 }
00410                 else
00411                 {
00412                         if ($a_target_class != $this->getCmdClass())
00413                         {
00414 //echo "<br>:$a_target_class:".$this->getCmdClass().":DELTRANSIT";
00415                                 $this->transit = array();
00416                         }
00417                 }
00418 //echo "<br>"; var_dump($this->transit);
00419                 $next = $this->searchNext($path, $a_class, $a_target_class, array($a_class));
00420                 $this->transit = $this->store_transit;
00421 //foreach($path as $a_next) { echo "<br>->".$a_next; } echo "<br>";
00422                 $this->bench->stop("GUIControl", "getPath");
00423         }*/
00424 
00428         /*
00429         function searchNext(&$a_path, $a_class, $a_target_class, $c_path = "")
00430         {
00431                 $a_target_class = strtolower($a_target_class);
00432                 $a_class = strtolower($a_class);
00433 
00434                 if ($targetClass = $this->getNextTransit())
00435                 {
00436                         if ($a_class == $targetClass)
00437                         {
00438                                 $this->removeTransit();
00439                         }
00440                 }
00441                 else
00442                 {
00443                         $targetClass = $a_target_class;
00444                         if ($a_class == $a_target_class)
00445                         {
00446 //echo "2:$c_class<br>";
00447                                 $a_path = $c_path;
00448                                 return true;
00449                         }
00450                 }
00451 
00452 //echo "<br>...$a_class:$targetClass:<br>";
00453 
00454                 // recursively search each forward
00455                 if (is_array($this->forward[$a_class]))
00456                 {
00457                         reset($this->forward[$a_class]);
00458                         foreach($this->forward[$a_class] as $next_class)
00459                         {
00460                                 if ($next_class == strtolower($targetClass))
00461                                 {
00462                                         // found command class
00463                                         if ($next_class == $a_target_class)
00464                                         {
00465 //echo "3:$next_class<br>";
00466                                                 $c_path[] = $next_class;
00467                                                 $a_path = $c_path;
00468                                                 return true;
00469                                         }
00470                                         else
00471                                         {
00472 //echo "4:$next_class<br>";
00473                                                 // found a transit class
00474                                                 $c_path[] = $next_class;
00475                                                 $this->removeTransit();                                 // remove transit
00476                                                 if ($this->searchNext($a_path, $next_class, $a_target_class, $c_path))
00477                                                 {
00478                                                         return true;
00479                                                 }
00480                                                 return false;
00481                                         }
00482                                 }
00483                         }
00484                         reset($this->forward[$a_class]);
00485 //echo "4a:($a_class)<br";
00486                         foreach($this->forward[$a_class] as $next_class)
00487                         {
00488 //echo "5:$a_class:$next_class<br>";
00489                                 $c_path[] = $next_class;
00490                                 if ($this->searchNext($a_path, $next_class, $a_target_class, $c_path))
00491                                 {
00492 //echo "6:YES:"; var_dump($a_path);
00493                                         return true;
00494                                 }
00495                         }
00496                 }
00497                 return false;
00498         }*/
00499 
00500 
00506         function setTargetScript($a_target_script)
00507         {
00508                 $this->target_script = $a_target_script;
00509         }
00510 
00511 
00517         function getTargetScript()
00518         {
00519                 return $this->target_script;
00520         }
00521 
00522 
00526         function getCmd($a_default_cmd = "")
00527         {
00528                 $cmd = $_GET["cmd"];
00529                 if($cmd == "post")
00530                 {
00531                         $cmd = @key($_POST["cmd"]);
00532                 }
00533                 if($cmd == "")
00534                 {
00535                         $cmd = $a_default_cmd;
00536                 }
00537 
00538                 return $cmd;
00539         }
00540 
00551         function setCmd($a_cmd)
00552         {
00553                 $_GET["cmd"] = $a_cmd;
00554         }
00555 
00566         function setCmdClass($a_cmd_class)
00567         {
00568                 $a_cmd_class = strtolower($a_cmd_class);
00569 
00570 //echo "<br><b>setCmdClass:$a_cmd_class:</b>";
00571                 $nr = $this->getNodeIdForTargetClass($this->current_node, $a_cmd_class);
00572                 $_GET["cmdClass"] = $a_cmd_class;
00573                 $_GET["cmdNode"] = $nr;
00574         }
00575 
00579         function getCmdClass()
00580         {
00581                 return strtolower($_GET["cmdClass"]);
00582         }
00583 
00584         function getFormAction(&$a_gui_obj, $a_transits = "", $a_prepend_transits = false)
00585         {
00586                 $script =  $this->getFormActionByClass(strtolower(get_class($a_gui_obj)), $a_transits, $a_prepend_transits);
00587                 return $script;
00588         }
00589 
00590         function getFormActionByClass($a_class, $a_transits = "", $a_prepend_transits = false)
00591         {
00592                 $a_class = strtolower($a_class);
00593 
00594                 $script = $this->getLinkTargetByClass($a_class, "post", $a_transits, $a_prepend_transits);
00595                 return $script;
00596         }
00597 
00598         function redirect(&$a_gui_obj, $a_cmd = "")
00599         {
00600 //echo "<br>class:".get_class($a_gui_obj).":";
00601                 $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd);
00602 //echo "<br>script:$script:";
00603                 ilUtil::redirect($script);
00604         }
00605 
00606 
00613         function redirectByClass($a_class, $a_cmd = "")
00614         {
00615                 // $a_class may be an array
00616                 //$a_class = strtolower($a_class);
00617 
00618 //echo "<br>class:".get_class($a_gui_obj).":";
00619                 $script = $this->getLinkTargetByClass($a_class, $a_cmd);
00620 //echo "<br>script:$script:";
00621                 ilUtil::redirect($script);
00622         }
00623 
00624 
00633         function getLinkTarget(&$a_gui_obj, $a_cmd = "")
00634         {
00635 //echo "<br>getLinkTarget";
00636                 $script = $this->getLinkTargetByClass(strtolower(get_class($a_gui_obj)), $a_cmd);
00637                 return $script;
00638         }
00639 
00640 
00650         function getLinkTargetByClass($a_class, $a_cmd  = "", $a_transits = "", $a_prepend_transits = false)
00651         {
00652                 // note: $a_class may be an array
00653                 //$a_class = strtolower($a_class);
00654 
00655 //echo "<br>getLinkTargetByClass";
00656                 $script = $this->getTargetScript();
00657                 $script = $this->getUrlParameters($a_class, $script, $a_cmd, $transits);
00658 
00659                 return $script;
00660         }
00661 
00665         function setReturn(&$a_gui_obj, $a_cmd)
00666         {
00667                 $script = $this->getTargetScript();
00668                 $script = $this->getUrlParameters(strtolower(get_class($a_gui_obj)), $script, $a_cmd);
00669 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
00670                 $this->return[strtolower(get_class($a_gui_obj))] = $script;
00671         }
00672 
00676         function setReturnByClass($a_class, $a_cmd)
00677         {
00678                 // may not be an array!
00679                 $a_class = strtolower($a_class);
00680 
00681                 $script = $this->getTargetScript();
00682                 $script = $this->getUrlParameters($a_class, $script, $a_cmd);
00683 //echo "<br>setReturn:".get_class($a_gui_obj).":".$script.":<br>";
00684                 $this->return[strtolower($a_class)] = $script;
00685         }
00686 
00690         function returnToParent(&$a_gui_obj, $a_anchor = "")
00691         {
00692                 $script = $this->getParentReturn($a_gui_obj);
00693                 $script = ilUtil::appendUrlParameterString($script,
00694                         "redirectSource=".strtolower(get_class($a_gui_obj)));
00695                 if ($a_anchor != "")
00696                 {
00697                  $script = $script."#".$a_anchor;
00698                 }
00699                 ilUtil::redirect($script);
00700         }
00701 
00702 
00708         function getRedirectSource()
00709         {
00710                 return $_GET["redirectSource"];
00711         }
00712 
00716         function getParentReturn(&$a_gui_obj)
00717         {
00718                 return $this->getParentReturnByClass(strtolower(get_class($a_gui_obj)));
00719         }
00720 
00721 
00722         function getParentReturnByClass($a_class)
00723         {
00724                 $a_class = strtolower($a_class);
00725                 $ret_class = $this->searchReturnClass($a_class);
00726 //echo ":$ret_class:";
00727                 if($ret_class)
00728                 {
00729 //echo ":".$this->return[$ret_class].":";
00730                         return $this->return[$ret_class];
00731                 }
00732         }
00733 
00737         function searchReturnClass($a_class)
00738         {
00739 //echo "<br>searchReturnClass".$a_class;
00740                 $a_class = strtolower($a_class);
00741 
00742                 $nr = $this->getNodeIdForTargetClass($this->current_node, $a_class);
00743                 $path = $this->getPathNew(1, $nr);
00744 //var_dump($path);
00745                 for($i = count($path)-2; $i>=0; $i--)
00746                 {
00747 //echo "<br>:$i:".$path[$i].":".$this->call_node[$path[$i]]["class"]
00748 //             .":".$this->return[$this->call_node[$path[$i]]["class"]].":";
00749                         if ($this->return[$this->call_node[$path[$i]]["class"]] != "")
00750                         {
00751                                 return $this->call_node[$path[$i]]["class"];
00752                         }
00753                 }
00754 
00755                 return false;
00756         }
00757 
00758         function getUrlParameters($a_class, $a_str, $a_cmd = "", $a_transits = "")
00759         {
00760                 // note: $a_class may be an array!
00761                 //$a_class = strtolower($a_class);
00762 
00763                 $params = $this->getParameterArrayByClass($a_class, $a_cmd, $a_transits);
00764 
00765                 foreach ($params as $par => $value)
00766                 {
00767                         $a_str = ilUtil::appendUrlParameterString($a_str, $par."=".$value);
00768                 }
00769 
00770                 return $a_str;
00771         }
00772 
00773         function appendTransitClasses($a_str)
00774         {
00775                 if (is_array($_GET["cmdTransit"]))
00776                 {
00777                         reset($_GET["cmdTransit"]);
00778                         foreach ($_GET["cmdTransit"] as $transit)
00779                         {
00780                                 $a_str = ilUtil::appendUrlParameterString($a_str, "cmdTransit[]=".$transit);
00781                         }
00782                 }
00783                 return $a_str;
00784         }
00785 
00786         function getTransitArray()
00787         {
00788                 $trans_arr = array();
00789                 if (is_array($_GET["cmdTransit"]))
00790                 {
00791                         reset($_GET["cmdTransit"]);
00792                         foreach ($_GET["cmdTransit"] as $key => $transit)
00793                         {
00794                                 $trans_arr["cmdTransit[".$key."]"] = $transit;
00795                         }
00796                 }
00797                 return $trans_arr;
00798         }
00799 
00800         function addTransit($a_class)
00801         {
00802                 $a_class = strtolower($a_class);
00803                 $_GET["cmdTransit"][] = $a_class;
00804         }
00805 
00806         function getParameterArray(&$a_gui_obj, $a_cmd = "", $a_incl_transit = true)
00807         {
00808                 $par_arr = $this->getParameterArrayByClass(strtolower(get_class($a_gui_obj)), $a_cmd,
00809                         $trans_arr);
00810 
00811                 return $par_arr;
00812         }
00813 
00817         function getParameterArrayByClass($a_class, $a_cmd = "", $a_transits = "")
00818         {
00819 //echo "<br>getparameter for $a_class";
00820                 if ($a_class == "")
00821                 {
00822                         return array();
00823                 }
00824 
00825                 if (!is_array($a_class))
00826                 {
00827                         $a_class = array($a_class);
00828                 }
00829 
00830                 $nr = $this->current_node;
00831                 foreach ($a_class as $class)
00832                 {
00833 //echo "<br>-$class-";
00834                         $class = strtolower($class);
00835                         $nr = $this->getNodeIdForTargetClass($nr, $class);
00836                         $target_class = $class;
00837 //echo "-$nr-";
00838                 }
00839 
00840                 $path = $this->getPathNew(1, $nr);
00841                 $params = array();
00842 
00843                 // append parameters of parent classes
00844                 foreach($path as $node_id)
00845                 {
00846                         $class = $this->call_node[$node_id]["class"];
00847                         if (is_array($this->save_parameter[$class]))
00848                         {
00849                                 foreach($this->save_parameter[$class] as $par)
00850                                 {
00851                                         $params[$par] = $_GET[$par];
00852                                 }
00853                         }
00854 
00855                         if (is_array($this->parameter[$class]))
00856                         {
00857                                 foreach($this->parameter[$class] as $par => $value)
00858                                 {
00859                                         $params[$par] = $value;
00860                                 }
00861                         }
00862                 }
00863 
00864                 if ($a_cmd != "")
00865                 {
00866                         $params["cmd"] = $a_cmd;
00867                 }
00868 
00869                 $params["cmdClass"] = $target_class;
00870                 $params["cmdNode"] = $nr;
00871 
00872                 return $params;
00873         }
00874 
00875 
00876 } // END class.ilCtrl
00877 ?>

Generated on Fri Dec 13 2013 09:06:33 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1