show MAC address vendors
[freeside.git] / httemplate / view / elements / svc_Common.html
1 <%doc>
2
3 #Example:
4
5   include( 'elements/svc_Common.html, 
6
7              'table' => 'svc_something'
8
9              'labels' => {
10                            'column' => 'Label',
11                          },
12
13              #listref - each item is a literal column name (or method) or
14              # (notyet) coderef.  if not specified all columns (except for the
15              #primary key) will be viewable
16              'fields' => [
17                          ]
18
19              # defaults to "edit/$table.cgi?", will have svcnum appended
20              'edit_url' => 
21
22              #at the very bottom (well, as low as you can go from here)
23              'html_foot'  => '',
24
25          )
26
27 </%doc>
28 <SCRIPT>
29 function areyousure(href) {
30 % my $delmsg = emt("Permanently delete this [_1]?", $label);
31   if (confirm(<% $delmsg |js_string %>) == true)
32     window.location.href = href;
33 }
34 </SCRIPT>
35
36 % if ( $custnum ) { 
37
38   <& /elements/header.html, mt("View [_1]: [_2]",$label,$value) &>
39
40   <& /elements/small_custview.html, $custnum, '', 1,
41      "${p}view/cust_main.cgi" &>
42   <BR>
43
44 % } else { 
45
46   <& /elements/header.html, mt("View [_1]: [_2]",$label,$value), menubar(
47       emt("Cancel this (unaudited) [_1]",$label) =>
48             "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')"
49   ) &>
50
51 % } 
52
53 % if ( $opt{radius_usage} ) {
54     <& svc_radius_usage.html,
55               'svc'      => $svc_x,
56               'part_svc' => $part_svc,
57               'cust_pkg' => $cust_pkg,
58     &>
59 % }
60
61 <% mt('Service #') |h %><B><% $svcnum %></B>
62 % if ( $custnum ) {
63 %   my $url = $opt{'edit_url'} || $p. 'edit/'. $opt{'table'}. '.cgi?';
64 <& /view/elements/svc_edit_link.html, 'svc' => $svc_x, 'edit_url' => $url &>
65 % }
66 <BR>
67
68 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
69
70 % my @inventory_items = $svc_x->inventory_item;
71 % foreach my $f ( @$fields ) {
72 %
73 %   my($field, $type, $value);
74 %   if ( ref($f) ) {
75 %     $field = $f->{'field'};
76 %     $type  = $f->{'type'} || 'text';
77 %     if ( $f->{'value_callback'} ) {
78 %       my $hack_strict_refs = \&{ $f->{'value_callback'} };
79 %       $value = &$hack_strict_refs($svc_x);
80 %     } else {
81 %       $value = encode_entities($svc_x->$field);
82 %     }
83 %   } else {
84 %     $field = $f;
85 %     $type = 'text';
86 %     $value = encode_entities($svc_x->$field);
87 %   }
88 %
89 %   my $columndef = $part_svc->part_svc_column($field);
90 %   if ( $columndef->columnflag =~ /^[MA]$/ && $columndef->columnvalue =~ /,/ )
91 %   {
92 %     # inventory-select field with multiple classes
93 %     # show the class name to disambiguate
94 %     my ($item) = grep { $_->svc_field eq $field } @inventory_items;
95 %     my $class = qsearchs('inventory_class', { classnum => $item->classnum });
96 %     $value .= ' <i>('. $class->classname . ')</i>' if $class;
97 %   }
98 %   unless ($columndef->columnflag eq 'F' && !length($columndef->columnvalue)) {
99
100       <TR>
101         <TD ALIGN="right">
102           <% ( $opt{labels} && exists $opt{labels}->{$field} )
103                   ? $opt{labels}->{$field}
104                   : $field
105           %>
106         </TD>
107
108 %       $value = time2str($date_format,$value)
109 %         if $type eq 'date' && $value;
110 %       $value = time2str("$date_format %H:%M",$value)
111 %         if $type eq 'datetime' && $value;
112 %       $value = $value eq 'Y' ? emt('Yes') : emt('No')
113 %         if $type eq 'checkbox';
114 %       $value .= ' ('. (Net::MAC::Vendor::lookup($value))->[0]. ')'
115 %         if $type =~ /mac_addr$/ && $value =~ /\w/i;
116 %       #eventually more options for <SELECT>, etc. fields
117
118         <TD BGCOLOR="#ffffff"><% $value %><TD>
119
120       </TR>
121
122 %   }
123 %
124 % } 
125
126 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) { 
127   <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
128 % } 
129
130
131 </TABLE></TD></TR></TABLE>
132
133 <BR>
134
135 <& svc_devices.html,
136      'svc_x' => $svc_x,
137      'table' => $svc_x->device_table,
138 &>
139
140 % if ( defined($opt{'html_foot'}) ) {
141
142   <% ref($opt{'html_foot'})
143        ? &{ $opt{'html_foot'} }($svc_x)
144        : $opt{'html_foot'}
145   %>
146   <BR>
147
148 % }
149
150 % if ( $cust_svc ) {
151 <& /elements/table-tickets.html, object => $cust_svc &>
152 % }
153
154 <% joblisting({'svcnum'=>$svcnum}, 1) %>
155
156 <% include('/elements/footer.html') %>
157 <%init>
158
159 die "access denied"
160   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
161
162 my(%opt) = @_;
163
164 my $conf = new FS::Conf;
165 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
166
167 my $table = $opt{'table'};
168
169 my $fields = $opt{'fields'}
170              #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
171              || [ grep { $_ ne 'svcnum' } fields($table) ];
172
173 my $svcnum;
174 if ( $cgi->param('svcnum') ) {
175   $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparseable svcnum";
176   $svcnum = $1;
177 } else {
178   my($query) = $cgi->keywords;
179   $query =~ /^(\d+)$/ or die "no svcnum";
180   $svcnum = $1;
181 }
182 my $svc_x = qsearchs({
183   'select'    => $opt{'table'}.'.*',
184   'table'     => $opt{'table'},
185   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
186                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
187                  ' LEFT JOIN cust_main USING ( custnum ) ',
188   'hashref'   => { 'svcnum' => $svcnum },
189   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
190                             'null_right' => 'View/link unlinked services'
191                           ),
192 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
193
194 my $cust_svc = $svc_x->cust_svc;
195 my ($label, $value, $svcdb, $part_svc );
196 my $labels = $opt{labels}; #not -> here
197
198 if ( $cust_svc ) {
199   ($label, $value, $svcdb) = $cust_svc->label;
200
201   $part_svc = $cust_svc->part_svc;
202
203   #false laziness w/edit/svc_Common.html
204   #override default labels with service-definition labels if applicable
205   foreach my $field ( keys %$labels ) {
206     my $col = $part_svc->part_svc_column($field);
207     $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/;
208   }
209 } else {
210   $label = "Unlinked $table";
211   $value = $svc_x->label;
212   $svcdb = $table;
213   # just to satisfy callbacks
214   $part_svc = FS::part_svc->new({ svcpart => 0, svcdb => $table });
215 }
216
217 my $pkgnum = $cust_svc->pkgnum if $cust_svc;
218
219 my($cust_pkg, $custnum);
220 if ($pkgnum) {
221   $cust_pkg = $cust_svc->cust_pkg;
222   $custnum = $cust_pkg->custnum;
223 } else {
224   $cust_pkg = '';
225   $custnum = '';
226 }
227
228 # attached routers
229 if ( my $router = qsearchs('router', { svcnum => $svc_x->svcnum }) ) {
230   push @$fields, qw(router_routername router_block);
231   $labels->{'router_routername'} = 'Attached router';
232   $labels->{'router_block'} = 'Attached address block';
233   $svc_x->set('router_routername', $router->routername);
234   my $block = qsearchs('addr_block', { routernum => $router->routernum });
235   if ( $block ) {
236     $svc_x->set('router_block', $block->cidr);
237   } else {
238     $svc_x->set('router_block', '<i>(none)</i>');
239   }
240 }
241
242 &{ $opt{'svc_callback'} }( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, \%opt ) 
243     if $opt{'svc_callback'};
244 </%init>