739b83a55b0f262415df34f32587e20933921bc6
[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 //                               0     1         2         3      4            5            6            7           8
101 $result = SQL_QUERY_ESC("SELECT id, cat_id, payment_id, subject, url, timestamp_ordered, max_rec, timestamp_send, clicks
102 FROM `{!_MYSQL_PREFIX!}_user_stats`
103 WHERE userid=%s
104 ORDER BY timestamp_ordered DESC",
105 array(getUserId()), __FILE__, __LINE__);
106
107 if (SQL_NUMROWS($result) > 0) {
108         // Mail orders are in pool so we can display them
109         $OUT = ''; $SW = 2;
110         while ($data = SQL_FETCHROW($result)) {
111                 // Prepare data for the template
112                 $content = array(
113                         'sw'    => $SW,
114                         'cat'   => getCategory($data[1]),
115                         'pay'   => getPaymentTitlePrice($data[2]),
116                         'subj'  => COMPILE_CODE($data[3]),
117                         'url'   => DEREFERER($data[4]),
118                         'stamp' => generateDateTime($data[5], '2'),
119                         'recs'  => $data[6],
120                         'sent'  => generateDateTime($data[7], '2'),
121                         'clix'  => $data[8],
122                         'perc'  => COMPILE_CODE($data[8] / $data[6] * 100)."%",
123                 );
124
125                 // Load row template and switch colors
126                 $OUT .= LOAD_TEMPLATE("member_stats_row", true, $content);
127                 $SW = 3 - $SW;
128         }
129
130         // Load main template
131         $main_content['stats'] = LOAD_TEMPLATE("member_stats_table", true, $OUT);
132 } else {
133         // No mail orders fond
134         $main_content['stats'] = LOAD_TEMPLATE('admin_settings_saved', true, getMessage('MEMBER_NO_MAILS_IN_STATS'));
135 }
136
137 // Free result
138 SQL_FREERESULT($result);
139
140 // Load main template
141 LOAD_TEMPLATE("member_stats_pool", false, $main_content);
142
143 //
144 ?>