UPDATE 4.4.0.0
[phpmyadmin.git] / db_tracking.php
blob8a5028d7e4bb8d8f69ef5da681605d09c72d2f8f
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="noclick <?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" href="<?php echo $delete_link;?>" >
204 <?php echo $delete; ?></a>
205 <?php
206 echo '</td>'
207 . '<td>'
208 . '<a href="' . $tmp_link . '">' . $versions . '</a>'
209 . '&nbsp;&nbsp;'
210 . '<a href="' . $tmp_link . '&amp;report=true&amp;version='
211 . $version_data['version'] . '">' . $report . '</a>'
212 . '&nbsp;&nbsp;'
213 . '<a href="' . $tmp_link . '&amp;snapshot=true&amp;version='
214 . $version_data['version'] . '">' . $structure . '</a>'
215 . '</td>'
216 . '</tr>';
217 if ($style == 'even') {
218 $style = 'odd';
219 } else {
220 $style = 'even';
223 unset($tmp_link);
225 </tbody>
226 </table>
227 <?php
228 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
229 echo PMA_Util::getButtonOrImage(
230 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
231 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
234 </form>
235 </div>
236 <?php
239 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
241 // Get list of tables
242 $table_list = PMA_Util::getTableList($GLOBALS['db']);
244 $my_tables = array();
246 // For each table try to get the tracking version
247 foreach ($table_list as $key => $value) {
248 // If $value is a table group.
249 if (array_key_exists(('is' . $sep . 'group'), $value)
250 && $value['is' . $sep . 'group']
252 foreach ($value as $temp_table) {
253 // If $temp_table is a table with the value for 'Name' is set,
254 // rather than a property of the table group.
255 if (is_array($temp_table)
256 && array_key_exists('Name', $temp_table)
258 $tracking_version = PMA_Tracker::getVersion(
259 $GLOBALS['db'],
260 $temp_table['Name']
262 if ($tracking_version == -1) {
263 $my_tables[] = $temp_table['Name'];
267 } else { // If $value is a table.
268 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
269 $my_tables[] = $value['Name'];
274 // If untracked tables exist
275 if (count($my_tables) > 0) {
277 <h3><?php echo __('Untracked tables');?></h3>
278 <form method="post" action="db_tracking.php" name="untrackedForm"
279 id="untrackedForm" class="ajax">
280 <?php
281 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
283 <table id="noversions" class="data">
284 <thead>
285 <tr>
286 <th></th>
287 <th style="width: 300px"><?php echo __('Table');?></th>
288 <th><?php echo __('Action');?></th>
289 </tr>
290 </thead>
291 <tbody>
292 <?php
293 // Print out list of untracked tables
295 $style = 'odd';
297 foreach ($my_tables as $key => $tablename) {
298 $checkbox_id = "selected_tbl_"
299 . htmlspecialchars($tablename);
300 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
301 $my_link = '<a href="tbl_tracking.php' . $url_query
302 . '&amp;table=' . htmlspecialchars($tablename) . '">';
303 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
304 $my_link .= '</a>';
306 <tr class="noclick <?php echo $style;?>">
307 <td class="center">
308 <input type="checkbox" name="selected_tbl[]"
309 class="checkall" id="<?php echo $checkbox_id;?>"
310 value="<?php echo htmlspecialchars($tablename);?>"/>
311 </td>
312 <th>
313 <label for="<?php echo $checkbox_id;?>">
314 <?php echo htmlspecialchars($tablename);?>
315 </label>
316 </th>
317 <td><?php echo $my_link;?></td>
318 </tr>
319 <?php
320 if ($style == 'even') {
321 $style = 'odd';
322 } else {
323 $style = 'even';
328 </tbody>
329 </table>
330 <?php
331 echo PMA_Util::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
332 echo PMA_Util::getButtonOrImage(
333 'submit_mult', 'mult_submit', 'submit_mult_track',
334 __('Track table'), 'eye.png', 'track'
337 </form>
338 <?php
340 // If available print out database log
341 if (count($data['ddlog']) > 0) {
342 $log = '';
343 foreach ($data['ddlog'] as $entry) {
344 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
345 . $entry['statement'] . "\n";
347 echo PMA_Util::getMessage(__('Database Log'), $log);