2 /* vim: set expandtab sw=4 ts=4 sts=4: */
10 require_once 'libraries/common.inc.php';
12 //Get some js files needed for Ajax requests
13 $GLOBALS['js_include'][] = 'db_structure.js';
16 * If we are not in an Ajax request, then do the common work and show the links etc.
18 if ($GLOBALS['is_ajax_request'] != true) {
19 include 'libraries/db_common.inc.php';
21 $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php';
23 // Get the database structure
24 $sub_part = '_structure';
25 require 'libraries/db_info.inc.php';
28 // (here, do not use $_REQUEST['db] as it can be crafted)
29 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
30 PMA_Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
33 * If in an Ajax request, generate the success message and use
34 * {@link PMA_ajaxResponse()} to send the output
36 if ($GLOBALS['is_ajax_request'] == true) {
37 $message = PMA_Message
::success();
38 PMA_ajaxResponse($message, true);
42 // Get tracked data about the database
43 $data = PMA_Tracker
::getTrackedData($_REQUEST['db'], '', '1');
45 // No tables present and no log exist
46 if ($num_tables == 0 && count($data['ddlog']) == 0) {
47 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
49 if (empty($db_is_information_schema)) {
50 include 'libraries/display_create_table.lib.php';
54 include 'libraries/footer.inc.php';
58 // ---------------------------------------------------------------------------
61 * Display top menu links
63 require_once 'libraries/db_links.inc.php';
65 // Prepare statement to get HEAD version
66 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
67 PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
68 PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
69 ' WHERE db_name = \'' . PMA_sqlAddSlashes($_REQUEST['db']) . '\' ' .
70 ' GROUP BY table_name' .
71 ' ORDER BY table_name ASC';
73 $all_tables_result = PMA_query_as_controluser($all_tables_query);
75 // If a HEAD version exists
76 if (PMA_DBI_num_rows($all_tables_result) > 0) {
78 <div id
="tracked_tables">
79 <h3
><?php
echo __('Tracked tables');?
></h3
>
81 <table id
="versions" class="data">
84 <th
><?php
echo __('Database');?
></th
>
85 <th
><?php
echo __('Table');?
></th
>
86 <th
><?php
echo __('Last version');?
></th
>
87 <th
><?php
echo __('Created');?
></th
>
88 <th
><?php
echo __('Updated');?
></th
>
89 <th
><?php
echo __('Status');?
></th
>
90 <th
><?php
echo __('Action');?
></th
>
91 <th
><?php
echo __('Show');?
></th
>
97 // Print out information about versions
99 $drop_image_or_text = '';
100 if (true == $GLOBALS['cfg']['PropertiesIconic']) {
101 $drop_image_or_text .= PMA_getImage('b_drop.png', __('Delete tracking data for this table'));
103 if ('both' === $GLOBALS['cfg']['PropertiesIconic']
104 ||
false === $GLOBALS['cfg']['PropertiesIconic']
106 $drop_image_or_text .= __('Drop');
110 while ($one_result = PMA_DBI_fetch_array($all_tables_result)) {
111 list($table_name, $version_number) = $one_result;
112 $table_query = ' SELECT * FROM ' .
113 PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
114 PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
115 ' WHERE `db_name` = \'' . PMA_sqlAddSlashes($_REQUEST['db'])
116 . '\' AND `table_name` = \'' . PMA_sqlAddSlashes($table_name)
117 . '\' AND `version` = \'' . $version_number . '\'';
119 $table_result = PMA_query_as_controluser($table_query);
120 $version_data = PMA_DBI_fetch_array($table_result);
122 if ($version_data['tracking_active'] == 1) {
123 $version_status = __('active');
125 $version_status = __('not active');
127 $tmp_link = 'tbl_tracking.php?' . $url_query . '&table='
128 . htmlspecialchars($version_data['table_name']);
129 $delete_link = 'db_tracking.php?' . $url_query . '&table='
130 . htmlspecialchars($version_data['table_name']) . '&delete_tracking=true&';
132 <tr
class="noclick <?php echo $style;?>">
133 <td
><?php
echo htmlspecialchars($version_data['db_name']);?
></td
>
134 <td
><?php
echo htmlspecialchars($version_data['table_name']);?
></td
>
135 <td
><?php
echo $version_data['version'];?
></td
>
136 <td
><?php
echo $version_data['date_created'];?
></td
>
137 <td
><?php
echo $version_data['date_updated'];?
></td
>
138 <td
><?php
echo $version_status;?
></td
>
139 <td
><a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="drop_tracking_anchor"' : ''); ?
> href
="<?php echo $delete_link;?>" ><?php
echo $drop_image_or_text; ?
></a
></td
>
140 <td
> <a href
="<?php echo $tmp_link; ?>"><?php
echo __('Versions');?
></a
>
141 |
<a href
="<?php echo $tmp_link; ?>&report=true&version=<?php echo $version_data['version'];?>"><?php
echo __('Tracking report');?
></a
>
142 |
<a href
="<?php echo $tmp_link; ?>&snapshot=true&version=<?php echo $version_data['version'];?>"><?php
echo __('Structure snapshot');?
></a
></td
>
145 if ($style == 'even') {
159 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
161 // Get list of tables
162 $table_list = PMA_getTableList($GLOBALS['db']);
164 // For each table try to get the tracking version
165 foreach ($table_list as $key => $value) {
166 // If $value is a table group.
167 if (array_key_exists(('is' . $sep . 'group'), $value) && $value['is' . $sep . 'group']) {
168 foreach ($value as $temp_table) {
169 // If $temp_table is a table with the value for 'Name' is set,
170 // rather than a propery of the table group.
171 if (is_array($temp_table) && array_key_exists('Name', $temp_table)) {
172 if (PMA_Tracker
::getVersion($GLOBALS['db'], $temp_table['Name']) == -1) {
173 $my_tables[] = $temp_table['Name'];
177 // If $value is a table.
179 if (PMA_Tracker
::getVersion($GLOBALS['db'], $value['Name']) == -1) {
180 $my_tables[] = $value['Name'];
185 // If untracked tables exist
186 if (isset($my_tables)) {
188 <h3
><?php
echo __('Untracked tables');?
></h3
>
190 <table id
="noversions" class="data">
193 <th style
="width: 300px"><?php
echo __('Table');?
></th
>
199 // Print out list of untracked tables
203 foreach ($my_tables as $key => $tablename) {
204 if (PMA_Tracker
::getVersion($GLOBALS['db'], $tablename) == -1) {
205 $my_link = '<a href="tbl_tracking.php?' . $url_query
206 . '&table=' . htmlspecialchars($tablename) .'">';
207 $my_link .= PMA_getIcon('eye.png', __('Track table')) . '</a>';
209 <tr
class="noclick <?php echo $style;?>">
210 <td
><?php
echo htmlspecialchars($tablename);?
></td
>
211 <td
><?php
echo $my_link;?
></td
>
214 if ($style == 'even') {
227 // If available print out database log
228 if (count($data['ddlog']) > 0) {
230 foreach ($data['ddlog'] as $entry) {
231 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n" . $entry['statement'] . "\n";
233 PMA_showMessage(__('Database Log'), $log);
239 require 'libraries/footer.inc.php';