add location to svc_phone, RT#7047
[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 $loc = $svc_phone->cust_location_or_main;
33
34   my $e911 = 
35     'E911 Information'.
36     &ntable("#cccccc"). '<TR><TD>'. ntable("#cccccc",2).
37       '<TR><TD>Location</TD>'.
38       '<TD BGCOLOR="#FFFFFF">'.
39         $loc->location_label( 'join_string'     => '<BR>',
40                               'double_space'    => ' &nbsp; ',
41                               'escape_function' => \&encode_entities,
42                               'countrydefault'  => $countrydefault,
43                             ).
44       '</TD></TR>'.
45     '</TABLE></TD></TR></TABLE>'.
46     '<BR>'
47   ;
48
49   ###
50   # Devices
51   ###
52
53   my $devices = '';
54
55   my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device") #WHERE disabled = '' OR disabled IS NULL;");
56     or die dbh->errstr;
57   $sth->execute or die $sth->errstr;
58   my $num_part_device = $sth->fetchrow_arrayref->[0];
59
60   my @phone_device = $svc_phone->phone_device;
61   if ( @phone_device || $num_part_device ) {
62     my $svcnum = $svc_phone->svcnum;
63     $devices .=
64       qq[Devices (<A HREF="${p}edit/phone_device.html?svcnum=$svcnum">Add device</A>)<BR>];
65     if ( @phone_device ) {
66
67       $devices .= qq!
68         <SCRIPT>
69           function areyousure(href) {
70            if (confirm("Are you sure you want to delete this device?") == true)
71              window.location.href = href;
72           }
73         </SCRIPT>
74       !;
75
76
77       $devices .= 
78         include('/elements/table-grid.html').
79           '<TR>'.
80             '<TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>'.
81             '<TH CLASS="grid" BGCOLOR="#cccccc">MAC Addr</TH>'.
82             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
83             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
84           '</TR>';
85       my $bgcolor1 = '#eeeeee';
86       my $bgcolor2 = '#ffffff';
87       my $bgcolor = '';
88
89       foreach my $phone_device ( @phone_device ) {
90
91         if ( $bgcolor eq $bgcolor1 ) {
92           $bgcolor = $bgcolor2;
93         } else {
94           $bgcolor = $bgcolor1;
95         }
96         my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
97
98         my $devicenum = $phone_device->devicenum;
99         my $export_links = join( '<BR>', @{ $phone_device->export_links } );
100
101         $devices .= '<TR>'.
102                       $td. $phone_device->part_device->devicename. '</TD>'.
103                       $td. $phone_device->mac_addr. '</TD>'.
104                       $td. $export_links. '</TD>'.
105                       "$td( ".
106                         qq(<A HREF="${p}edit/phone_device.html?$devicenum">edit</A> | ).
107                         qq(<A HREF="javascript:areyousure('${p}misc/delete-phone_device.html?$devicenum')">delete</A>).
108                       ' )</TD>'.
109                     '</TR>';
110       }
111       $devices .= '</TABLE><BR>';
112     }
113     $devices .= '<BR>';
114   }
115
116   ##
117   # CDR links
118   ##
119
120   tie my %what, 'Tie::IxHash',
121     'pending' => 'NULL',
122     'billed'  => 'done',
123   ;
124
125   #XXX src & charged party (& default prefix) as per voip_cdr.pm
126   #XXX handle toll free too
127
128   my $number = $svc_phone->phonenum;
129   $number = $svc_phone->countrycode. $number
130     unless $svc_phone->countrycode eq '1';
131
132   #my @links = map {
133   #  qq(<A HREF="${p}search/cdr.html?src=$number;freesidestatus=$what{$_}">).
134   #  "View $_ CDRs</A>";
135   #} keys(%what);
136   my @links = map {
137     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;charged_party=$number;freesidestatus=$what{$_}">).
138     "View $_ CDRs</A>";
139   } keys(%what);
140
141   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
142                  'View incoming CDRs</A>' );
143
144   ###
145   # concatenate & return
146   ###
147
148   $e911.
149   $devices.
150   join(' | ', @links ). '<BR>'.
151   join(' | ', @ilinks). '<BR>';
152
153 };
154
155 </%init>