]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/guest/what-stats.php
A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / guest / what-stats.php
index 1be2f8e639d7ba4c9d80394136c4c5b9645ffe46..a26da2a721c6ef80f0e5b9c099fbcccb1a9e363f 100644 (file)
@@ -67,16 +67,16 @@ switch (getConfig('guest_stats'))
 {
 case "MEMBERS": // Statistics about your members
        // Members yesterday / today online
 {
 case "MEMBERS": // Statistics about your members
        // Members yesterday / today online
-       $ymem = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE last_online >= ".START_YDAY." AND last_online < ".START_TDAY." AND `status`='CONFIRMED'", __FILE__, __LINE__));
-       $tmem = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE last_online >= ".START_TDAY." AND `status`='CONFIRMED'", __FILE__, __LINE__));
+       $ymem = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE last_online >= ".constant('START_YDAY')." AND last_online < ".constant('START_TDAY')." AND `status`='CONFIRMED'", __FILE__, __LINE__));
+       $tmem = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE last_online >= ".constant('START_TDAY')." AND `status`='CONFIRMED'", __FILE__, __LINE__));
 
        // Yesterday / today registered
 
        // Yesterday / today registered
-       $yreg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".START_YDAY." AND joined < ".START_TDAY, __FILE__, __LINE__));
-       $treg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".START_TDAY, __FILE__, __LINE__));
+       $yreg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".constant('START_YDAY')." AND joined < ".constant('START_TDAY'), __FILE__, __LINE__));
+       $treg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".constant('START_TDAY'), __FILE__, __LINE__));
 
        // Only males / females
 
        // Only males / females
-       $male   = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE gender='M' AND `status`='CONFIRMED'", __FILE__, __LINE__));
-       $female = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE gender='F' AND `status`='CONFIRMED'", __FILE__, __LINE__));
+       $male   = GET_TOTAL_DATA("M", "user_data", "userid", "gender", true, " AND `status`='CONFIRMED'");
+       $female = GET_TOTAL_DATA("F", "user_data", "userid", "gender", true, " AND `status`='CONFIRMED'");
 
        // Unconfirmed accounts
        $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE status != 'CONFIRMED'", __FILE__, __LINE__));
 
        // Unconfirmed accounts
        $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE status != 'CONFIRMED'", __FILE__, __LINE__));
@@ -86,11 +86,15 @@ case "MEMBERS": // Statistics about your members
 
        // List every month
        $months = array();
 
        // List every month
        $months = array();
-       for ($idx = 1; $idx < 13; $idx++)
-       {
-               $month = $idx; if ($idx < 10) $month = "0".$idx;
-               $months[$month] = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE birth_month=%s AND `status`='CONFIRMED'",
-                array(bigintval($month)), __FILE__, __LINE__));
+       for ($idx = 1; $idx < 13; $idx++) {
+               // Copy it so we don't touch the for() loop index
+               $month = $idx;
+
+               // Append leading zero
+               if ($idx < 10) $month = "0".$idx;
+
+               // Count months
+               $months[$month] = GET_TOTAL_DATA(bigintval($month), "user_data", "userid", "birth_month", true, " AND `status`='CONFIRMED'");
        }
 
        // Members in categories
        }
 
        // Members in categories
@@ -98,19 +102,20 @@ case "MEMBERS": // Statistics about your members
 
        // Load categories first
        $cats = array(); $cat_cnt = array();
 
        // Load categories first
        $cats = array(); $cat_cnt = array();
-       while (list($id, $cat) = SQL_FETCHROW($result)) {
+       // @TODO This can be somehow rewritten
+       while ($content = SQL_FETCHARRAY($result)) {
                // Simple...
                // Simple...
-               $cats[$id] = $cat;
+               $cats[$content['id']] = $content['cat'];
        }
 
        // Now we have all categories loaded, count members
        foreach ($cats as $id => $dummy) {
                // We only need id and nothing more to count...
        }
 
        // Now we have all categories loaded, count members
        foreach ($cats as $id => $dummy) {
                // We only need id and nothing more to count...
-               $cat_cnt[$id] = SQL_NUMROWS(SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE cat_id=%s",
-                       array(bigintval($id)), __FILE__, __LINE__));
+               $cat_cnt[$id] = GET_TOTAL_DATA(bigintval($id), "user_cats", "id", "cat_id", true);
        }
 
        // Prepare data for the template
        }
 
        // Prepare data for the template
+       // @TODO Rewrite all these constants
        define('__TOTAL_USERS' , $total);
        define('__UNCONFIRMED' , $unconfirmed);
        define('__MALE_COUNT'  , $male);
        define('__TOTAL_USERS' , $total);
        define('__UNCONFIRMED' , $unconfirmed);
        define('__MALE_COUNT'  , $male);
@@ -124,8 +129,7 @@ case "MEMBERS": // Statistics about your members
 
        // Generate monthly stats
        $SW = 2; $r2 = " right2"; $l = "ll"; $r = "lr"; $OUT = "";
 
        // Generate monthly stats
        $SW = 2; $r2 = " right2"; $l = "ll"; $r = "lr"; $OUT = "";
