2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 require_once 'Export_Relation_Schema.class.php';
9 require_once './libraries/PDF.class.php';
12 * Extends the "TCPDF" class and helps
13 * in developing the structure of PDF Schema Export
18 class PMA_Schema_PDF
extends PMA_PDF
29 var $Outlines = array();
32 private $_ff = PMA_PDF_FONT
;
35 * Sets the value for margins
37 * @param float $c_margin margin
41 public function setCMargin($c_margin)
43 $this->cMargin
= $c_margin;
47 * Sets the scaling factor, defines minimum coordinates and margins
49 * @param float $scale The scaling factor
50 * @param float $xMin The minimum X coordinate
51 * @param float $yMin The minimum Y coordinate
52 * @param float $leftMargin The left margin
53 * @param float $topMargin The top margin
59 function PMA_PDF_setScale($scale = 1, $xMin = 0, $yMin = 0, $leftMargin = -1, $topMargin = -1)
61 $this->scale
= $scale;
64 if ($this->leftMargin
!= -1) {
65 $this->leftMargin
= $leftMargin;
67 if ($this->topMargin
!= -1) {
68 $this->topMargin
= $topMargin;
73 * Outputs a scaled cell
75 * @param float $w The cell width
76 * @param float $h The cell height
77 * @param string $txt The text to output
78 * @param mixed $border Whether to add borders or not
79 * @param integer $ln Where to put the cursor once the output is done
80 * @param string $align Align mode
81 * @param integer $fill Whether to fill the cell with a color or not
82 * @param string $link Link
90 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
92 $h = $h / $this->scale
;
93 $w = $w / $this->scale
;
94 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
100 * @param float $x1 The horizontal position of the starting point
101 * @param float $y1 The vertical position of the starting point
102 * @param float $x2 The horizontal position of the ending point
103 * @param float $y2 The vertical position of the ending point
111 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
113 $x1 = ($x1 - $this->_xMin
) / $this->scale +
$this->leftMargin
;
114 $y1 = ($y1 - $this->_yMin
) / $this->scale +
$this->topMargin
;
115 $x2 = ($x2 - $this->_xMin
) / $this->scale +
$this->leftMargin
;
116 $y2 = ($y2 - $this->_yMin
) / $this->scale +
$this->topMargin
;
117 $this->Line($x1, $y1, $x2, $y2);
121 * Sets x and y scaled positions
123 * @param float $x The x position
124 * @param float $y The y position
130 * @see TCPDF::SetXY()
132 function PMA_PDF_setXyScale($x, $y)
134 $x = ($x - $this->_xMin
) / $this->scale +
$this->leftMargin
;
135 $y = ($y - $this->_yMin
) / $this->scale +
$this->topMargin
;
136 $this->SetXY($x, $y);
140 * Sets the X scaled positions
142 * @param float $x The x position
150 function PMA_PDF_setXScale($x)
152 $x = ($x - $this->_xMin
) / $this->scale +
$this->leftMargin
;
157 * Sets the scaled font size
159 * @param float $size The font size (in points)
165 * @see TCPDF::SetFontSize()
167 function PMA_PDF_setFontSizeScale($size)
169 // Set font size in points
170 $size = $size / $this->scale
;
171 $this->SetFontSize($size);
175 * Sets the scaled line width
177 * @param float $width The line width
183 * @see TCPDF::SetLineWidth()
185 function PMA_PDF_setLineWidthScale($width)
187 $width = $width / $this->scale
;
188 $this->SetLineWidth($width);
192 * This method is used to render the page header.
196 * @see TCPDF::Header()
200 // We only show this if we find something in the new pdf_pages table
202 // This function must be named "Header" to work with the TCPDF library
203 global $cfgRelation, $db, $pdf_page_number, $with_doc;
205 $test_query = 'SELECT * FROM '
206 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
207 . PMA_backquote($cfgRelation['pdf_pages'])
208 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
209 . ' AND page_nr = \'' . $pdf_page_number . '\'';
210 $test_rs = PMA_query_as_controluser($test_query);
211 $pages = @PMA_DBI_fetch_assoc
($test_rs);
212 $this->SetFont($this->_ff
, 'B', 14);
213 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
214 $this->SetFont($this->_ff
, '');
220 * This function must be named "Footer" to work with the TCPDF library
224 * @see PMA_PDF::Footer()
237 * @param array $w array of widths
241 function SetWidths($w)
247 function Row($data, $links)
251 $data_cnt = count($data);
252 for ($i = 0;$i < $data_cnt;$i++
) {
253 $nb = max($nb, $this->NbLines($this->widths
[$i], $data[$i]));
255 $il = $this->FontSize
;
256 $h = ($il +
1) * $nb;
257 // page break if necessary
258 $this->CheckPageBreak($h);
260 $data_cnt = count($data);
261 for ($i = 0;$i < $data_cnt;$i++
) {
262 $w = $this->widths
[$i];
263 // save current position
267 $this->Rect($x, $y, $w, $h);
268 if (isset($links[$i])) {
269 $this->Link($x, $y, $w, $h, $links[$i]);
272 $this->MultiCell($w, $il +
1, $data[$i], 0, 'L');
274 $this->SetXY($x +
$w, $y);
281 * Compute number of lines used by a multicell of width w
283 * @param int $w width
284 * @param string $txt text
288 function NbLines($w, $txt)
290 $cw = &$this->CurrentFont
['cw'];
292 $w = $this->w
- $this->rMargin
- $this->x
;
294 $wmax = ($w-2 * $this->cMargin
) * 1000 / $this->FontSize
;
295 $s = str_replace("\r", '', $txt);
297 if ($nb > 0 and $s[$nb-1] == "\n") {
318 $l +
= isset($cw[ord($c)])?
$cw[ord($c)]:0 ;
340 * Table preferences/statistics
342 * This class preserves the table co-ordinates,fields
343 * and helps in drawing/generating the Tables in PDF document.
346 * @see PMA_Schema_PDF
354 private $_showInfo = false;
359 public $fields = array();
360 public $heightCell = 6;
362 public $primary = array();
363 private $_ff = PMA_PDF_FONT
;
366 * The "Table_Stats" constructor
368 * @param string $tableName The table name
369 * @param integer $fontSize The font size
370 * @param integer $pageNumber The current page number (from the
371 * $cfg['Servers'][$i]['table_coords'] table)
372 * @param integer &$sameWideWidth The max. with among tables
373 * @param boolean $showKeys Whether to display keys or not
374 * @param boolean $showInfo Whether to display table position or not
376 * @global object The current PDF document
377 * @global array The relations settings
378 * @global string The current db name
382 * @see PMA_Schema_PDF, Table_Stats::Table_Stats_setWidth,
383 * Table_Stats::Table_Stats_setHeight
385 function __construct($tableName, $fontSize, $pageNumber, &$sameWideWidth, $showKeys = false, $showInfo = false)
387 global $pdf, $cfgRelation, $db;
389 $this->_tableName
= $tableName;
390 $sql = 'DESCRIBE ' . PMA_backquote($tableName);
391 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE
);
392 if (! $result ||
! PMA_DBI_num_rows($result)) {
393 $pdf->Error(sprintf(__('The %s table doesn\'t exist!'), $tableName));
396 //check to see if it will load all fields or only the foreign keys
398 $indexes = PMA_Index
::getFromTable($this->_tableName
, $db);
399 $all_columns = array();
400 foreach ($indexes as $index) {
401 $all_columns = array_merge(
403 array_flip(array_keys($index->getColumns()))
406 $this->fields
= array_keys($all_columns);
408 while ($row = PMA_DBI_fetch_row($result)) {
409 $this->fields
[] = $row[0];
413 $this->_showInfo
= $showInfo;
416 * setWidth must me after setHeight, because title
417 * can include table height which changes table width
419 $this->_setWidth($fontSize);
420 if ($sameWideWidth < $this->width
) {
421 $sameWideWidth = $this->width
;
423 $sql = 'SELECT x, y FROM '
424 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
425 . PMA_backquote($cfgRelation['table_coords'])
426 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
427 . ' AND table_name = \'' . PMA_sqlAddSlashes($tableName) . '\''
428 . ' AND pdf_page_number = ' . $pageNumber;
429 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE
);
430 if (! $result ||
! PMA_DBI_num_rows($result)) {
433 __('Please configure the coordinates for table %s'),
438 list($this->x
, $this->y
) = PMA_DBI_fetch_row($result);
439 $this->x
= (double) $this->x
;
440 $this->y
= (double) $this->y
;
444 $this->displayfield
= PMA_getDisplayField($db, $tableName);
448 $result = PMA_DBI_query(
449 'SHOW INDEX FROM ' . PMA_backquote($tableName) . ';',
450 null, PMA_DBI_QUERY_STORE
452 if (PMA_DBI_num_rows($result) > 0) {
453 while ($row = PMA_DBI_fetch_assoc($result)) {
454 if ($row['Key_name'] == 'PRIMARY') {
455 $this->primary
[] = $row['Column_name'];
462 * Returns title of the current table,
463 * title can have the dimensions of the table
467 private function _getTitle()
469 return ($this->_showInfo ?
sprintf('%.0f', $this->width
) . 'x' . sprintf('%.0f', $this->height
) : '') . ' ' . $this->_tableName
;
473 * Sets the width of the table
475 * @param integer $fontSize The font size
477 * @global object The current PDF document
483 * @see PMA_Schema_PDF
485 private function _setWidth($fontSize)
489 foreach ($this->fields
as $field) {
490 $this->width
= max($this->width
, $pdf->GetStringWidth($field));
492 $this->width +
= $pdf->GetStringWidth(' ');
493 $pdf->SetFont($this->_ff
, 'B', $fontSize);
495 * it is unknown what value must be added, because
496 * table title is affected by the tabe width value
498 while ($this->width
< $pdf->GetStringWidth($this->_getTitle())) {
501 $pdf->SetFont($this->_ff
, '', $fontSize);
505 * Sets the height of the table
511 private function _setHeight()
513 $this->height
= (count($this->fields
) +
1) * $this->heightCell
;
519 * @param integer $fontSize The font size
520 * @param boolean $withDoc
521 * @param boolean $setColor Whether to display color
523 * @global object The current PDF document
529 * @see PMA_Schema_PDF
531 public function tableDraw($fontSize, $withDoc, $setColor = 0)
533 global $pdf, $withDoc;
535 $pdf->PMA_PDF_setXyScale($this->x
, $this->y
);
536 $pdf->SetFont($this->_ff
, 'B', $fontSize);
538 $pdf->SetTextColor(200);
539 $pdf->SetFillColor(0, 0, 128);
542 $pdf->SetLink($pdf->PMA_links
['RT'][$this->_tableName
]['-'], -1);
544 $pdf->PMA_links
['doc'][$this->_tableName
]['-'] = '';
547 $pdf->PMA_PDF_cellScale(
555 $pdf->PMA_links
['doc'][$this->_tableName
]['-']
557 $pdf->PMA_PDF_setXScale($this->x
);
558 $pdf->SetFont($this->_ff
, '', $fontSize);
559 $pdf->SetTextColor(0);
560 $pdf->SetFillColor(255);
562 foreach ($this->fields
as $field) {
564 if (in_array($field, $this->primary
)) {
565 $pdf->SetFillColor(215, 121, 123);
567 if ($field == $this->displayfield
) {
568 $pdf->SetFillColor(142, 159, 224);
572 $pdf->SetLink($pdf->PMA_links
['RT'][$this->_tableName
][$field], -1);
574 $pdf->PMA_links
['doc'][$this->_tableName
][$field] = '';
577 $pdf->PMA_PDF_cellScale(
585 $pdf->PMA_links
['doc'][$this->_tableName
][$field]
587 $pdf->PMA_PDF_setXScale($this->x
);
588 $pdf->SetFillColor(255);
590 /*if ($pdf->PageNo() > 1) {
592 __('The scale factor is too small to fit the schema on one page')
599 * Relation preferences/statistics
601 * This class fetches the table master and foreign fields positions
602 * and helps in generating the Table references and then connects
603 * master table's master field to foreign table's foreign key
606 * @name Relation_Stats
607 * @see PMA_Schema_PDF::SetDrawColor, PMA_Schema_PDF::PMA_PDF_setLineWidthScale,
608 * PMA_Schema_PDF::PMA_PDF_lineScale
618 public $xDest, $yDest;
622 * The "Relation_Stats" constructor
624 * @param string $master_table The master table name
625 * @param string $master_field The relation field in the master table
626 * @param string $foreign_table The foreign table name
627 * @param string $foreign_field The relation field in the foreign table
631 * @see Relation_Stats::_getXy
633 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
635 $src_pos = $this->_getXy($master_table, $master_field);
636 $dest_pos = $this->_getXy($foreign_table, $foreign_field);
642 $src_left = $src_pos[0] - $this->wTick
;
643 $src_right = $src_pos[1] +
$this->wTick
;
644 $dest_left = $dest_pos[0] - $this->wTick
;
645 $dest_right = $dest_pos[1] +
$this->wTick
;
647 $d1 = abs($src_left - $dest_left);
648 $d2 = abs($src_right - $dest_left);
649 $d3 = abs($src_left - $dest_right);
650 $d4 = abs($src_right - $dest_right);
651 $d = min($d1, $d2, $d3, $d4);
654 $this->xSrc
= $src_pos[0];
656 $this->xDest
= $dest_pos[0];
658 } elseif ($d == $d2) {
659 $this->xSrc
= $src_pos[1];
661 $this->xDest
= $dest_pos[0];
663 } elseif ($d == $d3) {
664 $this->xSrc
= $src_pos[0];
666 $this->xDest
= $dest_pos[1];
669 $this->xSrc
= $src_pos[1];
671 $this->xDest
= $dest_pos[1];
674 $this->ySrc
= $src_pos[2];
675 $this->yDest
= $dest_pos[2];
679 * Gets arrows coordinates
681 * @param string $table The current table name
682 * @param string $column The relation column name
684 * @return array Arrows coordinates
688 private function _getXy($table, $column)
690 $pos = array_search($column, $table->fields
);
691 // x_left, x_right, y
692 return array($table->x
, $table->x + +
$table->width
, $table->y +
($pos +
1.5) * $table->heightCell
);
696 * draws relation links and arrows shows foreign key relations
698 * @param boolean $changeColor Whether to use one color per relation or not
699 * @param integer $i The id of the link to draw
701 * @global object The current PDF document
707 * @see PMA_Schema_PDF
709 public function relationDraw($changeColor, $i)
726 list ($a, $b, $c) = $case[$d];
727 $e = (1 - ($j - 1) / 6);
728 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
730 $pdf->SetDrawColor(0);
732 $pdf->PMA_PDF_setLineWidthScale(0.2);
733 $pdf->PMA_PDF_lineScale(
736 $this->xSrc +
$this->srcDir
* $this->wTick
,
739 $pdf->PMA_PDF_lineScale(
740 $this->xDest +
$this->destDir
* $this->wTick
,
745 $pdf->PMA_PDF_setLineWidthScale(0.1);
746 $pdf->PMA_PDF_lineScale(
747 $this->xSrc +
$this->srcDir
* $this->wTick
,
749 $this->xDest +
$this->destDir
* $this->wTick
,
755 $root2 = 2 * sqrt(2);
756 $pdf->PMA_PDF_lineScale(
757 $this->xSrc +
$this->srcDir
* $this->wTick
* 0.75,
759 $this->xSrc +
$this->srcDir
* (0.75 - 1 / $root2) * $this->wTick
,
760 $this->ySrc +
$this->wTick
/ $root2
762 $pdf->PMA_PDF_lineScale(
763 $this->xSrc +
$this->srcDir
* $this->wTick
* 0.75,
765 $this->xSrc +
$this->srcDir
* (0.75 - 1 / $root2) * $this->wTick
,
766 $this->ySrc
- $this->wTick
/ $root2
769 $pdf->PMA_PDF_lineScale(
770 $this->xDest +
$this->destDir
* $this->wTick
/ 2,
772 $this->xDest +
$this->destDir
* (0.5 +
1 / $root2) * $this->wTick
,
773 $this->yDest +
$this->wTick
/ $root2
775 $pdf->PMA_PDF_lineScale(
776 $this->xDest +
$this->destDir
* $this->wTick
/ 2,
778 $this->xDest +
$this->destDir
* (0.5 +
1 / $root2) * $this->wTick
,
779 $this->yDest
- $this->wTick
/ $root2
781 $pdf->SetDrawColor(0);
786 * Pdf Relation Schema Class
788 * Purpose of this class is to generate the PDF Document. PDF is widely
789 * used format for documenting text,fonts,images and 3d vector graphics.
791 * This class inherits Export_Relation_Schema class has common functionality added
794 * @name Pdf_Relation_Schema
796 class PMA_Pdf_Relation_Schema
extends PMA_Export_Relation_Schema
801 private $_ff = PMA_PDF_FONT
;
805 private $_xMin = 100000;
806 private $_yMin = 100000;
807 private $topMargin = 10;
808 private $bottomMargin = 10;
809 private $leftMargin = 10;
810 private $rightMargin = 10;
811 private $_tablewidth;
814 * The "PMA_Pdf_Relation_Schema" constructor
816 * @global object The current PDF Schema document
817 * @global string The current db name
818 * @global array The relations settings
820 * @see PMA_Schema_PDF
822 function __construct()
826 $this->setPageNumber($_POST['pdf_page_number']);
827 $this->setShowGrid(isset($_POST['show_grid']));
828 $this->setShowColor(isset($_POST['show_color']));
829 $this->setShowKeys(isset($_POST['show_keys']));
830 $this->setTableDimension(isset($_POST['show_table_dimension']));
831 $this->setAllTableSameWidth(isset($_POST['all_table_same_wide']));
832 $this->setWithDataDictionary($_POST['with_doc']);
833 $this->setOrientation($_POST['orientation']);
834 $this->setPaper($_POST['paper']);
835 $this->setExportType($_POST['export_type']);
837 // Initializes a new document
838 $pdf = new PMA_Schema_PDF($this->orientation
, 'mm', $this->paper
);
841 __('Schema of the %s database - Page %s'),
848 $pdf->SetAutoPageBreak('auto');
849 $alltables = $this->getAllTables($db, $this->pageNumber
);
851 if ($this->withDoc
) {
852 $pdf->SetAutoPageBreak('auto', 15);
854 $this->dataDictionaryDoc($alltables);
855 $pdf->SetAutoPageBreak('auto');
861 if ($this->withDoc
) {
862 $pdf->SetLink($pdf->PMA_links
['RT']['-'], -1);
863 $pdf->Bookmark(__('Relational schema'));
864 $pdf->SetAlias('{00}', $pdf->PageNo());
865 $this->topMargin
= 28;
866 $this->bottomMargin
= 28;
870 foreach ($alltables as $table) {
871 if (! isset($this->tables
[$table])) {
872 $this->tables
[$table] = new Table_Stats(
877 $this->tableDimension
880 if ($this->sameWide
) {
881 $this->tables
[$table]->width
= $this->_tablewidth
;
883 $this->_setMinMax($this->tables
[$table]);
886 // Defines the scale factor
889 ($this->_xMax
- $this->_xMin
) / ($pdf->getPageWidth() - $this->rightMargin
- $this->leftMargin
),
890 ($this->_yMax
- $this->_yMin
) / ($pdf->getPageHeight() - $this->topMargin
- $this->bottomMargin
)
894 $pdf->PMA_PDF_setScale(
901 // Builds and save the PDF document
902 $pdf->PMA_PDF_setLineWidthScale(0.1);
904 if ($this->showGrid
) {
905 $pdf->SetFontSize(10);
906 $this->_strokeGrid();
908 $pdf->PMA_PDF_setFontSizeScale(14);
909 // previous logic was checking master tables and foreign tables
910 // but I think that looping on every table of the pdf page as a master
911 // and finding its foreigns is OK (then we can support innodb)
912 $seen_a_relation = false;
913 foreach ($alltables as $one_table) {
914 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
916 $seen_a_relation = true;
917 foreach ($exist_rel as $master_field => $rel) {
918 // put the foreign table on the schema only if selected
920 // (do not use array_search() because we would have to
921 // to do a === false and this is not PHP3 compatible)
922 if (in_array($rel['foreign_table'], $alltables)) {
926 $rel['foreign_table'],
927 $rel['foreign_field'],
928 $this->tableDimension
935 if ($seen_a_relation) {
936 $this->_drawRelations($this->showColor
);
938 $this->_drawTables($this->showColor
);
939 $this->_showOutput($this->pageNumber
);
944 * Sets X and Y minimum and maximum for a table cell
946 * @param string $table The table name of which sets XY co-ordinates
952 private function _setMinMax($table)
954 $this->_xMax
= max($this->_xMax
, $table->x +
$table->width
);
955 $this->_yMax
= max($this->_yMax
, $table->y +
$table->height
);
956 $this->_xMin
= min($this->_xMin
, $table->x
);
957 $this->_yMin
= min($this->_yMin
, $table->y
);
961 * Defines relation objects
963 * @param string $masterTable The master table name
964 * @param string $masterField The relation field in the master table
965 * @param string $foreignTable The foreign table name
966 * @param string $foreignField The relation field in the foreign table
967 * @param boolean $showInfo Whether to display table position or not
975 private function _addRelation($masterTable, $masterField, $foreignTable, $foreignField, $showInfo)
977 if (! isset($this->tables
[$masterTable])) {
978 $this->tables
[$masterTable] = new Table_Stats(
979 $masterTable, $this->_ff
, $this->pageNumber
,
980 $this->_tablewidth
, false, $showInfo
982 $this->_setMinMax($this->tables
[$masterTable]);
984 if (! isset($this->tables
[$foreignTable])) {
985 $this->tables
[$foreignTable] = new Table_Stats(
986 $foreignTable, $this->_ff
, $this->pageNumber
,
987 $this->_tablewidth
, false, $showInfo
989 $this->_setMinMax($this->tables
[$foreignTable]);
991 $this->relations
[] = new Relation_Stats(
992 $this->tables
[$masterTable], $masterField,
993 $this->tables
[$foreignTable], $foreignField
1000 * @global object the current PMA_Schema_PDF instance
1006 * @see PMA_Schema_PDF
1008 private function _strokeGrid()
1015 if ($this->withDoc
) {
1023 $pdf->SetMargins(0, 0);
1024 $pdf->SetDrawColor(200, 200, 200);
1025 // Draws horizontal lines
1026 for ($l = 0; $l <= intval(($pdf->getPageHeight() - $topSpace - $bottomSpace) / $gridSize); $l++
) {
1028 0, $l * $gridSize +
$topSpace,
1029 $pdf->getPageWidth(), $l * $gridSize +
$topSpace
1033 && $l <= intval(($pdf->getPageHeight() - $topSpace - $bottomSpace - $labelHeight) / $gridSize)
1035 $pdf->SetXY(0, $l * $gridSize +
$topSpace);
1036 $label = (string) sprintf(
1038 ($l * $gridSize +
$topSpace - $this->topMargin
) * $this->scale +
$this->_yMin
1040 $pdf->Cell($labelWidth, $labelHeight, ' ' . $label);
1043 // Draws vertical lines
1044 for ($j = 0; $j <= intval($pdf->getPageWidth() / $gridSize); $j++
) {
1049 $pdf->getPageHeight() - $bottomSpace
1051 $pdf->SetXY($j * $gridSize, $topSpace);
1052 $label = (string) sprintf(
1054 ($j * $gridSize - $this->leftMargin
) * $this->scale +
$this->_xMin
1056 $pdf->Cell($labelWidth, $labelHeight, $label);
1061 * Draws relation arrows
1063 * @param boolean $changeColor Whether to use one color per relation or not
1069 * @see Relation_Stats::relationdraw()
1071 private function _drawRelations($changeColor)
1074 foreach ($this->relations
as $relation) {
1075 $relation->relationDraw($changeColor, $i);
1083 * @param boolean $changeColor Whether to display table position or not
1089 * @see Table_Stats::tableDraw()
1091 private function _drawTables($changeColor = 0)
1093 foreach ($this->tables
as $table) {
1094 $table->tableDraw($this->_ff
, $this->withDoc
, $changeColor);
1099 * Ouputs the PDF document to a file
1100 * or sends the output to browser
1102 * @param integer $pageNumber page number
1104 * @global object The current PDF document
1105 * @global string The current database name
1106 * @global integer The current page number (from the
1107 * $cfg['Servers'][$i]['table_coords'] table)
1112 * @see PMA_Schema_PDF
1114 private function _showOutput($pageNumber)
1116 global $pdf, $cfgRelation;
1118 // Get the name of this pdfpage to use as filename
1119 $_name_sql = 'SELECT page_descr FROM '
1120 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
1121 . PMA_backquote($cfgRelation['pdf_pages'])
1122 . ' WHERE page_nr = ' . $pageNumber;
1123 $_name_rs = PMA_query_as_controluser($_name_sql);
1125 $_name_row = PMA_DBI_fetch_row($_name_rs);
1126 $filename = $_name_row[0] . '.pdf';
1128 if (empty($filename)) {
1129 $filename = $pageNumber . '.pdf';
1131 $pdf->Download($filename);
1134 public function dataDictionaryDoc($alltables)
1136 global $db, $pdf, $orientation, $paper;
1138 $pdf->addpage($GLOBALS['orientation']);
1139 $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
1142 foreach ($alltables as $table) {
1143 $pdf->PMA_links
['doc'][$table]['-'] = $pdf->AddLink();
1147 0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0,
1148 'R', 0, $pdf->PMA_links
['doc'][$table]['-']
1152 0, 6, $i . ' ' . $table, 0, 1,
1153 'L', 0, $pdf->PMA_links
['doc'][$table]['-']
1156 $fields = PMA_DBI_get_columns($GLOBALS['db'], $table);
1157 foreach ($fields as $row) {
1159 $field_name = $row['Field'];
1160 $pdf->PMA_links
['doc'][$table][$field_name] = $pdf->AddLink();
1162 // 0, 6, $field_name, 0, 1,
1163 // 'L', 0, $pdf->PMA_links['doc'][$table][$field_name]
1168 $pdf->PMA_links
['RT']['-'] = $pdf->AddLink();
1171 0, 6, __('Page number:') . ' {00}', 0, 0,
1172 'R', 0, $pdf->PMA_links
['RT']['-']
1176 0, 6, $i . ' ' . __('Relational schema'), 0, 1,
1177 'L', 0, $pdf->PMA_links
['RT']['-']
1180 foreach ($alltables as $table) {
1182 $pdf->SetAutoPageBreak(true, 15);
1183 $pdf->addpage($GLOBALS['orientation']);
1184 $pdf->Bookmark($table);
1185 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
1186 $pdf->PMA_links
['RT'][$table]['-'] = $pdf->AddLink();
1187 $pdf->SetLink($pdf->PMA_links
['doc'][$table]['-'], -1);
1188 $pdf->SetFont($this->_ff
, 'B', 18);
1190 0, 8, $z . ' ' . $table, 1, 1,
1191 'C', 0, $pdf->PMA_links
['RT'][$table]['-']
1193 $pdf->SetFont($this->_ff
, '', 8);
1196 $cfgRelation = PMA_getRelationsParam();
1197 $comments = PMA_getComments($db, $table);
1198 if ($cfgRelation['mimework']) {
1199 $mime_map = PMA_getMIME($db, $table, true);
1203 * Gets table informations
1205 $showtable = PMA_Table
::sGetStatusInfo($db, $table);
1206 $show_comment = isset($showtable['Comment'])
1207 ?
$showtable['Comment']
1209 $create_time = isset($showtable['Create_time'])
1210 ?
PMA_localisedDate(strtotime($showtable['Create_time']))
1212 $update_time = isset($showtable['Update_time'])
1213 ?
PMA_localisedDate(strtotime($showtable['Update_time']))
1215 $check_time = isset($showtable['Check_time'])
1216 ?
PMA_localisedDate(strtotime($showtable['Check_time']))
1220 * Gets table keys and retains them
1222 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1226 $indexes_info = array();
1227 $indexes_data = array();
1228 $pk_array = array(); // will be use to emphasis prim. keys in the table
1230 while ($row = PMA_DBI_fetch_assoc($result)) {
1231 // Backups the list of primary keys
1232 if ($row['Key_name'] == 'PRIMARY') {
1233 $primary .= $row['Column_name'] . ', ';
1234 $pk_array[$row['Column_name']] = 1;
1236 // Retains keys informations
1237 if ($row['Key_name'] != $lastIndex) {
1238 $indexes[] = $row['Key_name'];
1239 $lastIndex = $row['Key_name'];
1241 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1242 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1243 if (isset($row['Cardinality'])) {
1244 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1246 // I don't know what does following column mean....
1247 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1248 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1250 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1251 if (isset($row['Sub_part'])) {
1252 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1256 PMA_DBI_free_result($result);
1260 * Gets fields properties
1262 $columns = PMA_DBI_get_columns($db, $table);
1263 // Check if we can use Relations
1264 if (!empty($cfgRelation['relation'])) {
1265 // Find which tables are related with the current one and write it in
1267 $res_rel = PMA_getForeigners($db, $table);
1269 if (count($res_rel) > 0) {
1279 * Displays the comments of the table if MySQL >= 3.23
1283 if (! empty($show_comment)) {
1284 $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
1288 if (! empty($create_time)) {
1289 $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
1293 if (! empty($update_time)) {
1294 $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
1298 if (! empty($check_time)) {
1299 $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
1303 if ($break == true) {
1304 $pdf->Cell(0, 3, '', 0, 1);
1308 $pdf->SetFont($this->_ff
, 'B');
1309 if (isset($orientation) && $orientation == 'L') {
1310 $pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
1311 $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
1312 $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
1313 $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
1314 $pdf->Cell(20, 8, __('Default'), 1, 0, 'C');
1315 $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
1316 $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
1318 if ($paper == 'A4') {
1319 $comments_width = 67;
1321 // this is really intended for 'letter'
1323 * @todo find optimal width for all formats
1325 $comments_width = 50;
1327 $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
1328 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1329 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1331 $pdf->Cell(20, 8, __('Column'), 1, 0, 'C');
1332 $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
1333 $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
1334 $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
1335 $pdf->Cell(15, 8, __('Default'), 1, 0, 'C');
1336 $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C');
1337 $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C');
1338 $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C');
1339 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1340 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1342 $pdf->SetFont($this->_ff
, '');
1344 foreach ($columns as $row) {
1345 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
1346 $type = $extracted_fieldspec['print_type'];
1347 $attribute = $extracted_fieldspec['attribute'];
1348 if (! isset($row['Default'])) {
1349 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1350 $row['Default'] = 'NULL';
1353 $field_name = $row['Field'];
1355 $pdf->PMA_links
['RT'][$table][$field_name] = $pdf->AddLink();
1356 $pdf->Bookmark($field_name, 1, -1);
1357 $pdf->SetLink($pdf->PMA_links
['doc'][$table][$field_name], -1);
1362 ($row['Null'] == '' ||
$row['Null'] == 'NO') ?
__('No') : __('Yes'),
1363 (isset($row['Default']) ?
$row['Default'] : ''),
1365 (isset($res_rel[$field_name])
1366 ?
$res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']
1368 (isset($comments[$field_name])
1369 ?
$comments[$field_name]
1371 (isset($mime_map) && isset($mime_map[$field_name])
1372 ?
str_replace('_', '/', $mime_map[$field_name]['mimetype'])
1375 $links[0] = $pdf->PMA_links
['RT'][$table][$field_name];
1376 if (isset($res_rel[$field_name]['foreign_table'])
1377 AND isset($res_rel[$field_name]['foreign_field'])
1378 AND isset($pdf->PMA_links
['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1380 $links[6] = $pdf->PMA_links
['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1384 $pdf->Row($pdf_row, $links);
1386 $pdf->SetFont($this->_ff
, '', 14);