Ejemplo n.º 1
0
/**
 * Function to get html for the common form title headers
 *
 * @param array  $cfgRelation        configuration relation
 * @param string $tbl_storage_engine table storage engine
 *
 * @return string
 */
function PMA_getHtmlForCommonFormTableHeaders($cfgRelation, $tbl_storage_engine)
{
    $html_output = '<tr><th>' . __('Column') . '</th>';
    if ($cfgRelation['relwork']) {
        $html_output .= '<th>' . __('Internal relation');
        if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
            $html_output .= PMA_Util::showHint(__('An internal relation is not necessary when a corresponding' . ' FOREIGN KEY relation exists.'));
        }
        $html_output .= '</th>';
    }
    if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
        // this does not have to be translated, it's part of the MySQL syntax
        $html_output .= '<th colspan="2">' . __('Foreign key constraint') . ' (' . $tbl_storage_engine . ')';
        $html_output .= '</th>';
    }
    $html_output .= '</tr>';
    return $html_output;
}
Ejemplo n.º 2
0
/**
 * Get HTML links for 'Print view', 'Relation view', 'Propose table structure',
 * 'Track table' and 'Move columns'
 *
 * @param string  $url_query           url query
 * @param boolean $tbl_is_view         whether table is view or not
 * @param boolean $db_is_system_schema whether db is information schema or not
 * @param string  $tbl_storage_engine  table storage engine
 * @param array   $cfgRelation         current relation parameters
 *
 * @return string $html_output
 */
function PMA_getHtmlForOptionalActionLinks($url_query, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $cfgRelation)
{
    $html_output = '<a href="tbl_printview.php?' . $url_query . '" target="print_view">' . PMA_Util::getIcon('b_print.png', __('Print view'), true) . '</a>';
    if (!$tbl_is_view && !$db_is_system_schema) {
        // if internal relations are available, or foreign keys are supported
        // ($tbl_storage_engine comes from libraries/tbl_info.inc.php
        if ($cfgRelation['relwork'] || PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
            $html_output .= '<a href="tbl_relation.php?' . $url_query . '">' . PMA_Util::getIcon('b_relations.png', __('Relation view'), true) . '</a>';
        }
        if (!PMA_DRIZZLE) {
            $html_output .= '<a href="sql.php?' . $url_query . '&amp;session_max_rows=all&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_Util::backquote($GLOBALS['table']) . ' PROCEDURE ANALYSE()') . '">' . PMA_Util::getIcon('b_tblanalyse.png', __('Propose table structure'), true) . '</a>';
            $html_output .= PMA_Util::showMySQLDocu('procedure_analyse') . "\n";
        }
        if (PMA_Tracker::isActive()) {
            $html_output .= '<a href="tbl_tracking.php?' . $url_query . '">' . PMA_Util::getIcon('eye.png', __('Track table'), true) . '</a>';
        }
        $html_output .= '<a href="#" id="move_columns_anchor">' . PMA_Util::getIcon('b_move.png', __('Move columns'), true) . '</a>';
    }
    return $html_output;
}
Ejemplo n.º 3
0
/**
 * Removes a foreign relation
 *
 * @param string $T1 foreign db.table
 * @param string $F1 foreign field
 * @param string $T2 master db.table
 * @param string $F2 master field
 *
 * @return array array of success/failure and message
 */
