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://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','random_refid',
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=list_user&status=UNCONFIRMED%}">' . $value . '</a>';
108 // And locked accounts
109 $value = getTotalLockedUser();
111 $content['locked_members'] = '<a href="{%url=modules.php?module=admin&what=list_user&status=locked%}">' . $value . '</a>';
114 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
116 $value = getTotalRandomRefidUser();
118 $content['random_refid'] = '<a href="{%url=modules.php?module=admin&what=list_user&mode=random_refid%}">' . $value . '</a>';
125 $value = countSumTotalData(0, 'task_system', 'id', 'assigned_admin', true, " AND `status` != 'DELETED'");
128 $content['new_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=unassigned%}">' . $value . '</a>';
134 $value = countSumTotalData('CLOSED', 'task_system', 'id', 'status', true);
137 $content['closed_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=closed%}">' . $value . '</a>';
143 $value = countSumTotalData('DELETED', 'task_system', 'id', 'status', true);
146 $content['deleted_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=deleted%}">' . $value . '</a>';
152 $value = countSumTotalData('SOLVED', 'task_system', 'id', 'status', true, sprintf(" AND `assigned_admin`=%s", getCurrentAdminId()));
155 $content['solved_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task&type=solved%}">' . $value . '</a>';
161 $value = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', true, " AND `status`='NEW' AND task_type != 'EXTENSION_UPDATE'");
164 $content['your_tasks'] = '<a href="{%url=modules.php?module=admin&what=list_task%}">' . $value . '</a>';
168 // Mails waiting to be approved
170 $value = countSumTotalData('ADMIN', 'pool', 'id', 'data_type', true);
173 $content['pending_mails'] = '<a href="{%url=modules.php?module=admin&what=unlock_emails%}">' . $value . '</a>';
177 // Unfinished mail orders
179 $value = countSumTotalData('TEMP', 'pool', 'id', 'data_type', true);
182 $content['canceled_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
188 $value = countSumTotalData('SEND', 'pool', 'id', 'data_type', true);
191 $content['send_emails'] = '<a href="{%url=modules.php?module=admin&what=email_archiv%}">' . $value . '</a>';
197 if (isExtensionActive('autopurge')) {
198 // Get auto-purged mails
199 $value = countSumTotalData('DELETED', 'pool', 'id', 'data_type', true);
202 $content['purged_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
206 // Autopurged bonus mails
208 if (isExtensionInstalledAndNewer('bonus', '0.1.8')) {
209 // Get auto-purged bonus mails
210 $value = countSumTotalData('DELETED', 'bonus', 'id', 'data_type', true);
213 $content['purged_bonus_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
215 } elseif (isExtensionActive('bonus')) {
216 $content['purged_bonus_mails'] = '{%message,ADMIN_EXTENSION_BONUS_OUTDATED=0.1.8%}';
218 $content['purged_bonus_mails'] = '<span class="bad">{--ADMIN_EXTENSION_BONUS_404--}</span>';
221 $content['purged_bonus_mails'] = '<span class="bad">{--ADMIN_EXTENSION_AUTOPURGE_404--}</span>';
222 $content['purged_mails'] = '<span class="bad">{--ADMIN_EXTENSION_AUTOPURGE_404--}</span>';
228 if (isExtensionInstalledAndNewer('bonus', '0.1.8')) {
229 // Get sent bonus mails (but not notifications)
230 $value = countSumTotalData('SEND', 'bonus', 'id', 'data_type', true, " AND `is_notify`='N'");
233 $content['send_bonus_mails'] = '<a href="{%url=modules.php?module=admin&what=email_details%}">' . $value . '</a>';
235 } elseif (isExtensionActive('bonus')) {
236 $content['send_bonus_mails'] = '{%message,ADMIN_EXTENSION_BONUS_OUTDATED=0.1.8%}';
238 $content['send_bonus_mails'] = '{--ADMIN_EXTENSION_BONUS_404--}';
241 // Both extensions must be there
242 if ((isExtensionActive('autopurge')) && (isExtensionActive('user'))) {
243 // Start finding them...
246 // Check for more extensions
247 // @TODO These can be rewritten to filter
248 if (isValidUserId(getDefRefid())) $EXCLUDE_LIST .= ' AND d.`userid` != {?def_refid?}';
249 if (isExtensionActive('beg')) $EXCLUDE_LIST .= ' AND d.`userid` != {?beg_userid?}';
250 if (isExtensionActive('bonus')) $EXCLUDE_LIST .= ' AND d.`userid` != {?bonus_userid?}';
251 if (isExtensionActive('doubler')) $EXCLUDE_LIST .= ' AND d.`userid` != {?doubler_userid?}';
252 if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
253 // Recent ext-holiday found
254 $EXCLUDE_LIST .= " AND d.`holiday_active`='N'";
257 // Check for all accounts
259 d.userid, d.email, d.last_online
261 `{?_MYSQL_PREFIX?}_user_data` AS d
263 d.`status`='CONFIRMED' AND
264 (UNIX_TIMESTAMP() - d.`joined`) >= {?ap_inactive_since?} AND
265 (UNIX_TIMESTAMP() - d.`last_online`) >= {?ap_inactive_since?} AND
266 (UNIX_TIMESTAMP() - d.`ap_notified`) >= {?ap_inactive_since?}
270 $WHATs[] = 'list_autopurge';
271 $DESCRs[] = '{--ADMIN_TASK_INACTIVE_AUTOPURGE--}';
272 $TITLEs[] = '{--ADMIN_TASK_INACTIVE_AUTOPURGE_TITLE--}';
275 if ((isExtensionInstalledAndNewer('sql_patches', '0.3.4')) && (isExtensionActive('user'))) {
276 // Check for accounts without referral
277 addSql("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `refid`=0 OR `refid` IS NULL ORDER BY `userid` ASC");
278 $DESCRs[] = '{--ADMIN_TASK_LIST_ACCOUNT_NO_REFERRAL--}';
279 $TITLEs[] = '{--ADMIN_TASK_LIST_ACCOUNT_NO_REFERRAL_TITLE--}';
280 $WHATs[] = 'list_user&mode=norefs';
283 if (isExtensionActive('payout')) {
284 // List new payout requests
285 addSql("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `status`='NEW' ORDER BY `userid` ASC");
286 $WHATs[] = 'list_payouts';
287 $DESCRs[] = '{--ADMIN_TASK_LIST_PAYOUTS_WAITING--}';
288 $TITLEs[] = '{--ADMIN_TASK_LIST_PAYOUTS_WAITING_TITLE--}';
289 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_payouts` ORDER BY `userid` ASC');
290 $WHATs[] = 'list_payouts';
291 $DESCRs[] = '{--ADMIN_TASK_LIST_PAYOUTS_ALL--}';
292 $TITLEs[] = '{--ADMIN_TASK_LIST_PAYOUTS_ALL_TITLE--}';
295 if (isExtensionActive('wernis')) {
296 // List new wernis requests
297 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_wernis` ORDER BY `userid` ASC');
298 $WHATs[] = 'list_wernis';
299 $DESCRs[] = '{--ADMIN_TASK_LIST_WERNIS_ALL--}';
300 $TITLEs[] = '{--ADMIN_TASK_LIST_WERNIS_ALL_TITLE--}';
303 if (isExtensionActive('primera')) {
304 // List new primera requests
305 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_primera` ORDER BY `userid` ASC');
306 $WHATs[] = 'list_primera';
307 $DESCRs[] = '{--ADMIN_TASK_LIST_PRIMERA_ALL--}';
308 $TITLEs[] = '{--ADMIN_TASK_LIST_PRIMERA_ALL_TITLE--}';
311 if (isExtensionActive('holiday')) {
312 // List holiday requests
313 addSql('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_holidays` ORDER BY `userid` ASC');
314 $WHATs[] = 'list_holiday';
315 $DESCRs[] = '{--ADMIN_TASK_LIST_HOLIDAYS--}';
316 $TITLEs[] = '{--ADMIN_TASK_LIST_HOLIDAYS_TITLE--}';
319 if (isExtensionInstalledAndNewer('bonus', '0.8.7')) {
320 // List all notifications
321 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `is_notify`='Y' ORDER BY `timestamp` DESC");
322 $WHATs[] = 'list_notifications';
323 $DESCRs[] = '{--ADMIN_TASK_LIST_NOTIFICATIONS--}';
324 $TITLEs[] = '{--ADMIN_TASK_LIST_NOTIFICATIONS_TITLE--}';
327 // Both extensions must be there
328 if ((isExtensionInstalledAndNewer('bonus', '0.2.3')) && (isExtensionActive('user'))) {
330 $add = runFilterChain('add_bonus_points_user_columns', '');
332 // Active rallye, so add more point columns, if not empty
333 $USE = '`turbo_bonus`';
335 $USE = '(0' . $add . ')';
341 // Autopurge installed?
342 if ((isExtensionActive('autopurge')) && (isAutopurgeInactiveEnabled()) && (getApInactiveSince() > 0)) {
343 // Use last online timestamp to keep inactive members away from here
344 $lastOnline = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
348 " . $USE . " AS `points`
350 `{?_MYSQL_PREFIX?}_user_data`
352 `status`='CONFIRMED' AND
358 $WHATs[] = 'list_bonus';
359 $DESCRs[] = '{--ADMIN_TASK_LIST_BONUS--}';
360 $TITLEs[] = '{--ADMIN_TASK_LIST_BONUS_TITLE--}';
363 // Again both extensions must be there
364 if ((isExtensionInstalledAndNewer('beg', '0.1.2')) && (isExtensionActive('user'))) {
365 // ----- Begging rallye -----
370 // Autopurge installed?
371 if ((isExtensionActive('autopurge')) && (isAutopurgeInactiveEnabled()) && (getApInactiveSince() > 0)) {
372 // Use last online timestamp to keep inactive members away from here
373 $lastOnline = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
379 `{?_MYSQL_PREFIX?}_user_data`
381 `status`='CONFIRMED' AND
387 $WHATs[] = 'list_beg';
388 $DESCRs[] = '{--ADMIN_TASK_LIST_BEG--}';
389 $TITLEs[] = '{--ADMIN_TASK_LIST_BEG_TITLE--}';
392 if (isExtensionActive('doubler')) {
393 // List waiting payouts
394 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_doubler` WHERE `completed`='N' ORDER BY `id` ASC");
395 $WHATs[] = 'list_doubler&mode=waiting&select=all';
396 $DESCRs[] = '{--ADMIN_TASK_LIST_DOUBLER_WAITING--}';
397 $TITLEs[] = '{--ADMIN_TASK_LIST_DOUBLER_WAITING_TITLE--}';
398 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_doubler` ORDER BY `id` ASC');
399 $WHATs[] = 'list_doubler';
400 $DESCRs[] = '{--ADMIN_TASK_LIST_DOUBLER_ALL--}';
401 $TITLEs[] = '{--ADMIN_TASK_LIST_DOUBLER_ALL_TITLE--}';
405 // All referral banner
407 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY `id` ASC');
408 $WHATs[] = 'refbanner';
409 $DESCRs[] = '{--ADMIN_TASK_LIST_REFBANNER_ALL--}';
410 $TITLEs[] = '{--ADMIN_TASK_LIST_REFBANNER_ALL_TITLE--}';
413 // All activated referral banner
415 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `visible`='Y' ORDER BY `id` ASC");
416 $WHATs[] = 'refbanner';
417 $DESCRs[] = '{--ADMIN_TASK_LIST_REFBANNER_ACTIVE--}';
418 $TITLEs[] = '{--ADMIN_TASK_LIST_REFBANNER_ACTIVE_TITLE--}';
423 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` ORDER BY `id` ASC');
424 $WHATs[] = 'extensions';
425 $DESCRs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ALL--}';
426 $TITLEs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ALL_TITLE--}';
429 // All activated extensions
431 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_active`='Y' ORDER BY `id` ASC");
432 $WHATs[] = 'extensions&active=Y';
433 $DESCRs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ACTIVE--}';
434 $TITLEs[] = '{--ADMIN_TASK_LIST_EXTENSIONS_ACTIVE_TITLE--}';
436 if (isExtensionActive('sponsor')) {
438 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` ORDER BY `id` ASC');
439 $WHATs[] = 'list_sponsor';
440 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR--}';
441 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_TITLE--}';
443 // List confirmed sponsor accounts
444 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='CONFIRMED' ORDER BY `id` ASC");
445 $WHATs[] = 'list_sponsor';
446 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_CONFIRMED--}';
447 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_CONFIRMED_TITLE--}';
449 // List unconfirmed sponsor accounts
450 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='UNCONFIRMED' ORDER BY `id` ASC");
451 $WHATs[] = 'list_sponsor';
452 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_UNCONFIRMED--}';
453 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_UNCONFIRMED_TITLE--}';
455 // List locked sponsor accounts
456 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='LOCKED' ORDER BY `id` ASC");
457 $WHATs[] = 'list_sponsor';
458 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_LOCKED--}';
459 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_LOCKED_TITLE--}';
461 // List waiting sponsor accounts to be approved
462 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `status`='PENDING' ORDER BY `id` ASC");
463 $WHATs[] = 'unlock_sponsor';
464 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_PENDING--}';
465 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_PENDING_TITLE--}';
468 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_orders` WHERE `pay_status`='PENDING' ORDER BY `id` ASC");
469 $WHATs[] = 'list_sponsor_pays';
470 $DESCRs[] = '{--ADMIN_TASK_LIST_SPONSOR_ORDERS--}';
471 $TITLEs[] = '{--ADMIN_TASK_LIST_SPONSOR_ORDERS_TITLE--}';
474 if (isExtensionActive('country')) {
475 // List country codes
476 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_countries` ORDER BY `id` ASC');
477 $WHATs[] = 'list_country';
478 $DESCRs[] = '{--ADMIN_TASK_LIST_COUNTRY--}';
479 $TITLEs[] = '{--ADMIN_TASK_LIST_COUNTRY_TITLE--}';
482 if (isExtensionActive('theme')) {
484 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` ORDER BY `id` ASC');
485 $WHATs[] = 'theme_edit';
486 $DESCRs[] = '{--ADMIN_TASK_LIST_THEME_ALL--}';
487 $TITLEs[] = '{--ADMIN_TASK_LIST_THEME_ALL_TITLE--}';
489 // List active themes
490 addSql("SELECT `id` FROM `{?_MYSQL_PREFIX?}_themes` WHERE `theme_active`='Y' ORDER BY `id` ASC");
491 $WHATs[] = 'theme_edit';
492 $DESCRs[] = '{--ADMIN_TASK_LIST_THEME_ACTIVE--}';
493 $TITLEs[] = '{--ADMIN_TASK_LIST_THEME_ACTIVE_TITLE--}';
496 if (isExtensionActive('admins')) {
497 // List all administrator logins
498 addSql('SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC');
499 $WHATs[] = 'admins_edit';
500 $DESCRs[] = '{--ADMIN_TASK_LIST_ADMINS_ALL--}';
501 $TITLEs[] = '{--ADMIN_TASK_LIST_ADMINS_ALL_TITLE--}';
504 if (isExtensionActive('surfbar')) {
505 // List all URLs in surfbar
506 addSql('SELECT `url_id` FROM `{?_MYSQL_PREFIX?}_surfbar_urls` ORDER BY `url_id` ASC');
507 $WHATs[] = 'list_surfbar_urls';
508 $DESCRs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_ALL--}';
509 $TITLEs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_ALL_TITLE--}';
511 // List all pending URLs in surfbar
512 addSql("SELECT `url_id` FROM `{?_MYSQL_PREFIX?}_surfbar_urls` WHERE `url_status`='PENDING' ORDER BY `url_id` ASC");
513 $WHATs[] = 'unlock_surfbar_urls';
514 $DESCRs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_PENDING--}';
515 $TITLEs[] = '{--ADMIN_TASK_LIST_SURFBAR_URLS_PENDING_TITLE--}';
518 // Generate extra overview rows
519 $EXTRAS .= createExtraTaskRows($WHATs, $DESCRs, $TITLEs);
521 // If empty just keep a forced-space left for CSS issues
522 if (empty($EXTRAS)) {
526 // Add compiled string to constant for final template
527 $content['extra_table'] = $EXTRAS;
529 // Simply load the template... :-)
530 loadTemplate('admin_overview_task', false, $content);
534 function createExtraTaskRows ($WHATs, $DESCRs, $TITLEs) {
538 // Sadly this cannot be rewritten to a filter... :(
539 foreach (getSqls() as $sqls) {
541 foreach ($sqls as $key => $sql) {
542 // Run SQL command, get line numbers and free memory
543 $result = SQL_QUERY($sql, __FUNCTION__, __LINE__);
545 // Prepare array for output
547 'row_descr' => $DESCRs[$key],
551 // Rewrite CSS class if not last entry is reached
552 if ($key < (count($sqls) - 1)) {
553 $content['bottom'] = 'bottom';
556 if ((!SQL_HASZERONUMS($result)) && (!empty($WHATs[$key]))) {
557 if (empty($TITLEs[$key])) {
558 $TITLEs[$key] = '{--ADMIN_TASK_UNKNOWN_LIST_TITLE--}';
560 $content['row_link'] = '<a href="{%url=modules.php?module=admin&what=' . $WHATs[$key] . '%}" title="' . $TITLEs[$key] . '">' . SQL_NUMROWS($result) . '</a>';
562 $content['row_link'] = '0';
566 SQL_FREERESULT($result);
568 // And insert the final string into extras template
569 $OUT .= loadTemplate('admin_overview_task_rows', true, $content);
573 // Return output in the template
574 return loadTemplate('admin_overview_task_extras', true, $OUT);