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="<?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"
204 href
="<?php echo $delete_link;?>" >
205 <?php
echo $delete; ?
></a
>
209 . '<a href="' . $tmp_link . '">' . $versions . '</a>'
211 . '<a href="' . $tmp_link . '&report=true&version='
212 . $version_data['version'] . '">' . $report . '</a>'
214 . '<a href="' . $tmp_link . '&snapshot=true&version='
215 . $version_data['version'] . '">' . $structure . '</a>'
218 if ($style == 'even') {
229 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "trackedForm");
230 echo PMA_Util
::getButtonOrImage(
231 'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
232 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
240 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
242 // Get list of tables
243 $table_list = PMA_Util
::getTableList($GLOBALS['db']);
245 $my_tables = array();
247 // For each table try to get the tracking version
248 foreach ($table_list as $key => $value) {
249 // If $value is a table group.
250 if (array_key_exists(('is' . $sep . 'group'), $value)
251 && $value['is' . $sep . 'group']
253 foreach ($value as $temp_table) {
254 // If $temp_table is a table with the value for 'Name' is set,
255 // rather than a property of the table group.
256 if (is_array($temp_table)
257 && array_key_exists('Name', $temp_table)
259 $tracking_version = PMA_Tracker
::getVersion(
263 if ($tracking_version == -1) {
264 $my_tables[] = $temp_table['Name'];
268 } else { // If $value is a table.
269 if (PMA_Tracker
::getVersion($GLOBALS['db'], $value['Name']) == -1) {
270 $my_tables[] = $value['Name'];
275 // If untracked tables exist
276 if (count($my_tables) > 0) {
278 <h3
><?php
echo __('Untracked tables');?
></h3
>
279 <form method
="post" action
="db_tracking.php" name
="untrackedForm"
280 id
="untrackedForm" class="ajax">
282 echo PMA_URL_getHiddenInputs($GLOBALS['db'])
284 <table id
="noversions" class="data">
288 <th style
="width: 300px"><?php
echo __('Table');?
></th
>
289 <th
><?php
echo __('Action');?
></th
>
294 // Print out list of untracked tables
298 foreach ($my_tables as $key => $tablename) {
299 $checkbox_id = "selected_tbl_"
300 . htmlspecialchars($tablename);
301 if (PMA_Tracker
::getVersion($GLOBALS['db'], $tablename) == -1) {
302 $my_link = '<a href="tbl_tracking.php' . $url_query
303 . '&table=' . htmlspecialchars($tablename) . '">';
304 $my_link .= PMA_Util
::getIcon('eye.png', __('Track table'));
307 <tr
class="<?php echo $style;?>">
309 <input type
="checkbox" name
="selected_tbl[]"
310 class="checkall" id
="<?php echo $checkbox_id;?>"
311 value
="<?php echo htmlspecialchars($tablename);?>"/>
314 <label
for="<?php echo $checkbox_id;?>">
315 <?php
echo htmlspecialchars($tablename);?
>
318 <td
><?php
echo $my_link;?
></td
>
321 if ($style == 'even') {
332 echo PMA_Util
::getWithSelected($pmaThemeImage, $text_dir, "untrackedForm");
333 echo PMA_Util
::getButtonOrImage(
334 'submit_mult', 'mult_submit', 'submit_mult_track',
335 __('Track table'), 'eye.png', 'track'
341 // If available print out database log
342 if (count($data['ddlog']) > 0) {
344 foreach ($data['ddlog'] as $entry) {
345 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
346 . $entry['statement'] . "\n";
348 echo PMA_Util
::getMessage(__('Database Log'), $log);