Merge pull request #6553 from sudhabisht/C12658
[civicrm-core.git] / CRM / Mailing / Form / Schedule.php
index a09e2b09ce1f558d9c60986a0f656d2d954c1762..bed7590956f42172b91837427e723d8950c88c9c 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
   +--------------------------------------------------------------------+
-  | CiviCRM version 4.6                                                |
+  | CiviCRM version 4.7                                                |
   +--------------------------------------------------------------------+
-  | Copyright CiviCRM LLC (c) 2004-2014                                |
+  | Copyright CiviCRM LLC (c) 2004-2015                                |
   +--------------------------------------------------------------------+
   | This file is a part of CiviCRM.                                    |
   |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
 
   /**
-   * Set variables up before form is built
+   * Set variables up before form is built.
    *
    * @return void
    */
   public function preProcess() {
     if (CRM_Mailing_Info::workflowEnabled() &&
-      !CRM_Core_Permission::check('schedule mailings')
+      !CRM_Core_Permission::check('schedule mailings') &&
+      !CRM_Core_Permission::check('access CiviMail')
     ) {
       $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'reset=1&scheduled=false');
       CRM_Utils_System::redirect($url);
@@ -67,6 +68,7 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
       $this->_scheduleFormOnly = TRUE;
     }
   }
+
   /**
    * Set default values for the form.
    *
@@ -87,7 +89,7 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
   }
 
   /**
-   * Build the form object for the last step of the mailing wizard
+   * Build the form object for the last step of the mailing wizard.
    *
    * @param
    *
@@ -102,13 +104,13 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
 
     if ($this->_scheduleFormOnly) {
       $title = ts('Schedule Mailing') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing',
-        $this->_mailingID,
-        'name'
-      );
+          $this->_mailingID,
+          'name'
+        );
       CRM_Utils_System::setTitle($title);
       $buttons = array(
         array(
-      'type' => 'next',
+          'type' => 'next',
           'name' => ts('Submit Mailing'),
           'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;',
           'isDefault' => TRUE,
@@ -162,8 +164,8 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
       $this->_scheduleFormOnly
     ) {
       // add the preview elements
-      $preview            = array();
-      $preview['type']    = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'body_html') ? 'html' : 'text';
+      $preview = array();
+      $preview['type'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'body_html') ? 'html' : 'text';
       $preview['subject'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing',
         $this->_mailingID,
         'subject'
@@ -195,9 +197,9 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
    * @param $files
    * @param $self
    *
-   * @return boolean          True if either we deliver immediately, or the
+   * @return bool
+   *   True if either we deliver immediately, or the
    *                          date is properly set.
-   * @static
    */
   public static function formRule($params, $files, $self) {
     if (!empty($params['_qf_Schedule_submit'])) {
@@ -229,7 +231,7 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
         }
 
         $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
-        $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
+        $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $self);
         if (CRM_Utils_Rule::qfKey($qfKey)) {
           $urlParams .= "&qfKey=$qfKey";
         }
@@ -242,13 +244,14 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
       CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
       CRM_Utils_System::redirect($url);
     }
-    if (isset($params['now']) || CRM_Utils_Array::value('_qf_Schedule_back', $params) == '<< Previous') {
+    if (isset($params['now']) || 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'))) {
+        $params['start_date_time']
+      )) < CRM_Utils_Date::format(date('YmdHi00'))
+    ) {
       return array(
         'start_date' => ts('Start date cannot be earlier than the current time.'),
       );
@@ -341,12 +344,12 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
 
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled',
-        'reset=1&scheduled=true'
-      ));
+      'reset=1&scheduled=true'
+    ));
   }
 
   /**
-   * Display Name of the form
+   * Display Name of the form.
    *
    *
    * @return string
@@ -354,4 +357,5 @@ class CRM_Mailing_Form_Schedule extends CRM_Core_Form {
   public function getTitle() {
     return ts('Schedule or Send');
   }
+
 }