c3ecf925becd5900eb66cdd8616105200ec69fd4
[mailer.git] / inc / modules / guest / what-mediadata.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 12/09/2003 *
4  * ===================                          Last change: 02/12/2006 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-mediadata.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Media data                                       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mediendaten                                      *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         exit();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('guest', __FILE__);
45
46 // Both ext-mediadata and ext-user must be there
47 if ((!isExtensionActive('mediadata')) && (!isAdmin())) {
48         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=mediadata%}');
49         return;
50 } elseif ((!isExtensionActive('user')) && (!isAdmin())) {
51         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
52         return;
53 }
54
55 // Get total confirmed user ids...
56 $content['user_confirmed']   = getTotalConfirmedUser();
57 $content['user_unconfirmed'] = getTotalUnconfirmedUser();
58 $content['user_locked']      = getTotalLockedUser();
59 $content['user_count']       = ($content['user_confirmed'] + $content['user_unconfirmed'] + $content['user_locked']);
60
61 // Start of this exchange
62 $content['mt_start'] = generateDateTime(getMtStart(), '3');
63
64 // Project timestamp when number of members are reached
65 $PROJECTED = '0';
66 if ($content['user_count'] > 0) {
67         // @TODO Find a better formular than this one
68         $PROJECTED = round((time() - getMtStart()) / $content['user_count'] * getMtStage() + getMtStart());
69 } // END - if
70
71 // Generate timestamp
72 $TEST = makeTime(0, 0, 0, $PROJECTED);
73
74 if ($TEST > time()) {
75         $content['projected'] = '{%message,USER_MT_PROJECTED=' . generateDateTime($PROJECTED, '3') . '%}';
76 } else {
77         $content['projected'] = getMaskedMessage('USER_MT_PROJECTED', '{--USER_PROJECTION_UNKNOWN--}');
78 }
79
80 // User who can receive mails
81 $content['user_max_mails'] = countSumTotalData('CONFIRMED', 'user_data', 'max_mails', 'status', TRUE, runFilterChain('user_exclusion_sql', " AND `max_mails` > 0"));
82
83 // Users who can receive mails today
84 $content['user_max_rec'] = countSumTotalData('CONFIRMED', 'user_data', 'receive_mails', 'status', TRUE, runFilterChain('user_exclusion_sql', " AND `receive_mails` > 0"));
85
86 // Max mails per day
87 $content['max'] = countSumTotalData('CONFIRMED', 'user_data', 'max_mails', 'status', FALSE, runFilterChain('user_exclusion_sql', " AND `max_mails` > 0"));
88
89 // Max mails for this day
90 $content['rec'] = countSumTotalData('CONFIRMED', 'user_data', 'receive_mails', 'status', FALSE, runFilterChain('user_exclusion_sql', " AND `receive_mails` > 0"));
91
92 // Initial lots of variables
93 $bmails = '0';
94 $sent   = '0';
95 $max    = '0';
96 $rec    = '0';
97 $clicks = '0';
98
99 // Mail orders (only current)
100 $nmails = getMediadataEntry('normal_orders');
101 if (empty($nmails)) $nmails = '0';
102
103 // Mails sent so far
104 $clicks = getMediadataEntry('normal_clicks');
105 $sent   = getMediadataEntry('normal_send');
106 if (empty($sent))   $sent   = '0';
107 if (empty($clicks)) $clicks = '0';
108
109 // Bonus mails
110 if (isExtensionActive('bonus')) {
111         $bmails = getMediadataEntry('bonus_orders');
112         if (empty($bmails)) $bmails = '0';
113
114         // Count bonus mails clicks / sent mails
115         $dmy  = getMediadataEntry('bonus_clicks');
116         $dmy2 = getMediadataEntry('bonus_send');
117         if (empty($dmy))  $dmy  = '0';
118         if (empty($dmy2)) $dmy2 = '0';
119         $sent += $dmy2; $clicks += $dmy;
120 } // END - if
121
122 $content['user_stats'] = ($nmails + $bmails);
123 $content['sent']       = $sent;
124
125 // All clicks
126 $content['user_links'] = abs($sent - $clicks);
127
128 // Click rate
129 $content['click_rate'] = calculatePercentageRate($clicks, $sent);
130
131 // Load jackpot
132 $content['jackpot'] = '0';
133 if (isExtensionActive('jackpot')) $content['jackpot'] = getJackpotPoints();
134 if (empty($content['jackpot'])) $content['jackpot'] = '0';
135
136 // Total referral link clicks, total logins
137 $result = sqlQuery('SELECT
138         SUM(`d`.`ref_clicks`) AS `total_ref_clicks`,
139         SUM(`d`.`total_logins`) AS `total_logins`
140 FROM
141         `{?_MYSQL_PREFIX?}_user_data` AS `d`
142 ' . runFilterChain('user_exclusion_sql', ''), __FILE__, __LINE__);
143 list($ref, $logins) = sqlFetchRow($result);
144 sqlFreeResult($result);
145
146 // Get total points
147 $points = getMediadataEntry('total_points');
148
149 if (empty($points)) $points = '0';
150 if (empty($ref))    $ref    = '0';
151 if (empty($logins)) $logins = '0';
152
153 $content['total_points']    = $points;
154 $content['total_refclicks'] = $ref;
155 $content['total_logins']    = $logins;
156
157 // Referral banner
158 $total = countSumTotalData('Y', 'refbanner', 'id', 'visible', TRUE);
159
160 // Total views and clicks
161 $result = sqlQuery("SELECT SUM(`counter`) AS `views`, SUM(`clicks`) AS `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `visible`='Y'", __FILE__, __LINE__);
162 list($views, $clicks) = sqlFetchRow($result);
163 sqlFreeResult($result);
164
165 if (empty($total))  $total  = '0';
166 if (empty($views))  $views  = '0';
167 if (empty($clicks)) $clicks = '0';
168
169 $content['ref_total']  = $total;
170 $content['ref_views']  = $views;
171 $content['ref_clicks'] = $clicks;
172
173 //
174 // Extra mediadata depending on installed extensions
175 //
176
177 // Initialize Variables
178 $OUT_EXTRA   = '';
179 $OUT_POINTS  = '';
180 $OUT_USER    = '';
181 $OUT_SPECIAL = ''; // We don't need row count here
182
183 // @TODO Rewrite all these if-blocks to filters
184 if (isExtensionActive('beg')) {
185         // Clicks on beg links
186         $data = array(
187                 'lang'  => '{--MEDIA_BEG_CLICKS--}',
188                 'value' => countSumTotalData('0', 'user_data', 'beg_clicks', 'userid', FALSE, ' WHERE `beg_clicks` > 0')
189         );
190         $OUT_EXTRA .= loadTemplate('mediadata_extra_row', TRUE, $data);
191 } // END - if
192
193 if (isExtensionActive('doubler')) {
194         // Add header
195         $OUT_SPECIAL .= loadTemplate('mediadata_extra_hrow', TRUE, '{--MEDIA_DOUBLER_HEADER--}');
196
197         // Add first line (count)
198         $data = array(
199                 'lang'  => '{--MEDIA_DOUBLER_COUNT--}',
200                 'value' => countSumTotalData('Y','doubler','id','completed', TRUE, ' AND `points` > 0'),
201         );
202
203         // Add points
204         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row2', TRUE, $data);
205         $data = array(
206                 'lang'  => '{--MEDIA_DOUBLER_CPOINTS--}',
207                 'value' => countSumTotalData('Y','doubler','id','completed', FALSE, ' AND `points` > 0')
208         );
209         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
210         $data = array(
211                 'lang'  => '{--MEDIA_DOUBLER_WAITING--}',
212                 'value' => countSumTotalData('N','doubler','id','completed', TRUE, ' AND `points` > 0')
213         );
214         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
215         $data = array(
216                 'lang'  => '{--MEDIA_DOUBLER_WPOINTS--}',
217                 'value' => countSumTotalData('N','doubler','id','completed', FALSE, ' AND `points` > 0')
218         );
219         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
220 } // END - if
221
222 if (isExtensionActive('holiday')) {
223         // Total holiday requests
224         $result = sqlQuery("SELECT
225         COUNT(`h`.`userid`) AS `count_holidays`
226 FROM
227         `{?_MYSQL_PREFIX?}_user_holidays` AS `h`
228 LEFT JOIN
229         `{?_MYSQL_PREFIX?}_user_data` AS `d`
230 ON
231         `h`.`userid`=`d`.`userid`
232 WHERE
233         `d`.`holiday_active`='Y'
234 " . runFilterChain('user_exclusion_sql', ' '),
235         __FILE__, __LINE__);
236         list($holiday) = sqlFetchRow($result);
237         sqlFreeResult($result);
238         if (empty($holiday)) $holiday = '0';
239         $data = array(
240                 'lang'  => '{--MEDIA_HOLIDAY_COUNT--}',
241                 'value' => $holiday
242         );
243         $OUT_USER .= loadTemplate('mediadata_extra_row', TRUE, $data);
244 } // END - if
245
246 if (isExtensionActive('transfer')) {
247         // Statistics for points transfers
248         $result = sqlQuery("SELECT
249         COUNT(`t`.`id`) AS `cnt`,
250         SUM(`t`.`points`) AS `points`
251 FROM
252         `{?_MYSQL_PREFIX?}_user_transfers_in` AS `t`
253 LEFT JOIN
254         `{?_MYSQL_PREFIX?}_user_data` AS `d`
255 ON
256         `t`.`userid`=`d`.`userid`
257 " . runFilterChain('user_exclusion_sql', ''),
258                 __FILE__, __LINE__);
259         list($count_in, $points_in) = sqlFetchRow($result);
260         sqlFreeResult($result);
261         if (empty($count_in))  $count_in  = '0';
262         if (empty($points_in)) $points_in = '0';
263
264         $result = sqlQuery("SELECT
265         COUNT(`t`.`id`) AS `cnt`, SUM(`t`.`points`) AS `points`
266 FROM
267         `{?_MYSQL_PREFIX?}_user_transfers_out` AS `t`
268 LEFT JOIN
269         `{?_MYSQL_PREFIX?}_user_data` AS `d`
270 ON
271         `t`.`userid`=`d`.`userid`
272 " . runFilterChain('user_exclusion_sql', ''),
273         __FILE__, __LINE__);
274         list($count_out, $points_out) = sqlFetchRow($result);
275         sqlFreeResult($result);
276         if (empty($count_out))  $count_out  = '0';
277         if (empty($points_out)) $points_out = '0';
278
279         // Add header
280         $OUT_SPECIAL .= loadTemplate('mediadata_extra_hrow', TRUE, '{--MEDIA_TRANSFER_HEADER--}');
281         $data = array(
282                 'lang'  => '{--MEDIA_TRANSFER_IN_COUNT--}',
283                 'value' => $count_in,
284         );
285         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row2', TRUE, $data);
286         $data = array(
287                 'lang'  => '{--MEDIA_TRANSFER_IN_POINTS--}',
288                 'value' => $points_in
289         );
290         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
291         $data = array(
292                 'lang'  => '{--MEDIA_TRANSFER_OUT_COUNT--}',
293                 'value' => $count_out
294         );
295         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
296         $data = array(
297                 'lang'  => '{--MEDIA_TRANSFER_OUT_POINTS--}',
298                 'value' => $points_out
299         );
300         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
301 } // END - if
302
303 $content['out_extra']   = $OUT_EXTRA;
304 $content['out_points']  = $OUT_POINTS;
305 $content['out_user']    = $OUT_USER;
306 $content['out_special'] = $OUT_SPECIAL;
307
308 // Load template
309 loadTemplate('mediadata', FALSE, $content);
310
311 // [EOF]
312 ?>