Start PHP from main script for selenium tests
[phpmyadmin.git] / tbl_relation.php
blob44fa1b68e565e26389f4fa6dd80c063461e8ee0c
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 * Gets tables informations
42 require_once 'libraries/tbl_info.inc.php';
44 $options_array = array(
45 'CASCADE' => 'CASCADE',
46 'SET_NULL' => 'SET NULL',
47 'NO_ACTION' => 'NO ACTION',
48 'RESTRICT' => 'RESTRICT',
51 /**
52 * Gets the relation settings
54 $cfgRelation = PMA_getRelationsParam();
56 /**
57 * Updates
59 if ($cfgRelation['relwork']) {
60 $existrel = PMA_getForeigners($db, $table, '', 'internal');
62 if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
63 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
65 if ($cfgRelation['displaywork']) {
66 $disp = PMA_getDisplayField($db, $table);
67 } else {
68 $disp = '';
71 // will be used in the logic for internal relations and foreign keys:
72 $multi_edit_columns_name = isset($_REQUEST['fields_name'])
73 ? $_REQUEST['fields_name']
74 : null;
77 $html_output = '';
79 // 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
80 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
81 $html_output .= PMA_handleUpdatesForInternalRelations(
82 $_POST['destination_db'], $multi_edit_columns_name,
83 $_POST['destination_table'],
84 $_POST['destination_column'], $cfgRelation, $db, $table,
85 isset($existrel) ? $existrel : null
87 } // end if (updates for internal relations)
89 $multi_edit_columns_name = isset($_REQUEST['foreign_key_fields_name'])
90 ? $_REQUEST['foreign_key_fields_name']
91 : null;
93 // u p d a t e s f o r f o r e i g n k e y s
94 // (for now, one index name only; we keep the definitions if the
95 // foreign db is not the same)
96 if (isset($_POST['destination_foreign_db'])) {
97 $html_output .= PMA_handleUpdatesForForeignKeys(
98 $_POST['destination_foreign_db'],
99 $multi_edit_columns_name, $_POST['destination_foreign_table'],
100 $_POST['destination_foreign_column'], $options_array, $table,
101 isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : null
103 } // end if isset($destination_foreign)
105 // U p d a t e s f o r d i s p l a y f i e l d
106 if ($cfgRelation['displaywork'] && isset($_POST['display_field'])) {
107 $html_output .= PMA_handleUpdateForDisplayField(
108 $disp, $_POST['display_field'], $db, $table, $cfgRelation
110 } // end if
112 // If we did an update, refresh our data
113 if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
114 $existrel = PMA_getForeigners($db, $table, '', 'internal');
116 if (isset($_POST['destination_foreign_db'])
117 && PMA_Util::isForeignKeySupported($tbl_storage_engine)
119 $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
122 if ($cfgRelation['displaywork']) {
123 $disp = PMA_getDisplayField($db, $table);
128 * Dialog
130 // Now find out the columns of our $table
131 // need to use PMA_DatabaseInterface::QUERY_STORE with $GLOBALS['dbi']->numRows()
132 // in mysqli
133 $columns = $GLOBALS['dbi']->getColumns($db, $table);
135 // common form
136 $html_output .= PMA_getHtmlForCommonForm(
137 $db, $table, $columns, $cfgRelation, $tbl_storage_engine,
138 isset($existrel) ? $existrel : array(),
139 isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : array(),
140 $options_array
143 if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
144 $html_output .= PMA_getHtmlForDisplayIndexes();
146 // Render HTML output
147 PMA_Response::getInstance()->addHTML($html_output);