Export Relation Schema: renaming files + renaming classes according to pear standards
[phpmyadmin-themes.git] / libraries / schema / Pdf_Relation_Schema.class.php
blobf94aa1a1d2217b5c2c0d62241af5e98e6a9cfab5
1 <?php
2 include_once("Export_Relation_Schema.class.php");
3 /**
4 * Font used in PDF.
6 * @todo Make this configuratble (at least Sans/Serif).
7 */
8 define('PMA_PDF_FONT', 'DejaVuSans');
9 require_once './libraries/tcpdf/tcpdf.php';
11 /**
12 * Extends the "FPDF" class and prepares the work
14 * @access public
15 * @see FPDF
16 * @package phpMyAdmin
18 class PMA_PDF extends TCPDF {
19 /**
20 * Defines private properties
22 var $x_min;
23 var $y_min;
24 var $l_marg = 10;
25 var $t_marg = 10;
26 var $scale;
27 var $PMA_links;
28 var $Outlines = array();
29 var $def_outlines;
30 var $Alias = array();
31 var $widths;
33 public function getFh()
35 return $this->fh;
38 public function getFw()
40 return $this->fw;
43 public function setCMargin($c_margin)
45 $this->cMargin = $c_margin;
48 function SetAlias($name, $value)
50 $this->Alias[$name] = $value ;
53 function _putpages()
55 if (count($this->Alias) > 0) {
56 $nb = $this->page;
57 foreach ($this->Alias as $alias => $value) {
58 for ($n = 1;$n <= $nb;$n++)
59 $this->pages[$n]=str_replace($alias, $value, $this->pages[$n]);
62 parent::_putpages();
65 /**
66 * Sets the scaling factor, defines minimum coordinates and margins
68 * @param float scale The scaling factor
69 * @param float x_min The minimum X coordinate
70 * @param float y_min The minimum Y coordinate
71 * @param float l_marg The left margin
72 * @param float t_marg The top margin
73 * @access public
75 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
77 $this->scale = $scale;
78 $this->x_min = $x_min;
79 $this->y_min = $y_min;
80 if ($this->l_marg != -1) {
81 $this->l_marg = $l_marg;
83 if ($this->t_marg != -1) {
84 $this->t_marg = $t_marg;
86 } // end of the "PMA_PDF_setScale" function
87 /**
88 * Outputs a scaled cell
90 * @param float w The cell width
91 * @param float h The cell height
92 * @param string txt The text to output
93 * @param mixed border Whether to add borders or not
94 * @param integer ln Where to put the cursor once the output is done
95 * @param string align Align mode
96 * @param integer fill Whether to fill the cell with a color or not
97 * @access public
98 * @see FPDF::Cell()
100 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
102 $h = $h / $this->scale;
103 $w = $w / $this->scale;
104 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
105 } // end of the "PMA_PDF_cellScale" function
107 * Draws a scaled line
109 * @param float x1 The horizontal position of the starting point
110 * @param float y1 The vertical position of the starting point
111 * @param float x2 The horizontal position of the ending point
112 * @param float y2 The vertical position of the ending point
113 * @access public
114 * @see FPDF::Line()
116 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
118 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
119 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
120 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
121 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
122 $this->Line($x1, $y1, $x2, $y2);
123 } // end of the "PMA_PDF_lineScale" function
125 * Sets x and y scaled positions
127 * @param float x The x position
128 * @param float y The y position
129 * @access public
130 * @see FPDF::SetXY()
132 function PMA_PDF_setXyScale($x, $y)
134 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
135 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
136 $this->SetXY($x, $y);
137 } // end of the "PMA_PDF_setXyScale" function
139 * Sets the X scaled positions
141 * @param float x The x position
142 * @access public
143 * @see FPDF::SetX()
145 function PMA_PDF_setXScale($x)
147 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
148 $this->SetX($x);
149 } // end of the "PMA_PDF_setXScale" function
151 * Sets the scaled font size
153 * @param float size The font size (in points)
154 * @access public
155 * @see FPDF::SetFontSize()
157 function PMA_PDF_setFontSizeScale($size)
159 // Set font size in points
160 $size = $size / $this->scale;
161 $this->SetFontSize($size);
162 } // end of the "PMA_PDF_setFontSizeScale" function
164 * Sets the scaled line width
166 * @param float width The line width
167 * @access public
168 * @see FPDF::SetLineWidth()
170 function PMA_PDF_setLineWidthScale($width)
172 $width = $width / $this->scale;
173 $this->SetLineWidth($width);
174 } // end of the "PMA_PDF_setLineWidthScale" function
176 * Displays an error message
178 * @param string error_message the error mesage
179 * @global array the PMA configuration array
180 * @global integer the current server id
181 * @global string the current language
182 * @global string the charset to convert to
183 * @global string the current database name
184 * @global string the current charset
185 * @global string the current text direction
186 * @global string a localized string
187 * @global string an other localized string
188 * @access public
190 /* function PMA_PDF_die($error_message = '')
192 global $cfg;
193 global $server, $lang, $convcharset, $db;
194 global $charset, $text_dir;
196 require_once './libraries/header.inc.php';
198 echo '<p><strong>PDF - ' . __('Error') . '</strong></p>' . "\n";
199 if (!empty($error_message)) {
200 $error_message = htmlspecialchars($error_message);
202 echo '<p>' . "\n";
203 echo ' ' . $error_message . "\n";
204 echo '</p>' . "\n";
206 echo '<a href="db_structure.php?' . PMA_generate_common_url($db)
207 . '">' . __('Back') . '</a>';
208 echo "\n";
210 require_once './libraries/footer.inc.php';
211 }*/ // end of the "PMA_PDF_die()" function
213 * Aliases the "Error()" function from the FPDF class to the
214 * "PMA_PDF_die()" one
216 * @param string error_message the error mesage
217 * @access public
218 * @see PMA_PDF_die
220 function Error($error_message = '')
222 PMA_Relation_Schema::PMA_Schema_die($error_message);
223 } // end of the "Error()" method
224 function Header()
226 // We only show this if we find something in the new pdf_pages table
228 // This function must be named "Header" to work with the FPDF library
229 global $cfgRelation, $db, $pdf_page_number, $with_doc;
230 if ($with_doc) {
231 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
232 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
233 . ' AND page_nr = \'' . $pdf_page_number . '\'';
234 $test_rs = PMA_query_as_controluser($test_query);
235 $pages = @PMA_DBI_fetch_assoc($test_rs);
236 $this->SetFont('', 'B', 14);
237 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
238 $this->SetFont('', '');
239 $this->Ln();
242 function Footer()
244 // This function must be named "Footer" to work with the FPDF library
245 global $with_doc;
246 if ($with_doc) {
247 $this->SetY(-15);
248 $this->SetFont('', '', 14);
249 $this->Cell(0, 6, __('Page number:') . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
250 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
251 $this->SetY(20);
254 function Bookmark($txt, $level = 0, $y = 0)
256 // Add a bookmark
257 $this->Outlines[0][] = $level;
258 $this->Outlines[1][] = $txt;
259 $this->Outlines[2][] = $this->page;
260 if ($y == -1) {
261 $y = $this->GetY();
263 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
266 function _putbookmarks()
268 if (count($this->Outlines) > 0) {
269 // Save object number
270 $memo_n = $this->n;
271 // Take the number of sub elements for an outline
272 $nb_outlines = sizeof($this->Outlines[0]);
273 $first_level = array();
274 $parent = array();
275 $parent[0] = 1;
276 for ($i = 0; $i < $nb_outlines; $i++) {
277 $level = $this->Outlines[0][$i];
278 $kids = 0;
279 $last = -1;
280 $prev = -1;
281 $next = -1;
282 if ($i > 0) {
283 $cursor = $i-1;
284 // Take the previous outline in the same level
285 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
286 $cursor--;
287 if ($this->Outlines[0][$cursor] == $level) {
288 $prev = $cursor;
291 if ($i < $nb_outlines-1) {
292 $cursor = $i + 1;
293 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
294 // Take the immediate kid in level + 1
295 if ($this->Outlines[0][$cursor] == $level + 1) {
296 $kids++;
297 $last = $cursor;
299 $cursor++;
301 $cursor = $i + 1;
302 // Take the next outline in the same level
303 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
304 $cursor++;
305 if ($this->Outlines[0][$cursor] == $level) {
306 $next = $cursor;
309 $this->_newobj();
310 $parent[$level + 1] = $this->n;
311 if ($level == 0) {
312 $first_level[] = $this->n;
314 $this->_out('<<');
315 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
316 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
317 if ($prev != -1) {
318 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
320 if ($next != -1) {
321 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
323 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
324 if ($kids > 0) {
325 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
326 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
327 $this->_out('/Count -' . $kids);
328 }tur
329 $this->_out('>>');
330 $this->_out('endobj');
332 // First page of outlines
333 $this->_newobj();
334 $this->def_outlines = $this->n;
335 $this->_out('<<');
336 $this->_out('/Type');
337 $this->_out('/Outlines');
338 $this->_out('/First ' . $first_level[0] . ' 0 R');
339 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
340 $this->_out('/Count ' . sizeof($first_level));
341 $this->_out('>>');
342 $this->_out('endobj');
346 function _putresources()
348 parent::_putresources();
349 $this->_putbookmarks();
352 function _putcatalog()
354 parent::_putcatalog();
355 if (count($this->Outlines) > 0) {
356 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
357 $this->_out('/PageMode /UseOutlines');
360 function SetWidths($w)
362 // column widths
363 $this->widths = $w;
366 function Row($data, $links)
368 // line height
369 $nb = 0;
370 $data_cnt = count($data);
371 for ($i = 0;$i < $data_cnt;$i++)
372 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
373 $il = $this->FontSize;
374 $h = ($il + 1) * $nb;
375 // page break if necessary
376 $this->CheckPageBreak($h);
377 // draw the cells
378 $data_cnt = count($data);
379 for ($i = 0;$i < $data_cnt;$i++) {
380 $w = $this->widths[$i];
381 // save current position
382 $x = $this->GetX();
383 $y = $this->GetY();
384 // draw the border
385 $this->Rect($x, $y, $w, $h);
386 if (isset($links[$i])) {
387 $this->Link($x, $y, $w, $h, $links[$i]);
389 // print text
390 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
391 // go to right side
392 $this->SetXY($x + $w, $y);
394 // go to line
395 $this->Ln($h);
398 function CheckPageBreak($h)
400 // if height h overflows, manual page break
401 if ($this->GetY() + $h > $this->PageBreakTrigger) {
402 $this->AddPage($this->CurOrientation);
406 function NbLines($w, $txt)
408 // compute number of lines used by a multicell of width w
409 $cw = &$this->CurrentFont['cw'];
410 if ($w == 0) {
411 $w = $this->w - $this->rMargin - $this->x;
413 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
414 $s = str_replace("\r", '', $txt);
415 $nb = strlen($s);
416 if ($nb > 0 and $s[$nb-1] == "\n") {
417 $nb--;
419 $sep = -1;
420 $i = 0;
421 $j = 0;
422 $l = 0;
423 $nl = 1;
424 while ($i < $nb) {
425 $c = $s[$i];
426 if ($c == "\n") {
427 $i++;
428 $sep = -1;
429 $j = $i;
430 $l = 0;
431 $nl++;
432 continue;
434 if ($c == ' ') {
435 $sep = $i;
437 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
438 if ($l > $wmax) {
439 if ($sep == -1) {
440 if ($i == $j) {
441 $i++;
443 } else {
444 $i = $sep + 1;
446 $sep = -1;
447 $j = $i;
448 $l = 0;
449 $nl++;
450 } else {
451 $i++;
454 return $nl;
456 } // end of the "PMA_PDF" class
459 * Draws tables schema
461 * @access private
462 * @see PMA_RT
463 * @package phpMyAdmin
465 class PMA_RT_Table {
467 * Defines private properties
469 var $nb_fiels;
470 var $table_name;
471 var $width = 0;
472 var $height;
473 var $fields = array();
474 var $height_cell = 6;
475 var $x, $y;
476 var $primary = array();
477 var $show_info = false;
480 * Returns title of the current table,
481 * title can have the dimensions of the table
483 * @access private
485 function getTitle()
487 return ($this->show_info ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) : '') . ' ' . $this->table_name;
488 } // end of the "getTitle" function
490 * Sets the width of the table
492 * @param integer ff The font size
493 * @global object The current PDF document
494 * @access private
495 * @see PMA_PDF
497 function PMA_RT_Table_setWidth($ff)
499 global $pdf;
501 foreach ($this->fields as $field) {
502 $this->width = max($this->width, $pdf->GetStringWidth($field));
504 //echo $this->width.'<br />';
505 $this->width += $pdf->GetStringWidth(' ');
506 //echo $this->width.'<br />';
507 $pdf->SetFont($ff, 'B');
508 // it is unknown what value must be added, because
509 // table title is affected by the tabe width value
510 //echo $this->getTitle();
511 while ($this->width < $pdf->GetStringWidth($this->getTitle())) {
512 $this->width += 5;
514 //echo $this->width.'<br />';
515 $pdf->SetFont($ff, '');
516 } // end of the "PMA_RT_Table_setWidth()" method
518 * Sets the height of the table
520 * @access private
522 function PMA_RT_Table_setHeight()
524 $this->height = (count($this->fields) + 1) * $this->height_cell;
525 } // end of the "PMA_RT_Table_setHeight()" method
527 * Do draw the table
529 * @param integer ff The font size
530 * @param boolean setcolortWhether to display color
531 * @global object The current PDF document
532 * @access private
533 * @see PMA_PDF
535 function PMA_RT_Table_draw($ff, $setcolor = 0)
537 global $pdf, $with_doc;
539 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
540 $pdf->SetFont($ff, 'B');
541 if ($setcolor) {
542 $pdf->SetTextColor(200);
543 $pdf->SetFillColor(0, 0, 128);
545 if ($with_doc) {
546 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
547 } else {
548 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
551 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->getTitle(), 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
552 $pdf->PMA_PDF_setXScale($this->x);
553 $pdf->SetFont($ff, '');
554 $pdf->SetTextColor(0);
555 $pdf->SetFillColor(255);
557 foreach ($this->fields as $field) {
558 if ($setcolor) {
559 if (in_array($field, $this->primary)) {
560 $pdf->SetFillColor(215, 121, 123);
562 if ($field == $this->displayfield) {
563 $pdf->SetFillColor(142, 159, 224);
566 if ($with_doc) {
567 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
568 } else {
569 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
572 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
573 $pdf->PMA_PDF_setXScale($this->x);
574 $pdf->SetFillColor(255);
575 } // end while
576 /*if ($pdf->PageNo() > 1) {
577 $pdf->PMA_PDF_die(__('The scale factor is too small to fit the schema on one page'));
578 } */
579 } // end of the "PMA_RT_Table_draw()" method
581 * The "PMA_RT_Table" constructor
583 * @param string table_name The table name
584 * @param integer ff The font size
585 * @param integer same_width The max. with among tables
586 * @param boolean show_keys Whether to display keys or not
587 * @param boolean show_info Whether to display table position or not
588 * @global object The current PDF document
589 * @global integer The current page number (from the
590 * $cfg['Servers'][$i]['table_coords'] table)
591 * @global array The relations settings
592 * @global string The current db name
593 * @access private
594 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
595 PMA_RT_Table::PMA_RT_Table_setHeight
597 function __construct($table_name, $ff, &$same_wide_width, $show_keys = false, $show_info = false)
599 global $pdf, $pdf_page_number, $cfgRelation, $db;
601 $this->table_name = $table_name;
602 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
603 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
604 if (!$result || !PMA_DBI_num_rows($result)) {
605 $pdf->PMA_PDF_die(sprintf(__('The %s table doesn\'t exist!'), $table_name));
607 // load fields
608 //check to see if it will load all fields or only the foreign keys
609 if ($show_keys) {
610 $indexes = PMA_Index::getFromTable($this->table_name, $db);
611 $all_columns = array();
612 foreach ($indexes as $index) {
613 $all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
615 $this->fields = array_keys($all_columns);
616 } else {
617 while ($row = PMA_DBI_fetch_row($result)) {
618 $this->fields[] = $row[0];
622 $this->show_info = $show_info;
624 // height and width
625 $this->PMA_RT_Table_setHeight();
626 // setWidth must me after setHeight, because title
627 // can include table height which changes table width
628 $this->PMA_RT_Table_setWidth($ff);
629 if ($same_wide_width < $this->width) {
630 $same_wide_width = $this->width;
632 // x and y
633 $sql = 'SELECT x, y FROM '
634 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
635 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
636 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
637 . ' AND pdf_page_number = ' . $pdf_page_number;
638 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
640 if (!$result || !PMA_DBI_num_rows($result)) {
641 $pdf->PMA_PDF_die(sprintf(__('Please configure the coordinates for table %s'), $table_name));
643 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
644 $this->x = (double) $this->x;
645 $this->y = (double) $this->y;
646 // displayfield
647 $this->displayfield = PMA_getDisplayField($db, $table_name);
648 // index
649 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
650 if (PMA_DBI_num_rows($result) > 0) {
651 while ($row = PMA_DBI_fetch_assoc($result)) {
652 if ($row['Key_name'] == 'PRIMARY') {
653 $this->primary[] = $row['Column_name'];
656 } // end if
657 } // end of the "PMA_RT_Table()" method
658 } // end class "PMA_RT_Table"
661 * Draws relation links
663 * @access private
664 * @see PMA_RT
665 * @package phpMyAdmin
667 class PMA_RT_Relation {
669 * Defines private properties
671 var $x_src, $y_src;
672 var $src_dir ;
673 var $dest_dir;
674 var $x_dest, $y_dest;
675 var $w_tick = 5;
678 * Gets arrows coordinates
680 * @param string table The current table name
681 * @param string column The relation column name
682 * @return array Arrows coordinates
683 * @access private
685 function PMA_RT_Relation_getXy($table, $column)
687 $pos = array_search($column, $table->fields);
688 // x_left, x_right, y
689 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
690 } // end of the "PMA_RT_Relation_getXy()" method
692 * Do draws relation links
694 * @param boolean change_color Whether to use one color per relation or not
695 * @param integer i The id of the link to draw
696 * @global object The current PDF document
697 * @access private
698 * @see PMA_PDF
700 function PMA_RT_Relation_draw($change_color, $i)
702 global $pdf;
704 if ($change_color) {
705 $d = $i % 6;
706 $j = ($i - $d) / 6;
707 $j = $j % 4;
708 $j++;
709 $case = array(
710 array(1, 0, 0),
711 array(0, 1, 0),
712 array(0, 0, 1),
713 array(1, 1, 0),
714 array(1, 0, 1),
715 array(0, 1, 1)
717 list ($a, $b, $c) = $case[$d];
718 $e = (1 - ($j - 1) / 6);
719 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
720 } else {
721 $pdf->SetDrawColor(0);
722 } // end if... else...
723 $pdf->PMA_PDF_setLineWidthScale(0.2);
724 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
725 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
726 $pdf->PMA_PDF_setLineWidthScale(0.1);
727 $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);
728 // arrow
729 $root2 = 2 * sqrt(2);
730 $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);
731 $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);
733 $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);
734 $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);
735 $pdf->SetDrawColor(0);
736 } // end of the "PMA_RT_Relation_draw()" method
738 * The "PMA_RT_Relation" constructor
740 * @param string master_table The master table name
741 * @param string master_field The relation field in the master table
742 * @param string foreign_table The foreign table name
743 * @param string foreigh_field The relation field in the foreign table
744 * @access private
745 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
747 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
749 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
750 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
751 $src_left = $src_pos[0] - $this->w_tick;
752 $src_right = $src_pos[1] + $this->w_tick;
753 $dest_left = $dest_pos[0] - $this->w_tick;
754 $dest_right = $dest_pos[1] + $this->w_tick;
756 $d1 = abs($src_left - $dest_left);
757 $d2 = abs($src_right - $dest_left);
758 $d3 = abs($src_left - $dest_right);
759 $d4 = abs($src_right - $dest_right);
760 $d = min($d1, $d2, $d3, $d4);
762 if ($d == $d1) {
763 $this->x_src = $src_pos[0];
764 $this->src_dir = -1;
765 $this->x_dest = $dest_pos[0];
766 $this->dest_dir = -1;
767 } elseif ($d == $d2) {
768 $this->x_src = $src_pos[1];
769 $this->src_dir = 1;
770 $this->x_dest = $dest_pos[0];
771 $this->dest_dir = -1;
772 } elseif ($d == $d3) {
773 $this->x_src = $src_pos[0];
774 $this->src_dir = -1;
775 $this->x_dest = $dest_pos[1];
776 $this->dest_dir = 1;
777 } else {
778 $this->x_src = $src_pos[1];
779 $this->src_dir = 1;
780 $this->x_dest = $dest_pos[1];
781 $this->dest_dir = 1;
783 $this->y_src = $src_pos[2];
784 $this->y_dest = $dest_pos[2];
785 } // end of the "PMA_RT_Relation()" method
786 } // end of the "PMA_RT_Relation" class
788 class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
791 * Defines private properties
793 private $tables = array();
794 private $relations = array();
795 private $ff = PMA_PDF_FONT;
796 private $x_max = 0;
797 private $y_max = 0;
798 private $scale;
799 private $x_min = 100000;
800 private $y_min = 100000;
801 private $t_marg = 10;
802 private $b_marg = 10;
803 private $l_marg = 10;
804 private $r_marg = 10;
805 private $_tablewidth;
808 * The "PMA_RT" constructor
810 * @param integer page_number The page number to draw (from the
811 * $cfg['Servers'][$i]['table_coords'] table)
812 * @param boolean show_info Whether to display table position or not
813 * @param boolean change_color Was originally whether to use one color per
814 * relation or not, now enables/disables color
815 * everywhere, due to some problems printing with color
816 * @param boolean show_grid Whether to draw grids or not
817 * @param boolean all_tab_same_wide Whether all tables should have the same width or not
818 * @param boolean show_keys Wheter to show all field or only the keys
819 * @global object The current PDF document
820 * @global string The current db name
821 * @global array The relations settings
822 * @access private
823 * @see PMA_PDF
825 function __construct($page_number, $show_info = 0, $change_color = 0, $show_grid = 0, $all_table_same_wide = 0, $orientation = 'L', $paper = 'A4', $show_keys = 0)
827 global $pdf, $db, $cfgRelation, $with_doc;
829 $this->setSameWidthTables($all_table_same_wide);
831 // Initializes a new document
832 $pdf = new PMA_PDF('L', 'mm', $paper);
833 $pdf->SetTitle(sprintf(__('Schema of the %s database - Page %s'), $GLOBALS['db'], $page_number));
834 $pdf->setCMargin(0);
835 $pdf->Open();
836 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
837 $pdf->AliasNbPages();
838 $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
839 $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
840 $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
841 $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
842 // $this->ff = PMA_PDF_FONT;
844 $pdf->SetFont($this->ff, '', 14);
845 $pdf->SetAutoPageBreak('auto');
848 // Gets tables on this page
849 /* $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
850 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
851 . ' AND pdf_page_number = ' . $page_number;
852 echo $tab_sql;
853 $tab_rs = PMA_query_as_controluser($tab_sql, null, PMA_DBI_QUERY_STORE);
854 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
855 $pdf->PMA_PDF_die(__('No tables'));
856 // die('No tables');
857 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
858 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
859 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
861 $alltables=$this->getAllTables($db,$page_number);
864 // make doc //
865 if ($with_doc) {
866 $pdf->SetAutoPageBreak('auto', 15);
867 $pdf->setCMargin(1);
868 $this->PMA_RT_DOC($alltables);
869 $pdf->SetAutoPageBreak('auto');
870 $pdf->setCMargin(0);
873 $pdf->Addpage();
875 if ($with_doc) {
876 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
877 $pdf->Bookmark(__('Relational schema'));
878 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
879 $this->t_marg = 28;
880 $this->b_marg = 28;
883 /* snip */
885 foreach ($alltables as $table) {
886 if (!isset($this->tables[$table])) {
887 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->_tablewidth, $show_keys, $show_info);
888 // $this->tables[$table]=$table;
891 if ($this->same_wide) {
892 $this->tables[$table]->width = $this->_tablewidth;
894 $this->PMA_RT_setMinMax($this->tables[$table]);
897 // Defines the scale factor
898 $this->scale = ceil(
899 max(
900 ($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg),
901 ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg))
902 * 100) / 100;
904 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
905 // Builds and save the PDF document
906 $pdf->PMA_PDF_setLineWidthScale(0.1);
908 if ($show_grid) {
909 $pdf->SetFontSize(10);
910 $this->PMA_RT_strokeGrid();
912 $pdf->PMA_PDF_setFontSizeScale(14);
913 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
914 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
915 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
916 // . ' AND master_table IN (' . $intable . ')'
917 // . ' AND foreign_table IN (' . $intable . ')';
918 // $result = PMA_query_as_controluser($sql);
920 // previous logic was checking master tables and foreign tables
921 // but I think that looping on every table of the pdf page as a master
922 // and finding its foreigns is OK (then we can support innodb)
923 $seen_a_relation = false;
924 foreach ($alltables as $one_table) {
925 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
926 if ($exist_rel) {
927 $seen_a_relation = true;
928 foreach ($exist_rel as $master_field => $rel) {
929 // put the foreign table on the schema only if selected
930 // by the user
931 // (do not use array_search() because we would have to
932 // to do a === FALSE and this is not PHP3 compatible)
933 if (in_array($rel['foreign_table'], $alltables)) {
934 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $show_info);
936 } // end while
937 } // end if
938 } // end while
940 /* print '<pre>';
941 print_r(get_object_vars($this));
942 print '</pre>';
943 exit();*/
945 if ($seen_a_relation) {
946 $this->PMA_RT_drawRelations($change_color);
949 $this->PMA_RT_drawTables($change_color);
951 $this->PMA_RT_showRt();
952 } // end of the "PMA_RT()" Constructor method
954 * Sets X and Y minimum and maximum for a table cell
956 * @param string table The table name
957 * @access private
959 function PMA_RT_setMinMax($table)
961 $this->x_max = max($this->x_max, $table->x + $table->width);
962 $this->y_max = max($this->y_max, $table->y + $table->height);
963 $this->x_min = min($this->x_min, $table->x);
964 $this->y_min = min($this->y_min, $table->y);
965 } // end of the "PMA_RT_setMinMax()" method
967 * Defines relation objects
969 * @param string master_table The master table name
970 * @param string master_field The relation field in the master table
971 * @param string foreign_table The foreign table name
972 * @param string foreign_field The relation field in the foreign table
973 * @param boolean show_info Whether to display table position or not
974 * @access private
975 * @see PMA_RT_setMinMax
977 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field, $show_info)
979 if (!isset($this->tables[$master_table])) {
980 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->_tablewidth, false, $show_info);
981 $this->PMA_RT_setMinMax($this->tables[$master_table]);
983 if (!isset($this->tables[$foreign_table])) {
984 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->_tablewidth, false, $show_info);
985 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
987 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
988 } // end of the "PMA_RT_addRelation()" method
990 * Draws the grid
992 * @global object the current PMA_PDF instance
993 * @access private
994 * @see PMA_PDF
996 function PMA_RT_strokeGrid()
998 global $pdf;
1000 $pdf->SetMargins(0, 0);
1001 $pdf->SetDrawColor(200, 200, 200);
1002 // Draws horizontal lines
1003 for ($l = 0; $l < 21; $l++) {
1004 $pdf->line(0, $l * 10, $pdf->getFh(), $l * 10);
1005 // Avoid duplicates
1006 if ($l > 0) {
1007 $pdf->SetXY(0, $l * 10);
1008 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
1009 $pdf->Cell(5, 5, ' ' . $label);
1010 } // end if
1011 } // end for
1012 // Draws vertical lines
1013 for ($j = 0; $j < 30 ;$j++) {
1014 $pdf->line($j * 10, 0, $j * 10, $pdf->getFw());
1015 $pdf->SetXY($j * 10, 0);
1016 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
1017 $pdf->Cell(5, 7, $label);
1018 } // end for
1019 } // end of the "PMA_RT_strokeGrid()" method
1021 * Draws relation arrows
1023 * @param boolean change_color Whether to use one color per relation or not
1024 * @access private
1025 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
1027 function PMA_RT_drawRelations($change_color)
1029 $i = 0;
1030 foreach ($this->relations as $relation) {
1031 $relation->PMA_RT_Relation_draw($change_color, $i);
1032 $i++;
1033 } // end while
1034 } // end of the "PMA_RT_drawRelations()" method
1036 * Draws tables
1038 * @param boolean draw_color Whether to display table position or not
1039 * @access private
1040 * @see PMA_RT_Table::PMA_RT_Table_draw()
1042 function PMA_RT_drawTables($draw_color = 0)
1044 foreach ($this->tables as $table) {
1045 $table->PMA_RT_Table_draw($this->ff, $draw_color);
1047 } // end of the "PMA_RT_drawTables()" method
1049 * Ouputs the PDF document to a file
1051 * @global object The current PDF document
1052 * @global string The current database name
1053 * @global integer The current page number (from the
1054 * $cfg['Servers'][$i]['table_coords'] table)
1055 * @access private
1056 * @see PMA_PDF
1058 function PMA_RT_showRt()
1060 global $pdf, $db, $pdf_page_number, $cfgRelation;
1062 $pdf->SetFontSize(14);
1063 $pdf->SetLineWidth(0.2);
1064 $pdf->SetDisplayMode('fullpage');
1065 // Get the name of this pdfpage to use as filename (Mike Beck)
1066 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
1067 . ' WHERE page_nr = ' . $pdf_page_number;
1068 $_name_rs = PMA_query_as_controluser($_name_sql);
1069 if ($_name_rs) {
1070 $_name_row = PMA_DBI_fetch_row($_name_rs);
1071 $filename = $_name_row[0] . '.pdf';
1073 // i don't know if there is a chance for this to happen, but rather be on the safe side:
1074 if (empty($filename)) {
1075 $filename = $pdf_page_number . '.pdf';
1077 // $pdf->Output($db . '_' . $filename, TRUE);
1078 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
1079 } // end of the "PMA_RT_showRt()" method
1081 function PMA_RT_DOC($alltables)
1083 global $db, $pdf, $orientation, $paper;
1084 // TOC
1085 $pdf->addpage($GLOBALS['orientation']);
1086 $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
1087 $pdf->Ln(15);
1088 $i = 1;
1089 foreach ($alltables as $table) {
1090 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1091 $pdf->SetX(10);
1092 // $pdf->Ln(1);
1093 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1094 $pdf->SetX(10);
1095 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1096 // $pdf->Ln(1);
1097 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1098 while ($row = PMA_DBI_fetch_assoc($result)) {
1099 $pdf->SetX(20);
1100 $field_name = $row['Field'];
1101 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1102 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1104 $lasttable = $table;
1105 $i++;
1107 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1108 $pdf->SetX(10);
1109 $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1110 $pdf->SetX(10);
1111 $pdf->Cell(0, 6, $i + 1 . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1112 $z = 0;
1113 foreach ($alltables as $table) {
1114 $z++;
1115 $pdf->addpage($GLOBALS['orientation']);
1116 $pdf->Bookmark($table);
1117 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1118 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1119 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1120 $pdf->SetFont('', 'B', 18);
1121 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1122 $pdf->SetFont('', '', 8);
1123 $pdf->ln();
1125 $cfgRelation = PMA_getRelationsParam();
1126 $comments = PMA_getComments($db, $table);
1127 if ($cfgRelation['mimework']) {
1128 $mime_map = PMA_getMIME($db, $table, true);
1132 * Gets table informations
1134 $showtable = PMA_Table::sGetStatusInfo($db, $table);
1135 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1136 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1137 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1138 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1139 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1142 * Gets table keys and retains them
1144 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1145 $primary = '';
1146 $indexes = array();
1147 $lastIndex = '';
1148 $indexes_info = array();
1149 $indexes_data = array();
1150 $pk_array = array(); // will be use to emphasis prim. keys in the table
1151 // view
1152 while ($row = PMA_DBI_fetch_assoc($result)) {
1153 // Backups the list of primary keys
1154 if ($row['Key_name'] == 'PRIMARY') {
1155 $primary .= $row['Column_name'] . ', ';
1156 $pk_array[$row['Column_name']] = 1;
1158 // Retains keys informations
1159 if ($row['Key_name'] != $lastIndex) {
1160 $indexes[] = $row['Key_name'];
1161 $lastIndex = $row['Key_name'];
1163 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1164 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1165 if (isset($row['Cardinality'])) {
1166 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1168 // I don't know what does following column mean....
1169 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1170 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1172 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1173 if (isset($row['Sub_part'])) {
1174 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1176 } // end while
1177 if ($result) {
1178 PMA_DBI_free_result($result);
1182 * Gets fields properties
1184 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1185 $fields_cnt = PMA_DBI_num_rows($result);
1186 // Check if we can use Relations (Mike Beck)
1187 if (!empty($cfgRelation['relation'])) {
1188 // Find which tables are related with the current one and write it in
1189 // an array
1190 $res_rel = PMA_getForeigners($db, $table);
1192 if (count($res_rel) > 0) {
1193 $have_rel = true;
1194 } else {
1195 $have_rel = false;
1197 } else {
1198 $have_rel = false;
1199 } // end if
1201 * Displays the comments of the table if MySQL >= 3.23
1204 $break = false;
1205 if (!empty($show_comment)) {
1206 $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
1207 $break = true;
1210 if (!empty($create_time)) {
1211 $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
1212 $break = true;
1215 if (!empty($update_time)) {
1216 $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
1217 $break = true;
1220 if (!empty($check_time)) {
1221 $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
1222 $break = true;
1225 if ($break == true) {
1226 $pdf->Cell(0, 3, '', 0, 1);
1227 $pdf->Ln();
1230 $pdf->SetFont('', 'B');
1231 if (isset($orientation) && $orientation == 'L') {
1232 $pdf->Cell(25, 8, ucfirst(__('Column')), 1, 0, 'C');
1233 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1234 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1235 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1236 $pdf->Cell(20, 8, ucfirst(__('Default')), 1, 0, 'C');
1237 $pdf->Cell(25, 8, ucfirst(__('Extra')), 1, 0, 'C');
1238 $pdf->Cell(45, 8, ucfirst(__('Links to')), 1, 0, 'C');
1240 if ($paper == 'A4') {
1241 $comments_width = 67;
1242 } else {
1243 // this is really intended for 'letter'
1245 * @todo find optimal width for all formats
1247 $comments_width = 50;
1249 $pdf->Cell($comments_width, 8, ucfirst(__('Comments')), 1, 0, 'C');
1250 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1251 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1252 } else {
1253 $pdf->Cell(20, 8, ucfirst(__('Column')), 1, 0, 'C');
1254 $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
1255 $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
1256 $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
1257 $pdf->Cell(15, 8, ucfirst(__('Default')), 1, 0, 'C');
1258 $pdf->Cell(15, 8, ucfirst(__('Extra')), 1, 0, 'C');
1259 $pdf->Cell(30, 8, ucfirst(__('Links to')), 1, 0, 'C');
1260 $pdf->Cell(30, 8, ucfirst(__('Comments')), 1, 0, 'C');
1261 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1262 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1264 $pdf->SetFont('', '');
1266 while ($row = PMA_DBI_fetch_assoc($result)) {
1267 $type = $row['Type'];
1268 // reformat mysql query output
1269 // set or enum types: slashes single quotes inside options
1270 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1271 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1272 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1273 $type_nowrap = '';
1275 $binary = 0;
1276 $unsigned = 0;
1277 $zerofill = 0;
1278 } else {
1279 $type_nowrap = ' nowrap="nowrap"';
1280 $type = preg_replace('@BINARY@i', '', $type);
1281 $type = preg_replace('@ZEROFILL@i', '', $type);
1282 $type = preg_replace('@UNSIGNED@i', '', $type);
1283 if (empty($type)) {
1284 $type = '&nbsp;';
1287 $binary = stristr($row['Type'], 'BINARY');
1288 $unsigned = stristr($row['Type'], 'UNSIGNED');
1289 $zerofill = stristr($row['Type'], 'ZEROFILL');
1291 $attribute = ' ';
1292 if ($binary) {
1293 $attribute = 'BINARY';
1295 if ($unsigned) {
1296 $attribute = 'UNSIGNED';
1298 if ($zerofill) {
1299 $attribute = 'UNSIGNED ZEROFILL';
1301 if (!isset($row['Default'])) {
1302 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1303 $row['Default'] = 'NULL';
1306 $field_name = $row['Field'];
1307 // $pdf->Ln();
1308 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1309 $pdf->Bookmark($field_name, 1, -1);
1310 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1311 $pdf_row = array($field_name,
1312 $type,
1313 $attribute,
1314 ($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes'),
1315 ((isset($row['Default'])) ? $row['Default'] : ''),
1316 $row['Extra'],
1317 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1318 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1319 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1321 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1322 if (isset($res_rel[$field_name]['foreign_table']) AND
1323 isset($res_rel[$field_name]['foreign_field']) AND
1324 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1327 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1328 } else {
1329 unset($links[6]);
1331 $pdf->Row($pdf_row, $links);
1332 } // end while
1333 $pdf->SetFont('', '', 14);
1334 PMA_DBI_free_result($result);
1335 } //end each