Get the script name corresponding to a plain English config word
in order to append in links on navigation and main panel
public static getScriptNameForOption ( string $target, string $location ) : string | ||
$target | string | a valid value for $cfg['NavigationTreeDefaultTabTable'], $cfg['NavigationTreeDefaultTabTable2'], $cfg['DefaultTabTable'], $cfg['DefaultTabDatabase'] or $cfg['DefaultTabServer'] |
$location | string | one out of 'server', 'table', 'database' |
return | string | script name corresponding to the config word |
/** * Initialises the class * * @param string $name An identifier for the new node * @param int $type Type of node, may be one of CONTAINER or OBJECT * @param bool $is_group Whether this object has been created * while grouping nodes */ public function __construct($name, $type = Node::OBJECT, $is_group = false) { parent::__construct($name, $type, $is_group); $this->icon = Util::getImage('s_db.png', __('Database operations')); $script_name = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database'); $this->links = array('text' => $script_name . '?server=' . $GLOBALS['server'] . '&db=%1$s&token=' . $_SESSION[' PMA_token '], 'icon' => 'db_operations.php?server=' . $GLOBALS['server'] . '&db=%1$s&token=' . $_SESSION[' PMA_token '], 'title' => __('Structure')); $this->classes = 'database'; }
/** * Initialises the class * * @param string $name An identifier for the new node * @param int $type Type of node, may be one of CONTAINER or OBJECT * @param bool $is_group Whether this object has been created * while grouping nodes */ public function __construct($name, $type = Node::OBJECT, $is_group = false) { parent::__construct($name, $type, $is_group); $this->icon = array(); $this->_addIcon(Util::getScriptNameForOption($GLOBALS['cfg']['NavigationTreeDefaultTabTable'], 'table')); $this->_addIcon(Util::getScriptNameForOption($GLOBALS['cfg']['NavigationTreeDefaultTabTable2'], 'table')); $title = Util::getTitleForTarget($GLOBALS['cfg']['DefaultTabTable']); $this->title = $title; $script_name = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table'); $this->links = array('text' => $script_name . '?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s' . '&pos=0&token=' . $_SESSION[' PMA_token '], 'icon' => array(Util::getScriptNameForOption($GLOBALS['cfg']['NavigationTreeDefaultTabTable'], 'table') . '?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s&token=' . $_SESSION[' PMA_token '], Util::getScriptNameForOption($GLOBALS['cfg']['NavigationTreeDefaultTabTable2'], 'table') . '?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s&token=' . $_SESSION[' PMA_token ']), 'title' => $this->title); $this->classes = 'table'; }
/** * Display selection form action * * @return void */ public function displaySelectionFormAction($datalabel = null) { $this->url_query .= '&goto=tbl_select.php&back=tbl_select.php'; include_once 'libraries/tbl_info.inc.php'; if (!isset($goto)) { $goto = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table'); } // Displays the table search form $this->response->addHTML(Template::get('secondary_tabs')->render(array('url_params' => array('db' => $this->db, 'table' => $this->table), 'sub_tabs' => $this->_getSubTabs()))); $this->response->addHTML(Template::get('table/search/selection_form')->render(array('searchType' => $this->_searchType, 'db' => $this->db, 'table' => $this->table, 'goto' => $goto, 'self' => $this, 'geomColumnFlag' => $this->_geomColumnFlag, 'columnNames' => $this->_columnNames, 'columnTypes' => $this->_columnTypes, 'columnCollations' => $this->_columnCollations, 'dataLabel' => $datalabel))); }
/** * Provide a line with links to the relevant database and table * * @param string $url_dbname url database name that urlencode() string * @param string $dbname database name * @param string $tablename table name * * @return string HTML snippet */ function PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename) { $html_output = '[ ' . __('Database') . ' <a href="' . Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . PMA_URL_getCommon(array('db' => $url_dbname, 'reload' => 1)) . '">' . htmlspecialchars($dbname) . ': ' . Util::getTitleForTarget($GLOBALS['cfg']['DefaultTabDatabase']) . "</a> ]\n"; if (mb_strlen($tablename)) { $html_output .= ' [ ' . __('Table') . ' <a href="' . Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table') . PMA_URL_getCommon(array('db' => $url_dbname, 'table' => $tablename, 'reload' => 1)) . '">' . htmlspecialchars($tablename) . ': ' . Util::getTitleForTarget($GLOBALS['cfg']['DefaultTabTable']) . "</a> ]\n"; } return $html_output; }
$scripts->addFile('multi_column_sort.js'); /** * Set ajax_reload in the response if it was already set */ if (isset($ajax_reload) && $ajax_reload['reload'] === true) { $response->addJSON('ajax_reload', $ajax_reload); } /** * Defines the url to return to in case of error in a sql statement */ $is_gotofile = true; if (empty($goto)) { if (empty($table)) { $goto = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database'); } else { $goto = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table'); } } // end if if (!isset($err_url)) { $err_url = (!empty($back) ? $back : $goto) . '?' . URL::getCommon(array('db' => $GLOBALS['db'])) . (mb_strpos(' ' . $goto, 'db_') != 1 && mb_strlen($table) ? '&table=' . urlencode($table) : ''); } // end if // Coming from a bookmark dialog if (isset($_POST['bkm_fields']['bkm_sql_query'])) { $sql_query = $_POST['bkm_fields']['bkm_sql_query']; } elseif (isset($_GET['sql_query'])) { $sql_query = $_GET['sql_query']; } // This one is just to fill $db if (isset($_POST['bkm_fields']['bkm_database'])) {
/** * returns html code for db link to default db page * * @param string $database database * * @return string html link to default db page */ public static function getDbLink($database = null) { if (strlen($database) === 0) { if (strlen($GLOBALS['db']) === 0) { return ''; } $database = $GLOBALS['db']; } else { $database = self::unescapeMysqlWildcards($database); } return '<a href="' . Util::getScriptNameForOption( $GLOBALS['cfg']['DefaultTabDatabase'], 'database' ) . URL::getCommon(array('db' => $database)) . '" title="' . htmlspecialchars( sprintf( __('Jump to database "%s".'), $database ) ) . '">' . htmlspecialchars($database) . '</a>'; }
<?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * handles creation of the GIS visualizations. * * @package PhpMyAdmin */ namespace PMA; use PMA\libraries\controllers\table\TableGisVisualizationController; use PMA\libraries\Response; use PMA\libraries\Util; require_once 'libraries/common.inc.php'; $container = libraries\di\Container::getDefaultContainer(); $container->factory('PMA\\libraries\\controllers\\table\\TableGisVisualizationController'); $container->alias('TableGisVisualizationController', 'PMA\\libraries\\controllers\\table\\TableGisVisualizationController'); $container->set('PMA\\libraries\\Response', Response::getInstance()); $container->alias('response', 'PMA\\libraries\\Response'); /* Define dependencies for the concerned controller */ $dependency_definitions = array("sql_query" => &$GLOBALS['sql_query'], "url_params" => &$GLOBALS['url_params'], "goto" => Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database'), "back" => 'sql.php', "visualizationSettings" => array()); /** @var TableGisVisualizationController $controller */ $controller = $container->get('TableGisVisualizationController', $dependency_definitions); $controller->indexAction();
/** * Display selection form action * * @return void */ public function displaySelectionFormAction() { //$err_url = 'tbl_select.php' . $err_url; $this->url_query .= '&goto=tbl_select.php&back=tbl_select.php'; include_once 'libraries/tbl_info.inc.php'; if (!isset($goto)) { $goto = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table'); } // Defines the url to return to in case of error in the next sql statement $err_url = $goto . PMA_URL_getCommon(array('db' => $this->db, 'table' => $this->table)); // Displays the table search form $this->response->addHTML(Template::get('secondary_tabs')->render(array('url_params' => array('db' => $this->db, 'table' => $this->table), 'sub_tabs' => $this->_getSubTabs()))); $this->response->addHTML(Template::get('table/search/selection_form')->render(array('searchType' => $this->_searchType, 'db' => $this->db, 'table' => $this->table, 'goto' => $goto, 'self' => $this, 'geomColumnFlag' => $this->_geomColumnFlag, 'columnNames' => $this->_columnNames, 'columnTypes' => $this->_columnTypes, 'columnCollations' => $this->_columnCollations, 'dataLabel' => null))); }
/** * Execute the query and return the result * * @return void */ public function indexAction() { if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['pos']) && isset($_REQUEST['session_max_rows'])) { $this->ajaxAction(); return; } // Throw error if no sql query is set if (!isset($this->sql_query) || $this->sql_query == '') { $this->response->setRequestStatus(false); $this->response->addHTML(Message::error(__('No SQL query was set to fetch data.'))); return; } $this->response->getHeader()->getScripts()->addFiles(array('chart.js', 'tbl_chart.js', 'jqplot/jquery.jqplot.js', 'jqplot/plugins/jqplot.barRenderer.js', 'jqplot/plugins/jqplot.canvasAxisLabelRenderer.js', 'jqplot/plugins/jqplot.canvasTextRenderer.js', 'jqplot/plugins/jqplot.categoryAxisRenderer.js', 'jqplot/plugins/jqplot.dateAxisRenderer.js', 'jqplot/plugins/jqplot.pointLabels.js', 'jqplot/plugins/jqplot.pieRenderer.js', 'jqplot/plugins/jqplot.highlighter.js')); /** * Extract values for common work * @todo Extract common files */ $db =& $this->db; $table =& $this->table; /** * Runs common work */ if (mb_strlen($this->table)) { $url_params['goto'] = Util::getScriptNameForOption($this->cfg['DefaultTabTable'], 'table'); $url_params['back'] = 'tbl_sql.php'; include 'libraries/tbl_common.inc.php'; include 'libraries/tbl_info.inc.php'; } elseif (mb_strlen($this->db)) { $url_params['goto'] = Util::getScriptNameForOption($this->cfg['DefaultTabDatabase'], 'database'); $url_params['back'] = 'sql.php'; include 'libraries/db_common.inc.php'; } else { $url_params['goto'] = Util::getScriptNameForOption($this->cfg['DefaultTabServer'], 'server'); $url_params['back'] = 'sql.php'; include 'libraries/server_common.inc.php'; } $data = array(); $result = $this->dbi->tryQuery($this->sql_query); $fields_meta = $this->dbi->getFieldsMeta($result); while ($row = $this->dbi->fetchAssoc($result)) { $data[] = $row; } $keys = array_keys($data[0]); $numeric_types = array('int', 'real'); $numeric_column_count = 0; foreach ($keys as $idx => $key) { if (in_array($fields_meta[$idx]->type, $numeric_types)) { $numeric_column_count++; } } if ($numeric_column_count == 0) { $this->response->setRequestStatus(false); $this->response->addJSON('message', __('No numeric columns present in the table to plot.')); return; } $url_params['db'] = $this->db; $url_params['reload'] = 1; /** * Displays the page */ $this->response->addHTML(Template::get('table/chart/tbl_chart')->render(array('url_query' => $this->url_query, 'url_params' => $url_params, 'keys' => $keys, 'fields_meta' => $fields_meta, 'numeric_types' => $numeric_types, 'numeric_column_count' => $numeric_column_count, 'sql_query' => $this->sql_query))); }
if (!defined('PHPMYADMIN')) { exit; } PMA\libraries\Util::checkParameters(array('db')); global $cfg; global $db; $is_show_stats = $cfg['ShowStats']; $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($db); if ($db_is_system_schema) { $is_show_stats = false; } /** * Defines the urls to return to in case of error in a sql statement */ $err_url_0 = 'index.php' . URL::getCommon(); $err_url = PMA\libraries\Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . URL::getCommon(array('db' => $db)); /** * Ensures the database exists (else move to the "parent" script) and displays * headers */ if (!isset($is_db) || !$is_db) { if (strlen($db) > 0) { $is_db = $GLOBALS['dbi']->selectDb($db); // This "Command out of sync" 2014 error may happen, for example // after calling a MySQL procedure; at this point we can't select // the db but it's not necessarily wrong if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) { $is_db = true; unset($GLOBALS['errno']); } } else {
/** * Returns, as an array, a list of parameters * used on the client side * * @return array */ public function getJsParams() { $db = !empty($GLOBALS['db']) ? $GLOBALS['db'] : ''; $table = !empty($GLOBALS['table']) ? $GLOBALS['table'] : ''; $pftext = !empty($_SESSION['tmpval']['pftext']) ? $_SESSION['tmpval']['pftext'] : ''; // not sure when this happens, but it happens if (!isset($GLOBALS['collation_connection'])) { $GLOBALS['collation_connection'] = 'utf8_general_ci'; } $params = array('common_query' => PMA_URL_getCommon(array(), 'text'), 'opendb_url' => Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database'), 'safari_browser' => PMA_USR_BROWSER_AGENT == 'SAFARI' ? 1 : 0, 'collation_connection' => $GLOBALS['collation_connection'], 'lang' => $GLOBALS['lang'], 'server' => $GLOBALS['server'], 'table' => $table, 'db' => $db, 'token' => $_SESSION[' PMA_token '], 'text_dir' => $GLOBALS['text_dir'], 'show_databases_navigation_as_tree' => $GLOBALS['cfg']['ShowDatabasesNavigationAsTree'], 'pma_absolute_uri' => $GLOBALS['cfg']['PmaAbsoluteUri'], 'pma_text_default_tab' => Util::getTitleForTarget($GLOBALS['cfg']['DefaultTabTable']), 'pma_text_left_default_tab' => Util::getTitleForTarget($GLOBALS['cfg']['NavigationTreeDefaultTabTable']), 'pma_text_left_default_tab2' => Util::getTitleForTarget($GLOBALS['cfg']['NavigationTreeDefaultTabTable2']), 'LimitChars' => $GLOBALS['cfg']['LimitChars'], 'pftext' => $pftext, 'confirm' => $GLOBALS['cfg']['Confirm'], 'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'], 'logged_in' => isset($GLOBALS['userlink']) ? true : false, 'PMA_VERSION' => PMA_VERSION); if (isset($GLOBALS['cfg']['Server']) && isset($GLOBALS['cfg']['Server']['auth_type'])) { $params['auth_type'] = $GLOBALS['cfg']['Server']['auth_type']; } return $params; }
/** * User is not allowed to login to MySQL -> authentication failed * * @return boolean always true (no return indeed) */ public function authFails() { $conn_error = $GLOBALS['dbi']->getError(); if (!$conn_error) { $conn_error = __('Cannot connect: invalid settings.'); } /* HTML header */ $response = PMA\libraries\Response::getInstance(); $response->getFooter()->setMinimal(); $header = $response->getHeader(); $header->setBodyId('loginform'); $header->setTitle(__('Access denied!')); $header->disableMenuAndConsole(); echo '<br /><br /> <center> <h1>'; echo sprintf(__('Welcome to %s'), ' phpMyAdmin '); echo '</h1> </center> <br /> <table cellpadding="0" cellspacing="3" style="margin: 0 auto" width="80%"> <tr> <td>'; if (isset($GLOBALS['allowDeny_forbidden']) && $GLOBALS['allowDeny_forbidden']) { trigger_error(__('Access denied!'), E_USER_NOTICE); } else { // Check whether user has configured something if ($GLOBALS['PMA_Config']->source_mtime == 0) { echo '<p>', sprintf(__('You probably did not create a configuration file.' . ' You might want to use the %1$ssetup script%2$s to' . ' create one.'), '<a href="setup/">', '</a>'), '</p>', "\n"; } elseif (!isset($GLOBALS['errno']) || isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002 && $GLOBALS['errno'] != 2003) { // if we display the "Server not responding" error, do not confuse // users by telling them they have a settings problem // (note: it's true that they could have a badly typed host name, // but anyway the current message tells that the server // rejected the connection, which is not really what happened) // 2002 is the error given by mysqli // 2003 is the error given by mysql trigger_error(__('phpMyAdmin tried to connect to the MySQL server, and the' . ' server rejected the connection. You should check the' . ' host, username and password in your configuration and' . ' make sure that they correspond to the information given' . ' by the administrator of the MySQL server.'), E_USER_WARNING); } echo PMA\libraries\Util::mysqlDie($conn_error, '', true, '', false); } $GLOBALS['error_handler']->dispUserErrors(); echo '</td> </tr> <tr> <td>', "\n"; echo '<a href="', PMA\libraries\Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server'), URL::getCommon(), '" class="button disableAjax">', __('Retry to connect'), '</a>', "\n"; echo '</td> </tr>', "\n"; if (count($GLOBALS['cfg']['Servers']) > 1) { // offer a chance to login to other servers if the current one failed include_once './libraries/select_server.lib.php'; echo '<tr>', "\n"; echo ' <td>', "\n"; echo PMA_selectServer(true, true); echo ' </td>', "\n"; echo '</tr>', "\n"; } echo '</table>', "\n"; if (!defined('TESTSUITE')) { exit; } return true; }
/** * Returns the breadcrumbs as HTML * * @return string HTML formatted breadcrumbs */ private function _getBreadcrumbs() { $retval = ''; $tbl_is_view = $GLOBALS['dbi']->getTable($this->_db, $this->_table)->isView(); if (empty($GLOBALS['cfg']['Server']['host'])) { $GLOBALS['cfg']['Server']['host'] = ''; } $server_info = !empty($GLOBALS['cfg']['Server']['verbose']) ? $GLOBALS['cfg']['Server']['verbose'] : $GLOBALS['cfg']['Server']['host']; $server_info .= empty($GLOBALS['cfg']['Server']['port']) ? '' : ':' . $GLOBALS['cfg']['Server']['port']; $separator = "<span class='separator item'> »</span>"; $item = '<a href="%1$s%2$s" class="item">'; if (Util::showText('TabsMode')) { $item .= '%4$s: '; } $item .= '%3$s</a>'; $retval .= "<div id='floating_menubar'></div>"; $retval .= "<div id='serverinfo'>"; if (Util::showIcons('TabsMode')) { $retval .= Util::getImage('s_host.png', '', array('class' => 'item')); } $retval .= sprintf($item, Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server'), URL::getCommon(), htmlspecialchars($server_info), __('Server')); if (strlen($this->_db) > 0) { $retval .= $separator; if (Util::showIcons('TabsMode')) { $retval .= Util::getImage('s_db.png', '', array('class' => 'item')); } $retval .= sprintf($item, Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database'), URL::getCommon(array('db' => $this->_db)), htmlspecialchars($this->_db), __('Database')); // if the table is being dropped, $_REQUEST['purge'] is set to '1' // so do not display the table name in upper div if (strlen($this->_table) > 0 && !(isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1')) { include './libraries/tbl_info.inc.php'; $retval .= $separator; if (Util::showIcons('TabsMode')) { $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png'; $retval .= Util::getImage($icon, '', array('class' => 'item')); } $retval .= sprintf($item, Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table'), URL::getCommon(array('db' => $this->_db, 'table' => $this->_table)), str_replace(' ', ' ', htmlspecialchars($this->_table)), $tbl_is_view ? __('View') : __('Table')); /** * Displays table comment */ if (!empty($show_comment) && !isset($GLOBALS['avoid_show_comment'])) { if (mb_strstr($show_comment, '; InnoDB free')) { $show_comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment); } $retval .= '<span class="table_comment"'; $retval .= ' id="span_table_comment">"'; $retval .= htmlspecialchars($show_comment); $retval .= '"</span>'; } // end if } else { // no table selected, display database comment if present $cfgRelation = PMA_getRelationsParam(); // Get additional information about tables for tooltip is done // in Util::getDbInfo() only once if ($cfgRelation['commwork']) { $comment = PMA_getDbComment($this->_db); /** * Displays table comment */ if (!empty($comment)) { $retval .= '<span class="table_comment"' . ' id="span_table_comment">"' . htmlspecialchars($comment) . '"</span>'; } // end if } } } $retval .= '<div class="clearfloat"></div>'; $retval .= '</div>'; return $retval; }
/** * Handles creating a new database * * @return void */ public function createDatabaseAction() { /** * Builds and executes the db creation sql query */ $sql_query = 'CREATE DATABASE ' . Util::backquote($_POST['new_db']); if (!empty($_POST['db_collation'])) { list($db_charset) = explode('_', $_POST['db_collation']); if (in_array($db_charset, $GLOBALS['mysql_charsets']) && in_array($_POST['db_collation'], $GLOBALS['mysql_collations'][$db_charset])) { $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($_POST['db_collation']); } } $sql_query .= ';'; $result = $GLOBALS['dbi']->tryQuery($sql_query); if (!$result) { // avoid displaying the not-created db name in header or navi panel $GLOBALS['db'] = ''; $message = Message::rawError($GLOBALS['dbi']->getError()); $this->response->setRequestStatus(false); $this->response->addJSON('message', $message); } else { $GLOBALS['db'] = $_POST['new_db']; $message = Message::success(__('Database %1$s has been created.')); $message->addParam($_POST['new_db']); $this->response->addJSON('message', $message); $this->response->addJSON('sql_query', Util::getMessage(null, $sql_query, 'success')); $url_query = PMA_URL_getCommon(array('db' => $_POST['new_db'])); $this->response->addJSON('url_query', Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . $url_query . '&db=' . urlencode($_POST['new_db'])); } }