patch #3150164 [structure] Ordering by size gives incorrect results
[phpmyadmin-themes.git] / pdf_schema.php
blobce87e97b288a05bdf585c6d1d369a2947803a2b1
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();
514 var $show_info = false;
517 * Returns title of the current table,
518 * title can have the dimensions of the table
520 * @access private
522 function getTitle()
524 return ($this->show_info ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) : '') . ' ' . $this->table_name;
525 } // end of the "getTitle" function
527 * Sets the width of the table
529 * @param integer $ The font size
530 * @global object The current PDF document
531 * @access private
532 * @see PMA_PDF
534 function PMA_RT_Table_setWidth($ff)
536 global $pdf;
538 foreach ($this->fields AS $field) {
539 $this->width = max($this->width, $pdf->GetStringWidth($field));
541 $this->width += $pdf->GetStringWidth(' ');
542 $pdf->SetFont($ff, 'B');
543 // it is unknown what value must be added, because
544 // table title is affected by the tabe width value
545 while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
546 $this->width += 5;
548 $pdf->SetFont($ff, '');
549 } // end of the "PMA_RT_Table_setWidth()" method
551 * Sets the height of the table
553 * @access private
555 function PMA_RT_Table_setHeight()
557 $this->height = (count($this->fields) + 1) * $this->height_cell;
558 } // end of the "PMA_RT_Table_setHeight()" method
560 * Do draw the table
562 * @param integer $ The font size
563 * @param boolean $ Whether to display color
564 * @param integer $ The max. with among tables
565 * @global object The current PDF document
566 * @access private
567 * @see PMA_PDF
569 function PMA_RT_Table_draw($ff, $setcolor = 0)
571 global $pdf, $with_doc;
573 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
574 $pdf->SetFont($ff, 'B');
575 if ($setcolor) {
576 $pdf->SetTextColor(200);
577 $pdf->SetFillColor(0, 0, 128);
579 if ($with_doc) {
580 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
581 } else {
582 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
585 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->getTitle(), 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
586 $pdf->PMA_PDF_setXScale($this->x);
587 $pdf->SetFont($ff, '');
588 $pdf->SetTextColor(0);
589 $pdf->SetFillColor(255);
591 foreach ($this->fields AS $field) {
592 // loic1 : PHP3 fix
593 // if (in_array($field, $this->primary)) {
594 if ($setcolor) {
595 if (in_array($field, $this->primary)) {
596 $pdf->SetFillColor(215, 121, 123);
598 if ($field == $this->displayfield) {
599 $pdf->SetFillColor(142, 159, 224);
602 if ($with_doc) {
603 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
604 } else {
605 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
608 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
609 $pdf->PMA_PDF_setXScale($this->x);
610 $pdf->SetFillColor(255);
611 } // end while
612 /*if ($pdf->PageNo() > 1) {
613 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
614 } */
615 } // end of the "PMA_RT_Table_draw()" method
617 * The "PMA_RT_Table" constructor
619 * @param string $ The table name
620 * @param integer $ The font size
621 * @param integer $ The max. with among tables
622 * @param boolean $ Whether to display keys or not
623 * @param boolean $ Whether to display table position or not
624 * @global object The current PDF document
625 * @global integer The current page number (from the
626 * $cfg['Servers'][$i]['table_coords'] table)
627 * @global array The relations settings
628 * @global string The current db name
629 * @access private
630 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
631 PMA_RT_Table::PMA_RT_Table_setHeight
633 function __construct($table_name, $ff, &$same_wide_width, $show_keys = false, $show_info = false)
635 global $pdf, $pdf_page_number, $cfgRelation, $db;
637 $this->table_name = $table_name;
638 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
639 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
640 if (!$result || !PMA_DBI_num_rows($result)) {
641 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
643 // load fields
644 //check to see if it will load all fields or only the foreign keys
645 if ($show_keys) {
646 $indexes = PMA_Index::getFromTable($this->table_name, $db);
647 $all_columns = array();
648 foreach ($indexes as $index) {
649 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
651 $this->fields = array_keys($all_columns);
652 } else {
653 while ($row = PMA_DBI_fetch_row($result)) {
654 $this->fields[] = $row[0];
658 $this->show_info = $show_info;
660 // height and width
661 $this->PMA_RT_Table_setHeight();
662 // setWidth must me after setHeight, because title
663 // can include table height which changes table width
664 $this->PMA_RT_Table_setWidth($ff);
665 if ($same_wide_width < $this->width) {
666 $same_wide_width = $this->width;
668 // x and y
669 $sql = 'SELECT x, y FROM '
670 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
671 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
672 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
673 . ' AND pdf_page_number = ' . $pdf_page_number;
674 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
676 if (!$result || !PMA_DBI_num_rows($result)) {
677 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
679 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
680 $this->x = (double) $this->x;
681 $this->y = (double) $this->y;
682 // displayfield
683 $this->displayfield = PMA_getDisplayField($db, $table_name);
684 // index
685 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
686 if (PMA_DBI_num_rows($result) > 0) {
687 while ($row = PMA_DBI_fetch_assoc($result)) {
688 if ($row['Key_name'] == 'PRIMARY') {
689 $this->primary[] = $row['Column_name'];
692 } // end if
693 } // end of the "PMA_RT_Table()" method
694 } // end class "PMA_RT_Table"
696 * Draws relation links
698 * @access private
699 * @see PMA_RT
700 * @package phpMyAdmin
702 class PMA_RT_Relation {
704 * Defines private properties
706 var $x_src, $y_src;
707 var $src_dir ;
708 var $dest_dir;
709 var $x_dest, $y_dest;
710 var $w_tick = 5;
713 * Gets arrows coordinates
715 * @param string $ The current table name
716 * @param string $ The relation column name
717 * @return array Arrows coordinates
718 * @access private
720 function PMA_RT_Relation_getXy($table, $column)
722 $pos = array_search($column, $table->fields);
723 // x_left, x_right, y
724 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
725 } // end of the "PMA_RT_Relation_getXy()" method
727 * Do draws relation links
729 * @param boolean $ Whether to use one color per relation or not
730 * @param integer $ The id of the link to draw
731 * @global object The current PDF document
732 * @access private
733 * @see PMA_PDF
735 function PMA_RT_Relation_draw($change_color, $i)
737 global $pdf;
739 if ($change_color) {
740 $d = $i % 6;
741 $j = ($i - $d) / 6;
742 $j = $j % 4;
743 $j++;
744 $case = array(
745 array(1, 0, 0),
746 array(0, 1, 0),
747 array(0, 0, 1),
748 array(1, 1, 0),
749 array(1, 0, 1),
750 array(0, 1, 1)
752 list ($a, $b, $c) = $case[$d];
753 $e = (1 - ($j - 1) / 6);
754 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
755 } else {
756 $pdf->SetDrawColor(0);
757 } // end if... else...
758 $pdf->PMA_PDF_setLineWidthScale(0.2);
759 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
760 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
761 $pdf->PMA_PDF_setLineWidthScale(0.1);
762 $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);
763 // arrow
764 $root2 = 2 * sqrt(2);
765 $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);
766 $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);
768 $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);
769 $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);
770 $pdf->SetDrawColor(0);
771 } // end of the "PMA_RT_Relation_draw()" method
773 * The "PMA_RT_Relation" constructor
775 * @param string $ The master table name
776 * @param string $ The relation field in the master table
777 * @param string $ The foreign table name
778 * @param string $ The relation field in the foreign table
779 * @access private
780 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
782 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
784 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
785 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
786 $src_left = $src_pos[0] - $this->w_tick;
787 $src_right = $src_pos[1] + $this->w_tick;
788 $dest_left = $dest_pos[0] - $this->w_tick;
789 $dest_right = $dest_pos[1] + $this->w_tick;
791 $d1 = abs($src_left - $dest_left);
792 $d2 = abs($src_right - $dest_left);
793 $d3 = abs($src_left - $dest_right);
794 $d4 = abs($src_right - $dest_right);
795 $d = min($d1, $d2, $d3, $d4);
797 if ($d == $d1) {
798 $this->x_src = $src_pos[0];
799 $this->src_dir = -1;
800 $this->x_dest = $dest_pos[0];
801 $this->dest_dir = -1;
802 } elseif ($d == $d2) {
803 $this->x_src = $src_pos[1];
804 $this->src_dir = 1;
805 $this->x_dest = $dest_pos[0];
806 $this->dest_dir = -1;
807 } elseif ($d == $d3) {
808 $this->x_src = $src_pos[0];
809 $this->src_dir = -1;
810 $this->x_dest = $dest_pos[1];
811 $this->dest_dir = 1;
812 } else {
813 $this->x_src = $src_pos[1];
814 $this->src_dir = 1;
815 $this->x_dest = $dest_pos[1];
816 $this->dest_dir = 1;
818 $this->y_src = $src_pos[2];
819 $this->y_dest = $dest_pos[2];
820 } // end of the "PMA_RT_Relation()" method
821 } // end of the "PMA_RT_Relation" class
823 * Draws and send the database schema
825 * @access public
826 * @see PMA_PDF
827 * @package phpMyAdmin
829 class PMA_RT {
831 * Defines private properties
833 var $tables = array();
834 var $relations = array();
835 var $ff = PMA_PDF_FONT;
836 var $x_max = 0;
837 var $y_max = 0;
838 var $scale;
839 var $x_min = 100000;
840 var $y_min = 100000;
841 var $t_marg = 10;
842 var $b_marg = 10;
843 var $l_marg = 10;
844 var $r_marg = 10;
845 var $tablewidth;
846 var $same_wide = 0;
849 * Sets X and Y minimum and maximum for a table cell
851 * @param string $ The table name
852 * @access private
854 function PMA_RT_setMinMax($table)
856 $this->x_max = max($this->x_max, $table->x + $table->width);
857 $this->y_max = max($this->y_max, $table->y + $table->height);
858 $this->x_min = min($this->x_min, $table->x);
859 $this->y_min = min($this->y_min, $table->y);
860 } // end of the "PMA_RT_setMinMax()" method
862 * Defines relation objects
864 * @param string $ The master table name
865 * @param string $ The relation field in the master table
866 * @param string $ The foreign table name
867 * @param string $ The relation field in the foreign table
868 * @param boolean $ Whether to display table position or not
869 * @access private
870 * @see PMA_RT_setMinMax
872 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field, $show_info)
874 if (!isset($this->tables[$master_table])) {
875 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth, false, $show_info);
876 $this->PMA_RT_setMinMax($this->tables[$master_table]);
878 if (!isset($this->tables[$foreign_table])) {
879 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth, false, $show_info);
880 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
882 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
883 } // end of the "PMA_RT_addRelation()" method
885 * Draws the grid
887 * @global object the current PMA_PDF instance
888 * @access private
889 * @see PMA_PDF
891 function PMA_RT_strokeGrid()
893 global $pdf;
895 $pdf->SetMargins(0, 0);
896 $pdf->SetDrawColor(200, 200, 200);
897 // Draws horizontal lines
898 for ($l = 0; $l < 21; $l++) {
899 $pdf->line(0, $l * 10, $pdf->getFh(), $l * 10);
900 // Avoid duplicates
901 if ($l > 0) {
902 $pdf->SetXY(0, $l * 10);
903 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
904 $pdf->Cell(5, 5, ' ' . $label);
905 } // end if
906 } // end for
907 // Draws vertical lines
908 for ($j = 0; $j < 30 ;$j++) {
909 $pdf->line($j * 10, 0, $j * 10, $pdf->getFw());
910 $pdf->SetXY($j * 10, 0);
911 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
912 $pdf->Cell(5, 7, $label);
913 } // end for
914 } // end of the "PMA_RT_strokeGrid()" method
916 * Draws relation arrows
918 * @param boolean $ Whether to use one color per relation or not
919 * @access private
920 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
922 function PMA_RT_drawRelations($change_color)
924 $i = 0;
925 foreach ($this->relations AS $relation) {
926 $relation->PMA_RT_Relation_draw($change_color, $i);
927 $i++;
928 } // end while
929 } // end of the "PMA_RT_drawRelations()" method
931 * Draws tables
933 * @param boolean $ Whether to display table position or not
934 * @access private
935 * @see PMA_RT_Table::PMA_RT_Table_draw()
937 function PMA_RT_drawTables($draw_color = 0)
939 foreach ($this->tables AS $table) {
940 $table->PMA_RT_Table_draw($this->ff, $draw_color);
942 } // end of the "PMA_RT_drawTables()" method
944 * Ouputs the PDF document to a file
946 * @global object The current PDF document
947 * @global string The current database name
948 * @global integer The current page number (from the
949 * $cfg['Servers'][$i]['table_coords'] table)
950 * @access private
951 * @see PMA_PDF
953 function PMA_RT_showRt()
955 global $pdf, $db, $pdf_page_number, $cfgRelation;
957 $pdf->SetFontSize(14);
958 $pdf->SetLineWidth(0.2);
959 $pdf->SetDisplayMode('fullpage');
960 // Get the name of this pdfpage to use as filename (Mike Beck)
961 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
962 . ' WHERE page_nr = ' . $pdf_page_number;
963 $_name_rs = PMA_query_as_controluser($_name_sql);
964 if ($_name_rs) {
965 $_name_row = PMA_DBI_fetch_row($_name_rs);
966 $filename = $_name_row[0] . '.pdf';
968 // i don't know if there is a chance for this to happen, but rather be on the safe side:
969 if (empty($filename)) {
970 $filename = $pdf_page_number . '.pdf';
972 // $pdf->Output($db . '_' . $filename, TRUE);
973 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
974 } // end of the "PMA_RT_showRt()" method
976 * The "PMA_RT" constructor
978 * @param mixed $ The scaling factor
979 * @param integer $ The page number to draw (from the
980 * $cfg['Servers'][$i]['table_coords'] table)
981 * @param boolean $ Whether to display table position or not
982 * @param boolean $ Was originally whether to use one color per
983 * relation or not, now enables/disables color
984 * everywhere, due to some problems printing with color
985 * @param boolean $ Whether to draw grids or not
986 * @param boolean $ Whether all tables should have the same width or not
987 * @param boolean $ Wheter to show all field or only the keys
988 * @global object The current PDF document
989 * @global string The current db name
990 * @global array The relations settings
991 * @access private
992 * @see PMA_PDF
994 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)
996 global $pdf, $db, $cfgRelation, $with_doc;
998 $this->same_wide = $all_tab_same_wide;
999 // Initializes a new document
1000 $pdf = new PMA_PDF('L', 'mm', $paper);
1001 $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
1002 $pdf->setCMargin(0);
1003 $pdf->Open();
1004 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
1005 $pdf->AliasNbPages();
1006 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
1007 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
1008 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
1009 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
1010 $this->ff = PMA_PDF_FONT;
1011 $pdf->SetFont($this->ff, '', 14);
1012 $pdf->SetAutoPageBreak('auto');
1013 // Gets tables on this page
1014 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
1015 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1016 . ' AND pdf_page_number = ' . $which_rel;
1017 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
1018 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1019 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
1020 // die('No tables');
1021 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1022 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1023 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1025 // make doc //
1026 if ($with_doc) {
1027 $pdf->SetAutoPageBreak('auto', 15);
1028 $pdf->setCMargin(1);
1029 PMA_RT_DOC($alltables);
1030 $pdf->SetAutoPageBreak('auto');
1031 $pdf->setCMargin(0);
1034 $pdf->Addpage();
1036 if ($with_doc) {
1037 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1038 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1039 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1040 $this->t_marg = 18;
1041 $this->b_marg = 18;
1044 /* snip */
1046 foreach ($alltables AS $table) {
1047 if (!isset($this->tables[$table])) {
1048 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys, $show_info);
1051 if ($this->same_wide) {
1052 $this->tables[$table]->width = $this->tablewidth;
1054 $this->PMA_RT_setMinMax($this->tables[$table]);
1056 // Defines the scale factor
1057 $this->scale = ceil(
1058 max(
1059 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1060 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1061 * 100) / 100;
1063 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1064 // Builds and save the PDF document
1065 $pdf->PMA_PDF_setLineWidthScale(0.1);
1067 if ($show_grid) {
1068 $pdf->SetFontSize(10);
1069 $this->PMA_RT_strokeGrid();
1071 $pdf->PMA_PDF_setFontSizeScale(14);
1072 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1073 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1074 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1075 // . ' AND master_table IN (' . $intable . ')'
1076 // . ' AND foreign_table IN (' . $intable . ')';
1077 // $result = PMA_query_as_controluser($sql);
1079 // lem9:
1080 // previous logic was checking master tables and foreign tables
1081 // but I think that looping on every table of the pdf page as a master
1082 // and finding its foreigns is OK (then we can support innodb)
1083 $seen_a_relation = false;
1084 foreach ($alltables AS $one_table) {
1085 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1086 if ($exist_rel) {
1087 $seen_a_relation = true;
1088 foreach ($exist_rel AS $master_field => $rel) {
1089 // put the foreign table on the schema only if selected
1090 // by the user
1091 // (do not use array_search() because we would have to
1092 // to do a === FALSE and this is not PHP3 compatible)
1093 if (in_array($rel['foreign_table'], $alltables)) {
1094 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info);
1096 } // end while
1097 } // end if
1098 } // end while
1099 // loic1: also show tables without relations
1100 // $norelations = TRUE;
1101 // if ($result && PMA_DBI_num_rows($result) > 0) {
1102 // $norelations = FALSE;
1103 // while ($row = PMA_DBI_fetch_assoc($result)) {
1104 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1105 // }
1106 // }
1107 // if ($norelations == FALSE) {
1108 if ($seen_a_relation) {
1109 $this->PMA_RT_drawRelations($change_color);
1112 $this->PMA_RT_drawTables($change_color);
1114 $this->PMA_RT_showRt();
1115 } // end of the "PMA_RT()" method
1116 } // end of the "PMA_RT" class
1118 function PMA_RT_DOC($alltables)
1120 global $db, $pdf, $orientation, $paper;
1121 // TOC
1122 $pdf->addpage($GLOBALS['orientation']);
1123 $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C');
1124 $pdf->Ln(15);
1125 $i = 1;
1126 foreach ($alltables AS $table) {
1127 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1128 $pdf->SetX(10);
1129 // $pdf->Ln(1);
1130 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1131 $pdf->SetX(10);
1132 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1133 // $pdf->Ln(1);
1134 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1135 while ($row = PMA_DBI_fetch_assoc($result)) {
1136 $pdf->SetX(20);
1137 $field_name = $row['Field'];
1138 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1139 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1141 $lasttable = $table;
1142 $i++;
1144 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1145 $pdf->SetX(10);
1146 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1147 $pdf->SetX(10);
1148 $pdf->Cell(0, 6, $i + 1 . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1149 $z = 0;
1150 foreach ($alltables AS $table) {
1151 $z++;
1152 $pdf->addpage($GLOBALS['orientation']);
1153 $pdf->Bookmark($table);
1154 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1155 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1156 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1157 $pdf->SetFont('', 'B', 18);
1158 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1159 $pdf->SetFont('', '', 8);
1160 $pdf->ln();
1162 $cfgRelation = PMA_getRelationsParam();
1163 $comments = PMA_getComments($db, $table);
1164 if ($cfgRelation['mimework']) {
1165 $mime_map = PMA_getMIME($db, $table, true);
1169 * Gets table informations
1171 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1172 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1173 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1174 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1175 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1176 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1179 * Gets table keys and retains them
1181 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1182 $primary = '';
1183 $indexes = array();
1184 $lastIndex = '';
1185 $indexes_info = array();
1186 $indexes_data = array();
1187 $pk_array = array(); // will be use to emphasis prim. keys in the table
1188 // view
1189 while ($row = PMA_DBI_fetch_assoc($result)) {
1190 // Backups the list of primary keys
1191 if ($row['Key_name'] == 'PRIMARY') {
1192 $primary .= $row['Column_name'] . ', ';
1193 $pk_array[$row['Column_name']] = 1;
1195 // Retains keys informations
1196 if ($row['Key_name'] != $lastIndex) {
1197 $indexes[] = $row['Key_name'];
1198 $lastIndex = $row['Key_name'];
1200 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1201 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1202 if (isset($row['Cardinality'])) {
1203 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1205 // I don't know what does following column mean....
1206 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1207 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1209 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1210 if (isset($row['Sub_part'])) {
1211 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1213 } // end while
1214 if ($result) {
1215 PMA_DBI_free_result($result);
1219 * Gets fields properties
1221 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1222 $fields_cnt = PMA_DBI_num_rows($result);
1223 // Check if we can use Relations (Mike Beck)
1224 if (!empty($cfgRelation['relation'])) {
1225 // Find which tables are related with the current one and write it in
1226 // an array
1227 $res_rel = PMA_getForeigners($db, $table);
1229 if (count($res_rel) > 0) {
1230 $have_rel = true;
1231 } else {
1232 $have_rel = false;
1234 } else {
1235 $have_rel = false;
1236 } // end if
1238 * Displays the comments of the table if MySQL >= 3.23
1241 $break = false;
1242 if (!empty($show_comment)) {
1243 $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1);
1244 $break = true;
1247 if (!empty($create_time)) {
1248 $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1);
1249 $break = true;
1252 if (!empty($update_time)) {
1253 $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1);
1254 $break = true;
1257 if (!empty($check_time)) {
1258 $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1);
1259 $break = true;
1262 if ($break == true) {
1263 $pdf->Cell(0, 3, '', 0, 1);
1264 $pdf->Ln();
1267 $pdf->SetFont('', 'B');
1268 if (isset($orientation) && $orientation == 'L') {
1269 $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1270 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1271 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1272 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1273 $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1274 $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1275 $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1277 if ($paper == 'A4') {
1278 $comments_width = 67;
1279 } else {
1280 // this is really intended for 'letter'
1282 * @todo find optimal width for all formats
1284 $comments_width = 50;
1286 $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1287 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1288 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1289 } else {
1290 $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1291 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1292 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1293 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1294 $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1295 $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1296 $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1297 $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1298 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1299 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1301 $pdf->SetFont('', '');
1303 while ($row = PMA_DBI_fetch_assoc($result)) {
1304 $type = $row['Type'];
1305 // reformat mysql query output - staybyte - 9. June 2001
1306 // loic1: set or enum types: slashes single quotes inside options
1307 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1308 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1309 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1310 $type_nowrap = '';
1312 $binary = 0;
1313 $unsigned = 0;
1314 $zerofill = 0;
1315 } else {
1316 $type_nowrap = ' nowrap="nowrap"';
1317 $type = preg_replace('@BINARY@i', '', $type);
1318 $type = preg_replace('@ZEROFILL@i', '', $type);
1319 $type = preg_replace('@UNSIGNED@i', '', $type);
1320 if (empty($type)) {
1321 $type = '&nbsp;';
1324 $binary = stristr($row['Type'], 'BINARY');
1325 $unsigned = stristr($row['Type'], 'UNSIGNED');
1326 $zerofill = stristr($row['Type'], 'ZEROFILL');
1328 $strAttribute = ' ';
1329 if ($binary) {
1330 $strAttribute = 'BINARY';
1332 if ($unsigned) {
1333 $strAttribute = 'UNSIGNED';
1335 if ($zerofill) {
1336 $strAttribute = 'UNSIGNED ZEROFILL';
1338 if (!isset($row['Default'])) {
1339 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1340 $row['Default'] = 'NULL';
1343 $field_name = $row['Field'];
1344 // $pdf->Ln();
1345 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1346 $pdf->Bookmark($field_name, 1, -1);
1347 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1348 $pdf_row = array($field_name,
1349 $type,
1350 $strAttribute,
1351 ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1352 ((isset($row['Default'])) ? $row['Default'] : ''),
1353 $row['Extra'],
1354 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1355 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1356 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1358 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1359 if (isset($res_rel[$field_name]['foreign_table']) AND
1360 isset($res_rel[$field_name]['foreign_field']) AND
1361 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1364 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1365 } else {
1366 unset($links[6]);
1368 $pdf->Row($pdf_row, $links);
1370 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1371 //echo ' ' . $field_name . '&nbsp;' . "\n";
1373 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1374 $pdf->Cell(20, 8, $strAttribute, 1, 0, 'L');
1375 $pdf->Cell(15, 8, , 1, 0, 'L');
1376 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1377 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1378 if ($have_rel) {
1379 if (isset($res_rel[$field_name])) {
1380 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1383 if ($cfgRelation['commwork']) {
1384 if (isset($comments[$field_name])) {
1385 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1387 } */
1388 } // end while
1389 $pdf->SetFont('', '', 14);
1390 PMA_DBI_free_result($result);
1391 } //end each
1392 } // end function PMA_RT_DOC
1395 * Main logic
1397 if (!isset($pdf_page_number)) {
1398 $pdf_page_number = 1;
1401 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1402 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1403 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1404 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1405 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1406 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1407 $paper = isset($paper) ? $paper : 'A4';
1408 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1409 PMA_DBI_select_db($db);
1411 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);