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