3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_SMS_Form_Schedule
extends CRM_Core_Form
{
36 * Set variables up before form is built.
38 public function preProcess() {
40 $this->_mailingID
= $this->get('mailing_id');
42 if (!$this->_mailingID
) {
43 $this->_mailingID
= CRM_Utils_Request
::retrieve('mid', 'Integer', $this, TRUE);
48 * Set default values for the form.
50 public function setDefaultValues() {
53 $count = $this->get('count');
55 $this->assign('count', $count);
56 $defaults['send_option'] = 'send_immediate';
61 * Build the form object for the last step of the sms wizard.
63 public function buildQuickform() {
65 // Fix Firefox issue where the non-default field is displayed as checked
67 $this->setAttribute('autocomplete', 'off');
70 $this->createElement('radio', NULL, NULL, ts('Send immediately'), 'send_immediate', ['id' => 'send_immediate', 'style' => 'margin-bottom: 10px;']),
71 $this->createElement('radio', NULL, NULL, ts('Send at:'), 'send_later', ['id' => 'send_later']),
73 $this->addGroup($sendOptions, 'send_option', '', '<br>');
75 $this->add('datepicker', 'start_date', '', NULL, FALSE, ['minDate' => time()]);
77 $this->addFormRule(['CRM_SMS_Form_Schedule', 'formRule'], $this);
82 'name' => ts('Previous'),
86 'name' => ts('Submit Mass SMS'),
87 'spacing' => ' ',
89 'js' => ['onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"],
93 'name' => ts('Continue Later'),
97 $this->addButtons($buttons);
100 $preview['type'] = CRM_Core_DAO
::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID
, 'body_html') ?
'html' : 'text';
101 $preview['viewURL'] = CRM_Utils_System
::url('civicrm/mailing/view', "reset=1&id={$this->_mailingID}");
102 $this->assign_by_ref('preview', $preview);
106 * Form rule to validate the date selector and/or if we should deliver
109 * Warning: if you make changes here, be sure to also make them in
112 * @param array $params
119 * True if either we deliver immediately, or the date is properly
122 public static function formRule($params, $files, $self) {
124 if (!empty($params['_qf_Schedule_submit'])) {
125 CRM_Core_Session
::setStatus(ts("Your Mass SMS has been saved. Click the 'Continue' action to resume working on it."), ts('Saved'), 'success');
126 $url = CRM_Utils_System
::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1&sms=1');
127 CRM_Utils_System
::redirect($url);
130 if ((isset($params['send_option']) && $params['send_option'] == 'send_immediate') || CRM_Utils_Array
::value('_qf_Schedule_back', $params) == ts('Previous')) {
134 if (strtotime($params['start_date']) < time()) {
136 'start_date' => ts('Start date cannot be earlier than the current time.'),
144 * Process the posted form values. Create and schedule a Mass SMS.
146 public function postProcess() {
149 $params['mailing_id'] = $ids['mailing_id'] = $this->_mailingID
;
151 if (empty($params['mailing_id'])) {
152 CRM_Core_Error
::fatal(ts('Could not find a mailing id'));
155 $params['send_option'] = $this->controller
->exportValue($this->_name
, 'send_option');
156 if (isset($params['send_option']) && $params['send_option'] == 'send_immediate') {
157 $params['scheduled_date'] = date('YmdHis');
160 $params['scheduled_date'] = $this->controller
->exportValue($this->_name
, 'start_date');
163 $session = CRM_Core_Session
::singleton();
164 // set the scheduled_id
165 $params['scheduled_id'] = $session->get('userID');
167 // set approval details if workflow is not enabled
168 if (!CRM_Mailing_Info
::workflowEnabled()) {
169 $params['approver_id'] = $session->get('userID');
170 $params['approval_date'] = date('YmdHis');
171 $params['approval_status_id'] = 1;
174 // Build the mailing object.
175 CRM_Mailing_BAO_Mailing
::create($params, $ids);
177 $session = CRM_Core_Session
::singleton();
178 $session->pushUserContext(CRM_Utils_System
::url('civicrm/mailing/browse/scheduled',
179 'reset=1&scheduled=true&sms=1'
184 * Display Name of the form.
189 public function getTitle() {
190 return ts('Schedule or Send');