function auditfiles_not_in_database_form in Audit Files 7.3
Same name and namespace in other branches
- 7.4 auditfiles.notindatabase.inc \auditfiles_not_in_database_form()
Generates the report.
This cannot be sorted, because a result set that is too large will time out.
Parameters
array $form: The form definition.
array $form_state: The current state of the form.
Return value
array The form definition.
1 string reference to 'auditfiles_not_in_database_form'
- auditfiles_menu in ./
auditfiles.module - Implements hook_menu().
File
- ./
auditfiles.notindatabase.inc, line 25 - Generates a report showing files on the server, but not in the database.
Code
function auditfiles_not_in_database_form(array $form, array &$form_state) {
// Check to see if the confirmation form needs to be displayed instead of the
// normal form.
if (isset($form_state['storage']['confirm'])) {
return _auditfiles_not_in_database_confirm_operation($form, $form_state);
}
// Get the records to display.
// Check to see if there is saved data, and if so, use that.
$rows = variable_get('auditfiles_not_in_database_files_to_display', array());
if (empty($rows)) {
// The data is not saved and the batch operation has not been run, so get
// the data using the default options.
$rows = _auditfiles_not_in_database_get_reports_files();
// Save the data for persistent use.
variable_set('auditfiles_not_in_database_files_to_display', $rows);
}
if (!empty($rows)) {
// Set up the pager.
$items_per_page = variable_get('auditfiles_report_options_items_per_page', 50);
if (!empty($items_per_page)) {
$current_page = pager_default_initialize(count($rows), $items_per_page);
// Break the total data set into page sized chunks.
$pages = array_chunk($rows, $items_per_page, TRUE);
}
}
// Define the form.
// Setup the record count and related messages.
$maximum_records = variable_get('auditfiles_report_options_maximum_records', 250);
if (!empty($rows)) {
if ($maximum_records > 0) {
$file_count_message = 'Found at least @count files on the server that are not in the database.';
}
else {
$file_count_message = 'Found @count files on the server that are not in the database.';
}
$form_count = format_plural(count($rows), 'Found 1 file on the server that is not in the database.', $file_count_message);
}
else {
$form_count = t('Found no files on the server that are not in the database.');
}
// Add the button to reset the record selection.
$form['reset_records'] = array(
'#type' => 'submit',
'#value' => t('Reset file list'),
'#suffix' => '<div>' . t("Use this button to reset this report's variables and load the page anew.") . '</div>',
);
// Add the button to batch process the list of results.
if ($maximum_records > 0) {
$form['batch_process'] = array(
'#type' => 'submit',
'#value' => t('Load all files'),
'#suffix' => '<div>' . t('Use this button to load the number of records specified with the "Batch size" administrative configuration setting.') . '</div>',
);
}
// Create the form table.
$form['files'] = array(
'#type' => 'tableselect',
'#header' => _auditfiles_not_in_database_get_header(),
'#empty' => t('No items found.'),
'#prefix' => '<div><em>' . $form_count . '</em></div>',
);
// Add the data.
if (!empty($rows) && !empty($pages)) {
$form['files']['#options'] = $pages[$current_page];
}
elseif (!empty($rows)) {
$form['files']['#options'] = $rows;
}
else {
$form['files']['#options'] = array();
}
// Add any action buttons.
if (!empty($rows)) {
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['add'] = array(
'#type' => 'submit',
'#value' => t('Add selected items to the database'),
);
$form['actions']['markup'] = array(
'#markup' => ' ' . t('or') . ' ',
);
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete selected items from the server'),
);
// Add the pager.
$form['pager'] = array(
'#markup' => theme('pager'),
);
}
return $form;
}