import rt 3.6.4
[freeside.git] / rt / html / Admin / Users / Modify.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2007 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/copyleft/gpl.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 </td>
138
139 <td valign="top" class="boxcontainer">
140 <&| /Widgets/TitleBox, title => loc('Location') &>
141 <table>
142 <tr><td align="right">
143 <&|/l&>Organization</&>: 
144 </td><td>
145 <input name="Organization" value="<%$UserObj->Organization%>" />
146 </td></tr>
147 <tr><td align="right">
148 <&|/l&>Address1</&>: 
149 </td><td>
150 <input name="Address1" value="<%$UserObj->Address1%>" />
151 </td></tr>
152 <tr><td align="right">
153 <&|/l&>Address2</&>: 
154 </td><td>
155 <input name="Address2" value="<%$UserObj->Address2%>" />
156 </td></tr>
157 <tr><td align="right">
158 <&|/l&>City</&>: 
159 </td><td>
160 <input name="City" value="<%$UserObj->City%>" size="14" />
161
162 </td></tr>
163 <tr><td align="right">
164 <&|/l&>State</&>: 
165 </td><td>
166 <input name="State" value="<%$UserObj->State%>" size="3" />
167
168 </td></tr>
169 <tr><td align="right">
170 <&|/l&>Zip</&>: 
171 </td><td>
172 <input name="Zip" value="<%$UserObj->Zip%>" size="9" />
173 </td></tr>
174 <tr><td align="right">
175 <&|/l&>Country</&>: 
176 </td><td>
177 <input name="Country" value="<%$UserObj->Country%>" />
178 </td></tr>
179 </table>
180 </&>
181 <br />
182 <&| /Widgets/TitleBox, title => loc('Phone numbers') &>
183 <table>
184 <tr><td align="right">
185 <&|/l&>Residence</&>: 
186 </td><td>
187 <input name="HomePhone" value="<%$UserObj->HomePhone%>" size="13" /><br />
188 </td></tr>
189 <tr><td align="right">
190 <&|/l&>Work</&>: 
191 </td><td>
192 <input name="WorkPhone" value="<%$UserObj->WorkPhone%>" size="13" /><br />
193 </td></tr>
194 <tr><td align="right">
195 <&|/l&>Mobile</&>: 
196 </td><td>
197 <input name="MobilePhone" value="<%$UserObj->MobilePhone%>" size="13" /><br />
198 </td></tr>
199 <tr><td align="right">
200 <&|/l&>Pager</&>: 
201 </td><td>
202 <input name="PagerPhone" value="<%$UserObj->PagerPhone%>" size="13" /><br />
203 </td>
204 </table>
205 </&>
206 <br />
207 <&| /Widgets/TitleBox, title => loc('Custom Fields') &>
208 <table>
209 % my $CFs = $UserObj->CustomFields;
210 % while (my $CF = $CFs->Next) {
211 <tr valign="top"><td align="right">
212 <% $CF->Name %>:
213 </td><td>
214 % if ($UserObj->id) {
215 <& /Elements/EditCustomField, %ARGS, Object => $UserObj, CustomField => $CF &>
216 % } else {
217 <& /Elements/EditCustomField, %ARGS, NamePrefix => 'Object-RT::User-new-CustomField-', CustomField => $CF &>
218 % }
219 </td></tr>
220 % }
221 <tr>
222 </tr>
223 </table>
224 </&>
225 <tr>
226 <td colspan="2">
227 <&| /Widgets/TitleBox, title => loc('Comments about this user') &>
228 <textarea class="comments" name="Comments" cols="80" rows="5" wrap="virtual"><%$UserObj->Comments%></textarea>
229 </&>
230 %if ($UserObj->Privileged) {
231 <br />
232 <&| /Widgets/TitleBox, title => loc('Signature') &>
233 <textarea class="signature" cols="80" rows="5" name="Signature" wrap="hard"><%$UserObj->Signature%></textarea>
234 </&>
235 % }
236
237 </td>
238 </tr>
239 </table>
240
241 <& /Elements/Submit, Label => loc('Save Changes') &>
242 </form>
243
244 <%INIT>
245
246 my $current_tab;
247 my $UserObj = new RT::User($session{'CurrentUser'});
248 my ($title, $PrivilegedChecked, $EnabledChecked, $Disabled, $result, @results);
249
250 my ($val, $msg);
251
252 if ($Create) {
253     $current_tab = 'Admin/Users/Modify.html?Create=1';
254     $title = loc("Create a new user");
255
256 else {
257
258     $current_tab = 'Admin/Users/Modify.html?id='.$id;
259     if ($id eq 'new') {
260         ( $val, $msg ) = $UserObj->Create(
261             Name                  => $Name,
262             EmailAddress          => $ARGS{'EmailAddress'},
263             Name                  => $ARGS{'Name'},
264             Comments              => $ARGS{'Comments'},
265             Signature             => $ARGS{'Signature'},
266             EmailAddress          => $ARGS{'EmailAddress'},
267             FreeformContactInfo   => $ARGS{'FreeformContactInfo'},
268             Organization          => $ARGS{'Organization'},
269             RealName              => $ARGS{'RealName'},
270             NickName              => $ARGS{'NickName'},
271             Lang                  => $ARGS{'Lang'},
272             EmailEncoding         => $ARGS{'EmailEncoding'},
273             WebEncoding           => $ARGS{'WebEncoding'},
274             ExternalContactInfoId => $ARGS{'ExternalContactInfoId'},
275             ContactInfoSystem     => $ARGS{'ContactInfoSystem'},
276             Gecos                 => $ARGS{'Gecos'},
277             ExternalAuthId        => $ARGS{'ExternalAuthId'},
278             AuthSystem            => $ARGS{'AuthSystem'},
279             HomePhone             => $ARGS{'HomePhone'},
280             WorkPhone             => $ARGS{'WorkPhone'},
281             MobilePhone           => $ARGS{'MobilePhone'},
282             PagerPhone            => $ARGS{'PagerPhone'},
283             Address1              => $ARGS{'Address1'},
284             Address2              => $ARGS{'Address2'},
285             City                  => $ARGS{'City'},
286             State                 => $ARGS{'State'},
287             Zip                   => $ARGS{'Zip'},
288             Country               => $ARGS{'Country'},
289             Privileged           => $ARGS{'Privileged'},
290             Disabled            => ($ARGS{'Enabled'} ? 0 : 1)
291         );
292
293         if ($val) {
294                 push @results, $msg;
295         foreach my $key ( keys %ARGS) {
296             # Convert custom fields on the "new" object to custom fields on the one we've just created
297             if ($key =~ /^Object-RT::User-new-CustomField-(.*)$/) {
298             $ARGS{'Object-RT::User-'.$val.'-CustomField-'.$1} = delete $ARGS{$key};
299             }
300         }
301         push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
302         } else {
303                 push @results, loc('User could not be created: [_1]', $msg);
304         }
305     } else {
306             $UserObj->Load($id) || $UserObj->Load($Name) || Abort("Couldn't load user '$Name'");
307         $val = $UserObj->Id();
308     }
309
310     if ($val) {
311         $title = loc("Modify the user [_1]", $UserObj->Name);
312     }
313
314     # If the create failed
315     else {
316         $title = loc("Create a new user");
317         $Create = 1;
318     }
319 }
320
321
322
323
324 # If we have a user to modify, lets try. 
325 if ($UserObj->Id && $id ne 'new') {
326
327     my @fields = qw(Name Comments Signature EmailAddress FreeformContactInfo 
328                     Organization RealName NickName Lang EmailEncoding WebEncoding 
329                     ExternalContactInfoId ContactInfoSystem Gecos ExternalAuthId 
330                     AuthSystem HomePhone WorkPhone MobilePhone PagerPhone Address1
331                     Address2 City State Zip Country 
332                    );
333
334     my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
335                                             Object => $UserObj,
336                                             ARGSRef => \%ARGS );
337     push (@results,@fieldresults);
338     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
339
340
341     # {{{ Deal with special fields: Privileged, Enabled
342     if  ( $SetPrivileged and $Privileged != $UserObj->Privileged ) {
343          my ($code, $msg) = $UserObj->SetPrivileged($Privileged);
344          push @results, loc('Privileged status: [_1]', loc_fuzzy($msg));
345     }
346
347     #we're asking about enabled on the web page but really care about disabled.
348     $Disabled = $Enabled ? 0 : 1;
349
350     if  ( ($SetEnabled) and ( $Disabled != $UserObj->Disabled) ) { 
351         my  ($code, $msg) = $UserObj->SetDisabled($Disabled);
352         push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
353     }
354
355
356     # }}}
357 }
358
359 if ( $UserObj->Id ) {
360     my $password_not_set;
361     # Deal with Password field
362     if ( !$Pass1 and !$Pass2 ) {
363         $password_not_set = 1;
364     } elsif ( $Pass1 ne $Pass2 ) {
365         $password_not_set = 1;
366         push @results, loc("Passwords do not match.");
367     } elsif ( $Pass1 eq $Pass2 and !$UserObj->IsPassword($Pass1) ) {
368         my ($code, $msg) = $UserObj->SetPassword($Pass1);
369         push @results, loc_fuzzy($msg);
370         $password_not_set = 1 unless $code;
371     }
372     if ($id eq 'new' and $password_not_set) {
373         push @results, loc("A password was not set, so user won't be able to login.");
374     } 
375 }
376
377
378 # {{{ Do some setup for the ui
379 unless ($UserObj->Disabled()) {
380     $EnabledChecked ="CHECKED";
381 }
382
383 if ($UserObj->Privileged()) {  
384     $PrivilegedChecked = "CHECKED";
385 }
386
387 # }}}
388
389 # set the id, so the the menu will have the right info, this needs to
390 # be done here to avoid creating and then modifying a user
391 $id = $UserObj->Id;
392
393 </%INIT>
394
395
396 <%ARGS>
397 $id => undef
398 $Name  => undef
399 $Comments  => undef
400 $Signature  => undef
401 $EmailAddress  => undef
402 $FreeformContactInfo => undef
403 $Organization  => undef
404 $RealName  => undef
405 $NickName  => undef
406 $Privileged => undef
407 $SetPrivileged => undef
408 $Enabled => undef
409 $SetEnabled => undef
410 $Lang  => undef
411 $EmailEncoding  => undef
412 $WebEncoding => undef
413 $ExternalContactInfoId  => undef
414 $ContactInfoSystem  => undef
415 $Gecos => undef
416 $ExternalAuthId  => undef
417 $AuthSystem  => undef
418 $HomePhone => undef
419 $WorkPhone  => undef
420 $MobilePhone  => undef
421 $PagerPhone  => undef
422 $Address1 => undef
423 $Address2  => undef
424 $City  => undef
425 $State  => undef
426 $Zip  => undef
427 $Country => undef
428 $Pass1 => undef
429 $Pass2=> undef
430 $Create=> undef
431 </%ARGS>