You are here

function shouts_shout_form_submit in Heartbeat 6.3

Same name and namespace in other branches
  1. 6.4 modules/shouts/shouts.module \shouts_shout_form_submit()

User submitted the shoutform, save the shout.

1 string reference to 'shouts_shout_form_submit'
shouts_menu in modules/shouts/shouts.module
Implementation of hook_menu().

File

modules/shouts/shouts.module, line 138
Gives the possibility to the user to shout a message.

Code

function shouts_shout_form_submit($form = array(), &$form_state = array()) {
  $ahah = empty($form);
  global $user;
  $uid = $user->uid;
  $message = '';
  if (user_access('make shout')) {
    $message = $ahah ? $_POST['shout'] : $form_state['values']['shout'];
  }
  $result = false;
  if (!empty($message)) {
    $sql = "INSERT INTO {shouts} (uid, message, time) VALUES (%d,'%s', '%s')";
    $result = db_query($sql, $uid, $message, date('Y-m-d H:i:s'));
  }
  if ($ahah) {
    if ($result) {
      $comment = new stdClass();
      $comment->comment = $message;
      rules_invoke_event('shout_post', $user, $comment);
      $output = theme('shoutform_message', $message, true, true);
      drupal_json(array(
        'status' => TRUE,
        'data' => $output,
      ));
    }
    else {
      $output = 'error';
      drupal_json(array(
        'status' => TRUE,
        'data' => $output,
      ));
    }
  }
  else {
    if ($result) {
      $comment = new stdClass();
      $comment->comment = $message;
      rules_invoke_event('shout_post', $user, $comment);
      drupal_set_message(t('Shout has been posted.'));
    }
    else {
      drupal_set_message(t('Error while posting shout.'));
    }
  }
}