diff --git a/tbl_tracking.php b/tbl_tracking.php index deff7f813..28752151e 100644 --- a/tbl_tracking.php +++ b/tbl_tracking.php @@ -20,83 +20,77 @@ $url_params['back'] = 'tbl_tracking.php'; require_once './libraries/relation.lib.php'; // Init vars for tracking report -if(isset($_REQUEST['report']) or isset($_REQUEST['report_export'])) -{ +if (isset($_REQUEST['report']) || isset($_REQUEST['report_export'])) { $data = PMA_Tracker::getTrackedData($_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']); $selection_schema = ''; $selection_data = ''; $selection_both = ''; - if(!isset($_REQUEST['logtype'])) + if (!isset($_REQUEST['logtype'])) { $_REQUEST['logtype'] = 'schema_and_data'; - - if($_REQUEST['logtype'] == 'schema') + } + if ($_REQUEST['logtype'] == 'schema') { $selection_schema = 'selected'; - else if($_REQUEST['logtype'] == 'data') + } elseif($_REQUEST['logtype'] == 'data') { $selection_data = 'selected'; - else + } else { $selection_both = 'selected'; - - if(!isset($_REQUEST['date_from'])) + } + if (! isset($_REQUEST['date_from'])) { $_REQUEST['date_from'] = $data['date_from']; - if(!isset($_REQUEST['date_to'])) + } + if (! isset($_REQUEST['date_to'])) { $_REQUEST['date_to'] = $data['date_to']; - - if(!isset($_REQUEST['users'])) + } + if (! isset($_REQUEST['users'])) { $_REQUEST['users'] = '*'; - + } $filter_ts_from = strtotime($_REQUEST['date_from']); $filter_ts_to = strtotime($_REQUEST['date_to']); $filter_users = array_map('trim', explode(',', $_REQUEST['users'])); } // Prepare export -if(isset($_REQUEST['report_export'])) -{ +if (isset($_REQUEST['report_export'])) { // Filtering data definition statements - if($_REQUEST['logtype'] == 'schema' or $_REQUEST['logtype'] == 'schema_and_data') - { + if ($_REQUEST['logtype'] == 'schema' || $_REQUEST['logtype'] == 'schema_and_data') { $id = 0; - foreach( $data['ddlog'] as $entry ) - { + foreach( $data['ddlog'] as $entry ) { $timestamp = strtotime($entry['date']); - if( $timestamp >= $filter_ts_from and $timestamp <= $filter_ts_to and - ( in_array('*', $filter_users) or in_array($entry['username'], $filter_users) ) ) + if ($timestamp >= $filter_ts_from && $timestamp <= $filter_ts_to && + ( in_array('*', $filter_users) || in_array($entry['username'], $filter_users) ) ) { $entries[] = array( 'id' => $id, 'timestamp' => $timestamp, 'username' => $entry['username'], 'statement' => $entry['statement'] ); - + } $id++; } } // Filtering data manipulation statments - if($_REQUEST['logtype'] == 'data' or $_REQUEST['logtype'] == 'schema_and_data') - { + if ($_REQUEST['logtype'] == 'data' || $_REQUEST['logtype'] == 'schema_and_data') { $id = 0; - foreach( $data['dmlog'] as $entry ) - { + foreach( $data['dmlog'] as $entry ) { $timestamp = strtotime($entry['date']); - if( $timestamp >= $filter_ts_from and $timestamp <= $filter_ts_to and - ( in_array('*', $filter_users) or in_array($entry['username'], $filter_users) ) ) + if( $timestamp >= $filter_ts_from && $timestamp <= $filter_ts_to && + ( in_array('*', $filter_users) or in_array($entry['username'], $filter_users) ) ) { $entries[] = array( 'id' => $id, 'timestamp' => $timestamp, 'username' => $entry['username'], 'statement' => $entry['statement'] ); - + } $id++; } } // Sort it - foreach ($entries as $key => $row) - { + foreach ($entries as $key => $row) { $ids[$key] = $row['id']; $timestamps[$key] = $row['timestamp']; $usernames[$key] = $row['username']; @@ -105,31 +99,25 @@ if(isset($_REQUEST['report_export'])) array_multisort($timestamps, SORT_ASC, $ids, SORT_ASC, $usernames, SORT_ASC, $statements, SORT_ASC, $entries); - } // Export as file download -if(isset($_REQUEST['report_export']) and $_REQUEST['export_type'] == 'sqldumpfile') -{ - +if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldumpfile') { @ini_set('url_rewriter.tags',''); - $dump = "# Tracking report for table `" . $_REQUEST['table'] . "`\n" . + $dump = "# Tracking report for table `" . htmlspecialchars($_REQUEST['table']) . "`\n" . "# " . date('Y-m-d H:i:s') . "\n"; - foreach($entries as $entry) + foreach($entries as $entry) { $dump .= $entry['statement']; - - $filename = 'log_' . $_REQUEST['table'] . '.sql'; + } + $filename = 'log_' . htmlspecialchars($_REQUEST['table']) . '.sql'; header('Content-Type: text/x-sql'); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: attachment; filename="' . $filename . '"'); - if (PMA_USR_BROWSER_AGENT == 'IE') - { + if (PMA_USR_BROWSER_AGENT == 'IE') { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); - } - else - { + } else { header('Pragma: no-cache'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); } @@ -143,88 +131,85 @@ if(isset($_REQUEST['report_export']) and $_REQUEST['export_type'] == 'sqldumpfil * Gets tables informations */ -//require './libraries/tbl_info.inc.php'; - /** * Displays top menu links */ require_once './libraries/tbl_links.inc.php'; - -?> -
-'; /** * Actions */ // Create tracking version -if(isset($_REQUEST['submit_create_version'])) -{ +if (isset($_REQUEST['submit_create_version'])) { $tracking_set = ''; - if($_REQUEST['alter_table'] == true) + if ($_REQUEST['alter_table'] == true) { $tracking_set .= 'ALTER TABLE,'; - if($_REQUEST['rename_table'] == true) + } + if ($_REQUEST['rename_table'] == true) { $tracking_set .= 'RENAME TABLE,'; - if($_REQUEST['create_table'] == true) + } + if ($_REQUEST['create_table'] == true) { $tracking_set .= 'CREATE TABLE,'; - if($_REQUEST['drop_table'] == true) + } + if ($_REQUEST['drop_table'] == true) { $tracking_set .= 'DROP TABLE,'; - if($_REQUEST['create_index'] == true) + } + if ($_REQUEST['create_index'] == true) { $tracking_set .= 'CREATE INDEX,'; - if($_REQUEST['drop_index'] == true) + } + if ($_REQUEST['drop_index'] == true) { $tracking_set .= 'DROP INDEX,'; - if($_REQUEST['insert'] == true) + } + if ($_REQUEST['insert'] == true) { $tracking_set .= 'INSERT,'; - if($_REQUEST['update'] == true) + } + if ($_REQUEST['update'] == true) { $tracking_set .= 'UPDATE,'; - if($_REQUEST['delete'] == true) + } + if ($_REQUEST['delete'] == true) { $tracking_set .= 'DELETE,'; - if($_REQUEST['truncate'] == true) + } + if ($_REQUEST['truncate'] == true) { $tracking_set .= 'TRUNCATE,'; - + } $tracking_set = rtrim($tracking_set, ','); - if(PMA_Tracker::createVersion($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'], $tracking_set )) - { + if (PMA_Tracker::createVersion($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'], $tracking_set )) { $msg = PMA_Message::success(sprintf($strTrackingVersionCreated, $_REQUEST['version'], $GLOBALS['db'], $GLOBALS['table'])); $msg->display(); } } // Deactivate tracking -if(isset($_REQUEST['submit_deactivate_now'])) -{ - if(PMA_Tracker::deactivateTracking($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])) - { +if (isset($_REQUEST['submit_deactivate_now'])) { + if (PMA_Tracker::deactivateTracking($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])) { $msg = PMA_Message::success(sprintf($strTrackingVersionDeactivated, $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])); $msg->display(); } } // Activate tracking -if(isset($_REQUEST['submit_activate_now'])) -{ - if(PMA_Tracker::activateTracking($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])) - { +if (isset($_REQUEST['submit_activate_now'])) { + if (PMA_Tracker::activateTracking($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])) { $msg = PMA_Message::success(sprintf($strTrackingVersionActivated, $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])); $msg->display(); } } // Export as SQL execution -if(isset($_REQUEST['report_export']) and $_REQUEST['export_type'] == 'execution') -{ - foreach($entries as $entry) - $sql_result = PMA_DBI_query( "/*NOTRACK*/\n" . $entry['statement'] ); - +if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'execution') { + foreach($entries as $entry) { + $sql_result = PMA_DBI_query( "/*NOTRACK*/\n" . $entry['statement'] ); + } $msg = PMA_Message::success($strTrackingSQLExecuted); $msg->display(); } // Export as SQL dump -if(isset($_REQUEST['report_export']) and $_REQUEST['export_type'] == 'sqldump') +if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldump') { $new_query = "# You can execute the dump by creating and using a temporary table. Please ensure that you have the privileges to do that. \n" . "# Comment out or remove these two lines if you don't need them. \n" . @@ -234,9 +219,9 @@ if(isset($_REQUEST['report_export']) and $_REQUEST['export_type'] == 'sqldump') "\n" . "/* BEGIN OF SQL DUMP */ \n"; - foreach($entries as $entry) - $new_query .= $entry['statement']; - + foreach($entries as $entry) { + $new_query .= $entry['statement']; + } $msg = PMA_Message::success($strTrackingSQLExported); $msg->display(); @@ -253,25 +238,21 @@ if(isset($_REQUEST['report_export']) and $_REQUEST['export_type'] == 'sqldump') $table = $table_temp; } - - /* * Schema snapshot */ -if(isset($_REQUEST['snapshot'])) -{ +if (isset($_REQUEST['snapshot'])) { ?>