diff --git a/js/pmd/move.js b/js/pmd/move.js
index 020c945954..1be0e87a78 100644
--- a/js/pmd/move.js
+++ b/js/pmd/move.js
@@ -936,11 +936,20 @@ function Export_pages()
PMA_ajaxShowMessage(data.error, false);
} else {
PMA_ajaxRemoveMessage($msgbox);
+
+ var $form = $(data.message);
+ var $formatDropDown = $form.find('#plugins');
+ $formatDropDown.change(function() {
+ var format = $formatDropDown.val();
+ $form.find('.format_specific_options').hide();
+ $form.find('#' + format + '_options').show();
+ }).trigger('change');
+
$('
')
- .append(data.message)
+ .append($form)
.dialog({
title: PMA_messages.strExportRelationalSchema,
- width: 400,
+ width: 550,
modal: true,
buttons: button_options,
close: function () {
@@ -951,26 +960,13 @@ function Export_pages()
}); // end $.get()
}// end export pages
-function getParamsForExport($from)
+function getParamsForExport($form)
{
- var url = "";
- url += "&db=" + $from.find('input[name="db"]').val();
- url += "&token=" + $from.find('input[name="token"]').val();
- url += "&do=" + $from.find('input[name="do"]').val();
- url += "&export_type=" + $from.find("#export_type").val();
- url += "&chpage=" + $from.find('input[name="chpage"]').val();
- url += "&orientation=" + $from.find('select[name="orientation"]').val();
- url += "&paper=" + $from.find('select[name="paper"]').val();
- url += "&show_color=" + ($from.find('input[name="show_color"]').is(":checked") ? "on" : "off");
- url += "&with_doc=" + ($from.find('input[name="with_doc"]').is(":checked") ? "on" : "off");
- url += "&all_tables_same_width=" + ($from.find('input[name="all_tables_same_width"]').is(":checked") ? "on" : "off");
- url += "&show_grid=" + ($from.find('input[name="show_grid"]').is(":checked") ? "on" : "off");
- url += "&show_keys=" + ($from.find('input[name="show_keys"]').is(":checked") ? "on" : "off");
- url += "&show_table_dimension=" + ($from.find('input[name="show_table_dimension"]').is(":checked") ? "on" : "off");
- url += "&offline_export=" + (pmd_tables_enabled ? "off" : "on");
+ var url = $form.serialize();
if (pmd_tables_enabled) {
url += Get_url_pos();
} else {
+ url += "&offline_export=true";
url += "&tbl_coords=" + JSON.stringify(Get_url_pos());
}
diff --git a/libraries/designer.lib.php b/libraries/designer.lib.php
index 880285a62e..59993b7195 100644
--- a/libraries/designer.lib.php
+++ b/libraries/designer.lib.php
@@ -143,64 +143,34 @@ function PMA_getPageIdsAndNames($db)
*/
function PMA_getHtmlForSchemaExport($db, $page)
{
- $htmlString = '';
+ $htmlString = '';
return $htmlString;
}
diff --git a/libraries/plugins/SchemaPlugin.class.php b/libraries/plugins/SchemaPlugin.class.php
new file mode 100644
index 0000000000..1a49823b50
--- /dev/null
+++ b/libraries/plugins/SchemaPlugin.class.php
@@ -0,0 +1,76 @@
+properties;
+ }
+
+ /**
+ * Sets the export plugins properties and is implemented by
+ * each schema export plugin
+ *
+ * @return void
+ */
+ protected abstract function setProperties();
+
+ /**
+ * Exports the shcema into the specified format.
+ *
+ * @param string $db database name
+ *
+ * @return bool Whether it succeeded
+ */
+ public abstract function exportSchema($db);
+
+ /**
+ * Adds export options common to all plugins.
+ *
+ * @param OptionsPropertyMainGroup $properyGroup property group
+ *
+ * @return void
+ */
+ protected function addCommonOptions(OptionsPropertyMainGroup $properyGroup)
+ {
+ $leaf = new BoolPropertyItem();
+ $leaf->setName('show_color');
+ $leaf->setText(__('Show color'));
+ $properyGroup->addProperty($leaf);
+ $leaf = new BoolPropertyItem();
+ $leaf->setName('show_keys');
+ $leaf->setText(__('Only show keys'));
+ $properyGroup->addProperty($leaf);
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/schema/Export_Relation_Schema.class.php b/libraries/plugins/schema/Export_Relation_Schema.class.php
similarity index 69%
rename from libraries/schema/Export_Relation_Schema.class.php
rename to libraries/plugins/schema/Export_Relation_Schema.class.php
index 1d452f4a18..0b0808ea9a 100644
--- a/libraries/schema/Export_Relation_Schema.class.php
+++ b/libraries/plugins/schema/Export_Relation_Schema.class.php
@@ -19,18 +19,26 @@ if (! defined('PHPMYADMIN')) {
*/
class PMA_Export_Relation_Schema
{
- private $_pageTitle;
- public $showGrid;
- public $showColor;
- public $tableDimension;
- public $sameWide;
- public $withDoc;
- public $showKeys;
- public $orientation;
- public $paper;
- public $pageNumber;
- public $exportType;
- public $offline;
+ /**
+ * Constructor.
+ *
+ * @see PMA_SVG
+ */
+ function __construct()
+ {
+ $this->setPageNumber($_REQUEST['page_number']);
+ $this->setOffline(isset($_REQUEST['offline_export']));
+ }
+
+ protected $showColor;
+ protected $tableDimension;
+ protected $sameWide;
+ protected $showKeys;
+ protected $orientation;
+ protected $paper;
+
+ protected $pageNumber;
+ protected $offline;
/**
* Set Page Number
@@ -43,33 +51,19 @@ class PMA_Export_Relation_Schema
*/
public function setPageNumber($value)
{
- $this->pageNumber = isset($value) ? $value : 1;
- }
-
- /**
- * Set Show Grid
- *
- * @param boolean $value show grid of the document or not
- *
- * @return void
- *
- * @access public
- */
- public function setShowGrid($value)
- {
- $this->showGrid = (isset($value) && $value == 'on');
+ $this->pageNumber = $value;
}
/**
* Sets showColor
*
- * @param string $value 'on' to set the the variable
+ * @param boolean $value whether to show colors
*
* @return void
*/
public function setShowColor($value)
{
- $this->showColor = (isset($value) && $value == 'on');
+ $this->showColor = $value;
}
/**
@@ -83,7 +77,7 @@ class PMA_Export_Relation_Schema
*/
public function setTableDimension($value)
{
- $this->tableDimension = (isset($value) && $value == 'on');
+ $this->tableDimension = $value;
}
/**
@@ -97,21 +91,7 @@ class PMA_Export_Relation_Schema
*/
public function setAllTablesSameWidth($value)
{
- $this->sameWide = (isset($value) && $value == 'on');
- }
-
- /**
- * Set Data Dictionary
- *
- * @param boolean $value show selected database data dictionary or not
- *
- * @return void
- *
- * @access public
- */
- public function setWithDataDictionary($value)
- {
- $this->withDoc = (isset($value) && $value == 'on');
+ $this->sameWide = $value;
}
/**
@@ -125,7 +105,7 @@ class PMA_Export_Relation_Schema
*/
public function setShowKeys($value)
{
- $this->showKeys = (isset($value) && $value == 'on');
+ $this->showKeys = $value;
}
/**
@@ -139,7 +119,7 @@ class PMA_Export_Relation_Schema
*/
public function setOrientation($value)
{
- $this->orientation = (isset($value) && $value == 'P') ? 'P' : 'L';
+ $this->orientation = ($value == 'P') ? 'P' : 'L';
}
/**
@@ -153,35 +133,7 @@ class PMA_Export_Relation_Schema
*/
public function setPaper($value)
{
- $this->paper = isset($value) ? $value : 'A4';
- }
-
- /**
- * Set title of the page
- *
- * @param string $title title of the page displayed at top of the document
- *
- * @return void
- *
- * @access public
- */
- public function setPageTitle($title)
- {
- $this->_pageTitle=$title;
- }
-
- /**
- * Set type of export relational schema
- *
- * @param string $value can be pdf,svg,dia,eps etc
- *
- * @return void
- *
- * @access public
- */
- public function setExportType($value)
- {
- $this->exportType=$value;
+ $this->paper = $value;
}
/**
@@ -195,7 +147,7 @@ class PMA_Export_Relation_Schema
*/
public function setOffline($value)
{
- $this->offline = (isset($value) && $value == 'on');
+ $this->offline = $value;
}
/**
@@ -222,12 +174,10 @@ class PMA_Export_Relation_Schema
*/
public function getAllTables($db, $pageNumber)
{
- global $cfgRelation;
-
// Get All tables
$tab_sql = 'SELECT table_name FROM '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
- . PMA_Util::backquote($cfgRelation['table_coords'])
+ . PMA_Util::backquote($GLOBALS['cfgRelation']['table_coords'])
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
. ' AND pdf_page_number = ' . $pageNumber;
diff --git a/libraries/plugins/schema/RelationStats.class.php b/libraries/plugins/schema/RelationStats.class.php
new file mode 100644
index 0000000000..a79facf200
--- /dev/null
+++ b/libraries/plugins/schema/RelationStats.class.php
@@ -0,0 +1,26 @@
+
\ No newline at end of file
diff --git a/libraries/plugins/schema/SchemaDia.class.php b/libraries/plugins/schema/SchemaDia.class.php
new file mode 100644
index 0000000000..5dcf548204
--- /dev/null
+++ b/libraries/plugins/schema/SchemaDia.class.php
@@ -0,0 +1,117 @@
+setProperties();
+ }
+
+ /**
+ * Sets the schema export Dia properties
+ *
+ * @return void
+ */
+ protected function setProperties()
+ {
+ $props = 'libraries/properties/';
+ include_once "$props/plugins/SchemaPluginProperties.class.php";
+ include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
+ include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
+ include_once "$props/options/items/BoolPropertyItem.class.php";
+ include_once "$props/options/items/SelectPropertyItem.class.php";
+
+ $schemaPluginProperties = new SchemaPluginProperties();
+ $schemaPluginProperties->setText('Dia');
+ $schemaPluginProperties->setExtension('dia');
+ $schemaPluginProperties->setMimeType('application/dia');
+
+ // create the root group that will be the options field for
+ // $schemaPluginProperties
+ // this will be shown as "Format specific options"
+ $exportSpecificOptions = new OptionsPropertyRootGroup();
+ $exportSpecificOptions->setName("Format Specific Options");
+
+ // specific options main group
+ $specificOptions = new OptionsPropertyMainGroup();
+ $specificOptions->setName("general_opts");
+ // add options common to all plugins
+ $this->addCommonOptions($specificOptions);
+
+ $leaf = new SelectPropertyItem();
+ $leaf->setName("orientation");
+ $leaf->setText(__('Orientation'));
+ $leaf->setValues(
+ array(
+ 'L' => 'Landscape',
+ 'P' => 'Portrait',
+ )
+ );
+ $specificOptions->addProperty($leaf);
+
+ $leaf = new SelectPropertyItem();
+ $leaf->setName("paper");
+ $leaf->setText(__('Paper size'));
+ $leaf->setValues($this->_getPaperSizeArray());
+ $specificOptions->addProperty($leaf);
+
+ // add the main group to the root group
+ $exportSpecificOptions->addProperty($specificOptions);
+
+ // set the options for the schema export plugin property item
+ $schemaPluginProperties->setOptions($exportSpecificOptions);
+ $this->properties = $schemaPluginProperties;
+ }
+
+ /**
+ * Returns the array of paper sizes
+ *
+ * @return array array of paper sizes
+ */
+ private function _getPaperSizeArray()
+ {
+ $ret = array();
+ foreach ($GLOBALS['cfg']['PDFPageSizes'] as $val) {
+ $ret[$val] = $val;
+ }
+ return $ret;
+ }
+
+
+ /**
+ * Exports the shcema into DIA format.
+ *
+ * @param string $db database name
+ *
+ * @return bool Whether it succeeded
+ */
+ public function exportSchema($db)
+ {
+ $export = new PMA_Dia_Relation_Schema();
+ $export->showOutput();
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/plugins/schema/SchemaEps.class.php b/libraries/plugins/schema/SchemaEps.class.php
new file mode 100644
index 0000000000..f2281b9c89
--- /dev/null
+++ b/libraries/plugins/schema/SchemaEps.class.php
@@ -0,0 +1,102 @@
+setProperties();
+ }
+
+ /**
+ * Sets the schema export EPS properties
+ *
+ * @return void
+ */
+ protected function setProperties()
+ {
+ $props = 'libraries/properties/';
+ include_once "$props/plugins/SchemaPluginProperties.class.php";
+ include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
+ include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
+ include_once "$props/options/items/BoolPropertyItem.class.php";
+ include_once "$props/options/items/SelectPropertyItem.class.php";
+
+ $schemaPluginProperties = new SchemaPluginProperties();
+ $schemaPluginProperties->setText('EPS');
+ $schemaPluginProperties->setExtension('eps');
+ $schemaPluginProperties->setMimeType('application/eps');
+
+ // create the root group that will be the options field for
+ // $schemaPluginProperties
+ // this will be shown as "Format specific options"
+ $exportSpecificOptions = new OptionsPropertyRootGroup();
+ $exportSpecificOptions->setName("Format Specific Options");
+
+ // specific options main group
+ $specificOptions = new OptionsPropertyMainGroup();
+ $specificOptions->setName("general_opts");
+ // add options common to all plugins
+ $this->addCommonOptions($specificOptions);
+
+ // create leaf items and add them to the group
+ $leaf = new BoolPropertyItem();
+ $leaf->setName('all_tables_same_width');
+ $leaf->setText(__('Same width for all tables'));
+ $specificOptions->addProperty($leaf);
+
+ $leaf = new SelectPropertyItem();
+ $leaf->setName("orientation");
+ $leaf->setText(__('Orientation'));
+ $leaf->setValues(
+ array(
+ 'L' => 'Landscape',
+ 'P' => 'Portrait',
+ )
+ );
+ $specificOptions->addProperty($leaf);
+
+ // add the main group to the root group
+ $exportSpecificOptions->addProperty($specificOptions);
+
+ // set the options for the schema export plugin property item
+ $schemaPluginProperties->setOptions($exportSpecificOptions);
+ $this->properties = $schemaPluginProperties;
+ }
+
+ /**
+ * Exports the shcema into EPS format.
+ *
+ * @param string $db database name
+ *
+ * @return bool Whether it succeeded
+ */
+ public function exportSchema($db)
+ {
+ $export = new PMA_Eps_Relation_Schema();
+ $export->showOutput();
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/plugins/schema/SchemaPdf.class.php b/libraries/plugins/schema/SchemaPdf.class.php
new file mode 100644
index 0000000000..b41dda67ab
--- /dev/null
+++ b/libraries/plugins/schema/SchemaPdf.class.php
@@ -0,0 +1,132 @@
+setProperties();
+ }
+
+ /**
+ * Sets the schema export PDF properties
+ *
+ * @return void
+ */
+ protected function setProperties()
+ {
+ $props = 'libraries/properties/';
+ include_once "$props/plugins/SchemaPluginProperties.class.php";
+ include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
+ include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
+ include_once "$props/options/items/BoolPropertyItem.class.php";
+ include_once "$props/options/items/SelectPropertyItem.class.php";
+
+ $schemaPluginProperties = new SchemaPluginProperties();
+ $schemaPluginProperties->setText('PDF');
+ $schemaPluginProperties->setExtension('pdf');
+ $schemaPluginProperties->setMimeType('application/pdf');
+
+ // create the root group that will be the options field for
+ // $schemaPluginProperties
+ // this will be shown as "Format specific options"
+ $exportSpecificOptions = new OptionsPropertyRootGroup();
+ $exportSpecificOptions->setName("Format Specific Options");
+
+ // specific options main group
+ $specificOptions = new OptionsPropertyMainGroup();
+ $specificOptions->setName("general_opts");
+ // add options common to all plugins
+ $this->addCommonOptions($specificOptions);
+
+ // create leaf items and add them to the group
+ $leaf = new BoolPropertyItem();
+ $leaf->setName('all_tables_same_width');
+ $leaf->setText(__('Same width for all tables'));
+ $specificOptions->addProperty($leaf);
+
+ $leaf = new SelectPropertyItem();
+ $leaf->setName("orientation");
+ $leaf->setText(__('Orientation'));
+ $leaf->setValues(
+ array(
+ 'L' => 'Landscape',
+ 'P' => 'Portrait',
+ )
+ );
+ $specificOptions->addProperty($leaf);
+
+ $leaf = new SelectPropertyItem();
+ $leaf->setName("paper");
+ $leaf->setText(__('Paper size'));
+ $leaf->setValues($this->_getPaperSizeArray());
+ $specificOptions->addProperty($leaf);
+
+ $leaf = new BoolPropertyItem();
+ $leaf->setName('show_grid');
+ $leaf->setText(__('Show grid'));
+ $specificOptions->addProperty($leaf);
+
+ $leaf = new BoolPropertyItem();
+ $leaf->setName('with_doc');
+ $leaf->setText(__('Data Dictionary'));
+ $specificOptions->addProperty($leaf);
+
+ // add the main group to the root group
+ $exportSpecificOptions->addProperty($specificOptions);
+
+ // set the options for the schema export plugin property item
+ $schemaPluginProperties->setOptions($exportSpecificOptions);
+ $this->properties = $schemaPluginProperties;
+ }
+
+ /**
+ * Returns the array of paper sizes
+ *
+ * @return array array of paper sizes
+ */
+ private function _getPaperSizeArray()
+ {
+ $ret = array();
+ foreach ($GLOBALS['cfg']['PDFPageSizes'] as $val) {
+ $ret[$val] = $val;
+ }
+ return $ret;
+ }
+
+ /**
+ * Exports the shcema into PDF format.
+ *
+ * @param string $db database name
+ *
+ * @return bool Whether it succeeded
+ */
+ public function exportSchema($db)
+ {
+ $export = new PMA_Pdf_Relation_Schema();
+ $export->showOutput();
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/plugins/schema/SchemaSvg.class.php b/libraries/plugins/schema/SchemaSvg.class.php
new file mode 100644
index 0000000000..c7a33d364c
--- /dev/null
+++ b/libraries/plugins/schema/SchemaSvg.class.php
@@ -0,0 +1,90 @@
+setProperties();
+ }
+
+ /**
+ * Sets the schema export SVG properties
+ *
+ * @return void
+ */
+ protected function setProperties()
+ {
+ $props = 'libraries/properties/';
+ include_once "$props/plugins/SchemaPluginProperties.class.php";
+ include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
+ include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
+ include_once "$props/options/items/BoolPropertyItem.class.php";
+
+ $schemaPluginProperties = new SchemaPluginProperties();
+ $schemaPluginProperties->setText('SVG');
+ $schemaPluginProperties->setExtension('svg');
+ $schemaPluginProperties->setMimeType('application/svg');
+
+ // create the root group that will be the options field for
+ // $schemaPluginProperties
+ // this will be shown as "Format specific options"
+ $exportSpecificOptions = new OptionsPropertyRootGroup();
+ $exportSpecificOptions->setName("Format Specific Options");
+
+ // specific options main group
+ $specificOptions = new OptionsPropertyMainGroup();
+ $specificOptions->setName("general_opts");
+ // add options common to all plugins
+ $this->addCommonOptions($specificOptions);
+
+ // create leaf items and add them to the group
+ $leaf = new BoolPropertyItem();
+ $leaf->setName('all_tables_same_width');
+ $leaf->setText(__('Same width for all tables'));
+ $specificOptions->addProperty($leaf);
+
+ // add the main group to the root group
+ $exportSpecificOptions->addProperty($specificOptions);
+
+ // set the options for the schema export plugin property item
+ $schemaPluginProperties->setOptions($exportSpecificOptions);
+ $this->properties = $schemaPluginProperties;
+ }
+
+ /**
+ * Exports the shcema into SVG format.
+ *
+ * @param string $db database name
+ *
+ * @return bool Whether it succeeded
+ */
+ public function exportSchema($db)
+ {
+ $export = new PMA_Svg_Relation_Schema();
+ $export->showOutput();
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/schema/TableStats.class.php b/libraries/plugins/schema/TableStats.class.php
similarity index 81%
rename from libraries/schema/TableStats.class.php
rename to libraries/plugins/schema/TableStats.class.php
index f9e6f1e06a..6b61693b7f 100644
--- a/libraries/schema/TableStats.class.php
+++ b/libraries/plugins/schema/TableStats.class.php
@@ -26,7 +26,7 @@ abstract class TableStats
protected $tableName;
protected $showKeys;
- protected $showInfo;
+ protected $tableDimension;
public $displayfield;
public $fields = array();
@@ -41,16 +41,18 @@ abstract class TableStats
/**
* Constructor
*
- * @param object $diagram schema diagram
- * @param string $db current db name
- * @param integer $pageNumber current page number (from the
- * $cfg['Servers'][$i]['table_coords'] table)
- * @param string $tableName table name
- * @param boolean $showKeys whether to display keys or not
- * @param boolean $showInfo whether to display table position or not
+ * @param object $diagram schema diagram
+ * @param string $db current db name
+ * @param integer $pageNumber current page number (from the
+ * $cfg['Servers'][$i]['table_coords'] table)
+ * @param string $tableName table name
+ * @param boolean $showKeys whether to display keys or not
+ * @param boolean $tableDimension whether to display table position or not
+ * @param boolean $offline whether the coordinates are sent
+ * from the browser
*/
public function __construct(
- $diagram, $db, $pageNumber, $tableName, $showKeys, $showInfo, $offline
+ $diagram, $db, $pageNumber, $tableName, $showKeys, $tableDimension, $offline
) {
$this->diagram = $diagram;
$this->db = $db;
@@ -58,7 +60,7 @@ abstract class TableStats
$this->tableName = $tableName;
$this->showKeys = $showKeys;
- $this->showInfo = $showInfo;
+ $this->tableDimension = $tableDimension;
$this->offline = $offline;
@@ -122,10 +124,10 @@ abstract class TableStats
{
global $cfgRelation;
- if ($this->offline){
- $tbl_coords = json_decode($GLOBALS['tbl_coords']);
+ if ($this->offline) {
+ $tbl_coords = json_decode($_REQUEST['tbl_coords']);
foreach ($tbl_coords as $tbl) {
- if( $this->tableName === $tbl->table_name){
+ if ($this->tableName === $tbl->table_name) {
$this->x = (double) $tbl->x;
$this->y = (double) $tbl->y;
break;
@@ -136,8 +138,8 @@ abstract class TableStats
. PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . "."
. PMA_Util::backquote($cfgRelation['table_coords'])
. " WHERE db_name = '" . PMA_Util::sqlAddSlashes($this->db) . "'"
- . " AND table_name = '" . PMA_Util::sqlAddSlashes($this->tableName) . "'"
- . " AND pdf_page_number = " . $this->pageNumber;
+ . " AND table_name = '" . PMA_Util::sqlAddSlashes($this->tableName) . "'"
+ . " AND pdf_page_number = " . $this->pageNumber;
$result = PMA_queryAsControlUser(
$sql, false, PMA_DatabaseInterface::QUERY_STORE
);
@@ -196,7 +198,7 @@ abstract class TableStats
*/
protected function getTitle()
{
- return ($this->showInfo
+ return ($this->tableDimension
? sprintf('%.0fx%0.f', $this->width, $this->heightCell)
: ''
)
diff --git a/libraries/plugins/schema/dia/Dia_Relation_Schema.class.php b/libraries/plugins/schema/dia/Dia_Relation_Schema.class.php
new file mode 100644
index 0000000000..7c26e44f18
--- /dev/null
+++ b/libraries/plugins/schema/dia/Dia_Relation_Schema.class.php
@@ -0,0 +1,383 @@
+openMemory();
+ /*
+ * Set indenting using three spaces,
+ * so output is formatted
+ */
+ $this->setIndent(true);
+ $this->setIndentString(' ');
+ /*
+ * Create the XML document
+ */
+ $this->startDocument('1.0', 'UTF-8');
+ }
+
+ /**
+ * Starts Dia Document
+ *
+ * dia document starts by first initializing dia:diagram tag
+ * then dia:diagramdata contains all the attributes that needed
+ * to define the document, then finally a Layer starts which
+ * holds all the objects.
+ *
+ * @param string $paper the size of the paper/document
+ * @param float $topMargin top margin of the paper/document in cm
+ * @param float $bottomMargin bottom margin of the paper/document in cm
+ * @param float $leftMargin left margin of the paper/document in cm
+ * @param float $rightMargin right margin of the paper/document in cm
+ * @param string $orientation orientation of the document, portrait or landscape
+ *
+ * @return void
+ *
+ * @access public
+ * @see XMLWriter::startElement(),XMLWriter::writeAttribute(),
+ * XMLWriter::writeRaw()
+ */
+ function startDiaDoc($paper, $topMargin, $bottomMargin, $leftMargin,
+ $rightMargin, $orientation
+ ) {
+ if ($orientation == 'P') {
+ $isPortrait = 'true';
+ } else {
+ $isPortrait = 'false';
+ }
+ $this->startElement('dia:diagram');
+ $this->writeAttribute('xmlns:dia', 'http://www.lysator.liu.se/~alla/dia/');
+ $this->startElement('dia:diagramdata');
+ $this->writeRaw(
+ '
+
+
+
+
+
+
+
+
+ #' . $paper . '#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ '
+ );
+ $this->endElement();
+ $this->startElement('dia:layer');
+ $this->writeAttribute('name', 'Background');
+ $this->writeAttribute('visible', 'true');
+ $this->writeAttribute('active', 'true');
+ }
+
+ /**
+ * Ends Dia Document
+ *
+ * @return void
+ * @access public
+ * @see XMLWriter::endElement(),XMLWriter::endDocument()
+ */
+ function endDiaDoc()
+ {
+ $this->endElement();
+ $this->endDocument();
+ }
+
+ /**
+ * Output Dia Document for download
+ *
+ * @param string $fileName name of the dia document
+ *
+ * @return void
+ * @access public
+ * @see XMLWriter::flush()
+ */
+ function showOutput($fileName)
+ {
+ if (ob_get_clean()) {
+ ob_end_clean();
+ }
+ $output = $this->flush();
+ PMA_Response::getInstance()->disable();
+ PMA_downloadHeader(
+ $fileName . '.dia', 'application/x-dia-diagram', strlen($output)
+ );
+ print $output;
+ }
+}
+
+/**
+ * Dia Relation Schema Class
+ *
+ * Purpose of this class is to generate the Dia XML Document
+ * which is used for representing the database diagrams in Dia IDE
+ * This class uses Database Table and Reference Objects of Dia and with
+ * the combination of these objects actually helps in preparing Dia XML.
+ *
+ * Dia XML is generated by using XMLWriter php extension and this class
+ * inherits Export_Relation_Schema class has common functionality added
+ * to this class
+ *
+ * @package PhpMyAdmin
+ * @name Dia_Relation_Schema
+ */
+class PMA_Dia_Relation_Schema extends PMA_Export_Relation_Schema
+{
+ /**
+ * Defines properties
+ */
+ private $_tables = array();
+ private $_relations = array();
+ private $_topMargin = 2.8222000598907471;
+ private $_bottomMargin = 2.8222000598907471;
+ private $_leftMargin = 2.8222000598907471;
+ private $_rightMargin = 2.8222000598907471;
+ public static $objectId = 0;
+
+ /**
+ * The "PMA_Dia_Relation_Schema" constructor
+ *
+ * Upon instantiation This outputs the Dia XML document
+ * that user can download
+ *
+ * @see PMA_DIA,Table_Stats_Dia,Relation_Stats_Dia
+ */
+ function __construct()
+ {
+ parent::__construct();
+
+ global $dia, $db;
+
+ $this->setShowColor(isset($_REQUEST['dia_show_color']));
+ $this->setShowKeys(isset($_REQUEST['dia_show_keys']));
+ $this->setOrientation($_REQUEST['dia_orientation']);
+ $this->setPaper($_REQUEST['dia_paper']);
+
+ $dia = new PMA_DIA();
+ $dia->startDiaDoc(
+ $this->paper, $this->_topMargin, $this->_bottomMargin,
+ $this->_leftMargin, $this->_rightMargin, $this->orientation
+ );
+
+ if ($this->isOffline()) {
+ $alltables = array();
+ $tbl_coords = json_decode($_REQUEST['tbl_coords']);
+ foreach ($tbl_coords as $tbl) {
+ $alltables[] = $tbl->table_name;
+ }
+ } else {
+ $alltables = $this->getAllTables($db, $this->pageNumber);
+ }
+
+ foreach ($alltables as $table) {
+ if (! isset($this->tables[$table])) {
+ $this->_tables[$table] = new Table_Stats_Dia(
+ $table, $this->pageNumber, $this->showKeys, $this->isOffline()
+ );
+ }
+ }
+
+ $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 ($master_field != 'foreign_keys_data') {
+ if (in_array($rel['foreign_table'], $alltables)) {
+ $this->_addRelation(
+ $one_table, $master_field, $rel['foreign_table'],
+ $rel['foreign_field'], $this->showKeys
+ );
+ }
+ } else {
+ foreach ($rel as $key => $one_key) {
+ if (in_array($one_key['ref_table_name'], $alltables)) {
+ foreach ($one_key['index_list'] as $index => $one_field) {
+ $this->_addRelation(
+ $one_table, $one_field, $one_key['ref_table_name'],
+ $one_key['ref_index_list'][$index], $this->showKeys
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ $this->_drawTables();
+
+ if ($seen_a_relation) {
+ $this->_drawRelations();
+ }
+ $dia->endDiaDoc();
+ }
+
+ /**
+ * Output Dia Document for download
+ *
+ * @return void
+ * @access public
+ */
+ function showOutput()
+ {
+ global $dia, $db;
+ $filename = $db . '-' . $this->pageNumber;
+ if ($this->isOffline()) {
+ $filename = __("Dia export page");
+ }
+ $dia->showOutput($filename);
+ }
+
+ /**
+ * Defines relation objects
+ *
+ * @param string $masterTable The master table name
+ * @param string $masterField The relation field in the master table
+ * @param string $foreignTable The foreign table name
+ * @param string $foreignField The relation field in the foreign table
+ * @param bool $showKeys Whether to display ONLY keys or not
+ *
+ * @return void
+ *
+ * @access private
+ * @see Table_Stats_Dia::__construct(),Relation_Stats_Dia::__construct()
+ */
+ private function _addRelation($masterTable, $masterField, $foreignTable,
+ $foreignField, $showKeys
+ ) {
+ if (! isset($this->_tables[$masterTable])) {
+ $this->_tables[$masterTable] = new Table_Stats_Dia(
+ $masterTable, $this->pageNumber, $showKeys
+ );
+ }
+ if (! isset($this->_tables[$foreignTable])) {
+ $this->_tables[$foreignTable] = new Table_Stats_Dia(
+ $foreignTable, $this->pageNumber, $showKeys
+ );
+ }
+ $this->_relations[] = new Relation_Stats_Dia(
+ $this->_tables[$masterTable], $masterField,
+ $this->_tables[$foreignTable], $foreignField
+ );
+ }
+
+ /**
+ * Draws relation references
+ *
+ * connects master table's master field to
+ * foreign table's forein field using Dia object
+ * type Database - Reference
+ *
+ * @return void
+ *
+ * @access private
+ * @see Relation_Stats_Dia::relationDraw()
+ */
+ private function _drawRelations()
+ {
+ foreach ($this->_relations as $relation) {
+ $relation->relationDraw($this->showColor);
+ }
+ }
+
+ /**
+ * Draws tables
+ *
+ * Tables are generated using Dia object type Database - Table
+ * primary fields are underlined and bold in tables
+ *
+ * @return void
+ *
+ * @access private
+ * @see Table_Stats_Dia::tableDraw()
+ */
+ private function _drawTables()
+ {
+ foreach ($this->_tables as $table) {
+ $table->tableDraw($this->showColor);
+ }
+ }
+}
+?>
diff --git a/libraries/plugins/schema/dia/RelationStatsDia.class.php b/libraries/plugins/schema/dia/RelationStatsDia.class.php
new file mode 100644
index 0000000000..772257ed7f
--- /dev/null
+++ b/libraries/plugins/schema/dia/RelationStatsDia.class.php
@@ -0,0 +1,218 @@
+_getXy($master_table, $master_field);
+ $dest_pos = $this->_getXy($foreign_table, $foreign_field);
+ $this->srcConnPointsLeft = $src_pos[0];
+ $this->srcConnPointsRight = $src_pos[1];
+ $this->destConnPointsLeft = $dest_pos[0];
+ $this->destConnPointsRight = $dest_pos[1];
+ $this->masterTablePos = $src_pos[2];
+ $this->foreignTablePos = $dest_pos[2];
+ $this->masterTableId = $master_table->tableId;
+ $this->foreignTableId = $foreign_table->tableId;
+ }
+
+ /**
+ * Each Table object have connection points
+ * which is used to connect to other objects in Dia
+ * we detect the position of key in fields and
+ * then determines its left and right connection
+ * points.
+ *
+ * @param string $table The current table name
+ * @param string $column The relation column name
+ *
+ * @return array Table right,left connection points and key position
+ *
+ * @access private
+ */
+ private function _getXy($table, $column)
+ {
+ $pos = array_search($column, $table->fields);
+ // left, right, position
+ $value = 12;
+ if ($pos != 0) {
+ return array($pos + $value + $pos, $pos + $value + $pos + 1, $pos);
+ }
+ return array($pos + $value , $pos + $value + 1, $pos);
+ }
+
+ /**
+ * Draws relation references
+ *
+ * connects master table's master field to foreign table's
+ * forein field using Dia object type Database - Reference
+ * Dia object is used to generate the XML of Dia Document.
+ * Database reference Object and their attributes are involved
+ * in the combination of displaing Database - reference on Dia Document.
+ *
+ * @param boolean $showColor Whether to use one color per relation or not
+ * if showColor is true then an array of $listOfColors will be used to choose
+ * the random colors for references lines. we can change/add more colors to this
+ *
+ * @return boolean|void
+ *
+ * @global object $dia The current Dia document
+ *
+ * @access public
+ * @see PMA_PDF
+ */
+ public function relationDraw($showColor)
+ {
+ global $dia;
+
+ PMA_Dia_Relation_Schema::$objectId += 1;
+ /*
+ * if source connection points and destination connection
+ * points are same then return it false and don't draw that
+ * relation
+ */
+ if ( $this->srcConnPointsRight == $this->destConnPointsRight) {
+ if ( $this->srcConnPointsLeft == $this->destConnPointsLeft) {
+ return false;
+ }
+ }
+
+ if ($showColor) {
+ $listOfColors = array(
+ 'FF0000',
+ '000099',
+ '00FF00'
+ );
+ shuffle($listOfColors);
+ $this->referenceColor = '#' . $listOfColors[0] . '';
+ } else {
+ $this->referenceColor = '#000000';
+ }
+
+ $dia->writeRaw(
+ '
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #1#
+
+
+ #n#
+
+
+
+
+
+
+
+
+
+
+
+ '
+ );
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/plugins/schema/dia/TableStatsDia.class.php b/libraries/plugins/schema/dia/TableStatsDia.class.php
new file mode 100644
index 0000000000..710752d0ff
--- /dev/null
+++ b/libraries/plugins/schema/dia/TableStatsDia.class.php
@@ -0,0 +1,247 @@
+tableId = PMA_Dia_Relation_Schema::$objectId;
+ }
+
+ /**
+ * Displays an error when the table cannot be found.
+ *
+ * @return void
+ */
+ protected function showMissingTableError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "DIA",
+ sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
+ );
+ }
+
+ /**
+ * Displays an error on missing coordinates
+ *
+ * @return void
+ */
+ protected function showMissingCoordinatesError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "DIA",
+ sprintf(
+ __('Please configure the coordinates for table %s'),
+ $this->tableName
+ )
+ );
+ }
+
+
+ /**
+ * Do draw the table
+ *
+ * Tables are generated using object type Database - Table
+ * primary fields are underlined in tables. Dia object
+ * is used to generate the XML of Dia Document. Database Table
+ * Object and their attributes are involved in the combination
+ * of displaing Database - Table on Dia Document.
+ *
+ * @param boolean $showColor Whether to show color for tables text or not
+ * if showColor is true then an array of $listOfColors will be used to choose
+ * the random colors for tables text we can change/add more colors to this array
+ *
+ * @return void
+ *
+ * @global object $dia The current Dia document
+ *
+ * @access public
+ * @see PMA_DIA
+ */
+ public function tableDraw($showColor)
+ {
+ global $dia;
+
+ if ($showColor) {
+ $listOfColors = array(
+ 'FF0000',
+ '000099',
+ '00FF00'
+ );
+ shuffle($listOfColors);
+ $this->tableColor = '#' . $listOfColors[0] . '';
+ } else {
+ $this->tableColor = '#000000';
+ }
+
+ $factor = 0.1;
+
+ $dia->startElement('dia:object');
+ $dia->writeAttribute('type', 'Database - Table');
+ $dia->writeAttribute('version', '0');
+ $dia->writeAttribute('id', '' . $this->tableId . '');
+ $dia->writeRaw(
+ '
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #' . $this->tableName . '#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ '
+ );
+
+ $dia->startElement('dia:attribute');
+ $dia->writeAttribute('name', 'attributes');
+
+ foreach ($this->fields as $field) {
+ $dia->writeRaw(
+ '
+
+ #' . $field . '#
+
+
+ ##
+
+
+ ##
+ '
+ );
+ unset($pm);
+ $pm = 'false';
+ if (in_array($field, $this->primary)) {
+ $pm = 'true';
+ }
+ if ($field == $this->displayfield) {
+ $pm = 'false';
+ }
+ $dia->writeRaw(
+ '
+
+
+
+
+
+
+
+
+ '
+ );
+ }
+ $dia->endElement();
+ $dia->endElement();
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/schema/Eps_Relation_Schema.class.php b/libraries/plugins/schema/eps/Eps_Relation_Schema.class.php
similarity index 51%
rename from libraries/schema/Eps_Relation_Schema.class.php
rename to libraries/plugins/schema/eps/Eps_Relation_Schema.class.php
index aea5607cde..699c94dab2 100644
--- a/libraries/schema/Eps_Relation_Schema.class.php
+++ b/libraries/plugins/schema/eps/Eps_Relation_Schema.class.php
@@ -9,7 +9,9 @@ if (! defined('PHPMYADMIN')) {
exit;
}
-require_once 'Export_Relation_Schema.class.php';
+require_once 'libraries/plugins/schema/Export_Relation_Schema.class.php';
+require_once 'libraries/plugins/schema/eps/RelationStatsEps.class.php';
+require_once 'libraries/plugins/schema/eps/TableStatsEps.class.php';
require_once 'libraries/Font.class.php';
/**
@@ -89,21 +91,21 @@ class PMA_EPS
/**
* Set document orientation
*
- * @param string $value sets the author
+ * @param string $orientation sets the orientation
*
* @return void
*
* @access public
*/
- function setOrientation($value)
+ function setOrientation($orientation)
{
$this->stringCommands .= "%%PageOrder: Ascend \n";
- if ($value == "L") {
- $value = "Landscape";
- $this->stringCommands .= '%%Orientation: ' . $value . "\n";
+ if ($orientation == "L") {
+ $orientation = "Landscape";
+ $this->stringCommands .= '%%Orientation: ' . $orientation . "\n";
} else {
- $value = "Portrait";
- $this->stringCommands .= '%%Orientation: ' . $value . "\n";
+ $orientation = "Portrait";
+ $this->stringCommands .= '%%Orientation: ' . $orientation . "\n";
}
$this->stringCommands .= "%%EndComments \n";
$this->stringCommands .= "%%Pages 1 \n";
@@ -297,372 +299,6 @@ class PMA_EPS
}
}
-require_once './libraries/schema/TableStats.class.php';
-
-/**
- * Table preferences/statistics
- *
- * This class preserves the table co-ordinates,fields
- * and helps in drawing/generating the Tables in EPS.
- *
- * @package PhpMyAdmin
- * @name Table_Stats_Eps
- * @see PMA_EPS
- */
-class Table_Stats_Eps extends TableStats
-{
- /**
- * Defines properties
- */
- public $height;
- public $currentCell = 0;
-
- /**
- * The "Table_Stats_Eps" constructor
- *
- * @param string $tableName The table name
- * @param string $font The font name
- * @param integer $fontSize The font size
- * @param integer $pageNumber Page number
- * @param integer &$same_wide_width The max width among tables
- * @param boolean $showKeys Whether to display keys or not
- * @param boolean $showInfo Whether to display table position or not
- *
- * @global object $eps The current eps document
- * @global integer The current page number (from the
- * $cfg['Servers'][$i]['table_coords'] table)
- * @global array $cfgRelation The relations settings
- * @global string $db The current db name
- *
- * @access private
- * @see PMA_EPS, Table_Stats_Eps::Table_Stats_setWidth,
- * Table_Stats_Eps::Table_Stats_setHeight
- */
- function __construct(
- $tableName, $font, $fontSize, $pageNumber, &$same_wide_width,
- $showKeys = false, $showInfo = false, $offline = false
- ) {
- global $eps, $cfgRelation, $db;
- parent::__construct(
- $eps, $db, $pageNumber, $tableName, $showKeys, $showInfo, $offline
- );
-
- // 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;
- }
- }
-
- /**
- * Displays an error when the table cannot be found.
- *
- * @return void
- */
- protected function showMissingTableError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "EPS",
- sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
- );
- }
-
- /**
- * Displays an error on missing coordinates
- *
- * @return void
- */
- protected function showMissingCoordinatesError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "EPS",
- sprintf(
- __('Please configure the coordinates for table %s'),
- $this->tableName
- )
- );
- }
-
- /**
- * Sets the width of the table
- *
- * @param string $font The font name
- * @param integer $fontSize The font size
- *
- * @global object $eps The current eps document
- *
- * @return void
- *
- * @access private
- * @see PMA_EPS
- */
- private function _setWidthTable($font,$fontSize)
- {
- foreach ($this->fields as $field) {
- $this->width = max(
- $this->width,
- PMA_Font::getStringWidth($field, $font, $fontSize)
- );
- }
- $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
- /*
- * it is unknown what value must be added, because
- * table title is affected by the tabe width value
- */
- while ($this->width
- < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)) {
- $this->width += 7;
- }
- }
-
- /**
- * Sets the height of the table
- *
- * @param integer $fontSize The font size
- *
- * @return void
- * @access private
- */
- private function _setHeightTable($fontSize)
- {
- $this->heightCell = $fontSize + 4;
- $this->height = (count($this->fields) + 1) * $this->heightCell;
- }
-
- /**
- * Draw the table
- *
- * @param boolean $showColor Whether to display color
- *
- * @global object $eps The current eps document
- *
- * @return void
- *
- * @access public
- * @see PMA_EPS,PMA_EPS::line,PMA_EPS::rect
- */
- public function tableDraw($showColor)
- {
- global $eps;
- //echo $this->tableName.'
';
- $eps->rect($this->x, $this->y + 12, $this->width, $this->heightCell, 1);
- $eps->showXY($this->getTitle(), $this->x + 5, $this->y + 14);
- foreach ($this->fields as $field) {
- $this->currentCell += $this->heightCell;
- $showColor = 'none';
- if ($showColor) {
- if (in_array($field, $this->primary)) {
- $showColor = '#0c0';
- }
- if ($field == $this->displayfield) {
- $showColor = 'none';
- }
- }
- $eps->rect(
- $this->x, $this->y + 12 + $this->currentCell,
- $this->width, $this->heightCell, 1
- );
- $eps->showXY($field, $this->x + 5, $this->y + 14 + $this->currentCell);
- }
- }
-}
-
-/**
- * Relation preferences/statistics
- *
- * This class fetches the table master and foreign fields positions
- * and helps in generating the Table references and then connects
- * master table's master field to foreign table's foreign key
- * in EPS document.
- *
- * @package PhpMyAdmin
- * @name Relation_Stats_Eps
- * @see PMA_EPS
- */
-class Relation_Stats_Eps
-{
- /**
- * Defines properties
- */
- public $xSrc, $ySrc;
- public $srcDir ;
- public $destDir;
- public $xDest, $yDest;
- public $wTick = 10;
-
- /**
- * The "Relation_Stats_Eps" constructor
- *
- * @param string $master_table The master table name
- * @param string $master_field The relation field in the master table
- * @param string $foreign_table The foreign table name
- * @param string $foreign_field The relation field in the foreign table
- *
- * @see Relation_Stats_Eps::_getXy
- */
- function __construct(
- $master_table, $master_field, $foreign_table, $foreign_field
- ) {
- $src_pos = $this->_getXy($master_table, $master_field);
- $dest_pos = $this->_getXy($foreign_table, $foreign_field);
- /*
- * [0] is x-left
- * [1] is x-right
- * [2] is y
- */
- $src_left = $src_pos[0] - $this->wTick;
- $src_right = $src_pos[1] + $this->wTick;
- $dest_left = $dest_pos[0] - $this->wTick;
- $dest_right = $dest_pos[1] + $this->wTick;
-
- $d1 = abs($src_left - $dest_left);
- $d2 = abs($src_right - $dest_left);
- $d3 = abs($src_left - $dest_right);
- $d4 = abs($src_right - $dest_right);
- $d = min($d1, $d2, $d3, $d4);
-
- if ($d == $d1) {
- $this->xSrc = $src_pos[0];
- $this->srcDir = -1;
- $this->xDest = $dest_pos[0];
- $this->destDir = -1;
- } elseif ($d == $d2) {
- $this->xSrc = $src_pos[1];
- $this->srcDir = 1;
- $this->xDest = $dest_pos[0];
- $this->destDir = -1;
- } elseif ($d == $d3) {
- $this->xSrc = $src_pos[0];
- $this->srcDir = -1;
- $this->xDest = $dest_pos[1];
- $this->destDir = 1;
- } else {
- $this->xSrc = $src_pos[1];
- $this->srcDir = 1;
- $this->xDest = $dest_pos[1];
- $this->destDir = 1;
- }
- $this->ySrc = $src_pos[2] + 10;
- $this->yDest = $dest_pos[2] + 10;
- }
-
- /**
- * Gets arrows coordinates
- *
- * @param string $table The current table name
- * @param string $column The relation column name
- *
- * @return array Arrows coordinates
- *
- * @access private
- */
- private function _getXy($table, $column)
- {
- $pos = array_search($column, $table->fields);
- // x_left, x_right, y
- return array(
- $table->x,
- $table->x + $table->width,
- $table->y + ($pos + 1.5) * $table->heightCell
- );
- }
-
- /**
- * draws relation links and arrows
- * shows foreign key relations
- *
- * @param boolean $changeColor Whether to use one color per relation or not
- *
- * @global object $eps The current EPS document
- *
- * @access public
- * @see PMA_EPS
- *
- * @return void
- */
- public function relationDraw($changeColor)
- {
- global $eps;
-
- if ($changeColor) {
- $listOfColors = array(
- 'red',
- 'grey',
- 'black',
- 'yellow',
- 'green',
- 'cyan',
- ' orange'
- );
- shuffle($listOfColors);
- $color = $listOfColors[0];
- } else {
- $color = 'black';
- }
- // draw a line like -- to foreign field
- $eps->line(
- $this->xSrc,
- $this->ySrc,
- $this->xSrc + $this->srcDir * $this->wTick,
- $this->ySrc,
- 1
- );
- // draw a line like -- to master field
- $eps->line(
- $this->xDest + $this->destDir * $this->wTick,
- $this->yDest,
- $this->xDest,
- $this->yDest,
- 1
- );
- // draw a line that connects to master field line and foreign field line
- $eps->line(
- $this->xSrc + $this->srcDir * $this->wTick,
- $this->ySrc,
- $this->xDest + $this->destDir * $this->wTick,
- $this->yDest,
- 1
- );
- $root2 = 2 * sqrt(2);
- $eps->line(
- $this->xSrc + $this->srcDir * $this->wTick * 0.75,
- $this->ySrc,
- $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
- $this->ySrc + $this->wTick / $root2,
- 1
- );
- $eps->line(
- $this->xSrc + $this->srcDir * $this->wTick * 0.75,
- $this->ySrc,
- $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
- $this->ySrc - $this->wTick / $root2,
- 1
- );
- $eps->line(
- $this->xDest + $this->destDir * $this->wTick / 2,
- $this->yDest,
- $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
- $this->yDest + $this->wTick / $root2,
- 1
- );
- $eps->line(
- $this->xDest + $this->destDir * $this->wTick / 2,
- $this->yDest,
- $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
- $this->yDest - $this->wTick / $root2,
- 1
- );
- }
-}
-/*
-* end of the "Relation_Stats_Eps" class
-*/
-
/**
* EPS Relation Schema Class
*
@@ -692,16 +328,15 @@ class PMA_Eps_Relation_Schema extends PMA_Export_Relation_Schema
*/
function __construct()
{
+ parent::__construct();
+
global $eps,$db;
- $this->setPageNumber($_POST['pdf_page_number']);
- $this->setShowColor($_POST['show_color']);
- $this->setShowKeys($_POST['show_keys']);
- $this->setTableDimension($_POST['show_table_dimension']);
- $this->setAllTablesSameWidth($_POST['all_tables_same_width']);
- $this->setOrientation($_POST['orientation']);
- $this->setExportType($_POST['export_type']);
- $this->setOffline($_POST['offline_export']);
+ $this->setShowColor(isset($_REQUEST['eps_show_color']));
+ $this->setShowKeys(isset($_REQUEST['eps_show_keys']));
+ $this->setTableDimension(isset($_REQUEST['eps_show_table_dimension']));
+ $this->setAllTablesSameWidth(isset($_REQUEST['eps_all_tables_same_width']));
+ $this->setOrientation($_REQUEST['eps_orientation']);
$eps = new PMA_EPS();
$eps->setTitle(
@@ -718,7 +353,7 @@ class PMA_Eps_Relation_Schema extends PMA_Export_Relation_Schema
if ($this->isOffline()) {
$alltables = array();
- $tbl_coords = json_decode($GLOBALS['tbl_coords']);
+ $tbl_coords = json_decode($_REQUEST['tbl_coords']);
foreach ($tbl_coords as $tbl) {
$alltables[] = $tbl->table_name;
}
@@ -780,10 +415,10 @@ class PMA_Eps_Relation_Schema extends PMA_Export_Relation_Schema
}
}
if ($seen_a_relation) {
- $this->_drawRelations($this->showColor);
+ $this->_drawRelations();
}
- $this->_drawTables($this->showColor);
+ $this->_drawTables();
$eps->endEpsDoc();
}
@@ -806,13 +441,13 @@ class PMA_Eps_Relation_Schema extends PMA_Export_Relation_Schema
/**
* Defines relation objects
*
- * @param string $masterTable The master table name
- * @param string $font The font
- * @param int $fontSize The font size
- * @param string $masterField The relation field in the master table
- * @param string $foreignTable The foreign table name
- * @param string $foreignField The relation field in the foreign table
- * @param boolean $showInfo Whether to display table position or not
+ * @param string $masterTable The master table name
+ * @param string $font The font
+ * @param int $fontSize The font size
+ * @param string $masterField The relation field in the master table
+ * @param string $foreignTable The foreign table name
+ * @param string $foreignField The relation field in the foreign table
+ * @param boolean $tableDimension Whether to display table position or not
*
* @return void
*
@@ -822,18 +457,18 @@ class PMA_Eps_Relation_Schema extends PMA_Export_Relation_Schema
*/
private function _addRelation(
$masterTable, $font, $fontSize, $masterField,
- $foreignTable, $foreignField, $showInfo
+ $foreignTable, $foreignField, $tableDimension
) {
if (! isset($this->_tables[$masterTable])) {
$this->_tables[$masterTable] = new Table_Stats_Eps(
$masterTable, $font, $fontSize, $this->pageNumber,
- $this->_tablewidth, false, $showInfo
+ $this->_tablewidth, false, $tableDimension
);
}
if (! isset($this->_tables[$foreignTable])) {
$this->_tables[$foreignTable] = new Table_Stats_Eps(
$foreignTable, $font, $fontSize, $this->pageNumber,
- $this->_tablewidth, false, $showInfo
+ $this->_tablewidth, false, $tableDimension
);
}
$this->_relations[] = new Relation_Stats_Eps(
@@ -846,34 +481,30 @@ class PMA_Eps_Relation_Schema extends PMA_Export_Relation_Schema
* Draws relation arrows and lines connects master table's master field to
* foreign table's forein field
*
- * @param boolean $changeColor Whether to use one color per relation or not
- *
* @return void
*
* @access private
* @see Relation_Stats_Eps::relationDraw()
*/
- private function _drawRelations($changeColor)
+ private function _drawRelations()
{
foreach ($this->_relations as $relation) {
- $relation->relationDraw($changeColor);
+ $relation->relationDraw($this->showColor);
}
}
/**
* Draws tables
*
- * @param boolean $changeColor Whether to show color for primary fields or not
- *
* @return void
*
* @access private
* @see Table_Stats_Eps::Table_Stats_tableDraw()
*/
- private function _drawTables($changeColor)
+ private function _drawTables()
{
foreach ($this->_tables as $table) {
- $table->tableDraw($changeColor);
+ $table->tableDraw($this->showColor);
}
}
}
diff --git a/libraries/plugins/schema/eps/RelationStatsEps.class.php b/libraries/plugins/schema/eps/RelationStatsEps.class.php
new file mode 100644
index 0000000000..65ff70f8d2
--- /dev/null
+++ b/libraries/plugins/schema/eps/RelationStatsEps.class.php
@@ -0,0 +1,201 @@
+_getXy($master_table, $master_field);
+ $dest_pos = $this->_getXy($foreign_table, $foreign_field);
+ /*
+ * [0] is x-left
+ * [1] is x-right
+ * [2] is y
+ */
+ $src_left = $src_pos[0] - $this->wTick;
+ $src_right = $src_pos[1] + $this->wTick;
+ $dest_left = $dest_pos[0] - $this->wTick;
+ $dest_right = $dest_pos[1] + $this->wTick;
+
+ $d1 = abs($src_left - $dest_left);
+ $d2 = abs($src_right - $dest_left);
+ $d3 = abs($src_left - $dest_right);
+ $d4 = abs($src_right - $dest_right);
+ $d = min($d1, $d2, $d3, $d4);
+
+ if ($d == $d1) {
+ $this->xSrc = $src_pos[0];
+ $this->srcDir = -1;
+ $this->xDest = $dest_pos[0];
+ $this->destDir = -1;
+ } elseif ($d == $d2) {
+ $this->xSrc = $src_pos[1];
+ $this->srcDir = 1;
+ $this->xDest = $dest_pos[0];
+ $this->destDir = -1;
+ } elseif ($d == $d3) {
+ $this->xSrc = $src_pos[0];
+ $this->srcDir = -1;
+ $this->xDest = $dest_pos[1];
+ $this->destDir = 1;
+ } else {
+ $this->xSrc = $src_pos[1];
+ $this->srcDir = 1;
+ $this->xDest = $dest_pos[1];
+ $this->destDir = 1;
+ }
+ $this->ySrc = $src_pos[2] + 10;
+ $this->yDest = $dest_pos[2] + 10;
+ }
+
+ /**
+ * Gets arrows coordinates
+ *
+ * @param string $table The current table name
+ * @param string $column The relation column name
+ *
+ * @return array Arrows coordinates
+ *
+ * @access private
+ */
+ private function _getXy($table, $column)
+ {
+ $pos = array_search($column, $table->fields);
+ // x_left, x_right, y
+ return array(
+ $table->x,
+ $table->x + $table->width,
+ $table->y + ($pos + 1.5) * $table->heightCell
+ );
+ }
+
+ /**
+ * draws relation links and arrows
+ * shows foreign key relations
+ *
+ * @param boolean $showColor Whether to use one color per relation or not
+ *
+ * @global object $eps The current EPS document
+ *
+ * @access public
+ * @see PMA_EPS
+ *
+ * @return void
+ */
+ public function relationDraw($showColor)
+ {
+ global $eps;
+
+ if ($showColor) {
+ $listOfColors = array(
+ 'red',
+ 'grey',
+ 'black',
+ 'yellow',
+ 'green',
+ 'cyan',
+ 'orange'
+ );
+ shuffle($listOfColors);
+ $color = $listOfColors[0];
+ } else {
+ $color = 'black';
+ }
+ // draw a line like -- to foreign field
+ $eps->line(
+ $this->xSrc,
+ $this->ySrc,
+ $this->xSrc + $this->srcDir * $this->wTick,
+ $this->ySrc,
+ 1
+ );
+ // draw a line like -- to master field
+ $eps->line(
+ $this->xDest + $this->destDir * $this->wTick,
+ $this->yDest,
+ $this->xDest,
+ $this->yDest,
+ 1
+ );
+ // draw a line that connects to master field line and foreign field line
+ $eps->line(
+ $this->xSrc + $this->srcDir * $this->wTick,
+ $this->ySrc,
+ $this->xDest + $this->destDir * $this->wTick,
+ $this->yDest,
+ 1
+ );
+ $root2 = 2 * sqrt(2);
+ $eps->line(
+ $this->xSrc + $this->srcDir * $this->wTick * 0.75,
+ $this->ySrc,
+ $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
+ $this->ySrc + $this->wTick / $root2,
+ 1
+ );
+ $eps->line(
+ $this->xSrc + $this->srcDir * $this->wTick * 0.75,
+ $this->ySrc,
+ $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
+ $this->ySrc - $this->wTick / $root2,
+ 1
+ );
+ $eps->line(
+ $this->xDest + $this->destDir * $this->wTick / 2,
+ $this->yDest,
+ $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
+ $this->yDest + $this->wTick / $root2,
+ 1
+ );
+ $eps->line(
+ $this->xDest + $this->destDir * $this->wTick / 2,
+ $this->yDest,
+ $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
+ $this->yDest - $this->wTick / $root2,
+ 1
+ );
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/plugins/schema/eps/TableStatsEps.class.php b/libraries/plugins/schema/eps/TableStatsEps.class.php
new file mode 100644
index 0000000000..aacd5f7f4c
--- /dev/null
+++ b/libraries/plugins/schema/eps/TableStatsEps.class.php
@@ -0,0 +1,179 @@
+_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;
+ }
+ }
+
+ /**
+ * Displays an error when the table cannot be found.
+ *
+ * @return void
+ */
+ protected function showMissingTableError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "EPS",
+ sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
+ );
+ }
+
+ /**
+ * Displays an error on missing coordinates
+ *
+ * @return void
+ */
+ protected function showMissingCoordinatesError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "EPS",
+ sprintf(
+ __('Please configure the coordinates for table %s'),
+ $this->tableName
+ )
+ );
+ }
+
+ /**
+ * Sets the width of the table
+ *
+ * @param string $font The font name
+ * @param integer $fontSize The font size
+ *
+ * @global object $eps The current eps document
+ *
+ * @return void
+ *
+ * @access private
+ * @see PMA_EPS
+ */
+ private function _setWidthTable($font,$fontSize)
+ {
+ foreach ($this->fields as $field) {
+ $this->width = max(
+ $this->width,
+ PMA_Font::getStringWidth($field, $font, $fontSize)
+ );
+ }
+ $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
+ /*
+ * it is unknown what value must be added, because
+ * table title is affected by the tabe width value
+ */
+ while ($this->width
+ < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)) {
+ $this->width += 7;
+ }
+ }
+
+ /**
+ * Sets the height of the table
+ *
+ * @param integer $fontSize The font size
+ *
+ * @return void
+ * @access private
+ */
+ private function _setHeightTable($fontSize)
+ {
+ $this->heightCell = $fontSize + 4;
+ $this->height = (count($this->fields) + 1) * $this->heightCell;
+ }
+
+ /**
+ * Draw the table
+ *
+ * @param boolean $showColor Whether to display color
+ *
+ * @global object $eps The current eps document
+ *
+ * @return void
+ *
+ * @access public
+ * @see PMA_EPS,PMA_EPS::line,PMA_EPS::rect
+ */
+ public function tableDraw($showColor)
+ {
+ global $eps;
+ //echo $this->tableName.'
';
+ $eps->rect($this->x, $this->y + 12, $this->width, $this->heightCell, 1);
+ $eps->showXY($this->getTitle(), $this->x + 5, $this->y + 14);
+ foreach ($this->fields as $field) {
+ $this->currentCell += $this->heightCell;
+ $eps->rect(
+ $this->x, $this->y + 12 + $this->currentCell,
+ $this->width, $this->heightCell, 1
+ );
+ $eps->showXY($field, $this->x + 5, $this->y + 14 + $this->currentCell);
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/schema/Pdf_Relation_Schema.class.php b/libraries/plugins/schema/pdf/Pdf_Relation_Schema.class.php
similarity index 69%
rename from libraries/schema/Pdf_Relation_Schema.class.php
rename to libraries/plugins/schema/pdf/Pdf_Relation_Schema.class.php
index 04f34013ad..c771a1b00a 100644
--- a/libraries/schema/Pdf_Relation_Schema.class.php
+++ b/libraries/plugins/schema/pdf/Pdf_Relation_Schema.class.php
@@ -24,8 +24,10 @@ if (getcwd() == dirname(__FILE__)) {
die('Attack stopped');
}
-require_once 'Export_Relation_Schema.class.php';
-require_once './libraries/PDF.class.php';
+require_once 'libraries/plugins/schema/Export_Relation_Schema.class.php';
+require_once 'libraries/plugins/schema/pdf/RelationStatsPdf.class.php';
+require_once 'libraries/plugins/schema/pdf/TableStatsPdf.class.php';
+require_once 'libraries/PDF.class.php';
/**
* Extends the "TCPDF" class and helps
@@ -50,7 +52,25 @@ class PMA_Schema_PDF extends PMA_PDF
var $def_outlines;
var $widths;
private $_ff = PMA_PDF_FONT;
- private $offline;
+ private $_offline;
+ private $_exportingPage;
+
+ /**
+ * Constructs PDF for schema export.
+ *
+ * @param string $orientation page orientation
+ * @param string $unit unit
+ * @param string $format the format used for pages
+ * @param int $exportingPage schema page number that is being exported
+ *
+ * @access public
+ */
+ public function __construct(
+ $orientation, $unit, $format, $exportingPage
+ ) {
+ parent::__construct($orientation, $unit, $format);
+ $this->_exportingPage = $exportingPage;
+ }
/**
* Sets the value for margins
@@ -223,16 +243,16 @@ class PMA_Schema_PDF extends PMA_PDF
// We only show this if we find something in the new pdf_pages table
// This function must be named "Header" to work with the TCPDF library
- global $cfgRelation, $db, $pdf_page_number, $with_doc;
- if ($with_doc) {
- if ($this->offline) {
+ global $cfgRelation, $db, $pdf_with_doc;
+ if ($pdf_with_doc) {
+ if ($this->_offline) {
$pg_name = __("PDF export page");
} else {
$test_query = 'SELECT * FROM '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
- . PMA_Util::backquote($cfgRelation['pdf_pages'])
+ . PMA_Util::backquote($GLOBALS['cfgRelation']['pdf_pages'])
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
- . ' AND page_nr = \'' . $pdf_page_number . '\'';
+ . ' AND page_nr = \'' . $this->_exportingPage . '\'';
$test_rs = PMA_queryAsControlUser($test_query);
$pages = @$GLOBALS['dbi']->fetchAssoc($test_rs);
$pg_name = ucfirst($pages['page_descr']);
@@ -254,8 +274,8 @@ class PMA_Schema_PDF extends PMA_PDF
*/
function Footer()
{
- global $with_doc;
- if ($with_doc) {
+ global $pdf_with_doc;
+ if ($pdf_with_doc) {
parent::Footer();
}
}
@@ -372,435 +392,18 @@ class PMA_Schema_PDF extends PMA_PDF
return $nl;
}
- /**
- * Set whether the document is generated from client side DB
- *
- * @param string $value 'on' if offline
- *
- * @return void
- *
- * @access private
- */
- public function setOffline($value)
- {
- $this->offline = (isset($value) && $value == 'on');
- }
-}
-
-require_once './libraries/schema/TableStats.class.php';
-
-/**
- * Table preferences/statistics
- *
- * This class preserves the table co-ordinates,fields
- * and helps in drawing/generating the Tables in PDF document.
- *
- * @name Table_Stats_Pdf
- * @package PhpMyAdmin
- * @see PMA_Schema_PDF
- */
-class Table_Stats_Pdf extends TableStats
-{
/**
- * Defines properties
- */
- public $nb_fiels;
- public $height;
- private $_ff = PMA_PDF_FONT;
-
- /**
- * The "Table_Stats_Pdf" constructor
+ * Set whether the document is generated from client side DB
*
- * @param string $tableName The table name
- * @param integer $fontSize The font size
- * @param integer $pageNumber The current page number (from the
- * $cfg['Servers'][$i]['table_coords'] table)
- * @param integer &$sameWideWidth The max. with among tables
- * @param boolean $showKeys Whether to display keys or not
- * @param boolean $showInfo Whether to display table position or not
- *
- * @global object $pdf The current PDF document
- * @global array $cfgRelation The relations settings
- * @global string $db The current db name
- *
- * @see PMA_Schema_PDF, Table_Stats_Pdf::Table_Stats_setWidth,
- * Table_Stats_Pdf::Table_Stats_setHeight
- */
- function __construct($tableName, $fontSize, $pageNumber, &$sameWideWidth,
- $showKeys = false, $showInfo = false, $offline = false
- ) {
- global $pdf, $cfgRelation, $db;
- parent::__construct(
- $pdf, $db, $pageNumber, $tableName, $showKeys, $showInfo, $offline
- );
-
- $this->heightCell = 6;
- $this->_setHeight();
- /*
- * setWidth must me after setHeight, because title
- * can include table height which changes table width
- */
- $this->_setWidth($fontSize);
- if ($sameWideWidth < $this->width) {
- $sameWideWidth = $this->width;
- }
- }
-
- /**
- * Displays an error when the table cannot be found.
- *
- * @return void
- */
- protected function showMissingTableError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "PDF",
- sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
- );
- }
-
- /**
- * Displays an error on missing coordinates
- *
- * @return void
- */
- protected function showMissingCoordinatesError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "PDF",
- sprintf(
- __('Please configure the coordinates for table %s'),
- $this->tableName
- )
- );
- }
-
- /**
- * Returns title of the current table,
- * title can have the dimensions of the table
- *
- * @return string
- */
- protected function getTitle()
- {
- $ret = '';
- if ($this->showInfo) {
- $ret = sprintf('%.0fx%0.f', $this->width, $this->height);
- }
- return $ret . ' ' . $this->tableName;
- }
-
- /**
- * Sets the width of the table
- *
- * @param integer $fontSize The font size
- *
- * @global object $pdf The current PDF document
- *
- * @access private
- *
- * @return void
- *
- * @see PMA_Schema_PDF
- */
- private function _setWidth($fontSize)
- {
- global $pdf;
-
- foreach ($this->fields as $field) {
- $this->width = max($this->width, $pdf->GetStringWidth($field));
- }
- $this->width += $pdf->GetStringWidth(' ');
- $pdf->SetFont($this->_ff, 'B', $fontSize);
- /*
- * it is unknown what value must be added, because
- * table title is affected by the tabe width value
- */
- while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
- $this->width += 5;
- }
- $pdf->SetFont($this->_ff, '', $fontSize);
- }
-
- /**
- * Sets the height of the table
+ * @param string $value 'on' if offline
*
* @return void
*
* @access private
*/
- private function _setHeight()
+ public function setOffline($value)
{
- $this->height = (count($this->fields) + 1) * $this->heightCell;
- }
-
- /**
- * Do draw the table
- *
- * @param integer $fontSize The font size
- * @param boolean $withDoc Whether to include links to documentation
- * @param boolean|integer $setColor Whether to display color
- *
- * @global object $pdf The current PDF document
- *
- * @access public
- *
- * @return void
- *
- * @see PMA_Schema_PDF
- */
- public function tableDraw($fontSize, $withDoc, $setColor = 0)
- {
- global $pdf, $withDoc;
-
- $pdf->setXyScale($this->x, $this->y);
- $pdf->SetFont($this->_ff, 'B', $fontSize);
- if ($setColor) {
- $pdf->SetTextColor(200);
- $pdf->SetFillColor(0, 0, 128);
- }
- if ($withDoc) {
- $pdf->SetLink($pdf->PMA_links['RT'][$this->tableName]['-'], -1);
- } else {
- $pdf->PMA_links['doc'][$this->tableName]['-'] = '';
- }
-
- $pdf->cellScale(
- $this->width,
- $this->heightCell,
- $this->getTitle(),
- 1,
- 1,
- 'C',
- $setColor,
- $pdf->PMA_links['doc'][$this->tableName]['-']
- );
- $pdf->setXScale($this->x);
- $pdf->SetFont($this->_ff, '', $fontSize);
- $pdf->SetTextColor(0);
- $pdf->SetFillColor(255);
-
- foreach ($this->fields as $field) {
- if ($setColor) {
- if (in_array($field, $this->primary)) {
- $pdf->SetFillColor(215, 121, 123);
- }
- if ($field == $this->displayfield) {
- $pdf->SetFillColor(142, 159, 224);
- }
- }
- if ($withDoc) {
- $pdf->SetLink($pdf->PMA_links['RT'][$this->tableName][$field], -1);
- } else {
- $pdf->PMA_links['doc'][$this->tableName][$field] = '';
- }
-
- $pdf->cellScale(
- $this->width,
- $this->heightCell,
- ' ' . $field,
- 1,
- 1,
- 'L',
- $setColor,
- $pdf->PMA_links['doc'][$this->tableName][$field]
- );
- $pdf->setXScale($this->x);
- $pdf->SetFillColor(255);
- }
- }
-}
-
-/**
- * Relation preferences/statistics
- *
- * This class fetches the table master and foreign fields positions
- * and helps in generating the Table references and then connects
- * master table's master field to foreign table's foreign key
- * in PDF document.
- *
- * @name Relation_Stats_Pdf
- * @package PhpMyAdmin
- * @see PMA_Schema_PDF::SetDrawColor, PMA_Schema_PDF::setLineWidthScale,
- * PMA_Schema_PDF::lineScale
- */
-class Relation_Stats_Pdf
-{
- /**
- * Defines properties
- */
- public $xSrc, $ySrc;
- public $srcDir;
- public $destDir;
- public $xDest, $yDest;
- public $wTick = 5;
-
- /**
- * The "Relation_Stats_Pdf" constructor
- *
- * @param string $master_table The master table name
- * @param string $master_field The relation field in the master table
- * @param string $foreign_table The foreign table name
- * @param string $foreign_field The relation field in the foreign table
- *
- * @see Relation_Stats_Pdf::_getXy
- */
- function __construct($master_table, $master_field, $foreign_table,
- $foreign_field
- ) {
- $src_pos = $this->_getXy($master_table, $master_field);
- $dest_pos = $this->_getXy($foreign_table, $foreign_field);
- /*
- * [0] is x-left
- * [1] is x-right
- * [2] is y
- */
- $src_left = $src_pos[0] - $this->wTick;
- $src_right = $src_pos[1] + $this->wTick;
- $dest_left = $dest_pos[0] - $this->wTick;
- $dest_right = $dest_pos[1] + $this->wTick;
-
- $d1 = abs($src_left - $dest_left);
- $d2 = abs($src_right - $dest_left);
- $d3 = abs($src_left - $dest_right);
- $d4 = abs($src_right - $dest_right);
- $d = min($d1, $d2, $d3, $d4);
-
- if ($d == $d1) {
- $this->xSrc = $src_pos[0];
- $this->srcDir = -1;
- $this->xDest = $dest_pos[0];
- $this->destDir = -1;
- } elseif ($d == $d2) {
- $this->xSrc = $src_pos[1];
- $this->srcDir = 1;
- $this->xDest = $dest_pos[0];
- $this->destDir = -1;
- } elseif ($d == $d3) {
- $this->xSrc = $src_pos[0];
- $this->srcDir = -1;
- $this->xDest = $dest_pos[1];
- $this->destDir = 1;
- } else {
- $this->xSrc = $src_pos[1];
- $this->srcDir = 1;
- $this->xDest = $dest_pos[1];
- $this->destDir = 1;
- }
- $this->ySrc = $src_pos[2];
- $this->yDest = $dest_pos[2];
- }
-
- /**
- * Gets arrows coordinates
- *
- * @param string $table The current table name
- * @param string $column The relation column name
- *
- * @return array Arrows coordinates
- *
- * @access private
- */
- private function _getXy($table, $column)
- {
- $pos = array_search($column, $table->fields);
- // x_left, x_right, y
- return array(
- $table->x,
- $table->x + $table->width,
- $table->y + ($pos + 1.5) * $table->heightCell
- );
- }
-
- /**
- * draws relation links and arrows shows foreign key relations
- *
- * @param boolean $changeColor Whether to use one color per relation or not
- * @param integer $i The id of the link to draw
- *
- * @global object $pdf The current PDF document
- *
- * @access public
- *
- * @return void
- *
- * @see PMA_Schema_PDF
- */
- public function relationDraw($changeColor, $i)
- {
- global $pdf;
-
- if ($changeColor) {
- $d = $i % 6;
- $j = ($i - $d) / 6;
- $j = $j % 4;
- $j++;
- $case = array(
- array(1, 0, 0),
- array(0, 1, 0),
- array(0, 0, 1),
- array(1, 1, 0),
- array(1, 0, 1),
- array(0, 1, 1)
- );
- list ($a, $b, $c) = $case[$d];
- $e = (1 - ($j - 1) / 6);
- $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
- } else {
- $pdf->SetDrawColor(0);
- }
- $pdf->setLineWidthScale(0.2);
- $pdf->lineScale(
- $this->xSrc,
- $this->ySrc,
- $this->xSrc + $this->srcDir * $this->wTick,
- $this->ySrc
- );
- $pdf->lineScale(
- $this->xDest + $this->destDir * $this->wTick,
- $this->yDest,
- $this->xDest,
- $this->yDest
- );
- $pdf->setLineWidthScale(0.1);
- $pdf->lineScale(
- $this->xSrc + $this->srcDir * $this->wTick,
- $this->ySrc,
- $this->xDest + $this->destDir * $this->wTick,
- $this->yDest
- );
- /*
- * Draws arrows ->
- */
- $root2 = 2 * sqrt(2);
- $pdf->lineScale(
- $this->xSrc + $this->srcDir * $this->wTick * 0.75,
- $this->ySrc,
- $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
- $this->ySrc + $this->wTick / $root2
- );
- $pdf->lineScale(
- $this->xSrc + $this->srcDir * $this->wTick * 0.75,
- $this->ySrc,
- $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
- $this->ySrc - $this->wTick / $root2
- );
-
- $pdf->lineScale(
- $this->xDest + $this->destDir * $this->wTick / 2,
- $this->yDest,
- $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
- $this->yDest + $this->wTick / $root2
- );
- $pdf->lineScale(
- $this->xDest + $this->destDir * $this->wTick / 2,
- $this->yDest,
- $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
- $this->yDest - $this->wTick / $root2
- );
- $pdf->SetDrawColor(0);
+ $this->_offline = (isset($value) && $value == 'on');
}
}
@@ -821,6 +424,8 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
/**
* Defines properties
*/
+ private $_showGrid;
+ private $_withDoc;
private $_tables = array();
private $_ff = PMA_PDF_FONT;
private $_xMax = 0;
@@ -840,28 +445,28 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
*
* @global object $pdf The current PDF Schema document
* @global string $db The current db name
- * @global array The relations settings
* @access private
* @see PMA_Schema_PDF
*/
function __construct()
{
+ parent::__construct();
+
global $pdf, $db;
- $this->setPageNumber($_POST['pdf_page_number']);
- $this->setShowGrid($_POST['show_grid']);
- $this->setShowColor($_POST['show_color']);
- $this->setShowKeys($_POST['show_keys']);
- $this->setTableDimension($_POST['show_table_dimension']);
- $this->setAllTablesSameWidth($_POST['all_tables_same_width']);
- $this->setWithDataDictionary($_POST['with_doc']);
- $this->setOrientation($_POST['orientation']);
- $this->setPaper($_POST['paper']);
- $this->setExportType($_POST['export_type']);
- $this->setOffline($_POST['offline_export']);
+ $this->setShowGrid(isset($_REQUEST['pdf_show_grid']));
+ $this->setShowColor(isset($_REQUEST['pdf_show_color']));
+ $this->setShowKeys(isset($_REQUEST['pdf_show_keys']));
+ $this->setTableDimension(isset($_REQUEST['pdf_show_table_dimension']));
+ $this->setAllTablesSameWidth(isset($_REQUEST['pdf_all_tables_same_width']));
+ $this->setWithDataDictionary(isset($_REQUEST['pdf_with_doc']));
+ $this->setOrientation($_REQUEST['pdf_orientation']);
+ $this->setPaper($_REQUEST['pdf_paper']);
// Initializes a new document
- $pdf = new PMA_Schema_PDF($this->orientation, 'mm', $this->paper);
+ $pdf = new PMA_Schema_PDF(
+ $this->orientation, 'mm', $this->paper, intval($_REQUEST['chpage'])
+ );
$pdf->SetTitle(
sprintf(
__('Schema of the %s database - Page %s'),
@@ -875,7 +480,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
$pdf->setOffline($this->isOffline());
if ($this->isOffline()) {
$alltables = array();
- $tbl_coords = json_decode($GLOBALS['tbl_coords']);
+ $tbl_coords = json_decode($_REQUEST['tbl_coords']);
foreach ($tbl_coords as $tbl) {
$alltables[] = $tbl->table_name;
}
@@ -883,7 +488,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
$alltables = $this->getAllTables($db, $this->pageNumber);
}
- if ($this->withDoc) {
+ if ($this->_withDoc) {
$pdf->SetAutoPageBreak('auto', 15);
$pdf->setCMargin(1);
$this->dataDictionaryDoc($alltables);
@@ -893,7 +498,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
$pdf->Addpage();
- if ($this->withDoc) {
+ if ($this->_withDoc) {
$pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
$pdf->Bookmark(__('Relational schema'));
$pdf->SetAlias('{00}', $pdf->PageNo());
@@ -940,7 +545,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
// Builds and save the PDF document
$pdf->setLineWidthScale(0.1);
- if ($this->showGrid) {
+ if ($this->_showGrid) {
$pdf->SetFontSize(10);
$this->_strokeGrid();
}
@@ -988,9 +593,37 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
} // end while
if ($seen_a_relation) {
- $this->_drawRelations($this->showColor);
+ $this->_drawRelations();
}
- $this->_drawTables($this->showColor);
+ $this->_drawTables();
+ }
+
+ /**
+ * Set Show Grid
+ *
+ * @param boolean $value show grid of the document or not
+ *
+ * @return void
+ *
+ * @access public
+ */
+ public function setShowGrid($value)
+ {
+ $this->_showGrid = (isset($value) && $value == 'on');
+ }
+
+ /**
+ * Set Data Dictionary
+ *
+ * @param boolean $value show selected database data dictionary or not
+ *
+ * @return void
+ *
+ * @access public
+ */
+ public function setWithDataDictionary($value)
+ {
+ $this->_withDoc = (isset($value) && $value == 'on');
}
/**
@@ -1080,7 +713,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
$gridSize = 10;
$labelHeight = 4;
$labelWidth = 5;
- if ($this->withDoc) {
+ if ($this->_withDoc) {
$topSpace = 6;
$bottomSpace = 15;
} else {
@@ -1141,19 +774,17 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
/**
* Draws relation arrows
*
- * @param boolean $changeColor Whether to use one color per relation or not
- *
* @access private
*
* @return void
*
* @see Relation_Stats_Pdf::relationdraw()
*/
- private function _drawRelations($changeColor)
+ private function _drawRelations()
{
$i = 0;
foreach ($this->relations as $relation) {
- $relation->relationDraw($changeColor, $i);
+ $relation->relationDraw($this->showColor, $i);
$i++;
}
}
@@ -1161,18 +792,16 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
/**
* Draws tables
*
- * @param boolean|integer $changeColor Whether to display table position or not
- *
* @access private
*
* @return void
*
* @see Table_Stats_Pdf::tableDraw()
*/
- private function _drawTables($changeColor = 0)
+ private function _drawTables()
{
foreach ($this->_tables as $table) {
- $table->tableDraw(null, $this->withDoc, $changeColor);
+ $table->tableDraw(null, $this->_withDoc, $this->showColor);
}
}
@@ -1194,16 +823,18 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
*/
private function _showOutput($pageNumber)
{
- global $pdf, $cfgRelation;
+ global $pdf;
// Get the name of this pdfpage to use as filename
if ($this->isOffline()) {
$filename = __("PDF export page") . '.pdf';
} else {
- $editingPage = $_POST['chpage'] != '-1' ? $_POST['chpage'] : $pageNumber;
+ $editingPage = $_REQUEST['chpage'] != '-1'
+ ? $_REQUEST['chpage']
+ : $pageNumber;
$_name_sql = 'SELECT page_descr FROM '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
- . PMA_Util::backquote($cfgRelation['pdf_pages'])
+ . PMA_Util::backquote($GLOBALS['cfgRelation']['pdf_pages'])
. ' WHERE page_nr = ' . $editingPage;
$_name_rs = PMA_queryAsControlUser($_name_sql);
if ($_name_rs) {
@@ -1227,9 +858,9 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
*/
public function dataDictionaryDoc($alltables)
{
- global $db, $pdf, $orientation, $paper;
+ global $db, $pdf, $pdf_orientation, $pdf_paper;
// TOC
- $pdf->addpage($_POST['orientation']);
+ $pdf->addpage($this->orientation);
$pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
$pdf->Ln(15);
$i = 1;
@@ -1274,7 +905,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
foreach ($alltables as $table) {
$z++;
$pdf->SetAutoPageBreak(true, 15);
- $pdf->addpage($_POST['orientation']);
+ $pdf->addpage($this->orientation);
$pdf->Bookmark($table);
$pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
$pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
@@ -1404,7 +1035,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
}
$pdf->SetFont($this->_ff, 'B');
- if (isset($orientation) && $orientation == 'L') {
+ if (isset($pdf_orientation) && $pdf_orientation == 'L') {
$pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
$pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
$pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
@@ -1413,7 +1044,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
$pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
$pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
- if ($paper == 'A4') {
+ if ($pdf_paper == 'A4') {
$comments_width = 67;
} else {
// this is really intended for 'letter'
diff --git a/libraries/plugins/schema/pdf/RelationStatsPdf.class.php b/libraries/plugins/schema/pdf/RelationStatsPdf.class.php
new file mode 100644
index 0000000000..1d0e02d951
--- /dev/null
+++ b/libraries/plugins/schema/pdf/RelationStatsPdf.class.php
@@ -0,0 +1,204 @@
+_getXy($master_table, $master_field);
+ $dest_pos = $this->_getXy($foreign_table, $foreign_field);
+ /*
+ * [0] is x-left
+ * [1] is x-right
+ * [2] is y
+ */
+ $src_left = $src_pos[0] - $this->wTick;
+ $src_right = $src_pos[1] + $this->wTick;
+ $dest_left = $dest_pos[0] - $this->wTick;
+ $dest_right = $dest_pos[1] + $this->wTick;
+
+ $d1 = abs($src_left - $dest_left);
+ $d2 = abs($src_right - $dest_left);
+ $d3 = abs($src_left - $dest_right);
+ $d4 = abs($src_right - $dest_right);
+ $d = min($d1, $d2, $d3, $d4);
+
+ if ($d == $d1) {
+ $this->xSrc = $src_pos[0];
+ $this->srcDir = -1;
+ $this->xDest = $dest_pos[0];
+ $this->destDir = -1;
+ } elseif ($d == $d2) {
+ $this->xSrc = $src_pos[1];
+ $this->srcDir = 1;
+ $this->xDest = $dest_pos[0];
+ $this->destDir = -1;
+ } elseif ($d == $d3) {
+ $this->xSrc = $src_pos[0];
+ $this->srcDir = -1;
+ $this->xDest = $dest_pos[1];
+ $this->destDir = 1;
+ } else {
+ $this->xSrc = $src_pos[1];
+ $this->srcDir = 1;
+ $this->xDest = $dest_pos[1];
+ $this->destDir = 1;
+ }
+ $this->ySrc = $src_pos[2];
+ $this->yDest = $dest_pos[2];
+ }
+
+ /**
+ * Gets arrows coordinates
+ *
+ * @param string $table The current table name
+ * @param string $column The relation column name
+ *
+ * @return array Arrows coordinates
+ *
+ * @access private
+ */
+ private function _getXy($table, $column)
+ {
+ $pos = array_search($column, $table->fields);
+ // x_left, x_right, y
+ return array(
+ $table->x,
+ $table->x + $table->width,
+ $table->y + ($pos + 1.5) * $table->heightCell
+ );
+ }
+
+ /**
+ * draws relation links and arrows shows foreign key relations
+ *
+ * @param boolean $showColor Whether to use one color per relation or not
+ * @param integer $i The id of the link to draw
+ *
+ * @global object $pdf The current PDF document
+ *
+ * @access public
+ *
+ * @return void
+ *
+ * @see PMA_Schema_PDF
+ */
+ public function relationDraw($showColor, $i)
+ {
+ global $pdf;
+
+ if ($showColor) {
+ $d = $i % 6;
+ $j = ($i - $d) / 6;
+ $j = $j % 4;
+ $j++;
+ $case = array(
+ array(1, 0, 0),
+ array(0, 1, 0),
+ array(0, 0, 1),
+ array(1, 1, 0),
+ array(1, 0, 1),
+ array(0, 1, 1)
+ );
+ list ($a, $b, $c) = $case[$d];
+ $e = (1 - ($j - 1) / 6);
+ $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
+ } else {
+ $pdf->SetDrawColor(0);
+ }
+ $pdf->setLineWidthScale(0.2);
+ $pdf->lineScale(
+ $this->xSrc,
+ $this->ySrc,
+ $this->xSrc + $this->srcDir * $this->wTick,
+ $this->ySrc
+ );
+ $pdf->lineScale(
+ $this->xDest + $this->destDir * $this->wTick,
+ $this->yDest,
+ $this->xDest,
+ $this->yDest
+ );
+ $pdf->setLineWidthScale(0.1);
+ $pdf->lineScale(
+ $this->xSrc + $this->srcDir * $this->wTick,
+ $this->ySrc,
+ $this->xDest + $this->destDir * $this->wTick,
+ $this->yDest
+ );
+ /*
+ * Draws arrows ->
+ */
+ $root2 = 2 * sqrt(2);
+ $pdf->lineScale(
+ $this->xSrc + $this->srcDir * $this->wTick * 0.75,
+ $this->ySrc,
+ $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
+ $this->ySrc + $this->wTick / $root2
+ );
+ $pdf->lineScale(
+ $this->xSrc + $this->srcDir * $this->wTick * 0.75,
+ $this->ySrc,
+ $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
+ $this->ySrc - $this->wTick / $root2
+ );
+
+ $pdf->lineScale(
+ $this->xDest + $this->destDir * $this->wTick / 2,
+ $this->yDest,
+ $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
+ $this->yDest + $this->wTick / $root2
+ );
+ $pdf->lineScale(
+ $this->xDest + $this->destDir * $this->wTick / 2,
+ $this->yDest,
+ $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
+ $this->yDest - $this->wTick / $root2
+ );
+ $pdf->SetDrawColor(0);
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/plugins/schema/pdf/TableStatsPdf.class.php b/libraries/plugins/schema/pdf/TableStatsPdf.class.php
new file mode 100644
index 0000000000..a92e63d3ad
--- /dev/null
+++ b/libraries/plugins/schema/pdf/TableStatsPdf.class.php
@@ -0,0 +1,240 @@
+heightCell = 6;
+ $this->_setHeight();
+ /*
+ * setWidth must me after setHeight, because title
+ * can include table height which changes table width
+ */
+ $this->_setWidth($fontSize);
+ if ($sameWideWidth < $this->width) {
+ $sameWideWidth = $this->width;
+ }
+ }
+
+ /**
+ * Displays an error when the table cannot be found.
+ *
+ * @return void
+ */
+ protected function showMissingTableError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "PDF",
+ sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
+ );
+ }
+
+ /**
+ * Displays an error on missing coordinates
+ *
+ * @return void
+ */
+ protected function showMissingCoordinatesError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "PDF",
+ sprintf(
+ __('Please configure the coordinates for table %s'),
+ $this->tableName
+ )
+ );
+ }
+
+ /**
+ * Returns title of the current table,
+ * title can have the dimensions of the table
+ *
+ * @return string
+ */
+ protected function getTitle()
+ {
+ $ret = '';
+ if ($this->tableDimension) {
+ $ret = sprintf('%.0fx%0.f', $this->width, $this->height);
+ }
+ return $ret . ' ' . $this->tableName;
+ }
+
+ /**
+ * Sets the width of the table
+ *
+ * @param integer $fontSize The font size
+ *
+ * @global object $pdf The current PDF document
+ *
+ * @access private
+ *
+ * @return void
+ *
+ * @see PMA_Schema_PDF
+ */
+ private function _setWidth($fontSize)
+ {
+ global $pdf;
+
+ foreach ($this->fields as $field) {
+ $this->width = max($this->width, $pdf->GetStringWidth($field));
+ }
+ $this->width += $pdf->GetStringWidth(' ');
+ $pdf->SetFont($this->_ff, 'B', $fontSize);
+ /*
+ * it is unknown what value must be added, because
+ * table title is affected by the tabe width value
+ */
+ while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
+ $this->width += 5;
+ }
+ $pdf->SetFont($this->_ff, '', $fontSize);
+ }
+
+ /**
+ * Sets the height of the table
+ *
+ * @return void
+ *
+ * @access private
+ */
+ private function _setHeight()
+ {
+ $this->height = (count($this->fields) + 1) * $this->heightCell;
+ }
+
+ /**
+ * Do draw the table
+ *
+ * @param integer $fontSize The font size
+ * @param boolean $withDoc Whether to include links to documentation
+ * @param boolean|integer $setColor Whether to display color
+ *
+ * @global object $pdf The current PDF document
+ *
+ * @access public
+ *
+ * @return void
+ *
+ * @see PMA_Schema_PDF
+ */
+ public function tableDraw($fontSize, $withDoc, $setColor = 0)
+ {
+ global $pdf;
+
+ $pdf->setXyScale($this->x, $this->y);
+ $pdf->SetFont($this->_ff, 'B', $fontSize);
+ if ($setColor) {
+ $pdf->SetTextColor(200);
+ $pdf->SetFillColor(0, 0, 128);
+ }
+ if ($withDoc) {
+ $pdf->SetLink($pdf->PMA_links['RT'][$this->tableName]['-'], -1);
+ } else {
+ $pdf->PMA_links['doc'][$this->tableName]['-'] = '';
+ }
+
+ $pdf->cellScale(
+ $this->width,
+ $this->heightCell,
+ $this->getTitle(),
+ 1,
+ 1,
+ 'C',
+ $setColor,
+ $pdf->PMA_links['doc'][$this->tableName]['-']
+ );
+ $pdf->setXScale($this->x);
+ $pdf->SetFont($this->_ff, '', $fontSize);
+ $pdf->SetTextColor(0);
+ $pdf->SetFillColor(255);
+
+ foreach ($this->fields as $field) {
+ if ($setColor) {
+ if (in_array($field, $this->primary)) {
+ $pdf->SetFillColor(215, 121, 123);
+ }
+ if ($field == $this->displayfield) {
+ $pdf->SetFillColor(142, 159, 224);
+ }
+ }
+ if ($withDoc) {
+ $pdf->SetLink($pdf->PMA_links['RT'][$this->tableName][$field], -1);
+ } else {
+ $pdf->PMA_links['doc'][$this->tableName][$field] = '';
+ }
+
+ $pdf->cellScale(
+ $this->width,
+ $this->heightCell,
+ ' ' . $field,
+ 1,
+ 1,
+ 'L',
+ $setColor,
+ $pdf->PMA_links['doc'][$this->tableName][$field]
+ );
+ $pdf->setXScale($this->x);
+ $pdf->SetFillColor(255);
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/libraries/plugins/schema/svg/RelationStatsSvg.class.php b/libraries/plugins/schema/svg/RelationStatsSvg.class.php
new file mode 100644
index 0000000000..b8ec990c05
--- /dev/null
+++ b/libraries/plugins/schema/svg/RelationStatsSvg.class.php
@@ -0,0 +1,187 @@
+_getXy($master_table, $master_field);
+ $dest_pos = $this->_getXy($foreign_table, $foreign_field);
+ /*
+ * [0] is x-left
+ * [1] is x-right
+ * [2] is y
+ */
+ $src_left = $src_pos[0] - $this->wTick;
+ $src_right = $src_pos[1] + $this->wTick;
+ $dest_left = $dest_pos[0] - $this->wTick;
+ $dest_right = $dest_pos[1] + $this->wTick;
+
+ $d1 = abs($src_left - $dest_left);
+ $d2 = abs($src_right - $dest_left);
+ $d3 = abs($src_left - $dest_right);
+ $d4 = abs($src_right - $dest_right);
+ $d = min($d1, $d2, $d3, $d4);
+
+ if ($d == $d1) {
+ $this->xSrc = $src_pos[0];
+ $this->srcDir = -1;
+ $this->xDest = $dest_pos[0];
+ $this->destDir = -1;
+ } elseif ($d == $d2) {
+ $this->xSrc = $src_pos[1];
+ $this->srcDir = 1;
+ $this->xDest = $dest_pos[0];
+ $this->destDir = -1;
+ } elseif ($d == $d3) {
+ $this->xSrc = $src_pos[0];
+ $this->srcDir = -1;
+ $this->xDest = $dest_pos[1];
+ $this->destDir = 1;
+ } else {
+ $this->xSrc = $src_pos[1];
+ $this->srcDir = 1;
+ $this->xDest = $dest_pos[1];
+ $this->destDir = 1;
+ }
+ $this->ySrc = $src_pos[2];
+ $this->yDest = $dest_pos[2];
+ }
+
+ /**
+ * Gets arrows coordinates
+ *
+ * @param string $table The current table name
+ * @param string $column The relation column name
+ *
+ * @return array Arrows coordinates
+ * @access private
+ */
+ function _getXy($table, $column)
+ {
+ $pos = array_search($column, $table->fields);
+ // x_left, x_right, y
+ return array(
+ $table->x,
+ $table->x + $table->width,
+ $table->y + ($pos + 1.5) * $table->heightCell
+ );
+ }
+
+ /**
+ * draws relation links and arrows shows foreign key relations
+ *
+ * @param boolean $showColor Whether to use one color per relation or not
+ *
+ * @global object $svg The current SVG image document
+ *
+ * @return void
+ * @access public
+ *
+ * @see PMA_SVG
+ */
+ public function relationDraw($showColor)
+ {
+ global $svg;
+
+ if ($showColor) {
+ $listOfColors = array(
+ 'red',
+ 'grey',
+ 'black',
+ 'yellow',
+ 'green',
+ 'cyan',
+ ' orange'
+ );
+ shuffle($listOfColors);
+ $color = $listOfColors[0];
+ } else {
+ $color = 'black';
+ }
+
+ $svg->printElementLine(
+ 'line', $this->xSrc, $this->ySrc,
+ $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
+ 'fill:' . $color . ';stroke:black;stroke-width:2;'
+ );
+ $svg->printElementLine(
+ 'line', $this->xDest + $this->destDir * $this->wTick,
+ $this->yDest, $this->xDest, $this->yDest,
+ 'fill:' . $color . ';stroke:black;stroke-width:2;'
+ );
+ $svg->printElementLine(
+ 'line', $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
+ $this->xDest + $this->destDir * $this->wTick, $this->yDest,
+ 'fill:' . $color . ';stroke:' . $color . ';stroke-width:1;'
+ );
+ $root2 = 2 * sqrt(2);
+ $svg->printElementLine(
+ 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
+ $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
+ $this->ySrc + $this->wTick / $root2,
+ 'fill:' . $color . ';stroke:black;stroke-width:2;'
+ );
+ $svg->printElementLine(
+ 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
+ $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
+ $this->ySrc - $this->wTick / $root2,
+ 'fill:' . $color . ';stroke:black;stroke-width:2;'
+ );
+ $svg->printElementLine(
+ 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
+ $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
+ $this->yDest + $this->wTick / $root2,
+ 'fill:' . $color . ';stroke:black;stroke-width:2;'
+ );
+ $svg->printElementLine(
+ 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
+ $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
+ $this->yDest - $this->wTick / $root2,
+ 'fill:' . $color . ';stroke:black;stroke-width:2;'
+ );
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/schema/Svg_Relation_Schema.class.php b/libraries/plugins/schema/svg/Svg_Relation_Schema.class.php
similarity index 51%
rename from libraries/schema/Svg_Relation_Schema.class.php
rename to libraries/plugins/schema/svg/Svg_Relation_Schema.class.php
index c46f0be5da..dc02f0cdf1 100644
--- a/libraries/schema/Svg_Relation_Schema.class.php
+++ b/libraries/plugins/schema/svg/Svg_Relation_Schema.class.php
@@ -9,7 +9,9 @@ if (! defined('PHPMYADMIN')) {
exit;
}
-require_once 'Export_Relation_Schema.class.php';
+require_once 'libraries/plugins/schema/Export_Relation_Schema.class.php';
+require_once 'libraries/plugins/schema/svg/RelationStatsSvg.class.php';
+require_once 'libraries/plugins/schema/svg/TableStatsSvg.class.php';
require_once 'libraries/Font.class.php';
/**
@@ -263,371 +265,6 @@ class PMA_SVG extends XMLWriter
}
}
-require_once './libraries/schema/TableStats.class.php';
-
-/**
- * Table preferences/statistics
- *
- * This class preserves the table co-ordinates,fields
- * and helps in drawing/generating the Tables in SVG XML document.
- *
- * @package PhpMyAdmin
- * @name Table_Stats_Svg
- * @see PMA_SVG
- */
-class Table_Stats_Svg extends TableStats
-{
- /**
- * Defines properties
- */
- public $height;
- public $currentCell = 0;
-
- /**
- * The "Table_Stats_Svg" constructor
- *
- * @param string $tableName The table name
- * @param string $font Font face
- * @param integer $fontSize The font size
- * @param integer $pageNumber Page number
- * @param integer &$same_wide_width The max. with among tables
- * @param boolean $showKeys Whether to display keys or not
- * @param boolean $showInfo Whether to display table position or not
- *
- * @global object $svg The current SVG image document
- * @global integer The current page number (from the
- * $cfg['Servers'][$i]['table_coords'] table)
- * @global array $cfgRelation The relations settings
- * @global string $db The current db name
- *
- * @access private
- *
- * @see PMA_SVG, Table_Stats_Svg::Table_Stats_setWidth,
- * Table_Stats_Svg::Table_Stats_setHeight
- */
- function __construct(
- $tableName, $font, $fontSize, $pageNumber, &$same_wide_width,
- $showKeys = false, $showInfo = false, $offline = false
- ) {
- global $svg, $cfgRelation, $db;
- parent::__construct(
- $svg, $db, $pageNumber, $tableName, $showKeys, $showInfo, $offline
- );
-
- // 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;
- }
- }
-
- /**
- * Displays an error when the table cannot be found.
- *
- * @return void
- */
- protected function showMissingTableError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "SVG",
- sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
- );
- }
-
- /**
- * Displays an error on missing coordinates
- *
- * @return void
- */
- protected function showMissingCoordinatesError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "SVG",
- sprintf(
- __('Please configure the coordinates for table %s'),
- $this->tableName
- )
- );
- }
-
- /**
- * Sets the width of the table
- *
- * @param string $font The font size
- * @param integer $fontSize The font size
- *
- * @global object $svg The current SVG image document
- *
- * @return void
- * @access private
- *
- * @see PMA_SVG
- */
- private function _setWidthTable($font,$fontSize)
- {
- foreach ($this->fields as $field) {
- $this->width = max(
- $this->width,
- PMA_Font::getStringWidth($field, $font, $fontSize)
- );
- }
- $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
-
- /*
- * it is unknown what value must be added, because
- * table title is affected by the tabe width value
- */
- while ($this->width
- < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)
- ) {
- $this->width += 7;
- }
- }
-
- /**
- * Sets the height of the table
- *
- * @param integer $fontSize font size
- *
- * @return void
- * @access private
- */
- function _setHeightTable($fontSize)
- {
- $this->heightCell = $fontSize + 4;
- $this->height = (count($this->fields) + 1) * $this->heightCell;
- }
-
- /**
- * draw the table
- *
- * @param boolean $showColor Whether to display color
- *
- * @global object $svg The current SVG image document
- *
- * @access public
- * @return void
- *
- * @see PMA_SVG,PMA_SVG::printElement
- */
- public function tableDraw($showColor)
- {
- global $svg;
- //echo $this->tableName.'
';
- $svg->printElement(
- 'rect', $this->x, $this->y, $this->width,
- $this->heightCell, null, 'fill:red;stroke:black;'
- );
- $svg->printElement(
- 'text', $this->x + 5, $this->y+ 14, $this->width, $this->heightCell,
- $this->getTitle(), 'fill:none;stroke:black;'
- );
- foreach ($this->fields as $field) {
- $this->currentCell += $this->heightCell;
- $showColor = 'none';
- if ($showColor) {
- if (in_array($field, $this->primary)) {
- $showColor = '#0c0';
- }
- if ($field == $this->displayfield) {
- $showColor = 'none';
- }
- }
- $svg->printElement(
- 'rect', $this->x, $this->y + $this->currentCell, $this->width,
- $this->heightCell, null, 'fill:' . $showColor . ';stroke:black;'
- );
- $svg->printElement(
- 'text', $this->x + 5, $this->y + 14 + $this->currentCell,
- $this->width, $this->heightCell, $field, 'fill:none;stroke:black;'
- );
- }
- }
-}
-
-
-/**
- * Relation preferences/statistics
- *
- * This class fetches the table master and foreign fields positions
- * and helps in generating the Table references and then connects
- * master table's master field to foreign table's foreign key
- * in SVG XML document.
- *
- * @package PhpMyAdmin
- * @name Relation_Stats_Svg
- * @see PMA_SVG::printElementLine
- */
-class Relation_Stats_Svg
-{
- /**
- * Defines properties
- */
- public $xSrc, $ySrc;
- public $srcDir ;
- public $destDir;
- public $xDest, $yDest;
- public $wTick = 10;
-
- /**
- * The "Relation_Stats_Svg" constructor
- *
- * @param string $master_table The master table name
- * @param string $master_field The relation field in the master table
- * @param string $foreign_table The foreign table name
- * @param string $foreign_field The relation field in the foreign table
- *
- * @see Relation_Stats_Svg::_getXy
- */
- function __construct($master_table, $master_field, $foreign_table,
- $foreign_field
- ) {
- $src_pos = $this->_getXy($master_table, $master_field);
- $dest_pos = $this->_getXy($foreign_table, $foreign_field);
- /*
- * [0] is x-left
- * [1] is x-right
- * [2] is y
- */
- $src_left = $src_pos[0] - $this->wTick;
- $src_right = $src_pos[1] + $this->wTick;
- $dest_left = $dest_pos[0] - $this->wTick;
- $dest_right = $dest_pos[1] + $this->wTick;
-
- $d1 = abs($src_left - $dest_left);
- $d2 = abs($src_right - $dest_left);
- $d3 = abs($src_left - $dest_right);
- $d4 = abs($src_right - $dest_right);
- $d = min($d1, $d2, $d3, $d4);
-
- if ($d == $d1) {
- $this->xSrc = $src_pos[0];
- $this->srcDir = -1;
- $this->xDest = $dest_pos[0];
- $this->destDir = -1;
- } elseif ($d == $d2) {
- $this->xSrc = $src_pos[1];
- $this->srcDir = 1;
- $this->xDest = $dest_pos[0];
- $this->destDir = -1;
- } elseif ($d == $d3) {
- $this->xSrc = $src_pos[0];
- $this->srcDir = -1;
- $this->xDest = $dest_pos[1];
- $this->destDir = 1;
- } else {
- $this->xSrc = $src_pos[1];
- $this->srcDir = 1;
- $this->xDest = $dest_pos[1];
- $this->destDir = 1;
- }
- $this->ySrc = $src_pos[2];
- $this->yDest = $dest_pos[2];
- }
-
- /**
- * Gets arrows coordinates
- *
- * @param string $table The current table name
- * @param string $column The relation column name
- *
- * @return array Arrows coordinates
- * @access private
- */
- function _getXy($table, $column)
- {
- $pos = array_search($column, $table->fields);
- // x_left, x_right, y
- return array(
- $table->x,
- $table->x + $table->width,
- $table->y + ($pos + 1.5) * $table->heightCell
- );
- }
-
- /**
- * draws relation links and arrows shows foreign key relations
- *
- * @param boolean $changeColor Whether to use one color per relation or not
- *
- * @global object $svg The current SVG image document
- *
- * @return void
- * @access public
- *
- * @see PMA_SVG
- */
- public function relationDraw($changeColor)
- {
- global $svg;
-
- if ($changeColor) {
- $listOfColors = array(
- 'red',
- 'grey',
- 'black',
- 'yellow',
- 'green',
- 'cyan',
- ' orange'
- );
- shuffle($listOfColors);
- $color = $listOfColors[0];
- } else {
- $color = 'black';
- }
-
- $svg->printElementLine(
- 'line', $this->xSrc, $this->ySrc,
- $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
- 'fill:' . $color . ';stroke:black;stroke-width:2;'
- );
- $svg->printElementLine(
- 'line', $this->xDest + $this->destDir * $this->wTick,
- $this->yDest, $this->xDest, $this->yDest,
- 'fill:' . $color . ';stroke:black;stroke-width:2;'
- );
- $svg->printElementLine(
- 'line', $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
- $this->xDest + $this->destDir * $this->wTick, $this->yDest,
- 'fill:' . $color . ';stroke:' . $color . ';stroke-width:1;'
- );
- $root2 = 2 * sqrt(2);
- $svg->printElementLine(
- 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
- $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
- $this->ySrc + $this->wTick / $root2,
- 'fill:' . $color . ';stroke:black;stroke-width:2;'
- );
- $svg->printElementLine(
- 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
- $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
- $this->ySrc - $this->wTick / $root2,
- 'fill:' . $color . ';stroke:black;stroke-width:2;'
- );
- $svg->printElementLine(
- 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
- $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
- $this->yDest + $this->wTick / $root2,
- 'fill:' . $color . ';stroke:black;stroke-width:2;'
- );
- $svg->printElementLine(
- 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
- $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
- $this->yDest - $this->wTick / $root2,
- 'fill:' . $color . ';stroke:black;stroke-width:2;'
- );
- }
-}
-/*
-* end of the "Relation_Stats_Svg" class
-*/
-
/**
* Svg Relation Schema Class
*
@@ -664,15 +301,14 @@ class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
*/
function __construct()
{
- global $svg,$db;
+ parent::__construct();
- $this->setPageNumber($_POST['pdf_page_number']);
- $this->setShowColor($_POST['show_color']);
- $this->setShowKeys($_POST['show_keys']);
- $this->setTableDimension($_POST['show_table_dimension']);
- $this->setAllTablesSameWidth($_POST['all_tables_same_width']);
- $this->setExportType($_POST['export_type']);
- $this->setOffline($_POST['offline_export']);
+ global $svg, $db;
+
+ $this->setShowColor(isset($_REQUEST['svg_show_color']));
+ $this->setShowKeys(isset($_REQUEST['svg_show_keys']));
+ $this->setTableDimension(isset($_REQUEST['svg_show_table_dimension']));
+ $this->setAllTablesSameWidth(isset($_REQUEST['svg_all_tables_same_width']));
$svg = new PMA_SVG();
$svg->setTitle(
@@ -689,7 +325,7 @@ class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
if ($this->isOffline()) {
$alltables = array();
- $tbl_coords = json_decode($GLOBALS['tbl_coords']);
+ $tbl_coords = json_decode($_REQUEST['tbl_coords']);
foreach ($tbl_coords as $tbl) {
$alltables[] = $tbl->table_name;
}
@@ -751,10 +387,10 @@ class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
}
}
if ($seen_a_relation) {
- $this->_drawRelations($this->showColor);
+ $this->_drawRelations();
}
- $this->_drawTables($this->showColor);
+ $this->_drawTables();
$svg->endSvgDoc();
}
@@ -766,7 +402,7 @@ class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
*/
function showOutput()
{
- global $svg,$db;
+ global $svg, $db;
$filename = $db . '-' . $this->pageNumber;
if ($this->isOffline()) {
$filename = __("SVG export page");
@@ -794,13 +430,13 @@ class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
/**
* Defines relation objects
*
- * @param string $masterTable The master table name
- * @param string $font The font face
- * @param int $fontSize Font size
- * @param string $masterField The relation field in the master table
- * @param string $foreignTable The foreign table name
- * @param string $foreignField The relation field in the foreign table
- * @param boolean $showInfo Whether to display table position or not
+ * @param string $masterTable The master table name
+ * @param string $font The font face
+ * @param int $fontSize Font size
+ * @param string $masterField The relation field in the master table
+ * @param string $foreignTable The foreign table name
+ * @param string $foreignField The relation field in the foreign table
+ * @param boolean $tableDimension Whether to display table position or not
*
* @access private
* @return void
@@ -810,19 +446,19 @@ class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
*/
private function _addRelation(
$masterTable,$font,$fontSize, $masterField,
- $foreignTable, $foreignField, $showInfo
+ $foreignTable, $foreignField, $tableDimension
) {
if (! isset($this->_tables[$masterTable])) {
$this->_tables[$masterTable] = new Table_Stats_Svg(
$masterTable, $font, $fontSize, $this->pageNumber,
- $this->_tablewidth, false, $showInfo
+ $this->_tablewidth, false, $tableDimension
);
$this->_setMinMax($this->_tables[$masterTable]);
}
if (! isset($this->_tables[$foreignTable])) {
$this->_tables[$foreignTable] = new Table_Stats_Svg(
$foreignTable, $font, $fontSize, $this->pageNumber,
- $this->_tablewidth, false, $showInfo
+ $this->_tablewidth, false, $tableDimension
);
$this->_setMinMax($this->_tables[$foreignTable]);
}
@@ -837,34 +473,30 @@ class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
* connects master table's master field to
* foreign table's forein field
*
- * @param boolean $changeColor Whether to use one color per relation or not
- *
* @return void
* @access private
*
* @see Relation_Stats_Svg::relationDraw()
*/
- private function _drawRelations($changeColor)
+ private function _drawRelations()
{
foreach ($this->_relations as $relation) {
- $relation->relationDraw($changeColor);
+ $relation->relationDraw($this->showColor);
}
}
/**
* Draws tables
*
- * @param boolean $changeColor Whether to show color for primary fields or not
- *
* @return void
* @access private
*
* @see Table_Stats_Svg::Table_Stats_tableDraw()
*/
- private function _drawTables($changeColor)
+ private function _drawTables()
{
foreach ($this->_tables as $table) {
- $table->tableDraw($changeColor);
+ $table->tableDraw($this->showColor);
}
}
}
diff --git a/libraries/plugins/schema/svg/TableStatsSvg.class.php b/libraries/plugins/schema/svg/TableStatsSvg.class.php
new file mode 100644
index 0000000000..3230f021c0
--- /dev/null
+++ b/libraries/plugins/schema/svg/TableStatsSvg.class.php
@@ -0,0 +1,198 @@
+_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;
+ }
+ }
+
+ /**
+ * Displays an error when the table cannot be found.
+ *
+ * @return void
+ */
+ protected function showMissingTableError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "SVG",
+ sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
+ );
+ }
+
+ /**
+ * Displays an error on missing coordinates
+ *
+ * @return void
+ */
+ protected function showMissingCoordinatesError()
+ {
+ $this->diagram->dieSchema(
+ $this->pageNumber,
+ "SVG",
+ sprintf(
+ __('Please configure the coordinates for table %s'),
+ $this->tableName
+ )
+ );
+ }
+
+ /**
+ * Sets the width of the table
+ *
+ * @param string $font The font size
+ * @param integer $fontSize The font size
+ *
+ * @global object $svg The current SVG image document
+ *
+ * @return void
+ * @access private
+ *
+ * @see PMA_SVG
+ */
+ private function _setWidthTable($font,$fontSize)
+ {
+ foreach ($this->fields as $field) {
+ $this->width = max(
+ $this->width,
+ PMA_Font::getStringWidth($field, $font, $fontSize)
+ );
+ }
+ $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
+
+ /*
+ * it is unknown what value must be added, because
+ * table title is affected by the tabe width value
+ */
+ while ($this->width
+ < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)
+ ) {
+ $this->width += 7;
+ }
+ }
+
+ /**
+ * Sets the height of the table
+ *
+ * @param integer $fontSize font size
+ *
+ * @return void
+ * @access private
+ */
+ function _setHeightTable($fontSize)
+ {
+ $this->heightCell = $fontSize + 4;
+ $this->height = (count($this->fields) + 1) * $this->heightCell;
+ }
+
+ /**
+ * draw the table
+ *
+ * @param boolean $showColor Whether to display color
+ *
+ * @global object $svg The current SVG image document
+ *
+ * @access public
+ * @return void
+ *
+ * @see PMA_SVG,PMA_SVG::printElement
+ */
+ public function tableDraw($showColor)
+ {
+ global $svg;
+
+ $svg->printElement(
+ 'rect', $this->x, $this->y, $this->width,
+ $this->heightCell, null, 'fill:red;stroke:black;'
+ );
+ $svg->printElement(
+ 'text', $this->x + 5, $this->y+ 14, $this->width, $this->heightCell,
+ $this->getTitle(), 'fill:none;stroke:black;'
+ );
+ foreach ($this->fields as $field) {
+ $this->currentCell += $this->heightCell;
+ $fillColor = 'none';
+ if ($showColor) {
+ if (in_array($field, $this->primary)) {
+ $fillColor = '#0c0';
+ }
+ if ($field == $this->displayfield) {
+ $fillColor = 'none';
+ }
+ }
+ $svg->printElement(
+ 'rect', $this->x, $this->y + $this->currentCell, $this->width,
+ $this->heightCell, null, 'fill:' . $fillColor . ';stroke:black;'
+ );
+ $svg->printElement(
+ 'text', $this->x + 5, $this->y + 14 + $this->currentCell,
+ $this->width, $this->heightCell, $field, 'fill:none;stroke:black;'
+ );
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/libraries/properties/plugins/SchemaPluginProperties.class.php b/libraries/properties/plugins/SchemaPluginProperties.class.php
new file mode 100644
index 0000000000..5eb9a3416b
--- /dev/null
+++ b/libraries/properties/plugins/SchemaPluginProperties.class.php
@@ -0,0 +1,47 @@
+
\ No newline at end of file
diff --git a/libraries/schema/Dia_Relation_Schema.class.php b/libraries/schema/Dia_Relation_Schema.class.php
deleted file mode 100644
index 2f67a43cd3..0000000000
--- a/libraries/schema/Dia_Relation_Schema.class.php
+++ /dev/null
@@ -1,834 +0,0 @@
-openMemory();
- /*
- * Set indenting using three spaces,
- * so output is formatted
- */
-
- $this->setIndent(true);
- $this->setIndentString(' ');
- /*
- * Create the XML document
- */
-
- $this->startDocument('1.0', 'UTF-8');
- }
-
- /**
- * Starts Dia Document
- *
- * dia document starts by first initializing dia:diagram tag
- * then dia:diagramdata contains all the attributes that needed
- * to define the document, then finally a Layer starts which
- * holds all the objects.
- *
- * @param string $paper the size of the paper/document
- * @param float $topMargin top margin of the paper/document in cm
- * @param float $bottomMargin bottom margin of the paper/document in cm
- * @param float $leftMargin left margin of the paper/document in cm
- * @param float $rightMargin right margin of the paper/document in cm
- * @param string $portrait document will be portrait or landscape
- *
- * @return void
- *
- * @access public
- * @see XMLWriter::startElement(),XMLWriter::writeAttribute(),
- * XMLWriter::writeRaw()
- */
- function startDiaDoc($paper, $topMargin, $bottomMargin, $leftMargin,
- $rightMargin, $portrait
- ) {
- if ($portrait == 'P') {
- $isPortrait='true';
- } else {
- $isPortrait='false';
- }
- $this->startElement('dia:diagram');
- $this->writeAttribute('xmlns:dia', 'http://www.lysator.liu.se/~alla/dia/');
- $this->startElement('dia:diagramdata');
- $this->writeRaw(
- '
-
-
-
-
-
-
-
-
- #' . $paper . '#
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- '
- );
- $this->endElement();
- $this->startElement('dia:layer');
- $this->writeAttribute('name', 'Background');
- $this->writeAttribute('visible', 'true');
- $this->writeAttribute('active', 'true');
- }
-
- /**
- * Ends Dia Document
- *
- * @return void
- * @access public
- * @see XMLWriter::endElement(),XMLWriter::endDocument()
- */
- function endDiaDoc()
- {
- $this->endElement();
- $this->endDocument();
- }
-
- /**
- * Output Dia Document for download
- *
- * @param string $fileName name of the dia document
- *
- * @return void
- * @access public
- * @see XMLWriter::flush()
- */
- function showOutput($fileName)
- {
- if (ob_get_clean()) {
- ob_end_clean();
- }
- $output = $this->flush();
- PMA_Response::getInstance()->disable();
- PMA_downloadHeader(
- $fileName . '.dia', 'application/x-dia-diagram', strlen($output)
- );
- print $output;
- }
-}
-
-require_once './libraries/schema/TableStats.class.php';
-
-/**
- * Table preferences/statistics
- *
- * This class preserves the table co-ordinates,fields
- * and helps in drawing/generating the Tables in dia XML document.
- *
- * @package PhpMyAdmin
- * @name Table_Stats_Dia
- * @see PMA_DIA
- */
-class Table_Stats_Dia extends TableStats
-{
- /**
- * Defines properties
- */
- public $tableId;
- public $tableColor;
-
- /**
- * The "Table_Stats_Dia" constructor
- *
- * @param string $tableName 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
- *
- * @global object $dia The current dia document
- * @global array $cfgRelation The relations settings
- * @global string $db The current db name
- *
- * @see PMA_DIA
- */
- function __construct($tableName, $pageNumber, $showKeys = false, $offline = false)
- {
- global $dia, $cfgRelation, $db;
- parent::__construct($dia, $db, $pageNumber, $tableName, $showKeys, false, $offline);
-
- /**
- * 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;
- }
-
- /**
- * Displays an error when the table cannot be found.
- *
- * @return void
- */
- protected function showMissingTableError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "DIA",
- sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
- );
- }
-
- /**
- * Displays an error on missing coordinates
- *
- * @return void
- */
- protected function showMissingCoordinatesError()
- {
- $this->diagram->dieSchema(
- $this->pageNumber,
- "DIA",
- sprintf(
- __('Please configure the coordinates for table %s'),
- $this->tableName
- )
- );
- }
-
-
- /**
- * Do draw the table
- *
- * Tables are generated using object type Database - Table
- * primary fields are underlined in tables. Dia object
- * is used to generate the XML of Dia Document. Database Table
- * Object and their attributes are involved in the combination
- * of displaing Database - Table on Dia Document.
- *
- * @param boolean $changeColor Whether to show color for tables text or not
- * if changeColor is true then an array of $listOfColors will be used to choose
- * the random colors for tables text we can change/add more colors to this array
- *
- * @return void
- *
- * @global object $dia The current Dia document
- *
- * @access public
- * @see PMA_DIA
- */
- public function tableDraw($changeColor)
- {
- global $dia;
-
- if ($changeColor) {
- $listOfColors = array(
- 'FF0000',
- '000099',
- '00FF00'
- );
- shuffle($listOfColors);
- $this->tableColor = '#' . $listOfColors[0] . '';
- } else {
- $this->tableColor = '#000000';
- }
-
- $factor = 0.1;
-
- $dia->startElement('dia:object');
- $dia->writeAttribute('type', 'Database - Table');
- $dia->writeAttribute('version', '0');
- $dia->writeAttribute('id', '' . $this->tableId . '');
- $dia->writeRaw(
- '
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #' . $this->tableName . '#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- '
- );
-
- $dia->startElement('dia:attribute');
- $dia->writeAttribute('name', 'attributes');
-
- foreach ($this->fields as $field) {
- $dia->writeRaw(
- '
-
- #' . $field . '#
-
-
- ##
-
-
- ##
- '
- );
- unset($pm);
- $pm = 'false';
- if (in_array($field, $this->primary)) {
- $pm = 'true';
- }
- if ($field == $this->displayfield) {
- $pm = 'false';
- }
- $dia->writeRaw(
- '
-
-
-
-
-
-
-
-
- '
- );
- }
- $dia->endElement();
- $dia->endElement();
- }
-}
-
-/**
- * Relation preferences/statistics
- *
- * This class fetches the table master and foreign fields positions
- * and helps in generating the Table references and then connects
- * master table's master field to foreign table's foreign key
- * in dia XML document.
- *
- * @package PhpMyAdmin
- * @name Relation_Stats_Dia
- * @see PMA_DIA
- */
-class Relation_Stats_Dia
-{
- /**
- * Defines properties
- */
- public $srcConnPointsRight;
- public $srcConnPointsLeft;
- public $destConnPointsRight;
- public $destConnPointsLeft;
- public $masterTableId;
- public $foreignTableId;
- public $masterTablePos;
- public $foreignTablePos;
- public $referenceColor;
-
- /**
- * The "Relation_Stats_Dia" constructor
- *
- * @param string $master_table The master table name
- * @param string $master_field The relation field in the master table
- * @param string $foreign_table The foreign table name
- * @param string $foreign_field The relation field in the foreign table
- *
- * @see Relation_Stats_Dia::_getXy
- */
- function __construct($master_table, $master_field, $foreign_table,
- $foreign_field
- ) {
- $src_pos = $this->_getXy($master_table, $master_field);
- $dest_pos = $this->_getXy($foreign_table, $foreign_field);
- $this->srcConnPointsLeft = $src_pos[0];
- $this->srcConnPointsRight = $src_pos[1];
- $this->destConnPointsLeft = $dest_pos[0];
- $this->destConnPointsRight = $dest_pos[1];
- $this->masterTablePos = $src_pos[2];
- $this->foreignTablePos = $dest_pos[2];
- $this->masterTableId = $master_table->tableId;
- $this->foreignTableId = $foreign_table->tableId;
- }
-
- /**
- * Each Table object have connection points
- * which is used to connect to other objects in Dia
- * we detect the position of key in fields and
- * then determines its left and right connection
- * points.
- *
- * @param string $table The current table name
- * @param string $column The relation column name
- *
- * @return array Table right,left connection points and key position
- *
- * @access private
- */
- private function _getXy($table, $column)
- {
- $pos = array_search($column, $table->fields);
- // left, right, position
- $value = 12;
- if ($pos != 0) {
- return array($pos + $value + $pos, $pos + $value + $pos + 1, $pos);
- }
- return array($pos + $value , $pos + $value + 1, $pos);
- }
-
- /**
- * Draws relation references
- *
- * connects master table's master field to foreign table's
- * forein field using Dia object type Database - Reference
- * Dia object is used to generate the XML of Dia Document.
- * Database reference Object and their attributes are involved
- * in the combination of displaing Database - reference on Dia Document.
- *
- * @param boolean $changeColor Whether to use one color per relation or not
- * if changeColor is true then an array of $listOfColors will be used to choose
- * the random colors for references lines. we can change/add more colors to this
- *
- * @return boolean|void
- *
- * @global object $dia The current Dia document
- *
- * @access public
- * @see PMA_PDF
- */
- public function relationDraw($changeColor)
- {
- global $dia;
-
- PMA_Dia_Relation_Schema::$objectId += 1;
- /*
- * if source connection points and destination connection
- * points are same then return it false and don't draw that
- * relation
- */
- if ( $this->srcConnPointsRight == $this->destConnPointsRight) {
- if ( $this->srcConnPointsLeft == $this->destConnPointsLeft) {
- return false;
- }
- }
-
- if ($changeColor) {
- $listOfColors = array(
- 'FF0000',
- '000099',
- '00FF00'
- );
- shuffle($listOfColors);
- $this->referenceColor = '#' . $listOfColors[0] . '';
- } else {
- $this->referenceColor = '#000000';
- }
-
- $dia->writeRaw(
- '
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #1#
-
-
- #n#
-
-
-
-
-
-
-
-
-
-
-
- '
- );
- }
-}
-
-/**
- * Dia Relation Schema Class
- *
- * Purpose of this class is to generate the Dia XML Document
- * which is used for representing the database diagrams in Dia IDE
- * This class uses Database Table and Reference Objects of Dia and with
- * the combination of these objects actually helps in preparing Dia XML.
- *
- * Dia XML is generated by using XMLWriter php extension and this class
- * inherits Export_Relation_Schema class has common functionality added
- * to this class
- *
- * @package PhpMyAdmin
- * @name Dia_Relation_Schema
- */
-class PMA_Dia_Relation_Schema extends PMA_Export_Relation_Schema
-{
- /**
- * Defines properties
- */
- private $_tables = array();
- private $_relations = array();
- private $_topMargin = 2.8222000598907471;
- private $_bottomMargin = 2.8222000598907471;
- private $_leftMargin = 2.8222000598907471;
- private $_rightMargin = 2.8222000598907471;
- public static $objectId = 0;
-
- /**
- * The "PMA_Dia_Relation_Schema" constructor
- *
- * Upon instantiation This outputs the Dia XML document
- * that user can download
- *
- * @see PMA_DIA,Table_Stats_Dia,Relation_Stats_Dia
- */
- function __construct()
- {
- global $dia,$db;
-
- $this->setPageNumber($_POST['pdf_page_number']);
- $this->setShowGrid(isset($_POST['show_grid']));
- $this->setShowColor($_POST['show_color']);
- $this->setShowKeys(isset($_POST['show_keys']));
- $this->setOrientation(isset($_POST['orientation']));
- $this->setPaper($_POST['paper']);
- $this->setExportType($_POST['export_type']);
- $this->setOffline($_POST['offline_export']);
-
- $dia = new PMA_DIA();
- $dia->startDiaDoc(
- $this->paper, $this->_topMargin, $this->_bottomMargin,
- $this->_leftMargin, $this->_rightMargin, $this->orientation
- );
-
- if ($this->isOffline()) {
- $alltables = array();
- $tbl_coords = json_decode($GLOBALS['tbl_coords']);
- foreach ($tbl_coords as $tbl) {
- $alltables[] = $tbl->table_name;
- }
- } else {
- $alltables = $this->getAllTables($db, $this->pageNumber);
- }
-
- foreach ($alltables as $table) {
- if (! isset($this->tables[$table])) {
- $this->_tables[$table] = new Table_Stats_Dia(
- $table, $this->pageNumber, $this->showKeys, $this->isOffline()
- );
- }
- }
-
- $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 ($master_field != 'foreign_keys_data') {
- if (in_array($rel['foreign_table'], $alltables)) {
- $this->_addRelation(
- $one_table, $master_field, $rel['foreign_table'],
- $rel['foreign_field'], $this->showKeys
- );
- }
- } else {
- foreach ($rel as $key => $one_key) {
- if (in_array($one_key['ref_table_name'], $alltables)) {
- foreach ($one_key['index_list'] as $index => $one_field) {
- $this->_addRelation(
- $one_table, $one_field, $one_key['ref_table_name'],
- $one_key['ref_index_list'][$index], $this->showKeys
- );
- }
- }
- }
- }
- }
- }
- }
- $this->_drawTables($this->showColor);
-
- if ($seen_a_relation) {
- $this->_drawRelations($this->showColor);
- }
- $dia->endDiaDoc();
- }
-
- /**
- * Output Dia Document for download
- *
- * @return void
- * @access public
- */
- function showOutput()
- {
- global $dia, $db;
- $filename = $db . '-' . $this->pageNumber;
- if ($this->isOffline()) {
- $filename = __("Dia export page");
- }
- $dia->showOutput($filename);
- }
-
- /**
- * Defines relation objects
- *
- * @param string $masterTable The master table name
- * @param string $masterField The relation field in the master table
- * @param string $foreignTable The foreign table name
- * @param string $foreignField The relation field in the foreign table
- * @param bool $showKeys Whether to display ONLY keys or not
- *
- * @return void
- *
- * @access private
- * @see Table_Stats_Dia::__construct(),Relation_Stats_Dia::__construct()
- */
- private function _addRelation($masterTable, $masterField, $foreignTable,
- $foreignField, $showKeys
- ) {
- if (! isset($this->_tables[$masterTable])) {
- $this->_tables[$masterTable] = new Table_Stats_Dia(
- $masterTable, $this->pageNumber, $showKeys
- );
- }
- if (! isset($this->_tables[$foreignTable])) {
- $this->_tables[$foreignTable] = new Table_Stats_Dia(
- $foreignTable, $this->pageNumber, $showKeys
- );
- }
- $this->_relations[] = new Relation_Stats_Dia(
- $this->_tables[$masterTable], $masterField,
- $this->_tables[$foreignTable], $foreignField
- );
- }
-
- /**
- * Draws relation references
- *
- * connects master table's master field to
- * foreign table's forein field using Dia object
- * type Database - Reference
- *
- * @param boolean $changeColor Whether to use one color per relation or not
- *
- * @return void
- *
- * @access private
- * @see Relation_Stats_Dia::relationDraw()
- */
- private function _drawRelations($changeColor)
- {
- foreach ($this->_relations as $relation) {
- $relation->relationDraw($changeColor);
- }
- }
-
- /**
- * Draws tables
- *
- * Tables are generated using Dia object type Database - Table
- * primary fields are underlined and bold in tables
- *
- * @param boolean $changeColor Whether to show color for tables text or not
- *
- * @return void
- *
- * @access private
- * @see Table_Stats_Dia::tableDraw()
- */
- private function _drawTables($changeColor)
- {
- foreach ($this->_tables as $table) {
- $table->tableDraw($changeColor);
- }
- }
-}
-?>
diff --git a/pmd_general.php b/pmd_general.php
index 710ad1f328..3d6b81f834 100644
--- a/pmd_general.php
+++ b/pmd_general.php
@@ -31,6 +31,7 @@ if (isset($_REQUEST['dialog'])) {
} else if ($_REQUEST['dialog'] == 'save_as') {
$html = PMA_getHtmlForPageSaveAs($GLOBALS['db']);
} else if ($_REQUEST['dialog'] == 'export') {
+ include_once 'libraries/plugin_interface.lib.php';
$html = PMA_getHtmlForSchemaExport($GLOBALS['db'], $_REQUEST['selected_page']);
}
diff --git a/schema_export.php b/schema_export.php
index 9811d5e3c4..905c42ecd1 100644
--- a/schema_export.php
+++ b/schema_export.php
@@ -18,10 +18,9 @@ require 'libraries/StorageEngine.class.php';
*/
$cfgRelation = PMA_getRelationsParam();
-require_once 'libraries/transformations.lib.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/pmd_common.php';
-require_once 'libraries/schema/Export_Relation_Schema.class.php';
+require_once 'libraries/plugin_interface.lib.php';
/**
* get all the export options and verify
@@ -30,37 +29,26 @@ require_once 'libraries/schema/Export_Relation_Schema.class.php';
*/
$post_params = array(
- 'all_tables_same_width',
- 'chpage',
'db',
- 'export_type',
- 'orientation',
- 'paper',
- 'names',
- 'show_color',
- 'show_grid',
- 'show_keys',
- 'show_table_dimension',
- 'with_doc',
- 'offline_export',
- 'tbl_coords'
+ 'pdf_with_doc',
+ 'pdf_orientation',
+ 'pdf_paper'
);
foreach ($post_params as $one_post_param) {
if (isset($_REQUEST[$one_post_param])) {
$GLOBALS[$one_post_param] = $_REQUEST[$one_post_param];
- $_POST[$one_post_param] = $_REQUEST[$one_post_param];
}
}
-if ($_POST['offline_export'] === "on") {
- $_POST['pdf_page_number'] = -1;
- PMA_processExportSchema();
+if (isset($_REQUEST['offline_export'])) {
+ $_REQUEST['page_number'] = -1;
+ PMA_processExportSchema($_REQUEST['export_type']);
} else {
$temp_page = PMA_createNewPage("_temp" . rand(), $GLOBALS['db']);
try {
PMA_saveTablePositions($temp_page);
- $_POST['pdf_page_number'] = $temp_page;
- PMA_processExportSchema();
+ $_REQUEST['page_number'] = $temp_page;
+ PMA_processExportSchema($_REQUEST['export_type']);
PMA_deletePage($temp_page);
} catch (Exception $e) {
PMA_deletePage($temp_page); // delete temp page even if an exception occured
@@ -72,40 +60,35 @@ if ($_POST['offline_export'] === "on") {
* get all the export options and verify
* call and include the appropriate Schema Class depending on $export_type
*
+ * @param string $export_type format of the export
+ *
* @return void
*/
-function PMA_processExportSchema()
+function PMA_processExportSchema($export_type)
{
/**
* default is PDF, otherwise validate it's only letters a-z
*/
- global $db,$export_type;
-
if (! isset($export_type) || ! preg_match('/^[a-zA-Z]+$/', $export_type)) {
$export_type = 'pdf';
}
- $GLOBALS['dbi']->selectDb($db);
- $path = PMA_securePath(ucfirst($export_type));
- $filename = 'libraries/schema/' . $path . '_Relation_Schema.class.php';
- if (!file_exists($filename)) {
- PMA_Export_Relation_Schema::dieSchema(
- $_POST['chpage'],
- $export_type,
- __('File doesn\'t exist')
- );
+ // sanitize this parameter which will be used below in a file inclusion
+ $export_type = PMA_securePath($export_type);
+
+ // get the specific plugin
+ $export_plugin = PMA_getPlugin(
+ "Schema",
+ $export_type,
+ 'libraries/plugins/schema/'
+ );
+
+ // Check schema export type
+ if (! isset($export_plugin)) {
+ PMA_fatalError(__('Bad type!'));
}
- $GLOBALS['skip_import'] = false;
- include $filename;
- if ( $GLOBALS['skip_import']) {
- PMA_Export_Relation_Schema::dieSchema(
- $_POST['chpage'],
- $export_type,
- __('Plugin is disabled')
- );
- }
- $class_name = 'PMA_' . $path . '_Relation_Schema';
- $obj_schema = new $class_name();
- $obj_schema->showOutput();
+
+ $GLOBALS['dbi']->selectDb($GLOBALS['db']);
+ $export_plugin->exportSchema($GLOBALS['db']);
}
?>