2 /************************************************************************
3 * MXChange v0.2.1 Start: 03/25/2004 *
4 * =============== Last change: 09/29/2004 *
6 * -------------------------------------------------------------------- *
7 * File : extensions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Extension management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Erweiterungen-Management *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Load the extension and maybe found language and function files.
41 function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = "") {
42 global $EXT_LOADED, $_CONFIG, $CSS, $cacheMode;
44 // Is the extension already loaded?
45 //* DEBUG: */ echo "Loading extension {$ext_name}.<br />\n";
46 if ((isset($EXT_LOADED[$ext_name])) && (empty($EXT_LOAD_MODE))) {
48 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
52 // Construct FQFN for extension file
53 $extInclude = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
55 // Is the extension file NOT there?
56 if (!FILE_READABLE($extInclude)) {
58 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s not found.", $ext_name));
64 // Construct FQFN for language file
65 $langInclude = sprintf("%sinc/language/%s_%s.php", PATH, $ext_name, GET_LANGUAGE());
67 // Is this include there?
68 if (FILE_READABLE($langInclude)) {
70 //* DEBUG: */ echo "--- Language loaded.<br />\n";
71 require($langInclude);
74 // Construct FQFN for functions file
75 $funcsInclude = sprintf("%sinc/libs/%s_functions.php", PATH, $ext_name);
77 // Is this include there?
78 if (FILE_READABLE($funcsInclude)) {
80 //* DEBUG: */ echo "--- Functions loaded.<br />\n";
81 require($funcsInclude);
84 // Extensions are not deprecated by default
85 $EXT_DEPRECATED = "N";
87 // Include the extension file
88 //* DEBUG: */ echo "Extension loaded.<br />\n";
91 // Is this extension deprecated?
92 if ($EXT_DEPRECATED == "Y") {
93 // Deactivate the extension
94 DEACTIVATE_EXTENSION($ext_name);
101 $EXT_LOADED[$ext_name] = true;
108 function EXTENSION_REGISTER ($ext_name, $id, $dry_run=false) {
109 global $NOTES, $_CONFIG, $INC_POOL, $cacheInstance;
111 // This shall never do a non-admin user!
112 if (!IS_ADMIN()) return false;
114 // Is this extension already installed?
115 if (EXT_IS_ACTIVE($ext_name)) return false;
117 // We want to register an extension and registration status is by default "failed" (= false)
118 $EXT_LOAD_MODE = "register"; $ret = false; $SQLs = array();
121 // By default the language prefix is the extension's name
122 // @TODO: Do we really need this one anymore? Can't we just take $ext_name and done?
123 // By default we have no failtures
124 $EXT_REPORTS_FAILURE = false;
126 // Generate file name
127 $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
129 // Does this extension exists?
130 if (FILE_READABLE($file)) {
131 // Extension was found so we can load it in registration mode
132 $EXT_ALWAYS_ACTIVE = "N";
135 // And run possible updates
136 $EXT_LOAD_MODE = "update"; $EXT_UPDATE_DEPENDS = "";
137 foreach ($EXT_VER_HISTORY as $EXT_VER) {
138 // Load extension in update mode
141 // Do we have an update?
142 if (((GET_EXT_VERSION("sql_patches") != "") && ($_CONFIG['verbose_sql'] == "Y")) || (!EXT_IS_ACTIVE("sql_patches"))) {
143 if (!empty($UPDATE_NOTES)) {
144 // Update notes found
145 $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".$UPDATE_NOTES."<br /><br />\n";
147 } elseif (($EXT_VER == "0.0") || ($EXT_VER == "0.0.0")) {
149 $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".INITIAL_RELEASE."<br /><br />\n";
151 // No update notes found!
152 $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br /><I>".NO_UPDATE_NOTES."</I><br /><br />\n";
157 // Does this extension depends on an outstanding update of another update?
158 if (!empty($EXT_UPDATE_DEPENDS)) {
159 // Backup SQL commands and clear current
164 // Load required extension also in update mode
165 $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $EXT_UPDATE_DEPENDS);
167 // Check for required file
168 if (FILE_READABLE($file)) {
169 // Bacup version number
170 $VER_BACKUP = $EXT_VERSION;
172 // Save the Parrent $EXT_ALWAYS_ACTIVE for later!
173 $EXT_ALWAYS_ACTIVE_PARRENT = $EXT_ALWAYS_ACTIVE;
175 // Set EXT_ALWAYS_ACTIVE for update
176 $EXT_ALWAYS_ACTIVE = "N";
178 // File exists so let's load it
181 // If versions mismatch update extension first
182 $ext_ver = GET_EXT_VERSION($EXT_UPDATE_DEPENDS);
184 // Extension version set? If empty the extension is not registered
185 if (empty($ext_ver)) {
186 // Extension not registered so far so first load task's ID...
187 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE task_type='EXTENSION' AND subject LIKE '[%s:]%%' LIMIT 1",
188 array($EXT_UPDATE_DEPENDS), __FILE__, __LINE__);
191 if (SQL_NUMROWS($result) == 1) {
192 // Task found so load task's ID and register extension...
193 list($task) = SQL_FETCHROW($result);
195 // Try to register the extension
196 $test = EXTENSION_REGISTER($EXT_UPDATE_DEPENDS, $task, $dry_run);
200 SQL_FREERESULT($result);
201 } elseif ($ext_ver != $EXT_VERSION) {
202 // Ok, update this extension now
203 EXTENSION_UPDATE(basename($file), $EXT_UPDATE_DEPENDS, $ext_ver, $dry_run);
208 // Nothing to register / update before...
212 // Restore version number
213 $EXT_VERSION = $VER_BACKUP;
215 // Restore $EXT_ALWAYS_ACTIVE with the value from parrent
216 $EXT_ALWAYS_ACTIVE = $EXT_ALWAYS_ACTIVE_PARRENT;
218 // Required file for update does not exists!
220 // But this is fine for the first time...
223 // Finally restore previous SQLs
224 $SQLs = $SQLs2; unset($SQLs2);
226 // Does not depend on an other extension
230 // Switch back to register mode
231 $EXT_LOAD_MODE = "register";
233 // Remains true if extension registration reports no failtures
234 $test = ($test && !$EXT_REPORTS_FAILURE);
236 // Does everthing before wents ok?
238 // "Dry-run-mode" activated?
241 foreach ($SQLs as $sql) {
242 // Trim spaces away which we don't need
245 // Is there still an SQL query?
247 // Do we have an "ALTER TABLE" command?
248 if (substr(strtolower($sql), 0, 11) == "alter table") {
249 // Analyse the alteration command
250 SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
252 // Run regular SQL command
253 $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
258 // Remove cache file(s) if extension is active
259 RUN_FILTER('post_extension_installed', $ext_name);
261 // Check for added include files
262 if (count($INC_POOL > 0)) {
263 // Loads every include file
264 foreach ($INC_POOL as $inc) {
272 // Register extension
273 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_extensions (ext_name, ext_active, ext_version) VALUES ('%s','%s','%s')",
274 array($ext_name, $EXT_ALWAYS_ACTIVE, $EXT_VERSION), __FILE__, __LINE__);
276 // Update task management
277 ADMIN_SOLVE_TASK($id);
279 // @TODO This causes the whole (!) menu cache being purged
280 CACHE_PURGE_ADMIN_MENU();
282 // In normal mode return a true on success
288 // Rewrite SQL command to keep { and } inside
289 foreach ($SQLs as $key => $sql) {
290 $sql = str_replace('{', "{", str_replace('}', "}", $sql));
294 // In "dry-run" mode return array with all SQL commands
297 // Remove all SQL commands
301 // No, an error occurs while registering extension :-(
304 } elseif (($id > 0) && (!empty($ext_name))) {
305 // Remove task from system when id and extension's name is valid
306 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%s AND status='NEW' LIMIT 1",
307 array(bigintval($id)), __FILE__, __LINE__);
310 // Is this the sql_patches?
311 //* DEBUG: */ echo __LINE__.":{$ext_name}/{$EXT_LOAD_MODE}<br />\n";
312 if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove")) && (!$dry_run) && ($test)) {
313 // Then redirect to logout
314 //* DEBUG: */ echo __LINE__.": LOAD!<br />\n";
315 LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
318 // Return status code
322 function EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE) {
323 global $cacheInstance, $_CONFIG;
326 // Extensions are never active by default
327 $EXT_ALWAYS_ACTIVE = "N";
329 // By default no SQL has been executed
332 // This shall never do a non-admin user!
333 if (!IS_ADMIN()) return false;
335 // Get extension's name
336 $ext_name = GET_EXT_NAME($id);
337 if (empty($ext_name)) return false;
339 // Load extension in detected mode
340 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ext_name[{$id}]={$ext_name}<br />\n";
341 $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
342 if (FILE_READABLE($file)) {
347 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):SQLs::count=".count($SQLs)."<br />\n";
348 if ((is_array($SQLs) && (sizeof($SQLs) > 0))) {
349 // Run SQL commands...
350 foreach ($SQLs as $sql) {
351 // Trim spaces away which we don't need
354 // Is there still an SQL query?
356 // Do we have an "ALTER TABLE" command?
357 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):SQL={$SQL}<br />\n";
358 if (substr(strtolower($sql), 0, 11) == "alter table") {
359 // Analyse the alteration command
360 SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
362 // Run regular SQL command
363 $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
366 // An SQL has been executed
372 if ($EXT_LOAD_MODE == "remove") {
373 // Delete this extension (remember to remove it from your server *before* you click on welcome!
374 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
375 array($id), __FILE__, __LINE__);
378 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):mode={$EXT_LOAD_MODE}<br />\n";
380 // Is this the sql_patches?
381 //* DEBUG: */ echo __LINE__.": {$id}/{$ext_name}/{$EXT_LOAD_MODE}<br />\n";
382 if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove"))) {
383 // Then redirect to logout
384 //* DEBUG: */ echo __LINE__.": LOAD!<br />\n";
385 LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
389 // Remove cache file(s) if extension is active
390 if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($EXT_LOAD_MODE == "activate") || ($EXT_LOAD_MODE == "deactivate"))) {
392 RUN_FILTER('post_extension_run_sql', $ext_name);
394 // @TODO This causes the whole (!) menu cache being purged
395 CACHE_PURGE_ADMIN_MENU();
398 // Check if given extension is active
399 function EXT_IS_ACTIVE ($ext_name) {
400 global $cacheArray, $_CONFIG;
402 // Extensions are all inactive during installation
403 if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (empty($ext_name))) return false;
405 // Not active is the default
409 if (!empty($cacheArray['extensions']['ext_active'][$ext_name])) {
411 //* DEBUG: */ echo "CACHE! ext_name={$ext_name}<br />\n";
412 $active = $cacheArray['extensions']['ext_active'][$ext_name];
415 if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++;
416 } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
417 //* DEBUG: */ echo "DB! ext_name={$ext_name}<br />\n";
418 // Load from database
419 $result = SQL_QUERY_ESC("SELECT ext_active FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
420 array($ext_name), __FILE__, __LINE__);
421 if (SQL_NUMROWS($result) == 0) {
422 // Extension was not found!
427 list($active) = SQL_FETCHROW($result);
430 SQL_FREERESULT($result);
434 //* DEBUG: */ echo $ext_name."[DB]: {$active}<br />\n";
435 $cacheArray['extensions']['ext_active'][$ext_name] = $active;
437 // Extension not active!
438 //* DEBUG: */ echo $ext_name.": Not active!<br />\n";
439 $cacheArray['extensions']['ext_active'][$ext_name] = "N";
443 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, " ext_name={$ext_name},active={$active}");
445 // Is this extension activated? (For admins we always have active extensions...)
446 return ($active == "Y");
448 // Get version from extensions
449 function GET_EXT_VERSION ($ext_name) {
450 global $cacheArray, $_CONFIG, $cacheInstance;
453 // Extensions are all inactive during installation
454 if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return "";
455 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ext_name={$ext_name}<br />\n";
457 // Is the cache written?
458 if (!empty($cacheArray['extensions']['ext_version'][$ext_name])) {
459 // Load data from cache
460 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): CACHE!<br />\n";
461 $ret = $cacheArray['extensions']['ext_version'][$ext_name];
464 if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++; else $_CONFIG['cache_hits'] = 1;
465 } elseif (!is_object($cacheInstance)) {
466 // Load from database
467 $result = SQL_QUERY_ESC("SELECT ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
468 array($ext_name), __FILE__, __LINE__);
469 list($ret) = SQL_FETCHROW($result);
470 SQL_FREERESULT($result);
473 $cacheArray['extensions']['ext_version'][$ext_name] = $ret;
477 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ret={$ret}<br />\n";
481 function EXTENSION_UPDATE($file, $ext, $EXT_VER, $dry_run=false) {
482 // This shall never do a non-admin user!
483 global $cacheInstance, $_CONFIG, $NOTES;
486 $SQLs = array(); $INC_POOL = array();
488 // Only admins are allowed to update extensions
489 if ((!IS_ADMIN()) || (empty($ext))) return false;
491 // Load extension in update mode
492 $EXT_LOAD_MODE = "update"; $EXT_UPDATE_DEPENDS = ""; $NOTES = "";
494 // Load extension file
495 include(sprintf("%sinc/extensions/%s", PATH, $file));
497 if (!empty($EXT_UPDATE_DEPENDS)) {
498 // Update another extension first!
499 $test = EXTENSION_UPDATE(("ext-".$EXT_UPDATE_DEPENDS.".php"), $EXT_UPDATE_DEPENDS, GET_EXT_VERSION($EXT_UPDATE_DEPENDS), $dry_run);
502 // Check if version is updated
503 if ((($EXT_VERSION != $EXT_VER) || ($dry_run)) && (is_array($EXT_VER_HISTORY))) {
504 // Search for starting point
505 $start = array_search($EXT_VER, $EXT_VER_HISTORY);
508 // And load SQL queries in order of version history
509 for ($idx = ($start + 1); $idx < sizeof($EXT_VER_HISTORY); $idx++) {
510 // Remove old SQLs array to prevent possible bugs
511 if (!$dry_run) { unset($SQLs); $SQLs = array(); }
514 $EXT_VER = $EXT_VER_HISTORY[$idx];
517 include(PATH."inc/extensions/".$file);
520 if ($_CONFIG['verbose_sql'] == "Y") {
521 $EXT_VER = $EXT_VER_HISTORY[$idx];
522 if (!empty($UPDATE_NOTES)) {
523 // Update notes found
524 $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".$UPDATE_NOTES."<br /><br />\n";
526 } elseif ($EXT_VER == "0.0") {
528 $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br />".INITIAL_RELEASE."<br /><br />\n";
530 $NOTES .= "<STRONG>v".$EXT_VER.":</STRONG><br /><I>".NO_UPDATE_NOTES."</I><br /><br />\n";
534 // In real-mode execute any existing includes
535 if ((!$dry_run) && (count($INC_POOL) > 0)) {
537 foreach ($INC_POOL as $fqfn) {
543 if ((is_array($SQLs)) && (!$dry_run)) {
545 foreach ($SQLs as $sql)
550 // Do we have an "ALTER TABLE" command?
551 if (substr(strtolower($sql), 0, 11) == "alter table") {
552 // Analyse the alteration command
553 SQL_ALTER_TABLE($sql, __FILE__, __LINE__);
555 // Run regular SQL command
556 $result = SQL_QUERY($sql, __FILE__, __LINE__, false);
560 } elseif (GET_EXT_VERSION("sql_patches") == "") {
561 // Remove SQLs if extension is not installed
567 // In normal mode insert task and update extension's version...
568 $ext_subj = "[UPDATE-".$ext."-".$EXT_VERSION.":] ".ADMIN_UPDATE_EXT_SUBJ;
571 CREATE_EXTENSION_UPDATE_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, addslashes($NOTES));
573 // Update extension's version
574 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
575 array($EXT_VERSION, $ext), __FILE__, __LINE__);
580 // Run filters on success extension update
581 RUN_FILTER('extension_update', $ext);
583 // In "dry-run" mode return array with SQL commands
589 // Output verbose SQL table for extension
590 function EXTENSION_VERBOSE_TABLE ($SQLs, $title = ADMIN_SQLS_EXECUTED_ON_REMOVAL, $dashed = "", $switch = false, $width = "480") {
593 $S = false; $SW = 2; $i = 1;
595 if ((is_array($SQLs)) && (GET_EXT_VERSION("sql_patches") >= "0.0.7") && ($_CONFIG['verbose_sql'] == "Y")) {
596 $OUT = "<DIV align=\"center\">
597 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"".$width."\" align=\"center\"".$dashed.">
599 <TD colspan=\"2\" align=\"center\" class=\"admin_title bottom2\" height=\"24\">
600 <STRONG>".$title.":</STRONG>
603 foreach ($SQLs as $idx => $sql) {
608 <TD class=\"switch_sw".(3 - $SW)." bottom2\" style=\"padding-left: 2px\" width=\"30\">".$i.".</TD>
609 <TD class=\"switch_sw".(3 - $SW)." bottom2\" style=\"padding-left: 5px; padding-right: 5px\">
613 if ($switch) $SW = 3 - $SW;
619 if ((!$S) && (GET_EXT_VERSION("sql_patches") >= "0.0.7") && ($_CONFIG['verbose_sql'] == "Y")) {
620 // No addional SQL commands to run
622 <TD colspan=\"2\" align=\"center\" class=\"switch_sw2 bottom2\" height=\"24\">
623 <FONT class=\"admin_note\">".ADMIN_NO_ADDIONAL_SQLS."</FONT>
629 // Add missing close-table tag
638 // Get extension name from id
639 function GET_EXT_NAME ($id) {
641 global $cacheArray, $_CONFIG;
642 if (!empty($cacheArray['extensions']['ext_name'][$id])) {
644 $ret = $cacheArray['extensions']['ext_name'][$id];
647 if (isset($_CONFIG['cache_hits'])) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
648 } elseif (!EXT_IS_ACTIVE("cache")) {
649 // Load from database
650 $result = SQL_QUERY_ESC("SELECT ext_name FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
651 array(bigintval($id)), __FILE__, __LINE__);
652 list($ret) = SQL_FETCHROW($result);
653 SQL_FREERESULT($result);
658 // Get extension id from name
659 function GET_EXT_ID($name) {
661 global $cacheArray, $_CONFIG;
662 if (isset($cacheArray['extensions']['ext_id'][$name])) {
664 $ret = $cacheArray['extensions']['ext_id'][$name];
667 if (isset($_CONFIG['cache_hits'])) { $_CONFIG['cache_hits']++; } else { $_CONFIG['cache_hits'] = 1; }
668 } elseif (!EXT_IS_ACTIVE("cache")) {
669 // Load from database
670 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
671 array($name), __FILE__, __LINE__);
672 list($ret) = SQL_FETCHROW($result);
673 SQL_FREERESULT($result);
680 // Activate given extension
681 function ACTIVATE_EXTENSION ($ext_name) {
682 // Activate the extension
683 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_active='Y' WHERE ext_name='%s' LIMIT 1",
684 array($ext_name), __FILE__, __LINE__);
686 // Extension has been activated?
687 if (SQL_AFFECTEDROWS() == 1) {
688 // Then run all queries
689 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "activate");
693 // Deactivate given extension
694 function DEACTIVATE_EXTENSION($ext_name) {
695 // Activate the extension
696 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_active='N' WHERE ext_name='%s' LIMIT 1",
697 array($ext_name), __FILE__, __LINE__);
699 // Extension has been activated?
700 if (SQL_AFFECTEDROWS() == 1) {
701 // Then run all queries
702 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "deactivate");
705 CREATE_EXTENSION_DEACTIVATION_TASK($ext_name);
708 SEND_ADMIN_NOTIFICATION(ADMIN_SUBJECT_EXTENSION_DEACTIVATED, "admin_ext_deactivated", array('ext_name' => $ext_name));
712 // Checks wether the extension is older than given
713 function EXT_VERSION_IS_OLDER ($ext_name, $ext_ver) {
714 // Get current extension version
715 $currVersion = GET_EXT_VERSION($ext_name);
717 // Remove all dots from both versions
718 $currVersion = str_replace(".", "", $currVersion);
719 $ext_ver = str_replace(".", "", $ext_ver);
721 // Now compare both and return the result
722 return ($currVersion < $ext_ver);
725 // Creates a new task for updated extension
726 function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $subject, $notes) {
727 // Check if task is not there
728 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE subject='%s' LIMIT 1",
729 array($subject), __FILE__, __LINE__);
730 if (SQL_NUMROWS($result) == 0) {
731 // Task not created so it's a brand-new extension which we need to register and create a task for!
732 $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())",
733 array($admin_id, $subject, $notes), __FILE__, __LINE__);
737 SQL_FREERESULT($result);
740 // Creates a new task for newly installed extension
741 function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
742 // Not installed and do we have created a task for the admin?
743 $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
744 array($subject), __FILE__, __LINE__);
745 if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) == "")) {
747 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
753 // Load text for task
754 if (FILE_READABLE($tpl)) {
755 // Load extension's own text template (HTML!)
756 $msg = LOAD_TEMPLATE("ext_".$ext, true);
758 // Load default message
759 $msg = LOAD_TEMPLATE("admin_new_ext", "", 0);
762 // Task not created so it's a brand-new extension which we need to register and create a task for!
763 $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created)
764 VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
769 ), __FILE__, __LINE__, true, false
774 SQL_FREERESULT($result);
777 // Creates a task for automatically deactivated (deprecated) extension
778 function CREATE_EXTENSION_DEACTIVATION_TASK ($ext) {
779 // Create subject line
780 $subject = sprintf("[%s:] %s", $ext, TASK_SUBJ_EXTENSION_DEACTIVATED);
782 // Not installed and do we have created a task for the admin?
783 $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` = '%s' LIMIT 1",
784 array($subject), __FILE__, __LINE__);
785 if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) != "")) {
786 // Task not created so add it
787 $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created)
788 VALUES (0,0,'NEW','EXTENSION_DEACTIVATION','%s','%s',UNIX_TIMESTAMP())",
791 addslashes(LOAD_TEMPLATE("task_ext_deactivated", true, $ext)),
792 ), __FILE__, __LINE__, true, false
797 SQL_FREERESULT($result);