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);
70 if (!isset($newpage) ||
$newpage == '') {
71 $newpage = $strNoDescription;
73 $ins_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['pdf_pages'])
74 . ' (db_name, page_descr)'
75 . ' VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($newpage) . '\')';
76 PMA_query_as_cu($ins_query);
78 // A u t o m a t i c l a y o u t
80 if (isset($autolayout)) {
81 // save the page number
82 $pdf_page_number = mysql_insert_id((isset($dbh)?
$dbh:''));
84 // get the tables that have relations, by descending
86 $master_tables = 'SELECT COUNT(master_table), master_table'
87 . ' FROM ' . PMA_backquote($cfgRelation['relation'])
88 . ' WHERE master_db = \'' . $db . '\''
89 . ' GROUP BY master_table'
90 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
91 $master_tables_rs = PMA_query_as_cu($master_tables);
92 if ($master_tables_rs && mysql_num_rows($master_tables_rs) > 0) {
93 // first put all the master tables at beginning
94 // of the list, so they are near the center of
96 while (list(,$master_table) = mysql_fetch_row($master_tables_rs)) {
97 $all_tables[] = $master_table;
100 // then for each master, add its foreigns into an array
101 // of foreign tables, if not already there
102 // (a foreign might be foreign for more than
103 // one table, and might be a master itself)
105 $foreign_tables = array();
106 while (list(,$master_table) = each($all_tables)) {
107 $foreigners = PMA_getForeigners($db, $master_table);
108 while (list(, $foreigner) = each($foreigners)) {
109 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
110 $foreign_tables[] = $foreigner['foreign_table'];
115 // then merge the arrays
117 while (list(,$foreign_table) = each($foreign_tables)) {
118 if (!in_array($foreign_table, $all_tables)) {
119 $all_tables[] = $foreign_table;
123 // now generate the coordinates for the schema,
124 // in a clockwise spiral
130 $direction = "right";
133 while (list(,$current_table) = each($all_tables)) {
135 // save current table's coordinates
136 $insert_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_coords']) . ' '
137 . '(db_name, table_name, pdf_page_number, x, y) '
138 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pdf_page_number . ',' . $pos_x . ',' . $pos_y . ')';
139 PMA_query_as_cu($insert_query);
142 // compute for the next table
143 switch ($direction) {
147 $delta *= $delta_mult;
152 $delta *= $delta_mult;
157 $delta *= $delta_mult;
161 $direction = "right";
162 $delta *= $delta_mult;
166 } // end if there are master tables
168 $chpage = $pdf_page_number;
169 } // end if isset autolayout
174 for ($i = 0; $i < $c_table_rows; $i++
) {
175 $arrvalue = 'c_table_' . $i;
176 $arrvalue = $
$arrvalue;
177 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
180 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
183 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
184 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords'])
185 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
186 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
187 . ' AND pdf_page_number = ' . $chpage;
188 $test_rs = PMA_query_as_cu($test_query);
189 if ($test_rs && mysql_num_rows($test_rs) > 0) {
190 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
191 $ch_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords'])
192 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
193 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
194 . ' AND pdf_page_number = ' . $chpage;
196 $ch_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords']) . ' '
197 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
198 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
199 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
200 . ' AND pdf_page_number = ' . $chpage;
203 $ch_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['table_coords']) . ' '
204 . '(db_name, table_name, pdf_page_number, x, y) '
205 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\',' . $chpage . ',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
207 PMA_query_as_cu($ch_query);
212 while (list(,$current_row) = each($delrow)) {
213 $d_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
214 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
215 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
216 . ' AND pdf_page_number = ' . $chpage;
217 PMA_query_as_cu($d_query);
221 } // end if (isset($do))
223 // We will need an array of all tables in this db
224 $selectboxall[] = '--';
225 $alltab_qry = 'SHOW TABLES FROM ' . PMA_backquote($db);
226 $alltab_rs = @PMA_mysql_query
($alltab_qry) or PMA_mysqlDie('', $alltab_qry, '', $err_url_0);
227 while (list($table) = @PMA_mysql_fetch_array
($alltab_rs)) {
228 $selectboxall[] = $table;
232 // Now first show some possibility to choose a page for the pdf
233 $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
234 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
235 $page_rs = PMA_query_as_cu($page_query);
236 if ($page_rs && mysql_num_rows($page_rs) > 0) {
238 <form method
="post" action
="pdf_pages.php3" name
="selpage">
239 <?php
echo $strChoosePage . "\n"; ?
>
240 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
241 <input type
="hidden" name
="do" value
="choosepage" />
242 <select name
="chpage" onchange
="this.form.submit()">
244 while ($curr_page = @PMA_mysql_fetch_array
($page_rs)) {
246 . '<option value="' . $curr_page['page_nr'] . '"';
247 if (isset($chpage) && $chpage == $curr_page['page_nr']) {
248 echo ' selected="selected"';
250 echo '>' . $curr_page['page_nr'] . ': ' . $curr_page['page_descr'] . '</option>';
255 <input type
="radio" name
="action_choose" value
="0" id
="radio_choose0" checked
="checked" style
="vertical-align: middle" /> <label
for="radio_choose0">
256 <?php
echo $strEdit; ?
> </label
>
257 <input type
="radio" name
="action_choose" value
="1" id
="radio_choose1" style
="vertical-align: middle" /> <label
for="radio_choose1">
258 <?php
echo $strDelete; ?
> </label
>
260 <input type
="submit" value
="<?php echo $strGo; ?>" />
266 // Possibility to create a new page:
268 <form method
="post" action
="pdf_pages.php3" name
="crpage">
269 <?php
echo $strCreatePage . "\n"; ?
>
270 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
271 <input type
="hidden" name
="do" value
="createpage" />
272 <input type
="text" name
="newpage" size
="20" maxlength
="50" />
273 <input type
="checkbox" name
="autolayout" />
274 <?php
echo '(' . $strAutomaticLayout . ')' . "\n"; ?
>
275 <input type
="submit" value
="<?php echo $strGo; ?>" />
278 // Now if we already have chosen a page number then we should show the
280 if (isset($chpage) && $chpage > 0) {
285 <h2
><?php
echo $strSelectTables ;?
></h2
>
286 <form method
="post" action
="pdf_pages.php3" name
="edcoord">
287 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
288 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
289 <input type
="hidden" name
="do" value
="edcoord" />
292 <th
><?php
echo $strTable; ?
></th
>
293 <th
><?php
echo $strDelete; ?
></th
>
298 if (isset($ctable)) {
302 $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords'])
303 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
304 . ' AND pdf_page_number = ' . $chpage;
305 $page_rs = PMA_query_as_cu($page_query);
308 while ($sh_page = @PMA_mysql_fetch_array
($page_rs)) {
309 $_mtab = $sh_page['table_name'];
310 $tabExist[$_mtab] = FALSE;
313 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
315 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
319 . "\n" . ' <select name="c_table_' . $i . '[name]">';
320 reset($selectboxall);
321 while (list($key, $value) = each($selectboxall)) {
322 echo "\n" . ' <option value="' . $value . '"';
323 if ($value == $sh_page['table_name']) {
324 echo ' selected="selected"';
325 $tabExist[$_mtab] = TRUE;
327 echo '>' . $value . '</option>';
329 echo "\n" . ' </select>'
332 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
333 echo "\n" . ' </td>';
335 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
336 echo "\n" . ' </td>';
338 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
339 echo "\n" . ' </td>';
340 echo "\n" . ' </tr>';
343 // Do one more empty row
346 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
348 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
352 . "\n" . ' <select name="c_table_' . $i . '[name]">';
353 reset($selectboxall);
354 while (list($key, $value) = each($selectboxall)) {
355 echo "\n" . ' <option value="' . $value . '">' . $value . '</option>';
357 echo "\n" . ' </select>'
360 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
361 echo "\n" . ' </td>';
363 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
364 echo "\n" . ' </td>';
366 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
367 echo "\n" . ' </td>';
368 echo "\n" . ' </tr>';
369 echo "\n" . ' </table>' . "\n";
371 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
372 echo "\n" . ' <input type="submit" value="' . $strGo . '" />';
373 echo "\n" . '</form>' . "\n\n";
376 // Check if there are tables that need to be deleted,
377 // if there are, ask the user for allowance
381 if (!empty($tabExist) && is_array($tabExist)) {
382 while (list($key, $value) = each($tabExist)) {
384 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '">' . "\n";
385 $_strname .= '<li>' . $key . '</li>' . "\n";
390 echo '<FORM action="pdf_pages.php3" method="post">' . "\n"
391 . PMA_generate_common_hidden_inputs($db, $table)
392 . '<input type="hidden" name="do" value="deleteCrap">' . "\n"
393 . '<input type="hidden" name="chpage" value="' . $chpage . '">' . "\n"
399 . '<input type="submit" value="' . $strGo . '">' . "\n"
403 // ------------------------------------
404 // d i s p l a y p d f s c h e m a
405 // ------------------------------------
409 ||
$do == 'choosepage'
410 ||
($do == 'createpage' && isset($chpage)))) {
412 <form method
="post" action
="pdf_schema.php3">
413 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
414 <input type
="hidden" name
="pdf_page_number" value
="<?php echo $chpage; ?>" />
415 <?php
echo $strDisplayPDF; ?
> 
;:<br
/>
416 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
417 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
418 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" />
419 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
420 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
421 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
422 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
423 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
><br
/>
424 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
425 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
> <br
/>
426 <?php
echo $strShowDatadictAs; ?
>
427 <select name
="orientation">
428 <option value
="L"><?php
echo $strLandscape;?
></option
>
429 <option value
="P"><?php
echo $strPortrait;?
></option
>
431  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
435 } // end if ($cfgRelation['pdfwork'])
439 * Displays the footer
442 require('./footer.inc.php3');