/**
  * The "PMA_Pdf_Relation_Schema" constructor
  *
  * @global object   The current PDF Schema document
  * @global string   The current db name
  * @global array    The relations settings
  * @access private
  * @see PMA_PDF
  */
 function __construct()
 {
     global $pdf, $db, $cfgRelation;
     $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->setAllTableSameWidth(isset($_POST['all_table_same_wide']));
     $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_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->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $pdf->AliasNbPages();
     $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
     $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
     $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
     $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
     $pdf->SetFont($this->_ff, '', 14);
     $pdf->setFooterFont(array($this->_ff, '', 14));
     $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($table, $this->_ff, $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->getW() - $this->rightMargin - $this->leftMargin), ($this->_yMax - $this->_yMin) / ($pdf->getH() - $this->topMargin - $this->bottomMargin)) * 100) / 100;
     $pdf->PMA_PDF_setScale($this->scale, $this->_xMin, $this->_yMin, $this->leftMargin, $this->topMargin);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($this->showGrid) {
         $pdf->SetFontSize(10);
         $this->_strokeGrid();
     }
     $pdf->PMA_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);
     $this->_showOutput($this->pageNumber);
     exit;
 }