📄 pdf_schema.php
字号:
// x_left, x_right, y return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell); } // end of the "PMA_RT_Relation_getXy()" method /** * Do draws relation links * * @param boolean $ Whether to use one color per relation or not * @param integer $ The id of the link to draw * @global object The current PDF document * @access private * @see PMA_PDF */ function PMA_RT_Relation_draw($change_color, $i) { global $pdf; if ($change_color) { $d = $i % 6; $j = ($i - $d) / 6; $j = $j % 4; $j++; $case = array( array(1, 0, 0), array(0, 1, 0), array(0, 0, 1), array(1, 1, 0), array(1, 0, 1), array(0, 1, 1) ); list ($a, $b, $c) = $case[$d]; $e = (1 - ($j - 1) / 6); $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); } else { $pdf->SetDrawColor(0); } // end if... else... $pdf->PMA_PDF_setLineWidthScale(0.2); $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src); $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest); $pdf->PMA_PDF_setLineWidthScale(0.1); $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick, $this->y_src, $this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest); // arrow $root2 = 2 * sqrt(2); $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src + $this->w_tick / $root2); $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src - $this->w_tick / $root2); $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick / 2, $this->y_dest, $this->x_dest + $this->dest_dir * (0.5 + 1 / $root2) * $this->w_tick, $this->y_dest + $this->w_tick / $root2); $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick / 2, $this->y_dest, $this->x_dest + $this->dest_dir * (0.5 + 1 / $root2) * $this->w_tick, $this->y_dest - $this->w_tick / $root2); $pdf->SetDrawColor(0); } // end of the "PMA_RT_Relation_draw()" method /** * The "PMA_RT_Relation" constructor * * @param string $ The master table name * @param string $ The relation field in the master table * @param string $ The foreign table name * @param string $ The relation field in the foreign table * @access private * @see PMA_RT_Relation::PMA_RT_Relation_getXy */ function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field) { $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field); $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field); $src_left = $src_pos[0] - $this->w_tick; $src_right = $src_pos[1] + $this->w_tick; $dest_left = $dest_pos[0] - $this->w_tick; $dest_right = $dest_pos[1] + $this->w_tick; $d1 = abs($src_left - $dest_left); $d2 = abs($src_right - $dest_left); $d3 = abs($src_left - $dest_right); $d4 = abs($src_right - $dest_right); $d = min($d1, $d2, $d3, $d4); if ($d == $d1) { $this->x_src = $src_pos[0]; $this->src_dir = -1; $this->x_dest = $dest_pos[0]; $this->dest_dir = -1; } elseif ($d == $d2) { $this->x_src = $src_pos[1]; $this->src_dir = 1; $this->x_dest = $dest_pos[0]; $this->dest_dir = -1; } elseif ($d == $d3) { $this->x_src = $src_pos[0]; $this->src_dir = -1; $this->x_dest = $dest_pos[1]; $this->dest_dir = 1; } else { $this->x_src = $src_pos[1]; $this->src_dir = 1; $this->x_dest = $dest_pos[1]; $this->dest_dir = 1; } $this->y_src = $src_pos[2]; $this->y_dest = $dest_pos[2]; } // end of the "PMA_RT_Relation()" method} // end of the "PMA_RT_Relation" class/** * Draws and send the database schema * * @access public * @see PMA_PDF */class PMA_RT { /** * Defines private properties */ var $tables = array(); var $relations = array(); var $ff = PMA_PDF_FONT; var $x_max = 0; var $y_max = 0; var $scale; var $x_min = 100000; var $y_min = 100000; var $t_marg = 10; var $b_marg = 10; var $l_marg = 10; var $r_marg = 10; var $tablewidth; var $same_wide = 0; /** * Sets X and Y minimum and maximum for a table cell * * @param string $ The table name * @access private */ function PMA_RT_setMinMax($table) { $this->x_max = max($this->x_max, $table->x + $table->width); $this->y_max = max($this->y_max, $table->y + $table->height); $this->x_min = min($this->x_min, $table->x); $this->y_min = min($this->y_min, $table->y); } // end of the "PMA_RT_setMinMax()" method /** * Defines relation objects * * @param string $ The master table name * @param string $ The relation field in the master table * @param string $ The foreign table name * @param string $ The relation field in the foreign table * @access private * @see PMA_RT_setMinMax */ function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field) { if (!isset($this->tables[$master_table])) { $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth); $this->PMA_RT_setMinMax($this->tables[$master_table]); } if (!isset($this->tables[$foreign_table])) { $this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth); $this->PMA_RT_setMinMax($this->tables[$foreign_table]); } $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field); } // end of the "PMA_RT_addRelation()" method /** * Draws the grid * * @global object the current PMA_PDF instance * @access private * @see PMA_PDF */ function PMA_RT_strokeGrid() { global $pdf; $pdf->SetMargins(0, 0); $pdf->SetDrawColor(200, 200, 200); // Draws horizontal lines for ($l = 0; $l < 21; $l++) { $pdf->line(0, $l * 10, $pdf->fh, $l * 10); // Avoid duplicates if ($l > 0) { $pdf->SetXY(0, $l * 10); $label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min); $pdf->Cell(5, 5, ' ' . $label); } // end if } // end for // Draws vertical lines for ($j = 0; $j < 30 ;$j++) { $pdf->line($j * 10, 0, $j * 10, $pdf->fw); $pdf->SetXY($j * 10, 0); $label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min); $pdf->Cell(5, 7, $label); } // end for } // end of the "PMA_RT_strokeGrid()" method /** * Draws relation arrows * * @param boolean $ Whether to use one color per relation or not * @access private * @see PMA_RT_Relation::PMA_RT_Relation_draw() */ function PMA_RT_drawRelations($change_color) { $i = 0; foreach ($this->relations AS $relation) { $relation->PMA_RT_Relation_draw($change_color, $i); $i++; } // end while } // end of the "PMA_RT_drawRelations()" method /** * Draws tables * * @param boolean $ Whether to display table position or not * @access private * @see PMA_RT_Table::PMA_RT_Table_draw() */ function PMA_RT_drawTables($show_info, $draw_color = 0) { foreach ($this->tables AS $table) { $table->PMA_RT_Table_draw($show_info, $this->ff, $draw_color); } } // end of the "PMA_RT_drawTables()" method /** * Ouputs the PDF document to a file * * @global object The current PDF document * @global string The current database name * @global integer The current page number (from the * $cfg['Servers'][$i]['table_coords'] table) * @access private * @see PMA_PDF */ function PMA_RT_showRt() { global $pdf, $db, $pdf_page_number, $cfgRelation; $pdf->SetFontSize(14); $pdf->SetLineWidth(0.2); $pdf->SetDisplayMode('fullpage'); // Get the name of this pdfpage to use as filename (Mike Beck) $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE page_nr = ' . $pdf_page_number; $_name_rs = PMA_query_as_cu($_name_sql); if ($_name_rs) { $_name_row = PMA_DBI_fetch_row($_name_rs); $filename = $_name_row[0] . '.pdf'; } // i don't know if there is a chance for this to happen, but rather be on the safe side: if (empty($filename)) { $filename = $pdf_page_number . '.pdf'; } // $pdf->Output($db . '_' . $filename, TRUE); $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline } // end of the "PMA_RT_showRt()" method /** * 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; $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(); $pdf->AddFont('DejaVuSans', '', 'dejavusans.php'); $pdf->AddFont('DejaVuSans', 'B', 'dejavusans-bold.php'); $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php'); $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserif-bold.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->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($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' ' // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -