Merge commit '5924811'
[phpmyadmin.git] / db_tracking.php
blobe1d5aee3960538e36c0530f52147e2476825845d
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';
15 require_once 'libraries/display_create_table.lib.php';
17 //Get some js files needed for Ajax requests
18 $response = PMA_Response::getInstance();
19 $header = $response->getHeader();
20 $scripts = $header->getScripts();
21 $scripts->addFile('jquery/jquery.tablesorter.js');
22 $scripts->addFile('db_tracking.js');
24 /**
25 * If we are not in an Ajax request, then do the common work and show the links etc.
27 require 'libraries/db_common.inc.php';
28 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
30 // Get the database structure
31 $sub_part = '_structure';
32 require 'libraries/db_info.inc.php';
34 // Work to do?
35 // (here, do not use $_REQUEST['db] as it can be crafted)
36 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
38 PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
39 PMA_Message::success(
40 __('Tracking data deleted successfully.')
41 )->display();
43 } elseif (isset($_REQUEST['submit_create_version'])) {
45 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
46 PMA_Message::success(
47 sprintf(
48 __(
49 'Version %1$s was created for selected tables,'
50 . ' tracking is active for them.'
52 htmlspecialchars($_REQUEST['version'])
54 )->display();
56 } elseif (isset($_REQUEST['submit_mult'])) {
58 if (! empty($_REQUEST['selected_tbl'])) {
59 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
61 foreach ($_REQUEST['selected_tbl'] as $table) {
62 PMA_Tracker::deleteTracking($GLOBALS['db'], $table);
64 PMA_Message::success(
65 __('Tracking data deleted successfully.')
66 )->display();
68 } elseif ($_REQUEST['submit_mult'] == 'track') {
70 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
71 'db_tracking.php' . $url_query,
73 $GLOBALS['db'],
74 $_REQUEST['selected_tbl']
76 exit;
78 } else {
79 PMA_Message::notice(
80 __('No tables selected.')
81 )->display();
85 // Get tracked data about the database
86 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
88 // No tables present and no log exist
89 if ($num_tables == 0 && count($data['ddlog']) == 0) {
90 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
92 if (empty($db_is_system_schema)) {
93 echo PMA_getHtmlForCreateTable($db);
95 exit;
98 // ---------------------------------------------------------------------------
99 $cfgRelation = PMA_getRelationsParam();
101 // Prepare statement to get HEAD version
102 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
103 PMA_Util::backquote($cfgRelation['db']) . '.' .
104 PMA_Util::backquote($cfgRelation['tracking']) .
105 ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
106 ' GROUP BY table_name' .
107 ' ORDER BY table_name ASC';
109 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
111 // If a HEAD version exists
112 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
114 <div id="tracked_tables">
115 <h3><?php echo __('Tracked tables');?></h3>
117 <form method="post" action="db_tracking.php" name="trackedForm"
118 id="trackedForm" class="ajax">
119 <?php
120 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
122 <table id="versions" class="data">
123 <thead>
124 <tr>
125 <th></th>
126 <th><?php echo __('Table');?></th>
127 <th><?php echo __('Last version');?></th>
128 <th><?php echo __('Created');?></th>
129 <th><?php echo __('Updated');?></th>
130 <th><?php echo __('Status');?></th>
131 <th><?php echo __('Action');?></th>
132 <th><?php echo __('Show');?></th>
133 </tr>
134 </thead>
135 <tbody>
136 <?php
138 // Print out information about versions
140 $delete = PMA_Util::getIcon('b_drop.png', __('Delete tracking'));
141 $versions = PMA_Util::getIcon('b_versions.png', __('Versions'));
142 $report = PMA_Util::getIcon('b_report.png', __('Tracking report'));
143 $structure = PMA_Util::getIcon('b_props.png', __('Structure snapshot'));
145 $style = 'odd';
146 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
147 list($table_name, $version_number) = $one_result;
148 $table_query = ' SELECT * FROM ' .
149 PMA_Util::backquote($cfgRelation['db']) . '.' .
150 PMA_Util::backquote($cfgRelation['tracking']) .
151 ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db'])
152 . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table_name)
153 . '\' AND `version` = \'' . $version_number . '\'';
155 $table_result = PMA_queryAsControlUser($table_query);
156 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
158 $tmp_link = 'tbl_tracking.php' . $url_query . '&amp;table='
159 . htmlspecialchars($version_data['table_name']);
160 $delete_link = 'db_tracking.php' . $url_query . '&amp;table='
161 . htmlspecialchars($version_data['table_name'])
162 . '&amp;delete_tracking=true&amp';
163 $checkbox_id = "selected_tbl_"
164 . htmlspecialchars($version_data['table_name']);
166 <tr class="<?php echo $style;?>">
167 <td class="center">
168 <input type="checkbox" name="selected_tbl[]"
169 class="checkall" id="<?php echo $checkbox_id;?>"
170 value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
171 </td>
172 <th>
173 <label for="<?php echo $checkbox_id;?>">
174 <?php echo htmlspecialchars($version_data['table_name']);?>
175 </label>
176 </th>
177 <td class="right"><?php echo $version_data['version'];?></td>
178 <td><?php echo $version_data['date_created'];?></td>
179 <td><?php echo $version_data['date_updated'];?></td>
180 <td>
181 <?php
182 $state = PMA_getVersionStatus($version_data);
183 $options = array(
184 0 => array(
185 'label' => __('not active'),
186 'value' => 'deactivate_now',
187 'selected' => ($state != 'active')
189 1 => array(
190 'label' => __('active'),
191 'value' => 'activate_now',
192 'selected' => ($state == 'active')
195 echo PMA_Util::toggleButton(
196 $tmp_link . '&amp;version=' . $version_data['version'],
197 'toggle_activation',
198 $options,
199 null
202 </td>
203 <td>
204 <a class="delete_tracking_anchor ajax"
205 href="<?php echo $delete_link;?>" >
206 <?php echo $delete; ?></a>
207 <?php
208 echo '</td>'
209 . '<td>'
210 . '<a href="' . $tmp_link . '">' . $versions . '</a>'
211 . '&nbsp;&nbsp;'
212 . '<a href="' . $tmp_link . '&amp;report=true&amp;version='
213 . $version_data['version'] . '">' . $report . '</a>'
214 . '&nbsp;&nbsp;'
215 . '<a href="' . $tmp_link . '&amp;snapshot=true&amp;version='
216 . $version_data['version'] . '">' . $structure . '</a>'
217 . '</td>'
218 . '</tr>';
219 if ($style == 'even') {
220 $style = 'odd';
221 } else {
222 $style = 'even';
225 unset($tmp_link);
227 </tbody>
228 </table>
229 <?php
230 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
231 echo PMA_Util::getButtonOrImage(
232 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
233 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
236 </form>
237 </div>
238 <?php
241 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
243 // Get list of tables
244 $table_list = PMA_Util::getTableList($GLOBALS['db']);
246 $my_tables = array();
248 // For each table try to get the tracking version
249 foreach ($table_list as $key => $value) {
250 // If $value is a table group.
251 if (array_key_exists(('is' . $sep . 'group'), $value)
252 && $value['is' . $sep . 'group']
254 foreach ($value as $temp_table) {
255 // If $temp_table is a table with the value for 'Name' is set,
256 // rather than a property of the table group.
257 if (is_array($temp_table)
258 && array_key_exists('Name', $temp_table)
260 $tracking_version = PMA_Tracker::getVersion(
261 $GLOBALS['db'],
262 $temp_table['Name']
264 if ($tracking_version == -1) {
265 $my_tables[] = $temp_table['Name'];
269 } else { // If $value is a table.
270 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
271 $my_tables[] = $value['Name'];
276 // If untracked tables exist
277 if (count($my_tables) > 0) {
279 <h3><?php echo __('Untracked tables');?></h3>
280 <form method="post" action="db_tracking.php" name="untrackedForm"
281 id="untrackedForm" class="ajax">
282 <?php
283 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
285 <table id="noversions" class="data">
286 <thead>
287 <tr>
288 <th></th>
289 <th style="width: 300px"><?php echo __('Table');?></th>
290 <th><?php echo __('Action');?></th>
291 </tr>
292 </thead>
293 <tbody>
294 <?php
295 // Print out list of untracked tables
297 $style = 'odd';
299 foreach ($my_tables as $key => $tablename) {
300 $checkbox_id = "selected_tbl_"
301 . htmlspecialchars($tablename);
302 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
303 $my_link = '<a href="tbl_tracking.php' . $url_query
304 . '&amp;table=' . htmlspecialchars($tablename) . '">';
305 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
306 $my_link .= '</a>';
308 <tr class="<?php echo $style;?>">
309 <td class="center">
310 <input type="checkbox" name="selected_tbl[]"
311 class="checkall" id="<?php echo $checkbox_id;?>"
312 value="<?php echo htmlspecialchars($tablename);?>"/>
313 </td>
314 <th>
315 <label for="<?php echo $checkbox_id;?>">
316 <?php echo htmlspecialchars($tablename);?>
317 </label>
318 </th>
319 <td><?php echo $my_link;?></td>
320 </tr>
321 <?php
322 if ($style == 'even') {
323 $style = 'odd';
324 } else {
325 $style = 'even';
330 </tbody>
331 </table>
332 <?php
333 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
334 echo PMA_Util::getButtonOrImage(
335 'submit_mult', 'mult_submit', 'submit_mult_track',
336 __('Track table'), 'eye.png', 'track'
339 </form>
340 <?php
342 // If available print out database log
343 if (count($data['ddlog']) > 0) {
344 $log = '';
345 foreach ($data['ddlog'] as $entry) {
346 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
347 . $entry['statement'] . "\n";
349 echo PMA_Util::getMessage(__('Database Log'), $log);