You are here

function auditfiles_used_not_managed_form_submit in Audit Files 7.3

Same name and namespace in other branches
  1. 7.4 auditfiles.usednotmanaged.inc \auditfiles_used_not_managed_form_submit()

Submit handler for the auditfiles_used_not_managed_form form.

File

./auditfiles.usednotmanaged.inc, line 131
Generates a report showing files in file_usage, but not in file_managed.

Code

function auditfiles_used_not_managed_form_submit($form, &$form_state) {

  // Check if an operation was performed.
  if (!empty($form_state['values']['op'])) {

    // Check which operation was performed and start the batch process.
    if ($form_state['values']['op'] == t('Load all files')) {

      // Clear the variable, so subsequent pages will load the correct data.
      variable_del('auditfiles_used_not_managed_files_to_display');

      // Prepare and set the batch.
      batch_set(_auditfiles_used_not_managed_batch_display_create_batch());
    }
    elseif ($form_state['values']['op'] == t('Reset file list')) {

      // Reset all the variables for this report, so subsequent pages loads will
      // load and use the correct data.
      db_delete('variable')
        ->condition('name', 'auditfiles_used_not_managed_%', 'LIKE')
        ->execute();
      cache_clear_all('variables', 'cache_bootstrap');
    }
    elseif ($form_state['values']['op'] == t('Delete selected items from the file_usage table') && !empty($form_state['values']['files'])) {
      foreach ($form_state['values']['files'] as $file_id) {
        if (!empty($file_id)) {

          // At least one file was selected, and the operation has not been
          // confirmed, so modify the data to display the confirmation form.
          $form_state['storage']['files'] = $form_state['values']['files'];
          $form_state['storage']['op'] = $form_state['values']['op'];
          $form_state['storage']['confirm'] = TRUE;
          $form_state['rebuild'] = TRUE;
          return TRUE;
        }
      }
      drupal_set_message(t('No items were selected to operate on.'));
    }
    elseif ($form_state['values']['op'] == t('Yes')) {
      if ($form_state['values']['operation'] == 'delete') {

        // Prepare and set the batch.
        batch_set(_auditfiles_used_not_managed_batch_delete_create_batch($form_state['values']['changelist']));
      }
    }
  }
}