bug #2961609 Potential information disclosure at login page
[phpmyadmin/dkf.git] / pdf_schema.php
blob82a07c12f40e0c3ac7ded9e323bfd5c6d6be349d
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 * @package phpMyAdmin
8 */
10 /**
11 * Gets some core scripts
13 require_once './libraries/common.inc.php';
15 /**
16 * Settings for relation stuff
18 require_once './libraries/relation.lib.php';
19 require_once './libraries/transformations.lib.php';
20 require_once './libraries/Index.class.php';
22 $cfgRelation = PMA_getRelationsParam();
24 /**
25 * Now in ./libraries/relation.lib.php we check for all tables
26 * that we need, but if we don't find them we are quiet about it
27 * so people can work without.
28 * This page is absolutely useless if you didn't set up your tables
29 * correctly, so it is a good place to see which tables we can and
30 * complain ;-)
32 if (!$cfgRelation['pdfwork']) {
33 echo '<font color="red">' . $strError . '</font><br />' . "\n";
34 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
35 echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
38 /**
39 * Font used in PDF.
41 * @todo Make this configuratble (at least Sans/Serif).
43 define('PMA_PDF_FONT', 'DejaVuSans');
44 require_once './libraries/tcpdf/tcpdf.php';
46 /**
47 * Extends the "FPDF" class and prepares the work
49 * @access public
50 * @see FPDF
51 * @package phpMyAdmin
53 class PMA_PDF extends TCPDF {
54 /**
55 * Defines private properties
57 var $x_min;
58 var $y_min;
59 var $l_marg = 10;
60 var $t_marg = 10;
61 var $scale;
62 var $PMA_links;
63 var $Outlines = array();
64 var $def_outlines;
65 var $Alias = array();
66 var $widths;
68 public function getFh()
70 return $this->fh;
73 public function getFw()
75 return $this->fw;
78 public function setCMargin($c_margin)
80 $this->cMargin = $c_margin;
83 function SetAlias($name, $value)
85 $this->Alias[$name] = $value ;
88 function _putpages()
90 if (count($this->Alias) > 0) {
91 $nb = $this->page;
92 foreach ($this->Alias AS $alias => $value) {
93 for ($n = 1;$n <= $nb;$n++)
94 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
97 parent::_putpages();
101 * Sets the scaling factor, defines minimum coordinates and margins
103 * @param double $ The scaling factor
104 * @param double $ The minimum X coordinate
105 * @param double $ The minimum Y coordinate
106 * @param double $ The left margin
107 * @param double $ The top margin
108 * @access public
110 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
112 $this->scale = $scale;
113 $this->x_min = $x_min;
114 $this->y_min = $y_min;
115 if ($this->l_marg != -1) {
116 $this->l_marg = $l_marg;
118 if ($this->t_marg != -1) {
119 $this->t_marg = $t_marg;
121 } // end of the "PMA_PDF_setScale" function
123 * Outputs a scaled cell
125 * @param double $ The cell width
126 * @param double $ The cell height
127 * @param string $ The text to output
128 * @param mixed $ Whether to add borders or not
129 * @param integer $ Where to put the cursor once the output is done
130 * @param string $ Align mode
131 * @param integer $ Whether to fill the cell with a color or not
132 * @access public
133 * @see FPDF::Cell()
135 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
137 $h = $h / $this->scale;
138 $w = $w / $this->scale;
139 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
140 } // end of the "PMA_PDF_cellScale" function
142 * Draws a scaled line
144 * @param double $ The horizontal position of the starting point
145 * @param double $ The vertical position of the starting point
146 * @param double $ The horizontal position of the ending point
147 * @param double $ The vertical position of the ending point
148 * @access public
149 * @see FPDF::Line()
151 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
153 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
154 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
155 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
156 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
157 $this->Line($x1, $y1, $x2, $y2);
158 } // end of the "PMA_PDF_lineScale" function
160 * Sets x and y scaled positions
162 * @param double $ The x position
163 * @param double $ The y position
164 * @access public
165 * @see FPDF::SetXY()
167 function PMA_PDF_setXyScale($x, $y)
169 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
170 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
171 $this->SetXY($x, $y);
172 } // end of the "PMA_PDF_setXyScale" function
174 * Sets the X scaled positions
176 * @param double $ The x position
177 * @access public
178 * @see FPDF::SetX()
180 function PMA_PDF_setXScale($x)
182 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
183 $this->SetX($x);
184 } // end of the "PMA_PDF_setXScale" function
186 * Sets the scaled font size
188 * @param double $ The font size (in points)
189 * @access public
190 * @see FPDF::SetFontSize()
192 function PMA_PDF_setFontSizeScale($size)
194 // Set font size in points
195 $size = $size / $this->scale;
196 $this->SetFontSize($size);
197 } // end of the "PMA_PDF_setFontSizeScale" function
199 * Sets the scaled line width
201 * @param double $ The line width
202 * @access public
203 * @see FPDF::SetLineWidth()
205 function PMA_PDF_setLineWidthScale($width)
207 $width = $width / $this->scale;
208 $this->SetLineWidth($width);
209 } // end of the "PMA_PDF_setLineWidthScale" function
211 * Displays an error message
213 * @param string $ the error mesage
214 * @global array the PMA configuration array
215 * @global integer the current server id
216 * @global string the current language
217 * @global string the charset to convert to
218 * @global string the current database name
219 * @global string the current charset
220 * @global string the current text direction
221 * @global string a localized string
222 * @global string an other localized string
223 * @access public
225 function PMA_PDF_die($error_message = '')
227 global $cfg;
228 global $server, $lang, $convcharset, $db;
229 global $charset, $text_dir, $strRunning, $strDatabase;
231 require_once './libraries/header.inc.php';
233 echo '<p><strong>PDF - ' . $GLOBALS['strError'] . '</strong></p>' . "\n";
234 if (!empty($error_message)) {
235 $error_message = htmlspecialchars($error_message);
237 echo '<p>' . "\n";
238 echo ' ' . $error_message . "\n";
239 echo '</p>' . "\n";
241 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
242 . '">' . $GLOBALS['strBack'] . '</a>';
243 echo "\n";
245 require_once './libraries/footer.inc.php';
246 } // end of the "PMA_PDF_die()" function
248 * Aliases the "Error()" function from the FPDF class to the
249 * "PMA_PDF_die()" one
251 * @param string $ the error mesage
252 * @access public
253 * @see PMA_PDF_die
255 function Error($error_message = '')
257 $this->PMA_PDF_die($error_message);
258 } // end of the "Error()" method
259 function Header()
261 // $datefmt
262 // We only show this if we find something in the new pdf_pages table
264 // This function must be named "Header" to work with the FPDF library
265 global $cfgRelation, $db, $pdf_page_number, $with_doc;
266 if ($with_doc) {
267 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
268 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
269 . ' AND page_nr = \'' . $pdf_page_number . '\'';
270 $test_rs = PMA_query_as_controluser($test_query);
271 $pages = @PMA_DBI_fetch_assoc($test_rs);
272 $this->SetFont('', 'B', 14);
273 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
274 $this->SetFont('', '');
275 $this->Ln();
278 function Footer()
280 // This function must be named "Footer" to work with the FPDF library
281 global $with_doc;
282 if ($with_doc) {
283 $this->SetY(-15);
284 $this->SetFont('', '', 14);
285 $this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
286 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
287 $this->SetY(20);
290 function Bookmark($txt, $level = 0, $y = 0)
292 // Add a bookmark
293 $this->Outlines[0][] = $level;
294 $this->Outlines[1][] = $txt;
295 $this->Outlines[2][] = $this->page;
296 if ($y == -1) {
297 $y = $this->GetY();
299 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
302 function _putbookmarks()
304 if (count($this->Outlines) > 0) {
305 // Save object number
306 $memo_n = $this->n;
307 // Take the number of sub elements for an outline
308 $nb_outlines = sizeof($this->Outlines[0]);
309 $first_level = array();
310 $parent = array();
311 $parent[0] = 1;
312 for ($i = 0; $i < $nb_outlines; $i++) {
313 $level = $this->Outlines[0][$i];
314 $kids = 0;
315 $last = -1;
316 $prev = -1;
317 $next = -1;
318 if ($i > 0) {
319 $cursor = $i-1;
320 // Take the previous outline in the same level
321 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
322 $cursor--;
323 if ($this->Outlines[0][$cursor] == $level) {
324 $prev = $cursor;
327 if ($i < $nb_outlines-1) {
328 $cursor = $i + 1;
329 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
330 // Take the immediate kid in level + 1
331 if ($this->Outlines[0][$cursor] == $level + 1) {
332 $kids++;
333 $last = $cursor;
335 $cursor++;
337 $cursor = $i + 1;
338 // Take the next outline in the same level
339 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
340 $cursor++;
341 if ($this->Outlines[0][$cursor] == $level) {
342 $next = $cursor;
345 $this->_newobj();
346 $parent[$level + 1] = $this->n;
347 if ($level == 0) {
348 $first_level[] = $this->n;
350 $this->_out('<<');
351 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
352 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
353 if ($prev != -1) {
354 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
356 if ($next != -1) {
357 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
359 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
360 if ($kids > 0) {
361 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
362 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
363 $this->_out('/Count -' . $kids);
365 $this->_out('>>');
366 $this->_out('endobj');
368 // First page of outlines
369 $this->_newobj();
370 $this->def_outlines = $this->n;
371 $this->_out('<<');
372 $this->_out('/Type');
373 $this->_out('/Outlines');
374 $this->_out('/First ' . $first_level[0] . ' 0 R');
375 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
376 $this->_out('/Count ' . sizeof($first_level));
377 $this->_out('>>');
378 $this->_out('endobj');
382 function _putresources()
384 parent::_putresources();
385 $this->_putbookmarks();
388 function _putcatalog()
390 parent::_putcatalog();
391 if (count($this->Outlines) > 0) {
392 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
393 $this->_out('/PageMode /UseOutlines');
396 function SetWidths($w)
398 // column widths
399 $this->widths = $w;
402 function Row($data, $links)
404 // line height
405 $nb = 0;
406 $data_cnt = count($data);
407 for ($i = 0;$i < $data_cnt;$i++)
408 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
409 $il = $this->FontSize;
410 $h = ($il + 1) * $nb;
411 // page break if necessary
412 $this->CheckPageBreak($h);
413 // draw the cells
414 $data_cnt = count($data);
415 for ($i = 0;$i < $data_cnt;$i++) {
416 $w = $this->widths[$i];
417 // save current position
418 $x = $this->GetX();
419 $y = $this->GetY();
420 // draw the border
421 $this->Rect($x, $y, $w, $h);
422 if (isset($links[$i])) {
423 $this->Link($x, $y, $w, $h, $links[$i]);
425 // print text
426 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
427 // go to right side
428 $this->SetXY($x + $w, $y);
430 // go to line
431 $this->Ln($h);
434 function CheckPageBreak($h)
436 // if height h overflows, manual page break
437 if ($this->GetY() + $h > $this->PageBreakTrigger) {
438 $this->AddPage($this->CurOrientation);
442 function NbLines($w, $txt)
444 // compute number of lines used by a multicell of width w
445 $cw = &$this->CurrentFont['cw'];
446 if ($w == 0) {
447 $w = $this->w - $this->rMargin - $this->x;
449 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
450 $s = str_replace("\r", '', $txt);
451 $nb = strlen($s);
452 if ($nb > 0 and $s[$nb-1] == "\n") {
453 $nb--;
455 $sep = -1;
456 $i = 0;
457 $j = 0;
458 $l = 0;
459 $nl = 1;
460 while ($i < $nb) {
461 $c = $s[$i];
462 if ($c == "\n") {
463 $i++;
464 $sep = -1;
465 $j = $i;
466 $l = 0;
467 $nl++;
468 continue;
470 if ($c == ' ') {
471 $sep = $i;
473 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
474 if ($l > $wmax) {
475 if ($sep == -1) {
476 if ($i == $j) {
477 $i++;
479 } else {
480 $i = $sep + 1;
482 $sep = -1;
483 $j = $i;
484 $l = 0;
485 $nl++;
486 } else {
487 $i++;
490 return $nl;
492 } // end of the "PMA_PDF" class
496 * Draws tables schema
498 * @access private
499 * @see PMA_RT
500 * @package phpMyAdmin
502 class PMA_RT_Table {
504 * Defines private properties
506 var $nb_fiels;
507 var $table_name;
508 var $width = 0;
509 var $height;
510 var $fields = array();
511 var $height_cell = 6;
512 var $x, $y;
513 var $primary = array();
516 * Sets the width of the table
518 * @param integer $ The font size
519 * @global object The current PDF document
520 * @access private
521 * @see PMA_PDF
523 function PMA_RT_Table_setWidth($ff)
525 // this looks buggy to me... does it really work if
526 // there are fields that require wider cells than the name of the table?
527 global $pdf;
529 foreach ($this->fields AS $field) {
530 $this->width = max($this->width, $pdf->GetStringWidth($field));
532 $this->width += $pdf->GetStringWidth(' ');
533 $pdf->SetFont($ff, 'B');
534 $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
535 $pdf->SetFont($ff, '');
536 } // end of the "PMA_RT_Table_setWidth()" method
538 * Sets the height of the table
540 * @access private
542 function PMA_RT_Table_setHeight()
544 $this->height = (count($this->fields) + 1) * $this->height_cell;
545 } // end of the "PMA_RT_Table_setHeight()" method
547 * Do draw the table
549 * @param boolean $ Whether to display table position or not
550 * @param integer $ The font size
551 * @param boolean $ Whether to display color
552 * @param integer $ The max. with among tables
553 * @global object The current PDF document
554 * @access private
555 * @see PMA_PDF
557 function PMA_RT_Table_draw($show_info, $ff, $setcolor = 0)
559 global $pdf, $with_doc;
561 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
562 $pdf->SetFont($ff, 'B');
563 if ($setcolor) {
564 $pdf->SetTextColor(200);
565 $pdf->SetFillColor(0, 0, 128);
567 if ($with_doc) {
568 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
569 } else {
570 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
573 if ($show_info) {
574 $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]['-']);
575 } else {
576 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
578 $pdf->PMA_PDF_setXScale($this->x);
579 $pdf->SetFont($ff, '');
580 $pdf->SetTextColor(0);
581 $pdf->SetFillColor(255);
583 foreach ($this->fields AS $field) {
584 // loic1 : PHP3 fix
585 // if (in_array($field, $this->primary)) {
586 if ($setcolor) {
587 if (in_array($field, $this->primary)) {
588 $pdf->SetFillColor(215, 121, 123);
590 if ($field == $this->displayfield) {
591 $pdf->SetFillColor(142, 159, 224);
594 if ($with_doc) {
595 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
596 } else {
597 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
600 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
601 $pdf->PMA_PDF_setXScale($this->x);
602 $pdf->SetFillColor(255);
603 } // end while
604 /*if ($pdf->PageNo() > 1) {
605 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
606 } */
607 } // end of the "PMA_RT_Table_draw()" method
609 * The "PMA_RT_Table" constructor
611 * @param string $ The table name
612 * @param integer $ The font size
613 * @param integer $ The max. with among tables
614 * @global object The current PDF document
615 * @global integer The current page number (from the
616 * $cfg['Servers'][$i]['table_coords'] table)
617 * @global array The relations settings
618 * @global string The current db name
619 * @access private
620 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
621 PMA_RT_Table::PMA_RT_Table_setHeight
623 function __construct($table_name, $ff, &$same_wide_width, $show_keys)
625 global $pdf, $pdf_page_number, $cfgRelation, $db;
627 $this->table_name = $table_name;
628 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
629 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
630 if (!$result || !PMA_DBI_num_rows($result)) {
631 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
633 // load fields
634 //check to see if it will load all fields or only the foreign keys
635 if ($show_keys) {
636 $indexes = PMA_Index::getFromTable($this->table_name, $db);
637 $all_columns = array();
638 foreach ($indexes as $index) {
639 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
641 $this->fields = array_keys($all_columns);
642 } else {
643 while ($row = PMA_DBI_fetch_row($result)) {
644 $this->fields[] = $row[0];
647 // height and width
648 $this->PMA_RT_Table_setWidth($ff);
649 $this->PMA_RT_Table_setHeight();
650 if ($same_wide_width < $this->width) {
651 $same_wide_width = $this->width;
653 // x and y
654 $sql = 'SELECT x, y FROM '
655 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
656 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
657 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
658 . ' AND pdf_page_number = ' . $pdf_page_number;
659 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
661 if (!$result || !PMA_DBI_num_rows($result)) {
662 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
664 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
665 $this->x = (double) $this->x;
666 $this->y = (double) $this->y;
667 // displayfield
668 $this->displayfield = PMA_getDisplayField($db, $table_name);
669 // index
670 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
671 if (PMA_DBI_num_rows($result) > 0) {
672 while ($row = PMA_DBI_fetch_assoc($result)) {
673 if ($row['Key_name'] == 'PRIMARY') {
674 $this->primary[] = $row['Column_name'];
677 } // end if
678 } // end of the "PMA_RT_Table()" method
679 } // end class "PMA_RT_Table"
681 * Draws relation links
683 * @access private
684 * @see PMA_RT
685 * @package phpMyAdmin
687 class PMA_RT_Relation {
689 * Defines private properties
691 var $x_src, $y_src;
692 var $src_dir ;
693 var $dest_dir;
694 var $x_dest, $y_dest;
695 var $w_tick = 5;
698 * Gets arrows coordinates
700 * @param string $ The current table name
701 * @param string $ The relation column name
702 * @return array Arrows coordinates
703 * @access private
705 function PMA_RT_Relation_getXy($table, $column)
707 $pos = array_search($column, $table->fields);
708 // x_left, x_right, y
709 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
710 } // end of the "PMA_RT_Relation_getXy()" method
712 * Do draws relation links
714 * @param boolean $ Whether to use one color per relation or not
715 * @param integer $ The id of the link to draw
716 * @global object The current PDF document
717 * @access private
718 * @see PMA_PDF
720 function PMA_RT_Relation_draw($change_color, $i)
722 global $pdf;
724 if ($change_color) {
725 $d = $i % 6;
726 $j = ($i - $d) / 6;
727 $j = $j % 4;
728 $j++;
729 $case = array(
730 array(1, 0, 0),
731 array(0, 1, 0),
732 array(0, 0, 1),
733 array(1, 1, 0),
734 array(1, 0, 1),
735 array(0, 1, 1)
737 list ($a, $b, $c) = $case[$d];
738 $e = (1 - ($j - 1) / 6);
739 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
740 } else {
741 $pdf->SetDrawColor(0);
742 } // end if... else...
743 $pdf->PMA_PDF_setLineWidthScale(0.2);
744 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
745 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
746 $pdf->PMA_PDF_setLineWidthScale(0.1);
747 $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);
748 // arrow
749 $root2 = 2 * sqrt(2);
750 $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);
751 $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);
753 $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);
754 $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);
755 $pdf->SetDrawColor(0);
756 } // end of the "PMA_RT_Relation_draw()" method
758 * The "PMA_RT_Relation" constructor
760 * @param string $ The master table name
761 * @param string $ The relation field in the master table
762 * @param string $ The foreign table name
763 * @param string $ The relation field in the foreign table
764 * @access private
765 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
767 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
769 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
770 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
771 $src_left = $src_pos[0] - $this->w_tick;
772 $src_right = $src_pos[1] + $this->w_tick;
773 $dest_left = $dest_pos[0] - $this->w_tick;
774 $dest_right = $dest_pos[1] + $this->w_tick;
776 $d1 = abs($src_left - $dest_left);
777 $d2 = abs($src_right - $dest_left);
778 $d3 = abs($src_left - $dest_right);
779 $d4 = abs($src_right - $dest_right);
780 $d = min($d1, $d2, $d3, $d4);
782 if ($d == $d1) {
783 $this->x_src = $src_pos[0];
784 $this->src_dir = -1;
785 $this->x_dest = $dest_pos[0];
786 $this->dest_dir = -1;
787 } elseif ($d == $d2) {
788 $this->x_src = $src_pos[1];
789 $this->src_dir = 1;
790 $this->x_dest = $dest_pos[0];
791 $this->dest_dir = -1;
792 } elseif ($d == $d3) {
793 $this->x_src = $src_pos[0];
794 $this->src_dir = -1;
795 $this->x_dest = $dest_pos[1];
796 $this->dest_dir = 1;
797 } else {
798 $this->x_src = $src_pos[1];
799 $this->src_dir = 1;
800 $this->x_dest = $dest_pos[1];
801 $this->dest_dir = 1;
803 $this->y_src = $src_pos[2];
804 $this->y_dest = $dest_pos[2];
805 } // end of the "PMA_RT_Relation()" method
806 } // end of the "PMA_RT_Relation" class
808 * Draws and send the database schema
810 * @access public
811 * @see PMA_PDF
812 * @package phpMyAdmin
814 class PMA_RT {
816 * Defines private properties
818 var $tables = array();
819 var $relations = array();
820 var $ff = PMA_PDF_FONT;
821 var $x_max = 0;
822 var $y_max = 0;
823 var $scale;
824 var $x_min = 100000;
825 var $y_min = 100000;
826 var $t_marg = 10;
827 var $b_marg = 10;
828 var $l_marg = 10;
829 var $r_marg = 10;
830 var $tablewidth;
831 var $same_wide = 0;
834 * Sets X and Y minimum and maximum for a table cell
836 * @param string $ The table name
837 * @access private
839 function PMA_RT_setMinMax($table)
841 $this->x_max = max($this->x_max, $table->x + $table->width);
842 $this->y_max = max($this->y_max, $table->y + $table->height);
843 $this->x_min = min($this->x_min, $table->x);
844 $this->y_min = min($this->y_min, $table->y);
845 } // end of the "PMA_RT_setMinMax()" method
847 * Defines relation objects
849 * @param string $ The master table name
850 * @param string $ The relation field in the master table
851 * @param string $ The foreign table name
852 * @param string $ The relation field in the foreign table
853 * @access private
854 * @see PMA_RT_setMinMax
856 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field)
858 if (!isset($this->tables[$master_table])) {
859 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth);
860 $this->PMA_RT_setMinMax($this->tables[$master_table]);
862 if (!isset($this->tables[$foreign_table])) {
863 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth);
864 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
866 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
867 } // end of the "PMA_RT_addRelation()" method
869 * Draws the grid
871 * @global object the current PMA_PDF instance
872 * @access private
873 * @see PMA_PDF
875 function PMA_RT_strokeGrid()
877 global $pdf;
879 $pdf->SetMargins(0, 0);
880 $pdf->SetDrawColor(200, 200, 200);
881 // Draws horizontal lines
882 for ($l = 0; $l < 21; $l++) {
883 $pdf->line(0, $l * 10, $pdf->fh, $l * 10);
884 // Avoid duplicates
885 if ($l > 0) {
886 $pdf->SetXY(0, $l * 10);
887 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
888 $pdf->Cell(5, 5, ' ' . $label);
889 } // end if
890 } // end for
891 // Draws vertical lines
892 for ($j = 0; $j < 30 ;$j++) {
893 $pdf->line($j * 10, 0, $j * 10, $pdf->fw);
894 $pdf->SetXY($j * 10, 0);
895 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
896 $pdf->Cell(5, 7, $label);
897 } // end for
898 } // end of the "PMA_RT_strokeGrid()" method
900 * Draws relation arrows
902 * @param boolean $ Whether to use one color per relation or not
903 * @access private
904 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
906 function PMA_RT_drawRelations($change_color)
908 $i = 0;
909 foreach ($this->relations AS $relation) {
910 $relation->PMA_RT_Relation_draw($change_color, $i);
911 $i++;
912 } // end while
913 } // end of the "PMA_RT_drawRelations()" method
915 * Draws tables
917 * @param boolean $ Whether to display table position or not
918 * @access private
919 * @see PMA_RT_Table::PMA_RT_Table_draw()
921 function PMA_RT_drawTables($show_info, $draw_color = 0)
923 foreach ($this->tables AS $table) {
924 $table->PMA_RT_Table_draw($show_info, $this->ff, $draw_color);
926 } // end of the "PMA_RT_drawTables()" method
928 * Ouputs the PDF document to a file
930 * @global object The current PDF document
931 * @global string The current database name
932 * @global integer The current page number (from the
933 * $cfg['Servers'][$i]['table_coords'] table)
934 * @access private
935 * @see PMA_PDF
937 function PMA_RT_showRt()
939 global $pdf, $db, $pdf_page_number, $cfgRelation;
941 $pdf->SetFontSize(14);
942 $pdf->SetLineWidth(0.2);
943 $pdf->SetDisplayMode('fullpage');
944 // Get the name of this pdfpage to use as filename (Mike Beck)
945 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
946 . ' WHERE page_nr = ' . $pdf_page_number;
947 $_name_rs = PMA_query_as_controluser($_name_sql);
948 if ($_name_rs) {
949 $_name_row = PMA_DBI_fetch_row($_name_rs);
950 $filename = $_name_row[0] . '.pdf';
952 // i don't know if there is a chance for this to happen, but rather be on the safe side:
953 if (empty($filename)) {
954 $filename = $pdf_page_number . '.pdf';
956 // $pdf->Output($db . '_' . $filename, TRUE);
957 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
958 } // end of the "PMA_RT_showRt()" method
960 * The "PMA_RT" constructor
962 * @param mixed $ The scaling factor
963 * @param integer $ The page number to draw (from the
964 * $cfg['Servers'][$i]['table_coords'] table)
965 * @param boolean $ Whether to display table position or not
966 * @param boolean $ Was originally whether to use one color per
967 * relation or not, now enables/disables color
968 * everywhere, due to some problems printing with color
969 * @param boolean $ Whether to draw grids or not
970 * @param boolean $ Whether all tables should have the same width or not
971 * @param boolean $ Wheter to show all field or only the keys
972 * @global object The current PDF document
973 * @global string The current db name
974 * @global array The relations settings
975 * @access private
976 * @see PMA_PDF
978 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)
980 global $pdf, $db, $cfgRelation, $with_doc;
982 $this->same_wide = $all_tab_same_wide;
983 // Initializes a new document
984 $pdf = new PMA_PDF('L', 'mm', $paper);
985 $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
986 $pdf->setCMargin(0);
987 $pdf->Open();
988 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
989 $pdf->AliasNbPages();
990 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
991 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
992 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
993 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
994 $this->ff = PMA_PDF_FONT;
995 $pdf->SetFont($this->ff, '', 14);
996 $pdf->SetAutoPageBreak('auto');
997 // Gets tables on this page
998 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
999 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1000 . ' AND pdf_page_number = ' . $which_rel;
1001 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
1002 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1003 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
1004 // die('No tables');
1005 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1006 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1007 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1009 // make doc //
1010 if ($with_doc) {
1011 $pdf->SetAutoPageBreak('auto', 15);
1012 $pdf->setCMargin(1);
1013 PMA_RT_DOC($alltables);
1014 $pdf->SetAutoPageBreak('auto');
1015 $pdf->setCMargin(0);
1018 $pdf->Addpage();
1020 if ($with_doc) {
1021 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1022 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1023 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1024 $this->t_marg = 18;
1025 $this->b_marg = 18;
1028 /* snip */
1030 foreach ($alltables AS $table) {
1031 if (!isset($this->tables[$table])) {
1032 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys);
1035 if ($this->same_wide) {
1036 $this->tables[$table]->width = $this->tablewidth;
1038 $this->PMA_RT_setMinMax($this->tables[$table]);
1040 // Defines the scale factor
1041 $this->scale = ceil(
1042 max(
1043 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1044 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1045 * 100) / 100;
1047 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1048 // Builds and save the PDF document
1049 $pdf->PMA_PDF_setLineWidthScale(0.1);
1051 if ($show_grid) {
1052 $pdf->SetFontSize(10);
1053 $this->PMA_RT_strokeGrid();
1055 $pdf->PMA_PDF_setFontSizeScale(14);
1056 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1057 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1058 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1059 // . ' AND master_table IN (' . $intable . ')'
1060 // . ' AND foreign_table IN (' . $intable . ')';
1061 // $result = PMA_query_as_controluser($sql);
1063 // lem9:
1064 // previous logic was checking master tables and foreign tables
1065 // but I think that looping on every table of the pdf page as a master
1066 // and finding its foreigns is OK (then we can support innodb)
1067 $seen_a_relation = false;
1068 foreach ($alltables AS $one_table) {
1069 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1070 if ($exist_rel) {
1071 $seen_a_relation = true;
1072 foreach ($exist_rel AS $master_field => $rel) {
1073 // put the foreign table on the schema only if selected
1074 // by the user
1075 // (do not use array_search() because we would have to
1076 // to do a === FALSE and this is not PHP3 compatible)
1077 if (in_array($rel['foreign_table'], $alltables)) {
1078 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
1080 } // end while
1081 } // end if
1082 } // end while
1083 // loic1: also show tables without relations
1084 // $norelations = TRUE;
1085 // if ($result && PMA_DBI_num_rows($result) > 0) {
1086 // $norelations = FALSE;
1087 // while ($row = PMA_DBI_fetch_assoc($result)) {
1088 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1089 // }
1090 // }
1091 // if ($norelations == FALSE) {
1092 if ($seen_a_relation) {
1093 $this->PMA_RT_drawRelations($change_color);
1096 $this->PMA_RT_drawTables($show_info, $change_color);
1098 $this->PMA_RT_showRt();
1099 } // end of the "PMA_RT()" method
1100 } // end of the "PMA_RT" class
1102 function PMA_RT_DOC($alltables)
1104 global $db, $pdf, $orientation, $paper;
1105 // TOC
1106 $pdf->addpage($GLOBALS['orientation']);
1107 $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C');
1108 $pdf->Ln(15);
1109 $i = 1;
1110 foreach ($alltables AS $table) {
1111 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1112 $pdf->SetX(10);
1113 // $pdf->Ln(1);
1114 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1115 $pdf->SetX(10);
1116 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1117 // $pdf->Ln(1);
1118 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1119 while ($row = PMA_DBI_fetch_assoc($result)) {
1120 $pdf->SetX(20);
1121 $field_name = $row['Field'];
1122 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1123 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1125 $lasttable = $table;
1126 $i++;
1128 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1129 $pdf->SetX(10);
1130 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1131 $pdf->SetX(10);
1132 $pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1133 $z = 0;
1134 foreach ($alltables AS $table) {
1135 $z++;
1136 $pdf->addpage($GLOBALS['orientation']);
1137 $pdf->Bookmark($table);
1138 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1139 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1140 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1141 $pdf->SetFont('', 'B', 18);
1142 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1143 $pdf->SetFont('', '', 8);
1144 $pdf->ln();
1146 $cfgRelation = PMA_getRelationsParam();
1147 $comments = PMA_getComments($db, $table);
1148 if ($cfgRelation['mimework']) {
1149 $mime_map = PMA_getMIME($db, $table, true);
1153 * Gets table informations
1155 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1156 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1157 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1158 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1159 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1160 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1163 * Gets table keys and retains them
1165 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1166 $primary = '';
1167 $indexes = array();
1168 $lastIndex = '';
1169 $indexes_info = array();
1170 $indexes_data = array();
1171 $pk_array = array(); // will be use to emphasis prim. keys in the table
1172 // view
1173 while ($row = PMA_DBI_fetch_assoc($result)) {
1174 // Backups the list of primary keys
1175 if ($row['Key_name'] == 'PRIMARY') {
1176 $primary .= $row['Column_name'] . ', ';
1177 $pk_array[$row['Column_name']] = 1;
1179 // Retains keys informations
1180 if ($row['Key_name'] != $lastIndex) {
1181 $indexes[] = $row['Key_name'];
1182 $lastIndex = $row['Key_name'];
1184 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1185 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1186 if (isset($row['Cardinality'])) {
1187 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1189 // I don't know what does following column mean....
1190 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1191 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1193 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1194 if (isset($row['Sub_part'])) {
1195 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1197 } // end while
1198 if ($result) {
1199 PMA_DBI_free_result($result);
1203 * Gets fields properties
1205 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1206 $fields_cnt = PMA_DBI_num_rows($result);
1207 // Check if we can use Relations (Mike Beck)
1208 if (!empty($cfgRelation['relation'])) {
1209 // Find which tables are related with the current one and write it in
1210 // an array
1211 $res_rel = PMA_getForeigners($db, $table);
1213 if (count($res_rel) > 0) {
1214 $have_rel = true;
1215 } else {
1216 $have_rel = false;
1218 } else {
1219 $have_rel = false;
1220 } // end if
1222 * Displays the comments of the table if MySQL >= 3.23
1225 $break = false;
1226 if (!empty($show_comment)) {
1227 $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1);
1228 $break = true;
1231 if (!empty($create_time)) {
1232 $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1);
1233 $break = true;
1236 if (!empty($update_time)) {
1237 $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1);
1238 $break = true;
1241 if (!empty($check_time)) {
1242 $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1);
1243 $break = true;
1246 if ($break == true) {
1247 $pdf->Cell(0, 3, '', 0, 1);
1248 $pdf->Ln();
1251 $pdf->SetFont('', 'B');
1252 if (isset($orientation) && $orientation == 'L') {
1253 $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1254 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1255 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1256 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1257 $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1258 $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1259 $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1261 if ($paper == 'A4') {
1262 $comments_width = 67;
1263 } else {
1264 // this is really intended for 'letter'
1266 * @todo find optimal width for all formats
1268 $comments_width = 50;
1270 $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1271 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1272 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1273 } else {
1274 $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1275 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1276 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1277 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1278 $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1279 $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1280 $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1281 $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1282 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1283 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1285 $pdf->SetFont('', '');
1287 while ($row = PMA_DBI_fetch_assoc($result)) {
1288 $type = $row['Type'];
1289 // reformat mysql query output - staybyte - 9. June 2001
1290 // loic1: set or enum types: slashes single quotes inside options
1291 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1292 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1293 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1294 $type_nowrap = '';
1296 $binary = 0;
1297 $unsigned = 0;
1298 $zerofill = 0;
1299 } else {
1300 $type_nowrap = ' nowrap="nowrap"';
1301 $type = preg_replace('@BINARY@i', '', $type);
1302 $type = preg_replace('@ZEROFILL@i', '', $type);
1303 $type = preg_replace('@UNSIGNED@i', '', $type);
1304 if (empty($type)) {
1305 $type = '&nbsp;';
1308 $binary = stristr($row['Type'], 'BINARY');
1309 $unsigned = stristr($row['Type'], 'UNSIGNED');
1310 $zerofill = stristr($row['Type'], 'ZEROFILL');
1312 $strAttribute = ' ';
1313 if ($binary) {
1314 $strAttribute = 'BINARY';
1316 if ($unsigned) {
1317 $strAttribute = 'UNSIGNED';
1319 if ($zerofill) {
1320 $strAttribute = 'UNSIGNED ZEROFILL';
1322 if (!isset($row['Default'])) {
1323 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1324 $row['Default'] = 'NULL';
1327 $field_name = $row['Field'];
1328 // $pdf->Ln();
1329 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1330 $pdf->Bookmark($field_name, 1, -1);
1331 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1332 $pdf_row = array($field_name,
1333 $type,
1334 $strAttribute,
1335 ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1336 ((isset($row['Default'])) ? $row['Default'] : ''),
1337 $row['Extra'],
1338 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1339 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1340 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1342 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1343 if (isset($res_rel[$field_name]['foreign_table']) AND
1344 isset($res_rel[$field_name]['foreign_field']) AND
1345 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1348 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1349 } else {
1350 unset($links[6]);
1352 $pdf->Row($pdf_row, $links);
1354 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1355 //echo ' ' . $field_name . '&nbsp;' . "\n";
1357 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1358 $pdf->Cell(20, 8, $strAttribute, 1, 0, 'L');
1359 $pdf->Cell(15, 8, , 1, 0, 'L');
1360 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1361 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1362 if ($have_rel) {
1363 if (isset($res_rel[$field_name])) {
1364 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1367 if ($cfgRelation['commwork']) {
1368 if (isset($comments[$field_name])) {
1369 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1371 } */
1372 } // end while
1373 $pdf->SetFont('', '', 14);
1374 PMA_DBI_free_result($result);
1375 } //end each
1376 } // end function PMA_RT_DOC
1379 * Main logic
1381 if (!isset($pdf_page_number)) {
1382 $pdf_page_number = 1;
1385 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1386 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1387 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1388 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1389 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1390 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1391 $paper = isset($paper) ? $paper : 'A4';
1392 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1393 PMA_DBI_select_db($db);
1395 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);