Translated using Weblate (Turkish)
[phpmyadmin.git] / tbl_tracking.php
blobff2074e95a9c14b0e82b2f6446df27f78c3a73c4
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\Response;
12 use PhpMyAdmin\Tracker;
13 use PhpMyAdmin\Tracking;
15 if (! defined('ROOT_PATH')) {
16 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
19 global $pmaThemeImage, $text_dir, $url_query;
21 require_once ROOT_PATH . 'libraries/common.inc.php';
23 //Get some js files needed for Ajax requests
24 $response = Response::getInstance();
25 $header = $response->getHeader();
26 $scripts = $header->getScripts();
27 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
28 $scripts->addFile('table/tracking.js');
30 define('TABLE_MAY_BE_ABSENT', true);
31 require ROOT_PATH . 'libraries/tbl_common.inc.php';
33 /** @var Tracking $tracking */
34 $tracking = $containerBuilder->get('tracking');
36 if (Tracker::isActive()
37 && Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"])
38 && ! (isset($_POST['toggle_activation'])
39 && $_POST['toggle_activation'] == 'deactivate_now')
40 && ! (isset($_POST['report_export'])
41 && $_POST['export_type'] == 'sqldumpfile')
42 ) {
43 $msg = Message::notice(
44 sprintf(
45 __('Tracking of %s is activated.'),
46 htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
49 $response->addHTML($msg->getDisplay());
52 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
53 $url_params['goto'] = 'tbl_tracking.php';
54 $url_params['back'] = 'tbl_tracking.php';
55 $data = [];
56 $entries = [];
57 $filter_ts_from = '';
58 $filter_ts_to = '';
59 $filter_users = [];
60 $selection_schema = false;
61 $selection_data = false;
62 $selection_both = false;
64 // Init vars for tracking report
65 if (isset($_POST['report']) || isset($_POST['report_export'])) {
66 $data = Tracker::getTrackedData(
67 $GLOBALS['db'],
68 $GLOBALS['table'],
69 $_POST['version']
73 if (! isset($_POST['logtype'])) {
74 $_POST['logtype'] = 'schema_and_data';
76 if ($_POST['logtype'] == 'schema') {
77 $selection_schema = true;
78 } elseif ($_POST['logtype'] == 'data') {
79 $selection_data = true;
80 } else {
81 $selection_both = true;
83 if (! isset($_POST['date_from'])) {
84 $_POST['date_from'] = $data['date_from'];
86 if (! isset($_POST['date_to'])) {
87 $_POST['date_to'] = $data['date_to'];
89 if (! isset($_POST['users'])) {
90 $_POST['users'] = '*';
92 $filter_ts_from = strtotime($_POST['date_from']);
93 $filter_ts_to = strtotime($_POST['date_to']);
94 $filter_users = array_map('trim', explode(',', $_POST['users']));
97 // Prepare export
98 if (isset($_POST['report_export'])) {
99 $entries = $tracking->getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users);
102 // Export as file download
103 if (isset($_POST['report_export'])
104 && $_POST['export_type'] == 'sqldumpfile'
106 $tracking->exportAsFileDownload($entries);
109 $html = '<br>';
112 * Actions
114 if (isset($_POST['submit_mult'])) {
115 if (! empty($_POST['selected_versions'])) {
116 if ($_POST['submit_mult'] == 'delete_version') {
117 foreach ($_POST['selected_versions'] as $version) {
118 $tracking->deleteTrackingVersion($version);
120 $html .= Message::success(
121 __('Tracking versions deleted successfully.')
122 )->getDisplay();
124 } else {
125 $html .= Message::notice(
126 __('No versions selected.')
127 )->getDisplay();
131 if (isset($_POST['submit_delete_version'])) {
132 $html .= $tracking->deleteTrackingVersion($_POST['version']);
135 // Create tracking version
136 if (isset($_POST['submit_create_version'])) {
137 $html .= $tracking->createTrackingVersion();
140 // Deactivate tracking
141 if (isset($_POST['toggle_activation'])
142 && $_POST['toggle_activation'] == 'deactivate_now'
144 $html .= $tracking->changeTracking('deactivate');
147 // Activate tracking
148 if (isset($_POST['toggle_activation'])
149 && $_POST['toggle_activation'] == 'activate_now'
151 $html .= $tracking->changeTracking('activate');
154 // Export as SQL execution
155 if (isset($_POST['report_export']) && $_POST['export_type'] == 'execution') {
156 $sql_result = $tracking->exportAsSqlExecution($entries);
157 $msg = Message::success(__('SQL statements executed.'));
158 $html .= $msg->getDisplay();
161 // Export as SQL dump
162 if (isset($_POST['report_export']) && $_POST['export_type'] == 'sqldump') {
163 $html .= $tracking->exportAsSqlDump($entries);
167 * Schema snapshot
169 if (isset($_POST['snapshot'])) {
170 $html .= $tracking->getHtmlForSchemaSnapshot($url_query);
172 // end of snapshot report
175 * Tracking report
177 if (isset($_POST['report'])
178 && (isset($_POST['delete_ddlog']) || isset($_POST['delete_dmlog']))
180 $html .= $tracking->deleteTrackingReportRows($data);
183 if (isset($_POST['report']) || isset($_POST['report_export'])) {
184 $html .= $tracking->getHtmlForTrackingReport(
185 $url_query,
186 $data,
187 $url_params,
188 $selection_schema,
189 $selection_data,
190 $selection_both,
191 $filter_ts_to,
192 $filter_ts_from,
193 $filter_users
195 } // end of report
198 * Main page
200 $html .= $tracking->getHtmlForMainPage(
201 $url_query,
202 $url_params,
203 $pmaThemeImage,
204 $text_dir
207 $html .= '<br class="clearfloat">';
209 $response->addHTML($html);