Translated using Weblate (Slovak)
[phpmyadmin.git] / db_tracking.php
blob5bb4ff5c7666cc2b26d5186b0b150a8e9f1a8dad
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Tracking configuration for database
6 * @package PhpMyAdmin
7 */
9 /**
10 * Run common work
12 require_once 'libraries/common.inc.php';
14 require_once './libraries/tracking.lib.php';
16 //Get some js files needed for Ajax requests
17 $response = PMA_Response::getInstance();
18 $header = $response->getHeader();
19 $scripts = $header->getScripts();
20 $scripts->addFile('db_tracking.js');
22 /**
23 * If we are not in an Ajax request, then do the common work and show the links etc.
25 require 'libraries/db_common.inc.php';
26 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
28 // Get the database structure
29 $sub_part = '_structure';
30 require 'libraries/db_info.inc.php';
32 // Work to do?
33 // (here, do not use $_REQUEST['db] as it can be crafted)
34 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
36 PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
37 PMA_Message::success(
38 __('Tracking data deleted successfully.')
39 )->display();
41 } elseif (isset($_REQUEST['submit_create_version'])) {
43 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
44 PMA_Message::success(
45 sprintf(
46 __(
47 'Version %1$s was created for selected tables,'
48 . ' tracking is active for them.'
50 htmlspecialchars($_REQUEST['version'])
52 )->display();
54 } elseif (isset($_REQUEST['submit_mult'])) {
56 if (! empty($_REQUEST['selected_tbl'])) {
57 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
59 foreach ($_REQUEST['selected_tbl'] as $table) {
60 PMA_Tracker::deleteTracking($GLOBALS['db'], $table);
62 PMA_Message::success(
63 __('Tracking data deleted successfully.')
64 )->display();
66 } elseif ($_REQUEST['submit_mult'] == 'track') {
68 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
69 'db_tracking.php' . $url_query,
71 $GLOBALS['db'],
72 $_REQUEST['selected_tbl']
74 exit;
76 } else {
77 PMA_Message::notice(
78 __('No tables selected.')
79 )->display();
83 // Get tracked data about the database
84 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
86 // No tables present and no log exist
87 if ($num_tables == 0 && count($data['ddlog']) == 0) {
88 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
90 if (empty($db_is_system_schema)) {
91 include 'libraries/display_create_table.lib.php';
93 exit;
96 // ---------------------------------------------------------------------------
97 $cfgRelation = PMA_getRelationsParam();
99 // Prepare statement to get HEAD version
100 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
101 PMA_Util::backquote($cfgRelation['db']) . '.' .
102 PMA_Util::backquote($cfgRelation['tracking']) .
103 ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
104 ' GROUP BY table_name' .
105 ' ORDER BY table_name ASC';
107 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
109 // If a HEAD version exists
110 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
112 <div id="tracked_tables">
113 <h3><?php echo __('Tracked tables');?></h3>
115 <form method="post" action="db_tracking.php" name="trackedForm"
116 id="trackedForm" class="ajax">
117 <?php
118 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
120 <table id="versions" class="data">
121 <thead>
122 <tr>
123 <th></th>
124 <th><?php echo __('Table');?></th>
125 <th><?php echo __('Last version');?></th>
126 <th><?php echo __('Created');?></th>
127 <th><?php echo __('Updated');?></th>
128 <th><?php echo __('Status');?></th>
129 <th><?php echo __('Action');?></th>
130 <th><?php echo __('Show');?></th>
131 </tr>
132 </thead>
133 <tbody>
134 <?php
136 // Print out information about versions
138 $delete_image_or_text = '';
139 if (PMA_Util::showIcons('ActionLinksMode')) {
140 $delete_image_or_text .= PMA_Util::getImage(
141 'b_drop.png',
142 __('Delete tracking data for this table')
145 if (PMA_Util::showText('ActionLinksMode')) {
146 $delete_image_or_text .= __('Delete tracking');
149 $style = 'odd';
150 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
151 list($table_name, $version_number) = $one_result;
152 $table_query = ' SELECT * FROM ' .
153 PMA_Util::backquote($cfgRelation['db']) . '.' .
154 PMA_Util::backquote($cfgRelation['tracking']) .
155 ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db'])
156 . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table_name)
157 . '\' AND `version` = \'' . $version_number . '\'';
159 $table_result = PMA_queryAsControlUser($table_query);
160 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
162 $tmp_link = 'tbl_tracking.php' . $url_query . '&amp;table='
163 . htmlspecialchars($version_data['table_name']);
164 $delete_link = 'db_tracking.php' . $url_query . '&amp;table='
165 . htmlspecialchars($version_data['table_name'])
166 . '&amp;delete_tracking=true&amp';
168 <tr class="noclick <?php echo $style;?>">
169 <td class="center">
170 <input type="checkbox" name="selected_tbl[]" class="checkall"
171 value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
172 </td>
173 <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
174 <td><?php echo $version_data['version'];?></td>
175 <td><?php echo $version_data['date_created'];?></td>
176 <td><?php echo $version_data['date_updated'];?></td>
177 <td><?php echo PMA_getVersionStatus($version_data);?></td>
178 <td>
179 <a class="delete_tracking_anchor ajax" href="<?php echo $delete_link;?>" >
180 <?php echo $delete_image_or_text; ?></a>
181 <?php
182 echo '</td>'
183 . '<td>'
184 . '<a href="' . $tmp_link . '">' . __('Versions') . '</a>'
185 . '&nbsp;|&nbsp;'
186 . '<a href="' . $tmp_link . '&amp;report=true&amp;version='
187 . $version_data['version'] . '">' . __('Tracking report') . '</a>'
188 . '&nbsp;|&nbsp;'
189 . '<a href="' . $tmp_link . '&amp;snapshot=true&amp;version='
190 . $version_data['version'] . '">' . __('Structure snapshot')
191 . '</a>'
192 . '</td>'
193 . '</tr>';
194 if ($style == 'even') {
195 $style = 'odd';
196 } else {
197 $style = 'even';
200 unset($tmp_link);
202 </tbody>
203 </table>
204 <?php
205 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
206 echo PMA_Util::getButtonOrImage(
207 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
208 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
211 </form>
212 </div>
213 <?php
216 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
218 // Get list of tables
219 $table_list = PMA_Util::getTableList($GLOBALS['db']);
221 $my_tables = array();
223 // For each table try to get the tracking version
224 foreach ($table_list as $key => $value) {
225 // If $value is a table group.
226 if (array_key_exists(('is' . $sep . 'group'), $value)
227 && $value['is' . $sep . 'group']
229 foreach ($value as $temp_table) {
230 // If $temp_table is a table with the value for 'Name' is set,
231 // rather than a property of the table group.
232 if (is_array($temp_table)
233 && array_key_exists('Name', $temp_table)
235 $tracking_version = PMA_Tracker::getVersion(
236 $GLOBALS['db'],
237 $temp_table['Name']
239 if ($tracking_version == -1) {
240 $my_tables[] = $temp_table['Name'];
244 } else { // If $value is a table.
245 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
246 $my_tables[] = $value['Name'];
251 // If untracked tables exist
252 if (count($my_tables) > 0) {
254 <h3><?php echo __('Untracked tables');?></h3>
255 <form method="post" action="db_tracking.php" name="untrackedForm"
256 id="untrackedForm" class="ajax">
257 <?php
258 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
260 <table id="noversions" class="data">
261 <thead>
262 <tr>
263 <th></th>
264 <th style="width: 300px"><?php echo __('Table');?></th>
265 <th><?php echo __('Action');?></th>
266 </tr>
267 </thead>
268 <tbody>
269 <?php
270 // Print out list of untracked tables
272 $style = 'odd';
274 foreach ($my_tables as $key => $tablename) {
275 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
276 $my_link = '<a href="tbl_tracking.php' . $url_query
277 . '&amp;table=' . htmlspecialchars($tablename) . '">';
278 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
279 $my_link .= '</a>';
281 <tr class="noclick <?php echo $style;?>">
282 <td class="center">
283 <input type="checkbox" name="selected_tbl[]" class="checkall"
284 value="<?php echo htmlspecialchars($tablename);?>"/>
285 </td>
286 <td><?php echo htmlspecialchars($tablename);?></td>
287 <td><?php echo $my_link;?></td>
288 </tr>
289 <?php
290 if ($style == 'even') {
291 $style = 'odd';
292 } else {
293 $style = 'even';
298 </tbody>
299 </table>
300 <?php
301 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
302 echo PMA_Util::getButtonOrImage(
303 'submit_mult', 'mult_submit', 'submit_mult_track',
304 __('Track table'), 'eye.png', 'track'
307 </form>
308 <?php
310 // If available print out database log
311 if (count($data['ddlog']) > 0) {
312 $log = '';
313 foreach ($data['ddlog'] as $entry) {
314 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
315 . $entry['statement'] . "\n";
317 echo PMA_Util::getMessage(__('Database Log'), $log);