public function buildQuickForm() {
parent::buildQuickForm();
$this->_mappingID = $mappingID = NULL;
+ $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
if ($this->_action & (CRM_Core_Action::DELETE)) {
$reminderName =
//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) {
+ $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');
+ $this->add('select', 'mode', ts('Send as'), $options);
+
+ $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
+
+ $providerSelect = array();
+ foreach ($providers as $provider) {
+ $providerSelect[$provider['id']] = $provider['title'];
+ }
+ $this->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE);
+ }
+ $this->assign('title', $title);
foreach ($this->_freqUnits as $val => $label) {
$freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
}
$this->add('select', 'start_action_date', ts('Date Field'), $sel4, TRUE);
- $this->addElement('checkbox', 'record_activity', ts('Record activity for automated email'));
+ $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);")
CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject')
);
- $this->add('checkbox', 'is_active', ts('Send email'));
+ $this->add('checkbox', 'is_active', $isActive);
$this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule'));
}
function setDefaultValues() {
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['is_active'] = 1;
+ $defaults['mode'] = 'Email';
$defaults['record_activity'] = 1;
}
else {
'absolute_date',
'group_id',
'record_activity',
- 'limit_to'
+ 'limit_to',
+ 'mode',
+ 'sms_provider_id'
);
foreach ($keys as $key) {
$params[$key] = CRM_Utils_Array::value($key, $values);
return $list;
}
- static function sendReminder($contactId, $email, $scheduleID, $from, $tokenParams) {
-
+ static function sendReminder($contactId, $to, $scheduleID, $from, $tokenParams) {
+ $email = $to['email'];
+ $phoneNumber = $to['phone'];
$schedule = new CRM_Core_DAO_ActionSchedule();
$schedule->id = $scheduleID;
$messageSubject = $smarty->fetch("string:{$messageSubject}");
- // set up the parameters for CRM_Utils_Mail::send
- $mailParams = array(
- 'groupName' => 'Scheduled Reminder Sender',
- 'from' => $from,
- 'toName' => $contact['display_name'],
- 'toEmail' => $email,
- 'subject' => $messageSubject,
- 'entity' => 'action_schedule',
- 'entity_id' => $scheduleID,
- );
+ if ($schedule->mode == 'SMS' or $schedule->mode == 'User_Preference') {
+ $session = CRM_Core_Session::singleton();
+ $userID = $session->get('userID') ? $session->get('userID') : $contactId;
+ $smsParams = array('To' => $phoneNumber, 'provider_id' => $schedule->sms_provider_id, 'activity_subject' => $messageSubject);
+ $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type',
+ 'SMS',
+ 'name'
+ );
+ $details = $html ? $html : $text;
+ $activityParams = array(
+ 'source_contact_id' => $userID,
+ 'activity_type_id' => $activityTypeID,
+ 'activity_date_time' => date('YmdHis'),
+ 'subject' => $messageSubject,
+ 'details' => $details,
+ 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'),
+ );
+
+ $activity = CRM_Activity_BAO_Activity::create($activityParams);
- if (!$html || $contact['preferred_mail_format'] == 'Text' ||
- $contact['preferred_mail_format'] == 'Both'
- ) {
- // render the & entities in text mode, so that the links work
- $mailParams['text'] = str_replace('&', '&', $text);
+ CRM_Activity_BAO_Activity::sendSMSMessage($contactId,
+ $text,
+ $html,
+ $smsParams,
+ $activity->id,
+ $userID
+ );
}
- if ($html && ($contact['preferred_mail_format'] == 'HTML' ||
+
+ if ($schedule->mode == 'Email' or $schedule->mode == 'User_Preference') {
+ // set up the parameters for CRM_Utils_Mail::send
+ $mailParams = array(
+ 'groupName' => 'Scheduled Reminder Sender',
+ 'from' => $from,
+ 'toName' => $contact['display_name'],
+ 'toEmail' => $email,
+ 'subject' => $messageSubject,
+ 'entity' => 'action_schedule',
+ 'entity_id' => $scheduleID,
+ );
+
+ if (!$html || $contact['preferred_mail_format'] == 'Text' ||
$contact['preferred_mail_format'] == 'Both'
- )) {
- $mailParams['html'] = $html;
+ ) {
+ // render the & entities in text mode, so that the links work
+ $mailParams['text'] = str_replace('&', '&', $text);
+ }
+ if ($html && ($contact['preferred_mail_format'] == 'HTML' ||
+ $contact['preferred_mail_format'] == 'Both'
+ )
+ ) {
+ $mailParams['html'] = $html;
+ }
+ $result = CRM_Utils_Mail::send($mailParams);
}
-
- $result = CRM_Utils_Mail::send($mailParams);
}
$schedule->free();
}
$isError = 0;
- $errorMsg = '';
- $toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($dao->contactID);
- if ($toEmail) {
+ $errorMsg = $toEmail = $toPhoneNumber = '';
+
+ if ($actionSchedule->mode == 'SMS' or $actionSchedule->mode == 'User_Preference') {
+ $filters = array('is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0);
+ $toPhoneNumbers = CRM_Core_BAO_Phone::allPhones($dao->contactID, FALSE, 'Mobile', $filters);
+ //to get primary mobile ph,if not get a first mobile phONE
+ if (!empty($toPhoneNumbers)) {
+ $toPhoneNumberDetails = reset($toPhoneNumbers);
+ $toPhoneNumber = CRM_Utils_Array::value('phone', $toPhoneNumberDetails);
+ //contact allows to send sms
+ $toDoNotSms = 0;
+ }
+ }
+ if ($actionSchedule->mode == 'Email' or $actionSchedule->mode == 'User_Preference') {
+ $toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($dao->contactID);
+ }
+ if ($toEmail || !(empty($toPhoneNumber) or $toDoNotSms)) {
+ $to['email'] = $toEmail;
+ $to['phone'] = $toPhoneNumber;
$result =
CRM_Core_BAO_ActionSchedule::sendReminder(
$dao->contactID,
- $toEmail,
+ $to,
$actionSchedule->id,
$fromEmailAddress,
$entityTokenParams
UPDATE `civicrm_option_value`
SET is_reserved = 1
-WHERE is_reserved = 0 AND option_group_id = @option_group_id_activity_type AND component_id = @caseCompId;
\ No newline at end of file
+WHERE is_reserved = 0 AND option_group_id = @option_group_id_activity_type AND component_id = @caseCompId;
+
+-- CRM-13912
+ALTER TABLE civicrm_action_schedule
+ADD COLUMN `mode` varchar(128) COLLATE utf8_unicode_ci DEFAULT 'Email' COMMENT 'Send the message as email or sms or both.';
+
+INSERT INTO
+civicrm_option_group (name, {localize field='title'}title{/localize}, is_reserved, is_active)
+VALUES
+('msg_mode', {localize}'{ts escape="sql"}Message Mode{/ts}'{/localize}, 1, 1);
+
+SELECT @option_group_id_msg_mode := max(id) from civicrm_option_group where name = 'msg_mode';
+
+INSERT INTO
+civicrm_option_value (option_group_id, label, value, name, is_default, weight, is_reserved, is_active)
+VALUES
+(@option_group_id_msg_mode, {localize}'{ts escape="sql"}Email{/ts}'{/localize}, 'Email', 'Email', 1, 1, 1, 1),
+(@option_group_id_msg_mode, {localize}'{ts escape="sql"}SMS{/ts}'{/localize},'SMS', 'SMS', 0, 2, 1, 1),
+(@option_group_id_msg_mode, {localize}'{ts escape="sql"}User Preference{/ts}'{/localize}, 'User_Preference', 'User Preference', 0, 3, 1, 1);
<td class="label">{$form.group_id.label}</td>
<td>{$form.group_id.html}</td>
</tr>
+ <tr id="msgMode" class="crm-scheduleReminder-form-block-mode">
+ <td class="label">{$form.mode.label}</td>
+ <td>{$form.mode.html}</td>
+ </tr>
+ <tr id="smsProvider" class="crm-scheduleReminder-form-block-sms_provider_id">
+ <td class="label">{$form.sms_provider_id.label}</td>
+ <td>{$form.sms_provider_id.html}</td>
+ </tr>
</table>
<fieldset id="compose_id"><legend>{ts}Email{/ts}</legend>
<table id="email-field-table" class="form-layout-compressed">
</tr>
</table>
- {include file="CRM/Contact/Form/Task/EmailCommon.tpl" upload=1 noAttach=1}
+ <div id="email">{include file="CRM/Contact/Form/Task/EmailCommon.tpl" upload=1 noAttach=1}</div>
+ <div id="sms">{include file="CRM/Contact/Form/Task/SMSCommon.tpl" upload=1 noAttach=1}</div>
</fieldset>
{include file="CRM/common/showHideByFieldValue.tpl"
});
});
- cj(function() {
+ cj(function () {
+ loadMsgBox();
+ cj('#mode').change(function () {
+ loadMsgBox();
+ });
+ });
+
+ function loadMsgBox() {
+ if (cj('#mode').val() == 'Email' || cj('#mode').val() == 0){
+ cj('#sms').hide();
+ cj('#smsProvider').hide();
+ cj('#email').show();
+ }
+ else if (cj('#mode').val() == 'SMS'){
+ cj('#email').hide();
+ cj('#sms').show();
+ cj('#smsProvider').show();
+ }
+ else if (cj('#mode').val() == 'User_Preference'){
+ cj('#email').show();
+ cj('#sms').show();
+ cj('#smsProvider').show();
+ }
+ }
+
+ cj(function() {
if ( cj('#is_recipient_listing').val( ) ) {
cj('#recipientList').show();
} else {
<comment>Date on which the reminder be sent.</comment>
<add>4.1</add>
</field>
+ <field>
+ <name>mode</name>
+ <title>Message Mode</title>
+ <default>"Email"</default>
+ <type>varchar</type>
+ <length>128</length>
+ <comment>Send the message as email or sms or both.</comment>
+ <pseudoconstant>
+ <optionGroupName>msg_mode</optionGroupName>
+ </pseudoconstant>
+ <html>
+ <type>Select</type>
+ </html>
+ <add>4.5</add>
+ </field>
+ <field>
+ <name>sms_provider_id</name>
+ <type>int unsigned</type>
+ <add>4.5</add>
+ <html>
+ <type>Select</type>
+ </html>
+ </field>
+ <foreignKey>
+ <name>sms_provider_id</name>
+ <table>civicrm_sms_provider</table>
+ <key>id</key>
+ <onDelete>SET NULL</onDelete>
+ <add>4.5</add>
+ </foreignKey>
</table>
('financial_item_status' , '{ts escape="sql"}Financial Item Status{/ts}' , 1, 1),
('label_type' , '{ts escape="sql"}Label Type{/ts}' , 1, 1),
('name_badge' , '{ts escape="sql"}Name Badge Format{/ts}' , 1, 1),
- ('communication_style' , '{ts escape="sql"}Communication Style{/ts}' , 1, 1);
+ ('communication_style' , '{ts escape="sql"}Communication Style{/ts}' , 1, 1),
+ ('msg_mode' , '{ts escape="sql"}Message Mode{/ts}' , 1, 1);
SELECT @option_group_id_pcm := max(id) from civicrm_option_group where name = 'preferred_communication_method';
SELECT @option_group_id_act := max(id) from civicrm_option_group where name = 'activity_type';
SELECT @option_group_id_label_type := max(id) from civicrm_option_group where name = 'label_type';
SELECT @option_group_id_name_badge := max(id) from civicrm_option_group where name = 'name_badge';
SELECT @option_group_id_communication_style := max(id) from civicrm_option_group where name = 'communication_style';
-
+SELECT @option_group_id_msg_mode := max(id) from civicrm_option_group where name = 'msg_mode';
SELECT @contributeCompId := max(id) FROM civicrm_component where name = 'CiviContribute';
SELECT @eventCompId := max(id) FROM civicrm_component where name = 'CiviEvent';
-- Communication Styles
(@option_group_id_communication_style, '{ts escape="sql"}Formal{/ts}' , 1, 'formal' , NULL, 0, 1, 1, NULL, 0, 0, 1, NULL, NULL),
- (@option_group_id_communication_style, '{ts escape="sql"}Familiar{/ts}', 2, 'familiar', NULL, 0, 0, 2, NULL, 0, 0, 1, NULL, NULL);
+ (@option_group_id_communication_style, '{ts escape="sql"}Familiar{/ts}', 2, 'familiar', NULL, 0, 0, 2, NULL, 0, 0, 1, NULL, NULL),
+
+-- Message Mode
+(@option_group_id_msg_mode, '{ts escape="sql"}Email{/ts}', 'Email', 'Email', NULL, 0, 1, 1, NULL, 0, 1, 1, NULL, NULL),
+(@option_group_id_msg_mode, '{ts escape="sql"}SMS{/ts}', 'SMS', 'SMS', NULL, 0, 0, 2, NULL, 0, 1, 1, NULL, NULL),
+(@option_group_id_msg_mode, '{ts escape="sql"}User Preference{/ts}', 'User_Preference', 'User Preference', NULL, 0, 0, 3, NULL, 0, 1, 1, NULL, NULL);
-- financial accounts
SELECT @opval := value FROM civicrm_option_value WHERE name = 'Revenue' and option_group_id = @option_group_id_fat;