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