/** * 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(); }
/** * 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(); }