line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Labyrinth::Plugin::Groups; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
4386
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
86
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '5.19'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Labyrinth::Plugin::Groups - handler for Labyrinth groups |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Contains all the group handling functionality for the Labyrinth |
15
|
|
|
|
|
|
|
framework. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# type 1 - userid link to groupid |
20
|
|
|
|
|
|
|
# type 2 - groupid link to groupid |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# ------------------------------------- |
23
|
|
|
|
|
|
|
# Library Modules |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
8
|
use base qw(Labyrinth::Plugin::Base); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
645
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Labyrinth::Audit; |
28
|
|
|
|
|
|
|
use Labyrinth::DBUtils; |
29
|
|
|
|
|
|
|
use Labyrinth::Groups; |
30
|
|
|
|
|
|
|
use Labyrinth::MLUtils; |
31
|
|
|
|
|
|
|
use Labyrinth::Support; |
32
|
|
|
|
|
|
|
use Labyrinth::Users; |
33
|
|
|
|
|
|
|
use Labyrinth::Variables; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# ------------------------------------- |
36
|
|
|
|
|
|
|
# Variables |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# html: 0 = none, 1 = text, 2 = textarea |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my %fields = ( |
41
|
|
|
|
|
|
|
groupid => { type => 0, html => 0 }, |
42
|
|
|
|
|
|
|
groupname => { type => 1, html => 1 }, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my (@mandatory, @allfields); |
46
|
|
|
|
|
|
|
for(keys %fields) { |
47
|
|
|
|
|
|
|
push @mandatory, $_ if($fields{$_}->{type}); |
48
|
|
|
|
|
|
|
push @allfields, $_; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# ------------------------------------- |
52
|
|
|
|
|
|
|
# The Subs |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 PUBLIC INTERFACE METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over 4 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item GetUserGroup() |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
For the current user login, set main group. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=back |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub GetUserGroup { |
67
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','UserGroups',$tvars{loginid}); |
68
|
|
|
|
|
|
|
$tvars{user}{groupid} = $rows[0]->{groupid} if(@rows); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 ADMIN INTERFACE METHODS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
All action methods are only accessible by users with admin permission. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item Admin |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Provides List and Delete functionality for Group Admin. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item Add |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Creates a new group. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item AddLinkUser |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Links a given user to the given group. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item AddLinkGroup |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Links a given group to another, the latter becoming the parent of the former. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item Edit |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Provides group admin functionality for a given group. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item Save |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Saves the current settings for the given group. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item User |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Provides group admin functionality for a given user. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item UserSave |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Saves the current group settings for the given user. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item Delete |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Deletes a group. Called from within the Admin method above. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item DeleteLinkUser |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Removes the given user from the given group. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item DeleteLinkGroup |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Removes the given group from a nominated parent. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub Admin { |
126
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
127
|
|
|
|
|
|
|
if($cgiparams{doaction}) { |
128
|
|
|
|
|
|
|
Delete() if($cgiparams{doaction} eq 'Delete'); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
my @where = ($tvars{useraccess} == MASTER ? () : ('groupid!=9')); |
131
|
|
|
|
|
|
|
push @where, "groupname LIKE '%$cgiparams{'searchname'}%'" if($cgiparams{'searchname'}); |
132
|
|
|
|
|
|
|
my $where = @where ? 'WHERE '.join(' AND ',@where) : ''; |
133
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','AllGroups',{where=>$where}); |
134
|
|
|
|
|
|
|
for(@rows) { |
135
|
|
|
|
|
|
|
my @cnt = $dbi->GetQuery('hash','GroupCount',$_->{groupid}); |
136
|
|
|
|
|
|
|
$_->{count} = @cnt ? $cnt[0]->{count} : 0; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
$tvars{data} = \@rows if(@rows); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub Add { |
142
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
143
|
|
|
|
|
|
|
$tvars{newgroup} = 1; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub AddLinkUser { |
147
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
148
|
|
|
|
|
|
|
return unless $cgiparams{'groupid'}; |
149
|
|
|
|
|
|
|
return unless $cgiparams{'id'}; |
150
|
|
|
|
|
|
|
$dbi->DoQuery('AddLinkIndex',0,$cgiparams{'id'},$cgiparams{'groupid'}); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub AddLinkGroup { |
154
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
155
|
|
|
|
|
|
|
return unless $cgiparams{'groupid'}; |
156
|
|
|
|
|
|
|
return unless $cgiparams{'id'}; |
157
|
|
|
|
|
|
|
$dbi->DoQuery('AddLinkIndex',1,$cgiparams{'id'},$cgiparams{'groupid'}); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub User { |
161
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
162
|
|
|
|
|
|
|
return unless $cgiparams{'userid'}; |
163
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','GetUserByID',$cgiparams{'userid'}); |
164
|
|
|
|
|
|
|
$tvars{data} = $rows[0]; |
165
|
|
|
|
|
|
|
my @urows = $dbi->GetQuery('hash','UserGroups',$cgiparams{'userid'}); |
166
|
|
|
|
|
|
|
$tvars{primary} = \@urows if(@urows); |
167
|
|
|
|
|
|
|
my %groups; |
168
|
|
|
|
|
|
|
my @arows = $dbi->GetQuery('hash','AllGroups'); |
169
|
|
|
|
|
|
|
my @irows = $dbi->GetQuery('hash','AllGroupIndex'); |
170
|
|
|
|
|
|
|
foreach (@irows) { push @{$groups{$_->{groupid}}}, $_->{linkid}; } |
171
|
|
|
|
|
|
|
my @list; |
172
|
|
|
|
|
|
|
my %grps = map {$_->{groupid} => 1} @urows; |
173
|
|
|
|
|
|
|
my @grps = keys %grps; |
174
|
|
|
|
|
|
|
while(@grps) { |
175
|
|
|
|
|
|
|
my $g = shift @grps; |
176
|
|
|
|
|
|
|
push @list, $g unless($grps{$g}); # not primary group |
177
|
|
|
|
|
|
|
next unless($groups{$g}); # not already seen |
178
|
|
|
|
|
|
|
push @grps, @{$groups{$g}}; |
179
|
|
|
|
|
|
|
delete $groups{$g}; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
my %list = map {$_->{groupid} => $_->{groupname}} @arows; |
182
|
|
|
|
|
|
|
my @deps = sort map {$list{$_}} @list; |
183
|
|
|
|
|
|
|
$tvars{secondary} = \@deps if(@deps); |
184
|
|
|
|
|
|
|
$tvars{ddgroups} = GroupSelect(); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub Edit { |
188
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
189
|
|
|
|
|
|
|
return unless $cgiparams{'groupid'}; |
190
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','GetGroup',$cgiparams{'groupid'}); |
191
|
|
|
|
|
|
|
return unless(@rows); |
192
|
|
|
|
|
|
|
$tvars{data} = $rows[0]; |
193
|
|
|
|
|
|
|
my @urows = $dbi->GetQuery('hash','LinkUsers',$cgiparams{'groupid'}); |
194
|
|
|
|
|
|
|
my @grows = $dbi->GetQuery('hash','LinkGroups',$cgiparams{'groupid'}); |
195
|
|
|
|
|
|
|
$tvars{groupusers} = \@urows if(@urows); |
196
|
|
|
|
|
|
|
$tvars{primary} = \@grows if(@grows); |
197
|
|
|
|
|
|
|
my %groups; |
198
|
|
|
|
|
|
|
my @arows = $dbi->GetQuery('hash','AllGroups'); |
199
|
|
|
|
|
|
|
my @irows = $dbi->GetQuery('hash','AllGroupIndex'); |
200
|
|
|
|
|
|
|
foreach (@irows) { push @{$groups{$_->{groupid}}}, $_->{linkid}; } |
201
|
|
|
|
|
|
|
my @list; |
202
|
|
|
|
|
|
|
my %grps = map {$_->{linkid} => 1} @grows; |
203
|
|
|
|
|
|
|
my @grps = keys %grps; |
204
|
|
|
|
|
|
|
while(@grps) { |
205
|
|
|
|
|
|
|
my $g = shift @grps; |
206
|
|
|
|
|
|
|
push @list, $g unless($grps{$g}); # not primary group |
207
|
|
|
|
|
|
|
next unless($groups{$g}); # not already seen |
208
|
|
|
|
|
|
|
push @grps, @{$groups{$g}}; |
209
|
|
|
|
|
|
|
delete $groups{$g}; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
my %list = map {$_->{groupid} => $_->{groupname}} @arows; |
212
|
|
|
|
|
|
|
my @deps = sort map {$list{$_}} @list; |
213
|
|
|
|
|
|
|
$tvars{secondary} = \@deps if(@deps); |
214
|
|
|
|
|
|
|
$tvars{ddusers} = UserSelect(undef,5); |
215
|
|
|
|
|
|
|
$tvars{ddgroups} = GroupSelectMulti($cgiparams{'groupid'}); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub Save { |
219
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
220
|
|
|
|
|
|
|
for(keys %fields) { |
221
|
|
|
|
|
|
|
if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) } |
222
|
|
|
|
|
|
|
elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) } |
223
|
|
|
|
|
|
|
elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) } |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
return if FieldCheck(\@allfields,\@mandatory); |
226
|
|
|
|
|
|
|
# cannot change names of core groups |
227
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','GetGroup',$cgiparams{'groupid'}); |
228
|
|
|
|
|
|
|
unless($rows[0]->{master}) { |
229
|
|
|
|
|
|
|
if($cgiparams{'groupid'}) |
230
|
|
|
|
|
|
|
{ $dbi->DoQuery('SaveGroup',$cgiparams{'groupname'},$cgiparams{'groupid'}); } |
231
|
|
|
|
|
|
|
else { $cgiparams{'groupid'} = $dbi->IDQuery('AddGroup',$cgiparams{'groupname'}); } |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
if($cgiparams{'users'}) { |
234
|
|
|
|
|
|
|
push my @ids, CGIArray('users'); |
235
|
|
|
|
|
|
|
$dbi->DoQuery('AddLinkIndex',1,$_,$cgiparams{'groupid'}) for @ids; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
if($cgiparams{'groups'}) { |
238
|
|
|
|
|
|
|
push my @ids, CGIArray('groups'); |
239
|
|
|
|
|
|
|
$dbi->DoQuery('AddLinkIndex',2,$_,$cgiparams{'groupid'}) for @ids; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub UserSave { |
244
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
245
|
|
|
|
|
|
|
return unless($cgiparams{'userid'}); |
246
|
|
|
|
|
|
|
if($cgiparams{'groups'}) { |
247
|
|
|
|
|
|
|
push my @ids, CGIArray('groups'); |
248
|
|
|
|
|
|
|
$dbi->DoQuery('AddLinkIndex',1,$cgiparams{'userid'},$_) for @ids; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
sub Delete { |
253
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
254
|
|
|
|
|
|
|
my @ids = CGIArray('LISTED'); |
255
|
|
|
|
|
|
|
return unless @ids; |
256
|
|
|
|
|
|
|
for my $id (@ids) { |
257
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','GetGroup',$id); |
258
|
|
|
|
|
|
|
next if($rows[0]->{master}); # cannot delete core groups |
259
|
|
|
|
|
|
|
$dbi->DoQuery('DeleteGroupIndex',$id); |
260
|
|
|
|
|
|
|
$dbi->DoQuery('DeleteGroup',$id); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub DeleteLinkUser { |
265
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
266
|
|
|
|
|
|
|
return unless $cgiparams{'groupid'}; |
267
|
|
|
|
|
|
|
return unless $cgiparams{'userid'}; |
268
|
|
|
|
|
|
|
$dbi->DoQuery('DeleteLinkIndex',1,$cgiparams{'userid'},$cgiparams{'groupid'}); |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub DeleteLinkGroup { |
272
|
|
|
|
|
|
|
return unless AccessUser(ADMIN); |
273
|
|
|
|
|
|
|
return unless $cgiparams{'groupid'}; |
274
|
|
|
|
|
|
|
return unless $cgiparams{'id'}; |
275
|
|
|
|
|
|
|
$dbi->DoQuery('DeleteLinkIndex',2,$cgiparams{'id'},$cgiparams{'groupid'}); |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
1; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
__END__ |