5 include( 'elements/svc_Common.html,
7 'table' => 'svc_something'
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
19 # defaults to "edit/$table.cgi?", will have svcnum appended
22 #at the very bottom (well, as low as you can go from here)
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;
37 background-color: #ffffff;
47 <& /elements/header.html, mt("View [_1]: [_2]",$label,$value) &>
49 <& /elements/small_custview.html, $custnum, '', 1,
50 "${p}view/cust_main.cgi" &>
55 <& /elements/header.html, mt("View [_1]: [_2]",$label,$value), menubar(
56 emt("Cancel this (unaudited) [_1]",$label) =>
57 "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')"
62 % if ( $opt{radius_usage} ) {
63 <& svc_radius_usage.html,
65 'part_svc' => $part_svc,
66 'cust_pkg' => $cust_pkg,
70 <% mt('Service #') |h %><B><% $svcnum %></B>
72 % my $url = $opt{'edit_url'} || $p. 'edit/'. $opt{'table'}. '.cgi?';
73 <& /view/elements/svc_edit_link.html, 'svc' => $svc_x, 'edit_url' => $url &>
77 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
79 % foreach my $f ( @$fields ) {
80 % my ($field, $label, $value) = &{ $format_field }($f);
94 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) {
95 <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
99 </TABLE></TD></TR></TABLE>
105 'table' => $svc_x->device_table,
108 % if ( defined($opt{'html_foot'}) ) {
110 <% ref($opt{'html_foot'})
111 ? &{ $opt{'html_foot'} }($svc_x)
119 <& /elements/table-tickets.html, object => $cust_svc &>
122 <% joblisting({'svcnum'=>$svcnum}, 1) %>
124 <% include('/elements/footer.html') %>
128 unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
132 my $conf = new FS::Conf;
133 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
135 my $table = $opt{'table'};
137 my $fields = $opt{'fields'}
138 #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
139 || [ grep { $_ ne 'svcnum' } fields($table) ];
142 if ( $cgi->param('svcnum') ) {
143 $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparseable svcnum";
146 my($query) = $cgi->keywords;
147 $query =~ /^(\d+)$/ or die "no svcnum";
150 my $svc_x = qsearchs({
151 'select' => $opt{'table'}.'.*',
152 'table' => $opt{'table'},
153 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
154 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
155 ' LEFT JOIN cust_main USING ( custnum ) ',
156 'hashref' => { 'svcnum' => $svcnum },
157 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
158 'null_right' => 'View/link unlinked services'
160 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
162 my $cust_svc = $svc_x->cust_svc;
163 my ($label, $value, $svcdb, $part_svc );
164 my $labels = $opt{labels} || {};
167 ($label, $value, $svcdb) = $cust_svc->label;
169 $part_svc = $cust_svc->part_svc;
171 #false laziness w/edit/svc_Common.html
172 #override default labels with service-definition labels if applicable
173 foreach my $field ( keys %$labels ) {
174 my $col = $part_svc->part_svc_column($field);
175 $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/;
178 $label = "Unlinked $table";
179 $value = $svc_x->label;
181 # just to satisfy callbacks
182 $part_svc = FS::part_svc->new({ svcpart => 0, svcdb => $table });
185 my $pkgnum = $cust_svc->pkgnum if $cust_svc;
187 my($cust_pkg, $custnum);
189 $cust_pkg = $cust_svc->cust_pkg;
190 $custnum = $cust_pkg->custnum;
197 if ( my $router = qsearchs('router', { svcnum => $svc_x->svcnum }) ) {
202 $labels->{'router_routername'} = 'Attached router';
203 $labels->{'router_block'} = 'Attached address block';
204 $svc_x->set('router_routername', $router->routername);
205 my $block = qsearchs('addr_block', { routernum => $router->routernum });
207 $svc_x->set('router_block', $block->cidr);
209 $svc_x->set('router_block', '(none)');
213 my @inventory_items = $svc_x->inventory_item;
215 my $format_field = sub {
217 my($field, $type, $value);
219 $field = $f->{'field'};
220 $type = $f->{'type'} || 'text';
226 my $columndef = $part_svc->part_svc_column($field);
227 # skip fields that are fixed and empty
228 if ( $columndef->columnflag eq 'F'
229 and length($columndef->columnvalue) == 0 ) {
233 # things that override the column value: value_callback, select
234 if ( ref($f) and $f->{'value_callback'} ) {
236 my $hack_strict_refs = \&{ $f->{'value_callback'} };
237 $value = &$hack_strict_refs($svc_x);
239 } elsif ( $type eq 'select-table' ) {
240 # imitates the /elements/select-table interface
241 $value = $svc_x->$field;
243 my $value_col = $f->{'value_col'} ||
244 dbdef->table($f->{'table'})->primary_key;
245 my $name_col = $f->{'name_col'} or die 'name_col required';
246 # we don't yet support multiple-valued fields here
247 my $obj = qsearchs($f->{'table'}, { $value_col => $value });
249 $value = $obj->$name_col; # can be any method of the object
251 # show the raw value, but mark it as an error
252 $value = '<SPAN CLASS="error">' . $f->{'table'} . ' ' .
253 encode_entities($value) . '</SPAN>';
257 $value = encode_entities($svc_x->$field);
260 # inventory-select field with multiple classes
261 # show the class name to disambiguate
262 if ( $columndef->columnflag =~ /^[MA]$/ && $columndef->columnvalue =~ /,/ )
264 my ($item) = grep { $_->svc_field eq $field } @inventory_items;
265 my $class = qsearchs('inventory_class', { classnum => $item->classnum });
266 $value .= ' <i>('. $class->classname . ')</i>' if $class;
270 if ( $type eq 'date' and $value ) {
271 $value = time2str($date_format,$value)
272 } elsif ( $type eq 'datetime' and $value ) {
273 $value = time2str("$date_format %H:%M",$value)
274 } elsif ( $type eq 'checkbox' ) {
275 $value = $value eq 'Y' ? emt('Yes') : emt('No');
276 } elsif ( $type eq 'mac_addr' and $value =~ /\w/) {
277 $value .= ' ('. (Net::MAC::Vendor::lookup($value))->[0]. ')'
282 if ( ref($f) and exists $f->{'link'} ) {
283 my $link = $f->{'link'};
284 if ( ref($link) eq 'CODE' ) {
285 $link = &{$link}($svc_x);
287 if ( ref($link) eq 'ARRAY' ) {
288 my ($base, $method) = @$link;
289 $href = $base . $svc_x->$method();
290 } elsif ( !ref($link) ) {
295 $value = qq!<A HREF="$href">$value</A>!;
299 my $label = $opt{labels}->{$field} || $field;
300 return ($field, $label, $value);
303 &{ $opt{'svc_callback'} }( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, \%opt )
304 if $opt{'svc_callback'};