starting to work...
[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-2012 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-new-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         foreach my $key ( keys %ARGS) {
286             # Convert custom fields on the "new" object to custom fields on the one we've just created
287             if ($key =~ /^Object-RT::User-new-CustomField-(.*)$/) {
288             $ARGS{'Object-RT::User-'.$val.'-CustomField-'.$1} = delete $ARGS{$key};
289             }
290         }
291         push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
292         } else {
293                 push @results, loc('User could not be created: [_1]', $msg);
294         }
295     } else {
296             $UserObj->Load($id) || $UserObj->Load($Name) 
297             || Abort("Couldn't load user '" . ( $Name || '') . "'");
298         $val = $UserObj->Id();
299     }
300
301     if ($val) {
302         $title = loc("Modify the user [_1]", $UserObj->Name);
303     }
304
305     # If the create failed
306     else {
307         $title = loc("Create a new user");
308         $Create = 1;
309     }
310 }
311
312
313 $m->callback( %ARGS, CallbackName => 'BeforeUpdate', User => $UserObj, ARGSRef => \%ARGS, Results => \@results );
314
315
316 # If we have a user to modify, lets try. 
317 if ($UserObj->Id && $id ne 'new') {
318
319     my @fields = qw(Name Comments Signature EmailAddress FreeformContactInfo 
320                     Organization RealName NickName Lang EmailEncoding WebEncoding 
321                     ExternalContactInfoId ContactInfoSystem Gecos ExternalAuthId 
322                     AuthSystem HomePhone WorkPhone MobilePhone PagerPhone Address1
323                     Address2 City State Zip Country 
324                    );
325
326     my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
327                                             Object => $UserObj,
328                                             ARGSRef => \%ARGS );
329     push (@results,@fieldresults);
330     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
331
332     #deal with freeside customer links
333     push @results, ProcessObjectCustomers( ARGSRef => \%ARGS, Object => $UserObj );
334
335     # {{{ Deal with special fields: Privileged, Enabled
336     if  ( $SetPrivileged and $Privileged != $UserObj->Privileged ) {
337          my ($code, $msg) = $UserObj->SetPrivileged($Privileged);
338          push @results, loc('Privileged status: [_1]', loc_fuzzy($msg));
339     }
340
341     #we're asking about enabled on the web page but really care about disabled.
342     $Disabled = $Enabled ? 0 : 1;
343
344     if  ( ($SetEnabled) and ( $Disabled != $UserObj->Disabled) ) { 
345         my  ($code, $msg) = $UserObj->SetDisabled($Disabled);
346         push @results, $msg;
347     }
348
349
350 }
351
352
353 my %password_cond = $UserObj->CurrentUserRequireToSetPassword;
354 if ( $UserObj->Id ) {
355     # Deal with Password field
356     my ($status, $msg) = $UserObj->SafeSetPassword(
357         Current      => $CurrentPass,
358         New          => $Pass1,
359         Confirmation => $Pass2,
360     );
361     push @results, $msg;
362
363     if ( $id eq 'new' && !$status ) {
364         push @results, loc("A password was not set, so user won't be able to login.");
365     }
366 }
367
368
369 # Do some setup for the ui
370 unless ( $UserObj->id && $UserObj->Disabled ) {
371     $EnabledChecked = 'checked="checked"';
372 }
373
374 if ((!$Create && $UserObj->Privileged()) or (!$UserObj->Id and $Privileged)) {  
375     $PrivilegedChecked = 'checked="checked"';
376 }
377
378 # This code does automatic redirection if any updates happen.
379 MaybeRedirectForResults(
380     Actions   => \@results,
381     Arguments => { id => $UserObj->Id },
382 ) if $UserObj->Id;
383
384 </%INIT>
385
386
387 <%ARGS>
388 $id => undef
389 $Name  => undef
390 $Comments  => undef
391 $Signature  => undef
392 $EmailAddress  => undef
393 $FreeformContactInfo => undef
394 $Organization  => undef
395 $RealName  => undef
396 $NickName  => undef
397 $Privileged => undef
398 $SetPrivileged => undef
399 $Enabled => undef
400 $SetEnabled => undef
401 $Lang  => undef
402 $EmailEncoding  => undef
403 $WebEncoding => undef
404 $ExternalContactInfoId  => undef
405 $ContactInfoSystem  => undef
406 $Gecos => undef
407 $ExternalAuthId  => undef
408 $AuthSystem  => undef
409 $HomePhone => undef
410 $WorkPhone  => undef
411 $MobilePhone  => undef
412 $PagerPhone  => undef
413 $Address1 => undef
414 $Address2  => undef
415 $City  => undef
416 $State  => undef
417 $Zip  => undef
418 $Country => undef
419 $CurrentPass => undef
420 $Pass1 => undef
421 $Pass2 => undef
422 $Create=> undef
423 $OnlySearchForCustomers => undef
424 $OnlySearchForServices => undef
425 $CustomerString => undef
426 $ServiceString => undef
427 </%ARGS>