2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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')
40 $msg = Message
::notice(
42 __('Tracking of %s is activated.'),
43 htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
46 $response->addHTML($msg->getDisplay());
49 $url_query .= '&goto=tbl_tracking.php&back=tbl_tracking.php';
50 $url_params['goto'] = 'tbl_tracking.php';
51 $url_params['back'] = 'tbl_tracking.php';
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(
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;
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']));
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);
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.')
122 $html .= Message
::notice(
123 __('No versions selected.')
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');
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);
166 if (isset($_POST['snapshot'])) {
167 $html .= $tracking->getHtmlForSchemaSnapshot($url_query);
169 // end of snapshot 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(
197 $html .= $tracking->getHtmlForMainPage(
204 $html .= '<br class="clearfloat">';
206 $response->addHTML($html);