bug #2363919 [display] Incorrect size for view
[phpmyadmin/crack.git] / pdf_schema.php
blob0113cbaa4589d53d83e32cb7e7ec4d4a19c098d0
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';
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
51 class PMA_PDF extends TCPDF {
52 /**
53 * Defines private properties
55 var $x_min;
56 var $y_min;
57 var $l_marg = 10;
58 var $t_marg = 10;
59 var $scale;
60 var $PMA_links;
61 var $Outlines = array();
62 var $def_outlines;
63 var $Alias = array();
64 var $widths;
66 public function getFh()
68 return $this->fh;
71 public function getFw()
73 return $this->fw;
76 public function setCMargin($c_margin)
78 $this->cMargin = $c_margin;
81 function SetAlias($name, $value)
83 $this->Alias[$name] = $value ;
86 function _putpages()
88 if (count($this->Alias) > 0) {
89 $nb = $this->page;
90 foreach ($this->Alias AS $alias => $value) {
91 for ($n = 1;$n <= $nb;$n++)
92 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
95 parent::_putpages();
98 /**
99 * Sets the scaling factor, defines minimum coordinates and margins
101 * @param double $ The scaling factor
102 * @param double $ The minimum X coordinate
103 * @param double $ The minimum Y coordinate
104 * @param double $ The left margin
105 * @param double $ The top margin
106 * @access public
108 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
110 $this->scale = $scale;
111 $this->x_min = $x_min;
112 $this->y_min = $y_min;
113 if ($this->l_marg != -1) {
114 $this->l_marg = $l_marg;
116 if ($this->t_marg != -1) {
117 $this->t_marg = $t_marg;
119 } // end of the "PMA_PDF_setScale" function
121 * Outputs a scaled cell
123 * @param double $ The cell width
124 * @param double $ The cell height
125 * @param string $ The text to output
126 * @param mixed $ Whether to add borders or not
127 * @param integer $ Where to put the cursor once the output is done
128 * @param string $ Align mode
129 * @param integer $ Whether to fill the cell with a color or not
130 * @access public
131 * @see FPDF::Cell()
133 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
135 $h = $h / $this->scale;
136 $w = $w / $this->scale;
137 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
138 } // end of the "PMA_PDF_cellScale" function
140 * Draws a scaled line
142 * @param double $ The horizontal position of the starting point
143 * @param double $ The vertical position of the starting point
144 * @param double $ The horizontal position of the ending point
145 * @param double $ The vertical position of the ending point
146 * @access public
147 * @see FPDF::Line()
149 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
151 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
152 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
153 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
154 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
155 $this->Line($x1, $y1, $x2, $y2);
156 } // end of the "PMA_PDF_lineScale" function
158 * Sets x and y scaled positions
160 * @param double $ The x position
161 * @param double $ The y position
162 * @access public
163 * @see FPDF::SetXY()
165 function PMA_PDF_setXyScale($x, $y)
167 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
168 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
169 $this->SetXY($x, $y);
170 } // end of the "PMA_PDF_setXyScale" function
172 * Sets the X scaled positions
174 * @param double $ The x position
175 * @access public
176 * @see FPDF::SetX()
178 function PMA_PDF_setXScale($x)
180 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
181 $this->SetX($x);
182 } // end of the "PMA_PDF_setXScale" function
184 * Sets the scaled font size
186 * @param double $ The font size (in points)
187 * @access public
188 * @see FPDF::SetFontSize()
190 function PMA_PDF_setFontSizeScale($size)
192 // Set font size in points
193 $size = $size / $this->scale;
194 $this->SetFontSize($size);
195 } // end of the "PMA_PDF_setFontSizeScale" function
197 * Sets the scaled line width
199 * @param double $ The line width
200 * @access public
201 * @see FPDF::SetLineWidth()
203 function PMA_PDF_setLineWidthScale($width)
205 $width = $width / $this->scale;
206 $this->SetLineWidth($width);
207 } // end of the "PMA_PDF_setLineWidthScale" function
209 * Displays an error message
211 * @param string $ the error mesage
212 * @global array the PMA configuration array
213 * @global integer the current server id
214 * @global string the current language
215 * @global string the charset to convert to
216 * @global string the current database name
217 * @global string the current charset
218 * @global string the current text direction
219 * @global string a localized string
220 * @global string an other localized string
221 * @access public
223 function PMA_PDF_die($error_message = '')
225 global $cfg;
226 global $server, $lang, $convcharset, $db;
227 global $charset, $text_dir, $strRunning, $strDatabase;
229 require_once './libraries/header.inc.php';
231 echo '<p><strong>PDF - ' . $GLOBALS['strError'] . '</strong></p>' . "\n";
232 if (!empty($error_message)) {
233 $error_message = htmlspecialchars($error_message);
235 echo '<p>' . "\n";
236 echo ' ' . $error_message . "\n";
237 echo '</p>' . "\n";
239 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
240 . '">' . $GLOBALS['strBack'] . '</a>';
241 echo "\n";
243 require_once './libraries/footer.inc.php';
244 } // end of the "PMA_PDF_die()" function
246 * Aliases the "Error()" function from the FPDF class to the
247 * "PMA_PDF_die()" one
249 * @param string $ the error mesage
250 * @access public
251 * @see PMA_PDF_die
253 function Error($error_message = '')
255 $this->PMA_PDF_die($error_message);
256 } // end of the "Error()" method
257 function Header()
259 // $datefmt
260 // We only show this if we find something in the new pdf_pages table
262 // This function must be named "Header" to work with the FPDF library
263 global $cfgRelation, $db, $pdf_page_number, $with_doc;
264 if ($with_doc) {
265 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
266 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
267 . ' AND page_nr = \'' . $pdf_page_number . '\'';
268 $test_rs = PMA_query_as_cu($test_query);
269 $pages = @PMA_DBI_fetch_assoc($test_rs);
270 $this->SetFont('', 'B', 14);
271 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
272 $this->SetFont('', '');
273 $this->Ln();
276 function Footer()
278 // This function must be named "Footer" to work with the FPDF library
279 global $with_doc;
280 if ($with_doc) {
281 $this->SetY(-15);
282 $this->SetFont('', '', 14);
283 $this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
284 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
285 $this->SetY(20);
288 function Bookmark($txt, $level = 0, $y = 0)
290 // Add a bookmark
291 $this->Outlines[0][] = $level;
292 $this->Outlines[1][] = $txt;
293 $this->Outlines[2][] = $this->page;
294 if ($y == -1) {
295 $y = $this->GetY();
297 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
300 function _putbookmarks()
302 if (count($this->Outlines) > 0) {
303 // Save object number
304 $memo_n = $this->n;
305 // Take the number of sub elements for an outline
306 $nb_outlines = sizeof($this->Outlines[0]);
307 $first_level = array();
308 $parent = array();
309 $parent[0] = 1;
310 for ($i = 0; $i < $nb_outlines; $i++) {
311 $level = $this->Outlines[0][$i];
312 $kids = 0;
313 $last = -1;
314 $prev = -1;
315 $next = -1;
316 if ($i > 0) {
317 $cursor = $i-1;
318 // Take the previous outline in the same level
319 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
320 $cursor--;
321 if ($this->Outlines[0][$cursor] == $level) {
322 $prev = $cursor;
325 if ($i < $nb_outlines-1) {
326 $cursor = $i + 1;
327 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
328 // Take the immediate kid in level + 1
329 if ($this->Outlines[0][$cursor] == $level + 1) {
330 $kids++;
331 $last = $cursor;
333 $cursor++;
335 $cursor = $i + 1;
336 // Take the next outline in the same level
337 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
338 $cursor++;
339 if ($this->Outlines[0][$cursor] == $level) {
340 $next = $cursor;
343 $this->_newobj();
344 $parent[$level + 1] = $this->n;
345 if ($level == 0) {
346 $first_level[] = $this->n;
348 $this->_out('<<');
349 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
350 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
351 if ($prev != -1) {
352 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
354 if ($next != -1) {
355 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
357 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
358 if ($kids > 0) {
359 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
360 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
361 $this->_out('/Count -' . $kids);
363 $this->_out('>>');
364 $this->_out('endobj');
366 // First page of outlines
367 $this->_newobj();
368 $this->def_outlines = $this->n;
369 $this->_out('<<');
370 $this->_out('/Type');
371 $this->_out('/Outlines');
372 $this->_out('/First ' . $first_level[0] . ' 0 R');
373 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
374 $this->_out('/Count ' . sizeof($first_level));
375 $this->_out('>>');
376 $this->_out('endobj');
380 function _putresources()
382 parent::_putresources();
383 $this->_putbookmarks();
386 function _putcatalog()
388 parent::_putcatalog();
389 if (count($this->Outlines) > 0) {
390 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
391 $this->_out('/PageMode /UseOutlines');
394 function SetWidths($w)
396 // column widths
397 $this->widths = $w;
400 function Row($data, $links)
402 // line height
403 $nb = 0;
404 $data_cnt = count($data);
405 for ($i = 0;$i < $data_cnt;$i++)
406 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
407 $il = $this->FontSize;
408 $h = ($il + 1) * $nb;
409 // page break if necessary
410 $this->CheckPageBreak($h);
411 // draw the cells
412 $data_cnt = count($data);
413 for ($i = 0;$i < $data_cnt;$i++) {
414 $w = $this->widths[$i];
415 // save current position
416 $x = $this->GetX();
417 $y = $this->GetY();
418 // draw the border
419 $this->Rect($x, $y, $w, $h);
420 if (isset($links[$i])) {
421 $this->Link($x, $y, $w, $h, $links[$i]);
423 // print text
424 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
425 // go to right side
426 $this->SetXY($x + $w, $y);
428 // go to line
429 $this->Ln($h);
432 function CheckPageBreak($h)
434 // if height h overflows, manual page break
435 if ($this->GetY() + $h > $this->PageBreakTrigger) {
436 $this->AddPage($this->CurOrientation);
440 function NbLines($w, $txt)
442 // compute number of lines used by a multicell of width w
443 $cw = &$this->CurrentFont['cw'];
444 if ($w == 0) {
445 $w = $this->w - $this->rMargin - $this->x;
447 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
448 $s = str_replace("\r", '', $txt);
449 $nb = strlen($s);
450 if ($nb > 0 and $s[$nb-1] == "\n") {
451 $nb--;
453 $sep = -1;
454 $i = 0;
455 $j = 0;
456 $l = 0;
457 $nl = 1;
458 while ($i < $nb) {
459 $c = $s[$i];
460 if ($c == "\n") {
461 $i++;
462 $sep = -1;
463 $j = $i;
464 $l = 0;
465 $nl++;
466 continue;
468 if ($c == ' ') {
469 $sep = $i;
471 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
472 if ($l > $wmax) {
473 if ($sep == -1) {
474 if ($i == $j) {
475 $i++;
477 } else {
478 $i = $sep + 1;
480 $sep = -1;
481 $j = $i;
482 $l = 0;
483 $nl++;
484 } else {
485 $i++;
488 return $nl;
490 } // end of the "PMA_PDF" class
494 * Draws tables schema
496 * @access private
497 * @see PMA_RT
499 class PMA_RT_Table {
501 * Defines private properties
503 var $nb_fiels;
504 var $table_name;
505 var $width = 0;
506 var $height;
507 var $fields = array();
508 var $height_cell = 6;
509 var $x, $y;
510 var $primary = array();
513 * Sets the width of the table
515 * @param integer $ The font size
516 * @global object The current PDF document
517 * @access private
518 * @see PMA_PDF
520 function PMA_RT_Table_setWidth($ff)
522 // this looks buggy to me... does it really work if
523 // there are fields that require wider cells than the name of the table?
524 global $pdf;
526 foreach ($this->fields AS $field) {
527 $this->width = max($this->width, $pdf->GetStringWidth($field));
529 $this->width += $pdf->GetStringWidth(' ');
530 $pdf->SetFont($ff, 'B');
531 $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
532 $pdf->SetFont($ff, '');
533 } // end of the "PMA_RT_Table_setWidth()" method
535 * Sets the height of the table
537 * @access private
539 function PMA_RT_Table_setHeight()
541 $this->height = (count($this->fields) + 1) * $this->height_cell;
542 } // end of the "PMA_RT_Table_setHeight()" method
544 * Do draw the table
546 * @param boolean $ Whether to display table position or not
547 * @param integer $ The font size
548 * @param boolean $ Whether to display color
549 * @param integer $ The max. with among tables
550 * @global object The current PDF document
551 * @access private
552 * @see PMA_PDF
554 function PMA_RT_Table_draw($show_info, $ff, $setcolor = 0)
556 global $pdf, $with_doc;
558 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
559 $pdf->SetFont($ff, 'B');
560 if ($setcolor) {
561 $pdf->SetTextColor(200);
562 $pdf->SetFillColor(0, 0, 128);
564 if ($with_doc) {
565 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
566 } else {
567 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
570 if ($show_info) {
571 $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]['-']);
572 } else {
573 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
575 $pdf->PMA_PDF_setXScale($this->x);
576 $pdf->SetFont($ff, '');
577 $pdf->SetTextColor(0);
578 $pdf->SetFillColor(255);
580 foreach ($this->fields AS $field) {
581 // loic1 : PHP3 fix
582 // if (in_array($field, $this->primary)) {
583 if ($setcolor) {
584 if (in_array($field, $this->primary)) {
585 $pdf->SetFillColor(215, 121, 123);
587 if ($field == $this->displayfield) {
588 $pdf->SetFillColor(142, 159, 224);
591 if ($with_doc) {
592 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
593 } else {
594 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
597 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
598 $pdf->PMA_PDF_setXScale($this->x);
599 $pdf->SetFillColor(255);
600 } // end while
601 /*if ($pdf->PageNo() > 1) {
602 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
603 } */
604 } // end of the "PMA_RT_Table_draw()" method
606 * The "PMA_RT_Table" constructor
608 * @param string $ The table name
609 * @param integer $ The font size
610 * @param integer $ The max. with among tables
611 * @global object The current PDF document
612 * @global integer The current page number (from the
613 * $cfg['Servers'][$i]['table_coords'] table)
614 * @global array The relations settings
615 * @global string The current db name
616 * @access private
617 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
618 PMA_RT_Table::PMA_RT_Table_setHeight
620 function __construct($table_name, $ff, &$same_wide_width, $show_keys)
622 global $pdf, $pdf_page_number, $cfgRelation, $db;
624 $this->table_name = $table_name;
625 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
626 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
627 if (!$result || !PMA_DBI_num_rows($result)) {
628 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
630 // load fields
631 //check to see if it will load all fields or only the foreign keys
632 if ($show_keys) {
633 $indexes = PMA_Index::getFromTable($this->table_name, $db);
634 $all_columns = array();
635 foreach ($indexes as $index) {
636 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
638 $this->fields = array_keys($all_columns);
639 } else {
640 while ($row = PMA_DBI_fetch_row($result)) {
641 $this->fields[] = $row[0];
644 // height and width
645 $this->PMA_RT_Table_setWidth($ff);
646 $this->PMA_RT_Table_setHeight();
647 if ($same_wide_width < $this->width) {
648 $same_wide_width = $this->width;
650 // x and y
651 $sql = 'SELECT x, y FROM '
652 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
653 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
654 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
655 . ' AND pdf_page_number = ' . $pdf_page_number;
656 $result = PMA_query_as_cu($sql, false, PMA_DBI_QUERY_STORE);
658 if (!$result || !PMA_DBI_num_rows($result)) {
659 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
661 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
662 $this->x = (double) $this->x;
663 $this->y = (double) $this->y;
664 // displayfield
665 $this->displayfield = PMA_getDisplayField($db, $table_name);
666 // index
667 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
668 if (PMA_DBI_num_rows($result) > 0) {
669 while ($row = PMA_DBI_fetch_assoc($result)) {
670 if ($row['Key_name'] == 'PRIMARY') {
671 $this->primary[] = $row['Column_name'];
674 } // end if
675 } // end of the "PMA_RT_Table()" method
676 } // end class "PMA_RT_Table"
678 * Draws relation links
680 * @access private
681 * @see PMA_RT
683 class PMA_RT_Relation {
685 * Defines private properties
687 var $x_src, $y_src;
688 var $src_dir ;
689 var $dest_dir;
690 var $x_dest, $y_dest;
691 var $w_tick = 5;
694 * Gets arrows coordinates
696 * @param string $ The current table name
697 * @param string $ The relation column name
698 * @return array Arrows coordinates
699 * @access private
701 function PMA_RT_Relation_getXy($table, $column)
703 $pos = array_search($column, $table->fields);
704 // x_left, x_right, y
705 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
706 } // end of the "PMA_RT_Relation_getXy()" method
708 * Do draws relation links
710 * @param boolean $ Whether to use one color per relation or not
711 * @param integer $ The id of the link to draw
712 * @global object The current PDF document
713 * @access private
714 * @see PMA_PDF
716 function PMA_RT_Relation_draw($change_color, $i)
718 global $pdf;
720 if ($change_color) {
721 $d = $i % 6;
722 $j = ($i - $d) / 6;
723 $j = $j % 4;
724 $j++;
725 $case = array(
726 array(1, 0, 0),
727 array(0, 1, 0),
728 array(0, 0, 1),
729 array(1, 1, 0),
730 array(1, 0, 1),
731 array(0, 1, 1)
733 list ($a, $b, $c) = $case[$d];
734 $e = (1 - ($j - 1) / 6);
735 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
736 } else {
737 $pdf->SetDrawColor(0);
738 } // end if... else...
739 $pdf->PMA_PDF_setLineWidthScale(0.2);
740 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
741 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
742 $pdf->PMA_PDF_setLineWidthScale(0.1);
743 $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);
744 // arrow
745 $root2 = 2 * sqrt(2);
746 $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);
747 $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);
749 $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);
750 $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);
751 $pdf->SetDrawColor(0);
752 } // end of the "PMA_RT_Relation_draw()" method
754 * The "PMA_RT_Relation" constructor
756 * @param string $ The master table name
757 * @param string $ The relation field in the master table
758 * @param string $ The foreign table name
759 * @param string $ The relation field in the foreign table
760 * @access private
761 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
763 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
765 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
766 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
767 $src_left = $src_pos[0] - $this->w_tick;
768 $src_right = $src_pos[1] + $this->w_tick;
769 $dest_left = $dest_pos[0] - $this->w_tick;
770 $dest_right = $dest_pos[1] + $this->w_tick;
772 $d1 = abs($src_left - $dest_left);
773 $d2 = abs($src_right - $dest_left);
774 $d3 = abs($src_left - $dest_right);
775 $d4 = abs($src_right - $dest_right);
776 $d = min($d1, $d2, $d3, $d4);
778 if ($d == $d1) {
779 $this->x_src = $src_pos[0];
780 $this->src_dir = -1;
781 $this->x_dest = $dest_pos[0];
782 $this->dest_dir = -1;
783 } elseif ($d == $d2) {
784 $this->x_src = $src_pos[1];
785 $this->src_dir = 1;
786 $this->x_dest = $dest_pos[0];
787 $this->dest_dir = -1;
788 } elseif ($d == $d3) {
789 $this->x_src = $src_pos[0];
790 $this->src_dir = -1;
791 $this->x_dest = $dest_pos[1];
792 $this->dest_dir = 1;
793 } else {
794 $this->x_src = $src_pos[1];
795 $this->src_dir = 1;
796 $this->x_dest = $dest_pos[1];
797 $this->dest_dir = 1;
799 $this->y_src = $src_pos[2];
800 $this->y_dest = $dest_pos[2];
801 } // end of the "PMA_RT_Relation()" method
802 } // end of the "PMA_RT_Relation" class
804 * Draws and send the database schema
806 * @access public
807 * @see PMA_PDF
809 class PMA_RT {
811 * Defines private properties
813 var $tables = array();
814 var $relations = array();
815 var $ff = PMA_PDF_FONT;
816 var $x_max = 0;
817 var $y_max = 0;
818 var $scale;
819 var $x_min = 100000;
820 var $y_min = 100000;
821 var $t_marg = 10;
822 var $b_marg = 10;
823 var $l_marg = 10;
824 var $r_marg = 10;
825 var $tablewidth;
826 var $same_wide = 0;
829 * Sets X and Y minimum and maximum for a table cell
831 * @param string $ The table name
832 * @access private
834 function PMA_RT_setMinMax($table)
836 $this->x_max = max($this->x_max, $table->x + $table->width);
837 $this->y_max = max($this->y_max, $table->y + $table->height);
838 $this->x_min = min($this->x_min, $table->x);
839 $this->y_min = min($this->y_min, $table->y);
840 } // end of the "PMA_RT_setMinMax()" method
842 * Defines relation objects
844 * @param string $ The master table name
845 * @param string $ The relation field in the master table
846 * @param string $ The foreign table name
847 * @param string $ The relation field in the foreign table
848 * @access private
849 * @see PMA_RT_setMinMax
851 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field)
853 if (!isset($this->tables[$master_table])) {
854 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth);
855 $this->PMA_RT_setMinMax($this->tables[$master_table]);
857 if (!isset($this->tables[$foreign_table])) {
858 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth);
859 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
861 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
862 } // end of the "PMA_RT_addRelation()" method
864 * Draws the grid
866 * @global object the current PMA_PDF instance
867 * @access private
868 * @see PMA_PDF
870 function PMA_RT_strokeGrid()
872 global $pdf;
874 $pdf->SetMargins(0, 0);
875 $pdf->SetDrawColor(200, 200, 200);
876 // Draws horizontal lines
877 for ($l = 0; $l < 21; $l++) {
878 $pdf->line(0, $l * 10, $pdf->fh, $l * 10);
879 // Avoid duplicates
880 if ($l > 0) {
881 $pdf->SetXY(0, $l * 10);
882 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
883 $pdf->Cell(5, 5, ' ' . $label);
884 } // end if
885 } // end for
886 // Draws vertical lines
887 for ($j = 0; $j < 30 ;$j++) {
888 $pdf->line($j * 10, 0, $j * 10, $pdf->fw);
889 $pdf->SetXY($j * 10, 0);
890 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
891 $pdf->Cell(5, 7, $label);
892 } // end for
893 } // end of the "PMA_RT_strokeGrid()" method
895 * Draws relation arrows
897 * @param boolean $ Whether to use one color per relation or not
898 * @access private
899 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
901 function PMA_RT_drawRelations($change_color)
903 $i = 0;
904 foreach ($this->relations AS $relation) {
905 $relation->PMA_RT_Relation_draw($change_color, $i);
906 $i++;
907 } // end while
908 } // end of the "PMA_RT_drawRelations()" method
910 * Draws tables
912 * @param boolean $ Whether to display table position or not
913 * @access private
914 * @see PMA_RT_Table::PMA_RT_Table_draw()
916 function PMA_RT_drawTables($show_info, $draw_color = 0)
918 foreach ($this->tables AS $table) {
919 $table->PMA_RT_Table_draw($show_info, $this->ff, $draw_color);
921 } // end of the "PMA_RT_drawTables()" method
923 * Ouputs the PDF document to a file
925 * @global object The current PDF document
926 * @global string The current database name
927 * @global integer The current page number (from the
928 * $cfg['Servers'][$i]['table_coords'] table)
929 * @access private
930 * @see PMA_PDF
932 function PMA_RT_showRt()
934 global $pdf, $db, $pdf_page_number, $cfgRelation;
936 $pdf->SetFontSize(14);
937 $pdf->SetLineWidth(0.2);
938 $pdf->SetDisplayMode('fullpage');
939 // Get the name of this pdfpage to use as filename (Mike Beck)
940 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
941 . ' WHERE page_nr = ' . $pdf_page_number;
942 $_name_rs = PMA_query_as_cu($_name_sql);
943 if ($_name_rs) {
944 $_name_row = PMA_DBI_fetch_row($_name_rs);
945 $filename = $_name_row[0] . '.pdf';
947 // i don't know if there is a chance for this to happen, but rather be on the safe side:
948 if (empty($filename)) {
949 $filename = $pdf_page_number . '.pdf';
951 // $pdf->Output($db . '_' . $filename, TRUE);
952 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
953 } // end of the "PMA_RT_showRt()" method
955 * The "PMA_RT" constructor
957 * @param mixed $ The scaling factor
958 * @param integer $ The page number to draw (from the
959 * $cfg['Servers'][$i]['table_coords'] table)
960 * @param boolean $ Whether to display table position or not
961 * @param boolean $ Was originally whether to use one color per
962 * relation or not, now enables/disables color
963 * everywhere, due to some problems printing with color
964 * @param boolean $ Whether to draw grids or not
965 * @param boolean $ Whether all tables should have the same width or not
966 * @param boolean $ Wheter to show all field or only the keys
967 * @global object The current PDF document
968 * @global string The current db name
969 * @global array The relations settings
970 * @access private
971 * @see PMA_PDF
973 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)
975 global $pdf, $db, $cfgRelation, $with_doc;
977 $this->same_wide = $all_tab_same_wide;
978 // Initializes a new document
979 $pdf = new PMA_PDF('L', 'mm', $paper);
980 $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
981 $pdf->setCMargin(0);
982 $pdf->Open();
983 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
984 $pdf->AliasNbPages();
985 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
986 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
987 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
988 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
989 $this->ff = PMA_PDF_FONT;
990 $pdf->SetFont($this->ff, '', 14);
991 $pdf->SetAutoPageBreak('auto');
992 // Gets tables on this page
993 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
994 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
995 . ' AND pdf_page_number = ' . $which_rel;
996 $tab_rs = PMA_query_as_cu($tab_sql, null, PMA_DBI_QUERY_STORE);
997 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
998 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
999 // die('No tables');
1000 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1001 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1002 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1004 // make doc //
1005 if ($with_doc) {
1006 $pdf->SetAutoPageBreak('auto', 15);
1007 $pdf->setCMargin(1);
1008 PMA_RT_DOC($alltables);
1009 $pdf->SetAutoPageBreak('auto');
1010 $pdf->setCMargin(0);
1013 $pdf->Addpage();
1015 if ($with_doc) {
1016 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1017 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1018 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1019 $this->t_marg = 18;
1020 $this->b_marg = 18;
1023 /* snip */
1025 foreach ($alltables AS $table) {
1026 if (!isset($this->tables[$table])) {
1027 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys);
1030 if ($this->same_wide) {
1031 $this->tables[$table]->width = $this->tablewidth;
1033 $this->PMA_RT_setMinMax($this->tables[$table]);
1035 // Defines the scale factor
1036 $this->scale = ceil(
1037 max(
1038 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1039 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1040 * 100) / 100;
1042 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1043 // Builds and save the PDF document
1044 $pdf->PMA_PDF_setLineWidthScale(0.1);
1046 if ($show_grid) {
1047 $pdf->SetFontSize(10);
1048 $this->PMA_RT_strokeGrid();
1050 $pdf->PMA_PDF_setFontSizeScale(14);
1051 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1052 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1053 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1054 // . ' AND master_table IN (' . $intable . ')'
1055 // . ' AND foreign_table IN (' . $intable . ')';
1056 // $result = PMA_query_as_cu($sql);
1058 // lem9:
1059 // previous logic was checking master tables and foreign tables
1060 // but I think that looping on every table of the pdf page as a master
1061 // and finding its foreigns is OK (then we can support innodb)
1062 $seen_a_relation = false;
1063 foreach ($alltables AS $one_table) {
1064 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1065 if ($exist_rel) {
1066 $seen_a_relation = true;
1067 foreach ($exist_rel AS $master_field => $rel) {
1068 // put the foreign table on the schema only if selected
1069 // by the user
1070 // (do not use array_search() because we would have to
1071 // to do a === FALSE and this is not PHP3 compatible)
1072 if (in_array($rel['foreign_table'], $alltables)) {
1073 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
1075 } // end while
1076 } // end if
1077 } // end while
1078 // loic1: also show tables without relations
1079 // $norelations = TRUE;
1080 // if ($result && PMA_DBI_num_rows($result) > 0) {
1081 // $norelations = FALSE;
1082 // while ($row = PMA_DBI_fetch_assoc($result)) {
1083 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1084 // }
1085 // }
1086 // if ($norelations == FALSE) {
1087 if ($seen_a_relation) {
1088 $this->PMA_RT_drawRelations($change_color);
1091 $this->PMA_RT_drawTables($show_info, $change_color);
1093 $this->PMA_RT_showRt();
1094 } // end of the "PMA_RT()" method
1095 } // end of the "PMA_RT" class
1097 function PMA_RT_DOC($alltables)
1099 global $db, $pdf, $orientation, $paper;
1100 // TOC
1101 $pdf->addpage($GLOBALS['orientation']);
1102 $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C');
1103 $pdf->Ln(15);
1104 $i = 1;
1105 foreach ($alltables AS $table) {
1106 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1107 $pdf->SetX(10);
1108 // $pdf->Ln(1);
1109 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1110 $pdf->SetX(10);
1111 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1112 // $pdf->Ln(1);
1113 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1114 while ($row = PMA_DBI_fetch_assoc($result)) {
1115 $pdf->SetX(20);
1116 $field_name = $row['Field'];
1117 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1118 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1120 $lasttable = $table;
1121 $i++;
1123 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1124 $pdf->SetX(10);
1125 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1126 $pdf->SetX(10);
1127 $pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1128 $z = 0;
1129 foreach ($alltables AS $table) {
1130 $z++;
1131 $pdf->addpage($GLOBALS['orientation']);
1132 $pdf->Bookmark($table);
1133 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1134 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1135 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1136 $pdf->SetFont('', 'B', 18);
1137 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1138 $pdf->SetFont('', '', 8);
1139 $pdf->ln();
1141 $cfgRelation = PMA_getRelationsParam();
1142 $comments = PMA_getComments($db, $table);
1143 if ($cfgRelation['mimework']) {
1144 $mime_map = PMA_getMIME($db, $table, true);
1148 * Gets table informations
1150 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';', null, PMA_DBI_QUERY_STORE);
1151 $showtable = PMA_DBI_fetch_assoc($result);
1152 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1153 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1154 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1155 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1156 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1158 PMA_DBI_free_result($result);
1159 unset($result);
1162 * Gets table keys and retains them
1164 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1165 $primary = '';
1166 $indexes = array();
1167 $lastIndex = '';
1168 $indexes_info = array();
1169 $indexes_data = array();
1170 $pk_array = array(); // will be use to emphasis prim. keys in the table
1171 // view
1172 while ($row = PMA_DBI_fetch_assoc($result)) {
1173 // Backups the list of primary keys
1174 if ($row['Key_name'] == 'PRIMARY') {
1175 $primary .= $row['Column_name'] . ', ';
1176 $pk_array[$row['Column_name']] = 1;
1178 // Retains keys informations
1179 if ($row['Key_name'] != $lastIndex) {
1180 $indexes[] = $row['Key_name'];
1181 $lastIndex = $row['Key_name'];
1183 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1184 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1185 if (isset($row['Cardinality'])) {
1186 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1188 // I don't know what does following column mean....
1189 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1190 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1192 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1193 if (isset($row['Sub_part'])) {
1194 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1196 } // end while
1197 if ($result) {
1198 PMA_DBI_free_result($result);
1202 * Gets fields properties
1204 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1205 $fields_cnt = PMA_DBI_num_rows($result);
1206 // Check if we can use Relations (Mike Beck)
1207 if (!empty($cfgRelation['relation'])) {
1208 // Find which tables are related with the current one and write it in
1209 // an array
1210 $res_rel = PMA_getForeigners($db, $table);
1212 if (count($res_rel) > 0) {
1213 $have_rel = true;
1214 } else {
1215 $have_rel = false;
1217 } else {
1218 $have_rel = false;
1219 } // end if
1221 * Displays the comments of the table if MySQL >= 3.23
1224 $break = false;
1225 if (!empty($show_comment)) {
1226 $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1);
1227 $break = true;
1230 if (!empty($create_time)) {
1231 $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1);
1232 $break = true;
1235 if (!empty($update_time)) {
1236 $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1);
1237 $break = true;
1240 if (!empty($check_time)) {
1241 $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1);
1242 $break = true;
1245 if ($break == true) {
1246 $pdf->Cell(0, 3, '', 0, 1);
1247 $pdf->Ln();
1250 $pdf->SetFont('', 'B');
1251 if (isset($orientation) && $orientation == 'L') {
1252 $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1253 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1254 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1255 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1256 $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1257 $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1258 $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1260 if ($paper == 'A4') {
1261 $comments_width = 67;
1262 } else {
1263 // this is really intended for 'letter'
1265 * @todo find optimal width for all formats
1267 $comments_width = 50;
1269 $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1270 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1271 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1272 } else {
1273 $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1274 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1275 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1276 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1277 $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1278 $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1279 $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1280 $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1281 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1282 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1284 $pdf->SetFont('', '');
1286 while ($row = PMA_DBI_fetch_assoc($result)) {
1287 $type = $row['Type'];
1288 // reformat mysql query output - staybyte - 9. June 2001
1289 // loic1: set or enum types: slashes single quotes inside options
1290 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1291 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1292 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1293 $type_nowrap = '';
1295 $binary = 0;
1296 $unsigned = 0;
1297 $zerofill = 0;
1298 } else {
1299 $type_nowrap = ' nowrap="nowrap"';
1300 $type = preg_replace('@BINARY@i', '', $type);
1301 $type = preg_replace('@ZEROFILL@i', '', $type);
1302 $type = preg_replace('@UNSIGNED@i', '', $type);
1303 if (empty($type)) {
1304 $type = '&nbsp;';
1307 $binary = stristr($row['Type'], 'BINARY');
1308 $unsigned = stristr($row['Type'], 'UNSIGNED');
1309 $zerofill = stristr($row['Type'], 'ZEROFILL');
1311 $strAttribute = ' ';
1312 if ($binary) {
1313 $strAttribute = 'BINARY';
1315 if ($unsigned) {
1316 $strAttribute = 'UNSIGNED';
1318 if ($zerofill) {
1319 $strAttribute = 'UNSIGNED ZEROFILL';
1321 if (!isset($row['Default'])) {
1322 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1323 $row['Default'] = 'NULL';
1326 $field_name = $row['Field'];
1327 // $pdf->Ln();
1328 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1329 $pdf->Bookmark($field_name, 1, -1);
1330 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1331 $pdf_row = array($field_name,
1332 $type,
1333 $strAttribute,
1334 ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1335 ((isset($row['Default'])) ? $row['Default'] : ''),
1336 $row['Extra'],
1337 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1338 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1339 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1341 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1342 if (isset($res_rel[$field_name]['foreign_table']) AND
1343 isset($res_rel[$field_name]['foreign_field']) AND
1344 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1347 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1348 } else {
1349 unset($links[6]);
1351 $pdf->Row($pdf_row, $links);
1353 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1354 //echo ' ' . $field_name . '&nbsp;' . "\n";
1356 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1357 $pdf->Cell(20, 8, $strAttribute, 1, 0, 'L');
1358 $pdf->Cell(15, 8, , 1, 0, 'L');
1359 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1360 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1361 if ($have_rel) {
1362 if (isset($res_rel[$field_name])) {
1363 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1366 if ($cfgRelation['commwork']) {
1367 if (isset($comments[$field_name])) {
1368 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1370 } */
1371 } // end while
1372 $pdf->SetFont('', '', 14);
1373 PMA_DBI_free_result($result);
1374 } //end each
1375 } // end function PMA_RT_DOC
1378 * Main logic
1380 if (!isset($pdf_page_number)) {
1381 $pdf_page_number = 1;
1384 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1385 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1386 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1387 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1388 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1389 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1390 $paper = isset($paper) ? $paper : 'A4';
1391 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1392 PMA_DBI_select_db($db);
1394 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);