Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
80ff0e5eff
750
db_qbe.php
750
db_qbe.php
@ -40,6 +40,15 @@ foreach (array_keys($_POST) as $post_key) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Initialize some more global variables
|
||||
*/
|
||||
$GLOBALS['curField'] = array();
|
||||
$GLOBALS['curSort'] = array();
|
||||
$GLOBALS['curShow'] = array();
|
||||
$GLOBALS['curCriteria'] = array();
|
||||
$GLOBALS['curAndOrRow'] = array();
|
||||
$GLOBALS['curAndOrCol'] = array();
|
||||
|
||||
/**
|
||||
* Gets the relation settings
|
||||
@ -170,32 +179,393 @@ $realwidth = $form_column_width . 'ex';
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* Provides select options list containing column names
|
||||
*
|
||||
* @param array $columns
|
||||
* @param integer $column_number
|
||||
* @param string $selected
|
||||
* @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 = '')
|
||||
{
|
||||
?>
|
||||
<td class="center">
|
||||
<select name="Field[<?php echo $column_number; ?>]" size="1">
|
||||
<option value=""> </option>
|
||||
<?php
|
||||
$html_output = '';
|
||||
$html_output .= '<td class="center">';
|
||||
$html_output .= '<select name="Field[' . $column_number . ']" size="1">';
|
||||
$html_output .= '<option value=""> </option>';
|
||||
foreach ($columns as $column) {
|
||||
if ($column === $selected) {
|
||||
$sel = ' selected="selected"';
|
||||
} else {
|
||||
$sel = '';
|
||||
}
|
||||
echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'
|
||||
. str_replace(' ', ' ', htmlspecialchars($column)) . '</option>' . "\n";
|
||||
$html_output .= '<option value="' . htmlspecialchars($column) . '"'
|
||||
. (($column === $selected) ? ' selected="selected"' : '') . '>'
|
||||
. str_replace(' ', ' ', htmlspecialchars($column)) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<?php
|
||||
$html_output .= '</select>';
|
||||
$html_output .= '</td>';
|
||||
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 = '<td class="center">';
|
||||
$html_output .= '<select style="width: ' . $realwidth
|
||||
. '" name="Sort[' . $column_number . ']" size="1">';
|
||||
$html_output .= '<option value=""> </option>';
|
||||
$html_output .= '<option value="ASC"' . $asc_selected . '>' . __('Ascending')
|
||||
. '</option>';
|
||||
$html_output .= '<option value="DESC"' . $desc_selected . '>' . __('Descending')
|
||||
. '</option>';
|
||||
$html_output .= '</select>';
|
||||
$html_output .= '</td>';
|
||||
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 = '<tr class="odd noclick">';
|
||||
$html_output .= '<th>' . __('Column') . ':</th>';
|
||||
$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 .= '</tr>';
|
||||
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 = '<tr class="even noclick">';
|
||||
$html_output .= '<th>' . __('Sort') . ':</th>';
|
||||
$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 .= '</tr>';
|
||||
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 = '<tr class="odd noclick">';
|
||||
$html_output .= '<th>' . __('Show') . ':</th>';
|
||||
$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 .= '<td class="center">';
|
||||
$html_output .= '<input type="checkbox" name="Show[' . $z . ']" />';
|
||||
$html_output .= '</td>';
|
||||
$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 .= '<td class="center">';
|
||||
$html_output .= '<input type="checkbox" name="Show[' . $z . ']"' . $checked
|
||||
. ' />';
|
||||
$html_output .= '</td>';
|
||||
$z++;
|
||||
} // end for
|
||||
$html_output .= '</tr>';
|
||||
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 = '<tr class="even noclick">';
|
||||
$html_output .= '<th>' . __('Criteria') . ':</th>';
|
||||
$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 .= '<td class="center">';
|
||||
$html_output .= '<input type="text" name="criteria[' . $z . ']"'
|
||||
. ' value="" class="textfield" style="width: ' . $realwidth
|
||||
. '" size="20" />';
|
||||
$html_output .= '</td>';
|
||||
$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 .= '<td class="center">';
|
||||
$html_output .= '<input type="hidden" name="prev_criteria[' . $z . ']"'
|
||||
. ' value="' . htmlspecialchars($GLOBALS['curCriteria'][$z]) . '" />';
|
||||
$html_output .= '<input type="text" name="criteria[' . $z . ']"'
|
||||
. ' value="' . htmlspecialchars($tmp_criteria) . '" class="textfield"'
|
||||
. ' style="width: ' . $realwidth . '" size="20" />';
|
||||
$html_output .= '</td>';
|
||||
$z++;
|
||||
} // end for
|
||||
$html_output .= '</tr>';
|
||||
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 = '<div class="floatleft">';
|
||||
$html_output .= (($type == 'row')
|
||||
? __('Add/Delete criteria rows') : __('Add/Delete columns'));
|
||||
$html_output .= ':<select size="1" name="'
|
||||
. (($type == 'row') ? 'add_row' : 'add_col') . '">';
|
||||
$html_output .= '<option value="-3">-3</option>';
|
||||
$html_output .= '<option value="-2">-2</option>';
|
||||
$html_output .= '<option value="-1">-1</option>';
|
||||
$html_output .= '<option value="0" selected="selected">0</option>';
|
||||
$html_output .= '<option value="1">1</option>';
|
||||
$html_output .= '<option value="2">2</option>';
|
||||
$html_output .= '<option value="3">3</option>';
|
||||
$html_output .= '</select>';
|
||||
$html_output .= '</div>';
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides search form table's footer options
|
||||
*
|
||||
* @return HTML for table footer
|
||||
*/
|
||||
function PMA_dbQbeGetTableFooters()
|
||||
{
|
||||
$html_output = '<fieldset class="tblFooters">';
|
||||
$html_output .= PMA_dbQbeGetFootersOptions("row");
|
||||
$html_output .= PMA_dbQbeGetFootersOptions("column");
|
||||
$html_output .= '<div class="floatleft">';
|
||||
$html_output .= '<input type="submit" name="modify"'
|
||||
. 'value="' . __('Update Query') . '" />';
|
||||
$html_output .= '</div>';
|
||||
$html_output .= '</fieldset>';
|
||||
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 = '<div class="floatleft">';
|
||||
$html_output .= '<fieldset>';
|
||||
$html_output .= '<legend>' . __('Use Tables') . '</legend>';
|
||||
// Build the options list for each table name
|
||||
$options = '';
|
||||
$numTableListOptions = 0;
|
||||
foreach ($table_names as $key => $val) {
|
||||
$options .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
|
||||
. (str_replace(' ', ' ', htmlspecialchars($key))) . '</option>';
|
||||
$numTableListOptions++;
|
||||
}
|
||||
$html_output .= '<select name="TableList[]" multiple="multiple" id="listTable"'
|
||||
. ' size="' . (($numTableListOptions > 30) ? '15' : '7') . '">';
|
||||
$html_output .= $options;
|
||||
$html_output .= '</select>';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '<fieldset class="tblFooters">';
|
||||
$html_output .= '<input type="submit" name="modify" value="'
|
||||
. __('Update Query') . '" />';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '</div>';
|
||||
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 = '<td class="center">';
|
||||
$html_output .= '<strong>' . __('Or') . ':</strong>';
|
||||
$html_output .= '<input type="radio" name="and_or_col[' . $column_number . ']"'
|
||||
. ' value="or"' . $selected['or'] . ' />';
|
||||
$html_output .= ' <strong>' . __('And') . ':</strong>';
|
||||
$html_output .= '<input type="radio" name="and_or_col[' . $column_number . ']"'
|
||||
. ' value="and"' . $selected['and'] . ' />';
|
||||
$html_output .= '<br />' . __('Ins');
|
||||
$html_output .= '<input type="checkbox" name="ins_col[' . $column_number . ']" />';
|
||||
$html_output .= ' ' . __('Del');
|
||||
$html_output .= '<input type="checkbox" name="del_col[' . $column_number . ']" />';
|
||||
$html_output .= '</td>';
|
||||
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 = '<tr class="even noclick">';
|
||||
$html_output .= '<th>' . __('Modify') . ':</th>';
|
||||
$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 .= '</tr>';
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
if ($cfgRelation['designerwork']) {
|
||||
@ -217,172 +587,20 @@ if ($cfgRelation['designerwork']) {
|
||||
<form action="db_qbe.php" method="post">
|
||||
<fieldset>
|
||||
<table class="data" style="width: 100%;">
|
||||
<tr class="odd noclick">
|
||||
<th><?php echo __('Column'); ?>:</th>
|
||||
<?php
|
||||
$z = 0;
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
|
||||
showColumnSelectCell($fld, $z);
|
||||
$z++;
|
||||
}
|
||||
|
||||
if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$selected = '';
|
||||
if (isset($Field[$x])) {
|
||||
$selected = $Field[$x];
|
||||
$curField[$z] = $Field[$x];
|
||||
}
|
||||
showColumnSelectCell($fld, $z, $selected);
|
||||
$z++;
|
||||
} // end for
|
||||
echo PMA_dbQbegetColumnNamesRow(
|
||||
$col, $fld, $ins_col, $del_col
|
||||
);
|
||||
echo PMA_dbQbegetSortRow(
|
||||
$col, $realwidth, $ins_col, $del_col
|
||||
);
|
||||
echo PMA_dbQbegetShowRow(
|
||||
$col, $ins_col, $del_col
|
||||
);
|
||||
echo PMA_dbQbegetCriteriaInputboxRow(
|
||||
$col, $realwidth, $criteria, $prev_criteria, $ins_col, $del_col
|
||||
);
|
||||
?>
|
||||
</tr>
|
||||
|
||||
<!-- Sort row -->
|
||||
<tr class="even noclick">
|
||||
<th><?php echo __('Sort'); ?>:</th>
|
||||
<?php
|
||||
$z = 0;
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (! empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
|
||||
?>
|
||||
<td class="center">
|
||||
<select style="width: <?php echo $realwidth; ?>" name="Sort[<?php echo $z; ?>]" size="1">
|
||||
<option value=""> </option>
|
||||
<option value="ASC"><?php echo __('Ascending'); ?></option>
|
||||
<option value="DESC"><?php echo __('Descending'); ?></option>
|
||||
</select>
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
} // end if
|
||||
echo "\n";
|
||||
|
||||
if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
|
||||
continue;
|
||||
}
|
||||
?>
|
||||
<td class="center">
|
||||
<select style="width: <?php echo $realwidth; ?>" name="Sort[<?php echo $z; ?>]" size="1">
|
||||
<option value=""> </option>
|
||||
<?php
|
||||
echo "\n";
|
||||
|
||||
// If they have chosen all fields using the * selector,
|
||||
// then sorting is not available
|
||||
// Fix for Bug #570698
|
||||
if (isset($Sort[$x]) && isset($Field[$x])
|
||||
&& substr($Field[$x], -2) == '.*'
|
||||
) {
|
||||
$Sort[$x] = '';
|
||||
} //end if
|
||||
|
||||
if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {
|
||||
$curSort[$z] = $Sort[$x];
|
||||
$sel = ' selected="selected"';
|
||||
} else {
|
||||
$sel = '';
|
||||
} // end if
|
||||
echo ' ';
|
||||
echo '<option value="ASC"' . $sel . '>' . __('Ascending') . '</option>' . "\n";
|
||||
if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {
|
||||
$curSort[$z] = $Sort[$x];
|
||||
$sel = ' selected="selected"';
|
||||
} else {
|
||||
$sel = '';
|
||||
} // end if
|
||||
echo ' ';
|
||||
echo '<option value="DESC"' . $sel . '>' . __('Descending') . '</option>' . "\n";
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
echo "\n";
|
||||
} // end for
|
||||
?>
|
||||
</tr>
|
||||
|
||||
<!-- Show row -->
|
||||
<tr class="odd noclick">
|
||||
<th><?php echo __('Show'); ?>:</th>
|
||||
<?php
|
||||
$z = 0;
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (! empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
|
||||
?>
|
||||
<td class="center">
|
||||
<input type="checkbox" name="Show[<?php echo $z; ?>]" />
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
} // end if
|
||||
echo "\n";
|
||||
|
||||
if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
|
||||
continue;
|
||||
}
|
||||
if (isset($Show[$x])) {
|
||||
$checked = ' checked="checked"';
|
||||
$curShow[$z] = $Show[$x];
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
?>
|
||||
<td class="center">
|
||||
<input type="checkbox" name="Show[<?php echo $z; ?>]"<?php echo $checked; ?> />
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
echo "\n";
|
||||
} // end for
|
||||
?>
|
||||
</tr>
|
||||
|
||||
<!-- Criteria row -->
|
||||
<tr class="even noclick">
|
||||
<th><?php echo __('Criteria'); ?>:</th>
|
||||
<?php
|
||||
$z = 0;
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (! empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
|
||||
?>
|
||||
<td class="center">
|
||||
<input type="text" name="criteria[<?php echo $z; ?>]" value="" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
} // end if
|
||||
echo "\n";
|
||||
|
||||
if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
|
||||
continue;
|
||||
}
|
||||
if (isset($criteria[$x])) {
|
||||
$tmp_criteria = $criteria[$x];
|
||||
}
|
||||
if ((empty($prev_criteria) || ! isset($prev_criteria[$x]))
|
||||
|| $prev_criteria[$x] != htmlspecialchars($tmp_criteria)
|
||||
) {
|
||||
$curCriteria[$z] = $tmp_criteria;
|
||||
} else {
|
||||
$curCriteria[$z] = $prev_criteria[$x];
|
||||
}
|
||||
?>
|
||||
<td class="center">
|
||||
<input type="hidden" name="prev_criteria[<?php echo $z; ?>]" value="<?php echo htmlspecialchars($curCriteria[$z]); ?>" />
|
||||
<input type="text" name="criteria[<?php echo $z; ?>]" value="<?php echo htmlspecialchars($tmp_criteria); ?>" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
echo "\n";
|
||||
} // end for
|
||||
?>
|
||||
</tr>
|
||||
|
||||
<!-- And/Or columns and rows -->
|
||||
<?php
|
||||
@ -464,7 +682,7 @@ for ($y = 0; $y <= $row; $y++) {
|
||||
}
|
||||
|
||||
if (isset($and_or_row[$y])) {
|
||||
$curAndOrRow[$w] = $and_or_row[$y];
|
||||
$GLOBALS['curAndOrRow'][$w] = $and_or_row[$y];
|
||||
}
|
||||
if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') {
|
||||
$chk['and'] = ' checked="checked"';
|
||||
@ -551,73 +769,13 @@ for ($y = 0; $y <= $row; $y++) {
|
||||
$odd_row =! $odd_row;
|
||||
} // end for
|
||||
?>
|
||||
<!-- Modify columns -->
|
||||
<tr class="even noclick">
|
||||
<th><?php echo __('Modify'); ?>:</th>
|
||||
|
||||
<?php
|
||||
$z = 0;
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (! empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
|
||||
$curAndOrCol[$z] = $and_or_col[$y];
|
||||
if ($and_or_col[$z] == 'or') {
|
||||
$chk['or'] = ' checked="checked"';
|
||||
$chk['and'] = '';
|
||||
} else {
|
||||
$chk['and'] = ' checked="checked"';
|
||||
$chk['or'] = '';
|
||||
}
|
||||
?>
|
||||
<td class="center">
|
||||
<strong><?php echo __('Or'); ?>:</strong>
|
||||
<input type="radio" name="and_or_col[<?php echo $z; ?>]" value="or"<?php echo $chk['or']; ?> />
|
||||
<strong><?php echo __('And'); ?>:</strong>
|
||||
<input type="radio" name="and_or_col[<?php echo $z; ?>]" value="and"<?php echo $chk['and']; ?> />
|
||||
<br />
|
||||
<?php echo __('Ins') . "\n"; ?>
|
||||
<input type="checkbox" name="ins_col[<?php echo $z; ?>]" />
|
||||
<?php echo __('Del') . "\n"; ?>
|
||||
<input type="checkbox" name="del_col[<?php echo $z; ?>]" />
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
} // end if
|
||||
echo "\n";
|
||||
|
||||
if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($and_or_col[$y])) {
|
||||
$curAndOrCol[$z] = $and_or_col[$y];
|
||||
}
|
||||
if (isset($and_or_col[$z]) && $and_or_col[$z] == 'or') {
|
||||
$chk['or'] = ' checked="checked"';
|
||||
$chk['and'] = '';
|
||||
} else {
|
||||
$chk['and'] = ' checked="checked"';
|
||||
$chk['or'] = '';
|
||||
}
|
||||
?>
|
||||
<td class="center">
|
||||
<strong><?php echo __('Or'); ?>:</strong>
|
||||
<input type="radio" name="and_or_col[<?php echo $z; ?>]" value="or"<?php echo $chk['or']; ?> />
|
||||
<strong><?php echo __('And'); ?>:</strong>
|
||||
<input type="radio" name="and_or_col[<?php echo $z; ?>]" value="and"<?php echo $chk['and']; ?> />
|
||||
<br />
|
||||
<?php echo __('Ins') . "\n"; ?>
|
||||
<input type="checkbox" name="ins_col[<?php echo $z; ?>]" />
|
||||
<?php echo __('Del') . "\n"; ?>
|
||||
<input type="checkbox" name="del_col[<?php echo $z; ?>]" />
|
||||
</td>
|
||||
<?php
|
||||
$z++;
|
||||
echo "\n";
|
||||
} // end for
|
||||
echo PMA_dbQbeGetModifyColumnsRow(
|
||||
$col, $and_or_col, $ins_col, $del_col
|
||||
);
|
||||
?>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- Other controls -->
|
||||
<?php
|
||||
$w--;
|
||||
$url_params['db'] = $db;
|
||||
@ -626,59 +784,11 @@ $url_params['rows'] = $w;
|
||||
echo PMA_generate_common_hidden_inputs($url_params);
|
||||
?>
|
||||
</fieldset>
|
||||
<fieldset class="tblFooters">
|
||||
<div class="floatleft">
|
||||
<?php echo __('Add/Delete criteria rows'); ?>:
|
||||
<select size="1" name="add_row">
|
||||
<option value="-3">-3</option>
|
||||
<option value="-2">-2</option>
|
||||
<option value="-1">-1</option>
|
||||
<option value="0" selected="selected">0</option>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="floatleft">
|
||||
<?php echo __('Add/Delete columns'); ?>:
|
||||
<select size="1" name="add_col">
|
||||
<option value="-3">-3</option>
|
||||
<option value="-2">-2</option>
|
||||
<option value="-1">-1</option>
|
||||
<option value="0" selected="selected">0</option>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Generates a query -->
|
||||
<div class="floatleft">
|
||||
<input type="submit" name="modify" value="<?php echo __('Update Query'); ?>" />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="floatleft">
|
||||
<fieldset>
|
||||
<legend><?php echo __('Use Tables'); ?></legend>
|
||||
<?php
|
||||
$options = '';
|
||||
$numTableListOptions = 0;
|
||||
foreach ($tbl_names as $key => $val) {
|
||||
$options .= ' ';
|
||||
$options .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
|
||||
. str_replace(' ', ' ', htmlspecialchars($key)) . '</option>' . "\n";
|
||||
$numTableListOptions++;
|
||||
}
|
||||
echo PMA_dbQbeGetTableFooters();
|
||||
echo PMA_dbQbeGetTablesList($tbl_names);
|
||||
?>
|
||||
<select name="TableList[]" multiple="multiple" id="listTable"
|
||||
size="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>">
|
||||
<?php echo $options; ?>
|
||||
</select>
|
||||
</fieldset>
|
||||
<fieldset class="tblFooters">
|
||||
<input type="submit" name="modify" value="<?php echo __('Update Query'); ?>" />
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="floatleft">
|
||||
<fieldset>
|
||||
@ -694,11 +804,14 @@ if (! isset($qry_select)) {
|
||||
$qry_select = '';
|
||||
}
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (! empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') {
|
||||
if (! empty($GLOBALS['curField'][$x])
|
||||
&& isset($GLOBALS['curShow'][$x])
|
||||
&& $GLOBALS['curShow'][$x] == 'on')
|
||||
{
|
||||
if ($last_select) {
|
||||
$qry_select .= ', ';
|
||||
}
|
||||
$qry_select .= $curField[$x];
|
||||
$qry_select .= $GLOBALS['curField'][$x];
|
||||
$last_select = 1;
|
||||
}
|
||||
} // end for
|
||||
@ -901,11 +1014,16 @@ if (! empty($qry_from)) {
|
||||
$qry_where = '';
|
||||
$criteria_cnt = 0;
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (! empty($curField[$x]) && ! empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) {
|
||||
$qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
|
||||
if (! empty($GLOBALS['curField'][$x])
|
||||
&& ! empty($GLOBALS['curCriteria'][$x])
|
||||
&& $x
|
||||
&& isset($last_where)
|
||||
&& isset($GLOBALS['curAndOrCol'])) {
|
||||
$qry_where .= ' ' . strtoupper($GLOBALS['curAndOrCol'][$last_where]) . ' ';
|
||||
}
|
||||
if (! empty($curField[$x]) && ! empty($curCriteria[$x])) {
|
||||
$qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
|
||||
if (! empty($GLOBALS['curField'][$x]) && ! empty($GLOBALS['curCriteria'][$x])) {
|
||||
$qry_where .= '(' . $GLOBALS['curField'][$x] . ' '
|
||||
. $GLOBALS['curCriteria'][$x] . ')';
|
||||
$last_where = $x;
|
||||
$criteria_cnt++;
|
||||
}
|
||||
@ -914,19 +1032,19 @@ if ($criteria_cnt > 1) {
|
||||
$qry_where = '(' . $qry_where . ')';
|
||||
}
|
||||
// OR rows ${'cur' . $or}[$x]
|
||||
if (! isset($curAndOrRow)) {
|
||||
$curAndOrRow = array();
|
||||
if (! isset($GLOBALS['curAndOrRow'])) {
|
||||
$GLOBALS['curAndOrRow'] = array();
|
||||
}
|
||||
for ($y = 0; $y <= $row; $y++) {
|
||||
$criteria_cnt = 0;
|
||||
$qry_orwhere = '';
|
||||
$last_orwhere = '';
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if (! empty($curField[$x]) && ! empty(${'curOr' . $y}[$x]) && $x) {
|
||||
$qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';
|
||||
if (! empty($GLOBALS['curField'][$x]) && ! empty(${'curOr' . $y}[$x]) && $x) {
|
||||
$qry_orwhere .= ' ' . strtoupper($GLOBALS['curAndOrCol'][$last_orwhere]) . ' ';
|
||||
}
|
||||
if (! empty($curField[$x]) && ! empty(${'curOr' . $y}[$x])) {
|
||||
$qry_orwhere .= '(' . $curField[$x]
|
||||
if (! empty($GLOBALS['curField'][$x]) && ! empty(${'curOr' . $y}[$x])) {
|
||||
$qry_orwhere .= '(' . $GLOBALS['curField'][$x]
|
||||
. ' '
|
||||
. ${'curOr' . $y}[$x]
|
||||
. ')';
|
||||
@ -939,7 +1057,7 @@ for ($y = 0; $y <= $row; $y++) {
|
||||
}
|
||||
if (! empty($qry_orwhere)) {
|
||||
$qry_where .= "\n"
|
||||
. strtoupper(isset($curAndOrRow[$y]) ? $curAndOrRow[$y] . ' ' : '')
|
||||
. strtoupper(isset($GLOBALS['curAndOrRow'][$y]) ? $GLOBALS['curAndOrRow'][$y] . ' ' : '')
|
||||
. $qry_orwhere;
|
||||
} // end if
|
||||
} // end for
|
||||
@ -955,15 +1073,15 @@ if (! isset($qry_orderby)) {
|
||||
$qry_orderby = '';
|
||||
}
|
||||
for ($x = 0; $x < $col; $x++) {
|
||||
if ($last_orderby && $x && ! empty($curField[$x]) && ! empty($curSort[$x])) {
|
||||
if ($last_orderby && $x && ! empty($GLOBALS['curField'][$x]) && ! empty($GLOBALS['curSort'][$x])) {
|
||||
$qry_orderby .= ', ';
|
||||
}
|
||||
if (! empty($curField[$x]) && ! empty($curSort[$x])) {
|
||||
if (! empty($GLOBALS['curField'][$x]) && ! empty($GLOBALS['curSort'][$x])) {
|
||||
// if they have chosen all fields using the * selector,
|
||||
// then sorting is not available
|
||||
// Fix for Bug #570698
|
||||
if (substr($curField[$x], -2) != '.*') {
|
||||
$qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
|
||||
if (substr($GLOBALS['curField'][$x], -2) != '.*') {
|
||||
$qry_orderby .= $GLOBALS['curField'][$x] . ' ' . $GLOBALS['curSort'][$x];
|
||||
$last_orderby = 1;
|
||||
}
|
||||
}
|
||||
|
||||
106
db_search.php
106
db_search.php
@ -9,10 +9,10 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets some core libraries
|
||||
*/
|
||||
require_once 'libraries/common.inc.php';
|
||||
require_once 'libraries/db_search.lib.php';
|
||||
require_once 'libraries/DbSearch.class.php';
|
||||
|
||||
$response = PMA_Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
@ -21,119 +21,39 @@ $scripts->addFile('db_search.js');
|
||||
$scripts->addFile('sql.js');
|
||||
$scripts->addFile('makegrid.js');
|
||||
$scripts->addFile('jquery/timepicker.js');
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
|
||||
/**
|
||||
* Gets some core libraries and send headers
|
||||
*/
|
||||
require 'libraries/db_common.inc.php';
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
// If config variable $GLOBALS['cfg']['Usedbsearch'] is on false : exit.
|
||||
if (! $GLOBALS['cfg']['UseDbSearch']) {
|
||||
$common_functions->mysqlDie(__('Access denied'), '', false, $err_url);
|
||||
PMA_CommonFunctions::getInstance()->mysqlDie(
|
||||
__('Access denied'), '', false, $err_url
|
||||
);
|
||||
} // end if
|
||||
$url_query .= '&goto=db_search.php';
|
||||
$url_params['goto'] = 'db_search.php';
|
||||
|
||||
/**
|
||||
* @global array list of tables from the current database
|
||||
* but do not clash with $tables coming from db_info.inc.php
|
||||
*/
|
||||
$tables_names_only = PMA_DBI_get_tables($GLOBALS['db']);
|
||||
|
||||
$searchTypes = array(
|
||||
'1' => __('at least one of the words'),
|
||||
'2' => __('all words'),
|
||||
'3' => __('the exact phrase'),
|
||||
'4' => __('as regular expression'),
|
||||
);
|
||||
|
||||
if (empty($_REQUEST['criteriaSearchType'])
|
||||
|| ! is_string($_REQUEST['criteriaSearchType'])
|
||||
|| ! array_key_exists($_REQUEST['criteriaSearchType'], $searchTypes)
|
||||
) {
|
||||
$criteriaSearchType = 1;
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$criteriaSearchType = (int) $_REQUEST['criteriaSearchType'];
|
||||
$searchTypeDescription = $searchTypes[$_REQUEST['criteriaSearchType']];
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['criteriaSearchString'])
|
||||
|| ! is_string($_REQUEST['criteriaSearchString'])
|
||||
) {
|
||||
$criteriaSearchString = '';
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$criteriaSearchString = $_REQUEST['criteriaSearchString'];
|
||||
}
|
||||
|
||||
$criteriaTables = array();
|
||||
if (empty($_REQUEST['criteriaTables']) || ! is_array($_REQUEST['criteriaTables'])) {
|
||||
unset($_REQUEST['submit_search']);
|
||||
} elseif (! isset($_REQUEST['selectall']) && ! isset($_REQUEST['unselectall'])) {
|
||||
$criteriaTables = array_intersect(
|
||||
$_REQUEST['criteriaTables'], $tables_names_only
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['selectall'])) {
|
||||
$criteriaTables = $tables_names_only;
|
||||
} elseif (isset($_REQUEST['unselectall'])) {
|
||||
$criteriaTables = array();
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['criteriaColumnName'])
|
||||
|| ! is_string($_REQUEST['criteriaColumnName'])
|
||||
) {
|
||||
unset($criteriaColumnName);
|
||||
} else {
|
||||
$criteriaColumnName = $common_functions->sqlAddSlashes(
|
||||
$_REQUEST['criteriaColumnName'], true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays top links if we are not in an Ajax request
|
||||
*/
|
||||
$sub_part = '';
|
||||
// Create a database search instance
|
||||
$db_search = new PMA_DbSearch($GLOBALS['db']);
|
||||
|
||||
// Displays top links if we are not in an Ajax request
|
||||
if ( $GLOBALS['is_ajax_request'] != true) {
|
||||
include 'libraries/db_info.inc.php';
|
||||
$response->addHTML('<div id="searchresults">');
|
||||
}
|
||||
|
||||
/**
|
||||
* Main search form has been submitted
|
||||
*/
|
||||
// Main search form has been submitted, get results
|
||||
if (isset($_REQUEST['submit_search'])) {
|
||||
$response->addHTML(
|
||||
PMA_dbSearchGetSearchResults(
|
||||
$criteriaTables, $searchTypeDescription,
|
||||
$criteriaSearchString, $criteriaSearchType,
|
||||
(! empty($criteriaColumnName) ? $criteriaColumnName : '')
|
||||
)
|
||||
);
|
||||
$response->addHTML($db_search->getSearchResults());
|
||||
}
|
||||
|
||||
/**
|
||||
* If we are in an Ajax request, we need to exit after displaying all the HTML
|
||||
*/
|
||||
// If we are in an Ajax request, we need to exit after displaying all the HTML
|
||||
if ($GLOBALS['is_ajax_request'] == true) {
|
||||
exit;
|
||||
} else {
|
||||
$response->addHTML('</div>');//end searchresults div
|
||||
}
|
||||
|
||||
// Add search form
|
||||
$response->addHTML(
|
||||
PMA_dbSearchGetSelectionForm(
|
||||
$criteriaSearchString, $criteriaSearchType, $tables_names_only,
|
||||
$criteriaTables, $url_params,
|
||||
(! empty($criteriaColumnName) ? $criteriaColumnName : '')
|
||||
)
|
||||
);
|
||||
// Add search form to response
|
||||
$response->addHTML($db_search->getSelectionForm($url_params));
|
||||
?>
|
||||
|
||||
526
libraries/DbSearch.class.php
Normal file
526
libraries/DbSearch.class.php
Normal file
@ -0,0 +1,526 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Handles Database Search
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to handle database search
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class PMA_DbSearch
|
||||
{
|
||||
/**
|
||||
* Database name
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_db;
|
||||
/**
|
||||
* Table Names
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_tables_names_only;
|
||||
/**
|
||||
* Type of search
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_searchTypes;
|
||||
/**
|
||||
* Already set search type
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_criteriaSearchType;
|
||||
/**
|
||||
* Already set search type's description
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_searchTypeDescription;
|
||||
/**
|
||||
* Search string/regexp
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_criteriaSearchString;
|
||||
/**
|
||||
* Criteria Tables to search in
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_criteriaTables;
|
||||
/**
|
||||
* Restrict the search to this column
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_criteriaColumnName;
|
||||
/**
|
||||
* PMA_CommonFunctions object
|
||||
*
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
private $_common_functions;
|
||||
|
||||
/**
|
||||
* Public Constructor
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->_db = $db;
|
||||
// Sets criteria parameters
|
||||
$this->_setSearchParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set CommmonFunctions
|
||||
*
|
||||
* @param PMA_CommonFunctions $commonFunctions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCommonFunctions(PMA_CommonFunctions $commonFunctions)
|
||||
{
|
||||
$this->_common_functions = $commonFunctions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get CommmonFunctions
|
||||
*
|
||||
* @return CommonFunctions object
|
||||
*/
|
||||
public function getCommonFunctions()
|
||||
{
|
||||
if (is_null($this->_common_functions)) {
|
||||
$this->_common_functions = PMA_CommonFunctions::getInstance();
|
||||
}
|
||||
return $this->_common_functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets search parameters
|
||||
*
|
||||
*/
|
||||
private function _setSearchParams()
|
||||
{
|
||||
$this->_tables_names_only = PMA_DBI_get_tables($this->_db);
|
||||
|
||||
$this->_searchTypes = array(
|
||||
'1' => __('at least one of the words'),
|
||||
'2' => __('all words'),
|
||||
'3' => __('the exact phrase'),
|
||||
'4' => __('as regular expression'),
|
||||
);
|
||||
|
||||
if (empty($_REQUEST['criteriaSearchType'])
|
||||
|| ! is_string($_REQUEST['criteriaSearchType'])
|
||||
|| ! array_key_exists($_REQUEST['criteriaSearchType'], $this->_searchTypes)
|
||||
) {
|
||||
$this->_criteriaSearchType = 1;
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$this->_criteriaSearchType = (int) $_REQUEST['criteriaSearchType'];
|
||||
$this->_searchTypeDescription = $this->_searchTypes[$_REQUEST['criteriaSearchType']];
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['criteriaSearchString'])
|
||||
|| ! is_string($_REQUEST['criteriaSearchString'])
|
||||
) {
|
||||
$this->_criteriaSearchString = '';
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$this->_criteriaSearchString = $_REQUEST['criteriaSearchString'];
|
||||
}
|
||||
|
||||
$this->_criteriaTables = array();
|
||||
if (empty($_REQUEST['criteriaTables']) || ! is_array($_REQUEST['criteriaTables'])) {
|
||||
unset($_REQUEST['submit_search']);
|
||||
} elseif (! isset($_REQUEST['selectall']) && ! isset($_REQUEST['unselectall'])) {
|
||||
$this->_criteriaTables = array_intersect(
|
||||
$_REQUEST['criteriaTables'], $this->_tables_names_only
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['selectall'])) {
|
||||
$this->_criteriaTables = $this->_tables_names_only;
|
||||
} elseif (isset($_REQUEST['unselectall'])) {
|
||||
$this->_criteriaTables = array();
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['criteriaColumnName'])
|
||||
|| ! is_string($_REQUEST['criteriaColumnName'])
|
||||
) {
|
||||
unset($this->_criteriaColumnName);
|
||||
} else {
|
||||
$this->_criteriaColumnName = $this->getCommonFunctions()->sqlAddSlashes(
|
||||
$_REQUEST['criteriaColumnName'], true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the SQL search query
|
||||
*
|
||||
* @param string $table The table name
|
||||
*
|
||||
* @return array 3 SQL querys (for count, display and delete results)
|
||||
*
|
||||
* @todo can we make use of fulltextsearch IN BOOLEAN MODE for this?
|
||||
* PMA_backquote
|
||||
* PMA_DBI_free_result
|
||||
* PMA_DBI_fetch_assoc
|
||||
* $GLOBALS['db']
|
||||
* explode
|
||||
* count
|
||||
* strlen
|
||||
*/
|
||||
private function _getSearchSqls($table)
|
||||
{
|
||||
// Statement types
|
||||
$sqlstr_select = 'SELECT';
|
||||
$sqlstr_delete = 'DELETE';
|
||||
// Table to use
|
||||
$sqlstr_from = ' FROM '
|
||||
. $this->getCommonFunctions()->backquote($GLOBALS['db']) . '.'
|
||||
. $this->getCommonFunctions()->backquote($table);
|
||||
// Gets where clause for the query
|
||||
$where_clause = $this->_getWhereClause($table);
|
||||
// Builds complete queries
|
||||
$sql['select_columns'] = $sqlstr_select . ' * ' . $sqlstr_from . $where_clause;
|
||||
// here, I think we need to still use the COUNT clause, even for
|
||||
// VIEWs, anyway we have a WHERE clause that should limit results
|
||||
$sql['select_count'] = $sqlstr_select . ' COUNT(*) AS `count`'
|
||||
. $sqlstr_from . $where_clause;
|
||||
$sql['delete'] = $sqlstr_delete . $sqlstr_from . $where_clause;
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides where clause for bulding SQL query
|
||||
*
|
||||
* @param string $table The table name
|
||||
*
|
||||
* @return string The generated where clause
|
||||
*/
|
||||
private function _getWhereClause($table)
|
||||
{
|
||||
$where_clause = '';
|
||||
// Columns to select
|
||||
$allColumns = PMA_DBI_get_columns($GLOBALS['db'], $table);
|
||||
$likeClauses = array();
|
||||
// Based on search type, decide like/regex & '%'/''
|
||||
$like_or_regex = (($this->_criteriaSearchType == 4) ? 'REGEXP' : 'LIKE');
|
||||
$automatic_wildcard = (($this->_criteriaSearchType < 3) ? '%' : '');
|
||||
// For "as regular expression" (search option 4), LIKE won't be used
|
||||
// Usage example: If user is seaching for a literal $ in a regexp search,
|
||||
// he should enter \$ as the value.
|
||||
$this->_criteriaSearchString = $this->getCommonFunctions()->sqlAddSlashes(
|
||||
$this->_criteriaSearchString, ($this->_criteriaSearchType == 4 ? false : true)
|
||||
);
|
||||
// Extract search words or pattern
|
||||
$search_words = (($this->_criteriaSearchType > 2)
|
||||
? array($this->_criteriaSearchString) : explode(' ', $this->_criteriaSearchString));
|
||||
|
||||
foreach ($search_words as $search_word) {
|
||||
// Eliminates empty values
|
||||
if (strlen($search_word) === 0) {
|
||||
continue;
|
||||
}
|
||||
$likeClausesPerColumn = array();
|
||||
// for each column in the table
|
||||
foreach ($allColumns as $column) {
|
||||
if (! isset($this->_criteriaColumnName)
|
||||
|| strlen($this->_criteriaColumnName) == 0
|
||||
|| $column['Field'] == $this->_criteriaColumnName
|
||||
) {
|
||||
// Drizzle has no CONVERT and all text columns are UTF-8
|
||||
$column = ((PMA_DRIZZLE)
|
||||
? $this->getCommonFunctions()->backquote($column['Field'])
|
||||
: 'CONVERT(' . $this->getCommonFunctions()->backquote($column['Field'])
|
||||
. ' USING utf8)');
|
||||
$likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' '
|
||||
. "'"
|
||||
. $automatic_wildcard . $search_word . $automatic_wildcard
|
||||
. "'";
|
||||
}
|
||||
} // end for
|
||||
if (count($likeClausesPerColumn) > 0) {
|
||||
$likeClauses[] = implode(' OR ', $likeClausesPerColumn);
|
||||
}
|
||||
} // end for
|
||||
// Use 'OR' if 'at least one word' is to be searched, else use 'AND'
|
||||
$implode_str = ($this->_criteriaSearchType == 1 ? ' OR ' : ' AND ');
|
||||
if ( empty($likeClauses)) {
|
||||
// this could happen when the "inside column" does not exist
|
||||
// in any selected tables
|
||||
$where_clause = ' WHERE FALSE';
|
||||
} else {
|
||||
$where_clause = ' WHERE ('
|
||||
. implode(') ' . $implode_str . ' (', $likeClauses)
|
||||
. ')';
|
||||
}
|
||||
return $where_clause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays database search results
|
||||
*
|
||||
* @return string HTML for search results
|
||||
*/
|
||||
public function getSearchResults()
|
||||
{
|
||||
$html_output = '';
|
||||
// Displays search string
|
||||
$html_output .= '<br />'
|
||||
. '<table class="data">'
|
||||
. '<caption class="tblHeaders">'
|
||||
. sprintf(
|
||||
__('Search results for "<i>%s</i>" %s:'),
|
||||
htmlspecialchars($this->_criteriaSearchString),
|
||||
$this->_searchTypeDescription
|
||||
)
|
||||
. '</caption>';
|
||||
|
||||
$num_search_result_total = 0;
|
||||
$odd_row = true;
|
||||
// For each table selected as search criteria
|
||||
foreach ($this->_criteriaTables as $each_table) {
|
||||
// Gets the SQL statements
|
||||
$newsearchsqls = $this->_getSearchSqls($each_table);
|
||||
// Executes the "COUNT" statement
|
||||
$res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
|
||||
$num_search_result_total += $res_cnt;
|
||||
// Gets the result row's HTML for a table
|
||||
$html_output .= $this->_getResultsRow(
|
||||
$each_table, $newsearchsqls, $odd_row
|
||||
);
|
||||
$odd_row = ! $odd_row;
|
||||
} // end for
|
||||
$html_output .= '</table>';
|
||||
// Displays total number of matches
|
||||
if (count($this->_criteriaTables) > 1) {
|
||||
$html_output .= '<p>';
|
||||
$html_output .= sprintf(
|
||||
_ngettext(
|
||||
'<b>Total:</b> <i>%s</i> match',
|
||||
'<b>Total:</b> <i>%s</i> matches',
|
||||
$num_search_result_total
|
||||
),
|
||||
$num_search_result_total
|
||||
);
|
||||
$html_output .= '</p>';
|
||||
}
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides search results row with browse/delete links.
|
||||
* (for a table)
|
||||
*
|
||||
* @param string $each_table Tables on which search is to be performed
|
||||
* @param array $newsearchsqls Contains SQL queries
|
||||
* @param bool $odd_row For displaying contrasting table rows
|
||||
*
|
||||
* @return string HTML row
|
||||
*/
|
||||
private function _getResultsRow($each_table, $newsearchsqls, $odd_row)
|
||||
{
|
||||
$this_url_params = array(
|
||||
'db' => $GLOBALS['db'],
|
||||
'goto' => 'db_sql.php',
|
||||
'pos' => 0,
|
||||
'is_js_confirmed' => 0,
|
||||
);
|
||||
$res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
|
||||
// Start forming search results row
|
||||
$html_output = '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
|
||||
// Displays results count for a table
|
||||
$html_output .= '<td>';
|
||||
$html_output .= sprintf(
|
||||
_ngettext(
|
||||
'%1$s match in <strong>%2$s</strong>',
|
||||
'%1$s matches in <strong>%2$s</strong>', $res_cnt
|
||||
),
|
||||
$res_cnt, htmlspecialchars($each_table)
|
||||
);
|
||||
$html_output .= '</td>';
|
||||
// Displays browse/delete link if result count > 0
|
||||
if ($res_cnt > 0) {
|
||||
$this_url_params['sql_query'] = $newsearchsqls['select_columns'];
|
||||
$browse_result_path = 'sql.php' . PMA_generate_common_url($this_url_params);
|
||||
$html_output .= '<td><a name="browse_search" href="'
|
||||
. $browse_result_path . '" onclick="loadResult(\''
|
||||
. $browse_result_path . '\',\'' . $each_table . '\',\''
|
||||
. PMA_generate_common_url($GLOBALS['db'], $each_table) . '\',\''
|
||||
. ($GLOBALS['cfg']['AjaxEnable']) .'\');return false;" >'
|
||||
. __('Browse') . '</a></td>';
|
||||
$this_url_params['sql_query'] = $newsearchsqls['delete'];
|
||||
$delete_result_path = 'sql.php' . PMA_generate_common_url($this_url_params);
|
||||
$html_output .= '<td><a name="delete_search" href="'
|
||||
. $delete_result_path . '" onclick="deleteResult(\''
|
||||
. $delete_result_path . '\' , \''
|
||||
. sprintf(
|
||||
__('Delete the matches for the %s table?'),
|
||||
htmlspecialchars($each_table)
|
||||
)
|
||||
. '\',\'' . ($GLOBALS['cfg']['AjaxEnable']) . '\');return false;">'
|
||||
. __('Delete') . '</a></td>';
|
||||
} else {
|
||||
$html_output .= '<td> </td>'
|
||||
.'<td> </td>';
|
||||
}// end if else
|
||||
$html_output .= '</tr>';
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the main search form's html
|
||||
*
|
||||
* @param array $url_params URL parameters
|
||||
*
|
||||
* @return string HTML for selection form
|
||||
*/
|
||||
public function getSelectionForm($url_params)
|
||||
{
|
||||
$html_output = '<a id="db_search"></a>';
|
||||
$html_output .= '<form id="db_search_form"'
|
||||
. ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '')
|
||||
. ' method="post" action="db_search.php" name="db_search">';
|
||||
$html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db']);
|
||||
$html_output .= '<fieldset>';
|
||||
// set legend caption
|
||||
$html_output .= '<legend>' . __('Search in database') . '</legend>';
|
||||
$html_output .= '<table class="formlayout">';
|
||||
// inputbox for search phrase
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td>' . __('Words or values to search for (wildcard: "%"):')
|
||||
. '</td>';
|
||||
$html_output .= '<td><input type="text" name="criteriaSearchString" size="60"'
|
||||
. ' value="' . htmlspecialchars($this->_criteriaSearchString) . '" /></td>';
|
||||
$html_output .= '</tr>';
|
||||
// choices for types of search
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right vtop">' . __('Find:') . '</td>';
|
||||
$html_output .= '<td>';
|
||||
$choices = array(
|
||||
'1' => __('at least one of the words')
|
||||
. $this->getCommonFunctions()->showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'2' => __('all words')
|
||||
. $this->getCommonFunctions()->showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'3' => __('the exact phrase'),
|
||||
'4' => __('as regular expression')
|
||||
. ' ' . $this->getCommonFunctions()->showMySQLDocu('Regexp', 'Regexp')
|
||||
);
|
||||
// 4th parameter set to true to add line breaks
|
||||
// 5th parameter set to false to avoid htmlspecialchars() escaping in the label
|
||||
// since we have some HTML in some labels
|
||||
$html_output .= $this->getCommonFunctions()->getRadioFields(
|
||||
'criteriaSearchType', $choices, $this->_criteriaSearchType, true, false
|
||||
);
|
||||
$html_output .= '</td></tr>';
|
||||
// displays table names as select options
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right vtop">' . __('Inside tables:') . '</td>';
|
||||
$html_output .= '<td rowspan="2">';
|
||||
$html_output .= '<select name="criteriaTables[]" size="6" multiple="multiple">';
|
||||
foreach ($this->_tables_names_only as $each_table) {
|
||||
if (in_array($each_table, $this->_criteriaTables)) {
|
||||
$is_selected = ' selected="selected"';
|
||||
} else {
|
||||
$is_selected = '';
|
||||
}
|
||||
$html_output .= '<option value="' . htmlspecialchars($each_table) . '"'
|
||||
. $is_selected . '>'
|
||||
. str_replace(' ', ' ', htmlspecialchars($each_table))
|
||||
. '</option>';
|
||||
} // end for
|
||||
$html_output .= '</select>';
|
||||
$html_output .= '</td></tr>';
|
||||
// Displays 'select all' and 'unselect all' links
|
||||
$alter_select = '<a href="db_search.php'
|
||||
. PMA_generate_common_url(
|
||||
array_merge($url_params, array('selectall' => 1))
|
||||
)
|
||||
. '#db_search" onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', true); return false;">'
|
||||
. __('Select All') . '</a> / ';
|
||||
$alter_select .= '<a href="db_search.php'
|
||||
. PMA_generate_common_url(
|
||||
array_merge($url_params, array('unselectall' => 1))
|
||||
)
|
||||
. '#db_search" onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', false); return false;">'
|
||||
. __('Unselect All') . '</a>';
|
||||
$html_output .= '<tr><td class="right vbottom">' . $alter_select . '</td></tr>';
|
||||
// Inputbox for column name entry
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right">' . __('Inside column:') . '</td>';
|
||||
$html_output .= '<td><input type="text" name="criteriaColumnName" size="60"'
|
||||
. 'value="'
|
||||
. (! empty($this->_criteriaColumnName) ? htmlspecialchars($this->_criteriaColumnName) : '')
|
||||
. '" /></td>';
|
||||
$html_output .= '</tr>';
|
||||
$html_output .= '</table>';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '<fieldset class="tblFooters">';
|
||||
$html_output .= '<input type="submit" name="submit_search" value="'
|
||||
. __('Go') . '" id="buttonGo" />';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '</form>';
|
||||
$html_output .= $this->_getResultDivs();
|
||||
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides div tags for browsing search results and sql query form.
|
||||
*
|
||||
* @return string div tags
|
||||
*/
|
||||
private function _getResultDivs()
|
||||
{
|
||||
$html_output = '<!-- These two table-image and table-link elements display'
|
||||
. ' the table name in browse search results -->';
|
||||
$html_output .= '<div id="table-info">';
|
||||
$html_output .= '<a class="item" id="table-link" ></a>';
|
||||
$html_output .= '</div>';
|
||||
// div for browsing results
|
||||
$html_output .= '<div id="browse-results">';
|
||||
$html_output .= '<!-- this browse-results div is used to load the browse'
|
||||
. ' and delete results in the db search -->';
|
||||
$html_output .= '</div>';
|
||||
$html_output .= '<br class="clearfloat" />';
|
||||
$html_output .= '<div id="sqlqueryform">';
|
||||
$html_output .= '<!-- this sqlqueryform div is used to load the delete form in'
|
||||
. ' the db search -->';
|
||||
$html_output .= '</div>';
|
||||
$html_output .= '<!-- toggle query box link-->';
|
||||
$html_output .= '<a id="togglequerybox"></a>';
|
||||
return $html_output;
|
||||
}
|
||||
}
|
||||
@ -118,7 +118,6 @@ class PMA_TableSearch
|
||||
* @param string $table Table name
|
||||
* @param string $searchType Whether normal or zoom search
|
||||
*
|
||||
* @return New PMA_TableSearch
|
||||
*/
|
||||
public function __construct($db, $table, $searchType)
|
||||
{
|
||||
@ -132,7 +131,7 @@ class PMA_TableSearch
|
||||
$this->_geomColumnFlag = false;
|
||||
$this->_foreigners = array();
|
||||
// Loads table's information
|
||||
$this->_loadTableInfo($this->_db, $this->_table);
|
||||
$this->_loadTableInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,8 +148,6 @@ class PMA_TableSearch
|
||||
* Gets all the columns of a table along with their types, collations
|
||||
* and whether null or not.
|
||||
*
|
||||
* @return array Array containing the column list, column types, collations
|
||||
* and null constraint
|
||||
*/
|
||||
private function _loadTableInfo()
|
||||
{
|
||||
@ -396,7 +393,7 @@ EOT;
|
||||
* @param bool $in_fbs Whether we are in 'function based search'
|
||||
* @param bool $in_zoom_search_edit Whether we are in zoom search edit
|
||||
*
|
||||
* @return string HTML content for viewing foreing data and elements
|
||||
* @return string HTML content for viewing foreign data and elements
|
||||
* for search criteria input.
|
||||
*/
|
||||
private function _getInputbox($foreignData, $column_name, $column_type,
|
||||
@ -456,7 +453,7 @@ EOT;
|
||||
* Return the where clause in case column's type is ENUM.
|
||||
*
|
||||
* @param mixed $criteriaValues Search criteria input
|
||||
* @param string $func_type Search fucntion/operator
|
||||
* @param string $func_type Search function/operator
|
||||
*
|
||||
* @return string part of where clause.
|
||||
*/
|
||||
@ -501,7 +498,7 @@ EOT;
|
||||
*
|
||||
* @param mixed $criteriaValues Search criteria input
|
||||
* @param string $names Name of the column on which search is submitted
|
||||
* @param string $func_type Search fucntion/operator
|
||||
* @param string $func_type Search function/operator
|
||||
* @param bool $geom_func Whether geometry functions should be applied
|
||||
*
|
||||
* @return string part of where clause.
|
||||
@ -556,7 +553,7 @@ EOT;
|
||||
* @param string $names Name of the column on which search is submitted
|
||||
* @param string $types Type of the field
|
||||
* @param string $collations Field collation
|
||||
* @param string $func_type Search fucntion/operator
|
||||
* @param string $func_type Search function/operator
|
||||
* @param bool $unaryFlag Whether operator unary or not
|
||||
* @param bool $geom_func Whether geometry functions should be applied
|
||||
*
|
||||
|
||||
@ -1,389 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Handles database search feature
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the SQL search query
|
||||
*
|
||||
* @param string $table The table name
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
* @param string $criteriaSearchString The search word/phrase/regexp to be searched
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
*
|
||||
* @return array 3 SQL querys (for count, display and delete results)
|
||||
*
|
||||
* @todo can we make use of fulltextsearch IN BOOLEAN MODE for this?
|
||||
* PMA_backquote
|
||||
* PMA_DBI_free_result
|
||||
* PMA_DBI_fetch_assoc
|
||||
* $GLOBALS['db']
|
||||
* explode
|
||||
* count
|
||||
* strlen
|
||||
*/
|
||||
function PMA_getSearchSqls($table, $criteriaColumnName, $criteriaSearchString,
|
||||
$criteriaSearchType
|
||||
) {
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
// Statement types
|
||||
$sqlstr_select = 'SELECT';
|
||||
$sqlstr_delete = 'DELETE';
|
||||
// Table to use
|
||||
$sqlstr_from = ' FROM '
|
||||
. $common_functions->backquote($GLOBALS['db']) . '.'
|
||||
. $common_functions->backquote($table);
|
||||
// Gets where clause for the query
|
||||
$where_clause = PMA_dbSearchGetWhereClause(
|
||||
$table, $criteriaSearchString, $criteriaSearchType, $criteriaColumnName
|
||||
);
|
||||
// Builds complete queries
|
||||
$sql['select_columns'] = $sqlstr_select . ' * ' . $sqlstr_from . $where_clause;
|
||||
// here, I think we need to still use the COUNT clause, even for
|
||||
// VIEWs, anyway we have a WHERE clause that should limit results
|
||||
$sql['select_count'] = $sqlstr_select . ' COUNT(*) AS `count`'
|
||||
. $sqlstr_from . $where_clause;
|
||||
$sql['delete'] = $sqlstr_delete . $sqlstr_from . $where_clause;
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides where clause for bulding SQL query
|
||||
*
|
||||
* @param string $table The table name
|
||||
* @param integer $criteriaSearchString The search word/phrase/regexp to be searched
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
*
|
||||
* @return string The generated where clause
|
||||
*/
|
||||
function PMA_dbSearchGetWhereClause($table, $criteriaSearchString,
|
||||
$criteriaSearchType, $criteriaColumnName
|
||||
) {
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
$where_clause = '';
|
||||
// Columns to select
|
||||
$allColumns = PMA_DBI_get_columns($GLOBALS['db'], $table);
|
||||
$likeClauses = array();
|
||||
// Based on search type, decide like/regex & '%'/''
|
||||
$like_or_regex = (($criteriaSearchType == 4) ? 'REGEXP' : 'LIKE');
|
||||
$automatic_wildcard = (($criteriaSearchType < 3) ? '%' : '');
|
||||
// For "as regular expression" (search option 4), LIKE won't be used
|
||||
// Usage example: If user is seaching for a literal $ in a regexp search,
|
||||
// he should enter \$ as the value.
|
||||
$criteriaSearchString = $common_functions->sqlAddSlashes(
|
||||
$criteriaSearchString, ($criteriaSearchType == 4 ? false : true)
|
||||
);
|
||||
// Extract search words or pattern
|
||||
$search_words = (($criteriaSearchType > 2)
|
||||
? array($criteriaSearchString) : explode(' ', $criteriaSearchString));
|
||||
|
||||
foreach ($search_words as $search_word) {
|
||||
// Eliminates empty values
|
||||
if (strlen($search_word) === 0) {
|
||||
continue;
|
||||
}
|
||||
$likeClausesPerColumn = array();
|
||||
// for each column in the table
|
||||
foreach ($allColumns as $column) {
|
||||
if (! isset($criteriaColumnName)
|
||||
|| strlen($criteriaColumnName) == 0
|
||||
|| $column['Field'] == $criteriaColumnName
|
||||
) {
|
||||
// Drizzle has no CONVERT and all text columns are UTF-8
|
||||
$column = ((PMA_DRIZZLE)
|
||||
? $common_functions->backquote($column['Field'])
|
||||
: 'CONVERT(' . $common_functions->backquote($column['Field'])
|
||||
. ' USING utf8)');
|
||||
$likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' '
|
||||
. "'"
|
||||
. $automatic_wildcard . $search_word . $automatic_wildcard
|
||||
. "'";
|
||||
}
|
||||
} // end for
|
||||
if (count($likeClausesPerColumn) > 0) {
|
||||
$likeClauses[] = implode(' OR ', $likeClausesPerColumn);
|
||||
}
|
||||
} // end for
|
||||
// Use 'OR' if 'at least one word' is to be searched, else use 'AND'
|
||||
$implode_str = ($criteriaSearchType == 1 ? ' OR ' : ' AND ');
|
||||
if ( empty($likeClauses)) {
|
||||
// this could happen when the "inside column" does not exist
|
||||
// in any selected tables
|
||||
$where_clause = ' WHERE FALSE';
|
||||
} else {
|
||||
$where_clause = ' WHERE ('
|
||||
. implode(') ' . $implode_str . ' (', $likeClauses)
|
||||
. ')';
|
||||
}
|
||||
return $where_clause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays database search results
|
||||
*
|
||||
* @param array $criteriaTables Tables on which search is to be performed
|
||||
* @param string $searchTypeDescription Description for search type
|
||||
* @param string $criteriaSearchString The search word/phrase/regexp to be searched
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
*
|
||||
* @return string HTML for search results
|
||||
*/
|
||||
function PMA_dbSearchGetSearchResults($criteriaTables, $searchTypeDescription,
|
||||
$criteriaSearchString, $criteriaSearchType, $criteriaColumnName = null
|
||||
) {
|
||||
$html_output = '';
|
||||
// Displays search string
|
||||
$html_output .= '<br />'
|
||||
. '<table class="data">'
|
||||
. '<caption class="tblHeaders">'
|
||||
. sprintf(
|
||||
__('Search results for "<i>%s</i>" %s:'),
|
||||
htmlspecialchars($criteriaSearchString), $searchTypeDescription
|
||||
)
|
||||
. '</caption>';
|
||||
|
||||
$num_search_result_total = 0;
|
||||
$odd_row = true;
|
||||
// For each table selected as search criteria
|
||||
foreach ($criteriaTables as $each_table) {
|
||||
// Gets the SQL statements
|
||||
$newsearchsqls = PMA_getSearchSqls(
|
||||
$each_table, (! empty($criteriaColumnName) ? $criteriaColumnName : ''),
|
||||
$criteriaSearchString, $criteriaSearchType
|
||||
);
|
||||
// Executes the "COUNT" statement
|
||||
$res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
|
||||
$num_search_result_total += $res_cnt;
|
||||
// Gets the result row's HTML for a table
|
||||
$html_output .= PMA_dbSearchGetResultsRow(
|
||||
$each_table, $newsearchsqls, $odd_row
|
||||
);
|
||||
$odd_row = ! $odd_row;
|
||||
} // end for
|
||||
$html_output .= '</table>';
|
||||
// Displays total number of matches
|
||||
if (count($criteriaTables) > 1) {
|
||||
$html_output .= '<p>';
|
||||
$html_output .= sprintf(
|
||||
_ngettext(
|
||||
'<b>Total:</b> <i>%s</i> match',
|
||||
'<b>Total:</b> <i>%s</i> matches',
|
||||
$num_search_result_total
|
||||
),
|
||||
$num_search_result_total
|
||||
);
|
||||
$html_output .= '</p>';
|
||||
}
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides search results row with browse/delete links.
|
||||
* (for a table)
|
||||
*
|
||||
* @param string $each_table Tables on which search is to be performed
|
||||
* @param array $newsearchsqls Contains SQL queries
|
||||
* @param bool $odd_row For displaying contrasting table rows
|
||||
*
|
||||
* @return string HTML row
|
||||
*/
|
||||
function PMA_dbSearchGetResultsRow($each_table, $newsearchsqls, $odd_row)
|
||||
{
|
||||
$this_url_params = array(
|
||||
'db' => $GLOBALS['db'],
|
||||
'goto' => 'db_sql.php',
|
||||
'pos' => 0,
|
||||
'is_js_confirmed' => 0,
|
||||
);
|
||||
$res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
|
||||
// Start forming search results row
|
||||
$html_output = '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
|
||||
// Displays results count for a table
|
||||
$html_output .= '<td>';
|
||||
$html_output .= sprintf(
|
||||
_ngettext(
|
||||
'%1$s match in <strong>%2$s</strong>',
|
||||
'%1$s matches in <strong>%2$s</strong>', $res_cnt
|
||||
),
|
||||
$res_cnt, htmlspecialchars($each_table)
|
||||
);
|
||||
$html_output .= '</td>';
|
||||
// Displays browse/delete link if result count > 0
|
||||
if ($res_cnt > 0) {
|
||||
$this_url_params['sql_query'] = $newsearchsqls['select_columns'];
|
||||
$browse_result_path = 'sql.php' . PMA_generate_common_url($this_url_params);
|
||||
$html_output .= '<td><a name="browse_search" href="'
|
||||
. $browse_result_path . '" onclick="loadResult(\''
|
||||
. $browse_result_path . '\',\'' . $each_table . '\',\''
|
||||
. PMA_generate_common_url($GLOBALS['db'], $each_table) . '\',\''
|
||||
. ($GLOBALS['cfg']['AjaxEnable']) .'\');return false;" >'
|
||||
. __('Browse') . '</a></td>';
|
||||
$this_url_params['sql_query'] = $newsearchsqls['delete'];
|
||||
$delete_result_path = 'sql.php' . PMA_generate_common_url($this_url_params);
|
||||
$html_output .= '<td><a name="delete_search" href="'
|
||||
. $delete_result_path . '" onclick="deleteResult(\''
|
||||
. $delete_result_path . '\' , \''
|
||||
. sprintf(
|
||||
__('Delete the matches for the %s table?'),
|
||||
htmlspecialchars($each_table)
|
||||
)
|
||||
. '\',\'' . ($GLOBALS['cfg']['AjaxEnable']) . '\');return false;">'
|
||||
. __('Delete') . '</a></td>';
|
||||
} else {
|
||||
$html_output .= '<td> </td>'
|
||||
.'<td> </td>';
|
||||
}// end if else
|
||||
$html_output .= '</tr>';
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the main search form's html
|
||||
*
|
||||
* @param string $criteriaSearchString Keyword/Regular expression earlier entered
|
||||
* @param integer $criteriaSearchType Type of search (one word, phrase etc.)
|
||||
* @param array $tables_names_only Names of all tables
|
||||
* @param array $criteriaTables Tables on which search is to be performed
|
||||
* @param array $url_params URL parameters
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
*
|
||||
* @return string HTML for selection form
|
||||
*/
|
||||
function PMA_dbSearchGetSelectionForm($criteriaSearchString, $criteriaSearchType,
|
||||
$tables_names_only, $criteriaTables, $url_params, $criteriaColumnName = null
|
||||
) {
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
$html_output = '<a id="db_search"></a>';
|
||||
$html_output .= '<form id="db_search_form"'
|
||||
. ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '')
|
||||
. ' method="post" action="db_search.php" name="db_search">';
|
||||
$html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db']);
|
||||
$html_output .= '<fieldset>';
|
||||
// set legend caption
|
||||
$html_output .= '<legend>' . __('Search in database') . '</legend>';
|
||||
$html_output .= '<table class="formlayout">';
|
||||
// inputbox for search phrase
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td>' . __('Words or values to search for (wildcard: "%"):')
|
||||
. '</td>';
|
||||
$html_output .= '<td><input type="text" name="criteriaSearchString" size="60"'
|
||||
. ' value="' . htmlspecialchars($criteriaSearchString) . '" /></td>';
|
||||
$html_output .= '</tr>';
|
||||
// choices for types of search
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right vtop">' . __('Find:') . '</td>';
|
||||
$html_output .= '<td>';
|
||||
$choices = array(
|
||||
'1' => __('at least one of the words')
|
||||
. $common_functions->showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'2' => __('all words')
|
||||
. $common_functions->showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'3' => __('the exact phrase'),
|
||||
'4' => __('as regular expression')
|
||||
. ' ' . $common_functions->showMySQLDocu('Regexp', 'Regexp')
|
||||
);
|
||||
// 4th parameter set to true to add line breaks
|
||||
// 5th parameter set to false to avoid htmlspecialchars() escaping in the label
|
||||
// since we have some HTML in some labels
|
||||
$html_output .= $common_functions->getRadioFields(
|
||||
'criteriaSearchType', $choices, $criteriaSearchType, true, false
|
||||
);
|
||||
$html_output .= '</td></tr>';
|
||||
// displays table names as select options
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right vtop">' . __('Inside tables:') . '</td>';
|
||||
$html_output .= '<td rowspan="2">';
|
||||
$html_output .= '<select name="criteriaTables[]" size="6" multiple="multiple">';
|
||||
foreach ($tables_names_only as $each_table) {
|
||||
if (in_array($each_table, $criteriaTables)) {
|
||||
$is_selected = ' selected="selected"';
|
||||
} else {
|
||||
$is_selected = '';
|
||||
}
|
||||
$html_output .= '<option value="' . htmlspecialchars($each_table) . '"'
|
||||
. $is_selected . '>'
|
||||
. str_replace(' ', ' ', htmlspecialchars($each_table))
|
||||
. '</option>';
|
||||
} // end for
|
||||
$html_output .= '</select>';
|
||||
$html_output .= '</td></tr>';
|
||||
// Displays 'select all' and 'unselect all' links
|
||||
$alter_select = '<a href="db_search.php'
|
||||
. PMA_generate_common_url(
|
||||
array_merge($url_params, array('selectall' => 1))
|
||||
)
|
||||
. '#db_search" onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', true); return false;">'
|
||||
. __('Select All') . '</a> / ';
|
||||
$alter_select .= '<a href="db_search.php'
|
||||
. PMA_generate_common_url(
|
||||
array_merge($url_params, array('unselectall' => 1))
|
||||
)
|
||||
. '#db_search" onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', false); return false;">'
|
||||
. __('Unselect All') . '</a>';
|
||||
$html_output .= '<tr><td class="right vbottom">' . $alter_select . '</td></tr>';
|
||||
// Inputbox for column name entry
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right">' . __('Inside column:') . '</td>';
|
||||
$html_output .= '<td><input type="text" name="criteriaColumnName" size="60"'
|
||||
. 'value="'
|
||||
. (! empty($criteriaColumnName) ? htmlspecialchars($criteriaColumnName) : '')
|
||||
. '" /></td>';
|
||||
$html_output .= '</tr>';
|
||||
$html_output .= '</table>';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '<fieldset class="tblFooters">';
|
||||
$html_output .= '<input type="submit" name="submit_search" value="'
|
||||
. __('Go') . '" id="buttonGo" />';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '</form>';
|
||||
$html_output .= getResultDivs();
|
||||
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides div tags for browsing search results and sql query form.
|
||||
*
|
||||
* @return string div tags
|
||||
*/
|
||||
function getResultDivs()
|
||||
{
|
||||
$html_output = '<!-- These two table-image and table-link elements display'
|
||||
. ' the table name in browse search results -->';
|
||||
$html_output .= '<div id="table-info">';
|
||||
$html_output .= '<a class="item" id="table-link" ></a>';
|
||||
$html_output .= '</div>';
|
||||
// div for browsing results
|
||||
$html_output .= '<div id="browse-results">';
|
||||
$html_output .= '<!-- this browse-results div is used to load the browse'
|
||||
. ' and delete results in the db search -->';
|
||||
$html_output .= '</div>';
|
||||
$html_output .= '<br class="clearfloat" />';
|
||||
$html_output .= '<div id="sqlqueryform">';
|
||||
$html_output .= '<!-- this sqlqueryform div is used to load the delete form in'
|
||||
. ' the db search -->';
|
||||
$html_output .= '</div>';
|
||||
$html_output .= '<!-- toggle query box link-->';
|
||||
$html_output .= '<a id="togglequerybox"></a>';
|
||||
return $html_output;
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user