RT# 75817 - Added the ability to set contacts password on the backend
[freeside.git] / httemplate / elements / contact.html
1 % unless ( $opt{'js_only'} ) {
2
3   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
4
5   <TABLE STYLE="display:inline">
6     <TR>
7 %     if ( @contact_class && ! $opt{name_only} ) {
8         <TD>
9           <SELECT NAME="<%$name%>_classnum" <% $onchange %>>
10             <OPTION VALUE="">
11 %           my $classnum = scalar($cgi->param($name.'_classnum'))
12 %                            || $contact->classnum;
13 %           foreach my $contact_class (@contact_class) {
14               <OPTION VALUE="<% $contact_class->classnum %>"
15                  <% ($contact_class->classnum == $classnum) ? 'SELECTED' : '' %>
16               ><% $contact_class->classname |h %>
17 %           }
18           </SELECT><BR>
19           <FONT SIZE="-1">Type</FONT>
20         </TD>
21 %     } else {
22         <INPUT TYPE="hidden" NAME="<%$name%>_classnum" VALUE="">
23 %     }
24 %
25 %     foreach my $field ( @fields ) {
26 %
27 %       my $value = '';
28 %       if ( $field =~ /^phonetypenum(\d+)$/ ) {
29 %         my $contact_phone = qsearchs('contact_phone', {
30 %           'contactnum'   => $curr_value,
31 %           'phonetypenum' => $1,
32 %         });
33 %         if ( $contact_phone ) {
34 %           $value = $contact_phone->phonenum_pretty;
35 %           $value .= 'x'.$contact_phone->extension
36 %             if $contact_phone->extension;
37 %           $value = '+'. $contact_phone->countrycode. " $value"
38 %             if $contact_phone->countrycode
39 %             && $contact_phone->countrycode ne '1';
40 %         }
41 %       } elsif ( $field eq 'emailaddress' ) {
42 %         $value = join(', ', map $_->emailaddress, $contact->contact_email);
43 %       } else {
44 %         $value = $contact->get($field);
45 %       }
46
47         <TD>
48 %         if ( $field eq 'selfservice_access' ) {
49             <SELECT NAME = "<%$name%>_<%$field%>"
50                     ID   = "<%$id%>_<%$field%>"
51             >
52               <OPTION VALUE="">Disabled
53 %             if ( $value || $self_base_url ) {
54                 <OPTION VALUE="Y" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
55 %               if ( $value eq 'Y' && $self_base_url ) {
56                   <OPTION VALUE="R">Re-email
57 %               }
58 %             }
59             </SELECT>
60
61 %         } else {
62             <INPUT TYPE  = "text"
63                    NAME  = "<%$name%>_<%$field%>"
64                    ID    = "<%$id%>_<%$field%>"
65                    SIZE  = "<% $size{$field} || 14 %>"
66                    VALUE = "<% scalar($cgi->param($name."_$field"))
67                                || $value |h %>"
68                    <% $onchange %>
69             >
70 %         }
71           <BR>
72           <FONT SIZE="-1"><% $label{$field} %></FONT>
73         </TD>
74 %     }
75 %     my $pwd_change_label = 'change password';
76 %     $pwd_change_label = 'setup password' unless $contact->_password;
77 %     if ($curr_value) {
78         <TD>
79           <span STYLE="white-space: nowrap">
80             <& /elements/change_password.html,
81               'contact_num' => $curr_value,
82               'custnum'     => $opt{'custnum'},
83               'curr_value'  => '',
84               'label'       => $pwd_change_label,
85             &>
86           </span>
87           <br>
88           <FONT SIZE="-1">Password</FONT>
89         </TD>
90 %     }
91     </TR>
92   </TABLE>
93
94 % }
95 <%init>
96
97 my( %opt ) = @_;
98
99 my $conf = new FS::Conf;
100 my $self_base_url = $conf->config('selfservice_server-base_url');
101
102 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
103 my $id = $opt{'id'} || 'contactnum';
104
105 my $curr_value = $opt{'curr_value'} || $opt{'value'};
106
107 my $onchange = '';
108 if ( $opt{'onchange'} ) {
109   $onchange = $opt{'onchange'};
110   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
111   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
112                                         #callbacks should act the same
113   $onchange = 'onChange="'. $onchange. '"';
114 }
115
116 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
117
118 my $contact;
119 if ( $curr_value ) {
120   $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
121 } else {
122   $contact = new FS::contact {};
123 }
124
125 my %size = ( 'title' => 12 );
126
127 tie my %label, 'Tie::IxHash',
128   'first'              => 'First name',
129   'last'               => 'Last name',
130   'title'              => 'Title/Position',
131   'emailaddress'       => 'Email',
132   'selfservice_access' => 'Self-service'
133 ;
134
135 my $first = 0;
136 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
137   next if $phone_type->typename =~ /^(Home|Fax)$/;
138   my $f = 'phonetypenum'.$phone_type->phonetypenum;
139   $label{$f} = $phone_type->typename. ' phone';
140   $size{$f} = $first++ ? 10 : 15;
141 }
142
143 $label{'comment'} = 'Comment';
144
145 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
146
147 </%init>