Refactor duplicate code

Signed-off-by: Marc Delisle <marc@infomarc.info>
This commit is contained in:
Marc Delisle 2014-09-27 12:42:55 -04:00
parent 74709bb48e
commit 4314444675
3 changed files with 22 additions and 14 deletions

View File

@ -11,6 +11,8 @@
*/
require_once 'libraries/common.inc.php';
require_once './libraries/tracking.lib.php';
//Get some js files needed for Ajax requests
$response = PMA_Response::getInstance();
$header = $response->getHeader();
@ -116,11 +118,6 @@ if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
$table_result = PMA_queryAsControlUser($table_query);
$version_data = $GLOBALS['dbi']->fetchArray($table_result);
if ($version_data['tracking_active'] == 1) {
$version_status = __('active');
} else {
$version_status = __('not active');
}
$tmp_link = 'tbl_tracking.php?' . $url_query . '&amp;table='
. htmlspecialchars($version_data['table_name']);
$delete_link = 'db_tracking.php?' . $url_query . '&amp;table='
@ -133,7 +130,7 @@ if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
<td><?php echo $version_data['version'];?></td>
<td><?php echo $version_data['date_created'];?></td>
<td><?php echo $version_data['date_updated'];?></td>
<td><?php echo $version_status;?></td>
<td><?php echo PMA_getVersionStatus($version_data);?></td>
<td>
<a class="drop_tracking_anchor ajax" href="<?php echo $delete_link;?>" >
<?php echo $drop_image_or_text; ?></a>

View File

@ -1,7 +1,7 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functions used to generate table tracking
* Functions used for database and table tracking
*
* @package PhpMyAdmin
*/
@ -251,11 +251,6 @@ function PMA_getHtmlForTableVersionDetails($sql_result, $last_version, $url_para
$style = 'odd';
$GLOBALS['dbi']->dataSeek($sql_result, 0);
while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) {
if ($version['tracking_active'] == 1) {
$version_status = __('active');
} else {
$version_status = __('not active');
}
if ($version['version'] == $last_version) {
if ($version['tracking_active'] == 1) {
$tracking_active = true;
@ -269,7 +264,7 @@ function PMA_getHtmlForTableVersionDetails($sql_result, $last_version, $url_para
$html .= '<td>' . htmlspecialchars($version['version']) . '</td>';
$html .= '<td>' . htmlspecialchars($version['date_created']) . '</td>';
$html .= '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
$html .= '<td>' . $version_status . '</td>';
$html .= '<td>' . PMA_getVersionStatus($version) . '</td>';
$html .= '<td><a href="tbl_tracking.php';
$html .= PMA_URL_getCommon(
$url_params + array(
@ -1343,4 +1338,20 @@ function PMA_getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users)
return $entries;
}
/**
* Function to get version status
*
* @param array $version version info
*
* @return string $version_status The status message
*/
function PMA_getVersionStatus($version)
{
if ($version['tracking_active'] == 1) {
return __('active');
} else {
return __('not active');
}
}
?>

View File

@ -9,7 +9,7 @@
// Run common work
require_once './libraries/common.inc.php';
require_once './libraries/tbl_tracking.lib.php';
require_once './libraries/tracking.lib.php';
define('TABLE_MAY_BE_ABSENT', true);
require './libraries/tbl_common.inc.php';