Translation update done using Pootle.
[phpmyadmin/bananer.git] / pdf_schema.php
blob80972aa0f99839dc8170ad1b23c471b3b26031e7
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">' . $strError . '</font><br />' . "\n";
33 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
34 echo sprintf($strRelationNotWorking, $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 double $ The scaling factor
103 * @param double $ The minimum X coordinate
104 * @param double $ The minimum Y coordinate
105 * @param double $ The left margin
106 * @param double $ 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 double $ The cell width
125 * @param double $ The cell height
126 * @param string $ The text to output
127 * @param mixed $ Whether to add borders or not
128 * @param integer $ Where to put the cursor once the output is done
129 * @param string $ Align mode
130 * @param integer $ 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 double $ The horizontal position of the starting point
144 * @param double $ The vertical position of the starting point
145 * @param double $ The horizontal position of the ending point
146 * @param double $ 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 double $ The x position
162 * @param double $ 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 double $ 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 double $ 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 double $ 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 $ 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, $strRunning, $strDatabase;
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 $ 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 $ 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 $ The font size
562 * @param boolean $ Whether to display color
563 * @param integer $ The max. with among tables
564 * @global object The current PDF document
565 * @access private
566 * @see PMA_PDF
568 function PMA_RT_Table_draw($ff, $setcolor = 0)
570 global $pdf, $with_doc;
572 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
573 $pdf->SetFont($ff, 'B');
574 if ($setcolor) {
575 $pdf->SetTextColor(200);
576 $pdf->SetFillColor(0, 0, 128);
578 if ($with_doc) {
579 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
580 } else {
581 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
584 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->getTitle(), 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
585 $pdf->PMA_PDF_setXScale($this->x);
586 $pdf->SetFont($ff, '');
587 $pdf->SetTextColor(0);
588 $pdf->SetFillColor(255);
590 foreach ($this->fields AS $field) {
591 if ($setcolor) {
592 if (in_array($field, $this->primary)) {
593 $pdf->SetFillColor(215, 121, 123);
595 if ($field == $this->displayfield) {
596 $pdf->SetFillColor(142, 159, 224);
599 if ($with_doc) {
600 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
601 } else {
602 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
605 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
606 $pdf->PMA_PDF_setXScale($this->x);
607 $pdf->SetFillColor(255);
608 } // end while
609 /*if ($pdf->PageNo() > 1) {
610 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
611 } */
612 } // end of the "PMA_RT_Table_draw()" method
614 * The "PMA_RT_Table" constructor
616 * @param string $ The table name
617 * @param integer $ The font size
618 * @param integer $ The max. with among tables
619 * @param boolean $ Whether to display keys or not
620 * @param boolean $ Whether to display table position or not
621 * @global object The current PDF document
622 * @global integer The current page number (from the
623 * $cfg['Servers'][$i]['table_coords'] table)
624 * @global array The relations settings
625 * @global string The current db name
626 * @access private
627 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
628 PMA_RT_Table::PMA_RT_Table_setHeight
630 function __construct($table_name, $ff, &$same_wide_width, $show_keys = false, $show_info = false)
632 global $pdf, $pdf_page_number, $cfgRelation, $db;
634 $this->table_name = $table_name;
635 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
636 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
637 if (!$result || !PMA_DBI_num_rows($result)) {
638 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
640 // load fields
641 //check to see if it will load all fields or only the foreign keys
642 if ($show_keys) {
643 $indexes = PMA_Index::getFromTable($this->table_name, $db);
644 $all_columns = array();
645 foreach ($indexes as $index) {
646 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
648 $this->fields = array_keys($all_columns);
649 } else {
650 while ($row = PMA_DBI_fetch_row($result)) {
651 $this->fields[] = $row[0];
655 $this->show_info = $show_info;
657 // height and width
658 $this->PMA_RT_Table_setHeight();
659 // setWidth must me after setHeight, because title
660 // can include table height which changes table width
661 $this->PMA_RT_Table_setWidth($ff);
662 if ($same_wide_width < $this->width) {
663 $same_wide_width = $this->width;
665 // x and y
666 $sql = 'SELECT x, y FROM '
667 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
668 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
669 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
670 . ' AND pdf_page_number = ' . $pdf_page_number;
671 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
673 if (!$result || !PMA_DBI_num_rows($result)) {
674 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
676 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
677 $this->x = (double) $this->x;
678 $this->y = (double) $this->y;
679 // displayfield
680 $this->displayfield = PMA_getDisplayField($db, $table_name);
681 // index
682 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
683 if (PMA_DBI_num_rows($result) > 0) {
684 while ($row = PMA_DBI_fetch_assoc($result)) {
685 if ($row['Key_name'] == 'PRIMARY') {
686 $this->primary[] = $row['Column_name'];
689 } // end if
690 } // end of the "PMA_RT_Table()" method
691 } // end class "PMA_RT_Table"
693 * Draws relation links
695 * @access private
696 * @see PMA_RT
697 * @package phpMyAdmin
699 class PMA_RT_Relation {
701 * Defines private properties
703 var $x_src, $y_src;
704 var $src_dir ;
705 var $dest_dir;
706 var $x_dest, $y_dest;
707 var $w_tick = 5;
710 * Gets arrows coordinates
712 * @param string $ The current table name
713 * @param string $ The relation column name
714 * @return array Arrows coordinates
715 * @access private
717 function PMA_RT_Relation_getXy($table, $column)
719 $pos = array_search($column, $table->fields);
720 // x_left, x_right, y
721 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
722 } // end of the "PMA_RT_Relation_getXy()" method
724 * Do draws relation links
726 * @param boolean $ Whether to use one color per relation or not
727 * @param integer $ The id of the link to draw
728 * @global object The current PDF document
729 * @access private
730 * @see PMA_PDF
732 function PMA_RT_Relation_draw($change_color, $i)
734 global $pdf;
736 if ($change_color) {
737 $d = $i % 6;
738 $j = ($i - $d) / 6;
739 $j = $j % 4;
740 $j++;
741 $case = array(
742 array(1, 0, 0),
743 array(0, 1, 0),
744 array(0, 0, 1),
745 array(1, 1, 0),
746 array(1, 0, 1),
747 array(0, 1, 1)
749 list ($a, $b, $c) = $case[$d];
750 $e = (1 - ($j - 1) / 6);
751 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
752 } else {
753 $pdf->SetDrawColor(0);
754 } // end if... else...
755 $pdf->PMA_PDF_setLineWidthScale(0.2);
756 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
757 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
758 $pdf->PMA_PDF_setLineWidthScale(0.1);
759 $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);
760 // arrow
761 $root2 = 2 * sqrt(2);
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);
763 $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);
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->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);
767 $pdf->SetDrawColor(0);
768 } // end of the "PMA_RT_Relation_draw()" method
770 * The "PMA_RT_Relation" constructor
772 * @param string $ The master table name
773 * @param string $ The relation field in the master table
774 * @param string $ The foreign table name
775 * @param string $ The relation field in the foreign table
776 * @access private
777 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
779 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
781 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
782 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
783 $src_left = $src_pos[0] - $this->w_tick;
784 $src_right = $src_pos[1] + $this->w_tick;
785 $dest_left = $dest_pos[0] - $this->w_tick;
786 $dest_right = $dest_pos[1] + $this->w_tick;
788 $d1 = abs($src_left - $dest_left);
789 $d2 = abs($src_right - $dest_left);
790 $d3 = abs($src_left - $dest_right);
791 $d4 = abs($src_right - $dest_right);
792 $d = min($d1, $d2, $d3, $d4);
794 if ($d == $d1) {
795 $this->x_src = $src_pos[0];
796 $this->src_dir = -1;
797 $this->x_dest = $dest_pos[0];
798 $this->dest_dir = -1;
799 } elseif ($d == $d2) {
800 $this->x_src = $src_pos[1];
801 $this->src_dir = 1;
802 $this->x_dest = $dest_pos[0];
803 $this->dest_dir = -1;
804 } elseif ($d == $d3) {
805 $this->x_src = $src_pos[0];
806 $this->src_dir = -1;
807 $this->x_dest = $dest_pos[1];
808 $this->dest_dir = 1;
809 } else {
810 $this->x_src = $src_pos[1];
811 $this->src_dir = 1;
812 $this->x_dest = $dest_pos[1];
813 $this->dest_dir = 1;
815 $this->y_src = $src_pos[2];
816 $this->y_dest = $dest_pos[2];
817 } // end of the "PMA_RT_Relation()" method
818 } // end of the "PMA_RT_Relation" class
820 * Draws and send the database schema
822 * @access public
823 * @see PMA_PDF
824 * @package phpMyAdmin
826 class PMA_RT {
828 * Defines private properties
830 var $tables = array();
831 var $relations = array();
832 var $ff = PMA_PDF_FONT;
833 var $x_max = 0;
834 var $y_max = 0;
835 var $scale;
836 var $x_min = 100000;
837 var $y_min = 100000;
838 var $t_marg = 10;
839 var $b_marg = 10;
840 var $l_marg = 10;
841 var $r_marg = 10;
842 var $tablewidth;
843 var $same_wide = 0;
846 * Sets X and Y minimum and maximum for a table cell
848 * @param string $ The table name
849 * @access private
851 function PMA_RT_setMinMax($table)
853 $this->x_max = max($this->x_max, $table->x + $table->width);
854 $this->y_max = max($this->y_max, $table->y + $table->height);
855 $this->x_min = min($this->x_min, $table->x);
856 $this->y_min = min($this->y_min, $table->y);
857 } // end of the "PMA_RT_setMinMax()" method
859 * Defines relation objects
861 * @param string $ The master table name
862 * @param string $ The relation field in the master table
863 * @param string $ The foreign table name
864 * @param string $ The relation field in the foreign table
865 * @param boolean $ Whether to display table position or not
866 * @access private
867 * @see PMA_RT_setMinMax
869 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field, $show_info)
871 if (!isset($this->tables[$master_table])) {
872 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth, false, $show_info);
873 $this->PMA_RT_setMinMax($this->tables[$master_table]);
875 if (!isset($this->tables[$foreign_table])) {
876 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth, false, $show_info);
877 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
879 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
880 } // end of the "PMA_RT_addRelation()" method
882 * Draws the grid
884 * @global object the current PMA_PDF instance
885 * @access private
886 * @see PMA_PDF
888 function PMA_RT_strokeGrid()
890 global $pdf;
892 $pdf->SetMargins(0, 0);
893 $pdf->SetDrawColor(200, 200, 200);
894 // Draws horizontal lines
895 for ($l = 0; $l < 21; $l++) {
896 $pdf->line(0, $l * 10, $pdf->getFh(), $l * 10);
897 // Avoid duplicates
898 if ($l > 0) {
899 $pdf->SetXY(0, $l * 10);
900 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
901 $pdf->Cell(5, 5, ' ' . $label);
902 } // end if
903 } // end for
904 // Draws vertical lines
905 for ($j = 0; $j < 30 ;$j++) {
906 $pdf->line($j * 10, 0, $j * 10, $pdf->getFw());
907 $pdf->SetXY($j * 10, 0);
908 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
909 $pdf->Cell(5, 7, $label);
910 } // end for
911 } // end of the "PMA_RT_strokeGrid()" method
913 * Draws relation arrows
915 * @param boolean $ Whether to use one color per relation or not
916 * @access private
917 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
919 function PMA_RT_drawRelations($change_color)
921 $i = 0;
922 foreach ($this->relations AS $relation) {
923 $relation->PMA_RT_Relation_draw($change_color, $i);
924 $i++;
925 } // end while
926 } // end of the "PMA_RT_drawRelations()" method
928 * Draws tables
930 * @param boolean $ Whether to display table position or not
931 * @access private
932 * @see PMA_RT_Table::PMA_RT_Table_draw()
934 function PMA_RT_drawTables($draw_color = 0)
936 foreach ($this->tables AS $table) {
937 $table->PMA_RT_Table_draw($this->ff, $draw_color);
939 } // end of the "PMA_RT_drawTables()" method
941 * Ouputs the PDF document to a file
943 * @global object The current PDF document
944 * @global string The current database name
945 * @global integer The current page number (from the
946 * $cfg['Servers'][$i]['table_coords'] table)
947 * @access private
948 * @see PMA_PDF
950 function PMA_RT_showRt()
952 global $pdf, $db, $pdf_page_number, $cfgRelation;
954 $pdf->SetFontSize(14);
955 $pdf->SetLineWidth(0.2);
956 $pdf->SetDisplayMode('fullpage');
957 // Get the name of this pdfpage to use as filename (Mike Beck)
958 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
959 . ' WHERE page_nr = ' . $pdf_page_number;
960 $_name_rs = PMA_query_as_controluser($_name_sql);
961 if ($_name_rs) {
962 $_name_row = PMA_DBI_fetch_row($_name_rs);
963 $filename = $_name_row[0] . '.pdf';
965 // i don't know if there is a chance for this to happen, but rather be on the safe side:
966 if (empty($filename)) {
967 $filename = $pdf_page_number . '.pdf';
969 // $pdf->Output($db . '_' . $filename, TRUE);
970 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
971 } // end of the "PMA_RT_showRt()" method
973 * The "PMA_RT" constructor
975 * @param mixed $ The scaling factor
976 * @param integer $ The page number to draw (from the
977 * $cfg['Servers'][$i]['table_coords'] table)
978 * @param boolean $ Whether to display table position or not
979 * @param boolean $ Was originally whether to use one color per
980 * relation or not, now enables/disables color
981 * everywhere, due to some problems printing with color
982 * @param boolean $ Whether to draw grids or not
983 * @param boolean $ Whether all tables should have the same width or not
984 * @param boolean $ Wheter to show all field or only the keys
985 * @global object The current PDF document
986 * @global string The current db name
987 * @global array The relations settings
988 * @access private
989 * @see PMA_PDF
991 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)
993 global $pdf, $db, $cfgRelation, $with_doc;
995 $this->same_wide = $all_tab_same_wide;
996 // Initializes a new document
997 $pdf = new PMA_PDF('L', 'mm', $paper);
998 $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
999 $pdf->setCMargin(0);
1000 $pdf->Open();
1001 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
1002 $pdf->AliasNbPages();
1003 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
1004 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
1005 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
1006 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
1007 $this->ff = PMA_PDF_FONT;
1008 $pdf->SetFont($this->ff, '', 14);
1009 $pdf->SetAutoPageBreak('auto');
1010 // Gets tables on this page
1011 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
1012 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1013 . ' AND pdf_page_number = ' . $which_rel;
1014 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
1015 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1016 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
1017 // die('No tables');
1018 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1019 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1020 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1022 // make doc //
1023 if ($with_doc) {
1024 $pdf->SetAutoPageBreak('auto', 15);
1025 $pdf->setCMargin(1);
1026 PMA_RT_DOC($alltables);
1027 $pdf->SetAutoPageBreak('auto');
1028 $pdf->setCMargin(0);
1031 $pdf->Addpage();
1033 if ($with_doc) {
1034 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1035 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1036 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1037 $this->t_marg = 18;
1038 $this->b_marg = 18;
1041 /* snip */
1043 foreach ($alltables AS $table) {
1044 if (!isset($this->tables[$table])) {
1045 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys, $show_info);
1048 if ($this->same_wide) {
1049 $this->tables[$table]->width = $this->tablewidth;
1051 $this->PMA_RT_setMinMax($this->tables[$table]);
1053 // Defines the scale factor
1054 $this->scale = ceil(
1055 max(
1056 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1057 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1058 * 100) / 100;
1060 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1061 // Builds and save the PDF document
1062 $pdf->PMA_PDF_setLineWidthScale(0.1);
1064 if ($show_grid) {
1065 $pdf->SetFontSize(10);
1066 $this->PMA_RT_strokeGrid();
1068 $pdf->PMA_PDF_setFontSizeScale(14);
1069 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1070 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1071 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1072 // . ' AND master_table IN (' . $intable . ')'
1073 // . ' AND foreign_table IN (' . $intable . ')';
1074 // $result = PMA_query_as_controluser($sql);
1076 // previous logic was checking master tables and foreign tables
1077 // but I think that looping on every table of the pdf page as a master
1078 // and finding its foreigns is OK (then we can support innodb)
1079 $seen_a_relation = false;
1080 foreach ($alltables AS $one_table) {
1081 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1082 if ($exist_rel) {
1083 $seen_a_relation = true;
1084 foreach ($exist_rel AS $master_field => $rel) {
1085 // put the foreign table on the schema only if selected
1086 // by the user
1087 // (do not use array_search() because we would have to
1088 // to do a === FALSE and this is not PHP3 compatible)
1089 if (in_array($rel['foreign_table'], $alltables)) {
1090 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info);
1092 } // end while
1093 } // end if
1094 } // end while
1095 // also show tables without relations
1096 // $norelations = TRUE;
1097 // if ($result && PMA_DBI_num_rows($result) > 0) {
1098 // $norelations = FALSE;
1099 // while ($row = PMA_DBI_fetch_assoc($result)) {
1100 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1101 // }
1102 // }
1103 // if ($norelations == FALSE) {
1104 if ($seen_a_relation) {
1105 $this->PMA_RT_drawRelations($change_color);
1108 $this->PMA_RT_drawTables($change_color);
1110 $this->PMA_RT_showRt();
1111 } // end of the "PMA_RT()" method
1112 } // end of the "PMA_RT" class
1114 function PMA_RT_DOC($alltables)
1116 global $db, $pdf, $orientation, $paper;
1117 // TOC
1118 $pdf->addpage($GLOBALS['orientation']);
1119 $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C');
1120 $pdf->Ln(15);
1121 $i = 1;
1122 foreach ($alltables AS $table) {
1123 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1124 $pdf->SetX(10);
1125 // $pdf->Ln(1);
1126 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1127 $pdf->SetX(10);
1128 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1129 // $pdf->Ln(1);
1130 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1131 while ($row = PMA_DBI_fetch_assoc($result)) {
1132 $pdf->SetX(20);
1133 $field_name = $row['Field'];
1134 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1135 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1137 $lasttable = $table;
1138 $i++;
1140 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1141 $pdf->SetX(10);
1142 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1143 $pdf->SetX(10);
1144 $pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1145 $z = 0;
1146 foreach ($alltables AS $table) {
1147 $z++;
1148 $pdf->addpage($GLOBALS['orientation']);
1149 $pdf->Bookmark($table);
1150 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1151 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1152 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1153 $pdf->SetFont('', 'B', 18);
1154 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1155 $pdf->SetFont('', '', 8);
1156 $pdf->ln();
1158 $cfgRelation = PMA_getRelationsParam();
1159 $comments = PMA_getComments($db, $table);
1160 if ($cfgRelation['mimework']) {
1161 $mime_map = PMA_getMIME($db, $table, true);
1165 * Gets table informations
1167 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1168 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1169 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1170 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1171 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1172 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1175 * Gets table keys and retains them
1177 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1178 $primary = '';
1179 $indexes = array();
1180 $lastIndex = '';
1181 $indexes_info = array();
1182 $indexes_data = array();
1183 $pk_array = array(); // will be use to emphasis prim. keys in the table
1184 // view
1185 while ($row = PMA_DBI_fetch_assoc($result)) {
1186 // Backups the list of primary keys
1187 if ($row['Key_name'] == 'PRIMARY') {
1188 $primary .= $row['Column_name'] . ', ';
1189 $pk_array[$row['Column_name']] = 1;
1191 // Retains keys informations
1192 if ($row['Key_name'] != $lastIndex) {
1193 $indexes[] = $row['Key_name'];
1194 $lastIndex = $row['Key_name'];
1196 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1197 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1198 if (isset($row['Cardinality'])) {
1199 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1201 // I don't know what does following column mean....
1202 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1203 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1205 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1206 if (isset($row['Sub_part'])) {
1207 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1209 } // end while
1210 if ($result) {
1211 PMA_DBI_free_result($result);
1215 * Gets fields properties
1217 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1218 $fields_cnt = PMA_DBI_num_rows($result);
1219 // Check if we can use Relations (Mike Beck)
1220 if (!empty($cfgRelation['relation'])) {
1221 // Find which tables are related with the current one and write it in
1222 // an array
1223 $res_rel = PMA_getForeigners($db, $table);
1225 if (count($res_rel) > 0) {
1226 $have_rel = true;
1227 } else {
1228 $have_rel = false;
1230 } else {
1231 $have_rel = false;
1232 } // end if
1234 * Displays the comments of the table if MySQL >= 3.23
1237 $break = false;
1238 if (!empty($show_comment)) {
1239 $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1);
1240 $break = true;
1243 if (!empty($create_time)) {
1244 $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1);
1245 $break = true;
1248 if (!empty($update_time)) {
1249 $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1);
1250 $break = true;
1253 if (!empty($check_time)) {
1254 $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1);
1255 $break = true;
1258 if ($break == true) {
1259 $pdf->Cell(0, 3, '', 0, 1);
1260 $pdf->Ln();
1263 $pdf->SetFont('', 'B');
1264 if (isset($orientation) && $orientation == 'L') {
1265 $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1266 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1267 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1268 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1269 $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1270 $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1271 $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1273 if ($paper == 'A4') {
1274 $comments_width = 67;
1275 } else {
1276 // this is really intended for 'letter'
1278 * @todo find optimal width for all formats
1280 $comments_width = 50;
1282 $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1283 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1284 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1285 } else {
1286 $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1287 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1288 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1289 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1290 $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1291 $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1292 $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1293 $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1294 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1295 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1297 $pdf->SetFont('', '');
1299 while ($row = PMA_DBI_fetch_assoc($result)) {
1300 $type = $row['Type'];
1301 // reformat mysql query output
1302 // set or enum types: slashes single quotes inside options
1303 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1304 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1305 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1306 $type_nowrap = '';
1308 $binary = 0;
1309 $unsigned = 0;
1310 $zerofill = 0;
1311 } else {
1312 $type_nowrap = ' nowrap="nowrap"';
1313 $type = preg_replace('@BINARY@i', '', $type);
1314 $type = preg_replace('@ZEROFILL@i', '', $type);
1315 $type = preg_replace('@UNSIGNED@i', '', $type);
1316 if (empty($type)) {
1317 $type = '&nbsp;';
1320 $binary = stristr($row['Type'], 'BINARY');
1321 $unsigned = stristr($row['Type'], 'UNSIGNED');
1322 $zerofill = stristr($row['Type'], 'ZEROFILL');
1324 $strAttribute = ' ';
1325 if ($binary) {
1326 $strAttribute = 'BINARY';
1328 if ($unsigned) {
1329 $strAttribute = 'UNSIGNED';
1331 if ($zerofill) {
1332 $strAttribute = 'UNSIGNED ZEROFILL';
1334 if (!isset($row['Default'])) {
1335 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1336 $row['Default'] = 'NULL';
1339 $field_name = $row['Field'];
1340 // $pdf->Ln();
1341 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1342 $pdf->Bookmark($field_name, 1, -1);
1343 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1344 $pdf_row = array($field_name,
1345 $type,
1346 $strAttribute,
1347 ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1348 ((isset($row['Default'])) ? $row['Default'] : ''),
1349 $row['Extra'],
1350 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1351 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1352 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1354 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1355 if (isset($res_rel[$field_name]['foreign_table']) AND
1356 isset($res_rel[$field_name]['foreign_field']) AND
1357 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1360 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1361 } else {
1362 unset($links[6]);
1364 $pdf->Row($pdf_row, $links);
1366 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1367 //echo ' ' . $field_name . '&nbsp;' . "\n";
1369 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1370 $pdf->Cell(20, 8, $strAttribute, 1, 0, 'L');
1371 $pdf->Cell(15, 8, , 1, 0, 'L');
1372 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1373 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1374 if ($have_rel) {
1375 if (isset($res_rel[$field_name])) {
1376 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1379 if ($cfgRelation['commwork']) {
1380 if (isset($comments[$field_name])) {
1381 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1383 } */
1384 } // end while
1385 $pdf->SetFont('', '', 14);
1386 PMA_DBI_free_result($result);
1387 } //end each
1388 } // end function PMA_RT_DOC
1391 * Main logic
1393 if (!isset($pdf_page_number)) {
1394 $pdf_page_number = 1;
1397 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1398 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1399 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1400 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1401 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1402 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1403 $paper = isset($paper) ? $paper : 'A4';
1404 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1405 PMA_DBI_select_db($db);
1407 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);