* Add enclair_db option to UserDB.pm. Allows logging of enclair password
[interchange.git] / code / SystemTag / selected.coretag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: selected.coretag,v 1.9 2007-03-30 23:40:49 pajamian Exp $
9
10 UserTag selected            Order        name value
11 UserTag selected            addAttr
12 UserTag selected            PosNumber    2
13 UserTag selected            Version      $Revision: 1.9 $
14 UserTag selected            Routine      <<EOR
15 # Returns ' SELECTED' when a value is present on the form
16 # Must match exactly, but NOT case-sensitive
17 sub {
18         my ($field,$value,$opt) = @_;
19         $value = '' unless defined $value;
20         my $ref = $opt->{cgi} ? $CGI::values{$field} : $::Values->{$field};
21         return ' selected="selected"' if ! length($ref) and $opt->{default};
22
23         if(! $opt->{case}) {
24                 $ref = lc($ref);
25                 $value = lc($value);
26         }
27
28         my $r = '';
29
30         return ' selected="selected"' if $ref eq $value;
31
32         if ($opt->{delimiter}) {
33                 $opt->{multiple} = 1;
34         }
35
36         if ($opt->{multiple}) {
37             
38             my $be;
39             my $ee;
40             $opt->{delimiter} = "\0" unless defined $opt->{delimiter};
41
42             if (length $opt->{delimiter}) {
43                 my $del = Vend::Interpolate::get_joiner($opt->{delimiter}, "\0");
44                 $be = '(?:^|' . $del . ')'; ;
45                 $ee = '(?:$|' . $del . ')'; ;
46             }
47             else {
48                 $be = '';
49                 $ee = '';
50             }
51
52             my $regex = qr/$be\Q$value\E$ee/;
53             return ' selected="selected"' if $ref =~ $regex;
54         }
55
56         return '';
57 }
58 EOR