You are here

function auditfiles_not_in_database_form_submit in Audit Files 7.4

Same name and namespace in other branches
  1. 7.3 auditfiles.notindatabase.inc \auditfiles_not_in_database_form_submit()

Submit handler for the auditfiles_not_in_database_form form.

File

./auditfiles.notindatabase.inc, line 191
Generates a report showing files on the server, but not in the database.

Code

function auditfiles_not_in_database_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'] == 'Load all records' || $form_state['values']['op'] == 'Load first batch set') {

      // Clear the variable, so subsequent pages will load the correct data.
      variable_del('auditfiles_not_in_database_files_to_display');
      $batch_size = variable_get('auditfiles_report_options_batch_size', 0);
      if ($batch_size > 0) {

        // Set appropriate variables for this operation.
        variable_set('auditfiles_not_in_database_record_selection', 'batch_sets');
      }
      else {

        // Set appropriate variables for this operation.
        variable_set('auditfiles_not_in_database_record_selection', 'batched');
      }

      // Prepare and set the batch.
      batch_set(_auditfiles_not_in_database_batch_display_create_batch());
    }
    elseif ($form_state['values']['op'] == 'Load previous batch set') {

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

      // Set appropriate variables for this operation.
      $batch_size = variable_get('auditfiles_report_options_batch_size', 0);
      $batch_offset = variable_get('auditfiles_not_in_database_batch_offset', 0);
      variable_set('auditfiles_not_in_database_batch_offset', $batch_offset - $batch_size);
      variable_set('auditfiles_not_in_database_record_selection', 'batch_sets');

      // Prepare and set the batch.
      batch_set(_auditfiles_not_in_database_batch_display_create_batch());
    }
    elseif ($form_state['values']['op'] == 'Load next batch set') {

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

      // Set appropriate variables for this operation.
      $batch_size = variable_get('auditfiles_report_options_batch_size', 0);
      $batch_offset = variable_get('auditfiles_not_in_database_batch_offset', 0);
      variable_set('auditfiles_not_in_database_batch_offset', $batch_offset + $batch_size);
      variable_set('auditfiles_not_in_database_record_selection', 'batch_sets');

      // Prepare and set the batch.
      batch_set(_auditfiles_not_in_database_batch_display_create_batch());
    }
    elseif ($form_state['values']['op'] == 'Reset record selection') {

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

      // Set appropriate variables for this operation.
      unset($form_state['values']['saved_rows']);
      variable_set('auditfiles_not_in_database_record_selection', 'normal');
      variable_del('auditfiles_not_in_database_batch_offset');
    }
    elseif (($form_state['values']['op'] == 'Add selected items to the database' || $form_state['values']['op'] == 'Delete selected items from the server') && !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'] == 'Yes') {
      if ($form_state['values']['operation'] == 'add') {

        // Prepare and set the batch.
        batch_set(_auditfiles_not_in_database_batch_add_create_batch($form_state['values']['changelist']));
      }
      elseif ($form_state['values']['operation'] == 'delete') {

        // Prepare and set the batch.
        batch_set(_auditfiles_not_in_database_batch_delete_create_batch($form_state['values']['changelist']));
      }
    }
  }
  if (!empty($form_state['values']['saved_rows'])) {
    $form_state['storage']['saved_rows'] = $form_state['values']['saved_rows'];
  }
}