Exemple #1
0
 /**
  * This function handles create the email notifications email.
  * @param string $notify_user the user to send the notification email to
  */
 function create_notification_email($notify_user)
 {
     global $sugar_version;
     global $sugar_config;
     global $app_list_strings;
     global $current_user;
     global $locale;
     global $beanList;
     $OBCharset = $locale->getPrecedentPreference('default_email_charset');
     require_once "include/SugarPHPMailer.php";
     $notify_address = $notify_user->emailAddress->getPrimaryAddress($notify_user);
     $notify_name = $notify_user->full_name;
     $GLOBALS['log']->debug("Notifications: user has e-mail defined");
     $notify_mail = new SugarPHPMailer();
     $notify_mail->AddAddress($notify_address, $locale->translateCharsetMIME(trim($notify_name), 'UTF-8', $OBCharset));
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $sugar_config['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     $xtpl = new XTemplate(get_notify_template_file($current_language));
     if ($this->module_dir == "Cases") {
         $template_name = "Case";
         //we should use Case, you can refer to the en_us.notify_template.html.
     } else {
         $template_name = $beanList[$this->module_dir];
         //bug 20637, in workflow this->object_name = strange chars.
     }
     $this->current_notify_user = $notify_user;
     if (in_array('set_notification_body', get_class_methods($this))) {
         $xtpl = $this->set_notification_body($xtpl, $this);
     } else {
         $xtpl->assign("OBJECT", $this->object_name);
         $template_name = "Default";
     }
     if (!empty($_SESSION["special_notification"]) && $_SESSION["special_notification"]) {
         $template_name = $beanList[$this->module_dir] . 'Special';
     }
     if ($this->special_notification) {
         $template_name = $beanList[$this->module_dir] . 'Special';
     }
     $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name);
     $xtpl->assign("ASSIGNER", $current_user->name);
     $port = '';
     if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
         $port = $_SERVER['SERVER_PORT'];
     }
     if (!isset($_SERVER['HTTP_HOST'])) {
         $_SERVER['HTTP_HOST'] = '';
     }
     $httpHost = $_SERVER['HTTP_HOST'];
     if ($colon = strpos($httpHost, ':')) {
         $httpHost = substr($httpHost, 0, $colon);
     }
     $parsedSiteUrl = parse_url($sugar_config['site_url']);
     $host = $parsedSiteUrl['host'];
     if (!isset($parsedSiteUrl['port'])) {
         $parsedSiteUrl['port'] = 80;
     }
     $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : '';
     $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : "";
     $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
     $xtpl->assign("URL", $cleanUrl . "/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
     $xtpl->assign("SUGAR", "Sugar v{$sugar_version}");
     $xtpl->parse($template_name);
     $xtpl->parse($template_name . "_Subject");
     $notify_mail->Body = from_html(trim($xtpl->text($template_name)));
     $notify_mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
     // cn: bug 8568 encode notify email in User's outbound email encoding
     $notify_mail->prepForOutbound();
     return $notify_mail;
 }
 /**
  * send reminders
  * @param SugarBean $bean
  * @param Administration $admin
  * @param array $recipients
  * @return boolean
  */
 protected function sendReminders(SugarBean $bean, Administration $admin, $recipients)
 {
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $GLOBALS['sugar_config']['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     if (!empty($bean->created_by)) {
         $user_id = $bean->created_by;
     } else {
         if (!empty($bean->assigned_user_id)) {
             $user_id = $bean->assigned_user_id;
         } else {
             $user_id = $GLOBALS['current_user']->id;
         }
     }
     $user = new User();
     $user->retrieve($bean->created_by);
     $OBCharset = $GLOBALS['locale']->getPrecedentPreference('default_email_charset');
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     if (empty($admin->settings['notify_send_from_assigning_user'])) {
         $from_address = $admin->settings['notify_fromaddress'];
         $from_name = $admin->settings['notify_fromname'] ? "" : $admin->settings['notify_fromname'];
     } else {
         $from_address = $user->emailAddress->getReplyToAddress($user);
         $from_name = $user->full_name;
     }
     $mail->From = $from_address;
     $mail->FromName = $from_name;
     $xtpl = new XTemplate(get_notify_template_file($current_language));
     $xtpl = $this->setReminderBody($xtpl, $bean, $user);
     $template_name = $GLOBALS['beanList'][$bean->module_dir] . 'Reminder';
     $xtpl->parse($template_name);
     $xtpl->parse($template_name . "_Subject");
     $mail->Body = from_html(trim($xtpl->text($template_name)));
     $mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
     $oe = new OutboundEmail();
     $oe = $oe->getSystemMailerSettings();
     if (empty($oe->mail_smtpserver)) {
         Log::fatal("Email Reminder: error sending email, system smtp server is not set");
         return;
     }
     foreach ($recipients as $r) {
         $mail->ClearAddresses();
         $mail->AddAddress($r['email'], $GLOBALS['locale']->translateCharsetMIME(trim($r['name']), 'UTF-8', $OBCharset));
         $mail->prepForOutbound();
         if (!$mail->Send()) {
             Log::fatal("Email Reminder: error sending e-mail (method: {$mail->Mailer}), (error: {$mail->ErrorInfo})");
         }
     }
     return true;
 }
