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');
56 $this->createElement('radio', NULL, NULL, ts('Send immediately'), 'send_immediate', ['id' => 'send_immediate', 'style' => 'margin-bottom: 10px;']),
57 $this->createElement('radio', NULL, NULL, ts('Send at:'), 'send_later', ['id' => 'send_later']),
59 $this->addGroup($sendOptions, 'send_option', '', '<br>');
61 $this->add('datepicker', 'start_date', '', NULL, FALSE, ['minDate' => time()]);
63 $this->addFormRule(['CRM_SMS_Form_Schedule', 'formRule'], $this);
68 'name' => ts('Previous'),
72 'name' => ts('Submit Mass SMS'),
73 'spacing' => ' ',
78 'name' => ts('Continue Later'),
82 $this->addButtons($buttons);
85 $preview['type'] = CRM_Core_DAO
::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID
, 'body_html') ?
'html' : 'text';
86 $preview['viewURL'] = CRM_Utils_System
::url('civicrm/mailing/view', "reset=1&id={$this->_mailingID}");
87 $this->assign_by_ref('preview', $preview);
91 * Form rule to validate the date selector and/or if we should deliver
94 * Warning: if you make changes here, be sure to also make them in
97 * @param array $params
104 * True if either we deliver immediately, or the date is properly
107 public static function formRule($params, $files, $self) {
109 if (!empty($params['_qf_Schedule_submit'])) {
110 CRM_Core_Session
::setStatus(ts("Your Mass SMS has been saved. Click the 'Continue' action to resume working on it."), ts('Saved'), 'success');
111 $url = CRM_Utils_System
::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1&sms=1');
112 CRM_Utils_System
::redirect($url);
115 if ((isset($params['send_option']) && $params['send_option'] == 'send_immediate') || CRM_Utils_Array
::value('_qf_Schedule_back', $params) == ts('Previous')) {
119 if (strtotime($params['start_date']) < time()) {
121 'start_date' => ts('Start date cannot be earlier than the current time.'),
129 * Process the posted form values. Create and schedule a Mass SMS.
131 public function postProcess() {
134 $params['id'] = $this->_mailingID
;
136 if (empty($params['id'])) {
137 CRM_Core_Error
::statusBounce(ts('Could not find a mailing id'));
140 $params['send_option'] = $this->controller
->exportValue($this->_name
, 'send_option');
141 if (isset($params['send_option']) && $params['send_option'] == 'send_immediate') {
142 $params['scheduled_date'] = date('YmdHis');
145 $params['scheduled_date'] = $this->controller
->exportValue($this->_name
, 'start_date');
148 $session = CRM_Core_Session
::singleton();
149 // set the scheduled_id
150 $params['scheduled_id'] = $session->get('userID');
152 // set approval details if workflow is not enabled
153 if (!CRM_Mailing_Info
::workflowEnabled()) {
154 $params['approver_id'] = $session->get('userID');
155 $params['approval_date'] = date('YmdHis');
156 $params['approval_status_id'] = 1;
159 // Build the mailing object.
160 CRM_Mailing_BAO_Mailing
::create($params);
162 $session = CRM_Core_Session
::singleton();
163 $session->pushUserContext(CRM_Utils_System
::url('civicrm/mailing/browse/scheduled',
164 'reset=1&scheduled=true&sms=1'
169 * Display Name of the form.
174 public function getTitle() {
175 return ts('Schedule or Send');