Menus.pm

filter: Statementstmt 21.4% 58 / 270 Branchbran 1.8% 2 / 108 Conditioncond 0.0% 0 / 56 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 50.0% 13 / 26 Podpod 100% 11 / 11 totaltotal 16.7% 84 / 503 CC 88 SCAR 56.2
CC
88
Cov
14%
LoadMenus
702.0
Save
342.0
_LoadMenus
306.0
CRAP 275.3
« Articles.pm ↑ Summary Users.pm »
1 package Labyrinth::Plugin::Menus;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '5.19';
7  
8 =head1 NAME
9  
10 Labyrinth::Plugin::Menus - Plugin Menus handler for Labyrinth
11  
12 =head1 DESCRIPTION
13  
14 Contains all the menu handling functionality for the Labyrinth
15 framework.
16  
17 =cut
18  
19 # menu array
20 # 0 = ?
21 # 1 = selected=1, unselected=0
22 # 2 = title
23 # 3 = href
24 # 4 = access
25 # 5 = text
26 # 6.. = images
27  
28 # -------------------------------------
29 # Library Modules
30  
31 4 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use Labyrinth::Globals;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 4 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 4 ▶use Labyrinth::Media;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 4 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 4 ▶use Labyrinth::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 4 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # -------------------------------------
43 # Constants
44  
45 4 ▶use constant MaxMenuWidth => 400;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 4 ▶use constant MaxMenuHeight => 400;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 # -------------------------------------
49 # Variables
50  
51 # type: 0 = optional, 1 = mandatory
52 # html: 0 = none, 1 = text, 2 = textarea
53  
54 4 my %fields = (
55 menuid => { type => 0, html => 0 },
56 name => { type => 1, html => 1 },
57 realmid => { type => 1, html => 0 },
58 typeid => { type => 1, html => 0 },
59 title => { type => 0, html => 1 },
60 parentid => { type => 0, html => 0 },
61 );
62  
63 4 my (@mandatory,@allfields);
64 4 for(keys %fields) {
65 24 ▶ push @mandatory, $_ if($fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $fields{$_}{"type"} 12 12 24
66 24 push @allfields, $_;
67 }
68  
69 4 my @savefields = qw(name title typeid realmid parentid);
70 4 my $INDEXKEY = 'menuid';
71 4 my $ALLSQL = 'AllMenus';
72 4 my $SAVESQL = 'SaveMenu';
73 4 my $ADDSQL = 'AddMenu';
74 4 my $GETSQL = 'GetMenuByID';
75 4 my $DELETESQL = 'DeleteMenu';
76 4 my $LEVEL = ADMIN;
77  
78 4 my %adddata = (
79 menuid => 0,
80 realmid => 0,
81 type => 0,
82 title => '',
83 name => '',
84 );
85  
86  
87 # -------------------------------------
88 # The Subs
89  
90 =head1 PUBLIC INTERFACE METHODS
91  
92 =head2 Default Methods
93  
94 =over 4
95  
96 =item LoadMenus
97  
98 Loads all the menus used within the system, and stores them within the 'menu'
99 template variable hash, using the menuid as the key to each.
100  
101 =back
102  
103 =cut
104  
105 0 ▶sub LoadMenus {
Subroutine LoadMenus: not called CC=26 SCAR=65.5
Pod documented
106 # get menu list for current realm
107 0 my @rows = $dbi->GetQuery('hash','GetMenus',RealmID($tvars{realm}));
108  
109 0 $tvars{menus} = undef; # in case we're reloading
110 0 my $request = $ENV{REQUEST_URI};
111 0 my $script = $settings{script};
112 0 my (%match,%tree);
113 # LogDebug("script=[$script]");
114  
115 # for each menu get option list
116 0 for my $row (@rows) {
117 0 $tvars{menus}->{$row->{menuid}}->{name} = $row->{name};
118 0 $tvars{menus}->{$row->{menuid}}->{title} = $row->{title};
119 0 $tvars{menus}->{$row->{menuid}}->{typeid} = $row->{typeid};
120 0 $tvars{menus}->{$row->{menuid}}->{parentid} = $row->{parentid};
121 0 my @opts = $dbi->GetQuery('hash','GetOptions',$row->{menuid});
122 0 for my $opt (@opts) {
123 0 my @images;
124 0 ▶ if($row->{typeid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"typeid"} > 1) 0 0 0
125 0 my @rs = $dbi->GetQuery('hash','GetOptImages',$opt->{optionid});
126 0 @images = map {$_->{'link'}} @rs;
127 }
128 #LogDebug("request=$request, opt=$opt->{href}");
129 #LogDebug("section=$tvars{section}, opt=$opt->{section}");
130 # try and find the selected option
131 0 ▶ my $inx = $tvars{menus}->{$row->{menuid}}->{data} ? scalar(@{$tvars{menus}->{$row->{menuid}}->{data}}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Labyrinth::Plugin::Menus::tvars{'menus'}{$row->{'menuid'}}{'data'} ? : 0 0 0
132 0 ▶ $match{request} = [$row->{menuid},$inx,$opt->{optionid}] if($request && $request eq $opt->{href});
Branch: 1 branch
BranchTrueFalseTotal
if $request and $request eq $opt->{"href"} 0 0 0
Condition0%0/3
$request and $request eq $opt->{"href"}
!ll&&!rl&&r
000
MC/DC0%0/2
$request and $request eq $opt->{"href"}
$request $request eq $opt->{"href"}
Truth table0%0/3
A and B
A= $requestB= $request eq $opt->{"href"}
ABresult
0X0
100
111
133 0 ▶ $match{section} = [$row->{menuid},$inx,$opt->{optionid}] if($opt->{section} && $tvars{section} eq $opt->{section});
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"section"} and $Labyrinth::Plugin::Menus::tvars{"section"} eq $opt->{"section"} 0 0 0
Condition0%0/3
$opt->{"section"} and $Labyrinth::Plugin::Menus::tvars{"section"} eq $opt->{"section"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->{"section"} and $Labyrinth::Plugin::Menus::tvars{"section"} eq $opt->{"section"}
$opt->{"section"} $Labyrinth::Plugin::Menus::tvars{"section"} eq $opt->{"section"}
Truth table0%0/3
A and B
A= $opt->{"section"}B= $Labyrinth::Plugin::Menus::tvars{"section"} eq $opt->{"section"}
ABresult
0X0
100
111
134 0 ▶ $match{options} = [$row->{menuid},$inx,$opt->{optionid}] if($request && $request =~ /$opt->{href}/);
Branch: 1 branch
BranchTrueFalseTotal
if $request and $request =~ /$opt->{"href"}/ 0 0 0
Condition0%0/3
$request and $request =~ /$opt->{"href"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$request and $request =~ /$opt->{"href"}/
$request $request =~ /$opt->{"href"}/
Truth table0%0/3
A and B
A= $requestB= $request =~ /$opt->{"href"}/
ABresult
0X0
100
111
135 0 ▶ $match{hideout} = [$row->{menuid},$inx,$opt->{optionid}] if($opt->{section} && ($opt->{section} eq 'home' || $opt->{href} eq '/'));
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"section"} and $opt->{"section"} eq "home" || $opt->{"href"} eq "/" 0 0 0
Condition0%0/6
$opt->{"section"} and $opt->{"section"} eq "home" || $opt->{"href"} eq "/"
!ll&&!rl&&r
000
$opt->{"section"} eq "home" or $opt->{"href"} eq "/"
l!l&&r!l&&!r
000
MC/DC0%0/3
$opt->{"section"} and $opt->{"section"} eq "home" || $opt->{"href"} eq "/"
$opt->{"section"} $opt->{"section"} eq "home" $opt->{"href"} eq "/"
Truth table0%0/4
A and B or C
A= $opt->{"section"}B= $opt->{"section"} eq "home"C= $opt->{"href"} eq "/"
ABCresult
0XX0
1000
11X1
1011
136 0 ▶ $match{default} = [$row->{menuid},$inx,$opt->{optionid}] if(!$match{default});
Branch: 1 branch
BranchTrueFalseTotal
unless $match{"default"} 0 0 0
137 0 $opt->{href} =~ s!^\?!$script\?!; # all query only links are local
138 # $opt->{href} =~ s!^/$script!$tvars{cgipath}/$script!; # all script links are local
139 0 ▶ push @{$tvars{menus}->{$row->{menuid}}->{data}},
Condition0%0/2
$opt->{'accessid'} || 0
l!l
00
MC/DC0%0/1
$opt->{'accessid'} || 0
$opt->{'accessid'}
Truth table0%0/2
A
A= $opt->{'accessid'}
Aresult
11
00
140 [ 0,0,
141 $opt->{text},
142 $opt->{href},
143 ($opt->{accessid}||0),
144 $opt->{name},
145 @images
146 0 ];
147 0 $tree{$opt->{optionid}} = { menuid => $row->{menuid}, index => scalar(@{$tvars{menus}->{$row->{menuid}}->{data}}) - 1, parent => $row->{parentid} };
148 }
149 }
150  
151 #LogDebug("match{$_}=$match{$_}[0]/$match{$_}[2]") for(qw(request section options hideout default));
152  
153 0 my $match = 'default';
154 0 ▶ if($match{request}[0]) { $match = 'request'; }
Branch: 4 branches
BranchTrueFalseTotal
if ($match{'request'}[0]) { } 0 0 0
elsif ($match{'section'}[0]) { } 0 0 0
elsif ($match{'options'}[0]) { } 0 0 0
elsif ($match{'hideout'}[0]) { } 0 0 0
155 0 elsif($match{section}[0]) { $match = 'section'; }
156 0 elsif($match{options}[0]) { $match = 'options'; }
157 0 elsif($match{hideout}[0]) { $match = 'hideout'; }
158 0 UpdateSession(optionid => $match{$match}->[2]);
159  
160 # previous/next trail
161 0 $tvars{trail2}{prev} = _trail2($match{$match},-1);
162 0 $tvars{trail2}{this} = _trail2($match{$match}, 0);
163 0 $tvars{trail2}{next} = _trail2($match{$match}, 1);
164 0 $tvars{trail1} = undef;
165  
166 # breadcrumbs trail
167 0 my $menu = 0;
168 0 my $opt = $match{$match}->[2];
169 0 $tvars{menus}->{$tree{$opt}{menuid}}->{data}->[$tree{$opt}{index}][1] = 1; # option has been selected
170  
171 # use Data::Dumper;
172 # LogDebug("opt=$opt");
173 # LogDebug("tree=".Dumper(\%tree));
174  
175 0 for(keys %tree) {
176 0 ▶ next unless(defined $opt && defined $tree{$_} && defined $tree{$_}->{parent});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt and defined $tree{$_} and defined $tree{$_}{"parent"} 0 0 0
Condition0%0/6
defined $opt and defined $tree{$_} and defined $tree{$_}{"parent"}
!ll&&!rl&&r
000
defined $opt and defined $tree{$_}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opt and defined $tree{$_} and defined $tree{$_}{"parent"}
defined $opt defined $tree{$_} defined $tree{$_}{"parent"}
Truth table0%0/4
A and B and C
A= defined $optB= defined $tree{$_}C= defined $tree{$_}{"parent"}
ABCresult
0XX0
10X0
1100
1111
177 0 ▶ $menu = $tree{$_}->{menuid} if($opt == $tree{$_}->{parent});
Branch: 1 branch
BranchTrueFalseTotal
if $opt == $tree{$_}{"parent"} 0 0 0
178 }
179  
180 0 ▶ while($opt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt) 0 0 0
181 0 $tvars{menus}->{$tree{$opt}{menuid}}->{data}->[$tree{$opt}{index}][0] = $menu; # submenu has been selected
182 0 push @{$tvars{trail1}},
183 {
184 text => $tvars{menus}->{$tree{$opt}{menuid}}->{data}->[$tree{$opt}{index}][2],
185 0 href => $tvars{menus}->{$tree{$opt}{menuid}}->{data}->[$tree{$opt}{index}][3]
186 };
187 0 $menu = $tree{$opt}{menuid};
188 0 $opt = $tree{$opt}{parent};
189 }
190 }
191  
192 0 ▶sub _trail2 {
Subroutine _trail2: not called CC=5 SCAR=34.0
193 0 my ($hash,$diff) = @_;
194 0 ▶ return unless(defined $hash && @$hash);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hash and @$hash 0 0 0
Condition0%0/3
defined $hash and @$hash
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and @$hash
defined $hash @$hash
Truth table0%0/3
A and B
A= defined $hashB= @$hash
ABresult
0X0
100
111
195  
196 0 my %hash;
197 0 my $opt = $hash->[1] + $diff;
198 0 ▶ if($opt >= 0 && $opt < scalar(@{$tvars{menus}->{$hash->[0]}->{data}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt >= 0 and $opt < scalar @{$Labyrinth::Plugin::Menus::tvars{"menus"}{$hash->[0]}{"data"};}) 0 0 0
Condition0%0/3
$opt >= 0 and $opt < scalar @{$Labyrinth::Plugin::Menus::tvars{"menus"}{$hash->[0]}{"data"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$opt >= 0 and $opt < scalar @{$Labyrinth::Plugin::Menus::tvars{"menus"}{$hash->[0]}{"data"};}
$opt >= 0 $opt < scalar @{$Labyrinth::Plugin::Menus::tvars{"menus"}{$hash->[0]}{"data"};}
Truth table0%0/3
A and B
A= $opt >= 0B= $opt < scalar @{$Labyrinth::Plugin::Menus::tvars{"menus"}{$hash->[0]}{"data"};}
ABresult
0X0
100
111
199 0 $hash{text} = $tvars{menus}->{$hash->[0]}->{data}->[$opt][2];
200 0 $hash{href} = $tvars{menus}->{$hash->[0]}->{data}->[$opt][3];
201 }
202 0 return \%hash;
203 }
204  
205 0 ▶sub _LoadMenus {
Subroutine _LoadMenus: not called CC=17 SCAR=57.2
206 # get menu list for current realm
207 0 my @rows = $dbi->GetQuery('hash','GetMenus',RealmID($tvars{realm}));
208 0 $tvars{menus} = undef; # in case we're reloading
209 0 my $request = $ENV{REQUEST_URI};
210 0 my $script = $settings{script};
211 0 my (%tree,$last,$href);
212 # LogDebug("script=[$script]");
213  
214 # for each menu get option list
215 0 for my $row (@rows) {
216 0 $tvars{menus}->{$row->{menuid}}->{name} = $row->{name};
217 0 $tvars{menus}->{$row->{menuid}}->{title} = $row->{title};
218 0 $tvars{menus}->{$row->{menuid}}->{typeid} = $row->{typeid};
219 0 $tvars{menus}->{$row->{menuid}}->{parentid} = $row->{parentid};
220 0 $last = '';
221 0 $href = '';
222 0 my @opts = $dbi->GetQuery('hash','GetOptions',$row->{menuid});
223 0 for my $opt (@opts) {
224 0 my @images;
225 0 ▶ if($row->{typeid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"typeid"} > 1) 0 0 0
226 0 my @rs = $dbi->GetQuery('hash','GetOptImages',$opt->{optionid});
227 0 @images = map {$_->{'link'}} @rs;
228 }
229 0 ▶ UpdateSession(optionid => $opt->{optionid}) if($request && $request =~ /$opt->{href}/);
Branch: 1 branch
BranchTrueFalseTotal
if $request and $request =~ /$opt->{"href"}/ 0 0 0
Condition0%0/3
$request and $request =~ /$opt->{"href"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$request and $request =~ /$opt->{"href"}/
$request $request =~ /$opt->{"href"}/
Truth table0%0/3
A and B
A= $requestB= $request =~ /$opt->{"href"}/
ABresult
0X0
100
111
230 0 $opt->{href} =~ s!^\?!$script\?!; # all query only links are local
231 # $opt->{href} =~ s!^/$script!$tvars{cgipath}/$script!; # all script links are local
232  
233 # establish the current level trail
234 0 ▶ if($tvars{trail2} && !$tvars{trail2}{'next'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::tvars{"trail2"} and not $Labyrinth::Plugin::Menus::tvars{"trail2"}{"next"}) 0 0 0
Condition0%0/3
$Labyrinth::Plugin::Menus::tvars{"trail2"} and not $Labyrinth::Plugin::Menus::tvars{"trail2"}{"next"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Labyrinth::Plugin::Menus::tvars{"trail2"} and not $Labyrinth::Plugin::Menus::tvars{"trail2"}{"next"}
$Labyrinth::Plugin::Menus::tvars{"trail2"} not $Labyrinth::Plugin::Menus::tvars{"trail2"}{"next"}
Truth table0%0/3
A and not(B)
A= $Labyrinth::Plugin::Menus::tvars{"trail2"}B= not $Labyrinth::Plugin::Menus::tvars{"trail2"}{"next"}
ABresult
0X0
100
111
235 0 $tvars{trail2}{'next'} = {text => $opt->{text}, href => $opt->{href}};
236 }
237 0 ▶ if($opt->{optionid} == $tvars{user}{option}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'optionid'} == $Labyrinth::Plugin::Menus::tvars{'user'}{'option'}) { } 0 0 0
238 $tvars{trail2} = { 'prev' => {text => $last, href => $href},
239 0 'this' => {text => $opt->{text}}};
240 } else {
241 0 $last = $opt->{text};
242 0 $href = $opt->{href};
243 }
244 0 ▶ push @{$tvars{menus}->{$row->{menuid}}->{data}}, [0,0,$opt->{text},$opt->{href},($opt->{accessid}||0),@images];
Condition0%0/2
$opt->{'accessid'} || 0
l!l
00
MC/DC0%0/1
$opt->{'accessid'} || 0
$opt->{'accessid'}
Truth table0%0/2
A
A= $opt->{'accessid'}
Aresult
11
00
245  
246 $tree{$opt->{optionid}} = {
247 minx => $row->{menuid},
248 0 oinx => (scalar(@{$tvars{menus}->{$row->{menuid}}->{data}}) - 1),
249 opar => $row->{parentid}
250 0 };
251 }
252 }
253 # use Data::Dumper;
254 # LogDebug("LoadMenus: tree=".Dumper(\%tree));
255 # now establish the main trail
256 0 ▶ if($tvars{user}{option}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::tvars{"user"}{"option"}) 0 0 0
257 0 my $option = $tvars{user}{option};
258 0 for my $opt (keys %tree) {
259 0 ▶ if($tree{$opt}->{opar} == $option) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree{$opt}{"opar"} == $option) 0 0 0
260 0 $tvars{menus}{$tree{$option}->{minx}}{data}[$tree{$option}->{oinx}][0] = $tree{$opt}->{minx};
261 0 LogDebug("LoadMenus: option=$option, opt=$opt, minx=$tree{$option}->{minx}, oinx=$tree{$option}->{oinx}, minx=$tree{$opt}->{minx}");
262 # menu has a sub menu
263 0 last;
264 }
265 }
266  
267 0 ▶ while($option) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option) 0 0 0
268 0 my $minx = $tree{$option}->{minx};
269 0 my $oinx = $tree{$option}->{oinx};
270 0 ▶ if($minx && $oinx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($minx and $oinx) 0 0 0
Condition0%0/3
$minx and $oinx
!ll&&!rl&&r
000
MC/DC0%0/2
$minx and $oinx
$minx $oinx
Truth table0%0/3
A and B
A= $minxB= $oinx
ABresult
0X0
100
111
271 0 $tvars{menus}{$minx}{data}[$oinx][1] = 1; # menu has been selected
272 0 unshift @{$tvars{trail1}}, # breadcrumbs trail
273 {text => $tvars{menus}{$minx}{data}[$oinx][2],
274 0 href => $tvars{menus}{$minx}{data}[$oinx][3]};
275 }
276 0 $option = $tree{$option}->{opar};
277 0 ▶ next unless($option);
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 0 0
278 0 my $pinx = $tree{$option}->{minx};
279 0 $oinx = $tree{$option}->{oinx};
280 0 $tvars{menus}{$pinx}{data}[$oinx][0] = $minx; # menu has this sub menu
281 }
282 }
283 }
284  
285 =head1 ADMIN INTERFACE METHODS
286  
287 =head2 Menu Methods
288  
289 =over
290  
291 =item Admin
292  
293 List current menus.
294  
295 =item Add
296  
297 Add a new menu.
298  
299 =item Edit
300  
301 Edit a given menu.
302  
303 =item Save
304  
305 Save the given menu.
306  
307 =item Delete
308  
309 Delete the given menu.
310  
311 =item DeleteOptions
312  
313 Delete the specified option(s) of a given menu.
314  
315 =item TypeSelect
316  
317 Provide a drop down list of menu option types.
318  
319 =item TypeName
320  
321 Provide the name of the given option type.
322  
323 =item ParentSelect
324  
325 Provides a drop down in order to enable multiple levels of menus and options.
326  
327 =item CheckImages
328  
329 Stores the image for a menu option state.
330  
331 =back
332  
333 =cut
334  
335 0 ▶sub Admin {
Subroutine Admin: not called CC=6 SCAR=37.4
Pod documented
336 0 ▶ return unless(AccessUser($LEVEL));
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
337  
338 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::cgiparams{"doaction"}) 0 0 0
339 0 ▶ if($cgiparams{doaction} eq 'Delete' ) { Delete(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::cgiparams{"doaction"} eq "Delete") 0 0 0
340 }
341  
342 0 my @rows = $dbi->GetQuery('hash',$ALLSQL);
343 0 for (@rows) {
344 0 $_->{type} = TypeName($_->{typeid});
345 0 $_->{realm} = RealmName($_->{realmid});
346 }
347 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
348 }
349  
350 0 ▶sub Add {
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
351 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
352 0 $tvars{data} = \%adddata;
353 0 $tvars{data}->{ddtypes} = TypeSelect();
354 0 $tvars{data}->{ddrealms} = RealmSelect();
355 0 $tvars{data}->{ddparent} = ParentSelect();
356 }
357  
358 0 ▶sub Edit {
Subroutine Edit: not called CC=9 SCAR=45.0
Pod documented
359 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
360 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, $LEVEL) 0 0 0
361  
362 0 my $script = $settings{script};
363  
364 0 my @opts = $dbi->GetQuery('hash','GetOptions',$tvars{data}->{menuid});
365 0 for my $opt (@opts) {
366 0 my @images;
367 0 ▶ if($tvars{data}->{typeid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::tvars{"data"}{"typeid"} > 1) 0 0 0
368 0 my @rs = $dbi->GetQuery('hash','GetOptImages',$opt->{optionid});
369 0 for(@rs) {
370 0 $opt->{'image' . $_->{typeid}} = $_->{'link'};
371 0 $opt->{'imageid' . $_->{typeid}} = $_->{'imageid'};
372 }
373 0 @images = map {$_->{'link'}} @rs;
374 }
375 0 $opt->{ddaccess} = AccessSelect($opt->{accessid},'ACCESS'.$opt->{optionid});
376  
377 0 my $href = $opt->{href};
378 0 $href =~ s!^\?!$script\?!; # all query only links are local
379 0 ▶ push @{$tvars{preview}->{data}}, [0,0,$opt->{text},$href,($opt->{accessid}||0),$opt->{name},@images];
Condition0%0/2
$opt->{'accessid'} || 0
l!l
00
MC/DC0%0/1
$opt->{'accessid'} || 0
$opt->{'accessid'}
Truth table0%0/2
A
A= $opt->{'accessid'}
Aresult
11
00
380 }
381 0 ▶ $tvars{data}->{options} = \@opts if(@opts);
Branch: 1 branch
BranchTrueFalseTotal
if @opts 0 0 0
382 0 $tvars{data}->{ddtypes} = TypeSelect($tvars{data}->{typeid});
383 0 $tvars{data}->{ddrealms} = RealmSelect($tvars{data}->{realmid});
384 0 $tvars{data}->{ddparent} = ParentSelect($tvars{data}->{parentid},$tvars{data}->{menuid});
385  
386 0 $tvars{preview}->{$_} = $tvars{data}->{$_} for(qw(title typeid parentid));
387 }
388  
389 0 ▶sub Save {
Subroutine Save: not called CC=18 SCAR=58.3
Pod documented
390 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
391 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, $LEVEL) 0 0 0
392  
393 0 for(keys %fields) {
394 0 ▶ if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
elsif ($fields{$_}{'html'} == 3) { } 0 0 0
395 0 elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
396 0 elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
397 }
398  
399 0 ▶ return if FieldCheck(\@allfields,\@mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@allfields, \@mandatory) 0 0 0
400  
401 0 my @fields = map {$tvars{data}->{$_}} @savefields;
402 0 ▶ if($cgiparams{$INDEXKEY}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::cgiparams{$INDEXKEY}) { } 0 0 0
403 0 $dbi->DoQuery($SAVESQL,@fields,$cgiparams{$INDEXKEY});
404 } else {
405 0 $cgiparams{$INDEXKEY} = $dbi->IDQuery($ADDSQL,@fields);
406 }
407  
408 # delete option if requested
409 0 ▶ if($cgiparams{'doaction'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::cgiparams{"doaction"}) 0 0 0
410 0 ▶ DeleteOptions() if($cgiparams{'doaction'} eq 'DeleteOption');
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Menus::cgiparams{"doaction"} eq "DeleteOption" 0 0 0
411 }
412  
413 # save options
414 0 my $order = 1;
415 0 my @opts = $dbi->GetQuery('hash','GetOptions',$tvars{data}->{menuid});
416 0 for my $opt (@opts) {
417 my @fields = (
418 $cgiparams{"ORDER" . $opt->{optionid}}, # menu order
419 $cgiparams{"NAME" . $opt->{optionid}}, # CSS code name
420 $cgiparams{"SECT" . $opt->{optionid}}, # section name
421 $cgiparams{"TEXT" . $opt->{optionid}}, # menu text
422 $cgiparams{"HREF" . $opt->{optionid}}, # menu link
423 0 ▶ ($cgiparams{"ACCESS" . $opt->{optionid}} || 0), # access level
Condition0%0/2
$Labyrinth::Plugin::Menus::cgiparams{'ACCESS' . $opt->{'optionid'}} || 0
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Menus::cgiparams{'ACCESS' . $opt->{'optionid'}} || 0
$Labyrinth::Plugin::Menus::cgiparams{'ACCESS' . $opt->{'optionid'}}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Menus::cgiparams{'ACCESS' . $opt->{'optionid'}}
Aresult
11
00
424 );
425 0 $dbi->DoQuery('SaveOption',@fields,$opt->{optionid});
426 0 $order = $opt->{orderno} + 1;
427  
428 0 my @rs = $dbi->GetQuery('hash','GetOptImages',$opt->{optionid});
429 0 my %images = map {$_->{typeid} => $_->{imageid}} @rs;
430 0 ▶ CheckImages($images{1},'IMAGEFILE',$opt->{optionid},1) if($tvars{data}->{typeid} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Menus::tvars{"data"}{"typeid"} > 1 0 0 0
431 0 ▶ CheckImages($images{2},'ROLLOVER' ,$opt->{optionid},2) if($tvars{data}->{typeid} > 2);
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Menus::tvars{"data"}{"typeid"} > 2 0 0 0
432 0 ▶ CheckImages($images{3},'SELECTED' ,$opt->{optionid},3) if($tvars{data}->{typeid} > 3);
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Menus::tvars{"data"}{"typeid"} > 3 0 0 0
433 }
434  
435 # add option if requested
436 0 ▶ if($cgiparams{'doaction'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Menus::cgiparams{"doaction"}) 0 0 0
437 0 ▶ $dbi->DoQuery('AddOption',$tvars{data}->{menuid},$order,0) if($cgiparams{'doaction'} eq 'AddOption');
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Menus::cgiparams{"doaction"} eq "AddOption" 0 0 0
438 }
439  
440 0 $tvars{thanks} = 1;
441 }
442  
443 0 ▶sub Delete {
Subroutine Delete: not called CC=3 SCAR=24.8
Pod documented
444 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
445 0 my @ids = CGIArray('LISTED');
446 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
447  
448 # remove menus
449 0 my $ids = join(",",@ids);
450 0 $dbi->DoQuery($DELETESQL,{ids=>$ids});
451 0 my @opts = $dbi->GetQuery('hash','FindOptions',{ids=>$ids});
452  
453 # remove options
454 0 $ids = join(",",map {$_->{optionid}} @opts);
455 0 $dbi->DoQuery('DeleteOptions',{ids=>$ids});
456 0 $dbi->DoQuery('DeleteOptImages',{ids=>$ids});
457 }
458  
459 0 ▶sub DeleteOptions {
Subroutine DeleteOptions: not called CC=2 SCAR=17.9
Pod documented
460 0 my @ids = CGIArray('LISTED');
461 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
462 0 my $ids = join(",",@ids);
463 0 $dbi->DoQuery('DeleteOptions',{ids=>$ids});
464 0 $dbi->DoQuery('DeleteOptImages',{ids=>$ids});
465 }
466  
467 4 my %types = (
468 1 => 'text',
469 2 => 'image',
470 3 => 'rollover',
471 4 => 'highlighted',
472 );
473 4 my @types = map {{'id'=>$_,'value'=> $types{$_}}} sort keys %types;
474  
475 0 ▶sub TypeSelect {
Subroutine TypeSelect: not called CC=2 SCAR=17.9
Pod documented
476 0 ▶ my $opt = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
477 0 DropDownRows($opt,"typeid",'id','value',@types);
478 }
479  
480 0 ▶sub TypeName {
Subroutine TypeName: not called CC=2 SCAR=17.9
Pod documented
481 0 ▶ my $id = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
482 0 return $types{$id};
483 }
484  
485 0 ▶sub ParentSelect {
Subroutine ParentSelect: not called CC=3 SCAR=24.8
Pod documented
486 0 ▶ my $oinx = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
487 0 ▶ my $minx = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
488 0 my @opts = $dbi->GetQuery('hash','GetAllOptions',$minx);
489 0 my @rows = map {{optionid => $_->{optionid}, text => "$_->{name} - $_->{text}"}} @opts;
490 0 unshift @rows, {optionid => 0, text => 'Select Parent Option'};
491 0 DropDownRows($oinx,"parentid",'optionid','text',@rows);
492 }
493  
494 0 ▶sub CheckImages {
Subroutine CheckImages: not called CC=5 SCAR=34.0
Pod documented
495 0 my ($oldid,$key,$optionid,$typeid) = @_;
496 0 my $param = $key . $optionid;
497  
498 0 ▶ return unless($cgiparams{$param});
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Menus::cgiparams{$param} 0 0 0
499  
500 0 ▶ my $maximagewidth = $settings{maxmenuwidth} || MaxMenuWidth;
Condition0%0/2
$Labyrinth::Plugin::Menus::settings{'maxmenuwidth'} || 400
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Menus::settings{'maxmenuwidth'} || 400
$Labyrinth::Plugin::Menus::settings{'maxmenuwidth'}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Menus::settings{'maxmenuwidth'}
Aresult
11
00
501 0 ▶ my $maximageheight = $settings{maxmenuheight} || MaxMenuHeight;
Condition0%0/2
$Labyrinth::Plugin::Menus::settings{'maxmenuheight'} || 400
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Menus::settings{'maxmenuheight'} || 400
$Labyrinth::Plugin::Menus::settings{'maxmenuheight'}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Menus::settings{'maxmenuheight'}
Aresult
11
00
502  
503 # my $file = CGIFile($key . $optionid);
504 0 my ($imageid) = SaveImageFile(
505 param => $key . $optionid,
506 stock => 'DRAFT'
507 );
508  
509 0 ▶ my $sqlkey = ($oldid ? 'SaveOptImage' : 'AddOptImage');
Branch: 1 branch
BranchTrueFalseTotal
$oldid ? : 0 0 0
510 0 $dbi->DoQuery($sqlkey,$imageid,$optionid,$typeid);
511 }
512  
513 4 1;
514  
515 __END__
« Articles.pm ↑ Summary Users.pm »