Translated using Weblate (Frisian)
[phpmyadmin.git] / db_tracking.php
blob6c4c21233b313187f4bde1756d9756a594bb3b85
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 // ---------------------------------------------------------------------------
98 // Prepare statement to get HEAD version
99 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
100 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
101 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
102 ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
103 ' GROUP BY table_name' .
104 ' ORDER BY table_name ASC';
106 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
108 // If a HEAD version exists
109 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
111 <div id="tracked_tables">
112 <h3><?php echo __('Tracked tables');?></h3>
114 <form method="post" action="db_tracking.php" name="trackedForm"
115 id="trackedForm" class="ajax">
116 <?php
117 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
119 <table id="versions" class="data">
120 <thead>
121 <tr>
122 <th></th>
123 <th><?php echo __('Table');?></th>
124 <th><?php echo __('Last version');?></th>
125 <th><?php echo __('Created');?></th>
126 <th><?php echo __('Updated');?></th>
127 <th><?php echo __('Status');?></th>
128 <th><?php echo __('Action');?></th>
129 <th><?php echo __('Show');?></th>
130 </tr>
131 </thead>
132 <tbody>
133 <?php
135 // Print out information about versions
137 $delete_image_or_text = '';
138 if (PMA_Util::showIcons('ActionLinksMode')) {
139 $delete_image_or_text .= PMA_Util::getImage(
140 'b_drop.png',
141 __('Delete tracking data for this table')
144 if (PMA_Util::showText('ActionLinksMode')) {
145 $delete_image_or_text .= __('Delete tracking');
148 $style = 'odd';
149 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
150 list($table_name, $version_number) = $one_result;
151 $table_query = ' SELECT * FROM ' .
152 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
153 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
154 ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db'])
155 . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table_name)
156 . '\' AND `version` = \'' . $version_number . '\'';
158 $table_result = PMA_queryAsControlUser($table_query);
159 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
161 $tmp_link = 'tbl_tracking.php' . $url_query . '&amp;table='
162 . htmlspecialchars($version_data['table_name']);
163 $delete_link = 'db_tracking.php' . $url_query . '&amp;table='
164 . htmlspecialchars($version_data['table_name'])
165 . '&amp;delete_tracking=true&amp';
167 <tr class="noclick <?php echo $style;?>">
168 <td class="center">
169 <input type="checkbox" name="selected_tbl[]" class="checkall"
170 value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
171 </td>
172 <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
173 <td><?php echo $version_data['version'];?></td>
174 <td><?php echo $version_data['date_created'];?></td>
175 <td><?php echo $version_data['date_updated'];?></td>
176 <td><?php echo PMA_getVersionStatus($version_data);?></td>
177 <td>
178 <a class="delete_tracking_anchor ajax" href="<?php echo $delete_link;?>" >
179 <?php echo $delete_image_or_text; ?></a>
180 <?php
181 echo '</td>'
182 . '<td>'
183 . '<a href="' . $tmp_link . '">' . __('Versions') . '</a>'
184 . '&nbsp;|&nbsp;'
185 . '<a href="' . $tmp_link . '&amp;report=true&amp;version='
186 . $version_data['version'] . '">' . __('Tracking report') . '</a>'
187 . '&nbsp;|&nbsp;'
188 . '<a href="' . $tmp_link . '&amp;snapshot=true&amp;version='
189 . $version_data['version'] . '">' . __('Structure snapshot')
190 . '</a>'
191 . '</td>'
192 . '</tr>';
193 if ($style == 'even') {
194 $style = 'odd';
195 } else {
196 $style = 'even';
199 unset($tmp_link);
201 </tbody>
202 </table>
203 <?php
204 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
205 echo PMA_Util::getButtonOrImage(
206 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
207 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
210 </form>
211 </div>
212 <?php
215 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
217 // Get list of tables
218 $table_list = PMA_Util::getTableList($GLOBALS['db']);
220 $my_tables = array();
222 // For each table try to get the tracking version
223 foreach ($table_list as $key => $value) {
224 // If $value is a table group.
225 if (array_key_exists(('is' . $sep . 'group'), $value)
226 && $value['is' . $sep . 'group']
228 foreach ($value as $temp_table) {
229 // If $temp_table is a table with the value for 'Name' is set,
230 // rather than a property of the table group.
231 if (is_array($temp_table)
232 && array_key_exists('Name', $temp_table)
234 $tracking_version = PMA_Tracker::getVersion(
235 $GLOBALS['db'],
236 $temp_table['Name']
238 if ($tracking_version == -1) {
239 $my_tables[] = $temp_table['Name'];
243 } else { // If $value is a table.
244 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
245 $my_tables[] = $value['Name'];
250 // If untracked tables exist
251 if (count($my_tables) > 0) {
253 <h3><?php echo __('Untracked tables');?></h3>
254 <form method="post" action="db_tracking.php" name="untrackedForm"
255 id="untrackedForm" class="ajax">
256 <?php
257 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
259 <table id="noversions" class="data">
260 <thead>
261 <tr>
262 <th></th>
263 <th style="width: 300px"><?php echo __('Table');?></th>
264 <th><?php echo __('Action');?></th>
265 </tr>
266 </thead>
267 <tbody>
268 <?php
269 // Print out list of untracked tables
271 $style = 'odd';
273 foreach ($my_tables as $key => $tablename) {
274 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
275 $my_link = '<a href="tbl_tracking.php' . $url_query
276 . '&amp;table=' . htmlspecialchars($tablename) . '">';
277 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
278 $my_link .= '</a>';
280 <tr class="noclick <?php echo $style;?>">
281 <td class="center">
282 <input type="checkbox" name="selected_tbl[]" class="checkall"
283 value="<?php echo htmlspecialchars($tablename);?>"/>
284 </td>
285 <td><?php echo htmlspecialchars($tablename);?></td>
286 <td><?php echo $my_link;?></td>
287 </tr>
288 <?php
289 if ($style == 'even') {
290 $style = 'odd';
291 } else {
292 $style = 'even';
297 </tbody>
298 </table>
299 <?php
300 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
301 echo PMA_Util::getButtonOrImage(
302 'submit_mult', 'mult_submit', 'submit_mult_track',
303 __('Track table'), 'eye.png', 'track'
306 </form>
307 <?php
309 // If available print out database log
310 if (count($data['ddlog']) > 0) {
311 $log = '';
312 foreach ($data['ddlog'] as $entry) {
313 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
314 . $entry['statement'] . "\n";
316 echo PMA_Util::getMessage(__('Database Log'), $log);