| 1 | <?php |
|---|
| 2 | // WCF includes |
|---|
| 3 | require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * sends emails to group leaders and places a display notification |
|---|
| 7 | * |
|---|
| 8 | * @author Markus Gerdelmann, Torben Brodt |
|---|
| 9 | * @package de.mdman.application.register |
|---|
| 10 | * @license GNU General Public License <http://opensource.org/licenses/gpl-3.0.html> |
|---|
| 11 | */ |
|---|
| 12 | class UserGroupApplyMailListener implements EventListener { |
|---|
| 13 | protected $this->eventObj; |
|---|
| 14 | |
|---|
| 15 | /** |
|---|
| 16 | * @see EventListener::execute() |
|---|
| 17 | */ |
|---|
| 18 | public function execute($eventObj, $className, $eventName) { |
|---|
| 19 | $this->eventObj = $eventObj; |
|---|
| 20 | |
|---|
| 21 | // requires |
|---|
| 22 | require_once(WCF_DIR.'lib/data/mail/Mail.class.php'); |
|---|
| 23 | require_once(WCF_DIR.'lib/system/language/Language.class.php'); |
|---|
| 24 | |
|---|
| 25 | // send notifications |
|---|
| 26 | $sql = "SELECT user.*, |
|---|
| 27 | displayNotification, |
|---|
| 28 | emailNotification |
|---|
| 29 | FROM wcf".WCF_N."_group_application_mail |
|---|
| 30 | NATURAL JOIN wcf".WCF_N."_user user |
|---|
| 31 | WHERE groupID = ".intval($this->eventObj->group->groupID)." |
|---|
| 32 | AND emailNotification = 1"; |
|---|
| 33 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 34 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 35 | if ($row['userID'] == WCF::getUser()->userID) { |
|---|
| 36 | continue; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | if($row['displayNotification']) { |
|---|
| 40 | $this->display($row); |
|---|
| 41 | } |
|---|
| 42 | if($row['emailNotification']) { |
|---|
| 43 | $this->email($row); |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | // enable user language |
|---|
| 48 | WCF::getLanguage()->setLocale(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * |
|---|
| 53 | */ |
|---|
| 54 | protected function display($row) { |
|---|
| 55 | $sql = "INSERT INTO wcf".WCF_N."_group_application_notification |
|---|
| 56 | (applicationID, userID) |
|---|
| 57 | VALUES (".$this->eventObj->applicationID.", ".$row['userID'].")"; |
|---|
| 58 | WCF::getDB()->sendQuery($sql); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * |
|---|
| 63 | */ |
|---|
| 64 | protected function email($row) { |
|---|
| 65 | $languages = array(); |
|---|
| 66 | $languages[WCF::getLanguage()->getLanguageID()] = WCF::getLanguage(); |
|---|
| 67 | $languages[0] = WCF::getLanguage(); |
|---|
| 68 | |
|---|
| 69 | // get language |
|---|
| 70 | if (!isset($languages[$row['languageID']])) { |
|---|
| 71 | $languages[$row['languageID']] = new Language($row['languageID']); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | // enable language |
|---|
| 75 | $languages[$row['languageID']]->setLocale(); |
|---|
| 76 | |
|---|
| 77 | // send mail |
|---|
| 78 | $subjectData = array( |
|---|
| 79 | '$author' => WCF::getUser()->username, |
|---|
| 80 | '$group' => $this->eventObj->group, |
|---|
| 81 | 'PAGE_TITLE' => PAGE_TITLE |
|---|
| 82 | ); |
|---|
| 83 | $messageData = array( |
|---|
| 84 | '$author' => WCF::getUser()->username, |
|---|
| 85 | '$group' => $this->eventObj->group, |
|---|
| 86 | 'PAGE_TITLE' => PAGE_TITLE, |
|---|
| 87 | '$pageurl' => FileUtil::addTrailingSlash(PAGE_URL), |
|---|
| 88 | '$recipient' => $row['username'], |
|---|
| 89 | '$reason' => isset($this->eventObj->reason) ? $this->eventObj->reason : '' |
|---|
| 90 | ); |
|---|
| 91 | |
|---|
| 92 | $mail = new Mail(array($row['username'] => $row['email']), $languages[$row['languageID']]->get('wcf.groupapplymail.mail.subject.'.$this->eventObj->group->groupType, $subjectData), $languages[$row['languageID']]->get('wcf.groupapplymail.mail.body.'.$this->eventObj->group->groupType, $messageData)); |
|---|
| 93 | $mail->send(); |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | ?> |
|---|