* Add enclair_db option to UserDB.pm. Allows logging of enclair password
[interchange.git] / dist / standard / config / breadcrumbs.tag
1 # Copyright 2004-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: breadcrumbs.tag,v 1.5 2007-08-09 13:40:53 pajamian Exp $
9
10 UserTag breadcrumbs Order number
11 UserTag breadcrumbs addAttr
12 UserTag breadcrumbs Routine <<EOR
13 sub {
14         my ($number, $opt) = @_;
15
16         use vars qw/$Tag $Scratch $CGI $Session $Variable/;
17         my $only_last = $::Variable->{BREADCRUMB_ONLY_LAST} || 'ord/basket login';
18         my $exclude   = $::Variable->{BREADCRUMB_EXCLUDE};
19         my $max   = $number || $::Variable->{BREADCRUMB_MAX} || 6;
20
21         my %exclude;
22         my %only_last;
23
24         my @exclude = split /[\s,\0]+/, $exclude;
25         my @only_last = split /[\s,\0]+/, $only_last;
26         @exclude{@exclude} = @exclude;
27         @only_last{@only_last} = @only_last;
28
29         my $curpage = $Global::Variable->{MV_PAGE};
30         my $titles = $Scratch->{bc_titles} ||= {};
31
32         my %special = (
33                 scan => sub { 
34                         my $url = shift;
35                         my @items = split m{/}, $url;
36
37                         my $title;
38                         for(@items) {
39                                 if(s/^se=//) {
40                                         $title = $_;
41                                 }
42                                 elsif(s/^va=banner_text=//) {
43                                         $title = $_;
44                                 }
45                         }
46                         return ($title, $title);
47                 },
48         );
49
50         my $curhist   = $Session->{History}->[-1] || [];
51         my $curparams = $curhist->[1] || {};
52
53         my $keyname;
54
55         my $curfull = $curhist->[0];
56         $curfull =~ s/$Vend::Cfg->{HTMLsuffix}$//;
57         $curfull =~ s{^/}{};
58         my ($curaction,$curpath) = split m{/}, $curfull, 2;
59
60         my $ptitle = $opt->{title} || $curparams->{short_title};
61         $ptitle ||= $Scratch->{short_title};
62
63         my $db;
64
65         my @extra;
66
67         if($special{$curaction} and ! $ptitle) {
68                 ($ptitle, $keyname) = $special{$curaction}->($curpath);
69         }
70         elsif(
71                         $Vend::Flypart
72                                 and
73                         $db = Vend::Data::product_code_exists_ref($Vend::Flypart)
74                 )
75         {
76                 my $tab = $db->name();
77                 my $record = tag_data($tab, undef, $Vend::Flypart, { hash => 1});
78                 $ptitle = $keyname = $record->{$Vend::Cfg->{DescriptionField}};
79
80                 if($record and $record->{prod_group}) {
81                         my @parms;
82                         push @parms, "fi=$tab";
83                         push @parms, "co=yes";
84                         push @parms, "st=db";
85                         push @parms, "sf=prod_group";
86                         push @parms, "se=$record->{prod_group}";
87                         push @parms, "op=eq";
88                         push @extra, {
89                                 key => $record->{prod_group},
90                                 title => $record->{prod_group},
91                                 description => undef,
92                                 url => $Tag->area({ search => join("\n", @parms) }),
93                         };
94                 }
95                 if($record and $record->{category}) {
96                         my @parms;
97                         push @parms, "fi=$tab";
98                         push @parms, "co=yes";
99                         push @parms, "st=db";
100                         if($record->{prod_group}) {
101                                 push @parms, "sf=prod_group";
102                                 push @parms, "se=$record->{prod_group}";
103                                 push @parms, "op=eq";
104                         }
105                         push @parms, "sf=category";
106                         push @parms, "se=$record->{category}";
107                         push @parms, "op=eq";
108                         push @extra, {
109                                 key => $record->{category},
110                                 title => $record->{category},
111                                 description => undef,
112                                 url => $Tag->area({ search => join "\n", @parms }),
113                         };
114                 }
115         }
116
117         if(! $ptitle) {
118                 $ptitle = $Scratch->{page_title};
119                 $ptitle =~ s/(\s*\W+\s*)?$Variable->{COMPANY}(\s*\W+\s*)?//;
120         }
121
122         $ptitle =~ s/^\s+//;
123         $ptitle =~ s/\s+$//;
124
125         $keyname ||= $curpage;
126
127         $titles->{$curpage} = $ptitle if $ptitle;
128
129         my %exclude_param = qw(
130                 mv_pc 1
131                 bread_reset 1
132         );
133
134         if($Scratch->{bread_reset} || $CGI->{bread_reset}) {
135                 delete $Session->{breadcrumbs};
136         }
137
138         my $crumbs = $Session->{breadcrumbs} ||= [];
139         my $crumb;
140
141         if($opt->{reset_on_product} and @extra) {
142 #::logDebug("Resetting based on product");
143                 @$crumbs = ();
144         }
145
146         if(! $exclude{$curpage}) {
147                 my $form = '';
148                 if(! $CGI->{bread_no_params}) {
149                         for(grep !$exclude_param{$_}, keys %$curparams) {
150                                  $form .= "\n$_=";
151                                  $form .= join("\n$_=", split /\0/, $curparams->{$_});
152                         }
153                 }
154                 $crumb = {
155                         key => $keyname,
156                         title => HTML::Entities::encode($ptitle),
157                         description => HTML::Entities::encode($Scratch->{page_description}),
158                         url => $Tag->area({ href => $curfull, form => $form, secure => $CGI->{secure} }),
159                 };
160         }
161
162         push @$crumbs, @extra if @extra;
163         push @$crumbs, $crumb if $crumb;
164         
165         my %seen;
166         my @new = grep !$seen{$_->{key}}++, reverse @$crumbs;
167         
168         my $did_one;
169         for(@new) {
170                 ## Kill ones that only are allowed in last position
171                 if( $did_one and $only_last{$_->{key}}) {
172                         $_ = undef;
173                 }
174                 $did_one = 1;
175         }
176
177         if(@new > $max) {
178                 splice @new, $max;
179         }
180
181         @$crumbs = grep $_, reverse @new;
182
183         my $tpl = $opt->{template} || <<EOF;
184 <a href="{url}"{description?} title="{description}"{/description?} class=breadlink>{title}</a>
185 EOF
186
187         my @out;
188         for(@$crumbs) {
189                 next unless ref($_) eq 'HASH' and $_->{url};
190                 my $link = tag_attr_list($tpl, $_);
191 #::logDebug("link=$link from:\ntpl=$tpl\ncrumb=" . ::uneval($_));
192                 push @out, $link;
193         }
194
195         $opt->{joiner} = '&nbsp;&gt;&nbsp;' unless defined $opt->{joiner};
196         return join $opt->{joiner}, @out;
197 }
198 EOR