Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / tbl_tracking.php
blobf4e23c42c813aa3b8350a40935b9a85b28a6a014
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table tracking page
6 * @package PhpMyAdmin
7 */
9 // Run common work
10 use PMA\libraries\Tracker;
12 require_once './libraries/common.inc.php';
14 require_once './libraries/tracking.lib.php';
16 //Get some js files needed for Ajax requests
17 $response = PMA\libraries\Response::getInstance();
18 $header = $response->getHeader();
19 $scripts = $header->getScripts();
20 $scripts->addFile('jquery/jquery.tablesorter.js');
21 $scripts->addFile('tbl_tracking.js');
23 define('TABLE_MAY_BE_ABSENT', true);
24 require './libraries/tbl_common.inc.php';
26 if (Tracker::isActive()
27 && Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"])
28 && ! (isset($_REQUEST['toggle_activation'])
29 && $_REQUEST['toggle_activation'] == 'deactivate_now')
30 && ! (isset($_REQUEST['report_export'])
31 && $_REQUEST['export_type'] == 'sqldumpfile')
32 ) {
33 $msg = PMA\libraries\Message::notice(
34 sprintf(
35 __('Tracking of %s is activated.'),
36 htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
39 PMA\libraries\Response::getInstance()->addHTML($msg->getDisplay());
42 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
43 $url_params['goto'] = 'tbl_tracking.php';
44 $url_params['back'] = 'tbl_tracking.php';
46 // Init vars for tracking report
47 if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) {
48 $data = Tracker::getTrackedData(
49 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
52 $selection_schema = false;
53 $selection_data = false;
54 $selection_both = false;
56 if (! isset($_REQUEST['logtype'])) {
57 $_REQUEST['logtype'] = 'schema_and_data';
59 if ($_REQUEST['logtype'] == 'schema') {
60 $selection_schema = true;
61 } elseif ($_REQUEST['logtype'] == 'data') {
62 $selection_data = true;
63 } else {
64 $selection_both = true;
66 if (! isset($_REQUEST['date_from'])) {
67 $_REQUEST['date_from'] = $data['date_from'];
69 if (! isset($_REQUEST['date_to'])) {
70 $_REQUEST['date_to'] = $data['date_to'];
72 if (! isset($_REQUEST['users'])) {
73 $_REQUEST['users'] = '*';
75 $filter_ts_from = strtotime($_REQUEST['date_from']);
76 $filter_ts_to = strtotime($_REQUEST['date_to']);
77 $filter_users = array_map('trim', explode(',', $_REQUEST['users']));
80 // Prepare export
81 if (isset($_REQUEST['report_export'])) {
82 $entries = PMA_getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users);
85 // Export as file download
86 if (isset($_REQUEST['report_export'])
87 && $_REQUEST['export_type'] == 'sqldumpfile'
88 ) {
89 PMA_exportAsFileDownload($entries);
92 $html = '<br />';
94 /**
95 * Actions
97 if (isset($_REQUEST['submit_mult'])) {
98 if (! empty($_REQUEST['selected_versions'])) {
99 if ($_REQUEST['submit_mult'] == 'delete_version') {
100 foreach ($_REQUEST['selected_versions'] as $version) {
101 PMA_deleteTrackingVersion($version);
103 $html .= PMA\libraries\Message::success(
104 __('Tracking versions deleted successfully.')
105 )->getDisplay();
107 } else {
108 $html .= PMA\libraries\Message::notice(
109 __('No versions selected.')
110 )->getDisplay();
114 if (isset($_REQUEST['submit_delete_version'])) {
115 $html .= PMA_deleteTrackingVersion($_REQUEST['version']);
118 // Create tracking version
119 if (isset($_REQUEST['submit_create_version'])) {
120 $html .= PMA_createTrackingVersion();
123 // Deactivate tracking
124 if (isset($_REQUEST['toggle_activation'])
125 && $_REQUEST['toggle_activation'] == 'deactivate_now'
127 $html .= PMA_changeTracking('deactivate');
130 // Activate tracking
131 if (isset($_REQUEST['toggle_activation'])
132 && $_REQUEST['toggle_activation'] == 'activate_now'
134 $html .= PMA_changeTracking('activate');
137 // Export as SQL execution
138 if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'execution') {
139 $sql_result = PMA_exportAsSQLExecution($entries);
140 $msg = PMA\libraries\Message::success(__('SQL statements executed.'));
141 $html .= $msg->getDisplay();
144 // Export as SQL dump
145 if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldump') {
146 $html .= PMA_exportAsSQLDump($entries);
150 * Schema snapshot
152 if (isset($_REQUEST['snapshot'])) {
153 $html .= PMA_getHtmlForSchemaSnapshot($url_query);
155 // end of snapshot report
158 * Tracking report
160 if (isset($_REQUEST['report'])
161 && (isset($_REQUEST['delete_ddlog']) || isset($_REQUEST['delete_dmlog']))
163 $html .= PMA_deleteTrackingReportRows($data);
166 if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) {
167 $html .= PMA_getHtmlForTrackingReport(
168 $url_query, $data, $url_params, $selection_schema, $selection_data,
169 $selection_both, $filter_ts_to, $filter_ts_from, $filter_users
171 } // end of report
175 * List selectable tables
177 $selectable_tables_sql_result = PMA_getSQLResultForSelectableTables();
178 if ($GLOBALS['dbi']->numRows($selectable_tables_sql_result) > 0) {
179 $html .= PMA_getHtmlForSelectableTables(
180 $selectable_tables_sql_result, $url_query
183 $html .= '<br />';
186 * List versions of current table
188 $sql_result = PMA_getListOfVersionsOfTable();
189 $last_version = PMA_getTableLastVersionNumber($sql_result);
190 if ($last_version > 0) {
191 $html .= PMA_getHtmlForTableVersionDetails(
192 $sql_result, $last_version, $url_params,
193 $url_query, $pmaThemeImage, $text_dir
197 $type = $GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])
198 ->isView() ? 'view' : 'table';
199 $html .= PMA_getHtmlForDataDefinitionAndManipulationStatements(
200 'tbl_tracking.php' . $url_query,
201 $last_version,
202 $GLOBALS['db'],
203 array($GLOBALS['table']),
204 $type
207 $html .= '<br class="clearfloat"/>';
209 $response = PMA\libraries\Response::getInstance();
210 $response->addHTML($html);