Support for customizing foreign-key dropdown, take #2, now very customizable,

incl max item limit.
This commit is contained in:
Robin Johnson
2005-06-23 14:16:33 +00:00
parent b27fd27f89
commit 131866b448
6 changed files with 185 additions and 164 deletions

306
ChangeLog

File diff suppressed because it is too large Load Diff

View File

@@ -266,7 +266,13 @@ $cfg['CharEditing'] = 'input';
// input - allows limiting of input length
// textarea - allows newlines in fields
$cfg['InsertRows'] = 2; // How many rows can be inserted at one time
$cfg['InsertDropdownOrder'] = FALSE; // Ordering for elements in dropdown.
$cfg['ForeignKeyDropdownOrder'] = array(
'content-id'
//,
//'id-content'
); // Sort order for items in a foreign-key dropdown box.
$cfg['ForeignKeyMaxLimit'] = 100; // If less items than this exist, a dropdown will be used.
// For the export features...
$cfg['ZipDump'] = TRUE; // Allow the use of zip/gzip/bzip

View File

@@ -27,7 +27,7 @@ if ($foreigners && isset($foreigners[$field])) {
$the_total = PMA_countRecords($foreign_db, $foreign_table, TRUE);
if ((isset($override_total) && $override_total == true) || $the_total < 200) {
if ((isset($override_total) && $override_total == true) || $the_total < $cfg['ForeignKeyMaxLimit']) {
// foreign_display can be FALSE if no display field defined:
$foreign_display = PMA_getDisplayField($foreign_db, $foreign_table);

View File

@@ -793,7 +793,7 @@ function PMA_purgeHistory($username) {
*
* @access public
*/
function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $max = 100) {
function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $max) {
global $cfg;
$ret = '<option value=""></option>' . "\n";
@@ -836,22 +836,27 @@ function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $ma
asort($reloptions['content-id']);
}
if ($cfg['InsertDropdownOrder']) {
$top = $reloptions['content-id'];
$bot = $reloptions['id-content'];
$c = count($cfg['ForeignKeyDropdownOrder']);
if($c == 2) {
$top = $reloptions[$cfg['ForeignKeyDropdownOrder'][0]];
$bot = $reloptions[$cfg['ForeignKeyDropdownOrder'][1]];
} elseif($c == 1) {
$bot = $reloptions[$cfg['ForeignKeyDropdownOrder'][0]];
$top = NULL;
} else {
$top = $reloptions['id-content'];
$bot = $reloptions['content-id'];
}
$str_top = implode('', $top);
$str_bot = implode('', $bot);
$top_count = count($top);
if ($max == -1 || $top_count < $max) {
$ret .= $str_top;
if ($top_count > 0) {
$ret .= '<option value=""></option>' . "\n";
$ret .= '<option value=""></option>' . "\n";
if($top !== NULL) {
$str_top = implode('', $top);
$top_count = count($top);
if ($max == -1 || $top_count < $max) {
$ret .= $str_top;
if ($top_count > 0) {
$ret .= '<option value=""></option>' . "\n";
$ret .= '<option value=""></option>' . "\n";
}
}
}
$ret .= $str_bot;

View File

@@ -550,7 +550,7 @@ foreach ($loop_array AS $vrowcount => $vrow) {
<input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
<input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo $idindex; ?>_1" />
<select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3">
<?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, 100); ?>
<?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, $cfg['ForeignKeyMaxLimit']); ?>
</select>
</td>
<?php

View File

@@ -286,7 +286,7 @@ function PMA_tbl_select_operator(f, index, multiple) {
// 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($disp_row, $foreign_field, $foreign_display, '', 100);
echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, '', $cfg['ForeignKeyMaxLimit']);
echo ' </select>' . "\n";
} else if (isset($foreign_link) && $foreign_link == true) {
?>