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