You are here

function shoutbox_edit_form_submit in Shoutbox 6

Same name and namespace in other branches
  1. 5 shoutbox.module \shoutbox_edit_form_submit()
  2. 6.2 shoutbox.pages.inc \shoutbox_edit_form_submit()
  3. 7.2 shoutbox.pages.inc \shoutbox_edit_form_submit()
  4. 7 shoutbox.pages.inc \shoutbox_edit_form_submit()

Handle the edit form submission.

Parameters

$form_id: The form ID of the form.

$form_values: Form values.

File

./shoutbox.module, line 701
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_edit_form_submit($form, $form_state) {
  if (is_numeric($form_state['values']['shout_id'])) {

    // Get existing shout object.
    $result = db_query("SELECT * FROM {shoutbox} WHERE shout_id = %d", $form_state['values']['shout_id']);
    $existing_shout = db_fetch_object($result);

    // If the user is a shoutbox admin they can edit any shout.
    if (_shoutbox_user_access('administer shoutbox')) {
      db_query("UPDATE {shoutbox} SET uid=%d, nick='%s', shout='%s', url='%s', moderate=%d, changed=%d WHERE shout_id=%d", $form_state['values']['uid'], $form_state['values']['nick'], $form_state['values']['shout'], $form_state['values']['url'], $form_state['values']['moderate'], time(), $form_state['values']['shout_id']);
      drupal_set_message(t('The shout has been saved.'));
    }
    else {
      if (_shoutbox_user_access('edit own shouts', $existing_shout)) {
        db_query("UPDATE {shoutbox} SET nick='%s', shout='%s', url='%s', changed=%d WHERE shout_id=%d", $form_state['values']['nick'], $form_state['values']['shout'], $form_state['values']['url'], time(), $form_state['values']['shout_id']);
        drupal_set_message(t('Your shout has been saved.'));
      }
      else {
        shoutbox_set_message(t('You do not have permission to edit this shout.'));
      }
    }
  }
  else {
    return drupal_not_found();
  }
  drupal_goto('');
}