A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / libs / sponsor_functions.php
index 4f2fd8fa348a89e073e73ef414dbc2d7a20035e9..31d010bf5697b1ab9aaabdf2f3685175c605e4cd 100644 (file)
@@ -272,31 +272,31 @@ function GENERATE_SPONSOR_MENU($current)
        if (IS_ADMIN()) $WHERE = "";
 
        // Load main menu entries
        if (IS_ADMIN()) $WHERE = "";
 
        // Load main menu entries
-       $result_main = SQL_QUERY("SELECT actiontitle FROM `{!_MYSQL_PREFIX!}_sponsor_menu`
+       $result_main = SQL_QUERY("SELECT action AS main_action, title AS main_title FROM `{!_MYSQL_PREFIX!}_sponsor_menu`
 WHERE (what='' OR `what` IS NULL) ".$WHERE."
 ORDER BY `sort`", __FUNCTION__, __LINE__);
 WHERE (what='' OR `what` IS NULL) ".$WHERE."
 ORDER BY `sort`", __FUNCTION__, __LINE__);
-       if (SQL_NUMROWS($result_main) > 0)
-       {
+       if (SQL_NUMROWS($result_main) > 0) {
                // Load every menu and it's sub menus
                // Load every menu and it's sub menus
-               while (list($action, $title_main) = SQL_FETCHROW($result_main))
-               {
+               while ($content = SQL_FETCHARRAY($result_main)) {
                        // Load sub menus
                        // Load sub menus
-                       $result_sub = SQL_QUERY_ESC("SELECT whattitle FROM `{!_MYSQL_PREFIX!}_sponsor_menu`
+                       $result_sub = SQL_QUERY_ESC("SELECT what AS sub_what, title AS sub_title FROM `{!_MYSQL_PREFIX!}_sponsor_menu`
 WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$WHERE."
 WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$WHERE."
-ORDER BY `sort`", array($action), __FUNCTION__, __LINE__);
-                       if (SQL_NUMROWS($result_sub) > 0)
-                       {
+ORDER BY `sort`",
+                               array($content['main_action']), __FUNCTION__, __LINE__);
+                       if (SQL_NUMROWS($result_sub) > 0) {
                                // Load sub menus
                                $SUB = "";
                                // Load sub menus
                                $SUB = "";
-                               while (list($what, $title_sub) = SQL_FETCHROW($result_sub))
-                               {
+                               while ($content2 = SQL_FETCHARRAY($result_sub)) {
+                                       // Merge both arrays
+                                       $content = merge_array($content, $content2);
+
                                        // Check if current selected menu is matching the loaded one
                                        // Check if current selected menu is matching the loaded one
-                                       if ($current == $what) $title_sub = "<strong>".$title_sub."</strong>";
+                                       if ($current == $content['sub_what']) $content['sub_title'] = "<strong>".$content['sub_title']."</strong>";
 
                                        // Prepare data for the sub template
                                        $content = array(
 
                                        // Prepare data for the sub template
                                        $content = array(
-                                               'what'  => $what,
-                                               'title' => $title_sub
+                                               'what'  => $content['sub_what'],
+                                               'title' => $content['sub_title']
                                        );
 
                                        // Load row template
                                        );
 
                                        // Load row template
@@ -305,27 +305,23 @@ ORDER BY `sort`", array($action), __FUNCTION__, __LINE__);
 
                                // Prepare data for the main template
                                $content = array(
 
                                // Prepare data for the main template
                                $content = array(
-                                       'title' => $title_main,
+                                       'title' => $content['main_title'],
                                        'menu'  => $SUB
                                );
 
                                // Load menu template
                                $OUT .= LOAD_TEMPLATE("sponsor_action", true, $content);
                                        'menu'  => $SUB
                                );
 
                                // Load menu template
                                $OUT .= LOAD_TEMPLATE("sponsor_action", true, $content);
-                       }
-                        else
-                       {
+                       } else {
                                // No sub menus active
                                // No sub menus active
-                               $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_NO_SUB_MENUS_ACTIVE);
+                               $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, getMessage('SPONSOR_NO_SUB_MENUS_ACTIVE'));
                        }
 
                        // Free memory
                        SQL_FREERESULT($result_sub);
                }
                        }
 
                        // Free memory
                        SQL_FREERESULT($result_sub);
                }
-       }
-        else
-       {
+       } else {
                // No main menus active
                // No main menus active
-               $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_NO_MAIN_MENUS_ACTIVE);
+               $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, getMessage('SPONSOR_NO_MAIN_MENUS_ACTIVE'));
        }
 
        // Free memory
        }
 
        // Free memory
@@ -334,9 +330,9 @@ ORDER BY `sort`", array($action), __FUNCTION__, __LINE__);
        // Return content
        return $OUT;
 }
        // Return content
        return $OUT;
 }
