3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_SMS_Form_Schedule
extends CRM_Core_Form
{
19 public $submitOnce = TRUE;
22 * Set variables up before form is built.
24 public function preProcess() {
26 $this->_mailingID
= $this->get('mailing_id');
28 if (!$this->_mailingID
) {
29 $this->_mailingID
= CRM_Utils_Request
::retrieve('mid', 'Integer', $this, TRUE);
34 * Set default values for the form.
36 public function setDefaultValues() {
39 $count = $this->get('count');
41 $this->assign('count', $count);
42 $defaults['send_option'] = 'send_immediate';
47 * Build the form object for the last step of the sms wizard.
49 public function buildQuickform() {
51 // Fix Firefox issue where the non-default field is displayed as checked
53 $this->setAttribute('autocomplete', 'off');
55 $this->addRadio('send_option', '', [
56 'send_immediate' => ts('Send immediately'),
57 'send_later' => ts('Send at:'),
58 ], [], '<br>', FALSE, [
59 'send_immediate' => ['id' => 'send_immediate', 'style' => 'margin-bottom: 10px;'],
60 'send_later' => ['id' => 'send_later'],
63 $this->add('datepicker', 'start_date', '', NULL, FALSE, ['minDate' => date('Y-m-d')]);
65 $this->addFormRule(['CRM_SMS_Form_Schedule', 'formRule'], $this);
70 'name' => ts('Previous'),
74 'name' => ts('Submit Mass SMS'),
75 'spacing' => ' ',
80 'name' => ts('Continue Later'),
84 $this->addButtons($buttons);
87 $preview['type'] = CRM_Core_DAO
::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID
, 'body_html') ?
'html' : 'text';
88 $preview['viewURL'] = CRM_Utils_System
::url('civicrm/mailing/view', "reset=1&id={$this->_mailingID}");
89 $this->assign_by_ref('preview', $preview);
93 * Form rule to validate the date selector and/or if we should deliver
96 * Warning: if you make changes here, be sure to also make them in
99 * @param array $params
106 * True if either we deliver immediately, or the date is properly
109 public static function formRule($params, $files, $self) {
111 if (!empty($params['_qf_Schedule_submit'])) {
112 CRM_Core_Session
::setStatus(ts("Your Mass SMS has been saved. Click the 'Continue' action to resume working on it."), ts('Saved'), 'success');
113 $url = CRM_Utils_System
::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1&sms=1');
114 CRM_Utils_System
::redirect($url);
117 if ((isset($params['send_option']) && $params['send_option'] == 'send_immediate') || CRM_Utils_Array
::value('_qf_Schedule_back', $params) == ts('Previous')) {
121 if (strtotime($params['start_date']) < time()) {
123 'start_date' => ts('Start date cannot be earlier than the current time.'),
131 * Process the posted form values. Create and schedule a Mass SMS.
133 public function postProcess() {
136 $params['id'] = $this->_mailingID
;
138 if (empty($params['id'])) {
139 CRM_Core_Error
::statusBounce(ts('Could not find a mailing id'));
142 $params['send_option'] = $this->controller
->exportValue($this->_name
, 'send_option');
143 if (isset($params['send_option']) && $params['send_option'] == 'send_immediate') {
144 $params['scheduled_date'] = date('YmdHis');
147 $params['scheduled_date'] = $this->controller
->exportValue($this->_name
, 'start_date');
150 $session = CRM_Core_Session
::singleton();
151 // set the scheduled_id
152 $params['scheduled_id'] = $session->get('userID');
154 // set approval details if workflow is not enabled
155 if (!CRM_Mailing_Info
::workflowEnabled()) {
156 $params['approver_id'] = $session->get('userID');
157 $params['approval_date'] = date('YmdHis');
158 $params['approval_status_id'] = 1;
161 // Build the mailing object.
162 CRM_Mailing_BAO_Mailing
::create($params);
164 $session = CRM_Core_Session
::singleton();
165 $session->pushUserContext(CRM_Utils_System
::url('civicrm/mailing/browse/scheduled',
166 'reset=1&scheduled=true&sms=1'
171 * Display Name of the form.
176 public function getTitle() {
177 return ts('Schedule or Send');