Fix for CRM-12362
authorDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Wed, 17 Apr 2013 14:03:36 +0000 (19:33 +0530)
committerDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Wed, 17 Apr 2013 14:07:28 +0000 (19:37 +0530)
CRM/SMS/Form/Schedule.php
CRM/SMS/Provider.php
tools/extensions/org.civicrm.sms.clickatell.zip
tools/extensions/org.civicrm.sms.clickatell/org_civicrm_sms_clickatell.php

index 555973d5eb72398bc6b447d238dae958cf3f4b2b..ab7384c0af501fce1a14b1afbd7db39c9e1b1dab 100644 (file)
@@ -162,42 +162,39 @@ class CRM_SMS_Form_Schedule extends CRM_Core_Form {
       CRM_Core_Error::fatal(ts('Could not find a mailing id'));
     }
 
-    foreach (array(
-      'now', 'start_date', 'start_date_time') as $parameter) {
-      $params[$parameter] = $this->controller->exportValue($this->_name,
-        $parameter
-      );
+    foreach (array('now', 'start_date', 'start_date_time') as $parameter) {
+      $params[$parameter] = $this->controller->exportValue($this->_name, $parameter);
     }
 
-    $mailing = new CRM_Mailing_BAO_Mailing();
-    $mailing->id = $ids['mailing_id'];
-    if ($mailing->find(TRUE)) {
-      $job             = new CRM_Mailing_BAO_Job();
-      $job->mailing_id = $mailing->id;
-      $job->is_test    = 0;
-      if ($job->find(TRUE)) {
-        CRM_Core_Error::fatal(ts('A job for this mailing already exists'));
-      }
-
-      if (empty($mailing->is_template)) {
-        $job->status = 'Scheduled';
-        if ($params['now']) {
-          $job->scheduled_date = date('YmdHis');
-        }
-        else {
-          $job->scheduled_date = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']);
-        }
-        $job->save();
-      }
-
-      // also set the scheduled_id
-      $session = CRM_Core_Session::singleton();
-      $mailing->scheduled_id = $session->get('userID');
-      $mailing->scheduled_date = date('YmdHis');
-      $mailing->created_date = CRM_Utils_Date::isoToMysql($mailing->created_date);
-      $mailing->save();
+    if ($params['now']) {
+      $params['scheduled_date'] = date('YmdHis');
+    }
+    else {
+      $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']);
+    }
+
+    $session = CRM_Core_Session::singleton();
+    // set the scheduled_id
+    $params['scheduled_id'] = $session->get('userID');
+    $params['scheduled_date'] = date('YmdHis');
+
+    // set approval details if workflow is not enabled
+    if (!CRM_Mailing_Info::workflowEnabled()) {
+      $params['approver_id'] = $session->get('userID');
+      $params['approval_date'] = date('YmdHis');
+      $params['approval_status_id'] = 1;
     }
 
+    if ($params['now']) {
+      $params['scheduled_date'] = date('YmdHis');
+    }
+    else {
+      $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']);
+    }
+
+    /* Build the mailing object */
+    CRM_Mailing_BAO_Mailing::create($params, $ids);
+
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled',
         'reset=1&scheduled=true&sms=1'
index f72ec43f9e28ff95e0b0111d02fb905c35e5e105..ae9cbeaee6408a6f390f43f21b1103aaec5c3355 100644 (file)
@@ -291,5 +291,17 @@ INNER JOIN civicrm_mailing_job mj ON mj.mailing_id = m.id AND mj.id = %1";
         return $phone;
     }
   }
+
+  function urlEncode($values) {
+    $uri = '';
+    foreach ($values as $key => $value) {
+      $value = urlencode($value);
+      $uri .= "&{$key}={$value}";
+    }
+    if (!empty($uri)) {
+      $uri = substr($uri, 1);
+    }
+    return $uri;
+  }
 }
 
index c64f100796ead4c72ecdd54607c0cc17a9b90aa4..6d8308ce37692a18aaa3ded976c3c6b90dd911bf 100644 (file)
Binary files a/tools/extensions/org.civicrm.sms.clickatell.zip and b/tools/extensions/org.civicrm.sms.clickatell.zip differ
index 1eeac0664dfbbf945338070fd5c38cafdb41e365..6aeeb5d23e8d92437e7e4086329cddd99be687dc 100644 (file)
@@ -184,8 +184,8 @@ class org_civicrm_sms_clickatell extends CRM_SMS_Provider {
         $this->_providerInfo['api_params']['is_test'] == 1 ) {
         $response = array('data' => 'OK:' . rand());
     } else {
-      $postData = CRM_Utils_Array::urlEncode($postDataArray);
-        $response = $this->curl($url, $postData);
+      $postData = $this->urlEncode($postDataArray);
+      $response = $this->curl($url, $postData);
     }
     if (PEAR::isError($response)) {
       return $response;
@@ -271,7 +271,7 @@ class org_civicrm_sms_clickatell extends CRM_SMS_Provider {
         $response = array('data' => 'ID:' . rand());
       }
       else {
-        $postData = CRM_Utils_Array::urlEncode($postDataArray);
+        $postData = $this->urlEncode($postDataArray);
         $response = $this->curl($url, $postData);
       }
       if (PEAR::isError($response)) {