Non-existing columns cannot be dropped (now this scenario is safely detected and...
authorRoland Häder <roland@mxchange.org>
Mon, 1 Nov 2010 22:00:43 +0000 (22:00 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 1 Nov 2010 22:00:43 +0000 (22:00 +0000)
inc/db/lib-mysql3.php
inc/extensions/ext-sql_patches.php
inc/filters.php
inc/functions.php
inc/language/de.php
inc/libs/surfbar_functions.php
inc/template-functions.php
inc/wrapper-functions.php
mailid_top.php

index 8aeff002e20daf7443f274cbda9f2ac9177bc09e..747da66559c582e43f45251254200ee2e5372eb0 100644 (file)
@@ -381,10 +381,19 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
        $tableArray = explode(' ', $sql);
        $tableName = str_replace('`', '', $tableArray[2]);
 
+       // Debug log
+       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ',tableName=' . $tableName);
+
        // Shall we add/drop?
        if (((strpos($sql, 'ADD') !== false) || (strpos($sql, 'DROP') !== false) || (strpos($sql, 'CHANGE') !== false)) && ($noIndex === true)) {
                // Try two columns, one should fix
                foreach (array(4,5) as $idx) {
+                       // If an entry is not set, abort here
+                       if (!isset($tableArray[$idx])) {
+                               // Debug log this
+                               logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ' is missing!');
+                       } // END - if
+
                        // And column name as well
                        $columnName = str_replace('`', '', $tableArray[$idx]);
 
@@ -409,6 +418,9 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
                                // Abort here because it is alreay there
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: ' . $sql);
                                break;
+                       } elseif ((SQL_HASZERONUMS($result)) && (strpos($sql, 'DROP') !== false)) {
+                               // Abort here because we tried to drop a column which is not there (never created maybe)
+                               break;
                        } elseif ($columnName != 'KEY') {
                                // Something didn't fit, we better log it
                                logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql . ',hasZeroNums=' . intval(SQL_HASZERONUMS($result)) . '');
index 9ae78ef3660d2ffac48381cf1dd12fd5916e0553..f472c40497678c00d542037b3654bd09c44f7977 100644 (file)
@@ -274,11 +274,14 @@ switch (getExtensionMode()) {
                                break;
 
                        case '0.2.4': // SQL queries for v0.2.4
-                               $auto_type = 'png'; // PNG image is the default
-                               if ((isIncludeReadable('theme/'.getCurrentTheme().'/images/code_bg.jpg')) && function_exists('imagecreatefromjpeg')) {
+                               // PNG image is the default
+                               $auto_type = 'png';
+
+                               // Is the JPEG file found and required PHP function there?
+                               if ((isFileReadable(getPath() . 'theme/' . getCurrentTheme() . '/images/code_bg.jpg')) && function_exists('imagecreatefromjpeg')) {
                                        // Switch to JPEG format
                                        $auto_type = 'jpg';
-                               }
+                               } // END - if
                                addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `img_type` ENUM('jpg','png') NOT NULL DEFAULT '" . $auto_type . "'");
 
                                // Update notes (these will be set as task text!)
@@ -689,15 +692,12 @@ PRIMARY KEY (`filter_id`)
                                break;
 
                        case '0.6.8': // SQL queries for v0.6.8
-                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu`
-CHANGE `action` `action` VARCHAR(50) NOT NULL,
-CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL');
-                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_guest_menu`
-CHANGE `action` `action` VARCHAR(50) NOT NULL,
-CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL');
-                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_member_menu`
-CHANGE `action` `action` VARCHAR(50) NOT NULL,
-CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `action` `action` VARCHAR(50) NOT NULL');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_guest_menu` CHANGE `action` `action` VARCHAR(50) NOT NULL');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_member_menu` CHANGE `action` `action` VARCHAR(50) NOT NULL');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_admin_menu` CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL');
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Spalten verk&uuml;rzt, damit die Schl&uuml;ssel passen.");
index 8ae57cee986bbdfce660d4d311db869d4fdcef2b..73828d019c7255457f87c06dd11da6b7e748f5f5 100644 (file)
@@ -330,7 +330,7 @@ function FILTER_INIT_RANDOMIZER () {
        setConfigEntry('_PRIME', 591623);
 
        // Calculate "entropy" with the prime number (for code generation)
-       setConfigEntry('_ADD', (getPrime() * getPrime() / (pi() * getConfig('code_length') + 1)));
+       setConfigEntry('_ADD', (getPrime() * getPrime() / (pi() * getCodeLength() + 1)));
 
        // Simply init the randomizer with seed and _ADD value
        mt_srand(generateSeed() + getConfig('_ADD'));
index 92e47c9c44bc94460e1341a39933246d3a3f6ccc..99ff9804f5ebc9e3fea65fc32852eb39ed54374f 100644 (file)
@@ -698,7 +698,7 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') {
        }
 
        // At least 10 numbers shall be secure enought!
-       $len = getConfig('code_length');
+       $len = getCodeLength();
        if ($len == '0') $len = $length;
        if ($len == '0') $len = 10;
 
index 4abf6b23b878e25165b3d57a0411b7d5d38f4e29..e321cf5acf60594e3b1ea1f31e7b66647432e195 100644 (file)
@@ -317,7 +317,7 @@ addMessages(array(
        'MEMBER_UNKNOWN_MODE' => "Unbekannter Modus erkannt",
        'MEMBER_CHANGED_EMAIL' => "Sie haben Ihre Email-Adresse ge&auml;ndert! Alte Adresse war",
        'MEMBER_CHANGED_PASS' => "Sie haben Ihr Passwort ge&auml;ndert.",
-       'MEMBER_CHANGED_DATA' => "&auml;nderung Ihrer Profildaten",
+       'MEMBER_CHANGED_DATA' => "&Auml;nderung Ihrer Profildaten",
        'MEMBER_MYDATA_MAIL_SENT' => "Es ist eine Email zu Ihnen unterwegs.",
        'ADMIN_CHANGED_DATA' => "Profildaten ge&auml;ndert",
        'ADMIN_MEMBER_CHANGED_PROFILE' => "Eines Ihrer Mitglieder hat seine Profildaten ge&auml;ndert.",
index 340347e418f3b86ff91a1348ba6af06e82501bbe..ee7784102cf1f5a471f5600e0336f7ca158c3ac5 100644 (file)
@@ -952,7 +952,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
        $GLOBALS['surfbar_cache']['salt'] = 'INVALID';
 
        // Get code length from config
-       $length = getConfig('code_length');
+       $length = getCodeLength();
 
        // Fix length to 10
        if ($length == '0') $length = 10;
index 56ee2adb8e57c6a1afa2b6e36c296108a1c1aa81..0c364ef457151a047c4b87d5dbedb00f3ad9c8b7 100644 (file)
@@ -766,9 +766,9 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 'fo
 // Insert the code in $img_code into jpeg or PNG image
 function generateImageOrCode ($img_code, $headerSent = true) {
        // Is the code size oversized or shouldn't we display it?
-       if ((strlen($img_code) > 6) || (empty($img_code)) || (getConfig('code_length') == '0')) {
+       if ((strlen($img_code) > 6) || (empty($img_code)) || (getCodeLength() == '0')) {
                // Stop execution of function here because of over-sized code length
-               debug_report_bug(__FUNCTION__, __LINE__, 'img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length'));
+               debug_report_bug(__FUNCTION__, __LINE__, 'img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getCodeLength());
        } elseif ($headerSent === false) {
                // Return an HTML code here
                return '<img src="{%url=img.php?code=' . $img_code . '%}" alt="Image" />';
@@ -778,26 +778,24 @@ function generateImageOrCode ($img_code, $headerSent = true) {
        $img = sprintf("%s/theme/%s/images/code_bg.%s",
                getPath(),
                getCurrentTheme(),
-               getConfig('img_type')
+               getImgType()
        );
 
        // Is it readable?
        if (isFileReadable($img)) {
                // Switch image type
-               switch (getConfig('img_type')) {
-                       case 'jpg':
-                               // Okay, load image and hide all errors
+               switch (getImgType()) {
+                       case 'jpg': // Okay, load image and hide all errors
                                $image = imagecreatefromjpeg($img);
                                break;
 
-                       case 'png':
-                               // Okay, load image and hide all errors
+                       case 'png': // Okay, load image and hide all errors
                                $image = imagecreatefrompng($img);
                                break;
                } // END - switch
        } else {
-               // Exit function here
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image type %s not found.", getConfig('img_type')));
+               // Silently log the error
+               logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image-type %s in theme %s not found.", getImgType(), getCurrentTheme()));
                return;
        }
 
@@ -808,10 +806,10 @@ function generateImageOrCode ($img_code, $headerSent = true) {
        imagestring($image, 5, 14, 2, $img_code, $text_color);
 
        // Return to browser
-       setContentType('image/' . getConfig('img_type'));
+       setContentType('image/' . getImgType());
 
        // Output image with matching image factory
-       switch (getConfig('img_type')) {
+       switch (getImgType()) {
                case 'jpg': imagejpeg($image); break;
                case 'png': imagepng($image);  break;
        } // END - switch
@@ -1097,28 +1095,28 @@ function generateEmailLink ($email, $table = 'admins') {
 // Output error messages in a fasioned way and die...
 function app_die ($F, $L, $message) {
        // Check if Script is already dieing and not let it kill itself another 1000 times
-       if (!isset($GLOBALS['app_died'])) {
-               // Make sure, that the script realy realy diese here and now
-               $GLOBALS['app_died'] = true;
+       if (isset($GLOBALS['app_died'])) {
+               // Script tried to kill itself twice
+               die('[' . __FUNCTION__ . ':' . __LINE__ . ']: Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L);
+       } // END - if
 
-               // Set content type as text/html
-               setContentType('text/html');
+       // Make sure, that the script realy realy diese here and now
+       $GLOBALS['app_died'] = true;
 
-               // Load header
-               loadIncludeOnce('inc/header.php');
+       // Set content type as text/html
+       setContentType('text/html');
 
-               // Rewrite message for output
-               $message = sprintf(getMessage('MAILER_HAS_DIED'), basename($F), $L, $message);
+       // Load header
+       loadIncludeOnce('inc/header.php');
 
-               // Load the message template
-               loadTemplate('app_die_message', false, $message);
+       // Rewrite message for output
+       $message = sprintf(getMessage('MAILER_HAS_DIED'), basename($F), $L, $message);
 
-               // Load footer
-               loadIncludeOnce('inc/footer.php');
-       } else {
-               // Script tried to kill itself twice
-               die('['.__FUNCTION__.':'.__LINE__.']: Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L);
-       }
+       // Load the message template
+       loadTemplate('app_die_message', false, $message);
+
+       // Load footer
+       loadIncludeOnce('inc/footer.php');
 }
 
 // Display parsing time and number of SQL queries in footer
@@ -1325,7 +1323,7 @@ function linenumberCode ($code)    {
 
                // Add code
                $r .= '<span class="linetext">' . encodeEntities($c) . '</span></div>';
-       }
+       } // END - foreach
 
        return '<div class="code">' . $r . '</div>';
 }
@@ -1464,6 +1462,9 @@ function escapeJavaScriptQuotes ($str) {
 // Send out mails depending on the 'mod/modes' combination
 // @TODO Lame description for this function
 function sendModeMails ($mod, $modes) {
+       // Init user data
+       $content = array ();
+
        // Load hash
        if (fetchUserData(getMemberId())) {
                // Extract salt from cookie
@@ -1527,45 +1528,43 @@ function sendModeMails ($mod, $modes) {
                                        $sub_mem = '{--MEMBER_CHANGED_DATA--}';
 
                                        // Output success message
-                                       $content = '<span class="message">{--MEMBER_MYDATA_MAIL_SENT--}</span>';
+                                       $content['message'] = '<span class="message">{--MEMBER_MYDATA_MAIL_SENT--}</span>';
                                        break;
 
                                default: // Unsupported module!
                                        logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported module %s detected.", $mod));
-                                       $content = '<span class="notice">{--UNKNOWN_MODULE--}</span>';
+                                       $content['message'] = '<span class="notice">{--UNKNOWN_MODULE--}</span>';
                                        break;
                        } // END - switch
                } else {
                        // Passwords mismatch
-                       $content = '<span class="notice">{--MEMBER_PASSWORD_ERROR--}</span>';
+                       $content['message'] = '<span class="notice">{--MEMBER_PASSWORD_ERROR--}</span>';
                }
        } else {
                // Could not load profile
-               $content = '<span class="notice">{--MEMBER_CANNOT_LOAD_PROFILE--}</span>';
+               $content['message'] = '<span class="notice">{--MEMBER_CANNOT_LOAD_PROFILE--}</span>';
        }
 
        // Send email to user if required
-       if ((!empty($sub_mem)) && (!empty($message))) {
+       if ((!empty($sub_mem)) && (!empty($message)) && (!empty($content['email']))) {
                // Send member mail
                sendEmail($content['email'], $sub_mem, $message);
        } // END - if
 
        // Send only if no other error has occured
-       if (empty($content)) {
-               if ((!empty($sub_adm)) && (!empty($message_admin))) {
-                       // Send admin mail
-                       sendAdminNotification($sub_adm, $message_admin, $content, getMemberId());
-               } elseif (isAdminNotificationEnabled()) {
-                       // Cannot send mails to admin!
-                       $content = '{--CANNOT_SEND_ADMIN_MAILS--}';
-               } else {
-                       // No mail to admin
-                       $content = '<span class="message">{--MEMBER_MYDATA_MAIL_SENT--}</span>';
-               }
-       } // END - if
+       if ((!empty($sub_adm)) && (!empty($message_admin)) && (isAdminNotificationEnabled())) {
+               // Send admin mail
+               sendAdminNotification($sub_adm, $message_admin, $content, getMemberId());
+       } elseif (isAdminNotificationEnabled()) {
+               // Cannot send mails to admin!
+               $content['message'] = '{--CANNOT_SEND_ADMIN_MAILS--}';
+       } else {
+               // No mail to admin
+               $content['message'] = '<span class="message">{--MEMBER_MYDATA_MAIL_SENT--}</span>';
+       }
 
        // Load template
-       loadTemplate('admin_settings_saved', false, $content);
+       loadTemplate('admin_settings_saved', false, $content['message']);
 }
 
 // Generates a 'selection box' from given array
@@ -1576,12 +1575,12 @@ function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionCo
 
        // Walk through all options
        foreach ($options as $option) {
-               // Add the <option> entry
+               // Add the <option> entry from ...
                if (empty($optionContent)) {
-                       // ... from template
+                       // ... template
                        $OUT .= loadTemplate('select_' . $name . $extraName . '_option', true, $option);
                } else {
-                       // Direct HTML code
+                       // ... direct HTML code
                        $OUT .= '<option value="' . $option[$optionValue] . '">' . $option[$optionContent] . '</option>';
                }
        } // END - foreach
@@ -1696,7 +1695,7 @@ function doTemplateColorSwitch ($template, $clear = false, $return = true) {
                // Switch color if called from loadTemplate()
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SWITCH:' . $template);
                $GLOBALS['color_switch'][$template] = 3 - $GLOBALS['color_switch'][$template];
-       } // END - if
+       }
 
        // Return CSS class name
        if ($return === true) {
index 6aed1f77e93d98e8cac2e98ca73fcc5c9dbaf368..74f30d01b012a6e43b215658adaa12cdbf630e72 100644 (file)
@@ -1867,6 +1867,30 @@ function getActivateXchange () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for img_type
+function getImgType () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('img_type');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for code_length
+function getCodeLength () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('code_length');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Checks wether proxy configuration is used
 function isProxyUsed () {
        // Do we have cache?
index ceb720dce3cf1c463a8eabd459c084dd60a89bd9..8b812839c4f142799e26bf750395e0c4a1d7a7f7 100644 (file)
@@ -176,7 +176,7 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr
                                                        $img_code = '0';
                                                        if (!empty($code)) {
                                                                // Generate code
-                                                               $img_code = generateRandomCode(getConfig('code_length'), $code, $userId, $urlId);
+                                                               $img_code = generateRandomCode(getCodeLength(), $code, $userId, $urlId);
                                                        } // END - if
 
                                                        // @TODO Rewrite this to a filter
@@ -316,7 +316,7 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr
                                                                                $content['type']   = $type;
                                                                                $content['data']   = $urlId;
                                                                                $content['banner'] = loadTemplate('mailid_banner', true);
-                                                                               if (getConfig('code_length') > 0) {
+                                                                               if (getCodeLength() > 0) {
                                                                                        // Generate Code
                                                                                        $content['image'] = generateCaptchaCode($code, $type, $urlId, $userId);
                                                                                        $templ = 'mailid_enter_code';