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

setup/classes/class.ilCtrlStructureReader.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 
00034 class ilCtrlStructureReader
00035 {
00036         var $class_script;
00037         var $class_childs;
00038         var $executed;
00039 
00040         function ilCtrlStructureReader()
00041         {
00042                 $this->class_script = array();
00043                 $this->class_childs = array();
00044                 $this->executed = false;
00045         }
00046 
00047         function setErrorObject(&$err)
00048         {
00049                 $this->err_object =& $err;
00050         }
00051         
00055         function getStructure()
00056         {
00057                 $this->get_structure = true;
00058         }
00059                 
00060         function readStructure($a_force = false)
00061         {
00062 
00063                 if (!$this->get_structure && !$a_force)
00064                 {
00065                         return;
00066                 }
00067 
00068                 // only run one time per db_update request
00069                 if (!$this->executed)
00070                 {
00071                         $this->read(ILIAS_ABSOLUTE_PATH);
00072                         $this->store();
00073                         $this->executed = true;
00074                 }
00075                 
00076                 // read module information
00077                 // not clear whether this is a good place for module reading info
00078                 // or not
00079                 require_once("../classes/class.ilCtrl.php");
00080                 $ctrl = new ilCtrl();
00081                 $ctrl->storeCommonStructures();
00082         }
00083 
00089         function read($a_cdir)
00090         {
00091                 global $ilDB, $lng;
00092                 
00093                 // check wether $a_cdir is a directory
00094                 if (!@is_dir($a_cdir))
00095                 {
00096                         return false;
00097                 }
00098 
00099                 // read current directory
00100                 $dir = opendir($a_cdir);
00101 
00102                 while($file = readdir($dir))
00103                 {
00104                         if ($file != "." and
00105                                 $file != "..")
00106                         {
00107                                 // directories
00108                                 if (@is_dir($a_cdir."/".$file))
00109                                 {
00110                                         if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data")
00111                                         {
00112                                                 $this->read($a_cdir."/".$file);
00113                                         }
00114                                 }
00115 
00116                                 // files
00117                                 if (@is_file($a_cdir."/".$file))
00118                                 {
00119                                         if (eregi("^class.*php$", $file))
00120                                         {
00121                                                 $handle = fopen($a_cdir."/".$file, "r");
00122 //echo "<br>".$a_cdir."/".$file;
00123                                                 while (!feof($handle)) {
00124                                                         $line = fgets($handle, 4096);
00125                                                         $pos = strpos(strtolower($line), "@ilctrl_calls");
00126                                                         if (is_int($pos))
00127                                                         {
00128                                                                 $com = substr($line, $pos + 14);
00129                                                                 $pos2 = strpos($com, ":");
00130                                                                 if (is_int($pos2))
00131                                                                 {
00132                                                                         $com_arr = explode(":", $com);
00133                                                                         $parent = strtolower(trim($com_arr[0]));
00134                                                                         
00135                                                                         // check file duplicates
00136                                                                         if ($parent != "" && isset($this->class_script[$parent]) &&
00137                                                                                 $this->class_script[$parent] != $a_cdir."/".$file)
00138                                                                         {
00139                                                                                 // delete all class to file assignments
00140                                                                                 $q = "DELETE FROM ctrl_classfile";
00141                                                                                 $ilDB->query($q);
00142                                                                 
00143                                                                                 // delete all call entries
00144                                                                                 $q = "DELETE FROM ctrl_calls";
00145                                                                                 $ilDB->query($q);
00146                                                                                 
00147                                                                                 $this->err_object->raiseError(
00148                                                                                         sprintf($lng->txt("duplicate_ctrl"),
00149                                                                                                 $parent,
00150                                                                                                 $this->class_script[$parent],
00151                                                                                                 $a_cdir."/".$file)
00152                                                                                         , $this->err_object->MESSAGE);
00153                                                                         }
00154 
00155                                                                         $this->class_script[$parent] = $a_cdir."/".$file;
00156                                                                         $childs = explode(",", $com_arr[1]);
00157                                                                         foreach($childs as $child)
00158                                                                         {
00159                                                                                 $child = trim(strtolower($child));
00160                                                                                 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
00161                                                                                 {
00162                                                                                         $this->class_childs[$parent][] = $child;
00163                                                                                 }
00164                                                                         }
00165                                                                 }
00166                                                         }
00167                                                 }
00168                                                 fclose($handle);
00169                                         }
00170                                 }
00171                         }
00172                 }
00173         }
00174 
00180         function store($a_cdir = "./..")
00181         {
00182                 global $ilDB;
00183 
00184                 // delete all class to file assignments
00185                 $q = "DELETE FROM ctrl_classfile";
00186                 $ilDB->query($q);
00187 
00188                 // delete all call entries
00189                 $q = "DELETE FROM ctrl_calls";
00190                 $ilDB->query($q);
00191 
00192                 foreach($this->class_script as $class => $script)
00193                 {
00194                         $file = substr($script, strlen(ILIAS_ABSOLUTE_PATH) + 1);
00195 
00196                         // store class to file assignment
00197                         $q = "INSERT INTO ctrl_classfile (class, file) VALUES".
00198                                 "(".$ilDB->quote($class).",".$ilDB->quote($file).")";
00199                         $ilDB->query($q);
00200 
00201                         if (is_array($this->class_childs[$class]))
00202                         {
00203                                 foreach($this->class_childs[$class] as $child)
00204                                 {
00205                                         // store call entry
00206                                         $q = "INSERT INTO ctrl_calls (parent, child) VALUES".
00207                                                 "(".$ilDB->quote($class).",".$ilDB->quote($child).")";
00208                                         $ilDB->query($q);
00209                                 }
00210                         }
00211                 }
00212 
00213         }
00214 
00215 }

Generated on Fri Dec 13 2013 11:57:59 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1