A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / guest / what-sponsor_infos.php
index a4723fd..2539e16 100644 (file)
@@ -42,8 +42,9 @@ if (!defined('__SECURITY')) {
 // Add description as navigation point
 ADD_DESCR("guest", __FILE__);
 
-// Remove result_act
-unset($result_act);
+// Init both results (see footer of this file)
+$result_act = false;
+$result_pay = false;
 
 // Load all sponsor actions
 $result_act = SQL_QUERY("SELECT DISTINCT m.title, c.conv_rate, c.conv_name
@@ -52,18 +53,18 @@ LEFT JOIN `{!_MYSQL_PREFIX!}_sponsor_action_convert` AS c ON m.what=c.ext_name
 LEFT JOIN `{!_MYSQL_PREFIX!}_sponsor_registry` AS r ON m.what=r.ext_name
 WHERE m.action='actions' AND r.is_active='Y'
 ORDER BY m.sort ASC", __FILE__, __LINE__);
-$num_act = SQL_NUMROWS($result_act);
 
-if ($num_act > 0) {
+if (SQL_NUMROWS($result_act) > 0) {
        // Load all actions
        $OUT_ACT = ""; $SW = 2;
-       while (list($title, $conv, $name) = SQL_FETCHROW($result_act)) {
+       while ($content = SQL_FETCHARRAY($result_act)) {
                // Prepare data for the row template
+               // @TODO Rewritings: conv->conv_rate,name->conv_name in template
                $content = array(
                        'sw'    => $SW,
-                       'title' => $title,
-                       'conv'  => round($conv),
-                       'name'  => $name,
+                       'title' => $content['title'],
+                       'conv'  => round($content['conv_rate']),
+                       'name'  => $content['conv_name'],
                );
 
                // Load row template and switch color
@@ -76,15 +77,16 @@ if ($num_act > 0) {
        if (SQL_NUMROWS($result_pay) > 0) {
                // Load all pay types
                $OUT_PAY = ""; $SW = 2;
-               while (list($name, $rate, $min, $curr) = SQL_FETCHROW($result_pay)) {
+               while ($content = SQL_FETCHARRAY($result_pay)) {
                        // Prepare data for the row template
+                       // @TODO Rewritings: name->pay_name,min->pay_min_count,min->pay_min_count,curr->pay_currency
                        $content = array(
                                'sw'    => $SW,
-                               'name'  => $name,
-                               'rate'  => TRANSLATE_COMMA($rate),
-                               'min'   => $min,
-                               'curr'  => $curr,
-                               'price' => TRANSLATE_COMMA($min),
+                               'name'  => $content['pay_name'],
+                               'rate'  => TRANSLATE_COMMA($content['pay_rate']),
+                               'min'   => $content['pay_min_count'],
+                               'curr'  => $content['pay_currency'],
+                               'price' => TRANSLATE_COMMA($content['pay_min_count']),
                        );
 
                        // Load row template and switch color
@@ -93,30 +95,26 @@ if ($num_act > 0) {
                }
        } else {
                // No pay types setuped so far!
-               $OUT_PAY = "<tr><td colspan=\"2\">
-  ".LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_NO_ACTIONS_ACTIVATED)."
-</td></tr>";
+               $OUT_PAY = LOAD_TEMPLATE("guest_sponsor_infos_none_row", LOAD_TEMPLATE("admin_settings_saved", true, getMessage('SPONSOR_NO_ACTIONS_ACTIVATED')));
        }
 } else {
        // No actions activated so far!
-       $OUT_ACT = "<tr><td colspan=\"2\" class=\"bottom2\" style=\"padding-top: 10px; padding-bottom: 10px\">
-  ".LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_NO_ACTIONS_ACTIVATED)."
-</td></tr>";
-       $OUT_PAY = "<tr><td colspan=\"2\" class=\"bottom2\" style=\"padding-top: 10px; padding-bottom: 10px\">
-  ".LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_NO_ACTIONS_ACTIVATED)."
-</td></tr>";
+       $OUT_ACT = LOAD_TEMPLATE("guest_sponsor_infos_none_row", LOAD_TEMPLATE("admin_settings_saved", true, getMessage('SPONSOR_NO_ACTIONS_ACTIVATED')));
+       $OUT_PAY = LOAD_TEMPLATE("guest_sponsor_infos_none_row", LOAD_TEMPLATE("admin_settings_saved", true, getMessage('SPONSOR_NO_ACTIONS_ACTIVATED')));
 }
 
-// Transfer rows to constans
-define('__SPONSOR_ACTIONS' , $OUT_ACT);
-define('__SPONSOR_PAYTYPES', $OUT_PAY);
-
 // Free memory
-if (isset($result_act)) SQL_FREERESULT($result_act);
-if (isset($result_pay)) SQL_FREERESULT($result_pay);
+SQL_FREERESULT($result_act);
+SQL_FREERESULT($result_pay);
+
+// Transfer rows to an array
+$content = array(
+       'actions'  => $OUT_ACT,
+       'paytypes' => $OUT_PAY
+);
 
 // Load main template
-LOAD_TEMPLATE("guest_sponsor_infos");
+LOAD_TEMPLATE("guest_sponsor_infos", false, $content);
 
 //
 ?>