Ejemplo n.º 1
0
 /**
  * The "PMA_RT" constructor
  *
  * @param   mixed    The scaling factor
  * @param   integer  The page number to draw (from the
  *                   $cfg['Servers'][$i]['table_coords'] table)
  * @param   boolean  Whether to display table position or not
  * @param   boolean  Was originally whether to use one color per
  *                   relation or not, now enables/disables color
  *                   everywhere, due to some problems printing with color
  * @param   boolean  Whether to draw grids or not
  * @param   boolean  Whether all tables should have the same width or not
  *
  * @global  object   The current PDF document
  * @global  string   The current db name
  * @global  array    The relations settings
  *
  * @access  private
  *
  * @see     PMA_PDF
  */
 function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
 {
     global $pdf, $db, $cfgRelation, $with_doc;
     // Font face depends on the current language
     $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
     $this->same_wide = $all_tab_same_wide;
     // Initializes a new document
     $pdf = new PMA_PDF('L', 'mm', $paper);
     $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
     $pdf->cMargin = 0;
     $pdf->Open();
     $pdf->SetTitle($pdf->title);
     $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $pdf->AliasNbPages();
     // fonts added to phpMyAdmin and considered non-standard by fpdf
     // (Note: those tahoma fonts are iso-8859-2 based)
     if ($this->ff == 'tahoma') {
         $pdf->AddFont('tahoma', '', 'tahoma.php');
         $pdf->AddFont('tahoma', 'B', 'tahomab.php');
     }
     $pdf->SetFont($this->ff, '', 14);
     $pdf->SetAutoPageBreak('auto');
     // Gets tables on this page
     $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel;
     $tab_rs = PMA_query_as_cu($tab_sql);
     if (!$tab_rs || !mysql_num_rows($tab_rs) > 0) {
         $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
         //            die('No tables');
     }
     while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
         $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
         //$intable     = '\'' . implode('\', \'', $alltables) . '\'';
     }
     //              make doc                    //
     if ($with_doc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->cMargin = 1;
         PMA_RT_DOC($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->cMargin = 0;
     }
     $pdf->Addpage();
     if ($with_doc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark($GLOBALS['strRelationalSchema']);
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->t_marg = 18;
         $this->b_marg = 18;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
         }
         if ($this->same_wide) {
             $this->tables[$table]->width = $this->tablewidth;
         }
         $this->PMA_RT_setMinMax($this->tables[$table]);
     }
     // Defines the scale factor
     $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->fh - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->fw - $this->t_marg - $this->b_marg)) * 100) / 100;
     $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($show_grid) {
         $pdf->SetFontSize(10);
         $this->PMA_RT_strokeGrid();
     }
     $pdf->PMA_PDF_setFontSizeScale(14);
     //        $sql    = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
     //                .   ' WHERE master_db   = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND foreign_db    = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND master_table  IN (' . $intable . ')'
     //                .   ' AND foreign_table IN (' . $intable . ')';
     //        $result =  PMA_query_as_cu($sql);
     //
     // lem9:
     // previous logic was checking master tables and foreign tables
     // but I think that looping on every table of the pdf page as a master
     // and finding its foreigns is OK (then we can support innodb)
     $seen_a_relation = FALSE;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
         if ($exist_rel) {
             $seen_a_relation = TRUE;
             foreach ($exist_rel as $master_field => $rel) {
                 // put the foreign table on the schema only if selected
                 // by the user
                 // (do not use array_search() because we would have to
                 // to do a === FALSE and this is not PHP3 compatible)
                 if (PMA_isInto($rel['foreign_table'], $alltables) > -1) {
                     $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     // loic1: also show tables without relations
     //        $norelations     = TRUE;
     //        if ($result && mysql_num_rows($result) > 0) {
     //            $norelations = FALSE;
     //            while ($row = PMA_mysql_fetch_array($result)) {
     //                $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
     //            }
     //        }
     //        if ($norelations == FALSE) {
     if ($seen_a_relation) {
         $this->PMA_RT_drawRelations($change_color);
     }
     $this->PMA_RT_drawTables($show_info, $change_color);
     $this->PMA_RT_showRt();
 }
Ejemplo n.º 2
0
/**
 * Get the complete list of Databases a user can access
 *
 * @param   boolean   whether to include check on failed 'only_db' operations
 * @param   resource  database handle (superuser)
 * @param   integer   amount of databases inside the 'only_db' container
 * @param   resource  possible resource from a failed previous query
 * @param   resource  database handle (user)
 * @param   array     configuration
 * @param   array     previous list of databases
 *
 * @return  array     all databases a user has access to
 *
 * @access  private
 */
function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist)
{
    if ($only_db_check == FALSE) {
        // try to get the available dbs list
        // use userlink by default
        $dblist = PMA_DBI_get_dblist();
        $dblist_cnt = count($dblist);
        // did not work so check for available databases in the "mysql" db;
        // I don't think we can fall here now...
        if (!$dblist_cnt) {
            $auth_query = 'SELECT User, Select_priv ' . 'FROM mysql.user ' . 'WHERE User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
            $rs = PMA_DBI_try_query($auth_query, $dbh);
        }
        // end
    }
    // Access to "mysql" db allowed and dblist still empty -> gets the
    // usable db list
    if (!$dblist_cnt && ($rs && @PMA_DBI_num_rows($rs))) {
        $row = PMA_DBI_fetch_assoc($rs);
        PMA_DBI_free_result($rs);
        // Correction uva 19991215
        // Previous code assumed database "mysql" admin table "db" column
        // "db" contains literal name of user database, and works if so.
        // Mysql usage generally (and uva usage specifically) allows this
        // column to contain regular expressions (we have all databases
        // owned by a given student/faculty/staff beginning with user i.d.
        // and governed by default by a single set of privileges with
        // regular expression as key). This breaks previous code.
        // This maintenance is to fix code to work correctly for regular
        // expressions.
        if ($row['Select_priv'] != 'Y') {
            // 1. get allowed dbs from the "mysql.db" table
            // lem9: User can be blank (anonymous user)
            $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')';
            $rs = PMA_DBI_try_query($local_query, $dbh);
            if ($rs && @PMA_DBI_num_rows($rs)) {
                // Will use as associative array of the following 2 code
                // lines:
                //   the 1st is the only line intact from before
                //     correction,
                //   the 2nd replaces $dblist[] = $row['Db'];
                $uva_mydbs = array();
                // Code following those 2 lines in correction continues
                // populating $dblist[], as previous code did. But it is
                // now populated with actual database names instead of
                // with regular expressions.
                while ($row = PMA_DBI_fetch_assoc($rs)) {
                    // loic1: all databases cases - part 1
                    if (empty($row['Db']) || $row['Db'] == '%') {
                        $uva_mydbs['%'] = 1;
                        break;
                    }
                    // loic1: avoid multiple entries for dbs
                    if (!isset($uva_mydbs[$row['Db']])) {
                        $uva_mydbs[$row['Db']] = 1;
                    }
                }
                // end while
                PMA_DBI_free_result($rs);
                $uva_alldbs = PMA_DBI_query('SHOW DATABASES;', $GLOBALS['dbh']);
                // loic1: all databases cases - part 2
                if (isset($uva_mydbs['%'])) {
                    while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) {
                        $dblist[] = $uva_row[0];
                    }
                    // end while
                } else {
                    while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) {
                        $uva_db = $uva_row[0];
                        if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) {
                            $dblist[] = $uva_db;
                            $uva_mydbs[$uva_db] = 0;
                        } else {
                            if (!isset($dblist[$uva_db])) {
                                foreach ($uva_mydbs as $uva_matchpattern => $uva_value) {
                                    // loic1: fixed bad regexp
                                    // TODO: db names may contain characters
                                    //       that are regexp instructions
                                    $re = '(^|(\\\\\\\\)+|[^\\])';
                                    $uva_regex = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $uva_matchpattern));
                                    // Fixed db name matching
                                    // 2000-08-28 -- Benjamin Gandon
                                    if (ereg('^' . $uva_regex . '$', $uva_db)) {
                                        $dblist[] = $uva_db;
                                        break;
                                    }
                                }
                                // end while
                            }
                        }
                        // end if ... else if....
                    }
                    // end while
                }
                // end else
                PMA_DBI_free_result($uva_alldbs);
                unset($uva_mydbs);
            }
            // end if
            // 2. get allowed dbs from the "mysql.tables_priv" table
            $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
            $rs = PMA_DBI_try_query($local_query, $dbh);
            if ($rs && @PMA_DBI_num_rows($rs)) {
                while ($row = PMA_DBI_fetch_assoc($rs)) {
                    if (PMA_isInto($row['Db'], $dblist) == -1) {
                        $dblist[] = $row['Db'];
                    }
                }
                // end while
                PMA_DBI_free_result($rs);
            }
            // end if
        }
        // end if
    }
    // end building available dbs from the "mysql" db
    return $dblist;
}
Ejemplo n.º 3
0
                             // end if ... else if....
                         }
                         // end while
                     }
                     // end else
                     mysql_free_result($uva_alldbs);
                     unset($uva_mydbs);
                 }
                 // end if
                 // 2. get allowed dbs from the "mysql.tables_priv" table
                 $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfgServer['user']) . '\'';
                 $rs = mysql_query($local_query, $dbh);
                 // Debug: or PMA_mysqlDie('', $local_query, FALSE);
                 if (@mysql_numrows($rs)) {
                     while ($row = mysql_fetch_array($rs)) {
                         if (PMA_isInto($row['Db'], $dblist) == -1) {
                             $dblist[] = $row['Db'];
                         }
                     }
                     // end while
                     mysql_free_result($rs);
                 }
                 // end if
             }
             // end if
         }
         // end building available dbs from the "mysql" db
     } else {
         echo $strHostEmpty;
     }
 }
