Merge branch 'QA_3_3'
[phpmyadmin/dkf.git] / pdf_schema.php
blob8b709b5f861bfd4fe11fc5496a6d0a5da6393d3e
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
10 * Gets some core scripts
12 require_once './libraries/common.inc.php';
14 /**
15 * Settings for relation stuff
17 require_once './libraries/relation.lib.php';
18 require_once './libraries/transformations.lib.php';
19 require_once './libraries/Index.class.php';
21 $cfgRelation = PMA_getRelationsParam();
23 /**
24 * Now in ./libraries/relation.lib.php we check for all tables
25 * that we need, but if we don't find them we are quiet about it
26 * so people can work without.
27 * This page is absolutely useless if you didn't set up your tables
28 * correctly, so it is a good place to see which tables we can and
29 * complain ;-)
31 if (!$cfgRelation['pdfwork']) {
32 echo '<font color="red">' . __('Error') . '</font><br />' . "\n";
33 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
34 echo sprintf(__('The additional features for working with linked tables have been deactivated. To find out why click %shere%s.'), $url_to_goto, '</a>') . "\n";
37 /**
38 * Font used in PDF.
40 * @todo Make this configuratble (at least Sans/Serif).
42 define('PMA_PDF_FONT', 'DejaVuSans');
43 require_once './libraries/tcpdf/tcpdf.php';
45 /**
46 * Extends the "FPDF" class and prepares the work
48 * @access public
49 * @see FPDF
50 * @package phpMyAdmin
52 class PMA_PDF extends TCPDF {
53 /**
54 * Defines private properties
56 var $x_min;
57 var $y_min;
58 var $l_marg = 10;
59 var $t_marg = 10;
60 var $scale;
61 var $PMA_links;
62 var $Outlines = array();
63 var $def_outlines;
64 var $Alias = array();
65 var $widths;
67 public function getFh()
69 return $this->fh;
72 public function getFw()
74 return $this->fw;
77 public function setCMargin($c_margin)
79 $this->cMargin = $c_margin;
82 function SetAlias($name, $value)
84 $this->Alias[$name] = $value ;
87 function _putpages()
89 if (count($this->Alias) > 0) {
90 $nb = $this->page;
91 foreach ($this->Alias AS $alias => $value) {
92 for ($n = 1;$n <= $nb;$n++)
93 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
96 parent::_putpages();
99 /**
100 * Sets the scaling factor, defines minimum coordinates and margins
102 * @param float scale The scaling factor
103 * @param float x_min The minimum X coordinate
104 * @param float y_min The minimum Y coordinate
105 * @param float l_marg The left margin
106 * @param float t_marg The top margin
107 * @access public
109 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
111 $this->scale = $scale;
112 $this->x_min = $x_min;
113 $this->y_min = $y_min;
114 if ($this->l_marg != -1) {
115 $this->l_marg = $l_marg;
117 if ($this->t_marg != -1) {
118 $this->t_marg = $t_marg;
120 } // end of the "PMA_PDF_setScale" function
122 * Outputs a scaled cell
124 * @param float w The cell width
125 * @param float h The cell height
126 * @param string txt The text to output
127 * @param mixed border Whether to add borders or not
128 * @param integer ln Where to put the cursor once the output is done
129 * @param string align Align mode
130 * @param integer fill Whether to fill the cell with a color or not
131 * @access public
132 * @see FPDF::Cell()
134 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
136 $h = $h / $this->scale;
137 $w = $w / $this->scale;
138 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
139 } // end of the "PMA_PDF_cellScale" function
141 * Draws a scaled line
143 * @param float x1 The horizontal position of the starting point
144 * @param float y1 The vertical position of the starting point
145 * @param float x2 The horizontal position of the ending point
146 * @param float y2 The vertical position of the ending point
147 * @access public
148 * @see FPDF::Line()
150 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
152 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
153 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
154 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
155 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
156 $this->Line($x1, $y1, $x2, $y2);
157 } // end of the "PMA_PDF_lineScale" function
159 * Sets x and y scaled positions
161 * @param float x The x position
162 * @param float y The y position
163 * @access public
164 * @see FPDF::SetXY()
166 function PMA_PDF_setXyScale($x, $y)
168 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
169 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
170 $this->SetXY($x, $y);
171 } // end of the "PMA_PDF_setXyScale" function
173 * Sets the X scaled positions
175 * @param float x The x position
176 * @access public
177 * @see FPDF::SetX()
179 function PMA_PDF_setXScale($x)
181 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
182 $this->SetX($x);
183 } // end of the "PMA_PDF_setXScale" function
185 * Sets the scaled font size
187 * @param float size The font size (in points)
188 * @access public
189 * @see FPDF::SetFontSize()
191 function PMA_PDF_setFontSizeScale($size)
193 // Set font size in points
194 $size = $size / $this->scale;
195 $this->SetFontSize($size);
196 } // end of the "PMA_PDF_setFontSizeScale" function
198 * Sets the scaled line width
200 * @param float width The line width
201 * @access public
202 * @see FPDF::SetLineWidth()
204 function PMA_PDF_setLineWidthScale($width)
206 $width = $width / $this->scale;
207 $this->SetLineWidth($width);
208 } // end of the "PMA_PDF_setLineWidthScale" function
210 * Displays an error message
212 * @param string error_message the error mesage
213 * @global array the PMA configuration array
214 * @global integer the current server id
215 * @global string the current language
216 * @global string the charset to convert to
217 * @global string the current database name
218 * @global string the current charset
219 * @global string the current text direction
220 * @global string a localized string
221 * @global string an other localized string
222 * @access public
224 function PMA_PDF_die($error_message = '')
226 global $cfg;
227 global $server, $lang, $convcharset, $db;
228 global $charset, $text_dir;
230 require_once './libraries/header.inc.php';
232 echo '<p><strong>PDF - ' . $GLOBALS['strError'] . '</strong></p>' . "\n";
233 if (!empty($error_message)) {
234 $error_message = htmlspecialchars($error_message);
236 echo '<p>' . "\n";
237 echo ' ' . $error_message . "\n";
238 echo '</p>' . "\n";
240 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
241 . '">' . $GLOBALS['strBack'] . '</a>';
242 echo "\n";
244 require_once './libraries/footer.inc.php';
245 } // end of the "PMA_PDF_die()" function
247 * Aliases the "Error()" function from the FPDF class to the
248 * "PMA_PDF_die()" one
250 * @param string error_message the error mesage
251 * @access public
252 * @see PMA_PDF_die
254 function Error($error_message = '')
256 $this->PMA_PDF_die($error_message);
257 } // end of the "Error()" method
258 function Header()
260 // $datefmt
261 // We only show this if we find something in the new pdf_pages table
263 // This function must be named "Header" to work with the FPDF library
264 global $cfgRelation, $db, $pdf_page_number, $with_doc;
265 if ($with_doc) {
266 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
267 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
268 . ' AND page_nr = \'' . $pdf_page_number . '\'';
269 $test_rs = PMA_query_as_controluser($test_query);
270 $pages = @PMA_DBI_fetch_assoc($test_rs);
271 $this->SetFont('', 'B', 14);
272 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
273 $this->SetFont('', '');
274 $this->Ln();
277 function Footer()
279 // This function must be named "Footer" to work with the FPDF library
280 global $with_doc;
281 if ($with_doc) {
282 $this->SetY(-15);
283 $this->SetFont('', '', 14);
284 $this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
285 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
286 $this->SetY(20);
289 function Bookmark($txt, $level = 0, $y = 0)
291 // Add a bookmark
292 $this->Outlines[0][] = $level;
293 $this->Outlines[1][] = $txt;
294 $this->Outlines[2][] = $this->page;
295 if ($y == -1) {
296 $y = $this->GetY();
298 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
301 function _putbookmarks()
303 if (count($this->Outlines) > 0) {
304 // Save object number
305 $memo_n = $this->n;
306 // Take the number of sub elements for an outline
307 $nb_outlines = sizeof($this->Outlines[0]);
308 $first_level = array();
309 $parent = array();
310 $parent[0] = 1;
311 for ($i = 0; $i < $nb_outlines; $i++) {
312 $level = $this->Outlines[0][$i];
313 $kids = 0;
314 $last = -1;
315 $prev = -1;
316 $next = -1;
317 if ($i > 0) {
318 $cursor = $i-1;
319 // Take the previous outline in the same level
320 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
321 $cursor--;
322 if ($this->Outlines[0][$cursor] == $level) {
323 $prev = $cursor;
326 if ($i < $nb_outlines-1) {
327 $cursor = $i + 1;
328 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
329 // Take the immediate kid in level + 1
330 if ($this->Outlines[0][$cursor] == $level + 1) {
331 $kids++;
332 $last = $cursor;
334 $cursor++;
336 $cursor = $i + 1;
337 // Take the next outline in the same level
338 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
339 $cursor++;
340 if ($this->Outlines[0][$cursor] == $level) {
341 $next = $cursor;
344 $this->_newobj();
345 $parent[$level + 1] = $this->n;
346 if ($level == 0) {
347 $first_level[] = $this->n;
349 $this->_out('<<');
350 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
351 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
352 if ($prev != -1) {
353 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
355 if ($next != -1) {
356 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
358 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
359 if ($kids > 0) {
360 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
361 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
362 $this->_out('/Count -' . $kids);
364 $this->_out('>>');
365 $this->_out('endobj');
367 // First page of outlines
368 $this->_newobj();
369 $this->def_outlines = $this->n;
370 $this->_out('<<');
371 $this->_out('/Type');
372 $this->_out('/Outlines');
373 $this->_out('/First ' . $first_level[0] . ' 0 R');
374 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
375 $this->_out('/Count ' . sizeof($first_level));
376 $this->_out('>>');
377 $this->_out('endobj');
381 function _putresources()
383 parent::_putresources();
384 $this->_putbookmarks();
387 function _putcatalog()
389 parent::_putcatalog();
390 if (count($this->Outlines) > 0) {
391 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
392 $this->_out('/PageMode /UseOutlines');
395 function SetWidths($w)
397 // column widths
398 $this->widths = $w;
401 function Row($data, $links)
403 // line height
404 $nb = 0;
405 $data_cnt = count($data);
406 for ($i = 0;$i < $data_cnt;$i++)
407 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
408 $il = $this->FontSize;
409 $h = ($il + 1) * $nb;
410 // page break if necessary
411 $this->CheckPageBreak($h);
412 // draw the cells
413 $data_cnt = count($data);
414 for ($i = 0;$i < $data_cnt;$i++) {
415 $w = $this->widths[$i];
416 // save current position
417 $x = $this->GetX();
418 $y = $this->GetY();
419 // draw the border
420 $this->Rect($x, $y, $w, $h);
421 if (isset($links[$i])) {
422 $this->Link($x, $y, $w, $h, $links[$i]);
424 // print text
425 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
426 // go to right side
427 $this->SetXY($x + $w, $y);
429 // go to line
430 $this->Ln($h);
433 function CheckPageBreak($h)
435 // if height h overflows, manual page break
436 if ($this->GetY() + $h > $this->PageBreakTrigger) {
437 $this->AddPage($this->CurOrientation);
441 function NbLines($w, $txt)
443 // compute number of lines used by a multicell of width w
444 $cw = &$this->CurrentFont['cw'];
445 if ($w == 0) {
446 $w = $this->w - $this->rMargin - $this->x;
448 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
449 $s = str_replace("\r", '', $txt);
450 $nb = strlen($s);
451 if ($nb > 0 and $s[$nb-1] == "\n") {
452 $nb--;
454 $sep = -1;
455 $i = 0;
456 $j = 0;
457 $l = 0;
458 $nl = 1;
459 while ($i < $nb) {
460 $c = $s[$i];
461 if ($c == "\n") {
462 $i++;
463 $sep = -1;
464 $j = $i;
465 $l = 0;
466 $nl++;
467 continue;
469 if ($c == ' ') {
470 $sep = $i;
472 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
473 if ($l > $wmax) {
474 if ($sep == -1) {
475 if ($i == $j) {
476 $i++;
478 } else {
479 $i = $sep + 1;
481 $sep = -1;
482 $j = $i;
483 $l = 0;
484 $nl++;
485 } else {
486 $i++;
489 return $nl;
491 } // end of the "PMA_PDF" class
495 * Draws tables schema
497 * @access private
498 * @see PMA_RT
499 * @package phpMyAdmin
501 class PMA_RT_Table {
503 * Defines private properties
505 var $nb_fiels;
506 var $table_name;
507 var $width = 0;
508 var $height;
509 var $fields = array();
510 var $height_cell = 6;
511 var $x, $y;
512 var $primary = array();
513 var $show_info = false;
516 * Returns title of the current table,
517 * title can have the dimensions of the table
519 * @access private
521 function getTitle()
523 return ($this->show_info ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) : '') . ' ' . $this->table_name;
524 } // end of the "getTitle" function
526 * Sets the width of the table
528 * @param integer ff The font size
529 * @global object The current PDF document
530 * @access private
531 * @see PMA_PDF
533 function PMA_RT_Table_setWidth($ff)
535 global $pdf;
537 foreach ($this->fields AS $field) {
538 $this->width = max($this->width, $pdf->GetStringWidth($field));
540 $this->width += $pdf->GetStringWidth(' ');
541 $pdf->SetFont($ff, 'B');
542 // it is unknown what value must be added, because
543 // table title is affected by the tabe width value
544 while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
545 $this->width += 5;
547 $pdf->SetFont($ff, '');
548 } // end of the "PMA_RT_Table_setWidth()" method
550 * Sets the height of the table
552 * @access private
554 function PMA_RT_Table_setHeight()
556 $this->height = (count($this->fields) + 1) * $this->height_cell;
557 } // end of the "PMA_RT_Table_setHeight()" method
559 * Do draw the table
561 * @param integer ff The font size
562 * @param boolean setcolortWhether to display color
563 * @global object The current PDF document
564 * @access private
565 * @see PMA_PDF
567 function PMA_RT_Table_draw($ff, $setcolor = 0)
569 global $pdf, $with_doc;
571 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
572 $pdf->SetFont($ff, 'B');
573 if ($setcolor) {
574 $pdf->SetTextColor(200);
575 $pdf->SetFillColor(0, 0, 128);
577 if ($with_doc) {
578 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
579 } else {
580 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
583 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->getTitle(), 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
584 $pdf->PMA_PDF_setXScale($this->x);
585 $pdf->SetFont($ff, '');
586 $pdf->SetTextColor(0);
587 $pdf->SetFillColor(255);
589 foreach ($this->fields AS $field) {
590 if ($setcolor) {
591 if (in_array($field, $this->primary)) {
592 $pdf->SetFillColor(215, 121, 123);
594 if ($field == $this->displayfield) {
595 $pdf->SetFillColor(142, 159, 224);
598 if ($with_doc) {
599 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
600 } else {
601 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
604 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
605 $pdf->PMA_PDF_setXScale($this->x);
606 $pdf->SetFillColor(255);
607 } // end while
608 /*if ($pdf->PageNo() > 1) {
609 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
610 } */
611 } // end of the "PMA_RT_Table_draw()" method
613 * The "PMA_RT_Table" constructor
615 * @param string table_name The table name
616 * @param integer ff The font size
617 * @param integer same_width The max. with among tables
618 * @param boolean show_keys Whether to display keys or not
619 * @param boolean show_info Whether to display table position or not
620 * @global object The current PDF document
621 * @global integer The current page number (from the
622 * $cfg['Servers'][$i]['table_coords'] table)
623 * @global array The relations settings
624 * @global string The current db name
625 * @access private
626 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
627 PMA_RT_Table::PMA_RT_Table_setHeight
629 function __construct($table_name, $ff, &$same_wide_width, $show_keys = false, $show_info = false)
631 global $pdf, $pdf_page_number, $cfgRelation, $db;
633 $this->table_name = $table_name;
634 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
635 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
636 if (!$result || !PMA_DBI_num_rows($result)) {
637 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
639 // load fields
640 //check to see if it will load all fields or only the foreign keys
641 if ($show_keys) {
642 $indexes = PMA_Index::getFromTable($this->table_name, $db);
643 $all_columns = array();
644 foreach ($indexes as $index) {
645 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
647 $this->fields = array_keys($all_columns);
648 } else {
649 while ($row = PMA_DBI_fetch_row($result)) {
650 $this->fields[] = $row[0];
654 $this->show_info = $show_info;
656 // height and width
657 $this->PMA_RT_Table_setHeight();
658 // setWidth must me after setHeight, because title
659 // can include table height which changes table width
660 $this->PMA_RT_Table_setWidth($ff);
661 if ($same_wide_width < $this->width) {
662 $same_wide_width = $this->width;
664 // x and y
665 $sql = 'SELECT x, y FROM '
666 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
667 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
668 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
669 . ' AND pdf_page_number = ' . $pdf_page_number;
670 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
672 if (!$result || !PMA_DBI_num_rows($result)) {
673 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
675 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
676 $this->x = (double) $this->x;
677 $this->y = (double) $this->y;
678 // displayfield
679 $this->displayfield = PMA_getDisplayField($db, $table_name);
680 // index
681 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
682 if (PMA_DBI_num_rows($result) > 0) {
683 while ($row = PMA_DBI_fetch_assoc($result)) {
684 if ($row['Key_name'] == 'PRIMARY') {
685 $this->primary[] = $row['Column_name'];
688 } // end if
689 } // end of the "PMA_RT_Table()" method
690 } // end class "PMA_RT_Table"
692 * Draws relation links
694 * @access private
695 * @see PMA_RT
696 * @package phpMyAdmin
698 class PMA_RT_Relation {
700 * Defines private properties
702 var $x_src, $y_src;
703 var $src_dir ;
704 var $dest_dir;
705 var $x_dest, $y_dest;
706 var $w_tick = 5;
709 * Gets arrows coordinates
711 * @param string table The current table name
712 * @param string column The relation column name
713 * @return array Arrows coordinates
714 * @access private
716 function PMA_RT_Relation_getXy($table, $column)
718 $pos = array_search($column, $table->fields);
719 // x_left, x_right, y
720 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
721 } // end of the "PMA_RT_Relation_getXy()" method
723 * Do draws relation links
725 * @param boolean change_color Whether to use one color per relation or not
726 * @param integer i The id of the link to draw
727 * @global object The current PDF document
728 * @access private
729 * @see PMA_PDF
731 function PMA_RT_Relation_draw($change_color, $i)
733 global $pdf;
735 if ($change_color) {
736 $d = $i % 6;
737 $j = ($i - $d) / 6;
738 $j = $j % 4;
739 $j++;
740 $case = array(
741 array(1, 0, 0),
742 array(0, 1, 0),
743 array(0, 0, 1),
744 array(1, 1, 0),
745 array(1, 0, 1),
746 array(0, 1, 1)
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);
751 } else {
752 $pdf->SetDrawColor(0);
753 } // end if... else...
754 $pdf->PMA_PDF_setLineWidthScale(0.2);
755 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
756 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
757 $pdf->PMA_PDF_setLineWidthScale(0.1);
758 $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick, $this->y_src, $this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest);
759 // arrow
760 $root2 = 2 * sqrt(2);
761 $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src + $this->w_tick / $root2);
762 $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src - $this->w_tick / $root2);
764 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick / 2, $this->y_dest, $this->x_dest + $this->dest_dir * (0.5 + 1 / $root2) * $this->w_tick, $this->y_dest + $this->w_tick / $root2);
765 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick / 2, $this->y_dest, $this->x_dest + $this->dest_dir * (0.5 + 1 / $root2) * $this->w_tick, $this->y_dest - $this->w_tick / $root2);
766 $pdf->SetDrawColor(0);
767 } // end of the "PMA_RT_Relation_draw()" method
769 * The "PMA_RT_Relation" constructor
771 * @param string master_table The master table name
772 * @param string master_field The relation field in the master table
773 * @param string foreign_table The foreign table name
774 * @param string foreigh_field The relation field in the foreign table
775 * @access private
776 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
778 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
780 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
781 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
782 $src_left = $src_pos[0] - $this->w_tick;
783 $src_right = $src_pos[1] + $this->w_tick;
784 $dest_left = $dest_pos[0] - $this->w_tick;
785 $dest_right = $dest_pos[1] + $this->w_tick;
787 $d1 = abs($src_left - $dest_left);
788 $d2 = abs($src_right - $dest_left);
789 $d3 = abs($src_left - $dest_right);
790 $d4 = abs($src_right - $dest_right);
791 $d = min($d1, $d2, $d3, $d4);
793 if ($d == $d1) {
794 $this->x_src = $src_pos[0];
795 $this->src_dir = -1;
796 $this->x_dest = $dest_pos[0];
797 $this->dest_dir = -1;
798 } elseif ($d == $d2) {
799 $this->x_src = $src_pos[1];
800 $this->src_dir = 1;
801 $this->x_dest = $dest_pos[0];
802 $this->dest_dir = -1;
803 } elseif ($d == $d3) {
804 $this->x_src = $src_pos[0];
805 $this->src_dir = -1;
806 $this->x_dest = $dest_pos[1];
807 $this->dest_dir = 1;
808 } else {
809 $this->x_src = $src_pos[1];
810 $this->src_dir = 1;
811 $this->x_dest = $dest_pos[1];
812 $this->dest_dir = 1;
814 $this->y_src = $src_pos[2];
815 $this->y_dest = $dest_pos[2];
816 } // end of the "PMA_RT_Relation()" method
817 } // end of the "PMA_RT_Relation" class
819 * Draws and send the database schema
821 * @access public
822 * @see PMA_PDF
823 * @package phpMyAdmin
825 class PMA_RT {
827 * Defines private properties
829 var $tables = array();
830 var $relations = array();
831 var $ff = PMA_PDF_FONT;
832 var $x_max = 0;
833 var $y_max = 0;
834 var $scale;
835 var $x_min = 100000;
836 var $y_min = 100000;
837 var $t_marg = 10;
838 var $b_marg = 10;
839 var $l_marg = 10;
840 var $r_marg = 10;
841 var $tablewidth;
842 var $same_wide = 0;
845 * Sets X and Y minimum and maximum for a table cell
847 * @param string table The table name
848 * @access private
850 function PMA_RT_setMinMax($table)
852 $this->x_max = max($this->x_max, $table->x + $table->width);
853 $this->y_max = max($this->y_max, $table->y + $table->height);
854 $this->x_min = min($this->x_min, $table->x);
855 $this->y_min = min($this->y_min, $table->y);
856 } // end of the "PMA_RT_setMinMax()" method
858 * Defines relation objects
860 * @param string master_table The master table name
861 * @param string master_field The relation field in the master table
862 * @param string foreign_table The foreign table name
863 * @param string foreign_field The relation field in the foreign table
864 * @param boolean show_info Whether to display table position or not
865 * @access private
866 * @see PMA_RT_setMinMax
868 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field, $show_info)
870 if (!isset($this->tables[$master_table])) {
871 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth, false, $show_info);
872 $this->PMA_RT_setMinMax($this->tables[$master_table]);
874 if (!isset($this->tables[$foreign_table])) {
875 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth, false, $show_info);
876 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
878 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
879 } // end of the "PMA_RT_addRelation()" method
881 * Draws the grid
883 * @global object the current PMA_PDF instance
884 * @access private
885 * @see PMA_PDF
887 function PMA_RT_strokeGrid()
889 global $pdf;
891 $pdf->SetMargins(0, 0);
892 $pdf->SetDrawColor(200, 200, 200);
893 // Draws horizontal lines
894 for ($l = 0; $l < 21; $l++) {
895 $pdf->line(0, $l * 10, $pdf->getFh(), $l * 10);
896 // Avoid duplicates
897 if ($l > 0) {
898 $pdf->SetXY(0, $l * 10);
899 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
900 $pdf->Cell(5, 5, ' ' . $label);
901 } // end if
902 } // end for
903 // Draws vertical lines
904 for ($j = 0; $j < 30 ;$j++) {
905 $pdf->line($j * 10, 0, $j * 10, $pdf->getFw());
906 $pdf->SetXY($j * 10, 0);
907 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
908 $pdf->Cell(5, 7, $label);
909 } // end for
910 } // end of the "PMA_RT_strokeGrid()" method
912 * Draws relation arrows
914 * @param boolean change_color Whether to use one color per relation or not
915 * @access private
916 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
918 function PMA_RT_drawRelations($change_color)
920 $i = 0;
921 foreach ($this->relations AS $relation) {
922 $relation->PMA_RT_Relation_draw($change_color, $i);
923 $i++;
924 } // end while
925 } // end of the "PMA_RT_drawRelations()" method
927 * Draws tables
929 * @param boolean draw_color Whether to display table position or not
930 * @access private
931 * @see PMA_RT_Table::PMA_RT_Table_draw()
933 function PMA_RT_drawTables($draw_color = 0)
935 foreach ($this->tables AS $table) {
936 $table->PMA_RT_Table_draw($this->ff, $draw_color);
938 } // end of the "PMA_RT_drawTables()" method
940 * Ouputs the PDF document to a file
942 * @global object The current PDF document
943 * @global string The current database name
944 * @global integer The current page number (from the
945 * $cfg['Servers'][$i]['table_coords'] table)
946 * @access private
947 * @see PMA_PDF
949 function PMA_RT_showRt()
951 global $pdf, $db, $pdf_page_number, $cfgRelation;
953 $pdf->SetFontSize(14);
954 $pdf->SetLineWidth(0.2);
955 $pdf->SetDisplayMode('fullpage');
956 // Get the name of this pdfpage to use as filename (Mike Beck)
957 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
958 . ' WHERE page_nr = ' . $pdf_page_number;
959 $_name_rs = PMA_query_as_controluser($_name_sql);
960 if ($_name_rs) {
961 $_name_row = PMA_DBI_fetch_row($_name_rs);
962 $filename = $_name_row[0] . '.pdf';
964 // i don't know if there is a chance for this to happen, but rather be on the safe side:
965 if (empty($filename)) {
966 $filename = $pdf_page_number . '.pdf';
968 // $pdf->Output($db . '_' . $filename, TRUE);
969 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
970 } // end of the "PMA_RT_showRt()" method
972 * The "PMA_RT" constructor
974 * @param integer which_rel The page number to draw (from the
975 * $cfg['Servers'][$i]['table_coords'] table)
976 * @param boolean show_info Whether to display table position or not
977 * @param boolean change_color Was originally whether to use one color per
978 * relation or not, now enables/disables color
979 * everywhere, due to some problems printing with color
980 * @param boolean show_grid Whether to draw grids or not
981 * @param boolean all_tab_same_wide Whether all tables should have the same width or not
982 * @param boolean show_keys Wheter to show all field or only the keys
983 * @global object The current PDF document
984 * @global string The current db name
985 * @global array The relations settings
986 * @access private
987 * @see PMA_PDF
989 function __construct($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4', $show_keys = 0)
991 global $pdf, $db, $cfgRelation, $with_doc;
993 $this->same_wide = $all_tab_same_wide;
994 // Initializes a new document
995 $pdf = new PMA_PDF('L', 'mm', $paper);
996 $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
997 $pdf->setCMargin(0);
998 $pdf->Open();
999 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
1000 $pdf->AliasNbPages();
1001 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
1002 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
1003 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
1004 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
1005 $this->ff = PMA_PDF_FONT;
1006 $pdf->SetFont($this->ff, '', 14);
1007 $pdf->SetAutoPageBreak('auto');
1008 // Gets tables on this page
1009 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
1010 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1011 . ' AND pdf_page_number = ' . $which_rel;
1012 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
1013 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1014 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
1015 // die('No tables');
1016 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1017 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1018 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1020 // make doc //
1021 if ($with_doc) {
1022 $pdf->SetAutoPageBreak('auto', 15);
1023 $pdf->setCMargin(1);
1024 PMA_RT_DOC($alltables);
1025 $pdf->SetAutoPageBreak('auto');
1026 $pdf->setCMargin(0);
1029 $pdf->Addpage();
1031 if ($with_doc) {
1032 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1033 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1034 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1035 $this->t_marg = 18;
1036 $this->b_marg = 18;
1039 /* snip */
1041 foreach ($alltables AS $table) {
1042 if (!isset($this->tables[$table])) {
1043 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys, $show_info);
1046 if ($this->same_wide) {
1047 $this->tables[$table]->width = $this->tablewidth;
1049 $this->PMA_RT_setMinMax($this->tables[$table]);
1051 // Defines the scale factor
1052 $this->scale = ceil(
1053 max(
1054 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1055 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1056 * 100) / 100;
1058 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1059 // Builds and save the PDF document
1060 $pdf->PMA_PDF_setLineWidthScale(0.1);
1062 if ($show_grid) {
1063 $pdf->SetFontSize(10);
1064 $this->PMA_RT_strokeGrid();
1066 $pdf->PMA_PDF_setFontSizeScale(14);
1067 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1068 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1069 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1070 // . ' AND master_table IN (' . $intable . ')'
1071 // . ' AND foreign_table IN (' . $intable . ')';
1072 // $result = PMA_query_as_controluser($sql);
1074 // previous logic was checking master tables and foreign tables
1075 // but I think that looping on every table of the pdf page as a master
1076 // and finding its foreigns is OK (then we can support innodb)
1077 $seen_a_relation = false;
1078 foreach ($alltables AS $one_table) {
1079 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1080 if ($exist_rel) {
1081 $seen_a_relation = true;
1082 foreach ($exist_rel AS $master_field => $rel) {
1083 // put the foreign table on the schema only if selected
1084 // by the user
1085 // (do not use array_search() because we would have to
1086 // to do a === FALSE and this is not PHP3 compatible)
1087 if (in_array($rel['foreign_table'], $alltables)) {
1088 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info);
1090 } // end while
1091 } // end if
1092 } // end while
1093 // also show tables without relations
1094 // $norelations = TRUE;
1095 // if ($result && PMA_DBI_num_rows($result) > 0) {
1096 // $norelations = FALSE;
1097 // while ($row = PMA_DBI_fetch_assoc($result)) {
1098 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1099 // }
1100 // }
1101 // if ($norelations == FALSE) {
1102 if ($seen_a_relation) {
1103 $this->PMA_RT_drawRelations($change_color);
1106 $this->PMA_RT_drawTables($change_color);
1108 $this->PMA_RT_showRt();
1109 } // end of the "PMA_RT()" method
1110 } // end of the "PMA_RT" class
1112 function PMA_RT_DOC($alltables)
1114 global $db, $pdf, $orientation, $paper;
1115 // TOC
1116 $pdf->addpage($GLOBALS['orientation']);
1117 $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C');
1118 $pdf->Ln(15);
1119 $i = 1;
1120 foreach ($alltables AS $table) {
1121 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1122 $pdf->SetX(10);
1123 // $pdf->Ln(1);
1124 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1125 $pdf->SetX(10);
1126 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1127 // $pdf->Ln(1);
1128 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1129 while ($row = PMA_DBI_fetch_assoc($result)) {
1130 $pdf->SetX(20);
1131 $field_name = $row['Field'];
1132 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1133 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1135 $lasttable = $table;
1136 $i++;
1138 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1139 $pdf->SetX(10);
1140 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1141 $pdf->SetX(10);
1142 $pdf->Cell(0, 6, $i + 1 . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1143 $z = 0;
1144 foreach ($alltables AS $table) {
1145 $z++;
1146 $pdf->addpage($GLOBALS['orientation']);
1147 $pdf->Bookmark($table);
1148 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1149 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1150 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1151 $pdf->SetFont('', 'B', 18);
1152 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1153 $pdf->SetFont('', '', 8);
1154 $pdf->ln();
1156 $cfgRelation = PMA_getRelationsParam();
1157 $comments = PMA_getComments($db, $table);
1158 if ($cfgRelation['mimework']) {
1159 $mime_map = PMA_getMIME($db, $table, true);
1163 * Gets table informations
1165 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1166 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1167 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1168 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1169 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1170 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1173 * Gets table keys and retains them
1175 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1176 $primary = '';
1177 $indexes = array();
1178 $lastIndex = '';
1179 $indexes_info = array();
1180 $indexes_data = array();
1181 $pk_array = array(); // will be use to emphasis prim. keys in the table
1182 // view
1183 while ($row = PMA_DBI_fetch_assoc($result)) {
1184 // Backups the list of primary keys
1185 if ($row['Key_name'] == 'PRIMARY') {
1186 $primary .= $row['Column_name'] . ', ';
1187 $pk_array[$row['Column_name']] = 1;
1189 // Retains keys informations
1190 if ($row['Key_name'] != $lastIndex) {
1191 $indexes[] = $row['Key_name'];
1192 $lastIndex = $row['Key_name'];
1194 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1195 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1196 if (isset($row['Cardinality'])) {
1197 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1199 // I don't know what does following column mean....
1200 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1201 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1203 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1204 if (isset($row['Sub_part'])) {
1205 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1207 } // end while
1208 if ($result) {
1209 PMA_DBI_free_result($result);
1213 * Gets fields properties
1215 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1216 $fields_cnt = PMA_DBI_num_rows($result);
1217 // Check if we can use Relations (Mike Beck)
1218 if (!empty($cfgRelation['relation'])) {
1219 // Find which tables are related with the current one and write it in
1220 // an array
1221 $res_rel = PMA_getForeigners($db, $table);
1223 if (count($res_rel) > 0) {
1224 $have_rel = true;
1225 } else {
1226 $have_rel = false;
1228 } else {
1229 $have_rel = false;
1230 } // end if
1232 * Displays the comments of the table if MySQL >= 3.23
1235 $break = false;
1236 if (!empty($show_comment)) {
1237 $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1);
1238 $break = true;
1241 if (!empty($create_time)) {
1242 $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1);
1243 $break = true;
1246 if (!empty($update_time)) {
1247 $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1);
1248 $break = true;
1251 if (!empty($check_time)) {
1252 $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1);
1253 $break = true;
1256 if ($break == true) {
1257 $pdf->Cell(0, 3, '', 0, 1);
1258 $pdf->Ln();
1261 $pdf->SetFont('', 'B');
1262 if (isset($orientation) && $orientation == 'L') {
1263 $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1264 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1265 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1266 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1267 $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1268 $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1269 $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1271 if ($paper == 'A4') {
1272 $comments_width = 67;
1273 } else {
1274 // this is really intended for 'letter'
1276 * @todo find optimal width for all formats
1278 $comments_width = 50;
1280 $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1281 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1282 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1283 } else {
1284 $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1285 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1286 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1287 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1288 $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1289 $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1290 $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1291 $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1292 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1293 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1295 $pdf->SetFont('', '');
1297 while ($row = PMA_DBI_fetch_assoc($result)) {
1298 $type = $row['Type'];
1299 // reformat mysql query output
1300 // set or enum types: slashes single quotes inside options
1301 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1302 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1303 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1304 $type_nowrap = '';
1306 $binary = 0;
1307 $unsigned = 0;
1308 $zerofill = 0;
1309 } else {
1310 $type_nowrap = ' nowrap="nowrap"';
1311 $type = preg_replace('@BINARY@i', '', $type);
1312 $type = preg_replace('@ZEROFILL@i', '', $type);
1313 $type = preg_replace('@UNSIGNED@i', '', $type);
1314 if (empty($type)) {
1315 $type = '&nbsp;';
1318 $binary = stristr($row['Type'], 'BINARY');
1319 $unsigned = stristr($row['Type'], 'UNSIGNED');
1320 $zerofill = stristr($row['Type'], 'ZEROFILL');
1322 $attribute = ' ';
1323 if ($binary) {
1324 $attribute = 'BINARY';
1326 if ($unsigned) {
1327 $attribute = 'UNSIGNED';
1329 if ($zerofill) {
1330 $attribute = 'UNSIGNED ZEROFILL';
1332 if (!isset($row['Default'])) {
1333 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1334 $row['Default'] = 'NULL';
1337 $field_name = $row['Field'];
1338 // $pdf->Ln();
1339 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1340 $pdf->Bookmark($field_name, 1, -1);
1341 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1342 $pdf_row = array($field_name,
1343 $type,
1344 $attribute,
1345 ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1346 ((isset($row['Default'])) ? $row['Default'] : ''),
1347 $row['Extra'],
1348 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1349 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1350 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1352 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1353 if (isset($res_rel[$field_name]['foreign_table']) AND
1354 isset($res_rel[$field_name]['foreign_field']) AND
1355 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1358 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1359 } else {
1360 unset($links[6]);
1362 $pdf->Row($pdf_row, $links);
1364 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1365 //echo ' ' . $field_name . '&nbsp;' . "\n";
1367 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1368 $pdf->Cell(20, 8, $attribute, 1, 0, 'L');
1369 $pdf->Cell(15, 8, , 1, 0, 'L');
1370 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1371 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1372 if ($have_rel) {
1373 if (isset($res_rel[$field_name])) {
1374 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1377 if ($cfgRelation['commwork']) {
1378 if (isset($comments[$field_name])) {
1379 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1381 } */
1382 } // end while
1383 $pdf->SetFont('', '', 14);
1384 PMA_DBI_free_result($result);
1385 } //end each
1386 } // end function PMA_RT_DOC
1389 * Main logic
1391 if (!isset($pdf_page_number)) {
1392 $pdf_page_number = 1;
1395 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1396 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1397 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1398 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1399 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1400 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1401 $paper = isset($paper) ? $paper : 'A4';
1402 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1403 PMA_DBI_select_db($db);
1405 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);