diff --git a/browse_foreigners.php b/browse_foreigners.php index 3abedb401a53..ea585d4065ef 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -68,8 +68,8 @@ $table, $_REQUEST['field'], $foreignData, - isset($fieldkey) ? $fieldkey : null, - isset($data) ? $data : null + isset($fieldkey) ? $fieldkey : '', + isset($data) ? $data : '' ); $response->addHtml($html); diff --git a/libraries/classes/Controllers/Database/DatabaseStructureController.php b/libraries/classes/Controllers/Database/DatabaseStructureController.php index 2bfd2fa67c64..6a96fe8b61cc 100644 --- a/libraries/classes/Controllers/Database/DatabaseStructureController.php +++ b/libraries/classes/Controllers/Database/DatabaseStructureController.php @@ -681,12 +681,12 @@ protected function displayTableList() 'formatted_size' => $formatted_size, 'unit' => $unit, 'overhead' => $overhead, - 'create_time' => isset($create_time) - ? $create_time : '', - 'update_time' => isset($update_time) - ? $update_time : '', - 'check_time' => isset($check_time) - ? $check_time : '', + 'create_time' => (isset($create_time) && $create_time + ? Util::localisedDate(strtotime($create_time)) : '-'), + 'update_time' => (isset($update_time) && $update_time + ? Util::localisedDate(strtotime($update_time)) : '-'), + 'check_time' => (isset($check_time) && $check_time + ? Util::localisedDate(strtotime($check_time)) : '-'), 'charset' => isset($charset) ? $charset : '', 'is_show_stats' => $this->_is_show_stats, @@ -730,9 +730,9 @@ protected function displayTableList() 'db_charset' => $db_charset, 'sum_size' => $sum_size, 'overhead_size' => $overhead_size, - 'create_time_all' => $create_time_all, - 'update_time_all' => $update_time_all, - 'check_time_all' => $check_time_all, + 'create_time_all' => ($create_time_all ? Util::localisedDate(strtotime($create_time_all)) : '-'), + 'update_time_all' => ($update_time_all ? Util::localisedDate(strtotime($update_time_all)) : '-'), + 'check_time_all' => ($check_time_all ? Util::localisedDate(strtotime($check_time_all)) : '-'), 'approx_rows' => $overall_approx_rows, 'num_favorite_tables' => $GLOBALS['cfg']['NumFavoriteTables'], 'db' => $GLOBALS['db'], diff --git a/libraries/classes/Controllers/Server/ServerDatabasesController.php b/libraries/classes/Controllers/Server/ServerDatabasesController.php index 3fe1ccf2d9c4..94bef486cfc5 100644 --- a/libraries/classes/Controllers/Server/ServerDatabasesController.php +++ b/libraries/classes/Controllers/Server/ServerDatabasesController.php @@ -1,5 +1,6 @@ $stat) { + if (array_key_exists($stat_name,$first_database)) { + if ($stat['format'] == 'byte') { + $byte_format = Util_formatByteDown($stat['footer'], 3, 1); + $values[$stat_name] = $byte_format[0]; + $units[$stat_name] = $byte_format[1]; + } elseif ($stat['format'] == 'number') { + $values[$stat_name] = Util::formatNumber($stat['footer'], 0); + } else{ + $values[$stat_name] = htmlentities($stat['footer'], 0); + } + } + } + $_url_params = array( 'pos' => $this->_pos, 'dbstats' => $this->_dbstats, @@ -308,6 +326,8 @@ private function _getHtmlForDatabases(array $replication_types) 'pma_theme_image' => $GLOBALS['pmaThemeImage'], 'text_dir' => $GLOBALS['text_dir'], 'dbstats' => $this->_dbstats, + 'values' => $values, + 'units' => $units, ]); return $html; @@ -446,6 +466,22 @@ function _buildHtmlForDb( } } + $values = array(); + $units = array(); + foreach ($column_order as $stat_name => $stat) { + if (array_key_exists($stat_name,$current)) { + if ($stat['format'] == 'byte') { + $byte_format = Util::formatByteDown($stat['footer'], 3, 1); + $values[$stat_name] = $byte_format[0]; + $units[$stat_name] = $byte_format[1]; + } elseif ($stat['format'] == 'number') { + $values[$stat_name] = Util_formatNumber($stat['footer'], 0); + } else{ + $values[$stat_name] = htmlentities($stat['footer'], 0); + } + } + } + return Template::get('server/databases/table_row')->render([ 'current' => $current, 'tr_class' => $tr_class, @@ -458,6 +494,8 @@ function _buildHtmlForDb( 'allow_user_drop_database' => $GLOBALS['cfg']['AllowUserDropDatabase'], 'is_system_schema' => $this->dbi->isSystemSchema($current['SCHEMA_NAME'], true), 'default_tab_database' => $GLOBALS['cfg']['DefaultTabDatabase'], + 'values' => $values, + 'units' => $units, ]); } } diff --git a/libraries/classes/Controllers/Server/ServerPluginsController.php b/libraries/classes/Controllers/Server/ServerPluginsController.php index 4a3d3d2f6820..b465a1990c75 100644 --- a/libraries/classes/Controllers/Server/ServerPluginsController.php +++ b/libraries/classes/Controllers/Server/ServerPluginsController.php @@ -96,15 +96,26 @@ private function _setServerPlugins() */ private function _getPluginsHtml() { + $plugins_type_clean = array(); + $keys = array_keys($this->plugins); + foreach ($keys as $plugin_type) { + $plugins_type_clean[$plugin_type] = preg_replace( + '/[^a-z]/', '', mb_strtolower($plugin_type) + ); + } $html = '
'; $html .= Template::get('server/plugins/section_links') - ->render(array('plugins' => $this->plugins)); + ->render(array( + 'plugins' => $this->plugins, + 'plugins_type_clean' => $plugins_type_clean, + )); foreach ($this->plugins as $plugin_type => $plugin_list) { $html .= Template::get('server/plugins/section') ->render( array( 'plugin_type' => $plugin_type, + 'plugin_type_clean' => $plugins_type_clean[$plugin_type], 'plugin_list' => $plugin_list, ) ); diff --git a/libraries/classes/Controllers/Table/TableSearchController.php b/libraries/classes/Controllers/Table/TableSearchController.php index 8d187af5f617..3f94874c2738 100644 --- a/libraries/classes/Controllers/Table/TableSearchController.php +++ b/libraries/classes/Controllers/Table/TableSearchController.php @@ -525,6 +525,27 @@ public function displaySelectionFormAction($dataLabel = null) ) ) ); + + $column_names = $this->_columnNames; + $column_types = $this->_columnTypes; + $types = array(); + 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 = array(); + 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( Template::get('table/search/selection_form')->render(array( 'search_type' => $this->_searchType, @@ -533,11 +554,13 @@ public function displaySelectionFormAction($dataLabel = null) 'goto' => $goto, 'self' => $this, 'geom_column_flag' => $this->_geomColumnFlag, - 'column_names' => $this->_columnNames, - 'column_types' => $this->_columnTypes, + 'column_names' => $column_names, + 'column_types' => $column_types, + 'types' => $types, 'column_collations' => $this->_columnCollations, 'data_label' => $dataLabel, - 'criteria_column_names' => isset($_POST['criteriaColumnNames']) ? $_POST['criteriaColumnNames'] : null, + 'keys' => $keys, + 'criteria_column_names' => $criteria_column_names, 'criteria_column_types' => isset($_POST['criteriaColumnTypes']) ? $_POST['criteriaColumnTypes'] : null, 'sql_types' => $this->dbi->types, 'max_rows' => intval($GLOBALS['cfg']['MaxRows']), diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index bf9832bd8e83..da541875f32e 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -1308,6 +1308,58 @@ function ($key, $val) { $hideStructureActions = true; } + // logic removed from Template + $rownum = 0; + $columns_list = array(); + $attributes = array(); + $displayed_field_names = array(); + $displayed_field_names_replaced = array(); + $row_comments = array(); + $extracted_columnspecs = array(); + foreach ($fields as $field) { + $rownum += 1; + $columns_list[] = $field['Field']; + + $extracted_columnspecs[$rownum] = Util::extractColumnSpec($field['Type']); + $attributes[$rownum] = $extracted_columnspecs[$rownum]['attribute']; + if (strpos($field['Extra'], 'on update CURRENT_TIMESTAMP') !== false) { + $attributes[$rownum] = 'on update CURRENT_TIMESTAMP'; + } + + if (isset($field['Default'])) { + if ($field['Null'] == 'Yes') { + $field = array_merge($field, array('Default' => 'NULL')); + } + } else { + $field = array_merge($field, array('Default' => $field['Default'])); + } + + $displayed_field_names[$rownum] = $field['Field']; + $row_comments[$rownum] = ''; + + if (isset($comments_map[$field['Field']])) { + $displayed_field_names[$rownum] = '' . htmlspecialchars($field['Field']) . ""; + $row_comments[$rownum] = $comments_map[$field['Field']]; + } + + if ($primary_index && $primary_index->hasColumn($field['Field'])) { + $displayed_field_names[$rownum] = $displayed_field_names[$rownum] . + Util::getImage('b_primary', __('Primary')); + } + + if (in_array($field['Field'], $columns_with_index)) { + $displayed_field_names[$rownum] = $displayed_field_names[$rownum] . + Util::getImage('b_key', __('Index')); + } + $displayed_field_names_replaced[$rownum] = preg_replace( + '/[\\x00-\\x1F]/', + '⁑', + $displayed_field_names[$rownum] + ); + } + return Template::get('table/structure/display_structure')->render( array( 'hide_structure_actions' => $hideStructureActions, @@ -1325,6 +1377,7 @@ function ($key, $val) { 'columns_list' => $columns_list, 'table_stats' => isset($tablestats) ? $tablestats : null, 'fields' => $fields, + 'extracted_columnspecs' => $extracted_columnspecs, 'columns_with_index' => $columns_with_index, 'central_list' => $central_list, 'comments_map' => $comments_map, @@ -1340,6 +1393,11 @@ function ($key, $val) { 'is_active' => Tracker::isActive(), 'have_partitioning' => Partition::havePartitioning(), 'partition_names' => Partition::getPartitionNames($this->db, $this->table), + 'columns_list' => $columns_list, + 'attributes' => $attributes, + 'displayed_field_names' => $displayed_field_names, + 'displayed_field_names_replaced' => $displayed_field_names_replaced, + 'row_comments' => $row_comments, ) ); } diff --git a/libraries/classes/Database/Designer.php b/libraries/classes/Database/Designer.php index eab6605a7e18..18d2ac4cdb7d 100644 --- a/libraries/classes/Database/Designer.php +++ b/libraries/classes/Database/Designer.php @@ -212,7 +212,7 @@ private function getSideMenuParamsArray() $result = $this->dbi->fetchSingleRow($query); - $params = json_decode($result['settings_data'], true); + $params = json_decode((string)$result['settings_data'], true); } return $params; @@ -328,6 +328,32 @@ public function getDatabaseTables( array $tables_all_keys, array $tables_pk_or_unique_keys ) { + $table_names = $GLOBALS['designer']['TABLE_NAME']; + $columns_type = array(); + foreach ($table_names as $table_name) { + $limit = count($tab_column[$table_name]['COLUMN_ID']); + for ($j = 0; $j < $limit; $j++) { + $table_column_name = $table_name . '.' . $tab_column[$table_name]['COLUMN_NAME'][$j]; + if (isset($tables_pk_or_unique_keys[$table_column_name])) { + $columns_type[$table_column_name] = 'designer/FieldKey_small'; + } else { + $columns_type[$table_column_name] = 'designer/Field_small'; + if (strstr($tab_column[$table_name]['TYPE'][$j], 'char') + || strstr($tab_column[$table_name]['TYPE'][$j], 'text')) { + $columns_type[$table_column_name] .= '_char'; + } elseif (strstr($tab_column[$table_name]['TYPE'][$j], 'int') + || strstr($tab_column[$table_name]['TYPE'][$j], 'float') + || strstr($tab_column[$table_name]['TYPE'][$j], 'double') + || strstr($tab_column[$table_name]['TYPE'][$j], 'decimal')) { + $columns_type[$table_column_name] .= '_int'; + } elseif (strstr($tab_column[$table_name]['TYPE'][$j], 'date') + || strstr($tab_column[$table_name]['TYPE'][$j], 'time') + || strstr($tab_column[$table_name]['TYPE'][$j], 'year')) { + $columns_type[$table_column_name] .= '_date'; + } + } + } + } return Template::get('database/designer/database_tables')->render([ 'db' => $GLOBALS['db'], 'get_db' => $_GET['db'], @@ -337,13 +363,14 @@ public function getDatabaseTables( 'tab_column' => $tab_column, 'tables_all_keys' => $tables_all_keys, 'tables_pk_or_unique_keys' => $tables_pk_or_unique_keys, - 'table_names' => $GLOBALS['designer']['TABLE_NAME'], + 'table_names' => $table_names, 'table_names_url' => $GLOBALS['designer_url']['TABLE_NAME'], 'table_names_small' => $GLOBALS['designer']['TABLE_NAME_SMALL'], 'table_names_small_url' => $GLOBALS['designer_url']['TABLE_NAME_SMALL'], 'table_names_small_out' => $GLOBALS['designer_out']['TABLE_NAME_SMALL'], 'table_types' => $GLOBALS['designer']['TABLE_TYPE'], 'owner_out' => $GLOBALS['designer_out']['OWNER'], + 'columns_type' => $columns_type, 'theme' => $GLOBALS['PMA_Theme'], ]); } diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index a539554dcf73..bea4942d3677 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -4448,7 +4448,7 @@ private function _getSortedColumnMessage( $column_for_first_row = mb_strtoupper( mb_substr( - $column_for_first_row, 0, $GLOBALS['cfg']['LimitChars'] + (string) $column_for_first_row, 0, $GLOBALS['cfg']['LimitChars'] ) . '...' ); diff --git a/libraries/classes/Template.php b/libraries/classes/Template.php index 76aea4557d1c..37275ad79f3b 100644 --- a/libraries/classes/Template.php +++ b/libraries/classes/Template.php @@ -15,7 +15,6 @@ use PhpMyAdmin\Twig\IndexExtension; use PhpMyAdmin\Twig\MessageExtension; use PhpMyAdmin\Twig\PartitionExtension; -use PhpMyAdmin\Twig\PhpFunctionsExtension; use PhpMyAdmin\Twig\PluginsExtension; use PhpMyAdmin\Twig\RelationExtension; use PhpMyAdmin\Twig\SanitizeExtension; @@ -77,7 +76,6 @@ protected function __construct($name) $twig->addExtension(new IndexExtension()); $twig->addExtension(new MessageExtension()); $twig->addExtension(new PartitionExtension()); - $twig->addExtension(new PhpFunctionsExtension()); $twig->addExtension(new PluginsExtension()); $twig->addExtension(new RelationExtension()); $twig->addExtension(new SanitizeExtension()); diff --git a/libraries/classes/Twig/PhpFunctionsExtension.php b/libraries/classes/Twig/PhpFunctionsExtension.php deleted file mode 100644 index ac3cabcf2ab3..000000000000 --- a/libraries/classes/Twig/PhpFunctionsExtension.php +++ /dev/null @@ -1,40 +0,0 @@ -getAvailableMimeTypes(); } +// this will be used on templates/columns_definitions/transformation.twig +$mime_type= 'input_transformation'; +if (isset($available_mime[$mime_type]) and is_iterable($available_mime[$mime_type])) { + foreach ($available_mime[$mime_type] as $mimekey => $transform) { + $available_mime[$mime_type . '_file_quoted'][$mimekey] = preg_quote( + $available_mime[$mime_type . '_file'][$mimekey], '@' + ); + } +} + // workaround for field_fulltext, because its submitted indices contain // the index as a value, not a key. Inserted here for easier maintenance // and less code to change in existing files. @@ -380,10 +390,24 @@ ); } + $default_value = ''; + $type_upper = mb_strtoupper($type); + + // For a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value + if (isset($columnMeta['DefaultValue'])) { + $default_value = $columnMeta['DefaultValue']; + } + if ($type_upper == 'BIN)') { + $default_value = Util::convertBitDefaultValue($columnMeta['DefaultValue']); + } elseif ($type_upper == 'BINARY' || $type_upper == 'VARBINARY') { + $default_value = bin2hex($columnMeta['DefaultValue']); + } + $content_cells[$columnNumber] = array( 'column_number' => $columnNumber, 'column_meta' => $columnMeta, - 'type_upper' => mb_strtoupper($type), + 'type_upper' => $type_upper, + 'default_value' => $default_value, 'length_values_input_size' => $length_values_input_size, 'length' => $length, 'extracted_columnspec' => $extracted_columnspec, diff --git a/scripts/generate-twig-cache b/scripts/generate-twig-cache index 65dcb4671aee..571dd3e00df4 100644 --- a/scripts/generate-twig-cache +++ b/scripts/generate-twig-cache @@ -12,7 +12,6 @@ use PhpMyAdmin\Twig\I18nExtension; use PhpMyAdmin\Twig\IndexExtension; use PhpMyAdmin\Twig\MessageExtension; use PhpMyAdmin\Twig\PartitionExtension; -use PhpMyAdmin\Twig\PhpFunctionsExtension; use PhpMyAdmin\Twig\PluginsExtension; use PhpMyAdmin\Twig\RelationExtension; use PhpMyAdmin\Twig\SanitizeExtension; @@ -39,7 +38,6 @@ $twig->addExtension(new I18nExtension()); $twig->addExtension(new IndexExtension()); $twig->addExtension(new MessageExtension()); $twig->addExtension(new PartitionExtension()); -$twig->addExtension(new PhpFunctionsExtension()); $twig->addExtension(new PluginsExtension()); $twig->addExtension(new RelationExtension()); $twig->addExtension(new SanitizeExtension()); diff --git a/templates/columns_definitions/column_attributes.twig b/templates/columns_definitions/column_attributes.twig index e9a5f2d8b50c..848b56d35b4c 100644 --- a/templates/columns_definitions/column_attributes.twig +++ b/templates/columns_definitions/column_attributes.twig @@ -47,6 +47,7 @@ 'ci_offset': ci_offset, 'column_meta': column_meta, 'type_upper': type_upper, + 'default_value': default_value, 'char_editing': char_editing } only %} {% set ci = ci + 1 %} diff --git a/templates/columns_definitions/column_default.twig b/templates/columns_definitions/column_default.twig index b60853987c1f..aee5756814b9 100644 --- a/templates/columns_definitions/column_default.twig +++ b/templates/columns_definitions/column_default.twig @@ -8,17 +8,6 @@ have problems if they forget to enter the default value (example, for an INT) #} 'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP' } %} -{# For a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value #} -{% set default_value = '' %} -{% if column_meta['DefaultValue'] is defined %} - {% set default_value = column_meta['DefaultValue'] %} -{% endif %} -{% if type_upper == 'BIT' %} - {% set default_value = Util_convertBitDefaultValue(column_meta['DefaultValue']) %} -{% elseif type_upper == 'BINARY' or type_upper == 'VARBINARY' %} - {% set default_value = bin2hex(column_meta['DefaultValue']) %} -{% endif %} - - {% if criteria_column_names is defined + {% if criteria_column_names[i] is defined and criteria_column_names[i] != 'pma_null' %} - {% set key = array_search(criteria_column_names[i], column_names) %} + {% set key = keys[criteria_column_names[i]] %} {% set properties = self.getColumnProperties(i, key) %} {% set type = type|merge({i: properties['type']}) %} {% set collation = collation|merge({i: properties['collation']}) %} diff --git a/templates/table/search/search_and_replace.twig b/templates/table/search/search_and_replace.twig index 530ea6df95d6..8237dd599edd 100644 --- a/templates/table/search/search_and_replace.twig +++ b/templates/table/search/search_and_replace.twig @@ -6,11 +6,11 @@ {% trans 'Column:' %}