Several rewrites/fixes which I have done yesterday but not commited, mxchange_die...
[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()), __FUNCTION__, __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)), __FUNCTION__, __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()), __FUNCTION__, __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                 app_die(__FUNCTION__, __LINE__, "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), __FUNCTION__, __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), __FUNCTION__, __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()), __FUNCTION__, __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)), __FUNCTION__, __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), __FUNCTION__, __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), __FUNCTION__, __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), __FUNCTION__, __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), __FUNCTION__, __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                 // Set default message if ext-foo is missing
744                 $msg = sprintf(getMessage('ADMIN_EXT_TEXT_FILE_MISSING'), $ext);
745
746                 // Load text for task if found
747                 if (FILE_READABLE($tpl)) {
748                         // Load extension's own text template (HTML!)
749                         $msg = LOAD_TEMPLATE("ext_".$ext, true);
750                 } else {
751                         // Write this in debug.log as well
752                         DEBUG_LOG(__FUNCTION__, __LINE__, $msg);
753                 }
754
755                 // Task not created so it's a brand-new extension which we need to register and create a task for!
756                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
757 VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
758                         array(
759                                 $admin_id,
760                                 $subject,
761                                 SQL_ESCAPE($msg),
762                         ),  __FUNCTION__, __LINE__, true, false
763                 );
764         } // END - if
765 }
766
767 // Creates a task for automatically deactivated (deprecated) extension
768 function CREATE_EXTENSION_DEACTIVATION_TASK ($ext) {
769         // Create subject line
770         $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
771
772         // Not installed and do we have created a task for the admin?
773         if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) != "")) {
774                 // Task not created so add it
775                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
776 VALUES (0,0,'NEW','EXTENSION_DEACTIVATION','%s','%s',UNIX_TIMESTAMP())",
777                         array(
778                                 $subject,
779                                 SQL_ESCAPE(LOAD_TEMPLATE("task_ext_deactivated", true, $ext)),
780                         ),  __FUNCTION__, __LINE__, true, false
781                 );
782         } // END - if
783 }
784
785 // Checks if the module has a menu
786 function MODULE_HAS_MENU ($mod, $forceDb = false) {
787         // All is false by default
788         $ret = false;
789
790         //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):mod={$mod},cache=".GET_EXT_VERSION("cache")."<br />\n";
791         if (GET_EXT_VERSION("cache") >= "0.1.2") {
792                 // Cache version is okay, so let's check the cache!
793                 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
794                         // Check module cache and count hit
795                         $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == "Y");
796                         incrementConfigEntry('cache_hits');
797                 } elseif (isset($GLOBALS['cache_array']['extensions']['ext_menu'][$mod])) {
798                         // Check cache and count hit
799                         $ret = ($GLOBALS['cache_array']['extensions']['ext_menu'][$mod] == "Y");
800                         incrementConfigEntry('cache_hits');
801                 } elseif ((IS_ADMIN()) && ($mod == "admin")) {
802                         // Admin module has always a menu!
803                         $ret = true;
804                 }
805         } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ((!EXT_IS_ACTIVE("cache")) || ($forceDb === true))) {
806                 // Check database for entry
807                 $result = SQL_QUERY_ESC("SELECT has_menu FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE `module`='%s' LIMIT 1",
808                         array($mod), __FUNCTION__, __LINE__);
809
810                 // Entry found?
811                 if (SQL_NUMROWS($result) == 1) {
812                         // Load "has_menu" column
813                         list($has_menu) = SQL_FETCHROW($result);
814
815                         // Fake cache... ;-)
816                         $GLOBALS['cache_array']['extensions']['ext_menu'][$mod] = $has_menu;
817
818                         // Does it have a menu?
819                         $ret = ($has_menu == "Y");
820                 } // END  - if
821
822                 // Free memory
823                 SQL_FREERESULT($result);
824         } elseif (GET_EXT_VERSION("sql_patches") == "") {
825                 // No sql_patches installed, so maybe in admin area or no admin registered?
826                 $ret = (((IS_ADMIN()) || (!isAdminRegistered())) && ($mod == "admin")); // Then there is a menu!
827         }
828
829         // Return status
830         //* DEBUG: */ var_dump($ret);
831         return $ret;
832 }
833
834 // Determines the task id for given extension
835 function DETERMINE_EXTENSION_TASK_ID ($ext_name) {
836         // Default is not found
837         $task_id = 0;
838
839         // Search for extension task's id
840         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE task_type='EXTENSION' AND subject='[%s:]' LIMIT 1",
841                 array($ext_name), __FUNCTION__, __LINE__);
842
843         // Entry found?
844         if (SQL_NUMROWS($result) == 1) {
845                 // Task found so load task's ID and register extension...
846                 list($task_id) = SQL_FETCHROW($result);
847         } // END - if
848
849         // Free result
850         SQL_FREERESULT($result);
851
852         // Return it
853         return $task_id;
854 }
855
856 // Determines the task id for given subject
857 function DETERMINE_TASK_ID_BY_SUBJECT ($subject) {
858         // Default is not found
859         $task_id = 0;
860
861         // Search for task id
862         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE subject LIKE '%s%%' LIMIT 1",
863                 array($subject), __FUNCTION__, __LINE__);
864
865         // Entry found?
866         if (SQL_NUMROWS($result) == 1) {
867                 // Task found so load task's ID and register extension...
868                 list($task_id) = SQL_FETCHROW($result);
869         } // END - if
870
871         // Free result
872         SQL_FREERESULT($result);
873
874         // Return it
875         return $task_id;
876 }
877
878 // Add updates notes for given version
879 function ADD_EXTENSION_NOTES ($ver) {
880         // Init notes/content
881         $out = ""; $content = array();
882
883         // Is do we have verbose output enabled?
884         if ((getConfig('verbose_sql') == "Y") || (!EXT_IS_ACTIVE("sql_patches"))) {
885
886                 // Update notes found?
887                 if (EXT_GET_UPDATE_NOTES() != "") {
888                         // Update notes found
889                         $content = array(
890                                 'ver'   => $ver,
891                                 'notes' => EXT_GET_UPDATE_NOTES()
892                         );
893
894                         // Reset them
895                         EXT_SET_UPDATE_NOTES("");
896                 } elseif (($ver == "0.0") || ($ver == "0.0.0")) {
897                         // Initial release
898                         $content = array(
899                                 'ver'   => $ver,
900                                 'notes' => getMessage('INITIAL_RELEASE')
901                         );
902                 } else {
903                         // No update notes found!
904                         $content = array(
905                                 'ver'   => $ver,
906                                 'notes' => getMessage('NO_UPDATE_NOTES')
907                         );
908                 }
909
910                 // Load template
911                 $out = LOAD_TEMPLATE("admin_ext_notes", true, $content);
912         } // END - if
913
914         // Add the notes
915         EXT_APPEND_NOTES($out);
916 }
917
918 // Getter for CSS files array
919 function EXT_GET_CSS_FILES () {
920         // By default no additional CSS files are found
921         $cssFiles = array();
922
923         // Is the array there?
924         if (isset($GLOBALS['css_files'])) {
925                 // Then use it
926                 $cssFiles = $GLOBALS['css_files'];
927         } // END - if
928
929         // Return array
930         return $cssFiles;
931 }
932
933 // Init CSS files array
934 function EXT_INIT_CSS_FILES () {
935         // Simply init it
936         $GLOBALS['css_files'] = array();
937 }
938
939 // Add new entry
940 function EXT_ADD_CSS_FILE ($file) {
941         // Is the array there?
942         if (!isset($GLOBALS['css_files'])) {
943                 // Then auto-init them
944                 EXT_INIT_CSS_FILES();
945         } // END - if
946
947         // Add the entry
948         $GLOBALS['css_files'][] = $file;
949 }
950
951 // Setter for EXT_ALWAYS_ACTIVE flag
952 function EXT_SET_ALWAYS_ACTIVE ($active) {
953         $GLOBALS['ext_always_active'][EXT_GET_CURR_NAME()] = (string) $active;
954 }
955
956 // Getter for EXT_ALWAYS_ACTIVE flag
957 function EXT_GET_ALWAYS_ACTIVE () {
958         return $GLOBALS['ext_always_active'][EXT_GET_CURR_NAME()];
959 }
960
961 // Setter for EXT_VERSION flag
962 function EXT_SET_VERSION ($version) {
963         $GLOBALS['ext_version'][EXT_GET_CURR_NAME()] = (float) $version;
964 }
965
966 // Getter for EXT_VERSION flag
967 function EXT_GET_VERSION () {
968         return $GLOBALS['ext_version'][EXT_GET_CURR_NAME()];
969 }
970
971 // Setter for EXT_DEPRECATED flag
972 function EXT_SET_DEPRECATED ($deprecated) {
973         $GLOBALS['ext_deprecated'][EXT_GET_CURR_NAME()] = (string) $deprecated;
974 }
975
976 // Getter for EXT_DEPRECATED flag
977 function EXT_GET_DEPRECATED () {
978         return $GLOBALS['ext_deprecated'][EXT_GET_CURR_NAME()];
979 }
980
981 // Setter for EXT_UPDATE_DEPENDS flag
982 function EXT_ADD_UPDATE_DEPENDS ($updateDepends) {
983         // Is the update depency empty? (NEED TO BE FIXED!)
984         if (empty($updateDepends)) {
985                 // Please report this bug!
986                 debug_report_bug("updateDepends is left empty!");
987         } // END - if
988
989         // Is it not yet added?
990         if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
991                 //* DEBUG */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."/".$updateDepends."<br />\n";
992                 // Add it to the list of extension update depencies map
993                 $GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()][] = (string) $updateDepends;
994
995                 // Remember it in the list of running updates
996                 $GLOBALS['ext_running_updates'][] = $updateDepends;
997         } // END - if
998 }
999
1000 // Init EXT_UPDATE_DEPENDS flag
1001 function EXT_INIT_UPDATE_DEPENDS () {
1002         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1003
1004         // Init update depency map
1005         $GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()] = array();
1006
1007         // Init running updates array
1008         EXT_INIT_RUNNING_UPDATES();
1009 }
1010
1011 // Initializes the list of running updates
1012 function EXT_INIT_RUNNING_UPDATES () {
1013         // Auto-init ext_running_updates
1014         if (!isset($GLOBALS['ext_running_updates'])) {
1015                 $GLOBALS['ext_running_updates'] = array();
1016         } // END - if
1017 }
1018
1019 // Getter for EXT_UPDATE_DEPENDS flag
1020 function EXT_GET_UPDATE_DEPENDS () {
1021         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1022         return $GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()];
1023 }
1024
1025 // Getter for next iterator depency
1026 function EXT_GET_ITERATOR_UPDATE_DEPENDS () {
1027         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1028         return ($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()][EXT_GET_UPDATE_ITERATOR()]);
1029 }
1030
1031 // Counter for extension update depencies
1032 function EXT_COUNT_UPDATE_DEPENDS () {
1033         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1034         return count($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()]);
1035 }
1036
1037 // Removes given extension from update denpency list
1038 function EXT_REMOVE_UPDATE_DEPENDS ($ext_name) {
1039         // Look it up
1040         $key = array_search($ext_name, EXT_GET_UPDATE_DEPENDS());
1041
1042         // Is it valid?
1043         if ($key !== false) {
1044                 // Then remove it
1045                 unset($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()][$key]);
1046
1047                 // And sort the array
1048                 ksort($GLOBALS['ext_update_depends'][EXT_GET_CURR_NAME()]);
1049         } // END - if
1050 }
1051
1052 // Init iterator for update depencies
1053 function EXT_INIT_UPDATE_ITERATOR () {
1054         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1055         $GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()] = 0;
1056 }
1057
1058 // Getter for depency iterator
1059 function EXT_GET_UPDATE_ITERATOR () {
1060         // Auto-init iterator
1061         if (!isset($GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()])) EXT_INIT_UPDATE_ITERATOR();
1062
1063         // Return it
1064         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."/".$GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()]."<br />\n";
1065         return $GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()];
1066 }
1067
1068 // Increments the update iterator
1069 function EXT_INCREMENT_UPDATE_INTERATOR () {
1070         //* DEBUG: */ print __FUNCTION__.":".EXT_GET_CURR_NAME()."<br />\n";
1071         $GLOBALS['ext_depend_iterator'][EXT_GET_CURR_NAME()]++;
1072 }
1073
1074 // Setter for EXT_REPORTS_FAILURE flag
1075 function EXT_SET_REPORTS_FAILURE ($reportsFailure) {
1076         $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1077 }
1078
1079 // Getter for EXT_REPORTS_FAILURE flag
1080 function EXT_GET_REPORTS_FAILURE () {
1081         return $GLOBALS['ext_reports_failure'];
1082 }
1083
1084 // Setter for EXT_VER_HISTORY flag
1085 function EXT_SET_VER_HISTORY ($verHistory) {
1086         $GLOBALS['ext_ver_history'] = (array) $verHistory;
1087 }
1088
1089 // Getter for EXT_VER_HISTORY array
1090 function EXT_GET_VER_HISTORY () {
1091         return $GLOBALS['ext_ver_history'];
1092 }
1093
1094 // Setter for EXT_UPDATE_NOTES flag
1095 function EXT_SET_UPDATE_NOTES ($updateNotes) {
1096         $GLOBALS['ext_update_notes'] = (string) $updateNotes;
1097 }
1098
1099 // Getter for EXT_UPDATE_NOTES flag
1100 function EXT_GET_UPDATE_NOTES () {
1101         return $GLOBALS['ext_update_notes'];
1102 }
1103
1104 // Init extension notice
1105 function EXT_INIT_NOTES () {
1106         $GLOBALS['ext_notes'] = "";
1107 }
1108
1109 // Append extension notice
1110 function EXT_APPEND_NOTES ($notes) {
1111         $GLOBALS['ext_notes'] .= (string) $notes;
1112 }
1113
1114 // Getter for extension notes
1115 function EXT_GET_NOTES () {
1116         return $GLOBALS['ext_notes'];
1117 }
1118
1119 // Setter for current extension name
1120 function EXT_SET_CURR_NAME ($ext_name) {
1121         $GLOBALS['curr_ext_name'] = (string) $ext_name;
1122 }
1123
1124 // Getter for current extension name
1125 function EXT_GET_CURR_NAME () {
1126         if (isset($GLOBALS['curr_ext_name'])) {
1127                 return $GLOBALS['curr_ext_name'];
1128         } // END - if
1129
1130         // Not set!
1131         debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute INIT_EXT_SQLS() before calling this function.");
1132 }
1133
1134 // Init SQLs array for current extension
1135 function INIT_EXT_SQLS () {
1136         // Auto-init the array now...
1137         if (!isset($GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()])) {
1138                 $GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()] = array();
1139         } // END - if
1140 }
1141
1142 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1143 function ADD_EXT_SQL ($sql) {
1144         $GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()][] = $sql;
1145 }
1146
1147 // Getter for SQLs array for current extension
1148 function GET_EXT_SQLS () {
1149         // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1150         if (!isset($GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()])) {
1151                 // Not found, should not happen
1152                 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1153                         EXT_GET_CURR_NAME()
1154                 ));
1155         } // END - if
1156
1157         // Return the array
1158         return $GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()];
1159 }
1160
1161 // Removes SQLs for current extension
1162 function UNSET_EXT_SQLS () {
1163         unset($GLOBALS['ext_sqls'][EXT_GET_CURR_NAME()]);
1164 }
1165
1166 // Auto-initializes the removal list
1167 function EXT_INIT_REMOVAL_LIST () {
1168         // Is the remove list there?
1169         if (!isset($GLOBALS['ext_update_remove'])) {
1170                 // Then create it
1171                 $GLOBALS['ext_update_remove'] = array();
1172         } // END - if
1173 }
1174
1175 // Checks wether the current extension is on the removal list
1176 function EXT_IS_ON_REMOVAL_LIST () {
1177         // Init removal list
1178         EXT_INIT_REMOVAL_LIST();
1179
1180         // Is it there?
1181         return (in_array(EXT_GET_CURR_NAME(), $GLOBALS['ext_update_remove']));
1182 }
1183
1184 // Adds the current extension to the removal list
1185 function EXT_ADD_CURRENT_TO_REMOVAL_LIST () {
1186         // Simply add it
1187         $GLOBALS['ext_update_remove'][] = EXT_GET_CURR_NAME();
1188 }
1189
1190 // Getter for removal list
1191 function EXT_GET_REMOVAL_LIST () {
1192         // Return the removal list
1193         return $GLOBALS['ext_update_remove'];
1194 }
1195
1196 //
1197 ?>