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