11cf83c782903240b5a51600d3ed4573f125c7c1
[mailer.git] / inc / extensions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 03/25/2004 *
4  * ===============                              Last change: 09/29/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : extensions.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Extension management                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Erweiterungen-Management                         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 }
44
45 // Load the extension and maybe found language and function files.
46 function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = "", $EXT_VER = "", $dry_run = false) {
47         // Init array
48         INIT_INC_POOL();
49
50         // Set current extension name
51         EXT_SET_CURR_NAME($ext_name);
52
53         // Init EXT_UPDATE_DEPENDS
54         EXT_INIT_UPDATE_DEPENDS();
55
56         // Init current extension name list
57         INIT_EXT_SQLS();
58
59         // Is the extension already loaded?
60         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode={$EXT_LOAD_MODE}, ver={$EXT_VER}.");
61         if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (empty($EXT_LOAD_MODE))) {
62                 // Debug message
63                 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
64                 return false;
65         } // END - if
66
67         // Construct include filename and FQFN for extension file
68         $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
69         $FQFN = constant('PATH') . $INC;
70
71         // Is the extension file NOT there?
72         if (!INCLUDE_READABLE($INC)) {
73                 // Debug message
74                 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s not found.", $ext_name));
75
76                 // Abort here
77                 return false;
78         } // END - if
79
80         // Construct FQFN for language file
81         $langInclude = sprintf("inc/language/%s_%s.php", $ext_name, GET_LANGUAGE());
82
83         // Is this include there?
84         if ((FILE_READABLE($langInclude)) && (!isset($GLOBALS['ext_loaded']['lang'][$ext_name]))) {
85                 // Then load it
86                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Language loaded.");
87                 $GLOBALS['ext_loaded']['lang'][$ext_name] = true;
88                 LOAD_INC_ONCE($langInclude);
89         } // END - if
90
91         // Construct FQFN for functions file
92         $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
93
94         // Is this include there?
95         if ((FILE_READABLE($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name]))) {
96                 // Then load it
97                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Functions loaded.");
98                 $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
99                 LOAD_INC_ONCE($funcsInclude);
100         } // END - if
101
102         // Extensions are not deprecated by default
103         EXT_SET_DEPRECATED("N");
104
105         // Extensions are not always active by default
106         EXT_SET_ALWAYS_ACTIVE("N");
107
108         // Extension update notes
109         EXT_SET_UPDATE_NOTES("");
110
111         // Include the extension file
112         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Extension loaded.");
113         require($FQFN);
114
115         // Is this extension deprecated?
116         if (EXT_GET_DEPRECATED() == "Y") {
117                 // Deactivate the extension
118                 DEACTIVATE_EXTENSION($ext_name);
119
120                 // Abort here
121                 return false;
122         } // END - if
123
124         // Mark it as loaded in normal mode
125         if (empty($EXT_LOAD_MODE)) {
126                 // Mark it now...
127                 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
128         } // END - if
129
130         // All fine!
131         return true;
132 }
133
134 // Registeres an extension and possible update depencies
135 function REGISTER_EXTENSION ($ext_name, $task_id, $dry_run = false, $logout = true) {
136         // This shall never do a non-admin user!
137         if (!IS_ADMIN()) return false;
138
139         // Is this extension already installed?
140         if (EXT_IS_ACTIVE($ext_name)) return false;
141
142         // Set current extension name
143         EXT_SET_CURR_NAME($ext_name);
144
145         // Init EXT_UPDATE_DEPENDS
146         EXT_INIT_UPDATE_DEPENDS();
147
148         // Is the task id zero? Then we need to auto-fix it here
149         if ($task_id == 0) {
150                 // Try to find the task
151                 $task_id = DETERMINE_EXTENSION_TASK_ID(EXT_GET_CURR_NAME());
152
153                 // Still zero and not in dry-run?
154                 if (($task_id == 0) && (!$dry_run)) {
155                         // Then request a bug report
156                         debug_report_bug(sprintf("%s: task_id is still zero after DETERMINE_EXTENSION_TASK_ID(%s)",
157                                 __FUNCTION__,
158                                 EXT_GET_CURR_NAME()
159                         ));
160                 } // END - if
161         } // END - if
162
163         // Init queries and notes
164         INIT_EXT_SQLS();
165         EXT_INIT_NOTES();
166
167         // Init variables
168         $ret = false;
169         $test = false;
170         INIT_INC_POOL();
171
172         // By default we have no failures
173         EXT_SET_REPORTS_FAILURE(false);
174
175         // Does this extension exists?
176         //* DEBUG: */ print __LINE__.":".EXT_GET_CURR_NAME()."<br />\n";
177         if (LOAD_EXTENSION(EXT_GET_CURR_NAME(), "register", "", $dry_run)) {
178                 // And run possible updates
179                 //* DEBUG: */ print __LINE__.":".EXT_GET_CURR_NAME()."<br />\n";
180                 $history = EXT_GET_VER_HISTORY();
181                 foreach ($history as $ver) {
182                         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ext_name={EXT_GET_CURR_NAME()}, ext_ver={$ver}");
183                         // Load extension in update mode
184                         LOAD_EXTENSION(EXT_GET_CURR_NAME(), "update", $ver, $dry_run);
185
186                         // Add update notes to our output
187                         ADD_EXTENSION_NOTES($ver);
188                 } // END - foreach
189
190                 // Does this extension depends on an outstanding update of another update?
191                 for ($dmy = EXT_GET_UPDATE_ITERATOR(); EXT_GET_UPDATE_ITERATOR() < EXT_COUNT_UPDATE_DEPENDS();) {
192                         // Get next update
193                         $ext_update = EXT_GET_ITERATOR_UPDATE_DEPENDS();
194
195                         // Increment here to avoid endless loop
196                         EXT_INCREMENT_UPDATE_INTERATOR();
197
198                         // Check for required file
199                         if (LOAD_EXTENSION($ext_update, "register", "", $dry_run)) {
200                                 // If versions mismatch update extension first
201                                 $ext_ver = GET_EXT_VERSION($ext_update);
202
203                                 // Extension version set? If empty the extension is not registered
204                                 if (empty($ext_ver)) {
205                                         // Extension not registered so far so first load task's ID...
206                                         $task = DETERMINE_EXTENSION_TASK_ID($ext_update);
207
208                                         // Entry found?
209                                         if ($task > 0) {
210                                                 // Try to register the extension
211                                                 //* DEBUG: */ print __LINE__.sprintf(":ext_update=%s,task=%s<br />\n", $ext_update, $task);
212                                                 $test = REGISTER_EXTENSION($ext_update, $task, $dry_run, false);
213                                                 //* DEBUG: */ var_dump($test);
214                                         } // END - if
215                                 } elseif ($ext_ver != EXT_GET_VERSION()) {
216                                         // Ok, update this extension now
217                                         EXTENSION_UPDATE($ext_update, $ext_ver, $dry_run);
218
219                                         // All okay!
220                                         $test = true;
221                                 } else {
222                                         // Nothing to register / update before...
223                                         $test = true;
224                                 }
225                         } else {
226                                 // Required file for update does not exists!
227                                 $test = true;
228                                 // But this is fine for the first time...
229                         }
230
231                         // Restore the current extension name
232                         EXT_SET_CURR_NAME($ext_name);
233                 } // END - for
234
235                 // Is there no update?
236                 if (EXT_COUNT_UPDATE_DEPENDS(EXT_GET_CURR_NAME()) == 0) {
237                         // Then test is passed!
238                         $test = true;
239                 } // END - if
240
241                 // Switch back to register mode
242                 $EXT_LOAD_MODE = "register";
243
244                 // Remains true if extension registration reports no failures
245                 //* DEBUG: */ print __LINE__.":".EXT_GET_CURR_NAME();
246                 //* DEBUG: */ var_dump($test);
247                 $test = (($test === true) && (EXT_GET_REPORTS_FAILURE() === false));
248                 //* DEBUG: */ var_dump($test);
249
250                 // Does everthing before wents ok?
251                 if ($test === true) {
252                         // "Dry-run-mode" activated?
253                         if ((!$dry_run) && (!EXT_IS_ON_REMOVAL_LIST())) {
254                                 //* DEBUG: */ print __LINE__.": ext_name=".EXT_GET_CURR_NAME()."<br />\n";
255                                 // Init SQLs and transfer ext->generic
256                                 INIT_SQLS();
257                                 SET_SQLS(GET_EXT_SQLS());
258
259                                 // Run installation pre-installation filters
260                                 runFilterChain('pre_extension_installed', array('dry_run' => $dry_run));
261
262                                 // Register extension
263                                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_extensions` (ext_name, ext_active, ext_version) VALUES ('%s','%s','%s')",
264                                         array(EXT_GET_CURR_NAME(), EXT_GET_ALWAYS_ACTIVE(), EXT_GET_VERSION()), __FILE__, __LINE__);
265
266                                 // Remove cache file(s) if extension is active
267                                 runFilterChain('post_extension_installed', array('ext_name' => EXT_GET_CURR_NAME(), 'task_id' => $task_id));
268
269                                 // Remove all SQL commands
270                                 UNSET_SQLS();
271
272                                 // In normal mode return a true on success
273                                 $ret = true;
274                         } elseif ($dry_run) {
275                                 // Init SQLs and transfer ext->generic
276                                 INIT_SQLS();
277                                 SET_SQLS(GET_EXT_SQLS());
278
279                                 // Rewrite SQL command to keep { and } inside for dry-run
280                                 foreach (GET_SQLS() as $key => $sql) {
281                                         $sql = str_replace('{', "&#123;", str_replace('}', "&#125;", $sql));
282                                         SET_SQL_KEY($key, $sql);
283                                 } // END - foreach
284
285                                 // In  "dry-run" mode return array with all SQL commands
286                                 $ret = GET_SQLS();
287
288                                 // Remove all SQL commands
289                                 UNSET_SQLS();
290                         } else {
291                                 // Extension has been removed for updates, so all is fine!
292                                 $ret = true;
293                         }
294                 } else {
295                         // No, an error occurs while registering extension :-(
296                         //* DEBUG: */ print __LINE__.":".EXT_GET_CURR_NAME()."<br />\n";
297                         $ret = false;
298                 }
299         } elseif (($task_id > 0) && (EXT_GET_CURR_NAME() != "")) {
300                 // Remove task from system when id and extension's name is valid
301                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s AND `status`='NEW' LIMIT 1",
302                         array(bigintval($task_id)), __FILE__, __LINE__);
303         }
304
305         // Is this the sql_patches?
306         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":{EXT_GET_CURR_NAME()}/{$EXT_LOAD_MODE}");
307         if ((EXT_GET_CURR_NAME() == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove")) && (!$dry_run) && ($test)) {
308                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": LOAD!");
309                 if ($logout === true) {
310                         // Then redirect to logout
311                         LOAD_URL("modules.php?module=admin&amp;logout=1&amp;".$EXT_LOAD_MODE."=sql_patches");
312                 } else {
313                         // Add temporary filter
314                         REGISTER_FILTER('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
315                         $GLOBALS['ext_load_mode'] = $EXT_LOAD_MODE;
316                 }
317         } // END - if
318
319         // Return status code
320         return $ret;
321 }
322
323 // Run SQL queries for given extension id
324 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
325 function EXTENSION_RUN_SQLS ($ext_id, $load_mode) {
326         // This shall never do a non-admin user!
327         if (!IS_ADMIN()) return false;
328
329         // Get extension's name
330         $ext_name = GET_EXT_NAME($ext_id);
331
332         // If it is not set then maybe there is no extension for that ID number
333         if ($ext_name == "") return false;
334
335         // Set current SQL name
336         EXT_SET_CURR_NAME($ext_name);
337
338         // Init EXT_UPDATE_DEPENDS
339         EXT_INIT_UPDATE_DEPENDS();
340
341         // Init array
342         INIT_EXT_SQLS();
343
344         // By default no SQL has been executed
345         $sqlRan = false;
346
347         // Load extension in detected mode
348         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]={EXT_GET_CURR_NAME()}");
349         LOAD_EXTENSION(EXT_GET_CURR_NAME(), $load_mode, "", false);
350
351         // Init these SQLs
352         INIT_SQLS();
353         SET_SQLS(GET_EXT_SQLS());
354
355         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":SQLs::count=".COUNT_SQLS()."");
356         if ((IS_SQLS_VALID() && (COUNT_SQLS() > 0))) {
357                 // Run SQL commands...
358                 runFilterChain('run_sqls');
359
360                 // Removal mode?
361                 if ($load_mode == "remove") {
362                         // Delete this extension (remember to remove it from your server *before* you click on welcome!
363                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
364                                 array(EXT_GET_CURR_NAME()), __FILE__, __LINE__);
365                 } // END - if
366         } // END - if
367
368         // Remove cache file(s) if extension is active
369         if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == "activate") || ($load_mode == "deactivate"))) {
370                 // Run filters
371                 runFilterChain('post_extension_run_sql', EXT_GET_CURR_NAME());
372         } // END - if
373
374         // Is this the sql_patches?
375         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": {$ext_id}/{EXT_GET_CURR_NAME()}/{$load_mode}");
376         if ((EXT_GET_CURR_NAME() == "sql_patches") && (($load_mode == "register") || ($load_mode == "remove"))) {
377                 // Then redirect to logout
378                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": LOAD!");
379                 LOAD_URL("modules.php?module=admin&amp;logout=1&amp;".$load_mode."=sql_patches");
380         } // END - if
381 }
382
383 // Check if given extension is active
384 function EXT_IS_ACTIVE ($ext_name) {
385         // Extensions are all inactive during installation
386         if ((!isInstalled()) || (isInstalling()) || (empty($ext_name))) return false;
387
388         // Not active is the default
389         $active = "N";
390
391         // Check cache
392         if (isset($GLOBALS['cache_array']['extensions']['ext_active'][$ext_name])) {
393                 // Load from cache
394                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
395                 $active = $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name];
396
397                 // Count cache hits
398                 incrementConfigEntry('cache_hits');
399         } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
400                 // @TODO Extension is loaded, what next?
401                 mxchange_die("LOADED:$ext_name");
402         } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
403                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
404                 // Load from database
405                 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
406                         array($ext_name), __FILE__, __LINE__);
407
408                 // Entry found?
409                 if (SQL_NUMROWS($result) == 1) {
410                         // Load entry
411                         list($active) = SQL_FETCHROW($result);
412                 } // END - if
413
414                 // Free result
415                 SQL_FREERESULT($result);
416
417                 // Write cache array
418                 //* DEBUG: */ echo $ext_name."[DB]: {$active}<br />\n";
419                 $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name] = $active;
420         } else {
421                 // Extension not active!
422                 //* DEBUG: */ echo $ext_name.": Not active!<br />\n";
423                 $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name] = "N";
424         }
425
426         // Debug message
427         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, " ext_name={$ext_name},active={$active}");
428
429         // Is this extension activated? (For admins we always have active extensions...)
430         return ($active == "Y");
431 }
432 // Get version from extensions
433 function GET_EXT_VERSION ($ext_name) {
434         // By default no extension is found
435         $ext_ver = false;
436
437         // Empty extension name should be fixed!
438         if (empty($ext_name)) {
439                 // Please report this bug!
440                 debug_report_bug(__FUNCTION__.": ext_name is empty which is not allowed here.");
441         } // END - if
442
443         // Extensions are all inactive during installation
444         if ((!isInstalled()) || (isInstalling())) return "";
445         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": ext_name={$ext_name}");
446
447         // Is the cache written?
448         if (isset($GLOBALS['cache_array']['extensions']['ext_version'][$ext_name])) {
449                 // Load data from cache
450                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": CACHE!");
451                 $ext_ver = $GLOBALS['cache_array']['extensions']['ext_version'][$ext_name];
452
453                 // Count cache hits
454                 incrementConfigEntry('cache_hits');
455         } elseif (!isCacheInstanceValid()) {
456                 // Load from database
457                 $result = SQL_QUERY_ESC("SELECT ext_version FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
458                         array($ext_name), __FILE__, __LINE__);
459                 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
460
461                 // Is the extension there?
462                 if (SQL_NUMROWS($result) == 1) {
463                         // Load entry
464                         list($ext_ver) = SQL_FETCHROW($result);
465                 } // END - if
466
467                 // Free result
468                 SQL_FREERESULT($result);
469
470                 // Set cache
471                 $GLOBALS['cache_array']['extensions']['ext_version'][$ext_name] = $ext_ver;
472         }
473
474         // Return result
475         //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": ret={$ext_ver}");
476         return $ext_ver;
477 }
478
479 // Updates a given extension with current extension version to latest version
480 function EXTENSION_UPDATE ($ext_name, $ext_ver, $dry_run = false) {
481         // Only admins are allowed to update extensions
482         if ((!IS_ADMIN()) || (empty($ext_name))) return false;
483
484         // Set current SQL name
485         EXT_SET_CURR_NAME($ext_name);
486
487         // Init arrays
488         INIT_EXT_SQLS();
489         EXT_INIT_NOTES();
490         INIT_INC_POOL();
491
492         // Load extension in test mode
493         LOAD_EXTENSION($ext_name, "test", $ext_ver, $dry_run);
494
495         // Save version history
496         $history = EXT_GET_VER_HISTORY();
497
498         // Remove old SQLs array to prevent possible bugs
499         INIT_EXT_SQLS();
500
501         // Check if version is updated
502         if (((EXT_GET_VERSION() != $ext_ver) || ($dry_run)) && (is_array($history))) {
503                 // Search for starting point
504                 $start = array_search($ext_ver, $history);
505
506                 // And load SQL queries in order of version history
507                 for ($idx = ($start + 1); $idx < count($history); $idx++) {
508                         // Set extension version
509                         $GLOBALS['cache_array']['update_ver'][EXT_GET_CURR_NAME()] = $history[$idx];
510
511                         // Load again...
512                         LOAD_EXTENSION(EXT_GET_CURR_NAME(), "update", $GLOBALS['cache_array']['update_ver'][EXT_GET_CURR_NAME()], $dry_run);
513
514                         if (EXT_GET_UPDATE_DEPENDS() != "") {
515                                 // Is the extension there?
516                                 if (GET_EXT_VERSION(EXT_GET_UPDATE_DEPENDS()) != "") {
517                                         // Update another extension first!
518                                         $test = EXTENSION_UPDATE(EXT_GET_UPDATE_DEPENDS(), GET_EXT_VERSION(EXT_GET_UPDATE_DEPENDS()), $dry_run);
519                                 } else {
520                                         // Register new extension
521                                         $test = REGISTER_EXTENSION(EXT_GET_UPDATE_DEPENDS(), 0, $dry_run, false);
522                                 }
523                         } // END - if
524
525                         // Add notes
526                         ADD_EXTENSION_NOTES($GLOBALS['cache_array']['update_ver'][EXT_GET_CURR_NAME()]);
527                 } // END - for
528
529                 // In real-mode execute any existing includes
530                 if (!$dry_run) {
531                         $GLOBALS['cache_array']['inc_pool'][EXT_GET_CURR_NAME()] = GET_INC_POOL();
532                         runFilterChain('load_includes');
533                         SET_INC_POOL($GLOBALS['cache_array']['inc_pool'][EXT_GET_CURR_NAME()]);
534                         unset($GLOBALS['cache_array']['inc_pool'][EXT_GET_CURR_NAME()]);
535                 } // END - if
536
537                 // Init these SQLs
538                 INIT_SQLS();
539                 SET_SQLS(GET_EXT_SQLS());
540
541                 // Run SQLs
542                 runFilterChain('run_sqls', array('dry_run' => $dry_run));
543
544                 if (!$dry_run) {
545                         // Create task
546                         CREATE_EXTENSION_UPDATE_TASK(GET_CURRENT_ADMIN_ID(), EXT_GET_CURR_NAME(), $GLOBALS['cache_array']['update_ver'][EXT_GET_CURR_NAME()], SQL_ESCAPE(EXT_GET_NOTES(EXT_GET_NOTES())));
547
548                         // Update extension's version
549                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
550                                 array($GLOBALS['cache_array']['update_ver'][EXT_GET_CURR_NAME()], EXT_GET_CURR_NAME()), __FILE__, __LINE__);
551
552                         // Remove arrays
553                         UNSET_SQLS();
554                         unset($GLOBALS['cache_array']['update_ver'][EXT_GET_CURR_NAME()]);
555
556                         // Run filters on success extension update
557                         runFilterChain('extension_update', EXT_GET_CURR_NAME());
558                 } // END - if
559         } // END - if
560 }
561
562 // Output verbose SQL table for extension
563 function EXTENSION_VERBOSE_TABLE ($queries = array(), $title = "", $dashed = "", $switch = false, $width = "100%") {
564         // Empty title?
565         if (empty($title)) {
566                 // Then fix it to default
567                 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
568         } // END - if
569
570         // Are there some queries in $queries?
571         if (count($queries) > 0) {
572                 // Then use them instead!
573                 SET_SQLS($queries);
574         } // END - if
575
576         // Init variables
577         $SW = 2; $i = 1;
578         $OUT = "";
579
580         // Do we have queries?
581         if ((IS_SQLS_VALID()) && (GET_EXT_VERSION("sql_patches") >= "0.0.7") && (getConfig('verbose_sql') == "Y")) {
582                 foreach (GET_SQLS() as $idx => $sql) {
583                         // Trim out spaces
584                         $sql = trim($sql);
585
586                         // Output command if set
587                         if (!empty($sql)) {
588                                 // Prepare output for template
589                                 $content = array(
590                                         'sw'  => $SW,
591                                         'i'   => $i,
592                                         'sql' => $sql
593                                 );
594
595                                 // Load row template
596                                 $OUT .= LOAD_TEMPLATE("admin_ext_sql_row", true, $content);
597
598                                 // Switch color and count up
599                                 $SW = 3 - $SW;
600                                 $i++;
601                         } // END - if
602                 } // END - foreach
603
604                 // Prepare content for template
605                 $content = array(
606                         'width'  => $width,
607                         'dashed' => $dashed,
608                         'title'  => $title,
609                         'out'    => $OUT
610                 );
611
612                 // Load main template
613                 $OUT = LOAD_TEMPLATE("admin_ext_sql_table", true, $content);
614         } elseif ((GET_EXT_VERSION("sql_patches") >= "0.0.7") && (getConfig('verbose_sql') == "Y")) {
615                 // No addional SQL commands to run
616                 $OUT = LOAD_TEMPLATE("admin_settings_saved", true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
617         } // END - if
618
619         // Return output
620         return $OUT;
621 }
622
623 // Get extension name from id
624 function GET_EXT_NAME ($ext_id) {
625         // Init extension name
626         $ret = "";
627
628         // Is cache there?
629         if (isset($GLOBALS['cache_array']['extensions']['ext_name'][$ext_id])) {
630                 // Load from cache
631                 $ret = $GLOBALS['cache_array']['extensions']['ext_name'][$ext_id];
632
633                 // Count cache hits
634                 incrementConfigEntry('cache_hits');
635         } elseif (!EXT_IS_ACTIVE("cache")) {
636                 // Load from database
637                 $result = SQL_QUERY_ESC("SELECT ext_name FROM `{!_MYSQL_PREFIX!}_extensions` WHERE id=%s LIMIT 1",
638                         array(bigintval($ext_id)), __FILE__, __LINE__);
639                 list($ret) = SQL_FETCHROW($result);
640                 SQL_FREERESULT($result);
641         }
642         return $ret;
643 }
644
645 // Get extension id from name
646 function GET_EXT_ID ($ext_name) {
647         // Init ID number
648         $ret = 0;
649         if (isset($GLOBALS['cache_array']['extensions']['ext_id'][$ext_name])) {
650                 // Load from cache
651                 $ret = $GLOBALS['cache_array']['extensions']['ext_id'][$ext_name];
652
653                 // Count cache hits
654                 incrementConfigEntry('cache_hits');
655         } elseif (!EXT_IS_ACTIVE("cache")) {
656                 // Load from database
657                 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
658                         array($ext_name), __FILE__, __LINE__);
659                 list($ret) = SQL_FETCHROW($result);
660                 SQL_FREERESULT($result);
661         }
662
663         // Return value
664         return $ret;
665 }
666
667 // Activate given extension
668 function ACTIVATE_EXTENSION ($ext_name) {
669         // Activate the extension
670         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='Y' WHERE ext_name='%s' LIMIT 1",
671                 array($ext_name), __FILE__, __LINE__);
672
673         // Extension has been activated?
674         if (SQL_AFFECTEDROWS() == 1) {
675                 // Then run all queries
676                 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "activate");
677         } // END - if
678 }
679
680 // Deactivate given extension
681 function DEACTIVATE_EXTENSION($ext_name) {
682         // Activate the extension
683         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='N' WHERE ext_name='%s' LIMIT 1",
684                 array($ext_name), __FILE__, __LINE__);
685
686         // Extension has been activated?
687         if (SQL_AFFECTEDROWS() == 1) {
688                 // Then run all queries
689                 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "deactivate");
690
691                 // Create new task
692                 CREATE_EXTENSION_DEACTIVATION_TASK($ext_name);
693
694                 // Notify the admin
695                 SEND_ADMIN_NOTIFICATION(
696                         getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
697                         "admin_ext_deactivated",
698                         array('ext_name' => $ext_name)
699                 );
700         } // END - if
701 }
702
703 // Checks wether the extension is older than given
704 function EXT_VERSION_IS_OLDER ($ext_name, $ext_ver) {
705         // Get current extension version
706         $currVersion = GET_EXT_VERSION($ext_name);
707
708         // Remove all dots from both versions
709         $currVersion = str_replace(".", "", $currVersion);
710         $ext_ver = str_replace(".", "", $ext_ver);
711
712         // Now compare both and return the result
713         return ($currVersion < $ext_ver);
714 }
715
716 // Creates a new task for updated extension
717 function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $ext_name, $ext_ver, $notes) {
718         // Create subject line
719         $subject = "[UPDATE-".$ext_name."-".$ext_ver.":] {--ADMIN_UPDATE_EXT_SUBJ--}";
720
721         // Is the extension there?
722         if (GET_EXT_VERSION($ext_name) != "") {
723                 // Check if task is not there
724                 if (DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) {
725                         // Task not created so it's a brand-new extension which we need to register and create a task for!
726                         SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s','0','NEW','EXTENSION_UPDATE','%s','%s', UNIX_TIMESTAMP())",
727                                 array($admin_id, $subject, $notes), __FILE__, __LINE__);
728                 } // END - if
729         } // END - if
730 }
731
732 // Creates a new task for newly installed extension
733 function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
734         // Not installed and do we have created a task for the admin?
735         if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) == "")) {
736                 // Template file
737                 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
738                         constant('PATH'),
739                         GET_LANGUAGE(),
740                         $ext
741                 );
742
743                 // Load text for task
744                 if (FILE_READABLE($tpl)) {
745                         // Load extension's own text template (HTML!)
746                         $msg = LOAD_TEMPLATE("ext_".$ext, true);
747                 } else {
748                         // Load default message
749                         $msg = LOAD_TEMPLATE("admin_new_ext", "", 0);
750                 }
751
752                 // Task not created so it's a brand-new extension which we need to register and create a task for!
753                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
754 VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
755                         array(
756                                 $admin_id,
757                                 $subject,
758                                 SQL_ESCAPE($msg),
759                         ),  __FILE__, __LINE__, true, false
760                 );
761         } // END - if
762 }
763
764 // Creates a task for automatically deactivated (deprecated) extension
765 function CREATE_EXTENSION_DEACTIVATION_TASK ($ext) {
766         // Create subject line
767         $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
768
769         // Not installed and do we have created a task for the admin?
770         if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) != "")) {
771                 // Task not created so add it
772                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
773 VALUES (0,0,'NEW','EXTENSION_DEACTIVATION','%s','%s',UNIX_TIMESTAMP())",
774                         array(
775                                 $subject,
776                                 SQL_ESCAPE(LOAD_TEMPLATE("task_ext_deactivated", true, $ext)),
777                         ),  __FILE__, __LINE__, true, false
778                 );
779         } // END - if
780 }
781
782 // Checks if the module has a menu
783 function MODULE_HAS_MENU ($mod, $forceDb = false) {
784         // All is false by default
785         $ret = false;
786
787         //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):mod={$mod},cache=".GET_EXT_VERSION("cache")."<br />\n";
788         if (GET_EXT_VERSION("cache") >= "0.1.2") {
789                 // Cache version is okay, so let's check the cache!
790                 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
791                         // Check module cache and count hit
792                         $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == "Y");
793                         incrementConfigEntry('cache_hits');
794                 } elseif (isset($GLOBALS['cache_array']['extensions']['ext_menu'][$mod])) {
795                         // Check cache and count hit
796                         $ret = ($GLOBALS['cache_array']['extensions']['ext_menu'][$mod] == "Y");
797                         incrementConfigEntry('cache_hits');
798                 } elseif ((IS_ADMIN()) && ($mod == "admin")) {
799                         // Admin module has always a menu!
800                         $ret = true;
801                 }
802         } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ((!EXT_IS_ACTIVE("cache")) || ($forceDb === true))) {
803                 // Check database for entry
804                 $result = SQL_QUERY_ESC("SELECT has_menu FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE module='%s' LIMIT 1",
805                         array($mod), __FILE__, __LINE__);
806
807                 // Entry found?
808                 if (SQL_NUMROWS($result) == 1) {
809                         // Load "has_menu" column
810                         list($has_menu) = SQL_FETCHROW($result);
811
812                         // Fake cache... ;-)
813                         $GLOBALS['cache_array']['extensions']['ext_menu'][$mod] = $has_menu;
814
815                         // Does it have a menu?
816                         $ret = ($has_menu == "Y");
817                 } // END  - if
818
819                 // Free memory
820                 SQL_FREERESULT($result);
821         } elseif (GET_EXT_VERSION("sql_patches") == "") {
822                 // No sql_patches installed, so maybe in admin area or no admin registered?
823                 $ret = (((IS_ADMIN()) || (!isAdminRegistered())) && ($mod == "admin")); // Then there is a menu!
824         }
825
826         // Return status
827         //* DEBUG: */ var_dump($ret);
828         return $ret;
829 }
830
831 // Determines the task id for given extension
832 function DETERMINE_EXTENSION_TASK_ID ($ext_name) {
833         // Default is not found
834         $task_id = 0;
835
836         // Search for extension task's id
837         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE task_type='EXTENSION' AND subject='[%s:]' LIMIT 1",
838                 array($ext_name), __FILE__, __LINE__);
839
840         // Entry found?
841         if (SQL_NUMROWS($result) == 1) {
842                 // Task found so load task's ID and register extension...
843                 list($task_id) = SQL_FETCHROW($result);
844         } // END - if
845
846         // Free result
847         SQL_FREERESULT($result);
848
849         // Return it
850         return $task_id;
851 }
852
853 // Determines the task id for given subject
854 function DETERMINE_TASK_ID_BY_SUBJECT ($subject) {
855         // Default is not found
856         $task_id = 0;
857
858         // Search for task id
859         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE subject LIKE '%s%%' LIMIT 1",
860                 array($subject), __FILE__, __LINE__);
861
862         // Entry found?
863         if (SQL_NUMROWS($result) == 1) {
864                 // Task found so load task's ID and register extension...
865                 list($task_id) = SQL_FETCHROW($result);
866         } // END - if
867
868         // Free result
869         SQL_FREERESULT($result);
870
871         // Return it
872         return $task_id;
873 }
874
875 // Add updates notes for given version
876 function ADD_EXTENSION_NOTES ($ver) {
877         // Init notes/content
878         $out = ""; $content = array();
879
880         // Is do we have verbose output enabled?
881         if ((getConfig('verbose_sql') == "Y") || (!EXT_IS_ACTIVE("sql_patches"))) {
882
883                 // Update notes found?
884                 if (EXT_GET_UPDATE_NOTES() != "") {
885                         // Update notes found
886                         $content = array(
887                                 'ver'   => $ver,
888                                 'notes' => EXT_GET_UPDATE_NOTES()
889                         );
890
891                         // Reset them
892                         EXT_SET_UPDATE_NOTES("");
893                 } elseif (($ver == "0.0") || ($ver == "0.0.0")) {
894                         // Initial release
895                         $content = array(
896                                 'ver'   => $ver,
897                                 'notes' => getMessage('INITIAL_RELEASE')
898                         );
899                 } else {
900                         // No update notes found!
901                         $content = array(
902                                 'ver'   => $ver,
903                                 'notes' => getMessage('NO_UPDATE_NOTES')
904                         );
905                 }
906
907                 // Load template
908                 $out = LOAD_TEMPLATE("admin_ext_notes", true, $content);
909         } // END - if
910
911         // Add the notes
912         EXT_APPEND_NOTES($out);
913 }
914
915 // Getter for CSS files array
916 function EXT_GET_CSS_FILES () {
917         // By default no additional CSS files are found
918         $cssFiles = array();
919
920         // Is the array there?
921         if (isset($GLOBALS['css_files'])) {
922                 // Then use it
923                 $cssFiles = $GLOBALS['css_files'];
924         } // END - if
925
926         // Return array
927         return $cssFiles;
928 }
929
930 // Init CSS files array
931 function EXT_INIT_CSS_FILES () {
932         // Simply init it
933         $GLOBALS['css_files'] = array();
934 }
935
936 // Add new entry
937 function EXT_ADD_CSS_FILE ($file) {
938         // Is the array there?
939         if (!isset($GLOBALS['css_files'])) {
940                 // Then auto-init them
941                 EXT_INIT_CSS_FILES();
942         } // END - if
943
944         // Add the entry
945         $GLOBALS['css_files'][] = $file;
946 }
947
948 // Setter for EXT_ALWAYS_ACTIVE flag
949 function EXT_SET_ALWAYS_ACTIVE ($active) {
950         $GLOBALS['ext_always_active'][EXT_GET_CURR_NAME()] = (string) $active;
951 }
952
953 // Getter for EXT_ALWAYS_ACTIVE flag
954 function EXT_GET_ALWAYS_ACTIVE () {
955         return $GLOBALS['ext_always_active'][EXT_GET_CURR_NAME()];
956 }
957
958 // Setter for EXT_VERSION flag
959 function EXT_SET_VERSION ($version) {
960         $GLOBALS['ext_version'][EXT_GET_CURR_NAME()] = (float) $version;
961 }
962
963 // Getter for EXT_VERSION flag
964 function EXT_GET_VERSION () {
965         return $GLOBALS['ext_version'][EXT_GET_CURR_NAME()];
966 }
967
968 // Setter for EXT_DEPRECATED flag
969 function EXT_SET_DEPRECATED ($deprecated) {
970         $GLOBALS['ext_deprecated'][EXT_GET_CURR_NAME()] = (string) $deprecated;
971 }
972
973 // Getter for EXT_DEPRECATED flag
974 function EXT_GET_DEPRECATED () {
975         return $GLOBALS['ext_deprecated'][EXT_GET_CURR_NAME()];
976 }
977
978 // Setter for EXT_UPDATE_DEPENDS flag
979 function EXT_ADD_UPDATE_DEPENDS ($updateDepends) {
980         // Is the update depency empty? (NEED TO BE FIXED!)
981         if (empty($updateDepends)) {
982                 // Please report this bug!
983                 debug_report_bug("updateDepends is left empty!");
984         } // END - if
985
986         // Is it not yet added?
987         if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
988                 //* DEBUG */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."/".$updateDepends."<br />\n";
989                 // Add it to the list of extension update depencies map
990                 $GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()][] = (string) $updateDepends;
991
992                 // Remember it in the list of running updates
993                 $GLOBALS['ext_running_updates'][] = $updateDepends;
994         } // END - if
995 }
996
997 // Init EXT_UPDATE_DEPENDS flag
998 function EXT_INIT_UPDATE_DEPENDS () {
999         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1000
1001         // Init update depency map
1002         $GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()] = array();
1003
1004         // Init running updates array
1005         EXT_INIT_RUNNING_UPDATES();
1006 }
1007
1008 // Initializes the list of running updates
1009 function EXT_INIT_RUNNING_UPDATES () {
1010         // Auto-init ext_running_updates
1011         if (!isset($GLOBALS['ext_running_updates'])) {
1012                 $GLOBALS['ext_running_updates'] = array();
1013         } // END - if
1014 }
1015
1016 // Getter for EXT_UPDATE_DEPENDS flag
1017 function EXT_GET_UPDATE_DEPENDS () {
1018         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1019         return $GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()];
1020 }
1021
1022 // Getter for next iterator depency
1023 function EXT_GET_ITERATOR_UPDATE_DEPENDS () {
1024         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1025         return ($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()][EXT_GET_UPDATE_ITERATOR()]);
1026 }
1027
1028 // Counter for extension update depencies
1029 function EXT_COUNT_UPDATE_DEPENDS () {
1030         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1031         return count($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()]);
1032 }
1033
1034 // Removes given extension from update denpency list
1035 function EXT_REMOVE_UPDATE_DEPENDS ($ext_name) {
1036         // Look it up
1037         $key = array_search($ext_name, EXT_GET_UPDATE_DEPENDS());
1038
1039         // Is it valid?
1040         if ($key !== false) {
1041                 // Then remove it
1042                 unset($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()][$key]);
1043
1044                 // And sort the array
1045                 ksort($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()]);
1046         } // END - if
1047 }
1048
1049 // Init iterator for update depencies
1050 function EXT_INIT_UPDATE_ITERATOR () {
1051         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1052         $GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()] = 0;
1053 }
1054
1055 // Getter for depency iterator
1056 function EXT_GET_UPDATE_ITERATOR () {
1057         // Auto-init iterator
1058         if (!isset($GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()])) EXT_INIT_UPDATE_ITERATOR();
1059
1060         // Return it
1061         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."/".$GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()]."<br />\n";
1062         return $GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()];
1063 }
1064
1065 // Increments the update iterator
1066 function EXT_INCREMENT_UPDATE_INTERATOR () {
1067         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1068         $GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()]++;
1069 }
1070
1071 // Setter for EXT_REPORTS_FAILURE flag
1072 function EXT_SET_REPORTS_FAILURE ($reportsFailure) {
1073         $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1074 }
1075
1076 // Getter for EXT_REPORTS_FAILURE flag
1077 function EXT_GET_REPORTS_FAILURE () {
1078         return $GLOBALS['ext_reports_failure'];
1079 }
1080
1081 // Setter for EXT_VER_HISTORY flag
1082 function EXT_SET_VER_HISTORY ($verHistory) {
1083         $GLOBALS['ext_ver_history'] = (array) $verHistory;
1084 }
1085
1086 // Getter for EXT_VER_HISTORY array
1087 function EXT_GET_VER_HISTORY () {
1088         return $GLOBALS['ext_ver_history'];
1089 }
1090
1091 // Setter for EXT_UPDATE_NOTES flag
1092 function EXT_SET_UPDATE_NOTES ($updateNotes) {
1093         $GLOBALS['ext_update_notes'] = (string) $updateNotes;
1094 }
1095
1096 // Getter for EXT_UPDATE_NOTES flag
1097 function EXT_GET_UPDATE_NOTES () {
1098         return $GLOBALS['ext_update_notes'];
1099 }
1100
1101 // Init extension notice
1102 function EXT_INIT_NOTES () {
1103         $GLOBALS['ext_notes'] = "";
1104 }
1105
1106 // Append extension notice
1107 function EXT_APPEND_NOTES ($notes) {
1108         $GLOBALS['ext_notes'] .= (string) $notes;
1109 }
1110
1111 // Getter for extension notes
1112 function EXT_GET_NOTES () {
1113         return $GLOBALS['ext_notes'];
1114 }
1115
1116 // Setter for current extension name
1117 function EXT_SET_CURR_NAME ($ext_name) {
1118         $GLOBALS['curr_ext_name'] = (string) $ext_name;
1119 }
1120
1121 // Getter for current extension name
1122 function EXT_GET_CURR_NAME () {
1123         if (isset($GLOBALS['curr_ext_name'])) {
1124                 return $GLOBALS['curr_ext_name'];
1125         } // END - if
1126
1127         // Not set!
1128         debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute INIT_EXT_SQLS() before calling this function.");
1129 }
1130
1131 // Init SQLs array for current extension
1132 function INIT_EXT_SQLS () {
1133         // Auto-init the array now...
1134         if (!isset($GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()])) {
1135                 $GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()] = array();
1136         } // END - if
1137 }
1138
1139 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1140 function ADD_EXT_SQL ($sql) {
1141         $GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()][] = $sql;
1142 }
1143
1144 // Getter for SQLs array for current extension
1145 function GET_EXT_SQLS () {
1146         // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1147         if (!isset($GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()])) {
1148                 // Not found, should not happen
1149                 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1150                         EXT_GET_CURR_NAME()
1151                 ));
1152         } // END - if
1153
1154         // Return the array
1155         return $GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()];
1156 }
1157
1158 // Removes SQLs for current extension
1159 function UNSET_EXT_SQLS () {
1160         unset($GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()]);
1161 }
1162
1163 // Auto-initializes the removal list
1164 function EXT_INIT_REMOVAL_LIST () {
1165         // Is the remove list there?
1166         if (!isset($GLOBALS['ext_update_remove'])) {
1167                 // Then create it
1168                 $GLOBALS['ext_update_remove'] = array();
1169         } // END - if
1170 }
1171
1172 // Checks wether the current extension is on the removal list
1173 function EXT_IS_ON_REMOVAL_LIST () {
1174         // Init removal list
1175         EXT_INIT_REMOVAL_LIST();
1176
1177         // Is it there?
1178         return (in_array(EXT_GET_CURR_NAME(), $GLOBALS['ext_update_remove']));
1179 }
1180
1181 // Adds the current extension to the removal list
1182 function EXT_ADD_CURRENT_TO_REMOVAL_LIST () {
1183         // Simply add it
1184         $GLOBALS['ext_update_remove'][] = EXT_GET_CURR_NAME();
1185 }
1186
1187 // Getter for removal list
1188 function EXT_GET_REMOVAL_LIST () {
1189         // Return the removal list
1190         return $GLOBALS['ext_update_remove'];
1191 }
1192
1193 //
1194 ?>