2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tracking configuration for database
8 use PhpMyAdmin\Message
;
9 use PhpMyAdmin\Relation
;
10 use PhpMyAdmin\Response
;
11 use PhpMyAdmin\Tracker
;
12 use PhpMyAdmin\Tracking
;
18 require_once 'libraries/common.inc.php';
19 require_once 'libraries/display_create_table.lib.php';
21 //Get some js files needed for Ajax requests
22 $response = Response
::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
26 $scripts->addFile('db_tracking.js');
29 * If we are not in an Ajax request, then do the common work and show the links etc.
31 require 'libraries/db_common.inc.php';
32 $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php';
34 // Get the database structure
35 $sub_part = '_structure';
47 ) = Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
50 // (here, do not use $_REQUEST['db] as it can be crafted)
51 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
53 Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
55 __('Tracking data deleted successfully.')
58 } elseif (isset($_REQUEST['submit_create_version'])) {
60 Tracking
::createTrackingForMultipleTables($_REQUEST['selected']);
64 'Version %1$s was created for selected tables,'
65 . ' tracking is active for them.'
67 htmlspecialchars($_REQUEST['version'])
71 } elseif (isset($_REQUEST['submit_mult'])) {
73 if (! empty($_REQUEST['selected_tbl'])) {
74 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
76 foreach ($_REQUEST['selected_tbl'] as $table) {
77 Tracker
::deleteTracking($GLOBALS['db'], $table);
80 __('Tracking data deleted successfully.')
83 } elseif ($_REQUEST['submit_mult'] == 'track') {
85 echo Tracking
::getHtmlForDataDefinitionAndManipulationStatements(
86 'db_tracking.php' . $url_query,
89 $_REQUEST['selected_tbl']
95 __('No tables selected.')
100 // Get tracked data about the database
101 $data = Tracker
::getTrackedData($_REQUEST['db'], '', '1');
103 // No tables present and no log exist
104 if ($num_tables == 0 && count($data['ddlog']) == 0) {
105 echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
107 if (empty($db_is_system_schema)) {
108 echo PMA_getHtmlForCreateTable($db);
113 // ---------------------------------------------------------------------------
114 $cfgRelation = Relation
::getRelationsParam();
116 // Prepare statement to get HEAD version
117 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
118 Util
::backquote($cfgRelation['db']) . '.' .
119 Util
::backquote($cfgRelation['tracking']) .
120 ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($_REQUEST['db']) .
122 ' GROUP BY table_name' .
123 ' ORDER BY table_name ASC';
125 $all_tables_result = Relation
::queryAsControlUser($all_tables_query);
127 // If a HEAD version exists
128 if (is_object($all_tables_result)
129 && $GLOBALS['dbi']->numRows($all_tables_result) > 0
131 Tracking
::displayTrackedTables(
132 $GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
133 $text_dir, $cfgRelation
137 $untracked_tables = Tracking
::getUntrackedTables($GLOBALS['db']);
139 // If untracked tables exist
140 if (count($untracked_tables) > 0) {
141 Tracking
::displayUntrackedTables(
142 $GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir
145 // If available print out database log
146 if (count($data['ddlog']) > 0) {
148 foreach ($data['ddlog'] as $entry) {
149 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
150 . $entry['statement'] . "\n";
152 echo Util
::getMessage(__('Database Log'), $log);