Translated using Weblate (Tamil)
[phpmyadmin.git] / tbl_tracking.php
blobe0fdb22af7e6f846dfb0eb713ab784f516fb8bf8
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 = PMA_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')) {
304 $drop_create_statements .= $data['ddlog'][1]['statement'];
306 // Print SQL code
307 echo PMA_Util::getMessage(
308 sprintf(
309 __('Version %s snapshot (SQL code)'),
310 htmlspecialchars($_REQUEST['version'])
312 $drop_create_statements
315 // Unserialize snapshot
316 $temp = unserialize($data['schema_snapshot']);
317 $columns = $temp['COLUMNS'];
318 $indexes = $temp['INDEXES'];
319 echo '<h3>' . __('Structure') . '</h3>';
320 echo '<table id="tablestructure" class="data">';
321 echo '<thead>';
322 echo '<tr>';
323 echo '<th>' . __('Column') . '</th>';
324 echo '<th>' . __('Type') . '</th>';
325 echo '<th>' . __('Collation') . '</th>';
326 echo '<th>' . __('Null') . '</th>';
327 echo '<th>' . __('Default') . '</th>';
328 echo '<th>' . __('Extra') . '</th>';
329 echo '<th>' . __('Comment') . '</th>';
330 echo '</tr>';
331 echo '</thead>';
332 echo '<tbody>';
333 $style = 'odd';
334 foreach ($columns as $field_index => $field) {
335 echo '<tr class="noclick ' . $style . '">';
336 if ($field['Key'] == 'PRI') {
337 echo '<td><b><u>' . htmlspecialchars($field['Field']) . '</u></b></td>';
338 } else {
339 echo '<td><b>' . htmlspecialchars($field['Field']) . '</b></td>';
341 echo "\n";
342 echo '<td>' . htmlspecialchars($field['Type']) . '</td>';
343 echo '<td>' . htmlspecialchars($field['Collation']) . '</td>';
344 echo '<td>' . (($field['Null'] == 'YES') ? __('Yes') : __('No')) . '</td>';
345 echo '<td>';
346 if (isset($field['Default'])) {
347 $extracted_columnspec = PMA_Util::extractColumnSpec($field['Type']);
348 if ($extracted_columnspec['type'] == 'bit') {
349 // here, $field['Default'] contains something like b'010'
350 echo PMA_Util::convertBitDefaultValue($field['Default']);
351 } else {
352 echo htmlspecialchars($field['Default']);
354 } else {
355 if ($field['Null'] == 'YES') {
356 echo '<i>NULL</i>';
357 } else {
358 echo '<i>' . _pgettext('None for default', 'None') . '</i>';
361 echo '</td>';
362 echo '<td>' . htmlspecialchars($field['Extra']) . '</td>';
363 echo '<td>' . htmlspecialchars($field['Comment']) . '</td>';
364 echo '</tr>';
366 if ($style == 'even') {
367 $style = 'odd';
368 } else {
369 $style = 'even';
373 echo '</tbody>';
374 echo '</table>';
376 if (count($indexes) > 0) {
377 echo '<h3>' . __('Indexes') . '</h3>';
378 echo '<table id="tablestructure_indexes" class="data">';
379 echo '<thead>';
380 echo '<tr>';
381 echo '<th>' . __('Keyname') . '</th>';
382 echo '<th>' . __('Type') . '</th>';
383 echo '<th>' . __('Unique') . '</th>';
384 echo '<th>' . __('Packed') . '</th>';
385 echo '<th>' . __('Column') . '</th>';
386 echo '<th>' . __('Cardinality') . '</th>';
387 echo '<th>' . __('Collation') . '</th>';
388 echo '<th>' . __('Null') . '</th>';
389 echo '<th>' . __('Comment') . '</th>';
390 echo '</tr>';
391 echo '<tbody>';
393 $style = 'odd';
394 foreach ($indexes as $indexes_index => $index) {
395 if ($index['Non_unique'] == 0) {
396 $str_unique = __('Yes');
397 } else {
398 $str_unique = __('No');
400 if ($index['Packed'] != '') {
401 $str_packed = __('Yes');
402 } else {
403 $str_packed = __('No');
406 echo '<tr class="noclick ' . $style . '">';
407 echo '<td><b>' . htmlspecialchars($index['Key_name']) . '</b></td>';
408 echo '<td>' . htmlspecialchars($index['Index_type']) . '</td>';
409 echo '<td>' . $str_unique . '</td>';
410 echo '<td>' . $str_packed . '</td>';
411 echo '<td>' . htmlspecialchars($index['Column_name']) . '</td>';
412 echo '<td>' . htmlspecialchars($index['Cardinality']) . '</td>';
413 echo '<td>' . htmlspecialchars($index['Collation']) . '</td>';
414 echo '<td>' . htmlspecialchars($index['Null']) . '</td>';
415 echo '<td>' . htmlspecialchars($index['Comment']) . '</td>';
416 echo '</tr>';
418 if ($style == 'even') {
419 $style = 'odd';
420 } else {
421 $style = 'even';
424 echo '</tbody>';
425 echo '</table>';
426 } // endif
427 echo '<br /><hr /><br />';
429 // end of snapshot report
432 * Tracking report
434 if (isset($_REQUEST['report'])
435 && (isset($_REQUEST['delete_ddlog']) || isset($_REQUEST['delete_dmlog']))
438 if (isset($_REQUEST['delete_ddlog'])) {
440 // Delete ddlog row data
441 $delete_id = $_REQUEST['delete_ddlog'];
443 // Only in case of valable id
444 if ($delete_id == (int)$delete_id) {
445 unset($data['ddlog'][$delete_id]);
447 $successfullyDeleted = PMA_Tracker::changeTrackingData(
448 $_REQUEST['db'], $_REQUEST['table'],
449 $_REQUEST['version'], 'DDL', $data['ddlog']
451 if ($successfullyDeleted) {
452 $msg = PMA_Message::success(
453 __('Tracking data definition successfully deleted')
455 } else {
456 $msg = PMA_Message::rawError(__('Query error'));
458 $msg->display();
462 if (isset($_REQUEST['delete_dmlog'])) {
464 // Delete dmlog row data
465 $delete_id = $_REQUEST['delete_dmlog'];
467 // Only in case of valable id
468 if ($delete_id == (int)$delete_id) {
469 unset($data['dmlog'][$delete_id]);
471 $successfullyDeleted = PMA_Tracker::changeTrackingData(
472 $_REQUEST['db'], $_REQUEST['table'],
473 $_REQUEST['version'], 'DML', $data['dmlog']
475 if ($successfullyDeleted) {
476 $msg = PMA_Message::success(
477 __('Tracking data manipulation successfully deleted')
479 } else {
480 $msg = PMA_Message::rawError(__('Query error'));
482 $msg->display();
487 if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) {
488 echo '<h3>' . __('Tracking report')
489 . ' [<a href="tbl_tracking.php?' . $url_query . '">' . __('Close')
490 . '</a>]</h3>';
492 echo '<small>' . __('Tracking statements') . ' '
493 . htmlspecialchars($data['tracking']) . '</small><br/>';
494 echo '<br/>';
496 echo '<form method="post" action="tbl_tracking.php'
497 . PMA_generate_common_url(
498 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
500 . '">';
502 $str1 = '<select name="logtype">'
503 . '<option value="schema"'
504 . ($selection_schema ? ' selected="selected"' : '') . '>'
505 . __('Structure only') . '</option>'
506 . '<option value="data"'
507 . ($selection_data ? ' selected="selected"' : ''). '>'
508 . __('Data only') . '</option>'
509 . '<option value="schema_and_data"'
510 . ($selection_both ? ' selected="selected"' : '') . '>'
511 . __('Structure and data') . '</option>'
512 . '</select>';
513 $str2 = '<input type="text" name="date_from" value="'
514 . htmlspecialchars($_REQUEST['date_from']) . '" size="19" />';
515 $str3 = '<input type="text" name="date_to" value="'
516 . htmlspecialchars($_REQUEST['date_to']) . '" size="19" />';
517 $str4 = '<input type="text" name="users" value="'
518 . htmlspecialchars($_REQUEST['users']) . '" />';
519 $str5 = '<input type="hidden" name="list_report" value="1" />'
520 . '<input type="submit" value="' . __('Go') . '" />';
522 printf(
523 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
524 $str1, $str2, $str3, $str4, $str5
527 // Prepare delete link content here
528 $drop_image_or_text = '';
529 if (true == $GLOBALS['cfg']['PropertiesIconic']) {
530 $drop_image_or_text .= PMA_Util::getImage(
531 'b_drop.png', __('Delete tracking data row from report')
534 if ('both' === $GLOBALS['cfg']['PropertiesIconic']
535 || false === $GLOBALS['cfg']['PropertiesIconic']
537 $drop_image_or_text .= __('Delete');
541 * First, list tracked data definition statements
543 $i = 1;
544 if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
545 $msg = PMA_Message::notice(__('No data'));
546 $msg->display();
549 if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
550 echo '<table id="ddl_versions" class="data" width="100%">';
551 echo '<thead>';
552 echo '<tr>';
553 echo '<th width="18">#</th>';
554 echo '<th width="100">' . __('Date') . '</th>';
555 echo '<th width="60">' . __('Username') . '</th>';
556 echo '<th>' . __('Data definition statement') . '</th>';
557 echo '<th>' . __('Delete') . '</th>';
558 echo '</tr>';
559 echo '</thead>';
560 echo '<tbody>';
562 $style = 'odd';
563 foreach ($data['ddlog'] as $entry) {
564 if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
565 $statement = substr(
566 $entry['statement'],
568 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
569 ) . '[...]';
570 } else {
571 $statement = PMA_Util::formatSql(PMA_SQP_parse($entry['statement']));
573 $timestamp = strtotime($entry['date']);
575 if ($timestamp >= $filter_ts_from
576 && $timestamp <= $filter_ts_to
577 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
579 echo '<tr class="noclick ' . $style . '">';
580 echo '<td><small>' . $i . '</small></td>';
581 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
582 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
583 echo '<td>' . $statement . '</td>';
584 echo '<td class="nowrap"><a href="tbl_tracking.php?'
585 . $url_query . '&amp;report=true&amp;version='
586 . $version['version'] . '&amp;delete_ddlog='
587 . ($i - 1) . '">' . $drop_image_or_text
588 . '</a></td>';
589 echo '</tr>';
591 if ($style == 'even') {
592 $style = 'odd';
593 } else {
594 $style = 'even';
596 $i++;
599 echo '</tbody>';
600 echo '</table>';
602 } //endif
604 // Memorize data definition amount
605 $ddlog_count = $i;
608 * Secondly, list tracked data manipulation statements
611 if (($selection_data || $selection_both) && count($data['dmlog']) > 0) {
612 echo '<table id="dml_versions" class="data" width="100%">';
613 echo '<thead>';
614 echo '<tr>';
615 echo '<th width="18">#</th>';
616 echo '<th width="100">' . __('Date') . '</th>';
617 echo '<th width="60">' . __('Username') . '</th>';
618 echo '<th>' . __('Data manipulation statement') . '</th>';
619 echo '<th>' . __('Delete') . '</th>';
620 echo '</tr>';
621 echo '</thead>';
622 echo '<tbody>';
624 $style = 'odd';
625 foreach ($data['dmlog'] as $entry) {
626 if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
627 $statement = substr(
628 $entry['statement'],
630 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
631 ) . '[...]';
632 } else {
633 $statement = PMA_Util::formatSql(PMA_SQP_parse($entry['statement']));
635 $timestamp = strtotime($entry['date']);
637 if ($timestamp >= $filter_ts_from
638 && $timestamp <= $filter_ts_to
639 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
641 echo '<tr class="noclick ' . $style . '">';
642 echo '<td><small>' . $i . '</small></td>';
643 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
644 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
645 echo '<td>' . $statement . '</td>';
646 echo '<td class="nowrap"><a href="tbl_tracking.php?' . $url_query
647 . '&amp;report=true&amp;version=' . $version['version']
648 . '&amp;delete_dmlog=' . ($i - $ddlog_count) . '">'
649 . $drop_image_or_text
650 . '</a></td>';
651 echo '</tr>';
653 if ($style == 'even') {
654 $style = 'odd';
655 } else {
656 $style = 'even';
658 $i++;
661 echo '</tbody>';
662 echo '</table>';
664 echo '</form>';
665 echo '<form method="post" action="tbl_tracking.php'
666 . PMA_generate_common_url(
667 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
669 . '">';
670 printf(
671 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
672 $str1, $str2, $str3, $str4, $str5
675 $str_export1 = '<select name="export_type">'
676 . '<option value="sqldumpfile">' . __('SQL dump (file download)') . '</option>'
677 . '<option value="sqldump">' . __('SQL dump') . '</option>'
678 . '<option value="execution" onclick="alert(\''
679 . PMA_escapeJsString(__('This option will replace your table and contained data.'))
680 .'\')">' . __('SQL execution') . '</option>' . '</select>';
682 $str_export2 = '<input type="hidden" name="report_export" value="1" />'
683 . '<input type="submit" value="' . __('Go') .'" />';
684 echo '</form>';
685 echo '<form class="disableAjax" method="post" action="tbl_tracking.php'
686 . PMA_generate_common_url(
687 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
689 . '">';
690 echo '<input type="hidden" name="logtype" value="'
691 . htmlspecialchars($_REQUEST['logtype']) . '" />';
692 echo '<input type="hidden" name="date_from" value="'
693 . htmlspecialchars($_REQUEST['date_from']) . '" />';
694 echo '<input type="hidden" name="date_to" value="'
695 . htmlspecialchars($_REQUEST['date_to']) . '" />';
696 echo '<input type="hidden" name="users" value="'
697 . htmlspecialchars($_REQUEST['users']) . '" />';
698 echo "<br/>" . sprintf(__('Export as %s'), $str_export1)
699 . $str_export2 . "<br/>";
700 echo '</form>';
701 echo "<br/><br/><hr/><br/>\n";
702 } // end of report
706 * List selectable tables
709 $sql_query = " SELECT DISTINCT db_name, table_name FROM " .
710 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
711 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
712 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "' " .
713 " ORDER BY db_name, table_name";
715 $sql_result = PMA_queryAsControlUser($sql_query);
717 if (PMA_DBI_num_rows($sql_result) > 0) {
718 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
719 echo '<select name="table">';
720 while ($entries = PMA_DBI_fetch_array($sql_result)) {
721 if (PMA_Tracker::isTracked($entries['db_name'], $entries['table_name'])) {
722 $status = ' (' . __('active') . ')';
723 } else {
724 $status = ' (' . __('not active') . ')';
726 if ($entries['table_name'] == $_REQUEST['table']) {
727 $s = ' selected="selected"';
728 } else {
729 $s = '';
731 echo '<option value="' . htmlspecialchars($entries['table_name']) . '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . ' . htmlspecialchars($entries['table_name']) . $status . '</option>' . "\n";
733 echo '</select>';
734 echo '<input type="hidden" name="show_versions_submit" value="1" />';
735 echo '<input type="submit" value="' . __('Show versions') . '" />';
736 echo '</form>';
738 echo '<br />';
741 * List versions of current table
744 $sql_query = " SELECT * FROM " .
745 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
746 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
747 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['db']) . "' ".
748 " AND table_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['table']) ."' ".
749 " ORDER BY version DESC ";
751 $sql_result = PMA_queryAsControlUser($sql_query);
753 $last_version = 0;
754 $maxversion = PMA_DBI_fetch_array($sql_result);
755 $last_version = $maxversion['version'];
757 if ($last_version > 0) {
758 echo '<table id="versions" class="data">';
759 echo '<thead>';
760 echo '<tr>';
761 echo '<th>' . __('Database') . '</th>';
762 echo '<th>' . __('Table') . '</th>';
763 echo '<th>' . __('Version') . '</th>';
764 echo '<th>' . __('Created') . '</th>';
765 echo '<th>' . __('Updated') . '</th>';
766 echo '<th>' . __('Status') . '</th>';
767 echo '<th>' . __('Show') . '</th>';
768 echo '</tr>';
769 echo '</thead>';
770 echo '<tbody>';
772 $style = 'odd';
773 PMA_DBI_data_seek($sql_result, 0);
774 while ($version = PMA_DBI_fetch_array($sql_result)) {
775 if ($version['tracking_active'] == 1) {
776 $version_status = __('active');
777 } else {
778 $version_status = __('not active');
780 if ($version['version'] == $last_version) {
781 if ($version['tracking_active'] == 1) {
782 $tracking_active = true;
783 } else {
784 $tracking_active = false;
787 echo '<tr class="noclick ' . $style . '">';
788 echo '<td>' . htmlspecialchars($version['db_name']) . '</td>';
789 echo '<td>' . htmlspecialchars($version['table_name']) . '</td>';
790 echo '<td>' . htmlspecialchars($version['version']) . '</td>';
791 echo '<td>' . htmlspecialchars($version['date_created']) . '</td>';
792 echo '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
793 echo '<td>' . $version_status . '</td>';
794 echo '<td><a href="tbl_tracking.php';
795 echo PMA_generate_common_url(
796 $url_params + array('report' => 'true', 'version' => $version['version'])
798 echo '">' . __('Tracking report') . '</a>';
799 echo '| <a href="tbl_tracking.php';
800 echo PMA_generate_common_url(
801 $url_params + array('snapshot' => 'true', 'version' => $version['version'])
803 echo '">' . __('Structure snapshot') . '</a>';
804 echo '</td>';
805 echo '</tr>';
807 if ($style == 'even') {
808 $style = 'odd';
809 } else {
810 $style = 'even';
814 echo '</tbody>';
815 echo '</table>';
817 if ($tracking_active) {
818 echo '<div id="div_deactivate_tracking">';
819 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
820 echo '<fieldset>';
821 echo '<legend>';
822 printf(
823 __('Deactivate tracking for %s'),
824 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
826 echo '</legend>';
827 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
828 echo '<input type="hidden" name="submit_deactivate_now" value="1" />';
829 echo '<input type="submit" value="' . __('Deactivate now') . '" />';
830 echo '</fieldset>';
831 echo '</form>';
832 echo '</div>';
833 } else {
834 echo '<div id="div_activate_tracking">';
835 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
836 echo '<fieldset>';
837 echo '<legend>';
838 printf(
839 __('Activate tracking for %s'),
840 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
842 echo '</legend>';
843 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
844 echo '<input type="hidden" name="submit_activate_now" value="1" />';
845 echo '<input type="submit" value="' . __('Activate now') . '" />';
846 echo '</fieldset>';
847 echo '</form>';
848 echo '</div>';
852 echo '<div id="div_create_version">';
853 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
854 echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
855 echo '<fieldset>';
856 echo '<legend>';
857 printf(
858 __('Create version %1$s of %2$s'),
859 ($last_version + 1),
860 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
862 echo '</legend>';
864 echo '<input type="hidden" name="version" value="' . ($last_version + 1) . '" />';
866 echo '<p>' . __('Track these data definition statements:') . '</p>';
867 echo '<input type="checkbox" name="alter_table" value="true" checked="checked" /> ALTER TABLE<br/>';
868 echo '<input type="checkbox" name="rename_table" value="true" checked="checked" /> RENAME TABLE<br/>';
869 echo '<input type="checkbox" name="create_table" value="true" checked="checked" /> CREATE TABLE<br/>';
870 echo '<input type="checkbox" name="drop_table" value="true" checked="checked" /> DROP TABLE<br/>';
871 echo '<br/>';
872 echo '<input type="checkbox" name="create_index" value="true" checked="checked" /> CREATE INDEX<br/>';
873 echo '<input type="checkbox" name="drop_index" value="true" checked="checked" /> DROP INDEX<br/>';
874 echo '<p>' . __('Track these data manipulation statements:') . '</p>';
875 echo '<input type="checkbox" name="insert" value="true" checked="checked" /> INSERT<br/>';
876 echo '<input type="checkbox" name="update" value="true" checked="checked" /> UPDATE<br/>';
877 echo '<input type="checkbox" name="delete" value="true" checked="checked" /> DELETE<br/>';
878 echo '<input type="checkbox" name="truncate" value="true" checked="checked" /> TRUNCATE<br/>';
880 echo '</fieldset>';
881 echo '<fieldset class="tblFooters">';
883 echo '<input type="hidden" name="submit_create_version" value="1" />';
884 echo '<input type="submit" value="' . __('Create version') . '" />';
885 echo '</fieldset>';
886 echo '</form>';
887 echo '</div>';
889 echo '<br class="clearfloat"/>';