Ref link fixed, nickname fixed, several rewrites, TODOs.txt updated:
[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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif (!IS_MEMBER()) {
44         redirectToUrl('modules.php?module=index');
45 }
46
47 // Add description as navigation point
48 ADD_DESCR('member', __FILE__);
49
50 // Init output
51 $main_content = array();
52
53 // Load waiting/pending orders
54 $result = SQL_QUERY_ESC("SELECT id, cat_id, payment_id, subject, url, timestamp, target_send, data_type, zip
55 FROM `{!_MYSQL_PREFIX!}_pool`
56 WHERE sender=%s AND data_type != 'SEND'
57 ORDER BY timestamp DESC",
58 array(getUserId()), __FILE__, __LINE__);
59
60 // Are there mails left in pool?
61 if (SQL_NUMROWS($result) > 0) {
62         // Load all orders
63         $OUT = ''; $SW = 2;
64         while ($data = SQL_FETCHARRAY($result)) {
65                 // Is the ZIP code set? If not, set dashes
66                 if (empty($data['zip'])) $data['zip'] =  '---';
67
68                 // Prepare content for output
69                 $content = array(
70                         'sw'    => $SW,
71                         'id'    => $data['id'],
72                         'cat'   => getCategory($data['cat_id']),
73                         'pay'   => getPaymentTitlePrice($data['payment_id']),
74                         'subj'  => COMPILE_CODE($data['subject']),
75                         'url'   => DEREFERER($data['url']),
76                         'stamp' => generateDateTime($data['timestamp'], '2'),
77                         'recs'  => $data['target_send'],
78                         'type'  => translatePoolType($data['data_type']),
79                         'zip'   => $data['zip']
80                 );
81
82                 // Load template
83                 $OUT .= LOAD_TEMPLATE("member_pool_row", true, $content);
84
85                 // Switch color
86                 $SW = 3 - $SW;
87         } // END - if
88
89         // Load main template
90         $main_content['pool'] = LOAD_TEMPLATE("member_pool_table", true, $OUT);
91 } else {
92         // No mails in pool!
93         $main_content['pool'] = LOAD_TEMPLATE('admin_settings_saved', true, getMessage('MEMBER_NO_MAILS_IN_POOL'));
94 }
95
96 // Free result
97 SQL_FREERESULT($result);
98
99 // Load sent orders
100 $result = SQL_QUERY_ESC("SELECT
101         `id`, `cat_id`, `payment_id`, `subject`, `url`, `timestamp_ordered`, `max_rec`, `timestamp_send`, `clicks`
102 FROM
103         `{!_MYSQL_PREFIX!}_user_stats`
104 WHERE
105         `userid`=%s
106 ORDER BY
107         `timestamp_ordered` DESC",
108         array(getUserId()), __FILE__, __LINE__);
109
110 if (SQL_NUMROWS($result) > 0) {
111         // Mail orders are in pool so we can display them
112         $OUT = ''; $SW = 2;
113         while ($content = SQL_FETCHARRAY($result)) {
114                 // Prepare data for the template
115                 $content = array(
116                         'sw'    => $SW,
117                         'cat'   => getCategory($content['cat_id']),
118                         'pay'   => getPaymentTitlePrice($content['payment_id']),
119                         'subj'  => COMPILE_CODE($content['subject']),
120                         'url'   => DEREFERER($content['url']),
121                         'stamp' => generateDateTime($content['timestamp_ordered'], '2'),
122                         'recs'  => $content['max_rec'],
123                         'sent'  => generateDateTime($content['timestamp_send'], '2'),
124                         'clix'  => $content['clicks'],
125                         'perc'  => COMPILE_CODE($content['clicks'] / $content['max_rec'] * 100)."%",
126                 );
127
128                 // Load row template and switch colors
129                 $OUT .= LOAD_TEMPLATE('member_stats_row', true, $content);
130                 $SW = 3 - $SW;
131         }
132
133         // Load main template
134         $main_content['stats'] = LOAD_TEMPLATE('member_stats_table', true, $OUT);
135 } else {
136         // No mail orders fond
137         $main_content['stats'] = LOAD_TEMPLATE('admin_settings_saved', true, getMessage('MEMBER_NO_MAILS_IN_STATS'));
138 }
139
140 // Free result
141 SQL_FREERESULT($result);
142
143 // Load main template
144 LOAD_TEMPLATE('member_stats_pool', false, $main_content);
145
146 //
147 ?>