2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tracking configuration for database
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_tracking.js');
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 .= '&goto=tbl_tracking.php&back=db_tracking.php';
28 // Get the database structure
29 $sub_part = '_structure';
30 require 'libraries/db_info.inc.php';
33 // (here, do not use $_REQUEST['db] as it can be crafted)
34 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
36 PMA_Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
38 __('Tracking data deleted successfully.')
41 } elseif (isset($_REQUEST['submit_create_version'])) {
43 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
47 'Version %1$s was created for selected tables,'
48 . ' tracking is active for them.'
50 htmlspecialchars($_REQUEST['version'])
54 } elseif (isset($_REQUEST['submit_mult'])) {
56 if (! empty($_REQUEST['selected_tbl'])) {
57 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
59 foreach ($_REQUEST['selected_tbl'] as $table) {
60 PMA_Tracker
::deleteTracking($GLOBALS['db'], $table);
63 __('Tracking data deleted successfully.')
66 } elseif ($_REQUEST['submit_mult'] == 'track') {
68 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
69 'db_tracking.php' . $url_query,
72 $_REQUEST['selected_tbl']
78 __('No tables selected.')
83 // Get tracked data about the database
84 $data = PMA_Tracker
::getTrackedData($_REQUEST['db'], '', '1');
86 // No tables present and no log exist
87 if ($num_tables == 0 && count($data['ddlog']) == 0) {
88 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
90 if (empty($db_is_system_schema)) {
91 include 'libraries/display_create_table.lib.php';
96 // ---------------------------------------------------------------------------
97 $cfgRelation = PMA_getRelationsParam();
99 // Prepare statement to get HEAD version
100 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
101 PMA_Util
::backquote($cfgRelation['db']) . '.' .
102 PMA_Util
::backquote($cfgRelation['tracking']) .
103 ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db']) . '\' ' .
104 ' GROUP BY table_name' .
105 ' ORDER BY table_name ASC';
107 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
109 // If a HEAD version exists
110 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
112 <div id
="tracked_tables">
113 <h3
><?php
echo __('Tracked tables');?
></h3
>
115 <form method
="post" action
="db_tracking.php" name
="trackedForm"
116 id
="trackedForm" class="ajax">
118 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
120 <table id
="versions" class="data">
124 <th
><?php
echo __('Table');?
></th
>
125 <th
><?php
echo __('Last version');?
></th
>
126 <th
><?php
echo __('Created');?
></th
>
127 <th
><?php
echo __('Updated');?
></th
>
128 <th
><?php
echo __('Status');?
></th
>
129 <th
><?php
echo __('Action');?
></th
>
130 <th
><?php
echo __('Show');?
></th
>
136 // Print out information about versions
138 $delete_image_or_text = '';
139 if (PMA_Util
::showIcons('ActionLinksMode')) {
140 $delete_image_or_text .= PMA_Util
::getImage(
142 __('Delete tracking data for this table')
145 if (PMA_Util
::showText('ActionLinksMode')) {
146 $delete_image_or_text .= __('Delete tracking');
150 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
151 list($table_name, $version_number) = $one_result;
152 $table_query = ' SELECT * FROM ' .
153 PMA_Util
::backquote($cfgRelation['db']) . '.' .
154 PMA_Util
::backquote($cfgRelation['tracking']) .
155 ' WHERE `db_name` = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db'])
156 . '\' AND `table_name` = \'' . PMA_Util
::sqlAddSlashes($table_name)
157 . '\' AND `version` = \'' . $version_number . '\'';
159 $table_result = PMA_queryAsControlUser($table_query);
160 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
162 $tmp_link = 'tbl_tracking.php' . $url_query . '&table='
163 . htmlspecialchars($version_data['table_name']);
164 $delete_link = 'db_tracking.php' . $url_query . '&table='
165 . htmlspecialchars($version_data['table_name'])
166 . '&delete_tracking=true&';
168 <tr
class="noclick <?php echo $style;?>">
170 <input type
="checkbox" name
="selected_tbl[]" class="checkall"
171 value
="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
173 <td
><?php
echo htmlspecialchars($version_data['table_name']);?
></td
>
174 <td
><?php
echo $version_data['version'];?
></td
>
175 <td
><?php
echo $version_data['date_created'];?
></td
>
176 <td
><?php
echo $version_data['date_updated'];?
></td
>
177 <td
><?php
echo PMA_getVersionStatus($version_data);?
></td
>
179 <a
class="delete_tracking_anchor ajax" href
="<?php echo $delete_link;?>" >
180 <?php
echo $delete_image_or_text; ?
></a
>
184 . '<a href="' . $tmp_link . '">' . __('Versions') . '</a>'
186 . '<a href="' . $tmp_link . '&report=true&version='
187 . $version_data['version'] . '">' . __('Tracking report') . '</a>'
189 . '<a href="' . $tmp_link . '&snapshot=true&version='
190 . $version_data['version'] . '">' . __('Structure snapshot')
194 if ($style == 'even') {
205 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
206 echo PMA_Util
::getButtonOrImage(
207 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
208 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
216 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
218 // Get list of tables
219 $table_list = PMA_Util
::getTableList($GLOBALS['db']);
221 $my_tables = array();
223 // For each table try to get the tracking version
224 foreach ($table_list as $key => $value) {
225 // If $value is a table group.
226 if (array_key_exists(('is' . $sep . 'group'), $value)
227 && $value['is' . $sep . 'group']
229 foreach ($value as $temp_table) {
230 // If $temp_table is a table with the value for 'Name' is set,
231 // rather than a property of the table group.
232 if (is_array($temp_table)
233 && array_key_exists('Name', $temp_table)
235 $tracking_version = PMA_Tracker
::getVersion(
239 if ($tracking_version == -1) {
240 $my_tables[] = $temp_table['Name'];
244 } else { // If $value is a table.
245 if (PMA_Tracker
::getVersion($GLOBALS['db'], $value['Name']) == -1) {
246 $my_tables[] = $value['Name'];
251 // If untracked tables exist
252 if (count($my_tables) > 0) {
254 <h3
><?php
echo __('Untracked tables');?
></h3
>
255 <form method
="post" action
="db_tracking.php" name
="untrackedForm"
256 id
="untrackedForm" class="ajax">
258 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
260 <table id
="noversions" class="data">
264 <th style
="width: 300px"><?php
echo __('Table');?
></th
>
265 <th
><?php
echo __('Action');?
></th
>
270 // Print out list of untracked tables
274 foreach ($my_tables as $key => $tablename) {
275 if (PMA_Tracker
::getVersion($GLOBALS['db'], $tablename) == -1) {
276 $my_link = '<a href="tbl_tracking.php' . $url_query
277 . '&table=' . htmlspecialchars($tablename) . '">';
278 $my_link .= PMA_Util
::getIcon('eye.png', __('Track table'));
281 <tr
class="noclick <?php echo $style;?>">
283 <input type
="checkbox" name
="selected_tbl[]" class="checkall"
284 value
="<?php echo htmlspecialchars($tablename);?>"/>
286 <td
><?php
echo htmlspecialchars($tablename);?
></td
>
287 <td
><?php
echo $my_link;?
></td
>
290 if ($style == 'even') {
301 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
302 echo PMA_Util
::getButtonOrImage(
303 'submit_mult', 'mult_submit', 'submit_mult_track',
304 __('Track table'), 'eye.png', 'track'
310 // If available print out database log
311 if (count($data['ddlog']) > 0) {
313 foreach ($data['ddlog'] as $entry) {
314 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
315 . $entry['statement'] . "\n";
317 echo PMA_Util
::getMessage(__('Database Log'), $log);