You are here

function smiley_overview_form_submit in Smiley 7

Smileys form submit.

File

./smiley.admin.inc, line 122
Smileys administrative pages.

Code

function smiley_overview_form_submit($form, &$form_state) {
  $values = $form_state['values'];
  $delete = array();
  $update_cnt = 0;
  foreach ($values as $sid => $value) {
    if (is_array($value) && !empty($value['uri'])) {
      $smiley = (object) $value;
      $smiley->sid = $sid;
      $smiley->description = strip_tags($smiley->description);

      // Adding.
      if ($sid == 'new') {
        unset($smiley->sid);
        drupal_write_record('smiley', $smiley);
        drupal_set_message(t('New smiley has been added.'));
      }
      elseif ($value['delete']) {
        $delete[] = $sid;
      }
      else {
        $update_cnt++;
        drupal_write_record('smiley', $smiley, 'sid');
      }
    }
  }
  if ($update_cnt) {
    drupal_set_message(format_plural($update_cnt, 'Updated 1 smiley.', '@count smiley has been updated'));
  }

  // Deleting.
  if ($delete) {
    $num_deleted = db_delete('smiley')
      ->condition('sid', $delete, 'IN')
      ->execute();
    drupal_set_message(format_plural($num_deleted, 'Deleted 1 smiley.', '@count smiley has been deleted'));
  }
}