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