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('jquery/jquery.tablesorter.js');
21 $scripts->addFile('db_tracking.js');
24 * If we are not in an Ajax request, then do the common work and show the links etc.
26 require 'libraries/db_common.inc.php';
27 $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php';
29 // Get the database structure
30 $sub_part = '_structure';
31 require 'libraries/db_info.inc.php';
34 // (here, do not use $_REQUEST['db] as it can be crafted)
35 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
37 PMA_Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
39 __('Tracking data deleted successfully.')
42 } elseif (isset($_REQUEST['submit_create_version'])) {
44 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
48 'Version %1$s was created for selected tables,'
49 . ' tracking is active for them.'
51 htmlspecialchars($_REQUEST['version'])
55 } elseif (isset($_REQUEST['submit_mult'])) {
57 if (! empty($_REQUEST['selected_tbl'])) {
58 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
60 foreach ($_REQUEST['selected_tbl'] as $table) {
61 PMA_Tracker
::deleteTracking($GLOBALS['db'], $table);
64 __('Tracking data deleted successfully.')
67 } elseif ($_REQUEST['submit_mult'] == 'track') {
69 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
70 'db_tracking.php' . $url_query,
73 $_REQUEST['selected_tbl']
79 __('No tables selected.')
84 // Get tracked data about the database
85 $data = PMA_Tracker
::getTrackedData($_REQUEST['db'], '', '1');
87 // No tables present and no log exist
88 if ($num_tables == 0 && count($data['ddlog']) == 0) {
89 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
91 if (empty($db_is_system_schema)) {
92 include 'libraries/display_create_table.lib.php';
97 // ---------------------------------------------------------------------------
98 $cfgRelation = PMA_getRelationsParam();
100 // Prepare statement to get HEAD version
101 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
102 PMA_Util
::backquote($cfgRelation['db']) . '.' .
103 PMA_Util
::backquote($cfgRelation['tracking']) .
104 ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db']) . '\' ' .
105 ' GROUP BY table_name' .
106 ' ORDER BY table_name ASC';
108 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
110 // If a HEAD version exists
111 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
113 <div id
="tracked_tables">
114 <h3
><?php
echo __('Tracked tables');?
></h3
>
116 <form method
="post" action
="db_tracking.php" name
="trackedForm"
117 id
="trackedForm" class="ajax">
119 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
121 <table id
="versions" class="data">
125 <th
><?php
echo __('Table');?
></th
>
126 <th
><?php
echo __('Last version');?
></th
>
127 <th
><?php
echo __('Created');?
></th
>
128 <th
><?php
echo __('Updated');?
></th
>
129 <th
><?php
echo __('Status');?
></th
>
130 <th
><?php
echo __('Action');?
></th
>
131 <th
><?php
echo __('Show');?
></th
>
137 // Print out information about versions
139 $delete = PMA_Util
::getIcon('b_drop.png', __('Delete tracking'));
140 $versions = PMA_Util
::getIcon('b_versions.png', __('Versions'));
141 $report = PMA_Util
::getIcon('b_report.png', __('Tracking report'));
142 $structure = PMA_Util
::getIcon('b_props.png', __('Structure snapshot'));
145 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
146 list($table_name, $version_number) = $one_result;
147 $table_query = ' SELECT * FROM ' .
148 PMA_Util
::backquote($cfgRelation['db']) . '.' .
149 PMA_Util
::backquote($cfgRelation['tracking']) .
150 ' WHERE `db_name` = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db'])
151 . '\' AND `table_name` = \'' . PMA_Util
::sqlAddSlashes($table_name)
152 . '\' AND `version` = \'' . $version_number . '\'';
154 $table_result = PMA_queryAsControlUser($table_query);
155 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
157 $tmp_link = 'tbl_tracking.php' . $url_query . '&table='
158 . htmlspecialchars($version_data['table_name']);
159 $delete_link = 'db_tracking.php' . $url_query . '&table='
160 . htmlspecialchars($version_data['table_name'])
161 . '&delete_tracking=true&';
162 $checkbox_id = "selected_tbl_"
163 . htmlspecialchars($version_data['table_name']);
165 <tr
class="noclick <?php echo $style;?>">
167 <input type
="checkbox" name
="selected_tbl[]"
168 class="checkall" id
="<?php echo $checkbox_id;?>"
169 value
="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
172 <label
for="<?php echo $checkbox_id;?>">
173 <?php
echo htmlspecialchars($version_data['table_name']);?
>
176 <td
class="right"><?php
echo $version_data['version'];?
></td
>
177 <td
><?php
echo $version_data['date_created'];?
></td
>
178 <td
><?php
echo $version_data['date_updated'];?
></td
>
181 $state = PMA_getVersionStatus($version_data);
184 'label' => __('not active'),
185 'value' => 'deactivate_now',
186 'selected' => ($state != 'active')
189 'label' => __('active'),
190 'value' => 'activate_now',
191 'selected' => ($state == 'active')
194 echo PMA_Util
::toggleButton(
195 $tmp_link . '&version=' . $version_data['version'],
203 <a
class="delete_tracking_anchor ajax" href
="<?php echo $delete_link;?>" >
204 <?php
echo $delete; ?
></a
>
208 . '<a href="' . $tmp_link . '">' . $versions . '</a>'
210 . '<a href="' . $tmp_link . '&report=true&version='
211 . $version_data['version'] . '">' . $report . '</a>'
213 . '<a href="' . $tmp_link . '&snapshot=true&version='
214 . $version_data['version'] . '">' . $structure . '</a>'
217 if ($style == 'even') {
228 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
229 echo PMA_Util
::getButtonOrImage(
230 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
231 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
239 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
241 // Get list of tables
242 $table_list = PMA_Util
::getTableList($GLOBALS['db']);
244 $my_tables = array();
246 // For each table try to get the tracking version
247 foreach ($table_list as $key => $value) {
248 // If $value is a table group.
249 if (array_key_exists(('is' . $sep . 'group'), $value)
250 && $value['is' . $sep . 'group']
252 foreach ($value as $temp_table) {
253 // If $temp_table is a table with the value for 'Name' is set,
254 // rather than a property of the table group.
255 if (is_array($temp_table)
256 && array_key_exists('Name', $temp_table)
258 $tracking_version = PMA_Tracker
::getVersion(
262 if ($tracking_version == -1) {
263 $my_tables[] = $temp_table['Name'];
267 } else { // If $value is a table.
268 if (PMA_Tracker
::getVersion($GLOBALS['db'], $value['Name']) == -1) {
269 $my_tables[] = $value['Name'];
274 // If untracked tables exist
275 if (count($my_tables) > 0) {
277 <h3
><?php
echo __('Untracked tables');?
></h3
>
278 <form method
="post" action
="db_tracking.php" name
="untrackedForm"
279 id
="untrackedForm" class="ajax">
281 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
283 <table id
="noversions" class="data">
287 <th style
="width: 300px"><?php
echo __('Table');?
></th
>
288 <th
><?php
echo __('Action');?
></th
>
293 // Print out list of untracked tables
297 foreach ($my_tables as $key => $tablename) {
298 $checkbox_id = "selected_tbl_"
299 . htmlspecialchars($tablename);
300 if (PMA_Tracker
::getVersion($GLOBALS['db'], $tablename) == -1) {
301 $my_link = '<a href="tbl_tracking.php' . $url_query
302 . '&table=' . htmlspecialchars($tablename) . '">';
303 $my_link .= PMA_Util
::getIcon('eye.png', __('Track table'));
306 <tr
class="noclick <?php echo $style;?>">
308 <input type
="checkbox" name
="selected_tbl[]"
309 class="checkall" id
="<?php echo $checkbox_id;?>"
310 value
="<?php echo htmlspecialchars($tablename);?>"/>
313 <label
for="<?php echo $checkbox_id;?>">
314 <?php
echo htmlspecialchars($tablename);?
>
317 <td
><?php
echo $my_link;?
></td
>
320 if ($style == 'even') {
331 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
332 echo PMA_Util
::getButtonOrImage(
333 'submit_mult', 'mult_submit', 'submit_mult_track',
334 __('Track table'), 'eye.png', 'track'
340 // If available print out database log
341 if (count($data['ddlog']) > 0) {
343 foreach ($data['ddlog'] as $entry) {
344 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
345 . $entry['statement'] . "\n";
347 echo PMA_Util
::getMessage(__('Database Log'), $log);