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