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';
13 require './libraries/StorageEngine.class.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_foreign)) {
89 $all_tables = array();
92 if (isset($auto_layout_foreign)) {
93 // get the tables list
94 $tables = PMA_DBI_get_tables_full($db);
95 // find the ones who support FOREIGN KEY; it's not
96 // important that we group together InnoDB tables
97 // and PBXT tables, as this logic is just to put
98 // the tables on the layout, not to determine relations
99 $foreignkey_tables = array();
100 foreach($tables as $table_name => $table_properties) {
101 if (PMA_foreignkey_supported($table_properties['ENGINE'])) {
102 $foreignkey_tables[] = $table_name;
105 $all_tables = $foreignkey_tables;
106 // could be improved by finding the tables which have the
107 // most references keys and placing them at the beginning
108 // of the array (so that they are all center of schema)
109 unset($tables, $foreignkey_tables);
110 } // endif auto_layout_foreign
112 if (isset($auto_layout_internal)) {
113 // get the tables that have relations, by descending
115 $master_tables = 'SELECT COUNT(master_table), master_table'
116 . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
117 . ' WHERE master_db = \'' . $db . '\''
118 . ' GROUP BY master_table'
119 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
120 $master_tables_rs = PMA_query_as_cu($master_tables, FALSE, $query_default_option);
121 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
122 // first put all the master tables at beginning
123 // of the list, so they are near the center of
125 while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
126 $all_tables[] = $master_table;
129 // then for each master, add its foreigns into an array
130 // of foreign tables, if not already there
131 // (a foreign might be foreign for more than
132 // one table, and might be a master itself)
134 $foreign_tables = array();
135 foreach ($all_tables AS $master_table) {
136 $foreigners = PMA_getForeigners($db, $master_table);
137 foreach ($foreigners AS $foreigner) {
138 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
139 $foreign_tables[] = $foreigner['foreign_table'];
144 // then merge the arrays
145 foreach ($foreign_tables AS $foreign_table) {
146 if (!in_array($foreign_table, $all_tables)) {
147 $all_tables[] = $foreign_table;
150 } // endif there are master tables
151 } // endif auto_layout_internal
153 if (isset($auto_layout_internal) ||
isset($auto_layout_foreign)) {
154 // now generate the coordinates for the schema,
155 // in a clockwise spiral
161 $direction = "right";
162 foreach ($all_tables AS $current_table) {
164 // save current table's coordinates
165 $insert_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
166 . '(db_name, table_name, pdf_page_number, x, y) '
167 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pdf_page_number . ',' . $pos_x . ',' . $pos_y . ')';
168 PMA_query_as_cu($insert_query, FALSE, $query_default_option);
170 // compute for the next table
171 switch ($direction) {
175 $delta *= $delta_mult;
180 $delta *= $delta_mult;
185 $delta *= $delta_mult;
189 $direction = "right";
190 $delta *= $delta_mult;
194 } // end if some auto-layout to do
196 $chpage = $pdf_page_number;
201 for ($i = 0; $i < $c_table_rows; $i++
) {
202 $arrvalue = 'c_table_' . $i;
203 $arrvalue = $
$arrvalue;
204 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
207 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
210 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
211 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
212 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
213 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
214 . ' AND pdf_page_number = ' . $chpage;
215 $test_rs = PMA_query_as_cu($test_query, FALSE, $query_default_option);
216 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
217 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
218 $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
219 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
220 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
221 . ' AND pdf_page_number = ' . $chpage;
223 $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
224 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
225 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
226 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
227 . ' AND pdf_page_number = ' . $chpage;
230 $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
231 . '(db_name, table_name, pdf_page_number, x, y) '
232 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\',' . $chpage . ',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
234 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
239 foreach ($delrow AS $current_row) {
240 $d_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
241 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
242 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
243 . ' AND pdf_page_number = ' . $chpage;
244 PMA_query_as_cu($d_query, FALSE, $query_default_option);
248 } // end if (isset($do))
250 // We will need an array of all tables in this db
251 $selectboxall = array('--');
252 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
253 while ($val = @PMA_DBI_fetch_row
($alltab_rs)) {
254 $selectboxall[] = $val[0];
257 // Now first show some possibility to choose a page for the pdf
258 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
259 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
260 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
262 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
264 <form method
="get" action
="pdf_pages.php" name
="selpage">
267 <?php
echo $strChoosePage . "\n"; ?
>
269 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
270 <input type
="hidden" name
="do" value
="choosepage" />
271 <select name
="chpage" onchange
="this.form.submit()">
273 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
275 . '<option value="' . $curr_page['page_nr'] . '"';
276 if (isset($chpage) && $chpage == $curr_page['page_nr']) {
277 echo ' selected="selected"';
279 echo '>' . $curr_page['page_nr'] . ': ' . $curr_page['page_descr'] . '</option>';
288 PMA_generate_html_radio('action_choose', $choices, '0', false);
291 <input type
="submit" value
="<?php echo $strGo; ?>" /><br
/>
298 // Possibility to create a new page:
300 <form method
="post" action
="pdf_pages.php" name
="crpage">
303 <?php
echo $strCreatePage . "\n"; ?
>
305 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
306 <input type
="hidden" name
="do" value
="createpage" />
307 <input type
="text" name
="newpage" size
="20" maxlength
="50" />
308 <input type
="checkbox" name
="auto_layout_internal" />
309 <?php
echo '(' . $strAutomaticLayout . ' / ' . $strInternalRelations . ')';
310 if (PMA_StorageEngine
::isValid('InnoDB') || PMA_StorageEngine
::isValid('PBXT')) {
311 echo '<input type="checkbox" name="auto_layout_foreign" />'
312 . '(' . $strAutomaticLayout . ' / FOREIGN KEY)';
315 <input type
="submit" value
="<?php echo $strGo; ?>" />
319 // Now if we already have chosen a page number then we should show the
321 if (isset($chpage) && $chpage > 0) {
326 <h2
><?php
echo $strSelectTables ;?
></h2
>
329 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
330 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
331 . ' AND pdf_page_number = ' . $chpage;
332 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
333 $array_sh_page = array();
335 $reset_draginit = '';
337 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
338 $array_sh_page[] = $temp_sh_page;
341 // garvin: Display WYSIWYG-PDF parts?
342 if ($cfg['WYSIWYG-PDF']) {
343 if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
344 $with_field_names = TRUE;
347 <script type
="text/javascript" src
="./js/dom-drag.js"></script
>
348 <form method
="post" action
="pdf_pages.php" name
="dragdrop">
349 <input type
="button" name
="dragdrop" value
="<?php echo $strToggleScratchboard; ?>" onclick
="ToggleDragDrop('pdflayout');" />
350 <input type
="button" name
="dragdropreset" value
="<?php echo $strReset; ?>" onclick
="resetDrag();" />
352 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
354 foreach ($array_sh_page AS $key => $temp_sh_page) {
355 $drag_x = $temp_sh_page['x'];
356 $drag_y = $temp_sh_page['y'];
358 $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
359 $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";
360 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
361 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
362 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
363 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
364 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
365 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
367 $local_query = 'SHOW FIELDS FROM '
368 . PMA_backquote($temp_sh_page['table_name'])
369 . ' FROM ' . PMA_backquote($db);
370 $fields_rs = PMA_DBI_query($local_query);
372 $fields_cnt = PMA_DBI_num_rows($fields_rs);
374 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
375 if (isset($with_field_names)) {
376 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
377 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
380 echo '</div>' . "\n";
381 PMA_DBI_free_result($fields_rs);
388 <script type
="text/javascript">
392 myid
= getElement('pdflayout');
393 <?php
echo $draginit; ?
>
396 function resetDrag() {
397 <?php
echo $reset_draginit; ?
>
402 } // end if WYSIWYG-PDF
405 <form method
="post" action
="pdf_pages.php" name
="edcoord">
406 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
407 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
408 <input type
="hidden" name
="do" value
="edcoord" />
411 <th
><?php
echo $strTable; ?
></th
>
412 <th
><?php
echo $strDelete; ?
></th
>
417 if (isset($ctable)) {
424 foreach ($array_sh_page AS $dummy_sh_page => $sh_page) {
425 $_mtab = $sh_page['table_name'];
426 $tabExist[$_mtab] = FALSE;
427 echo "\n" . ' <tr class="';
434 $odd_row != $odd_row;
436 . "\n" . ' <select name="c_table_' . $i . '[name]">';
437 foreach ($selectboxall AS $key => $value) {
438 echo "\n" . ' <option value="' . $value . '"';
439 if ($value == $sh_page['table_name']) {
440 echo ' selected="selected"';
441 $tabExist[$_mtab] = TRUE;
443 echo '>' . $value . '</option>';
445 echo "\n" . ' </select>'
448 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
449 echo "\n" . ' </td>';
451 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'x\', this.value)"' : '') . ' name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
452 echo "\n" . ' </td>';
454 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'y\', this.value)"' : '') . ' name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
455 echo "\n" . ' </td>';
456 echo "\n" . ' </tr>';
459 // Do one more empty row
460 echo "\n" . ' <tr class="';
466 $odd_row != $odd_row;
469 . "\n" . ' <select name="c_table_' . $i . '[name]">';
470 foreach ($selectboxall AS $key => $value) {
471 echo "\n" . ' <option value="' . $value . '">' . $value . '</option>';
473 echo "\n" . ' </select>'
476 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
477 echo "\n" . ' </td>';
479 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
480 echo "\n" . ' </td>';
482 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
483 echo "\n" . ' </td>';
484 echo "\n" . ' </tr>';
485 echo "\n" . ' </table>' . "\n";
487 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
488 echo ($cfg['WYSIWYG-PDF'] ?
"\n" . ' <input type="hidden" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />' : '');
489 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . $strColumnNames . '<br />';
490 echo "\n" . ' <input type="submit" value="' . $strSave . '" />';
491 echo "\n" . '</form>' . "\n\n";
494 // Check if there are tables that need to be deleted,
495 // if there are, ask the user for allowance
499 if (!empty($tabExist) && is_array($tabExist)) {
500 foreach ($tabExist AS $key => $value) {
502 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '" />' . "\n";
503 $_strname .= '<li>' . $key . '</li>' . "\n";
508 echo '<form action="pdf_pages.php" method="post">' . "\n"
509 . PMA_generate_common_hidden_inputs($db, $table)
510 . '<input type="hidden" name="do" value="deleteCrap" />' . "\n"
511 . '<input type="hidden" name="chpage" value="' . $chpage . '" />' . "\n"
517 . '<input type="submit" value="' . $strGo . '" />' . "\n"
521 // ------------------------------------
522 // d i s p l a y p d f s c h e m a
523 // ------------------------------------
527 ||
($do == 'choosepage' && isset($chpage))
528 ||
($do == 'createpage' && isset($chpage)))) {
530 <form method
="post" action
="pdf_schema.php" name
="pdfoptions">
531 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
532 <input type
="hidden" name
="pdf_page_number" value
="<?php echo $chpage; ?>" />
534 <?php
echo '<br /><b>' . $strDisplayPDF . '</b>'; ?
>: 
;<br
/>
535 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" /><label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
536 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" /><label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
537 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" /><label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
538 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" /><label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
><br
/>
539 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" /><label
for="with_doc"><?php
echo $strDataDict; ?
></label
>
541 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
542 <select id
="orientation_opt" name
="orientation" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
543 <option value
="L"><?php
echo $strLandscape;?
></option
>
544 <option value
="P"><?php
echo $strPortrait;?
></option
>
547 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
548 <select id
="paper_opt" name
="paper" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
550 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
551 echo '<option value="' . $val . '"';
552 if ($val == $cfg['PDFDefaultPageSize']) {
553 echo ' selected="selected"';
555 echo ' >' . $val . '</option>' . "\n";
559  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
562 if ((isset($showwysiwyg) && $showwysiwyg == '1')) {
564 <script type
="text/javascript">
566 ToggleDragDrop('pdflayout');
572 } // end if ($cfgRelation['pdfwork'])
576 * Displays the footer
579 require_once './libraries/footer.inc.php';