You are here

function shoutbox_add_form_submit in Shoutbox 5

Same name and namespace in other branches
  1. 6.2 shoutbox.module \shoutbox_add_form_submit()
  2. 6 shoutbox.module \shoutbox_add_form_submit()
  3. 7.2 shoutbox.module \shoutbox_add_form_submit()
  4. 7 shoutbox.module \shoutbox_add_form_submit()

Handles submission of a shout.

Handles both ajax submission and regular form submission.

Parameters

$form_id: The form ID of the form.

$form_values: Form values.

File

./shoutbox.module, line 682
shoutbox module displays a block for users to create short messages for thw whole site. Uses AHAH to update the database and display content.

Code

function shoutbox_add_form_submit($form_id, $form_values) {
  global $user;

  // Save the user's nick and url in a cookie for next time (expires in 30 days)
  setcookie("shoutinfo", "{$form_values['nick']}|{$form_values['url']}", time() + 60 * 60 * 24 * 30, '/');
  $moderate = 0;

  // Check user's permission and set shout visibility status accordingly.
  if (!_shoutbox_user_access('post shouts without approval')) {
    $moderate = 1;
  }
  $created = time();

  // Add shout to the database.
  db_query("INSERT INTO {shoutbox} (uid, nick, shout, url, moderate, created, changed, sid) VALUES (%d, '%s', '%s', '%s', %d, %d, %d, '%s')", $user->uid, $form_values['nick'], $form_values['message'], $form_values['url'], $moderate, $created, $created, session_id());

  // If form was not submitted via javascript
  // set a display message and redirect the user back to the form.
  if ($form_values['ajax'] == '0') {
    if ($moderate == 1) {
      drupal_set_message(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));
    }
    else {
      drupal_set_message(t('Your shout has been submitted.'));
    }
    drupal_goto('');
  }
  else {

    // Pull shout out of db and display.
    // We are pulling it out because thats the only way to get th shout_id
    // which is need for edit, etc.
    $shout = db_fetch_object(db_query("SELECT * FROM {shoutbox} WHERE nick = '%s' AND shout = '%s' AND created = %d AND sid = '%s'", $form_values['nick'], $form_values['message'], $created, session_id()));

    // Add shout color.
    $shout->color = $form_values['nextcolor'];
    _shoutbox_sanitize_shout($shout);

    // Add edit/delete links depending on user's permissions.
    $shoutlinks = _shoutbox_get_links($shout);
    $ajax_output = theme('shoutbox_post', $shout, $shoutlinks);
    print $ajax_output;

    // Exit required to stop drupal from redirecting page.
    exit;
  }
}