From 4ab83556c628e3c01f446252115f570776003afe Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Thu, 2 Jul 2015 08:07:18 +0530 Subject: Allow using templates created for other databases/tables Signed-off-by: Madhura Jayaratne --- js/export.js | 4 ++++ libraries/display_export.inc.php | 2 +- libraries/display_export.lib.php | 21 ++++++--------------- libraries/plugins/export/ExportSql.class.php | 5 ----- libraries/relation_cleanup.lib.php | 15 --------------- sql/create_tables.sql | 11 +++++------ sql/create_tables_drizzle.sql | 11 +++++------ tbl_export.php | 13 +++---------- 8 files changed, 24 insertions(+), 58 deletions(-) diff --git a/js/export.js b/js/export.js index 4a3c7d94f3..8a9dd28954 100644 --- a/js/export.js +++ b/js/export.js @@ -69,6 +69,7 @@ function createTemplate(name) server : PMA_commonParams.get('server'), db : PMA_commonParams.get('db'), table : PMA_commonParams.get('table'), + exportType : $('input[name="export_type"]').val(), templateAction : 'create', templateName : name, templateData : JSON.stringify(templateData) @@ -99,6 +100,7 @@ function loadTemplate(id) server : PMA_commonParams.get('server'), db : PMA_commonParams.get('db'), table : PMA_commonParams.get('table'), + exportType : $('input[name="export_type"]').val(), templateAction : 'load', templateId : id, }; @@ -144,6 +146,7 @@ function updateTemplate(id) server : PMA_commonParams.get('server'), db : PMA_commonParams.get('db'), table : PMA_commonParams.get('table'), + exportType : $('input[name="export_type"]').val(), templateAction : 'update', templateId : id, templateData : JSON.stringify(templateData) @@ -172,6 +175,7 @@ function deleteTemplate(id) server : PMA_commonParams.get('server'), db : PMA_commonParams.get('db'), table : PMA_commonParams.get('table'), + exportType : $('input[name="export_type"]').val(), templateAction : 'delete', templateId : id, }; diff --git a/libraries/display_export.inc.php b/libraries/display_export.inc.php index 6665bfb90b..9d251a3272 100644 --- a/libraries/display_export.inc.php +++ b/libraries/display_export.inc.php @@ -43,7 +43,7 @@ $html = PMA_getHtmlForExportOptionHeader($export_type, $db, $table); $cfgRelation = PMA_getRelationsParam(); if ($cfgRelation['exporttemplateswork']) { - $html .= PMA_getHtmlForExportTemplateLoading($db, $table); + $html .= PMA_getHtmlForExportTemplateLoading($export_type); } $html .= '
'; @@ -212,7 +211,7 @@ function PMA_getHtmlForExportTemplateLoading($db, $table) $html .= '

' . __('Existing templates:') . '

