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)
25 #only needed for svc_broadband Manage Devices link
26 'manage_link' => scalar($conf->config('svc_broadband-manage_link')),
27 'manage_link_text' => scalar($conf->config('svc_broadband-manage_link_text')),
28 'manage_link-new_window' => $conf->exists('svc_broadband-manage_link-new_window')
34 function areyousure(href) {
35 % my $delmsg = emt("Permanently delete this [_1]?", $label);
36 if (confirm(<% $delmsg |js_string %>) == true)
37 window.location.href = href;
42 background-color: #ffffff;
52 <& /elements/header.html, mt("View [_1]: [_2]",$label,$value) &>
54 <& /elements/small_custview.html, $custnum, '', 1,
55 "${p}view/cust_main.cgi" &>
60 <& /elements/header.html, mt("View [_1]: [_2]",$label,$value), menubar(
61 emt("Cancel this (unaudited) [_1]",$label) =>
62 "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')"
67 % if ( $opt{radius_usage} ) {
68 <& svc_radius_usage.html,
70 'part_svc' => $part_svc,
71 'cust_pkg' => $cust_pkg,
75 <% mt('Service #') |h %><B><% $svcnum %></B>
77 % my $url = $opt{'edit_url'} || $p. 'edit/'. $opt{'table'}. '.cgi?';
78 <& /view/elements/svc_edit_link.html, 'svc' => $svc_x, 'part_svc' => $part_svc, 'edit_url' => $url,
79 'manage_link' => $opt{'manage_link'},
80 'manage_link_text' => $opt{'manage_link_text'},
81 'manage_link-new_window' => $opt{'manage_link-new_window'}
86 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
88 % foreach my $f ( @$fields ) {
89 % my ($field, $label, $value) = &{ $format_field }($f);
103 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) {
104 <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
108 </TABLE></TD></TR></TABLE>
114 'table' => $svc_x->device_table,
117 % if ( defined($opt{'html_foot'}) ) {
119 <% ref($opt{'html_foot'})
120 ? &{ $opt{'html_foot'} }($svc_x)
128 <& /elements/table-tickets.html, object => $cust_svc &>
131 <% joblisting({'svcnum'=>$svcnum}, 1) %>
133 <% include('/elements/footer.html') %>
137 unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
141 my $conf = new FS::Conf;
142 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
144 my $table = $opt{'table'};
146 my $fields = $opt{'fields'}
147 #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
148 || [ grep { $_ ne 'svcnum' } fields($table) ];
151 if ( $cgi->param('svcnum') ) {
152 $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparseable svcnum";
155 my($query) = $cgi->keywords;
156 $query =~ /^(\d+)$/ or die "no svcnum";
159 my $svc_x = qsearchs({
160 'select' => $opt{'table'}.'.*',
161 'table' => $opt{'table'},
162 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
163 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
164 ' LEFT JOIN cust_main USING ( custnum ) ',
165 'hashref' => { 'svcnum' => $svcnum },
166 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
167 'null_right' => 'View/link unlinked services'
169 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
171 my $cust_svc = $svc_x->cust_svc;
172 my ($label, $value, $svcdb, $part_svc );
173 my $labels = $opt{labels} || {};
176 ($label, $value, $svcdb) = $cust_svc->label;
178 $part_svc = $cust_svc->part_svc;
180 #false laziness w/edit/svc_Common.html
181 #override default labels with service-definition labels if applicable
182 foreach my $field ( keys %$labels ) {
183 my $col = $part_svc->part_svc_column($field);
184 $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/;
187 $label = "Unlinked $table";
188 $value = $svc_x->label;
190 # just to satisfy callbacks
191 $part_svc = FS::part_svc->new({ svcpart => 0, svcdb => $table });
194 my $pkgnum = $cust_svc->pkgnum if $cust_svc;
196 my($cust_pkg, $custnum);
198 $cust_pkg = $cust_svc->cust_pkg;
199 $custnum = $cust_pkg->custnum;
206 if ( my $router = qsearchs('router', { svcnum => $svc_x->svcnum }) ) {
211 $labels->{'router_routername'} = 'Attached router';
212 $labels->{'router_block'} = 'Attached address block';
213 $svc_x->set('router_routername', $router->routername);
214 my $block = qsearchs('addr_block', { routernum => $router->routernum });
216 $svc_x->set('router_block', $block->cidr);
218 $svc_x->set('router_block', '(none)');
222 my @inventory_items = $svc_x->inventory_item;
224 my $format_field = sub {
226 my($field, $type, $value);
228 $field = $f->{'field'};
229 $type = $f->{'type'} || 'text';
235 my $columndef = $part_svc->part_svc_column($field);
236 # skip fields that are fixed and empty
237 if ( $columndef->columnflag eq 'F'
238 and length($columndef->columnvalue) == 0 ) {
242 # things that override the column value: value_callback, select
243 if ( ref($f) and $f->{'value_callback'} ) {
245 my $hack_strict_refs = \&{ $f->{'value_callback'} };
246 $value = &$hack_strict_refs($svc_x);
248 } elsif ( $type eq 'select-table' ) {
249 # imitates the /elements/select-table interface
250 $value = $svc_x->$field;
252 my $value_col = $f->{'value_col'} ||
253 dbdef->table($f->{'table'})->primary_key;
254 my $name_col = $f->{'name_col'} or die 'name_col required';
255 # we don't yet support multiple-valued fields here
256 my $obj = qsearchs($f->{'table'}, { $value_col => $value });
258 $value = $obj->$name_col; # can be any method of the object
260 # show the raw value, but mark it as an error
261 $value = '<SPAN CLASS="error">' . $f->{'table'} . ' ' .
262 encode_entities($value) . '</SPAN>';
266 $value = encode_entities($svc_x->$field);
269 # inventory-select field with multiple classes
270 # show the class name to disambiguate
271 if ( $columndef->columnflag =~ /^[MA]$/ && $columndef->columnvalue =~ /,/ )
273 my ($item) = grep { $_->svc_field eq $field } @inventory_items;
274 my $class = qsearchs('inventory_class', { classnum => $item->classnum });
275 $value .= ' <i>('. $class->classname . ')</i>' if $class;
279 if ( $type eq 'date' and $value ) {
280 $value = time2str($date_format,$value)
281 } elsif ( $type eq 'datetime' and $value ) {
282 $value = time2str("$date_format %H:%M",$value)
283 } elsif ( $type eq 'checkbox' ) {
284 $value = $value eq 'Y' ? emt('Yes') : emt('No');
285 } elsif ( $type =~ /(input-)?mac_addr/ and $value =~ /\w/) {
286 my $vendor = Net::MAC::Vendor::lookup($value)->[0];
287 $value .= " ($vendor)" if $vendor;
288 $value = $m->scomp('/elements/mac_addr.html', $value);
293 if ( ref($f) and exists $f->{'link'} ) {
294 my $link = $f->{'link'};
295 if ( ref($link) eq 'CODE' ) {
296 $link = &{$link}($svc_x);
298 if ( ref($link) eq 'ARRAY' ) {
299 my ($base, $method) = @$link;
300 $href = $base . $svc_x->$method();
301 } elsif ( !ref($link) ) {
306 $value = qq!<A HREF="$href">$value</A>!;
310 my $label = $opt{labels}->{$field} || $field;
311 return ($field, $label, $value);
314 &{ $opt{'svc_callback'} }( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, \%opt )
315 if $opt{'svc_callback'};