Translated using Weblate (Estonian)
[phpmyadmin.git] / tbl_tracking.php
blobed23b881a4a8373b31595c65d32505e2461d7b23
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table tracking page
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Message;
11 use PhpMyAdmin\Tracker;
12 use PhpMyAdmin\Tracking;
13 use PhpMyAdmin\Response;
15 if (! defined('ROOT_PATH')) {
16 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
19 require_once ROOT_PATH . 'libraries/common.inc.php';
21 //Get some js files needed for Ajax requests
22 $response = Response::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
26 $scripts->addFile('tbl_tracking.js');
28 define('TABLE_MAY_BE_ABSENT', true);
29 require ROOT_PATH . 'libraries/tbl_common.inc.php';
31 $tracking = new Tracking();
33 if (Tracker::isActive()
34 && Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"])
35 && ! (isset($_POST['toggle_activation'])
36 && $_POST['toggle_activation'] == 'deactivate_now')
37 && ! (isset($_POST['report_export'])
38 && $_POST['export_type'] == 'sqldumpfile')
39 ) {
40 $msg = Message::notice(
41 sprintf(
42 __('Tracking of %s is activated.'),
43 htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
46 $response->addHTML($msg->getDisplay());
49 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
50 $url_params['goto'] = 'tbl_tracking.php';
51 $url_params['back'] = 'tbl_tracking.php';
52 $data = [];
53 $entries = [];
54 $filter_ts_from = '';
55 $filter_ts_to = '';
56 $filter_users = [];
57 $selection_schema = false;
58 $selection_data = false;
59 $selection_both = false;
61 // Init vars for tracking report
62 if (isset($_POST['report']) || isset($_POST['report_export'])) {
63 $data = Tracker::getTrackedData(
64 $GLOBALS['db'],
65 $GLOBALS['table'],
66 $_POST['version']
70 if (! isset($_POST['logtype'])) {
71 $_POST['logtype'] = 'schema_and_data';
73 if ($_POST['logtype'] == 'schema') {
74 $selection_schema = true;
75 } elseif ($_POST['logtype'] == 'data') {
76 $selection_data = true;
77 } else {
78 $selection_both = true;
80 if (! isset($_POST['date_from'])) {
81 $_POST['date_from'] = $data['date_from'];
83 if (! isset($_POST['date_to'])) {
84 $_POST['date_to'] = $data['date_to'];
86 if (! isset($_POST['users'])) {
87 $_POST['users'] = '*';
89 $filter_ts_from = strtotime($_POST['date_from']);
90 $filter_ts_to = strtotime($_POST['date_to']);
91 $filter_users = array_map('trim', explode(',', $_POST['users']));
94 // Prepare export
95 if (isset($_POST['report_export'])) {
96 $entries = $tracking->getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users);
99 // Export as file download
100 if (isset($_POST['report_export'])
101 && $_POST['export_type'] == 'sqldumpfile'
103 $tracking->exportAsFileDownload($entries);
106 $html = '<br>';
109 * Actions
111 if (isset($_POST['submit_mult'])) {
112 if (! empty($_POST['selected_versions'])) {
113 if ($_POST['submit_mult'] == 'delete_version') {
114 foreach ($_POST['selected_versions'] as $version) {
115 $tracking->deleteTrackingVersion($version);
117 $html .= Message::success(
118 __('Tracking versions deleted successfully.')
119 )->getDisplay();
121 } else {
122 $html .= Message::notice(
123 __('No versions selected.')
124 )->getDisplay();
128 if (isset($_POST['submit_delete_version'])) {
129 $html .= $tracking->deleteTrackingVersion($_POST['version']);
132 // Create tracking version
133 if (isset($_POST['submit_create_version'])) {
134 $html .= $tracking->createTrackingVersion();
137 // Deactivate tracking
138 if (isset($_POST['toggle_activation'])
139 && $_POST['toggle_activation'] == 'deactivate_now'
141 $html .= $tracking->changeTracking('deactivate');
144 // Activate tracking
145 if (isset($_POST['toggle_activation'])
146 && $_POST['toggle_activation'] == 'activate_now'
148 $html .= $tracking->changeTracking('activate');
151 // Export as SQL execution
152 if (isset($_POST['report_export']) && $_POST['export_type'] == 'execution') {
153 $sql_result = $tracking->exportAsSqlExecution($entries);
154 $msg = Message::success(__('SQL statements executed.'));
155 $html .= $msg->getDisplay();
158 // Export as SQL dump
159 if (isset($_POST['report_export']) && $_POST['export_type'] == 'sqldump') {
160 $html .= $tracking->exportAsSqlDump($entries);
164 * Schema snapshot
166 if (isset($_POST['snapshot'])) {
167 $html .= $tracking->getHtmlForSchemaSnapshot($url_query);
169 // end of snapshot report
172 * Tracking report
174 if (isset($_POST['report'])
175 && (isset($_POST['delete_ddlog']) || isset($_POST['delete_dmlog']))
177 $html .= $tracking->deleteTrackingReportRows($data);
180 if (isset($_POST['report']) || isset($_POST['report_export'])) {
181 $html .= $tracking->getHtmlForTrackingReport(
182 $url_query,
183 $data,
184 $url_params,
185 $selection_schema,
186 $selection_data,
187 $selection_both,
188 $filter_ts_to,
189 $filter_ts_from,
190 $filter_users
192 } // end of report
195 * Main page
197 $html .= $tracking->getHtmlForMainPage(
198 $url_query,
199 $url_params,
200 $pmaThemeImage,
201 $text_dir
204 $html .= '<br class="clearfloat">';
206 $response->addHTML($html);