This commit was generated by cvs2svn to compensate for changes in r9232,
[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   #XXX src & charged party (& default prefix) as per voip_cdr.pm
124   #XXX handle toll free too
125
126   my $number = $svc_phone->phonenum;
127   $number = $svc_phone->countrycode. $number
128     unless $svc_phone->countrycode eq '1';
129
130   #my @links = map {
131   #  qq(<A HREF="${p}search/cdr.html?src=$number;freesidestatus=$what{$_}">).
132   #  "View $_ CDRs</A>";
133   #} keys(%what);
134   my @links = map {
135     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;charged_party=$number;freesidestatus=$what{$_}">).
136     "View $_ CDRs</A>";
137   } keys(%what);
138
139   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
140                  'View incoming CDRs</A>' );
141
142   ###
143   # concatenate & return
144   ###
145
146   $e911.
147   $devices.
148   join(' | ', @links ). '<BR>'.
149   join(' | ', @ilinks). '<BR>';
150
151 };
152
153 </%init>