Remove author names per our policy
[phpmyadmin-themes.git] / db_tracking.php
blobd9a7da35abf93584be63b96090b0c778ed011781
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';
14 $GLOBALS['js_include'][] = 'db_structure.js';
16 /**
17 * If we are not in an Ajax request, then do the common work and show the links etc.
19 if($GLOBALS['is_ajax_request'] != true) {
20 require './libraries/db_common.inc.php';
22 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
24 // Get the database structure
25 $sub_part = '_structure';
26 require './libraries/db_info.inc.php';
28 // Work to do?
29 // (here, do not use $_REQUEST['db] as it can be crafted)
30 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
31 PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
33 /**
34 * If in an Ajax request, generate the success message and use
35 * {@link PMA_ajaxResponse()} to send the output
37 if($GLOBALS['is_ajax_request'] == true) {
38 $message = PMA_Message::success();
39 PMA_ajaxResponse($message, true);
43 // Get tracked data about the database
44 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
46 // No tables present and no log exist
47 if ($num_tables == 0 && count($data['ddlog']) == 0) {
48 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
50 if (empty($db_is_information_schema)) {
51 require './libraries/display_create_table.lib.php';
54 // Display the footer
55 require './libraries/footer.inc.php';
56 exit;
59 // ---------------------------------------------------------------------------
62 * Display top menu links
64 require_once './libraries/db_links.inc.php';
66 // Prepare statement to get HEAD version
67 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
68 PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
69 PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
70 ' WHERE ' . PMA_backquote('db_name') . ' = \'' . PMA_sqlAddslashes($_REQUEST['db']) . '\' ' .
71 ' GROUP BY '. PMA_backquote('table_name') .
72 ' ORDER BY '. PMA_backquote('table_name') .' ASC';
74 $all_tables_result = PMA_query_as_controluser($all_tables_query);
76 // If a HEAD version exists
77 if (PMA_DBI_num_rows($all_tables_result) > 0) {
79 <h3><?php echo __('Tracked tables');?></h3>
81 <table id="versions" class="data">
82 <thead>
83 <tr>
84 <th><?php echo __('Database');?></th>
85 <th><?php echo __('Table');?></th>
86 <th><?php echo __('Last version');?></th>
87 <th><?php echo __('Created');?></th>
88 <th><?php echo __('Updated');?></th>
89 <th><?php echo __('Status');?></th>
90 <th><?php echo __('Action');?></th>
91 <th><?php echo __('Show');?></th>
92 </tr>
93 </thead>
94 <tbody>
95 <?php
97 // Print out information about versions
99 $drop_image_or_text = '';
100 if (true == $GLOBALS['cfg']['PropertiesIconic']) {
101 $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') . '" />';
103 if ('both' === $GLOBALS['cfg']['PropertiesIconic'] || false === $GLOBALS['cfg']['PropertiesIconic']) {
104 $drop_image_or_text .= __('Drop');
107 $style = 'odd';
108 while ($one_result = PMA_DBI_fetch_array($all_tables_result)) {
109 list($table_name, $version_number) = $one_result;
110 $table_query = ' SELECT * FROM ' .
111 PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
112 PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
113 ' WHERE `db_name` = \'' . PMA_sqlAddslashes($_REQUEST['db']) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($table_name) . '\' AND `version` = \'' . $version_number . '\'';
115 $table_result = PMA_query_as_controluser($table_query);
116 $version_data = PMA_DBI_fetch_array($table_result);
118 if ($version_data['tracking_active'] == 1) {
119 $version_status = __('active');
120 } else {
121 $version_status = __('not active');
123 $tmp_link = 'tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']);
124 $delete_link = 'db_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']) . '&amp;delete_tracking=true&amp';
126 <tr class="<?php echo $style;?>">
127 <td><?php echo htmlspecialchars($version_data['db_name']);?></td>
128 <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
129 <td><?php echo $version_data['version'];?></td>
130 <td><?php echo $version_data['date_created'];?></td>
131 <td><?php echo $version_data['date_updated'];?></td>
132 <td><?php echo $version_status;?></td>
133 <td><a <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'class="drop_tracking_anchor"' : ''); ?> href="<?php echo $delete_link;?>" ><?php echo $drop_image_or_text; ?></a></td>
134 <td> <a href="<?php echo $tmp_link; ?>"><?php echo __('Versions');?></a>
135 | <a href="<?php echo $tmp_link; ?>&amp;report=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Tracking report');?></a>
136 | <a href="<?php echo $tmp_link; ?>&amp;snapshot=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Structure snapshot');?></a></td>
137 </tr>
138 <?php
139 if ($style == 'even') {
140 $style = 'odd';
141 } else {
142 $style = 'even';
145 unset($tmp_link);
147 </tbody>
148 </table>
149 <?php
152 // Get list of tables
153 $table_list = PMA_getTableList($GLOBALS['db']);
155 // For each table try to get the tracking version
156 foreach ($table_list as $key => $value) {
157 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
158 $my_tables[] = $value['Name'];
162 // If untracked tables exist
163 if (isset($my_tables)) {
165 <h3><?php echo __('Untracked tables');?></h3>
167 <table id="noversions" class="data">
168 <thead>
169 <tr>
170 <th width="300"><?php echo __('Table');?></th>
171 <th></th>
172 </tr>
173 </thead>
174 <tbody>
175 <?php
176 // Print out list of untracked tables
178 $style = 'odd';
180 foreach ($my_tables as $key => $tablename) {
181 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
182 $my_link = '<a href="tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($tablename) .'">';
184 if ($cfg['PropertiesIconic']) {
185 $my_link .= '<img class="icon" src="' . $pmaThemeImage . 'eye.png" width="16" height="16" alt="' . __('Track table') . '" /> ';
187 $my_link .= __('Track table') . '</a>';
189 <tr class="<?php echo $style;?>">
190 <td><?php echo htmlspecialchars($tablename);?></td>
191 <td><?php echo $my_link;?></td>
192 </tr>
193 <?php
194 if ($style == 'even') {
195 $style = 'odd';
196 } else {
197 $style = 'even';
202 </tbody>
203 </table>
205 <?php
207 // If available print out database log
208 if (count($data['ddlog']) > 0) {
209 $log = '';
210 foreach ($data['ddlog'] as $entry) {
211 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n" . $entry['statement'] . "\n";
213 PMA_showMessage(__('Database Log'), $log);
217 * Display the footer
219 require './libraries/footer.inc.php';