You are here

function download_count_reset_form_submit in Download Count 7.3

Same name and namespace in other branches
  1. 6.2 includes/download_count.pages.inc \download_count_reset_form_submit()
  2. 7.2 includes/download_count.pages.inc \download_count_reset_form_submit()

Implements hook_submit().

File

includes/download_count.pages.inc, line 198
Administrative page callbacks for the download_count module.

Code

function download_count_reset_form_submit($form, &$form_state) {
  $result = NULL;
  if ($form['dcid']['#value'] == 'all') {
    $result = db_truncate('download_count')
      ->execute();
    if ($result) {
      db_truncate('download_count_cache')
        ->execute();
      drupal_set_message(t('All download counts have been reset.'));
      watchdog('download_count', 'All download counts have been reset.', array(), WATCHDOG_NOTICE);
    }
    else {
      drupal_set_message(t('Unable to reset all download counts.'), 'error');
      watchdog('download_count', 'Unable to reset all download counts.', array(), WATCHDOG_ERROR);
    }
  }
  else {
    $result = db_delete('download_count')
      ->condition('fid', $form['fid']['#value'])
      ->condition('type', $form['type']['#value'])
      ->condition('id', $form['id']['#value'])
      ->execute();
    if ($result) {
      db_delete('download_count_cache')
        ->condition('fid', $form['fid']['#value'])
        ->condition('type', $form['type']['#value'])
        ->condition('id', $form['id']['#value'])
        ->execute();
      drupal_set_message(t('Download count for %filename on %type %id was reset.', array(
        '%filename' => $form['filename']['#value'],
        '%type' => $form['type']['#value'],
        '%id' => $form['id']['#value'],
      )));
      watchdog('download_count', 'Download count for %filename on %type %id was reset.', array(
        '%filename' => $form['filename']['#value'],
        '%type' => $form['type']['#value'],
        '%id' => $form['id']['#value'],
      ), WATCHDOG_NOTICE);
    }
    else {
      drupal_set_message(t('Unable to reset download count for %filename on %type %id.', array(
        '%filename' => $form['filename']['#value'],
        '%type' => $form['type']['#value'],
        '%id' => $form['id']['#value'],
      )), 'error');
      watchdog('download_count', 'Unable to reset download count for %filename on %type %id.', array(
        '%filename' => $form['filename']['#value'],
        '%type' => $form['type']['#value'],
        '%id' => $form['id']['#value'],
      ), WATCHDOG_ERROR);
    }
  }
  $form_state['redirect'] = 'admin/reports/download-count';
}