+
 //
 //
-function GENERATE_SPONSOR_CONTENT($what)
-{
+function GENERATE_SPONSOR_CONTENT ($what) {
        $OUT = "";
        $INC = sprintf("inc/modules/sponsor/%s.php", $what);
        if (INCLUDE_READABLE($INC)) {
        $OUT = "";
        $INC = sprintf("inc/modules/sponsor/%s.php", $what);
        if (INCLUDE_READABLE($INC)) {
@@ -344,12 +340,13 @@ function GENERATE_SPONSOR_CONTENT($what)
                LOAD_INC_ONCE($INC);
        } else {
                // File not found!
                LOAD_INC_ONCE($INC);
        } else {
                // File not found!
-               $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_CONTENT_404_1.$what.SPONSOR_CONTENT_404_2);
+               $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, sprintf(getMessage('SPONSOR_CONTENT_404'), $what));
        }
 
        // Return content
        return $OUT;
 }
        }
 
        // Return content
        return $OUT;
 }
+
 //
 function UPDATE_SPONSOR_LOGIN () {
        // Failed by default
 //
 function UPDATE_SPONSOR_LOGIN () {
        // Failed by default
@@ -380,7 +377,7 @@ function SPONSOR_SAVE_DATA ($POST, $content) {
                        'ok', 'pass1', 'pass2');
 
        // Set default message ("not saved")
                        'ok', 'pass1', 'pass2');
 
        // Set default message ("not saved")
-       $MSG = SPONSOR_ACCOUNT_DATA_NOT_SAVED;
+       $MSG = getMessage('SPONSOR_ACCOUNT_DATA_NOT_SAVED');
 
        // Check for submitted passwords
        if ((!empty($POST['pass1'])) && (!empty($POST['pass2']))) {
 
        // Check for submitted passwords
        if ((!empty($POST['pass1'])) && (!empty($POST['pass2']))) {
@@ -388,13 +385,13 @@ function SPONSOR_SAVE_DATA ($POST, $content) {
                if ($POST['pass1'] == $POST['pass2']) {
                        // Okay, then set password and remove pass1 and pass2
                        $POST['password'] = md5($POST['pass1']);
                if ($POST['pass1'] == $POST['pass2']) {
                        // Okay, then set password and remove pass1 and pass2
                        $POST['password'] = md5($POST['pass1']);
-               }
-       }
+               } // END - if
+       } // END - if
 
        // Remove all (maybe spoofed) unsafe data from array
        foreach ($UNSAFE as $remove) {
                unset($POST[$remove]);
 
        // Remove all (maybe spoofed) unsafe data from array
        foreach ($UNSAFE as $remove) {
                unset($POST[$remove]);
-       }
+       } // END - foreach
 
        // This array is for the submitted data which we will use with the SQL_QUERY_ESC() function to
        // secure the data
 
        // This array is for the submitted data which we will use with the SQL_QUERY_ESC() function to
        // secure the data
@@ -411,7 +408,7 @@ function SPONSOR_SAVE_DATA ($POST, $content) {
 
                // Compile {SLASH} and so on for the email templates
                $POST[$key] = COMPILE_CODE($value);
 
                // Compile {SLASH} and so on for the email templates
                $POST[$key] = COMPILE_CODE($value);
-       }
+       } // END - foreach
 
        // Check if email has changed
        if ((!empty($content['email'])) && (!empty($POST['email']))) {
 
        // Check if email has changed
        if ((!empty($content['email'])) && (!empty($POST['email']))) {
@@ -425,8 +422,8 @@ function SPONSOR_SAVE_DATA ($POST, $content) {
                        // Generate hash code
                        $HASH = md5(session_id().":".$POST['email'].":".GET_REMOTE_ADDR().":".GET_USER_AGENT().":".time());
                        $DATA[] = $HASH;
                        // Generate hash code
                        $HASH = md5(session_id().":".$POST['email'].":".GET_REMOTE_ADDR().":".GET_USER_AGENT().":".time());
                        $DATA[] = $HASH;
-               }
-       }
+               } // END - if
+       } // END - if
 
        // Remove last commata
        $sql = substr($sql, 0, -1);
 
        // Remove last commata
        $sql = substr($sql, 0, -1);
@@ -515,9 +512,9 @@ function SPONSOR_SAVE_DATA ($POST, $content) {
                                        SEND_EMAIL($content['email'], getMessage('SPONSOR_SETTINGS_SUBJ'), $email_msg);
                                        break;
                                }
                                        SEND_EMAIL($content['email'], getMessage('SPONSOR_SETTINGS_SUBJ'), $email_msg);
                                        break;
                                }
-                       }
-               }
-       }
+                       } // END - if
+               } // END - if
+       } // END - if
 
        // Return final message
        return $MSG;
 
        // Return final message
        return $MSG;