import rt 3.8.11
[freeside.git] / rt / html / Admin / Users / Modify.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
6 %#                                          <jesse@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 <& /Admin/Elements/UserTabs, 
50     id => $id, 
51     UserObj => $UserObj,
52     current_tab => $current_tab, 
53     Title => $title &>
54
55 <& /Elements/ListActions, actions => \@results &>
56
57 <form action="<%$RT::WebPath%>/Admin/Users/Modify.html" method="post" enctype="multipart/form-data">
58 %if ($Create) {
59 <input type="hidden" class="hidden" name="id" value="new" />
60 % } else {
61 <input type="hidden" class="hidden" name="id" value="<%$UserObj->Id%>" />
62 % }
63 <table width="100%" border="0">
64 <tr>
65
66 <td valign="top" class="boxcontainer">
67 <&| /Widgets/TitleBox, title => loc('Identity') &>
68
69 <table>
70 <tr><td align="right">
71 <&|/l&>Username</&>:
72 </td><td>
73 <input name="Name" value="<%$UserObj->Name%>" /> <strong><&|/l&>(required)</&></strong>
74 </td></tr>
75 <tr><td align="right">
76 <&|/l&>Email</&>:
77 </td><td>
78 <input name="EmailAddress" value="<%$UserObj->EmailAddress%>" />
79 </td></tr>
80 <tr><td align="right">
81 <&|/l&>Real Name</&>: 
82 </td><td>
83 <input name="RealName" value="<%$UserObj->RealName%>" />
84 </td></tr>
85 <tr><td align="right">
86 <&|/l&>Nickname</&>: 
87 </td><td>
88 <input name="NickName" value="<%$UserObj->NickName%>" />
89 </td></tr>
90 <tr><td align="right">
91 <&|/l&>Unix login</&>: 
92 </td><td>
93 <input name="Gecos" value="<%$UserObj->Gecos%>" />
94 </td></tr>
95 <tr><td align="right">
96 <&|/l&>Language</&>: 
97 </td><td>
98 <& /Elements/SelectLang, Name => 'Lang', Default => $UserObj->Lang &>
99 </td></tr>
100 <tr><td align="right">
101 <&|/l&>Extra info</&>: 
102 </td><td>
103 <textarea name="FreeformContactInfo" cols="20" rows="5"><%$UserObj->FreeformContactInfo%></textarea>
104 </td></tr>
105 </table>
106 </&>
107 <br />
108 <&| /Widgets/TitleBox, title => loc('Access control') &>
109 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
110 <input type="checkbox" class="checkbox" name="Enabled" value="1" <%$EnabledChecked%> />
111 <&|/l&>Let this user access RT</&><br />
112
113
114 <input type="hidden" class="hidden" name="SetPrivileged" value="1" />
115 <input type="checkbox" class="checkbox" name="Privileged" value="1" <%$PrivilegedChecked%> /> <&|/l&>Let this user be granted rights</&><br />
116                     
117 % unless ($RT::WebExternalAuth and !$RT::WebFallbackToInternalAuth) {
118 <table>
119 <tr>
120 <td align="right">
121 <&|/l&>New Password</&>:
122 </td>
123 <td align="left">
124 <input type="password" name="Pass1" />
125 </td>
126 </tr>
127 <tr><td align="right">
128 <&|/l&>Retype Password</&>:
129 </td>
130 <td>
131 <input type="password" name="Pass2" />
132 </td>
133 </tr>
134 </table>
135 % }
136 </&>
137 <& /Elements/Callback, _CallbackName => 'LeftColumnBottom', UserObj => $UserObj, %ARGS &>
138 </td>
139
140 <td valign="top" class="boxcontainer">
141 <&| /Widgets/TitleBox, title => loc('Location') &>
142 <table>
143 <tr><td align="right">
144 <&|/l&>Organization</&>: 
145 </td><td>
146 <input name="Organization" value="<%$UserObj->Organization%>" />
147 </td></tr>
148 <tr><td align="right">
149 <&|/l&>Address1</&>: 
150 </td><td>
151 <input name="Address1" value="<%$UserObj->Address1%>" />
152 </td></tr>
153 <tr><td align="right">
154 <&|/l&>Address2</&>: 
155 </td><td>
156 <input name="Address2" value="<%$UserObj->Address2%>" />
157 </td></tr>
158 <tr><td align="right">
159 <&|/l&>City</&>: 
160 </td><td>
161 <input name="City" value="<%$UserObj->City%>" size="14" />
162
163 </td></tr>
164 <tr><td align="right">
165 <&|/l&>State</&>: 
166 </td><td>
167 <input name="State" value="<%$UserObj->State%>" size="3" />
168
169 </td></tr>
170 <tr><td align="right">
171 <&|/l&>Zip</&>: 
172 </td><td>
173 <input name="Zip" value="<%$UserObj->Zip%>" size="9" />
174 </td></tr>
175 <tr><td align="right">
176 <&|/l&>Country</&>: 
177 </td><td>
178 <input name="Country" value="<%$UserObj->Country%>" />
179 </td></tr>
180 </table>
181 </&>
182 <br />
183 <&| /Widgets/TitleBox, title => loc('Phone numbers') &>
184 <table>
185 <tr><td align="right">
186 <&|/l&>Residence</&>: 
187 </td><td>
188 <input name="HomePhone" value="<%$UserObj->HomePhone%>" size="13" /><br />
189 </td></tr>
190 <tr><td align="right">
191 <&|/l&>Work</&>: 
192 </td><td>
193 <input name="WorkPhone" value="<%$UserObj->WorkPhone%>" size="13" /><br />
194 </td></tr>
195 <tr><td align="right">
196 <&|/l&>Mobile</&>: 
197 </td><td>
198 <input name="MobilePhone" value="<%$UserObj->MobilePhone%>" size="13" /><br />
199 </td></tr>
200 <tr><td align="right">
201 <&|/l&>Pager</&>: 
202 </td><td>
203 <input name="PagerPhone" value="<%$UserObj->PagerPhone%>" size="13" /><br />
204 </td>
205 </tr>
206 </table>
207 </&>
208 <br />
209 <&| /Widgets/TitleBox, title => loc('Custom Fields') &>
210 <table>
211 % my $CFs = $UserObj->CustomFields;
212 % while (my $CF = $CFs->Next) {
213 <tr valign="top"><td align="right">
214 <% $CF->Name %>:
215 </td><td>
216 % if ($UserObj->id) {
217 <& /Elements/EditCustomField, %ARGS, Object => $UserObj, CustomField => $CF &>
218 % } else {
219 <& /Elements/EditCustomField, %ARGS, NamePrefix => 'Object-RT::User-new-CustomField-', CustomField => $CF &>
220 % }
221 </td></tr>
222 % }
223 </table>
224 </&>
225 <& /Elements/Callback, _CallbackName => 'RightColumnBottom', UserObj => $UserObj, %ARGS &>
226 </td></tr>
227 <tr>
228 <td colspan="2">
229 <&| /Widgets/TitleBox, title => loc('Comments about this user') &>
230 <textarea class="comments" name="Comments" cols="80" rows="5" wrap="virtual"><%$UserObj->Comments%></textarea>
231 </&>
232 %if ($UserObj->Privileged) {
233 <br />
234 <&| /Widgets/TitleBox, title => loc('Signature') &>
235 <textarea class="signature" cols="80" rows="5" name="Signature" wrap="hard"><%$UserObj->Signature%></textarea>
236 </&>
237 % }
238
239 </td>
240 </tr>
241 </table>
242
243 <& /Elements/Submit, Label => loc('Save Changes') &>
244 </form>
245
246 <%INIT>
247
248 my $current_tab;
249 my $UserObj = new RT::User($session{'CurrentUser'});
250 my ($title, $PrivilegedChecked, $EnabledChecked, $Disabled, $result, @results);
251
252 my ($val, $msg);
253
254 if ($Create) {
255     $current_tab = 'Admin/Users/Modify.html?Create=1';
256     $title = loc("Create a new user");
257
258 else {
259
260     $current_tab = 'Admin/Users/Modify.html?id='.$id;
261     if ($id eq 'new') {
262         ( $val, $msg ) = $UserObj->Create(
263             Name                  => $Name,
264             EmailAddress          => $ARGS{'EmailAddress'},
265             Name                  => $ARGS{'Name'},
266             Comments              => $ARGS{'Comments'},
267             Signature             => $ARGS{'Signature'},
268             EmailAddress          => $ARGS{'EmailAddress'},
269             FreeformContactInfo   => $ARGS{'FreeformContactInfo'},
270             Organization          => $ARGS{'Organization'},
271             RealName              => $ARGS{'RealName'},
272             NickName              => $ARGS{'NickName'},
273             Lang                  => $ARGS{'Lang'},
274             EmailEncoding         => $ARGS{'EmailEncoding'},
275             WebEncoding           => $ARGS{'WebEncoding'},
276             ExternalContactInfoId => $ARGS{'ExternalContactInfoId'},
277             ContactInfoSystem     => $ARGS{'ContactInfoSystem'},
278             Gecos                 => $ARGS{'Gecos'},
279             ExternalAuthId        => $ARGS{'ExternalAuthId'},
280             AuthSystem            => $ARGS{'AuthSystem'},
281             HomePhone             => $ARGS{'HomePhone'},
282             WorkPhone             => $ARGS{'WorkPhone'},
283             MobilePhone           => $ARGS{'MobilePhone'},
284             PagerPhone            => $ARGS{'PagerPhone'},
285             Address1              => $ARGS{'Address1'},
286             Address2              => $ARGS{'Address2'},
287             City                  => $ARGS{'City'},
288             State                 => $ARGS{'State'},
289             Zip                   => $ARGS{'Zip'},
290             Country               => $ARGS{'Country'},
291             Privileged           => $ARGS{'Privileged'},
292             Disabled            => ($ARGS{'Enabled'} ? 0 : 1)
293         );
294
295         if ($val) {
296                 push @results, $msg;
297         foreach my $key ( keys %ARGS) {
298             # Convert custom fields on the "new" object to custom fields on the one we've just created
299             if ($key =~ /^Object-RT::User-new-CustomField-(.*)$/) {
300             $ARGS{'Object-RT::User-'.$val.'-CustomField-'.$1} = delete $ARGS{$key};
301             }
302         }
303         push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
304         } else {
305                 push @results, loc('User could not be created: [_1]', $msg);
306         }
307     } else {
308             $UserObj->Load($id) || $UserObj->Load($Name) || Abort("Couldn't load user '$Name'");
309         $val = $UserObj->Id();
310     }
311
312     if ($val) {
313         $title = loc("Modify the user [_1]", $UserObj->Name);
314     }
315
316     # If the create failed
317     else {
318         $title = loc("Create a new user");
319         $Create = 1;
320     }
321 }
322
323
324
325
326 # If we have a user to modify, lets try. 
327 if ($UserObj->Id && $id ne 'new') {
328
329     my @fields = qw(Name Comments Signature EmailAddress FreeformContactInfo 
330                     Organization RealName NickName Lang EmailEncoding WebEncoding 
331                     ExternalContactInfoId ContactInfoSystem Gecos ExternalAuthId 
332                     AuthSystem HomePhone WorkPhone MobilePhone PagerPhone Address1
333                     Address2 City State Zip Country 
334                    );
335
336     my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
337                                             Object => $UserObj,
338                                             ARGSRef => \%ARGS );
339     push (@results,@fieldresults);
340     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
341
342
343     # {{{ Deal with special fields: Privileged, Enabled
344     if  ( $SetPrivileged and $Privileged != $UserObj->Privileged ) {
345          my ($code, $msg) = $UserObj->SetPrivileged($Privileged);
346          push @results, loc('Privileged status: [_1]', loc_fuzzy($msg));
347     }
348
349     #we're asking about enabled on the web page but really care about disabled.
350     $Disabled = $Enabled ? 0 : 1;
351
352     if  ( ($SetEnabled) and ( $Disabled != $UserObj->Disabled) ) { 
353         my  ($code, $msg) = $UserObj->SetDisabled($Disabled);
354         push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
355     }
356
357
358     # }}}
359 }
360
361 if ( $UserObj->Id ) {
362     my $password_not_set;
363     # Deal with Password field
364     if ( !$Pass1 and !$Pass2 ) {
365         $password_not_set = 1;
366     } elsif ( $Pass1 ne $Pass2 ) {
367         $password_not_set = 1;
368         push @results, loc("Passwords do not match.");
369     } elsif ( $Pass1 eq $Pass2 and !$UserObj->IsPassword($Pass1) ) {
370         my ($code, $msg) = $UserObj->SetPassword($Pass1);
371         push @results, loc_fuzzy($msg);
372         $password_not_set = 1 unless $code;
373     }
374     if ($id eq 'new' and $password_not_set) {
375         push @results, loc("A password was not set, so user won't be able to login.");
376     } 
377 }
378
379
380 # {{{ Do some setup for the ui
381 unless ($UserObj->Disabled()) {
382     $EnabledChecked ="CHECKED";
383 }
384
385 if ($UserObj->Privileged()) {  
386     $PrivilegedChecked = "CHECKED";
387 }
388
389 # }}}
390
391 # set the id, so the the menu will have the right info, this needs to
392 # be done here to avoid creating and then modifying a user
393 $id = $UserObj->Id;
394
395 </%INIT>
396
397
398 <%ARGS>
399 $id => undef
400 $Name  => undef
401 $Comments  => undef
402 $Signature  => undef
403 $EmailAddress  => undef
404 $FreeformContactInfo => undef
405 $Organization  => undef
406 $RealName  => undef
407 $NickName  => undef
408 $Privileged => undef
409 $SetPrivileged => undef
410 $Enabled => undef
411 $SetEnabled => undef
412 $Lang  => undef
413 $EmailEncoding  => undef
414 $WebEncoding => undef
415 $ExternalContactInfoId  => undef
416 $ContactInfoSystem  => undef
417 $Gecos => undef
418 $ExternalAuthId  => undef
419 $AuthSystem  => undef
420 $HomePhone => undef
421 $WorkPhone  => undef
422 $MobilePhone  => undef
423 $PagerPhone  => undef
424 $Address1 => undef
425 $Address2  => undef
426 $City  => undef
427 $State  => undef
428 $Zip  => undef
429 $Country => undef
430 $Pass1 => undef
431 $Pass2=> undef
432 $Create=> undef
433 </%ARGS>