lang
[phpmyadmin/crack.git] / pdf_pages.php3
blob0d77228d2109808640300ec6deb6674447c32e12
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Gets some core libraries
8 */
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
11 require('./db_details_common.php3');
14 /**
15 * Settings for relation stuff
17 require('./libraries/relation.lib.php3');
18 $cfgRelation = PMA_getRelationsParam();
21 /**
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
27 * complain ;-)
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";
32 exit();
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";
38 exit();
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";
44 exit();
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";
49 exit();
52 if ($cfgRelation['pdfwork']) {
53 // Now is the time to work on all changes
54 if (isset($do)) {
55 switch ($do) {
56 case 'choosepage':
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);
68 break;
69 case 'createpage':
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
85 // number of links
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
95 // the schema
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
126 $pos_x = 500;
127 $pos_y = 500;
128 $delta = 50;
129 $delta_mult = 1.34;
130 $direction = "right";
131 reset($all_tables);
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) {
144 case 'right':
145 $pos_x += $delta;
146 $direction = "down";
147 $delta *= $delta_mult;
148 break;
149 case 'down':
150 $pos_y += $delta;
151 $direction = "left";
152 $delta *= $delta_mult;
153 break;
154 case 'left':
155 $pos_x -= $delta;
156 $direction = "up";
157 $delta *= $delta_mult;
158 break;
159 case 'up':
160 $pos_y -= $delta;
161 $direction = "right";
162 $delta *= $delta_mult;
163 break;
164 } // end switch
165 } // end while
166 } // end if there are master tables
168 $chpage = $pdf_page_number;
169 } // end if isset autolayout
171 break;
173 case 'edcoord':
174 for ($i = 0; $i < $c_table_rows; $i++) {
175 $arrvalue = 'c_table_' . $i;
176 $arrvalue = $$arrvalue;
177 if (!isset($arrvalue['x']) || $arrvalue['x'] == '') {
178 $arrvalue['x'] = 0;
180 if (!isset($arrvalue['y']) || $arrvalue['y'] == '') {
181 $arrvalue['y'] = 0;
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;
195 } else {
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;
202 } else {
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);
208 } // end if
209 } // end for
210 break;
211 case 'deleteCrap':
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);
219 break;
220 } // end switch
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()">
243 <?php
244 while ($curr_page = @PMA_mysql_fetch_array($page_rs)) {
245 echo "\n" . ' '
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>';
251 } // end while
252 echo "\n";
254 </select>
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; ?>" />
261 </form>
262 <?php
264 echo "\n";
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; ?>" />
276 </form>
277 <?php
278 // Now if we already have chosen a page number then we should show the
279 // tables involved
280 if (isset($chpage) && $chpage > 0) {
281 echo "\n";
283 <hr />
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" />
290 <table border="0">
291 <tr>
292 <th><?php echo $strTable; ?></th>
293 <th><?php echo $strDelete; ?></th>
294 <th>X</th>
295 <th>Y</th>
296 </tr>
297 <?php
298 if (isset($ctable)) {
299 unset($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);
307 $i = 0;
308 while ($sh_page = @PMA_mysql_fetch_array($page_rs)) {
309 $_mtab = $sh_page['table_name'];
310 $tabExist[$_mtab] = FALSE;
311 echo "\n" . ' <tr ';
312 if ($i % 2 == 0) {
313 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
314 } else {
315 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
317 echo '>';
318 echo "\n" . ' <td>'
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>';
328 } // end while
329 echo "\n" . ' </select>'
330 . "\n" . ' </td>';
331 echo "\n" . ' <td>'
332 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
333 echo "\n" . ' </td>';
334 echo "\n" . ' <td>'
335 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
336 echo "\n" . ' </td>';
337 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>';
341 $i++;
342 } // end while
343 // Do one more empty row
344 echo "\n" . ' <tr ';
345 if ($i % 2 == 0) {
346 echo 'bgcolor="' . $cfg['BgcolorOne'] . '"';
347 } else {
348 echo 'bgcolor="' . $cfg['BgcolorTwo'] . '"';
350 echo '>';
351 echo "\n" . ' <td>'
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>'
358 . "\n" . ' </td>';
359 echo "\n" . ' <td>'
360 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . $strDelete;
361 echo "\n" . ' </td>';
362 echo "\n" . ' <td>'
363 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
364 echo "\n" . ' </td>';
365 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";
374 } // end if
376 // Check if there are tables that need to be deleted,
377 // if there are, ask the user for allowance
378 $_strtrans = '';
379 $_strname = '';
380 $shoot = FALSE;
381 if (!empty($tabExist) && is_array($tabExist)) {
382 while (list($key, $value) = each($tabExist)) {
383 if (!$value) {
384 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . $key . '">' . "\n";
385 $_strname .= '<li>' . $key . '</li>' . "\n";
386 $shoot = TRUE;
389 if ($shoot) {
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"
394 . $strDelOld
395 . '<ul>' . "\n"
396 . $_strname
397 . '</ul>' . "\n"
398 . $_strtrans
399 . '<input type="submit" value="' . $strGo . '">' . "\n"
400 . '</FORM>';
403 // ------------------------------------
404 // d i s p l a y p d f s c h e m a
405 // ------------------------------------
407 if (isset($do)
408 && ($do == 'edcoord'
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; ?>&nbsp;:<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>
430 </select>
431 &nbsp;&nbsp;<input type="submit" value="<?php echo $strGo; ?>" />
432 </form>
433 <?php
434 } // end if
435 } // end if ($cfgRelation['pdfwork'])
439 * Displays the footer
441 echo "\n";
442 require('./footer.inc.php3');