Translated using Weblate (Spanish)
[phpmyadmin.git] / tbl_tracking.php
blob19431dc69e4a33c4f96f329eae66f5c3719327b4
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_filterTracking(
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(
78 'id' => $id,
79 'timestamp' => $timestamp,
80 'username' => $entry['username'],
81 'statement' => $entry['statement']
84 $id++;
86 return($tmp_entries);
89 $entries = array();
90 // Filtering data definition statements
91 if ($_REQUEST['logtype'] == 'schema'
92 || $_REQUEST['logtype'] == 'schema_and_data'
93 ) {
94 $entries = array_merge(
95 $entries,
96 PMA_filterTracking(
97 $data['ddlog'], $filter_ts_from, $filter_ts_to, $filter_users
102 // Filtering data manipulation statements
103 if ($_REQUEST['logtype'] == 'data'
104 || $_REQUEST['logtype'] == 'schema_and_data'
106 $entries = array_merge(
107 $entries,
108 PMA_filterTracking(
109 $data['dmlog'], $filter_ts_from, $filter_ts_to, $filter_users
114 // Sort it
115 foreach ($entries as $key => $row) {
116 $ids[$key] = $row['id'];
117 $timestamps[$key] = $row['timestamp'];
118 $usernames[$key] = $row['username'];
119 $statements[$key] = $row['statement'];
122 array_multisort(
123 $timestamps, SORT_ASC, $ids, SORT_ASC, $usernames,
124 SORT_ASC, $statements, SORT_ASC, $entries
129 // Export as file download
130 if (isset($_REQUEST['report_export'])
131 && $_REQUEST['export_type'] == 'sqldumpfile'
133 @ini_set('url_rewriter.tags', '');
135 $dump = "# " . sprintf(
136 __('Tracking report for table `%s`'), htmlspecialchars($_REQUEST['table'])
138 . "\n" . "# " . date('Y-m-d H:i:s') . "\n";
139 foreach ($entries as $entry) {
140 $dump .= $entry['statement'];
142 $filename = 'log_' . htmlspecialchars($_REQUEST['table']) . '.sql';
143 PMA_downloadHeader($filename, 'text/x-sql', strlen($dump));
145 echo $dump;
146 exit();
151 * Gets tables informations
154 echo '<br />';
157 * Actions
160 // Create tracking version
161 if (isset($_REQUEST['submit_create_version'])) {
162 $tracking_set = '';
164 if ($_REQUEST['alter_table'] == true) {
165 $tracking_set .= 'ALTER TABLE,';
167 if ($_REQUEST['rename_table'] == true) {
168 $tracking_set .= 'RENAME TABLE,';
170 if ($_REQUEST['create_table'] == true) {
171 $tracking_set .= 'CREATE TABLE,';
173 if ($_REQUEST['drop_table'] == true) {
174 $tracking_set .= 'DROP TABLE,';
176 if ($_REQUEST['create_index'] == true) {
177 $tracking_set .= 'CREATE INDEX,';
179 if ($_REQUEST['drop_index'] == true) {
180 $tracking_set .= 'DROP INDEX,';
182 if ($_REQUEST['insert'] == true) {
183 $tracking_set .= 'INSERT,';
185 if ($_REQUEST['update'] == true) {
186 $tracking_set .= 'UPDATE,';
188 if ($_REQUEST['delete'] == true) {
189 $tracking_set .= 'DELETE,';
191 if ($_REQUEST['truncate'] == true) {
192 $tracking_set .= 'TRUNCATE,';
194 $tracking_set = rtrim($tracking_set, ',');
196 $versionCreated = PMA_Tracker::createVersion(
197 $GLOBALS['db'],
198 $GLOBALS['table'],
199 $_REQUEST['version'],
200 $tracking_set,
201 PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])
203 if ($versionCreated) {
204 $msg = PMA_Message::success(
205 sprintf(
206 __('Version %1$s was created, tracking for %2$s is active.'),
207 htmlspecialchars($_REQUEST['version']),
208 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
211 $msg->display();
215 // Deactivate tracking
216 if (isset($_REQUEST['submit_deactivate_now'])) {
217 $deactivated = PMA_Tracker::deactivateTracking(
218 $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
220 if ($deactivated) {
221 $msg = PMA_Message::success(
222 sprintf(
223 __('Tracking for %1$s was deactivated at version %2$s.'),
224 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
225 htmlspecialchars($_REQUEST['version'])
228 $msg->display();
232 // Activate tracking
233 if (isset($_REQUEST['submit_activate_now'])) {
234 $activated = PMA_Tracker::activateTracking(
235 $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
237 if ($activated) {
238 $msg = PMA_Message::success(
239 sprintf(
240 __('Tracking for %1$s was activated at version %2$s.'),
241 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
242 htmlspecialchars($_REQUEST['version'])
245 $msg->display();
249 // Export as SQL execution
250 if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'execution') {
251 foreach ($entries as $entry) {
252 $sql_result = $GLOBALS['dbi']->query("/*NOTRACK*/\n" . $entry['statement']);
254 $msg = PMA_Message::success(__('SQL statements executed.'));
255 $msg->display();
258 // Export as SQL dump
259 if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldump') {
260 $new_query = "# "
261 . __('You can execute the dump by creating and using a temporary database. Please ensure that you have the privileges to do so.')
262 . "\n"
263 . "# " . __('Comment out these two lines if you do not need them.') . "\n"
264 . "\n"
265 . "CREATE database IF NOT EXISTS pma_temp_db; \n"
266 . "USE pma_temp_db; \n"
267 . "\n";
269 foreach ($entries as $entry) {
270 $new_query .= $entry['statement'];
272 $msg = PMA_Message::success(
273 __('SQL statements exported. Please copy the dump or execute it.')
275 $msg->display();
277 $db_temp = $db;
278 $table_temp = $table;
280 $db = $table = '';
281 include_once './libraries/sql_query_form.lib.php';
283 PMA_sqlQueryForm($new_query, 'sql');
285 $db = $db_temp;
286 $table = $table_temp;
290 * Schema snapshot
292 if (isset($_REQUEST['snapshot'])) {
293 echo '<h3>' . __('Structure snapshot')
294 . ' [<a href="tbl_tracking.php?' . $url_query . '">' . __('Close')
295 . '</a>]</h3>';
296 $data = PMA_Tracker::getTrackedData(
297 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
300 // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements
301 $drop_create_statements = $data['ddlog'][0]['statement'];
303 if (strstr($data['ddlog'][0]['statement'], 'DROP TABLE')
304 || strstr($data['ddlog'][0]['statement'], 'DROP VIEW')
306 $drop_create_statements .= $data['ddlog'][1]['statement'];
308 // Print SQL code
309 echo PMA_Util::getMessage(
310 sprintf(
311 __('Version %s snapshot (SQL code)'),
312 htmlspecialchars($_REQUEST['version'])
314 $drop_create_statements
317 // Unserialize snapshot
318 $temp = unserialize($data['schema_snapshot']);
319 $columns = $temp['COLUMNS'];
320 $indexes = $temp['INDEXES'];
321 echo '<h3>' . __('Structure') . '</h3>';
322 echo '<table id="tablestructure" class="data">';
323 echo '<thead>';
324 echo '<tr>';
325 echo '<th>' . __('Column') . '</th>';
326 echo '<th>' . __('Type') . '</th>';
327 echo '<th>' . __('Collation') . '</th>';
328 echo '<th>' . __('Null') . '</th>';
329 echo '<th>' . __('Default') . '</th>';
330 echo '<th>' . __('Extra') . '</th>';
331 echo '<th>' . __('Comment') . '</th>';
332 echo '</tr>';
333 echo '</thead>';
334 echo '<tbody>';
335 $style = 'odd';
336 foreach ($columns as $field_index => $field) {
337 echo '<tr class="noclick ' . $style . '">';
338 if ($field['Key'] == 'PRI') {
339 echo '<td><b><u>' . htmlspecialchars($field['Field']) . '</u></b></td>';
340 } else {
341 echo '<td><b>' . htmlspecialchars($field['Field']) . '</b></td>';
343 echo "\n";
344 echo '<td>' . htmlspecialchars($field['Type']) . '</td>';
345 echo '<td>' . htmlspecialchars($field['Collation']) . '</td>';
346 echo '<td>' . (($field['Null'] == 'YES') ? __('Yes') : __('No')) . '</td>';
347 echo '<td>';
348 if (isset($field['Default'])) {
349 $extracted_columnspec = PMA_Util::extractColumnSpec($field['Type']);
350 if ($extracted_columnspec['type'] == 'bit') {
351 // here, $field['Default'] contains something like b'010'
352 echo PMA_Util::convertBitDefaultValue($field['Default']);
353 } else {
354 echo htmlspecialchars($field['Default']);
356 } else {
357 if ($field['Null'] == 'YES') {
358 echo '<i>NULL</i>';
359 } else {
360 echo '<i>' . _pgettext('None for default', 'None') . '</i>';
363 echo '</td>';
364 echo '<td>' . htmlspecialchars($field['Extra']) . '</td>';
365 echo '<td>' . htmlspecialchars($field['Comment']) . '</td>';
366 echo '</tr>';
368 if ($style == 'even') {
369 $style = 'odd';
370 } else {
371 $style = 'even';
375 echo '</tbody>';
376 echo '</table>';
378 if (count($indexes) > 0) {
379 echo '<h3>' . __('Indexes') . '</h3>';
380 echo '<table id="tablestructure_indexes" class="data">';
381 echo '<thead>';
382 echo '<tr>';
383 echo '<th>' . __('Keyname') . '</th>';
384 echo '<th>' . __('Type') . '</th>';
385 echo '<th>' . __('Unique') . '</th>';
386 echo '<th>' . __('Packed') . '</th>';
387 echo '<th>' . __('Column') . '</th>';
388 echo '<th>' . __('Cardinality') . '</th>';
389 echo '<th>' . __('Collation') . '</th>';
390 echo '<th>' . __('Null') . '</th>';
391 echo '<th>' . __('Comment') . '</th>';
392 echo '</tr>';
393 echo '<tbody>';
395 $style = 'odd';
396 foreach ($indexes as $indexes_index => $index) {
397 if ($index['Non_unique'] == 0) {
398 $str_unique = __('Yes');
399 } else {
400 $str_unique = __('No');
402 if ($index['Packed'] != '') {
403 $str_packed = __('Yes');
404 } else {
405 $str_packed = __('No');
408 echo '<tr class="noclick ' . $style . '">';
409 echo '<td><b>' . htmlspecialchars($index['Key_name']) . '</b></td>';
410 echo '<td>' . htmlspecialchars($index['Index_type']) . '</td>';
411 echo '<td>' . $str_unique . '</td>';
412 echo '<td>' . $str_packed . '</td>';
413 echo '<td>' . htmlspecialchars($index['Column_name']) . '</td>';
414 echo '<td>' . htmlspecialchars($index['Cardinality']) . '</td>';
415 echo '<td>' . htmlspecialchars($index['Collation']) . '</td>';
416 echo '<td>' . htmlspecialchars($index['Null']) . '</td>';
417 echo '<td>' . htmlspecialchars($index['Comment']) . '</td>';
418 echo '</tr>';
420 if ($style == 'even') {
421 $style = 'odd';
422 } else {
423 $style = 'even';
426 echo '</tbody>';
427 echo '</table>';
428 } // endif
429 echo '<br /><hr /><br />';
431 // end of snapshot report
434 * Tracking report
436 if (isset($_REQUEST['report'])
437 && (isset($_REQUEST['delete_ddlog']) || isset($_REQUEST['delete_dmlog']))
440 if (isset($_REQUEST['delete_ddlog'])) {
442 // Delete ddlog row data
443 $delete_id = $_REQUEST['delete_ddlog'];
445 // Only in case of valable id
446 if ($delete_id == (int)$delete_id) {
447 unset($data['ddlog'][$delete_id]);
449 $successfullyDeleted = PMA_Tracker::changeTrackingData(
450 $_REQUEST['db'], $_REQUEST['table'],
451 $_REQUEST['version'], 'DDL', $data['ddlog']
453 if ($successfullyDeleted) {
454 $msg = PMA_Message::success(
455 __('Tracking data definition successfully deleted')
457 } else {
458 $msg = PMA_Message::rawError(__('Query error'));
460 $msg->display();
464 if (isset($_REQUEST['delete_dmlog'])) {
466 // Delete dmlog row data
467 $delete_id = $_REQUEST['delete_dmlog'];
469 // Only in case of valable id
470 if ($delete_id == (int)$delete_id) {
471 unset($data['dmlog'][$delete_id]);
473 $successfullyDeleted = PMA_Tracker::changeTrackingData(
474 $_REQUEST['db'], $_REQUEST['table'],
475 $_REQUEST['version'], 'DML', $data['dmlog']
477 if ($successfullyDeleted) {
478 $msg = PMA_Message::success(
479 __('Tracking data manipulation successfully deleted')
481 } else {
482 $msg = PMA_Message::rawError(__('Query error'));
484 $msg->display();
489 if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) {
490 echo '<h3>' . __('Tracking report')
491 . ' [<a href="tbl_tracking.php?' . $url_query . '">' . __('Close')
492 . '</a>]</h3>';
494 echo '<small>' . __('Tracking statements') . ' '
495 . htmlspecialchars($data['tracking']) . '</small><br/>';
496 echo '<br/>';
498 echo '<form method="post" action="tbl_tracking.php'
499 . PMA_URL_getCommon(
500 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
502 . '">';
504 $str1 = '<select name="logtype">'
505 . '<option value="schema"'
506 . ($selection_schema ? ' selected="selected"' : '') . '>'
507 . __('Structure only') . '</option>'
508 . '<option value="data"'
509 . ($selection_data ? ' selected="selected"' : ''). '>'
510 . __('Data only') . '</option>'
511 . '<option value="schema_and_data"'
512 . ($selection_both ? ' selected="selected"' : '') . '>'
513 . __('Structure and data') . '</option>'
514 . '</select>';
515 $str2 = '<input type="text" name="date_from" value="'
516 . htmlspecialchars($_REQUEST['date_from']) . '" size="19" />';
517 $str3 = '<input type="text" name="date_to" value="'
518 . htmlspecialchars($_REQUEST['date_to']) . '" size="19" />';
519 $str4 = '<input type="text" name="users" value="'
520 . htmlspecialchars($_REQUEST['users']) . '" />';
521 $str5 = '<input type="hidden" name="list_report" value="1" />'
522 . '<input type="submit" value="' . __('Go') . '" />';
524 printf(
525 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
526 $str1, $str2, $str3, $str4, $str5
529 // Prepare delete link content here
530 $drop_image_or_text = '';
531 if (PMA_Util::showIcons('ActionsLinksMode')) {
532 $drop_image_or_text .= PMA_Util::getImage(
533 'b_drop.png', __('Delete tracking data row from report')
536 if (PMA_Util::showText('ActionLinksMode')) {
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 $statement = PMA_Util::formatSql($entry['statement'], true);
565 $timestamp = strtotime($entry['date']);
567 if ($timestamp >= $filter_ts_from
568 && $timestamp <= $filter_ts_to
569 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
571 echo '<tr class="noclick ' . $style . '">';
572 echo '<td><small>' . $i . '</small></td>';
573 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
574 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
575 echo '<td>' . $statement . '</td>';
576 echo '<td class="nowrap"><a href="tbl_tracking.php?'
577 . PMA_URL_getCommon(
578 $url_params + array(
579 'report' => 'true',
580 'version' => $_REQUEST['version'],
581 'delete_ddlog' => ($i - 1),
584 . '">' . $drop_image_or_text
585 . '</a></td>';
586 echo '</tr>';
588 if ($style == 'even') {
589 $style = 'odd';
590 } else {
591 $style = 'even';
593 $i++;
596 echo '</tbody>';
597 echo '</table>';
599 } //endif
601 // Memorize data definition amount
602 $ddlog_count = $i;
605 * Secondly, list tracked data manipulation statements
608 if (($selection_data || $selection_both) && count($data['dmlog']) > 0) {
609 echo '<table id="dml_versions" class="data" width="100%">';
610 echo '<thead>';
611 echo '<tr>';
612 echo '<th width="18">#</th>';
613 echo '<th width="100">' . __('Date') . '</th>';
614 echo '<th width="60">' . __('Username') . '</th>';
615 echo '<th>' . __('Data manipulation statement') . '</th>';
616 echo '<th>' . __('Delete') . '</th>';
617 echo '</tr>';
618 echo '</thead>';
619 echo '<tbody>';
621 $style = 'odd';
622 foreach ($data['dmlog'] as $entry) {
623 $statement = PMA_Util::formatSql($entry['statement'], true);
624 $timestamp = strtotime($entry['date']);
626 if ($timestamp >= $filter_ts_from
627 && $timestamp <= $filter_ts_to
628 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
630 echo '<tr class="noclick ' . $style . '">';
631 echo '<td><small>' . $i . '</small></td>';
632 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
633 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
634 echo '<td>' . $statement . '</td>';
635 echo '<td class="nowrap"><a href="tbl_tracking.php?'
636 . PMA_URL_getCommon(
637 $url_params + array(
638 'report' => 'true',
639 'version' => $_REQUEST['version'],
640 'delete_dmlog' => ($i - $ddlog_count),
643 . '">'
644 . $drop_image_or_text
645 . '</a></td>';
646 echo '</tr>';
648 if ($style == 'even') {
649 $style = 'odd';
650 } else {
651 $style = 'even';
653 $i++;
656 echo '</tbody>';
657 echo '</table>';
659 echo '</form>';
660 echo '<form method="post" action="tbl_tracking.php'
661 . PMA_URL_getCommon(
662 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
664 . '">';
665 printf(
666 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
667 $str1, $str2, $str3, $str4, $str5
670 $str_export1 = '<select name="export_type">'
671 . '<option value="sqldumpfile">' . __('SQL dump (file download)') . '</option>'
672 . '<option value="sqldump">' . __('SQL dump') . '</option>'
673 . '<option value="execution" onclick="alert(\''
674 . PMA_escapeJsString(__('This option will replace your table and contained data.'))
675 .'\')">' . __('SQL execution') . '</option>' . '</select>';
677 $str_export2 = '<input type="hidden" name="report_export" value="1" />'
678 . '<input type="submit" value="' . __('Go') .'" />';
679 echo '</form>';
680 echo '<form class="disableAjax" method="post" action="tbl_tracking.php'
681 . PMA_URL_getCommon(
682 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
684 . '">';
685 echo '<input type="hidden" name="logtype" value="'
686 . htmlspecialchars($_REQUEST['logtype']) . '" />';
687 echo '<input type="hidden" name="date_from" value="'
688 . htmlspecialchars($_REQUEST['date_from']) . '" />';
689 echo '<input type="hidden" name="date_to" value="'
690 . htmlspecialchars($_REQUEST['date_to']) . '" />';
691 echo '<input type="hidden" name="users" value="'
692 . htmlspecialchars($_REQUEST['users']) . '" />';
693 echo "<br/>" . sprintf(__('Export as %s'), $str_export1)
694 . $str_export2 . "<br/>";
695 echo '</form>';
696 echo "<br/><br/><hr/><br/>\n";
697 } // end of report
701 * List selectable tables
704 $sql_query = " SELECT DISTINCT db_name, table_name FROM " .
705 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
706 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
707 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "' " .
708 " ORDER BY db_name, table_name";
710 $sql_result = PMA_queryAsControlUser($sql_query);
712 if ($GLOBALS['dbi']->numRows($sql_result) > 0) {
713 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
714 echo '<select name="table">';
715 while ($entries = $GLOBALS['dbi']->fetchArray($sql_result)) {
716 if (PMA_Tracker::isTracked($entries['db_name'], $entries['table_name'])) {
717 $status = ' (' . __('active') . ')';
718 } else {
719 $status = ' (' . __('not active') . ')';
721 if ($entries['table_name'] == $_REQUEST['table']) {
722 $s = ' selected="selected"';
723 } else {
724 $s = '';
726 echo '<option value="' . htmlspecialchars($entries['table_name']) . '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . ' . htmlspecialchars($entries['table_name']) . $status . '</option>' . "\n";
728 echo '</select>';
729 echo '<input type="hidden" name="show_versions_submit" value="1" />';
730 echo '<input type="submit" value="' . __('Show versions') . '" />';
731 echo '</form>';
733 echo '<br />';
736 * List versions of current table
739 $sql_query = " SELECT * FROM " .
740 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
741 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
742 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['db']) . "' ".
743 " AND table_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['table']) ."' ".
744 " ORDER BY version DESC ";
746 $sql_result = PMA_queryAsControlUser($sql_query);
748 $last_version = 0;
749 $maxversion = $GLOBALS['dbi']->fetchArray($sql_result);
750 $last_version = $maxversion['version'];
752 if ($last_version > 0) {
753 echo '<table id="versions" class="data">';
754 echo '<thead>';
755 echo '<tr>';
756 echo '<th>' . __('Database') . '</th>';
757 echo '<th>' . __('Table') . '</th>';
758 echo '<th>' . __('Version') . '</th>';
759 echo '<th>' . __('Created') . '</th>';
760 echo '<th>' . __('Updated') . '</th>';
761 echo '<th>' . __('Status') . '</th>';
762 echo '<th>' . __('Show') . '</th>';
763 echo '</tr>';
764 echo '</thead>';
765 echo '<tbody>';
767 $style = 'odd';
768 $GLOBALS['dbi']->dataSeek($sql_result, 0);
769 while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) {
770 if ($version['tracking_active'] == 1) {
771 $version_status = __('active');
772 } else {
773 $version_status = __('not active');
775 if ($version['version'] == $last_version) {
776 if ($version['tracking_active'] == 1) {
777 $tracking_active = true;
778 } else {
779 $tracking_active = false;
782 echo '<tr class="noclick ' . $style . '">';
783 echo '<td>' . htmlspecialchars($version['db_name']) . '</td>';
784 echo '<td>' . htmlspecialchars($version['table_name']) . '</td>';
785 echo '<td>' . htmlspecialchars($version['version']) . '</td>';
786 echo '<td>' . htmlspecialchars($version['date_created']) . '</td>';
787 echo '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
788 echo '<td>' . $version_status . '</td>';
789 echo '<td><a href="tbl_tracking.php';
790 echo PMA_URL_getCommon(
791 $url_params + array('report' => 'true', 'version' => $version['version'])
793 echo '">' . __('Tracking report') . '</a>';
794 echo '| <a href="tbl_tracking.php';
795 echo PMA_URL_getCommon(
796 $url_params + array('snapshot' => 'true', 'version' => $version['version'])
798 echo '">' . __('Structure snapshot') . '</a>';
799 echo '</td>';
800 echo '</tr>';
802 if ($style == 'even') {
803 $style = 'odd';
804 } else {
805 $style = 'even';
809 echo '</tbody>';
810 echo '</table>';
812 if ($tracking_active) {
813 echo '<div id="div_deactivate_tracking">';
814 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
815 echo '<fieldset>';
816 echo '<legend>';
817 printf(
818 __('Deactivate tracking for %s'),
819 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
821 echo '</legend>';
822 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
823 echo '<input type="hidden" name="submit_deactivate_now" value="1" />';
824 echo '<input type="submit" value="' . __('Deactivate now') . '" />';
825 echo '</fieldset>';
826 echo '</form>';
827 echo '</div>';
828 } else {
829 echo '<div id="div_activate_tracking">';
830 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
831 echo '<fieldset>';
832 echo '<legend>';
833 printf(
834 __('Activate tracking for %s'),
835 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
837 echo '</legend>';
838 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
839 echo '<input type="hidden" name="submit_activate_now" value="1" />';
840 echo '<input type="submit" value="' . __('Activate now') . '" />';
841 echo '</fieldset>';
842 echo '</form>';
843 echo '</div>';
847 echo '<div id="div_create_version">';
848 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
849 echo PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
850 echo '<fieldset>';
851 echo '<legend>';
852 printf(
853 __('Create version %1$s of %2$s'),
854 ($last_version + 1),
855 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
857 echo '</legend>';
859 echo '<input type="hidden" name="version" value="' . ($last_version + 1) . '" />';
861 echo '<p>' . __('Track these data definition statements:') . '</p>';
862 echo '<input type="checkbox" name="alter_table" value="true" checked="checked" /> ALTER TABLE<br/>';
863 echo '<input type="checkbox" name="rename_table" value="true" checked="checked" /> RENAME TABLE<br/>';
864 echo '<input type="checkbox" name="create_table" value="true" checked="checked" /> CREATE TABLE<br/>';
865 echo '<input type="checkbox" name="drop_table" value="true" checked="checked" /> DROP TABLE<br/>';
866 echo '<br/>';
867 echo '<input type="checkbox" name="create_index" value="true" checked="checked" /> CREATE INDEX<br/>';
868 echo '<input type="checkbox" name="drop_index" value="true" checked="checked" /> DROP INDEX<br/>';
869 echo '<p>' . __('Track these data manipulation statements:') . '</p>';
870 echo '<input type="checkbox" name="insert" value="true" checked="checked" /> INSERT<br/>';
871 echo '<input type="checkbox" name="update" value="true" checked="checked" /> UPDATE<br/>';
872 echo '<input type="checkbox" name="delete" value="true" checked="checked" /> DELETE<br/>';
873 echo '<input type="checkbox" name="truncate" value="true" checked="checked" /> TRUNCATE<br/>';
875 echo '</fieldset>';
876 echo '<fieldset class="tblFooters">';
878 echo '<input type="hidden" name="submit_create_version" value="1" />';
879 echo '<input type="submit" value="' . __('Create version') . '" />';
880 echo '</fieldset>';
881 echo '</form>';
882 echo '</div>';
884 echo '<br class="clearfloat"/>';