Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-surfbar_stats.php
index f9e34b061ad4656faed06d1ebf0585f10e99e710..aca6624c8a7d1579528489c64a05077d1c38f690 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 09/09/2008 *
- * ================                             Last change: 09/09/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 09/09/2008 *
+ * ===================                          Last change: 09/09/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-surfbar_stats.php                           *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : URL-Statistiken fuer die Surfbar                 *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
  ************************************************************************/
 
 // Some security stuff...
-if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
 
 // Add description as navigation point
-ADD_DESCR("admin", __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
 // Is the 'url_id' set?
-if (isset($_GET['url_id'])) {
+if (isGetRequestElementSet('url_id')) {
        // Generate general statistics
-       $result = SQL_QUERY_ESC("SELECT `userid`, `count` AS `total_visits`, UNIX_TIMESTAMP(`last_online`) AS `last_online`
-FROM `"._MYSQL_PREFIX."_surfbar_stats`
-WHERE `url_id`=%s
-ORDER BY `userid` ASC",
-               array(bigintval($_GET['url_id'])), __FILE__, __LINE__);
+       $result = sqlQueryEscaped("SELECT
+       `stats_userid`,
+       `stats_count` AS `total_visits`,
+       UNIX_TIMESTAMP(`stats_last_surfed`) AS `last_surfed`
+FROM
+       `{?_MYSQL_PREFIX?}_surfbar_stats`
+WHERE
+       `stats_url_id`=%s
+ORDER BY
+       `stats_userid` ASC",
+               array(bigintval(getRequestElement('url_id'))), __FILE__, __LINE__);
 
        // Entries found?
-       if (SQL_NUMROWS($result) > 0) {
+       if (!ifSqlHasZeroNumRows($result)) {
                // Get all rows
-               $OUT = ""; $SW = 2; $cnt = 0; $visits = 0;
-               while ($content = SQL_FETCHARRAY($result)) {
+               $OUT = ''; $count = '0'; $visits = '0';
+               while ($content = sqlFetchArray($result)) {
                        // Count totals
                        $visits += $content['total_visits'];
 
                        // "Translate" some data
-                       $content['userid']       = ADMIN_USER_PROFILE_LINK($content['userid']);
-                       $content['total_visits'] = TRANSLATE_COMMA($content['total_visits']);
-                       $content['last_online']  = MAKE_DATETIME($content['last_online'], "2");
-                       $content['sw']           = $SW;
+                       $content['last_surfed']  = generateDateTime($content['last_surfed'], 2);
 
                        // Load row template
-                       $OUT .= LOAD_TEMPLATE("admin_surfbar_url_stats_row", true, $content);
-                       $cnt++; $SW = 3 - $SW;
+                       $OUT .= loadTemplate('admin_surfbar_url_stats_row', TRUE, $content);
+                       $count++;
                } // END - while
 
                // Prepare content
                $content = array(
                        'rows'    => $OUT,
-                       'userids' => $cnt,
+                       'userids' => $count,
                        'visits'  => $visits
                );
 
 
                // Load main template
-               LOAD_TEMPLATE("admin_surfbar_url_stats", false, $content);
+               loadTemplate('admin_surfbar_url_stats', FALSE, $content);
        } else {
                // No statistics so far
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SURFBAR_NO_URL_STATS);
+               displayMessage('{--ADMIN_SURFBAR_NO_URL_STATS--}');
        }
 } else {
        // Generate general statistics
-       $result = SQL_QUERY("SELECT `userid`, COUNT(`url_id`) AS `visited_urls`, SUM(`count`) AS `total_visits`
-FROM `"._MYSQL_PREFIX."_surfbar_stats`
-GROUP BY `userid`
-ORDER BY `userid` ASC", __FILE__, __LINE__);
+       $result = sqlQuery("SELECT
+       `stats_userid`,
+       COUNT(`stats_url_id`) AS `visited_urls`,
+       SUM(`stats_count`) AS `total_visits`
+FROM
+       `{?_MYSQL_PREFIX?}_surfbar_stats`
+GROUP BY
+       `stats_userid`
+ORDER BY
+       `stats_userid` ASC", __FILE__, __LINE__);
 
        // Entries found?
-       if (SQL_NUMROWS($result) > 0) {
+       if (!ifSqlHasZeroNumRows($result)) {
                // Get all rows
-               $OUT = ""; $SW = 2; $urls = 0; $visits = 0;
-               while ($content = SQL_FETCHARRAY($result)) {
+               $OUT = ''; $urlArray = '0'; $visits = '0';
+               while ($content = sqlFetchArray($result)) {
                        // Count totals
-                       $urls   += $content['visited_urls'];
-                       $visits += $content['total_visits'];
-
-                       // "Translate" some data
-                       $content['userid']       = ADMIN_USER_PROFILE_LINK($content['userid']);
-                       $content['visited_urls'] = TRANSLATE_COMMA($content['visited_urls']);
-                       $content['total_visits'] = TRANSLATE_COMMA($content['total_visits']);
-                       $content['sw']           = $SW;
+                       $urlArray += $content['visited_urls'];
+                       $visits   += $content['total_visits'];
 
                        // Load row template
-                       $OUT .= LOAD_TEMPLATE("admin_surfbar_stats_row", true, $content);
-                       $SW = 3 - $SW;
+                       $OUT .= loadTemplate('admin_surfbar_stats_row', TRUE, $content);
                } // END - while
 
                // Prepare content
                $content = array(
                        'rows'   => $OUT,
-                       'urls'   => $urls,
+                       'urls'   => $urlArray,
                        'visits' => $visits
                );
 
 
                // Load main template
-               LOAD_TEMPLATE("admin_surfbar_stats", false, $content);
+               loadTemplate('admin_surfbar_stats', FALSE, $content);
        } else {
                // No statistics so far
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SURFBAR_NO_STATS);
+               displayMessage('{--ADMIN_SURFBAR_NO_STATS--}');
        }
 }
 
 // Free result
-SQL_FREERESULT($result);
+sqlFreeResult($result);
 
-//
+// [EOF]
 ?>