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