250 |
kaklik |
1 |
<?php |
|
|
2 |
/* $Id: pdf_schema.php,v 2.25 2006/01/19 15:39:29 cybot_tm Exp $ */ |
|
|
3 |
// vim: expandtab sw=4 ts=4 sts=4: |
|
|
4 |
/** |
|
|
5 |
* Contributed by Maxime Delorme and merged by lem9 |
|
|
6 |
*/ |
|
|
7 |
|
|
|
8 |
/** |
|
|
9 |
* Gets some core scripts |
|
|
10 |
*/ |
|
|
11 |
require_once('./libraries/common.lib.php'); |
|
|
12 |
|
|
|
13 |
/** |
|
|
14 |
* Settings for relation stuff |
|
|
15 |
*/ |
|
|
16 |
require_once('./libraries/relation.lib.php'); |
|
|
17 |
require_once('./libraries/transformations.lib.php'); |
|
|
18 |
|
|
|
19 |
$cfgRelation = PMA_getRelationsParam(); |
|
|
20 |
|
|
|
21 |
/** |
|
|
22 |
* Now in ./libraries/relation.lib.php we check for all tables |
|
|
23 |
* that we need, but if we don't find them we are quiet about it |
|
|
24 |
* so people can work without. |
|
|
25 |
* This page is absolutely useless if you didn't set up your tables |
|
|
26 |
* correctly, so it is a good place to see which tables we can and |
|
|
27 |
* complain ;-) |
|
|
28 |
*/ |
|
|
29 |
if (!$cfgRelation['pdfwork']) { |
|
|
30 |
echo '<font color="red">' . $strError . '</font><br />' . "\n"; |
|
|
31 |
$url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">'; |
|
|
32 |
echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n"; |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
/** |
|
|
36 |
* Gets the "fpdf" libraries and defines the pdf font path, use unicode version for unicode. |
|
|
37 |
*/ |
|
|
38 |
define('FPDF_FONTPATH', './libraries/fpdf/font/'); |
|
|
39 |
if ($charset == 'utf-8') { |
|
|
40 |
define('PMA_PDF_FONT', 'FreeSans'); |
|
|
41 |
require_once('./libraries/fpdf/ufpdf.php'); |
|
|
42 |
class PMA_FPDF extends UFPDF { |
|
|
43 |
}; |
|
|
44 |
} else { |
|
|
45 |
define('PMA_PDF_FONT', 'Arial'); |
|
|
46 |
require_once('./libraries/fpdf/fpdf.php'); |
|
|
47 |
class PMA_FPDF extends FPDF { |
|
|
48 |
}; |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
/** |
|
|
52 |
* Extends the "FPDF" class and prepares the work |
|
|
53 |
* |
|
|
54 |
* @access public |
|
|
55 |
* @see FPDF |
|
|
56 |
*/ |
|
|
57 |
class PMA_PDF extends PMA_FPDF { |
|
|
58 |
/** |
|
|
59 |
* Defines private properties |
|
|
60 |
*/ |
|
|
61 |
var $x_min; |
|
|
62 |
var $y_min; |
|
|
63 |
var $l_marg = 10; |
|
|
64 |
var $t_marg = 10; |
|
|
65 |
var $scale; |
|
|
66 |
var $title; |
|
|
67 |
var $PMA_links; |
|
|
68 |
var $Outlines = array(); |
|
|
69 |
var $def_outlines; |
|
|
70 |
var $Alias ; |
|
|
71 |
var $widths; |
|
|
72 |
|
|
|
73 |
/** |
|
|
74 |
* The PMA_PDF constructor |
|
|
75 |
* |
|
|
76 |
* This function just refers to the "FPDF" constructor: with PHP3 a class |
|
|
77 |
* must have a constructor |
|
|
78 |
* |
|
|
79 |
* @param string $ The page orientation (p, portrait, l or landscape) |
|
|
80 |
* @param string $ The unit for sizes (pt, mm, cm or in) |
|
|
81 |
* @param mixed $ The page format (A3, A4, A5, letter, legal or an array |
|
|
82 |
* with page sizes) |
|
|
83 |
* @access public |
|
|
84 |
* @see FPDF::FPDF() |
|
|
85 |
*/ |
|
|
86 |
function PMA_PDF($orientation = 'L', $unit = 'mm', $format = 'A4') |
|
|
87 |
{ |
|
|
88 |
$this->Alias = array() ; |
|
|
89 |
$this->FPDF($orientation, $unit, $format); |
|
|
90 |
} // end of the "PMA_PDF()" method |
|
|
91 |
function SetAlias($name, $value) |
|
|
92 |
{ |
|
|
93 |
$this->Alias[$name] = $value ; |
|
|
94 |
} |
|
|
95 |
function _putpages() |
|
|
96 |
{ |
|
|
97 |
if (count($this->Alias) > 0) { |
|
|
98 |
$nb = $this->page; |
|
|
99 |
foreach ($this->Alias AS $alias => $value) { |
|
|
100 |
for ($n = 1;$n <= $nb;$n++) |
|
|
101 |
$this->pages[$n] = $this->_strreplace($alias, $value, $this->pages[$n]); |
|
|
102 |
} |
|
|
103 |
} |
|
|
104 |
parent::_putpages(); |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
/** |
|
|
108 |
* Sets the scaling factor, defines minimum coordinates and margins |
|
|
109 |
* |
|
|
110 |
* @param double $ The scaling factor |
|
|
111 |
* @param double $ The minimum X coordinate |
|
|
112 |
* @param double $ The minimum Y coordinate |
|
|
113 |
* @param double $ The left margin |
|
|
114 |
* @param double $ The top margin |
|
|
115 |
* @access public |
|
|
116 |
*/ |
|
|
117 |
function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1) |
|
|
118 |
{ |
|
|
119 |
$this->scale = $scale; |
|
|
120 |
$this->x_min = $x_min; |
|
|
121 |
$this->y_min = $y_min; |
|
|
122 |
if ($this->l_marg != -1) { |
|
|
123 |
$this->l_marg = $l_marg; |
|
|
124 |
} |
|
|
125 |
if ($this->t_marg != -1) { |
|
|
126 |
$this->t_marg = $t_marg; |
|
|
127 |
} |
|
|
128 |
} // end of the "PMA_PDF_setScale" function |
|
|
129 |
/** |
|
|
130 |
* Outputs a scaled cell |
|
|
131 |
* |
|
|
132 |
* @param double $ The cell width |
|
|
133 |
* @param double $ The cell height |
|
|
134 |
* @param string $ The text to output |
|
|
135 |
* @param mixed $ Wether to add borders or not |
|
|
136 |
* @param integer $ Where to put the cursor once the output is done |
|
|
137 |
* @param string $ Align mode |
|
|
138 |
* @param integer $ Whether to fill the cell with a color or not |
|
|
139 |
* @access public |
|
|
140 |
* @see FPDF::Cell() |
|
|
141 |
*/ |
|
|
142 |
function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '') |
|
|
143 |
{ |
|
|
144 |
$h = $h / $this->scale; |
|
|
145 |
$w = $w / $this->scale; |
|
|
146 |
$this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link); |
|
|
147 |
} // end of the "PMA_PDF_cellScale" function |
|
|
148 |
/** |
|
|
149 |
* Draws a scaled line |
|
|
150 |
* |
|
|
151 |
* @param double $ The horizontal position of the starting point |
|
|
152 |
* @param double $ The vertical position of the starting point |
|
|
153 |
* @param double $ The horizontal position of the ending point |
|
|
154 |
* @param double $ The vertical position of the ending point |
|
|
155 |
* @access public |
|
|
156 |
* @see FPDF::Line() |
|
|
157 |
*/ |
|
|
158 |
function PMA_PDF_lineScale($x1, $y1, $x2, $y2) |
|
|
159 |
{ |
|
|
160 |
$x1 = ($x1 - $this->x_min) / $this->scale + $this->l_marg; |
|
|
161 |
$y1 = ($y1 - $this->y_min) / $this->scale + $this->t_marg; |
|
|
162 |
$x2 = ($x2 - $this->x_min) / $this->scale + $this->l_marg; |
|
|
163 |
$y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg; |
|
|
164 |
$this->Line($x1, $y1, $x2, $y2); |
|
|
165 |
} // end of the "PMA_PDF_lineScale" function |
|
|
166 |
/** |
|
|
167 |
* Sets x and y scaled positions |
|
|
168 |
* |
|
|
169 |
* @param double $ The x position |
|
|
170 |
* @param double $ The y position |
|
|
171 |
* @access public |
|
|
172 |
* @see FPDF::SetXY() |
|
|
173 |
*/ |
|
|
174 |
function PMA_PDF_setXyScale($x, $y) |
|
|
175 |
{ |
|
|
176 |
$x = ($x - $this->x_min) / $this->scale + $this->l_marg; |
|
|
177 |
$y = ($y - $this->y_min) / $this->scale + $this->t_marg; |
|
|
178 |
$this->SetXY($x, $y); |
|
|
179 |
} // end of the "PMA_PDF_setXyScale" function |
|
|
180 |
/** |
|
|
181 |
* Sets the X scaled positions |
|
|
182 |
* |
|
|
183 |
* @param double $ The x position |
|
|
184 |
* @access public |
|
|
185 |
* @see FPDF::SetX() |
|
|
186 |
*/ |
|
|
187 |
function PMA_PDF_setXScale($x) |
|
|
188 |
{ |
|
|
189 |
$x = ($x - $this->x_min) / $this->scale + $this->l_marg; |
|
|
190 |
$this->SetX($x); |
|
|
191 |
} // end of the "PMA_PDF_setXScale" function |
|
|
192 |
/** |
|
|
193 |
* Sets the scaled font size |
|
|
194 |
* |
|
|
195 |
* @param double $ The font size (in points) |
|
|
196 |
* @access public |
|
|
197 |
* @see FPDF::SetFontSize() |
|
|
198 |
*/ |
|
|
199 |
function PMA_PDF_setFontSizeScale($size) |
|
|
200 |
{ |
|
|
201 |
// Set font size in points |
|
|
202 |
$size = $size / $this->scale; |
|
|
203 |
$this->SetFontSize($size); |
|
|
204 |
} // end of the "PMA_PDF_setFontSizeScale" function |
|
|
205 |
/** |
|
|
206 |
* Sets the scaled line width |
|
|
207 |
* |
|
|
208 |
* @param double $ The line width |
|
|
209 |
* @access public |
|
|
210 |
* @see FPDF::SetLineWidth() |
|
|
211 |
*/ |
|
|
212 |
function PMA_PDF_setLineWidthScale($width) |
|
|
213 |
{ |
|
|
214 |
$width = $width / $this->scale; |
|
|
215 |
$this->SetLineWidth($width); |
|
|
216 |
} // end of the "PMA_PDF_setLineWidthScale" function |
|
|
217 |
/** |
|
|
218 |
* Displays an error message |
|
|
219 |
* |
|
|
220 |
* @param string $ the error mesage |
|
|
221 |
* @global array the PMA configuration array |
|
|
222 |
* @global integer the current server id |
|
|
223 |
* @global string the current language |
|
|
224 |
* @global string the charset to convert to |
|
|
225 |
* @global string the current database name |
|
|
226 |
* @global string the current charset |
|
|
227 |
* @global string the current text direction |
|
|
228 |
* @global string a localized string |
|
|
229 |
* @global string an other localized string |
|
|
230 |
* @access public |
|
|
231 |
*/ |
|
|
232 |
function PMA_PDF_die($error_message = '') |
|
|
233 |
{ |
|
|
234 |
global $cfg; |
|
|
235 |
global $server, $lang, $convcharset, $db; |
|
|
236 |
global $charset, $text_dir, $strRunning, $strDatabase; |
|
|
237 |
|
|
|
238 |
require_once('./libraries/header.inc.php'); |
|
|
239 |
|
|
|
240 |
echo '<p><b>PDF - ' . $GLOBALS['strError'] . '</b></p>' . "\n"; |
|
|
241 |
if (!empty($error_message)) { |
|
|
242 |
$error_message = htmlspecialchars($error_message); |
|
|
243 |
} |
|
|
244 |
echo '<p>' . "\n"; |
|
|
245 |
echo ' ' . $error_message . "\n"; |
|
|
246 |
echo '</p>' . "\n"; |
|
|
247 |
|
|
|
248 |
echo '<a href="db_details_structure.php?' . PMA_generate_common_url($db) |
|
|
249 |
. '">' . $GLOBALS['strBack'] . '</a>'; |
|
|
250 |
echo "\n"; |
|
|
251 |
|
|
|
252 |
require_once('./libraries/footer.inc.php'); |
|
|
253 |
} // end of the "PMA_PDF_die()" function |
|
|
254 |
/** |
|
|
255 |
* Aliases the "Error()" function from the FPDF class to the |
|
|
256 |
* "PMA_PDF_die()" one |
|
|
257 |
* |
|
|
258 |
* @param string $ the error mesage |
|
|
259 |
* @access public |
|
|
260 |
* @see PMA_PDF_die |
|
|
261 |
*/ |
|
|
262 |
function Error($error_message = '') |
|
|
263 |
{ |
|
|
264 |
$this->PMA_PDF_die($error_message); |
|
|
265 |
} // end of the "Error()" method |
|
|
266 |
function Header() |
|
|
267 |
{ |
|
|
268 |
// $datefmt |
|
|
269 |
// We only show this if we find something in the new pdf_pages table |
|
|
270 |
|
|
|
271 |
// This function must be named "Header" to work with the FPDF library |
|
|
272 |
global $cfgRelation, $db, $pdf_page_number, $with_doc; |
|
|
273 |
if ($with_doc) { |
|
|
274 |
$test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) |
|
|
275 |
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' |
|
|
276 |
. ' AND page_nr = \'' . $pdf_page_number . '\''; |
|
|
277 |
$test_rs = PMA_query_as_cu($test_query); |
|
|
278 |
$pages = @PMA_DBI_fetch_assoc($test_rs); |
|
|
279 |
$this->SetFont('', 'B', 14); |
|
|
280 |
$this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C'); |
|
|
281 |
$this->SetFont('', ''); |
|
|
282 |
$this->Ln(); |
|
|
283 |
} |
|
|
284 |
} |
|
|
285 |
function Footer() |
|
|
286 |
{ |
|
|
287 |
// This function must be named "Footer" to work with the FPDF library |
|
|
288 |
global $with_doc; |
|
|
289 |
if ($with_doc) { |
|
|
290 |
$this->SetY(-15); |
|
|
291 |
$this->SetFont('', '', 14); |
|
|
292 |
$this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C'); |
|
|
293 |
$this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R'); |
|
|
294 |
$this->SetY(20); |
|
|
295 |
} |
|
|
296 |
} |
|
|
297 |
function Bookmark($txt, $level = 0, $y = 0) |
|
|
298 |
{ |
|
|
299 |
// Add a bookmark |
|
|
300 |
$this->Outlines[0][] = $level; |
|
|
301 |
$this->Outlines[1][] = $txt; |
|
|
302 |
$this->Outlines[2][] = $this->page; |
|
|
303 |
if ($y == -1) { |
|
|
304 |
$y = $this->GetY(); |
|
|
305 |
} |
|
|
306 |
$this->Outlines[3][] = round($this->hPt - $y * $this->k, 2); |
|
|
307 |
} |
|
|
308 |
|
|
|
309 |
function _putbookmarks() |
|
|
310 |
{ |
|
|
311 |
if (count($this->Outlines) > 0) { |
|
|
312 |
// Save object number |
|
|
313 |
$memo_n = $this->n; |
|
|
314 |
// Take the number of sub elements for an outline |
|
|
315 |
$nb_outlines = sizeof($this->Outlines[0]); |
|
|
316 |
$first_level = array(); |
|
|
317 |
$parent = array(); |
|
|
318 |
$parent[0] = 1; |
|
|
319 |
for ($i = 0; $i < $nb_outlines; $i++) { |
|
|
320 |
$level = $this->Outlines[0][$i]; |
|
|
321 |
$kids = 0; |
|
|
322 |
$last = -1; |
|
|
323 |
$prev = -1; |
|
|
324 |
$next = -1; |
|
|
325 |
if ($i > 0) { |
|
|
326 |
$cursor = $i-1; |
|
|
327 |
// Take the previous outline in the same level |
|
|
328 |
while ($this->Outlines[0][$cursor] > $level && $cursor > 0) |
|
|
329 |
$cursor--; |
|
|
330 |
if ($this->Outlines[0][$cursor] == $level) { |
|
|
331 |
$prev = $cursor; |
|
|
332 |
} |
|
|
333 |
} |
|
|
334 |
if ($i < $nb_outlines-1) { |
|
|
335 |
$cursor = $i + 1; |
|
|
336 |
while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) { |
|
|
337 |
// Take the immediate kid in level + 1 |
|
|
338 |
if ($this->Outlines[0][$cursor] == $level + 1) { |
|
|
339 |
$kids++; |
|
|
340 |
$last = $cursor; |
|
|
341 |
} |
|
|
342 |
$cursor++; |
|
|
343 |
} |
|
|
344 |
$cursor = $i + 1; |
|
|
345 |
// Take the next outline in the same level |
|
|
346 |
while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0]))) |
|
|
347 |
$cursor++; |
|
|
348 |
if ($this->Outlines[0][$cursor] == $level) { |
|
|
349 |
$next = $cursor; |
|
|
350 |
} |
|
|
351 |
} |
|
|
352 |
$this->_newobj(); |
|
|
353 |
$parent[$level + 1] = $this->n; |
|
|
354 |
if ($level == 0) { |
|
|
355 |
$first_level[] = $this->n; |
|
|
356 |
} |
|
|
357 |
$this->_out('<<'); |
|
|
358 |
$this->_out('/Title (' . $this->Outlines[1][$i] . ')'); |
|
|
359 |
$this->_out('/Parent ' . $parent[$level] . ' 0 R'); |
|
|
360 |
if ($prev != -1) { |
|
|
361 |
$this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R'); |
|
|
362 |
} |
|
|
363 |
if ($next != -1) { |
|
|
364 |
$this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R'); |
|
|
365 |
} |
|
|
366 |
$this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]'); |
|
|
367 |
if ($kids > 0) { |
|
|
368 |
$this->_out('/First ' . ($this->n + 1) . ' 0 R'); |
|
|
369 |
$this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R'); |
|
|
370 |
$this->_out('/Count -' . $kids); |
|
|
371 |
} |
|
|
372 |
$this->_out('>>'); |
|
|
373 |
$this->_out('endobj'); |
|
|
374 |
} |
|
|
375 |
// First page of outlines |
|
|
376 |
$this->_newobj(); |
|
|
377 |
$this->def_outlines = $this->n; |
|
|
378 |
$this->_out('<<'); |
|
|
379 |
$this->_out('/Type'); |
|
|
380 |
$this->_out('/Outlines'); |
|
|
381 |
$this->_out('/First ' . $first_level[0] . ' 0 R'); |
|
|
382 |
$this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R'); |
|
|
383 |
$this->_out('/Count ' . sizeof($first_level)); |
|
|
384 |
$this->_out('>>'); |
|
|
385 |
$this->_out('endobj'); |
|
|
386 |
} |
|
|
387 |
} |
|
|
388 |
|
|
|
389 |
function _putresources() |
|
|
390 |
{ |
|
|
391 |
parent::_putresources(); |
|
|
392 |
$this->_putbookmarks(); |
|
|
393 |
} |
|
|
394 |
|
|
|
395 |
function _putcatalog() |
|
|
396 |
{ |
|
|
397 |
parent::_putcatalog(); |
|
|
398 |
if (count($this->Outlines) > 0) { |
|
|
399 |
$this->_out('/Outlines ' . $this->def_outlines . ' 0 R'); |
|
|
400 |
$this->_out('/PageMode /UseOutlines'); |
|
|
401 |
} |
|
|
402 |
} |
|
|
403 |
function SetWidths($w) |
|
|
404 |
{ |
|
|
405 |
// column widths |
|
|
406 |
$this->widths = $w; |
|
|
407 |
} |
|
|
408 |
|
|
|
409 |
function Row($data, $links) |
|
|
410 |
{ |
|
|
411 |
// line height |
|
|
412 |
$nb = 0; |
|
|
413 |
$data_cnt = count($data); |
|
|
414 |
for ($i = 0;$i < $data_cnt;$i++) |
|
|
415 |
$nb = max($nb, $this->NbLines($this->widths[$i], $data[$i])); |
|
|
416 |
$il = $this->FontSize; |
|
|
417 |
$h = ($il + 1) * $nb; |
|
|
418 |
// page break if necessary |
|
|
419 |
$this->CheckPageBreak($h); |
|
|
420 |
// draw the cells |
|
|
421 |
$data_cnt = count($data); |
|
|
422 |
for ($i = 0;$i < $data_cnt;$i++) { |
|
|
423 |
$w = $this->widths[$i]; |
|
|
424 |
// save current position |
|
|
425 |
$x = $this->GetX(); |
|
|
426 |
$y = $this->GetY(); |
|
|
427 |
// draw the border |
|
|
428 |
$this->Rect($x, $y, $w, $h); |
|
|
429 |
if (isset($links[$i])) { |
|
|
430 |
$this->Link($x, $y, $w, $h, $links[$i]); |
|
|
431 |
} |
|
|
432 |
// print text |
|
|
433 |
$this->MultiCell($w, $il + 1, $data[$i], 0, 'L'); |
|
|
434 |
// go to right side |
|
|
435 |
$this->SetXY($x + $w, $y); |
|
|
436 |
} |
|
|
437 |
// go to line |
|
|
438 |
$this->Ln($h); |
|
|
439 |
} |
|
|
440 |
|
|
|
441 |
function CheckPageBreak($h) |
|
|
442 |
{ |
|
|
443 |
// if height h overflows, manual page break |
|
|
444 |
if ($this->GetY() + $h > $this->PageBreakTrigger) { |
|
|
445 |
$this->AddPage($this->CurOrientation); |
|
|
446 |
} |
|
|
447 |
} |
|
|
448 |
|
|
|
449 |
function NbLines($w, $txt) |
|
|
450 |
{ |
|
|
451 |
// compute number of lines used by a multicell of width w |
|
|
452 |
$cw = &$this->CurrentFont['cw']; |
|
|
453 |
if ($w == 0) { |
|
|
454 |
$w = $this->w - $this->rMargin - $this->x; |
|
|
455 |
} |
|
|
456 |
$wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; |
|
|
457 |
$s = str_replace("\r", '', $txt); |
|
|
458 |
$nb = strlen($s); |
|
|
459 |
if ($nb > 0 and $s[$nb-1] == "\n") { |
|
|
460 |
$nb--; |
|
|
461 |
} |
|
|
462 |
$sep = -1; |
|
|
463 |
$i = 0; |
|
|
464 |
$j = 0; |
|
|
465 |
$l = 0; |
|
|
466 |
$nl = 1; |
|
|
467 |
while ($i < $nb) { |
|
|
468 |
$c = $s[$i]; |
|
|
469 |
if ($c == "\n") { |
|
|
470 |
$i++; |
|
|
471 |
$sep = -1; |
|
|
472 |
$j = $i; |
|
|
473 |
$l = 0; |
|
|
474 |
$nl++; |
|
|
475 |
continue; |
|
|
476 |
} |
|
|
477 |
if ($c == ' ') { |
|
|
478 |
$sep = $i; |
|
|
479 |
} |
|
|
480 |
$l += isset($cw[ord($c)])?$cw[ord($c)]:0 ; |
|
|
481 |
if ($l > $wmax) { |
|
|
482 |
if ($sep == -1) { |
|
|
483 |
if ($i == $j) { |
|
|
484 |
$i++; |
|
|
485 |
} |
|
|
486 |
} else { |
|
|
487 |
$i = $sep + 1; |
|
|
488 |
} |
|
|
489 |
$sep = -1; |
|
|
490 |
$j = $i; |
|
|
491 |
$l = 0; |
|
|
492 |
$nl++; |
|
|
493 |
} else { |
|
|
494 |
$i++; |
|
|
495 |
} |
|
|
496 |
} |
|
|
497 |
return $nl; |
|
|
498 |
} |
|
|
499 |
} // end of the "PMA_PDF" class |
|
|
500 |
/** |
|
|
501 |
* Draws tables schema |
|
|
502 |
* |
|
|
503 |
* @access private |
|
|
504 |
* @see PMA_RT |
|
|
505 |
*/ |
|
|
506 |
class PMA_RT_Table { |
|
|
507 |
/** |
|
|
508 |
* Defines private properties |
|
|
509 |
*/ |
|
|
510 |
var $nb_fiels; |
|
|
511 |
var $table_name; |
|
|
512 |
var $width = 0; |
|
|
513 |
var $height; |
|
|
514 |
var $fields = array(); |
|
|
515 |
var $height_cell = 6; |
|
|
516 |
var $x, $y; |
|
|
517 |
var $primary = array(); |
|
|
518 |
|
|
|
519 |
/** |
|
|
520 |
* Sets the width of the table |
|
|
521 |
* |
|
|
522 |
* @param integer $ The font size |
|
|
523 |
* @global object The current PDF document |
|
|
524 |
* @access private |
|
|
525 |
* @see PMA_PDF |
|
|
526 |
*/ |
|
|
527 |
function PMA_RT_Table_setWidth($ff) |
|
|
528 |
{ |
|
|
529 |
// this looks buggy to me... does it really work if |
|
|
530 |
// there are fields that require wider cells than the name of the table? |
|
|
531 |
global $pdf; |
|
|
532 |
|
|
|
533 |
foreach ($this->fields AS $field) { |
|
|
534 |
$this->width = max($this->width, $pdf->GetStringWidth($field)); |
|
|
535 |
} |
|
|
536 |
$this->width += $pdf->GetStringWidth(' '); |
|
|
537 |
$pdf->SetFont($ff, 'B'); |
|
|
538 |
$this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name)); |
|
|
539 |
$pdf->SetFont($ff, ''); |
|
|
540 |
} // end of the "PMA_RT_Table_setWidth()" method |
|
|
541 |
/** |
|
|
542 |
* Sets the height of the table |
|
|
543 |
* |
|
|
544 |
* @access private |
|
|
545 |
*/ |
|
|
546 |
function PMA_RT_Table_setHeight() |
|
|
547 |
{ |
|
|
548 |
$this->height = (count($this->fields) + 1) * $this->height_cell; |
|
|
549 |
} // end of the "PMA_RT_Table_setHeight()" method |
|
|
550 |
/** |
|
|
551 |
* Do draw the table |
|
|
552 |
* |
|
|
553 |
* @param boolean $ Whether to display table position or not |
|
|
554 |
* @param integer $ The font size |
|
|
555 |
* @param boolean $ Whether to display color |
|
|
556 |
* @param integer $ The max. with among tables |
|
|
557 |
* @global object The current PDF document |
|
|
558 |
* @access private |
|
|
559 |
* @see PMA_PDF |
|
|
560 |
*/ |
|
|
561 |
function PMA_RT_Table_draw($show_info, $ff, $setcolor = 0) |
|
|
562 |
{ |
|
|
563 |
global $pdf, $with_doc; |
|
|
564 |
|
|
|
565 |
$pdf->PMA_PDF_setXyScale($this->x, $this->y); |
|
|
566 |
$pdf->SetFont($ff, 'B'); |
|
|
567 |
if ($setcolor) { |
|
|
568 |
$pdf->SetTextColor(200); |
|
|
569 |
$pdf->SetFillColor(0, 0, 128); |
|
|
570 |
} |
|
|
571 |
if ($with_doc) { |
|
|
572 |
$pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1); |
|
|
573 |
} else { |
|
|
574 |
$pdf->PMA_links['doc'][$this->table_name]['-'] = ''; |
|
|
575 |
} |
|
|
576 |
|
|
|
577 |
if ($show_info) { |
|
|
578 |
$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]['-']); |
|
|
579 |
} else { |
|
|
580 |
$pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']); |
|
|
581 |
} |
|
|
582 |
$pdf->PMA_PDF_setXScale($this->x); |
|
|
583 |
$pdf->SetFont($ff, ''); |
|
|
584 |
$pdf->SetTextColor(0); |
|
|
585 |
$pdf->SetFillColor(255); |
|
|
586 |
|
|
|
587 |
foreach ($this->fields AS $field) { |
|
|
588 |
// loic1 : PHP3 fix |
|
|
589 |
// if (in_array($field, $this->primary)) { |
|
|
590 |
if ($setcolor) { |
|
|
591 |
if (in_array($field, $this->primary)) { |
|
|
592 |
$pdf->SetFillColor(215, 121, 123); |
|
|
593 |
} |
|
|
594 |
if ($field == $this->displayfield) { |
|
|
595 |
$pdf->SetFillColor(142, 159, 224); |
|
|
596 |
} |
|
|
597 |
} |
|
|
598 |
if ($with_doc) { |
|
|
599 |
$pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1); |
|
|
600 |
} else { |
|
|
601 |
$pdf->PMA_links['doc'][$this->table_name][$field] = ''; |
|
|
602 |
} |
|
|
603 |
|
|
|
604 |
$pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]); |
|
|
605 |
$pdf->PMA_PDF_setXScale($this->x); |
|
|
606 |
$pdf->SetFillColor(255); |
|
|
607 |
} // end while |
|
|
608 |
/*if ($pdf->PageNo() > 1) { |
|
|
609 |
$pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']); |
|
|
610 |
} */ |
|
|
611 |
} // end of the "PMA_RT_Table_draw()" method |
|
|
612 |
/** |
|
|
613 |
* The "PMA_RT_Table" constructor |
|
|
614 |
* |
|
|
615 |
* @param string $ The table name |
|
|
616 |
* @param integer $ The font size |
|
|
617 |
* @param integer $ The max. with among tables |
|
|
618 |
* @global object The current PDF document |
|
|
619 |
* @global integer The current page number (from the |
|
|
620 |
* $cfg['Servers'][$i]['table_coords'] table) |
|
|
621 |
* @global array The relations settings |
|
|
622 |
* @global string The current db name |
|
|
623 |
* @access private |
|
|
624 |
* @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth, |
|
|
625 |
PMA_RT_Table::PMA_RT_Table_setHeight |
|
|
626 |
*/ |
|
|
627 |
function PMA_RT_Table($table_name, $ff, &$same_wide_width) |
|
|
628 |
{ |
|
|
629 |
global $pdf, $pdf_page_number, $cfgRelation, $db; |
|
|
630 |
|
|
|
631 |
$this->table_name = $table_name; |
|
|
632 |
$sql = 'DESCRIBE ' . PMA_backquote($table_name); |
|
|
633 |
$result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE); |
|
|
634 |
if (!$result || !PMA_DBI_num_rows($result)) { |
|
|
635 |
$pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name)); |
|
|
636 |
} |
|
|
637 |
// load fields |
|
|
638 |
while ($row = PMA_DBI_fetch_row($result)) { |
|
|
639 |
$this->fields[] = $row[0]; |
|
|
640 |
} |
|
|
641 |
// height and width |
|
|
642 |
$this->PMA_RT_Table_setWidth($ff); |
|
|
643 |
$this->PMA_RT_Table_setHeight(); |
|
|
644 |
if ($same_wide_width < $this->width) { |
|
|
645 |
$same_wide_width = $this->width; |
|
|
646 |
} |
|
|
647 |
// x and y |
|
|
648 |
$sql = 'SELECT x, y FROM ' |
|
|
649 |
. PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) |
|
|
650 |
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' |
|
|
651 |
. ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\'' |
|
|
652 |
. ' AND pdf_page_number = ' . $pdf_page_number; |
|
|
653 |
$result = PMA_query_as_cu($sql, false, PMA_DBI_QUERY_STORE); |
|
|
654 |
|
|
|
655 |
if (!$result || !PMA_DBI_num_rows($result)) { |
|
|
656 |
$pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name)); |
|
|
657 |
} |
|
|
658 |
list($this->x, $this->y) = PMA_DBI_fetch_row($result); |
|
|
659 |
$this->x = (double) $this->x; |
|
|
660 |
$this->y = (double) $this->y; |
|
|
661 |
// displayfield |
|
|
662 |
$this->displayfield = PMA_getDisplayField($db, $table_name); |
|
|
663 |
// index |
|
|
664 |
$result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE); |
|
|
665 |
if (PMA_DBI_num_rows($result) > 0) { |
|
|
666 |
while ($row = PMA_DBI_fetch_assoc($result)) { |
|
|
667 |
if ($row['Key_name'] == 'PRIMARY') { |
|
|
668 |
$this->primary[] = $row['Column_name']; |
|
|
669 |
} |
|
|
670 |
} |
|
|
671 |
} // end if |
|
|
672 |
} // end of the "PMA_RT_Table()" method |
|
|
673 |
} // end class "PMA_RT_Table" |
|
|
674 |
/** |
|
|
675 |
* Draws relation links |
|
|
676 |
* |
|
|
677 |
* @access private |
|
|
678 |
* @see PMA_RT |
|
|
679 |
*/ |
|
|
680 |
class PMA_RT_Relation { |
|
|
681 |
/** |
|
|
682 |
* Defines private properties |
|
|
683 |
*/ |
|
|
684 |
var $x_src, $y_src; |
|
|
685 |
var $src_dir ; |
|
|
686 |
var $dest_dir; |
|
|
687 |
var $x_dest, $y_dest; |
|
|
688 |
var $w_tick = 5; |
|
|
689 |
|
|
|
690 |
/** |
|
|
691 |
* Gets arrows coordinates |
|
|
692 |
* |
|
|
693 |
* @param string $ The current table name |
|
|
694 |
* @param string $ The relation column name |
|
|
695 |
* @return array Arrows coordinates |
|
|
696 |
* @access private |
|
|
697 |
*/ |
|
|
698 |
function PMA_RT_Relation_getXy($table, $column) |
|
|
699 |
{ |
|
|
700 |
$pos = array_search($column, $table->fields); |
|
|
701 |
// x_left, x_right, y |
|
|
702 |
return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell); |
|
|
703 |
} // end of the "PMA_RT_Relation_getXy()" method |
|
|
704 |
/** |
|
|
705 |
* Do draws relation links |
|
|
706 |
* |
|
|
707 |
* @param boolean $ Whether to use one color per relation or not |
|
|
708 |
* @param integer $ The id of the link to draw |
|
|
709 |
* @global object The current PDF document |
|
|
710 |
* @access private |
|
|
711 |
* @see PMA_PDF |
|
|
712 |
*/ |
|
|
713 |
function PMA_RT_Relation_draw($change_color, $i) |
|
|
714 |
{ |
|
|
715 |
global $pdf; |
|
|
716 |
|
|
|
717 |
if ($change_color) { |
|
|
718 |
$d = $i % 6; |
|
|
719 |
$j = ($i - $d) / 6; |
|
|
720 |
$j = $j % 4; |
|
|
721 |
$j++; |
|
|
722 |
$case = array( |
|
|
723 |
array(1, 0, 0), |
|
|
724 |
array(0, 1, 0), |
|
|
725 |
array(0, 0, 1), |
|
|
726 |
array(1, 1, 0), |
|
|
727 |
array(1, 0, 1), |
|
|
728 |
array(0, 1, 1) |
|
|
729 |
); |
|
|
730 |
list ($a, $b, $c) = $case[$d]; |
|
|
731 |
$e = (1 - ($j - 1) / 6); |
|
|
732 |
$pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); |
|
|
733 |
} else { |
|
|
734 |
$pdf->SetDrawColor(0); |
|
|
735 |
} // end if... else... |
|
|
736 |
$pdf->PMA_PDF_setLineWidthScale(0.2); |
|
|
737 |
$pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src); |
|
|
738 |
$pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest); |
|
|
739 |
$pdf->PMA_PDF_setLineWidthScale(0.1); |
|
|
740 |
$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); |
|
|
741 |
// arrow |
|
|
742 |
$root2 = 2 * sqrt(2); |
|
|
743 |
$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); |
|
|
744 |
$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); |
|
|
745 |
|
|
|
746 |
$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); |
|
|
747 |
$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); |
|
|
748 |
$pdf->SetDrawColor(0); |
|
|
749 |
} // end of the "PMA_RT_Relation_draw()" method |
|
|
750 |
/** |
|
|
751 |
* The "PMA_RT_Relation" constructor |
|
|
752 |
* |
|
|
753 |
* @param string $ The master table name |
|
|
754 |
* @param string $ The relation field in the master table |
|
|
755 |
* @param string $ The foreign table name |
|
|
756 |
* @param string $ The relation field in the foreign table |
|
|
757 |
* @access private |
|
|
758 |
* @see PMA_RT_Relation::PMA_RT_Relation_getXy |
|
|
759 |
*/ |
|
|
760 |
function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field) |
|
|
761 |
{ |
|
|
762 |
$src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field); |
|
|
763 |
$dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field); |
|
|
764 |
$src_left = $src_pos[0] - $this->w_tick; |
|
|
765 |
$src_right = $src_pos[1] + $this->w_tick; |
|
|
766 |
$dest_left = $dest_pos[0] - $this->w_tick; |
|
|
767 |
$dest_right = $dest_pos[1] + $this->w_tick; |
|
|
768 |
|
|
|
769 |
$d1 = abs($src_left - $dest_left); |
|
|
770 |
$d2 = abs($src_right - $dest_left); |
|
|
771 |
$d3 = abs($src_left - $dest_right); |
|
|
772 |
$d4 = abs($src_right - $dest_right); |
|
|
773 |
$d = min($d1, $d2, $d3, $d4); |
|
|
774 |
|
|
|
775 |
if ($d == $d1) { |
|
|
776 |
$this->x_src = $src_pos[0]; |
|
|
777 |
$this->src_dir = -1; |
|
|
778 |
$this->x_dest = $dest_pos[0]; |
|
|
779 |
$this->dest_dir = -1; |
|
|
780 |
} elseif ($d == $d2) { |
|
|
781 |
$this->x_src = $src_pos[1]; |
|
|
782 |
$this->src_dir = 1; |
|
|
783 |
$this->x_dest = $dest_pos[0]; |
|
|
784 |
$this->dest_dir = -1; |
|
|
785 |
} elseif ($d == $d3) { |
|
|
786 |
$this->x_src = $src_pos[0]; |
|
|
787 |
$this->src_dir = -1; |
|
|
788 |
$this->x_dest = $dest_pos[1]; |
|
|
789 |
$this->dest_dir = 1; |
|
|
790 |
} else { |
|
|
791 |
$this->x_src = $src_pos[1]; |
|
|
792 |
$this->src_dir = 1; |
|
|
793 |
$this->x_dest = $dest_pos[1]; |
|
|
794 |
$this->dest_dir = 1; |
|
|
795 |
} |
|
|
796 |
$this->y_src = $src_pos[2]; |
|
|
797 |
$this->y_dest = $dest_pos[2]; |
|
|
798 |
} // end of the "PMA_RT_Relation()" method |
|
|
799 |
} // end of the "PMA_RT_Relation" class |
|
|
800 |
/** |
|
|
801 |
* Draws and send the database schema |
|
|
802 |
* |
|
|
803 |
* @access public |
|
|
804 |
* @see PMA_PDF |
|
|
805 |
*/ |
|
|
806 |
class PMA_RT { |
|
|
807 |
/** |
|
|
808 |
* Defines private properties |
|
|
809 |
*/ |
|
|
810 |
var $tables = array(); |
|
|
811 |
var $relations = array(); |
|
|
812 |
var $ff = PMA_PDF_FONT; |
|
|
813 |
var $x_max = 0; |
|
|
814 |
var $y_max = 0; |
|
|
815 |
var $scale; |
|
|
816 |
var $x_min = 100000; |
|
|
817 |
var $y_min = 100000; |
|
|
818 |
var $t_marg = 10; |
|
|
819 |
var $b_marg = 10; |
|
|
820 |
var $l_marg = 10; |
|
|
821 |
var $r_marg = 10; |
|
|
822 |
var $tablewidth; |
|
|
823 |
var $same_wide = 0; |
|
|
824 |
|
|
|
825 |
/** |
|
|
826 |
* Sets X and Y minimum and maximum for a table cell |
|
|
827 |
* |
|
|
828 |
* @param string $ The table name |
|
|
829 |
* @access private |
|
|
830 |
*/ |
|
|
831 |
function PMA_RT_setMinMax($table) |
|
|
832 |
{ |
|
|
833 |
$this->x_max = max($this->x_max, $table->x + $table->width); |
|
|
834 |
$this->y_max = max($this->y_max, $table->y + $table->height); |
|
|
835 |
$this->x_min = min($this->x_min, $table->x); |
|
|
836 |
$this->y_min = min($this->y_min, $table->y); |
|
|
837 |
} // end of the "PMA_RT_setMinMax()" method |
|
|
838 |
/** |
|
|
839 |
* Defines relation objects |
|
|
840 |
* |
|
|
841 |
* @param string $ The master table name |
|
|
842 |
* @param string $ The relation field in the master table |
|
|
843 |
* @param string $ The foreign table name |
|
|
844 |
* @param string $ The relation field in the foreign table |
|
|
845 |
* @access private |
|
|
846 |
* @see PMA_RT_setMinMax |
|
|
847 |
*/ |
|
|
848 |
function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field) |
|
|
849 |
{ |
|
|
850 |
if (!isset($this->tables[$master_table])) { |
|
|
851 |
$this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth); |
|
|
852 |
$this->PMA_RT_setMinMax($this->tables[$master_table]); |
|
|
853 |
} |
|
|
854 |
if (!isset($this->tables[$foreign_table])) { |
|
|
855 |
$this->tables[$foreign_table] = new PMA_RT_Table($foreign_table, $this->ff, $this->tablewidth); |
|
|
856 |
$this->PMA_RT_setMinMax($this->tables[$foreign_table]); |
|
|
857 |
} |
|
|
858 |
$this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field); |
|
|
859 |
} // end of the "PMA_RT_addRelation()" method |
|
|
860 |
/** |
|
|
861 |
* Draws the grid |
|
|
862 |
* |
|
|
863 |
* @global object the current PMA_PDF instance |
|
|
864 |
* @access private |
|
|
865 |
* @see PMA_PDF |
|
|
866 |
*/ |
|
|
867 |
function PMA_RT_strokeGrid() |
|
|
868 |
{ |
|
|
869 |
global $pdf; |
|
|
870 |
|
|
|
871 |
$pdf->SetMargins(0, 0); |
|
|
872 |
$pdf->SetDrawColor(200, 200, 200); |
|
|
873 |
// Draws horizontal lines |
|
|
874 |
for ($l = 0; $l < 21; $l++) { |
|
|
875 |
$pdf->line(0, $l * 10, $pdf->fh, $l * 10); |
|
|
876 |
// Avoid duplicates |
|
|
877 |
if ($l > 0) { |
|
|
878 |
$pdf->SetXY(0, $l * 10); |
|
|
879 |
$label = (string) sprintf('%.0f', ($l * 10 - $this->t_marg) * $this->scale + $this->y_min); |
|
|
880 |
$pdf->Cell(5, 5, ' ' . $label); |
|
|
881 |
} // end if |
|
|
882 |
} // end for |
|
|
883 |
// Draws vertical lines |
|
|
884 |
for ($j = 0; $j < 30 ;$j++) { |
|
|
885 |
$pdf->line($j * 10, 0, $j * 10, $pdf->fw); |
|
|
886 |
$pdf->SetXY($j * 10, 0); |
|
|
887 |
$label = (string) sprintf('%.0f', ($j * 10 - $this->l_marg) * $this->scale + $this->x_min); |
|
|
888 |
$pdf->Cell(5, 7, $label); |
|
|
889 |
} // end for |
|
|
890 |
} // end of the "PMA_RT_strokeGrid()" method |
|
|
891 |
/** |
|
|
892 |
* Draws relation arrows |
|
|
893 |
* |
|
|
894 |
* @param boolean $ Whether to use one color per relation or not |
|
|
895 |
* @access private |
|
|
896 |
* @see PMA_RT_Relation::PMA_RT_Relation_draw() |
|
|
897 |
*/ |
|
|
898 |
function PMA_RT_drawRelations($change_color) |
|
|
899 |
{ |
|
|
900 |
$i = 0; |
|
|
901 |
foreach ($this->relations AS $relation) { |
|
|
902 |
$relation->PMA_RT_Relation_draw($change_color, $i); |
|
|
903 |
$i++; |
|
|
904 |
} // end while |
|
|
905 |
} // end of the "PMA_RT_drawRelations()" method |
|
|
906 |
/** |
|
|
907 |
* Draws tables |
|
|
908 |
* |
|
|
909 |
* @param boolean $ Whether to display table position or not |
|
|
910 |
* @access private |
|
|
911 |
* @see PMA_RT_Table::PMA_RT_Table_draw() |
|
|
912 |
*/ |
|
|
913 |
function PMA_RT_drawTables($show_info, $draw_color = 0) |
|
|
914 |
{ |
|
|
915 |
foreach ($this->tables AS $table) { |
|
|
916 |
$table->PMA_RT_Table_draw($show_info, $this->ff, $draw_color); |
|
|
917 |
} |
|
|
918 |
} // end of the "PMA_RT_drawTables()" method |
|
|
919 |
/** |
|
|
920 |
* Ouputs the PDF document to a file |
|
|
921 |
* |
|
|
922 |
* @global object The current PDF document |
|
|
923 |
* @global string The current database name |
|
|
924 |
* @global integer The current page number (from the |
|
|
925 |
* $cfg['Servers'][$i]['table_coords'] table) |
|
|
926 |
* @access private |
|
|
927 |
* @see PMA_PDF |
|
|
928 |
*/ |
|
|
929 |
function PMA_RT_showRt() |
|
|
930 |
{ |
|
|
931 |
global $pdf, $db, $pdf_page_number, $cfgRelation; |
|
|
932 |
|
|
|
933 |
$pdf->SetFontSize(14); |
|
|
934 |
$pdf->SetLineWidth(0.2); |
|
|
935 |
$pdf->SetDisplayMode('fullpage'); |
|
|
936 |
// Get the name of this pdfpage to use as filename (Mike Beck) |
|
|
937 |
$_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) |
|
|
938 |
. ' WHERE page_nr = ' . $pdf_page_number; |
|
|
939 |
$_name_rs = PMA_query_as_cu($_name_sql); |
|
|
940 |
if ($_name_rs) { |
|
|
941 |
$_name_row = PMA_DBI_fetch_row($_name_rs); |
|
|
942 |
$filename = $_name_row[0] . '.pdf'; |
|
|
943 |
} |
|
|
944 |
// i don't know if there is a chance for this to happen, but rather be on the safe side: |
|
|
945 |
if (empty($filename)) { |
|
|
946 |
$filename = $pdf_page_number . '.pdf'; |
|
|
947 |
} |
|
|
948 |
// $pdf->Output($db . '_' . $filename, TRUE); |
|
|
949 |
$pdf->Output($db . '_' . $filename, 'I'); // destination: Inline |
|
|
950 |
} // end of the "PMA_RT_showRt()" method |
|
|
951 |
/** |
|
|
952 |
* The "PMA_RT" constructor |
|
|
953 |
* |
|
|
954 |
* @param mixed $ The scaling factor |
|
|
955 |
* @param integer $ The page number to draw (from the |
|
|
956 |
* $cfg['Servers'][$i]['table_coords'] table) |
|
|
957 |
* @param boolean $ Whether to display table position or not |
|
|
958 |
* @param boolean $ Was originally whether to use one color per |
|
|
959 |
* relation or not, now enables/disables color |
|
|
960 |
* everywhere, due to some problems printing with color |
|
|
961 |
* @param boolean $ Whether to draw grids or not |
|
|
962 |
* @param boolean $ Whether all tables should have the same width or not |
|
|
963 |
* @global object The current PDF document |
|
|
964 |
* @global string The current db name |
|
|
965 |
* @global array The relations settings |
|
|
966 |
* @access private |
|
|
967 |
* @see PMA_PDF |
|
|
968 |
*/ |
|
|
969 |
function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4') |
|
|
970 |
{ |
|
|
971 |
global $pdf, $db, $cfgRelation, $with_doc; |
|
|
972 |
|
|
|
973 |
$this->same_wide = $all_tab_same_wide; |
|
|
974 |
// Initializes a new document |
|
|
975 |
$pdf = new PMA_PDF('L', 'mm', $paper); |
|
|
976 |
$pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel); |
|
|
977 |
$pdf->cMargin = 0; |
|
|
978 |
$pdf->Open(); |
|
|
979 |
$pdf->SetTitle($pdf->title); |
|
|
980 |
$pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION); |
|
|
981 |
$pdf->AliasNbPages(); |
|
|
982 |
|
|
|
983 |
if ($GLOBALS['charset'] == 'utf-8') { |
|
|
984 |
// Force FreeSans for utf-8 |
|
|
985 |
$this->ff = 'FreeSans'; |
|
|
986 |
$pdf->AddFont('FreeSans', '', 'FreeSans.php'); |
|
|
987 |
$pdf->AddFont('FreeSans', 'B', 'FreeSansBold.php'); |
|
|
988 |
} elseif ($GLOBALS['charset'] == 'iso-8859-2') { |
|
|
989 |
// fonts added to phpMyAdmin and considered non-standard by fpdf |
|
|
990 |
// (Note: those tahoma fonts are iso-8859-2 based) |
|
|
991 |
$this->ff == 'tahoma'; |
|
|
992 |
$pdf->AddFont('tahoma', '', 'tahoma.php'); |
|
|
993 |
$pdf->AddFont('tahoma', 'B', 'tahomab.php'); |
|
|
994 |
} else { |
|
|
995 |
$this->ff == 'helvetica'; |
|
|
996 |
} |
|
|
997 |
$pdf->SetFont($this->ff, '', 14); |
|
|
998 |
$pdf->SetAutoPageBreak('auto'); |
|
|
999 |
// Gets tables on this page |
|
|
1000 |
$tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) |
|
|
1001 |
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' |
|
|
1002 |
. ' AND pdf_page_number = ' . $which_rel; |
|
|
1003 |
$tab_rs = PMA_query_as_cu($tab_sql, null, PMA_DBI_QUERY_STORE); |
|
|
1004 |
if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) { |
|
|
1005 |
$pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']); |
|
|
1006 |
// die('No tables'); |
|
|
1007 |
} while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) { |
|
|
1008 |
$alltables[] = PMA_sqlAddslashes($curr_table['table_name']); |
|
|
1009 |
// $intable = '\'' . implode('\', \'', $alltables) . '\''; |
|
|
1010 |
} |
|
|
1011 |
// make doc // |
|
|
1012 |
if ($with_doc) { |
|
|
1013 |
$pdf->SetAutoPageBreak('auto', 15); |
|
|
1014 |
$pdf->cMargin = 1; |
|
|
1015 |
PMA_RT_DOC($alltables); |
|
|
1016 |
$pdf->SetAutoPageBreak('auto'); |
|
|
1017 |
$pdf->cMargin = 0; |
|
|
1018 |
} |
|
|
1019 |
|
|
|
1020 |
$pdf->Addpage(); |
|
|
1021 |
|
|
|
1022 |
if ($with_doc) { |
|
|
1023 |
$pdf->SetLink($pdf->PMA_links['RT']['-'], -1); |
|
|
1024 |
$pdf->Bookmark($GLOBALS['strRelationalSchema']); |
|
|
1025 |
$pdf->SetAlias('{00}', $pdf->PageNo()) ; |
|
|
1026 |
$this->t_marg = 18; |
|
|
1027 |
$this->b_marg = 18; |
|
|
1028 |
} |
|
|
1029 |
|
|
|
1030 |
/* snip */ |
|
|
1031 |
|
|
|
1032 |
foreach ($alltables AS $table) { |
|
|
1033 |
if (!isset($this->tables[$table])) { |
|
|
1034 |
$this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth); |
|
|
1035 |
} |
|
|
1036 |
|
|
|
1037 |
if ($this->same_wide) { |
|
|
1038 |
$this->tables[$table]->width = $this->tablewidth; |
|
|
1039 |
} |
|
|
1040 |
$this->PMA_RT_setMinMax($this->tables[$table]); |
|
|
1041 |
} |
|
|
1042 |
// Defines the scale factor |
|
|
1043 |
$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; |
|
|
1044 |
$pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg); |
|
|
1045 |
// Builds and save the PDF document |
|
|
1046 |
$pdf->PMA_PDF_setLineWidthScale(0.1); |
|
|
1047 |
|
|
|
1048 |
if ($show_grid) { |
|
|
1049 |
$pdf->SetFontSize(10); |
|
|
1050 |
$this->PMA_RT_strokeGrid(); |
|
|
1051 |
} |
|
|
1052 |
$pdf->PMA_PDF_setFontSizeScale(14); |
|
|
1053 |
// $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) |
|
|
1054 |
// . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' ' |
|
|
1055 |
// . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' ' |
|
|
1056 |
// . ' AND master_table IN (' . $intable . ')' |
|
|
1057 |
// . ' AND foreign_table IN (' . $intable . ')'; |
|
|
1058 |
// $result = PMA_query_as_cu($sql); |
|
|
1059 |
|
|
|
1060 |
// lem9: |
|
|
1061 |
// previous logic was checking master tables and foreign tables |
|
|
1062 |
// but I think that looping on every table of the pdf page as a master |
|
|
1063 |
// and finding its foreigns is OK (then we can support innodb) |
|
|
1064 |
$seen_a_relation = false; |
|
|
1065 |
foreach ($alltables AS $one_table) { |
|
|
1066 |
$exist_rel = PMA_getForeigners($db, $one_table, '', 'both'); |
|
|
1067 |
if ($exist_rel) { |
|
|
1068 |
$seen_a_relation = true; |
|
|
1069 |
foreach ($exist_rel AS $master_field => $rel) { |
|
|
1070 |
// put the foreign table on the schema only if selected |
|
|
1071 |
// by the user |
|
|
1072 |
// (do not use array_search() because we would have to |
|
|
1073 |
// to do a === FALSE and this is not PHP3 compatible) |
|
|
1074 |
if (in_array($rel['foreign_table'], $alltables)) { |
|
|
1075 |
$this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']); |
|
|
1076 |
} |
|
|
1077 |
} // end while |
|
|
1078 |
} // end if |
|
|
1079 |
} // end while |
|
|
1080 |
// loic1: also show tables without relations |
|
|
1081 |
// $norelations = TRUE; |
|
|
1082 |
// if ($result && PMA_DBI_num_rows($result) > 0) { |
|
|
1083 |
// $norelations = FALSE; |
|
|
1084 |
// while ($row = PMA_DBI_fetch_assoc($result)) { |
|
|
1085 |
// $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']); |
|
|
1086 |
// } |
|
|
1087 |
// } |
|
|
1088 |
// if ($norelations == FALSE) { |
|
|
1089 |
if ($seen_a_relation) { |
|
|
1090 |
$this->PMA_RT_drawRelations($change_color); |
|
|
1091 |
} |
|
|
1092 |
|
|
|
1093 |
$this->PMA_RT_drawTables($show_info, $change_color); |
|
|
1094 |
|
|
|
1095 |
$this->PMA_RT_showRt(); |
|
|
1096 |
} // end of the "PMA_RT()" method |
|
|
1097 |
} // end of the "PMA_RT" class |
|
|
1098 |
|
|
|
1099 |
function PMA_RT_DOC($alltables) |
|
|
1100 |
{ |
|
|
1101 |
global $db, $pdf, $orientation, $paper; |
|
|
1102 |
// TOC |
|
|
1103 |
$pdf->addpage($GLOBALS['orientation']); |
|
|
1104 |
$pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C'); |
|
|
1105 |
$pdf->Ln(15); |
|
|
1106 |
$i = 1; |
|
|
1107 |
foreach ($alltables AS $table) { |
|
|
1108 |
$pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink(); |
|
|
1109 |
$pdf->SetX(10); |
|
|
1110 |
// $pdf->Ln(1); |
|
|
1111 |
$pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']); |
|
|
1112 |
$pdf->SetX(10); |
|
|
1113 |
$pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']); |
|
|
1114 |
// $pdf->Ln(1); |
|
|
1115 |
$result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); |
|
|
1116 |
while ($row = PMA_DBI_fetch_assoc($result)) { |
|
|
1117 |
$pdf->SetX(20); |
|
|
1118 |
$field_name = $row['Field']; |
|
|
1119 |
$pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink(); |
|
|
1120 |
// $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]); |
|
|
1121 |
} |
|
|
1122 |
$lasttable = $table; |
|
|
1123 |
$i++; |
|
|
1124 |
} |
|
|
1125 |
$pdf->PMA_links['RT']['-'] = $pdf->AddLink(); |
|
|
1126 |
$pdf->SetX(10); |
|
|
1127 |
$pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']); |
|
|
1128 |
$pdf->SetX(10); |
|
|
1129 |
$pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']); |
|
|
1130 |
$z = 0; |
|
|
1131 |
foreach ($alltables AS $table) { |
|
|
1132 |
$z++; |
|
|
1133 |
$pdf->addpage($GLOBALS['orientation']); |
|
|
1134 |
$pdf->Bookmark($table); |
|
|
1135 |
$pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ; |
|
|
1136 |
$pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink(); |
|
|
1137 |
$pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1); |
|
|
1138 |
$pdf->SetFont('', 'B', 18); |
|
|
1139 |
$pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']); |
|
|
1140 |
$pdf->SetFont('', '', 8); |
|
|
1141 |
$pdf->ln(); |
|
|
1142 |
|
|
|
1143 |
$cfgRelation = PMA_getRelationsParam(); |
|
|
1144 |
if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) { |
|
|
1145 |
$comments = PMA_getComments($db, $table); |
|
|
1146 |
} |
|
|
1147 |
if ($cfgRelation['mimework']) { |
|
|
1148 |
$mime_map = PMA_getMIME($db, $table, true); |
|
|
1149 |
} |
|
|
1150 |
|
|
|
1151 |
/** |
|
|
1152 |
* Gets table informations |
|
|
1153 |
*/ |
|
|
1154 |
$result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';', null, PMA_DBI_QUERY_STORE); |
|
|
1155 |
$showtable = PMA_DBI_fetch_assoc($result); |
|
|
1156 |
$num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); |
|
|
1157 |
$show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : ''); |
|
|
1158 |
$create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : ''); |
|
|
1159 |
$update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''); |
|
|
1160 |
$check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''); |
|
|
1161 |
|
|
|
1162 |
PMA_DBI_free_result($result); |
|
|
1163 |
unset($result); |
|
|
1164 |
|
|
|
1165 |
/** |
|
|
1166 |
* Gets table keys and retains them |
|
|
1167 |
*/ |
|
|
1168 |
$result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); |
|
|
1169 |
$primary = ''; |
|
|
1170 |
$indexes = array(); |
|
|
1171 |
$lastIndex = ''; |
|
|
1172 |
$indexes_info = array(); |
|
|
1173 |
$indexes_data = array(); |
|
|
1174 |
$pk_array = array(); // will be use to emphasis prim. keys in the table |
|
|
1175 |
// view |
|
|
1176 |
while ($row = PMA_DBI_fetch_assoc($result)) { |
|
|
1177 |
// Backups the list of primary keys |
|
|
1178 |
if ($row['Key_name'] == 'PRIMARY') { |
|
|
1179 |
$primary .= $row['Column_name'] . ', '; |
|
|
1180 |
$pk_array[$row['Column_name']] = 1; |
|
|
1181 |
} |
|
|
1182 |
// Retains keys informations |
|
|
1183 |
if ($row['Key_name'] != $lastIndex) { |
|
|
1184 |
$indexes[] = $row['Key_name']; |
|
|
1185 |
$lastIndex = $row['Key_name']; |
|
|
1186 |
} |
|
|
1187 |
$indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index']; |
|
|
1188 |
$indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique']; |
|
|
1189 |
if (isset($row['Cardinality'])) { |
|
|
1190 |
$indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality']; |
|
|
1191 |
} |
|
|
1192 |
// I don't know what does following column mean.... |
|
|
1193 |
// $indexes_info[$row['Key_name']]['Packed'] = $row['Packed']; |
|
|
1194 |
$indexes_info[$row['Key_name']]['Comment'] = $row['Comment']; |
|
|
1195 |
|
|
|
1196 |
$indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name']; |
|
|
1197 |
if (isset($row['Sub_part'])) { |
|
|
1198 |
$indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part']; |
|
|
1199 |
} |
|
|
1200 |
} // end while |
|
|
1201 |
if ($result) { |
|
|
1202 |
PMA_DBI_free_result($result); |
|
|
1203 |
} |
|
|
1204 |
|
|
|
1205 |
/** |
|
|
1206 |
* Gets fields properties |
|
|
1207 |
*/ |
|
|
1208 |
$result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); |
|
|
1209 |
$fields_cnt = PMA_DBI_num_rows($result); |
|
|
1210 |
// Check if we can use Relations (Mike Beck) |
|
|
1211 |
if (!empty($cfgRelation['relation'])) { |
|
|
1212 |
// Find which tables are related with the current one and write it in |
|
|
1213 |
// an array |
|
|
1214 |
$res_rel = PMA_getForeigners($db, $table); |
|
|
1215 |
|
|
|
1216 |
if (count($res_rel) > 0) { |
|
|
1217 |
$have_rel = true; |
|
|
1218 |
} else { |
|
|
1219 |
$have_rel = false; |
|
|
1220 |
} |
|
|
1221 |
} else { |
|
|
1222 |
$have_rel = false; |
|
|
1223 |
} // end if |
|
|
1224 |
/** |
|
|
1225 |
* Displays the comments of the table if MySQL >= 3.23 |
|
|
1226 |
*/ |
|
|
1227 |
|
|
|
1228 |
$break = false; |
|
|
1229 |
if (!empty($show_comment)) { |
|
|
1230 |
$pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1); |
|
|
1231 |
$break = true; |
|
|
1232 |
} |
|
|
1233 |
|
|
|
1234 |
if (!empty($create_time)) { |
|
|
1235 |
$pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1); |
|
|
1236 |
$break = true; |
|
|
1237 |
} |
|
|
1238 |
|
|
|
1239 |
if (!empty($update_time)) { |
|
|
1240 |
$pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1); |
|
|
1241 |
$break = true; |
|
|
1242 |
} |
|
|
1243 |
|
|
|
1244 |
if (!empty($check_time)) { |
|
|
1245 |
$pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1); |
|
|
1246 |
$break = true; |
|
|
1247 |
} |
|
|
1248 |
|
|
|
1249 |
if ($break == true) { |
|
|
1250 |
$pdf->Cell(0, 3, '', 0, 1); |
|
|
1251 |
$pdf->Ln(); |
|
|
1252 |
} |
|
|
1253 |
|
|
|
1254 |
$i = 0; |
|
|
1255 |
$pdf->SetFont('', 'B'); |
|
|
1256 |
if (isset($orientation) && $orientation == 'L') { |
|
|
1257 |
$pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C'); |
|
|
1258 |
$pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C'); |
|
|
1259 |
$pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C'); |
|
|
1260 |
$pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C'); |
|
|
1261 |
$pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C'); |
|
|
1262 |
$pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C'); |
|
|
1263 |
$pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C'); |
|
|
1264 |
|
|
|
1265 |
if ($paper == 'A4') { |
|
|
1266 |
$comments_width = 67; |
|
|
1267 |
} else { |
|
|
1268 |
// this is really intended for 'letter' |
|
|
1269 |
// TODO: find optimal width for all formats |
|
|
1270 |
$comments_width = 50; |
|
|
1271 |
} |
|
|
1272 |
$pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C'); |
|
|
1273 |
$pdf->Cell(45, 8, 'MIME', 1, 1, 'C'); |
|
|
1274 |
$pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45)); |
|
|
1275 |
} else { |
|
|
1276 |
$pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C'); |
|
|
1277 |
$pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C'); |
|
|
1278 |
$pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C'); |
|
|
1279 |
$pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C'); |
|
|
1280 |
$pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C'); |
|
|
1281 |
$pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C'); |
|
|
1282 |
$pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C'); |
|
|
1283 |
$pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C'); |
|
|
1284 |
$pdf->Cell(30, 8, 'MIME', 1, 1, 'C'); |
|
|
1285 |
$pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30)); |
|
|
1286 |
} |
|
|
1287 |
$pdf->SetFont('', ''); |
|
|
1288 |
|
|
|
1289 |
while ($row = PMA_DBI_fetch_assoc($result)) { |
|
|
1290 |
$bgcolor = ($i % 2) ?$GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; |
|
|
1291 |
$i++; |
|
|
1292 |
|
|
|
1293 |
$type = $row['Type']; |
|
|
1294 |
// reformat mysql query output - staybyte - 9. June 2001 |
|
|
1295 |
// loic1: set or enum types: slashes single quotes inside options |
|
|
1296 |
if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) { |
|
|
1297 |
$tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1); |
|
|
1298 |
$type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; |
|
|
1299 |
$type_nowrap = ''; |
|
|
1300 |
|
|
|
1301 |
$binary = 0; |
|
|
1302 |
$unsigned = 0; |
|
|
1303 |
$zerofill = 0; |
|
|
1304 |
} else { |
|
|
1305 |
$type_nowrap = ' nowrap="nowrap"'; |
|
|
1306 |
$type = preg_replace('@BINARY@i', '', $type); |
|
|
1307 |
$type = preg_replace('@ZEROFILL@i', '', $type); |
|
|
1308 |
$type = preg_replace('@UNSIGNED@i', '', $type); |
|
|
1309 |
if (empty($type)) { |
|
|
1310 |
$type = ' '; |
|
|
1311 |
} |
|
|
1312 |
|
|
|
1313 |
$binary = stristr($row['Type'], 'BINARY'); |
|
|
1314 |
$unsigned = stristr($row['Type'], 'UNSIGNED'); |
|
|
1315 |
$zerofill = stristr($row['Type'], 'ZEROFILL'); |
|
|
1316 |
} |
|
|
1317 |
$strAttribute = ' '; |
|
|
1318 |
if ($binary) { |
|
|
1319 |
$strAttribute = 'BINARY'; |
|
|
1320 |
} |
|
|
1321 |
if ($unsigned) { |
|
|
1322 |
$strAttribute = 'UNSIGNED'; |
|
|
1323 |
} |
|
|
1324 |
if ($zerofill) { |
|
|
1325 |
$strAttribute = 'UNSIGNED ZEROFILL'; |
|
|
1326 |
} |
|
|
1327 |
if (!isset($row['Default'])) { |
|
|
1328 |
if ($row['Null'] != '' && $row['Null'] != 'NO') { |
|
|
1329 |
$row['Default'] = 'NULL'; |
|
|
1330 |
} |
|
|
1331 |
} |
|
|
1332 |
$field_name = $row['Field']; |
|
|
1333 |
// $pdf->Ln(); |
|
|
1334 |
$pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink(); |
|
|
1335 |
$pdf->Bookmark($field_name, 1, -1); |
|
|
1336 |
$pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1); |
|
|
1337 |
$pdf_row = array($field_name, |
|
|
1338 |
$type, |
|
|
1339 |
$strAttribute, |
|
|
1340 |
($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'], |
|
|
1341 |
((isset($row['Default'])) ? $row['Default'] : ''), |
|
|
1342 |
$row['Extra'], |
|
|
1343 |
((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''), |
|
|
1344 |
((isset($comments[$field_name])) ? $comments[$field_name] : ''), |
|
|
1345 |
((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '') |
|
|
1346 |
); |
|
|
1347 |
$links[0] = $pdf->PMA_links['RT'][$table][$field_name]; |
|
|
1348 |
if (isset($res_rel[$field_name]['foreign_table']) AND |
|
|
1349 |
isset($res_rel[$field_name]['foreign_field']) AND |
|
|
1350 |
isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]) |
|
|
1351 |
) |
|
|
1352 |
{ |
|
|
1353 |
$links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]; |
|
|
1354 |
} else { |
|
|
1355 |
unset($links[6]); |
|
|
1356 |
} |
|
|
1357 |
$pdf->Row($pdf_row, $links); |
|
|
1358 |
|
|
|
1359 |
/*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]); |
|
|
1360 |
//echo ' ' . $field_name . ' ' . "\n"; |
|
|
1361 |
} |
|
|
1362 |
$pdf->Cell(20, 8, $type, 1, 0, 'L'); |
|
|
1363 |
$pdf->Cell(20, 8, $strAttribute, 1, 0, 'L'); |
|
|
1364 |
$pdf->Cell(15, 8, , 1, 0, 'L'); |
|
|
1365 |
$pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L'); |
|
|
1366 |
$pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L'); |
|
|
1367 |
if ($have_rel) { |
|
|
1368 |
if (isset($res_rel[$field_name])) { |
|
|
1369 |
$pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L'); |
|
|
1370 |
} |
|
|
1371 |
} |
|
|
1372 |
if ($cfgRelation['commwork']) { |
|
|
1373 |
if (isset($comments[$field_name])) { |
|
|
1374 |
$pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L'); |
|
|
1375 |
} |
|
|
1376 |
} */ |
|
|
1377 |
} // end while |
|
|
1378 |
$pdf->SetFont('', '', 14); |
|
|
1379 |
PMA_DBI_free_result($result); |
|
|
1380 |
} //end each |
|
|
1381 |
} // end function PMA_RT_DOC |
|
|
1382 |
|
|
|
1383 |
/** |
|
|
1384 |
* Main logic |
|
|
1385 |
*/ |
|
|
1386 |
if (!isset($pdf_page_number)) { |
|
|
1387 |
$pdf_page_number = 1; |
|
|
1388 |
} |
|
|
1389 |
|
|
|
1390 |
$show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0; |
|
|
1391 |
$show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0; |
|
|
1392 |
$show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0; |
|
|
1393 |
$all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0; |
|
|
1394 |
$with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0; |
|
|
1395 |
$orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L'; |
|
|
1396 |
$paper = isset($paper) ? $paper : 'A4'; |
|
|
1397 |
PMA_DBI_select_db($db); |
|
|
1398 |
|
|
|
1399 |
$rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper); |
|
|
1400 |
|
|
|
1401 |
?> |