add dsl_device to track mac addresses, RT#13656
[freeside.git] / httemplate / view / elements / svc_devices.html
1 <%doc>
2
3 #Example:
4
5   include( 'elements/svc_devices.html',
6              #required
7              'svc_x' => $svc_phone,     #or $svc_dsl
8              'table' => 'phone_device', #or dsl_device
9
10              #optional
11              'no_edit' => 0, #set true to turn off edit link
12          )
13
14 </%doc>
15 <% $devices %>
16 <%init>
17
18   my %opt = @_;
19   my $table = $opt{'table'}; #part_device, dsl_device
20   my $svc_x = $opt{'svc_x'};
21
22   my $devices = '';
23
24   my $num_part_device = 0;
25   if ( $table eq 'phone_device' )  {
26     my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device")
27                               #WHERE disabled = '' OR disabled IS NULL;");
28       or die dbh->errstr;
29     $sth->execute or die $sth->errstr;
30     $num_part_device = $sth->fetchrow_arrayref->[0];
31 }
32
33   my @devices = $svc_x->$table();
34
35   #should move the below to proper mason code above instead of making $devices
36   if ( @devices || $num_part_device || $table eq 'dsl_device' ) {
37     my $svcnum = $svc_x->svcnum;
38     $devices .=
39       qq[Devices (<A HREF="${p}edit/$table.html?svcnum=$svcnum">Add device</A>)<BR>];
40     if ( @devices ) {
41
42       $devices .= qq!
43         <SCRIPT>
44           function areyousure(href) {
45            if (confirm("Are you sure you want to delete this device?") == true)
46              window.location.href = href;
47           }
48         </SCRIPT>
49       !;
50
51
52       $devices .= 
53         include('/elements/table-grid.html').
54           '<TR>';
55
56       $devices .=
57             '<TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>'
58         if $table eq 'phone_device';
59
60       $devices .=
61             '<TH CLASS="grid" BGCOLOR="#cccccc">MAC Addr</TH>'.
62             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
63             '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'.
64           '</TR>';
65       my $bgcolor1 = '#eeeeee';
66       my $bgcolor2 = '#ffffff';
67       my $bgcolor = '';
68
69       foreach my $device ( @devices ) {
70
71         if ( $bgcolor eq $bgcolor1 ) {
72           $bgcolor = $bgcolor2;
73         } else {
74           $bgcolor = $bgcolor1;
75         }
76         my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
77
78         my $devicenum = $device->devicenum;
79         my $export_links = join( '<BR>', @{ $device->export_links } )
80           if $device->can('export_links');
81
82         $devices .= '<TR>';
83         $devices .= $td. $device->part_device->devicename. '</TD>'
84           if $table eq 'phone_device'; #$devices->can('part_device');
85
86         $devices .=   $td. $device->mac_addr. '</TD>'.
87                       $td. $export_links. '</TD>'.
88                       "$td( ";
89
90         $devices .= qq(<A HREF="${p}edit/$table.html?$devicenum">edit</A> | )
91           unless $opt{'no_edit'};
92
93         $devices .= qq(<A HREF="javascript:areyousure('${p}misc/delete-$table.html?$devicenum')">delete</A>).
94                       ' )</TD>'.
95                     '</TR>';
96       }
97       $devices .= '</TABLE><BR>';
98     }
99     $devices .= '<BR>';
100   }
101
102 </%init>