tbl_tracking.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Table tracking page
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Message;
  9. use PhpMyAdmin\Tracker;
  10. use PhpMyAdmin\Tracking;
  11. use PhpMyAdmin\Response;
  12. require_once './libraries/common.inc.php';
  13. //Get some js files needed for Ajax requests
  14. $response = Response::getInstance();
  15. $header = $response->getHeader();
  16. $scripts = $header->getScripts();
  17. $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
  18. $scripts->addFile('tbl_tracking.js');
  19. define('TABLE_MAY_BE_ABSENT', true);
  20. require './libraries/tbl_common.inc.php';
  21. if (Tracker::isActive()
  22. && Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"])
  23. && ! (isset($_POST['toggle_activation'])
  24. && $_POST['toggle_activation'] == 'deactivate_now')
  25. && ! (isset($_POST['report_export'])
  26. && $_POST['export_type'] == 'sqldumpfile')
  27. ) {
  28. $msg = Message::notice(
  29. sprintf(
  30. __('Tracking of %s is activated.'),
  31. htmlspecialchars($GLOBALS["db"] . '.' . $GLOBALS["table"])
  32. )
  33. );
  34. $response->addHTML($msg->getDisplay());
  35. }
  36. $url_query .= '&amp;goto=tbl_tracking.php&amp;back=tbl_tracking.php';
  37. $url_params['goto'] = 'tbl_tracking.php';
  38. $url_params['back'] = 'tbl_tracking.php';
  39. // Init vars for tracking report
  40. if (isset($_POST['report']) || isset($_POST['report_export'])) {
  41. $data = Tracker::getTrackedData(
  42. $GLOBALS['db'], $GLOBALS['table'], $_POST['version']
  43. );
  44. $selection_schema = false;
  45. $selection_data = false;
  46. $selection_both = false;
  47. if (! isset($_POST['logtype'])) {
  48. $_POST['logtype'] = 'schema_and_data';
  49. }
  50. if ($_POST['logtype'] == 'schema') {
  51. $selection_schema = true;
  52. } elseif ($_POST['logtype'] == 'data') {
  53. $selection_data = true;
  54. } else {
  55. $selection_both = true;
  56. }
  57. if (! isset($_POST['date_from'])) {
  58. $_POST['date_from'] = $data['date_from'];
  59. }
  60. if (! isset($_POST['date_to'])) {
  61. $_POST['date_to'] = $data['date_to'];
  62. }
  63. if (! isset($_POST['users'])) {
  64. $_POST['users'] = '*';
  65. }
  66. $filter_ts_from = strtotime($_POST['date_from']);
  67. $filter_ts_to = strtotime($_POST['date_to']);
  68. $filter_users = array_map('trim', explode(',', $_POST['users']));
  69. }
  70. // Prepare export
  71. if (isset($_POST['report_export'])) {
  72. $entries = Tracking::getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users);
  73. }
  74. // Export as file download
  75. if (isset($_POST['report_export'])
  76. && $_POST['export_type'] == 'sqldumpfile'
  77. ) {
  78. Tracking::exportAsFileDownload($entries);
  79. }
  80. $html = '<br />';
  81. /**
  82. * Actions
  83. */
  84. if (isset($_POST['submit_mult'])) {
  85. if (! empty($_POST['selected_versions'])) {
  86. if ($_POST['submit_mult'] == 'delete_version') {
  87. foreach ($_POST['selected_versions'] as $version) {
  88. Tracking::deleteTrackingVersion($version);
  89. }
  90. $html .= Message::success(
  91. __('Tracking versions deleted successfully.')
  92. )->getDisplay();
  93. }
  94. } else {
  95. $html .= Message::notice(
  96. __('No versions selected.')
  97. )->getDisplay();
  98. }
  99. }
  100. if (isset($_POST['submit_delete_version'])) {
  101. $html .= Tracking::deleteTrackingVersion($_POST['version']);
  102. }
  103. // Create tracking version
  104. if (isset($_POST['submit_create_version'])) {
  105. $html .= Tracking::createTrackingVersion();
  106. }
  107. // Deactivate tracking
  108. if (isset($_POST['toggle_activation'])
  109. && $_POST['toggle_activation'] == 'deactivate_now'
  110. ) {
  111. $html .= Tracking::changeTracking('deactivate');
  112. }
  113. // Activate tracking
  114. if (isset($_POST['toggle_activation'])
  115. && $_POST['toggle_activation'] == 'activate_now'
  116. ) {
  117. $html .= Tracking::changeTracking('activate');
  118. }
  119. // Export as SQL execution
  120. if (isset($_POST['report_export']) && $_POST['export_type'] == 'execution') {
  121. $sql_result = Tracking::exportAsSqlExecution($entries);
  122. $msg = Message::success(__('SQL statements executed.'));
  123. $html .= $msg->getDisplay();
  124. }
  125. // Export as SQL dump
  126. if (isset($_POST['report_export']) && $_POST['export_type'] == 'sqldump') {
  127. $html .= Tracking::exportAsSqlDump($entries);
  128. }
  129. /*
  130. * Schema snapshot
  131. */
  132. if (isset($_POST['snapshot'])) {
  133. $html .= Tracking::getHtmlForSchemaSnapshot($url_query);
  134. }
  135. // end of snapshot report
  136. /*
  137. * Tracking report
  138. */
  139. if (isset($_POST['report'])
  140. && (isset($_POST['delete_ddlog']) || isset($_POST['delete_dmlog']))
  141. ) {
  142. $html .= Tracking::deleteTrackingReportRows($data);
  143. }
  144. if (isset($_POST['report']) || isset($_POST['report_export'])) {
  145. $html .= Tracking::getHtmlForTrackingReport(
  146. $url_query, $data, $url_params, $selection_schema, $selection_data,
  147. $selection_both, $filter_ts_to, $filter_ts_from, $filter_users
  148. );
  149. } // end of report
  150. /*
  151. * List selectable tables
  152. */
  153. $selectable_tables_sql_result = Tracking::getSqlResultForSelectableTables();
  154. if ($GLOBALS['dbi']->numRows($selectable_tables_sql_result) > 0) {
  155. $html .= Tracking::getHtmlForSelectableTables(
  156. $selectable_tables_sql_result, $url_query
  157. );
  158. }
  159. $html .= '<br />';
  160. /*
  161. * List versions of current table
  162. */
  163. $sql_result = Tracking::getListOfVersionsOfTable();
  164. $last_version = Tracking::getTableLastVersionNumber($sql_result);
  165. if ($last_version > 0) {
  166. $html .= Tracking::getHtmlForTableVersionDetails(
  167. $sql_result, $last_version, $url_params,
  168. $url_query, $pmaThemeImage, $text_dir
  169. );
  170. }
  171. $type = $GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])
  172. ->isView() ? 'view' : 'table';
  173. $html .= Tracking::getHtmlForDataDefinitionAndManipulationStatements(
  174. 'tbl_tracking.php' . $url_query,
  175. $last_version,
  176. $GLOBALS['db'],
  177. array($GLOBALS['table']),
  178. $type
  179. );
  180. $html .= '<br class="clearfloat"/>';
  181. $response->addHTML($html);