Fix saving user preferences to configuration storage
[phpmyadmin.git] / tbl_relation.php
blob748fa40a6a8543f3025b0e8799607188397b190c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Display table relations for viewing and editing
6 * includes phpMyAdmin relations and InnoDB relations
8 * @todo fix name handling: currently names with dots (.) are not properly handled
9 * for internal relations (but foreign keys relations are correct)
10 * @todo foreign key constraints require both fields being of equal type and size
11 * @todo check foreign fields to be from same type and size, all other makes no sense
12 * @todo if above todos are fullfilled we can add all fields meet requirements
13 * in the select dropdown
14 * @package PhpMyAdmin
17 /**
18 * Gets some core libraries
20 require_once 'libraries/common.inc.php';
21 require_once 'libraries/index.lib.php';
22 require_once 'libraries/tbl_relation.lib.php';
24 $response = PMA_Response::getInstance();
26 // Send table of column names to populate corresponding dropdowns depending
27 // on the current selection
28 if (isset($_REQUEST['getDropdownValues'])
29 && $_REQUEST['getDropdownValues'] === 'true'
30 ) {
31 PMA_sendHtmlForTableOrColumnDropdownList();
34 $header = $response->getHeader();
35 $scripts = $header->getScripts();
36 $scripts->addFile('tbl_relation.js');
37 $scripts->addFile('indexes.js');
39 /**
40 * Sets globals from $_POST
42 $post_params = array(
43 'destination_foreign_db',
44 'destination_foreign_table',
45 'destination_foreign_column',
46 'display_field',
47 'fields_name',
48 'on_delete',
49 'on_update'
52 foreach ($post_params as $one_post_param) {
53 if (isset($_POST[$one_post_param])) {
54 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
58 /**
59 * Gets tables informations
61 require_once 'libraries/tbl_info.inc.php';
63 $options_array = array(
64 'CASCADE' => 'CASCADE',
65 'SET_NULL' => 'SET NULL',
66 'NO_ACTION' => 'NO ACTION',
67 'RESTRICT' => 'RESTRICT',
70 /**
71 * Gets the relation settings
73 $cfgRelation = PMA_getRelationsParam();
75 /**
76 * Updates
78 if ($cfgRelation['relwork']) {
79 $existrel = PMA_getForeigners($db, $table, '', 'internal');
81 if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
82 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
84 if ($cfgRelation['displaywork']) {
85 $disp = PMA_getDisplayField($db, $table);
88 // will be used in the logic for internal relations and foreign keys:
89 $multi_edit_columns_name = isset($_REQUEST['fields_name'])
90 ? $_REQUEST['fields_name']
91 : null;
94 // u p d a t e s f o r I n t e r n a l r e l a t i o n s
95 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
96 PMA_handleUpdatesForInternalRelations(
97 $_POST['destination_db'], $multi_edit_columns_name,
98 $_POST['destination_table'],
99 $_POST['destination_column'], $cfgRelation, $db, $table,
100 isset($existrel) ? $existrel : null
102 } // end if (updates for internal relations)
104 $html_output = '';
106 // u p d a t e s f o r f o r e i g n k e y s
107 // (for now, one index name only; we keep the definitions if the
108 // foreign db is not the same)
109 if (isset($destination_foreign_db)) {
110 $html_output .= PMA_handleUpdatesForForeignKeys(
111 $destination_foreign_db,
112 $multi_edit_columns_name, $destination_foreign_table,
113 $destination_foreign_column, $options_array, $table,
114 isset($existrel_foreign) ? $existrel_foreign : null
116 } // end if isset($destination_foreign)
119 // U p d a t e s f o r d i s p l a y f i e l d
120 if ($cfgRelation['displaywork'] && isset($display_field)) {
121 PMA_handleUpdateForDisplayField(
122 $disp, $display_field, $db, $table, $cfgRelation
124 } // end if
126 // If we did an update, refresh our data
127 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
128 $existrel = PMA_getForeigners($db, $table, '', 'internal');
130 if (isset($destination_foreign_db)
131 && PMA_Util::isForeignKeySupported($tbl_storage_engine)
133 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
136 if ($cfgRelation['displaywork']) {
137 $disp = PMA_getDisplayField($db, $table);
142 * Dialog
144 // Now find out the columns of our $table
145 // need to use PMA_DatabaseInterface::QUERY_STORE with $GLOBALS['dbi']->numRows()
146 // in mysqli
147 $columns = $GLOBALS['dbi']->getColumns($db, $table);
149 // common form
150 $html_output .= PMA_getHtmlForCommonForm(
151 $db, $table, $columns, $cfgRelation, $tbl_storage_engine, $existrel,
152 $existrel_foreign, $options_array
155 if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
156 $html_output .= PMA_getHtmlForDisplayIndexes();
158 // Render HTML output
159 PMA_Response::getInstance()->addHTML($html_output);