patch #3038312 [export] JSON export
[phpmyadmin.git] / pdf_schema.php
blobdd7426f1be285581abcaf21ac76f41870dd0bdca
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 /**
9 * Gets some core scripts
11 require_once './libraries/common.inc.php';
13 /**
14 * Settings for relation stuff
16 require_once './libraries/transformations.lib.php';
17 require_once './libraries/Index.class.php';
19 $cfgRelation = PMA_getRelationsParam();
21 /**
22 * Now in ./libraries/relation.lib.php we check for all tables
23 * that we need, but if we don't find them we are quiet about it
24 * so people can work without.
25 * This page is absolutely useless if you didn't set up your tables
26 * correctly, so it is a good place to see which tables we can and
27 * complain ;-)
29 if (!$cfgRelation['pdfwork']) {
30 echo '<font color="red">' . __('Error') . '</font><br />' . "\n";
31 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
32 echo sprintf(__('The phpMyAdmin configuration storage has been deactivated. To find out why click %shere%s.'), $url_to_goto, '</a>') . "\n";
35 /**
36 * Font used in PDF.
38 * @todo Make this configuratble (at least Sans/Serif).
40 define('PMA_PDF_FONT', 'DejaVuSans');
41 require_once './libraries/tcpdf/tcpdf.php';
43 /**
44 * Extends the "FPDF" class and prepares the work
46 * @access public
47 * @see FPDF
48 * @package phpMyAdmin
50 class PMA_PDF extends TCPDF {
51 /**
52 * Defines private properties
54 var $x_min;
55 var $y_min;
56 var $l_marg = 10;
57 var $t_marg = 10;
58 var $scale;
59 var $PMA_links;
60 var $Outlines = array();
61 var $def_outlines;
62 var $Alias = array();
63 var $widths;
65 public function getFh()
67 return $this->fh;
70 public function getFw()
72 return $this->fw;
75 public function setCMargin($c_margin)
77 $this->cMargin = $c_margin;
80 function SetAlias($name, $value)
82 $this->Alias[$name] = $value ;
85 function _putpages()
87 if (count($this->Alias) > 0) {
88 $nb = $this->page;
89 foreach ($this->Alias AS $alias => $value) {
90 for ($n = 1;$n <= $nb;$n++)
91 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
94 parent::_putpages();
97 /**
98 * Sets the scaling factor, defines minimum coordinates and margins
100 * @param float scale The scaling factor
101 * @param float x_min The minimum X coordinate
102 * @param float y_min The minimum Y coordinate
103 * @param float l_marg The left margin
104 * @param float t_marg The top margin
105 * @access public
107 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
109 $this->scale = $scale;
110 $this->x_min = $x_min;
111 $this->y_min = $y_min;
112 if ($this->l_marg != -1) {
113 $this->l_marg = $l_marg;
115 if ($this->t_marg != -1) {
116 $this->t_marg = $t_marg;
118 } // end of the "PMA_PDF_setScale" function
120 * Outputs a scaled cell
122 * @param float w The cell width
123 * @param float h The cell height
124 * @param string txt The text to output
125 * @param mixed border Whether to add borders or not
126 * @param integer ln Where to put the cursor once the output is done
127 * @param string align Align mode
128 * @param integer fill Whether to fill the cell with a color or not
129 * @access public
130 * @see FPDF::Cell()
132 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
134 $h = $h / $this->scale;
135 $w = $w / $this->scale;
136 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
137 } // end of the "PMA_PDF_cellScale" function
139 * Draws a scaled line
141 * @param float x1 The horizontal position of the starting point
142 * @param float y1 The vertical position of the starting point
143 * @param float x2 The horizontal position of the ending point
144 * @param float y2 The vertical position of the ending point
145 * @access public
146 * @see FPDF::Line()
148 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
150 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
151 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
152 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
153 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
154 $this->Line($x1, $y1, $x2, $y2);
155 } // end of the "PMA_PDF_lineScale" function
157 * Sets x and y scaled positions
159 * @param float x The x position
160 * @param float y The y position
161 * @access public
162 * @see FPDF::SetXY()
164 function PMA_PDF_setXyScale($x, $y)
166 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
167 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
168 $this->SetXY($x, $y);
169 } // end of the "PMA_PDF_setXyScale" function
171 * Sets the X scaled positions
173 * @param float x The x position
174 * @access public
175 * @see FPDF::SetX()
177 function PMA_PDF_setXScale($x)
179 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
180 $this->SetX($x);
181 } // end of the "PMA_PDF_setXScale" function
183 * Sets the scaled font size
185 * @param float size The font size (in points)
186 * @access public
187 * @see FPDF::SetFontSize()
189 function PMA_PDF_setFontSizeScale($size)
191 // Set font size in points
192 $size = $size / $this->scale;
193 $this->SetFontSize($size);
194 } // end of the "PMA_PDF_setFontSizeScale" function
196 * Sets the scaled line width
198 * @param float width The line width
199 * @access public
200 * @see FPDF::SetLineWidth()
202 function PMA_PDF_setLineWidthScale($width)
204 $width = $width / $this->scale;
205 $this->SetLineWidth($width);
206 } // end of the "PMA_PDF_setLineWidthScale" function
208 * Displays an error message
210 * @param string error_message the error mesage
211 * @global array the PMA configuration array
212 * @global integer the current server id
213 * @global string the current language
214 * @global string the charset to convert to
215 * @global string the current database name
216 * @global string the current charset
217 * @global string the current text direction
218 * @global string a localized string
219 * @global string an other localized string
220 * @access public
222 function PMA_PDF_die($error_message = '')
224 global $cfg;
225 global $server, $lang, $db;
226 global $charset, $text_dir;
228 require_once './libraries/header.inc.php';
230 echo '<p><strong>PDF - ' . __('Error') . '</strong></p>' . "\n";
231 if (!empty($error_message)) {
232 $error_message = htmlspecialchars($error_message);
234 echo '<p>' . "\n";
235 echo ' ' . $error_message . "\n";
236 echo '</p>' . "\n";
238 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
239 . '">' . __('Back') . '</a>';
240 echo "\n";
242 require './libraries/footer.inc.php';
243 } // end of the "PMA_PDF_die()" function
245 * Aliases the "Error()" function from the FPDF class to the
246 * "PMA_PDF_die()" one
248 * @param string error_message the error mesage
249 * @access public
250 * @see PMA_PDF_die
252 function Error($error_message = '')
254 $this->PMA_PDF_die($error_message);
255 } // end of the "Error()" method
256 function Header()
258 // We only show this if we find something in the new pdf_pages table
260 // This function must be named "Header" to work with the FPDF library
261 global $cfgRelation, $db, $pdf_page_number, $with_doc;
262 if ($with_doc) {
263 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
264 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
265 . ' AND page_nr = \'' . $pdf_page_number . '\'';
266 $test_rs = PMA_query_as_controluser($test_query);
267 $pages = @PMA_DBI_fetch_assoc($test_rs);
268 $this->SetFont('', 'B', 14);
269 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
270 $this->SetFont('', '');
271 $this->Ln();
274 function Footer()
276 // This function must be named "Footer" to work with the FPDF library
277 global $with_doc;
278 if ($with_doc) {
279 $this->SetY(-15);
280 $this->SetFont('', '', 14);
281 $this->Cell(0, 6, __('Page number:') . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
282 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
283 $this->SetY(20);
286 function Bookmark($txt, $level = 0, $y = 0)
288 // Add a bookmark
289 $this->Outlines[0][] = $level;
290 $this->Outlines[1][] = $txt;
291 $this->Outlines[2][] = $this->page;
292 if ($y == -1) {
293 $y = $this->GetY();
295 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
298 function _putbookmarks()
300 if (count($this->Outlines) > 0) {
301 // Save object number
302 $memo_n = $this->n;
303 // Take the number of sub elements for an outline
304 $nb_outlines = sizeof($this->Outlines[0]);
305 $first_level = array();
306 $parent = array();
307 $parent[0] = 1;
308 for ($i = 0; $i < $nb_outlines; $i++) {
309 $level = $this->Outlines[0][$i];
310 $kids = 0;
311 $last = -1;
312 $prev = -1;
313 $next = -1;
314 if ($i > 0) {
315 $cursor = $i-1;
316 // Take the previous outline in the same level
317 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
318 $cursor--;
319 if ($this->Outlines[0][$cursor] == $level) {
320 $prev = $cursor;
323 if ($i < $nb_outlines-1) {
324 $cursor = $i + 1;
325 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
326 // Take the immediate kid in level + 1
327 if ($this->Outlines[0][$cursor] == $level + 1) {
328 $kids++;
329 $last = $cursor;
331 $cursor++;
333 $cursor = $i + 1;
334 // Take the next outline in the same level
335 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
336 $cursor++;
337 if ($this->Outlines[0][$cursor] == $level) {
338 $next = $cursor;
341 $this->_newobj();
342 $parent[$level + 1] = $this->n;
343 if ($level == 0) {
344 $first_level[] = $this->n;
346 $this->_out('<<');
347 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
348 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
349 if ($prev != -1) {
350 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
352 if ($next != -1) {
353 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
355 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
356 if ($kids > 0) {
357 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
358 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
359 $this->_out('/Count -' . $kids);
361 $this->_out('>>');
362 $this->_out('endobj');
364 // First page of outlines
365 $this->_newobj();
366 $this->def_outlines = $this->n;
367 $this->_out('<<');
368 $this->_out('/Type');
369 $this->_out('/Outlines');
370 $this->_out('/First ' . $first_level[0] . ' 0 R');
371 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
372 $this->_out('/Count ' . sizeof($first_level));
373 $this->_out('>>');
374 $this->_out('endobj');
378 function _putresources()
380 parent::_putresources();
381 $this->_putbookmarks();
384 function _putcatalog()
386 parent::_putcatalog();
387 if (count($this->Outlines) > 0) {
388 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
389 $this->_out('/PageMode /UseOutlines');
392 function SetWidths($w)
394 // column widths
395 $this->widths = $w;
398 function Row($data, $links)
400 // line height
401 $nb = 0;
402 $data_cnt = count($data);
403 for ($i = 0;$i < $data_cnt;$i++)
404 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
405 $il = $this->FontSize;
406 $h = ($il + 1) * $nb;
407 // page break if necessary
408 $this->CheckPageBreak($h);
409 // draw the cells
410 $data_cnt = count($data);
411 for ($i = 0;$i < $data_cnt;$i++) {
412 $w = $this->widths[$i];
413 // save current position
414 $x = $this->GetX();
415 $y = $this->GetY();
416 // draw the border
417 $this->Rect($x, $y, $w, $h);
418 if (isset($links[$i])) {
419 $this->Link($x, $y, $w, $h, $links[$i]);
421 // print text
422 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
423 // go to right side
424 $this->SetXY($x + $w, $y);
426 // go to line
427 $this->Ln($h);
430 function CheckPageBreak($h)
432 // if height h overflows, manual page break
433 if ($this->GetY() + $h > $this->PageBreakTrigger) {
434 $this->AddPage($this->CurOrientation);
438 function NbLines($w, $txt)
440 // compute number of lines used by a multicell of width w
441 $cw = &$this->CurrentFont['cw'];
442 if ($w == 0) {
443 $w = $this->w - $this->rMargin - $this->x;
445 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
446 $s = str_replace("\r", '', $txt);
447 $nb = strlen($s);
448 if ($nb > 0 and $s[$nb-1] == "\n") {
449 $nb--;
451 $sep = -1;
452 $i = 0;
453 $j = 0;
454 $l = 0;
455 $nl = 1;
456 while ($i < $nb) {
457 $c = $s[$i];
458 if ($c == "\n") {
459 $i++;
460 $sep = -1;
461 $j = $i;
462 $l = 0;
463 $nl++;
464 continue;
466 if ($c == ' ') {
467 $sep = $i;
469 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
470 if ($l > $wmax) {
471 if ($sep == -1) {
472 if ($i == $j) {
473 $i++;
475 } else {
476 $i = $sep + 1;
478 $sep = -1;
479 $j = $i;
480 $l = 0;
481 $nl++;
482 } else {
483 $i++;
486 return $nl;
488 } // end of the "PMA_PDF" class
492 * Draws tables schema
494 * @access private
495 * @see PMA_RT
496 * @package phpMyAdmin
498 class PMA_RT_Table {
500 * Defines private properties
502 var $nb_fiels;
503 var $table_name;
504 var $width = 0;
505 var $height;
506 var $fields = array();
507 var $height_cell = 6;
508 var $x, $y;
509 var $primary = array();
510 var $show_info = false;
513 * Returns title of the current table,
514 * title can have the dimensions of the table
516 * @access private
518 function getTitle()
520 return ($this->show_info ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) : '') . ' ' . $this->table_name;
521 } // end of the "getTitle" function
523 * Sets the width of the table
525 * @param integer ff The font size
526 * @global object The current PDF document
527 * @access private
528 * @see PMA_PDF
530 function PMA_RT_Table_setWidth($ff)
532 global $pdf;
534 foreach ($this->fields AS $field) {
535 $this->width = max($this->width, $pdf->GetStringWidth($field));
537 $this->width += $pdf->GetStringWidth(' ');
538 $pdf->SetFont($ff, 'B');
539 // it is unknown what value must be added, because
540 // table title is affected by the tabe width value
541 while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
542 $this->width += 5;
544 $pdf->SetFont($ff, '');
545 } // end of the "PMA_RT_Table_setWidth()" method
547 * Sets the height of the table
549 * @access private
551 function PMA_RT_Table_setHeight()
553 $this->height = (count($this->fields) + 1) * $this->height_cell;
554 } // end of the "PMA_RT_Table_setHeight()" method
556 * Do draw the table
558 * @param integer ff The font size
559 * @param boolean setcolortWhether to display color
560 * @global object The current PDF document
561 * @access private
562 * @see PMA_PDF
564 function PMA_RT_Table_draw($ff, $setcolor = 0)
566 global $pdf, $with_doc;
568 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
569 $pdf->SetFont($ff, 'B');
570 if ($setcolor) {
571 $pdf->SetTextColor(200);
572 $pdf->SetFillColor(0, 0, 128);
574 if ($with_doc) {
575 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
576 } else {
577 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
580 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->getTitle(), 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
581 $pdf->PMA_PDF_setXScale($this->x);
582 $pdf->SetFont($ff, '');
583 $pdf->SetTextColor(0);
584 $pdf->SetFillColor(255);
586 foreach ($this->fields AS $field) {
587 if ($setcolor) {
588 if (in_array($field, $this->primary)) {
589 $pdf->SetFillColor(215, 121, 123);
591 if ($field == $this->displayfield) {
592 $pdf->SetFillColor(142, 159, 224);
595 if ($with_doc) {
596 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
597 } else {
598 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
601 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
602 $pdf->PMA_PDF_setXScale($this->x);
603 $pdf->SetFillColor(255);
604 } // end while
605 /*if ($pdf->PageNo() > 1) {
606 $pdf->PMA_PDF_die(__('The scale factor is too small to fit the schema on one page'));
607 } */
608 } // end of the "PMA_RT_Table_draw()" method
610 * The "PMA_RT_Table" constructor
612 * @param string table_name The table name
613 * @param integer ff The font size
614 * @param integer same_width The max. with among tables
615 * @param boolean show_keys Whether to display keys or not
616 * @param boolean show_info Whether to display table position or not
617 * @global object The current PDF document
618 * @global integer The current page number (from the
619 * $cfg['Servers'][$i]['table_coords'] table)
620 * @global array The relations settings
621 * @global string The current db name
622 * @access private
623 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
624 PMA_RT_Table::PMA_RT_Table_setHeight
626 function __construct($table_name, $ff, &$same_wide_width, $show_keys = false, $show_info = false)
628 global $pdf, $pdf_page_number, $cfgRelation, $db;
630 $this->table_name = $table_name;
631 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
632 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
633 if (!$result || !PMA_DBI_num_rows($result)) {
634 $pdf->PMA_PDF_die(sprintf(__('The %s table doesn\'t exist!'), $table_name));
636 // load fields
637 //check to see if it will load all fields or only the foreign keys
638 if ($show_keys) {
639 $indexes = PMA_Index::getFromTable($this->table_name, $db);
640 $all_columns = array();
641 foreach ($indexes as $index) {
642 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
644 $this->fields = array_keys($all_columns);
645 } else {
646 while ($row = PMA_DBI_fetch_row($result)) {
647 $this->fields[] = $row[0];
651 $this->show_info = $show_info;
653 // height and width
654 $this->PMA_RT_Table_setHeight();
655 // setWidth must me after setHeight, because title
656 // can include table height which changes table width
657 $this->PMA_RT_Table_setWidth($ff);
658 if ($same_wide_width < $this->width) {
659 $same_wide_width = $this->width;
661 // x and y
662 $sql = 'SELECT x, y FROM '
663 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
664 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
665 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
666 . ' AND pdf_page_number = ' . $pdf_page_number;
667 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
669 if (!$result || !PMA_DBI_num_rows($result)) {
670 $pdf->PMA_PDF_die(sprintf(__('Please configure the coordinates for table %s'), $table_name));
672 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
673 $this->x = (double) $this->x;
674 $this->y = (double) $this->y;
675 // displayfield
676 $this->displayfield = PMA_getDisplayField($db, $table_name);
677 // index
678 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
679 if (PMA_DBI_num_rows($result) > 0) {
680 while ($row = PMA_DBI_fetch_assoc($result)) {
681 if ($row['Key_name'] == 'PRIMARY') {
682 $this->primary[] = $row['Column_name'];
685 } // end if
686 } // end of the "PMA_RT_Table()" method
687 } // end class "PMA_RT_Table"
689 * Draws relation links
691 * @access private
692 * @see PMA_RT
693 * @package phpMyAdmin
695 class PMA_RT_Relation {
697 * Defines private properties
699 var $x_src, $y_src;
700 var $src_dir ;
701 var $dest_dir;
702 var $x_dest, $y_dest;
703 var $w_tick = 5;
706 * Gets arrows coordinates
708 * @param string table The current table name
709 * @param string column The relation column name
710 * @return array Arrows coordinates
711 * @access private
713 function PMA_RT_Relation_getXy($table, $column)
715 $pos = array_search($column, $table->fields);
716 // x_left, x_right, y
717 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
718 } // end of the "PMA_RT_Relation_getXy()" method
720 * Do draws relation links
722 * @param boolean change_color Whether to use one color per relation or not
723 * @param integer i The id of the link to draw
724 * @global object The current PDF document
725 * @access private
726 * @see PMA_PDF
728 function PMA_RT_Relation_draw($change_color, $i)
730 global $pdf;
732 if ($change_color) {
733 $d = $i % 6;
734 $j = ($i - $d) / 6;
735 $j = $j % 4;
736 $j++;
737 $case = array(
738 array(1, 0, 0),
739 array(0, 1, 0),
740 array(0, 0, 1),
741 array(1, 1, 0),
742 array(1, 0, 1),
743 array(0, 1, 1)
745 list ($a, $b, $c) = $case[$d];
746 $e = (1 - ($j - 1) / 6);
747 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
748 } else {
749 $pdf->SetDrawColor(0);
750 } // end if... else...
751 $pdf->PMA_PDF_setLineWidthScale(0.2);
752 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
753 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
754 $pdf->PMA_PDF_setLineWidthScale(0.1);
755 $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);
756 // arrow
757 $root2 = 2 * sqrt(2);
758 $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);
759 $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);
761 $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);
762 $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);
763 $pdf->SetDrawColor(0);
764 } // end of the "PMA_RT_Relation_draw()" method
766 * The "PMA_RT_Relation" constructor
768 * @param string master_table The master table name
769 * @param string master_field The relation field in the master table
770 * @param string foreign_table The foreign table name
771 * @param string foreigh_field The relation field in the foreign table
772 * @access private
773 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
775 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
777 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
778 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
779 $src_left = $src_pos[0] - $this->w_tick;
780 $src_right = $src_pos[1] + $this->w_tick;
781 $dest_left = $dest_pos[0] - $this->w_tick;
782 $dest_right = $dest_pos[1] + $this->w_tick;
784 $d1 = abs($src_left - $dest_left);
785 $d2 = abs($src_right - $dest_left);
786 $d3 = abs($src_left - $dest_right);
787 $d4 = abs($src_right - $dest_right);
788 $d = min($d1, $d2, $d3, $d4);
790 if ($d == $d1) {
791 $this->x_src = $src_pos[0];
792 $this->src_dir = -1;
793 $this->x_dest = $dest_pos[0];
794 $this->dest_dir = -1;
795 } elseif ($d == $d2) {
796 $this->x_src = $src_pos[1];
797 $this->src_dir = 1;
798 $this->x_dest = $dest_pos[0];
799 $this->dest_dir = -1;
800 } elseif ($d == $d3) {
801 $this->x_src = $src_pos[0];
802 $this->src_dir = -1;
803 $this->x_dest = $dest_pos[1];
804 $this->dest_dir = 1;
805 } else {
806 $this->x_src = $src_pos[1];
807 $this->src_dir = 1;
808 $this->x_dest = $dest_pos[1];
809 $this->dest_dir = 1;
811 $this->y_src = $src_pos[2];
812 $this->y_dest = $dest_pos[2];
813 } // end of the "PMA_RT_Relation()" method
814 } // end of the "PMA_RT_Relation" class
816 * Draws and send the database schema
818 * @access public
819 * @see PMA_PDF
820 * @package phpMyAdmin
822 class PMA_RT {
824 * Defines private properties
826 var $tables = array();
827 var $relations = array();
828 var $ff = PMA_PDF_FONT;
829 var $x_max = 0;
830 var $y_max = 0;
831 var $scale;
832 var $x_min = 100000;
833 var $y_min = 100000;
834 var $t_marg = 10;
835 var $b_marg = 10;
836 var $l_marg = 10;
837 var $r_marg = 10;
838 var $tablewidth;
839 var $same_wide = 0;
842 * Sets X and Y minimum and maximum for a table cell
844 * @param string table The table name
845 * @access private
847 function PMA_RT_setMinMax($table)
849 $this->x_max = max($this->x_max, $table->x + $table->width);
850 $this->y_max = max($this->y_max, $table->y + $table->height);
851 $this->x_min = min($this->x_min, $table->x);
852 $this->y_min = min($this->y_min, $table->y);
853 } // end of the "PMA_RT_setMinMax()" method
855 * Defines relation objects
857 * @param string master_table The master table name
858 * @param string master_field The relation field in the master table
859 * @param string foreign_table The foreign table name
860 * @param string foreign_field The relation field in the foreign table
861 * @param boolean show_info Whether to display table position or not
862 * @access private
863 * @see PMA_RT_setMinMax
865 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field, $show_info)
867 if (!isset($this->tables[$master_table])) {
868 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth, false, $show_info);
869 $this->PMA_RT_setMinMax($this->tables[$master_table]);
871 if (!isset($this->tables[$foreign_table])) {
872 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth, false, $show_info);
873 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
875 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
876 } // end of the "PMA_RT_addRelation()" method
878 * Draws the grid
880 * @global object the current PMA_PDF instance
881 * @access private
882 * @see PMA_PDF
884 function PMA_RT_strokeGrid()
886 global $pdf;
888 $pdf->SetMargins(0, 0);
889 $pdf->SetDrawColor(200, 200, 200);
890 // Draws horizontal lines
891 for ($l = 0; $l < 21; $l++) {
892 $pdf->line(0, $l * 10, $pdf->getFh(), $l * 10);
893 // Avoid duplicates
894 if ($l > 0) {
895 $pdf->SetXY(0, $l * 10);
896 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
897 $pdf->Cell(5, 5, ' ' . $label);
898 } // end if
899 } // end for
900 // Draws vertical lines
901 for ($j = 0; $j < 30 ;$j++) {
902 $pdf->line($j * 10, 0, $j * 10, $pdf->getFw());
903 $pdf->SetXY($j * 10, 0);
904 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
905 $pdf->Cell(5, 7, $label);
906 } // end for
907 } // end of the "PMA_RT_strokeGrid()" method
909 * Draws relation arrows
911 * @param boolean change_color Whether to use one color per relation or not
912 * @access private
913 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
915 function PMA_RT_drawRelations($change_color)
917 $i = 0;
918 foreach ($this->relations AS $relation) {
919 $relation->PMA_RT_Relation_draw($change_color, $i);
920 $i++;
921 } // end while
922 } // end of the "PMA_RT_drawRelations()" method
924 * Draws tables
926 * @param boolean draw_color Whether to display table position or not
927 * @access private
928 * @see PMA_RT_Table::PMA_RT_Table_draw()
930 function PMA_RT_drawTables($draw_color = 0)
932 foreach ($this->tables AS $table) {
933 $table->PMA_RT_Table_draw($this->ff, $draw_color);
935 } // end of the "PMA_RT_drawTables()" method
937 * Ouputs the PDF document to a file
939 * @global object The current PDF document
940 * @global string The current database name
941 * @global integer The current page number (from the
942 * $cfg['Servers'][$i]['table_coords'] table)
943 * @access private
944 * @see PMA_PDF
946 function PMA_RT_showRt()
948 global $pdf, $db, $pdf_page_number, $cfgRelation;
950 $pdf->SetFontSize(14);
951 $pdf->SetLineWidth(0.2);
952 $pdf->SetDisplayMode('fullpage');
953 // Get the name of this pdfpage to use as filename (Mike Beck)
954 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
955 . ' WHERE page_nr = ' . $pdf_page_number;
956 $_name_rs = PMA_query_as_controluser($_name_sql);
957 if ($_name_rs) {
958 $_name_row = PMA_DBI_fetch_row($_name_rs);
959 $filename = $_name_row[0] . '.pdf';
961 // i don't know if there is a chance for this to happen, but rather be on the safe side:
962 if (empty($filename)) {
963 $filename = $pdf_page_number . '.pdf';
965 // $pdf->Output($db . '_' . $filename, TRUE);
966 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
967 } // end of the "PMA_RT_showRt()" method
969 * The "PMA_RT" constructor
971 * @param integer which_rel The page number to draw (from the
972 * $cfg['Servers'][$i]['table_coords'] table)
973 * @param boolean show_info Whether to display table position or not
974 * @param boolean change_color Was originally whether to use one color per
975 * relation or not, now enables/disables color
976 * everywhere, due to some problems printing with color
977 * @param boolean show_grid Whether to draw grids or not
978 * @param boolean all_tab_same_wide Whether all tables should have the same width or not
979 * @param boolean show_keys Wheter to show all field or only the keys
980 * @global object The current PDF document
981 * @global string The current db name
982 * @global array The relations settings
983 * @access private
984 * @see PMA_PDF
986 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)
988 global $pdf, $db, $cfgRelation, $with_doc;
990 $this->same_wide = $all_tab_same_wide;
991 // Initializes a new document
992 $pdf = new PMA_PDF('L', 'mm', $paper);
993 $pdf->SetTitle(sprintf(__('Schema of the %s database - Page %s'), $GLOBALS['db'], $which_rel));
994 $pdf->setCMargin(0);
995 $pdf->Open();
996 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
997 $pdf->AliasNbPages();
998 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
999 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
1000 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
1001 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
1002 $this->ff = PMA_PDF_FONT;
1003 $pdf->SetFont($this->ff, '', 14);
1004 $pdf->SetAutoPageBreak('auto');
1005 // Gets tables on this page
1006 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
1007 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1008 . ' AND pdf_page_number = ' . $which_rel;
1009 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
1010 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1011 $pdf->PMA_PDF_die(__('No tables'));
1012 // die('No tables');
1013 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1014 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1015 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1017 // make doc //
1018 if ($with_doc) {
1019 $pdf->SetAutoPageBreak('auto', 15);
1020 $pdf->setCMargin(1);
1021 PMA_RT_DOC($alltables);
1022 $pdf->SetAutoPageBreak('auto');
1023 $pdf->setCMargin(0);
1026 $pdf->Addpage();
1028 if ($with_doc) {
1029 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1030 $pdf->Bookmark(__('Relational schema'));
1031 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1032 $this->t_marg = 18;
1033 $this->b_marg = 18;
1036 /* snip */
1038 foreach ($alltables AS $table) {
1039 if (!isset($this->tables[$table])) {
1040 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys, $show_info);
1043 if ($this->same_wide) {
1044 $this->tables[$table]->width = $this->tablewidth;
1046 $this->PMA_RT_setMinMax($this->tables[$table]);
1048 // Defines the scale factor
1049 $this->scale = ceil(
1050 max(
1051 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1052 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1053 * 100) / 100;
1055 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1056 // Builds and save the PDF document
1057 $pdf->PMA_PDF_setLineWidthScale(0.1);
1059 if ($show_grid) {
1060 $pdf->SetFontSize(10);
1061 $this->PMA_RT_strokeGrid();
1063 $pdf->PMA_PDF_setFontSizeScale(14);
1064 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1065 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1066 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1067 // . ' AND master_table IN (' . $intable . ')'
1068 // . ' AND foreign_table IN (' . $intable . ')';
1069 // $result = PMA_query_as_controluser($sql);
1071 // previous logic was checking master tables and foreign tables
1072 // but I think that looping on every table of the pdf page as a master
1073 // and finding its foreigns is OK (then we can support innodb)
1074 $seen_a_relation = false;
1075 foreach ($alltables AS $one_table) {
1076 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1077 if ($exist_rel) {
1078 $seen_a_relation = true;
1079 foreach ($exist_rel AS $master_field => $rel) {
1080 // put the foreign table on the schema only if selected
1081 // by the user
1082 // (do not use array_search() because we would have to
1083 // to do a === FALSE and this is not PHP3 compatible)
1084 if (in_array($rel['foreign_table'], $alltables)) {
1085 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info);
1087 } // end while
1088 } // end if
1089 } // end while
1090 // also show tables without relations
1091 // $norelations = TRUE;
1092 // if ($result && PMA_DBI_num_rows($result) > 0) {
1093 // $norelations = FALSE;
1094 // while ($row = PMA_DBI_fetch_assoc($result)) {
1095 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1096 // }
1097 // }
1098 // if ($norelations == FALSE) {
1099 if ($seen_a_relation) {
1100 $this->PMA_RT_drawRelations($change_color);
1103 $this->PMA_RT_drawTables($change_color);
1105 $this->PMA_RT_showRt();
1106 } // end of the "PMA_RT()" method
1107 } // end of the "PMA_RT" class
1109 function PMA_RT_DOC($alltables)
1111 global $db, $pdf, $orientation, $paper;
1112 // TOC
1113 $pdf->addpage($GLOBALS['orientation']);
1114 $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
1115 $pdf->Ln(15);
1116 $i = 1;
1117 foreach ($alltables AS $table) {
1118 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1119 $pdf->SetX(10);
1120 // $pdf->Ln(1);
1121 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1122 $pdf->SetX(10);
1123 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1124 // $pdf->Ln(1);
1125 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1126 while ($row = PMA_DBI_fetch_assoc($result)) {
1127 $pdf->SetX(20);
1128 $field_name = $row['Field'];
1129 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1130 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1132 $lasttable = $table;
1133 $i++;
1135 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1136 $pdf->SetX(10);
1137 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1138 $pdf->SetX(10);
1139 $pdf->Cell(0, 6, $i + 1 . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1140 $z = 0;
1141 foreach ($alltables AS $table) {
1142 $z++;
1143 $pdf->addpage($GLOBALS['orientation']);
1144 $pdf->Bookmark($table);
1145 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1146 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1147 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1148 $pdf->SetFont('', 'B', 18);
1149 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1150 $pdf->SetFont('', '', 8);
1151 $pdf->ln();
1153 $cfgRelation = PMA_getRelationsParam();
1154 $comments = PMA_getComments($db, $table);
1155 if ($cfgRelation['mimework']) {
1156 $mime_map = PMA_getMIME($db, $table, true);
1160 * Gets table informations
1162 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1163 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1164 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1165 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1166 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1167 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1170 * Gets table keys and retains them
1172 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1173 $primary = '';
1174 $indexes = array();
1175 $lastIndex = '';
1176 $indexes_info = array();
1177 $indexes_data = array();
1178 $pk_array = array(); // will be use to emphasis prim. keys in the table
1179 // view
1180 while ($row = PMA_DBI_fetch_assoc($result)) {
1181 // Backups the list of primary keys
1182 if ($row['Key_name'] == 'PRIMARY') {
1183 $primary .= $row['Column_name'] . ', ';
1184 $pk_array[$row['Column_name']] = 1;
1186 // Retains keys informations
1187 if ($row['Key_name'] != $lastIndex) {
1188 $indexes[] = $row['Key_name'];
1189 $lastIndex = $row['Key_name'];
1191 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1192 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1193 if (isset($row['Cardinality'])) {
1194 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1196 // I don't know what does following column mean....
1197 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1198 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1200 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1201 if (isset($row['Sub_part'])) {
1202 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1204 } // end while
1205 if ($result) {
1206 PMA_DBI_free_result($result);
1210 * Gets fields properties
1212 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1213 $fields_cnt = PMA_DBI_num_rows($result);
1214 // Check if we can use Relations (Mike Beck)
1215 if (!empty($cfgRelation['relation'])) {
1216 // Find which tables are related with the current one and write it in
1217 // an array
1218 $res_rel = PMA_getForeigners($db, $table);
1220 if (count($res_rel) > 0) {
1221 $have_rel = true;
1222 } else {
1223 $have_rel = false;
1225 } else {
1226 $have_rel = false;
1227 } // end if
1229 * Displays the comments of the table if MySQL >= 3.23
1232 $break = false;
1233 if (!empty($show_comment)) {
1234 $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
1235 $break = true;
1238 if (!empty($create_time)) {
1239 $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
1240 $break = true;
1243 if (!empty($update_time)) {
1244 $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
1245 $break = true;
1248 if (!empty($check_time)) {
1249 $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
1250 $break = true;
1253 if ($break == true) {
1254 $pdf->Cell(0, 3, '', 0, 1);
1255 $pdf->Ln();
1258 $pdf->SetFont('', 'B');
1259 if (isset($orientation) && $orientation == 'L') {
1260 $pdf->Cell(25, 8, ucfirst(__('Column')), 1, 0, 'C');
1261 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1262 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1263 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1264 $pdf->Cell(20, 8, ucfirst(__('Default')), 1, 0, 'C');
1265 $pdf->Cell(25, 8, ucfirst(__('Extra')), 1, 0, 'C');
1266 $pdf->Cell(45, 8, ucfirst(__('Links to')), 1, 0, 'C');
1268 if ($paper == 'A4') {
1269 $comments_width = 67;
1270 } else {
1271 // this is really intended for 'letter'
1273 * @todo find optimal width for all formats
1275 $comments_width = 50;
1277 $pdf->Cell($comments_width, 8, ucfirst(__('Comments')), 1, 0, 'C');
1278 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1279 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1280 } else {
1281 $pdf->Cell(20, 8, ucfirst(__('Column')), 1, 0, 'C');
1282 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1283 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1284 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1285 $pdf->Cell(15, 8, ucfirst(__('Default')), 1, 0, 'C');
1286 $pdf->Cell(15, 8, ucfirst(__('Extra')), 1, 0, 'C');
1287 $pdf->Cell(30, 8, ucfirst(__('Links to')), 1, 0, 'C');
1288 $pdf->Cell(30, 8, ucfirst(__('Comments')), 1, 0, 'C');
1289 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1290 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1292 $pdf->SetFont('', '');
1294 while ($row = PMA_DBI_fetch_assoc($result)) {
1295 $type = $row['Type'];
1296 // reformat mysql query output
1297 // set or enum types: slashes single quotes inside options
1298 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1299 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1300 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1301 $type_nowrap = '';
1303 $binary = 0;
1304 $unsigned = 0;
1305 $zerofill = 0;
1306 } else {
1307 $type_nowrap = ' nowrap="nowrap"';
1308 $type = preg_replace('@BINARY@i', '', $type);
1309 $type = preg_replace('@ZEROFILL@i', '', $type);
1310 $type = preg_replace('@UNSIGNED@i', '', $type);
1311 if (empty($type)) {
1312 $type = '&nbsp;';
1315 $binary = stristr($row['Type'], 'BINARY');
1316 $unsigned = stristr($row['Type'], 'UNSIGNED');
1317 $zerofill = stristr($row['Type'], 'ZEROFILL');
1319 $attribute = ' ';
1320 if ($binary) {
1321 $attribute = 'BINARY';
1323 if ($unsigned) {
1324 $attribute = 'UNSIGNED';
1326 if ($zerofill) {
1327 $attribute = 'UNSIGNED ZEROFILL';
1329 if (!isset($row['Default'])) {
1330 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1331 $row['Default'] = 'NULL';
1334 $field_name = $row['Field'];
1335 // $pdf->Ln();
1336 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1337 $pdf->Bookmark($field_name, 1, -1);
1338 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1339 $pdf_row = array($field_name,
1340 $type,
1341 $attribute,
1342 ($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes'),
1343 ((isset($row['Default'])) ? $row['Default'] : ''),
1344 $row['Extra'],
1345 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1346 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1347 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1349 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1350 if (isset($res_rel[$field_name]['foreign_table']) AND
1351 isset($res_rel[$field_name]['foreign_field']) AND
1352 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1355 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1356 } else {
1357 unset($links[6]);
1359 $pdf->Row($pdf_row, $links);
1361 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1362 //echo ' ' . $field_name . '&nbsp;' . "\n";
1364 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1365 $pdf->Cell(20, 8, $attribute, 1, 0, 'L');
1366 $pdf->Cell(15, 8, , 1, 0, 'L');
1367 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1368 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1369 if ($have_rel) {
1370 if (isset($res_rel[$field_name])) {
1371 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1374 if ($cfgRelation['commwork']) {
1375 if (isset($comments[$field_name])) {
1376 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1378 } */
1379 } // end while
1380 $pdf->SetFont('', '', 14);
1381 PMA_DBI_free_result($result);
1382 } //end each
1383 } // end function PMA_RT_DOC
1386 * Main logic
1388 if (!isset($pdf_page_number)) {
1389 $pdf_page_number = 1;
1392 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1393 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1394 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1395 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1396 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1397 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1398 $paper = isset($paper) ? $paper : 'A4';
1399 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1400 PMA_DBI_select_db($db);
1402 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);