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