function PMA_removeRelation($T1, $F1, $T2, $F2)
{
    list($DB1, $T1) = explode(".", $T1);
    list($DB2, $T2) = explode(".", $T2);
    $tables = $GLOBALS['dbi']->getTablesFull($DB1, $T1);
    $type_T1 = mb_strtoupper($tables[$T1]['ENGINE']);
    $tables = $GLOBALS['dbi']->getTablesFull($DB2, $T2);
    $type_T2 = mb_strtoupper($tables[$T2]['ENGINE']);
    if (PMA_Util::isForeignKeySupported($type_T1) && PMA_Util::isForeignKeySupported($type_T2) && $type_T1 == $type_T2) {
        // InnoDB
        $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
        $foreigner = PMA_searchColumnInForeigners($existrel_foreign, $F2);
        if (isset($foreigner['constraint'])) {
            $upd_query = 'ALTER TABLE ' . PMA_Util::backquote($DB2) . '.' . PMA_Util::backquote($T2) . ' DROP FOREIGN KEY ' . PMA_Util::backquote($foreigner['constraint']) . ';';
            if ($GLOBALS['dbi']->query($upd_query)) {
                return array(true, __('FOREIGN KEY relation has been removed.'));
            }
            $error = $GLOBALS['dbi']->getError();
            return array(false, __('Error: FOREIGN KEY relation could not be removed!') . "<br/>" . $error);
        }
    }
    // internal relations
    $delete_query = "DELETE FROM " . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . "." . $GLOBALS['cfgRelation']['relation'] . " WHERE " . "master_db = '" . PMA_Util::sqlAddSlashes($DB2) . "'" . " AND master_table = '" . PMA_Util::sqlAddSlashes($T2) . "'" . " AND master_field = '" . PMA_Util::sqlAddSlashes($F2) . "'" . " AND foreign_db = '" . PMA_Util::sqlAddSlashes($DB1) . "'" . " AND foreign_table = '" . PMA_Util::sqlAddSlashes($T1) . "'" . " AND foreign_field = '" . PMA_Util::sqlAddSlashes($F1) . "'";
    $result = PMA_queryAsControlUser($delete_query, false, PMA_DatabaseInterface::QUERY_STORE);
    if (!$result) {
        $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']);
        return array(false, __('Error: Internal relation could not be removed!') . "<br/>" . $error);
    }
    return array(true, __('Internal relation has been removed.'));
}
Ejemplo n.º 4
0
 /**
  * foreign key supported test
  *
  * @param string $a Engine
  * @param bool   $e Expected Value
  *
  * @return void
  *
  * @dataProvider foreignkeySupportedDataProvider
  */
 public function testForeignkeySupported($a, $e)
 {
     $this->assertEquals($e, PMA_Util::isForeignKeySupported($a));
 }
Ejemplo n.º 5
0
/**
 * Returns the HTML for secondary levels tabs of the table structure page
 *
 * @return string HTML for secondary levels tabs
 */
function PMA_getStructureSecondaryTabs($tbl_storage_engine)
{
    $html_output = '';
    $cfgRelation = PMA_getRelationsParam();
    if ($cfgRelation['relwork'] || PMA_Util::isForeignKeySupported(strtoupper($tbl_storage_engine))) {
        $url_params = array();
        $url_params['db'] = $GLOBALS['db'];
        $url_params['table'] = $GLOBALS['table'];
        $html_output .= '<ul id="topmenu2">';
        foreach (PMA_getStructureSubTabs() as $tab) {
            $html_output .= PMA_Util::getHtmlTab($tab, $url_params);
        }
        $html_output .= '</ul>';
        $html_output .= '<div class="clearfloat"></div>';
    }
    return $html_output;
}
Ejemplo n.º 6
0
/**
 * Function to get html for Internal relations form
 *
 * @param array  $columns            columns
 * @param string $tbl_storage_engine table storage engine
 * @param array  $existrel           db, table, column
 * @param string $db                 current database
 *
 * @return string
 */
function PMA_getHtmlForInternalRelationForm($columns, $tbl_storage_engine, $existrel, $db)
{
    $save_row = array_values($columns);
    $saved_row_cnt = count($save_row);
    $html_output = '<fieldset>' . '<legend>' . __('Internal relations') . '</legend>' . '<table id="internal_relations" class="relationalTable">';
    $html_output .= '<tr><th>' . __('Column') . '</th>';
    $html_output .= '<th>' . __('Internal relation');
    if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
        $html_output .= PMA_Util::showHint(__('An internal relation is not necessary when a corresponding' . ' FOREIGN KEY relation exists.'));
    }
    $html_output .= '</th>';
    $odd_row = true;
    for ($i = 0; $i < $saved_row_cnt; $i++) {
        $html_output .= PMA_getHtmlForInternalRelationRow($save_row, $i, $odd_row, $existrel, $db);
        $odd_row = !$odd_row;
    }
    $html_output .= '</table>';
    $html_output .= '</fieldset>';
    return $html_output;
}
Ejemplo n.º 7
0
/**
 * Get HTML to display tables on designer page
 *
 * @param array $tab_pos                  tables positions
 * @param int   $display_page             page number of the selected page
 * @param array $tab_column               table column info
 * @param array $tables_all_keys          all indices
 * @param array $tables_pk_or_unique_keys unique or primary indices
 *
 * @return string html
 */