Exemple #3
0
 /**
  * This function handles create the email notifications email.
  * @param string $templateName the name of the template used for the email content
  * @param null|User $notify_user User object, current user if not specified
  * @return XTemplate
  */
 protected function createNotificationEmailTemplate($templateName, $notify_user = null)
 {
     global $sugar_config, $current_user, $sugar_version, $locale;
     if ($notify_user && !empty($notify_user->preferred_language)) {
         $currentLanguage = $notify_user->preferred_language;
     } else {
         $currentLanguage = $locale->getAuthenticatedUserLanguage();
     }
     $xtpl = new XTemplate(get_notify_template_file($currentLanguage));
     if (in_array('set_notification_body', get_class_methods($this))) {
         $xtpl = $this->set_notification_body($xtpl, $this);
     } else {
         //Default uses OBJECT key for both subject and body (see en_us.notify_template.html)
         $singularModuleLabel = $GLOBALS['app_list_strings']['moduleListSingular'][$this->module_name];
         $xtpl->assign("OBJECT", $singularModuleLabel);
     }
     $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name);
     $xtpl->assign("ASSIGNER", $current_user->name);
     $parsedSiteUrl = parse_url($sugar_config['site_url']);
     $host = $parsedSiteUrl['host'];
     if (!isset($parsedSiteUrl['port'])) {
         $parsedSiteUrl['port'] = 80;
     }
     $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : '';
     $path = isset($parsedSiteUrl['path']) ? rtrim($parsedSiteUrl['path'], '/') : '';
     $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
     if (isModuleBWC($this->module_name)) {
         $xtpl->assign("URL", $cleanUrl . "/#bwc/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
     } else {
         $xtpl->assign('URL', $cleanUrl . '/index.php#' . $this->module_name . '/' . $this->id);
     }
     $xtpl->assign("SUGAR", "Sugar v{$sugar_version}");
     $xtpl->parse($templateName);
     $xtpl->parse($templateName . "_Subject");
     return $xtpl;
 }
Exemple #4
0
/**
 * @deprecated 7.0
 * @param $notify_user
 * @return mixed
 */
function create_alert_email($notify_user)
{
    global $sugar_version, $sugar_config, $app_list_strings, $current_user;
    if (empty($_SESSION['authenticated_user_language'])) {
        $current_language = $sugar_config['default_language'];
    } else {
        $current_language = $_SESSION['authenticated_user_language'];
    }
    $xtpl = new XTemplate(get_notify_template_file($current_language));
    $template_name = $focus->object_name;
    $focus->current_notify_user = $notify_user;
    if (in_array('set_notification_body', get_class_methods($focus))) {
        $xtpl = $focus->set_notification_body($xtpl, $focus);
    } else {
        $xtpl->assign("OBJECT", $focus->object_name);
        $template_name = "Default";
    }
    $xtpl->assign("ASSIGNED_USER", $focus->new_assigned_user_name);
    $xtpl->assign("ASSIGNER", $current_user->user_name);
    $xtpl->assign("URL", "{$sugar_config['site_url']}/index.php?module={$focus->module_dir}&action=DetailView&record={$focus->id}");
    $xtpl->assign("SUGAR", "Sugar v{$sugar_version}");
    $xtpl->parse($template_name);
    $xtpl->parse($template_name . "_Subject");
    $notify_mail->Body = from_html(trim($xtpl->text($template_name)));
    $notify_mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
    return $notify_mail;
    //end function create_alert_email
}
 /**
  * send reminders
  * @param SugarBean $bean
  * @param Administration $admin *use is deprecated*
  * @param array $recipients
  * @return boolean
  */
 protected function sendReminders(SugarBean $bean, Administration $admin, $recipients)
 {
     if (!empty($_SESSION["authenticated_user_language"])) {
         $currentLanguage = $_SESSION["authenticated_user_language"];
     } else {
         $currentLanguage = $GLOBALS["sugar_config"]["default_language"];
     }
     $user = BeanFactory::getBean('Users', $bean->created_by);
     $xtpl = new XTemplate(get_notify_template_file($currentLanguage));
     $xtpl = $this->setReminderBody($xtpl, $bean, $user);
     $templateName = "{$GLOBALS["beanList"][$bean->module_dir]}Reminder";
     $xtpl->parse($templateName);
     $xtpl->parse("{$templateName}_Subject");
     $mailTransmissionProtocol = "unknown";
     try {
         $mailer = MailerFactory::getSystemDefaultMailer();
         $mailTransmissionProtocol = $mailer->getMailTransmissionProtocol();
         // set the subject of the email
         $subject = $xtpl->text("{$templateName}_Subject");
         $mailer->setSubject($subject);
         // set the body of the email
         $body = trim($xtpl->text($templateName));
         $textOnly = EmailFormatter::isTextOnly($body);
         if ($textOnly) {
             $mailer->setTextBody($body);
         } else {
             $textBody = strip_tags(br2nl($body));
             // need to create the plain-text part
             $mailer->setTextBody($textBody);
             $mailer->setHtmlBody($body);
         }
         foreach ($recipients as $recipient) {
             // reuse the mailer, but process one send per recipient
             $mailer->clearRecipients();
             $mailer->addRecipientsTo(new EmailIdentity($recipient["email"], $recipient["name"]));
             $mailer->send();
         }
     } catch (MailerException $me) {
         $message = $me->getMessage();
         switch ($me->getCode()) {
             case MailerException::FailedToConnectToRemoteServer:
                 $GLOBALS["log"]->fatal("Email Reminder: error sending email, system smtp server is not set");
                 break;
             default:
                 $GLOBALS["log"]->fatal("Email Reminder: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})");
                 break;
         }
         return false;
     }
     return true;
 }
