Fixes for db/cache counter
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 //
41 function EXTENSION_REGISTER ($ext_name, $id, $dry_run=false)
42 {
43         global $NOTES, $_CONFIG, $INC_POOL, $cacheInstance;
44         // We want to register an extension and registration status is by default "failed" (= false)
45         $EXT_LOAD_MODE = "register"; $ret = false; $SQLs = array();
46         $INC_POOL = array();
47
48         // This shall never do a non-admin user!
49         if (!IS_ADMIN()) return false;
50
51         // Is this extension already installed?
52         if (EXT_IS_ACTIVE($ext_name)) return false;
53
54         // Generate file name
55         $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
56
57         // Does this extension exists?
58         if (file_exists($file) && is_readable($file))
59         {
60                 // Extension was found so we can load it in registration mode
61                 require($file);
62
63                 // And run possible updates
64                 $EXT_LOAD_MODE = "update"; $EXT_UPDATE_DEPENDS = "";
65                 foreach ($EXT_VER_HISTORY as $EXT_VER)
66                 {
67                         require($file);
68                         if (((GET_EXT_VERSION("sql_patches") != '') && ($_CONFIG['verbose_sql'] == "Y")) || (!EXT_IS_ACTIVE("sql_patches")))
69                         {
70                                 if (!empty($UPDATE_NOTES))
71                                 {
72                                         // Update notes found
73                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".$UPDATE_NOTES."<br /><br />\n";
74                                         $UPDATE_NOTES = "";
75                                 }
76                                  elseif (($EXT_VER == "0.0") || ($EXT_VER == "0.0.0"))
77                                 {
78                                         // Initial release
79                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".INITIAL_RELEASE."<br /><br />\n";
80                                 }
81                                  else
82                                 {
83                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br /><I>".NO_UPDATE_NOTES."</I><br /><br />\n";
84                                 }
85                         }
86                 }
87
88                 // Does this extension depends on an outstanding update of another update?
89                 if (!empty($EXT_UPDATE_DEPENDS))
90                 {
91                         // Backup SQL commands and clear current
92                         $SQLs2 = $SQLs;  $SQLs = array(); $test = false;
93
94                         // Backup language as well
95                         $LANG_BCK = $EXT_LANG_PREFIX; $EXT_ALWAYS_ACTIVE = "N";
96
97                         // Load required extension also in update mode
98                         $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $EXT_UPDATE_DEPENDS);
99
100                         // Check for required file
101                         if (file_exists($file) && is_readable($file))
102                         {
103                                 // File exists so let's load it
104                                 $VER_BACKUP = $EXT_VERSION;
105                                 require($file);
106                                 $EXT_VERSION = $VER_BACKUP;
107
108                                 // If versions mismatch update extension first
109                                 $ext_ver = GET_EXT_VERSION($EXT_UPDATE_DEPENDS);
110                                 if (empty($ext_ver))
111                                 {
112                                         // Extension not registered so far so first load task's ID...
113                                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE task_type='EXTENSION' AND subject LIKE '[%s:]%%' LIMIT 1",
114                                          array($EXT_UPDATE_DEPENDS), __FILE__, __LINE__);
115                                         if (SQL_NUMROWS($result) == 1)
116                                         {
117                                                 // Task found so load task's ID and register extension...
118                                                 list($task) = SQL_FETCHROW($result);
119                                                 SQL_FREERESULT($result);
120                                                 $test = EXTENSION_REGISTER($EXT_UPDATE_DEPENDS, $task, $dry_run);
121                                         }
122                                 }
123                                  elseif ($ext_ver != $EXT_VERSION)
124                                 {
125                                         // Ok, update this extension now
126                                         EXTENSION_UPDATE(basename($file), $EXT_UPDATE_DEPENDS, $ext_ver, $dry_run);
127
128                                         // All okay!
129                                         $test = true;
130                                 }
131                                  else
132                                 {
133                                         // Nothing to register / update before...
134                                         $test = true;
135                                 }
136                         }
137                          else
138                         {
139                                 // Required file for update does not exists!
140                                 $test = true;
141                                 // But this is fine for the first time...
142                         }
143
144                         // Finally restore previous SQLs
145                         $SQLs = $SQLs2; unset($SQLs2);
146                         $EXT_LANG_PREFIX = $LANG_BCK;
147                 }
148                  else
149                 {
150                         // Does not depend on an other extension
151                         $test = true;
152                 }
153
154                 // Switch back to register mode
155                 $EXT_LOAD_MODE = "register";
156
157                 // Does everthing before wents ok?
158                 if ($test) {
159                         // "Dry-run-mode" activated?
160                         if (!$dry_run) {
161                                 // Run all SQLs
162                                 foreach ($SQLs as $sql) {
163                                         // Trim spaces away which we don't need
164                                         $sql = trim($sql);
165
166                                         // Is there still an SQL query?
167                                         if (!empty($sql)) {
168                                                 // Do we have an "ALTER TABLE" command?
169                                                 if (substr(strtolower($sql), 0, 11) == "alter table") {
170                                                         // Analyse the alteration command
171                                                         SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
172                                                 } else {
173                                                         // Run regular SQL command
174                                                         $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
175                                                 }
176                                         } // END - if
177                                 } // END - foreach
178
179                                 // Remove cache file(s) if extension is active
180                                 if ((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) {
181                                         //* DEBUG: */ echo __LINE__.": DESTROY!<br />\n";
182                                         // Remove cache files
183                                         if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy();
184                                         if ($cacheInstance->cache_file("mod_reg", true))    $cacheInstance->cache_destroy();
185                                         if ($cacheInstance->cache_file("config", true))     $cacheInstance->cache_destroy();
186                                 } // END - if
187
188                                 // Check for added include files
189                                 if (count($INC_POOL > 0)) {
190                                         // Loads every include file
191                                         foreach ($INC_POOL as $inc) {
192                                                 require_once($inc);
193                                         } // END - foreach
194                                 }
195
196                                 // Register extension
197                                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_extensions (ext_name, ext_lang_file, ext_active, ext_version) VALUES ('%s', '%s', '%s', '%s')",
198                                  array($ext_name, $EXT_LANG_PREFIX, $EXT_ALWAYS_ACTIVE, $EXT_VERSION), __FILE__, __LINE__);
199
200                                 // Update task management
201                                 ADMIN_SOLVE_TASK($id);
202
203                                 // In normal mode return a true on success
204                                 $ret = true; unset($SQLs);
205                         } else {
206                                 // Rewrite SQL command to keep { and } inside
207                                 foreach ($SQLs as $key => $sql) {
208                                         $sql = str_replace('{', "&#123;", str_replace('}', "&#125;", $sql));
209                                         $SQLs[$key] = $sql;
210                                 } // END - foreach
211
212                                 // In  "dry-run" mode return array with all SQL commands
213                                 $ret = $SQLs;
214
215                                 // Remove all SQL commands
216                                 unset($SQLs);
217                         }
218                 } else {
219                         // No, an error occurs while registering extension :-(
220                         $ret = false;
221                 }
222         } elseif (($id > 0) && (!empty($ext_name))) {
223                 // Remove task from system when id and extension's name is valid
224                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%s AND status='NEW' LIMIT 1",
225                  array(bigintval($id)), __FILE__, __LINE__);
226         }
227
228         // Is this the sql_patches?
229         //* DEBUG: */ echo __LINE__.":{$ext_name}/{$EXT_LOAD_MODE}<br />\n";
230         if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove")) && (!$dry_run) && ($test)) {
231                 // Then redirect to logout
232                 //* DEBUG: */ echo __LINE__.": LOAD!<br />\n";
233                 LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
234         } // END - if
235
236         // Return status code
237         return $ret;
238 }
239 //
240 function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) {
241         global $cacheInstance;
242         $SQLs = array();
243
244         // By default no SQL has been executed
245         $sqlRan = false;
246
247         // This shall never do a non-admin user!
248         if (!IS_ADMIN()) return false;
249
250         // Get extension's name
251         $ext_name = GET_EXT_NAME($id);
252         if (empty($ext_name)) return false;
253
254         // Load extension in detected mode
255         //* DEBUG: */ echo __FUNCTION__.":ext_name[{$id}]={$ext_name}<br />\n";
256         $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
257         if (file_exists($file) && is_readable($file)) require($file);
258
259         //* DEBUG: */ echo __FUNCTION__.":SQLs::count=".count($SQLs)."<br />\n";
260         if ((is_array($SQLs) && (sizeof($SQLs) > 0))) {
261                 // Run SQL commands...
262                 foreach ($SQLs as $sql) {
263                         // Trim spaces away which we don't need
264                         $sql = trim($sql);
265
266                         // Is there still an SQL query?
267                         if (!empty($sql)) {
268                                 // Do we have an "ALTER TABLE" command?
269                                 //* DEBUG: */ echo __FUNCTION__.":SQL={$SQL}<br />\n";
270                                 if (substr(strtolower($sql), 0, 11) == "alter table") {
271                                         // Analyse the alteration command
272                                         SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
273                                 } else {
274                                         // Run regular SQL command
275                                         $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
276                                 }
277
278                                 // An SQL has been executed
279                                 $sqlRan = true;
280                         } // END - if
281                 } // END - foreach
282
283                 // Removal mode?
284                 if ($EXT_LOAD_MODE == "remove") {
285                         // Delete this extension (remember to remove it from your server *before* you click on welcome!
286                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
287                          array($id), __FILE__, __LINE__);
288                 } // END - if
289
290                 //* DEBUG: */ echo __FUNCTION__.":mode={$EXT_LOAD_MODE}<br />\n";
291
292                 // Remove cache file(s) if extension is active
293                 if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1) && ($EXT_LOAD_MODE == "remove")) || ($sqlRan === true))) {
294                         //* DEBUG: */ echo __LINE__.": DESTROY!<br />\n";
295                         // Remove cache files
296                         if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy();
297                         if ($cacheInstance->cache_file("mod_reg", true))    $cacheInstance->cache_destroy();
298                         if ($cacheInstance->cache_file("config", true))     $cacheInstance->cache_destroy();
299                 } // END - if
300
301                 // Is this the sql_patches?
302                 //* DEBUG: */ echo __LINE__.": {$id}/{$ext_name}/{$EXT_LOAD_MODE}<br />\n";
303                 if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove"))) {
304                         // Then redirect to logout
305                         //* DEBUG: */ echo __LINE__.": LOAD!<br />\n";
306                         LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
307                 } // END - if
308         } // END - if
309 }
310 // Check if given extension is active
311 function EXT_IS_ACTIVE ($ext_name, $ignore_admin = false, $ignore_cache = false) {
312         global $cacheArray, $_CONFIG;
313
314         // Extensions are all inactive during installation
315         if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (empty($ext_name))) return false;
316
317         // Extension's file name will also be checked
318         $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
319         if ((!file_exists($file)) && (!is_readable($file))) return false;
320         //* DEBUG: */ echo "*".$ext_name."(".count($cacheArray).")<br />";
321
322         // Not active is the default
323         $active = "N";
324
325         // Check cache
326         if ((!empty($cacheArray['extensions']['ext_active'][$ext_name])) && (!$ignore_cache)) {
327                 // Load from cache
328                 //* DEBUG: */ echo "CACHE!<br />\n";
329                 $active = $cacheArray['extensions']['ext_active'][$ext_name];
330
331                 // Count cache hits
332                 if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++;
333         } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
334                 //* DEBUG: */ echo "DB!<br />\n";
335                 // Load from database
336                 $result = SQL_QUERY_ESC("SELECT ext_active FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
337                  array($ext_name), __FILE__, __LINE__);
338                 if (SQL_NUMROWS($result) == 0) {
339                         // Extension was not found!
340                         return false;
341                 }
342                 list($active) = SQL_FETCHROW($result);
343                 //* DEBUG: */ echo $ext_name."[DB]: {$active}<br />\n";
344                 SQL_FREERESULT($result);
345
346                 // Write cache array
347                 $cacheArray['extensions']['ext_active'][$ext_name] = $active;
348         } else {
349                 // Extension not active!
350                 //* DEBUG: */ echo $ext_name.": Not active!<br />\n";
351                 $cacheArray['extensions']['ext_active'][$ext_name] = "N";
352         }
353
354         // Create FQFN for extension file
355         $inc = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
356
357         // Debug message
358         //DEBUG_LOG(__FUNCTION__.": ext_name={$ext_name},active={$active}");
359
360         // Is this extension activated? (For admins we always have active extensions...)
361         return (
362                 (
363                         $active == "Y"
364                 ) && (
365                         file_exists($inc)
366                 ) && (
367                         is_readable($inc)
368                 )
369         );
370 }
371 // Get version from extensions
372 function GET_EXT_VERSION ($ext_name) {
373         global $cacheArray, $_CONFIG, $cacheInstance;
374         $ret = false;
375
376         // Extensions are all inactive during installation
377         if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return "";
378         //* DEBUG: */ echo __FUNCTION__.": ext_name={$ext_name}<br />\n";
379
380         // Is the cache written?
381         if (!empty($cacheArray['extensions']['ext_version'][$ext_name])) {
382                 // Load data from cache
383                 //* DEBUG: */ echo __FUNCTION__.": CACHE!<br />\n";
384                 $ret = $cacheArray['extensions']['ext_version'][$ext_name];
385
386                 // Count cache hits
387                 if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++; else $_CONFIG['cache_hits'] = 1;
388         } elseif (!is_object($cacheInstance)) {
389                 // Load from database
390                 $result = SQL_QUERY_ESC("SELECT ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
391                  array($ext_name), __FILE__, __LINE__);
392                 list($ret) = SQL_FETCHROW($result);
393                 SQL_FREERESULT($result);
394
395                 // Set cache
396                 $cacheArray['extensions']['ext_version'][$ext_name] = $ret;
397         }
398
399         // Return result
400         //* DEBUG: */ echo __FUNCTION__.": ret={$ret}<br />\n";
401         return $ret;
402 }
403 //
404 function EXTENSION_UPDATE($file, $ext, $EXT_VER, $dry_run=false)
405 {
406         // This shall never do a non-admin user!
407         global $cacheInstance, $_CONFIG, $NOTES; $SQLs = array();
408         if ((!IS_ADMIN()) || (empty($ext))) return false;
409
410         // Load extension in update mode
411         $EXT_LOAD_MODE = "update"; $EXT_UPDATE_DEPENDS = ""; $NOTES = "";
412         include(PATH."inc/extensions/".$file);
413         if (!empty($EXT_UPDATE_DEPENDS))
414         {
415                 // Update another extension first!
416                 $test = EXTENSION_UPDATE(("ext-".$EXT_UPDATE_DEPENDS.".php"), $EXT_UPDATE_DEPENDS, GET_EXT_VERSION($EXT_UPDATE_DEPENDS), $dry_run);
417         }
418
419         // Check if version is updated
420         if ((($EXT_VERSION != $EXT_VER) || ($dry_run)) && (is_array($EXT_VER_HISTORY)))
421         {
422                 // Search for starting point
423                 $start = array_search($EXT_VER, $EXT_VER_HISTORY);
424                 $NOTES = "";
425
426                 // And load SQL queries in order of version history
427                 for ($idx = ($start + 1); $idx < sizeof($EXT_VER_HISTORY); $idx++)
428                 {
429                         // Remove old SQLs array to prevent possible bugs
430                         if (!$dry_run) { unset($SQLs); $SQLs = array(); }
431
432                         // Set version
433                         $EXT_VER = $EXT_VER_HISTORY[$idx];
434
435                         // Include again...
436                         include(PATH."inc/extensions/".$file);
437
438                         // Add notes
439                         if ($_CONFIG['verbose_sql'] == "Y")
440                         {
441                                 $EXT_VER = $EXT_VER_HISTORY[$idx];
442                                 if (!empty($UPDATE_NOTES))
443                                 {
444                                         // Update notes found
445                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".$UPDATE_NOTES."<br /><br />\n";
446                                         $UPDATE_NOTES = "";
447                                 }
448                                  elseif ($EXT_VER == "0.0")
449                                 {
450                                         // Initial release
451                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".INITIAL_RELEASE."<br /><br />\n";
452                                 }
453                                  else
454                                 {
455                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br /><I>".NO_UPDATE_NOTES."</I><br /><br />\n";
456                                 }
457                         }
458
459                         // Run SQLs
460                         if ((is_array($SQLs)) && (!$dry_run))
461                         {
462                                 // Run SQL commands
463                                 foreach ($SQLs as $sql)
464                                 {
465                                         $sql = trim($sql);
466                                         if (!empty($sql))
467                                         {
468                                                 // Do we have an "ALTER TABLE" command?
469                                                 if (substr(strtolower($sql), 0, 11) == "alter table") {
470                                                         // Analyse the alteration command
471                                                         SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
472                                                 } else {
473                                                         // Run regular SQL command
474                                                         $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
475                                                 }
476                                         }
477                                 }
478                         } elseif (GET_EXT_VERSION("sql_patches") == "") {
479                                 // Remove SQLs if extension is not installed
480                                 $SQLs = array();
481                         }
482                 }
483
484                 if (!$dry_run)
485                 {
486                         // In normal mode insert task and update extension's version...
487                         $ext_subj = "[UPDATE-".$ext."-".$EXT_VERSION.":] ".ADMIN_UPDATE_EXT_SUBJ;
488
489                         // Create task
490                         CREATE_EXTENSION_UPDATE_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, addslashes($NOTES));
491
492                         // Update extension's version
493                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
494                          array($EXT_VERSION, $ext), __FILE__, __LINE__);
495
496                         // Update cache
497                         if (EXT_IS_ACTIVE("cache")) {
498                                 if ($cacheInstance->cache_file("extensions", true) == true) $cacheInstance->cache_destroy();
499                                 if ($cacheInstance->cache_file("config", true) == true)     $cacheInstance->cache_destroy();
500                                 if ($cacheInstance->cache_file("mod_reg", true) == true)    $cacheInstance->cache_destroy();
501                         } // END - if
502
503                         // Remove array
504                         unset($SQLs);
505                 } else {
506                         // In "dry-run" mode return array with SQL commands
507                         return $SQLs;
508                 }
509         }
510 }
511 //
512 function EXTENSION_VERBOSE_TABLE($SQLs, $title = ADMIN_SQLS_EXECUTED_ON_REMOVAL, $dashed = "", $switch = false, $WIDTH = "480") {
513         global $_CONFIG;
514
515         $S = false; $SW = 2; $i = 1;
516         $OUT = "";
517         if ((is_array($SQLs)) && (GET_EXT_VERSION("sql_patches")) && ($_CONFIG['verbose_sql'] == "Y")) {
518                 $OUT  = "<DIV align=\"center\">
519 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"".$WIDTH."\" align=\"center\"".$dashed.">
520 <TR>
521   <TD colspan=\"2\" align=\"center\" class=\"admin_title bottom2\" height=\"24\">
522     <STRONG>".$title.":</STRONG>
523   </TD>
524 </TR>\n";
525                 foreach ($SQLs as $idx => $sql) {
526                         $sql = trim($sql);
527                         if (!empty($sql)) {
528                                 $S = true;
529                                 $OUT .= "<TR>
530   <TD class=\"switch_sw".(3 - $SW)." bottom2\" style=\"padding-left: 2px\" width=\"30\">".$i.".</TD>
531   <TD class=\"switch_sw".(3 - $SW)." bottom2\" style=\"padding-left: 5px; padding-right: 5px\">
532     ".$sql."
533   </TD>
534 </TR>\n";
535                                 if ($switch) $SW = 3 - $SW;
536                                 $i++;
537                         }
538                 }
539         }
540
541         if ((!$S) && (GET_EXT_VERSION("sql_patches")) && ($_CONFIG['verbose_sql'] == "Y")) {
542                 // No addional SQL commands to run
543                 $OUT .= "<TR>
544   <TD colspan=\"2\" align=\"center\" class=\"switch_sw2 bottom2\" height=\"24\">
545     <FONT class=\"admin_note\">".ADMIN_NO_ADDIONAL_SQLS."</FONT>
546   </TD>
547 </TR>\n";
548         }
549
550         if (!empty($OUT)) {
551                 // Add missing close-table tag
552                 $OUT .= "</TABLE>
553 </DIV>\n";
554         }
555
556         // Return output
557         return $OUT;
558 }
559 // Get extension name from id
560 function GET_EXT_NAME ($id) {
561         $ret = "";
562         global $cacheArray, $_CONFIG;
563         if (!empty($cacheArray['extensions']['ext_name'][$id])) {
564                 // Load from cache
565                 $ret = $cacheArray['extensions']['ext_name'][$id];
566
567                 // Count cache hits
568                 $_CONFIG['cache_hits']++;
569         } elseif (!EXT_IS_ACTIVE("cache")) {
570                 // Load from database
571                 $result = SQL_QUERY_ESC("SELECT ext_name FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
572                  array(bigintval($id)), __FILE__, __LINE__);
573                 list($ret) = SQL_FETCHROW($result);
574                 SQL_FREERESULT($result);
575         }
576         return $ret;
577 }
578 // Get extension id from name
579 function GET_EXT_ID($name) {
580         $ret = 0;
581         global $cacheArray, $_CONFIG;
582         if (isset($cacheArray['extensions']['ext_id'][$name])) {
583                 // Load from cache
584                 $ret = $cacheArray['extensions']['ext_id'][$name];
585
586                 // Count cache hits
587                 $_CONFIG['cache_hits']++;
588         } elseif (!EXT_IS_ACTIVE("cache")) {
589                 // Load from database
590                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
591                  array($name), __FILE__, __LINE__);
592                 list($ret) = SQL_FETCHROW($result);
593                 SQL_FREERESULT($result);
594         }
595
596         // Return value
597         return $ret;
598 }
599 //
600 ?>