lang
[phpmyadmin/crack.git] / pdf_schema.php3
blobf65b542d60c2301901553ad64db27799f3461100
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['allworks']) {
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
376 * @global object The current PDF document
377 * @global object The current relation table object
379 * @access private
381 * @see PMA_PDF
383 function PMA_RT_Table_draw($show_info, $ff, $same_wide = 0)
385 global $pdf, $rt;
387 if (isset($rt->tablewidth) && $rt->tablewidth > 0 && $same_wide == 1){
388 $this->width = $rt->tablewidth;
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 if (in_array($field, $this->primary)) {
408 $pdf->SetFillColor(215, 121, 123);
410 if ($field == $this->displayfield) {
411 $pdf->SetFillColor(142, 159, 224);
413 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', 1);
414 $pdf->PMA_PDF_setXScale($this->x);
415 $pdf->SetFillColor(255);
416 } // end while
418 if ($pdf->PageNo() > 1) {
419 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
421 } // end of the "PMA_RT_Table_draw()" method
425 * The "PMA_RT_Table" constructor
427 * @param string The table name
428 * @param integer The font size
430 * @global object The current PDF document
431 * @global object The current relation table object
432 * @global integer The current page number (from the
433 * $cfg['Servers'][$i]['table_coords'] table)
434 * @global array The relations settings
435 * @global string The current db name
437 * @access private
439 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
440 * PMA_RT_Table::PMA_RT_Table_setHeight
442 function PMA_RT_Table($table_name, $ff)
444 global $pdf, $rt, $pdf_page_number, $cfgRelation, $db;
446 $this->table_name = $table_name;
447 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
448 $result = PMA_mysql_query($sql);
449 if (!$result || !mysql_num_rows($result)) {
450 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
452 // load fields
453 while ($row = PMA_mysql_fetch_array($result)) {
454 $this->fields[] = $row[0];
457 //height and width
458 $this->PMA_RT_Table_setWidth($ff);
459 $this->PMA_RT_Table_setHeight();
460 if ($rt->tablewidth < $this->width) {
461 $rt->tablewidth = $this->width;
464 //x and y
465 $sql = 'SELECT x, y FROM '
466 . PMA_backquote($cfgRelation['table_coords'])
467 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
468 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
469 . ' AND pdf_page_number = ' . $pdf_page_number;
470 $result = PMA_query_as_cu($sql);
472 if (!$result || !mysql_num_rows($result)) {
473 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
475 list($this->x, $this->y) = PMA_mysql_fetch_array($result);
476 $this->x = (double) $this->x;
477 $this->y = (double) $this->y;
479 // displayfield
480 $this->displayfield = PMA_getDisplayField($db, $table_name);
482 // index
483 $sql = 'SHOW index FROM ' . PMA_backquote($table_name);
484 $result = PMA_mysql_query($sql);
485 if ($result && mysql_num_rows($result) > 0) {
486 while ($row = PMA_mysql_fetch_array($result)) {
487 if ($row['Key_name'] == 'PRIMARY') {
488 $this->primary[] = $row['Column_name'];
491 } // end if
492 } // end of the "PMA_RT_Table()" method
493 } // end class "PMA_RT_Table"
498 * Draws relation links
500 * @access private
502 * @see PMA_RT
504 class PMA_RT_Relation
507 * Defines private properties
509 var $x_src, $y_src;
510 var $src_dir ;
511 var $dest_dir;
512 var $x_dest, $y_dest;
513 var $w_tick = 5;
517 * Gets arrows coordinates
519 * @param string The current table name
520 * @param string The relation column name
522 * @return array Arrows coordinates
524 * @access private
526 function PMA_RT_Relation_getXy($table, $column)
528 $pos = array_search($column, $table->fields);
529 // x_left, x_right, y
530 return array($table->x, $table->x + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
531 } // end of the "PMA_RT_Relation_getXy()" method
535 * Do draws relation links
537 * @param boolean Whether to use one color per relation or not
538 * @param integer The id of the link to draw
540 * @global object The current PDF document
542 * @access private
544 * @see PMA_PDF
546 function PMA_RT_Relation_draw($change_color, $i)
548 global $pdf;
550 if ($change_color){
551 $d = $i % 6;
552 $j = ($i - $d) / 6;
553 $j = $j % 4;
554 $j++;
555 $case = array(
556 array(1, 0, 0),
557 array(0, 1, 0),
558 array(0, 0, 1),
559 array(1, 1, 0),
560 array(1, 0, 1),
561 array(0, 1, 1)
563 list ($a, $b, $c) = $case[$d];
564 $e = (1 - ($j - 1) / 6);
565 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); }
566 else {
567 $pdf->SetDrawColor(0);
568 } // end if... else...
570 $pdf->PMA_PDF_setLineWidthScale(0.2);
571 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
572 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
573 $pdf->PMA_PDF_setLineWidthScale(0.1);
574 $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);
576 //arrow
577 $root2 = 2 * sqrt(2);
578 $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);
579 $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_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);
582 $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);
583 $pdf->SetDrawColor(0);
584 } // end of the "PMA_RT_Table_draw()" method
588 * The "PMA_RT_Relation" constructor
590 * @param string The master table name
591 * @param string The relation field in the master table
592 * @param string The foreign table name
593 * @param string The relation field in the foreign table
596 * @access private
598 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
600 function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field)
602 $src_pos = $this->PMA_RT_Relation_getXy($master_table , $master_field);
603 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
604 $src_left = $src_pos[0] - $this->w_tick;
605 $src_right = $src_pos[1] + $this->w_tick;
606 $dest_left = $dest_pos[0] - $this->w_tick;
607 $dest_right = $dest_pos[1] + $this->w_tick;
609 $d1 = abs($src_left - $dest_left);
610 $d2 = abs($src_right - $dest_left);
611 $d3 = abs($src_left - $dest_right);
612 $d4 = abs($src_right - $dest_right);
613 $d = min($d1, $d2, $d3, $d4);
615 if ($d == $d1) {
616 $this->x_src = $src_pos[0];
617 $this->src_dir = -1;
618 $this->x_dest = $dest_pos[0];
619 $this->dest_dir = -1;
620 } else if ($d == $d2) {
621 $this->x_src = $src_pos[1];
622 $this->src_dir = 1;
623 $this->x_dest = $dest_pos[0];
624 $this->dest_dir = -1;
625 } else if ($d == $d3) {
626 $this->x_src = $src_pos[0];
627 $this->src_dir = -1;
628 $this->x_dest = $dest_pos[1];
629 $this->dest_dir = 1;
630 } else {
631 $this->x_src = $src_pos[1];
632 $this->src_dir = 1;
633 $this->x_dest = $dest_pos[1];
634 $this->dest_dir = 1;
636 $this->y_src = $src_pos[2];
637 $this->y_dest = $dest_pos[2];
638 } // end of the "PMA_RT_Relation()" method
639 } // end of the "PMA_RT_Relation" class
644 * Draws and send the database schema
646 * @access public
648 * @see PMA_PDF
650 class PMA_RT
653 * Defines private properties
655 var $tables = array();
656 var $relations = array();
657 var $ff = 'Arial';
658 var $x_max = 0;
659 var $y_max = 0;
660 var $scale;
661 var $x_min = 100000;
662 var $y_min = 100000;
663 var $t_marg = 10;
664 var $b_marg = 10;
665 var $l_marg = 10;
666 var $r_marg = 10;
667 var $tablewidth;
668 var $same_wide = 0;
671 * Sets X and Y minimum and maximum for a table cell
673 * @param string The table name
675 * @access private
677 function PMA_RT_setMinMax($table)
679 $this->x_max = max($this->x_max, $table->x + $table->width);
680 $this->y_max = max($this->y_max, $table->y + $table->height);
681 $this->x_min = min($this->x_min, $table->x);
682 $this->y_min = min($this->y_min, $table->y);
683 } // end of the "PMA_RT_setMinMax()" method
687 * Defines relation objects
689 * @param string The master table name
690 * @param string The relation field in the master table
691 * @param string The foreign table name
692 * @param string The relation field in the foreign table
694 * @access private
696 * @see PMA_RT_setMinMax()
698 function PMA_RT_addRelation($master_table , $master_field, $foreign_table, $foreign_field)
700 if (!isset($this->tables[$master_table])) {
701 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff);
702 $this->PMA_RT_setMinMax($this->tables[$master_table]);
704 if (!isset($this->tables[$foreign_table])) {
705 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff);
706 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
708 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
709 } // end of the "PMA_RT_addRelation()" method
713 * Draws the grid
715 * @global object the current PMA_PDF instance
717 * @access private
719 * @see PMA_PDF
721 function PMA_RT_strokeGrid()
723 global $pdf;
725 $pdf->SetMargins(0, 0);
726 $pdf->SetDrawColor(200, 200, 200);
728 // Draws horizontal lines
729 for ($l = 0; $l < 21; $l++) {
730 $pdf->line(0, $l * 10, 297, $l * 10);
731 // Avoid duplicates
732 if ($l > 0) {
733 $pdf->SetXY(0, $l * 10);
734 $label = (string) $pdf->_FPDF_round(($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
735 $pdf->Cell(5, 5, ' ' . $label);
736 } // end if
737 } // end for
739 // Draws vertical lines
740 for ($j = 0; $j < 30 ;$j++) {
741 $pdf->line($j * 10, 0, $j * 10, 210);
742 $pdf->SetXY($j * 10, 0);
743 $label = (string) $pdf->_FPDF_round(($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
744 $pdf->Cell(5, 7, $label);
745 } // end for
746 } // end of the "PMA_RT_strokeGrid()" method
750 * Draws relation arrows
752 * @param boolean Whether to use one color per relation or not
754 * @access private
756 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
758 function PMA_RT_drawRelations($change_color)
760 $i = 0;
761 reset($this->relations);
762 while (list(, $relation) = each($this->relations)) {
763 $relation->PMA_RT_Relation_draw($change_color, $i);
764 $i++;
765 } // end while
766 } // end of the "PMA_RT_drawRelations()" method
770 * Draws tables
772 * @param boolean Whether to display table position or not
774 * @access private
776 * @see PMA_RT_Table::PMA_RT_Table_draw()
778 function PMA_RT_drawTables($show_info)
780 reset($this->tables);
781 while (list(, $table) = each($this->tables)) {
782 $table->PMA_RT_Table_draw($show_info, $this->ff, $this->same_wide);
784 } // end of the "PMA_RT_drawTables()" method
788 * Ouputs the PDF document to a file
790 * @global object The current PDF document
791 * @global string The current database name
792 * @global integer The current page number (from the
793 * $cfg['Servers'][$i]['table_coords'] table)
795 * @access private
797 * @see PMA_PDF
799 function PMA_RT_showRt()
801 global $pdf, $db, $pdf_page_number;
803 $pdf->SetDisplayMode('fullpage');
804 $pdf->Output($db . '_' . $pdf_page_number . '.pdf', TRUE);
805 //$pdf->Output('', TRUE);
806 } // end of the "PMA_RT_showRt()" method
810 * The "PMA_RT" constructor
812 * @param mixed The scalling factor
813 * @param integer The page number to draw (from the
814 * $cfg['Servers'][$i]['table_coords'] table)
815 * @param boolean Whether to display table position or not
816 * @param boolean Whether to use one color per relation or not
817 * @param boolean Whether to draw grids or not
818 * @param boolean Whether all tables should have the same width or not
820 * @global object The current PDF document
821 * @global string The current db name
822 * @global array The relations settings
824 * @access private
826 * @see PMA_PDF
828 function PMA_RT($scale, $which_rel, $show_info = 0, $change_color = 0 , $show_grid = 0, $all_tab_same_wide = 0)
830 global $pdf, $db, $cfgRelation;;
832 // Font face depends on the current language
833 $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
834 $this->same_wide = $all_tab_same_wide;
836 // Initializes a new document
837 $pdf = new PMA_PDF('L');
838 $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
839 $pdf->cMargin = 0;
840 $pdf->Open();
841 $pdf->SetTitle($pdf->title);
842 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
843 $pdf->AliasNbPages();
844 $pdf->Addpage();
845 $pdf->SetFont($this->ff, '', 14);
846 $pdf->SetAutoPageBreak('auto');
848 // Gets tables on this page
849 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords'])
850 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
851 . ' AND pdf_page_number = ' . $which_rel;
852 $tab_rs = PMA_query_as_cu($tab_sql);
853 if (!mysql_num_rows($tab_rs) > 0) {
854 die('No tables');
856 while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
857 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
858 $intable = '\'' . implode('\', \'', $alltables) . '\'';
861 $sql = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
862 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
863 . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
864 . ' AND master_table IN (' . $intable . ')'
865 . ' AND foreign_table IN (' . $intable . ')';
866 $result = PMA_query_as_cu($sql);
868 // mikebeck: maybe we can show tables without relations if i comment
869 // that out
870 // if (!$result || !mysql_num_rows($result)) {
871 // $pdf->PMA_PDF_die($GLOBALS['strPdfInvalidPageNum']);
872 // }
873 if (isset($result) && $result && mysql_num_rows($result) > 0) {
874 while ($row = PMA_mysql_fetch_array($result)) {
875 $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
877 $norelations = FALSE;
878 } else {
879 reset ($alltables);
880 while (list(, $table) = each ($alltables)) {
881 $this->tables[$table] = new PMA_RT_Table($table, $this->ff);
882 $this->PMA_RT_setMinMax($this->tables[$table]);
884 $norelations = TRUE;
885 } // end if... else...
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);