You are here

function download_count_reset_form_submit in Download Count 7.2

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

@todo Please document this function.

See also

http://drupal.org/node/1354

File

includes/download_count.pages.inc, line 157
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') {
    $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.', WATCHDOG_NOTICE);
    }
    else {
      drupal_set_message(t('Unable to reset all download counts.'), 'error');
      watchdog('download_count', 'Unable to reset all download counts.', WATCHDOG_ERROR);
    }
  }
  else {

    // TODO Please review the conversion of this statement to the D7 database API syntax.

    /* db_query('DELETE FROM {download_count} WHERE fid = %d AND nid = %d', $form['fid']['#value'], $form['nid']['#value']) */
    $result = db_delete('download_count')
      ->condition('fid', $form['fid']['#value'])
      ->condition('nid', $form['nid']['#value'])
      ->execute();
    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';
}