Translated using Weblate (French)
[phpmyadmin.git] / db_tracking.php
bloba813786338d40fe26b2bdd72a369c9775ba11595
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('jquery/jquery.tablesorter.js');
21 $scripts->addFile('db_tracking.js');
23 /**
24 * If we are not in an Ajax request, then do the common work and show the links etc.
26 require 'libraries/db_common.inc.php';
27 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
29 // Get the database structure
30 $sub_part = '_structure';
31 require 'libraries/db_info.inc.php';
33 // Work to do?
34 // (here, do not use $_REQUEST['db] as it can be crafted)
35 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
37 PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
38 PMA_Message::success(
39 __('Tracking data deleted successfully.')
40 )->display();
42 } elseif (isset($_REQUEST['submit_create_version'])) {
44 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
45 PMA_Message::success(
46 sprintf(
47 __(
48 'Version %1$s was created for selected tables,'
49 . ' tracking is active for them.'
51 htmlspecialchars($_REQUEST['version'])
53 )->display();
55 } elseif (isset($_REQUEST['submit_mult'])) {
57 if (! empty($_REQUEST['selected_tbl'])) {
58 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
60 foreach ($_REQUEST['selected_tbl'] as $table) {
61 PMA_Tracker::deleteTracking($GLOBALS['db'], $table);
63 PMA_Message::success(
64 __('Tracking data deleted successfully.')
65 )->display();
67 } elseif ($_REQUEST['submit_mult'] == 'track') {
69 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
70 'db_tracking.php' . $url_query,
72 $GLOBALS['db'],
73 $_REQUEST['selected_tbl']
75 exit;
77 } else {
78 PMA_Message::notice(
79 __('No tables selected.')
80 )->display();
84 // Get tracked data about the database
85 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
87 // No tables present and no log exist
88 if ($num_tables == 0 && count($data['ddlog']) == 0) {
89 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
91 if (empty($db_is_system_schema)) {
92 include 'libraries/display_create_table.lib.php';
94 exit;
97 // ---------------------------------------------------------------------------
98 $cfgRelation = PMA_getRelationsParam();
100 // Prepare statement to get HEAD version
101 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
102 PMA_Util::backquote($cfgRelation['db']) . '.' .
103 PMA_Util::backquote($cfgRelation['tracking']) .
104 ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
105 ' GROUP BY table_name' .
106 ' ORDER BY table_name ASC';
108 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
110 // If a HEAD version exists
111 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
113 <div id="tracked_tables">
114 <h3><?php echo __('Tracked tables');?></h3>
116 <form method="post" action="db_tracking.php" name="trackedForm"
117 id="trackedForm" class="ajax">
118 <?php
119 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
121 <table id="versions" class="data">
122 <thead>
123 <tr>
124 <th></th>
125 <th><?php echo __('Table');?></th>
126 <th><?php echo __('Last version');?></th>
127 <th><?php echo __('Created');?></th>
128 <th><?php echo __('Updated');?></th>
129 <th><?php echo __('Status');?></th>
130 <th><?php echo __('Action');?></th>
131 <th><?php echo __('Show');?></th>
132 </tr>
133 </thead>
134 <tbody>
135 <?php
137 // Print out information about versions
139 $delete = PMA_Util::getIcon('b_drop.png', __('Delete tracking'));
140 $versions = PMA_Util::getIcon('b_versions.png', __('Versions'));
141 $report = PMA_Util::getIcon('b_report.png', __('Tracking report'));
142 $structure = PMA_Util::getIcon('b_props.png', __('Structure snapshot'));
144 $style = 'odd';
145 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
146 list($table_name, $version_number) = $one_result;
147 $table_query = ' SELECT * FROM ' .
148 PMA_Util::backquote($cfgRelation['db']) . '.' .
149 PMA_Util::backquote($cfgRelation['tracking']) .
150 ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db'])
151 . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table_name)
152 . '\' AND `version` = \'' . $version_number . '\'';
154 $table_result = PMA_queryAsControlUser($table_query);
155 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
157 $tmp_link = 'tbl_tracking.php' . $url_query . '&amp;table='
158 . htmlspecialchars($version_data['table_name']);
159 $delete_link = 'db_tracking.php' . $url_query . '&amp;table='
160 . htmlspecialchars($version_data['table_name'])
161 . '&amp;delete_tracking=true&amp';
162 $checkbox_id = "selected_tbl_"
163 . htmlspecialchars($version_data['table_name']);
165 <tr class="<?php echo $style;?>">
166 <td class="center">
167 <input type="checkbox" name="selected_tbl[]"
168 class="checkall" id="<?php echo $checkbox_id;?>"
169 value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
170 </td>
171 <th>
172 <label for="<?php echo $checkbox_id;?>">
173 <?php echo htmlspecialchars($version_data['table_name']);?>
174 </label>
175 </th>
176 <td class="right"><?php echo $version_data['version'];?></td>
177 <td><?php echo $version_data['date_created'];?></td>
178 <td><?php echo $version_data['date_updated'];?></td>
179 <td>
180 <?php
181 $state = PMA_getVersionStatus($version_data);
182 $options = array(
183 0 => array(
184 'label' => __('not active'),
185 'value' => 'deactivate_now',
186 'selected' => ($state != 'active')
188 1 => array(
189 'label' => __('active'),
190 'value' => 'activate_now',
191 'selected' => ($state == 'active')
194 echo PMA_Util::toggleButton(
195 $tmp_link . '&amp;version=' . $version_data['version'],
196 'toggle_activation',
197 $options,
198 null
201 </td>
202 <td>
203 <a class="delete_tracking_anchor ajax"
204 href="<?php echo $delete_link;?>" >
205 <?php echo $delete; ?></a>
206 <?php
207 echo '</td>'
208 . '<td>'
209 . '<a href="' . $tmp_link . '">' . $versions . '</a>'
210 . '&nbsp;&nbsp;'
211 . '<a href="' . $tmp_link . '&amp;report=true&amp;version='
212 . $version_data['version'] . '">' . $report . '</a>'
213 . '&nbsp;&nbsp;'
214 . '<a href="' . $tmp_link . '&amp;snapshot=true&amp;version='
215 . $version_data['version'] . '">' . $structure . '</a>'
216 . '</td>'
217 . '</tr>';
218 if ($style == 'even') {
219 $style = 'odd';
220 } else {
221 $style = 'even';
224 unset($tmp_link);
226 </tbody>
227 </table>
228 <?php
229 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
230 echo PMA_Util::getButtonOrImage(
231 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
232 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
235 </form>
236 </div>
237 <?php
240 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
242 // Get list of tables
243 $table_list = PMA_Util::getTableList($GLOBALS['db']);
245 $my_tables = array();
247 // For each table try to get the tracking version
248 foreach ($table_list as $key => $value) {
249 // If $value is a table group.
250 if (array_key_exists(('is' . $sep . 'group'), $value)
251 && $value['is' . $sep . 'group']
253 foreach ($value as $temp_table) {
254 // If $temp_table is a table with the value for 'Name' is set,
255 // rather than a property of the table group.
256 if (is_array($temp_table)
257 && array_key_exists('Name', $temp_table)
259 $tracking_version = PMA_Tracker::getVersion(
260 $GLOBALS['db'],
261 $temp_table['Name']
263 if ($tracking_version == -1) {
264 $my_tables[] = $temp_table['Name'];
268 } else { // If $value is a table.
269 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
270 $my_tables[] = $value['Name'];
275 // If untracked tables exist
276 if (count($my_tables) > 0) {
278 <h3><?php echo __('Untracked tables');?></h3>
279 <form method="post" action="db_tracking.php" name="untrackedForm"
280 id="untrackedForm" class="ajax">
281 <?php
282 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
284 <table id="noversions" class="data">
285 <thead>
286 <tr>
287 <th></th>
288 <th style="width: 300px"><?php echo __('Table');?></th>
289 <th><?php echo __('Action');?></th>
290 </tr>
291 </thead>
292 <tbody>
293 <?php
294 // Print out list of untracked tables
296 $style = 'odd';
298 foreach ($my_tables as $key => $tablename) {
299 $checkbox_id = "selected_tbl_"
300 . htmlspecialchars($tablename);
301 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
302 $my_link = '<a href="tbl_tracking.php' . $url_query
303 . '&amp;table=' . htmlspecialchars($tablename) . '">';
304 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
305 $my_link .= '</a>';
307 <tr class="<?php echo $style;?>">
308 <td class="center">
309 <input type="checkbox" name="selected_tbl[]"
310 class="checkall" id="<?php echo $checkbox_id;?>"
311 value="<?php echo htmlspecialchars($tablename);?>"/>
312 </td>
313 <th>
314 <label for="<?php echo $checkbox_id;?>">
315 <?php echo htmlspecialchars($tablename);?>
316 </label>
317 </th>
318 <td><?php echo $my_link;?></td>
319 </tr>
320 <?php
321 if ($style == 'even') {
322 $style = 'odd';
323 } else {
324 $style = 'even';
329 </tbody>
330 </table>
331 <?php
332 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
333 echo PMA_Util::getButtonOrImage(
334 'submit_mult', 'mult_submit', 'submit_mult_track',
335 __('Track table'), 'eye.png', 'track'
338 </form>
339 <?php
341 // If available print out database log
342 if (count($data['ddlog']) > 0) {
343 $log = '';
344 foreach ($data['ddlog'] as $entry) {
345 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
346 . $entry['statement'] . "\n";
348 echo PMA_Util::getMessage(__('Database Log'), $log);