-       foreach ($months as $month => $cnt)
-       {
+       foreach ($months as $month => $cnt) {
                if ($SW == 2) $OUT .= "<tr>\n";
 
                // Prepare data for template
                if ($SW == 2) $OUT .= "<tr>\n";
 
                // Prepare data for template
@@ -140,13 +144,10 @@ case "MEMBERS": // Statistics about your members
                // Load row template
                $OUT .= LOAD_TEMPLATE("guest_stats_month_row", true, $content);
 
                // Load row template
                $OUT .= LOAD_TEMPLATE("guest_stats_month_row", true, $content);
 
-               if ($SW == 2)
-               {
+               if ($SW == 2) {
                        $r2 = "";
                        $l = "rl"; $r = "rr";
                        $r2 = "";
                        $l = "rl"; $r = "rr";
-               }
-                else
-               {
+               } else {
                        $OUT .= "</tr>\n";
                        $r2 = " right2";
                        $l = "ll"; $r = "lr";
                        $OUT .= "</tr>\n";
                        $r2 = " right2";
                        $l = "ll"; $r = "lr";
@@ -156,9 +157,8 @@ case "MEMBERS": // Statistics about your members
        define('__MONTH_STATS_ROWS', $OUT);
 
        // Generate category stats
        define('__MONTH_STATS_ROWS', $OUT);
 
        // Generate category stats
-       $SW = 2; $OUT = "";
-       foreach ($cat_cnt as $id => $cnt)
-       {
+       $OUT = ""; $SW = 2;
+       foreach ($cat_cnt as $id => $cnt) {
                // Prepare data for the template
                $content = array(
                        'sw'  => $SW,
                // Prepare data for the template
                $content = array(
                        'sw'  => $SW,
@@ -181,8 +181,10 @@ case "MODULES": // TOP10 module clicks
        if (!IS_ADMIN()) $AND = " AND `locked`='N' AND `visible`='Y'";
        $guest_t10 = SQL_QUERY("SELECT counter, title FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE counter > 0".$AND." ORDER BY counter DESC LIMIT 0,10", __FILE__, __LINE__);
        $mem_t10   = SQL_QUERY("SELECT counter, title FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE counter > 0".$AND." ORDER BY counter DESC LIMIT 0,10", __FILE__, __LINE__);
        if (!IS_ADMIN()) $AND = " AND `locked`='N' AND `visible`='Y'";
        $guest_t10 = SQL_QUERY("SELECT counter, title FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE counter > 0".$AND." ORDER BY counter DESC LIMIT 0,10", __FILE__, __LINE__);
        $mem_t10   = SQL_QUERY("SELECT counter, title FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE counter > 0".$AND." ORDER BY counter DESC LIMIT 0,10", __FILE__, __LINE__);
+       $OUT = "";
        if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
                // Output header
        if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
                // Output header
+               // @TODO Rewrite this to one template and $OUT .= ....
                OUTPUT_HTML("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"guest_table dashed\" width=\"310\">
 <tr>
   <td align=\"center\" class=\"guest_stats_title bottom2\" colspan=\"2\"><strong>{--GUEST_TOPTEN_STATS--}</strong></td>
                OUTPUT_HTML("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"guest_table dashed\" width=\"310\">
 <tr>
   <td align=\"center\" class=\"guest_stats_title bottom2\" colspan=\"2\"><strong>{--GUEST_TOPTEN_STATS--}</strong></td>
@@ -195,10 +197,10 @@ case "MODULES": // TOP10 module clicks
   <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_GUEST_STATS--}</td>
 </tr>");
                $SW = 2;
   <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_GUEST_STATS--}</td>
 </tr>");
                $SW = 2;
-               while (list($clicks, $title) = SQL_FETCHROW($guest_t10)) {
+               while ($content = SQL_FETCHARRAY($guest_t10)) {
                        OUTPUT_HTML("<tr>
                        OUTPUT_HTML("<tr>
-  <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title."&nbsp;</td>
-  <td class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$clicks."</td>
+  <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$content['title']."&nbsp;</td>
+  <td class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$content['counter']."</td>
 </tr>");
                        $SW = 3 - $SW;
                }
 </tr>");
                        $SW = 3 - $SW;
                }
@@ -210,10 +212,10 @@ case "MODULES": // TOP10 module clicks
   <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_MEMBER_STATS--}</td>
 </tr>");
                $SW = 2;
   <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_MEMBER_STATS--}</td>
 </tr>");
                $SW = 2;
-               while (list($clicks, $title) = SQL_FETCHROW($mem_t10)) {
+               while ($content = SQL_FETCHARRAY($mem_t10)) {
                        OUTPUT_HTML("<tr>
                        OUTPUT_HTML("<tr>
-  <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title."&nbsp;</td>
-  <td class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$clicks."</td>
+  <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$content['title']."&nbsp;</td>
+  <td class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$content['counter']."</td>
 </tr>");
                        $SW = 3 - $SW;
                }
 </tr>");
                        $SW = 3 - $SW;
                }
@@ -222,7 +224,9 @@ case "MODULES": // TOP10 module clicks
        if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
                // Output footer
                OUTPUT_HTML("<tr>
        if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
                // Output footer
                OUTPUT_HTML("<tr>
-  <td align=\"center\" class=\"guest_stats_footer\" colspan=\"2\"><a href=\"{!URL!}/modules.php?module=index&amp;what=stats&amp;mode=".$lmode."\">".$ltitle."</a></td>
+  <td align=\"center\" class=\"guest_stats_footer\" colspan=\"2\">
+    <a href=\"{!URL!}/modules.php?module=index&amp;what=stats&amp;mode=".$lmode."\">".$ltitle."</a>
+  </td>
 </tr>
 </table>");
        }
 </tr>
 </table>");
        }