Exemple #6
0
 /**
  * This function handles create the email notifications email.
  * @param string $notify_user the user to send the notification email to
  * @return SugarPHPMailer
  */
 public function create_notification_email($notify_user)
 {
     global $sugar_version;
     global $sugar_config;
     global $current_user;
     global $locale;
     global $beanList;
     $OBCharset = $locale->getPrecedentPreference('default_email_charset');
     require_once "include/SugarPHPMailer.php";
     $notify_address = $notify_user->emailAddress->getPrimaryAddress($notify_user);
     $notify_name = $notify_user->full_name;
     $GLOBALS['log']->debug("Notifications: user has e-mail defined");
     $notify_mail = new SugarPHPMailer();
     $notify_mail->addAddress($notify_address, $locale->translateCharsetMIME(trim($notify_name), 'UTF-8', $OBCharset));
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $sugar_config['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     $xtpl = new XTemplate(get_notify_template_file($current_language));
     if ($this->module_dir == "Cases") {
         $template_name = "Case";
         //we should use Case, you can refer to the en_us.notify_template.html.
     } else {
         $template_name = $beanList[$this->module_dir];
         //bug 20637, in workflow this->object_name = strange chars.
     }
     $this->current_notify_user = $notify_user;
     if (in_array('set_notification_body', get_class_methods($this))) {
         $xtpl = $this->set_notification_body($xtpl, $this);
     } else {
         $xtpl->assign("OBJECT", translate('LBL_MODULE_NAME'));
         $template_name = "Default";
     }
     if (!empty($_SESSION["special_notification"]) && $_SESSION["special_notification"]) {
         $template_name = $beanList[$this->module_dir] . 'Special';
     }
     if ($this->special_notification) {
         $template_name = $beanList[$this->module_dir] . 'Special';
     }
     $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name);
     $xtpl->assign("ASSIGNER", $current_user->name);
     $parsedSiteUrl = parse_url($sugar_config['site_url']);
     $host = $parsedSiteUrl['host'];
     if (!isset($parsedSiteUrl['port'])) {
         $parsedSiteUrl['port'] = 80;
     }
     $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : '';
     $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : "";
     $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
     $xtpl->assign("URL", $cleanUrl . "/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
     $xtpl->assign("SUGAR", "Sugar v{$sugar_version}");
     $xtpl->parse($template_name);
     $xtpl->parse($template_name . "_Subject");
     // NOTE: Crowdin translation system requires some HTML tags in the template, namely <p> and <br>.
     // These will go into the HTML version of the email, but not into the text version, nor the subject line.
     $tempBody = from_html(trim($xtpl->text($template_name)));
     $notify_mail->msgHTML($tempBody);
     // Improve the text version of the email with some "reverse linkification",
     // making "<a href=link>text</a>" links readable as "text [link]"
     $tempBody = preg_replace('/<a href=([\\"\']?)(.*?)\\1>(.*?)<\\/a>/', "\\3 [\\2]", $tempBody);
     // all the other HTML tags get removed from the text version:
     $notify_mail->AltBody = strip_tags($tempBody);
     // strip_tags is used because subject lines NEVER include HTML tags, according to official specification:
     $notify_mail->Subject = strip_tags(from_html($xtpl->text($template_name . "_Subject")));
     // cn: bug 8568 encode notify email in User's outbound email encoding
     $notify_mail->prepForOutbound();
     return $notify_mail;
 }