/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { parent::preProcess(); require_once 'CRM/Utils/Rule.php'; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= '&qfKey=' . $qfKey; } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/search/custom', $urlParams); $session->replaceUserContext($url); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('survey_id', $this->get('formValues')); $isHeld = CRM_Utils_Array::value('status_id', $this->get('formValues')); if (!$this->_surveyId || !$isHeld) { CRM_Core_Error::statusBounce(ts("Please search with 'Is Held' and 'Survey Id' filters to apply this action.")); } $session = CRM_Core_Session::singleton(); if (empty($this->_contactIds) || !$session->get('userID')) { CRM_Core_Error::statusBounce(ts("Could not find contacts for release voters resevation Or Missing Interviewer contact.")); } $this->_interviewerId = $session->get('userID'); $surveyDetails = array(); $params = array('id' => $this->_surveyId); $this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails); $numVoters = CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM " . self::ACTIVITY_SURVEY_DETAIL_TABLE . " WHERE status_id = 'H' AND survey_id = %1 AND interviewer_id = %2", array(1 => array($this->_surveyId, 'Integer'), 2 => array($this->_interviewerId, 'Integer'))); if (!isset($numVoters) || $numVoters < 1) { CRM_Core_Error::statusBounce(ts("All voters held by you are already released for this survey.")); } $this->assign('surveyTitle', $surveyDetails['title']); }
/** * build all the data structures needed to build the form * * @return void * @access public */ public function preProcess() { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this); $context = CRM_Utils_Request::retrieve('context', 'String', $this); //get current client name. require_once 'CRM/Contact/BAO/Contact.php'; $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($this->_contactId)); //set the context. $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactId}&selectedChild=case"); if ($context == 'search') { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey require_once 'CRM/Utils/Rule.php'; $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); } else { if ($context == 'dashboard') { $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); } } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $context = CRM_Utils_Request::retrieve('context', 'String', $this); //get current client name. $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid)); //set the context. $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case"); if ($context == 'search') { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); } elseif ($context == 'dashboard') { $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); } elseif (in_array($context, array('dashlet', 'dashletFullscreen'))) { $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); if ($id) { $this->_contributionIds = array($id); $this->_componentClause = " civicrm_contribution.id IN ( {$id} ) "; $this->_single = TRUE; $this->assign('totalSelectedContributions', 1); } else { parent::preProcess(); } // check that all the contribution ids have pending status $query = "\nSELECT count(*)\nFROM civicrm_contribution\nWHERE contribution_status_id != 1\nAND {$this->_componentClause}"; $count = CRM_Core_DAO::singleValueQuery($query); if ($count != 0) { CRM_Core_Error::statusBounce("Please select only online contributions with Completed status."); } // we have all the contribution ids, so now we get the contact ids parent::setContactIDs(); $this->assign('single', $this->_single); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contribute/search', $urlParams); $breadCrumb = array(array('url' => $url, 'title' => ts('Search Results'))); CRM_Utils_System::appendBreadCrumb($breadCrumb); CRM_Utils_System::setTitle(ts('Print Contribution Receipts')); }
/** * Process the uploaded file. * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $exportParams = $this->controller->exportValues('Select'); $currentPath = CRM_Utils_System::currentPath(); $urlParams = NULL; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams = "&qfKey={$qfKey}"; } //get the button name $buttonName = $this->controller->getButtonName('done'); $buttonName1 = $this->controller->getButtonName('next'); if ($buttonName == '_qf_Map_done') { $this->set('exportColumnCount', NULL); $this->controller->resetPage($this->_name); return CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, 'force=1' . $urlParams)); } if ($this->controller->exportValue($this->_name, 'addMore')) { $this->set('exportColumnCount', $this->_exportColumnCount); return; } $mapperKeys = $params['mapper'][1]; $checkEmpty = 0; foreach ($mapperKeys as $value) { if ($value[0]) { $checkEmpty++; } } if (!$checkEmpty) { $this->set('mappingId', NULL); CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, '_qf_Map_display=true' . $urlParams)); } if ($buttonName1 == '_qf_Map_next') { if (!empty($params['updateMapping'])) { //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($params, $params['mappingId']); } if (!empty($params['saveMapping'])) { $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => $this->get('mappingTypeId')); $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams); //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($params, $saveMapping->id); } } //get the csv file CRM_Export_BAO_Export_Relationship::exportComponents($this->get('selectAll'), $this->get('componentIds'), $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), $mapperKeys, $this->get('returnProperties'), $this->get('exportMode'), $this->get('componentClause'), $this->get('componentTable'), $this->get('mergeSameAddress'), $this->get('mergeSameHousehold'), $exportParams); }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $session = CRM_Core_Session::singleton(); $this->set('searchRows', ''); $ssID = $this->get('ssID'); if (isset($ssID)) { $urlParams = 'reset=1&force=1&ssID=' . $ssID; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/grant/search', $urlParams); $session->replaceUserContext($url); return; } }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); $lid = CRM_Utils_Request::retrieve('lid', 'Positive', $this, FALSE); $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, FALSE); $profileGID = CRM_Utils_Request::retrieve('profileGID', 'Integer', $this, FALSE); $this->assign('profileGID', $profileGID); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $type = 'Contact'; if ($cid) { $ids = array($cid); $this->_single = TRUE; if ($profileGID) { // this does a check and ensures that the user has permission on this profile // CRM-11766 $profileIDs = CRM_Profile_Page_Listings::getProfileContact($profileGID); if (!in_array($cid, $profileIDs)) { CRM_Core_Error::fatal(); } } elseif ($context) { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $session = CRM_Core_Session::singleton(); $urlString = "civicrm/contact/search/{$context}"; if ($context == 'search') { $urlString = 'civicrm/contact/search'; } $url = CRM_Utils_System::url($urlString, $urlParams); $session->replaceUserContext($url); } } elseif ($eid) { $ids = $eid; $type = 'Event'; } else { if ($profileGID) { $ids = CRM_Profile_Page_Listings::getProfileContact($profileGID); } else { parent::preProcess(); $ids = $this->_contactIds; } } self::createMapXML($ids, $lid, $this, TRUE, $type); $this->assign('single', $this->_single); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { parent::preProcess(); require_once 'CRM/Utils/Rule.php'; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= '&qfKey=' . $qfKey; } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/search/custom', $urlParams); $session->replaceUserContext($url); if (empty($this->_contactIds) || !$session->get('userID')) { CRM_Core_Error::statusBounce(ts("Could not find contacts for voter reservation Or Missing Interviewer contact.")); } $this->_interviewerId = $session->get('userID'); }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $session = CRM_Core_Session::singleton(); //this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization $this->set('searchRows', ''); $ssID = $this->get('ssID'); $path = 'force=1'; if (isset($ssID)) { $path .= "&reset=1&ssID={$ssID}"; } $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $path .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/event/search', $path); $session->replaceUserContext($url); CRM_Utils_System::redirect($url); }
/** * 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; }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false); $lid = CRM_Utils_Request::retrieve('lid', 'Positive', $this, false); $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, false); $profileGID = CRM_Utils_Request::retrieve('profileGID', 'Integer', $this, false); $this->assign('profileGID', $profileGID); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $type = 'Contact'; if ($cid) { $ids = array($cid); $this->_single = true; if ($context && !$profileGID) { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $session = CRM_Core_Session::singleton(); $urlString = "civicrm/contact/search/{$context}"; if ($context == 'search') { $urlString = 'civicrm/contact/search'; } $url = CRM_Utils_System::url($urlString, $urlParams); $session->replaceUserContext($url); } } else { if ($eid) { $ids = $eid; $type = 'Event'; } else { if ($profileGID) { require_once "CRM/Profile/Page/Listings.php"; $ids = CRM_Profile_Page_Listings::getProfileContact($profileGID); } else { parent::preProcess(); $ids = $this->_contactIds; } } } self::createMapXML($ids, $lid, $this, true, $type); $this->assign('single', $this->_single); }
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); } } }
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); } } }
/** * Get context. * * @param $form */ public static function setContext(&$form) { $context = CRM_Utils_Request::retrieve('context', 'String', $form, FALSE, 'search'); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $form); //validate the qfKey if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } switch ($context) { case 'dashboard': case 'pledgeDashboard': $url = CRM_Utils_System::url('civicrm/pledge', 'reset=1'); break; case 'search': $urlParams = 'force=1'; if ($qfKey) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/pledge/search', $urlParams); break; case 'user': $url = CRM_Utils_System::url('civicrm/user', 'reset=1'); break; case 'pledge': $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$form->_contactId}&selectedChild=pledge"); break; case 'home': $url = CRM_Utils_System::url('civicrm/dashboard', 'force=1'); break; case 'activity': $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$form->_contactId}&selectedChild=activity"); break; case 'standalone': $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); break; default: $cid = NULL; if ($form->_contactId) { $cid = '&cid=' . $form->_contactId; } $url = CRM_Utils_System::url('civicrm/pledge/search', 'force=1' . $cid); break; } $session = CRM_Core_Session::singleton(); $session->pushUserContext($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'); } }
static function preProcessCommon(&$form, $useTable = FALSE) { $form->_caseIds = array(); $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = $values['task']; $caseTasks = CRM_Case_Task::tasks(); $form->assign('taskName', $caseTasks[$form->_task]); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CASE); $query->_distinctComponentClause = " ( civicrm_case.id )"; $query->_groupByComponentClause = " GROUP BY civicrm_case.id "; $result = $query->searchQuery(0, 0, NULL); while ($result->fetch()) { $ids[] = $result->case_id; } } if (!empty($ids)) { $form->_componentClause = ' civicrm_case.id IN ( ' . implode(',', $ids) . ' ) '; $form->assign('totalSelectedCases', count($ids)); } $form->_caseIds = $form->_componentIds = $ids; //set the context for redirection for any task actions $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $session = CRM_Core_Session::singleton(); $searchFormName = strtolower($form->get('searchFormName')); if ($searchFormName == 'search') { $session->replaceUserContext(CRM_Utils_System::url('civicrm/case/search', $urlParams)); } else { $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/{$searchFormName}", $urlParams)); } }
function setContext() { $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search'); $compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } switch ($context) { case 'dashboard': $url = CRM_Utils_System::url('civicrm/event', 'reset=1'); break; case 'search': $urlParams = 'force=1'; if ($qfKey) { $urlParams .= "&qfKey={$qfKey}"; } $this->assign('searchKey', $qfKey); if ($compContext == 'advanced') { $url = CRM_Utils_System::url('civicrm/contact/search/advanced', $urlParams); } else { $url = CRM_Utils_System::url('civicrm/event/search', $urlParams); } break; case 'user': $url = CRM_Utils_System::url('civicrm/user', 'reset=1'); break; case 'participant': $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactId}&selectedChild=participant"); break; case 'home': $url = CRM_Utils_System::url('civicrm/dashboard', 'force=1'); break; case 'activity': $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"); break; case 'standalone': $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); break; case 'fulltext': $keyName = '&qfKey'; $urlParams = 'force=1'; $urlString = 'civicrm/contact/search/custom'; if ($this->_action == CRM_Core_Action::UPDATE) { if ($this->_contactId) { $urlParams .= '&cid=' . $this->_contactId; } $keyName = '&key'; $urlParams .= '&context=fulltext&action=view'; $urlString = 'civicrm/contact/view/participant'; } if ($qfKey) { $urlParams .= "{$keyName}={$qfKey}"; } $this->assign('searchKey', $qfKey); $url = CRM_Utils_System::url($urlString, $urlParams); break; default: $cid = NULL; if ($this->_contactId) { $cid = '&cid=' . $this->_contactId; } $url = CRM_Utils_System::url('civicrm/event/search', 'force=1' . $cid); break; } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
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); } }
/** * Common pre-process function. * * @param CRM_Core_Form $form * @param bool $useTable */ public static function preProcessCommon(&$form, $useTable = FALSE) { $form->_activityHolderIds = array(); $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = $values['task']; $activityTasks = CRM_Activity_Task::tasks(); $form->assign('taskName', $activityTasks[$form->_task]); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_ACTIVITY); $query->_distinctComponentClause = '( civicrm_activity.id )'; $query->_groupByComponentClause = " GROUP BY civicrm_activity.id "; // CRM-12675 $activityClause = NULL; $components = CRM_Core_Component::getNames(); $componentClause = array(); foreach ($components as $componentID => $componentName) { if (!CRM_Core_Permission::check("access {$componentName}")) { $componentClause[] = " (activity_type.component_id IS NULL OR activity_type.component_id <> {$componentID}) "; } } if (!empty($componentClause)) { $activityClause = implode(' AND ', $componentClause); } $result = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $activityClause); while ($result->fetch()) { if (!empty($result->activity_id)) { $ids[] = $result->activity_id; } } } if (!empty($ids)) { $form->_componentClause = ' civicrm_activity.id IN ( ' . implode(',', $ids) . ' ) '; $form->assign('totalSelectedActivities', count($ids)); } $form->_activityHolderIds = $form->_componentIds = $ids; // Set the context for redirection for any task actions. $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $session = CRM_Core_Session::singleton(); $searchFormName = strtolower($form->get('searchFormName')); if ($searchFormName == 'search') { $session->replaceUserContext(CRM_Utils_System::url('civicrm/activity/search', $urlParams)); } else { $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/{$searchFormName}", $urlParams)); } }
/** * @param CRM_Core_Form $form * @param bool $useTable */ public static function preProcessCommon(&$form, $useTable = FALSE) { $form->_contributionIds = array(); $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = $values['task']; $contributeTasks = CRM_Contribute_Task::tasks(); $form->assign('taskName', $contributeTasks[$form->_task]); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $sortOrder = NULL; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); } $form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams); $query = new CRM_Contact_BAO_Query($queryParams, array('contribution_id'), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE); // @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this // can we remove? if not why not? if ($form->_includesSoftCredits) { $contactIds = $contributionContactIds = array(); $query->_rowCountClause = " count(civicrm_contribution.id)"; $query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id "; } else { $query->_distinctComponentClause = ' civicrm_contribution.id'; $query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id '; } $result = $query->searchQuery(0, 0, $sortOrder); while ($result->fetch()) { $ids[] = $result->contribution_id; if ($form->_includesSoftCredits) { $contactIds[$result->contact_id] = $result->contact_id; $contributionContactIds["{$result->contact_id}-{$result->contribution_id}"] = $result->contribution_id; } } $result->free(); $form->assign('totalSelectedContributions', $form->get('rowCount')); } if (!empty($ids)) { $form->_componentClause = ' civicrm_contribution.id IN ( ' . implode(',', $ids) . ' ) '; $form->assign('totalSelectedContributions', count($ids)); } if (!empty($form->_includesSoftCredits) && !empty($contactIds)) { $form->_contactIds = $contactIds; $form->_contributionContactIds = $contributionContactIds; } $form->_contributionIds = $form->_componentIds = $ids; //set the context for redirection for any task actions $session = CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $searchFormName = strtolower($form->get('searchFormName')); if ($searchFormName == 'search') { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contribute/search', $urlParams)); } else { $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/{$searchFormName}", $urlParams)); } }
static function preProcessCommon(&$form, $useTable = FALSE) { $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = CRM_Utils_Array::value('task', $values); $mailingTasks = CRM_Mailing_Task::tasks(); $form->assign('taskName', CRM_Utils_Array::value('task', $values)); // ids are mailing event queue ids $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $sortOrder = null; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); } $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_MAILING); $result = $query->searchQuery(0, 0, $sortOrder); while ($result->fetch()) { $ids[] = $result->mailing_recipients_id; } $form->assign('totalSelectedMailingRecipients', $form->get('rowCount')); } if (!empty($ids)) { $form->_componentClause = ' civicrm_mailing_recipients.id IN ( ' . implode(',', $ids) . ' ) '; } //set the context for redirection for any task actions $session = CRM_Core_Session::singleton(); $fragment = 'search'; if ($form->_action == CRM_Core_Action::ADVANCED) { $fragment .= '/advanced'; } $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($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')); }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $values = $this->controller->exportValues('Search'); $this->_task = $values['task']; $campaignTasks = CRM_Campaign_Task::tasks(); $taskName = CRM_Utils_Array::value($this->_task, $campaignTasks); $this->assign('taskName', $taskName); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $cacheKey = "civicrm search {$qfKey}"; $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall"); $ids = array_keys($allCids[$cacheKey]); $this->assign('totalSelectedVoters', count($ids)); } if (!empty($ids)) { $this->_componentClause = 'contact_a.id IN ( ' . implode(',', $ids) . ' ) '; $this->assign('totalSelectedVoters', count($ids)); } $this->_voterIds = $this->_contactIds = $this->_componentIds = $ids; $this->assign('totalSelectedContacts', count($this->_contactIds)); //set the context for redirection for any task actions $session = CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= '&qfKey=' . $qfKey; } $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/search', $urlParams)); }
/** * Heart of the viewing process. * * The runner gets all the meta data for the contact and calls the appropriate type of page to view. */ public function preProcess() { // process url params $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->assign('id', $this->_id); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } $this->assign('searchKey', $qfKey); // retrieve the group contact id, so that we can get contact id $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this); if (!$gcid) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); } else { $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id'); } if (!$this->_contactId) { CRM_Core_Error::statusBounce(ts('We could not find a contact id.'), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } // ensure that the id does exist if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'id') != $this->_contactId) { CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } $this->assign('contactId', $this->_contactId); // see if we can get prev/next positions from qfKey $navContacts = array('prevContactID' => NULL, 'prevContactName' => NULL, 'nextContactID' => NULL, 'nextContactName' => NULL, 'nextPrevError' => 0); if ($qfKey) { $pos = CRM_Core_BAO_PrevNextCache::getPositions("civicrm search {$qfKey}", $this->_contactId, $this->_contactId); $found = FALSE; if (isset($pos['prev'])) { $navContacts['prevContactID'] = $pos['prev']['id1']; $navContacts['prevContactName'] = $pos['prev']['data']; $found = TRUE; } if (isset($pos['next'])) { $navContacts['nextContactID'] = $pos['next']['id1']; $navContacts['nextContactName'] = $pos['next']['data']; $found = TRUE; } $context = CRM_Utils_Array::value('context', $_GET); if (!$found) { // seems like we did not find any contacts // maybe due to bug CRM-9096 // however we should account for 1 contact results (which dont have prev next) if (!$pos['foundEntry']) { $navContacts['nextPrevError'] = 1; } } elseif ($context) { $this->assign('context', $context); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => CRM_Utils_System::url("civicrm/contact/search/{$context}", array('qfKey' => $qfKey))))); } } $this->assign($navContacts); $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path))); if ($image_URL = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'image_URL')) { //CRM-7265 --time being fix. $config = CRM_Core_Config::singleton(); $image_URL = str_replace('https://', 'http://', $image_URL); if (Civi::settings()->get('enableSSL')) { $image_URL = str_replace('http://', 'https://', $image_URL); } list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($image_URL)); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $this->assign("imageWidth", $imageWidth); $this->assign("imageHeight", $imageHeight); $this->assign("imageThumbWidth", $imageThumbWidth); $this->assign("imageThumbHeight", $imageThumbHeight); $this->assign("imageURL", $image_URL); } // also store in session for future use $session = CRM_Core_Session::singleton(); $session->set('view.id', $this->_contactId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->assign('action', $this->_action); // check logged in user permission self::checkUserPermission($this); list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self::getContactDetails($this->_contactId); $this->assign('displayName', $displayName); $this->set('contactType', $contactType); // note: there could still be multiple subtypes. We just trimming the outer separator. $this->set('contactSubtype', trim($contactSubtype, CRM_Core_DAO::VALUE_SEPARATOR)); // add to recently viewed block $isDeleted = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'is_deleted'); $recentOther = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'isDeleted' => $isDeleted); if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}"); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts') && !$isDeleted) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}"); } CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"), $this->_contactId, $contactType, $this->_contactId, $displayName, $recentOther); $this->assign('isDeleted', $isDeleted); // set page title $title = self::setTitle($this->_contactId, $isDeleted); $this->assign('title', $title); // Check if this is default domain contact CRM-10482 if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactId)) { $this->assign('domainContact', TRUE); } else { $this->assign('domainContact', FALSE); } // Add links for actions menu self::addUrls($this, $this->_contactId); if ($contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations') && Civi::settings()->get('is_enabled')) { //check is any relationship between the organization and groups $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId); if ($groupOrg) { $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}"); $this->assign('groupOrganizationUrl', $groupOrganizationUrl); } } }
/** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { $session = CRM_Core_Session::singleton(); $currentUserId = $session->get('userID'); $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'basic'); $urlParams = 'force=1'; $urlString = "civicrm/contact/search/{$context}"; if (CRM_Utils_Rule::qfKey($this->_searchKey)) { $urlParams .= "&qfKey={$this->_searchKey}"; } elseif ($context == 'search') { $urlParams .= "&qfKey={$this->controller->_key}"; $urlString = 'civicrm/contact/search'; } elseif ($context == 'smog') { $urlParams .= "&qfKey={$this->controller->_key}&context=smog"; $urlString = 'civicrm/group/search'; } else { $urlParams = "reset=1"; $urlString = 'civicrm/dashboard'; } // Delete/Restore Contacts. Report errors. $deleted = 0; $not_deleted = array(); foreach ($this->_contactIds as $cid) { $name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name'); if (CRM_Contact_BAO_Contact::checkDomainContact($cid)) { $session->setStatus(ts("'%1' cannot be deleted because the information is used for special system purposes.", array(1 => $name)), 'Cannot Delete Domain Contact', 'error'); continue; } if ($currentUserId == $cid && !$this->_restore) { $session->setStatus(ts("You are currently logged in as '%1'. You cannot delete yourself.", array(1 => $name)), 'Unable To Delete', 'error'); continue; } if (CRM_Contact_BAO_Contact::deleteContact($cid, $this->_restore, $this->_skipUndelete)) { $deleted++; } else { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}"); $not_deleted[$cid] = "<a href='{$url}'>{$name}</a>"; } } if ($deleted) { $title = ts('Deleted'); if ($this->_restore) { $title = ts('Restored'); $status = ts('%1 has been restored from the trash.', array(1 => $name, 'plural' => '%count contacts restored from trash.', 'count' => $deleted)); } elseif ($this->_skipUndelete) { $status = ts('%1 has been permanently deleted.', array(1 => $name, 'plural' => '%count contacts permanently deleted.', 'count' => $deleted)); } else { $status = ts('%1 has been moved to the trash.', array(1 => $name, 'plural' => '%count contacts moved to trash.', 'count' => $deleted)); } $session->setStatus($status, $title, 'success'); } // Alert user of any failures if ($not_deleted) { $status = ts('The contact might be the Membership Organization of a Membership Type. You will need to edit the Membership Type and change the Membership Organization before you can delete this contact.'); $title = ts('Unable to Delete'); $session->setStatus('<ul><li>' . implode('</li><li>', $not_deleted) . '</li></ul>' . $status, $title, 'error'); } if (isset($this->_sharedAddressMessage) && $this->_sharedAddressMessage['count'] > 0 && !$this->_restore) { if (count($this->_sharedAddressMessage['contactList']) == 1) { $message = ts('The following contact had been sharing an address with a contact you just deleted. Their address will no longer be shared, but has not been removed or altered.'); } else { $message = ts('The following contacts had been sharing addresses with a contact you just deleted. Their addressses will no longer be shared, but have not been removed or altered.'); } $message .= '<ul><li>' . implode('</li><li>', $this->_sharedAddressMessage['contactList']) . '</li></ul>'; $session->setStatus($message, ts('Shared Addesses Owner Deleted'), 'info', array('expires' => 0)); $this->set('sharedAddressMessage', NULL); } if ($this->_single && empty($this->_skipUndelete)) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactIds[0]}")); } else { $session->replaceUserContext(CRM_Utils_System::url($urlString, $urlParams)); } }
/** * Form submission of new/edit contact is processed. */ public function postProcess() { // check if dedupe button, if so return. $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_dedupeButtonName) { return; } //get the submitted values in an array $params = $this->controller->exportValues($this->_name); $group = CRM_Utils_Array::value('group', $params); if (!empty($group) && is_array($group)) { unset($params['group']); foreach ($group as $key => $value) { $params['group'][$value] = 1; } } CRM_Contact_BAO_Contact_Optimizer::edit($params, $this->_preEditValues); if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && !empty($params['current_employer'])) { $params['current_employer'] = $params['current_employer_id']; } // don't carry current_employer_id field, // since we don't want to directly update DAO object without // handling related business logic ( eg related membership ) if (isset($params['current_employer_id'])) { unset($params['current_employer_id']); } $params['contact_type'] = $this->_contactType; if (empty($params['contact_sub_type']) && $this->_isContactSubType) { $params['contact_sub_type'] = array($this->_contactSubType); } if ($this->_contactId) { $params['contact_id'] = $this->_contactId; } //make deceased date null when is_deceased = false if ($this->_contactType == 'Individual' && !empty($this->_editOptions['Demographics']) && empty($params['is_deceased'])) { $params['is_deceased'] = FALSE; $params['deceased_date'] = NULL; } if (isset($params['contact_id'])) { // process membership status for deceased contact $deceasedParams = array('contact_id' => CRM_Utils_Array::value('contact_id', $params), 'is_deceased' => CRM_Utils_Array::value('is_deceased', $params, FALSE), 'deceased_date' => CRM_Utils_Array::value('deceased_date', $params, NULL)); $updateMembershipMsg = $this->updateMembershipStatus($deceasedParams); } // action is taken depending upon the mode if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); } else { CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params); } $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, TRUE); //CRM-5143 //if subtype is set, send subtype as extend to validate subtype customfield $customFieldExtends = CRM_Utils_Array::value('contact_sub_type', $params) ? $params['contact_sub_type'] : $params['contact_type']; $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_contactId, $customFieldExtends, TRUE); if ($this->_contactId && !empty($this->_oldSubtypes)) { CRM_Contact_BAO_ContactType::deleteCustomSetForSubtypeMigration($this->_contactId, $params['contact_type'], $this->_oldSubtypes, $params['contact_sub_type']); } if (array_key_exists('CommunicationPreferences', $this->_editOptions)) { // this is a chekbox, so mark false if we dont get a POST value $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE); } // process shared contact address. CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']); if (!array_key_exists('TagsAndGroups', $this->_editOptions) && !empty($params['group'])) { unset($params['group']); } if (!empty($params['contact_id']) && $this->_action & CRM_Core_Action::UPDATE && !empty($params['group'])) { // figure out which all groups are intended to be removed $contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added'); if (is_array($contactGroupList)) { foreach ($contactGroupList as $key) { if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1) && empty($key['is_hidden'])) { $params['group'][$key['group_id']] = -1; } } } } // parse street address, CRM-5450 $parseStatusMsg = NULL; if ($this->_parseStreetAddress) { $parseResult = self::parseAddress($params); $parseStatusMsg = self::parseAddressStatusMsg($parseResult); } // Allow un-setting of location info, CRM-5969 $params['updateBlankLocInfo'] = TRUE; $contact = CRM_Contact_BAO_Contact::create($params, TRUE, FALSE, TRUE); // status message if ($this->_contactId) { $message = ts('%1 has been updated.', array(1 => $contact->display_name)); } else { $message = ts('%1 has been created.', array(1 => $contact->display_name)); } // set the contact ID $this->_contactId = $contact->id; if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $params['contact_id']); //save free tags if (isset($params['contact_taglist']) && !empty($params['contact_taglist'])) { CRM_Core_Form_Tag::postProcess($params['contact_taglist'], $params['contact_id'], 'civicrm_contact', $this); } } if (!empty($parseStatusMsg)) { $message .= "<br />{$parseStatusMsg}"; } if (!empty($updateMembershipMsg)) { $message .= "<br />{$updateMembershipMsg}"; } $session = CRM_Core_Session::singleton(); $session->setStatus($message, ts('Contact Saved'), 'success'); // add the recently viewed contact $recentOther = array(); if ($session->get('userID') == $contact->id || CRM_Contact_BAO_Contact_Permission::allow($contact->id, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', 'reset=1&action=update&cid=' . $contact->id); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', 'reset=1&delete=1&cid=' . $contact->id); } CRM_Utils_Recent::add($contact->display_name, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contact->id, $this->_contactType, $contact->id, $contact->display_name, $recentOther); // here we replace the user context with the url to view this contact $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('upload', 'new')) { $contactSubTypes = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_contactSubType)); $resetStr = "reset=1&ct={$contact->contact_type}"; $resetStr .= count($contactSubTypes) == 1 ? "&cst=" . array_pop($contactSubTypes) : ''; $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add', $resetStr)); } else { $context = CRM_Utils_Request::retrieve('context', 'String', $this); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey $urlParams = 'reset=1&cid=' . $contact->id; if ($context) { $urlParams .= "&context={$context}"; } if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&key={$qfKey}"; } $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', $urlParams)); } // now invoke the post hook if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); } else { CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); } }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $this->addElement('text', 'newGroupName', ts('Name for new group')); $this->addElement('text', 'newGroupDesc', ts('Description of new group')); $groups = $this->get('groups'); if (!empty($groups)) { $this->addElement('select', 'groups', ts('Add imported records to existing group(s)'), $groups, array('multiple' => "multiple", 'class' => 'crm-select2')); } //display new tag $this->addElement('text', 'newTagName', ts('Tag')); $this->addElement('text', 'newTagDesc', ts('Description')); $tag = $this->get('tag'); if (!empty($tag)) { foreach ($tag as $tagID => $tagName) { $this->addElement('checkbox', "tag[{$tagID}]", NULL, $tagName); } } $path = "_qf_MapField_display=true"; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); if (CRM_Utils_Rule::qfKey($qfKey)) { $path .= "&qfKey={$qfKey}"; } $previousURL = CRM_Utils_System::url('civicrm/import/contact', $path, FALSE, NULL, FALSE); $cancelURL = CRM_Utils_System::url('civicrm/import/contact', 'reset=1'); $buttons = array(array('type' => 'back', 'name' => ts('<< Previous'), 'js' => array('onclick' => "location.href='{$previousURL}'; return false;")), array('type' => 'next', 'name' => ts('Import Now >>'), 'spacing' => ' ', 'isDefault' => TRUE, 'js' => array('onclick' => "return verify( );")), array('type' => 'cancel', 'name' => ts('Cancel'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))); $this->addButtons($buttons); $this->addFormRule(array('CRM_Contact_Import_Form_Preview', 'formRule'), $this); }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); if ($id) { $this->_contributionIds = array($id); $this->_componentClause = " civicrm_contribution.id IN ( {$id} ) "; $this->_single = TRUE; $this->assign('totalSelectedContributions', 1); // set the redirection after actions $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$id}&cid={$contactId}&context=contribution&selectedChild=contribute"); CRM_Core_Session::singleton()->pushUserContext($url); } else { parent::preProcess(); } // check that all the contribution ids have status Completed, Pending, Refunded. $this->_contributionStatusId = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $status = array('Completed', 'Pending', 'Refunded'); $statusId = array(); foreach ($this->_contributionStatusId as $key => $value) { if (in_array($value, $status)) { $statusId[] = $key; } } $Id = implode(",", $statusId); $query = "SELECT count(*) FROM civicrm_contribution WHERE contribution_status_id NOT IN ({$Id}) AND {$this->_componentClause}"; $count = CRM_Core_DAO::singleValueQuery($query); if ($count != 0) { CRM_Core_Error::statusBounce(ts('Please select only contributions with Completed, Pending, Refunded status.')); } // we have all the contribution ids, so now we get the contact ids parent::setContactIDs(); $this->assign('single', $this->_single); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contribute/search', $urlParams); $breadCrumb = array(array('url' => $url, 'title' => ts('Search Results'))); CRM_Utils_System::appendBreadCrumb($breadCrumb); $this->_selectedOutput = CRM_Utils_Request::retrieve('select', 'String', $this); $this->assign('selectedOutput', $this->_selectedOutput); if ($this->_selectedOutput == 'email') { CRM_Utils_System::setTitle(ts('Email Invoice')); } else { CRM_Utils_System::setTitle(ts('Print Contribution Invoice')); } }
static function preProcessCommon(&$form, $useTable = false) { $form->_contactIds = array(); $form->_contactTypes = array(); // get the submitted values of the search form // we'll need to get fv from either search or adv search in the future $fragment = 'search'; if ($form->_action == CRM_Core_Action::ADVANCED) { $values = $form->controller->exportValues('Advanced'); $fragment .= '/advanced'; } else { if ($form->_action == CRM_Core_Action::PROFILE) { $values = $form->controller->exportValues('Builder'); $fragment .= '/builder'; } else { if ($form->_action == CRM_Core_Action::COPY) { $values = $form->controller->exportValues('Custom'); $fragment .= '/custom'; } else { $values = $form->controller->exportValues('Basic'); } } } //set the user context for redirection of task actions $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); require_once 'CRM/Utils/Rule.php'; $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); require_once 'CRM/Contact/Task.php'; $form->_task = CRM_Utils_Array::value('task', $values); $crmContactTaskTasks = CRM_Contact_Task::taskTitles(); $form->assign('taskName', CRM_Utils_Array::value($form->_task, $crmContactTaskTasks)); if ($useTable) { $form->_componentTable = CRM_Core_DAO::createTempTableName('civicrm_task_action', false); $sql = " DROP TABLE IF EXISTS {$form->_componentTable}"; CRM_Core_DAO::executeQuery($sql); $sql = "CREATE TABLE {$form->_componentTable} ( contact_id int primary key) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; CRM_Core_DAO::executeQuery($sql); } // all contacts or action = save a search if (CRM_Utils_Array::value('radio_ts', $values) == 'ts_all' || $form->_task == CRM_Contact_Task::SAVE_SEARCH) { // need to perform action on all contacts // fire the query again and get the contact id's + display name $sortID = null; if ($form->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($form->get(CRM_Utils_Sort::SORT_ID), $form->get(CRM_Utils_Sort::SORT_DIRECTION)); } $selectorName = $form->controller->selectorName(); require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php'; $fv = $form->get('formValues'); $customClass = $form->get('customSearchClass'); require_once "CRM/Core/BAO/Mapping.php"; $returnProperties = CRM_Core_BAO_Mapping::returnProperties($values); eval('$selector = new ' . $selectorName . '( $customClass, $fv, null, $returnProperties ); '); $params = $form->get('queryParams'); // fix for CRM-5165 $sortByCharacter = $form->get('sortByCharacter'); if ($sortByCharacter && $sortByCharacter != 1) { $params[] = array('sortByCharacter', '=', $sortByCharacter, 0, 0); } $dao =& $selector->contactIDQuery($params, $form->_action, $sortID); $form->_contactIds = array(); if ($useTable) { $count = 0; $insertString = array(); while ($dao->fetch()) { $count++; $insertString[] = " ( {$dao->contact_id} ) "; if ($count % 200 == 0) { $string = implode(',', $insertString); $sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES {$string}"; CRM_Core_DAO::executeQuery($sql); $insertString = array(); } } if (!empty($insertString)) { $string = implode(',', $insertString); $sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES {$string}"; CRM_Core_DAO::executeQuery($sql); } $dao->free(); } else { // filter duplicates here // CRM-7058 // might be better to do this in the query, but that logic is a bit complex // and it decides when to use distinct based on input criteria, which needs // to be fixed and optimized. $alreadySeen = array(); while ($dao->fetch()) { if (!array_key_exists($dao->contact_id, $alreadySeen)) { $form->_contactIds[] = $dao->contact_id; $alreadySeen[$dao->contact_id] = 1; } } unset($alreadySeen); $dao->free(); } } else { if (CRM_Utils_Array::value('radio_ts', $values) == 'ts_sel') { // selected contacts only // need to perform action on only selected contacts $insertString = array(); foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $contactID = substr($name, CRM_Core_Form::CB_PREFIX_LEN); if ($useTable) { $insertString[] = " ( {$contactID} ) "; } else { $form->_contactIds[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } if (!empty($insertString)) { $string = implode(',', $insertString); $sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES {$string}"; CRM_Core_DAO::executeQuery($sql); } } } //contact type for pick up profiles as per selected contact types with subtypes //CRM-5521 if ($selectedTypes = CRM_Utils_Array::value('contact_type', $values)) { if (!is_array($selectedTypes)) { $selectedTypes = explode(" ", $selectedTypes); } foreach ($selectedTypes as $ct => $dontcare) { if (strpos($ct, CRM_Core_DAO::VALUE_SEPARATOR) === false) { $form->_contactTypes[] = $ct; } else { $separator = strpos($ct, CRM_Core_DAO::VALUE_SEPARATOR); $form->_contactTypes[] = substr($ct, $separator + 1); } } } if (!empty($form->_contactIds)) { $form->_componentClause = ' contact_a.id IN ( ' . implode(',', $form->_contactIds) . ' ) '; $form->assign('totalSelectedContacts', count($form->_contactIds)); $form->_componentIds = $form->_contactIds; } }