2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tracking configuration for database
8 declare(strict_types
=1);
10 use PhpMyAdmin\Display\CreateTable
;
11 use PhpMyAdmin\Message
;
12 use PhpMyAdmin\Relation
;
13 use PhpMyAdmin\Response
;
14 use PhpMyAdmin\Tracker
;
15 use PhpMyAdmin\Tracking
;
18 if (! defined('ROOT_PATH')) {
19 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
22 global $db, $pmaThemeImage, $text_dir, $url_query;
24 require_once ROOT_PATH
. 'libraries/common.inc.php';
26 //Get some js files needed for Ajax requests
27 $response = Response
::getInstance();
28 $header = $response->getHeader();
29 $scripts = $header->getScripts();
30 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
31 $scripts->addFile('database/tracking.js');
33 /** @var Tracking $tracking */
34 $tracking = $containerBuilder->get('tracking');
37 * If we are not in an Ajax request, then do the common work and show the links etc.
39 require ROOT_PATH
. 'libraries/db_common.inc.php';
40 $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php';
41 $url_params['goto'] = 'tbl_tracking.php';
42 $url_params['back'] = 'db_tracking.php';
44 // Get the database structure
45 $sub_part = '_structure';
57 ) = Util
::getDbInfo($db, $sub_part === null ?
'' : $sub_part);
59 if (isset($_POST['delete_tracking']) && isset($_POST['table'])) {
60 Tracker
::deleteTracking($db, $_POST['table']);
62 __('Tracking data deleted successfully.')
64 } elseif (isset($_POST['submit_create_version'])) {
65 $tracking->createTrackingForMultipleTables($_POST['selected']);
69 'Version %1$s was created for selected tables,'
70 . ' tracking is active for them.'
72 htmlspecialchars($_POST['version'])
75 } elseif (isset($_POST['submit_mult'])) {
76 if (! empty($_POST['selected_tbl'])) {
77 if ($_POST['submit_mult'] == 'delete_tracking') {
78 foreach ($_POST['selected_tbl'] as $table) {
79 Tracker
::deleteTracking($db, $table);
82 __('Tracking data deleted successfully.')
84 } elseif ($_POST['submit_mult'] == 'track') {
85 echo $tracking->getHtmlForDataDefinitionAndManipulationStatements(
86 'db_tracking.php' . $url_query,
89 $_POST['selected_tbl']
95 __('No tables selected.')
100 // Get tracked data about the database
101 $data = Tracker
::getTrackedData($db, '', '1');
103 // No tables present and no log exist
104 if ($num_tables == 0 && count($data['ddlog']) == 0) {
105 echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
107 if (empty($db_is_system_schema)) {
108 echo CreateTable
::getHtml($db);
113 // ---------------------------------------------------------------------------
114 echo $tracking->getHtmlForDbTrackingTables(
121 // If available print out database log
122 if (count($data['ddlog']) > 0) {
124 foreach ($data['ddlog'] as $entry) {
125 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
126 . $entry['statement'] . "\n";
128 echo Util
::getMessage(__('Database Log'), $log);