X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FAdmin%2FForm%2FScheduleReminders.php;h=154079b8fdec1fb858f39bda65cb0110f47a1b55;hb=892da4a9850da99e44b28e1a12315baf94c63296;hp=cb962cf94438d94411163d60b841bb50fcf25d38;hpb=6643a63b47c9607cdc5f14a739cf7c7cfe55d726;p=civicrm-core.git diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php index cb962cf944..154079b8fd 100644 --- a/CRM/Admin/Form/ScheduleReminders.php +++ b/CRM/Admin/Form/ScheduleReminders.php @@ -135,12 +135,10 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { //reminder_interval $this->add('select', 'start_action_offset', ts('When'), $numericOptions); - $title = ts('Email'); $isActive = ts('Send email'); $recordActivity = ts('Record activity for automated email'); if ($providersCount) { $this->assign('sms', $providersCount); - $title = ts('Email or SMS'); $isActive = ts('Send email or SMS'); $recordActivity = ts('Record activity for automated email or SMS'); $options = CRM_Core_OptionGroup::values('msg_mode'); @@ -152,10 +150,9 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { foreach ($providers as $provider) { $providerSelect[$provider['id']] = $provider['title']; } - $this->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE); + $this->add('select', 'sms_provider_id', ts('SMS Provider'), $providerSelect, TRUE); } - $this->assign('title', $title); foreach ($this->_freqUnits as $val => $label) { $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label)); } @@ -176,7 +173,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $this->addElement('checkbox', 'record_activity', $recordActivity); $this->addElement('checkbox', 'is_repeat', ts('Repeat'), - NULL, array('onclick' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);") + NULL, array('onchange' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);") ); $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay); @@ -186,6 +183,9 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE); $this->add('select', 'end_date', ts('Date Field'), $sel4, TRUE); + $this->add('text', 'from_name', ts('From Name')); + $this->add('text', 'from_email', ts('From Email')); + $recipient = 'activity_contacts'; $recipientListingOptions = array(); @@ -196,11 +196,11 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { ); } - $limitOptions = array(1 => ts('Limit to'), 0 => ts('Addition to')); + $limitOptions = array(1 => ts('Limit to'), 0 => ts('Also include')); $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions); $this->add('select', 'recipient', ts('Recipients'), $sel5[$recipient], - FALSE, array('onClick' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);") + FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);") ); if (!empty($_POST['is_recipient_listing'])) { @@ -209,18 +209,14 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { elseif (!empty($this->_values['recipient_listing'])) { $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']); } - $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'), $recipientListingOptions); - $recipientListing->setMultiple(TRUE); - $this->add('hidden', 'is_recipient_listing', empty($recipientListingOptions) ? FALSE : TRUE, array('id' => 'is_recipient_listing')); + $this->add('select', 'recipient_listing', ts('Recipient Roles'), $recipientListingOptions, FALSE, + array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE)); + $this->add('hidden', 'is_recipient_listing', (int) !empty($recipientListingOptions)); $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE)); - $this->addElement( - 'select', - 'group_id', - ts('Group'), - // CRM-13577 - CRM_Core_PseudoConstant::group() + $this->add('select', 'group_id', ts('Group'), + CRM_Core_PseudoConstant::nestedGroup(), FALSE, array('class' => 'crm-select2 huge') ); CRM_Mailing_BAO_Mailing::commonCompose($this); @@ -232,6 +228,8 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $this->add('checkbox', 'is_active', $isActive); $this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule')); + + $this->setPageTitle(ts('Scheduled Reminder')); } /** * global form rule @@ -244,13 +242,22 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { */ static function formRule($fields) { $errors = array(); - if ((array_key_exists(1, $fields['entity']) && $fields['entity'][1][0] == 0) || + if ((array_key_exists(1, $fields['entity']) && $fields['entity'][1][0] === 0) || (array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] == 0) ) { $errors['entity'] = ts('Please select appropriate value'); } - if (!empty($fields['is_active']) && + if (array_key_exists(1, $fields['entity']) && !is_numeric($fields['entity'][1][0])) { + if (count($fields['entity'][1]) > 1) { + $errors['entity'] = ts('You may only select one contact field per reminder'); + } + elseif (!(array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] > 0)) { + $errors['entity'] = ts('Please select whether the reminder is sent each year.'); + } + } + + if (!empty($fields['is_active']) && $fields['mode'] != 'SMS' && CRM_Utils_System::isNull($fields['subject']) ) { $errors['subject'] = ts('Subject is a required field.'); @@ -273,6 +280,9 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { return empty($errors) ? TRUE : $errors; } + /** + * @return int + */ function setDefaultValues() { if ($this->_action & CRM_Core_Action::ADD) { $defaults['is_active'] = 1; @@ -302,7 +312,9 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { } $defaults['text_message'] = CRM_Utils_Array::value('body_text', $defaults); $defaults['html_message'] = CRM_Utils_Array::value('body_html', $defaults); + $defaults['sms_text_message'] = CRM_Utils_Array::value('sms_body_text', $defaults); $defaults['template'] = CRM_Utils_Array::value('msg_template_id', $defaults); + $defaults['SMStemplate'] = CRM_Utils_Array::value('sms_template_id', $defaults); if (!empty($defaults['group_id'])) { $defaults['recipient'] = 'group'; } @@ -346,12 +358,16 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { 'record_activity', 'limit_to', 'mode', - 'sms_provider_id' + 'sms_provider_id', + 'from_name', + 'from_email', ); foreach ($keys as $key) { $params[$key] = CRM_Utils_Array::value($key, $values); } + $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0); + $moreKeys = array( 'start_action_offset', 'start_action_unit', @@ -367,6 +383,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) { $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate); + $params['is_repeat'] = 0; foreach ($moreKeys as $mkey) { $params[$mkey] = 'null'; } @@ -379,6 +396,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { } $params['body_text'] = CRM_Utils_Array::value('text_message', $values); + $params['sms_body_text'] = CRM_Utils_Array::value('sms_text_message', $values); $params['body_html'] = CRM_Utils_Array::value('html_message', $values); if (CRM_Utils_Array::value('recipient', $values) == 'manual') { @@ -411,7 +429,6 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { } $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0); - $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0); if (CRM_Utils_Array::value('is_repeat', $values) == 0) { $params['repetition_frequency_unit'] = 'null'; @@ -430,6 +447,17 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64); } + $modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS'); + + if ($params['mode'] == 'Email' || empty($params['sms_provider_id'])) { + unset($modePrefixes['SMS']); + } + elseif ($params['mode'] == 'SMS') { + unset($modePrefixes['Mail']); + } + + //TODO: handle postprocessing of SMS and/or Email info based on $modePrefixes + $composeFields = array( 'template', 'saveTemplate', 'updateTemplate', 'saveTemplateName', @@ -437,44 +465,71 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $msgTemplate = NULL; //mail template is composed - $composeParams = array(); - foreach ($composeFields as $key) { - if (!empty($values[$key])) { - $composeParams[$key] = $values[$key]; + foreach ($modePrefixes as $prefix) { + $composeParams = array(); + foreach ($composeFields as $key) { + $key = $prefix . $key; + if (!empty($values[$key])) { + $composeParams[$key] = $values[$key]; + } } - } - - if (!empty($composeParams['updateTemplate'])) { - $templateParams = array( - 'msg_text' => $params['body_text'], - 'msg_html' => $params['body_html'], - 'msg_subject' => $params['subject'], - 'is_active' => TRUE, - ); - - $templateParams['id'] = $values['template']; - - $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); - } - - if (!empty($composeParams['saveTemplate'])) { - $templateParams = array( - 'msg_text' => $params['body_text'], - 'msg_html' => $params['body_html'], - 'msg_subject' => $params['subject'], - 'is_active' => TRUE, - ); - $templateParams['msg_title'] = $composeParams['saveTemplateName']; + if (!empty($composeParams[$prefix . 'updateTemplate'])) { + $templateParams = array('is_active' => TRUE); + if ($prefix == 'SMS') { + $templateParams += array( + 'msg_text' => $params['sms_body_text'], + 'is_sms' => TRUE, + ); + } + else { + $templateParams += array( + 'msg_text' => $params['body_text'], + 'msg_html' => $params['body_html'], + 'msg_subject' => $params['subject'], + ); + } + $templateParams['id'] = $values[$prefix . 'template']; + + $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); + } - $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); - } + if (!empty($composeParams[$prefix . 'saveTemplate'])) { + $templateParams = array('is_active' => TRUE); + if ($prefix == 'SMS') { + $templateParams += array( + 'msg_text' => $params['sms_body_text'], + 'is_sms' => TRUE, + ); + } + else { + $templateParams += array( + 'msg_text' => $params['body_text'], + 'msg_html' => $params['body_html'], + 'msg_subject' => $params['subject'], + ); + } + $templateParams['msg_title'] = $composeParams[$prefix . 'saveTemplateName']; + + $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); + } - if (isset($msgTemplate->id)) { - $params['msg_template_id'] = $msgTemplate->id; - } - else { - $params['msg_template_id'] = CRM_Utils_Array::value('template', $values); + if ($prefix == 'SMS') { + if (isset($msgTemplate->id)) { + $params['sms_template_id'] = $msgTemplate->id; + } + else { + $params['sms_template_id'] = CRM_Utils_Array::value('SMStemplate', $values); + } + } + else { + if (isset($msgTemplate->id)) { + $params['msg_template_id'] = $msgTemplate->id; + } + else { + $params['msg_template_id'] = CRM_Utils_Array::value('template', $values); + } + } } $bao = CRM_Core_BAO_ActionSchedule::add($params);