You are here

function shoutbox_edit_form_submit in Shoutbox 5

Same name and namespace in other branches
  1. 6.2 shoutbox.pages.inc \shoutbox_edit_form_submit()
  2. 6 shoutbox.module \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 738
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_id, $form_values) {
  if (is_numeric($form_values['shout_id'])) {

    // Get existing shout object.
    $result = db_query("SELECT * FROM {shoutbox} WHERE shout_id = %d", $form_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_values['uid'], $form_values['nick'], $form_values['shout'], $form_values['url'], $form_values['moderate'], time(), $form_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_values['nick'], $form_values['shout'], $form_values['url'], time(), $form_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('');
}