/** * Returns recently used tables from phpMyAdmin database. * * @return array */ public function getFromDb() { // Read from phpMyAdmin database, if recent tables is not in session $sql_query = " SELECT `tables` FROM " . $this->pma_table . " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'"; $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); if (isset($row[0])) { return json_decode($row[0], true); } else { return array(); } }
/** * Cleanup database related relation stuff * * @param string $db */ function PMA_relationsCleanupDatabase($db) { $cfgRelation = PMA_getRelationsParam(); if ($cfgRelation['commwork']) { $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); } if ($cfgRelation['bookmarkwork']) { $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['bookmark']) . ' WHERE dbase = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); } if ($cfgRelation['displaywork']) { $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); } if ($cfgRelation['pdfwork']) { $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); } if ($cfgRelation['designerwork']) { $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['designer_coords']) . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); } if ($cfgRelation['relwork']) { $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE master_db = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE foreign_db = \'' . PMA_sqlAddSlashes($db) . '\''; PMA_query_as_controluser($remove_query); } }
/** * update X and Y coordinates for a table * * @param string $db The database name * @param array $cfgRelation relation settings * * @return void * @access private */ private function _editCoordinates($db, $cfgRelation) { for ($i = 0; $i < $this->c_table_rows; $i++) { $arrvalue = 'c_table_' . $i; global ${$arrvalue}; $arrvalue = ${$arrvalue}; if (!isset($arrvalue['x']) || $arrvalue['x'] == '') { $arrvalue['x'] = 0; } if (!isset($arrvalue['y']) || $arrvalue['y'] == '') { $arrvalue['y'] = 0; } if (isset($arrvalue['name']) && $arrvalue['name'] != '--') { $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\'' . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage) . '\''; $test_rs = PMA_query_as_controluser($test_query, false, PMA_DBI_QUERY_STORE); //echo $test_query; if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') { $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\'' . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage) . '\''; } else { $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y'] . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\'' . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage) . '\''; } } else { $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . '(db_name, table_name, pdf_page_number, x, y) ' . 'VALUES (\'' . PMA_sqlAddSlashes($db) . '\', \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\', \'' . PMA_sqlAddSlashes($this->chosenPage) . '\',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')'; } //echo $ch_query; PMA_query_as_controluser($ch_query, false); } // end if } // end for }
/** * The "Table_Stats" constructor * * @param string table_name The table name * @param integer pageNumber The current page number (from the * $cfg['Servers'][$i]['table_coords'] table) * @param boolean showKeys Whether to display ONLY keys or not * @return void * @global object The current dia document * @global array The relations settings * @global string The current db name * @see PMA_DIA */ function __construct($tableName, $pageNumber, $showKeys = false) { global $dia, $cfgRelation, $db; $this->tableName = $tableName; $sql = 'DESCRIBE ' . PMA_backquote($tableName); $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE); if (!$result || !PMA_DBI_num_rows($result)) { $dia->dieSchema($pageNumber, "DIA", sprintf(__('The %s table doesn\'t exist!'), $tableName)); } /* * load fields * check to see if it will load all fields or only the foreign keys */ if ($showKeys) { $indexes = PMA_Index::getFromTable($this->tableName, $db); $all_columns = array(); foreach ($indexes as $index) { $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns()))); } $this->fields = array_keys($all_columns); } else { while ($row = PMA_DBI_fetch_row($result)) { $this->fields[] = $row[0]; } } $sql = 'SELECT x, y FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($tableName) . '\'' . ' AND pdf_page_number = ' . $pageNumber; $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE); if (!$result || !PMA_DBI_num_rows($result)) { $dia->dieSchema($pageNumber, "DIA", sprintf(__('Please configure the coordinates for table %s'), $tableName)); } list($this->x, $this->y) = PMA_DBI_fetch_row($result); $this->x = (double) $this->x; $this->y = (double) $this->y; /* * displayfield */ $this->displayfield = PMA_getDisplayField($db, $tableName); /* * index */ $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE); if (PMA_DBI_num_rows($result) > 0) { while ($row = PMA_DBI_fetch_assoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } } } /** * Every object in Dia document needs an ID to identify * so, we used a static variable to keep the things unique */ PMA_Dia_Relation_Schema::$objectId += 1; $this->tableId = PMA_Dia_Relation_Schema::$objectId; }
/** * renames table * * @param string new table name * @param string new database name * @return boolean success */ function rename($new_name, $new_db = null) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid if (!$GLOBALS['pma']->databases->exists($new_db)) { $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db; return false; } } else { $new_db = $this->getDbName(); } $new_table = new PMA_Table($new_name, $new_db); if ($this->getFullName() === $new_table->getFullName()) { return true; } if (!PMA_Table::isValidName($new_name)) { $this->errors[] = $GLOBALS['strInvalidTableName'] . ': ' . $new_table->getFullName(); return false; } $GLOBALS['sql_query'] = ' RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; if (!PMA_DBI_query($GLOBALS['sql_query'])) { $this->errors[] = sprintf($GLOBALS['strErrorRenamingTable'], $this->getFullName(), $new_table->getFullName()); return false; } $old_name = $this->getName(); $old_db = $this->getDbName(); $this->setName($new_name); $this->setDbName($new_db); /** * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db) */ // garvin: Move old entries from comments to new table require_once './libraries/relation.lib.php'; $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); if ($GLOBALS['cfgRelation']['commwork']) { $remove_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($remove_query); unset($remove_query); } if ($GLOBALS['cfgRelation']['displaywork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['relwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `foreign_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `foreign_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `master_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `master_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['pdfwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['designerwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } $this->messages[] = sprintf($GLOBALS['strRenameTableOK'], htmlspecialchars($old_name), htmlspecialchars($new_name)); return true; }
/** * @author Ivan A Kirillov (Ivan.A.Kirillov@gmail.com) * @version $Id$ * @package phpMyAdmin-Designer */ /** * */ include_once 'pmd_common.php'; require_once './libraries/relation.lib.php'; $table = $T; $display_field = $F; if ($cfgRelation['displaywork']) { $disp = PMA_getDisplayField($db, $table); if ($disp) { if ($display_field != $disp) { $upd_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' SET display_field = \'' . PMA_sqlAddslashes($display_field) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; } else { $upd_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; } } elseif ($display_field != '') { $upd_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . '(db_name, table_name, display_field) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($display_field) . '\')'; } if (isset($upd_query)) { $upd_rs = PMA_query_as_controluser($upd_query); } } // end if header("Content-Type: text/xml; charset=utf-8"); header("Cache-Control: no-cache"); die("<root act='save_pos' return='strModifications'></root>");
/** * The "Table_Stats" constructor * * @param string table_name The table name * @param integer ff The font size * @param integer samewidth The max. with among tables * @param boolean show_keys Whether to display keys or not * @param boolean show_info Whether to display table position or not * @global object The current SVG image document * @global integer The current page number (from the * $cfg['Servers'][$i]['table_coords'] table) * @global array The relations settings * @global string The current db name * @access private * @see PMA_SVG, Table_Stats::Table_Stats_setWidth, Table_Stats::Table_Stats_setHeight */ function __construct($tableName, $font, $fontSize, $pageNumber, &$same_wide_width, $showKeys = false, $showInfo = false) { global $svg, $cfgRelation, $db; $this->_tableName = $tableName; $sql = 'DESCRIBE ' . PMA_backquote($tableName); $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE); if (!$result || !PMA_DBI_num_rows($result)) { $svg->dieSchema($pageNumber, "SVG", sprintf(__('The %s table doesn\'t exist!'), $tableName)); } /* * load fields * check to see if it will load all fields or only the foreign keys */ if ($showKeys) { $indexes = PMA_Index::getFromTable($this->_tableName, $db); $all_columns = array(); foreach ($indexes as $index) { $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns()))); } $this->fields = array_keys($all_columns); } else { while ($row = PMA_DBI_fetch_row($result)) { $this->fields[] = $row[0]; } } $this->_showInfo = $showInfo; // height and width $this->_setHeightTable($fontSize); // setWidth must me after setHeight, because title // can include table height which changes table width $this->_setWidthTable($font, $fontSize); if ($same_wide_width < $this->width) { $same_wide_width = $this->width; } // x and y $sql = 'SELECT x, y FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($tableName) . '\'' . ' AND pdf_page_number = ' . $pageNumber; $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE); if (!$result || !PMA_DBI_num_rows($result)) { $svg->dieSchema($pageNumber, "SVG", sprintf(__('Please configure the coordinates for table %s'), $tableName)); } list($this->x, $this->y) = PMA_DBI_fetch_row($result); $this->x = (double) $this->x; $this->y = (double) $this->y; // displayfield $this->displayfield = PMA_getDisplayField($db, $tableName); // index $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE); if (PMA_DBI_num_rows($result) > 0) { while ($row = PMA_DBI_fetch_assoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } } } }
$upd_query .= ' ON DELETE ' . $on_delete; } if ($on_update != 'nix') { $upd_query .= ' ON UPDATE ' . $on_update; } PMA_DBI_try_query($upd_query) or PMD_return_new(0, __('Error: Relation not added.')); PMD_return_new(1, __('FOREIGN KEY relation added')); } // internal (pmadb) relation } else { if ($GLOBALS['cfgRelation']['relwork'] == false) { PMD_return_new(0, _('General relation features') . ':' . _('Disabled')); } else { // no need to recheck if the keys are primary or unique at this point, // this was checked on the interface part $q = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)' . ' values(' . '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($T2) . '\', ' . '\'' . PMA_sqlAddslashes($F2) . '\', ' . '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($T1) . '\',' . '\'' . PMA_sqlAddslashes($F1) . '\')'; if (PMA_query_as_controluser($q, false, PMA_DBI_QUERY_STORE)) { PMD_return_new(1, __('Internal relation added')); } else { PMD_return_new(0, __('Error: Relation not added.')); } } } function PMD_return_new($b, $ret) { global $db, $T1, $F1, $T2, $F2; header("Content-Type: text/xml; charset=utf-8"); //utf-8 .$_GLOBALS['charset'] header("Cache-Control: no-cache"); die('<root act="relation_new" return="' . $ret . '" b="' . $b . '" DB1="' . urlencode($db) . '" T1="' . urlencode($T1) . '" F1="' . urlencode($F1) . '" DB2="' . urlencode($db) . '" T2="' . urlencode($T2) . '" F2="' . urlencode($F2) . '"></root>'); }
/** * Set a single mimetype to a certain value. * * @param string $db the name of the db * @param string $table the name of the table * @param string $key the name of the column * @param string $mimetype the mimetype of the column * @param string $transformation the transformation of the column * @param string $transformation_options the transformation options of the column * @param string $forcedelete force delete, will erase any existing * comments for this column * * @access public * * @return boolean true, if comment-query was made. */ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false ) { $cfgRelation = PMA_getRelationsParam(); if (! $cfgRelation['commwork']) { return false; } $test_qry = ' SELECT `mimetype`, `comment` FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\' AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\' AND `column_name` = \'' . PMA_sqlAddSlashes($key) . '\''; $test_rs = PMA_query_as_controluser($test_qry, true, PMA_DBI_QUERY_STORE); if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { $row = @PMA_DBI_fetch_assoc($test_rs); PMA_DBI_free_result($test_rs); if (! $forcedelete && (strlen($mimetype) || strlen($transformation) || strlen($transformation_options) || strlen($row['comment'])) ) { $upd_query = ' UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' SET `mimetype` = \'' . PMA_sqlAddSlashes($mimetype) . '\', `transformation` = \'' . PMA_sqlAddSlashes($transformation) . '\', `transformation_options` = \'' . PMA_sqlAddSlashes($transformation_options) . '\''; } else { $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']); } $upd_query .= ' WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\' AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\' AND `column_name` = \'' . PMA_sqlAddSlashes($key) . '\''; } elseif (strlen($mimetype) || strlen($transformation) || strlen($transformation_options)) { $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) ' . ' VALUES(' . '\'' . PMA_sqlAddSlashes($db) . '\',' . '\'' . PMA_sqlAddSlashes($table) . '\',' . '\'' . PMA_sqlAddSlashes($key) . '\',' . '\'' . PMA_sqlAddSlashes($mimetype) . '\',' . '\'' . PMA_sqlAddSlashes($transformation) . '\',' . '\'' . PMA_sqlAddSlashes($transformation_options) . '\')'; } if (isset($upd_query)) { return PMA_query_as_controluser($upd_query); } else { return false; } } // end of 'PMA_setMIME()' function
/** * 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 * @param boolean $ Wheter to show all field or only the keys * @global object The current PDF document * @global string The current db name * @global array The relations settings * @access private * @see PMA_PDF */ function __construct($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4', $show_keys = 0) { global $pdf, $db, $cfgRelation, $with_doc; $this->same_wide = $all_tab_same_wide; // Initializes a new document $pdf = new PMA_PDF('L', 'mm', $paper); $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel)); $pdf->setCMargin(0); $pdf->Open(); $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION); $pdf->AliasNbPages(); $pdf->AddFont('DejaVuSans', '', 'dejavusans.php'); $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php'); $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php'); $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php'); $this->ff = PMA_PDF_FONT; $pdf->SetFont($this->ff, '', 14); $pdf->SetAutoPageBreak('auto'); // Gets tables on this page $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel; $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE); if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) { $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']); // die('No tables'); } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) { $alltables[] = PMA_sqlAddslashes($curr_table['table_name']); // $intable = '\'' . implode('\', \'', $alltables) . '\''; } // make doc // if ($with_doc) { $pdf->SetAutoPageBreak('auto', 15); $pdf->setCMargin(1); PMA_RT_DOC($alltables); $pdf->SetAutoPageBreak('auto'); $pdf->setCMargin(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, $show_keys, $show_info); } 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->getFh() - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->getFw() - $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($GLOBALS['cfgRelation']['db']) . '.' . 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_controluser($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 (in_array($rel['foreign_table'], $alltables)) { $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info); } } // end while } // end if } // end while // loic1: also show tables without relations // $norelations = TRUE; // if ($result && PMA_DBI_num_rows($result) > 0) { // $norelations = FALSE; // while ($row = PMA_DBI_fetch_assoc($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($change_color); $this->PMA_RT_showRt(); }
</thead> <tbody> <?php // Print out information about versions $drop_image_or_text = ''; if (true == $GLOBALS['cfg']['PropertiesIconic']) { $drop_image_or_text .= '<img class="icon" width="16" height="16" src="' . $pmaThemeImage . 'b_drop.png" alt="' . __('Delete tracking data for this table') . '" title="' . __('Delete tracking data for this table') . '" />'; } if ('both' === $GLOBALS['cfg']['PropertiesIconic'] || false === $GLOBALS['cfg']['PropertiesIconic']) { $drop_image_or_text .= __('Drop'); } $style = 'odd'; while ($one_result = PMA_DBI_fetch_array($all_tables_result)) { list($table_name, $version_number) = $one_result; $table_query = ' SELECT * FROM ' . PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' . PMA_backquote($GLOBALS['cfg']['Server']['tracking']) . ' WHERE `db_name` = \'' . PMA_sqlAddslashes($_REQUEST['db']) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($table_name) . '\' AND `version` = \'' . $version_number . '\''; $table_result = PMA_query_as_controluser($table_query); $version_data = PMA_DBI_fetch_array($table_result); if ($version_data['tracking_active'] == 1) { $version_status = __('active'); } else { $version_status = __('not active'); } $tmp_link = 'tbl_tracking.php?' . $url_query . '&table=' . htmlspecialchars($version_data['table_name']); $delete_link = 'db_tracking.php?' . $url_query . '&table=' . htmlspecialchars($version_data['table_name']) . '&delete_tracking=true&'; ?> <tr class="noclick <?php echo $style; ?> "> <td><?php echo htmlspecialchars($version_data['db_name']);
/** * get all tables involved or included in page * * @param string db name of the database * @param integer pageNumber page number whose tables will be fetched in an array * @return Array an array of tables * @access public */ public function getAllTables($db, $pageNumber) { global $cfgRelation; // Get All tables $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $pageNumber; $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE); if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) { $this->dieSchema('', __('This page does not contain any tables!')); } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) { $alltables[] = PMA_sqlAddslashes($curr_table['table_name']); } return $alltables; }
/** * renames table * * @param string new table name * @param string new database name * @param boolean is this for a VIEW rename? * @return boolean success */ function rename($new_name, $new_db = null, $is_view = false) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid if (!$GLOBALS['pma']->databases->exists($new_db)) { $this->errors[] = __('Invalid database') . ': ' . $new_db; return false; } } else { $new_db = $this->getDbName(); } $new_table = new PMA_Table($new_name, $new_db); if ($this->getFullName() === $new_table->getFullName()) { return true; } if (!PMA_Table::isValidName($new_name)) { $this->errors[] = __('Invalid table name') . ': ' . $new_table->getFullName(); return false; } if (!$is_view) { $GLOBALS['sql_query'] = ' ALTER TABLE ' . $this->getName(true) . ' RENAME TO ' . $new_table->getName(true); } else { $GLOBALS['sql_query'] = ' ALTER TABLE ' . $this->getFullName(true) . ' RENAME ' . $new_table->getFullName(true) . ';'; } // I don't think a specific error message for views is necessary if (!PMA_DBI_query($GLOBALS['sql_query'])) { $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $this->getFullName(), $new_table->getFullName()); return false; } $old_name = $this->getName(); $old_db = $this->getDbName(); $this->setName($new_name); $this->setDbName($new_db); /** * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db) */ // Move old entries from comments to new table $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); if ($GLOBALS['cfgRelation']['commwork']) { $remove_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($remove_query); unset($remove_query); } if ($GLOBALS['cfgRelation']['displaywork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['relwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `foreign_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `foreign_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `master_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `master_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['pdfwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['designerwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } $this->messages[] = sprintf(__('Table %s has been renamed to %s'), htmlspecialchars($old_name), htmlspecialchars($new_name)); return true; }
<?php // Now if we already have chosen a page number then we should show the // tables involved if (isset($chpage) && $chpage > 0) { echo "\n"; ?> <hr /> <h2><?php echo $strSelectTables; ?> </h2> <?php $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($chpage) . '\''; $page_rs = PMA_query_as_controluser($page_query, FALSE, $query_default_option); $array_sh_page = array(); $draginit = ''; $draginit2 = ''; $reset_draginit = ''; $i = 0; while ($temp_sh_page = @PMA_DBI_fetch_assoc($page_rs)) { $array_sh_page[] = $temp_sh_page; } // garvin: Display WYSIWYG-PDF parts? if ($cfg['WYSIWYG-PDF']) { if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) { $with_field_names = TRUE; } ?> <script type="text/javascript" src="./js/dom-drag.js"></script>
} // end if } // end if (!$is_information_schema) // not sure about displaying the PDF dialog in case db is information_schema if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?> <!-- Work on PDF Pages --> <?php // We only show this if we find something in the new pdf_pages table $test_query = ' SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''; $test_rs = PMA_query_as_controluser($test_query, null, PMA_DBI_QUERY_STORE); if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?> <!-- PDF schema --> <form method="post" action="pdf_schema.php"> <fieldset> <legend> <?php echo PMA_generate_common_hidden_inputs($db); if ($cfg['PropertiesIconic']) { echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"' . ' alt="" width="16" height="16" />'; } echo $strDisplayPDF; ?> : </legend>
} 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_query_as_controluser( 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . $cfg['Server']['relation'].' WHERE ' . 'master_db = \'' . PMA_sqlAddSlashes($DB2) . '\'' . ' AND master_table = \'' . PMA_sqlAddSlashes($T2) . '\'' . ' AND master_field = \'' . PMA_sqlAddSlashes($F2) . '\'' . ' AND foreign_db = \'' . PMA_sqlAddSlashes($DB1) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddSlashes($T1) . '\'' . ' AND foreign_field = \'' . PMA_sqlAddSlashes($F1) . '\'', false, PMA_DBI_QUERY_STORE ); } PMD_return_upd(1, __('Relation deleted')); function PMD_return_upd($b, $ret) { global $K; header("Content-Type: text/xml; charset=utf-8"); header("Cache-Control: no-cache"); die('<root act="relation_upd" return="'.$ret.'" b="'.$b.'" K="'.$K.'"></root>');
* */ require_once './libraries/pmd_common.php'; $cfgRelation = PMA_getRelationsParam(); if (!$cfgRelation['designerwork']) { PMD_err_sav(); } foreach ($t_x as $key => $value) { $KEY = empty($IS_AJAX) ? urldecode($key) : $key; // table name decode (post PDF exp/imp) list($DB, $TAB) = explode(".", $KEY); PMA_query_as_controluser('DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' WHERE `db_name` = \'' . PMA_sqlAddSlashes($DB) . '\' AND `table_name` = \'' . PMA_sqlAddSlashes($TAB) . '\'', true, PMA_DBI_QUERY_STORE); PMA_query_as_controluser('INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' (db_name, table_name, x, y, v, h) VALUES (' . '\'' . PMA_sqlAddSlashes($DB) . '\', ' . '\'' . PMA_sqlAddSlashes($TAB) . '\', ' . '\'' . PMA_sqlAddSlashes($t_x[$key]) . '\', ' . '\'' . PMA_sqlAddSlashes($t_y[$key]) . '\', ' . '\'' . PMA_sqlAddSlashes($t_v[$key]) . '\', ' . '\'' . PMA_sqlAddSlashes($t_h[$key]) . '\'' . ')', true, PMA_DBI_QUERY_STORE); } //---------------------------------------------------------------------------- function PMD_err_sav() { global $die_save_pos; // if this file included if (!empty($die_save_pos)) { header("Content-Type: text/xml; charset=utf-8"); header("Cache-Control: no-cache"); die('<root act="save_pos" return="' . __('Error saving coordinates for Designer.') . '"></root>'); } } if (!empty($die_save_pos)) { header("Content-Type: text/xml; charset=utf-8");
</head> <body> <br> <div> <?php if (!empty($message)) { $message->display(); } ?> <form name="form1" method="post" action="pmd_pdf.php"> <?php echo PMA_generate_common_hidden_inputs($db); echo '<div>'; echo '<fieldset><legend>' . __('Import/Export coordinates for PDF schema') . '</legend>'; $choices = array(); $table_info_result = PMA_query_as_controluser('SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''); if (PMA_DBI_num_rows($table_info_result) > 0) { echo '<p>' . __('Page') . ':'; echo '<select name="pdf_page_number">'; while ($page = PMA_DBI_fetch_assoc($table_info_result)) { echo '<option value="' . $page['page_nr'] . '">'; echo htmlspecialchars($page['page_descr']); echo '</option>'; } echo '</select>'; echo '</p>'; $choices['import'] = __('Import from selected page'); $choices['export'] = __('Export to selected page'); } $choices['create_export'] = __('Create a page and export to it'); if (1 == count($choices)) {
/** * Create a PDF page * * @param string $newpage name of the new PDF page * @param array $cfgRelation * @param string $db database name * * @return string $pdf_page_number */ function PMA_REL_create_page($newpage, $cfgRelation, $db) { if (!isset($newpage) || $newpage == '') { $newpage = __('no description'); } $ins_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' (db_name, page_descr)' . ' VALUES (\'' . PMA_sqlAddSlashes($db) . '\', \'' . PMA_sqlAddSlashes($newpage) . '\')'; PMA_query_as_controluser($ins_query, false); return PMA_DBI_insert_id(isset($GLOBALS['controllink']) ? $GLOBALS['controllink'] : ''); }
/** * Ouputs the PDF document to a file * or sends the output to browser * * @global object The current PDF document * @global string The current database name * @global integer The current page number (from the * $cfg['Servers'][$i]['table_coords'] table) * @access private * @see PMA_PDF */ private function _showOutput($pageNumber) { global $pdf, $db, $cfgRelation; $pdf->SetFontSize(14); $pdf->SetLineWidth(0.2); $pdf->SetDisplayMode('fullpage'); // Get the name of this pdfpage to use as filename (Mike Beck) $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE page_nr = ' . $pageNumber; $_name_rs = PMA_query_as_controluser($_name_sql); if ($_name_rs) { $_name_row = PMA_DBI_fetch_row($_name_rs); $filename = $_name_row[0] . '.pdf'; } if (empty($filename)) { $filename = $pageNumber . '.pdf'; } $fileName = PMA_sanitize_filename($fileName); // instead of $pdf->Output(): $pdfData = $pdf->getPDFData(); header('Content-Type: application/pdf'); header('Content-Length: ' . strlen($pdfData) . ''); header('Content-disposition: attachment; filename="' . $filename . '"'); echo $pdfData; }
/** * Ouputs the PDF document to a file * or sends the output to browser * * @param integer $pageNumber page number * * @global object The current PDF document * @global string The current database name * @global integer The current page number (from the * $cfg['Servers'][$i]['table_coords'] table) * @access private * * @return void * * @see PMA_Schema_PDF */ private function _showOutput($pageNumber) { global $pdf, $cfgRelation; // Get the name of this pdfpage to use as filename $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE page_nr = ' . $pageNumber; $_name_rs = PMA_query_as_controluser($_name_sql); if ($_name_rs) { $_name_row = PMA_DBI_fetch_row($_name_rs); $filename = $_name_row[0] . '.pdf'; } if (empty($filename)) { $filename = $pageNumber . '.pdf'; } $pdf->Download($filename); }
/** * renames table * * @param string new table name * @param string new database name * @param boolean is this for a VIEW rename? * @return boolean success * @todo remove the $is_view parameter (also in callers) */ function rename($new_name, $new_db = null, $is_view = false) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid if (!$GLOBALS['pma']->databases->exists($new_db)) { $this->errors[] = __('Invalid database') . ': ' . $new_db; return false; } } else { $new_db = $this->getDbName(); } $new_table = new PMA_Table($new_name, $new_db); if ($this->getFullName() === $new_table->getFullName()) { return true; } if (!PMA_Table::isValidName($new_name)) { $this->errors[] = __('Invalid table name') . ': ' . $new_table->getFullName(); return false; } // If the table is moved to a different database drop its triggers first $triggers = PMA_DBI_get_triggers($this->getDbName(), $this->getName(), ''); $handle_triggers = $this->getDbName() != $new_db && $triggers; if ($handle_triggers) { foreach ($triggers as $trigger) { $sql = 'DROP TRIGGER IF EXISTS ' . PMA_backquote($this->getDbName()) . '.' . PMA_backquote($trigger['name']) . ';'; PMA_DBI_query($sql); } } /* * tested also for a view, in MySQL 5.0.92, 5.1.55 and 5.5.13 */ $GLOBALS['sql_query'] = ' RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; // I don't think a specific error message for views is necessary if (!PMA_DBI_query($GLOBALS['sql_query'])) { // Restore triggers in the old database if ($handle_triggers) { PMA_DBI_select_db($this->getDbName()); foreach ($triggers as $trigger) { PMA_DBI_query($trigger['create']); } } $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $this->getFullName(), $new_table->getFullName()); return false; } $old_name = $this->getName(); $old_db = $this->getDbName(); $this->setName($new_name); $this->setDbName($new_db); /** * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db) */ // Move old entries from comments to new table $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); if ($GLOBALS['cfgRelation']['commwork']) { $remove_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($remove_query); unset($remove_query); } if ($GLOBALS['cfgRelation']['displaywork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['relwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `foreign_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `foreign_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `master_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `master_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['pdfwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['designerwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_controluser($table_query); unset($table_query); } $this->messages[] = sprintf(__('Table %s has been renamed to %s'), htmlspecialchars($old_name), htmlspecialchars($new_name)); return true; }
/** * Return UI preferences for this table from phpMyAdmin database. * * @return array */ protected function getUiPrefsFromDb() { $pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_backquote($GLOBALS['cfg']['Server']['table_uiprefs']); // Read from phpMyAdmin database $sql_query = " SELECT `prefs` FROM " . $pma_table . " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'" . " AND `db_name` = '" . PMA_sqlAddSlashes($this->db_name) . "'" . " AND `table_name` = '" . PMA_sqlAddSlashes($this->name) . "'"; $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); if (isset($row[0])) { return json_decode($row[0], true); } else { return array(); } }
/** * Analyzes a given SQL statement and saves tracking data. * * @param string $query a SQL query * * @static * * @return void */ static public function handleQuery($query) { // If query is marked as untouchable, leave if (strstr($query, "/*NOTRACK*/")) { return; } if (! (substr($query, -1) == ';')) { $query = $query . ";\n"; } // Get some information about query $result = self::parseQuery($query); // Get database name $dbname = trim($GLOBALS['db'], '`'); // $dbname can be empty, for example when coming from Synchronize // and this is a query for the remote server if (empty($dbname)) { return; } // If we found a valid statement if (isset($result['identifier'])) { $version = self::getVersion($dbname, $result['tablename'], $result['identifier']); // If version not exists and auto-creation is enabled if (self::$version_auto_create == true && self::isTracked($dbname, $result['tablename']) == false && $version == -1 ) { // Create the version switch ($result['identifier']) { case 'CREATE TABLE': self::createVersion($dbname, $result['tablename'], '1'); break; case 'CREATE VIEW': self::createVersion($dbname, $result['tablename'], '1', '', true); break; case 'CREATE DATABASE': self::createDatabaseVersion($dbname, '1', $query); break; } // end switch } // If version exists if (self::isTracked($dbname, $result['tablename']) && $version != -1) { if ($result['type'] == 'DDL') { $save_to = 'schema_sql'; } elseif ($result['type'] == 'DML') { $save_to = 'data_sql'; } else { $save_to = ''; } $date = date('Y-m-d H:i:s'); // Cut off `dbname`. from query $query = preg_replace('/`' . $dbname . '`\s?\./', '', $query); // Add log information $query = self::getLogComment() . $query ; // Mark it as untouchable $sql_query = " /*NOTRACK*/\n" . " UPDATE " . self::$pma_table . " SET " . PMA_backquote($save_to) ." = CONCAT( " . PMA_backquote($save_to) . ",'\n" . PMA_sqlAddSlashes($query) . "') ," . " `date_updated` = '" . $date . "' "; // If table was renamed we have to change the tablename attribute in pma_tracking too if ($result['identifier'] == 'RENAME TABLE') { $sql_query .= ', `table_name` = \'' . PMA_sqlAddSlashes($result['tablename_after_rename']) . '\' '; } // Save the tracking information only for // 1. the database // 2. the table / view // 3. the statements // we want to track $sql_query .= " WHERE FIND_IN_SET('" . $result['identifier'] . "',tracking) > 0" . " AND `db_name` = '" . PMA_sqlAddSlashes($dbname) . "' " . " AND `table_name` = '" . PMA_sqlAddSlashes($result['tablename']) . "' " . " AND `version` = '" . PMA_sqlAddSlashes($version) . "' "; $result = PMA_query_as_controluser($sql_query); } } }
</select> <input type="submit" name="show_versions_submit" value="<?php echo $strTrackingShowVersions; ?> " /> </form> <?php } ?> <br /> <?php /* * List versions of current table */ $sql_query = " SELECT * FROM " . PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_backquote($GLOBALS['cfg']['Server']['tracking']) . " WHERE " . PMA_backquote('db_name') . " = '" . PMA_sqlAddslashes($_REQUEST['db']) . "' " . " AND " . PMA_backquote('table_name') . " = '" . PMA_sqlAddslashes($_REQUEST['table']) . "' " . " ORDER BY " . PMA_backquote('version') . " DESC "; $sql_result = PMA_query_as_controluser($sql_query); $last_version = 0; $maxversion = PMA_DBI_fetch_array($sql_result); $last_version = $maxversion['version']; if ($last_version > 0) { ?> <table id="versions" class="data"> <thead> <tr> <th><?php echo $strDatabase; ?> </th> <th><?php echo $strTable; ?>
/** * Runs query inside import buffer. This is needed to allow displaying * of last SELECT, SHOW or HANDLER results and similar nice stuff. * * @param string $sql query to run * @param string $full query to display, this might be commented * @param bool $controluser whether to use control user for queries * * @access public */ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) { global $import_run_buffer, $go_sql, $complete_query, $display_query, $sql_query, $my_die, $error, $reload, $last_query_with_results, $skip_queries, $executed_queries, $max_sql_len, $read_multiply, $cfg, $sql_query_disabled, $db, $run_query, $is_superuser; $read_multiply = 1; if (isset($import_run_buffer)) { // Should we skip something? if ($skip_queries > 0) { $skip_queries--; } else { if (!empty($import_run_buffer['sql']) && trim($import_run_buffer['sql']) != '') { $max_sql_len = max($max_sql_len, strlen($import_run_buffer['sql'])); if (!$sql_query_disabled) { $sql_query .= $import_run_buffer['full']; } if (!$cfg['AllowUserDropDatabase'] && !$is_superuser && preg_match('@^[[:space:]]*DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE @i', $import_run_buffer['sql'])) { $GLOBALS['message'] = PMA_Message::error(__('"DROP DATABASE" statements are disabled.')); $error = true; } else { $executed_queries++; if ($run_query && $GLOBALS['finished'] && empty($sql) && !$error && (!empty($import_run_buffer['sql']) && preg_match('/^[\\s]*(SELECT|SHOW|HANDLER)/i', $import_run_buffer['sql']) || $executed_queries == 1)) { $go_sql = true; if (!$sql_query_disabled) { $complete_query = $sql_query; $display_query = $sql_query; } else { $complete_query = ''; $display_query = ''; } $sql_query = $import_run_buffer['sql']; // If a 'USE <db>' SQL-clause was found, set our current $db to the new one list($db, $reload) = PMA_lookForUse($import_run_buffer['sql'], $db, $reload); } elseif ($run_query) { if ($controluser) { $result = PMA_query_as_controluser($import_run_buffer['sql']); } else { $result = PMA_DBI_try_query($import_run_buffer['sql']); } $msg = '# '; if ($result === false) { // execution failed if (!isset($my_die)) { $my_die = array(); } $my_die[] = array('sql' => $import_run_buffer['full'], 'error' => PMA_DBI_getError()); if ($cfg['VerboseMultiSubmit']) { $msg .= __('Error'); } if (!$cfg['IgnoreMultiSubmitErrors']) { $error = true; return; } } elseif ($cfg['VerboseMultiSubmit']) { $a_num_rows = (int) @PMA_DBI_num_rows($result); $a_aff_rows = (int) @PMA_DBI_affected_rows(); if ($a_num_rows > 0) { $msg .= __('Rows') . ': ' . $a_num_rows; $last_query_with_results = $import_run_buffer['sql']; } elseif ($a_aff_rows > 0) { $message = PMA_Message::affected_rows($a_aff_rows); $msg .= $message->getMessage(); } else { $msg .= __('MySQL returned an empty result set (i.e. zero rows).'); } } if (!$sql_query_disabled) { $sql_query .= $msg . "\n"; } // If a 'USE <db>' SQL-clause was found and the query succeeded, set our current $db to the new one if ($result != false) { list($db, $reload) = PMA_lookForUse($import_run_buffer['sql'], $db, $reload); } if ($result != false && preg_match('@^[\\s]*(DROP|CREATE)[\\s]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $import_run_buffer['sql'])) { $reload = true; } } // end run query } // end if not DROP DATABASE // end non empty query } elseif (!empty($import_run_buffer['full'])) { if ($go_sql) { $complete_query .= $import_run_buffer['full']; $display_query .= $import_run_buffer['full']; } else { if (!$sql_query_disabled) { $sql_query .= $import_run_buffer['full']; } } } // check length of query unless we decided to pass it to sql.php // (if $run_query is false, we are just displaying so show // the complete query in the textarea) if (!$go_sql && $run_query) { if ($cfg['VerboseMultiSubmit'] && !empty($sql_query)) { if (strlen($sql_query) > 50000 || $executed_queries > 50 || $max_sql_len > 1000) { $sql_query = ''; $sql_query_disabled = true; } } else { if (strlen($sql_query) > 10000 || $executed_queries > 10 || $max_sql_len > 500) { $sql_query = ''; $sql_query_disabled = true; } } } } // end do query (no skip) } // end buffer exists // Do we have something to push into buffer? if (!empty($sql) || !empty($full)) { $import_run_buffer = array('sql' => $sql, 'full' => $full); } else { unset($GLOBALS['import_run_buffer']); } }