diff options
122 files changed, 2504 insertions, 2503 deletions
diff --git a/browse_foreigners.php b/browse_foreigners.php index daba389733..b7c194f2e7 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -5,7 +5,9 @@ * * @package PhpMyAdmin */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; +use PhpMyAdmin\Util; require_once 'libraries/common.inc.php'; require_once 'libraries/browse_foreigners.lib.php'; @@ -24,7 +26,7 @@ foreach ($request_params as $one_request_param) { } } -PhpMyAdmin\Util::checkParameters(array('db', 'table', 'field')); +Util::checkParameters(array('db', 'table', 'field')); $response = Response::getInstance(); $response->getFooter()->setMinimal(); @@ -36,12 +38,12 @@ $header->setBodyId('body_browse_foreigners'); * Displays the frame */ -$foreigners = PMA_getForeigners($db, $table); +$foreigners = Relation::getForeigners($db, $table); $foreign_limit = PMA_getForeignLimit( isset($_REQUEST['foreign_showAll']) ? $_REQUEST['foreign_showAll'] : null ); -$foreignData = PMA_getForeignData( +$foreignData = Relation::getForeignData( $foreigners, $_REQUEST['field'], true, isset($_REQUEST['foreign_filter']) ? $_REQUEST['foreign_filter'] diff --git a/chk_rel.php b/chk_rel.php index 3ba2323429..183ee4f338 100644 --- a/chk_rel.php +++ b/chk_rel.php @@ -5,29 +5,30 @@ * * @package PhpMyAdmin */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; require_once 'libraries/common.inc.php'; // If request for creating the pmadb if (isset($_REQUEST['create_pmadb'])) { - if (PMA_createPMADatabase()) { - PMA_fixPMATables('phpmyadmin'); + if (Relation::createPmaDatabase()) { + Relation::fixPmaTables('phpmyadmin'); } } // If request for creating all PMA tables. if (isset($_REQUEST['fixall_pmadb'])) { - PMA_fixPMATables($GLOBALS['db']); + Relation::fixPmaTables($GLOBALS['db']); } -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); // If request for creating missing PMA tables. if (isset($_REQUEST['fix_pmadb'])) { - PMA_fixPMATables($cfgRelation['db']); + Relation::fixPmaTables($cfgRelation['db']); } $response = Response::getInstance(); $response->addHTML( - PMA_getRelationsParamDiagnostic($cfgRelation) + Relation::getRelationsParamDiagnostic($cfgRelation) ); diff --git a/db_datadict.php b/db_datadict.php index 5cd979e86c..94e8beb860 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -5,7 +5,7 @@ * * @package PhpMyAdmin */ - +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; use PhpMyAdmin\Url; @@ -37,7 +37,7 @@ $header->enablePrintView(); /** * Gets the relations settings */ -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); /** * Check parameters @@ -50,7 +50,7 @@ PhpMyAdmin\Util::checkParameters(array('db')); $err_url = 'db_sql.php' . Url::getCommon(array('db' => $db)); if ($cfgRelation['commwork']) { - $comment = PMA_getDbComment($db); + $comment = Relation::getDbComment($db); /** * Displays DB comment @@ -69,7 +69,7 @@ $tables = $GLOBALS['dbi']->getTables($db); $count = 0; foreach ($tables as $table) { - $comments = PMA_getComments($db, $table); + $comments = Relation::getComments($db, $table); echo '<div>' , "\n"; @@ -95,7 +95,7 @@ foreach ($tables as $table) { $columns = $GLOBALS['dbi']->getColumns($db, $table); // Check if we can use Relations - list($res_rel, $have_rel) = PMA_getRelationsAndStatus( + list($res_rel, $have_rel) = Relation::getRelationsAndStatus( ! empty($cfgRelation['relation']), $db, $table ); @@ -171,7 +171,7 @@ foreach ($tables as $table) { if ($have_rel) { echo ' <td>'; - if ($foreigner = PMA_searchColumnInForeigners($res_rel, $column_name)) { + if ($foreigner = Relation::searchColumnInForeigners($res_rel, $column_name)) { echo htmlspecialchars( $foreigner['foreign_table'] . ' -> ' diff --git a/db_operations.php b/db_operations.php index 503a0ae5c0..174a36f09b 100644 --- a/db_operations.php +++ b/db_operations.php @@ -13,8 +13,9 @@ */ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Message; -use PhpMyAdmin\Plugins\Export\ExportSql; use PhpMyAdmin\Operations; +use PhpMyAdmin\Plugins\Export\ExportSql; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Util; @@ -199,14 +200,14 @@ if (strlen($GLOBALS['db']) > 0 * Settings for relations stuff */ -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); /** * Check if comments were updated * (must be done before displaying the menu tabs) */ if (isset($_REQUEST['comment'])) { - PMA_setDbComment($GLOBALS['db'], $_REQUEST['comment']); + Relation::setDbComment($GLOBALS['db'], $_REQUEST['comment']); } require 'libraries/db_common.inc.php'; @@ -303,7 +304,7 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) { . '.' . Util::backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($GLOBALS['db']) . '\''; - $test_rs = PMA_queryAsControlUser( + $test_rs = Relation::queryAsControlUser( $test_query, false, DatabaseInterface::QUERY_STORE diff --git a/db_qbe.php b/db_qbe.php index a2b1e4a314..b571480be9 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -5,7 +5,7 @@ * * @package PhpMyAdmin */ - +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\SavedSearches; use PhpMyAdmin\Sql; @@ -19,7 +19,7 @@ require_once 'libraries/common.inc.php'; $response = Response::getInstance(); // Gets the relation settings -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); $savedSearchList = array(); $savedSearch = null; diff --git a/db_tracking.php b/db_tracking.php index 3f8f148180..32cbbe7ad7 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -6,6 +6,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Tracker; use PhpMyAdmin\Tracking; @@ -110,7 +111,7 @@ if ($num_tables == 0 && count($data['ddlog']) == 0) { } // --------------------------------------------------------------------------- -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); // Prepare statement to get HEAD version $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' . @@ -121,7 +122,7 @@ $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' . ' GROUP BY table_name' . ' ORDER BY table_name ASC'; -$all_tables_result = PMA_queryAsControlUser($all_tables_query); +$all_tables_result = Relation::queryAsControlUser($all_tables_query); // If a HEAD version exists if (is_object($all_tables_result) diff --git a/export.php b/export.php index 9f153c8bca..c121f49901 100644 --- a/export.php +++ b/export.php @@ -9,9 +9,10 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Sanitize; use PhpMyAdmin\Url; use PhpMyAdmin\Util; -use PhpMyAdmin\Sanitize; /** * Get the variables sent or posted to this script and a core script @@ -408,7 +409,7 @@ do { || isset($GLOBALS[$what . '_comments']); $do_mime = isset($GLOBALS[$what . '_mime']); if ($do_relation || $do_comments || $do_mime) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); } // Include dates in export? @@ -11,6 +11,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\LanguageManager; use PhpMyAdmin\Message; use PhpMyAdmin\RecentFavoriteTable; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Sanitize; use PhpMyAdmin\ThemeManager; @@ -560,7 +561,7 @@ if (@file_exists('config')) { } if ($server > 0) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false ) { diff --git a/libraries/central_columns.lib.php b/libraries/central_columns.lib.php index 28ee1f9c52..344d2572cc 100644 --- a/libraries/central_columns.lib.php +++ b/libraries/central_columns.lib.php @@ -7,8 +7,9 @@ */ use PhpMyAdmin\Charsets; use PhpMyAdmin\Message; -use PhpMyAdmin\Util; +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; +use PhpMyAdmin\Util; /** * Defines the central_columns parameters for the current user @@ -24,7 +25,7 @@ function PMA_centralColumnsGetParams() return $cfgCentralColumns; } - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['centralcolumnswork']) { $cfgCentralColumns = array( @@ -409,7 +410,7 @@ function PMA_makeConsistentWithList($db, $selected_tables) $has_list = PMA_getCentralColumnsFromTable($db, $table, true); $GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']); foreach ($has_list as $column) { - $column_status = PMA_checkChildForeignReferences( + $column_status = Relation::checkChildForeignReferences( $db, $table, $column['col_name'] ); //column definition can only be changed if diff --git a/libraries/classes/Bookmark.php b/libraries/classes/Bookmark.php index a4168d1a7e..01b0978d03 100644 --- a/libraries/classes/Bookmark.php +++ b/libraries/classes/Bookmark.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; use PhpMyAdmin\Util; /** @@ -207,7 +208,7 @@ class Bookmark return $cfgBookmark; } - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['bookmarkwork']) { $cfgBookmark = array( 'user' => $GLOBALS['cfg']['Server']['user'], diff --git a/libraries/classes/Console.php b/libraries/classes/Console.php index d33d968510..dab6e341be 100644 --- a/libraries/classes/Console.php +++ b/libraries/classes/Console.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Bookmark; +use PhpMyAdmin\Relation; use PhpMyAdmin\Template; use PhpMyAdmin\Util; @@ -127,7 +128,7 @@ class Console $cfgBookmark = Bookmark::getParams(); $image = Util::getImage('console.png', __('SQL Query Console')); - $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); + $_sql_history = Relation::getHistory($GLOBALS['cfg']['Server']['user']); $bookmarkContent = static::getBookmarkContent(); return Template::get('console/display') diff --git a/libraries/classes/Controllers/Database/DatabaseStructureController.php b/libraries/classes/Controllers/Database/DatabaseStructureController.php index f13513b87d..6fc46929d6 100644 --- a/libraries/classes/Controllers/Database/DatabaseStructureController.php +++ b/libraries/classes/Controllers/Database/DatabaseStructureController.php @@ -15,6 +15,7 @@ use PhpMyAdmin\Controllers\DatabaseController; use PhpMyAdmin\Core; use PhpMyAdmin\Message; use PhpMyAdmin\RecentFavoriteTable; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Template; @@ -234,7 +235,7 @@ class DatabaseStructureController extends DatabaseController // Request for Synchronization of favorite tables. if (isset($_REQUEST['sync_favorite_tables'])) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['favoritework']) { $this->synchronizeFavoriteTables($fav_instance, $user, $favorite_tables); } diff --git a/libraries/classes/Controllers/Table/TableRelationController.php b/libraries/classes/Controllers/Table/TableRelationController.php index 6d3d4137ac..de49fe7358 100644 --- a/libraries/classes/Controllers/Table/TableRelationController.php +++ b/libraries/classes/Controllers/Table/TableRelationController.php @@ -11,6 +11,7 @@ use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Index; +use PhpMyAdmin\Relation; use PhpMyAdmin\Table; use PhpMyAdmin\Template; use PhpMyAdmin\Util; @@ -130,20 +131,20 @@ class TableRelationController extends TableController // If we did an update, refresh our data if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) { - $this->existrel = PMA_getForeigners( + $this->existrel = Relation::getForeigners( $this->db, $this->table, '', 'internal' ); } if (isset($_POST['destination_foreign_db']) && Util::isForeignKeySupported($this->tbl_storage_engine) ) { - $this->existrel_foreign = PMA_getForeigners( + $this->existrel_foreign = Relation::getForeigners( $this->db, $this->table, '', 'foreign' ); } if ($this->cfgRelation['displaywork']) { - $this->disp = PMA_getDisplayField($this->db, $this->table); + $this->disp = Relation::getDisplayField($this->db, $this->table); } // display secondary level tabs if necessary @@ -157,7 +158,7 @@ class TableRelationController extends TableController 'table' => $GLOBALS['table'] ), 'is_foreign_key_supported' => Util::isForeignKeySupported($engine), - 'cfg_relation' => PMA_getRelationsParam(), + 'cfg_relation' => Relation::getRelationsParam(), ) ) ); diff --git a/libraries/classes/Controllers/Table/TableSearchController.php b/libraries/classes/Controllers/Table/TableSearchController.php index 9c325fc715..c0016f4d8d 100644 --- a/libraries/classes/Controllers/Table/TableSearchController.php +++ b/libraries/classes/Controllers/Table/TableSearchController.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Controllers\Table; use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; use PhpMyAdmin\Sql; use PhpMyAdmin\Template; use PhpMyAdmin\Util; @@ -155,7 +156,7 @@ class TableSearchController extends TableController } // end for // Retrieve foreign keys - $this->_foreigners = PMA_getForeigners($this->db, $this->table); + $this->_foreigners = Relation::getForeigners($this->db, $this->table); } /** @@ -265,7 +266,7 @@ class TableSearchController extends TableController //Set default datalabel if not selected if (!isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') { - $dataLabel = PMA_getDisplayField($this->db, $this->table); + $dataLabel = Relation::getDisplayField($this->db, $this->table); } else { $dataLabel = $_POST['dataLabel']; } @@ -854,7 +855,7 @@ class TableSearchController extends TableController ) ); //Gets link to browse foreign data(if any) and criteria inputbox - $foreignData = PMA_getForeignData( + $foreignData = Relation::getForeignData( $this->_foreigners, $this->_columnNames[$column_index], false, '', '' ); $value = Template::get('table/search/input_box')->render( diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index 5d2c70d940..28a5b7f96d 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\Core; use PhpMyAdmin\Index; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Sql; use PhpMyAdmin\SqlParser\Context; use PhpMyAdmin\SqlParser\Parser; @@ -257,7 +258,7 @@ class TableStructureController extends TableController 'table' => $this->table ), 'is_foreign_key_supported' => Util::isForeignKeySupported($engine), - 'cfg_relation' => PMA_getRelationsParam(), + 'cfg_relation' => Relation::getRelationsParam(), ) ) ); @@ -304,7 +305,7 @@ class TableStructureController extends TableController /** * Gets the relation settings */ - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); /** * Runs common work @@ -1029,7 +1030,7 @@ class TableStructureController extends TableController if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) { foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) { if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) { - PMA_REL_renameField( + Relation::renameField( $this->db, $this->table, $fieldcontent, $_REQUEST['field_name'][$fieldindex] ); @@ -1172,7 +1173,7 @@ class TableStructureController extends TableController $mime_map = array(); if ($GLOBALS['cfg']['ShowPropertyComments']) { - $comments_map = PMA_getComments($this->db, $this->table); + $comments_map = Relation::getComments($this->db, $this->table); if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { $mime_map = Transformations::getMIME($this->db, $this->table, true); } diff --git a/libraries/classes/DbQbe.php b/libraries/classes/DbQbe.php index 65eeea356e..7c4e859b9f 100644 --- a/libraries/classes/DbQbe.php +++ b/libraries/classes/DbQbe.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; use PhpMyAdmin\Table; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -1433,7 +1434,7 @@ class DbQbe // So we select candidate tables which are foreign tables. $foreign_tables = array(); foreach ($candidate_columns as $one_table) { - $foreigners = PMA_getForeigners($this->_db, $one_table); + $foreigners = Relation::getForeigners($this->_db, $one_table); foreach ($foreigners as $key => $foreigner) { if ($key != 'foreign_keys_data') { if (in_array($foreigner['foreign_table'], $candidate_columns)) { @@ -1622,7 +1623,7 @@ class DbQbe // having relationships with unfinalized tables foreach ($unfinalized as $oneTable) { - $references = PMA_getChildReferences($this->_db, $oneTable); + $references = Relation::getChildReferences($this->_db, $oneTable); foreach ($references as $column => $columnReferences) { foreach ($columnReferences as $reference) { @@ -1705,7 +1706,7 @@ class DbQbe { $relations[$oneTable] = array(); - $foreigners = PMA_getForeigners($GLOBALS['db'], $oneTable); + $foreigners = Relation::getForeigners($GLOBALS['db'], $oneTable); foreach ($foreigners as $field => $foreigner) { // Foreign keys data if ($field == 'foreign_keys_data') { diff --git a/libraries/classes/DisplayResults.php b/libraries/classes/DisplayResults.php index eabada6697..99ec87d68d 100644 --- a/libraries/classes/DisplayResults.php +++ b/libraries/classes/DisplayResults.php @@ -12,6 +12,7 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\Transformations\Text_Plain_Link; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Sql; @@ -310,7 +311,7 @@ class DisplayResults ) ); - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['db']) { $this->transformation_info[$cfgRelation['db']] = array(); $relDb = &$this->transformation_info[$cfgRelation['db']]; @@ -1607,7 +1608,7 @@ class DisplayResults if (empty($field->table)) { continue; } - $ret[$field->table] = PMA_getComments( + $ret[$field->table] = Relation::getComments( empty($field->database) ? $this->__get('db') : $field->database, $field->table ); @@ -4761,7 +4762,7 @@ class DisplayResults // configuration storage. If no PMA storage, we won't be able // to use the "column to display" notion (for example show // the name related to a numeric id). - $exist_rel = PMA_getForeigners( + $exist_rel = Relation::getForeigners( $this->__get('db'), $this->__get('table'), '', self::POSITION_BOTH ); @@ -4769,7 +4770,7 @@ class DisplayResults foreach ($exist_rel as $master_field => $rel) { if ($master_field != 'foreign_keys_data') { - $display_field = PMA_getDisplayField( + $display_field = Relation::getDisplayField( $rel['foreign_db'], $rel['foreign_table'] ); $map[$master_field] = array( @@ -4781,7 +4782,7 @@ class DisplayResults } else { foreach ($rel as $key => $one_key) { foreach ($one_key['index_list'] as $index => $one_field) { - $display_field = PMA_getDisplayField( + $display_field = Relation::getDisplayField( isset($one_key['ref_db_name']) ? $one_key['ref_db_name'] : $GLOBALS['db'], diff --git a/libraries/classes/Footer.php b/libraries/classes/Footer.php index d5938d0892..d8a66be6d6 100644 --- a/libraries/classes/Footer.php +++ b/libraries/classes/Footer.php @@ -10,6 +10,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Config; use PhpMyAdmin\Core; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Scripts; @@ -246,7 +247,7 @@ class Footer || isset($GLOBALS['controllink']) && $GLOBALS['controllink'])) ) { - PMA_setHistory( + Relation::setHistory( Core::ifSetOr($GLOBALS['db'], ''), Core::ifSetOr($GLOBALS['table'], ''), $GLOBALS['cfg']['Server']['user'], diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 1c3703f7cb..93bbf7f20f 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -10,6 +10,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\TransformationsPlugin; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Transformations; @@ -504,7 +505,7 @@ class InsertEdit */ public static function getNullifyCodeForNullColumn($column, $foreigners, $foreignData) { - $foreigner = PMA_searchColumnInForeigners($foreigners, $column['Field']); + $foreigner = Relation::searchColumnInForeigners($foreigners, $column['Field']); if (mb_strstr($column['True_Type'], 'enum')) { if (mb_strlen($column['Type']) > 20) { $nullify_code = '1'; @@ -740,7 +741,7 @@ class InsertEdit . ($readOnly ? ' disabled' : '') . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"' . ' id="field_' . $idindex . '_3">'; - $html_output .= PMA_foreignDropdown( + $html_output .= Relation::foreignDropdown( $foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $GLOBALS['cfg']['ForeignKeyMaxLimit'] @@ -2090,8 +2091,8 @@ class InsertEdit public static function getDisplayValueForForeignTableColumn($where_comparison, $map, $relation_field ) { - $foreigner = PMA_searchColumnInForeigners($map, $relation_field); - $display_field = PMA_getDisplayField( + $foreigner = Relation::searchColumnInForeigners($map, $relation_field); + $display_field = Relation::getDisplayField( $foreigner['foreign_db'], $foreigner['foreign_table'] ); @@ -2133,7 +2134,7 @@ class InsertEdit public static function getLinkForRelationalDisplayField($map, $relation_field, $where_comparison, $dispval, $relation_field_value ) { - $foreigner = PMA_searchColumnInForeigners($map, $relation_field); + $foreigner = Relation::searchColumnInForeigners($map, $relation_field); if ('K' == $_SESSION['tmpval']['relational_display']) { // user chose "relational key" in the display options, so // the title contains the display field @@ -2596,7 +2597,7 @@ class InsertEdit $comments_map = array(); if ($GLOBALS['cfg']['ShowPropertyComments']) { - $comments_map = PMA_getComments($db, $table); + $comments_map = Relation::getComments($db, $table); } return $comments_map; @@ -2854,7 +2855,7 @@ class InsertEdit // The function column // ------------------- - $foreignData = PMA_getForeignData( + $foreignData = Relation::getForeignData( $foreigners, $column['Field'], false, '', '' ); if ($GLOBALS['cfg']['ShowFunctionFields']) { diff --git a/libraries/classes/Menu.php b/libraries/classes/Menu.php index d214743533..91d3ef050d 100644 --- a/libraries/classes/Menu.php +++ b/libraries/classes/Menu.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; use PhpMyAdmin\Tracker; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -137,7 +138,7 @@ class Menu return Util::cacheGet($cache_key); } $allowedTabs = Util::getMenuTabList($level); - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['menuswork']) { $groupTable = Util::backquote($cfgRelation['db']) . "." @@ -152,7 +153,7 @@ class Menu . $userTable . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "')"; - $result = PMA_queryAsControlUser($sql_query, false); + $result = Relation::queryAsControlUser($sql_query, false); if ($result) { while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { $tabName = mb_substr( @@ -292,12 +293,12 @@ class Menu } // end if } else { // no table selected, display database comment if present - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); // Get additional information about tables for tooltip is done // in Util::getDbInfo() only once if ($cfgRelation['commwork']) { - $comment = PMA_getDbComment($this->_db); + $comment = Relation::getDbComment($this->_db); /** * Displays table comment */ @@ -448,7 +449,7 @@ class Menu /** * Gets the relation settings */ - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $tabs = array(); diff --git a/libraries/classes/Navigation/Navigation.php b/libraries/classes/Navigation/Navigation.php index f801b52c7b..f4e7fa2f3d 100644 --- a/libraries/classes/Navigation/Navigation.php +++ b/libraries/classes/Navigation/Navigation.php @@ -10,9 +10,10 @@ namespace PhpMyAdmin\Navigation; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; -use PhpMyAdmin\Util; use PhpMyAdmin\Url; +use PhpMyAdmin\Util; /** * The navigation panel - displays server, db and table selection tree @@ -98,7 +99,7 @@ class Navigation . "'" . $GLOBALS['dbi']->escapeString($dbName) . "'," . "'" . (! empty($tableName)? $GLOBALS['dbi']->escapeString($tableName) : "" ) . "')"; - PMA_queryAsControlUser($sqlQuery, false); + Relation::queryAsControlUser($sqlQuery, false); } /** @@ -149,7 +150,7 @@ class Navigation ? " AND `table_name`='" . $GLOBALS['dbi']->escapeString($tableName) . "'" : "" ); - PMA_queryAsControlUser($sqlQuery, false); + Relation::queryAsControlUser($sqlQuery, false); } /** @@ -175,7 +176,7 @@ class Navigation . " AND `db_name`='" . $GLOBALS['dbi']->escapeString($dbName) . "'" . " AND `table_name`='" . (! empty($tableName) ? $GLOBALS['dbi']->escapeString($tableName) : '') . "'"; - $result = PMA_queryAsControlUser($sqlQuery, false); + $result = Relation::queryAsControlUser($sqlQuery, false); $hidden = array(); if ($result) { diff --git a/libraries/classes/Navigation/Nodes/Node.php b/libraries/classes/Navigation/Nodes/Node.php index c8ca16dc5b..9017ae3a65 100644 --- a/libraries/classes/Navigation/Nodes/Node.php +++ b/libraries/classes/Navigation/Nodes/Node.php @@ -7,6 +7,7 @@ */ namespace PhpMyAdmin\Navigation\Nodes; +use PhpMyAdmin\Relation; use PhpMyAdmin\Util; /** @@ -806,7 +807,7 @@ class Node */ public function getNavigationHidingData() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['navwork']) { $navTable = Util::backquote($cfgRelation['db']) . "." . Util::backquote( diff --git a/libraries/classes/Navigation/Nodes/NodeDatabase.php b/libraries/classes/Navigation/Nodes/NodeDatabase.php index 4698c68c5e..27ab2559d9 100644 --- a/libraries/classes/Navigation/Nodes/NodeDatabase.php +++ b/libraries/classes/Navigation/Nodes/NodeDatabase.php @@ -7,6 +7,7 @@ */ namespace PhpMyAdmin\Navigation\Nodes; +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -386,7 +387,7 @@ class NodeDatabase extends Node } // Remove hidden items so that they are not displayed in navigation tree - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['navwork']) { $hiddenItems = $this->getHiddenItems(substr($type, 0, -1)); foreach ($retval as $key => $item) { @@ -410,7 +411,7 @@ class NodeDatabase extends Node public function getHiddenItems($type) { $db = $this->real_name; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (empty($cfgRelation['navigationhiding'])) { return array(); } @@ -421,7 +422,7 @@ class NodeDatabase extends Node . " AND `item_type`='" . $type . "'" . " AND `db_name`='" . $GLOBALS['dbi']->escapeString($db) . "'"; - $result = PMA_queryAsControlUser($sqlQuery, false); + $result = Relation::queryAsControlUser($sqlQuery, false); $hiddenItems = array(); if ($result) { while ($row = $GLOBALS['dbi']->fetchArray($result)) { @@ -668,7 +669,7 @@ class NodeDatabase extends Node public function getHtmlForControlButtons() { $ret = ''; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['navwork']) { if ($this->hiddenCount > 0) { $params = array( diff --git a/libraries/classes/Navigation/Nodes/NodeDatabaseChild.php b/libraries/classes/Navigation/Nodes/NodeDatabaseChild.php index d0616857eb..7a7d5cbff4 100644 --- a/libraries/classes/Navigation/Nodes/NodeDatabaseChild.php +++ b/libraries/classes/Navigation/Nodes/NodeDatabaseChild.php @@ -7,6 +7,7 @@ */ namespace PhpMyAdmin\Navigation\Nodes; +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -34,7 +35,7 @@ abstract class NodeDatabaseChild extends Node public function getHtmlForControlButtons() { $ret = ''; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['navwork']) { $db = $this->realParent()->real_name; $item = $this->real_name; diff --git a/libraries/classes/Operations.php b/libraries/classes/Operations.php index e26a0e45c5..15ac55378b 100644 --- a/libraries/classes/Operations.php +++ b/libraries/classes/Operations.php @@ -13,6 +13,7 @@ use PhpMyAdmin\Engines\Innodb; use PhpMyAdmin\Message; use PhpMyAdmin\Partition; use PhpMyAdmin\Plugins\Export\ExportSql; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\StorageEngine; use PhpMyAdmin\Table; @@ -47,7 +48,7 @@ class Operations $html_output .= '</legend>'; $html_output .= '<input type="text" name="comment" ' . 'class="textfield"' - . 'value="' . htmlspecialchars(PMA_getDBComment($db)) . '" />' + . 'value="' . htmlspecialchars(Relation::getDbComment($db)) . '" />' . '</fieldset>'; $html_output .= '<fieldset class="tblFooters">' . '<input type="submit" value="' . __('Go') . '" />' @@ -1279,7 +1280,7 @@ class Operations // display "Add constraints" choice only if there are // foreign keys - if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) { + if (Relation::getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) { $html_output .= '<input type="checkbox" name="add_constraints" ' . 'value="1" id="checkbox_constraints" checked="checked"/>'; $html_output .= '<label for="checkbox_constraints">' diff --git a/libraries/classes/Plugins/Export/ExportHtmlword.php b/libraries/classes/Plugins/Export/ExportHtmlword.php index 991acaa27d..36e6fa1b02 100644 --- a/libraries/classes/Plugins/Export/ExportHtmlword.php +++ b/libraries/classes/Plugins/Export/ExportHtmlword.php @@ -16,6 +16,7 @@ use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem; use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; +use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Util; @@ -371,7 +372,7 @@ class ExportHtmlword extends ExportPlugin $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations - list($res_rel, $have_rel) = PMA_getRelationsAndStatus( + list($res_rel, $have_rel) = Relation::getRelationsAndStatus( $do_relation && !empty($cfgRelation['relation']), $db, $table @@ -404,7 +405,7 @@ class ExportHtmlword extends ExportPlugin $schema_insert .= '<td class="print"><strong>' . __('Comments') . '</strong></td>'; - $comments = PMA_getComments($db, $table); + $comments = Relation::getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print"><strong>' diff --git a/libraries/classes/Plugins/Export/ExportLatex.php b/libraries/classes/Plugins/Export/ExportLatex.php index 83554b45b0..c1f0c3012f 100644 --- a/libraries/classes/Plugins/Export/ExportLatex.php +++ b/libraries/classes/Plugins/Export/ExportLatex.php @@ -16,6 +16,7 @@ use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem; use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; +use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Util; @@ -494,7 +495,7 @@ class ExportLatex extends ExportPlugin $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations - list($res_rel, $have_rel) = PMA_getRelationsAndStatus( + list($res_rel, $have_rel) = Relation::getRelationsAndStatus( $do_relation && !empty($cfgRelation['relation']), $db, $table @@ -530,7 +531,7 @@ class ExportLatex extends ExportPlugin } if ($do_comments) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}'; - $comments = PMA_getComments($db, $table); + $comments = Relation::getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; diff --git a/libraries/classes/Plugins/Export/ExportOdt.php b/libraries/classes/Plugins/Export/ExportOdt.php index d146c80f30..5e9c2d47f2 100644 --- a/libraries/classes/Plugins/Export/ExportOdt.php +++ b/libraries/classes/Plugins/Export/ExportOdt.php @@ -17,6 +17,7 @@ use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem; use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; +use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Util; @@ -452,7 +453,7 @@ class ExportOdt extends ExportPlugin $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations - list($res_rel, $have_rel) = PMA_getRelationsAndStatus( + list($res_rel, $have_rel) = Relation::getRelationsAndStatus( $do_relation && !empty($cfgRelation['relation']), $db, $table @@ -497,7 +498,7 @@ class ExportOdt extends ExportPlugin $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Comments') . '</text:p>' . '</table:table-cell>'; - $comments = PMA_getComments($db, $table); + $comments = Relation::getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' @@ -518,7 +519,7 @@ class ExportOdt extends ExportPlugin $col_as ); if ($do_relation && $have_rel) { - $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name); + $foreigner = Relation::searchColumnInForeigners($res_rel, $field_name); if ($foreigner) { $rtable = $foreigner['foreign_table']; $rfield = $foreigner['foreign_field']; diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php index bde8d4eaf5..f7c81c3677 100644 --- a/libraries/classes/Plugins/Export/ExportSql.php +++ b/libraries/classes/Plugins/Export/ExportSql.php @@ -21,6 +21,7 @@ use PhpMyAdmin\Properties\Options\Items\NumberPropertyItem; use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem; use PhpMyAdmin\Properties\Options\Items\SelectPropertyItem; use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; +use PhpMyAdmin\Relation; use PhpMyAdmin\SqlParser\Components\CreateDefinition; use PhpMyAdmin\SqlParser\Context; use PhpMyAdmin\SqlParser\Parser; @@ -996,7 +997,7 @@ class ExportSql extends ExportPlugin $tables, $metadataTypes ) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (!isset($cfgRelation['db'])) { return true; } @@ -1048,7 +1049,7 @@ class ExportSql extends ExportPlugin $table, $metadataTypes ) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (isset($table)) { $types = array( @@ -1837,7 +1838,7 @@ class ExportSql extends ExportPlugin $schema_create = ''; // Check if we can use Relations - list($res_rel, $have_rel) = PMA_getRelationsAndStatus( + list($res_rel, $have_rel) = Relation::getRelationsAndStatus( $do_relation && !empty($cfgRelation['relation']), $db, $table diff --git a/libraries/classes/Plugins/Export/ExportTexytext.php b/libraries/classes/Plugins/Export/ExportTexytext.php index b039e0ef94..65cd1e7e6b 100644 --- a/libraries/classes/Plugins/Export/ExportTexytext.php +++ b/libraries/classes/Plugins/Export/ExportTexytext.php @@ -16,6 +16,7 @@ use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem; use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; +use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Util; @@ -362,7 +363,7 @@ class ExportTexytext extends ExportPlugin $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations - list($res_rel, $have_rel) = PMA_getRelationsAndStatus( + list($res_rel, $have_rel) = Relation::getRelationsAndStatus( $do_relation && !empty($cfgRelation['relation']), $db, $table @@ -382,7 +383,7 @@ class ExportTexytext extends ExportPlugin } if ($do_comments) { $text_output .= '|' . __('Comments'); - $comments = PMA_getComments($db, $table); + $comments = Relation::getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $text_output .= '|' . htmlspecialchars('MIME'); diff --git a/libraries/classes/Plugins/Export/Helpers/Pdf.php b/libraries/classes/Plugins/Export/Helpers/Pdf.php index 67ff1ebdda..f308af5826 100644 --- a/libraries/classes/Plugins/Export/Helpers/Pdf.php +++ b/libraries/classes/Plugins/Export/Helpers/Pdf.php @@ -10,6 +10,7 @@ namespace PhpMyAdmin\Plugins\Export\Helpers; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Pdf as PdfLib; +use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Util; use TCPDF_STATIC; @@ -463,7 +464,7 @@ class Pdf extends PdfLib if ($do_relation) { // Find which tables are related with the current one and write it in // an array - $res_rel = PMA_getForeigners($db, $table); + $res_rel = Relation::getForeigners($db, $table); $have_rel = !empty($res_rel); } else { $have_rel = false; @@ -516,7 +517,7 @@ class Pdf extends PdfLib // Now let's start to write the table structure if ($do_comments) { - $comments = PMA_getComments($db, $table); + $comments = Relation::getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $mime_map = Transformations::getMIME($db, $table, true); diff --git a/libraries/classes/Plugins/ExportPlugin.php b/libraries/classes/Plugins/ExportPlugin.php index 0d2622468c..ff856f99a7 100644 --- a/libraries/classes/Plugins/ExportPlugin.php +++ b/libraries/classes/Plugins/ExportPlugin.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Plugins; use PhpMyAdmin\Properties\Plugins\ExportPluginProperties; +use PhpMyAdmin\Relation; /** * Provides a common interface that will have to be implemented by all of the @@ -349,7 +350,7 @@ abstract class ExportPlugin $aliases = array() ) { $relation = ''; - $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name); + $foreigner = Relation::searchColumnInForeigners($res_rel, $field_name); if ($foreigner) { $ftable = $foreigner['foreign_table']; $ffield = $foreigner['foreign_field']; diff --git a/libraries/classes/Plugins/Schema/Dia/DiaRelationSchema.php b/libraries/classes/Plugins/Schema/Dia/DiaRelationSchema.php index 138e18a984..d63304f0cf 100644 --- a/libraries/classes/Plugins/Schema/Dia/DiaRelationSchema.php +++ b/libraries/classes/Plugins/Schema/Dia/DiaRelationSchema.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Plugins\Schema\ExportRelationSchema; use PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf; use PhpMyAdmin\Plugins\Schema\Svg\TableStatsSvg; use PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia; +use PhpMyAdmin\Relation; /** * Dia Relation Schema Class @@ -83,7 +84,7 @@ class DiaRelationSchema extends ExportRelationSchema $seen_a_relation = false; foreach ($alltables as $one_table) { - $exist_rel = PMA_getForeigners($this->db, $one_table, '', 'both'); + $exist_rel = Relation::getForeigners($this->db, $one_table, '', 'both'); if (!$exist_rel) { continue; } diff --git a/libraries/classes/Plugins/Schema/Eps/EpsRelationSchema.php b/libraries/classes/Plugins/Schema/Eps/EpsRelationSchema.php index 4026c3392a..0d812225c7 100644 --- a/libraries/classes/Plugins/Schema/Eps/EpsRelationSchema.php +++ b/libraries/classes/Plugins/Schema/Eps/EpsRelationSchema.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia; use PhpMyAdmin\Plugins\Schema\ExportRelationSchema; use PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf; use PhpMyAdmin\Plugins\Schema\Svg\TableStatsSvg; +use PhpMyAdmin\Relation; /** * EPS Relation Schema Class @@ -91,7 +92,7 @@ class EpsRelationSchema extends ExportRelationSchema $seen_a_relation = false; foreach ($alltables as $one_table) { - $exist_rel = PMA_getForeigners($this->db, $one_table, '', 'both'); + $exist_rel = Relation::getForeigners($this->db, $one_table, '', 'both'); if (!$exist_rel) { continue; } diff --git a/libraries/classes/Plugins/Schema/ExportRelationSchema.php b/libraries/classes/Plugins/Schema/ExportRelationSchema.php index 939f40928f..fa0bc51505 100644 --- a/libraries/classes/Plugins/Schema/ExportRelationSchema.php +++ b/libraries/classes/Plugins/Schema/ExportRelationSchema.php @@ -8,6 +8,7 @@ */ namespace PhpMyAdmin\Plugins\Schema; +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -265,7 +266,7 @@ class ExportRelationSchema . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . Util::backquote($GLOBALS['cfgRelation']['pdf_pages']) . ' WHERE page_nr = ' . $this->pageNumber; - $_name_rs = PMA_queryAsControlUser($_name_sql); + $_name_rs = Relation::queryAsControlUser($_name_sql); $_name_row = $GLOBALS['dbi']->fetchRow($_name_rs); $filename = $_name_row[0] . $extension; } diff --git a/libraries/classes/Plugins/Schema/Pdf/Pdf.php b/libraries/classes/Plugins/Schema/Pdf/Pdf.php index 9cbc02b813..98e080f619 100644 --- a/libraries/classes/Plugins/Schema/Pdf/Pdf.php +++ b/libraries/classes/Plugins/Schema/Pdf/Pdf.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin\Plugins\Schema\Pdf; use PhpMyAdmin\Pdf as PdfLib; +use PhpMyAdmin\Relation; use PhpMyAdmin\Util; /** @@ -241,7 +242,7 @@ class Pdf extends PdfLib . Util::backquote($GLOBALS['cfgRelation']['pdf_pages']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($this->_db) . '\' AND page_nr = \'' . $this->_pageNumber . '\''; - $test_rs = PMA_queryAsControlUser($test_query); + $test_rs = Relation::queryAsControlUser($test_query); $pages = @$GLOBALS['dbi']->fetchAssoc($test_rs); $pg_name = ucfirst($pages['page_descr']); } diff --git a/libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php b/libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php index e05f63332d..523936c3ba 100644 --- a/libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php +++ b/libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Plugins\Schema\Pdf; use PhpMyAdmin\Pdf as PdfLib; use PhpMyAdmin\Plugins\Schema\ExportRelationSchema; +use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Util; @@ -185,7 +186,7 @@ class PdfRelationSchema extends ExportRelationSchema // and finding its foreigns is OK (then we can support innodb) $seen_a_relation = false; foreach ($alltables as $one_table) { - $exist_rel = PMA_getForeigners($this->db, $one_table, '', 'both'); + $exist_rel = Relation::getForeigners($this->db, $one_table, '', 'both'); if (!$exist_rel) { continue; } @@ -546,8 +547,8 @@ class PdfRelationSchema extends ExportRelationSchema $this->diagram->SetFont($this->_ff, '', 8); $this->diagram->ln(); - $cfgRelation = PMA_getRelationsParam(); - $comments = PMA_getComments($this->db, $table); + $cfgRelation = Relation::getRelationsParam(); + $comments = Relation::getComments($this->db, $table); if ($cfgRelation['mimework']) { $mime_map = Transformations::getMIME($this->db, $table, true); } @@ -583,7 +584,7 @@ class PdfRelationSchema extends ExportRelationSchema // Find which tables are related with the current one and write it in // an array - $res_rel = PMA_getForeigners($this->db, $table); + $res_rel = Relation::getForeigners($this->db, $table); /** * Displays the comments of the table if MySQL >= 3.23 @@ -679,7 +680,7 @@ class PdfRelationSchema extends ExportRelationSchema $this->diagram->SetLink( $this->diagram->PMA_links['doc'][$table][$field_name], -1 ); - $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name); + $foreigner = Relation::searchColumnInForeigners($res_rel, $field_name); $linksTo = ''; if ($foreigner) { diff --git a/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php b/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php index 1aeca84a50..5d5231125b 100644 --- a/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php +++ b/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php @@ -14,6 +14,7 @@ use PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf; use PhpMyAdmin\Plugins\Schema\Svg\Svg; use PhpMyAdmin\Plugins\Schema\Svg\TableStatsSvg; use PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia; +use PhpMyAdmin\Relation; /** * RelationStatsSvg Relation Schema Class @@ -103,7 +104,7 @@ class SvgRelationSchema extends ExportRelationSchema $seen_a_relation = false; foreach ($alltables as $one_table) { - $exist_rel = PMA_getForeigners($this->db, $one_table, '', 'both'); + $exist_rel = Relation::getForeigners($this->db, $one_table, '', 'both'); if (!$exist_rel) { continue; } diff --git a/libraries/classes/Plugins/Schema/TableStats.php b/libraries/classes/Plugins/Schema/TableStats.php index 50f21a7653..a994505581 100644 --- a/libraries/classes/Plugins/Schema/TableStats.php +++ b/libraries/classes/Plugins/Schema/TableStats.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Plugins\Schema; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Index; +use PhpMyAdmin\Relation; use PhpMyAdmin\Util; /** @@ -136,7 +137,7 @@ abstract class TableStats */ protected function loadDisplayField() { - $this->displayfield = PMA_getDisplayField($this->db, $this->tableName); + $this->displayfield = Relation::getDisplayField($this->db, $this->tableName); } /** diff --git a/libraries/classes/RecentFavoriteTable.php b/libraries/classes/RecentFavoriteTable.php index 0486a8d549..33b803e1b6 100644 --- a/libraries/classes/RecentFavoriteTable.php +++ b/libraries/classes/RecentFavoriteTable.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -103,7 +104,7 @@ class RecentFavoriteTable " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "'"; $return = array(); - $result = PMA_queryAsControlUser($sql_query, false); + $result = Relation::queryAsControlUser($sql_query, false); if ($result) { $row = $GLOBALS['dbi']->fetchArray($result); if (isset($row[0])) { @@ -348,7 +349,7 @@ class RecentFavoriteTable if ($server_id == 0) { return ''; } - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); // Not to show this once list is synchronized. if ($cfgRelation['favoritework'] && ! isset($_SESSION['tmpval']['favorites_synced'][$server_id])) { $params = array('ajax_request' => true, 'favorite_table' => true, @@ -381,7 +382,7 @@ class RecentFavoriteTable */ private function _getPmaTable() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! empty($cfgRelation['db']) && ! empty($cfgRelation[$this->_tableType]) ) { diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php new file mode 100644 index 0000000000..02442b6bbd --- /dev/null +++ b/libraries/classes/Relation.php @@ -0,0 +1,2100 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Set of functions used with the relation and pdf feature + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin; + +use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Message; +use PhpMyAdmin\RecentFavoriteTable; +use PhpMyAdmin\SqlParser\Parser; +use PhpMyAdmin\SqlParser\Utils\Table as TableUtils; +use PhpMyAdmin\Table; +use PhpMyAdmin\Template; +use PhpMyAdmin\Url; +use PhpMyAdmin\Util; + +/** + * PhpMyAdmin\Relation class + * + * @package PhpMyAdmin + */ +class Relation +{ + /** + * Executes a query as controluser if possible, otherwise as normal user + * + * @param string $sql the query to execute + * @param boolean $show_error whether to display SQL error messages or not + * @param int $options query options + * + * @return resource|boolean the result set, or false if no result set + * + * @access public + * + */ + public static function queryAsControlUser($sql, $show_error = true, $options = 0) + { + // Avoid caching of the number of rows affected; for example, this function + // is called for tracking purposes but we want to display the correct number + // of rows affected by the original query, not by the query generated for + // tracking. + $cache_affected_rows = false; + + if ($show_error) { + $result = $GLOBALS['dbi']->query( + $sql, + $GLOBALS['controllink'], + $options, + $cache_affected_rows + ); + } else { + $result = @$GLOBALS['dbi']->tryQuery( + $sql, + $GLOBALS['controllink'], + $options, + $cache_affected_rows + ); + } // end if... else... + + if ($result) { + return $result; + } else { + return false; + } + } // end of the "self::queryAsControlUser()" function + + /** + * Returns current relation parameters + * + * @return array $cfgRelation + */ + public static function getRelationsParam() + { + if (empty($_SESSION['relation'][$GLOBALS['server']]) + || (empty($_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'])) + || $_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'] != PMA_VERSION + ) { + $_SESSION['relation'][$GLOBALS['server']] = self::checkRelationsParam(); + } + + // just for BC but needs to be before self::getRelationsParamDiagnostic() + // which uses it + $GLOBALS['cfgRelation'] = $_SESSION['relation'][$GLOBALS['server']]; + + return $_SESSION['relation'][$GLOBALS['server']]; + } + + /** + * prints out diagnostic info for pma relation feature + * + * @param array $cfgRelation Relation configuration + * + * @return string + */ + public static function getRelationsParamDiagnostic($cfgRelation) + { + $retval = '<br>'; + + $messages = array(); + $messages['error'] = '<span style="color:red"><strong>' + . __('not OK') + . '</strong></span>'; + + $messages['ok'] = '<span style="color:green"><strong>' + . _pgettext('Correctly working', 'OK') + . '</strong></span>'; + + $messages['enabled'] = '<span style="color:green">' . __('Enabled') . '</span>'; + $messages['disabled'] = '<span style="color:red">' . __('Disabled') . '</span>'; + + if (empty($cfgRelation['db'])) { + $retval .= __('Configuration of pmadb…') . ' ' + . $messages['error'] + . Util::showDocu('setup', 'linked-tables') + . '<br />' . "\n" + . __('General relation features') + . ' <font color="green">' . __('Disabled') + . '</font>' . "\n"; + if ($GLOBALS['cfg']['ZeroConf']) { + if (empty($GLOBALS['db'])) { + $retval .= self::getHtmlFixPmaTables(true, true); + } else { + $retval .= self::getHtmlFixPmaTables(true); + } + } + } else { + $retval .= '<table>' . "\n"; + + if (! $cfgRelation['allworks'] + && $GLOBALS['cfg']['ZeroConf'] + // Avoid showing a "Create missing tables" link if it's a + // problem of missing definition + && self::arePmadbTablesDefined() + ) { + $retval .= self::getHtmlFixPmaTables(false); + $retval .= '<br />'; + } + + $retval .= self::getDiagMessageForParameter( + 'pmadb', + $cfgRelation['db'], + $messages, + 'pmadb' + ); + $retval .= self::getDiagMessageForParameter( + 'relation', + isset($cfgRelation['relation']), + $messages, + 'relation' + ); + $retval .= self::getDiagMessageForFeature( + __('General relation features'), + 'relwork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'table_info', + isset($cfgRelation['table_info']), + $messages, + 'table_info' + ); + $retval .= self::getDiagMessageForFeature( + __('Display Features'), + 'displaywork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'table_coords', + isset($cfgRelation['table_coords']), + $messages, + 'table_coords' + ); + $retval .= self::getDiagMessageForParameter( + 'pdf_pages', + isset($cfgRelation['pdf_pages']), + $messages, + 'pdf_pages' + ); + $retval .= self::getDiagMessageForFeature( + __('Designer and creation of PDFs'), + 'pdfwork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'column_info', + isset($cfgRelation['column_info']), + $messages, + 'column_info' + ); + $retval .= self::getDiagMessageForFeature( + __('Displaying Column Comments'), + 'commwork', + $messages, + false + ); + $retval .= self::getDiagMessageForFeature( + __('Browser transformation'), + 'mimework', + $messages + ); + if ($cfgRelation['commwork'] && ! $cfgRelation['mimework']) { + $retval .= '<tr><td colspan=2 class="left error">'; + $retval .= __( + 'Please see the documentation on how to' + . ' update your column_info table.' + ); + $retval .= Util::showDocu( + 'config', + 'cfg_Servers_column_info' + ); + $retval .= '</td></tr>'; + } + $retval .= self::getDiagMessageForParameter( + 'bookmarktable', + isset($cfgRelation['bookmark']), + $messages, + 'bookmark' + ); + $retval .= self::getDiagMessageForFeature( + __('Bookmarked SQL query'), + 'bookmarkwork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'history', + isset($cfgRelation['history']), + $messages, + 'history' + ); + $retval .= self::getDiagMessageForFeature( + __('SQL history'), + 'historywork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'recent', + isset($cfgRelation['recent']), + $messages, + 'recent' + ); + $retval .= self::getDiagMessageForFeature( + __('Persistent recently used tables'), + 'recentwork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'favorite', + isset($cfgRelation['favorite']), + $messages, + 'favorite' + ); + $retval .= self::getDiagMessageForFeature( + __('Persistent favorite tables'), + 'favoritework', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'table_uiprefs', + isset($cfgRelation['table_uiprefs']), + $messages, + 'table_uiprefs' + ); + $retval .= self::getDiagMessageForFeature( + __('Persistent tables\' UI preferences'), + 'uiprefswork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'tracking', + isset($cfgRelation['tracking']), + $messages, + 'tracking' + ); + $retval .= self::getDiagMessageForFeature( + __('Tracking'), + 'trackingwork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'userconfig', + isset($cfgRelation['userconfig']), + $messages, + 'userconfig' + ); + $retval .= self::getDiagMessageForFeature( + __('User preferences'), + 'userconfigwork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'users', + isset($cfgRelation['users']), + $messages, + 'users' + ); + $retval .= self::getDiagMessageForParameter( + 'usergroups', + isset($cfgRelation['usergroups']), + $messages, + 'usergroups' + ); + $retval .= self::getDiagMessageForFeature( + __('Configurable menus'), + 'menuswork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'navigationhiding', + isset($cfgRelation['navigationhiding']), + $messages, + 'navigationhiding' + ); + $retval .= self::getDiagMessageForFeature( + __('Hide/show navigation items'), + 'navwork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'savedsearches', + isset($cfgRelation['savedsearches']), + $messages, + 'savedsearches' + ); + $retval .= self::getDiagMessageForFeature( + __('Saving Query-By-Example searches'), + 'savedsearcheswork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'central_columns', + isset($cfgRelation['central_columns']), + $messages, + 'central_columns' + ); + $retval .= self::getDiagMessageForFeature( + __('Managing Central list of columns'), + 'centralcolumnswork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'designer_settings', + isset($cfgRelation['designer_settings']), + $messages, + 'designer_settings' + ); + $retval .= self::getDiagMessageForFeature( + __('Remembering Designer Settings'), + 'designersettingswork', + $messages + ); + $retval .= self::getDiagMessageForParameter( + 'export_templates', + isset($cfgRelation['export_templates']), + $messages, + 'export_templates' + ); + $retval .= self::getDiagMessageForFeature( + __('Saving export templates'), + 'exporttemplateswork', + $messages + ); + $retval .= '</table>' . "\n"; + + if (! $cfgRelation['allworks']) { + + $retval .= '<p>' . __('Quick steps to set up advanced features:') + . '</p>'; + + $items = array(); + $items[] = sprintf( + __( + 'Create the needed tables with the ' + . '<code>%screate_tables.sql</code>.' + ), + htmlspecialchars(SQL_DIR) + ) . ' ' . Util::showDocu('setup', 'linked-tables'); + $items[] = __('Create a pma user and give access to these tables.') . ' ' + . Util::showDocu('config', 'cfg_Servers_controluser'); + $items[] = __( + 'Enable advanced features in configuration file ' + . '(<code>config.inc.php</code>), for example by ' + . 'starting from <code>config.sample.inc.php</code>.' + ) . ' ' . Util::showDocu('setup', 'quick-install'); + $items[] = __( + 'Re-login to phpMyAdmin to load the updated configuration file.' + ); + + $retval .= Template::get('list/unordered')->render( + array('items' => $items,) + ); + } + } + + return $retval; + } + + /** + * prints out one diagnostic message for a feature + * + * @param string $feature_name feature name in a message string + * @param string $relation_parameter the $GLOBALS['cfgRelation'] parameter to check + * @param array $messages utility messages + * @param boolean $skip_line whether to skip a line after the message + * + * @return string + */ + public static function getDiagMessageForFeature($feature_name, + $relation_parameter, $messages, $skip_line = true + ) { + $retval = ' <tr><td colspan=2 class="right">' . $feature_name . ': '; + if (isset($GLOBALS['cfgRelation'][$relation_parameter]) + && $GLOBALS['cfgRelation'][$relation_parameter] + ) { + $retval .= $messages['enabled']; + } else { + $retval .= $messages['disabled']; + } + $retval .= '</td></tr>'; + if ($skip_line) { + $retval .= '<tr><td> </td></tr>'; + } + return $retval; + } + + /** + * prints out one diagnostic message for a configuration parameter + * + * @param string $parameter config parameter name to display + * @param boolean $relationParameterSet whether this parameter is set + * @param array $messages utility messages + * @param string $docAnchor anchor in documentation + * + * @return string + */ + public static function getDiagMessageForParameter($parameter, + $relationParameterSet, $messages, $docAnchor + ) { + $retval = '<tr><th class="left">'; + $retval .= '$cfg[\'Servers\'][$i][\'' . $parameter . '\'] ... '; + $retval .= '</th><td class="right">'; + if ($relationParameterSet) { + $retval .= $messages['ok']; + } else { + $retval .= sprintf( + $messages['error'], + Util::getDocuLink('config', 'cfg_Servers_' . $docAnchor) + ); + } + $retval .= '</td></tr>' . "\n"; + return $retval; + } + + /** + * Defines the relation parameters for the current user + * just a copy of the functions used for relations ;-) + * but added some stuff to check what will work + * + * @access protected + * @return array the relation parameters for the current user + */ + public static function checkRelationsParam() + { + $cfgRelation = array(); + $cfgRelation['PMA_VERSION'] = PMA_VERSION; + + $workToTable = array( + 'relwork' => 'relation', + 'displaywork' => array('relation', 'table_info'), + 'bookmarkwork' => 'bookmarktable', + 'pdfwork' => array('table_coords', 'pdf_pages'), + 'commwork' => 'column_info', + 'mimework' => 'column_info', + 'historywork' => 'history', + 'recentwork' => 'recent', + 'favoritework' => 'favorite', + 'uiprefswork' => 'table_uiprefs', + 'trackingwork' => 'tracking', + 'userconfigwork' => 'userconfig', + 'menuswork' => array('users', 'usergroups'), + 'navwork' => 'navigationhiding', + 'savedsearcheswork' => 'savedsearches', + 'centralcolumnswork' => 'central_columns', + 'designersettingswork' => 'designer_settings', + 'exporttemplateswork' => 'export_templates', + ); + + foreach ($workToTable as $work => $table) { + $cfgRelation[$work] = false; + } + $cfgRelation['allworks'] = false; + $cfgRelation['user'] = null; + $cfgRelation['db'] = null; + + if ($GLOBALS['server'] == 0 + || empty($GLOBALS['cfg']['Server']['pmadb']) + || empty($GLOBALS['controllink']) + || ! $GLOBALS['dbi']->selectDb( + $GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink'] + ) + ) { + // No server selected -> no bookmark table + // we return the array with the falses in it, + // to avoid some 'Uninitialized string offset' errors later + $GLOBALS['cfg']['Server']['pmadb'] = false; + return $cfgRelation; + } + + $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user']; + $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb']; + + // Now I just check if all tables that i need are present so I can for + // example enable relations but not pdf... + // I was thinking of checking if they have all required columns but I + // fear it might be too slow + + $tab_query = 'SHOW TABLES FROM ' + . Util::backquote( + $GLOBALS['cfg']['Server']['pmadb'] + ); + $tab_rs = self::queryAsControlUser( + $tab_query, false, DatabaseInterface::QUERY_STORE + ); + + if (! $tab_rs) { + // query failed ... ? + //$GLOBALS['cfg']['Server']['pmadb'] = false; + return $cfgRelation; + } + + while ($curr_table = @$GLOBALS['dbi']->fetchRow($tab_rs)) { + if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) { + $cfgRelation['bookmark'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { + $cfgRelation['relation'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) { + $cfgRelation['table_info'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) { + $cfgRelation['table_coords'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) { + $cfgRelation['column_info'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) { + $cfgRelation['pdf_pages'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) { + $cfgRelation['history'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { + $cfgRelation['recent'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['favorite']) { + $cfgRelation['favorite'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) { + $cfgRelation['table_uiprefs'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { + $cfgRelation['tracking'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { + $cfgRelation['userconfig'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['users']) { + $cfgRelation['users'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['usergroups']) { + $cfgRelation['usergroups'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['navigationhiding']) { + $cfgRelation['navigationhiding'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['savedsearches']) { + $cfgRelation['savedsearches'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['central_columns']) { + $cfgRelation['central_columns'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['designer_settings']) { + $cfgRelation['designer_settings'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['export_templates']) { + $cfgRelation['export_templates'] = $curr_table[0]; + } + } // end while + $GLOBALS['dbi']->freeResult($tab_rs); + + if (isset($cfgRelation['relation'])) { + $cfgRelation['relwork'] = true; + } + + if (isset($cfgRelation['relation']) && isset($cfgRelation['table_info'])) { + $cfgRelation['displaywork'] = true; + } + + if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { + $cfgRelation['pdfwork'] = true; + } + + if (isset($cfgRelation['column_info'])) { + $cfgRelation['commwork'] = true; + // phpMyAdmin 4.3+ + // Check for input transformations upgrade. + $cfgRelation['mimework'] = self::tryUpgradeTransformations(); + } + + if (isset($cfgRelation['history'])) { + $cfgRelation['historywork'] = true; + } + + if (isset($cfgRelation['recent'])) { + $cfgRelation['recentwork'] = true; + } + + if (isset($cfgRelation['favorite'])) { + $cfgRelation['favoritework'] = true; + } + + if (isset($cfgRelation['table_uiprefs'])) { + $cfgRelation['uiprefswork'] = true; + } + + if (isset($cfgRelation['tracking'])) { + $cfgRelation['trackingwork'] = true; + } + + if (isset($cfgRelation['userconfig'])) { + $cfgRelation['userconfigwork'] = true; + } + + if (isset($cfgRelation['bookmark'])) { + $cfgRelation['bookmarkwork'] = true; + } + + if (isset($cfgRelation['users']) && isset($cfgRelation['usergroups'])) { + $cfgRelation['menuswork'] = true; + } + + if (isset($cfgRelation['navigationhiding'])) { + $cfgRelation['navwork'] = true; + } + + if (isset($cfgRelation['savedsearches'])) { + $cfgRelation['savedsearcheswork'] = true; + } + + if (isset($cfgRelation['central_columns'])) { + $cfgRelation['centralcolumnswork'] = true; + } + + if (isset($cfgRelation['designer_settings'])) { + $cfgRelation['designersettingswork'] = true; + } + + if (isset($cfgRelation['export_templates'])) { + $cfgRelation['exporttemplateswork'] = true; + } + + $allWorks = true; + foreach ($workToTable as $work => $table) { + if (! $cfgRelation[$work]) { + if (is_string($table)) { + if (isset($GLOBALS['cfg']['Server'][$table]) + && $GLOBALS['cfg']['Server'][$table] !== false + ) { + $allWorks = false; + break; + } + } else if (is_array($table)) { + $oneNull = false; + foreach ($table as $t) { + if (isset($GLOBALS['cfg']['Server'][$t]) + && $GLOBALS['cfg']['Server'][$t] === false + ) { + $oneNull = true; + break; + } + } + if (! $oneNull) { + $allWorks = false; + break; + } + } + } + } + $cfgRelation['allworks'] = $allWorks; + + return $cfgRelation; + } // end of the 'self::checkRelationsParam()' function + + /** + * Check whether column_info table input transformation + * upgrade is required and try to upgrade silently + * + * @return bool false if upgrade failed + * + * @access public + */ + public static function tryUpgradeTransformations() + { + // From 4.3, new input oriented transformation feature was introduced. + // Check whether column_info table has input transformation columns + $new_cols = array( + "input_transformation", + "input_transformation_options" + ); + $query = 'SHOW COLUMNS FROM ' + . Util::backquote($GLOBALS['cfg']['Server']['pmadb']) + . '.' . Util::backquote( + $GLOBALS['cfg']['Server']['column_info'] + ) + . ' WHERE Field IN (\'' . implode('\', \'', $new_cols) . '\')'; + $result = self::queryAsControlUser( + $query, false, DatabaseInterface::QUERY_STORE + ); + if ($result) { + $rows = $GLOBALS['dbi']->numRows($result); + $GLOBALS['dbi']->freeResult($result); + // input transformations are present + // no need to upgrade + if ($rows === 2) { + return true; + // try silent upgrade without disturbing the user + } else { + // read upgrade query file + $query = @file_get_contents(SQL_DIR . 'upgrade_column_info_4_3_0+.sql'); + // replace database name from query to with set in config.inc.php + $query = str_replace( + '`phpmyadmin`', + Util::backquote($GLOBALS['cfg']['Server']['pmadb']), + $query + ); + // replace pma__column_info table name from query + // to with set in config.inc.php + $query = str_replace( + '`pma__column_info`', + Util::backquote( + $GLOBALS['cfg']['Server']['column_info'] + ), + $query + ); + $GLOBALS['dbi']->tryMultiQuery($query, $GLOBALS['controllink']); + // skips result sets of query as we are not interested in it + while ($GLOBALS['dbi']->moreResults($GLOBALS['controllink']) + && $GLOBALS['dbi']->nextResult($GLOBALS['controllink']) + ) { + } + $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']); + // return true if no error exists otherwise false + return empty($error); + } + } + // some failure, either in upgrading or something else + // make some noise, time to wake up user. + return false; + } + + /** + * Gets all Relations to foreign tables for a given table or + * optionally a given column in a table + * + * @param string $db the name of the db to check for + * @param string $table the name of the table to check for + * @param string $column the name of the column to check for + * @param string $source the source for foreign key information + * + * @return array db,table,column + * + * @access public + */ + public static function getForeigners($db, $table, $column = '', $source = 'both') + { + $cfgRelation = self::getRelationsParam(); + $foreign = array(); + + if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) { + $rel_query = ' + SELECT `master_field`, + `foreign_db`, + `foreign_table`, + `foreign_field` + FROM ' . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['relation']) . ' + WHERE `master_db` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' + AND `master_table` = \'' . $GLOBALS['dbi']->escapeString($table) + . '\' '; + if (strlen($column) > 0) { + $rel_query .= ' AND `master_field` = ' + . '\'' . $GLOBALS['dbi']->escapeString($column) . '\''; + } + $foreign = $GLOBALS['dbi']->fetchResult( + $rel_query, 'master_field', null, $GLOBALS['controllink'] + ); + } + + if (($source == 'both' || $source == 'foreign') && strlen($table) > 0) { + $tableObj = new Table($table, $db); + $show_create_table = $tableObj->showCreate(); + if ($show_create_table) { + $parser = new Parser($show_create_table); + /** + * @var \PhpMyAdmin\SqlParser\Statements\CreateStatement $stmt + */ + $stmt = $parser->statements[0]; + $foreign['foreign_keys_data'] = TableUtils::getForeignKeys( + $stmt + ); + } + } + + /** + * Emulating relations for some information_schema tables + */ + $isInformationSchema = mb_strtolower($db) == 'information_schema'; + $isMysql = mb_strtolower($db) == 'mysql'; + if (($isInformationSchema || $isMysql) + && ($source == 'internal' || $source == 'both') + ) { + if ($isInformationSchema) { + $relations_key = 'information_schema_relations'; + include_once './libraries/information_schema_relations.lib.php'; + } else { + $relations_key = 'mysql_relations'; + include_once './libraries/mysql_relations.lib.php'; + } + if (isset($GLOBALS[$relations_key][$table])) { + foreach ($GLOBALS[$relations_key][$table] as $field => $relations) { + if ((strlen($column) === 0 || $column == $field) + && (! isset($foreign[$field]) + || strlen($foreign[$field]) === 0) + ) { + $foreign[$field] = $relations; + } + } + } + } + + return $foreign; + } // end of the 'self::getForeigners()' function + + /** + * Gets the display field of a table + * + * @param string $db the name of the db to check for + * @param string $table the name of the table to check for + * + * @return string field name + * + * @access public + */ + public static function getDisplayField($db, $table) + { + $cfgRelation = self::getRelationsParam(); + + /** + * Try to fetch the display field from DB. + */ + if ($cfgRelation['displaywork']) { + $disp_query = ' + SELECT `display_field` + FROM ' . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_info']) . ' + WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' + AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) + . '\''; + + $row = $GLOBALS['dbi']->fetchSingleRow( + $disp_query, 'ASSOC', $GLOBALS['controllink'] + ); + if (isset($row['display_field'])) { + return $row['display_field']; + } + } + + /** + * Emulating the display field for some information_schema tables. + */ + if ($db == 'information_schema') { + switch ($table) { + case 'CHARACTER_SETS': + return 'DESCRIPTION'; + case 'TABLES': + return 'TABLE_COMMENT'; + } + } + + /** + * Pick first char field + */ + $columns = $GLOBALS['dbi']->getColumnsFull($db, $table); + if ($columns) { + foreach ($columns as $column) { + if ($GLOBALS['PMA_Types']->getTypeClass($column['DATA_TYPE']) == 'CHAR') { + return $column['COLUMN_NAME']; + } + } + } + + /** + * No Luck... + */ + return false; + + } // end of the 'self::getDisplayField()' function + + /** + * Gets the comments for all columns of a table or the db itself + * + * @param string $db the name of the db to check for + * @param string $table the name of the table to check for + * + * @return array [column_name] = comment + * + * @access public + */ + public static function getComments($db, $table = '') + { + $comments = array(); + + if ($table != '') { + // MySQL native column comments + $columns = $GLOBALS['dbi']->getColumns($db, $table, null, true); + if ($columns) { + foreach ($columns as $column) { + if (! empty($column['Comment'])) { + $comments[$column['Field']] = $column['Comment']; + } + } + } + } else { + $comments[] = self::getDbComment($db); + } + + return $comments; + } // end of the 'self::getComments()' function + + /** + * Gets the comment for a db + * + * @param string $db the name of the db to check for + * + * @return string comment + * + * @access public + */ + public static function getDbComment($db) + { + $cfgRelation = self::getRelationsParam(); + $comment = ''; + + if ($cfgRelation['commwork']) { + // pmadb internal db comment + $com_qry = " + SELECT `comment` + FROM " . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['column_info']) + . " + WHERE db_name = '" . $GLOBALS['dbi']->escapeString($db) . "' + AND table_name = '' + AND column_name = '(db_comment)'"; + $com_rs = self::queryAsControlUser( + $com_qry, true, DatabaseInterface::QUERY_STORE + ); + + if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { + $row = $GLOBALS['dbi']->fetchAssoc($com_rs); + $comment = $row['comment']; + } + $GLOBALS['dbi']->freeResult($com_rs); + } + + return $comment; + } // end of the 'self::getDbComment()' function + + /** + * Gets the comment for a db + * + * @access public + * + * @return string comment + */ + public static function getDbComments() + { + $cfgRelation = self::getRelationsParam(); + $comments = array(); + + if ($cfgRelation['commwork']) { + // pmadb internal db comment + $com_qry = " + SELECT `db_name`, `comment` + FROM " . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['column_info']) + . " + WHERE `column_name` = '(db_comment)'"; + $com_rs = self::queryAsControlUser( + $com_qry, true, DatabaseInterface::QUERY_STORE + ); + + if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { + while ($row = $GLOBALS['dbi']->fetchAssoc($com_rs)) { + $comments[$row['db_name']] = $row['comment']; + } + } + $GLOBALS['dbi']->freeResult($com_rs); + } + + return $comments; + } // end of the 'self::getDbComments()' function + + /** + * Set a database comment to a certain value. + * + * @param string $db the name of the db + * @param string $comment the value of the column + * + * @return boolean true, if comment-query was made. + * + * @access public + */ + public static function setDbComment($db, $comment = '') + { + $cfgRelation = self::getRelationsParam(); + + if (! $cfgRelation['commwork']) { + return false; + } + + if (strlen($comment) > 0) { + $upd_query = 'INSERT INTO ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['column_info']) + . ' (`db_name`, `table_name`, `column_name`, `comment`)' + . ' VALUES (\'' + . $GLOBALS['dbi']->escapeString($db) + . "', '', '(db_comment)', '" + . $GLOBALS['dbi']->escapeString($comment) + . "') " + . ' ON DUPLICATE KEY UPDATE ' + . "`comment` = '" . $GLOBALS['dbi']->escapeString($comment) . "'"; + } else { + $upd_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['column_info']) + . ' WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) + . '\' + AND `table_name` = \'\' + AND `column_name` = \'(db_comment)\''; + } + + if (isset($upd_query)) { + return self::queryAsControlUser($upd_query); + } + + return false; + } // end of 'self::setDbComment()' function + + /** + * Set a SQL history entry + * + * @param string $db the name of the db + * @param string $table the name of the table + * @param string $username the username + * @param string $sqlquery the sql query + * + * @return void + * + * @access public + */ + public static function setHistory($db, $table, $username, $sqlquery) + { + $maxCharactersInDisplayedSQL = $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']; + // Prevent to run this automatically on Footer class destroying in testsuite + if (defined('TESTSUITE') + || mb_strlen($sqlquery) > $maxCharactersInDisplayedSQL + ) { + return; + } + + $cfgRelation = self::getRelationsParam(); + + if (! isset($_SESSION['sql_history'])) { + $_SESSION['sql_history'] = array(); + } + + $_SESSION['sql_history'][] = array( + 'db' => $db, + 'table' => $table, + 'sqlquery' => $sqlquery, + ); + + if (count($_SESSION['sql_history']) > $GLOBALS['cfg']['QueryHistoryMax']) { + // history should not exceed a maximum count + array_shift($_SESSION['sql_history']); + } + + if (! $cfgRelation['historywork'] || ! $GLOBALS['cfg']['QueryHistoryDB']) { + return; + } + + self::queryAsControlUser( + 'INSERT INTO ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['history']) . ' + (`username`, + `db`, + `table`, + `timevalue`, + `sqlquery`) + VALUES + (\'' . $GLOBALS['dbi']->escapeString($username) . '\', + \'' . $GLOBALS['dbi']->escapeString($db) . '\', + \'' . $GLOBALS['dbi']->escapeString($table) . '\', + NOW(), + \'' . $GLOBALS['dbi']->escapeString($sqlquery) . '\')' + ); + + self::purgeHistory($username); + + } // end of 'self::setHistory()' function + + /** + * Gets a SQL history entry + * + * @param string $username the username + * + * @return array list of history items + * + * @access public + */ + public static function getHistory($username) + { + $cfgRelation = self::getRelationsParam(); + + if (! $cfgRelation['historywork']) { + return false; + } + + /** + * if db-based history is disabled but there exists a session-based + * history, use it + */ + if (! $GLOBALS['cfg']['QueryHistoryDB']) { + if (isset($_SESSION['sql_history'])) { + return array_reverse($_SESSION['sql_history']); + } + return false; + } + + $hist_query = ' + SELECT `db`, + `table`, + `sqlquery`, + `timevalue` + FROM ' . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['history']) . ' + WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) . '\' + ORDER BY `id` DESC'; + + return $GLOBALS['dbi']->fetchResult( + $hist_query, null, null, $GLOBALS['controllink'] + ); + } // end of 'self::getHistory()' function + + /** + * purges SQL history + * + * deletes entries that exceeds $cfg['QueryHistoryMax'], oldest first, for the + * given user + * + * @param string $username the username + * + * @return void + * + * @access public + */ + public static function purgeHistory($username) + { + $cfgRelation = self::getRelationsParam(); + if (! $GLOBALS['cfg']['QueryHistoryDB'] || ! $cfgRelation['historywork']) { + return; + } + + if (! $cfgRelation['historywork']) { + return; + } + + $search_query = ' + SELECT `timevalue` + FROM ' . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['history']) . ' + WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) . '\' + ORDER BY `timevalue` DESC + LIMIT ' . $GLOBALS['cfg']['QueryHistoryMax'] . ', 1'; + + if ($max_time = $GLOBALS['dbi']->fetchValue( + $search_query, 0, 0, $GLOBALS['controllink'] + )) { + self::queryAsControlUser( + 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['history']) . ' + WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) + . '\' + AND `timevalue` <= \'' . $max_time . '\'' + ); + } + } // end of 'self::purgeHistory()' function + + /** + * Prepares the dropdown for one mode + * + * @param array $foreign the keys and values for foreigns + * @param string $data the current data of the dropdown + * @param string $mode the needed mode + * + * @return array the <option value=""><option>s + * + * @access protected + */ + public static function buildForeignDropdown($foreign, $data, $mode) + { + $reloptions = array(); + + // id-only is a special mode used when no foreign display column + // is available + if ($mode == 'id-content' || $mode == 'id-only') { + // sort for id-content + if ($GLOBALS['cfg']['NaturalOrder']) { + uksort($foreign, 'strnatcasecmp'); + } else { + ksort($foreign); + } + } elseif ($mode == 'content-id') { + // sort for content-id + if ($GLOBALS['cfg']['NaturalOrder']) { + natcasesort($foreign); + } else { + asort($foreign); + } + } + + foreach ($foreign as $key => $value) { + if (mb_strlen($value) <= $GLOBALS['cfg']['LimitChars'] + ) { + $vtitle = ''; + $value = htmlspecialchars($value); + } else { + $vtitle = htmlspecialchars($value); + $value = htmlspecialchars( + mb_substr( + $value, 0, $GLOBALS['cfg']['LimitChars'] + ) . '...' + ); + } + + $reloption = '<option value="' . htmlspecialchars($key) . '"'; + if ($vtitle != '') { + $reloption .= ' title="' . $vtitle . '"'; + } + + if ((string) $key == (string) $data) { + $reloption .= ' selected="selected"'; + } + + if ($mode == 'content-id') { + $reloptions[] = $reloption . '>' + . $value . ' - ' . htmlspecialchars($key) . '</option>'; + } elseif ($mode == 'id-content') { + $reloptions[] = $reloption . '>' + . htmlspecialchars($key) . ' - ' . $value . '</option>'; + } elseif ($mode == 'id-only') { + $reloptions[] = $reloption . '>' + . htmlspecialchars($key) . '</option>'; + } + } // end foreach + + return $reloptions; + } // end of 'self::buildForeignDropdown' function + + /** + * Outputs dropdown with values of foreign fields + * + * @param array $disp_row array of the displayed row + * @param string $foreign_field the foreign field + * @param string $foreign_display the foreign field to display + * @param string $data the current data of the dropdown (field in row) + * @param int $max maximum number of items in the dropdown + * + * @return string the <option value=""><option>s + * + * @access public + */ + public static function foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, + $max = null + ) { + if (null === $max) { + $max = $GLOBALS['cfg']['ForeignKeyMaxLimit']; + } + + $foreign = array(); + + // collect the data + foreach ($disp_row as $relrow) { + $key = $relrow[$foreign_field]; + + // if the display field has been defined for this foreign table + if ($foreign_display) { + $value = $relrow[$foreign_display]; + } else { + $value = ''; + } // end if ($foreign_display) + + $foreign[$key] = $value; + } // end foreach + + // put the dropdown sections in correct order + $top = array(); + $bottom = array(); + if ($foreign_display) { + if (Core::isValid($GLOBALS['cfg']['ForeignKeyDropdownOrder'], 'array')) { + if (Core::isValid($GLOBALS['cfg']['ForeignKeyDropdownOrder'][0])) { + $top = self::buildForeignDropdown( + $foreign, + $data, + $GLOBALS['cfg']['ForeignKeyDropdownOrder'][0] + ); + } + if (Core::isValid($GLOBALS['cfg']['ForeignKeyDropdownOrder'][1])) { + $bottom = self::buildForeignDropdown( + $foreign, + $data, + $GLOBALS['cfg']['ForeignKeyDropdownOrder'][1] + ); + } + } else { + $top = self::buildForeignDropdown($foreign, $data, 'id-content'); + $bottom = self::buildForeignDropdown($foreign, $data, 'content-id'); + } + } else { + $top = self::buildForeignDropdown($foreign, $data, 'id-only'); + } + + // beginning of dropdown + $ret = '<option value=""> </option>'; + $top_count = count($top); + if ($max == -1 || $top_count < $max) { + $ret .= implode('', $top); + if ($foreign_display && $top_count > 0) { + // this empty option is to visually mark the beginning of the + // second series of values (bottom) + $ret .= '<option value=""> </option>'; + } + } + if ($foreign_display) { + $ret .= implode('', $bottom); + } + + return $ret; + } // end of 'self::foreignDropdown()' function + + /** + * Gets foreign keys in preparation for a drop-down selector + * + * @param array|boolean $foreigners array of the foreign keys + * @param string $field the foreign field name + * @param bool $override_total whether to override the total + * @param string $foreign_filter a possible filter + * @param string $foreign_limit a possible LIMIT clause + * @param bool $get_total optional, whether to get total num of rows + * in $foreignData['the_total;] + * (has an effect of performance) + * + * @return array data about the foreign keys + * + * @access public + */ + public static function getForeignData( + $foreigners, $field, $override_total, + $foreign_filter, $foreign_limit, $get_total=false + ) { + // we always show the foreign field in the drop-down; if a display + // field is defined, we show it besides the foreign field + $foreign_link = false; + do { + if (! $foreigners) { + break; + } + $foreigner = self::searchColumnInForeigners($foreigners, $field); + if ($foreigner != false) { + $foreign_db = $foreigner['foreign_db']; + $foreign_table = $foreigner['foreign_table']; + $foreign_field = $foreigner['foreign_field']; + } else { + break; + } + + // Count number of rows in the foreign table. Currently we do + // not use a drop-down if more than ForeignKeyMaxLimit rows in the + // foreign table, + // for speed reasons and because we need a better interface for this. + // + // We could also do the SELECT anyway, with a LIMIT, and ensure that + // the current value of the field is one of the choices. + + // Check if table has more rows than specified by + // $GLOBALS['cfg']['ForeignKeyMaxLimit'] + $moreThanLimit = $GLOBALS['dbi']->getTable($foreign_db, $foreign_table) + ->checkIfMinRecordsExist($GLOBALS['cfg']['ForeignKeyMaxLimit']); + + if ($override_total == true + || !$moreThanLimit + ) { + // foreign_display can be false if no display field defined: + $foreign_display = self::getDisplayField($foreign_db, $foreign_table); + + $f_query_main = 'SELECT ' . Util::backquote($foreign_field) + . ( + ($foreign_display == false) + ? '' + : ', ' . Util::backquote($foreign_display) + ); + $f_query_from = ' FROM ' . Util::backquote($foreign_db) + . '.' . Util::backquote($foreign_table); + $f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' + . Util::backquote($foreign_field) + . ' LIKE "%' . $GLOBALS['dbi']->escapeString($foreign_filter) . '%"' + . ( + ($foreign_display == false) + ? '' + : ' OR ' . Util::backquote($foreign_display) + . ' LIKE "%' . $GLOBALS['dbi']->escapeString($foreign_filter) + . '%"' + ); + $f_query_order = ($foreign_display == false) ? '' :' ORDER BY ' + . Util::backquote($foreign_table) . '.' + . Util::backquote($foreign_display); + + $f_query_limit = ! empty($foreign_limit) ? ($foreign_limit) : ''; + + if (!empty($foreign_filter)) { + $the_total = $GLOBALS['dbi']->fetchValue( + 'SELECT COUNT(*)' . $f_query_from . $f_query_filter + ); + if ($the_total === false) { + $the_total = 0; + } + } + + $disp = $GLOBALS['dbi']->tryQuery( + $f_query_main . $f_query_from . $f_query_filter + . $f_query_order . $f_query_limit + ); + if ($disp && $GLOBALS['dbi']->numRows($disp) > 0) { + // If a resultset has been created, pre-cache it in the $disp_row + // array. This helps us from not needing to use mysql_data_seek by + // accessing a pre-cached PHP array. Usually those resultsets are + // not that big, so a performance hit should not be expected. + $disp_row = array(); + while ($single_disp_row = @$GLOBALS['dbi']->fetchAssoc($disp)) { + $disp_row[] = $single_disp_row; + } + @$GLOBALS['dbi']->freeResult($disp); + } else { + // Either no data in the foreign table or + // user does not have select permission to foreign table/field + // Show an input field with a 'Browse foreign values' link + $disp_row = null; + $foreign_link = true; + } + } else { + $disp_row = null; + $foreign_link = true; + } + } while (false); + + if ($get_total) { + $the_total = $GLOBALS['dbi']->getTable($foreign_db, $foreign_table) + ->countRecords(true); + } + + $foreignData = array(); + $foreignData['foreign_link'] = $foreign_link; + $foreignData['the_total'] = isset($the_total) ? $the_total : null; + $foreignData['foreign_display'] = ( + isset($foreign_display) ? $foreign_display : null + ); + $foreignData['disp_row'] = isset($disp_row) ? $disp_row : null; + $foreignData['foreign_field'] = isset($foreign_field) ? $foreign_field : null; + + return $foreignData; + } // end of 'self::getForeignData()' function + + /** + * Rename a field in relation tables + * + * usually called after a column in a table was renamed + * + * @param string $db database name + * @param string $table table name + * @param string $field old field name + * @param string $new_name new field name + * + * @return void + */ + public static function renameField($db, $table, $field, $new_name) + { + $cfgRelation = self::getRelationsParam(); + + if ($cfgRelation['displaywork']) { + $table_query = 'UPDATE ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['table_info']) + . ' SET display_field = \'' . $GLOBALS['dbi']->escapeString( + $new_name + ) . '\'' + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) + . '\'' + . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND display_field = \'' . $GLOBALS['dbi']->escapeString($field) + . '\''; + self::queryAsControlUser($table_query); + } + + if ($cfgRelation['relwork']) { + $table_query = 'UPDATE ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['relation']) + . ' SET master_field = \'' . $GLOBALS['dbi']->escapeString( + $new_name + ) . '\'' + . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) + . '\'' + . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND master_field = \'' . $GLOBALS['dbi']->escapeString($field) + . '\''; + self::queryAsControlUser($table_query); + + $table_query = 'UPDATE ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['relation']) + . ' SET foreign_field = \'' . $GLOBALS['dbi']->escapeString( + $new_name + ) . '\'' + . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) + . '\'' + . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND foreign_field = \'' . $GLOBALS['dbi']->escapeString($field) + . '\''; + self::queryAsControlUser($table_query); + + } // end if relwork + } + + + /** + * Performs SQL query used for renaming table. + * + * @param string $table Relation table to use + * @param string $source_db Source database name + * @param string $target_db Target database name + * @param string $source_table Source table name + * @param string $target_table Target table name + * @param string $db_field Name of database field + * @param string $table_field Name of table field + * + * @return void + */ + public static function renameSingleTable($table, + $source_db, $target_db, + $source_table, $target_table, + $db_field, $table_field + ) { + $query = 'UPDATE ' + . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' + . Util::backquote($GLOBALS['cfgRelation'][$table]) + . ' SET ' + . $db_field . ' = \'' . $GLOBALS['dbi']->escapeString($target_db) + . '\', ' + . $table_field . ' = \'' . $GLOBALS['dbi']->escapeString($target_table) + . '\'' + . ' WHERE ' + . $db_field . ' = \'' . $GLOBALS['dbi']->escapeString($source_db) . '\'' + . ' AND ' + . $table_field . ' = \'' . $GLOBALS['dbi']->escapeString($source_table) + . '\''; + self::queryAsControlUser($query); + } + + + /** + * Rename a table in relation tables + * + * usually called after table has been moved + * + * @param string $source_db Source database name + * @param string $target_db Target database name + * @param string $source_table Source table name + * @param string $target_table Target table name + * + * @return void + */ + public static function renameTable($source_db, $target_db, $source_table, $target_table) + { + // Move old entries from PMA-DBs to new table + if ($GLOBALS['cfgRelation']['commwork']) { + self::renameSingleTable( + 'column_info', + $source_db, $target_db, + $source_table, $target_table, + 'db_name', 'table_name' + ); + } + + // updating bookmarks is not possible since only a single table is + // moved, and not the whole DB. + + if ($GLOBALS['cfgRelation']['displaywork']) { + self::renameSingleTable( + 'table_info', + $source_db, $target_db, + $source_table, $target_table, + 'db_name', 'table_name' + ); + } + + if ($GLOBALS['cfgRelation']['relwork']) { + self::renameSingleTable( + 'relation', + $source_db, $target_db, + $source_table, $target_table, + 'foreign_db', 'foreign_table' + ); + + self::renameSingleTable( + 'relation', + $source_db, $target_db, + $source_table, $target_table, + 'master_db', 'master_table' + ); + } + + if ($GLOBALS['cfgRelation']['pdfwork']) { + if ($source_db == $target_db) { + // rename within the database can be handled + self::renameSingleTable( + 'table_coords', + $source_db, $target_db, + $source_table, $target_table, + 'db_name', 'table_name' + ); + } else { + // if the table is moved out of the database we can no loger keep the + // record for table coordinate + $remove_query = "DELETE FROM " + . Util::backquote($GLOBALS['cfgRelation']['db']) . "." + . Util::backquote($GLOBALS['cfgRelation']['table_coords']) + . " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($source_db) . "'" + . " AND table_name = '" . $GLOBALS['dbi']->escapeString($source_table) + . "'"; + self::queryAsControlUser($remove_query); + } + } + + if ($GLOBALS['cfgRelation']['uiprefswork']) { + self::renameSingleTable( + 'table_uiprefs', + $source_db, $target_db, + $source_table, $target_table, + 'db_name', 'table_name' + ); + } + + if ($GLOBALS['cfgRelation']['navwork']) { + // update hidden items inside table + self::renameSingleTable( + 'navigationhiding', + $source_db, $target_db, + $source_table, $target_table, + 'db_name', 'table_name' + ); + + // update data for hidden table + $query = "UPDATE " + . Util::backquote($GLOBALS['cfgRelation']['db']) . "." + . Util::backquote( + $GLOBALS['cfgRelation']['navigationhiding'] + ) + . " SET db_name = '" . $GLOBALS['dbi']->escapeString($target_db) + . "'," + . " item_name = '" . $GLOBALS['dbi']->escapeString($target_table) + . "'" + . " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($source_db) + . "'" + . " AND item_name = '" . $GLOBALS['dbi']->escapeString($source_table) + . "'" + . " AND item_type = 'table'"; + self::queryAsControlUser($query); + } + } + + /** + * Create a PDF page + * + * @param string $newpage name of the new PDF page + * @param array $cfgRelation Relation configuration + * @param string $db database name + * + * @return int $pdf_page_number + */ + public static function createPage($newpage, $cfgRelation, $db) + { + if (! isset($newpage) || $newpage == '') { + $newpage = __('no description'); + } + $ins_query = 'INSERT INTO ' + . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' + . Util::backquote($cfgRelation['pdf_pages']) + . ' (db_name, page_descr)' + . ' VALUES (\'' + . $GLOBALS['dbi']->escapeString($db) . '\', \'' + . $GLOBALS['dbi']->escapeString($newpage) . '\')'; + self::queryAsControlUser($ins_query, false); + + return $GLOBALS['dbi']->insertId( + isset($GLOBALS['controllink']) ? $GLOBALS['controllink'] : '' + ); + } + + /** + * Get child table references for a table column. + * This works only if 'DisableIS' is false. An empty array is returned otherwise. + * + * @param string $db name of master table db. + * @param string $table name of master table. + * @param string $column name of master table column. + * + * @return array $child_references + */ + public static function getChildReferences($db, $table, $column = '') + { + $child_references = array(); + if (! $GLOBALS['cfg']['Server']['DisableIS']) { + $rel_query = "SELECT `column_name`, `table_name`," + . " `table_schema`, `referenced_column_name`" + . " FROM `information_schema`.`key_column_usage`" + . " WHERE `referenced_table_name` = '" + . $GLOBALS['dbi']->escapeString($table) . "'" + . " AND `referenced_table_schema` = '" + . $GLOBALS['dbi']->escapeString($db) . "'"; + if ($column) { + $rel_query .= " AND `referenced_column_name` = '" + . $GLOBALS['dbi']->escapeString($column) . "'"; + } + + $child_references = $GLOBALS['dbi']->fetchResult( + $rel_query, array('referenced_column_name', null) + ); + } + return $child_references; + } + + /** + * Check child table references and foreign key for a table column. + * + * @param string $db name of master table db. + * @param string $table name of master table. + * @param string $column name of master table column. + * @param array $foreigners_full foreiners array for the whole table. + * @param array $child_references_full child references for the whole table. + * + * @return array $column_status telling about references if foreign key. + */ + public static function checkChildForeignReferences( + $db, $table, $column, $foreigners_full = null, $child_references_full = null + ) { + $column_status = array(); + $column_status['isEditable'] = false; + $column_status['isReferenced'] = false; + $column_status['isForeignKey'] = false; + $column_status['references'] = array(); + + $foreigners = array(); + if ($foreigners_full !== null) { + if (isset($foreigners_full[$column])) { + $foreigners[$column] = $foreigners_full[$column]; + } + if (isset($foreigners_full['foreign_keys_data'])) { + $foreigners['foreign_keys_data'] = $foreigners_full['foreign_keys_data']; + } + } else { + $foreigners = self::getForeigners($db, $table, $column, 'foreign'); + } + $foreigner = self::searchColumnInForeigners($foreigners, $column); + + $child_references = array(); + if ($child_references_full !== null) { + if (isset($child_references_full[$column])) { + $child_references = $child_references_full[$column]; + } + } else { + $child_references = self::getChildReferences($db, $table, $column); + } + + if (sizeof($child_references, 0) > 0 + || $foreigner + ) { + if (sizeof($child_references, 0) > 0) { + $column_status['isReferenced'] = true; + foreach ($child_references as $columns) { + array_push( + $column_status['references'], + Util::backquote($columns['table_schema']) + . '.' . Util::backquote($columns['table_name']) + ); + } + } + + if ($foreigner) { + $column_status['isForeignKey'] = true; + } + } else { + $column_status['isEditable'] = true; + } + + return $column_status; + } + + /** + * Search a table column in foreign data. + * + * @param array $foreigners Table Foreign data + * @param string $column Column name + * + * @return bool|array + */ + public static function searchColumnInForeigners($foreigners, $column) + { + if (isset($foreigners[$column])) { + return $foreigners[$column]; + } else { + $foreigner = array(); + foreach ($foreigners['foreign_keys_data'] as $one_key) { + $column_index = array_search($column, $one_key['index_list']); + if ($column_index !== false) { + $foreigner['foreign_field'] + = $one_key['ref_index_list'][$column_index]; + $foreigner['foreign_db'] = isset($one_key['ref_db_name']) + ? $one_key['ref_db_name'] + : $GLOBALS['db']; + $foreigner['foreign_table'] = $one_key['ref_table_name']; + $foreigner['constraint'] = $one_key['constraint']; + $foreigner['on_update'] = isset($one_key['on_update']) + ? $one_key['on_update'] + : 'RESTRICT'; + $foreigner['on_delete'] = isset($one_key['on_delete']) + ? $one_key['on_delete'] + : 'RESTRICT'; + + return $foreigner; + } + } + } + + return false; + } + + /** + * Returns default PMA table names and their create queries. + * + * @return array table name, create query + */ + public static function getDefaultPmaTableNames() + { + $pma_tables = array(); + $create_tables_file = file_get_contents( + SQL_DIR . 'create_tables.sql' + ); + + $queries = explode(';', $create_tables_file); + + foreach ($queries as $query) { + if (preg_match( + '/CREATE TABLE IF NOT EXISTS `(.*)` \(/', + $query, + $table + ) + ) { + $pma_tables[$table[1]] = $query . ';'; + } + } + + return $pma_tables; + } + + /** + * Create a table named phpmyadmin to be used as configuration storage + * + * @return bool + */ + public static function createPmaDatabase() + { + $GLOBALS['dbi']->tryQuery("CREATE DATABASE IF NOT EXISTS `phpmyadmin`"); + if ($error = $GLOBALS['dbi']->getError()) { + if ($GLOBALS['errno'] == 1044) { + $GLOBALS['message'] = __( + 'You do not have necessary privileges to create a database named' + . ' \'phpmyadmin\'. You may go to \'Operations\' tab of any' + . ' database to set up the phpMyAdmin configuration storage there.' + ); + } else { + $GLOBALS['message'] = $error; + } + return false; + } + return true; + } + + /** + * Creates PMA tables in the given db, updates if already exists. + * + * @param string $db database + * @param boolean $create whether to create tables if they don't exist. + * + * @return void + */ + public static function fixPmaTables($db, $create = true) + { + $tablesToFeatures = array( + 'pma__bookmark' => 'bookmarktable', + 'pma__relation' => 'relation', + 'pma__table_info' => 'table_info', + 'pma__table_coords' => 'table_coords', + 'pma__pdf_pages' => 'pdf_pages', + 'pma__column_info' => 'column_info', + 'pma__history' => 'history', + 'pma__recent' => 'recent', + 'pma__favorite' => 'favorite', + 'pma__table_uiprefs' => 'table_uiprefs', + 'pma__tracking' => 'tracking', + 'pma__userconfig' => 'userconfig', + 'pma__users' => 'users', + 'pma__usergroups' => 'usergroups', + 'pma__navigationhiding' => 'navigationhiding', + 'pma__savedsearches' => 'savedsearches', + 'pma__central_columns' => 'central_columns', + 'pma__designer_settings' => 'designer_settings', + 'pma__export_templates' => 'export_templates', + ); + + $existingTables = $GLOBALS['dbi']->getTables($db, $GLOBALS['controllink']); + + $createQueries = null; + $foundOne = false; + foreach ($tablesToFeatures as $table => $feature) { + if (! in_array($table, $existingTables)) { + if ($create) { + if ($createQueries == null) { // first create + $createQueries = self::getDefaultPmaTableNames(); + $GLOBALS['dbi']->selectDb($db); + } + $GLOBALS['dbi']->tryQuery($createQueries[$table]); + if ($error = $GLOBALS['dbi']->getError()) { + $GLOBALS['message'] = $error; + return; + } + $foundOne = true; + $GLOBALS['cfg']['Server'][$feature] = $table; + } + } else { + $foundOne = true; + $GLOBALS['cfg']['Server'][$feature] = $table; + } + } + + if (! $foundOne) { + return; + } + $GLOBALS['cfg']['Server']['pmadb'] = $db; + $_SESSION['relation'][$GLOBALS['server']] = self::checkRelationsParam(); + + $cfgRelation = self::getRelationsParam(); + if ($cfgRelation['recentwork'] || $cfgRelation['favoritework']) { + // Since configuration storage is updated, we need to + // re-initialize the favorite and recent tables stored in the + // session from the current configuration storage. + if ($cfgRelation['favoritework']) { + $fav_tables = RecentFavoriteTable::getInstance('favorite'); + $_SESSION['tmpval']['favorite_tables'][$GLOBALS['server']] + = $fav_tables->getFromDb(); + } + + if ($cfgRelation['recentwork']) { + $recent_tables = RecentFavoriteTable::getInstance('recent'); + $_SESSION['tmpval']['recent_tables'][$GLOBALS['server']] + = $recent_tables->getFromDb(); + } + + // Reload navi panel to update the recent/favorite lists. + $GLOBALS['reload'] = true; + } + } + + /** + * Get Html for PMA tables fixing anchor. + * + * @param boolean $allTables whether to create all tables + * @param boolean $createDb whether to create the pmadb also + * + * @return string Html + */ + public static function getHtmlFixPmaTables($allTables, $createDb = false) + { + $retval = ''; + + $url_query = Url::getCommon(array('db' => $GLOBALS['db'])); + if ($allTables) { + if ($createDb) { + $url_query .= '&goto=db_operations.php&create_pmadb=1'; + $message = Message::notice( + __( + '%sCreate%s a database named \'phpmyadmin\' and setup ' + . 'the phpMyAdmin configuration storage there.' + ) + ); + } else { + $url_query .= '&goto=db_operations.php&fixall_pmadb=1'; + $message = Message::notice( + __( + '%sCreate%s the phpMyAdmin configuration storage in the ' + . 'current database.' + ) + ); + } + } else { + $url_query .= '&goto=db_operations.php&fix_pmadb=1'; + $message = Message::notice( + __('%sCreate%s missing phpMyAdmin configuration storage tables.') + ); + } + $message->addParamHtml('<a href="./chk_rel.php' . $url_query . '">'); + $message->addParamHtml('</a>'); + + $retval .= $message->getDisplay(); + + return $retval; + } + + /** + * Gets the relations info and status, depending on the condition + * + * @param boolean $condition whether to look for foreigners or not + * @param string $db database name + * @param string $table table name + * + * @return array ($res_rel, $have_rel) + */ + public static function getRelationsAndStatus($condition, $db, $table) + { + if ($condition) { + // Find which tables are related with the current one and write it in + // an array + $res_rel = self::getForeigners($db, $table); + + if (count($res_rel) > 0) { + $have_rel = true; + } else { + $have_rel = false; + } + } else { + $have_rel = false; + $res_rel = array(); + } // end if + return(array($res_rel, $have_rel)); + } + + /** + * Verifies if all the pmadb tables are defined + * + * @return boolean + */ + public static function arePmadbTablesDefined() + { + if (empty($GLOBALS['cfg']['Server']['bookmarktable']) + || empty($GLOBALS['cfg']['Server']['relation']) + || empty($GLOBALS['cfg']['Server']['table_info']) + || empty($GLOBALS['cfg']['Server']['table_coords']) + || empty($GLOBALS['cfg']['Server']['column_info']) + || empty($GLOBALS['cfg']['Server']['pdf_pages']) + || empty($GLOBALS['cfg']['Server']['history']) + || empty($GLOBALS['cfg']['Server']['recent']) + || empty($GLOBALS['cfg']['Server']['favorite']) + || empty($GLOBALS['cfg']['Server']['table_uiprefs']) + || empty($GLOBALS['cfg']['Server']['tracking']) + || empty($GLOBALS['cfg']['Server']['userconfig']) + || empty($GLOBALS['cfg']['Server']['users']) + || empty($GLOBALS['cfg']['Server']['usergroups']) + || empty($GLOBALS['cfg']['Server']['navigationhiding']) + || empty($GLOBALS['cfg']['Server']['savedsearches']) + || empty($GLOBALS['cfg']['Server']['central_columns']) + || empty($GLOBALS['cfg']['Server']['designer_settings']) + || empty($GLOBALS['cfg']['Server']['export_templates']) + ) { + return false; + } else { + return true; + } + } +} diff --git a/libraries/classes/SavedSearches.php b/libraries/classes/SavedSearches.php index 23ed47a44b..6d61d18705 100644 --- a/libraries/classes/SavedSearches.php +++ b/libraries/classes/SavedSearches.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Util; @@ -312,7 +313,7 @@ class SavedSearches . "'" . $GLOBALS['dbi']->escapeString(json_encode($this->getCriterias())) . "')"; - $result = (bool)PMA_queryAsControlUser($sqlQuery); + $result = (bool)Relation::queryAsControlUser($sqlQuery); if (!$result) { return false; } @@ -346,7 +347,7 @@ class SavedSearches . "`search_data` = '" . $GLOBALS['dbi']->escapeString(json_encode($this->getCriterias())) . "' " . "WHERE id = " . $this->getId(); - return (bool)PMA_queryAsControlUser($sqlQuery); + return (bool)Relation::queryAsControlUser($sqlQuery); } /** @@ -374,7 +375,7 @@ class SavedSearches $sqlQuery = "DELETE FROM " . $savedSearchesTbl . "WHERE id = '" . $GLOBALS['dbi']->escapeString($this->getId()) . "'"; - return (bool)PMA_queryAsControlUser($sqlQuery); + return (bool)Relation::queryAsControlUser($sqlQuery); } /** @@ -402,7 +403,7 @@ class SavedSearches . "FROM " . $savedSearchesTbl . " " . "WHERE id = '" . $GLOBALS['dbi']->escapeString($this->getId()) . "' "; - $resList = PMA_queryAsControlUser($sqlQuery); + $resList = Relation::queryAsControlUser($sqlQuery); if (false === ($oneResult = $GLOBALS['dbi']->fetchArray($resList))) { $message = Message::error(__('Error while loading the search.')); @@ -449,7 +450,7 @@ class SavedSearches $sqlQuery .= "order by search_name ASC "; - $resList = PMA_queryAsControlUser($sqlQuery); + $resList = Relation::queryAsControlUser($sqlQuery); $list = array(); while ($oneResult = $GLOBALS['dbi']->fetchArray($resList)) { diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 9a4e3ee820..7b4a8137d8 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -10,10 +10,11 @@ namespace PhpMyAdmin\Server; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Template; -use PhpMyAdmin\Util; use PhpMyAdmin\Url; +use PhpMyAdmin\Util; /** * Privileges class @@ -523,7 +524,7 @@ class Privileges */ public static function getHtmlToChooseUserGroup($username) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $groupTable = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['usergroups']); $userTable = Util::backquote($cfgRelation['db']) @@ -540,7 +541,7 @@ class Privileges $allUserGroups = array('' => ''); $sql_query = "SELECT DISTINCT `usergroup` FROM " . $groupTable; - $result = PMA_queryAsControlUser($sql_query, false); + $result = Relation::queryAsControlUser($sql_query, false); if ($result) { while ($row = $GLOBALS['dbi']->fetchRow($result)) { $allUserGroups[$row[0]] = $row[0]; @@ -570,7 +571,7 @@ class Privileges */ public static function setUserGroup($username, $userGroup) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (empty($cfgRelation['db']) || empty($cfgRelation['users']) || empty($cfgRelation['usergroups'])) { return; } @@ -599,7 +600,7 @@ class Privileges } } if (isset($upd_query)) { - PMA_queryAsControlUser($upd_query); + Relation::queryAsControlUser($upd_query); } } @@ -2841,7 +2842,7 @@ class Privileges */ public static function getUserGroupCount() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $user_group_table = Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['usergroups']); $sql_query = 'SELECT COUNT(*) FROM ' . $user_group_table; @@ -2861,7 +2862,7 @@ class Privileges */ public static function getUserGroupForUser($username) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (empty($cfgRelation['db']) || empty($cfgRelation['users']) @@ -2952,7 +2953,7 @@ class Privileges // if $cfg['Servers'][$i]['users'] and $cfg['Servers'][$i]['usergroups'] are // enabled - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (!empty($cfgRelation['users']) && !empty($cfgRelation['usergroups'])) { $new_user_string .= '<td class="usrGroup"></td>'; } @@ -3560,12 +3561,12 @@ class Privileges */ public static function getHtmlTableBodyForUserRights($db_rights) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['menuswork']) { $users_table = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['users']); $sql_query = 'SELECT * FROM ' . $users_table; - $result = PMA_queryAsControlUser($sql_query, false); + $result = Relation::queryAsControlUser($sql_query, false); $group_assignment = array(); if ($result) { while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php index 88a1cd0ed5..1050e10a6d 100644 --- a/libraries/classes/Sql.php +++ b/libraries/classes/Sql.php @@ -14,6 +14,7 @@ use PhpMyAdmin\DisplayResults; use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Operations; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\SqlParser\Statements\AlterStatement; use PhpMyAdmin\SqlParser\Statements\DropStatement; @@ -192,9 +193,9 @@ class Sql */ public static function getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_value) { - $foreigners = PMA_getForeigners($db, $table, $column); + $foreigners = Relation::getForeigners($db, $table, $column); - $foreignData = PMA_getForeignData($foreigners, $column, false, '', ''); + $foreignData = Relation::getForeignData($foreigners, $column, false, '', ''); if ($foreignData['disp_row'] == null) { //Handle the case when number of values @@ -214,7 +215,7 @@ class Sql . __('Browse foreign values') . '</a>'; } else { - $dropdown = PMA_foreignDropdown( + $dropdown = Relation::foreignDropdown( $foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], diff --git a/libraries/classes/SystemDatabase.php b/libraries/classes/SystemDatabase.php index caf8919263..7d78fae457 100644 --- a/libraries/classes/SystemDatabase.php +++ b/libraries/classes/SystemDatabase.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; use PhpMyAdmin\Util; require_once 'libraries/database_interface.inc.php'; @@ -45,7 +46,7 @@ class SystemDatabase */ public function getExistingTransformationData($db) { - $cfgRelation = \PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); // Get the existing transformation details of the same database // from pma__column_info table @@ -72,7 +73,7 @@ class SystemDatabase function getNewTransformationDataSql( $pma_transformation_data, $column_map, $view_name, $db ) { - $cfgRelation = \PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); // Need to store new transformation details for VIEW $new_transformations_sql = sprintf( diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index c1e869df6a..a67337a69e 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -11,6 +11,7 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\Export\ExportSql; +use PhpMyAdmin\Relation; use PhpMyAdmin\SqlParser\Components\Expression; use PhpMyAdmin\SqlParser\Components\OptionsArray; use PhpMyAdmin\SqlParser\Context; @@ -799,7 +800,7 @@ class Table // must use DatabaseInterface::QUERY_STORE here, since we execute // another query inside the loop - $table_copy_rs = PMA_queryAsControlUser( + $table_copy_rs = Relation::queryAsControlUser( $table_copy_query, true, DatabaseInterface::QUERY_STORE ); @@ -819,7 +820,7 @@ class Table . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')'; - PMA_queryAsControlUser($new_table_query); + Relation::queryAsControlUser($new_table_query); $last_id = $GLOBALS['dbi']->insertId(); } // end while @@ -1160,7 +1161,7 @@ class Table } } - PMA_getRelationsParam(); + Relation::getRelationsParam(); // Drops old table if the user has requested to move it if ($move) { @@ -1179,7 +1180,7 @@ class Table $GLOBALS['dbi']->query($sql_drop_query); // Renable table in configuration storage - PMA_REL_renameTable( + Relation::renameTable( $source_db, $target_db, $source_table, $target_table ); @@ -1197,7 +1198,7 @@ class Table if ($GLOBALS['cfgRelation']['commwork']) { // Get all comments and MIME-Types for current table - $comments_copy_rs = PMA_queryAsControlUser( + $comments_copy_rs = Relation::queryAsControlUser( 'SELECT column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' @@ -1245,7 +1246,7 @@ class Table . '\'' : '') . ')'; - PMA_queryAsControlUser($new_comment_query); + Relation::queryAsControlUser($new_comment_query); } // end while $GLOBALS['dbi']->freeResult($comments_copy_rs); unset($comments_copy_rs); @@ -1484,7 +1485,7 @@ class Table $this->_db_name = $new_db; // Renable table in configuration storage - PMA_REL_renameTable( + Relation::renameTable( $old_db, $new_db, $old_name, $new_name ); @@ -1679,7 +1680,7 @@ class Table */ protected function getUiPrefsFromDb() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $pma_table = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['table_uiprefs']); @@ -1689,7 +1690,7 @@ class Table . " AND `db_name` = '" . $GLOBALS['dbi']->escapeString($this->_db_name) . "'" . " AND `table_name` = '" . $GLOBALS['dbi']->escapeString($this->_name) . "'"; - $row = $this->_dbi->fetchArray(PMA_queryAsControlUser($sql_query)); + $row = $this->_dbi->fetchArray(Relation::queryAsControlUser($sql_query)); if (isset($row[0])) { return json_decode($row[0], true); } else { @@ -1704,7 +1705,7 @@ class Table */ protected function saveUiPrefsToDb() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $pma_table = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['table_uiprefs']); @@ -1779,7 +1780,7 @@ class Table */ protected function loadUiPrefs() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $server_id = $GLOBALS['server']; // set session variable if it's still undefined @@ -1917,7 +1918,7 @@ class Table $this->uiprefs[$property] = $value; // check if pmadb is set - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['uiprefswork']) { return $this->saveUiprefsToDb(); } @@ -1940,7 +1941,7 @@ class Table unset($this->uiprefs[$property]); // check if pmadb is set - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['uiprefswork']) { return $this->saveUiprefsToDb(); } diff --git a/libraries/classes/Tracker.php b/libraries/classes/Tracker.php index 03d5f36fce..ac9c999f79 100644 --- a/libraries/classes/Tracker.php +++ b/libraries/classes/Tracker.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Plugins\Export\ExportSql; +use PhpMyAdmin\Relation; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statements\AlterStatement; use PhpMyAdmin\SqlParser\Statements\CreateStatement; @@ -64,10 +65,10 @@ class Tracker return false; } /* We need to avoid attempt to track any queries - * from PMA_getRelationsParam + * from Relation::getRelationsParam */ self::$enabled = false; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); /* Restore original state */ self::$enabled = true; if (! $cfgRelation['trackingwork']) { @@ -131,10 +132,10 @@ class Tracker return self::$_tracking_cache[$dbname][$tablename]; } /* We need to avoid attempt to track any queries - * from PMA_getRelationsParam + * from Relation::getRelationsParam */ self::$enabled = false; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); /* Restore original state */ self::$enabled = true; if (! $cfgRelation['trackingwork']) { @@ -271,7 +272,7 @@ class Tracker '" . $GLOBALS['dbi']->escapeString($tracking_set) . "' )"; - $result = PMA_queryAsControlUser($sql_query); + $result = Relation::queryAsControlUser($sql_query); if ($result) { // Deactivate previous version @@ -305,7 +306,7 @@ class Tracker $sql_query .= " AND `version` = '" . $GLOBALS['dbi']->escapeString($version) . "'"; } - $result = PMA_queryAsControlUser($sql_query); + $result = Relation::queryAsControlUser($sql_query); return $result; } @@ -367,7 +368,7 @@ class Tracker '" . $GLOBALS['dbi']->escapeString($tracking_set) . "' )"; - $result = PMA_queryAsControlUser($sql_query); + $result = Relation::queryAsControlUser($sql_query); return $result; } @@ -396,7 +397,7 @@ class Tracker " AND `table_name` = '" . $GLOBALS['dbi']->escapeString($tablename) . "' " . " AND `version` = '" . $GLOBALS['dbi']->escapeString($version) . "' "; - $result = PMA_queryAsControlUser($sql_query); + $result = Relation::queryAsControlUser($sql_query); return $result; } @@ -442,7 +443,7 @@ class Tracker " AND `table_name` = '" . $GLOBALS['dbi']->escapeString($tablename) . "' " . " AND `version` = '" . $GLOBALS['dbi']->escapeString($version) . "' "; - $result = PMA_queryAsControlUser($sql_query); + $result = Relation::queryAsControlUser($sql_query); return (boolean) $result; } @@ -503,7 +504,7 @@ class Tracker $sql_query .= " AND FIND_IN_SET('" . $statement . "',tracking) > 0" ; } - $row = $GLOBALS['dbi']->fetchArray(PMA_queryAsControlUser($sql_query)); + $row = $GLOBALS['dbi']->fetchArray(Relation::queryAsControlUser($sql_query)); return isset($row[0]) ? $row[0] : -1; @@ -533,7 +534,7 @@ class Tracker $sql_query .= " AND `version` = '" . $GLOBALS['dbi']->escapeString($version) . "' " . " ORDER BY `version` DESC LIMIT 1"; - $mixed = $GLOBALS['dbi']->fetchAssoc(PMA_queryAsControlUser($sql_query)); + $mixed = $GLOBALS['dbi']->fetchAssoc(Relation::queryAsControlUser($sql_query)); // Parse log $log_schema_entries = explode('# log ', $mixed['schema_sql']); @@ -878,7 +879,7 @@ class Tracker . $GLOBALS['dbi']->escapeString($result['tablename']) . "' " . " AND `version` = '" . $GLOBALS['dbi']->escapeString($version) . "' "; - PMA_queryAsControlUser($sql_query); + Relation::queryAsControlUser($sql_query); } } } @@ -890,7 +891,7 @@ class Tracker */ private static function _getTrackingTable() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); return Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['tracking']); } diff --git a/libraries/classes/Tracking.php b/libraries/classes/Tracking.php index 97140bf0e1..6c01c933ff 100644 --- a/libraries/classes/Tracking.php +++ b/libraries/classes/Tracking.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Core; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Template; @@ -255,7 +256,7 @@ class Tracking */ public static function getListOfVersionsOfTable() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $sql_query = " SELECT * FROM " . Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['tracking']) . @@ -265,7 +266,7 @@ class Tracking $GLOBALS['dbi']->escapeString($_REQUEST['table']) . "' " . " ORDER BY version DESC "; - return PMA_queryAsControlUser($sql_query); + return Relation::queryAsControlUser($sql_query); } /** @@ -409,8 +410,7 @@ class Tracking */ public static function getSqlResultForSelectableTables() { - include_once 'libraries/relation.lib.php'; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $sql_query = " SELECT DISTINCT db_name, table_name FROM " . Util::backquote($cfgRelation['db']) . "." . @@ -419,7 +419,7 @@ class Tracking "' " . " ORDER BY db_name, table_name"; - return PMA_queryAsControlUser($sql_query); + return Relation::queryAsControlUser($sql_query); } /** @@ -1640,7 +1640,7 @@ class Tracking . $GLOBALS['dbi']->escapeString($table_name) . '\' AND `version` = \'' . $version_number . '\''; - $table_result = PMA_queryAsControlUser($table_query); + $table_result = Relation::queryAsControlUser($table_query); $version_data = $GLOBALS['dbi']->fetchArray($table_result); $tbl_link = 'tbl_tracking.php' . $url_query . '&table=' diff --git a/libraries/classes/Transformations.php b/libraries/classes/Transformations.php index 7e9a40125c..cb53b2bfc0 100644 --- a/libraries/classes/Transformations.php +++ b/libraries/classes/Transformations.php @@ -18,6 +18,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; use PhpMyAdmin\Util; /** @@ -249,7 +250,7 @@ class Transformations */ public static function getMIME($db, $table, $strict = false, $fullName = false) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['mimework']) { return false; @@ -326,7 +327,7 @@ class Transformations public static function setMIME($db, $table, $key, $mimetype, $transformation, $transformationOpts, $inputTransform, $inputTransformOpts, $forcedelete = false ) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['mimework']) { return false; @@ -345,7 +346,7 @@ class Transformations AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) . '\' AND `column_name` = \'' . $GLOBALS['dbi']->escapeString($key) . '\''; - $test_rs = PMA_queryAsControlUser( + $test_rs = Relation::queryAsControlUser( $test_qry, true, DatabaseInterface::QUERY_STORE ); @@ -407,7 +408,7 @@ class Transformations } if (isset($upd_query)) { - return PMA_queryAsControlUser($upd_query); + return Relation::queryAsControlUser($upd_query); } else { return false; } @@ -430,7 +431,7 @@ class Transformations */ public static function clear($db, $table = '', $column = '') { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! isset($cfgRelation['column_info'])) { return false; diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 7f46dea77b..19634c86c2 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -40,6 +40,7 @@ use PhpMyAdmin\LanguageManager; use PhpMyAdmin\Logging; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\AuthenticationPlugin; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Session; use PhpMyAdmin\ThemeManager; @@ -120,12 +121,6 @@ mb_internal_encoding('utf-8'); */ ini_set('precision', 14); -/** - * the relation lib, tracker needs it - */ -require './libraries/relation.lib.php'; - - /******************************************************************************/ /* start procedural code label_start_procedural */ @@ -937,15 +932,15 @@ if (! defined('PMA_MINIMUM_COMMON') && $GLOBALS['cfg']['ZeroConf'] == true ) { if (! empty($GLOBALS['db'])) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (empty($cfgRelation['db'])) { - PMA_fixPMATables($GLOBALS['db'], false); + Relation::fixPmaTables($GLOBALS['db'], false); } } - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (empty($cfgRelation['db'])) { if ($GLOBALS['dblist']->databases->exists('phpmyadmin')) { - PMA_fixPMATables('phpmyadmin', false); + Relation::fixPmaTables('phpmyadmin', false); } } } diff --git a/libraries/db_designer.lib.php b/libraries/db_designer.lib.php index 4fe39242da..c6f6ef8ce5 100644 --- a/libraries/db_designer.lib.php +++ b/libraries/db_designer.lib.php @@ -7,13 +7,12 @@ */ use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\SchemaPlugin; +use PhpMyAdmin\Relation; if (! defined('PHPMYADMIN')) { exit; } -require_once 'libraries/relation.lib.php'; - /** * Function to get html to display a page selector * @@ -78,13 +77,13 @@ function PMA_getHtmlForPageSaveAs($db) */ function PMA_getPageIdsAndNames($db) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $page_query = "SELECT `page_nr`, `page_descr` FROM " . PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['pdf_pages']) . " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($db) . "'" . " ORDER BY `page_descr`"; - $page_rs = PMA_queryAsControlUser( + $page_rs = Relation::queryAsControlUser( $page_query, false, PhpMyAdmin\DatabaseInterface::QUERY_STORE ); @@ -185,7 +184,7 @@ function PMA_getSideMenuParamsArray() { $params = array(); - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($GLOBALS['cfgRelation']['designersettingswork']) { diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index 7764b625f6..9e0bc6cefe 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -11,6 +11,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Table; use PhpMyAdmin\Template; @@ -249,7 +250,7 @@ function PMA_getOptionsForExportTemplates($export_type) $ret = '<option value="">-- ' . __('Select a template') . ' --</option>'; // Get the relation settings - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $query = "SELECT `id`, `template_name` FROM " . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' @@ -259,7 +260,7 @@ function PMA_getOptionsForExportTemplates($export_type) . "' AND `export_type` = '" . $GLOBALS['dbi']->escapeString($export_type) . "'" . " ORDER BY `template_name`;"; - $result = PMA_queryAsControlUser($query); + $result = Relation::queryAsControlUser($query); if (!$result) { return $ret; } @@ -986,7 +987,7 @@ function PMA_getExportDisplay( $export_type, $db, $table, $sql_query, $num_tables, $unlim_num_rows, $multi_values ) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (isset($_REQUEST['single_table'])) { $GLOBALS['single_table'] = $_REQUEST['single_table']; @@ -1099,7 +1100,7 @@ function PMA_handleExportTemplateActions($cfgRelation) break; } - $result = PMA_queryAsControlUser($query, false); + $result = Relation::queryAsControlUser($query, false); $response = Response::getInstance(); if (! $result) { diff --git a/libraries/error_report.lib.php b/libraries/error_report.lib.php index 3e02a70198..569651e798 100644 --- a/libraries/error_report.lib.php +++ b/libraries/error_report.lib.php @@ -5,6 +5,7 @@ * * @package PhpMyAdmin */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; if (! defined('PHPMYADMIN')) { @@ -48,7 +49,7 @@ function PMA_getPrettyReportData() */ function PMA_getReportData($exception_type = 'js') { - $relParams = PMA_getRelationsParam(); + $relParams = Relation::getRelationsParam(); // common params for both, php & js exceptions $report = array( "pma_version" => PMA_VERSION, diff --git a/libraries/normalization.lib.php b/libraries/normalization.lib.php index 1aa0cb023b..ece61d7364 100644 --- a/libraries/normalization.lib.php +++ b/libraries/normalization.lib.php @@ -6,6 +6,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -74,7 +75,7 @@ function PMA_getHtmlForColumnsList( function PMA_getHtmlForCreateNewColumn( $num_fields, $db, $table, $columnMeta=array() ) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $content_cells = array(); $available_mime = array(); $mime_map = array(); @@ -82,7 +83,7 @@ function PMA_getHtmlForCreateNewColumn( $mime_map = Transformations::getMIME($db, $table); $available_mime = Transformations::getAvailableMIMEtypes(); } - $comments_map = PMA_getComments($db, $table); + $comments_map = Relation::getComments($db, $table); for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { $content_cells[$columnNumber] = array( 'columnNumber' => $columnNumber, diff --git a/libraries/pmd_common.php b/libraries/pmd_common.php index 00debed234..601c9b91fe 100644 --- a/libraries/pmd_common.php +++ b/libraries/pmd_common.php @@ -5,6 +5,7 @@ * * @package PhpMyAdmin-Designer */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Table; /** @@ -16,7 +17,7 @@ if (! defined('PHPMYADMIN')) { $GLOBALS['PMD']['STYLE'] = 'default'; -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); /** * Retrieves table info and stores it in $GLOBALS['PMD'] @@ -63,7 +64,7 @@ function PMA_getTablesInfo() $one_table['ENGINE'] ); - $DF = PMA_getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']); + $DF = Relation::getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']); if ($DF != '') { $retval[$GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i]] = $DF; } @@ -124,7 +125,7 @@ function PMA_getScriptContr() PhpMyAdmin\DatabaseInterface::QUERY_STORE ); while ($val = @$GLOBALS['dbi']->fetchRow($alltab_rs)) { - $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal'); + $row = Relation::getForeigners($GLOBALS['db'], $val[0], '', 'internal'); if ($row !== false) { foreach ($row as $field => $value) { @@ -138,7 +139,7 @@ function PMA_getScriptContr() $i++; } } - $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign'); + $row = Relation::getForeigners($GLOBALS['db'], $val[0], '', 'foreign'); if ($row !== false) { foreach ($row['foreign_keys_data'] as $one_key) { @@ -248,7 +249,7 @@ function PMA_getScriptTabs() */ function PMA_getTablePositions($pg) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['pdfwork']) { return null; } @@ -282,7 +283,7 @@ function PMA_getTablePositions($pg) */ function PMA_getPageName($pg) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['pdfwork']) { return null; } @@ -310,7 +311,7 @@ function PMA_getPageName($pg) */ function PMA_deletePage($pg) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['pdfwork']) { return false; } @@ -318,7 +319,7 @@ function PMA_deletePage($pg) $query = "DELETE FROM " . PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['table_coords']) . " WHERE " . PhpMyAdmin\Util::backquote('pdf_page_number') . " = " . intval($pg); - $success = PMA_queryAsControlUser( + $success = Relation::queryAsControlUser( $query, true, PhpMyAdmin\DatabaseInterface::QUERY_STORE ); @@ -326,7 +327,7 @@ function PMA_deletePage($pg) $query = "DELETE FROM " . PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['pdf_pages']) . " WHERE " . PhpMyAdmin\Util::backquote('page_nr') . " = " . intval($pg); - $success = PMA_queryAsControlUser( + $success = Relation::queryAsControlUser( $query, true, PhpMyAdmin\DatabaseInterface::QUERY_STORE ); } @@ -344,7 +345,7 @@ function PMA_deletePage($pg) */ function PMA_getDefaultPage($db) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['pdfwork']) { return null; } @@ -379,7 +380,7 @@ function PMA_getDefaultPage($db) */ function PMA_getLoadingPage($db) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['pdfwork']) { return null; } @@ -419,9 +420,9 @@ function PMA_getLoadingPage($db) */ function PMA_createNewPage($pageName, $db) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['pdfwork']) { - $pageNumber = PMA_REL_createPage( + $pageNumber = Relation::createPage( $pageName, $cfgRelation, $db @@ -440,7 +441,7 @@ function PMA_createNewPage($pageName, $db) */ function PMA_saveTablePositions($pg) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['pdfwork']) { return false; } @@ -455,7 +456,7 @@ function PMA_saveTablePositions($pg) . " AND `pdf_page_number` = '" . $GLOBALS['dbi']->escapeString($pg) . "'"; - $res = PMA_queryAsControlUser( + $res = Relation::queryAsControlUser( $query, true, PhpMyAdmin\DatabaseInterface::QUERY_STORE @@ -482,7 +483,7 @@ function PMA_saveTablePositions($pg) . "'" . $GLOBALS['dbi']->escapeString($_REQUEST['t_x'][$key]) . "', " . "'" . $GLOBALS['dbi']->escapeString($_REQUEST['t_y'][$key]) . "')"; - $res = PMA_queryAsControlUser( + $res = Relation::queryAsControlUser( $query, true, PhpMyAdmin\DatabaseInterface::QUERY_STORE ); } @@ -501,12 +502,12 @@ function PMA_saveTablePositions($pg) */ function PMA_saveDisplayField($db, $table, $field) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (!$cfgRelation['displaywork']) { return false; } - $disp = PMA_getDisplayField($db, $table); + $disp = Relation::getDisplayField($db, $table); if ($disp && $disp === $field) { $field = ''; } @@ -543,8 +544,8 @@ function PMA_addNewRelation($db, $T1, $F1, $T2, $F2, $on_delete, $on_update, $DB && $type_T1 == $type_T2 ) { // relation exists? - $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign'); - $foreigner = PMA_searchColumnInForeigners($existrel_foreign, $F2); + $existrel_foreign = Relation::getForeigners($DB2, $T2, '', 'foreign'); + $foreigner = Relation::searchColumnInForeigners($existrel_foreign, $F2); if ($foreigner && isset($foreigner['constraint']) ) { @@ -630,7 +631,7 @@ function PMA_addNewRelation($db, $T1, $F1, $T2, $F2, $on_delete, $on_update, $DB . "'" . $GLOBALS['dbi']->escapeString($T1) . "', " . "'" . $GLOBALS['dbi']->escapeString($F1) . "')"; - if (PMA_queryAsControlUser($q, false, PhpMyAdmin\DatabaseInterface::QUERY_STORE) + if (Relation::queryAsControlUser($q, false, PhpMyAdmin\DatabaseInterface::QUERY_STORE) ) { return array(true, __('Internal relationship has been added.')); } @@ -668,8 +669,8 @@ function PMA_removeRelation($T1, $F1, $T2, $F2) && $type_T1 == $type_T2 ) { // InnoDB - $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign'); - $foreigner = PMA_searchColumnInForeigners($existrel_foreign, $F2); + $existrel_foreign = Relation::getForeigners($DB2, $T2, '', 'foreign'); + $foreigner = Relation::searchColumnInForeigners($existrel_foreign, $F2); if (isset($foreigner['constraint'])) { $upd_query = 'ALTER TABLE ' . PhpMyAdmin\Util::backquote($DB2) @@ -699,7 +700,7 @@ function PMA_removeRelation($T1, $F1, $T2, $F2) . " AND foreign_table = '" . $GLOBALS['dbi']->escapeString($T1) . "'" . " AND foreign_field = '" . $GLOBALS['dbi']->escapeString($F1) . "'"; - $result = PMA_queryAsControlUser( + $result = Relation::queryAsControlUser( $delete_query, false, PhpMyAdmin\DatabaseInterface::QUERY_STORE @@ -726,7 +727,7 @@ function PMA_removeRelation($T1, $F1, $T2, $F2) */ function PMA_saveDesignerSetting($index, $value) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $cfgDesigner = array( 'user' => $GLOBALS['cfg']['Server']['user'], 'db' => $cfgRelation['db'], @@ -758,7 +759,7 @@ function PMA_saveDesignerSetting($index, $value) . " WHERE username = '" . $GLOBALS['dbi']->escapeString($cfgDesigner['user']) . "';"; - $success = PMA_queryAsControlUser($save_query); + $success = Relation::queryAsControlUser($save_query); } else { $save_data = array($index => $value); @@ -769,7 +770,7 @@ function PMA_saveDesignerSetting($index, $value) . " VALUES('" . $cfgDesigner['user'] . "'," . " '" . json_encode($save_data) . "');"; - $success = PMA_queryAsControlUser($query); + $success = Relation::queryAsControlUser($query); } } diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php deleted file mode 100644 index 263222c497..0000000000 --- a/libraries/relation.lib.php +++ /dev/null @@ -1,2087 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Set of functions used with the relation and pdf feature - * - * @package PhpMyAdmin - */ - -use PhpMyAdmin\Core; -use PhpMyAdmin\Message; -use PhpMyAdmin\Table; -use PhpMyAdmin\RecentFavoriteTable; -use PhpMyAdmin\Url; - -/** - * Executes a query as controluser if possible, otherwise as normal user - * - * @param string $sql the query to execute - * @param boolean $show_error whether to display SQL error messages or not - * @param int $options query options - * - * @return resource|boolean the result set, or false if no result set - * - * @access public - * - */ -function PMA_queryAsControlUser($sql, $show_error = true, $options = 0) -{ - // Avoid caching of the number of rows affected; for example, this function - // is called for tracking purposes but we want to display the correct number - // of rows affected by the original query, not by the query generated for - // tracking. - $cache_affected_rows = false; - - if ($show_error) { - $result = $GLOBALS['dbi']->query( - $sql, - $GLOBALS['controllink'], - $options, - $cache_affected_rows - ); - } else { - $result = @$GLOBALS['dbi']->tryQuery( - $sql, - $GLOBALS['controllink'], - $options, - $cache_affected_rows - ); - } // end if... else... - - if ($result) { - return $result; - } else { - return false; - } -} // end of the "PMA_queryAsControlUser()" function - -/** - * Returns current relation parameters - * - * @return array $cfgRelation - */ -function PMA_getRelationsParam() -{ - if (empty($_SESSION['relation'][$GLOBALS['server']]) - || (empty($_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'])) - || $_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'] != PMA_VERSION - ) { - $_SESSION['relation'][$GLOBALS['server']] = PMA_checkRelationsParam(); - } - - // just for BC but needs to be before PMA_getRelationsParamDiagnostic() - // which uses it - $GLOBALS['cfgRelation'] = $_SESSION['relation'][$GLOBALS['server']]; - - return $_SESSION['relation'][$GLOBALS['server']]; -} - -/** - * prints out diagnostic info for pma relation feature - * - * @param array $cfgRelation Relation configuration - * - * @return string - */ -function PMA_getRelationsParamDiagnostic($cfgRelation) -{ - $retval = '<br>'; - - $messages = array(); - $messages['error'] = '<span style="color:red"><strong>' - . __('not OK') - . '</strong></span>'; - - $messages['ok'] = '<span style="color:green"><strong>' - . _pgettext('Correctly working', 'OK') - . '</strong></span>'; - - $messages['enabled'] = '<span style="color:green">' . __('Enabled') . '</span>'; - $messages['disabled'] = '<span style="color:red">' . __('Disabled') . '</span>'; - - if (empty($cfgRelation['db'])) { - $retval .= __('Configuration of pmadb…') . ' ' - . $messages['error'] - . PhpMyAdmin\Util::showDocu('setup', 'linked-tables') - . '<br />' . "\n" - . __('General relation features') - . ' <font color="green">' . __('Disabled') - . '</font>' . "\n"; - if ($GLOBALS['cfg']['ZeroConf']) { - if (empty($GLOBALS['db'])) { - $retval .= PMA_getHtmlFixPMATables(true, true); - } else { - $retval .= PMA_getHtmlFixPMATables(true); - } - } - } else { - $retval .= '<table>' . "\n"; - - if (! $cfgRelation['allworks'] - && $GLOBALS['cfg']['ZeroConf'] - // Avoid showing a "Create missing tables" link if it's a - // problem of missing definition - && PMA_arePmadbTablesDefined() - ) { - $retval .= PMA_getHtmlFixPMATables(false); - $retval .= '<br />'; - } - - $retval .= PMA_getDiagMessageForParameter( - 'pmadb', - $cfgRelation['db'], - $messages, - 'pmadb' - ); - $retval .= PMA_getDiagMessageForParameter( - 'relation', - isset($cfgRelation['relation']), - $messages, - 'relation' - ); - $retval .= PMA_getDiagMessageForFeature( - __('General relation features'), - 'relwork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'table_info', - isset($cfgRelation['table_info']), - $messages, - 'table_info' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Display Features'), - 'displaywork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'table_coords', - isset($cfgRelation['table_coords']), - $messages, - 'table_coords' - ); - $retval .= PMA_getDiagMessageForParameter( - 'pdf_pages', - isset($cfgRelation['pdf_pages']), - $messages, - 'pdf_pages' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Designer and creation of PDFs'), - 'pdfwork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'column_info', - isset($cfgRelation['column_info']), - $messages, - 'column_info' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Displaying Column Comments'), - 'commwork', - $messages, - false - ); - $retval .= PMA_getDiagMessageForFeature( - __('Browser transformation'), - 'mimework', - $messages - ); - if ($cfgRelation['commwork'] && ! $cfgRelation['mimework']) { - $retval .= '<tr><td colspan=2 class="left error">'; - $retval .= __( - 'Please see the documentation on how to' - . ' update your column_info table.' - ); - $retval .= PhpMyAdmin\Util::showDocu( - 'config', - 'cfg_Servers_column_info' - ); - $retval .= '</td></tr>'; - } - $retval .= PMA_getDiagMessageForParameter( - 'bookmarktable', - isset($cfgRelation['bookmark']), - $messages, - 'bookmark' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Bookmarked SQL query'), - 'bookmarkwork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'history', - isset($cfgRelation['history']), - $messages, - 'history' - ); - $retval .= PMA_getDiagMessageForFeature( - __('SQL history'), - 'historywork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'recent', - isset($cfgRelation['recent']), - $messages, - 'recent' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Persistent recently used tables'), - 'recentwork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'favorite', - isset($cfgRelation['favorite']), - $messages, - 'favorite' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Persistent favorite tables'), - 'favoritework', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'table_uiprefs', - isset($cfgRelation['table_uiprefs']), - $messages, - 'table_uiprefs' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Persistent tables\' UI preferences'), - 'uiprefswork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'tracking', - isset($cfgRelation['tracking']), - $messages, - 'tracking' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Tracking'), - 'trackingwork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'userconfig', - isset($cfgRelation['userconfig']), - $messages, - 'userconfig' - ); - $retval .= PMA_getDiagMessageForFeature( - __('User preferences'), - 'userconfigwork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'users', - isset($cfgRelation['users']), - $messages, - 'users' - ); - $retval .= PMA_getDiagMessageForParameter( - 'usergroups', - isset($cfgRelation['usergroups']), - $messages, - 'usergroups' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Configurable menus'), - 'menuswork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'navigationhiding', - isset($cfgRelation['navigationhiding']), - $messages, - 'navigationhiding' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Hide/show navigation items'), - 'navwork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'savedsearches', - isset($cfgRelation['savedsearches']), - $messages, - 'savedsearches' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Saving Query-By-Example searches'), - 'savedsearcheswork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'central_columns', - isset($cfgRelation['central_columns']), - $messages, - 'central_columns' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Managing Central list of columns'), - 'centralcolumnswork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'designer_settings', - isset($cfgRelation['designer_settings']), - $messages, - 'designer_settings' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Remembering Designer Settings'), - 'designersettingswork', - $messages - ); - $retval .= PMA_getDiagMessageForParameter( - 'export_templates', - isset($cfgRelation['export_templates']), - $messages, - 'export_templates' - ); - $retval .= PMA_getDiagMessageForFeature( - __('Saving export templates'), - 'exporttemplateswork', - $messages - ); - $retval .= '</table>' . "\n"; - - if (! $cfgRelation['allworks']) { - - $retval .= '<p>' . __('Quick steps to set up advanced features:') - . '</p>'; - - $items = array(); - $items[] = sprintf( - __( - 'Create the needed tables with the ' - . '<code>%screate_tables.sql</code>.' - ), - htmlspecialchars(SQL_DIR) - ) . ' ' . PhpMyAdmin\Util::showDocu('setup', 'linked-tables'); - $items[] = __('Create a pma user and give access to these tables.') . ' ' - . PhpMyAdmin\Util::showDocu('config', 'cfg_Servers_controluser'); - $items[] = __( - 'Enable advanced features in configuration file ' - . '(<code>config.inc.php</code>), for example by ' - . 'starting from <code>config.sample.inc.php</code>.' - ) . ' ' . PhpMyAdmin\Util::showDocu('setup', 'quick-install'); - $items[] = __( - 'Re-login to phpMyAdmin to load the updated configuration file.' - ); - - $retval .= PhpMyAdmin\Template::get('list/unordered')->render( - array('items' => $items,) - ); - } - } - - return $retval; -} - -/** - * prints out one diagnostic message for a feature - * - * @param string $feature_name feature name in a message string - * @param string $relation_parameter the $GLOBALS['cfgRelation'] parameter to check - * @param array $messages utility messages - * @param boolean $skip_line whether to skip a line after the message - * - * @return string - */ -function PMA_getDiagMessageForFeature($feature_name, - $relation_parameter, $messages, $skip_line = true -) { - $retval = ' <tr><td colspan=2 class="right">' . $feature_name . ': '; - if (isset($GLOBALS['cfgRelation'][$relation_parameter]) - && $GLOBALS['cfgRelation'][$relation_parameter] - ) { - $retval .= $messages['enabled']; - } else { - $retval .= $messages['disabled']; - } - $retval .= '</td></tr>'; - if ($skip_line) { - $retval .= '<tr><td> </td></tr>'; - } - return $retval; -} - -/** - * prints out one diagnostic message for a configuration parameter - * - * @param string $parameter config parameter name to display - * @param boolean $relationParameterSet whether this parameter is set - * @param array $messages utility messages - * @param string $docAnchor anchor in documentation - * - * @return string - */ -function PMA_getDiagMessageForParameter($parameter, - $relationParameterSet, $messages, $docAnchor -) { - $retval = '<tr><th class="left">'; - $retval .= '$cfg[\'Servers\'][$i][\'' . $parameter . '\'] ... '; - $retval .= '</th><td class="right">'; - if ($relationParameterSet) { - $retval .= $messages['ok']; - } else { - $retval .= sprintf( - $messages['error'], - PhpMyAdmin\Util::getDocuLink('config', 'cfg_Servers_' . $docAnchor) - ); - } - $retval .= '</td></tr>' . "\n"; - return $retval; -} - - -/** - * Defines the relation parameters for the current user - * just a copy of the functions used for relations ;-) - * but added some stuff to check what will work - * - * @access protected - * @return array the relation parameters for the current user - */ -function PMA_checkRelationsParam() -{ - $cfgRelation = array(); - $cfgRelation['PMA_VERSION'] = PMA_VERSION; - - $workToTable = array( - 'relwork' => 'relation', - 'displaywork' => array('relation', 'table_info'), - 'bookmarkwork' => 'bookmarktable', - 'pdfwork' => array('table_coords', 'pdf_pages'), - 'commwork' => 'column_info', - 'mimework' => 'column_info', - 'historywork' => 'history', - 'recentwork' => 'recent', - 'favoritework' => 'favorite', - 'uiprefswork' => 'table_uiprefs', - 'trackingwork' => 'tracking', - 'userconfigwork' => 'userconfig', - 'menuswork' => array('users', 'usergroups'), - 'navwork' => 'navigationhiding', - 'savedsearcheswork' => 'savedsearches', - 'centralcolumnswork' => 'central_columns', - 'designersettingswork' => 'designer_settings', - 'exporttemplateswork' => 'export_templates', - ); - - foreach ($workToTable as $work => $table) { - $cfgRelation[$work] = false; - } - $cfgRelation['allworks'] = false; - $cfgRelation['user'] = null; - $cfgRelation['db'] = null; - - if ($GLOBALS['server'] == 0 - || empty($GLOBALS['cfg']['Server']['pmadb']) - || empty($GLOBALS['controllink']) - || ! $GLOBALS['dbi']->selectDb( - $GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink'] - ) - ) { - // No server selected -> no bookmark table - // we return the array with the falses in it, - // to avoid some 'Uninitialized string offset' errors later - $GLOBALS['cfg']['Server']['pmadb'] = false; - return $cfgRelation; - } - - $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user']; - $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb']; - - // Now I just check if all tables that i need are present so I can for - // example enable relations but not pdf... - // I was thinking of checking if they have all required columns but I - // fear it might be too slow - - $tab_query = 'SHOW TABLES FROM ' - . PhpMyAdmin\Util::backquote( - $GLOBALS['cfg']['Server']['pmadb'] - ); - $tab_rs = PMA_queryAsControlUser( - $tab_query, false, PhpMyAdmin\DatabaseInterface::QUERY_STORE - ); - - if (! $tab_rs) { - // query failed ... ? - //$GLOBALS['cfg']['Server']['pmadb'] = false; - return $cfgRelation; - } - - while ($curr_table = @$GLOBALS['dbi']->fetchRow($tab_rs)) { - if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) { - $cfgRelation['bookmark'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { - $cfgRelation['relation'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) { - $cfgRelation['table_info'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) { - $cfgRelation['table_coords'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) { - $cfgRelation['column_info'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) { - $cfgRelation['pdf_pages'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) { - $cfgRelation['history'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { - $cfgRelation['recent'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['favorite']) { - $cfgRelation['favorite'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) { - $cfgRelation['table_uiprefs'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { - $cfgRelation['tracking'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { - $cfgRelation['userconfig'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['users']) { - $cfgRelation['users'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['usergroups']) { - $cfgRelation['usergroups'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['navigationhiding']) { - $cfgRelation['navigationhiding'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['savedsearches']) { - $cfgRelation['savedsearches'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['central_columns']) { - $cfgRelation['central_columns'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['designer_settings']) { - $cfgRelation['designer_settings'] = $curr_table[0]; - } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['export_templates']) { - $cfgRelation['export_templates'] = $curr_table[0]; - } - } // end while - $GLOBALS['dbi']->freeResult($tab_rs); - - if (isset($cfgRelation['relation'])) { - $cfgRelation['relwork'] = true; - } - - if (isset($cfgRelation['relation']) && isset($cfgRelation['table_info'])) { - $cfgRelation['displaywork'] = true; - } - - if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { - $cfgRelation['pdfwork'] = true; - } - - if (isset($cfgRelation['column_info'])) { - $cfgRelation['commwork'] = true; - // phpMyAdmin 4.3+ - // Check for input transformations upgrade. - $cfgRelation['mimework'] = PMA_tryUpgradeTransformations(); - } - - if (isset($cfgRelation['history'])) { - $cfgRelation['historywork'] = true; - } - - if (isset($cfgRelation['recent'])) { - $cfgRelation['recentwork'] = true; - } - - if (isset($cfgRelation['favorite'])) { - $cfgRelation['favoritework'] = true; - } - - if (isset($cfgRelation['table_uiprefs'])) { - $cfgRelation['uiprefswork'] = true; - } - - if (isset($cfgRelation['tracking'])) { - $cfgRelation['trackingwork'] = true; - } - - if (isset($cfgRelation['userconfig'])) { - $cfgRelation['userconfigwork'] = true; - } - - if (isset($cfgRelation['bookmark'])) { - $cfgRelation['bookmarkwork'] = true; - } - - if (isset($cfgRelation['users']) && isset($cfgRelation['usergroups'])) { - $cfgRelation['menuswork'] = true; - } - - if (isset($cfgRelation['navigationhiding'])) { - $cfgRelation['navwork'] = true; - } - - if (isset($cfgRelation['savedsearches'])) { - $cfgRelation['savedsearcheswork'] = true; - } - - if (isset($cfgRelation['central_columns'])) { - $cfgRelation['centralcolumnswork'] = true; - } - - if (isset($cfgRelation['designer_settings'])) { - $cfgRelation['designersettingswork'] = true; - } - - if (isset($cfgRelation['export_templates'])) { - $cfgRelation['exporttemplateswork'] = true; - } - - $allWorks = true; - foreach ($workToTable as $work => $table) { - if (! $cfgRelation[$work]) { - if (is_string($table)) { - if (isset($GLOBALS['cfg']['Server'][$table]) - && $GLOBALS['cfg']['Server'][$table] !== false - ) { - $allWorks = false; - break; - } - } else if (is_array($table)) { - $oneNull = false; - foreach ($table as $t) { - if (isset($GLOBALS['cfg']['Server'][$t]) - && $GLOBALS['cfg']['Server'][$t] === false - ) { - $oneNull = true; - break; - } - } - if (! $oneNull) { - $allWorks = false; - break; - } - } - } - } - $cfgRelation['allworks'] = $allWorks; - - return $cfgRelation; -} // end of the 'PMA_checkRelationsParam()' function - -/** - * Check whether column_info table input transformation - * upgrade is required and try to upgrade silently - * - * @return bool false if upgrade failed - * - * @access public - */ -function PMA_tryUpgradeTransformations() -{ - // From 4.3, new input oriented transformation feature was introduced. - // Check whether column_info table has input transformation columns - $new_cols = array( - "input_transformation", - "input_transformation_options" - ); - $query = 'SHOW COLUMNS FROM ' - . PhpMyAdmin\Util::backquote($GLOBALS['cfg']['Server']['pmadb']) - . '.' . PhpMyAdmin\Util::backquote( - $GLOBALS['cfg']['Server']['column_info'] - ) - . ' WHERE Field IN (\'' . implode('\', \'', $new_cols) . '\')'; - $result = PMA_queryAsControlUser( - $query, false, PhpMyAdmin\DatabaseInterface::QUERY_STORE - ); - if ($result) { - $rows = $GLOBALS['dbi']->numRows($result); - $GLOBALS['dbi']->freeResult($result); - // input transformations are present - // no need to upgrade - if ($rows === 2) { - return true; - // try silent upgrade without disturbing the user - } else { - // read upgrade query file - $query = @file_get_contents(SQL_DIR . 'upgrade_column_info_4_3_0+.sql'); - // replace database name from query to with set in config.inc.php - $query = str_replace( - '`phpmyadmin`', - PhpMyAdmin\Util::backquote($GLOBALS['cfg']['Server']['pmadb']), - $query - ); - // replace pma__column_info table name from query - // to with set in config.inc.php - $query = str_replace( - '`pma__column_info`', - PhpMyAdmin\Util::backquote( - $GLOBALS['cfg']['Server']['column_info'] - ), - $query - ); - $GLOBALS['dbi']->tryMultiQuery($query, $GLOBALS['controllink']); - // skips result sets of query as we are not interested in it - while ($GLOBALS['dbi']->moreResults($GLOBALS['controllink']) - && $GLOBALS['dbi']->nextResult($GLOBALS['controllink']) - ) { - } - $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']); - // return true if no error exists otherwise false - return empty($error); - } - } - // some failure, either in upgrading or something else - // make some noise, time to wake up user. - return false; -} - -/** - * Gets all Relations to foreign tables for a given table or - * optionally a given column in a table - * - * @param string $db the name of the db to check for - * @param string $table the name of the table to check for - * @param string $column the name of the column to check for - * @param string $source the source for foreign key information - * - * @return array db,table,column - * - * @access public - */ -function PMA_getForeigners($db, $table, $column = '', $source = 'both') -{ - $cfgRelation = PMA_getRelationsParam(); - $foreign = array(); - - if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) { - $rel_query = ' - SELECT `master_field`, - `foreign_db`, - `foreign_table`, - `foreign_field` - FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) . ' - WHERE `master_db` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' - AND `master_table` = \'' . $GLOBALS['dbi']->escapeString($table) - . '\' '; - if (strlen($column) > 0) { - $rel_query .= ' AND `master_field` = ' - . '\'' . $GLOBALS['dbi']->escapeString($column) . '\''; - } - $foreign = $GLOBALS['dbi']->fetchResult( - $rel_query, 'master_field', null, $GLOBALS['controllink'] - ); - } - - if (($source == 'both' || $source == 'foreign') && strlen($table) > 0) { - $tableObj = new Table($table, $db); - $show_create_table = $tableObj->showCreate(); - if ($show_create_table) { - $parser = new \PhpMyAdmin\SqlParser\Parser($show_create_table); - /** - * @var \PhpMyAdmin\SqlParser\Statements\CreateStatement $stmt - */ - $stmt = $parser->statements[0]; - $foreign['foreign_keys_data'] = \PhpMyAdmin\SqlParser\Utils\Table::getForeignKeys( - $stmt - ); - } - } - - /** - * Emulating relations for some information_schema tables - */ - $isInformationSchema = mb_strtolower($db) == 'information_schema'; - $isMysql = mb_strtolower($db) == 'mysql'; - if (($isInformationSchema || $isMysql) - && ($source == 'internal' || $source == 'both') - ) { - if ($isInformationSchema) { - $relations_key = 'information_schema_relations'; - include_once './libraries/information_schema_relations.lib.php'; - } else { - $relations_key = 'mysql_relations'; - include_once './libraries/mysql_relations.lib.php'; - } - if (isset($GLOBALS[$relations_key][$table])) { - foreach ($GLOBALS[$relations_key][$table] as $field => $relations) { - if ((strlen($column) === 0 || $column == $field) - && (! isset($foreign[$field]) - || strlen($foreign[$field]) === 0) - ) { - $foreign[$field] = $relations; - } - } - } - } - - return $foreign; -} // end of the 'PMA_getForeigners()' function - -/** - * Gets the display field of a table - * - * @param string $db the name of the db to check for - * @param string $table the name of the table to check for - * - * @return string field name - * - * @access public - */ -function PMA_getDisplayField($db, $table) -{ - $cfgRelation = PMA_getRelationsParam(); - - /** - * Try to fetch the display field from DB. - */ - if ($cfgRelation['displaywork']) { - $disp_query = ' - SELECT `display_field` - FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_info']) . ' - WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' - AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) - . '\''; - - $row = $GLOBALS['dbi']->fetchSingleRow( - $disp_query, 'ASSOC', $GLOBALS['controllink'] - ); - if (isset($row['display_field'])) { - return $row['display_field']; - } - } - - /** - * Emulating the display field for some information_schema tables. - */ - if ($db == 'information_schema') { - switch ($table) { - case 'CHARACTER_SETS': - return 'DESCRIPTION'; - case 'TABLES': - return 'TABLE_COMMENT'; - } - } - - /** - * Pick first char field - */ - $columns = $GLOBALS['dbi']->getColumnsFull($db, $table); - if ($columns) { - foreach ($columns as $column) { - if ($GLOBALS['PMA_Types']->getTypeClass($column['DATA_TYPE']) == 'CHAR') { - return $column['COLUMN_NAME']; - } - } - } - - /** - * No Luck... - */ - return false; - -} // end of the 'PMA_getDisplayField()' function - -/** - * Gets the comments for all columns of a table or the db itself - * - * @param string $db the name of the db to check for - * @param string $table the name of the table to check for - * - * @return array [column_name] = comment - * - * @access public - */ -function PMA_getComments($db, $table = '') -{ - $comments = array(); - - if ($table != '') { - // MySQL native column comments - $columns = $GLOBALS['dbi']->getColumns($db, $table, null, true); - if ($columns) { - foreach ($columns as $column) { - if (! empty($column['Comment'])) { - $comments[$column['Field']] = $column['Comment']; - } - } - } - } else { - $comments[] = PMA_getDbComment($db); - } - - return $comments; -} // end of the 'PMA_getComments()' function - -/** - * Gets the comment for a db - * - * @param string $db the name of the db to check for - * - * @return string comment - * - * @access public - */ -function PMA_getDbComment($db) -{ - $cfgRelation = PMA_getRelationsParam(); - $comment = ''; - - if ($cfgRelation['commwork']) { - // pmadb internal db comment - $com_qry = " - SELECT `comment` - FROM " . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) - . " - WHERE db_name = '" . $GLOBALS['dbi']->escapeString($db) . "' - AND table_name = '' - AND column_name = '(db_comment)'"; - $com_rs = PMA_queryAsControlUser( - $com_qry, true, PhpMyAdmin\DatabaseInterface::QUERY_STORE - ); - - if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { - $row = $GLOBALS['dbi']->fetchAssoc($com_rs); - $comment = $row['comment']; - } - $GLOBALS['dbi']->freeResult($com_rs); - } - - return $comment; -} // end of the 'PMA_getDbComment()' function - -/** - * Gets the comment for a db - * - * @access public - * - * @return string comment - */ -function PMA_getDbComments() -{ - $cfgRelation = PMA_getRelationsParam(); - $comments = array(); - - if ($cfgRelation['commwork']) { - // pmadb internal db comment - $com_qry = " - SELECT `db_name`, `comment` - FROM " . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) - . " - WHERE `column_name` = '(db_comment)'"; - $com_rs = PMA_queryAsControlUser( - $com_qry, true, PhpMyAdmin\DatabaseInterface::QUERY_STORE - ); - - if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { - while ($row = $GLOBALS['dbi']->fetchAssoc($com_rs)) { - $comments[$row['db_name']] = $row['comment']; - } - } - $GLOBALS['dbi']->freeResult($com_rs); - } - - return $comments; -} // end of the 'PMA_getDbComments()' function - -/** - * Set a database comment to a certain value. - * - * @param string $db the name of the db - * @param string $comment the value of the column - * - * @return boolean true, if comment-query was made. - * - * @access public - */ -function PMA_setDbComment($db, $comment = '') -{ - $cfgRelation = PMA_getRelationsParam(); - - if (! $cfgRelation['commwork']) { - return false; - } - - if (strlen($comment) > 0) { - $upd_query = 'INSERT INTO ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) - . ' (`db_name`, `table_name`, `column_name`, `comment`)' - . ' VALUES (\'' - . $GLOBALS['dbi']->escapeString($db) - . "', '', '(db_comment)', '" - . $GLOBALS['dbi']->escapeString($comment) - . "') " - . ' ON DUPLICATE KEY UPDATE ' - . "`comment` = '" . $GLOBALS['dbi']->escapeString($comment) . "'"; - } else { - $upd_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) - . ' WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) - . '\' - AND `table_name` = \'\' - AND `column_name` = \'(db_comment)\''; - } - - if (isset($upd_query)) { - return PMA_queryAsControlUser($upd_query); - } - - return false; -} // end of 'PMA_setDbComment()' function - -/** - * Set a SQL history entry - * - * @param string $db the name of the db - * @param string $table the name of the table - * @param string $username the username - * @param string $sqlquery the sql query - * - * @return void - * - * @access public - */ -function PMA_setHistory($db, $table, $username, $sqlquery) -{ - $maxCharactersInDisplayedSQL = $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']; - // Prevent to run this automatically on Footer class destroying in testsuite - if (defined('TESTSUITE') - || mb_strlen($sqlquery) > $maxCharactersInDisplayedSQL - ) { - return; - } - - $cfgRelation = PMA_getRelationsParam(); - - if (! isset($_SESSION['sql_history'])) { - $_SESSION['sql_history'] = array(); - } - - $_SESSION['sql_history'][] = array( - 'db' => $db, - 'table' => $table, - 'sqlquery' => $sqlquery, - ); - - if (count($_SESSION['sql_history']) > $GLOBALS['cfg']['QueryHistoryMax']) { - // history should not exceed a maximum count - array_shift($_SESSION['sql_history']); - } - - if (! $cfgRelation['historywork'] || ! $GLOBALS['cfg']['QueryHistoryDB']) { - return; - } - - PMA_queryAsControlUser( - 'INSERT INTO ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['history']) . ' - (`username`, - `db`, - `table`, - `timevalue`, - `sqlquery`) - VALUES - (\'' . $GLOBALS['dbi']->escapeString($username) . '\', - \'' . $GLOBALS['dbi']->escapeString($db) . '\', - \'' . $GLOBALS['dbi']->escapeString($table) . '\', - NOW(), - \'' . $GLOBALS['dbi']->escapeString($sqlquery) . '\')' - ); - - PMA_purgeHistory($username); - -} // end of 'PMA_setHistory()' function - -/** - * Gets a SQL history entry - * - * @param string $username the username - * - * @return array list of history items - * - * @access public - */ -function PMA_getHistory($username) -{ - $cfgRelation = PMA_getRelationsParam(); - - if (! $cfgRelation['historywork']) { - return false; - } - - /** - * if db-based history is disabled but there exists a session-based - * history, use it - */ - if (! $GLOBALS['cfg']['QueryHistoryDB']) { - if (isset($_SESSION['sql_history'])) { - return array_reverse($_SESSION['sql_history']); - } - return false; - } - - $hist_query = ' - SELECT `db`, - `table`, - `sqlquery`, - `timevalue` - FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['history']) . ' - WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) . '\' - ORDER BY `id` DESC'; - - return $GLOBALS['dbi']->fetchResult( - $hist_query, null, null, $GLOBALS['controllink'] - ); -} // end of 'PMA_getHistory()' function - -/** - * purges SQL history - * - * deletes entries that exceeds $cfg['QueryHistoryMax'], oldest first, for the - * given user - * - * @param string $username the username - * - * @return void - * - * @access public - */ -function PMA_purgeHistory($username) -{ - $cfgRelation = PMA_getRelationsParam(); - if (! $GLOBALS['cfg']['QueryHistoryDB'] || ! $cfgRelation['historywork']) { - return; - } - - if (! $cfgRelation['historywork']) { - return; - } - - $search_query = ' - SELECT `timevalue` - FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['history']) . ' - WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) . '\' - ORDER BY `timevalue` DESC - LIMIT ' . $GLOBALS['cfg']['QueryHistoryMax'] . ', 1'; - - if ($max_time = $GLOBALS['dbi']->fetchValue( - $search_query, 0, 0, $GLOBALS['controllink'] - )) { - PMA_queryAsControlUser( - 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['history']) . ' - WHERE `username` = \'' . $GLOBALS['dbi']->escapeString($username) - . '\' - AND `timevalue` <= \'' . $max_time . '\'' - ); - } -} // end of 'PMA_purgeHistory()' function - -/** - * Prepares the dropdown for one mode - * - * @param array $foreign the keys and values for foreigns - * @param string $data the current data of the dropdown - * @param string $mode the needed mode - * - * @return array the <option value=""><option>s - * - * @access protected - */ -function PMA_buildForeignDropdown($foreign, $data, $mode) -{ - $reloptions = array(); - - // id-only is a special mode used when no foreign display column - // is available - if ($mode == 'id-content' || $mode == 'id-only') { - // sort for id-content - if ($GLOBALS['cfg']['NaturalOrder']) { - uksort($foreign, 'strnatcasecmp'); - } else { - ksort($foreign); - } - } elseif ($mode == 'content-id') { - // sort for content-id - if ($GLOBALS['cfg']['NaturalOrder']) { - natcasesort($foreign); - } else { - asort($foreign); - } - } - - foreach ($foreign as $key => $value) { - if (mb_strlen($value) <= $GLOBALS['cfg']['LimitChars'] - ) { - $vtitle = ''; - $value = htmlspecialchars($value); - } else { - $vtitle = htmlspecialchars($value); - $value = htmlspecialchars( - mb_substr( - $value, 0, $GLOBALS['cfg']['LimitChars'] - ) . '...' - ); - } - - $reloption = '<option value="' . htmlspecialchars($key) . '"'; - if ($vtitle != '') { - $reloption .= ' title="' . $vtitle . '"'; - } - - if ((string) $key == (string) $data) { - $reloption .= ' selected="selected"'; - } - - if ($mode == 'content-id') { - $reloptions[] = $reloption . '>' - . $value . ' - ' . htmlspecialchars($key) . '</option>'; - } elseif ($mode == 'id-content') { - $reloptions[] = $reloption . '>' - . htmlspecialchars($key) . ' - ' . $value . '</option>'; - } elseif ($mode == 'id-only') { - $reloptions[] = $reloption . '>' - . htmlspecialchars($key) . '</option>'; - } - } // end foreach - - return $reloptions; -} // end of 'PMA_buildForeignDropdown' function - -/** - * Outputs dropdown with values of foreign fields - * - * @param array $disp_row array of the displayed row - * @param string $foreign_field the foreign field - * @param string $foreign_display the foreign field to display - * @param string $data the current data of the dropdown (field in row) - * @param int $max maximum number of items in the dropdown - * - * @return string the <option value=""><option>s - * - * @access public - */ -function PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, - $max = null -) { - if (null === $max) { - $max = $GLOBALS['cfg']['ForeignKeyMaxLimit']; - } - - $foreign = array(); - - // collect the data - foreach ($disp_row as $relrow) { - $key = $relrow[$foreign_field]; - - // if the display field has been defined for this foreign table - if ($foreign_display) { - $value = $relrow[$foreign_display]; - } else { - $value = ''; - } // end if ($foreign_display) - - $foreign[$key] = $value; - } // end foreach - - // put the dropdown sections in correct order - $top = array(); - $bottom = array(); - if ($foreign_display) { - if (Core::isValid($GLOBALS['cfg']['ForeignKeyDropdownOrder'], 'array')) { - if (Core::isValid($GLOBALS['cfg']['ForeignKeyDropdownOrder'][0])) { - $top = PMA_buildForeignDropdown( - $foreign, - $data, - $GLOBALS['cfg']['ForeignKeyDropdownOrder'][0] - ); - } - if (Core::isValid($GLOBALS['cfg']['ForeignKeyDropdownOrder'][1])) { - $bottom = PMA_buildForeignDropdown( - $foreign, - $data, - $GLOBALS['cfg']['ForeignKeyDropdownOrder'][1] - ); - } - } else { - $top = PMA_buildForeignDropdown($foreign, $data, 'id-content'); - $bottom = PMA_buildForeignDropdown($foreign, $data, 'content-id'); - } - } else { - $top = PMA_buildForeignDropdown($foreign, $data, 'id-only'); - } - - // beginning of dropdown - $ret = '<option value=""> </option>'; - $top_count = count($top); - if ($max == -1 || $top_count < $max) { - $ret .= implode('', $top); - if ($foreign_display && $top_count > 0) { - // this empty option is to visually mark the beginning of the - // second series of values (bottom) - $ret .= '<option value=""> </option>'; - } - } - if ($foreign_display) { - $ret .= implode('', $bottom); - } - - return $ret; -} // end of 'PMA_foreignDropdown()' function - -/** - * Gets foreign keys in preparation for a drop-down selector - * - * @param array|boolean $foreigners array of the foreign keys - * @param string $field the foreign field name - * @param bool $override_total whether to override the total - * @param string $foreign_filter a possible filter - * @param string $foreign_limit a possible LIMIT clause - * @param bool $get_total optional, whether to get total num of rows - * in $foreignData['the_total;] - * (has an effect of performance) - * - * @return array data about the foreign keys - * - * @access public - */ -function PMA_getForeignData( - $foreigners, $field, $override_total, - $foreign_filter, $foreign_limit, $get_total=false -) { - // we always show the foreign field in the drop-down; if a display - // field is defined, we show it besides the foreign field - $foreign_link = false; - do { - if (! $foreigners) { - break; - } - $foreigner = PMA_searchColumnInForeigners($foreigners, $field); - if ($foreigner != false) { - $foreign_db = $foreigner['foreign_db']; - $foreign_table = $foreigner['foreign_table']; - $foreign_field = $foreigner['foreign_field']; - } else { - break; - } - - // Count number of rows in the foreign table. Currently we do - // not use a drop-down if more than ForeignKeyMaxLimit rows in the - // foreign table, - // for speed reasons and because we need a better interface for this. - // - // We could also do the SELECT anyway, with a LIMIT, and ensure that - // the current value of the field is one of the choices. - - // Check if table has more rows than specified by - // $GLOBALS['cfg']['ForeignKeyMaxLimit'] - $moreThanLimit = $GLOBALS['dbi']->getTable($foreign_db, $foreign_table) - ->checkIfMinRecordsExist($GLOBALS['cfg']['ForeignKeyMaxLimit']); - - if ($override_total == true - || !$moreThanLimit - ) { - // foreign_display can be false if no display field defined: - $foreign_display = PMA_getDisplayField($foreign_db, $foreign_table); - - $f_query_main = 'SELECT ' . PhpMyAdmin\Util::backquote($foreign_field) - . ( - ($foreign_display == false) - ? '' - : ', ' . PhpMyAdmin\Util::backquote($foreign_display) - ); - $f_query_from = ' FROM ' . PhpMyAdmin\Util::backquote($foreign_db) - . '.' . PhpMyAdmin\Util::backquote($foreign_table); - $f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' - . PhpMyAdmin\Util::backquote($foreign_field) - . ' LIKE "%' . $GLOBALS['dbi']->escapeString($foreign_filter) . '%"' - . ( - ($foreign_display == false) - ? '' - : ' OR ' . PhpMyAdmin\Util::backquote($foreign_display) - . ' LIKE "%' . $GLOBALS['dbi']->escapeString($foreign_filter) - . '%"' - ); - $f_query_order = ($foreign_display == false) ? '' :' ORDER BY ' - . PhpMyAdmin\Util::backquote($foreign_table) . '.' - . PhpMyAdmin\Util::backquote($foreign_display); - - $f_query_limit = ! empty($foreign_limit) ? ($foreign_limit) : ''; - - if (!empty($foreign_filter)) { - $the_total = $GLOBALS['dbi']->fetchValue( - 'SELECT COUNT(*)' . $f_query_from . $f_query_filter - ); - if ($the_total === false) { - $the_total = 0; - } - } - - $disp = $GLOBALS['dbi']->tryQuery( - $f_query_main . $f_query_from . $f_query_filter - . $f_query_order . $f_query_limit - ); - if ($disp && $GLOBALS['dbi']->numRows($disp) > 0) { - // If a resultset has been created, pre-cache it in the $disp_row - // array. This helps us from not needing to use mysql_data_seek by - // accessing a pre-cached PHP array. Usually those resultsets are - // not that big, so a performance hit should not be expected. - $disp_row = array(); - while ($single_disp_row = @$GLOBALS['dbi']->fetchAssoc($disp)) { - $disp_row[] = $single_disp_row; - } - @$GLOBALS['dbi']->freeResult($disp); - } else { - // Either no data in the foreign table or - // user does not have select permission to foreign table/field - // Show an input field with a 'Browse foreign values' link - $disp_row = null; - $foreign_link = true; - } - } else { - $disp_row = null; - $foreign_link = true; - } - } while (false); - - if ($get_total) { - $the_total = $GLOBALS['dbi']->getTable($foreign_db, $foreign_table) - ->countRecords(true); - } - - $foreignData = array(); - $foreignData['foreign_link'] = $foreign_link; - $foreignData['the_total'] = isset($the_total) ? $the_total : null; - $foreignData['foreign_display'] = ( - isset($foreign_display) ? $foreign_display : null - ); - $foreignData['disp_row'] = isset($disp_row) ? $disp_row : null; - $foreignData['foreign_field'] = isset($foreign_field) ? $foreign_field : null; - - return $foreignData; -} // end of 'PMA_getForeignData()' function - -/** - * Rename a field in relation tables - * - * usually called after a column in a table was renamed - * - * @param string $db database name - * @param string $table table name - * @param string $field old field name - * @param string $new_name new field name - * - * @return void - */ -function PMA_REL_renameField($db, $table, $field, $new_name) -{ - $cfgRelation = PMA_getRelationsParam(); - - if ($cfgRelation['displaywork']) { - $table_query = 'UPDATE ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['table_info']) - . ' SET display_field = \'' . $GLOBALS['dbi']->escapeString( - $new_name - ) . '\'' - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) - . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND display_field = \'' . $GLOBALS['dbi']->escapeString($field) - . '\''; - PMA_queryAsControlUser($table_query); - } - - if ($cfgRelation['relwork']) { - $table_query = 'UPDATE ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' SET master_field = \'' . $GLOBALS['dbi']->escapeString( - $new_name - ) . '\'' - . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) - . '\'' - . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND master_field = \'' . $GLOBALS['dbi']->escapeString($field) - . '\''; - PMA_queryAsControlUser($table_query); - - $table_query = 'UPDATE ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' SET foreign_field = \'' . $GLOBALS['dbi']->escapeString( - $new_name - ) . '\'' - . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) - . '\'' - . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND foreign_field = \'' . $GLOBALS['dbi']->escapeString($field) - . '\''; - PMA_queryAsControlUser($table_query); - - } // end if relwork -} - - -/** - * Performs SQL query used for renaming table. - * - * @param string $table Relation table to use - * @param string $source_db Source database name - * @param string $target_db Target database name - * @param string $source_table Source table name - * @param string $target_table Target table name - * @param string $db_field Name of database field - * @param string $table_field Name of table field - * - * @return void - */ -function PMA_REL_renameSingleTable($table, - $source_db, $target_db, - $source_table, $target_table, - $db_field, $table_field -) { - $query = 'UPDATE ' - . PhpMyAdmin\Util::backquote($GLOBALS['cfgRelation']['db']) . '.' - . PhpMyAdmin\Util::backquote($GLOBALS['cfgRelation'][$table]) - . ' SET ' - . $db_field . ' = \'' . $GLOBALS['dbi']->escapeString($target_db) - . '\', ' - . $table_field . ' = \'' . $GLOBALS['dbi']->escapeString($target_table) - . '\'' - . ' WHERE ' - . $db_field . ' = \'' . $GLOBALS['dbi']->escapeString($source_db) . '\'' - . ' AND ' - . $table_field . ' = \'' . $GLOBALS['dbi']->escapeString($source_table) - . '\''; - PMA_queryAsControlUser($query); -} - - -/** - * Rename a table in relation tables - * - * usually called after table has been moved - * - * @param string $source_db Source database name - * @param string $target_db Target database name - * @param string $source_table Source table name - * @param string $target_table Target table name - * - * @return void - */ -function PMA_REL_renameTable($source_db, $target_db, $source_table, $target_table) -{ - // Move old entries from PMA-DBs to new table - if ($GLOBALS['cfgRelation']['commwork']) { - PMA_REL_renameSingleTable( - 'column_info', - $source_db, $target_db, - $source_table, $target_table, - 'db_name', 'table_name' - ); - } - - // updating bookmarks is not possible since only a single table is - // moved, and not the whole DB. - - if ($GLOBALS['cfgRelation']['displaywork']) { - PMA_REL_renameSingleTable( - 'table_info', - $source_db, $target_db, - $source_table, $target_table, - 'db_name', 'table_name' - ); - } - - if ($GLOBALS['cfgRelation']['relwork']) { - PMA_REL_renameSingleTable( - 'relation', - $source_db, $target_db, - $source_table, $target_table, - 'foreign_db', 'foreign_table' - ); - - PMA_REL_renameSingleTable( - 'relation', - $source_db, $target_db, - $source_table, $target_table, - 'master_db', 'master_table' - ); - } - - if ($GLOBALS['cfgRelation']['pdfwork']) { - if ($source_db == $target_db) { - // rename within the database can be handled - PMA_REL_renameSingleTable( - 'table_coords', - $source_db, $target_db, - $source_table, $target_table, - 'db_name', 'table_name' - ); - } else { - // if the table is moved out of the database we can no loger keep the - // record for table coordinate - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($GLOBALS['cfgRelation']['db']) . "." - . PhpMyAdmin\Util::backquote($GLOBALS['cfgRelation']['table_coords']) - . " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($source_db) . "'" - . " AND table_name = '" . $GLOBALS['dbi']->escapeString($source_table) - . "'"; - PMA_queryAsControlUser($remove_query); - } - } - - if ($GLOBALS['cfgRelation']['uiprefswork']) { - PMA_REL_renameSingleTable( - 'table_uiprefs', - $source_db, $target_db, - $source_table, $target_table, - 'db_name', 'table_name' - ); - } - - if ($GLOBALS['cfgRelation']['navwork']) { - // update hidden items inside table - PMA_REL_renameSingleTable( - 'navigationhiding', - $source_db, $target_db, - $source_table, $target_table, - 'db_name', 'table_name' - ); - - // update data for hidden table - $query = "UPDATE " - . PhpMyAdmin\Util::backquote($GLOBALS['cfgRelation']['db']) . "." - . PhpMyAdmin\Util::backquote( - $GLOBALS['cfgRelation']['navigationhiding'] - ) - . " SET db_name = '" . $GLOBALS['dbi']->escapeString($target_db) - . "'," - . " item_name = '" . $GLOBALS['dbi']->escapeString($target_table) - . "'" - . " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($source_db) - . "'" - . " AND item_name = '" . $GLOBALS['dbi']->escapeString($source_table) - . "'" - . " AND item_type = 'table'"; - PMA_queryAsControlUser($query); - } -} - -/** - * Create a PDF page - * - * @param string $newpage name of the new PDF page - * @param array $cfgRelation Relation configuration - * @param string $db database name - * - * @return int $pdf_page_number - */ -function PMA_REL_createPage($newpage, $cfgRelation, $db) -{ - if (! isset($newpage) || $newpage == '') { - $newpage = __('no description'); - } - $ins_query = 'INSERT INTO ' - . PhpMyAdmin\Util::backquote($GLOBALS['cfgRelation']['db']) . '.' - . PhpMyAdmin\Util::backquote($cfgRelation['pdf_pages']) - . ' (db_name, page_descr)' - . ' VALUES (\'' - . $GLOBALS['dbi']->escapeString($db) . '\', \'' - . $GLOBALS['dbi']->escapeString($newpage) . '\')'; - PMA_queryAsControlUser($ins_query, false); - - return $GLOBALS['dbi']->insertId( - isset($GLOBALS['controllink']) ? $GLOBALS['controllink'] : '' - ); -} - -/** - * Get child table references for a table column. - * This works only if 'DisableIS' is false. An empty array is returned otherwise. - * - * @param string $db name of master table db. - * @param string $table name of master table. - * @param string $column name of master table column. - * - * @return array $child_references - */ -function PMA_getChildReferences($db, $table, $column = '') -{ - $child_references = array(); - if (! $GLOBALS['cfg']['Server']['DisableIS']) { - $rel_query = "SELECT `column_name`, `table_name`," - . " `table_schema`, `referenced_column_name`" - . " FROM `information_schema`.`key_column_usage`" - . " WHERE `referenced_table_name` = '" - . $GLOBALS['dbi']->escapeString($table) . "'" - . " AND `referenced_table_schema` = '" - . $GLOBALS['dbi']->escapeString($db) . "'"; - if ($column) { - $rel_query .= " AND `referenced_column_name` = '" - . $GLOBALS['dbi']->escapeString($column) . "'"; - } - - $child_references = $GLOBALS['dbi']->fetchResult( - $rel_query, array('referenced_column_name', null) - ); - } - return $child_references; -} - -/** - * Check child table references and foreign key for a table column. - * - * @param string $db name of master table db. - * @param string $table name of master table. - * @param string $column name of master table column. - * @param array $foreigners_full foreiners array for the whole table. - * @param array $child_references_full child references for the whole table. - * - * @return array $column_status telling about references if foreign key. - */ -function PMA_checkChildForeignReferences( - $db, $table, $column, $foreigners_full = null, $child_references_full = null -) { - $column_status = array(); - $column_status['isEditable'] = false; - $column_status['isReferenced'] = false; - $column_status['isForeignKey'] = false; - $column_status['references'] = array(); - - $foreigners = array(); - if ($foreigners_full !== null) { - if (isset($foreigners_full[$column])) { - $foreigners[$column] = $foreigners_full[$column]; - } - if (isset($foreigners_full['foreign_keys_data'])) { - $foreigners['foreign_keys_data'] = $foreigners_full['foreign_keys_data']; - } - } else { - $foreigners = PMA_getForeigners($db, $table, $column, 'foreign'); - } - $foreigner = PMA_searchColumnInForeigners($foreigners, $column); - - $child_references = array(); - if ($child_references_full !== null) { - if (isset($child_references_full[$column])) { - $child_references = $child_references_full[$column]; - } - } else { - $child_references = PMA_getChildReferences($db, $table, $column); - } - - if (sizeof($child_references, 0) > 0 - || $foreigner - ) { - if (sizeof($child_references, 0) > 0) { - $column_status['isReferenced'] = true; - foreach ($child_references as $columns) { - array_push( - $column_status['references'], - PhpMyAdmin\Util::backquote($columns['table_schema']) - . '.' . PhpMyAdmin\Util::backquote($columns['table_name']) - ); - } - } - - if ($foreigner) { - $column_status['isForeignKey'] = true; - } - } else { - $column_status['isEditable'] = true; - } - - return $column_status; -} - -/** - * Search a table column in foreign data. - * - * @param array $foreigners Table Foreign data - * @param string $column Column name - * - * @return bool|array - */ -function PMA_searchColumnInForeigners($foreigners, $column) -{ - if (isset($foreigners[$column])) { - return $foreigners[$column]; - } else { - $foreigner = array(); - foreach ($foreigners['foreign_keys_data'] as $one_key) { - $column_index = array_search($column, $one_key['index_list']); - if ($column_index !== false) { - $foreigner['foreign_field'] - = $one_key['ref_index_list'][$column_index]; - $foreigner['foreign_db'] = isset($one_key['ref_db_name']) - ? $one_key['ref_db_name'] - : $GLOBALS['db']; - $foreigner['foreign_table'] = $one_key['ref_table_name']; - $foreigner['constraint'] = $one_key['constraint']; - $foreigner['on_update'] = isset($one_key['on_update']) - ? $one_key['on_update'] - : 'RESTRICT'; - $foreigner['on_delete'] = isset($one_key['on_delete']) - ? $one_key['on_delete'] - : 'RESTRICT'; - - return $foreigner; - } - } - } - - return false; -} - -/** - * Returns default PMA table names and their create queries. - * - * @return array table name, create query - */ -function PMA_getDefaultPMATableNames() -{ - $pma_tables = array(); - $create_tables_file = file_get_contents( - SQL_DIR . 'create_tables.sql' - ); - - $queries = explode(';', $create_tables_file); - - foreach ($queries as $query) { - if (preg_match( - '/CREATE TABLE IF NOT EXISTS `(.*)` \(/', - $query, - $table - ) - ) { - $pma_tables[$table[1]] = $query . ';'; - } - } - - return $pma_tables; -} - -/** - * Create a table named phpmyadmin to be used as configuration storage - * - * @return bool - */ -function PMA_createPMADatabase() -{ - $GLOBALS['dbi']->tryQuery("CREATE DATABASE IF NOT EXISTS `phpmyadmin`"); - if ($error = $GLOBALS['dbi']->getError()) { - if ($GLOBALS['errno'] == 1044) { - $GLOBALS['message'] = __( - 'You do not have necessary privileges to create a database named' - . ' \'phpmyadmin\'. You may go to \'Operations\' tab of any' - . ' database to set up the phpMyAdmin configuration storage there.' - ); - } else { - $GLOBALS['message'] = $error; - } - return false; - } - return true; -} - -/** - * Creates PMA tables in the given db, updates if already exists. - * - * @param string $db database - * @param boolean $create whether to create tables if they don't exist. - * - * @return void - */ -function PMA_fixPMATables($db, $create = true) -{ - $tablesToFeatures = array( - 'pma__bookmark' => 'bookmarktable', - 'pma__relation' => 'relation', - 'pma__table_info' => 'table_info', - 'pma__table_coords' => 'table_coords', - 'pma__pdf_pages' => 'pdf_pages', - 'pma__column_info' => 'column_info', - 'pma__history' => 'history', - 'pma__recent' => 'recent', - 'pma__favorite' => 'favorite', - 'pma__table_uiprefs' => 'table_uiprefs', - 'pma__tracking' => 'tracking', - 'pma__userconfig' => 'userconfig', - 'pma__users' => 'users', - 'pma__usergroups' => 'usergroups', - 'pma__navigationhiding' => 'navigationhiding', - 'pma__savedsearches' => 'savedsearches', - 'pma__central_columns' => 'central_columns', - 'pma__designer_settings' => 'designer_settings', - 'pma__export_templates' => 'export_templates', - ); - - $existingTables = $GLOBALS['dbi']->getTables($db, $GLOBALS['controllink']); - - $createQueries = null; - $foundOne = false; - foreach ($tablesToFeatures as $table => $feature) { - if (! in_array($table, $existingTables)) { - if ($create) { - if ($createQueries == null) { // first create - $createQueries = PMA_getDefaultPMATableNames(); - $GLOBALS['dbi']->selectDb($db); - } - $GLOBALS['dbi']->tryQuery($createQueries[$table]); - if ($error = $GLOBALS['dbi']->getError()) { - $GLOBALS['message'] = $error; - return; - } - $foundOne = true; - $GLOBALS['cfg']['Server'][$feature] = $table; - } - } else { - $foundOne = true; - $GLOBALS['cfg']['Server'][$feature] = $table; - } - } - - if (! $foundOne) { - return; - } - $GLOBALS['cfg']['Server']['pmadb'] = $db; - $_SESSION['relation'][$GLOBALS['server']] = PMA_checkRelationsParam(); - - $cfgRelation = PMA_getRelationsParam(); - if ($cfgRelation['recentwork'] || $cfgRelation['favoritework']) { - // Since configuration storage is updated, we need to - // re-initialize the favorite and recent tables stored in the - // session from the current configuration storage. - if ($cfgRelation['favoritework']) { - $fav_tables = RecentFavoriteTable::getInstance('favorite'); - $_SESSION['tmpval']['favorite_tables'][$GLOBALS['server']] - = $fav_tables->getFromDb(); - } - - if ($cfgRelation['recentwork']) { - $recent_tables = RecentFavoriteTable::getInstance('recent'); - $_SESSION['tmpval']['recent_tables'][$GLOBALS['server']] - = $recent_tables->getFromDb(); - } - - // Reload navi panel to update the recent/favorite lists. - $GLOBALS['reload'] = true; - } -} - -/** - * Get Html for PMA tables fixing anchor. - * - * @param boolean $allTables whether to create all tables - * @param boolean $createDb whether to create the pmadb also - * - * @return string Html - */ -function PMA_getHtmlFixPMATables($allTables, $createDb = false) -{ - $retval = ''; - - $url_query = Url::getCommon(array('db' => $GLOBALS['db'])); - if ($allTables) { - if ($createDb) { - $url_query .= '&goto=db_operations.php&create_pmadb=1'; - $message = Message::notice( - __( - '%sCreate%s a database named \'phpmyadmin\' and setup ' - . 'the phpMyAdmin configuration storage there.' - ) - ); - } else { - $url_query .= '&goto=db_operations.php&fixall_pmadb=1'; - $message = Message::notice( - __( - '%sCreate%s the phpMyAdmin configuration storage in the ' - . 'current database.' - ) - ); - } - } else { - $url_query .= '&goto=db_operations.php&fix_pmadb=1'; - $message = Message::notice( - __('%sCreate%s missing phpMyAdmin configuration storage tables.') - ); - } - $message->addParamHtml('<a href="./chk_rel.php' . $url_query . '">'); - $message->addParamHtml('</a>'); - - $retval .= $message->getDisplay(); - - return $retval; -} - -/** - * Gets the relations info and status, depending on the condition - * - * @param boolean $condition whether to look for foreigners or not - * @param string $db database name - * @param string $table table name - * - * @return array ($res_rel, $have_rel) - */ -function PMA_getRelationsAndStatus($condition, $db, $table) -{ - if ($condition) { - // Find which tables are related with the current one and write it in - // an array - $res_rel = PMA_getForeigners($db, $table); - - if (count($res_rel) > 0) { - $have_rel = true; - } else { - $have_rel = false; - } - } else { - $have_rel = false; - $res_rel = array(); - } // end if - return(array($res_rel, $have_rel)); -} - -/** - * Verifies if all the pmadb tables are defined - * - * @return boolean - */ -function PMA_arePmadbTablesDefined() -{ - if (empty($GLOBALS['cfg']['Server']['bookmarktable']) - || empty($GLOBALS['cfg']['Server']['relation']) - || empty($GLOBALS['cfg']['Server']['table_info']) - || empty($GLOBALS['cfg']['Server']['table_coords']) - || empty($GLOBALS['cfg']['Server']['column_info']) - || empty($GLOBALS['cfg']['Server']['pdf_pages']) - || empty($GLOBALS['cfg']['Server']['history']) - || empty($GLOBALS['cfg']['Server']['recent']) - || empty($GLOBALS['cfg']['Server']['favorite']) - || empty($GLOBALS['cfg']['Server']['table_uiprefs']) - || empty($GLOBALS['cfg']['Server']['tracking']) - || empty($GLOBALS['cfg']['Server']['userconfig']) - || empty($GLOBALS['cfg']['Server']['users']) - || empty($GLOBALS['cfg']['Server']['usergroups']) - || empty($GLOBALS['cfg']['Server']['navigationhiding']) - || empty($GLOBALS['cfg']['Server']['savedsearches']) - || empty($GLOBALS['cfg']['Server']['central_columns']) - || empty($GLOBALS['cfg']['Server']['designer_settings']) - || empty($GLOBALS['cfg']['Server']['export_templates']) - ) { - return false; - } else { - return true; - } -} diff --git a/libraries/relation_cleanup.lib.php b/libraries/relation_cleanup.lib.php index 1cb5bf2dc8..54290dc811 100644 --- a/libraries/relation_cleanup.lib.php +++ b/libraries/relation_cleanup.lib.php @@ -6,6 +6,8 @@ * @package PhpMyAdmin */ +use PhpMyAdmin\Relation; + /** * Cleanup column related relation stuff * @@ -17,7 +19,7 @@ */ function PMA_relationsCleanupColumn($db, $table, $column) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['commwork']) { $remove_query = 'DELETE FROM ' @@ -28,7 +30,7 @@ function PMA_relationsCleanupColumn($db, $table, $column) . '\'' . ' AND column_name = \'' . $GLOBALS['dbi']->escapeString($column) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['displaywork']) { @@ -40,7 +42,7 @@ function PMA_relationsCleanupColumn($db, $table, $column) . '\'' . ' AND display_field = \'' . $GLOBALS['dbi']->escapeString($column) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['relwork']) { @@ -53,7 +55,7 @@ function PMA_relationsCleanupColumn($db, $table, $column) . '\'' . ' AND master_field = \'' . $GLOBALS['dbi']->escapeString($column) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); $remove_query = 'DELETE FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) @@ -64,7 +66,7 @@ function PMA_relationsCleanupColumn($db, $table, $column) . '\'' . ' AND foreign_field = \'' . $GLOBALS['dbi']->escapeString($column) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } } @@ -78,7 +80,7 @@ function PMA_relationsCleanupColumn($db, $table, $column) */ function PMA_relationsCleanupTable($db, $table) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['commwork']) { $remove_query = 'DELETE FROM ' @@ -87,7 +89,7 @@ function PMA_relationsCleanupTable($db, $table) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['displaywork']) { @@ -97,7 +99,7 @@ function PMA_relationsCleanupTable($db, $table) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['pdfwork']) { @@ -107,7 +109,7 @@ function PMA_relationsCleanupTable($db, $table) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['relwork']) { @@ -118,7 +120,7 @@ function PMA_relationsCleanupTable($db, $table) . '\'' . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); $remove_query = 'DELETE FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) @@ -127,7 +129,7 @@ function PMA_relationsCleanupTable($db, $table) . '\'' . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['uiprefswork']) { @@ -137,7 +139,7 @@ function PMA_relationsCleanupTable($db, $table) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['navwork']) { @@ -150,7 +152,7 @@ function PMA_relationsCleanupTable($db, $table) . ' OR (item_name = \'' . $GLOBALS['dbi']->escapeString($table) . '\'' . ' AND item_type = \'table\'))'; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } } @@ -163,14 +165,14 @@ function PMA_relationsCleanupTable($db, $table) */ function PMA_relationsCleanupDatabase($db) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['commwork']) { $remove_query = 'DELETE FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['bookmarkwork']) { @@ -178,7 +180,7 @@ function PMA_relationsCleanupDatabase($db) . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['bookmark']) . ' WHERE dbase = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['displaywork']) { @@ -186,7 +188,7 @@ function PMA_relationsCleanupDatabase($db) . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_info']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['pdfwork']) { @@ -194,13 +196,13 @@ function PMA_relationsCleanupDatabase($db) . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); $remove_query = 'DELETE FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['relwork']) { @@ -209,14 +211,14 @@ function PMA_relationsCleanupDatabase($db) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); $remove_query = 'DELETE FROM ' . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['uiprefswork']) { @@ -224,7 +226,7 @@ function PMA_relationsCleanupDatabase($db) . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_uiprefs']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['navwork']) { @@ -232,7 +234,7 @@ function PMA_relationsCleanupDatabase($db) . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['navigationhiding']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['savedsearcheswork']) { @@ -240,7 +242,7 @@ function PMA_relationsCleanupDatabase($db) . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['savedsearches']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['centralcolumnswork']) { @@ -248,7 +250,7 @@ function PMA_relationsCleanupDatabase($db) . PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.' . PhpMyAdmin\Util::backquote($cfgRelation['central_columns']) . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } } @@ -261,7 +263,7 @@ function PMA_relationsCleanupDatabase($db) */ function PMA_relationsCleanupUser($username) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['bookmarkwork']) { $remove_query = "DELETE FROM " @@ -269,7 +271,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['bookmark']) . " WHERE `user` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['historywork']) { @@ -278,7 +280,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['history']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['recentwork']) { @@ -287,7 +289,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['recent']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['favoritework']) { @@ -296,7 +298,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['favorite']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['uiprefswork']) { @@ -305,7 +307,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['table_uiprefs']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['userconfigwork']) { @@ -314,7 +316,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['userconfig']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['menuswork']) { @@ -323,7 +325,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['users']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['navwork']) { @@ -332,7 +334,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['navigationhiding']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['savedsearcheswork']) { @@ -341,7 +343,7 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['savedsearches']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } if ($cfgRelation['designersettingswork']) { @@ -350,7 +352,6 @@ function PMA_relationsCleanupUser($username) . "." . PhpMyAdmin\Util::backquote($cfgRelation['designer_settings']) . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - PMA_queryAsControlUser($remove_query); + Relation::queryAsControlUser($remove_query); } } - diff --git a/libraries/server_user_groups.lib.php b/libraries/server_user_groups.lib.php index 5030b94e83..0e353d52af 100644 --- a/libraries/server_user_groups.lib.php +++ b/libraries/server_user_groups.lib.php @@ -5,6 +5,7 @@ * * @package PhpMyAdmin */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; /** @@ -20,13 +21,13 @@ function PMA_getHtmlForListingUsersofAGroup($userGroup) . sprintf(__('Users of \'%s\' user group'), htmlspecialchars($userGroup)) . '</h2>'; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $usersTable = PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['users']); $sql_query = "SELECT `username` FROM " . $usersTable . " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup) . "'"; - $result = PMA_queryAsControlUser($sql_query, false); + $result = Relation::queryAsControlUser($sql_query, false); if ($result) { if ($GLOBALS['dbi']->numRows($result) == 0) { $html_output .= '<p>' @@ -60,11 +61,11 @@ function PMA_getHtmlForListingUsersofAGroup($userGroup) function PMA_getHtmlForUserGroupsTable() { $html_output = '<h2>' . __('User groups') . '</h2>'; - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $groupTable = PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['usergroups']); $sql_query = "SELECT * FROM " . $groupTable . " ORDER BY `usergroup` ASC"; - $result = PMA_queryAsControlUser($sql_query, false); + $result = Relation::queryAsControlUser($sql_query, false); if ($result && $GLOBALS['dbi']->numRows($result)) { $html_output .= '<form name="userGroupsForm" id="userGroupsForm"' @@ -178,7 +179,7 @@ function _getAllowedTabNames($row, $level) */ function PMA_deleteUserGroup($userGroup) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $userTable = PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['users']); $groupTable = PhpMyAdmin\Util::backquote($cfgRelation['db']) @@ -186,11 +187,11 @@ function PMA_deleteUserGroup($userGroup) $sql_query = "DELETE FROM " . $userTable . " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup) . "'"; - PMA_queryAsControlUser($sql_query, true); + Relation::queryAsControlUser($sql_query, true); $sql_query = "DELETE FROM " . $groupTable . " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup) . "'"; - PMA_queryAsControlUser($sql_query, true); + Relation::queryAsControlUser($sql_query, true); } /** @@ -242,13 +243,13 @@ function PMA_getHtmlToEditUserGroup($userGroup = null) 'table' => array() ); if ($userGroup != null) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $groupTable = PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['usergroups']); $sql_query = "SELECT * FROM " . $groupTable . " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup) . "'"; - $result = PMA_queryAsControlUser($sql_query, false); + $result = Relation::queryAsControlUser($sql_query, false); if ($result) { while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { $key = $row['tab']; @@ -327,7 +328,7 @@ function _getTabList($title, $level, $selected) function PMA_editUserGroup($userGroup, $new = false) { $tabs = PhpMyAdmin\Util::getMenuTabList(); - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $groupTable = PhpMyAdmin\Util::backquote($cfgRelation['db']) . "." . PhpMyAdmin\Util::backquote($cfgRelation['usergroups']); @@ -335,7 +336,7 @@ function PMA_editUserGroup($userGroup, $new = false) $sql_query = "DELETE FROM " . $groupTable . " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup) . "';"; - PMA_queryAsControlUser($sql_query, true); + Relation::queryAsControlUser($sql_query, true); } $sql_query = "INSERT INTO " . $groupTable @@ -355,5 +356,5 @@ function PMA_editUserGroup($userGroup, $new = false) } } $sql_query .= ";"; - PMA_queryAsControlUser($sql_query, true); + Relation::queryAsControlUser($sql_query, true); } diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 249a08ddd2..d2620aac00 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -8,6 +8,7 @@ */ use PhpMyAdmin\Di\Container; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Table; use PhpMyAdmin\Template; @@ -85,9 +86,9 @@ if (isset($selected) && is_array($selected)) { $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php'); -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); -$comments_map = PMA_getComments($db, $table); +$comments_map = Relation::getComments($db, $table); $move_columns = array(); if (isset($fields_meta)) { @@ -117,12 +118,12 @@ if (isset($_REQUEST['submit_num_fields']) $regenerate = 1; } -$foreigners = PMA_getForeigners($db, $table, '', 'foreign'); +$foreigners = Relation::getForeigners($db, $table, '', 'foreign'); $child_references = null; // From MySQL 5.6.6 onwards columns with foreign keys can be renamed. // Hence, no need to get child references if ($GLOBALS['dbi']->getVersion() < 50606) { - $child_references = PMA_getChildReferences($db, $table); + $child_references = Relation::getChildReferences($db, $table); } for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { @@ -285,7 +286,7 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { && isset($form_params['table']) && $GLOBALS['dbi']->getVersion() < 50606 ) { - $columnMeta['column_status'] = PMA_checkChildForeignReferences( + $columnMeta['column_status'] = Relation::checkChildForeignReferences( $form_params['db'], $form_params['table'], $columnMeta['Field'], diff --git a/libraries/user_preferences.inc.php b/libraries/user_preferences.inc.php index e6c470ba97..581a81cca6 100644 --- a/libraries/user_preferences.inc.php +++ b/libraries/user_preferences.inc.php @@ -6,6 +6,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Sanitize; if (!defined('PHPMYADMIN')) { @@ -51,28 +52,13 @@ echo PhpMyAdmin\Template::get('list/unordered')->render( ); echo '<div class="clearfloat"></div>'; - // show "configuration saved" message and reload navigation panel if needed if (!empty($_GET['saved'])) { Message::rawSuccess(__('Configuration has been saved.'))->display(); } -/* debug code -$arr = $cf->getConfigArray(); -$arr2 = array(); -foreach ($arr as $k => $v) { - $arr2[] = "<b>$k</b> " . var_export($v, true); -} -$arr2 = implode(', ', $arr2); -$arr2 .= '<br />Blacklist: ' . (empty($cfg['UserprefsDisallow']) - ? '<i>empty</i>' - : implode(', ', $cfg['UserprefsDisallow'])); -$msg = Message::notice('Settings: ' . $arr2); -$msg->display(); -//*/ - // warn about using session storage for settings -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['userconfigwork']) { $msg = __( 'Your preferences will be saved for current session only. Storing them ' diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php index 7a73778e4c..efe305c570 100644 --- a/libraries/user_preferences.lib.php +++ b/libraries/user_preferences.lib.php @@ -8,6 +8,7 @@ use PhpMyAdmin\Config\ConfigFile; use PhpMyAdmin\Core; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Url; if (! defined('PHPMYADMIN')) { @@ -47,7 +48,7 @@ function PMA_userprefsPageInit(ConfigFile $cf) */ function PMA_loadUserprefs() { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); if (! $cfgRelation['userconfigwork']) { // no pmadb table, use session storage if (! isset($_SESSION['userconfig'])) { @@ -85,7 +86,7 @@ function PMA_loadUserprefs() */ function PMA_saveUserprefs(array $config_array) { - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = Relation::getRelationsParam(); $server = isset($GLOBALS['server']) ? $GLOBALS['server'] : $GLOBALS['cfg']['ServerDefault']; diff --git a/navigation.php b/navigation.php index 73add27fd9..e67c600927 100644 --- a/navigation.php +++ b/navigation.php @@ -7,9 +7,10 @@ */ // Include common functionalities -use PhpMyAdmin\Response; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Navigation\Navigation; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Response; require_once './libraries/common.inc.php'; @@ -30,7 +31,7 @@ if (isset($_REQUEST['getNaviSettings']) && $_REQUEST['getNaviSettings']) { exit(); } -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); if ($cfgRelation['navwork']) { if (isset($_REQUEST['hideNavItem'])) { if (! empty($_REQUEST['itemName']) diff --git a/schema_export.php b/schema_export.php index c223552efd..040768dd2b 100644 --- a/schema_export.php +++ b/schema_export.php @@ -8,6 +8,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Plugins\SchemaPlugin; +use PhpMyAdmin\Relation; /** * Gets some core libraries @@ -18,7 +19,7 @@ require_once 'libraries/common.inc.php'; * get all variables needed for exporting relational schema * in $cfgRelation */ -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); require_once 'libraries/pmd_common.php'; require_once 'libraries/plugin_interface.lib.php'; diff --git a/server_privileges.php b/server_privileges.php index 9e803c6033..23022a72b5 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -8,6 +8,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Privileges; @@ -22,7 +23,7 @@ require_once 'libraries/common.inc.php'; require_once 'libraries/display_change_password.lib.php'; require_once 'libraries/check_user_privileges.lib.php'; -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); /** * Does the common work diff --git a/server_user_groups.php b/server_user_groups.php index ac80fad3f8..4f669ca5e9 100644 --- a/server_user_groups.php +++ b/server_user_groups.php @@ -5,13 +5,14 @@ * * @package PhpMyAdmin */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; require_once 'libraries/common.inc.php'; require_once 'libraries/server_users.lib.php'; require_once 'libraries/server_user_groups.lib.php'; -PMA_getRelationsParam(); +Relation::getRelationsParam(); if (! $GLOBALS['cfgRelation']['menuswork']) { exit; } diff --git a/tbl_change.php b/tbl_change.php index 13c95e63e0..fcd71bf589 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -7,6 +7,7 @@ */ use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\InsertEdit; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Util; use PhpMyAdmin\Url; @@ -92,7 +93,7 @@ if (! empty($disp_message)) { $table_columns = InsertEdit::getTableColumns($db, $table); // retrieve keys into foreign fields, if any -$foreigners = PMA_getForeigners($db, $table); +$foreigners = Relation::getForeigners($db, $table); // Retrieve form parameters for insert/edit form $_form_params = InsertEdit::getFormParametersForInsertForm( diff --git a/tbl_export.php b/tbl_export.php index 7b5e31d449..ee22273070 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -6,6 +6,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; /** @@ -24,7 +25,7 @@ $scripts = $header->getScripts(); $scripts->addFile('export.js'); // Get the relation settings -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); // handling export template actions if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) { diff --git a/tbl_operations.php b/tbl_operations.php index c6b0f8046c..9738fb262d 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -9,6 +9,7 @@ use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Partition; use PhpMyAdmin\Operations; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Table; use PhpMyAdmin\Util; @@ -43,10 +44,10 @@ $url_params['goto'] = $url_params['back'] = 'tbl_operations.php'; /** * Gets relation settings */ -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); // reselect current db (needed in some cases probably due to -// the calling of relation.lib.php) +// the calling of PhpMyAdmin\Relation) $GLOBALS['dbi']->selectDb($GLOBALS['db']); /** @@ -457,7 +458,7 @@ unset($partition_names); if ($cfgRelation['relwork'] && ! $pma_table->isEngine("INNODB")) { $GLOBALS['dbi']->selectDb($GLOBALS['db']); - $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'internal'); + $foreign = Relation::getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'internal'); if (! empty($foreign)) { $response->addHTML( diff --git a/tbl_relation.php b/tbl_relation.php index 1782198563..33d1cc61a5 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -16,6 +16,7 @@ use PhpMyAdmin\Controllers\Table\TableRelationController; use PhpMyAdmin\Di\Container; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Table; use PhpMyAdmin\Util; @@ -41,7 +42,7 @@ $options_array = array( 'NO_ACTION' => 'NO ACTION', 'RESTRICT' => 'RESTRICT', ); -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); $tbl_storage_engine = mb_strtoupper( $dbi->getTable($db, $table)->getStatusInfo('Engine') ); @@ -54,17 +55,17 @@ $dependency_definitions = array( "upd_query" => $upd_query ); if ($cfgRelation['relwork']) { - $dependency_definitions['existrel'] = PMA_getForeigners( + $dependency_definitions['existrel'] = Relation::getForeigners( $db, $table, '', 'internal' ); } if (Util::isForeignKeySupported($tbl_storage_engine)) { - $dependency_definitions['existrel_foreign'] = PMA_getForeigners( + $dependency_definitions['existrel_foreign'] = Relation::getForeigners( $db, $table, '', 'foreign' ); } if ($cfgRelation['displaywork']) { - $dependency_definitions['disp'] = PMA_getDisplayField($db, $table); + $dependency_definitions['disp'] = Relation::getDisplayField($db, $table); } else { $dependency_definitions['disp'] = 'asas'; } diff --git a/tbl_replace.php b/tbl_replace.php index 404ec9366f..533064d188 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -15,6 +15,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\InsertEdit; use PhpMyAdmin\Plugins\IOTransformationsPlugin; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Table; use PhpMyAdmin\Transformations; @@ -381,7 +382,7 @@ if ($response->isAjax() && ! isset($_POST['ajax_page_request'])) { if (isset($_REQUEST['rel_fields_list']) && $_REQUEST['rel_fields_list'] != '') { - $map = PMA_getForeigners($db, $table, '', 'both'); + $map = Relation::getForeigners($db, $table, '', 'both'); $relation_fields = array(); parse_str($_REQUEST['rel_fields_list'], $relation_fields); diff --git a/templates/database/designer/database_tables.phtml b/templates/database/designer/database_tables.phtml index 01969741d5..f7ff9f0d56 100644 --- a/templates/database/designer/database_tables.phtml +++ b/templates/database/designer/database_tables.phtml @@ -54,7 +54,7 @@ </tr> </thead> <tbody id="id_tbody_<?= $t_n_url; ?>" style="<?= (isset($tab_pos[$t_n]) && empty($tab_pos[$t_n]["V"])) ? 'display: none' : ''; ?>"> - <?php $display_field = PMA_getDisplayField( + <?php $display_field = PhpMyAdmin\Relation::getDisplayField( $_GET['db'], $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i] ); diff --git a/templates/database/designer/edit_delete_pages.phtml b/templates/database/designer/edit_delete_pages.phtml index 356bf7b839..a30f9b881e 100644 --- a/templates/database/designer/edit_delete_pages.phtml +++ b/templates/database/designer/edit_delete_pages.phtml @@ -1,4 +1,4 @@ -<?php $cfgRelation = PMA_getRelationsParam(); ?> +<?php $cfgRelation = PhpMyAdmin\Relation::getRelationsParam(); ?> <form action="db_designer.php" method="post" name="edit_delete_pages" id="edit_delete_pages" class="ajax"> <?= PhpMyAdmin\Url::getHiddenInputs($db); ?> <fieldset id="page_edit_delete_options"> diff --git a/templates/database/designer/js_fields.phtml b/templates/database/designer/js_fields.phtml index a8c069f90c..45bd07b883 100644 --- a/templates/database/designer/js_fields.phtml +++ b/templates/database/designer/js_fields.phtml @@ -1,4 +1,4 @@ -<?php $cfgRelation = PMA_getRelationsParam(); ?> +<?php $cfgRelation = PhpMyAdmin\Relation::getRelationsParam(); ?> <!-- Do not expand HTML here, invisible characters will make javascript crash --> <div id="script_server" class="hide"><?= htmlspecialchars($GLOBALS['server']); ?></div> <div id="script_db" class="hide"><?= htmlspecialchars($_GET['db']); ?></div> diff --git a/templates/database/designer/page_save_as.phtml b/templates/database/designer/page_save_as.phtml index 4bd1473100..c50d301498 100644 --- a/templates/database/designer/page_save_as.phtml +++ b/templates/database/designer/page_save_as.phtml @@ -1,5 +1,5 @@ <?php -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = PhpMyAdmin\Relation::getRelationsParam(); $choices = array( 'same' => __('Save to selected page'), 'new' => __('Create a page and save to it') diff --git a/templates/table/relation/common_form.phtml b/templates/table/relation/common_form.phtml index 0cdc8095b4..1e3a4a477b 100644 --- a/templates/table/relation/common_form.phtml +++ b/templates/table/relation/common_form.phtml @@ -151,7 +151,7 @@ <?php if ($cfgRelation['displaywork']): ?> <?php $save_row = array_values($columns);?> - <?php $disp = PMA_getDisplayField($db, $table); ?> + <?php $disp = PhpMyAdmin\Relation::getDisplayField($db, $table); ?> <fieldset> <label><?= __('Choose column to display:'); ?></label> <select name="display_field"> diff --git a/templates/table/search/input_box.phtml b/templates/table/search/input_box.phtml index 302cc4e5b9..6af9e46b34 100644 --- a/templates/table/search/input_box.phtml +++ b/templates/table/search/input_box.phtml @@ -2,11 +2,11 @@ // Get inputbox based on different column types // (Foreign key, geometrical, enum) if ($_foreigners - && PMA_searchColumnInForeigners($_foreigners, $column_name)): ?> + && PhpMyAdmin\Relation::searchColumnInForeigners($_foreigners, $column_name)): ?> <?php if (is_array($foreignData['disp_row'])): ?> <select name="criteriaValues[<?= $column_index; ?>]" id="<?= $column_id , $column_index ?>"> - <?= PMA_foreignDropdown( + <?= PhpMyAdmin\Relation::foreignDropdown( $foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], '', $foreignMaxLimit ) ?> diff --git a/templates/table/search/zoom_result_form.phtml b/templates/table/search/zoom_result_form.phtml index 66f737a616..73c9a41bb3 100644 --- a/templates/table/search/zoom_result_form.phtml +++ b/templates/table/search/zoom_result_form.phtml @@ -42,7 +42,7 @@ $column_index++ ): ?> <?php - $foreignData = PMA_getForeignData( + $foreignData = PhpMyAdmin\Relation::getForeignData( $_foreigners, $_columnNames[$column_index], false, @@ -57,7 +57,7 @@ ): ?> <?php $fieldpopup = $_columnNames[$column_index]; - $foreignData = PMA_getForeignData($_foreigners, $fieldpopup, false, '', '' );?> + $foreignData = PhpMyAdmin\Relation::getForeignData($_foreigners, $fieldpopup, false, '', '' );?> <tr class="noclick"> <!-- Display column Names --> <th><?= htmlspecialchars($_columnNames[$column_index]); ?></th> diff --git a/test/classes/BookmarkTest.php b/test/classes/BookmarkTest.php index a27b656156..621f7c4e7c 100644 --- a/test/classes/BookmarkTest.php +++ b/test/classes/BookmarkTest.php @@ -8,7 +8,6 @@ use PhpMyAdmin\Bookmark; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; /** * Tests for Bookmark class diff --git a/test/classes/ConfigTest.php b/test/classes/ConfigTest.php index d29a1e5020..b77f117c7e 100644 --- a/test/classes/ConfigTest.php +++ b/test/classes/ConfigTest.php @@ -12,7 +12,6 @@ */ use PhpMyAdmin\Theme; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/DbQbeTest.php b/test/classes/DbQbeTest.php index e758d44063..6580e7f934 100644 --- a/test/classes/DbQbeTest.php +++ b/test/classes/DbQbeTest.php @@ -10,7 +10,6 @@ */ require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; use PhpMyAdmin\DbQbe; diff --git a/test/classes/DisplayResultsTest.php b/test/classes/DisplayResultsTest.php index de06036a78..6bdf56fbbf 100644 --- a/test/classes/DisplayResultsTest.php +++ b/test/classes/DisplayResultsTest.php @@ -12,7 +12,6 @@ use PhpMyAdmin\Core; use PhpMyAdmin\DisplayResults; use PhpMyAdmin\Plugins\Transformations\Text_Plain_Link; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/FooterTest.php b/test/classes/FooterTest.php index e1e4fdd49e..92f66a327b 100644 --- a/test/classes/FooterTest.php +++ b/test/classes/FooterTest.php @@ -14,7 +14,6 @@ use PhpMyAdmin\ErrorHandler; use PhpMyAdmin\Footer; use PhpMyAdmin\Theme; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/HeaderTest.php b/test/classes/HeaderTest.php index 1d4ea70a42..39c556879a 100644 --- a/test/classes/HeaderTest.php +++ b/test/classes/HeaderTest.php @@ -12,7 +12,6 @@ use PhpMyAdmin\Header; use PhpMyAdmin\Theme; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index a034363b31..a018eeac6e 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -20,7 +20,6 @@ use ReflectionProperty; use stdClass; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; /** * Tests for PhpMyAdmin\InsertEdit diff --git a/test/classes/ListDatabaseTest.php b/test/classes/ListDatabaseTest.php index c3d80fe9ce..d3b1485211 100644 --- a/test/classes/ListDatabaseTest.php +++ b/test/classes/ListDatabaseTest.php @@ -13,7 +13,6 @@ $GLOBALS['cfg']['Server']['DisableIS'] = false; /* * Include to test. */ -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/MenuTest.php b/test/classes/MenuTest.php index c1ae0315ef..637f558a9f 100644 --- a/test/classes/MenuTest.php +++ b/test/classes/MenuTest.php @@ -14,7 +14,6 @@ use PhpMyAdmin\Menu; use PhpMyAdmin\Theme; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/OperationsTest.php b/test/classes/OperationsTest.php index 159c67ed64..2fd62bed1b 100644 --- a/test/classes/OperationsTest.php +++ b/test/classes/OperationsTest.php @@ -10,7 +10,6 @@ namespace PhpMyAdmin\Tests; use PhpMyAdmin\Operations; use PhpMyAdmin\Theme; -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; /** diff --git a/test/libraries/PMA_relation_test.php b/test/classes/RelationTest.php index fa1e063ace..0546948cb0 100644 --- a/test/libraries/PMA_relation_test.php +++ b/test/classes/RelationTest.php @@ -1,29 +1,24 @@ <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * tests for relation.lib.php + * tests for PhpMyAdmin\Relation * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin\Tests; -/* - * Include to test. - */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Theme; - - require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; - /** - * Tests for libraries/relation.lib.php + * Tests for PhpMyAdmin\Relation * * @package PhpMyAdmin-test * @group medium */ -class PMA_Relation_Test extends PHPUnit_Framework_TestCase +class RelationTest extends \PHPUnit_Framework_TestCase { /** * Sets up the fixture, for example, opens a network connection. @@ -45,12 +40,10 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $GLOBALS['pmaThemePath'] = $GLOBALS['PMA_Theme']->getPath(); $GLOBALS['cfg']['ServerDefault'] = 0; - - include_once 'libraries/relation.lib.php'; } /** - * Test for PMA_queryAsControlUser + * Test for Relation::queryAsControlUser * * @return void */ @@ -73,22 +66,22 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $sql = "insert into PMA_bookmark A,B values(1, 2)"; $this->assertEquals( 'executeResult1', - PMA_queryAsControlUser($sql) + Relation::queryAsControlUser($sql) ); $this->assertEquals( 'executeResult2', - PMA_queryAsControlUser($sql, false) + Relation::queryAsControlUser($sql, false) ); } /** - * Test for PMA_getRelationsParam & PMA_getRelationsParamDiagnostic + * Test for Relation::getRelationsParam & Relation::getRelationsParamDiagnostic * * @return void */ public function testPMAGetRelationsParam() { - $relationsPara = PMA_getRelationsParam(); + $relationsPara = Relation::getRelationsParam(); $this->assertEquals( false, $relationsPara['relwork'] @@ -106,7 +99,7 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $relationsPara['db'] ); - $retval = PMA_getRelationsParamDiagnostic($relationsPara); + $retval = Relation::getRelationsParamDiagnostic($relationsPara); //check $cfg['Servers'][$i]['pmadb'] $this->assertContains( "\$cfg['Servers'][\$i]['pmadb']", @@ -153,7 +146,7 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase ); $relationsPara['db'] = false; - $retval = PMA_getRelationsParamDiagnostic($relationsPara); + $retval = Relation::getRelationsParamDiagnostic($relationsPara); $result = __('General relation features'); $this->assertContains( @@ -173,7 +166,7 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getDisplayField + * Test for Relation::getDisplayField * * @return void */ @@ -183,27 +176,27 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $table = 'CHARACTER_SETS'; $this->assertEquals( 'DESCRIPTION', - PMA_getDisplayField($db, $table) + Relation::getDisplayField($db, $table) ); $db = 'information_schema'; $table = 'TABLES'; $this->assertEquals( 'TABLE_COMMENT', - PMA_getDisplayField($db, $table) + Relation::getDisplayField($db, $table) ); $db = 'information_schema'; $table = 'PMA'; $this->assertEquals( false, - PMA_getDisplayField($db, $table) + Relation::getDisplayField($db, $table) ); } /** - * Test for PMA_getComments + * Test for Relation::getComments * * @return void */ @@ -236,7 +229,7 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $db = 'information_schema'; $this->assertEquals( array(''), - PMA_getComments($db) + Relation::getComments($db) ); $db = 'information_schema'; @@ -246,12 +239,12 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase 'field1' => 'Comment1', 'field2' => 'Comment1' ), - PMA_getComments($db, $table) + Relation::getComments($db, $table) ); } /** - * Test for PMA_tryUpgradeTransformations + * Test for Relation::tryUpgradeTransformations * * @return void */ @@ -275,14 +268,14 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['Server']['column_info'] = 'column_info'; // Case 1 - $actual = PMA_tryUpgradeTransformations(); + $actual = Relation::tryUpgradeTransformations(); $this->assertEquals( false, $actual ); // Case 2 - $actual = PMA_tryUpgradeTransformations(); + $actual = Relation::tryUpgradeTransformations(); $this->assertEquals( true, $actual @@ -290,7 +283,7 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_searchColumnInForeigners + * Test for Relation::searchColumnInForeigners * * @return void */ @@ -316,7 +309,7 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase ) ); - $foreigner = PMA_searchColumnInForeigners($foreigners, 'id'); + $foreigner = Relation::searchColumnInForeigners($foreigners, 'id'); $expected = array(); $expected['foreign_field'] = 'id'; $expected['foreign_db'] = 'GSoC14'; diff --git a/test/classes/Server/PrivilegesTest.php b/test/classes/Server/PrivilegesTest.php index a778be7702..db013b0d46 100644 --- a/test/classes/Server/PrivilegesTest.php +++ b/test/classes/Server/PrivilegesTest.php @@ -15,7 +15,6 @@ use PhpMyAdmin\Url; use PhpMyAdmin\Util; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'libraries/relation_cleanup.lib.php'; /** diff --git a/test/classes/TableTest.php b/test/classes/TableTest.php index 30b523e176..2a72363da0 100644 --- a/test/classes/TableTest.php +++ b/test/classes/TableTest.php @@ -9,12 +9,12 @@ /* * Include to test. */ +use PhpMyAdmin\Relation; use PhpMyAdmin\Table; use PhpMyAdmin\Theme; use PhpMyAdmin\Util; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** @@ -44,7 +44,7 @@ class TableTest extends PMATestCase $GLOBALS['sql_drop_table'] = true; $GLOBALS['cfg']['Server']['table_uiprefs'] = "pma__table_uiprefs"; - $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); + $GLOBALS['cfgRelation'] = Relation::getRelationsParam(); $GLOBALS['dblist'] = new DataBasePMAMock(); $GLOBALS['dblist']->databases = new DataBaseMock(); diff --git a/test/classes/TrackerTest.php b/test/classes/TrackerTest.php index a1622f04c3..da260ef2f8 100644 --- a/test/classes/TrackerTest.php +++ b/test/classes/TrackerTest.php @@ -13,7 +13,6 @@ use PhpMyAdmin\Tracker; use PhpMyAdmin\Util; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/TrackingTest.php b/test/classes/TrackingTest.php index 55d68f97e0..fbe0a7fc1e 100644 --- a/test/classes/TrackingTest.php +++ b/test/classes/TrackingTest.php @@ -12,7 +12,6 @@ use PhpMyAdmin\Tracking; use PhpMyAdmin\Url; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; /** * Tests for PhpMyAdmin\Tracking diff --git a/test/classes/TransformationsTest.php b/test/classes/TransformationsTest.php index 71efa5779e..ea35c1947f 100644 --- a/test/classes/TransformationsTest.php +++ b/test/classes/TransformationsTest.php @@ -13,7 +13,6 @@ use PhpMyAdmin\Transformations; * Include to test. */ require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; /** * tests for transformation wrappers diff --git a/test/classes/controllers/TableIndexesControllerTest.php b/test/classes/controllers/TableIndexesControllerTest.php index 028de7d8d4..1b4fd0f2f9 100644 --- a/test/classes/controllers/TableIndexesControllerTest.php +++ b/test/classes/controllers/TableIndexesControllerTest.php @@ -17,7 +17,6 @@ use PhpMyAdmin\Url; * Include to test. */ require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/controllers/TableRelationControllerTest.php b/test/classes/controllers/TableRelationControllerTest.php index 427e6e941c..4dd4fcd54d 100644 --- a/test/classes/controllers/TableRelationControllerTest.php +++ b/test/classes/controllers/TableRelationControllerTest.php @@ -14,7 +14,6 @@ use PhpMyAdmin\Tests\Stubs\Response as ResponseStub; use PhpMyAdmin\Theme; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/controllers/TableSearchControllerTest.php b/test/classes/controllers/TableSearchControllerTest.php index 53c4870b10..09c08caa75 100644 --- a/test/classes/controllers/TableSearchControllerTest.php +++ b/test/classes/controllers/TableSearchControllerTest.php @@ -11,6 +11,7 @@ */ use PhpMyAdmin\Controllers\Table\TableSearchController; use PhpMyAdmin\Di\Container; +use PhpMyAdmin\Relation; use PhpMyAdmin\Tests\Stubs\Response as ResponseStub; use PhpMyAdmin\Theme; use PhpMyAdmin\TypesMySQL; @@ -44,7 +45,7 @@ class TableSearchControllerTest extends PMATestCase $GLOBALS['server'] = 1; $GLOBALS['PMA_PHP_SELF'] = 'index.php'; - $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); + $GLOBALS['cfgRelation'] = Relation::getRelationsParam(); $GLOBALS['PMA_Types'] = new TypesMySQL(); $GLOBALS['cfg']['Server']['DisableIS'] = false; diff --git a/test/classes/dbi/DbiMysqlTest.php b/test/classes/dbi/DbiMysqlTest.php index cf5ac49a68..9148de4aea 100644 --- a/test/classes/dbi/DbiMysqlTest.php +++ b/test/classes/dbi/DbiMysqlTest.php @@ -11,7 +11,6 @@ use PhpMyAdmin\Dbi\DbiMysql; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; require_once 'libraries/database_interface.inc.php'; diff --git a/test/classes/dbi/DbiMysqliTest.php b/test/classes/dbi/DbiMysqliTest.php index 14cea6208e..5446ab92fd 100644 --- a/test/classes/dbi/DbiMysqliTest.php +++ b/test/classes/dbi/DbiMysqliTest.php @@ -11,7 +11,6 @@ use PhpMyAdmin\Dbi\DbiMysqli; use PhpMyAdmin\Theme; -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'test/PMATestCase.php'; diff --git a/test/classes/navigation/NavigationTest.php b/test/classes/navigation/NavigationTest.php index 4e5b6ba155..fce13f76f2 100644 --- a/test/classes/navigation/NavigationTest.php +++ b/test/classes/navigation/NavigationTest.php @@ -10,7 +10,6 @@ use PhpMyAdmin\Theme; use PhpMyAdmin\Url; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/navigation/NavigationTreeTest.php b/test/classes/navigation/NavigationTreeTest.php index 2a0c125c6a..3de803fb09 100644 --- a/test/classes/navigation/NavigationTreeTest.php +++ b/test/classes/navigation/NavigationTreeTest.php @@ -17,7 +17,6 @@ $GLOBALS['server'] = 0; $GLOBALS['cfg']['Server']['DisableIS'] = false; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'libraries/check_user_privileges.lib.php'; require_once 'test/PMATestCase.php'; diff --git a/test/classes/navigation/NodeDatabaseChildTest.php b/test/classes/navigation/NodeDatabaseChildTest.php index 8d4865a4af..2a60a25a5d 100644 --- a/test/classes/navigation/NodeDatabaseChildTest.php +++ b/test/classes/navigation/NodeDatabaseChildTest.php @@ -11,7 +11,6 @@ use PhpMyAdmin\Navigation\Nodes\NodeDatabaseChild; use PhpMyAdmin\Theme; use PhpMyAdmin\Url; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/plugin/export/ExportHtmlwordTest.php b/test/classes/plugin/export/ExportHtmlwordTest.php index 63af384f2f..fd1c07cc9a 100644 --- a/test/classes/plugin/export/ExportHtmlwordTest.php +++ b/test/classes/plugin/export/ExportHtmlwordTest.php @@ -9,7 +9,6 @@ use PhpMyAdmin\Plugins\Export\ExportHtmlword; require_once 'libraries/export.lib.php'; require_once 'libraries/config.default.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/plugin/export/ExportLatexTest.php b/test/classes/plugin/export/ExportLatexTest.php index 547df0ddf7..b9187f71cb 100644 --- a/test/classes/plugin/export/ExportLatexTest.php +++ b/test/classes/plugin/export/ExportLatexTest.php @@ -9,7 +9,6 @@ use PhpMyAdmin\Plugins\Export\ExportLatex; require_once 'libraries/export.lib.php'; require_once 'libraries/config.default.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/plugin/export/ExportOdtTest.php b/test/classes/plugin/export/ExportOdtTest.php index 5a31144706..f0fc2d3622 100644 --- a/test/classes/plugin/export/ExportOdtTest.php +++ b/test/classes/plugin/export/ExportOdtTest.php @@ -9,7 +9,6 @@ use PhpMyAdmin\Plugins\Export\ExportOdt; require_once 'libraries/export.lib.php'; require_once 'libraries/config.default.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/plugin/export/ExportSqlTest.php b/test/classes/plugin/export/ExportSqlTest.php index 5d0b6559c1..de3079279c 100644 --- a/test/classes/plugin/export/ExportSqlTest.php +++ b/test/classes/plugin/export/ExportSqlTest.php @@ -10,7 +10,6 @@ use PhpMyAdmin\Table; require_once 'libraries/export.lib.php'; require_once 'libraries/config.default.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/plugin/export/ExportTexytextTest.php b/test/classes/plugin/export/ExportTexytextTest.php index e0ee14ac8f..a9079dac8f 100644 --- a/test/classes/plugin/export/ExportTexytextTest.php +++ b/test/classes/plugin/export/ExportTexytextTest.php @@ -9,7 +9,6 @@ use PhpMyAdmin\Plugins\Export\ExportTexytext; require_once 'libraries/export.lib.php'; require_once 'libraries/config.default.php'; -require_once 'libraries/relation.lib.php'; require_once 'test/PMATestCase.php'; /** diff --git a/test/classes/schema/DiaRelationSchemaTest.php b/test/classes/schema/DiaRelationSchemaTest.php index dc8bd7d409..aa15cc2e63 100644 --- a/test/classes/schema/DiaRelationSchemaTest.php +++ b/test/classes/schema/DiaRelationSchemaTest.php @@ -9,8 +9,8 @@ * Include to test. */ use PhpMyAdmin\Plugins\Schema\Dia\DiaRelationSchema; +use PhpMyAdmin\Relation; -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'test/PMATestCase.php'; @@ -59,7 +59,7 @@ class DiaRelationSchemaTest extends PMATestCase 'relwork' => 'relwork', 'relation' => 'relation' ); - PMA_getRelationsParam(); + Relation::getRelationsParam(); $dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface') ->disableOriginalConstructor() diff --git a/test/classes/schema/EpsRelationSchemaTest.php b/test/classes/schema/EpsRelationSchemaTest.php index 0c0a791602..6b27d7babb 100644 --- a/test/classes/schema/EpsRelationSchemaTest.php +++ b/test/classes/schema/EpsRelationSchemaTest.php @@ -9,8 +9,8 @@ * Include to test. */ use PhpMyAdmin\Plugins\Schema\Eps\EpsRelationSchema; +use PhpMyAdmin\Relation; -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'test/PMATestCase.php'; @@ -60,7 +60,7 @@ class EpsRelationSchemaTest extends PMATestCase 'relwork' => 'relwork', 'relation' => 'relation' ); - PMA_getRelationsParam(); + Relation::getRelationsParam(); $dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface') ->disableOriginalConstructor() diff --git a/test/classes/schema/ExportRelationSchemaTest.php b/test/classes/schema/ExportRelationSchemaTest.php index 3f75fc9d20..d48adbb17a 100644 --- a/test/classes/schema/ExportRelationSchemaTest.php +++ b/test/classes/schema/ExportRelationSchemaTest.php @@ -11,7 +11,6 @@ use PhpMyAdmin\Plugins\Schema\ExportRelationSchema; -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'test/PMATestCase.php'; diff --git a/test/classes/schema/PdfRelationSchemaTest.php b/test/classes/schema/PdfRelationSchemaTest.php index ab27bf604d..81c3d0ea33 100644 --- a/test/classes/schema/PdfRelationSchemaTest.php +++ b/test/classes/schema/PdfRelationSchemaTest.php @@ -9,8 +9,8 @@ * Include to test. */ use PhpMyAdmin\Plugins\Schema\Pdf\PdfRelationSchema; +use PhpMyAdmin\Relation; -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'test/PMATestCase.php'; @@ -72,7 +72,7 @@ class PdfRelationSchemaTest extends PMATestCase 'column_info' => 'column_info', 'pdf_pages' => 'pdf_pages' ); - PMA_getRelationsParam(); + Relation::getRelationsParam(); $dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface') ->disableOriginalConstructor() diff --git a/test/classes/schema/SvgRelationSchemaTest.php b/test/classes/schema/SvgRelationSchemaTest.php index f85874295d..5887a3667d 100644 --- a/test/classes/schema/SvgRelationSchemaTest.php +++ b/test/classes/schema/SvgRelationSchemaTest.php @@ -9,8 +9,8 @@ * Include to test. */ use PhpMyAdmin\Plugins\Schema\Svg\SvgRelationSchema; +use PhpMyAdmin\Relation; -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'test/PMATestCase.php'; @@ -59,7 +59,7 @@ class SvgRelationSchemaTest extends PMATestCase 'relwork' => 'relwork', 'relation' => 'relation' ); - PMA_getRelationsParam(); + Relation::getRelationsParam(); $dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface') ->disableOriginalConstructor() diff --git a/test/libraries/PMA_PMD_common_test.php b/test/libraries/PMA_PMD_common_test.php index ea8bf926c0..08ca8d3054 100644 --- a/test/libraries/PMA_PMD_common_test.php +++ b/test/libraries/PMA_PMD_common_test.php @@ -7,7 +7,6 @@ require_once 'libraries/database_interface.inc.php'; - /** * Tests for libraries/pmd_common.php * @@ -15,7 +14,6 @@ require_once 'libraries/database_interface.inc.php'; */ class PMA_PMD_CommonTest extends PHPUnit_Framework_TestCase { - /** * Setup for test cases * @@ -37,7 +35,6 @@ class PMA_PMD_CommonTest extends PHPUnit_Framework_TestCase ) ); - include_once 'libraries/relation.lib.php'; include_once 'libraries/pmd_common.php'; } diff --git a/test/libraries/PMA_central_columns_test.php b/test/libraries/PMA_central_columns_test.php index c7be718243..b7b3004047 100644 --- a/test/libraries/PMA_central_columns_test.php +++ b/test/libraries/PMA_central_columns_test.php @@ -16,9 +16,6 @@ use PhpMyAdmin\Url; $GLOBALS['server'] = 1; require_once 'libraries/database_interface.inc.php'; - -require_once 'libraries/relation.lib.php'; - require_once 'libraries/central_columns.lib.php'; /** diff --git a/test/libraries/PMA_designer_test.php b/test/libraries/PMA_designer_test.php index d4000983e7..625533ba6f 100644 --- a/test/libraries/PMA_designer_test.php +++ b/test/libraries/PMA_designer_test.php @@ -9,7 +9,6 @@ */ require_once 'libraries/db_designer.lib.php'; require_once 'libraries/database_interface.inc.php'; -require_once 'libraries/relation.lib.php'; require_once 'libraries/plugin_interface.lib.php'; /** diff --git a/test/libraries/PMA_display_export_test.php b/test/libraries/PMA_display_export_test.php index 026622754b..bce3d262de 100644 --- a/test/libraries/PMA_display_export_test.php +++ b/test/libraries/PMA_display_export_test.php @@ -13,7 +13,6 @@ use PhpMyAdmin\Url; require_once 'libraries/display_export.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'libraries/plugin_interface.lib.php'; -require_once 'libraries/relation.lib.php'; /** * class PMA_DisplayExport_Test diff --git a/test/libraries/PMA_mult_submits_test.php b/test/libraries/PMA_mult_submits_test.php index f25251257c..743a6e5a6c 100644 --- a/test/libraries/PMA_mult_submits_test.php +++ b/test/libraries/PMA_mult_submits_test.php @@ -15,7 +15,6 @@ use PhpMyAdmin\Url; require_once 'libraries/mult_submits.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'libraries/relation_cleanup.lib.php'; -require_once 'libraries/relation.lib.php'; /** * class PMA_MultSubmits_Test diff --git a/test/libraries/PMA_normalization_test.php b/test/libraries/PMA_normalization_test.php index 2f5ff98ec1..ca983b64e6 100644 --- a/test/libraries/PMA_normalization_test.php +++ b/test/libraries/PMA_normalization_test.php @@ -15,12 +15,8 @@ use PhpMyAdmin\TypesMySQL; $GLOBALS['server'] = 1; require_once 'libraries/database_interface.inc.php'; - -require_once 'libraries/relation.lib.php'; - require_once 'libraries/normalization.lib.php'; - /** * tests for normalization.lib.php * diff --git a/test/libraries/PMA_relation_cleanup_test.php b/test/libraries/PMA_relation_cleanup_test.php index 0ce99e8918..6c2681ccb3 100644 --- a/test/libraries/PMA_relation_cleanup_test.php +++ b/test/libraries/PMA_relation_cleanup_test.php @@ -6,18 +6,15 @@ * @package PhpMyAdmin-test */ -/* - * Include to test. - */ - +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; +/* +* Include to test. +*/ require_once 'libraries/database_interface.inc.php'; - -require_once 'libraries/relation.lib.php'; require_once 'libraries/relation_cleanup.lib.php'; -use PhpMyAdmin\DatabaseInterface; - /** * PMA_Relation_Cleanup_Test class * @@ -87,13 +84,13 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase $this->redefineRelation(); //the $cfgRelation value before cleanup column - $cfgRelation = PMA_checkRelationsParam(); + $cfgRelation = Relation::checkRelationsParam(); $this->assertEquals( true, $cfgRelation['commwork'] ); - //validate PMA_getDbComments when commwork = true - $db_comments = PMA_getDbComments(); + //validate Relation::getDbComments when commwork = true + $db_comments = Relation::getDbComments(); $this->assertEquals( array('db_name0' => 'comment0','db_name1' => 'comment1'), $db_comments @@ -103,8 +100,8 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase true, $cfgRelation['displaywork'] ); - //validate PMA_getDisplayField when displaywork = true - $display_field = PMA_getDisplayField($db, $table); + //validate Relation::getDisplayField when displaywork = true + $display_field = Relation::getDisplayField($db, $table); $this->assertEquals( 'PMA_display_field', $display_field @@ -130,7 +127,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase PMA_relationsCleanupColumn($db, $table, $column); //the $cfgRelation value after cleanup column - $cfgRelation = PMA_checkRelationsParam(); + $cfgRelation = Relation::checkRelationsParam(); $is_defined_column_info = isset($cfgRelation['column_info'])? $cfgRelation['column_info'] : null; @@ -166,7 +163,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase $this->redefineRelation(); //the $cfgRelation value before cleanup column - $cfgRelation = PMA_checkRelationsParam(); + $cfgRelation = Relation::checkRelationsParam(); $this->assertEquals( 'column_info', $cfgRelation['column_info'] @@ -188,7 +185,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase PMA_relationsCleanupTable($db, $table); //the $cfgRelation value after cleanup column - $cfgRelation = PMA_checkRelationsParam(); + $cfgRelation = Relation::checkRelationsParam(); $is_defined_column_info = isset($cfgRelation['column_info'])? $cfgRelation['column_info'] : null; @@ -230,7 +227,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase $this->redefineRelation(); //the $cfgRelation value before cleanup column - $cfgRelation = PMA_checkRelationsParam(); + $cfgRelation = Relation::checkRelationsParam(); $this->assertEquals( 'column_info', $cfgRelation['column_info'] @@ -260,7 +257,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase PMA_relationsCleanupDatabase($db); //the value after cleanup column - $cfgRelation = PMA_checkRelationsParam(); + $cfgRelation = Relation::checkRelationsParam(); $is_defined_column_info = isset($cfgRelation['column_info'])? $cfgRelation['column_info'] : null; diff --git a/test/libraries/PMA_server_user_groups_test.php b/test/libraries/PMA_server_user_groups_test.php index 7dd23c1180..87ae690815 100644 --- a/test/libraries/PMA_server_user_groups_test.php +++ b/test/libraries/PMA_server_user_groups_test.php @@ -9,13 +9,10 @@ use PhpMyAdmin\Theme; use PhpMyAdmin\Url; - - -require_once 'libraries/relation.lib.php'; -require_once 'libraries/database_interface.inc.php'; /* * Include to test. */ +require_once 'libraries/database_interface.inc.php'; require_once 'libraries/server_user_groups.lib.php'; /** diff --git a/test/libraries/PMA_sql_query_form_test.php b/test/libraries/PMA_sql_query_form_test.php index dac3b6c4e0..5ee9553af4 100644 --- a/test/libraries/PMA_sql_query_form_test.php +++ b/test/libraries/PMA_sql_query_form_test.php @@ -17,8 +17,6 @@ $GLOBALS['server'] = 0; /* * Include to test. */ - -require_once 'libraries/relation.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'libraries/sql_query_form.lib.php'; diff --git a/test/libraries/PMA_user_preferences_test.php b/test/libraries/PMA_user_preferences_test.php index 48d861b44a..564314bf2c 100644 --- a/test/libraries/PMA_user_preferences_test.php +++ b/test/libraries/PMA_user_preferences_test.php @@ -12,8 +12,6 @@ use PhpMyAdmin\Config\ConfigFile; require_once 'libraries/user_preferences.lib.php'; -require_once 'libraries/relation.lib.php'; - /** * tests for methods under user_preferences library diff --git a/transformation_wrapper.php b/transformation_wrapper.php index ba1666bacd..cbf4772c40 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -7,6 +7,7 @@ */ use PhpMyAdmin\Core; +use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; @@ -20,7 +21,7 @@ define('IS_TRANSFORMATION_WRAPPER', true); */ require_once './libraries/common.inc.php'; -$cfgRelation = PMA_getRelationsParam(); +$cfgRelation = Relation::getRelationsParam(); /** * Ensures db and table are valid, else moves to the "parent" script |