function auditfiles_used_not_managed_form in Audit Files 7.3
Same name and namespace in other branches
- 7.4 auditfiles.usednotmanaged.inc \auditfiles_used_not_managed_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_used_not_managed_form'
- auditfiles_menu in ./
auditfiles.module - Implements hook_menu().
File
- ./
auditfiles.usednotmanaged.inc, line 25 - Generates a report showing files in file_usage, but not in file_managed.
Code
function auditfiles_used_not_managed_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_used_not_managed_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_used_not_managed_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.
$file_ids = _auditfiles_used_not_managed_get_file_list();
if (!empty($file_ids)) {
foreach ($file_ids as $file_id) {
$rows[$file_id] = _auditfiles_used_not_managed_get_file_data($file_id);
}
}
// Save the data for persistent use.
variable_set('auditfiles_used_not_managed_files_to_display', $rows);
}
// Set up the pager.
if (!empty($rows)) {
$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 in the file_usage table that are not in the file_managed table.';
}
else {
$file_count_message = 'Found @count files in the file_usage table that are not in the file_managed table.';
}
$form_count = format_plural(count($rows), 'Found 1 file in the file_usage table that is not in the file_managed table.', $file_count_message);
}
else {
$form_count = t('Found no files in the file_usage table that are not in the file_managed table.');
}
// 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_used_not_managed_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']['submit'] = array(
'#type' => 'submit',
'#value' => t('Delete selected items from the file_usage table'),
);
// Add the pager.
$form['pager'] = array(
'#markup' => theme('pager'),
);
}
return $form;
}