fix behaviour when invalid string is specified
[phpmyadmin/crack.git] / pdf_schema.php
blob557eda41c04a1c4ef957c19274694365864af89d
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4 /**
5 * Contributed by Maxime Delorme and merged by lem9
6 */
8 /**
9 * Gets some core scripts
11 require_once('./libraries/common.lib.php');
13 /**
14 * Settings for relation stuff
16 require_once('./libraries/relation.lib.php');
17 require_once('./libraries/transformations.lib.php');
19 $cfgRelation = PMA_getRelationsParam();
21 /**
22 * Now in ./libraries/relation.lib.php we check for all tables
23 * that we need, but if we don't find them we are quiet about it
24 * so people can work without.
25 * This page is absolutely useless if you didn't set up your tables
26 * correctly, so it is a good place to see which tables we can and
27 * complain ;-)
29 if (!$cfgRelation['pdfwork']) {
30 echo '<font color="red">' . $strError . '</font><br />' . "\n";
31 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
32 echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
35 /**
36 * Gets the "fpdf" libraries and defines the pdf font path, use unicode version for unicode.
38 define('FPDF_FONTPATH', './libraries/fpdf/font/');
39 if ($charset == 'utf-8') {
40 define('PMA_PDF_FONT', 'FreeSans');
41 require_once('./libraries/fpdf/ufpdf.php');
42 class PMA_FPDF extends UFPDF {
44 } else {
45 define('PMA_PDF_FONT', 'Arial');
46 require_once('./libraries/fpdf/fpdf.php');
47 class PMA_FPDF extends FPDF {
51 /**
52 * Extends the "FPDF" class and prepares the work
54 * @access public
55 * @see FPDF
57 class PMA_PDF extends PMA_FPDF {
58 /**
59 * Defines private properties
61 var $x_min;
62 var $y_min;
63 var $l_marg = 10;
64 var $t_marg = 10;
65 var $scale;
66 var $title;
67 var $PMA_links;
68 var $Outlines = array();
69 var $def_outlines;
70 var $Alias ;
71 var $widths;
73 /**
74 * The PMA_PDF constructor
76 * This function just refers to the "FPDF" constructor: with PHP3 a class
77 * must have a constructor
79 * @param string $ The page orientation (p, portrait, l or landscape)
80 * @param string $ The unit for sizes (pt, mm, cm or in)
81 * @param mixed $ The page format (A3, A4, A5, letter, legal or an array
82 * with page sizes)
83 * @access public
84 * @see FPDF::FPDF()
86 function PMA_PDF($orientation = 'L', $unit = 'mm', $format = 'A4')
88 $this->Alias = array() ;
89 $this->FPDF($orientation, $unit, $format);
90 } // end of the "PMA_PDF()" method
91 function SetAlias($name, $value)
93 $this->Alias[$name] = $value ;
95 function _putpages()
97 if (count($this->Alias) > 0) {
98 $nb = $this->page;
99 foreach ($this->Alias AS $alias => $value) {
100 for ($n = 1;$n <= $nb;$n++)
101 $this->pages[$n] = $this->_strreplace($alias, $value, $this->pages[$n]);
104 parent::_putpages();
108 * Sets the scaling factor, defines minimum coordinates and margins
110 * @param double $ The scaling factor
111 * @param double $ The minimum X coordinate
112 * @param double $ The minimum Y coordinate
113 * @param double $ The left margin
114 * @param double $ The top margin
115 * @access public
117 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
119 $this->scale = $scale;
120 $this->x_min = $x_min;
121 $this->y_min = $y_min;
122 if ($this->l_marg != -1) {
123 $this->l_marg = $l_marg;
125 if ($this->t_marg != -1) {
126 $this->t_marg = $t_marg;
128 } // end of the "PMA_PDF_setScale" function
130 * Outputs a scaled cell
132 * @param double $ The cell width
133 * @param double $ The cell height
134 * @param string $ The text to output
135 * @param mixed $ Wether to add borders or not
136 * @param integer $ Where to put the cursor once the output is done
137 * @param string $ Align mode
138 * @param integer $ Whether to fill the cell with a color or not
139 * @access public
140 * @see FPDF::Cell()
142 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
144 $h = $h / $this->scale;
145 $w = $w / $this->scale;
146 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
147 } // end of the "PMA_PDF_cellScale" function
149 * Draws a scaled line
151 * @param double $ The horizontal position of the starting point
152 * @param double $ The vertical position of the starting point
153 * @param double $ The horizontal position of the ending point
154 * @param double $ The vertical position of the ending point
155 * @access public
156 * @see FPDF::Line()
158 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
160 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
161 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
162 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
163 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
164 $this->Line($x1, $y1, $x2, $y2);
165 } // end of the "PMA_PDF_lineScale" function
167 * Sets x and y scaled positions
169 * @param double $ The x position
170 * @param double $ The y position
171 * @access public
172 * @see FPDF::SetXY()
174 function PMA_PDF_setXyScale($x, $y)
176 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
177 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
178 $this->SetXY($x, $y);
179 } // end of the "PMA_PDF_setXyScale" function
181 * Sets the X scaled positions
183 * @param double $ The x position
184 * @access public
185 * @see FPDF::SetX()
187 function PMA_PDF_setXScale($x)
189 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
190 $this->SetX($x);
191 } // end of the "PMA_PDF_setXScale" function
193 * Sets the scaled font size
195 * @param double $ The font size (in points)
196 * @access public
197 * @see FPDF::SetFontSize()
199 function PMA_PDF_setFontSizeScale($size)
201 // Set font size in points
202 $size = $size / $this->scale;
203 $this->SetFontSize($size);
204 } // end of the "PMA_PDF_setFontSizeScale" function
206 * Sets the scaled line width
208 * @param double $ The line width
209 * @access public
210 * @see FPDF::SetLineWidth()
212 function PMA_PDF_setLineWidthScale($width)
214 $width = $width / $this->scale;
215 $this->SetLineWidth($width);
216 } // end of the "PMA_PDF_setLineWidthScale" function
218 * Displays an error message
220 * @param string $ the error mesage
221 * @global array the PMA configuration array
222 * @global integer the current server id
223 * @global string the current language
224 * @global string the charset to convert to
225 * @global string the current database name
226 * @global string the current charset
227 * @global string the current text direction
228 * @global string a localized string
229 * @global string an other localized string
230 * @access public
232 function PMA_PDF_die($error_message = '')
234 global $cfg;
235 global $server, $lang, $convcharset, $db;
236 global $charset, $text_dir, $strRunning, $strDatabase;
238 require_once('./libraries/header.inc.php');
240 echo '<p><b>PDF - ' . $GLOBALS['strError'] . '</b></p>' . "\n";
241 if (!empty($error_message)) {
242 $error_message = htmlspecialchars($error_message);
244 echo '<p>' . "\n";
245 echo ' ' . $error_message . "\n";
246 echo '</p>' . "\n";
248 echo '<a href="db_details_structure.php?' . PMA_generate_common_url($db)
249 . '">' . $GLOBALS['strBack'] . '</a>';
250 echo "\n";
252 require_once('./libraries/footer.inc.php');
253 } // end of the "PMA_PDF_die()" function
255 * Aliases the "Error()" function from the FPDF class to the
256 * "PMA_PDF_die()" one
258 * @param string $ the error mesage
259 * @access public
260 * @see PMA_PDF_die
262 function Error($error_message = '')
264 $this->PMA_PDF_die($error_message);
265 } // end of the "Error()" method
266 function Header()
268 // $datefmt
269 // We only show this if we find something in the new pdf_pages table
271 // This function must be named "Header" to work with the FPDF library
272 global $cfgRelation, $db, $pdf_page_number, $with_doc;
273 if ($with_doc) {
274 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
275 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
276 . ' AND page_nr = \'' . $pdf_page_number . '\'';
277 $test_rs = PMA_query_as_cu($test_query);
278 $pages = @PMA_DBI_fetch_assoc($test_rs);
279 $this->SetFont('', 'B', 14);
280 $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
281 $this->SetFont('', '');
282 $this->Ln();
285 function Footer()
287 // This function must be named "Footer" to work with the FPDF library
288 global $with_doc;
289 if ($with_doc) {
290 $this->SetY(-15);
291 $this->SetFont('', '', 14);
292 $this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
293 $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
294 $this->SetY(20);
297 function Bookmark($txt, $level = 0, $y = 0)
299 // Add a bookmark
300 $this->Outlines[0][] = $level;
301 $this->Outlines[1][] = $txt;
302 $this->Outlines[2][] = $this->page;
303 if ($y == -1) {
304 $y = $this->GetY();
306 $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
309 function _putbookmarks()
311 if (count($this->Outlines) > 0) {
312 // Save object number
313 $memo_n = $this->n;
314 // Take the number of sub elements for an outline
315 $nb_outlines = sizeof($this->Outlines[0]);
316 $first_level = array();
317 $parent = array();
318 $parent[0] = 1;
319 for ($i = 0; $i < $nb_outlines; $i++) {
320 $level = $this->Outlines[0][$i];
321 $kids = 0;
322 $last = -1;
323 $prev = -1;
324 $next = -1;
325 if ($i > 0) {
326 $cursor = $i-1;
327 // Take the previous outline in the same level
328 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
329 $cursor--;
330 if ($this->Outlines[0][$cursor] == $level) {
331 $prev = $cursor;
334 if ($i < $nb_outlines-1) {
335 $cursor = $i + 1;
336 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
337 // Take the immediate kid in level + 1
338 if ($this->Outlines[0][$cursor] == $level + 1) {
339 $kids++;
340 $last = $cursor;
342 $cursor++;
344 $cursor = $i + 1;
345 // Take the next outline in the same level
346 while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
347 $cursor++;
348 if ($this->Outlines[0][$cursor] == $level) {
349 $next = $cursor;
352 $this->_newobj();
353 $parent[$level + 1] = $this->n;
354 if ($level == 0) {
355 $first_level[] = $this->n;
357 $this->_out('<<');
358 $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
359 $this->_out('/Parent ' . $parent[$level] . ' 0 R');
360 if ($prev != -1) {
361 $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
363 if ($next != -1) {
364 $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
366 $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
367 if ($kids > 0) {
368 $this->_out('/First ' . ($this->n + 1) . ' 0 R');
369 $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
370 $this->_out('/Count -' . $kids);
372 $this->_out('>>');
373 $this->_out('endobj');
375 // First page of outlines
376 $this->_newobj();
377 $this->def_outlines = $this->n;
378 $this->_out('<<');
379 $this->_out('/Type');
380 $this->_out('/Outlines');
381 $this->_out('/First ' . $first_level[0] . ' 0 R');
382 $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
383 $this->_out('/Count ' . sizeof($first_level));
384 $this->_out('>>');
385 $this->_out('endobj');
389 function _putresources()
391 parent::_putresources();
392 $this->_putbookmarks();
395 function _putcatalog()
397 parent::_putcatalog();
398 if (count($this->Outlines) > 0) {
399 $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
400 $this->_out('/PageMode /UseOutlines');
403 function SetWidths($w)
405 // column widths
406 $this->widths = $w;
409 function Row($data, $links)
411 // line height
412 $nb = 0;
413 $data_cnt = count($data);
414 for ($i = 0;$i < $data_cnt;$i++)
415 $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
416 $il = $this->FontSize;
417 $h = ($il + 1) * $nb;
418 // page break if necessary
419 $this->CheckPageBreak($h);
420 // draw the cells
421 $data_cnt = count($data);
422 for ($i = 0;$i < $data_cnt;$i++) {
423 $w = $this->widths[$i];
424 // save current position
425 $x = $this->GetX();
426 $y = $this->GetY();
427 // draw the border
428 $this->Rect($x, $y, $w, $h);
429 if (isset($links[$i])) {
430 $this->Link($x, $y, $w, $h, $links[$i]);
432 // print text
433 $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
434 // go to right side
435 $this->SetXY($x + $w, $y);
437 // go to line
438 $this->Ln($h);
441 function CheckPageBreak($h)
443 // if height h overflows, manual page break
444 if ($this->GetY() + $h > $this->PageBreakTrigger) {
445 $this->AddPage($this->CurOrientation);
449 function NbLines($w, $txt)
451 // compute number of lines used by a multicell of width w
452 $cw = &$this->CurrentFont['cw'];
453 if ($w == 0) {
454 $w = $this->w - $this->rMargin - $this->x;
456 $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
457 $s = str_replace("\r", '', $txt);
458 $nb = strlen($s);
459 if ($nb > 0 and $s[$nb-1] == "\n") {
460 $nb--;
462 $sep = -1;
463 $i = 0;
464 $j = 0;
465 $l = 0;
466 $nl = 1;
467 while ($i < $nb) {
468 $c = $s[$i];
469 if ($c == "\n") {
470 $i++;
471 $sep = -1;
472 $j = $i;
473 $l = 0;
474 $nl++;
475 continue;
477 if ($c == ' ') {
478 $sep = $i;
480 $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
481 if ($l > $wmax) {
482 if ($sep == -1) {
483 if ($i == $j) {
484 $i++;
486 } else {
487 $i = $sep + 1;
489 $sep = -1;
490 $j = $i;
491 $l = 0;
492 $nl++;
493 } else {
494 $i++;
497 return $nl;
499 } // end of the "PMA_PDF" class
501 * Draws tables schema
503 * @access private
504 * @see PMA_RT
506 class PMA_RT_Table {
508 * Defines private properties
510 var $nb_fiels;
511 var $table_name;
512 var $width = 0;
513 var $height;
514 var $fields = array();
515 var $height_cell = 6;
516 var $x, $y;
517 var $primary = array();
520 * Sets the width of the table
522 * @param integer $ The font size
523 * @global object The current PDF document
524 * @access private
525 * @see PMA_PDF
527 function PMA_RT_Table_setWidth($ff)
529 // this looks buggy to me... does it really work if
530 // there are fields that require wider cells than the name of the table?
531 global $pdf;
533 foreach ($this->fields AS $field) {
534 $this->width = max($this->width, $pdf->GetStringWidth($field));
536 $this->width += $pdf->GetStringWidth(' ');
537 $pdf->SetFont($ff, 'B');
538 $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
539 $pdf->SetFont($ff, '');
540 } // end of the "PMA_RT_Table_setWidth()" method
542 * Sets the height of the table
544 * @access private
546 function PMA_RT_Table_setHeight()
548 $this->height = (count($this->fields) + 1) * $this->height_cell;
549 } // end of the "PMA_RT_Table_setHeight()" method
551 * Do draw the table
553 * @param boolean $ Whether to display table position or not
554 * @param integer $ The font size
555 * @param boolean $ Whether to display color
556 * @param integer $ The max. with among tables
557 * @global object The current PDF document
558 * @access private
559 * @see PMA_PDF
561 function PMA_RT_Table_draw($show_info, $ff, $setcolor = 0)
563 global $pdf, $with_doc;
565 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
566 $pdf->SetFont($ff, 'B');
567 if ($setcolor) {
568 $pdf->SetTextColor(200);
569 $pdf->SetFillColor(0, 0, 128);
571 if ($with_doc) {
572 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
573 } else {
574 $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
577 if ($show_info) {
578 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) . ' ' . $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
579 } else {
580 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 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 // loic1 : PHP3 fix
589 // if (in_array($field, $this->primary)) {
590 if ($setcolor) {
591 if (in_array($field, $this->primary)) {
592 $pdf->SetFillColor(215, 121, 123);
594 if ($field == $this->displayfield) {
595 $pdf->SetFillColor(142, 159, 224);
598 if ($with_doc) {
599 $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
600 } else {
601 $pdf->PMA_links['doc'][$this->table_name][$field] = '';
604 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
605 $pdf->PMA_PDF_setXScale($this->x);
606 $pdf->SetFillColor(255);
607 } // end while
608 /*if ($pdf->PageNo() > 1) {
609 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
610 } */
611 } // end of the "PMA_RT_Table_draw()" method
613 * The "PMA_RT_Table" constructor
615 * @param string $ The table name
616 * @param integer $ The font size
617 * @param integer $ The max. with among tables
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 PMA_RT_Table($table_name, $ff, &$same_wide_width)
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($GLOBALS['strPdfInvalidTblName'], $table_name));
637 // load fields
638 while ($row = PMA_DBI_fetch_row($result)) {
639 $this->fields[] = $row[0];
641 // height and width
642 $this->PMA_RT_Table_setWidth($ff);
643 $this->PMA_RT_Table_setHeight();
644 if ($same_wide_width < $this->width) {
645 $same_wide_width = $this->width;
647 // x and y
648 $sql = 'SELECT x, y FROM '
649 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
650 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
651 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
652 . ' AND pdf_page_number = ' . $pdf_page_number;
653 $result = PMA_query_as_cu($sql, false, PMA_DBI_QUERY_STORE);
655 if (!$result || !PMA_DBI_num_rows($result)) {
656 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
658 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
659 $this->x = (double) $this->x;
660 $this->y = (double) $this->y;
661 // displayfield
662 $this->displayfield = PMA_getDisplayField($db, $table_name);
663 // index
664 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE);
665 if (PMA_DBI_num_rows($result) > 0) {
666 while ($row = PMA_DBI_fetch_assoc($result)) {
667 if ($row['Key_name'] == 'PRIMARY') {
668 $this->primary[] = $row['Column_name'];
671 } // end if
672 } // end of the "PMA_RT_Table()" method
673 } // end class "PMA_RT_Table"
675 * Draws relation links
677 * @access private
678 * @see PMA_RT
680 class PMA_RT_Relation {
682 * Defines private properties
684 var $x_src, $y_src;
685 var $src_dir ;
686 var $dest_dir;
687 var $x_dest, $y_dest;
688 var $w_tick = 5;
691 * Gets arrows coordinates
693 * @param string $ The current table name
694 * @param string $ The relation column name
695 * @return array Arrows coordinates
696 * @access private
698 function PMA_RT_Relation_getXy($table, $column)
700 $pos = array_search($column, $table->fields);
701 // x_left, x_right, y
702 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
703 } // end of the "PMA_RT_Relation_getXy()" method
705 * Do draws relation links
707 * @param boolean $ Whether to use one color per relation or not
708 * @param integer $ The id of the link to draw
709 * @global object The current PDF document
710 * @access private
711 * @see PMA_PDF
713 function PMA_RT_Relation_draw($change_color, $i)
715 global $pdf;
717 if ($change_color) {
718 $d = $i % 6;
719 $j = ($i - $d) / 6;
720 $j = $j % 4;
721 $j++;
722 $case = array(
723 array(1, 0, 0),
724 array(0, 1, 0),
725 array(0, 0, 1),
726 array(1, 1, 0),
727 array(1, 0, 1),
728 array(0, 1, 1)
730 list ($a, $b, $c) = $case[$d];
731 $e = (1 - ($j - 1) / 6);
732 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
733 } else {
734 $pdf->SetDrawColor(0);
735 } // end if... else...
736 $pdf->PMA_PDF_setLineWidthScale(0.2);
737 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
738 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
739 $pdf->PMA_PDF_setLineWidthScale(0.1);
740 $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);
741 // arrow
742 $root2 = 2 * sqrt(2);
743 $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);
744 $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);
746 $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);
747 $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);
748 $pdf->SetDrawColor(0);
749 } // end of the "PMA_RT_Relation_draw()" method
751 * The "PMA_RT_Relation" constructor
753 * @param string $ The master table name
754 * @param string $ The relation field in the master table
755 * @param string $ The foreign table name
756 * @param string $ The relation field in the foreign table
757 * @access private
758 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
760 function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field)
762 $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field);
763 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
764 $src_left = $src_pos[0] - $this->w_tick;
765 $src_right = $src_pos[1] + $this->w_tick;
766 $dest_left = $dest_pos[0] - $this->w_tick;
767 $dest_right = $dest_pos[1] + $this->w_tick;
769 $d1 = abs($src_left - $dest_left);
770 $d2 = abs($src_right - $dest_left);
771 $d3 = abs($src_left - $dest_right);
772 $d4 = abs($src_right - $dest_right);
773 $d = min($d1, $d2, $d3, $d4);
775 if ($d == $d1) {
776 $this->x_src = $src_pos[0];
777 $this->src_dir = -1;
778 $this->x_dest = $dest_pos[0];
779 $this->dest_dir = -1;
780 } elseif ($d == $d2) {
781 $this->x_src = $src_pos[1];
782 $this->src_dir = 1;
783 $this->x_dest = $dest_pos[0];
784 $this->dest_dir = -1;
785 } elseif ($d == $d3) {
786 $this->x_src = $src_pos[0];
787 $this->src_dir = -1;
788 $this->x_dest = $dest_pos[1];
789 $this->dest_dir = 1;
790 } else {
791 $this->x_src = $src_pos[1];
792 $this->src_dir = 1;
793 $this->x_dest = $dest_pos[1];
794 $this->dest_dir = 1;
796 $this->y_src = $src_pos[2];
797 $this->y_dest = $dest_pos[2];
798 } // end of the "PMA_RT_Relation()" method
799 } // end of the "PMA_RT_Relation" class
801 * Draws and send the database schema
803 * @access public
804 * @see PMA_PDF
806 class PMA_RT {
808 * Defines private properties
810 var $tables = array();
811 var $relations = array();
812 var $ff = PMA_PDF_FONT;
813 var $x_max = 0;
814 var $y_max = 0;
815 var $scale;
816 var $x_min = 100000;
817 var $y_min = 100000;
818 var $t_marg = 10;
819 var $b_marg = 10;
820 var $l_marg = 10;
821 var $r_marg = 10;
822 var $tablewidth;
823 var $same_wide = 0;
826 * Sets X and Y minimum and maximum for a table cell
828 * @param string $ The table name
829 * @access private
831 function PMA_RT_setMinMax($table)
833 $this->x_max = max($this->x_max, $table->x + $table->width);
834 $this->y_max = max($this->y_max, $table->y + $table->height);
835 $this->x_min = min($this->x_min, $table->x);
836 $this->y_min = min($this->y_min, $table->y);
837 } // end of the "PMA_RT_setMinMax()" method
839 * Defines relation objects
841 * @param string $ The master table name
842 * @param string $ The relation field in the master table
843 * @param string $ The foreign table name
844 * @param string $ The relation field in the foreign table
845 * @access private
846 * @see PMA_RT_setMinMax
848 function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field)
850 if (!isset($this->tables[$master_table])) {
851 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth);
852 $this->PMA_RT_setMinMax($this->tables[$master_table]);
854 if (!isset($this->tables[$foreign_table])) {
855 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth);
856 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
858 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
859 } // end of the "PMA_RT_addRelation()" method
861 * Draws the grid
863 * @global object the current PMA_PDF instance
864 * @access private
865 * @see PMA_PDF
867 function PMA_RT_strokeGrid()
869 global $pdf;
871 $pdf->SetMargins(0, 0);
872 $pdf->SetDrawColor(200, 200, 200);
873 // Draws horizontal lines
874 for ($l = 0; $l < 21; $l++) {
875 $pdf->line(0, $l * 10, $pdf->fh, $l * 10);
876 // Avoid duplicates
877 if ($l > 0) {
878 $pdf->SetXY(0, $l * 10);
879 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
880 $pdf->Cell(5, 5, ' ' . $label);
881 } // end if
882 } // end for
883 // Draws vertical lines
884 for ($j = 0; $j < 30 ;$j++) {
885 $pdf->line($j * 10, 0, $j * 10, $pdf->fw);
886 $pdf->SetXY($j * 10, 0);
887 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
888 $pdf->Cell(5, 7, $label);
889 } // end for
890 } // end of the "PMA_RT_strokeGrid()" method
892 * Draws relation arrows
894 * @param boolean $ Whether to use one color per relation or not
895 * @access private
896 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
898 function PMA_RT_drawRelations($change_color)
900 $i = 0;
901 foreach ($this->relations AS $relation) {
902 $relation->PMA_RT_Relation_draw($change_color, $i);
903 $i++;
904 } // end while
905 } // end of the "PMA_RT_drawRelations()" method
907 * Draws tables
909 * @param boolean $ Whether to display table position or not
910 * @access private
911 * @see PMA_RT_Table::PMA_RT_Table_draw()
913 function PMA_RT_drawTables($show_info, $draw_color = 0)
915 foreach ($this->tables AS $table) {
916 $table->PMA_RT_Table_draw($show_info, $this->ff, $draw_color);
918 } // end of the "PMA_RT_drawTables()" method
920 * Ouputs the PDF document to a file
922 * @global object The current PDF document
923 * @global string The current database name
924 * @global integer The current page number (from the
925 * $cfg['Servers'][$i]['table_coords'] table)
926 * @access private
927 * @see PMA_PDF
929 function PMA_RT_showRt()
931 global $pdf, $db, $pdf_page_number, $cfgRelation;
933 $pdf->SetFontSize(14);
934 $pdf->SetLineWidth(0.2);
935 $pdf->SetDisplayMode('fullpage');
936 // Get the name of this pdfpage to use as filename (Mike Beck)
937 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
938 . ' WHERE page_nr = ' . $pdf_page_number;
939 $_name_rs = PMA_query_as_cu($_name_sql);
940 if ($_name_rs) {
941 $_name_row = PMA_DBI_fetch_row($_name_rs);
942 $filename = $_name_row[0] . '.pdf';
944 // i don't know if there is a chance for this to happen, but rather be on the safe side:
945 if (empty($filename)) {
946 $filename = $pdf_page_number . '.pdf';
948 // $pdf->Output($db . '_' . $filename, TRUE);
949 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
950 } // end of the "PMA_RT_showRt()" method
952 * The "PMA_RT" constructor
954 * @param mixed $ The scaling factor
955 * @param integer $ The page number to draw (from the
956 * $cfg['Servers'][$i]['table_coords'] table)
957 * @param boolean $ Whether to display table position or not
958 * @param boolean $ Was originally whether to use one color per
959 * relation or not, now enables/disables color
960 * everywhere, due to some problems printing with color
961 * @param boolean $ Whether to draw grids or not
962 * @param boolean $ Whether all tables should have the same width or not
963 * @global object The current PDF document
964 * @global string The current db name
965 * @global array The relations settings
966 * @access private
967 * @see PMA_PDF
969 function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
971 global $pdf, $db, $cfgRelation, $with_doc;
973 $this->same_wide = $all_tab_same_wide;
974 // Initializes a new document
975 $pdf = new PMA_PDF('L', 'mm', $paper);
976 $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
977 $pdf->cMargin = 0;
978 $pdf->Open();
979 $pdf->SetTitle($pdf->title);
980 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
981 $pdf->AliasNbPages();
983 if ($GLOBALS['charset'] == 'utf-8') {
984 // Force FreeSans for utf-8
985 $this->ff = 'FreeSans';
986 $pdf->AddFont('FreeSans', '', 'FreeSans.php');
987 $pdf->AddFont('FreeSans', 'B', 'FreeSansBold.php');
988 } elseif ($GLOBALS['charset'] == 'iso-8859-2') {
989 // fonts added to phpMyAdmin and considered non-standard by fpdf
990 // (Note: those tahoma fonts are iso-8859-2 based)
991 $this->ff == 'tahoma';
992 $pdf->AddFont('tahoma', '', 'tahoma.php');
993 $pdf->AddFont('tahoma', 'B', 'tahomab.php');
994 } else {
995 $this->ff == 'helvetica';
997 $pdf->SetFont($this->ff, '', 14);
998 $pdf->SetAutoPageBreak('auto');
999 // Gets tables on this page
1000 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
1001 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1002 . ' AND pdf_page_number = ' . $which_rel;
1003 $tab_rs = PMA_query_as_cu($tab_sql, null, PMA_DBI_QUERY_STORE);
1004 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1005 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
1006 // die('No tables');
1007 } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1008 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1009 // $intable = '\'' . implode('\', \'', $alltables) . '\'';
1011 // make doc //
1012 if ($with_doc) {
1013 $pdf->SetAutoPageBreak('auto', 15);
1014 $pdf->cMargin = 1;
1015 PMA_RT_DOC($alltables);
1016 $pdf->SetAutoPageBreak('auto');
1017 $pdf->cMargin = 0;
1020 $pdf->Addpage();
1022 if ($with_doc) {
1023 $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
1024 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1025 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1026 $this->t_marg = 18;
1027 $this->b_marg = 18;
1030 /* snip */
1032 foreach ($alltables AS $table) {
1033 if (!isset($this->tables[$table])) {
1034 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
1037 if ($this->same_wide) {
1038 $this->tables[$table]->width = $this->tablewidth;
1040 $this->PMA_RT_setMinMax($this->tables[$table]);
1042 // Defines the scale factor
1043 $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->fh - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->fw - $this->t_marg - $this->b_marg)) * 100) / 100;
1044 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1045 // Builds and save the PDF document
1046 $pdf->PMA_PDF_setLineWidthScale(0.1);
1048 if ($show_grid) {
1049 $pdf->SetFontSize(10);
1050 $this->PMA_RT_strokeGrid();
1052 $pdf->PMA_PDF_setFontSizeScale(14);
1053 // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
1054 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1055 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1056 // . ' AND master_table IN (' . $intable . ')'
1057 // . ' AND foreign_table IN (' . $intable . ')';
1058 // $result = PMA_query_as_cu($sql);
1060 // lem9:
1061 // previous logic was checking master tables and foreign tables
1062 // but I think that looping on every table of the pdf page as a master
1063 // and finding its foreigns is OK (then we can support innodb)
1064 $seen_a_relation = false;
1065 foreach ($alltables AS $one_table) {
1066 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1067 if ($exist_rel) {
1068 $seen_a_relation = true;
1069 foreach ($exist_rel AS $master_field => $rel) {
1070 // put the foreign table on the schema only if selected
1071 // by the user
1072 // (do not use array_search() because we would have to
1073 // to do a === FALSE and this is not PHP3 compatible)
1074 if (in_array($rel['foreign_table'], $alltables)) {
1075 $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
1077 } // end while
1078 } // end if
1079 } // end while
1080 // loic1: also show tables without relations
1081 // $norelations = TRUE;
1082 // if ($result && PMA_DBI_num_rows($result) > 0) {
1083 // $norelations = FALSE;
1084 // while ($row = PMA_DBI_fetch_assoc($result)) {
1085 // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1086 // }
1087 // }
1088 // if ($norelations == FALSE) {
1089 if ($seen_a_relation) {
1090 $this->PMA_RT_drawRelations($change_color);
1093 $this->PMA_RT_drawTables($show_info, $change_color);
1095 $this->PMA_RT_showRt();
1096 } // end of the "PMA_RT()" method
1097 } // end of the "PMA_RT" class
1099 function PMA_RT_DOC($alltables)
1101 global $db, $pdf, $orientation, $paper;
1102 // TOC
1103 $pdf->addpage($GLOBALS['orientation']);
1104 $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C');
1105 $pdf->Ln(15);
1106 $i = 1;
1107 foreach ($alltables AS $table) {
1108 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1109 $pdf->SetX(10);
1110 // $pdf->Ln(1);
1111 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
1112 $pdf->SetX(10);
1113 $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
1114 // $pdf->Ln(1);
1115 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1116 while ($row = PMA_DBI_fetch_assoc($result)) {
1117 $pdf->SetX(20);
1118 $field_name = $row['Field'];
1119 $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
1120 // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
1122 $lasttable = $table;
1123 $i++;
1125 $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
1126 $pdf->SetX(10);
1127 $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']);
1128 $pdf->SetX(10);
1129 $pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
1130 $z = 0;
1131 foreach ($alltables AS $table) {
1132 $z++;
1133 $pdf->addpage($GLOBALS['orientation']);
1134 $pdf->Bookmark($table);
1135 $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ;
1136 $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
1137 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
1138 $pdf->SetFont('', 'B', 18);
1139 $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
1140 $pdf->SetFont('', '', 8);
1141 $pdf->ln();
1143 $cfgRelation = PMA_getRelationsParam();
1144 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
1145 $comments = PMA_getComments($db, $table);
1147 if ($cfgRelation['mimework']) {
1148 $mime_map = PMA_getMIME($db, $table, true);
1152 * Gets table informations
1154 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';', null, PMA_DBI_QUERY_STORE);
1155 $showtable = PMA_DBI_fetch_assoc($result);
1156 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1157 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1158 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1159 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1160 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1162 PMA_DBI_free_result($result);
1163 unset($result);
1166 * Gets table keys and retains them
1168 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1169 $primary = '';
1170 $indexes = array();
1171 $lastIndex = '';
1172 $indexes_info = array();
1173 $indexes_data = array();
1174 $pk_array = array(); // will be use to emphasis prim. keys in the table
1175 // view
1176 while ($row = PMA_DBI_fetch_assoc($result)) {
1177 // Backups the list of primary keys
1178 if ($row['Key_name'] == 'PRIMARY') {
1179 $primary .= $row['Column_name'] . ', ';
1180 $pk_array[$row['Column_name']] = 1;
1182 // Retains keys informations
1183 if ($row['Key_name'] != $lastIndex) {
1184 $indexes[] = $row['Key_name'];
1185 $lastIndex = $row['Key_name'];
1187 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1188 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1189 if (isset($row['Cardinality'])) {
1190 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1192 // I don't know what does following column mean....
1193 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1194 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1196 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1197 if (isset($row['Sub_part'])) {
1198 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1200 } // end while
1201 if ($result) {
1202 PMA_DBI_free_result($result);
1206 * Gets fields properties
1208 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
1209 $fields_cnt = PMA_DBI_num_rows($result);
1210 // Check if we can use Relations (Mike Beck)
1211 if (!empty($cfgRelation['relation'])) {
1212 // Find which tables are related with the current one and write it in
1213 // an array
1214 $res_rel = PMA_getForeigners($db, $table);
1216 if (count($res_rel) > 0) {
1217 $have_rel = true;
1218 } else {
1219 $have_rel = false;
1221 } else {
1222 $have_rel = false;
1223 } // end if
1225 * Displays the comments of the table if MySQL >= 3.23
1228 $break = false;
1229 if (!empty($show_comment)) {
1230 $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1);
1231 $break = true;
1234 if (!empty($create_time)) {
1235 $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1);
1236 $break = true;
1239 if (!empty($update_time)) {
1240 $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1);
1241 $break = true;
1244 if (!empty($check_time)) {
1245 $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1);
1246 $break = true;
1249 if ($break == true) {
1250 $pdf->Cell(0, 3, '', 0, 1);
1251 $pdf->Ln();
1254 $pdf->SetFont('', 'B');
1255 if (isset($orientation) && $orientation == 'L') {
1256 $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1257 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1258 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1259 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1260 $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1261 $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1262 $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1264 if ($paper == 'A4') {
1265 $comments_width = 67;
1266 } else {
1267 // this is really intended for 'letter'
1269 * @todo find optimal width for all formats
1271 $comments_width = 50;
1273 $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1274 $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
1275 $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
1276 } else {
1277 $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C');
1278 $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C');
1279 $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C');
1280 $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C');
1281 $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C');
1282 $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C');
1283 $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C');
1284 $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C');
1285 $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
1286 $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
1288 $pdf->SetFont('', '');
1290 while ($row = PMA_DBI_fetch_assoc($result)) {
1291 $type = $row['Type'];
1292 // reformat mysql query output - staybyte - 9. June 2001
1293 // loic1: set or enum types: slashes single quotes inside options
1294 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1295 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1296 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1297 $type_nowrap = '';
1299 $binary = 0;
1300 $unsigned = 0;
1301 $zerofill = 0;
1302 } else {
1303 $type_nowrap = ' nowrap="nowrap"';
1304 $type = preg_replace('@BINARY@i', '', $type);
1305 $type = preg_replace('@ZEROFILL@i', '', $type);
1306 $type = preg_replace('@UNSIGNED@i', '', $type);
1307 if (empty($type)) {
1308 $type = '&nbsp;';
1311 $binary = stristr($row['Type'], 'BINARY');
1312 $unsigned = stristr($row['Type'], 'UNSIGNED');
1313 $zerofill = stristr($row['Type'], 'ZEROFILL');
1315 $strAttribute = ' ';
1316 if ($binary) {
1317 $strAttribute = 'BINARY';
1319 if ($unsigned) {
1320 $strAttribute = 'UNSIGNED';
1322 if ($zerofill) {
1323 $strAttribute = 'UNSIGNED ZEROFILL';
1325 if (!isset($row['Default'])) {
1326 if ($row['Null'] != '' && $row['Null'] != 'NO') {
1327 $row['Default'] = 'NULL';
1330 $field_name = $row['Field'];
1331 // $pdf->Ln();
1332 $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
1333 $pdf->Bookmark($field_name, 1, -1);
1334 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
1335 $pdf_row = array($field_name,
1336 $type,
1337 $strAttribute,
1338 ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1339 ((isset($row['Default'])) ? $row['Default'] : ''),
1340 $row['Extra'],
1341 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1342 ((isset($comments[$field_name])) ? $comments[$field_name] : ''),
1343 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '')
1345 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1346 if (isset($res_rel[$field_name]['foreign_table']) AND
1347 isset($res_rel[$field_name]['foreign_field']) AND
1348 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1351 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1352 } else {
1353 unset($links[6]);
1355 $pdf->Row($pdf_row, $links);
1357 /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]);
1358 //echo ' ' . $field_name . '&nbsp;' . "\n";
1360 $pdf->Cell(20, 8, $type, 1, 0, 'L');
1361 $pdf->Cell(20, 8, $strAttribute, 1, 0, 'L');
1362 $pdf->Cell(15, 8, , 1, 0, 'L');
1363 $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1364 $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L');
1365 if ($have_rel) {
1366 if (isset($res_rel[$field_name])) {
1367 $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1370 if ($cfgRelation['commwork']) {
1371 if (isset($comments[$field_name])) {
1372 $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L');
1374 } */
1375 } // end while
1376 $pdf->SetFont('', '', 14);
1377 PMA_DBI_free_result($result);
1378 } //end each
1379 } // end function PMA_RT_DOC
1382 * Main logic
1384 if (!isset($pdf_page_number)) {
1385 $pdf_page_number = 1;
1388 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1389 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1390 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1391 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1392 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1393 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1394 $paper = isset($paper) ? $paper : 'A4';
1395 PMA_DBI_select_db($db);
1397 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper);