diff --git a/libraries/schema/Dia_Relation_Schema.class.php b/libraries/schema/Dia_Relation_Schema.class.php
index 8309d08e3d..49051a6250 100644
--- a/libraries/schema/Dia_Relation_Schema.class.php
+++ b/libraries/schema/Dia_Relation_Schema.class.php
@@ -187,6 +187,8 @@ class PMA_DIA extends XMLWriter
}
}
+require_once './libraries/schema/TableStats.class.php';
+
/**
* Table preferences/statistics
*
@@ -197,15 +199,11 @@ class PMA_DIA extends XMLWriter
* @name Table_Stats_Dia
* @see PMA_DIA
*/
-class Table_Stats_Dia
+class Table_Stats_Dia extends TableStats
{
/**
* Defines properties
*/
- public $tableName;
- public $fields = array();
- public $x, $y;
- public $primary = array();
public $tableId;
public $tableColor;
@@ -226,80 +224,8 @@ class Table_Stats_Dia
function __construct($tableName, $pageNumber, $showKeys = false)
{
global $dia, $cfgRelation, $db;
+ parent::__construct($dia, $db, $pageNumber, $tableName, $showKeys, false);
- $this->tableName = $tableName;
- $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName);
- $result = $GLOBALS['dbi']->tryQuery(
- $sql, null, PMA_DatabaseInterface::QUERY_STORE
- );
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $dia->dieSchema(
- $pageNumber, "DIA",
- sprintf(__('The %s table doesn\'t exist!'), $tableName)
- );
- }
- /*
- * load fields
- * check to see if it will load all fields or only the foreign keys
- */
- if ($showKeys) {
- $indexes = PMA_Index::getFromTable($this->tableName, $db);
- $all_columns = array();
- foreach ($indexes as $index) {
- $all_columns = array_merge(
- $all_columns,
- array_flip(array_keys($index->getColumns()))
- );
- }
- $this->fields = array_keys($all_columns);
- } else {
- while ($row = $GLOBALS['dbi']->fetchRow($result)) {
- $this->fields[] = $row[0];
- }
- }
-
- $sql = 'SELECT x, y FROM '
- . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
- . PMA_Util::backquote($cfgRelation['table_coords'])
- . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
- . ' AND table_name = \''
- . PMA_Util::sqlAddSlashes($tableName) . '\''
- . ' AND pdf_page_number = ' . $pageNumber;
- $result = PMA_queryAsControlUser(
- $sql, false, PMA_DatabaseInterface::QUERY_STORE
- );
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $dia->dieSchema(
- $pageNumber,
- "DIA",
- sprintf(
- __('Please configure the coordinates for table %s'),
- $tableName
- )
- );
- }
- list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result);
- $this->x = (double) $this->x;
- $this->y = (double) $this->y;
- /*
- * displayfield
- */
- $this->displayfield = PMA_getDisplayField($db, $tableName);
- /*
- * index
- */
- $result = $GLOBALS['dbi']->query(
- 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';',
- null,
- PMA_DatabaseInterface::QUERY_STORE
- );
- if ($GLOBALS['dbi']->numRows($result) > 0) {
- while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
- if ($row['Key_name'] == 'PRIMARY') {
- $this->primary[] = $row['Column_name'];
- }
- }
- }
/**
* Every object in Dia document needs an ID to identify
* so, we used a static variable to keep the things unique
@@ -308,6 +234,38 @@ class Table_Stats_Dia
$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
*
diff --git a/libraries/schema/Eps_Relation_Schema.class.php b/libraries/schema/Eps_Relation_Schema.class.php
index f32102d039..f0480f9e22 100644
--- a/libraries/schema/Eps_Relation_Schema.class.php
+++ b/libraries/schema/Eps_Relation_Schema.class.php
@@ -297,6 +297,8 @@ class PMA_EPS
}
}
+require_once './libraries/schema/TableStats.class.php';
+
/**
* Table preferences/statistics
*
@@ -307,22 +309,13 @@ class PMA_EPS
* @name Table_Stats_Eps
* @see PMA_EPS
*/
-class Table_Stats_Eps
+class Table_Stats_Eps extends TableStats
{
/**
* Defines properties
*/
-
- private $_tableName;
- private $_showInfo = false;
-
- public $width = 0;
public $height;
- public $fields = array();
- public $heightCell = 0;
public $currentCell = 0;
- public $x, $y;
- public $primary = array();
/**
* The "Table_Stats_Eps" constructor
@@ -350,103 +343,49 @@ class Table_Stats_Eps
$showKeys = false, $showInfo = false
) {
global $eps, $cfgRelation, $db;
-
- $this->_tableName = $tableName;
- $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName);
- $result = $GLOBALS['dbi']->tryQuery(
- $sql, null, PMA_DatabaseInterface::QUERY_STORE
+ parent::__construct(
+ $eps, $db, $pageNumber, $tableName, $showKeys, $showInfo
);
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $eps->dieSchema(
- $pageNumber, "EPS",
- sprintf(__('The %s table doesn\'t exist!'), $tableName)
- );
- }
-
- /*
- * load fields
- * check to see if it will load all fields or only the foreign keys
- */
- if ($showKeys) {
- $indexes = PMA_Index::getFromTable($this->_tableName, $db);
- $all_columns = array();
- foreach ($indexes as $index) {
- $all_columns = array_merge(
- $all_columns,
- array_flip(array_keys($index->getColumns()))
- );
- }
- $this->fields = array_keys($all_columns);
- } else {
- while ($row = $GLOBALS['dbi']->fetchRow($result)) {
- $this->fields[] = $row[0];
- }
- }
-
- $this->_showInfo = $showInfo;
// height and width
$this->_setHeightTable($fontSize);
-
// setWidth must me after setHeight, because title
// can include table height which changes table width
$this->_setWidthTable($font, $fontSize);
if ($same_wide_width < $this->width) {
$same_wide_width = $this->width;
}
-
- // x and y
- $sql = 'SELECT x, y FROM '
- . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
- . PMA_Util::backquote($cfgRelation['table_coords'])
- . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
- . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($tableName) . '\''
- . ' AND pdf_page_number = ' . $pageNumber;
- $result = PMA_queryAsControlUser(
- $sql, false, PMA_DatabaseInterface::QUERY_STORE
- );
-
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $eps->dieSchema(
- $pageNumber, "EPS",
- sprintf(
- __('Please configure the coordinates for table %s'),
- $tableName
- )
- );
- }
- list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result);
- $this->x = (double) $this->x;
- $this->y = (double) $this->y;
- // displayfield
- $this->displayfield = PMA_getDisplayField($db, $tableName);
- // index
- $result = $GLOBALS['dbi']->query(
- 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';',
- null, PMA_DatabaseInterface::QUERY_STORE
- );
- if ($GLOBALS['dbi']->numRows($result) > 0) {
- while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
- if ($row['Key_name'] == 'PRIMARY') {
- $this->primary[] = $row['Column_name'];
- }
- }
- }
}
/**
- * Returns title of the current table,
- * title can have the dimensions/co-ordinates of the table
+ * Displays an error when the table cannot be found.
*
- * @return string The relation/table name
- * @access private
+ * @return void
*/
- private function _getTitle()
+ protected function showMissingTableError()
{
- return ($this->_showInfo
- ? sprintf('%.0f', $this->width) . 'x'
- . sprintf('%.0f', $this->heightCell)
- : '') . ' ' . $this->_tableName;
+ $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
+ )
+ );
}
/**
@@ -476,7 +415,7 @@ class Table_Stats_Eps
* table title is affected by the tabe width value
*/
while ($this->width
- < PMA_Font::getStringWidth($this->_getTitle(), $font, $fontSize)) {
+ < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)) {
$this->width += 7;
}
}
@@ -510,9 +449,9 @@ class Table_Stats_Eps
public function tableDraw($showColor)
{
global $eps;
- //echo $this->_tableName.'
';
+ //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);
+ $eps->showXY($this->getTitle(), $this->x + 5, $this->y + 14);
foreach ($this->fields as $field) {
$this->currentCell += $this->heightCell;
$showColor = 'none';
diff --git a/libraries/schema/Pdf_Relation_Schema.class.php b/libraries/schema/Pdf_Relation_Schema.class.php
index 93def6ebb0..cb4e2bffe6 100644
--- a/libraries/schema/Pdf_Relation_Schema.class.php
+++ b/libraries/schema/Pdf_Relation_Schema.class.php
@@ -358,6 +358,8 @@ class PMA_Schema_PDF extends PMA_PDF
}
}
+require_once './libraries/schema/TableStats.class.php';
+
/**
* Table preferences/statistics
*
@@ -368,21 +370,13 @@ class PMA_Schema_PDF extends PMA_PDF
* @package PhpMyAdmin
* @see PMA_Schema_PDF
*/
-class Table_Stats_Pdf
+class Table_Stats_Pdf extends TableStats
{
/**
* Defines properties
*/
- private $_tableName;
- private $_showInfo = false;
-
public $nb_fiels;
- public $width = 0;
public $height;
- public $fields = array();
- public $heightCell = 6;
- public $x, $y;
- public $primary = array();
private $_ff = PMA_PDF_FONT;
/**
@@ -407,34 +401,11 @@ class Table_Stats_Pdf
$showKeys = false, $showInfo = false
) {
global $pdf, $cfgRelation, $db;
-
- $this->_tableName = $tableName;
- $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName);
- $result = $GLOBALS['dbi']->tryQuery(
- $sql, null, PMA_DatabaseInterface::QUERY_STORE
+ parent::__construct(
+ $pdf, $db, $pageNumber, $tableName, $showKeys, $showInfo
);
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $pdf->Error(sprintf(__('The %s table doesn\'t exist!'), $tableName));
- }
- // load fields
- //check to see if it will load all fields or only the foreign keys
- if ($showKeys) {
- $indexes = PMA_Index::getFromTable($this->_tableName, $db);
- $all_columns = array();
- foreach ($indexes as $index) {
- $all_columns = array_merge(
- $all_columns,
- array_flip(array_keys($index->getColumns()))
- );
- }
- $this->fields = array_keys($all_columns);
- } else {
- while ($row = $GLOBALS['dbi']->fetchRow($result)) {
- $this->fields[] = $row[0];
- }
- }
- $this->_showInfo = $showInfo;
+ $this->heightCell = 6;
$this->_setHeight();
/*
* setWidth must me after setHeight, because title
@@ -444,44 +415,37 @@ class Table_Stats_Pdf
if ($sameWideWidth < $this->width) {
$sameWideWidth = $this->width;
}
- $sql = 'SELECT x, y FROM '
- . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
- . PMA_Util::backquote($cfgRelation['table_coords'])
- . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
- . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($tableName) . '\''
- . ' AND pdf_page_number = ' . $pageNumber;
- $result = PMA_queryAsControlUser(
- $sql, false, PMA_DatabaseInterface::QUERY_STORE
+ }
+
+ /**
+ * 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)
);
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $pdf->Error(
- sprintf(
- __('Please configure the coordinates for table %s'),
- $tableName
- )
- );
- }
- list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result);
- $this->x = (double) $this->x;
- $this->y = (double) $this->y;
- /*
- * displayfield
- */
- $this->displayfield = PMA_getDisplayField($db, $tableName);
- /*
- * index
- */
- $result = $GLOBALS['dbi']->query(
- 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';',
- null, PMA_DatabaseInterface::QUERY_STORE
+ }
+
+ /**
+ * 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
+ )
);
- if ($GLOBALS['dbi']->numRows($result) > 0) {
- while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
- if ($row['Key_name'] == 'PRIMARY') {
- $this->primary[] = $row['Column_name'];
- }
- }
- }
}
/**
@@ -490,13 +454,13 @@ class Table_Stats_Pdf
*
* @return string
*/
- private function _getTitle()
+ protected function getTitle()
{
$ret = '';
- if ($this->_showInfo) {
+ if ($this->showInfo) {
$ret = sprintf('%.0fx%0.f', $this->width, $this->height);
}
- return $ret . ' ' . $this->_tableName;
+ return $ret . ' ' . $this->tableName;
}
/**
@@ -525,7 +489,7 @@ class Table_Stats_Pdf
* 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())) {
+ while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
$this->width += 5;
}
$pdf->SetFont($this->_ff, '', $fontSize);
@@ -569,20 +533,20 @@ class Table_Stats_Pdf
$pdf->SetFillColor(0, 0, 128);
}
if ($withDoc) {
- $pdf->SetLink($pdf->PMA_links['RT'][$this->_tableName]['-'], -1);
+ $pdf->SetLink($pdf->PMA_links['RT'][$this->tableName]['-'], -1);
} else {
- $pdf->PMA_links['doc'][$this->_tableName]['-'] = '';
+ $pdf->PMA_links['doc'][$this->tableName]['-'] = '';
}
$pdf->cellScale(
$this->width,
$this->heightCell,
- $this->_getTitle(),
+ $this->getTitle(),
1,
1,
'C',
$setColor,
- $pdf->PMA_links['doc'][$this->_tableName]['-']
+ $pdf->PMA_links['doc'][$this->tableName]['-']
);
$pdf->setXScale($this->x);
$pdf->SetFont($this->_ff, '', $fontSize);
@@ -599,9 +563,9 @@ class Table_Stats_Pdf
}
}
if ($withDoc) {
- $pdf->SetLink($pdf->PMA_links['RT'][$this->_tableName][$field], -1);
+ $pdf->SetLink($pdf->PMA_links['RT'][$this->tableName][$field], -1);
} else {
- $pdf->PMA_links['doc'][$this->_tableName][$field] = '';
+ $pdf->PMA_links['doc'][$this->tableName][$field] = '';
}
$pdf->cellScale(
@@ -612,7 +576,7 @@ class Table_Stats_Pdf
1,
'L',
$setColor,
- $pdf->PMA_links['doc'][$this->_tableName][$field]
+ $pdf->PMA_links['doc'][$this->tableName][$field]
);
$pdf->setXScale($this->x);
$pdf->SetFillColor(255);
diff --git a/libraries/schema/Svg_Relation_Schema.class.php b/libraries/schema/Svg_Relation_Schema.class.php
index 72b5ffc6fa..4cb0b9f19a 100644
--- a/libraries/schema/Svg_Relation_Schema.class.php
+++ b/libraries/schema/Svg_Relation_Schema.class.php
@@ -263,6 +263,8 @@ class PMA_SVG extends XMLWriter
}
}
+require_once './libraries/schema/TableStats.class.php';
+
/**
* Table preferences/statistics
*
@@ -273,22 +275,13 @@ class PMA_SVG extends XMLWriter
* @name Table_Stats_Svg
* @see PMA_SVG
*/
-class Table_Stats_Svg
+class Table_Stats_Svg extends TableStats
{
/**
* Defines properties
*/
-
- private $_tableName;
- private $_showInfo = false;
-
- public $width = 0;
public $height;
- public $fields = array();
- public $heightCell = 0;
public $currentCell = 0;
- public $x, $y;
- public $primary = array();
/**
* The "Table_Stats_Svg" constructor
@@ -317,108 +310,49 @@ class Table_Stats_Svg
&$same_wide_width, $showKeys = false, $showInfo = false
) {
global $svg, $cfgRelation, $db;
-
- $this->_tableName = $tableName;
- $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName);
- $result = $GLOBALS['dbi']->tryQuery(
- $sql, null, PMA_DatabaseInterface::QUERY_STORE
+ parent::__construct(
+ $svg, $db, $pageNumber, $tableName, $showKeys, $showInfo
);
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $svg->dieSchema(
- $pageNumber,
- "SVG",
- sprintf(__('The %s table doesn\'t exist!'), $tableName)
- );
- }
-
- /*
- * load fields
- * check to see if it will load all fields or only the foreign keys
- */
-
- if ($showKeys) {
- $indexes = PMA_Index::getFromTable($this->_tableName, $db);
- $all_columns = array();
- foreach ($indexes as $index) {
- $all_columns = array_merge(
- $all_columns,
- array_flip(array_keys($index->getColumns()))
- );
- }
- $this->fields = array_keys($all_columns);
- } else {
- while ($row = $GLOBALS['dbi']->fetchRow($result)) {
- $this->fields[] = $row[0];
- }
- }
-
- $this->_showInfo = $showInfo;
// height and width
$this->_setHeightTable($fontSize);
-
// setWidth must me after setHeight, because title
// can include table height which changes table width
$this->_setWidthTable($font, $fontSize);
if ($same_wide_width < $this->width) {
$same_wide_width = $this->width;
}
-
- // x and y
- $sql = 'SELECT x, y FROM '
- . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
- . PMA_Util::backquote($cfgRelation['table_coords'])
- . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
- . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($tableName) . '\''
- . ' AND pdf_page_number = ' . $pageNumber;
- $result = PMA_queryAsControlUser(
- $sql, false, PMA_DatabaseInterface::QUERY_STORE
- );
-
- if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
- $svg->dieSchema(
- $pageNumber,
- "SVG",
- sprintf(
- __('Please configure the coordinates for table %s'),
- $tableName
- )
- );
- }
- list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result);
- $this->x = (double) $this->x;
- $this->y = (double) $this->y;
- // displayfield
- $this->displayfield = PMA_getDisplayField($db, $tableName);
- // index
- $result = $GLOBALS['dbi']->query(
- 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';',
- null,
- PMA_DatabaseInterface::QUERY_STORE
- );
- if ($GLOBALS['dbi']->numRows($result) > 0) {
- while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
- if ($row['Key_name'] == 'PRIMARY') {
- $this->primary[] = $row['Column_name'];
- }
- }
- }
}
/**
- * Returns title of the current table,
- * title can have the dimensions/co-ordinates of the table
+ * Displays an error when the table cannot be found.
*
- * @return string title of the current table
- * @access private
+ * @return void
*/
- private function _getTitle()
+ protected function showMissingTableError()
{
- return ($this->_showInfo
- ? sprintf('%.0f', $this->width) . 'x'
- . sprintf('%.0f', $this->heightCell)
- : ''
- ) . ' ' . $this->_tableName;
+ $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
+ )
+ );
}
/**
@@ -449,7 +383,7 @@ class Table_Stats_Svg
* table title is affected by the tabe width value
*/
while ($this->width
- < PMA_Font::getStringWidth($this->_getTitle(), $font, $fontSize)
+ < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)
) {
$this->width += 7;
}
@@ -484,14 +418,14 @@ class Table_Stats_Svg
public function tableDraw($showColor)
{
global $svg;
- //echo $this->_tableName.'
';
+ //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;'
+ $this->getTitle(), 'fill:none;stroke:black;'
);
foreach ($this->fields as $field) {
$this->currentCell += $this->heightCell;
diff --git a/libraries/schema/TableStats.class.php b/libraries/schema/TableStats.class.php
new file mode 100644
index 0000000000..a59366b24d
--- /dev/null
+++ b/libraries/schema/TableStats.class.php
@@ -0,0 +1,191 @@
+diagram = $diagram;
+ $this->db = $db;
+ $this->pageNumber = $pageNumber;
+ $this->tableName = $tableName;
+
+ $this->showKeys = $showKeys;
+ $this->showInfo = $showInfo;
+
+ // checks whether the table exists
+ // and loads fields
+ $this->validateTableAndLoadFields();
+ // load table coordinates
+ $this->loadCoordinates();
+ // loads display field
+ $this->loadDisplayField();
+ // loads primary keys
+ $this->loadPrimaryKey();
+ }
+
+ /**
+ * Validate whether the table exists.
+ *
+ * @return void
+ */
+ protected function validateTableAndLoadFields()
+ {
+ $sql = 'DESCRIBE ' . PMA_Util::backquote($this->tableName);
+ $result = $GLOBALS['dbi']->tryQuery(
+ $sql, null, PMA_DatabaseInterface::QUERY_STORE
+ );
+ if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
+ $this->showMissingTableError();
+ }
+
+ if ($this->showKeys) {
+ $indexes = PMA_Index::getFromTable($this->tableName, $this->db);
+ $all_columns = array();
+ foreach ($indexes as $index) {
+ $all_columns = array_merge(
+ $all_columns,
+ array_flip(array_keys($index->getColumns()))
+ );
+ }
+ $this->fields = array_keys($all_columns);
+ } else {
+ while ($row = $GLOBALS['dbi']->fetchRow($result)) {
+ $this->fields[] = $row[0];
+ }
+ }
+ }
+
+ /**
+ * Displays an error when the table cannot be found.
+ *
+ * @return void
+ * @abstract
+ */
+ protected abstract function showMissingTableError();
+
+ /**
+ * Loads coordinates of a table
+ *
+ * @return void
+ */
+ protected function loadCoordinates()
+ {
+ global $cfgRelation;
+
+ $sql = "SELECT x, y FROM "
+ . 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;
+ $result = PMA_queryAsControlUser(
+ $sql, false, PMA_DatabaseInterface::QUERY_STORE
+ );
+ if (! $result || ! $GLOBALS['dbi']->numRows($result)) {
+ $this->showMissingCoordinatesError();
+ }
+ list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result);
+ $this->x = (double) $this->x;
+ $this->y = (double) $this->y;
+ }
+
+ /**
+ * Displays an error on missing coordinates
+ *
+ * @return void
+ * @abstract
+ */
+ protected abstract function showMissingCoordinatesError();
+
+ /**
+ * Loads the table's display field
+ *
+ * @return void
+ */
+ protected function loadDisplayField()
+ {
+ $this->displayfield = PMA_getDisplayField($this->db, $this->tableName);
+ }
+
+ /**
+ * Loads the PRIMARY key.
+ *
+ * @return void
+ */
+ protected function loadPrimaryKey()
+ {
+ $result = $GLOBALS['dbi']->query(
+ 'SHOW INDEX FROM ' . PMA_Util::backquote($this->tableName) . ';',
+ null, PMA_DatabaseInterface::QUERY_STORE
+ );
+ if ($GLOBALS['dbi']->numRows($result) > 0) {
+ while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
+ if ($row['Key_name'] == 'PRIMARY') {
+ $this->primary[] = $row['Column_name'];
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns title of the current table,
+ * title can have the dimensions/co-ordinates of the table
+ *
+ * @return string title of the current table
+ */
+ protected function getTitle()
+ {
+ return ($this->showInfo
+ ? sprintf('%.0fx%0.f', $this->width, $this->heightCell)
+ : ''
+ )
+ . ' ' . $this->tableName;
+ }
+}
+?>
\ No newline at end of file