]> git.mxchange.org Git - mailer.git/blobdiff - inc/mysql-manager.php
Extension ext-repair extended, outdated calls DEBUG_LOG() fixed:
[mailer.git] / inc / mysql-manager.php
index cc9b9aedcab6bec531ef0606903b2ee46d9cbb70..b986d783baef83eb44ccdc717ba0f9a62040e1e0 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 08/26/2003 *
- * ===============                              Last change: 11/29/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 08/26/2003 *
+ * ===================                          Last change: 11/29/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : mysql-manager.php                                *
@@ -91,7 +91,7 @@ function getModuleTitle ($mod) {
 
 // "Getter" for module description
 // @TODO Can we cache this?
-function getModuleDescription ($mode, $what, $column = 'what') {
+function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') {
        // Fix empty 'what'
        if (empty($what)) {
                $what = getConfig('index_home');
@@ -101,8 +101,12 @@ function getModuleDescription ($mode, $what, $column = 'what') {
        $ret = '??? (' . $what . ')';
 
        // Look for title
-       $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' LIMIT 1",
-               array($mode, $column, $what), __FUNCTION__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `%s`='%s'" . $ADD . " LIMIT 1",
+               array(
+                       $mode,
+                       $column,
+                       $what
+               ), __FUNCTION__, __LINE__);
 
        // Is there an entry?
        if (SQL_NUMROWS($result) == 1) {
@@ -285,65 +289,52 @@ function checkModulePermissions ($mod = '') {
 }
 
 // Add menu description pending on given file name (without path!)
-function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = true) {
+function addMenuDescription ($accessLevel, $FQFN, $return = false) {
        // Use only filename of the FQFN...
        $file = basename($FQFN);
 
        // Init variables
        $LINK_ADD = '';
        $OUT = '';
-       $AND = '';
+       $ADD = '';
 
        // First we have to do some analysis...
        if (substr($file, 0, 7) == 'action-') {
                // This is an action file!
                $type = 'action';
                $search = substr($file, 7);
-               switch ($accessLevel) {
-                       case 'admin':
-                               $modCheck = 'admin';
-                               break;
-
-                       case 'sponsor':
-                       case 'guest':
-                       case 'member':
-                               $modCheck = getModule();
-                               break;
-               }
-               $AND = " AND (`what`='' OR `what` IS NULL)";
+
+               // Get access level from it
+               $modCheck = getModuleFromFileName($file, $accessLevel);
+
+               // Add what
+               $ADD = " AND (`what`='' OR `what` IS NULL)";
        } elseif (substr($file, 0, 5) == 'what-') {
-               // This is an admin what file!
+               // This is a 'what file'!
                $type = 'what';
                $search = substr($file, 5);
-               $AND = '';
-               switch ($accessLevel) {
-                       case 'admin':
-                               $modCheck = 'admin';
-                               break;
-
-                       case 'guest':
-                       case 'member':
-                               $modCheck = getModule();
-                               if (!isAdmin()) {
-                                       $AND = " AND `visible`='Y' AND `locked`='N'";
-                               }
-                               break;
-               }
+               $ADD = " AND `visible`='Y' AND `locked`='N'";
+
+               // Get access level from it
+               $modCheck = getModuleFromFileName($file, $accessLevel);
+
+               // Do we have admin? Then display all
+               if (isAdmin()) $ADD = '';
 
                $dummy = substr($search, 0, -4);
-               $AND .= " AND `action`='".getModeAction($accessLevel, $dummy)."'";
-       } elseif (($accessLevel == 'sponsor') || ($accessLevel == "engine")) {
+               $ADD .= " AND `action`='".getModeAction($accessLevel, $dummy)."'";
+       } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) {
                // Sponsor / engine menu
                $type     = 'what';
                $search   = $file;
                $modCheck = getModule();
-               $AND      = '';
+               $ADD      = '';
        } else {
                // Other
                $type     = 'menu';
                $search   = $file;
                $modCheck = getModule();
-               $AND      = '';
+               $ADD      = '';
        }
 
        // Begin the navigation line
@@ -363,48 +354,33 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru
                $search = substr($search, 0, -4);
        } // END - i
 
-       // Get the title from menu
-       $result = SQL_QUERY_ESC("SELECT title FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' ".$AND." LIMIT 1",
-       array($accessLevel, $type, $search), __FUNCTION__, __LINE__);
+       if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
+               // Output HTML code
+               $OUT = $prefix . "<strong><a class=\"you_are_here\" href=\"{?URL?}/modules.php?module=" . $modCheck . '&amp;' . $type . '=' . $search . $LINK_ADD . "\">" . getTitleFromMenu($accessLevel, $search, $type, $ADD) . "</a></strong>\n";
 
-       // Menu found?
-       if (SQL_NUMROWS($result) == 1) {
-               // Load title
-               list($ret) = SQL_FETCHROW($result);
+               // Can we close the you-are-here navigation?
+               //* DEBUG: */ print(__LINE__."*".$type.'/'.getWhat()."*<br />");
+               if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
+                       //* DEBUG: */ print(__LINE__.'+'.$type."+<br />");
+                       // Add closing div and br-tag
+                       $OUT .= "</div><br />\n";
+                       $GLOBALS['nav_depth'] = '0';
 
-               // Shall we return it?
-               if ($return === true) {
-                       // Return title
-                       return $ret;
-               } elseif (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
-                       // Output HTML code
-                       $OUT = $prefix . "<strong><a class=\"you_are_here\" href=\"{?URL?}/modules.php?module=" . $modCheck . '&amp;' . $type . '=' . $search.$LINK_ADD . "\">" . $ret . "</a></strong>\n";
-
-                       // Can we close the you-are-here navigation?
-                       //* DEBUG: */ print(__LINE__."*".$type.'/'.getWhat()."*<br />");
-                       if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
-                               //* DEBUG: */ print(__LINE__.'+'.$type."+<br />");
-                               // Add closing div and br-tag
-                               $OUT .= "</div><br />\n";
-                               $GLOBALS['nav_depth'] = '0';
-
-                               // Run the filter chain
-                               $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => ""));
-                               $OUT .= $ret['content'];
-                       } // END - if
-               }
-       } // END - if
+                       // Run the filter chain
+                       $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => ''));
 
