コード例 #1
0
 static function parse_template($string, $bean_arr)
 {
     global $beanList;
     $person = array();
     foreach ($bean_arr as $bean_name => $bean_id) {
         $focus = BeanFactory::getBean($bean_name, $bean_id);
         $string = aowTemplateParser::parse_template_bean($string, strtolower($beanList[$bean_name]), $focus);
         if ($focus instanceof Person) {
             $person[] = $focus;
         }
     }
     if (!empty($person)) {
         $focus = $person[0];
     } else {
         $focus = new Contact();
     }
     $string = aowTemplateParser::parse_template_bean($string, 'contact', $focus);
     return $string;
 }
コード例 #2
0
 function parse_template(SugarBean $bean, &$template, $object_override = array())
 {
     global $sugar_config;
     require_once 'modules/AOW_Actions/actions/templateParser.php';
     $object_arr[$bean->module_dir] = $bean->id;
     foreach ($bean->field_defs as $bean_arr) {
         if ($bean_arr['type'] == 'relate') {
             if (isset($bean_arr['module']) && $bean_arr['module'] != '' && isset($bean_arr['id_name']) && $bean_arr['id_name'] != '' && $bean_arr['module'] != 'EmailAddress') {
                 $idName = $bean_arr['id_name'];
                 if (isset($bean->field_defs[$idName]) && $bean->field_defs[$idName]['source'] != 'non-db') {
                     if (!isset($object_arr[$bean_arr['module']])) {
                         $object_arr[$bean_arr['module']] = $bean->{$idName};
                     }
                 }
             }
         } else {
             if ($bean_arr['type'] == 'link') {
                 if (!isset($bean_arr['module']) || $bean_arr['module'] == '') {
                     $bean_arr['module'] = getRelatedModule($bean->module_dir, $bean_arr['name']);
                 }
                 if (isset($bean_arr['module']) && $bean_arr['module'] != '' && !isset($object_arr[$bean_arr['module']]) && $bean_arr['module'] != 'EmailAddress') {
                     $linkedBeans = $bean->get_linked_beans($bean_arr['name'], $bean_arr['module'], array(), 0, 1);
                     if ($linkedBeans) {
                         $linkedBean = $linkedBeans[0];
                         if (!isset($object_arr[$linkedBean->module_dir])) {
                             $object_arr[$linkedBean->module_dir] = $linkedBean->id;
                         }
                     }
                 }
             }
         }
     }
     $object_arr['Users'] = is_a($bean, 'User') ? $bean->id : $bean->assigned_user_id;
     $object_arr = array_merge($object_arr, $object_override);
     $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}";
     $url = $cleanUrl . "/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}";
     $template->subject = str_replace("\$contact_user", "\$user", $template->subject);
     $template->body_html = str_replace("\$contact_user", "\$user", $template->body_html);
     $template->body = str_replace("\$contact_user", "\$user", $template->body);
     $template->subject = aowTemplateParser::parse_template($template->subject, $object_arr);
     $template->body_html = aowTemplateParser::parse_template($template->body_html, $object_arr);
     $template->body_html = str_replace("\$url", $url, $template->body_html);
     $template->body = aowTemplateParser::parse_template($template->body, $object_arr);
     $template->body = str_replace("\$url", $url, $template->body);
 }
コード例 #3
0
 function run_action(SugarBean $bean, $params = array(), $in_save = false)
 {
     global $sugar_config, $beanList;
     include_once 'modules/EmailTemplates/EmailTemplate.php';
     require_once 'modules/AOW_Actions/actions/templateParser.php';
     $emailTemp = new EmailTemplate();
     $emailTemp->retrieve($params['email_template']);
     if ($emailTemp->id == '') {
         return false;
     }
     $object_arr[$bean->module_dir] = $bean->id;
     foreach ($bean->field_defs as $bean_arr) {
         if ($bean_arr['type'] == 'relate') {
             if (isset($bean_arr['module']) && $bean_arr['module'] != '' && isset($bean_arr['id_name']) && $bean_arr['id_name'] != '' && $bean_arr['module'] != 'EmailAddress') {
                 $relate_bean = new $beanList[$bean_arr['module']]();
                 if (!isset($object_arr[$relate_bean->module_dir])) {
                     $object_arr[$relate_bean->module_dir] = $bean->{$bean_arr}['id_name'];
                 }
             }
         } else {
             if ($bean_arr['type'] == 'link') {
                 if (!isset($bean_arr['module']) || $bean_arr['module'] == '') {
                     $bean_arr['module'] = getRelatedModule($bean->module_dir, $bean_arr['name']);
                 }
                 if (isset($bean_arr['module']) && $bean_arr['module'] != '' && !isset($object_arr[$bean_arr['module']]) && $bean_arr['module'] != 'EmailAddress') {
                     $linkedBeans = $bean->get_linked_beans($bean_arr['name'], $bean_arr['module']);
                     if ($linkedBeans) {
                         $linkedBean = $linkedBeans[0];
                         if (!isset($object_arr[$linkedBean->module_dir])) {
                             $object_arr[$linkedBean->module_dir] = $linkedBean->id;
                         }
                     }
                 }
             }
         }
     }
     $object_arr['Users'] = $bean->assigned_user_id;
     $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}";
     $url = $cleanUrl . "/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}";
     $subject = str_replace("\$contact_user", "\$user", $emailTemp->subject);
     $body_html = str_replace("\$contact_user", "\$user", $emailTemp->body_html);
     $body_plain = str_replace("\$contact_user", "\$user", $emailTemp->body);
     $subject = aowTemplateParser::parse_template($subject, $object_arr);
     $body_html = aowTemplateParser::parse_template($body_html, $object_arr);
     $body_html = str_replace("\$url", $url, $body_html);
     $body_plain = aowTemplateParser::parse_template($body_plain, $object_arr);
     $body_plain = str_replace("\$url", $url, $body_plain);
     $emails = $this->getEmailsFromParams($bean, $params);
     return $this->sendEmail($emails['to'], $subject, $body_html, $body_plain, $bean, $emails['cc'], $emails['bcc']);
 }
コード例 #4
0
ファイル: templateParser.php プロジェクト: MexinaD/SuiteCRM
 static function parse_template($string, &$bean_arr)
 {
     global $beanFiles, $beanList;
     $person = array();
     foreach ($bean_arr as $bean_name => $bean_id) {
         require_once $beanFiles[$beanList[$bean_name]];
         $focus = new $beanList[$bean_name]();
         $focus->retrieve($bean_id);
         $string = aowTemplateParser::parse_template_bean($string, strtolower($beanList[$bean_name]), $focus);
         if ($focus instanceof Person) {
             $person[] = $focus;
         }
     }
     if (!empty($person)) {
         $focus = $person[0];
     } else {
         $focus = new Contact();
     }
     $string = aowTemplateParser::parse_template_bean($string, 'contact', $focus);
     return $string;
 }