import of rt 3.0.4
[freeside.git] / rt / html / Admin / 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 <& /Admin/Elements/Header, Title => "RT/Admin/Edit the group ". $Group->Name &>
25 <& /Admin/Elements/GroupTabs, GroupObj => $Group, 
26     current_tab => 'Admin/Groups/Members.html?id='.$id, 
27     Title => "RT/Admin/Edit the group ". $Group->Name &>
28 <& /Elements/ListActions, actions => \@results &>
29
30
31 <& /Elements/TitleBoxStart, title => loc('Editing membership for group [_1]', $Group->Name) &>
32
33 <FORM ACTION="<%$RT::WebPath%>/Admin/Groups/Members.html" METHOD=POST>
34 <INPUT TYPE=HIDDEN NAME=id VALUE="<%$Group->Id%>">
35 <TABLE WIDTH="100%">
36 <TR>
37 <TD>
38 <h3><&|/l&>Current members</&></h3>
39 </TD>
40 <TD>
41 <h3><&|/l&>Add members</&></h3>
42 </TD>
43 </TR>
44
45 <TR>
46 <TD VALIGN=TOP>
47
48 % if ($Group->MembersObj->Count == 0 ) {
49 <i><&|/l&>(No members)</&></i>
50 % } else {
51 <i><&|/l&>(Check box to delete)</&></i>
52 <br>
53 <br>
54 <&|/l&>Users</&>
55 % my $UserMembers = $Group->MembersObj;
56 % $UserMembers->LimitToUsers();
57 <UL>
58 % while (my $member = $UserMembers->Next()) {
59 <LI><INPUT TYPE=CHECKBOX Name="DeleteMember-<%$member->MemberId%>">
60 <%$member->MemberObj->Object->Name%> (<%$member->MemberObj->Object->RealName%>)
61 % }
62 </ul>
63 <&|/l&>Groups</&>
64 <ul>
65 % my $GroupMembers = $Group->MembersObj;
66 % $GroupMembers->LimitToGroups();
67 % while (my $member = $GroupMembers->Next()) {
68 <LI><INPUT TYPE=CHECKBOX Name="DeleteMember-<%$member->MemberId%>">
69 <%$member->MemberObj->Object->Name%>
70 % }
71 % }
72 </UL>
73 </TD>
74 <TD VALIGN=TOP>
75 <& /Admin/Elements/SelectNewGroupMembers, Name => "AddMembers", Group => $Group &>
76 </TD>
77 </TR>
78 </TABLE>
79 <& /Elements/TitleBoxEnd &>
80 <& /Elements/Submit, Caption => loc("Be sure to save your changes"), Reset => 1 &>
81 </form>
82
83
84 <%INIT>
85
86 my $Group = new RT::Group($session{'CurrentUser'});
87 $Group->Load($id) || Abort(loc('Could not load group'));
88
89 my (@results);
90
91 my $key;
92 foreach $key (keys %ARGS) {
93
94 if ($key =~ /^DeleteMember-(\d+)$/) {
95     my $id = $1; 
96     my ($val,$msg) = $Group->DeleteMember($id);
97     push (@results, $msg);
98 }
99 }
100
101 # Make sure AddMembers is always an array
102 my @AddMembers = (
103     ((ref $AddMembersUsers eq 'ARRAY') ? @{$AddMembersUsers} : ($AddMembersUsers)),
104     ((ref $AddMembersGroups eq 'ARRAY') ? @{$AddMembersGroups} : ($AddMembersGroups)),
105 );
106
107 foreach my $member (@AddMembers) {
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 </%INIT>
129
130 <%ARGS>
131 $AddMembersUsers  => undef
132 $AddMembersGroups => undef
133 $id => undef
134 </%ARGS>