Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * 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');
     }
 }
Exemplo n.º 5
0
 /**
  * This method is called for processing a submitted search form.
  */
 public function postProcess()
 {
     $this->set('isAdvanced', '0');
     $this->set('isSearchBuilder', '0');
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
     }
     if (isset($this->_groupID) && empty($this->_formValues['group'])) {
         $this->_formValues['group'] = $this->_groupID;
     } elseif (isset($this->_ssID) && empty($_POST)) {
         // if we are editing / running a saved search and the form has not been posted
         $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
         //fix for CRM-1505
         if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) {
             $this->_params = CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID);
         }
     }
     // we dont want to store the sortByCharacter in the formValue, it is more like
     // a filter on the result set
     // this filter is reset if we click on the search button
     if ($this->_sortByCharacter !== NULL && empty($_POST)) {
         if (strtolower($this->_sortByCharacter) == 'all') {
             $this->_formValues['sortByCharacter'] = NULL;
         } else {
             $this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
         }
     } else {
         $this->_sortByCharacter = NULL;
     }
     $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $this->_returnProperties =& $this->returnProperties();
     parent::postProcess();
 }
Exemplo n.º 6
0
 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);
     }
 }
Exemplo n.º 7
0
 /**
  * define the set of valid contexts that the search form operates on
  *
  * @return array the valid context set and the titles
  * @access protected
  * @static
  */
 static function &validContext()
 {
     if (!self::$_validContext) {
         self::$_validContext = array('search' => 'Search', 'smog' => 'Show members of group', 'amtg' => 'Add members to group');
     }
     return self::$_validContext;
 }
Exemplo n.º 8
0
 /**
  * Process the uploaded file
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $this->set('isAdvanced', '2');
     $this->set('isSearchBuilder', '1');
     $this->set('showSearchForm', FALSE);
     $params = $this->controller->exportValues($this->_name);
     if (!empty($params)) {
         // Add another block
         if (!empty($params['addBlock'])) {
             $this->set('newBlock', $this->_blockCount);
             $this->_blockCount += 3;
             $this->set('blockCount', $this->_blockCount);
             $this->set('showSearchForm', TRUE);
             return;
         }
         // Add another field
         $addMore = CRM_Utils_Array::value('addMore', $params);
         for ($x = 1; $x <= $this->_blockCount; $x++) {
             if (!empty($addMore[$x])) {
                 $this->set('newBlock', $x);
                 $this->_columnCount[$x] = $this->_columnCount[$x] + 5;
                 $this->set('columnCount', $this->_columnCount);
                 $this->set('showSearchForm', TRUE);
                 return;
             }
         }
         $this->set('newBlock', NULL);
         $checkEmpty = NULL;
         foreach ($params['mapper'] as $key => $value) {
             foreach ($value as $k => $v) {
                 if ($v[0]) {
                     $checkEmpty++;
                 }
             }
         }
         if (!$checkEmpty) {
             $this->set('newBlock', 1);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/search/builder', '_qf_Builder_display=true'));
         }
     }
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         // set the group if group is submitted
         if (CRM_Utils_Array::value('uf_group_id', $this->_formValues)) {
             $this->set('id', $this->_formValues['uf_group_id']);
         } else {
             $this->set('id', '');
         }
     }
     // we dont want to store the sortByCharacter in the formValue, it is more like
     // a filter on the result set
     // this filter is reset if we click on the search button
     if ($this->_sortByCharacter !== NULL && empty($_POST)) {
         if (strtolower($this->_sortByCharacter) == 'all') {
             $this->_formValues['sortByCharacter'] = NULL;
         } else {
             $this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
         }
     } else {
         $this->_sortByCharacter = NULL;
     }
     $this->_params =& $this->convertFormValues($this->_formValues);
     $this->_returnProperties =& $this->returnProperties();
     // CRM-10338 check if value is empty array
     foreach ($this->_params as $k => $v) {
         $this->_params[$k][2] = self::checkArrayKeyEmpty($v[2]);
     }
     parent::postProcess();
 }
Exemplo n.º 9
0
 /**
  * Determine the form name based on the action. This allows us
  * to avoid using  conditional state machine, much more efficient
  * and simpler
  *
  * @param CRM_Core_Controller $controller the controller object
  *
  * @return string the name of the form that will handle the task
  * @access protected
  */
 function taskName($controller, $formName = 'Search')
 {
     // total hack, check POST vars and then session to determine stuff
     // fix value if print button is pressed
     if (CRM_Utils_Array::value('_qf_' . $formName . '_next_print', $_POST)) {
         $value = CRM_Contact_Task::PRINT_CONTACTS;
     } else {
         $value = CRM_Utils_Array::value('task', $_POST);
     }
     if (!isset($value)) {
         $value = $this->_controller->get('task');
     }
     $this->_controller->set('task', $value);
     if ($value) {
         $componentMode = $this->_controller->get('component_mode');
         require_once 'CRM/Contact/Form/Search.php';
         $modeValue = CRM_Contact_Form_Search::getModeValue($componentMode);
         require_once str_replace('_', DIRECTORY_SEPARATOR, $modeValue['taskClassName']) . '.php';
         return eval("return {$modeValue['taskClassName']}::getTask( {$value} );");
     } else {
         return CRM_Contact_Task::getTask($value);
     }
 }
