Translated using Weblate (Uzbek)
[phpmyadmin.git] / tbl_tracking.php
blobc1ae531dac5f1c93048afee6256607ce01977c44
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 ('icons' == $GLOBALS['cfg']['ActionsLinksMode']) {
530 $drop_image_or_text .= PMA_Util::getImage(
531 'b_drop.png', __('Delete tracking data row from report')
534 if (in_array(
535 $GLOBALS['cfg']['ActionLinksMode'],
536 array('text', 'both')
539 $drop_image_or_text .= __('Delete');
543 * First, list tracked data definition statements
545 $i = 1;
546 if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
547 $msg = PMA_Message::notice(__('No data'));
548 $msg->display();
551 if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
552 echo '<table id="ddl_versions" class="data" width="100%">';
553 echo '<thead>';
554 echo '<tr>';
555 echo '<th width="18">#</th>';
556 echo '<th width="100">' . __('Date') . '</th>';
557 echo '<th width="60">' . __('Username') . '</th>';
558 echo '<th>' . __('Data definition statement') . '</th>';
559 echo '<th>' . __('Delete') . '</th>';
560 echo '</tr>';
561 echo '</thead>';
562 echo '<tbody>';
564 $style = 'odd';
565 foreach ($data['ddlog'] as $entry) {
566 if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
567 $statement = substr(
568 $entry['statement'],
570 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
571 ) . '[...]';
572 } else {
573 $statement = PMA_Util::formatSql(PMA_SQP_parse($entry['statement']));
575 $timestamp = strtotime($entry['date']);
577 if ($timestamp >= $filter_ts_from
578 && $timestamp <= $filter_ts_to
579 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
581 echo '<tr class="noclick ' . $style . '">';
582 echo '<td><small>' . $i . '</small></td>';
583 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
584 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
585 echo '<td>' . $statement . '</td>';
586 echo '<td class="nowrap"><a href="tbl_tracking.php?'
587 . $url_query . '&amp;report=true&amp;version='
588 . $version['version'] . '&amp;delete_ddlog='
589 . ($i - 1) . '">' . $drop_image_or_text
590 . '</a></td>';
591 echo '</tr>';
593 if ($style == 'even') {
594 $style = 'odd';
595 } else {
596 $style = 'even';
598 $i++;
601 echo '</tbody>';
602 echo '</table>';
604 } //endif
606 // Memorize data definition amount
607 $ddlog_count = $i;
610 * Secondly, list tracked data manipulation statements
613 if (($selection_data || $selection_both) && count($data['dmlog']) > 0) {
614 echo '<table id="dml_versions" class="data" width="100%">';
615 echo '<thead>';
616 echo '<tr>';
617 echo '<th width="18">#</th>';
618 echo '<th width="100">' . __('Date') . '</th>';
619 echo '<th width="60">' . __('Username') . '</th>';
620 echo '<th>' . __('Data manipulation statement') . '</th>';
621 echo '<th>' . __('Delete') . '</th>';
622 echo '</tr>';
623 echo '</thead>';
624 echo '<tbody>';
626 $style = 'odd';
627 foreach ($data['dmlog'] as $entry) {
628 if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
629 $statement = substr(
630 $entry['statement'],
632 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
633 ) . '[...]';
634 } else {
635 $statement = PMA_Util::formatSql(PMA_SQP_parse($entry['statement']));
637 $timestamp = strtotime($entry['date']);
639 if ($timestamp >= $filter_ts_from
640 && $timestamp <= $filter_ts_to
641 && (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
643 echo '<tr class="noclick ' . $style . '">';
644 echo '<td><small>' . $i . '</small></td>';
645 echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
646 echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
647 echo '<td>' . $statement . '</td>';
648 echo '<td class="nowrap"><a href="tbl_tracking.php?' . $url_query
649 . '&amp;report=true&amp;version=' . $version['version']
650 . '&amp;delete_dmlog=' . ($i - $ddlog_count) . '">'
651 . $drop_image_or_text
652 . '</a></td>';
653 echo '</tr>';
655 if ($style == 'even') {
656 $style = 'odd';
657 } else {
658 $style = 'even';
660 $i++;
663 echo '</tbody>';
664 echo '</table>';
666 echo '</form>';
667 echo '<form method="post" action="tbl_tracking.php'
668 . PMA_generate_common_url(
669 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
671 . '">';
672 printf(
673 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
674 $str1, $str2, $str3, $str4, $str5
677 $str_export1 = '<select name="export_type">'
678 . '<option value="sqldumpfile">' . __('SQL dump (file download)') . '</option>'
679 . '<option value="sqldump">' . __('SQL dump') . '</option>'
680 . '<option value="execution" onclick="alert(\''
681 . PMA_escapeJsString(__('This option will replace your table and contained data.'))
682 .'\')">' . __('SQL execution') . '</option>' . '</select>';
684 $str_export2 = '<input type="hidden" name="report_export" value="1" />'
685 . '<input type="submit" value="' . __('Go') .'" />';
686 echo '</form>';
687 echo '<form class="disableAjax" method="post" action="tbl_tracking.php'
688 . PMA_generate_common_url(
689 $url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
691 . '">';
692 echo '<input type="hidden" name="logtype" value="'
693 . htmlspecialchars($_REQUEST['logtype']) . '" />';
694 echo '<input type="hidden" name="date_from" value="'
695 . htmlspecialchars($_REQUEST['date_from']) . '" />';
696 echo '<input type="hidden" name="date_to" value="'
697 . htmlspecialchars($_REQUEST['date_to']) . '" />';
698 echo '<input type="hidden" name="users" value="'
699 . htmlspecialchars($_REQUEST['users']) . '" />';
700 echo "<br/>" . sprintf(__('Export as %s'), $str_export1)
701 . $str_export2 . "<br/>";
702 echo '</form>';
703 echo "<br/><br/><hr/><br/>\n";
704 } // end of report
708 * List selectable tables
711 $sql_query = " SELECT DISTINCT db_name, table_name FROM " .
712 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
713 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
714 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "' " .
715 " ORDER BY db_name, table_name";
717 $sql_result = PMA_queryAsControlUser($sql_query);
719 if (PMA_DBI_num_rows($sql_result) > 0) {
720 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
721 echo '<select name="table">';
722 while ($entries = PMA_DBI_fetch_array($sql_result)) {
723 if (PMA_Tracker::isTracked($entries['db_name'], $entries['table_name'])) {
724 $status = ' (' . __('active') . ')';
725 } else {
726 $status = ' (' . __('not active') . ')';
728 if ($entries['table_name'] == $_REQUEST['table']) {
729 $s = ' selected="selected"';
730 } else {
731 $s = '';
733 echo '<option value="' . htmlspecialchars($entries['table_name']) . '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . ' . htmlspecialchars($entries['table_name']) . $status . '</option>' . "\n";
735 echo '</select>';
736 echo '<input type="hidden" name="show_versions_submit" value="1" />';
737 echo '<input type="submit" value="' . __('Show versions') . '" />';
738 echo '</form>';
740 echo '<br />';
743 * List versions of current table
746 $sql_query = " SELECT * FROM " .
747 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
748 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
749 " WHERE db_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['db']) . "' ".
750 " AND table_name = '" . PMA_Util::sqlAddSlashes($_REQUEST['table']) ."' ".
751 " ORDER BY version DESC ";
753 $sql_result = PMA_queryAsControlUser($sql_query);
755 $last_version = 0;
756 $maxversion = PMA_DBI_fetch_array($sql_result);
757 $last_version = $maxversion['version'];
759 if ($last_version > 0) {
760 echo '<table id="versions" class="data">';
761 echo '<thead>';
762 echo '<tr>';
763 echo '<th>' . __('Database') . '</th>';
764 echo '<th>' . __('Table') . '</th>';
765 echo '<th>' . __('Version') . '</th>';
766 echo '<th>' . __('Created') . '</th>';
767 echo '<th>' . __('Updated') . '</th>';
768 echo '<th>' . __('Status') . '</th>';
769 echo '<th>' . __('Show') . '</th>';
770 echo '</tr>';
771 echo '</thead>';
772 echo '<tbody>';
774 $style = 'odd';
775 PMA_DBI_data_seek($sql_result, 0);
776 while ($version = PMA_DBI_fetch_array($sql_result)) {
777 if ($version['tracking_active'] == 1) {
778 $version_status = __('active');
779 } else {
780 $version_status = __('not active');
782 if ($version['version'] == $last_version) {
783 if ($version['tracking_active'] == 1) {
784 $tracking_active = true;
785 } else {
786 $tracking_active = false;
789 echo '<tr class="noclick ' . $style . '">';
790 echo '<td>' . htmlspecialchars($version['db_name']) . '</td>';
791 echo '<td>' . htmlspecialchars($version['table_name']) . '</td>';
792 echo '<td>' . htmlspecialchars($version['version']) . '</td>';
793 echo '<td>' . htmlspecialchars($version['date_created']) . '</td>';
794 echo '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
795 echo '<td>' . $version_status . '</td>';
796 echo '<td><a href="tbl_tracking.php';
797 echo PMA_generate_common_url(
798 $url_params + array('report' => 'true', 'version' => $version['version'])
800 echo '">' . __('Tracking report') . '</a>';
801 echo '| <a href="tbl_tracking.php';
802 echo PMA_generate_common_url(
803 $url_params + array('snapshot' => 'true', 'version' => $version['version'])
805 echo '">' . __('Structure snapshot') . '</a>';
806 echo '</td>';
807 echo '</tr>';
809 if ($style == 'even') {
810 $style = 'odd';
811 } else {
812 $style = 'even';
816 echo '</tbody>';
817 echo '</table>';
819 if ($tracking_active) {
820 echo '<div id="div_deactivate_tracking">';
821 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
822 echo '<fieldset>';
823 echo '<legend>';
824 printf(
825 __('Deactivate tracking for %s'),
826 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
828 echo '</legend>';
829 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
830 echo '<input type="hidden" name="submit_deactivate_now" value="1" />';
831 echo '<input type="submit" value="' . __('Deactivate now') . '" />';
832 echo '</fieldset>';
833 echo '</form>';
834 echo '</div>';
835 } else {
836 echo '<div id="div_activate_tracking">';
837 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
838 echo '<fieldset>';
839 echo '<legend>';
840 printf(
841 __('Activate tracking for %s'),
842 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
844 echo '</legend>';
845 echo '<input type="hidden" name="version" value="' . $last_version . '" />';
846 echo '<input type="hidden" name="submit_activate_now" value="1" />';
847 echo '<input type="submit" value="' . __('Activate now') . '" />';
848 echo '</fieldset>';
849 echo '</form>';
850 echo '</div>';
854 echo '<div id="div_create_version">';
855 echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
856 echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
857 echo '<fieldset>';
858 echo '<legend>';
859 printf(
860 __('Create version %1$s of %2$s'),
861 ($last_version + 1),
862 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
864 echo '</legend>';
866 echo '<input type="hidden" name="version" value="' . ($last_version + 1) . '" />';
868 echo '<p>' . __('Track these data definition statements:') . '</p>';
869 echo '<input type="checkbox" name="alter_table" value="true" checked="checked" /> ALTER TABLE<br/>';
870 echo '<input type="checkbox" name="rename_table" value="true" checked="checked" /> RENAME TABLE<br/>';
871 echo '<input type="checkbox" name="create_table" value="true" checked="checked" /> CREATE TABLE<br/>';
872 echo '<input type="checkbox" name="drop_table" value="true" checked="checked" /> DROP TABLE<br/>';
873 echo '<br/>';
874 echo '<input type="checkbox" name="create_index" value="true" checked="checked" /> CREATE INDEX<br/>';
875 echo '<input type="checkbox" name="drop_index" value="true" checked="checked" /> DROP INDEX<br/>';
876 echo '<p>' . __('Track these data manipulation statements:') . '</p>';
877 echo '<input type="checkbox" name="insert" value="true" checked="checked" /> INSERT<br/>';
878 echo '<input type="checkbox" name="update" value="true" checked="checked" /> UPDATE<br/>';
879 echo '<input type="checkbox" name="delete" value="true" checked="checked" /> DELETE<br/>';
880 echo '<input type="checkbox" name="truncate" value="true" checked="checked" /> TRUNCATE<br/>';
882 echo '</fieldset>';
883 echo '<fieldset class="tblFooters">';
885 echo '<input type="hidden" name="submit_create_version" value="1" />';
886 echo '<input type="submit" value="' . __('Create version') . '" />';
887 echo '</fieldset>';
888 echo '</form>';
889 echo '</div>';
891 echo '<br class="clearfloat"/>';