port skinning, customer display/edit from RT 3.6 integration to RT 3.8 integration
[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-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->Config->Get('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->Config->Get('WebExternalAuth') and !RT->Config->Get('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" autocomplete="off" />
131 </td>
132 </tr>
133 <tr><td align="right">
134 <&|/l&>Retype Password</&>:
135 </td>
136 <td>
137 <input type="password" name="Pass2" autocomplete="off" />
138 </td>
139 </tr>
140 </table>
141 % }
142 </&>
143 % $m->callback( %ARGS, CallbackName => 'LeftColumnBottom', UserObj => $UserObj );
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 <% loc($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 % $m->callback( %ARGS, CallbackName => 'RightColumnBottom', UserObj => $UserObj );
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 (!$Create && $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 % if ( $Create ) {
250 <& /Elements/Submit, Label => loc('Create') &>
251 % } else {
252 <& /Elements/Submit, Label => loc('Save Changes') &>
253 % }
254 </form>
255
256 <%INIT>
257
258 my $current_tab;
259 my $UserObj = new RT::User($session{'CurrentUser'});
260 my ($title, $PrivilegedChecked, $EnabledChecked, $Disabled, $result, @results);
261
262 my ($val, $msg);
263
264 if ($Create) {
265     $current_tab = 'Admin/Users/Modify.html?Create=1';
266     $title = loc("Create a new user");
267
268 else {
269
270     $current_tab = 'Admin/Users/Modify.html?id='.$id if $id;
271
272     if ( defined $id && $id eq 'new') {
273         ( $val, $msg ) = $UserObj->Create(
274             Name                  => $Name,
275             EmailAddress          => $ARGS{'EmailAddress'},
276             Name                  => $ARGS{'Name'},
277             Comments              => $ARGS{'Comments'},
278             Signature             => $ARGS{'Signature'},
279             EmailAddress          => $ARGS{'EmailAddress'},
280             FreeformContactInfo   => $ARGS{'FreeformContactInfo'},
281             Organization          => $ARGS{'Organization'},
282             RealName              => $ARGS{'RealName'},
283             NickName              => $ARGS{'NickName'},
284             Lang                  => $ARGS{'Lang'},
285             EmailEncoding         => $ARGS{'EmailEncoding'},
286             WebEncoding           => $ARGS{'WebEncoding'},
287             ExternalContactInfoId => $ARGS{'ExternalContactInfoId'},
288             ContactInfoSystem     => $ARGS{'ContactInfoSystem'},
289             Gecos                 => $ARGS{'Gecos'},
290             ExternalAuthId        => $ARGS{'ExternalAuthId'},
291             AuthSystem            => $ARGS{'AuthSystem'},
292             HomePhone             => $ARGS{'HomePhone'},
293             WorkPhone             => $ARGS{'WorkPhone'},
294             MobilePhone           => $ARGS{'MobilePhone'},
295             PagerPhone            => $ARGS{'PagerPhone'},
296             Address1              => $ARGS{'Address1'},
297             Address2              => $ARGS{'Address2'},
298             City                  => $ARGS{'City'},
299             State                 => $ARGS{'State'},
300             Zip                   => $ARGS{'Zip'},
301             Country               => $ARGS{'Country'},
302             Privileged           => $ARGS{'Privileged'},
303             Disabled            => ($ARGS{'Enabled'} ? 0 : 1)
304         );
305
306         if ($val) {
307                 push @results, $msg;
308         foreach my $key ( keys %ARGS) {
309             # Convert custom fields on the "new" object to custom fields on the one we've just created
310             if ($key =~ /^Object-RT::User-new-CustomField-(.*)$/) {
311             $ARGS{'Object-RT::User-'.$val.'-CustomField-'.$1} = delete $ARGS{$key};
312             }
313         }
314         push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
315         } else {
316                 push @results, loc('User could not be created: [_1]', $msg);
317         }
318     } else {
319             $UserObj->Load($id) || $UserObj->Load($Name) 
320             || Abort("Couldn't load user '" . ( $Name || '') . "'");
321         $val = $UserObj->Id();
322     }
323
324     if ($val) {
325         $title = loc("Modify the user [_1]", $UserObj->Name);
326     }
327
328     # If the create failed
329     else {
330         $title = loc("Create a new user");
331         $Create = 1;
332     }
333 }
334
335
336
337
338 # If we have a user to modify, lets try. 
339 if ($UserObj->Id && $id ne 'new') {
340
341     my @fields = qw(Name Comments Signature EmailAddress FreeformContactInfo 
342                     Organization RealName NickName Lang EmailEncoding WebEncoding 
343                     ExternalContactInfoId ContactInfoSystem Gecos ExternalAuthId 
344                     AuthSystem HomePhone WorkPhone MobilePhone PagerPhone Address1
345                     Address2 City State Zip Country 
346                    );
347
348     my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
349                                             Object => $UserObj,
350                                             ARGSRef => \%ARGS );
351     push (@results,@fieldresults);
352     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
353
354     #deal with freeside customer links
355     push @results, ProcessObjectCustomers( ARGSRef => \%ARGS, Object => $UserObj );
356
357     # {{{ Deal with special fields: Privileged, Enabled
358     if  ( $SetPrivileged and $Privileged != $UserObj->Privileged ) {
359          my ($code, $msg) = $UserObj->SetPrivileged($Privileged);
360          push @results, loc('Privileged status: [_1]', loc_fuzzy($msg));
361     }
362
363     #we're asking about enabled on the web page but really care about disabled.
364     $Disabled = $Enabled ? 0 : 1;
365
366     if  ( ($SetEnabled) and ( $Disabled != $UserObj->Disabled) ) { 
367         my  ($code, $msg) = $UserObj->SetDisabled($Disabled);
368         push @results, $msg;
369     }
370
371
372     # }}}
373 }
374
375 if ( $UserObj->Id ) {
376     my $password_not_set;
377     # Deal with Password field
378     if ( !$Pass1 and !$Pass2 ) {
379         $password_not_set = 1;
380     } elsif ( $Pass1 ne $Pass2 ) {
381         $password_not_set = 1;
382         push @results, loc("Passwords do not match.");
383     } elsif ( $Pass1 eq $Pass2 and !$UserObj->IsPassword($Pass1) ) {
384         my ($code, $msg) = $UserObj->SetPassword($Pass1);
385         push @results, loc_fuzzy($msg);
386         $password_not_set = 1 unless $code;
387     }
388     if ($id eq 'new' and $password_not_set) {
389         push @results, loc("A password was not set, so user won't be able to login.");
390     } 
391 }
392
393
394 # Do some setup for the ui
395 unless ( $UserObj->id && $UserObj->Disabled ) {
396     $EnabledChecked = 'checked="checked"';
397 }
398
399 if (!$Create && $UserObj->Privileged()) {  
400     $PrivilegedChecked = 'checked="checked"';
401 }
402
403 # set the id, so the the menu will have the right info, this needs to
404 # be done here to avoid creating and then modifying a user
405 $id = $UserObj->Id;
406
407 </%INIT>
408
409
410 <%ARGS>
411 $id => undef
412 $Name  => undef
413 $Comments  => undef
414 $Signature  => undef
415 $EmailAddress  => undef
416 $FreeformContactInfo => undef
417 $Organization  => undef
418 $RealName  => undef
419 $NickName  => undef
420 $Privileged => undef
421 $SetPrivileged => undef
422 $Enabled => undef
423 $SetEnabled => undef
424 $Lang  => undef
425 $EmailEncoding  => undef
426 $WebEncoding => undef
427 $ExternalContactInfoId  => undef
428 $ContactInfoSystem  => undef
429 $Gecos => undef
430 $ExternalAuthId  => undef
431 $AuthSystem  => undef
432 $HomePhone => undef
433 $WorkPhone  => undef
434 $MobilePhone  => undef
435 $PagerPhone  => undef
436 $Address1 => undef
437 $Address2  => undef
438 $City  => undef
439 $State  => undef
440 $Zip  => undef
441 $Country => undef
442 $Pass1 => undef
443 $Pass2=> undef
444 $Create=> undef
445 $OnlySearchForCustomers => undef
446 $OnlySearchForServices => undef
447 $CustomerString => undef
448 $ServiceString => undef
449 </%ARGS>