3 // vim: expandtab sw=4 ts=4 sts=4:
6 * Gets some core libraries
8 require_once('./libraries/grab_globals.lib.php');
9 require_once('./libraries/common.lib.php');
10 require_once('./db_details_common.php');
14 * Settings for relation stuff
16 require_once('./libraries/relation.lib.php');
17 $cfgRelation = PMA_getRelationsParam();
19 // This is to avoid "Command out of sync" errors. Before switching this to
20 // a value of 0 (for MYSQLI_USE_RESULT), please check the logic
21 // to free results wherever needed.
22 $query_default_option = PMA_DBI_QUERY_STORE
;
25 * Now in ./libraries/relation.lib.php we check for all tables
26 * that we need, but if we don't find them we are quiet about it
27 * so people can work without.
28 * This page is absolutely useless if you didn't set up your tables
29 * correctly, so it is a good place to see which tables we can and
32 if (!$cfgRelation['relwork']) {
33 echo sprintf($strNotSet, 'relation', 'config.inc.php') . '<br />' . "\n"
34 . '<a href="./Documentation.html#relation" target="documentation">' . $strDocu . '</a>' . "\n";
35 require_once('./footer.inc.php');
38 if (!$cfgRelation['displaywork']) {
39 echo sprintf($strNotSet, 'table_info', 'config.inc.php') . '<br />' . "\n"
40 . '<a href="./Documentation.html#table_info" target="documentation">' . $strDocu . '</a>' . "\n";
41 require_once('./footer.inc.php');
44 if (!isset($cfgRelation['table_coords'])){
45 echo sprintf($strNotSet, 'table_coords', 'config.inc.php') . '<br />' . "\n"
46 . '<a href="./Documentation.html#table_coords" target="documentation">' . $strDocu . '</a>' . "\n";
49 if (!isset($cfgRelation['pdf_pages'])) {
50 echo sprintf($strNotSet, 'pdf_page', 'config.inc.php') . '<br />' . "\n"
51 . '<a href="./Documentation.html#pdf_pages" target="documentation">' . $strDocu . '</a>' . "\n";
55 if ($cfgRelation['pdfwork']) {
56 // Now is the time to work on all changes
60 if ($action_choose=="1") {
61 $ch_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
62 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
63 . ' AND pdf_page_number = ' . $chpage;
64 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
66 $ch_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
67 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
68 . ' AND page_nr = ' . $chpage;
69 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
75 if (!isset($newpage) ||
$newpage == '') {
76 $newpage = $strNoDescription;
78 $ins_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['pdf_pages'])
79 . ' (db_name, page_descr)'
80 . ' VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($newpage) . '\')';
81 PMA_query_as_cu($ins_query, FALSE, $query_default_option);
83 // A u t o m a t i c l a y o u t
85 // TODO: support InnoDB
87 if (isset($autolayout)) {
88 // save the page number
89 $pdf_page_number = PMA_DBI_insert_id((isset($dbh)?
$dbh:''));
91 // get the tables that have relations, by descending
93 $master_tables = 'SELECT COUNT(master_table), master_table'
94 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
95 . ' WHERE master_db = \'' . $db . '\''
96 . ' GROUP BY master_table'
97 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
98 $master_tables_rs = PMA_query_as_cu($master_tables, FALSE, $query_default_option);
99 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
100 // first put all the master tables at beginning
101 // of the list, so they are near the center of
103 while (list(,$master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
104 $all_tables[] = $master_table;
107 // then for each master, add its foreigns into an array
108 // of foreign tables, if not already there
109 // (a foreign might be foreign for more than
110 // one table, and might be a master itself)
112 $foreign_tables = array();
113 foreach ($all_tables AS $master_table) {
114 $foreigners = PMA_getForeigners($db, $master_table);
115 foreach ($foreigners AS $foreigner) {
116 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
117 $foreign_tables[] = $foreigner['foreign_table'];
122 // then merge the arrays
123 foreach ($foreign_tables AS $foreign_table) {
124 if (!in_array($foreign_table, $all_tables)) {
125 $all_tables[] = $foreign_table;
129 // now generate the coordinates for the schema,
130 // in a clockwise spiral
136 $direction = "right";
137 foreach ($all_tables AS $current_table) {
139 // save current table's coordinates
140 $insert_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_coords']) . ' '
141 . '(db_name, table_name, pdf_page_number, x, y) '
142 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pdf_page_number . ',' . $pos_x . ',' . $pos_y . ')';
143 PMA_query_as_cu($insert_query, FALSE, $query_default_option);
145 // compute for the next table
146 switch ($direction) {
150 $delta *= $delta_mult;
155 $delta *= $delta_mult;
160 $delta *= $delta_mult;
164 $direction = "right";
165 $delta *= $delta_mult;
169 } // end if there are master tables
171 $chpage = $pdf_page_number;
172 } // end if isset autolayout
177 for ($i = 0; $i < $c_table_rows; $i++
) {
178 $arrvalue = 'c_table_' . $i;
179 $arrvalue = $
$arrvalue;
180 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
183 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
186 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
187 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords'])
188 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
189 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
190 . ' AND pdf_page_number = ' . $chpage;
191 $test_rs = PMA_query_as_cu($test_query, FALSE, $query_default_option);
192 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
193 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
194 $ch_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
195 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
196 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
197 . ' AND pdf_page_number = ' . $chpage;
199 $ch_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords']) . ' '
200 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
201 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
202 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
203 . ' AND pdf_page_number = ' . $chpage;
206 $ch_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_coords']) . ' '
207 . '(db_name, table_name, pdf_page_number, x, y) '
208 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\',' . $chpage . ',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
210 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
215 foreach ($delrow AS $current_row) {
216 $d_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
217 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
218 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
219 . ' AND pdf_page_number = ' . $chpage;
220 PMA_query_as_cu($d_query, FALSE, $query_default_option);
224 } // end if (isset($do))
226 // We will need an array of all tables in this db
227 $selectboxall = array('--');
228 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE
);
229 while ($val = @PMA_DBI_fetch_row
($alltab_rs)) {
230 $selectboxall[] = $val[0];
233 // Now first show some possibility to choose a page for the pdf
234 $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
235 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
236 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
238 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
240 <form method
="get" action
="pdf_pages.php" name
="selpage">
241 <?php
echo $strChoosePage . "\n"; ?
>
242 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
243 <input type
="hidden" name
="do" value
="choosepage" />
244 <select name
="chpage" onchange
="this.form.submit()">
246 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
248 . '<option value="' . $curr_page['page_nr'] . '"';
249 if (isset($chpage) && $chpage == $curr_page['page_nr']) {
250 echo ' selected="selected"';
252 echo '>' . $curr_page['page_nr'] . ': ' . $curr_page['page_descr'] . '</option>';
257 <input type
="radio" name
="action_choose" value
="0" id
="radio_choose0" checked
="checked" style
="vertical-align: middle" /><label
for="radio_choose0">
258 <?php
echo $strEdit; ?
> </label
>
259 <input type
="radio" name
="action_choose" value
="1" id
="radio_choose1" style
="vertical-align: middle" /><label
for="radio_choose1">
260 <?php
echo $strDelete; ?
> </label
>
262 <input type
="submit" value
="<?php echo $strGo; ?>" />
268 // Possibility to create a new page:
270 <form method
="post" action
="pdf_pages.php" name
="crpage">
271 <?php
echo $strCreatePage . "\n"; ?
>
272 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
273 <input type
="hidden" name
="do" value
="createpage" />
274 <input type
="text" name
="newpage" size
="20" maxlength
="50" />
275 <input type
="checkbox" name
="autolayout" />
276 <?php
echo '(' . $strAutomaticLayout . ')' . "\n"; ?
>
277 <input type
="submit" value
="<?php echo $strGo; ?>" />
280 // Now if we already have chosen a page number then we should show the
282 if (isset($chpage) && $chpage > 0) {
287 <h2
><?php
echo $strSelectTables ;?
></h2
>
290 $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords'])
291 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
292 . ' AND pdf_page_number = ' . $chpage;
293 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
294 $array_sh_page = array();
296 $reset_draginit = '';
298 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
299 $array_sh_page[] = $temp_sh_page;
302 // garvin: Display WYSIWYG-PDF parts?
303 if ($cfg['WYSIWYG-PDF']) {
304 if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
305 $with_field_names = TRUE;
308 <script type
="text/javascript" src
="./libraries/dom-drag.js"></script
>
309 <form method
="post" action
="pdf_pages.php" name
="dragdrop">
310 <input type
="button" name
="dragdrop" value
="<?php echo $strToggleScratchboard; ?>" onclick
="ToggleDragDrop('pdflayout');" />
311 <input type
="button" name
="dragdropreset" value
="<?php echo $strReset; ?>" onclick
="resetDrag();" />
313 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
315 foreach ($array_sh_page AS $key => $temp_sh_page) {
316 $drag_x = $temp_sh_page['x'];
317 $drag_y = $temp_sh_page['y'];
319 $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
320 $draginit .= ' getElement("table_' . $i . '").onDrag = function (x, y) { document.edcoord.elements["c_table_' . $i . '[x]"].value = parseInt(x); document.edcoord.elements["c_table_' . $i . '[y]"].value = parseInt(y) }' . "\n";
321 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
322 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
323 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
324 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
325 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
326 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
328 $local_query = 'SHOW FIELDS FROM '
329 . PMA_backquote($temp_sh_page['table_name'] )
330 . ' FROM ' . PMA_backquote($db);
331 $fields_rs = PMA_DBI_query($local_query);
333 $fields_cnt = PMA_DBI_num_rows($fields_rs);
335 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
336 if (isset($with_field_names)) {
337 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
338 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
341 echo '</div>' . "\n";
342 PMA_DBI_free_result($fields_rs);
349 <script type
="text/javascript">
353 myid
= getElement('pdflayout');
354 <?php
echo $draginit; ?
>
357 function resetDrag() {
358 <?php
echo $reset_draginit; ?
>
363 } // end if WYSIWYG-PDF
366 <form method
="post" action
="pdf_pages.php" name
="edcoord">
367 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
368 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
369 <input type
="hidden" name
="do" value
="edcoord" />
372 <th
><?php
echo $strTable; ?
></th
>
373 <th
><?php
echo $strDelete; ?
></th
>
378 if (isset($ctable)) {
384 foreach ($array_sh_page AS $dummy_sh_page => $sh_page) {
385 $_mtab = $sh_page['table_name'];
386 $tabExist[$_mtab] = FALSE;
389 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
391 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
395 . "\n" . ' <select name="c_table_' . $i . '[name]">';
396 foreach ($selectboxall AS $key => $value) {
397 echo "\n" . ' <option value="' . $value . '"';
398 if ($value == $sh_page['table_name']) {
399 echo ' selected="selected"';
400 $tabExist[$_mtab] = TRUE;
402 echo '>' . $value . '</option>';
404 echo "\n" . ' </select>'
407 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
408 echo "\n" . ' </td>';
410 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'x\', this.value)"' : '') . ' name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
411 echo "\n" . ' </td>';
413 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'y\', this.value)"' : '') . ' name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
414 echo "\n" . ' </td>';
415 echo "\n" . ' </tr>';
418 // Do one more empty row
421 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
423 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
427 . "\n" . ' <select name="c_table_' . $i . '[name]">';
428 foreach ($selectboxall AS $key => $value) {
429 echo "\n" . ' <option value="' . $value . '">' . $value . '</option>';
431 echo "\n" . ' </select>'
434 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
435 echo "\n" . ' </td>';
437 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
438 echo "\n" . ' </td>';
440 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
441 echo "\n" . ' </td>';
442 echo "\n" . ' </tr>';
443 echo "\n" . ' </table>' . "\n";
445 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
446 echo ($cfg['WYSIWYG-PDF'] ?
"\n" . ' <input type="hidden" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />' : '');
447 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . $strColumnNames . '<br />';
448 echo "\n" . ' <input type="submit" value="' . $strSave . '" />';
449 echo "\n" . '</form>' . "\n\n";
452 // Check if there are tables that need to be deleted,
453 // if there are, ask the user for allowance
457 if (!empty($tabExist) && is_array($tabExist)) {
458 foreach ($tabExist AS $key => $value) {
460 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '" />' . "\n";
461 $_strname .= '<li>' . $key . '</li>' . "\n";
466 echo '<form action="pdf_pages.php" method="post">' . "\n"
467 . PMA_generate_common_hidden_inputs($db, $table)
468 . '<input type="hidden" name="do" value="deleteCrap" />' . "\n"
469 . '<input type="hidden" name="chpage" value="' . $chpage . '" />' . "\n"
475 . '<input type="submit" value="' . $strGo . '" />' . "\n"
479 // ------------------------------------
480 // d i s p l a y p d f s c h e m a
481 // ------------------------------------
485 ||
($do == 'choosepage' && isset($chpage))
486 ||
($do == 'createpage' && isset($chpage)))) {
488 <form method
="post" action
="pdf_schema.php" name
="pdfoptions">
489 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
490 <input type
="hidden" name
="pdf_page_number" value
="<?php echo $chpage; ?>" />
492 <?php
echo '<br /><b>' . $strDisplayPDF . '</b>'; ?
>: 
;<br
/>
493 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" /><label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
494 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" /><label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
495 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" /><label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
496 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" /><label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
><br
/>
497 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" /><label
for="with_doc"><?php
echo $strDataDict; ?
></label
>
499 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
500 <select id
="orientation_opt" name
="orientation" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
501 <option value
="L"><?php
echo $strLandscape;?
></option
>
502 <option value
="P"><?php
echo $strPortrait;?
></option
>
505 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
506 <select id
="paper_opt" name
="paper" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
508 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
509 echo '<option value="' . $val . '"';
510 if ($val == $cfg['PDFDefaultPageSize']) {
511 echo ' selected="selected"';
513 echo ' >' . $val . '</option>' . "\n";
517  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
520 if ((isset($showwysiwyg) && $showwysiwyg == '1')) {
522 <script type
="text/javascript">
524 ToggleDragDrop('pdflayout');
530 } // end if ($cfgRelation['pdfwork'])
534 * Displays the footer
537 require_once('./footer.inc.php');