Code style changed, ext-user continued:
[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 - 2012 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'] * getConfig('mt_stage') + 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, " 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, " AND `receive_mails` > 0");
85
86 // Max mails per day
87 $content['max'] = countSumTotalData('CONFIRMED', 'user_data', 'max_mails', 'status', FALSE, " AND `max_mails` > 0");
88
89 // Max mails for this day
90 $content['rec'] = countSumTotalData('CONFIRMED', 'user_data', 'receive_mails', 'status', FALSE, " 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'] = '0';
130 if ($sent > 0) {
131         $content['click_rate'] = $clicks / $sent * 100;
132 } // END - if
133
134 // Load jackpot
135 $jackpot = '0';
136 if (isExtensionActive('jackpot')) $jackpot = getJackpotPoints();
137
138 if (empty($jackpot)) $jackpot = '0';
139 $content['jackpot'] = $jackpot;
140
141 // Total referral link clicks, total logins
142 $result = SQL_QUERY('SELECT
143         SUM(d.ref_clicks), SUM(d.total_logins)
144 FROM
145         `{?_MYSQL_PREFIX?}_user_data` AS d', __FILE__, __LINE__);
146 list($ref, $logins) = SQL_FETCHROW($result);
147 SQL_FREERESULT($result);
148
149 // Get total points
150 $points = getMediadataEntry('total_points');
151
152 if (empty($points)) $points = '0';
153 if (empty($ref))    $ref    = '0';
154 if (empty($logins)) $logins = '0';
155
156 $content['total_points']    = $points;
157 $content['total_refclicks'] = $ref;
158 $content['total_logins']    = $logins;
159
160 // Referral banner
161 $total = countSumTotalData('Y', 'refbanner', 'id', 'visible', TRUE);
162
163 // Total views and clicks
164 $result = SQL_QUERY("SELECT SUM(`counter`) AS cnt, SUM(`clicks`) AS clx FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `visible`='Y'", __FILE__, __LINE__);
165 list($views, $clicks) = SQL_FETCHROW($result);
166 SQL_FREERESULT($result);
167
168 if (empty($total))  $total  = '0';
169 if (empty($views))  $views  = '0';
170 if (empty($clicks)) $clicks = '0';
171
172 $content['ref_total']  = $total;
173 $content['ref_views']  = $views;
174 $content['ref_clicks'] = $clicks;
175
176 //
177 // Extra mediadata depending on installed extensions
178 //
179
180 // Initialize Variables
181 $OUT_EXTRA   = '';
182 $OUT_POINTS  = '';
183 $OUT_USER    = '';
184 $OUT_SPECIAL = ''; // We don't need row count here
185
186 // @TODO Rewrite all these if-blocks to filters
187 if (isExtensionActive('beg')) {
188         // Clicks on beg links
189         $data = array(
190                 'lang'  => '{--MEDIA_BEG_CLICKS--}',
191                 'value' => countSumTotalData('0', 'user_data', 'beg_clicks', 'userid', FALSE, ' AND `beg_clicks` > 0')
192         );
193         $OUT_EXTRA .= loadTemplate('mediadata_extra_row', TRUE, $data);
194 } // END - if
195
196 if (isExtensionActive('doubler')) {
197         // Add header
198         $OUT_SPECIAL .= loadTemplate('mediadata_extra_hrow', TRUE, '{--MEDIA_DOUBLER_HEADER--}');
199
200         // Add first line (count)
201         $data = array(
202                 'lang'  => '{--MEDIA_DOUBLER_COUNT--}',
203                 'value' => countSumTotalData('Y','doubler','id','completed', TRUE, ' AND `points` > 0'),
204         );
205
206         // Add points
207         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row2', TRUE, $data);
208         $data = array(
209                 'lang'  => '{--MEDIA_DOUBLER_CPOINTS--}',
210                 'value' => countSumTotalData('Y','doubler','id','completed', FALSE, ' AND `points` > 0')
211         );
212         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
213         $data = array(
214                 'lang'  => '{--MEDIA_DOUBLER_WAITING--}',
215                 'value' => countSumTotalData('N','doubler','id','completed', TRUE, ' AND `points` > 0')
216         );
217         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
218         $data = array(
219                 'lang'  => '{--MEDIA_DOUBLER_WPOINTS--}',
220                 'value' => countSumTotalData('N','doubler','id','completed', FALSE, ' AND `points` > 0')
221         );
222         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
223 } // END - if
224
225 if (isExtensionActive('holiday')) {
226         // Total holiday requests
227         $result = SQL_QUERY("SELECT
228         COUNT(h.userid) AS count_holidays
229 FROM
230         `{?_MYSQL_PREFIX?}_user_holidays` AS h
231 LEFT JOIN
232         `{?_MYSQL_PREFIX?}_user_data` AS d
233 ON
234         h.userid=d.userid
235 WHERE
236         d.`holiday_active`='Y'",
237         __FILE__, __LINE__);
238         list($holiday) = SQL_FETCHROW($result);
239         SQL_FREERESULT($result);
240         if (empty($holiday)) $holiday = '0';
241         $data = array(
242                 'lang'  => '{--MEDIA_HOLIDAY_COUNT--}',
243                 'value' => $holiday
244         );
245         $OUT_USER .= loadTemplate('mediadata_extra_row', TRUE, $data);
246 } // END - if
247
248 if (isExtensionActive('transfer')) {
249         // Statistics for points transfers
250         $result = SQL_QUERY("SELECT
251         COUNT(t.id) AS cnt, SUM(t.points) AS `points`
252 FROM
253         `{?_MYSQL_PREFIX?}_user_transfers_in` AS t
254 LEFT JOIN
255         `{?_MYSQL_PREFIX?}_user_data` AS d
256 ON
257         t.userid=d.userid",
258                 __FILE__, __LINE__);
259         list($count_in, $points_in) = SQL_FETCHROW($result);
260         SQL_FREERESULT($result);
261         if (empty($count_in))  $count_in  = '0';
262         if (empty($points_in)) $points_in = '0';
263
264         $result = SQL_QUERY("SELECT
265         COUNT(t.id), SUM(t.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         __FILE__, __LINE__);
273         list($count_out, $points_out) = SQL_FETCHROW($result);
274         SQL_FREERESULT($result);
275         if (empty($count_out))  $count_out  = '0';
276         if (empty($points_out)) $points_out = '0';
277
278         // Add header
279         $OUT_SPECIAL .= loadTemplate('mediadata_extra_hrow', TRUE, '{--MEDIA_TRANSFER_HEADER--}');
280         $data = array(
281                 'lang'  => '{--MEDIA_TRANSFER_IN_COUNT--}',
282                 'value' => $count_in,
283         );
284         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row2', TRUE, $data);
285         $data = array(
286                 'lang'  => '{--MEDIA_TRANSFER_IN_POINTS--}',
287                 'value' => $points_in
288         );
289         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
290         $data = array(
291                 'lang'  => '{--MEDIA_TRANSFER_OUT_COUNT--}',
292                 'value' => $count_out
293         );
294         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
295         $data = array(
296                 'lang'  => '{--MEDIA_TRANSFER_OUT_POINTS--}',
297                 'value' => $points_out
298         );
299         $OUT_SPECIAL .= loadTemplate('mediadata_extra_row', TRUE, $data);
300 } // END - if
301
302 $content['out_extra']   = $OUT_EXTRA;
303 $content['out_points']  = $OUT_POINTS;
304 $content['out_user']    = $OUT_USER;
305 $content['out_special'] = $OUT_SPECIAL;
306
307 // Load template
308 loadTemplate('mediadata', FALSE, $content);
309
310 // [EOF]
311 ?>