for Loic
[phpmyadmin/crack.git] / pdf_schema.php3
blob2a0619646feb13bdd4964bcab0eb117955c27c56
1 <?php
2 /* $Id$ */
4 /**
5 * Contributed by Maxime Delorme and merged by lem9
6 */
9 /**
10 * Gets some core scripts
12 require('./libraries/grab_globals.lib.php3');
13 require('./libraries/common.lib.php3');
16 /**
17 * Settings for relation stuff
19 require('./libraries/relation.lib.php3');
20 $cfgRelation = PMA_getRelationsParam();
23 /**
24 * Now in ./libraries/relation.lib.php3 we check for all tables
25 * that we need, but if we don't find them we are quiet about it
26 * so people can work without.
27 * This page is absolutely useless if you didn't set up your tables
28 * correctly, so it is a good place to see which tables we can and
29 * complain ;-)
31 if (!$cfgRelation['pdfwork']) {
32 echo '<font color="red">' . $strError . '</font><br />' . "\n";
33 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php3?' . $url_query . '">';
34 echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
38 /**
39 * Gets the "fpdf" libraries and defines the pdf font path
41 require('./libraries/fpdf/fpdf.php3');
42 // loic1: PHP3 compatibility
43 // define('FPDF_FONTPATH', './libraries/fpdf/font/');
44 $FPDF_font_path = './libraries/fpdf/font/';
47 /**
48 * Emulates the "array_search" function with PHP < 4.0.5
50 if (PMA_PHP_INT_VERSION < 40005) {
51 function array_search($needle, $haystack) {
52 $match = FALSE;
54 reset($haystack);
55 while (list($key, $value) = each($haystack)) {
56 if ($value == $needle) {
57 $match = $key;
59 } // end while
61 return $match;
62 } // end of the "array_search" function
63 } // end if
67 /**
68 * Extends the "FPDF" class and prepares the work
70 * @access public
72 * @see FPDF
74 class PMA_PDF extends FPDF
76 /**
77 * Defines private properties
79 var $x_min;
80 var $y_min;
81 var $l_marg = 10;
82 var $t_marg = 10;
83 var $scale;
84 var $title;
87 /**
88 * The PMA_PDF constructor
90 * This function just refers to the "FPDF" constructor: with PHP3 a class
91 * must have a constructor
93 * @param string The page orientation (p, portrait, l or landscape)
94 * @param string The unit for sizes (pt, mm, cm or in)
95 * @param mixed The page format (A3, A4, A5, letter, legal or an array
96 * with page sizes)
98 * @access public
100 * @see FPDF::FPDF()
102 function PMA_PDF($orientation = 'P', $unit = 'mm', $format = 'A4')
104 $this->FPDF($orientation, $unit, $format);
105 } // end of the "PMA_PDF()" method
109 * Sets the scalling factor, defines minimum coordinates and margins
111 * @param double The scalling factor
112 * @param double The minimum X coordinate
113 * @param double The minimum Y coordinate
114 * @param double The left margin
115 * @param double The top margin
117 * @access public
119 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
121 $this->scale = $scale;
122 $this->x_min = $x_min;
123 $this->y_min = $y_min;
124 if ($this->l_marg != -1) {
125 $this->l_marg = $l_marg;
127 if ($this->t_marg != -1) {
128 $this->t_marg = $t_marg;
130 } // end of the "PMA_PDF_setScale" function
134 * Outputs a scalled cell
136 * @param double The cell width
137 * @param double The cell height
138 * @param string The text to output
139 * @param mixed Wether to add borders or not
140 * @param integer Where to put the cursor once the output is done
141 * @param string Align mode
142 * @param integer Whether to fill the cell with a color or not
144 * @access public
146 * @see FPDF::Cell()
148 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0)
150 $h = $h / $this->scale;
151 $w = $w / $this->scale;
152 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill);
153 } // end of the "PMA_PDF_cellScale" function
157 * Draws a scalled line
159 * @param double The horizontal position of the starting point
160 * @param double The vertical position of the starting point
161 * @param double The horizontal position of the ending point
162 * @param double The vertical position of the ending point
164 * @access public
166 * @see FPDF::Line()
168 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
170 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
171 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
172 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
173 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
174 $this->Line($x1, $y1, $x2, $y2);
175 } // end of the "PMA_PDF_lineScale" function
179 * Sets x and y scalled positions
181 * @param double The x position
182 * @param double The y position
184 * @access public
186 * @see FPDF::SetXY()
188 function PMA_PDF_setXyScale($x, $y)
190 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
191 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
192 $this->SetXY($x, $y);
193 } // end of the "PMA_PDF_setXyScale" function
197 * Sets the X scalled positions
199 * @param double The x position
201 * @access public
203 * @see FPDF::SetX()
205 function PMA_PDF_setXScale($x)
207 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
208 $this->SetX($x);
209 } // end of the "PMA_PDF_setXScale" function
213 * Sets the scalled font size
215 * @param double The font size (in points)
217 * @access public
219 * @see FPDF::SetFontSize()
221 function PMA_PDF_setFontSizeScale($size)
223 // Set font size in points
224 $size = $size / $this->scale;
225 $this->SetFontSize($size);
226 } // end of the "PMA_PDF_setFontSizeScale" function
230 * Sets the scalled line width
232 * @param double The line width
234 * @access public
236 * @see FPDF::SetLineWidth()
238 function PMA_PDF_setLineWidthScale($width)
240 $width = $width / $this->scale;
241 $this->SetLineWidth($width);
242 } // end of the "PMA_PDF_setLineWidthScale" function
246 * Displays an error message
248 * @param string the error mesage
250 * @global array the PMA configuration array
251 * @global integer the current server id
252 * @global string the current language
253 * @global string the charset to convert to
254 * @global string the current database name
255 * @global string the current charset
256 * @global string the current text direction
257 * @global string a localized string
258 * @global string an other localized string
260 * @access public
262 function PMA_PDF_die($error_message = '')
264 global $cfg;
265 global $server, $lang, $convcharset, $db;
266 global $charset, $text_dir, $strRunning, $strDatabase;
268 include('./header.inc.php3');
270 echo '<p><b>PDF - '. $GLOBALS['strError'] . '</b></p>' . "\n";
271 if (!empty($error_message)) {
272 $error_message = htmlspecialchars($error_message);
274 echo '<p>' . "\n";
275 echo ' ' . $error_message . "\n";
276 echo '</p>' . "\n";
278 echo '<a href="db_details_structure.php3'
279 . '?lang=' . $lang
280 . '&amp;convcharset=' . $convcharset
281 . '&amp;server=' . $server
282 . '&amp;db=' . urlencode($db)
283 . '">' . $GLOBALS['strBack'] . '</a>';
284 echo "\n";
286 include('./footer.inc.php3');
287 exit();
288 } // end of the "PMA_PDF_die()" function
292 * Aliases the "Error()" function from the FPDF class to the
293 * "PMA_PDF_die()" one
295 * @param string the error mesage
297 * @access public
299 * @see PMA_PDF_die()
301 function Error($error_message = '')
303 $this->PMA_PDF_die($error_message);
304 } // end of the "Error()" method
305 } // end of the "PMA_PDF" class
309 * Draws tables schema
311 * @access private
313 * @see PMA_RT
315 class PMA_RT_Table
318 * Defines private properties
320 var $nb_fiels;
321 var $table_name;
322 var $width = 0;
323 var $height;
324 var $fields = array();
325 var $height_cell = 6;
326 var $x, $y;
327 var $primary = array();
331 * Sets the width of the table
333 * @param integer The font size
335 * @global object The current PDF document
337 * @access private
339 * @see PMA_PDF
341 function PMA_RT_Table_setWidth($ff)
343 // this looks buggy to me... does it really work if
344 // there are fields that require wider cells than the name of the table?
345 global $pdf;
347 reset($this->fields);
348 while (list(, $field) = each($this->fields)) {
349 $this->width = max($this->width, $pdf->GetStringWidth($field));
351 $this->width += $pdf->GetStringWidth(' ');
352 $pdf->SetFont($ff, 'B');
353 $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
354 $pdf->SetFont($ff, '');
355 } // end of the "PMA_RT_Table_setWidth()" method
359 * Sets the height of the table
361 * @access private
363 function PMA_RT_Table_setHeight()
365 $this->height = (count($this->fields) + 1) * $this->height_cell;
366 } // end of the "PMA_RT_Table_setHeight()" method
370 * Do draw the table
372 * @param boolean Whether to display table position or not
373 * @param integer The font size
374 * @param boolean Whether all tables should have the same width or not
375 * @param integer The max. with among tables
377 * @global object The current PDF document
379 * @access private
381 * @see PMA_PDF
383 function PMA_RT_Table_draw($show_info, $ff, $same_wide = 0, $same_wide_width = 0)
385 global $pdf;
387 if ($same_wide == 1 && $same_wide_width > 0) {
388 $this->width = $same_wide_width;
391 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
392 $pdf->SetFont($ff, 'B');
393 $pdf->SetTextColor(200);
394 $pdf->SetFillColor(0, 0, 128);
395 if ($show_info){
396 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $pdf->_FPDF_round($this->width) . 'x' . $pdf->_FPDF_round($this->height) . ' ' . $this->table_name, 1, 1, 'C', 1);
397 } else {
398 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', 1);
400 $pdf->PMA_PDF_setXScale($this->x);
401 $pdf->SetFont($ff, '');
402 $pdf->SetTextColor(0);
403 $pdf->SetFillColor(255);
405 reset($this->fields);
406 while (list(, $field) = each($this->fields)) {
407 // loic1 : PHP3 fix
408 // if (in_array($field, $this->primary)) {
409 if (PMA_isInto($field, $this->primary) != -1) {
410 $pdf->SetFillColor(215, 121, 123);
412 if ($field == $this->displayfield) {
413 $pdf->SetFillColor(142, 159, 224);
415 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', 1);
416 $pdf->PMA_PDF_setXScale($this->x);
417 $pdf->SetFillColor(255);
418 } // end while
420 if ($pdf->PageNo() > 1) {
421 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
423 } // end of the "PMA_RT_Table_draw()" method
427 * The "PMA_RT_Table" constructor
429 * @param string The table name
430 * @param integer The font size
431 * @param integer The max. with among tables
433 * @global object The current PDF document
434 * @global integer The current page number (from the
435 * $cfg['Servers'][$i]['table_coords'] table)
436 * @global array The relations settings
437 * @global string The current db name
439 * @access private
441 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
442 * PMA_RT_Table::PMA_RT_Table_setHeight
444 function PMA_RT_Table($table_name, $ff, &$same_wide_width)
446 global $pdf, $pdf_page_number, $cfgRelation, $db;
448 $this->table_name = $table_name;
449 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
450 $result = PMA_mysql_query($sql);
451 if (!$result || !mysql_num_rows($result)) {
452 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
454 // load fields
455 while ($row = PMA_mysql_fetch_array($result)) {
456 $this->fields[] = $row[0];
459 //height and width
460 $this->PMA_RT_Table_setWidth($ff);
461 $this->PMA_RT_Table_setHeight();
462 if ($same_wide_width < $this->width) {
463 $same_wide_width = $this->width;
466 //x and y
467 $sql = 'SELECT x, y FROM '
468 . PMA_backquote($cfgRelation['table_coords'])
469 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
470 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
471 . ' AND pdf_page_number = ' . $pdf_page_number;
472 $result = PMA_query_as_cu($sql);
474 if (!$result || !mysql_num_rows($result)) {
475 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
477 list($this->x, $this->y) = PMA_mysql_fetch_array($result);
478 $this->x = (double) $this->x;
479 $this->y = (double) $this->y;
481 // displayfield
482 $this->displayfield = PMA_getDisplayField($db, $table_name);
484 // index
485 $sql = 'SHOW index FROM ' . PMA_backquote($table_name);
486 $result = PMA_mysql_query($sql);
487 if ($result && mysql_num_rows($result) > 0) {
488 while ($row = PMA_mysql_fetch_array($result)) {
489 if ($row['Key_name'] == 'PRIMARY') {
490 $this->primary[] = $row['Column_name'];
493 } // end if
494 } // end of the "PMA_RT_Table()" method
495 } // end class "PMA_RT_Table"
500 * Draws relation links
502 * @access private
504 * @see PMA_RT
506 class PMA_RT_Relation
509 * Defines private properties
511 var $x_src, $y_src;
512 var $src_dir ;
513 var $dest_dir;
514 var $x_dest, $y_dest;
515 var $w_tick = 5;
519 * Gets arrows coordinates
521 * @param string The current table name
522 * @param string The relation column name
524 * @return array Arrows coordinates
526 * @access private
528 function PMA_RT_Relation_getXy($table, $column)
530 $pos = array_search($column, $table->fields);
531 // x_left, x_right, y
532 return array($table->x, $table->x + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
533 } // end of the "PMA_RT_Relation_getXy()" method
537 * Do draws relation links
539 * @param boolean Whether to use one color per relation or not
540 * @param integer The id of the link to draw
542 * @global object The current PDF document
544 * @access private
546 * @see PMA_PDF
548 function PMA_RT_Relation_draw($change_color, $i)
550 global $pdf;
552 if ($change_color){
553 $d = $i % 6;
554 $j = ($i - $d) / 6;
555 $j = $j % 4;
556 $j++;
557 $case = array(
558 array(1, 0, 0),
559 array(0, 1, 0),
560 array(0, 0, 1),
561 array(1, 1, 0),
562 array(1, 0, 1),
563 array(0, 1, 1)
565 list ($a, $b, $c) = $case[$d];
566 $e = (1 - ($j - 1) / 6);
567 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); }
568 else {
569 $pdf->SetDrawColor(0);
570 } // end if... else...
572 $pdf->PMA_PDF_setLineWidthScale(0.2);
573 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
574 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
575 $pdf->PMA_PDF_setLineWidthScale(0.1);
576 $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);
578 //arrow
579 $root2 = 2 * sqrt(2);
580 $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);
581 $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);
583 $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);
584 $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);
585 $pdf->SetDrawColor(0);
586 } // end of the "PMA_RT_Relation_draw()" method
590 * The "PMA_RT_Relation" constructor
592 * @param string The master table name
593 * @param string The relation field in the master table
594 * @param string The foreign table name
595 * @param string The relation field in the foreign table
598 * @access private
600 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
602 function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field)
604 $src_pos = $this->PMA_RT_Relation_getXy($master_table , $master_field);
605 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
606 $src_left = $src_pos[0] - $this->w_tick;
607 $src_right = $src_pos[1] + $this->w_tick;
608 $dest_left = $dest_pos[0] - $this->w_tick;
609 $dest_right = $dest_pos[1] + $this->w_tick;
611 $d1 = abs($src_left - $dest_left);
612 $d2 = abs($src_right - $dest_left);
613 $d3 = abs($src_left - $dest_right);
614 $d4 = abs($src_right - $dest_right);
615 $d = min($d1, $d2, $d3, $d4);
617 if ($d == $d1) {
618 $this->x_src = $src_pos[0];
619 $this->src_dir = -1;
620 $this->x_dest = $dest_pos[0];
621 $this->dest_dir = -1;
622 } else if ($d == $d2) {
623 $this->x_src = $src_pos[1];
624 $this->src_dir = 1;
625 $this->x_dest = $dest_pos[0];
626 $this->dest_dir = -1;
627 } else if ($d == $d3) {
628 $this->x_src = $src_pos[0];
629 $this->src_dir = -1;
630 $this->x_dest = $dest_pos[1];
631 $this->dest_dir = 1;
632 } else {
633 $this->x_src = $src_pos[1];
634 $this->src_dir = 1;
635 $this->x_dest = $dest_pos[1];
636 $this->dest_dir = 1;
638 $this->y_src = $src_pos[2];
639 $this->y_dest = $dest_pos[2];
640 } // end of the "PMA_RT_Relation()" method
641 } // end of the "PMA_RT_Relation" class
646 * Draws and send the database schema
648 * @access public
650 * @see PMA_PDF
652 class PMA_RT
655 * Defines private properties
657 var $tables = array();
658 var $relations = array();
659 var $ff = 'Arial';
660 var $x_max = 0;
661 var $y_max = 0;
662 var $scale;
663 var $x_min = 100000;
664 var $y_min = 100000;
665 var $t_marg = 10;
666 var $b_marg = 10;
667 var $l_marg = 10;
668 var $r_marg = 10;
669 var $tablewidth;
670 var $same_wide = 0;
673 * Sets X and Y minimum and maximum for a table cell
675 * @param string The table name
677 * @access private
679 function PMA_RT_setMinMax($table)
681 $this->x_max = max($this->x_max, $table->x + $table->width);
682 $this->y_max = max($this->y_max, $table->y + $table->height);
683 $this->x_min = min($this->x_min, $table->x);
684 $this->y_min = min($this->y_min, $table->y);
685 } // end of the "PMA_RT_setMinMax()" method
689 * Defines relation objects
691 * @param string The master table name
692 * @param string The relation field in the master table
693 * @param string The foreign table name
694 * @param string The relation field in the foreign table
696 * @access private
698 * @see PMA_RT_setMinMax()
700 function PMA_RT_addRelation($master_table , $master_field, $foreign_table, $foreign_field)
702 if (!isset($this->tables[$master_table])) {
703 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth);
704 $this->PMA_RT_setMinMax($this->tables[$master_table]);
706 if (!isset($this->tables[$foreign_table])) {
707 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth);
708 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
710 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
711 } // end of the "PMA_RT_addRelation()" method
715 * Draws the grid
717 * @global object the current PMA_PDF instance
719 * @access private
721 * @see PMA_PDF
723 function PMA_RT_strokeGrid()
725 global $pdf;
727 $pdf->SetMargins(0, 0);
728 $pdf->SetDrawColor(200, 200, 200);
730 // Draws horizontal lines
731 for ($l = 0; $l < 21; $l++) {
732 $pdf->line(0, $l * 10, 297, $l * 10);
733 // Avoid duplicates
734 if ($l > 0) {
735 $pdf->SetXY(0, $l * 10);
736 $label = (string) $pdf->_FPDF_round(($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
737 $pdf->Cell(5, 5, ' ' . $label);
738 } // end if
739 } // end for
741 // Draws vertical lines
742 for ($j = 0; $j < 30 ;$j++) {
743 $pdf->line($j * 10, 0, $j * 10, 210);
744 $pdf->SetXY($j * 10, 0);
745 $label = (string) $pdf->_FPDF_round(($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
746 $pdf->Cell(5, 7, $label);
747 } // end for
748 } // end of the "PMA_RT_strokeGrid()" method
752 * Draws relation arrows
754 * @param boolean Whether to use one color per relation or not
756 * @access private
758 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
760 function PMA_RT_drawRelations($change_color)
762 $i = 0;
763 reset($this->relations);
764 while (list(, $relation) = each($this->relations)) {
765 $relation->PMA_RT_Relation_draw($change_color, $i);
766 $i++;
767 } // end while
768 } // end of the "PMA_RT_drawRelations()" method
772 * Draws tables
774 * @param boolean Whether to display table position or not
776 * @access private
778 * @see PMA_RT_Table::PMA_RT_Table_draw()
780 function PMA_RT_drawTables($show_info)
782 reset($this->tables);
783 while (list(, $table) = each($this->tables)) {
784 $table->PMA_RT_Table_draw($show_info, $this->ff, $this->same_wide, $this->tablewidth);
786 } // end of the "PMA_RT_drawTables()" method
790 * Ouputs the PDF document to a file
792 * @global object The current PDF document
793 * @global string The current database name
794 * @global integer The current page number (from the
795 * $cfg['Servers'][$i]['table_coords'] table)
797 * @access private
799 * @see PMA_PDF
801 function PMA_RT_showRt()
803 global $pdf, $db, $pdf_page_number;
805 $pdf->SetDisplayMode('fullpage');
806 $pdf->Output($db . '_' . $pdf_page_number . '.pdf', TRUE);
807 //$pdf->Output('', TRUE);
808 } // end of the "PMA_RT_showRt()" method
812 * The "PMA_RT" constructor
814 * @param mixed The scalling factor
815 * @param integer The page number to draw (from the
816 * $cfg['Servers'][$i]['table_coords'] table)
817 * @param boolean Whether to display table position or not
818 * @param boolean Whether to use one color per relation or not
819 * @param boolean Whether to draw grids or not
820 * @param boolean Whether all tables should have the same width or not
822 * @global object The current PDF document
823 * @global string The current db name
824 * @global array The relations settings
826 * @access private
828 * @see PMA_PDF
830 function PMA_RT($scale, $which_rel, $show_info = 0, $change_color = 0 , $show_grid = 0, $all_tab_same_wide = 0)
832 global $pdf, $db, $cfgRelation;;
834 // Font face depends on the current language
835 $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
836 $this->same_wide = $all_tab_same_wide;
838 // Initializes a new document
839 $pdf = new PMA_PDF('L');
840 $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
841 $pdf->cMargin = 0;
842 $pdf->Open();
843 $pdf->SetTitle($pdf->title);
844 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
845 $pdf->AliasNbPages();
846 $pdf->Addpage();
847 $pdf->SetFont($this->ff, '', 14);
848 $pdf->SetAutoPageBreak('auto');
850 // Gets tables on this page
851 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords'])
852 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
853 . ' AND pdf_page_number = ' . $which_rel;
854 $tab_rs = PMA_query_as_cu($tab_sql);
855 if (!$tab_rs || !mysql_num_rows($tab_rs) > 0) {
856 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
857 // die('No tables');
859 while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
860 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
861 $intable = '\'' . implode('\', \'', $alltables) . '\'';
864 $sql = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
865 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
866 . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
867 . ' AND master_table IN (' . $intable . ')'
868 . ' AND foreign_table IN (' . $intable . ')';
869 $result = PMA_query_as_cu($sql);
871 // loic1: also show tables without relations
872 $norelations = TRUE;
873 if ($result && mysql_num_rows($result) > 0) {
874 $norelations = FALSE;
875 while ($row = PMA_mysql_fetch_array($result)) {
876 $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
879 reset ($alltables);
880 while (list(, $table) = each ($alltables)) {
881 if (!isset($this->tables[$table])) {
882 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
883 $this->PMA_RT_setMinMax($this->tables[$table]);
885 } // while
887 // Defines the scale factor
888 if ($scale == 'auto') {
889 $this->scale = ceil(max(($this->x_max - $this->x_min) / (297 - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / (210 - $this->t_marg - $this->b_marg)) * 100) / 100;
890 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
891 } else {
892 $this->scale = $scale;
893 $pdf->PMA_PDF_setScale($scale);
894 } // end if... else...
896 // Builds and save the PDF document
897 $pdf->PMA_PDF_setLineWidthScale(0.1);
899 if ($show_grid) {
900 $pdf->SetFontSize(10);
901 $this->PMA_RT_strokeGrid();
903 $pdf->PMA_PDF_setFontSizeScale(14);
904 if ($norelations == FALSE) {
905 $this->PMA_RT_drawRelations($change_color);
907 $this->PMA_RT_drawTables($show_info);
909 $this->PMA_RT_showRt();
910 } // end of the "PMA_RT()" method
911 } // end of the "PMA_RT" class
917 * Main logic
919 if (!isset($pdf_page_number)) {
920 $pdf_page_number = 1;
922 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
923 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
924 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
925 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
927 PMA_mysql_select_db($db);
929 $rt = new PMA_RT('auto', $pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide);