2.3.3
[phpmyadmin/crack.git] / tbl_relation.php3
blobf8dec0fca14c009c880e1f7fc1069bf8567be8a4
1 <?php
2 /* $Id$ */
5 /**
6 * Gets some core libraries
7 */
8 require('./libraries/grab_globals.lib.php3');
9 require('./libraries/common.lib.php3');
10 require('./tbl_properties_common.php3');
11 $url_query .= '&amp;goto=tbl_properties.php3';
12 require('./tbl_properties_table_info.php3');
13 require('./libraries/relation.lib.php3');
16 /**
17 * Gets the relation settings
19 $cfgRelation = PMA_getRelationsParam();
22 /**
23 * Adds/removes slashes if required
25 * @param string the string to slash
27 * @return string the slashed string
29 * @access public
31 function PMA_handleSlashes($val) {
32 return (get_magic_quotes_gpc() ? str_replace('\\"', '"', $val) : PMA_sqlAddslashes($val));
33 } // end of the "PMA_handleSlashes()" function
36 /**
37 * Updates
39 if (get_magic_quotes_gpc()) {
40 $db = stripslashes($db);
41 $table = stripslashes($table);
44 if ($cfgRelation['relwork']) {
45 $existrel = PMA_getForeigners($db, $table);
47 if ($cfgRelation['displaywork']) {
48 $disp = PMA_getDisplayField($db, $table);
50 if ($cfgRelation['relwork']
51 && isset($submit_rel) && $submit_rel == 'true') {
53 while (list($key, $value) = each($destination)) {
54 if ($value != 'nix') {
55 $for = explode('.', $value);
56 if (!isset($existrel[$key])) {
57 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['relation'])
58 . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)'
59 . ' values('
60 . '\'' . PMA_sqlAddslashes($db) . '\', '
61 . '\'' . PMA_sqlAddslashes($table) . '\', '
62 . '\'' . PMA_handleSlashes($key) . '\', '
63 . '\'' . PMA_handleSlashes($for[0]) . '\', '
64 . '\'' . PMA_handleSlashes($for[1]) . '\','
65 . '\'' . PMA_handleSlashes($for[2]) . '\')';
66 } else if ($existrel[$key] != $value) {
67 $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET'
68 . ' foreign_db = \'' . PMA_handleSlashes($for[0]) . '\', '
69 . ' foreign_table = \'' . PMA_handleSlashes($for[1]) . '\', '
70 . ' foreign_field = \'' . PMA_handleSlashes($for[2]) . '\' '
71 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
72 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
73 . ' AND master_field = \'' . PMA_handleSlashes($key) . '\'';
74 } // end if... else....
75 } else if (isset($existrel[$key])) {
76 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['relation'])
77 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
78 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
79 . ' AND master_field = \'' . PMA_handleSlashes($key) . '\'';
80 } // end if... else....
81 if (isset($upd_query)) {
82 $upd_rs = PMA_query_as_cu($upd_query);
83 unset($upd_query);
85 } // end while
86 } // end if
88 if ($cfgRelation['displaywork']
89 && isset($submit_show) && $submit_show == 'true') {
91 if ($disp) {
92 $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
93 . ' SET display_field = \'' . PMA_handleSlashes($display_field) . '\''
94 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
95 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
96 } else {
97 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_info'])
98 . '(db_name, table_name, display_field) '
99 . ' VALUES('
100 . '\'' . PMA_sqlAddslashes($db) . '\','
101 . '\'' . PMA_sqlAddslashes($table) . '\','
102 . '\'' . PMA_handleSlashes($display_field) . '\')';
104 if (isset($upd_query)) {
105 $upd_rs = PMA_query_as_cu($upd_query);
107 } // end if
109 if ($cfgRelation['commwork']
110 && isset($submit_comm) && $submit_comm == 'true') {
111 while (list($key, $value) = each($comment)) {
112 $test_qry = 'SELECT comment FROM ' . PMA_backquote($cfgRelation['column_comments'])
113 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
114 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
115 . ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
116 $test_rs = PMA_query_as_cu($test_qry);
117 if ($test_rs && mysql_num_rows($test_rs) > 0) {
118 if (strlen($value) > 0) {
119 $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments'])
120 . ' SET comment = \'' . PMA_handleSlashes($value) . '\''
121 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
122 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
123 . ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
124 } else {
125 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments'])
126 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
127 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
128 . ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
130 } else if (strlen($value) > 0) {
131 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
132 . ' (db_name, table_name, column_name, comment) '
133 . ' VALUES('
134 . '\'' . PMA_sqlAddslashes($db) . '\','
135 . '\'' . PMA_sqlAddslashes($table) . '\','
136 . '\'' . PMA_handleSlashes($key) . '\','
137 . '\'' . PMA_handleSlashes($value) . '\')';
139 if (isset($upd_query)){
140 $upd_rs = PMA_query_as_cu($upd_query);
142 } // end while (transferred data)
143 } // end if (commwork)
145 // Now that we might have changed we have to see again
146 if ($cfgRelation['relwork']) {
147 $existrel = PMA_getForeigners($db, $table);
149 if ($cfgRelation['displaywork']) {
150 $disp = PMA_getDisplayField($db, $table);
152 if ($cfgRelation['commwork']) {
153 $comments = PMA_getComments($db, $table);
158 * Dialog
160 if ($cfgRelation['relwork']) {
162 // To choose relations we first need all tables names in current db
163 $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
164 $tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0);
165 $selectboxall['nix'] = '--';
166 while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
167 if (($curr_table[0] != $table) && ($curr_table[0] != $cfg['Server']['relation'])) {
168 $fi_query = 'SHOW KEYS FROM ' . PMA_backquote($curr_table[0]);
169 $fi_rs = PMA_mysql_query($fi_query) or PMA_mysqlDie('', $fi_query, '', $err_url_0);
170 if ($fi_rs && mysql_num_rows($fi_rs) > 0) {
171 while ($curr_field = PMA_mysql_fetch_array($fi_rs)) {
172 if (isset($curr_field['Key_name']) && $curr_field['Key_name'] == 'PRIMARY') {
173 $field_full = $db . '.' .$curr_field['Table'] . '.' . $curr_field['Column_name'];
174 $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
175 break;
176 } else if (isset($curr_field['non_unique']) && $curr_field['non_unique'] == 0) {
177 // if we can't find a primary key we take any unique one
178 $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
179 $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
180 } // end if
181 } // end while over keys
182 if (isset($field_full) && isset($field_v)) {
183 $selectboxall[$field_full] = $field_v;
185 } // end if (mysql_num_rows)
186 // Mike Beck - 24.07.02: i've been asked to add all keys of the
187 // current table (see bug report #574851)
189 else if ($curr_table[0] == $table) {
190 $fi_query = 'SHOW KEYS FROM ' . PMA_backquote($curr_table[0]);
191 $fi_rs = PMA_mysql_query($fi_query) or PMA_mysqlDie('', $fi_query, '', $err_url_0);
192 if ($fi_rs && mysql_num_rows($fi_rs) > 0) {
193 while ($curr_field = PMA_mysql_fetch_array($fi_rs)) {
194 $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name'];
195 $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name'];
196 if (isset($field_full) && isset($field_v)) {
197 $selectboxall[$field_full] = $field_v;
199 } // end while
200 } // end if (mysql_num_rows)
202 } // end while over tables
204 // Create array of relations (Mike Beck)
205 $rel_dest = PMA_getForeigners($db, $table);
206 } // end if
208 // Now find out the columns of our $table
209 $col_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table);
210 $col_rs = PMA_mysql_query($col_query) or PMA_mysqlDie('', $col_query, '', $err_url_0);
212 if ($col_rs && mysql_num_rows($col_rs) > 0) {
213 while ($row = PMA_mysql_fetch_array($col_rs)) {
214 $save_row[] = $row;
216 $saved_row_cnt = count($save_row);
219 <form method="post" action="tbl_relation.php3">
220 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
221 <input type="hidden" name="server" value="<?php echo $server; ?>" />
222 <input type="hidden" name="db" value="<?php echo $db; ?>" />
223 <input type="hidden" name="table" value="<?php echo $table; ?>" />
224 <input type="hidden" name="submit_rel" value="true" />
226 <table>
227 <tr>
228 <th colspan="2" align="center"><b><?php echo $strLinksTo; ?></b></th>
229 </tr>
230 <?php
231 for ($i = 0; $i < $saved_row_cnt; $i++) {
232 echo "\n";
234 <tr>
235 <th><?php echo $save_row[$i]['Field']; ?></th>
236 <td>
237 <input type="hidden" name="src_field" value="<?php echo $save_row[$i]['Field']; ?>" />
238 <select name="destination[<?php echo htmlspecialchars($save_row[$i]['Field']); ?>]">
239 <?php
240 echo "\n";
241 reset($selectboxall);
242 while (list($key, $value) = each($selectboxall)) {
243 $myfield = $save_row[$i]['Field'];
244 if (isset($existrel[$myfield])) {
245 $test = $existrel[$myfield]['foreign_db'] . '.'
246 . $existrel[$myfield]['foreign_table'] . '.'
247 . $existrel[$myfield]['foreign_field'];
248 } else {
249 $test = FALSE;
251 echo ' '
252 . '<option value="' . htmlspecialchars($key) . '"';
253 if ($test && $key == $test) {
254 echo ' selected="selected"';
256 echo '>' . $value . '</option>'. "\n";
257 } // end while
259 </select>
260 </td>
261 </tr>
262 <?php
263 } // end for
265 echo "\n";
267 <tr>
268 <td colspan="2" align="center">
269 <input type="submit" value="<?php echo $strGo; ?>" />
270 </td>
271 </tr>
272 </table>
273 </form>
275 <?php
276 if ($cfgRelation['displaywork']) {
277 // Get "display_filed" infos
278 $disp = PMA_getDisplayField($db, $table);
280 echo "\n";
282 <form method="post" action="tbl_relation.php3">
283 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
284 <input type="hidden" name="server" value="<?php echo $server; ?>" />
285 <input type="hidden" name="db" value="<?php echo $db; ?>" />
286 <input type="hidden" name="table" value="<?php echo $table; ?>" />
287 <input type="hidden" name="submit_show" value="true" />
289 <p><?php echo $strChangeDisplay; ?></p>
290 <select name="display_field" onchange="this.form.submit();">
291 <?php
292 echo "\n";
293 mysql_data_seek($col_rs, 0);
294 while ($row = @PMA_mysql_fetch_array($col_rs)) {
295 echo ' <option value="' . htmlspecialchars($row['Field']) . '"';
296 if (isset($disp) && $row['Field'] == $disp) {
297 echo ' selected="selected"';
299 echo '>' . htmlspecialchars($row['Field']) . '</option>'. "\n";
300 } // end while
302 </select>
303 <script type="text/javascript" language="javascript">
304 <!--
305 // Fake js to allow the use of the <noscript> tag
306 //-->
307 </script>
308 <noscript>
309 <input type="submit" value="<?php echo $strGo; ?>" />
310 </noscript>
311 </form>
312 <?php
313 } // end if (displayworks)
315 if ($cfgRelation['commwork']) {
317 echo "\n";
319 <form method="post" action="tbl_relation.php3">
320 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
321 <input type="hidden" name="server" value="<?php echo $server; ?>" />
322 <input type="hidden" name="db" value="<?php echo $db; ?>" />
323 <input type="hidden" name="table" value="<?php echo $table; ?>" />
324 <input type="hidden" name="submit_comm" value="true" />
326 <table>
327 <tr>
328 <th colspan="2" align="center"><b><?php echo $strComments; ?></b></th>
329 </tr>
330 <?php
331 for ($i = 0; $i < $saved_row_cnt; $i++) {
332 $field = $save_row[$i]['Field'];
333 echo "\n";
335 <tr>
336 <th><?php echo $field; ?></th>
337 <td>
338 <input type="text" name="comment[<?php echo $field; ?>]" value="<?php echo (isset($comments[$field]) ? htmlspecialchars($comments[$field]) : ''); ?>" />
339 </td>
340 </tr>
341 <?php
342 } // end for
344 echo "\n";
346 <tr>
347 <td colspan="2" align="center">
348 <input type="submit" value="<?php echo $strGo; ?>" />
349 </td>
350 </tr>
351 </table>
352 </form>
353 <?php
354 } // end if (comments work)
355 } // end if (we have columns in this table)
359 * Displays the footer
361 echo "\n";
362 require('./footer.inc.php3');