fix display of contacts on customer basics tab, #25536
[freeside.git] / httemplate / view / svc_phone.cgi
1 <& elements/svc_Common.html,
2               'table'     => 'svc_phone',
3               'fields'    => \@fields,
4               'labels'    => \%labels,
5               'html_foot' => $html_foot,
6 &>
7 <%init>
8
9 my $conf = new FS::Conf;
10 my $countrydefault = $conf->config('countrydefault') || 'US';
11
12 my $fields = FS::svc_phone->table_info->{'fields'};
13 my %labels = map { $_ =>  ( ref($fields->{$_})
14                              ? $fields->{$_}{'label'}
15                              : $fields->{$_}
16                          );
17                  } keys %$fields;
18
19 my @fields = qw( countrycode phonenum sim_imsi );
20 push @fields, 'domain' if $conf->exists('svc_phone-domain');
21 push @fields, qw( pbx_title );
22 $labels{pbx_title} = 'PBX';
23
24 if ( $conf->exists('showpasswords') ) {
25   push @fields, qw( sip_password );
26 } else {
27   push @fields, { 'field' => 'sip_password', #'_HIDDEN_sip_password',
28                   'type'  => 'fixed',
29                   'value' => '<I>('. mt('hidden') .')</I>',
30                 };
31 }
32
33 push @fields, qw( pin phone_name forwarddst email );
34
35 push @fields, { field => 'sms_carrierid', 
36                 #type=>'cdr_carrier',
37                 value_callback => sub {
38                   $_[0]->sms_carriername,
39                 },
40               },
41               'sms_account',
42               'max_simultaneous',
43 ;
44
45 if ( $conf->exists('svc_phone-lnp') ) {
46   push @fields, 'lnp_status',
47                 'lnp_reject_reason',
48                 { field => 'portable', type => 'checkbox', },
49                 'lrn',
50                 { field => 'lnp_desired_due_date', type => 'date', },
51                 { field => 'lnp_due_date', type => 'date', },
52                 'lnp_other_provider',
53                 'lnp_other_provider_account',
54   ;
55 }
56
57 $labels{circuit_label} = mt('Circuit');
58 push @fields, { field => 'circuit_label',
59                 link => [ $p.'view/svc_circuit.cgi?', 'circuit_svcnum' ]
60               };
61
62 push @fields, 'sip_server';
63
64 my $html_foot = sub {
65   my $svc_phone = shift;
66
67   ###
68   # E911 Info
69   ###
70
71   my $e911 = 
72     emt('E911 Information').
73     &ntable("#cccccc"). '<TR><TD>'. ntable("#cccccc",2).
74       '<TR><TD>'.emt('Location').'</TD>'.
75       '<TD BGCOLOR="#FFFFFF">'.
76         $svc_phone->location_label( 'join_string'     => '<BR>',
77                                     'double_space'    => ' &nbsp; ',
78                                     'escape_function' => \&encode_entities,
79                                     'countrydefault'  => $countrydefault,
80                                   ).
81       '</TD></TR>'.
82     '</TABLE></TD></TR></TABLE>'.
83     '<BR>'
84   ;
85
86   ###
87   # Devices
88   ###
89   #remove this when svc_phone isa device_Common, as elements/svc_Common will display it
90   my $devices = include('/view/elements/svc_devices.html',
91                           'svc_x' => $svc_phone,
92                           'table' => 'phone_device',
93                        );
94
95   my $status = include('/view/elements/svc_export_status.html', $svc_phone );
96
97   ##
98   # CDR links
99   ##
100
101   tie my %what, 'Tie::IxHash',
102     'pending' => 'NULL',
103     'billed'  => 'done',
104     'skipped' => 'failed',
105   ;
106
107   my $number = $svc_phone->phonenum;
108   $number = $svc_phone->countrycode. $number
109     unless $svc_phone->countrycode eq '1';
110
111   #src & charged party as per voip_cdr.pm
112   #XXX handle toll free too
113
114   my $search = "charged_party_or_src=";
115
116   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
117
118   if ( $cust_pkg ) {
119
120     #XXX handle voip_inbound too
121
122     my @part_pkg = grep { $_->plan eq 'voip_cdr' }
123                         $cust_pkg->part_pkg->self_and_bill_linked;
124
125     foreach my $prefix (grep $_, map $_->option('default_prefix'), @part_pkg) {
126       $number .= ",$prefix$number";
127     }
128
129     $search = 'charged_party='
130       unless !@part_pkg || grep { ! $_->option('disable_src',1) } @part_pkg;
131
132   }
133
134   $search .= $number;
135
136   my @links = map {
137     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
138     "View $_ CDRs</A>";
139   } keys(%what);
140
141   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
142                  'View incoming CDRs</A>' );
143
144   ###
145   # concatenate & return
146   ###
147
148   $e911.
149   #$devices.
150   $status.
151   join(' | ', @links ). '<BR>'.
152   join(' | ', @ilinks). '<BR>';
153
154 };
155
156 </%init>