本文整理汇总了PHP中CRM_Mailing_BAO_Mailing::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Mailing_BAO_Mailing::create方法的具体用法?PHP CRM_Mailing_BAO_Mailing::create怎么用?PHP CRM_Mailing_BAO_Mailing::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Mailing_BAO_Mailing
的用法示例。
在下文中一共展示了CRM_Mailing_BAO_Mailing::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Store Mails into Spool table.
*
* @param string|array $recipient
* Either a comma-seperated list of recipients
* (RFC822 compliant), or an array of recipients,
* each RFC822 valid. This may contain recipients not
* specified in the headers, for Bcc:, resending
* messages, etc.
* @param array $headers
* The array of headers to send with the mail.
*
* @param string $body
* The full text of the message body, including any mime parts, etc.
*
* @param int $job_id
*
* @return bool|CRM_Core_Error
* true if successful
*/
public function send($recipient, $headers, $body, $job_id = NULL)
{
$headerStr = array();
foreach ($headers as $name => $value) {
$headerStr[] = "{$name}: {$value}";
}
$headerStr = implode("\n", $headerStr);
if (is_null($job_id)) {
// This is not a bulk mailing. Create a dummy job for it.
$session = CRM_Core_Session::singleton();
$params = array();
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
$params['scheduled_id'] = $params['created_id'];
$params['scheduled_date'] = $params['created_date'];
$params['is_completed'] = 1;
$params['is_archived'] = 1;
$params['body_html'] = htmlspecialchars($headerStr) . "\n\n" . $body;
$params['subject'] = $headers['Subject'];
$params['name'] = $headers['Subject'];
$ids = array();
$mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
if (empty($mailing) || is_a($mailing, 'CRM_Core_Error')) {
return PEAR::raiseError('Unable to create spooled mailing.');
}
$job = new CRM_Mailing_BAO_MailingJob();
$job->is_test = 0;
// if set to 1 it doesn't show in the UI
$job->status = 'Complete';
$job->scheduled_date = CRM_Utils_Date::processDate(date('Y-m-d'), date('H:i:s'));
$job->start_date = $job->scheduled_date;
$job->end_date = $job->scheduled_date;
$job->mailing_id = $mailing->id;
$job->save();
$job_id = $job->id;
// need this for parent_id below
$job = new CRM_Mailing_BAO_MailingJob();
$job->is_test = 0;
$job->status = 'Complete';
$job->scheduled_date = CRM_Utils_Date::processDate(date('Y-m-d'), date('H:i:s'));
$job->start_date = $job->scheduled_date;
$job->end_date = $job->scheduled_date;
$job->mailing_id = $mailing->id;
$job->parent_id = $job_id;
$job->job_type = 'child';
$job->save();
$job_id = $job->id;
// this is the one we want for the spool
if (is_array($recipient)) {
$recipient = implode(';', $recipient);
}
}
$session = CRM_Core_Session::singleton();
$params = array('job_id' => $job_id, 'recipient_email' => $recipient, 'headers' => $headerStr, 'body' => $body, 'added_at' => date("YmdHis"), 'removed_at' => NULL);
$spoolMail = new CRM_Mailing_DAO_Spool();
$spoolMail->copyValues($params);
$spoolMail->save();
return TRUE;
}
示例2: postProcess
/**
* Process the posted form values. Create and schedule a Mass SMS.
*/
public function postProcess()
{
$params = array();
$params['mailing_id'] = $ids['mailing_id'] = $this->_mailingID;
if (empty($params['mailing_id'])) {
CRM_Core_Error::fatal(ts('Could not find a mailing id'));
}
foreach (array('now', 'start_date', 'start_date_time') as $parameter) {
$params[$parameter] = $this->controller->exportValue($this->_name, $parameter);
}
if ($params['now']) {
$params['scheduled_date'] = date('YmdHis');
} else {
$params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']);
}
$session = CRM_Core_Session::singleton();
// set the scheduled_id
$params['scheduled_id'] = $session->get('userID');
$params['scheduled_date'] = date('YmdHis');
// set approval details if workflow is not enabled
if (!CRM_Mailing_Info::workflowEnabled()) {
$params['approver_id'] = $session->get('userID');
$params['approval_date'] = date('YmdHis');
$params['approval_status_id'] = 1;
}
if ($params['now']) {
$params['scheduled_date'] = date('YmdHis');
} else {
$params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']);
}
// Build the mailing object.
CRM_Mailing_BAO_Mailing::create($params, $ids);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled', 'reset=1&scheduled=true&sms=1'));
}
示例3: postProcess
public function postProcess()
{
$values = $this->controller->exportValues($this->_name);
$groups = array();
foreach (array('name', 'group_id', 'is_sms') as $n) {
if (!empty($values[$n])) {
$params[$n] = $values[$n];
}
}
$qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit');
$this->set('name', $params['name']);
$inGroups = $values['includeGroups'];
$outGroups = $values['excludeGroups'];
$inMailings = $values['includeMailings'];
$outMailings = $values['excludeMailings'];
if (is_array($inGroups)) {
foreach ($inGroups as $key => $id) {
if ($id) {
$groups['include'][] = $id;
}
}
}
if (is_array($outGroups)) {
foreach ($outGroups as $key => $id) {
if ($id) {
$groups['exclude'][] = $id;
}
}
}
$mailings = array();
if (is_array($inMailings)) {
foreach ($inMailings as $key => $id) {
if ($id) {
$mailings['include'][] = $id;
}
}
}
if (is_array($outMailings)) {
foreach ($outMailings as $key => $id) {
if ($id) {
$mailings['exclude'][] = $id;
}
}
}
$session = CRM_Core_Session::singleton();
$params['groups'] = $groups;
$params['mailings'] = $mailings;
$ids = array();
if ($this->get('mailing_id')) {
// don't create a new mass sms if already exists
$ids['mailing_id'] = $this->get('mailing_id');
$groupTableName = CRM_Contact_BAO_Group::getTableName();
$mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
// delete previous includes/excludes, if mailing already existed
foreach (array('groups', 'mailings') as $entity) {
$mg = new CRM_Mailing_DAO_MailingGroup();
$mg->mailing_id = $ids['mailing_id'];
$mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
$mg->find();
while ($mg->fetch()) {
$mg->delete();
}
}
} else {
// new mailing, so lets set the created_id
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
}
$mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
$this->set('mailing_id', $mailing->id);
// also compute the recipients and store them in the mailing recipients table
CRM_Mailing_BAO_Mailing::getRecipients($mailing->id, $mailing->id, TRUE, FALSE, 'sms');
$count = CRM_Mailing_BAO_Recipients::mailingSize($mailing->id);
$this->set('count', $count);
$this->assign('count', $count);
$this->set('groups', $groups);
$this->set('mailings', $mailings);
if ($qf_Group_submit) {
$status = ts("Your Mass SMS has been saved.");
CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
$url = CRM_Utils_System::url('civicrm/mailing', 'reset=1&sms=1');
return $this->controller->setDestination($url);
}
}
示例4: postProcess
public function postProcess()
{
$values = $this->controller->exportValues($this->_name);
//build hidden smart group. when user want to send mailing
//through search contact-> more action -> send Mailing. CRM-3711
$groups = array();
if ($this->_searchBasedMailing && $this->_contactIds) {
//get the hidden smart group id.
$ssId = $this->get('ssID');
$session = CRM_Core_Session::singleton();
$hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $this->get('formValues'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context'));
require_once 'CRM/Contact/BAO/Group.php';
list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
//set the saved search id.
if (!$ssId) {
if ($savedSearchId) {
$this->set('ssID', $savedSearchId);
} else {
CRM_Core_Error::fatal();
}
}
//get the base group for this mailing, CRM-3711
$groups['base'] = array($values['baseGroup']);
$values['includeGroups'][] = $smartGroupId;
}
foreach (array('name', 'group_id', 'search_id', 'search_args') as $n) {
if (CRM_Utils_Array::value($n, $values)) {
$params[$n] = $values[$n];
}
}
$qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit');
$this->set('name', $params['name']);
$inGroups = $values['includeGroups'];
$outGroups = $values['excludeGroups'];
$inMailings = $values['includeMailings'];
$outMailings = $values['excludeMailings'];
if (is_array($inGroups)) {
foreach ($inGroups as $key => $id) {
if ($id) {
$groups['include'][] = $id;
}
}
}
if (is_array($outGroups)) {
foreach ($outGroups as $key => $id) {
if ($id) {
$groups['exclude'][] = $id;
}
}
}
$mailings = array();
if (is_array($inMailings)) {
foreach ($inMailings as $key => $id) {
if ($id) {
$mailings['include'][] = $id;
}
}
}
if (is_array($outMailings)) {
foreach ($outMailings as $key => $id) {
if ($id) {
$mailings['exclude'][] = $id;
}
}
}
$session = CRM_Core_Session::singleton();
$params['groups'] = $groups;
$params['mailings'] = $mailings;
if ($this->get('mailing_id')) {
$ids = array();
// don't create a new mailing if already exists
$ids['mailing_id'] = $this->get('mailing_id');
$groupTableName = CRM_Contact_BAO_Group::getTableName();
$mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
// delete previous includes/excludes, if mailing already existed
require_once 'CRM/Contact/DAO/Group.php';
foreach (array('groups', 'mailings') as $entity) {
$mg = new CRM_Mailing_DAO_Group();
$mg->mailing_id = $ids['mailing_id'];
$mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
$mg->find();
while ($mg->fetch()) {
$mg->delete();
}
}
} else {
// new mailing, so lets set the created_id
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
}
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
$this->set('mailing_id', $mailing->id);
$count = CRM_Mailing_BAO_Mailing::getRecipientsCount(true, false, $mailing->id);
$this->set('count', $count);
$this->assign('count', $count);
$this->set('groups', $groups);
$this->set('mailings', $mailings);
if ($qf_Group_submit) {
//.........这里部分代码省略.........
示例5: postProcess
public function postProcess()
{
$values = $this->controller->exportValues($this->_name);
//build hidden smart group. when user want to send mailing
//through search contact-> more action -> send Mailing. CRM-3711
$groups = array();
if ($this->_searchBasedMailing && $this->_contactIds) {
$session = CRM_Core_Session::singleton();
if ($this->_resultSelectOption == 'ts_sel') {
// create a static grp if only a subset of result set was selected:
$randID = md5(time());
$grpTitle = "Hidden Group {$randID}";
$grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title');
if (!$grpID) {
$groupParams = array('title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, 'group_type' => array('2' => 1));
$group = CRM_Contact_BAO_Group::create($groupParams);
$grpID = $group->id;
CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id);
$newGroupTitle = "Hidden Group {$grpID}";
$groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle);
$group = CRM_Contact_BAO_Group::create($groupParams);
}
// note at this point its a static group
$smartGroupId = $grpID;
} else {
//get the hidden smart group id.
$ssId = $this->get('ssID');
$hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $this->get('formValues'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context'));
list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
//set the saved search id.
if (!$ssId) {
if ($savedSearchId) {
$this->set('ssID', $savedSearchId);
} else {
CRM_Core_Error::fatal();
}
}
}
//get the base group for this mailing, CRM-3711
$groups['base'] = array($values['baseGroup']);
$values['includeGroups'][] = $smartGroupId;
}
foreach (array('name', 'group_id', 'search_id', 'search_args', 'campaign_id', 'dedupe_email') as $n) {
if (CRM_Utils_Array::value($n, $values)) {
$params[$n] = $values[$n];
}
}
$qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit');
$this->set('name', $params['name']);
$inGroups = $values['includeGroups'];
$outGroups = $values['excludeGroups'];
$inMailings = $values['includeMailings'];
$outMailings = $values['excludeMailings'];
if (is_array($inGroups)) {
foreach ($inGroups as $key => $id) {
if ($id) {
$groups['include'][] = $id;
}
}
}
if (is_array($outGroups)) {
foreach ($outGroups as $key => $id) {
if ($id) {
$groups['exclude'][] = $id;
}
}
}
$mailings = array();
if (is_array($inMailings)) {
foreach ($inMailings as $key => $id) {
if ($id) {
$mailings['include'][] = $id;
}
}
}
if (is_array($outMailings)) {
foreach ($outMailings as $key => $id) {
if ($id) {
$mailings['exclude'][] = $id;
}
}
}
$session = CRM_Core_Session::singleton();
$params['groups'] = $groups;
$params['mailings'] = $mailings;
if ($this->get('mailing_id')) {
$ids = array();
// don't create a new mailing if already exists
$ids['mailing_id'] = $this->get('mailing_id');
$groupTableName = CRM_Contact_BAO_Group::getTableName();
$mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
// delete previous includes/excludes, if mailing already existed
foreach (array('groups', 'mailings') as $entity) {
$mg = new CRM_Mailing_DAO_Group();
$mg->mailing_id = $ids['mailing_id'];
$mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
$mg->find();
while ($mg->fetch()) {
$mg->delete();
}
//.........这里部分代码省略.........
示例6: 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';
}
//.........这里部分代码省略.........
示例7: 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);
}
示例8: postProcess
/**
* Process the posted form values. Approve /reject a mailing.
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
$ids = array();
if (isset($this->_mailingID)) {
$ids['mailing_id'] = $this->_mailingID;
} else {
$ids['mailing_id'] = $this->get('mailing_id');
}
if (!$ids['mailing_id']) {
CRM_Core_Error::fatal();
}
$params['approver_id'] = $this->_contactID;
$params['approval_date'] = date('YmdHis');
// if rejected, then we need to reset the scheduled date and scheduled id
$rejectOptionID = CRM_Core_OptionGroup::getValue('mail_approval_status', 'Rejected', 'name');
if ($rejectOptionID && $params['approval_status_id'] == $rejectOptionID) {
$params['scheduled_id'] = 'null';
$params['scheduled_date'] = 'null';
// also delete any jobs associated with this mailing
$job = new CRM_Mailing_BAO_MailingJob();
$job->mailing_id = $ids['mailing_id'];
$job->delete();
} else {
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $ids['mailing_id'];
$mailing->find(TRUE);
$params['scheduled_date'] = CRM_Utils_Date::processDate($mailing->scheduled_date);
}
CRM_Mailing_BAO_Mailing::create($params, $ids);
//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';
}
$context = $this->get('context');
if (!CRM_Contact_Form_Search::isSearchContext($context)) {
$context = 'search';
}
$urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey={$qfKey}";
}
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
return $this->controller->setDestination($url);
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled', 'reset=1&scheduled=true'));
}
示例9: createCiviMailing
/**
* Create or update CiviCRM mailing
*
* @param $params
*
* @return object
*/
protected static function createCiviMailing($params)
{
$crmMailingParams = static::buildCiviMailingParams($params);
$crmMailingId = array('mailing_id' => isset($params['crm_mailing_id']) ? $params['crm_mailing_id'] : NULL);
// Create or update CiviCRM mailing - a mailing job would be created (scheduled) if scheduled date has been set
$crmMailing = CRM_Mailing_BAO_Mailing::create($crmMailingParams, $crmMailingId);
return $crmMailing;
}
示例10: postProcess
/**
* Process the posted form values. Create and schedule a mailing.
*
* @param
* @return void
* @access public
*/
function postProcess()
{
$params = array();
foreach (array('template', 'mailing_name', 'groups', 'mailings', 'header_id', 'footer_id', 'reply_id', 'unsubscribe_id', 'optout_id', 'textFile', 'htmlFile', 'subject', 'from_name', 'from_email', 'forward_reply', 'track_urls', 'track_opens', 'auto_responder') as $parameter) {
$params[$parameter] = $this->get($parameter);
}
foreach (array('now', 'start_date') as $parameter) {
$params[$parameter] = $this->controller->exportValue($this->_name, $parameter);
}
$session =& CRM_Core_Session::singleton();
$params['domain_id'] = $session->get('domainID');
$params['contact_id'] = $session->get('userID');
/* Build the mailing object */
require_once 'CRM/Mailing/BAO/Mailing.php';
CRM_Mailing_BAO_Mailing::create($params);
}
示例11: postProcess
/**
* Process the posted form values. Create and schedule a mailing.
*
* @param
*
* @return void
* @access public
*/
public function postProcess()
{
$params = array();
$params['mailing_id'] = $ids['mailing_id'] = $this->_mailingID;
if (empty($params['mailing_id'])) {
CRM_Core_Error::fatal(ts('Could not find a mailing id'));
}
foreach (array('now', 'start_date', 'start_date_time') as $parameter) {
$params[$parameter] = $this->controller->exportValue($this->_name, $parameter);
}
// Previously, we checked if $mailing->is_template, and did *not*
// schedule if it was set. Discussed with Lobo, removed that check
// as it appeared to prevent mails being scheduled if they were
// saved as a template, and this wasn't the documented behaviour.
// $saveTemplate = $this->controller->exportValue('saveTemplate');
if ($params['now']) {
$params['scheduled_date'] = date('YmdHis');
} else {
$params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']);
}
$session = CRM_Core_Session::singleton();
// set the scheduled_id
$params['scheduled_id'] = $session->get('userID');
// set approval details if workflow is not enabled
if (!CRM_Mailing_Info::workflowEnabled()) {
$params['approver_id'] = $session->get('userID');
$params['approval_date'] = date('YmdHis');
$params['approval_status_id'] = 1;
} else {
// reset them in case this mailing was rejected
$params['approver_id'] = 'null';
$params['approval_date'] = 'null';
$params['approval_status_id'] = 'null';
}
/* Build the mailing object */
CRM_Mailing_BAO_Mailing::create($params, $ids);
//when user perform mailing from search context
//redirect it to search result CRM-3711.
$ssID = $this->get('ssID');
if ($ssID && $this->_searchBasedMailing && !CRM_Mailing_Info::workflowEnabled()) {
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';
}
$context = $this->get('context');
if (!CRM_Contact_Form_Search::isSearchContext($context)) {
$context = 'search';
}
$urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey={$qfKey}";
}
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
return $this->controller->setDestination($url);
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled', 'reset=1&scheduled=true'));
}
示例12: updateTemplateOptions
function updateTemplateOptions()
{
// Update the templates and upload options
$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 (CRM_Utils_Array::value($key, $formValues) || in_array($key, array('header_id', 'footer_id'))) {
$params[$key] = $formValues[$key];
$this->set($key, $formValues[$key]);
}
}
$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');
CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->get('mailing_id'));
$ids['mailing_id'] = $this->get('mailing_id');
//set msg_template_id
$params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
$this->set('template', $params['msg_template_id']);
//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 (CRM_Utils_Array::value('reply_to_address', $formValues)) {
$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);
}
示例13: postProcess
public function postProcess()
{
$params = $ids = array();
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
$uploadParams = array('reply_id', 'unsubscribe_id', 'optout_id', 'resubscribe_id');
$uploadParamsBoolean = array('override_verp', 'forward_replies', 'url_tracking', 'open_tracking', 'auto_responder');
$qf_Settings_submit = $this->controller->exportValue($this->_name, '_qf_Settings_submit');
foreach ($uploadParams as $key) {
$params[$key] = $this->controller->exportvalue($this->_name, $key);
$this->set($key, $this->controller->exportvalue($this->_name, $key));
}
foreach ($uploadParamsBoolean as $key) {
if ($this->controller->exportvalue($this->_name, $key)) {
$params[$key] = TRUE;
} else {
$params[$key] = FALSE;
}
$this->set($key, $this->controller->exportvalue($this->_name, $key));
}
$params['visibility'] = $this->controller->exportvalue($this->_name, 'visibility');
// override_verp must be flipped, as in 3.2 we reverted
// its meaning to ‘should CiviMail manage replies?’ – i.e.,
// ‘should it *not* override Reply-To: with VERP-ed address?’
$params['override_verp'] = !$params['override_verp'];
$ids['mailing_id'] = $this->get('mailing_id');
// update mailing
CRM_Mailing_BAO_Mailing::create($params, $ids);
if ($qf_Settings_submit) {
//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';
}
$context = $this->get('context');
if (!CRM_Contact_Form_Search::isSearchContext($context)) {
$context = 'search';
}
$urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey={$qfKey}";
}
$draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
$status = ts("You can continue later by clicking the 'Continue' action to resume working on it.<br />From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
// Redirect user to search.
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
} else {
$status = ts("Click the 'Continue' action to resume working on it.");
$url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
}
CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
CRM_Utils_System::redirect($url);
}
}
示例14: postProcess
public function postProcess()
{
$params = $ids = array();
$uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email', 'override_verp');
$fileType = array('textFile', 'htmlFile');
$formValues = $this->controller->exportValues($this->_name);
foreach ($uploadParams as $key) {
if (CRM_Utils_Array::value($key, $formValues) || 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']) {
foreach ($composeFields as $key) {
if (CRM_Utils_Array::value($key, $formValues)) {
$composeParams[$key] = $formValues[$key];
$this->set($key, $formValues[$key]);
}
}
if (CRM_Utils_Array::value('updateTemplate', $composeParams)) {
$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_MessageTemplates::add($templateParams);
}
if (CRM_Utils_Array::value('saveTemplate', $composeParams)) {
$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_MessageTemplates::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.
$formEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_PseudoConstant::fromEmailAddress("from_email_address"));
//get the from email address
require_once 'CRM/Utils/Mail.php';
$params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($formEmailAddress);
//get the from Name
$params['from_name'] = CRM_Utils_Array::value(1, explode('"', $formEmailAddress));
/* Build the mailing object */
require_once 'CRM/Mailing/BAO/Mailing.php';
CRM_Mailing_BAO_Mailing::create($params, $ids);
if ($this->_submitValues['_qf_Upload_upload'] == 'Save & Continue Later') {
//when user perform mailing from search context
//redirect it to search result CRM-3711.
$ssID = $this->get('ssID');
$context = $this->get('context');
if ($ssID && $context == 'search') {
if ($this->_action == CRM_Core_Action::BASIC) {
$fragment = 'search';
} else {
if ($this->_action == CRM_Core_Action::PROFILE) {
$fragment = 'search/builder';
} else {
if ($this->_action == CRM_Core_Action::ADVANCED) {
$fragment = 'search/advanced';
} else {
$fragment = 'search/custom';
}
}
//.........这里部分代码省略.........
示例15: postProcess
public function postProcess()
{
$params = $ids = array();
$uploadParams = array('reply_id', 'unsubscribe_id', 'optout_id', 'resubscribe_id');
$uploadParamsBoolean = array('forward_replies', 'url_tracking', 'open_tracking', 'auto_responder');
$qf_Settings_submit = $this->controller->exportValue($this->_name, '_qf_Settings_submit');
foreach ($uploadParams as $key) {
$params[$key] = $this->controller->exportvalue($this->_name, $key);
$this->set($key, $this->controller->exportvalue($this->_name, $key));
}
foreach ($uploadParamsBoolean as $key) {
if ($this->controller->exportvalue($this->_name, $key)) {
$params[$key] = true;
} else {
$params[$key] = false;
}
$this->set($key, $this->controller->exportvalue($this->_name, $key));
}
$ids['mailing_id'] = $this->get('mailing_id');
// update mailing
require_once 'CRM/Mailing/BAO/Mailing.php';
CRM_Mailing_BAO_Mailing::create($params, $ids);
if ($qf_Settings_submit) {
//when user perform mailing from search context
//redirect it to search result CRM-3711.
$ssID = $this->get('ssID');
$context = $this->get('context');
if ($ssID && $context == 'search') {
if ($this->_action == CRM_Core_Action::BASIC) {
$fragment = 'search';
} else {
if ($this->_action == CRM_Core_Action::PROFILE) {
$fragment = 'search/builder';
} else {
if ($this->_action == CRM_Core_Action::ADVANCED) {
$fragment = 'search/advanced';
} else {
$fragment = 'search/custom';
}
}
}
$draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
$status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
CRM_Core_Session::setStatus($status);
//replace user context to search.
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, "force=1&reset=1&ssID={$ssID}");
CRM_Utils_System::redirect($url);
} else {
$status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it.");
CRM_Core_Session::setStatus($status);
$url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
CRM_Utils_System::redirect($url);
}
}
}