. */ class CandidateMail { private $oldvalues; private $newvalues; private $newappl; private $candidate_id; private $position; private $datenow; public function __construct($oldvalues, $newvalues, $newappl, $candidate_id) { $this->oldvalues = $oldvalues; $this->newvalues = $newvalues; #debug_array("oldvalues", $oldvalues); #debug_array("newvalues", $newvalues); $this->newappl = $newappl; $this->candidate_id = $candidate_id; if( isset($newvalues['Position']) && strlen($newvalues['Position'])>0 && $newvalues['Position']!="!ERROR!" ) $this->position = $newvalues['Position']; else $this->position = $oldvalues['Position']; $this->datenow = date("Y-m-d H:i:s"); } public function __destruct() { } public function send() { global $setup; if( $this->newappl ) { if( $setup['CandidateMailApplicantNew'] ) $this->newToCandidate(); if( $setup['CandidateMailJcNew'] ) $this->newToJC(); }elseif( strlen($this->getChangedInfo())>0 ) { if( $setup['CandidateMailApplicantEdit'] ) $this->editToCandidate(); if( $setup['CandidateMailJcEdit'] ) $this->editToJC(); } } public function sendapproval() { global $setup; $ret = ""; if( $setup['CandidateMailApplicantStatus'] ) $ret .= $this->approvalToCandidate(); if( $setup['CandidateMailJcStatus'] ) $ret .= $this->approvalToJC(); return $ret; } private function getCandidateMail($newappl) { if( $newappl ) { return $this->newvalues['E-mail']; }else { if( $_SESSION['sess_name']==$this->oldvalues['username'] ) { // Candidate did update his/her own application if( isset($this->newvalues['E-mail']) ) return $this->newvalues['E-mail']; elseif( isset($this->oldvalues['E-mail']) ) return $this->oldvalues['E-mail']; else return null; }else { // Candidate did not update his/her own application if( isset($this->oldvalues['E-mail']) AND isset($this->newvalues['E-mail']) ) { if( $this->oldvalues['E-mail']==$this->newvalues['E-mail'] ) return $this->newvalues['E-mail']; else return array($this->oldvalues['E-mail'], $this->newvalues['E-mail']); }elseif( isset($this->oldvalues['E-mail']) ) return $this->oldvalues['E-mail']; elseif( isset($this->newvalues['E-mail']) ) return $this->newvalues['E-mail']; else return null; } } } private function getFrom() { global $setup; return "\"Juridical Commission AEGEE-Europe\" <".$setup['MailSenderJc'].">"; } private function getNewInfo() { $k = array_keys($this->newvalues); $r = ""; for( $i=0; $inewvalues[ $k[$i] ])."\n"; } return rtrim($r); } private function getChangedInfo() { $ko = array_keys($this->oldvalues); $kn = array_keys($this->newvalues); $r = ""; for( $i=0; $ioldvalues[ $kn[$i] ])>0 AND strlen($this->newvalues[ $kn[$i] ])>0 AND $this->oldvalues[ $kn[$i] ]!=$this->newvalues[ $kn[$i] ] ) $r .= "\t".$kn[$i].": ".$this->oldvalues[ $kn[$i] ]." => ".$this->newvalues[ $kn[$i] ]."\n"; elseif( strlen($this->oldvalues[ $kn[$i] ])>0 AND !(strlen($this->newvalues[ $kn[$i] ])>0) AND $this->oldvalues[ $kn[$i] ]!=$this->newvalues[ $kn[$i] ] ) $r .= "\t".$kn[$i].": ".$this->oldvalues[ $kn[$i] ]." => [empty]\n"; elseif( !(strlen($this->oldvalues[ $kn[$i] ])>0) AND strlen($this->newvalues[ $kn[$i] ])>0 AND $this->oldvalues[ $kn[$i] ]!=$this->newvalues[ $kn[$i] ] ) $r .= "\t".$kn[$i].": [empty] => ".$this->newvalues[ $kn[$i] ]."\n"; }elseif( strlen($this->newvalues[ $kn[$i] ])>0 ) { $r .= "\t".$kn[$i].": [N/A] => ".$this->newvalues[ $kn[$i] ]."\n"; } } return rtrim($r); } private function newToCandidate() { global $setup, $ldap; if( $mail = new Mail($setup['MailReturnpath'], $this->getCandidateMail(true)) ) { $mail->setSubject("Candidature upcoming Agora (ID ".$this->candidate_id.")"); $mail->addHeader("To", "\"".Mail::encodeHeader($this->newvalues['First name']." ".$this->newvalues['Family name'])."\" <".$this->newvalues['E-mail'].">"); $mail->addHeader("From", $this->getFrom()); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "new to candidate"); $mail->addHeader("X-ApplicationID", $this->candidate_id); $mail->addHeader("X-Signature", get_signature("new to candidate", $this->candidate_id)); if( isset($this->newvalues['First name']) ) $m = "Hi ".$this->newvalues['First name'].",\n\n"; else $m = "Hi ".$this->oldvalues['First name'].",\n\n"; $m .= "Thanks for candidating for the position of '".$this->position."'.\n\n"; $m .= "Please keep in mind that the Juridical Commission still has to accept your candidature. You can find the status of your candidature when you log in again."; if( $setup['CandidateMailApplicantStatus'] ) $m .= " You will also receive a notification by mail when your candidature is approved or rejected."; $m .= "\n\n"; $m .= "In case you want to edit your candidature, log in with your ".$ldap->getSystemName()." account or contact the Juridical Commission by mail.\n\n"; $m .= "If you want to withdraw your candidature, please contact the Juridical Commission as soon as possible.\n\n"; $m .= "You filled in the following information:\n\n"; $m .= $this->getNewInfo()."\n\n"; $m .= "For questions, you can reply to this e-mail.\n\n"; if( $_SESSION['sess_uid']>0 ) $m .= "\n\n-- This candidature was created by ".$_SESSION['sess_name']." --"; $mail->setMessage($m); switch( $mail->send(true) ) { case Mail::MAIL_OK: echoln("
Send mail to candidate."); break; case Mail::MAIL_QUEUE: echoln("
Queued mail to candidate (will be sent later)."); break; default: echoln("
Failed sending mail to candidate."); } }else { echoln("
Failed sending mail to candidate."); } } private function editToCandidate() { global $setup, $ldap; if( $mail = new Mail($setup['MailReturnpath'], $this->getCandidateMail(false)) ) { $mail->setSubject("Candidature upcoming Agora (ID ".$this->candidate_id.")"); if( isset($this->newvalues['First name']) ) $mail->addHeader("To", "\"".Mail::encodeHeader($this->newvalues['First name']." ".$this->newvalues['Family name'])."\" <".$this->newvalues['E-mail'].">"); else $mail->addHeader("To", "\"".Mail::encodeHeader($this->oldvalues['First name']." ".$this->oldvalues['Family name'])."\" <".$this->newvalues['E-mail'].">"); if( is_array($tomail = $this->getCandidateMail(false)) ) { if( isset($this->newvalues['First name']) ) $mail->addHeader("Cc", "\"".Mail::encodeHeader($this->newvalues['First name']." ".$this->newvalues['Family name'])."\" <".$this->oldvalues['E-mail'].">"); else $mail->addHeader("Cc", "\"".Mail::encodeHeader($this->oldvalues['First name']." ".$this->oldvalues['Family name'])."\" <".$this->oldvalues['E-mail'].">"); } $mail->addHeader("From", $this->getFrom()); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "edit to candidate"); $mail->addHeader("X-ApplicationID", $this->candidate_id); $mail->addHeader("X-Signature", get_signature("edit to candidate", $this->candidate_id)); if( isset($this->newvalues['First name']) ) $m = "Hi ".$this->newvalues['First name'].",\n\n"; else $m = "Hi ".$this->oldvalues['First name'].",\n\n"; $m .= "Thanks for updating your candidature for the position of '".$this->position."'.\n\n"; $m .= "Please keep in mind that the Juridical Commission still has to accept your candidature in case this was not done yet. You can find the status of your candidature when you log in again.\n\n"; $m .= "In case you want to edit your candidature, log in with your ".$ldap->getSystemName()." account or contact the Juridical Commission by mail.\n\n"; $m .= "If you want to withdraw your candidature, please contact the Juridical Commission as soon as possible.\n\n"; $m .= "The following information was changed:\n\n"; $m .= $this->getChangedInfo()."\n\n"; $m .= "For questions, you can reply to this e-mail.\n\n"; if( $_SESSION['sess_uid']>0 ) $m .= "\n\n-- This candidature was updated by ".$_SESSION['sess_name']." --"; $mail->setMessage($m); switch( $mail->send(true) ) { case Mail::MAIL_OK: echoln("
Send mail to candidate."); break; case Mail::MAIL_QUEUE: echoln("
Queued mail to candidate (will be sent later)."); break; default: echoln("
Failed sending mail to candidate."); } }else { echoln("
Failed sending mail to candidate."); } } private function newToJC() { global $setup; if( $mail = new Mail($setup['MailReturnpath'], $setup['MailJc']) ) { if( isset($this->newvalues['First name']) ) $mail->setSubject(Mail::encodeHeader("Candidature for '".$this->position."' by ".$this->newvalues['First name']." ".$this->newvalues['Family name']." (ID ".$this->candidate_id.")")); else $mail->setSubject(Mail::encodeHeader("Candidature for '".$this->position."' by ".$this->oldvalues['First name']." ".$this->oldvalues['Family name']." (ID ".$this->candidate_id.")")); $mail->addHeader("To", "\"Juridical Commission AEGEE-Europe\" <".$setup['MailJc'].">"); $mail->addHeader("From", $this->getFrom()); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "new to jc"); $mail->addHeader("X-ApplicationID", $this->candidate_id); $mail->addHeader("X-Signature", get_signature("new to jc", $this->candidate_id)); $m = "Hi JC,\n\n"; $m .= "A new candidature was made for the position of '".$this->position."'.\n\n"; $m .= "The personal data of the candidate are:\n\n"; $m .= $this->getNewInfo()."\n\n"; if( $_SESSION['sess_uid']>0 ) $m .= "\n\n-- This candidature was created by ".$_SESSION['sess_name']." --"; $mail->setMessage($m); switch( $mail->send(true) ) { case Mail::MAIL_OK: echoln("
Send mail to Juridical Commission."); break; case Mail::MAIL_QUEUE: echoln("
Queued mail to Juridical Commission (will be sent later)."); break; default: echoln("
Failed sending mail to Juridical Commission."); } }else { echoln("
Failed sending mail to Juridical Commission."); } } private function editToJC() { global $setup; if( $mail = new Mail($setup['MailReturnpath'], $setup['MailJc']) ) { if( isset($this->newvalues['First name']) ) $mail->setSubject(Mail::encodeHeader("Changed candidature for '".$this->position."' by ".$this->newvalues['First name']." ".$this->newvalues['Family name']." (ID ".$this->candidate_id.")")); else $mail->setSubject(Mail::encodeHeader("Changed candidature for '".$this->position."' by ".$this->oldvalues['First name']." ".$this->oldvalues['Family name']." (ID ".$this->candidate_id.")")); $mail->addHeader("To", "\"Juridical Commission AEGEE-Europe\" <".$setup['MailJc'].">"); $mail->addHeader("From", $this->getFrom()); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "edit to jc"); $mail->addHeader("X-ApplicationID", $this->candidate_id); $mail->addHeader("X-Signature", get_signature("edit to jc", $this->candidate_id)); $m = "Hi JC,\n\n"; $m .= "A candidature for the position of '".$this->position."' has been changed.\n\n"; $m .= "The following information was changed:\n\n"; $m .= $this->getChangedInfo()."\n\n"; if( $_SESSION['sess_uid']>0 ) $m .= "\n\n-- This candidature was changed by ".$_SESSION['sess_name']." --"; $mail->setMessage($m); switch( $mail->send(true) ) { case Mail::MAIL_OK: echoln("
Send mail to Juridical Commission."); break; case Mail::MAIL_QUEUE: echoln("
Queued mail to Juridical Commission (will be sent later)."); break; default: echoln("
Failed sending mail to Juridical Commission."); } }else { echoln("
Failed sending mail to Juridical Commission."); } } private function approvalToCandidate() { global $setup, $ldap; if( $mail = new Mail($setup['MailReturnpath'], $this->newvalues['Email']) ) { $mail->setSubject("Change in the approval of your candidature (ID ".$this->candidate_id.")"); $mail->addHeader("To", "\"".Mail::encodeHeader($this->newvalues['FirstName']." ".$this->newvalues['LastName'])."\" <".$this->newvalues['Email'].">"); $mail->addHeader("From", $this->getFrom()); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "approval to candidate"); $mail->addHeader("X-ApplicationID", $this->candidate_id); $mail->addHeader("X-Signature", get_signature("approval to candidate", $this->candidate_id)); $m = "Hi ".$this->newvalues['FirstName'].",\n\n"; $m .= "The approval of your candidature for the position of '".$this->newvalues['Position']."' changed from ".$this->oldvalues['Approved']." to *".$this->newvalues['Approved']."*.\n\n"; $m .= "If you want to edit your candidature, go back to the website, log in with your ".$ldap->getSystemName()." account, and edit it. You can also contact the Juridical Commission. For canceling you'll have to contact the Juridical Commission.\n\n"; $m .= "For questions, you can reply to this e-mail.\n\n"; $m .= "With kind regards,\n\nThe Juridical Commission of AEGEE-Europe\n\n"; if( $_SESSION['sess_uid']>0 ) $m .= "\n\n-- This candidature was handled by ".$_SESSION['sess_name']." --"; $mail->setMessage($m); switch( $mail->send(true) ) { case Mail::MAIL_OK: return "
Send mail to candidate."; break; case Mail::MAIL_QUEUE: return "
Queued mail to candidate (will be sent later)."; break; default: return "
Failed sending mail to candidate."; } }else { return "
Failed sending mail to the candidate."; } } private function approvalToJC() { global $setup; if( $mail = new Mail($setup['MailReturnpath'], $setup['MailJc']) ) { $mail->setSubject("Change in the approval of a candidature (ID ".$this->candidate_id.")"); $mail->addHeader("To", "\"Juridical Commission AEGEE-Europe\" <".$setup['MailJc'].">"); $mail->addHeader("From", $this->getFrom()); $mail->addHeader("Auto-Submitted", "auto-generated"); $mail->addHeader("X-Content", "approval to jc"); $mail->addHeader("X-ApplicationID", $this->candidate_id); $mail->addHeader("X-Signature", get_signature("approval to jc", $this->candidate_id)); $m = "Hi JC,\n\n"; $m .= "The candidature of '".$this->newvalues['FirstName']." ".$this->newvalues['LastName']."' for the position of '".$this->newvalues['Position']."' changed from ".$this->oldvalues['Approved']." to *".$this->newvalues['Approved']."*.\n\n"; $m .= "With kind regards,\n\nYour webmaster\n\n"; if( $_SESSION['sess_uid']>0 ) $m .= "\n\n-- This candidature was handled by ".$_SESSION['sess_name']." --"; $mail->setMessage($m); switch( $mail->send(true) ) { case Mail::MAIL_OK: return "
Send mail to Juridical Commission."; break; case Mail::MAIL_QUEUE: return "
Queued mail to Juridical Commission (will be sent later)."; break; default: return "
Failed sending mail to Juridical Commission."; } }else { return "
Failed sending mail to the Juridical Commission."; } } } ?>