Viewing file: pdf_schema.php (52.22 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
' . $strError . ' ' . "\n";
$url_to_goto = '';
echo sprintf($strRelationNotWorking, $url_to_goto, '') . "\n";
}
/**
* Gets the "fpdf" libraries and defines the pdf font path, use unicode version for unicode.
*/
define('FPDF_FONTPATH', './libraries/fpdf/font/');
if ($charset == 'utf-8') {
define('PMA_PDF_FONT', 'FreeSans');
require_once('./libraries/fpdf/ufpdf.php');
class PMA_FPDF extends UFPDF {
};
} else {
define('PMA_PDF_FONT', 'Arial');
require_once('./libraries/fpdf/fpdf.php');
class PMA_FPDF extends FPDF {
};
}
/**
* Extends the "FPDF" class and prepares the work
*
* @access public
* @see FPDF
*/
class PMA_PDF extends PMA_FPDF {
/**
* Defines private properties
*/
var $x_min;
var $y_min;
var $l_marg = 10;
var $t_marg = 10;
var $scale;
var $title;
var $PMA_links;
var $Outlines = array();
var $def_outlines;
var $Alias ;
var $widths;
/**
* The PMA_PDF constructor
*
* This function just refers to the "FPDF" constructor: with PHP3 a class
* must have a constructor
*
* @param string $ The page orientation (p, portrait, l or landscape)
* @param string $ The unit for sizes (pt, mm, cm or in)
* @param mixed $ The page format (A3, A4, A5, letter, legal or an array
* with page sizes)
* @access public
* @see FPDF::FPDF()
*/
function PMA_PDF($orientation = 'L', $unit = 'mm', $format = 'A4')
{
$this->Alias = array() ;
$this->FPDF($orientation, $unit, $format);
} // end of the "PMA_PDF()" method
function SetAlias($name, $value)
{
$this->Alias[$name] = $value ;
}
function _putpages()
{
if (count($this->Alias) > 0) {
$nb = $this->page;
foreach ($this->Alias AS $alias => $value) {
for ($n = 1;$n <= $nb;$n++)
$this->pages[$n] = $this->_strreplace($alias, $value, $this->pages[$n]);
}
}
parent::_putpages();
}
/**
* Sets the scaling factor, defines minimum coordinates and margins
*
* @param double $ The scaling factor
* @param double $ The minimum X coordinate
* @param double $ The minimum Y coordinate
* @param double $ The left margin
* @param double $ The top margin
* @access public
*/
function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1)
{
$this->scale = $scale;
$this->x_min = $x_min;
$this->y_min = $y_min;
if ($this->l_marg != -1) {
$this->l_marg = $l_marg;
}
if ($this->t_marg != -1) {
$this->t_marg = $t_marg;
}
} // end of the "PMA_PDF_setScale" function
/**
* Outputs a scaled cell
*
* @param double $ The cell width
* @param double $ The cell height
* @param string $ The text to output
* @param mixed $ Wether to add borders or not
* @param integer $ Where to put the cursor once the output is done
* @param string $ Align mode
* @param integer $ Whether to fill the cell with a color or not
* @access public
* @see FPDF::Cell()
*/
function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '')
{
$h = $h / $this->scale;
$w = $w / $this->scale;
$this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
} // end of the "PMA_PDF_cellScale" function
/**
* Draws a scaled line
*
* @param double $ The horizontal position of the starting point
* @param double $ The vertical position of the starting point
* @param double $ The horizontal position of the ending point
* @param double $ The vertical position of the ending point
* @access public
* @see FPDF::Line()
*/
function PMA_PDF_lineScale($x1, $y1, $x2, $y2)
{
$x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg;
$y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg;
$x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg;
$y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg;
$this->Line($x1, $y1, $x2, $y2);
} // end of the "PMA_PDF_lineScale" function
/**
* Sets x and y scaled positions
*
* @param double $ The x position
* @param double $ The y position
* @access public
* @see FPDF::SetXY()
*/
function PMA_PDF_setXyScale($x, $y)
{
$x = ($x - $this->x_min) / $this->scale + $this->l_marg;
$y = ($y - $this->y_min) / $this->scale + $this->t_marg;
$this->SetXY($x, $y);
} // end of the "PMA_PDF_setXyScale" function
/**
* Sets the X scaled positions
*
* @param double $ The x position
* @access public
* @see FPDF::SetX()
*/
function PMA_PDF_setXScale($x)
{
$x = ($x - $this->x_min) / $this->scale + $this->l_marg;
$this->SetX($x);
} // end of the "PMA_PDF_setXScale" function
/**
* Sets the scaled font size
*
* @param double $ The font size (in points)
* @access public
* @see FPDF::SetFontSize()
*/
function PMA_PDF_setFontSizeScale($size)
{
// Set font size in points
$size = $size / $this->scale;
$this->SetFontSize($size);
} // end of the "PMA_PDF_setFontSizeScale" function
/**
* Sets the scaled line width
*
* @param double $ The line width
* @access public
* @see FPDF::SetLineWidth()
*/
function PMA_PDF_setLineWidthScale($width)
{
$width = $width / $this->scale;
$this->SetLineWidth($width);
} // end of the "PMA_PDF_setLineWidthScale" function
/**
* Displays an error message
*
* @param string $ the error mesage
* @global array the PMA configuration array
* @global integer the current server id
* @global string the current language
* @global string the charset to convert to
* @global string the current database name
* @global string the current charset
* @global string the current text direction
* @global string a localized string
* @global string an other localized string
* @access public
*/
function PMA_PDF_die($error_message = '')
{
global $cfg;
global $server, $lang, $convcharset, $db;
global $charset, $text_dir, $strRunning, $strDatabase;
require_once('./libraries/header.inc.php');
echo 'PDF - ' . $GLOBALS['strError'] . ' ' . "\n";
if (!empty($error_message)) {
$error_message = htmlspecialchars($error_message);
}
echo '' . "\n";
echo ' ' . $error_message . "\n";
echo ' ' . "\n";
echo '' . $GLOBALS['strBack'] . '';
echo "\n";
require_once('./libraries/footer.inc.php');
} // end of the "PMA_PDF_die()" function
/**
* Aliases the "Error()" function from the FPDF class to the
* "PMA_PDF_die()" one
*
* @param string $ the error mesage
* @access public
* @see PMA_PDF_die
*/
function Error($error_message = '')
{
$this->PMA_PDF_die($error_message);
} // end of the "Error()" method
function Header()
{
// $datefmt
// We only show this if we find something in the new pdf_pages table
// This function must be named "Header" to work with the FPDF library
global $cfgRelation, $db, $pdf_page_number, $with_doc;
if ($with_doc) {
$test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND page_nr = \'' . $pdf_page_number . '\'';
$test_rs = PMA_query_as_cu($test_query);
$pages = @PMA_DBI_fetch_assoc($test_rs);
$this->SetFont('', 'B', 14);
$this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C');
$this->SetFont('', '');
$this->Ln();
}
}
function Footer()
{
// This function must be named "Footer" to work with the FPDF library
global $with_doc;
if ($with_doc) {
$this->SetY(-15);
$this->SetFont('', '', 14);
$this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C');
$this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R');
$this->SetY(20);
}
}
function Bookmark($txt, $level = 0, $y = 0)
{
// Add a bookmark
$this->Outlines[0][] = $level;
$this->Outlines[1][] = $txt;
$this->Outlines[2][] = $this->page;
if ($y == -1) {
$y = $this->GetY();
}
$this->Outlines[3][] = round($this->hPt - $y * $this->k, 2);
}
function _putbookmarks()
{
if (count($this->Outlines) > 0) {
// Save object number
$memo_n = $this->n;
// Take the number of sub elements for an outline
$nb_outlines = sizeof($this->Outlines[0]);
$first_level = array();
$parent = array();
$parent[0] = 1;
for ($i = 0; $i < $nb_outlines; $i++) {
$level = $this->Outlines[0][$i];
$kids = 0;
$last = -1;
$prev = -1;
$next = -1;
if ($i > 0) {
$cursor = $i-1;
// Take the previous outline in the same level
while ($this->Outlines[0][$cursor] > $level && $cursor > 0)
$cursor--;
if ($this->Outlines[0][$cursor] == $level) {
$prev = $cursor;
}
}
if ($i < $nb_outlines-1) {
$cursor = $i + 1;
while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) {
// Take the immediate kid in level + 1
if ($this->Outlines[0][$cursor] == $level + 1) {
$kids++;
$last = $cursor;
}
$cursor++;
}
$cursor = $i + 1;
// Take the next outline in the same level
while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0])))
$cursor++;
if ($this->Outlines[0][$cursor] == $level) {
$next = $cursor;
}
}
$this->_newobj();
$parent[$level + 1] = $this->n;
if ($level == 0) {
$first_level[] = $this->n;
}
$this->_out('<<');
$this->_out('/Title (' . $this->Outlines[1][$i] . ')');
$this->_out('/Parent ' . $parent[$level] . ' 0 R');
if ($prev != -1) {
$this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R');
}
if ($next != -1) {
$this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R');
}
$this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]');
if ($kids > 0) {
$this->_out('/First ' . ($this->n + 1) . ' 0 R');
$this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R');
$this->_out('/Count -' . $kids);
}
$this->_out('>>');
$this->_out('endobj');
}
// First page of outlines
$this->_newobj();
$this->def_outlines = $this->n;
$this->_out('<<');
$this->_out('/Type');
$this->_out('/Outlines');
$this->_out('/First ' . $first_level[0] . ' 0 R');
$this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R');
$this->_out('/Count ' . sizeof($first_level));
$this->_out('>>');
$this->_out('endobj');
}
}
function _putresources()
{
parent::_putresources();
$this->_putbookmarks();
}
function _putcatalog()
{
parent::_putcatalog();
if (count($this->Outlines) > 0) {
$this->_out('/Outlines ' . $this->def_outlines . ' 0 R');
$this->_out('/PageMode /UseOutlines');
}
}
function SetWidths($w)
{
// column widths
$this->widths = $w;
}
function Row($data, $links)
{
// line height
$nb = 0;
$data_cnt = count($data);
for ($i = 0;$i < $data_cnt;$i++)
$nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
$il = $this->FontSize;
$h = ($il + 1) * $nb;
// page break if necessary
$this->CheckPageBreak($h);
// draw the cells
$data_cnt = count($data);
for ($i = 0;$i < $data_cnt;$i++) {
$w = $this->widths[$i];
// save current position
$x = $this->GetX();
$y = $this->GetY();
// draw the border
$this->Rect($x, $y, $w, $h);
if (isset($links[$i])) {
$this->Link($x, $y, $w, $h, $links[$i]);
}
// print text
$this->MultiCell($w, $il + 1, $data[$i], 0, 'L');
// go to right side
$this->SetXY($x + $w, $y);
}
// go to line
$this->Ln($h);
}
function CheckPageBreak($h)
{
// if height h overflows, manual page break
if ($this->GetY() + $h > $this->PageBreakTrigger) {
$this->AddPage($this->CurOrientation);
}
}
function NbLines($w, $txt)
{
// compute number of lines used by a multicell of width w
$cw = &$this->CurrentFont['cw'];
if ($w == 0) {
$w = $this->w - $this->rMargin - $this->x;
}
$wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize;
$s = str_replace("\r", '', $txt);
$nb = strlen($s);
if ($nb > 0 and $s[$nb-1] == "\n") {
$nb--;
}
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while ($i < $nb) {
$c = $s[$i];
if ($c == "\n") {
$i++;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
continue;
}
if ($c == ' ') {
$sep = $i;
}
$l += isset($cw[ord($c)])?$cw[ord($c)]:0 ;
if ($l > $wmax) {
if ($sep == -1) {
if ($i == $j) {
$i++;
}
} else {
$i = $sep + 1;
}
$sep = -1;
$j = $i;
$l = 0;
$nl++;
} else {
$i++;
}
}
return $nl;
}
} // end of the "PMA_PDF" class
/**
* Draws tables schema
*
* @access private
* @see PMA_RT
*/
class PMA_RT_Table {
/**
* Defines private properties
*/
var $nb_fiels;
var $table_name;
var $width = 0;
var $height;
var $fields = array();
var $height_cell = 6;
var $x, $y;
var $primary = array();
/**
* Sets the width of the table
*
* @param integer $ The font size
* @global object The current PDF document
* @access private
* @see PMA_PDF
*/
function PMA_RT_Table_setWidth($ff)
{
// this looks buggy to me... does it really work if
// there are fields that require wider cells than the name of the table?
global $pdf;
foreach ($this->fields AS $field) {
$this->width = max($this->width, $pdf->GetStringWidth($field));
}
$this->width += $pdf->GetStringWidth(' ');
$pdf->SetFont($ff, 'B');
$this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name));
$pdf->SetFont($ff, '');
} // end of the "PMA_RT_Table_setWidth()" method
/**
* Sets the height of the table
*
* @access private
*/
function PMA_RT_Table_setHeight()
{
$this->height = (count($this->fields) + 1) * $this->height_cell;
} // end of the "PMA_RT_Table_setHeight()" method
/**
* Do draw the table
*
* @param boolean $ Whether to display table position or not
* @param integer $ The font size
* @param boolean $ Whether to display color
* @param integer $ The max. with among tables
* @global object The current PDF document
* @access private
* @see PMA_PDF
*/
function PMA_RT_Table_draw($show_info, $ff, $setcolor = 0)
{
global $pdf, $with_doc;
$pdf->PMA_PDF_setXyScale($this->x, $this->y);
$pdf->SetFont($ff, 'B');
if ($setcolor) {
$pdf->SetTextColor(200);
$pdf->SetFillColor(0, 0, 128);
}
if ($with_doc) {
$pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1);
} else {
$pdf->PMA_links['doc'][$this->table_name]['-'] = '';
}
if ($show_info) {
$pdf->PMA_PDF_cellScale($this->width, $this->height_cell, sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) . ' ' . $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
} else {
$pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']);
}
$pdf->PMA_PDF_setXScale($this->x);
$pdf->SetFont($ff, '');
$pdf->SetTextColor(0);
$pdf->SetFillColor(255);
foreach ($this->fields AS $field) {
// loic1 : PHP3 fix
// if (in_array($field, $this->primary)) {
if ($setcolor) {
if (in_array($field, $this->primary)) {
$pdf->SetFillColor(215, 121, 123);
}
if ($field == $this->displayfield) {
$pdf->SetFillColor(142, 159, 224);
}
}
if ($with_doc) {
$pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1);
} else {
$pdf->PMA_links['doc'][$this->table_name][$field] = '';
}
$pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]);
$pdf->PMA_PDF_setXScale($this->x);
$pdf->SetFillColor(255);
} // end while
/*if ($pdf->PageNo() > 1) {
$pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']);
} */
} // end of the "PMA_RT_Table_draw()" method
/**
* The "PMA_RT_Table" constructor
*
* @param string $ The table name
* @param integer $ The font size
* @param integer $ The max. with among tables
* @global object The current PDF document
* @global integer The current page number (from the
* $cfg['Servers'][$i]['table_coords'] table)
* @global array The relations settings
* @global string The current db name
* @access private
* @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth,
PMA_RT_Table::PMA_RT_Table_setHeight
*/
function PMA_RT_Table($table_name, $ff, &$same_wide_width)
{
global $pdf, $pdf_page_number, $cfgRelation, $db;
$this->table_name = $table_name;
$sql = 'DESCRIBE ' . PMA_backquote($table_name);
$result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
if (!$result bool(false)
|