本文整理汇总了PHP中CRM_Core_BAO_MessageTemplate::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_MessageTemplate::add方法的具体用法?PHP CRM_Core_BAO_MessageTemplate::add怎么用?PHP CRM_Core_BAO_MessageTemplate::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_MessageTemplate
的用法示例。
在下文中一共展示了CRM_Core_BAO_MessageTemplate::add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* Process the form after the input has been submitted and validated.
*
*
* @param CRM_Core_Form $form
*
* @return void
*/
public static function postProcess(&$form)
{
// check and ensure that
$thisValues = $form->controller->exportValues($form->getName());
$fromSmsProviderId = $thisValues['sms_provider_id'];
// process message template
if (!empty($thisValues['saveTemplate']) || !empty($thisValues['updateTemplate'])) {
$messageTemplate = array('msg_text' => $thisValues['sms_text_message'], 'is_active' => TRUE);
if (!empty($thisValues['saveTemplate'])) {
$messageTemplate['msg_title'] = $thisValues['saveTemplateName'];
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
if (!empty($thisValues['template']) && !empty($thisValues['updateTemplate'])) {
$messageTemplate['id'] = $thisValues['template'];
unset($messageTemplate['msg_title']);
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
}
// format contact details array to handle multiple sms from same contact
$formattedContactDetails = array();
$tempPhones = array();
foreach ($form->_contactIds as $key => $contactId) {
$phone = $form->_toContactPhone[$key];
if ($phone) {
$phoneKey = "{$contactId}::{$phone}";
if (!in_array($phoneKey, $tempPhones)) {
$tempPhones[] = $phoneKey;
if (!empty($form->_contactDetails[$contactId])) {
$formattedContactDetails[] = $form->_contactDetails[$contactId];
}
}
}
}
// $smsParams carries all the arguments provided on form (or via hooks), to the provider->send() method
// this gives flexibity to the users / implementors to add their own args via hooks specific to their sms providers
$smsParams = $thisValues;
unset($smsParams['sms_text_message']);
$smsParams['provider_id'] = $fromSmsProviderId;
$contactIds = array_keys($form->_contactDetails);
$allContactIds = array_keys($form->_allContactDetails);
list($sent, $activityId, $countSuccess) = CRM_Activity_BAO_Activity::sendSMS($formattedContactDetails, $thisValues, $smsParams, $contactIds);
if ($countSuccess > 0) {
CRM_Core_Session::setStatus(ts('One message was sent successfully.', array('plural' => '%count messages were sent successfully.', 'count' => $countSuccess)), ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $countSuccess)), 'success');
}
if (is_array($sent)) {
// At least one PEAR_Error object was generated.
// Display the error messages to the user.
$status = '<ul>';
foreach ($sent as $errMsg) {
$status .= '<li>' . $errMsg . '</li>';
}
$status .= '</ul>';
CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($sent), 'plural' => '%count Messages Not Sent')), 'info');
} else {
//Display the name and number of contacts for those sms is not sent.
$smsNotSent = array_diff_assoc($allContactIds, $contactIds);
if (!empty($smsNotSent)) {
$not_sent = array();
foreach ($smsNotSent as $index => $contactId) {
$displayName = $form->_allContactDetails[$contactId]['display_name'];
$phone = $form->_allContactDetails[$contactId]['phone'];
$contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}");
$not_sent[] = "<a href='{$contactViewUrl}' title='{$phone}'>{$displayName}</a>";
}
$status = '(' . ts('because no phone number on file or communication preferences specify DO NOT SMS or Contact is deceased');
if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
$status .= ' ' . ts("or the contact is not part of the activity '%1'", array(1 => self::RECIEVED_SMS_ACTIVITY_SUBJECT));
}
$status .= ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>';
CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($smsNotSent), 'plural' => '%count Messages Not Sent')), 'info');
}
}
}
示例2: postProcess
/**
* Function to process the form
*
* @access public
*
* @return void
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
// delete reminder
CRM_Core_BAO_ActionSchedule::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
return;
}
$values = $this->controller->exportValues($this->getName());
$keys = array('title', 'subject', 'absolute_date', 'group_id', 'record_activity', 'limit_to');
foreach ($keys as $key) {
$params[$key] = CRM_Utils_Array::value($key, $values);
}
$moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date');
if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) {
$params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate);
foreach ($moreKeys as $mkey) {
$params[$mkey] = 'null';
}
} else {
$params['absolute_date'] = 'null';
foreach ($moreKeys as $mkey) {
$params[$mkey] = CRM_Utils_Array::value($mkey, $values);
}
}
$params['body_text'] = CRM_Utils_Array::value('text_message', $values);
$params['body_html'] = CRM_Utils_Array::value('html_message', $values);
if (CRM_Utils_Array::value('recipient', $values) == 'manual') {
$params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values);
$params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
} elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
$params['group_id'] = $values['group_id'];
$params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
} elseif (!CRM_Utils_System::isNull($values['recipient_listing'])) {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values));
$params['group_id'] = $params['recipient_manual'] = 'null';
} else {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
}
$params['mapping_id'] = $this->_mappingID;
$params['entity_value'] = $this->_id;
$params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $values['entity']);
$params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
$params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0);
if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
$params['repetition_frequency_unit'] = 'null';
$params['repetition_frequency_interval'] = 'null';
$params['end_frequency_unit'] = 'null';
$params['end_frequency_interval'] = 'null';
$params['end_action'] = 'null';
$params['end_date'] = 'null';
}
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
$composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
$msgTemplate = NULL;
//mail template is composed
$composeParams = array();
foreach ($composeFields as $key) {
if (!empty($values[$key])) {
$composeParams[$key] = $values[$key];
}
}
if (!empty($composeParams['updateTemplate'])) {
$templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
$templateParams['id'] = $values['template'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (!empty($composeParams['saveTemplate'])) {
$templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
$templateParams['msg_title'] = $composeParams['saveTemplateName'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (isset($msgTemplate->id)) {
$params['msg_template_id'] = $msgTemplate->id;
} else {
$params['msg_template_id'] = CRM_Utils_Array::value('template', $values);
}
CRM_Core_BAO_ActionSchedule::add($params, $ids);
$status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>"));
CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
parent::endPostProcess();
}
示例3: parseActionSchedule
//.........这里部分代码省略.........
} elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
$params['group_id'] = $values['group_id'];
$params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
} elseif (isset($values['recipient_listing']) && isset($values['limit_to']) && !CRM_Utils_System::isNull($values['recipient_listing']) && !CRM_Utils_System::isNull($values['limit_to'])) {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values));
$params['group_id'] = $params['recipient_manual'] = 'null';
} else {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
}
if (!empty($this->_mappingID) && !empty($this->_compId)) {
$params['mapping_id'] = $this->_mappingID;
$params['entity_value'] = $this->_compId;
$params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $values['entity']);
} else {
$params['mapping_id'] = $values['entity'][0];
if ($params['mapping_id'] == 1) {
$params['limit_to'] = 1;
}
$entity_value = CRM_Utils_Array::value(1, $values['entity'], array());
$entity_status = CRM_Utils_Array::value(2, $values['entity'], array());
$params['entity_value'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $entity_value);
$params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $entity_status);
}
$params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
$params['repetition_frequency_unit'] = 'null';
$params['repetition_frequency_interval'] = 'null';
$params['end_frequency_unit'] = 'null';
$params['end_frequency_interval'] = 'null';
$params['end_action'] = 'null';
$params['end_date'] = 'null';
}
// multilingual options
$params['filter_contact_language'] = CRM_Utils_Array::value('filter_contact_language', $values, array());
$params['filter_contact_language'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['filter_contact_language']);
$params['communication_language'] = CRM_Utils_Array::value('communication_language', $values, NULL);
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
} elseif ($this->_action & CRM_Core_Action::ADD) {
// we do this only once, so name never changes
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
}
$modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS');
if ($params['mode'] == 'Email' || empty($params['sms_provider_id'])) {
unset($modePrefixes['SMS']);
} elseif ($params['mode'] == 'SMS') {
unset($modePrefixes['Mail']);
}
//TODO: handle postprocessing of SMS and/or Email info based on $modePrefixes
$composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
$msgTemplate = NULL;
//mail template is composed
foreach ($modePrefixes as $prefix) {
$composeParams = array();
foreach ($composeFields as $key) {
$key = $prefix . $key;
if (!empty($values[$key])) {
$composeParams[$key] = $values[$key];
}
}
if (!empty($composeParams[$prefix . 'updateTemplate'])) {
$templateParams = array('is_active' => TRUE);
if ($prefix == 'SMS') {
$templateParams += array('msg_text' => $params['sms_body_text'], 'is_sms' => TRUE);
} else {
$templateParams += array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject']);
}
$templateParams['id'] = $values[$prefix . 'template'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (!empty($composeParams[$prefix . 'saveTemplate'])) {
$templateParams = array('is_active' => TRUE);
if ($prefix == 'SMS') {
$templateParams += array('msg_text' => $params['sms_body_text'], 'is_sms' => TRUE);
} else {
$templateParams += array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject']);
}
$templateParams['msg_title'] = $composeParams[$prefix . 'saveTemplateName'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if ($prefix == 'SMS') {
if (isset($msgTemplate->id)) {
$params['sms_template_id'] = $msgTemplate->id;
} else {
$params['sms_template_id'] = CRM_Utils_Array::value('SMStemplate', $values);
}
} else {
if (isset($msgTemplate->id)) {
$params['msg_template_id'] = $msgTemplate->id;
} else {
$params['msg_template_id'] = CRM_Utils_Array::value('template', $values);
}
}
}
$actionSchedule = new CRM_Core_DAO_ActionSchedule();
$actionSchedule->copyValues($params);
return $actionSchedule;
}
示例4: postProcess
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_MessageTemplate::del($this->_id);
} elseif ($this->_action & CRM_Core_Action::VIEW) {
// currently, the above action is used solely for previewing default workflow templates
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
} else {
$params = array();
// store the submitted values in an array
$params = $this->exportValues();
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
}
if ($this->_workflow_id) {
$params['workflow_id'] = $this->_workflow_id;
$params['is_active'] = TRUE;
}
$messageTemplate = CRM_Core_BAO_MessageTemplate::add($params);
CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title)), ts('Saved'), 'success');
if ($this->_workflow_id) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
} else {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
}
}
}
示例5: postProcess
public function postProcess()
{
$params = $ids = array();
$uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email');
$fileType = array('textFile', 'htmlFile');
$formValues = $this->controller->exportValues($this->_name);
foreach ($uploadParams as $key) {
if (!empty($formValues[$key]) || in_array($key, array('header_id', 'footer_id'))) {
$params[$key] = $formValues[$key];
$this->set($key, $formValues[$key]);
}
}
if (!$formValues['upload_type']) {
foreach ($fileType as $key) {
$contents = NULL;
if (isset($formValues[$key]) && !empty($formValues[$key])) {
$contents = file_get_contents($formValues[$key]['name']);
$this->set($key, $formValues[$key]['name']);
}
if ($contents) {
$params['body_' . substr($key, 0, 4)] = $contents;
} else {
$params['body_' . substr($key, 0, 4)] = 'NULL';
}
}
} else {
$text_message = $formValues['text_message'];
$params['body_text'] = $text_message;
$this->set('textFile', $params['body_text']);
$this->set('text_message', $params['body_text']);
$html_message = $formValues['html_message'];
// dojo editor does some html conversion when tokens are
// inserted as links. Hence token replacement fails.
// this is hack to revert html conversion for { to %7B and
// } to %7D by dojo editor
$html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
$params['body_html'] = $html_message;
$this->set('htmlFile', $params['body_html']);
$this->set('html_message', $params['body_html']);
}
$params['name'] = $this->get('name');
$session = CRM_Core_Session::singleton();
$params['contact_id'] = $session->get('userID');
$composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
$msgTemplate = NULL;
//mail template is composed
if ($formValues['upload_type']) {
$composeParams = array();
foreach ($composeFields as $key) {
if (!empty($formValues[$key])) {
$composeParams[$key] = $formValues[$key];
$this->set($key, $formValues[$key]);
}
}
if (!empty($composeParams['updateTemplate'])) {
$templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => TRUE);
$templateParams['id'] = $formValues['template'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (!empty($composeParams['saveTemplate'])) {
$templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => TRUE);
$templateParams['msg_title'] = $composeParams['saveTemplateName'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (isset($msgTemplate->id)) {
$params['msg_template_id'] = $msgTemplate->id;
} else {
$params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
}
$this->set('template', $params['msg_template_id']);
}
CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->_mailingID);
$ids['mailing_id'] = $this->_mailingID;
//handle mailing from name & address.
$fromEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_OptionGroup::values('from_email_address'));
//get the from email address
$params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($fromEmailAddress);
//get the from Name
$params['from_name'] = CRM_Utils_Array::value(1, explode('"', $fromEmailAddress));
//Add Reply-To to headers
if (!empty($formValues['reply_to_address'])) {
$replyToEmail = CRM_Core_OptionGroup::values('from_email_address');
$params['replyto_email'] = CRM_Utils_Array::value($formValues['reply_to_address'], $replyToEmail);
}
/* Build the mailing object */
CRM_Mailing_BAO_Mailing::create($params, $ids);
if (isset($this->_submitValues['_qf_Upload_upload_save']) && $this->_submitValues['_qf_Upload_upload_save'] == 'Save & Continue Later') {
//when user perform mailing from search context
//redirect it to search result CRM-3711.
$ssID = $this->get('ssID');
if ($ssID && $this->_searchBasedMailing) {
if ($this->_action == CRM_Core_Action::BASIC) {
$fragment = 'search';
} elseif ($this->_action == CRM_Core_Action::PROFILE) {
$fragment = 'search/builder';
} elseif ($this->_action == CRM_Core_Action::ADVANCED) {
$fragment = 'search/advanced';
} else {
$fragment = 'search/custom';
}
//.........这里部分代码省略.........
示例6: postProcess
/**
* Function to process the form
*
* @access public
*
* @return void
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
// delete reminder
CRM_Core_BAO_ActionSchedule::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
if ($this->_context == 'event' && $this->_eventId) {
$url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=update&id={$this->_eventId}");
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
return;
}
$values = $this->controller->exportValues($this->getName());
$keys = array('title', 'subject', 'absolute_date', 'group_id', 'record_activity', 'limit_to', 'mode', 'sms_provider_id', 'from_name', 'from_email');
foreach ($keys as $key) {
$params[$key] = CRM_Utils_Array::value($key, $values);
}
$moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date');
if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) {
$params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate);
foreach ($moreKeys as $mkey) {
$params[$mkey] = 'null';
}
} else {
$params['absolute_date'] = 'null';
foreach ($moreKeys as $mkey) {
$params[$mkey] = CRM_Utils_Array::value($mkey, $values);
}
}
$params['body_text'] = CRM_Utils_Array::value('text_message', $values);
$params['body_html'] = CRM_Utils_Array::value('html_message', $values);
if (CRM_Utils_Array::value('recipient', $values) == 'manual') {
$params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values);
$params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
} elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
$params['group_id'] = $values['group_id'];
$params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
} elseif (!CRM_Utils_System::isNull($values['recipient_listing'])) {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values));
$params['group_id'] = $params['recipient_manual'] = 'null';
} else {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
}
$params['mapping_id'] = $values['entity'][0];
$entity_value = $values['entity'][1];
$entity_status = $values['entity'][2];
foreach (array('entity_value', 'entity_status') as $key) {
$params[$key] = implode(CRM_Core_DAO::VALUE_SEPARATOR, ${$key});
}
$params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
$params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0);
if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
$params['repetition_frequency_unit'] = 'null';
$params['repetition_frequency_interval'] = 'null';
$params['end_frequency_unit'] = 'null';
$params['end_frequency_interval'] = 'null';
$params['end_action'] = 'null';
$params['end_date'] = 'null';
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
} elseif ($this->_action & CRM_Core_Action::ADD) {
// we do this only once, so name never changes
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
}
$composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
$msgTemplate = NULL;
//mail template is composed
$composeParams = array();
foreach ($composeFields as $key) {
if (!empty($values[$key])) {
$composeParams[$key] = $values[$key];
}
}
if (!empty($composeParams['updateTemplate'])) {
$templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
$templateParams['id'] = $values['template'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (!empty($composeParams['saveTemplate'])) {
$templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE);
$templateParams['msg_title'] = $composeParams['saveTemplateName'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (isset($msgTemplate->id)) {
$params['msg_template_id'] = $msgTemplate->id;
} else {
$params['msg_template_id'] = CRM_Utils_Array::value('template', $values);
}
$bao = CRM_Core_BAO_ActionSchedule::add($params);
//.........这里部分代码省略.........
示例7: postProcess
/**
* Process the form after the input has been submitted and validated.
*
* @param CRM_Core_Form $form
*/
public static function postProcess(&$form)
{
if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) {
CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => self::MAX_EMAILS_KILL_SWITCH)));
}
// check and ensure that
$formValues = $form->controller->exportValues($form->getName());
$fromEmail = $formValues['fromEmailAddress'];
$from = CRM_Utils_Array::value($fromEmail, $form->_emails);
$subject = $formValues['subject'];
// CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields
$elements = array('cc_id', 'bcc_id');
$additionalDetails = NULL;
$ccValues = $bccValues = array();
foreach ($elements as $element) {
if (!empty($formValues[$element])) {
$allEmails = explode(',', $formValues[$element]);
foreach ($allEmails as $value) {
list($contactId, $email) = explode('::', $value);
$contactURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}", TRUE);
switch ($element) {
case 'cc_id':
$ccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
$ccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
break;
case 'bcc_id':
$bccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
$bccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
break;
}
}
}
}
$cc = $bcc = '';
if (!empty($ccValues)) {
$cc = implode(',', $ccValues['email']);
$additionalDetails .= "\ncc : " . implode(", ", $ccValues['details']);
}
if (!empty($bccValues)) {
$bcc = implode(',', $bccValues['email']);
$additionalDetails .= "\nbcc : " . implode(", ", $bccValues['details']);
}
// CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects
if (isset($form->_caseId) && is_numeric($form->_caseId)) {
$hash = substr(sha1(CIVICRM_SITE_KEY . $form->_caseId), 0, 7);
$subject = "[case #{$hash}] {$subject}";
}
// process message template
if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
$messageTemplate = array('msg_text' => $formValues['text_message'], 'msg_html' => $formValues['html_message'], 'msg_subject' => $formValues['subject'], 'is_active' => TRUE);
if (!empty($formValues['saveTemplate'])) {
$messageTemplate['msg_title'] = $formValues['saveTemplateName'];
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
if (!empty($formValues['template']) && !empty($formValues['updateTemplate'])) {
$messageTemplate['id'] = $formValues['template'];
unset($messageTemplate['msg_title']);
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
}
$attachments = array();
CRM_Core_BAO_File::formatAttachment($formValues, $attachments, NULL, NULL);
// format contact details array to handle multiple emails from same contact
$formattedContactDetails = array();
$tempEmails = array();
foreach ($form->_contactIds as $key => $contactId) {
// if we dont have details on this contactID, we should ignore
// potentially this is due to the contact not wanting to receive email
if (!isset($form->_contactDetails[$contactId])) {
continue;
}
$email = $form->_toContactEmails[$key];
// prevent duplicate emails if same email address is selected CRM-4067
// we should allow same emails for different contacts
$emailKey = "{$contactId}::{$email}";
if (!in_array($emailKey, $tempEmails)) {
$tempEmails[] = $emailKey;
$details = $form->_contactDetails[$contactId];
$details['email'] = $email;
unset($details['email_id']);
$formattedContactDetails[] = $details;
}
}
// send the mail
list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail($formattedContactDetails, $subject, $formValues['text_message'], $formValues['html_message'], NULL, NULL, $from, $attachments, $cc, $bcc, array_keys($form->_toContactDetails), $additionalDetails);
$followupStatus = '';
if ($sent) {
$followupActivity = NULL;
if (!empty($formValues['followup_activity_type_id'])) {
$params['followup_activity_type_id'] = $formValues['followup_activity_type_id'];
$params['followup_activity_subject'] = $formValues['followup_activity_subject'];
$params['followup_date'] = $formValues['followup_date'];
$params['followup_date_time'] = $formValues['followup_date_time'];
$params['target_contact_id'] = $form->_contactIds;
$params['followup_assignee_contact_id'] = explode(',', $formValues['followup_assignee_contact_id']);
//.........这里部分代码省略.........
示例8: postProcess
public function postProcess()
{
$params = $ids = array();
$uploadParams = array('from_name');
$formValues = $this->controller->exportValues($this->_name);
foreach ($uploadParams as $key) {
if (!empty($formValues[$key])) {
$params[$key] = $formValues[$key];
$this->set($key, $formValues[$key]);
}
}
if (!$formValues['upload_type']) {
$contents = NULL;
if (isset($formValues['textFile']) && !empty($formValues['textFile'])) {
$contents = file_get_contents($formValues['textFile']['name']);
$this->set($key, $formValues['textFile']['name']);
}
if ($contents) {
$params['body_text'] = $contents;
} else {
$params['body_text'] = 'NULL';
}
} else {
$text_message = $formValues['text_message'];
$params['body_text'] = $text_message;
$this->set('textFile', $params['body_text']);
$this->set('text_message', $params['body_text']);
}
$params['name'] = $this->get('name');
$session = CRM_Core_Session::singleton();
$params['contact_id'] = $session->get('userID');
$composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
$msgTemplate = NULL;
//mail template is composed
if ($formValues['upload_type']) {
$composeParams = array();
foreach ($composeFields as $key) {
if (!empty($formValues[$key])) {
$composeParams[$key] = $formValues[$key];
$this->set($key, $formValues[$key]);
}
}
if (!empty($composeParams['updateTemplate'])) {
$templateParams = array('msg_text' => $text_message, 'is_active' => TRUE);
$templateParams['id'] = $formValues['template'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (!empty($composeParams['saveTemplate'])) {
$templateParams = array('msg_text' => $text_message, 'is_active' => TRUE);
$templateParams['msg_title'] = $composeParams['saveTemplateName'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (isset($msgTemplate->id)) {
$params['msg_template_id'] = $msgTemplate->id;
} else {
$params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
}
$this->set('template', $params['msg_template_id']);
}
$ids['mailing_id'] = $this->_mailingID;
//get the from email address
$params['sms_provider_id'] = $formValues['sms_provider_id'];
//get the from Name
$params['from_name'] = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $params['sms_provider_id'], 'username');
//Build SMS in mailing table
CRM_Mailing_BAO_Mailing::create($params, $ids);
}
示例9: processMessageTemplate
/**
* Part of the post process which prepare and extract information from the template.
*
*
* @param CRM_Core_Form $form
*
* @return array
* [$categories, $html_message, $messageToken, $returnProperties]
*/
protected static function processMessageTemplate(&$form)
{
$formValues = $form->controller->exportValues($form->getName());
// process message template
if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
$messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => TRUE);
$messageTemplate['pdf_format_id'] = 'null';
if (!empty($formValues['bind_format']) && $formValues['format_id']) {
$messageTemplate['pdf_format_id'] = $formValues['format_id'];
}
if (!empty($formValues['saveTemplate']) && $formValues['saveTemplate']) {
$messageTemplate['msg_title'] = $formValues['saveTemplateName'];
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
if (!empty($formValues['updateTemplate']) && $formValues['template'] && $formValues['updateTemplate']) {
$messageTemplate['id'] = $formValues['template'];
unset($messageTemplate['msg_title']);
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
} elseif (CRM_Utils_Array::value('template', $formValues) > 0) {
if (!empty($formValues['bind_format']) && $formValues['format_id']) {
$query = "UPDATE civicrm_msg_template SET pdf_format_id = {$formValues['format_id']} WHERE id = {$formValues['template']}";
} else {
$query = "UPDATE civicrm_msg_template SET pdf_format_id = NULL WHERE id = {$formValues['template']}";
}
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
if (!empty($formValues['update_format'])) {
$bao = new CRM_Core_BAO_PdfFormat();
$bao->savePdfFormat($formValues, $formValues['format_id']);
}
$html = array();
$tokens = array();
CRM_Utils_Hook::tokens($tokens);
$categories = array_keys($tokens);
$html_message = $formValues['html_message'];
//time being hack to strip ' '
//from particular letter line, CRM-6798
self::formatMessage($html_message);
$messageToken = CRM_Utils_Token::getTokens($html_message);
$returnProperties = array();
if (isset($messageToken['contact'])) {
foreach ($messageToken['contact'] as $key => $value) {
$returnProperties[$value] = 1;
}
}
return array($formValues, $categories, $html_message, $messageToken, $returnProperties);
}
示例10: postProcess
/**
* Process the form submission.
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_MessageTemplate::del($this->_id);
} elseif ($this->_action & CRM_Core_Action::VIEW) {
// currently, the above action is used solely for previewing default workflow templates
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
} else {
$params = array();
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
}
if (!empty($params['file_type'])) {
unset($params['msg_html']);
unset($params['msg_text']);
CRM_Utils_File::formatFile($params, 'file_id');
} elseif (!empty($this->_id)) {
$entityFileDAO = new CRM_Core_DAO_EntityFile();
$entityFileDAO->entity_id = $this->_id;
$entityFileDAO->entity_table = 'civicrm_msg_template';
if ($entityFileDAO->find(TRUE)) {
$fileDAO = new CRM_Core_DAO_File();
$fileDAO->id = $entityFileDAO->file_id;
$fileDAO->find(TRUE);
$entityFileDAO->delete();
$fileDAO->delete();
}
}
if ($this->_workflow_id) {
$params['workflow_id'] = $this->_workflow_id;
$params['is_active'] = TRUE;
}
$messageTemplate = CRM_Core_BAO_MessageTemplate::add($params);
CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title)), ts('Saved'), 'success');
if ($this->_workflow_id) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
} else {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
}
}
}
示例11: processDl
/**
* handler for dl requests
*/
static function processDl()
{
$config = self::getConfig();
global $http_return_code;
/* run this puppy through premailer */
// DS: not sure why we need premailer as it always sends out mobile (inline) layout.
// Lets disable it till we figure out why we need it.
//$premailer = Premailer::html( $_POST[ "html" ], true, "hpricot", $config['BASE_URL'] );
//$html = $premailer[ "html" ];
$html = $_POST["html"];
/* create static versions of resized images */
$matches = [];
$num_full_pattern_matches = preg_match_all('#<img.*?src="([^"]*?\\/[^/]*\\.[^"]+)#i', $html, $matches);
for ($i = 0; $i < $num_full_pattern_matches; $i++) {
if (preg_match('#/img/(\\?|&)src=#i', $matches[1][$i])) {
$src_matches = [];
if (preg_match('#/img/(\\?|&)src=(.*)&method=(.*)&params=(.*)#i', $matches[1][$i], $src_matches) !== FALSE) {
$file_name = urldecode($src_matches[2]);
$file_name = substr($file_name, strlen($config['BASE_URL']));
$method = urldecode($src_matches[3]);
$params = urldecode($src_matches[4]);
$params = explode(",", $params);
$width = (int) $params[0];
$height = (int) $params[1];
$static_file_name = $method . "_" . $width . "x" . $height . "_" . $file_name;
$html = str_ireplace($matches[1][$i], $config['BASE_URL'] . $config['STATIC_URL'] . rawurlencode($static_file_name), $html);
//Changed to rawurlencode because space gets into + in the image file name if it has space
$image = self::resizeImage($file_name, $method, $width, $height);
$image->writeImage($config['BASE_DIR'] . $config['STATIC_DIR'] . $static_file_name);
}
}
}
/* perform the requested action */
switch (CRM_Utils_Type::escape($_POST['action'], 'String')) {
case "download":
// download
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"" . $_POST["filename"] . "\"");
header("Content-Length: " . strlen($html));
echo $html;
break;
case "save":
$result = array();
$msgTplId = NULL;
$hashKey = CRM_Utils_Type::escape($_POST['key'], 'String');
if (!$hashKey) {
CRM_Core_Session::setStatus(ts('Mosaico hask key not found...'));
return FALSE;
}
$mosTpl = new CRM_Mosaico_DAO_MessageTemplate();
$mosTpl->hash_key = $hashKey;
if ($mosTpl->find(TRUE)) {
$msgTplId = $mosTpl->msg_tpl_id;
}
$name = "Mosaico Template " . date('d-m-Y H:i:s');
if (CRM_Utils_Type::escape($_POST['name'], 'String')) {
$name = $_POST['name'];
}
// save to message templates
$messageTemplate = array('msg_html' => $html, 'is_active' => TRUE);
$messageTemplate['msg_title'] = $messageTemplate['msg_subject'];
if ($msgTplId) {
$messageTemplate['id'] = $msgTplId;
}
$messageTemplate['msg_title'] = $messageTemplate['msg_subject'] = $name;
$msgTpl = CRM_Core_BAO_MessageTemplate::add($messageTemplate);
$mosaicoTemplate = array('msg_tpl_id' => $msgTpl->id, 'hash_key' => $hashKey, 'name' => $name, 'html' => $_POST['html'], 'metadata' => $_POST['metadata'], 'template' => $_POST['template']);
$mosTpl = new CRM_Mosaico_DAO_MessageTemplate();
$mosTpl->msg_tpl_id = $msgTpl->id;
$mosTpl->hash_key = $hashKey;
$mosTpl->find(TRUE);
$mosTpl->copyValues($mosaicoTemplate);
$mosTpl->save();
if ($mosTpl->id) {
$result['id'] = $mosTpl->id;
}
CRM_Utils_JSON::output($result);
break;
case "email":
$result = array();
if (!CRM_Utils_Rule::email($_POST['rcpt'])) {
CRM_Core_Session::setStatus('Recipient Email address not found');
return FALSE;
}
$to = $_POST['rcpt'];
$subject = CRM_Utils_Type::escape($_POST['subject'], 'String');
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$mailParams = array('from' => $domainEmailAddress, 'toName' => 'Test Recipient', 'toEmail' => $to, 'subject' => $subject, 'html' => $html);
$sent = FALSE;
if (CRM_Utils_Mail::send($mailParams)) {
$result['sent'] = TRUE;
CRM_Utils_JSON::output($result);
} else {
CRM_Utils_JSON::output($result);
return FALSE;
}
break;
//.........这里部分代码省略.........
示例12: getDefaultTemplateID
/**
* Returns default template ID.
* If default template doesn't exist, it will install it
*
* @return int template ID
* @throws Exception if there's something wrong with the default template
*/
public static function getDefaultTemplateID()
{
$default_template_title = sprintf("%s - %s", ts('Donation Receipts', array('domain' => 'de.systopia.donrec')), ts('Default template', array('domain' => 'de.systopia.donrec')));
$result = civicrm_api3('MessageTemplate', 'get', array('msg_title' => $default_template_title, 'return' => 'id'));
if (!empty($result['id'])) {
// we found it!
return $result['id'];
}
if ($result['count'] > 1) {
// oops, there's more of them...
CRM_Core_Error::debug_log_message("de.systopia.donrec: getDefaultTemplate '{$default_template_title}' is ambiguous.");
$first_result = reset($result['values']);
return $first_result['id'];
}
// default template is not installed yet, so do it
$default_template_file = dirname(__DIR__) . '/../../templates/Export/default_template.tpl';
$default_template_html = file_get_contents($default_template_file);
if ($default_template_html === FALSE) {
throw new Exception("Cannot load default template from '{$default_template_file}'.");
}
// TODO: what is this...?
$workflowId = CRM_Donrec_DataStructure::getFirstUsedOptionValueId();
$params = array('msg_title' => $default_template_title, 'msg_html' => $default_template_html, 'is_active' => 1, 'workflow_id' => $workflowId, 'is_default' => 0, 'is_reserved' => 0);
$result = CRM_Core_BAO_MessageTemplate::add($params);
if ($result) {
return $result->id;
} else {
throw new Exception("Cannot create default template.");
}
}
示例13: processMessageTemplate
/**
* Part of the post process which prepare and extract information from the template.
*
*
* @param array $formValues
*
* @return array
* [$categories, $html_message, $messageToken, $returnProperties]
*/
public static function processMessageTemplate($formValues)
{
$html_message = CRM_Utils_Array::value('html_message', $formValues);
// process message template
if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
$messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => TRUE);
$messageTemplate['pdf_format_id'] = 'null';
if (!empty($formValues['bind_format']) && $formValues['format_id']) {
$messageTemplate['pdf_format_id'] = $formValues['format_id'];
}
if (!empty($formValues['saveTemplate']) && $formValues['saveTemplate']) {
$messageTemplate['msg_title'] = $formValues['saveTemplateName'];
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
if (!empty($formValues['updateTemplate']) && $formValues['template'] && $formValues['updateTemplate']) {
$messageTemplate['id'] = $formValues['template'];
unset($messageTemplate['msg_title']);
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
} elseif (CRM_Utils_Array::value('template', $formValues) > 0) {
if (!empty($formValues['bind_format']) && $formValues['format_id']) {
$query = "UPDATE civicrm_msg_template SET pdf_format_id = {$formValues['format_id']} WHERE id = {$formValues['template']}";
} else {
$query = "UPDATE civicrm_msg_template SET pdf_format_id = NULL WHERE id = {$formValues['template']}";
}
CRM_Core_DAO::executeQuery($query);
$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $formValues['template']);
foreach ((array) $documentInfo as $info) {
list($html_message, $formValues['document_type']) = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type']);
$formValues['document_file_path'] = $info['fullPath'];
}
} elseif (!empty($formValues['document_file'])) {
list($html_message, $formValues['document_type']) = CRM_Utils_PDF_Document::docReader($formValues['document_file']['name'], $formValues['document_file']['type']);
$formValues['document_file_path'] = $formValues['document_file']['name'];
}
if (!empty($formValues['update_format'])) {
$bao = new CRM_Core_BAO_PdfFormat();
$bao->savePdfFormat($formValues, $formValues['format_id']);
}
$tokens = array();
CRM_Utils_Hook::tokens($tokens);
$categories = array_keys($tokens);
//time being hack to strip ' '
//from particular letter line, CRM-6798
self::formatMessage($html_message);
$messageToken = CRM_Utils_Token::getTokens($html_message);
$returnProperties = array();
if (isset($messageToken['contact'])) {
foreach ($messageToken['contact'] as $key => $value) {
$returnProperties[$value] = 1;
}
}
return array($formValues, $categories, $html_message, $messageToken, $returnProperties);
}