Remove extra wrapping of jQuery objects
[phpmyadmin/ammar_yasir.git] / db_datadict.php
blobb760a27fc7e56333e034f42a06f78065765eeada
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 /**
9 * Gets the variables sent or posted to this script, then displays headers
11 require_once './libraries/common.inc.php';
13 if (!isset($selected_tbl)) {
14 require_once './libraries/header.inc.php';
18 /**
19 * Gets the relations settings
21 $cfgRelation = PMA_getRelationsParam();
23 require_once './libraries/transformations.lib.php';
26 /**
27 * Check parameters
29 PMA_checkParameters(array('db'));
31 /**
32 * Defines the url to return to in case of error in a sql statement
34 if (strlen($table)) {
35 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
36 } else {
37 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
40 if ($cfgRelation['commwork']) {
41 $comment = PMA_getDbComment($db);
43 /**
44 * Displays DB comment
46 if ($comment) {
48 <p> <?php echo __('Database comment: '); ?>
49 <i><?php echo htmlspecialchars($comment); ?></i></p>
50 <?php
51 } // end if
54 /**
55 * Selects the database and gets tables names
57 PMA_DBI_select_db($db);
58 $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
60 $count = 0;
61 while ($row = PMA_DBI_fetch_assoc($rowset)) {
62 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
63 $table = $row[$myfieldname];
64 $comments = PMA_getComments($db, $table);
66 echo '<div>' . "\n";
68 echo '<h2>' . $table . '</h2>' . "\n";
70 /**
71 * Gets table informations
73 // The 'show table' statement works correct since 3.23.03
74 $num_rows = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_ROWS');
75 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
77 /**
78 * Gets table keys and retains them
81 PMA_DBI_select_db($db);
82 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
83 $primary = '';
84 $indexes = array();
85 $lastIndex = '';
86 $indexes_info = array();
87 $indexes_data = array();
88 $pk_array = array(); // will be use to emphasis prim. keys in the table
89 // view
90 while ($row = PMA_DBI_fetch_assoc($result)) {
91 // Backups the list of primary keys
92 if ($row['Key_name'] == 'PRIMARY') {
93 $primary .= $row['Column_name'] . ', ';
94 $pk_array[$row['Column_name']] = 1;
96 // Retains keys informations
97 if ($row['Key_name'] != $lastIndex){
98 $indexes[] = $row['Key_name'];
99 $lastIndex = $row['Key_name'];
101 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
102 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
103 if (isset($row['Cardinality'])) {
104 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
106 // I don't know what does following column mean....
107 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
109 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
111 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
112 if (isset($row['Sub_part'])) {
113 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
116 } // end while
117 if ($result) {
118 PMA_DBI_free_result($result);
123 * Gets columns properties
125 $result = PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
126 $fields_cnt = PMA_DBI_num_rows($result);
128 if (PMA_MYSQL_INT_VERSION < 50025) {
129 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
130 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
131 // and SHOW CREATE TABLE says NOT NULL
132 // http://bugs.mysql.com/20910.
134 $show_create_table = PMA_DBI_fetch_value(
135 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
136 0, 1);
137 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
140 // Check if we can use Relations (Mike Beck)
141 if (!empty($cfgRelation['relation'])) {
142 // Find which tables are related with the current one and write it in
143 // an array
144 $res_rel = PMA_getForeigners($db, $table);
146 if (count($res_rel) > 0) {
147 $have_rel = TRUE;
148 } else {
149 $have_rel = FALSE;
151 } else {
152 $have_rel = FALSE;
153 } // end if
157 * Displays the comments of the table if MySQL >= 3.23
159 if (!empty($show_comment)) {
160 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
164 * Displays the table structure
168 <table width="100%" class="print">
169 <tr><th width="50"><?php echo __('Column'); ?></th>
170 <th width="80"><?php echo __('Type'); ?></th>
171 <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
172 <th width="40"><?php echo __('Null'); ?></th>
173 <th width="70"><?php echo __('Default'); ?></th>
174 <?php /* <th width="50"><?php echo __('Extra'); ?></th>*/ ?>
175 <?php
176 if ($have_rel) {
177 echo ' <th>' . __('Links to') . '</th>' . "\n";
179 echo ' <th>' . __('Comments') . '</th>' . "\n";
180 if ($cfgRelation['mimework']) {
181 echo ' <th>MIME</th>' . "\n";
184 </tr>
185 <?php
186 $odd_row = true;
187 while ($row = PMA_DBI_fetch_assoc($result)) {
189 if ($row['Null'] == '') {
190 $row['Null'] = 'NO';
192 $type = $row['Type'];
193 // reformat mysql query output
194 // set or enum types: slashes single quotes inside options
195 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
196 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
197 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
198 $type_nowrap = '';
200 $binary = 0;
201 $unsigned = 0;
202 $zerofill = 0;
203 } else {
204 $binary = stristr($row['Type'], 'binary');
205 $unsigned = stristr($row['Type'], 'unsigned');
206 $zerofill = stristr($row['Type'], 'zerofill');
207 $type_nowrap = ' nowrap="nowrap"';
208 $type = preg_replace('@BINARY@i', '', $type);
209 $type = preg_replace('@ZEROFILL@i', '', $type);
210 $type = preg_replace('@UNSIGNED@i', '', $type);
211 if (empty($type)) {
212 $type = ' ';
215 $attribute = ' ';
216 if ($binary) {
217 $attribute = 'BINARY';
219 if ($unsigned) {
220 $attribute = 'UNSIGNED';
222 if ($zerofill) {
223 $attribute = 'UNSIGNED ZEROFILL';
225 if (!isset($row['Default'])) {
226 if ($row['Null'] != 'NO') {
227 $row['Default'] = '<i>NULL</i>';
229 } else {
230 $row['Default'] = htmlspecialchars($row['Default']);
232 $field_name = htmlspecialchars($row['Field']);
234 if (PMA_MYSQL_INT_VERSION < 50025
235 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
236 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
237 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
238 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
239 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
240 // the latter.
242 * @todo merge this logic with the one in tbl_structure.php
243 * or move it in a function similar to PMA_DBI_get_columns_full()
244 * but based on SHOW CREATE TABLE because information_schema
245 * cannot be trusted in this case (MySQL bug)
247 $row['Null'] = 'NO';
250 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
251 <td nowrap="nowrap">
252 <?php
253 if (isset($pk_array[$row['Field']])) {
254 echo '<u>' . $field_name . '</u>';
255 } else {
256 echo $field_name;
259 </td>
260 <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
261 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $attribute; ?></td>*/ ?>
262 <td><?php echo (($row['Null'] == 'NO') ? __('No') : __('Yes')); ?></td>
263 <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
264 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
265 <?php
266 if ($have_rel) {
267 echo ' <td>';
268 if (isset($res_rel[$field_name])) {
269 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
271 echo '</td>' . "\n";
273 echo ' <td>';
274 if (isset($comments[$field_name])) {
275 echo htmlspecialchars($comments[$field_name]);
277 echo '</td>' . "\n";
278 if ($cfgRelation['mimework']) {
279 $mime_map = PMA_getMIME($db, $table, true);
281 echo ' <td>';
282 if (isset($mime_map[$field_name])) {
283 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
285 echo '</td>' . "\n";
288 </tr>
289 <?php
290 } // end while
291 PMA_DBI_free_result($result);
292 $count++;
294 </table>
295 </div>
296 <?php
297 } //ends main while
300 * Displays the footer
303 <script type="text/javascript">
304 //<![CDATA[
305 function printPage()
307 document.getElementById('print').style.visibility = 'hidden';
308 // Do print the page
309 if (typeof(window.print) != 'undefined') {
310 window.print();
312 document.getElementById('print').style.visibility = '';
314 //]]>
315 </script>
316 <?php
317 echo '<br /><br /><input type="button" id="print" value="' . __('Print') . '" onclick="printPage()" />';
319 require './libraries/footer.inc.php';