RT# 75817 - removed change password link as it is not needed anymore
[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 %       } elsif ( $field eq 'password' ) {
44 %          $value = $contact->get('_password') ? '********' : '';
45 %       } else {
46 %         $value = $contact->get($field);
47 %       }
48
49         <TD>
50 %         if ( $field eq 'selfservice_access' ) {
51
52             <SELECT NAME = "<%$name%>_<%$field%>"
53                     ID   = "<%$id%>_<%$field%>"
54                     STYLE = "width: 140px"
55             >
56               <OPTION VALUE="" <% !$value ? 'SELECTED' : '' %>>Disabled
57 %             if ( $value || $self_base_url ) {
58                 <OPTION VALUE="<% $value eq 'Y' ? 'Y' : 'E' %>" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
59 %               if ( $value eq 'Y' && $self_base_url ) {
60                   <OPTION VALUE="R">Re-email
61 %               }
62 %             }
63             </SELECT>
64 % #password form
65 %         } elsif ( $field eq 'password') {
66             <INPUT TYPE  = "text"
67                    NAME  = "<%$name%>_<%$field%>"
68                    ID    = "changepw<%$id%>_<%$field%>"
69                    SIZE  = "<% $size{$field} || 14 %>"
70                    VALUE = ""
71                    placeholder = "<% $value |h %>"
72             >
73 %           my $contactnum = $curr_value ? $curr_value : '0';
74             <& '/elements/validate_password.html',
75              'fieldid'    => "changepw".$id."_password",
76              'svcnum'     => '',
77              'contactnum' => $contactnum,
78              'submitid'   => "submit",
79            &>
80
81             <SCRIPT TYPE="text/javascript">
82                     var selfService = document.getElementById("<%$id%>_selfservice_access").value;
83
84                     if (selfService !== "Y") { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
85                     document.getElementById("<%$id%>_selfservice_access").onchange = function() {
86                       if (this.value == "P" || this.value == "E" || this.value =="Y") {
87                         document.getElementById("changepw<%$id%>_password").disabled = '';
88                       }
89                       else { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
90                       return false;
91                     }
92             </SCRIPT>
93 %         } elsif ( $field eq 'invoice_dest' ) {
94 %           my $curr_value = $cgi->param($name . '_' . $field);
95 %           $curr_value = $value if !defined($curr_value);
96             <& select.html,
97                 field         => $name . '_' . $field,
98                 curr_value    => $curr_value,
99                 options       => [ '', 'Y' ],
100                 option_labels => { '' => 'no', 'Y' => 'yes' },
101                 style         => 'width: 100%',
102             &>
103 %         } else {
104             <INPUT TYPE  = "text"
105                    NAME  = "<%$name%>_<%$field%>"
106                    ID    = "<%$id%>_<%$field%>"
107                    SIZE  = "<% $size{$field} || 14 %>"
108                    VALUE = "<% scalar($cgi->param($name."_$field"))
109                                || $value |h %>"
110                    <% $onchange %>
111             >
112 %         }
113           <BR>
114           <FONT SIZE="-1"><% $label{$field} %></FONT>
115 %       if ( $field eq 'password' ) {
116           <div id="changepw<%$id%>_<%$field%>_result"></div>
117 %       }
118         </TD>
119 %     }
120     </TR>
121   </TABLE>
122
123 % }
124 <%init>
125
126 my( %opt ) = @_;
127
128 my $conf = new FS::Conf;
129
130 my $self_base_url = $conf->config('selfservice_server-base_url');
131
132 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
133 my $id = $opt{'id'} || 'contactnum';
134
135 my $curr_value = $opt{'curr_value'} || $opt{'value'};
136
137 my $onchange = '';
138 if ( $opt{'onchange'} ) {
139   $onchange = $opt{'onchange'};
140   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
141   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
142                                         #callbacks should act the same
143   $onchange = 'onChange="'. $onchange. '"';
144 }
145
146 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
147
148 my $contact;
149 if ( $curr_value ) {
150   $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
151 } else {
152   $contact = new FS::contact {};
153 }
154
155 my %size = ( 'title' => 12 );
156
157 tie my %label, 'Tie::IxHash',
158   'first'              => 'First name',
159   'last'               => 'Last name',
160   'title'              => 'Title/Position',
161   'emailaddress'       => 'Email',
162   'selfservice_access' => 'Self-service'
163 ;
164
165 unless ($opt{'for_prospect'}) {
166   $label{'selfservice_access'} = 'Self-service';
167   $label{'password'} = 'Password';
168 }
169
170 my $first = 0;
171 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
172   next if $phone_type->typename =~ /^(Home|Fax)$/;
173   my $f = 'phonetypenum'.$phone_type->phonetypenum;
174   $label{$f} = $phone_type->typename. ' phone';
175   $size{$f} = $first++ ? 10 : 15;
176 }
177
178 $label{'comment'} = 'Comment';
179
180 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
181
182 </%init>