Пример #1
0
/**
 * Custom parse template method since sugars own doesn't deal with custom fields.
 */
function aop_parse_template($string, &$bean_arr)
{
    global $beanFiles, $beanList;
    $typeMap = array('dynamicenum' => 'enum');
    foreach ($bean_arr as $bean_name => $bean_id) {
        require_once $beanFiles[$beanList[$bean_name]];
        $focus = new $beanList[$bean_name]();
        $result = $focus->retrieve($bean_id);
        if ($bean_name == 'Leads' || $bean_name == 'Prospects') {
            $bean_name = 'Contacts';
        }
        foreach ($focus->field_defs as $key => $field_def) {
            if (array_key_exists($field_def['type'], $typeMap)) {
                $focus->field_defs[$key]['type'] = $typeMap[$field_def['type']];
            }
        }
        if (isset($this) && isset($this->module_dir) && $this->module_dir == 'EmailTemplates') {
            $string = $this->parse_template_bean($string, $bean_name, $focus);
        } else {
            $string = EmailTemplate::parse_template_bean($string, $bean_name, $focus);
        }
    }
    return $string;
}
Пример #2
0
 public function action_sendinvitemails()
 {
     global $db;
     global $sugar_config;
     global $mod_strings;
     $id = $_GET['record'];
     //get event
     $event = new FP_events();
     $event->retrieve($id);
     $event->load_relationship('fp_events_contacts');
     // get related contacts
     $event->load_relationship('fp_events_prospects_1');
     //get related targets
     $event->load_relationship('fp_events_leads_1');
     //get related leads
     //Count the number of delegates linked to the event that have not yet been invited
     $query = "SELECT * FROM fp_events_contacts_c WHERE fp_events_contactsfp_events_ida='" . $event->id . "' AND (invite_status='Not Invited' OR invite_status='' OR invite_status IS NULL) AND deleted='0'";
     $result = $db->query($query);
     $contact_count = $db->getRowCount($result);
     //count contacts
     $query = "SELECT * FROM fp_events_prospects_1_c WHERE fp_events_prospects_1fp_events_ida='" . $event->id . "' AND (invite_status='Not Invited' OR invite_status='' OR invite_status IS NULL) AND deleted='0'";
     $result = $db->query($query);
     $prospect_count = $db->getRowCount($result);
     //count targets
     $query = "SELECT * FROM fp_events_leads_1_c WHERE fp_events_leads_1fp_events_ida='" . $event->id . "' AND (invite_status='Not Invited' OR invite_status='' OR invite_status IS NULL) AND deleted='0'";
     $result = $db->query($query);
     $lead_count = $db->getRowCount($result);
     //count leads
     $delegate_count = $contact_count + $prospect_count + $lead_count;
     //Total up delegates
     $invite_count = 0;
     //used to count the number of emails sent
     $error_count = 0;
     //used to count the number of failed email attempts
     //loop through related contacts
     foreach ($event->fp_events_contacts->getBeans() as $contact) {
         //Get accept status of contact
         $query = 'SELECT invite_status FROM fp_events_contacts_c WHERE fp_events_contactsfp_events_ida="' . $event->id . '" AND fp_events_contactscontacts_idb="' . $contact->id . '"';
         $status = $db->getOne($query);
         if ($status == null || $status == '' || $status == 'Not Invited') {
             $invite_count++;
             //set email links
             $event->link = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $contact->id . "&type=c&response=accept'>Accept</a>";
             $event->link_declined = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $contact->id . "&type=c&response=decline'>Decline</a>";
             //Get the TO name and e-mail address for the message
             $rcpt_name = $contact->first_name . ' ' . $contact->last_name;
             $rcpt_email = $contact->email1;
             $emailTemp = new EmailTemplate();
             $emailTemp->disable_row_level_security = true;
             $emailTemp->retrieve($event->invite_templates);
             //Use the ID value of the email template record
             //check email template is set, if not return error
             if ($emailTemp->id == '') {
                 SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_5']);
                 SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id);
                 die;
             }
             //parse the lead varibales first
             $firstpass = $emailTemp->parse_template_bean($emailTemp->body_html, 'Contacts', $contact);
             $email_subject = $emailTemp->parse_template_bean($emailTemp->subject, 'FP_events', $event);
             $email_body = from_html($emailTemp->parse_template_bean($firstpass, 'FP_events', $event));
             $alt_emailbody = wordwrap($emailTemp->parse_template_bean($firstpass, 'FP_events', $event), 900);
             //get attachments
             $attachmentBean = new Note();
             $attachment_list = $attachmentBean->get_full_list('', "parent_type = 'Emails' AND parent_id = '" . $event->invite_templates . "'");
             $attachments = array();
             if ($attachment_list != null) {
                 foreach ($attachment_list as $attachment) {
                     $attachments[] = $attachment;
                 }
             }
             //send the email
             $send_invite = $this->sendEmail($rcpt_email, $email_subject, $rcpt_name, $email_body, $alt_emailbody, $contact, $attachments);
             //Send the message, log if error occurs
             if (!$send_invite) {
                 $GLOBALS['log']->fatal('ERROR: Invite email failed to send to: ' . $rcpt_name . ' at ' . $rcpt_email);
                 $error_count++;
             } else {
                 //update contact to invites
                 $query = 'UPDATE fp_events_contacts_c SET invite_status="Invited" WHERE fp_events_contactsfp_events_ida="' . $event->id . '" AND fp_events_contactscontacts_idb="' . $contact->id . '"';
                 $res = $db->query($query);
             }
         }
     }
     //loop through related targets
     foreach ($event->fp_events_prospects_1->getBeans() as $target) {
         //Get accept status of contact
         $query = 'SELECT invite_status FROM fp_events_prospects_1_c WHERE fp_events_prospects_1fp_events_ida="' . $event->id . '" AND fp_events_prospects_1prospects_idb="' . $target->id . '"';
         $status = $db->getOne($query);
         if ($status == null || $status == '' || $status == 'Not Invited') {
             $invite_count++;
             //set email links
             $event->link = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $target->id . "&type=t&response=accept'>Accept</a>";
             $event->link_declined = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $target->id . "&type=t&response=decline'>Decline</a>";
             //Get the TO name and e-mail address for the message
             $rcpt_name = $target->first_name . ' ' . $target->last_name;
             $rcpt_email = $target->email1;
             $emailTemp = new EmailTemplate();
             $emailTemp->disable_row_level_security = true;
             $emailTemp->retrieve($event->invite_templates);
             //Use the ID value of the email template record
             //parse the lead varibales first
             $firstpass = $emailTemp->parse_template_bean($emailTemp->body_html, 'Contacts', $target);
             $email_subject = $emailTemp->parse_template_bean($emailTemp->subject, 'FP_events', $event);
             $email_body = from_html($emailTemp->parse_template_bean($firstpass, 'FP_events', $event));
             $alt_emailbody = wordwrap($emailTemp->parse_template_bean($firstpass, 'FP_events', $event), 900);
             //get attachments
             $attachmentBean = new Note();
             $attachment_list = $attachmentBean->get_full_list('', "parent_type = 'Emails' AND parent_id = '" . $event->invite_templates . "'");
             $attachments = array();
             if ($attachment_list != null) {
                 foreach ($attachment_list as $attachment) {
                     $attachments[] = $attachment;
                 }
             }
             //send the email
             $send_invite = $this->sendEmail($rcpt_email, $email_subject, $rcpt_name, $email_body, $alt_emailbody, $target, $attachments);
             //Send the message, log if error occurs
             if (!$send_invite) {
                 $GLOBALS['log']->fatal('ERROR: Invite email failed to send to: ' . $rcpt_name . ' at ' . $rcpt_email);
                 $error_count++;
             } else {
                 //update contact to invites
                 $query = 'UPDATE fp_events_prospects_1_c SET invite_status="Invited" WHERE fp_events_prospects_1fp_events_ida="' . $event->id . '" AND fp_events_prospects_1prospects_idb="' . $target->id . '"';
                 $res = $db->query($query);
             }
         }
     }
     //loop through related leads
     foreach ($event->fp_events_leads_1->getBeans() as $lead) {
         //Get accept status of contact
         $query = 'SELECT invite_status FROM fp_events_leads_1_c WHERE fp_events_leads_1fp_events_ida="' . $event->id . '" AND fp_events_leads_1leads_idb="' . $lead->id . '"';
         $status = $db->getOne($query);
         if ($status == null || $status == '' || $status == 'Not Invited') {
             $invite_count++;
             //set email links
             $event->link = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $lead->id . "&type=l&response=accept'>Accept</a>";
             $event->link_declined = "<a href='" . $sugar_config['site_url'] . "/index.php?entryPoint=responseEntryPoint&event=" . $event->id . "&delegate=" . $lead->id . "&type=l&response=decline'>Decline</a>";
             //Get the TO name and e-mail address for the message
             $rcpt_name = $lead->first_name . ' ' . $lead->last_name;
             $rcpt_email = $lead->email1;
             $emailTemp = new EmailTemplate();
             $emailTemp->disable_row_level_security = true;
             $emailTemp->retrieve($event->invite_templates);
             //Use the ID value of the email template record
             //parse the lead varibales first
             $firstpass = $emailTemp->parse_template_bean($emailTemp->body_html, 'Contacts', $lead);
             $email_subject = $emailTemp->parse_template_bean($emailTemp->subject, 'FP_events', $event);
             $email_body = from_html($emailTemp->parse_template_bean($firstpass, 'FP_events', $event));
             $alt_emailbody = wordwrap($emailTemp->parse_template_bean($firstpass, 'FP_events', $event), 900);
             //get attachments
             $attachmentBean = new Note();
             $attachment_list = $attachmentBean->get_full_list('', "parent_type = 'Emails' AND parent_id = '" . $event->invite_templates . "'");
             $attachments = array();
             if ($attachment_list != null) {
                 foreach ($attachment_list as $attachment) {
                     $attachments[] = $attachment;
                 }
             }
             //send the email
             $send_invite = $this->sendEmail($rcpt_email, $email_subject, $rcpt_name, $email_body, $alt_emailbody, $lead, $attachments);
             //Send the message, log if error occurs
             if (!$send_invite) {
                 $GLOBALS['log']->fatal('ERROR: Invite email failed to send to: ' . $rcpt_name . ' at ' . $rcpt_email);
                 $error_count++;
             } else {
                 //update contact to invites
                 $query = 'UPDATE fp_events_leads_1_c SET invite_status="Invited" WHERE fp_events_leads_1fp_events_ida="' . $event->id . '" AND fp_events_leads_1leads_idb="' . $lead->id . '"';
                 $res = $db->query($query);
             }
         }
     }
     //Redirect with error message if all linked contacts have already been invited
     if ($invite_count == 0) {
         SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_1']);
         SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id);
     }
     //Redirect if all emails fail to send
     if ($error_count == $delegate_count) {
         $_SESSION['user_error_message'] = array();
         //clear the error message array
         SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_2'] . $delegate_count);
         SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id);
     } else {
         if ($error_count > 0 && $error_count <= 10) {
             //redirect with failed email count.
             $_SESSION['user_error_message'] = array();
             SugarApplication::appendErrorMessage($error_count . $mod_strings['LBL_ERROR_MSG_4']);
             SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id);
         } else {
             if ($error_count > 10) {
                 $_SESSION['user_error_message'] = array();
                 SugarApplication::appendErrorMessage($mod_strings['LBL_ERROR_MSG_3']);
                 SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id);
             } else {
                 SugarApplication::appendErrorMessage($mod_strings['LBL_SUCCESS_MSG']);
                 SugarApplication::redirect("index.php?module=FP_events&return_module=FP_events&action=DetailView&record=" . $event->id);
             }
         }
     }
 }
