1 % if ( $opt{'js_only'} ) {
5 <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
7 <TABLE STYLE="display:inline">
9 % if ( @contact_class && ! $opt{name_only} ) {
11 <SELECT NAME="<%$name%>_classnum" <% $onchange %>>
13 % my $classnum = scalar($cgi->param($name.'_classnum'))
14 % || $X_contact->classnum;
15 % foreach my $contact_class (@contact_class) {
16 <OPTION VALUE="<% $contact_class->classnum %>"
17 <% ($contact_class->classnum == $classnum) ? 'SELECTED' : '' %>
18 ><% $contact_class->classname |h %>
21 <FONT SIZE="-1">Type</FONT>
24 <INPUT TYPE="hidden" NAME="<%$name%>_classnum" VALUE="">
27 % foreach my $field ( @fields ) {
30 % if ( $field =~ /^phonetypenum(\d+)$/ ) {
31 % my $contact_phone = qsearchs('contact_phone', {
32 % 'contactnum' => $curr_value,
33 % 'phonetypenum' => $1,
35 % if ( $contact_phone ) {
36 % $value = $contact_phone->phonenum_pretty;
37 % $value .= 'x'.$contact_phone->extension
38 % if $contact_phone->extension;
39 % $value = '+'. $contact_phone->countrycode. " $value"
40 % if $contact_phone->countrycode
41 % && $contact_phone->countrycode ne '1';
43 % } elsif ( $field eq 'emailaddress' ) {
44 % $value = join(', ', map $_->emailaddress, $contact->contact_email);
45 % } elsif ( $field eq 'password' ) {
46 % $value = $contact->get('_password') ? '********' : '';
47 % } elsif ( $field eq 'selfservice_access'
48 % or $field eq 'comment'
49 % or $field eq 'invoice_dest'
50 % or $field eq 'message_dest' ) {
51 % $value = $X_contact->get($field);
53 % $value = $contact->get($field);
57 % if ( $field eq 'selfservice_access' ) {
59 <SELECT NAME = "<%$name%>_<%$field%>"
60 ID = "<%$id%>_<%$field%>"
61 STYLE = "width: 140px"
63 <OPTION VALUE="" <% !$value ? 'SELECTED' : '' %>>Disabled
64 % if ( $value || $self_base_url ) {
65 <OPTION VALUE="<% $value eq 'Y' ? 'Y' : 'E' %>" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
66 % if ( $value eq 'Y' && $self_base_url ) {
67 <OPTION VALUE="R">Re-email
72 % } elsif ( $field eq 'password') {
74 NAME = "<%$name%>_<%$field%>"
75 ID = "changepw<%$id%>_<%$field%>"
76 SIZE = "<% $size{$field} || 14 %>"
78 placeholder = "<% $value |h %>"
83 % } elsif ( $field eq 'invoice_dest' || $field eq 'message_dest' ) {
84 % my $curr_value = $cgi->param($name . '_' . $field);
85 % $curr_value = $value if !defined($curr_value);
87 field => $name . '_' . $field,
88 curr_value => $curr_value,
89 options => [ '', 'Y' ],
90 option_labels => { '' => 'no', 'Y' => 'yes' },
91 style => 'width: 100%',
95 NAME = "<%$name%>_<%$field%>"
96 ID = "<%$id%>_<%$field%>"
97 SIZE = "<% $size{$field} || 14 %>"
98 VALUE = "<% scalar($cgi->param($name . '_' . $field))
104 <FONT SIZE="-1"><% $label{$field} %></FONT>
105 % if ( $field eq 'password' ) {
106 <DIV ID="changepw<%$id%>_<%$field%>_result" STYLE="font-size: smaller"></DIV>
118 my $conf = new FS::Conf;
120 my $self_base_url = $conf->config('selfservice_server-base_url');
122 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
123 my $id = $opt{'id'} || 'contactnum';
125 my $curr_value = $opt{'curr_value'} || $opt{'value'};
126 my $contactnum = $curr_value ? $curr_value : '0';
129 if ( $opt{'onchange'} ) {
130 $onchange = $opt{'onchange'};
131 $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
132 $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange
133 #callbacks should act the same
134 $onchange = 'onChange="'. $onchange. '"';
137 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
142 $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
143 if ( $opt{'custnum'} ) {
144 $X_contact = qsearchs('cust_contact', {
145 'contactnum' => $curr_value,
146 'custnum' => $opt{'custnum'},
148 } elsif ( $opt{'prospectnum'} ) {
149 $X_contact = qsearchs('prospect_contact', {
150 'contactnum' => $curr_value,
151 'prospectnum' => $opt{'prospectnum'},
153 $opt{'for_prospect'} = 1;
155 die 'neither custnum nor prospectnum specified';
158 $contact = new FS::contact {};
159 if ($opt{'for_prospect'}) {
160 $X_contact = new FS::prospect_contact;
162 $X_contact = new FS::cust_contact;
166 my %size = ( 'title' => 12 );
168 tie my %label, 'Tie::IxHash',
169 'first' => 'First name',
170 'last' => 'Last name',
171 'title' => 'Title/Position',
172 'emailaddress' => 'Email'
175 unless ($opt{'for_prospect'}) {
176 $label{'invoice_dest'} = 'Send invoices';
177 $label{'message_dest'} = 'Send messages';
178 $label{'selfservice_access'} = 'Self-service';
179 $label{'password'} = 'Password';
183 foreach my $phone_type ( FS::phone_type->get_phone_types() ) {
184 next if $phone_type->typename =~ /^(Home|Fax)$/;
185 my $f = 'phonetypenum'.$phone_type->phonetypenum;
186 $label{$f} = $phone_type->typename. ' phone';
187 $size{$f} = $first++ ? 10 : 15;
190 $label{'comment'} = 'Comment';
192 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
194 my $submitid = $opt{'submit_id'} ? $opt{'submit_id'} : 'submit';
197 add_password_validation('changepw$id\_password', '$submitid', '', '$contactnum');
199 var selfService = document.getElementById("$id\_selfservice_access").value;
201 if (selfService !== "Y") { document.getElementById("changepw$id\_password").disabled = 'true'; }
202 document.getElementById("$id\_selfservice_access").onchange = function() {
203 if (this.value == "P" || this.value == "E" || this.value =="Y") {
204 document.getElementById("changepw$id\_password").disabled = '';
206 else { document.getElementById("changepw$id\_password").disabled = 'true'; }
209 ) unless $opt{'for_prospect'};