File Coverage

blib/lib/Labyrinth/Plugin/Requests.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Labyrinth::Plugin::Requests;
2              
3 5     5   77752 use warnings;
  5         9  
  5         175  
4 5     5   21 use strict;
  5         5  
  5         152  
5              
6 5     5   19 use vars qw($VERSION);
  5         7  
  5         279  
7             $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     5   19 use base qw(Labyrinth::Plugin::Base);
  5         11  
  5         4870  
23              
24             use Labyrinth::Audit;
25             use Labyrinth::Globals;
26             use Labyrinth::DBUtils;
27             use Labyrinth::MLUtils;
28             use Labyrinth::Support;
29             use Labyrinth::Variables;
30              
31             # -------------------------------------
32             # Variables
33              
34             # type: 0 = optional, 1 = mandatory
35             # html: 0 = none, 1 = text, 2 = textarea
36              
37             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             my (@mandatory,@allfields);
52             for(keys %fields) {
53             push @mandatory, $_ if($fields{$_}->{type});
54             push @allfields, $_;
55             }
56              
57             my @savefields = qw(section command actions layout content onsuccess onerror onfailure secure rewrite);
58             my $INDEXKEY = 'requestid';
59             my $ALLSQL = 'AllRequests';
60             my $SAVESQL = 'SaveRequest';
61             my $ADDSQL = 'AddRequest';
62             my $GETSQL = 'GetRequestByID';
63             my $DELETESQL = 'DeleteRequests';
64             my $LEVEL = ADMIN;
65              
66             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             my %types = (
82             1 => 'off',
83             2 => 'on',
84             3 => 'either',
85             4 => 'both',
86             );
87             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             return unless(AccessUser($LEVEL));
131              
132             if($cgiparams{doaction}) {
133             if($cgiparams{doaction} eq 'Delete' ) { Delete(); }
134             }
135              
136             my @rows = $dbi->GetQuery('hash','AllRequests');
137             for(@rows) {
138             $_->{secured} = SecureName($_->{secure});
139             }
140             $tvars{data} = \@rows if(@rows);
141             }
142              
143             sub Add {
144             return unless AccessUser($LEVEL);
145             $tvars{data} = \%adddata;
146             $tvars{data}->{ddsecure} = SecureSelect($adddata{secure});
147             }
148              
149             sub Edit {
150             return unless AccessUser($LEVEL);
151             return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
152             $tvars{data}->{ddsecure} = SecureSelect($tvars{data}->{secure});
153             }
154              
155             sub Save {
156             return unless AccessUser($LEVEL);
157             return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
158              
159             for(keys %fields) {
160             if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
161             elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
162             elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
163             }
164              
165             return if FieldCheck(\@allfields,\@mandatory);
166              
167             my @fields;
168             push @fields, $tvars{data}->{$_} for(@savefields);
169             if($cgiparams{$INDEXKEY}) {
170             $dbi->DoQuery($SAVESQL,@fields,$cgiparams{$INDEXKEY});
171             } else {
172             $cgiparams{$INDEXKEY} = $dbi->IDQuery($ADDSQL,@fields);
173             }
174              
175             $tvars{thanks} = 1;
176             }
177              
178             sub Delete {
179             return unless AccessUser($LEVEL);
180             my @ids = CGIArray('LISTED');
181             return unless @ids;
182              
183             # remove requests
184             my $ids = join(",",@ids);
185             $dbi->DoQuery($DELETESQL,{ids=>$ids});
186             }
187              
188             sub SecureSelect {
189             my $opt = shift || 0;
190             DropDownRows($opt,"typeid",'id','value',@types);
191             }
192              
193             sub SecureName {
194             my $id = shift || 1;
195             return $types{$id};
196             }
197              
198             1;
199              
200             __END__