diff --git a/export_relation_schema.php b/export_relation_schema.php
index c3c985283..b8c2a4d17 100644
--- a/export_relation_schema.php
+++ b/export_relation_schema.php
@@ -20,20 +20,24 @@ $url_query .= '&goto=export_relation_schema.php';
require_once './libraries/db_info.inc.php';
/**
- * Settings for relation stuff
+ * Includ settings for relation stuff
+ * get all variables needed for exporting relational schema
+ * in $cfgRelation
*/
require_once './libraries/relation.lib.php';
$cfgRelation = PMA_getRelationsParam();
-// This is to avoid "Command out of sync" errors. Before switching this to
-// a value of 0 (for MYSQLI_USE_RESULT), please check the logic
-// to free results wherever needed.
+/**
+ * This is to avoid "Command out of sync" errors. Before switching this to
+ * a value of 0 (for MYSQLI_USE_RESULT), please check the logic
+ * to free results wherever needed.
+ */
$query_default_option = PMA_DBI_QUERY_STORE;
/**
* Now in ./libraries/relation.lib.php we check for all tables
* that we need, but if we don't find them we are quiet about it
- * so people can work without.
+ * so people can't work without relational variables.
* This page is absolutely useless if you didn't set up your tables
* correctly, so it is a good place to see which tables we can and
* complain ;-)
@@ -63,46 +67,50 @@ if (!isset($cfgRelation['pdf_pages'])) {
if ($cfgRelation['pdfwork']) {
- /**
- * User Object Created for displaying the HTML options
- * so, user can play with it and perform export of relations schema
- */
+ /**
+ * User object created for presenting the HTML options
+ * so, user can interact with it and perform export of relations schema
+ */
- require_once './libraries/schema/user_schema.php';
- $user_schema = new PMA_User_Schema();
+ require_once './libraries/schema/User_Schema.class.php';
+ $user_schema = new PMA_User_Schema();
- /**
- * This function will process the user input
- *
- */
- $user_schema->userInputProcess($do);
-
- /**
- * Now first show some possibility to select a page for the export of relation schema
- */
- $user_schema->selectPage();
-
- /**
- * Possibility to create a new page:
- */
- $user_schema->createPage();
-
- /**
- * After selection of page or creating a page
- * It will show you the list of tables
- * A dashboard will also be shown where you can position the tables
- */
- $user_schema->showTableDashBoard();
+ /**
+ * This function will process the user input
+ */
+
+ $user_schema->processUserPreferences($do);
+
+ /**
+ * Now first show some possibility to select a page for the export of relation schema
+ */
+
+ $user_schema->selectPage();
+
+ /**
+ * Possibility to create a new page:
+ */
+
+ $user_schema->createPage();
+
+ /**
+ * After selection of page or creating a page
+ * It will show you the list of tables
+ * A dashboard will also be shown where you can position the tables
+ */
+
+ $user_schema->showTableDashBoard();
if (isset($do)
&& ($do == 'edcoord'
- || ($do == 'selectpage' && isset($chpage))
- || ($do == 'createpage' && isset($chpage)))) {
- /**
- * show Export schema generation options
- */
+ || ($do == 'selectpage' && isset($chpage) && $chpage != 0)
+ || ($do == 'createpage' && isset($chpage) && $chpage != 0))) {
+
+ /**
+ * show Export schema generation options
+ */
$user_schema->displaySchemaGenerationOptions();
-
+
if ((isset($showwysiwyg) && $showwysiwyg == '1')) {
?>
- _out('/First ' . ($this->n + 1) . ' 0 R');
$this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
$this->_out('/Count -' . $kids);
- }tur
+ }
$this->_out('>>');
$this->_out('endobj');
}
diff --git a/libraries/schema/User_Schema.class.php b/libraries/schema/User_Schema.class.php
index 723ce3d69..60c703a92 100644
--- a/libraries/schema/User_Schema.class.php
+++ b/libraries/schema/User_Schema.class.php
@@ -1,608 +1,588 @@
+ * @copyright
+ * @license
+ */
+
class PMA_User_Schema
-{
-/* private $_exportType;
- public function __construct()
- {
- $this->_exportType='pdf'; // default export type
- }
-
- public function setExportType($type)
- {
- $this->_exportType=$type;
- }
-
- public function getExportType()
- {
- return $this->_exportType;
- }*/
-
- /**
- * This function will process the user input
- *
- */
- public function userInputProcess($do)
- {
- global $action_choose,$chpage,$db,$cfgRelation,$cfg,$auto_layout_foreign,$auto_layout_internal,$newpage,$c_table_rows,$query_default_option;
- // Now is the time to work on all changes
- //echo $do;
+{
+ /**
+ * 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 $do It is hidden value
+ * @access public
+ */
+
+ public function processUserPreferences($do)
+ {
+ global $action_choose,$chpage,$db,$cfgRelation,$cfg,$auto_layout_foreign,$auto_layout_internal,$newpage,$c_table_rows,$query_default_option;
+
if (isset($do)) {
switch ($do) {
- case 'selectpage':
- if ($action_choose=="1") {
- $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
- . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
- . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($chpage) . '\'';
- PMA_query_as_controluser($ch_query, FALSE, $query_default_option);
+ case 'selectpage':
+ if ($action_choose=="1") {
+ $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
+ . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
+ . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($chpage) . '\'';
+ PMA_query_as_controluser($ch_query, FALSE, $query_default_option);
- $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
- . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
- . ' AND page_nr = \'' . PMA_sqlAddslashes($chpage) . '\'';
- PMA_query_as_controluser($ch_query, FALSE, $query_default_option);
+ $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
+ . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
+ . ' AND page_nr = \'' . PMA_sqlAddslashes($chpage) . '\'';
+ PMA_query_as_controluser($ch_query, FALSE, $query_default_option);
- unset($chpage);
- }
- break;
- case 'createpage':
-
- $pdf_page_number = PMA_REL_create_page($newpage, $cfgRelation, $db, $query_default_option);
-
- // A u t o m a t i c l a y o u t
- // ================================
- if (isset($auto_layout_internal) || isset($auto_layout_foreign)) {
- $all_tables = array();
- }
+ unset($chpage);
+ }
+ break;
+ case 'createpage':
+ $pdf_page_number = PMA_REL_create_page($newpage, $cfgRelation, $db, $query_default_option);
- if (isset($auto_layout_foreign)) {
- // get the tables list
- $tables = PMA_DBI_get_tables_full($db);
- // find the ones 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
- $foreignkey_tables = array();
- foreach($tables as $table_name => $table_properties) {
+ /*
+ * A u t o m a t i c l a y o u t
+ *
+ * There are 2 kinds of relations in PMA
+ * 1) Internal Relations 2) Foreign Key Relations
+ */
+ if (isset($auto_layout_internal) || isset($auto_layout_foreign)) {
+ $all_tables = array();
+ }
+
+ if (isset($auto_layout_foreign)) {
+ /*
+ * 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;
+ }
+ $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);
- } // endif auto_layout_foreign
+ unset($tables, $foreignkey_tables);
+ }
- if (isset($auto_layout_internal)) {
- // get the tables that have relations, by descending
- // number of links
- $master_tables = 'SELECT COUNT(master_table), master_table'
+ if (isset($auto_layout_internal)) {
+ /*
+ * 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;
- }
+ $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;
+ }
- // then 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)
+ /* 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) {
+ $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'];
}
}
- }
+ }
- // then merge the arrays
- foreach ($foreign_tables as $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;
}
- }
- } // endif there are master tables
- } // endif auto_layout_internal
+ }
+ } // endif there are master tables
+ } // endif auto_layout_internal
- if (isset($auto_layout_internal) || isset($auto_layout_foreign)) {
- // now generate the coordinates for the schema,
- // in a clockwise spiral
-
- $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
+ if (isset($auto_layout_internal) || isset($auto_layout_foreign)) {
+ /*
+ * Now generate the coordinates for the schema
+ * in a clockwise spiral
+ */
+ $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) . '\',' . $pdf_page_number . ',' . $pos_x . ',' . $pos_y . ')';
PMA_query_as_controluser($insert_query, FALSE, $query_default_option);
- // compute for the next table
+ /*
+ * 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;
+ 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;
} // end switch
- } // end foreach
- } // end if some auto-layout to do
+ } // end foreach
+ } // end if some auto-layout to do
- $chpage = $pdf_page_number;
+ $chpage = $pdf_page_number;
+ break;
- break;
-
- case 'edcoord':
- for ($i = 0; $i < $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($chpage) . '\'';
- // echo $test_query;
- $test_rs = PMA_query_as_controluser($test_query, FALSE, $query_default_option);
- 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($chpage) . '\'';
- } 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($chpage) . '\'';
- }
- } 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($chpage) . '\',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
- }
- //echo $ch_query;
- PMA_query_as_controluser($ch_query, FALSE, $query_default_option);
- } // end if
- } // end for
- break;
- case 'deleteCrap':
- foreach ($delrow as $current_row) {
- $d_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
- . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
- . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
- . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($chpage) . '\'';
- PMA_query_as_controluser($d_query, FALSE, $query_default_option);
+ case 'edcoord':
+ for ($i = 0; $i < $c_table_rows; $i++) {
+ $arrvalue = 'c_table_' . $i;
+ global $$arrvalue;
+ $arrvalue = $$arrvalue;
+ if (!isset($arrvalue['x']) || $arrvalue['x'] == '') {
+ $arrvalue['x'] = 0;
}
- break;
+ 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($chpage) . '\'';
+ // echo $test_query;
+ $test_rs = PMA_query_as_controluser($test_query, FALSE, $query_default_option);
+ 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($chpage) . '\'';
+ } 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($chpage) . '\'';
+ }
+ } 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($chpage) . '\',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
+ }
+ //echo $ch_query;
+ PMA_query_as_controluser($ch_query, FALSE, $query_default_option);
+ } // end if
+ } // end for
+ break;
+
+ case 'deleteCrap':
+ $this->_deleteTableRows();
+ break;
+
+ case 'process_export':
+ $this->_processExportSchema();
+ break;
+
} // end switch
} // end if (isset($do))
}
- /**
- * This function shows/displays the HTML FORM to create the page
- *
- */
+ /**
+ * shows/displays the HTML FORM to create the page
+ *
+ * @access public
+ */
+
public function createPage()
{
- global $db,$table;
- ?>
-