Skip to content

Commit

Permalink
refactor PMA_getHtmlForSqlQueryForm and fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
xmujay committed Aug 20, 2013
1 parent a820f0d commit ea1f6f3
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 52 deletions.
10 changes: 7 additions & 3 deletions db_sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
/**
* Query box, bookmark, insert data from textfile
*/
PMA_sqlQueryForm(
true, false,
isset($_REQUEST['delimiter']) ? htmlspecialchars($_REQUEST['delimiter']) : ';'
$response->addHTML(
PMA_getHtmlForSqlQueryForm(
true, false,
isset($_REQUEST['delimiter'])
? htmlspecialchars($_REQUEST['delimiter'])
: ';'
)
);

?>
36 changes: 18 additions & 18 deletions libraries/sql_query_form.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
require_once './libraries/bookmark.lib.php'; // used for bookmarks

/**
* Prints the sql query boxes
* return HTML for the sql query boxes
*
* @param boolean|string $query query to display in the textarea
* or true to display last executed
Expand All @@ -31,7 +31,7 @@
* false if not inside querywindow
* @param string $delimiter delimeter
*
* @return void
* @return string
*
* @usedby server_sql.php
* @usedby db_sql.php
Expand All @@ -40,8 +40,9 @@
* @usedby tbl_tracking.php
* @usedby querywindow.php
*/
function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
{
function PMA_getHtmlForSqlQueryForm(
$query = true, $display_tab = false, $delimiter = ';'
) {
$html = '';
// check tab to display if inside querywindow
if (! $display_tab) {
Expand Down Expand Up @@ -81,18 +82,16 @@ function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
'tbl_sql.php' : $GLOBALS['goto'];
}


// start output
if ($is_querywindow) {
?>
<form method="post" id="sqlqueryform" target="frame_content"
action="import.php"<?php echo $enctype; ?> name="sqlform"
onsubmit="var save_name = window.opener.parent.frame_content.name;
window.opener.parent.frame_content.name
= save_name + '<?php echo time(); ?>';
this.target = window.opener.parent.frame_content.name;
return checkSqlQuery(this)">
<?php
$html .= '<form method="post" id="sqlqueryform" target="frame_content"';
$html .= ' action="import.php" ' . $enctype . ' name="sqlform"';
$html .= ' onsubmit="var save_name ';
$html .= ' = window.opener.parent.frame_content.name;';
$html .= ' window.opener.parent.frame_content.name ';
$html .= ' = save_name + \'' . time() . '\';';
$html .= ' this.target = window.opener.parent.frame_content.name;';
$html .= ' return checkSqlQuery(this)">';
} else {
$html .= '<form method="post" action="import.php" ' . $enctype;
$html .= ' class="ajax"';
Expand Down Expand Up @@ -147,7 +146,8 @@ function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
// print an empty div, which will be later filled with
// the sql query results by ajax
$html .= '<div id="sqlqueryresults"></div>';
echo $html;

return $html;
}

/**
Expand All @@ -159,7 +159,7 @@ function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
*
* @return string
*
* @usedby PMA_sqlQueryForm()
* @usedby PMA_getHtmlForSqlQueryForm()
*/
function PMA_getHtmlForSqlQueryFormInsert(
$query = '', $is_querywindow = false, $delimiter = ';'
Expand Down Expand Up @@ -388,7 +388,7 @@ function PMA_getHtmlForSqlQueryFormInsert(
*
* @return string
*
* @usedby PMA_sqlQueryForm()
* @usedby PMA_getHtmlForSqlQueryForm()
*/
function PMA_getHtmlForSqlQueryFormBookmark()
{
Expand Down Expand Up @@ -447,7 +447,7 @@ function PMA_getHtmlForSqlQueryFormBookmark()
*
* @return string
*
* @usedby PMA_sqlQueryForm()
* @usedby PMA_getHtmlForSqlQueryForm()
*/
function PMA_getHtmlForSqlQueryFormUpload()
{
Expand Down
2 changes: 1 addition & 1 deletion querywindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
unset($tabs);
}

PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
echo PMA_getHtmlForSqlQueryForm($query_to_display, $querydisplay_tab);

// Hidden forms and query frame interaction stuff

Expand Down
2 changes: 1 addition & 1 deletion server_sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
/**
* Query box, bookmark, insert data from textfile
*/
PMA_sqlQueryForm();
$response->addHTML(PMA_getHtmlForSqlQueryForm());

?>
10 changes: 7 additions & 3 deletions tbl_sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@
/**
* Query box, bookmark, insert data from textfile
*/
PMA_sqlQueryForm(
true, false,
isset($_REQUEST['delimiter']) ? htmlspecialchars($_REQUEST['delimiter']) : ';'
$response->addHTML(
PMA_getHtmlForSqlQueryForm(
true, false,
isset($_REQUEST['delimiter'])
? htmlspecialchars($_REQUEST['delimiter'])
: ';'
)
);

?>
90 changes: 64 additions & 26 deletions tbl_tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function PMA_filterTracking(

if ($timestamp >= $filter_ts_from
&& $timestamp <= $filter_ts_to
&& (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
&& (in_array('*', $filter_users)
|| in_array($entry['username'], $filter_users))
) {
$tmp_entries[] = array(
'id' => $id,
Expand Down Expand Up @@ -258,7 +259,10 @@ function PMA_filterTracking(
// Export as SQL dump
if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldump') {
$new_query = "# "
. __('You can execute the dump by creating and using a temporary database. Please ensure that you have the privileges to do so.')
. __(
'You can execute the dump by creating and using a temporary database. '
. 'Please ensure that you have the privileges to do so.'
)
. "\n"
. "# " . __('Comment out these two lines if you do not need them.') . "\n"
. "\n"
Expand All @@ -280,7 +284,7 @@ function PMA_filterTracking(
$db = $table = '';
include_once './libraries/sql_query_form.lib.php';

PMA_sqlQueryForm($new_query, 'sql');
echo PMA_getHtmlForSqlQueryForm($new_query, 'sql');

$db = $db_temp;
$table = $table_temp;
Expand Down Expand Up @@ -497,7 +501,10 @@ function PMA_filterTracking(

echo '<form method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
$url_params + array(
'report' => 'true',
'version' => $_REQUEST['version']
)
)
. '">';

Expand Down Expand Up @@ -566,12 +573,15 @@ function PMA_filterTracking(

if ($timestamp >= $filter_ts_from
&& $timestamp <= $filter_ts_to
&& (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
&& (in_array('*', $filter_users)
|| in_array($entry['username'], $filter_users))
) {
echo '<tr class="noclick ' . $style . '">';
echo '<td><small>' . $i . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['date'])
. '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['username'])
. '</small></td>';
echo '<td>' . $statement . '</td>';
echo '<td class="nowrap"><a href="tbl_tracking.php?'
. PMA_URL_getCommon(
Expand Down Expand Up @@ -625,12 +635,15 @@ function PMA_filterTracking(

if ($timestamp >= $filter_ts_from
&& $timestamp <= $filter_ts_to
&& (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
&& (in_array('*', $filter_users)
|| in_array($entry['username'], $filter_users))
) {
echo '<tr class="noclick ' . $style . '">';
echo '<td><small>' . $i . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['date'])
. '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['username'])
. '</small></td>';
echo '<td>' . $statement . '</td>';
echo '<td class="nowrap"><a href="tbl_tracking.php?'
. PMA_URL_getCommon(
Expand Down Expand Up @@ -659,7 +672,10 @@ function PMA_filterTracking(
echo '</form>';
echo '<form method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
$url_params + array(
'report' => 'true',
'version' => $_REQUEST['version']
)
)
. '">';
printf(
Expand All @@ -668,18 +684,24 @@ function PMA_filterTracking(
);

$str_export1 = '<select name="export_type">'
. '<option value="sqldumpfile">' . __('SQL dump (file download)') . '</option>'
. '<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.'))
. 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') .'" />';
echo '</form>';
echo '<form class="disableAjax" method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array('report' => 'true', 'version' => $_REQUEST['version'])
$url_params + array(
'report' => 'true',
'version' => $_REQUEST['version']
)
)
. '">';
echo '<input type="hidden" name="logtype" value="'
Expand Down Expand Up @@ -723,7 +745,10 @@ function PMA_filterTracking(
} else {
$s = '';
}
echo '<option value="' . htmlspecialchars($entries['table_name']) . '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . ' . htmlspecialchars($entries['table_name']) . $status . '</option>' . "\n";
echo '<option value="' . htmlspecialchars($entries['table_name'])
. '"' . $s . '>' . htmlspecialchars($entries['db_name'])
. ' . ' . htmlspecialchars($entries['table_name'])
. $status . '</option>' . "\n";
}
echo '</select>';
echo '<input type="hidden" name="show_versions_submit" value="1" />';
Expand Down Expand Up @@ -793,7 +818,10 @@ function PMA_filterTracking(
echo '">' . __('Tracking report') . '</a>';
echo '| <a href="tbl_tracking.php';
echo PMA_URL_getCommon(
$url_params + array('snapshot' => 'true', 'version' => $version['version'])
$url_params + array(
'snapshot' => 'true',
'version' => $version['version']
)
);
echo '">' . __('Structure snapshot') . '</a>';
echo '</td>';
Expand Down Expand Up @@ -859,18 +887,28 @@ function PMA_filterTracking(
echo '<input type="hidden" name="version" value="' . ($last_version + 1) . '" />';

echo '<p>' . __('Track these data definition statements:') . '</p>';
echo '<input type="checkbox" name="alter_table" value="true" checked="checked" /> ALTER TABLE<br/>';
echo '<input type="checkbox" name="rename_table" value="true" checked="checked" /> RENAME TABLE<br/>';
echo '<input type="checkbox" name="create_table" value="true" checked="checked" /> CREATE TABLE<br/>';
echo '<input type="checkbox" name="drop_table" value="true" checked="checked" /> DROP TABLE<br/>';
echo '<input type="checkbox" name="alter_table" value="true" checked="checked" />'
. ' ALTER TABLE<br/>';
echo '<input type="checkbox" name="rename_table" value="true" checked="checked" />'
. ' RENAME TABLE<br/>';
echo '<input type="checkbox" name="create_table" value="true" checked="checked" />'
. ' CREATE TABLE<br/>';
echo '<input type="checkbox" name="drop_table" value="true" checked="checked" />'
. ' DROP TABLE<br/>';
echo '<br/>';
echo '<input type="checkbox" name="create_index" value="true" checked="checked" /> CREATE INDEX<br/>';
echo '<input type="checkbox" name="drop_index" value="true" checked="checked" /> DROP INDEX<br/>';
echo '<input type="checkbox" name="create_index" value="true" checked="checked" />'
. ' CREATE INDEX<br/>';
echo '<input type="checkbox" name="drop_index" value="true" checked="checked" />'
. ' DROP INDEX<br/>';
echo '<p>' . __('Track these data manipulation statements:') . '</p>';
echo '<input type="checkbox" name="insert" value="true" checked="checked" /> INSERT<br/>';
echo '<input type="checkbox" name="update" value="true" checked="checked" /> UPDATE<br/>';
echo '<input type="checkbox" name="delete" value="true" checked="checked" /> DELETE<br/>';
echo '<input type="checkbox" name="truncate" value="true" checked="checked" /> TRUNCATE<br/>';
echo '<input type="checkbox" name="insert" value="true" checked="checked" />'
. ' INSERT<br/>';
echo '<input type="checkbox" name="update" value="true" checked="checked" />'
. ' UPDATE<br/>';
echo '<input type="checkbox" name="delete" value="true" checked="checked" />'
. ' DELETE<br/>';
echo '<input type="checkbox" name="truncate" value="true" checked="checked" />'
. ' TRUNCATE<br/>';

echo '</fieldset>';
echo '<fieldset class="tblFooters">';
Expand Down

0 comments on commit ea1f6f3

Please sign in to comment.