ffb6fcc4aac2c859d4feb5b35720e8fa06b0dbbe
[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 );
20 push @fields, 'domain' if $conf->exists('svc_phone-domain');
21 push @fields, qw( pbx_title sip_password pin phone_name forwarddst email );
22
23 if ( $conf->exists('svc_phone-lnp') ) {
24 push @fields, 'lnp_status',
25             'lnp_reject_reason',
26             { field => 'portable', type => 'checkbox', },
27             'lrn',
28             { field => 'lnp_desired_due_date', type => 'date', },
29             { field => 'lnp_due_date', type => 'date', },
30             'lnp_other_provider',
31             'lnp_other_provider_account';
32 }
33
34 my $html_foot = sub {
35   my $svc_phone = shift;
36
37   ###
38   # E911 Info
39   ###
40
41   my $e911 = 
42     emt('E911 Information').
43     &ntable("#cccccc"). '<TR><TD>'. ntable("#cccccc",2).
44       '<TR><TD>'.emt('Location').'</TD>'.
45       '<TD BGCOLOR="#FFFFFF">'.
46         $svc_phone->location_label( 'join_string'     => '<BR>',
47                                     'double_space'    => ' &nbsp; ',
48                                     'escape_function' => \&encode_entities,
49                                     'countrydefault'  => $countrydefault,
50                                   ).
51       '</TD></TR>'.
52     '</TABLE></TD></TR></TABLE>'.
53     '<BR>'
54   ;
55
56   ###
57   # Devices
58   ###
59
60   my $devices = '';
61
62   my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device") #WHERE disabled = '' OR disabled IS NULL;");
63     or die dbh->errstr;
64   $sth->execute or die $sth->errstr;
65   my $num_part_device = $sth->fetchrow_arrayref->[0];
66
67   my @phone_device = $svc_phone->phone_device;
68   if ( @phone_device || $num_part_device ) {
69     my $svcnum = $svc_phone->svcnum;
70     $devices .=
71       qq[Devices (<A HREF="${p}edit/phone_device.html?svcnum=$svcnum">Add device</A>)<BR>];
72     if ( @phone_device ) {
73
74       $devices .= qq!
75         <SCRIPT>
76           function areyousure(href) {
77            if (confirm("Are you sure you want to delete this device?") == true)
78              window.location.href = href;
79           }
80         </SCRIPT>
81       !;
82
83
84       $devices .= 
85         include('/elements/table-grid.html').
86           '<TR>'.
87             '<TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>'.
88             '<TH CLASS="grid" BGCOLOR="#cccccc">MAC Addr</TH>'.
89             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
90             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
91           '</TR>';
92       my $bgcolor1 = '#eeeeee';
93       my $bgcolor2 = '#ffffff';
94       my $bgcolor = '';
95
96       foreach my $phone_device ( @phone_device ) {
97
98         if ( $bgcolor eq $bgcolor1 ) {
99           $bgcolor = $bgcolor2;
100         } else {
101           $bgcolor = $bgcolor1;
102         }
103         my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
104
105         my $devicenum = $phone_device->devicenum;
106         my $export_links = join( '<BR>', @{ $phone_device->export_links } );
107
108         $devices .= '<TR>'.
109                       $td. $phone_device->part_device->devicename. '</TD>'.
110                       $td. $phone_device->mac_addr. '</TD>'.
111                       $td. $export_links. '</TD>'.
112                       "$td( ".
113                         qq(<A HREF="${p}edit/phone_device.html?$devicenum">edit</A> | ).
114                         qq(<A HREF="javascript:areyousure('${p}misc/delete-phone_device.html?$devicenum')">delete</A>).
115                       ' )</TD>'.
116                     '</TR>';
117       }
118       $devices .= '</TABLE><BR>';
119     }
120     $devices .= '<BR>';
121   }
122
123   ##
124   # CDR links
125   ##
126
127   tie my %what, 'Tie::IxHash',
128     'pending' => 'NULL',
129     'billed'  => 'done',
130   ;
131
132   my $number = $svc_phone->phonenum;
133   $number = $svc_phone->countrycode. $number
134     unless $svc_phone->countrycode eq '1';
135
136   #src & charged party as per voip_cdr.pm
137   #XXX handle toll free too
138
139   my $search = "charged_party_or_src=";
140
141   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
142
143   if ( $cust_pkg ) {
144
145     #XXX handle voip_inbound too
146
147     my @part_pkg = grep { $_->plan eq 'voip_cdr' }
148                         $cust_pkg->part_pkg->self_and_bill_linked;
149
150     foreach my $prefix (grep $_, map $_->option('default_prefix'), @part_pkg) {
151       $number .= ",$prefix$number";
152     }
153
154     $search = 'charged_party='
155       unless !@part_pkg || grep { ! $_->option('disable_src',1) } @part_pkg;
156
157   }
158
159   $search .= $number;
160
161   my @links = map {
162     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
163     "View $_ CDRs</A>";
164   } keys(%what);
165
166   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
167                  'View incoming CDRs</A>' );
168
169   ###
170   # concatenate & return
171   ###
172
173   $e911.
174   $devices.
175   join(' | ', @links ). '<BR>'.
176   join(' | ', @ilinks). '<BR>';
177
178 };
179
180 </%init>