grandstream device configuration support #4220
[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             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
62           '</TR>';
63       my $bgcolor1 = '#eeeeee';
64       my $bgcolor2 = '#ffffff';
65       my $bgcolor = '';
66
67       foreach my $phone_device ( @phone_device ) {
68
69         if ( $bgcolor eq $bgcolor1 ) {
70           $bgcolor = $bgcolor2;
71         } else {
72           $bgcolor = $bgcolor1;
73         }
74         my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
75
76         my $devicenum = $phone_device->devicenum;
77         my $export_links = join( '<BR>', @{ $phone_device->export_links } );
78
79         $devices .= '<TR>'.
80                       $td. $phone_device->part_device->devicename. '</TD>'.
81                       $td. $phone_device->mac_addr. '</TD>'.
82                       $td. $export_links. '</TD>'.
83                       "$td( ".
84                         qq(<A HREF="${p}edit/phone_device.html?$devicenum">edit</A> | ).
85                         qq(<A HREF="javascript:areyousure('${p}misc/delete-phone_device.html?$devicenum')">delete</A>).
86                       ' )</TD>'.
87                     '</TR>';
88       }
89       $devices .= '</TABLE><BR>';
90     }
91     $devices .= '<BR>';
92   }
93
94   ##
95   # CDR links
96   ##
97
98   tie my %what, 'Tie::IxHash',
99     'pending' => 'NULL',
100     'billed'  => 'done',
101   ;
102
103   #XXX src & charged party (& default prefix) as per voip_cdr.pm
104   #XXX handle toll free too
105
106   my $number = $svc_phone->phonenum;
107   $number = $svc_phone->countrycode. $number
108     unless $svc_phone->countrycode eq '1';
109
110   #my @links = map {
111   #  qq(<A HREF="${p}search/cdr.html?src=$number;freesidestatus=$what{$_}">).
112   #  "View $_ CDRs</A>";
113   #} keys(%what);
114   my @links = map {
115     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;charged_party=$number;freesidestatus=$what{$_}">).
116     "View $_ CDRs</A>";
117   } keys(%what);
118
119   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
120                  'View incoming CDRs</A>' );
121
122   ###
123   # concatenate & return
124   ###
125
126   $devices.
127   join(' | ', @links ). '<BR>'.
128   join(' | ', @ilinks). '<BR>';
129
130 };
131
132 </%init>