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