2 /* vim: set expandtab sw=4 ts=4 sts=4: */
9 * Gets some core libraries
11 require_once './libraries/common.inc.php';
12 require_once './libraries/db_common.inc.php';
16 * Settings for relation stuff
18 require_once './libraries/relation.lib.php';
19 $cfgRelation = PMA_getRelationsParam();
21 // This is to avoid "Command out of sync" errors. Before switching this to
22 // a value of 0 (for MYSQLI_USE_RESULT), please check the logic
23 // to free results wherever needed.
24 $query_default_option = PMA_DBI_QUERY_STORE
;
27 * Now in ./libraries/relation.lib.php we check for all tables
28 * that we need, but if we don't find them we are quiet about it
29 * so people can work without.
30 * This page is absolutely useless if you didn't set up your tables
31 * correctly, so it is a good place to see which tables we can and
34 if (!$cfgRelation['relwork']) {
35 echo sprintf($strNotSet, 'relation', 'config.inc.php') . '<br />' . "\n"
36 . '<a href="./Documentation.html#relation" target="documentation">' . $strDocu . '</a>' . "\n";
37 require_once './libraries/footer.inc.php';
40 if (!$cfgRelation['displaywork']) {
41 echo sprintf($strNotSet, 'table_info', 'config.inc.php') . '<br />' . "\n"
42 . '<a href="./Documentation.html#table_info" target="documentation">' . $strDocu . '</a>' . "\n";
43 require_once './libraries/footer.inc.php';
46 if (!isset($cfgRelation['table_coords'])){
47 echo sprintf($strNotSet, 'table_coords', 'config.inc.php') . '<br />' . "\n"
48 . '<a href="./Documentation.html#table_coords" target="documentation">' . $strDocu . '</a>' . "\n";
51 if (!isset($cfgRelation['pdf_pages'])) {
52 echo sprintf($strNotSet, 'pdf_page', 'config.inc.php') . '<br />' . "\n"
53 . '<a href="./Documentation.html#pdf_pages" target="documentation">' . $strDocu . '</a>' . "\n";
57 if ($cfgRelation['pdfwork']) {
58 // Now is the time to work on all changes
62 if ($action_choose=="1") {
63 $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
64 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
65 . ' AND pdf_page_number = ' . $chpage;
66 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
68 $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
69 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
70 . ' AND page_nr = ' . $chpage;
71 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
77 if (!isset($newpage) ||
$newpage == '') {
78 $newpage = $strNoDescription;
80 $ins_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
81 . ' (db_name, page_descr)'
82 . ' VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($newpage) . '\')';
83 PMA_query_as_cu($ins_query, FALSE, $query_default_option);
84 $pdf_page_number = PMA_DBI_insert_id(isset($controllink) ?
$controllink : '');
86 // A u t o m a t i c l a y o u t
87 // ================================
88 if (isset($auto_layout_internal) ||
isset($auto_layout_innodb)) {
89 $all_tables = array();
92 if (isset($auto_layout_innodb)) {
93 // get the tables list
94 $tables = PMA_DBI_get_tables_full($db);
95 // find the InnoDB ones
96 $innodb_tables = array();
97 foreach($tables as $table_name => $table_properties) {
98 if ($table_properties['ENGINE'] == 'InnoDB') {
99 $innodb_tables[] = $table_name;
102 $all_tables = $innodb_tables;
103 // could be improved by finding the tables which have the
104 // most references keys and place them at the beginning
105 // of the array (so that they are all center of schema)
106 unset($tables, $innodb_tables);
107 } // endif auto_layout_innodb
109 if (isset($auto_layout_internal)) {
110 // get the tables that have relations, by descending
112 $master_tables = 'SELECT COUNT(master_table), master_table'
113 . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
114 . ' WHERE master_db = \'' . $db . '\''
115 . ' GROUP BY master_table'
116 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
117 $master_tables_rs = PMA_query_as_cu($master_tables, FALSE, $query_default_option);
118 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
119 // first put all the master tables at beginning
120 // of the list, so they are near the center of
122 while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
123 $all_tables[] = $master_table;
126 // then for each master, add its foreigns into an array
127 // of foreign tables, if not already there
128 // (a foreign might be foreign for more than
129 // one table, and might be a master itself)
131 $foreign_tables = array();
132 foreach ($all_tables AS $master_table) {
133 $foreigners = PMA_getForeigners($db, $master_table);
134 foreach ($foreigners AS $foreigner) {
135 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
136 $foreign_tables[] = $foreigner['foreign_table'];
141 // then merge the arrays
142 foreach ($foreign_tables AS $foreign_table) {
143 if (!in_array($foreign_table, $all_tables)) {
144 $all_tables[] = $foreign_table;
147 } // endif there are master tables
148 } // endif auto_layout_internal
150 if (isset($auto_layout_internal) ||
isset($auto_layout_innodb)) {
151 // now generate the coordinates for the schema,
152 // in a clockwise spiral
158 $direction = "right";
159 foreach ($all_tables AS $current_table) {
161 // save current table's coordinates
162 $insert_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
163 . '(db_name, table_name, pdf_page_number, x, y) '
164 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pdf_page_number . ',' . $pos_x . ',' . $pos_y . ')';
165 PMA_query_as_cu($insert_query, FALSE, $query_default_option);
167 // compute for the next table
168 switch ($direction) {
172 $delta *= $delta_mult;
177 $delta *= $delta_mult;
182 $delta *= $delta_mult;
186 $direction = "right";
187 $delta *= $delta_mult;
191 } // end if some auto-layout to do
193 $chpage = $pdf_page_number;
198 for ($i = 0; $i < $c_table_rows; $i++
) {
199 $arrvalue = 'c_table_' . $i;
200 $arrvalue = $
$arrvalue;
201 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
204 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
207 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
208 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
209 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
210 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
211 . ' AND pdf_page_number = ' . $chpage;
212 $test_rs = PMA_query_as_cu($test_query, FALSE, $query_default_option);
213 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
214 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
215 $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
216 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
217 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
218 . ' AND pdf_page_number = ' . $chpage;
220 $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
221 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
222 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
223 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
224 . ' AND pdf_page_number = ' . $chpage;
227 $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
228 . '(db_name, table_name, pdf_page_number, x, y) '
229 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\',' . $chpage . ',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
231 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
236 foreach ($delrow AS $current_row) {
237 $d_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
238 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
239 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
240 . ' AND pdf_page_number = ' . $chpage;
241 PMA_query_as_cu($d_query, FALSE, $query_default_option);
245 } // end if (isset($do))
247 // We will need an array of all tables in this db
248 $selectboxall = array('--');
249 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
250 while ($val = @PMA_DBI_fetch_row
($alltab_rs)) {
251 $selectboxall[] = $val[0];
254 // Now first show some possibility to choose a page for the pdf
255 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
256 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
257 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
259 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
261 <form method
="get" action
="pdf_pages.php" name
="selpage">
264 <?php
echo $strChoosePage . "\n"; ?
>
266 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
267 <input type
="hidden" name
="do" value
="choosepage" />
268 <select name
="chpage" onchange
="this.form.submit()">
270 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
272 . '<option value="' . $curr_page['page_nr'] . '"';
273 if (isset($chpage) && $chpage == $curr_page['page_nr']) {
274 echo ' selected="selected"';
276 echo '>' . $curr_page['page_nr'] . ': ' . $curr_page['page_descr'] . '</option>';
281 <input type
="radio" name
="action_choose" value
="0" id
="radio_choose0" checked
="checked" style
="vertical-align: middle" /><label
for="radio_choose0">
282 <?php
echo $strEdit; ?
> </label
>
283 <input type
="radio" name
="action_choose" value
="1" id
="radio_choose1" style
="vertical-align: middle" /><label
for="radio_choose1">
284 <?php
echo $strDelete; ?
> </label
>
285 <input type
="submit" value
="<?php echo $strGo; ?>" /><br
/>
292 // Possibility to create a new page:
294 <form method
="post" action
="pdf_pages.php" name
="crpage">
297 <?php
echo $strCreatePage . "\n"; ?
>
299 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
300 <input type
="hidden" name
="do" value
="createpage" />
301 <input type
="text" name
="newpage" size
="20" maxlength
="50" />
302 <input type
="checkbox" name
="auto_layout_internal" />
303 <?php
echo '(' . $strAutomaticLayout . ' / ' . $strInternalRelations . ')' . "\n"; ?
>
304 <input type
="checkbox" name
="auto_layout_innodb" />
305 <?php
echo '(' . $strAutomaticLayout . ' / InnoDB)' . "\n"; ?
>
306 <input type
="submit" value
="<?php echo $strGo; ?>" />
310 // Now if we already have chosen a page number then we should show the
312 if (isset($chpage) && $chpage > 0) {
317 <h2
><?php
echo $strSelectTables ;?
></h2
>
320 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
321 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
322 . ' AND pdf_page_number = ' . $chpage;
323 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
324 $array_sh_page = array();
326 $reset_draginit = '';
328 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
329 $array_sh_page[] = $temp_sh_page;
332 // garvin: Display WYSIWYG-PDF parts?
333 if ($cfg['WYSIWYG-PDF']) {
334 if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
335 $with_field_names = TRUE;
338 <script type
="text/javascript" src
="./js/dom-drag.js"></script
>
339 <form method
="post" action
="pdf_pages.php" name
="dragdrop">
340 <input type
="button" name
="dragdrop" value
="<?php echo $strToggleScratchboard; ?>" onclick
="ToggleDragDrop('pdflayout');" />
341 <input type
="button" name
="dragdropreset" value
="<?php echo $strReset; ?>" onclick
="resetDrag();" />
343 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
345 foreach ($array_sh_page AS $key => $temp_sh_page) {
346 $drag_x = $temp_sh_page['x'];
347 $drag_y = $temp_sh_page['y'];
349 $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
350 $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";
351 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
352 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
353 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
354 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
355 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
356 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
358 $local_query = 'SHOW FIELDS FROM '
359 . PMA_backquote($temp_sh_page['table_name'])
360 . ' FROM ' . PMA_backquote($db);
361 $fields_rs = PMA_DBI_query($local_query);
363 $fields_cnt = PMA_DBI_num_rows($fields_rs);
365 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
366 if (isset($with_field_names)) {
367 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
368 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
371 echo '</div>' . "\n";
372 PMA_DBI_free_result($fields_rs);
379 <script type
="text/javascript">
383 myid
= getElement('pdflayout');
384 <?php
echo $draginit; ?
>
387 function resetDrag() {
388 <?php
echo $reset_draginit; ?
>
393 } // end if WYSIWYG-PDF
396 <form method
="post" action
="pdf_pages.php" name
="edcoord">
397 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
398 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
399 <input type
="hidden" name
="do" value
="edcoord" />
402 <th
><?php
echo $strTable; ?
></th
>
403 <th
><?php
echo $strDelete; ?
></th
>
408 if (isset($ctable)) {
415 foreach ($array_sh_page AS $dummy_sh_page => $sh_page) {
416 $_mtab = $sh_page['table_name'];
417 $tabExist[$_mtab] = FALSE;
418 echo "\n" . ' <tr class="';
425 $odd_row != $odd_row;
427 . "\n" . ' <select name="c_table_' . $i . '[name]">';
428 foreach ($selectboxall AS $key => $value) {
429 echo "\n" . ' <option value="' . $value . '"';
430 if ($value == $sh_page['table_name']) {
431 echo ' selected="selected"';
432 $tabExist[$_mtab] = TRUE;
434 echo '>' . $value . '</option>';
436 echo "\n" . ' </select>'
439 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
440 echo "\n" . ' </td>';
442 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'x\', this.value)"' : '') . ' name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
443 echo "\n" . ' </td>';
445 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'y\', this.value)"' : '') . ' name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
446 echo "\n" . ' </td>';
447 echo "\n" . ' </tr>';
450 // Do one more empty row
451 echo "\n" . ' <tr class="';
457 $odd_row != $odd_row;
460 . "\n" . ' <select name="c_table_' . $i . '[name]">';
461 foreach ($selectboxall AS $key => $value) {
462 echo "\n" . ' <option value="' . $value . '">' . $value . '</option>';
464 echo "\n" . ' </select>'
467 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
468 echo "\n" . ' </td>';
470 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
471 echo "\n" . ' </td>';
473 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
474 echo "\n" . ' </td>';
475 echo "\n" . ' </tr>';
476 echo "\n" . ' </table>' . "\n";
478 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
479 echo ($cfg['WYSIWYG-PDF'] ?
"\n" . ' <input type="hidden" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />' : '');
480 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . $strColumnNames . '<br />';
481 echo "\n" . ' <input type="submit" value="' . $strSave . '" />';
482 echo "\n" . '</form>' . "\n\n";
485 // Check if there are tables that need to be deleted,
486 // if there are, ask the user for allowance
490 if (!empty($tabExist) && is_array($tabExist)) {
491 foreach ($tabExist AS $key => $value) {
493 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '" />' . "\n";
494 $_strname .= '<li>' . $key . '</li>' . "\n";
499 echo '<form action="pdf_pages.php" method="post">' . "\n"
500 . PMA_generate_common_hidden_inputs($db, $table)
501 . '<input type="hidden" name="do" value="deleteCrap" />' . "\n"
502 . '<input type="hidden" name="chpage" value="' . $chpage . '" />' . "\n"
508 . '<input type="submit" value="' . $strGo . '" />' . "\n"
512 // ------------------------------------
513 // d i s p l a y p d f s c h e m a
514 // ------------------------------------
518 ||
($do == 'choosepage' && isset($chpage))
519 ||
($do == 'createpage' && isset($chpage)))) {
521 <form method
="post" action
="pdf_schema.php" name
="pdfoptions">
522 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
523 <input type
="hidden" name
="pdf_page_number" value
="<?php echo $chpage; ?>" />
525 <?php
echo '<br /><b>' . $strDisplayPDF . '</b>'; ?
>: 
;<br
/>
526 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" /><label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
527 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" /><label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
528 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" /><label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
529 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" /><label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
><br
/>
530 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" /><label
for="with_doc"><?php
echo $strDataDict; ?
></label
>
532 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
533 <select id
="orientation_opt" name
="orientation" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
534 <option value
="L"><?php
echo $strLandscape;?
></option
>
535 <option value
="P"><?php
echo $strPortrait;?
></option
>
538 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
539 <select id
="paper_opt" name
="paper" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
541 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
542 echo '<option value="' . $val . '"';
543 if ($val == $cfg['PDFDefaultPageSize']) {
544 echo ' selected="selected"';
546 echo ' >' . $val . '</option>' . "\n";
550  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
553 if ((isset($showwysiwyg) && $showwysiwyg == '1')) {
555 <script type
="text/javascript">
557 ToggleDragDrop('pdflayout');
563 } // end if ($cfgRelation['pdfwork'])
567 * Displays the footer
570 require_once './libraries/footer.inc.php';