9458c922c58d80a328a7ff0f8c9f08afb4521416
[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    Devices
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 eq 'phone_device' || $table eq 'cable_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 %></TD>
66           <% $td %><% $export_links %></TD>
67           <% $td %>(
68 %           unless ( $opt{'no_edit'} ) {
69               <A HREF="<%$p%>edit/<%$table%>.html?<%$devicenum%>">edit</A> |
70 %           }
71             <A HREF="javascript:areyousure('<%$p%>misc/delete-<%$table%>.html?<%$devicenum%>')">delete</A>
72           )</TD>
73         </TR>
74 %     }
75       </TABLE>
76       <BR>
77
78 %  }
79    <BR>
80 %}
81 <%init>
82
83 my %opt = @_;
84 my $table = $opt{'table'}; #part_device, dsl_device
85 my $svc_x = $opt{'svc_x'};
86
87 my $num_part_device = 0;
88 if ( $table eq 'phone_device' || $table eq 'cable_device' ) {
89   my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device")
90                             #WHERE disabled = '' OR disabled IS NULL;");
91     or die dbh->errstr;
92   $sth->execute or die $sth->errstr;
93   $num_part_device = $sth->fetchrow_arrayref->[0];
94 }
95
96 my @devices = $svc_x->isa('FS::device_Common') ? $svc_x->device_objects()
97                                                : $table ? $svc_x->$table()
98                                                         : ();
99
100 </%init>