diff --git a/composer.json b/composer.json index 0c995a9..b883865 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,11 @@ "name":"Cliff Parnitzky", "email":"contao@cliff-parnitzky.de", "role":"Developer" + }, + { + "name":"Richard Henkenjohann", + "email":"richardhenkenjohann@googlemail.com", + "role":"Developer" } ], "support":{ @@ -18,10 +23,11 @@ }, "require":{ "php":">=5.3", - "contao/core":">=3.2.0,<3.5", + "contao/core":"~3.2", "contao-community-alliance/composer-plugin":"~2.0", "friends-of-contao/contao-associategroups":"~1.3", - "terminal42/notification_center":"~1.0" + "terminal42/notification_center":"~1.0", + "codefog/contao-haste":"~4.11" }, "conflict": { "contao/core":"3.4.0,3.4.1,3.4.2" @@ -32,9 +38,7 @@ "extra":{ "contao":{ "sources":{ - "system/modules/BirthdayMailer":"system/modules/BirthdayMailer", - "files/tiny_templates/birthdaymailer_default_de.html": "files/tiny_templates/birthdaymailer_default_de.html", - "files/tiny_templates/birthdaymailer_default_en.html": "files/tiny_templates/birthdaymailer_default_en.html" + "system/modules/BirthdayMailer":"system/modules/BirthdayMailer" } }, "branch-alias": { diff --git a/files/tiny_templates/birthdaymailer_default_de.html b/files/tiny_templates/birthdaymailer_default_de.html deleted file mode 100644 index f78b27b..0000000 --- a/files/tiny_templates/birthdaymailer_default_de.html +++ /dev/null @@ -1,4 +0,0 @@ -

##birthdaychild_salutation## ##birthdaychild_firstname## ##birthdaychild_lastname##,

-

als Mitglied der Gruppe ##birthdaychild_groupname## gratulieren wir Ihnen recht herzlich zu Ihrem ##birthdaychild_age##. Geburtstag und wünschen Ihnen alles erdenklich Gute, viel Glück und vor allem Gesundheit.

-

Genießen Sie Ihren ganz besonderen Ehrentag.

-

Viele Grüße, ihr Contao [BirthdayMailer]

\ No newline at end of file diff --git a/files/tiny_templates/birthdaymailer_default_en.html b/files/tiny_templates/birthdaymailer_default_en.html deleted file mode 100644 index 5c67c15..0000000 --- a/files/tiny_templates/birthdaymailer_default_en.html +++ /dev/null @@ -1,4 +0,0 @@ -

##welcoming_formally## ##birthdaychild_firstname## ##birthdaychild_lastname##,

-

as a member of group ##birthdaymailer_groupname##, we heartily congratulate you on your ##birthdaychild_age##th birthday and wish you all the very best, good luck and health in particular.

-

Enjoy your very special day.

-

Best regards, yours Contao [BirthdayMailer]

\ No newline at end of file diff --git a/system/modules/BirthdayMailer/assets/.htaccess b/system/modules/BirthdayMailer/assets/.htaccess old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon.png b/system/modules/BirthdayMailer/assets/icon.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon_1.png b/system/modules/BirthdayMailer/assets/icon_1.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon_execute.png b/system/modules/BirthdayMailer/assets/icon_execute.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon_root.png b/system/modules/BirthdayMailer/assets/icon_root.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/classes/BirthdayMailSender.php b/system/modules/BirthdayMailer/classes/BirthdayMailSender.php deleted file mode 100644 index 9125518..0000000 --- a/system/modules/BirthdayMailer/classes/BirthdayMailSender.php +++ /dev/null @@ -1,452 +0,0 @@ -. - * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL - */ - -/** - * Run in a custom namespace, so the class can be replaced - */ -namespace BirthdayMailer; - -/** - * Class BirthdayMailSender - * - * Provide methods to send the birthday emails - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - */ -class BirthdayMailSender extends \Backend -{ - // the default language will always be englisch - const DEFAULT_LANGUAGE = 'en'; - - public function __construct() - { - parent::__construct(); - } - - /** - * Execute the sender manually from backend and get a result page. - */ - public function sendBirthdayMailManually() - { - if (TL_MODE == 'BE') - { - $result = $this->sendBirthdayMail(); - - // Create template object - $objTemplate = new \BackendTemplate('be_birthday-mailer'); - - $objTemplate->backLink = ''.$GLOBALS['TL_LANG']['MSC']['backBT'].''; - $objTemplate->headline = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['headline']; - $objTemplate->sendingHeadline = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['sendingHeadline']; - $objTemplate->success = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['successMessage'], $result['success']); - - $objTemplate->failed = sizeof($result['failed']) > 0; - $objTemplate->failureMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureMessage'], sizeof($result['failed'])); - $objTemplate->failureTableHead = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureTableHead']; - $objTemplate->failures = $result['failed']; - $objTemplate->failureInfo = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureInfo']; - - $objTemplate->aborted = sizeof($result['aborted']) > 0; - $objTemplate->abortionMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionMessage'], sizeof($result['aborted'])); - $objTemplate->abortionTableHead = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionTableHead']; - $objTemplate->abortions = $result['aborted']; - $objTemplate->abortionInfo = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionInfo']; - - if ($GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode']) - { - $objTemplate->developerMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['developerMessage'], $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperModeEmail']); - } - - return $this->replaceInsertTags($objTemplate->parse()); - } - return; - } - - /** - * Sends the birthday emails. - */ - public function sendBirthdayMail() - { - // first check if required extension 'associategroups' is installed - if (!in_array('associategroups', $this->Config->getActiveModules())) - { - $this->log('BirthdayMailSender: Extension "associategroups" is required!', 'BirthdayMailSender sendBirthdayMail()', TL_ERROR); - return false; - } - - $alreadySendTo = array(); - $notSendCauseOfError = array(); - $notSendCauseOfAbortion = array(); - - $config = $this->Database->prepare("SELECT tl_member.*, " - . "tl_member_group.name as memberGroupName, tl_member_group.disable as memberGroupDisable, tl_member_group.start as memberGroupStart, tl_member_group.stop as memberGroupStop, " - . "tl_birthdaymailer.sender as mailSender, tl_birthdaymailer.senderName as mailSenderName, tl_birthdaymailer.mailCopy as mailCopy, tl_birthdaymailer.mailBlindCopy as mailBlindCopy, " - . "tl_birthdaymailer.mailUseCustomText as mailUseCustomText, tl_birthdaymailer.mailTextKey as mailTextKey " - . "FROM tl_member " - . "JOIN tl_member_to_group ON tl_member_to_group.member_id = tl_member.id " - . "JOIN tl_member_group ON tl_member_group.id = tl_member_to_group.group_id " - . "JOIN tl_birthdaymailer ON tl_birthdaymailer.membergroup = tl_member_group.id " - . "ORDER BY tl_member.id, tl_birthdaymailer.sorting DESC") - ->execute(); - - if($config->numRows < 1) - { - return; - } - - while($config->next()) - { - if( - is_numeric($config->dateOfBirth) - && - ( - ( - $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode'] - && - $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperModeIgnoreDate'] - ) - || - ( - date("d.m") == date("d.m", $config->dateOfBirth) - ) - ) - && - ( - $this->isMemberActive($config) - && - $this->isMemberGroupActive($config) - && - $this->allowSendingDuplicates($alreadySendTo, $config) - ) - ) - { - // now check via custom hook, if sending should be aborted - $blnAbortSendMail = false; - if (isset($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail']) && is_array($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail'])) - { - foreach ($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail'] as $callback) - { - $this->import($callback[0]); - $blnAbortSendMail = $this->$callback[0]->$callback[1]($config, $blnAbortSendMail); - } - } - - if (!$blnAbortSendMail) - { - if ($this->sendMail($config)) - { - $alreadySendTo[] = $config->id; - } - else - { - $notSendCauseOfError[] = array('id' => $config->id, 'firstname' => $config->firstname, 'lastname' => $config->lastname, 'email' => $config->email); - } - } - else - { - $notSendCauseOfAbortion[] = array('id' => $config->id, 'firstname' => $config->firstname, 'lastname' => $config->lastname, 'email' => $config->email); - } - } - } - - $this->log('BirthdayMailer: Daily sending of birthday mail finished. Send ' . sizeof($alreadySendTo) . ' emails. ' - . sizeof($notSendCauseOfError) . ' emails could not be send due to errors. ' - . sizeof($notSendCauseOfAbortion) . ' emails were aborted due to custom hooks. See birthdaymails.log for details.', 'BirthdayMailSender sendBirthdayMail()', TL_CRON); - - return array('success' => sizeof($alreadySendTo), 'failed' => $notSendCauseOfError, 'aborted' => $notSendCauseOfAbortion); - } - - /** - * Get the text for specific types for the email. Fallback ist to 'default' if no text is set. - * FALLBACK Chain: - * 1. check, if there is a text for the specified textKey and language (search in system/config/langconfig.php) - * 2. if nothing found, check, if there is a text for the specified textKey and 'en' (search in system/config/langconfig.php) - * 3. if nothing found, get default text in specified language - * 4. if nothing found, get default text in language 'en' - */ - private function getEmailText ($textType, $config, $language) - { - $text = ""; - - if ($config->mailUseCustomText) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][$language]; - - if (strlen($text) == 0 && $language != self::DEFAULT_LANGUAGE) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][self::DEFAULT_LANGUAGE]; - } - } - - if (strlen($text) == 0) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail']['default'][$textType]; - } - - $textReplaced = $this->replaceBirthdayMailerInsertTags($text, $config, $language); - - if ($textReplaced) - { - return $textReplaced; - } - - return $text; - } - - /** - * Send an email. - * @return boolean - */ - private function sendMail($config) - { - $language = $config->language; - if (strlen($language) == 0) - { - $language = self::DEFAULT_LANGUAGE; - } - - $this->loadLanguageFile('BirthdayMailer', $language); - - $emailSubject = $this->getEmailText('subject', $config, $language); - $emailText = $this->getEmailText('text', $config, $language); - $emailHtml = $this->getEmailText('html', $config, $language); - - if ($GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode'] || $GLOBALS['TL_CONFIG']['birthdayMailerLogDebugInfo']) - { - $mailTextUsageOutput = $config->mailUseCustomText ? 'yes' : 'no'; - $this->log('BirthdayMailer: These are additional debugging information that will only be logged in developer mode or if debugging is enabled.' - . ' | Userlanguage = ' . $config->language - . ' | used language = ' . $language - . ' | mailTextUsage = ' . $mailTextUsageOutput - . ' | mailTextKey = ' . $config->mailTextKey - . ' | email = ' . $config->email - . ' | subject = ' . $emailSubject - . ' | text = ' . $emailText - . ' | html = ' . $emailHtml, 'BirthdayMailSender sendMail()', TL_CRON); - } - - $objEmail = new \Email(); - - $objEmail->logFile = 'birthdaymails.log'; - - $objEmail->from = $config->mailSender; - if (strlen($config->mailSenderName) > 0) - { - $objEmail->fromName = $config->mailSenderName; - } - $objEmail->subject = $emailSubject; - $objEmail->text = $emailText; - $objEmail->html = $emailHtml; - - try - { - $emailTo = $config->email; - - if ($GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode']) - { - $emailTo = $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperModeEmail']; - } - else - { - if (strlen($config->mailCopy) > 0) - { - $emailCC = trimsplit(',', $config->mailCopy); - $objEmail->sendCc($emailCC); - } - - if (strlen($config->mailBlindCopy) > 0) - { - $emailBCC = trimsplit(',', $config->mailBlindCopy); - $objEmail->sendBcc($emailBCC); - } - - $emailTo = $config->email; - } - return $objEmail->sendTo($emailTo); - } - catch (Swift_RfcComplianceException $e) - { - return false; - } - } - - /** - * Checks if the member is active. - * @return boolean - */ - private function isMemberActive($config) - { - if ($config->disable || - (strlen($config->start) > 0 && - $config->start > time()) || - (strlen($config->stop) > 0 && - $config->stop < time())) - { - return false; - } - return true; - } - - /** - * Checks if the associated group is active. - * @return boolean - */ - private function isMemberGroupActive($config) - { - if ($config->memberGroupDisable || - (strlen($config->memberGroupStart) > 0 && - $config->memberGroupStart > time()) || - (strlen($config->memberGroupStop) > 0 && - $config->memberGroupStop < time())) - { - return false; - } - return true; - } - - /** - * Checks if sending duplicate emails is allowed. - * @return boolean - */ - private function allowSendingDuplicates($alreadySendTo, $config) - { - if (!$GLOBALS['TL_CONFIG']['birthdayMailerAllowDuplicates'] && in_array($config->id, $alreadySendTo)) - { - return false; - } - return true; - } - - /** - * Delete an according configuration, if the member group is deleted. - */ - public function deleteConfiguration(DataContainer $dc) - { - $this->Database->prepare("DELETE FROM tl_birthdaymailer WHERE memberGroup = ?") - ->execute($dc->id); - } - - /** - * Replaces all insert tags for the email text. - */ - private function replaceBirthdayMailerInsertTags ($text, $config, $language) - { - $textArray = preg_split('/\{\{([^\}]+)\}\}/', $text, -1, PREG_SPLIT_DELIM_CAPTURE); - - for ($count = 0; $count < count($textArray); $count++) - { - $parts = explode("::", $textArray[$count]); - switch ($parts[0]) - { - case 'birthdaychild': - switch ($parts[1]) - { - case 'salutation': - $salutation = $this->getSalutation($config, $language, 'salutation_' . $config->gender); - if (strlen($salutation) == 0) - { - $salutation = $this->getSalutation($config, $language, 'salutation'); - } - $textArray[$count] = $salutation; - break; - - case 'name': - $textArray[$count] = trim($config->firstname . ' ' . $config->lastname); - break; - - case 'groupname': - $textArray[$count] = trim($config->memberGroupName); - break; - - case 'password': - // do not allow extracting the password - $textArray[$count] = ""; - break; - - case 'age': - $textArray[$count] = (date("Y") - date("Y", $config->dateOfBirth)); - break; - - default: - $textArray[$count] = $config->$parts[1]; - break; - } - break; - - case 'birthdaymailer': - switch ($parts[1]) - { - case 'email': - $textArray[$count] = trim($config->mailSender); - break; - - case 'name': - $textArray[$count] = trim($config->mailSenderName); - break; - } - break; - } - } - - return implode('', $textArray); - } - - /** - * Get the text for specific types. Fallback ist to 'default' if no text is set. - * FALLBACK Chain: - * 1. check, if there is a text for the specified textKey and language (search in system/config/langconfig.php) - * 2. if nothing found, check, if there is a text for the specified textKey and 'en' (search in system/config/langconfig.php) - * 3. if nothing found, get default text in specified language - * 4. if nothing found, get default text in language 'en' - */ - private function getSalutation($config, $language, $textType) - { - $text = ""; - - if ($config->mailUseCustomText) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][$language]; - - if (strlen($text) == 0 && $language != self::DEFAULT_LANGUAGE) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][self::DEFAULT_LANGUAGE]; - } - } - - if (strlen($text) == 0) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail']['default'][$textType]; - } - - return $text; - } -} - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/config/autoload.ini b/system/modules/BirthdayMailer/config/autoload.ini old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/config/autoload.php b/system/modules/BirthdayMailer/config/autoload.php index f4e70e0..43474e8 100644 --- a/system/modules/BirthdayMailer/config/autoload.php +++ b/system/modules/BirthdayMailer/config/autoload.php @@ -3,11 +3,9 @@ /** * Contao Open Source CMS * - * Copyright (c) 2005-2015 Leo Feyer + * Copyright (c) 2005-2016 Leo Feyer * - * @package BirthdayMailer - * @link https://contao.org - * @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL + * @license LGPL-3.0+ */ @@ -26,7 +24,13 @@ ClassLoader::addClasses(array ( // Classes - 'BirthdayMailer\BirthdayMailSender' => 'system/modules/BirthdayMailer/classes/BirthdayMailSender.php', + 'BirthdayMailer\BirthdayMailSender' => 'system/modules/BirthdayMailer/classes/BirthdayMailSender.php', + + // Library + 'BirthdayMailer\Helper\Backend' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Backend.php', + 'BirthdayMailer\Helper\Cron' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Cron.php', + 'BirthdayMailer\Helper\Dca' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Dca.php', + 'BirthdayMailer\Model\BirthdayMailer' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php', )); diff --git a/system/modules/BirthdayMailer/config/config.php b/system/modules/BirthdayMailer/config/config.php old mode 100644 new mode 100755 index d30e4e8..0068705 --- a/system/modules/BirthdayMailer/config/config.php +++ b/system/modules/BirthdayMailer/config/config.php @@ -28,73 +28,56 @@ */ /** - * ------------------------------------------------------------------------- - * BACK END MODULES - * ------------------------------------------------------------------------- + * Back end modules */ - -// Add configuration to Backend -> Accounts $GLOBALS['BE_MOD']['accounts']['BirthdayMailer'] = array ( 'tables' => array('tl_birthdaymailer'), 'icon' => 'system/modules/BirthdayMailer/assets/icon.png', - 'sendBirthdayMail' => array('BirthdayMailSender', 'sendBirthdayMailManually'), + 'sendBirthdayMail' => array('BirthdayMailer\Helper\Backend', 'sendBirthdayMailsManually'), ); + /** - * ------------------------------------------------------------------------- - * CRON - * ------------------------------------------------------------------------- + * Models */ +$GLOBALS['TL_MODELS'][BirthdayMailer\Model\BirthdayMailer::getTable()] = 'BirthdayMailer\Model\BirthdayMailer'; + + +/** + * Cron + */ +$GLOBALS['TL_CRON']['daily'][] = array('BirthdayMailer\Helper\Cron', 'sendBirthdayMails'); -// Daily cron job to send birthday mails -$GLOBALS['TL_CRON']['daily'][] = array('BirthdayMailSender', 'sendBirthdayMail'); /** * Notification Center Notification Types */ $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['recipients'] = array( - 'birthdaychild_email', // returns the email of the member - 'admin_email' + 'birthdaychild_email', // returns the email of the member + 'admin_email' ); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_subject'] = array( - 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) - 'birthdaychild_name', // returns first and last name of the member - 'birthdaychild_age', // returns the age of the member - 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) - 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) - 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) - 'birthdaymailer_groupname', // returns the name of the member group of the current configuration - 'admin_email' -); -$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_text'] = array( - 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) - 'birthdaychild_name', // returns first and last name of the member - 'birthdaychild_age', // returns the age of the member - 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) - 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) - 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) - 'birthdaymailer_groupname', // returns the name of the member group of the current configuration - 'admin_email' -); -$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_html'] = array( - 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) - 'birthdaychild_name', // returns first and last name of the member - 'birthdaychild_age', // returns the age of the member - 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) - 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) - 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) - 'birthdaymailer_groupname', // returns the name of the member group of the current configuration - 'admin_email' + 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) + 'birthdaychild_name', // returns first and last name of the member + 'birthdaychild_age', // returns the age of the member + 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) + 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) + 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) + 'birthdaymailer_groupname', // returns the name of the member group of the current configuration ); +$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_text'] = + $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_subject']; +$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_html'] = + $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_subject']; + $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_recipient_cc'] = array( - 'admin_email' + 'admin_email' ); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_recipient_bcc'] = array( - 'admin_email' + 'admin_email' ); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_replyTo'] = array( - 'admin_email' + 'admin_email' ); -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php b/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php old mode 100644 new mode 100755 index ede5f31..bfe0b61 --- a/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php +++ b/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php @@ -1,32 +1,15 @@ . - * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * BirthdayMailer for Contao Open Source CMS + * + * Copyright (c) 2011-2016 Cliff Parnitzky + * + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Table tl_birthdaymailer */ @@ -34,12 +17,12 @@ ( // Config - 'config' => array + 'config' => array ( - 'dataContainer' => 'Table', - 'enableVersioning' => true, - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['root_label'], - 'sql' => array + 'dataContainer' => 'Table', + 'enableVersioning' => true, + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['root_label'], + 'sql' => array ( 'keys' => array ( @@ -49,78 +32,89 @@ ), // List - 'list' => array + 'list' => array ( - 'sorting' => array ( + 'sorting' => array( 'mode' => 5, 'fields' => array('sorting'), 'flag' => 11, 'panelLayout' => 'filter,limit', - 'paste_button_callback' => array('tl_birthdaymailer', 'pasteConfig'), + 'paste_button_callback' => array('BirthdayMailer\Helper\Dca', 'pasteConfig'), 'icon' => 'system/modules/BirthdayMailer/assets/icon_root.png', ), - 'label' => array + 'label' => array ( - 'fields' => array('memberGroup:tl_member_group.name'), - 'format' => '%s', - 'label_callback' => array('tl_birthdaymailer', 'addIcon') + 'fields' => array('memberGroup:tl_member_group.name'), + 'format' => '%s', + 'label_callback' => array('BirthdayMailer\Helper\Dca', 'addIcon') ), 'global_operations' => array ( 'sendBirthdayMail' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['sendBirthdayMail'], - 'href' => 'key=sendBirthdayMail', - 'attributes' => 'onclick="Backend.getScrollOffset();" style="background: url(\'system/modules/BirthdayMailer/assets/icon_execute.png\') no-repeat scroll left center transparent; margin-left: 15px; padding: 2px 0 3px 20px;"' + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['sendBirthdayMail'], + 'href' => 'key=sendBirthdayMail', + 'attributes' => 'onclick="Backend.getScrollOffset();" style="background: url(\'system/modules/BirthdayMailer/assets/icon_execute.png\') no-repeat scroll left center transparent; margin-left: 15px; padding: 2px 0 3px 20px;"' ), - 'all' => array + 'all' => array ( - 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], - 'href' => 'act=select', - 'class' => 'header_edit_all', - 'attributes' => 'onclick="Backend.getScrollOffset();"' + 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], + 'href' => 'act=select', + 'class' => 'header_edit_all', + 'attributes' => 'onclick="Backend.getScrollOffset();"' ) ), - 'operations' => array + 'operations' => array ( - 'edit' => array + 'edit' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['edit'], - 'href' => 'act=edit', - 'icon' => 'edit.gif' + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['edit'], + 'href' => 'act=edit', + 'icon' => 'edit.gif' ), - 'copy' => array + 'copy' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['copy'], - 'href' => 'act=copy', - 'icon' => 'copy.gif' + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['copy'], + 'href' => 'act=copy', + 'icon' => 'copy.gif' ), - 'cut' => array + 'cut' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['cut'], - 'href' => 'act=paste&mode=cut', - 'icon' => 'cut.gif', - 'attributes' => 'onclick="Backend.getScrollOffset()"', + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['cut'], + 'href' => 'act=paste&mode=cut', + 'icon' => 'cut.gif', + 'attributes' => 'onclick="Backend.getScrollOffset()"', ), 'delete' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['delete'], - 'href' => 'act=delete', - 'icon' => 'delete.gif', - 'attributes' => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"' + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['delete'], + 'href' => 'act=delete', + 'icon' => 'delete.gif', + 'attributes' => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"' ), 'toggle' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['toggle'], - 'icon' => 'visible.gif', - 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', - 'button_callback' => array('tl_birthdaymailer', 'toggleIcon') + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['toggle'], + 'attributes' => 'onclick="Backend.getScrollOffset();"', + 'haste_ajax_operation' => array( + 'field' => 'disable', + 'options' => array( + array( + 'value' => '1', + 'icon' => 'invisible.gif' + ), + array( + 'value' => '', + 'icon' => 'visible.gif' + ) + ) + ) ), - 'show' => array + 'show' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['show'], - 'href' => 'act=show', - 'icon' => 'show.gif' + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['show'], + 'href' => 'act=show', + 'icon' => 'show.gif' ) ) ), @@ -128,249 +122,81 @@ // Palettes 'palettes' => array ( - 'default' => '{config_legend},memberGroup,nc_notification;{disable_legend},disable' + 'default' => '{config_legend},memberGroup,nc_notification;{disable_legend},disable' ), // Fields - 'fields' => array + 'fields' => array ( - 'id' => array + 'id' => array ( - 'sql' => "int(10) unsigned NOT NULL auto_increment" + 'sql' => "int(10) unsigned NOT NULL auto_increment" ), - 'pid' => array + 'pid' => array ( - 'sql' => "int(10) unsigned NOT NULL default '0'" + 'sql' => "int(10) unsigned NOT NULL default '0'" ), - 'sorting' => array + 'sorting' => array ( - 'label' => &$GLOBALS['TL_LANG']['MSC']['sorting'], - 'sorting' => true, - 'flag' => 11, - 'sql' => "int(10) unsigned NOT NULL default '0'" + 'label' => &$GLOBALS['TL_LANG']['MSC']['sorting'], + 'sorting' => true, + 'flag' => 11, + 'sql' => "int(10) unsigned NOT NULL default '0'" ), - 'tstamp' => array + 'tstamp' => array ( - 'sql' => "int(10) unsigned NOT NULL default '0'" + 'sql' => "int(10) unsigned NOT NULL default '0'" ), - 'memberGroup' => array + 'memberGroup' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['memberGroup'], - 'exclude' => true, - 'inputType' => 'select', - 'foreignKey' => 'tl_member_group.name', - 'filter' => true, - 'eval' => array('mandatory'=>true, 'unique'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50', 'chosen'=>true), - 'sql' => "int(10) unsigned NOT NULL default '0'", - 'relation' => array('type'=>'hasOne', 'load'=>'eager') + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['memberGroup'], + 'exclude' => true, + 'inputType' => 'select', + 'foreignKey' => 'tl_member_group.name', + 'filter' => true, + 'eval' => array + ( + 'mandatory' => true, + 'unique' => true, + 'includeBlankOption' => true, + 'tl_class' => 'w50', + 'chosen' => true + ), + 'sql' => "int(10) unsigned NOT NULL default '0'", + 'relation' => array + ( + 'type' => 'hasOne', + 'load' => 'eager' + ) ), 'nc_notification' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['nc_notification'], - 'exclude' => true, - 'inputType' => 'select', - 'foreignKey' => 'tl_nc_notification.title', - 'filter' => true, - 'options_callback' => array('tl_birthdaymailer', 'getNotificationChoices'), - 'eval' => array('mandatory'=>true, 'unique'=>true, 'includeBlankOption'=>true, 'tl_class'=>'clr w50', 'chosen'=>true, 'submitOnChange'=>true), - 'wizard' => array + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['nc_notification'], + 'exclude' => true, + 'inputType' => 'select', + 'foreignKey' => 'tl_nc_notification.title', + 'filter' => true, + 'options_callback' => array('BirthdayMailer\Helper\Dca', 'getNotificationChoices'), + 'eval' => array ( - array('tl_birthdaymailer', 'editNotification') + 'mandatory' => true, + 'unique' => true, + 'includeBlankOption' => true, + 'tl_class' => 'w50', + 'chosen' => true, + 'submitOnChange' => true ), - 'sql' => "int(10) unsigned NOT NULL default '0'", - 'relation' => array('type'=>'hasOne', 'load'=>'eager') + 'wizard' => array(array('BirthdayMailer\Helper\Dca', 'editNotification')), + 'sql' => "int(10) unsigned NOT NULL default '0'", + 'relation' => array('type' => 'hasOne', 'load' => 'eager') ), - 'disable' => array + 'disable' => array ( - 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['disable'], - 'exclude' => true, - 'filter' => true, - 'inputType' => 'checkbox', - 'sql' => "char(1) NOT NULL default ''" + 'label' => &$GLOBALS['TL_LANG']['tl_birthdaymailer']['disable'], + 'exclude' => true, + 'filter' => true, + 'inputType' => 'checkbox', + 'sql' => "char(1) NOT NULL default ''" ) ) ); - -/** - * Class tl_birthdaymailer - * - * Provide miscellaneous methods that are used by the data configuration array. - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package Controller - */ -class tl_birthdaymailer extends Backend -{ - /** - * Import the back end user object - */ - public function __construct() - { - parent::__construct(); - $this->import('BackendUser', 'User'); - } - - /** - * Add an image to each record - * @param array - * @param string - * @param \DataContainer - * @param array - * @return string - */ - public function addIcon($row, $label, DataContainer $dc, $args) - { - - $image = 'icon'; - - if ($row['disable']) - { - $image .= '_1'; - } - - // get group from database - $objMemberGroup = \MemberGroupModel::findByPk($row['memberGroup']); - - $memberGroupImage = 'mgroup'; - $memberGroupTitle = $GLOBALS['TL_LANG']['tl_birthdaymailer']['group_enabled']; - - if ($objMemberGroup->disable || strlen($objMemberGroup->start) && $objMemberGroup->start > time() || strlen($objMemberGroup->stop) && $objMemberGroup->stop < time()) - { - $memberGroupImage .= '_'; - $memberGroupTitle = $GLOBALS['TL_LANG']['tl_birthdaymailer']['group_disabled']; - } - - return sprintf('Status icon %s %s', $image, $label, $this->getTheme(), $memberGroupImage, $memberGroupTitle, $memberGroupTitle); - } - - /** - * Return the paste button - * @param object - * @param array - * @param string - * @param boolean - * @param array - * @return string - */ - public function pasteConfig(DataContainer $dc, $row, $table, $cr, $arrClipboard=false) - { - $this->import('BackendUser', 'User'); - $imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])); - $imagePasteInto = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id'])); - if ($row['id'] == 0) - { - return $cr ? $this->generateImage('pasteinto_.gif').' ' : ''.$imagePasteInto.' '; - } - return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || $cr) ? $this->generateImage('pasteafter_.gif').' ' : ''.$imagePasteAfter.' '; - } - - /** - * Return the "toggle visibility" button - * @param array - * @param string - * @param string - * @param string - * @param string - * @param string - * @return string - */ - public function toggleIcon($row, $href, $label, $title, $icon, $attributes) - { - if (strlen(Input::get('tid'))) - { - $this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1), (@func_get_arg(12) ?: null)); - $this->redirect($this->getReferer()); - } - - // Check permissions AFTER checking the tid, so hacking attempts are logged - if (!$this->User->isAdmin && !$this->User->hasAccess('tl_birthdaymailer::disable', 'alexf')) - { - return ''; - } - - $href .= '&tid='.$row['id'].'&state='.$row['disable']; - - if ($row['disable']) - { - $icon = 'invisible.gif'; - } - - return ''.Image::getHtml($icon, $label).' '; - } - - - /** - * Disable/enable a configuration - * @param integer - * @param boolean - * @param \DataContainer - */ - public function toggleVisibility($intId, $blnVisible, DataContainer $dc=null) - { - // Check permissions - if (!$this->User->isAdmin && !$this->User->hasAccess('tl_birthdaymailer::disable', 'alexf')) - { - $this->log('Not enough permissions to activate/deactivate bithday mailer configuration ID "'.$intId.'"', __METHOD__, TL_ERROR); - $this->redirect('contao/main.php?act=error'); - } - - $objVersions = new Versions('tl_birthdaymailer', $intId); - $objVersions->initialize(); - - // Trigger the save_callback - if (is_array($GLOBALS['TL_DCA']['tl_birthdaymailer']['fields']['disable']['save_callback'])) - { - foreach ($GLOBALS['TL_DCA']['tl_birthdaymailer']['fields']['disable']['save_callback'] as $callback) - { - if (is_array($callback)) - { - $this->import($callback[0]); - $blnVisible = $this->$callback[0]->$callback[1]($blnVisible, ($dc ?: $this)); - } - elseif (is_callable($callback)) - { - $blnVisible = $callback($blnVisible, ($dc ?: $this)); - } - } - } - - $time = time(); - - // Update the database - \Database::getInstance()->prepare("UPDATE tl_birthdaymailer SET tstamp=$time, disable='" . ($blnVisible ? '' : 1) . "' WHERE id=?") - ->execute($intId); - - $objVersions->create(); - $this->log('A new version of record "tl_birthdaymailer.id='.$intId.'" has been created'.$this->getParentEntries('tl_birthdaymailer', $intId), __METHOD__, TL_GENERAL); - } - - /** - * Get notification choices - * - * @return array - */ - public function getNotificationChoices() - { - $arrChoices = array(); - $objNotifications = \Database::getInstance()->execute("SELECT id,title FROM tl_nc_notification WHERE type='birthday_mail' ORDER BY title"); - - while ($objNotifications->next()) { - $arrChoices[$objNotifications->id] = $objNotifications->title; - } - - return $arrChoices; - } - - /** - * Return the edit notification wizard - * @param \DataContainer - * @return string - */ - public function editNotification(DataContainer $dc) - { - return ($dc->value < 1) ? '' : ' value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_birthdaymailer']['edit_notification'][0], 'style="vertical-align:top"') . ''; - } -} - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/dca/tl_member_group.php b/system/modules/BirthdayMailer/dca/tl_member_group.php old mode 100644 new mode 100755 index fa269df..418187f --- a/system/modules/BirthdayMailer/dca/tl_member_group.php +++ b/system/modules/BirthdayMailer/dca/tl_member_group.php @@ -1,35 +1,17 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** - * Delete an according BirthdayMailer configuration, if the member group is deleted. + * Table tl_member_group */ -$GLOBALS['TL_DCA']['tl_member_group']['config']['ondelete_callback'][] = array('BirthdayMailSender', 'deleteConfiguration'); - -?> \ No newline at end of file +// Config +$GLOBALS['TL_DCA']['tl_member_group']['config']['ondelete_callback'][] = array('BirthdayMailer\Helper\Dca', 'deleteConfiguration'); diff --git a/system/modules/BirthdayMailer/dca/tl_settings.php b/system/modules/BirthdayMailer/dca/tl_settings.php old mode 100644 new mode 100755 index 181bf77..ad08da6 --- a/system/modules/BirthdayMailer/dca/tl_settings.php +++ b/system/modules/BirthdayMailer/dca/tl_settings.php @@ -1,73 +1,54 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** - * Add to palette + * Palettes */ $GLOBALS['TL_DCA']['tl_settings']['palettes']['__selector__'][] = 'birthdayMailerDeveloperMode'; $GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] .= ';{birthdayMailer_legend},birthdayMailerAllowDuplicates, birthdayMailerLogDebugInfo, birthdayMailerDeveloperMode;'; $GLOBALS['TL_DCA']['tl_settings']['subpalettes']['birthdayMailerDeveloperMode'] = 'birthdayMailerDeveloperModeEmail, birthdayMailerDeveloperModeIgnoreDate'; /** - * Add fields + * Fields */ $GLOBALS['TL_DCA']['tl_settings']['fields']['birthdayMailerAllowDuplicates'] = array( 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerAllowDuplicates'], 'inputType' => 'checkbox', - 'eval' => array('tl_class'=>'w50') + 'eval' => array('tl_class' => 'w50') ); $GLOBALS['TL_DCA']['tl_settings']['fields']['birthdayMailerLogDebugInfo'] = array( 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerLogDebugInfo'], 'inputType' => 'checkbox', - 'eval' => array('tl_class'=>'w50') + 'eval' => array('tl_class' => 'w50') ); $GLOBALS['TL_DCA']['tl_settings']['fields']['birthdayMailerDeveloperMode'] = array ( - 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperMode'], - 'inputType' => 'checkbox', - 'eval' => array('submitOnChange'=>true, 'tl_class'=>'w50 clr') + 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperMode'], + 'inputType' => 'checkbox', + 'eval' => array('submitOnChange' => true, 'tl_class' => 'w50 clr') ); $GLOBALS['TL_DCA']['tl_settings']['fields']['birthdayMailerDeveloperModeEmail'] = array ( - 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeEmail'], - 'inputType' => 'text', - 'eval' => array('mandatory'=>true, 'rgxp'=>'email', 'tl_class'=>'w50 clr') + 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeEmail'], + 'inputType' => 'text', + 'eval' => array('mandatory' => true, 'rgxp' => 'email', 'tl_class' => 'w50 clr') ); $GLOBALS['TL_DCA']['tl_settings']['fields']['birthdayMailerDeveloperModeIgnoreDate'] = array ( - 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeIgnoreDate'], - 'inputType' => 'checkbox', - 'eval' => array('tl_class'=>'w50') + 'label' => &$GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeIgnoreDate'], + 'inputType' => 'checkbox', + 'eval' => array('tl_class' => 'w50') ); - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/de/default.php b/system/modules/BirthdayMailer/languages/de/default.php old mode 100644 new mode 100755 index ba52d8d..c8d2d5f --- a/system/modules/BirthdayMailer/languages/de/default.php +++ b/system/modules/BirthdayMailer/languages/de/default.php @@ -1,32 +1,15 @@ . - * - * PHP version 5 - * @copyright Cliff Parnitzky 2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * defaults */ @@ -39,5 +22,3 @@ $GLOBALS['TL_LANG']['BirthdayMailer']['welcoming_formally'] = 'Sehr geehrte/-r'; $GLOBALS['TL_LANG']['BirthdayMailer']['welcoming_formally_female'] = 'Sehr geehrte Frau'; $GLOBALS['TL_LANG']['BirthdayMailer']['welcoming_formally_male'] = 'Sehr geehrter Herr'; - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/de/modules.php b/system/modules/BirthdayMailer/languages/de/modules.php old mode 100644 new mode 100755 index 952220f..a361964 --- a/system/modules/BirthdayMailer/languages/de/modules.php +++ b/system/modules/BirthdayMailer/languages/de/modules.php @@ -1,35 +1,16 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Define name and tooltip for preferences (inactive modules) */ $GLOBALS['TL_LANG']['MOD']['BirthdayMailer'] = array('Geburtstagsmailer', 'Versendet eine Geburtstagsmail an Mitglieder, die am aktuellen Tag Geburtstag haben.'); - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/de/tl_birthdaymailer.php b/system/modules/BirthdayMailer/languages/de/tl_birthdaymailer.php old mode 100644 new mode 100755 index 58c3762..e2cc408 --- a/system/modules/BirthdayMailer/languages/de/tl_birthdaymailer.php +++ b/system/modules/BirthdayMailer/languages/de/tl_birthdaymailer.php @@ -1,32 +1,15 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Fields */ @@ -75,5 +58,3 @@ $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionTableHead'] = "Abbrüche"; $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionInfo'] = "Bitte prüfen Sie das Contao System-Log um weitere Informationen zu den Abbrüchen zu erhalten."; $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['developerMessage'] = "Sie befinden sich im Entwicklermodus. Alle E-Mails werden an die folgende Entwickler E-Mail-Adresse gesendet: %s. Bitte stellen Sie sicher, dass dies eine gültige E-Mail-Adresse ist. Änderungen können in den Einstellungen vorgenommen werden."; - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/de/tl_nc_notification.php b/system/modules/BirthdayMailer/languages/de/tl_nc_notification.php old mode 100644 new mode 100755 index c1c04c8..0e5ee2b --- a/system/modules/BirthdayMailer/languages/de/tl_nc_notification.php +++ b/system/modules/BirthdayMailer/languages/de/tl_nc_notification.php @@ -1,36 +1,17 @@ . - * - * PHP version 5 - * @copyright Cliff Parnitzky 2015-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Notification types */ $GLOBALS['TL_LANG']['tl_nc_notification']['type']['BirthdayMailer'] = 'Geburtstagsmailer'; $GLOBALS['TL_LANG']['tl_nc_notification']['type']['birthday_mail'] = array('Geburtstagsmail', 'Dieser Benachrichtigungstyp kann vewendet werden um Geburtstagsmails zu versenden.'); - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/de/tl_settings.php b/system/modules/BirthdayMailer/languages/de/tl_settings.php old mode 100644 new mode 100755 index 5d3ad85..e82a276 --- a/system/modules/BirthdayMailer/languages/de/tl_settings.php +++ b/system/modules/BirthdayMailer/languages/de/tl_settings.php @@ -1,37 +1,18 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ - + + $GLOBALS['TL_LANG']['tl_settings']['birthdayMailer_legend'] = "Geburtstagsmailer"; $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerAllowDuplicates'] = array('Duplikate erlauben', 'Wenn diese Option gewählt ist, werden Geburtstagsmails an ein und dasselbe Mitglieder mit mehreren konfigurierten Mitgliedergruppen mehrfach gesendet (das Mitglieder bekommt dann mehrere Geburtstagsmails).'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerLogDebugInfo'] = array('Zusätzliche Debug Informationen loggen', 'Wenn diese Option gewählt ist, werden zusätzliche Debug Informationen im System-Log eingetragen (pro E-Mail die versendet werden soll ein Eintrag mit allen Inhalten).'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperMode'] = array('Entwicklermodus', 'Aktiviert den Entwicklermodus. Emails gehen nur an die Entwickler E-Mail-Adresse.'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeEmail'] = array('Entwickler E-Mail-Adresse', 'Im Entwicklermodus werden alle E-Mails an diese Adresse umgeleitet.'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeIgnoreDate'] = array('Geburtsdatum im Entwicklermodus ignorieren', 'Umgeht im Entwicklermodus die Prüfung ob ein Mitglied am aktuellen Tag Geburtstag hat. Es wird für jedes aktive Mitglied eine Email gesendet.'); - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/de/tokens.php b/system/modules/BirthdayMailer/languages/de/tokens.php old mode 100644 new mode 100755 index a84a174..3fd97bd --- a/system/modules/BirthdayMailer/languages/de/tokens.php +++ b/system/modules/BirthdayMailer/languages/de/tokens.php @@ -1,32 +1,15 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Tokens */ @@ -39,5 +22,3 @@ $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['birthday_mail']['birthdaychild_welcoming_personally'] = 'Die persönliche Begrüßung für das Geburtstagskind (abhängig vom Geschlecht).'; $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['birthday_mail']['birthdaychild_welcoming_formally'] = 'Die formelle Begrüßung für das Geburtstagskind (abhängig vom Geschlecht).'; $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['birthday_mail']['birthdaymailer_groupname'] = 'Der Name der Mitgliedergruppe der verwendeten Geburtstagsmailer Konfiguration.'; - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/en/default.php b/system/modules/BirthdayMailer/languages/en/default.php old mode 100644 new mode 100755 index 13c2e30..3c3062f --- a/system/modules/BirthdayMailer/languages/en/default.php +++ b/system/modules/BirthdayMailer/languages/en/default.php @@ -1,32 +1,15 @@ . - * - * PHP version 5 - * @copyright Cliff Parnitzky 2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * defaults */ @@ -39,5 +22,3 @@ $GLOBALS['TL_LANG']['BirthdayMailer']['welcoming_formally'] = 'Dear Ms/Mr'; $GLOBALS['TL_LANG']['BirthdayMailer']['welcoming_formally_female'] = 'Dear Ms'; $GLOBALS['TL_LANG']['BirthdayMailer']['welcoming_formally_male'] = 'Dear Mr'; - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/en/modules.php b/system/modules/BirthdayMailer/languages/en/modules.php old mode 100644 new mode 100755 index cd4cb0b..46a31b1 --- a/system/modules/BirthdayMailer/languages/en/modules.php +++ b/system/modules/BirthdayMailer/languages/en/modules.php @@ -1,35 +1,16 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Define name and tooltip for preferences (inactive modules) */ $GLOBALS['TL_LANG']['MOD']['BirthdayMailer'] = array('Birthday mailer', 'Sends a birthday email to all the members having their birtday on the current day.'); - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/en/tl_birthdaymailer.php b/system/modules/BirthdayMailer/languages/en/tl_birthdaymailer.php old mode 100644 new mode 100755 index 1c218d6..1dcd4cb --- a/system/modules/BirthdayMailer/languages/en/tl_birthdaymailer.php +++ b/system/modules/BirthdayMailer/languages/en/tl_birthdaymailer.php @@ -1,32 +1,15 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Fields */ @@ -50,7 +33,7 @@ $GLOBALS['TL_LANG']['tl_birthdaymailer']['copy'] = array('Duplicate configuration', 'Duplicate configuration ID %s'); $GLOBALS['TL_LANG']['tl_birthdaymailer']['cut'] = array('Move configuration', 'Move configuration ID %s'); $GLOBALS['TL_LANG']['tl_birthdaymailer']['delete'] = array('Delete configuration', 'Delete configuration ID %s'); -$GLOBALS['TL_LANG']['tl_birthdaymailer']['toggle'] = array('Konfiguration veröffentlichen/unveröffentlichen', 'Konfiguration ID %s veröffentlichen/unveröffentlichen'); +$GLOBALS['TL_LANG']['tl_birthdaymailer']['toggle'] = array('Konfiguration ver�ffentlichen/unver�ffentlichen', 'Konfiguration ID %s ver�ffentlichen/unver�ffentlichen'); $GLOBALS['TL_LANG']['tl_birthdaymailer']['pasteafter'] = array('Paste after', 'Paste after configuration ID %s'); $GLOBALS['TL_LANG']['tl_birthdaymailer']['pasteinto'] = array('Paste on top', 'Paste on top'); $GLOBALS['TL_LANG']['tl_birthdaymailer']['edit_notification'] = array('Edit notification', 'Edit the notification ID %s'); @@ -75,5 +58,3 @@ $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionTableHead'] = "Abortions"; $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionInfo'] = "Please check the Contao System log to get additional information about the abortions."; $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['developerMessage'] = "You are in developermode. All emails will be send to the folowing developer email address: %s. Please make sure that this is a valid email address. Changes can be made in the Settings."; - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/en/tl_nc_notification.php b/system/modules/BirthdayMailer/languages/en/tl_nc_notification.php old mode 100644 new mode 100755 index 7660538..2ab1c9a --- a/system/modules/BirthdayMailer/languages/en/tl_nc_notification.php +++ b/system/modules/BirthdayMailer/languages/en/tl_nc_notification.php @@ -1,36 +1,17 @@ . - * - * PHP version 5 - * @copyright Cliff Parnitzky 2015-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Notification types */ $GLOBALS['TL_LANG']['tl_nc_notification']['type']['BirthdayMailer'] = 'Birthdaymailer'; $GLOBALS['TL_LANG']['tl_nc_notification']['type']['birthday_mail'] = array('Birthdaymail', 'This notification type could be used for sending birthday mails.'); - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/en/tl_settings.php b/system/modules/BirthdayMailer/languages/en/tl_settings.php old mode 100644 new mode 100755 index 59259a2..941b92c --- a/system/modules/BirthdayMailer/languages/en/tl_settings.php +++ b/system/modules/BirthdayMailer/languages/en/tl_settings.php @@ -1,37 +1,18 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ - + + $GLOBALS['TL_LANG']['tl_settings']['birthdayMailer_legend'] = "Birthdaymailer"; $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerAllowDuplicates'] = array('Allow duplicates', 'If this option is selected, birthday emails are sent repeatedly to one and the same member with several configured member groups (the member receives several birthday emails).'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerLogDebugInfo'] = array('Log additional debug information', 'If this option is selected, additional debug information will be written to system log (per e-mail to be sent an entry with all contents).'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperMode'] = array('Developer mode', 'Enables the developer mode. Emails will be send to the developer e-mail address.'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeEmail'] = array('Developer E-mail address', 'In developer mode, all emails are forwarded to this address.'); $GLOBALS['TL_LANG']['tl_settings']['birthdayMailerDeveloperModeIgnoreDate'] = array('Ignore date of birth in developer mode', 'Bypasses in developer mode the check whether the members date of birth is the current day. For each active member, an email will be sent.'); - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/languages/en/tokens.php b/system/modules/BirthdayMailer/languages/en/tokens.php old mode 100644 new mode 100755 index e378f86..58ed183 --- a/system/modules/BirthdayMailer/languages/en/tokens.php +++ b/system/modules/BirthdayMailer/languages/en/tokens.php @@ -1,32 +1,15 @@ . + * Copyright (c) 2011-2016 Cliff Parnitzky * - * PHP version 5 - * @copyright Cliff Parnitzky 2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann */ + /** * Tokens */ @@ -39,5 +22,3 @@ $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['birthday_mail']['birthdaychild_welcoming_personally'] = 'The he personally welcoming for the birthday child (depending on gender).'; $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['birthday_mail']['birthdaychild_welcoming_formally'] = 'The formally welcoming for the birthday child (depending on gender).'; $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['birthday_mail']['birthdaymailer_groupname'] = 'The name of the member group of the used birthday mailer configuration.'; - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Backend.php b/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Backend.php new file mode 100644 index 0000000..39ad90a --- /dev/null +++ b/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Backend.php @@ -0,0 +1,66 @@ + + */ + + +namespace BirthdayMailer\Helper; + +use BirthdayMailer\Model\BirthdayMailer; + + +/** + * Class Backend + * @package BirthdayMailer\Helper + */ +class Backend extends \Backend +{ + + /** + * Execute the sender manually from backend and get a result page. + * + * @return string + */ + public function sendBirthdayMailsManually() + { + if (TL_MODE != 'BE') + { + return ''; + } + + $result = BirthdayMailer::sendBirthdayMails(); + + // Create template object + $objTemplate = new \BackendTemplate('be_birthday-mailer'); + + $objTemplate->backLink = '' . $GLOBALS['TL_LANG']['MSC']['backBT'] . ''; + $objTemplate->headline = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['headline']; + $objTemplate->sendingHeadline = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['sendingHeadline']; + $objTemplate->success = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['successMessage'], sizeof($result['success'])); + + $objTemplate->failed = sizeof($result['failed']) > 0; + $objTemplate->failureMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureMessage'], sizeof($result['failed'])); + $objTemplate->failureTableHead = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureTableHead']; + $objTemplate->failures = $result['failed']; + $objTemplate->failureInfo = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureInfo']; + + $objTemplate->aborted = sizeof($result['aborted']) > 0; + $objTemplate->abortionMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionMessage'], sizeof($result['aborted'])); + $objTemplate->abortionTableHead = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionTableHead']; + $objTemplate->abortions = $result['aborted']; + $objTemplate->abortionInfo = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionInfo']; + + if (\Config::get('birthdayMailerDeveloperMode')) + { + $objTemplate->developerMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['developerMessage'], \Config::get('birthdayMailerDeveloperModeEmail')); + } + + return $objTemplate->parse(); + } +} diff --git a/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Cron.php b/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Cron.php new file mode 100644 index 0000000..939aca3 --- /dev/null +++ b/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Cron.php @@ -0,0 +1,39 @@ + + */ + + +namespace BirthdayMailer\Helper; + +use BirthdayMailer\Model\BirthdayMailer; + + +/** + * Class Cron + * @package BirthdayMailer\Helper + */ +class Cron +{ + + /** + * Sends the birthday emails. + * + * @return array + */ + public function sendBirthdayMails() + { + $arrResult = BirthdayMailer::sendBirthdayMails(); + + \System::log('BirthdayMailer: Daily sending of birthday mail finished. Send ' . sizeof($arrResult['success']) . ' emails. ' + . sizeof($arrResult['failed']) . ' emails could not be send due to errors. ' + . sizeof($arrResult['aborted']) . ' emails were aborted due to custom hooks. See birthdaymails.log for details.', __METHOD__, TL_CRON); + } + +} diff --git a/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Dca.php b/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Dca.php new file mode 100644 index 0000000..00bee24 --- /dev/null +++ b/system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Dca.php @@ -0,0 +1,130 @@ + + */ + + +namespace BirthdayMailer\Helper; + +use BirthdayMailer\Model\BirthdayMailer; + + +/** + * Class Dca + * @package BirthdayMailer\Helper + */ +class Dca extends \Backend +{ + + /** + * Add an image to each record + * + * @param array + * @param string + * @param \DataContainer + * @param array + * + * @return string + */ + public function addIcon($row, $label, \DataContainer $dc, $args) + { + + $image = 'icon'; + + if ($row['disable']) + { + $image .= '_1'; + } + + // get group from database + $objMemberGroup = \MemberGroupModel::findByPk($row['memberGroup']); + + $memberGroupImage = 'mgroup'; + $memberGroupTitle = $GLOBALS['TL_LANG']['tl_birthdaymailer']['group_enabled']; + + if ($objMemberGroup->disable || strlen($objMemberGroup->start) && $objMemberGroup->start > time() || strlen($objMemberGroup->stop) && $objMemberGroup->stop < time()) + { + $memberGroupImage .= '_'; + $memberGroupTitle = $GLOBALS['TL_LANG']['tl_birthdaymailer']['group_disabled']; + } + + return sprintf('Status icon %s %s', $image, $label, $this->getTheme(), $memberGroupImage, $memberGroupTitle, $memberGroupTitle); + } + + + /** + * Return the paste button + * + * @param \DataContainer $dc + * @param $row + * @param $table + * @param $cr + * @param bool $arrClipboard + * + * @return string + */ + public function pasteConfig(\DataContainer $dc, $row, $table, $cr, $arrClipboard = false) + { + $this->import('BackendUser', 'User'); + $imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])); + $imagePasteInto = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id'])); + if ($row['id'] == 0) + { + return $cr ? $this->generateImage('pasteinto_.gif') . ' ' : '' . $imagePasteInto . ' '; + } + + return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || $cr) ? $this->generateImage('pasteafter_.gif') . ' ' : '' . $imagePasteAfter . ' '; + } + + + /** + * Get notification choices + * + * @return array + */ + public function getNotificationChoices() + { + $arrChoices = array(); + $objNotifications = \Database::getInstance()->execute("SELECT id,title FROM tl_nc_notification WHERE type='birthday_mail' ORDER BY title"); + + while ($objNotifications->next()) + { + $arrChoices[$objNotifications->id] = $objNotifications->title; + } + + return $arrChoices; + } + + + /** + * Return the edit notification wizard + * + * @param \DataContainer + * + * @return string + */ + public function editNotification(\DataContainer $dc) + { + return ($dc->value < 1) ? '' : ' value))) . '\',\'url\':this.href});return false">' . \Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_birthdaymailer']['edit_notification'][0], 'style="vertical-align:top"') . ''; + } + + + /** + * Delete an according BirthdayMailer configuration if the member group is deleted. + * + * @param \DataContainer $dc + */ + public function deleteConfiguration(\DataContainer $dc) + { + /** @var BirthdayMailer|\Contao\Model $objBirthdayMailer */ + /** @noinspection PhpUndefinedMethodInspection */ + $objBirthdayMailer = BirthdayMailer::findBy('memberGroup', $dc->id); + $objBirthdayMailer->delete(); + } +} \ No newline at end of file diff --git a/system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php b/system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php new file mode 100644 index 0000000..fe7ae95 --- /dev/null +++ b/system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php @@ -0,0 +1,187 @@ + + */ + + +namespace BirthdayMailer\Model; + +use Haste\DateTime\DateTime; +use NotificationCenter\Model\Notification; + + +/** + * Class BirthdayMailer + * @package BirthdayMailer\Model + */ +class BirthdayMailer extends \Model +{ + + /** + * The table name + * + * @var string + */ + protected static $strTable = 'tl_birthdaymailer'; + + + /** + * Send the birthday emails for the current configuration + * + * @return array + */ + public static function sendBirthdayMails() + { + $arrResult = array + ( + 'success' => array(), + 'failed' => array(), + 'aborted' => array() + ); + + $time = time(); + + self::synchronizeDatabaseTimeZone(); + + /** @noinspection PhpUndefinedMethodInspection */ + $objResult = \Database::getInstance()->query(sprintf(' + SELECT%4$s m.*, mg.name as memberGroupName, bm.nc_notification + FROM %2$s m + JOIN tl_member_to_group m2g ON m2g.member_id=m.id + JOIN %3$s mg ON mg.id=m2g.group_id + JOIN %1$s bm ON bm.membergroup=mg.id + WHERE %5$s%6$s%7$s%8$s + ORDER BY m.id, bm.sorting DESC', + static::getTable(), + \MemberModel::getTable(), + \MemberGroupModel::getTable(), + // Select distinct + \Config::get('birthdayMailerAllowDuplicates') ? "" : " DISTINCT", + // Only active BirthdayMail configurations + "bm.disable<>1 ", + // Only active members + "AND m.disable<>1 AND (m.start='' OR m.start<$time) AND (m.stop='' OR m.stop>$time) ", + // Only active member groups + "AND mg.disable<>1 AND (mg.start='' OR mg.start<$time) AND (mg.stop='' OR mg.stop>$time) ", + // Only birthday members if not in developer mode + (\Config::get('birthdayMailerDeveloperMode') && \Config::get('birthdayMailerDeveloperModeIgnoreDate')) ? '' : "AND FROM_UNIXTIME(m.dateOfBirth, '%e.%m') = '" . date('d.m', $time) . "' " + ) + ); + + if ($objResult->numRows < 1) + { + return array(); + } + + while ($objResult->next()) + { + // !HOOK: now check via custom hook if sending should be aborted + $blnAbortSendMail = false; + + if (isset($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail']) && is_array($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail'])) + { + foreach ($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail'] as $callback) + { + $objCallback = \System::importStatic($callback[0]); + $blnAbortSendMail = $objCallback->{$callback[1]}($objResult, $blnAbortSendMail); + } + } + + if ($blnAbortSendMail) + { + $arrResult['aborted'][] = $objResult->row(); + continue; + } + + if (static::sendMail($objResult)) + { + $arrResult['success'][] = $objResult->row(); + } + else + { + $arrResult['failed'][] = $objResult->row(); + } + } + + return $arrResult; + } + + + /** + * Send an email. + * + * @param \Database\Result|object $objResult + * + * @return bool + */ + protected static function sendMail($objResult) + { + /** @var Notification $objNotification */ + /** @noinspection PhpUndefinedMethodInspection */ + $objNotification = Notification::findByPk($objResult->nc_notification); + + // Build tokens + $arrTokens = array(); + $objDateOfBirth = new DateTime('@' . $objResult->dateOfBirth); + + foreach ($objResult->row() as $field => $value) + { + if (in_array($field, ['memberGroupName', 'nc_notification'])) + { + continue; + } + + $arrTokens['birthdaychild_' . $field] = $value; + } + + $arrTokens['birthdaychild_name'] = trim(sprintf('%s %s', $objResult->firstname, $objResult->lastname)); + $arrTokens['birthdaychild_age'] = $objDateOfBirth->getAge(); +// $arrTokens['birthdaychild_salutation'] = +// $arrTokens['birthdaychild_welcoming_personally'] +// $arrTokens['birthdaychild_welcoming_formally'] +// $arrTokens['birthdaymailer_groupname'] + + // !HOOK: alter the notification tokens + if (isset($GLOBALS['TL_HOOKS']['birthdayMailerGetNotificationTokens']) && is_array($GLOBALS['TL_HOOKS']['birthdayMailerGetNotificationTokens'])) + { + foreach ($GLOBALS['TL_HOOKS']['birthdayMailerGetNotificationTokens'] as $callback) + { + $objCallback = \System::importStatic($callback[0]); + $arrTokens = $objCallback->{$callback[1]}($arrTokens, $objResult); + } + } + + if (null !== $objNotification) + { + $objNotification->send($arrTokens); + + return true; + } + + return false; + } + + + /** + * Synchronize time zone on database + * @see https://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/ + */ + private static function synchronizeDatabaseTimeZone() { + $now = new DateTime(); + + $mins = $now->getOffset() / 60; + $sgn = ($mins < 0 ? -1 : 1); + $mins = abs($mins); + $hrs = floor($mins / 60); + $mins -= $hrs * 60; + $offset = sprintf('%+d:%02d', $hrs*$sgn, $mins); + + \Database::getInstance()->query(sprintf('SET time_zone=\'%s\';', $offset)); + } +} diff --git a/system/modules/BirthdayMailer/templates/backend/be_birthday-mailer.html5 b/system/modules/BirthdayMailer/templates/backend/be_birthday-mailer.html5 old mode 100644 new mode 100755