Translated using Weblate (Slovenian)
[phpmyadmin.git] / tbl_relation.php
blob6b8172b9f2afc34f8a35f6df0d79f0de4aeac7d5
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';
23 require_once 'libraries/structure.lib.php';
25 $response = PMA_Response::getInstance();
27 // Send table of column names to populate corresponding dropdowns depending
28 // on the current selection
29 if (isset($_REQUEST['getDropdownValues'])
30 && $_REQUEST['getDropdownValues'] === 'true'
31 ) {
32 PMA_sendHtmlForTableOrColumnDropdownList();
35 $header = $response->getHeader();
36 $scripts = $header->getScripts();
37 $scripts->addFile('tbl_relation.js');
38 $scripts->addFile('indexes.js');
40 /**
41 * Gets tables informations
43 require_once 'libraries/tbl_info.inc.php';
45 $options_array = array(
46 'CASCADE' => 'CASCADE',
47 'SET_NULL' => 'SET NULL',
48 'NO_ACTION' => 'NO ACTION',
49 'RESTRICT' => 'RESTRICT',
52 /**
53 * Gets the relation settings
55 $cfgRelation = PMA_getRelationsParam();
57 /**
58 * Updates
60 if ($cfgRelation['relwork']) {
61 $existrel = PMA_getForeigners($db, $table, '', 'internal');
63 if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
64 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
66 if ($cfgRelation['displaywork']) {
67 $disp = PMA_getDisplayField($db, $table);
68 } else {
69 $disp = '';
72 // will be used in the logic for internal relations and foreign keys:
73 $multi_edit_columns_name = isset($_REQUEST['fields_name'])
74 ? $_REQUEST['fields_name']
75 : null;
78 $html_output = '';
80 // 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
81 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
82 $html_output .= PMA_handleUpdatesForInternalRelations(
83 $_POST['destination_db'], $multi_edit_columns_name,
84 $_POST['destination_table'],
85 $_POST['destination_column'], $cfgRelation, $db, $table,
86 isset($existrel) ? $existrel : null
88 } // end if (updates for internal relations)
90 $multi_edit_columns_name = isset($_REQUEST['foreign_key_fields_name'])
91 ? $_REQUEST['foreign_key_fields_name']
92 : null;
94 // u p d a t e s f o r f o r e i g n k e y s
95 // (for now, one index name only; we keep the definitions if the
96 // foreign db is not the same)
97 if (isset($_POST['destination_foreign_db'])) {
98 $html_output .= PMA_handleUpdatesForForeignKeys(
99 $_POST['destination_foreign_db'],
100 $multi_edit_columns_name, $_POST['destination_foreign_table'],
101 $_POST['destination_foreign_column'], $options_array, $table,
102 isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : null
104 } // end if isset($destination_foreign)
106 // U p d a t e s f o r d i s p l a y f i e l d
107 if ($cfgRelation['displaywork'] && isset($_POST['display_field'])) {
108 $html_output .= PMA_handleUpdateForDisplayField(
109 $disp, $_POST['display_field'], $db, $table, $cfgRelation
111 } // end if
113 // If we did an update, refresh our data
114 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
115 $existrel = PMA_getForeigners($db, $table, '', 'internal');
117 if (isset($_POST['destination_foreign_db'])
118 && PMA_Util::isForeignKeySupported($tbl_storage_engine)
120 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
123 if ($cfgRelation['displaywork']) {
124 $disp = PMA_getDisplayField($db, $table);
128 // display secondary level tabs if necessary
129 $engine = PMA_Table::sGetStatusInfo($db, $table, 'ENGINE');
130 $response->addHTML(PMA_getStructureSecondaryTabs($engine));
131 $response->addHTML('<div id="structure_content">');
134 * Dialog
136 // Now find out the columns of our $table
137 // need to use PMA_DatabaseInterface::QUERY_STORE with $GLOBALS['dbi']->numRows()
138 // in mysqli
139 $columns = $GLOBALS['dbi']->getColumns($db, $table);
141 // common form
142 $html_output .= PMA_getHtmlForCommonForm(
143 $db, $table, $columns, $cfgRelation, $tbl_storage_engine,
144 isset($existrel) ? $existrel : array(),
145 isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : array(),
146 $options_array
149 if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
150 $html_output .= PMA_getHtmlForDisplayIndexes();
152 // Render HTML output
153 $response->addHTML($html_output);
155 $response->addHTML('</div>');