You are here

function sms_track_archive_write in SMS Framework 6

Same name and namespace in other branches
  1. 6.2 modules/sms_track/sms_track.module \sms_track_archive_write()
  2. 7 modules/sms_track/sms_track.module \sms_track_archive_write()

Write a record to the DB table

Parameters

$direction: Direction integer of message (0=outgoing, 1=incoming)

$number: MSISDN of remote

$message: SMS message body string

$options: Array of additional options

Return value

DB Query result

2 calls to sms_track_archive_write()
sms_track_sms_incoming in modules/sms_track/sms_track.module
Implement hook_sms_incoming()
sms_track_sms_send_process in modules/sms_track/sms_track.module
Implement hook_sms_send_process()

File

modules/sms_track/sms_track.module, line 199
Message tracking feature module for Drupal SMS Framework.

Code

function sms_track_archive_write($dir, $number, $message, $options = array()) {
  $archive_dir = variable_get('sms_track_archive_dir', SMS_DIR_NONE);
  if ($dir == 0) {

    // Outgoing
    if ($archive_dir == SMS_DIR_ALL || $archive_dir == SMS_DIR_OUT) {
      $reference = array_key_exists('reference', $options) ? $options['reference'] : NULL;

      // Status code may be provided by send result handler
      $status = is_array($options['result']) ? $options['result']['status_code'] : NULL;

      // Or render a status code from a simple true/false result
      if (!$status) {
        if ($options['result']) {
          $status = SWS_GW_OK;
        }
        else {
          $status = SMS_GW_ERR_OTHER;
        }
      }
    }
    else {
      return;
    }
  }
  elseif ($dir == 1) {

    // Incoming
    if ($archive_dir == SMS_DIR_ALL || $archive_dir == SMS_DIR_IN) {
      $reference = NULL;

      // Inbound message status is always the same
      $status = SMS_MSG_STATUS_OK;
    }
    else {
      return;
    }
  }
  $gw_number = array_key_exists('gw_number', $options) ? $options['gw_number'] : NULL;
  $created = time();
  $options_z = serialize($options);
  $result = db_query("INSERT INTO {sms_track} (reference, dir, number,\n    gw_number, message, status, created, options) VALUES\n    ('%s', %d, '%s', '%s', '%s', %d, %d, '%s')", $reference, $dir, $number, $gw_number, $message, $status, $created, $options_z);
  if (!$result) {
    $to_from = $dir == 0 ? 'To' : 'From';
    watchdog('sms_track', 'Failed to record message: ' . $to_from . ' ' . $number . ': ' . $message);
  }
}