Translation update done using Pootle.
[phpmyadmin/crack.git] / pdf_schema.php
blob097979209dbe6a3525166cb82a9ac5c815938f7f
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/relation.lib.php';
17 require_once './libraries/transformations.lib.php';
18 require_once './libraries/Index.class.php';
20 $cfgRelation = PMA_getRelationsParam();
22 /**
23 * Now in ./libraries/relation.lib.php we check for all tables
24 * that we need, but if we don't find them we are quiet about it
25 * so people can work without.
26 * This page is absolutely useless if you didn't set up your tables
27 * correctly, so it is a good place to see which tables we can and
28 * complain ;-)
30 if (!$cfgRelation['pdfwork']) {
31 echo '<font color="red">' . __('Error') . '</font><br />' . "\n";
32 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
33 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";
36 /**
37 * Font used in PDF.
39 * @todo Make this configuratble (at least Sans/Serif).
41 define('PMA_PDF_FONT', 'DejaVuSans');
42 require_once './libraries/tcpdf/tcpdf.php';
44 /**
45 * Extends the "FPDF" class and prepares the work
47 * @access public
48 * @see FPDF
49 * @package phpMyAdmin
51 class PMA_PDF extends TCPDF {
52 /**
53 * Defines private properties
55 var $x_min;
56 var $y_min;
57 var $l_marg = 10;
58 var $t_marg = 10;
59 var $scale;
60 var $PMA_links;
61 var $Outlines = array();
62 var $def_outlines;
63 var $Alias = array();
64 var $widths;
66 public function getFh()
68 return $this->fh;
71 public function getFw()
73 return $this->fw;
76 public function setCMargin($c_margin)
78 $this->cMargin = $c_margin;
81 function SetAlias($name, $value)
83 $this->Alias[$name] = $value ;
86 function _putpages()
88 if (count($this->Alias) > 0) {
89 $nb = $this->page;
90 foreach ($this->Alias AS $alias => $value) {
91 for ($n = 1;$n <= $nb;$n++)
92 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
95 parent::_putpages();
98 /**
99 * Sets the scaling factor, defines minimum coordinates and margins
101 * @param float scale The scaling factor
102 * @param float x_min The minimum X coordinate
103 * @param float y_min The minimum Y coordinate
104 * @param float l_marg The left margin
105 * @param float t_marg The top margin
106 * @access public
108 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
110 $this->scale = $scale;
111 $this->x_min = $x_min;
112 $this->y_min = $y_min;
113 if ($this->l_marg != -1) {
114 $this->l_marg = $l_marg;
116 if ($this->t_marg != -1) {
117 $this->t_marg = $t_marg;
119 } // end of the "PMA_PDF_setScale" function
121 * Outputs a scaled cell
123 * @param float w The cell width
124 * @param float h The cell height
125 * @param string txt The text to output
126 * @param mixed border Whether to add borders or not
127 * @param integer ln Where to put the cursor once the output is done
128 * @param string align Align mode
129 * @param integer fill Whether to fill the cell with a color or not
130 * @access public
131 * @see FPDF::Cell()
133 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
135 $h = $h / $this->scale;
136 $w = $w / $this->scale;
137 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
138 } // end of the "PMA_PDF_cellScale" function
140 * Draws a scaled line
142 * @param float x1 The horizontal position of the starting point
143 * @param float y1 The vertical position of the starting point
144 * @param float x2 The horizontal position of the ending point
145 * @param float y2 The vertical position of the ending point
146 * @access public
147 * @see FPDF::Line()
149 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
151 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
152 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
153 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
154 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
155 $this->Line($x1, $y1, $x2, $y2);
156 } // end of the "PMA_PDF_lineScale" function
158 * Sets x and y scaled positions
160 * @param float x The x position
161 * @param float y The y position
162 * @access public
163 * @see FPDF::SetXY()
165 function PMA_PDF_setXyScale($x, $y)
167 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
168 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
169 $this->SetXY($x, $y);
170 } // end of the "PMA_PDF_setXyScale" function
172 * Sets the X scaled positions
174 * @param float x The x position
175 * @access public
176 * @see FPDF::SetX()
178 function PMA_PDF_setXScale($x)
180 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
181 $this->SetX($x);
182 } // end of the "PMA_PDF_setXScale" function
184 * Sets the scaled font size
186 * @param float size The font size (in points)
187 * @access public
188 * @see FPDF::SetFontSize()
190 function PMA_PDF_setFontSizeScale($size)
192 // Set font size in points
193 $size = $size / $this->scale;
194 $this->SetFontSize($size);
195 } // end of the "PMA_PDF_setFontSizeScale" function
197 * Sets the scaled line width
199 * @param float width The line width
200 * @access public
201 * @see FPDF::SetLineWidth()
203 function PMA_PDF_setLineWidthScale($width)
205 $width = $width / $this->scale;
206 $this->SetLineWidth($width);
207 } // end of the "PMA_PDF_setLineWidthScale" function
209 * Displays an error message
211 * @param string error_message the error mesage
212 * @global array the PMA configuration array
213 * @global integer the current server id
214 * @global string the current language
215 * @global string the charset to convert to
216 * @global string the current database name
217 * @global string the current charset
218 * @global string the current text direction
219 * @global string a localized string
220 * @global string an other localized string
221 * @access public
223 function PMA_PDF_die($error_message = '')
225 global $cfg;
226 global $server, $lang, $db;
227 global $charset, $text_dir;
229 require_once './libraries/header.inc.php';
231 echo '<p><strong>PDF - ' . __('Error') . '</strong></p>' . "\n";
232 if (!empty($error_message)) {
233 $error_message = htmlspecialchars($error_message);
235 echo '<p>' . "\n";
236 echo ' ' . $error_message . "\n";
237 echo '</p>' . "\n";
239 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
240 . '">' . __('Back') . '</a>';
241 echo "\n";
243 require_once './libraries/footer.inc.php';
244 } // end of the "PMA_PDF_die()" function
246 * Aliases the "Error()" function from the FPDF class to the
247 * "PMA_PDF_die()" one
249 * @param string error_message the error mesage
250 * @access public
251 * @see PMA_PDF_die
253 function Error($error_message = '')
255 $this->PMA_PDF_die($error_message);
256 } // end of the "Error()" method
257 function Header()
259 // We only show this if we find something in the new pdf_pages table
261 // This function must be named "Header" to work with the FPDF library
262 global $cfgRelation, $db, $pdf_page_number, $with_doc;
263 if ($with_doc) {
264 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
265 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
266 . ' AND page_nr = \'' . $pdf_page_number . '\'';
267 $test_rs = PMA_query_as_controluser($test_query);
268 $pages = @PMA_DBI_fetch_assoc($test_rs);
269 $this->SetFont('', 'B', 14);
270 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
271 $this->SetFont('', '');
272 $this->Ln();
275 function Footer()
277 // This function must be named "Footer" to work with the FPDF library
278 global $with_doc;
279 if ($with_doc) {
280 $this->SetY(-15);
281 $this->SetFont('', '', 14);
282 $this->Cell(0, 6, __('Page number:') . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
283 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
284 $this->SetY(20);
287 function Bookmark($txt, $level = 0, $y = 0)
289 // Add a bookmark
290 $this->Outlines[0][] = $level;
291 $this->Outlines[1][] = $txt;
292 $this->Outlines[2][] = $this->page;
293 if ($y == -1) {
294 $y = $this->GetY();
296 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
299 function _putbookmarks()
301 if (count($this->Outlines) > 0) {
302 // Save object number
303 $memo_n = $this->n;
304 // Take the number of sub elements for an outline
305 $nb_outlines = sizeof($this->Outlines[0]);
306 $first_level = array();
307 $parent = array();
308 $parent[0] = 1;
309 for ($i = 0; $i < $nb_outlines; $i++) {
310 $level = $this->Outlines[0][$i];
311 $kids = 0;
312 $last = -1;
313 $prev = -1;
314 $next = -1;
315 if ($i > 0) {
316 $cursor = $i-1;
317 // Take the previous outline in the same level
318 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
319 $cursor--;
320 if ($this->Outlines[0][$cursor] == $level) {
321 $prev = $cursor;
324 if ($i < $nb_outlines-1) {
325 $cursor = $i + 1;
326 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
327 // Take the immediate kid in level + 1
328 if ($this->Outlines[0][$cursor] == $level + 1) {
329 $kids++;
330 $last = $cursor;
332 $cursor++;
334 $cursor = $i + 1;
335 // Take the next outline in the same level
336 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
337 $cursor++;
338 if ($this->Outlines[0][$cursor] == $level) {
339 $next = $cursor;
342 $this->_newobj();
343 $parent[$level + 1] = $this->n;
344 if ($level == 0) {
345 $first_level[] = $this->n;
347 $this->_out('<<');
348 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
349 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
350 if ($prev != -1) {
351 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
353 if ($next != -1) {
354 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
356 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
357 if ($kids > 0) {
358 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
359 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
360 $this->_out('/Count -' . $kids);
362 $this->_out('>>');
363 $this->_out('endobj');
365 // First page of outlines
366 $this->_newobj();
367 $this->def_outlines = $this->n;
368 $this->_out('<<');
369 $this->_out('/Type');
370 $this->_out('/Outlines');
371 $this->_out('/First ' . $first_level[0] . ' 0 R');
372 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
373 $this->_out('/Count ' . sizeof($first_level));
374 $this->_out('>>');
375 $this->_out('endobj');
379 function _putresources()
381 parent::_putresources();
382 $this->_putbookmarks();
385 function _putcatalog()
387 parent::_putcatalog();
388 if (count($this->Outlines) > 0) {
389 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
390 $this->_out('/PageMode /UseOutlines');
393 function SetWidths($w)
395 // column widths
396 $this->widths = $w;
399 function Row($data, $links)
401 // line height
402 $nb = 0;
403 $data_cnt = count($data);
404 for ($i = 0;$i < $data_cnt;$i++)
405 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
406 $il = $this->FontSize;
407 $h = ($il + 1) * $nb;
408 // page break if necessary
409 $this->CheckPageBreak($h);
410 // draw the cells
411 $data_cnt = count($data);
412 for ($i = 0;$i < $data_cnt;$i++) {
413 $w = $this->widths[$i];
414 // save current position
415 $x = $this->GetX();
416 $y = $this->GetY();
417 // draw the border
418 $this->Rect($x, $y, $w, $h);
419 if (isset($links[$i])) {
420 $this->Link($x, $y, $w, $h, $links[$i]);
422 // print text
423 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
424 // go to right side
425 $this->SetXY($x + $w, $y);
427 // go to line
428 $this->Ln($h);
431 function CheckPageBreak($h)
433 // if height h overflows, manual page break
434 if ($this->GetY() + $h > $this->PageBreakTrigger) {
435 $this->AddPage($this->CurOrientation);
439 function NbLines($w, $txt)
441 // compute number of lines used by a multicell of width w
442 $cw = &$this->CurrentFont['cw'];
443 if ($w == 0) {
444 $w = $this->w - $this->rMargin - $this->x;
446 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
447 $s = str_replace("\r", '', $txt);
448 $nb = strlen($s);
449 if ($nb > 0 and $s[$nb-1] == "\n") {
450 $nb--;
452 $sep = -1;
453 $i = 0;
454 $j = 0;
455 $l = 0;
456 $nl = 1;
457 while ($i < $nb) {
458 $c = $s[$i];
459 if ($c == "\n") {
460 $i++;
461 $sep = -1;
462 $j = $i;
463 $l = 0;
464 $nl++;
465 continue;
467 if ($c == ' ') {
468 $sep = $i;
470 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
471 if ($l > $wmax) {
472 if ($sep == -1) {
473 if ($i == $j) {
474 $i++;
476 } else {
477 $i = $sep + 1;
479 $sep = -1;
480 $j = $i;
481 $l = 0;
482 $nl++;
483 } else {
484 $i++;
487 return $nl;
489 } // end of the "PMA_PDF" class
493 * Draws tables schema
495 * @access private
496 * @see PMA_RT
497 * @package phpMyAdmin
499 class PMA_RT_Table {
501 * Defines private properties
503 var $nb_fiels;
504 var $table_name;
505 var $width = 0;
506 var $height;
507 var $fields = array();
508 var $height_cell = 6;
509 var $x, $y;
510 var $primary = array();
511 var $show_info = false;
514 * Returns title of the current table,
515 * title can have the dimensions of the table
517 * @access private
519 function getTitle()
521 return ($this->show_info ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) : '') . ' ' . $this->table_name;
522 } // end of the "getTitle" function
524 * Sets the width of the table
526 * @param integer ff The font size
527 * @global object The current PDF document
528 * @access private
529 * @see PMA_PDF
531 function PMA_RT_Table_setWidth($ff)
533 global $pdf;
535 foreach ($this->fields AS $field) {
536 $this->width = max($this->width, $pdf->GetStringWidth($field));
538 $this->width += $pdf->GetStringWidth(' ');
539 $pdf->SetFont($ff, 'B');
540 // it is unknown what value must be added, because
541 // table title is affected by the tabe width value
542 while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
543 $this->width += 5;
545 $pdf->SetFont($ff, '');
546 } // end of the "PMA_RT_Table_setWidth()" method
548 * Sets the height of the table
550 * @access private
552 function PMA_RT_Table_setHeight()
554 $this->height = (count($this->fields) + 1) * $this->height_cell;
555 } // end of the "PMA_RT_Table_setHeight()" method
557 * Do draw the table
559 * @param integer ff The font size
560 * @param boolean setcolortWhether to display color
561 * @global object The current PDF document
562 * @access private
563 * @see PMA_PDF
565 function PMA_RT_Table_draw($ff, $setcolor = 0)
567 global $pdf, $with_doc;
569 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
570 $pdf->SetFont($ff, 'B');
571 if ($setcolor) {
572 $pdf->SetTextColor(200);
573 $pdf->SetFillColor(0, 0, 128);
575 if ($with_doc) {
576 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
577 } else {
578 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
581 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->getTitle(), 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
582 $pdf->PMA_PDF_setXScale($this->x);
583 $pdf->SetFont($ff, '');
584 $pdf->SetTextColor(0);
585 $pdf->SetFillColor(255);
587 foreach ($this->fields AS $field) {
588 if ($setcolor) {
589 if (in_array($field, $this->primary)) {
590 $pdf->SetFillColor(215, 121, 123);
592 if ($field == $this->displayfield) {
593 $pdf->SetFillColor(142, 159, 224);
596 if ($with_doc) {
597 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
598 } else {
599 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
602 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
603 $pdf->PMA_PDF_setXScale($this->x);
604 $pdf->SetFillColor(255);
605 } // end while
606 /*if ($pdf->PageNo() > 1) {
607 $pdf->PMA_PDF_die(__('The scale factor is too small to fit the schema on one page'));
608 } */
609 } // end of the "PMA_RT_Table_draw()" method
611 * The "PMA_RT_Table" constructor
613 * @param string table_name The table name
614 * @param integer ff The font size
615 * @param integer same_width The max. with among tables
616 * @param boolean show_keys Whether to display keys or not
617 * @param boolean show_info Whether to display table position or not
618 * @global object The current PDF document
619 * @global integer The current page number (from the
620 * $cfg['Servers'][$i]['table_coords'] table)
621 * @global array The relations settings
622 * @global string The current db name
623 * @access private
624 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
625 PMA_RT_Table::PMA_RT_Table_setHeight
627 function __construct($table_name, $ff, &$same_wide_width, $show_keys = false, $show_info = false)
629 global $pdf, $pdf_page_number, $cfgRelation, $db;
631 $this->table_name = $table_name;
632 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
633 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
634 if (!$result || !PMA_DBI_num_rows($result)) {
635 $pdf->PMA_PDF_die(sprintf(__('The %s table doesn\'t exist!'), $table_name));
637 // load fields
638 //check to see if it will load all fields or only the foreign keys
639 if ($show_keys) {
640 $indexes = PMA_Index::getFromTable($this->table_name, $db);
641 $all_columns = array();
642 foreach ($indexes as $index) {
643 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
645 $this->fields = array_keys($all_columns);
646 } else {
647 while ($row = PMA_DBI_fetch_row($result)) {
648 $this->fields[] = $row[0];
652 $this->show_info = $show_info;
654 // height and width
655 $this->PMA_RT_Table_setHeight();
656 // setWidth must me after setHeight, because title
657 // can include table height which changes table width
658 $this->PMA_RT_Table_setWidth($ff);
659 if ($same_wide_width < $this->width) {
660 $same_wide_width = $this->width;
662 // x and y
663 $sql = 'SELECT x, y FROM '
664 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
665 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
666 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
667 . ' AND pdf_page_number = ' . $pdf_page_number;
668 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
670 if (!$result || !PMA_DBI_num_rows($result)) {
671 $pdf->PMA_PDF_die(sprintf(__('Please configure the coordinates for table %s'), $table_name));
673 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
674 $this->x = (double) $this->x;
675 $this->y = (double) $this->y;
676 // displayfield
677 $this->displayfield = PMA_getDisplayField($db, $table_name);
678 // index
679 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
680 if (PMA_DBI_num_rows($result) > 0) {
681 while ($row = PMA_DBI_fetch_assoc($result)) {
682 if ($row['Key_name'] == 'PRIMARY') {
683 $this->primary[] = $row['Column_name'];
686 } // end if
687 } // end of the "PMA_RT_Table()" method
688 } // end class "PMA_RT_Table"
690 * Draws relation links
692 * @access private
693 * @see PMA_RT
694 * @package phpMyAdmin
696 class PMA_RT_Relation {
698 * Defines private properties
700 var $x_src, $y_src;
701 var $src_dir ;
702 var $dest_dir;
703 var $x_dest, $y_dest;
704 var $w_tick = 5;
707 * Gets arrows coordinates
709 * @param string table The current table name
710 * @param string column The relation column name
711 * @return array Arrows coordinates
712 * @access private
714 function PMA_RT_Relation_getXy($table, $column)
716 $pos = array_search($column, $table->fields);
717 // x_left, x_right, y
718 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
719 } // end of the "PMA_RT_Relation_getXy()" method
721 * Do draws relation links
723 * @param boolean change_color Whether to use one color per relation or not
724 * @param integer i The id of the link to draw
725 * @global object The current PDF document
726 * @access private
727 * @see PMA_PDF
729 function PMA_RT_Relation_draw($change_color, $i)
731 global $pdf;
733 if ($change_color) {
734 $d = $i % 6;
735 $j = ($i - $d) / 6;
736 $j = $j % 4;
737 $j++;
738 $case = array(
739 array(1, 0, 0),
740 array(0, 1, 0),
741 array(0, 0, 1),
742 array(1, 1, 0),
743 array(1, 0, 1),
744 array(0, 1, 1)
746 list ($a, $b, $c) = $case[$d];
747 $e = (1 - ($j - 1) / 6);
748 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
749 } else {
750 $pdf->SetDrawColor(0);
751 } // end if... else...
752 $pdf->PMA_PDF_setLineWidthScale(0.2);
753 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
754 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
755 $pdf->PMA_PDF_setLineWidthScale(0.1);
756 $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);
757 // arrow
758 $root2 = 2 * sqrt(2);
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);
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);
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->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->SetDrawColor(0);
765 } // end of the "PMA_RT_Relation_draw()" method
767 * The "PMA_RT_Relation" constructor
769 * @param string master_table The master table name
770 * @param string master_field The relation field in the master table
771 * @param string foreign_table The foreign table name
772 * @param string foreigh_field The relation field in the foreign table
773 * @access private
774 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
776 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
778 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
779 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
780 $src_left = $src_pos[0] - $this->w_tick;
781 $src_right = $src_pos[1] + $this->w_tick;
782 $dest_left = $dest_pos[0] - $this->w_tick;
783 $dest_right = $dest_pos[1] + $this->w_tick;
785 $d1 = abs($src_left - $dest_left);
786 $d2 = abs($src_right - $dest_left);
787 $d3 = abs($src_left - $dest_right);
788 $d4 = abs($src_right - $dest_right);
789 $d = min($d1, $d2, $d3, $d4);
791 if ($d == $d1) {
792 $this->x_src = $src_pos[0];
793 $this->src_dir = -1;
794 $this->x_dest = $dest_pos[0];
795 $this->dest_dir = -1;
796 } elseif ($d == $d2) {
797 $this->x_src = $src_pos[1];
798 $this->src_dir = 1;
799 $this->x_dest = $dest_pos[0];
800 $this->dest_dir = -1;
801 } elseif ($d == $d3) {
802 $this->x_src = $src_pos[0];
803 $this->src_dir = -1;
804 $this->x_dest = $dest_pos[1];
805 $this->dest_dir = 1;
806 } else {
807 $this->x_src = $src_pos[1];
808 $this->src_dir = 1;
809 $this->x_dest = $dest_pos[1];
810 $this->dest_dir = 1;
812 $this->y_src = $src_pos[2];
813 $this->y_dest = $dest_pos[2];
814 } // end of the "PMA_RT_Relation()" method
815 } // end of the "PMA_RT_Relation" class
817 * Draws and send the database schema
819 * @access public
820 * @see PMA_PDF
821 * @package phpMyAdmin
823 class PMA_RT {
825 * Defines private properties
827 var $tables = array();
828 var $relations = array();
829 var $ff = PMA_PDF_FONT;
830 var $x_max = 0;
831 var $y_max = 0;
832 var $scale;
833 var $x_min = 100000;
834 var $y_min = 100000;
835 var $t_marg = 10;
836 var $b_marg = 10;
837 var $l_marg = 10;
838 var $r_marg = 10;
839 var $tablewidth;
840 var $same_wide = 0;
843 * Sets X and Y minimum and maximum for a table cell
845 * @param string table The table name
846 * @access private
848 function PMA_RT_setMinMax($table)
850 $this->x_max = max($this->x_max, $table->x + $table->width);
851 $this->y_max = max($this->y_max, $table->y + $table->height);
852 $this->x_min = min($this->x_min, $table->x);
853 $this->y_min = min($this->y_min, $table->y);
854 } // end of the "PMA_RT_setMinMax()" method
856 * Defines relation objects
858 * @param string master_table The master table name
859 * @param string master_field The relation field in the master table
860 * @param string foreign_table The foreign table name
861 * @param string foreign_field The relation field in the foreign table
862 * @param boolean show_info Whether to display table position or not
863 * @access private
864 * @see PMA_RT_setMinMax
866 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field, $show_info)
868 if (!isset($this->tables[$master_table])) {
869 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth, false, $show_info);
870 $this->PMA_RT_setMinMax($this->tables[$master_table]);
872 if (!isset($this->tables[$foreign_table])) {
873 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth, false, $show_info);
874 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
876 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
877 } // end of the "PMA_RT_addRelation()" method
879 * Draws the grid
881 * @global object the current PMA_PDF instance
882 * @access private
883 * @see PMA_PDF
885 function PMA_RT_strokeGrid()
887 global $pdf;
889 $pdf->SetMargins(0, 0);
890 $pdf->SetDrawColor(200, 200, 200);
891 // Draws horizontal lines
892 for ($l = 0; $l < 21; $l++) {
893 $pdf->line(0, $l * 10, $pdf->getFh(), $l * 10);
894 // Avoid duplicates
895 if ($l > 0) {
896 $pdf->SetXY(0, $l * 10);
897 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
898 $pdf->Cell(5, 5, ' ' . $label);
899 } // end if
900 } // end for
901 // Draws vertical lines
902 for ($j = 0; $j < 30 ;$j++) {
903 $pdf->line($j * 10, 0, $j * 10, $pdf->getFw());
904 $pdf->SetXY($j * 10, 0);
905 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
906 $pdf->Cell(5, 7, $label);
907 } // end for
908 } // end of the "PMA_RT_strokeGrid()" method
910 * Draws relation arrows
912 * @param boolean change_color Whether to use one color per relation or not
913 * @access private
914 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
916 function PMA_RT_drawRelations($change_color)
918 $i = 0;
919 foreach ($this->relations AS $relation) {
920 $relation->PMA_RT_Relation_draw($change_color, $i);
921 $i++;
922 } // end while
923 } // end of the "PMA_RT_drawRelations()" method
925 * Draws tables
927 * @param boolean draw_color Whether to display table position or not
928 * @access private
929 * @see PMA_RT_Table::PMA_RT_Table_draw()
931 function PMA_RT_drawTables($draw_color = 0)
933 foreach ($this->tables AS $table) {
934 $table->PMA_RT_Table_draw($this->ff, $draw_color);
936 } // end of the "PMA_RT_drawTables()" method
938 * Ouputs the PDF document to a file
940 * @global object The current PDF document
941 * @global string The current database name
942 * @global integer The current page number (from the
943 * $cfg['Servers'][$i]['table_coords'] table)
944 * @access private
945 * @see PMA_PDF
947 function PMA_RT_showRt()
949 global $pdf, $db, $pdf_page_number, $cfgRelation;
951 $pdf->SetFontSize(14);
952 $pdf->SetLineWidth(0.2);
953 $pdf->SetDisplayMode('fullpage');
954 // Get the name of this pdfpage to use as filename (Mike Beck)
955 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
956 . ' WHERE page_nr = ' . $pdf_page_number;
957 $_name_rs = PMA_query_as_controluser($_name_sql);
958 if ($_name_rs) {
959 $_name_row = PMA_DBI_fetch_row($_name_rs);
960 $filename = $_name_row[0] . '.pdf';
962 // i don't know if there is a chance for this to happen, but rather be on the safe side:
963 if (empty($filename)) {
964 $filename = $pdf_page_number . '.pdf';
966 // $pdf->Output($db . '_' . $filename, TRUE);
967 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
968 } // end of the "PMA_RT_showRt()" method
970 * The "PMA_RT" constructor
972 * @param integer which_rel The page number to draw (from the
973 * $cfg['Servers'][$i]['table_coords'] table)
974 * @param boolean show_info Whether to display table position or not
975 * @param boolean change_color Was originally whether to use one color per
976 * relation or not, now enables/disables color
977 * everywhere, due to some problems printing with color
978 * @param boolean show_grid Whether to draw grids or not
979 * @param boolean all_tab_same_wide Whether all tables should have the same width or not
980 * @param boolean show_keys Wheter to show all field or only the keys
981 * @global object The current PDF document
982 * @global string The current db name
983 * @global array The relations settings
984 * @access private
985 * @see PMA_PDF
987 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)
989 global $pdf, $db, $cfgRelation, $with_doc;
991 $this->same_wide = $all_tab_same_wide;
992 // Initializes a new document
993 $pdf = new PMA_PDF('L', 'mm', $paper);
994 $pdf->SetTitle(sprintf(__('Schema of the %s database - Page %s'), $GLOBALS['db'], $which_rel));
995 $pdf->setCMargin(0);
996 $pdf->Open();
997 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
998 $pdf->AliasNbPages();
999 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
1000 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
1001 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
1002 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
1003 $this->ff = PMA_PDF_FONT;
1004 $pdf->SetFont($this->ff, '', 14);
1005 $pdf->SetAutoPageBreak('auto');
1006 // Gets tables on this page
1007 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
1008 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1009 . ' AND pdf_page_number = ' . $which_rel;
1010 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
1011 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1012 $pdf->PMA_PDF_die(__('No tables'));
1013 // die('No tables');
1014 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1015 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1016 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1018 // make doc //
1019 if ($with_doc) {
1020 $pdf->SetAutoPageBreak('auto', 15);
1021 $pdf->setCMargin(1);
1022 PMA_RT_DOC($alltables);
1023 $pdf->SetAutoPageBreak('auto');
1024 $pdf->setCMargin(0);
1027 $pdf->Addpage();
1029 if ($with_doc) {
1030 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1031 $pdf->Bookmark(__('Relational schema'));
1032 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1033 $this->t_marg = 18;
1034 $this->b_marg = 18;
1037 /* snip */
1039 foreach ($alltables AS $table) {
1040 if (!isset($this->tables[$table])) {
1041 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys, $show_info);
1044 if ($this->same_wide) {
1045 $this->tables[$table]->width = $this->tablewidth;
1047 $this->PMA_RT_setMinMax($this->tables[$table]);
1049 // Defines the scale factor
1050 $this->scale = ceil(
1051 max(
1052 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
1053 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
1054 * 100) / 100;
1056 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1057 // Builds and save the PDF document
1058 $pdf->PMA_PDF_setLineWidthScale(0.1);
1060 if ($show_grid) {
1061 $pdf->SetFontSize(10);
1062 $this->PMA_RT_strokeGrid();
1064 $pdf->PMA_PDF_setFontSizeScale(14);
1065 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1066 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1067 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1068 // . ' AND master_table IN (' . $intable . ')'
1069 // . ' AND foreign_table IN (' . $intable . ')';
1070 // $result = PMA_query_as_controluser($sql);
1072 // previous logic was checking master tables and foreign tables
1073 // but I think that looping on every table of the pdf page as a master
1074 // and finding its foreigns is OK (then we can support innodb)
1075 $seen_a_relation = false;
1076 foreach ($alltables AS $one_table) {
1077 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1078 if ($exist_rel) {
1079 $seen_a_relation = true;
1080 foreach ($exist_rel AS $master_field => $rel) {
1081 // put the foreign table on the schema only if selected
1082 // by the user
1083 // (do not use array_search() because we would have to
1084 // to do a === FALSE and this is not PHP3 compatible)
1085 if (in_array($rel['foreign_table'], $alltables)) {
1086 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info);
1088 } // end while
1089 } // end if
1090 } // end while
1091 // also show tables without relations
1092 // $norelations = TRUE;
1093 // if ($result && PMA_DBI_num_rows($result) > 0) {
1094 // $norelations = FALSE;
1095 // while ($row = PMA_DBI_fetch_assoc($result)) {
1096 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1097 // }
1098 // }
1099 // if ($norelations == FALSE) {
1100 if ($seen_a_relation) {
1101 $this->PMA_RT_drawRelations($change_color);
1104 $this->PMA_RT_drawTables($change_color);
1106 $this->PMA_RT_showRt();
1107 } // end of the "PMA_RT()" method
1108 } // end of the "PMA_RT" class
1110 function PMA_RT_DOC($alltables)
1112 global $db, $pdf, $orientation, $paper;
1113 // TOC
1114 $pdf->addpage($GLOBALS['orientation']);
1115 $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
1116 $pdf->Ln(15);
1117 $i = 1;
1118 foreach ($alltables AS $table) {
1119 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1120 $pdf->SetX(10);
1121 // $pdf->Ln(1);
1122 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1123 $pdf->SetX(10);
1124 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1125 // $pdf->Ln(1);
1126 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1127 while ($row = PMA_DBI_fetch_assoc($result)) {
1128 $pdf->SetX(20);
1129 $field_name = $row['Field'];
1130 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1131 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1133 $lasttable = $table;
1134 $i++;
1136 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1137 $pdf->SetX(10);
1138 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1139 $pdf->SetX(10);
1140 $pdf->Cell(0, 6, $i + 1 . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1141 $z = 0;
1142 foreach ($alltables AS $table) {
1143 $z++;
1144 $pdf->addpage($GLOBALS['orientation']);
1145 $pdf->Bookmark($table);
1146 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1147 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1148 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1149 $pdf->SetFont('', 'B', 18);
1150 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1151 $pdf->SetFont('', '', 8);
1152 $pdf->ln();
1154 $cfgRelation = PMA_getRelationsParam();
1155 $comments = PMA_getComments($db, $table);
1156 if ($cfgRelation['mimework']) {
1157 $mime_map = PMA_getMIME($db, $table, true);
1161 * Gets table informations
1163 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1164 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1165 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1166 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1167 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1168 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1171 * Gets table keys and retains them
1173 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1174 $primary = '';
1175 $indexes = array();
1176 $lastIndex = '';
1177 $indexes_info = array();
1178 $indexes_data = array();
1179 $pk_array = array(); // will be use to emphasis prim. keys in the table
1180 // view
1181 while ($row = PMA_DBI_fetch_assoc($result)) {
1182 // Backups the list of primary keys
1183 if ($row['Key_name'] == 'PRIMARY') {
1184 $primary .= $row['Column_name'] . ', ';
1185 $pk_array[$row['Column_name']] = 1;
1187 // Retains keys informations
1188 if ($row['Key_name'] != $lastIndex) {
1189 $indexes[] = $row['Key_name'];
1190 $lastIndex = $row['Key_name'];
1192 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1193 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1194 if (isset($row['Cardinality'])) {
1195 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1197 // I don't know what does following column mean....
1198 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1199 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1201 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1202 if (isset($row['Sub_part'])) {
1203 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1205 } // end while
1206 if ($result) {
1207 PMA_DBI_free_result($result);
1211 * Gets fields properties
1213 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1214 $fields_cnt = PMA_DBI_num_rows($result);
1215 // Check if we can use Relations (Mike Beck)
1216 if (!empty($cfgRelation['relation'])) {
1217 // Find which tables are related with the current one and write it in
1218 // an array
1219 $res_rel = PMA_getForeigners($db, $table);
1221 if (count($res_rel) > 0) {
1222 $have_rel = true;
1223 } else {
1224 $have_rel = false;
1226 } else {
1227 $have_rel = false;
1228 } // end if
1230 * Displays the comments of the table if MySQL >= 3.23
1233 $break = false;
1234 if (!empty($show_comment)) {
1235 $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
1236 $break = true;
1239 if (!empty($create_time)) {
1240 $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
1241 $break = true;
1244 if (!empty($update_time)) {
1245 $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
1246 $break = true;
1249 if (!empty($check_time)) {
1250 $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
1251 $break = true;
1254 if ($break == true) {
1255 $pdf->Cell(0, 3, '', 0, 1);
1256 $pdf->Ln();
1259 $pdf->SetFont('', 'B');
1260 if (isset($orientation) && $orientation == 'L') {
1261 $pdf->Cell(25, 8, ucfirst(__('Column')), 1, 0, 'C');
1262 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1263 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1264 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1265 $pdf->Cell(20, 8, ucfirst(__('Default')), 1, 0, 'C');
1266 $pdf->Cell(25, 8, ucfirst(__('Extra')), 1, 0, 'C');
1267 $pdf->Cell(45, 8, ucfirst(__('Links to')), 1, 0, 'C');
1269 if ($paper == 'A4') {
1270 $comments_width = 67;
1271 } else {
1272 // this is really intended for 'letter'
1274 * @todo find optimal width for all formats
1276 $comments_width = 50;
1278 $pdf->Cell($comments_width, 8, ucfirst(__('Comments')), 1, 0, 'C');
1279 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1280 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1281 } else {
1282 $pdf->Cell(20, 8, ucfirst(__('Column')), 1, 0, 'C');
1283 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1284 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1285 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1286 $pdf->Cell(15, 8, ucfirst(__('Default')), 1, 0, 'C');
1287 $pdf->Cell(15, 8, ucfirst(__('Extra')), 1, 0, 'C');
1288 $pdf->Cell(30, 8, ucfirst(__('Links to')), 1, 0, 'C');
1289 $pdf->Cell(30, 8, ucfirst(__('Comments')), 1, 0, 'C');
1290 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1291 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1293 $pdf->SetFont('', '');
1295 while ($row = PMA_DBI_fetch_assoc($result)) {
1296 $type = $row['Type'];
1297 // reformat mysql query output
1298 // set or enum types: slashes single quotes inside options
1299 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1300 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1301 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1302 $type_nowrap = '';
1304 $binary = 0;
1305 $unsigned = 0;
1306 $zerofill = 0;
1307 } else {
1308 $type_nowrap = ' nowrap="nowrap"';
1309 $type = preg_replace('@BINARY@i', '', $type);
1310 $type = preg_replace('@ZEROFILL@i', '', $type);
1311 $type = preg_replace('@UNSIGNED@i', '', $type);
1312 if (empty($type)) {
1313 $type = '&nbsp;';
1316 $binary = stristr($row['Type'], 'BINARY');
1317 $unsigned = stristr($row['Type'], 'UNSIGNED');
1318 $zerofill = stristr($row['Type'], 'ZEROFILL');
1320 $attribute = ' ';
1321 if ($binary) {
1322 $attribute = 'BINARY';
1324 if ($unsigned) {
1325 $attribute = 'UNSIGNED';
1327 if ($zerofill) {
1328 $attribute = 'UNSIGNED ZEROFILL';
1330 if (!isset($row['Default'])) {
1331 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1332 $row['Default'] = 'NULL';
1335 $field_name = $row['Field'];
1336 // $pdf->Ln();
1337 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1338 $pdf->Bookmark($field_name, 1, -1);
1339 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1340 $pdf_row = array($field_name,
1341 $type,
1342 $attribute,
1343 ($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes'),
1344 ((isset($row['Default'])) ? $row['Default'] : ''),
1345 $row['Extra'],
1346 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1347 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1348 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1350 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1351 if (isset($res_rel[$field_name]['foreign_table']) AND
1352 isset($res_rel[$field_name]['foreign_field']) AND
1353 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1356 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1357 } else {
1358 unset($links[6]);
1360 $pdf->Row($pdf_row, $links);
1362 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1363 //echo ' ' . $field_name . '&nbsp;' . "\n";
1365 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1366 $pdf->Cell(20, 8, $attribute, 1, 0, 'L');
1367 $pdf->Cell(15, 8, , 1, 0, 'L');
1368 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1369 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1370 if ($have_rel) {
1371 if (isset($res_rel[$field_name])) {
1372 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1375 if ($cfgRelation['commwork']) {
1376 if (isset($comments[$field_name])) {
1377 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1379 } */
1380 } // end while
1381 $pdf->SetFont('', '', 14);
1382 PMA_DBI_free_result($result);
1383 } //end each
1384 } // end function PMA_RT_DOC
1387 * Main logic
1389 if (!isset($pdf_page_number)) {
1390 $pdf_page_number = 1;
1393 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1394 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1395 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1396 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1397 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1398 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1399 $paper = isset($paper) ? $paper : 'A4';
1400 $show_keys = (isset($show_keys) && $show_keys == 'on') ? 1 : 0;
1401 PMA_DBI_select_db($db);
1403 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper, $show_keys);