Exemplo n.º 10
0
 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);
     }
 }
Exemplo n.º 11
0
 static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         $contact_type = array();
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             $form->add('select', 'group', ts('Groups'), $form->_group, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE, TRUE);
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'source'));
     //added job title
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
     //added internal ID
     $attributes['id']['size'] = 30;
     $form->addElement('text', 'id', ts('Contact ID'), $attributes['id'], 'size="30"');
     //added external ID
     $attributes['external_identifier']['size'] = 30;
     $form->addElement('text', 'external_identifier', ts('External ID'), $attributes['external_identifier'], 'size="30"');
     $config = CRM_Core_Config::singleton();
     if (CRM_Core_Permission::check('access deleted contacts') and $config->contactUndelete) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'));
     // tag all search
     $form->add('text', 'tag_search', ts('All Tags'));
     // add search profiles
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->addElement('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles);
     $componentModes = CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::access('CiviMember')) {
         unset($componentModes['5']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->addElement('select', 'component_mode', ts('Display Results As'), $componentModes);
     }
     $form->addElement('select', 'operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')));
     // add the option to display relationships
     $rTypes = CRM_Core_PseudoConstant::relationshipType();
     $rSelect = array('' => ts('- Select Relationship Type-'));
     foreach ($rTypes as $rid => $rValue) {
         if ($rValue['label_a_b'] == $rValue['label_b_a']) {
             $rSelect[$rid] = $rValue['label_a_b'];
         } else {
             $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
             $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
         }
     }
     $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect);
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'title' => ts('- select -')));
     $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND')));
     $toggleChoice = array();
     $toggleChoice[] = $form->createElement('radio', NULL, '', ' ' . ts('Exclude'), '1');
     $toggleChoice[] = $form->createElement('radio', NULL, '', ' ' . ts('Include by Privacy Option(s)'), '2');
     $form->addGroup($toggleChoice, 'privacy_toggle', 'Privacy Options');
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::pcm();
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
     }
     $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, ts(''));
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $langPreff = CRM_Core_PseudoConstant::languages();
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select language -')) + $langPreff);
 }
Exemplo n.º 12
0
 /**
  * Generate the custom Data Fields based for those with is_searchable = 1.
  *
  * @param CRM_Contact_Form_Search $form
  */
 public static function custom(&$form)
 {
     $form->add('hidden', 'hidden_custom', 1);
     $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes());
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
     $form->assign('groupTree', $groupDetails);
     foreach ($groupDetails as $key => $group) {
         $_groupTitle[$key] = $group['name'];
         CRM_Core_ShowHideBlocks::links($form, $group['name'], '', '');
         foreach ($group['fields'] as $field) {
             $fieldId = $field['id'];
             $elementName = 'custom_' . $fieldId;
             if ($field['data_type'] == 'Date' && $field['is_search_range']) {
                 CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE);
             } else {
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
             }
         }
     }
 }
