rt 4.0.23
[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">
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') &>
64
65 <table>
66 <tr><td align="right">
67 <&|/l&>Username</&>:
68 </td><td>
69 <input name="Name" value="<%$UserObj->Name||$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||$EmailAddress||''%>" />
75 </td></tr>
76 <tr><td align="right">
77 <&|/l&>Real Name</&>: 
78 </td><td>
79 <input name="RealName" value="<%$UserObj->RealName||$RealName||''%>" />
80 </td></tr>
81 <tr><td align="right">
82 <&|/l&>Nickname</&>: 
83 </td><td>
84 <input name="NickName" value="<%$UserObj->NickName||$NickName||''%>" />
85 </td></tr>
86 <tr><td align="right">
87 <&|/l&>Unix login</&>: 
88 </td><td>
89 <input name="Gecos" value="<%$UserObj->Gecos||$Gecos||''%>" />
90 </td></tr>
91 <tr><td align="right">
92 <&|/l&>Language</&>: 
93 </td><td>
94 <& /Elements/SelectLang, Name => 'Lang', Default => $UserObj->Lang||$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||$FreeformContactInfo||''%></textarea>
100 </td></tr>
101 </table>
102 </&>
103 <br />
104
105 <&| /Widgets/TitleBox, title => loc('Customers') &>
106 <& /Elements/EditCustomers, Object => $UserObj, CustomerString=> $CustomerString, ServiceString => $ServiceString &>
107 </&>
108 <br />
109
110 <&| /Widgets/TitleBox, title => loc('Access control') &>
111 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
112 <input type="checkbox" class="checkbox" name="Enabled" value="1" <%$EnabledChecked||''%> />
113 <&|/l&>Let this user access RT</&><br />
114
115
116 <input type="hidden" class="hidden" name="SetPrivileged" value="1" />
117 <input type="checkbox" class="checkbox" name="Privileged" value="1" <%$PrivilegedChecked||''%> /> <&|/l&>Let this user be granted rights</&> (<&|/l&>Privileged</&>)<br />
118
119 <& /Elements/EditPassword,
120     User => $UserObj,
121     Name => [qw(CurrentPass Pass1 Pass2)],
122 &>
123 </&>
124 % $m->callback( %ARGS, CallbackName => 'LeftColumnBottom', UserObj => $UserObj );
125 </td>
126
127 <td valign="top" class="boxcontainer">
128 <&| /Widgets/TitleBox, title => loc('Location') &>
129 <table>
130 <tr><td align="right">
131 <&|/l&>Organization</&>: 
132 </td><td>
133 <input name="Organization" value="<%$UserObj->Organization||$Organization||''%>" />
134 </td></tr>
135 <tr><td align="right">
136 <&|/l&>Address1</&>: 
137 </td><td>
138 <input name="Address1" value="<%$UserObj->Address1||$Address1||''%>" />
139 </td></tr>
140 <tr><td align="right">
141 <&|/l&>Address2</&>: 
142 </td><td>
143 <input name="Address2" value="<%$UserObj->Address2||$Address2||''%>" />
144 </td></tr>
145 <tr><td align="right">
146 <&|/l&>City</&>: 
147 </td><td>
148 <input name="City" value="<%$UserObj->City||$City||''%>" size="14" />
149
150 </td></tr>
151 <tr><td align="right">
152 <&|/l&>State</&>: 
153 </td><td>
154 <input name="State" value="<%$UserObj->State||$State||''%>" size="3" />
155
156 </td></tr>
157 <tr><td align="right">
158 <&|/l&>Zip</&>: 
159 </td><td>
160 <input name="Zip" value="<%$UserObj->Zip||$Zip||''%>" size="9" />
161 </td></tr>
162 <tr><td align="right">
163 <&|/l&>Country</&>: 
164 </td><td>
165 <input name="Country" value="<%$UserObj->Country||$Country||''%>" />
166 </td></tr>
167 </table>
168 </&>
169 <br />
170 <&| /Widgets/TitleBox, title => loc('Phone numbers') &>
171 <table>
172 <tr><td align="right">
173 <&|/l&>Residence</&>: 
174 </td><td>
175 <input name="HomePhone" value="<%$UserObj->HomePhone||$HomePhone||''%>" size="13" /><br />
176 </td></tr>
177 <tr><td align="right">
178 <&|/l&>Work</&>: 
179 </td><td>
180 <input name="WorkPhone" value="<%$UserObj->WorkPhone||$WorkPhone||''%>" size="13" /><br />
181 </td></tr>
182 <tr><td align="right">
183 <&|/l&>Mobile</&>: 
184 </td><td>
185 <input name="MobilePhone" value="<%$UserObj->MobilePhone||$MobilePhone||''%>" size="13" /><br />
186 </td></tr>
187 <tr><td align="right">
188 <&|/l&>Pager</&>: 
189 </td><td>
190 <input name="PagerPhone" value="<%$UserObj->PagerPhone||$PagerPhone||''%>" size="13" /><br />
191 </td>
192 </tr>
193 </table>
194 </&>
195 <br />
196 <&| /Widgets/TitleBox, title => loc('Custom Fields') &>
197 <table>
198 % my $CFs = $UserObj->CustomFields;
199 % while (my $CF = $CFs->Next) {
200 <tr valign="top"><td align="right">
201 <% loc($CF->Name) %>:
202 </td><td>
203 % if ($UserObj->id) {
204 <& /Elements/EditCustomField, %ARGS, Object => $UserObj, CustomField => $CF &>
205 % } else {
206 <& /Elements/EditCustomField, %ARGS, NamePrefix => 'Object-RT::User--CustomField-', CustomField => $CF &>
207 % }
208 </td></tr>
209 % }
210 </table>
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') &>
217 <textarea class="comments" name="Comments" cols="80" rows="5" wrap="virtual"><%$UserObj->Comments||$Comments||''%></textarea>
218 </&>
219 %if (!$Create && $UserObj->Privileged) {
220 <br />
221 <&| /Widgets/TitleBox, title => loc('Signature') &>
222 <textarea class="signature" cols="80" rows="5" name="Signature" wrap="hard"><%$UserObj->Signature||$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, $PrivilegedChecked, $EnabledChecked, $Disabled, $result, @results);
241
242 my ($val, $msg);
243
244 if ($Create) {
245     $title = loc("Create a new user");
246
247 else {
248
249     if ( defined $id && $id eq 'new') {
250         ( $val, $msg ) = $UserObj->Create(
251             Name                  => $Name,
252             EmailAddress          => $ARGS{'EmailAddress'},
253             Name                  => $ARGS{'Name'},
254             Comments              => $ARGS{'Comments'},
255             Signature             => $ARGS{'Signature'},
256             EmailAddress          => $ARGS{'EmailAddress'},
257             FreeformContactInfo   => $ARGS{'FreeformContactInfo'},
258             Organization          => $ARGS{'Organization'},
259             RealName              => $ARGS{'RealName'},
260             NickName              => $ARGS{'NickName'},
261             Lang                  => $ARGS{'Lang'},
262             EmailEncoding         => $ARGS{'EmailEncoding'},
263             WebEncoding           => $ARGS{'WebEncoding'},
264             ExternalContactInfoId => $ARGS{'ExternalContactInfoId'},
265             ContactInfoSystem     => $ARGS{'ContactInfoSystem'},
266             Gecos                 => $ARGS{'Gecos'},
267             ExternalAuthId        => $ARGS{'ExternalAuthId'},
268             AuthSystem            => $ARGS{'AuthSystem'},
269             HomePhone             => $ARGS{'HomePhone'},
270             WorkPhone             => $ARGS{'WorkPhone'},
271             MobilePhone           => $ARGS{'MobilePhone'},
272             PagerPhone            => $ARGS{'PagerPhone'},
273             Address1              => $ARGS{'Address1'},
274             Address2              => $ARGS{'Address2'},
275             City                  => $ARGS{'City'},
276             State                 => $ARGS{'State'},
277             Zip                   => $ARGS{'Zip'},
278             Country               => $ARGS{'Country'},
279             Privileged           => $ARGS{'Privileged'},
280             Disabled            => ($ARGS{'Enabled'} ? 0 : 1)
281         );
282
283         if ($val) {
284                 push @results, $msg;
285         push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
286         } else {
287                 push @results, loc('User could not be created: [_1]', $msg);
288         }
289     } else {
290             $UserObj->Load($id) || $UserObj->Load($Name) 
291             || Abort("Couldn't load user '" . ( $Name || '') . "'");
292         $val = $UserObj->Id();
293     }
294
295     if ($val) {
296         $title = loc("Modify the user [_1]", $UserObj->Name);
297     }
298
299     # If the create failed
300     else {
301         $title = loc("Create a new user");
302         $Create = 1;
303     }
304 }
305
306
307 $m->callback( %ARGS, CallbackName => 'BeforeUpdate', User => $UserObj, ARGSRef => \%ARGS, Results => \@results );
308
309
310 # If we have a user to modify, lets try. 
311 if ($UserObj->Id && $id ne 'new') {
312
313     my @fields = qw(Name Comments Signature EmailAddress FreeformContactInfo 
314                     Organization RealName NickName Lang EmailEncoding WebEncoding 
315                     ExternalContactInfoId ContactInfoSystem Gecos ExternalAuthId 
316                     AuthSystem HomePhone WorkPhone MobilePhone PagerPhone Address1
317                     Address2 City State Zip Country 
318                    );
319
320     my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
321                                             Object => $UserObj,
322                                             ARGSRef => \%ARGS );
323     push (@results,@fieldresults);
324     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
325
326     #deal with freeside customer links
327     push @results, ProcessObjectCustomers( ARGSRef => \%ARGS, Object => $UserObj );
328
329     # {{{ Deal with special fields: Privileged, Enabled
330     if  ( $SetPrivileged and $Privileged != $UserObj->Privileged ) {
331          my ($code, $msg) = $UserObj->SetPrivileged($Privileged);
332          push @results, loc('Privileged status: [_1]', loc_fuzzy($msg));
333     }
334
335     #we're asking about enabled on the web page but really care about disabled.
336     $Disabled = $Enabled ? 0 : 1;
337
338     if  ( ($SetEnabled) and ( $Disabled != $UserObj->Disabled) ) { 
339         my  ($code, $msg) = $UserObj->SetDisabled($Disabled);
340         push @results, $msg;
341     }
342
343
344 }
345
346
347 my %password_cond = $UserObj->CurrentUserRequireToSetPassword;
348 if ( $UserObj->Id ) {
349     # Deal with Password field
350     my ($status, $msg) = $UserObj->SafeSetPassword(
351         Current      => $CurrentPass,
352         New          => $Pass1,
353         Confirmation => $Pass2,
354     );
355     push @results, $msg;
356
357     if ( $id eq 'new' && !$status ) {
358         push @results, loc("A password was not set, so user won't be able to login.");
359     }
360 }
361
362
363 # Do some setup for the ui
364 unless ( $UserObj->id && $UserObj->Disabled ) {
365     $EnabledChecked = 'checked="checked"';
366 }
367
368 if ((!$Create && $UserObj->Privileged()) or (!$UserObj->Id and $Privileged)) {  
369     $PrivilegedChecked = 'checked="checked"';
370 }
371
372 # This code does automatic redirection if any updates happen.
373 MaybeRedirectForResults(
374     Actions   => \@results,
375     Arguments => { id => $UserObj->Id },
376 ) if $UserObj->Id;
377
378 </%INIT>
379
380
381 <%ARGS>
382 $id => undef
383 $Name  => undef
384 $Comments  => undef
385 $Signature  => undef
386 $EmailAddress  => undef
387 $FreeformContactInfo => undef
388 $Organization  => undef
389 $RealName  => undef
390 $NickName  => undef
391 $Privileged => undef
392 $SetPrivileged => undef
393 $Enabled => undef
394 $SetEnabled => undef
395 $Lang  => undef
396 $EmailEncoding  => undef
397 $WebEncoding => undef
398 $ExternalContactInfoId  => undef
399 $ContactInfoSystem  => undef
400 $Gecos => undef
401 $ExternalAuthId  => undef
402 $AuthSystem  => undef
403 $HomePhone => undef
404 $WorkPhone  => undef
405 $MobilePhone  => undef
406 $PagerPhone  => undef
407 $Address1 => undef
408 $Address2  => undef
409 $City  => undef
410 $State  => undef
411 $Zip  => undef
412 $Country => undef
413 $CurrentPass => undef
414 $Pass1 => undef
415 $Pass2 => undef
416 $Create=> undef
417 $OnlySearchForCustomers => undef
418 $OnlySearchForServices => undef
419 $CustomerString => undef
420 $ServiceString => undef
421 </%ARGS>