Translated using Weblate (Portuguese (Brazil))
[phpmyadmin.git] / db_tracking.php
blob8a4eba5bdde76ee9d61f0fe09d97992610f51ab2
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('db_structure.js');
22 /**
23 * If we are not in an Ajax request, then do the common work and show the links etc.
25 require 'libraries/db_common.inc.php';
26 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
28 // Get the database structure
29 $sub_part = '_structure';
30 require 'libraries/db_info.inc.php';
32 // Work to do?
33 // (here, do not use $_REQUEST['db] as it can be crafted)
34 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
35 PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
37 /**
38 * If in an Ajax request, generate the success message and use
39 * {@link PMA_Response()} to send the output
41 if ($GLOBALS['is_ajax_request'] == true) {
42 $response = PMA_Response::getInstance();
43 $response->addJSON('message', PMA_Message::success());
44 exit;
48 // Get tracked data about the database
49 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
51 // No tables present and no log exist
52 if ($num_tables == 0 && count($data['ddlog']) == 0) {
53 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
55 if (empty($db_is_system_schema)) {
56 include 'libraries/display_create_table.lib.php';
58 exit;
61 // ---------------------------------------------------------------------------
62 $cfgRelation = PMA_getRelationsParam();
64 // Prepare statement to get HEAD version
65 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
66 PMA_Util::backquote($cfgRelation['db']) . '.' .
67 PMA_Util::backquote($cfgRelation['tracking']) .
68 ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
69 ' GROUP BY table_name' .
70 ' ORDER BY table_name ASC';
72 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
74 // If a HEAD version exists
75 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
77 <div id="tracked_tables">
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 (PMA_Util::showIcons('ActionLinksMode')) {
100 $drop_image_or_text .= PMA_Util::getImage(
101 'b_drop.png',
102 __('Delete tracking data for this table')
105 if (PMA_Util::showText('ActionLinksMode')) {
106 $drop_image_or_text .= __('Drop');
109 $style = 'odd';
110 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
111 list($table_name, $version_number) = $one_result;
112 $table_query = ' SELECT * FROM ' .
113 PMA_Util::backquote($cfgRelation['db']) . '.' .
114 PMA_Util::backquote($cfgRelation['tracking']) .
115 ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db'])
116 . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table_name)
117 . '\' AND `version` = \'' . $version_number . '\'';
119 $table_result = PMA_queryAsControlUser($table_query);
120 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
122 $tmp_link = 'tbl_tracking.php' . $url_query . '&amp;table='
123 . htmlspecialchars($version_data['table_name']);
124 $delete_link = 'db_tracking.php' . $url_query . '&amp;table='
125 . htmlspecialchars($version_data['table_name'])
126 . '&amp;delete_tracking=true&amp';
128 <tr class="noclick <?php echo $style;?>">
129 <td><?php echo htmlspecialchars($version_data['db_name']);?></td>
130 <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
131 <td><?php echo $version_data['version'];?></td>
132 <td><?php echo $version_data['date_created'];?></td>
133 <td><?php echo $version_data['date_updated'];?></td>
134 <td><?php echo PMA_getVersionStatus($version_data);?></td>
135 <td>
136 <a class="drop_tracking_anchor ajax" href="<?php echo $delete_link;?>" >
137 <?php echo $drop_image_or_text; ?></a>
138 <?php
139 echo '</td>'
140 . '<td>'
141 . '<a href="' . $tmp_link . '">' . __('Versions') . '</a>'
142 . '&nbsp;|&nbsp;'
143 . '<a href="' . $tmp_link . '&amp;report=true&amp;version='
144 . $version_data['version'] . '">' . __('Tracking report') . '</a>'
145 . '&nbsp;|&nbsp;'
146 . '<a href="' . $tmp_link . '&amp;snapshot=true&amp;version='
147 . $version_data['version'] . '">' . __('Structure snapshot')
148 . '</a>'
149 . '</td>'
150 . '</tr>';
151 if ($style == 'even') {
152 $style = 'odd';
153 } else {
154 $style = 'even';
157 unset($tmp_link);
159 </tbody>
160 </table>
161 </div>
162 <?php
165 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
167 // Get list of tables
168 $table_list = PMA_Util::getTableList($GLOBALS['db']);
170 $my_tables = array();
172 // For each table try to get the tracking version
173 foreach ($table_list as $key => $value) {
174 // If $value is a table group.
175 if (array_key_exists(('is' . $sep . 'group'), $value)
176 && $value['is' . $sep . 'group']
178 foreach ($value as $temp_table) {
179 // If $temp_table is a table with the value for 'Name' is set,
180 // rather than a property of the table group.
181 if (is_array($temp_table)
182 && array_key_exists('Name', $temp_table)
184 $tracking_version = PMA_Tracker::getVersion(
185 $GLOBALS['db'],
186 $temp_table['Name']
188 if ($tracking_version == -1) {
189 $my_tables[] = $temp_table['Name'];
193 } else { // If $value is a table.
194 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
195 $my_tables[] = $value['Name'];
200 // If untracked tables exist
201 if (count($my_tables) > 0) {
203 <h3><?php echo __('Untracked tables');?></h3>
205 <table id="noversions" class="data">
206 <thead>
207 <tr>
208 <th style="width: 300px"><?php echo __('Table');?></th>
209 <th></th>
210 </tr>
211 </thead>
212 <tbody>
213 <?php
214 // Print out list of untracked tables
216 $style = 'odd';
218 foreach ($my_tables as $key => $tablename) {
219 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
220 $my_link = '<a href="tbl_tracking.php' . $url_query
221 . '&amp;table=' . htmlspecialchars($tablename) . '">';
222 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
223 $my_link .= '</a>';
225 <tr class="noclick <?php echo $style;?>">
226 <td><?php echo htmlspecialchars($tablename);?></td>
227 <td><?php echo $my_link;?></td>
228 </tr>
229 <?php
230 if ($style == 'even') {
231 $style = 'odd';
232 } else {
233 $style = 'even';
238 </tbody>
239 </table>
240 <?php
242 // If available print out database log
243 if (count($data['ddlog']) > 0) {
244 $log = '';
245 foreach ($data['ddlog'] as $entry) {
246 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
247 . $entry['statement'] . "\n";
249 echo PMA_Util::getMessage(__('Database Log'), $log);