Translation update done using Pootle.
[phpmyadmin/crack.git] / pdf_schema.php
blob598c9a4b52449ef54e47ef5f454587e086b7214c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
10 * Gets some core scripts
12 require_once './libraries/common.inc.php';
14 /**
15 * Settings for relation stuff
17 require_once './libraries/relation.lib.php';
18 require_once './libraries/transformations.lib.php';
19 require_once './libraries/Index.class.php';
21 $cfgRelation = PMA_getRelationsParam();
23 /**
24 * Now in ./libraries/relation.lib.php we check for all tables
25 * that we need, but if we don't find them we are quiet about it
26 * so people can work without.
27 * This page is absolutely useless if you didn't set up your tables
28 * correctly, so it is a good place to see which tables we can and
29 * complain ;-)
31 if (!$cfgRelation['pdfwork']) {
32 echo '<font color="red">' . __('Error') . '</font><br />' . "\n";
33 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
34 echo sprintf(__('The additional features for working with linked tables have been deactivated. To find out why click %shere%s.'), $url_to_goto, '</a>') . "\n";
37 /**
38 * Font used in PDF.
40 * @todo Make this configuratble (at least Sans/Serif).
42 define('PMA_PDF_FONT', 'DejaVuSans');
43 require_once './libraries/tcpdf/tcpdf.php';
45 /**
46 * Extends the "FPDF" class and prepares the work
48 * @access public
49 * @see FPDF
50 * @package phpMyAdmin
52 class PMA_PDF extends TCPDF {
53 /**
54 * Defines private properties
56 var $x_min;
57 var $y_min;
58 var $l_marg = 10;
59 var $t_marg = 10;
60 var $scale;
61 var $PMA_links;
62 var $Outlines = array();
63 var $def_outlines;
64 var $Alias = array();
65 var $widths;
67 public function getFh()
69 return $this->fh;
72 public function getFw()
74 return $this->fw;
77 public function setCMargin($c_margin)
79 $this->cMargin = $c_margin;
82 function SetAlias($name, $value)
84 $this->Alias[$name] = $value ;
87 function _putpages()
89 if (count($this->Alias) > 0) {
90 $nb = $this->page;
91 foreach ($this->Alias AS $alias => $value) {
92 for ($n = 1;$n <= $nb;$n++)
93 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
96 parent::_putpages();
99 /**
100 * Sets the scaling factor, defines minimum coordinates and margins
102 * @param float scale The scaling factor
103 * @param float x_min The minimum X coordinate
104 * @param float y_min The minimum Y coordinate
105 * @param float l_marg The left margin
106 * @param float t_marg The top margin
107 * @access public
109 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
111 $this->scale = $scale;
112 $this->x_min = $x_min;
113 $this->y_min = $y_min;
114 if ($this->l_marg != -1) {
115 $this->l_marg = $l_marg;
117 if ($this->t_marg != -1) {
118 $this->t_marg = $t_marg;
120 } // end of the "PMA_PDF_setScale" function
122 * Outputs a scaled cell
124 * @param float w The cell width
125 * @param float h The cell height
126 * @param string txt The text to output
127 * @param mixed border Whether to add borders or not
128 * @param integer ln Where to put the cursor once the output is done
129 * @param string align Align mode
130 * @param integer fill Whether to fill the cell with a color or not
131 * @access public
132 * @see FPDF::Cell()
134 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
136 $h = $h / $this->scale;
137 $w = $w / $this->scale;
138 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
139 } // end of the "PMA_PDF_cellScale" function
141 * Draws a scaled line
143 * @param float x1 The horizontal position of the starting point
144 * @param float y1 The vertical position of the starting point
145 * @param float x2 The horizontal position of the ending point
146 * @param float y2 The vertical position of the ending point
147 * @access public
148 * @see FPDF::Line()
150 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
152 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
153 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
154 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
155 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
156 $this->Line($x1, $y1, $x2, $y2);
157 } // end of the "PMA_PDF_lineScale" function
159 * Sets x and y scaled positions
161 * @param float x The x position
162 * @param float y The y position
163 * @access public
164 * @see FPDF::SetXY()
166 function PMA_PDF_setXyScale($x, $y)
168 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
169 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
170 $this->SetXY($x, $y);
171 } // end of the "PMA_PDF_setXyScale" function
173 * Sets the X scaled positions
175 * @param float x The x position
176 * @access public
177 * @see FPDF::SetX()
179 function PMA_PDF_setXScale($x)
181 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
182 $this->SetX($x);
183 } // end of the "PMA_PDF_setXScale" function
185 * Sets the scaled font size
187 * @param float size The font size (in points)
188 * @access public
189 * @see FPDF::SetFontSize()
191 function PMA_PDF_setFontSizeScale($size)
193 // Set font size in points
194 $size = $size / $this->scale;
195 $this->SetFontSize($size);
196 } // end of the "PMA_PDF_setFontSizeScale" function
198 * Sets the scaled line width
200 * @param float width The line width
201 * @access public
202 * @see FPDF::SetLineWidth()
204 function PMA_PDF_setLineWidthScale($width)
206 $width = $width / $this->scale;
207 $this->SetLineWidth($width);
208 } // end of the "PMA_PDF_setLineWidthScale" function
210 * Displays an error message
212 * @param string error_message the error mesage
213 * @global array the PMA configuration array
214 * @global integer the current server id
215 * @global string the current language
216 * @global string the charset to convert to
217 * @global string the current database name
218 * @global string the current charset
219 * @global string the current text direction
220 * @global string a localized string
221 * @global string an other localized string
222 * @access public
224 function PMA_PDF_die($error_message = '')
226 global $cfg;
227 global $server, $lang, $convcharset, $db;
228 global $charset, $text_dir;
230 require_once './libraries/header.inc.php';
232 echo '<p><strong>PDF - ' . __('Error') . '</strong></p>' . "\n";
233 if (!empty($error_message)) {
234 $error_message = htmlspecialchars($error_message);
236 echo '<p>' . "\n";
237 echo ' ' . $error_message . "\n";
238 echo '</p>' . "\n";
240 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
241 . '">' . __('Back') . '</a>';
242 echo "\n";
244 require_once './libraries/footer.inc.php';
245 } // end of the "PMA_PDF_die()" function
247 * Aliases the "Error()" function from the FPDF class to the
248 * "PMA_PDF_die()" one
250 * @param string error_message the error mesage
251 * @access public
252 * @see PMA_PDF_die
254 function Error($error_message = '')
256 $this->PMA_PDF_die($error_message);
257 } // end of the "Error()" method
258 function Header()
260 // We only show this if we find something in the new pdf_pages table
262 // This function must be named "Header" to work with the FPDF library
263 global $cfgRelation, $db, $pdf_page_number, $with_doc;
264 if ($with_doc) {
265 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
266 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
267 . ' AND page_nr = \'' . $pdf_page_number . '\'';
268 $test_rs = PMA_query_as_controluser($test_query);
269 $pages = @PMA_DBI_fetch_assoc($test_rs);
270 $this->SetFont('', 'B', 14);
271 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
272 $this->SetFont('', '');
273 $this->Ln();
276 function Footer()
278 // This function must be named "Footer" to work with the FPDF library
279 global $with_doc;
280 if ($with_doc) {
281 $this->SetY(-15);
282 $this->SetFont('', '', 14);
283 $this->Cell(0, 6, __('Page number:') . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
284 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
285 $this->SetY(20);
288 function Bookmark($txt, $level = 0, $y = 0)
290 // Add a bookmark
291 $this->Outlines[0][] = $level;
292 $this->Outlines[1][] = $txt;
293 $this->Outlines[2][] = $this->page;
294 if ($y == -1) {
295 $y = $this->GetY();
297 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
300 function _putbookmarks()
302 if (count($this->Outlines) > 0) {
303 // Save object number
304 $memo_n = $this->n;
305 // Take the number of sub elements for an outline
306 $nb_outlines = sizeof($this->Outlines[0]);
307 $first_level = array();
308 $parent = array();
309 $parent[0] = 1;
310 for ($i = 0; $i < $nb_outlines; $i++) {
311 $level = $this->Outlines[0][$i];
312 $kids = 0;
313 $last = -1;
314 $prev = -1;
315 $next = -1;
316 if ($i > 0) {
317 $cursor = $i-1;
318 // Take the previous outline in the same level
319 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
320 $cursor--;
321 if ($this->Outlines[0][$cursor] == $level) {
322 $prev = $cursor;
325 if ($i < $nb_outlines-1) {
326 $cursor = $i + 1;
327 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
328 // Take the immediate kid in level + 1
329 if ($this->Outlines[0][$cursor] == $level + 1) {
330 $kids++;
331 $last = $cursor;
333 $cursor++;
335 $cursor = $i + 1;
336 // Take the next outline in the same level
337 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
338 $cursor++;
339 if ($this->Outlines[0][$cursor] == $level) {
340 $next = $cursor;
343 $this->_newobj();
344 $parent[$level + 1] = $this->n;
345 if ($level == 0) {
346 $first_level[] = $this->n;
348 $this->_out('<<');
349 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
350 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
351 if ($prev != -1) {
352 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
354 if ($next != -1) {
355 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
357 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
358 if ($kids > 0) {
359 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
360 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
361 $this->_out('/Count -' . $kids);
363 $this->_out('>>');
364 $this->_out('endobj');
366 // First page of outlines
367 $this->_newobj();
368 $this->def_outlines = $this->n;
369 $this->_out('<<');
370 $this->_out('/Type');
371 $this->_out('/Outlines');
372 $this->_out('/First ' . $first_level[0] . ' 0 R');
373 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
374 $this->_out('/Count ' . sizeof($first_level));
375 $this->_out('>>');
376 $this->_out('endobj');
380 function _putresources()
382 parent::_putresources();
383 $this->_putbookmarks();
386 function _putcatalog()
388 parent::_putcatalog();
389 if (count($this->Outlines) > 0) {
390 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
391 $this->_out('/PageMode /UseOutlines');
394 function SetWidths($w)
396 // column widths
397 $this->widths = $w;
400 function Row($data, $links)
402 // line height
403 $nb = 0;
404 $data_cnt = count($data);
405 for ($i = 0;$i < $data_cnt;$i++)
406 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
407 $il = $this->FontSize;
408 $h = ($il + 1) * $nb;
409 // page break if necessary
410 $this->CheckPageBreak($h);
411 // draw the cells
412 $data_cnt = count($data);
413 for ($i = 0;$i < $data_cnt;$i++) {
414 $w = $this->widths[$i];
415 // save current position
416 $x = $this->GetX();
417 $y = $this->GetY();
418 // draw the border
419 $this->Rect($x, $y, $w, $h);
420 if (isset($links[$i])) {
421 $this->Link($x, $y, $w, $h, $links[$i]);
423 // print text
424 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
425 // go to right side
426 $this->SetXY($x + $w, $y);
428 // go to line
429 $this->Ln($h);
432 function CheckPageBreak($h)
434 // if height h overflows, manual page break
435 if ($this->GetY() + $h > $this->PageBreakTrigger) {
436 $this->AddPage($this->CurOrientation);
440 function NbLines($w, $txt)
442 // compute number of lines used by a multicell of width w
443 $cw = &$this->CurrentFont['cw'];
444 if ($w == 0) {
445 $w = $this->w - $this->rMargin - $this->x;
447 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
448 $s = str_replace("\r", '', $txt);
449 $nb = strlen($s);
450 if ($nb > 0 and $s[$nb-1] == "\n") {
451 $nb--;
453 $sep = -1;
454 $i = 0;
455 $j = 0;
456 $l = 0;
457 $nl = 1;
458 while ($i < $nb) {
459 $c = $s[$i];
460 if ($c == "\n") {
461 $i++;
462 $sep = -1;
463 $j = $i;
464 $l = 0;
465 $nl++;
466 continue;
468 if ($c == ' ') {
469 $sep = $i;
471 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
472 if ($l > $wmax) {
473 if ($sep == -1) {
474 if ($i == $j) {
475 $i++;
477 } else {
478 $i = $sep + 1;
480 $sep = -1;
481 $j = $i;
482 $l = 0;
483 $nl++;
484 } else {
485 $i++;
488 return $nl;
490 } // end of the "PMA_PDF" class
494 * Draws tables schema
496 * @access private
497 * @see PMA_RT
498 * @package phpMyAdmin
500 class PMA_RT_Table {
502 * Defines private properties
504 var $nb_fiels;
505 var $table_name;
506 var $width = 0;
507 var $height;
508 var $fields = array();
509 var $height_cell = 6;
510 var $x, $y;
511 var $primary = array();
512 var $show_info = false;
515 * Returns title of the current table,
516 * title can have the dimensions of the table
518 * @access private
520 function getTitle()
522 return ($this->show_info ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) : '') . ' ' . $this->table_name;
523 } // end of the "getTitle" function
525 * Sets the width of the table
527 * @param integer ff The font size
528 * @global object The current PDF document
529 * @access private
530 * @see PMA_PDF
532 function PMA_RT_Table_setWidth($ff)
534 global $pdf;
536 foreach ($this->fields AS $field) {
537 $this->width = max($this->width, $pdf->GetStringWidth($field));
539 $this->width += $pdf->GetStringWidth(' ');
540 $pdf->SetFont($ff, 'B');
541 // it is unknown what value must be added, because
542 // table title is affected by the tabe width value
543 while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
544 $this->width += 5;
546 $pdf->SetFont($ff, '');
547 } // end of the "PMA_RT_Table_setWidth()" method
549 * Sets the height of the table
551 * @access private
553 function PMA_RT_Table_setHeight()
555 $this->height = (count($this->fields) + 1) * $this->height_cell;
556 } // end of the "PMA_RT_Table_setHeight()" method
558 * Do draw the table
560 * @param integer ff The font size
561 * @param boolean setcolortWhether to display color
562 * @global object The current PDF document
563 * @access private
564 * @see PMA_PDF
566 function PMA_RT_Table_draw($ff, $setcolor = 0)
568 global $pdf, $with_doc;
570 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
571 $pdf->SetFont($ff, 'B');
572 if ($setcolor) {
573 $pdf->SetTextColor(200);
574 $pdf->SetFillColor(0, 0, 128);
576 if ($with_doc) {
577 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
578 } else {
579 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
582 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->getTitle(), 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
583 $pdf->PMA_PDF_setXScale($this->x);
584 $pdf->SetFont($ff, '');
585 $pdf->SetTextColor(0);
586 $pdf->SetFillColor(255);
588 foreach ($this->fields AS $field) {
589 if ($setcolor) {
590 if (in_array($field, $this->primary)) {
591 $pdf->SetFillColor(215, 121, 123);
593 if ($field == $this->displayfield) {
594 $pdf->SetFillColor(142, 159, 224);
597 if ($with_doc) {
598 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
599 } else {
600 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
603 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
604 $pdf->PMA_PDF_setXScale($this->x);
605 $pdf->SetFillColor(255);
606 } // end while
607 /*if ($pdf->PageNo() > 1) {
608 $pdf->PMA_PDF_die(__('The scale factor is too small to fit the schema on one page'));
609 } */
610 } // end of the "PMA_RT_Table_draw()" method
612 * The "PMA_RT_Table" constructor
614 * @param string table_name The table name
615 * @param integer ff The font size
616 * @param integer same_width The max. with among tables
617 * @param boolean show_keys Whether to display keys or not
618 * @param boolean show_info Whether to display table position or not
619 * @global object The current PDF document
620 * @global integer The current page number (from the
621 * $cfg['Servers'][$i]['table_coords'] table)
622 * @global array The relations settings
623 * @global string The current db name
624 * @access private
625 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
626 PMA_RT_Table::PMA_RT_Table_setHeight
628 function __construct($table_name, $ff, &$same_wide_width, $show_keys = false, $show_info = false)
630 global $pdf, $pdf_page_number, $cfgRelation, $db;
632 $this->table_name = $table_name;
633 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
634 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
635 if (!$result || !PMA_DBI_num_rows($result)) {
636 $pdf->PMA_PDF_die(sprintf(__('The %s table doesn\'t exist!'), $table_name));
638 // load fields
639 //check to see if it will load all fields or only the foreign keys
640 if ($show_keys) {
641 $indexes = PMA_Index::getFromTable($this->table_name, $db);
642 $all_columns = array();
643 foreach ($indexes as $index) {
644 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
646 $this->fields = array_keys($all_columns);
647 } else {
648 while ($row = PMA_DBI_fetch_row($result)) {
649 $this->fields[] = $row[0];
653 $this->show_info = $show_info;
655 // height and width
656 $this->PMA_RT_Table_setHeight();
657 // setWidth must me after setHeight, because title
658 // can include table height which changes table width
659 $this->PMA_RT_Table_setWidth($ff);
660 if ($same_wide_width < $this->width) {
661 $same_wide_width = $this->width;
663 // x and y
664 $sql = 'SELECT x, y FROM '
665 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
666 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
667 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
668 . ' AND pdf_page_number = ' . $pdf_page_number;
669 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
671 if (!$result || !PMA_DBI_num_rows($result)) {
672 $pdf->PMA_PDF_die(sprintf(__('Please configure the coordinates for table %s'), $table_name));
674 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
675 $this->x = (double) $this->x;
676 $this->y = (double) $this->y;
677 // displayfield
678 $this->displayfield = PMA_getDisplayField($db, $table_name);
679 // index
680 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
681 if (PMA_DBI_num_rows($result) > 0) {
682 while ($row = PMA_DBI_fetch_assoc($result)) {
683 if ($row['Key_name'] == 'PRIMARY') {
684 $this->primary[] = $row['Column_name'];
687 } // end if
688 } // end of the "PMA_RT_Table()" method
689 } // end class "PMA_RT_Table"
691 * Draws relation links
693 * @access private
694 * @see PMA_RT
695 * @package phpMyAdmin
697 class PMA_RT_Relation {
699 * Defines private properties
701 var $x_src, $y_src;
702 var $src_dir ;
703 var $dest_dir;
704 var $x_dest, $y_dest;
705 var $w_tick = 5;
708 * Gets arrows coordinates
710 * @param string table The current table name
711 * @param string column The relation column name
712 * @return array Arrows coordinates
713 * @access private
715 function PMA_RT_Relation_getXy($table, $column)
717 $pos = array_search($column, $table->fields);
718 // x_left, x_right, y
719 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
720 } // end of the "PMA_RT_Relation_getXy()" method
722 * Do draws relation links
724 * @param boolean change_color Whether to use one color per relation or not
725 * @param integer i The id of the link to draw
726 * @global object The current PDF document
727 * @access private
728 * @see PMA_PDF
730 function PMA_RT_Relation_draw($change_color, $i)
732 global $pdf;
734 if ($change_color) {
735 $d = $i % 6;
736 $j = ($i - $d) / 6;
737 $j = $j % 4;
738 $j++;
739 $case = array(
740 array(1, 0, 0),
741 array(0, 1, 0),
742 array(0, 0, 1),
743 array(1, 1, 0),
744 array(1, 0, 1),
745 array(0, 1, 1)
747 list ($a, $b, $c) = $case[$d];
748 $e = (1 - ($j - 1) / 6);
749 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
750 } else {
751 $pdf->SetDrawColor(0);
752 } // end if... else...
753 $pdf->PMA_PDF_setLineWidthScale(0.2);
754 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
755 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
756 $pdf->PMA_PDF_setLineWidthScale(0.1);
757 $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);
758 // arrow
759 $root2 = 2 * sqrt(2);
760 $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_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);
763 $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);
764 $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);
765 $pdf->SetDrawColor(0);
766 } // end of the "PMA_RT_Relation_draw()" method
768 * The "PMA_RT_Relation" constructor
770 * @param string master_table The master table name
771 * @param string master_field The relation field in the master table
772 * @param string foreign_table The foreign table name
773 * @param string foreigh_field The relation field in the foreign table
774 * @access private
775 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
777 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
779 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
780 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
781 $src_left = $src_pos[0] - $this->w_tick;
782 $src_right = $src_pos[1] + $this->w_tick;
783 $dest_left = $dest_pos[0] - $this->w_tick;
784 $dest_right = $dest_pos[1] + $this->w_tick;
786 $d1 = abs($src_left - $dest_left);
787 $d2 = abs($src_right - $dest_left);
788 $d3 = abs($src_left - $dest_right);
789 $d4 = abs($src_right - $dest_right);
790 $d = min($d1, $d2, $d3, $d4);
792 if ($d == $d1) {
793 $this->x_src = $src_pos[0];
794 $this->src_dir = -1;
795 $this->x_dest = $dest_pos[0];
796 $this->dest_dir = -1;
797 } elseif ($d == $d2) {
798 $this->x_src = $src_pos[1];
799 $this->src_dir = 1;
800 $this->x_dest = $dest_pos[0];
801 $this->dest_dir = -1;
802 } elseif ($d == $d3) {
803 $this->x_src = $src_pos[0];
804 $this->src_dir = -1;
805 $this->x_dest = $dest_pos[1];
806 $this->dest_dir = 1;
807 } else {
808 $this->x_src = $src_pos[1];
809 $this->src_dir = 1;
810 $this->x_dest = $dest_pos[1];
811 $this->dest_dir = 1;
813 $this->y_src = $src_pos[2];
814 $this->y_dest = $dest_pos[2];
815 } // end of the "PMA_RT_Relation()" method
816 } // end of the "PMA_RT_Relation" class
818 * Draws and send the database schema
820 * @access public
821 * @see PMA_PDF
822 * @package phpMyAdmin
824 class PMA_RT {
826 * Defines private properties
828 var $tables = array();
829 var $relations = array();
830 var $ff = PMA_PDF_FONT;
831 var $x_max = 0;
832 var $y_max = 0;
833 var $scale;
834 var $x_min = 100000;
835 var $y_min = 100000;
836 var $t_marg = 10;
837 var $b_marg = 10;
838 var $l_marg = 10;
839 var $r_marg = 10;
840 var $tablewidth;
841 var $same_wide = 0;
844 * Sets X and Y minimum and maximum for a table cell
846 * @param string table The table name
847 * @access private
849 function PMA_RT_setMinMax($table)
851 $this->x_max = max($this->x_max, $table->x + $table->width);
852 $this->y_max = max($this->y_max, $table->y + $table->height);
853 $this->x_min = min($this->x_min, $table->x);
854 $this->y_min = min($this->y_min, $table->y);
855 } // end of the "PMA_RT_setMinMax()" method
857 * Defines relation objects
859 * @param string master_table The master table name
860 * @param string master_field The relation field in the master table
861 * @param string foreign_table The foreign table name
862 * @param string foreign_field The relation field in the foreign table
863 * @param boolean show_info Whether to display table position or not
864 * @access private
865 * @see PMA_RT_setMinMax
867 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field, $show_info)
869 if (!isset($this->tables[$master_table])) {
870 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth, false, $show_info);
871 $this->PMA_RT_setMinMax($this->tables[$master_table]);
873 if (!isset($this->tables[$foreign_table])) {
874 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth, false, $show_info);
875 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
877 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
878 } // end of the "PMA_RT_addRelation()" method
880 * Draws the grid
882 * @global object the current PMA_PDF instance
883 * @access private
884 * @see PMA_PDF
886 function PMA_RT_strokeGrid()
888 global $pdf;
890 $pdf->SetMargins(0, 0);
891 $pdf->SetDrawColor(200, 200, 200);
892 // Draws horizontal lines
893 for ($l = 0; $l < 21; $l++) {
894 $pdf->line(0, $l * 10, $pdf->getFh(), $l * 10);
895 // Avoid duplicates
896 if ($l > 0) {
897 $pdf->SetXY(0, $l * 10);
898 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
899 $pdf->Cell(5, 5, ' ' . $label);
900 } // end if
901 } // end for
902 // Draws vertical lines
903 for ($j = 0; $j < 30 ;$j++) {
904 $pdf->line($j * 10, 0, $j * 10, $pdf->getFw());
905 $pdf->SetXY($j * 10, 0);
906 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
907 $pdf->Cell(5, 7, $label);
908 } // end for
909 } // end of the "PMA_RT_strokeGrid()" method
911 * Draws relation arrows
913 * @param boolean change_color Whether to use one color per relation or not
914 * @access private
915 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
917 function PMA_RT_drawRelations($change_color)
919 $i = 0;
920 foreach ($this->relations AS $relation) {
921 $relation->PMA_RT_Relation_draw($change_color, $i);
922 $i++;
923 } // end while
924 } // end of the "PMA_RT_drawRelations()" method
926 * Draws tables
928 * @param boolean draw_color Whether to display table position or not
929 * @access private
930 * @see PMA_RT_Table::PMA_RT_Table_draw()
932 function PMA_RT_drawTables($draw_color = 0)
934 foreach ($this->tables AS $table) {
935 $table->PMA_RT_Table_draw($this->ff, $draw_color);
937 } // end of the "PMA_RT_drawTables()" method
939 * Ouputs the PDF document to a file
941 * @global object The current PDF document
942 * @global string The current database name
943 * @global integer The current page number (from the
944 * $cfg['Servers'][$i]['table_coords'] table)
945 * @access private
946 * @see PMA_PDF
948 function PMA_RT_showRt()
950 global $pdf, $db, $pdf_page_number, $cfgRelation;
952 $pdf->SetFontSize(14);
953 $pdf->SetLineWidth(0.2);
954 $pdf->SetDisplayMode('fullpage');
955 // Get the name of this pdfpage to use as filename (Mike Beck)
956 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
957 . ' WHERE page_nr = ' . $pdf_page_number;
958 $_name_rs = PMA_query_as_controluser($_name_sql);
959 if ($_name_rs) {
960 $_name_row = PMA_DBI_fetch_row($_name_rs);
961 $filename = $_name_row[0] . '.pdf';
963 // i don't know if there is a chance for this to happen, but rather be on the safe side:
964 if (empty($filename)) {
965 $filename = $pdf_page_number . '.pdf';
967 // $pdf->Output($db . '_' . $filename, TRUE);
968 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
969 } // end of the "PMA_RT_showRt()" method
971 * The "PMA_RT" constructor
973 * @param integer which_rel The page number to draw (from the
974 * $cfg['Servers'][$i]['table_coords'] table)
975 * @param boolean show_info Whether to display table position or not
976 * @param boolean change_color Was originally whether to use one color per
977 * relation or not, now enables/disables color
978 * everywhere, due to some problems printing with color
979 * @param boolean show_grid Whether to draw grids or not
980 * @param boolean all_tab_same_wide Whether all tables should have the same width or not
981 * @param boolean show_keys Wheter to show all field or only the keys
982 * @global object The current PDF document
983 * @global string The current db name
984 * @global array The relations settings
985 * @access private
986 * @see PMA_PDF
988 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)
990 global $pdf, $db, $cfgRelation, $with_doc;
992 $this->same_wide = $all_tab_same_wide;
993 // Initializes a new document
994 $pdf = new PMA_PDF('L', 'mm', $paper);
995 $pdf->SetTitle(sprintf(__('Schema of the %s database - Page %s'), $GLOBALS['db'], $which_rel));
996 $pdf->setCMargin(0);
997 $pdf->Open();
998 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
999 $pdf->AliasNbPages();
1000 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
1001 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
1002 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
1003 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
1004 $this->ff = PMA_PDF_FONT;
1005 $pdf->SetFont($this->ff, '', 14);
1006 $pdf->SetAutoPageBreak('auto');
1007 // Gets tables on this page
1008 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
1009 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1010 . ' AND pdf_page_number = ' . $which_rel;
1011 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
1012 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1013 $pdf->PMA_PDF_die(__('No tables'));
1014 // die('No tables');
1015 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1016 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1017 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1019 // make doc //
1020 if ($with_doc) {
1021 $pdf->SetAutoPageBreak('auto', 15);
1022 $pdf->setCMargin(1);
1023 PMA_RT_DOC($alltables);
1024 $pdf->SetAutoPageBreak('auto');
1025 $pdf->setCMargin(0);
1028 $pdf->Addpage();
1030 if ($with_doc) {
1031 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1032 $pdf->Bookmark(__('Relational schema'));
1033 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1034 $this->t_marg = 18;
1035 $this->b_marg = 18;
1038 /* snip */
1040 foreach ($alltables AS $table) {
1041 if (!isset($this->tables[$table])) {
1042 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys, $show_info);
1045 if ($this->same_wide) {
1046 $this->tables[$table]->width = $this->tablewidth;
1048 $this->PMA_RT_setMinMax($this->tables[$table]);
1050 // Defines the scale factor
1051 $this->scale = ceil(
1052 max(
1053 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1054 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1055 * 100) / 100;
1057 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1058 // Builds and save the PDF document
1059 $pdf->PMA_PDF_setLineWidthScale(0.1);
1061 if ($show_grid) {
1062 $pdf->SetFontSize(10);
1063 $this->PMA_RT_strokeGrid();
1065 $pdf->PMA_PDF_setFontSizeScale(14);
1066 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1067 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1068 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1069 // . ' AND master_table IN (' . $intable . ')'
1070 // . ' AND foreign_table IN (' . $intable . ')';
1071 // $result = PMA_query_as_controluser($sql);
1073 // previous logic was checking master tables and foreign tables
1074 // but I think that looping on every table of the pdf page as a master
1075 // and finding its foreigns is OK (then we can support innodb)
1076 $seen_a_relation = false;
1077 foreach ($alltables AS $one_table) {
1078 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1079 if ($exist_rel) {
1080 $seen_a_relation = true;
1081 foreach ($exist_rel AS $master_field => $rel) {
1082 // put the foreign table on the schema only if selected
1083 // by the user
1084 // (do not use array_search() because we would have to
1085 // to do a === FALSE and this is not PHP3 compatible)
1086 if (in_array($rel['foreign_table'], $alltables)) {
1087 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info);
1089 } // end while
1090 } // end if
1091 } // end while
1092 // also show tables without relations
1093 // $norelations = TRUE;
1094 // if ($result && PMA_DBI_num_rows($result) > 0) {
1095 // $norelations = FALSE;
1096 // while ($row = PMA_DBI_fetch_assoc($result)) {
1097 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1098 // }
1099 // }
1100 // if ($norelations == FALSE) {
1101 if ($seen_a_relation) {
1102 $this->PMA_RT_drawRelations($change_color);
1105 $this->PMA_RT_drawTables($change_color);
1107 $this->PMA_RT_showRt();
1108 } // end of the "PMA_RT()" method
1109 } // end of the "PMA_RT" class
1111 function PMA_RT_DOC($alltables)
1113 global $db, $pdf, $orientation, $paper;
1114 // TOC
1115 $pdf->addpage($GLOBALS['orientation']);
1116 $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
1117 $pdf->Ln(15);
1118 $i = 1;
1119 foreach ($alltables AS $table) {
1120 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1121 $pdf->SetX(10);
1122 // $pdf->Ln(1);
1123 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1124 $pdf->SetX(10);
1125 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1126 // $pdf->Ln(1);
1127 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1128 while ($row = PMA_DBI_fetch_assoc($result)) {
1129 $pdf->SetX(20);
1130 $field_name = $row['Field'];
1131 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1132 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1134 $lasttable = $table;
1135 $i++;
1137 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1138 $pdf->SetX(10);
1139 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1140 $pdf->SetX(10);
1141 $pdf->Cell(0, 6, $i + 1 . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1142 $z = 0;
1143 foreach ($alltables AS $table) {
1144 $z++;
1145 $pdf->addpage($GLOBALS['orientation']);
1146 $pdf->Bookmark($table);
1147 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1148 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1149 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1150 $pdf->SetFont('', 'B', 18);
1151 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1152 $pdf->SetFont('', '', 8);
1153 $pdf->ln();
1155 $cfgRelation = PMA_getRelationsParam();
1156 $comments = PMA_getComments($db, $table);
1157 if ($cfgRelation['mimework']) {
1158 $mime_map = PMA_getMIME($db, $table, true);
1162 * Gets table informations
1164 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1165 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1166 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1167 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1168 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1169 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1172 * Gets table keys and retains them
1174 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1175 $primary = '';
1176 $indexes = array();
1177 $lastIndex = '';
1178 $indexes_info = array();
1179 $indexes_data = array();
1180 $pk_array = array(); // will be use to emphasis prim. keys in the table
1181 // view
1182 while ($row = PMA_DBI_fetch_assoc($result)) {
1183 // Backups the list of primary keys
1184 if ($row['Key_name'] == 'PRIMARY') {
1185 $primary .= $row['Column_name'] . ', ';
1186 $pk_array[$row['Column_name']] = 1;
1188 // Retains keys informations
1189 if ($row['Key_name'] != $lastIndex) {
1190 $indexes[] = $row['Key_name'];
1191 $lastIndex = $row['Key_name'];
1193 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1194 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1195 if (isset($row['Cardinality'])) {
1196 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1198 // I don't know what does following column mean....
1199 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1200 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1202 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1203 if (isset($row['Sub_part'])) {
1204 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1206 } // end while
1207 if ($result) {
1208 PMA_DBI_free_result($result);
1212 * Gets fields properties
1214 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1215 $fields_cnt = PMA_DBI_num_rows($result);
1216 // Check if we can use Relations (Mike Beck)
1217 if (!empty($cfgRelation['relation'])) {
1218 // Find which tables are related with the current one and write it in
1219 // an array
1220 $res_rel = PMA_getForeigners($db, $table);
1222 if (count($res_rel) > 0) {
1223 $have_rel = true;
1224 } else {
1225 $have_rel = false;
1227 } else {
1228 $have_rel = false;
1229 } // end if
1231 * Displays the comments of the table if MySQL >= 3.23
1234 $break = false;
1235 if (!empty($show_comment)) {
1236 $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
1237 $break = true;
1240 if (!empty($create_time)) {
1241 $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
1242 $break = true;
1245 if (!empty($update_time)) {
1246 $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
1247 $break = true;
1250 if (!empty($check_time)) {
1251 $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
1252 $break = true;
1255 if ($break == true) {
1256 $pdf->Cell(0, 3, '', 0, 1);
1257 $pdf->Ln();
1260 $pdf->SetFont('', 'B');
1261 if (isset($orientation) && $orientation == 'L') {
1262 $pdf->Cell(25, 8, ucfirst(__('Column')), 1, 0, 'C');
1263 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1264 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1265 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1266 $pdf->Cell(20, 8, ucfirst(__('Default')), 1, 0, 'C');
1267 $pdf->Cell(25, 8, ucfirst(__('Extra')), 1, 0, 'C');
1268 $pdf->Cell(45, 8, ucfirst(__('Links to')), 1, 0, 'C');
1270 if ($paper == 'A4') {
1271 $comments_width = 67;
1272 } else {
1273 // this is really intended for 'letter'
1275 * @todo find optimal width for all formats
1277 $comments_width = 50;
1279 $pdf->Cell($comments_width, 8, ucfirst(__('Comments')), 1, 0, 'C');
1280 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1281 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1282 } else {
1283 $pdf->Cell(20, 8, ucfirst(__('Column')), 1, 0, 'C');
1284 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1285 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1286 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1287 $pdf->Cell(15, 8, ucfirst(__('Default')), 1, 0, 'C');
1288 $pdf->Cell(15, 8, ucfirst(__('Extra')), 1, 0, 'C');
1289 $pdf->Cell(30, 8, ucfirst(__('Links to')), 1, 0, 'C');
1290 $pdf->Cell(30, 8, ucfirst(__('Comments')), 1, 0, 'C');
1291 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1292 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1294 $pdf->SetFont('', '');
1296 while ($row = PMA_DBI_fetch_assoc($result)) {
1297 $type = $row['Type'];
1298 // reformat mysql query output
1299 // set or enum types: slashes single quotes inside options
1300 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1301 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1302 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1303 $type_nowrap = '';
1305 $binary = 0;
1306 $unsigned = 0;
1307 $zerofill = 0;
1308 } else {
1309 $type_nowrap = ' nowrap="nowrap"';
1310 $type = preg_replace('@BINARY@i', '', $type);
1311 $type = preg_replace('@ZEROFILL@i', '', $type);
1312 $type = preg_replace('@UNSIGNED@i', '', $type);
1313 if (empty($type)) {
1314 $type = '&nbsp;';
1317 $binary = stristr($row['Type'], 'BINARY');
1318 $unsigned = stristr($row['Type'], 'UNSIGNED');
1319 $zerofill = stristr($row['Type'], 'ZEROFILL');
1321 $attribute = ' ';
1322 if ($binary) {
1323 $attribute = 'BINARY';
1325 if ($unsigned) {
1326 $attribute = 'UNSIGNED';
1328 if ($zerofill) {
1329 $attribute = 'UNSIGNED ZEROFILL';
1331 if (!isset($row['Default'])) {
1332 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1333 $row['Default'] = 'NULL';
1336 $field_name = $row['Field'];
1337 // $pdf->Ln();
1338 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1339 $pdf->Bookmark($field_name, 1, -1);
1340 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1341 $pdf_row = array($field_name,
1342 $type,
1343 $attribute,
1344 ($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes'),
1345 ((isset($row['Default'])) ? $row['Default'] : ''),
1346 $row['Extra'],
1347 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1348 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1349 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1351 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1352 if (isset($res_rel[$field_name]['foreign_table']) AND
1353 isset($res_rel[$field_name]['foreign_field']) AND
1354 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1357 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1358 } else {
1359 unset($links[6]);
1361 $pdf->Row($pdf_row, $links);
1363 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1364 //echo ' ' . $field_name . '&nbsp;' . "\n";
1366 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1367 $pdf->Cell(20, 8, $attribute, 1, 0, 'L');
1368 $pdf->Cell(15, 8, , 1, 0, 'L');
1369 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1370 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1371 if ($have_rel) {
1372 if (isset($res_rel[$field_name])) {
1373 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1376 if ($cfgRelation['commwork']) {
1377 if (isset($comments[$field_name])) {
1378 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1380 } */
1381 } // end while
1382 $pdf->SetFont('', '', 14);
1383 PMA_DBI_free_result($result);
1384 } //end each
1385 } // end function PMA_RT_DOC
1388 * Main logic
1390 if (!isset($pdf_page_number)) {
1391 $pdf_page_number = 1;
1394 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1395 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1396 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1397 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1398 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1399 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1400 $paper = isset($paper) ? $paper : 'A4';
1401 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1402 PMA_DBI_select_db($db);
1404 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);