for Loic
[phpmyadmin/crack.git] / db_details_structure.php3
blob6e6b6055449a75090e5e45c1c82aa4f765800cb2
1 <?php
2 /* $Id$ */
5 /**
6 * Prepares the tables list if the user where not redirected to this script
7 * because there is no table in the database ($is_info is TRUE)
8 */
9 if (empty($is_info)) {
10 include('./db_details_common.php3');
11 $url_query .= '&amp;goto=db_details_structure.php3';
13 // Drops/deletes multiple tables if required
14 if ((!empty($submit_mult) && isset($selected_tbl))
15 || isset($mult_btn)) {
16 $action = 'db_details_structure.php3';
17 include('./mult_submits.inc.php3');
20 // Gets the database structure
21 $sub_part = '_structure';
22 include('./db_details_db_info.php3');
23 echo "\n";
27 /**
28 * Settings for relations stuff
30 require('./libraries/relation.lib.php3');
31 $cfgRelation = PMA_getRelationsParam();
35 /**
36 * Displays the tables list
40 <!-- TABLE LIST -->
42 <?php
43 // 1. No tables
44 if ($num_tables == 0) {
45 echo $strNoTablesFound . "\n";
48 // 2. Shows table informations on mysql >= 3.23.03 - staybyte - 11 June 2001
49 else if (PMA_MYSQL_INT_VERSION >= 32303) {
51 <form method="post" action="db_details_structure.php3" name="tablesForm">
52 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
53 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
54 <input type="hidden" name="server" value="<?php echo $server; ?>" />
55 <input type="hidden" name="db" value="<?php echo $db; ?>" />
57 <table border="<?php echo $cfg['Border']; ?>">
58 <tr>
59 <td></td>
60 <th>&nbsp;<?php echo ucfirst($strTable); ?>&nbsp;</th>
61 <th colspan="6"><?php echo ucfirst($strAction); ?></th>
62 <th><?php echo ucfirst($strRecords); ?></th>
63 <th><?php echo ucfirst($strType); ?></th>
64 <?php
65 if ($cfg['ShowStats']) {
66 echo '<th>' . ucfirst($strSize) . '</th>';
68 echo "\n";
70 </tr>
71 <?php
72 $i = $sum_entries = 0;
73 (double) $sum_size = 0;
74 $checked = (!empty($checkall) ? ' checked="checked"' : '');
75 while (list($keyname, $sts_data) = each($tables)) {
76 $table = $sts_data['Name'];
77 $table_encoded = urlencode($table);
78 $table_name = htmlspecialchars($table);
80 // Sets parameters for links
81 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
82 $bgcolor = ($i++ % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
83 echo "\n";
85 <tr>
86 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
87 <input type="checkbox" name="selected_tbl[]" value="<?php echo $table_encoded; ?>" id="checkbox_tbl_<?php echo $i; ?>"<?php echo $checked; ?> />
88 </td>
89 <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
90 &nbsp;<b><label for="checkbox_tbl_<?php echo $i; ?>"><?php echo $table_name; ?></label>&nbsp;</b>&nbsp;
91 </td>
92 <td bgcolor="<?php echo $bgcolor; ?>">
93 <?php
94 if (!empty($sts_data['Rows'])) {
95 echo '<a href="sql.php3?' . $tbl_url_query . '&amp;sql_query='
96 . urlencode('SELECT * FROM ' . PMA_backquote($table))
97 . '&amp;pos=0">' . $strBrowse . '</a>';
98 } else {
99 echo $strBrowse;
102 </td>
103 <td bgcolor="<?php echo $bgcolor; ?>">
104 <?php
105 if (!empty($sts_data['Rows'])) {
106 echo '<a href="tbl_select.php3?' . $tbl_url_query . '">'
107 . $strSelect . '</a>';
108 } else {
109 echo $strSelect;
112 </td>
113 <td bgcolor="<?php echo $bgcolor; ?>">
114 <a href="tbl_change.php3?<?php echo $tbl_url_query; ?>">
115 <?php echo $strInsert; ?></a>
116 </td>
117 <td bgcolor="<?php echo $bgcolor; ?>">
118 <a href="tbl_properties_structure.php3?<?php echo $tbl_url_query; ?>">
119 <?php echo $strProperties; ?></a>
120 </td>
121 <td bgcolor="<?php echo $bgcolor; ?>">
122 <a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table))); ?>"
123 onclick="return confirmLink(this, 'DROP TABLE <?php echo PMA_jsFormat($table); ?>')">
124 <?php echo $strDrop; ?></a>
125 </td>
126 <td bgcolor="<?php echo $bgcolor; ?>">
127 <?php
128 if (!empty($sts_data['Rows'])) {
129 echo '<a href="sql.php3?' . $tbl_url_query
130 . '&amp;sql_query=';
131 if (PMA_MYSQL_INT_VERSION >= 40000) {
132 echo urlencode('TRUNCATE ' . PMA_backquote($table))
133 . '&amp;zero_rows='
134 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table)))
135 . '" onclick="return confirmLink(this, \'TRUNCATE ';
136 } else {
137 echo urlencode('DELETE FROM ' . PMA_backquote($table))
138 . '&amp;zero_rows='
139 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table)))
140 . '" onclick="return confirmLink(this, \'DELETE FROM ';
142 echo PMA_jsFormat($table) . '\')">' . $strEmpty . '</a>';
143 } else {
144 echo $strEmpty;
147 </td>
148 <?php
149 echo "\n";
151 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
152 // statistics whatever is the table type
153 if (isset($sts_data['Rows'])) {
154 // MyISAM, ISAM or Heap table: Row count, data size and index size
155 // is accurate.
156 if (isset($sts_data['Type']) && ereg('^(MyISAM|ISAM|HEAP)$', $sts_data['Type'])) {
157 if ($cfg['ShowStats']) {
158 $tblsize = doubleval($sts_data['Data_length']) + doubleval($sts_data['Index_length']);
159 $sum_size += $tblsize;
160 list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
162 $sum_entries += $sts_data['Rows'];
163 $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
166 // InnoDB table: Row count is not accurate but data and index
167 // sizes are.
168 else if (isset($sts_data['Type']) && $sts_data['Type'] == 'InnoDB') {
169 if ($cfg['ShowStats']) {
170 $tblsize = $sts_data['Data_length'] + $sts_data['Index_length'];
171 $sum_size += $tblsize;
172 list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
174 $display_rows = '&nbsp;-&nbsp;';
177 // Merge or BerkleyDB table: Only row count is accurate.
178 else if (isset($sts_data['Type']) && ereg('^(MRG_MyISAM|BerkeleyDB)$', $sts_data['Type'])) {
179 if ($cfg['ShowStats']) {
180 $formated_size = '&nbsp;-&nbsp;';
181 $unit = '';
183 $sum_entries += $sts_data['Rows'];
184 $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
187 // Unknown table type.
188 else {
189 if ($cfg['ShowStats']) {
190 $formated_size = 'unknown';
191 $unit = '';
193 $display_rows = 'unknown';
196 <td align="right" bgcolor="<?php echo $bgcolor; ?>">
197 <?php
198 echo "\n" . ' ' . $display_rows . "\n";
200 </td>
201 <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
202 &nbsp;<?php echo (isset($sts_data['Type']) ? $sts_data['Type'] : '&nbsp;'); ?>&nbsp;
203 </td>
204 <?php
205 if ($cfg['ShowStats']) {
206 echo "\n";
208 <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
209 &nbsp;&nbsp;
210 <a href="tbl_properties_structure.php3?<?php echo $tbl_url_query; ?>#showusage"><?php echo $formated_size . ' ' . $unit; ?></a>
211 </td>
212 <?php
213 echo "\n";
214 } // end if
215 } else {
217 <td colspan="3" align="center" bgcolor="<?php echo $bgcolor; ?>">
218 <?php echo $strInUse . "\n"; ?>
219 </td>
220 <?php
222 echo "\n";
224 </tr>
225 <?php
227 // Show Summary
228 if ($cfg['ShowStats']) {
229 list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
231 echo "\n";
233 <tr>
234 <td></td>
235 <th align="center" nowrap="nowrap">
236 &nbsp;<b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b>&nbsp;
237 </th>
238 <th colspan="6" align="center">
239 <b><?php echo $strSum; ?></b>
240 </th>
241 <th align="right" nowrap="nowrap">
242 <b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b>
243 </th>
244 <th align="center">
245 <b>--</b>
246 </th>
247 <?php
248 if ($cfg['ShowStats']) {
249 echo "\n";
251 <th align="right" nowrap="nowrap">
252 &nbsp;
253 <b><?php echo $sum_formated . ' ' . $unit; ?></b>
254 </th>
255 <?php
257 echo "\n";
259 </tr>
261 <?php
262 // Check all tables url
263 $checkall_url = 'db_details_structure.php3'
264 . '?lang=' . $lang
265 . '&amp;convcharset=' . $convcharset
266 . '&amp;server=' . $server
267 . '&amp;db=' . urlencode($db);
268 echo "\n";
270 <tr>
271 <td colspan="<?php echo (($cfg['ShowStats']) ? '11' : '10'); ?>" valign="bottom">
272 <img src="./images/arrow_<?php echo $text_dir; ?>.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
273 <a href="<?php echo $checkall_url; ?>&amp;checkall=1" onclick="setCheckboxes('tablesForm', true); return false;">
274 <?php echo $strCheckAll; ?></a>
275 &nbsp;/&nbsp;
276 <a href="<?php echo $checkall_url; ?>" onclick="setCheckboxes('tablesForm', false); return false;">
277 <?php echo $strUncheckAll; ?></a>
278 &nbsp;&nbsp;&nbsp;
279 <img src="./images/spacer.gif" border="0" width="38" height="1" alt="" />
280 <select name="submit_mult" dir="ltr" onchange="this.form.submit();">
281 <?php
282 echo "\n";
283 echo ' <option value="' . $strWithChecked . '" selected="selected">'
284 . $strWithChecked . '</option>' . "\n";
285 echo ' <option value="' . $strDrop . '" >'
286 . $strDrop . '</option>' . "\n";
287 echo ' <option value="' . $strEmpty . '" >'
288 . $strEmpty . '</option>' . "\n";
289 echo ' <option value="' . $strPrintView . '" >'
290 . $strPrintView . '</option>' . "\n";
291 echo ' <option value="' . $strOptimizeTable . '" >'
292 . $strOptimizeTable . '</option>' . "\n";
293 echo ' <option value="' . $strRepairTable . '" >'
294 . $strRepairTable . '</option>' . "\n";
296 </select>
297 <script type="text/javascript" language="javascript">
298 <!--
299 // Fake js to allow the use of the <noscript> tag
300 //-->
301 </script>
302 <noscript>
303 <input type="submit" value="<?php echo $strGo; ?>" />
304 </noscript>
305 </td>
306 </tr>
307 </table>
309 </form>
310 <?php
311 } // end case mysql >= 3.23.03
313 // 3. Shows tables list mysql < 3.23.03
314 else {
315 $i = 0;
316 echo "\n";
318 <form action="db_details_structure.php3">
319 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
320 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
321 <input type="hidden" name="server" value="<?php echo $server; ?>" />
322 <input type="hidden" name="db" value="<?php echo $db; ?>" />
324 <table border="<?php echo $cfg['Border']; ?>">
325 <tr>
326 <td></td>
327 <th>&nbsp;<?php echo ucfirst($strTable); ?>&nbsp;</th>
328 <th colspan="6"><?php echo ucfirst($strAction); ?></th>
329 <th><?php echo ucfirst($strRecords); ?></th>
330 </tr>
331 <?php
332 $checked = (!empty($checkall) ? ' checked="checked"' : '');
333 while ($i < $num_tables) {
334 $table = $tables[$i];
335 $table_encoded = urlencode($table);
336 $table_name = htmlspecialchars($table);
338 // Sets parameters for links
339 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
340 $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
341 echo "\n";
343 <tr>
344 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
345 <input type="checkbox" name="selected_tbl[]" value="<?php echo $table_encoded; ?>" id="checkbox_tbl_<?php echo $i; ?>"<?php echo $checked; ?> />
346 </td>
347 <td bgcolor="<?php echo $bgcolor; ?>" class="data">
348 <b>&nbsp;<label for="checkbox_tbl_<?php echo $i; ?>"><?php echo $table_name; ?></label>&nbsp;</b>
349 </td>
350 <td bgcolor="<?php echo $bgcolor; ?>">
351 <a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table)); ?>&amp;pos=0"><?php echo $strBrowse; ?></a>
352 </td>
353 <td bgcolor="<?php echo $bgcolor; ?>">
354 <a href="tbl_select.php3?<?php echo $tbl_url_query; ?>"><?php echo $strSelect; ?></a>
355 </td>
356 <td bgcolor="<?php echo $bgcolor; ?>">
357 <a href="tbl_change.php3?<?php echo $tbl_url_query; ?>"><?php echo $strInsert; ?></a>
358 </td>
359 <td bgcolor="<?php echo $bgcolor; ?>">
360 <a href="tbl_properties.php3?<?php echo $tbl_url_query; ?>"><?php echo $strProperties; ?></a>
361 </td>
362 <td bgcolor="<?php echo $bgcolor; ?>">
363 <a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, $table_name)); ?>"><?php echo $strDrop; ?></a>
364 </td>
365 <td bgcolor="<?php echo $bgcolor; ?>">
366 <a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;sql_query=<?php echo urlencode('DELETE FROM ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenEmptied, $table_name)); ?>"><?php echo $strEmpty; ?></a>
367 </td>
368 <td align="right" bgcolor="<?php echo $bgcolor; ?>">
369 <?php PMA_countRecords($db, $table); echo "\n"; ?>
370 </td>
371 </tr>
372 <?php
373 $i++;
374 } // end while
375 echo "\n";
377 // Check all tables url
378 $checkall_url = 'db_details_structure.php3'
379 . '?lang=' . $lang
380 . '&amp;convcharset=' . $convcharset
381 . '&amp;server=' . $server
382 . '&amp;db=' . urlencode($db);
384 <tr>
385 <td colspan="9">
386 <img src="./images/arrow_<?php echo $text_dir; ?>.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
387 <a href="<?php echo $checkall_url; ?>&amp;checkall=1" onclick="setCheckboxes('tablesForm', true); return false;">
388 <?php echo $strCheckAll; ?></a>
389 &nbsp;/&nbsp;
390 <a href="<?php echo $checkall_url; ?>" onclick="setCheckboxes('tablesForm', false); return false;">
391 <?php echo $strUncheckAll; ?></a>
392 </td>
393 </tr>
395 <tr>
396 <td colspan="9">
397 <img src="./images/spacer.gif" border="0" width="38" height="1" alt="" />
398 <i><?php echo $strWithChecked; ?></i>&nbsp;&nbsp;
399 <input type="submit" name="submit_mult" value="<?php echo $strDrop; ?>" />
400 &nbsp;<?php $strOr . "\n"; ?>&nbsp;
401 <input type="submit" name="submit_mult" value="<?php echo $strEmpty; ?>" />
402 </td>
403 </tr>
404 </table>
406 </form>
407 <?php
408 } // end case mysql < 3.23.03
410 echo "\n";
412 <hr />
415 <?php
417 * Work on the database
420 <!-- DATABASE WORK -->
421 <ul>
423 <?php
424 if ($num_tables > 0) {
426 <!-- Printable view of a table -->
427 <li>
428 <div style="margin-bottom: 10px"><a href="db_printview.php3?<?php echo $url_query; ?>"><?php echo $strPrintView; ?></a></div>
429 </li>
430 <?php
431 } // end if
434 <!-- Create a new table -->
435 <li>
436 <form method="post" action="tbl_create.php3"
437 onsubmit="return (emptyFormElements(this, 'table') && checkFormElementInRange(this, 'num_fields', 1))">
438 <input type="hidden" name="server" value="<?php echo $server; ?>" />
439 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
440 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
441 <input type="hidden" name="db" value="<?php echo $db; ?>" />
442 <?php
443 echo ' ' . sprintf($strCreateNewTable, htmlspecialchars($db)) . '&nbsp;:<br />' . "\n";
444 echo ' ' . $strName . '&nbsp;:&nbsp;' . "\n";
445 echo ' ' . '<input type="text" name="table" maxlength="64" class="textfield" />' . "\n";
446 echo ' ' . '<br />' . "\n";
447 echo ' ' . $strFields . '&nbsp;:&nbsp;' . "\n";
448 echo ' ' . '<input type="text" name="num_fields" size="2" class="textfield" />' . "\n";
449 echo ' ' . '&nbsp;<input type="submit" value="' . $strGo . '" />' . "\n";
451 </form>
452 </li>
454 <?php
455 if ($num_tables > 0
456 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
457 echo ' <li>' . "\n";
458 echo ' <div style="margin-bottom: 10px">' . "\n";
459 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
460 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php3?' . $url_query . '">';
461 echo ' ' . sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
462 echo ' </div>' . "\n";
463 echo ' </li>' . "\n";
464 } // end if
466 // is this OK to check for 'class' support?
467 if ($cfgRelation['pdfwork'] && $num_tables > 0) {
468 $takeaway = $url_query . '&amp;table=' . urlencode($table);
470 <!-- Work on PDF Pages -->
471 <li>
472 <div style="margin-bottom: 10px"><a href="pdf_pages.php3?<?php echo $takeaway; ?>"><?php echo $strEditPDFPages; ?></a></div>
473 </li>
475 <!-- PDF schema -->
476 <?php
477 // We only show this if we find something in the new pdf_pages table
478 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
479 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
480 $test_rs = PMA_query_as_cu($test_query);
481 if ($test_rs && mysql_num_rows($test_rs) > 0) {
482 echo "\n";
484 <li>
485 <form method="post" action="pdf_schema.php3">
486 <input type="hidden" name="server" value="<?php echo $server; ?>" />
487 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
488 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
489 <input type="hidden" name="db" value="<?php echo $db; ?>" />
490 <?php echo $strDisplayPDF; ?>&nbsp;:<br />
491 <?php echo $strPageNumber; ?>&nbsp;
492 <select name="pdf_page_number">
493 <?php
494 while ($pages = @PMA_mysql_fetch_array($test_rs)) {
495 echo "\n" . ' '
496 . '<option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>';
497 } // end while
498 echo "\n";
500 </select><br />
501 <input type="checkbox" name="show_grid" id="show_grid_opt" />
502 <label for="show_grid_opt"><?php echo $strShowGrid; ?></label><br />
503 <input type="checkbox" name="show_color" id="show_color_opt" checked="checked" />
504 <label for="show_color_opt"><?php echo $strShowColor; ?></label><br />
505 <input type="checkbox" name="show_table_dimension" id="show_table_dim_opt" />
506 <label for="show_table_dim_opt"><?php echo $strShowTableDimension; ?></label><br />
507 <input type="checkbox" name="all_tab_same_wide" id="all_tab_same_wide" />
508 <label for="all_tab_same_wide"><?php echo $strAllTableSameWidth; ?></label>
509 &nbsp;&nbsp;<input type="submit" value="<?php echo $strGo; ?>" />
510 </form>
511 </li>
512 <?php
513 } // end if
514 } // end if
516 echo "\n" . '</ul>';
520 * Displays the footer
522 echo "\n";
523 require('./footer.inc.php3');