]> git.mxchange.org Git - mailer.git/blob - inc/extensions.php
Fix for you-are-here navi
[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_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_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                                 } // END - if
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;
205
206                                 // Remove SQLs
207                                 unset($SQLs);
208                         } else {
209                                 // Rewrite SQL command to keep { and } inside
210                                 foreach ($SQLs as $key => $sql) {
211                                         $sql = str_replace('{', "&#123;", str_replace('}', "&#125;", $sql));
212                                         $SQLs[$key] = $sql;
213                                 } // END - foreach
214
215                                 // In  "dry-run" mode return array with all SQL commands
216                                 $ret = $SQLs;
217
218                                 // Remove all SQL commands
219                                 unset($SQLs);
220                         }
221                 } else {
222                         // No, an error occurs while registering extension :-(
223                         $ret = false;
224                 }
225         } elseif (($id > 0) && (!empty($ext_name))) {
226                 // Remove task from system when id and extension's name is valid
227                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%s AND status='NEW' LIMIT 1",
228                  array(bigintval($id)), __FILE__, __LINE__);
229         }
230
231         // Is this the sql_patches?
232         //* DEBUG: */ echo __LINE__.":{$ext_name}/{$EXT_LOAD_MODE}<br />\n";
233         if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove")) && (!$dry_run) && ($test)) {
234                 // Then redirect to logout
235                 //* DEBUG: */ echo __LINE__.": LOAD!<br />\n";
236                 LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
237         } // END - if
238
239         // Return status code
240         return $ret;
241 }
242 //
243 function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) {
244         global $cacheInstance;
245         $SQLs = array();
246
247         // By default no SQL has been executed
248         $sqlRan = false;
249
250         // This shall never do a non-admin user!
251         if (!IS_ADMIN()) return false;
252
253         // Get extension's name
254         $ext_name = GET_EXT_NAME($id);
255         if (empty($ext_name)) return false;
256
257         // Load extension in detected mode
258         //* DEBUG: */ echo __FUNCTION__.":ext_name[{$id}]={$ext_name}<br />\n";
259         $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
260         if (FILE_READABLE($file)) {
261                 // Load the include
262                 require($file);
263         }
264
265         //* DEBUG: */ echo __FUNCTION__.":SQLs::count=".count($SQLs)."<br />\n";
266         if ((is_array($SQLs) && (sizeof($SQLs) > 0))) {
267                 // Run SQL commands...
268                 foreach ($SQLs as $sql) {
269                         // Trim spaces away which we don't need
270                         $sql = trim($sql);
271
272                         // Is there still an SQL query?
273                         if (!empty($sql)) {
274                                 // Do we have an "ALTER TABLE" command?
275                                 //* DEBUG: */ echo __FUNCTION__.":SQL={$SQL}<br />\n";
276                                 if (substr(strtolower($sql), 0, 11) == "alter table") {
277                                         // Analyse the alteration command
278                                         SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
279                                 } else {
280                                         // Run regular SQL command
281                                         $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
282                                 }
283
284                                 // An SQL has been executed
285                                 $sqlRan = true;
286                         } // END - if
287                 } // END - foreach
288
289                 // Removal mode?
290                 if ($EXT_LOAD_MODE == "remove") {
291                         // Delete this extension (remember to remove it from your server *before* you click on welcome!
292                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
293                          array($id), __FILE__, __LINE__);
294                 } // END - if
295
296                 //* DEBUG: */ echo __FUNCTION__.":mode={$EXT_LOAD_MODE}<br />\n";
297
298                 // Remove cache file(s) if extension is active
299                 if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1) && ($EXT_LOAD_MODE == "remove")) || ($sqlRan === true))) {
300                         //* DEBUG: */ echo __LINE__.": DESTROY!<br />\n";
301                         // Remove cache files
302                         if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy();
303                         if ($cacheInstance->cache_file("mod_reg", true))    $cacheInstance->cache_destroy();
304                         if ($cacheInstance->cache_file("config", true))     $cacheInstance->cache_destroy();
305                 } // END - if
306
307                 // Is this the sql_patches?
308                 //* DEBUG: */ echo __LINE__.": {$id}/{$ext_name}/{$EXT_LOAD_MODE}<br />\n";
309                 if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove"))) {
310                         // Then redirect to logout
311                         //* DEBUG: */ echo __LINE__.": LOAD!<br />\n";
312                         LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
313                 } // END - if
314         } // END - if
315 }
316 // Check if given extension is active
317 function EXT_IS_ACTIVE ($ext_name, $ignore_admin = false, $ignore_cache = false) {
318         global $cacheArray, $_CONFIG;
319
320         // Extensions are all inactive during installation
321         if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (empty($ext_name))) return false;
322
323         // Extension's file name will also be checked
324         $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
325         if (!FILE_READABLE($file)) return false;
326         //* DEBUG: */ echo "*".$ext_name."(".count($cacheArray).")<br />";
327
328         // Not active is the default
329         $active = "N";
330
331         // Check cache
332         if ((!empty($cacheArray['extensions']['ext_active'][$ext_name])) && (!$ignore_cache)) {
333                 // Load from cache
334                 //* DEBUG: */ echo "CACHE! ext_name={$ext_name}<br />\n";
335                 $active = $cacheArray['extensions']['ext_active'][$ext_name];
336
337                 // Count cache hits
338                 if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++;
339         } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
340                 //* DEBUG: */ echo "DB! ext_name={$ext_name}<br />\n";
341                 // Load from database
342                 $result = SQL_QUERY_ESC("SELECT ext_active FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
343                  array($ext_name), __FILE__, __LINE__);
344                 if (SQL_NUMROWS($result) == 0) {
345                         // Extension was not found!
346                         return false;
347                 }
348                 list($active) = SQL_FETCHROW($result);
349                 //* DEBUG: */ echo $ext_name."[DB]: {$active}<br />\n";
350                 SQL_FREERESULT($result);
351
352                 // Write cache array
353                 $cacheArray['extensions']['ext_active'][$ext_name] = $active;
354         } else {
355                 // Extension not active!
356                 //* DEBUG: */ echo $ext_name.": Not active!<br />\n";
357                 $cacheArray['extensions']['ext_active'][$ext_name] = "N";
358         }
359
360         // Create FQFN for extension file
361         $inc = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
362
363         // Debug message
364         //DEBUG_LOG(__FUNCTION__.": ext_name={$ext_name},active={$active}");
365
366         // Is this extension activated? (For admins we always have active extensions...)
367         return (
368                 (
369                         $active == "Y"
370                 ) && (
371                         FILE_READABLE($inc)
372                 )
373         );
374 }
375 // Get version from extensions
376 function GET_EXT_VERSION ($ext_name) {
377         global $cacheArray, $_CONFIG, $cacheInstance;
378         $ret = false;
379
380         // Extensions are all inactive during installation
381         if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return "";
382         //* DEBUG: */ echo __FUNCTION__.": ext_name={$ext_name}<br />\n";
383
384         // Is the cache written?
385         if (!empty($cacheArray['extensions']['ext_version'][$ext_name])) {
386                 // Load data from cache
387                 //* DEBUG: */ echo __FUNCTION__.": CACHE!<br />\n";
388                 $ret = $cacheArray['extensions']['ext_version'][$ext_name];
389
390                 // Count cache hits
391                 if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++; else $_CONFIG['cache_hits'] = 1;
392         } elseif (!is_object($cacheInstance)) {
393                 // Load from database
394                 $result = SQL_QUERY_ESC("SELECT ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
395                  array($ext_name), __FILE__, __LINE__);
396                 list($ret) = SQL_FETCHROW($result);
397                 SQL_FREERESULT($result);
398
399                 // Set cache
400                 $cacheArray['extensions']['ext_version'][$ext_name] = $ret;
401         }
402
403         // Return result
404         //* DEBUG: */ echo __FUNCTION__.": ret={$ret}<br />\n";
405         return $ret;
406 }
407 //
408 function EXTENSION_UPDATE($file, $ext, $EXT_VER, $dry_run=false)
409 {
410         // This shall never do a non-admin user!
411         global $cacheInstance, $_CONFIG, $NOTES; $SQLs = array();
412         if ((!IS_ADMIN()) || (empty($ext))) return false;
413
414         // Load extension in update mode
415         $EXT_LOAD_MODE = "update"; $EXT_UPDATE_DEPENDS = ""; $NOTES = "";
416         include(PATH."inc/extensions/".$file);
417         if (!empty($EXT_UPDATE_DEPENDS))
418         {
419                 // Update another extension first!
420                 $test = EXTENSION_UPDATE(("ext-".$EXT_UPDATE_DEPENDS.".php"), $EXT_UPDATE_DEPENDS, GET_EXT_VERSION($EXT_UPDATE_DEPENDS), $dry_run);
421         }
422
423         // Check if version is updated
424         if ((($EXT_VERSION != $EXT_VER) || ($dry_run)) && (is_array($EXT_VER_HISTORY)))
425         {
426                 // Search for starting point
427                 $start = array_search($EXT_VER, $EXT_VER_HISTORY);
428                 $NOTES = "";
429
430                 // And load SQL queries in order of version history
431                 for ($idx = ($start + 1); $idx < sizeof($EXT_VER_HISTORY); $idx++)
432                 {
433                         // Remove old SQLs array to prevent possible bugs
434                         if (!$dry_run) { unset($SQLs); $SQLs = array(); }
435
436                         // Set version
437                         $EXT_VER = $EXT_VER_HISTORY[$idx];
438
439                         // Include again...
440                         include(PATH."inc/extensions/".$file);
441
442                         // Add notes
443                         if ($_CONFIG['verbose_sql'] == "Y")
444                         {
445                                 $EXT_VER = $EXT_VER_HISTORY[$idx];
446                                 if (!empty($UPDATE_NOTES))
447                                 {
448                                         // Update notes found
449                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".$UPDATE_NOTES."<br /><br />\n";
450                                         $UPDATE_NOTES = "";
451                                 }
452                                  elseif ($EXT_VER == "0.0")
453                                 {
454                                         // Initial release
455                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".INITIAL_RELEASE."<br /><br />\n";
456                                 }
457                                  else
458                                 {
459                                         $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br /><I>".NO_UPDATE_NOTES."</I><br /><br />\n";
460                                 }
461                         }
462
463                         // Run SQLs
464                         if ((is_array($SQLs)) && (!$dry_run))
465                         {
466                                 // Run SQL commands
467                                 foreach ($SQLs as $sql)
468                                 {
469                                         $sql = trim($sql);
470                                         if (!empty($sql))
471                                         {
472                                                 // Do we have an "ALTER TABLE" command?
473                                                 if (substr(strtolower($sql), 0, 11) == "alter table") {
474                                                         // Analyse the alteration command
475                                                         SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
476                                                 } else {
477                                                         // Run regular SQL command
478                                                         $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
479                                                 }
480                                         }
481                                 }
482                         } elseif (GET_EXT_VERSION("sql_patches") == "") {
483                                 // Remove SQLs if extension is not installed
484                                 $SQLs = array();
485                         }
486                 }
487
488                 if (!$dry_run)
489                 {
490                         // In normal mode insert task and update extension's version...
491                         $ext_subj = "[UPDATE-".$ext."-".$EXT_VERSION.":] ".ADMIN_UPDATE_EXT_SUBJ;
492
493                         // Create task
494                         CREATE_EXTENSION_UPDATE_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, addslashes($NOTES));
495
496                         // Update extension's version
497                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
498                          array($EXT_VERSION, $ext), __FILE__, __LINE__);
499
500                         // Update cache
501                         if (EXT_IS_ACTIVE("cache")) {
502                                 if ($cacheInstance->cache_file("extensions", true) == true) $cacheInstance->cache_destroy();
503                                 if ($cacheInstance->cache_file("config", true) == true)     $cacheInstance->cache_destroy();
504                                 if ($cacheInstance->cache_file("mod_reg", true) == true)    $cacheInstance->cache_destroy();
505                         } // END - if
506
507                         // Remove array
508                         unset($SQLs);
509                 } else {
510                         // In "dry-run" mode return array with SQL commands
511                         return $SQLs;
512                 }
513         }
514 }
515 //
516 function EXTENSION_VERBOSE_TABLE($SQLs, $title = ADMIN_SQLS_EXECUTED_ON_REMOVAL, $dashed = "", $switch = false, $WIDTH = "480") {
517         global $_CONFIG;
518
519         $S = false; $SW = 2; $i = 1;
520         $OUT = "";
521         if ((is_array($SQLs)) && (GET_EXT_VERSION("sql_patches")) && ($_CONFIG['verbose_sql'] == "Y")) {
522                 $OUT  = "<DIV align=\"center\">
523 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"".$WIDTH."\" align=\"center\"".$dashed.">
524 <TR>
525   <TD colspan=\"2\" align=\"center\" class=\"admin_title bottom2\" height=\"24\">
526     <STRONG>".$title.":</STRONG>
527   </TD>
528 </TR>\n";
529                 foreach ($SQLs as $idx => $sql) {
530                         $sql = trim($sql);
531                         if (!empty($sql)) {
532                                 $S = true;
533                                 $OUT .= "<TR>
534   <TD class=\"switch_sw".(3 - $SW)." bottom2\" style=\"padding-left: 2px\" width=\"30\">".$i.".</TD>
535   <TD class=\"switch_sw".(3 - $SW)." bottom2\" style=\"padding-left: 5px; padding-right: 5px\">
536     ".$sql."
537   </TD>
538 </TR>\n";
539                                 if ($switch) $SW = 3 - $SW;
540                                 $i++;
541                         }
542                 }
543         }
544
545         if ((!$S) && (GET_EXT_VERSION("sql_patches")) && ($_CONFIG['verbose_sql'] == "Y")) {
546                 // No addional SQL commands to run
547                 $OUT .= "<TR>
548   <TD colspan=\"2\" align=\"center\" class=\"switch_sw2 bottom2\" height=\"24\">
549     <FONT class=\"admin_note\">".ADMIN_NO_ADDIONAL_SQLS."</FONT>
550   </TD>
551 </TR>\n";
552         }
553
554         if (!empty($OUT)) {
555                 // Add missing close-table tag
556                 $OUT .= "</TABLE>
557 </DIV>\n";
558         }
559
560         // Return output
561         return $OUT;
562 }
563 // Get extension name from id
564 function GET_EXT_NAME ($id) {
565         $ret = "";
566         global $cacheArray, $_CONFIG;
567         if (!empty($cacheArray['extensions']['ext_name'][$id])) {
568                 // Load from cache
569                 $ret = $cacheArray['extensions']['ext_name'][$id];
570
571                 // Count cache hits
572                 $_CONFIG['cache_hits']++;
573         } elseif (!EXT_IS_ACTIVE("cache")) {
574                 // Load from database
575                 $result = SQL_QUERY_ESC("SELECT ext_name FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
576                  array(bigintval($id)), __FILE__, __LINE__);
577                 list($ret) = SQL_FETCHROW($result);
578                 SQL_FREERESULT($result);
579         }
580         return $ret;
581 }
582 // Get extension id from name
583 function GET_EXT_ID($name) {
584         $ret = 0;
585         global $cacheArray, $_CONFIG;
586         if (isset($cacheArray['extensions']['ext_id'][$name])) {
587                 // Load from cache
588                 $ret = $cacheArray['extensions']['ext_id'][$name];
589
590                 // Count cache hits
591                 $_CONFIG['cache_hits']++;
592         } elseif (!EXT_IS_ACTIVE("cache")) {
593                 // Load from database
594                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
595                  array($name), __FILE__, __LINE__);
596                 list($ret) = SQL_FETCHROW($result);
597                 SQL_FREERESULT($result);
598         }
599
600         // Return value
601         return $ret;
602 }
603 //
604 ?>