summaryrefslogtreecommitdiff
path: root/httemplate/elements/contact.html
blob: 850c2540d6156c882c95446c2819bd984050b923 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
% unless ( $opt{'js_only'} ) {

  <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">

  <TABLE STYLE="display:inline">
    <TR>
%     if ( @contact_class && ! $opt{name_only} ) {
        <TD>
          <SELECT NAME="<%$name%>_classnum" <% $onchange %>>
            <OPTION VALUE="">
%           my $classnum = scalar($cgi->param($name.'_classnum'))
%                            || $X_contact->classnum;
%           foreach my $contact_class (@contact_class) {
              <OPTION VALUE="<% $contact_class->classnum %>"
                 <% ($contact_class->classnum == $classnum) ? 'SELECTED' : '' %>
              ><% $contact_class->classname |h %>
%           }
          </SELECT><BR>
          <FONT SIZE="-1">Type</FONT>
        </TD>
%     } else {
        <INPUT TYPE="hidden" NAME="<%$name%>_classnum" VALUE="">
%     }
%
%     foreach my $field ( @fields ) {
%
%       my $value = '';
%       if ( $field =~ /^phonetypenum(\d+)$/ ) {
%         my $contact_phone = qsearchs('contact_phone', {
%           'contactnum'   => $curr_value,
%           'phonetypenum' => $1,
%         });
%         if ( $contact_phone ) {
%           $value = $contact_phone->phonenum_pretty;
%           $value .= 'x'.$contact_phone->extension
%             if $contact_phone->extension;
%           $value = '+'. $contact_phone->countrycode. " $value"
%             if $contact_phone->countrycode
%             && $contact_phone->countrycode ne '1';
%         }
%       } elsif ( $field eq 'emailaddress' ) {
%         $value = join(', ', map $_->emailaddress, $contact->contact_email);
%       } elsif ( $field eq 'selfservice_access'
%              or $field eq 'comment'
%              or $field eq 'invoice_dest' ) {
%         $value = $X_contact->get($field);
%       } else {
%         $value = $contact->get($field);
%       }

        <TD>
%         if ( $field eq 'selfservice_access' ) {

            <SELECT NAME = "<%$name%>_<%$field%>"
                    ID   = "<%$id%>_<%$field%>"
                    STYLE = "width: 140px"
            >
              <OPTION VALUE="">Disabled
%             if ( $value || $self_base_url ) {
                <OPTION VALUE="Y" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
%               if ( $value eq 'Y' && $self_base_url ) {
                  <OPTION VALUE="R">Re-email
                  <OPTION VALUE="P"><% $pwd_change_label %>
%               }
%             }
            </SELECT>
                  <& /elements/change_password.html,
                   'contact_num'         => $curr_value,
                   'custnum'             => $opt{'custnum'},
                   'curr_value'          => '',
                   'no_label_display'    => '1',
                   'noformtag'           => '1',
                   'pre_pwd_field_label' => $id.'_',
                  &>
            <SCRIPT TYPE="text/javascript">
                    document.getElementById("<%$id%>_<%$field%>").onchange = function() {
                      if (this.value == "P") { changepw<%$id%>_toggle(true); }
                      return false
                    }
            </SCRIPT>
%         } elsif ( $field eq 'invoice_dest' ) {
%           my $curr_value = $cgi->param($name . '_' . $field);
%           $curr_value = $value if !defined($curr_value);
            <& select.html,
                field         => $name . '_' . $field,
                curr_value    => $curr_value,
                options       => [ '', 'Y' ],
                option_labels => { '' => 'no', 'Y' => 'yes' },
                style         => 'width: 100%',
            &>
%         } else {
            <INPUT TYPE  = "text"
                   NAME  = "<%$name%>_<%$field%>"
                   ID    = "<%$id%>_<%$field%>"
                   SIZE  = "<% $size{$field} || 14 %>"
                   VALUE = "<% scalar($cgi->param($name . '_' . $field))
                               || $value |h %>"
                   <% $onchange %>
            >
%         }
          <BR>
          <FONT SIZE="-1"><% $label{$field} %></FONT>
        </TD>
%     }
    </TR>
  </TABLE>

% }
<%init>

my( %opt ) = @_;

my $conf = new FS::Conf;

my $self_base_url = $conf->config('selfservice_server-base_url');

my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
my $id = $opt{'id'} || 'contactnum';

my $curr_value = $opt{'curr_value'} || $opt{'value'};

my $onchange = '';
if ( $opt{'onchange'} ) {
  $onchange = $opt{'onchange'};
  $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
  $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
                                        #callbacks should act the same
  $onchange = 'onChange="'. $onchange. '"';
}

my @contact_class = qsearch('contact_class', { 'disabled' => '' });

my $contact;
my $X_contact;
if ( $curr_value ) {
  $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
  if ( $opt{'custnum'} ) {
    $X_contact = qsearchs('cust_contact', {
                            'contactnum' => $curr_value,
                            'custnum'    => $opt{'custnum'},
                 });
  } elsif ( $opt{'prospectnum'} ) {
    $X_contact = qsearchs('prospect_contact', {
                   'contactnum'  => $curr_value,
                   'prospectnum' => $opt{'prospectnum'},
                 });
    $opt{'for_prospect'} = 1;
  } else {
    die 'neither custnum nor prospectnum specified';
  }
} else {
  $contact = new FS::contact {};
  if ($opt{'for_prospect'}) {
    $X_contact = new FS::prospect_contact;
  } else {
    $X_contact = new FS::cust_contact;
  }
}

my %size = ( 'title' => 12 );

tie my %label, 'Tie::IxHash',
  'first'              => 'First name',
  'last'               => 'Last name',
  'title'              => 'Title/Position',
  'emailaddress'       => 'Email'
;

unless ($opt{'for_prospect'}) {
  $label{'invoice_dest'} = 'Send&nbsp;invoices';
  $label{'selfservice_access'} = 'Self-service';
}

my $first = 0;
foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
  next if $phone_type->typename =~ /^(Home|Fax)$/;
  my $f = 'phonetypenum'.$phone_type->phonetypenum;
  $label{$f} = $phone_type->typename. ' phone';
  $size{$f} = $first++ ? 10 : 15;
}

$label{'comment'} = 'Comment';

my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;

my $pwd_change_label = 'Change Password';
$pwd_change_label = 'Setup Password' unless $contact->_password;

</%init>