function PMA_getDatabaseTables($tab_pos, $display_page, $tab_column, $tables_all_keys, $tables_pk_or_unique_keys)
{
    $html = '';
    for ($i = 0; $i < count($GLOBALS['PMD']["TABLE_NAME"]); $i++) {
        $t_n = $GLOBALS['PMD']["TABLE_NAME"][$i];
        $t_n_url = $GLOBALS['PMD_URL']["TABLE_NAME"][$i];
        $html .= '<input name="t_x[' . $t_n_url . ']" type="hidden" id="t_x_' . $t_n_url . '_" />';
        $html .= '<input name="t_y[' . $t_n_url . ']" type="hidden" id="t_y_' . $t_n_url . '_" />';
        $html .= '<input name="t_v[' . $t_n_url . ']" type="hidden" id="t_v_' . $t_n_url . '_" />';
        $html .= '<input name="t_h[' . $t_n_url . ']" type="hidden" id="t_h_' . $t_n_url . '_" />';
        $html .= '<table id="' . $t_n_url . '" cellpadding="0" cellspacing="0" ';
        $html .= 'class="pmd_tab" style="position:absolute;';
        $html .= 'left:';
        $html .= (isset($tab_pos[$t_n]) ? $tab_pos[$t_n]["X"] : rand(20, 700)) . 'px;';
        $html .= 'top:';
        $html .= (isset($tab_pos[$t_n]) ? $tab_pos[$t_n]["Y"] : rand(20, 550)) . 'px;';
        $html .= 'display:';
        $html .= isset($tab_pos[$t_n]) || $display_page == -1 ? 'block;' : 'none;';
        $html .= 'z-index: 1;">';
        $html .= '<thead>';
        $html .= '<tr class="header">';
        if (isset($_REQUEST['query'])) {
            $html .= '<td class="select_all">';
            $html .= '<input class="select_all_1" type="checkbox" ' . 'style="margin: 0px;" ';
            $html .= 'value="select_all_' . htmlspecialchars($t_n_url) . '" ';
            $html .= 'id="select_all_' . htmlspecialchars($t_n_url) . '" ';
            $html .= 'title="select all" pmd_url_table_name="' . htmlspecialchars($t_n_url) . '" ';
            $html .= 'pmd_out_owner="' . htmlspecialchars($GLOBALS['PMD_OUT']['OWNER'][$i]) . '">';
            $html .= '</td>';
        }
        $html .= '<td class="small_tab" ';
        $html .= 'id="id_hide_tbody_' . $t_n_url . '" ';
        $html .= 'table_name="' . htmlspecialchars($t_n_url) . '" onmouseover="this.className=\'small_tab2\';" ';
        $html .= 'onmouseout="this.className=\'small_tab\';" ';
        $html .= '>';
        // no space allowed here, between tags and content !!!
        // JavaScript function does require this
        if (!isset($tab_pos[$t_n]) || !empty($tab_pos[$t_n]["V"])) {
            $html .= 'v';
        } else {
            $html .= '&gt;';
        }
        $html .= '</td>';
        $html .= '<td class="small_tab_pref small_tab_pref_1" ';
        $html .= 'table_name_small="' . $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . '" onmouseover="this.className=' . '\'small_tab_pref2 small_tab_pref_1\';" ';
        $html .= 'onmouseout="this.className=\'small_tab_pref small_tab_pref_1\';" ';
        $html .= '>';
        $html .= '<img alt="" ';
        $html .= 'src="' . $_SESSION['PMA_Theme']->getImgPath('pmd/exec_small.png') . '" />';
        $html .= '</td>';
        $html .= '<td id="id_zag_' . htmlspecialchars($t_n_url) . '" class="tab_zag nowrap tab_zag_noquery" ';
        $html .= 'onmousedown="cur_click=document.getElementById(\'' . $t_n_url . '\');" ';
        $html .= 'table_name="' . htmlspecialchars($t_n_url) . '' . '" query_set="' . (isset($_REQUEST['query']) ? 1 : 0) . '" ';
        $html .= '>';
        $html .= '<span class="owner">';
        $html .= $GLOBALS['PMD_OUT']["OWNER"][$i] . '.';
        $html .= '</span>';
        $html .= $GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'][$i];
        $html .= '</td>';
        if (isset($_REQUEST['query'])) {
            $html .= '<td class="tab_zag tab_zag_query" ';
            $html .= 'id="id_zag_' . htmlspecialchars($t_n_url) . '_2" ';
            $html .= 'table_name="' . htmlspecialchars($t_n_url) . '" ';
            $html .= 'onmousedown="cur_click=document.getElementById(\'' . htmlspecialchars($t_n_url) . '\');" ';
            $html .= '>';
        }
        $html .= '</tr>';
        $html .= '</thead>';
        $html .= '<tbody id="id_tbody_' . $t_n_url . '" ';
        if (isset($tab_pos[$t_n]) && empty($tab_pos[$t_n]["V"])) {
            $html .= 'style="display: none;"';
        }
        $html .= '>';
        $display_field = PMA_getDisplayField($_GET['db'], $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i]);
        for ($j = 0, $id_cnt = count($tab_column[$t_n]["COLUMN_ID"]); $j < $id_cnt; $j++) {
            $html .= '<tr id="id_tr_' . $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . '.' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '" ';
            if ($display_field == $tab_column[$t_n]["COLUMN_NAME"][$j]) {
                $html .= 'class="tab_field_3" ';
            } else {
                $html .= 'class="tab_field" ';
            }
            $html .= 'onmouseover="old_class = this.className; ';
            $html .= 'this.className = \'tab_field_2\';" ';
            $html .= 'onmouseout="this.className = old_class;" ';
            $html .= 'click_field_param="';
            $html .= $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . ',';
            $html .= urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . ',';
            $tmpColumn = $t_n . "." . $tab_column[$t_n]["COLUMN_NAME"][$j];
            if (!PMA_Util::isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i])) {
                $html .= isset($tables_pk_or_unique_keys[$tmpColumn]) ? 1 : 0;
            } else {
                // if foreign keys are supported, it's not necessary that the
                // index is a primary key
                $html .= isset($tables_all_keys[$tmpColumn]) ? 1 : 0;
            }
            $html .= '"';
            $html .= '>';
            if (isset($_REQUEST['query'])) {
                $html .= '<td class="select_all">';
                $html .= '<input class="select_all_store_col" value="' . htmlspecialchars($t_n_url) . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '"';
                $html .= 'type="checkbox" id="select_' . htmlspecialchars($t_n_url) . '._' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '" ';
                $html .= 'style="margin: 0px;" title="select_' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '" ';
                $html .= 'store_column_param="' . urlencode($GLOBALS['PMD_OUT']["TABLE_NAME_SMALL"][$i]) . ',' . htmlspecialchars($GLOBALS['PMD_OUT']["OWNER"][$i]) . ',' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '"></td>';
            }
            $html .= '<td width="10px" colspan="3"';
            $html .= 'id="' . $t_n_url . '.' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '">';
            $html .= '<div class="nowrap">';
            if (isset($tables_pk_or_unique_keys[$t_n . "." . $tab_column[$t_n]["COLUMN_NAME"][$j]])) {
                $html .= '<img src="' . $_SESSION['PMA_Theme']->getImgPath('pmd/FieldKey_small.png') . '" alt="*" />';
            } else {
                $image = 'pmd/Field_small';
                if (strstr($tab_column[$t_n]["TYPE"][$j], 'char') || strstr($tab_column[$t_n]["TYPE"][$j], 'text')) {
                    $image .= '_char';
                } elseif (strstr($tab_column[$t_n]["TYPE"][$j], 'int') || strstr($tab_column[$t_n]["TYPE"][$j], 'float') || strstr($tab_column[$t_n]["TYPE"][$j], 'double') || strstr($tab_column[$t_n]["TYPE"][$j], 'decimal')) {
                    $image .= '_int';
                } elseif (strstr($tab_column[$t_n]["TYPE"][$j], 'date') || strstr($tab_column[$t_n]["TYPE"][$j], 'time') || strstr($tab_column[$t_n]["TYPE"][$j], 'year')) {
                    $image .= '_date';
                }
                $image .= '.png';
                $html .= '<img src="' . $_SESSION['PMA_Theme']->getImgPath($image) . '" alt="*" />';
            }
            $html .= htmlspecialchars($tab_column[$t_n]["COLUMN_NAME"][$j] . " : " . $tab_column[$t_n]["TYPE"][$j], ENT_QUOTES);
            $html .= "</div>\n</td>\n";
            if (isset($_REQUEST['query'])) {
                $html .= '<td class="small_tab_pref small_tab_pref_click_opt" ';
                $html .= 'onmouseover="this.className=' . '\'small_tab_pref2 small_tab_pref_click_opt\';" ';
                $html .= 'onmouseout="this.className=' . '\'small_tab_pref small_tab_pref_click_opt\';" ';
                $html .= 'Click_option_param="pmd_optionse,' . urlencode($tab_column[$t_n]['COLUMN_NAME'][$j]) . ',' . $GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'][$i] . '" >';
                $html .= '<img src="' . $_SESSION['PMA_Theme']->getImgPath('pmd/exec_small.png') . '" title="options" alt="" /></td> ';
            }
            $html .= "</tr>";
        }
        $html .= "</tbody>";
        $html .= "</table>";
    }
    return $html;
}
Ejemplo n.º 8
0
/**
 * Return script to create j_tab and h_tab arrays
 *
 * @return string
 */
