spacing, RT#83503
[freeside.git] / httemplate / elements / contact.html
1 % if ( $opt{'js_only'} ) {
2 <% $js %>
3 % } else {
4
5   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
6
7   <TABLE STYLE="display:inline">
8     <TR>
9 %     if ( @contact_class && ! $opt{name_only} ) {
10         <TD>
11           <SELECT NAME="<%$name%>_classnum" <% $onchange %>>
12             <OPTION VALUE="">
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 %>
19 %           }
20           </SELECT><BR>
21           <FONT SIZE="-1">Type</FONT>
22         </TD>
23 %     } else {
24         <INPUT TYPE="hidden" NAME="<%$name%>_classnum" VALUE="">
25 %     }
26 %
27 %     foreach my $field ( @fields ) {
28 %
29 %       my $value = '';
30 %       if ( $field =~ /^phonetypenum(\d+)$/ ) {
31 %         my $contact_phone = qsearchs('contact_phone', {
32 %           'contactnum'   => $curr_value,
33 %           'phonetypenum' => $1,
34 %         });
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';
42 %         }
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);
52 %       } else {
53 %         $value = $contact->get($field);
54 %       }
55
56         <TD>
57 %         if ( $field eq 'selfservice_access' ) {
58
59             <SELECT NAME = "<%$name%>_<%$field%>"
60                     ID   = "<%$id%>_<%$field%>"
61                     STYLE = "width: 140px"
62             >
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
68 %               }
69 %             }
70             </SELECT>
71 % #password form
72 %         } elsif ( $field eq 'password') {
73             <INPUT TYPE  = "text"
74                    NAME  = "<%$name%>_<%$field%>"
75                    ID    = "changepw<%$id%>_<%$field%>"
76                    SIZE  = "<% $size{$field} || 14 %>"
77                    VALUE = ""
78                    placeholder = "<% $value |h %>"
79             >
80             <SCRIPT>
81               <% $js %>
82             </SCRIPT>
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);
86             <& select.html,
87                 field         => $name . '_' . $field,
88                 curr_value    => $curr_value,
89                 options       => [ '', 'Y' ],
90                 option_labels => { '' => 'no', 'Y' => 'yes' },
91                 style         => 'width: 100%',
92             &>
93 %         } else {
94             <INPUT TYPE  = "text"
95                    NAME  = "<%$name%>_<%$field%>"
96                    ID    = "<%$id%>_<%$field%>"
97                    SIZE  = "<% $size{$field} || 14 %>"
98                    VALUE = "<% scalar($cgi->param($name . '_' . $field))
99                                || $value |h %>"
100                    <% $onchange %>
101             >
102 %         }
103           <BR>
104           <FONT SIZE="-1"><% $label{$field} %></FONT>
105 %       if ( $field eq 'password' ) {
106           <DIV ID="changepw<%$id%>_<%$field%>_result" STYLE="font-size: smaller"></DIV>
107 %       }
108         </TD>
109 %     }
110     </TR>
111   </TABLE>
112
113 % }
114 <%init>
115
116 my( %opt ) = @_;
117
118 my $conf = new FS::Conf;
119
120 my $self_base_url = $conf->config('selfservice_server-base_url');
121
122 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
123 my $id = $opt{'id'} || 'contactnum';
124
125 my $curr_value = $opt{'curr_value'} || $opt{'value'};
126 my $contactnum = $curr_value ? $curr_value : '0';
127
128 my $onchange = '';
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. '"';
135 }
136
137 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
138
139 my $contact;
140 my $X_contact;
141 if ( $curr_value ) {
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'},
147                  });
148   } elsif ( $opt{'prospectnum'} ) {
149     $X_contact = qsearchs('prospect_contact', {
150                    'contactnum'  => $curr_value,
151                    'prospectnum' => $opt{'prospectnum'},
152                  });
153     $opt{'for_prospect'} = 1;
154   } else {
155     die 'neither custnum nor prospectnum specified';
156   }
157 } else {
158   $contact = new FS::contact {};
159   if ($opt{'for_prospect'}) {
160     $X_contact = new FS::prospect_contact;
161   } else {
162     $X_contact = new FS::cust_contact;
163   }
164 }
165
166 my %size = ( 'title' => 12 );
167
168 tie my %label, 'Tie::IxHash',
169   'first'              => 'First name',
170   'last'               => 'Last name',
171   'title'              => 'Title/Position',
172   'emailaddress'       => 'Email'
173 ;
174
175 unless ($opt{'for_prospect'}) {
176   $label{'invoice_dest'} = 'Send&nbsp;invoices';
177   $label{'message_dest'} = 'Send&nbsp;messages';
178   $label{'selfservice_access'} = 'Self-service';
179   $label{'password'} = 'Password';
180 }
181
182 my $first = 0;
183 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
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;
188 }
189
190 $label{'comment'} = 'Comment';
191
192 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
193
194 my $submitid = $opt{'submit_id'} ? $opt{'submit_id'} : 'submit';
195
196 my $js = qq(
197     add_password_validation('changepw$id\_password', '$submitid', '', '$contactnum');
198
199     var selfService = document.getElementById("$id\_selfservice_access").value;
200
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 = '';
205       }
206       else { document.getElementById("changepw$id\_password").disabled = 'true'; }
207       return false;
208     }
209 ) unless $opt{'for_prospect'};
210
211 </%init>