PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/db_tracking.php

https://bitbucket.org/adarshj/convenient_website
PHP | 234 lines | 164 code | 30 blank | 40 comment | 39 complexity | a85ef89f290cd68e03a0a07b080a2ed4 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  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. $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js';
  12. $GLOBALS['js_include'][] = 'db_structure.js';
  13. /**
  14. * If we are not in an Ajax request, then do the common work and show the links etc.
  15. */
  16. if ($GLOBALS['is_ajax_request'] != true) {
  17. include './libraries/db_common.inc.php';
  18. }
  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_ajaxResponse()} to send the output
  30. */
  31. if ($GLOBALS['is_ajax_request'] == true) {
  32. $message = PMA_Message::success();
  33. PMA_ajaxResponse($message, true);
  34. }
  35. }
  36. // Get tracked data about the database
  37. $data = PMA_Tracker::getTrackedData($_REQUEST['db'], '', '1');
  38. // No tables present and no log exist
  39. if ($num_tables == 0 && count($data['ddlog']) == 0) {
  40. echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
  41. if (empty($db_is_information_schema)) {
  42. include './libraries/display_create_table.lib.php';
  43. }
  44. // Display the footer
  45. include './libraries/footer.inc.php';
  46. exit;
  47. }
  48. // ---------------------------------------------------------------------------
  49. /*
  50. * Display top menu links
  51. */
  52. require_once './libraries/db_links.inc.php';
  53. // Prepare statement to get HEAD version
  54. $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
  55. PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
  56. PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
  57. ' WHERE db_name = \'' . PMA_sqlAddSlashes($_REQUEST['db']) . '\' ' .
  58. ' GROUP BY table_name' .
  59. ' ORDER BY table_name ASC';
  60. $all_tables_result = PMA_query_as_controluser($all_tables_query);
  61. // If a HEAD version exists
  62. if (PMA_DBI_num_rows($all_tables_result) > 0) {
  63. ?>
  64. <div id="tracked_tables">
  65. <h3><?php echo __('Tracked tables');?></h3>
  66. <table id="versions" class="data">
  67. <thead>
  68. <tr>
  69. <th><?php echo __('Database');?></th>
  70. <th><?php echo __('Table');?></th>
  71. <th><?php echo __('Last version');?></th>
  72. <th><?php echo __('Created');?></th>
  73. <th><?php echo __('Updated');?></th>
  74. <th><?php echo __('Status');?></th>
  75. <th><?php echo __('Action');?></th>
  76. <th><?php echo __('Show');?></th>
  77. </tr>
  78. </thead>
  79. <tbody>
  80. <?php
  81. // Print out information about versions
  82. $drop_image_or_text = '';
  83. if (true == $GLOBALS['cfg']['PropertiesIconic']) {
  84. $drop_image_or_text .= PMA_getImage('b_drop.png', __('Delete tracking data for this table'));
  85. }
  86. if ('both' === $GLOBALS['cfg']['PropertiesIconic'] || false === $GLOBALS['cfg']['PropertiesIconic']) {
  87. $drop_image_or_text .= __('Drop');
  88. }
  89. $style = 'odd';
  90. while ($one_result = PMA_DBI_fetch_array($all_tables_result)) {
  91. list($table_name, $version_number) = $one_result;
  92. $table_query = ' SELECT * FROM ' .
  93. PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' .
  94. PMA_backquote($GLOBALS['cfg']['Server']['tracking']) .
  95. ' WHERE `db_name` = \'' . PMA_sqlAddSlashes($_REQUEST['db']) . '\' AND `table_name` = \'' . PMA_sqlAddSlashes($table_name) . '\' AND `version` = \'' . $version_number . '\'';
  96. $table_result = PMA_query_as_controluser($table_query);
  97. $version_data = PMA_DBI_fetch_array($table_result);
  98. if ($version_data['tracking_active'] == 1) {
  99. $version_status = __('active');
  100. } else {
  101. $version_status = __('not active');
  102. }
  103. $tmp_link = 'tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']);
  104. $delete_link = 'db_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($version_data['table_name']) . '&amp;delete_tracking=true&amp';
  105. ?>
  106. <tr class="noclick <?php echo $style;?>">
  107. <td><?php echo htmlspecialchars($version_data['db_name']);?></td>
  108. <td><?php echo htmlspecialchars($version_data['table_name']);?></td>
  109. <td><?php echo $version_data['version'];?></td>
  110. <td><?php echo $version_data['date_created'];?></td>
  111. <td><?php echo $version_data['date_updated'];?></td>
  112. <td><?php echo $version_status;?></td>
  113. <td><a <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'class="drop_tracking_anchor"' : ''); ?> href="<?php echo $delete_link;?>" ><?php echo $drop_image_or_text; ?></a></td>
  114. <td> <a href="<?php echo $tmp_link; ?>"><?php echo __('Versions');?></a>
  115. | <a href="<?php echo $tmp_link; ?>&amp;report=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Tracking report');?></a>
  116. | <a href="<?php echo $tmp_link; ?>&amp;snapshot=true&amp;version=<?php echo $version_data['version'];?>"><?php echo __('Structure snapshot');?></a></td>
  117. </tr>
  118. <?php
  119. if ($style == 'even') {
  120. $style = 'odd';
  121. } else {
  122. $style = 'even';
  123. }
  124. }
  125. unset($tmp_link);
  126. ?>
  127. </tbody>
  128. </table>
  129. </div>
  130. <?php
  131. }
  132. $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
  133. // Get list of tables
  134. $table_list = PMA_getTableList($GLOBALS['db']);
  135. // For each table try to get the tracking version
  136. foreach ($table_list as $key => $value) {
  137. // If $value is a table group.
  138. if (array_key_exists(('is' . $sep . 'group'), $value) && $value['is' . $sep . 'group']) {
  139. foreach ($value as $temp_table) {
  140. // If $temp_table is a table with the value for 'Name' is set,
  141. // rather than a propery of the table group.
  142. if (is_array($temp_table) && array_key_exists('Name', $temp_table)) {
  143. if (PMA_Tracker::getVersion($GLOBALS['db'], $temp_table['Name']) == -1) {
  144. $my_tables[] = $temp_table['Name'];
  145. }
  146. }
  147. }
  148. // If $value is a table.
  149. } else {
  150. if (PMA_Tracker::getVersion($GLOBALS['db'], $value['Name']) == -1) {
  151. $my_tables[] = $value['Name'];
  152. }
  153. }
  154. }
  155. // If untracked tables exist
  156. if (isset($my_tables)) {
  157. ?>
  158. <h3><?php echo __('Untracked tables');?></h3>
  159. <table id="noversions" class="data">
  160. <thead>
  161. <tr>
  162. <th width="300"><?php echo __('Table');?></th>
  163. <th></th>
  164. </tr>
  165. </thead>
  166. <tbody>
  167. <?php
  168. // Print out list of untracked tables
  169. $style = 'odd';
  170. foreach ($my_tables as $key => $tablename) {
  171. if (PMA_Tracker::getVersion($GLOBALS['db'], $tablename) == -1) {
  172. $my_link = '<a href="tbl_tracking.php?' . $url_query . '&amp;table=' . htmlspecialchars($tablename) .'">';
  173. $my_link .= PMA_getIcon('eye.png', __('Track table')) . '</a>';
  174. ?>
  175. <tr class="noclick <?php echo $style;?>">
  176. <td><?php echo htmlspecialchars($tablename);?></td>
  177. <td><?php echo $my_link;?></td>
  178. </tr>
  179. <?php
  180. if ($style == 'even') {
  181. $style = 'odd';
  182. } else {
  183. $style = 'even';
  184. }
  185. }
  186. }
  187. ?>
  188. </tbody>
  189. </table>
  190. <?php
  191. }
  192. // If available print out database log
  193. if (count($data['ddlog']) > 0) {
  194. $log = '';
  195. foreach ($data['ddlog'] as $entry) {
  196. $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n" . $entry['statement'] . "\n";
  197. }
  198. PMA_showMessage(__('Database Log'), $log);
  199. }
  200. /**
  201. * Display the footer
  202. */
  203. require './libraries/footer.inc.php';
  204. ?>