2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 if (! defined('PHPMYADMIN')) {
12 require_once 'Export_Relation_Schema.class.php';
13 require_once './libraries/PDF.class.php';
16 * Extends the "TCPDF" class and helps
17 * in developing the structure of PDF Schema Export
23 class PMA_Schema_PDF
extends PMA_PDF
34 var $Outlines = array();
37 private $_ff = PMA_PDF_FONT
;
40 * Sets the value for margins
42 * @param float $c_margin margin
46 public function setCMargin($c_margin)
48 $this->cMargin
= $c_margin;
52 * Sets the scaling factor, defines minimum coordinates and margins
54 * @param float $scale The scaling factor
55 * @param float $xMin The minimum X coordinate
56 * @param float $yMin The minimum Y coordinate
57 * @param float $leftMargin The left margin
58 * @param float $topMargin The top margin
64 function setScale($scale = 1, $xMin = 0, $yMin = 0,
65 $leftMargin = -1, $topMargin = -1
67 $this->scale
= $scale;
70 if ($this->leftMargin
!= -1) {
71 $this->leftMargin
= $leftMargin;
73 if ($this->topMargin
!= -1) {
74 $this->topMargin
= $topMargin;
79 * Outputs a scaled cell
81 * @param float $w The cell width
82 * @param float $h The cell height
83 * @param string $txt The text to output
84 * @param mixed $border Whether to add borders or not
85 * @param integer $ln Where to put the cursor once the output is done
86 * @param string $align Align mode
87 * @param integer $fill Whether to fill the cell with a color or not
88 * @param string $link Link
96 function cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0,
97 $align = '', $fill = 0, $link = ''
99 $h = $h / $this->scale
;
100 $w = $w / $this->scale
;
101 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
105 * Draws a scaled line
107 * @param float $x1 The horizontal position of the starting point
108 * @param float $y1 The vertical position of the starting point
109 * @param float $x2 The horizontal position of the ending point
110 * @param float $y2 The vertical position of the ending point
118 function lineScale($x1, $y1, $x2, $y2)
120 $x1 = ($x1 - $this->_xMin
) / $this->scale +
$this->leftMargin
;
121 $y1 = ($y1 - $this->_yMin
) / $this->scale +
$this->topMargin
;
122 $x2 = ($x2 - $this->_xMin
) / $this->scale +
$this->leftMargin
;
123 $y2 = ($y2 - $this->_yMin
) / $this->scale +
$this->topMargin
;
124 $this->Line($x1, $y1, $x2, $y2);
128 * Sets x and y scaled positions
130 * @param float $x The x position
131 * @param float $y The y position
137 * @see TCPDF::SetXY()
139 function setXyScale($x, $y)
141 $x = ($x - $this->_xMin
) / $this->scale +
$this->leftMargin
;
142 $y = ($y - $this->_yMin
) / $this->scale +
$this->topMargin
;
143 $this->SetXY($x, $y);
147 * Sets the X scaled positions
149 * @param float $x The x position
157 function setXScale($x)
159 $x = ($x - $this->_xMin
) / $this->scale +
$this->leftMargin
;
164 * Sets the scaled font size
166 * @param float $size The font size (in points)
172 * @see TCPDF::SetFontSize()
174 function setFontSizeScale($size)
176 // Set font size in points
177 $size = $size / $this->scale
;
178 $this->SetFontSize($size);
182 * Sets the scaled line width
184 * @param float $width The line width
190 * @see TCPDF::SetLineWidth()
192 function setLineWidthScale($width)
194 $width = $width / $this->scale
;
195 $this->SetLineWidth($width);
199 * This method is used to render the page header.
203 * @see TCPDF::Header()
207 // We only show this if we find something in the new pdf_pages table
209 // This function must be named "Header" to work with the TCPDF library
210 global $cfgRelation, $db, $pdf_page_number, $with_doc;
212 $test_query = 'SELECT * FROM '
213 . PMA_Util
::backquote($GLOBALS['cfgRelation']['db']) . '.'
214 . PMA_Util
::backquote($cfgRelation['pdf_pages'])
215 . ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($db) . '\''
216 . ' AND page_nr = \'' . $pdf_page_number . '\'';
217 $test_rs = PMA_queryAsControlUser($test_query);
218 $pages = @PMA_DBI_fetch_assoc
($test_rs);
219 $this->SetFont($this->_ff
, 'B', 14);
220 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
221 $this->SetFont($this->_ff
, '');
227 * This function must be named "Footer" to work with the TCPDF library
231 * @see PMA_PDF::Footer()
244 * @param array $w array of widths
248 function SetWidths($w)
255 * Generates table row.
257 * @param array $data Data for table
258 * @param array $links Links for table cells
262 function Row($data, $links)
266 $data_cnt = count($data);
267 for ($i = 0;$i < $data_cnt;$i++
) {
268 $nb = max($nb, $this->NbLines($this->widths
[$i], $data[$i]));
270 $il = $this->FontSize
;
271 $h = ($il +
1) * $nb;
272 // page break if necessary
273 $this->CheckPageBreak($h);
275 $data_cnt = count($data);
276 for ($i = 0;$i < $data_cnt;$i++
) {
277 $w = $this->widths
[$i];
278 // save current position
282 $this->Rect($x, $y, $w, $h);
283 if (isset($links[$i])) {
284 $this->Link($x, $y, $w, $h, $links[$i]);
287 $this->MultiCell($w, $il +
1, $data[$i], 0, 'L');
289 $this->SetXY($x +
$w, $y);
296 * Compute number of lines used by a multicell of width w
298 * @param int $w width
299 * @param string $txt text
303 function NbLines($w, $txt)
305 $cw = &$this->CurrentFont
['cw'];
307 $w = $this->w
- $this->rMargin
- $this->x
;
309 $wmax = ($w-2 * $this->cMargin
) * 1000 / $this->FontSize
;
310 $s = str_replace("\r", '', $txt);
312 if ($nb > 0 and $s[$nb-1] == "\n") {
333 $l +
= isset($cw[ord($c)])?
$cw[ord($c)]:0 ;
355 * Table preferences/statistics
357 * This class preserves the table co-ordinates,fields
358 * and helps in drawing/generating the Tables in PDF document.
361 * @package PhpMyAdmin
362 * @see PMA_Schema_PDF
370 private $_showInfo = false;
375 public $fields = array();
376 public $heightCell = 6;
378 public $primary = array();
379 private $_ff = PMA_PDF_FONT
;
382 * The "Table_Stats" constructor
384 * @param string $tableName The table name
385 * @param integer $fontSize The font size
386 * @param integer $pageNumber The current page number (from the
387 * $cfg['Servers'][$i]['table_coords'] table)
388 * @param integer &$sameWideWidth The max. with among tables
389 * @param boolean $showKeys Whether to display keys or not
390 * @param boolean $showInfo Whether to display table position or not
392 * @global object The current PDF document
393 * @global array The relations settings
394 * @global string The current db name
398 * @see PMA_Schema_PDF, Table_Stats::Table_Stats_setWidth,
399 * Table_Stats::Table_Stats_setHeight
401 function __construct($tableName, $fontSize, $pageNumber, &$sameWideWidth,
402 $showKeys = false, $showInfo = false
404 global $pdf, $cfgRelation, $db;
406 $this->_tableName
= $tableName;
407 $sql = 'DESCRIBE ' . PMA_Util
::backquote($tableName);
408 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE
);
409 if (! $result ||
! PMA_DBI_num_rows($result)) {
410 $pdf->Error(sprintf(__('The %s table doesn\'t exist!'), $tableName));
413 //check to see if it will load all fields or only the foreign keys
415 $indexes = PMA_Index
::getFromTable($this->_tableName
, $db);
416 $all_columns = array();
417 foreach ($indexes as $index) {
418 $all_columns = array_merge(
420 array_flip(array_keys($index->getColumns()))
423 $this->fields
= array_keys($all_columns);
425 while ($row = PMA_DBI_fetch_row($result)) {
426 $this->fields
[] = $row[0];
430 $this->_showInfo
= $showInfo;
433 * setWidth must me after setHeight, because title
434 * can include table height which changes table width
436 $this->_setWidth($fontSize);
437 if ($sameWideWidth < $this->width
) {
438 $sameWideWidth = $this->width
;
440 $sql = 'SELECT x, y FROM '
441 . PMA_Util
::backquote($GLOBALS['cfgRelation']['db']) . '.'
442 . PMA_Util
::backquote($cfgRelation['table_coords'])
443 . ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($db) . '\''
444 . ' AND table_name = \'' . PMA_Util
::sqlAddSlashes($tableName) . '\''
445 . ' AND pdf_page_number = ' . $pageNumber;
446 $result = PMA_queryAsControlUser($sql, false, PMA_DBI_QUERY_STORE
);
447 if (! $result ||
! PMA_DBI_num_rows($result)) {
450 __('Please configure the coordinates for table %s'),
455 list($this->x
, $this->y
) = PMA_DBI_fetch_row($result);
456 $this->x
= (double) $this->x
;
457 $this->y
= (double) $this->y
;
461 $this->displayfield
= PMA_getDisplayField($db, $tableName);
465 $result = PMA_DBI_query(
466 'SHOW INDEX FROM ' . PMA_Util
::backquote($tableName) . ';',
467 null, PMA_DBI_QUERY_STORE
469 if (PMA_DBI_num_rows($result) > 0) {
470 while ($row = PMA_DBI_fetch_assoc($result)) {
471 if ($row['Key_name'] == 'PRIMARY') {
472 $this->primary
[] = $row['Column_name'];
479 * Returns title of the current table,
480 * title can have the dimensions of the table
484 private function _getTitle()
487 if ($this->_showInfo
) {
488 $ret = sprintf('%.0fx%0.f', $this->width
, $this->height
);
490 return $ret . ' ' . $this->_tableName
;
494 * Sets the width of the table
496 * @param integer $fontSize The font size
498 * @global object The current PDF document
504 * @see PMA_Schema_PDF
506 private function _setWidth($fontSize)
510 foreach ($this->fields
as $field) {
511 $this->width
= max($this->width
, $pdf->GetStringWidth($field));
513 $this->width +
= $pdf->GetStringWidth(' ');
514 $pdf->SetFont($this->_ff
, 'B', $fontSize);
516 * it is unknown what value must be added, because
517 * table title is affected by the tabe width value
519 while ($this->width
< $pdf->GetStringWidth($this->_getTitle())) {
522 $pdf->SetFont($this->_ff
, '', $fontSize);
526 * Sets the height of the table
532 private function _setHeight()
534 $this->height
= (count($this->fields
) +
1) * $this->heightCell
;
540 * @param integer $fontSize The font size
541 * @param boolean $withDoc Whether to include links to documentation
542 * @param boolean $setColor Whether to display color
544 * @global object The current PDF document
550 * @see PMA_Schema_PDF
552 public function tableDraw($fontSize, $withDoc, $setColor = 0)
554 global $pdf, $withDoc;
556 $pdf->setXyScale($this->x
, $this->y
);
557 $pdf->SetFont($this->_ff
, 'B', $fontSize);
559 $pdf->SetTextColor(200);
560 $pdf->SetFillColor(0, 0, 128);
563 $pdf->SetLink($pdf->PMA_links
['RT'][$this->_tableName
]['-'], -1);
565 $pdf->PMA_links
['doc'][$this->_tableName
]['-'] = '';
576 $pdf->PMA_links
['doc'][$this->_tableName
]['-']
578 $pdf->setXScale($this->x
);
579 $pdf->SetFont($this->_ff
, '', $fontSize);
580 $pdf->SetTextColor(0);
581 $pdf->SetFillColor(255);
583 foreach ($this->fields
as $field) {
585 if (in_array($field, $this->primary
)) {
586 $pdf->SetFillColor(215, 121, 123);
588 if ($field == $this->displayfield
) {
589 $pdf->SetFillColor(142, 159, 224);
593 $pdf->SetLink($pdf->PMA_links
['RT'][$this->_tableName
][$field], -1);
595 $pdf->PMA_links
['doc'][$this->_tableName
][$field] = '';
606 $pdf->PMA_links
['doc'][$this->_tableName
][$field]
608 $pdf->setXScale($this->x
);
609 $pdf->SetFillColor(255);
615 * Relation preferences/statistics
617 * This class fetches the table master and foreign fields positions
618 * and helps in generating the Table references and then connects
619 * master table's master field to foreign table's foreign key
622 * @name Relation_Stats
623 * @package PhpMyAdmin
624 * @see PMA_Schema_PDF::SetDrawColor, PMA_Schema_PDF::setLineWidthScale,
625 * PMA_Schema_PDF::lineScale
635 public $xDest, $yDest;
639 * The "Relation_Stats" constructor
641 * @param string $master_table The master table name
642 * @param string $master_field The relation field in the master table
643 * @param string $foreign_table The foreign table name
644 * @param string $foreign_field The relation field in the foreign table
648 * @see Relation_Stats::_getXy
650 function __construct($master_table, $master_field, $foreign_table,
653 $src_pos = $this->_getXy($master_table, $master_field);
654 $dest_pos = $this->_getXy($foreign_table, $foreign_field);
660 $src_left = $src_pos[0] - $this->wTick
;
661 $src_right = $src_pos[1] +
$this->wTick
;
662 $dest_left = $dest_pos[0] - $this->wTick
;
663 $dest_right = $dest_pos[1] +
$this->wTick
;
665 $d1 = abs($src_left - $dest_left);
666 $d2 = abs($src_right - $dest_left);
667 $d3 = abs($src_left - $dest_right);
668 $d4 = abs($src_right - $dest_right);
669 $d = min($d1, $d2, $d3, $d4);
672 $this->xSrc
= $src_pos[0];
674 $this->xDest
= $dest_pos[0];
676 } elseif ($d == $d2) {
677 $this->xSrc
= $src_pos[1];
679 $this->xDest
= $dest_pos[0];
681 } elseif ($d == $d3) {
682 $this->xSrc
= $src_pos[0];
684 $this->xDest
= $dest_pos[1];
687 $this->xSrc
= $src_pos[1];
689 $this->xDest
= $dest_pos[1];
692 $this->ySrc
= $src_pos[2];
693 $this->yDest
= $dest_pos[2];
697 * Gets arrows coordinates
699 * @param string $table The current table name
700 * @param string $column The relation column name
702 * @return array Arrows coordinates
706 private function _getXy($table, $column)
708 $pos = array_search($column, $table->fields
);
709 // x_left, x_right, y
712 $table->x +
$table->width
,
713 $table->y +
($pos +
1.5) * $table->heightCell
718 * draws relation links and arrows shows foreign key relations
720 * @param boolean $changeColor Whether to use one color per relation or not
721 * @param integer $i The id of the link to draw
723 * @global object The current PDF document
729 * @see PMA_Schema_PDF
731 public function relationDraw($changeColor, $i)
748 list ($a, $b, $c) = $case[$d];
749 $e = (1 - ($j - 1) / 6);
750 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
752 $pdf->SetDrawColor(0);
754 $pdf->setLineWidthScale(0.2);
758 $this->xSrc +
$this->srcDir
* $this->wTick
,
762 $this->xDest +
$this->destDir
* $this->wTick
,
767 $pdf->setLineWidthScale(0.1);
769 $this->xSrc +
$this->srcDir
* $this->wTick
,
771 $this->xDest +
$this->destDir
* $this->wTick
,
777 $root2 = 2 * sqrt(2);
779 $this->xSrc +
$this->srcDir
* $this->wTick
* 0.75,
781 $this->xSrc +
$this->srcDir
* (0.75 - 1 / $root2) * $this->wTick
,
782 $this->ySrc +
$this->wTick
/ $root2
785 $this->xSrc +
$this->srcDir
* $this->wTick
* 0.75,
787 $this->xSrc +
$this->srcDir
* (0.75 - 1 / $root2) * $this->wTick
,
788 $this->ySrc
- $this->wTick
/ $root2
792 $this->xDest +
$this->destDir
* $this->wTick
/ 2,
794 $this->xDest +
$this->destDir
* (0.5 +
1 / $root2) * $this->wTick
,
795 $this->yDest +
$this->wTick
/ $root2
798 $this->xDest +
$this->destDir
* $this->wTick
/ 2,
800 $this->xDest +
$this->destDir
* (0.5 +
1 / $root2) * $this->wTick
,
801 $this->yDest
- $this->wTick
/ $root2
803 $pdf->SetDrawColor(0);
808 * Pdf Relation Schema Class
810 * Purpose of this class is to generate the PDF Document. PDF is widely
811 * used format for documenting text,fonts,images and 3d vector graphics.
813 * This class inherits Export_Relation_Schema class has common functionality added
816 * @name Pdf_Relation_Schema
817 * @package PhpMyAdmin
819 class PMA_Pdf_Relation_Schema
extends PMA_Export_Relation_Schema
824 private $_tables = array();
825 private $_ff = PMA_PDF_FONT
;
829 private $_xMin = 100000;
830 private $_yMin = 100000;
831 private $_topMargin = 10;
832 private $_bottomMargin = 10;
833 private $_leftMargin = 10;
834 private $_rightMargin = 10;
835 private $_tablewidth;
838 * The "PMA_Pdf_Relation_Schema" constructor
840 * @global object The current PDF Schema document
841 * @global string The current db name
842 * @global array The relations settings
844 * @see PMA_Schema_PDF
846 function __construct()
850 $this->setPageNumber($_POST['pdf_page_number']);
851 $this->setShowGrid(isset($_POST['show_grid']));
852 $this->setShowColor(isset($_POST['show_color']));
853 $this->setShowKeys(isset($_POST['show_keys']));
854 $this->setTableDimension(isset($_POST['show_table_dimension']));
855 $this->setAllTablesSameWidth(isset($_POST['all_tables_same_width']));
856 $this->setWithDataDictionary($_POST['with_doc']);
857 $this->setOrientation($_POST['orientation']);
858 $this->setPaper($_POST['paper']);
859 $this->setExportType($_POST['export_type']);
861 // Initializes a new document
862 $pdf = new PMA_Schema_PDF($this->orientation
, 'mm', $this->paper
);
865 __('Schema of the %s database - Page %s'),
872 $pdf->SetAutoPageBreak('auto');
873 $alltables = $this->getAllTables($db, $this->pageNumber
);
875 if ($this->withDoc
) {
876 $pdf->SetAutoPageBreak('auto', 15);
878 $this->dataDictionaryDoc($alltables);
879 $pdf->SetAutoPageBreak('auto');
885 if ($this->withDoc
) {
886 $pdf->SetLink($pdf->PMA_links
['RT']['-'], -1);
887 $pdf->Bookmark(__('Relational schema'));
888 $pdf->SetAlias('{00}', $pdf->PageNo());
889 $this->_topMargin
= 28;
890 $this->_bottomMargin
= 28;
894 foreach ($alltables as $table) {
895 if (! isset($this->_tables
[$table])) {
896 $this->_tables
[$table] = new Table_Stats(
902 $this->tableDimension
905 if ($this->sameWide
) {
906 $this->_tables
[$table]->width
= $this->_tablewidth
;
908 $this->_setMinMax($this->_tables
[$table]);
911 // Defines the scale factor
912 $this->_scale
= ceil(
914 ($this->_xMax
- $this->_xMin
)
915 / ($pdf->getPageWidth() - $this->_rightMargin
- $this->_leftMargin
),
916 ($this->_yMax
- $this->_yMin
)
917 / ($pdf->getPageHeight() - $this->_topMargin
- $this->_bottomMargin
)
928 // Builds and save the PDF document
929 $pdf->setLineWidthScale(0.1);
931 if ($this->showGrid
) {
932 $pdf->SetFontSize(10);
933 $this->_strokeGrid();
935 $pdf->setFontSizeScale(14);
936 // previous logic was checking master tables and foreign tables
937 // but I think that looping on every table of the pdf page as a master
938 // and finding its foreigns is OK (then we can support innodb)
939 $seen_a_relation = false;
940 foreach ($alltables as $one_table) {
941 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
943 $seen_a_relation = true;
944 foreach ($exist_rel as $master_field => $rel) {
945 // put the foreign table on the schema only if selected
947 // (do not use array_search() because we would have to
948 // to do a === false and this is not PHP3 compatible)
949 if (in_array($rel['foreign_table'], $alltables)) {
953 $rel['foreign_table'],
954 $rel['foreign_field'],
955 $this->tableDimension
962 if ($seen_a_relation) {
963 $this->_drawRelations($this->showColor
);
965 $this->_drawTables($this->showColor
);
966 $this->_showOutput($this->pageNumber
);
971 * Sets X and Y minimum and maximum for a table cell
973 * @param string $table The table name of which sets XY co-ordinates
979 private function _setMinMax($table)
981 $this->_xMax
= max($this->_xMax
, $table->x +
$table->width
);
982 $this->_yMax
= max($this->_yMax
, $table->y +
$table->height
);
983 $this->_xMin
= min($this->_xMin
, $table->x
);
984 $this->_yMin
= min($this->_yMin
, $table->y
);
988 * Defines relation objects
990 * @param string $masterTable The master table name
991 * @param string $masterField The relation field in the master table
992 * @param string $foreignTable The foreign table name
993 * @param string $foreignField The relation field in the foreign table
994 * @param boolean $showInfo Whether to display table position or not
1002 private function _addRelation($masterTable, $masterField, $foreignTable,
1003 $foreignField, $showInfo
1005 if (! isset($this->_tables
[$masterTable])) {
1006 $this->_tables
[$masterTable] = new Table_Stats(
1007 $masterTable, null, $this->pageNumber
,
1008 $this->_tablewidth
, false, $showInfo
1010 $this->_setMinMax($this->_tables
[$masterTable]);
1012 if (! isset($this->_tables
[$foreignTable])) {
1013 $this->_tables
[$foreignTable] = new Table_Stats(
1014 $foreignTable, null, $this->pageNumber
,
1015 $this->_tablewidth
, false, $showInfo
1017 $this->_setMinMax($this->_tables
[$foreignTable]);
1019 $this->relations
[] = new Relation_Stats(
1020 $this->_tables
[$masterTable], $masterField,
1021 $this->_tables
[$foreignTable], $foreignField
1028 * @global object the current PMA_Schema_PDF instance
1034 * @see PMA_Schema_PDF
1036 private function _strokeGrid()
1043 if ($this->withDoc
) {
1051 $pdf->SetMargins(0, 0);
1052 $pdf->SetDrawColor(200, 200, 200);
1053 // Draws horizontal lines
1054 for ($l = 0; $l <= intval(($pdf->getPageHeight() - $topSpace - $bottomSpace) / $gridSize); $l++
) {
1056 0, $l * $gridSize +
$topSpace,
1057 $pdf->getPageWidth(), $l * $gridSize +
$topSpace
1061 && $l <= intval(($pdf->getPageHeight() - $topSpace - $bottomSpace - $labelHeight) / $gridSize)
1063 $pdf->SetXY(0, $l * $gridSize +
$topSpace);
1064 $label = (string) sprintf(
1066 ($l * $gridSize +
$topSpace - $this->_topMargin
)
1067 * $this->_scale +
$this->_yMin
1069 $pdf->Cell($labelWidth, $labelHeight, ' ' . $label);
1072 // Draws vertical lines
1073 for ($j = 0; $j <= intval($pdf->getPageWidth() / $gridSize); $j++
) {
1078 $pdf->getPageHeight() - $bottomSpace
1080 $pdf->SetXY($j * $gridSize, $topSpace);
1081 $label = (string) sprintf(
1083 ($j * $gridSize - $this->_leftMargin
) * $this->_scale +
$this->_xMin
1085 $pdf->Cell($labelWidth, $labelHeight, $label);
1090 * Draws relation arrows
1092 * @param boolean $changeColor Whether to use one color per relation or not
1098 * @see Relation_Stats::relationdraw()
1100 private function _drawRelations($changeColor)
1103 foreach ($this->relations
as $relation) {
1104 $relation->relationDraw($changeColor, $i);
1112 * @param boolean $changeColor Whether to display table position or not
1118 * @see Table_Stats::tableDraw()
1120 private function _drawTables($changeColor = 0)
1122 foreach ($this->_tables
as $table) {
1123 $table->tableDraw(null, $this->withDoc
, $changeColor);
1128 * Ouputs the PDF document to a file
1129 * or sends the output to browser
1131 * @param integer $pageNumber page number
1133 * @global object The current PDF document
1134 * @global string The current database name
1135 * @global integer The current page number (from the
1136 * $cfg['Servers'][$i]['table_coords'] table)
1141 * @see PMA_Schema_PDF
1143 private function _showOutput($pageNumber)
1145 global $pdf, $cfgRelation;
1147 // Get the name of this pdfpage to use as filename
1148 $_name_sql = 'SELECT page_descr FROM '
1149 . PMA_Util
::backquote($GLOBALS['cfgRelation']['db']) . '.'
1150 . PMA_Util
::backquote($cfgRelation['pdf_pages'])
1151 . ' WHERE page_nr = ' . $pageNumber;
1152 $_name_rs = PMA_queryAsControlUser($_name_sql);
1154 $_name_row = PMA_DBI_fetch_row($_name_rs);
1155 $filename = $_name_row[0] . '.pdf';
1157 if (empty($filename)) {
1158 $filename = $pageNumber . '.pdf';
1160 $pdf->Download($filename);
1164 * Generates data dictionary pages.
1166 * @param bool $alltables Tables to document.
1170 public function dataDictionaryDoc($alltables)
1172 global $db, $pdf, $orientation, $paper;
1174 $pdf->addpage($_POST['orientation']);
1175 $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
1178 foreach ($alltables as $table) {
1179 $pdf->PMA_links
['doc'][$table]['-'] = $pdf->AddLink();
1183 0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0,
1184 'R', 0, $pdf->PMA_links
['doc'][$table]['-']
1188 0, 6, $i . ' ' . $table, 0, 1,
1189 'L', 0, $pdf->PMA_links
['doc'][$table]['-']
1192 $fields = PMA_DBI_get_columns($GLOBALS['db'], $table);
1193 foreach ($fields as $row) {
1195 $field_name = $row['Field'];
1196 $pdf->PMA_links
['doc'][$table][$field_name] = $pdf->AddLink();
1198 // 0, 6, $field_name, 0, 1,
1199 // 'L', 0, $pdf->PMA_links['doc'][$table][$field_name]
1204 $pdf->PMA_links
['RT']['-'] = $pdf->AddLink();
1207 0, 6, __('Page number:') . ' {00}', 0, 0,
1208 'R', 0, $pdf->PMA_links
['RT']['-']
1212 0, 6, $i . ' ' . __('Relational schema'), 0, 1,
1213 'L', 0, $pdf->PMA_links
['RT']['-']
1216 foreach ($alltables as $table) {
1218 $pdf->SetAutoPageBreak(true, 15);
1219 $pdf->addpage($_POST['orientation']);
1220 $pdf->Bookmark($table);
1221 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
1222 $pdf->PMA_links
['RT'][$table]['-'] = $pdf->AddLink();
1223 $pdf->SetLink($pdf->PMA_links
['doc'][$table]['-'], -1);
1224 $pdf->SetFont($this->_ff
, 'B', 18);
1226 0, 8, $z . ' ' . $table, 1, 1,
1227 'C', 0, $pdf->PMA_links
['RT'][$table]['-']
1229 $pdf->SetFont($this->_ff
, '', 8);
1232 $cfgRelation = PMA_getRelationsParam();
1233 $comments = PMA_getComments($db, $table);
1234 if ($cfgRelation['mimework']) {
1235 $mime_map = PMA_getMIME($db, $table, true);
1239 * Gets table informations
1241 $showtable = PMA_Table
::sGetStatusInfo($db, $table);
1242 $show_comment = isset($showtable['Comment'])
1243 ?
$showtable['Comment']
1245 $create_time = isset($showtable['Create_time'])
1246 ? PMA_Util
::localisedDate(
1247 strtotime($showtable['Create_time'])
1250 $update_time = isset($showtable['Update_time'])
1251 ? PMA_Util
::localisedDate(
1252 strtotime($showtable['Update_time'])
1255 $check_time = isset($showtable['Check_time'])
1256 ? PMA_Util
::localisedDate(
1257 strtotime($showtable['Check_time'])
1262 * Gets table keys and retains them
1264 $result = PMA_DBI_query(
1265 'SHOW KEYS FROM ' . PMA_Util
::backquote($table) . ';'
1270 $indexes_info = array();
1271 $indexes_data = array();
1272 $pk_array = array(); // will be use to emphasis prim. keys in the table
1274 while ($row = PMA_DBI_fetch_assoc($result)) {
1275 // Backups the list of primary keys
1276 if ($row['Key_name'] == 'PRIMARY') {
1277 $primary .= $row['Column_name'] . ', ';
1278 $pk_array[$row['Column_name']] = 1;
1280 // Retains keys informations
1281 if ($row['Key_name'] != $lastIndex) {
1282 $indexes[] = $row['Key_name'];
1283 $lastIndex = $row['Key_name'];
1285 $indexes_info[$row['Key_name']]['Sequences'][]
1286 = $row['Seq_in_index'];
1287 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1288 if (isset($row['Cardinality'])) {
1289 $indexes_info[$row['Key_name']]['Cardinality']
1290 = $row['Cardinality'];
1292 // I don't know what does following column mean....
1293 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1294 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1296 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']
1297 = $row['Column_name'];
1298 if (isset($row['Sub_part'])) {
1299 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part']
1304 PMA_DBI_free_result($result);
1308 * Gets fields properties
1310 $columns = PMA_DBI_get_columns($db, $table);
1311 // Check if we can use Relations
1312 if (!empty($cfgRelation['relation'])) {
1313 // Find which tables are related with the current one and write it in
1315 $res_rel = PMA_getForeigners($db, $table);
1317 if (count($res_rel) > 0) {
1327 * Displays the comments of the table if MySQL >= 3.23
1331 if (! empty($show_comment)) {
1332 $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
1336 if (! empty($create_time)) {
1337 $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
1341 if (! empty($update_time)) {
1342 $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
1346 if (! empty($check_time)) {
1347 $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
1351 if ($break == true) {
1352 $pdf->Cell(0, 3, '', 0, 1);
1356 $pdf->SetFont($this->_ff
, 'B');
1357 if (isset($orientation) && $orientation == 'L') {
1358 $pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
1359 $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
1360 $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
1361 $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
1362 $pdf->Cell(20, 8, __('Default'), 1, 0, 'C');
1363 $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
1364 $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
1366 if ($paper == 'A4') {
1367 $comments_width = 67;
1369 // this is really intended for 'letter'
1371 * @todo find optimal width for all formats
1373 $comments_width = 50;
1375 $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
1376 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1378 array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45)
1381 $pdf->Cell(20, 8, __('Column'), 1, 0, 'C');
1382 $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
1383 $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
1384 $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
1385 $pdf->Cell(15, 8, __('Default'), 1, 0, 'C');
1386 $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C');
1387 $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C');
1388 $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C');
1389 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1390 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1392 $pdf->SetFont($this->_ff
, '');
1394 foreach ($columns as $row) {
1395 $extracted_columnspec
1396 = PMA_Util
::extractColumnSpec($row['Type']);
1397 $type = $extracted_columnspec['print_type'];
1398 $attribute = $extracted_columnspec['attribute'];
1399 if (! isset($row['Default'])) {
1400 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1401 $row['Default'] = 'NULL';
1404 $field_name = $row['Field'];
1406 $pdf->PMA_links
['RT'][$table][$field_name] = $pdf->AddLink();
1407 $pdf->Bookmark($field_name, 1, -1);
1408 $pdf->SetLink($pdf->PMA_links
['doc'][$table][$field_name], -1);
1413 ($row['Null'] == '' ||
$row['Null'] == 'NO')
1416 (isset($row['Default']) ?
$row['Default'] : ''),
1418 (isset($res_rel[$field_name])
1419 ?
$res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']
1421 (isset($comments[$field_name])
1422 ?
$comments[$field_name]
1424 (isset($mime_map) && isset($mime_map[$field_name])
1425 ?
str_replace('_', '/', $mime_map[$field_name]['mimetype'])
1428 $links[0] = $pdf->PMA_links
['RT'][$table][$field_name];
1429 if (isset($res_rel[$field_name]['foreign_table'])
1430 && isset($res_rel[$field_name]['foreign_field'])
1431 && isset($pdf->PMA_links
['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1433 $links[6] = $pdf->PMA_links
['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1437 $pdf->Row($pdf_row, $links);
1439 $pdf->SetFont($this->_ff
, '', 14);