Translated using Weblate.
[phpmyadmin.git] / db_tracking.php
blob6fd9a9c527fc878fc270579ab56c6c593e4ac178
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.16.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 include './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 include './libraries/display_create_table.lib.php';
54 // Display the footer
55 include './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 db_name = \'' . PMA_sqlAddSlashes($_REQUEST['db']) . '\' ' .
71 ' GROUP BY table_name' .
72 ' ORDER BY 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 <div id="tracked_tables">
80 <h3><?php echo __('Tracked tables');?></h3>
82 <table id="versions" class="data">
83 <thead>
84 <tr>
85 <th><?php echo __('Database');?></th>
86 <th><?php echo __('Table');?></th>
87 <th><?php echo __('Last version');?></th>
88 <th><?php echo __('Created');?></th>
89 <th><?php echo __('Updated');?></th>
90 <th><?php echo __('Status');?></th>
91 <th><?php echo __('Action');?></th>
92 <th><?php echo __('Show');?></th>
93 </tr>
94 </thead>
95 <tbody>
96 <?php
98 // Print out information about versions
100 $drop_image_or_text = '';
101 if (true == $GLOBALS['cfg']['PropertiesIconic']) {
102 $drop_image_or_text .= PMA_getImage('b_drop.png', __('Delete tracking data for this table'));
104 if ('both' === $GLOBALS['cfg']['PropertiesIconic'] || false === $GLOBALS['cfg']['PropertiesIconic']) {
105 $drop_image_or_text .= __('Drop');
108 $style = 'odd';
109 while ($one_result = PMA_DBI_fetch_array($all_tables_result)) {
110 list($table_name, $version_number) = $one_result;
111 $table_query = ' SELECT * FROM ' .
112 PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
113 PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
114 ' WHERE `db_name` = \'' . PMA_sqlAddSlashes($_REQUEST['db']) . '\' AND `table_name` = \'' . PMA_sqlAddSlashes($table_name) . '\' AND `version` = \'' . $version_number . '\'';
116 $table_result = PMA_query_as_controluser($table_query);
117 $version_data = PMA_DBI_fetch_array($table_result);
119 if ($version_data['tracking_active'] == 1) {
120 $version_status = __('active');
121 } else {
122 $version_status = __('not active');
124 $tmp_link = 'tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']);
125 $delete_link = 'db_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']) . '&amp;delete_tracking=true&amp';
127 <tr class="noclick <?php echo $style;?>">
128 <td><?php echo htmlspecialchars($version_data['db_name']);?></td>
129 <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
130 <td><?php echo $version_data['version'];?></td>
131 <td><?php echo $version_data['date_created'];?></td>
132 <td><?php echo $version_data['date_updated'];?></td>
133 <td><?php echo $version_status;?></td>
134 <td><a <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'class="drop_tracking_anchor"' : ''); ?> href="<?php echo $delete_link;?>" ><?php echo $drop_image_or_text; ?></a></td>
135 <td> <a href="<?php echo $tmp_link; ?>"><?php echo __('Versions');?></a>
136 | <a href="<?php echo $tmp_link; ?>&amp;report=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Tracking report');?></a>
137 | <a href="<?php echo $tmp_link; ?>&amp;snapshot=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Structure snapshot');?></a></td>
138 </tr>
139 <?php
140 if ($style == 'even') {
141 $style = 'odd';
142 } else {
143 $style = 'even';
146 unset($tmp_link);
148 </tbody>
149 </table>
150 </div>
151 <?php
154 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
156 // Get list of tables
157 $table_list = PMA_getTableList($GLOBALS['db']);
159 // For each table try to get the tracking version
160 foreach ($table_list as $key => $value) {
161 // If $value is a table group.
162 if (array_key_exists(('is' . $sep . 'group'), $value) && $value['is' . $sep . 'group']) {
163 foreach ($value as $temp_table) {
164 // If $temp_table is a table with the value for 'Name' is set,
165 // rather than a propery of the table group.
166 if (is_array($temp_table) && array_key_exists('Name', $temp_table)) {
167 if (PMA_Tracker::getVersion($GLOBALS['db'], $temp_table['Name']) == -1) {
168 $my_tables[] = $temp_table['Name'];
172 // If $value is a table.
173 } else {
174 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
175 $my_tables[] = $value['Name'];
180 // If untracked tables exist
181 if (isset($my_tables)) {
183 <h3><?php echo __('Untracked tables');?></h3>
185 <table id="noversions" class="data">
186 <thead>
187 <tr>
188 <th width="300"><?php echo __('Table');?></th>
189 <th></th>
190 </tr>
191 </thead>
192 <tbody>
193 <?php
194 // Print out list of untracked tables
196 $style = 'odd';
198 foreach ($my_tables as $key => $tablename) {
199 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
200 $my_link = '<a href="tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($tablename) .'">';
201 $my_link .= PMA_getIcon('eye.png', __('Track table')) . '</a>';
203 <tr class="noclick <?php echo $style;?>">
204 <td><?php echo htmlspecialchars($tablename);?></td>
205 <td><?php echo $my_link;?></td>
206 </tr>
207 <?php
208 if ($style == 'even') {
209 $style = 'odd';
210 } else {
211 $style = 'even';
216 </tbody>
217 </table>
219 <?php
221 // If available print out database log
222 if (count($data['ddlog']) > 0) {
223 $log = '';
224 foreach ($data['ddlog'] as $entry) {
225 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n" . $entry['statement'] . "\n";
227 PMA_showMessage(__('Database Log'), $log);
231 * Display the footer
233 require './libraries/footer.inc.php';