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