2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/03/2004 *
4 * =================== Last change: 11/19/2005 *
6 * -------------------------------------------------------------------- *
7 * File : task_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special task functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle task-Funktionen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 // The advanced overview shows detailed informations to your exchange script:
45 // - Unconfirmed / locked accounts
46 // - Mails waiting to be approved
51 // @TODO Move all extension-dependent queries into filters
52 function outputAdvancedOverview (&$result_main) {
53 // Init variables/arrays
60 // Chheck for new extensions and updates
61 $jobsDone = outputStandardOverview($result_main);
70 'confirmed_members','unconfirmed_members','locked_members',
72 'update_tasks','new_tasks','closed_tasks','your_tasks','deleted_tasks','solved_tasks',
74 'pending_mails','canceled_mails','send_emails',
78 'purged_mails','purged_bonus_mails'
81 $content[$entry] = '0';
84 // Extension updates found
85 $value = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', true, " AND `status`='NEW' AND `task_type`='EXTENSION_UPDATE'");
88 $content['update_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=updates%}">' . $value . '</a>';
92 // First check for all account status seperately
95 $value = getTotalConfirmedUser();
98 $content['confirmed_members'] = '<a href="{%url=modules.php?module=admin&what=list_user&status=confirmed%}">' . $value . '</a>';
101 // Unconfirmed accounts
102 $value = getTotalUnconfirmedUser();
105 $content['unconfirmed_members'] = '<a href="{%url=modules.php?module=admin&what=chk_regs%}">' . $value . '</a>';
109 // And locked accounts
110 $value = getTotalLockedUser();
112 $content['locked_members'] = '<a href="{%url=modules.php?module=admin&what=list_user&status=locked%}">' . $value . '</a>';
118 $value = countSumTotalData(0, 'task_system', 'id', 'assigned_admin', true, " AND `status` != 'DELETED'");
121 $content['new_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=unassigned%}">' . $value . '</a>';
127 $value = countSumTotalData('CLOSED', 'task_system', 'id', 'status', true);
130 $content['closed_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=closed%}">' . $value . '</a>';
136 $value = countSumTotalData('DELETED', 'task_system', 'id', 'status', true);
139 $content['deleted_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=deleted%}">' . $value . '</a>';
145 $value = countSumTotalData('SOLVED', 'task_system', 'id', 'status', true, sprintf(" AND `assigned_admin`=%s", getCurrentAdminId()));
148 $content['solved_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=solved%}">' . $value . '</a>';
154 $value = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', true, " AND `status`='NEW' AND task_type != 'EXTENSION_UPDATE'");
157 $content['your_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task%}">' . $value . '</a>';
161 // Mails waiting to be approved
163 $value = countSumTotalData('ADMIN', 'pool', 'id', 'data_type', true);
166 $content['pending_mails'] = '<a href="{%url=modules.php?module=admin&what=unlock_emails%}">' . $value . '</a>';
170 // Unfinished mail orders
172 $value = countSumTotalData('TEMP', 'pool', 'id', 'data_type', true);
175 $content['canceled_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
181 $value = countSumTotalData('SEND', 'pool', 'id', 'data_type', true);
184 $content['send_emails'] = '<a href="{%url=modules.php?module=admin&what=email_archiv%}">' . $value . '</a>';
190 if (isExtensionActive('autopurge')) {
191 // Get auto-purged mails
192 $value = countSumTotalData('DELETED', 'pool', 'id', 'data_type', true);
195 $content['purged_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
199 // Autopurged bonus mails
201 if (isExtensionInstalledAndNewer('bonus', '0.1.8')) {
202 // Get auto-purged bonus mails
203 $value = countSumTotalData('DELETED', 'bonus', 'id', 'data_type', true);
206 $content['purged_bonus_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
208 } elseif (isExtensionActive('bonus')) {
209 $content['purged_bonus_mails'] = getMaskedMessage('ADMIN_EXTENSION_BONUS_OUTDATED', '0.1.8');
211 $content['purged_bonus_mails'] = '<span class="notice">{--ADMIN_EXTENSION_BONUS_404--}</span>';
214 $content['purged_bonus_mails'] = '<span class="notice">{--ADMIN_EXTENSION_AUTOPURGE_404--}</span>';
215 $content['purged_mails'] = '<span class="notice">{--ADMIN_EXTENSION_AUTOPURGE_404--}</span>';
221 if (isExtensionInstalledAndNewer('bonus', '0.1.8')) {
222 // Get sent bonus mails (but not notifications)
223 $value = countSumTotalData('SEND', 'bonus', 'id', 'data_type', true, " AND `is_notify`='N'");
226 $content['send_bonus_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
228 } elseif (isExtensionActive('bonus')) {
229 $content['send_bonus_mails'] = getMaskedMessage('ADMIN_EXTENSION_BONUS_OUTDATED', '0.1.8');
231 $content['send_bonus_mails'] = '{--ADMIN_EXTENSION_BONUS_404--}';
234 if (isExtensionActive('autopurge')) {
235 // Start finding them...
238 // Check for more extensions
239 // @TODO These can be rewritten to filter
240 if (isValidUserId(getDefRefid())) $EXCLUDE_LIST .= ' AND d.`userid` != {?def_refid?}';
241 if (isExtensionActive('beg')) $EXCLUDE_LIST .= ' AND d.`userid` != {?beg_userid?}';
242 if (isExtensionActive('bonus')) $EXCLUDE_LIST .= ' AND d.`userid` != {?bonus_userid?}';
243 if (isExtensionActive('doubler')) $EXCLUDE_LIST .= ' AND d.`userid` != {?doubler_userid?}';
244 if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
245 // Recent ext-holiday found
246 $EXCLUDE_LIST .= " AND d.`holiday_active`='N'";
249 // Check for all accounts
251 d.userid, d.email, d.last_online
253 `{?_MYSQL_PREFIX?}_user_data` AS d
255 d.`status`='CONFIRMED' AND
256 (UNIX_TIMESTAMP() - d.`joined`) >= {?ap_inactive_since?} AND
257 (UNIX_TIMESTAMP() - d.`last_online`) >= {?ap_inactive_since?} AND
258 (UNIX_TIMESTAMP() - d.`ap_notified`) >= {?ap_inactive_since?}
262 $WHATs[] = 'list_autopurge';
263 $DESCRs[] = '{--ADMIN_TASK_INACTIVE_AUTOPURGE--}';
264 $TITLEs[] = '{--ADMIN_TASK_INACTIVE_AUTOPURGE_TITLE--}';
267 if (isExtensionInstalledAndNewer('sql_patches', '0.3.4')) {
268 // Check for accounts without referal
269 addSql("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `refid`=0 ORDER BY `userid` ASC");
270 $DESCRs[] = '{--ADMIN_TASK_LIST_ACCOUNT_NOREF--}';
271 $TITLEs[] = '{--ADMIN_TASK_LIST_ACCOUNT_NOREFERAL_TITLE--}';
272 $WHATs[] = 'list_user&mode=norefs';
275 if (isExtensionActive('payout')) {
276 // List new payout requests
277 addSql("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `status`='NEW' ORDER BY `userid` ASC");
278 $WHATs[] = 'list_payouts';
279 $DESCRs[] = '{--ADMIN_TASK_LIST_PAYOUTS_WAITING--}';
280 $TITLEs[] = '{--ADMIN_TASK_LIST_PAYOUTS_WAITING_TITLE--}';
281 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_payouts` ORDER BY `userid` ASC');
282 $WHATs[] = 'list_payouts';
283 $DESCRs[] = '{--ADMIN_TASK_LIST_PAYOUTS_ALL--}';
284 $TITLEs[] = '{--ADMIN_TASK_LIST_PAYOUTS_ALL_TITLE--}';
287 if (isExtensionActive('wernis')) {
288 // List new wernis requests
289 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_wernis` ORDER BY `userid` ASC');
290 $WHATs[] = 'list_wernis';
291 $DESCRs[] = '{--ADMIN_TASK_LIST_WERNIS_ALL--}';
292 $TITLEs[] = '{--ADMIN_TASK_LIST_WERNIS_ALL_TITLE--}';
295 if (isExtensionActive('primera')) {
296 // List new primera requests
297 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_primera` ORDER BY `userid` ASC');
298 $WHATs[] = 'list_primera';
299 $DESCRs[] = '{--ADMIN_TASK_LIST_PRIMERA_ALL--}';
300 $TITLEs[] = '{--ADMIN_TASK_LIST_PRIMERA_ALL_TITLE--}';
303 if (isExtensionActive('holiday')) {
304 // List holiday requests
305 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_holidays` ORDER BY `userid` ASC');
306 $WHATs[] = 'list_holiday';
307 $DESCRs[] = '{--ADMIN_TASK_LIST_HOLIDAYS--}';
308 $TITLEs[] = '{--ADMIN_TASK_LIST_HOLIDAYS_TITLE--}';
311 if (isExtensionInstalledAndNewer('bonus', '0.8.7')) {
312 // List all notifications
313 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `is_notify`='Y' ORDER BY `timestamp` DESC");
314 $WHATs[] = 'list_notifications';
315 $DESCRs[] = '{--ADMIN_TASK_LIST_NOTIFICATIONS--}';
316 $TITLEs[] = '{--ADMIN_TASK_LIST_NOTIFICATIONS_TITLE--}';
319 if (isExtensionInstalledAndNewer('bonus', '0.2.3')) {
321 if (isExtensionInstalledAndNewer('bonus', '0.6.9')) {
322 // Add more bonus points here
324 if (getConfig('bonus_click_yn') == 'Y') $USE .= ' + `turbo_bonus`';
325 if (getConfig('bonus_login_yn') == 'Y') $USE .= ' + `login_bonus`';
326 if (getConfig('bonus_order_yn') == 'Y') $USE .= ' + `bonus_order`';
327 if (getConfig('bonus_stats_yn') == 'Y') $USE .= ' + `bonus_stats`';
328 if (getConfig('bonus_ref_yn') == 'Y') $USE .= ' + `bonus_ref`';
332 $USE = 'turbo_bonus';
338 // Autopurge installed?
339 if ((isExtensionActive('autopurge')) && (isAutopurgeInactiveEnabled()) && (getApInactiveSince() > 0)) {
340 // Use last online timestamp to keep inactive members away from here
341 $lastOnline = ' AND (UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?}';
345 " . $USE . " AS `points`
347 `{?_MYSQL_PREFIX?}_user_data`
349 `status`='CONFIRMED' AND
355 $WHATs[] = 'list_bonus';
356 $DESCRs[] = '{--ADMIN_TASK_LIST_BONUS--}';
357 $TITLEs[] = '{--ADMIN_TASK_LIST_BONUS_TITLE--}';
360 if (isExtensionInstalledAndNewer('beg', '0.1.2')) {
361 // ----- Begging rallye -----
366 // Autopurge installed?
367 if ((isExtensionActive('autopurge')) && (isAutopurgeInactiveEnabled()) && (getApInactiveSince() > 0)) {
368 // Use last online timestamp to keep inactive members away from here
369 $lastOnline = ' AND (UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?}';
375 `{?_MYSQL_PREFIX?}_user_data`
377 `status`='CONFIRMED' AND
383 $WHATs[] = 'list_beg';
384 $DESCRs[] = '{--ADMIN_TASK_LIST_BEG--}';
385 $TITLEs[] = '{--ADMIN_TASK_LIST_BEG_TITLE--}';
388 if (isExtensionActive('doubler')) {
389 // List waiting payouts
390 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_doubler` WHERE `completed`='N' ORDER BY `id` ASC");
391 $WHATs[] = 'list_doubler&mode=waiting&select=all';
392 $DESCRs[] = '{--ADMIN_TASK_LIST_DOUBLER_WAITING--}';
393 $TITLEs[] = '{--ADMIN_TASK_LIST_DOUBLER_WAITING_TITLE--}';
394 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_doubler` ORDER BY `id` ASC');
395 $WHATs[] = 'list_doubler';
396 $DESCRs[] = '{--ADMIN_TASK_LIST_DOUBLER_ALL--}';
397 $TITLEs[] = '{--ADMIN_TASK_LIST_DOUBLER_ALL_TITLE--}';
401 // All referal banner
403 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY `id` ASC');
404 $WHATs[] = 'refbanner';
405 $DESCRs[] = '{--ADMIN_TASK_LIST_REFBANNER_ALL--}';
406 $TITLEs[] = '{--ADMIN_TASK_LIST_REFBANNER_ALL_TITLE--}';
409 // All activated referal banner
411 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `visible`='Y' ORDER BY `id` ASC");
412 $WHATs[] = 'refbanner';
413 $DESCRs[] = '{--ADMIN_TASK_LIST_REFBANNER_ACTIVE--}';
414 $TITLEs[] = '{--ADMIN_TASK_LIST_REFBANNER_ACTIVE_TITLE--}';
419 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` ORDER BY `id` ASC');
420 $WHATs[] = 'extensions';
421 $DESCRs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ALL--}';
422 $TITLEs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ALL_TITLE--}';
425 // All activated extensions
427 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_active`='Y' ORDER BY `id` ASC");
428 $WHATs[] = 'extensions&active=Y';
429 $DESCRs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ACTIVE--}';
430 $TITLEs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ACTIVE_TITLE--}';
432 if (isExtensionActive('sponsor')) {
434 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` ORDER BY `id` ASC');
435 $WHATs[] = 'list_sponsor';
436 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR--}';
437 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_TITLE--}';
439 // List confirmed sponsor accounts
440 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='CONFIRMED' ORDER BY `id` ASC");
441 $WHATs[] = 'list_sponsor';
442 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_CONFIRMED--}';
443 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_CONFIRMED_TITLE--}';
445 // List unconfirmed sponsor accounts
446 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='UNCONFIRMED' ORDER BY `id` ASC");
447 $WHATs[] = 'list_sponsor';
448 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_UNCONFIRMED--}';
449 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_UNCONFIRMED_TITLE--}';
451 // List locked sponsor accounts
452 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='LOCKED' ORDER BY `id` ASC");
453 $WHATs[] = 'list_sponsor';
454 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_LOCKED--}';
455 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_LOCKED_TITLE--}';
457 // List waiting sponsor accounts to be approved
458 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='PENDING' ORDER BY `id` ASC");
459 $WHATs[] = 'unlock_sponsor';
460 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_PENDING--}';
461 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_PENDING_TITLE--}';
464 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_orders` WHERE `pay_status`='PENDING' ORDER BY `id` ASC");
465 $WHATs[] = 'list_sponsor_pays';
466 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_ORDERS--}';
467 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_ORDERS_TITLE--}';
470 if (isExtensionActive('country')) {
471 // List country codes
472 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_countries` ORDER BY `id` ASC');
473 $WHATs[] = 'list_country';
474 $DESCRs[] = '{--ADMIN_TASK_LIST_COUNTRY--}';
475 $TITLEs[] = '{--ADMIN_TASK_LIST_COUNTRY_TITLE--}';
478 if (isExtensionActive('theme')) {
480 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` ORDER BY `id` ASC');
481 $WHATs[] = 'theme_edit';
482 $DESCRs[] = '{--ADMIN_TASK_LIST_THEME_ALL--}';
483 $TITLEs[] = '{--ADMIN_TASK_LIST_THEME_ALL_TITLE--}';
485 // List active themes
486 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_active`='Y' ORDER BY `id` ASC");
487 $WHATs[] = 'theme_edit';
488 $DESCRs[] = '{--ADMIN_TASK_LIST_THEME_ACTIVE--}';
489 $TITLEs[] = '{--ADMIN_TASK_LIST_THEME_ACTIVE_TITLE--}';
492 if (isExtensionActive('admins')) {
493 // List all administrator logins
494 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC');
495 $WHATs[] = 'admins_edit';
496 $DESCRs[] = '{--ADMIN_TASK_LIST_ADMINS_ALL--}';
497 $TITLEs[] = '{--ADMIN_TASK_LIST_ADMINS_ALL_TITLE--}';
500 if (isExtensionActive('surfbar')) {
501 // List all URLs in surfbar
502 addSql('SELECT `url_id` FROM `{?_MYSQL_PREFIX?}_surfbar_urls` ORDER BY `url_id` ASC');
503 $WHATs[] = 'list_surfbar_urls';
504 $DESCRs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_ALL--}';
505 $TITLEs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_ALL_TITLE--}';
507 // List all pending URLs in surfbar
508 addSql("SELECT `url_id` FROM `{?_MYSQL_PREFIX?}_surfbar_urls` WHERE `url_status`='PENDING' ORDER BY `url_id` ASC");
509 $WHATs[] = 'unlock_surfbar_urls';
510 $DESCRs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_PENDING--}';
511 $TITLEs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_PENDING_TITLE--}';
514 // Generate extra overview rows
515 $EXTRAS .= createExtraTaskRows($WHATs, $DESCRs, $TITLEs);
517 // If empty just keep a forced-space left for CSS issues
518 if (empty($EXTRAS)) {
522 // Add compiled string to constant for final template
523 $content['extra_table'] = $EXTRAS;
525 // Simply load the template... :-)
526 loadTemplate('admin_overview_task', false, $content);
530 function createExtraTaskRows ($WHATs, $DESCRs, $TITLEs) {
534 // Sadly this cannot be rewritten to a filter... :(
535 foreach (getSqls() as $sqls) {
537 foreach ($sqls as $key => $sql) {
538 // Run SQL command, get line numbers and free memory
539 $result = SQL_QUERY($sql, __FUNCTION__, __LINE__);
541 // Prepare array for output
543 'row_descr' => $DESCRs[$key],
547 // Rewrite CSS class if not last entry is reached
548 if ($key < (count($sqls) - 1)) {
549 $content['bottom'] = 'bottom';
552 if ((!SQL_HASZERONUMS($result)) && (!empty($WHATs[$key]))) {
553 if (empty($TITLEs[$key])) {
554 $TITLEs[$key] = '{--ADMIN_TASK_UNKNOWN_LIST_TITLE--}';
556 $content['row_link'] = '<a href="{%url=modules.php?module=admin&what=' . $WHATs[$key] . '%}" title="' . $TITLEs[$key] . '">' . SQL_NUMROWS($result) . '</a>';
558 $content['row_link'] = '0';
562 SQL_FREERESULT($result);
564 // And insert the final string into extras template
565 $OUT .= loadTemplate('admin_overview_task_rows', true, $content);
569 // Return output in the template
570 return loadTemplate('admin_overview_task_extras', true, $OUT);