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