Ejemplo n.º 4
0
/**
 * Defines the url to return to in case of error in a sql statement
 */
$err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
/**
 * Selects the database to work with
 */
PMA_mysql_select_db($db);
/**
 * A target table name has been sent to this script -> do the work
 */
if (isset($new_name) && trim($new_name) != '') {
    $use_backquotes = 1;
    $asfile = 1;
    // Ensure the target is valid
    if (count($dblist) > 0 && (PMA_isInto($db, $dblist) == -1 || PMA_isInto($target_db, $dblist) == -1)) {
        exit;
    }
    if ($db == $target_db && $new_name == $table) {
        $message = isset($submit_move) ? $strMoveTableSameNames : $strCopyTableSameNames;
    } else {
        $source = PMA_backquote($db) . '.' . PMA_backquote($table);
        if (empty($target_db)) {
            $target_db = $db;
        }
        // This could avoid some problems with replicated databases, when
        // moving table from replicated one to not replicated one
        PMA_mysql_select_db($target_db);
        $target = PMA_backquote($target_db) . '.' . PMA_backquote($new_name);
        // do not create the table if dataonly
        if ($what != 'dataonly') {
Ejemplo n.º 5
0
 
        </td>
        <td rowspan="2" bgcolor="<?php 
echo $cfg['BgcolorOne'];
?>
">
<?php 
$strDoSelectAll = '&nbsp;';
if ($num_tables > 1) {
    $i = 0;
    echo '            <select name="table_select[]" size="6"  multiple="multiple">' . "\n";
    while ($i < $num_tables) {
        if (!empty($unselectall)) {
            $is_selected = '';
        } else {
            if (isset($table_select) && PMA_isInto($tables[$i], $table_select) != -1 || !empty($selectall) || isset($onetable) && $onetable == $tables[$i]) {
                $is_selected = ' selected="selected"';
            } else {
                $is_selected = '';
            }
        }
        echo '                <option value="' . htmlspecialchars($tables[$i]) . '"' . $is_selected . '>' . htmlspecialchars($tables[$i]) . '</option>' . "\n";
        $i++;
    }
    // end while
    echo '            </select>' . "\n";
    $strDoSelectAll = '<a href="db_search.php?' . $url_query . '&amp;selectall=1#db_search"' . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', true); return false;">' . $strSelectAll . '</a>' . '&nbsp;/&nbsp;' . '<a href="db_search.php?' . $url_query . '&amp;unselectall=1#db_search"' . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', false); return false;">' . $strUnselectAll . '</a>';
} else {
    echo "\n";
    echo '            ' . htmlspecialchars($tables[0]) . "\n";
    echo '            <input type="hidden" name="table" value="' . htmlspecialchars($tables[0]) . '" />' . "\n";
Ejemplo n.º 6
0
/**
 * Copies or renames table
 * FIXME: use RENAME
 *
 * @author          Michal Čihař <*****@*****.**>
 */
function PMA_table_move_copy($source_db, $source_table, $target_db, $target_table, $what, $move)
{
    global $cfgRelation, $dblist, $err_url, $sql_query;
    // set export settings we need
    $GLOBALS['use_backquotes'] = 1;
    $GLOBALS['asfile'] = 1;
    // Ensure the target is valid
    if (count($dblist) > 0 && (PMA_isInto($source_db, $dblist) == -1 || PMA_isInto($target_db, $dblist) == -1)) {
        exit;
    }
    $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
    if (empty($target_db)) {
        $target_db = $source_db;
    }
    // This could avoid some problems with replicated databases, when
    // moving table from replicated one to not replicated one
    PMA_DBI_select_db($target_db);
    $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
    // do not create the table if dataonly
    if ($what != 'dataonly') {
        require_once './libraries/export/sql.php';
        $no_constraints_comments = true;
        $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
        unset($no_constraints_comments);
        $parsed_sql = PMA_SQP_parse($sql_structure);
        /* nijel: Find table name in query and replace it */
        $i = 0;
        while ($parsed_sql[$i]['type'] != 'quote_backtick') {
            $i++;
        }
        /* no need to PMA_backquote() */
        $parsed_sql[$i]['data'] = $target;
        /* Generate query back */
        $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
        // If table exists, and 'add drop table' is selected: Drop it!
        $drop_query = '';
        if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
            $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
            $result = PMA_DBI_query($drop_query);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $drop_query . ';';
            } else {
                $sql_query = $drop_query . ';';
            }
            // garvin: If an existing table gets deleted, maintain any entries
            // for the PMA_* tables
            $maintain_relations = TRUE;
        }
        $result = @PMA_DBI_query($sql_structure);
        if (isset($sql_query)) {
            $sql_query .= "\n" . $sql_structure . ';';
        } else {
            $sql_query = $sql_structure . ';';
        }
        if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) {
            $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']);
            $i = 0;
            while ($parsed_sql[$i]['type'] != 'quote_backtick') {
                $i++;
            }
            /* no need to PMA_backquote() */
            $parsed_sql[$i]['data'] = $target;
            /* Generate query back */
            $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
            $result = PMA_DBI_query($GLOBALS['sql_constraints']);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $GLOBALS['sql_constraints'];
            } else {
                $sql_query = $GLOBALS['sql_constraints'];
            }
            unset($GLOBALS['sql_constraints']);
        }
    } else {
        $sql_query = '';
    }
    // Copy the data
    //if ($result != FALSE && ($what == 'data' || $what == 'dataonly')) {
    if ($what == 'data' || $what == 'dataonly') {
        $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
        PMA_DBI_query($sql_insert_data);
        $sql_query .= "\n\n" . $sql_insert_data . ';';
    }
    require_once './libraries/relation.lib.php';
    $cfgRelation = PMA_getRelationsParam();
    // Drops old table if the user has requested to move it
    if ($move) {
        // This could avoid some problems with replicated databases, when
        // moving table from replicated one to not replicated one
        PMA_DBI_select_db($source_db);
        $sql_drop_table = 'DROP TABLE ' . $source;
        PMA_DBI_query($sql_drop_table);
        // garvin: Move old entries from PMA-DBs to new table
        if ($cfgRelation['commwork']) {
            $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $rmv_rs = PMA_query_as_cu($remove_query);
            unset($rmv_query);
        }
        // garvin: updating bookmarks is not possible since only a single table is moved,
        // and not the whole DB.
        // if ($cfgRelation['bookmarkwork']) {
        //     $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['bookmark'])
        //                   . ' SET     dbase = \'' . PMA_sqlAddslashes($target_db) . '\''
        //                   . ' WHERE dbase  = \'' . PMA_sqlAddslashes($source_db) . '\'';
        //     $rmv_rs    = PMA_query_as_cu($remove_query);
        //     unset($rmv_query);
        // }
        if ($cfgRelation['displaywork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        if ($cfgRelation['relwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        // garvin: [TODO] Can't get moving PDFs the right way. The page numbers always
        // get screwed up independently from duplication because the numbers do not
        // seem to be stored on a per-database basis. Would the author of pdf support
        // please have a look at it?
        if ($cfgRelation['pdfwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            /*
            $pdf_query = 'SELECT pdf_page_number '
                       . ' FROM ' . PMA_backquote($cfgRelation['table_coords'])
                       . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                       . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
            $pdf_rs = PMA_query_as_cu($pdf_query);
            
            while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['pdf_pages'])
                                . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                $tb_rs    = PMA_query_as_cu($table_query);
                unset($table_query);
                unset($tb_rs);
            }
            */
        }
        $sql_query .= "\n\n" . $sql_drop_table . ';';
    } else {
        // garvin: Create new entries as duplicates from old PMA DBs
        if ($what != 'dataonly' && !isset($maintain_relations)) {
            if ($cfgRelation['commwork']) {
                // Get all comments and MIME-Types for current table
                $comments_copy_query = 'SELECT
                                            column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                        FROM ' . PMA_backquote($cfgRelation['column_info']) . '
                                        WHERE
                                            db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                            table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                // Write every comment as new copied entry. [MIME]
                while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                    $new_comment_query = 'REPLACE INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($cfgRelation['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                    $new_comment_rs = PMA_query_as_cu($new_comment_query);
                }
                // end while
            }
            if ($source_db != $target_db) {
                $get_fields = array('user', 'label', 'query');
                $where_fields = array('dbase' => $source_db);
                $new_fields = array('dbase' => $target_db);
                PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
            }
            $get_fields = array('display_field');
            $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
            $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
            PMA_duplicate_table_info('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
            $get_fields = array('master_field', 'foreign_db', 'foreign_table', 'foreign_field');
            $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
            $new_fields = array('master_db' => $target_db, 'master_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            $get_fields = array('foreign_field', 'master_db', 'master_table', 'master_field');
            $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
            $new_fields = array('foreign_db' => $target_db, 'foreign_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            // garvin: [TODO] Can't get duplicating PDFs the right way. The page numbers always
            // get screwed up independently from duplication because the numbers do not
            // seem to be stored on a per-database basis. Would the author of pdf support
            // please have a look at it?
            /*
            $get_fields = array('page_descr');
            $where_fields = array('db_name' => $source_db);
            $new_fields = array('db_name' => $target_db);
            $last_id = PMA_duplicate_table_info('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields);
            
            if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
                $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id);
                PMA_duplicate_table_info('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
            }
            */
        }
    }
}
Ejemplo n.º 7
0
 */
require_once './libraries/common.lib.php';
$js_to_run = 'functions.js';
PMA_checkParameters(array('db', 'table'));
/**
 * Defines the url to return to in case of error in a sql statement
 */
$err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
/**
 * A new name has been submitted -> do the work
 */
if (isset($new_name) && trim($new_name) != '' && strpos($new_name, '.') === FALSE) {
    $old_name = $table;
    $table = $new_name;
    // Ensure the target is valid
    if (count($dblist) > 0 && PMA_isInto($db, $dblist) == -1) {
        exit;
    }
    require_once './header.inc.php';
    PMA_DBI_select_db($db);
    $sql_query = 'ALTER TABLE ' . PMA_backquote($old_name) . ' RENAME ' . PMA_backquote($new_name) . ';';
    $result = PMA_DBI_query($sql_query);
    $message = sprintf($strRenameTableOK, htmlspecialchars($old_name), htmlspecialchars($table));
    $reload = 1;
    // garvin: Move old entries from comments to new table
    require_once './libraries/relation.lib.php';
    $cfgRelation = PMA_getRelationsParam();
    if ($cfgRelation['commwork']) {
        $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($rmv_query);