From e84dfe5c366830a34e3398c5c3d609626699e6d2 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 29 Nov 2009 13:54:04 +0000 Subject: [PATCH] code cleanup; XHTML compliancy --- tbl_tracking.php | 344 ++++++++++++++++++++++++++----------------------------- 1 file changed, 163 insertions(+), 181 deletions(-) diff --git a/tbl_tracking.php b/tbl_tracking.php index deff7f813d..28752151e4 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'])) { ?>

[]

$field) - { + foreach($columns as $field_index => $field) { ?> ' . $field['Field'] . ''."\n"; - else - echo '' . $field['Field'] . ''."\n"; + if ($field['Key'] == 'PRI') { + echo '' . $field['Field'] . '' . "\n"; + } else { + echo '' . $field['Field'] . '' . "\n"; + } ?> @@ -315,15 +295,18 @@ if(isset($_REQUEST['snapshot'])) 0) - { + if (count($indexes) > 0) { ?>

@@ -342,17 +325,17 @@ if(isset($_REQUEST['snapshot'])) $index) - { - if($index['Non_unique'] == 0) + foreach ($indexes as $indexes_index => $index) { + if ($index['Non_unique'] == 0) { $str_unique = $strYes; - else + } else { $str_unique = $strNo; - - if($index['Packed'] != '') + } + if ($index['Packed'] != '') { $str_packed = $strYes; - else + } else { $str_packed = $strNo; + } ?> @@ -366,7 +349,11 @@ if(isset($_REQUEST['snapshot'])) @@ -374,7 +361,7 @@ if(isset($_REQUEST['snapshot'])) -


+


[]

-
+

@@ -410,8 +396,7 @@ if(isset($_REQUEST['report']) or isset($_REQUEST['report_export'])) * First, list tracked data defintion statements */ $i = 1; - if($selection_schema == 'selected' or $selection_both == 'selected') - { + if ($selection_schema == 'selected' || $selection_both == 'selected') { ?>
@@ -425,15 +410,13 @@ if(isset($_REQUEST['report']) or isset($_REQUEST['report_export'])) = $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) ) ) { ?> @@ -442,7 +425,11 @@ if(isset($_REQUEST['report']) or isset($_REQUEST['report_export'])) 0) - { + if (($selection_data == 'selected' || $selection_both == 'selected') && count($data['dmlog']) > 0) { ?>
@@ -472,15 +458,13 @@ if(isset($_REQUEST['report']) or isset($_REQUEST['report_export'])) = $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) ) ) { ?> @@ -489,7 +473,11 @@ if(isset($_REQUEST['report']) or isset($_REQUEST['report_export'])) ' . '' . '' . - '' . + '' . ''; - $str_export2 = ''; + $str_export2 = ''; ?> - - - - + + + + " . sprintf($strTrackingExportAs, $str_export1) . $str_export2 . "
"; ?> @@ -541,34 +527,32 @@ $sql_query = " SELECT DISTINCT db_name, table_name FROM " . $sql_result = PMA_query_as_controluser($sql_query); -if(PMA_DBI_num_rows($sql_result) > 0) -{ +if (PMA_DBI_num_rows($sql_result) > 0) { ?> - + -

+
0) -{ +if ($last_version > 0) { ?> -

@@ -608,18 +590,18 @@ if($last_version > 0) @@ -628,20 +610,24 @@ if($last_version > 0) - +
| |
- +
- +
@@ -649,21 +635,18 @@ if($last_version > 0) - +
- +
- - @@ -673,25 +656,24 @@ if($last_version > 0)
- +

- ALTER TABLE
- RENAME TABLE
- CREATE TABLE
- DROP TABLE
+ ALTER TABLE
+ RENAME TABLE
+ CREATE TABLE
+ DROP TABLE

- CREATE INDEX
- DROP INDEX
+ CREATE INDEX
+ DROP INDEX

- INSERT
- UPDATE
- DELETE
- TRUNCATE
+ INSERT
+ UPDATE
+ DELETE
+ TRUNCATE
-
-- 2.11.4.GIT