Beispiel #1
0
 /**
  * The "PMA_RT" constructor
  *
  * @param   mixed    The scaling factor
  * @param   integer  The page number to draw (from the
  *                   $cfg['Servers'][$i]['table_coords'] table)
  * @param   boolean  Whether to display table position or not
  * @param   boolean  Was originally whether to use one color per
  *                   relation or not, now enables/disables color
  *                   everywhere, due to some problems printing with color
  * @param   boolean  Whether to draw grids or not
  * @param   boolean  Whether all tables should have the same width or not
  *
  * @global  object   The current PDF document
  * @global  string   The current db name
  * @global  array    The relations settings
  *
  * @access  private
  *
  * @see     PMA_PDF
  */
 function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
 {
     global $pdf, $db, $cfgRelation, $with_doc;
     // Font face depends on the current language
     $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
     $this->same_wide = $all_tab_same_wide;
     // Initializes a new document
     $pdf = new PMA_PDF('L', 'mm', $paper);
     $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
     $pdf->cMargin = 0;
     $pdf->Open();
     $pdf->SetTitle($pdf->title);
     $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $pdf->AliasNbPages();
     // fonts added to phpMyAdmin and considered non-standard by fpdf
     // (Note: those tahoma fonts are iso-8859-2 based)
     if ($this->ff == 'tahoma') {
         $pdf->AddFont('tahoma', '', 'tahoma.php');
         $pdf->AddFont('tahoma', 'B', 'tahomab.php');
     }
     $pdf->SetFont($this->ff, '', 14);
     $pdf->SetAutoPageBreak('auto');
     // Gets tables on this page
     $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel;
     $tab_rs = PMA_query_as_cu($tab_sql);
     if (!$tab_rs || !mysql_num_rows($tab_rs) > 0) {
         $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
         //            die('No tables');
     }
     while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
         $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
         //$intable     = '\'' . implode('\', \'', $alltables) . '\'';
     }
     //              make doc                    //
     if ($with_doc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->cMargin = 1;
         PMA_RT_DOC($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->cMargin = 0;
     }
     $pdf->Addpage();
     if ($with_doc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark($GLOBALS['strRelationalSchema']);
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->t_marg = 18;
         $this->b_marg = 18;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
         }
         if ($this->same_wide) {
             $this->tables[$table]->width = $this->tablewidth;
         }
         $this->PMA_RT_setMinMax($this->tables[$table]);
     }
     // Defines the scale factor
     $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;
     $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($show_grid) {
         $pdf->SetFontSize(10);
         $this->PMA_RT_strokeGrid();
     }
     $pdf->PMA_PDF_setFontSizeScale(14);
     //        $sql    = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
     //                .   ' WHERE master_db   = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND foreign_db    = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND master_table  IN (' . $intable . ')'
     //                .   ' AND foreign_table IN (' . $intable . ')';
     //        $result =  PMA_query_as_cu($sql);
     //
     // lem9:
     // 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 (PMA_isInto($rel['foreign_table'], $alltables) > -1) {
                     $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     // loic1: also show tables without relations
     //        $norelations     = TRUE;
     //        if ($result && mysql_num_rows($result) > 0) {
     //            $norelations = FALSE;
     //            while ($row = PMA_mysql_fetch_array($result)) {
     //                $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
     //            }
     //        }
     //        if ($norelations == FALSE) {
     if ($seen_a_relation) {
         $this->PMA_RT_drawRelations($change_color);
     }
     $this->PMA_RT_drawTables($show_info, $change_color);
     $this->PMA_RT_showRt();
 }
 /**
  * Outputs the content of a table in PDF format
  *
  * @todo    user-defined page orientation, paper size
  * @param   string      the database name
  * @param   string      the table name
  * @param   string      the end of line sequence
  * @param   string      the url to go back in case of error
  * @param   string      SQL query for obtaining data
  *
  * @return  bool        Whether it suceeded
  *
  * @access  public
  */
 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
 {
     global $what;
     global $pdf_report_title;
     $pdf = new PMA_PDF('L', 'pt', 'A3');
     $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
     $pdf->AddFont('DejaVuSans', 'B', 'dejavusans-bold.php');
     $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
     $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserif-bold.php');
     $pdf->SetFont(PMA_PDF_FONT, '', 11.5);
     $pdf->AliasNbPages();
     $attr = array('titleFontSize' => 18, 'titleText' => $pdf_report_title);
     $pdf->mysql_report($sql_query, $attr);
     // instead of $pdf->Output():
     if ($pdf->state < 3) {
         $pdf->Close();
     }
     if (!PMA_exportOutputHandler($pdf->buffer)) {
         return FALSE;
     }
     return TRUE;
 }
