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>';
285 PMA_generate_html_radio('action_choose', $choices, '0', false);
288 <input type
="submit" value
="<?php echo $strGo; ?>" /><br
/>
295 // Possibility to create a new page:
297 <form method
="post" action
="pdf_pages.php" name
="crpage">
300 <?php
echo $strCreatePage . "\n"; ?
>
302 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
303 <input type
="hidden" name
="do" value
="createpage" />
304 <input type
="text" name
="newpage" size
="20" maxlength
="50" />
305 <input type
="checkbox" name
="auto_layout_internal" />
306 <?php
echo '(' . $strAutomaticLayout . ' / ' . $strInternalRelations . ')' . "\n"; ?
>
307 <input type
="checkbox" name
="auto_layout_innodb" />
308 <?php
echo '(' . $strAutomaticLayout . ' / InnoDB)' . "\n"; ?
>
309 <input type
="submit" value
="<?php echo $strGo; ?>" />
313 // Now if we already have chosen a page number then we should show the
315 if (isset($chpage) && $chpage > 0) {
320 <h2
><?php
echo $strSelectTables ;?
></h2
>
323 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
324 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
325 . ' AND pdf_page_number = ' . $chpage;
326 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
327 $array_sh_page = array();
329 $reset_draginit = '';
331 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
332 $array_sh_page[] = $temp_sh_page;
335 // garvin: Display WYSIWYG-PDF parts?
336 if ($cfg['WYSIWYG-PDF']) {
337 if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
338 $with_field_names = TRUE;
341 <script type
="text/javascript" src
="./js/dom-drag.js"></script
>
342 <form method
="post" action
="pdf_pages.php" name
="dragdrop">
343 <input type
="button" name
="dragdrop" value
="<?php echo $strToggleScratchboard; ?>" onclick
="ToggleDragDrop('pdflayout');" />
344 <input type
="button" name
="dragdropreset" value
="<?php echo $strReset; ?>" onclick
="resetDrag();" />
346 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
348 foreach ($array_sh_page AS $key => $temp_sh_page) {
349 $drag_x = $temp_sh_page['x'];
350 $drag_y = $temp_sh_page['y'];
352 $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
353 $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";
354 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
355 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
356 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
357 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
358 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
359 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
361 $local_query = 'SHOW FIELDS FROM '
362 . PMA_backquote($temp_sh_page['table_name'])
363 . ' FROM ' . PMA_backquote($db);
364 $fields_rs = PMA_DBI_query($local_query);
366 $fields_cnt = PMA_DBI_num_rows($fields_rs);
368 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
369 if (isset($with_field_names)) {
370 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
371 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
374 echo '</div>' . "\n";
375 PMA_DBI_free_result($fields_rs);
382 <script type
="text/javascript">
386 myid
= getElement('pdflayout');
387 <?php
echo $draginit; ?
>
390 function resetDrag() {
391 <?php
echo $reset_draginit; ?
>
396 } // end if WYSIWYG-PDF
399 <form method
="post" action
="pdf_pages.php" name
="edcoord">
400 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
401 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
402 <input type
="hidden" name
="do" value
="edcoord" />
405 <th
><?php
echo $strTable; ?
></th
>
406 <th
><?php
echo $strDelete; ?
></th
>
411 if (isset($ctable)) {
418 foreach ($array_sh_page AS $dummy_sh_page => $sh_page) {
419 $_mtab = $sh_page['table_name'];
420 $tabExist[$_mtab] = FALSE;
421 echo "\n" . ' <tr class="';
428 $odd_row != $odd_row;
430 . "\n" . ' <select name="c_table_' . $i . '[name]">';
431 foreach ($selectboxall AS $key => $value) {
432 echo "\n" . ' <option value="' . $value . '"';
433 if ($value == $sh_page['table_name']) {
434 echo ' selected="selected"';
435 $tabExist[$_mtab] = TRUE;
437 echo '>' . $value . '</option>';
439 echo "\n" . ' </select>'
442 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
443 echo "\n" . ' </td>';
445 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'x\', this.value)"' : '') . ' name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
446 echo "\n" . ' </td>';
448 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'y\', this.value)"' : '') . ' name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
449 echo "\n" . ' </td>';
450 echo "\n" . ' </tr>';
453 // Do one more empty row
454 echo "\n" . ' <tr class="';
460 $odd_row != $odd_row;
463 . "\n" . ' <select name="c_table_' . $i . '[name]">';
464 foreach ($selectboxall AS $key => $value) {
465 echo "\n" . ' <option value="' . $value . '">' . $value . '</option>';
467 echo "\n" . ' </select>'
470 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
471 echo "\n" . ' </td>';
473 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
474 echo "\n" . ' </td>';
476 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
477 echo "\n" . ' </td>';
478 echo "\n" . ' </tr>';
479 echo "\n" . ' </table>' . "\n";
481 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
482 echo ($cfg['WYSIWYG-PDF'] ?
"\n" . ' <input type="hidden" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />' : '');
483 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . $strColumnNames . '<br />';
484 echo "\n" . ' <input type="submit" value="' . $strSave . '" />';
485 echo "\n" . '</form>' . "\n\n";
488 // Check if there are tables that need to be deleted,
489 // if there are, ask the user for allowance
493 if (!empty($tabExist) && is_array($tabExist)) {
494 foreach ($tabExist AS $key => $value) {
496 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '" />' . "\n";
497 $_strname .= '<li>' . $key . '</li>' . "\n";
502 echo '<form action="pdf_pages.php" method="post">' . "\n"
503 . PMA_generate_common_hidden_inputs($db, $table)
504 . '<input type="hidden" name="do" value="deleteCrap" />' . "\n"
505 . '<input type="hidden" name="chpage" value="' . $chpage . '" />' . "\n"
511 . '<input type="submit" value="' . $strGo . '" />' . "\n"
515 // ------------------------------------
516 // d i s p l a y p d f s c h e m a
517 // ------------------------------------
521 ||
($do == 'choosepage' && isset($chpage))
522 ||
($do == 'createpage' && isset($chpage)))) {
524 <form method
="post" action
="pdf_schema.php" name
="pdfoptions">
525 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
526 <input type
="hidden" name
="pdf_page_number" value
="<?php echo $chpage; ?>" />
528 <?php
echo '<br /><b>' . $strDisplayPDF . '</b>'; ?
>: 
;<br
/>
529 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" /><label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
530 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" /><label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
531 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" /><label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
532 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" /><label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
><br
/>
533 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" /><label
for="with_doc"><?php
echo $strDataDict; ?
></label
>
535 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
536 <select id
="orientation_opt" name
="orientation" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
537 <option value
="L"><?php
echo $strLandscape;?
></option
>
538 <option value
="P"><?php
echo $strPortrait;?
></option
>
541 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
542 <select id
="paper_opt" name
="paper" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
544 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
545 echo '<option value="' . $val . '"';
546 if ($val == $cfg['PDFDefaultPageSize']) {
547 echo ' selected="selected"';
549 echo ' >' . $val . '</option>' . "\n";
553  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
556 if ((isset($showwysiwyg) && $showwysiwyg == '1')) {
558 <script type
="text/javascript">
560 ToggleDragDrop('pdflayout');
566 } // end if ($cfgRelation['pdfwork'])
570 * Displays the footer
573 require_once './libraries/footer.inc.php';