Translated using Weblate (Lithuanian)
[phpmyadmin.git] / db_tracking.php
blob49e4048025c2201591a2ce657a401baf8e77c5e5
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 /**
29 * If we are not in an Ajax request, then do the common work and show the links etc.
31 require 'libraries/db_common.inc.php';
32 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
33 $url_params['goto'] = 'tbl_tracking.php';
34 $url_params['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 if (isset($_POST['delete_tracking']) && isset($_POST['table'])) {
53 Tracker::deleteTracking($GLOBALS['db'], $_POST['table']);
54 Message::success(
55 __('Tracking data deleted successfully.')
56 )->display();
58 } elseif (isset($_POST['submit_create_version'])) {
60 Tracking::createTrackingForMultipleTables($_POST['selected']);
61 Message::success(
62 sprintf(
63 __(
64 'Version %1$s was created for selected tables,'
65 . ' tracking is active for them.'
67 htmlspecialchars($_POST['version'])
69 )->display();
71 } elseif (isset($_POST['submit_mult'])) {
73 if (! empty($_POST['selected_tbl'])) {
74 if ($_POST['submit_mult'] == 'delete_tracking') {
76 foreach ($_POST['selected_tbl'] as $table) {
77 Tracker::deleteTracking($GLOBALS['db'], $table);
79 Message::success(
80 __('Tracking data deleted successfully.')
81 )->display();
83 } elseif ($_POST['submit_mult'] == 'track') {
85 echo Tracking::getHtmlForDataDefinitionAndManipulationStatements(
86 'db_tracking.php' . $url_query,
88 $GLOBALS['db'],
89 $_POST['selected_tbl']
91 exit;
93 } else {
94 Message::notice(
95 __('No tables selected.')
96 )->display();
100 // Get tracked data about the database
101 $data = Tracker::getTrackedData($GLOBALS['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);
110 exit;
113 // ---------------------------------------------------------------------------
114 $relation = new Relation();
115 $cfgRelation = $relation->getRelationsParam();
117 // Prepare statement to get HEAD version
118 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
119 Util::backquote($cfgRelation['db']) . '.' .
120 Util::backquote($cfgRelation['tracking']) .
121 ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($GLOBALS['db']) .
122 '\' ' .
123 ' GROUP BY table_name' .
124 ' ORDER BY table_name ASC';
126 $all_tables_result = $relation->queryAsControlUser($all_tables_query);
128 // If a HEAD version exists
129 if (is_object($all_tables_result)
130 && $GLOBALS['dbi']->numRows($all_tables_result) > 0
132 echo Tracking::getHtmlForTrackedTables(
133 $GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
134 $text_dir, $cfgRelation
138 $untracked_tables = Tracking::getUntrackedTables($GLOBALS['db']);
140 // If untracked tables exist
141 if (count($untracked_tables) > 0) {
142 echo Tracking::getHtmlForUntrackedTables(
143 $GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir
146 // If available print out database log
147 if (count($data['ddlog']) > 0) {
148 $log = '';
149 foreach ($data['ddlog'] as $entry) {
150 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
151 . $entry['statement'] . "\n";
153 echo Util::getMessage(__('Database Log'), $log);