action = $value;
}
/**
* This function will process the user defined pages
* and tables which will be exported as Relational schema
* you can set the table positions on the paper via scratchboard
* for table positions, put the x,y co-ordinates
*
* @param string $this->action It tells what the Schema is supposed to do
* create and select a page, generate schema etc
* @access public
*/
public function processUserChoice()
{
global $action_choose,$db,$cfgRelation,$cfg,$query_default_option;
if (isset($this->action)) {
switch ($this->action) {
case 'selectpage':
$this->chosenPage = $_REQUEST['chpage'];
if ($action_choose=="1") {
$this->deleteCoordinates($db, $cfgRelation, $this->chosenPage, $query_default_option);
$this->deletePages($db, $cfgRelation, $this->chosenPage, $query_default_option);
$this->chosenPage = 0;
}
break;
case 'createpage':
$this->pageNumber = PMA_REL_create_page($_POST['newpage'], $cfgRelation, $db, $query_default_option);
$this->autoLayoutForeign = isset($_POST['auto_layout_foreign']) ? "1":NULL;
$this->autoLayoutInternal = isset($_POST['auto_layout_internal']) ? "1":NULL;
$this->processRelations($db, $this->pageNumber,$cfgRelation,$query_default_option);
break;
case 'edcoord':
$this->chosenPage = $_POST['chpage'];
$this->c_table_rows = $_POST['c_table_rows'];
$this->_editCoordinates($db, $cfgRelation,$query_default_option);
break;
case 'delete_old_references':
$this->_deleteTableRows($_POST['delrow'], $cfgRelation, $db, $_POST['chpage']);
break;
case 'process_export':
$this->_processExportSchema();
break;
} // end switch
} // end if (isset($do))
}
/**
* shows/displays the HTML FORM to create the page
*
* @param string db name of the selected database
* @return void
* @access public
*/
public function showCreatePageDialog($db)
{
?>
0) {
?>
chosenPage) && $this->chosenPage > 0) {
echo "\n";
?>
chosenPage) . '\'';
$page_rs = PMA_query_as_controluser($page_query, FALSE, $query_default_option);
$array_sh_page = array();
while ($temp_sh_page = @PMA_DBI_fetch_assoc($page_rs)) {
$array_sh_page[] = $temp_sh_page;
}
/*
* Display WYSIWYG parts
*/
if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
$with_field_names = TRUE;
}
$this->_displayScratchboardTables($array_sh_page);
?>
' . "\n\n";
} // end if
$this->_deleteTables($db, $this->chosenPage, $tabExist);
}
/**
* show Export relational schema generation options
* user can select export type of his own choice
* and the attributes related to it
*
* @return void
* @access public
*/
public function displaySchemaGenerationOptions()
{
global $cfg,$pmaThemeImage,$db,$test_rs,$chpage;
?>
$value) {
if (!$value) {
$_strtrans .= '' . "\n";
$_strname .= '
' . htmlspecialchars($key) . '
' . "\n";
$shoot = TRUE;
}
}
if ($shoot) {
echo '';
}
}
}
/**
* Check if there are tables that need to be deleted in dashboard,
* if there are, ask the user for allowance
*
* @return void
* @access private
*/
private function _displayScratchboardTables($array_sh_page)
{
global $with_field_names,$cfg,$db;
?>
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 = PMA_DBI_get_tables_full($db);
$foreignkey_tables = array();
foreach($tables as $table_name => $table_properties) {
if (PMA_foreignkey_supported($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_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . $db . '\''
. ' GROUP BY master_table'
. ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
$master_tables_rs = PMA_query_as_controluser($master_tables, FALSE, $query_default_option);
if ($master_tables_rs && PMA_DBI_num_rows($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) = PMA_DBI_fetch_row($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,$query_default_option);
}
$this->chosenPage = $pageNumber;
}
/**
* Add X and Y coordinates for a table
*
* @param string db The database name
* @param array cfgRelation relation settings
* @param integer pageNumber document number/Id
* @param array all_tables A list of all tables involved
* @return void
* @access private
*/
public function addRelationCoordinates($all_tables,$pageNumber,$db, $cfgRelation,$query_default_option)
{
/*
* Now generate the coordinates for the schema
* in a clockwise spiral and add to co-ordinates table
*/
$pos_x = 300;
$pos_y = 300;
$delta = 110;
$delta_mult = 1.10;
$direction = "right";
foreach ($all_tables as $current_table) {
/*
* save current table's coordinates
*/
$insert_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($current_table) . '\',' . $pageNumber . ',' . $pos_x . ',' . $pos_y . ')';
PMA_query_as_controluser($insert_query, FALSE, $query_default_option);
/*
* compute for the next table
*/
switch ($direction) {
case 'right':
$pos_x += $delta;
$direction = "down";
$delta *= $delta_mult;
break;
case 'down':
$pos_y += $delta;
$direction = "left";
$delta *= $delta_mult;
break;
case 'left':
$pos_x -= $delta;
$direction = "up";
$delta *= $delta_mult;
break;
case 'up':
$pos_y -= $delta;
$direction = "right";
$delta *= $delta_mult;
break;
}
}
}
/**
* 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,$query_default_option)
{
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, $query_default_option);
//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, $query_default_option);
} // end if
} // end for
}
}
?>