/** * Send an SMS Message via the Clickatell API Server * * @param array the message with a to/from/text * * @return mixed true on sucess or PEAR_Error object * @access public */ function send($recipients, $header, $message, $jobID = NULL) { if ($this->_apiType = 'http') { $postDataArray = array(); $url = $this->formURLPostData("/http/sendmsg", $postDataArray); if (array_key_exists('from', $this->_providerInfo['api_params'])) { $postDataArray['from'] = $this->_providerInfo['api_params']['from']; } $postDataArray['to'] = $header['To']; $postDataArray['text'] = substr($message, 0, 160); // max of 160 characters, is probably not multi-lingual if (array_key_exists('mo', $this->_providerInfo['api_params'])) { $postDataArray['mo'] = $this->_providerInfo['api_params']['mo']; } // sendmsg with callback request: $postDataArray['callback'] = 3; $isTest = 0; if (array_key_exists('is_test', $this->_providerInfo['api_params']) && $this->_providerInfo['api_params']['is_test'] == 1) { $isTest = 1; } /** * Check if we are using a queue when sending as each account * with Clickatell is assigned three queues namely 1, 2 and 3. */ if (isset($header['queue']) && is_numeric($header['queue'])) { if (in_array($header['queue'], range(1, 3))) { $postDataArray['queue'] = $header['queue']; } } /** * Must we escalate message delivery if message is stuck in * the queue at Clickatell? */ if (isset($header['escalate']) && !empty($header['escalate'])) { if (is_numeric($header['escalate'])) { if (in_array($header['escalate'], range(1, 2))) { $postDataArray['escalate'] = $header['escalate']; } } } if ($isTest == 1) { $response = array('data' => 'ID:' . rand()); } else { $postData = CRM_Utils_Array::urlEncode($postDataArray); $response = $this->curl($url, $postData); } if (PEAR::isError($response)) { return $response; } $send = explode(":", $response['data']); if ($send[0] == "ID") { //trim whitespace around the id $apiMsgID = trim($send[1], " \t\r\n"); $this->createActivity($apiMsgID, $message, $header, $jobID); return $apiMsgID; } else { // delete any parent activity & throw error if (CRM_Utils_Array::value('parent_activity_id', $header)) { $params = array('id' => $header['parent_activity_id']); CRM_Activity_BAO_Activity::deleteActivity($params); } return PEAR::raiseError($response['data']); } } }