The yearly copyright-update commit. 2009, 2010 are now copyrighted on the developer...
[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  *          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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
27  * For more information visit: http://www.mxchange.org                  *
28  *                                                                      *
29  * This program is free software; you can redistribute it and/or modify *
30  * it under the terms of the GNU General Public License as published by *
31  * the Free Software Foundation; either version 2 of the License, or    *
32  * (at your option) any later version.                                  *
33  *                                                                      *
34  * This program is distributed in the hope that it will be useful,      *
35  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
36  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
37  * GNU General Public License for more details.                         *
38  *                                                                      *
39  * You should have received a copy of the GNU General Public License    *
40  * along with this program; if not, write to the Free Software          *
41  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
42  * MA  02110-1301  USA                                                  *
43  ************************************************************************/
44
45 // Some security stuff...
46 if (!defined('__SECURITY')) {
47         die();
48 } // END - if
49
50 // Add description as navigation point
51 addMenuDescription('guest', __FILE__);
52
53 if ((!isExtensionActive('mediadata')) && (!isAdmin())) {
54         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('mediadata'));
55         return;
56 } // END - if
57
58 // Get total confirmed user ids...
59 $content['user_confirmed']   = round(countSumTotalData('CONFIRMED'  , 'user_data', 'userid', 'status', true));
60 $content['user_unconfirmed'] = round(countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true));
61 $content['user_locked']      = round(countSumTotalData('LOCKED'     , 'user_data', 'userid', 'status', true));
62 $content['user_count']       = ($content['user_confirmed'] + $content['user_unconfirmed'] + $content['user_locked']);
63
64 // Start of this exchange
65 $content['mt_start'] = generateDateTime(getConfig('mt_start'), 3);
66
67 // Project timestamp when number of members are reached
68 $PROJECTED = '0';
69 if ($content['user_count'] > 0) {
70         // @TODO Find a better formular than this one
71         $PROJECTED = round((time() - getConfig('mt_start')) / $content['user_count'] * getConfig('mt_stage') + getConfig('mt_start'));
72 } // END - if
73
74 // Generate timestamp
75 $TEST = makeTime(0, 0, 0, $PROJECTED);
76
77 if ($TEST > time()) {
78         $content['projected'] = generateDateTime($PROJECTED, 3);
79 } else {
80         $content['projected'] = getMessage('USER_PROJECTION_UNKNOWN');
81 }
82
83 // User who can receive mails
84 $content['user_max_mails'] = countSumTotalData('CONFIRMED', 'user_data', 'max_mails', 'status', true, " AND `max_mails` > 0");
85
86 // Users who can receive mails today
87 $content['user_max_rec'] = countSumTotalData('CONFIRMED', 'user_data', 'receive_mails', 'status', true, " AND `receive_mails` > 0");
88
89 // Max mails per day
90 $content['max'] = countSumTotalData('CONFIRMED', 'user_data', 'max_mails', 'status', false, " AND `max_mails` > 0");
91
92 // Max mails for this day
93 $content['rec'] = countSumTotalData('CONFIRMED', 'user_data', 'receive_mails', 'status', false, " AND `receive_mails` > 0");
94
95 // Initial lots of variables
96 $bmails = '0'; $sent = '0'; $max = '0'; $rec = '0'; $clicks = '0';
97
98 // Mail orders (only current)
99 $nmails = getMediadataEntry('normal_orders');
100 if (empty($nmails)) $nmails = '0';
101
102 // Mails sent so far
103 $clicks = getMediadataEntry('normal_clicks');
104 $sent   = getMediadataEntry('normal_send');
105 if (empty($sent))   $sent   = '0';
106 if (empty($clicks)) $clicks = '0';
107
108 // Bonus mails
109 if (isExtensionActive('bonus')) {
110         $bmails = getMediadataEntry('bonus_orders');
111         if (empty($bmails)) $bmails = '0';
112
113         // Count bonus mails clicks / sent mails
114         $dmy  = getMediadataEntry('bonus_clicks');
115         $dmy2 = getMediadataEntry('bonus_send');
116         if (empty($dmy))  $dmy  = '0';
117         if (empty($dmy2)) $dmy2 = '0';
118         $sent += $dmy2; $clicks += $dmy;
119 } // END - if
120
121 $content['user_stats'] = ($nmails + $bmails);
122 $content['sent']       = $sent;
123
124 // All clicks
125 $content['user_links'] = abs($sent - $clicks);
126
127 $clr = '0.00000';
128 if ($sent > 0) $clr = $clicks / $sent * 100;
129 $content['_clr'] = translateComma($clr) . '%';
130
131 // Load jackpot
132 $jackpot = '0';
133 if (isExtensionActive('jackpot')) $jackpot = getJackpotPoints();
134
135 if (empty($jackpot)) $jackpot = '0';
136 $content['jackpot'] = translateComma($jackpot);
137
138 // Total referal link clicks, total logins
139 $result = SQL_QUERY("SELECT
140         SUM(d.ref_clicks), SUM(d.total_logins)
141 FROM
142         `{?_MYSQL_PREFIX?}_user_data` AS d", __FILE__, __LINE__);
143 list($ref, $logins) = SQL_FETCHROW($result);
144 SQL_FREERESULT($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']    = translateComma($points);
154 $content['total_refclicks'] = $ref;
155 $content['total_logins']    = $logins;
156
157 // Referal banner
158 $total = countSumTotalData('Y', 'refbanner', 'id', 'visible', true);
159
160 // Total views and clicks
161 $result = SQL_QUERY("SELECT SUM(`counter`) AS cnt, SUM(`clicks`) AS clx FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `visible`='Y'", __FILE__, __LINE__);
162 list($views, $clicks) = SQL_FETCHROW($result);
163 SQL_FREERESULT($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'  => getMessage('MEDIA_BEG_CLICKS'),
188                 'value' => countSumTotalData(1, 'user_data', 'beg_clicks', 1, false, " AND `beg_clicks` > 0")
189         );
190         $OUT_EXTRA .= loadTemplate('mediadata_extra_row', true, $data);
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         );
202
203         // Add points
204         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row2', true, $data);
205         $data = array(
206                 'lang'  => getMessage('MEDIA_DOUBLER_CPOINTS'),
207                 'value' => translateComma(countSumTotalData('Y','doubler','id','completed', false, " AND `points` > 0"))
208         );
209         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', true, $data);
210         $data = array(
211                 'lang'  => getMessage('MEDIA_DOUBLER_WAITING'),
212                 'value' => translateComma(countSumTotalData('N','doubler','id','completed', true, " AND `points` > 0"))
213         );
214         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', true, $data);
215         $data = array(
216                 'lang'  => getMessage('MEDIA_DOUBLER_WPOINTS'),
217                 'value' => translateComma(countSumTotalData('N','doubler','id','completed', false, " AND `points` > 0"))
218         );
219         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', true, $data);
220 }
221
222 if (isExtensionActive('holiday')) {
223         // Total holiday requests
224         $result = SQL_QUERY("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         __FILE__, __LINE__);
235         list($holiday) = SQL_FETCHROW($result);
236         SQL_FREERESULT($result);
237         if (empty($holiday)) $holiday = '0';
238         $data = array(
239                 'lang'  => getMessage('MEDIA_HOLIDAY_COUNT'),
240                 'value' => $holiday
241         );
242         $OUT_USER .= loadTemplate('mediadata_extra_row', true, $data);
243 }
244
245 if (isExtensionActive('transfer')) {
246         // Statistics for points transfers
247         $result = SQL_QUERY("SELECT
248         COUNT(t.id) AS cnt, SUM(t.points) AS points
249 FROM
250         `{?_MYSQL_PREFIX?}_user_transfers_in` AS t
251 LEFT JOIN
252         `{?_MYSQL_PREFIX?}_user_data` AS d
253 ON
254         t.userid=d.userid",
255                 __FILE__, __LINE__);
256         list($count_in, $points_in) = SQL_FETCHROW($result);
257         SQL_FREERESULT($result);
258         if (empty($count_in))  $count_in  = '0';
259         if (empty($points_in)) $points_in = '0';
260
261         $result = SQL_QUERY("SELECT COUNT(t.id), SUM(t.points)
262 FROM `{?_MYSQL_PREFIX?}_user_transfers_out` AS t
263 LEFT JOIN `{?_MYSQL_PREFIX?}_user_data` AS d
264 ON t.userid=d.userid",
265         __FILE__, __LINE__);
266         list($count_out, $points_out) = SQL_FETCHROW($result);
267         SQL_FREERESULT($result);
268         if (empty($count_out))  $count_out  = '0';
269         if (empty($points_out)) $points_out = '0';
270
271         // Add header
272         $OUT_SPECIAL .= loadTemplate('mediadata_extra_hrow', true, getMessage('MEDIA_TRANSFER_HEADER'));
273         $data = array(
274                 'lang'  => getMessage('MEDIA_TRANSFER_IN_COUNT'),
275                 'value' => $count_in,
276         );
277         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row2', true, $data);
278         $data = array(
279                 'lang'  => getMessage('MEDIA_TRANSFER_IN_POINTS'),
280                 'value' => translateComma($points_in)
281         );
282         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', true, $data);
283         $data = array(
284                 'lang'  => getMessage('MEDIA_TRANSFER_OUT_COUNT'),
285                 'value' => $count_out
286         );
287         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', true, $data);
288         $data = array(
289                 'lang'  => getMessage('MEDIA_TRANSFER_OUT_POINTS'),
290                 'value' => translateComma($points_out)
291         );
292         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', true, $data);
293 } // END - if
294
295 $content['out_extra']      = $OUT_EXTRA;
296 $content['out_points']     = $OUT_POINTS;
297 $content['out_user']       = $OUT_USER;
298 $content['out_special']    = $OUT_SPECIAL;
299
300 // Patch timespamp
301 $content['patch_ctime'] = generateDateTime(getConfig('patch_ctime'), 2);
302
303 // Load template
304 loadTemplate('mediadata', false, $content);
305
306 // [EOF]
307 ?>