Beispiel #3
0
 /**
  * This function must be named "Footer" to work with the TCPDF library
  *
  * @return void
  *
  * @see PMA_PDF::Footer()
  */
 function Footer()
 {
     global $with_doc;
     if ($with_doc) {
         parent::Footer();
     }
 }
 /**
  * This function must be named "Footer" to work with the TCPDF library
  *
  * @return void
  *
  * @see PMA_PDF::Footer()
  */
 public function Footer()
 {
     if ($this->_withDoc) {
         parent::Footer();
     }
 }
 /**
  * The "PMA_RT" constructor
  *
  * @param mixed $ The scaling factor
  * @param integer $ The page number to draw (from the
  *                    $cfg['Servers'][$i]['table_coords'] table)
  * @param boolean $ Whether to display table position or not
  * @param boolean $ Was originally whether to use one color per
  *                    relation or not, now enables/disables color
  *                    everywhere, due to some problems printing with color
  * @param boolean $ Whether to draw grids or not
  * @param boolean $ Whether all tables should have the same width or not
  * @param boolean $ Wheter to show all field or only the keys
  * @global object   The current PDF document
  * @global string   The current db name
  * @global array    The relations settings
  * @access private
  * @see PMA_PDF
  */
 function __construct($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4', $show_keys = 0)
 {
     global $pdf, $db, $cfgRelation, $with_doc;
     $this->same_wide = $all_tab_same_wide;
     // Initializes a new document
     $pdf = new PMA_PDF('L', 'mm', $paper);
     $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
     $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');
     $this->ff = PMA_PDF_FONT;
     $pdf->SetFont($this->ff, '', 14);
     $pdf->SetAutoPageBreak('auto');
     // Gets tables on this page
     $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel;
     $tab_rs = PMA_query_as_cu($tab_sql, null, PMA_DBI_QUERY_STORE);
     if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
         $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
         // die('No tables');
     }
     while ($curr_table = PMA_DBI_fetch_assoc($tab_rs)) {
         $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
         // $intable     = '\'' . implode('\', \'', $alltables) . '\'';
     }
     // make doc                    //
     if ($with_doc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->setCMargin(1);
         PMA_RT_DOC($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->setCMargin(0);
     }
     $pdf->Addpage();
     if ($with_doc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark($GLOBALS['strRelationalSchema']);
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->t_marg = 18;
         $this->b_marg = 18;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys);
         }
         if ($this->same_wide) {
             $this->tables[$table]->width = $this->tablewidth;
         }
         $this->PMA_RT_setMinMax($this->tables[$table]);
     }
     // Defines the scale factor
     $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg)) * 100) / 100;
     $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($show_grid) {
         $pdf->SetFontSize(10);
         $this->PMA_RT_strokeGrid();
     }
     $pdf->PMA_PDF_setFontSizeScale(14);
     // $sql    = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
     // .   ' WHERE master_db   = \'' . PMA_sqlAddslashes($db) . '\' '
     // .   ' AND foreign_db    = \'' . PMA_sqlAddslashes($db) . '\' '
     // .   ' AND master_table  IN (' . $intable . ')'
     // .   ' AND foreign_table IN (' . $intable . ')';
     // $result =  PMA_query_as_cu($sql);
     // lem9:
     // 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->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     // loic1: also show tables without relations
     // $norelations     = TRUE;
     // if ($result && PMA_DBI_num_rows($result) > 0) {
     // $norelations = FALSE;
     // while ($row = PMA_DBI_fetch_assoc($result)) {
     // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
     // }
     // }
     // if ($norelations == FALSE) {
     if ($seen_a_relation) {
         $this->PMA_RT_drawRelations($change_color);
     }
     $this->PMA_RT_drawTables($show_info, $change_color);
     $this->PMA_RT_showRt();
 }
Beispiel #6
0
 /**
  * Test for PMA_PDF::getPDFData
  *
  * @group large
  * @return void
  */
 public function testDocument()
 {
     $pdf = new PMA_PDF();
     $pdf->SetTitle('Title');
     $pdf->Open();
     $pdf->SetAutoPageBreak('auto');
     $pdf->Addpage();
     $pdf->SetFont(PMA_PDF_FONT, 'B', 14);
     $pdf->Cell(0, 6, 'Cell', 'B', 1, 'C');
     $pdf->Ln();
     $pdf->Addpage();
     $pdf->Bookmark('Bookmark');
     $pdf->SetMargins(0, 0);
     $pdf->SetDrawColor(200, 200, 200);
     $pdf->line(0, 0, 100, 100);
     $this->assertContains('PDF', $pdf->getPDFData());
 }
 /**
  * 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;
 }
 /**
  * @group large
  */
 public function testAlias()
 {
     $arr = new PMA_PDF();
     $arr->SetAlias('{00}', '32');
     $this->assertContains('PDF', $arr->getPDFData());
 }