Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / member / what-stats.php
index a6a9468d838d0721da798c0921bfe03805bee606..9c62bc4fd2338fc2f8bd23a4df2b26620afa8b0f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 11/09/2003 *
- * ===============                              Last change: 04/21/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 11/09/2003 *
+ * ===================                          Last change: 04/21/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-stats.php                                   *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Statistik ueber gesendete Mails                  *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-} elseif (!IS_LOGGED_IN()) {
-       LOAD_URL("modules.php?module=index");
+if (!defined('__SECURITY')) {
+       exit();
+} elseif (!isMember()) {
+       redirectToIndexMemberOnlyModule();
 }
 
 // Add description as navigation point
-ADD_DESCR("member", basename(__FILE__));
+addYouAreHereLink('member', __FILE__);
+
+// Init output
+$main_content = array();
 
 // Load waiting/pending orders
-$result = SQL_QUERY_ESC("SELECT id, cat_id, payment_id, subject, url, timestamp, target_send, data_type, zip
-FROM "._MYSQL_PREFIX."_pool
-WHERE sender=%d AND data_type != 'SEND'
-ORDER BY timestamp DESC",
-       array($GLOBALS['userid']), __FILE__, __LINE__);
+$result = sqlQueryEscaped("SELECT
+       `id`,
+       `cat_id`,
+       `payment_id`,
+       `subject`,
+       `url`,
+       `timestamp`,
+       `target_send`,
+       `data_type`,
+       `zip`
+FROM
+       `{?_MYSQL_PREFIX?}_pool`
+WHERE
+       `sender`=%s AND
+       `data_type` != 'SEND'
+ORDER BY
+       `timestamp` DESC",
+       array(getMemberId()), __FILE__, __LINE__);
 
 // Are there mails left in pool?
-if (SQL_NUMROWS($result) > 0) {
+if (!ifSqlHasZeroNumRows($result)) {
        // Load all orders
-       $OUT = ""; $SW = 2;
-       while ($data = SQL_FETCHARRAY($result)) {
-               // Is the ZIP code set? If not, set dashes
-               if (empty($data['zip'])) $data['zip'] =  "---";
-
+       $OUT = '';
+       while ($content = sqlFetchArray($result)) {
                // Prepare content for output
-               $content = array(
-                       'sw'    => $SW,
-                       'id'    => $data['id']
-                       'cat'   => GET_CATEGORY($data['cat_id']),
-                       'pay'   => GET_PAYMENT($data['payment_id']),
-                       'subj'  => COMPILE_CODE($data['subject']),
-                       'url'   => DEREFERER($data['url']),
-                       'stamp' => MAKE_DATETIME($data['timestamp'], "0"),
-                       'recs'  => $data['target_send'],
-                       'type'  => TRANSLATE_POOL_TYPE($data['data_type']),
-                       'zip'   => bigintval($data['zip'])
-               );
+               $content['timestamp'] = generateDateTime($content['timestamp'], '2');
 
                // Load template
-               $OUT .= LOAD_TEMPLATE("member_pool_row", true, $content);
-
-               // Switch color
-               $SW = 3 - $SW;
+               $OUT .= loadTemplate('member_pool_row', TRUE, $content);
        } // END - if
 
        // Load main template
-       LOAD_TEMPLATE("member_pool", false, $OUT);
+       $main_content['pool'] = loadTemplate('member_pool_table', TRUE, $OUT);
 } else {
        // No mails in pool!
-       LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_NO_MAILS_IN_POOL);
+       $main_content['pool'] = returnMessage('{--MEMBER_NO_MAILS_IN_POOL--}');
 }
 
 // Free result
-SQL_FREERESULT($result);
+sqlFreeResult($result);
 
 // Load sent orders
-//                               0     1         2         3      4            5            6            7           8
-$result = SQL_QUERY_ESC("SELECT id, cat_id, payment_id, subject, url, timestamp_ordered, max_rec, timestamp_send, clicks
-FROM "._MYSQL_PREFIX."_user_stats
-WHERE userid=%d
-ORDER BY timestamp_ordered DESC",
-       array($GLOBALS['userid']), __FILE__, __LINE__);
-
-if (SQL_NUMROWS($result) > 0) {
+$result = sqlQueryEscaped('SELECT
+       `id`,
+       `cat_id`,
+       `payment_id`,
+       `subject`,
+       `url`,
+       `timestamp_ordered`,
+       `max_rec`,
+       `timestamp_send`,
+       `clicks`
+FROM
+       `{?_MYSQL_PREFIX?}_user_stats`
+WHERE
+       `userid`=%s
+ORDER BY
+       `timestamp_ordered` DESC',
+       array(getMemberId()), __FILE__, __LINE__);
+
+if (!ifSqlHasZeroNumRows($result)) {
        // Mail orders are in pool so we can display them
-       $SW = 2; $OUT = "";
-       while ($data = SQL_FETCHROW($result)) {
+       $OUT = '';
+       while ($content = sqlFetchArray($result)) {
                // Prepare data for the template
-               $content = array(
-                       'sw'    => $SW,
-                       'cat'   => GET_CATEGORY($data[1]),
-                       'pay'   => GET_PAYMENT($data[2]),
-                       'subj'  => COMPILE_CODE($data[3]),
-                       'url'   => DEREFERER($data[4]),
-                       'stamp' => MAKE_DATETIME($data[5], "0"),
-                       'recs'  => $data[6],
-                       'sent'  => MAKE_DATETIME($data[7], "0"),
-                       'clix'  => $data[8],
-                       'perc'  => COMPILE_CODE($data[8] / $data[6] * 100)."%",
-               );
+               $content['timestamp_ordered'] = generateDateTime($content['timestamp_ordered'], '2');
+               $content['timestamp_sent']    = generateDateTime($content['timestamp_send'], '2');
 
-               // Load row template and switch colors
-               $OUT .= LOAD_TEMPLATE("member_stats_row", true, $content);
-               $SW = 3 - $SW;
-       }
+               // Click rate
+               $content['click_rate'] = calculatePercentageRate($content['clicks'], $content['max_rec']);
 
-       // Remember rows in template
-       define('__STATS_ROWS', $OUT);
+               // Load row template and switch colors
+               $OUT .= loadTemplate('member_stats_row', TRUE, $content);
+       } // END - while
 
        // Load main template
-       LOAD_TEMPLATE("member_stats_table");
+       $main_content['stats'] = loadTemplate('member_stats_table', TRUE, $OUT);
 } else {
        // No mail orders fond
-       LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_NO_MAILS_IN_STATS);
+       $main_content['stats'] = returnMessage('{--MEMBER_NO_MAILS_IN_STATS--}');
 }
 
 // Free result
-SQL_FREERESULT($result);
+sqlFreeResult($result);
+
+// Load main template
+loadTemplate('member_stats_pool', FALSE, $main_content);
 
-//
+// [EOF]
 ?>