[ PHPXref.com ] [ Generated: Sun Jul 20 19:46:00 2008 ] [ phpMyAdmin 2.9.0.3 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> pdf_schema.php (source)

   1  <?php
   2  /* $Id: pdf_schema.php 8941 2006-04-25 15:21:33Z cybot_tm $ */
   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   * Gets the "fpdf" libraries and defines the pdf font path, use unicode version for unicode.
  37   */
  38  define('FPDF_FONTPATH', './libraries/fpdf/font/');
  39  if ($charset == 'utf-8') {
  40      define('PMA_PDF_FONT', 'FreeSans');
  41      require_once ('./libraries/fpdf/ufpdf.php');
  42      class PMA_FPDF extends UFPDF {
  43      };
  44  } else {
  45      define('PMA_PDF_FONT', 'Arial');
  46      require_once ('./libraries/fpdf/fpdf.php');
  47      class PMA_FPDF extends FPDF {
  48      };
  49  }
  50  
  51  /**
  52   * Extends the "FPDF" class and prepares the work
  53   *
  54   * @access public
  55   * @see FPDF
  56   */
  57  class PMA_PDF extends PMA_FPDF {
  58      /**
  59       * Defines private properties
  60       */
  61      var $x_min;
  62      var $y_min;
  63      var $l_marg = 10;
  64      var $t_marg = 10;
  65      var $scale;
  66      var $title;
  67      var $PMA_links;
  68      var $Outlines = array();
  69      var $def_outlines;
  70      var $Alias ;
  71      var $widths;
  72  
  73      /**
  74       * The PMA_PDF constructor
  75       *
  76       * This function just refers to the "FPDF" constructor: with PHP3 a class
  77       * must have a constructor
  78       *
  79       * @param string $ The page orientation (p, portrait, l or landscape)
  80       * @param string $ The unit for sizes (pt, mm, cm or in)
  81       * @param mixed $ The page format (A3, A4, A5, letter, legal or an array
  82       *                  with page sizes)
  83       * @access public
  84       * @see FPDF::FPDF()
  85       */
  86      function PMA_PDF($orientation = 'L', $unit = 'mm', $format = 'A4')
  87      {
  88          $this->Alias = array() ;
  89          $this->FPDF($orientation, $unit, $format);
  90      } // end of the "PMA_PDF()" method
  91      function SetAlias($name, $value)
  92      {
  93          $this->Alias[$name] = $value ;
  94      }
  95      function _putpages()
  96      {
  97          if (count($this->Alias) > 0) {
  98              $nb = $this->page;
  99              foreach ($this->Alias AS $alias => $value) {
 100                  for ($n = 1;$n <= $nb;$n++)
 101                  $this->pages[$n] = $this->_strreplace($alias, $value, $this->pages[$n]);
 102              }
 103          }
 104          parent::_putpages();
 105      }
 106  
 107      /**
 108       * Sets the scaling factor, defines minimum coordinates and margins
 109       *
 110       * @param double $ The scaling factor
 111       * @param double $ The minimum X coordinate
 112       * @param double $ The minimum Y coordinate
 113       * @param double $ The left margin
 114       * @param double $ The top margin
 115       * @access public
 116       */
 117      function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
 118      {
 119          $this->scale = $scale;
 120          $this->x_min = $x_min;
 121          $this->y_min = $y_min;
 122          if ($this->l_marg != -1) {
 123              $this->l_marg = $l_marg;
 124          }
 125          if ($this->t_marg != -1) {
 126              $this->t_marg = $t_marg;
 127          }
 128      } // end of the "PMA_PDF_setScale" function
 129      /**
 130       * Outputs a scaled cell
 131       *
 132       * @param double $ The cell width
 133       * @param double $ The cell height
 134       * @param string $ The text to output
 135       * @param mixed $ Wether to add borders or not
 136       * @param integer $ Where to put the cursor once the output is done
 137       * @param string $ Align mode
 138       * @param integer $ Whether to fill the cell with a color or not
 139       * @access public
 140       * @see FPDF::Cell()
 141       */
 142      function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
 143      {
 144          $h = $h / $this->scale;
 145          $w = $w / $this->scale;
 146          $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
 147      } // end of the "PMA_PDF_cellScale" function
 148      /**
 149       * Draws a scaled line
 150       *
 151       * @param double $ The horizontal position of the starting point
 152       * @param double $ The vertical position of the starting point
 153       * @param double $ The horizontal position of the ending point
 154       * @param double $ The vertical position of the ending point
 155       * @access public
 156       * @see FPDF::Line()
 157       */
 158      function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
 159      {
 160          $x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
 161          $y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
 162          $x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
 163          $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
 164          $this->Line($x1, $y1, $x2, $y2);
 165      } // end of the "PMA_PDF_lineScale" function
 166      /**
 167       * Sets x and y scaled positions
 168       *
 169       * @param double $ The x position
 170       * @param double $ The y position
 171       * @access public
 172       * @see FPDF::SetXY()
 173       */
 174      function PMA_PDF_setXyScale($x, $y)
 175      {
 176          $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
 177          $y = ($y - $this->y_min) / $this->scale + $this->t_marg;
 178          $this->SetXY($x, $y);
 179      } // end of the "PMA_PDF_setXyScale" function
 180      /**
 181       * Sets the X scaled positions
 182       *
 183       * @param double $ The x position
 184       * @access public
 185       * @see FPDF::SetX()
 186       */
 187      function PMA_PDF_setXScale($x)
 188      {
 189          $x = ($x - $this->x_min) / $this->scale + $this->l_marg;
 190          $this->SetX($x);
 191      } // end of the "PMA_PDF_setXScale" function
 192      /**
 193       * Sets the scaled font size
 194       *
 195       * @param double $ The font size (in points)
 196       * @access public
 197       * @see FPDF::SetFontSize()
 198       */
 199      function PMA_PDF_setFontSizeScale($size)
 200      {
 201          // Set font size in points
 202          $size = $size / $this->scale;
 203          $this->SetFontSize($size);
 204      } // end of the "PMA_PDF_setFontSizeScale" function
 205      /**
 206       * Sets the scaled line width
 207       *
 208       * @param double $ The line width
 209       * @access public
 210       * @see FPDF::SetLineWidth()
 211       */
 212      function PMA_PDF_setLineWidthScale($width)
 213      {
 214          $width = $width / $this->scale;
 215          $this->SetLineWidth($width);
 216      } // end of the "PMA_PDF_setLineWidthScale" function
 217      /**
 218       * Displays an error message
 219       *
 220       * @param string $ the error mesage
 221       * @global array    the PMA configuration array
 222       * @global integer  the current server id
 223       * @global string   the current language
 224       * @global string   the charset to convert to
 225       * @global string   the current database name
 226       * @global string   the current charset
 227       * @global string   the current text direction
 228       * @global string   a localized string
 229       * @global string   an other localized string
 230       * @access public
 231       */
 232      function PMA_PDF_die($error_message = '')
 233      {
 234          global $cfg;
 235          global $server, $lang, $convcharset, $db;
 236          global $charset, $text_dir, $strRunning, $strDatabase;
 237  
 238          require_once ('./libraries/header.inc.php');
 239  
 240          echo '<p><b>PDF - ' . $GLOBALS['strError'] . '</b></p>' . "\n";
 241          if (!empty($error_message)) {
 242              $error_message = htmlspecialchars($error_message);
 243          }
 244          echo '<p>' . "\n";
 245          echo '    ' . $error_message . "\n";
 246          echo '</p>' . "\n";
 247  
 248          echo '<a href="db_details_structure.php?' . PMA_generate_common_url($db)
 249           . '">' . $GLOBALS['strBack'] . '</a>';
 250          echo "\n";
 251  
 252          require_once ('./libraries/footer.inc.php');
 253      } // end of the "PMA_PDF_die()" function
 254      /**
 255       * Aliases the "Error()" function from the FPDF class to the
 256       * "PMA_PDF_die()" one
 257       *
 258       * @param string $ the error mesage
 259       * @access public
 260       * @see PMA_PDF_die
 261       */
 262      function Error($error_message = '')
 263      {
 264          $this->PMA_PDF_die($error_message);
 265      } // end of the "Error()" method
 266      function Header()
 267      {
 268          // $datefmt
 269          // We only show this if we find something in the new pdf_pages table
 270  
 271          // This function must be named "Header" to work with the FPDF library
 272          global $cfgRelation, $db, $pdf_page_number, $with_doc;
 273          if ($with_doc) {
 274              $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
 275               . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
 276               . ' AND page_nr = \'' . $pdf_page_number . '\'';
 277              $test_rs = PMA_query_as_cu($test_query);
 278              $pages = @PMA_DBI_fetch_assoc($test_rs);
 279              $this->SetFont('', 'B', 14);
 280              $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
 281              $this->SetFont('', '');
 282              $this->Ln();
 283          }
 284      }
 285      function Footer()
 286      {
 287          // This function must be named "Footer" to work with the FPDF library
 288          global $with_doc;
 289          if ($with_doc) {
 290              $this->SetY(-15);
 291              $this->SetFont('', '', 14);
 292              $this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
 293              $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
 294              $this->SetY(20);
 295          }
 296      }
 297      function Bookmark($txt, $level = 0, $y = 0)
 298      {
 299          // Add a bookmark
 300          $this->Outlines[0][] = $level;
 301          $this->Outlines[1][] = $txt;
 302          $this->Outlines[2][] = $this->page;
 303          if ($y == -1) {
 304              $y = $this->GetY();
 305          }
 306          $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
 307      }
 308  
 309      function _putbookmarks()
 310      {
 311          if (count($this->Outlines) > 0) {
 312              // Save object number
 313              $memo_n = $this->n;
 314              // Take the number of sub elements for an outline
 315              $nb_outlines = sizeof($this->Outlines[0]);
 316              $first_level = array();
 317              $parent = array();
 318              $parent[0] = 1;
 319              for ($i = 0; $i < $nb_outlines; $i++) {
 320                  $level = $this->Outlines[0][$i];
 321                  $kids = 0;
 322                  $last = -1;
 323                  $prev = -1;
 324                  $next = -1;
 325                  if ($i > 0) {
 326                      $cursor = $i-1;
 327                      // Take the previous outline in the same level
 328                      while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
 329                      $cursor--;
 330                      if ($this->Outlines[0][$cursor] == $level) {
 331                          $prev = $cursor;
 332                      }
 333                  }
 334                  if ($i < $nb_outlines-1) {
 335                      $cursor = $i + 1;
 336                      while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
 337                          // Take the immediate kid in level + 1
 338                          if ($this->Outlines[0][$cursor] == $level + 1) {
 339                              $kids++;
 340                              $last = $cursor;
 341                          }
 342                          $cursor++;
 343                      }
 344                      $cursor = $i + 1;
 345                      // Take the next outline in the same level
 346                      while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
 347                      $cursor++;
 348                      if ($this->Outlines[0][$cursor] == $level) {
 349                          $next = $cursor;
 350                      }
 351                  }
 352                  $this->_newobj();
 353                  $parent[$level + 1] = $this->n;
 354                  if ($level == 0) {
 355                      $first_level[] = $this->n;
 356                  }
 357                  $this->_out('<<');
 358                  $this->_out('/Title (' . $this->Outlines[1][$i] . ')');
 359                  $this->_out('/Parent ' . $parent[$level] . ' 0 R');
 360                  if ($prev != -1) {
 361                      $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
 362                  }
 363                  if ($next != -1) {
 364                      $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
 365                  }
 366                  $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
 367                  if ($kids > 0) {
 368                      $this->_out('/First ' . ($this->n + 1) . ' 0 R');
 369                      $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
 370                      $this->_out('/Count -' . $kids);
 371                  }
 372                  $this->_out('>>');
 373                  $this->_out('endobj');
 374              }
 375              // First page of outlines
 376              $this->_newobj();
 377              $this->def_outlines = $this->n;
 378              $this->_out('<<');
 379              $this->_out('/Type');
 380              $this->_out('/Outlines');
 381              $this->_out('/First ' . $first_level[0] . ' 0 R');
 382              $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
 383              $this->_out('/Count ' . sizeof($first_level));
 384              $this->_out('>>');
 385              $this->_out('endobj');
 386          }
 387      }
 388  
 389      function _putresources()
 390      {
 391          parent::_putresources();
 392          $this->_putbookmarks();
 393      }
 394  
 395      function _putcatalog()
 396      {
 397          parent::_putcatalog();
 398          if (count($this->Outlines) > 0) {
 399              $this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
 400              $this->_out('/PageMode /UseOutlines');
 401          }
 402      }
 403      function SetWidths($w)
 404      {
 405          // column widths
 406          $this->widths = $w;
 407      }
 408  
 409      function Row($data, $links)
 410      {
 411          // line height
 412          $nb = 0;
 413          $data_cnt = count($data);
 414          for ($i = 0;$i < $data_cnt;$i++)
 415          $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
 416          $il = $this->FontSize;
 417          $h = ($il + 1) * $nb;
 418          // page break if necessary
 419          $this->CheckPageBreak($h);
 420          // draw the cells
 421          $data_cnt = count($data);
 422          for ($i = 0;$i < $data_cnt;$i++) {
 423              $w = $this->widths[$i];
 424              // save current position
 425              $x = $this->GetX();
 426              $y = $this->GetY();
 427              // draw the border
 428              $this->Rect($x, $y, $w, $h);
 429              if (isset($links[$i])) {
 430                  $this->Link($x, $y, $w, $h, $links[$i]);
 431              }
 432              // print text
 433              $this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
 434              // go to right side
 435              $this->SetXY($x + $w, $y);
 436          }
 437          // go to line
 438          $this->Ln($h);
 439      }
 440  
 441      function CheckPageBreak($h)
 442      {
 443          // if height h overflows, manual page break
 444          if ($this->GetY() + $h > $this->PageBreakTrigger) {
 445              $this->AddPage($this->CurOrientation);
 446          }
 447      }
 448  
 449      function NbLines($w, $txt)
 450      {
 451          // compute number of lines used by a multicell of width w
 452          $cw = &$this->