Indentation.
[phpmyadmin/crack.git] / pdf_schema.php
blobb9c3e72a9b7860e3e97810a088375ebba53a0eda
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Contributed by Maxime Delorme and merged by lem9
6 * @version $Id$
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';
20 $cfgRelation = PMA_getRelationsParam();
22 /**
23 * Now in ./libraries/relation.lib.php we check for all tables
24 * that we need, but if we don't find them we are quiet about it
25 * so people can work without.
26 * This page is absolutely useless if you didn't set up your tables
27 * correctly, so it is a good place to see which tables we can and
28 * complain ;-)
30 if (!$cfgRelation['pdfwork']) {
31 echo '<font color="red">' . $strError . '</font><br />' . "\n";
32 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
33 echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
36 /**
37 * Font used in PDF.
39 * @todo Make this configuratble (at least Sans/Serif).
41 define('PMA_PDF_FONT', 'DejaVuSans');
42 require_once './libraries/tcpdf/tcpdf.php';
44 /**
45 * Extends the "FPDF" class and prepares the work
47 * @access public
48 * @see FPDF
50 class PMA_PDF extends TCPDF {
51 /**
52 * Defines private properties
54 var $x_min;
55 var $y_min;
56 var $l_marg = 10;
57 var $t_marg = 10;
58 var $scale;
59 var $PMA_links;
60 var $Outlines = array();
61 var $def_outlines;
62 var $Alias = array();
63 var $widths;
65 public function getFh()
67 return $this->fh;
70 public function getFw()
72 return $this->fw;
75 public function setCMargin($c_margin)
77 $this->cMargin = $c_margin;
80 function SetAlias($name, $value)
82 $this->Alias[$name] = $value ;
85 function _putpages()
87 if (count($this->Alias) > 0) {
88 $nb = $this->page;
89 foreach ($this->Alias AS $alias => $value) {
90 for ($n = 1;$n <= $nb;$n++)
91 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
94 parent::_putpages();
97 /**
98 * Sets the scaling factor, defines minimum coordinates and margins
100 * @param double $ The scaling factor
101 * @param double $ The minimum X coordinate
102 * @param double $ The minimum Y coordinate
103 * @param double $ The left margin
104 * @param double $ The top margin
105 * @access public
107 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
109 $this->scale = $scale;
110 $this->x_min = $x_min;
111 $this->y_min = $y_min;
112 if ($this->l_marg != -1) {
113 $this->l_marg = $l_marg;
115 if ($this->t_marg != -1) {
116 $this->t_marg = $t_marg;
118 } // end of the "PMA_PDF_setScale" function
120 * Outputs a scaled cell
122 * @param double $ The cell width
123 * @param double $ The cell height
124 * @param string $ The text to output
125 * @param mixed $ Whether to add borders or not
126 * @param integer $ Where to put the cursor once the output is done
127 * @param string $ Align mode
128 * @param integer $ Whether to fill the cell with a color or not
129 * @access public
130 * @see FPDF::Cell()
132 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
134 $h = $h / $this->scale;
135 $w = $w / $this->scale;
136 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
137 } // end of the "PMA_PDF_cellScale" function
139 * Draws a scaled line
141 * @param double $ The horizontal position of the starting point
142 * @param double $ The vertical position of the starting point
143 * @param double $ The horizontal position of the ending point
144 * @param double $ The vertical position of the ending point
145 * @access public
146 * @see FPDF::Line()
148 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
150 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
151 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
152 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
153 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
154 $this->Line($x1, $y1, $x2, $y2);
155 } // end of the "PMA_PDF_lineScale" function
157 * Sets x and y scaled positions
159 * @param double $ The x position
160 * @param double $ The y position
161 * @access public
162 * @see FPDF::SetXY()
164 function PMA_PDF_setXyScale($x, $y)
166 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
167 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
168 $this->SetXY($x, $y);
169 } // end of the "PMA_PDF_setXyScale" function
171 * Sets the X scaled positions
173 * @param double $ The x position
174 * @access public
175 * @see FPDF::SetX()
177 function PMA_PDF_setXScale($x)
179 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
180 $this->SetX($x);
181 } // end of the "PMA_PDF_setXScale" function
183 * Sets the scaled font size
185 * @param double $ The font size (in points)
186 * @access public
187 * @see FPDF::SetFontSize()
189 function PMA_PDF_setFontSizeScale($size)
191 // Set font size in points
192 $size = $size / $this->scale;
193 $this->SetFontSize($size);
194 } // end of the "PMA_PDF_setFontSizeScale" function
196 * Sets the scaled line width
198 * @param double $ The line width
199 * @access public
200 * @see FPDF::SetLineWidth()
202 function PMA_PDF_setLineWidthScale($width)
204 $width = $width / $this->scale;
205 $this->SetLineWidth($width);
206 } // end of the "PMA_PDF_setLineWidthScale" function
208 * Displays an error message
210 * @param string $ the error mesage
211 * @global array the PMA configuration array
212 * @global integer the current server id
213 * @global string the current language
214 * @global string the charset to convert to
215 * @global string the current database name
216 * @global string the current charset
217 * @global string the current text direction
218 * @global string a localized string
219 * @global string an other localized string
220 * @access public
222 function PMA_PDF_die($error_message = '')
224 global $cfg;
225 global $server, $lang, $convcharset, $db;
226 global $charset, $text_dir, $strRunning, $strDatabase;
228 require_once './libraries/header.inc.php';
230 echo '<p><strong>PDF - ' . $GLOBALS['strError'] . '</strong></p>' . "\n";
231 if (!empty($error_message)) {
232 $error_message = htmlspecialchars($error_message);
234 echo '<p>' . "\n";
235 echo ' ' . $error_message . "\n";
236 echo '</p>' . "\n";
238 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
239 . '">' . $GLOBALS['strBack'] . '</a>';
240 echo "\n";
242 require_once './libraries/footer.inc.php';
243 } // end of the "PMA_PDF_die()" function
245 * Aliases the "Error()" function from the FPDF class to the
246 * "PMA_PDF_die()" one
248 * @param string $ the error mesage
249 * @access public
250 * @see PMA_PDF_die
252 function Error($error_message = '')
254 $this->PMA_PDF_die($error_message);
255 } // end of the "Error()" method
256 function Header()
258 // $datefmt
259 // We only show this if we find something in the new pdf_pages table
261 // This function must be named "Header" to work with the FPDF library
262 global $cfgRelation, $db, $pdf_page_number, $with_doc;
263 if ($with_doc) {
264 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
265 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
266 . ' AND page_nr = \'' . $pdf_page_number . '\'';
267 $test_rs = PMA_query_as_cu($test_query);
268 $pages = @PMA_DBI_fetch_assoc($test_rs);
269 $this->SetFont('', 'B', 14);
270 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
271 $this->SetFont('', '');
272 $this->Ln();
275 function Footer()
277 // This function must be named "Footer" to work with the FPDF library
278 global $with_doc;
279 if ($with_doc) {
280 $this->SetY(-15);
281 $this->SetFont('', '', 14);
282 $this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
283 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
284 $this->SetY(20);
287 function Bookmark($txt, $level = 0, $y = 0)
289 // Add a bookmark
290 $this->Outlines[0][] = $level;
291 $this->Outlines[1][] = $txt;
292 $this->Outlines[2][] = $this->page;
293 if ($y == -1) {
294 $y = $this->GetY();
296 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
299 function _putbookmarks()
301 if (count($this->Outlines) > 0) {
302 // Save object number
303 $memo_n = $this->n;
304 // Take the number of sub elements for an outline
305 $nb_outlines = sizeof($this->Outlines[0]);
306 $first_level = array();
307 $parent = array();
308 $parent[0] = 1;
309 for ($i = 0; $i < $nb_outlines; $i++) {
310 $level = $this->Outlines[0][$i];
311 $kids = 0;
312 $last = -1;
313 $prev = -1;
314 $next = -1;
315 if ($i > 0) {
316 $cursor = $i-1;
317 // Take the previous outline in the same level
318 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
319 $cursor--;
320 if ($this->Outlines[0][$cursor] == $level) {
321 $prev = $cursor;
324 if ($i < $nb_outlines-1) {
325 $cursor = $i + 1;
326 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
327 // Take the immediate kid in level + 1
328 if ($this->Outlines[0][$cursor] == $level + 1) {
329 $kids++;
330 $last = $cursor;
332 $cursor++;
334 $cursor = $i + 1;
335 // Take the next outline in the same level
336 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
337 $cursor++;
338 if ($this->Outlines[0][$cursor] == $level) {
339 $next = $cursor;
342 $this->_newobj();
343 $parent[$level + 1] = $this->n;
344 if ($level == 0) {
345 $first_level[] = $this->n;
347 $this->_out('<<');
348 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
349 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
350 if ($prev != -1) {
351 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
353 if ($next != -1) {
354 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
356 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
357 if ($kids > 0) {
358 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
359 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
360 $this->_out('/Count -' . $kids);
362 $this->_out('>>');
363 $this->_out('endobj');
365 // First page of outlines
366 $this->_newobj();
367 $this->def_outlines = $this->n;
368 $this->_out('<<');
369 $this->_out('/Type');
370 $this->_out('/Outlines');
371 $this->_out('/First ' . $first_level[0] . ' 0 R');
372 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
373 $this->_out('/Count ' . sizeof($first_level));
374 $this->_out('>>');
375 $this->_out('endobj');
379 function _putresources()
381 parent::_putresources();
382 $this->_putbookmarks();
385 function _putcatalog()
387 parent::_putcatalog();
388 if (count($this->Outlines) > 0) {
389 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
390 $this->_out('/PageMode /UseOutlines');
393 function SetWidths($w)
395 // column widths
396 $this->widths = $w;
399 function Row($data, $links)
401 // line height
402 $nb = 0;
403 $data_cnt = count($data);
404 for ($i = 0;$i < $data_cnt;$i++)
405 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
406 $il = $this->FontSize;
407 $h = ($il + 1) * $nb;
408 // page break if necessary
409 $this->CheckPageBreak($h);
410 // draw the cells
411 $data_cnt = count($data);
412 for ($i = 0;$i < $data_cnt;$i++) {
413 $w = $this->widths[$i];
414 // save current position
415 $x = $this->GetX();
416 $y = $this->GetY();
417 // draw the border
418 $this->Rect($x, $y, $w, $h);
419 if (isset($links[$i])) {
420 $this->Link($x, $y, $w, $h, $links[$i]);
422 // print text
423 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
424 // go to right side
425 $this->SetXY($x + $w, $y);
427 // go to line
428 $this->Ln($h);
431 function CheckPageBreak($h)
433 // if height h overflows, manual page break
434 if ($this->GetY() + $h > $this->PageBreakTrigger) {
435 $this->AddPage($this->CurOrientation);
439 function NbLines($w, $txt)
441 // compute number of lines used by a multicell of width w
442 $cw = &$this->CurrentFont['cw'];
443 if ($w == 0) {
444 $w = $this->w - $this->rMargin - $this->x;
446 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
447 $s = str_replace("\r", '', $txt);
448 $nb = strlen($s);
449 if ($nb > 0 and $s[$nb-1] == "\n") {
450 $nb--;
452 $sep = -1;
453 $i = 0;
454 $j = 0;
455 $l = 0;
456 $nl = 1;
457 while ($i < $nb) {
458 $c = $s[$i];
459 if ($c == "\n") {
460 $i++;
461 $sep = -1;
462 $j = $i;
463 $l = 0;
464 $nl++;
465 continue;
467 if ($c == ' ') {
468 $sep = $i;
470 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
471 if ($l > $wmax) {
472 if ($sep == -1) {
473 if ($i == $j) {
474 $i++;
476 } else {
477 $i = $sep + 1;
479 $sep = -1;
480 $j = $i;
481 $l = 0;
482 $nl++;
483 } else {
484 $i++;
487 return $nl;
489 } // end of the "PMA_PDF" class
493 * Draws tables schema
495 * @access private
496 * @see PMA_RT
498 class PMA_RT_Table {
500 * Defines private properties
502 var $nb_fiels;
503 var $table_name;
504 var $width = 0;
505 var $height;
506 var $fields = array();
507 var $height_cell = 6;
508 var $x, $y;
509 var $primary = array();
512 * Sets the width of the table
514 * @param integer $ The font size
515 * @global object The current PDF document
516 * @access private
517 * @see PMA_PDF
519 function PMA_RT_Table_setWidth($ff)
521 // this looks buggy to me... does it really work if
522 // there are fields that require wider cells than the name of the table?
523 global $pdf;
525 foreach ($this->fields AS $field) {
526 $this->width = max($this->width, $pdf->GetStringWidth($field));
528 $this->width += $pdf->GetStringWidth(' ');
529 $pdf->SetFont($ff, 'B');
530 $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
531 $pdf->SetFont($ff, '');
532 } // end of the "PMA_RT_Table_setWidth()" method
534 * Sets the height of the table
536 * @access private
538 function PMA_RT_Table_setHeight()
540 $this->height = (count($this->fields) + 1) * $this->height_cell;
541 } // end of the "PMA_RT_Table_setHeight()" method
543 * Do draw the table
545 * @param boolean $ Whether to display table position or not
546 * @param integer $ The font size
547 * @param boolean $ Whether to display color
548 * @param integer $ The max. with among tables
549 * @global object The current PDF document
550 * @access private
551 * @see PMA_PDF
553 function PMA_RT_Table_draw($show_info, $ff, $setcolor = 0)
555 global $pdf, $with_doc;
557 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
558 $pdf->SetFont($ff, 'B');
559 if ($setcolor) {
560 $pdf->SetTextColor(200);
561 $pdf->SetFillColor(0, 0, 128);
563 if ($with_doc) {
564 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
565 } else {
566 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
569 if ($show_info) {
570 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) . ' ' . $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
571 } else {
572 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
574 $pdf->PMA_PDF_setXScale($this->x);
575 $pdf->SetFont($ff, '');
576 $pdf->SetTextColor(0);
577 $pdf->SetFillColor(255);
579 foreach ($this->fields AS $field) {
580 // loic1 : PHP3 fix
581 // if (in_array($field, $this->primary)) {
582 if ($setcolor) {
583 if (in_array($field, $this->primary)) {
584 $pdf->SetFillColor(215, 121, 123);
586 if ($field == $this->displayfield) {
587 $pdf->SetFillColor(142, 159, 224);
590 if ($with_doc) {
591 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
592 } else {
593 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
596 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
597 $pdf->PMA_PDF_setXScale($this->x);
598 $pdf->SetFillColor(255);
599 } // end while
600 /*if ($pdf->PageNo() > 1) {
601 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
602 } */
603 } // end of the "PMA_RT_Table_draw()" method
605 * The "PMA_RT_Table" constructor
607 * @param string $ The table name
608 * @param integer $ The font size
609 * @param integer $ The max. with among tables
610 * @global object The current PDF document
611 * @global integer The current page number (from the
612 * $cfg['Servers'][$i]['table_coords'] table)
613 * @global array The relations settings
614 * @global string The current db name
615 * @access private
616 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
617 PMA_RT_Table::PMA_RT_Table_setHeight
619 function __construct($table_name, $ff, &$same_wide_width)
621 global $pdf, $pdf_page_number, $cfgRelation, $db;
623 $this->table_name = $table_name;
624 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
625 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
626 if (!$result || !PMA_DBI_num_rows($result)) {
627 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
629 // load fields
630 while ($row = PMA_DBI_fetch_row($result)) {
631 $this->fields[] = $row[0];
633 // height and width
634 $this->PMA_RT_Table_setWidth($ff);
635 $this->PMA_RT_Table_setHeight();
636 if ($same_wide_width < $this->width) {
637 $same_wide_width = $this->width;
639 // x and y
640 $sql = 'SELECT x, y FROM '
641 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
642 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
643 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
644 . ' AND pdf_page_number = ' . $pdf_page_number;
645 $result = PMA_query_as_cu($sql, false, PMA_DBI_QUERY_STORE);
647 if (!$result || !PMA_DBI_num_rows($result)) {
648 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
650 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
651 $this->x = (double) $this->x;
652 $this->y = (double) $this->y;
653 // displayfield
654 $this->displayfield = PMA_getDisplayField($db, $table_name);
655 // index
656 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
657 if (PMA_DBI_num_rows($result) > 0) {
658 while ($row = PMA_DBI_fetch_assoc($result)) {
659 if ($row['Key_name'] == 'PRIMARY') {
660 $this->primary[] = $row['Column_name'];
663 } // end if
664 } // end of the "PMA_RT_Table()" method
665 } // end class "PMA_RT_Table"
667 * Draws relation links
669 * @access private
670 * @see PMA_RT
672 class PMA_RT_Relation {
674 * Defines private properties
676 var $x_src, $y_src;
677 var $src_dir ;
678 var $dest_dir;
679 var $x_dest, $y_dest;
680 var $w_tick = 5;
683 * Gets arrows coordinates
685 * @param string $ The current table name
686 * @param string $ The relation column name
687 * @return array Arrows coordinates
688 * @access private
690 function PMA_RT_Relation_getXy($table, $column)
692 $pos = array_search($column, $table->fields);
693 // x_left, x_right, y
694 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
695 } // end of the "PMA_RT_Relation_getXy()" method
697 * Do draws relation links
699 * @param boolean $ Whether to use one color per relation or not
700 * @param integer $ The id of the link to draw
701 * @global object The current PDF document
702 * @access private
703 * @see PMA_PDF
705 function PMA_RT_Relation_draw($change_color, $i)
707 global $pdf;
709 if ($change_color) {
710 $d = $i % 6;
711 $j = ($i - $d) / 6;
712 $j = $j % 4;
713 $j++;
714 $case = array(
715 array(1, 0, 0),
716 array(0, 1, 0),
717 array(0, 0, 1),
718 array(1, 1, 0),
719 array(1, 0, 1),
720 array(0, 1, 1)
722 list ($a, $b, $c) = $case[$d];
723 $e = (1 - ($j - 1) / 6);
724 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
725 } else {
726 $pdf->SetDrawColor(0);
727 } // end if... else...
728 $pdf->PMA_PDF_setLineWidthScale(0.2);
729 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
730 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
731 $pdf->PMA_PDF_setLineWidthScale(0.1);
732 $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);
733 // arrow
734 $root2 = 2 * sqrt(2);
735 $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);
736 $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);
738 $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);
739 $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);
740 $pdf->SetDrawColor(0);
741 } // end of the "PMA_RT_Relation_draw()" method
743 * The "PMA_RT_Relation" constructor
745 * @param string $ The master table name
746 * @param string $ The relation field in the master table
747 * @param string $ The foreign table name
748 * @param string $ The relation field in the foreign table
749 * @access private
750 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
752 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
754 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
755 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
756 $src_left = $src_pos[0] - $this->w_tick;
757 $src_right = $src_pos[1] + $this->w_tick;
758 $dest_left = $dest_pos[0] - $this->w_tick;
759 $dest_right = $dest_pos[1] + $this->w_tick;
761 $d1 = abs($src_left - $dest_left);
762 $d2 = abs($src_right - $dest_left);
763 $d3 = abs($src_left - $dest_right);
764 $d4 = abs($src_right - $dest_right);
765 $d = min($d1, $d2, $d3, $d4);
767 if ($d == $d1) {
768 $this->x_src = $src_pos[0];
769 $this->src_dir = -1;
770 $this->x_dest = $dest_pos[0];
771 $this->dest_dir = -1;
772 } elseif ($d == $d2) {
773 $this->x_src = $src_pos[1];
774 $this->src_dir = 1;
775 $this->x_dest = $dest_pos[0];
776 $this->dest_dir = -1;
777 } elseif ($d == $d3) {
778 $this->x_src = $src_pos[0];
779 $this->src_dir = -1;
780 $this->x_dest = $dest_pos[1];
781 $this->dest_dir = 1;
782 } else {
783 $this->x_src = $src_pos[1];
784 $this->src_dir = 1;
785 $this->x_dest = $dest_pos[1];
786 $this->dest_dir = 1;
788 $this->y_src = $src_pos[2];
789 $this->y_dest = $dest_pos[2];
790 } // end of the "PMA_RT_Relation()" method
791 } // end of the "PMA_RT_Relation" class
793 * Draws and send the database schema
795 * @access public
796 * @see PMA_PDF
798 class PMA_RT {
800 * Defines private properties
802 var $tables = array();
803 var $relations = array();
804 var $ff = PMA_PDF_FONT;
805 var $x_max = 0;
806 var $y_max = 0;
807 var $scale;
808 var $x_min = 100000;
809 var $y_min = 100000;
810 var $t_marg = 10;
811 var $b_marg = 10;
812 var $l_marg = 10;
813 var $r_marg = 10;
814 var $tablewidth;
815 var $same_wide = 0;
818 * Sets X and Y minimum and maximum for a table cell
820 * @param string $ The table name
821 * @access private
823 function PMA_RT_setMinMax($table)
825 $this->x_max = max($this->x_max, $table->x + $table->width);
826 $this->y_max = max($this->y_max, $table->y + $table->height);
827 $this->x_min = min($this->x_min, $table->x);
828 $this->y_min = min($this->y_min, $table->y);
829 } // end of the "PMA_RT_setMinMax()" method
831 * Defines relation objects
833 * @param string $ The master table name
834 * @param string $ The relation field in the master table
835 * @param string $ The foreign table name
836 * @param string $ The relation field in the foreign table
837 * @access private
838 * @see PMA_RT_setMinMax
840 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field)
842 if (!isset($this->tables[$master_table])) {
843 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth);
844 $this->PMA_RT_setMinMax($this->tables[$master_table]);
846 if (!isset($this->tables[$foreign_table])) {
847 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth);
848 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
850 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
851 } // end of the "PMA_RT_addRelation()" method
853 * Draws the grid
855 * @global object the current PMA_PDF instance
856 * @access private
857 * @see PMA_PDF
859 function PMA_RT_strokeGrid()
861 global $pdf;
863 $pdf->SetMargins(0, 0);
864 $pdf->SetDrawColor(200, 200, 200);
865 // Draws horizontal lines
866 for ($l = 0; $l < 21; $l++) {
867 $pdf->line(0, $l * 10, $pdf->fh, $l * 10);
868 // Avoid duplicates
869 if ($l > 0) {
870 $pdf->SetXY(0, $l * 10);
871 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
872 $pdf->Cell(5, 5, ' ' . $label);
873 } // end if
874 } // end for
875 // Draws vertical lines
876 for ($j = 0; $j < 30 ;$j++) {
877 $pdf->line($j * 10, 0, $j * 10, $pdf->fw);
878 $pdf->SetXY($j * 10, 0);
879 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
880 $pdf->Cell(5, 7, $label);
881 } // end for
882 } // end of the "PMA_RT_strokeGrid()" method
884 * Draws relation arrows
886 * @param boolean $ Whether to use one color per relation or not
887 * @access private
888 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
890 function PMA_RT_drawRelations($change_color)
892 $i = 0;
893 foreach ($this->relations AS $relation) {
894 $relation->PMA_RT_Relation_draw($change_color, $i);
895 $i++;
896 } // end while
897 } // end of the "PMA_RT_drawRelations()" method
899 * Draws tables
901 * @param boolean $ Whether to display table position or not
902 * @access private
903 * @see PMA_RT_Table::PMA_RT_Table_draw()
905 function PMA_RT_drawTables($show_info, $draw_color = 0)
907 foreach ($this->tables AS $table) {
908 $table->PMA_RT_Table_draw($show_info, $this->ff, $draw_color);
910 } // end of the "PMA_RT_drawTables()" method
912 * Ouputs the PDF document to a file
914 * @global object The current PDF document
915 * @global string The current database name
916 * @global integer The current page number (from the
917 * $cfg['Servers'][$i]['table_coords'] table)
918 * @access private
919 * @see PMA_PDF
921 function PMA_RT_showRt()
923 global $pdf, $db, $pdf_page_number, $cfgRelation;
925 $pdf->SetFontSize(14);
926 $pdf->SetLineWidth(0.2);
927 $pdf->SetDisplayMode('fullpage');
928 // Get the name of this pdfpage to use as filename (Mike Beck)
929 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
930 . ' WHERE page_nr = ' . $pdf_page_number;
931 $_name_rs = PMA_query_as_cu($_name_sql);
932 if ($_name_rs) {
933 $_name_row = PMA_DBI_fetch_row($_name_rs);
934 $filename = $_name_row[0] . '.pdf';
936 // i don't know if there is a chance for this to happen, but rather be on the safe side:
937 if (empty($filename)) {
938 $filename = $pdf_page_number . '.pdf';
940 // $pdf->Output($db . '_' . $filename, TRUE);
941 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
942 } // end of the "PMA_RT_showRt()" method
944 * The "PMA_RT" constructor
946 * @param mixed $ The scaling factor
947 * @param integer $ The page number to draw (from the
948 * $cfg['Servers'][$i]['table_coords'] table)
949 * @param boolean $ Whether to display table position or not
950 * @param boolean $ Was originally whether to use one color per
951 * relation or not, now enables/disables color
952 * everywhere, due to some problems printing with color
953 * @param boolean $ Whether to draw grids or not
954 * @param boolean $ Whether all tables should have the same width or not
955 * @global object The current PDF document
956 * @global string The current db name
957 * @global array The relations settings
958 * @access private
959 * @see PMA_PDF
961 function __construct($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
963 global $pdf, $db, $cfgRelation, $with_doc;
965 $this->same_wide = $all_tab_same_wide;
966 // Initializes a new document
967 $pdf = new PMA_PDF('L', 'mm', $paper);
968 $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
969 $pdf->setCMargin(0);
970 $pdf->Open();
971 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
972 $pdf->AliasNbPages();
973 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
974 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
975 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
976 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
977 $this->ff = PMA_PDF_FONT;
978 $pdf->SetFont($this->ff, '', 14);
979 $pdf->SetAutoPageBreak('auto');
980 // Gets tables on this page
981 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
982 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
983 . ' AND pdf_page_number = ' . $which_rel;
984 $tab_rs = PMA_query_as_cu($tab_sql, null, PMA_DBI_QUERY_STORE);
985 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
986 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
987 // die('No tables');
988 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
989 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
990 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
992 // make doc //
993 if ($with_doc) {
994 $pdf->SetAutoPageBreak('auto', 15);
995 $pdf->setCMargin(1);
996 PMA_RT_DOC($alltables);
997 $pdf->SetAutoPageBreak('auto');
998 $pdf->setCMargin(0);
1001 $pdf->Addpage();
1003 if ($with_doc) {
1004 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1005 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1006 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1007 $this->t_marg = 18;
1008 $this->b_marg = 18;
1011 /* snip */
1013 foreach ($alltables AS $table) {
1014 if (!isset($this->tables[$table])) {
1015 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
1018 if ($this->same_wide) {
1019 $this->tables[$table]->width = $this->tablewidth;
1021 $this->PMA_RT_setMinMax($this->tables[$table]);
1023 // Defines the scale factor
1024 $this->scale = ceil(
1025 max(
1026 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1027 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1028 * 100) / 100;
1030 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1031 // Builds and save the PDF document
1032 $pdf->PMA_PDF_setLineWidthScale(0.1);
1034 if ($show_grid) {
1035 $pdf->SetFontSize(10);
1036 $this->PMA_RT_strokeGrid();
1038 $pdf->PMA_PDF_setFontSizeScale(14);
1039 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1040 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1041 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1042 // . ' AND master_table IN (' . $intable . ')'
1043 // . ' AND foreign_table IN (' . $intable . ')';
1044 // $result = PMA_query_as_cu($sql);
1046 // lem9:
1047 // previous logic was checking master tables and foreign tables
1048 // but I think that looping on every table of the pdf page as a master
1049 // and finding its foreigns is OK (then we can support innodb)
1050 $seen_a_relation = false;
1051 foreach ($alltables AS $one_table) {
1052 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1053 if ($exist_rel) {
1054 $seen_a_relation = true;
1055 foreach ($exist_rel AS $master_field => $rel) {
1056 // put the foreign table on the schema only if selected
1057 // by the user
1058 // (do not use array_search() because we would have to
1059 // to do a === FALSE and this is not PHP3 compatible)
1060 if (in_array($rel['foreign_table'], $alltables)) {
1061 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
1063 } // end while
1064 } // end if
1065 } // end while
1066 // loic1: also show tables without relations
1067 // $norelations = TRUE;
1068 // if ($result && PMA_DBI_num_rows($result) > 0) {
1069 // $norelations = FALSE;
1070 // while ($row = PMA_DBI_fetch_assoc($result)) {
1071 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1072 // }
1073 // }
1074 // if ($norelations == FALSE) {
1075 if ($seen_a_relation) {
1076 $this->PMA_RT_drawRelations($change_color);
1079 $this->PMA_RT_drawTables($show_info, $change_color);
1081 $this->PMA_RT_showRt();
1082 } // end of the "PMA_RT()" method
1083 } // end of the "PMA_RT" class
1085 function PMA_RT_DOC($alltables)
1087 global $db, $pdf, $orientation, $paper;
1088 // TOC
1089 $pdf->addpage($GLOBALS['orientation']);
1090 $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C');
1091 $pdf->Ln(15);
1092 $i = 1;
1093 foreach ($alltables AS $table) {
1094 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1095 $pdf->SetX(10);
1096 // $pdf->Ln(1);
1097 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1098 $pdf->SetX(10);
1099 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1100 // $pdf->Ln(1);
1101 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1102 while ($row = PMA_DBI_fetch_assoc($result)) {
1103 $pdf->SetX(20);
1104 $field_name = $row['Field'];
1105 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1106 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1108 $lasttable = $table;
1109 $i++;
1111 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1112 $pdf->SetX(10);
1113 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1114 $pdf->SetX(10);
1115 $pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1116 $z = 0;
1117 foreach ($alltables AS $table) {
1118 $z++;
1119 $pdf->addpage($GLOBALS['orientation']);
1120 $pdf->Bookmark($table);
1121 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1122 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1123 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1124 $pdf->SetFont('', 'B', 18);
1125 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1126 $pdf->SetFont('', '', 8);
1127 $pdf->ln();
1129 $cfgRelation = PMA_getRelationsParam();
1130 $comments = PMA_getComments($db, $table);
1131 if ($cfgRelation['mimework']) {
1132 $mime_map = PMA_getMIME($db, $table, true);
1136 * Gets table informations
1138 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';', null, PMA_DBI_QUERY_STORE);
1139 $showtable = PMA_DBI_fetch_assoc($result);
1140 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1141 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1142 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1143 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1144 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1146 PMA_DBI_free_result($result);
1147 unset($result);
1150 * Gets table keys and retains them
1152 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1153 $primary = '';
1154 $indexes = array();
1155 $lastIndex = '';
1156 $indexes_info = array();
1157 $indexes_data = array();
1158 $pk_array = array(); // will be use to emphasis prim. keys in the table
1159 // view
1160 while ($row = PMA_DBI_fetch_assoc($result)) {
1161 // Backups the list of primary keys
1162 if ($row['Key_name'] == 'PRIMARY') {
1163 $primary .= $row['Column_name'] . ', ';
1164 $pk_array[$row['Column_name']] = 1;
1166 // Retains keys informations
1167 if ($row['Key_name'] != $lastIndex) {
1168 $indexes[] = $row['Key_name'];
1169 $lastIndex = $row['Key_name'];
1171 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1172 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1173 if (isset($row['Cardinality'])) {
1174 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1176 // I don't know what does following column mean....
1177 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1178 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1180 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1181 if (isset($row['Sub_part'])) {
1182 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1184 } // end while
1185 if ($result) {
1186 PMA_DBI_free_result($result);
1190 * Gets fields properties
1192 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1193 $fields_cnt = PMA_DBI_num_rows($result);
1194 // Check if we can use Relations (Mike Beck)
1195 if (!empty($cfgRelation['relation'])) {
1196 // Find which tables are related with the current one and write it in
1197 // an array
1198 $res_rel = PMA_getForeigners($db, $table);
1200 if (count($res_rel) > 0) {
1201 $have_rel = true;
1202 } else {
1203 $have_rel = false;
1205 } else {
1206 $have_rel = false;
1207 } // end if
1209 * Displays the comments of the table if MySQL >= 3.23
1212 $break = false;
1213 if (!empty($show_comment)) {
1214 $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1);
1215 $break = true;
1218 if (!empty($create_time)) {
1219 $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1);
1220 $break = true;
1223 if (!empty($update_time)) {
1224 $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1);
1225 $break = true;
1228 if (!empty($check_time)) {
1229 $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1);
1230 $break = true;
1233 if ($break == true) {
1234 $pdf->Cell(0, 3, '', 0, 1);
1235 $pdf->Ln();
1238 $pdf->SetFont('', 'B');
1239 if (isset($orientation) && $orientation == 'L') {
1240 $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1241 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1242 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1243 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1244 $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1245 $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1246 $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1248 if ($paper == 'A4') {
1249 $comments_width = 67;
1250 } else {
1251 // this is really intended for 'letter'
1253 * @todo find optimal width for all formats
1255 $comments_width = 50;
1257 $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1258 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1259 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1260 } else {
1261 $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1262 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1263 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1264 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1265 $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1266 $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1267 $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1268 $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1269 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1270 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1272 $pdf->SetFont('', '');
1274 while ($row = PMA_DBI_fetch_assoc($result)) {
1275 $type = $row['Type'];
1276 // reformat mysql query output - staybyte - 9. June 2001
1277 // loic1: set or enum types: slashes single quotes inside options
1278 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1279 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1280 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1281 $type_nowrap = '';
1283 $binary = 0;
1284 $unsigned = 0;
1285 $zerofill = 0;
1286 } else {
1287 $type_nowrap = ' nowrap="nowrap"';
1288 $type = preg_replace('@BINARY@i', '', $type);
1289 $type = preg_replace('@ZEROFILL@i', '', $type);
1290 $type = preg_replace('@UNSIGNED@i', '', $type);
1291 if (empty($type)) {
1292 $type = '&nbsp;';
1295 $binary = stristr($row['Type'], 'BINARY');
1296 $unsigned = stristr($row['Type'], 'UNSIGNED');
1297 $zerofill = stristr($row['Type'], 'ZEROFILL');
1299 $strAttribute = ' ';
1300 if ($binary) {
1301 $strAttribute = 'BINARY';
1303 if ($unsigned) {
1304 $strAttribute = 'UNSIGNED';
1306 if ($zerofill) {
1307 $strAttribute = 'UNSIGNED ZEROFILL';
1309 if (!isset($row['Default'])) {
1310 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1311 $row['Default'] = 'NULL';
1314 $field_name = $row['Field'];
1315 // $pdf->Ln();
1316 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1317 $pdf->Bookmark($field_name, 1, -1);
1318 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1319 $pdf_row = array($field_name,
1320 $type,
1321 $strAttribute,
1322 ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1323 ((isset($row['Default'])) ? $row['Default'] : ''),
1324 $row['Extra'],
1325 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1326 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1327 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1329 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1330 if (isset($res_rel[$field_name]['foreign_table']) AND
1331 isset($res_rel[$field_name]['foreign_field']) AND
1332 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1335 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1336 } else {
1337 unset($links[6]);
1339 $pdf->Row($pdf_row, $links);
1341 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1342 //echo ' ' . $field_name . '&nbsp;' . "\n";
1344 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1345 $pdf->Cell(20, 8, $strAttribute, 1, 0, 'L');
1346 $pdf->Cell(15, 8, , 1, 0, 'L');
1347 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1348 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1349 if ($have_rel) {
1350 if (isset($res_rel[$field_name])) {
1351 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1354 if ($cfgRelation['commwork']) {
1355 if (isset($comments[$field_name])) {
1356 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1358 } */
1359 } // end while
1360 $pdf->SetFont('', '', 14);
1361 PMA_DBI_free_result($result);
1362 } //end each
1363 } // end function PMA_RT_DOC
1366 * Main logic
1368 if (!isset($pdf_page_number)) {
1369 $pdf_page_number = 1;
1372 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1373 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1374 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1375 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1376 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1377 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1378 $paper = isset($paper) ? $paper : 'A4';
1379 PMA_DBI_select_db($db);
1381 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper);