Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00069 if (!$this->executed)
00070 {
00071 $this->read(ILIAS_ABSOLUTE_PATH);
00072 $this->store();
00073 $this->executed = true;
00074 }
00075
00076
00077
00078
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
00094 if (!@is_dir($a_cdir))
00095 {
00096 return false;
00097 }
00098
00099
00100 $dir = opendir($a_cdir);
00101
00102 while($file = readdir($dir))
00103 {
00104 if ($file != "." and
00105 $file != "..")
00106 {
00107
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
00117 if (@is_file($a_cdir."/".$file))
00118 {
00119 if (eregi("^class.*php$", $file))
00120 {
00121 $handle = fopen($a_cdir."/".$file, "r");
00122
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
00136 if ($parent != "" && isset($this->class_script[$parent]) &&
00137 $this->class_script[$parent] != $a_cdir."/".$file)
00138 {
00139
00140 $q = "DELETE FROM ctrl_classfile";
00141 $ilDB->query($q);
00142
00143
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
00185 $q = "DELETE FROM ctrl_classfile";
00186 $ilDB->query($q);
00187
00188
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
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
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 }