use of ui_select in sendmail/access-lib.pl

Help
2014-02-28
2014-02-28
  • I am attempting to setup a different set of defaults for the Spam Control page. I am stumped using ui_select.
    The current code for the Mail source select list is:

    # Mail source
    local $src = $v->{'from'} =~ /^\S+\@\S+$/ ? 0 :
             $v->{'from'} =~ /^[0-9\.]+$/ ? 1 :
             $v->{'from'} =~ /^\S+\@$/ ? 2 :
             $v->{'from'} =~ /^[A-z0-9\-\.]+$/ ? 3 : 0;
    print &ui_table_row($text{'sform_source'},
        &ui_select("from_type", $src,[ map { [ $_, $text{"sform_type$_"} ] } (0 .. 3) ])
        ."\n".
        &ui_textbox("from", $v->{'from'}, 25));
    

    which produces:

    <tr class='ui_table_row'>
    <td valign=top  class='ui_label'><b>Mail source</b></td>
    <td valign=top colspan=1  class='ui_value'><select class='ui_select' name="from_type">
    <option value="0" selected>Email Address</option>
    <option value="1">Network</option>
    <option value="2">User</option>
    <option value="3">Domain</option>
    </select>
    
    <input class='ui_textbox' type='text' name="from" value="" size=25></td>
    </tr>
    

    I simply want to have the second list item selected, Network:

    <tr class='ui_table_row'>
    <td valign=top  class='ui_label'><b>Mail source</b></td>
    <td valign=top colspan=1  class='ui_value'><select class='ui_select' name="from_type">
    <option value="0">Email Address</option>
    <option value="1" selected >Network</option>
    <option value="2">User</option>
    <option value="3">Domain</option>
    </select>
    
    <input class='ui_textbox' type='text' name="from" value="" size=25></td>
    </tr>
    

    I think I have to modify the map statement in the options argument of ui_select, but the perl is much too dense for me.
    Any Suggestions?

    For reference ui_select:

    sub ui_select
    {
    return &theme_ui_select(@_) if (defined(&theme_ui_select));
    my ($name, $value, $opts, $size, $multiple, $missing, $dis, $tags) = @_;
    my $rv;
    $rv .= "<select class='ui_select' name=\"".&quote_escape($name)."\"".
           ($size ? " size=$size" : "").
           ($multiple ? " multiple" : "").
           ($dis ? " disabled=true" : "").($tags ? " ".$tags : "").">\n";
    my ($o, %opt, $s);
    my %sel = ref($value) ? ( map { $_, 1 } @$value ) : ( $value, 1 );
    foreach $o (@$opts) {
        $o = [ $o ] if (!ref($o));
        $rv .= "<option value=\"".&quote_escape($o->[0])."\"".
               ($sel{$o->[0]} ? " selected" : "").($o->[2] ne '' ? " ".$o->[2] : "").">".
               ($o->[1] || $o->[0])."</option>\n";
        $opt{$o->[0]}++;
        }
    foreach $s (keys %sel) {
        if (!$opt{$s} && $missing) {
            $rv .= "<option value=\"".&quote_escape($s)."\"".
                   " selected>".($s eq "" ? "&nbsp;" : $s)."</option>\n";
            }
        }
    $rv .= "</select>\n";
    return $rv;
    }