/** * Sends appropriate email depending on status. * Should be called only once upon each change of this something, * * @param UserTable $user * @param string $cause 'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied' * @param string $reason 'N' new subscription, 'R' renewal, 'U'=update ) * @param int $autorenewed 0: not auto-renewing (manually renewed), 1: automatically renewed (if $reason == 'R') */ public function sendNewStatusEmail($user, $cause, $reason, $autorenewed = 0) { global $_CB_framework; if (!is_object($user)) { return; } $emailkind = null; if ($this->status == 'A' && $cause == 'PaidSubscription' && $reason != 'R') { $emailkind = 'thankyou'; } elseif ($this->status == 'A' && $cause == 'PaidSubscription' && $reason == 'R' && $autorenewed == 0) { $emailkind = 'renewal'; } elseif ($this->status == 'A' && $cause == 'PaidSubscription' && $reason == 'R' && $autorenewed == 1) { $emailkind = 'autorenewal'; } elseif ($this->status == 'X' && $cause == 'Denied') { $emailkind = 'expiration'; } elseif ($this->status == 'C' && $cause == 'Denied' && $user->id == $_CB_framework->myId() && $_CB_framework->getUi() == 1) { $emailkind = 'cancelled'; // by the user only in frontend } elseif ($cause == 'Pending' && $reason != 'R' && $autorenewed == 0) { $emailkind = 'pendingfirst'; } elseif ($cause == 'Pending' && $reason == 'R' && $autorenewed == 0) { $emailkind = 'pendingrenewal'; } if ($emailkind) { // email to user only if activated for the first time: $plan = $this->getPlan(); if (!$plan) { return; } cbimport('cb.tabs'); // for cbNotification and comprofilerMail() cbimport('language.front'); // for _UE_EMAILFOOTER translation $savedLanguage = CBPTXT::setLanguage($user->getUserLanguage()); $mailHtml = $plan->get($emailkind . 'emailhtml') == '1' ? 1 : 0; $mailSubject = $this->getPersonalized($emailkind . 'emailsubject', false, false); $mailBody = $this->getPersonalized($emailkind . 'emailbody', $mailHtml); $mailCC = trim($plan->get($emailkind . 'emailcc')); $mailBCC = trim($plan->get($emailkind . 'emailbcc')); $mailAttachments = trim($plan->get($emailkind . 'emailattachments')); if ($mailCC != '') { $mailCC = preg_split('/ *, */', $mailCC); } else { $mailCC = null; } if ($mailBCC != '') { $mailBCC = preg_split('/ *, */', $mailBCC); } else { $mailBCC = null; } if ($mailAttachments != '') { $mailAttachments = preg_split('/ *, */', $mailAttachments); } else { $mailAttachments = null; } if ($mailSubject || $mailBody) { $notifier = new cbNotification(); $notifier->sendFromSystem($user, $mailSubject, $mailBody, true, $mailHtml, $mailCC, $mailBCC, $mailAttachments); } CBPTXT::setLanguage($savedLanguage); } //TBD: else email in case of deactivation }