Translated using Weblate (Tatar)
[phpmyadmin.git] / db_tracking.php
blobe95a7e0a5fe8fe0eb04501803f62544964c188d8
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 $response = PMA_Response::getInstance();
14 $header = $response->getHeader();
15 $scripts = $header->getScripts();
16 $scripts->addFile('db_structure.js');
18 /**
19 * If we are not in an Ajax request, then do the common work and show the links etc.
21 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_Response()} to send the output
37 if ($GLOBALS['is_ajax_request'] == true) {
38 $response = PMA_Response::getInstance();
39 $response->addJSON('message', PMA_Message::success());
40 exit;
44 // Get tracked data about the database
45 $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
47 // No tables present and no log exist
48 if ($num_tables == 0 && count($data['ddlog']) == 0) {
49 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
51 if (empty($db_is_information_schema)) {
52 include 'libraries/display_create_table.lib.php';
54 exit;
57 // ---------------------------------------------------------------------------
59 // Prepare statement to get HEAD version
60 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
61 PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
62 PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
63 ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
64 ' GROUP BY table_name' .
65 ' ORDER BY table_name ASC';
67 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
69 // If a HEAD version exists
70 if (PMA_DBI_num_rows($all_tables_result) > 0) {
72 <div id="tracked_tables">
73 <h3><?php echo __('Tracked tables');?></h3>
75 <table id="versions" class="data">
76 <thead>
77 <tr>
78 <th><?php echo __('Database');?></th>
79 <th><?php echo __('Table');?></th>
80 <th><?php echo __('Last version');?></th>
81 <th><?php echo __('Created');?></th>
82 <th><?php echo __('Updated');?></th>
83 <th><?php echo __('Status');?></th>
84 <th><?php echo __('Action');?></th>
85 <th><?php echo __('Show');?></th>
86 </tr>
87 </thead>
88 <tbody>
89 <?php
91 // Print out information about versions
93 $drop_image_or_text = '';
94 if (true == $GLOBALS['cfg']['PropertiesIconic']) {
95 $drop_image_or_text .= PMA_Util::getImage(
96 'b_drop.png',
97 __('Delete tracking data for this table')
100 if ('both' === $GLOBALS['cfg']['PropertiesIconic']
101 || 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_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 = 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='
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><a class="drop_tracking_anchor ajax" href="<?php echo $delete_link;?>" ><?php echo $drop_image_or_text; ?></a></td>
138 <td> <a href="<?php echo $tmp_link; ?>"><?php echo __('Versions');?></a>
139 | <a href="<?php echo $tmp_link; ?>&amp;report=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Tracking report');?></a>
140 | <a href="<?php echo $tmp_link; ?>&amp;snapshot=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Structure snapshot');?></a></td>
141 </tr>
142 <?php
143 if ($style == 'even') {
144 $style = 'odd';
145 } else {
146 $style = 'even';
149 unset($tmp_link);
151 </tbody>
152 </table>
153 </div>
154 <?php
157 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
159 // Get list of tables
160 $table_list = PMA_Util::getTableList($GLOBALS['db']);
162 // For each table try to get the tracking version
163 foreach ($table_list as $key => $value) {
164 // If $value is a table group.
165 if (array_key_exists(('is' . $sep . 'group'), $value)
166 && $value['is' . $sep . 'group']
168 foreach ($value as $temp_table) {
169 // If $temp_table is a table with the value for 'Name' is set,
170 // rather than a propery of the table group.
171 if (is_array($temp_table)
172 && array_key_exists('Name', $temp_table)
174 $tracking_version = PMA_Tracker::getVersion(
175 $GLOBALS['db'],
176 $temp_table['Name']
178 if ($tracking_version == -1) {
179 $my_tables[] = $temp_table['Name'];
183 } else { // If $value is a table.
184 if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
185 $my_tables[] = $value['Name'];
190 // If untracked tables exist
191 if (isset($my_tables)) {
193 <h3><?php echo __('Untracked tables');?></h3>
195 <table id="noversions" class="data">
196 <thead>
197 <tr>
198 <th style="width: 300px"><?php echo __('Table');?></th>
199 <th></th>
200 </tr>
201 </thead>
202 <tbody>
203 <?php
204 // Print out list of untracked tables
206 $style = 'odd';
208 foreach ($my_tables as $key => $tablename) {
209 if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
210 $my_link = '<a href="tbl_tracking.php?' . $url_query
211 . '&amp;table=' . htmlspecialchars($tablename) .'">';
212 $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
213 $my_link .= '</a>';
215 <tr class="noclick <?php echo $style;?>">
216 <td><?php echo htmlspecialchars($tablename);?></td>
217 <td><?php echo $my_link;?></td>
218 </tr>
219 <?php
220 if ($style == 'even') {
221 $style = 'odd';
222 } else {
223 $style = 'even';
228 </tbody>
229 </table>
231 <?php
233 // If available print out database log
234 if (count($data['ddlog']) > 0) {
235 $log = '';
236 foreach ($data['ddlog'] as $entry) {
237 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
238 . $entry['statement'] . "\n";
240 echo PMA_Util::getMessage(__('Database Log'), $log);