function get_script_tabs()
{
    $script_tabs = 'var j_tabs = new Array();' . "\n" . 'var h_tabs = new Array();' . "\n";
    $retval = array('j_tabs' => array(), 'h_tabs' => array());
    for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
        $j = 0;
        if (PMA_Util::isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i])) {
            $j = 1;
        }
        $retval['j_tabs'][$GLOBALS['PMD_URL']['TABLE_NAME'][$i]] = $j;
        $retval['h_tabs'][$GLOBALS['PMD_URL']['TABLE_NAME'][$i]] = 1;
    }
    return $retval;
}
Ejemplo n.º 9
0
 /**
  * process internal and foreign key relations
  *
  * @param string  $db          The database name
  * @param integer $pageNumber  document number/Id
  * @param array   $cfgRelation relation settings
  *
  * @return void
  * @access private
  */
 public function processRelations($db, $pageNumber, $cfgRelation)
 {
     /*
      * A u t o m a t i c    l a y o u t
      *
      * There are 2 kinds of relations in PMA
      * 1) Internal Relations 2) Foreign Key Relations
      */
     if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) {
         $all_tables = array();
     }
     if (isset($this->autoLayoutForeign)) {
         /*
          * get the tables list
          * who support FOREIGN KEY, it's not
          * important that we group together InnoDB tables
          * and PBXT tables, as this logic is just to put
          * the tables on the layout, not to determine relations
          */
         $tables = $GLOBALS['dbi']->getTablesFull($db);
         $foreignkey_tables = array();
         foreach ($tables as $table_name => $table_properties) {
             if (PMA_Util::isForeignKeySupported($table_properties['ENGINE'])) {
                 $foreignkey_tables[] = $table_name;
             }
         }
         $all_tables = $foreignkey_tables;
         /*
          * could be improved by finding the tables which have the
          * most references keys and placing them at the beginning
          * of the array (so that they are all center of schema)
          */
         unset($tables, $foreignkey_tables);
     }
     if (isset($this->autoLayoutInternal)) {
         /*
          * get the tables list who support Internal Relations;
          * This type of relations will be created when
          * you setup the PMA tables correctly
          */
         $master_tables = 'SELECT COUNT(master_table), master_table' . ' FROM ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_Util::backquote($cfgRelation['relation']) . ' WHERE master_db = \'' . PMA_Util::sqlAddSlashes($db) . '\'' . ' GROUP BY master_table' . ' ORDER BY COUNT(master_table) DESC';
         $master_tables_rs = PMA_queryAsControlUser($master_tables, false, PMA_DatabaseInterface::QUERY_STORE);
         if ($master_tables_rs && $GLOBALS['dbi']->numRows($master_tables_rs) > 0) {
             /* first put all the master tables at beginning
              * of the list, so they are near the center of
              * the schema
              */
             while (list(, $master_table) = $GLOBALS['dbi']->fetchRow($master_tables_rs)) {
                 $all_tables[] = $master_table;
             }
             /* Now for each master, add its foreigns into an array
              * of foreign tables, if not already there
              * (a foreign might be foreign for more than
              * one table, and might be a master itself)
              */
             $foreign_tables = array();
             foreach ($all_tables as $master_table) {
                 $foreigners = PMA_getForeigners($db, $master_table);
                 foreach ($foreigners as $foreigner) {
                     if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
                         $foreign_tables[] = $foreigner['foreign_table'];
                     }
                 }
             }
             /*
              * Now merge the master and foreign arrays/tables
              */
             foreach ($foreign_tables as $foreign_table) {
                 if (!in_array($foreign_table, $all_tables)) {
                     $all_tables[] = $foreign_table;
                 }
             }
         }
     }
     if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) {
         $this->addRelationCoordinates($all_tables, $pageNumber, $db, $cfgRelation);
     }
     $this->chosenPage = $pageNumber;
 }
