RT# 75817 - fixed bug to only send email out to contact that is being enabled not...
[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
54             <SELECT NAME = "<%$name%>_<%$field%>"
55                     ID   = "<%$id%>_<%$field%>"
56                     STYLE = "width: 140px"
57             >
58               <OPTION VALUE="">Disabled
59 %             if ( $value || $self_base_url ) {
60                 <OPTION VALUE="<% $value eq 'Y' ? 'Y' : 'E' %>" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
61 %               if ( $value eq 'Y' && $self_base_url ) {
62                   <OPTION VALUE="R">Re-email
63                   <OPTION VALUE="P"><% $pwd_change_label %>
64 %               }
65 %             }
66             </SELECT>
67                   <& /elements/change_password.html,
68                    'contact_num'         => $curr_value,
69                    'custnum'             => $opt{'custnum'},
70                    'curr_value'          => '',
71                    'no_label_display'    => '1',
72                    'noformtag'           => '1',
73                    'pre_pwd_field_label' => $id.'_',
74                   &>
75             <SCRIPT TYPE="text/javascript">
76                     document.getElementById("<%$id%>_<%$field%>").onchange = function() {
77                       if (this.value == "P" || this.value == "E") { changepw<%$id%>_toggle(true); }
78                       return false
79                     }
80             </SCRIPT>
81 %         } elsif ( $field eq 'invoice_dest' ) {
82 %           my $curr_value = $cgi->param($name . '_' . $field);
83 %           $curr_value = $value if !defined($curr_value);
84             <& select.html,
85                 field         => $name . '_' . $field,
86                 curr_value    => $curr_value,
87                 options       => [ '', 'Y' ],
88                 option_labels => { '' => 'no', 'Y' => 'yes' },
89                 style         => 'width: 100%',
90             &>
91 %         } else {
92             <INPUT TYPE  = "text"
93                    NAME  = "<%$name%>_<%$field%>"
94                    ID    = "<%$id%>_<%$field%>"
95                    SIZE  = "<% $size{$field} || 14 %>"
96                    VALUE = "<% scalar($cgi->param($name . '_' . $field))
97                                || $value |h %>"
98                    <% $onchange %>
99             >
100 %         }
101           <BR>
102           <FONT SIZE="-1"><% $label{$field} %></FONT>
103         </TD>
104 %     }
105     </TR>
106   </TABLE>
107
108 % }
109 <%init>
110
111 my( %opt ) = @_;
112
113 my $conf = new FS::Conf;
114
115 my $self_base_url = $conf->config('selfservice_server-base_url');
116
117 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
118 my $id = $opt{'id'} || 'contactnum';
119
120 my $curr_value = $opt{'curr_value'} || $opt{'value'};
121
122 my $onchange = '';
123 if ( $opt{'onchange'} ) {
124   $onchange = $opt{'onchange'};
125   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
126   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
127                                         #callbacks should act the same
128   $onchange = 'onChange="'. $onchange. '"';
129 }
130
131 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
132
133 my $contact;
134 my $X_contact;
135 if ( $curr_value ) {
136   $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
137   if ( $opt{'custnum'} ) {
138     $X_contact = qsearchs('cust_contact', {
139                             'contactnum' => $curr_value,
140                             'custnum'    => $opt{'custnum'},
141                  });
142   } elsif ( $opt{'prospectnum'} ) {
143     $X_contact = qsearchs('prospect_contact', {
144                    'contactnum'  => $curr_value,
145                    'prospectnum' => $opt{'prospectnum'},
146                  });
147     $opt{'for_prospect'} = 1;
148   } else {
149     die 'neither custnum nor prospectnum specified';
150   }
151 } else {
152   $contact = new FS::contact {};
153   if ($opt{'for_prospect'}) {
154     $X_contact = new FS::prospect_contact;
155   } else {
156     $X_contact = new FS::cust_contact;
157   }
158 }
159
160 my %size = ( 'title' => 12 );
161
162 tie my %label, 'Tie::IxHash',
163   'first'              => 'First name',
164   'last'               => 'Last name',
165   'title'              => 'Title/Position',
166   'emailaddress'       => 'Email'
167 ;
168
169 unless ($opt{'for_prospect'}) {
170   $label{'invoice_dest'} = 'Send&nbsp;invoices';
171   $label{'selfservice_access'} = 'Self-service';
172 }
173
174 my $first = 0;
175 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
176   next if $phone_type->typename =~ /^(Home|Fax)$/;
177   my $f = 'phonetypenum'.$phone_type->phonetypenum;
178   $label{$f} = $phone_type->typename. ' phone';
179   $size{$f} = $first++ ? 10 : 15;
180 }
181
182 $label{'comment'} = 'Comment';
183
184 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
185
186 my $pwd_change_label = 'Change Password';
187 $pwd_change_label = 'Setup Password' unless $contact->_password;
188
189 </%init>