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 $pdf_page_number = PMA_REL_create_page($newpage, $cfgRelation, $db, $query_default_option);
79 // A u t o m a t i c l a y o u t
80 // ================================
81 if (isset($auto_layout_internal) ||
isset($auto_layout_foreign)) {
82 $all_tables = array();
85 if (isset($auto_layout_foreign)) {
86 // get the tables list
87 $tables = PMA_DBI_get_tables_full($db);
88 // find the ones who support FOREIGN KEY; it's not
89 // important that we group together InnoDB tables
90 // and PBXT tables, as this logic is just to put
91 // the tables on the layout, not to determine relations
92 $foreignkey_tables = array();
93 foreach($tables as $table_name => $table_properties) {
94 if (PMA_foreignkey_supported($table_properties['ENGINE'])) {
95 $foreignkey_tables[] = $table_name;
98 $all_tables = $foreignkey_tables;
99 // could be improved by finding the tables which have the
100 // most references keys and placing them at the beginning
101 // of the array (so that they are all center of schema)
102 unset($tables, $foreignkey_tables);
103 } // endif auto_layout_foreign
105 if (isset($auto_layout_internal)) {
106 // get the tables that have relations, by descending
108 $master_tables = 'SELECT COUNT(master_table), master_table'
109 . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
110 . ' WHERE master_db = \'' . $db . '\''
111 . ' GROUP BY master_table'
112 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
113 $master_tables_rs = PMA_query_as_cu($master_tables, FALSE, $query_default_option);
114 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
115 // first put all the master tables at beginning
116 // of the list, so they are near the center of
118 while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
119 $all_tables[] = $master_table;
122 // then for each master, add its foreigns into an array
123 // of foreign tables, if not already there
124 // (a foreign might be foreign for more than
125 // one table, and might be a master itself)
127 $foreign_tables = array();
128 foreach ($all_tables AS $master_table) {
129 $foreigners = PMA_getForeigners($db, $master_table);
130 foreach ($foreigners AS $foreigner) {
131 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
132 $foreign_tables[] = $foreigner['foreign_table'];
137 // then merge the arrays
138 foreach ($foreign_tables AS $foreign_table) {
139 if (!in_array($foreign_table, $all_tables)) {
140 $all_tables[] = $foreign_table;
143 } // endif there are master tables
144 } // endif auto_layout_internal
146 if (isset($auto_layout_internal) ||
isset($auto_layout_foreign)) {
147 // now generate the coordinates for the schema,
148 // in a clockwise spiral
154 $direction = "right";
155 foreach ($all_tables AS $current_table) {
157 // save current table's coordinates
158 $insert_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
159 . '(db_name, table_name, pdf_page_number, x, y) '
160 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pdf_page_number . ',' . $pos_x . ',' . $pos_y . ')';
161 PMA_query_as_cu($insert_query, FALSE, $query_default_option);
163 // compute for the next table
164 switch ($direction) {
168 $delta *= $delta_mult;
173 $delta *= $delta_mult;
178 $delta *= $delta_mult;
182 $direction = "right";
183 $delta *= $delta_mult;
187 } // end if some auto-layout to do
189 $chpage = $pdf_page_number;
194 for ($i = 0; $i < $c_table_rows; $i++
) {
195 $arrvalue = 'c_table_' . $i;
196 $arrvalue = $
$arrvalue;
197 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
200 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
203 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
204 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
205 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
206 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
207 . ' AND pdf_page_number = ' . $chpage;
208 $test_rs = PMA_query_as_cu($test_query, FALSE, $query_default_option);
209 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
210 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
211 $ch_query = 'DELETE 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;
216 $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
217 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
218 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
219 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
220 . ' AND pdf_page_number = ' . $chpage;
223 $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
224 . '(db_name, table_name, pdf_page_number, x, y) '
225 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\',' . $chpage . ',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
227 PMA_query_as_cu($ch_query, FALSE, $query_default_option);
232 foreach ($delrow AS $current_row) {
233 $d_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
234 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
235 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
236 . ' AND pdf_page_number = ' . $chpage;
237 PMA_query_as_cu($d_query, FALSE, $query_default_option);
241 } // end if (isset($do))
243 // We will need an array of all tables in this db
244 $selectboxall = array('--');
245 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
246 while ($val = @PMA_DBI_fetch_row
($alltab_rs)) {
247 $selectboxall[] = $val[0];
250 // Now first show some possibility to choose a page for the pdf
251 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
252 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
253 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
255 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
257 <form method
="get" action
="pdf_pages.php" name
="selpage">
260 <?php
echo $strChoosePage . "\n"; ?
>
262 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
263 <input type
="hidden" name
="do" value
="choosepage" />
264 <select name
="chpage" onchange
="this.form.submit()">
266 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
268 . '<option value="' . $curr_page['page_nr'] . '"';
269 if (isset($chpage) && $chpage == $curr_page['page_nr']) {
270 echo ' selected="selected"';
272 echo '>' . $curr_page['page_nr'] . ': ' . $curr_page['page_descr'] . '</option>';
281 PMA_generate_html_radio('action_choose', $choices, '0', false);
284 <input type
="submit" value
="<?php echo $strGo; ?>" /><br
/>
291 // Possibility to create a new page:
293 <form method
="post" action
="pdf_pages.php" name
="crpage">
296 <?php
echo $strCreatePage . "\n"; ?
>
298 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
299 <input type
="hidden" name
="do" value
="createpage" />
300 <input type
="text" name
="newpage" size
="20" maxlength
="50" />
301 <input type
="checkbox" name
="auto_layout_internal" />
302 <?php
echo '(' . $strAutomaticLayout . ' / ' . $strInternalRelations . ')';
303 if (PMA_StorageEngine
::isValid('InnoDB') || PMA_StorageEngine
::isValid('PBXT')) {
304 echo '<input type="checkbox" name="auto_layout_foreign" />'
305 . '(' . $strAutomaticLayout . ' / FOREIGN KEY)';
308 <input type
="submit" value
="<?php echo $strGo; ?>" />
312 // Now if we already have chosen a page number then we should show the
314 if (isset($chpage) && $chpage > 0) {
319 <h2
><?php
echo $strSelectTables ;?
></h2
>
322 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
323 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
324 . ' AND pdf_page_number = ' . $chpage;
325 $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
326 $array_sh_page = array();
328 $reset_draginit = '';
330 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
331 $array_sh_page[] = $temp_sh_page;
334 // garvin: Display WYSIWYG-PDF parts?
335 if ($cfg['WYSIWYG-PDF']) {
336 if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
337 $with_field_names = TRUE;
340 <script type
="text/javascript" src
="./js/dom-drag.js"></script
>
341 <form method
="post" action
="pdf_pages.php" name
="dragdrop">
342 <input type
="button" name
="dragdrop" value
="<?php echo $strToggleScratchboard; ?>" onclick
="ToggleDragDrop('pdflayout');" />
343 <input type
="button" name
="dragdropreset" value
="<?php echo $strReset; ?>" onclick
="resetDrag();" />
345 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
347 foreach ($array_sh_page AS $key => $temp_sh_page) {
348 $drag_x = $temp_sh_page['x'];
349 $drag_y = $temp_sh_page['y'];
351 $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
352 $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";
353 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
354 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
355 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
356 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
357 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
358 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
360 $local_query = 'SHOW FIELDS FROM '
361 . PMA_backquote($temp_sh_page['table_name'])
362 . ' FROM ' . PMA_backquote($db);
363 $fields_rs = PMA_DBI_query($local_query);
365 $fields_cnt = PMA_DBI_num_rows($fields_rs);
367 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
368 if (isset($with_field_names)) {
369 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
370 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
373 echo '</div>' . "\n";
374 PMA_DBI_free_result($fields_rs);
381 <script type
="text/javascript">
385 myid
= getElement('pdflayout');
386 <?php
echo $draginit; ?
>
389 function resetDrag() {
390 <?php
echo $reset_draginit; ?
>
395 } // end if WYSIWYG-PDF
398 <form method
="post" action
="pdf_pages.php" name
="edcoord">
399 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
400 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
401 <input type
="hidden" name
="do" value
="edcoord" />
404 <th
><?php
echo $strTable; ?
></th
>
405 <th
><?php
echo $strDelete; ?
></th
>
410 if (isset($ctable)) {
417 foreach ($array_sh_page AS $dummy_sh_page => $sh_page) {
418 $_mtab = $sh_page['table_name'];
419 $tabExist[$_mtab] = FALSE;
420 echo "\n" . ' <tr class="';
427 $odd_row != $odd_row;
429 . "\n" . ' <select name="c_table_' . $i . '[name]">';
430 foreach ($selectboxall AS $key => $value) {
431 echo "\n" . ' <option value="' . $value . '"';
432 if ($value == $sh_page['table_name']) {
433 echo ' selected="selected"';
434 $tabExist[$_mtab] = TRUE;
436 echo '>' . $value . '</option>';
438 echo "\n" . ' </select>'
441 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
442 echo "\n" . ' </td>';
444 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'x\', this.value)"' : '') . ' name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
445 echo "\n" . ' </td>';
447 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'y\', this.value)"' : '') . ' name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
448 echo "\n" . ' </td>';
449 echo "\n" . ' </tr>';
452 // Do one more empty row
453 echo "\n" . ' <tr class="';
459 $odd_row != $odd_row;
462 . "\n" . ' <select name="c_table_' . $i . '[name]">';
463 foreach ($selectboxall AS $key => $value) {
464 echo "\n" . ' <option value="' . $value . '">' . $value . '</option>';
466 echo "\n" . ' </select>'
469 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
470 echo "\n" . ' </td>';
472 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
473 echo "\n" . ' </td>';
475 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
476 echo "\n" . ' </td>';
477 echo "\n" . ' </tr>';
478 echo "\n" . ' </table>' . "\n";
480 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
481 echo ($cfg['WYSIWYG-PDF'] ?
"\n" . ' <input type="hidden" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />' : '');
482 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . $strColumnNames . '<br />';
483 echo "\n" . ' <input type="submit" value="' . $strSave . '" />';
484 echo "\n" . '</form>' . "\n\n";
487 // Check if there are tables that need to be deleted,
488 // if there are, ask the user for allowance
492 if (!empty($tabExist) && is_array($tabExist)) {
493 foreach ($tabExist AS $key => $value) {
495 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '" />' . "\n";
496 $_strname .= '<li>' . $key . '</li>' . "\n";
501 echo '<form action="pdf_pages.php" method="post">' . "\n"
502 . PMA_generate_common_hidden_inputs($db, $table)
503 . '<input type="hidden" name="do" value="deleteCrap" />' . "\n"
504 . '<input type="hidden" name="chpage" value="' . $chpage . '" />' . "\n"
510 . '<input type="submit" value="' . $strGo . '" />' . "\n"
514 // ------------------------------------
515 // d i s p l a y p d f s c h e m a
516 // ------------------------------------
520 ||
($do == 'choosepage' && isset($chpage))
521 ||
($do == 'createpage' && isset($chpage)))) {
523 <form method
="post" action
="pdf_schema.php" name
="pdfoptions">
524 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
525 <input type
="hidden" name
="pdf_page_number" value
="<?php echo $chpage; ?>" />
527 <?php
echo '<br /><strong>' . $strDisplayPDF . '</strong>'; ?
>: 
;<br
/>
528 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" /><label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
529 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" /><label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
530 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" /><label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
531 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" /><label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
><br
/>
532 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" /><label
for="with_doc"><?php
echo $strDataDict; ?
></label
>
534 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
535 <select id
="orientation_opt" name
="orientation" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
536 <option value
="L"><?php
echo $strLandscape;?
></option
>
537 <option value
="P"><?php
echo $strPortrait;?
></option
>
540 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
541 <select id
="paper_opt" name
="paper" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
543 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
544 echo '<option value="' . $val . '"';
545 if ($val == $cfg['PDFDefaultPageSize']) {
546 echo ' selected="selected"';
548 echo ' >' . $val . '</option>' . "\n";
552  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
555 if ((isset($showwysiwyg) && $showwysiwyg == '1')) {
557 <script type
="text/javascript">
559 ToggleDragDrop('pdflayout');
565 } // end if ($cfgRelation['pdfwork'])
569 * Displays the footer
572 require_once './libraries/footer.inc.php';