{$term}", $string); } /** * Sends a signal to a process */ function doSignal() { global $data, $lang; $status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']); if ($status == 0) doProcesses($lang['strsignalsent']); else doProcesses($lang['strsignalsentbad']); } /** * Searches for a named database object */ function doFind($confirm = true, $msg = '') { global $data, $misc; global $lang, $conf; if (!isset($_REQUEST['term'])) $_REQUEST['term'] = ''; if (!isset($_REQUEST['filter'])) $_REQUEST['filter'] = ''; $misc->printTrail('database'); $misc->printTabs('database','find'); $misc->printMsg($msg); echo "
\n"; echo "

_maxNameLen}\" />\n"; // Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities echo "\n"; echo "\n"; echo $misc->form; echo "

\n"; echo "
\n"; // Default focus $misc->setFocus('forms[0].term'); // If a search term has been specified, then perform the search // and display the results, grouped by object type if ($_REQUEST['term'] != '') { $rs = $data->findObject($_REQUEST['term'], $_REQUEST['filter']); if ($rs->recordCount() > 0) { $curr = ''; while (!$rs->EOF) { // Output a new header if the current type has changed, but not if it's just changed the rule type if ($rs->fields['type'] != $curr) { // Short-circuit in the case of changing from table rules to view rules; table cols to view cols; // table constraints to domain constraints if ($rs->fields['type'] == 'RULEVIEW' && $curr == 'RULETABLE') { $curr = $rs->fields['type']; } elseif ($rs->fields['type'] == 'COLUMNVIEW' && $curr == 'COLUMNTABLE') { $curr = $rs->fields['type']; } elseif ($rs->fields['type'] == 'CONSTRAINTTABLE' && $curr == 'CONSTRAINTDOMAIN') { $curr = $rs->fields['type']; } else { if ($curr != '') echo "\n"; $curr = $rs->fields['type']; echo "

"; switch ($curr) { case 'SCHEMA': echo $lang['strschemas']; break; case 'TABLE': echo $lang['strtables']; break; case 'VIEW': echo $lang['strviews']; break; case 'SEQUENCE': echo $lang['strsequences']; break; case 'COLUMNTABLE': case 'COLUMNVIEW': echo $lang['strcolumns']; break; case 'INDEX': echo $lang['strindexes']; break; case 'CONSTRAINTTABLE': case 'CONSTRAINTDOMAIN': echo $lang['strconstraints']; break; case 'TRIGGER': echo $lang['strtriggers']; break; case 'RULETABLE': case 'RULEVIEW': echo $lang['strrules']; break; case 'FUNCTION': echo $lang['strfunctions']; break; case 'TYPE': echo $lang['strtypes']; break; case 'DOMAIN': echo $lang['strdomains']; break; case 'OPERATOR': echo $lang['stroperators']; break; case 'CONVERSION': echo $lang['strconversions']; break; case 'LANGUAGE': echo $lang['strlanguages']; break; case 'AGGREGATE': echo $lang['straggregates']; break; case 'OPCLASS': echo $lang['stropclasses']; break; } echo "

"; echo "\n"; echo "

", $rs->recordCount(), " ", $lang['strobjects'], "

\n"; } else echo "

{$lang['strnoobjects']}

\n"; } } /** * Displays options for database download */ function doExport($msg = '') { global $data, $misc; global $lang; $misc->printTrail('database'); $misc->printTabs('database','export'); $misc->printMsg($msg); echo "
\n"; echo "\n"; echo "\n"; // Data only echo "\n"; echo "\n"; echo "\n\n"; if ($data->hasServerOids()) { echo "\n\n"; } // Structure only echo "\n"; echo "\n\n"; // Structure and data echo "\n"; echo "\n"; echo "\n\n"; echo "\n\n"; if ($data->hasServerOids()) { echo "\n\n"; } echo "
{$lang['strformat']}{$lang['stroptions']}
hasServerOids() ? 2 : 1) ."\">"; echo "{$lang['strformat']}\n
hasServerOids() ? 3 : 2) ."\">"; echo "{$lang['strformat']}\n
\n"; echo "

{$lang['stroptions']}

\n"; echo "

\n"; echo "
\n"; // MSIE cannot download gzip in SSL mode - it's just broken if (!(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS']))) { echo "
\n"; } echo "

\n"; echo "

\n"; echo "\n"; echo $misc->form; echo "

\n"; echo "
\n"; } /** * Show the current status of all database variables */ function doVariables() { global $data, $misc; global $lang; // Fetch the variables from the database $variables = $data->getVariables(); $misc->printTrail('database'); $misc->printTabs('database','variables'); $columns = array( 'variable' => array( 'title' => $lang['strname'], 'field' => field('name'), ), 'value' => array( 'title' => $lang['strsetting'], 'field' => field('setting'), ), ); $actions = array(); $misc->printTable($variables, $columns, $actions, 'database-variables', $lang['strnodata']); } /** * Show all current database connections and any queries they * are running. */ function doProcesses($msg = '') { global $data, $misc; global $lang; $misc->printTrail('database'); $misc->printTabs('database','processes'); $misc->printMsg($msg); if (strlen($msg) === 0) { echo "
icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}"; } echo "
"; currentProcesses(); echo "
"; } function currentProcesses($isAjax = false) { global $data, $misc, $lang; // Display prepared transactions if($data->hasPreparedXacts()) { echo "

{$lang['strpreparedxacts']}

