2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tracking configuration for database
12 require_once 'libraries/common.inc.php';
14 require_once './libraries/tracking.lib.php';
15 require_once 'libraries/display_create_table.lib.php';
17 //Get some js files needed for Ajax requests
18 $response = PMA_Response
::getInstance();
19 $header = $response->getHeader();
20 $scripts = $header->getScripts();
21 $scripts->addFile('jquery/jquery.tablesorter.js');
22 $scripts->addFile('db_tracking.js');
25 * If we are not in an Ajax request, then do the common work and show the links etc.
27 require 'libraries/db_common.inc.php';
28 $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php';
30 // Get the database structure
31 $sub_part = '_structure';
43 ) = PMA_Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
46 // (here, do not use $_REQUEST['db] as it can be crafted)
47 if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) {
49 PMA_Tracker
::deleteTracking($GLOBALS['db'], $_REQUEST['table']);
51 __('Tracking data deleted successfully.')
54 } elseif (isset($_REQUEST['submit_create_version'])) {
56 PMA_createTrackingForMultipleTables($_REQUEST['selected']);
60 'Version %1$s was created for selected tables,'
61 . ' tracking is active for them.'
63 htmlspecialchars($_REQUEST['version'])
67 } elseif (isset($_REQUEST['submit_mult'])) {
69 if (! empty($_REQUEST['selected_tbl'])) {
70 if ($_REQUEST['submit_mult'] == 'delete_tracking') {
72 foreach ($_REQUEST['selected_tbl'] as $table) {
73 PMA_Tracker
::deleteTracking($GLOBALS['db'], $table);
76 __('Tracking data deleted successfully.')
79 } elseif ($_REQUEST['submit_mult'] == 'track') {
81 echo PMA_getHtmlForDataDefinitionAndManipulationStatements(
82 'db_tracking.php' . $url_query,
85 $_REQUEST['selected_tbl']
91 __('No tables selected.')
96 // Get tracked data about the database
97 $data = PMA_Tracker
::getTrackedData($_REQUEST['db'], '', '1');
99 // No tables present and no log exist
100 if ($num_tables == 0 && count($data['ddlog']) == 0) {
101 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
103 if (empty($db_is_system_schema)) {
104 echo PMA_getHtmlForCreateTable($db);
109 // ---------------------------------------------------------------------------
110 $cfgRelation = PMA_getRelationsParam();
112 // Prepare statement to get HEAD version
113 $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
114 PMA_Util
::backquote($cfgRelation['db']) . '.' .
115 PMA_Util
::backquote($cfgRelation['tracking']) .
116 ' WHERE db_name = \'' . PMA_Util
::sqlAddSlashes($_REQUEST['db']) . '\' ' .
117 ' GROUP BY table_name' .
118 ' ORDER BY table_name ASC';
120 $all_tables_result = PMA_queryAsControlUser($all_tables_query);
122 // If a HEAD version exists
123 if (is_object($all_tables_result) && $GLOBALS['dbi']->numRows($all_tables_result) > 0) {
124 PMA_displayTrackedTables(
125 $GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
126 $text_dir, $cfgRelation
130 $untracked_tables = PMA_getUntrackedTables($GLOBALS['db']);
132 // If untracked tables exist
133 if (count($untracked_tables) > 0) {
134 PMA_displayUntrackedTables(
135 $GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir
138 // If available print out database log
139 if (count($data['ddlog']) > 0) {
141 foreach ($data['ddlog'] as $entry) {
142 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
143 . $entry['statement'] . "\n";
145 echo PMA_Util
::getMessage(__('Database Log'), $log);