ac1b450fbd88624803c535930d26a0bf99842e95
[mailer.git] / inc / modules / guest / what-mediadata.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *          mod_media - By Robert Niedziela                             *
14  *          (c)2003 www.megacomputing.net                               *
15  * -------------------------------------------------------------------- *
16  *           Rewritten by Roland Haeder, 2003 - 2008                    *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
19  * For more information visit: http://www.mxchange.org                  *
20  *                                                                      *
21  * This program is free software; you can redistribute it and/or modify *
22  * it under the terms of the GNU General Public License as published by *
23  * the Free Software Foundation; either version 2 of the License, or    *
24  * (at your option) any later version.                                  *
25  *                                                                      *
26  * This program is distributed in the hope that it will be useful,      *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
29  * GNU General Public License for more details.                         *
30  *                                                                      *
31  * You should have received a copy of the GNU General Public License    *
32  * along with this program; if not, write to the Free Software          *
33  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
34  * MA  02110-1301  USA                                                  *
35  ************************************************************************/
36
37 // Some security stuff...
38 if (!defined('__SECURITY')) {
39         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
40         require($INC);
41 } elseif ((!EXT_IS_ACTIVE('mediadata')) && (!IS_ADMIN())) {
42         addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('mediadata'));
43         return;
44 }
45
46 // Add description as navigation point
47 ADD_DESCR('guest', __FILE__);
48
49 // @TODO Rewrite all constants
50 define('value', 'value');
51 define('lang', 'lang');
52 define('rows', 'rows');
53
54 // Get total confirmed user IDs...
55 define('user_confirmed'  , round(GET_TOTAL_DATA('CONFIRMED'  , 'user_data', 'userid', 'status', true)));
56 define('user_unconfirmed', round(GET_TOTAL_DATA('UNCONFIRMED', 'user_data', 'userid', 'status', true)));
57 define('user_locked'     , round(GET_TOTAL_DATA('LOCKED'     , 'user_data', 'userid', 'status', true)));
58 define('user_count'      , (constant('user_confirmed') + constant('user_unconfirmed') + constant('user_locked')));
59
60 // Start of this exchange
61 define('__MT_START', generateDateTime(getConfig('mt_start'), '3'));
62
63 // Projected number of members
64 define('__MT_STAGE', getConfig('mt_stage'));
65
66 // Project timestamp when number of members are reached
67 $PROJECTED = 0;
68 if (constant('user_count')> 0) {
69         // @TODO Find a better formular than this one
70         $PROJECTED = round((time() - getConfig('mt_start')) / constant('user_count') * getConfig('mt_stage') + getConfig('mt_start'));
71 }
72
73 // Generate timestamp
74 $TEST = makeTime(0, 0, 0, $PROJECTED);
75
76 if ($TEST > time()) {
77         define('__MT_PROJECTED', generateDateTime($PROJECTED, '3'));
78 } else {
79         define('__MT_PROJECTED', getMessage('USER_PROJECTION_UNKNOWN'));
80 }
81
82 // User who can receive mails
83 define('user_max_mails', GET_TOTAL_DATA('CONFIRMED', 'user_data' 'max_mails', 'status', true, " AND `max_mails` > 0"));
84
85 // Users who can receive mails today
86 define('user_max_rec', GET_TOTAL_DATA('CONFIRMED', 'user_data', 'receive_mails', 'status', true, " AND `receive_mails` > 0"));
87
88 // Max mails per day
89 define('max', GET_TOTAL_DATA('CONFIRMED', 'user_data', 'max_mails', 'status', false, " AND `max_mails` > 0"));
90
91 // Max mails for this day
92 define('rec', GET_TOTAL_DATA('CONFIRMED', 'user_data', 'receive_mails', 'status', false, " AND `receive_mails` > 0"));
93
94 // Initial lots of variables
95 $bmails = 0; $sent = 0; $max = 0; $rec = 0; $clicks = 0;
96
97 // Mail orders (only current)
98 $nmails = MEDIA_GET_ENTRY('normal_orders');
99 if (empty($nmails)) $nmails = 0;
100
101 // Mails sent so far
102 $clicks = MEDIA_GET_ENTRY('normal_clicks');
103 $sent   = MEDIA_GET_ENTRY('normal_send');
104 if (empty($sent))   $sent   = 0;
105 if (empty($clicks)) $clicks = 0;
106
107 // Bonus mails
108 if (EXT_IS_ACTIVE('bonus')) {
109         $bmails = MEDIA_GET_ENTRY('bonus_orders');
110         if (empty($bmails)) $bmails = 0;
111
112         // Count bonus mails clicks / sent mails
113         $dmy  = MEDIA_GET_ENTRY('bonus_clicks');
114         $dmy2 = MEDIA_GET_ENTRY('bonus_send');
115         if (empty($dmy))  $dmy  = 0;
116         if (empty($dmy2)) $dmy2 = 0;
117         $sent += $dmy2; $clicks += $dmy;
118 } // END - if
119
120 define('user_stats', ($nmails + $bmails));
121 define('sent'      , $sent);
122
123 // All clicks
124 define('user_links', abs($sent - $clicks));
125
126 $clr = '0.00000';
127 if ($sent > 0) $clr = $clicks / $sent * 100;
128 define('_clr', translateComma($clr).'%');
129
130 // Load jackpot
131 $result = SQL_QUERY("SELECT `points` FROM `{!_MYSQL_PREFIX!}_jackpot` WHERE `ok`='ok' LIMIT 1", __FILE__, __LINE__);
132 list($jackpot) = SQL_FETCHROW($result);
133 SQL_FREERESULT($result);
134 if (empty($jackpot)) $jackpot = 0;
135 define('jackpot', translateComma($jackpot));
136
137 // Total referal link clicks, total logins
138 $result = SQL_QUERY("SELECT DISTINCT SUM(d.ref_clicks), SUM(d.total_logins)
139 FROM `{!_MYSQL_PREFIX!}_user_data` AS d", __FILE__, __LINE__);
140 list($ref, $logins) = SQL_FETCHROW($result);
141 SQL_FREERESULT($result);
142
143 // Get total points
144 $points = MEDIA_GET_ENTRY('total_points');
145
146 if (empty($points)) $points = 0;
147 if (empty($ref))    $ref    = 0;
148 if (empty($logins)) $logins = 0;
149
150 define('__TOTAL_POINTS'   , translateComma($points));
151 define('__TOTAL_REFCLICKS', $ref);
152 define('__TOTAL_LOGINS'   , $logins);
153
154 // Referal banner
155 $total = GET_TOTAL_DATA('Y', 'refbanner', 'id', 'visible', true);
156
157 // Total views and clicks
158 $result = SQL_QUERY("SELECT SUM(`counter`) AS cnt, SUM(`clicks`) AS clx FROM `{!_MYSQL_PREFIX!}_refbanner` WHERE `visible`='Y'", __FILE__, __LINE__);
159 list($views, $clicks) = SQL_FETCHROW($result);
160 SQL_FREERESULT($result);
161
162 if (empty($total))  $total  = 0;
163 if (empty($views))  $views  = 0;
164 if (empty($clicks)) $clicks = 0;
165
166 define('__REF_TOTAL' , $total);
167 define('__REF_VIEWS' , $views);
168 define('__REF_CLICKS', $clicks);
169
170 //
171 // Extra mediadata depending on installed extensions
172 //
173
174 // Initialize Variables
175 $OUT_EXTRA   = ''; $ROWS_EXTRA   = 2;
176 $OUT_POINTS  = ''; $ROWS_POINTS  = 2;
177 $OUT_USER    = ''; $ROWS_USER    = 6;
178 $OUT_SPECIAL = ''; // We don't need row count here
179
180 // @TODO Rewrite these all if-blocks to filters
181 if (EXT_IS_ACTIVE('beg')) {
182         // Clicks on beg links
183         $result = SQL_QUERY("SELECT SUM(beg_clicks) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE beg_clicks>0", __FILE__, __LINE__);
184         list($extra) = SQL_FETCHROW($result);
185         SQL_FREERESULT($result);
186         if (empty($extra)) $extra = 0;
187         $content = array(
188                 'lang'  => MEDIA_BEG_CLICKS,
189                 'value' => $extra
190         );
191         $OUT_EXTRA .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
192         $ROWS_EXTRA++;
193 }
194
195 if (EXT_IS_ACTIVE('doubler')) {
196         // Total payed points
197         $result = SQL_QUERY("SELECT COUNT(id), SUM(points) FROM `{!_MYSQL_PREFIX!}_doubler` WHERE completed='Y' AND points > 0", __FILE__, __LINE__);
198         list($count1, $points1) = SQL_FETCHROW($result);
199         SQL_FREERESULT($result);
200         $result = SQL_QUERY("SELECT COUNT(id), SUM(points) FROM `{!_MYSQL_PREFIX!}_doubler` WHERE completed='N' AND points > 0", __FILE__, __LINE__);
201         list($count2, $points2) = SQL_FETCHROW($result);
202         SQL_FREERESULT($result);
203
204         if (empty($count1))  $count1  = 0;
205         if (empty($count2))  $count2  = 0;
206         if (empty($points1)) $points1 = 0;
207         if (empty($points2)) $points2 = 0;
208
209         // Add header
210         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_hrow', true, getMessage('MEDIA_DOUBLER_HEADER'));
211
212         // Add first line (count)
213         $content = array(
214                 'lang'  => getMessage('MEDIA_DOUBLER_COUNT'),
215                 'value' => $count1,
216                 'rows'  => '4'
217         );
218
219         // Add points
220         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row2', true, $content);
221         $content = array(
222                 'lang'  => getMessage('MEDIA_DOUBLER_CPOINTS'),
223                 'value' => translateComma($points1)
224         );
225         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
226         $content = array(
227                 'lang'  => getMessage('MEDIA_DOUBLER_WAITING'),
228                 'value' => translateComma($count2)
229         );
230         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
231                 $content = array(
232                 'lang'  => getMessage('MEDIA_DOUBLER_WPOINTS'),
233                 'value' => translateComma($points2)
234         );
235         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
236 }
237
238 if (EXT_IS_ACTIVE('holiday')) {
239         // Total holiday requests
240         $result = SQL_QUERY("SELECT DISTINCT COUNT(h.userid)
241 FROM `{!_MYSQL_PREFIX!}_user_holidays` AS h
242 LEFT JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
243 ON h.userid=d.userid
244 WHERE d.`holiday_active`='Y'",
245         __FILE__, __LINE__);
246         list($holiday) = SQL_FETCHROW($result);
247         SQL_FREERESULT($result);
248         if (empty($holiday)) $holiday = 0;
249         $content = array(
250                 'lang'  => getMessage('MEDIA_HOLIDAY_COUNT'),
251                 'value' => $holiday
252         );
253         $OUT_USER .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
254         $ROWS_USER++;
255 }
256
257 if (EXT_IS_ACTIVE('transfer')) {
258         // Statistics for points transfers
259         $result = SQL_QUERY("SELECT DISTINCT COUNT(t.id), SUM(t.points)
260 FROM `{!_MYSQL_PREFIX!}_user_transfers_in` AS t
261 LEFT JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
262 ON t.userid=d.userid",
263         __FILE__, __LINE__);
264         list($count_in, $points_in) = SQL_FETCHROW($result);
265         SQL_FREERESULT($result);
266         if (empty($count_in))  $count_in  = 0;
267         if (empty($points_in)) $points_in = 0;
268
269         $result = SQL_QUERY("SELECT DISTINCT COUNT(t.id), SUM(t.points)
270 FROM `{!_MYSQL_PREFIX!}_user_transfers_out` AS t
271 LEFT JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
272 ON t.userid=d.userid",
273         __FILE__, __LINE__);
274         list($count_out, $points_out) = SQL_FETCHROW($result);
275         SQL_FREERESULT($result);
276         if (empty($count_out))  $count_out  = 0;
277         if (empty($points_out)) $points_out = 0;
278
279         // Add header
280         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_hrow', true, getMessage('MEDIA_TRANSFER_HEADER'));
281         $content = array(
282                 'lang'  => getMessage('MEDIA_TRANSFER_IN_COUNT'),
283                 'value' => $count_in,
284                 'rows'  => '4'
285         );
286         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row2', true, $content);
287         $content = array(
288                 'lang'  => getMessage('MEDIA_TRANSFER_IN_POINTS'),
289                 'value' => translateComma($points_in)
290         );
291         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
292         $content = array(
293                 'lang'  => getMessage('MEDIA_TRANSFER_OUT_COUNT'),
294                 'value' => $count_out
295         );
296         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
297         $content = array(
298                 'lang'  => getMessage('MEDIA_TRANSFER_OUT_POINTS'),
299                 'value' => translateComma($points_out)
300         );
301         $OUT_SPECIAL .= LOAD_TEMPLATE('mediadata_extra_row', true, $content);
302 } // END - if
303
304 define('__EXTRA_MEDIADATA'  , $OUT_EXTRA);
305 define('__POINTS_MEDIADATA' , $OUT_POINTS);
306 define('__USER_MEDIADATA'   , $OUT_USER);
307 define('__SPECIAL_MEDIADATA', $OUT_SPECIAL);
308 define('__ROWSPAN_EXTRA'    , $ROWS_EXTRA);
309 define('__ROWSPAN_POINTS'   , $ROWS_POINTS);
310 define('__ROWSPAN_USER'     , $ROWS_USER);
311
312 // Patch level and it's timespamp
313 define('__PATCH_LEVEL', getConfig('patch_level'));
314 define('__PATCH_CTIME', generateDateTime(getConfig('patch_ctime'), '2'));
315
316 // Load template
317 LOAD_TEMPLATE('mediadata');
318
319 //
320 ?>