Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / share / html / Admin / Users / Modify.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 %#                                          <sales@bestpractical.com>
7 %#
8 %# (Except where explicitly superseded by other copyright notices)
9 %#
10 %#
11 %# LICENSE:
12 %#
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %#
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %#
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %#
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <& /Admin/Elements/Header, Title => $title  &>
49 <& /Elements/Tabs &>
50
51 <& /Elements/ListActions, actions => \@results &>
52
53 <form action="<%RT->Config->Get('WebPath')%>/Admin/Users/Modify.html" method="post" enctype="multipart/form-data" name="<% $Create ? 'UserCreate': 'UserModify' %>">
54 %if ($Create) {
55 <input type="hidden" class="hidden" name="id" value="new" />
56 % } else {
57 <input type="hidden" class="hidden" name="id" value="<%$UserObj->Id%>" />
58 % }
59 <table width="100%" border="0">
60 <tr>
61
62 <td valign="top" class="boxcontainer">
63 <&| /Widgets/TitleBox, title => loc('Identity'), class => 'user-info-identity' &>
64
65 <table>
66 <tr><td align="right">
67 <&|/l&>Username</&>:
68 </td><td>
69 <input name="Name" value="<%$UserObj->Name//$ARGS{Name}//''%>" /> <strong><&|/l&>(required)</&></strong>
70 </td></tr>
71 <tr><td align="right">
72 <&|/l&>Email</&>:
73 </td><td>
74 <input name="EmailAddress" value="<%$UserObj->EmailAddress//$ARGS{EmailAddress}//''%>" />
75 </td></tr>
76 <tr><td align="right">
77 <&|/l&>Real Name</&>:
78 </td><td>
79 <input name="RealName" value="<%$UserObj->RealName//$ARGS{RealName}//''%>" />
80 </td></tr>
81 <tr><td align="right">
82 <&|/l&>Nickname</&>:
83 </td><td>
84 <input name="NickName" value="<%$UserObj->NickName//$ARGS{NickName}//''%>" />
85 </td></tr>
86 <tr><td align="right">
87 <&|/l&>Unix login</&>:
88 </td><td>
89 <input name="Gecos" value="<%$UserObj->Gecos//$ARGS{Gecos}//''%>" />
90 </td></tr>
91 <tr><td align="right">
92 <&|/l&>Language</&>:
93 </td><td>
94 <& /Elements/SelectLang, Name => 'Lang', Default => $UserObj->Lang//$ARGS{Lang} &>
95 </td></tr>
96 <tr><td align="right">
97 <&|/l&>Extra info</&>:
98 </td><td>
99 <textarea name="FreeformContactInfo" cols="20" rows="5"><%$UserObj->FreeformContactInfo//$ARGS{FreeformContactInfo}//''%></textarea>
100 </td></tr>
101 <& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Identity', InTable => 1 &>
102 </table>
103 </&>
104
105 <br />
106
107 <&| /Widgets/TitleBox, title => loc('Customers') &>
108 <& /Elements/EditCustomers, Object => $UserObj, CustomerString=> $CustomerString, ServiceString => $ServiceString &>
109 </&>
110 <br />
111
112 <&| /Widgets/TitleBox, title => loc('Access control'), class => 'user-info-access-control' &>
113 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
114 <input type="checkbox" class="checkbox" id="Enabled" name="Enabled" value="1" <% ($UserObj->Id && $UserObj->Disabled) ? '' : 'checked="checked"' |n%> />
115 <label for="Enabled"><&|/l&>Let this user access RT</&></label><br />
116
117
118 % my $PrivilegedChecked = ((!$Create && $UserObj->Privileged()) or (!$UserObj->Id and $ARGS{Privileged})) ? 'checked="checked"' : '';
119 <input type="hidden" class="hidden" name="SetPrivileged" value="1" />
120 <input type="checkbox" class="checkbox" id="Privileged" name="Privileged" value="1" <%$PrivilegedChecked|n%> />
121 <label for="Privileged"><&|/l&>Let this user be granted rights</&> (<&|/l&>Privileged</&>)</label><br />
122
123 <& /Elements/EditPassword,
124     User => $UserObj,
125     Name => [qw(CurrentPass Pass1 Pass2)],
126 &>
127
128 <& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Access control' &>
129
130 </&>
131 % $m->callback( %ARGS, CallbackName => 'LeftColumnBottom', UserObj => $UserObj );
132 </td>
133
134 <td valign="top" class="boxcontainer">
135 <&| /Widgets/TitleBox, title => loc('Location'), class => 'user-info-location' &>
136 <table>
137 <tr><td align="right">
138 <&|/l&>Organization</&>:
139 </td><td>
140 <input name="Organization" value="<%$UserObj->Organization//$ARGS{Organization}//''%>" />
141 </td></tr>
142 <tr><td align="right">
143 <&|/l&>Address1</&>:
144 </td><td>
145 <input name="Address1" value="<%$UserObj->Address1//$ARGS{Address1}//''%>" />
146 </td></tr>
147 <tr><td align="right">
148 <&|/l&>Address2</&>:
149 </td><td>
150 <input name="Address2" value="<%$UserObj->Address2//$ARGS{Address2}//''%>" />
151 </td></tr>
152 <tr><td align="right">
153 <&|/l&>City</&>:
154 </td><td>
155 <input name="City" value="<%$UserObj->City//$ARGS{City}//''%>" size="14" />
156
157 </td></tr>
158 <tr><td align="right">
159 <&|/l&>State</&>:
160 </td><td>
161 <input name="State" value="<%$UserObj->State//$ARGS{State}//''%>" size="3" />
162
163 </td></tr>
164 <tr><td align="right">
165 <&|/l&>Zip</&>:
166 </td><td>
167 <input name="Zip" value="<%$UserObj->Zip//$ARGS{Zip}//''%>" size="9" />
168 </td></tr>
169 <tr><td align="right">
170 <&|/l&>Country</&>:
171 </td><td>
172 <input name="Country" value="<%$UserObj->Country//$ARGS{Country}//''%>" />
173 </td></tr>
174
175 <& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Location', InTable => 1 &>
176
177 </table>
178 </&>
179 <br />
180 <&| /Widgets/TitleBox, title => loc('Phone numbers'), class => 'user-info-phones' &>
181 <table>
182 <tr><td align="right">
183 <&|/l&>Residence</&>:
184 </td><td>
185 <input name="HomePhone" value="<%$UserObj->HomePhone//$ARGS{HomePhone}//''%>" size="13" /><br />
186 </td></tr>
187 <tr><td align="right">
188 <&|/l&>Work</&>:
189 </td><td>
190 <input name="WorkPhone" value="<%$UserObj->WorkPhone//$ARGS{WorkPhone}//''%>" size="13" /><br />
191 </td></tr>
192 <tr><td align="right">
193 <&|/l&>Mobile</&>:
194 </td><td>
195 <input name="MobilePhone" value="<%$UserObj->MobilePhone//$ARGS{MobilePhone}//''%>" size="13" /><br />
196 </td></tr>
197 <tr><td align="right">
198 <&|/l&>Pager</&>:
199 </td><td>
200 <input name="PagerPhone" value="<%$UserObj->PagerPhone//$ARGS{PagerPhone}//''%>" size="13" /><br />
201 </td>
202 </tr>
203
204 <& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Phones', InTable => 1 &>
205
206 </table>
207 </&>
208 <br />
209
210 <& /Elements/EditCustomFieldCustomGroupings, Object => $UserObj &>
211
212 % $m->callback( %ARGS, CallbackName => 'RightColumnBottom', UserObj => $UserObj );
213 </td></tr>
214 <tr>
215 <td colspan="2">
216 <&| /Widgets/TitleBox, title => loc('Comments about this user'), class => 'user-info-comments' &>
217 <textarea class="comments" name="Comments" cols="80" rows="5" wrap="virtual"><%$UserObj->Comments//$ARGS{Comments}//''%></textarea>
218 </&>
219 %if (!$Create && $UserObj->Privileged) {
220 <br />
221 <&| /Widgets/TitleBox, title => loc('Signature'), class => 'user-info-signature' &>
222 <textarea class="signature" cols="80" rows="5" name="Signature" wrap="hard"><%$UserObj->Signature//$ARGS{Signature}//''%></textarea>
223 </&>
224 % }
225
226 </td>
227 </tr>
228 </table>
229
230 % if ( $Create ) {
231 <& /Elements/Submit, Label => loc('Create') &>
232 % } else {
233 <& /Elements/Submit, Label => loc('Save Changes') &>
234 % }
235 </form>
236
237 <%INIT>
238
239 my $UserObj = RT::User->new($session{'CurrentUser'});
240 +my ($title, @results);
241
242 my ($val, $msg);
243
244 $ARGS{Privileged} = $ARGS{Privileged} ? 1 : 0;
245 delete $ARGS{Privileged} unless $ARGS{SetPrivileged};
246
247 $ARGS{Disabled} = $ARGS{Enabled} ? 0 : 1;
248 delete $ARGS{Disabled} unless $ARGS{SetEnabled};
249
250 my @fields = qw(Name Comments Signature EmailAddress FreeformContactInfo
251                 Organization RealName NickName Lang EmailEncoding WebEncoding
252                 ExternalContactInfoId ContactInfoSystem Gecos ExternalAuthId
253                 AuthSystem HomePhone WorkPhone MobilePhone PagerPhone Address1
254                 Address2 City State Zip Country
255                );
256
257 if ($Create) {
258     $title = loc("Create a new user");
259 } elsif ( defined $id && $id eq 'new') {
260     ( $val, $msg ) = $UserObj->Create(
261         (map {($_ => $ARGS{$_})} @fields),
262         Privileged => $ARGS{'Privileged'},
263         Disabled   => $ARGS{'Disabled'},
264     );
265
266     if ($val) {
267         push @results, $msg;
268         push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
269         $title = loc("Modify the user [_1]", $UserObj->Name);
270     } else {
271         push @results, loc('User could not be created: [_1]', $msg);
272         $title = loc("Create a new user");
273         $Create = 1;
274     }
275 } else {
276     $UserObj->Load($id) || $UserObj->Load($ARGS{Name})
277         || Abort("Couldn't load user '" . ( $ARGS{Name} || '') . "'");
278
279     $title = loc("Modify the user [_1]", $UserObj->Name);
280
281     $m->callback( %ARGS, CallbackName => 'BeforeUpdate', User => $UserObj, ARGSRef => \%ARGS, Results => \@results );
282
283     my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
284                                             Object => $UserObj,
285                                             ARGSRef => \%ARGS );
286     push (@results,@fieldresults);
287     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
288
289     #deal with freeside customer links
290     push @results, ProcessObjectCustomers( ARGSRef => \%ARGS, Object => $UserObj );
291
292     if ( defined $ARGS{Privileged} and $ARGS{Privileged} != ($UserObj->Privileged || 0) ) {
293         my ($code, $msg) = $UserObj->SetPrivileged($ARGS{Privileged});
294         push @results, loc('Privileged status: [_1]', loc_fuzzy($msg));
295     }
296
297     if ( defined $ARGS{Disabled} and $ARGS{Disabled} != $UserObj->Disabled ) {
298         my ($code, $msg) = $UserObj->SetDisabled($ARGS{Disabled});
299         push @results, $msg;
300     }
301 }
302
303 if ( $UserObj->Id ) {
304     # Deal with Password field
305     my ($status, $msg) = $UserObj->SafeSetPassword(
306         Current      => $CurrentPass,
307         New          => $Pass1,
308         Confirmation => $Pass2,
309     );
310     push @results, $msg;
311
312     if ( $id eq 'new' && !$status ) {
313         push @results, loc("A password was not set, so user won't be able to login.");
314     }
315 }
316
317 # This code does automatic redirection if any updates happen.
318 MaybeRedirectForResults(
319     Actions   => \@results,
320     Arguments => { id => $UserObj->Id },
321 ) if $UserObj->Id;
322
323 </%INIT>
324
325
326 <%ARGS>
327 $id => undef
328 $CurrentPass => undef
329 $Pass1 => undef
330 $Pass2 => undef
331 $Create=> undef
332 $OnlySearchForCustomers => undef
333 $OnlySearchForServices => undef
334 $CustomerString => undef
335 $ServiceString => undef
336 </%ARGS>