Exemplo n.º 13
0
 /**
  * The post processing of the form gets done here.
  *
  * Key things done during post processing are
  *      - check for reset or next request. if present, skip post procesing.
  *      - now check if user requested running a saved search, if so, then
  *        the form values associated with the saved search are used for searching.
  *      - if user has done a submit with new values the regular post submissing is 
  *        done.
  * The processing consists of using a Selector / Controller framework for getting the
  * search results.
  *
  * @param
  *
  * @return void 
  * @access public
  */
 function postProcess()
 {
     $session =& CRM_Core_Session::singleton();
     $session->set('isAdvanced', '1');
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         // FIXME: couldn't figure out a good place to do this,
         // FIXME: so leaving this as a dependency for now
         if (array_key_exists('contribution_amount_low', $this->_formValues)) {
             foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) {
                 $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]);
             }
         }
         //assigning event values for autocomplete event selection
         $eventSearchIds = array('event_id' => 'event_name_id', 'event_type' => 'event_type_id', 'participant_fee_level' => 'participant_fee_id');
         foreach ($eventSearchIds as $key => $value) {
             $this->_formValues[$key] = empty($this->_formValues[$key]) ? '' : $this->_formValues[$value];
             $this->_formValues[$value] = '';
         }
         // set the group if group is submitted
         if ($this->_formValues['uf_group_id']) {
             $this->set('id', $this->_formValues['uf_group_id']);
         } else {
             $this->set('id', '');
         }
     }
     // retrieve ssID values only if formValues is null, i.e. form has never been posted
     if (empty($this->_formValues) && isset($this->_ssID)) {
         $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
     }
     if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) {
         $this->_formValues['group'] = array($this->_groupID => 1);
     }
     //search for civicase
     if (is_array($this->_formValues)) {
         if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner'] && !$this->_force) {
             $this->_formValues['case_owner'] = 0;
         } else {
             if (array_key_exists('case_owner', $this->_formValues)) {
                 $this->_formValues['case_owner'] = 1;
             }
         }
     }
     // we dont want to store the sortByCharacter in the formValue, it is more like
     // a filter on the result set
     // this filter is reset if we click on the search button
     if ($this->_sortByCharacter && empty($_POST)) {
         if ($this->_sortByCharacter == 1) {
             $this->_formValues['sortByCharacter'] = null;
         } else {
             $this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
         }
     }
     require_once 'CRM/Core/BAO/CustomValue.php';
     CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
     require_once 'CRM/Contact/BAO/Query.php';
     $this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $this->_returnProperties =& $this->returnProperties();
     parent::postProcess();
 }
Exemplo n.º 14
0
 /**
  * processing needed for buildForm and later
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     /**
      * set the varios class variables
      */
     $this->_group =& CRM_Core_PseudoConstant::group();
     $this->_tag =& CRM_Core_PseudoConstant::tag();
     $this->_done = false;
     /**
      * set the button names
      */
     $this->_searchButtonName = $this->getButtonName('refresh');
     $this->_exportButtonName = $this->getButtonName('refresh', 'export');
     $this->_printButtonName = $this->getButtonName('next', 'print');
     $this->_actionButtonName = $this->getButtonName('next', 'action');
     /*
      * we allow the controller to set force/reset externally, useful when we are being
      * driven by the wizard framework
      */
     $nullObject = null;
     $this->_reset = CRM_Utils_Request::retrieve('reset', $nullObject);
     $this->_force = CRM_Utils_Request::retrieve('force', $this, false);
     // we only force stuff once :)
     $this->set('force', false);
     $this->_groupID = CRM_Utils_Request::retrieve('gid', $this);
     $this->_amtgID = CRM_Utils_Request::retrieve('amtgID', $this);
     $this->_ssID = CRM_Utils_Request::retrieve('ssID', $this);
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', $this);
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         $this->normalizeFormValues();
         // CRM_Core_Error::debug( 'fv', $this->_formValues );
         // also reset the sort by character
         $this->_sortByCharacter = null;
         $this->set('sortByCharacter', null);
     } else {
         $this->_formValues = $this->get('formValues');
     }
     // we only retrieve the saved search values if out current values are null
     if (empty($this->_formValues) && isset($this->_ssID)) {
         $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
     }
     /*
      * assign context to drive the template display, make sure context is valid
      */
     $this->_context = CRM_Utils_Request::retrieve('context', $this, false, 'search');
     if (!CRM_Utils_Array::value($this->_context, CRM_Contact_Form_Search::validContext())) {
         $this->_context = 'search';
         $this->set('context', $this->_context);
     }
     $this->assign('context', $this->_context);
     $selector =& new CRM_Contact_Selector($this->_formValues, $this->_action);
     $controller =& new CRM_Contact_Selector_Controller($selector, $this->get(CRM_UTILS_PAGER_PAGE_ID), $this->get(CRM_UTILS_SORT_SORT_ID), CRM_CORE_ACTION_VIEW, $this, CRM_CORE_SELECTOR_CONTROLLER_TRANSFER);
     $controller->setEmbedded(true);
     if ($this->_force) {
         $this->postProcess();
         /*
          * Note that we repeat this, since the search creates and stores
          * values that potentially change the controller behavior. i.e. things
          * like totalCount etc
          */
         $sortID = null;
         if ($this->get(CRM_UTILS_SORT_SORT_ID)) {
             $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_UTILS_SORT_SORT_ID), $this->get(CRM_UTILS_SORT_SORT_DIRECTION));
         }
         $controller =& new CRM_Contact_Selector_Controller($selector, $this->get(CRM_UTILS_PAGER_PAGE_ID), $sortID, CRM_CORE_ACTION_VIEW, $this, CRM_CORE_SELECTOR_CONTROLLER_TRANSFER);
         $controller->setEmbedded(true);
     }
     $controller->moveFromSessionToTemplate();
 }