Ejemplo n.º 10
0
/**
 * Return script to create j_tab and h_tab arrays
 *
 * @return string
 */
function get_script_tabs()
{
    $script_tabs = 'var j_tabs = new Array();' . "\n" . 'var h_tabs = new Array();' . "\n";
    for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
        $script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '" . PMA_Util::isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i]) ? '1' : '0' . "';\n" . "h_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = 1;" . "\n";
    }
    return $script_tabs;
}
Ejemplo n.º 11
0
}
// end if isset($destination_foreign)
// U p d a t e s   f o r   d i s p l a y   f i e l d
if ($cfgRelation['displaywork'] && isset($_POST['display_field'])) {
    $html_output .= PMA_handleUpdateForDisplayField($disp, $_POST['display_field'], $db, $table, $cfgRelation);
}
// end if
// If we did an update, refresh our data
if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
    $existrel = PMA_getForeigners($db, $table, '', 'internal');
}
if (isset($_POST['destination_foreign_db']) && PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
    $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
}
if ($cfgRelation['displaywork']) {
    $disp = PMA_getDisplayField($db, $table);
}
/**
 * Dialog
 */
// Now find out the columns of our $table
// need to use PMA_DatabaseInterface::QUERY_STORE with $GLOBALS['dbi']->numRows()
// in mysqli
$columns = $GLOBALS['dbi']->getColumns($db, $table);
// common form
$html_output .= PMA_getHtmlForCommonForm($db, $table, $columns, $cfgRelation, $tbl_storage_engine, isset($existrel) ? $existrel : array(), isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : array(), $options_array);
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
    $html_output .= PMA_getHtmlForDisplayIndexes();
}
// Render HTML output
PMA_Response::getInstance()->addHTML($html_output);
Ejemplo n.º 12
0
    echo '>';
    $display_field = PMA_getDisplayField($_GET['db'], $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i]);
    for ($j = 0, $id_cnt = count($tab_column[$t_n]["COLUMN_ID"]); $j < $id_cnt; $j++) {
        echo '<tr id="id_tr_' . $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . '.' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '"';
        if ($display_field == $tab_column[$t_n]["COLUMN_NAME"][$j]) {
            echo ' class="tab_field_3" ';
        } else {
            echo ' class="tab_field" ';
        }
        ?>
        onmouseover="old_class = this.className; this.className = 'tab_field_2';"
        onmouseout="this.className = old_class;"
        onmousedown="Click_field('<?php 
        echo $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . "','" . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . "',";
        $tmpColumn = $t_n . "." . $tab_column[$t_n]["COLUMN_NAME"][$j];
        if (!PMA_Util::isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i])) {
            echo isset($tables_pk_or_unique_keys[$tmpColumn]) ? 1 : 0;
        } else {
            // if foreign keys are supported, it's not necessary that the
            // index is a primary key
            echo isset($tables_all_keys[$tmpColumn]) ? 1 : 0;
        }
        ?>
)">
    <?php 
        if (isset($_REQUEST['query'])) {
            echo '<td class="select_all">';
            echo '<input value="' . htmlspecialchars($t_n_url) . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '"';
            echo 'type="checkbox" id="select_' . htmlspecialchars($t_n_url) . '._' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '" ';
            echo 'style="margin: 0px;" title="select_' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '" ';
            echo 'onclick="store_column(\'' . urlencode($GLOBALS['PMD_OUT']["TABLE_NAME_SMALL"][$i]) . '\',\'' . htmlspecialchars($GLOBALS['PMD_OUT']["OWNER"][$i]) . '\',\'' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . '\')"></td>';
Ejemplo n.º 13
0
 */
require_once './libraries/common.inc.php';
PMA_Response::getInstance()->disable();
require_once 'libraries/pmd_common.php';
extract($_POST, EXTR_SKIP);
extract($_GET, EXTR_SKIP);
$die_save_pos = 0;
require_once 'pmd_save_pos.php';
list($DB1, $T1) = explode(".", $T1);
list($DB2, $T2) = explode(".", $T2);
$tables = $GLOBALS['dbi']->getTablesFull($db, $T1);
$type_T1 = strtoupper($tables[$T1]['ENGINE']);
$tables = $GLOBALS['dbi']->getTablesFull($db, $T2);
$type_T2 = strtoupper($tables[$T2]['ENGINE']);
$try_to_delete_internal_relation = false;
if (PMA_Util::isForeignKeySupported($type_T1) && PMA_Util::isForeignKeySupported($type_T2) && $type_T1 == $type_T2) {
    // InnoDB
    $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
    if (isset($existrel_foreign[$F2]['constraint'])) {
        $upd_query = 'ALTER TABLE ' . PMA_Util::backquote($DB2) . '.' . PMA_Util::backquote($T2) . ' DROP FOREIGN KEY ' . PMA_Util::backquote($existrel_foreign[$F2]['constraint']) . ';';
        $upd_rs = $GLOBALS['dbi']->query($upd_query);
    } else {
        // there can be an internal relation even if InnoDB
        $try_to_delete_internal_relation = true;
    }
} else {
    $try_to_delete_internal_relation = true;
}
if ($try_to_delete_internal_relation) {
    // internal relations
    PMA_queryAsControlUser('DELETE FROM ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . $cfg['Server']['relation'] . ' WHERE ' . 'master_db = \'' . PMA_Util::sqlAddSlashes($DB2) . '\'' . ' AND master_table = \'' . PMA_Util::sqlAddSlashes($T2) . '\'' . ' AND master_field = \'' . PMA_Util::sqlAddSlashes($F2) . '\'' . ' AND foreign_db = \'' . PMA_Util::sqlAddSlashes($DB1) . '\'' . ' AND foreign_table = \'' . PMA_Util::sqlAddSlashes($T1) . '\'' . ' AND foreign_field = \'' . PMA_Util::sqlAddSlashes($F1) . '\'', false, PMA_DatabaseInterface::QUERY_STORE);
Ejemplo n.º 14
0
/**
 * Removes a foreign relation
 *
 * @param string $T1 foreign db.table
 * @param string $F1 foreign field
 * @param string $T2 master db.table
 * @param string $F2 master field
 *
 * @return void
 */
function PMA_removeRelation($T1, $F1, $T2, $F2)
{
    /** @var PMA_String $pmaString */
    $pmaString = $GLOBALS['PMA_String'];
    list($DB1, $T1) = explode(".", $T1);
    list($DB2, $T2) = explode(".", $T2);
    $tables = $GLOBALS['dbi']->getTablesFull($DB1, $T1);
    $type_T1 = $pmaString->strtoupper($tables[$T1]['ENGINE']);
    $tables = $GLOBALS['dbi']->getTablesFull($DB2, $T2);
    $type_T2 = $pmaString->strtoupper($tables[$T2]['ENGINE']);
    $try_to_delete_internal_relation = false;
    if (PMA_Util::isForeignKeySupported($type_T1) && PMA_Util::isForeignKeySupported($type_T2) && $type_T1 == $type_T2) {
        // InnoDB
        $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
        $foreigner = PMA_searchColumnInForeigners($existrel_foreign, $F2);
        if (isset($foreigner['constraint'])) {
            $upd_query = 'ALTER TABLE ' . PMA_Util::backquote($DB2) . '.' . PMA_Util::backquote($T2) . ' DROP FOREIGN KEY ' . PMA_Util::backquote($foreigner['constraint']) . ';';
            $upd_rs = $GLOBALS['dbi']->query($upd_query);
        } else {
            // there can be an internal relation even if InnoDB
            $try_to_delete_internal_relation = true;
        }
    } else {
        $try_to_delete_internal_relation = true;
    }
    if ($try_to_delete_internal_relation) {
        // internal relations
        PMA_queryAsControlUser('DELETE FROM ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . $GLOBALS['cfgRelation']['relation'] . ' WHERE ' . 'master_db = \'' . PMA_Util::sqlAddSlashes($DB2) . '\'' . ' AND master_table = \'' . PMA_Util::sqlAddSlashes($T2) . '\'' . ' AND master_field = \'' . PMA_Util::sqlAddSlashes($F2) . '\'' . ' AND foreign_db = \'' . PMA_Util::sqlAddSlashes($DB1) . '\'' . ' AND foreign_table = \'' . PMA_Util::sqlAddSlashes($T1) . '\'' . ' AND foreign_field = \'' . PMA_Util::sqlAddSlashes($F1) . '\'', false, PMA_DatabaseInterface::QUERY_STORE);
    }
}