File Coverage

blib/lib/Labyrinth/Plugin/Folders.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Labyrinth::Plugin::Folders;
2              
3 2     2   6703 use warnings;
  2         4  
  2         61  
4 2     2   8 use strict;
  2         2  
  2         88  
5              
6             our $VERSION = '5.19';
7              
8             =head1 NAME
9              
10             Labyrinth::Plugin::Folders - handler for Labyrinth folders
11              
12             =head1 DESCRIPTION
13              
14             Contains all the folder handling functionality for the Labyrinth
15             framework.
16              
17             =cut
18              
19             # -------------------------------------
20             # Library Modules
21              
22 2     2   8 use base qw(Labyrinth::Plugin::Base);
  2         2  
  2         819  
23              
24             use Labyrinth::DBUtils;
25             use Labyrinth::MLUtils;
26             use Labyrinth::Support;
27             use Labyrinth::Variables;
28              
29             # -------------------------------------
30             # Variables
31              
32             # type: 0 = optional, 1 = mandatory
33             # html: 0 = none, 1 = text, 2 = textarea
34              
35             my %fields = (
36             folderid => { type => 0, html => 1 },
37             path => { type => 1, html => 1 },
38             parent => { type => 0, html => 1 },
39             accessid => { type => 1, html => 1 }
40             );
41              
42             my (@mandatory,@allfields);
43             for(keys %fields) {
44             push @mandatory, $_ if($fields{$_}->{type});
45             push @allfields, $_;
46             }
47              
48             my @savefields = qw(path accessid parent);
49              
50             my $LEVEL = ADMIN;
51             my $INDEXKEY = 'folderid';
52             my $ALLSQL = 'AllFolders';
53             my $GETSQL = 'GetFolder';
54             my $SAVESQL = 'UpdateFolder';
55             my $ADDSQL = 'InsertFolder';
56             my $DELETESQL = 'DeleteFolder';
57              
58             # -------------------------------------
59             # The Subs
60              
61             =head1 ADMIN INTERFACE METHODS
62              
63             All action methods are only accessible by users with admin permission.
64              
65             =over 4
66              
67             =item Admin
68              
69             Lists the current set of folders.
70              
71             =item Add
72              
73             Add a new folder.
74              
75             =item Edit
76              
77             Edit specified folder.
78              
79             =item Save
80              
81             Save specified folder.
82              
83             =item Delete
84              
85             Delete specified folder.
86              
87             =item DeleteLinkRealm
88              
89             Delete a link between the specified folder and realm.
90              
91             =back
92              
93             =cut
94              
95             sub Admin {
96             return unless AccessUser(ADMIN);
97              
98             if($cgiparams{doaction}) {
99             if($cgiparams{doaction} eq 'Delete' ) { Delete(); }
100             }
101              
102             my @rows = $dbi->GetQuery('hash','AllFolders');
103             $tvars{data} = \@rows if(@rows);
104             }
105              
106             sub Add {
107             return unless AccessUser(ADMIN);
108             $tvars{data} = {
109             path => '',
110             ddaccess => AccessSelect(1),
111             ddparent => FolderSelect(1,'parent')
112             };
113             }
114              
115             sub Edit {
116             return unless AccessUser($LEVEL);
117             return unless( $cgiparams{'folderid'} && $cgiparams{'folderid'} > 1 );
118              
119             my @rows = $dbi->GetQuery('hash','GetFolder',$cgiparams{'folderid'});
120             return unless(@rows);
121              
122             $tvars{data} = $rows[0];
123             $tvars{data}{ddaccess} = AccessSelect($rows[0]->{accessid});
124             $tvars{data}{ddparent} = FolderSelect($rows[0]->{parent},'parent');
125             }
126              
127             sub Save {
128             return unless AccessUser($LEVEL);
129             return unless AuthorCheck('GetFolder',$INDEXKEY);
130              
131             for(keys %fields) {
132             if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
133             elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
134             elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
135             }
136              
137             return if FieldCheck(\@allfields,\@mandatory);
138              
139             my @fields = map {$tvars{data}->{$_}} @savefields;
140             if($cgiparams{$INDEXKEY}) {
141             $dbi->DoQuery($SAVESQL,@fields,$cgiparams{$INDEXKEY});
142             } else {
143             $cgiparams{$INDEXKEY} = $dbi->IDQuery($ADDSQL,@fields);
144             }
145              
146             $tvars{thanks} = 1;
147             }
148              
149             sub Delete {
150             return unless AccessUser(ADMIN);
151             my @ids = CGIArray('LISTED');
152             return unless @ids;
153              
154             $dbi->DoQuery($DELETESQL,{ids=>join(",",@ids)});
155             }
156              
157             1;
158              
159             __END__