Exemplo n.º 15
0
 /**
  * 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 );");
     }
 }
Exemplo n.º 16
0
 function setModeValues()
 {
     if (!self::$_modeValues) {
         self::$_modeValues = array(1 => array('selectorName' => property_exists($this, '_selectorName') && $this->_selectorName ? $this->_selectorName : 'CRM_Contact_Selector', 'selectorLabel' => ts('Contacts'), 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl', 'taskContext' => NULL, 'resultFile' => 'CRM/Contact/Form/Selector.tpl', 'resultContext' => NULL, 'taskClassName' => 'CRM_Contact_Task'), 2 => array('selectorName' => 'CRM_Contribute_Selector_Search', 'selectorLabel' => ts('Contributions'), 'taskFile' => 'CRM/common/searchResultTasks.tpl', 'taskContext' => 'Contribution', 'resultFile' => 'CRM/Contribute/Form/Selector.tpl', 'resultContext' => 'Search', 'taskClassName' => 'CRM_Contribute_Task'), 3 => array('selectorName' => 'CRM_Event_Selector_Search', 'selectorLabel' => ts('Event Participants'), 'taskFile' => 'CRM/common/searchResultTasks.tpl', 'taskContext' => NULL, 'resultFile' => 'CRM/Event/Form/Selector.tpl', 'resultContext' => 'Search', 'taskClassName' => 'CRM_Event_Task'), 4 => array('selectorName' => 'CRM_Activity_Selector_Search', 'selectorLabel' => ts('Activities'), 'taskFile' => 'CRM/common/searchResultTasks.tpl', 'taskContext' => NULL, 'resultFile' => 'CRM/Activity/Form/Selector.tpl', 'resultContext' => 'Search', 'taskClassName' => 'CRM_Activity_Task'), 5 => array('selectorName' => 'CRM_Member_Selector_Search', 'selectorLabel' => ts('Memberships'), 'taskFile' => "CRM/common/searchResultTasks.tpl", 'taskContext' => NULL, 'resultFile' => 'CRM/Member/Form/Selector.tpl', 'resultContext' => 'Search', 'taskClassName' => 'CRM_Member_Task'), 6 => array('selectorName' => 'CRM_Case_Selector_Search', 'selectorLabel' => ts('Cases'), 'taskFile' => "CRM/common/searchResultTasks.tpl", 'taskContext' => NULL, 'resultFile' => 'CRM/Case/Form/Selector.tpl', 'resultContext' => 'Search', 'taskClassName' => 'CRM_Case_Task'), 7 => array('selectorName' => property_exists($this, '_selectorName') && $this->_selectorName ? $this->_selectorName : 'CRM_Contact_Selector', 'selectorLabel' => ts('Related Contacts'), 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl', 'taskContext' => NULL, 'resultFile' => 'CRM/Contact/Form/Selector.tpl', 'resultContext' => NULL, 'taskClassName' => 'CRM_Contact_Task'));
     }
 }
Exemplo n.º 17
0
 /**
  * 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'));
 }
Exemplo n.º 18
0
 /**
  * Process the uploaded file
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $session =& CRM_Core_Session::singleton();
     $session->set('isAdvanced', '2');
     $session->set('isSearchBuilder', '1');
     $params = $this->controller->exportValues($this->_name);
     if (!empty($params)) {
         if (CRM_Utils_Array::value('addBlock', $params)) {
             $this->_blockCount = $this->_blockCount + 1;
             $this->set('blockCount', $this->_blockCount);
             return;
         }
         for ($x = 1; $x <= $this->_blockCount; $x++) {
             if (CRM_Utils_Array::value($x, $params['addMore'])) {
                 $this->_columnCount[$x] = $this->_columnCount[$x] + 1;
                 $this->set('columnCount', $this->_columnCount);
                 return;
             }
         }
         $checkEmpty = null;
         foreach ($params['mapper'] as $key => $value) {
             foreach ($value as $k => $v) {
                 if ($v[0]) {
                     $checkEmpty++;
                 }
             }
         }
         if (!$checkEmpty) {
             require_once 'CRM/Utils/System.php';
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/search/builder', '_qf_Builder_display=true'));
         }
     }
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         // set the group if group is submitted
         if (CRM_Utils_Array::value('uf_group_id', $this->_formValues)) {
             $this->set('id', $this->_formValues['uf_group_id']);
         } else {
             $this->set('id', '');
         }
     }
     // we dont want to store the sortByCharacter in the formValue, it is more like
     // a filter on the result set
     // this filter is reset if we click on the search button
     if ($this->_sortByCharacter && empty($_POST)) {
         if ($this->_sortByCharacter == 1) {
             $this->_formValues['sortByCharacter'] = null;
         } else {
             $this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
         }
     }
     $this->_params =& $this->convertFormValues($this->_formValues);
     $this->_returnProperties =& $this->returnProperties();
     parent::postProcess();
 }
Exemplo n.º 19
0
 /**
  * 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'));
 }
Exemplo n.º 20
0
 function postProcess()
 {
     $session =& CRM_Core_Session::singleton();
     $session->set('isAdvanced', '3');
     $session->set('isCustom', '1');
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         $this->_formValues['customSearchID'] = $this->_customSearchID;
         $this->_formValues['customSearchClass'] = $this->_customSearchClass;
     }
     parent::postProcess();
 }
Exemplo n.º 21
0
 /**
  * The post processing of the form gets done here.
  *
  * Key things done during post processing are
  *      - check for reset or next request. if present, skip post procesing.
  *      - now check if user requested running a saved search, if so, then
  *        the form values associated with the saved search are used for searching.
  *      - if user has done a submit with new values the regular post submissing is
  *        done.
  * The processing consists of using a Selector / Controller framework for getting the
  * search results.
  *
  * @param
  *
  * @return void
  * @access public
  */
 function postProcess()
 {
     $this->set('isAdvanced', '1');
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         $this->normalizeFormValues();
         // FIXME: couldn't figure out a good place to do this,
         // FIXME: so leaving this as a dependency for now
         if (array_key_exists('contribution_amount_low', $this->_formValues)) {
             foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) {
                 $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]);
             }
         }
         // set the group if group is submitted
         if (!empty($this->_formValues['uf_group_id'])) {
             $this->set('id', $this->_formValues['uf_group_id']);
         } else {
             $this->set('id', '');
         }
     }
     // retrieve ssID values only if formValues is null, i.e. form has never been posted
     if (empty($this->_formValues) && isset($this->_ssID)) {
         $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
     }
     if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) {
         $this->_formValues['group'] = array($this->_groupID => 1);
     }
     //search for civicase
     if (is_array($this->_formValues)) {
         $allCases = FALSE;
         if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner'] && !$this->_force) {
             foreach (array('case_type_id', 'case_status_id', 'case_deleted', 'case_tags') as $caseCriteria) {
                 if (CRM_Utils_Array::value($caseCriteria, $this->_formValues)) {
                     $allCases = TRUE;
                     $this->_formValues['case_owner'] = 1;
                     continue;
                 }
             }
             if ($allCases) {
                 if (CRM_Core_Permission::check('access all cases and activities')) {
                     $this->_formValues['case_owner'] = 1;
                 } else {
                     $this->_formValues['case_owner'] = 2;
                 }
             } else {
                 $this->_formValues['case_owner'] = 0;
             }
         }
     }
     // we dont want to store the sortByCharacter in the formValue, it is more like
     // a filter on the result set
     // this filter is reset if we click on the search button
     if ($this->_sortByCharacter !== NULL && empty($_POST)) {
         if (strtolower($this->_sortByCharacter) == 'all') {
             $this->_formValues['sortByCharacter'] = NULL;
         } else {
             $this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
         }
     } else {
         $this->_sortByCharacter = NULL;
     }
     CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
     $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $this->_returnProperties =& $this->returnProperties();
     parent::postProcess();
 }
