/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $session = CRM_Core_Session::singleton(); //this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization $this->set('searchRows', ''); $context = $this->get('context'); if (in_array($context, array('smog', 'amtg'))) { $urlParams = 'reset=1&force=1&context=smog&gid='; $urlParams .= $context == 'smog' ? $this->get('gid') : $this->get('amtgID'); $session->replaceUserContext(CRM_Utils_System::url('civicrm/group/search', $urlParams)); return; } $ssID = $this->get('ssID'); 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'; } } } $path = 'force=1'; if (isset($ssID)) { $path .= "&reset=1&ssID={$ssID}"; } if (!CRM_Contact_Form_Search::isSearchContext($context)) { $context = 'search'; } $path .= "&context={$context}"; //set the user context for redirection of task actions $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); require_once 'CRM/Utils/Rule.php'; if (CRM_Utils_Rule::qfKey($qfKey)) { $path .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $path); $session->replaceUserContext($url); return; }
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) { //when user perform mailing from search context //redirect it to search result CRM-3711. $ssID = $this->get('ssID'); $context = $this->get('context'); if ($ssID && $this->_searchBasedMailing) { 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'; } } } $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("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, $urlParams); 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); } } }
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(); } } } 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); $dedupeEmail = FALSE; if (isset($params['dedupe_email'])) { $dedupeEmail = $params['dedupe_email']; } // also compute the recipients and store them in the mailing recipients table CRM_Mailing_BAO_Mailing::getRecipients($mailing->id, $mailing->id, NULL, NULL, TRUE, $dedupeEmail); $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) { //when user perform mailing from search context //redirect it to search result CRM-3711. $ssID = $this->get('ssID'); $context = $this->get('context'); 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("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, $urlParams); return $this->controller->setDestination($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'); return $this->controller->setDestination($url); } } }
/** * Build the form object. */ public function preProcess() { CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity'); $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET); $this->assign('atypefile', FALSE); if ($this->_atypefile) { $this->assign('atypefile', TRUE); } $session = CRM_Core_Session::singleton(); $this->_currentUserId = $session->get('userID'); $this->_currentlyViewedContactId = $this->get('contactId'); if (!$this->_currentlyViewedContactId) { $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); } $this->assign('contactId', $this->_currentlyViewedContactId); // Give the context. if (!isset($this->_context)) { $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); if (CRM_Contact_Form_Search::isSearchContext($this->_context)) { $this->_context = 'search'; } elseif (!in_array($this->_context, array('dashlet', 'dashletFullscreen')) && $this->_currentlyViewedContactId) { $this->_context = 'activity'; } $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this); } $this->assign('context', $this->_context); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); if ($this->_action & CRM_Core_Action::DELETE) { if (!CRM_Core_Permission::check('delete activities')) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } } // CRM-6957 // When we come from contact search, activity id never comes. // So don't try to get from object, it might gives you wrong one. // if we're not adding new one, there must be an id to // an activity we're trying to work on. if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') { $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this); } $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this); $this->assign('atype', $this->_activityTypeId); $this->assign('activityId', $this->_activityId); // Check for required permissions, CRM-6264. if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } if ($this->_action & CRM_Core_Action::VIEW && CRM_Activity_BAO_Activity::checkPermission($this->_activityId, CRM_Core_Action::UPDATE)) { $this->assign('permission', 'edit'); } if (!$this->_activityTypeId && $this->_activityId) { $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id'); } // Assigning Activity type name. if ($this->_activityTypeId) { $activityTName = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $this->_activityTypeId, 'label'); if ($activityTName[$this->_activityTypeId]) { $this->_activityTypeName = $activityTName[$this->_activityTypeId]; $this->assign('activityTName', $activityTName[$this->_activityTypeId]); } } // Set title. if (isset($activityTName)) { $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName); $this->assign('pageTitle', ts('%1 Activity', array(1 => $activityName))); if ($this->_currentlyViewedContactId) { $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId); // Check if this is default domain contact CRM-10482. if (CRM_Contact_BAO_Contact::checkDomainContact($this->_currentlyViewedContactId)) { $displayName .= ' (' . ts('default organization') . ')'; } CRM_Utils_System::setTitle($displayName . ' - ' . $activityName); } else { CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName))); } } // Check the mode when this form is called either single or as // search task action. if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) { $this->_single = TRUE; $this->assign('urlPath', 'civicrm/activity'); } else { // Set the appropriate action. $url = CRM_Utils_System::currentPath(); $urlArray = explode('/', $url); $searchPath = array_pop($urlArray); $searchType = 'basic'; $this->_action = CRM_Core_Action::BASIC; switch ($searchPath) { case 'basic': $searchType = $searchPath; $this->_action = CRM_Core_Action::BASIC; break; case 'advanced': $searchType = $searchPath; $this->_action = CRM_Core_Action::ADVANCED; break; case 'builder': $searchType = $searchPath; $this->_action = CRM_Core_Action::PROFILE; break; case 'custom': $this->_action = CRM_Core_Action::COPY; $searchType = $searchPath; break; } parent::preProcess(); $this->_single = FALSE; $this->assign('urlPath', "civicrm/contact/search/{$searchType}"); $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}"); } $this->assign('single', $this->_single); $this->assign('action', $this->_action); if ($this->_action & CRM_Core_Action::VIEW) { // Get the tree of custom fields. $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId); } if ($this->_activityTypeId) { // Set activity type name and description to template. list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId); $this->assign('activityTypeName', $this->_activityTypeName); $this->assign('activityTypeDescription', $activityTypeDescription); } // set user context $urlParams = $urlString = NULL; $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); if (!$qfKey) { $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); } // Validate the qfKey. if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } if ($this->_context == 'fulltext') { $keyName = '&qfKey'; $urlParams = 'force=1'; $urlString = 'civicrm/contact/search/custom'; if ($this->_action == CRM_Core_Action::UPDATE) { $keyName = '&key'; $urlParams .= '&context=fulltext&action=view'; $urlString = 'civicrm/contact/view/activity'; } if ($qfKey) { $urlParams .= "{$keyName}={$qfKey}"; } $this->assign('searchKey', $qfKey); } elseif (in_array($this->_context, array('standalone', 'home', 'dashlet', 'dashletFullscreen'))) { $urlParams = 'reset=1'; $urlString = 'civicrm/dashboard'; } elseif ($this->_context == 'search') { $urlParams = 'force=1'; if ($qfKey) { $urlParams .= "&qfKey={$qfKey}"; } $path = CRM_Utils_System::currentPath(); if ($this->_compContext == 'advanced') { $urlString = 'civicrm/contact/search/advanced'; } elseif ($path == 'civicrm/group/search' || $path == 'civicrm/contact/search' || $path == 'civicrm/contact/search/advanced' || $path == 'civicrm/contact/search/custom' || $path == 'civicrm/group/search') { $urlString = $path; } else { $urlString = 'civicrm/activity/search'; } $this->assign('searchKey', $qfKey); } elseif ($this->_context != 'caseActivity') { $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity"; $urlString = 'civicrm/contact/view'; } if ($urlString) { $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams)); } // hack to retrieve activity type id from post variables if (!$this->_activityTypeId) { $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST); } // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { // We need to set it in the session for the code below to work. // CRM-3014 // Need to assign custom data subtype to the template. $this->set('type', 'Activity'); $this->set('subType', $this->_activityTypeId); $this->set('entityId', $this->_activityId); CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity', $this->_activityId); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } // add attachments part CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId, NULL, TRUE); // figure out the file name for activity type, if any if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) { $this->assign('activityTypeFile', $this->_activityTypeFile); $this->assign('crmDir', $this->_crmDir); } $this->setFields(); if ($this->_activityTypeFile) { $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; $className::preProcess($this); } $this->_values = $this->get('values'); if (!is_array($this->_values)) { $this->_values = array(); if (isset($this->_activityId) && $this->_activityId) { $params = array('id' => $this->_activityId); CRM_Activity_BAO_Activity::retrieve($params, $this->_values); } $this->set('values', $this->_values); } if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity'); } }
/** * Form rule to send out a test mailing. * * @param aray $testParams * @param array $files * Any files posted to the form. * @param array $self * An current this object. * * @return bool * true on successful SMTP handoff */ public static function testMail($testParams, $files, $self) { $error = NULL; $urlString = 'civicrm/mailing/send'; $urlParams = "_qf_Test_display=true&qfKey={$testParams['qfKey']}"; $ssID = $self->get('ssID'); if ($ssID && $self->_searchBasedMailing) { if ($self->_action == CRM_Core_Action::BASIC) { $fragment = 'search'; } elseif ($self->_action == CRM_Core_Action::PROFILE) { $fragment = 'search/builder'; } elseif ($self->_action == CRM_Core_Action::ADVANCED) { $fragment = 'search/advanced'; } else { $fragment = 'search/custom'; } $urlString = 'civicrm/contact/' . $fragment; } $emails = NULL; if (!empty($testParams['sendtest'])) { if (!($testParams['test_group'] || $testParams['test_email'])) { CRM_Core_Session::setStatus(ts('You did not provide an email address or select a group.'), ts('Test not sent.'), 'error'); $error = TRUE; } if ($testParams['test_email']) { $emailAdd = explode(',', $testParams['test_email']); foreach ($emailAdd as $key => $value) { $email = trim($value); $testParams['emails'][] = $email; $emails .= ($emails ? ',' : '') . "'" . CRM_Core_DAO::escapeString($email) . "'"; if (!CRM_Utils_Rule::email($email)) { CRM_Core_Session::setStatus(ts('Please enter a valid email address.'), ts('Test not sent.'), 'error'); $error = TRUE; } } } if ($error) { $url = CRM_Utils_System::url($urlString, $urlParams); CRM_Utils_System::redirect($url); return $error; } } if (!empty($testParams['_qf_Test_submit'])) { //when user perform mailing from search context //redirect it to search result CRM-3711. if ($ssID && $self->_searchBasedMailing) { $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)); //replace user context to search. $context = $self->get('context'); if (!CRM_Contact_Form_Search::isSearchContext($context)) { $context = 'search'; } $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}&qfKey={$testParams['qfKey']}"; $url = CRM_Utils_System::url($urlString, $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); } if (CRM_Mailing_Info::workflowEnabled()) { if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) { $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); CRM_Utils_System::redirect($url); } } if (!empty($testParams['_qf_Test_next']) && $self->get('count') <= 0) { return array('_qf_default' => ts("You can not schedule or send this mailing because there are currently no recipients selected. Click 'Previous' to return to the Select Recipients step, OR click 'Save & Continue Later'.")); } if (!empty($_POST['_qf_Import_refresh']) || !empty($testParams['_qf_Test_next']) || empty($testParams['sendtest'])) { $error = TRUE; return $error; } $job = new CRM_Mailing_BAO_MailingJob(); $job->mailing_id = $self->get('mailing_id'); $job->is_test = TRUE; $job->save(); $newEmails = NULL; $session = CRM_Core_Session::singleton(); if (!empty($testParams['emails'])) { $query = "\nSELECT e.id, e.contact_id, e.email\nFROM civicrm_email e\nINNER JOIN civicrm_contact c ON e.contact_id = c.id\nWHERE e.email IN ({$emails})\nAND e.on_hold = 0\nAND c.is_opt_out = 0\nAND c.do_not_email = 0\nAND c.is_deleted = 0\nAND c.is_deceased = 0\nGROUP BY e.id\nORDER BY e.is_bulkmail DESC, e.is_primary DESC\n"; $dao = CRM_Core_DAO::executeQuery($query); $emailDetail = array(); // fetch contact_id and email id for all existing emails while ($dao->fetch()) { $emailDetail[$dao->email] = array('contact_id' => $dao->contact_id, 'email_id' => $dao->id); } $dao->free(); foreach ($testParams['emails'] as $key => $email) { // Email addresses are forced to lower case when saved, so ensure // we have the same case when comparing. $email = trim(strtolower($email)); $contactId = $emailId = NULL; if (array_key_exists($email, $emailDetail)) { $emailId = $emailDetail[$email]['email_id']; $contactId = $emailDetail[$email]['contact_id']; } if (!$contactId) { //create new contact. $params = array('contact_type' => 'Individual', 'email' => array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => 1))); $contact = CRM_Contact_BAO_Contact::create($params); $emailId = $contact->email[0]->id; $contactId = $contact->id; $contact->free(); } $params = array('job_id' => $job->id, 'email_id' => $emailId, 'contact_id' => $contactId); CRM_Mailing_Event_BAO_Queue::create($params); } } $testParams['job_id'] = $job->id; $isComplete = FALSE; while (!$isComplete) { $isComplete = CRM_Mailing_BAO_MailingJob::runJobs($testParams); } if (!empty($testParams['sendtest'])) { $status = NULL; if (CRM_Mailing_Info::workflowEnabled()) { if (CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings') || CRM_Core_Permission::check('access CiviMail')) { $status = ts("Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page)."); } } else { $status = ts("Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page)."); } if ($status) { CRM_Core_Session::setStatus($status, ts('Test message sent'), 'success'); } $url = CRM_Utils_System::url($urlString, $urlParams); CRM_Utils_System::redirect($url); } $error = TRUE; return $error; }
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'; } $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}"; } $session = CRM_Core_Session::singleton(); $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)); CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); // 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'); return $this->controller->setDestination($url); } }
/** * 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); } $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $ids['mailing_id']; if ($mailing->find(TRUE)) { $job = new CRM_Mailing_BAO_Job(); $job->mailing_id = $mailing->id; $job->is_test = 0; if ($job->find(TRUE)) { CRM_Core_Error::fatal(ts('A job for this mailing already exists')); } if (empty($mailing->is_template)) { $job->status = 'Scheduled'; if ($params['now']) { $job->scheduled_date = date('YmdHis'); } else { $job->scheduled_date = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']); } $job->save(); } // set approval details if workflow is not enabled if (!CRM_Mailing_Info::workflowEnabled()) { $session = CRM_Core_Session::singleton(); $mailing->approver_id = $session->get('userID'); $mailing->approval_date = date('YmdHis'); $mailing->approval_status_id = 1; } else { // reset them in case this mailing was rejected $mailing->approver_id = 'null'; $mailing->approval_date = 'null'; $mailing->approval_status_id = 'null'; } if ($mailing->approval_date) { $mailing->approval_date = CRM_Utils_Date::isoToMysql($mailing->approval_date); } // also set the scheduled_id $session = CRM_Core_Session::singleton(); $mailing->scheduled_id = $session->get('userID'); $mailing->scheduled_date = date('YmdHis'); $mailing->created_date = CRM_Utils_Date::isoToMysql($mailing->created_date); $mailing->save(); } //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')); }
/** * 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')); }
/** * 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')); }
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); } }
/** * Function to build the form * * @return None * @access public */ function preProcess() { $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET); $this->assign('atypefile', false); if ($this->_atypefile) { $this->assign('atypefile', true); } $this->_addAssigneeContact = CRM_Utils_Array::value('assignee_contact', $_GET); $this->assign('addAssigneeContact', false); if ($this->_addAssigneeContact) { $this->assign('addAssigneeContact', true); } $this->_addTargetContact = CRM_Utils_Array::value('target_contact', $_GET); $this->assign('addTargetContact', false); if ($this->_addTargetContact) { $this->assign('addTargetContact', true); } $session = CRM_Core_Session::singleton(); $this->_currentUserId = $session->get('userID'); //give the context. if (!$this->_context) { $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); require_once 'CRM/Contact/Form/Search.php'; if (CRM_Contact_Form_Search::isSearchContext($this->_context)) { $this->_context = 'search'; } $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this); } $this->assign('context', $this->_context); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); if ($this->_action & CRM_Core_Action::DELETE) { if (!CRM_Core_Permission::check('delete activities')) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } } //CRM-6957 //when we come from contact search, activity id never comes. //so don't try to get from object, it might gives you wrong one. // if we're not adding new one, there must be an id to // an activity we're trying to work on. if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') { $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this); } $this->_currentlyViewedContactId = $this->get('contactId'); if (!$this->_currentlyViewedContactId) { $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); } $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this); $this->assign('atype', $this->_activityTypeId); //check for required permissions, CRM-6264 require_once 'CRM/Case/BAO/Case.php'; if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } if (!$this->_activityTypeId && $this->_activityId) { $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id'); } //Assigning Activity type name if ($this->_activityTypeId) { require_once 'CRM/Core/OptionGroup.php'; $activityTName = CRM_Core_OptionGroup::values('activity_type', false, false, false, 'AND v.value = ' . $this->_activityTypeId, 'name'); if ($activityTName[$this->_activityTypeId]) { $this->assign('activityTName', $activityTName[$this->_activityTypeId]); } } // Assign pageTitle to be "Activity - "+ activity name $pageTitle = 'Activity - ' . CRM_Utils_Array::value($this->_activityTypeId, $activityTName); $this->assign('pageTitle', $pageTitle); //check the mode when this form is called either single or as //search task action if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) { $this->_single = true; $this->assign('urlPath', 'civicrm/activity'); } else { //set the appropriate action $url = CRM_Utils_System::currentPath(); $seachPath = array_pop(explode('/', $url)); $searchType = 'basic'; $this->_action = CRM_Core_Action::BASIC; switch ($seachPath) { case 'basic': $searchType = $seachPath; $this->_action = CRM_Core_Action::BASIC; break; case 'advanced': $searchType = $seachPath; $this->_action = CRM_Core_Action::ADVANCED; break; case 'builder': $searchType = $seachPath; $this->_action = CRM_Core_Action::PROFILE; break; case 'custom': $this->_action = CRM_Core_Action::COPY; $searchType = $seachPath; break; } parent::preProcess(); $this->_single = false; $this->assign('urlPath', "civicrm/contact/search/{$searchType}"); $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}"); } $this->assign('single', $this->_single); $this->assign('action', $this->_action); if ($this->_action & CRM_Core_Action::VIEW) { // get the tree of custom fields $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId); } if ($this->_activityTypeId) { //set activity type name and description to template require_once 'CRM/Core/BAO/OptionValue.php'; list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId); $this->assign('activityTypeName', $this->_activityTypeName); $this->assign('activityTypeDescription', $activityTypeDescription); } // set user context $urlParams = $urlString = null; $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = null; } if ($this->_context == 'fulltext') { $keyName = '&qfKey'; $urlParams = 'force=1'; $urlString = 'civicrm/contact/search/custom'; if ($this->_action == CRM_Core_Action::UPDATE) { $keyName = '&key'; $urlParams .= '&context=fulltext&action=view'; $urlString = 'civicrm/contact/view/activity'; } if ($qfKey) { $urlParams .= "{$keyName}={$qfKey}"; } $this->assign('searchKey', $qfKey); } else { if (in_array($this->_context, array('standalone', 'home'))) { $urlParams = 'reset=1'; $urlString = 'civicrm/dashboard'; } else { if ($this->_context == 'search') { $urlParams = 'force=1'; if ($qfKey) { $urlParams .= "&qfKey={$qfKey}"; } if ($this->_compContext == 'advanced') { $urlString = 'civicrm/contact/search/advanced'; } $this->assign('searchKey', $qfKey); } else { if ($this->_context != 'caseActivity') { $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity"; $urlString = 'civicrm/contact/view'; } } } } if ($urlString) { $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams)); } // hack to retrieve activity type id from post variables if (!$this->_activityTypeId) { $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST); } // when custom data is included in this page if (CRM_Utils_Array::value('hidden_custom', $_POST)) { // we need to set it in the session for the below code to work // CRM-3014 //need to assign custom data subtype to the template $this->set('type', 'Activity'); $this->set('subType', $this->_activityTypeId); $this->set('entityId', $this->_activityId); CRM_Custom_Form_CustomData::preProcess($this); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } // add attachments part CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId); // figure out the file name for activity type, if any if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) { require_once "CRM/{$this->_crmDir}/Form/Activity/{$this->_activityTypeFile}.php"; $this->assign('activityTypeFile', $this->_activityTypeFile); $this->assign('crmDir', $this->_crmDir); } $this->setFields(); if ($this->_activityTypeFile) { eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::preProcess( \$this );"); } }
/** * Form rule to send out a test mailing. * * @param array $params Array of the form values * @param array $files Any files posted to the form * @param array $self an current this object * * @return boolean true on succesful SMTP handoff * @access public */ static function &testMail($testParams, $files, $self) { $error = NULL; $urlString = 'civicrm/mailing/send'; $urlParams = "_qf_Test_display=true&qfKey={$testParams['qfKey']}"; $ssID = $self->get('ssID'); if ($ssID && $self->_searchBasedMailing) { if ($self->_action == CRM_Core_Action::BASIC) { $fragment = 'search'; } elseif ($self->_action == CRM_Core_Action::PROFILE) { $fragment = 'search/builder'; } elseif ($self->_action == CRM_Core_Action::ADVANCED) { $fragment = 'search/advanced'; } else { $fragment = 'search/custom'; } $urlString = 'civicrm/contact/' . $fragment; } $emails = NULL; if (CRM_Utils_Array::value('sendtest', $testParams)) { if (!($testParams['test_group'] || $testParams['test_email'])) { CRM_Core_Session::setStatus(ts('Your did not provided any email address or selected any group. No test mail is sent.')); $error = TRUE; } if ($testParams['test_email']) { $emailAdd = explode(',', $testParams['test_email']); foreach ($emailAdd as $key => $value) { $email = trim($value); $testParams['emails'][] = $email; $emails .= $emails ? ",'{$email}'" : "'{$email}'"; if (!CRM_Utils_Rule::email($email)) { CRM_Core_Session::setStatus(ts('Please enter valid email addresses only.')); $error = TRUE; } } } if ($error) { $url = CRM_Utils_System::url($urlString, $urlParams); CRM_Utils_System::redirect($url); return $error; } } if (CRM_Utils_Array::value('_qf_Test_submit', $testParams)) { //when user perform mailing from search context //redirect it to search result CRM-3711. if ($ssID && $self->_searchBasedMailing) { $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. $context = $self->get('context'); if (!CRM_Contact_Form_Search::isSearchContext($context)) { $context = 'search'; } $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}&qfKey={$testParams['qfKey']}"; $url = CRM_Utils_System::url($urlString, $urlParams); 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); } } if (CRM_Mailing_Info::workflowEnabled()) { if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) { $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); CRM_Utils_System::redirect($url); } } if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST) || CRM_Utils_Array::value('_qf_Test_next', $testParams) || !CRM_Utils_Array::value('sendtest', $testParams)) { $error = TRUE; return $error; } $job = new CRM_Mailing_BAO_Job(); $job->mailing_id = $self->get('mailing_id'); $job->is_test = TRUE; $job->save(); $newEmails = NULL; $session = CRM_Core_Session::singleton(); if (!empty($testParams['emails'])) { $query = "\n SELECT id, contact_id, email \n FROM civicrm_email \n WHERE civicrm_email.email IN ({$emails})"; $dao = CRM_Core_DAO::executeQuery($query); $emailDetail = array(); // fetch contact_id and email id for all existing emails while ($dao->fetch()) { $emailDetail[$dao->email] = array('contact_id' => $dao->contact_id, 'email_id' => $dao->id); } $dao->free(); foreach ($testParams['emails'] as $key => $email) { $email = trim($email); $contactId = $emailId = NULL; if (array_key_exists($email, $emailDetail)) { $emailId = $emailDetail[$email]['email_id']; $contactId = $emailDetail[$email]['contact_id']; } if (!$contactId) { //create new contact. $params = array('contact_type' => 'Individual', 'email' => array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => 1))); $contact = CRM_Contact_BAO_Contact::create($params); $emailId = $contact->email[0]->id; $contactId = $contact->id; $contact->free(); } $params = array('job_id' => $job->id, 'email_id' => $emailId, 'contact_id' => $contactId); CRM_Mailing_Event_BAO_Queue::create($params); } } $testParams['job_id'] = $job->id; $isComplete = FALSE; while (!$isComplete) { $isComplete = CRM_Mailing_BAO_Job::runJobs($testParams); } if (CRM_Utils_Array::value('sendtest', $testParams)) { $status = ts('Your test message has been sent.'); if (CRM_Mailing_Info::workflowEnabled()) { if (CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings') || CRM_Core_Permission::check('access CiviMail')) { $status .= ts(" Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page)."); } } else { $status .= ts(" Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page)."); } CRM_Core_Session::setStatus($status); $url = CRM_Utils_System::url($urlString, $urlParams); CRM_Utils_System::redirect($url); } $error = TRUE; return $error; }