/**
  * The "PMA_Pdf_Relation_Schema" constructor
  *
  * @global object $pdf The current PDF Schema document
  * @global string $db  The current db name
  * @global array    The relations settings
  * @access private
  * @see PMA_Schema_PDF
  */
 function __construct()
 {
     global $pdf, $db;
     $this->setPageNumber($_POST['pdf_page_number']);
     $this->setShowGrid(isset($_POST['show_grid']));
     $this->setShowColor(isset($_POST['show_color']));
     $this->setShowKeys(isset($_POST['show_keys']));
     $this->setTableDimension(isset($_POST['show_table_dimension']));
     $this->setAllTablesSameWidth(isset($_POST['all_tables_same_width']));
     $this->setWithDataDictionary($_POST['with_doc']);
     $this->setOrientation($_POST['orientation']);
     $this->setPaper($_POST['paper']);
     $this->setExportType($_POST['export_type']);
     // Initializes a new document
     $pdf = new PMA_Schema_PDF($this->orientation, 'mm', $this->paper);
     $pdf->SetTitle(sprintf(__('Schema of the %s database - Page %s'), $GLOBALS['db'], $this->pageNumber));
     $pdf->setCMargin(0);
     $pdf->Open();
     $pdf->SetAutoPageBreak('auto');
     $alltables = $this->getAllTables($db, $this->pageNumber);
     if ($this->withDoc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->setCMargin(1);
         $this->dataDictionaryDoc($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->setCMargin(0);
     }
     $pdf->Addpage();
     if ($this->withDoc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark(__('Relational schema'));
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->_topMargin = 28;
         $this->_bottomMargin = 28;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->_tables[$table])) {
             $this->_tables[$table] = new Table_Stats_Pdf($table, null, $this->pageNumber, $this->_tablewidth, $this->showKeys, $this->tableDimension);
         }
         if ($this->sameWide) {
             $this->_tables[$table]->width = $this->_tablewidth;
         }
         $this->_setMinMax($this->_tables[$table]);
     }
     // Defines the scale factor
     $this->_scale = ceil(max(($this->_xMax - $this->_xMin) / ($pdf->getPageWidth() - $this->_rightMargin - $this->_leftMargin), ($this->_yMax - $this->_yMin) / ($pdf->getPageHeight() - $this->_topMargin - $this->_bottomMargin)) * 100) / 100;
     $pdf->setScale($this->_scale, $this->_xMin, $this->_yMin, $this->_leftMargin, $this->_topMargin);
     // Builds and save the PDF document
     $pdf->setLineWidthScale(0.1);
     if ($this->showGrid) {
         $pdf->SetFontSize(10);
         $this->_strokeGrid();
     }
     $pdf->setFontSizeScale(14);
     // previous logic was checking master tables and foreign tables
     // but I think that looping on every table of the pdf page as a master
     // and finding its foreigns is OK (then we can support innodb)
     $seen_a_relation = false;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
         if ($exist_rel) {
             $seen_a_relation = true;
             foreach ($exist_rel as $master_field => $rel) {
                 // put the foreign table on the schema only if selected
                 // by the user
                 // (do not use array_search() because we would have to
                 // to do a === false and this is not PHP3 compatible)
                 if (in_array($rel['foreign_table'], $alltables)) {
                     $this->_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->tableDimension);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     if ($seen_a_relation) {
         $this->_drawRelations($this->showColor);
     }
     $this->_drawTables($this->showColor);
 }