Exemplo n.º 22
0
 /**
  * @param CRM_Core_Form $form
  */
 public static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
         // this is loaded onto then replace with something like '__' & test
         $separator = CRM_Core_DAO::VALUE_SEPARATOR;
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator);
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
             $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '&nbsp;&nbsp;', TRUE);
             $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
             $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $form->add('hidden', 'group_search_selected', 'group');
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
         $used_for = CRM_Core_OptionGroup::values('tag_used_for');
         $tagsTypes = array();
         $showAllTagTypes = FALSE;
         foreach ($used_for as $key => $value) {
             //check tags for every type and find if there are any defined
             $tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL);
             // check if there are tags other than contact type, if no - keep checkbox hidden on adv search
             // we will hide searching contact by attachments tags until it will be implemented in core
             if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
                 //if tags exists then add type to display in adv search form help text
                 $tagsTypes[] = ts($value);
                 $showAllTagTypes = TRUE;
             }
         }
         $tagTypesText = implode(" or ", $tagsTypes);
         if ($showAllTagTypes) {
             $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText)));
             $form->add('hidden', 'tag_types_text', $tagTypesText);
         }
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
     //added job title
     $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
     //added internal ID
     $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id'));
     $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
     //added external ID
     $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
     if (CRM_Core_Permission::check('access deleted contacts') and CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL)) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'), TRUE);
     // tag all search
     $form->add('text', 'tag_search', ts('All Tags'));
     // add search profiles
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->add('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles, FALSE, array('class' => 'crm-select2'));
     $componentModes = CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::access('CiviMember')) {
         unset($componentModes['5']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->add('select', 'component_mode', ts('Display Results As'), $componentModes, FALSE, array('class' => 'crm-select2'));
     }
     $form->addRadio('operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')), array('allowClear' => FALSE));
     // add the option to display relationships
     $rTypes = CRM_Core_PseudoConstant::relationshipType();
     $rSelect = array('' => ts('- Select Relationship Type-'));
     foreach ($rTypes as $rid => $rValue) {
         if ($rValue['label_a_b'] == $rValue['label_b_a']) {
             $rSelect[$rid] = $rValue['label_a_b'];
         } else {
             $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
             $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
         }
     }
     $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect, array('class' => 'crm-select2'));
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'class' => 'crm-select2'));
     $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND')));
     $options = array(1 => ts('Exclude'), 2 => ts('Include by Privacy Option(s)'));
     $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
     }
     $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, '');
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
     // Phone search
     $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType, FALSE, array('class' => 'crm-select2'));
     $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2'));
 }
