. */ require_once("./IRundaily.php"); class SendReminderRundaily implements IRundaily { private $messages; private $totalNotValidated = 0; public function __construct() { $this->messages = array(); } public function run() { $queryBuilder = new QueryBuilder($GLOBALS['DB'], "ab_bodies"); $queryBuilder->addField(array("bodycode", "bodyname", "email", "bodystatus", "bodycategory", "bodycategoryorder", "nodelegates", "noenvoys", "novisitors", "noobservers")); if( $GLOBALS['DB']->select($queryBuilder->toQuery()) > 0 ) { while( $body = $GLOBALS['DB']->fetchAssoc() ) { $this->sendReminderForBody($body); } }else { $this->addMessage("!!! No bodies found !!!"); } if( $this->isSendReminder() ) { $this->addMessage("Number of applications that are not validated: " . $this->totalNotValidated); } } public function isEnabled() { global $setup; return $setup['EventDateStart'] != "" && is_before_ex("EventDateStart") && $setup['SetupBoardApproval'] == "yes"; } public function getTitle() { return "Sending reminders about not validated members and no applications"; } public function getMessages() { return $this->messages; } private function addMessage($message) { $this->messages[] = $message; } private function isSendReminder() { global $setup; $applicationsOver = get_sql_date($setup['EventDateAppEnd']) <= date("Y-m-d"); $threeDaysBeforeParticipantTypeFixed = get_sql_date($setup['EventDatePartTypeFix']) == date("Y-m-d", strtotime("+3 days")); $notAfterParticipantTypeFixed = get_sql_date($setup['EventDatePartTypeFix']) >= date("Y-m-d"); return ($applicationsOver || $threeDaysBeforeParticipantTypeFixed) && $notAfterParticipantTypeFixed; } private function sendReminderForBody($body) { $queryBuilder = new QueryBuilder($GLOBALS['DB'], "applications"); $queryBuilder->addField(array("id", "firstname", "lastname", "email", "participanttype", "participantorder", "boardconfirmed")); $queryBuilder->addWhereEquals("bodycode", $body['bodycode']); if( $GLOBALS['DB']->select2($queryBuilder->toQuery()) > 0 ) { $this->sendReminderIfNotValidatedApplications($body); }else { $this->sendReminderNoApplications($body); } } private function sendReminderIfNotValidatedApplications($body) { global $setup; if( $this->isSendReminder() ) { $notValidated = array(); while( $application = $GLOBALS['DB']->fetchAssoc2() ) { if( $application['participanttype'] == "-" && $application['boardconfirmed'] != "no" ) { $notValidated[] = $application; } } if( count($notValidated) > 0 ) { // This body has not validated all applications yet $this->totalNotValidated += count($notValidated); $bccAddresses = array(); $message ="--- this mail has been send as a copy to the people that are not validated ---\n\n\n"; $message .="Dear board of " . $body['bodyname'] . ",\n\n"; $message .="We noticed that there are still applications for your body that are not "; $message .="validated. Please keep in mind that in order to let your members participate "; $message .="in this " . $setup['SetupEventType'] . " you'll have to assign them a participant type (delegate, "; $message .="envoy, visitor). If you fail to do so, your members will not be able to "; $message .="participate.\n\n"; $message .="At the moment, the following people are not yet validated:\n\n"; foreach( $notValidated as $application ) { $message .= "\t- " . $application['firstname'] . " " . $application['lastname'] . " (ID " . $application['id'] . ")\n"; $bccAddresses[] = $application['email']; } $message .= "\nTo stop receiving this message, please go to\n"; $message .= "\n\thttps://" . FULL_URL . "board.php?login\n\n"; $message .= "and either assign your member a participant type or reject them. You'll not "; $message .= "receive this message for people you have rejected.\n\n"; $message .= "The deadline to validate your members is " . $setup['EventDatePartTypeFix'] . " 23h59 " . date("T", strtotime($setup['EventDatePartTypeFix'])) . ".\n\n"; $message .= "Greetings,\n\n"; $message .= "The webmaster\n"; $message .= "\n\nThis reminder has been send on " . date("d.m.Y") . " and will be repeated few times until all participants are validated or the deadline has passed."; $mail = new Mail($setup['MailReturnpath'], $body['email']); $mail->setSubject("Please validate the " . $setup['SetupEventType'] . " applications for your body"); $mail->addHeader("To", "\"" . Mail::encodeHeader("Board " . $body['bodyname']) . "\" <" . $body['email'] . ">"); $mail->addHeader("From", "\"" . $setup['SetupEventType'] . " Application Mailer\" <" . $setup['EventApplFromEmail'] . ">"); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "reminder to board"); $mail->addHeader("X-BodyCode", $body['bodycode']); $mail->addHeader("X-Signature", get_signature("reminder to board", $body['bodycode'])); $mail->setMessage($message); switch( $mail->send(true) ) { case Mail::MAIL_OK: $this->addMessage("Send reminder for " . $body['bodyname'] . ": " . count($notValidated) . " applications not validated, send mail to inform board."); break; case MAIL::MAIL_QUEUE: $this->addMessage("Send reminder for " . $body['bodyname'] . ": " . count($notValidated) . " applications not validated, queued mail to inform board."); break; default: $this->addMessage("Send reminder for " . $body['bodyname'] . ": " . count($notValidated) . " applications not validated, but failed sending mail to board."); } // Make a separate mail as BCC to participants to prevent returning mails from triggering the wrong warnings $mail = new Mail($setup['MailReturnpath'], $bccAddresses); $mail->setSubject("Please validate the " . $setup['SetupEventType'] . " applications for your body"); $mail->addHeader("To", "\"" . Mail::encodeHeader("Board " . $body['bodyname']) . "\" <" . $body['email'] . ">"); $mail->addHeader("From", "\"" . $setup['SetupEventType'] . " Application Mailer\" <" . $setup['EventApplFromEmail'] . ">"); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "reminder to bccparticipants"); $mail->addHeader("X-BodyCode", $body['bodycode']); $mail->addHeader("X-Signature", get_signature("reminder to bccparticipants", $body['bodycode'])); $mail->setMessage($message); switch( $mail->send(true) ) { case Mail::MAIL_OK: $this->addMessage("- Send BCC to " . count($bccAddresses) . " applicants, mail send"); break; case MAIL::MAIL_QUEUE: $this->addMessage("- Send BCC to " . count($bccAddresses) . " applicants, mail queued"); break; default: $this->addMessage("- Send BCC to " . count($bccAddresses) . " applicants, mail failed"); } } } } private function sendReminderNoApplications($body) { global $setup; $reminderEnabled = $setup['NoApplicationsReminder'] > 0; $exactDaysBeforeDeadline = get_sql_date($setup['EventDateAppEnd']) == date("Y-m-d", strtotime("+" . $setup['NoApplicationsReminder'] . " days")); $deadlineApplicationsBeforeParticipantTypeFixed = get_sql_date($setup['EventDateAppEnd']) < get_sql_date($setup['EventDatePartTypeFix']); if( $reminderEnabled && $exactDaysBeforeDeadline && $deadlineApplicationsBeforeParticipantTypeFixed ) { if( $body['bodycategory'] == "Locals" && (in_array($setup['SetupEventType'], array("EBM", "EPM", "AGORA"))) ) { $m = "Dear board of " . $body['bodyname'] . ",\n\n"; $m .= "Your are receiving this automated reminder because nobody from your local has yet applied for the upcoming " . $setup['SetupEventType'] . ", while the deadline will be soon (" . $setup['EventDateAppEnd'] . "). Please make sure that your local will be represented at this statutory meeting. Not only because the " . $setup['SetupEventType'] . " needs your opinion and votes, but also because this is one of the Antenna Criteria (as explained below).\n\n"; if( $body['bodystatus'] == "CA" ) { // Contact Antenna $m .= "In the 'Working Format Antennae Criteria', article 3.1, the following is stated:\n\n"; $m .= "\tTo remain a Contact Antenna, it must: send envoys to at least one ordinary Agora or European Boards' Meeting in a period of three consecutive statutory meetings; ...\n\n"; }else { // Antenna $m .= "In the 'Working Format Antennae Criteria', article 5.1, the following is stated:\n\n"; $m .= "\tTo remain Antenna, it must: send delegates either to two ordinary Agoras or to one ordinary Agora and a European Boards' Meeting in every period of three consecutive AEGEE-Europe meetings (Agora or European Boards' Meeting); ...\n\n"; } $m .= "(please note there are more criteria than mentioned here, and that the Comité Directeur can make exceptions, please consult the CIA for the full text).\n\n"; $m .= "Not fulfilling this criterion may result in the downgrading or deletion of your local. Naturally, if you've fulfilled this requirement up until now you have nothing to worry about.\n\n"; $m .= "We hope to meet you soon!\n\n"; $m .= "With kind regards,\n\nThe Chair team of AEGEE-Europe"; if( $mail = new Mail($setup['MailReturnpath'], $body['email']) ) { $mail->setSubject("Deadline for " . $setup['SetupEventType'] . " approaching - there is no applications from your local yet"); $mail->addHeader("To", "\"" . Mail::encodeHeader("Board " . $body['bodyname']) . "\" <" . $body['email'] . ">"); $mail->addHeader("From", "\"Chair team AEGEE-Europe\" <" . $setup['MailChair'] . ">"); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "reminder to board"); $mail->addHeader("X-BodyCode", $body['bodycode']); $mail->addHeader("X-Signature", get_signature("reminder to board", $body['bodycode'])); $mail->setMessage($m); switch( $mail->send(true) ) { case Mail::MAIL_OK: $this->addMessage("No applications from " . $body['bodyname'] . ", send mail to inform board."); break; case MAIL::MAIL_QUEUE: $this->addMessage("No applications from " . $body['bodyname'] . ", queued mail to inform board."); break; default: $this->addMessage("No applications from " . $body['bodyname'] . ", but failed sending mail to board."); } }else { $this->addMessage("No applications from " . $body['bodyname'] . ", but failed sending mail to board."); } } } } } ?>