/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. */ public function preProcess() { $this->_unscheduled = $this->_archived = $archiveLinks = FALSE; $this->_mailingId = CRM_Utils_Request::retrieve('mid', 'Positive', $this); $this->_sms = CRM_Utils_Request::retrieve('sms', 'Positive', $this); $this->assign('sms', $this->_sms); // check that the user has permission to access mailing id CRM_Mailing_BAO_Mailing::checkPermission($this->_mailingId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); $this->assign('action', $this->_action); $showLinks = TRUE; if (CRM_Mailing_Info::workflowEnabled()) { if (CRM_Core_Permission::check('create mailings')) { $archiveLinks = TRUE; } if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings')) { $showLinks = FALSE; } } $this->assign('showLinks', $showLinks); if (CRM_Core_Permission::check('access CiviMail')) { $archiveLinks = TRUE; } if ($archiveLinks == TRUE) { $this->assign('archiveLinks', $archiveLinks); } }
/** * Get AngularJS modules and their dependencies * * @return array * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules) * @see CRM_Utils_Hook::angularModules */ public function getAngularModules() { // load angular files only if valid permissions are granted to the user if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings') && !CRM_Core_Permission::check('schedule mailings') && !CRM_Core_Permission::check('approve mailings')) { return array(); } $result = array(); $result['crmMailing'] = array('ext' => 'civicrm', 'js' => array('ang/crmMailing.js', 'ang/crmMailing/*.js'), 'css' => array('ang/crmMailing.css'), 'partials' => array('ang/crmMailing')); $result['crmMailingAB'] = array('ext' => 'civicrm', 'js' => array('ang/crmMailingAB.js', 'ang/crmMailingAB/*.js', 'ang/crmMailingAB/*/*.js'), 'css' => array('ang/crmMailingAB.css'), 'partials' => array('ang/crmMailingAB')); $result['crmD3'] = array('ext' => 'civicrm', 'js' => array('ang/crmD3.js', 'bower_components/d3/d3.min.js')); $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); // Get past mailings // CRM-16155 - Limit to a reasonable number $civiMails = civicrm_api3('Mailing', 'get', array('is_completed' => 1, 'mailing_type' => array('IN' => array('standalone', 'winner')), 'return' => array('id', 'name', 'scheduled_date'), 'sequential' => 1, 'options' => array('limit' => 500, 'sort' => 'is_archived asc, scheduled_date desc'))); // Generic params $params = array('options' => array('limit' => 0), 'sequential' => 1); $groupNames = civicrm_api3('Group', 'get', $params + array('is_active' => 1, 'check_permissions' => TRUE, 'return' => array('title', 'visibility', 'group_type', 'is_hidden'))); $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array('is_active' => 1, 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'))); $emailAdd = civicrm_api3('Email', 'get', array('sequential' => 1, 'return' => "email", 'contact_id' => $contactID)); $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array('sequential' => 1, 'is_active' => 1, 'return' => array("id", "msg_title"), 'workflow_id' => array('IS NULL' => ""))); $mailTokens = civicrm_api3('Mailing', 'gettokens', array('entity' => array('contact', 'mailing'), 'sequential' => 1)); $fromAddress = civicrm_api3('OptionValue', 'get', $params + array('option_group_id' => "from_email_address", 'domain_id' => CRM_Core_Config::domainID())); CRM_Core_Resources::singleton()->addSetting(array('crmMailing' => array('civiMails' => $civiMails['values'], 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), 'groupNames' => $groupNames['values'], 'headerfooterList' => $headerfooterList['values'], 'mesTemplate' => $mesTemplate['values'], 'emailAdd' => $emailAdd['values'], 'mailTokens' => $mailTokens['values'], 'contactid' => $contactID, 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'), 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'), 'fromAddress' => $fromAddress['values'], 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array('id' => 'user_contact_id', 'return' => 'email')), 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()), 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled())))->addPermissions(array('view all contacts', 'access CiviMail', 'create mailings', 'schedule mailings', 'approve mailings', 'delete in CiviMail', 'edit message templates')); return $result; }
/** * Set variables up before form is built. */ public function preProcess() { if (CRM_Mailing_Info::workflowEnabled()) { if (!CRM_Core_Permission::check('approve mailings') && !CRM_Core_Permission::check('access CiviMail')) { $this->redirectToListing(); } } else { $this->redirectToListing(); } // when user come from search context. $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context')); //retrieve mid from different wizard and url contexts $this->_mailingID = $this->get('mailing_id'); $this->_approveFormOnly = FALSE; if (!$this->_mailingID) { $this->_mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, TRUE); $this->_approveFormOnly = TRUE; } $session = CRM_Core_Session::singleton(); $this->_contactID = $session->get('userID'); $this->_mailing = new CRM_Mailing_BAO_Mailing(); $this->_mailing->id = $this->_mailingID; if (!$this->_mailing->find(TRUE)) { $this->redirectToListing(); } }
/** * class constructor * * @param object CRM_Mailing_Controller * @param int $action * * @return object CRM_Mailing_StateMachine */ function __construct($controller, $action = CRM_Core_Action::NONE) { parent::__construct($controller, $action); $this->_pages = array('CRM_Mailing_Form_Group' => null, 'CRM_Mailing_Form_Settings' => null, 'CRM_Mailing_Form_Upload' => null, 'CRM_Mailing_Form_Test' => null); require_once 'CRM/Mailing/Info.php'; if (CRM_Mailing_Info::workflowEnabled()) { if (CRM_Core_Permission::check('schedule mailings')) { $this->_pages['CRM_Mailing_Form_Schedule'] = null; } } else { $this->_pages['CRM_Mailing_Form_Schedule'] = null; } $this->addSequentialPages($this->_pages, $action); }
/** * class constructor * * @param object CRM_Mailing_Controller * @param int $action * * @return object CRM_Mailing_StateMachine */ function __construct($controller, $action = CRM_Core_Action::NONE) { parent::__construct($controller, $action); $this->_pages = array('CRM_Mailing_Form_Group' => NULL, 'CRM_Mailing_Form_Settings' => NULL, 'CRM_Mailing_Form_Upload' => NULL, 'CRM_Mailing_Form_Test' => NULL); if (CRM_Mailing_Info::workflowEnabled()) { if (CRM_Core_Permission::check('schedule mailings')) { $this->_pages['CRM_Mailing_Form_Schedule'] = NULL; } if (CRM_Core_Permission::check('approve mailings')) { $this->_pages['CRM_Mailing_Form_Approve'] = NULL; } } else { $this->_pages['CRM_Mailing_Form_Schedule'] = NULL; } $this->addSequentialPages($this->_pages, $action); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { require_once 'CRM/Mailing/Info.php'; if (CRM_Mailing_Info::workflowEnabled()) { if (!CRM_Core_Permission::check('approve mailings')) { $this->redirectToListing(); } } else { $this->redirectToListing(); } $this->_mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, true); $session =& CRM_Core_Session::singleton(); $this->_contactID = $session->get('userID'); require_once 'CRM/Mailing/BAO/Mailing.php'; $this->_mailing = new CRM_Mailing_BAO_Mailing(); $this->_mailing->id = $this->_mailingID; if (!$this->_mailing->find(true)) { $this->redirectToListing(); } }
public static function initTasks() { if (!self::$_tasks) { self::$_tasks = array(self::GROUP_CONTACTS => array('title' => ts('Group - add contacts'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), self::REMOVE_CONTACTS => array('title' => ts('Group - remove contacts'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), self::TAG_CONTACTS => array('title' => ts('Tag - add to contacts'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), self::REMOVE_TAGS => array('title' => ts('Tag - remove from contacts'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), self::EXPORT_CONTACTS => array('title' => ts('Export contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), self::EMAIL_CONTACTS => array('title' => ts('Email - send now (to 50 or less)'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE), self::DELETE_CONTACTS => array('title' => ts('Delete contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::RECORD_CONTACTS => array('title' => ts('Add activity'), 'class' => 'CRM_Activity_Form_Activity'), self::SAVE_SEARCH => array('title' => ts('Smart group - create'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => TRUE), self::SAVE_SEARCH_UPDATE => array('title' => ts('Smart group - update'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => TRUE), self::PRINT_CONTACTS => array('title' => ts('Print selected rows'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => FALSE), self::LABEL_CONTACTS => array('title' => ts('Mailing labels - print'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => TRUE), self::BATCH_UPDATE => array('title' => ts('Batch update contacts via profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => TRUE), self::PRINT_FOR_CONTACTS => array('title' => ts('PDF letters - print'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => TRUE), self::EMAIL_UNHOLD => array('title' => ts('Email - unhold addresses'), 'class' => 'CRM_Contact_Form_Task_Unhold'), self::COMMUNICATION_PREFS => array('title' => ts('Communication preferences - alter'), 'class' => 'CRM_Contact_Form_Task_AlterPreferences'), self::RESTORE => array('title' => ts('Restore contacts from trash'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::DELETE_PERMANENTLY => array('title' => ts('Delete permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE)); //CRM-16329, if SMS provider is configured show sms action. $providersCount = CRM_SMS_BAO_Provider::activeProviderCount(); if ($providersCount) { self::$_tasks[self::SMS_CONTACTS] = array('title' => ts('SMS - schedule/send'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => TRUE); } if (CRM_Contact_BAO_ContactType::isActive('Household')) { $label = CRM_Contact_BAO_ContactType::getLabel('household'); self::$_tasks[self::HOUSEHOLD_CONTACTS] = array('title' => ts('Add relationship - to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold'); } if (CRM_Contact_BAO_ContactType::isActive('Organization')) { $label = CRM_Contact_BAO_ContactType::getLabel('organization'); self::$_tasks[self::ORGANIZATION_CONTACTS] = array('title' => ts('Add relationship - to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization'); } if (CRM_Core_Permission::check('merge duplicate contacts')) { self::$_tasks[self::MERGE_CONTACTS] = array('title' => ts('Merge contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE); } //CRM-4418, check for delete if (!CRM_Core_Permission::check('delete contacts')) { unset(self::$_tasks[self::DELETE_CONTACTS]); } //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider) // should fix this to be more flexible as providers are added ?? $config = CRM_Core_Config::singleton(); if ($config->mapProvider && ($config->mapProvider == 'Google' || ($config->mapProvider == 'OpenStreetMaps' || $config->geoProvider == 'Google'))) { self::$_tasks[self::MAP_CONTACTS] = array('title' => ts('Map contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => FALSE); } if (CRM_Core_Permission::access('CiviEvent')) { self::$_tasks[self::ADD_EVENT] = array('title' => ts('Register participants for event'), 'class' => 'CRM_Event_Form_Participant'); } if (CRM_Core_Permission::access('CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) { self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Email - schedule/send via CiviMail'), 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', 'result' => FALSE); } self::$_tasks += CRM_Core_Component::taskList(); CRM_Utils_Hook::searchTasks('contact', self::$_tasks); asort(self::$_tasks); } }
/** * Handle a create event. * * @param array $params * * @return array * API Success Array * @throws \API_Exception * @throws \Civi\API\Exception\UnauthorizedException */ function civicrm_api3_mailing_create($params) { if (CRM_Mailing_Info::workflowEnabled()) { // Note: 'schedule mailings' and 'approve mailings' can update certain fields, but can't create. if (empty($params['id'])) { if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings')) { throw new \Civi\API\Exception\UnauthorizedException("Cannot create new mailing. Required permission: 'access CiviMail' or 'create mailings'"); } } $safeParams = array(); $fieldPerms = CRM_Mailing_BAO_Mailing::getWorkflowFieldPerms(); foreach (array_keys($params) as $field) { if (CRM_Core_Permission::check($fieldPerms[$field])) { $safeParams[$field] = $params[$field]; } } } else { $safeParams = $params; } $safeParams['_evil_bao_validator_'] = 'CRM_Mailing_BAO_Mailing::checkSendable'; return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $safeParams); }
/** * Build the form object. */ public function buildQuickForm() { //create radio buttons to select existing group or add a new group $options = array(ts('Add Contact To Existing Group'), ts('Create New Group')); if (!$this->_id) { $this->addRadio('group_option', ts('Group Options'), $options, array('onclick' => "return showElements();")); $this->add('text', 'title', ts('Group Name:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title')); $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title')); $this->add('textarea', 'description', ts('Description:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')); $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE); if (!CRM_Core_Permission::access('CiviMail')) { $isWorkFlowEnabled = CRM_Mailing_Info::workflowEnabled(); if ($isWorkFlowEnabled && !CRM_Core_Permission::check('create mailings') && !CRM_Core_Permission::check('schedule mailings') && !CRM_Core_Permission::check('approve mailings')) { unset($groupTypes['Mailing List']); } } if (!empty($groupTypes)) { $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, NULL, NULL, NULL, NULL, ' '); } } // add select for groups $group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup(); $groupElement = $this->add('select', 'group_id', ts('Select Group'), $group, FALSE, array('class' => 'crm-select2 huge')); $this->_title = $group[$this->_id]; if ($this->_context === 'amtg') { $groupElement->freeze(); // also set the group title $groupValues = array('id' => $this->_id, 'title' => $this->_title); $this->assign_by_ref('group', $groupValues); } // Set dynamic page title for 'Add Members Group (confirm)' if ($this->_id) { CRM_Utils_System::setTitle(ts('Add Contacts: %1', array(1 => $this->_title))); } else { CRM_Utils_System::setTitle(ts('Add Contacts to A Group')); } $this->addDefaultButtons(ts('Add to Group')); }
public static function runJobs_pre($offset = 200) { $job = new CRM_Mailing_BAO_Job(); $config = CRM_Core_Config::singleton(); $jobTable = CRM_Mailing_DAO_Job::getTableName(); $mailingTable = CRM_Mailing_DAO_Mailing::getTableName(); $currentTime = date('YmdHis'); $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL('m'); // add an additional check and only process // jobs that are approved $workflowClause = null; require_once 'CRM/Mailing/Info.php'; if (CRM_Mailing_Info::workflowEnabled()) { require_once 'CRM/Core/OptionGroup.php'; $approveOptionID = CRM_Core_OptionGroup::getValue('mail_approval_status', 'Approved', 'name'); if ($approveOptionID) { $workflowClause = " AND m.approval_status_id = {$approveOptionID} "; } } // Select all the mailing jobs that are created from // when the mailing is submitted or scheduled. $query = "\n\t\tSELECT j.*\n\t\t FROM {$jobTable} j,\n\t\t\t\t {$mailingTable} m\n\t\t WHERE m.id = j.mailing_id\n {$workflowClause}\n\t\t AND j.is_test = 0\n\t\t AND ( ( j.start_date IS null\n\t\t AND j.scheduled_date <= {$currentTime}\n\t\t AND j.status = 'Scheduled'\n\t\t AND j.end_date IS null ) )\n\t\t AND ((j.job_type is NULL) OR (j.job_type <> 'child'))\n\t\tORDER BY j.scheduled_date,\n\t\t\t\t j.start_date"; $job->query($query); require_once 'CRM/Core/Lock.php'; // For reach of the "Parent Jobs" we find, we split them into // X Number of child jobs while ($job->fetch()) { // still use job level lock for each child job $lockName = "civimail.job.{$job->id}"; $lock = new CRM_Core_Lock($lockName); if (!$lock->isAcquired()) { continue; } // refetch the job status in case things // changed between the first query and now // avoid race conditions $job->status = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Job', $job->id, 'status'); if ($job->status != 'Scheduled') { $lock->release(); continue; } $job->split_job($offset); // update the status of the parent job require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $saveJob = new CRM_Mailing_DAO_Job(); $saveJob->id = $job->id; $saveJob->start_date = date('YmdHis'); $saveJob->status = 'Running'; $saveJob->save(); $transaction->commit(); // Release the job lock $lock->release(); } }
function upgrade_3_3_2($rev) { $dropMailingIndex = FALSE; $indexes = CRM_Core_DAO::executeQuery('SHOW INDEXES FROM civicrm_mailing_job'); while ($indexes->fetch()) { if ($indexes->Key_name == 'parent_id') { $dropMailingIndex = TRUE; break; } } //CRM-7137 // get membership type for each membership block. $sql = "SELECT id, membership_types FROM civicrm_membership_block "; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $memType = explode(',', $dao->membership_types); $memTypeSerialize = array(); foreach ($memType as $k => $v) { $memTypeSerialize[$v] = 0; } // save membership type as an serialized array along w/ auto_renew defalt value zero. $memBlock = new CRM_Member_DAO_MembershipBlock(); $memBlock->id = $dao->id; $memBlock->membership_types = serialize($memTypeSerialize); $memBlock->save(); } //CRM-7172 if (CRM_Mailing_Info::workflowEnabled()) { $config = CRM_Core_Config::singleton(); if (is_callable(array($config->userSystem, 'replacePermission'))) { $config->userSystem->replacePermission('access CiviMail', array('access CiviMail', 'create mailings', 'approve mailings', 'schedule mailings')); } } $upgrade = new CRM_Upgrade_Form(); $upgrade->assign('dropMailingIndex', $dropMailingIndex); $upgrade->processSQL($rev); }
/** * @param $ext * * @return bool */ public static function isExtensionSafe($ext) { static $extensions = NULL; if (!$extensions) { $extensions = CRM_Core_OptionGroup::values('safe_file_extension', TRUE); // make extensions to lowercase $extensions = array_change_key_case($extensions, CASE_LOWER); // allow html/htm extension ONLY if the user is admin // and/or has access CiviMail if (!(CRM_Core_Permission::check('access CiviMail') || CRM_Core_Permission::check('administer CiviCRM') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))) { unset($extensions['html']); unset($extensions['htm']); } } // support lower and uppercase file extensions return isset($extensions[strtolower($ext)]) ? TRUE : FALSE; }
static function isExtensionSafe($ext) { static $extensions = null; if (!$extensions) { require_once 'CRM/Core/OptionGroup.php'; $extensions = CRM_Core_OptionGroup::values('safe_file_extension', true); //make extensions to lowercase $extensions = array_change_key_case($extensions, CASE_LOWER); // allow html/htm extension ONLY if the user is admin // and/or has access CiviMail require_once 'CRM/Mailing/Info.php'; require_once 'CRM/Core/Permission.php'; if (!(CRM_Core_Permission::check('access CiviMail') || CRM_Core_Permission::check('administer CiviCRM') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))) { unset($extensions['html']); unset($extensions['htm']); } } //support lower and uppercase file extensions return isset($extensions[strtolower($ext)]) ? true : false; }
/** * Get the list Activities. * * @param array $input * Array of parameters. * Keys include * - contact_id int contact_id whose activities we want to retrieve * - offset int which row to start from ? * - rowCount int how many rows to fetch * - sort object|array object or array describing sort order for sql query. * - admin boolean if contact is admin * - caseId int case ID * - context string page on which selector is build * - activity_type_id int|string the activitiy types we want to restrict by * * @return array * Relevant data object values of open activities */ public static function &getActivities($input) { // Step 1: Get the basic activity data. $bulkActivityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $config = CRM_Core_Config::singleton(); $randomNum = md5(uniqid()); $activityTempTable = "civicrm_temp_activity_details_{$randomNum}"; $tableFields = array('activity_id' => 'int unsigned', 'activity_date_time' => 'datetime', 'source_record_id' => 'int unsigned', 'status_id' => 'int unsigned', 'subject' => 'varchar(255)', 'source_contact_name' => 'varchar(255)', 'activity_type_id' => 'int unsigned', 'activity_type' => 'varchar(128)', 'case_id' => 'int unsigned', 'case_subject' => 'varchar(255)', 'campaign_id' => 'int unsigned'); $sql = "CREATE TEMPORARY TABLE {$activityTempTable} ( "; $insertValueSQL = array(); // The activityTempTable contains the sorted rows // so in order to maintain the sort order as-is we add an auto_increment // field; we can sort by this later to ensure the sort order stays correct. $sql .= " fixed_sort_order INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,"; foreach ($tableFields as $name => $desc) { $sql .= "{$name} {$desc},\n"; $insertValueSQL[] = $name; } // add unique key on activity_id just to be sure // this cannot be primary key because we need that for the auto_increment // fixed_sort_order field $sql .= "\n UNIQUE KEY ( activity_id )\n ) ENGINE=HEAP DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci\n "; CRM_Core_DAO::executeQuery($sql); $insertSQL = "INSERT INTO {$activityTempTable} (" . implode(',', $insertValueSQL) . " ) "; $order = $limit = $groupBy = ''; $groupBy = " GROUP BY tbl.activity_id "; if (!empty($input['sort'])) { if (is_a($input['sort'], 'CRM_Utils_Sort')) { $orderBy = $input['sort']->orderBy(); if (!empty($orderBy)) { $order = " ORDER BY {$orderBy}"; } } elseif (trim($input['sort'])) { $sort = CRM_Utils_Type::escape($input['sort'], 'String'); $order = " ORDER BY {$sort} "; } } if (empty($order)) { // context = 'activity' in Activities tab. $order = CRM_Utils_Array::value('context', $input) == 'activity' ? " ORDER BY tbl.activity_date_time desc " : " ORDER BY tbl.status_id asc, tbl.activity_date_time asc "; } if (!empty($input['rowCount']) && $input['rowCount'] > 0) { $limit = " LIMIT {$input['offset']}, {$input['rowCount']} "; } $input['count'] = FALSE; list($sqlClause, $params) = self::getActivitySQLClause($input); $query = "{$insertSQL}\n SELECT DISTINCT tbl.* from ( {$sqlClause} )\nas tbl "; // Filter case activities - CRM-5761. $components = self::activityComponents(); if (!in_array('CiviCase', $components)) { $query .= "\nLEFT JOIN civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.activity_id )\n WHERE civicrm_case_activity.id IS NULL"; } $query = $query . $groupBy . $order . $limit; $dao = CRM_Core_DAO::executeQuery($query, $params); // step 2: Get target and assignee contacts for above activities // create temp table for target contacts $activityContactTempTable = "civicrm_temp_activity_contact_{$randomNum}"; $query = "CREATE TEMPORARY TABLE {$activityContactTempTable} (\n activity_id int unsigned, contact_id int unsigned, record_type_id varchar(16),\n contact_name varchar(255), is_deleted int unsigned, counter int unsigned, INDEX index_activity_id( activity_id ) )\n ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; CRM_Core_DAO::executeQuery($query); // note that we ignore bulk email for targets, since we don't show it in selector $query = "\nINSERT INTO {$activityContactTempTable} ( activity_id, contact_id, record_type_id, contact_name, is_deleted )\nSELECT ac.activity_id,\n ac.contact_id,\n ac.record_type_id,\n c.sort_name,\n c.is_deleted\nFROM {$activityTempTable}\nINNER JOIN civicrm_activity a ON ( a.id = {$activityTempTable}.activity_id )\nINNER JOIN civicrm_activity_contact ac ON ( ac.activity_id = {$activityTempTable}.activity_id )\nINNER JOIN civicrm_contact c ON c.id = ac.contact_id\nWHERE ac.record_type_id != %1\n"; $params = array(1 => array($targetID, 'Integer')); CRM_Core_DAO::executeQuery($query, $params); // for each activity insert one target contact // if we load all target contacts the performance will suffer a lot for mass-activities. $query = "\nINSERT INTO {$activityContactTempTable} ( activity_id, contact_id, record_type_id, contact_name, is_deleted, counter )\nSELECT ac.activity_id,\n ac.contact_id,\n ac.record_type_id,\n c.sort_name,\n c.is_deleted,\n count(ac.contact_id)\nFROM {$activityTempTable}\nINNER JOIN civicrm_activity a ON ( a.id = {$activityTempTable}.activity_id )\nINNER JOIN civicrm_activity_contact ac ON ( ac.activity_id = {$activityTempTable}.activity_id )\nINNER JOIN civicrm_contact c ON c.id = ac.contact_id\nWHERE ac.record_type_id = %1\nGROUP BY ac.activity_id\n"; CRM_Core_DAO::executeQuery($query, $params); // step 3: Combine all temp tables to get final query for activity selector // sort by the original sort order, stored in fixed_sort_order $query = "\nSELECT {$activityTempTable}.*,\n {$activityContactTempTable}.contact_id,\n {$activityContactTempTable}.record_type_id,\n {$activityContactTempTable}.contact_name,\n {$activityContactTempTable}.is_deleted,\n {$activityContactTempTable}.counter,\n re.parent_id as is_recurring_activity\nFROM {$activityTempTable}\nINNER JOIN {$activityContactTempTable} on {$activityTempTable}.activity_id = {$activityContactTempTable}.activity_id\nLEFT JOIN civicrm_recurring_entity re on {$activityContactTempTable}.activity_id = re.entity_id\nORDER BY fixed_sort_order\n "; $dao = CRM_Core_DAO::executeQuery($query); // CRM-3553, need to check user has access to target groups. $mailingIDs = CRM_Mailing_BAO_Mailing::mailingACLIDs(); $accessCiviMail = CRM_Core_Permission::check('access CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'); // Get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $values = array(); while ($dao->fetch()) { $activityID = $dao->activity_id; $values[$activityID]['activity_id'] = $dao->activity_id; $values[$activityID]['source_record_id'] = $dao->source_record_id; $values[$activityID]['activity_type_id'] = $dao->activity_type_id; $values[$activityID]['activity_type'] = $dao->activity_type; $values[$activityID]['activity_date_time'] = $dao->activity_date_time; $values[$activityID]['status_id'] = $dao->status_id; $values[$activityID]['subject'] = $dao->subject; $values[$activityID]['campaign_id'] = $dao->campaign_id; $values[$activityID]['is_recurring_activity'] = $dao->is_recurring_activity; if ($dao->campaign_id) { $values[$activityID]['campaign'] = $allCampaigns[$dao->campaign_id]; } if (empty($values[$activityID]['assignee_contact_name'])) { $values[$activityID]['assignee_contact_name'] = array(); } if (empty($values[$activityID]['target_contact_name'])) { $values[$activityID]['target_contact_name'] = array(); $values[$activityID]['target_contact_counter'] = $dao->counter; } // if deleted, wrap in <del> if ($dao->is_deleted) { $dao->contact_name = "<del>{$dao->contact_name}</del>"; } if ($dao->record_type_id == $sourceID && $dao->contact_id) { $values[$activityID]['source_contact_id'] = $dao->contact_id; $values[$activityID]['source_contact_name'] = $dao->contact_name; } if (!$bulkActivityTypeID || $bulkActivityTypeID != $dao->activity_type_id) { // build array of target / assignee names if ($dao->record_type_id == $targetID && $dao->contact_id) { $values[$activityID]['target_contact_name'][$dao->contact_id] = $dao->contact_name; } if ($dao->record_type_id == $assigneeID && $dao->contact_id) { $values[$activityID]['assignee_contact_name'][$dao->contact_id] = $dao->contact_name; } // case related fields $values[$activityID]['case_id'] = $dao->case_id; $values[$activityID]['case_subject'] = $dao->case_subject; } else { $values[$activityID]['recipients'] = ts('(%1 recipients)', array(1 => $dao->counter)); $values[$activityID]['mailingId'] = FALSE; if ($accessCiviMail && ($mailingIDs === TRUE || in_array($dao->source_record_id, $mailingIDs))) { $values[$activityID]['mailingId'] = TRUE; } } } return $values; }
/** * function to get the list Actvities * * @param array $input array of parameters * Keys include * - contact_id int contact_id whose activties we want to retrieve * - offset int which row to start from ? * - rowCount int how many rows to fetch * - sort object|array object or array describing sort order for sql query. * - admin boolean if contact is admin * - caseId int case ID * - context string page on which selector is build * - activity_type_id int|string the activitiy types we want to restrict by * * @return array (reference) $values the relevant data object values of open activitie * * @access public * @static */ static function &getActivities($input) { //step 1: Get the basic activity data $bulkActivityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name'); $config = CRM_Core_Config::singleton(); $randomNum = md5(uniqid()); $activityTempTable = "civicrm_temp_activity_details_{$randomNum}"; $tableFields = array('activity_id' => 'int unsigned', 'activity_date_time' => 'datetime', 'status_id' => 'int unsigned', 'subject' => 'varchar(255)', 'source_contact_id' => 'int unsigned', 'source_record_id' => 'int unsigned', 'source_contact_name' => 'varchar(255)', 'activity_type_id' => 'int unsigned', 'activity_type' => 'varchar(128)', 'case_id' => 'int unsigned', 'case_subject' => 'varchar(255)', 'campaign_id' => 'int unsigned'); $sql = "CREATE TEMPORARY TABLE {$activityTempTable} ( "; $insertValueSQL = array(); foreach ($tableFields as $name => $desc) { $sql .= "{$name} {$desc},\n"; $insertValueSQL[] = $name; } $sql .= "\n PRIMARY KEY ( activity_id )\n ) ENGINE=HEAP DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci\n "; CRM_Core_DAO::executeQuery($sql); $insertSQL = "INSERT INTO {$activityTempTable} (" . implode(',', $insertValueSQL) . " ) "; $order = $limit = $groupBy = ''; //$groupBy = " GROUP BY tbl.activity_id"; if (!empty($input['sort'])) { if (is_a($input['sort'], 'CRM_Utils_Sort')) { $orderBy = $input['sort']->orderBy(); if (!empty($orderBy)) { $order = " ORDER BY {$orderBy}"; } } elseif (trim($input['sort'])) { $order = " ORDER BY {$input['sort']}"; } } if (empty($order)) { $order = CRM_Utils_Array::value('context', $input) == 'activity' ? " ORDER BY tbl.activity_date_time desc " : " ORDER BY tbl.status_id asc, tbl.activity_date_time asc "; } if (!empty($input['rowCount']) && $input['rowCount'] > 0) { $limit = " LIMIT {$input['offset']}, {$input['rowCount']} "; } $input['count'] = FALSE; list($sqlClause, $params) = self::getActivitySQLClause($input); $query = "{$insertSQL}\n SELECT DISTINCT tbl.* from ( {$sqlClause} )\nas tbl "; //filter case activities - CRM-5761 $components = self::activityComponents(); if (!in_array('CiviCase', $components)) { $query .= "\nLEFT JOIN civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.activity_id )\n WHERE civicrm_case_activity.id IS NULL"; } $query = $query . $groupBy . $order . $limit; $dao = CRM_Core_DAO::executeQuery($query, $params); $notbulkActivityClause = ''; if ($bulkActivityTypeID) { $notbulkActivityClause = " AND {$activityTempTable}.activity_type_id <> {$bulkActivityTypeID} "; } // step 2: Get target and assignee contacts for above activities // create temp table for target contacts $activityTargetContactTempTable = "civicrm_temp_target_contact_{$randomNum}"; $query = "CREATE TEMPORARY TABLE {$activityTargetContactTempTable} (\n activity_id int unsigned, target_contact_id int unsigned, target_contact_name varchar(255) )\n ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; CRM_Core_DAO::executeQuery($query); // note that we ignore bulk email for targets, since we don't show it in selector $query = "INSERT INTO {$activityTargetContactTempTable} ( activity_id, target_contact_id, target_contact_name )\n SELECT at.activity_id,\n at.target_contact_id ,\n c.sort_name\n FROM civicrm_activity_target at\n INNER JOIN {$activityTempTable} ON ( at.activity_id = {$activityTempTable}.activity_id\n {$notbulkActivityClause} )\n INNER JOIN civicrm_contact c ON c.id = at.target_contact_id\n WHERE c.is_deleted = 0"; CRM_Core_DAO::executeQuery($query); // create temp table for assignee contacts $activityAssigneetContactTempTable = "civicrm_temp_assignee_contact_{$randomNum}"; $query = "CREATE TEMPORARY TABLE {$activityAssigneetContactTempTable} (\n activity_id int unsigned, assignee_contact_id int unsigned, assignee_contact_name varchar(255) )\n ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; CRM_Core_DAO::executeQuery($query); // note that we ignore bulk email for assignee, since we don't show it in selector $query = "INSERT INTO {$activityAssigneetContactTempTable} ( activity_id, assignee_contact_id, assignee_contact_name )\n SELECT DISTINCT ( aa.activity_id ) ,\n aa.assignee_contact_id,\n c.sort_name\n FROM civicrm_activity_assignment aa\n INNER JOIN {$activityTempTable} ON ( aa.activity_id = {$activityTempTable}.activity_id\n {$notbulkActivityClause} )\n INNER JOIN civicrm_contact c ON c.id = aa.assignee_contact_id\n WHERE c.is_deleted = 0"; CRM_Core_DAO::executeQuery($query); // step 3: Combine all temp tables to get final query for activity selector $query = "\n SELECT {$activityTempTable}.*,\n {$activityTargetContactTempTable}.target_contact_id,{$activityTargetContactTempTable}.target_contact_name,\n {$activityAssigneetContactTempTable}.assignee_contact_id, {$activityAssigneetContactTempTable}.assignee_contact_name\n FROM {$activityTempTable}\n LEFT JOIN {$activityTargetContactTempTable} on {$activityTempTable}.activity_id = {$activityTargetContactTempTable}.activity_id\n LEFT JOIN {$activityAssigneetContactTempTable} on {$activityTempTable}.activity_id = {$activityAssigneetContactTempTable}.activity_id\n "; $dao = CRM_Core_DAO::executeQuery($query); //CRM-3553, need to check user has access to target groups. $mailingIDs = CRM_Mailing_BAO_Mailing::mailingACLIDs(); $accessCiviMail = CRM_Core_Permission::check('access CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $values = array(); while ($dao->fetch()) { $activityID = $dao->activity_id; $values[$activityID]['activity_id'] = $dao->activity_id; $values[$activityID]['source_record_id'] = $dao->source_record_id; $values[$activityID]['activity_type_id'] = $dao->activity_type_id; $values[$activityID]['activity_type'] = $dao->activity_type; $values[$activityID]['activity_date_time'] = $dao->activity_date_time; $values[$activityID]['status_id'] = $dao->status_id; $values[$activityID]['subject'] = $dao->subject; $values[$activityID]['source_contact_name'] = $dao->source_contact_name; $values[$activityID]['source_contact_id'] = $dao->source_contact_id; $values[$activityID]['campaign_id'] = $dao->campaign_id; if ($dao->campaign_id) { $values[$activityID]['campaign'] = $allCampaigns[$dao->campaign_id]; } if (!CRM_Utils_Array::value('assignee_contact_name', $values[$activityID])) { $values[$activityID]['assignee_contact_name'] = array(); } if (!CRM_Utils_Array::value('target_contact_name', $values[$activityID])) { $values[$activityID]['target_contact_name'] = array(); } if (!$bulkActivityTypeID || $bulkActivityTypeID != $dao->activity_type_id) { // build array of target / assignee names if ($dao->target_contact_id) { $values[$activityID]['target_contact_name'][$dao->target_contact_id] = $dao->target_contact_name; } if ($dao->assignee_contact_id) { $values[$activityID]['assignee_contact_name'][$dao->assignee_contact_id] = $dao->assignee_contact_name; } // case related fields $values[$activityID]['case_id'] = $dao->case_id; $values[$activityID]['case_subject'] = $dao->case_subject; } else { $values[$activityID]['recipients'] = ts('(recipients)'); $values[$activityID]['mailingId'] = ''; if ($accessCiviMail && in_array($dao->source_record_id, $mailingIDs)) { $values[$activityID]['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$dao->source_record_id}&reset=1&cid={$dao->source_contact_id}&context=activitySelector"); } } } // add info on whether the related contacts are deleted (CRM-5673) // FIXME: ideally this should be tied to ACLs // grab all the related contact ids $cids = array(); foreach ($values as $value) { $cids[] = $value['source_contact_id']; } $cids = array_filter(array_unique($cids)); // see which of the cids are of deleted contacts if ($cids) { $sql = 'SELECT id FROM civicrm_contact WHERE id IN (' . implode(', ', $cids) . ') AND is_deleted = 1'; $dao = CRM_Core_DAO::executeQuery($sql); $dels = array(); while ($dao->fetch()) { $dels[] = $dao->id; } // hide the deleted contacts foreach ($values as &$value) { if (in_array($value['source_contact_id'], $dels)) { unset($value['source_contact_id'], $value['source_contact_name']); } } } return $values; }
/** * 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')); }
public static function initTasks() { if (!self::$_tasks) { self::$_tasks = array(self::GROUP_CONTACTS => array('title' => ts('Add Contacts to Group'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), self::REMOVE_CONTACTS => array('title' => ts('Remove Contacts from Group'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), self::TAG_CONTACTS => array('title' => ts('Tag Contacts (assign tags)'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), self::REMOVE_TAGS => array('title' => ts('Untag Contacts (remove tags)'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), self::EXPORT_CONTACTS => array('title' => ts('Export Contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), self::EMAIL_CONTACTS => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE), self::SMS_CONTACTS => array('title' => ts('Send SMS to Contacts'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => TRUE), self::DELETE_CONTACTS => array('title' => ts('Delete Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::RECORD_CONTACTS => array('title' => ts('Record Activity for Contacts'), 'class' => 'CRM_Activity_Form_Activity'), self::SAVE_SEARCH => array('title' => ts('New Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => TRUE), self::SAVE_SEARCH_UPDATE => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => TRUE), self::PRINT_CONTACTS => array('title' => ts('Print Selected Rows'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => FALSE), self::LABEL_CONTACTS => array('title' => ts('Mailing Labels'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => TRUE), self::BATCH_UPDATE => array('title' => ts('Batch Update via Profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => TRUE), self::PRINT_FOR_CONTACTS => array('title' => ts('Print PDF Letter for Contacts'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => TRUE), self::EMAIL_UNHOLD => array('title' => ts('Unhold Emails'), 'class' => 'CRM_Contact_Form_Task_Unhold'), self::COMMUNICATION_PREFS => array('title' => ts('Alter Contact Communication Preferences'), 'class' => 'CRM_Contact_Form_Task_AlterPreferences'), self::RESTORE => array('title' => ts('Restore Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::DELETE_PERMANENTLY => array('title' => ts('Delete Permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE)); if (CRM_Contact_BAO_ContactType::isActive('Household')) { $label = CRM_Contact_BAO_ContactType::getLabel('Household'); self::$_tasks[self::HOUSEHOLD_CONTACTS] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold'); } if (CRM_Contact_BAO_ContactType::isActive('Organization')) { $label = CRM_Contact_BAO_ContactType::getLabel('Organization'); self::$_tasks[self::ORGANIZATION_CONTACTS] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization'); } if (CRM_Core_Permission::check('merge duplicate contacts')) { self::$_tasks[self::MERGE_CONTACTS] = array('title' => ts('Merge Contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE); } //CRM-4418, check for delete if (!CRM_Core_Permission::check('delete contacts')) { unset(self::$_tasks[self::DELETE_CONTACTS]); } //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider) // should fix this to be more flexible as providers are added ?? $config = CRM_Core_Config::singleton(); if ($config->mapProvider && ($config->mapProvider == 'Google' || ($config->mapProvider == 'OpenStreetMaps' || $config->geoProvider == 'Google'))) { self::$_tasks[self::MAP_CONTACTS] = array('title' => ts('Map Contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => FALSE); } if (CRM_Core_Permission::access('CiviEvent')) { self::$_tasks[self::ADD_EVENT] = array('title' => ts('Add Contacts to Event'), 'class' => 'CRM_Event_Form_Participant'); } if (defined('CIVICRM_CIVIMAIL_UI_LEGACY')) { if (CRM_Core_Permission::access('CiviMail')) { self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test', 'CRM_Mailing_Form_Schedule'), 'result' => FALSE); } elseif (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) { self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Create a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test'), 'result' => FALSE); } } else { if (CRM_Core_Permission::access('CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) { self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', 'result' => FALSE); } } self::$_tasks += CRM_Core_Component::taskList(); CRM_Utils_Hook::searchTasks('contact', self::$_tasks); asort(self::$_tasks); } }
/** * Build the form object. * * It consists of * - displaying the QILL (query in local language) * - displaying elements for saving the search */ public function buildQuickForm() { // get the qill $query = new CRM_Contact_BAO_Query($this->get('queryParams')); $qill = $query->qill(); // Values from the search form $formValues = $this->controller->exportValues(); // need to save qill for the smarty template $this->assign('qill', $qill); // the name and description are actually stored with the group and not the saved search $this->add('text', 'title', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE); $this->addElement('textarea', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')); $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE); unset($groupTypes['Access Control']); if (!CRM_Core_Permission::access('CiviMail')) { $isWorkFlowEnabled = CRM_Mailing_Info::workflowEnabled(); if ($isWorkFlowEnabled && !CRM_Core_Permission::check('create mailings') && !CRM_Core_Permission::check('schedule mailings') && !CRM_Core_Permission::check('approve mailings')) { unset($groupTypes['Mailing List']); } } if (!empty($groupTypes)) { $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, NULL, NULL, NULL, NULL, ' '); } //CRM-14190 CRM_Group_Form_Edit::buildParentGroups($this); // get the group id for the saved search $groupID = NULL; if (isset($this->_id)) { $groupID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_id, 'id', 'saved_search_id'); $this->addDefaultButtons(ts('Update Smart Group')); } else { $this->addDefaultButtons(ts('Save Smart Group')); $this->assign('partiallySelected', $formValues['radio_ts'] != 'ts_all'); } $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $groupID, 'title')); }
static function initTasks() { if (!self::$_tasks) { self::$_tasks = array(1 => array('title' => ts('Add Contacts to Group'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), 2 => array('title' => ts('Remove Contacts from Group'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), 3 => array('title' => ts('Tag Contacts (assign tags)'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), 4 => array('title' => ts('Untag Contacts (remove tags)'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), 5 => array('title' => ts('Export Contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => false), 6 => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => true), 7 => array('title' => ts('Send SMS to Contacts'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => true), 8 => array('title' => ts('Delete Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => false), 11 => array('title' => ts('Record Activity for Contacts'), 'class' => 'CRM_Activity_Form_Activity'), 13 => array('title' => ts('New Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => true), 14 => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => true), 15 => array('title' => ts('Print Contacts'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => false), 16 => array('title' => ts('Mailing Labels'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => true), 17 => array('title' => ts('Batch Update via Profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => true), 19 => array('title' => ts('Print PDF Letter for Contacts'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => true), 22 => array('title' => ts('Unhold Emails'), 'class' => 'CRM_Contact_Form_Task_Unhold'), self::RESTORE => array('title' => ts('Restore Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => false), self::DELETE_PERMANENTLY => array('title' => ts('Delete Permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => false)); if (CRM_Contact_BAO_ContactType::isActive('Household')) { $label = CRM_Contact_BAO_ContactType::getLabel('Household'); self::$_tasks[9] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold'); } if (CRM_Contact_BAO_ContactType::isActive('Organization')) { $label = CRM_Contact_BAO_ContactType::getLabel('Organization'); self::$_tasks[10] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization'); } if (CRM_Core_Permission::check('merge duplicate contacts')) { self::$_tasks[21] = array('title' => ts('Merge Contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => true); } //CRM-4418, check for delete if (!CRM_Core_Permission::check('delete contacts')) { unset(self::$_tasks[8]); } //show map action only if map provider and key is set $config = CRM_Core_Config::singleton(); if ($config->mapProvider && $config->mapAPIKey) { self::$_tasks[12] = array('title' => ts('Map Contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => false); } if (CRM_Core_Permission::access('CiviEvent')) { self::$_tasks[18] = array('title' => ts('Add Contacts to Event'), 'class' => 'CRM_Event_Form_Participant'); } if (CRM_Core_Permission::access('CiviMail')) { self::$_tasks[20] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test', 'CRM_Mailing_Form_Schedule'), 'result' => false); } elseif (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) { self::$_tasks[20] = array('title' => ts('Create a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test'), 'result' => false); } self::$_tasks += CRM_Core_Component::taskList(); require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::searchTasks('contact', self::$_tasks); asort(self::$_tasks); } }
/** * 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; }
/** * Returns all the rows in the given offset and rowCount. * * @param string $action * The action being performed. * @param int $offset * The row number to start from. * @param int $rowCount * The number of rows to return. * @param string $sort * The sql string that describes the sort order. * @param string $output * What should the result set include (web/email/csv). * * @return int * the total number of rows for this action */ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { static $actionLinks = NULL; if (empty($actionLinks)) { $cancelExtra = ts('Are you sure you want to cancel this mailing?'); $deleteExtra = ts('Are you sure you want to delete this mailing?'); $archiveExtra = ts('Are you sure you want to archive this mailing?'); $actionLinks = array(CRM_Core_Action::ENABLE => array('name' => ts('Approve/Reject'), 'url' => 'civicrm/mailing/approve', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('Approve/Reject Mailing')), CRM_Core_Action::VIEW => array('name' => ts('Report'), 'url' => 'civicrm/mailing/report', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('View Mailing Report')), CRM_Core_Action::UPDATE => array('name' => ts('Re-Use'), 'url' => 'civicrm/mailing/send', 'qs' => 'mid=%%mid%%&reset=1', 'title' => ts('Re-Send Mailing')), CRM_Core_Action::DISABLE => array('name' => ts('Cancel'), 'url' => 'civicrm/mailing/browse', 'qs' => 'action=disable&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $cancelExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Cancel Mailing')), CRM_Core_Action::PREVIEW => array('name' => ts('Continue'), 'url' => 'civicrm/mailing/send', 'qs' => 'mid=%%mid%%&continue=true&reset=1', 'title' => ts('Continue Mailing')), CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => 'civicrm/mailing/browse', 'qs' => 'action=delete&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $deleteExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Delete Mailing')), CRM_Core_Action::RENEW => array('name' => ts('Archive'), 'url' => 'civicrm/mailing/browse/archived', 'qs' => 'action=renew&mid=%%mid%%&reset=1', 'extra' => 'onclick="if (confirm(\'' . $archiveExtra . '\')) this.href+=\'&confirmed=1\'; else return false;"', 'title' => ts('Archive Mailing'))); } $allAccess = TRUE; $workFlow = $showApprovalLinks = $showScheduleLinks = $showCreateLinks = FALSE; if (CRM_Mailing_Info::workflowEnabled()) { $allAccess = FALSE; $workFlow = TRUE; //supercedes all permission if (CRM_Core_Permission::check('access CiviMail')) { $allAccess = TRUE; } if (CRM_Core_Permission::check('approve mailings')) { $showApprovalLinks = TRUE; } if (CRM_Core_Permission::check('create mailings')) { $showCreateLinks = TRUE; } if (CRM_Core_Permission::check('schedule mailings')) { $showScheduleLinks = TRUE; } } $mailing = new CRM_Mailing_BAO_Mailing(); $params = array(); $whereClause = ' AND ' . $this->whereClause($params); if (empty($params)) { $this->_parent->assign('isSearch', 0); } else { $this->_parent->assign('isSearch', 1); } $rows =& $mailing->getRows($offset, $rowCount, $sort, $whereClause, $params); //get the search base mailing Ids, CRM-3711. $searchMailings = $mailing->searchMailingIDs(); //check for delete CRM-4418 $allowToDelete = CRM_Core_Permission::check('delete in CiviMail'); if ($output != CRM_Core_Selector_Controller::EXPORT) { //create the appropriate $op to use for hook_civicrm_links $pageTypes = array('view', 'mailing', 'browse'); if ($this->_parent->_unscheduled) { $pageTypes[] = 'unscheduled'; } if ($this->_parent->_scheduled) { $pageTypes[] = 'scheduled'; } if ($this->_parent->_archived) { $pageTypes[] = 'archived'; } $opString = implode('.', $pageTypes); foreach ($rows as $key => $row) { $actionMask = NULL; if ($row['sms_provider_id']) { $actionLinks[CRM_Core_Action::PREVIEW]['url'] = 'civicrm/sms/send'; } if (!($row['status'] == 'Not scheduled') && !$row['sms_provider_id']) { if ($allAccess || $showCreateLinks) { $actionMask = CRM_Core_Action::VIEW; } if (!in_array($row['id'], $searchMailings)) { if ($allAccess || $showCreateLinks) { $actionMask |= CRM_Core_Action::UPDATE; } } } else { if ($allAccess || ($showCreateLinks || $showScheduleLinks)) { $actionMask = CRM_Core_Action::PREVIEW; } } if (in_array($row['status'], array('Scheduled', 'Running', 'Paused'))) { if ($allAccess || $showApprovalLinks && $showCreateLinks && $showScheduleLinks) { $actionMask |= CRM_Core_Action::DISABLE; } if ($row['status'] == 'Scheduled' && empty($row['approval_status_id'])) { if ($workFlow && ($allAccess || $showApprovalLinks)) { $actionMask |= CRM_Core_Action::ENABLE; } } } if (in_array($row['status'], array('Complete', 'Canceled')) && !$row['archived']) { if ($allAccess || $showCreateLinks) { $actionMask |= CRM_Core_Action::RENEW; } } //check for delete permission. if ($allowToDelete) { $actionMask |= CRM_Core_Action::DELETE; } if ($actionMask == NULL) { $actionMask = CRM_Core_Action::ADD; } //get status strings as per locale settings CRM-4411. $rows[$key]['status'] = CRM_Mailing_BAO_MailingJob::status($row['status']); $rows[$key]['action'] = CRM_Core_Action::formLink($actionLinks, $actionMask, array('mid' => $row['id']), "more", FALSE, $opString, "Mailing", $row['id']); //unset($rows[$key]['id']); // if the scheduled date is 0, replace it with an empty string if ($rows[$key]['scheduled_iso'] == '0000-00-00 00:00:00') { $rows[$key]['scheduled'] = ''; } unset($rows[$key]['scheduled_iso']); } } // also initialize the AtoZ pager $this->pagerAtoZ(); return $rows; }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { $this->_unscheduled = $this->_archived = $archiveLinks = false; $this->_mailingId = CRM_Utils_Request::retrieve('mid', 'Positive', $this); // check that the user has permission to access mailing id require_once 'CRM/Mailing/BAO/Mailing.php'; CRM_Mailing_BAO_Mailing::checkPermission($this->_mailingId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); $this->assign('action', $this->_action); $showLinks = true; require_once 'CRM/Mailing/Info.php'; if (CRM_Mailing_Info::workflowEnabled()) { if (CRM_Core_Permission::check('create mailings')) { $archiveLinks = true; } if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings')) { $showLinks = false; } } $this->assign('showLinks', $showLinks); if (CRM_Core_Permission::check('access CiviMail')) { $archiveLinks = true; } if ($archiveLinks == true) { $this->assign('archiveLinks', $archiveLinks); } }
/** * 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; }
/** * Set default values for the form. * * @return array */ public function setDefaultValues() { $defaults = array(); if (isset($this->_id)) { $defaults = $this->_groupValues; if (!empty($defaults['group_type'])) { $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaults['group_type'], 1, -1)); $defaults['group_type'] = array(); foreach ($types as $type) { $defaults['group_type'][$type] = 1; } } if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) { CRM_Contact_BAO_GroupOrganization::retrieve($this->_id, $defaults); } } if (!(CRM_Core_Permission::check('access CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))) { $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE); if ($defaults['group_type'][$groupTypes['Mailing List']] == 1) { $this->assign('freezeMailignList', $groupTypes['Mailing List']); } else { $this->assign('hideMailignList', $groupTypes['Mailing List']); } } if (empty($defaults['parents'])) { $defaults['parents'] = CRM_Core_BAO_Domain::getGroupId(); } // custom data set defaults $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this); return $defaults; }
/** * Return a workflow clause for use in SQL queries, * to only process jobs that are approved. * * @return string * For use in a WHERE clause */ public static function workflowClause() { // add an additional check and only process // jobs that are approved if (CRM_Mailing_Info::workflowEnabled()) { $approveOptionID = CRM_Core_OptionGroup::getValue('mail_approval_status', 'Approved', 'name'); if ($approveOptionID) { return " AND m.approval_status_id = {$approveOptionID} "; } } return ''; }
/** * 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')); }
/** * Process the posted form values. Create and schedule a Mass SMS. */ public function postProcess() { $params = array(); $params['mailing_id'] = $ids['mailing_id'] = $this->_mailingID; if (empty($params['mailing_id'])) { CRM_Core_Error::fatal(ts('Could not find a mailing id')); } foreach (array('now', 'start_date', 'start_date_time') as $parameter) { $params[$parameter] = $this->controller->exportValue($this->_name, $parameter); } if ($params['now']) { $params['scheduled_date'] = date('YmdHis'); } else { $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']); } $session = CRM_Core_Session::singleton(); // set the scheduled_id $params['scheduled_id'] = $session->get('userID'); $params['scheduled_date'] = date('YmdHis'); // set approval details if workflow is not enabled if (!CRM_Mailing_Info::workflowEnabled()) { $params['approver_id'] = $session->get('userID'); $params['approval_date'] = date('YmdHis'); $params['approval_status_id'] = 1; } if ($params['now']) { $params['scheduled_date'] = date('YmdHis'); } else { $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']); } // Build the mailing object. CRM_Mailing_BAO_Mailing::create($params, $ids); $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled', 'reset=1&scheduled=true&sms=1')); }
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_MailingJob(); $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(); } $status = ts("Your mailing has been saved."); CRM_Core_Session::setStatus($status); $url = CRM_Utils_System::url('civicrm/view/quickbulkemail'); return $this->controller->setDestination($url); }