<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
* @static
*/
static private $_singleton = array();
- CONST MAX_SMS_CHAR = 160;
+ CONST MAX_SMS_CHAR = 460;
/**
* singleton function used to manage this object
}
function createActivity($apiMsgID, $message, $headers = array(
- ), $jobID = NULL) {
+ ), $jobID = NULL, $userID = NULL) {
if ($jobID) {
$sql = "
SELECT scheduled_id FROM civicrm_mailing m
INNER JOIN civicrm_mailing_job mj ON mj.mailing_id = m.id AND mj.id = %1";
$sourceContactID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($jobID, 'Integer')));
}
+ elseif($userID) {
+ $sourceContactID=$userID;
+ }
else {
$session = CRM_Core_Session::singleton();
$sourceContactID = $session->get('userID');
return false;
}
- $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS', 'name');
+ $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS delivery', 'name');
// note: lets not pass status here, assuming status will be updated by callback
$activityParams = array(
'source_contact_id' => $sourceContactID,
'target_contact_id' => $headers['contact_id'],
'activity_type_id' => $activityTypeID,
'activity_date_time' => date('YmdHis'),
- 'subject' => 'SMS Sent',
'details' => $message,
'result' => $apiMsgID,
);
function processInbound($from, $body, $to = NULL, $trackID = NULL) {
$formatFrom = $this->formatPhone($this->stripPhone($from), $like, "like");
$escapedFrom = CRM_Utils_Type::escape($formatFrom, 'String');
- $fromContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone WHERE phone LIKE "' . $escapedFrom . '"');
+ $fromContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id WHERE !civicrm_contact.is_deleted AND phone LIKE "%' . $escapedFrom . '"');
if (! $fromContactID) {
// unknown mobile sender -- create new contact
if ($to) {
$to = CRM_Utils_Type::escape($to, 'String');
- $toContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone WHERE phone LIKE "' . $to . '"');
+ $toContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id WHERE !civicrm_contact.is_deleted AND phone LIKE "%' . $to . '"');
}
else {
$toContactID = $fromContactID;
if ($fromContactID) {
$actStatusIDs = array_flip(CRM_Core_OptionGroup::values('activity_status'));
- $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS', 'name');
+ $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Inbound SMS', 'name');
// note: lets not pass status here, assuming status will be updated by callback
$activityParams = array(
'target_contact_id' => $fromContactID,
'activity_type_id' => $activityTypeID,
'activity_date_time' => date('YmdHis'),
- 'subject' => 'SMS Received',
'status_id' => $actStatusIDs['Completed'],
'details' => $body,
'phone_number' => $from