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