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