Translated using Weblate (Slovenian)
[phpmyadmin.git] / db_tracking.php
blobc8f78379dd42a7c49dedb2eeef4751bb007bae84
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Tracking configuration for database
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\Tracker;
10 /**
11 * Run common work
13 require_once 'libraries/common.inc.php';
15 require_once './libraries/tracking.lib.php';
16 require_once 'libraries/display_create_table.lib.php';
18 //Get some js files needed for Ajax requests
19 $response = PMA\libraries\Response::getInstance();
20 $header = $response->getHeader();
21 $scripts = $header->getScripts();
22 $scripts->addFile('jquery/jquery.tablesorter.js');
23 $scripts->addFile('db_tracking.js');
25 /**
26 * If we are not in an Ajax request, then do the common work and show the links etc.
28 require 'libraries/db_common.inc.php';
29 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
31 // Get the database structure
32 $sub_part = '_structure';
34 list(
35 $tables,
36 $num_tables,
37 $total_num_tables,
38 $sub_part,
39 $is_show_stats,
40 $db_is_system_schema,
41 $tooltip_truename,
42 $tooltip_aliasname,
43 $pos
44 ) = PMA\libraries\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
46 // Work to do?
47 // (here, do not use $_REQUEST['db] as it can be crafted)
48 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
50 Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
51 PMA\libraries\Message::success(
52 __('Tracking data deleted successfully.')
53 )->display();
55 } elseif (isset($_REQUEST['submit_create_version'])) {
57 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
58 PMA\libraries\Message::success(
59 sprintf(
60 __(
61 'Version %1$s was created for selected tables,'
62 . ' tracking is active for them.'
64 htmlspecialchars($_REQUEST['version'])
66 )->display();
68 } elseif (isset($_REQUEST['submit_mult'])) {
70 if (! empty($_REQUEST['selected_tbl'])) {
71 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
73 foreach ($_REQUEST['selected_tbl'] as $table) {
74 Tracker::deleteTracking($GLOBALS['db'], $table);
76 PMA\libraries\Message::success(
77 __('Tracking data deleted successfully.')
78 )->display();
80 } elseif ($_REQUEST['submit_mult'] == 'track') {
82 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
83 'db_tracking.php' . $url_query,
85 $GLOBALS['db'],
86 $_REQUEST['selected_tbl']
88 exit;
90 } else {
91 PMA\libraries\Message::notice(
92 __('No tables selected.')
93 )->display();
97 // Get tracked data about the database
98 $data = Tracker::getTrackedData($_REQUEST['db'], '', '1');
100 // No tables present and no log exist
101 if ($num_tables == 0 && count($data['ddlog']) == 0) {
102 echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
104 if (empty($db_is_system_schema)) {
105 echo PMA_getHtmlForCreateTable($db);
107 exit;
110 // ---------------------------------------------------------------------------
111 $cfgRelation = PMA_getRelationsParam();
113 // Prepare statement to get HEAD version
114 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
115 PMA\libraries\Util::backquote($cfgRelation['db']) . '.' .
116 PMA\libraries\Util::backquote($cfgRelation['tracking']) .
117 ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($_REQUEST['db']) .
118 '\' ' .
119 ' GROUP BY table_name' .
120 ' ORDER BY table_name ASC';
122 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
124 // If a HEAD version exists
125 if (is_object($all_tables_result)
126 && $GLOBALS['dbi']->numRows($all_tables_result) > 0
128 PMA_displayTrackedTables(
129 $GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
130 $text_dir, $cfgRelation
134 $untracked_tables = PMA_getUntrackedTables($GLOBALS['db']);
136 // If untracked tables exist
137 if (count($untracked_tables) > 0) {
138 PMA_displayUntrackedTables(
139 $GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir
142 // If available print out database log
143 if (count($data['ddlog']) > 0) {
144 $log = '';
145 foreach ($data['ddlog'] as $entry) {
146 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
147 . $entry['statement'] . "\n";
149 echo PMA\libraries\Util::getMessage(__('Database Log'), $log);