(maybe) execute it
*/
$message_to_display = false;
if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
if (! preg_match('@^SELECT@i', $sql_query)) {
$message_to_display = true;
} else {
$goto = 'db_sql.php';
include 'sql.php';
exit;
}
}
$sub_part = '_qbe';
require 'libraries/db_common.inc.php';
$url_query .= '&goto=db_qbe.php';
$url_params['goto'] = 'db_qbe.php';
require 'libraries/db_info.inc.php';
if ($message_to_display) {
PMA_Message::error(__('You have to choose at least one column to display'))->display();
}
unset($message_to_display);
/**
* Initialize some variables
*/
$col_cnt = PMA_ifSetOr($_REQUEST['col_cnt'], 3, 'numeric');
$add_col = PMA_ifSetOr($_REQUEST['add_col'], 0, 'numeric');
$add_row = PMA_ifSetOr($_REQUEST['add_row'], 0, 'numeric');
$rows = PMA_ifSetOr($_REQUEST['rows'], 0, 'numeric');
$ins_col = PMA_ifSetOr($_REQUEST['ins_col'], null, 'array');
$del_col = PMA_ifSetOr($_REQUEST['del_col'], null, 'array');
$prev_criteria = isset($_REQUEST['prev_criteria'])
? $_REQUEST['prev_criteria']
: array();
$criteria = isset($_REQUEST['criteria'])
? $_REQUEST['criteria']
: array_fill(0, $col_cnt, '');
$ins_row = isset($_REQUEST['ins_row'])
? $_REQUEST['ins_row']
: array_fill(0, $col_cnt, '');
$del_row = isset($_REQUEST['del_row'])
? $_REQUEST['del_row']
: array_fill(0, $col_cnt, '');
$and_or_row = isset($_REQUEST['and_or_row'])
? $_REQUEST['and_or_row']
: array_fill(0, $col_cnt, '');
$and_or_col = isset($_REQUEST['and_or_col'])
? $_REQUEST['and_or_col']
: array_fill(0, $col_cnt, '');
// minimum width
$form_column_width = 12;
$col = max($col_cnt + $add_col, 0);
$row = max($rows + $add_row, 0);
// The tables list sent by a previously submitted form
if (PMA_isValid($_REQUEST['TableList'], 'array')) {
foreach ($_REQUEST['TableList'] as $each_table) {
$tbl_names[$each_table] = ' selected="selected"';
}
} // end if
// this was a work in progress, deactivated for now
//$columns = PMA_DBI_get_columns_full($GLOBALS['db']);
//$tables = PMA_DBI_get_columns_full($GLOBALS['db']);
/**
* Prepares the form
*/
$tbl_result = PMA_DBI_query(
'SHOW TABLES FROM ' . $common_functions->backquote($db) . ';',
null, PMA_DBI_QUERY_STORE
);
$tbl_result_cnt = PMA_DBI_num_rows($tbl_result);
if (0 == $tbl_result_cnt) {
PMA_Message::error(__('No tables found in database.'))->display();
exit;
}
// The tables list gets from MySQL
while (list($tbl) = PMA_DBI_fetch_row($tbl_result)) {
$fld_results = PMA_DBI_get_columns($db, $tbl);
if (empty($tbl_names[$tbl]) && ! empty($_REQUEST['TableList'])) {
$tbl_names[$tbl] = '';
} else {
$tbl_names[$tbl] = ' selected="selected"';
} // end if
// The fields list per selected tables
if ($tbl_names[$tbl] == ' selected="selected"') {
$each_table = $common_functions->backquote($tbl);
$fld[] = $each_table . '.*';
foreach ($fld_results as $each_field) {
$each_field = $each_table . '.' . $common_functions->backquote($each_field['Field']);
$fld[] = $each_field;
// increase the width if necessary
$form_column_width = max(strlen($each_field), $form_column_width);
} // end foreach
} // end if
} // end while
PMA_DBI_free_result($tbl_result);
// largest width found
$realwidth = $form_column_width . 'ex';
/**
* Displays the Query by example form
*/
/**
* Provides select options list containing column names
*
* @param array $columns All Column Names
* @param integer $column_number Column Number (0,1,2) or more
* @param string $selected Selected criteria column name
*
* @return HTML for select options
*/
function showColumnSelectCell($columns, $column_number, $selected = '')
{
$html_output = '';
$html_output .= '
';
$html_output .= '';
$html_output .= ' ';
foreach ($columns as $column) {
$html_output .= ''
. str_replace(' ', ' ', htmlspecialchars($column)) . ' ';
}
$html_output .= ' ';
$html_output .= ' ';
return $html_output;
}
/**
* Provides select options list containing sort options (ASC/DESC)
*
* @param integer $column_number Column Number (0,1,2) or more
* @param string $realwidth Largest column width found
* @param string $asc_selected Selected criteria 'Ascending'
* @param string $desc_selected Selected criteria 'Descending'
*
* @return HTML for select options
*/
function getSortSelectCell($column_number, $realwidth, $asc_selected = '',
$desc_selected = '')
{
$html_output = '';
$html_output .= '';
$html_output .= ' ';
$html_output .= '' . __('Ascending')
. ' ';
$html_output .= '' . __('Descending')
. ' ';
$html_output .= ' ';
$html_output .= ' ';
return $html_output;
}
/**
* Provides search form's row containing column select options
*
* @param array $criteria_column_count Number of criteria columns
* @param integer $columns All column names
* @param string $ins_col If a new criteria column is needed
* @param string $del_col If a criteria column is to be deleted
*
* @return HTML for search table's row
*/
function PMA_dbQbegetColumnNamesRow(
$criteria_column_count, $columns, $ins_col = null, $del_col = null
) {
$html_output = '';
$html_output .= '' . __('Column') . ': ';
$z = 0;
for ($column_index = 0; $column_index < $criteria_column_count; $column_index++)
{
if (isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') {
$html_output .= showColumnSelectCell($columns, $z);
$z++;
}
if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') {
continue;
}
$selected = '';
if (isset($_REQUEST['Field'][$column_index])) {
$selected = $_REQUEST['Field'][$column_index];
$GLOBALS['curField'][$z] = $_REQUEST['Field'][$column_index];
}
$html_output .= showColumnSelectCell($columns, $z, $selected);
$z++;
} // end for
$html_output .= ' ';
return $html_output;
}
/**
* Provides search form's row containing sort(ASC/DESC) select options
*
* @param array $criteria_column_count Number of criteria columns
* @param string $realwidth Largest column width found
* @param string $ins_col If a new criteria column is needed
* @param string $del_col If a criteria column is to be deleted
*
* @return HTML for search table's row
*/
function PMA_dbQbegetSortRow(
$criteria_column_count, $realwidth, $ins_col = null, $del_col = null
) {
$html_output = '';
$html_output .= '' . __('Sort') . ': ';
$z = 0;
for ($column_index = 0; $column_index < $criteria_column_count; $column_index++)
{
if (! empty($ins_col) && isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') {
$html_output .= getSortSelectCell($z, $realwidth);
$z++;
} // end if
if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') {
continue;
}
// If they have chosen all fields using the * selector,
// then sorting is not available, Fix for Bug #570698
if (isset($_REQUEST['Sort'][$column_index]) && isset($_REQUEST['Field'][$column_index])
&& substr($_REQUEST['Field'][$column_index], -2) == '.*'
) {
$_REQUEST['Sort'][$column_index] = '';
} //end if
// Set asc_selected
if (isset($_REQUEST['Sort'][$column_index]) && $_REQUEST['Sort'][$column_index] == 'ASC') {
$GLOBALS['curSort'][$z] = $_REQUEST['Sort'][$column_index];
$asc_selected = ' selected="selected"';
} else {
$asc_selected = '';
} // end if
// Set desc selected
if (isset($_REQUEST['Sort'][$column_index]) && $_REQUEST['Sort'][$column_index] == 'DESC') {
$GLOBALS['curSort'][$z] = $_REQUEST['Sort'][$column_index];
$desc_selected = ' selected="selected"';
} else {
$desc_selected = '';
} // end if
$html_output .= getSortSelectCell(
$z, $realwidth, $asc_selected, $desc_selected
);
$z++;
} // end for
$html_output .= ' ';
return $html_output;
}
/**
* Provides search form's row containing SHOW checkboxes
*
* @param array $criteria_column_count Number of criteria columns
* @param string $ins_col If a new criteria column is needed
* @param string $del_col If a criteria column is to be deleted
*
* @return HTML for search table's row
*/
function PMA_dbQbegetShowRow(
$criteria_column_count, $ins_col = null, $del_col = null
) {
$html_output = '';
$html_output .= '' . __('Show') . ': ';
$z = 0;
for ($column_index = 0; $column_index < $criteria_column_count; $column_index++)
{
if (! empty($ins_col) && isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') {
$html_output .= '';
$html_output .= ' ';
$html_output .= ' ';
$z++;
} // end if
if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') {
continue;
}
if (isset($_REQUEST['Show'][$column_index])) {
$checked = ' checked="checked"';
$GLOBALS['curShow'][$z] = $_REQUEST['Show'][$column_index];
} else {
$checked = '';
}
$html_output .= '';
$html_output .= ' ';
$html_output .= ' ';
$z++;
} // end for
$html_output .= ' ';
return $html_output;
}
/**
* Provides search form's row containing criteria Inputboxes
*
* @param array $criteria_column_count Number of criteria columns
* @param string $realwidth Largest column width found
* @param string $criteria Already Filled criteria
* @param string $prev_criteria Previously filled criteria(hidden form field)
* @param string $ins_col If a new criteria column is needed
* @param string $del_col If a criteria column is to be deleted
*
* @return HTML for search table's row
*/
function PMA_dbQbegetCriteriaInputboxRow(
$criteria_column_count, $realwidth, $criteria, $prev_criteria,
$ins_col = null, $del_col = null
) {
$html_output = '';
$html_output .= '' . __('Criteria') . ': ';
$z = 0;
for ($column_index = 0; $column_index < $criteria_column_count; $column_index++)
{
if (! empty($ins_col) && isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') {
$html_output .= '';
$html_output .= ' ';
$html_output .= ' ';
$z++;
} // end if
if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') {
continue;
}
if (isset($criteria[$column_index])) {
$tmp_criteria = $criteria[$column_index];
}
if ((empty($prev_criteria) || ! isset($prev_criteria[$column_index]))
|| $prev_criteria[$column_index] != htmlspecialchars($tmp_criteria)
) {
$GLOBALS['curCriteria'][$z] = $tmp_criteria;
} else {
$GLOBALS['curCriteria'][$z] = $prev_criteria[$column_index];
}
$html_output .= '';
$html_output .= ' ';
$html_output .= ' ';
$html_output .= ' ';
$z++;
} // end for
$html_output .= ' ';
return $html_output;
}
/**
* Provides footer options for adding/deleting row/columns
*
* @param string $type Whether row or column
*
* @return HTML for footer options
*/
function PMA_dbQbeGetFootersOptions($type)
{
$html_output = '';
$html_output .= (($type == 'row')
? __('Add/Delete criteria rows') : __('Add/Delete columns'));
$html_output .= ':';
$html_output .= '-3 ';
$html_output .= '-2 ';
$html_output .= '-1 ';
$html_output .= '0 ';
$html_output .= '1 ';
$html_output .= '2 ';
$html_output .= '3 ';
$html_output .= ' ';
$html_output .= '
';
return $html_output;
}
/**
* Provides search form table's footer options
*
* @return HTML for table footer
*/
function PMA_dbQbeGetTableFooters()
{
$html_output = '';
return $html_output;
}
/**
* Provides a select list of database tables
*
* @param array $table_names Names of all the tables
*
* @return HTML for table select list
*/
function PMA_dbQbeGetTablesList($table_names)
{
$html_output = '';
$html_output .= '
';
$html_output .= '' . __('Use Tables') . ' ';
// Build the options list for each table name
$options = '';
$numTableListOptions = 0;
foreach ($table_names as $key => $val) {
$options .= ''
. (str_replace(' ', ' ', htmlspecialchars($key))) . ' ';
$numTableListOptions++;
}
$html_output .= '';
$html_output .= $options;
$html_output .= ' ';
$html_output .= ' ';
$html_output .= '';
$html_output .= '';
return $html_output;
}
/**
* Provides And/Or modification cell along with Insert/Delete options
* (For modifying search form's table columns)
*
* @param integer $column_number Column Number (0,1,2) or more
* @param array $selected Selected criteria column name
*
* @return HTML for modification cell
*/
function PMA_dbQbeGetAndOrColCell($column_number, $selected = null)
{
$html_output = '';
$html_output .= '' . __('Or') . ': ';
$html_output .= ' ';
$html_output .= ' ' . __('And') . ': ';
$html_output .= ' ';
$html_output .= ' ' . __('Ins');
$html_output .= ' ';
$html_output .= ' ' . __('Del');
$html_output .= ' ';
$html_output .= ' ';
return $html_output;
}
/**
* Provides search form's row containing column modifications options
* (For modifying search form's table columns)
*
* @param array $criteria_column_count Number of criteria columns
* @param string $realwidth Largest column width found
* @param string $criteria Already Filled criteria
* @param string $prev_criteria Previously filled criteria(hidden form field)
* @param string $ins_col If a new criteria column is needed
* @param string $del_col If a criteria column is to be deleted
*
* @return HTML for search table's row
*/
function PMA_dbQbeGetModifyColumnsRow($criteria_column_count, $and_or_col,
$ins_col = null, $del_col = null
) {
$html_output = '';
$html_output .= '' . __('Modify') . ': ';
$z = 0;
for ($x = 0; $x < $criteria_column_count; $x++) {
if (! empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
$html_output .= PMA_dbQbeGetAndOrColCell($z);
$z++;
} // end if
if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
continue;
}
if (isset($and_or_col[$x])) {
$GLOBALS['curAndOrCol'][$z] = $and_or_col[$x];
}
if (isset($and_or_col[$x]) && $and_or_col[$x] == 'or') {
$chk['or'] = ' checked="checked"';
$chk['and'] = '';
} else {
$chk['and'] = ' checked="checked"';
$chk['or'] = '';
}
$html_output .= PMA_dbQbeGetAndOrColCell($z, $chk);
$z++;
} // end for
$html_output .= ' ';
return $html_output;
}
if ($cfgRelation['designerwork']) {
$url = 'pmd_general.php' . PMA_generate_common_url(
array_merge(
$url_params,
array('query' => 1)
)
);
PMA_Message::notice(
sprintf(
__('Switch to %svisual builder%s'),
'',
' '
)
)->display();
}
?>