Fixed a comparison problem like string1 < string2
[mailer.git] / inc / modules / member / what-stats.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/09/2003 *
4  * ===============                              Last change: 04/21/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-stats.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Statistics over send mails                       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Statistik ueber gesendete Mails                  *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php?module=index");
40 }
41
42 // Add description as navigation point
43 ADD_DESCR("member", basename(__FILE__));
44
45 // Load waiting/pending orders
46 $result = SQL_QUERY_ESC("SELECT id, cat_id, payment_id, subject, url, timestamp, target_send, data_type, zip
47 FROM "._MYSQL_PREFIX."_pool
48 WHERE sender=%s AND data_type != 'SEND'
49 ORDER BY timestamp DESC",
50         array($GLOBALS['userid']), __FILE__, __LINE__);
51
52 // Are there mails left in pool?
53 if (SQL_NUMROWS($result) > 0) {
54         // Load all orders
55         $OUT = ""; $SW = 2;
56         while ($data = SQL_FETCHARRAY($result)) {
57                 // Is the ZIP code set? If not, set dashes
58                 if (empty($data['zip'])) $data['zip'] =  "---";
59
60                 // Prepare content for output
61                 $content = array(
62                         'sw'    => $SW,
63                         'id'    => $data['id']
64                         'cat'   => GET_CATEGORY($data['cat_id']),
65                         'pay'   => GET_PAYMENT($data['payment_id']),
66                         'subj'  => COMPILE_CODE($data['subject']),
67                         'url'   => DEREFERER($data['url']),
68                         'stamp' => MAKE_DATETIME($data['timestamp'], "0"),
69                         'recs'  => $data['target_send'],
70                         'type'  => TRANSLATE_POOL_TYPE($data['data_type']),
71                         'zip'   => bigintval($data['zip'])
72                 );
73
74                 // Load template
75                 $OUT .= LOAD_TEMPLATE("member_pool_row", true, $content);
76
77                 // Switch color
78                 $SW = 3 - $SW;
79         } // END - if
80
81         // Load main template
82         LOAD_TEMPLATE("member_pool", false, $OUT);
83 } else {
84         // No mails in pool!
85         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_NO_MAILS_IN_POOL);
86 }
87
88 // Free result
89 SQL_FREERESULT($result);
90
91 // Load sent orders
92 //                               0     1         2         3      4            5            6            7           8
93 $result = SQL_QUERY_ESC("SELECT id, cat_id, payment_id, subject, url, timestamp_ordered, max_rec, timestamp_send, clicks
94 FROM "._MYSQL_PREFIX."_user_stats
95 WHERE userid=%s
96 ORDER BY timestamp_ordered DESC",
97         array($GLOBALS['userid']), __FILE__, __LINE__);
98
99 if (SQL_NUMROWS($result) > 0) {
100         // Mail orders are in pool so we can display them
101         $SW = 2; $OUT = "";
102         while ($data = SQL_FETCHROW($result)) {
103                 // Prepare data for the template
104                 $content = array(
105                         'sw'    => $SW,
106                         'cat'   => GET_CATEGORY($data[1]),
107                         'pay'   => GET_PAYMENT($data[2]),
108                         'subj'  => COMPILE_CODE($data[3]),
109                         'url'   => DEREFERER($data[4]),
110                         'stamp' => MAKE_DATETIME($data[5], "0"),
111                         'recs'  => $data[6],
112                         'sent'  => MAKE_DATETIME($data[7], "0"),
113                         'clix'  => $data[8],
114                         'perc'  => COMPILE_CODE($data[8] / $data[6] * 100)."%",
115                 );
116
117                 // Load row template and switch colors
118                 $OUT .= LOAD_TEMPLATE("member_stats_row", true, $content);
119                 $SW = 3 - $SW;
120         }
121
122         // Remember rows in template
123         define('__STATS_ROWS', $OUT);
124
125         // Load main template
126         LOAD_TEMPLATE("member_stats_table");
127 } else {
128         // No mail orders fond
129         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_NO_MAILS_IN_STATS);
130 }
131
132 // Free result
133 SQL_FREERESULT($result);
134
135 //
136 ?>