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