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';
15 require_once 'libraries/display_create_table.lib.php';
17 //Get some js files needed for Ajax requests
18 $response = PMA_Response
::getInstance();
19 $header = $response->getHeader();
20 $scripts = $header->getScripts();
21 $scripts->addFile('jquery/jquery.tablesorter.js');
22 $scripts->addFile('db_tracking.js');
25 * If we are not in an Ajax request, then do the common work and show the links etc.
27 require 'libraries/db_common.inc.php';
28 $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php';
30 // Get the database structure
31 $sub_part = '_structure';
32 require 'libraries/db_info.inc.php';
35 // (here, do not use $_REQUEST['db] as it can be crafted)
36 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
38 PMA_Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
40 __('Tracking data deleted successfully.')
43 } elseif (isset($_REQUEST['submit_create_version'])) {
45 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
49 'Version %1$s was created for selected tables,'
50 . ' tracking is active for them.'
52 htmlspecialchars($_REQUEST['version'])
56 } elseif (isset($_REQUEST['submit_mult'])) {
58 if (! empty($_REQUEST['selected_tbl'])) {
59 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
61 foreach ($_REQUEST['selected_tbl'] as $table) {
62 PMA_Tracker
::deleteTracking($GLOBALS['db'], $table);
65 __('Tracking data deleted successfully.')
68 } elseif ($_REQUEST['submit_mult'] == 'track') {
70 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
71 'db_tracking.php' . $url_query,
74 $_REQUEST['selected_tbl']
80 __('No tables selected.')
85 // Get tracked data about the database
86 $data = PMA_Tracker
::getTrackedData($_REQUEST['db'], '', '1');
88 // No tables present and no log exist
89 if ($num_tables == 0 && count($data['ddlog']) == 0) {
90 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
92 if (empty($db_is_system_schema)) {
93 echo PMA_getHtmlForCreateTable($db);
98 // ---------------------------------------------------------------------------
99 $cfgRelation = PMA_getRelationsParam();
101 // Prepare statement to get HEAD version
102 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
103 PMA_Util
::backquote($cfgRelation['db']) . '.' .
104 PMA_Util
::backquote($cfgRelation['tracking']) .
105 ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db']) . '\' ' .
106 ' GROUP BY table_name' .
107 ' ORDER BY table_name ASC';
109 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
111 // If a HEAD version exists
112 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
114 <div id
="tracked_tables">
115 <h3
><?php
echo __('Tracked tables');?
></h3
>
117 <form method
="post" action
="db_tracking.php" name
="trackedForm"
118 id
="trackedForm" class="ajax">
120 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
122 <table id
="versions" class="data">
126 <th
><?php
echo __('Table');?
></th
>
127 <th
><?php
echo __('Last version');?
></th
>
128 <th
><?php
echo __('Created');?
></th
>
129 <th
><?php
echo __('Updated');?
></th
>
130 <th
><?php
echo __('Status');?
></th
>
131 <th
><?php
echo __('Action');?
></th
>
132 <th
><?php
echo __('Show');?
></th
>
138 // Print out information about versions
140 $delete = PMA_Util
::getIcon('b_drop.png', __('Delete tracking'));
141 $versions = PMA_Util
::getIcon('b_versions.png', __('Versions'));
142 $report = PMA_Util
::getIcon('b_report.png', __('Tracking report'));
143 $structure = PMA_Util
::getIcon('b_props.png', __('Structure snapshot'));
146 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
147 list($table_name, $version_number) = $one_result;
148 $table_query = ' SELECT * FROM ' .
149 PMA_Util
::backquote($cfgRelation['db']) . '.' .
150 PMA_Util
::backquote($cfgRelation['tracking']) .
151 ' WHERE `db_name` = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db'])
152 . '\' AND `table_name` = \'' . PMA_Util
::sqlAddSlashes($table_name)
153 . '\' AND `version` = \'' . $version_number . '\'';
155 $table_result = PMA_queryAsControlUser($table_query);
156 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
158 $tmp_link = 'tbl_tracking.php' . $url_query . '&table='
159 . htmlspecialchars($version_data['table_name']);
160 $delete_link = 'db_tracking.php' . $url_query . '&table='
161 . htmlspecialchars($version_data['table_name'])
162 . '&delete_tracking=true&';
163 $checkbox_id = "selected_tbl_"
164 . htmlspecialchars($version_data['table_name']);
166 <tr
class="<?php echo $style;?>">
168 <input type
="checkbox" name
="selected_tbl[]"
169 class="checkall" id
="<?php echo $checkbox_id;?>"
170 value
="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
173 <label
for="<?php echo $checkbox_id;?>">
174 <?php
echo htmlspecialchars($version_data['table_name']);?
>
177 <td
class="right"><?php
echo $version_data['version'];?
></td
>
178 <td
><?php
echo $version_data['date_created'];?
></td
>
179 <td
><?php
echo $version_data['date_updated'];?
></td
>
182 $state = PMA_getVersionStatus($version_data);
185 'label' => __('not active'),
186 'value' => 'deactivate_now',
187 'selected' => ($state != 'active')
190 'label' => __('active'),
191 'value' => 'activate_now',
192 'selected' => ($state == 'active')
195 echo PMA_Util
::toggleButton(
196 $tmp_link . '&version=' . $version_data['version'],
204 <a
class="delete_tracking_anchor ajax"
205 href
="<?php echo $delete_link;?>" >
206 <?php
echo $delete; ?
></a
>
210 . '<a href="' . $tmp_link . '">' . $versions . '</a>'
212 . '<a href="' . $tmp_link . '&report=true&version='
213 . $version_data['version'] . '">' . $report . '</a>'
215 . '<a href="' . $tmp_link . '&snapshot=true&version='
216 . $version_data['version'] . '">' . $structure . '</a>'
219 if ($style == 'even') {
230 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
231 echo PMA_Util
::getButtonOrImage(
232 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
233 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
241 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
243 // Get list of tables
244 $table_list = PMA_Util
::getTableList($GLOBALS['db']);
246 $my_tables = array();
248 // For each table try to get the tracking version
249 foreach ($table_list as $key => $value) {
250 // If $value is a table group.
251 if (array_key_exists(('is' . $sep . 'group'), $value)
252 && $value['is' . $sep . 'group']
254 foreach ($value as $temp_table) {
255 // If $temp_table is a table with the value for 'Name' is set,
256 // rather than a property of the table group.
257 if (is_array($temp_table)
258 && array_key_exists('Name', $temp_table)
260 $tracking_version = PMA_Tracker
::getVersion(
264 if ($tracking_version == -1) {
265 $my_tables[] = $temp_table['Name'];
269 } else { // If $value is a table.
270 if (PMA_Tracker
::getVersion($GLOBALS['db'], $value['Name']) == -1) {
271 $my_tables[] = $value['Name'];
276 // If untracked tables exist
277 if (count($my_tables) > 0) {
279 <h3
><?php
echo __('Untracked tables');?
></h3
>
280 <form method
="post" action
="db_tracking.php" name
="untrackedForm"
281 id
="untrackedForm" class="ajax">
283 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
285 <table id
="noversions" class="data">
289 <th style
="width: 300px"><?php
echo __('Table');?
></th
>
290 <th
><?php
echo __('Action');?
></th
>
295 // Print out list of untracked tables
299 foreach ($my_tables as $key => $tablename) {
300 $checkbox_id = "selected_tbl_"
301 . htmlspecialchars($tablename);
302 if (PMA_Tracker
::getVersion($GLOBALS['db'], $tablename) == -1) {
303 $my_link = '<a href="tbl_tracking.php' . $url_query
304 . '&table=' . htmlspecialchars($tablename) . '">';
305 $my_link .= PMA_Util
::getIcon('eye.png', __('Track table'));
308 <tr
class="<?php echo $style;?>">
310 <input type
="checkbox" name
="selected_tbl[]"
311 class="checkall" id
="<?php echo $checkbox_id;?>"
312 value
="<?php echo htmlspecialchars($tablename);?>"/>
315 <label
for="<?php echo $checkbox_id;?>">
316 <?php
echo htmlspecialchars($tablename);?
>
319 <td
><?php
echo $my_link;?
></td
>
322 if ($style == 'even') {
333 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
334 echo PMA_Util
::getButtonOrImage(
335 'submit_mult', 'mult_submit', 'submit_mult_track',
336 __('Track table'), 'eye.png', 'track'
342 // If available print out database log
343 if (count($data['ddlog']) > 0) {
345 foreach ($data['ddlog'] as $entry) {
346 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
347 . $entry['statement'] . "\n";
349 echo PMA_Util
::getMessage(__('Database Log'), $log);