2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 include_once("Export_Relation_Schema.class.php");
10 require_once './libraries/PDF.class.php';
13 * Extends the "TCPDF" class and helps
14 * in developing the structure of PDF Schema Export
19 class PMA_Schema_PDF
extends PMA_PDF
30 var $Outlines = array();
33 private $_ff = PMA_PDF_FONT
;
35 public function setCMargin($c_margin)
37 $this->cMargin
= $c_margin;
41 * Sets the scaling factor, defines minimum coordinates and margins
43 * @param float scale The scaling factor
44 * @param float _xMin The minimum X coordinate
45 * @param float _yMin The minimum Y coordinate
46 * @param float leftMargin The left margin
47 * @param float topMargin The top margin
50 function PMA_PDF_setScale($scale = 1, $xMin = 0, $yMin = 0, $leftMargin = -1, $topMargin = -1)
52 $this->scale
= $scale;
55 if ($this->leftMargin
!= -1) {
56 $this->leftMargin
= $leftMargin;
58 if ($this->topMargin
!= -1) {
59 $this->topMargin
= $topMargin;
64 * Outputs a scaled cell
66 * @param float w The cell width
67 * @param float h The cell height
68 * @param string txt The text to output
69 * @param mixed border Whether to add borders or not
70 * @param integer ln Where to put the cursor once the output is done
71 * @param string align Align mode
72 * @param integer fill Whether to fill the cell with a color or not
76 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
78 $h = $h / $this->scale
;
79 $w = $w / $this->scale
;
80 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
86 * @param float x1 The horizontal position of the starting point
87 * @param float y1 The vertical position of the starting point
88 * @param float x2 The horizontal position of the ending point
89 * @param float y2 The vertical position of the ending point
93 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
95 $x1 = ($x1 - $this->_xMin
) / $this->scale +
$this->leftMargin
;
96 $y1 = ($y1 - $this->_yMin
) / $this->scale +
$this->topMargin
;
97 $x2 = ($x2 - $this->_xMin
) / $this->scale +
$this->leftMargin
;
98 $y2 = ($y2 - $this->_yMin
) / $this->scale +
$this->topMargin
;
99 $this->Line($x1, $y1, $x2, $y2);
103 * Sets x and y scaled positions
105 * @param float x The x position
106 * @param float y The y position
108 * @see TCPDF::SetXY()
110 function PMA_PDF_setXyScale($x, $y)
112 $x = ($x - $this->_xMin
) / $this->scale +
$this->leftMargin
;
113 $y = ($y - $this->_yMin
) / $this->scale +
$this->topMargin
;
114 $this->SetXY($x, $y);
118 * Sets the X scaled positions
120 * @param float x The x position
124 function PMA_PDF_setXScale($x)
126 $x = ($x - $this->_xMin
) / $this->scale +
$this->leftMargin
;
131 * Sets the scaled font size
133 * @param float size The font size (in points)
135 * @see TCPDF::SetFontSize()
137 function PMA_PDF_setFontSizeScale($size)
139 // Set font size in points
140 $size = $size / $this->scale
;
141 $this->SetFontSize($size);
145 * Sets the scaled line width
147 * @param float $width The line width
149 * @see TCPDF::SetLineWidth()
151 function PMA_PDF_setLineWidthScale($width)
153 $width = $width / $this->scale
;
154 $this->SetLineWidth($width);
159 // We only show this if we find something in the new pdf_pages table
161 // This function must be named "Header" to work with the TCPDF library
162 global $cfgRelation, $db, $pdf_page_number, $with_doc;
164 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
165 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
166 . ' AND page_nr = \'' . $pdf_page_number . '\'';
167 $test_rs = PMA_query_as_controluser($test_query);
168 $pages = @PMA_DBI_fetch_assoc
($test_rs);
169 $this->SetFont($this->_ff
, 'B', 14);
170 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
171 $this->SetFont($this->_ff
, '');
177 * This function must be named "Footer" to work with the TCPDF library
187 function SetWidths($w)
193 function Row($data, $links)
197 $data_cnt = count($data);
198 for ($i = 0;$i < $data_cnt;$i++
)
199 $nb = max($nb, $this->NbLines($this->widths
[$i], $data[$i]));
200 $il = $this->FontSize
;
201 $h = ($il +
1) * $nb;
202 // page break if necessary
203 $this->CheckPageBreak($h);
205 $data_cnt = count($data);
206 for ($i = 0;$i < $data_cnt;$i++
) {
207 $w = $this->widths
[$i];
208 // save current position
212 $this->Rect($x, $y, $w, $h);
213 if (isset($links[$i])) {
214 $this->Link($x, $y, $w, $h, $links[$i]);
217 $this->MultiCell($w, $il +
1, $data[$i], 0, 'L');
219 $this->SetXY($x +
$w, $y);
226 * Compute number of lines used by a multicell of width w
232 function NbLines($w, $txt)
234 $cw = &$this->CurrentFont
['cw'];
236 $w = $this->w
- $this->rMargin
- $this->x
;
238 $wmax = ($w-2 * $this->cMargin
) * 1000 / $this->FontSize
;
239 $s = str_replace("\r", '', $txt);
241 if ($nb > 0 and $s[$nb-1] == "\n") {
262 $l +
= isset($cw[ord($c)])?
$cw[ord($c)]:0 ;
284 * Table preferences/statistics
286 * This class preserves the table co-ordinates,fields
287 * and helps in drawing/generating the Tables in PDF document.
290 * @see PMA_Schema_PDF
298 private $_showInfo = false;
303 public $fields = array();
304 public $heightCell = 6;
306 public $primary = array();
307 private $_ff = PMA_PDF_FONT
;
310 * The "Table_Stats" constructor
312 * @param string table_name The table name
313 * @param integer fontSize The font size
314 * @param integer pageNumber The current page number (from the
315 * $cfg['Servers'][$i]['table_coords'] table)
316 * @param integer sameWideWidth The max. with among tables
317 * @param boolean showKeys Whether to display keys or not
318 * @param boolean showInfo Whether to display table position or not
319 * @global object The current PDF document
320 * @global array The relations settings
321 * @global string The current db name
322 * @see PMA_Schema_PDF, Table_Stats::Table_Stats_setWidth,
323 Table_Stats::Table_Stats_setHeight
325 function __construct($tableName, $fontSize, $pageNumber, &$sameWideWidth, $showKeys = false, $showInfo = false)
327 global $pdf, $cfgRelation, $db;
329 $this->_tableName
= $tableName;
330 $sql = 'DESCRIBE ' . PMA_backquote($tableName);
331 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE
);
332 if (!$result ||
!PMA_DBI_num_rows($result)) {
333 $pdf->Error(sprintf(__('The %s table doesn\'t exist!'), $tableName));
336 //check to see if it will load all fields or only the foreign keys
338 $indexes = PMA_Index
::getFromTable($this->_tableName
, $db);
339 $all_columns = array();
340 foreach ($indexes as $index) {
341 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
343 $this->fields
= array_keys($all_columns);
345 while ($row = PMA_DBI_fetch_row($result)) {
346 $this->fields
[] = $row[0];
350 $this->_showInfo
= $showInfo;
353 * setWidth must me after setHeight, because title
354 * can include table height which changes table width
356 $this->_setWidth($fontSize);
357 if ($sameWideWidth < $this->width
) {
358 $sameWideWidth = $this->width
;
360 $sql = 'SELECT x, y FROM '
361 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
362 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
363 . ' AND table_name = \'' . PMA_sqlAddSlashes($tableName) . '\''
364 . ' AND pdf_page_number = ' . $pageNumber;
365 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE
);
366 if (!$result ||
!PMA_DBI_num_rows($result)) {
367 $pdf->Error(sprintf(__('Please configure the coordinates for table %s'), $tableName));
369 list($this->x
, $this->y
) = PMA_DBI_fetch_row($result);
370 $this->x
= (double) $this->x
;
371 $this->y
= (double) $this->y
;
375 $this->displayfield
= PMA_getDisplayField($db, $tableName);
379 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE
);
380 if (PMA_DBI_num_rows($result) > 0) {
381 while ($row = PMA_DBI_fetch_assoc($result)) {
382 if ($row['Key_name'] == 'PRIMARY') {
383 $this->primary
[] = $row['Column_name'];
390 * Returns title of the current table,
391 * title can have the dimensions of the table
395 private function _getTitle()
397 return ($this->_showInfo ?
sprintf('%.0f', $this->width
) . 'x' . sprintf('%.0f', $this->height
) : '') . ' ' . $this->_tableName
;
401 * Sets the width of the table
403 * @param integer fontSize The font size
404 * @global object The current PDF document
406 * @see PMA_Schema_PDF
408 private function _setWidth($fontSize)
412 foreach ($this->fields
as $field) {
413 $this->width
= max($this->width
, $pdf->GetStringWidth($field));
415 $this->width +
= $pdf->GetStringWidth(' ');
416 $pdf->SetFont($this->_ff
, 'B', $fontSize);
418 * it is unknown what value must be added, because
419 * table title is affected by the tabe width value
421 while ($this->width
< $pdf->GetStringWidth($this->_getTitle())) {
424 $pdf->SetFont($this->_ff
, '', $fontSize);
428 * Sets the height of the table
432 private function _setHeight()
434 $this->height
= (count($this->fields
) +
1) * $this->heightCell
;
440 * @param integer fontSize The font size
441 * @param boolean setColor Whether to display color
442 * @global object The current PDF document
444 * @see PMA_Schema_PDF
446 public function tableDraw($fontSize, $withDoc, $setColor = 0)
448 global $pdf, $withDoc;
450 $pdf->PMA_PDF_setXyScale($this->x
, $this->y
);
451 $pdf->SetFont($this->_ff
, 'B', $fontSize);
453 $pdf->SetTextColor(200);
454 $pdf->SetFillColor(0, 0, 128);
457 $pdf->SetLink($pdf->PMA_links
['RT'][$this->_tableName
]['-'], -1);
459 $pdf->PMA_links
['doc'][$this->_tableName
]['-'] = '';
462 $pdf->PMA_PDF_cellScale($this->width
, $this->heightCell
, $this->_getTitle(), 1, 1, 'C', $setColor, $pdf->PMA_links
['doc'][$this->_tableName
]['-']);
463 $pdf->PMA_PDF_setXScale($this->x
);
464 $pdf->SetFont($this->_ff
, '', $fontSize);
465 $pdf->SetTextColor(0);
466 $pdf->SetFillColor(255);
468 foreach ($this->fields
as $field) {
470 if (in_array($field, $this->primary
)) {
471 $pdf->SetFillColor(215, 121, 123);
473 if ($field == $this->displayfield
) {
474 $pdf->SetFillColor(142, 159, 224);
478 $pdf->SetLink($pdf->PMA_links
['RT'][$this->_tableName
][$field], -1);
480 $pdf->PMA_links
['doc'][$this->_tableName
][$field] = '';
483 $pdf->PMA_PDF_cellScale($this->width
, $this->heightCell
, ' ' . $field, 1, 1, 'L', $setColor, $pdf->PMA_links
['doc'][$this->_tableName
][$field]);
484 $pdf->PMA_PDF_setXScale($this->x
);
485 $pdf->SetFillColor(255);
487 /*if ($pdf->PageNo() > 1) {
488 $pdf->PMA_PDF_die(__('The scale factor is too small to fit the schema on one page'));
494 * Relation preferences/statistics
496 * This class fetches the table master and foreign fields positions
497 * and helps in generating the Table references and then connects
498 * master table's master field to foreign table's foreign key
501 * @name Relation_Stats
502 * @see PMA_Schema_PDF::SetDrawColor,PMA_Schema_PDF::PMA_PDF_setLineWidthScale,PMA_Schema_PDF::PMA_PDF_lineScale
512 public $xDest, $yDest;
516 * The "Relation_Stats" constructor
518 * @param string master_table The master table name
519 * @param string master_field The relation field in the master table
520 * @param string foreign_table The foreign table name
521 * @param string foreigh_field The relation field in the foreign table
522 * @see Relation_Stats::_getXy
524 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
526 $src_pos = $this->_getXy($master_table, $master_field);
527 $dest_pos = $this->_getXy($foreign_table, $foreign_field);
533 $src_left = $src_pos[0] - $this->wTick
;
534 $src_right = $src_pos[1] +
$this->wTick
;
535 $dest_left = $dest_pos[0] - $this->wTick
;
536 $dest_right = $dest_pos[1] +
$this->wTick
;
538 $d1 = abs($src_left - $dest_left);
539 $d2 = abs($src_right - $dest_left);
540 $d3 = abs($src_left - $dest_right);
541 $d4 = abs($src_right - $dest_right);
542 $d = min($d1, $d2, $d3, $d4);
545 $this->xSrc
= $src_pos[0];
547 $this->xDest
= $dest_pos[0];
549 } elseif ($d == $d2) {
550 $this->xSrc
= $src_pos[1];
552 $this->xDest
= $dest_pos[0];
554 } elseif ($d == $d3) {
555 $this->xSrc
= $src_pos[0];
557 $this->xDest
= $dest_pos[1];
560 $this->xSrc
= $src_pos[1];
562 $this->xDest
= $dest_pos[1];
565 $this->ySrc
= $src_pos[2];
566 $this->yDest
= $dest_pos[2];
570 * Gets arrows coordinates
572 * @param string table The current table name
573 * @param string column The relation column name
574 * @return array Arrows coordinates
577 private function _getXy($table, $column)
579 $pos = array_search($column, $table->fields
);
580 // x_left, x_right, y
581 return array($table->x
, $table->x + +
$table->width
, $table->y +
($pos +
1.5) * $table->heightCell
);
585 * draws relation links and arrows
586 * shows foreign key relations
588 * @param boolean changeColor Whether to use one color per relation or not
589 * @param integer i The id of the link to draw
590 * @global object The current PDF document
592 * @see PMA_Schema_PDF
594 public function relationDraw($changeColor, $i)
611 list ($a, $b, $c) = $case[$d];
612 $e = (1 - ($j - 1) / 6);
613 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
615 $pdf->SetDrawColor(0);
617 $pdf->PMA_PDF_setLineWidthScale(0.2);
618 $pdf->PMA_PDF_lineScale($this->xSrc
, $this->ySrc
, $this->xSrc +
$this->srcDir
* $this->wTick
, $this->ySrc
);
619 $pdf->PMA_PDF_lineScale($this->xDest +
$this->destDir
* $this->wTick
, $this->yDest
, $this->xDest
, $this->yDest
);
620 $pdf->PMA_PDF_setLineWidthScale(0.1);
621 $pdf->PMA_PDF_lineScale($this->xSrc +
$this->srcDir
* $this->wTick
, $this->ySrc
, $this->xDest +
$this->destDir
* $this->wTick
, $this->yDest
);
625 $root2 = 2 * sqrt(2);
626 $pdf->PMA_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);
627 $pdf->PMA_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);
629 $pdf->PMA_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);
630 $pdf->PMA_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);
631 $pdf->SetDrawColor(0);
636 * Pdf Relation Schema Class
638 * Purpose of this class is to generate the PDF Document. PDF is widely
639 * used format for documenting text,fonts,images and 3d vector graphics.
641 * This class inherits Export_Relation_Schema class has common functionality added
644 * @name Pdf_Relation_Schema
646 class PMA_Pdf_Relation_Schema
extends PMA_Export_Relation_Schema
651 private $_tables = array();
652 private $_relations = array();
653 private $_ff = PMA_PDF_FONT
;
657 private $_xMin = 100000;
658 private $_yMin = 100000;
659 private $topMargin = 10;
660 private $bottomMargin = 10;
661 private $leftMargin = 10;
662 private $rightMargin = 10;
663 private $_tablewidth;
666 * The "PMA_Pdf_Relation_Schema" constructor
668 * @global object The current PDF Schema document
669 * @global string The current db name
670 * @global array The relations settings
672 * @see PMA_Schema_PDF
674 function __construct()
676 global $pdf,$db,$cfgRelation;
678 $this->setPageNumber($_POST['pdf_page_number']);
679 $this->setShowGrid(isset($_POST['show_grid']));
680 $this->setShowColor(isset($_POST['show_color']));
681 $this->setShowKeys(isset($_POST['show_keys']));
682 $this->setTableDimension(isset($_POST['show_table_dimension']));
683 $this->setAllTableSameWidth(isset($_POST['all_table_same_wide']));
684 $this->setWithDataDictionary($_POST['with_doc']);
685 $this->setOrientation($_POST['orientation']);
686 $this->setPaper($_POST['paper']);
687 $this->setExportType($_POST['export_type']);
689 // Initializes a new document
690 $pdf = new PMA_Schema_PDF($this->orientation
, 'mm', $this->paper
);
691 $pdf->SetTitle(sprintf(__('Schema of the %s database - Page %s'), $GLOBALS['db'], $this->pageNumber
));
694 $pdf->SetAutoPageBreak('auto');
695 $alltables = $this->getAllTables($db,$this->pageNumber
);
697 if ($this->withDoc
) {
698 $pdf->SetAutoPageBreak('auto', 15);
700 $this->dataDictionaryDoc($alltables);
701 $pdf->SetAutoPageBreak('auto');
707 if ($this->withDoc
) {
708 $pdf->SetLink($pdf->PMA_links
['RT']['-'], -1);
709 $pdf->Bookmark(__('Relational schema'));
710 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
711 $this->topMargin
= 28;
712 $this->bottomMargin
= 28;
716 foreach ($alltables as $table) {
717 if (! isset($this->tables
[$table])) {
718 $this->tables
[$table] = new Table_Stats($table, $this->_ff
, $this->pageNumber
, $this->_tablewidth
, $this->showKeys
, $this->tableDimension
);
720 if ($this->sameWide
) {
721 $this->tables
[$table]->width
= $this->_tablewidth
;
723 $this->_setMinMax($this->tables
[$table]);
726 // Defines the scale factor
729 ($this->_xMax
- $this->_xMin
) / ($pdf->getPageWidth() - $this->rightMargin
- $this->leftMargin
),
730 ($this->_yMax
- $this->_yMin
) / ($pdf->getPageHeight() - $this->topMargin
- $this->bottomMargin
))
733 $pdf->PMA_PDF_setScale($this->scale
, $this->_xMin
, $this->_yMin
, $this->leftMargin
, $this->topMargin
);
734 // Builds and save the PDF document
735 $pdf->PMA_PDF_setLineWidthScale(0.1);
737 if ($this->showGrid
) {
738 $pdf->SetFontSize(10);
739 $this->_strokeGrid();
741 $pdf->PMA_PDF_setFontSizeScale(14);
742 // previous logic was checking master tables and foreign tables
743 // but I think that looping on every table of the pdf page as a master
744 // and finding its foreigns is OK (then we can support innodb)
745 $seen_a_relation = false;
746 foreach ($alltables as $one_table) {
747 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
749 $seen_a_relation = true;
750 foreach ($exist_rel as $master_field => $rel) {
751 // put the foreign table on the schema only if selected
753 // (do not use array_search() because we would have to
754 // to do a === false and this is not PHP3 compatible)
755 if (in_array($rel['foreign_table'], $alltables)) {
756 $this->_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->tableDimension
);
762 if ($seen_a_relation) {
763 $this->_drawRelations($this->showColor
);
765 $this->_drawTables($this->showColor
);
766 $this->_showOutput($this->pageNumber
);
771 * Sets X and Y minimum and maximum for a table cell
773 * @param string table The table name of which sets XY co-ordinates
776 private function _setMinMax($table)
778 $this->_xMax
= max($this->_xMax
, $table->x +
$table->width
);
779 $this->_yMax
= max($this->_yMax
, $table->y +
$table->height
);
780 $this->_xMin
= min($this->_xMin
, $table->x
);
781 $this->_yMin
= min($this->_yMin
, $table->y
);
785 * Defines relation objects
787 * @param string master_table The master table name
788 * @param string master_field The relation field in the master table
789 * @param string foreign_table The foreign table name
790 * @param string foreign_field The relation field in the foreign table
791 * @param boolean show_info Whether to display table position or not
795 private function _addRelation($masterTable, $masterField, $foreignTable, $foreignField, $showInfo)
797 if (! isset($this->tables
[$masterTable])) {
798 $this->tables
[$masterTable] = new Table_Stats($masterTable, $this->_ff
, $this->pageNumber
, $this->_tablewidth
, false, $showInfo);
799 $this->_setMinMax($this->tables
[$masterTable]);
801 if (! isset($this->tables
[$foreignTable])) {
802 $this->tables
[$foreignTable] = new Table_Stats($foreignTable, $this->_ff
, $this->pageNumber
, $this->_tablewidth
, false, $showInfo);
803 $this->_setMinMax($this->tables
[$foreignTable]);
805 $this->relations
[] = new Relation_Stats($this->tables
[$masterTable], $masterField, $this->tables
[$foreignTable], $foreignField);
811 * @global object the current PMA_Schema_PDF instance
813 * @see PMA_Schema_PDF
815 private function _strokeGrid()
822 if ($this->withDoc
) {
830 $pdf->SetMargins(0, 0);
831 $pdf->SetDrawColor(200, 200, 200);
832 // Draws horizontal lines
833 for ($l = 0; $l <= intval(($pdf->getPageHeight() - $topSpace - $bottomSpace) / $gridSize); $l++
) {
834 $pdf->line(0, $l * $gridSize +
$topSpace, $pdf->getPageWidth(), $l * $gridSize +
$topSpace);
836 if ($l > 0 && $l <= intval(($pdf->getPageHeight() - $topSpace - $bottomSpace - $labelHeight) / $gridSize)) {
837 $pdf->SetXY(0, $l * $gridSize +
$topSpace);
838 $label = (string) sprintf('%.0f', ($l * $gridSize +
$topSpace - $this->topMargin
) * $this->scale +
$this->_yMin
);
839 $pdf->Cell($labelWidth, $labelHeight, ' ' . $label);
842 // Draws vertical lines
843 for ($j = 0; $j <= intval($pdf->getPageWidth() / $gridSize); $j++
) {
844 $pdf->line($j * $gridSize, $topSpace, $j * $gridSize, $pdf->getPageHeight() - $bottomSpace);
845 $pdf->SetXY($j * $gridSize, $topSpace);
846 $label = (string) sprintf('%.0f', ($j * $gridSize - $this->leftMargin
) * $this->scale +
$this->_xMin
);
847 $pdf->Cell($labelWidth, $labelHeight, $label);
852 * Draws relation arrows
854 * @param boolean changeColor Whether to use one color per relation or not
856 * @see Relation_Stats::relationdraw()
858 private function _drawRelations($changeColor)
861 foreach ($this->relations
as $relation) {
862 $relation->relationDraw($changeColor, $i);
870 * @param boolean changeColor Whether to display table position or not
872 * @see Table_Stats::tableDraw()
874 private function _drawTables($changeColor = 0)
876 foreach ($this->tables
as $table) {
877 $table->tableDraw($this->_ff
, $this->withDoc
, $changeColor);
882 * Ouputs the PDF document to a file
883 * or sends the output to browser
885 * @global object The current PDF document
886 * @global string The current database name
887 * @global integer The current page number (from the
888 * $cfg['Servers'][$i]['table_coords'] table)
890 * @see PMA_Schema_PDF
892 private function _showOutput($pageNumber)
894 global $pdf, $db, $cfgRelation;
896 // Get the name of this pdfpage to use as filename
897 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
898 . ' WHERE page_nr = ' . $pageNumber;
899 $_name_rs = PMA_query_as_controluser($_name_sql);
901 $_name_row = PMA_DBI_fetch_row($_name_rs);
902 $filename = $_name_row[0] . '.pdf';
904 if (empty($filename)) {
905 $filename = $pageNumber . '.pdf';
907 $pdf->Download($filename);
910 public function dataDictionaryDoc($alltables)
912 global $db, $pdf, $orientation, $paper;
914 $pdf->addpage($GLOBALS['orientation']);
915 $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
918 foreach ($alltables as $table) {
919 $pdf->PMA_links
['doc'][$table]['-'] = $pdf->AddLink();
922 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links
['doc'][$table]['-']);
924 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links
['doc'][$table]['-']);
926 $fields = PMA_DBI_get_columns($GLOBALS['db'], $table);
927 foreach($fields as $row) {
929 $field_name = $row['Field'];
930 $pdf->PMA_links
['doc'][$table][$field_name] = $pdf->AddLink();
931 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
936 $pdf->PMA_links
['RT']['-'] = $pdf->AddLink();
938 $pdf->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links
['RT']['-']);
940 $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links
['RT']['-']);
942 foreach ($alltables as $table) {
944 $pdf->SetAutoPageBreak(true, 15);
945 $pdf->addpage($GLOBALS['orientation']);
946 $pdf->Bookmark($table);
947 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
948 $pdf->PMA_links
['RT'][$table]['-'] = $pdf->AddLink();
949 $pdf->SetLink($pdf->PMA_links
['doc'][$table]['-'], -1);
950 $pdf->SetFont($this->_ff
, 'B', 18);
951 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links
['RT'][$table]['-']);
952 $pdf->SetFont($this->_ff
, '', 8);
955 $cfgRelation = PMA_getRelationsParam();
956 $comments = PMA_getComments($db, $table);
957 if ($cfgRelation['mimework']) {
958 $mime_map = PMA_getMIME($db, $table, true);
962 * Gets table informations
964 $showtable = PMA_Table
::sGetStatusInfo($db, $table);
965 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
966 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
967 $create_time = (isset($showtable['Create_time']) ?
PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
968 $update_time = (isset($showtable['Update_time']) ?
PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
969 $check_time = (isset($showtable['Check_time']) ?
PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
972 * Gets table keys and retains them
974 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
978 $indexes_info = array();
979 $indexes_data = array();
980 $pk_array = array(); // will be use to emphasis prim. keys in the table
982 while ($row = PMA_DBI_fetch_assoc($result)) {
983 // Backups the list of primary keys
984 if ($row['Key_name'] == 'PRIMARY') {
985 $primary .= $row['Column_name'] . ', ';
986 $pk_array[$row['Column_name']] = 1;
988 // Retains keys informations
989 if ($row['Key_name'] != $lastIndex) {
990 $indexes[] = $row['Key_name'];
991 $lastIndex = $row['Key_name'];
993 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
994 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
995 if (isset($row['Cardinality'])) {
996 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
998 // I don't know what does following column mean....
999 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1000 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1002 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1003 if (isset($row['Sub_part'])) {
1004 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1008 PMA_DBI_free_result($result);
1012 * Gets fields properties
1014 $columns = PMA_DBI_get_columns($db, $table);
1015 // Check if we can use Relations
1016 if (!empty($cfgRelation['relation'])) {
1017 // Find which tables are related with the current one and write it in
1019 $res_rel = PMA_getForeigners($db, $table);
1021 if (count($res_rel) > 0) {
1031 * Displays the comments of the table if MySQL >= 3.23
1035 if (!empty($show_comment)) {
1036 $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
1040 if (!empty($create_time)) {
1041 $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
1045 if (!empty($update_time)) {
1046 $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
1050 if (!empty($check_time)) {
1051 $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
1055 if ($break == true) {
1056 $pdf->Cell(0, 3, '', 0, 1);
1060 $pdf->SetFont($this->_ff
, 'B');
1061 if (isset($orientation) && $orientation == 'L') {
1062 $pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
1063 $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
1064 $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
1065 $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
1066 $pdf->Cell(20, 8, __('Default'), 1, 0, 'C');
1067 $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
1068 $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
1070 if ($paper == 'A4') {
1071 $comments_width = 67;
1073 // this is really intended for 'letter'
1075 * @todo find optimal width for all formats
1077 $comments_width = 50;
1079 $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
1080 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1081 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1083 $pdf->Cell(20, 8, __('Column'), 1, 0, 'C');
1084 $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
1085 $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
1086 $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
1087 $pdf->Cell(15, 8, __('Default'), 1, 0, 'C');
1088 $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C');
1089 $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C');
1090 $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C');
1091 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1092 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1094 $pdf->SetFont($this->_ff
, '');
1096 foreach ($columns as $row) {
1097 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
1098 $type = $extracted_fieldspec['print_type'];
1099 $attribute = $extracted_fieldspec['attribute'];
1100 if (! isset($row['Default'])) {
1101 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1102 $row['Default'] = 'NULL';
1105 $field_name = $row['Field'];
1107 $pdf->PMA_links
['RT'][$table][$field_name] = $pdf->AddLink();
1108 $pdf->Bookmark($field_name, 1, -1);
1109 $pdf->SetLink($pdf->PMA_links
['doc'][$table][$field_name], -1);
1110 $pdf_row = array($field_name,
1113 ($row['Null'] == '' ||
$row['Null'] == 'NO') ?
__('No') : __('Yes'),
1114 ((isset($row['Default'])) ?
$row['Default'] : ''),
1116 ((isset($res_rel[$field_name])) ?
$res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1117 ((isset($comments[$field_name])) ?
$comments[$field_name] : ''),
1118 ((isset($mime_map) && isset($mime_map[$field_name])) ?
str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1120 $links[0] = $pdf->PMA_links
['RT'][$table][$field_name];
1121 if (isset($res_rel[$field_name]['foreign_table']) AND
1122 isset($res_rel[$field_name]['foreign_field']) AND
1123 isset($pdf->PMA_links
['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1126 $links[6] = $pdf->PMA_links
['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1130 $pdf->Row($pdf_row, $links);
1132 $pdf->SetFont($this->_ff
, '', 14);