ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCtrlStructureReader.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
17  var $executed;
18 
20  {
21  $this->class_script = array();
22  $this->class_childs = array();
23  $this->executed = false;
24  $this->ini = $a_ini_file;
25  }
26 
27  function setIniFile($a_ini_file)
28  {
29  $this->ini = $a_ini_file;
30  }
31 
32  function setErrorObject(&$err)
33  {
34  $this->err_object =& $err;
35  }
36 
40  function getStructure()
41  {
42  global $ilDB;
43 
44  $this->ini->setVariable("db","structure_reload", "1");
45  $this->ini->write();
46  if ($this->ini->readVariable("db","structure_reload") != "1")
47  {
48  echo "Error Cannot write client.ini.file.";
49  }
50  //$this->get_structure = true;
51  }
52 
56  function readStructure($a_force = false, $a_dir = "", $a_comp_prefix = "",
57  $a_plugin_path = "")
58  {
59  global $ilDB;
60 
61  if (!$a_force && $this->ini->readVariable("db","structure_reload") != "1")
62  {
63  return;
64  }
65 
66  // prefix for component
67  $this->comp_prefix = $a_comp_prefix;
68 
69  // plugin path
70  $this->plugin_path = $a_plugin_path;
71 
72  // only run one time per db_update request
73  if (!$this->executed)
74  {
75  if ($a_dir == "")
76  {
77  $this->start_dir = ILIAS_ABSOLUTE_PATH;
78  $this->read(ILIAS_ABSOLUTE_PATH);
79  }
80  else
81  {
82  $this->start_dir = $a_dir;
83  $this->read($a_dir);
84  }
85  $this->store();
86  $this->determineClassFileIds();
87  $this->executed = true;
88  if (!$a_force)
89  {
90  $this->ini->setVariable("db","structure_reload", "0");
91  $this->ini->write();
92  }
93  }
94 
95  // read module information
96  // not clear whether this is a good place for module reading info
97  // or not
98  include_once("./classes/class.ilCtrl.php");
99  $ctrl = new ilCtrl();
100 // $ctrl->storeCommonStructures();
101  }
102 
108  function read($a_cdir)
109  {
110  global $ilDB, $lng;
111 
112  // check wether $a_cdir is a directory
113  if (!@is_dir($a_cdir))
114  {
115  return false;
116  }
117 
118  // read current directory
119  $dir = opendir($a_cdir);
120 
121  while($file = readdir($dir))
122  {
123  if ($file != "." and
124  $file != "..")
125  {
126  // directories
127  if (@is_dir($a_cdir."/".$file))
128  {
129  if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data" &&
130  $a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/Customizing")
131  {
132  $this->read($a_cdir."/".$file);
133  }
134  }
135 
136  // files
137  if (@is_file($a_cdir."/".$file))
138  {
139  if (eregi("^class.*php$", $file) || eregi("^ilSCORM13Player.php$", $file))
140  {
141  $handle = fopen($a_cdir."/".$file, "r");
142 //echo "<br>".$a_cdir."/".$file;
143  while (!feof($handle)) {
144  $line = fgets($handle, 4096);
145 
146  // handle @ilctrl_calls
147  $pos = strpos(strtolower($line), "@ilctrl_calls");
148  if (is_int($pos))
149  {
150  $com = substr($line, $pos + 14);
151  $pos2 = strpos($com, ":");
152  if (is_int($pos2))
153  {
154  $com_arr = explode(":", $com);
155  $parent = strtolower(trim($com_arr[0]));
156 
157  // check file duplicates
158  if ($parent != "" && isset($this->class_script[$parent]) &&
159  $this->class_script[$parent] != $a_cdir."/".$file)
160  {
161  // delete all class to file assignments
162  $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = ".
163  $ilDB->quote($this->comp_prefix, "text"));
164  if ($this->comp_prefix == "")
165  {
166  $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE ".
167  $ilDB->equals("comp_prefix", "", "text", true));
168  }
169 
170  // delete all call entries
171  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = ".
172  $ilDB->quote($this->comp_prefix, "text"));
173  if ($this->comp_prefix == "")
174  {
175  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix IS NULL");
176  }
177 
178  $this->err_object->raiseError(
179  sprintf($lng->txt("duplicate_ctrl"),
180  $parent,
181  $this->class_script[$parent],
182  $a_cdir."/".$file)
183  , $this->err_object->MESSAGE);
184  }
185 
186  $this->class_script[$parent] = $a_cdir."/".$file;
187  $childs = explode(",", $com_arr[1]);
188  foreach($childs as $child)
189  {
190  $child = trim(strtolower($child));
191  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
192  {
193  $this->class_childs[$parent][] = $child;
194  }
195  }
196  }
197  }
198 
199  // handle isCalledBy comments
200  $pos = strpos(strtolower($line), "@ilctrl_iscalledby");
201  if (is_int($pos))
202  {
203  $com = substr($line, $pos + 19);
204  $pos2 = strpos($com, ":");
205  if (is_int($pos2))
206  {
207  $com_arr = explode(":", $com);
208  $child = strtolower(trim($com_arr[0]));
209  $this->class_script[$child] = $a_cdir."/".$file;
210 
211  $parents = explode(",", $com_arr[1]);
212  foreach($parents as $parent)
213  {
214  $parent = trim(strtolower($parent));
215  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
216  {
217  $this->class_childs[$parent][] = $child;
218  }
219  }
220  }
221  }
222 
223  if (eregi("^class\.(.*GUI)\.php$", $file, $res))
224  {
225  $cl = strtolower($res[1]);
226  $pos = strpos(strtolower($line), "class ".$cl);
227  if (is_int($pos) && $this->class_script[$cl] == "")
228  {
229  $this->class_script[$cl] = $a_cdir."/".$file;
230  //echo "<br>".$cl."-".$this->class_script[$cl]."-";
231  }
232  }
233  }
234  fclose($handle);
235  }
236  }
237  }
238  }
239  }
240 
246  function store($a_cdir = "./..")
247  {
248  global $ilDB;
249 
250  // delete all class to file assignments
251  $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = ".
252  $ilDB->quote($this->comp_prefix, "text"));
253  if ($this->comp_prefix == "")
254  {
255  $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE ".
256  $ilDB->equals("comp_prefix", "", "text", true));
257  }
258 
259  // delete all call entries
260  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = ".
261  $ilDB->quote($this->comp_prefix, "text"));
262  if ($this->comp_prefix == "")
263  {
264  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE ".
265  $ilDB->equals("comp_prefix", "", "text", true));
266  }
267 
268  foreach($this->class_script as $class => $script)
269  {
270  $file = substr($script, strlen($this->start_dir) + 1);
271 
272  // store class to file assignment
273  $ilDB->manipulate(sprintf("INSERT INTO ctrl_classfile (class, filename, comp_prefix, plugin_path) ".
274  " VALUES (%s,%s,%s,%s)",
275  $ilDB->quote($class, "text"),
276  $ilDB->quote($file, "text"),
277  $ilDB->quote($this->comp_prefix, "text"),
278  $ilDB->quote($this->plugin_path, "text")
279  ));
280  }
281 //$this->class_childs[$parent][] = $child;
282  foreach($this->class_childs as $parent => $v)
283  {
284  if (is_array($this->class_childs[$parent]))
285  {
286  foreach($this->class_childs[$parent] as $child)
287  {
288  // store call entry
289  $ilDB->manipulate(sprintf("INSERT INTO ctrl_calls (parent, child, comp_prefix) ".
290  "VALUES (%s,%s,%s)",
291  $ilDB->quote($parent, "text"),
292  $ilDB->quote($child, "text"),
293  $ilDB->quote($this->comp_prefix, "text")));
294  }
295  }
296  }
297 
298  }
299 
304  {
305  global $ilDB;
306 
307  $ilDB->manipulate("UPDATE ctrl_classfile SET ".
308  " cid = ".$ilDB->quote("", "text")
309  );
310  $set = $ilDB->query("SELECT * FROM ctrl_classfile ");
311  $cnt = 1;
312  while ($rec = $ilDB->fetchAssoc($set))
313  {
314  $cid = base_convert((string) $cnt, 10, 36);
315  $ilDB->manipulate("UPDATE ctrl_classfile SET ".
316  " cid = ".$ilDB->quote($cid, "text").
317  " WHERE class = ".$ilDB->quote($rec["class"], "text")
318  );
319  $cnt++;
320  }
321  }
322 }
323 ?>