You are here

function sms_muse_command in SMS Framework 5

6 calls to sms_muse_command()
sms_muse_authenticate in modules/sms_muse/sms_muse.module
Menu callback for Javascript validate.
sms_muse_balance in modules/sms_muse/sms_muse.module
sms_muse_get_callback in modules/sms_muse/sms_muse.module
sms_muse_get_session_id in modules/sms_muse/sms_muse.module
Get the session ID
sms_muse_send in modules/sms_muse/sms_muse.module

... See full list

File

modules/sms_muse/sms_muse.module, line 94

Code

function sms_muse_command($command = 'auth', $data = array(), $config = NULL) {
  $gateway = sms_gateways('gateway', 'muse');
  if ($config == NULL) {
    $config = $gateway['configuration'];
  }
  $usesoap = $config['sms_muse_soap'];
  $smsservicename = $config['sms_muse_service'];
  try {
    $client = new SoapClient($usesoap);
  } catch (Exception $error) {
    return array(
      'faultcode' => $error->faultcode,
      'faultstring' => $error->faultstring,
    );
  }
  switch ($command) {
    case 'auth':
      $userid = $config['sms_muse_user'];
      $pwd = $config['sms_muse_password'];
      try {
        $result = $client
          ->userAuthenticate($userid, $pwd);

        //  Remember the token returned in order to send the message
        variable_set('sms_muse_session_id', $result->AuthenticateToken);
        variable_set('sms_clickatell_session_id_timestamp', time());
        return true;
      } catch (Exception $error) {
        return array(
          'faultcode' => $error->faultcode,
          'faultstring' => $error->faultstring,
        );
      }
      break;
    case 'sendmsg':
      if (variable_get('sms_clickatell_session_id_timestamp', 0) < strtotime('-50 mins')) {
        sms_muse_command();
      }
      $user = variable_get('sms_muse_session_id', '');
      try {
        $phonenums = $client
          ->CleanPhoneList($user, $data['number'], $smsservicename);
      } catch (Exception $error) {
        return array(
          'faultcode' => $error->faultcode,
          'faultstring' => $error->faultstring,
        );
      }
      try {
        $result = $client
          ->sendSMS($user, null, $smsservicename, $data['number'], $data['message'], "TEST");
        drupal_set_message("Send message was successful.");
        return true;
      } catch (Exception $error) {
        return array(
          'faultcode' => $error->faultcode,
          'faultstring' => $error->faultstring,
        );
      }
      break;
    case 'setcallback':
      if (variable_get('sms_clickatell_session_id_timestamp', 0) < strtotime('-50 mins')) {
        sms_muse_command();
      }
      $user = variable_get('sms_muse_session_id', '');
      $url = $data['url'];
      try {
        return $client
          ->setCallBackURL($user, null, $smsservicename, $url);
      } catch (Exception $error) {
        drupal_set_message($error->faultstring);
        return array(
          'faultcode' => $error->faultcode,
          'faultstring' => $error->faultstring,
        );
      }
      break;
    case 'getcallback':
      if (variable_get('sms_clickatell_session_id_timestamp', 0) < strtotime('-50 mins')) {
        sms_muse_command();
      }
      $user = variable_get('sms_muse_session_id', '');
      try {
        return $client
          ->getCallBackURL($user, $smsservicename);
      } catch (Exception $error) {
        return $result = array(
          'faultcode' => $error->faultcode,
          'faultstring' => $error->faultstring,
        );
      }
      break;
  }
}