Translated using Weblate (Norwegian Bokmål)
[phpmyadmin.git] / db_tracking.php
blobfb64c6f2b46bce99a66a74de6da39ce5adcdf149
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Tracking configuration for database
6 * @package PhpMyAdmin
7 */
8 use PhpMyAdmin\Display\CreateTable;
9 use PhpMyAdmin\Message;
10 use PhpMyAdmin\Relation;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Tracker;
13 use PhpMyAdmin\Tracking;
14 use PhpMyAdmin\Util;
16 /**
17 * Run common work
19 require_once '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('db_tracking.js');
28 $tracking = new Tracking();
30 /**
31 * If we are not in an Ajax request, then do the common work and show the links etc.
33 require 'libraries/db_common.inc.php';
34 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
36 // Get the database structure
37 $sub_part = '_structure';
39 list(
40 $tables,
41 $num_tables,
42 $total_num_tables,
43 $sub_part,
44 $is_show_stats,
45 $db_is_system_schema,
46 $tooltip_truename,
47 $tooltip_aliasname,
48 $pos
49 ) = Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
51 // Work to do?
52 // (here, do not use $_REQUEST['db] as it can be crafted)
53 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
55 Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
56 Message::success(
57 __('Tracking data deleted successfully.')
58 )->display();
60 } elseif (isset($_REQUEST['submit_create_version'])) {
62 $tracking->createTrackingForMultipleTables($_REQUEST['selected']);
63 Message::success(
64 sprintf(
65 __(
66 'Version %1$s was created for selected tables,'
67 . ' tracking is active for them.'
69 htmlspecialchars($_REQUEST['version'])
71 )->display();
73 } elseif (isset($_REQUEST['submit_mult'])) {
75 if (! empty($_REQUEST['selected_tbl'])) {
76 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
78 foreach ($_REQUEST['selected_tbl'] as $table) {
79 Tracker::deleteTracking($GLOBALS['db'], $table);
81 Message::success(
82 __('Tracking data deleted successfully.')
83 )->display();
85 } elseif ($_REQUEST['submit_mult'] == 'track') {
87 echo $tracking->getHtmlForDataDefinitionAndManipulationStatements(
88 'db_tracking.php' . $url_query,
90 $GLOBALS['db'],
91 $_REQUEST['selected_tbl']
93 exit;
95 } else {
96 Message::notice(
97 __('No tables selected.')
98 )->display();
102 // Get tracked data about the database
103 $data = Tracker::getTrackedData($_REQUEST['db'], '', '1');
105 // No tables present and no log exist
106 if ($num_tables == 0 && count($data['ddlog']) == 0) {
107 echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
109 if (empty($db_is_system_schema)) {
110 echo CreateTable::getHtml($db);
112 exit;
115 // ---------------------------------------------------------------------------
116 $relation = new Relation();
117 $cfgRelation = $relation->getRelationsParam();
119 // Prepare statement to get HEAD version
120 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
121 Util::backquote($cfgRelation['db']) . '.' .
122 Util::backquote($cfgRelation['tracking']) .
123 ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($_REQUEST['db']) .
124 '\' ' .
125 ' GROUP BY table_name' .
126 ' ORDER BY table_name ASC';
128 $all_tables_result = $relation->queryAsControlUser($all_tables_query);
130 // If a HEAD version exists
131 if (is_object($all_tables_result)
132 && $GLOBALS['dbi']->numRows($all_tables_result) > 0
134 echo $tracking->getHtmlForTrackedTables(
135 $GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
136 $text_dir, $cfgRelation
140 $untracked_tables = $tracking->getUntrackedTables($GLOBALS['db']);
142 // If untracked tables exist
143 if (count($untracked_tables) > 0) {
144 echo $tracking->getHtmlForUntrackedTables(
145 $GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir
148 // If available print out database log
149 if (count($data['ddlog']) > 0) {
150 $log = '';
151 foreach ($data['ddlog'] as $entry) {
152 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
153 . $entry['statement'] . "\n";
155 echo Util::getMessage(__('Database Log'), $log);