2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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')
43 $msg = Message
::notice(
45 __('Tracking of %s is activated.'),
46 htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
49 $response->addHTML($msg->getDisplay());
52 $url_query .= '&goto=tbl_tracking.php&back=tbl_tracking.php';
53 $url_params['goto'] = 'tbl_tracking.php';
54 $url_params['back'] = 'tbl_tracking.php';
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(
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;
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']));
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);
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.')
125 $html .= Message
::notice(
126 __('No versions selected.')
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');
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);
169 if (isset($_POST['snapshot'])) {
170 $html .= $tracking->getHtmlForSchemaSnapshot($url_query);
172 // end of snapshot 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(
200 $html .= $tracking->getHtmlForMainPage(
207 $html .= '<br class="clearfloat">';
209 $response->addHTML($html);