Skip to content

Commit

Permalink
Reduce complexity of PMA_getHtmlForTrackingReport().
Browse files Browse the repository at this point in the history
Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
  • Loading branch information
Tithugues committed Jan 10, 2014
1 parent 22a2176 commit 31e67a3
Showing 1 changed file with 121 additions and 44 deletions.
165 changes: 121 additions & 44 deletions libraries/tbl_tracking.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,56 @@ function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
. htmlspecialchars($data['tracking']) . '</small><br/>';
$html .= '<br/>';

$html .= '<form method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array(
'report' => 'true', 'version' => $_REQUEST['version']
)
)
. '">';
list($str1, $str2, $str3, $str4, $str5) = PMA_getHtmlForElementsOfTrackingReport(
$selection_schema, $selection_data, $selection_both
);

// Prepare delete link content here
$drop_image_or_text = '';
if (PMA_Util::showIcons('ActionsLinksMode')) {
$drop_image_or_text .= PMA_Util::getImage(
'b_drop.png', __('Delete tracking data row from report')
);
}
if (PMA_Util::showText('ActionLinksMode')) {
$drop_image_or_text .= __('Delete');
}

/*
* First, list tracked data definition statements
*/
if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
$msg = PMA_Message::notice(__('No data'));
$msg->display();
}

$html .= PMA_getHtmlForTrackingReportExportForm1(
$data, $url_params, $selection_schema, $selection_data, $selection_both,
$filter_ts_to, $filter_ts_from, $filter_users, $str1, $str2, $str3,
$str4, $str5, $drop_image_or_text
);

$html .= PMA_getHtmlForTrackingReportExportForm2(
$url_params, $str1, $str2, $str3, $str4, $str5
);

$html .= "<br/><br/><hr/><br/>\n";

return $html;
}

/**
* Generate HTML element for report form
*
* @param boolean $selection_schema selection schema
* @param boolean $selection_data selection data
* @param boolean $selection_both selection both
*
* @return array
*/
function PMA_getHtmlForElementsOfTrackingReport(
$selection_schema, $selection_data, $selection_both
) {
$str1 = '<select name="logtype">'
. '<option value="schema"'
. ($selection_schema ? ' selected="selected"' : '') . '>'
Expand All @@ -383,33 +425,49 @@ function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
$str4 = '<input type="text" name="users" value="'
. htmlspecialchars($_REQUEST['users']) . '" />';
$str5 = '<input type="hidden" name="list_report" value="1" />'
. '<input type="submit" value="' . __('Go') . '" />';
. '<input type="submit" value="' . __('Go') . '" />';
return array($str1, $str2, $str3, $str4, $str5);
}

/**
* Generate HTML for export form
*
* @param array $data data
* @param array $url_params url params
* @param boolean $selection_schema selection schema
* @param boolean $selection_data selection data
* @param boolean $selection_both selection both
* @param int $filter_ts_to filter time stamp from
* @param int $filter_ts_from filter time stamp tp
* @param array $filter_users filter users
* @param string $str1 HTML for logtype select
* @param string $str2 HTML for "from date"
* @param string $str3 HTML for "to date"
* @param string $str4 HTML for user
* @param string $str5 HTML for "list report"
* @param string $drop_image_or_text HTML for image or text
*
* @return string HTML for form
*/
function PMA_getHtmlForTrackingReportExportForm1(
$data, $url_params, $selection_schema, $selection_data, $selection_both,
$filter_ts_to, $filter_ts_from, $filter_users, $str1, $str2, $str3,
$str4, $str5, $drop_image_or_text
) {
$html = '<form method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array(
'report' => 'true', 'version' => $_REQUEST['version']
)
)
. '">';

$html .= sprintf(
__('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
$str1, $str2, $str3, $str4, $str5
);

// Prepare delete link content here
$drop_image_or_text = '';
if (PMA_Util::showIcons('ActionsLinksMode')) {
$drop_image_or_text .= PMA_Util::getImage(
'b_drop.png', __('Delete tracking data row from report')
);
}
if (PMA_Util::showText('ActionLinksMode')) {
$drop_image_or_text .= __('Delete');
}

/*
* First, list tracked data definition statements
*/
if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
$msg = PMA_Message::notice(__('No data'));
$msg->display();
}

if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
list($temp, $ddlog_count) = PMA_getHtmlForDataDefinitionStatements(
$data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
$drop_image_or_text
Expand All @@ -428,7 +486,25 @@ function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
);
}
$html .= '</form>';
$html .= '<form method="post" action="tbl_tracking.php'
return $html;
}

/**
* Generate HTML for export form
*
* @param array $url_params Parameters
* @param string $str1 HTML for logtype select
* @param string $str2 HTML for "from date"
* @param string $str3 HTML for "to date"
* @param string $str4 HTML for user
* @param string $str5 HTML for "list report"
*
* @return string HTML for form
*/
function PMA_getHtmlForTrackingReportExportForm2(
$url_params, $str1, $str2, $str3, $str4, $str5
) {
$html = '<form method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array(
'report' => 'true', 'version' => $_REQUEST['version']
Expand All @@ -439,20 +515,8 @@ function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
__('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
$str1, $str2, $str3, $str4, $str5
);

$str_export1 = '<select name="export_type">'
. '<option value="sqldumpfile">' . __('SQL dump (file download)')
. '</option>'
. '<option value="sqldump">' . __('SQL dump') . '</option>'
. '<option value="execution" onclick="alert(\''
. PMA_escapeJsString(
__('This option will replace your table and contained data.')
)
. '\')">' . __('SQL execution') . '</option>' . '</select>';

$str_export2 = '<input type="hidden" name="report_export" value="1" />'
. '<input type="submit" value="' . __('Go') . '" />';
$html .= '</form>';

$html .= '<form class="disableAjax" method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params
Expand All @@ -467,13 +531,26 @@ function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
. htmlspecialchars($_REQUEST['date_to']) . '" />';
$html .= '<input type="hidden" name="users" value="'
. htmlspecialchars($_REQUEST['users']) . '" />';

$str_export1 = '<select name="export_type">'
. '<option value="sqldumpfile">' . __('SQL dump (file download)')
. '</option>'
. '<option value="sqldump">' . __('SQL dump') . '</option>'
. '<option value="execution" onclick="alert(\''
. PMA_escapeJsString(
__('This option will replace your table and contained data.')
)
. '\')">' . __('SQL execution') . '</option>' . '</select>';

$str_export2 = '<input type="hidden" name="report_export" value="1" />'
. '<input type="submit" value="' . __('Go') . '" />';

$html .= "<br/>" . sprintf(__('Export as %s'), $str_export1)
. $str_export2 . "<br/>";
$html .= '</form>';
$html .= "<br/><br/><hr/><br/>\n";

return $html;
}

/**
* Function to get html for data manipulation statements
*
Expand Down

0 comments on commit 31e67a3

Please sign in to comment.