You are here

function download_count_reset_form_submit in Download Count 6.2

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

Implementation of hook_submit().

File

includes/download_count.pages.inc, line 158
Page callback file for the download_count module.

Code

function download_count_reset_form_submit($form, &$form_state) {
  $result = NULL;
  if ($form['dcid']['#value'] == 'all') {
    if (module_exists('download_count_statistics')) {
      db_query('TRUNCATE TABLE {download_count_statistics}');
    }
    $result = db_query('TRUNCATE TABLE {download_count}');
    if ($result) {
      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 {
    if (module_exists('download_count_statistics')) {
      db_query('DELETE FROM {download_count_statistics} WHERE fid = %d', $form['fid']['#value']);
    }
    $result = db_query('DELETE FROM {download_count} WHERE fid = %d AND nid = %d', $form['fid']['#value'], $form['nid']['#value']);
    if ($result) {
      drupal_set_message(t('Download count for %name was reset.', array(
        '%name' => $form['filename']['#value'],
      )));
      watchdog('download_count', 'Download count for %name was reset.', array(
        '%name' => $form['filename']['#value'],
      ), WATCHDOG_NOTICE);
    }
    else {
      drupal_set_message(t('Unable to reset download count for %name.', array(
        '%name' => $form['filename']['#value'],
      )), 'error');
      watchdog('download_count', 'Unable to reset download count for %name.', array(
        '%name' => $form['filename']['#value'],
      ), WATCHDOG_ERROR);
    }
  }
  $form_state['redirect'] = 'download_count';
}