More rewrites, and output-mode fixed (we should documentate this)
[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
54         `id`, `cat_id`, `payment_id`, `subject`, `url`, `timestamp`, `target_send`, `data_type`, `zip`
55 FROM
56         `{?_MYSQL_PREFIX?}_pool`
57 WHERE
58         `sender`=%s AND `data_type` != 'SEND'
59 ORDER BY
60         `timestamp` DESC",
61         array(getUserId()), __FILE__, __LINE__);
62
63 // Are there mails left in pool?
64 if (SQL_NUMROWS($result) > 0) {
65         // Load all orders
66         $OUT = ''; $SW = 2;
67         while ($data = SQL_FETCHARRAY($result)) {
68                 // Is the ZIP code set? If not, set dashes
69                 if (empty($data['zip'])) $data['zip'] =  '---';
70
71                 // Prepare content for output
72                 $content = array(
73                         'sw'          => $SW,
74                         'id'          => $data['id'],
75                         'cat'         => getCategory($data['cat_id']),
76                         'pay'         => getPaymentTitlePrice($data['payment_id']),
77                         'subject'     => $data['subject'],
78                         'url'         => generateDerefererUrl($data['url']),
79                         'timestamp'   => generateDateTime($data['timestamp'], 2),
80                         'target_send' => $data['target_send'],
81                         'type'        => translatePoolType($data['data_type']),
82                         'zip'         => $data['zip']
83                 );
84
85                 // Load template
86                 $OUT .= loadTemplate('member_pool_row', true, $content);
87
88                 // Switch color
89                 $SW = 3 - $SW;
90         } // END - if
91
92         // Load main template
93         $main_content['pool'] = loadTemplate('member_pool_table', true, $OUT);
94 } else {
95         // No mails in pool!
96         $main_content['pool'] = loadTemplate('admin_settings_saved', true, getMessage('MEMBER_NO_MAILS_IN_POOL'));
97 }
98
99 // Free result
100 SQL_FREERESULT($result);
101
102 // Load sent orders
103 $result = SQL_QUERY_ESC("SELECT
104         `id`, `cat_id`, `payment_id`, `subject`, `url`, `timestamp_ordered`, `max_rec`, `timestamp_send`, `clicks`
105 FROM
106         `{?_MYSQL_PREFIX?}_user_stats`
107 WHERE
108         `userid`=%s
109 ORDER BY
110         `timestamp_ordered` DESC",
111         array(getUserId()), __FILE__, __LINE__);
112
113 if (SQL_NUMROWS($result) > 0) {
114         // Mail orders are in pool so we can display them
115         $OUT = ''; $SW = 2;
116         while ($content = SQL_FETCHARRAY($result)) {
117                 // Prepare data for the template
118                 // @TODO Rewrite in template: clix->clicks
119                 $content = array(
120                         'sw'                => $SW,
121                         'cat'               => getCategory($content['cat_id']),
122                         'pay'               => getPaymentTitlePrice($content['payment_id']),
123                         'url'               => generateDerefererUrl($content['url']),
124                         'timestamp_ordered' => generateDateTime($content['timestamp_ordered'], 2),
125                         'target_send'       => $content['max_rec'],
126                         'sent'              => generateDateTime($content['timestamp_send'], 2),
127                         'clix'              => $content['clicks'],
128                         'subject'           => $content['subject'],
129                         'percents'          => translateComma($content['clicks'] / $content['max_rec'] * 100)."%",
130                 );
131
132                 // Load row template and switch colors
133                 $OUT .= loadTemplate('member_stats_row', true, $content);
134                 $SW = 3 - $SW;
135         }
136
137         // Load main template
138         $main_content['stats'] = loadTemplate('member_stats_table', true, $OUT);
139 } else {
140         // No mail orders fond
141         $main_content['stats'] = loadTemplate('admin_settings_saved', true, getMessage('MEMBER_NO_MAILS_IN_STATS'));
142 }
143
144 // Free result
145 SQL_FREERESULT($result);
146
147 // Load main template
148 loadTemplate('member_stats_pool', false, $main_content);
149
150 // [EOF]
151 ?>