3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
11 require('./db_details_common.php3');
15 * Settings for relation stuff
17 require('./libraries/relation.lib.php3');
18 $cfgRelation = PMA_getRelationsParam();
22 * Now in ./libraries/relation.lib.php3 we check for all tables
23 * that we need, but if we don't find them we are quiet about it
24 * so people can work without.
25 * This page is absolutely useless if you didn't set up your tables
26 * correctly, so it is a good place to see which tables we can and
29 if (!$cfgRelation['relwork']) {
30 echo sprintf($strNotSet, 'relation', 'config.inc.php3') . '<br />' . "\n"
31 . '<a href="./Documentation.html#relation" target="documentation">' . $strDocu . '</a>' . "\n";
35 if (!$cfgRelation['displaywork']) {
36 echo sprintf($strNotSet, 'table_info', 'config.inc.php3') . '<br />' . "\n"
37 . '<a href="./Documentation.html#table_info" target="documentation">' . $strDocu . '</a>' . "\n";
41 if (!isset($cfgRelation['table_coords'])){
42 echo sprintf($strNotSet, 'table_coords', 'config.inc.php3') . '<br />' . "\n"
43 . '<a href="./Documentation.html#table_coords" target="documentation">' . $strDocu . '</a>' . "\n";
46 if (!isset($cfgRelation['pdf_pages'])) {
47 echo sprintf($strNotSet, 'pdf_page', 'config.inc.php3') . '<br />' . "\n"
48 . '<a href="./Documentation.html#pdf_pages" target="documentation">' . $strDocu . '</a>' . "\n";
52 if ($cfgRelation['pdfwork']) {
53 // Now is the time to work on all changes
57 if ($action_choose=="1") {
58 $ch_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
59 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
60 . ' AND pdf_page_number = ' . $chpage;
61 PMA_query_as_cu($ch_query);
63 $ch_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
64 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
65 . ' AND page_nr = ' . $chpage;
66 PMA_query_as_cu($ch_query);
72 if (!isset($newpage) ||
$newpage == '') {
73 $newpage = $strNoDescription;
75 $ins_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['pdf_pages'])
76 . ' (db_name, page_descr)'
77 . ' VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($newpage) . '\')';
78 PMA_query_as_cu($ins_query);
80 // A u t o m a t i c l a y o u t
82 if (isset($autolayout)) {
83 // save the page number
84 $pdf_page_number = mysql_insert_id((isset($dbh)?
$dbh:''));
86 // get the tables that have relations, by descending
88 $master_tables = 'SELECT COUNT(master_table), master_table'
89 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
90 . ' WHERE master_db = \'' . $db . '\''
91 . ' GROUP BY master_table'
92 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
93 $master_tables_rs = PMA_query_as_cu($master_tables);
94 if ($master_tables_rs && mysql_num_rows($master_tables_rs) > 0) {
95 // first put all the master tables at beginning
96 // of the list, so they are near the center of
98 while (list(,$master_table) = mysql_fetch_row($master_tables_rs)) {
99 $all_tables[] = $master_table;
102 // then for each master, add its foreigns into an array
103 // of foreign tables, if not already there
104 // (a foreign might be foreign for more than
105 // one table, and might be a master itself)
107 $foreign_tables = array();
108 while (list(,$master_table) = each($all_tables)) {
109 $foreigners = PMA_getForeigners($db, $master_table);
110 while (list(, $foreigner) = each($foreigners)) {
111 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
112 $foreign_tables[] = $foreigner['foreign_table'];
117 // then merge the arrays
119 while (list(,$foreign_table) = each($foreign_tables)) {
120 if (!in_array($foreign_table, $all_tables)) {
121 $all_tables[] = $foreign_table;
125 // now generate the coordinates for the schema,
126 // in a clockwise spiral
132 $direction = "right";
135 while (list(,$current_table) = each($all_tables)) {
137 // save current table's coordinates
138 $insert_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_coords']) . ' '
139 . '(db_name, table_name, pdf_page_number, x, y) '
140 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pdf_page_number . ',' . $pos_x . ',' . $pos_y . ')';
141 PMA_query_as_cu($insert_query);
144 // compute for the next table
145 switch ($direction) {
149 $delta *= $delta_mult;
154 $delta *= $delta_mult;
159 $delta *= $delta_mult;
163 $direction = "right";
164 $delta *= $delta_mult;
168 } // end if there are master tables
170 $chpage = $pdf_page_number;
171 } // end if isset autolayout
176 for ($i = 0; $i < $c_table_rows; $i++
) {
177 $arrvalue = 'c_table_' . $i;
178 $arrvalue = $
$arrvalue;
179 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
182 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
185 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
186 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords'])
187 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
188 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
189 . ' AND pdf_page_number = ' . $chpage;
190 $test_rs = PMA_query_as_cu($test_query);
191 if ($test_rs && mysql_num_rows($test_rs) > 0) {
192 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
193 $ch_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
194 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
195 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
196 . ' AND pdf_page_number = ' . $chpage;
198 $ch_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords']) . ' '
199 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
200 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
201 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
202 . ' AND pdf_page_number = ' . $chpage;
205 $ch_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_coords']) . ' '
206 . '(db_name, table_name, pdf_page_number, x, y) '
207 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\',' . $chpage . ',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
209 PMA_query_as_cu($ch_query);
214 while (list(,$current_row) = each($delrow)) {
215 $d_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
216 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
217 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
218 . ' AND pdf_page_number = ' . $chpage;
219 PMA_query_as_cu($d_query);
223 } // end if (isset($do))
225 // We will need an array of all tables in this db
226 $selectboxall = array('--');
227 $alltab_qry = 'SHOW TABLES FROM ' . PMA_backquote($db);
228 $alltab_rs = @PMA_mysql_query
($alltab_qry) or PMA_mysqlDie('', $alltab_qry, '', $err_url_0);
229 while ($val = @PMA_mysql_fetch_array
($alltab_rs)) {
230 $selectboxall[] = $val[0];
234 // Now first show some possibility to choose a page for the pdf
235 $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
236 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
237 $page_rs = PMA_query_as_cu($page_query);
238 if ($page_rs && mysql_num_rows($page_rs) > 0) {
240 <form method
="get" action
="pdf_pages.php3" 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_mysql_fetch_array
($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.php3" 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);
294 $array_sh_page = array();
296 $reset_draginit = '';
298 while ($temp_sh_page = @PMA_mysql_fetch_array
($page_rs)) {
299 $array_sh_page[] = $temp_sh_page;
301 reset($array_sh_page);
303 // garvin: Display WYSIWYG-PDF parts?
304 if ($cfg['WYSIWYG-PDF']) {
306 <script type
="text/javascript" src
="./libraries/dom-drag.js"></script
>
307 <form method
="post" action
="pdf_pages.php3" name
="dragdrop">
308 <input type
="button" name
="dragdrop" value
="<?php echo $strToggleScratchboard; ?>" onclick
="ToggleDragDrop('pdflayout');" />
309 <input type
="button" name
="dragdropreset" value
="<?php echo $strReset; ?>" onclick
="resetDrag();" />
311 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
313 while (list($key, $temp_sh_page) = each($array_sh_page)) {
314 $drag_x = $temp_sh_page['x'];
315 $drag_y = $temp_sh_page['y'];
317 $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
318 $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";
319 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
320 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
321 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
322 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
323 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
324 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
326 echo '<div id="table_' . $i . '" class="pdflayout_table">' . $temp_sh_page['table_name'] . '</div>' . "\n";
329 reset($array_sh_page);
332 <script type
="text/javascript">
336 myid
= getElement('pdflayout');
337 <?php
echo $draginit; ?
>
340 function resetDrag() {
341 <?php
echo $reset_draginit; ?
>
346 } // end if WYSIWYG-PDF
349 <form method
="post" action
="pdf_pages.php3" name
="edcoord">
350 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
351 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
352 <input type
="hidden" name
="do" value
="edcoord" />
355 <th
><?php
echo $strTable; ?
></th
>
356 <th
><?php
echo $strDelete; ?
></th
>
361 if (isset($ctable)) {
367 while (list($dummy_sh_page, $sh_page) = each($array_sh_page)) {
368 $_mtab = $sh_page['table_name'];
369 $tabExist[$_mtab] = FALSE;
372 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
374 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
378 . "\n" . ' <select name="c_table_' . $i . '[name]">';
379 reset($selectboxall);
380 while (list($key, $value) = each($selectboxall)) {
381 echo "\n" . ' <option value="' . $value . '"';
382 if ($value == $sh_page['table_name']) {
383 echo ' selected="selected"';
384 $tabExist[$_mtab] = TRUE;
386 echo '>' . $value . '</option>';
388 echo "\n" . ' </select>'
391 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
392 echo "\n" . ' </td>';
394 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'x\', this.value)"' : '') . ' name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
395 echo "\n" . ' </td>';
397 . "\n" . ' <input type="text" ' . ($cfg['WYSIWYG-PDF'] ?
'onchange="dragPlace(' . $i . ', \'y\', this.value)"' : '') . ' name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
398 echo "\n" . ' </td>';
399 echo "\n" . ' </tr>';
402 // Do one more empty row
405 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
407 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
411 . "\n" . ' <select name="c_table_' . $i . '[name]">';
412 reset($selectboxall);
413 while (list($key, $value) = each($selectboxall)) {
414 echo "\n" . ' <option value="' . $value . '">' . $value . '</option>';
416 echo "\n" . ' </select>'
419 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
420 echo "\n" . ' </td>';
422 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
423 echo "\n" . ' </td>';
425 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
426 echo "\n" . ' </td>';
427 echo "\n" . ' </tr>';
428 echo "\n" . ' </table>' . "\n";
430 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
431 echo ($cfg['WYSIWYG-PDF'] ?
"\n" . ' <input type="hidden" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />' : '');
432 echo "\n" . ' <input type="submit" value="' . $strGo . '" />';
433 echo "\n" . '</form>' . "\n\n";
436 // Check if there are tables that need to be deleted,
437 // if there are, ask the user for allowance
441 if (!empty($tabExist) && is_array($tabExist)) {
442 while (list($key, $value) = each($tabExist)) {
444 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '">' . "\n";
445 $_strname .= '<li>' . $key . '</li>' . "\n";
450 echo '<FORM action="pdf_pages.php3" method="post">' . "\n"
451 . PMA_generate_common_hidden_inputs($db, $table)
452 . '<input type="hidden" name="do" value="deleteCrap">' . "\n"
453 . '<input type="hidden" name="chpage" value="' . $chpage . '">' . "\n"
459 . '<input type="submit" value="' . $strGo . '">' . "\n"
463 // ------------------------------------
464 // d i s p l a y p d f s c h e m a
465 // ------------------------------------
469 ||
($do == 'choosepage' && isset($chpage))
470 ||
($do == 'createpage' && isset($chpage)))) {
472 <form method
="post" action
="pdf_schema.php3" name
="pdfoptions">
473 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
474 <input type
="hidden" name
="pdf_page_number" value
="<?php echo $chpage; ?>" />
475 <?php
echo $strDisplayPDF; ?
> 
;:<br
/>
476 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
477 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
478 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" />
479 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
480 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
481 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
482 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
483 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
><br
/>
484 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
485 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
> <br
/>
486 <?php
echo $strShowDatadictAs; ?
>
487 <select name
="orientation" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
488 <option value
="L"><?php
echo $strLandscape;?
></option
>
489 <option value
="P"><?php
echo $strPortrait;?
></option
>
491 <?php
echo $strPaperSize; ?
>
492 <select name
="paper" <?php
echo ($cfg['WYSIWYG-PDF'] ?
'onchange="refreshDragOption(\'pdflayout\');"' : ''); ?
>>
494 while (list($key,$val) = each($cfg['PDFPageSizes'])) {
495 echo '<option value="' . $val . '"';
496 if ($val == $cfg['PDFDefaultPageSize']) {
497 echo ' selected="selected"';
499 echo ' >' . $val . '</option>' . "\n";
503  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
506 if ((isset($showwysiwyg) && $showwysiwyg == '1')) {
508 <script type
="text/javascript">
510 ToggleDragDrop('pdflayout');
516 } // end if ($cfgRelation['pdfwork'])
520 * Displays the footer
523 require('./footer.inc.php3');