Exemplo n.º 23
0
 /**
  * Determine the form name based on the action. This allows us
  * to avoid using  conditional state machine, much more efficient
  * and simpler
  *
  * @param CRM_Core_Controller $controller
  *   The controller object.
  *
  * @param string $formName
  *
  * @return string
  *   the name of the form that will handle the task
  */
 public function taskName($controller, $formName = 'Search')
 {
     // total hack, check POST vars and then session to determine stuff
     $value = CRM_Utils_Array::value('task', $_POST);
     if (!isset($value)) {
         $value = $this->_controller->get('task');
     }
     $this->_controller->set('task', $value);
     if ($value) {
         $componentMode = $this->_controller->get('component_mode');
         $modeValue = CRM_Contact_Form_Search::getModeValue($componentMode);
         $taskClassName = $modeValue['taskClassName'];
         return $taskClassName::getTask($value);
     } else {
         return CRM_Contact_Task::getTask($value);
     }
 }
Exemplo n.º 24
0
 /**
  * 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'));
 }
Exemplo n.º 25
0
 /**
  * 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;
 }
Exemplo n.º 26
0
 /**
  * Determine the form name based on the action. This allows us
  * to avoid using  conditional state machine, much more efficient
  * and simpler
  *
  * @param CRM_Core_Controller $controller the controller object
  *
  * @return string the name of the form that will handle the task
  * @access protected
  */
 function taskName($controller, $formName = 'Search')
 {
     // total hack, check POST vars and then session to determine stuff
     // fix value if print button is pressed
     if (CRM_Utils_Array::value('_qf_' . $formName . '_next_print', $_POST)) {
         $value = CRM_Contact_Task::PRINT_CONTACTS;
     } else {
         $value = CRM_Utils_Array::value('task', $_POST);
     }
     if (!isset($value)) {
         $value = $this->_controller->get('task');
     }
     $this->_controller->set('task', $value);
     if ($value) {
         $componentMode = $this->_controller->get('component_mode');
         $modeValue = CRM_Contact_Form_Search::getModeValue($componentMode);
         $taskClassName = $modeValue['taskClassName'];
         return $taskClassName::getTask($value);
     } else {
         return CRM_Contact_Task::getTask($value);
     }
 }
Exemplo n.º 27
0
 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);
         }
     }
 }
