* =============== Last change: 08/29/2004 *
* *
* -------------------------------------------------------------------- *
- * File : lib.php *
+ * File : lib-mysql3.php *
* -------------------------------------------------------------------- *
- * Short description : *
+ * Short description : Database layer for MySQL +3.x server *
* -------------------------------------------------------------------- *
- * Kurzbeschreibung : *
+ * Kurzbeschreibung : Datenbankschicht fuer MySQL +3.x Server *
* -------------------------------------------------------------------- *
* *
* -------------------------------------------------------------------- *
$querytimeBefore = array_sum(explode(' ', microtime()));
// Run SQL command
+ //* DEBUG: */ echo $sql_string."<br />\n";
$result = @mysql_query($sql_string, $link)
or ADD_FATAL($F." (".$L."):".mysql_error()."<br />
".MYSQL_QUERY_STRING."<br />
// SQL string escaping
function SQL_QUERY_ESC($qstring, $data, $file, $line, $run=true, $strip=true) {
global $link;
+ $query = "";
$eval = "\$query = sprintf(\"".$qstring."\"";
foreach ($data as $var) {
if ((!empty($var)) || ($var === 0)) {
//
// Debugging
//
- //$fp = fopen(PATH."escape_debug.log", 'a') or mxchange_die("Cannot write debug.log!");
- //fwrite($fp, $file."(".$line."): ".str_replace('\r', "", str_replace('\n', " ", $eval))."\n");
+ //$fp = fopen(PATH."inc/cache/escape_debug.log", 'a') or mxchange_die("Cannot write debug.log!");
+ //fwrite($fp, $file."(".$line."): ".str_replace("\r", "", str_replace("\n", " ", $eval))."\n");
//fclose($fp);
- eval($eval);
+ @eval($eval);
+ if (empty($query)) {
+ print "eval=".htmlentities($eval)."<pre>";
+ debug_print_backtrace();
+ die("</pre>");
+ }
if ($run) {
// Run SQL query (default)
return SQL_QUERY($query, $file, $line);
if ((!file_exists($file)) && (!is_readable($file))) return false;
//* DEBUG: */ echo "*".$ext_name."(".count($cacheArray).")<br />";
- // Failed is the default
- $ret = false;
+ // Not active is the default
+ $active = "N";
+
+ // Check cache
if ((!empty($cacheArray['extensions']['ext_active'][$ext_name])) && (!$ignore_cache)) {
// Load from cache
//* DEBUG: */ echo "CACHE!<br />\n";
// Count cache hits
if (isset($_CONFIG['cache_hits'])) $_CONFIG['cache_hits']++;
- } else {
+ } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
//* DEBUG: */ echo "DB!<br />\n";
// Load from database
$result = SQL_QUERY_ESC("SELECT ext_active FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
return false;
}
list($active) = SQL_FETCHROW($result);
+ //* DEBUG: */ echo $ext_name."[DB]: {$active}<br />\n";
SQL_FREERESULT($result);
// Write cache array
$cacheArray['extensions']['ext_active'][$ext_name] = $active;
+ } else {
+ // Extension not active!
+ //* DEBUG: */ echo $ext_name.": Not active!<br />\n";
+ $cacheArray['extensions']['ext_active'][$ext_name] = "N";
}
- // Is this extension activated? (For admins we always have active extensions...)
+ // Create FQFN for extension file
$inc = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
- // Shorter way
+
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.": ext_name={$ext_name},active={$active}");
+
+ // Is this extension activated? (For admins we always have active extensions...)
return (
(
- ($active == "Y") || (
- (IS_ADMIN()) &&
- (!$ignore_admin) &&
- (!empty($active))
- )
+ $active == "Y"
) && (
file_exists($inc)
) && (
$ext_subj = "[UPDATE-".$ext."-".$EXT_VERSION.":] ".ADMIN_UPDATE_EXT_SUBJ;
// Create task
- $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE subject='%s' LIMIT 1",
- array($ext_subj), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 0) {
- // Task not created so it's a brand-new extension which we need to register and create a task for!
- $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())",
- array(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, addslashes($NOTES)), __FILE__, __LINE__);
- }
-
- // Free memory
- SQL_FREERESULT($result);
+ CREATE_EXTENSION_UPDATE_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, addslashes($NOTES));
// Update extension's version
$result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
// Possible newly installed extension found so we extract extension's name
$ext = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
- // Check if extension is installed or not
+ // Init variables
$ext_ver = "";
- if ((!is_array($cacheArray['extensions']['ext_version'])) || (empty($cacheArray['extensions']['ext_version'][$ext]))) {
- // Load data from database
- $result = SQL_QUERY_ESC("SELECT id, ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
- array($ext), __FILE__, __LINE__);
- } else {
+ $result = false;
+
+ // Check if extension is installed or not
+ if ((is_array($cacheArray['extensions']['ext_version'])) && (isset($cacheArray['extensions']['ext_version'][$ext]))) {
// Load version from cache
if (!empty($cacheArray['extensions']['ext_version'][$ext])) {
// Extension is installed so we can get it's version number
// Disable load from database
$result = false;
+ } elseif (!EXT_IS_ACTIVE("cache")) {
+ // Load data from database
+ $result = SQL_QUERY_ESC("SELECT id, ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
+ array($ext), __FILE__, __LINE__);
}
// Is the extension not yet installed?
// Generate subject line
$ext_subj = sprintf("[%s:]", $ext);
- // Not installed and do we have created a task for the admin?
- //* DEBUG: */ echo $ext.":".$ext_ver."=";
- $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
- array($ext_subj), __FILE__, __LINE__);
- //* DEBUG: */ echo SQL_NUMROWS($result)."<br />\n";
- if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) == "")) {
- // Template file
- $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
- PATH,
- GET_LANGUAGE(),
- $ext
- );
-
- // Load text for task
- if ((file_exists($tpl)) && (is_readable($tpl))) {
- // Load extension's own text template (HTML!)
- $MSG = LOAD_TEMPLATE("ext_".$ext, true);
- } else {
- // Load default message
- $MSG = LOAD_EMAIL_TEMPLATE("admin_new_ext","", 0);
- }
-
- // Task not created so it's a brand-new extension which we need to register and create a task for!
- $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created)
-VALUES ('%s', '0', 'NEW', 'EXTENSION', '%s', '%s', UNIX_TIMESTAMP())",
- array(
- GET_ADMIN_ID(get_session('admin_login')),
- $ext_subj,
- addslashes($MSG),
- ), __FILE__, __LINE__, true, false);
- }
-
- // Free memory
- SQL_FREERESULT($result);
+ // Create a task for newly installed extension
+ CREATE_NEW_EXTENSION_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, $ext);
// We maybe want to install an extension so let's test-drive it...
include(PATH."inc/extensions/".$file);
// Free memory
SQL_FREERESULT($result);
- //* DEBUG: */ var_dump($ret);
+
+ // Return result
return $ret;
}
//
return $ret;
}
//
-function GET_ADMIN_LOGIN($aid) {
+function GET_ADMIN_LOGIN ($aid) {
global $cacheArray;
$ret = "***";
- if (!empty($cacheArray['admins']['login']['aid'])) {
+ if (!empty($cacheArray['admins']['login'])) {
// Check cache
- if (!empty($cacheArray['admins']['login'][$aid])) $ret = $cacheArray['admins']['login'][$aid];
+ if (!empty($cacheArray['admins']['login'][$aid])) {
+ $ret = $cacheArray['admins']['login'][$aid];
+ } // END - if
if (empty($ret)) $ret = "***";
} else {
// Load from database
if (SQL_NUMROWS($result) == 1) {
// Fetch data
list($ret) = SQL_FETCHROW($result);
+
+ // Set cache
+ $cacheArray['admins']['login'][$aid] = $ret;
}
// Free memory
if (isset($cacheArray['modules']['has_menu'][$mod]))
{
// Check module cache and count hit
- if ($cacheArray['modules']['has_menu'][$mod] == "Y") $ret = true;
+ $ret = ($cacheArray['modules']['has_menu'][$mod] == "Y");
$_CONFIG['cache_hits']++;
}
elseif (isset($cacheArray['extensions']['ext_menu'][$mod]))
{
// Check cache and count hit
- if ($cacheArray['extensions']['ext_menu'][$mod] == "Y") $ret = true;
+ $ret = ($cacheArray['extensions']['ext_menu'][$mod] == "Y");
$_CONFIG['cache_hits']++;
}
- }
-
- if ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ($ret === false)) {
+ } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && (!EXT_IS_ACTIVE("cache"))) {
// Check database for entry
$result = SQL_QUERY_ESC("SELECT has_menu FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1",
array($mod), __FILE__, __LINE__);
if (SQL_NUMROWS($result) == 1) {
list($has_menu) = SQL_FETCHROW($result);
+
+ // Fake cache... ;-)
+ $cacheArray['extensions']['ext_menu'][$mod] = $has_menu;
+
+ // Does it have a menu?
$ret = ($has_menu == "Y");
- }
+ } // END - if
// Free memory
SQL_FREERESULT($result);
require(PATH."inc/load_cache-config.php");
} // END - if
}
+// Creates a new task for updated extension
+function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $subject, $notes) {
+ // Check if task is not there
+ $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE subject='%s' LIMIT 1",
+ array($subject), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 0) {
+ // Task not created so it's a brand-new extension which we need to register and create a task for!
+ $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())",
+ array($admin_id, $subject, $notes), __FILE__, __LINE__);
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+}
+// Creates a new task for newly installed extension
+function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
+ // Not installed and do we have created a task for the admin?
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
+ array($subject), __FILE__, __LINE__);
+ if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) == "")) {
+ // Template file
+ $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
+ PATH,
+ GET_LANGUAGE(),
+ $ext
+ );
+
+ // Load text for task
+ if ((file_exists($tpl)) && (is_readable($tpl))) {
+ // Load extension's own text template (HTML!)
+ $msg = LOAD_TEMPLATE("ext_".$ext, true);
+ } else {
+ // Load default message
+ $msg = LOAD_EMAIL_TEMPLATE("admin_new_ext","", 0);
+ }
+
+ // Task not created so it's a brand-new extension which we need to register and create a task for!
+ $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created)
+VALUES (%s, 0, 'NEW', 'EXTENSION', '%s', '%s', UNIX_TIMESTAMP())",
+ array(
+ $admin_id,
+ $subject,
+ addslashes($msg),
+ ), __FILE__, __LINE__, true, false
+ );
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+}
//
?>