Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / pmd_relation_upd.php
blob0599fe8a9f50ed333c15ff85a0c797c5fd26e6e1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin-Designer
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 PMA_Response::getInstance()->disable();
15 require_once 'libraries/pmd_common.php';
16 extract($_POST, EXTR_SKIP);
17 extract($_GET, EXTR_SKIP);
18 $die_save_pos = 0;
19 require_once 'pmd_save_pos.php';
20 list($DB1, $T1) = explode(".", $T1);
21 list($DB2, $T2) = explode(".", $T2);
23 $tables = PMA_DBI_get_tables_full($db, $T1);
24 $type_T1 = strtoupper($tables[$T1]['ENGINE']);
25 $tables = PMA_DBI_get_tables_full($db, $T2);
26 $type_T2 = strtoupper($tables[$T2]['ENGINE']);
28 $try_to_delete_internal_relation = false;
30 if (PMA_Util::isForeignKeySupported($type_T1)
31 && PMA_Util::isForeignKeySupported($type_T2)
32 && $type_T1 == $type_T2
33 ) {
34 // InnoDB
35 $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
37 if (isset($existrel_foreign[$F2]['constraint'])) {
38 $upd_query = 'ALTER TABLE ' . PMA_Util::backquote($DB2)
39 . '.' . PMA_Util::backquote($T2) . ' DROP FOREIGN KEY '
40 . PMA_Util::backquote($existrel_foreign[$F2]['constraint'])
41 . ';';
42 $upd_rs = PMA_DBI_query($upd_query);
43 } else {
44 // there can be an internal relation even if InnoDB
45 $try_to_delete_internal_relation = true;
47 } else {
48 $try_to_delete_internal_relation = true;
50 if ($try_to_delete_internal_relation) {
51 // internal relations
52 PMA_queryAsControlUser(
53 'DELETE FROM '
54 . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
55 . $cfg['Server']['relation'].' WHERE '
56 . 'master_db = \'' . PMA_Util::sqlAddSlashes($DB2) . '\''
57 . ' AND master_table = \'' . PMA_Util::sqlAddSlashes($T2) . '\''
58 . ' AND master_field = \'' . PMA_Util::sqlAddSlashes($F2) . '\''
59 . ' AND foreign_db = \'' . PMA_Util::sqlAddSlashes($DB1) . '\''
60 . ' AND foreign_table = \'' . PMA_Util::sqlAddSlashes($T1) . '\''
61 . ' AND foreign_field = \'' . PMA_Util::sqlAddSlashes($F1) . '\'',
62 false,
63 PMA_DBI_QUERY_STORE
66 PMD_return_upd(1, __('Relation deleted'));
68 function PMD_return_upd($b, $ret)
70 global $K;
71 header("Content-Type: text/xml; charset=utf-8");
72 header("Cache-Control: no-cache");
73 die('<root act="relation_upd" return="'.$ret.'" b="'.$b.'" K="'.$K.'"></root>');