A lot code rewritten:
[mailer.git] / inc / modules / member / what-stats.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } elseif (!isMember()) {
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
49
50 // Init output
51 $main_content = array();
52
53 // Load waiting/pending orders
54 $result = SQL_QUERY_ESC("SELECT
55         `id`, `cat_id`, `payment_id`, `subject`, `url`, `timestamp`, `target_send`, `data_type`, `zip`
56 FROM
57         `{?_MYSQL_PREFIX?}_pool`
58 WHERE
59         `sender`=%s AND
60         `data_type` != 'SEND'
61 ORDER BY
62         `timestamp` DESC",
63         array(getMemberId()), __FILE__, __LINE__);
64
65 // Are there mails left in pool?
66 if (SQL_NUMROWS($result) > 0) {
67         // Load all orders
68         $OUT = '';
69         while ($content = SQL_FETCHARRAY($result)) {
70                 // Is the ZIP code set? If not, set dashes
71                 if (empty($content['zip'])) $content['zip'] =  '---';
72
73                 // Prepare content for output
74                 // @TODO More usage of EL at this array
75                 $content = array(
76                         'id'          => $content['id'],
77                         'cat'         => getCategory($content['cat_id']),
78                         'pay'         => getPaymentTitlePrice($content['payment_id']),
79                         'subject'     => $content['subject'],
80                         'url'         => generateDerefererUrl($content['url']),
81                         'timestamp'   => generateDateTime($content['timestamp'], 2),
82                         'target_send' => $content['target_send'],
83                         'type'        => translatePoolType($content['data_type']),
84                         'zip'         => $content['zip']
85                 );
86
87                 // Load template
88                 $OUT .= loadTemplate('member_pool_row', true, $content);
89         } // END - if
90
91         // Load main template
92         $main_content['pool'] = loadTemplate('member_pool_table', true, $OUT);
93 } else {
94         // No mails in pool!
95         $main_content['pool'] = loadTemplate('admin_settings_saved', true, '{--MEMBER_NO_MAILS_IN_POOL--}');
96 }
97
98 // Free result
99 SQL_FREERESULT($result);
100
101 // Load sent orders
102 $result = SQL_QUERY_ESC("SELECT
103         `id`, `cat_id`, `payment_id`, `subject`, `url`, `timestamp_ordered`, `max_rec`, `timestamp_send`, `clicks`
104 FROM
105         `{?_MYSQL_PREFIX?}_user_stats`
106 WHERE
107         `userid`=%s
108 ORDER BY
109         `timestamp_ordered` DESC",
110         array(getMemberId()), __FILE__, __LINE__);
111
112 if (SQL_NUMROWS($result) > 0) {
113         // Mail orders are in pool so we can display them
114         $OUT = '';
115         while ($content = SQL_FETCHARRAY($result)) {
116                 // Prepare data for the template
117                 $content = array(
118                         'cat_id'            => $content['cat_id'],
119                         'payment_id'        => $content['payment_id'],
120                         'url'               => $content['url'],
121                         'timestamp_ordered' => generateDateTime($content['timestamp_ordered'], 2),
122                         'max_rec'           => $content['max_rec'],
123                         'timestamp_sent'    => generateDateTime($content['timestamp_send'], 2),
124                         'clicks'            => $content['clicks'],
125                         'subject'           => $content['subject'],
126                         'percents'          => ($content['clicks'] / $content['max_rec'] * 100),
127                 );
128
129                 // Load row template and switch colors
130                 $OUT .= loadTemplate('member_stats_row', true, $content);
131         } // END - if
132
133         // Load main template
134         $main_content['stats'] = loadTemplate('member_stats_table', true, $OUT);
135 } else {
136         // No mail orders fond
137         $main_content['stats'] = loadTemplate('admin_settings_saved', true, '{--MEMBER_NO_MAILS_IN_STATS--}');
138 }
139
140 // Free result
141 SQL_FREERESULT($result);
142
143 // Load main template
144 loadTemplate('member_stats_pool', false, $main_content);
145
146 // [EOF]
147 ?>