Rewrites to use filters instead of mass if() blocks
[mailer.git] / inc / daily / daily_birthday.php
index 42273b6f314564adfb3c0d85e8244a3b8f54181e..beae7944a22e7d32b1c66ee299641e55687683f1 100644 (file)
@@ -16,8 +16,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
 // Some security stuff...
 if (!defined('__SECURITY')) {
        die();
-} elseif ((!isHtmlOutputMode()) || (!isResetModeEnabled())) {
-       // Do not execute when script is in CSS mode
+} elseif ((!isHtmlOutputMode()) || (!isDailyResetEnabled())) {
+       // Do not execute when script is in non-HTML mode
        return;
 } elseif (!isExtensionActive('birthday')) {
        // Extension not active/installed
-       logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.');
+       if (isDebugModeEnabled()) logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension ext-birthday disabled.');
        return;
 }
 
@@ -55,27 +55,38 @@ $day   = getDay();
 $month = getMonth();
 $year  = getYear();
 
-// Init variable
+// Init variables
 $lastOnline = '';
+$excludeSql = '';
 
 // Shall I include only active members?
-if ((getConfig('birthday_active')  == 'Y') && (isExtensionActive('autopurge')) && (isBegActiveEnabled()) && ((getApInactiveSince() > 0))) {
-       $add = ' AND (UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?}';
+if ((getConfig('birthday_active')  == 'Y') && (isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
+       $excludeSql = ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
+} // END - if
+
+// Is ext-holiday installed?
+// @TODO Rewrite these if() blocks to a filter
+if (isExtensionActive('holiday')) {
+       // Exclude those as well
+       $excludeSql .= " AND `d`.`holiday_active`='N'";
 } // END - if
 
 // Only confirmed members shall receive birthday mails...
 $result_birthday = SQL_QUERY_ESC("SELECT
-       `userid`, `email`, `birth_year`
+       `d`.`userid`,
+       `d`.`email`,
+       `d`.`birth_year`
 FROM
-       `{?_MYSQL_PREFIX?}_user_data`
+       `{?_MYSQL_PREFIX?}_user_data` AS `d`
 WHERE
-       `status`='CONFIRMED' AND
-       `birth_day`=%s AND
-       `birth_month`=%s AND
-       `birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
-       ".$lastOnline."
+       `d`.`status`='CONFIRMED'
+       " . runFilterChain('user_exclusion_sql', $excludeSql) . " AND
+       `d`.`birth_day`=%s AND
+       `d`.`birth_month`=%s AND
+       `d`.`birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
+       " . $lastOnline . "
 ORDER BY
-       `userid` ASC",
+       `d`.`userid` ASC",
        array($day, $month), __FILE__, __LINE__);
 
 if (!SQL_HASZERONUMS($result_birthday)) {
@@ -88,13 +99,13 @@ if (!SQL_HASZERONUMS($result_birthday)) {
                // Simply subtract both values and you got the age... :)
                $age = $now - $bd;
 
-               if (getConfig('birthday_points') > 0) {
+               if (getBirthdayPoints() > 0) {
                        // Add more entries to the array
                        $content['age']    = $age;
                        $content['check']  = '';
 
                        // @TODO 4 is hard-coded here, should we move it out in config?
-                       for ($idx = '0'; $idx < 4; $idx++) {
+                       for ($idx = 0; $idx < 4; $idx++) {
                                $content['check'] .= generateRandomCode('8', mt_rand(0, $month . $day), $content['userid'], ($age * ($idx + 1)));
                        } // END - for
 
@@ -109,7 +120,7 @@ if (!SQL_HASZERONUMS($result_birthday)) {
                        $message = loadEmailTemplate('member_birthday_confirm', $content, bigintval($content['userid']));
                } else {
                        // Load default email template and fill in the age
-                       $message = loadEmailTemplate('member_birthday', $age, $content['userid']);
+                       $message = loadEmailTemplate('member_birthday', $content, $content['userid']);
                }
 
                // Send email