devilbox/.devilbox/www/htdocs/vendor/phpmyadmin-4.8.4/tbl_tracking.php

208 lines
5.7 KiB
PHP
Raw Normal View History

2016-10-22 14:57:10 +00:00
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Table tracking page
*
* @package PhpMyAdmin
*/
2018-04-14 09:18:00 +00:00
use PhpMyAdmin\Message;
use PhpMyAdmin\Tracker;
use PhpMyAdmin\Tracking;
use PhpMyAdmin\Response;
2016-10-22 14:57:10 +00:00
require_once './libraries/common.inc.php';
//Get some js files needed for Ajax requests
$response = Response::getInstance();
2016-10-22 14:57:10 +00:00
$header = $response->getHeader();
$scripts = $header->getScripts();
2018-04-14 09:18:00 +00:00
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
2016-10-22 14:57:10 +00:00
$scripts->addFile('tbl_tracking.js');
define('TABLE_MAY_BE_ABSENT', true);
require './libraries/tbl_common.inc.php';
if (Tracker::isActive()
&& Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"])
2018-12-16 14:31:03 +00:00
&& ! (isset($_POST['toggle_activation'])
&& $_POST['toggle_activation'] == 'deactivate_now')
&& ! (isset($_POST['report_export'])
&& $_POST['export_type'] == 'sqldumpfile')
2016-10-22 14:57:10 +00:00
) {
2018-04-14 09:18:00 +00:00
$msg = Message::notice(
2016-10-22 14:57:10 +00:00
sprintf(
__('Tracking of %s is activated.'),
htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
)
);
$response->addHTML($msg->getDisplay());
2016-10-22 14:57:10 +00:00
}
$url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
$url_params['goto'] = 'tbl_tracking.php';
$url_params['back'] = 'tbl_tracking.php';
// Init vars for tracking report
2018-12-16 14:31:03 +00:00
if (isset($_POST['report']) || isset($_POST['report_export'])) {
2016-10-22 14:57:10 +00:00
$data = Tracker::getTrackedData(
2018-12-16 14:31:03 +00:00
$GLOBALS['db'], $GLOBALS['table'], $_POST['version']
2016-10-22 14:57:10 +00:00
);
$selection_schema = false;
$selection_data = false;
$selection_both = false;
2018-12-16 14:31:03 +00:00
if (! isset($_POST['logtype'])) {
$_POST['logtype'] = 'schema_and_data';
2016-10-22 14:57:10 +00:00
}
2018-12-16 14:31:03 +00:00
if ($_POST['logtype'] == 'schema') {
2016-10-22 14:57:10 +00:00
$selection_schema = true;
2018-12-16 14:31:03 +00:00
} elseif ($_POST['logtype'] == 'data') {
2016-10-22 14:57:10 +00:00
$selection_data = true;
} else {
$selection_both = true;
}
2018-12-16 14:31:03 +00:00
if (! isset($_POST['date_from'])) {
$_POST['date_from'] = $data['date_from'];
2016-10-22 14:57:10 +00:00
}
2018-12-16 14:31:03 +00:00
if (! isset($_POST['date_to'])) {
$_POST['date_to'] = $data['date_to'];
2016-10-22 14:57:10 +00:00
}
2018-12-16 14:31:03 +00:00
if (! isset($_POST['users'])) {
$_POST['users'] = '*';
2016-10-22 14:57:10 +00:00
}
2018-12-16 14:31:03 +00:00
$filter_ts_from = strtotime($_POST['date_from']);
$filter_ts_to = strtotime($_POST['date_to']);
$filter_users = array_map('trim', explode(',', $_POST['users']));
2016-10-22 14:57:10 +00:00
}
// Prepare export
2018-12-16 14:31:03 +00:00
if (isset($_POST['report_export'])) {
2018-04-14 09:18:00 +00:00
$entries = Tracking::getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users);
2016-10-22 14:57:10 +00:00
}
// Export as file download
2018-12-16 14:31:03 +00:00
if (isset($_POST['report_export'])
&& $_POST['export_type'] == 'sqldumpfile'
2016-10-22 14:57:10 +00:00
) {
2018-04-14 09:18:00 +00:00
Tracking::exportAsFileDownload($entries);
2016-10-22 14:57:10 +00:00
}
$html = '<br />';
/**
* Actions
*/
2018-12-16 14:31:03 +00:00
if (isset($_POST['submit_mult'])) {
if (! empty($_POST['selected_versions'])) {
if ($_POST['submit_mult'] == 'delete_version') {
foreach ($_POST['selected_versions'] as $version) {
2018-04-14 09:18:00 +00:00
Tracking::deleteTrackingVersion($version);
2016-10-22 14:57:10 +00:00
}
2018-04-14 09:18:00 +00:00
$html .= Message::success(
2016-10-22 14:57:10 +00:00
__('Tracking versions deleted successfully.')
)->getDisplay();
}
} else {
2018-04-14 09:18:00 +00:00
$html .= Message::notice(
2016-10-22 14:57:10 +00:00
__('No versions selected.')
)->getDisplay();
}
}
2018-12-16 14:31:03 +00:00
if (isset($_POST['submit_delete_version'])) {
$html .= Tracking::deleteTrackingVersion($_POST['version']);
2016-10-22 14:57:10 +00:00
}
// Create tracking version
2018-12-16 14:31:03 +00:00
if (isset($_POST['submit_create_version'])) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::createTrackingVersion();
2016-10-22 14:57:10 +00:00
}
// Deactivate tracking
2018-12-16 14:31:03 +00:00
if (isset($_POST['toggle_activation'])
&& $_POST['toggle_activation'] == 'deactivate_now'
2016-10-22 14:57:10 +00:00
) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::changeTracking('deactivate');
2016-10-22 14:57:10 +00:00
}
// Activate tracking
2018-12-16 14:31:03 +00:00
if (isset($_POST['toggle_activation'])
&& $_POST['toggle_activation'] == 'activate_now'
2016-10-22 14:57:10 +00:00
) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::changeTracking('activate');
2016-10-22 14:57:10 +00:00
}
// Export as SQL execution
2018-12-16 14:31:03 +00:00
if (isset($_POST['report_export']) && $_POST['export_type'] == 'execution') {
2018-04-14 09:18:00 +00:00
$sql_result = Tracking::exportAsSqlExecution($entries);
$msg = Message::success(__('SQL statements executed.'));
2016-10-22 14:57:10 +00:00
$html .= $msg->getDisplay();
}
// Export as SQL dump
2018-12-16 14:31:03 +00:00
if (isset($_POST['report_export']) && $_POST['export_type'] == 'sqldump') {
2018-04-14 09:18:00 +00:00
$html .= Tracking::exportAsSqlDump($entries);
2016-10-22 14:57:10 +00:00
}
/*
* Schema snapshot
*/
2018-12-16 14:31:03 +00:00
if (isset($_POST['snapshot'])) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::getHtmlForSchemaSnapshot($url_query);
2016-10-22 14:57:10 +00:00
}
// end of snapshot report
/*
* Tracking report
*/
2018-12-16 14:31:03 +00:00
if (isset($_POST['report'])
&& (isset($_POST['delete_ddlog']) || isset($_POST['delete_dmlog']))
2016-10-22 14:57:10 +00:00
) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::deleteTrackingReportRows($data);
2016-10-22 14:57:10 +00:00
}
2018-12-16 14:31:03 +00:00
if (isset($_POST['report']) || isset($_POST['report_export'])) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::getHtmlForTrackingReport(
2016-10-22 14:57:10 +00:00
$url_query, $data, $url_params, $selection_schema, $selection_data,
$selection_both, $filter_ts_to, $filter_ts_from, $filter_users
);
} // end of report
/*
* List selectable tables
*/
2018-04-14 09:18:00 +00:00
$selectable_tables_sql_result = Tracking::getSqlResultForSelectableTables();
2016-10-22 14:57:10 +00:00
if ($GLOBALS['dbi']->numRows($selectable_tables_sql_result) > 0) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::getHtmlForSelectableTables(
2016-10-22 14:57:10 +00:00
$selectable_tables_sql_result, $url_query
);
}
$html .= '<br />';
/*
* List versions of current table
*/
2018-04-14 09:18:00 +00:00
$sql_result = Tracking::getListOfVersionsOfTable();
$last_version = Tracking::getTableLastVersionNumber($sql_result);
2016-10-22 14:57:10 +00:00
if ($last_version > 0) {
2018-04-14 09:18:00 +00:00
$html .= Tracking::getHtmlForTableVersionDetails(
2016-10-22 14:57:10 +00:00
$sql_result, $last_version, $url_params,
$url_query, $pmaThemeImage, $text_dir
);
}
$type = $GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])
->isView() ? 'view' : 'table';
2018-04-14 09:18:00 +00:00
$html .= Tracking::getHtmlForDataDefinitionAndManipulationStatements(
2016-10-22 14:57:10 +00:00
'tbl_tracking.php' . $url_query,
$last_version,
$GLOBALS['db'],
array($GLOBALS['table']),
$type
);
$html .= '<br class="clearfloat"/>';
$response->addHTML($html);