2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tracking configuration for database
8 use PMA\libraries\Tracker
;
13 require_once 'libraries/common.inc.php';
15 require_once './libraries/tracking.lib.php';
16 require_once 'libraries/display_create_table.lib.php';
18 //Get some js files needed for Ajax requests
19 $response = PMA\libraries\Response
::getInstance();
20 $header = $response->getHeader();
21 $scripts = $header->getScripts();
22 $scripts->addFile('jquery/jquery.tablesorter.js');
23 $scripts->addFile('db_tracking.js');
26 * If we are not in an Ajax request, then do the common work and show the links etc.
28 require 'libraries/db_common.inc.php';
29 $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php';
31 // Get the database structure
32 $sub_part = '_structure';
44 ) = PMA\libraries\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
47 // (here, do not use $_REQUEST['db] as it can be crafted)
48 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
50 Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
51 PMA\libraries\Message
::success(
52 __('Tracking data deleted successfully.')
55 } elseif (isset($_REQUEST['submit_create_version'])) {
57 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
58 PMA\libraries\Message
::success(
61 'Version %1$s was created for selected tables,'
62 . ' tracking is active for them.'
64 htmlspecialchars($_REQUEST['version'])
68 } elseif (isset($_REQUEST['submit_mult'])) {
70 if (! empty($_REQUEST['selected_tbl'])) {
71 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
73 foreach ($_REQUEST['selected_tbl'] as $table) {
74 Tracker
::deleteTracking($GLOBALS['db'], $table);
76 PMA\libraries\Message
::success(
77 __('Tracking data deleted successfully.')
80 } elseif ($_REQUEST['submit_mult'] == 'track') {
82 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
83 'db_tracking.php' . $url_query,
86 $_REQUEST['selected_tbl']
91 PMA\libraries\Message
::notice(
92 __('No tables selected.')
97 // Get tracked data about the database
98 $data = Tracker
::getTrackedData($_REQUEST['db'], '', '1');
100 // No tables present and no log exist
101 if ($num_tables == 0 && count($data['ddlog']) == 0) {
102 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
104 if (empty($db_is_system_schema)) {
105 echo PMA_getHtmlForCreateTable($db);
110 // ---------------------------------------------------------------------------
111 $cfgRelation = PMA_getRelationsParam();
113 // Prepare statement to get HEAD version
114 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
115 PMA\libraries\Util
::backquote($cfgRelation['db']) . '.' .
116 PMA\libraries\Util
::backquote($cfgRelation['tracking']) .
117 ' WHERE db_name = \'' . PMA\libraries\Util
::sqlAddSlashes($_REQUEST['db']) . '\' ' .
118 ' GROUP BY table_name' .
119 ' ORDER BY table_name ASC';
121 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
123 // If a HEAD version exists
124 if (is_object($all_tables_result) && $GLOBALS['dbi']->numRows($all_tables_result) > 0) {
125 PMA_displayTrackedTables(
126 $GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
127 $text_dir, $cfgRelation
131 $untracked_tables = PMA_getUntrackedTables($GLOBALS['db']);
133 // If untracked tables exist
134 if (count($untracked_tables) > 0) {
135 PMA_displayUntrackedTables(
136 $GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir
139 // If available print out database log
140 if (count($data['ddlog']) > 0) {
142 foreach ($data['ddlog'] as $entry) {
143 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
144 . $entry['statement'] . "\n";
146 echo PMA\libraries\Util
::getMessage(__('Database Log'), $log);