ab7384c0af501fce1a14b1afbd7db39c9e1b1dab
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
39 class CRM_SMS_Form_Schedule
extends CRM_Core_Form
{
42 * Function to set variables up before form is built
47 public function preProcess() {
49 $this->_mailingID
= $this->get('mailing_id');
51 if (!$this->_mailingID
) {
52 $this->_mailingID
= CRM_Utils_Request
::retrieve('mid', 'Integer', $this, TRUE);
57 * This function sets the default values for the form.
63 function setDefaultValues() {
66 $count = $this->get('count');
68 $this->assign('count', $count);
74 * Build the form for the last step of the sms wizard
81 public function buildQuickform() {
82 $this->addDateTime('start_date', ts('Schedule SMS'), FALSE, array('formatType' => 'mailing'));
84 $this->addElement('checkbox', 'now', ts('Send Immediately'));
86 $this->addFormRule(array('CRM_SMS_Form_Schedule', 'formRule'), $this);
89 array('type' => 'back',
90 'name' => ts('<< Previous'),
94 'name' => ts('Submit Mass SMS'),
95 'spacing' => ' ',
97 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
101 'name' => ts('Continue Later'),
105 $this->addButtons($buttons);
108 $preview['type'] = CRM_Core_DAO
::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID
, 'body_html') ?
'html' : 'text';
109 $preview['viewURL'] = CRM_Utils_System
::url('civicrm/mailing/view', "reset=1&id={$this->_mailingID}");
110 $this->assign_by_ref('preview', $preview);
114 * Form rule to validate the date selector and/or if we should deliver
117 * Warning: if you make changes here, be sure to also make them in
120 * @param array $params The form values
122 * @return boolean True if either we deliver immediately, or the
123 * date is properly set.
126 public static function formRule($params, $files, $self) {
127 if (!empty($params['_qf_Schedule_submit'])) {
129 CRM_Core_Session
::setStatus(ts("Your Mass SMS has been saved. Click the 'Continue' action to resume working on it."), ts('Saved'), 'success');
130 $url = CRM_Utils_System
::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1&sms=1');
131 CRM_Utils_System
::redirect($url);
133 if (isset($params['now']) || CRM_Utils_Array
::value('_qf_Schedule_back', $params) == '<< Previous') {
137 if (CRM_Utils_Date
::format(CRM_Utils_Date
::processDate($params['start_date'],
138 $params['start_date_time']
139 )) < CRM_Utils_Date
::format(date('YmdHi00'))) {
142 ts('Start date cannot be earlier than the current time.'),
149 * Process the posted form values. Create and schedule a Mass SMS.
156 public function postProcess() {
159 $params['mailing_id'] = $ids['mailing_id'] = $this->_mailingID
;
161 if (empty($params['mailing_id'])) {
162 CRM_Core_Error
::fatal(ts('Could not find a mailing id'));
165 foreach (array('now', 'start_date', 'start_date_time') as $parameter) {
166 $params[$parameter] = $this->controller
->exportValue($this->_name
, $parameter);
169 if ($params['now']) {
170 $params['scheduled_date'] = date('YmdHis');
173 $params['scheduled_date'] = CRM_Utils_Date
::processDate($params['start_date'] . ' ' . $params['start_date_time']);
176 $session = CRM_Core_Session
::singleton();
177 // set the scheduled_id
178 $params['scheduled_id'] = $session->get('userID');
179 $params['scheduled_date'] = date('YmdHis');
181 // set approval details if workflow is not enabled
182 if (!CRM_Mailing_Info
::workflowEnabled()) {
183 $params['approver_id'] = $session->get('userID');
184 $params['approval_date'] = date('YmdHis');
185 $params['approval_status_id'] = 1;
188 if ($params['now']) {
189 $params['scheduled_date'] = date('YmdHis');
192 $params['scheduled_date'] = CRM_Utils_Date
::processDate($params['start_date'] . ' ' . $params['start_date_time']);
195 /* Build the mailing object */
196 CRM_Mailing_BAO_Mailing
::create($params, $ids);
198 $session = CRM_Core_Session
::singleton();
199 $session->pushUserContext(CRM_Utils_System
::url('civicrm/mailing/browse/scheduled',
200 'reset=1&scheduled=true&sms=1'
205 * Display Name of the form
211 public function getTitle() {
212 return ts('Schedule or Send');