prevent unnecessary wrapping
[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 STYLE="display:inline">
6     <TR>
7 %     if ( @contact_class && ! $opt{name_only} ) {
8         <TD>
9           <SELECT NAME="<%$name%>_classnum" <% $onchange %>>
10             <OPTION VALUE="">
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 %>
17 %           }
18           </SELECT><BR>
19           <FONT SIZE="-1">Type</FONT>
20         </TD>
21 %     } else {
22         <INPUT TYPE="hidden" NAME="<%$name%>_classnum" VALUE="">
23 %     }
24 %
25 %     foreach my $field ( @fields ) {
26 %
27 %       my $value = '';
28 %       if ( $field =~ /^phonetypenum(\d+)$/ ) {
29 %         my $contact_phone = qsearchs('contact_phone', {
30 %           'contactnum'   => $curr_value,
31 %           'phonetypenum' => $1,
32 %         });
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';
40 %         }
41 %       } elsif ( $field eq 'emailaddress' ) {
42 %         $value = join(', ', map $_->emailaddress, $contact->contact_email);
43 %       } elsif ( $field eq 'selfservice_access'
44 %              or $field eq 'comment'
45 %              or $field eq 'invoice_dest' ) {
46 %         $value = $X_contact->get($field);
47 %       } else {
48 %         $value = $contact->get($field);
49 %       }
50
51         <TD>
52 %         if ( $field eq 'selfservice_access' ) {
53             <SELECT NAME = "<%$name%>_<%$field%>"
54                     ID   = "<%$id%>_<%$field%>"
55             >
56               <OPTION VALUE="">Disabled
57 %             if ( $value || $self_base_url ) {
58                 <OPTION VALUE="Y" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
59 %               if ( $value eq 'Y' && $self_base_url ) {
60                   <OPTION VALUE="R">Re-email
61 %               }
62 %             }
63             </SELECT>
64 %         } elsif ( $field eq 'invoice_dest' ) {
65 %           my $curr_value = $cgi->param($name . '_' . $field);
66 %           $curr_value = $value if !defined($curr_value);
67             <& select.html,
68                 field         => $name . '_' . $field,
69                 curr_value    => $curr_value,
70                 options       => [ '', 'Y' ],
71                 option_labels => { '' => 'no', 'Y' => 'yes' },
72                 style         => 'width: 100%',
73             &>
74 %         } else {
75             <INPUT TYPE  = "text"
76                    NAME  = "<%$name%>_<%$field%>"
77                    ID    = "<%$id%>_<%$field%>"
78                    SIZE  = "<% $size{$field} || 14 %>"
79                    VALUE = "<% scalar($cgi->param($name . '_' . $field))
80                                || $value |h %>"
81                    <% $onchange %>
82             >
83 %         }
84           <BR>
85           <FONT SIZE="-1"><% $label{$field} %></FONT>
86         </TD>
87 %     }
88 %     my $pwd_change_label = 'change';
89 %     $pwd_change_label = 'setup' unless $contact->_password;
90 %     my $action = $fsurl . "edit/cust_main-contacts-password.html?custnum=" . $opt{'custnum'} . "&contactnum=" . $curr_value . "&label=" . $pwd_change_label . "&popup=1";
91 %     if ($curr_value) {
92         <TD>
93           <% include('/elements/popup_link.html',
94                          'action'      => $action,
95                          'width'       => '763',
96                          'height'      => '408',
97                          'actionlabel' => "$pwd_change_label password",
98                          'html_label'  => "$pwd_change_label password",
99
100                     )
101           %>
102           <br>
103           <FONT SIZE="-1">Password</FONT>
104         </TD>
105 %     }
106     </TR>
107   </TABLE>
108
109 % }
110 <%init>
111
112 my( %opt ) = @_;
113
114 my $conf = new FS::Conf;
115
116 use Data::Dumper;
117 print Dumper($conf->config);
118
119 my $self_base_url = $conf->config('selfservice_server-base_url');
120
121 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
122 my $id = $opt{'id'} || 'contactnum';
123
124 my $curr_value = $opt{'curr_value'} || $opt{'value'};
125
126 my $onchange = '';
127 if ( $opt{'onchange'} ) {
128   $onchange = $opt{'onchange'};
129   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
130   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
131                                         #callbacks should act the same
132   $onchange = 'onChange="'. $onchange. '"';
133 }
134
135 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
136
137 my $contact;
138 my $X_contact;
139 if ( $curr_value ) {
140   $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
141   if ( $opt{'custnum'} ) {
142     $X_contact = qsearchs('cust_contact', {
143                             'contactnum' => $curr_value,
144                             'custnum'    => $opt{'custnum'},
145                  });
146   } elsif ( $opt{'prospectnum'} ) {
147     $X_contact = qsearchs('prospect_contact', {
148                    'contactnum'  => $curr_value,
149                    'prospectnum' => $opt{'prospectnum'},
150                  });
151     $opt{'for_prospect'} = 1;
152   } else {
153     die 'neither custnum nor prospectnum specified';
154   }
155 } else {
156   $contact = new FS::contact {};
157   if ($opt{'for_prospect'}) {
158     $X_contact = new FS::prospect_contact;
159   } else {
160     $X_contact = new FS::cust_contact;
161   }
162 }
163
164 my %size = ( 'title' => 12 );
165
166 tie my %label, 'Tie::IxHash',
167   'first'              => 'First name',
168   'last'               => 'Last name',
169   'title'              => 'Title/Position',
170   'emailaddress'       => 'Email'
171 ;
172
173 unless ($opt{'for_prospect'}) {
174   $label{'invoice_dest'} = 'Send&nbsp;invoices';
175   $label{'selfservice_access'} = 'Self-service';
176 }
177
178 my $first = 0;
179 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
180   next if $phone_type->typename =~ /^(Home|Fax)$/;
181   my $f = 'phonetypenum'.$phone_type->phonetypenum;
182   $label{$f} = $phone_type->typename. ' phone';
183   $size{$f} = $first++ ? 10 : 15;
184 }
185
186 $label{'comment'} = 'Comment';
187
188 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
189
190 </%init>