$count = $this->get('count');
$this->assign('count', $count);
- $defaults['now'] = 1;
+ $defaults['send_option'] = 'send_immediate';
return $defaults;
}
* Build the form object for the last step of the sms wizard.
*/
public function buildQuickform() {
- $this->addDateTime('start_date', ts('Schedule SMS'), FALSE, array('formatType' => 'mailing'));
- $this->addElement('checkbox', 'now', ts('Send Immediately'));
+ // Fix Firefox issue where the non-default field is displayed as checked
+ // on page refresh.
+ $this->setAttribute('autocomplete', 'off');
+
+ $sendOptions = [
+ $this->createElement('radio', NULL, NULL, 'Send immediately', 'send_immediate', ['id' => 'send_immediate', 'style' => 'margin-bottom: 10px;']),
+ $this->createElement('radio', NULL, NULL, 'Send at:', 'send_later', ['id' => 'send_later']),
+ ];
+ $this->addGroup($sendOptions, 'send_option', '', '<br>');
+
+ $this->add('datepicker', 'start_date', '', NULL, FALSE, ['minDate' => time()]);
$this->addFormRule(array('CRM_SMS_Form_Schedule', 'formRule'), $this);
* set.
*/
public static function formRule($params, $files, $self) {
- if (!empty($params['_qf_Schedule_submit'])) {
+ if (!empty($params['_qf_Schedule_submit'])) {
CRM_Core_Session::setStatus(ts("Your Mass SMS has been saved. Click the 'Continue' action to resume working on it."), ts('Saved'), 'success');
$url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1&sms=1');
CRM_Utils_System::redirect($url);
}
- if (isset($params['now']) || CRM_Utils_Array::value('_qf_Schedule_back', $params) == ts('Previous')) {
+
+ if ((isset($params['send_option']) && $params['send_option'] == 'send_immediate') || CRM_Utils_Array::value('_qf_Schedule_back', $params) == ts('Previous')) {
return TRUE;
}
- if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($params['start_date'],
- $params['start_date_time']
- )) < CRM_Utils_Date::format(date('YmdHi00'))
- ) {
+ if (strtotime($params['start_date']) < time()) {
return array(
'start_date' => ts('Start date cannot be earlier than the current time.'),
);
}
+
return TRUE;
}
/**
- * Process the posted form values. Create and schedule a Mass SMS.
+ * Process the posted form values. Create and schedule a Mass SMS.
*/
public function postProcess() {
$params = array();
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']) {
+ $send_option = $this->controller->exportValue($this->_name, 'send_option');
+ if (isset($params['send_option']) && $params['send_option'] == 'send_immediate') {
$params['scheduled_date'] = date('YmdHis');
}
else {
- $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']);
+ $params['scheduled_date'] = $this->controller->exportValue($this->_name, 'start_date');
}
$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['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);
</div>
{include file="CRM/Mailing/Form/Count.tpl"}
-<table class="form-layout">
- <tbody>
- <tr class="crm-sms-schedule-form-block-now">
- <td class="label">{$form.now.label}</td>
- <td>{$form.now.html}</td>
- </tr>
- <tr>
- <td class="label">{ts}OR{/ts}</td>
- <td> </td>
- </tr>
- <tr class="crm-sms-schedule-form-block-start_date">
- <td class="label">{$form.start_date.label}</td>
- <td>{include file="CRM/common/jcalendar.tpl" elementName=start_date}
- <div class="description">{ts}Set a date and time when you want CiviSMS to start sending this Mass SMS.{/ts}</div>
- </td>
- </tr>
- </tbody>
-</table>
+<div>
+ <div>
+ <div>
+ {$form.send_option.html}
+ <span class="start_date_elements">{$form.start_date.html}</span>
+ </div>
+
+ </div>
+ <div class="description">{ts}Set a date and time when you want CiviSMS to start sending this Mass SMS.{/ts}</div>
+</div>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl"}</div>
{if $preview}
<script type="text/javascript">
{literal}
CRM.$(function($) {
- $('#start_date_display').change(function() {
- $('#now').prop('checked', !$(this).val());
+
+ // If someone changes the schedule date, auto-select the 'send at' option
+ $(".start_date_elements input").change(function() {
+ $('#send_immediate').prop('checked', false);
+ $('#send_later').prop('checked', true);
});
- $('#now').change(function() {
+
+ // Clear scheduled date/time when send immediately is selected
+ $("#send_immediate").change(function() {
if ($(this).prop('checked')) {
- $('#start_date_display, #start_date, #start_date_time').val('');
- } else {
- $('#start_date_display').focus();
+ $(".start_date_elements input").val('');
+ $(".start_date_elements input").siblings("a.crm-clear-link").css('visibility', 'hidden');
}
});
+
});
{/literal}
</script>