Exemplo n.º 28
0
 /**
  * this method is called for processing a submitted search form
  *
  * @return void
  * @access public
  */
 function postProcess()
 {
     $session =& CRM_Core_Session::singleton();
     $session->set('isAdvanced', '0');
     $session->set('isSearchBuilder', '0');
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         $this->normalizeFormValues();
     }
     if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) {
         $this->_formValues['group'][$this->_groupID] = 1;
     } else {
         if (isset($this->_ssID) && empty($_POST)) {
             // if we are editing / running a saved search and the form has not been posted
             $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
             //fix for CRM-1505
             if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) {
                 $this->_params =& CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID);
             }
         }
     }
     // we dont want to store the sortByCharacter in the formValue, it is more like
     // a filter on the result set
     // this filter is reset if we click on the search button
     if ($this->_sortByCharacter && empty($_POST)) {
         if ($this->_sortByCharacter == 1) {
             $this->_formValues['sortByCharacter'] = null;
         } else {
             $this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
         }
     }
     $this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $this->_returnProperties =& $this->returnProperties();
     // CRM_Core_Error::debug( 'f', $this->_formValues );
     // CRM_Core_Error::debug( 'p', $this->_params );
     parent::postProcess();
 }
Exemplo n.º 29
0
 /**
  * Processing needed for buildForm and later.
  */
 public function preProcess()
 {
     // set the various class variables
     $this->_group = CRM_Core_PseudoConstant::group();
     $this->_groupIterator = CRM_Core_PseudoConstant::groupIterator();
     $this->_tag = CRM_Core_BAO_Tag::getTags();
     $this->_done = FALSE;
     /*
      * we allow the controller to set force/reset externally, useful when we are being
      * driven by the wizard framework
      */
     $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject);
     $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject);
     $this->_groupID = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
     $this->_amtgID = CRM_Utils_Request::retrieve('amtgID', 'Positive', $this);
     $this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this);
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
     $this->_ufGroupID = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_componentMode = CRM_Utils_Request::retrieve('component_mode', 'Positive', $this, FALSE, 1, $_REQUEST);
     $this->_operator = CRM_Utils_Request::retrieve('operator', 'String', $this, FALSE, 1, $_REQUEST, 'AND');
     /**
      * set the button names
      */
     $this->_searchButtonName = $this->getButtonName('refresh');
     $this->_actionButtonName = $this->getButtonName('next', 'action');
     $this->assign('actionButtonName', $this->_actionButtonName);
     // reset from session, CRM-3526
     $session = CRM_Core_Session::singleton();
     if ($this->_force && $session->get('selectedSearchContactIds')) {
         $session->resetScope('selectedSearchContactIds');
     }
     // if we dont get this from the url, use default if one exsts
     $config = CRM_Core_Config::singleton();
     if ($this->_ufGroupID == NULL && $config->defaultSearchProfileID != NULL) {
         $this->_ufGroupID = $config->defaultSearchProfileID;
     }
     // assign context to drive the template display, make sure context is valid
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
     if (!CRM_Utils_Array::value($this->_context, self::validContext())) {
         $this->_context = 'search';
     }
     $this->set('context', $this->_context);
     $this->assign('context', $this->_context);
     $this->_modeValue = self::getModeValue($this->_componentMode);
     $this->assign($this->_modeValue);
     $this->set('selectorName', self::$_selectorName);
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     // $this->controller->isModal( ) returns TRUE if page is
     // valid, i.e all the validations are TRUE
     if (!empty($_POST) && !$this->controller->isModal()) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         $this->normalizeFormValues();
         $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
         $this->_returnProperties =& $this->returnProperties();
         // also get the uf group id directly from the post value
         $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $_POST, $this->_ufGroupID);
         $this->_formValues['uf_group_id'] = $this->_ufGroupID;
         $this->set('id', $this->_ufGroupID);
         // also get the object mode directly from the post value
         $this->_componentMode = CRM_Utils_Array::value('component_mode', $_POST, $this->_componentMode);
         // also get the operator from the post value if set
         $this->_operator = CRM_Utils_Array::value('operator', $_POST, $this->_operator);
         $this->_formValues['operator'] = $this->_operator;
         $this->set('operator', $this->_operator);
     } else {
         $this->_formValues = $this->get('formValues');
         $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
         $this->_returnProperties =& $this->returnProperties();
         if (!empty($this->_ufGroupID)) {
             $this->set('id', $this->_ufGroupID);
         }
     }
     if (empty($this->_formValues)) {
         //check if group is a smart group (fix for CRM-1255)
         if ($this->_groupID) {
             if ($ssId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id')) {
                 $this->_ssID = $ssId;
             }
         }
         // fix for CRM-1907
         if (isset($this->_ssID) && $this->_context != 'smog') {
             // we only retrieve the saved search values if out current values are null
             $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
             //fix for CRM-1505
             if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) {
                 $this->_params = CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID);
             } else {
                 $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
             }
             $this->_returnProperties =& $this->returnProperties();
         } else {
             if (isset($this->_ufGroupID)) {
                 // also set the uf group id if not already present
                 $this->_formValues['uf_group_id'] = $this->_ufGroupID;
             }
             if (isset($this->_componentMode)) {
                 $this->_formValues['component_mode'] = $this->_componentMode;
             }
             if (isset($this->_operator)) {
                 $this->_formValues['operator'] = $this->_operator;
             }
             // FIXME: we should generalise in a way that components could inject url-filters
             // just like they build their own form elements
             foreach (array('mailing_id', 'mailing_delivery_status', 'mailing_open_status', 'mailing_click_status', 'mailing_reply_status', 'mailing_optout', 'mailing_forward', 'mailing_unsubscribe', 'mailing_date_low', 'mailing_date_high') as $mailingFilter) {
                 $type = 'String';
                 if ($mailingFilter == 'mailing_id' && ($filterVal = CRM_Utils_Request::retrieve('mailing_id', 'Positive', $this))) {
                     $this->_formValues[$mailingFilter] = array($filterVal);
                 } elseif ($filterVal = CRM_Utils_Request::retrieve($mailingFilter, $type, $this)) {
                     $this->_formValues[$mailingFilter] = $filterVal;
                 }
                 if ($filterVal) {
                     $this->_openedPanes['Mailings'] = 1;
                     $this->_formValues['hidden_CiviMail'] = 1;
                 }
             }
         }
     }
     $this->assign('id', CRM_Utils_Array::value('uf_group_id', $this->_formValues));
     $operator = CRM_Utils_Array::value('operator', $this->_formValues, 'AND');
     $this->set('queryOperator', $operator);
     if ($operator == 'OR') {
         $this->assign('operator', ts('OR'));
     } else {
         $this->assign('operator', ts('AND'));
     }
     // show the context menu only when we’re not searching for deleted contacts; CRM-5673
     if (empty($this->_formValues['deleted_contacts'])) {
         $menuItems = CRM_Contact_BAO_Contact::contextMenu();
         $primaryActions = CRM_Utils_Array::value('primaryActions', $menuItems, array());
         $this->_contextMenu = CRM_Utils_Array::value('moreActions', $menuItems, array());
         $this->assign('contextMenu', $primaryActions + $this->_contextMenu);
     }
     if (!isset($this->_componentMode)) {
         $this->_componentMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
     }
     $modeValues = self::getModeValue($this->_componentMode);
     self::$_selectorName = $this->_modeValue['selectorName'];
     $setDynamic = FALSE;
     if (strpos(self::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
         $selector = new self::$_selectorName($this->_customSearchClass, $this->_formValues, $this->_params, $this->_returnProperties, $this->_action, FALSE, TRUE, $this->_context, $this->_contextMenu);
         $setDynamic = TRUE;
     } else {
         $selector = new self::$_selectorName($this->_params, $this->_action, NULL, FALSE, NULL, "search", "advanced");
     }
     $selector->setKey($this->controller->_key);
     $controller = new CRM_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER);
     $controller->setEmbedded(TRUE);
     $controller->setDynamicAction($setDynamic);
     if ($this->_force) {
         $this->postProcess();
         /*
          * Note that we repeat this, since the search creates and stores
          * values that potentially change the controller behavior. i.e. things
          * like totalCount etc
          */
         $sortID = NULL;
         if ($this->get(CRM_Utils_Sort::SORT_ID)) {
             $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION));
         }
         $controller = new CRM_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER);
         $controller->setEmbedded(TRUE);
         $controller->setDynamicAction($setDynamic);
     }
     $controller->moveFromSessionToTemplate();
 }
Exemplo n.º 30
0
 function postProcess()
 {
     $this->set('isAdvanced', '3');
     $this->set('isCustom', '1');
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         $this->_formValues['customSearchID'] = $this->_customSearchID;
         $this->_formValues['customSearchClass'] = $this->_customSearchClass;
     }
     //use the custom selector
     self::$_selectorName = 'CRM_Contact_Selector_Custom';
     parent::postProcess();
 }