You are here

function sms_devel_virtualgw_js_getactivity in SMS Framework 6.2

Same name and namespace in other branches
  1. 6 modules/sms_devel/sms_devel.virtualgw.inc \sms_devel_virtualgw_js_getactivity()
  2. 7 modules/sms_devel/sms_devel.virtualgw.inc \sms_devel_virtualgw_js_getactivity()
1 string reference to 'sms_devel_virtualgw_js_getactivity'
sms_devel_menu in modules/sms_devel/sms_devel.module
Implement hook_menu()

File

modules/sms_devel/sms_devel.virtualgw.inc, line 121
Virtual Gateway for the sms_devel module of the SMS Framework.

Code

function sms_devel_virtualgw_js_getactivity() {

  // We should not need to get a default limit - expect it in the request
  $limit = 50;

  // Get limit from request
  if (array_key_exists('rows', $_REQUEST)) {
    $limit = $_REQUEST['rows'];
  }

  // Handle zero or null limit
  if (!$limit) {
    $limit = 1;
  }
  $lines = array();
  $result = db_query("SELECT * FROM {sms_devel_virtualgw} ORDER BY created LIMIT %d", $limit);
  while ($row = db_fetch_object($result)) {
    $options = unserialize($row->options);
    switch ($row->type) {
      case SMS_DEVEL_VIRTUALGW_TYPE_OUT:
        $from = $options['sender'];
        $to = $row->number;
      case SMS_DEVEL_VIRTUALGW_TYPE_IN:
        $from = $row->number;
        $to = $options['sender'];
      case SMS_DEVEL_VIRTUALGW_TYPE_RECEIPT:

        // Receipt
    }
    $dir = $row->type;
    $msg = $row->message;
    $lines[] = "{$dir} {$from} {$to} {$msg}";
  }
  $output = implode("\n", $lines);
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];

  // Get the form from the cache.
  $form = form_get_cache($form_build_id, $form_state);
  $args = $form['#parameters'];
  $form_id = array_shift($args);

  // We will run some of the submit handlers so we need to disable redirecting.
  $form['#redirect'] = FALSE;

  // We need to process the form, prepare for that by setting a few internals
  // variables.
  $form['#post'] = $_POST;
  $form['#programmed'] = FALSE;
  $form_state['post'] = $_POST;

  // Build, validate and if possible, submit the form.
  drupal_process_form($form_id, $form, $form_state);

  // This call recreates the form relying solely on the form_state that the
  // drupal_process_form set up.
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Render the new output.
  $logfield = $form['sms_devel_virtualgw_log']['sms_devel_virtualgw_logfield'];
  $logfield['#value'] = $output;
  unset($logfield['#prefix'], $logfield['#suffix']);

  // Prevent duplicate wrappers.
  $output = drupal_render($logfield);
  return drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}