3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
11 require('./tbl_properties_common.php3');
12 $url_query .= '&goto=tbl_properties.php3';
13 require('./tbl_properties_table_info.php3');
14 require('./libraries/relation.lib.php3');
17 * Gets the relation settings
19 $cfgRelation = PMA_getRelationsParam();
26 if ($cfgRelation['relwork']) {
27 $existrel = PMA_getForeigners($db, $table);
29 if ($cfgRelation['displaywork']) {
30 $disp = PMA_getDisplayField($db, $table);
32 if ($cfgRelation['relwork']
33 && isset($submit_rel) && $submit_rel == 'true') {
35 while (list($key, $value) = each($destination)) {
36 if ($value != 'nix') {
37 $for = explode('.', $value);
38 if (!isset($existrel[$key])) {
39 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
40 . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
42 . '\'' . PMA_sqlAddslashes($db) . '\', '
43 . '\'' . PMA_sqlAddslashes($table) . '\', '
44 . '\'' . PMA_sqlAddslashes($key) . '\', '
45 . '\'' . PMA_sqlAddslashes($for[0]) . '\', '
46 . '\'' . PMA_sqlAddslashes($for[1]) . '\','
47 . '\'' . PMA_sqlAddslashes($for[2]) . '\')';
48 } else if ($existrel[$key] != $value) {
49 $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET'
50 . ' foreign_db = \'' . PMA_sqlAddslashes($for[0]) . '\', '
51 . ' foreign_table = \'' . PMA_sqlAddslashes($for[1]) . '\', '
52 . ' foreign_field = \'' . PMA_sqlAddslashes($for[2]) . '\' '
53 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
54 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
55 . ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
56 } // end if... else....
57 } else if (isset($existrel[$key])) {
58 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
59 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
60 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
61 . ' AND master_field = \'' . PMA_sqlAddslashes($key) . '\'';
62 } // end if... else....
63 if (isset($upd_query)) {
64 $upd_rs = PMA_query_as_cu($upd_query);
70 if ($cfgRelation['displaywork']
71 && isset($submit_show) && $submit_show == 'true') {
74 $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
75 . ' SET display_field = \'' . PMA_sqlAddslashes($display_field) . '\''
76 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
77 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
79 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_info'])
80 . '(db_name, table_name, display_field) '
82 . '\'' . PMA_sqlAddslashes($db) . '\','
83 . '\'' . PMA_sqlAddslashes($table) . '\','
84 . '\'' . PMA_sqlAddslashes($display_field) . '\')';
87 if (isset($upd_query)) {
88 $upd_rs = PMA_query_as_cu($upd_query);
92 if ($cfgRelation['commwork']
93 && isset($submit_comm) && $submit_comm == 'true') {
94 while (list($key, $value) = each($comment)) {
95 // garvin: I exported the snippet here to a function (relation.lib.php3) , so it can be used multiple times throughout other pages where you can set comments.
96 PMA_setComment($db, $table, $key, $value);
97 } // end while (transferred data)
98 } // end if (commwork)
100 // Now that we might have changed we have to see again
101 if ($cfgRelation['relwork']) {
102 $existrel = PMA_getForeigners($db, $table);
104 if ($cfgRelation['displaywork']) {
105 $disp = PMA_getDisplayField($db, $table);
107 if ($cfgRelation['commwork']) {
108 $comments = PMA_getComments($db, $table);
115 if ($cfgRelation['relwork']) {
117 // To choose relations we first need all tables names in current db
118 $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
119 $tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0);
120 $selectboxall['nix'] = '--';
121 while ($curr_table = @PMA_mysql_fetch_array
($tab_rs)) {
122 if (($curr_table[0] != $table) && ($curr_table[0] != $cfg['Server']['relation'])) {
123 $fi_query = 'SHOW KEYS FROM ' . PMA_backquote($curr_table[0]);
124 $fi_rs = PMA_mysql_query($fi_query) or PMA_mysqlDie('', $fi_query, '', $err_url_0);
125 if ($fi_rs && mysql_num_rows($fi_rs) > 0) {
126 while ($curr_field = PMA_mysql_fetch_array($fi_rs)) {
127 if (isset($curr_field['Key_name']) && $curr_field['Key_name'] == 'PRIMARY') {
128 $field_full = $db . '.' .$curr_field['Table'] . '.' . $curr_field['Column_name'];
129 $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
131 } else if (isset($curr_field['Non_unique']) && $curr_field['Non_unique'] == 0) {
132 // if we can't find a primary key we take any unique one
133 $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
134 $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
136 } // end while over keys
137 if (isset($field_full) && isset($field_v)) {
138 $selectboxall[$field_full] = $field_v;
140 } // end if (mysql_num_rows)
141 // Mike Beck - 24.07.02: i've been asked to add all keys of the
142 // current table (see bug report #574851)
144 else if ($curr_table[0] == $table) {
145 $fi_query = 'SHOW KEYS FROM ' . PMA_backquote($curr_table[0]);
146 $fi_rs = PMA_mysql_query($fi_query) or PMA_mysqlDie('', $fi_query, '', $err_url_0);
147 if ($fi_rs && mysql_num_rows($fi_rs) > 0) {
148 while ($curr_field = PMA_mysql_fetch_array($fi_rs)) {
149 $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
150 $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
151 if (isset($field_full) && isset($field_v)) {
152 $selectboxall[$field_full] = $field_v;
155 } // end if (mysql_num_rows)
157 } // end while over tables
159 // Create array of relations (Mike Beck)
160 $rel_dest = PMA_getForeigners($db, $table);
163 // Now find out the columns of our $table
164 $col_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table);
165 $col_rs = PMA_mysql_query($col_query) or PMA_mysqlDie('', $col_query, '', $err_url_0);
167 if ($col_rs && mysql_num_rows($col_rs) > 0) {
168 while ($row = PMA_mysql_fetch_array($col_rs)) {
171 $saved_row_cnt = count($save_row);
174 <form method
="post" action
="tbl_relation.php3">
175 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
176 <input type
="hidden" name
="submit_rel" value
="true" />
180 <th colspan
="2" align
="center"><b
><?php
echo $strLinksTo; ?
></b
></th
>
183 for ($i = 0; $i < $saved_row_cnt; $i++
) {
187 <th
><?php
echo $save_row[$i]['Field']; ?
></th
>
189 <input type
="hidden" name
="src_field" value
="<?php echo $save_row[$i]['Field']; ?>" />
190 <select name
="destination[<?php echo htmlspecialchars($save_row[$i]['Field']); ?>]">
193 reset($selectboxall);
194 $myfield = $save_row[$i]['Field'];
195 if (isset($existrel[$myfield])) {
196 $foreign_field = $existrel[$myfield]['foreign_db'] . '.'
197 . $existrel[$myfield]['foreign_table'] . '.'
198 . $existrel[$myfield]['foreign_field'];
200 $foreign_field = FALSE;
203 while (list($key, $value) = each($selectboxall)) {
205 . '<option value="' . htmlspecialchars($key) . '"';
206 if ($foreign_field && $key == $foreign_field) {
207 echo ' selected="selected"';
210 echo '>' . $value . '</option>'. "\n";
213 // if the link defined in relationtable points to a foreign field
214 // that is not a key in the foreign table, we show the link
215 // (will not be shown with an arrow)
216 if ($foreign_field && !$seen_key) {
218 . '<option value="' . htmlspecialchars($foreign_field) . '"';
219 echo ' selected="selected"';
220 echo '>' . $foreign_field . '</option>'. "\n";
232 <td colspan
="2" align
="center">
233 <input type
="submit" value
="<?php echo $strGo; ?>" />
240 if ($cfgRelation['displaywork']) {
241 // Get "display_filed" infos
242 $disp = PMA_getDisplayField($db, $table);
246 <form method
="post" action
="tbl_relation.php3">
247 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
248 <input type
="hidden" name
="submit_show" value
="true" />
250 <p
><?php
echo $strChangeDisplay; ?
></p
>
251 <select name
="display_field" onchange
="this.form.submit();">
254 mysql_data_seek($col_rs, 0);
255 while ($row = @PMA_mysql_fetch_array
($col_rs)) {
256 echo ' <option value="' . htmlspecialchars($row['Field']) . '"';
257 if (isset($disp) && $row['Field'] == $disp) {
258 echo ' selected="selected"';
260 echo '>' . htmlspecialchars($row['Field']) . '</option>'. "\n";
264 <script type
="text/javascript" language
="javascript">
266 // Fake js to allow the use of the <noscript> tag
270 <input type
="submit" value
="<?php echo $strGo; ?>" />
274 } // end if (displayworks)
276 if ($cfgRelation['commwork']) {
280 <form method
="post" action
="tbl_relation.php3">
281 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
282 <input type
="hidden" name
="submit_comm" value
="true" />
286 <th colspan
="2" align
="center"><b
><?php
echo $strComments; ?
></b
></th
>
289 for ($i = 0; $i < $saved_row_cnt; $i++
) {
290 $field = $save_row[$i]['Field'];
294 <th
><?php
echo $field; ?
></th
>
296 <input type
="text" name
="comment[<?php echo $field; ?>]" value
="<?php echo (isset($comments[$field]) ? htmlspecialchars($comments[$field]) : ''); ?>" />
305 <td colspan
="2" align
="center">
306 <input type
="submit" value
="<?php echo $strGo; ?>" />
312 } // end if (comments work)
313 } // end if (we have columns in this table)
317 * Displays the footer
320 require('./footer.inc.php3');