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 // ---------------------------------------------------------------------------
98 // Prepare statement to get HEAD version
99 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
100 PMA_Util
::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
101 PMA_Util
::backquote($GLOBALS['cfg']['Server']['tracking']) .
102 ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db']) . '\' ' .
103 ' GROUP BY table_name' .
104 ' ORDER BY table_name ASC';
106 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
108 // If a HEAD version exists
109 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
111 <div id
="tracked_tables">
112 <h3
><?php
echo __('Tracked tables');?
></h3
>
114 <form method
="post" action
="db_tracking.php" name
="trackedForm"
115 id
="trackedForm" class="ajax">
117 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
119 <table id
="versions" class="data">
123 <th
><?php
echo __('Table');?
></th
>
124 <th
><?php
echo __('Last version');?
></th
>
125 <th
><?php
echo __('Created');?
></th
>
126 <th
><?php
echo __('Updated');?
></th
>
127 <th
><?php
echo __('Status');?
></th
>
128 <th
><?php
echo __('Action');?
></th
>
129 <th
><?php
echo __('Show');?
></th
>
135 // Print out information about versions
137 $delete_image_or_text = '';
138 if (PMA_Util
::showIcons('ActionLinksMode')) {
139 $delete_image_or_text .= PMA_Util
::getImage(
141 __('Delete tracking data for this table')
144 if (PMA_Util
::showText('ActionLinksMode')) {
145 $delete_image_or_text .= __('Delete tracking');
149 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
150 list($table_name, $version_number) = $one_result;
151 $table_query = ' SELECT * FROM ' .
152 PMA_Util
::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
153 PMA_Util
::backquote($GLOBALS['cfg']['Server']['tracking']) .
154 ' WHERE `db_name` = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db'])
155 . '\' AND `table_name` = \'' . PMA_Util
::sqlAddSlashes($table_name)
156 . '\' AND `version` = \'' . $version_number . '\'';
158 $table_result = PMA_queryAsControlUser($table_query);
159 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
161 $tmp_link = 'tbl_tracking.php' . $url_query . '&table='
162 . htmlspecialchars($version_data['table_name']);
163 $delete_link = 'db_tracking.php' . $url_query . '&table='
164 . htmlspecialchars($version_data['table_name'])
165 . '&delete_tracking=true&';
167 <tr
class="noclick <?php echo $style;?>">
169 <input type
="checkbox" name
="selected_tbl[]" class="checkall"
170 value
="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
172 <td
><?php
echo htmlspecialchars($version_data['table_name']);?
></td
>
173 <td
><?php
echo $version_data['version'];?
></td
>
174 <td
><?php
echo $version_data['date_created'];?
></td
>
175 <td
><?php
echo $version_data['date_updated'];?
></td
>
176 <td
><?php
echo PMA_getVersionStatus($version_data);?
></td
>
178 <a
class="delete_tracking_anchor ajax" href
="<?php echo $delete_link;?>" >
179 <?php
echo $delete_image_or_text; ?
></a
>
183 . '<a href="' . $tmp_link . '">' . __('Versions') . '</a>'
185 . '<a href="' . $tmp_link . '&report=true&version='
186 . $version_data['version'] . '">' . __('Tracking report') . '</a>'
188 . '<a href="' . $tmp_link . '&snapshot=true&version='
189 . $version_data['version'] . '">' . __('Structure snapshot')
193 if ($style == 'even') {
204 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
205 echo PMA_Util
::getButtonOrImage(
206 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
207 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
215 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
217 // Get list of tables
218 $table_list = PMA_Util
::getTableList($GLOBALS['db']);
220 $my_tables = array();
222 // For each table try to get the tracking version
223 foreach ($table_list as $key => $value) {
224 // If $value is a table group.
225 if (array_key_exists(('is' . $sep . 'group'), $value)
226 && $value['is' . $sep . 'group']
228 foreach ($value as $temp_table) {
229 // If $temp_table is a table with the value for 'Name' is set,
230 // rather than a property of the table group.
231 if (is_array($temp_table)
232 && array_key_exists('Name', $temp_table)
234 $tracking_version = PMA_Tracker
::getVersion(
238 if ($tracking_version == -1) {
239 $my_tables[] = $temp_table['Name'];
243 } else { // If $value is a table.
244 if (PMA_Tracker
::getVersion($GLOBALS['db'], $value['Name']) == -1) {
245 $my_tables[] = $value['Name'];
250 // If untracked tables exist
251 if (count($my_tables) > 0) {
253 <h3
><?php
echo __('Untracked tables');?
></h3
>
254 <form method
="post" action
="db_tracking.php" name
="untrackedForm"
255 id
="untrackedForm" class="ajax">
257 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
259 <table id
="noversions" class="data">
263 <th style
="width: 300px"><?php
echo __('Table');?
></th
>
264 <th
><?php
echo __('Action');?
></th
>
269 // Print out list of untracked tables
273 foreach ($my_tables as $key => $tablename) {
274 if (PMA_Tracker
::getVersion($GLOBALS['db'], $tablename) == -1) {
275 $my_link = '<a href="tbl_tracking.php' . $url_query
276 . '&table=' . htmlspecialchars($tablename) . '">';
277 $my_link .= PMA_Util
::getIcon('eye.png', __('Track table'));
280 <tr
class="noclick <?php echo $style;?>">
282 <input type
="checkbox" name
="selected_tbl[]" class="checkall"
283 value
="<?php echo htmlspecialchars($tablename);?>"/>
285 <td
><?php
echo htmlspecialchars($tablename);?
></td
>
286 <td
><?php
echo $my_link;?
></td
>
289 if ($style == 'even') {
300 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
301 echo PMA_Util
::getButtonOrImage(
302 'submit_mult', 'mult_submit', 'submit_mult_track',
303 __('Track table'), 'eye.png', 'track'
309 // If available print out database log
310 if (count($data['ddlog']) > 0) {
312 foreach ($data['ddlog'] as $entry) {
313 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
314 . $entry['statement'] . "\n";
316 echo PMA_Util
::getMessage(__('Database Log'), $log);