Cleaned up the logout script
[openemr.git] / phpmyadmin / db_structure.php
blobed5a481518838e15410e20206d6b0482d11a217d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
11 require_once 'libraries/common.inc.php';
13 /**
14 * Function implementations for this script
16 require_once 'libraries/structure.lib.php';
18 $response = PMA_Response::getInstance();
19 $header = $response->getHeader();
20 $scripts = $header->getScripts();
21 $scripts->addFile('db_structure.js');
22 $scripts->addFile('tbl_change.js');
23 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
25 $post_params = array(
26 'error',
27 'is_info',
28 'message',
29 'mult_btn',
30 'selected_tbl',
31 'submit_mult'
33 foreach ($post_params as $one_post_param) {
34 if (isset($_POST[$one_post_param])) {
35 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
38 /**
39 * Prepares the tables list if the user where not redirected to this script
40 * because there is no table in the database ($is_info is true)
42 if (empty($_POST['is_info'])) {
43 // Drops/deletes/etc. multiple tables if required
44 if ((!empty($_POST['submit_mult']) && isset($_POST['selected_tbl']))
45 || isset($_POST['mult_btn'])
46 ) {
47 $action = 'db_structure.php';
48 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
50 // see bug #2794840; in this case, code path is:
51 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
52 // -> db_structure.php and if we got an error on the multi submit,
53 // we must display it here and not call again mult_submits.inc.php
54 if (! isset($_POST['error']) || false === $_POST['error']) {
55 include 'libraries/mult_submits.inc.php';
57 if (empty($_POST['message'])) {
58 $_POST['message'] = PMA_Message::success();
61 include 'libraries/db_common.inc.php';
62 $url_query .= '&amp;goto=db_structure.php';
64 // Gets the database structure
65 $sub_part = '_structure';
66 include 'libraries/db_info.inc.php';
68 if (!PMA_DRIZZLE) {
69 include_once 'libraries/replication.inc.php';
70 } else {
71 $server_slave_status = false;
75 require_once 'libraries/bookmark.lib.php';
77 require_once 'libraries/mysql_charsets.lib.php';
78 $db_collation = PMA_getDbCollation($db);
80 $titles = PMA_Util::buildActionTitles();
82 // 1. No tables
84 if ($num_tables == 0) {
85 $response->addHTML(
86 '<p>' . __('No tables found in database') . '</p>' . "\n"
88 if (empty($db_is_information_schema)) {
89 ob_start();
90 include 'libraries/display_create_table.lib.php';
91 $content = ob_get_contents();
92 ob_end_clean();
93 $response->addHTML($content);
94 unset($content);
95 } // end if (Create Table dialog)
96 exit;
99 // else
100 // 2. Shows table informations
103 * Displays the tables list
105 $response->addHTML('<div id="tableslistcontainer">');
106 $_url_params = array(
107 'pos' => $pos,
108 'db' => $db);
110 // Add the sort options if they exists
111 if (isset($_REQUEST['sort'])) {
112 $_url_params['sort'] = $_REQUEST['sort'];
115 if (isset($_REQUEST['sort_order'])) {
116 $_url_params['sort_order'] = $_REQUEST['sort_order'];
119 $response->addHTML(
120 PMA_Util::getListNavigator(
121 $total_num_tables, $pos, $_url_params, 'db_structure.php',
122 'frame_content', $GLOBALS['cfg']['MaxTableList']
126 // tables form
127 $response->addHTML(
128 '<form method="post" action="db_structure.php" '
129 . 'name="tablesForm" id="tablesForm">'
132 $response->addHTML(PMA_generate_common_hidden_inputs($db));
134 $response->addHTML(
135 PMA_TableHeader($db_is_information_schema, $server_slave_status)
138 $i = $sum_entries = 0;
139 $overhead_check = '';
140 $create_time_all = '';
141 $update_time_all = '';
142 $check_time_all = '';
143 $num_columns = $cfg['PropertiesNumColumns'] > 1
144 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
145 : 0;
146 $row_count = 0;
147 $sum_size = (double) 0;
148 $overhead_size = (double) 0;
150 $hidden_fields = array();
151 $odd_row = true;
152 $sum_row_count_pre = '';
154 foreach ($tables as $keyname => $current_table) {
155 // Get valid statistics whatever is the table type
157 $drop_query = '';
158 $drop_message = '';
159 $overhead = '';
161 $table_is_view = false;
162 $table_encoded = urlencode($current_table['TABLE_NAME']);
163 // Sets parameters for links
164 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
165 // do not list the previous table's size info for a view
167 list($current_table, $formatted_size, $unit, $formatted_overhead,
168 $overhead_unit, $overhead_size, $table_is_view, $sum_size)
169 = PMA_getStuffForEngineTypeTable(
170 $current_table, $db_is_information_schema,
171 $is_show_stats, $table_is_view, $sum_size, $overhead_size
174 if (! PMA_Table::isMerge($db, $current_table['TABLE_NAME'])) {
175 $sum_entries += $current_table['TABLE_ROWS'];
178 if (isset($current_table['Collation'])) {
179 $collation = '<dfn title="'
180 . PMA_getCollationDescr($current_table['Collation']) . '">'
181 . $current_table['Collation'] . '</dfn>';
182 } else {
183 $collation = '---';
186 if ($is_show_stats) {
187 if ($formatted_overhead != '') {
188 $overhead = '<a href="tbl_structure.php?'
189 . $tbl_url_query . '#showusage">'
190 . '<span>' . $formatted_overhead . '</span>'
191 . '<span class="unit">' . $overhead_unit . '</span>'
192 . '</a>' . "\n";
193 $overhead_check .=
194 "markAllRows('row_tbl_" . ($i + 1) . "');";
195 } else {
196 $overhead = '-';
198 } // end if
200 unset($showtable);
202 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
203 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
204 $current_table, 'Create_time', $create_time_all
208 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
209 // $showtable might already be set from ShowDbStructureCreation, see above
210 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
211 $current_table, 'Update_time', $update_time_all
215 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
216 // $showtable might already be set from ShowDbStructureCreation, see above
217 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
218 $current_table, 'Check_time', $check_time_all
222 list($alias, $truename) = PMA_getAliasAndTrueName(
223 $tooltip_aliasname, $current_table, $tooltip_truename
226 $i++;
228 $row_count++;
229 if ($table_is_view) {
230 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
231 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
235 * Always activate links for Browse, Search and Empty, even if
236 * the icons are greyed, because
237 * 1. for views, we don't know the number of rows at this point
238 * 2. for tables, another source could have populated them since the
239 * page was generated
241 * I could have used the PHP ternary conditional operator but I find
242 * the code easier to read without this operator.
244 list($browse_table, $search_table, $browse_table_label, $empty_table,
245 $tracking_icon) = PMA_getHtmlForActionLinks(
246 $current_table, $table_is_view, $tbl_url_query,
247 $titles, $truename, $db_is_information_schema, $url_query
250 if (! $db_is_information_schema) {
251 list($drop_query, $drop_message)
252 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
255 if ($num_columns > 0
256 && $num_tables > $num_columns
257 && ($row_count % $num_columns) == 0
259 $row_count = 1;
260 $odd_row = true;
262 $response->addHTML(
263 '</tr></tbody></table>'
266 $response->addHTML(PMA_TableHeader(false, $server_slave_status));
269 list($do, $ignored) = PMA_getServerSlaveStatus(
270 $server_slave_status, $truename
273 list($html_output, $odd_row) = PMA_getHtmlForStructureTableRow(
274 $i, $odd_row, $table_is_view, $current_table,
275 $browse_table_label, $tracking_icon, $server_slave_status,
276 $browse_table, $tbl_url_query, $search_table, $db_is_information_schema,
277 $titles, $empty_table, $drop_query, $drop_message, $collation,
278 $formatted_size, $unit, $overhead,
279 (isset ($create_time) ? $create_time : ''),
280 (isset ($update_time) ? $update_time : ''),
281 (isset ($check_time) ? $check_time : ''),
282 $is_show_stats, $ignored, $do, $colspan_for_structure
284 $response->addHTML($html_output);
286 } // end foreach
288 // Show Summary
289 $response->addHTML('</tbody>');
290 $response->addHTML(
291 PMA_getHtmlBodyForTableSummary(
292 $num_tables, $server_slave_status, $db_is_information_schema, $sum_entries,
293 $db_collation, $is_show_stats, $sum_size, $overhead_size, $create_time_all,
294 $update_time_all, $check_time_all, $sum_row_count_pre
297 $response->addHTML('</table>');
298 //check all
299 $response->addHTML(
300 PMA_getHtmlForCheckAllTables(
301 $pmaThemeImage, $text_dir, $overhead_check,
302 $db_is_information_schema, $hidden_fields
305 $response->addHTML('</form>'); //end of form
307 // display again the table list navigator
308 $response->addHTML(
309 PMA_Util::getListNavigator(
310 $total_num_tables, $pos, $_url_params, 'db_structure.php',
311 'frame_content', $GLOBALS['cfg']['MaxTableList']
315 $response->addHTML('</div><hr />');
318 * Work on the database
320 /* DATABASE WORK */
321 /* Printable view of a table */
322 $response->addHTML(
323 PMA_getHtmlForTablePrintViewLink($url_query)
324 . PMA_getHtmlForDataDictionaryLink($url_query)
327 if (empty($db_is_information_schema)) {
328 ob_start();
329 include 'libraries/display_create_table.lib.php';
330 $content = ob_get_contents();
331 ob_end_clean();
332 $response->addHTML($content);
333 } // end if (Create Table dialog)