\n"; $prep_xacts = $data->getPreparedXacts($_REQUEST['database']); $columns = array( 'transaction' => array( 'title' => $lang['strxactid'], 'field' => field('transaction'), ), 'gid' => array( 'title' => $lang['strgid'], 'field' => field('gid'), ), 'prepared' => array( 'title' => $lang['strstarttime'], 'field' => field('prepared'), ), 'owner' => array( 'title' => $lang['strowner'], 'field' => field('owner'), ), ); $actions = array(); $misc->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $lang['strnodata']); } // Fetch the processes from the database echo "

{$lang['strprocesses']}

\n"; $processes = $data->getProcesses($_REQUEST['database']); $columns = array( 'user' => array( 'title' => $lang['strusername'], 'field' => field('usename'), ), 'process' => array( 'title' => $lang['strprocess'], 'field' => field('pid'), ), 'blocked' => array( 'title' => $lang['strblocked'], 'field' => field('waiting'), ), 'query' => array( 'title' => $lang['strsql'], 'field' => field('query'), ), 'start_time' => array( 'title' => $lang['strstarttime'], 'field' => field('query_start'), ), ); // Build possible actions for our process list $columns['actions'] = array('title' => $lang['stractions']); $actions = array(); if ($data->hasUserSignals() || $data->isSuperUser()) { $actions = array( 'cancel' => array( 'content' => $lang['strcancel'], 'attr'=> array ( 'href' => array ( 'url' => 'database.php', 'urlvars' => array ( 'action' => 'signal', 'signal' => 'CANCEL', 'pid' => field('pid') ) ) ) ), 'kill' => array( 'content' => $lang['strkill'], 'attr'=> array ( 'href' => array ( 'url' => 'database.php', 'urlvars' => array ( 'action' => 'signal', 'signal' => 'KILL', 'pid' => field('pid') ) ) ) ) ); // Remove actions where not supported if (!$data->hasQueryKill()) unset($actions['kill']); if (!$data->hasQueryCancel()) unset($actions['cancel']); } if (count($actions) == 0) unset($columns['actions']); $misc->printTable($processes, $columns, $actions, 'database-processes', $lang['strnodata']); if ($isAjax) exit; } function currentLocks($isAjax = false) { global $data, $misc, $lang; // Get the info from the pg_locks view $variables = $data->getLocks(); $columns = array( 'namespace' => array( 'title' => $lang['strschema'], 'field' => field('nspname'), ), 'tablename' => array( 'title' => $lang['strtablename'], 'field' => field('tablename'), ), 'vxid' => array( 'title' => $lang['strvirtualtransaction'], 'field' => field('virtualtransaction'), ), 'transactionid' => array( 'title' => $lang['strtransaction'], 'field' => field('transaction'), ), 'processid' => array( 'title' => $lang['strprocessid'], 'field' => field('pid'), ), 'mode' => array( 'title' => $lang['strmode'], 'field' => field('mode'), ), 'granted' => array( 'title' => $lang['strislockheld'], 'field' => field('granted'), 'type' => 'yesno', ), ); if (!$data->hasVirtualTransactionId()) unset($columns['vxid']); $actions = array(); $misc->printTable($variables, $columns, $actions, 'database-locks', $lang['strnodata']); if ($isAjax) exit; } /** * Show the existing table locks in the current database */ function doLocks() { global $data, $misc; global $lang; $misc->printTrail('database'); $misc->printTabs('database','locks'); echo "
icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}"; echo "
"; currentLocks(); echo "
"; } /** * Allow execution of arbitrary SQL statements on a database */ function doSQL() { global $data, $misc; global $lang; if ((!isset($_SESSION['sqlquery'])) || isset($_REQUEST['new'])) { $_SESSION['sqlquery'] = ''; $_REQUEST['paginate'] = 'on'; } $misc->printTrail('database'); $misc->printTabs('database','sql'); echo "

{$lang['strentersql']}

\n"; echo "
\n"; echo "

{$lang['strsql']}
\n"; echo "

\n"; // Check that file uploads are enabled if (ini_get('file_uploads')) { // Don't show upload option if max size of uploads is zero $max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize')); if (is_double($max_size) && $max_size > 0) { echo "

\n"; echo "

\n"; } } echo "

\n"; echo "

\n"; echo $misc->form; echo "

\n"; echo "
\n"; // Default focus $misc->setFocus('forms[0].query'); } function doTree() { global $misc, $data, $lang; $reqvars = $misc->getRequestVars('database'); $tabs = $misc->getNavTabs('database'); $items = $misc->adjustTabsForTree($tabs); $attrs = array( 'text' => field('title'), 'icon' => field('icon'), 'action' => url(field('url'), $reqvars, field('urlvars', array()) ), 'branch' => url(field('url'), $reqvars, field('urlvars'), array('action' => 'tree') ), ); $misc->printTree($items, $attrs, 'database'); exit; } require('./admin.php'); /* shortcuts: these functions exit the script */ if ($action == 'tree') doTree(); if ($action == 'refresh_locks') currentLocks(true); if ($action == 'refresh_processes') currentProcesses(true); /* normal flow */ if ($action == 'locks' or $action == 'processes') { $scripts .= ""; $refreshTime = $conf['ajax_refresh'] * 1000; $scripts .= "\n"; } $misc->printHeader($lang['strdatabase'], $scripts); $misc->printBody(); switch ($action) { case 'find': if (isset($_REQUEST['term'])) doFind(false); else doFind(true); break; case 'sql': doSQL(); break; case 'variables': doVariables(); break; case 'processes': doProcesses(); break; case 'locks': doLocks(); break; case 'export': doExport(); break; case 'signal': doSignal(); break; default: if (adminActions($action, 'database') === false) doSQL(); break; } $misc->printFooter(); ?>