db_tracking.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * @package PhpMyAdmin
  5. */
  6. /**
  7. * Run common work
  8. */
  9. require_once 'libraries/common.inc.php';
  10. //Get some js files needed for Ajax requests
  11. $response = PMA_Response::getInstance();
  12. $header = $response->getHeader();
  13. $scripts = $header->getScripts();
  14. $scripts->addFile('db_structure.js');
  15. /**
  16. * If we are not in an Ajax request, then do the common work and show the links etc.
  17. */
  18. require 'libraries/db_common.inc.php';
  19. $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
  20. // Get the database structure
  21. $sub_part = '_structure';
  22. require 'libraries/db_info.inc.php';
  23. // Work to do?
  24. // (here, do not use $_REQUEST['db] as it can be crafted)
  25. if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
  26. PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
  27. /**
  28. * If in an Ajax request, generate the success message and use
  29. * {@link PMA_Response()} to send the output
  30. */
  31. if ($GLOBALS['is_ajax_request'] == true) {
  32. $response = PMA_Response::getInstance();
  33. $response->addJSON('message', PMA_Message::success());
  34. exit;
  35. }
  36. }
  37. // Get tracked data about the database
  38. $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
  39. // No tables present and no log exist
  40. if ($num_tables == 0 && count($data['ddlog']) == 0) {
  41. echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
  42. if (empty($db_is_information_schema)) {
  43. include 'libraries/display_create_table.lib.php';
  44. }
  45. exit;
  46. }
  47. // ---------------------------------------------------------------------------
  48. // Prepare statement to get HEAD version
  49. $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
  50. PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
  51. PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
  52. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db']) . '\' ' .
  53. ' GROUP BY table_name' .
  54. ' ORDER BY table_name ASC';
  55. $all_tables_result = PMA_queryAsControlUser($all_tables_query);
  56. // If a HEAD version exists
  57. if (PMA_DBI_num_rows($all_tables_result) > 0) {
  58. ?>
  59. <div id="tracked_tables">
  60. <h3><?php echo __('Tracked tables');?></h3>
  61. <table id="versions" class="data">
  62. <thead>
  63. <tr>
  64. <th><?php echo __('Database');?></th>
  65. <th><?php echo __('Table');?></th>
  66. <th><?php echo __('Last version');?></th>
  67. <th><?php echo __('Created');?></th>
  68. <th><?php echo __('Updated');?></th>
  69. <th><?php echo __('Status');?></th>
  70. <th><?php echo __('Action');?></th>
  71. <th><?php echo __('Show');?></th>
  72. </tr>
  73. </thead>
  74. <tbody>
  75. <?php
  76. // Print out information about versions
  77. $drop_image_or_text = '';
  78. if (in_array(
  79. $GLOBALS['cfg']['ActionLinksMode'],
  80. array('icons', 'both')
  81. )
  82. ) {
  83. $drop_image_or_text .= PMA_Util::getImage(
  84. 'b_drop.png',
  85. __('Delete tracking data for this table')
  86. );
  87. }
  88. if (in_array(
  89. $GLOBALS['cfg']['ActionLinksMode'],
  90. array('text', 'both')
  91. )
  92. ) {
  93. $drop_image_or_text .= __('Drop');
  94. }
  95. $style = 'odd';
  96. while ($one_result = PMA_DBI_fetch_array($all_tables_result)) {
  97. list($table_name, $version_number) = $one_result;
  98. $table_query = ' SELECT * FROM ' .
  99. PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
  100. PMA_Util::backquote($GLOBALS['cfg']['Server']['tracking']) .
  101. ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($_REQUEST['db'])
  102. . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table_name)
  103. . '\' AND `version` = \'' . $version_number . '\'';
  104. $table_result = PMA_queryAsControlUser($table_query);
  105. $version_data = PMA_DBI_fetch_array($table_result);
  106. if ($version_data['tracking_active'] == 1) {
  107. $version_status = __('active');
  108. } else {
  109. $version_status = __('not active');
  110. }
  111. $tmp_link = 'tbl_tracking.php?' . $url_query . '&amp;table='
  112. . htmlspecialchars($version_data['table_name']);
  113. $delete_link = 'db_tracking.php?' . $url_query . '&amp;table='
  114. . htmlspecialchars($version_data['table_name'])
  115. . '&amp;delete_tracking=true&amp';
  116. ?>
  117. <tr class="noclick <?php echo $style;?>">
  118. <td><?php echo htmlspecialchars($version_data['db_name']);?></td>
  119. <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
  120. <td><?php echo $version_data['version'];?></td>
  121. <td><?php echo $version_data['date_created'];?></td>
  122. <td><?php echo $version_data['date_updated'];?></td>
  123. <td><?php echo $version_status;?></td>
  124. <td><a class="drop_tracking_anchor ajax" href="<?php echo $delete_link;?>" ><?php echo $drop_image_or_text; ?></a></td>
  125. <td> <a href="<?php echo $tmp_link; ?>"><?php echo __('Versions');?></a>
  126. | <a href="<?php echo $tmp_link; ?>&amp;report=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Tracking report');?></a>
  127. | <a href="<?php echo $tmp_link; ?>&amp;snapshot=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Structure snapshot');?></a></td>
  128. </tr>
  129. <?php
  130. if ($style == 'even') {
  131. $style = 'odd';
  132. } else {
  133. $style = 'even';
  134. }
  135. }
  136. unset($tmp_link);
  137. ?>
  138. </tbody>
  139. </table>
  140. </div>
  141. <?php
  142. }
  143. $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
  144. // Get list of tables
  145. $table_list = PMA_Util::getTableList($GLOBALS['db']);
  146. // For each table try to get the tracking version
  147. foreach ($table_list as $key => $value) {
  148. // If $value is a table group.
  149. if (array_key_exists(('is' . $sep . 'group'), $value)
  150. && $value['is' . $sep . 'group']
  151. ) {
  152. foreach ($value as $temp_table) {
  153. // If $temp_table is a table with the value for 'Name' is set,
  154. // rather than a propery of the table group.
  155. if (is_array($temp_table)
  156. && array_key_exists('Name', $temp_table)
  157. ) {
  158. $tracking_version = PMA_Tracker::getVersion(
  159. $GLOBALS['db'],
  160. $temp_table['Name']
  161. );
  162. if ($tracking_version == -1) {
  163. $my_tables[] = $temp_table['Name'];
  164. }
  165. }
  166. }
  167. } else { // If $value is a table.
  168. if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
  169. $my_tables[] = $value['Name'];
  170. }
  171. }
  172. }
  173. // If untracked tables exist
  174. if (isset($my_tables)) {
  175. ?>
  176. <h3><?php echo __('Untracked tables');?></h3>
  177. <table id="noversions" class="data">
  178. <thead>
  179. <tr>
  180. <th style="width: 300px"><?php echo __('Table');?></th>
  181. <th></th>
  182. </tr>
  183. </thead>
  184. <tbody>
  185. <?php
  186. // Print out list of untracked tables
  187. $style = 'odd';
  188. foreach ($my_tables as $key => $tablename) {
  189. if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
  190. $my_link = '<a href="tbl_tracking.php?' . $url_query
  191. . '&amp;table=' . htmlspecialchars($tablename) .'">';
  192. $my_link .= PMA_Util::getIcon('eye.png', __('Track table'));
  193. $my_link .= '</a>';
  194. ?>
  195. <tr class="noclick <?php echo $style;?>">
  196. <td><?php echo htmlspecialchars($tablename);?></td>
  197. <td><?php echo $my_link;?></td>
  198. </tr>
  199. <?php
  200. if ($style == 'even') {
  201. $style = 'odd';
  202. } else {
  203. $style = 'even';
  204. }
  205. }
  206. }
  207. ?>
  208. </tbody>
  209. </table>
  210. <?php
  211. }
  212. // If available print out database log
  213. if (count($data['ddlog']) > 0) {
  214. $log = '';
  215. foreach ($data['ddlog'] as $entry) {
  216. $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
  217. . $entry['statement'] . "\n";
  218. }
  219. echo PMA_Util::getMessage(__('Database Log'), $log);
  220. }
  221. ?>