Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / tbl_tracking.php
blob3e71694f844a7bc7b78ad851227865dd3c9e54eb
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table tracking page
6 * @package PhpMyAdmin
7 */
9 // Run common work
10 require_once './libraries/common.inc.php';
12 define('TABLE_MAY_BE_ABSENT', true);
13 require './libraries/tbl_common.inc.php';
14 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
15 $url_params['goto'] = 'tbl_tracking.php';;
16 $url_params['back'] = 'tbl_tracking.php';
18 // Init vars for tracking report
19 if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) {
20 $data = PMA_Tracker::getTrackedData(
21 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
24 $selection_schema = false;
25 $selection_data = false;
26 $selection_both = false;
28 if (! isset($_REQUEST['logtype'])) {
29 $_REQUEST['logtype'] = 'schema_and_data';
31 if ($_REQUEST['logtype'] == 'schema') {
32 $selection_schema = true;
33 } elseif ($_REQUEST['logtype'] == 'data') {
34 $selection_data = true;
35 } else {
36 $selection_both = true;
38 if (! isset($_REQUEST['date_from'])) {
39 $_REQUEST['date_from'] = $data['date_from'];
41 if (! isset($_REQUEST['date_to'])) {
42 $_REQUEST['date_to'] = $data['date_to'];
44 if (! isset($_REQUEST['users'])) {
45 $_REQUEST['users'] = '*';
47 $filter_ts_from = strtotime($_REQUEST['date_from']);
48 $filter_ts_to = strtotime($_REQUEST['date_to']);
49 $filter_users = array_map('trim', explode(',', $_REQUEST['users']));
52 // Prepare export
53 if (isset($_REQUEST['report_export'])) {
55 /**
56 * Filters tracking entries
58 * @param array $data the entries to filter
59 * @param string $filter_ts_from "from" date
60 * @param string $filter_ts_to "to" date
61 * @param string $filter_users users
63 * @return array filtered entries
65 function PMA_filter_tracking(
66 $data, $filter_ts_from, $filter_ts_to, $filter_users
67 ) {
68 $tmp_entries = array();
69 $id = 0;
70 foreach ( $data as $entry ) {
71 $timestamp = strtotime($entry['date']);
73 if ($timestamp >= $filter_ts_from
74 && $timestamp <= $filter_ts_to
75 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
76 ) {
77 $tmp_entries[] = array( 'id' => $id,
78 'timestamp' => $timestamp,
79 'username' => $entry['username'],
80 'statement' => $entry['statement']
83 $id++;
85 return($tmp_entries);
88 $entries = array();
89 // Filtering data definition statements
90 if ($_REQUEST['logtype'] == 'schema'
91 || $_REQUEST['logtype'] == 'schema_and_data'
92 ) {
93 $entries = array_merge(
94 $entries,
95 PMA_filter_tracking(
96 $data['ddlog'], $filter_ts_from, $filter_ts_to, $filter_users
101 // Filtering data manipulation statements
102 if ($_REQUEST['logtype'] == 'data'
103 || $_REQUEST['logtype'] == 'schema_and_data'
105 $entries = array_merge(
106 $entries,
107 PMA_filter_tracking(
108 $data['dmlog'], $filter_ts_from, $filter_ts_to, $filter_users
113 // Sort it
114 foreach ($entries as $key => $row) {
115 $ids[$key] = $row['id'];
116 $timestamps[$key] = $row['timestamp'];
117 $usernames[$key] = $row['username'];
118 $statements[$key] = $row['statement'];
121 array_multisort(
122 $timestamps, SORT_ASC, $ids, SORT_ASC, $usernames,
123 SORT_ASC, $statements, SORT_ASC, $entries
128 // Export as file download
129 if (isset($_REQUEST['report_export'])
130 && $_REQUEST['export_type'] == 'sqldumpfile'
132 @ini_set('url_rewriter.tags', '');
134 $dump = "# " . sprintf(
135 __('Tracking report for table `%s`'), htmlspecialchars($_REQUEST['table'])
137 . "\n" . "# " . date('Y-m-d H:i:s') . "\n";
138 foreach ($entries as $entry) {
139 $dump .= $entry['statement'];
141 $filename = 'log_' . htmlspecialchars($_REQUEST['table']) . '.sql';
142 PMA_downloadHeader($filename, 'text/x-sql', strlen($dump));
144 echo $dump;
145 exit();
150 * Gets tables informations
153 echo '<br />';
156 * Actions
159 // Create tracking version
160 if (isset($_REQUEST['submit_create_version'])) {
161 $tracking_set = '';
163 if ($_REQUEST['alter_table'] == true) {
164 $tracking_set .= 'ALTER TABLE,';
166 if ($_REQUEST['rename_table'] == true) {
167 $tracking_set .= 'RENAME TABLE,';
169 if ($_REQUEST['create_table'] == true) {
170 $tracking_set .= 'CREATE TABLE,';
172 if ($_REQUEST['drop_table'] == true) {
173 $tracking_set .= 'DROP TABLE,';
175 if ($_REQUEST['create_index'] == true) {
176 $tracking_set .= 'CREATE INDEX,';
178 if ($_REQUEST['drop_index'] == true) {
179 $tracking_set .= 'DROP INDEX,';
181 if ($_REQUEST['insert'] == true) {
182 $tracking_set .= 'INSERT,';
184 if ($_REQUEST['update'] == true) {
185 $tracking_set .= 'UPDATE,';
187 if ($_REQUEST['delete'] == true) {
188 $tracking_set .= 'DELETE,';
190 if ($_REQUEST['truncate'] == true) {
191 $tracking_set .= 'TRUNCATE,';
193 $tracking_set = rtrim($tracking_set, ',');
195 $versionCreated = PMA_Tracker::createVersion(
196 $GLOBALS['db'],
197 $GLOBALS['table'],
198 $_REQUEST['version'],
199 $tracking_set,
200 PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])
202 if ($versionCreated) {
203 $msg = PMA_Message::success(
204 sprintf(
205 __('Version %1$s was created, tracking for %2$s is active.'),
206 htmlspecialchars($_REQUEST['version']),
207 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
210 $msg->display();
214 // Deactivate tracking
215 if (isset($_REQUEST['submit_deactivate_now'])) {
216 $deactivated = PMA_Tracker::deactivateTracking(
217 $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
219 if ($deactivated) {
220 $msg = PMA_Message::success(
221 sprintf(
222 __('Tracking for %1$s was deactivated at version %2$s.'),
223 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
224 htmlspecialchars($_REQUEST['version'])
227 $msg->display();
231 // Activate tracking
232 if (isset($_REQUEST['submit_activate_now'])) {
233 $activated = PMA_Tracker::activateTracking(
234 $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
236 if ($activated) {
237 $msg = PMA_Message::success(
238 sprintf(
239 __('Tracking for %1$s was activated at version %2$s.'),
240 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
241 htmlspecialchars($_REQUEST['version'])
244 $msg->display();
248 // Export as SQL execution
249 if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'execution') {
250 foreach ($entries as $entry) {
251 $sql_result = $GLOBALS['dbi']->query("/*NOTRACK*/\n" . $entry['statement']);
253 $msg = PMA_Message::success(__('SQL statements executed.'));
254 $msg->display();
257 // Export as SQL dump
258 if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldump') {
259 $new_query = "# "
260 . __('You can execute the dump by creating and using a temporary database. Please ensure that you have the privileges to do so.')
261 . "\n"
262 . "# " . __('Comment out these two lines if you do not need them.') . "\n"
263 . "\n"
264 . "CREATE database IF NOT EXISTS pma_temp_db; \n"
265 . "USE pma_temp_db; \n"
266 . "\n";
268 foreach ($entries as $entry) {
269 $new_query .= $entry['statement'];
271 $msg = PMA_Message::success(
272 __('SQL statements exported. Please copy the dump or execute it.')
274 $msg->display();
276 $db_temp = $db;
277 $table_temp = $table;
279 $db = $table = '';
280 include_once './libraries/sql_query_form.lib.php';
282 PMA_sqlQueryForm($new_query, 'sql');
284 $db = $db_temp;
285 $table = $table_temp;
289 * Schema snapshot
291 if (isset($_REQUEST['snapshot'])) {
292 echo '<h3>' . __('Structure snapshot')
293 . ' [<a href="tbl_tracking.php?' . $url_query . '">' . __('Close')
294 . '</a>]</h3>';
295 $data = PMA_Tracker::getTrackedData(
296 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
299 // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements
300 $drop_create_statements = $data['ddlog'][0]['statement'];
302 if (strstr($data['ddlog'][0]['statement'], 'DROP TABLE')
303 || strstr($data['ddlog'][0]['statement'], 'DROP VIEW')
305 $drop_create_statements .= $data['ddlog'][1]['statement'];
307 // Print SQL code
308 echo PMA_Util::getMessage(
309 sprintf(
310 __('Version %s snapshot (SQL code)'),
311 htmlspecialchars($_REQUEST['version'])
313 $drop_create_statements
316 // Unserialize snapshot
317 $temp = unserialize($data['schema_snapshot']);
318 $columns = $temp['COLUMNS'];
319 $indexes = $temp['INDEXES'];
320 echo '<h3>' . __('Structure') . '</h3>';
321 echo '<table id="tablestructure" class="data">';
322 echo '<thead>';
323 echo '<tr>';
324 echo '<th>' . __('Column') . '</th>';
325 echo '<th>' . __('Type') . '</th>';
326 echo '<th>' . __('Collation') . '</th>';
327 echo '<th>' . __('Null') . '</th>';
328 echo '<th>' . __('Default') . '</th>';
329 echo '<th>' . __('Extra') . '</th>';
330 echo '<th>' . __('Comment') . '</th>';
331 echo '</tr>';
332 echo '</thead>';
333 echo '<tbody>';
334 $style = 'odd';
335 foreach ($columns as $field_index => $field) {
336 echo '<tr class="noclick ' . $style . '">';
337 if ($field['Key'] == 'PRI') {
338 echo '<td><b><u>' . htmlspecialchars($field['Field']) . '</u></b></td>';
339 } else {
340 echo '<td><b>' . htmlspecialchars($field['Field']) . '</b></td>';
342 echo "\n";
343 echo '<td>' . htmlspecialchars($field['Type']) . '</td>';
344 echo '<td>' . htmlspecialchars($field['Collation']) . '</td>';
345 echo '<td>' . (($field['Null'] == 'YES') ? __('Yes') : __('No')) . '</td>';
346 echo '<td>';
347 if (isset($field['Default'])) {
348 $extracted_columnspec = PMA_Util::extractColumnSpec($field['Type']);
349 if ($extracted_columnspec['type'] == 'bit') {
350 // here, $field['Default'] contains something like b'010'
351 echo PMA_Util::convertBitDefaultValue($field['Default']);
352 } else {
353 echo htmlspecialchars($field['Default']);
355 } else {
356 if ($field['Null'] == 'YES') {
357 echo '<i>NULL</i>';
358 } else {
359 echo '<i>' . _pgettext('None for default', 'None') . '</i>';
362 echo '</td>';
363 echo '<td>' . htmlspecialchars($field['Extra']) . '</td>';
364 echo '<td>' . htmlspecialchars($field['Comment']) . '</td>';
365 echo '</tr>';
367 if ($style == 'even') {
368 $style = 'odd';
369 } else {
370 $style = 'even';
374 echo '</tbody>';
375 echo '</table>';
377 if (count($indexes) > 0) {
378 echo '<h3>' . __('Indexes') . '</h3>';
379 echo '<table id="tablestructure_indexes" class="data">';
380 echo '<thead>';
381 echo '<tr>';
382 echo '<th>' . __('Keyname') . '</th>';
383 echo '<th>' . __('Type') . '</th>';
384 echo '<th>' . __('Unique') . '</th>';
385 echo '<th>' . __('Packed') . '</th>';
386 echo '<th>' . __('Column') . '</th>';
387 echo '<th>' . __('Cardinality') . '</th>';
388 echo '<th>' . __('Collation') . '</th>';
389 echo '<th>' . __('Null') . '</th>';
390 echo '<th>' . __('Comment') . '</th>';
391 echo '</tr>';
392 echo '<tbody>';
394 $style = 'odd';
395 foreach ($indexes as $indexes_index => $index) {
396 if ($index['Non_unique'] == 0) {
397 $str_unique = __('Yes');
398 } else {
399 $str_unique = __('No');
401 if ($index['Packed'] != '') {
402 $str_packed = __('Yes');
403 } else {
404 $str_packed = __('No');
407 echo '<tr class="noclick ' . $style . '">';
408 echo '<td><b>' . htmlspecialchars($index['Key_name']) . '</b></td>';
409 echo '<td>' . htmlspecialchars($index['Index_type']) . '</td>';
410 echo '<td>' . $str_unique . '</td>';
411 echo '<td>' . $str_packed . '</td>';
412 echo '<td>' . htmlspecialchars($index['Column_name']) . '</td>';
413 echo '<td>' . htmlspecialchars($index['Cardinality']) . '</td>';
414 echo '<td>' . htmlspecialchars($index['Collation']) . '</td>';
415 echo '<td>' . htmlspecialchars($index['Null']) . '</td>';
416 echo '<td>' . htmlspecialchars($index['Comment']) . '</td>';
417 echo '</tr>';
419 if ($style == 'even') {
420 $style = 'odd';
421 } else {
422 $style = 'even';
425 echo '</tbody>';
426 echo '</table>';
427 } // endif
428 echo '<br /><hr /><br />';
430 // end of snapshot report
433 * Tracking report
435 if (isset($_REQUEST['report'])
436 && (isset($_REQUEST['delete_ddlog']) || isset($_REQUEST['delete_dmlog']))
439 if (isset($_REQUEST['delete_ddlog'])) {
441 // Delete ddlog row data
442 $delete_id = $_REQUEST['delete_ddlog'];
444 // Only in case of valable id
445 if ($delete_id == (int)$delete_id) {
446 unset($data['ddlog'][$delete_id]);
448 $successfullyDeleted = PMA_Tracker::changeTrackingData(
449 $_REQUEST['db'], $_REQUEST['table'],
450 $_REQUEST['version'], 'DDL', $data['ddlog']
452 if ($successfullyDeleted) {
453 $msg = PMA_Message::success(
454 __('Tracking data definition successfully deleted')
456 } else {
457 $msg = PMA_Message::rawError(__('Query error'));
459 $msg->display();
463 if (isset($_REQUEST['delete_dmlog'])) {
465 // Delete dmlog row data
466 $delete_id = $_REQUEST['delete_dmlog'];
468 // Only in case of valable id
469 if ($delete_id == (int)$delete_id) {
470 unset($data['dmlog'][$delete_id]);
472 $successfullyDeleted = PMA_Tracker::changeTrackingData(
473 $_REQUEST['db'], $_REQUEST['table'],
474 $_REQUEST['version'], 'DML', $data['dmlog']
476 if ($successfullyDeleted) {
477 $msg = PMA_Message::success(
478 __('Tracking data manipulation successfully deleted')
480 } else {
481 $msg = PMA_Message::rawError(__('Query error'));
483 $msg->display();
488 if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) {
489 echo '<h3>' . __('Tracking report')
490 . ' [<a href="tbl_tracking.php?' . $url_query . '">' . __('Close')
491 . '</a>]</h3>';
493 echo '<small>' . __('Tracking statements') . ' '
494 . htmlspecialchars($data['tracking']) . '</small><br/>';
495 echo '<br/>';
497 echo '<form method="post" action="tbl_tracking.php'
498 . PMA_generate_common_url(
499 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
501 . '">';
503 $str1 = '<select name="logtype">'
504 . '<option value="schema"'
505 . ($selection_schema ? ' selected="selected"' : '') . '>'
506 . __('Structure only') . '</option>'
507 . '<option value="data"'
508 . ($selection_data ? ' selected="selected"' : ''). '>'
509 . __('Data only') . '</option>'
510 . '<option value="schema_and_data"'
511 . ($selection_both ? ' selected="selected"' : '') . '>'
512 . __('Structure and data') . '</option>'
513 . '</select>';
514 $str2 = '<input type="text" name="date_from" value="'
515 . htmlspecialchars($_REQUEST['date_from']) . '" size="19" />';
516 $str3 = '<input type="text" name="date_to" value="'
517 . htmlspecialchars($_REQUEST['date_to']) . '" size="19" />';
518 $str4 = '<input type="text" name="users" value="'
519 . htmlspecialchars($_REQUEST['users']) . '" />';
520 $str5 = '<input type="hidden" name="list_report" value="1" />'
521 . '<input type="submit" value="' . __('Go') . '" />';
523 printf(
524 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
525 $str1, $str2, $str3, $str4, $str5
528 // Prepare delete link content here
529 $drop_image_or_text = '';
530 if (true == $GLOBALS['cfg']['PropertiesIconic']) {
531 $drop_image_or_text .= PMA_Util::getImage(
532 'b_drop.png', __('Delete tracking data row from report')
535 if ('both' === $GLOBALS['cfg']['PropertiesIconic']
536 || false === $GLOBALS['cfg']['PropertiesIconic']
538 $drop_image_or_text .= __('Delete');
542 * First, list tracked data definition statements
544 $i = 1;
545 if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
546 $msg = PMA_Message::notice(__('No data'));
547 $msg->display();
550 if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
551 echo '<table id="ddl_versions" class="data" width="100%">';
552 echo '<thead>';
553 echo '<tr>';
554 echo '<th width="18">#</th>';
555 echo '<th width="100">' . __('Date') . '</th>';
556 echo '<th width="60">' . __('Username') . '</th>';
557 echo '<th>' . __('Data definition statement') . '</th>';
558 echo '<th>' . __('Delete') . '</th>';
559 echo '</tr>';
560 echo '</thead>';
561 echo '<tbody>';
563 $style = 'odd';
564 foreach ($data['ddlog'] as $entry) {
565 if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
566 $statement = substr(
567 $entry['statement'],
569 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
570 ) . '[...]';
571 } else {
572 $statement = PMA_Util::formatSql(PMA_SQP_parse($entry['statement']));
574 $timestamp = strtotime($entry['date']);
576 if ($timestamp >= $filter_ts_from
577 && $timestamp <= $filter_ts_to
578 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
580 echo '<tr class="noclick ' . $style . '">';
581 echo '<td><small>' . $i . '</small></td>';
582 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
583 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
584 echo '<td>' . $statement . '</td>';
585 echo '<td class="nowrap"><a href="tbl_tracking.php?'
586 . $url_query . '&amp;report=true&amp;version='
587 . $version['version'] . '&amp;delete_ddlog='
588 . ($i - 1) . '">' . $drop_image_or_text
589 . '</a></td>';
590 echo '</tr>';
592 if ($style == 'even') {
593 $style = 'odd';
594 } else {
595 $style = 'even';
597 $i++;
600 echo '</tbody>';
601 echo '</table>';
603 } //endif
605 // Memorize data definition amount
606 $ddlog_count = $i;
609 * Secondly, list tracked data manipulation statements
612 if (($selection_data || $selection_both) && count($data['dmlog']) > 0) {
613 echo '<table id="dml_versions" class="data" width="100%">';
614 echo '<thead>';
615 echo '<tr>';
616 echo '<th width="18">#</th>';
617 echo '<th width="100">' . __('Date') . '</th>';
618 echo '<th width="60">' . __('Username') . '</th>';
619 echo '<th>' . __('Data manipulation statement') . '</th>';
620 echo '<th>' . __('Delete') . '</th>';
621 echo '</tr>';
622 echo '</thead>';
623 echo '<tbody>';
625 $style = 'odd';
626 foreach ($data['dmlog'] as $entry) {
627 if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
628 $statement = substr(
629 $entry['statement'],
631 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
632 ) . '[...]';
633 } else {
634 $statement = PMA_Util::formatSql(PMA_SQP_parse($entry['statement']));
636 $timestamp = strtotime($entry['date']);
638 if ($timestamp >= $filter_ts_from
639 && $timestamp <= $filter_ts_to
640 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
642 echo '<tr class="noclick ' . $style . '">';
643 echo '<td><small>' . $i . '</small></td>';
644 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
645 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
646 echo '<td>' . $statement . '</td>';
647 echo '<td class="nowrap"><a href="tbl_tracking.php?' . $url_query
648 . '&amp;report=true&amp;version=' . $version['version']
649 . '&amp;delete_dmlog=' . ($i - $ddlog_count) . '">'
650 . $drop_image_or_text
651 . '</a></td>';
652 echo '</tr>';
654 if ($style == 'even') {
655 $style = 'odd';
656 } else {
657 $style = 'even';
659 $i++;
662 echo '</tbody>';
663 echo '</table>';
665 echo '</form>';
666 echo '<form method="post" action="tbl_tracking.php'
667 . PMA_generate_common_url(
668 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
670 . '">';
671 printf(
672 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
673 $str1, $str2, $str3, $str4, $str5
676 $str_export1 = '<select name="export_type">'
677 . '<option value="sqldumpfile">' . __('SQL dump (file download)') . '</option>'
678 . '<option value="sqldump">' . __('SQL dump') . '</option>'
679 . '<option value="execution" onclick="alert(\''
680 . PMA_escapeJsString(__('This option will replace your table and contained data.'))
681 .'\')">' . __('SQL execution') . '</option>' . '</select>';
683 $str_export2 = '<input type="hidden" name="report_export" value="1" />'
684 . '<input type="submit" value="' . __('Go') .'" />';
685 echo '</form>';
686 echo '<form class="disableAjax" method="post" action="tbl_tracking.php'
687 . PMA_generate_common_url(
688 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
690 . '">';
691 echo '<input type="hidden" name="logtype" value="'
692 . htmlspecialchars($_REQUEST['logtype']) . '" />';
693 echo '<input type="hidden" name="date_from" value="'
694 . htmlspecialchars($_REQUEST['date_from']) . '" />';
695 echo '<input type="hidden" name="date_to" value="'
696 . htmlspecialchars($_REQUEST['date_to']) . '" />';
697 echo '<input type="hidden" name="users" value="'
698 . htmlspecialchars($_REQUEST['users']) . '" />';
699 echo "<br/>" . sprintf(__('Export as %s'), $str_export1)
700 . $str_export2 . "<br/>";
701 echo '</form>';
702 echo "<br/><br/><hr/><br/>\n";
703 } // end of report
707 * List selectable tables
710 $sql_query = " SELECT DISTINCT db_name, table_name FROM " .
711 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
712 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
713 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "' " .
714 " ORDER BY db_name, table_name";
716 $sql_result = PMA_queryAsControlUser($sql_query);
718 if ($GLOBALS['dbi']->numRows($sql_result) > 0) {
719 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
720 echo '<select name="table">';
721 while ($entries = $GLOBALS['dbi']->fetchArray($sql_result)) {
722 if (PMA_Tracker::isTracked($entries['db_name'], $entries['table_name'])) {
723 $status = ' (' . __('active') . ')';
724 } else {
725 $status = ' (' . __('not active') . ')';
727 if ($entries['table_name'] == $_REQUEST['table']) {
728 $s = ' selected="selected"';
729 } else {
730 $s = '';
732 echo '<option value="' . htmlspecialchars($entries['table_name']) . '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . ' . htmlspecialchars($entries['table_name']) . $status . '</option>' . "\n";
734 echo '</select>';
735 echo '<input type="hidden" name="show_versions_submit" value="1" />';
736 echo '<input type="submit" value="' . __('Show versions') . '" />';
737 echo '</form>';
739 echo '<br />';
742 * List versions of current table
745 $sql_query = " SELECT * FROM " .
746 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
747 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
748 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['db']) . "' ".
749 " AND table_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['table']) ."' ".
750 " ORDER BY version DESC ";
752 $sql_result = PMA_queryAsControlUser($sql_query);
754 $last_version = 0;
755 $maxversion = $GLOBALS['dbi']->fetchArray($sql_result);
756 $last_version = $maxversion['version'];
758 if ($last_version > 0) {
759 echo '<table id="versions" class="data">';
760 echo '<thead>';
761 echo '<tr>';
762 echo '<th>' . __('Database') . '</th>';
763 echo '<th>' . __('Table') . '</th>';
764 echo '<th>' . __('Version') . '</th>';
765 echo '<th>' . __('Created') . '</th>';
766 echo '<th>' . __('Updated') . '</th>';
767 echo '<th>' . __('Status') . '</th>';
768 echo '<th>' . __('Show') . '</th>';
769 echo '</tr>';
770 echo '</thead>';
771 echo '<tbody>';
773 $style = 'odd';
774 $GLOBALS['dbi']->dataSeek($sql_result, 0);
775 while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) {
776 if ($version['tracking_active'] == 1) {
777 $version_status = __('active');
778 } else {
779 $version_status = __('not active');
781 if ($version['version'] == $last_version) {
782 if ($version['tracking_active'] == 1) {
783 $tracking_active = true;
784 } else {
785 $tracking_active = false;
788 echo '<tr class="noclick ' . $style . '">';
789 echo '<td>' . htmlspecialchars($version['db_name']) . '</td>';
790 echo '<td>' . htmlspecialchars($version['table_name']) . '</td>';
791 echo '<td>' . htmlspecialchars($version['version']) . '</td>';
792 echo '<td>' . htmlspecialchars($version['date_created']) . '</td>';
793 echo '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
794 echo '<td>' . $version_status . '</td>';
795 echo '<td><a href="tbl_tracking.php';
796 echo PMA_generate_common_url(
797 $url_params + array('report' => 'true', 'version' => $version['version'])
799 echo '">' . __('Tracking report') . '</a>';
800 echo '| <a href="tbl_tracking.php';
801 echo PMA_generate_common_url(
802 $url_params + array('snapshot' => 'true', 'version' => $version['version'])
804 echo '">' . __('Structure snapshot') . '</a>';
805 echo '</td>';
806 echo '</tr>';
808 if ($style == 'even') {
809 $style = 'odd';
810 } else {
811 $style = 'even';
815 echo '</tbody>';
816 echo '</table>';
818 if ($tracking_active) {
819 echo '<div id="div_deactivate_tracking">';
820 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
821 echo '<fieldset>';
822 echo '<legend>';
823 printf(
824 __('Deactivate tracking for %s'),
825 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
827 echo '</legend>';
828 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
829 echo '<input type="hidden" name="submit_deactivate_now" value="1" />';
830 echo '<input type="submit" value="' . __('Deactivate now') . '" />';
831 echo '</fieldset>';
832 echo '</form>';
833 echo '</div>';
834 } else {
835 echo '<div id="div_activate_tracking">';
836 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
837 echo '<fieldset>';
838 echo '<legend>';
839 printf(
840 __('Activate tracking for %s'),
841 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
843 echo '</legend>';
844 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
845 echo '<input type="hidden" name="submit_activate_now" value="1" />';
846 echo '<input type="submit" value="' . __('Activate now') . '" />';
847 echo '</fieldset>';
848 echo '</form>';
849 echo '</div>';
853 echo '<div id="div_create_version">';
854 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
855 echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
856 echo '<fieldset>';
857 echo '<legend>';
858 printf(
859 __('Create version %1$s of %2$s'),
860 ($last_version + 1),
861 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
863 echo '</legend>';
865 echo '<input type="hidden" name="version" value="' . ($last_version + 1) . '" />';
867 echo '<p>' . __('Track these data definition statements:') . '</p>';
868 echo '<input type="checkbox" name="alter_table" value="true" checked="checked" /> ALTER TABLE<br/>';
869 echo '<input type="checkbox" name="rename_table" value="true" checked="checked" /> RENAME TABLE<br/>';
870 echo '<input type="checkbox" name="create_table" value="true" checked="checked" /> CREATE TABLE<br/>';
871 echo '<input type="checkbox" name="drop_table" value="true" checked="checked" /> DROP TABLE<br/>';
872 echo '<br/>';
873 echo '<input type="checkbox" name="create_index" value="true" checked="checked" /> CREATE INDEX<br/>';
874 echo '<input type="checkbox" name="drop_index" value="true" checked="checked" /> DROP INDEX<br/>';
875 echo '<p>' . __('Track these data manipulation statements:') . '</p>';
876 echo '<input type="checkbox" name="insert" value="true" checked="checked" /> INSERT<br/>';
877 echo '<input type="checkbox" name="update" value="true" checked="checked" /> UPDATE<br/>';
878 echo '<input type="checkbox" name="delete" value="true" checked="checked" /> DELETE<br/>';
879 echo '<input type="checkbox" name="truncate" value="true" checked="checked" /> TRUNCATE<br/>';
881 echo '</fieldset>';
882 echo '<fieldset class="tblFooters">';
884 echo '<input type="hidden" name="submit_create_version" value="1" />';
885 echo '<input type="submit" value="' . __('Create version') . '" />';
886 echo '</fieldset>';
887 echo '</form>';
888 echo '</div>';
890 echo '<br class="clearfloat"/>';