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_structure.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'])) {
35 PMA_Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
38 * If in an Ajax request, generate the success message and use
39 * {@link PMA_Response()} to send the output
41 if ($GLOBALS['is_ajax_request'] == true) {
42 $response = PMA_Response
::getInstance();
43 $response->addJSON('message', PMA_Message
::success());
48 // Get tracked data about the database
49 $data = PMA_Tracker
::getTrackedData($_REQUEST['db'], '', '1');
51 // No tables present and no log exist
52 if ($num_tables == 0 && count($data['ddlog']) == 0) {
53 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
55 if (empty($db_is_system_schema)) {
56 include 'libraries/display_create_table.lib.php';
61 // ---------------------------------------------------------------------------
63 // Prepare statement to get HEAD version
64 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
65 PMA_Util
::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
66 PMA_Util
::backquote($GLOBALS['cfg']['Server']['tracking']) .
67 ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db']) . '\' ' .
68 ' GROUP BY table_name' .
69 ' ORDER BY table_name ASC';
71 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
73 // If a HEAD version exists
74 if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
76 <div id
="tracked_tables">
77 <h3
><?php
echo __('Tracked tables');?
></h3
>
79 <table id
="versions" class="data">
82 <th
><?php
echo __('Database');?
></th
>
83 <th
><?php
echo __('Table');?
></th
>
84 <th
><?php
echo __('Last version');?
></th
>
85 <th
><?php
echo __('Created');?
></th
>
86 <th
><?php
echo __('Updated');?
></th
>
87 <th
><?php
echo __('Status');?
></th
>
88 <th
><?php
echo __('Action');?
></th
>
89 <th
><?php
echo __('Show');?
></th
>
95 // Print out information about versions
97 $drop_image_or_text = '';
98 if (PMA_Util
::showIcons('ActionLinksMode')) {
99 $drop_image_or_text .= PMA_Util
::getImage(
101 __('Delete tracking data for this table')
104 if (PMA_Util
::showText('ActionLinksMode')) {
105 $drop_image_or_text .= __('Drop');
109 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
110 list($table_name, $version_number) = $one_result;
111 $table_query = ' SELECT * FROM ' .
112 PMA_Util
::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
113 PMA_Util
::backquote($GLOBALS['cfg']['Server']['tracking']) .
114 ' WHERE `db_name` = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db'])
115 . '\' AND `table_name` = \'' . PMA_Util
::sqlAddSlashes($table_name)
116 . '\' AND `version` = \'' . $version_number . '\'';
118 $table_result = PMA_queryAsControlUser($table_query);
119 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
121 $tmp_link = 'tbl_tracking.php' . $url_query . '&table='
122 . htmlspecialchars($version_data['table_name']);
123 $delete_link = 'db_tracking.php' . $url_query . '&table='
124 . htmlspecialchars($version_data['table_name'])
125 . '&delete_tracking=true&';
127 <tr
class="noclick <?php echo $style;?>">
128 <td
><?php
echo htmlspecialchars($version_data['db_name']);?
></td
>
129 <td
><?php
echo htmlspecialchars($version_data['table_name']);?
></td
>
130 <td
><?php
echo $version_data['version'];?
></td
>
131 <td
><?php
echo $version_data['date_created'];?
></td
>
132 <td
><?php
echo $version_data['date_updated'];?
></td
>
133 <td
><?php
echo PMA_getVersionStatus($version_data);?
></td
>
135 <a
class="drop_tracking_anchor ajax" href
="<?php echo $delete_link;?>" >
136 <?php
echo $drop_image_or_text; ?
></a
>
140 . '<a href="' . $tmp_link . '">' . __('Versions') . '</a>'
142 . '<a href="' . $tmp_link . '&report=true&version='
143 . $version_data['version'] . '">' . __('Tracking report') . '</a>'
145 . '<a href="' . $tmp_link . '&snapshot=true&version='
146 . $version_data['version'] . '">' . __('Structure snapshot')
150 if ($style == 'even') {
164 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
166 // Get list of tables
167 $table_list = PMA_Util
::getTableList($GLOBALS['db']);
169 $my_tables = array();
171 // For each table try to get the tracking version
172 foreach ($table_list as $key => $value) {
173 // If $value is a table group.
174 if (array_key_exists(('is' . $sep . 'group'), $value)
175 && $value['is' . $sep . 'group']
177 foreach ($value as $temp_table) {
178 // If $temp_table is a table with the value for 'Name' is set,
179 // rather than a property of the table group.
180 if (is_array($temp_table)
181 && array_key_exists('Name', $temp_table)
183 $tracking_version = PMA_Tracker
::getVersion(
187 if ($tracking_version == -1) {
188 $my_tables[] = $temp_table['Name'];
192 } else { // If $value is a table.
193 if (PMA_Tracker
::getVersion($GLOBALS['db'], $value['Name']) == -1) {
194 $my_tables[] = $value['Name'];
199 // If untracked tables exist
200 if (count($my_tables) > 0) {
202 <h3
><?php
echo __('Untracked tables');?
></h3
>
204 <table id
="noversions" class="data">
207 <th style
="width: 300px"><?php
echo __('Table');?
></th
>
213 // Print out list of untracked tables
217 foreach ($my_tables as $key => $tablename) {
218 if (PMA_Tracker
::getVersion($GLOBALS['db'], $tablename) == -1) {
219 $my_link = '<a href="tbl_tracking.php' . $url_query
220 . '&table=' . htmlspecialchars($tablename) . '">';
221 $my_link .= PMA_Util
::getIcon('eye.png', __('Track table'));
224 <tr
class="noclick <?php echo $style;?>">
225 <td
><?php
echo htmlspecialchars($tablename);?
></td
>
226 <td
><?php
echo $my_link;?
></td
>
229 if ($style == 'even') {
241 // If available print out database log
242 if (count($data['ddlog']) > 0) {
244 foreach ($data['ddlog'] as $entry) {
245 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
246 . $entry['statement'] . "\n";
248 echo PMA_Util
::getMessage(__('Database Log'), $log);