From 5bf66662a9bdd62c5bccab15e607cd95cfb8fcab Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 27 Jul 2020 10:05:23 +0200 Subject: Removed wordpress and phpmyadmin, my server doesn't handle it well and it brings shame on my familly --- .../Controllers/Table/AbstractController.php | 54 - .../classes/Controllers/Table/ChartController.php | 261 ---- .../Table/GisVisualizationController.php | 227 --- .../Controllers/Table/IndexesController.php | 179 --- .../Controllers/Table/RelationController.php | 398 ----- .../classes/Controllers/Table/SearchController.php | 1244 --------------- .../classes/Controllers/Table/SqlController.php | 53 - .../Controllers/Table/StructureController.php | 1648 -------------------- 8 files changed, 4064 deletions(-) delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/AbstractController.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/ChartController.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/GisVisualizationController.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/IndexesController.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/RelationController.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/SearchController.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/SqlController.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Controllers/Table/StructureController.php (limited to 'srcs/phpmyadmin/libraries/classes/Controllers/Table') diff --git a/srcs/phpmyadmin/libraries/classes/Controllers/Table/AbstractController.php b/srcs/phpmyadmin/libraries/classes/Controllers/Table/AbstractController.php deleted file mode 100644 index 35f01ac..0000000 --- a/srcs/phpmyadmin/libraries/classes/Controllers/Table/AbstractController.php +++ /dev/null @@ -1,54 +0,0 @@ -db = $db; - $this->table = $table; - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Controllers/Table/ChartController.php b/srcs/phpmyadmin/libraries/classes/Controllers/Table/ChartController.php deleted file mode 100644 index b2c4176..0000000 --- a/srcs/phpmyadmin/libraries/classes/Controllers/Table/ChartController.php +++ /dev/null @@ -1,261 +0,0 @@ -sql_query = $sql_query; - $this->url_query = $url_query; - $this->cfg = $cfg; - } - - /** - * Execute the query and return the result - * - * @return void - */ - public function indexAction() - { - $response = Response::getInstance(); - if ($response->isAjax() - && isset($_REQUEST['pos']) - && isset($_REQUEST['session_max_rows']) - ) { - $this->ajaxAction(); - return; - } - - // Throw error if no sql query is set - if (! isset($this->sql_query) || $this->sql_query == '') { - $this->response->setRequestStatus(false); - $this->response->addHTML( - Message::error(__('No SQL query was set to fetch data.')) - ); - return; - } - - $this->response->getHeader()->getScripts()->addFiles( - [ - 'chart.js', - 'table/chart.js', - 'vendor/jqplot/jquery.jqplot.js', - 'vendor/jqplot/plugins/jqplot.barRenderer.js', - 'vendor/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js', - 'vendor/jqplot/plugins/jqplot.canvasTextRenderer.js', - 'vendor/jqplot/plugins/jqplot.categoryAxisRenderer.js', - 'vendor/jqplot/plugins/jqplot.dateAxisRenderer.js', - 'vendor/jqplot/plugins/jqplot.pointLabels.js', - 'vendor/jqplot/plugins/jqplot.pieRenderer.js', - 'vendor/jqplot/plugins/jqplot.enhancedPieLegendRenderer.js', - 'vendor/jqplot/plugins/jqplot.highlighter.js', - ] - ); - - /** - * Extract values for common work - * @todo Extract common files - */ - $db = &$this->db; - $table = &$this->table; - $url_params = []; - - /** - * Runs common work - */ - if (strlen($this->table) > 0) { - $url_params['goto'] = Util::getScriptNameForOption( - $this->cfg['DefaultTabTable'], - 'table' - ); - $url_params['back'] = 'tbl_sql.php'; - include ROOT_PATH . 'libraries/tbl_common.inc.php'; - $this->dbi->selectDb($GLOBALS['db']); - } elseif (strlen($this->db) > 0) { - $url_params['goto'] = Util::getScriptNameForOption( - $this->cfg['DefaultTabDatabase'], - 'database' - ); - $url_params['back'] = 'sql.php'; - include ROOT_PATH . 'libraries/db_common.inc.php'; - } else { - $url_params['goto'] = Util::getScriptNameForOption( - $this->cfg['DefaultTabServer'], - 'server' - ); - $url_params['back'] = 'sql.php'; - include ROOT_PATH . 'libraries/server_common.inc.php'; - } - - $data = []; - - $result = $this->dbi->tryQuery($this->sql_query); - $fields_meta = $this->dbi->getFieldsMeta($result); - while ($row = $this->dbi->fetchAssoc($result)) { - $data[] = $row; - } - - $keys = array_keys($data[0]); - - $numeric_types = [ - 'int', - 'real', - ]; - $numeric_column_count = 0; - foreach ($keys as $idx => $key) { - if (in_array($fields_meta[$idx]->type, $numeric_types)) { - $numeric_column_count++; - } - } - - if ($numeric_column_count == 0) { - $this->response->setRequestStatus(false); - $this->response->addJSON( - 'message', - __('No numeric columns present in the table to plot.') - ); - return; - } - - $url_params['db'] = $this->db; - $url_params['reload'] = 1; - - /** - * Displays the page - */ - $this->response->addHTML( - $this->template->render('table/chart/tbl_chart', [ - 'url_query' => $this->url_query, - 'url_params' => $url_params, - 'keys' => $keys, - 'fields_meta' => $fields_meta, - 'numeric_types' => $numeric_types, - 'numeric_column_count' => $numeric_column_count, - 'sql_query' => $this->sql_query, - ]) - ); - } - - /** - * Handle ajax request - * - * @return void - */ - public function ajaxAction() - { - /** - * Extract values for common work - * @todo Extract common files - */ - $db = &$this->db; - $table = &$this->table; - - if (strlen($this->table) > 0 && strlen($this->db) > 0) { - include ROOT_PATH . 'libraries/tbl_common.inc.php'; - } - - $parser = new Parser($this->sql_query); - /** - * @var SelectStatement $statement - */ - $statement = $parser->statements[0]; - if (empty($statement->limit)) { - $statement->limit = new Limit( - $_REQUEST['session_max_rows'], - $_REQUEST['pos'] - ); - } else { - $start = $statement->limit->offset + $_REQUEST['pos']; - $rows = min( - $_REQUEST['session_max_rows'], - $statement->limit->rowCount - $_REQUEST['pos'] - ); - $statement->limit = new Limit($rows, $start); - } - $sql_with_limit = $statement->build(); - - $data = []; - $result = $this->dbi->tryQuery($sql_with_limit); - while ($row = $this->dbi->fetchAssoc($result)) { - $data[] = $row; - } - - if (empty($data)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No data to display')); - return; - } - $sanitized_data = []; - - foreach ($data as $data_row_number => $data_row) { - $tmp_row = []; - foreach ($data_row as $data_column => $data_value) { - $escaped_value = $data_value === null ? null : htmlspecialchars($data_value); - $tmp_row[htmlspecialchars($data_column)] = $escaped_value; - } - $sanitized_data[] = $tmp_row; - } - $this->response->setRequestStatus(true); - $this->response->addJSON('message', null); - $this->response->addJSON('chartData', json_encode($sanitized_data)); - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Controllers/Table/GisVisualizationController.php b/srcs/phpmyadmin/libraries/classes/Controllers/Table/GisVisualizationController.php deleted file mode 100644 index 18e844f..0000000 --- a/srcs/phpmyadmin/libraries/classes/Controllers/Table/GisVisualizationController.php +++ /dev/null @@ -1,227 +0,0 @@ -sql_query = $sql_query; - $this->url_params = $url_params; - $this->url_params['goto'] = $goto; - $this->url_params['back'] = $back; - $this->visualizationSettings = $visualizationSettings; - } - - /** - * Save to file - * - * @return void - */ - public function saveToFileAction() - { - $this->response->disable(); - $file_name = $this->visualizationSettings['spatialColumn']; - $save_format = $_GET['fileFormat']; - $this->visualization->toFile($file_name, $save_format); - } - - /** - * Index - * - * @return void - */ - public function indexAction() - { - // Throw error if no sql query is set - if (! isset($this->sql_query) || $this->sql_query == '') { - $this->response->setRequestStatus(false); - $this->response->addHTML( - Message::error(__('No SQL query was set to fetch data.')) - ); - return; - } - - // Execute the query and return the result - $result = $this->dbi->tryQuery($this->sql_query); - // Get the meta data of results - $meta = $this->dbi->getFieldsMeta($result); - - // Find the candidate fields for label column and spatial column - $labelCandidates = []; - $spatialCandidates = []; - foreach ($meta as $column_meta) { - if ($column_meta->type == 'geometry') { - $spatialCandidates[] = $column_meta->name; - } else { - $labelCandidates[] = $column_meta->name; - } - } - - // Get settings if any posted - if (Core::isValid($_POST['visualizationSettings'], 'array')) { - $this->visualizationSettings = $_POST['visualizationSettings']; - } - - // Check mysql version - $this->visualizationSettings['mysqlVersion'] = $this->dbi->getVersion(); - - if (! isset($this->visualizationSettings['labelColumn']) - && isset($labelCandidates[0]) - ) { - $this->visualizationSettings['labelColumn'] = ''; - } - - // If spatial column is not set, use first geometric column as spatial column - if (! isset($this->visualizationSettings['spatialColumn'])) { - $this->visualizationSettings['spatialColumn'] = $spatialCandidates[0]; - } - - // Convert geometric columns from bytes to text. - $pos = isset($_GET['pos']) ? $_GET['pos'] - : $_SESSION['tmpval']['pos']; - if (isset($_GET['session_max_rows'])) { - $rows = $_GET['session_max_rows']; - } else { - if ($_SESSION['tmpval']['max_rows'] != 'all') { - $rows = $_SESSION['tmpval']['max_rows']; - } else { - $rows = $GLOBALS['cfg']['MaxRows']; - } - } - $this->visualization = GisVisualization::get( - $this->sql_query, - $this->visualizationSettings, - $rows, - $pos - ); - - if (isset($_GET['saveToFile'])) { - $this->saveToFileAction(); - return; - } - - $this->response->getHeader()->getScripts()->addFiles( - [ - 'vendor/openlayers/OpenLayers.js', - 'vendor/jquery/jquery.svg.js', - 'table/gis_visualization.js', - ] - ); - - // If all the rows contain SRID, use OpenStreetMaps on the initial loading. - if (! isset($_POST['displayVisualization'])) { - if ($this->visualization->hasSrid()) { - $this->visualizationSettings['choice'] = 'useBaseLayer'; - } else { - unset($this->visualizationSettings['choice']); - } - } - - $this->visualization->setUserSpecifiedSettings($this->visualizationSettings); - if ($this->visualizationSettings != null) { - foreach ($this->visualization->getSettings() as $setting => $val) { - if (! isset($this->visualizationSettings[$setting])) { - $this->visualizationSettings[$setting] = $val; - } - } - } - - /** - * Displays the page - */ - $this->url_params['sql_query'] = $this->sql_query; - $downloadUrl = 'tbl_gis_visualization.php' . Url::getCommon( - array_merge( - $this->url_params, - [ - 'saveToFile' => true, - 'session_max_rows' => $rows, - 'pos' => $pos, - ] - ) - ); - $html = $this->template->render('table/gis_visualization/gis_visualization', [ - 'url_params' => $this->url_params, - 'download_url' => $downloadUrl, - 'label_candidates' => $labelCandidates, - 'spatial_candidates' => $spatialCandidates, - 'visualization_settings' => $this->visualizationSettings, - 'sql_query' => $this->sql_query, - 'visualization' => $this->visualization->toImage('svg'), - 'draw_ol' => $this->visualization->asOl(), - 'pma_theme_image' => $GLOBALS['pmaThemeImage'], - ]); - - $this->response->addHTML($html); - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Controllers/Table/IndexesController.php b/srcs/phpmyadmin/libraries/classes/Controllers/Table/IndexesController.php deleted file mode 100644 index cdbfbb9..0000000 --- a/srcs/phpmyadmin/libraries/classes/Controllers/Table/IndexesController.php +++ /dev/null @@ -1,179 +0,0 @@ -index = $index; - } - - /** - * Index - * - * @return void - */ - public function indexAction() - { - if (isset($_POST['do_save_data'])) { - $this->doSaveDataAction(); - return; - } // end builds the new index - - $this->displayFormAction(); - } - - /** - * Display the form to edit/create an index - * - * @return void - */ - public function displayFormAction() - { - $this->dbi->selectDb($GLOBALS['db']); - $add_fields = 0; - if (isset($_POST['index']) && is_array($_POST['index'])) { - // coming already from form - if (isset($_POST['index']['columns']['names'])) { - $add_fields = count($_POST['index']['columns']['names']) - - $this->index->getColumnCount(); - } - if (isset($_POST['add_fields'])) { - $add_fields += $_POST['added_fields']; - } - } elseif (isset($_POST['create_index'])) { - $add_fields = $_POST['added_fields']; - } // end preparing form values - - // Get fields and stores their name/type - if (isset($_POST['create_edit_table'])) { - $fields = json_decode($_POST['columns'], true); - $index_params = [ - 'Non_unique' => $_POST['index']['Index_choice'] == 'UNIQUE' - ? '0' : '1', - ]; - $this->index->set($index_params); - $add_fields = count($fields); - } else { - $fields = $this->dbi->getTable($this->db, $this->table) - ->getNameAndTypeOfTheColumns(); - } - - $form_params = [ - 'db' => $this->db, - 'table' => $this->table, - ]; - - if (isset($_POST['create_index'])) { - $form_params['create_index'] = 1; - } elseif (isset($_POST['old_index'])) { - $form_params['old_index'] = $_POST['old_index']; - } elseif (isset($_POST['index'])) { - $form_params['old_index'] = $_POST['index']; - } - - $this->response->getHeader()->getScripts()->addFile('indexes.js'); - - $this->response->addHTML( - $this->template->render('table/index_form', [ - 'fields' => $fields, - 'index' => $this->index, - 'form_params' => $form_params, - 'add_fields' => $add_fields, - 'create_edit_table' => isset($_POST['create_edit_table']), - 'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'], - ]) - ); - } - - /** - * Process the data from the edit/create index form, - * run the query to build the new index - * and moves back to "tbl_sql.php" - * - * @return void - */ - public function doSaveDataAction() - { - $error = false; - - $sql_query = $this->dbi->getTable($this->db, $this->table) - ->getSqlQueryForIndexCreateOrEdit($this->index, $error); - - // If there is a request for SQL previewing. - if (isset($_POST['preview_sql'])) { - $this->response->addJSON( - 'sql_data', - $this->template->render('preview_sql', ['query_data' => $sql_query]) - ); - } elseif (! $error) { - $this->dbi->query($sql_query); - $response = Response::getInstance(); - if ($response->isAjax()) { - $message = Message::success( - __('Table %1$s has been altered successfully.') - ); - $message->addParam($this->table); - $this->response->addJSON( - 'message', - Util::getMessage($message, $sql_query, 'success') - ); - $this->response->addJSON( - 'index_table', - Index::getHtmlForIndexes( - $this->table, - $this->db - ) - ); - } else { - include ROOT_PATH . 'tbl_structure.php'; - } - } else { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', $error); - } - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Controllers/Table/RelationController.php b/srcs/phpmyadmin/libraries/classes/Controllers/Table/RelationController.php deleted file mode 100644 index 558842c..0000000 --- a/srcs/phpmyadmin/libraries/classes/Controllers/Table/RelationController.php +++ /dev/null @@ -1,398 +0,0 @@ -options_array = $options_array; - $this->cfgRelation = $cfgRelation; - $this->tbl_storage_engine = $tbl_storage_engine; - $this->existrel = $existrel; - $this->existrel_foreign = $existrel_foreign; - $this->upd_query = $upd_query; - $this->relation = $relation; - } - - /** - * Index - * - * @return void - */ - public function indexAction() - { - // Send table of column names to populate corresponding dropdowns depending - // on the current selection - if (isset($_POST['getDropdownValues']) - && $_POST['getDropdownValues'] === 'true' - ) { - // if both db and table are selected - if (isset($_POST['foreignTable'])) { - $this->getDropdownValueForTableAction(); - } else { // if only the db is selected - $this->getDropdownValueForDbAction(); - } - return; - } - - $this->response->getHeader()->getScripts()->addFiles( - [ - 'table/relation.js', - 'indexes.js', - ] - ); - - // Set the database - $this->dbi->selectDb($this->db); - - // updates for Internal relations - if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) { - $this->updateForInternalRelationAction(); - } - - // updates for foreign keys - $this->updateForForeignKeysAction(); - - // Updates for display field - if ($this->cfgRelation['displaywork'] && isset($_POST['display_field'])) { - $this->updateForDisplayField(); - } - - // If we did an update, refresh our data - if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) { - $this->existrel = $this->relation->getForeigners( - $this->db, - $this->table, - '', - 'internal' - ); - } - if (isset($_POST['destination_foreign_db']) - && Util::isForeignKeySupported($this->tbl_storage_engine) - ) { - $this->existrel_foreign = $this->relation->getForeigners( - $this->db, - $this->table, - '', - 'foreign' - ); - } - - /** - * Dialog - */ - // Now find out the columns of our $table - // need to use DatabaseInterface::QUERY_STORE with $this->dbi->numRows() - // in mysqli - $columns = $this->dbi->getColumns($this->db, $this->table); - - $column_array = []; - $column_hash_array = []; - $column_array[''] = ''; - foreach ($columns as $column) { - if (strtoupper($this->tbl_storage_engine) == 'INNODB' - || ! empty($column['Key']) - ) { - $column_array[$column['Field']] = $column['Field']; - $column_hash_array[$column['Field']] = md5($column['Field']); - } - } - if ($GLOBALS['cfg']['NaturalOrder']) { - uksort($column_array, 'strnatcasecmp'); - } - - // common form - $engine = $this->dbi->getTable($this->db, $this->table)->getStorageEngine(); - $foreignKeySupported = Util::isForeignKeySupported($this->tbl_storage_engine); - $this->response->addHTML( - $this->template->render('table/relation/common_form', [ - 'is_foreign_key_supported' => Util::isForeignKeySupported($engine), - 'db' => $this->db, - 'table' => $this->table, - 'cfg_relation' => $this->cfgRelation, - 'tbl_storage_engine' => $this->tbl_storage_engine, - 'existrel' => isset($this->existrel) ? $this->existrel : [], - 'existrel_foreign' => is_array($this->existrel_foreign) && array_key_exists('foreign_keys_data', $this->existrel_foreign) - ? $this->existrel_foreign['foreign_keys_data'] : [], - 'options_array' => $this->options_array, - 'column_array' => $column_array, - 'column_hash_array' => $column_hash_array, - 'save_row' => array_values($columns), - 'url_params' => $GLOBALS['url_params'], - 'databases' => $GLOBALS['dblist']->databases, - 'dbi' => $this->dbi, - 'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'], - 'foreignKeySupported' => $foreignKeySupported, - 'displayIndexesHtml' => $foreignKeySupported ? Index::getHtmlForDisplayIndexes() : null, - ]) - ); - } - - /** - * Update for display field - * - * @return void - */ - public function updateForDisplayField() - { - if ($this->upd_query->updateDisplayField( - $_POST['display_field'], - $this->cfgRelation - ) - ) { - $this->response->addHTML( - Util::getMessage( - __('Display column was successfully updated.'), - '', - 'success' - ) - ); - } - } - - /** - * Update for FK - * - * @return void - */ - public function updateForForeignKeysAction() - { - $multi_edit_columns_name = isset($_POST['foreign_key_fields_name']) - ? $_POST['foreign_key_fields_name'] - : null; - $preview_sql_data = ''; - $seen_error = false; - - // (for now, one index name only; we keep the definitions if the - // foreign db is not the same) - if (isset($_POST['destination_foreign_db']) - && isset($_POST['destination_foreign_table']) - && isset($_POST['destination_foreign_column'])) { - list($html, $preview_sql_data, $display_query, $seen_error) - = $this->upd_query->updateForeignKeys( - $_POST['destination_foreign_db'], - $multi_edit_columns_name, - $_POST['destination_foreign_table'], - $_POST['destination_foreign_column'], - $this->options_array, - $this->table, - is_array($this->existrel_foreign) && array_key_exists('foreign_keys_data', $this->existrel_foreign) - ? $this->existrel_foreign['foreign_keys_data'] : [] - ); - $this->response->addHTML($html); - } - - // If there is a request for SQL previewing. - if (isset($_POST['preview_sql'])) { - Core::previewSQL($preview_sql_data); - } - - if (! empty($display_query) && ! $seen_error) { - $GLOBALS['display_query'] = $display_query; - $this->response->addHTML( - Util::getMessage( - __('Your SQL query has been executed successfully.'), - null, - 'success' - ) - ); - } - } - - /** - * Update for internal relation - * - * @return void - */ - public function updateForInternalRelationAction() - { - $multi_edit_columns_name = isset($_POST['fields_name']) - ? $_POST['fields_name'] - : null; - - if ($this->upd_query->updateInternalRelations( - $multi_edit_columns_name, - $_POST['destination_db'], - $_POST['destination_table'], - $_POST['destination_column'], - $this->cfgRelation, - isset($this->existrel) ? $this->existrel : null - ) - ) { - $this->response->addHTML( - Util::getMessage( - __('Internal relationships were successfully updated.'), - '', - 'success' - ) - ); - } - } - - /** - * Send table columns for foreign table dropdown - * - * @return void - * - */ - public function getDropdownValueForTableAction() - { - $foreignTable = $_POST['foreignTable']; - $table_obj = $this->dbi->getTable($_POST['foreignDb'], $foreignTable); - // Since views do not have keys defined on them provide the full list of - // columns - if ($table_obj->isView()) { - $columnList = $table_obj->getColumns(false, false); - } else { - $columnList = $table_obj->getIndexedColumns(false, false); - } - $columns = []; - foreach ($columnList as $column) { - $columns[] = htmlspecialchars($column); - } - if ($GLOBALS['cfg']['NaturalOrder']) { - usort($columns, 'strnatcasecmp'); - } - $this->response->addJSON('columns', $columns); - - // @todo should be: $server->db($db)->table($table)->primary() - $primary = Index::getPrimary($foreignTable, $_POST['foreignDb']); - if (false === $primary) { - return; - } - - $this->response->addJSON('primary', array_keys($primary->getColumns())); - } - - /** - * Send database selection values for dropdown - * - * @return void - * - */ - public function getDropdownValueForDbAction() - { - $tables = []; - $foreign = isset($_POST['foreign']) && $_POST['foreign'] === 'true'; - - if ($foreign) { - $query = 'SHOW TABLE STATUS FROM ' - . Util::backquote($_POST['foreignDb']); - $tables_rs = $this->dbi->query( - $query, - DatabaseInterface::CONNECT_USER, - DatabaseInterface::QUERY_STORE - ); - - while ($row = $this->dbi->fetchArray($tables_rs)) { - if (isset($row['Engine']) - && mb_strtoupper($row['Engine']) == $this->tbl_storage_engine - ) { - $tables[] = htmlspecialchars($row['Name']); - } - } - } else { - $query = 'SHOW TABLES FROM ' - . Util::backquote($_POST['foreignDb']); - $tables_rs = $this->dbi->query( - $query, - DatabaseInterface::CONNECT_USER, - DatabaseInterface::QUERY_STORE - ); - while ($row = $this->dbi->fetchArray($tables_rs)) { - $tables[] = htmlspecialchars($row[0]); - } - } - if ($GLOBALS['cfg']['NaturalOrder']) { - usort($tables, 'strnatcasecmp'); - } - $this->response->addJSON('tables', $tables); - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Controllers/Table/SearchController.php b/srcs/phpmyadmin/libraries/classes/Controllers/Table/SearchController.php deleted file mode 100644 index 3f2ceae..0000000 --- a/srcs/phpmyadmin/libraries/classes/Controllers/Table/SearchController.php +++ /dev/null @@ -1,1244 +0,0 @@ -url_query = $url_query; - $this->_searchType = $searchType; - $this->_columnNames = []; - $this->_columnNullFlags = []; - $this->_columnTypes = []; - $this->_columnCollations = []; - $this->_geomColumnFlag = false; - $this->_foreigners = []; - $this->relation = $relation; - // Loads table's information - $this->_loadTableInfo(); - $this->_connectionCharSet = $this->dbi->fetchValue( - "SELECT @@character_set_connection" - ); - } - - /** - * Gets all the columns of a table along with their types, collations - * and whether null or not. - * - * @return void - */ - private function _loadTableInfo() - { - // Gets the list and number of columns - $columns = $this->dbi->getColumns( - $this->db, - $this->table, - null, - true - ); - // Get details about the geometry functions - $geom_types = Util::getGISDatatypes(); - - foreach ($columns as $row) { - // set column name - $this->_columnNames[] = $row['Field']; - - $type = $row['Type']; - // check whether table contains geometric columns - if (in_array($type, $geom_types)) { - $this->_geomColumnFlag = true; - } - // reformat mysql query output - if (strncasecmp($type, 'set', 3) == 0 - || strncasecmp($type, 'enum', 4) == 0 - ) { - $type = str_replace(',', ', ', $type); - } else { - // strip the "BINARY" attribute, except if we find "BINARY(" because - // this would be a BINARY or VARBINARY column type - if (! preg_match('@BINARY[\(]@i', $type)) { - $type = str_ireplace("BINARY", '', $type); - } - $type = str_ireplace("ZEROFILL", '', $type); - $type = str_ireplace("UNSIGNED", '', $type); - $type = mb_strtolower($type); - } - if (empty($type)) { - $type = ' '; - } - $this->_columnTypes[] = $type; - $this->_columnNullFlags[] = $row['Null']; - $this->_columnCollations[] - = ! empty($row['Collation']) && $row['Collation'] != 'NULL' - ? $row['Collation'] - : ''; - } // end for - - // Retrieve foreign keys - $this->_foreigners = $this->relation->getForeigners($this->db, $this->table); - } - - /** - * Index action - * - * @return void - */ - public function indexAction() - { - global $goto; - switch ($this->_searchType) { - case 'replace': - if (isset($_POST['find'])) { - $this->findAction(); - - return; - } - $this->response - ->getHeader() - ->getScripts() - ->addFile('table/find_replace.js'); - - if (isset($_POST['replace'])) { - $this->replaceAction(); - } - - // Displays the find and replace form - $this->displaySelectionFormAction(); - break; - - case 'normal': - $this->response->getHeader() - ->getScripts() - ->addFiles( - [ - 'makegrid.js', - 'sql.js', - 'table/select.js', - 'table/change.js', - 'vendor/jquery/jquery.uitablefilter.js', - 'gis_data_editor.js', - ] - ); - - if (isset($_POST['range_search'])) { - $this->rangeSearchAction(); - - return; - } - - /** - * No selection criteria received -> display the selection form - */ - if (! isset($_POST['columnsToDisplay']) - && ! isset($_POST['displayAllColumns']) - ) { - $this->displaySelectionFormAction(); - } else { - $this->doSelectionAction(); - } - break; - - case 'zoom': - $this->response->getHeader() - ->getScripts() - ->addFiles( - [ - 'makegrid.js', - 'sql.js', - 'vendor/jqplot/jquery.jqplot.js', - 'vendor/jqplot/plugins/jqplot.canvasTextRenderer.js', - 'vendor/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js', - 'vendor/jqplot/plugins/jqplot.dateAxisRenderer.js', - 'vendor/jqplot/plugins/jqplot.highlighter.js', - 'vendor/jqplot/plugins/jqplot.cursor.js', - 'table/zoom_plot_jqplot.js', - 'table/change.js', - ] - ); - - /** - * Handle AJAX request for data row on point select - * - * @var boolean Object containing parameters for the POST request - */ - if (isset($_POST['get_data_row']) - && $_POST['get_data_row'] == true - ) { - $this->getDataRowAction(); - - return; - } - /** - * Handle AJAX request for changing field information - * (value,collation,operators,field values) in input form - * - * @var boolean Object containing parameters for the POST request - */ - if (isset($_POST['change_tbl_info']) - && $_POST['change_tbl_info'] == true - ) { - $this->changeTableInfoAction(); - - return; - } - - //Set default datalabel if not selected - if (! isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') { - $dataLabel = $this->relation->getDisplayField($this->db, $this->table); - } else { - $dataLabel = $_POST['dataLabel']; - } - - // Displays the zoom search form - $this->displaySelectionFormAction($dataLabel); - - /* - * Handle the input criteria and generate the query result - * Form for displaying query results - */ - if (isset($_POST['zoom_submit']) - && $_POST['criteriaColumnNames'][0] != 'pma_null' - && $_POST['criteriaColumnNames'][1] != 'pma_null' - && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1] - ) { - if (! isset($goto)) { - $goto = Util::getScriptNameForOption( - $GLOBALS['cfg']['DefaultTabTable'], - 'table' - ); - } - $this->zoomSubmitAction($dataLabel, $goto); - } - break; - } - } - - /** - * Zoom submit action - * - * @param string $dataLabel Data label - * @param string $goto Goto - * - * @return void - */ - public function zoomSubmitAction($dataLabel, $goto) - { - //Query generation part - $sql_query = $this->_buildSqlQuery(); - $sql_query .= ' LIMIT ' . $_POST['maxPlotLimit']; - - //Query execution part - $result = $this->dbi->query( - $sql_query . ";", - DatabaseInterface::CONNECT_USER, - DatabaseInterface::QUERY_STORE - ); - $fields_meta = $this->dbi->getFieldsMeta($result); - $data = []; - while ($row = $this->dbi->fetchAssoc($result)) { - //Need a row with indexes as 0,1,2 for the getUniqueCondition - // hence using a temporary array - $tmpRow = []; - foreach ($row as $val) { - $tmpRow[] = $val; - } - //Get unique condition on each row (will be needed for row update) - $uniqueCondition = Util::getUniqueCondition( - $result, // handle - count($this->_columnNames), // fields_cnt - $fields_meta, // fields_meta - $tmpRow, // row - true, // force_unique - false, // restrict_to_table - null // analyzed_sql_results - ); - //Append it to row array as where_clause - $row['where_clause'] = $uniqueCondition[0]; - - $tmpData = [ - $_POST['criteriaColumnNames'][0] => - $row[$_POST['criteriaColumnNames'][0]], - $_POST['criteriaColumnNames'][1] => - $row[$_POST['criteriaColumnNames'][1]], - 'where_clause' => $uniqueCondition[0], - ]; - $tmpData[$dataLabel] = $dataLabel ? $row[$dataLabel] : ''; - $data[] = $tmpData; - } - unset($tmpData); - - //Displays form for point data and scatter plot - $titles = [ - 'Browse' => Util::getIcon( - 'b_browse', - __('Browse foreign values') - ), - ]; - $column_names_hashes = []; - - foreach ($this->_columnNames as $columnName) { - $column_names_hashes[$columnName] = md5($columnName); - } - - $this->response->addHTML( - $this->template->render('table/search/zoom_result_form', [ - 'db' => $this->db, - 'table' => $this->table, - 'column_names' => $this->_columnNames, - 'column_names_hashes' => $column_names_hashes, - 'foreigners' => $this->_foreigners, - 'column_null_flags' => $this->_columnNullFlags, - 'column_types' => $this->_columnTypes, - 'titles' => $titles, - 'goto' => $goto, - 'data' => $data, - 'data_json' => json_encode($data), - 'zoom_submit' => isset($_POST['zoom_submit']), - 'foreign_max_limit' => $GLOBALS['cfg']['ForeignKeyMaxLimit'], - ]) - ); - } - - /** - * Change table info action - * - * @return void - */ - public function changeTableInfoAction() - { - $field = $_POST['field']; - if ($field == 'pma_null') { - $this->response->addJSON('field_type', ''); - $this->response->addJSON('field_collation', ''); - $this->response->addJSON('field_operators', ''); - $this->response->addJSON('field_value', ''); - return; - } - $key = array_search($field, $this->_columnNames); - $search_index - = (isset($_POST['it']) && is_numeric($_POST['it']) - ? intval($_POST['it']) : 0); - - $properties = $this->getColumnProperties($search_index, $key); - $this->response->addJSON( - 'field_type', - htmlspecialchars($properties['type']) - ); - $this->response->addJSON('field_collation', $properties['collation']); - $this->response->addJSON('field_operators', $properties['func']); - $this->response->addJSON('field_value', $properties['value']); - } - - /** - * Get data row action - * - * @return void - */ - public function getDataRowAction() - { - $extra_data = []; - $row_info_query = 'SELECT * FROM `' . $_POST['db'] . '`.`' - . $_POST['table'] . '` WHERE ' . $_POST['where_clause']; - $result = $this->dbi->query( - $row_info_query . ";", - DatabaseInterface::CONNECT_USER, - DatabaseInterface::QUERY_STORE - ); - $fields_meta = $this->dbi->getFieldsMeta($result); - while ($row = $this->dbi->fetchAssoc($result)) { - // for bit fields we need to convert them to printable form - $i = 0; - foreach ($row as $col => $val) { - if ($fields_meta[$i]->type == 'bit') { - $row[$col] = Util::printableBitValue( - (int) $val, - (int) $fields_meta[$i]->length - ); - } - $i++; - } - $extra_data['row_info'] = $row; - } - $this->response->addJSON($extra_data); - } - - /** - * Do selection action - * - * @return void - */ - public function doSelectionAction() - { - /** - * Selection criteria have been submitted -> do the work - */ - $sql_query = $this->_buildSqlQuery(); - - /** - * Add this to ensure following procedures included running correctly. - */ - $sql = new Sql(); - $sql->executeQueryAndSendQueryResponse( - null, // analyzed_sql_results - false, // is_gotofile - $this->db, // db - $this->table, // table - null, // find_real_end - null, // sql_query_for_bookmark - null, // extra_data - null, // message_to_show - null, // message - null, // sql_data - $GLOBALS['goto'], // goto - $GLOBALS['pmaThemeImage'], // pmaThemeImage - null, // disp_query - null, // disp_message - null, // query_type - $sql_query, // sql_query - null, // selectedTables - null // complete_query - ); - } - - /** - * Display selection form action - * - * @param string $dataLabel Data label - * - * @return void - */ - public function displaySelectionFormAction($dataLabel = null) - { - global $goto; - $this->url_query .= '&goto=tbl_select.php&back=tbl_select.php'; - if (! isset($goto)) { - $goto = Util::getScriptNameForOption( - $GLOBALS['cfg']['DefaultTabTable'], - 'table' - ); - } - // Displays the table search form - $this->response->addHTML( - $this->template->render('secondary_tabs', [ - 'url_params' => [ - 'db' => $this->db, - 'table' => $this->table, - ], - 'sub_tabs' => $this->_getSubTabs(), - ]) - ); - - $column_names = $this->_columnNames; - $column_types = $this->_columnTypes; - $types = []; - if ($this->_searchType == 'replace') { - $num_cols = count($column_names); - for ($i = 0; $i < $num_cols; $i++) { - $types[$column_names[$i]] = preg_replace('@\\(.*@s', '', $column_types[$i]); - } - } - - $criteria_column_names = isset($_POST['criteriaColumnNames']) ? $_POST['criteriaColumnNames'] : null; - $keys = []; - for ($i = 0; $i < 4; $i++) { - if (isset($criteria_column_names[$i])) { - if ($criteria_column_names[$i] != 'pma_null') { - $keys[$criteria_column_names[$i]] = array_search($criteria_column_names[$i], $column_names); - } - } - } - - $this->response->addHTML( - $this->template->render('table/search/selection_form', [ - 'search_type' => $this->_searchType, - 'db' => $this->db, - 'table' => $this->table, - 'goto' => $goto, - 'self' => $this, - 'geom_column_flag' => $this->_geomColumnFlag, - 'column_names' => $column_names, - 'column_types' => $column_types, - 'types' => $types, - 'column_collations' => $this->_columnCollations, - 'data_label' => $dataLabel, - 'keys' => $keys, - 'criteria_column_names' => $criteria_column_names, - 'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'], - 'criteria_column_types' => isset($_POST['criteriaColumnTypes']) ? $_POST['criteriaColumnTypes'] : null, - 'sql_types' => $this->dbi->types, - 'max_rows' => intval($GLOBALS['cfg']['MaxRows']), - 'max_plot_limit' => ! empty($_POST['maxPlotLimit']) - ? intval($_POST['maxPlotLimit']) - : intval($GLOBALS['cfg']['maxRowPlotLimit']), - ]) - ); - } - - /** - * Range search action - * - * @return void - */ - public function rangeSearchAction() - { - $min_max = $this->getColumnMinMax($_POST['column']); - $this->response->addJSON('column_data', $min_max); - } - - /** - * Find action - * - * @return void - */ - public function findAction() - { - $useRegex = array_key_exists('useRegex', $_POST) - && $_POST['useRegex'] == 'on'; - - $preview = $this->getReplacePreview( - $_POST['columnIndex'], - $_POST['find'], - $_POST['replaceWith'], - $useRegex, - $this->_connectionCharSet - ); - $this->response->addJSON('preview', $preview); - } - - /** - * Replace action - * - * @return void - */ - public function replaceAction() - { - $this->replace( - $_POST['columnIndex'], - $_POST['findString'], - $_POST['replaceWith'], - $_POST['useRegex'], - $this->_connectionCharSet - ); - $this->response->addHTML( - Util::getMessage( - __('Your SQL query has been executed successfully.'), - null, - 'success' - ) - ); - } - - /** - * Returns HTML for previewing strings found and their replacements - * - * @param int $columnIndex index of the column - * @param string $find string to find in the column - * @param string $replaceWith string to replace with - * @param boolean $useRegex to use Regex replace or not - * @param string $charSet character set of the connection - * - * @return string HTML for previewing strings found and their replacements - */ - public function getReplacePreview( - $columnIndex, - $find, - $replaceWith, - $useRegex, - $charSet - ) { - $column = $this->_columnNames[$columnIndex]; - if ($useRegex) { - $result = $this->_getRegexReplaceRows( - $columnIndex, - $find, - $replaceWith, - $charSet - ); - } else { - $sql_query = "SELECT " - . Util::backquote($column) . "," - . " REPLACE(" - . Util::backquote($column) . ", '" . $find . "', '" - . $replaceWith - . "')," - . " COUNT(*)" - . " FROM " . Util::backquote($this->db) - . "." . Util::backquote($this->table) - . " WHERE " . Util::backquote($column) - . " LIKE '%" . $find . "%' COLLATE " . $charSet . "_bin"; // here we - // change the collation of the 2nd operand to a case sensitive - // binary collation to make sure that the comparison - // is case sensitive - $sql_query .= " GROUP BY " . Util::backquote($column) - . " ORDER BY " . Util::backquote($column) . " ASC"; - - $result = $this->dbi->fetchResult($sql_query, 0); - } - - return $this->template->render('table/search/replace_preview', [ - 'db' => $this->db, - 'table' => $this->table, - 'column_index' => $columnIndex, - 'find' => $find, - 'replace_with' => $replaceWith, - 'use_regex' => $useRegex, - 'result' => $result, - ]); - } - - /** - * Finds and returns Regex pattern and their replacements - * - * @param int $columnIndex index of the column - * @param string $find string to find in the column - * @param string $replaceWith string to replace with - * @param string $charSet character set of the connection - * - * @return array|bool Array containing original values, replaced values and count - */ - private function _getRegexReplaceRows( - $columnIndex, - $find, - $replaceWith, - $charSet - ) { - $column = $this->_columnNames[$columnIndex]; - $sql_query = "SELECT " - . Util::backquote($column) . "," - . " 1," // to add an extra column that will have replaced value - . " COUNT(*)" - . " FROM " . Util::backquote($this->db) - . "." . Util::backquote($this->table) - . " WHERE " . Util::backquote($column) - . " RLIKE '" . $this->dbi->escapeString($find) . "' COLLATE " - . $charSet . "_bin"; // here we - // change the collation of the 2nd operand to a case sensitive - // binary collation to make sure that the comparison is case sensitive - $sql_query .= " GROUP BY " . Util::backquote($column) - . " ORDER BY " . Util::backquote($column) . " ASC"; - - $result = $this->dbi->fetchResult($sql_query, 0); - - if (is_array($result)) { - /* Iterate over possible delimiters to get one */ - $delimiters = [ - '/', - '@', - '#', - '~', - '!', - '$', - '%', - '^', - '&', - '_', - ]; - $found = false; - for ($i = 0, $l = count($delimiters); $i < $l; $i++) { - if (strpos($find, $delimiters[$i]) === false) { - $found = true; - break; - } - } - if (! $found) { - return false; - } - $find = $delimiters[$i] . $find . $delimiters[$i]; - foreach ($result as $index => $row) { - $result[$index][1] = preg_replace( - $find, - $replaceWith, - $row[0] - ); - } - } - return $result; - } - - /** - * Replaces a given string in a column with a give replacement - * - * @param int $columnIndex index of the column - * @param string $find string to find in the column - * @param string $replaceWith string to replace with - * @param boolean $useRegex to use Regex replace or not - * @param string $charSet character set of the connection - * - * @return void - */ - public function replace( - $columnIndex, - $find, - $replaceWith, - $useRegex, - $charSet - ) { - $column = $this->_columnNames[$columnIndex]; - if ($useRegex) { - $toReplace = $