blib/lib/Labyrinth/Plugin/Requests.pm

filter: Statementstmt 56.9% 49 / 86 Branchbran 5.8% 2 / 34 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.8% 10 / 17 Podpod 100% 7 / 7 totaltotal 45.3% 68 / 150 SCAR 47.9
CC
22
Cov
41%
Save
110.0
Admin
42.0
Edit
12.0
CRAP 120.8
↑ Summary
1 package Labyrinth::Plugin::Requests;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 $VERSION = '1.07';
8  
9 =head1 NAME
10  
11 Labyrinth::Plugin::Requests - Requests handler for the Labyrinth framework.
12  
13 =head1 DESCRIPTION
14  
15 Contains all the request administration functionality for Labyrinth.
16  
17 =cut
18  
19 # -------------------------------------
20 # Library Modules
21  
22 5 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use Labyrinth::Globals;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 # -------------------------------------
32 # Variables
33  
34 # type: 0 = optional, 1 = mandatory
35 # html: 0 = none, 1 = text, 2 = textarea
36  
37 5 my %fields = (
38 requestid => { type => 0, html => 1 },
39 section => { type => 1, html => 1 },
40 command => { type => 1, html => 1 },
41 actions => { type => 0, html => 1 },
42 layout => { type => 0, html => 1 },
43 content => { type => 0, html => 1 },
44 onsuccess => { type => 0, html => 1 },
45 onerror => { type => 0, html => 1 },
46 onfailure => { type => 0, html => 1 },
47 secure => { type => 0, html => 1 },
48 rewrite => { type => 0, html => 1 },
49 );
50  
51 5 my (@mandatory,@allfields);
52 5 for(keys %fields) {
53 55 ▶ push @mandatory, $_ if($fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $fields{$_}{"type"} 10 45 55
54 55 push @allfields, $_;
55 }
56  
57 5 my @savefields = qw(section command actions layout content onsuccess onerror onfailure secure rewrite);
58 5 my $INDEXKEY = 'requestid';
59 5 my $ALLSQL = 'AllRequests';
60 5 my $SAVESQL = 'SaveRequest';
61 5 my $ADDSQL = 'AddRequest';
62 5 my $GETSQL = 'GetRequestByID';
63 5 my $DELETESQL = 'DeleteRequests';
64 5 my $LEVEL = ADMIN;
65  
66 5 my %adddata = (
67 section => '',
68 command => '',
69 actions => '',
70 layout => '',
71 content => '',
72 onsuccess => '',
73 onerror => '',
74 onfailure => '',
75 secure => 1,
76 rewrite => '',
77 );
78  
79 # security types
80  
81 5 my %types = (
82 1 => 'off',
83 2 => 'on',
84 3 => 'either',
85 4 => 'both',
86 );
87 5 my @types = map {{'id'=>$_,'value'=> $types{$_}}} sort keys %types;
88  
89  
90 # -------------------------------------
91 # Admin Methods
92  
93 =head1 ADMIN INTERFACE METHODS
94  
95 =over 4
96  
97 =item Admin
98  
99 Handle main administrive duties, and display requests admin page.
100  
101 =item Add
102  
103 Add a request.
104  
105 =item Edit
106  
107 Edit a request.
108  
109 =item Save
110  
111 Save a request.
112  
113 =item Delete
114  
115 Delete one or more requests.
116  
117 =item SecureSelect
118  
119 Security selection box. This denotes whether request requires SSL.
120  
121 =item SecureName
122  
123 Give an id, returns the security status.
124  
125 =back
126  
127 =cut
128  
129 sub Admin {
130 0 ▶ return unless(AccessUser($LEVEL));
Subroutine Admin: not called CC=6 SCAR=37.4
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
131  
132 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Requests::cgiparams{"doaction"}) 0 0 0
133 0 ▶ if($cgiparams{doaction} eq 'Delete' ) { Delete(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Requests::cgiparams{"doaction"} eq "Delete") 0 0 0
134 }
135  
136 0 my @rows = $dbi->GetQuery('hash','AllRequests');
137 0 for(@rows) {
138 0 $_->{secured} = SecureName($_->{secure});
139 }
140 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
141 }
142  
143 sub Add {
144 0 ▶ return unless AccessUser($LEVEL);
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
145 0 $tvars{data} = \%adddata;
146 0 $tvars{data}->{ddsecure} = SecureSelect($adddata{secure});
147 }
148  
149 sub Edit {
150 0 ▶ return unless AccessUser($LEVEL);
Subroutine Edit: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
151 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, $LEVEL) 0 0 0
152 0 $tvars{data}->{ddsecure} = SecureSelect($tvars{data}->{secure});
153 }
154  
155 sub Save {
156 0 ▶ return unless AccessUser($LEVEL);
Subroutine Save: not called CC=10 SCAR=47.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
157 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, $LEVEL) 0 0 0
158  
159 0 for(keys %fields) {
160 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
161 0 elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
162 0 elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
163 }
164  
165 0 ▶ return if FieldCheck(\@allfields,\@mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@allfields, \@mandatory) 0 0 0
166  
167 0 my @fields;
168 0 push @fields, $tvars{data}->{$_} for(@savefields);
169 0 ▶ if($cgiparams{$INDEXKEY}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Requests::cgiparams{$INDEXKEY}) { } 0 0 0
170 0 $dbi->DoQuery($SAVESQL,@fields,$cgiparams{$INDEXKEY});
171 } else {
172 0 $cgiparams{$INDEXKEY} = $dbi->IDQuery($ADDSQL,@fields);
173 }
174  
175 0 $tvars{thanks} = 1;
176 }
177  
178 sub Delete {
179 0 ▶ return unless AccessUser($LEVEL);
Subroutine Delete: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
180 0 my @ids = CGIArray('LISTED');
181 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
182  
183 # remove requests
184 0 my $ids = join(",",@ids);
185 0 $dbi->DoQuery($DELETESQL,{ids=>$ids});
186 }
187  
188 sub SecureSelect {
189 0 ▶ my $opt = shift || 0;
Subroutine SecureSelect: not called CC=2 SCAR=17.9
Pod documented
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
190 0 DropDownRows($opt,"typeid",'id','value',@types);
191 }
192  
193 sub SecureName {
194 0 ▶ my $id = shift || 1;
Subroutine SecureName: not called CC=2 SCAR=17.9
Pod documented
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
195 0 return $types{$id};
196 }
197  
198 5 1;
199  
200 __END__
201  
202 =head1 SEE ALSO
203  
204 L<Labyrinth>
205  
206 =head1 AUTHOR
207  
208 Barbie, <barbie@missbarbell.co.uk> for
209 Miss Barbell Productions, L<http://www.missbarbell.co.uk/>
210  
211 =head1 COPYRIGHT & LICENSE
212  
213 Copyright (C) 2002-2015 Barbie for Miss Barbell Productions
214 All Rights Reserved.
215  
216 This distribution is free software; you can redistribute it and/or
217 modify it under the Artistic License 2.0.
218  
219 =cut
↑ Summary