Several array indexes renamed, 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 - 2009 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         die();
42 } elseif (!isMember()) {
43         redirectToIndexMemberOnlyModule();
44 }
45
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
48
49 // Init output
50 $main_content = array();
51
52 // Load waiting/pending orders
53 $result = SQL_QUERY_ESC("SELECT id, cat_id, payment_id, subject, url, timestamp, target_send, data_type, zip
54 FROM `{?_MYSQL_PREFIX?}_pool`
55 WHERE sender=%s AND data_type != 'SEND'
56 ORDER BY timestamp DESC",
57 array(getUserId()), __FILE__, __LINE__);
58
59 // Are there mails left in pool?
60 if (SQL_NUMROWS($result) > 0) {
61         // Load all orders
62         $OUT = ''; $SW = 2;
63         while ($data = SQL_FETCHARRAY($result)) {
64                 // Is the ZIP code set? If not, set dashes
65                 if (empty($data['zip'])) $data['zip'] =  '---';
66
67                 // Prepare content for output
68                 // @TODO Rewrite in template subj->subject,stamp->timestamp,recs->target_send
69                 $content = array(
70                         'sw'      => $SW,
71                         'id'      => $data['id'],
72                         'cat'     => getCategory($data['cat_id']),
73                         'pay'     => getPaymentTitlePrice($data['payment_id']),
74                         'subject' => $data['subject'],
75                         'url'     => generateDerefererUrl($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 .= loadTemplate('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'] = loadTemplate('member_pool_table', true, $OUT);
91 } else {
92         // No mails in pool!
93         $main_content['pool'] = loadTemplate('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                 // @TODO Rewrite in template: stamp->timestamp_ordered,recs->max_rec,clix->clicks,perc->percents
116                 $content = array(
117                         'sw'       => $SW,
118                         'cat'      => getCategory($content['cat_id']),
119                         'pay'      => getPaymentTitlePrice($content['payment_id']),
120                         'url'      => generateDerefererUrl($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                         'subject'  => $content['subject'],
126                         'percents' => translateComma($content['clicks'] / $content['max_rec'] * 100)."%",
127                 );
128
129                 // Load row template and switch colors
130                 $OUT .= loadTemplate('member_stats_row', true, $content);
131                 $SW = 3 - $SW;
132         }
133
134         // Load main template
135         $main_content['stats'] = loadTemplate('member_stats_table', true, $OUT);
136 } else {
137         // No mail orders fond
138         $main_content['stats'] = loadTemplate('admin_settings_saved', true, getMessage('MEMBER_NO_MAILS_IN_STATS'));
139 }
140
141 // Free result
142 SQL_FREERESULT($result);
143
144 // Load main template
145 loadTemplate('member_stats_pool', false, $main_content);
146
147 // [EOF]
148 ?>