diff --git a/libraries/index.lib.php b/libraries/index.lib.php
index a9f812013e..dfffccfd83 100644
--- a/libraries/index.lib.php
+++ b/libraries/index.lib.php
@@ -19,7 +19,9 @@ require_once 'libraries/Index.class.php';
*/
function PMA_getHtmlForDisplayIndexes()
{
- $html_output = PMA_Util::getDivForSliderEffect(
+ $html_output = '
';
+
+ $html_output .= PMA_Util::getDivForSliderEffect(
'indexes', __('Indexes')
);
$html_output .= PMA_Index::getView($GLOBALS['table'], $GLOBALS['db']);
diff --git a/libraries/tbl_relation.lib.php b/libraries/tbl_relation.lib.php
index 86b7961fae..40def8f7be 100644
--- a/libraries/tbl_relation.lib.php
+++ b/libraries/tbl_relation.lib.php
@@ -155,4 +155,556 @@ function PMA_generateRelationalDropdown(
$html_output .= '';
return $html_output;
}
-?>
+
+/**
+ * Function to get html for the common form
+ *
+ * @param string $db current database
+ * @param string $table current table
+ * @param array $columns columns
+ * @param array $cfgRelation configuration relation
+ * @param string $tbl_storage_engine table storage engine
+ * @param array $existrel db, table, column
+ * @param array $existrel_foreign db, table, column
+ * @param array $options_array options array
+ *
+ * @return string
+ */
+function PMA_getHtmlForCommonForm($db, $table, $columns, $cfgRelation,
+ $tbl_storage_engine, $existrel, $existrel_foreign, $options_array
+) {
+ $html_output = PMA_getHtmlForCommonFormHeader($db, $table);
+
+ if (count($columns) > 0) {
+ $html_output .= PMA_getHtmlForCommonFormRows(
+ $columns, $cfgRelation, $tbl_storage_engine,
+ $existrel, $existrel_foreign, $options_array, $db, $table
+ );
+ } // end if (we have columns in this table)
+
+ $html_output .= PMA_getHtmlForCommonFormFooter();
+
+ return $html_output;
+}
+
+/**
+ * Function to get html for the common form rows
+ *
+ * @param array $columns columns
+ * @param array $cfgRelation configuration relation
+ * @param string $tbl_storage_engine table storage engine
+ * @param array $existrel db, table, column
+ * @param array $existrel_foreign db, table, column
+ * @param array $options_array options array
+ * @param string $db current database
+ * @param string $table current table
+ *
+ * @return string
+ */
+function PMA_getHtmlForCommonFormRows($columns, $cfgRelation, $tbl_storage_engine,
+ $existrel, $existrel_foreign, $options_array, $db, $table
+) {
+ foreach ($columns as $row) {
+ $save_row[] = $row;
+ }
+
+ $saved_row_cnt = count($save_row);
+
+ $html_output = '
'
+ . '' . __('Relations'). ' '
+ . '';
+
+ $html_output .= PMA_getHtmlForCommonFormTableHeaders(
+ $cfgRelation, $tbl_storage_engine
+ );
+
+ $odd_row = true;
+ for ($i = 0; $i < $saved_row_cnt; $i++) {
+ $html_output .= PMA_getHtmlForRow(
+ $save_row, $i, $odd_row, $cfgRelation, $existrel, $db,
+ $tbl_storage_engine, $existrel_foreign, $options_array
+ );
+ $odd_row = ! $odd_row;
+ } // end for
+
+ $html_output .= '
' . "\n"
+ . ' ' . "\n";
+
+ if ($cfgRelation['displaywork']) {
+ $html_output .= PMA_getHtmlForDisplayFieldInfos($db, $table, $save_row);
+ }
+
+ return $html_output;
+}
+
+/**
+ * Function to get html for an entire row in common form
+ *
+ * @param array $save_row save row
+ * @param int $i counter
+ * @param bool $odd_row whether odd row or not
+ * @param array $cfgRelation configuration relation
+ * @param array $existrel db, table, column
+ * @param string $db current db
+ * @param string $tbl_storage_engine table storage engine
+ * @param array $existrel_foreign db, table, column
+ * @param array $options_array options array
+ *
+ * @return string
+ */
+function PMA_getHtmlForRow($save_row, $i, $odd_row, $cfgRelation, $existrel, $db,
+ $tbl_storage_engine, $existrel_foreign, $options_array
+) {
+ $myfield = $save_row[$i]['Field'];
+ // Use an md5 as array index to avoid having special characters
+ // in the name atttibure (see bug #1746964 )
+ $myfield_md5 = md5($myfield);
+ $myfield_html = htmlspecialchars($myfield);
+
+ $html_output = '
'
+ . ''
+ . '' . $myfield_html . ' '
+ . ' '
+ . ' ';
+
+ if ($cfgRelation['relwork']) {
+ $html_output .= '';
+
+ $foreign_db = false;
+ $foreign_table = false;
+ $foreign_column = false;
+
+ // database dropdown
+ if (isset($existrel[$myfield])) {
+ $foreign_db = $existrel[$myfield]['foreign_db'];
+ } else {
+ $foreign_db = $db;
+ }
+ $html_output .= PMA_generateRelationalDropdown(
+ 'destination_db[' . $myfield_md5 . ']',
+ $GLOBALS['pma']->databases,
+ $foreign_db,
+ __('Database')
+ );
+ // end of database dropdown
+
+ // table dropdown
+ $tables = array();
+ if ($foreign_db) {
+ if (isset($existrel[$myfield])) {
+ $foreign_table = $existrel[$myfield]['foreign_table'];
+ }
+ $tables_rs = $GLOBALS['dbi']->query(
+ 'SHOW TABLES FROM ' . PMA_Util::backquote($foreign_db),
+ null,
+ PMA_DatabaseInterface::QUERY_STORE
+ );
+ while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
+ $tables[] = $row[0];
+ }
+ }
+ $html_output .= PMA_generateRelationalDropdown(
+ 'destination_table[' . $myfield_md5 . ']',
+ $tables,
+ $foreign_table,
+ __('Table')
+ );
+ // end of table dropdown
+
+ // column dropdown
+ $columns = array();
+ if ($foreign_db && $foreign_table) {
+ if (isset($existrel[$myfield])) {
+ $foreign_column = $existrel[$myfield]['foreign_field'];
+ }
+ $table_obj = new PMA_Table($foreign_table, $foreign_db);
+ $columns = $table_obj->getUniqueColumns(false, false);
+ }
+ $html_output .= PMA_generateRelationalDropdown(
+ 'destination_column[' . $myfield_md5 . ']',
+ $columns,
+ $foreign_column,
+ __('Column')
+ );
+ // end of column dropdown
+
+ $html_output .= ' ';
+ } // end if (internal relations)
+
+ if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
+ $html_output .= PMA_getHtmlForForeignKey(
+ $save_row, $i, $existrel_foreign, $myfield, $db,
+ $myfield_md5, $tbl_storage_engine, $options_array
+ );
+ } // end if (InnoDB)
+ $html_output .= ' ';
+
+ return $html_output;
+}
+
+/**
+ * Function to get html for the common form header
+ *
+ * @param string $db current database
+ * @param string $table current table
+ *
+ * @return string
+ */
+function PMA_getHtmlForCommonFormHeader($db, $table)
+{
+ return '
';
+}
+
+/**
+ * Function to get html for display field infos
+ *
+ * @param string $db current database
+ * @param string $table current table
+ * @param array $save_row save row
+ *
+ * @return string
+ */
+function PMA_getHtmlForDisplayFieldInfos($db, $table, $save_row)
+{
+ $disp = PMA_getDisplayField($db, $table);
+ $html_output = '
'
+ . '' . __('Choose column to display:') . ' '
+ . ''
+ . '--- ';
+
+ foreach ($save_row as $row) {
+ $html_output .= ''. "\n";
+ } // end while
+
+ $html_output .= ' '
+ . ' ';
+
+ return $html_output;
+}
+
+/**
+ * Function to get html for the common form title headers
+ *
+ * @param array $cfgRelation configuration relation
+ * @param string $tbl_storage_engine table storage engine
+ *
+ * @return string
+ */
+function PMA_getHtmlForCommonFormTableHeaders($cfgRelation, $tbl_storage_engine)
+{
+ $html_output = '
' . __('Column') . ' ';
+
+ if ($cfgRelation['relwork']) {
+ $html_output .= '' . __('Internal relation');
+ if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
+ $html_output .= PMA_Util::showHint(
+ __(
+ 'An internal relation is not necessary when a corresponding'
+ . ' FOREIGN KEY relation exists.'
+ )
+ );
+ }
+ $html_output .= ' ';
+ }
+
+ if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
+ // this does not have to be translated, it's part of the MySQL syntax
+ $html_output .= '' . __('Foreign key constraint')
+ . ' (' . $tbl_storage_engine . ')';
+ $html_output .= ' ';
+ }
+ $html_output .= '';
+
+ return $html_output;
+}
+
+/**
+ * Function to get html for the foreign key
+ *
+ * @param array $save_row save row
+ * @param int $i counter
+ * @param array $existrel_foreign db, table, columns
+ * @param string $myfield my field
+ * @param string $db current database
+ * @param string $myfield_md5 my field md5
+ * @param string $tbl_storage_engine table storage engine
+ * @param array $options_array options array
+ *
+ * @return string
+ */
+function PMA_getHtmlForForeignKey($save_row, $i, $existrel_foreign, $myfield, $db,
+ $myfield_md5, $tbl_storage_engine, $options_array
+) {
+ $html_output = '
';
+ if (! empty($save_row[$i]['Key'])) {
+
+ $foreign_db = false;
+ $foreign_table = false;
+ $foreign_column = false;
+
+ // foreign database dropdown
+ if (isset($existrel_foreign[$myfield])) {
+ $foreign_db = $existrel_foreign[$myfield]['foreign_db'];
+ } else {
+ $foreign_db = $db;
+ }
+ $html_output .= '';
+ $html_output .= PMA_generateRelationalDropdown(
+ 'destination_foreign_db[' . $myfield_md5 . ']',
+ $GLOBALS['pma']->databases,
+ $foreign_db,
+ __('Database')
+ );
+ // end of foreign database dropdown
+
+ // foreign table dropdown
+ $tables = array();
+ if ($foreign_db) {
+ if (isset($existrel_foreign[$myfield])) {
+ $foreign_table = $existrel_foreign[$myfield]['foreign_table'];
+ }
+ $tables_rs = $GLOBALS['dbi']->query(
+ 'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($foreign_db),
+ null,
+ PMA_DatabaseInterface::QUERY_STORE
+ );
+ while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
+ if (isset($row[1])
+ && strtoupper($row[1]) == $tbl_storage_engine
+ ) {
+ $tables[] = $row[0];
+ }
+ }
+ }
+ $html_output .= PMA_generateRelationalDropdown(
+ 'destination_foreign_table[' . $myfield_md5 . ']',
+ $tables,
+ $foreign_table,
+ __('Table')
+ );
+ // end of foreign table dropdown
+
+ // foreign column dropdown
+ $columns = array();
+ if ($foreign_db && $foreign_table) {
+ if (isset($existrel_foreign[$myfield])) {
+ $foreign_column = $existrel_foreign[$myfield]['foreign_field'];
+ }
+ $table_obj = new PMA_Table($foreign_table, $foreign_db);
+ $columns = $table_obj->getUniqueColumns(false, false);
+ }
+ $html_output .= PMA_generateRelationalDropdown(
+ 'destination_foreign_column[' . $myfield_md5 . ']',
+ $columns,
+ $foreign_column,
+ __('Column')
+ );
+ $html_output .= ' ';
+ // end of foreign column dropdown
+
+ // For constraint name
+ $html_output .= '';
+ $constraint_name = isset($existrel_foreign[$myfield]['constraint'])
+ ? $existrel_foreign[$myfield]['constraint'] : '';
+ $html_output .= __('Constraint name');
+ $html_output .= ' ';
+ $html_output .= ' ' . "\n";
+
+ $html_output .= '';
+ // For ON DELETE and ON UPDATE, the default action
+ // is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
+ // won't display the clause if it's set as RESTRICT.
+ $on_delete = isset($existrel_foreign[$myfield]['on_delete'])
+ ? $existrel_foreign[$myfield]['on_delete'] : 'RESTRICT';
+ $html_output .= PMA_generateDropdown(
+ 'ON DELETE',
+ 'on_delete[' . $myfield_md5 . ']',
+ $options_array,
+ $on_delete
+ );
+ $html_output .= ' ' . "\n";
+
+ $html_output .= '' . "\n";
+ $on_update = isset($existrel_foreign[$myfield]['on_update'])
+ ? $existrel_foreign[$myfield]['on_update'] : 'RESTRICT';
+ $html_output .= PMA_generateDropdown(
+ 'ON UPDATE',
+ 'on_update[' . $myfield_md5 . ']',
+ $options_array,
+ $on_update
+ );
+ $html_output .= ' ' . "\n";
+ } else {
+ $html_output .= __('No index defined! Create one below');
+ } // end if (a key exists)
+ $html_output .= ' ';
+
+ return $html_output;
+}
+
+/**
+ * Function to send html for table or column dropdown list
+ *
+ * @retrun void
+ */
+function PMA_sendHtmlForTableOrColumnDropdownList()
+{
+ if (isset($_REQUEST['foreignTable'])) { // if both db and table are selected
+ PMA_sendHtmlForColumnDorpdownList();
+ } else { // if only the db is selected
+ PMA_sendHtmlForTableDropdownList();
+ }
+ exit;
+}
+
+/**
+ * Function to send html for column dropdown list
+ *
+ * @return void
+ */
+function PMA_sendHtmlForColumnDorpdownList()
+{
+ $response = PMA_Response::getInstance();
+
+ $foreignTable = $_REQUEST['foreignTable'];
+ $table_obj = new PMA_Table($foreignTable, $_REQUEST['foreignDb']);
+ $columns = array();
+ foreach ($table_obj->getUniqueColumns(false, false) as $column) {
+ $columns[] = htmlspecialchars($column);
+ }
+ $response->addJSON('columns', $columns);
+}
+
+/**
+ * Function to send html for table dropdown list
+ *
+ * @return void
+ */
+function PMA_sendHtmlForTableDropdownList()
+{
+ $response = PMA_Response::getInstance();
+
+ $foreign = isset($_REQUEST['foreign']) && $_REQUEST['foreign'] === 'true';
+ if ($foreign) {
+ $query = 'SHOW TABLE STATUS FROM '
+ . PMA_Util::backquote($_REQUEST['foreignDb']);
+ $tbl_storage_engine = strtoupper(
+ PMA_Table::sGetStatusInfo(
+ $_REQUEST['db'],
+ $_REQUEST['table'],
+ 'Engine'
+ )
+ );
+ } else {
+ $query = 'SHOW TABLES FROM '
+ . PMA_Util::backquote( $_REQUEST['foreignDb']);
+ }
+ $tables_rs = $GLOBALS['dbi']->query(
+ $query,
+ null,
+ PMA_DatabaseInterface::QUERY_STORE
+ );
+ $tables = array();
+ while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
+ if ($foreign) {
+ if (isset($row[1])
+ && strtoupper($row[1]) == $tbl_storage_engine
+ ) {
+ $tables[] = htmlspecialchars($row[0]);
+ }
+ } else {
+ $tables[] = htmlspecialchars($row[0]);
+ }
+ }
+ $response->addJSON('tables', $tables);
+}
+
+/**
+ * Function to handle update for display field
+ *
+ * @param string $disp field name
+ * @param string $display_field display field
+ * @param string $db current database
+ * @param string $table current table
+ * @param array $cfgRelation configuration relation
+ *
+ * @return void
+ */
+function PMA_handleUpdateForDisplayField($disp, $display_field, $db, $table,
+ $cfgRelation
+) {
+ $upd_query = PMA_getQueryForDisplayUpdate(
+ $disp, $display_field, $db, $table, $cfgRelation
+ );
+ if ($upd_query) {
+ PMA_queryAsControlUser($upd_query);
+ }
+}
+
+/**
+ * Function to get display query for handlingdisplay update
+ *
+ * @param string $disp field name
+ * @param string $display_field display field
+ * @param string $db current database
+ * @param string $table current table
+ * @param array $cfgRelation configuration relation
+ *
+ * @return string
+ */
+function PMA_getQueryForDisplayUpdate($disp, $display_field, $db, $table,
+ $cfgRelation
+) {
+ $upd_query = false;
+ if ($disp) {
+ if ($display_field != '') {
+ $upd_query = 'UPDATE '
+ . PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
+ . '.' . PMA_Util::backquote($cfgRelation['table_info'])
+ . ' SET display_field = \''
+ . PMA_Util::sqlAddSlashes($display_field) . '\''
+ . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
+ . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\'';
+ } else {
+ $upd_query = 'DELETE FROM '
+ . PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
+ . '.' . PMA_Util::backquote($cfgRelation['table_info'])
+ . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
+ . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\'';
+ }
+ } elseif ($display_field != '') {
+ $upd_query = 'INSERT INTO '
+ . PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
+ . '.' . PMA_Util::backquote($cfgRelation['table_info'])
+ . '(db_name, table_name, display_field) VALUES('
+ . '\'' . PMA_Util::sqlAddSlashes($db) . '\','
+ . '\'' . PMA_Util::sqlAddSlashes($table) . '\','
+ . '\'' . PMA_Util::sqlAddSlashes($display_field) . '\')';
+ }
+
+ return $upd_query;
+}
+?>
\ No newline at end of file
diff --git a/tbl_relation.php b/tbl_relation.php
index b78e0877f5..a8a58defcc 100644
--- a/tbl_relation.php
+++ b/tbl_relation.php
@@ -28,51 +28,7 @@ $response = PMA_Response::getInstance();
if (isset($_REQUEST['getDropdownValues'])
&& $_REQUEST['getDropdownValues'] === 'true'
) {
- $foreignDb = $_REQUEST['foreignDb'];
-
- if (isset($_REQUEST['foreignTable'])) { // if both db and table are selected
- $foreignTable = $_REQUEST['foreignTable'];
- $table_obj = new PMA_Table($foreignTable, $foreignDb);
- $columns = array();
- foreach ($table_obj->getUniqueColumns(false, false) as $column) {
- $columns[] = htmlspecialchars($column);
- }
- $response->addJSON('columns', $columns);
-
- } else { // if only the db is selected
- $foreign = isset($_REQUEST['foreign']) && $_REQUEST['foreign'] === 'true';
- if ($foreign) {
- $query = 'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($foreignDb);
- $tbl_storage_engine = strtoupper(
- PMA_Table::sGetStatusInfo(
- $_REQUEST['db'],
- $_REQUEST['table'],
- 'Engine'
- )
- );
- } else {
- $query = 'SHOW TABLES FROM ' . PMA_Util::backquote($foreignDb);
- }
- $tables_rs = $GLOBALS['dbi']->query(
- $query,
- null,
- PMA_DatabaseInterface::QUERY_STORE
- );
- $tables = array();
- while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
- if ($foreign) {
- if (isset($row[1])
- && strtoupper($row[1]) == $tbl_storage_engine
- ) {
- $tables[] = htmlspecialchars($row[0]);
- }
- } else {
- $tables[] = htmlspecialchars($row[0]);
- }
- }
- $response->addJSON('tables', $tables);
- }
- exit;
+ PMA_sendHtmlForTableOrColumnDropdownList();
}
$header = $response->getHeader();
@@ -324,36 +280,9 @@ if (isset($destination_foreign_db)) {
// U p d a t e s f o r d i s p l a y f i e l d
if ($cfgRelation['displaywork'] && isset($display_field)) {
- $upd_query = false;
- if ($disp) {
- if ($display_field != '') {
- $upd_query = 'UPDATE '
- . PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
- . '.' . PMA_Util::backquote($cfgRelation['table_info'])
- . ' SET display_field = \''
- . PMA_Util::sqlAddSlashes($display_field) . '\''
- . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
- . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\'';
- } else {
- $upd_query = 'DELETE FROM '
- . PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
- . '.' . PMA_Util::backquote($cfgRelation['table_info'])
- . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
- . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\'';
- }
- } elseif ($display_field != '') {
- $upd_query = 'INSERT INTO '
- . PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
- . '.' . PMA_Util::backquote($cfgRelation['table_info'])
- . '(db_name, table_name, display_field) VALUES('
- . '\'' . PMA_Util::sqlAddSlashes($db) . '\','
- . '\'' . PMA_Util::sqlAddSlashes($table) . '\','
- . '\'' . PMA_Util::sqlAddSlashes($display_field) . '\')';
- }
-
- if ($upd_query) {
- PMA_queryAsControlUser($upd_query);
- }
+ PMA_handleUpdateForDisplayField(
+ $disp, $display_field, $db, $table, $cfgRelation
+ );
} // end if
// If we did an update, refresh our data
@@ -374,273 +303,19 @@ if ($cfgRelation['displaywork']) {
/**
* Dialog
*/
-
-// common form
-$html_output .= '
';
-} // end if (we have columns in this table)
+// common form
+$html_output .= PMA_getHtmlForCommonForm(
+ $db, $table, $columns, $cfgRelation, $tbl_storage_engine, $existrel,
+ $existrel_foreign, $options_array
+);
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
- $html_output .= '
'
- . PMA_getHtmlForDisplayIndexes();
+ $html_output .= PMA_getHtmlForDisplayIndexes();
}
// Render HTML output
PMA_Response::getInstance()->addHTML($html_output);