function dba_get_active_tables in Database Administration 5
Figure out what table(s) are currently selected.
There are various ways in the dba UI to select tables for each of the possible operations. The table name could be imbedded in the menu path, a set of tables could be selected via the checkboxes on the overview page, or a set of tables might be saved in a special form value to remember previously selected tables.
In all cases, this function will validate the table names by comparing them against the actual names of the tables in the DB, so it is essential to always use this function, even if you already have a list of tables.
Parameters
$use_all: Boolean to specify that if no active tables are found, return all tables.
$form_tables: Array of active table names that we got from a form element.
8 calls to dba_get_active_tables()
- dba_admin_tables_verify_op in ./
dba.module - Menu callback to verify the administrator wants to backup, empty or drop the selected table(s) by means of a confirm form.
- dba_check_tables_form in ./
dba.module - dba_database_overview_form_submit in ./
dba.module - dba_get_primary_key in ./
dba.module - dba_menu in ./
dba.module
File
- ./
dba.module, line 1103 - Allows administrators direct access to their Drupal database. Written by Jeremy Andrews <jeremy@kerneltrap.org>, June 2004. PostgreSQL functionality provided by AAM <aam@ugpl.de> Major security audit, porting, and maintenance by Derek…
Code
function dba_get_active_tables($use_all = TRUE, $form_tables = array()) {
static $all_tables = array();
if (empty($all_tables)) {
$all_tables = dba_get_tables();
}
$tables = array();
if (!empty($form_tables)) {
$tables = $form_tables;
}
elseif (arg(5) && arg(4)) {
$tables[] = arg(4);
}
elseif ($use_all) {
// No tables were set, by default we will return a list of all tables.
return $all_tables;
}
elseif (isset($_SESSION['dba_tables'])) {
$tables = $_SESSION['dba_tables'];
}
// Final sanity/security check to prevent malicious table names.
$safe_tables = array();
foreach ($tables as $table) {
if (isset($all_tables[$table])) {
$safe_tables[] = $table;
}
}
return $safe_tables;
}