svc_hardware and svc_dish, #11454
[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   if (confirm("Permanently delete this <% $label %>?") == true)
31     window.location.href = href;
32 }
33 </SCRIPT>
34
35 % if ( $custnum ) { 
36
37   <% include("/elements/header.html","View $label: $value") %>
38
39   <% include( '/elements/small_custview.html', $custnum, '', 1,
40      "${p}view/cust_main.cgi") %>
41   <BR>
42
43 % } else { 
44
45   <% include("/elements/header.html","View $label: $value", menubar(
46       "Cancel this (unaudited) $label" =>
47             "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')"
48   )) %>
49
50 % } 
51
52 Service #<B><% $svcnum %></B>
53 % my $url = $opt{'edit_url'} || $p. 'edit/'. $opt{'table'}. '.cgi?';
54 | <% include('/view/elements/svc_edit_link.html', 'svc' => $svc_x) %>
55 <BR>
56
57 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
58
59 % foreach my $f ( @$fields ) {
60 %
61 %   my($field, $type, $value, $hack_strict_refs);
62 %   if ( ref($f) ) {
63 %     $field = $f->{'field'};
64 %     $hack_strict_refs = \&{ $f->{'value'} } if $f->{'value'};
65 %     $value = $f->{'value'} ? &$hack_strict_refs($svc_x) : $svc_x->$field;
66 %     $type  = $f->{'type'} || 'text';
67 %   } else {
68 %     $field = $f;
69 %     $value = $svc_x->$field;
70 %     $type = 'text';
71 %   }
72 %
73 %   my $columndef = $part_svc->part_svc_column($field);
74 %   unless ($columndef->columnflag eq 'F' && !length($columndef->columnvalue)) {
75
76       <TR>
77         <TD ALIGN="right">
78           <% ( $opt{labels} && exists $opt{labels}->{$field} )
79                   ? $opt{labels}->{$field}
80                   : $field
81           %>
82         </TD>
83
84 %       $value = time2str($date_format,$value) if ( $type eq 'date' && $value );
85 %       $value = time2str("$date_format %H:%M",$value) if ( $type eq 'datetime' && $value );
86 %       $value = $value eq 'Y' ? 'Yes' : 'No' if ( $type eq 'checkbox' );
87 %       #eventually more options for <SELECT>, etc. fields
88
89         <TD BGCOLOR="#ffffff"><% $value %><TD>
90
91       </TR>
92
93 %   }
94 %
95 % } 
96
97 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) { 
98   <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
99 % } 
100
101
102 </TABLE></TD></TR></TABLE>
103
104 <BR>
105
106 % if ( defined($opt{'html_foot'}) ) {
107
108   <% ref($opt{'html_foot'})
109        ? &{ $opt{'html_foot'} }($svc_x)
110        : $opt{'html_foot'}
111   %>
112   <BR>
113
114 % }
115
116 <% joblisting({'svcnum'=>$svcnum}, 1) %>
117
118 <% include('/elements/footer.html') %>
119 <%init>
120
121 die "access denied"
122   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
123
124 my(%opt) = @_;
125
126 my $conf = new FS::Conf;
127 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
128
129 my $table = $opt{'table'};
130
131 my $fields = $opt{'fields'}
132              #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
133              || [ grep { $_ ne 'svcnum' } fields($table) ];
134
135 my $svcnum;
136 if ( $cgi->param('svcnum') ) {
137   $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparsable svcnum";
138   $svcnum = $1;
139 } else {
140   my($query) = $cgi->keywords;
141   $query =~ /^(\d+)$/ or die "no svcnum";
142   $svcnum = $1;
143 }
144 my $svc_x = qsearchs({
145   'select'    => $opt{'table'}.'.*',
146   'table'     => $opt{'table'},
147   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
148                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
149                  ' LEFT JOIN cust_main USING ( custnum ) ',
150   'hashref'   => { 'svcnum' => $svcnum },
151   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
152                             'null_right' => 'View/link unlinked services'
153                           ),
154 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
155
156 my $cust_svc = $svc_x->cust_svc;
157 my($label, $value, $svcdb) = $cust_svc->label;
158
159 my $part_svc = $cust_svc->part_svc;
160
161   #false laziness w/edit/svc_Common.html
162   #override default labels with service-definition labels if applicable
163   my $labels = $opt{labels}; #not -> here
164   foreach my $field ( keys %$labels ) {
165     my $col = $part_svc->part_svc_column($field);
166     $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\S*$/;
167   }
168
169 my $pkgnum = $cust_svc->pkgnum;
170
171 my($cust_pkg, $custnum);
172 if ($pkgnum) {
173   $cust_pkg = $cust_svc->cust_pkg;
174   $custnum = $cust_pkg->custnum;
175 } else {
176   $cust_pkg = '';
177   $custnum = '';
178 }
179
180 &{ $opt{'svc_callback'} }( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, \%opt ) 
181     if $opt{'svc_callback'};
182 </%init>