Пример #3
0
 function parse_template($string, &$bean_arr)
 {
     global $beanFiles, $beanList;
     foreach ($bean_arr as $bean_name => $bean_id) {
         require_once $beanFiles[$beanList[$bean_name]];
         $focus = new $beanList[$bean_name]();
         $result = $focus->retrieve($bean_id);
         if ($bean_name == 'Leads' || $bean_name == 'Prospects') {
             $bean_name = 'Contacts';
         }
         if (isset($this) && isset($this->module_dir) && $this->module_dir == 'EmailTemplates') {
             $string = $this->parse_template_bean($string, $bean_name, $focus);
         } else {
             $string = EmailTemplate::parse_template_bean($string, $bean_name, $focus);
         }
     }
     return $string;
 }
Пример #4
0
 public function testparse_template_bean()
 {
     $emailTemplate = new EmailTemplate();
     $contact = new Contact();
     $user = new User(1);
     $account = new Account();
     $contact->name = 'test';
     $account->name = 'test';
     //test with empty string
     $actual = $emailTemplate->parse_template_bean('', 'Contacts', $contact);
     $this->assertEquals('', $actual);
     //test with valid string
     $actual = $emailTemplate->parse_template_bean('test', 'Users', $user);
     $this->assertEquals('test', $actual);
     //test with empty string and different module
     $actual = $emailTemplate->parse_template_bean('', 'Accounts', $account);
     $this->assertEquals('', $actual);
 }
Пример #5
0
 function parse_template($string, $bean_arr)
 {
     global $beanFiles, $beanList;
     foreach ($bean_arr as $bean_name => $bean_id) {
         $focus = BeanFactory::getBean($bean_name, $bean_id);
         if ($bean_name == 'Leads' || $bean_name == 'Prospects') {
             $bean_name = 'Contacts';
         }
         if (isset($this) && isset($this->module_dir) && $this->module_dir == 'EmailTemplates') {
             $string = $this->parse_template_bean($string, $bean_name, $focus);
         } else {
             $string = EmailTemplate::parse_template_bean($string, $bean_name, $focus);
         }
     }
     return $string;
 }