Fix left frame reloading after dropping table (bug #1034531).
[phpmyadmin/crack.git] / pdf_schema.php
blob523b90beb68a876ecb4eed32007ad52a278c99d6
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Contributed by Maxime Delorme and merged by lem9
7 */
10 /**
11 * Gets some core scripts
13 require_once('./libraries/grab_globals.lib.php');
14 require_once('./libraries/common.lib.php');
17 /**
18 * Settings for relation stuff
20 require_once('./libraries/relation.lib.php');
21 require_once('./libraries/transformations.lib.php');
23 $cfgRelation = PMA_getRelationsParam();
26 /**
27 * Now in ./libraries/relation.lib.php we check for all tables
28 * that we need, but if we don't find them we are quiet about it
29 * so people can work without.
30 * This page is absolutely useless if you didn't set up your tables
31 * correctly, so it is a good place to see which tables we can and
32 * complain ;-)
34 if (!$cfgRelation['pdfwork']) {
35 echo '<font color="red">' . $strError . '</font><br />' . "\n";
36 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">';
37 echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
41 /**
42 * Gets the "fpdf" libraries and defines the pdf font path
44 define('FPDF_FONTPATH','./libraries/fpdf/font/');
45 require_once('./libraries/fpdf/fpdf.php');
48 /**
49 * Extends the "FPDF" class and prepares the work
51 * @access public
53 * @see FPDF
55 class PMA_PDF extends FPDF
57 /**
58 * Defines private properties
60 var $x_min;
61 var $y_min;
62 var $l_marg = 10;
63 var $t_marg = 10;
64 var $scale;
65 var $title;
66 var $PMA_links;
67 var $Outlines=array();
68 var $def_outlines;
69 var $Alias ;
70 var $widths;
72 /**
73 * The PMA_PDF constructor
75 * This function just refers to the "FPDF" constructor: with PHP3 a class
76 * must have a constructor
78 * @param string The page orientation (p, portrait, l or landscape)
79 * @param string The unit for sizes (pt, mm, cm or in)
80 * @param mixed The page format (A3, A4, A5, letter, legal or an array
81 * with page sizes)
83 * @access public
85 * @see FPDF::FPDF()
87 function PMA_PDF($orientation = 'L', $unit = 'mm', $format = 'A4')
89 $this->Alias = array() ;
90 $this->FPDF($orientation, $unit, $format);
91 } // end of the "PMA_PDF()" method
92 function SetAlias($name, $value)
94 $this->Alias[$name] = $value ;
96 function _putpages()
98 if (count($this->Alias) > 0)
100 $nb=$this->page;
101 foreach ($this->Alias AS $alias => $value) {
102 for ($n=1;$n<=$nb;$n++)
103 $this->pages[$n]=str_replace($alias,$value,$this->pages[$n]);
106 parent::_putpages();
110 * Sets the scaling factor, defines minimum coordinates and margins
112 * @param double The scaling factor
113 * @param double The minimum X coordinate
114 * @param double The minimum Y coordinate
115 * @param double The left margin
116 * @param double The top margin
118 * @access public
120 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
122 $this->scale = $scale;
123 $this->x_min = $x_min;
124 $this->y_min = $y_min;
125 if ($this->l_marg != -1) {
126 $this->l_marg = $l_marg;
128 if ($this->t_marg != -1) {
129 $this->t_marg = $t_marg;
131 } // end of the "PMA_PDF_setScale" function
135 * Outputs a scaled cell
137 * @param double The cell width
138 * @param double The cell height
139 * @param string The text to output
140 * @param mixed Wether to add borders or not
141 * @param integer Where to put the cursor once the output is done
142 * @param string Align mode
143 * @param integer Whether to fill the cell with a color or not
145 * @access public
147 * @see FPDF::Cell()
149 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0,$link ='')
151 $h = $h / $this->scale;
152 $w = $w / $this->scale;
153 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill,$link);
154 } // end of the "PMA_PDF_cellScale" function
158 * Draws a scaled line
160 * @param double The horizontal position of the starting point
161 * @param double The vertical position of the starting point
162 * @param double The horizontal position of the ending point
163 * @param double The vertical position of the ending point
165 * @access public
167 * @see FPDF::Line()
169 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
171 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
172 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
173 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
174 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
175 $this->Line($x1, $y1, $x2, $y2);
176 } // end of the "PMA_PDF_lineScale" function
180 * Sets x and y scaled positions
182 * @param double The x position
183 * @param double The y position
185 * @access public
187 * @see FPDF::SetXY()
189 function PMA_PDF_setXyScale($x, $y)
191 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
192 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
193 $this->SetXY($x, $y);
194 } // end of the "PMA_PDF_setXyScale" function
198 * Sets the X scaled positions
200 * @param double The x position
202 * @access public
204 * @see FPDF::SetX()
206 function PMA_PDF_setXScale($x)
208 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
209 $this->SetX($x);
210 } // end of the "PMA_PDF_setXScale" function
214 * Sets the scaled font size
216 * @param double The font size (in points)
218 * @access public
220 * @see FPDF::SetFontSize()
222 function PMA_PDF_setFontSizeScale($size)
224 // Set font size in points
225 $size = $size / $this->scale;
226 $this->SetFontSize($size);
227 } // end of the "PMA_PDF_setFontSizeScale" function
231 * Sets the scaled line width
233 * @param double The line width
235 * @access public
237 * @see FPDF::SetLineWidth()
239 function PMA_PDF_setLineWidthScale($width)
241 $width = $width / $this->scale;
242 $this->SetLineWidth($width);
243 } // end of the "PMA_PDF_setLineWidthScale" function
247 * Displays an error message
249 * @param string the error mesage
251 * @global array the PMA configuration array
252 * @global integer the current server id
253 * @global string the current language
254 * @global string the charset to convert to
255 * @global string the current database name
256 * @global string the current charset
257 * @global string the current text direction
258 * @global string a localized string
259 * @global string an other localized string
261 * @access public
263 function PMA_PDF_die($error_message = '')
265 global $cfg;
266 global $server, $lang, $convcharset, $db;
267 global $charset, $text_dir, $strRunning, $strDatabase;
269 require_once('./header.inc.php');
271 echo '<p><b>PDF - '. $GLOBALS['strError'] . '</b></p>' . "\n";
272 if (!empty($error_message)) {
273 $error_message = htmlspecialchars($error_message);
275 echo '<p>' . "\n";
276 echo ' ' . $error_message . "\n";
277 echo '</p>' . "\n";
279 echo '<a href="db_details_structure.php?' . PMA_generate_common_url($db)
280 . '">' . $GLOBALS['strBack'] . '</a>';
281 echo "\n";
283 require_once('./footer.inc.php');
284 } // end of the "PMA_PDF_die()" function
288 * Aliases the "Error()" function from the FPDF class to the
289 * "PMA_PDF_die()" one
291 * @param string the error mesage
293 * @access public
295 * @see PMA_PDF_die()
297 function Error($error_message = '')
299 $this->PMA_PDF_die($error_message);
300 } // end of the "Error()" method
302 function Header(){
303 //$datefmt
304 // We only show this if we find something in the new pdf_pages table
306 // This function must be named "Header" to work with the FPDF library
308 global $cfgRelation,$db,$pdf_page_number,$with_doc;
309 if ($with_doc){
310 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
311 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
312 . ' AND page_nr = \'' . $pdf_page_number . '\'';
313 $test_rs = PMA_query_as_cu($test_query);
314 $pages = @PMA_DBI_fetch_assoc($test_rs);
315 $this->SetFont('', 'B', 14);
316 $this->Cell(0,6, ucfirst($pages['page_descr']),'B',1,'C');
317 $this->SetFont('', '');
318 $this->Ln();
321 function Footer(){
322 // This function must be named "Footer" to work with the FPDF library
323 global $with_doc;
324 if ($with_doc){
325 $this->SetY(-15);
326 $this->SetFont('', '',14);
327 $this->Cell(0,6, $GLOBALS['strPageNumber'] .' '.$this->PageNo() .'/{nb}','T',0,'C');
328 $this->Cell(0,6, PMA_localisedDate(),0,1,'R');
329 $this->SetY(20);
332 function Bookmark($txt,$level=0,$y=0)
334 //Add a bookmark
335 $this->Outlines[0][]=$level;
336 $this->Outlines[1][]=$txt;
337 $this->Outlines[2][]=$this->page;
338 if ($y==-1)
339 $y=$this->GetY();
340 $this->Outlines[3][]=round($this->hPt-$y*$this->k,2);
343 function _putbookmarks()
345 if (count($this->Outlines)>0)
347 //Save object number
348 $memo_n = $this->n;
349 //Take the number of sub elements for an outline
350 $nb_outlines=sizeof($this->Outlines[0]);
351 $first_level=array();
352 $parent=array();
353 $parent[0]=1;
354 for ($i=0; $i<$nb_outlines; $i++)
356 $level=$this->Outlines[0][$i];
357 $kids=0;
358 $last=-1;
359 $prev=-1;
360 $next=-1;
361 if ($i>0 )
363 $cursor=$i-1;
364 //Take the previous outline in the same level
365 while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
366 $cursor--;
367 if ($this->Outlines[0][$cursor] == $level)
368 $prev=$cursor;
370 if ($i<$nb_outlines-1)
372 $cursor=$i+1;
373 while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level)
375 //Take the immediate kid in level + 1
376 if ($this->Outlines[0][$cursor] == $level+1)
378 $kids++;
379 $last=$cursor;
381 $cursor++;
383 $cursor=$i+1;
384 //Take the next outline in the same level
385 while ($this->Outlines[0][$cursor] > $level && ($cursor+1 < sizeof($this->Outlines[0])))
386 $cursor++;
387 if ($this->Outlines[0][$cursor] == $level)
388 $next=$cursor;
390 $this->_newobj();
391 $parent[$level+1]=$this->n;
392 if ($level == 0)
393 $first_level[]=$this->n;
394 $this->_out('<<');
395 $this->_out('/Title ('.$this->Outlines[1][$i].')');
396 $this->_out('/Parent '.$parent[$level].' 0 R');
397 if ($prev != -1)
398 $this->_out('/Prev '.($memo_n+$prev+1).' 0 R');
399 if ($next != -1)
400 $this->_out('/Next '.($this->n+$next-$i).' 0 R');
401 $this->_out('/Dest ['.(1+(2*$this->Outlines[2][$i])).' 0 R /XYZ null '.$this->Outlines[3][$i].' null]');
402 if ($kids > 0)
404 $this->_out('/First '.($this->n+1).' 0 R');
405 $this->_out('/Last '.($this->n+$last-$i).' 0 R');
406 $this->_out('/Count -'.$kids);
408 $this->_out('>>');
409 $this->_out('endobj');
411 //First page of outlines
412 $this->_newobj();
413 $this->def_outlines = $this->n;
414 $this->_out('<<');
415 $this->_out('/Type');
416 $this->_out('/Outlines');
417 $this->_out('/First '.$first_level[0].' 0 R');
418 $this->_out('/Last '.$first_level[sizeof($first_level)-1].' 0 R');
419 $this->_out('/Count '.sizeof($first_level));
420 $this->_out('>>');
421 $this->_out('endobj');
425 function _putresources()
427 parent::_putresources();
428 $this->_putbookmarks();
431 function _putcatalog()
433 parent::_putcatalog();
434 if (count($this->Outlines)>0)
436 $this->_out('/Outlines '.$this->def_outlines.' 0 R');
437 $this->_out('/PageMode /UseOutlines');
440 function SetWidths($w)
442 // column widths
443 $this->widths=$w;
446 function Row($data,$links)
448 // line height
449 $nb=0;
450 $data_cnt = count($data);
451 for ($i=0;$i<$data_cnt;$i++)
452 $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
453 $il = $this->FontSize;
454 $h=($il+1)*$nb;
455 // page break if necessary
456 $this->CheckPageBreak($h);
457 // draw the cells
458 $data_cnt = count($data);
459 for ($i=0;$i<$data_cnt;$i++)
461 $w=$this->widths[$i];
462 // save current position
463 $x=$this->GetX();
464 $y=$this->GetY();
465 // draw the border
466 $this->Rect($x,$y,$w,$h);
467 if (isset($links[$i]))
468 $this->Link($x,$y,$w,$h,$links[$i]);
469 // print text
470 $this->MultiCell($w,$il+1,$data[$i],0,'L');
471 // go to right side
472 $this->SetXY($x+$w,$y);
474 // go to line
475 $this->Ln($h);
478 function CheckPageBreak($h)
480 // if height h overflows, manual page break
481 if ($this->GetY()+$h>$this->PageBreakTrigger)
482 $this->AddPage($this->CurOrientation);
485 function NbLines($w,$txt)
487 // compute number of lines used by a multicell of width w
488 $cw=&$this->CurrentFont['cw'];
489 if ($w==0)
490 $w=$this->w-$this->rMargin-$this->x;
491 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
492 $s=str_replace("\r",'',$txt);
493 $nb=strlen($s);
494 if ($nb>0 and $s[$nb-1]=="\n")
495 $nb--;
496 $sep=-1;
497 $i=0;
498 $j=0;
499 $l=0;
500 $nl=1;
501 while ($i<$nb)
503 $c=$s[$i];
504 if ($c=="\n")
506 $i++;
507 $sep=-1;
508 $j=$i;
509 $l=0;
510 $nl++;
511 continue;
513 if ($c==' ')
514 $sep=$i;
515 $l+=$cw[$c];
516 if ($l>$wmax)
518 if ($sep==-1)
520 if ($i==$j)
521 $i++;
523 else
524 $i=$sep+1;
525 $sep=-1;
526 $j=$i;
527 $l=0;
528 $nl++;
530 else
531 $i++;
533 return $nl;
536 } // end of the "PMA_PDF" class
540 * Draws tables schema
542 * @access private
544 * @see PMA_RT
546 class PMA_RT_Table
549 * Defines private properties
551 var $nb_fiels;
552 var $table_name;
553 var $width = 0;
554 var $height;
555 var $fields = array();
556 var $height_cell = 6;
557 var $x, $y;
558 var $primary = array();
562 * Sets the width of the table
564 * @param integer The font size
566 * @global object The current PDF document
568 * @access private
570 * @see PMA_PDF
572 function PMA_RT_Table_setWidth($ff)
574 // this looks buggy to me... does it really work if
575 // there are fields that require wider cells than the name of the table?
576 global $pdf;
578 foreach ($this->fields AS $field) {
579 $this->width = max($this->width, $pdf->GetStringWidth($field));
581 $this->width += $pdf->GetStringWidth(' ');
582 $pdf->SetFont($ff, 'B');
583 $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
584 $pdf->SetFont($ff, '');
585 } // end of the "PMA_RT_Table_setWidth()" method
589 * Sets the height of the table
591 * @access private
593 function PMA_RT_Table_setHeight()
595 $this->height = (count($this->fields) + 1) * $this->height_cell;
596 } // end of the "PMA_RT_Table_setHeight()" method
600 * Do draw the table
602 * @param boolean Whether to display table position or not
603 * @param integer The font size
604 * @param boolean Whether to display color
605 * @param integer The max. with among tables
607 * @global object The current PDF document
609 * @access private
611 * @see PMA_PDF
613 function PMA_RT_Table_draw($show_info, $ff, $setcolor=0)
615 global $pdf, $with_doc;
617 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
618 $pdf->SetFont($ff, 'B');
619 if ($setcolor) {
620 $pdf->SetTextColor(200);
621 $pdf->SetFillColor(0, 0, 128);
623 if ($with_doc) $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'],-1);
624 else $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
625 if ($show_info){
626 $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]['-']);
627 } else {
628 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
630 $pdf->PMA_PDF_setXScale($this->x);
631 $pdf->SetFont($ff, '');
632 $pdf->SetTextColor(0);
633 $pdf->SetFillColor(255);
635 foreach ($this->fields AS $field) {
636 // loic1 : PHP3 fix
637 // if (in_array($field, $this->primary)) {
638 if ($setcolor) {
639 if (PMA_isInto($field, $this->primary) != -1) {
640 $pdf->SetFillColor(215, 121, 123);
642 if ($field == $this->displayfield) {
643 $pdf->SetFillColor(142, 159, 224);
646 if ($with_doc) $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field],-1);
647 else $pdf->PMA_links['doc'][$this->table_name][$field] = '';
650 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor,$pdf->PMA_links['doc'][$this->table_name][$field]);
651 $pdf->PMA_PDF_setXScale($this->x);
652 $pdf->SetFillColor(255);
653 } // end while
655 /*if ($pdf->PageNo() > 1) {
656 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
657 } */
658 } // end of the "PMA_RT_Table_draw()" method
662 * The "PMA_RT_Table" constructor
664 * @param string The table name
665 * @param integer The font size
666 * @param integer The max. with among tables
668 * @global object The current PDF document
669 * @global integer The current page number (from the
670 * $cfg['Servers'][$i]['table_coords'] table)
671 * @global array The relations settings
672 * @global string The current db name
674 * @access private
676 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
677 * PMA_RT_Table::PMA_RT_Table_setHeight
679 function PMA_RT_Table($table_name, $ff, &$same_wide_width)
681 global $pdf, $pdf_page_number, $cfgRelation, $db;
683 $this->table_name = $table_name;
684 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
685 $result = PMA_DBI_try_query($sql, NULL, PMA_DBI_QUERY_STORE);
686 if (!$result || !PMA_DBI_num_rows($result)) {
687 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
689 // load fields
690 while ($row = PMA_DBI_fetch_row($result)) {
691 $this->fields[] = $row[0];
694 //height and width
695 $this->PMA_RT_Table_setWidth($ff);
696 $this->PMA_RT_Table_setHeight();
697 if ($same_wide_width < $this->width) {
698 $same_wide_width = $this->width;
701 //x and y
702 $sql = 'SELECT x, y FROM '
703 . PMA_backquote($cfgRelation['table_coords'])
704 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
705 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
706 . ' AND pdf_page_number = ' . $pdf_page_number;
707 $result = PMA_query_as_cu($sql, FALSE, PMA_DBI_QUERY_STORE);
709 if (!$result || !PMA_DBI_num_rows($result)) {
710 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
712 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
713 $this->x = (double) $this->x;
714 $this->y = (double) $this->y;
715 // displayfield
716 $this->displayfield = PMA_getDisplayField($db, $table_name);
718 // index
719 $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', NULL, PMA_DBI_QUERY_STORE);
720 if (PMA_DBI_num_rows($result) > 0) {
721 while ($row = PMA_DBI_fetch_assoc($result)) {
722 if ($row['Key_name'] == 'PRIMARY') {
723 $this->primary[] = $row['Column_name'];
726 } // end if
727 } // end of the "PMA_RT_Table()" method
728 } // end class "PMA_RT_Table"
733 * Draws relation links
735 * @access private
737 * @see PMA_RT
739 class PMA_RT_Relation
742 * Defines private properties
744 var $x_src, $y_src;
745 var $src_dir ;
746 var $dest_dir;
747 var $x_dest, $y_dest;
748 var $w_tick = 5;
752 * Gets arrows coordinates
754 * @param string The current table name
755 * @param string The relation column name
757 * @return array Arrows coordinates
759 * @access private
761 function PMA_RT_Relation_getXy($table, $column)
763 $pos = array_search($column, $table->fields);
764 // x_left, x_right, y
765 return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
766 } // end of the "PMA_RT_Relation_getXy()" method
770 * Do draws relation links
772 * @param boolean Whether to use one color per relation or not
773 * @param integer The id of the link to draw
775 * @global object The current PDF document
777 * @access private
779 * @see PMA_PDF
781 function PMA_RT_Relation_draw($change_color, $i)
783 global $pdf;
785 if ($change_color){
786 $d = $i % 6;
787 $j = ($i - $d) / 6;
788 $j = $j % 4;
789 $j++;
790 $case = array(
791 array(1, 0, 0),
792 array(0, 1, 0),
793 array(0, 0, 1),
794 array(1, 1, 0),
795 array(1, 0, 1),
796 array(0, 1, 1)
798 list ($a, $b, $c) = $case[$d];
799 $e = (1 - ($j - 1) / 6);
800 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); }
801 else {
802 $pdf->SetDrawColor(0);
803 } // end if... else...
805 $pdf->PMA_PDF_setLineWidthScale(0.2);
806 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
807 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
808 $pdf->PMA_PDF_setLineWidthScale(0.1);
809 $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);
811 //arrow
812 $root2 = 2 * sqrt(2);
813 $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);
814 $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);
816 $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);
817 $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);
818 $pdf->SetDrawColor(0);
819 } // end of the "PMA_RT_Relation_draw()" method
823 * The "PMA_RT_Relation" constructor
825 * @param string The master table name
826 * @param string The relation field in the master table
827 * @param string The foreign table name
828 * @param string The relation field in the foreign table
831 * @access private
833 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
835 function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field)
837 $src_pos = $this->PMA_RT_Relation_getXy($master_table , $master_field);
838 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
839 $src_left = $src_pos[0] - $this->w_tick;
840 $src_right = $src_pos[1] + $this->w_tick;
841 $dest_left = $dest_pos[0] - $this->w_tick;
842 $dest_right = $dest_pos[1] + $this->w_tick;
844 $d1 = abs($src_left - $dest_left);
845 $d2 = abs($src_right - $dest_left);
846 $d3 = abs($src_left - $dest_right);
847 $d4 = abs($src_right - $dest_right);
848 $d = min($d1, $d2, $d3, $d4);
850 if ($d == $d1) {
851 $this->x_src = $src_pos[0];
852 $this->src_dir = -1;
853 $this->x_dest = $dest_pos[0];
854 $this->dest_dir = -1;
855 } else if ($d == $d2) {
856 $this->x_src = $src_pos[1];
857 $this->src_dir = 1;
858 $this->x_dest = $dest_pos[0];
859 $this->dest_dir = -1;
860 } else if ($d == $d3) {
861 $this->x_src = $src_pos[0];
862 $this->src_dir = -1;
863 $this->x_dest = $dest_pos[1];
864 $this->dest_dir = 1;
865 } else {
866 $this->x_src = $src_pos[1];
867 $this->src_dir = 1;
868 $this->x_dest = $dest_pos[1];
869 $this->dest_dir = 1;
871 $this->y_src = $src_pos[2];
872 $this->y_dest = $dest_pos[2];
873 } // end of the "PMA_RT_Relation()" method
874 } // end of the "PMA_RT_Relation" class
879 * Draws and send the database schema
881 * @access public
883 * @see PMA_PDF
885 class PMA_RT
888 * Defines private properties
890 var $tables = array();
891 var $relations = array();
892 var $ff = 'Arial';
893 var $x_max = 0;
894 var $y_max = 0;
895 var $scale;
896 var $x_min = 100000;
897 var $y_min = 100000;
898 var $t_marg = 10;
899 var $b_marg = 10;
900 var $l_marg = 10;
901 var $r_marg = 10;
902 var $tablewidth;
903 var $same_wide = 0;
906 * Sets X and Y minimum and maximum for a table cell
908 * @param string The table name
910 * @access private
912 function PMA_RT_setMinMax($table)
914 $this->x_max = max($this->x_max, $table->x + $table->width);
915 $this->y_max = max($this->y_max, $table->y + $table->height);
916 $this->x_min = min($this->x_min, $table->x);
917 $this->y_min = min($this->y_min, $table->y);
918 } // end of the "PMA_RT_setMinMax()" method
922 * Defines relation objects
924 * @param string The master table name
925 * @param string The relation field in the master table
926 * @param string The foreign table name
927 * @param string The relation field in the foreign table
929 * @access private
931 * @see PMA_RT_setMinMax()
933 function PMA_RT_addRelation($master_table , $master_field, $foreign_table, $foreign_field)
935 if (!isset($this->tables[$master_table])) {
936 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth);
937 $this->PMA_RT_setMinMax($this->tables[$master_table]);
939 if (!isset($this->tables[$foreign_table])) {
940 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth);
941 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
943 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
944 } // end of the "PMA_RT_addRelation()" method
948 * Draws the grid
950 * @global object the current PMA_PDF instance
952 * @access private
954 * @see PMA_PDF
956 function PMA_RT_strokeGrid()
958 global $pdf;
960 $pdf->SetMargins(0, 0);
961 $pdf->SetDrawColor(200, 200, 200);
963 // Draws horizontal lines
964 for ($l = 0; $l < 21; $l++) {
965 $pdf->line(0, $l * 10, $pdf->fh, $l * 10);
966 // Avoid duplicates
967 if ($l > 0) {
968 $pdf->SetXY(0, $l * 10);
969 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
970 $pdf->Cell(5, 5, ' ' . $label);
971 } // end if
972 } // end for
974 // Draws vertical lines
975 for ($j = 0; $j < 30 ;$j++) {
976 $pdf->line($j * 10, 0, $j * 10, $pdf->fw);
977 $pdf->SetXY($j * 10, 0);
978 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
979 $pdf->Cell(5, 7, $label);
980 } // end for
981 } // end of the "PMA_RT_strokeGrid()" method
985 * Draws relation arrows
987 * @param boolean Whether to use one color per relation or not
989 * @access private
991 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
993 function PMA_RT_drawRelations($change_color)
995 $i = 0;
996 foreach ($this->relations AS $relation) {
997 $relation->PMA_RT_Relation_draw($change_color, $i);
998 $i++;
999 } // end while
1000 } // end of the "PMA_RT_drawRelations()" method
1004 * Draws tables
1006 * @param boolean Whether to display table position or not
1008 * @access private
1010 * @see PMA_RT_Table::PMA_RT_Table_draw()
1012 function PMA_RT_drawTables($show_info,$draw_color=0)
1014 foreach ($this->tables AS $table) {
1015 $table->PMA_RT_Table_draw($show_info, $this->ff,$draw_color);
1017 } // end of the "PMA_RT_drawTables()" method
1021 * Ouputs the PDF document to a file
1023 * @global object The current PDF document
1024 * @global string The current database name
1025 * @global integer The current page number (from the
1026 * $cfg['Servers'][$i]['table_coords'] table)
1028 * @access private
1030 * @see PMA_PDF
1032 function PMA_RT_showRt()
1034 global $pdf, $db, $pdf_page_number, $cfgRelation;
1036 $pdf->SetFontSize(14);
1037 $pdf->SetLineWidth(0.2);
1038 $pdf->SetDisplayMode('fullpage');
1039 // Get the name of this pdfpage to use as filename (Mike Beck)
1040 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
1041 . ' WHERE page_nr = ' . $pdf_page_number;
1042 $_name_rs = PMA_query_as_cu($_name_sql);
1043 if ($_name_rs) {
1044 $_name_row = PMA_DBI_fetch_row($_name_rs);
1045 $filename = $_name_row[0] . '.pdf';
1047 // i don't know if there is a chance for this to happen, but rather be on the safe side:
1048 if (empty($filename)) {
1049 $filename = $pdf_page_number . '.pdf';
1051 //$pdf->Output($db . '_' . $filename, TRUE);
1052 $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline
1053 } // end of the "PMA_RT_showRt()" method
1057 * The "PMA_RT" constructor
1059 * @param mixed The scaling factor
1060 * @param integer The page number to draw (from the
1061 * $cfg['Servers'][$i]['table_coords'] table)
1062 * @param boolean Whether to display table position or not
1063 * @param boolean Was originally whether to use one color per
1064 * relation or not, now enables/disables color
1065 * everywhere, due to some problems printing with color
1066 * @param boolean Whether to draw grids or not
1067 * @param boolean Whether all tables should have the same width or not
1069 * @global object The current PDF document
1070 * @global string The current db name
1071 * @global array The relations settings
1073 * @access private
1075 * @see PMA_PDF
1077 function PMA_RT( $which_rel, $show_info = 0, $change_color = 0 , $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
1079 global $pdf, $db, $cfgRelation, $with_doc;
1081 // Font face depends on the current language
1082 $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
1083 $this->same_wide = $all_tab_same_wide;
1085 // Initializes a new document
1086 $pdf = new PMA_PDF('L', 'mm', $paper);
1087 $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
1088 $pdf->cMargin = 0;
1089 $pdf->Open();
1090 $pdf->SetTitle($pdf->title);
1091 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
1092 $pdf->AliasNbPages();
1094 // fonts added to phpMyAdmin and considered non-standard by fpdf
1095 // (Note: those tahoma fonts are iso-8859-2 based)
1096 if ($this->ff == 'tahoma') {
1097 $pdf->AddFont('tahoma','','tahoma.php');
1098 $pdf->AddFont('tahoma','B','tahomab.php');
1101 $pdf->SetFont($this->ff, '', 14);
1102 $pdf->SetAutoPageBreak('auto');
1104 // Gets tables on this page
1105 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords'])
1106 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1107 . ' AND pdf_page_number = ' . $which_rel;
1108 $tab_rs = PMA_query_as_cu($tab_sql, NULL, PMA_DBI_QUERY_STORE);
1109 if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
1110 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
1111 // die('No tables');
1113 while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) {
1114 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1115 //$intable = '\'' . implode('\', \'', $alltables) . '\'';
1118 // make doc //
1119 if ($with_doc) {
1120 $pdf->SetAutoPageBreak('auto',15);
1121 $pdf->cMargin = 1;
1122 PMA_RT_DOC($alltables);
1123 $pdf->SetAutoPageBreak('auto');
1124 $pdf->cMargin = 0;
1127 $pdf->Addpage();
1130 if ($with_doc) {
1131 $pdf->SetLink($pdf->PMA_links['RT']['-'],-1);
1132 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1133 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1134 $this->t_marg = 18;
1135 $this->b_marg = 18;
1138 /* snip */
1140 foreach ($alltables AS $table) {
1141 if (!isset($this->tables[$table])) {
1142 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
1145 if ($this->same_wide){
1146 $this->tables[$table]->width = $this->tablewidth;
1148 $this->PMA_RT_setMinMax($this->tables[$table]);
1150 // Defines the scale factor
1151 $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;
1152 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1155 // Builds and save the PDF document
1156 $pdf->PMA_PDF_setLineWidthScale(0.1);
1158 if ($show_grid) {
1159 $pdf->SetFontSize(10);
1160 $this->PMA_RT_strokeGrid();
1162 $pdf->PMA_PDF_setFontSizeScale(14);
1165 // $sql = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
1166 // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1167 // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1168 // . ' AND master_table IN (' . $intable . ')'
1169 // . ' AND foreign_table IN (' . $intable . ')';
1170 // $result = PMA_query_as_cu($sql);
1172 // lem9:
1173 // previous logic was checking master tables and foreign tables
1174 // but I think that looping on every table of the pdf page as a master
1175 // and finding its foreigns is OK (then we can support innodb)
1177 $seen_a_relation = FALSE;
1178 foreach ($alltables AS $one_table) {
1180 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
1181 if ($exist_rel) {
1182 $seen_a_relation = TRUE;
1183 foreach ($exist_rel AS $master_field => $rel) {
1184 // put the foreign table on the schema only if selected
1185 // by the user
1186 // (do not use array_search() because we would have to
1187 // to do a === FALSE and this is not PHP3 compatible)
1189 if (PMA_isInto($rel['foreign_table'], $alltables)> -1) {
1190 $this->PMA_RT_addRelation($one_table , $master_field, $rel['foreign_table'], $rel['foreign_field']);
1193 } // end while
1194 } // end if
1195 } // end while
1197 // loic1: also show tables without relations
1198 // $norelations = TRUE;
1199 // if ($result && PMA_DBI_num_rows($result) > 0) {
1200 // $norelations = FALSE;
1201 // while ($row = PMA_DBI_fetch_assoc($result)) {
1202 // $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1203 // }
1204 // }
1207 // if ($norelations == FALSE) {
1208 if ($seen_a_relation) {
1209 $this->PMA_RT_drawRelations($change_color);
1212 $this->PMA_RT_drawTables($show_info,$change_color);
1214 $this->PMA_RT_showRt();
1215 } // end of the "PMA_RT()" method
1216 } // end of the "PMA_RT" class
1218 function PMA_RT_DOC($alltables ){
1219 global $db, $pdf, $orientation, $paper;
1220 //TOC
1221 $pdf->addpage($GLOBALS['orientation']);
1222 $pdf->Cell(0,9, $GLOBALS['strTableOfContents'],1,0,'C');
1223 $pdf->Ln(15);
1224 $i = 1;
1225 foreach ($alltables AS $table) {
1226 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1227 $pdf->SetX(10);
1228 //$pdf->Ln(1);
1229 $pdf->Cell(0,6,$GLOBALS['strPageNumber'] . ' {'.sprintf("%02d", $i).'}',0,0,'R',0,$pdf->PMA_links['doc'][$table]['-']);
1230 $pdf->SetX(10);
1231 $pdf->Cell(0,6,$i.' '. $table,0,1,'L',0,$pdf->PMA_links['doc'][$table]['-']);
1233 //$pdf->Ln(1);
1234 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
1235 while ($row = PMA_DBI_fetch_assoc($result)) {
1236 $pdf->SetX(20);
1237 $field_name = $row['Field'];
1238 $pdf->PMA_links['doc'][$table][$field_name] =$pdf->AddLink();
1239 //$pdf->Cell(0,6,$field_name,0,1,'L',0,$pdf->PMA_links['doc'][$table][$field_name]);
1241 $lasttable = $table;
1242 $i++;
1244 $pdf->PMA_links['RT']['-'] =$pdf->AddLink();
1245 $pdf->SetX(10);
1246 $pdf->Cell(0,6,$GLOBALS['strPageNumber'] . ' {00}',0,0,'R',0,$pdf->PMA_links['doc'][$lasttable]['-']);
1247 $pdf->SetX(10);
1248 $pdf->Cell(0,6,$i.' '. $GLOBALS['strRelationalSchema'],0,1,'L',0,$pdf->PMA_links['RT']['-']);
1249 $z = 0;
1250 foreach ($alltables AS $table) {
1251 $z++;
1252 $pdf->addpage($GLOBALS['orientation']);
1253 $pdf->Bookmark($table);
1254 $pdf->SetAlias('{'.sprintf("%02d", $z).'}', $pdf->PageNo()) ;
1255 $pdf->PMA_links['RT'][$table]['-'] =$pdf->AddLink();
1256 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'],-1);
1257 $pdf->SetFont('', 'B',18);
1258 $pdf->Cell(0,8, $z .' '.$table,1,1,'C',0,$pdf->PMA_links['RT'][$table]['-']);
1259 $pdf->SetFont('', '',8);
1260 $pdf->ln();
1262 $cfgRelation = PMA_getRelationsParam();
1263 if ($cfgRelation['commwork']) {
1264 $comments = PMA_getComments($db, $table);
1266 if ($cfgRelation['mimework']) {
1267 $mime_map = PMA_getMIME($db, $table, true);
1272 * Gets table informations
1274 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';', NULL, PMA_DBI_QUERY_STORE);
1275 $showtable = PMA_DBI_fetch_assoc($result);
1276 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1277 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1278 $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '');
1279 $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '');
1280 $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '');
1282 PMA_DBI_free_result($result);
1283 unset($result);
1287 * Gets table keys and retains them
1289 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
1290 $primary = '';
1291 $indexes = array();
1292 $lastIndex = '';
1293 $indexes_info = array();
1294 $indexes_data = array();
1295 $pk_array = array(); // will be use to emphasis prim. keys in the table
1296 // view
1297 while ($row = PMA_DBI_fetch_assoc($result)) {
1298 // Backups the list of primary keys
1299 if ($row['Key_name'] == 'PRIMARY') {
1300 $primary .= $row['Column_name'] . ', ';
1301 $pk_array[$row['Column_name']] = 1;
1303 // Retains keys informations
1304 if ($row['Key_name'] != $lastIndex ){
1305 $indexes[] = $row['Key_name'];
1306 $lastIndex = $row['Key_name'];
1308 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1309 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1310 if (isset($row['Cardinality'])) {
1311 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1313 // I don't know what does following column mean....
1314 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1315 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1317 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1318 if (isset($row['Sub_part'])) {
1319 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1322 } // end while
1323 if ($result) {
1324 PMA_DBI_free_result($result);
1329 * Gets fields properties
1331 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE);
1332 $fields_cnt = PMA_DBI_num_rows($result);
1335 // Check if we can use Relations (Mike Beck)
1336 if (!empty($cfgRelation['relation'])) {
1337 // Find which tables are related with the current one and write it in
1338 // an array
1339 $res_rel = PMA_getForeigners($db, $table);
1341 if (count($res_rel) > 0) {
1342 $have_rel = TRUE;
1343 } else {
1344 $have_rel = FALSE;
1347 else {
1348 $have_rel = FALSE;
1349 } // end if
1353 * Displays the comments of the table if MySQL >= 3.23
1356 $break = false;
1357 if (!empty($show_comment)) {
1358 $pdf->Cell(0,3,$GLOBALS['strTableComments'] . ' : ' . $show_comment,0,1);
1359 $break = true;
1362 if (!empty($create_time)) {
1363 $pdf->Cell(0,3,$GLOBALS['strStatCreateTime'] . ': ' . $create_time,0,1);
1364 $break = true;
1367 if (!empty($update_time)) {
1368 $pdf->Cell(0,3,$GLOBALS['strStatUpdateTime'] . ': ' . $update_time,0,1);
1369 $break = true;
1372 if (!empty($check_time)) {
1373 $pdf->Cell(0,3,$GLOBALS['strStatCheckTime'] . ': ' . $check_time,0,1);
1374 $break = true;
1377 if ($break == true) {
1378 $pdf->Cell(0,3,'',0,1);
1379 $pdf->Ln();
1382 $i = 0;
1383 $pdf->SetFont('', 'B');
1384 if (isset($orientation) && $orientation == 'L') {
1385 $pdf->Cell(25,8,ucfirst($GLOBALS['strField']),1,0,'C');
1386 $pdf->Cell(20,8,ucfirst($GLOBALS['strType']),1,0,'C');
1387 $pdf->Cell(20,8,ucfirst($GLOBALS['strAttr']),1,0,'C');
1388 $pdf->Cell(10,8,ucfirst($GLOBALS['strNull']),1,0,'C');
1389 $pdf->Cell(20,8,ucfirst($GLOBALS['strDefault']),1,0,'C');
1390 $pdf->Cell(25,8,ucfirst($GLOBALS['strExtra']),1,0,'C');
1391 $pdf->Cell(45,8,ucfirst($GLOBALS['strLinksTo']),1,0,'C');
1393 if ($paper == 'A4') {
1394 $comments_width = 67;
1395 } else {
1396 // this is really intended for 'letter'
1397 // TODO: find optimal width for all formats
1398 $comments_width = 50;
1400 $pdf->Cell($comments_width,8,ucfirst($GLOBALS['strComments']),1,0,'C');
1401 $pdf->Cell(45,8,'MIME',1,1,'C');
1402 $pdf->SetWidths(array(25,20,20,10,20,25,45,$comments_width,45));
1403 } else {
1404 $pdf->Cell(20,8,ucfirst($GLOBALS['strField']),1,0,'C');
1405 $pdf->Cell(20,8,ucfirst($GLOBALS['strType']),1,0,'C');
1406 $pdf->Cell(20,8,ucfirst($GLOBALS['strAttr']),1,0,'C');
1407 $pdf->Cell(10,8,ucfirst($GLOBALS['strNull']),1,0,'C');
1408 $pdf->Cell(15,8,ucfirst($GLOBALS['strDefault']),1,0,'C');
1409 $pdf->Cell(15,8,ucfirst($GLOBALS['strExtra']),1,0,'C');
1410 $pdf->Cell(30,8,ucfirst($GLOBALS['strLinksTo']),1,0,'C');
1411 $pdf->Cell(30,8,ucfirst($GLOBALS['strComments']),1,0,'C');
1412 $pdf->Cell(30,8,'MIME',1,1,'C');
1413 $pdf->SetWidths(array(20,20,20,10,15,15,30,30,30));
1415 $pdf->SetFont('', '');
1417 while ($row = PMA_DBI_fetch_assoc($result)) {
1418 $bgcolor = ($i % 2) ?$GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1419 $i++;
1421 $type = $row['Type'];
1422 // reformat mysql query output - staybyte - 9. June 2001
1423 // loic1: set or enum types: slashes single quotes inside options
1424 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
1425 $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1);
1426 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1427 $type_nowrap = '';
1429 $binary = 0;
1430 $unsigned = 0;
1431 $zerofill = 0;
1432 } else {
1433 $type_nowrap = ' nowrap="nowrap"';
1434 $type = preg_replace('@BINARY@i', '', $type);
1435 $type = preg_replace('@ZEROFILL@i', '', $type);
1436 $type = preg_replace('@UNSIGNED@i', '', $type);
1437 if (empty($type)) {
1438 $type = '&nbsp;';
1441 $binary = stristr($row['Type'], 'BINARY');
1442 $unsigned = stristr($row['Type'], 'UNSIGNED');
1443 $zerofill = stristr($row['Type'], 'ZEROFILL');
1445 $strAttribute = ' ';
1446 if ($binary) {
1447 $strAttribute = 'BINARY';
1449 if ($unsigned) {
1450 $strAttribute = 'UNSIGNED';
1452 if ($zerofill) {
1453 $strAttribute = 'UNSIGNED ZEROFILL';
1455 if (!isset($row['Default'])) {
1456 if ($row['Null'] != '') {
1457 $row['Default'] = 'NULL';
1460 $field_name = $row['Field'];
1461 //$pdf->Ln();
1462 $pdf->PMA_links['RT'][$table][$field_name] =$pdf->AddLink();
1463 $pdf->Bookmark($field_name,1,-1);
1464 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name],-1);
1465 $pdf_row = array($field_name ,
1466 $type ,
1467 $strAttribute ,
1468 ($row['Null'] == '') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1469 ((isset($row['Default'])) ? $row['Default'] : ''),
1470 $row['Extra'] ,
1471 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1472 ((isset($comments[$field_name])) ? $comments[$field_name] : '' ),
1473 ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '' )
1475 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1476 if (isset($res_rel[$field_name]['foreign_table']) AND
1477 isset($res_rel[$field_name]['foreign_field']) AND
1478 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1479 ) $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1480 else unset($links[6]);
1481 $pdf->Row($pdf_row, $links);
1483 /*$pdf->Cell(20,8,$field_name,1,0,'L',0,$pdf->PMA_links['RT'][$table][$field_name]);
1484 //echo ' ' . $field_name . '&nbsp;' . "\n";
1486 $pdf->Cell(20,8,$type,1,0,'L');
1487 $pdf->Cell(20,8,$strAttribute,1,0,'L');
1488 $pdf->Cell(15,8,,1,0,'L');
1489 $pdf->Cell(15,8,((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1490 $pdf->Cell(15,8,$row['Extra'],1,0,'L');
1491 if ($have_rel) {
1492 if (isset($res_rel[$field_name])) {
1493 $pdf->Cell(30,8,$res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1496 if ($cfgRelation['commwork']) {
1497 if (isset($comments[$field_name])) {
1498 $pdf->Cell(0,8,$comments[$field_name],1,0,'L');
1500 } */
1501 } // end while
1502 $pdf->SetFont('', '',14);
1503 PMA_DBI_free_result($result);
1504 }//end each
1507 } // end function PMA_RT_DOC
1511 * Main logic
1513 if (!isset($pdf_page_number)) {
1514 $pdf_page_number = 1;
1516 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1517 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1518 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1519 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1520 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1521 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1522 $paper = isset($paper) ? $paper : 'A4';
1523 PMA_DBI_select_db($db);
1525 $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper);