Skip to content

Commit

Permalink
Refactored the tbl_select.php and tbl_zoom_select.php code in librari…
Browse files Browse the repository at this point in the history
…es/tbl_select.lib.php

Parts refactored are:
-> Setting titles
-> getting fields list
-> setting sub-tabs
-> setting table header of QBE display
-> displaying foreign data
-> search criteria input elements
  • Loading branch information
ammaryasir committed May 31, 2011
1 parent e794690 commit c7cef3b
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 190 deletions.
14 changes: 8 additions & 6 deletions js/tbl_select.js
Expand Up @@ -22,16 +22,18 @@ $(document).ready(function() {
cache: 'false' cache: 'false'
}); });


/* /*if($('#id_flag').val()==2)
* Handle events from zoom-search page {
* $('#tbl_search_form').hide();
*/ $('#zoom_search_form').show();
$('#tableid_1').change(function() { }*/

$('#tableid_0').change(function() {
$('#zoom_search_form').submit(); $('#zoom_search_form').submit();
}) })


$('#tableid_2').change(function() { $('#tableid_1').change(function() {
$('#zoom_search_form').submit(); $('#zoom_search_form').submit();
}) })


Expand Down
240 changes: 219 additions & 21 deletions libraries/tbl_select.lib.php
Expand Up @@ -9,6 +9,54 @@
* @package phpMyAdmin * @package phpMyAdmin
*/ */


require_once 'url_generating.lib.php';



/**
* PMA_tbl_setTitle() sets the title for foreign keys display link
*
* @param $propertiesIconic Type of icon property
* @param $themeImage Icon Image
* @return string $str Value of the Title
*
*/

function PMA_tbl_setTitle($propertiesIconic,$pmaThemeImage){
if ($propertiesIconic == true) {
$str = '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
.'b_browse.png" alt="' . __('Browse foreign values') . '" title="'
. __('Browse foreign values') . '" />';

if ($propertiesIconic === 'both') {
$str .= __('Browse foreign values');
return $str;
}
} else {
return __('Browse foreign values');
}
}

/**
* PMA_tbl_getFields() gets all the fields of a table along with their types,collations and whether null or not.
*
* @uses PMA_DBI_query()
* @uses PMA_backquote()
* @uses PMA_DBI_num_rows()
* @uses PMA_DBI_fetch_assoc()
* @uses PMA_DBI_free_result()
* @uses preg_replace()
* @uses str_replace()
* @uses strncasecmp()
* @uses empty()
*
* @param $db Selected database
* @param $table Selected table
*
* @return array($fields_list,$fields_type,$fields_collation,$fields_null) Array containing the field list, field types, collations and null constatint
*
*/

function PMA_tbl_getFields($table,$db) { function PMA_tbl_getFields($table,$db) {


// Gets the list and number of fields // Gets the list and number of fields
Expand Down Expand Up @@ -51,10 +99,179 @@ function PMA_tbl_getFields($table,$db) {


} }


/* PMA_tbl_setTableHeader() sets the table header for displaying a table in query-by-example format
*
* @return HTML content, the tags and content for table header
*
*/

function PMA_tbl_setTableHeader(){

return '<thead>
<tr><th>' . __('Column') . '</th>
<th>' . __('Type') . '</th>
<th>' . __('Collation') . '</th>
<th>' . __('Operator') . '</th>
<th>' . __('Value') . '</th>
</tr>
</thead>';


}

/* PMA_tbl_getSubTabs() returns an array with necessary configrations to create sub-tabs(Table Search and Zoom Search) in the table_select page
*
* @return array $subtabs Array containing configuration (icon,text,link,id,args) of sub-tabs for Table Search and Zoom search
*
*/

function PMA_tbl_getSubTabs(){

$subtabs = array();

$subtabs['search']['icon'] = 'b_search.png';
$subtabs['search']['text'] = __('Table Search');
$subtabs['search']['link'] = 'tbl_select.php';
$subtabs['search']['id'] = 'tbl_search_id';
$subtabs['search']['args']['pos'] = 0;

$subtabs['zoom']['icon'] = 'b_props.png';
$subtabs['zoom']['link'] = 'tbl_zoom_select.php';
$subtabs['zoom']['text'] = __('Zoom Search');
$subtabs['zoom']['id'] = 'zoom_search_id';

return $subtabs;

}


/* PMA_tbl_getForeignFields_Values() creates the HTML content for: 1) Browsing foreign data for a field. 2) Creating elements for search criteria input on fields.
*
* @uses PMA_foreignDropdown
* @uses PMA_generate_common_url
* @uses isset()
* @uses is_array()
* @uses in_array()
* @uses urlencode()
* @uses str_replace()
* @uses stbstr()
*
* @param $foreigners Array of foreign keys
* @param $foreignData Foreign keys data
* @param $field Column name
* @param $tbl_fields_type Column type
* @param $i Column index
* @param $db Selected database
* @param $table Selected table
* @param $titles Selected title
* @param $foreignMaxLimit Max limit of displaying foreign elements
* @param $fields Array of search criteria inputs
*
* @return string $str HTML content for viewing foreing data and elements for search criteria input.
*
*/

function PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i, $db, $table,$titles,$foreignMaxLimit, $fields){

$str = '';

if ($foreigners && isset($foreigners[$field]) && is_array($foreignData['disp_row'])) {

// f o r e i g n k e y s
$str .= ' <select name="fields[' . $i . ']">' . "\n";
// go back to first row

// here, the 4th parameter is empty because there is no current
// value of data for the dropdown (the search page initial values
// are displayed empty)
$str .= PMA_foreignDropdown($foreignData['disp_row'],
$foreignData['foreign_field'],
$foreignData['foreign_display'],
'', $foreignMaxLimit);
$str .= ' </select>' . "\n";
} elseif ($foreignData['foreign_link'] == true) {

$str .= '<input type="text" name="fields[' . $i . '] "';
'id="field_' . md5($field) . '[' . $i .']"
class="textfield" />' ; ?>

<?php $str .= '<script type="text/javascript">';
// <![CDATA[
$str .= <<<EOT
document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?
EOT;
$str .= '' . PMA_generate_common_url($db, $table) . '&amp;field=' . urlencode($field) . '&amp;fieldkey=' . $i . '">' . str_replace("'", "\'", $titles['Browse']) . '</a>\');';
// ]]
$str .= '</script>';
?>
<?php
} elseif (strncasecmp($tbl_fields_type[$i], 'enum', 4) == 0) {
// e n u m s
$enum_value=explode(', ', str_replace("'", '', substr($tbl_fields_type[$i], 5, -1)));
$cnt_enum_value = count($enum_value);
$str .= ' <select name="fields[' . ($i) . '][]"'
.' multiple="multiple" size="' . min(3, $cnt_enum_value) . '">' . "\n";
for ($j = 0; $j < $cnt_enum_value; $j++) {
if(isset($fields[$i]) && is_array($fields[$i]) && in_array($enum_value[$j],$fields[$i])){
$str .= ' <option value="' . $enum_value[$j] . '" Selected>'
. $enum_value[$j] . '</option>';
}
else{
$str .= ' <option value="' . $enum_value[$j] . '">'
. $enum_value[$j] . '</option>';
}
} // end for
$str .= ' </select>' . "\n";
} else {
// o t h e r c a s e s
$the_class = 'textfield';
$type = $tbl_fields_type[$i];
if ($type == 'date') {
$the_class .= ' datefield';
} elseif ($type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
$the_class .= ' datetimefield';
}
if(isset($fields[$i]) && is_string($fields[$i])){
$str .= ' <input type="text" name="fields[' . $i . ']"'
.' size="40" class="' . $the_class . '" id="field_' . $i . '" value = "' . $fields[$i] . '"/>' . "\n";
}
else{
$str .= ' <input type="text" name="fields[' . $i . ']"'
.' size="40" class="' . $the_class . '" id="field_' . $i . '" />' . "\n";
}
};
return $str;

}


/* PMA_tbl_search_getWhereClause() Return the where clause for query generation based on the inputs provided.
*
* @uses PMA_backquote
* @uses PMA_sqlAddslashes
* @uses preg_match
* @uses isset()
* @uses in_array()
* @uses str_replace()
* @uses strpos()
* @uses explode()
* @uses trim()
*
* @param $fields Search criteria input
* @param $names Name of the field(column) on which search criteria is submitted
* @param $types Type of the field
* @param $collations Field collation
* @param $func_type Search fucntion/operator
* @param $unaryFlag Whether operator unary or not
*
* @return string $str HTML content for viewing foreing data and elements for search criteria input.
*
*/

function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $func_type, $unaryFlag){ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $func_type, $unaryFlag){


//Return the where clause for query generation based on the inputs provided in the tbl_select.php form

$w = '';
if($unaryFlag){ if($unaryFlag){
$fields = ''; $fields = '';
$w = PMA_backquote($names) . ' ' . $func_type; $w = PMA_backquote($names) . ' ' . $func_type;
Expand Down Expand Up @@ -128,24 +345,5 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu


return $w; return $w;
} }

function PMA_tbl_getSubTabs(){

$subtabs = array();

$subtabs['search']['icon'] = 'b_search.png';
$subtabs['search']['text'] = __('Table Search');
$subtabs['search']['link'] = 'tbl_select.php';
$subtabs['search']['id'] = 'tbl_search_id';
$subtabs['search']['args']['pos'] = 0;

$subtabs['zoom']['icon'] = 'b_props.png';
$subtabs['zoom']['link'] = 'tbl_zoom_select.php';
$subtabs['zoom']['text'] = __('Zoom Search');
$subtabs['zoom']['id'] = 'zoom_search_id';

return $subtabs;

}


?> ?>
76 changes: 6 additions & 70 deletions tbl_select.php
Expand Up @@ -21,18 +21,8 @@
$GLOBALS['js_include'][] = 'tbl_select.js'; $GLOBALS['js_include'][] = 'tbl_select.js';
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js'; $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
$GLOBALS['js_include'][] = 'jquery/timepicker.js'; $GLOBALS['js_include'][] = 'jquery/timepicker.js';
if ($GLOBALS['cfg']['PropertiesIconic'] == true) {
$titles['Browse'] = $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
'<img class="icon" width="16" height="16" src="' . $pmaThemeImage
.'b_browse.png" alt="' . __('Browse foreign values') . '" title="'
. __('Browse foreign values') . '" />';

if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
$titles['Browse'] .= __('Browse foreign values');
}
} else {
$titles['Browse'] = __('Browse foreign values');
}


/** /**
* Not selection yet required -> displays the selection form * Not selection yet required -> displays the selection form
Expand Down Expand Up @@ -72,7 +62,6 @@
// check also foreigners even if relwork is FALSE (to get // check also foreigners even if relwork is FALSE (to get
// foreign keys from innodb) // foreign keys from innodb)
$foreigners = PMA_getForeigners($db, $table); $foreigners = PMA_getForeigners($db, $table);
$flag = 1;
?> ?>


<fieldset id="fieldset_subtab"> <fieldset id="fieldset_subtab">
Expand All @@ -95,14 +84,7 @@
<fieldset id="fieldset_table_qbe"> <fieldset id="fieldset_table_qbe">
<legend><?php echo __('Do a "query by example" (wildcard: "%")') ?></legend> <legend><?php echo __('Do a "query by example" (wildcard: "%")') ?></legend>
<table class="data"> <table class="data">
<thead> <?php echo PMA_tbl_setTableHeader(); ?>
<tr><th><?php echo __('Column'); ?></th>
<th><?php echo __('Type'); ?></th>
<th><?php echo __('Collation'); ?></th>
<th><?php echo __('Operator'); ?></th>
<th><?php echo __('Value'); ?></th>
</tr>
</thead>
<tbody> <tbody>
<?php <?php
$odd_row = true; $odd_row = true;
Expand Down Expand Up @@ -151,54 +133,9 @@


$foreignData = PMA_getForeignData($foreigners, $field, false, '', ''); $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');


if ($foreigners && isset($foreigners[$field]) && is_array($foreignData['disp_row'])) { echo PMA_getForeignFields_Values($foreigners, $foreignData, $field, $fields_type, $i, $db, $table, $titles,$GLOBALS['cfg']['ForeignKeyMaxLimit'], '' );
// f o r e i g n k e y s
echo ' <select name="fields[' . $i . ']">' . "\n"; ?>
// go back to first row

// here, the 4th parameter is empty because there is no current
// value of data for the dropdown (the search page initial values
// are displayed empty)
echo PMA_foreignDropdown($foreignData['disp_row'],
$foreignData['foreign_field'],
$foreignData['foreign_display'],
'', $GLOBALS['cfg']['ForeignKeyMaxLimit']);
echo ' </select>' . "\n";
} elseif ($foreignData['foreign_link'] == true) {
?>
<input type="text" name="fields[<?php echo $i; ?>]"
id="field_<?php echo md5($field); ?>[<?php echo $i; ?>]"
class="textfield" />
<script type="text/javascript">
// <![CDATA[
document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&amp;field=<?php echo urlencode($field); ?>&amp;fieldkey=<?php echo $i; ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
// ]]>
</script>
<?php
} elseif (strncasecmp($fields_type[$i], 'enum', 4) == 0) {
// e n u m s
$enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1)));
$cnt_enum_value = count($enum_value);
echo ' <select name="fields[' . $i . '][]"'
.' multiple="multiple" size="' . min(3, $cnt_enum_value) . '">' . "\n";
for ($j = 0; $j < $cnt_enum_value; $j++) {
echo ' <option value="' . $enum_value[$j] . '">'
. $enum_value[$j] . '</option>';
} // end for
echo ' </select>' . "\n";
} else {
// o t h e r c a s e s
$the_class = 'textfield';
$type = $fields_type[$i];
if ($type == 'date') {
$the_class .= ' datefield';
} elseif ($type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
$the_class .= ' datetimefield';
}
echo ' <input type="text" name="fields[' . $i . ']"'
.' size="40" class="' . $the_class . '" id="field_' . $i . '" />' . "\n";
};
?>
<input type="hidden" name="names[<?php echo $i; ?>]" <input type="hidden" name="names[<?php echo $i; ?>]"
value="<?php echo htmlspecialchars($fields_list[$i]); ?>" /> value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
<input type="hidden" name="types[<?php echo $i; ?>]" <input type="hidden" name="types[<?php echo $i; ?>]"
Expand Down Expand Up @@ -285,7 +222,6 @@ class="textfield" />
</fieldset> </fieldset>


<?php <?php
print_r($inputs);
} }




Expand Down

0 comments on commit c7cef3b

Please sign in to comment.