proper cdr_batch table, RT#6386
[freeside.git] / httemplate / view / svc_phone.cgi
1 <% include('elements/svc_Common.html',
2               'table'     => 'svc_phone',
3               'fields'    => [qw(
4                                   countrycode
5                                   phonenum
6                                   sip_password
7                                   pin
8                                   phone_name
9                              )],
10               'labels'    => {
11                                'countrycode'  => 'Country code',
12                                'phonenum'     => 'Phone number',
13                                'sip_password' => 'SIP password',
14                                'pin'          => 'PIN',
15                                'phone_name'   => 'Name',
16                              },
17               'html_foot' => $html_foot,
18           )
19 %>
20 <%init>
21
22 my $html_foot = sub {
23   my $svc_phone = shift;
24
25   ###
26   # Devices
27   ###
28
29   my $devices = '';
30
31   my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device") #WHERE disabled = '' OR disabled IS NULL;");
32     or die dbh->errstr;
33   $sth->execute or die $sth->errstr;
34   my $num_part_device = $sth->fetchrow_arrayref->[0];
35
36   my @phone_device = $svc_phone->phone_device;
37   if ( @phone_device || $num_part_device ) {
38     my $svcnum = $svc_phone->svcnum;
39     $devices .=
40       qq[Devices (<A HREF="${p}edit/phone_device.html?svcnum=$svcnum">Add device</A>)<BR>];
41     if ( @phone_device ) {
42
43       $devices .= qq!
44         <SCRIPT>
45           function areyousure(href) {
46            if (confirm("Are you sure you want to delete this device?") == true)
47              window.location.href = href;
48           }
49         </SCRIPT>
50       !;
51
52
53       $devices .= 
54         include('/elements/table-grid.html').
55           '<TR>'.
56             '<TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>'.
57             '<TH CLASS="grid" BGCOLOR="#cccccc">MAC Addr</TH>'.
58             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
59           '</TR>';
60       my $bgcolor1 = '#eeeeee';
61       my $bgcolor2 = '#ffffff';
62       my $bgcolor = '';
63
64       foreach my $phone_device ( @phone_device ) {
65
66         if ( $bgcolor eq $bgcolor1 ) {
67           $bgcolor = $bgcolor2;
68         } else {
69           $bgcolor = $bgcolor1;
70         }
71         my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
72
73         my $devicenum = $phone_device->devicenum;
74
75         $devices .= '<TR>'.
76                       $td. $phone_device->part_device->devicename. '</TD>'.
77                       $td. $phone_device->mac_addr. '</TD>'.
78                       "$td( ".
79                         qq(<A HREF="${p}edit/phone_device.html?$devicenum">edit</A> | ).
80                         qq(<A HREF="javascript:areyousure('${p}misc/delete-phone_device.html?$devicenum')">delete</A>).
81                       ' )</TD>'.
82                     '</TR>';
83       }
84       $devices .= '</TABLE><BR>';
85     }
86     $devices .= '<BR>';
87   }
88
89   ##
90   # CDR links
91   ##
92
93   tie my %what, 'Tie::IxHash',
94     'pending' => 'NULL',
95     'billed'  => 'done',
96   ;
97
98   #XXX src & charged party (& default prefix) as per voip_cdr.pm
99   #XXX handle toll free too
100
101   my $number = $svc_phone->phonenum;
102   $number = $svc_phone->countrycode. $number
103     unless $svc_phone->countrycode eq '1';
104
105   #my @links = map {
106   #  qq(<A HREF="${p}search/cdr.html?src=$number;freesidestatus=$what{$_}">).
107   #  "View $_ CDRs</A>";
108   #} keys(%what);
109   my @links = map {
110     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;charged_party=$number;freesidestatus=$what{$_}">).
111     "View $_ CDRs</A>";
112   } keys(%what);
113
114   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
115                  'View incoming CDRs</A>' );
116
117   ###
118   # concatenate & return
119   ###
120
121   $devices.
122   join(' | ', @links ). '<BR>'.
123   join(' | ', @ilinks). '<BR>';
124
125 };
126
127 </%init>