Merge branch 'master' of git://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin/dkf.git] / db_tracking.php
blob62f8554413ce8990cfc6b69b761585e500016d87
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package phpMyAdmin
5 */
7 /**
8 * Run common work
9 */
10 require_once './libraries/common.inc.php';
12 //Get some js files needed for Ajax requests
13 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
15 /**
16 * If we are not in an Ajax request, then do the common work and show the links etc.
18 if($GLOBALS['is_ajax_request'] != true) {
19 require './libraries/db_common.inc.php';
21 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
23 // Get the database structure
24 $sub_part = '_structure';
25 require './libraries/db_info.inc.php';
27 // Work to do?
28 // (here, do not use $_REQUEST['db] as it can be crafted)
29 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
30 PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
32 /**
33 * If in an Ajax request, generate the success message and use
34 * {@link PMA_ajaxResponse()} to send the output
36 if($GLOBALS['is_ajax_request'] == true) {
37 $message = PMA_Message::success();
38 PMA_ajaxResponse($message, true);
42 // Get tracked data about the database
43 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
45 // No tables present and no log exist
46 if ($num_tables == 0 && count($data['ddlog']) == 0) {
47 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
49 if (empty($db_is_information_schema)) {
50 require './libraries/display_create_table.lib.php';
53 // Display the footer
54 require './libraries/footer.inc.php';
55 exit;
58 // ---------------------------------------------------------------------------
61 * Display top menu links
63 require_once './libraries/db_links.inc.php';
65 // Prepare statement to get HEAD version
66 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
67 PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
68 PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
69 ' WHERE ' . PMA_backquote('db_name') . ' = \'' . PMA_sqlAddslashes($_REQUEST['db']) . '\' ' .
70 ' GROUP BY '. PMA_backquote('table_name') .
71 ' ORDER BY '. PMA_backquote('table_name') .' ASC';
73 $all_tables_result = PMA_query_as_controluser($all_tables_query);
75 // If a HEAD version exists
76 if (PMA_DBI_num_rows($all_tables_result) > 0) {
78 <h3><?php echo __('Tracked tables');?></h3>
80 <table id="versions" class="data">
81 <thead>
82 <tr>
83 <th><?php echo __('Database');?></th>
84 <th><?php echo __('Table');?></th>
85 <th><?php echo __('Last version');?></th>
86 <th><?php echo __('Created');?></th>
87 <th><?php echo __('Updated');?></th>
88 <th><?php echo __('Status');?></th>
89 <th><?php echo __('Action');?></th>
90 <th><?php echo __('Show');?></th>
91 </tr>
92 </thead>
93 <tbody>
94 <?php
96 // Print out information about versions
98 $drop_image_or_text = '';
99 if (true == $GLOBALS['cfg']['PropertiesIconic']) {
100 $drop_image_or_text .= '<img class="icon" width="16" height="16" src="' . $pmaThemeImage . 'b_drop.png" alt="' . __('Delete tracking data for this table') . '" title="' . __('Delete tracking data for this table') . '" />';
102 if ('both' === $GLOBALS['cfg']['PropertiesIconic'] || false === $GLOBALS['cfg']['PropertiesIconic']) {
103 $drop_image_or_text .= __('Drop');
106 $style = 'odd';
107 while ($one_result = PMA_DBI_fetch_array($all_tables_result)) {
108 list($table_name, $version_number) = $one_result;
109 $table_query = ' SELECT * FROM ' .
110 PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
111 PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
112 ' WHERE `db_name` = \'' . PMA_sqlAddslashes($_REQUEST['db']) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($table_name) . '\' AND `version` = \'' . $version_number . '\'';
114 $table_result = PMA_query_as_controluser($table_query);
115 $version_data = PMA_DBI_fetch_array($table_result);
117 if ($version_data['tracking_active'] == 1) {
118 $version_status = __('active');
119 } else {
120 $version_status = __('not active');
122 $tmp_link = 'tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']);
123 $delete_link = 'db_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']) . '&amp;delete_tracking=true&amp';
125 <tr class="<?php echo $style;?>">
126 <td><?php echo htmlspecialchars($version_data['db_name']);?></td>
127 <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
128 <td><?php echo $version_data['version'];?></td>
129 <td><?php echo $version_data['date_created'];?></td>
130 <td><?php echo $version_data['date_updated'];?></td>
131 <td><?php echo $version_status;?></td>
132 <td><a class="drop_tracking_anchor" href="<?php echo $delete_link;?>" ><?php echo $drop_image_or_text; ?></a></td>
133 <td> <a href="<?php echo $tmp_link; ?>"><?php echo __('Versions');?></a>
134 | <a href="<?php echo $tmp_link; ?>&amp;report=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Tracking report');?></a>
135 | <a href="<?php echo $tmp_link; ?>&amp;snapshot=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Structure snapshot');?></a></td>
136 </tr>
137 <?php
138 if ($style == 'even') {
139 $style = 'odd';
140 } else {
141 $style = 'even';
144 unset($tmp_link);
146 </tbody>
147 </table>
148 <?php
151 // Get list of tables
152 $table_list = PMA_getTableList($GLOBALS['db']);
154 // For each table try to get the tracking version
155 foreach ($table_list as $key => $value) {
156 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
157 $my_tables[] = $value['Name'];
161 // If untracked tables exist
162 if (isset($my_tables)) {
164 <h3><?php echo __('Untracked tables');?></h3>
166 <table id="noversions" class="data">
167 <thead>
168 <tr>
169 <th width="300"><?php echo __('Table');?></th>
170 <th></th>
171 </tr>
172 </thead>
173 <tbody>
174 <?php
175 // Print out list of untracked tables
177 $style = 'odd';
179 foreach ($my_tables as $key => $tablename) {
180 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
181 $my_link = '<a href="tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($tablename) .'">';
183 if ($cfg['PropertiesIconic']) {
184 $my_link .= '<img class="icon" src="' . $pmaThemeImage . 'eye.png" width="16" height="16" alt="' . __('Track table') . '" /> ';
186 $my_link .= __('Track table') . '</a>';
188 <tr class="<?php echo $style;?>">
189 <td><?php echo htmlspecialchars($tablename);?></td>
190 <td><?php echo $my_link;?></td>
191 </tr>
192 <?php
193 if ($style == 'even') {
194 $style = 'odd';
195 } else {
196 $style = 'even';
201 </tbody>
202 </table>
204 <?php
206 // If available print out database log
207 if (count($data['ddlog']) > 0) {
208 $log = '';
209 foreach ($data['ddlog'] as $entry) {
210 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n" . $entry['statement'] . "\n";
212 PMA_showMessage(__('Database Log'), $log);
216 * Display the footer
218 require './libraries/footer.inc.php';