Esempio n. 1
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");
     $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;
 }
Esempio n. 2
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;
 }