Fix #15592 - Warning: error_reporting() has been disabled for security reasons
[phpmyadmin.git] / tbl_tracking.php
blobc5218547fe69e73a960c3cd144b6d639621eae71
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table tracking page
6 * @package PhpMyAdmin
7 */
8 use PhpMyAdmin\Message;
9 use PhpMyAdmin\Tracker;
10 use PhpMyAdmin\Tracking;
11 use PhpMyAdmin\Response;
13 require_once './libraries/common.inc.php';
15 //Get some js files needed for Ajax requests
16 $response = Response::getInstance();
17 $header = $response->getHeader();
18 $scripts = $header->getScripts();
19 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
20 $scripts->addFile('tbl_tracking.js');
22 define('TABLE_MAY_BE_ABSENT', true);
23 require './libraries/tbl_common.inc.php';
25 if (Tracker::isActive()
26 && Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"])
27 && ! (isset($_POST['toggle_activation'])
28 && $_POST['toggle_activation'] == 'deactivate_now')
29 && ! (isset($_POST['report_export'])
30 && $_POST['export_type'] == 'sqldumpfile')
31 ) {
32 $msg = Message::notice(
33 sprintf(
34 __('Tracking of %s is activated.'),
35 htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
38 $response->addHTML($msg->getDisplay());
41 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
42 $url_params['goto'] = 'tbl_tracking.php';
43 $url_params['back'] = 'tbl_tracking.php';
45 // Init vars for tracking report
46 if (isset($_POST['report']) || isset($_POST['report_export'])) {
47 $data = Tracker::getTrackedData(
48 $GLOBALS['db'], $GLOBALS['table'], $_POST['version']
51 $selection_schema = false;
52 $selection_data = false;
53 $selection_both = false;
55 if (! isset($_POST['logtype'])) {
56 $_POST['logtype'] = 'schema_and_data';
58 if ($_POST['logtype'] == 'schema') {
59 $selection_schema = true;
60 } elseif ($_POST['logtype'] == 'data') {
61 $selection_data = true;
62 } else {
63 $selection_both = true;
65 if (! isset($_POST['date_from'])) {
66 $_POST['date_from'] = $data['date_from'];
68 if (! isset($_POST['date_to'])) {
69 $_POST['date_to'] = $data['date_to'];
71 if (! isset($_POST['users'])) {
72 $_POST['users'] = '*';
74 $filter_ts_from = strtotime($_POST['date_from']);
75 $filter_ts_to = strtotime($_POST['date_to']);
76 $filter_users = array_map('trim', explode(',', $_POST['users']));
79 // Prepare export
80 if (isset($_POST['report_export'])) {
81 $entries = Tracking::getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users);
84 // Export as file download
85 if (isset($_POST['report_export'])
86 && $_POST['export_type'] == 'sqldumpfile'
87 ) {
88 Tracking::exportAsFileDownload($entries);
91 $html = '<br />';
93 /**
94 * Actions
96 if (isset($_POST['submit_mult'])) {
97 if (! empty($_POST['selected_versions'])) {
98 if ($_POST['submit_mult'] == 'delete_version') {
99 foreach ($_POST['selected_versions'] as $version) {
100 Tracking::deleteTrackingVersion($version);
102 $html .= Message::success(
103 __('Tracking versions deleted successfully.')
104 )->getDisplay();
106 } else {
107 $html .= Message::notice(
108 __('No versions selected.')
109 )->getDisplay();
113 if (isset($_POST['submit_delete_version'])) {
114 $html .= Tracking::deleteTrackingVersion($_POST['version']);
117 // Create tracking version
118 if (isset($_POST['submit_create_version'])) {
119 $html .= Tracking::createTrackingVersion();
122 // Deactivate tracking
123 if (isset($_POST['toggle_activation'])
124 && $_POST['toggle_activation'] == 'deactivate_now'
126 $html .= Tracking::changeTracking('deactivate');
129 // Activate tracking
130 if (isset($_POST['toggle_activation'])
131 && $_POST['toggle_activation'] == 'activate_now'
133 $html .= Tracking::changeTracking('activate');
136 // Export as SQL execution
137 if (isset($_POST['report_export']) && $_POST['export_type'] == 'execution') {
138 $sql_result = Tracking::exportAsSqlExecution($entries);
139 $msg = Message::success(__('SQL statements executed.'));
140 $html .= $msg->getDisplay();
143 // Export as SQL dump
144 if (isset($_POST['report_export']) && $_POST['export_type'] == 'sqldump') {
145 $html .= Tracking::exportAsSqlDump($entries);
149 * Schema snapshot
151 if (isset($_POST['snapshot'])) {
152 $html .= Tracking::getHtmlForSchemaSnapshot($url_query);
154 // end of snapshot report
157 * Tracking report
159 if (isset($_POST['report'])
160 && (isset($_POST['delete_ddlog']) || isset($_POST['delete_dmlog']))
162 $html .= Tracking::deleteTrackingReportRows($data);
165 if (isset($_POST['report']) || isset($_POST['report_export'])) {
166 $html .= Tracking::getHtmlForTrackingReport(
167 $url_query, $data, $url_params, $selection_schema, $selection_data,
168 $selection_both, $filter_ts_to, $filter_ts_from, $filter_users
170 } // end of report
173 * List selectable tables
175 $selectable_tables_sql_result = Tracking::getSqlResultForSelectableTables();
176 if ($GLOBALS['dbi']->numRows($selectable_tables_sql_result) > 0) {
177 $html .= Tracking::getHtmlForSelectableTables(
178 $selectable_tables_sql_result, $url_query
181 $html .= '<br />';
184 * List versions of current table
186 $sql_result = Tracking::getListOfVersionsOfTable();
187 $last_version = Tracking::getTableLastVersionNumber($sql_result);
188 if ($last_version > 0) {
189 $html .= Tracking::getHtmlForTableVersionDetails(
190 $sql_result, $last_version, $url_params,
191 $url_query, $pmaThemeImage, $text_dir
195 $type = $GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])
196 ->isView() ? 'view' : 'table';
197 $html .= Tracking::getHtmlForDataDefinitionAndManipulationStatements(
198 'tbl_tracking.php' . $url_query,
199 $last_version,
200 $GLOBALS['db'],
201 array($GLOBALS['table']),
202 $type
205 $html .= '<br class="clearfloat"/>';
207 $response->addHTML($html);