(gl) Updates
[phpmyadmin/crack.git] / pdf_schema.php3
blobe06cb0ead415c60646fd39a08b040fd881be04c6
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Contributed by Maxime Delorme and merged by lem9
8 */
11 /**
12 * Gets some core scripts
14 require('./libraries/grab_globals.lib.php3');
15 require('./libraries/common.lib.php3');
18 /**
19 * Settings for relation stuff
21 require('./libraries/relation.lib.php3');
22 $cfgRelation = PMA_getRelationsParam();
25 /**
26 * Now in ./libraries/relation.lib.php3 we check for all tables
27 * that we need, but if we don't find them we are quiet about it
28 * so people can work without.
29 * This page is absolutely useless if you didn't set up your tables
30 * correctly, so it is a good place to see which tables we can and
31 * complain ;-)
33 if (!$cfgRelation['pdfwork']) {
34 echo '<font color="red">' . $strError . '</font><br />' . "\n";
35 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php3?' . $url_query . '">';
36 echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
40 /**
41 * Gets the "fpdf" libraries and defines the pdf font path
43 require('./libraries/fpdf/fpdf.php3');
44 // loic1: PHP3 compatibility
45 // define('FPDF_FONTPATH', './libraries/fpdf/font/');
46 $FPDF_font_path = './libraries/fpdf/font/';
49 /**
50 * Emulates the "array_search" function with PHP < 4.0.5
52 if (PMA_PHP_INT_VERSION < 40005) {
53 function array_search($needle, $haystack) {
54 $match = FALSE;
56 reset($haystack);
57 while (list($key, $value) = each($haystack)) {
58 if ($value == $needle) {
59 $match = $key;
61 } // end while
63 return $match;
64 } // end of the "array_search" function
65 } // end if
69 /**
70 * Extends the "FPDF" class and prepares the work
72 * @access public
74 * @see FPDF
76 class PMA_PDF extends FPDF
78 /**
79 * Defines private properties
81 var $x_min;
82 var $y_min;
83 var $l_marg = 10;
84 var $t_marg = 10;
85 var $scale;
86 var $title;
87 var $PMA_links;
88 var $Outlines=array();
89 var $def_outlines;
90 var $Alias ;
91 var $widths;
93 /**
94 * The PMA_PDF constructor
96 * This function just refers to the "FPDF" constructor: with PHP3 a class
97 * must have a constructor
99 * @param string The page orientation (p, portrait, l or landscape)
100 * @param string The unit for sizes (pt, mm, cm or in)
101 * @param mixed The page format (A3, A4, A5, letter, legal or an array
102 * with page sizes)
104 * @access public
106 * @see FPDF::FPDF()
108 function PMA_PDF($orientation = 'L', $unit = 'mm', $format = 'A4')
110 $this->Alias = array() ;
111 $this->FPDF($orientation, $unit, $format);
112 } // end of the "PMA_PDF()" method
113 function SetAlias($name, $value)
115 $this->Alias[$name] = $value ;
117 function _putpages()
119 if(count($this->Alias) > 0)
121 $nb=$this->page;
122 @reset($this->Alias);
123 while(list($alias, $value) = each($this->Alias)) {
124 for($n=1;$n<=$nb;$n++)
125 $this->pages[$n]=str_replace($alias,$value,$this->pages[$n]);
128 parent::_putpages();
132 * Sets the scaling factor, defines minimum coordinates and margins
134 * @param double The scaling factor
135 * @param double The minimum X coordinate
136 * @param double The minimum Y coordinate
137 * @param double The left margin
138 * @param double The top margin
140 * @access public
142 function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
144 $this->scale = $scale;
145 $this->x_min = $x_min;
146 $this->y_min = $y_min;
147 if ($this->l_marg != -1) {
148 $this->l_marg = $l_marg;
150 if ($this->t_marg != -1) {
151 $this->t_marg = $t_marg;
153 } // end of the "PMA_PDF_setScale" function
157 * Outputs a scaled cell
159 * @param double The cell width
160 * @param double The cell height
161 * @param string The text to output
162 * @param mixed Wether to add borders or not
163 * @param integer Where to put the cursor once the output is done
164 * @param string Align mode
165 * @param integer Whether to fill the cell with a color or not
167 * @access public
169 * @see FPDF::Cell()
171 function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0,$link ='')
173 $h = $h / $this->scale;
174 $w = $w / $this->scale;
175 $this->Cell($w, $h, $txt, $border, $ln, $align, $fill,$link);
176 } // end of the "PMA_PDF_cellScale" function
180 * Draws a scaled line
182 * @param double The horizontal position of the starting point
183 * @param double The vertical position of the starting point
184 * @param double The horizontal position of the ending point
185 * @param double The vertical position of the ending point
187 * @access public
189 * @see FPDF::Line()
191 function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
193 $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
194 $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
195 $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
196 $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
197 $this->Line($x1, $y1, $x2, $y2);
198 } // end of the "PMA_PDF_lineScale" function
202 * Sets x and y scaled positions
204 * @param double The x position
205 * @param double The y position
207 * @access public
209 * @see FPDF::SetXY()
211 function PMA_PDF_setXyScale($x, $y)
213 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
214 $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
215 $this->SetXY($x, $y);
216 } // end of the "PMA_PDF_setXyScale" function
220 * Sets the X scaled positions
222 * @param double The x position
224 * @access public
226 * @see FPDF::SetX()
228 function PMA_PDF_setXScale($x)
230 $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
231 $this->SetX($x);
232 } // end of the "PMA_PDF_setXScale" function
236 * Sets the scaled font size
238 * @param double The font size (in points)
240 * @access public
242 * @see FPDF::SetFontSize()
244 function PMA_PDF_setFontSizeScale($size)
246 // Set font size in points
247 $size = $size / $this->scale;
248 $this->SetFontSize($size);
249 } // end of the "PMA_PDF_setFontSizeScale" function
253 * Sets the scaled line width
255 * @param double The line width
257 * @access public
259 * @see FPDF::SetLineWidth()
261 function PMA_PDF_setLineWidthScale($width)
263 $width = $width / $this->scale;
264 $this->SetLineWidth($width);
265 } // end of the "PMA_PDF_setLineWidthScale" function
269 * Displays an error message
271 * @param string the error mesage
273 * @global array the PMA configuration array
274 * @global integer the current server id
275 * @global string the current language
276 * @global string the charset to convert to
277 * @global string the current database name
278 * @global string the current charset
279 * @global string the current text direction
280 * @global string a localized string
281 * @global string an other localized string
283 * @access public
285 function PMA_PDF_die($error_message = '')
287 global $cfg;
288 global $server, $lang, $convcharset, $db;
289 global $charset, $text_dir, $strRunning, $strDatabase;
291 include('./header.inc.php3');
293 echo '<p><b>PDF - '. $GLOBALS['strError'] . '</b></p>' . "\n";
294 if (!empty($error_message)) {
295 $error_message = htmlspecialchars($error_message);
297 echo '<p>' . "\n";
298 echo ' ' . $error_message . "\n";
299 echo '</p>' . "\n";
301 echo '<a href="db_details_structure.php3?' . PMA_generate_common_url($db)
302 . '">' . $GLOBALS['strBack'] . '</a>';
303 echo "\n";
305 include('./footer.inc.php3');
306 exit();
307 } // end of the "PMA_PDF_die()" function
311 * Aliases the "Error()" function from the FPDF class to the
312 * "PMA_PDF_die()" one
314 * @param string the error mesage
316 * @access public
318 * @see PMA_PDF_die()
320 function Error($error_message = '')
322 $this->PMA_PDF_die($error_message);
323 } // end of the "Error()" method
325 function Header(){
326 //$datefmt
327 // We only show this if we find something in the new pdf_pages table
329 // This function must be named "Header" to work with the FPDF library
331 global $cfgRelation,$db,$pdf_page_number,$with_doc;
332 if ($with_doc){
333 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
334 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
335 . ' AND page_nr = \'' . $pdf_page_number . '\'';
336 $test_rs = PMA_query_as_cu($test_query);
337 $pages = @PMA_mysql_fetch_array($test_rs);
338 $this->SetFont('', 'B');
339 $this->Cell(0,6, ucfirst($pages['page_descr']),'B',1,'C');
340 $this->SetFont('', '');
341 $this->Ln();
344 function Footer(){
345 // This function must be named "Footer" to work with the FPDF library
346 global $with_doc;
347 if ($with_doc){
348 $this->SetY(-15);
349 $this->Cell(0,6, $GLOBALS['strPageNumber'] .' '.$this->PageNo() .'/{nb}','T',0,'C');
350 $this->Cell(0,6, PMA_localisedDate(),0,1,'R');
351 $this->SetY(20);
354 function Bookmark($txt,$level=0,$y=0)
356 //Add a bookmark
357 $this->Outlines[0][]=$level;
358 $this->Outlines[1][]=$txt;
359 $this->Outlines[2][]=$this->page;
360 if($y==-1)
361 $y=$this->GetY();
362 $this->Outlines[3][]=round($this->hPt-$y*$this->k,2);
365 function _putbookmarks()
367 if(count($this->Outlines)>0)
369 //Save object number
370 $memo_n = $this->n;
371 //Take the number of sub elements for an outline
372 $nb_outlines=sizeof($this->Outlines[0]);
373 $first_level=array();
374 $parent=array();
375 $parent[0]=1;
376 for( $i=0; $i<$nb_outlines; $i++)
378 $level=$this->Outlines[0][$i];
379 $kids=0;
380 $last=-1;
381 $prev=-1;
382 $next=-1;
383 if( $i>0 )
385 $cursor=$i-1;
386 //Take the previous outline in the same level
387 while( $this->Outlines[0][$cursor] > $level && $cursor > 0)
388 $cursor--;
389 if( $this->Outlines[0][$cursor] == $level)
390 $prev=$cursor;
392 if( $i<$nb_outlines-1)
394 $cursor=$i+1;
395 while( isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level)
397 //Take the immediate kid in level + 1
398 if( $this->Outlines[0][$cursor] == $level+1)
400 $kids++;
401 $last=$cursor;
403 $cursor++;
405 $cursor=$i+1;
406 //Take the next outline in the same level
407 while( $this->Outlines[0][$cursor] > $level && ($cursor+1 < sizeof($this->Outlines[0])))
408 $cursor++;
409 if( $this->Outlines[0][$cursor] == $level)
410 $next=$cursor;
412 $this->_newobj();
413 $parent[$level+1]=$this->n;
414 if( $level == 0)
415 $first_level[]=$this->n;
416 $this->_out('<<');
417 $this->_out('/Title ('.$this->Outlines[1][$i].')');
418 $this->_out('/Parent '.$parent[$level].' 0 R');
419 if( $prev != -1)
420 $this->_out('/Prev '.($memo_n+$prev+1).' 0 R');
421 if( $next != -1)
422 $this->_out('/Next '.($this->n+$next-$i).' 0 R');
423 $this->_out('/Dest ['.(1+(2*$this->Outlines[2][$i])).' 0 R /XYZ null '.$this->Outlines[3][$i].' null]');
424 if( $kids > 0)
426 $this->_out('/First '.($this->n+1).' 0 R');
427 $this->_out('/Last '.($this->n+$last-$i).' 0 R');
428 $this->_out('/Count -'.$kids);
430 $this->_out('>>');
431 $this->_out('endobj');
433 //First page of outlines
434 $this->_newobj();
435 $this->def_outlines = $this->n;
436 $this->_out('<<');
437 $this->_out('/Type');
438 $this->_out('/Outlines');
439 $this->_out('/First '.$first_level[0].' 0 R');
440 $this->_out('/Last '.$first_level[sizeof($first_level)-1].' 0 R');
441 $this->_out('/Count '.sizeof($first_level));
442 $this->_out('>>');
443 $this->_out('endobj');
447 function _putresources()
449 parent::_putresources();
450 $this->_putbookmarks();
453 function _putcatalog()
455 parent::_putcatalog();
456 if(count($this->Outlines)>0)
458 $this->_out('/Outlines '.$this->def_outlines.' 0 R');
459 $this->_out('/PageMode /UseOutlines');
462 function SetWidths($w)
464 // column widths
465 $this->widths=$w;
468 function Row($data,$links)
470 // line height
471 $nb=0;
472 for($i=0;$i<count($data);$i++)
473 $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
474 $il = 2.7;
475 $h=$il*$nb+2;
476 // page break if necessary
477 $this->CheckPageBreak($h);
478 // draw the cells
479 for($i=0;$i<count($data);$i++)
481 $w=$this->widths[$i];
482 // save current position
483 $x=$this->GetX();
484 $y=$this->GetY();
485 // draw the border
486 $this->Rect($x,$y,$w,$h);
487 if (isset($links[$i]))
488 $this->Link($x,$y,$w,$h,$links[$i]);
489 // print text
490 $this->MultiCell($w,$il+1,$data[$i],0,'L');
491 // go to right side
492 $this->SetXY($x+$w,$y);
494 // go to line
495 $this->Ln($h);
498 function CheckPageBreak($h)
500 // if height h overflows, manual page break
501 if($this->GetY()+$h>$this->PageBreakTrigger)
502 $this->AddPage($this->CurOrientation);
505 function NbLines($w,$txt)
507 // compute number of lines used by a multicell of width w
508 $cw=&$this->CurrentFont['cw'];
509 if($w==0)
510 $w=$this->w-$this->rMargin-$this->x;
511 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
512 $s=str_replace("\r",'',$txt);
513 $nb=strlen($s);
514 if($nb>0 and $s[$nb-1]=="\n")
515 $nb--;
516 $sep=-1;
517 $i=0;
518 $j=0;
519 $l=0;
520 $nl=1;
521 while($i<$nb)
523 $c=$s[$i];
524 if($c=="\n")
526 $i++;
527 $sep=-1;
528 $j=$i;
529 $l=0;
530 $nl++;
531 continue;
533 if($c==' ')
534 $sep=$i;
535 $l+=$cw[$c];
536 if($l>$wmax)
538 if($sep==-1)
540 if($i==$j)
541 $i++;
543 else
544 $i=$sep+1;
545 $sep=-1;
546 $j=$i;
547 $l=0;
548 $nl++;
550 else
551 $i++;
553 return $nl;
556 } // end of the "PMA_PDF" class
560 * Draws tables schema
562 * @access private
564 * @see PMA_RT
566 class PMA_RT_Table
569 * Defines private properties
571 var $nb_fiels;
572 var $table_name;
573 var $width = 0;
574 var $height;
575 var $fields = array();
576 var $height_cell = 6;
577 var $x, $y;
578 var $primary = array();
582 * Sets the width of the table
584 * @param integer The font size
586 * @global object The current PDF document
588 * @access private
590 * @see PMA_PDF
592 function PMA_RT_Table_setWidth($ff)
594 // this looks buggy to me... does it really work if
595 // there are fields that require wider cells than the name of the table?
596 global $pdf;
598 reset($this->fields);
599 while (list(, $field) = each($this->fields)) {
600 $this->width = max($this->width, $pdf->GetStringWidth($field));
602 $this->width += $pdf->GetStringWidth(' ');
603 $pdf->SetFont($ff, 'B');
604 $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
605 $pdf->SetFont($ff, '');
606 } // end of the "PMA_RT_Table_setWidth()" method
610 * Sets the height of the table
612 * @access private
614 function PMA_RT_Table_setHeight()
616 $this->height = (count($this->fields) + 1) * $this->height_cell;
617 } // end of the "PMA_RT_Table_setHeight()" method
621 * Do draw the table
623 * @param boolean Whether to display table position or not
624 * @param integer The font size
625 * @param boolean Whether all tables should have the same width or not
626 * @param integer The max. with among tables
628 * @global object The current PDF document
630 * @access private
632 * @see PMA_PDF
634 function PMA_RT_Table_draw($show_info, $ff, $same_wide = 0, $same_wide_width = 0)
636 global $pdf, $with_doc;
638 if ($same_wide == 1 && $same_wide_width > 0) {
639 $this->width = $same_wide_width;
642 $pdf->PMA_PDF_setXyScale($this->x, $this->y);
643 $pdf->SetFont($ff, 'B');
644 $pdf->SetTextColor(200);
645 $pdf->SetFillColor(0, 0, 128);
646 if ($with_doc) $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'],-1);
647 else $pdf->PMA_links['doc'][$this->table_name]['-'] = '';
648 if ($show_info){
649 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) . ' ' . $this->table_name, 1, 1, 'C', 1,$pdf->PMA_links['doc'][$this->table_name]['-']);
650 } else {
651 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', 1,$pdf->PMA_links['doc'][$this->table_name]['-']);
653 $pdf->PMA_PDF_setXScale($this->x);
654 $pdf->SetFont($ff, '');
655 $pdf->SetTextColor(0);
656 $pdf->SetFillColor(255);
658 reset($this->fields);
659 while (list(, $field) = each($this->fields)) {
660 // loic1 : PHP3 fix
661 // if (in_array($field, $this->primary)) {
662 if (PMA_isInto($field, $this->primary) != -1) {
663 $pdf->SetFillColor(215, 121, 123);
665 if ($field == $this->displayfield) {
666 $pdf->SetFillColor(142, 159, 224);
668 if ($with_doc) $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field],-1);
669 else $pdf->PMA_links['doc'][$this->table_name][$field] = '';
672 $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', 1,$pdf->PMA_links['doc'][$this->table_name][$field]);
673 $pdf->PMA_PDF_setXScale($this->x);
674 $pdf->SetFillColor(255);
675 } // end while
677 /*if ($pdf->PageNo() > 1) {
678 $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
679 } */
680 } // end of the "PMA_RT_Table_draw()" method
684 * The "PMA_RT_Table" constructor
686 * @param string The table name
687 * @param integer The font size
688 * @param integer The max. with among tables
690 * @global object The current PDF document
691 * @global integer The current page number (from the
692 * $cfg['Servers'][$i]['table_coords'] table)
693 * @global array The relations settings
694 * @global string The current db name
696 * @access private
698 * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
699 * PMA_RT_Table::PMA_RT_Table_setHeight
701 function PMA_RT_Table($table_name, $ff, &$same_wide_width)
703 global $pdf, $pdf_page_number, $cfgRelation, $db;
705 $this->table_name = $table_name;
706 $sql = 'DESCRIBE ' . PMA_backquote($table_name);
707 $result = PMA_mysql_query($sql);
708 if (!$result || !mysql_num_rows($result)) {
709 $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name));
711 // load fields
712 while ($row = PMA_mysql_fetch_array($result)) {
713 $this->fields[] = $row[0];
716 //height and width
717 $this->PMA_RT_Table_setWidth($ff);
718 $this->PMA_RT_Table_setHeight();
719 if ($same_wide_width < $this->width) {
720 $same_wide_width = $this->width;
723 //x and y
724 $sql = 'SELECT x, y FROM '
725 . PMA_backquote($cfgRelation['table_coords'])
726 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
727 . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\''
728 . ' AND pdf_page_number = ' . $pdf_page_number;
729 $result = PMA_query_as_cu($sql);
731 if (!$result || !mysql_num_rows($result)) {
732 $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name));
734 list($this->x, $this->y) = PMA_mysql_fetch_array($result);
735 $this->x = (double) $this->x;
736 $this->y = (double) $this->y;
738 // displayfield
739 $this->displayfield = PMA_getDisplayField($db, $table_name);
741 // index
742 $sql = 'SHOW index FROM ' . PMA_backquote($table_name);
743 $result = PMA_mysql_query($sql);
744 if ($result && mysql_num_rows($result) > 0) {
745 while ($row = PMA_mysql_fetch_array($result)) {
746 if ($row['Key_name'] == 'PRIMARY') {
747 $this->primary[] = $row['Column_name'];
750 } // end if
751 } // end of the "PMA_RT_Table()" method
752 } // end class "PMA_RT_Table"
757 * Draws relation links
759 * @access private
761 * @see PMA_RT
763 class PMA_RT_Relation
766 * Defines private properties
768 var $x_src, $y_src;
769 var $src_dir ;
770 var $dest_dir;
771 var $x_dest, $y_dest;
772 var $w_tick = 5;
776 * Gets arrows coordinates
778 * @param string The current table name
779 * @param string The relation column name
781 * @return array Arrows coordinates
783 * @access private
785 function PMA_RT_Relation_getXy($table, $column)
787 $pos = array_search($column, $table->fields);
788 // x_left, x_right, y
789 return array($table->x, $table->x + $table->width, $table->y + ($pos + 1.5) * $table->height_cell);
790 } // end of the "PMA_RT_Relation_getXy()" method
794 * Do draws relation links
796 * @param boolean Whether to use one color per relation or not
797 * @param integer The id of the link to draw
799 * @global object The current PDF document
801 * @access private
803 * @see PMA_PDF
805 function PMA_RT_Relation_draw($change_color, $i)
807 global $pdf;
809 if ($change_color){
810 $d = $i % 6;
811 $j = ($i - $d) / 6;
812 $j = $j % 4;
813 $j++;
814 $case = array(
815 array(1, 0, 0),
816 array(0, 1, 0),
817 array(0, 0, 1),
818 array(1, 1, 0),
819 array(1, 0, 1),
820 array(0, 1, 1)
822 list ($a, $b, $c) = $case[$d];
823 $e = (1 - ($j - 1) / 6);
824 $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); }
825 else {
826 $pdf->SetDrawColor(0);
827 } // end if... else...
829 $pdf->PMA_PDF_setLineWidthScale(0.2);
830 $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src);
831 $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest);
832 $pdf->PMA_PDF_setLineWidthScale(0.1);
833 $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);
835 //arrow
836 $root2 = 2 * sqrt(2);
837 $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);
838 $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);
840 $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);
841 $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);
842 $pdf->SetDrawColor(0);
843 } // end of the "PMA_RT_Relation_draw()" method
847 * The "PMA_RT_Relation" constructor
849 * @param string The master table name
850 * @param string The relation field in the master table
851 * @param string The foreign table name
852 * @param string The relation field in the foreign table
855 * @access private
857 * @see PMA_RT_Relation::PMA_RT_Relation_getXy
859 function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field)
861 $src_pos = $this->PMA_RT_Relation_getXy($master_table , $master_field);
862 $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field);
863 $src_left = $src_pos[0] - $this->w_tick;
864 $src_right = $src_pos[1] + $this->w_tick;
865 $dest_left = $dest_pos[0] - $this->w_tick;
866 $dest_right = $dest_pos[1] + $this->w_tick;
868 $d1 = abs($src_left - $dest_left);
869 $d2 = abs($src_right - $dest_left);
870 $d3 = abs($src_left - $dest_right);
871 $d4 = abs($src_right - $dest_right);
872 $d = min($d1, $d2, $d3, $d4);
874 if ($d == $d1) {
875 $this->x_src = $src_pos[0];
876 $this->src_dir = -1;
877 $this->x_dest = $dest_pos[0];
878 $this->dest_dir = -1;
879 } else if ($d == $d2) {
880 $this->x_src = $src_pos[1];
881 $this->src_dir = 1;
882 $this->x_dest = $dest_pos[0];
883 $this->dest_dir = -1;
884 } else if ($d == $d3) {
885 $this->x_src = $src_pos[0];
886 $this->src_dir = -1;
887 $this->x_dest = $dest_pos[1];
888 $this->dest_dir = 1;
889 } else {
890 $this->x_src = $src_pos[1];
891 $this->src_dir = 1;
892 $this->x_dest = $dest_pos[1];
893 $this->dest_dir = 1;
895 $this->y_src = $src_pos[2];
896 $this->y_dest = $dest_pos[2];
897 } // end of the "PMA_RT_Relation()" method
898 } // end of the "PMA_RT_Relation" class
903 * Draws and send the database schema
905 * @access public
907 * @see PMA_PDF
909 class PMA_RT
912 * Defines private properties
914 var $tables = array();
915 var $relations = array();
916 var $ff = 'Arial';
917 var $x_max = 0;
918 var $y_max = 0;
919 var $scale;
920 var $x_min = 100000;
921 var $y_min = 100000;
922 var $t_marg = 10;
923 var $b_marg = 10;
924 var $l_marg = 10;
925 var $r_marg = 10;
926 var $tablewidth;
927 var $same_wide = 0;
930 * Sets X and Y minimum and maximum for a table cell
932 * @param string The table name
934 * @access private
936 function PMA_RT_setMinMax($table)
938 $this->x_max = max($this->x_max, $table->x + $table->width);
939 $this->y_max = max($this->y_max, $table->y + $table->height);
940 $this->x_min = min($this->x_min, $table->x);
941 $this->y_min = min($this->y_min, $table->y);
942 } // end of the "PMA_RT_setMinMax()" method
946 * Defines relation objects
948 * @param string The master table name
949 * @param string The relation field in the master table
950 * @param string The foreign table name
951 * @param string The relation field in the foreign table
953 * @access private
955 * @see PMA_RT_setMinMax()
957 function PMA_RT_addRelation($master_table , $master_field, $foreign_table, $foreign_field)
959 if (!isset($this->tables[$master_table])) {
960 $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth);
961 $this->PMA_RT_setMinMax($this->tables[$master_table]);
963 if (!isset($this->tables[$foreign_table])) {
964 $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth);
965 $this->PMA_RT_setMinMax($this->tables[$foreign_table]);
967 $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field);
968 } // end of the "PMA_RT_addRelation()" method
972 * Draws the grid
974 * @global object the current PMA_PDF instance
976 * @access private
978 * @see PMA_PDF
980 function PMA_RT_strokeGrid()
982 global $pdf;
984 $pdf->SetMargins(0, 0);
985 $pdf->SetDrawColor(200, 200, 200);
987 // Draws horizontal lines
988 for ($l = 0; $l < 21; $l++) {
989 $pdf->line(0, $l * 10, 297, $l * 10);
990 // Avoid duplicates
991 if ($l > 0) {
992 $pdf->SetXY(0, $l * 10);
993 $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min);
994 $pdf->Cell(5, 5, ' ' . $label);
995 } // end if
996 } // end for
998 // Draws vertical lines
999 for ($j = 0; $j < 30 ;$j++) {
1000 $pdf->line($j * 10, 0, $j * 10, 210);
1001 $pdf->SetXY($j * 10, 0);
1002 $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min);
1003 $pdf->Cell(5, 7, $label);
1004 } // end for
1005 } // end of the "PMA_RT_strokeGrid()" method
1009 * Draws relation arrows
1011 * @param boolean Whether to use one color per relation or not
1013 * @access private
1015 * @see PMA_RT_Relation::PMA_RT_Relation_draw()
1017 function PMA_RT_drawRelations($change_color)
1019 $i = 0;
1020 reset($this->relations);
1021 while (list(, $relation) = each($this->relations)) {
1022 $relation->PMA_RT_Relation_draw($change_color, $i);
1023 $i++;
1024 } // end while
1025 } // end of the "PMA_RT_drawRelations()" method
1029 * Draws tables
1031 * @param boolean Whether to display table position or not
1033 * @access private
1035 * @see PMA_RT_Table::PMA_RT_Table_draw()
1037 function PMA_RT_drawTables($show_info)
1039 reset($this->tables);
1040 while (list(, $table) = each($this->tables)) {
1041 $table->PMA_RT_Table_draw($show_info, $this->ff, $this->same_wide, $this->tablewidth);
1043 } // end of the "PMA_RT_drawTables()" method
1047 * Ouputs the PDF document to a file
1049 * @global object The current PDF document
1050 * @global string The current database name
1051 * @global integer The current page number (from the
1052 * $cfg['Servers'][$i]['table_coords'] table)
1054 * @access private
1056 * @see PMA_PDF
1058 function PMA_RT_showRt()
1060 global $pdf, $db, $pdf_page_number, $cfgRelation;
1062 $pdf->SetFontSize(14);
1063 $pdf->SetLineWidth(0.2);
1064 $pdf->SetDisplayMode('fullpage');
1065 // Get the name of this pdfpage to use as filename (Mike Beck)
1066 $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
1067 . ' WHERE page_nr = ' . $pdf_page_number;
1068 $_name_rs = PMA_query_as_cu($_name_sql);
1069 if ($_name_rs) {
1070 $_name_row = PMA_mysql_fetch_row($_name_rs);
1071 $filename = $_name_row[0] . '.pdf';
1073 // i don't know if there is a chance for this to happen, but rather be on the safe side:
1074 if (empty($filename)) {
1075 $filename = $pdf_page_number . '.pdf';
1077 $pdf->Output($db . '_' . $filename, TRUE);
1078 //$pdf->Output('', TRUE);
1079 } // end of the "PMA_RT_showRt()" method
1083 * The "PMA_RT" constructor
1085 * @param mixed The scaling factor
1086 * @param integer The page number to draw (from the
1087 * $cfg['Servers'][$i]['table_coords'] table)
1088 * @param boolean Whether to display table position or not
1089 * @param boolean Whether to use one color per relation or not
1090 * @param boolean Whether to draw grids or not
1091 * @param boolean Whether all tables should have the same width or not
1093 * @global object The current PDF document
1094 * @global string The current db name
1095 * @global array The relations settings
1097 * @access private
1099 * @see PMA_PDF
1101 function PMA_RT($scale, $which_rel, $show_info = 0, $change_color = 0 , $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L')
1103 global $pdf, $db, $cfgRelation, $with_doc;
1105 // Font face depends on the current language
1106 $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
1107 $this->same_wide = $all_tab_same_wide;
1109 // Initializes a new document
1110 $pdf = new PMA_PDF('L');
1111 $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
1112 $pdf->cMargin = 0;
1113 $pdf->Open();
1114 $pdf->SetTitle($pdf->title);
1115 $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
1116 $pdf->AliasNbPages();
1118 $pdf->SetFont($this->ff, '', 14);
1119 $pdf->SetAutoPageBreak('auto');
1121 // Gets tables on this page
1122 $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords'])
1123 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
1124 . ' AND pdf_page_number = ' . $which_rel;
1125 $tab_rs = PMA_query_as_cu($tab_sql);
1126 if (!$tab_rs || !mysql_num_rows($tab_rs) > 0) {
1127 $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
1128 // die('No tables');
1130 while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
1131 $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
1132 $intable = '\'' . implode('\', \'', $alltables) . '\'';
1134 // make doc //
1135 if ($with_doc) {
1136 $pdf->SetAutoPageBreak('auto',15);
1137 $pdf->cMargin = 1;
1138 PMA_RT_DOC($alltables);
1139 $pdf->SetAutoPageBreak('auto');
1140 $pdf->cMargin = 0;
1143 $pdf->Addpage();
1146 if ($with_doc) {
1147 $pdf->SetLink($pdf->PMA_links['RT']['-'],-1);
1148 $pdf->Bookmark($GLOBALS['strRelationalSchema']);
1149 $pdf->SetAlias('{00}', $pdf->PageNo()) ;
1150 $this->t_marg = 18;
1151 $this->b_marg = 18;
1155 $sql = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
1156 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
1157 . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
1158 . ' AND master_table IN (' . $intable . ')'
1159 . ' AND foreign_table IN (' . $intable . ')';
1160 $result = PMA_query_as_cu($sql);
1162 // loic1: also show tables without relations
1163 $norelations = TRUE;
1164 if ($result && mysql_num_rows($result) > 0) {
1165 $norelations = FALSE;
1166 while ($row = PMA_mysql_fetch_array($result)) {
1167 $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
1170 reset ($alltables);
1171 while (list(, $table) = each ($alltables)) {
1172 if (!isset($this->tables[$table])) {
1173 $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
1174 $this->PMA_RT_setMinMax($this->tables[$table]);
1176 } // while
1178 // Defines the scale factor
1179 if ($scale == 'auto') {
1180 $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;
1181 $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
1182 } else {
1183 $this->scale = $scale;
1184 $pdf->PMA_PDF_setScale($scale);
1185 } // end if... else...
1187 // Builds and save the PDF document
1188 $pdf->PMA_PDF_setLineWidthScale(0.1);
1190 if ($show_grid) {
1191 $pdf->SetFontSize(10);
1192 $this->PMA_RT_strokeGrid();
1194 $pdf->PMA_PDF_setFontSizeScale(14);
1195 if ($norelations == FALSE) {
1196 $this->PMA_RT_drawRelations($change_color);
1198 $this->PMA_RT_drawTables($show_info);
1200 $this->PMA_RT_showRt();
1201 } // end of the "PMA_RT()" method
1202 } // end of the "PMA_RT" class
1204 function PMA_RT_DOC($alltables ){
1205 global $db, $pdf, $orientation;
1206 //TOC
1207 $pdf->addpage("P");
1208 $pdf->Cell(0,9, $GLOBALS['strTableOfContents'],1,0,'C');
1209 $pdf->Ln(15);
1210 $i = 1;
1211 @reset($alltables);
1212 while(list(, $table) = each($alltables)) {
1213 $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
1214 $pdf->SetX(10);
1215 //$pdf->Ln(1);
1216 $pdf->Cell(0,6,$GLOBALS['strPageNumber'] . ' {'.sprintf("%02d", $i).'}',0,0,'R',0,$pdf->PMA_links['doc'][$table]['-']);
1217 $pdf->SetX(10);
1218 $pdf->Cell(0,6,$i.' '. $table,0,1,'L',0,$pdf->PMA_links['doc'][$table]['-']);
1220 //$pdf->Ln(1);
1221 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
1222 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
1223 while ($row = PMA_mysql_fetch_array($result)) {
1224 $pdf->SetX(20);
1225 $field_name = $row['Field'];
1226 $pdf->PMA_links['doc'][$table][$field_name] =$pdf->AddLink();
1227 //$pdf->Cell(0,6,$field_name,0,1,'L',0,$pdf->PMA_links['doc'][$table][$field_name]);
1229 $lasttable = $table;
1230 $i++;
1232 $pdf->PMA_links['RT']['-'] =$pdf->AddLink();
1233 $pdf->SetX(10);
1234 $pdf->Cell(0,6,$GLOBALS['strPageNumber'] . ' {00}',0,0,'R',0,$pdf->PMA_links['doc'][$lasttable]['-']);
1235 $pdf->SetX(10);
1236 $pdf->Cell(0,6,$i.' '. $GLOBALS['strRelationalSchema'],0,1,'L',0,$pdf->PMA_links['RT']['-']);
1237 $z = 0;
1238 @reset($alltables);
1239 while(list(, $table) = each($alltables)) {
1240 $z++;
1241 $pdf->addpage($GLOBALS['orientation']);
1242 $pdf->Bookmark($table);
1243 $pdf->SetAlias('{'.sprintf("%02d", $z).'}', $pdf->PageNo()) ;
1244 $pdf->PMA_links['RT'][$table]['-'] =$pdf->AddLink();
1245 $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'],-1);
1246 $pdf->SetFont('', 'B',18);
1247 $pdf->Cell(0,8, $z .' '.$table,1,1,'C',0,$pdf->PMA_links['RT'][$table]['-']);
1248 $pdf->SetFont('', '',8);
1249 $pdf->ln();
1251 $cfgRelation = PMA_getRelationsParam();
1252 if ($cfgRelation['commwork']) {
1253 $comments = PMA_getComments($db, $table);
1258 * Gets table informations
1260 // The 'show table' statement works correct since 3.23.03
1261 if (PMA_MYSQL_INT_VERSION >= 32303) {
1262 $local_query = "SHOW TABLE STATUS LIKE '" . PMA_sqlAddslashes($table, TRUE) . "'";
1263 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
1264 $showtable = PMA_mysql_fetch_array($result);
1265 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
1266 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
1267 } else {
1268 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
1269 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
1270 $showtable = array();
1271 $num_rows = PMA_mysql_result($result, 0, 'count');
1272 $show_comment = '';
1273 } // end display comments
1274 if ($result) {
1275 mysql_free_result($result);
1280 * Gets table keys and retains them
1282 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
1283 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
1284 $primary = '';
1285 $indexes = array();
1286 $lastIndex = '';
1287 $indexes_info = array();
1288 $indexes_data = array();
1289 $pk_array = array(); // will be use to emphasis prim. keys in the table
1290 // view
1291 while ($row = PMA_mysql_fetch_array($result)) {
1292 // Backups the list of primary keys
1293 if ($row['Key_name'] == 'PRIMARY') {
1294 $primary .= $row['Column_name'] . ', ';
1295 $pk_array[$row['Column_name']] = 1;
1297 // Retains keys informations
1298 if ($row['Key_name'] != $lastIndex ){
1299 $indexes[] = $row['Key_name'];
1300 $lastIndex = $row['Key_name'];
1302 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
1303 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
1304 if (isset($row['Cardinality'])) {
1305 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
1307 // I don't know what does following column mean....
1308 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
1309 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
1311 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
1312 if (isset($row['Sub_part'])) {
1313 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
1316 } // end while
1317 if ($result) {
1318 mysql_free_result($result);
1323 * Gets fields properties
1325 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
1326 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
1327 $fields_cnt = mysql_num_rows($result);
1330 // Check if we can use Relations (Mike Beck)
1331 if (!empty($cfgRelation['relation'])) {
1332 // Find which tables are related with the current one and write it in
1333 // an array
1334 $res_rel = PMA_getForeigners($db, $table);
1336 if (count($res_rel) > 0) {
1337 $have_rel = TRUE;
1338 } else {
1339 $have_rel = FALSE;
1342 else {
1343 $have_rel = FALSE;
1344 } // end if
1348 * Displays the comments of the table if MySQL >= 3.23
1351 if (!empty($show_comment)) {
1352 $pdf->Cell(0,8,$GLOBALS['strTableComments'] . ' : ' . $show_comment,0,1);
1353 $pdf->Ln();
1356 $i = 0;
1357 $pdf->SetFont('', 'B');
1358 if (isset($orientation) && $orientation == 'L') {
1359 $pdf->Cell(25,8,ucfirst($GLOBALS['strField']),1,0,'C');
1360 $pdf->Cell(20,8,ucfirst($GLOBALS['strType']),1,0,'C');
1361 $pdf->Cell(20,8,ucfirst($GLOBALS['strAttr']),1,0,'C');
1362 $pdf->Cell(10,8,ucfirst($GLOBALS['strNull']),1,0,'C');
1363 $pdf->Cell(20,8,ucfirst($GLOBALS['strDefault']),1,0,'C');
1364 $pdf->Cell(25,8,ucfirst($GLOBALS['strExtra']),1,0,'C');
1365 $pdf->Cell(45,8,ucfirst($GLOBALS['strLinksTo']),1,0,'C');
1366 $pdf->Cell(100,8,ucfirst($GLOBALS['strComments']),1,1,'C');
1367 $pdf->SetWidths(array(25,20,20,10,20,25,45,100));
1368 } else {
1369 $pdf->Cell(20,8,ucfirst($GLOBALS['strField']),1,0,'C');
1370 $pdf->Cell(20,8,ucfirst($GLOBALS['strType']),1,0,'C');
1371 $pdf->Cell(20,8,ucfirst($GLOBALS['strAttr']),1,0,'C');
1372 $pdf->Cell(10,8,ucfirst($GLOBALS['strNull']),1,0,'C');
1373 $pdf->Cell(15,8,ucfirst($GLOBALS['strDefault']),1,0,'C');
1374 $pdf->Cell(15,8,ucfirst($GLOBALS['strExtra']),1,0,'C');
1375 $pdf->Cell(30,8,ucfirst($GLOBALS['strLinksTo']),1,0,'C');
1376 $pdf->Cell(60,8,ucfirst($GLOBALS['strComments']),1,1,'C');
1377 $pdf->SetWidths(array(20,20,20,10,15,15,30,60));
1379 $pdf->SetFont('', '');
1381 while ($row = PMA_mysql_fetch_array($result)) {
1382 $bgcolor = ($i % 2) ?$GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
1383 $i++;
1385 $type = $row['Type'];
1386 // reformat mysql query output - staybyte - 9. June 2001
1387 // loic1: set or enum types: slashes single quotes inside options
1388 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
1389 $tmp[2] = substr(ereg_replace("([^,])''", "\\1\\'", ',' . $tmp[2]), 1);
1390 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
1391 $type_nowrap = '';
1393 $binary = 0;
1394 $unsigned = 0;
1395 $zerofill = 0;
1396 } else {
1397 $type_nowrap = ' nowrap="nowrap"';
1398 $type = eregi_replace('BINARY', '', $type);
1399 $type = eregi_replace('ZEROFILL', '', $type);
1400 $type = eregi_replace('UNSIGNED', '', $type);
1401 if (empty($type)) {
1402 $type = '&nbsp;';
1405 $binary = eregi('BINARY', $row['Type'], $test);
1406 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
1407 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
1409 $strAttribute = ' ';
1410 if ($binary) {
1411 $strAttribute = 'BINARY';
1413 if ($unsigned) {
1414 $strAttribute = 'UNSIGNED';
1416 if ($zerofill) {
1417 $strAttribute = 'UNSIGNED ZEROFILL';
1419 if (!isset($row['Default'])) {
1420 if ($row['Null'] != '') {
1421 $row['Default'] = 'NULL';
1424 $field_name = $row['Field'];
1425 //$pdf->Ln();
1426 $pdf->PMA_links['RT'][$table][$field_name] =$pdf->AddLink();
1427 $pdf->Bookmark($field_name,1,-1);
1428 $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name],-1);
1429 $pdf_row = array($field_name ,
1430 $type ,
1431 $strAttribute ,
1432 ($row['Null'] == '') ? $GLOBALS['strNo'] : $GLOBALS['strYes'],
1433 ((isset($row['Default'])) ? $row['Default'] : ''),
1434 $row['Extra'] ,
1435 ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''),
1436 ((isset($comments[$field_name])) ? $comments[$field_name] : '' )
1438 $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
1439 if (isset($res_rel[$field_name]['foreign_table']) AND
1440 isset($res_rel[$field_name]['foreign_field']) AND
1441 isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])
1442 ) $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
1443 else unset($links[6]);
1444 $pdf->Row($pdf_row, $links);
1446 /*$pdf->Cell(20,8,$field_name,1,0,'L',0,$pdf->PMA_links['RT'][$table][$field_name]);
1447 //echo ' ' . $field_name . '&nbsp;' . "\n";
1449 $pdf->Cell(20,8,$type,1,0,'L');
1450 $pdf->Cell(20,8,$strAttribute,1,0,'L');
1451 $pdf->Cell(15,8,,1,0,'L');
1452 $pdf->Cell(15,8,((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L');
1453 $pdf->Cell(15,8,$row['Extra'],1,0,'L');
1454 if ($have_rel) {
1455 if (isset($res_rel[$field_name])) {
1456 $pdf->Cell(30,8,$res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L');
1459 if ($cfgRelation['commwork']) {
1460 if (isset($comments[$field_name])) {
1461 $pdf->Cell(0,8,$comments[$field_name],1,0,'L');
1463 } */
1464 } // end while
1465 $pdf->SetFont('', '',14);
1466 mysql_free_result($result);
1467 }//end each
1470 } // end function PMA_RT_DOC
1474 * Main logic
1476 if (!isset($pdf_page_number)) {
1477 $pdf_page_number = 1;
1479 $show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0;
1480 $show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0;
1481 $show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0;
1482 $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0;
1483 $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0;
1484 $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L';
1485 PMA_mysql_select_db($db);
1487 $rt = new PMA_RT('auto', $pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation);