1 # Copyright 2002-2007 Interchange Development Group and others
2 # Copyright 2002-2005 Stefan Hornburg (racke@linuxia.de)
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version. See the LICENSE file for details.
9 # $Id: formel.tag,v 1.19 2007-08-01 10:52:44 kwalsh Exp $
11 UserTag formel Order label name type size
12 UserTag formel addAttr
13 UserTag formel Version $Revision: 1.19 $
14 UserTag formel Routine <<EOF
16 my ($label, $name, $type, $size, $opt) = @_;
17 my ($labelhtml, $elhtml, $fmt);
18 my $checkfor = $opt->{'checkfor'} || $name;
23 my ($label, $keep) = @_;
27 if ($error = $Tag->error({name => $checkfor, keep => 1})) {
28 $label .= $Tag->error({name => $checkfor, keep => $keep,
29 text => $opt->{cause}});
33 $error = $Tag->error({name => $checkfor, keep => $keep});
38 sprintf($opt->{signal}, $label);
41 my $contrast = $::Variable->{CSS_CONTRAST} || 'mv_contrast';
42 qq{<span class="$contrast">$label</span>};
51 $type = 'text' unless $type;
53 for ('cause', 'format', 'order', 'reset', 'signal', 'size') {
55 if ($::Values->{"mv_formel_$_"}) {
56 $opt->{$_} = $::Values->{"mv_formel_$_"};
60 if ($opt->{'format'}) {
61 $fmt = $opt->{'format'};
68 if ($type eq 'textarea') {
69 my ($cols, $rows) = split (/\s*[,x\s]\s*/, $opt->{'size'});
70 $sizestr = qq{ rows="$rows" cols="$cols"};
73 $sizestr = qq{ size="$opt->{size}"};
77 if ($opt->{'maxlength'}) {
78 $sizestr .= qq{ maxlength="$opt->{maxlength}"};
81 if ($type eq 'radio' || $type eq 'checkbox') {
82 my ($rlabel, $rvalue, $select, @vals);
84 if ($type eq 'checkbox') {
85 @vals = split(/\0/, $::Values->{$name});
88 for my $button (split (/\s*,\s*/, $opt->{choices})) {
90 if ($button =~ /^(.*?)=(.*)$/) {
95 $rvalue = $rlabel = $button;
98 if ($type eq 'checkbox') {
99 # multiple values possible for checkboxes
100 for my $val (@vals) {
101 if ($val eq $rvalue) {
106 } elsif ($::Values->{$name} eq $rvalue) {
107 $select = ' checked';
110 $rlabel = &$labelproc($rlabel, 1);
112 $elhtml .= qq{<input type="$type" name="$name" value="${rvalue}"$select $Vend::Xtrailer> $rlabel};
114 # delete error implicitly
115 $labelhtml = &$labelproc($label);
116 return sprintf ($fmt, $labelhtml, $elhtml);
119 $labelhtml = &$labelproc($label) if $label || $type ne 'display';
121 if ($type eq 'select') {
122 my ($rlabel, $rvalue, $select);
124 for my $option (split (/\s*,\s*/, $opt->{choices})) {
126 if ($option =~ /^(.*?)=(.*)$/) {
131 $rvalue = $rlabel = $option;
134 if ($::Values->{$name} eq $rvalue) {
135 $select = ' selected="selected"';
137 if ($rvalue eq $rlabel) {
138 $elhtml .= qq{<option $select>$rlabel</option>};
141 $elhtml .= qq{<option value="$rvalue"$select>$rlabel</option>};
144 return sprintf ($fmt, $labelhtml,
145 qq{<select name="$name">$elhtml</select>});
148 if ($type eq 'display') {
151 $elhtml = $Tag->display($opt->{table} || 'products', $name, '',
152 {value => $Values->{$name}});
155 # use dummy template to retrieve label from metadata
156 $elhtml = $Tag->display($opt->{table} || 'products', $name, '',
157 {value => $Values->{$name},
158 template => join(" \0", '$LABEL$', '$WIDGET$')});
159 ($label, $elhtml) = split(/\s\0/, $elhtml);
160 $labelhtml = &$labelproc($label);
162 } elsif ($opt->{reset}) {
163 if ($type eq 'textarea') {
164 $elhtml = qq{<textarea name="${name}"$sizestr></textarea>};
167 $elhtml = qq{<input type="$type" name="${name}"$sizestr $Vend::Xtrailer>};
171 if ($type eq 'textarea') {
172 $elhtml = qq{<textarea name="${name}"$sizestr>$::Values->{$name}</textarea>};
175 elsif ($type eq 'text' || $type eq 'password' || $type !~ /\S/) {
176 $elhtml = qq{<input type="$type" name="$name" value="$::Values->{$name}"$sizestr $Vend::Xtrailer>};
179 # pass type directly to display tag
181 $fmt = sprintf($fmt, '$WIDGET$', '$LABEL$', $opt->{help});
183 $fmt = sprintf($fmt, '$LABEL$', '$WIDGET$', $opt->{help});
186 return $Tag->display({name => $name,
189 value => $Values->{$name},
195 # display form element first
196 sprintf ($fmt, $elhtml, $labelhtml, $opt->{help});
199 # display label first
200 sprintf ($fmt, $labelhtml, $elhtml, $opt->{help});