part 1 of #1160: associate users w/customers, manual editing
[freeside.git] / rt / html / Admin / Users / Modify.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2005 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., 675 Mass Ave, Cambridge, MA 02139, USA.
26 %# 
27 %# 
28 %# CONTRIBUTION SUBMISSION POLICY:
29 %# 
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
35 %# 
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
44 %# 
45 %# END BPS TAGGED BLOCK }}}
46 <& /Admin/Elements/Header, Title => $title  &>
47 <& /Admin/Elements/UserTabs, 
48     id => $id, 
49     UserObj => $UserObj,
50     current_tab => $current_tab, 
51     Title => $title &>
52
53 <& /Elements/ListActions, actions => \@results &>
54
55 <FORM ACTION="<%$RT::WebPath%>/Admin/Users/Modify.html" METHOD=POST ENCTYPE="multipart/form-data">
56 %if ($Create) {
57 <INPUT TYPE=HIDDEN NAME=id VALUE="new">
58 % } else {
59 <INPUT TYPE=HIDDEN NAME=id VALUE="<%$UserObj->Id%>">
60 % }
61 <TABLE WIDTH=100% BORDER=0>
62 <TR>
63
64 <TD VALIGN=TOP class="boxcontainer">
65 <& /Elements/TitleBoxStart, title => loc('Identity') &>
66
67 <TABLE>
68 <TR><TD ALIGN="RIGHT">
69 <&|/l&>Username</&>:
70 </TD><TD>
71 <input name="Name" value="<%$UserObj->Name%>"> <b><&|/l&>(required)</&></b>
72 </TD></TR>
73 <TR><TD ALIGN="RIGHT">
74 <&|/l&>Email</&>:
75 </TD><TD>
76 <input name="EmailAddress" value="<%$UserObj->EmailAddress%>">
77 </TD></TR>
78 <TR><TD ALIGN="RIGHT">
79 <&|/l&>Real Name</&>: 
80 </TD><TD>
81 <input name="RealName" value="<%$UserObj->RealName%>">
82 </TD></TR>
83 <TR><TD ALIGN="RIGHT">
84 <&|/l&>Nickname</&>: 
85 </TD><TD>
86 <input name="NickName" value="<%$UserObj->NickName%>">
87 </TD></TR>
88 <TR><TD ALIGN="RIGHT">
89 <&|/l&>Unix login</&>: 
90 </TD><TD>
91 <input name="Gecos" value="<%$UserObj->Gecos%>">
92 </TD></TR>
93 <TR><TD ALIGN="RIGHT">
94 <&|/l&>Language</&>: 
95 </TD><TD>
96 <& /Elements/SelectLang, Name => 'Lang', Default => $UserObj->Lang &>
97 </TD></TR>
98 <TR><TD ALIGN="RIGHT">
99 <&|/l&>Extra info</&>: 
100 </TD><TD>
101 <textarea name="FreeformContactInfo" cols=20 rows=5><%$UserObj->FreeformContactInfo%></TEXTAREA>
102 </TD></TR>
103 </TABLE>
104 <& /Elements/TitleBoxEnd &>
105 <br>
106
107 <& /Elements/TitleBoxStart, title => loc('Customers') &>
108 <& /Elements/EditCustomers, Object => $UserObj, CustomerString=> $CustomerString, ServiceString => $ServiceString &>
109 <br>
110
111 <& /Elements/TitleBoxStart, title => loc('Access control') &>
112 <INPUT TYPE=HIDDEN NAME="SetEnabled" VALUE="1">
113 <INPUT TYPE=CHECKBOX NAME="Enabled" VALUE="1" <%$EnabledChecked%>>
114 <&|/l&>Let this user access RT</&><BR>
115
116
117 <INPUT TYPE=HIDDEN NAME="SetPrivileged" VALUE="1">
118 <INPUT TYPE=CHECKBOX NAME="Privileged" VALUE="1" <%$PrivilegedChecked%>> <&|/l&>Let this user be granted rights</&><BR>
119                     
120 % unless ($RT::WebExternalAuth and !$RT::WebFallbackToInternalAuth) {
121 <TABLE>
122 <TR>
123 <TD ALIGN=RIGHT>
124 <&|/l&>New Password</&>:
125 </TD>
126 <TD ALIGN=LEFT>
127 <input type=password name="Pass1">
128 </TD>
129 </TR>
130 <TR><TD ALIGN=RIGHT>
131 <&|/l&>Retype Password</&>:
132 </TD>
133 <TD>
134 <input type=password name="Pass2">
135 </TD>
136 </TR>
137 </TABLE>
138 % }
139 <& /Elements/TitleBoxEnd &>
140 </TD>
141
142 <TD VALIGN=TOP class="boxcontainer">
143 <& /Elements/TitleBoxStart, title => loc('Location') &>
144 <TABLE>
145 <TR><TD ALIGN="RIGHT">
146 <&|/l&>Organization</&>: 
147 </TD><TD>
148 <input name="Organization" value="<%$UserObj->Organization%>">
149 </TD></TR>
150 <TR><TD ALIGN="RIGHT">
151 <&|/l&>Address1</&>: 
152 </TD><TD>
153 <input name="Address1" value="<%$UserObj->Address1%>">
154 </TD></TR>
155 <TR><TD ALIGN="RIGHT">
156 <&|/l&>Address2</&>: 
157 </TD><TD>
158 <input name="Address2" value="<%$UserObj->Address2%>">
159 </TD></TR>
160 <TR><TD ALIGN="RIGHT">
161 <&|/l&>City</&>: 
162 </TD><TD>
163 <input name="City" value="<%$UserObj->City%>" size=14>
164
165 </TD></TR>
166 <TR><TD ALIGN="RIGHT">
167 <&|/l&>State</&>: 
168 </TD><TD>
169 <input name="State" value="<%$UserObj->State%>" size=3>
170
171 </TD></TR>
172 <TR><TD ALIGN="RIGHT">
173 <&|/l&>Zip</&>: 
174 </TD><TD>
175 <input name="Zip" value="<%$UserObj->Zip%>" size=9>
176 </TD></TR>
177 <TR><TD ALIGN="RIGHT">
178 <&|/l&>Country</&>: 
179 </TD><TD>
180 <input name="Country" value="<%$UserObj->Country%>">
181 </TD></TR>
182 </TABLE>
183 <& /Elements/TitleBoxEnd &>
184 <br>
185 <& /Elements/TitleBoxStart, title => loc('Phone numbers') &>
186 <TABLE>
187 <TR><TD ALIGN="RIGHT">
188 <&|/l&>Residence</&>: 
189 </TD><TD>
190 <input name="HomePhone" value="<%$UserObj->HomePhone%>" size=13><br>
191 </TD></TR>
192 <TR><TD ALIGN="RIGHT">
193 <&|/l&>Work</&>: 
194 </TD><TD>
195 <input name="WorkPhone" value="<%$UserObj->WorkPhone%>" size=13><br>
196 </TD></TR>
197 <TR><TD ALIGN="RIGHT">
198 <&|/l&>Mobile</&>: 
199 </TD><TD>
200 <input name="MobilePhone" value="<%$UserObj->MobilePhone%>" size=13><br>
201 </TD></TR>
202 <TR><TD ALIGN="RIGHT">
203 <&|/l&>Pager</&>: 
204 </TD><TD>
205 <input name="PagerPhone" value="<%$UserObj->PagerPhone%>" size=13><br>
206 <& /Elements/TitleBoxEnd &>
207 </TD>
208
209 <TR>
210 </TR>
211 </TABLE>
212 <BR>
213 <& /Elements/TitleBoxStart, title => loc('Custom Fields') &>
214 <TABLE>
215 % my $CFs = $UserObj->CustomFields;
216 % while (my $CF = $CFs->Next) {
217 <TR VALIGN="TOP"><TD ALIGN="RIGHT">
218 <% $CF->Name %>:
219 </TD><TD>
220 <& /Elements/EditCustomField, %ARGS, Object => $UserObj, CustomField => $CF &>
221 </TD></TR>
222 % }
223 <TR>
224 </TR>
225 </TABLE>
226 <& /Elements/TitleBoxEnd &>
227 <TR>
228 <TD colspan="2">
229 <& /Elements/TitleBoxStart, title => loc('Comments about this user') &>
230 <TEXTAREA class="comments" name="Comments" COLS=80 ROWS=5 WRAP=VIRTUAL><%$UserObj->Comments%></TEXTAREA>
231 <& /Elements/TitleBoxEnd &>
232 %if ($UserObj->Privileged) {
233 <BR>
234 <& /Elements/TitleBoxStart, title => loc('Signature') &>
235 <TEXTAREA class="signature" COLS=80 ROWS=5 name="Signature" WRAP=HARD><%$UserObj->Signature%></TEXTAREA>
236 <& /Elements/TitleBoxEnd &>
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         } else {
298                 push @results, loc('User could not be created: [_1]', $msg);
299         }
300     } else {
301         $UserObj->Load($id) || $UserObj->Load($Name) || Abort("Couldn't load user '$Name'");
302         $val = $UserObj->Id();
303     }
304
305     if ($val) {
306         $title = loc("Modify the user [_1]", $UserObj->Name);
307     }
308
309     # If the create failed
310     else {
311         $title = loc("Create a new user");
312         $Create = 1;
313     }
314 }
315
316
317
318
319 # If we have a user to modify, lets try. 
320 if ($UserObj->Id && $id ne 'new') {
321
322     my @fields = qw(Name Comments Signature EmailAddress FreeformContactInfo 
323                     Organization RealName NickName Lang EmailEncoding WebEncoding 
324                     ExternalContactInfoId ContactInfoSystem Gecos ExternalAuthId 
325                     AuthSystem HomePhone WorkPhone MobilePhone PagerPhone Address1
326                     Address2 City State Zip Country 
327                    );
328
329     my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
330                                             Object => $UserObj,
331                                             ARGSRef => \%ARGS );
332     push (@results,@fieldresults);
333     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
334
335     #deal with freeside customer links
336     push @results, ProcessObjectCustomers( ARGSRef => \%ARGS, Object => $UserObj );
337
338     # {{{ Deal with special fields: Privileged, Enabled
339     if  ( $SetPrivileged and $Privileged != $UserObj->Privileged ) {
340          my ($code, $msg) = $UserObj->SetPrivileged($Privileged);
341          push @results, loc('Privileged status: [_1]', loc_fuzzy($msg));
342     }
343
344     #we're asking about enabled on the web page but really care about disabled.
345     $Disabled = $Enabled ? 0 : 1;
346
347     if  ( ($SetEnabled) and ( $Disabled != $UserObj->Disabled) ) { 
348         my  ($code, $msg) = $UserObj->SetDisabled($Disabled);
349         push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
350     }
351
352
353     # }}}
354 }
355
356 if ( $UserObj->Id ) {
357     my $password_not_set;
358     # Deal with Password field
359     if ( !$Pass1 and !$Pass2 ) {
360         $password_not_set = 1;
361     } elsif ( $Pass1 ne $Pass2 ) {
362         $password_not_set = 1;
363         push @results, loc("Passwords do not match.");
364     } elsif ( $Pass1 eq $Pass2 and !$UserObj->IsPassword($Pass1) ) {
365         my ($code, $msg) = $UserObj->SetPassword($Pass1);
366         push @results, loc_fuzzy($msg);
367         $password_not_set = 1 unless $code;
368     }
369     if ($id eq 'new' and $password_not_set) {
370         push @results, loc("A password was not set, so user won't be able to login.");
371     } 
372 }
373
374
375 # {{{ Do some setup for the ui
376 unless ($UserObj->Disabled()) {
377     $EnabledChecked ="CHECKED";
378 }
379
380 if ($UserObj->Privileged()) {  
381     $PrivilegedChecked = "CHECKED";
382 }
383
384 # }}}
385
386 # set the id, so the the menu will have the right info, this needs to
387 # be done here to avoid creating and then modifying a user
388 $id = $UserObj->Id;
389
390 </%INIT>
391
392
393 <%ARGS>
394 $id => undef
395 $Name  => undef
396 $Comments  => undef
397 $Signature  => undef
398 $EmailAddress  => undef
399 $FreeformContactInfo => undef
400 $Organization  => undef
401 $RealName  => undef
402 $NickName  => undef
403 $Privileged => undef
404 $SetPrivileged => undef
405 $Enabled => undef
406 $SetEnabled => undef
407 $Lang  => undef
408 $EmailEncoding  => undef
409 $WebEncoding => undef
410 $ExternalContactInfoId  => undef
411 $ContactInfoSystem  => undef
412 $Gecos => undef
413 $ExternalAuthId  => undef
414 $AuthSystem  => undef
415 $HomePhone => undef
416 $WorkPhone  => undef
417 $MobilePhone  => undef
418 $PagerPhone  => undef
419 $Address1 => undef
420 $Address2  => undef
421 $City  => undef
422 $State  => undef
423 $Zip  => undef
424 $Country => undef
425 $Pass1 => undef
426 $Pass2=> undef
427 $Create=> undef
428 $OnlySearchForCustomers => undef
429 $OnlySearchForServices => undef
430 $CustomerString => undef
431 $ServiceString => undef
432 </%ARGS>