/** * Function to actually build the form * * @return None * @access public */ function buildQuickForm() { $session =& CRM_Core_Session::singleton(); $this->add('text', 'from_name', ts('From name')); $this->add('text', 'from_email', ts('From Email')); $defaults['from_email'] = $session->get('ufEmail'); $this->add('checkbox', 'forward_reply', ts('Forward replies?')); $defaults['forward_reply'] = true; $this->add('checkbox', 'track_urls', ts('Track URLs?')); $defaults['track_urls'] = true; $this->add('checkbox', 'track_opens', ts('Track Opens?')); $defaults['track_opens'] = true; $this->add('checkbox', 'auto_responder', ts('Auto-respond to replies?')); $defaults['auto_responder'] = false; $this->addElement('text', 'subject', ts('Mailing subject'), 'size=30 maxlength=60'); $defaults['subject'] = $this->get('mailing_name'); $this->addElement('file', 'textFile', ts('Upload Text Message'), 'size=30 maxlength=60'); $this->setMaxFileSize(1024 * 1024); $this->addRule('textFile', ts('File size should be less than 1 MByte'), 'maxfilesize', 1024 * 1024); $this->addRule('textFile', ts('File must be in ascii format'), 'asciiFile'); $this->addElement('file', 'htmlFile', ts('Upload HTML Message'), 'size=30 maxlength=60'); $this->setMaxFileSize(1024 * 1024); $this->addRule('htmlFile', ts('File size should be less than 1 MByte'), 'maxfilesize', 1024 * 1024); $this->addRule('htmlFile', ts('File must be in ascii format'), 'asciiFile'); $this->add('select', 'header_id', ts('Mailing Header'), CRM_Mailing_PseudoConstant::component('Header')); $this->add('select', 'footer_id', ts('Mailing Footer'), CRM_Mailing_PseudoConstant::component('Footer')); $this->add('select', 'reply_id', ts('Auto-responder'), CRM_Mailing_PseudoConstant::component('Reply')); $this->add('select', 'unsubscribe_id', ts('Unsubscribe Message'), CRM_Mailing_PseudoConstant::component('Unsubscribe')); $this->add('select', 'optout_id', ts('Opt-out Message'), CRM_Mailing_PseudoConstant::component('OptOut')); $this->addFormRule(array('CRM_Mailing_Form_Upload', 'dataRule')); $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'upload', 'name' => ts('Next >>'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->setDefaults($defaults); }
/** * Function to actually build the form * * @return None * @access public */ function buildQuickForm() { $template = ' <table{class}> <tr><td>{unselected}</td><td>{selected}</tr></tr> <tr><td>{add}</td><td>{remove}</tr></tr> </table>'; $groups =& CRM_Core_PseudoConstant::group(); $inG =& $this->addElement('advmultiselect', 'includeGroups', ts('Include group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px')); $this->addRule('includeGroups', ts('Please select a group to be mailed.'), 'required'); $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px')); $inG->setButtonAttributes('add', array('value' => ts('Add >>'))); $outG->setButtonAttributes('add', array('value' => ts('Add >>'))); $inG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); // $inG->setElementTemplate($template); // $outG->setElementTemplate($template); $mailings =& CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('Include mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px')); $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('Exclude mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px')); $inM->setButtonAttributes('add', array('value' => ts('Add >>'))); $outM->setButtonAttributes('add', array('value' => ts('Add >>'))); $inM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); // $inM->setElementTemplate($template); // $outM->setElementTemplate($template); $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule')); $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => ts('Next >>'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); }
/** * Function to actually build the form * * @return None * @access public */ public function buildQuickForm() { require_once 'CRM/Mailing/PseudoConstant.php'; $this->add('checkbox', 'forward_replies', ts('Forward Replies?')); $defaults['forward_replies'] = true; $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?')); $defaults['url_tracking'] = true; $this->add('checkbox', 'open_tracking', ts('Track Opens?')); $defaults['open_tracking'] = true; $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?')); $defaults['auto_responder'] = false; $this->add('select', 'reply_id', ts('Auto-responder'), CRM_Mailing_PseudoConstant::component('Reply'), true); $this->add('select', 'unsubscribe_id', ts('Unsubscribe Message'), CRM_Mailing_PseudoConstant::component('Unsubscribe'), true); $this->add('select', 'resubscribe_id', ts('Resubscribe Message'), CRM_Mailing_PseudoConstant::component('Resubscribe'), true); $this->add('select', 'optout_id', ts('Opt-out Message'), CRM_Mailing_PseudoConstant::component('OptOut'), true); //FIXME : currently we are hiding save an continue later when //search base mailing, we should handle it when we fix CRM-3876 $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); if ($this->get('context') == 'search' && $this->get('ssID')) { $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))); } $this->addButtons($buttons); $this->setDefaults($defaults); }
/** * Adjust Metadata for Create action. * * The metadata is used for setting defaults, documentation & validation. * * @param array $params * Array of parameters determined by getfields. */ function _civicrm_api3_mailing_create_spec(&$params) { $params['created_id']['api.required'] = 1; $params['created_id']['api.default'] = 'user_contact_id'; $params['override_verp']['api.default'] = !CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies'); $params['visibility']['api.default'] = 'Public Pages'; $params['dedupe_email']['api.default'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'dedupe_email_default'); $params['forward_replies']['api.default'] = FALSE; $params['auto_responder']['api.default'] = FALSE; $params['open_tracking']['api.default'] = TRUE; $params['url_tracking']['api.default'] = TRUE; $params['header_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Header', ''); $params['footer_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Footer', ''); $params['optout_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('OptOut', ''); $params['reply_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Reply', ''); $params['resubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Resubscribe', ''); $params['unsubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Unsubscribe', ''); $params['mailing_type']['api.default'] = 'standalone'; $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { $params['from_email']['api.default'] = $match[2]; $params['from_name']['api.default'] = $match[1]; } } }
/** * Construct a new mailing object, along with job and mailing_group * objects, from the form values of the create mailing wizard. * * @params array $params Form values * * @return object $mailing The new mailing object * @access public * @static */ public static function create(&$params, $ids = array()) { // CRM-12430 // Do the below only for an insert // for an update, we should not set the defaults if (!isset($ids['id']) && !isset($ids['mailing_id'])) { // Retrieve domain email and name for default sender $domain = civicrm_api('Domain', 'getsingle', array('version' => 3, 'current_domain' => 1, 'sequential' => 1)); if (isset($domain['from_email'])) { $domain_email = $domain['from_email']; $domain_name = $domain['from_name']; } else { $domain_email = '*****@*****.**'; $domain_name = 'EXAMPLE.ORG'; } if (!isset($params['created_id'])) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } $defaults = array('override_verp' => TRUE, 'forward_replies' => FALSE, 'open_tracking' => TRUE, 'url_tracking' => TRUE, 'visibility' => 'User and User Admin Only', 'replyto_email' => $domain_email, 'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''), 'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''), 'from_email' => $domain_email, 'from_name' => $domain_name, 'msg_template_id' => NULL, 'created_id' => $params['created_id'], 'approver_id' => NULL, 'auto_responder' => 0, 'created_date' => date('YmdHis'), 'scheduled_date' => NULL, 'approval_date' => NULL); // Get the default from email address, if not provided. if (empty($defaults['from_email'])) { $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { $defaults['from_email'] = $match[2]; $defaults['from_name'] = $match[1]; } } } $params = array_merge($defaults, $params); } /** * Could check and warn for the following cases: * * - groups OR mailings should be populated. * - body html OR body text should be populated. */ $transaction = new CRM_Core_Transaction(); $mailing = self::add($params, $ids); if (is_a($mailing, 'CRM_Core_Error')) { $transaction->rollback(); return $mailing; } $groupTableName = CRM_Contact_BAO_Group::getTableName(); $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName(); /* Create the mailing group record */ $mg = new CRM_Mailing_DAO_MailingGroup(); foreach (array('groups', 'mailings') as $entity) { foreach (array('include', 'exclude', 'base') as $type) { if (isset($params[$entity]) && CRM_Utils_Array::value($type, $params[$entity]) && is_array($params[$entity][$type])) { foreach ($params[$entity][$type] as $entityId) { $mg->reset(); $mg->mailing_id = $mailing->id; $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName; $mg->entity_id = $entityId; $mg->group_type = $type; $mg->save(); } } } } if (!empty($params['search_id']) && !empty($params['group_id'])) { $mg->reset(); $mg->mailing_id = $mailing->id; $mg->entity_table = $groupTableName; $mg->entity_id = $params['group_id']; $mg->search_id = $params['search_id']; $mg->search_args = $params['search_args']; $mg->group_type = 'Include'; $mg->save(); } // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id); $transaction->commit(); /** * create parent job if not yet created * condition on the existence of a scheduled date */ if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null') { $job = new CRM_Mailing_BAO_MailingJob(); $job->mailing_id = $mailing->id; $job->status = 'Scheduled'; $job->is_test = 0; if (!$job->find(TRUE)) { $job->scheduled_date = $params['scheduled_date']; $job->save(); } // Populate the recipients. $mailing->getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, FALSE); } return $mailing; }
/** * Get all mail approval status. * * The static array approvalStatus is returned * * @access public * @static * * @return array - array reference of all mail approval statuses * */ public static function &approvalStatus() { if (!self::$approvalStatus) { self::$approvalStatus = CRM_Core_OptionGroup::values('mail_approval_status'); } return self::$approvalStatus; }
/** * add all the elements shared between Mailing search and advnaced search * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { // mailing selectors $mailings = CRM_Mailing_BAO_Mailing::getMailingsList(); if (!empty($mailings)) { $form->add('select', 'mailing_id', ts('Mailing Name(s)'), $mailings, FALSE, array('id' => 'mailing_id', 'multiple' => 'multiple', 'title' => ts('- select -'))); } CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); // event filters $form->addRadio('mailing_delivery_status', ts('Delivery Status'), CRM_Mailing_PseudoConstant::yesNoOptions('delivered')); $form->addRadio('mailing_open_status', ts('Trackable Opens'), CRM_Mailing_PseudoConstant::yesNoOptions('open')); $form->addRadio('mailing_click_status', ts('Trackable URLs'), CRM_Mailing_PseudoConstant::yesNoOptions('click')); $form->addRadio('mailing_reply_status', ts('Trackable Replies'), CRM_Mailing_PseudoConstant::yesNoOptions('reply')); $form->add('checkbox', 'mailing_unsubscribe', ts('Unsubscribe Requests')); $form->add('checkbox', 'mailing_optout', ts('Opt-out Requests')); $form->add('checkbox', 'mailing_forward', ts('Forwards')); $form->assign('validCiviMailing', TRUE); $form->addFormRule(array('CRM_Mailing_BAO_Query', 'formRule'), $form); }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { //get the context $context = $this->get('context'); $this->assign('context', $context); $this->add('text', 'name', ts('Name Your SMS'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); //get the mailing groups. $groups = CRM_Core_PseudoConstant::group('Mailing'); //get the sms mailing list $mailings = CRM_Mailing_PseudoConstant::completed('sms'); if (!$mailings) { $mailings = array(); } // run the groups through a hook so users can trim it if needed CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); $inG =& $this->addElement('advmultiselect', 'includeGroups', ts('Include Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $this->addRule('includeGroups', ts('Please select a group to be SMSed.'), 'required'); $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inG->setButtonAttributes('add', array('value' => ts('Add >>'))); $outG->setButtonAttributes('add', array('value' => ts('Add >>'))); $inG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inM->setButtonAttributes('add', array('value' => ts('Add >>'))); $outM->setButtonAttributes('add', array('value' => ts('Add >>'))); $inM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $this->addFormRule(array('CRM_SMS_Form_Group', 'formRule')); $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); }
/** * Function to actually build the form * * @return None * @access public */ public function buildQuickForm() { require_once 'CRM/Mailing/PseudoConstant.php'; //get the context $context = $this->get('context'); if ($this->_searchBasedMailing) { $context = 'search'; } $this->assign('context', $context); $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), true); //get the mailing groups. $groups =& CRM_Core_PseudoConstant::group('Mailing'); $mailings =& CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } // run the groups through a hook so users can trim it if needed require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); //when the context is search add base group's. if ($this->_searchBasedMailing) { //get the static groups $staticGroups = CRM_Core_PseudoConstant::staticGroup(false, 'Mailing'); $this->add('select', 'baseGroup', ts('Base Group'), array('' => ts('- select -')) + $staticGroups, true); } $inG =& $this->addElement('advmultiselect', 'includeGroups', ts('Include Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); //as we are having hidden smart group so no need. if (!$this->_searchBasedMailing) { $this->addRule('includeGroups', ts('Please select a group to be mailed.'), 'required'); } $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inG->setButtonAttributes('add', array('value' => ts('Add >>'))); $outG->setButtonAttributes('add', array('value' => ts('Add >>'))); $inG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inM->setButtonAttributes('add', array('value' => ts('Add >>'))); $outM->setButtonAttributes('add', array('value' => ts('Add >>'))); $inM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); require_once 'CRM/Contact/Page/CustomSearch.php'; $urls = array('' => ts('- select -'), -1 => ts('CiviCRM Search')) + CRM_Contact_Page_CustomSearch::info(); $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule')); //FIXME : currently we are hiding save an continue later when //search base mailing, we should handle it when we fix CRM-3876 $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); if ($this->_searchBasedMailing) { $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))); } $this->addButtons($buttons); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); }
/** * Add all the elements shared between Mailing search and advnaced search. * * * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { // mailing selectors $mailings = CRM_Mailing_BAO_Mailing::getMailingsList(); if (!empty($mailings)) { $form->add('select', 'mailing_id', ts('Mailing Name(s)'), $mailings, FALSE, array('id' => 'mailing_id', 'multiple' => 'multiple', 'class' => 'crm-select2')); } CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE); $form->addElement('hidden', 'mailing_date_range_error'); $form->addFormRule(array('CRM_Mailing_BAO_Query', 'formRule'), $form); $mailingJobStatuses = array('' => ts('- select -'), 'Complete' => 'Complete', 'Scheduled' => 'Scheduled', 'Running' => 'Running', 'Canceled' => 'Canceled'); $form->addElement('select', 'mailing_job_status', ts('Mailing Job Status'), $mailingJobStatuses, FALSE); $mailingBounceTypes = CRM_Core_PseudoConstant::get('CRM_Mailing_Event_DAO_Bounce', 'bounce_type_id', array('keyColumn' => 'id', 'labelColumn' => 'name')); $form->add('select', 'mailing_bounce_types', ts('Bounce Types'), $mailingBounceTypes, FALSE, array('id' => 'mailing_bounce_types', 'multiple' => 'multiple', 'class' => 'crm-select2')); // event filters $form->addRadio('mailing_delivery_status', ts('Delivery Status'), CRM_Mailing_PseudoConstant::yesNoOptions('delivered'), array('allowClear' => TRUE)); $form->addRadio('mailing_open_status', ts('Trackable Opens'), CRM_Mailing_PseudoConstant::yesNoOptions('open'), array('allowClear' => TRUE)); $form->addRadio('mailing_click_status', ts('Trackable URLs'), CRM_Mailing_PseudoConstant::yesNoOptions('click'), array('allowClear' => TRUE)); $form->addRadio('mailing_reply_status', ts('Trackable Replies'), CRM_Mailing_PseudoConstant::yesNoOptions('reply'), array('allowClear' => TRUE)); $form->add('checkbox', 'mailing_unsubscribe', ts('Unsubscribe Requests')); $form->add('checkbox', 'mailing_optout', ts('Opt-out Requests')); $form->add('checkbox', 'mailing_forward', ts('Forwards')); // Campaign select field CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'mailing_campaign_id'); $form->assign('validCiviMailing', TRUE); }
/** * Function to actually build the form * * @return None * @access public */ public function buildQuickForm() { $session = CRM_Core_Session::singleton(); require_once 'CRM/Core/PseudoConstant.php'; $formEmailAddress = CRM_Core_PseudoConstant::fromEmailAddress('from_email_address'); if (empty($formEmailAddress)) { //redirect user to enter from email address. $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'group=from_email_address&action=add&reset=1'); $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url)); $session->setStatus($status); } else { foreach ($formEmailAddress as $key => $email) { $formEmailAddress[$key] = htmlspecialchars($formEmailAddress[$key]); } } $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $formEmailAddress, true); $this->add('text', 'subject', ts('Mailing Subject'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'subject'), true); $attributes = array('onclick' => "showHideUpload();"); $options = array(ts('Upload Content'), ts('Compose On-screen')); $this->addRadio('upload_type', ts('I want to'), $options, $attributes, " "); require_once 'CRM/Mailing/BAO/Mailing.php'; CRM_Mailing_BAO_Mailing::commonCompose($this); $this->addElement('file', 'textFile', ts('Upload TEXT Message'), 'size=30 maxlength=60'); $this->setMaxFileSize(1024 * 1024); $this->addRule('textFile', ts('File size should be less than 1 MByte'), 'maxfilesize', 1024 * 1024); $this->addRule('textFile', ts('File must be in UTF-8 encoding'), 'utf8File'); $this->addElement('file', 'htmlFile', ts('Upload HTML Message'), 'size=30 maxlength=60'); $this->setMaxFileSize(1024 * 1024); $this->addRule('htmlFile', ts('File size should be less than %1 MByte(s)', array(1 => 1)), 'maxfilesize', 1024 * 1024); $this->addRule('htmlFile', ts('File must be in UTF-8 encoding'), 'utf8File'); //fix upload files when context is search. CRM-3711 $ssID = $this->get('ssID'); if ($this->_searchBasedMailing && $ssID) { $this->set('uploadNames', array('textFile', 'htmlFile')); } require_once 'CRM/Core/BAO/File.php'; CRM_Core_BAO_File::buildAttachment($this, 'civicrm_mailing', $this->_mailingID); require_once 'CRM/Mailing/PseudoConstant.php'; $this->add('select', 'header_id', ts('Mailing Header'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header')); $this->add('select', 'footer_id', ts('Mailing Footer'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer')); $this->addFormRule(array('CRM_Mailing_Form_Upload', 'formRule'), $this); //FIXME : currently we are hiding save an continue later when //search base mailing, we should handle it when we fix CRM-3876 $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'upload', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'upload', 'name' => ts('Save & Continue Later'), 'subName' => 'save'), array('type' => 'cancel', 'name' => ts('Cancel'))); if ($this->_searchBasedMailing && $ssID) { $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'upload', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))); } $this->addButtons($buttons); }
/** * Get all the completed mailing * * @access public * @return array - array reference of all mailing templates if any * @static */ function &completed() { if (!$GLOBALS['_CRM_MAILING_PSEUDOCONSTANT']['completed']) { CRM_Mailing_PseudoConstant::populate($GLOBALS['_CRM_MAILING_PSEUDOCONSTANT']['completed'], 'CRM_Mailing_DAO_Mailing', true, 'name', 'is_completed'); } return $GLOBALS['_CRM_MAILING_PSEUDOCONSTANT']['completed']; }
public static function getMailingTokenReplacement($token, &$mailing, $escapeSmarty = false) { $value = ''; switch ($token) { case 'name': $value = $mailing ? $mailing->name : 'Mailing Name'; break; case 'group': $groups = $mailing ? $mailing->getGroupNames() : array('Mailing Groups'); $value = implode(', ', $groups); break; case 'subject': $value = $mailing->subject; break; case 'viewUrl': $value = CRM_Utils_System::url('civicrm/mailing/view', "reset=1&id={$mailing->id}", true, null, false, true); break; case 'editUrl': $value = CRM_Utils_System::url('civicrm/mailing/send', "reset=1&mid={$mailing->id}&continue=true", true, null, false, true); break; case 'scheduleUrl': $value = CRM_Utils_System::url('civicrm/mailing/schedule', "reset=1&mid={$mailing->id}", true, null, false, true); break; case 'html': require_once 'CRM/Mailing/Page/View.php'; $page = new CRM_Mailing_Page_View(); $value = $page->run($mailing->id, false); break; case 'approvalStatus': require_once 'CRM/Mailing/PseudoConstant.php'; $mailApprovalStatus = CRM_Mailing_PseudoConstant::approvalStatus(); $value = $mailApprovalStatus[$mailing->approval_status_id]; break; case 'approvalNote': $value = $mailing->approval_note; break; case 'approveUrl': $value = CRM_Utils_System::url('civicrm/mailing/approve', "reset=1&mid={$mailing->id}", true, null, false, true); break; case 'creator': $value = CRM_Contact_BAO_Contact::displayName($mailing->created_id); break; case 'creatorEmail': $value = CRM_Contact_BAO_Contact::getPrimaryEmail($mailing->created_id); break; default: $value = "{mailing.{$token}}"; break; } if ($escapeSmarty) { $value = self::tokenEscapeSmarty($value); } return $value; }
/** * Function to actually build the form * * @return None * @access public */ public function buildQuickForm() { //get the context $context = $this->get('context'); if ($this->_searchBasedMailing) { $context = 'search'; } $this->assign('context', $context); $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); $hiddenMailingGroup = NULL; $campaignId = NULL; //CRM-7362 --add campaigns. if ($this->_mailingID) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'campaign_id'); $hiddenMailingGroup = CRM_Mailing_BAO_Mailing::hiddenMailingGroup($this->_mailingID); } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); //dedupe on email option $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?')); //get the mailing groups. $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing'); // asort($groups); if ($hiddenMailingGroup) { $groups[$hiddenMailingGroup] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $hiddenMailingGroup, 'title'); } $mailings = CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } // run the groups through a hook so users can trim it if needed CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); //when the context is search add base group's. if ($this->_searchBasedMailing) { //CRM-16600 Include Smart Groups in Unsubscribe list as that matches //all other practices in CiviMail $this->add('select', 'baseGroup', ts('Unsubscription Group'), array('' => ts('- select -')) + $groups, TRUE); } if (count($groups) <= 10) { // setting minimum height to 2 since widget looks strange when size (height) is 1 $groupSize = max(count($groups), 2); } else { $groupSize = 10; } $inG =& $this->addElement('advmultiselect', 'includeGroups', ts('Include Group(s)') . ' ', $groups, array('size' => $groupSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect')); //as we are having hidden smart group so no need. if (!$this->_searchBasedMailing) { $this->addRule('includeGroups', ts('Please select a group to be mailed.'), 'required'); } $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => $groupSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect')); $inG->setButtonAttributes('add', array('value' => ts('Add >>'))); $outG->setButtonAttributes('add', array('value' => ts('Add >>'))); $inG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); if (count($mailings) <= 10) { // setting minimum height to 2 since widget looks strange when size (height) is 1 $mailingSize = max(count($mailings), 2); } else { $mailingSize = 10; } $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => $mailingSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect')); $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => $mailingSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect')); $inM->setButtonAttributes('add', array('value' => ts('Add >>'))); $outM->setButtonAttributes('add', array('value' => ts('Add >>'))); $inM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $urls = array('' => ts('- select -'), -1 => ts('CiviCRM Search')) + CRM_Contact_Page_CustomSearch::info(); $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule')); $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); if (count($groups) == 0 && count($mailings) == 0 && !$this->_searchBasedMailing) { CRM_Core_Error::statusBounce("To send a mailing, you must have a valid group of recipients - either at least one group that's a Mailing List or at least one previous mailing or start from a search"); } }
/** * Construct a new mailing object, along with job and mailing_group * objects, from the form values of the create mailing wizard. * * This function is a bit evil. It not only merges $params and saves * the mailing -- it also schedules the mailing and chooses the recipients. * Since it merges $params, it's also the only place to correctly trigger * multi-field validation. It should be broken up. * * In the mean time, use-cases which break under the weight of this * evil may find reprieve in these extra evil params: * * - _skip_evil_bao_auto_recipients_: bool * - _skip_evil_bao_auto_schedule_: bool * - _evil_bao_validator_: string|callable * * </twowrongsmakesaright> * * @params array $params * Form values. * * @param array $params * @param array $ids * * @return object * $mailing The new mailing object * @throws \Exception */ public static function create(&$params, $ids = array()) { // WTH $ids if (empty($ids) && isset($params['id'])) { $ids['mailing_id'] = $ids['id'] = $params['id']; } // CRM-12430 // Do the below only for an insert // for an update, we should not set the defaults if (!isset($ids['id']) && !isset($ids['mailing_id'])) { // Retrieve domain email and name for default sender $domain = civicrm_api('Domain', 'getsingle', array('version' => 3, 'current_domain' => 1, 'sequential' => 1)); if (isset($domain['from_email'])) { $domain_email = $domain['from_email']; $domain_name = $domain['from_name']; } else { $domain_email = '*****@*****.**'; $domain_name = 'EXAMPLE.ORG'; } if (!isset($params['created_id'])) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } $defaults = array('override_verp' => TRUE, 'forward_replies' => FALSE, 'open_tracking' => TRUE, 'url_tracking' => TRUE, 'visibility' => 'Public Pages', 'replyto_email' => $domain_email, 'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''), 'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''), 'from_email' => $domain_email, 'from_name' => $domain_name, 'msg_template_id' => NULL, 'created_id' => $params['created_id'], 'approver_id' => NULL, 'auto_responder' => 0, 'created_date' => date('YmdHis'), 'scheduled_date' => NULL, 'approval_date' => NULL); // Get the default from email address, if not provided. if (empty($defaults['from_email'])) { $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { $defaults['from_email'] = $match[2]; $defaults['from_name'] = $match[1]; } } } $params = array_merge($defaults, $params); } /** * Could check and warn for the following cases: * * - groups OR mailings should be populated. * - body html OR body text should be populated. */ $transaction = new CRM_Core_Transaction(); $mailing = self::add($params, $ids); if (is_a($mailing, 'CRM_Core_Error')) { $transaction->rollback(); return $mailing; } // update mailings with hash values CRM_Contact_BAO_Contact_Utils::generateChecksum($mailing->id, NULL, NULL, NULL, 'mailing', 16); $groupTableName = CRM_Contact_BAO_Group::getTableName(); $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName(); /* Create the mailing group record */ $mg = new CRM_Mailing_DAO_MailingGroup(); $groupTypes = array('include' => 'Include', 'exclude' => 'Exclude', 'base' => 'Base'); foreach (array('groups', 'mailings') as $entity) { foreach (array('include', 'exclude', 'base') as $type) { if (isset($params[$entity][$type])) { self::replaceGroups($mailing->id, $groupTypes[$type], $entity, $params[$entity][$type]); } } } if (!empty($params['search_id']) && !empty($params['group_id'])) { $mg->reset(); $mg->mailing_id = $mailing->id; $mg->entity_table = $groupTableName; $mg->entity_id = $params['group_id']; $mg->search_id = $params['search_id']; $mg->search_args = $params['search_args']; $mg->group_type = 'Include'; $mg->save(); } // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id); // If we're going to autosend, then check validity before saving. if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && !empty($params['_evil_bao_validator_'])) { $cb = Civi\Core\Resolver::singleton()->get($params['_evil_bao_validator_']); $errors = call_user_func($cb, $mailing); if (!empty($errors)) { $fields = implode(',', array_keys($errors)); throw new CRM_Core_Exception("Mailing cannot be sent. There are missing or invalid fields ({$fields}).", 'cannot-send', $errors); } } $transaction->commit(); // Create parent job if not yet created. // Condition on the existence of a scheduled date. if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && empty($params['_skip_evil_bao_auto_schedule_'])) { $job = new CRM_Mailing_BAO_MailingJob(); $job->mailing_id = $mailing->id; $job->status = 'Scheduled'; $job->is_test = 0; if (!$job->find(TRUE)) { $job->scheduled_date = $params['scheduled_date']; $job->save(); } // Populate the recipients. if (empty($params['_skip_evil_bao_auto_recipients_'])) { self::getRecipients($job->id, $mailing->id, TRUE, $mailing->dedupe_email); } } return $mailing; }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $this->addElement('checkbox', 'override_verp', ts('Track Replies?')); $defaults['override_verp'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies', NULL, FALSE); $this->add('checkbox', 'forward_replies', ts('Forward Replies?')); $defaults['forward_replies'] = FALSE; $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?')); $defaults['url_tracking'] = TRUE; $this->add('checkbox', 'open_tracking', ts('Track Opens?')); $defaults['open_tracking'] = TRUE; $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?')); $defaults['auto_responder'] = FALSE; $this->add('select', 'visibility', ts('Mailing Visibility'), CRM_Core_SelectValues::groupVisibility(), TRUE); $this->add('select', 'reply_id', ts('Auto-responder'), CRM_Mailing_PseudoConstant::component('Reply'), TRUE); $this->add('select', 'unsubscribe_id', ts('Unsubscribe Message'), CRM_Mailing_PseudoConstant::component('Unsubscribe'), TRUE); $this->add('select', 'resubscribe_id', ts('Resubscribe Message'), CRM_Mailing_PseudoConstant::component('Resubscribe'), TRUE); $this->add('select', 'optout_id', ts('Opt-out Message'), CRM_Mailing_PseudoConstant::component('OptOut'), TRUE); $buttons = array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'next', 'name' => ts('Next'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); $this->setDefaults($defaults); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $session = CRM_Core_Session::singleton(); $config = CRM_Core_Config::singleton(); $options = array(); $tempVar = FALSE; // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix $session->getVars($options, "CRM_Mailing_Controller_Send_{$this->controller->_key}"); $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address'); if (empty($fromEmailAddress)) { //redirect user to enter from email address. $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'action=add&reset=1'); $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url)); $session->setStatus($status, ts('Notice')); } else { foreach ($fromEmailAddress as $key => $email) { $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]); } } $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmailAddress, TRUE); //Added code to add custom field as Reply-To on form when it is enabled from Mailer settings if ((int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo') && empty($options['override_verp'])) { $this->add('select', 'reply_to_address', ts('Reply-To'), array('' => '- select -') + $fromEmailAddress); } elseif (!empty($options['override_verp'])) { $trackReplies = TRUE; $this->assign('trackReplies', $trackReplies); } $this->add('text', 'subject', ts('Mailing Subject'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'subject'), TRUE); $attributes = array('onclick' => "showHideUpload();"); $options = array(ts('Upload Content'), ts('Compose On-screen')); $this->addRadio('upload_type', ts('I want to'), $options, $attributes, " "); CRM_Mailing_BAO_Mailing::commonCompose($this); $this->addElement('file', 'textFile', ts('Upload TEXT Message'), 'size=30 maxlength=60'); $this->addUploadElement('textFile'); $this->setMaxFileSize(1024 * 1024); $this->addRule('textFile', ts('File size should be less than 1 MByte'), 'maxfilesize', 1024 * 1024); $this->addRule('textFile', ts('File must be in UTF-8 encoding'), 'utf8File'); $this->addElement('file', 'htmlFile', ts('Upload HTML Message'), 'size=30 maxlength=60'); $this->addUploadElement('htmlFile'); $this->setMaxFileSize(1024 * 1024); $this->addRule('htmlFile', ts('File size should be less than %1 MByte(s)', array(1 => 1)), 'maxfilesize', 1024 * 1024); $this->addRule('htmlFile', ts('File must be in UTF-8 encoding'), 'utf8File'); //fix upload files when context is search. CRM-3711 $ssID = $this->get('ssID'); if ($this->_searchBasedMailing && $ssID) { $this->set('uploadNames', array('textFile', 'htmlFile')); } CRM_Core_BAO_File::buildAttachment($this, 'civicrm_mailing', $this->_mailingID); $this->add('select', 'header_id', ts('Mailing Header'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header')); $this->add('select', 'footer_id', ts('Mailing Footer'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer')); $this->addFormRule(array('CRM_Mailing_Form_Upload', 'formRule'), $this); $buttons = array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'upload', 'name' => ts('Next'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save & Continue Later'), 'subName' => 'save'), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); }
/** * Build the form for the approval/rejection mailing * * @param * * @return void * @access public */ public function buildQuickform() { $title = ts('Approve/Reject Mailing') . " - {$this->_mailing->name}"; CRM_Utils_System::setTitle($title); $this->addElement('textarea', 'approval_note', ts('Approve/Reject Note')); $mailApprovalStatus = CRM_Mailing_PseudoConstant::approvalStatus(); // eliminate the none option $noneOptionID = CRM_Core_OptionGroup::getValue('mail_approval_status', 'None', 'name'); if ($noneOptionID) { unset($mailApprovalStatus[$noneOptionID]); } $this->addRadio('approval_status_id', ts('Approval Status'), $mailApprovalStatus, TRUE, NULL, TRUE); $buttons = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); // add the preview elements $preview = array(); $preview['subject'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'subject'); $preview['viewURL'] = CRM_Utils_System::url('civicrm/mailing/view', "reset=1&id={$this->_mailingID}"); $preview['type'] = $this->_mailing->body_html ? 'html' : 'text'; $preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $this->_mailingID); $this->assign_by_ref('preview', $preview); }
/** * Function to actually build the form * * @return None * @access public */ public function buildQuickForm() { //get the context $context = $this->get('context'); if ($this->_searchBasedMailing) { $context = 'search'; } $this->assign('context', $context); $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); //CRM-7362 --add campaigns. $mailingId = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL); $campaignId = NULL; if ($mailingId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingId, 'campaign_id'); } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); //dedupe on email option $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?')); //get the mailing groups. $groups = CRM_Core_PseudoConstant::group('Mailing'); $mailings = CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } // run the groups through a hook so users can trim it if needed CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); //when the context is search add base group's. if ($this->_searchBasedMailing) { //get the static groups $staticGroups = CRM_Core_PseudoConstant::staticGroup(FALSE, 'Mailing'); $this->add('select', 'baseGroup', ts('Unsubscription Group'), array('' => ts('- select -')) + $staticGroups, TRUE); } $inG =& $this->addElement('advmultiselect', 'includeGroups', ts('Include Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); //as we are having hidden smart group so no need. if (!$this->_searchBasedMailing) { $this->addRule('includeGroups', ts('Please select a group to be mailed.'), 'required'); } $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inG->setButtonAttributes('add', array('value' => ts('Add >>'))); $outG->setButtonAttributes('add', array('value' => ts('Add >>'))); $inG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inM->setButtonAttributes('add', array('value' => ts('Add >>'))); $outM->setButtonAttributes('add', array('value' => ts('Add >>'))); $inM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $urls = array('' => ts('- select -'), -1 => ts('CiviCRM Search')) + CRM_Contact_Page_CustomSearch::info(); $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule')); //FIXME : currently we are hiding save an continue later when //search base mailing, we should handle it when we fix CRM-3876 $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); if ($this->_searchBasedMailing) { $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))); } $this->addButtons($buttons); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { //get the context $context = $this->get('context'); if ($this->_searchBasedMailing) { $context = 'search'; } $this->assign('context', $context); $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); $hiddenMailingGroup = NULL; $campaignId = NULL; //CRM-7362 --add campaigns. if ($this->_mailingID) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'campaign_id'); $hiddenMailingGroup = CRM_Mailing_BAO_Mailing::hiddenMailingGroup($this->_mailingID); } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); //dedupe on email option $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?')); // location types $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('id' => 'display_name')); $this->addElement('select', 'location_type_id', ts("Location Type"), array('' => ts('Automatic')) + $locationTypes); $methods = CRM_Core_SelectValues::emailSelectMethods(); $this->addElement('select', 'email_selection_method', ts("Email Selection Method"), $methods); //get the mailing groups. $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing'); if ($hiddenMailingGroup) { $groups[$hiddenMailingGroup] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $hiddenMailingGroup, 'title'); } $mailings = CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } // run the groups through a hook so users can trim it if needed CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); //when the context is search add base group's. if ($this->_searchBasedMailing) { //get the static groups $staticGroups = CRM_Core_PseudoConstant::staticGroup(FALSE, 'Mailing'); $this->add('select', 'baseGroup', ts('Unsubscription Group'), array('' => ts('- select -')) + CRM_Contact_BAO_Group::getGroupsHierarchy($staticGroups, NULL, ' ', TRUE), TRUE, array('class' => 'crm-select2 huge')); } $select2style = array('multiple' => TRUE, 'style' => 'width: 100%; max-width: 60em;', 'class' => 'crm-select2', 'placeholder' => ts('- select -')); $this->add('select', 'includeGroups', ts('Include Group(s)'), $groups, !$this->_searchBasedMailing, $select2style); $this->add('select', 'excludeGroups', ts('Exclude Group(s)'), $groups, FALSE, $select2style); $this->add('select', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, FALSE, $select2style); $this->add('select', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, FALSE, $select2style); $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule')); $buttons = array(array('type' => 'next', 'name' => ts('Next'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); if (count($groups) == 0 && count($mailings) == 0 && !$this->_searchBasedMailing) { CRM_Core_Error::statusBounce("To send a mailing, you must have a valid group of recipients - either at least one group that's a Mailing List or at least one previous mailing or start from a search"); } }
/** * Determine the default mailing component of a given type. * * @param $type * The type of component needed. * @param $undefined * The value to use if no default is defined. * * @return int * The ID of the default mailing component. */ public static function &defaultComponent($type, $undefined = NULL) { if (!self::$defaultComponent) { $queryDefaultComponents = "SELECT id, component_type\n FROM civicrm_mailing_component\n WHERE is_active = 1\n AND is_default = 1\n GROUP BY component_type, id"; $dao = CRM_Core_DAO::executeQuery($queryDefaultComponents); self::$defaultComponent = array(); while ($dao->fetch()) { self::$defaultComponent[$dao->component_type] = $dao->id; } } $value = CRM_Utils_Array::value($type, self::$defaultComponent, $undefined); return $value; }
function buildQuickForm() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); // add form elements $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); //get the mailing groups. $groups = CRM_Core_PseudoConstant::group('Mailing'); $this->add('select', 'includeGroups', 'Select Group', array('' => '- select -') + $groups, true); // Add campaign // Start $mailingId = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL); $campaignId = NULL; if ($mailingId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingId, 'campaign_id'); } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); // End // Add email subject and and template elements // Start $this->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE); CRM_Mailing_BAO_Mailing::commonCompose($this); // End // Advanced options - Tracking options // Start $this->addElement('checkbox', 'override_verp', ts('Track Replies?')); $defaults['override_verp'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies', NULL, FALSE); $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?')); $defaults['url_tracking'] = TRUE; $this->add('checkbox', 'open_tracking', ts('Track Opens?')); //$this->add('checkbox', 'open_tracking', ts('Track Opens?'), '', array('value' => '1'), array('checked' => 'checked')); $defaults['open_tracking'] = TRUE; $this->add('checkbox', 'forward_replies', ts('Forward Replies?')); $defaults['forward_replies'] = FALSE; $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?')); $defaults['auto_responder'] = FALSE; $this->add('select', 'reply_id', ts('Auto-responder'), CRM_Mailing_PseudoConstant::component('Reply'), TRUE); // End // From email address and reply to options // Start $options = array(); // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix $session->getVars($options, "CRM_Mailing_Controller_Send_{$this->controller->_key}"); $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address'); if (empty($fromEmailAddress)) { //redirect user to enter from email address. $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'group=from_email_address&action=add&reset=1'); $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url)); $session->setStatus($status); } else { foreach ($fromEmailAddress as $key => $email) { $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]); } } $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmailAddress, TRUE); //echo "<pre>";print_r ($config);echo "</pre>"; //Added code to add custom field as Reply-To on form when it is enabled from Mailer settings if (isset($config->replyTo) && !empty($config->replyTo) && !CRM_Utils_Array::value('override_verp', $options)) { $this->add('select', 'reply_to_address', ts('Reply-To'), array('' => '- select -') + $fromEmailAddress); } elseif (CRM_Utils_Array::value('override_verp', $options)) { $trackReplies = TRUE; $this->assign('trackReplies', $trackReplies); } // Mailing Header and footer // Start $this->add('select', 'header_id', ts('Mailing Header'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header')); $this->add('select', 'footer_id', ts('Mailing Footer'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer')); // End #@madav getting default header na footer id to tpl #start $this->assign('headerId', key(CRM_Mailing_PseudoConstant::component('Header'))); $this->assign('footerId', key(CRM_Mailing_PseudoConstant::component('Footer'))); #end // Exclude from groups, Innclude/Exclude mailings // Start $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $outG->setButtonAttributes('add', array('value' => ts('Add >>'))); $outG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $mailings = CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inM->setButtonAttributes('add', array('value' => ts('Add >>'))); $outM->setButtonAttributes('add', array('value' => ts('Add >>'))); $inM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $this->assign('mailingCount', count($mailings)); // End $this->addFormRule(array('CRM_Quickbulkemail_Form_QuickBulkEmail', 'formRule')); // Schedule or send // Start //$this->addDateTime('start_date', ts('Schedule Mailing'), FALSE, array('formatType' => 'mailing')); //$this->addElement('checkbox', 'now', ts('Send Immediately')); // End $buttons = array(array('type' => 'next', 'name' => ts('Schedule & Send >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later'))); $this->addButtons($buttons); // export form elements // $this->assign('elementNames', $this->getRenderableElementNames()); parent::buildQuickForm(); }
/** * Build the form object. */ public function buildQuickForm() { // Get the context. $context = $this->get('context'); $this->assign('context', $context); $this->add('text', 'name', ts('Name Your SMS'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); // Get the mailing groups. $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing'); // Get the sms mailing list. $mailings = CRM_Mailing_PseudoConstant::completed('sms'); if (!$mailings) { $mailings = array(); } // run the groups through a hook so users can trim it if needed CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); $select2style = array('multiple' => TRUE, 'style' => 'width: 100%; max-width: 60em;', 'class' => 'crm-select2', 'placeholder' => ts('- select -')); $this->add('select', 'includeGroups', ts('Include Group(s)'), $groups, TRUE, $select2style); $this->add('select', 'excludeGroups', ts('Exclude Group(s)'), $groups, FALSE, $select2style); $this->add('select', 'includeMailings', ts('INCLUDE Recipients of These Message(s)'), $mailings, FALSE, $select2style); $this->add('select', 'excludeMailings', ts('EXCLUDE Recipients of These Message(s)'), $mailings, FALSE, $select2style); $this->addFormRule(array('CRM_SMS_Form_Group', 'formRule')); $buttons = array(array('type' => 'next', 'name' => ts('Next'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); }
/** * Get all mail approval status. * * The static array approvalStatus is returned * * @access public * @static * * @return array - array reference of all mail approval statuses * */ public static function &approvalStatus() { if (!self::$approvalStatus) { require_once 'CRM/Core/OptionGroup.php'; self::$approvalStatus = CRM_Core_OptionGroup::values('mail_approval_status'); } return self::$approvalStatus; }