1 % unless ( $opt{'js_only'} ) {
3 <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
5 <TABLE STYLE="display:inline">
7 % if ( @contact_class && ! $opt{name_only} ) {
9 <SELECT NAME="<%$name%>_classnum" <% $onchange %>>
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 %>
19 <FONT SIZE="-1">Type</FONT>
22 <INPUT TYPE="hidden" NAME="<%$name%>_classnum" VALUE="">
25 % foreach my $field ( @fields ) {
28 % if ( $field =~ /^phonetypenum(\d+)$/ ) {
29 % my $contact_phone = qsearchs('contact_phone', {
30 % 'contactnum' => $curr_value,
31 % 'phonetypenum' => $1,
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';
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);
50 % $value = $contact->get($field);
54 % if ( $field eq 'selfservice_access' ) {
56 <SELECT NAME = "<%$name%>_<%$field%>"
57 ID = "<%$id%>_<%$field%>"
58 STYLE = "width: 140px"
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
69 % } elsif ( $field eq 'password') {
71 NAME = "<%$name%>_<%$field%>"
72 ID = "changepw<%$id%>_<%$field%>"
73 SIZE = "<% $size{$field} || 14 %>"
75 placeholder = "<% $value |h %>"
77 % my $contactnum = $curr_value ? $curr_value : '0';
80 add_password_validation('<% "changepw".$id."_password" %>', 'submit', '', '<% $contactnum %>');
83 <SCRIPT TYPE="text/javascript">
84 var selfService = document.getElementById("<%$id%>_selfservice_access").value;
86 if (selfService !== "Y") { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
87 document.getElementById("<%$id%>_selfservice_access").onchange = function() {
88 if (this.value == "P" || this.value == "E" || this.value =="Y") {
89 document.getElementById("changepw<%$id%>_password").disabled = '';
91 else { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
95 % } elsif ( $field eq 'invoice_dest' ) {
96 % my $curr_value = $cgi->param($name . '_' . $field);
97 % $curr_value = $value if !defined($curr_value);
99 field => $name . '_' . $field,
100 curr_value => $curr_value,
101 options => [ '', 'Y' ],
102 option_labels => { '' => 'no', 'Y' => 'yes' },
103 style => 'width: 100%',
107 NAME = "<%$name%>_<%$field%>"
108 ID = "<%$id%>_<%$field%>"
109 SIZE = "<% $size{$field} || 14 %>"
110 VALUE = "<% scalar($cgi->param($name . '_' . $field))
116 <FONT SIZE="-1"><% $label{$field} %></FONT>
117 % if ( $field eq 'password' ) {
118 <div id="changepw<%$id%>_<%$field%>_result"></div>
130 my $conf = new FS::Conf;
132 my $self_base_url = $conf->config('selfservice_server-base_url');
134 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
135 my $id = $opt{'id'} || 'contactnum';
137 my $curr_value = $opt{'curr_value'} || $opt{'value'};
140 if ( $opt{'onchange'} ) {
141 $onchange = $opt{'onchange'};
142 $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
143 $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange
144 #callbacks should act the same
145 $onchange = 'onChange="'. $onchange. '"';
148 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
153 $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
154 if ( $opt{'custnum'} ) {
155 $X_contact = qsearchs('cust_contact', {
156 'contactnum' => $curr_value,
157 'custnum' => $opt{'custnum'},
159 } elsif ( $opt{'prospectnum'} ) {
160 $X_contact = qsearchs('prospect_contact', {
161 'contactnum' => $curr_value,
162 'prospectnum' => $opt{'prospectnum'},
164 $opt{'for_prospect'} = 1;
166 die 'neither custnum nor prospectnum specified';
169 $contact = new FS::contact {};
170 if ($opt{'for_prospect'}) {
171 $X_contact = new FS::prospect_contact;
173 $X_contact = new FS::cust_contact;
177 my %size = ( 'title' => 12 );
179 tie my %label, 'Tie::IxHash',
180 'first' => 'First name',
181 'last' => 'Last name',
182 'title' => 'Title/Position',
183 'emailaddress' => 'Email'
186 unless ($opt{'for_prospect'}) {
187 $label{'invoice_dest'} = 'Send invoices';
188 $label{'selfservice_access'} = 'Self-service';
189 $label{'password'} = 'Password';
193 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
194 next if $phone_type->typename =~ /^(Home|Fax)$/;
195 my $f = 'phonetypenum'.$phone_type->phonetypenum;
196 $label{$f} = $phone_type->typename. ' phone';
197 $size{$f} = $first++ ? 10 : 15;
200 $label{'comment'} = 'Comment';
202 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;