Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Delisle <marc@infomarc.info>
  • Loading branch information
lem9 committed Jun 10, 2015
1 parent 9081189 commit e1c8b94
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions libraries/sql_query_form.lib.php
Expand Up @@ -124,29 +124,17 @@ function PMA_getHtmlForSqlQueryForm(
}

/**
* return HTML for Sql Query Form Insert
* Get initial values for Sql Query Form Insert
*
* @param string $query query to display in the textarea
* @param string $delimiter default delimiter to use
* @param string $query query to display in the textarea
*
* @return string
* @return array ($legend, $query, $columns_list)
*
* @usedby PMA_getHtmlForSqlQueryForm()
* @usedby PMA_getHtmlForSqlQueryFormInsert()
*/
function PMA_getHtmlForSqlQueryFormInsert(
$query = '', $delimiter = ';'
) {
// enable auto select text in textarea
if ($GLOBALS['cfg']['TextareaAutoSelect']) {
$auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"';
} else {
$auto_sel = '';
}

$locking = '';
$height = $GLOBALS['cfg']['TextareaRows'] * 2;

$fields_list = array();
function PMA_initQueryForm($query)
{
$columns_list = array();
if (! /*overload*/mb_strlen($GLOBALS['db'])) {
// prepare for server related
$legend = sprintf(
Expand All @@ -165,8 +153,6 @@ function PMA_getHtmlForSqlQueryFormInsert(
. PMA_URL_getCommon(array('db' => $db)) . '"';
$tmp_db_link .= '>'
. htmlspecialchars($db) . '</a>';
// else use
// $tmp_db_link = htmlspecialchars($db);
$legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
if (empty($query)) {
$query = PMA_Util::expandUserString(
Expand All @@ -178,16 +164,14 @@ function PMA_getHtmlForSqlQueryFormInsert(
// Get the list and number of fields
// we do a try_query here, because we could be in the query window,
// trying to synchronize and the table has not yet been created
$fields_list = $GLOBALS['dbi']->getColumns(
$columns_list = $GLOBALS['dbi']->getColumns(
$db, $GLOBALS['table'], null, true
);

$tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
. PMA_URL_getCommon(array('db' => $db)) . '"';
$tmp_db_link .= '>'
. htmlspecialchars($db) . '</a>';
// else use
// $tmp_db_link = htmlspecialchars($db);
$legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
if (empty($query)) {
$query = PMA_Util::expandUserString(
Expand All @@ -197,7 +181,35 @@ function PMA_getHtmlForSqlQueryFormInsert(
}
$legend .= ': ' . PMA_Util::showMySQLDocu('SELECT');

if (count($fields_list)) {
return array($legend, $query, $columns_list);
}

/**
* return HTML for Sql Query Form Insert
*
* @param string $query query to display in the textarea
* @param string $delimiter default delimiter to use
*
* @return string
*
* @usedby PMA_getHtmlForSqlQueryForm()
*/
function PMA_getHtmlForSqlQueryFormInsert(
$query = '', $delimiter = ';'
) {
// enable auto select text in textarea
if ($GLOBALS['cfg']['TextareaAutoSelect']) {
$auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"';
} else {
$auto_sel = '';
}

$locking = '';
$height = $GLOBALS['cfg']['TextareaRows'] * 2;

list($legend, $query, $columns_list) = PMA_initQueryForm($query);

if (count($columns_list)) {
$sqlquerycontainer_id = 'sqlquerycontainer';
} else {
$sqlquerycontainer_id = 'sqlquerycontainerfull';
Expand All @@ -219,7 +231,7 @@ function PMA_getHtmlForSqlQueryFormInsert(
$html .= '<div id="querymessage"></div>';
// Add buttons to generate query easily for
// select all, single select, insert, update and delete
if (count($fields_list)) {
if (count($columns_list)) {
$html .= '<input type="button" value="SELECT *" id="selectall"'
. ' class="button sqlbutton" />';
$html .= '<input type="button" value="SELECT" id="select"'
Expand Down Expand Up @@ -254,13 +266,13 @@ function PMA_getHtmlForSqlQueryFormInsert(

$html .= '</div>' . "\n";

if (count($fields_list)) {
if (count($columns_list)) {
$html .= '<div id="tablefieldscontainer">'
. '<label>' . __('Columns') . '</label>'
. '<select id="tablefields" name="dummy" '
. 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
. 'multiple="multiple" ondblclick="insertValueQuery()">';
foreach ($fields_list as $field) {
foreach ($columns_list as $field) {
$html .= '<option value="'
. PMA_Util::backquote(htmlspecialchars($field['Field'])) . '"';
if (isset($field['Field'])
Expand Down

0 comments on commit e1c8b94

Please sign in to comment.