import Net::Whois::Raw into install/5.005 directory *sigh*
[freeside.git] / rt / html / User / Groups / Members.html
1 %# BEGIN LICENSE BLOCK
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24 <& /Elements/Header, Title => $title &>
25 <& /User/Elements/GroupTabs, 
26     GroupObj => $Group, 
27     current_subtab => "User/Groups/Members.html?id=".$Group->id, 
28     Title => $title &>
29 <& /Elements/ListActions, actions => \@results &>
30
31
32
33 <FORM ACTION="<%$RT::WebPath%>/User/Groups/Members.html" METHOD="POST">
34 <INPUT TYPE=HIDDEN NAME=id VALUE="<%$Group->Id%>">
35 <TABLE WIDTH="100%">
36 <TR>
37 <TD>
38 <&|/l&>Add members</&>
39 </TD>
40 <TD>
41 <&|/l&>Current members</&>
42 </TD>
43 </TR>
44
45 <TR>
46 <TD VALIGN=TOP>
47 <& /Admin/Elements/SelectNewGroupMembers, Name => "AddMembers", Group => $Group &>
48 </TD>
49 <TD VALIGN=TOP>
50
51 % if ($Group->MembersObj->Count == 0 ) {
52 <i><&|/l&>(No members)</&></i>
53 % } else {
54 <i><&|/l&>(Check box to delete)</&></i>
55 <br>
56 <br>
57 <&|/l&>Users</&>
58 % my $UserMembers = $Group->MembersObj;
59 % $UserMembers->LimitToUsers();
60 <UL>
61 % while (my $member = $UserMembers->Next()) {
62 <LI><INPUT TYPE=CHECKBOX Name="DeleteMember-<%$member->MemberId%>">
63 <%$member->MemberObj->Object->Name%> (<%$member->MemberObj->Object->RealName%>)
64 % }
65 </ul>
66 <&|/l&>Groups</&>
67 <ul>
68 % my $GroupMembers = $Group->MembersObj;
69 % $GroupMembers->LimitToGroups();
70 % while (my $member = $GroupMembers->Next()) {
71 <LI><INPUT TYPE=CHECKBOX Name="DeleteMember-<%$member->MemberId%>">
72 <%$member->MemberObj->Object->Name%>
73 % }
74 % }
75 </UL>
76 </TD>
77 </TR>
78 </TABLE>
79 <& /Elements/Submit &>
80 </form>
81
82
83 <%INIT>
84
85 my $Group = new RT::Group($session{'CurrentUser'});
86 $Group->Load($id) ;
87
88 unless ($Group->id) {
89     Abort(loc('Could not load group'));
90 }
91
92 my (@results);
93
94 foreach my $key (keys %ARGS) {
95
96 if ($key =~ /^DeleteMember-(\d+)$/) {
97     my $mem_id = $1; 
98     my ($val,$msg) = $Group->DeleteMember($mem_id);
99     push (@results, $msg);
100 }
101 }
102
103 # Make sure AddMembers is always an array
104 my @AddMembersUsers = (ref $AddMembersUsers eq 'ARRAY') ? @{$AddMembersUsers} : ($AddMembersUsers);
105 my @AddMembersGroups = (ref $AddMembersGroups eq 'ARRAY') ? @{$AddMembersGroups} : ($AddMembersGroups);
106
107 foreach my $member (@AddMembersUsers, @AddMembersGroups) {
108     next unless ($member);
109
110     my $principal;
111
112     if ($member =~ /^Group-(\d+)$/) {
113         $principal = RT::Group->new($session{'CurrentUser'});
114         $principal->Load($1);
115     } elsif ($member =~ /^User-(\d+)$/) {
116         $principal = RT::User->new($session{'CurrentUser'});
117         $principal->Load($1);
118     } else {
119         next;
120     }
121
122
123     my ($val, $msg) = $Group->AddMember($principal->PrincipalId);
124     push (@results, $msg);
125 }
126
127
128 my $title = loc('Editing membership for personal group [_1]', $Group->Name);
129
130 </%INIT>
131
132 <%ARGS>
133 $AddMembersUsers => undef
134 $AddMembersGroups => undef
135 $id => undef
136 </%ARGS>