Translated using Weblate (Estonian)
[phpmyadmin.git] / db_tracking.php
blob983be487befbc78a88ca81b00aeeae8f42ad694c
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 //Get some js files needed for Ajax requests
15 $response = PMA_Response::getInstance();
16 $header = $response->getHeader();
17 $scripts = $header->getScripts();
18 $scripts->addFile('db_structure.js');
20 /**
21 * If we are not in an Ajax request, then do the common work and show the links etc.
23 require 'libraries/db_common.inc.php';
24 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
26 // Get the database structure
27 $sub_part = '_structure';
28 require 'libraries/db_info.inc.php';
30 // Work to do?
31 // (here, do not use $_REQUEST['db] as it can be crafted)
32 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
33 PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
35 /**
36 * If in an Ajax request, generate the success message and use
37 * {@link PMA_Response()} to send the output
39 if ($GLOBALS['is_ajax_request'] == true) {
40 $response = PMA_Response::getInstance();
41 $response->addJSON('message', PMA_Message::success());
42 exit;
46 // Get tracked data about the database
47 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
49 // No tables present and no log exist
50 if ($num_tables == 0 && count($data['ddlog']) == 0) {
51 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
53 if (empty($db_is_information_schema)) {
54 include 'libraries/display_create_table.lib.php';
56 exit;
59 // ---------------------------------------------------------------------------
61 // Prepare statement to get HEAD version
62 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
63 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
64 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
65 ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
66 ' GROUP BY table_name' .
67 ' ORDER BY table_name ASC';
69 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
71 // If a HEAD version exists
72 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
74 <div id="tracked_tables">
75 <h3><?php echo __('Tracked tables');?></h3>
77 <table id="versions" class="data">
78 <thead>
79 <tr>
80 <th><?php echo __('Database');?></th>
81 <th><?php echo __('Table');?></th>
82 <th><?php echo __('Last version');?></th>
83 <th><?php echo __('Created');?></th>
84 <th><?php echo __('Updated');?></th>
85 <th><?php echo __('Status');?></th>
86 <th><?php echo __('Action');?></th>
87 <th><?php echo __('Show');?></th>
88 </tr>
89 </thead>
90 <tbody>
91 <?php
93 // Print out information about versions
95 $drop_image_or_text = '';
96 if (PMA_Util::showIcons('ActionLinksMode')) {
97 $drop_image_or_text .= PMA_Util::getImage(
98 'b_drop.png',
99 __('Delete tracking data for this table')
102 if (PMA_Util::showText('ActionLinksMode')) {
103 $drop_image_or_text .= __('Drop');
106 $style = 'odd';
107 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
108 list($table_name, $version_number) = $one_result;
109 $table_query = ' SELECT * FROM ' .
110 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
111 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
112 ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db'])
113 . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table_name)
114 . '\' AND `version` = \'' . $version_number . '\'';
116 $table_result = PMA_queryAsControlUser($table_query);
117 $version_data = $GLOBALS['dbi']->fetchArray($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='
125 . htmlspecialchars($version_data['table_name']);
126 $delete_link = 'db_tracking.php?' . $url_query . '&amp;table='
127 . htmlspecialchars($version_data['table_name'])
128 . '&amp;delete_tracking=true&amp';
130 <tr class="noclick <?php echo $style;?>">
131 <td><?php echo htmlspecialchars($version_data['db_name']);?></td>
132 <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
133 <td><?php echo $version_data['version'];?></td>
134 <td><?php echo $version_data['date_created'];?></td>
135 <td><?php echo $version_data['date_updated'];?></td>
136 <td><?php echo $version_status;?></td>
137 <td>
138 <a class="drop_tracking_anchor ajax" href="<?php echo $delete_link;?>" >
139 <?php echo $drop_image_or_text; ?></a>
140 </td>
141 <td>
142 <a href="<?php echo $tmp_link; ?>"><?php echo __('Versions');?></a>
144 <a href="<?php echo $tmp_link; ?>&amp;report=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Tracking report');?></a>
146 <a href="<?php echo $tmp_link; ?>&amp;snapshot=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Structure snapshot');?></a></td>
147 </tr>
148 <?php
149 if ($style == 'even') {
150 $style = 'odd';
151 } else {
152 $style = 'even';
155 unset($tmp_link);
157 </tbody>
158 </table>
159 </div>
160 <?php
163 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
165 // Get list of tables
166 $table_list = PMA_Util::getTableList($GLOBALS['db']);
168 // For each table try to get the tracking version
169 foreach ($table_list as $key => $value) {
170 // If $value is a table group.
171 if (array_key_exists(('is' . $sep . 'group'), $value)
172 && $value['is' . $sep . 'group']
174 foreach ($value as $temp_table) {
175 // If $temp_table is a table with the value for 'Name' is set,
176 // rather than a propery of the table group.
177 if (is_array($temp_table)
178 && array_key_exists('Name', $temp_table)
180 $tracking_version = PMA_Tracker::getVersion(
181 $GLOBALS['db'],
182 $temp_table['Name']
184 if ($tracking_version == -1) {
185 $my_tables[] = $temp_table['Name'];
189 } else { // If $value is a table.
190 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
191 $my_tables[] = $value['Name'];
196 // If untracked tables exist
197 if (isset($my_tables)) {
199 <h3><?php echo __('Untracked tables');?></h3>
201 <table id="noversions" class="data">
202 <thead>
203 <tr>
204 <th style="width: 300px"><?php echo __('Table');?></th>
205 <th></th>
206 </tr>
207 </thead>
208 <tbody>
209 <?php
210 // Print out list of untracked tables
212 $style = 'odd';
214 foreach ($my_tables as $key => $tablename) {
215 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
216 $my_link = '<a href="tbl_tracking.php?' . $url_query
217 . '&amp;table=' . htmlspecialchars($tablename) .'">';
218 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
219 $my_link .= '</a>';
221 <tr class="noclick <?php echo $style;?>">
222 <td><?php echo htmlspecialchars($tablename);?></td>
223 <td><?php echo $my_link;?></td>
224 </tr>
225 <?php
226 if ($style == 'even') {
227 $style = 'odd';
228 } else {
229 $style = 'even';
234 </tbody>
235 </table>
236 <?php
238 // If available print out database log
239 if (count($data['ddlog']) > 0) {
240 $log = '';
241 foreach ($data['ddlog'] as $entry) {
242 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
243 . $entry['statement'] . "\n";
245 echo PMA_Util::getMessage(__('Database Log'), $log);