enhance contacts: multiple email addresses, RT#16819
[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>
6     <TR>
7 %     foreach my $field ( @fields ) {
8 %
9 %       my $value = '';
10 %       if ( $field =~ /^phonetypenum(\d+)$/ ) {
11 %         my $contact_phone = qsearchs('contact_phone', {
12 %           'contactnum'   => $curr_value,
13 %           'phonetypenum' => $1,
14 %         });
15 %         if ( $contact_phone ) {
16 %           $value = $contact_phone->phonenum;
17 %           $value .= 'x'.$contact_phone->extension
18 %             if $contact_phone->extension;
19 %           $value = '+'. $contact_phone->countrycode. " $value"
20 %             if $contact_phone->countrycode
21 %             && $contact_phone->countrycode ne '1';
22 %         }
23 %       } elsif ( $field eq 'emailaddress' ) {
24 %         $value = join(', ', map $_->emailaddress, $contact->contact_email);
25 %       } else {
26 %         $value = $contact->get($field);
27 %       }
28
29         <TD>
30           <INPUT TYPE  = "text"
31                  NAME  = "<%$name%>_<%$field%>"
32                  ID    = "<%$id%>_<%$field%>"
33                  SIZE  = "<% $size{$field} || 15 %>"
34                  VALUE = "<% scalar($cgi->param($name."_$field"))
35                              || $value |h %>"
36                  <% $onchange %>
37           ><BR>
38           <FONT SIZE="-1"><% $label{$field} %></FONT>
39         </TD>
40 %     }
41     </TR>
42   </TABLE>
43
44 % }
45 <%init>
46
47 my( %opt ) = @_;
48
49 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
50 my $id = $opt{'id'} || 'contactnum';
51
52 my $curr_value = $opt{'curr_value'} || $opt{'value'};
53
54 my $onchange = '';
55 if ( $opt{'onchange'} ) {
56   $onchange = $opt{'onchange'};
57   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
58   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
59                                         #callbacks should act the same
60   $onchange = 'onChange="'. $onchange. '"';
61 }
62
63 my $contact;
64 if ( $curr_value ) {
65   $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
66 } else {
67   $contact = new FS::contact {};
68 }
69
70 my %size = ( 'title' => 12 );
71
72 tie my %label, 'Tie::IxHash',
73   'first'        => 'First name',
74   'last'         => 'Last name',
75   'title'        => 'Title/Position',
76   'emailaddress' => 'Email',
77 ;
78
79 my $first = 0;
80 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
81   next if $phone_type->typename eq 'Home';
82   my $f = 'phonetypenum'.$phone_type->phonetypenum;
83   $label{$f} = $phone_type->typename. ' phone';
84   $size{$f} = $first++ ? 11 : 15;
85 }
86
87 $label{'comment'} = 'Comment';
88
89 my @fields = keys %label;
90
91 </%init>