getServerInfo(); return !empty($info[$all ? 'pg_dumpall_path' : 'pg_dump_path']); } /** * Sets the href tracking variable */ function setHREF() { $this->href = $this->getHREF(); } /** * Get a href query string, excluding objects below the given object type (inclusive) */ function getHREF($exclude_from = null) { $href = ''; if (isset($_REQUEST['server']) && $exclude_from != 'server') { $href .= 'server=' . urlencode($_REQUEST['server']); if (isset($_REQUEST['database']) && $exclude_from != 'database') { $href .= '&database=' . urlencode($_REQUEST['database']); if (isset($_REQUEST['schema']) && $exclude_from != 'schema') { $href .= '&schema=' . urlencode($_REQUEST['schema']); } } } return htmlentities($href); } function getSubjectParams($subject) { global $plugin_manager; $vars = array(); switch($subject) { case 'root': $vars = array ( 'params' => array( 'subject' => 'root' ) ); break; case 'server': $vars = array ('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'server' )); break; case 'role': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'role', 'action' => 'properties', 'rolename' => $_REQUEST['rolename'] )); break; case 'database': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'database', 'database' => $_REQUEST['database'], )); break; case 'schema': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'schema', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'] )); break; case 'table': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'table', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'] )); break; case 'selectrows': $vars = array( 'url' => 'tables.php', 'params' => array( 'server' => $_REQUEST['server'], 'subject' => 'table', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'], 'action' => 'confselectrows' )); break; case 'view': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'view', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $_REQUEST['view'] )); break; case 'fulltext': case 'ftscfg': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'fulltext', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'action' => 'viewconfig', 'ftscfg' => $_REQUEST['ftscfg'] )); break; case 'function': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'function', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'function' => $_REQUEST['function'], 'function_oid' => $_REQUEST['function_oid'] )); break; case 'aggregate': $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'aggregate', 'action' => 'properties', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'aggrname' => $_REQUEST['aggrname'], 'aggrtype' => $_REQUEST['aggrtype'] )); break; case 'column': if (isset($_REQUEST['table'])) $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'column', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'], 'column' => $_REQUEST['column'] )); else $vars = array('params' => array( 'server' => $_REQUEST['server'], 'subject' => 'column', 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $_REQUEST['view'], 'column' => $_REQUEST['column'] )); break; case 'plugin': $vars = array( 'url' => 'plugin.php', 'params' => array( 'server' => $_REQUEST['server'], 'subject' => 'plugin', 'plugin' => $_REQUEST['plugin'], )); if (!is_null($plugin_manager->getPlugin($_REQUEST['plugin']))) $vars['params'] = array_merge($vars['params'], $plugin_manager->getPlugin($_REQUEST['plugin'])->get_subject_params()); break; default: return false; } if (!isset($vars['url'])) $vars['url'] = 'redirect.php'; return $vars; } function getHREFSubject($subject) { $vars = $this->getSubjectParams($subject); return "{$vars['url']}?". http_build_query($vars['params'], '', '&'); } /** * Sets the form tracking variable */ function setForm() { $this->form = ''; if (isset($_REQUEST['server'])) { $this->form .= "\n"; if (isset($_REQUEST['database'])) { $this->form .= "\n"; if (isset($_REQUEST['schema'])) { $this->form .= "\n"; } } } } /** * Render a value into HTML using formatting rules specified * by a type name and parameters. * * @param $str The string to change * * @param $type Field type (optional), this may be an internal PostgreSQL type, or: * yesno - same as bool, but renders as 'Yes' or 'No'. * pre - render in a
block. * nbsp - replace all spaces with 's * verbatim - render exactly as supplied, no escaping what-so-ever. * callback - render using a callback function supplied in the 'function' param. * * @param $params Type parameters (optional), known parameters: * null - string to display if $str is null, or set to TRUE to use a default 'NULL' string, * otherwise nothing is rendered. * clip - if true, clip the value to a fixed length, and append an ellipsis... * cliplen - the maximum length when clip is enabled (defaults to $conf['max_chars']) * ellipsis - the string to append to a clipped value (defaults to $lang['strellipsis']) * tag - an HTML element name to surround the value. * class - a class attribute to apply to any surrounding HTML element. * align - an align attribute ('left','right','center' etc.) * true - (type='bool') the representation of true. * false - (type='bool') the representation of false. * function - (type='callback') a function name, accepts args ($str, $params) and returns a rendering. * lineno - prefix each line with a line number. * map - an associative array. * * @return The HTML rendered value */ function printVal($str, $type = null, $params = array()) { global $lang, $conf, $data; // Shortcircuit for a NULL value if (is_null($str)) return isset($params['null']) ? ($params['null'] === true ? 'NULL' : $params['null']) : ''; if (isset($params['map']) && isset($params['map'][$str])) $str = $params['map'][$str]; // Clip the value if the 'clip' parameter is true. if (isset($params['clip']) && $params['clip'] === true) { $maxlen = isset($params['cliplen']) && is_integer($params['cliplen']) ? $params['cliplen'] : $conf['max_chars']; $ellipsis = isset($params['ellipsis']) ? $params['ellipsis'] : $lang['strellipsis']; if (mb_strlen($str, 'UTF-8') > $maxlen) { $str = mb_substr($str, 0, $maxlen-1, 'UTF-8') . $ellipsis; } } $out = ''; switch ($type) { case 'int2': case 'int4': case 'int8': case 'float4': case 'float8': case 'money': case 'numeric': case 'oid': case 'xid': case 'cid': case 'tid': $align = 'right'; $out = nl2br(htmlspecialchars($str)); break; case 'yesno': if (!isset($params['true'])) $params['true'] = $lang['stryes']; if (!isset($params['false'])) $params['false'] = $lang['strno']; // No break - fall through to boolean case. case 'bool': case 'boolean': if (is_bool($str)) $str = $str ? 't' : 'f'; switch ($str) { case 't': $out = (isset($params['true']) ? $params['true'] : $lang['strtrue']); $align = 'center'; break; case 'f': $out = (isset($params['false']) ? $params['false'] : $lang['strfalse']); $align = 'center'; break; default: $out = htmlspecialchars($str); } break; case 'bytea': $tag = 'div'; $class = 'pre'; $out = $data->escapeBytea($str); break; case 'errormsg': $tag = 'pre'; $class = 'error'; $out = htmlspecialchars($str); break; case 'pre': $tag = 'pre'; $out = htmlspecialchars($str); break; case 'prenoescape': $tag = 'pre'; $out = $str; break; case 'nbsp': $out = nl2br(str_replace(' ', ' ', htmlspecialchars($str))); break; case 'verbatim': $out = $str; break; case 'callback': $out = $params['function']($str, $params); break; case 'prettysize': if ($str == -1) $out = $lang['strnoaccess']; else { $limit = 10 * 1024; $mult = 1; if ($str < $limit * $mult) $out = $str.' '.$lang['strbytes']; else { $mult *= 1024; if ($str < $limit * $mult) $out = floor(($str + $mult / 2) / $mult).' '.$lang['strkb']; else { $mult *= 1024; if ($str < $limit * $mult) $out = floor(($str + $mult / 2) / $mult).' '.$lang['strmb']; else { $mult *= 1024; if ($str < $limit * $mult) $out = floor(($str + $mult / 2) / $mult).' '.$lang['strgb']; else { $mult *= 1024; if ($str < $limit * $mult) $out = floor(($str + $mult / 2) / $mult).' '.$lang['strtb']; } } } } } break; default: // If the string contains at least one instance of >1 space in a row, a tab // character, a space at the start of a line, or a space at the start of // the whole string then render within a pre-formatted element (). if (preg_match('/(^ | |\t|\n )/m', $str)) { $tag = 'pre'; $class = 'data'; $out = htmlspecialchars($str); } else { $out = nl2br(htmlspecialchars($str)); } } if (isset($params['class'])) $class = $params['class']; if (isset($params['align'])) $align = $params['align']; if (!isset($tag) && (isset($class) || isset($align))) $tag = 'div'; if (isset($tag)) { $alignattr = isset($align) ? " style=\"text-align: {$align}\"" : ''; $classattr = isset($class) ? " class=\"{$class}\"" : ''; $out = "<{$tag}{$alignattr}{$classattr}>{$out}{$tag}>"; } // Add line numbers if 'lineno' param is true if (isset($params['lineno']) && $params['lineno'] === true) { $lines = explode("\n", $str); $num = count($lines); if ($num > 0) { $temp = "
"; for ($i = 1; $i <= $num; $i++) { $temp .= $i . "\n"; } $temp .= " | {$out} |