-       // Free result
-       SQL_FREERESULT($result);
+                       // Add additional content
+                       $OUT .= $ret['content'];
+               } // END - if
+       }
 
        // Return or output HTML code?
-       if ($output) {
-               // Output HTML code here
-               outputHtml($OUT);
-       } else {
+       if ($return === true) {
                // Return HTML code
                return $OUT;
+       } else {
+               // Output HTML code here
+               outputHtml($OUT);
        }
 }
 
@@ -412,7 +388,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru
 function addMenu ($mode, $action, $what) {
        // Init some variables
        $main_cnt = '0';
-       $AND = '';
+       $ADD = '';
 
        // is the menu action valid?
        if (!isMenuActionValid($mode, $action, $what, true)) {
@@ -421,11 +397,11 @@ function addMenu ($mode, $action, $what) {
 
        // Non-admin shall not see all menus
        if (!isAdmin()) {
-               $AND = " AND `visible`='Y' AND `locked`='N'";
+               $ADD = " AND `visible`='Y' AND `locked`='N'";
        } // END - if
 
        // Load SQL data and add the menu to the output stream...
-       $result_main = SQL_QUERY_ESC("SELECT `title`, `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL)".$AND." ORDER BY `sort` ASC",
+       $result_main = SQL_QUERY_ESC("SELECT `title`, `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL)".$ADD." ORDER BY `sort` ASC",
                array($mode), __FUNCTION__, __LINE__);
 
        //* DEBUG: */ print(__LINE__.'/'.$main_cnt.':'.getWhat()."*<br />");
@@ -442,7 +418,7 @@ function addMenu ($mode, $action, $what) {
                        $GLOBALS['rows'] .= loadTemplate($mode . '_menu_title', true, $content);
 
                        // Sub menu
-                       $result_sub = SQL_QUERY_ESC("SELECT `title` AS sub_title, `what` AS sub_what FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$AND." ORDER BY `sort`",
+                       $result_sub = SQL_QUERY_ESC("SELECT `title` AS sub_title, `what` AS sub_what FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$ADD." ORDER BY `sort`",
                                array($mode, $content['action']), __FUNCTION__, __LINE__);
 
                        // Get number of rows
@@ -897,132 +873,26 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) {
        return $ret;
 }
 
-// Send out mails depending on the 'mod/modes' combination
-// @TODO Lame description for this function
-function sendModeMails ($mod, $modes) {
-       // Load hash
-       if (fetchUserData(getMemberId())) {
-               // Extract salt from cookie
-               $salt = substr(getSession('u_hash'), 0, -40);
-
-               // Now let's compare passwords
-               $hash = generatePassString(getUserData('password'));
-
-               // Does the hash match or should we change it?
-               if (($hash == getSession('u_hash')) || (postRequestElement('pass1') == postRequestElement('pass2'))) {
-                       // Load user's data               0        1        2         3        4      5    6      7
-                       $result = SQL_QUERY_ESC("SELECT gender, surname, family, street_nr, country, zip, city, email FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s AND password='%s' LIMIT 1",
-                               array(getMemberId(), getUserData('password')), __FUNCTION__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1) {
-                               // Load the data
-                               $content = SQL_FETCHARRAY($result, 0, false);
-
-                               // Free result
-                               SQL_FREERESULT($result);
-
-                               // Translate gender
-                               $content['gender'] = translateGender($content['gender']);
-
-                               // Clear/init the content variable
-                               $content['message'] = '';
-
-                               switch ($mod) {
-                                       case 'mydata':
-                                               foreach ($modes as $mode) {
-                                                       switch ($mode) {
-                                                               case 'normal': break; // Do not add any special lines
-                                                               case 'email': // Email was changed!
-                                                                       $content['message'] = getMessage('MEMBER_CHANGED_EMAIL').": ".postRequestElement('old_email')."\n";
-                                                                       break;
-
-                                                               case 'pass': // Password was changed
-                                                                       $content['message'] = getMessage('MEMBER_CHANGED_PASS')."\n";
-                                                                       break;
-
-                                                               default:
-                                                                       logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode));
-                                                                       $content['message'] = getMessage('MEMBER_UNKNOWN_MODE') . ': ' . $mode . "\n\n";
-                                                                       break;
-                                                       } // END - switch
-                                               } // END - foreach
-
-                                               if (isExtensionActive('country')) {
-                                                       // Replace code with description
-                                                       $content['country'] = generateCountryInfo(postRequestElement('country_code'));
-                                               } // END - if
-
-                                               // Merge content with data from POST
-                                               $content = merge_array($content, postRequestArray());
-
-                                               // Load template
-                                               $message = loadEmailTemplate('member_mydata_notify', $content, getMemberId());
-
-                                               if (getConfig('admin_notify') == 'Y') {
-                                                       // The admin needs to be notified about a profile change
-                                                       $message_admin = 'admin_mydata_notify';
-                                                       $sub_adm   = getMessage('ADMIN_CHANGED_DATA');
-                                               } else {
-                                                       // No mail to admin
-                                                       $message_admin = '';
-                                                       $sub_adm   = '';
-                                               }
-
-                                               // Set subject lines
-                                               $sub_mem = getMessage('MEMBER_CHANGED_DATA');
-
-                                               // Output success message
-                                               $content = "<span class=\"member_done\">{--MYDATA_MAIL_SENT--}</span>";
-                                               break;
-
-                                       default: // Unsupported module!
-                                               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported module %s detected.", $mod));
-                                               $content = "<span class=\"member_failed\">{--UNKNOWN_MODULE--}</span>";
-                                               break;
-                               } // END - switch
-                       } else {
-                               // Could not load profile data
-                               $content = "<span class=\"member_failed\">{--MEMBER_CANNOT_LOAD_PROFILE--}</span>";
-                       }
-               } else {
-                       // Passwords mismatch
-                       $content = "<span class=\"member_failed\">{--MEMBER_PASSWORD_ERROR--}</span>";
-               }
-       } else {
-               // Could not load profile
-               $content = "<span class=\"member_failed\">{--MEMBER_CANNOT_LOAD_PROFILE--}</span>";
-       }
-
-       // Send email to user if required
-       if ((!empty($sub_mem)) && (!empty($message))) {
-               // 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 (getConfig('admin_notify') == 'Y') {
-                       // Cannot send mails to admin!
-                       $content = getMessage('CANNOT_SEND_ADMIN_MAILS');
-               } else {
-                       // No mail to admin
-                       $content = "<span class=\"member_done\">{--MYDATA_MAIL_SENT--}</span>";
-               }
-       } // END - if
-
-       // Load template
-       loadTemplate('admin_settings_saved', false, $content);
-}
-
 // Get action value from mode (admin/guest/member) and what-value
 function getModeAction ($mode, $what) {
        // Init status
        $ret = '';
 
        //* DEBUG: */ print(__LINE__.'='.$mode.'/'.$what.'/'.getAction()."=<br />");
-       if ((empty($what)) && ($mode != 'admin')) {
+       if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
+               // sql_patches is missing so choose depending on mode
+               if (isWhatSet()) {
+                       // Use setted what
+                       $what = getWhat();
+               } elseif ($mode == 'admin') {
+                       // Admin area
+                       $what = 'overview';
+               } else {
+                       // Everywhere else
+                       $what = 'welcome';
+               }
+       } elseif ((empty($what)) && ($mode != 'admin')) {
+               // Use configured 'home'
                $what = getConfig('index_home');
        } // END - if
 
@@ -1062,7 +932,7 @@ function getModeAction ($mode, $what) {
 
                // Free memory
                SQL_FREERESULT($result);
-       } elseif ((!isExtensionInstalled('sql_patches')) && ($mode != 'admin')) {
+       } elseif ((!isExtensionInstalled('sql_patches')) && (($mode != 'admin') && ($mode != 'unknown'))) {
                // No sql_patches installed, but maybe we need to register an admin?
                if (isAdminRegistered()) {
                        // Redirect to admin area
@@ -1644,22 +1514,32 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher
        $ret = '';
        if ($table == '/ARRAY/') {
                // Selection from array
-               if (is_array($id) && is_array($name) && count($id) == count($name)) {
+               if ((is_array($id)) && (is_array($name)) && (count($id)) == (count($name))) {
                        // Both are arrays
                        foreach ($id as $idx => $value) {
                                $ret .= '<option value="' . $value . '"';
                                if ($default == $value) $ret .= ' selected="selected"';
                                $ret .= '>' . $name[$idx] . '</option>';
                        } // END - foreach
-               } // END - if
+               } else {
+                       // Problem in request
+                       debug_report_bug('Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name));
+               }
        } else {
                // Data from database
-               $SPEC = ', '.$id;
-               if (!empty($special)) $SPEC = ', ' . $special;
-               $ORDER = $name.$SPEC;
-               if ($table == 'country') $ORDER = $special;
-               $result = SQL_QUERY_ESC("SELECT %s, %s".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$where." ORDER BY %s",
-               array($id, $ORDER, $table, $name), __FUNCTION__, __LINE__);
+               $SPEC = ', `' . $id . '`';
+               if (!empty($special)) $SPEC = ', `' . $special . '`';
+
+               // Query the database
+               $result = SQL_QUERY_ESC("SELECT `%s`, `%s`".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$where." ORDER BY `%s` ASC",
+                       array(
+                               $id,
+                               $name,
+                               $table,
+                               $name
+                       ), __FUNCTION__, __LINE__);
+
+               // Do we have rows?
                if (SQL_NUMROWS($result) > 0) {
                        // Found data so add them as OPTION lines: $id is the value and $name is the "name" of the option
                        // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
@@ -1670,13 +1550,13 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher
                                if (!empty($add)) $add = ' ('.$add.')';
                                $ret .= '>' . $title . $add . '</option>';
                        } // END - while
-
-                       // Free memory
-                       SQL_FREERESULT($result);
                } else {
                        // No data found
                        $ret = '<option value="x">{--SELECT_NONE--}</option>';
                }
+
+               // Free memory
+               SQL_FREERESULT($result);
        }
 
        // Return - hopefully - the requested data
@@ -1733,7 +1613,7 @@ WHERE
                SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s", array(bigintval($userid)), __FUNCTION__, __LINE__);
 
                // Update mediadata as well
-               if (getExtensionVersion('mediadata') >= '0.0.4') {
+               if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
                        // Update database
                        updateMediadataEntry(array('total_points'), 'sub', $points);
                } // END - if
@@ -1768,7 +1648,7 @@ function generateMetaDescriptionCode ($mod, $what) {
        // Exclude admin and member's area
        if (($mod != 'admin') && ($mod != 'login')) {
                // Construct dynamic description
-               $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . addMenuDescription('guest', 'what-'.$what, true);
+               $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', $what);
 
                // Output it directly
                outputHtml('<meta name="description" content="' . $DESCR . '" />');
@@ -1869,7 +1749,10 @@ function generateCategoryOptionsList ($mode) {
        );
 
        // Get categories
-       $result = SQL_QUERY("SELECT id, cat FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort`", __FUNCTION__, __LINE__);
+       $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort` ASC",
+               __FUNCTION__, __LINE__);
+
+       // Do we have entries?
        if (SQL_NUMROWS($result) > 0) {
                // ... and begin loading stuff
                while ($content = SQL_FETCHARRAY($result)) {
@@ -1890,7 +1773,9 @@ function generateCategoryOptionsList ($mode) {
 FROM
        `{?_MYSQL_PREFIX?}_user_data`
 WHERE
-       `userid`=%s AND `status`='CONFIRMED' AND `receive_mails` > 0".runFilterChain('exclude_users', $mode)."
+       `userid`=%s AND
+       `status`='CONFIRMED' AND
+       `receive_mails` > 0".runFilterChain('exclude_users', $mode)."
 LIMIT 1",
                                        array(bigintval($ucat)), __FUNCTION__, __LINE__);
 
@@ -2222,7 +2107,7 @@ function reduceRecipientReceivedMails ($column, $id, $count) {
 function createNewTask ($subject, $notes, $taskType, $userid = '0', $adminId = '0', $strip = true) {
        // Insert the task data into the database
        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_task_system` (`assigned_admin`, `userid`, `status`, `task_type`, `subject`, `text`, `task_created`) VALUES (%s,%s,'NEW','%s','%s','%s', UNIX_TIMESTAMP())",
-               array($adminId, $userid, $taskType, $subject, addslashes($notes)), __FUNCTION__, __LINE__, true, $strip);
+               array($adminId, $userid, $taskType, $subject, escapeQuotes($notes)), __FUNCTION__, __LINE__, true, $strip);
 }
 
 // Updates last module / online time