stray closing /TABLE in the no-ticket case
[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 %if ( @devices || $num_part_device || $table eq 'dsl_device' ) {
16 %  my $svcnum = $svc_x->svcnum;
17
18    <FONT CLASS="fsinnerbox-title">Devices</FONT>
19    (<A HREF="<%$p%>edit/<%$table%>.html?svcnum=<%$svcnum%>">Add device</A>)
20    <BR>
21
22 %  if ( @devices ) {
23
24      <SCRIPT>
25        function areyousure(href) {
26         if (confirm("Are you sure you want to delete this device?") == true)
27           window.location.href = href;
28        }
29      </SCRIPT>
30
31      <& /elements/table-grid.html &>
32        <TR>
33 %        if ( $table ne 'dsl_device' ) { # ( $table eq 'phone_device' || $table eq 'cable_device' || $table eq 'pbx_device' ) {
34            <TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>
35 %        }
36          <TH CLASS="grid" BGCOLOR="#cccccc">MAC Addr</TH>
37          <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
38          <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
39        </TR>
40
41 %      my $bgcolor1 = '#eeeeee';
42 %      my $bgcolor2 = '#ffffff';
43 %      my $bgcolor = '';
44 %
45 %      foreach my $device ( @devices ) {
46 %
47 %        if ( $bgcolor eq $bgcolor1 ) {
48 %          $bgcolor = $bgcolor2;
49 %        } else {
50 %          $bgcolor = $bgcolor1;
51 %        }
52 %
53 %        my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
54 %
55 %        my $devicenum = $device->devicenum;
56 %        my $export_links = '';
57 %        $export_links = join( '<BR>', @{ $device->export_links } )
58 %          if $device->can('export_links');
59
60         <TR>
61 %              #$devices->can('part_device')
62 %         if ( $table eq 'phone_device' || $svc_x->isa('FS::device_Common') ) {
63             <% $td %><% $device->part_device->devicename |h %></TD>
64 %         }
65           <% $td %><% $device->mac_addr_pretty %>
66 %                my $vendor = Net::MAC::Vendor::lookup($device->mac_addr_formatted('U',':'));
67                  (<% $vendor ? $vendor->[0] : '' %>)
68           </TD>
69           <% $td %><% $export_links %></TD>
70           <% $td %>(
71 %           unless ( $opt{'no_edit'} ) {
72               <A HREF="<%$p%>edit/<%$table%>.html?<%$devicenum%>">edit</A> |
73 %           }
74             <A HREF="javascript:areyousure('<%$p%>misc/delete-<%$table%>.html?<%$devicenum%>')">delete</A>
75           )</TD>
76         </TR>
77 %     }
78       </TABLE>
79       <BR>
80
81 %  }
82    <BR>
83 %}
84 <%init>
85
86 my %opt = @_;
87 my $table = $opt{'table'}; #part_device, dsl_device
88 my $svc_x = $opt{'svc_x'};
89
90 my $num_part_device = 0;
91 if ( $table ne 'dsl_device' ) { # ( $table eq 'phone_device' || $table eq 'cable_device' || $table eq 'pbx_device' ) {
92   my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device")
93                             #WHERE disabled = '' OR disabled IS NULL;");
94     or die dbh->errstr;
95   $sth->execute or die $sth->errstr;
96   $num_part_device = $sth->fetchrow_arrayref->[0];
97 }
98
99 my @devices = $svc_x->isa('FS::device_Common') ? $svc_x->device_objects()
100                                                : $table ? $svc_x->$table()
101                                                         : ();
102
103 </%init>