'; $html .= ''; $html .= ''; $html .= ''; @@ -233,12 +232,11 @@ function PMA_getHtmlForExportTemplateLoading($db, $table) /** * Returns HTML for the options in teplate dropdown * - * @param string $db database - * @param string $table table + * @param string $export_type export type - server, database, or table * * @return string HTML for the options in teplate dropdown */ -function PMA_getOptionsForExportTemplates($db, $table) +function PMA_getOptionsForExportTemplates($export_type) { $ret = ''; @@ -250,14 +248,7 @@ function PMA_getOptionsForExportTemplates($db, $table) . PMA_Util::backquote($cfgRelation['exporttemplates']) . " WHERE `username` = " . "'" . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "'" - . " AND `db_name` " - . (! empty($db) - ? "= '" . PMA_Util::sqlAddSlashes($db) . "'" - : "IS NULL") - . " AND `table_name` " - . (! empty($table) - ? "= '" . PMA_Util::sqlAddSlashes($table) . "'" - : "IS NULL") + . " AND `export_type` = '" . $export_type . "'" . " ORDER BY `template_name`;"; $result = PMA_queryAsControlUser($query); diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index 6f694d4401..59f5c893c8 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -1024,7 +1024,6 @@ class ExportSql extends ExportPlugin 'column_info' => 'db_name', 'table_uiprefs' => 'db_name', 'tracking' => 'db_name', - 'exporttemplates' => 'db_name', ); } else { $types = array( @@ -1034,7 +1033,6 @@ class ExportSql extends ExportPlugin //'table_coords' => 'db_name', 'savedsearches' => 'db_name', 'central_columns' => 'db_name', - 'exporttemplates' => 'db_name', ); } @@ -1077,9 +1075,6 @@ class ExportSql extends ExportPlugin } elseif ($type == 'savedsearches') { $sql_query = "SELECT `username`, `db_name`, `search_name`," . " `search_data` FROM"; - } elseif ($type == 'exporttemplates') { - $sql_query = "SELECT `username`, `db_name`, `table_name`," - . " `template_name`, `template_data` FROM"; } else { $sql_query = "SELECT * FROM "; } diff --git a/libraries/relation_cleanup.lib.php b/libraries/relation_cleanup.lib.php index 08cf37e2c3..1af6bca0de 100644 --- a/libraries/relation_cleanup.lib.php +++ b/libraries/relation_cleanup.lib.php @@ -124,14 +124,6 @@ function PMA_relationsCleanupTable($db, $table) . ' AND item_type = \'table\'))'; PMA_queryAsControlUser($remove_query); } - - if ($cfgRelation['exporttemplateswork']) { - $remove_query = 'DELETE FROM ' . PMA_Util::backquote($cfgRelation['db']) - . '.' . PMA_Util::backquote($cfgRelation['exporttemplates']) - . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'' - . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\''; - PMA_queryAsControlUser($remove_query); - } } /** @@ -219,13 +211,6 @@ function PMA_relationsCleanupDatabase($db) . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''; PMA_queryAsControlUser($remove_query); } - - if ($cfgRelation['exporttemplateswork']) { - $remove_query = 'DELETE FROM ' . PMA_Util::backquote($cfgRelation['db']) - . '.' . PMA_Util::backquote($cfgRelation['exporttemplates']) - . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''; - PMA_queryAsControlUser($remove_query); - } } /** diff --git a/sql/create_tables.sql b/sql/create_tables.sql index 4b78a16e46..2815ac8742 100644 --- a/sql/create_tables.sql +++ b/sql/create_tables.sql @@ -344,13 +344,12 @@ CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( CREATE TABLE IF NOT EXISTS `pma__exporttemplates` ( `id` int(5) unsigned NOT NULL AUTO_INCREMENT, - `username` varchar(64) COLLATE utf8_bin NOT NULL, - `db_name` varchar(64) COLLATE utf8_bin DEFAULT NULL, - `table_name` varchar(64) COLLATE utf8_bin DEFAULT NULL, - `template_name` varchar(64) COLLATE utf8_bin NOT NULL, - `template_data` text COLLATE utf8_bin NOT NULL, + `username` varchar(64) NOT NULL, + `export_type` varchar(10) NOT NULL, + `template_name` varchar(64) NOT NULL, + `template_data` text NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `u_user_db_table_template` (`username`,`db_name`,`table_name`,`template_name`) + UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) ) COMMENT='Saved export templates' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; diff --git a/sql/create_tables_drizzle.sql b/sql/create_tables_drizzle.sql index c3264ab6fd..472e63c945 100644 --- a/sql/create_tables_drizzle.sql +++ b/sql/create_tables_drizzle.sql @@ -296,13 +296,12 @@ CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( CREATE TABLE IF NOT EXISTS `pma__exporttemplates` ( `id` int(5) unsigned NOT NULL AUTO_INCREMENT, - `username` varchar(64) COLLATE utf8_bin NOT NULL, - `db_name` varchar(64) COLLATE utf8_bin DEFAULT NULL, - `table_name` varchar(64) COLLATE utf8_bin DEFAULT NULL, - `template_name` varchar(64) COLLATE utf8_bin NOT NULL, - `template_data` text COLLATE utf8_bin NOT NULL, + `username` varchar(64) NOT NULL, + `export_type` varchar(10) NOT NULL, + `template_name` varchar(64) NOT NULL, + `template_data` text NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `u_user_db_table_template` (`username`,`db_name`,`table_name`,`template_name`) + UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) ) COMMENT='Saved export templates' COLLATE utf8_bin; \ No newline at end of file diff --git a/tbl_export.php b/tbl_export.php index d9eeb701b3..11ef3ea970 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -37,18 +37,11 @@ if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) { if ('create' == $_REQUEST['templateAction']) { $query = "INSERT INTO " . $templateTable . "(" - . " `username`, `db_name`, `table_name`," + . " `username`, `export_type`," . " `template_name`, `template_data`" . ") VALUES (" . "'" . $user . "', " - . (! empty($GLOBALS['db']) - ? "'" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "'" - : 'NULL' - ) . "," - . (! empty($GLOBALS['table']) - ? "'" . PMA_Util::sqlAddSlashes($GLOBALS['table']) . "'" - : 'NULL' - ) . "," + . "'" . PMA_Util::sqlAddSlashes($_REQUEST['exportType']) . "', " . "'" . PMA_Util::sqlAddSlashes($_REQUEST['templateName']) . "', " . "'" . PMA_Util::sqlAddSlashes($_REQUEST['templateData']) . "');"; @@ -80,7 +73,7 @@ if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) { if ('create' == $_REQUEST['templateAction']) { $response->addJSON( 'data', - PMA_getOptionsForExportTemplates($GLOBALS['db'], $GLOBALS['table']) + PMA_getOptionsForExportTemplates($_REQUEST['exportType']) ); } elseif ('load' == $_REQUEST['templateAction']) { $data = null; -- cgit v1.2.3