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