also hide fixed+blank fields on service view, RT#3829
[freeside.git] / httemplate / view / elements / svc_Common.html
1 %  # options example...
2 %  #
3 %  # 'table' => 'svc_something'
4 %  #
5 %  # 'labels' => {
6 %  #               'column' => 'Label',
7 %  #             },
8 %  #
9 %  # listref - each item is a literal column name (or method) or (notyet) coderef
10 %  # if not specified all columns (except for the primary key) will be viewable
11 %  # 'fields' => [
12 %  #             ]
13 %  #
14 %  # # defaults to "edit/$table.cgi?", will have svcnum appended
15 %  # 'edit_url' => 
16 %
17 %
18 % if ( $custnum ) { 
19
20
21   <% include("/elements/header.html","View $label: $value") %>
22
23   <% include( '/elements/small_custview.html', $custnum, '', 1,
24      "${p}view/cust_main.cgi") %>
25   <BR>
26 % } else { 
27
28
29   <SCRIPT>
30   function areyousure(href) {
31       if (confirm("Permanently delete this <% $label %>?") == true)
32           window.location.href = href;
33   }
34   </SCRIPT>
35
36   <% include("/elements/header.html","View $label: $value", menubar(
37       "Cancel this (unaudited) $label" =>
38             "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')"
39   )) %>
40 % } 
41
42
43 Service #<B><% $svcnum %></B>
44 % my $url = $opt{'edit_url'} || $p. 'edit/'. $opt{'table'}. '.cgi?';
45 | <A HREF="<%$url%><%$svcnum%>">Edit this <% $label %></A>
46 <BR>
47
48 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
49
50 % foreach my $f ( @$fields ) {
51 %
52 %   my($field, $type);
53 %   if ( ref($f) ) {
54 %     $field = $f->{'field'},
55 %     $type  = $f->{'type'} || 'text',
56 %   } else {
57 %     $field = $f;
58 %     $type = 'text';
59 %   }
60 %
61 %   my $columndef = $part_svc->part_svc_column($field);
62 %   unless ($columndef->columnflag eq 'F' && !length($columndef->columnvalue)) {
63
64       <TR>
65         <TD ALIGN="right">
66           <% ( $opt{labels} && exists $opt{labels}->{$field} )
67                   ? $opt{labels}->{$field}
68                   : $field
69           %>
70         </TD>
71
72 %       #eventually more options for <SELECT>, etc. fields
73
74         <TD BGCOLOR="#ffffff"><% $svc_x->$field %><TD>
75
76       </TR>
77
78 %   }
79 %
80 % } 
81
82 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) { 
83   <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
84 % } 
85
86
87 </TABLE></TD></TR></TABLE>
88
89 <BR>
90
91 % if ( defined($opt{'html_foot'}) ) {
92
93   <% ref($opt{'html_foot'})
94        ? &{ $opt{'html_foot'} }($svc_x)
95        : $opt{'html_foot'}
96   %>
97   <BR>
98
99 % }
100
101 <% joblisting({'svcnum'=>$svcnum}, 1) %>
102
103 <% include('/elements/footer.html') %>
104 <%init>
105
106 die "access denied"
107   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
108
109 my(%opt) = @_;
110
111 my $table = $opt{'table'};
112
113 my $fields = $opt{'fields'}
114              #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
115              || [ grep { $_ ne 'svcnum' } fields($table) ];
116
117 my $svcnum;
118 if ( $cgi->param('svcnum') ) {
119   $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparsable svcnum";
120   $svcnum = $1;
121 } else {
122   my($query) = $cgi->keywords;
123   $query =~ /^(\d+)$/ or die "no svcnum";
124   $svcnum = $1;
125 }
126 my $svc_x = qsearchs({
127   'select'    => $opt{'table'}.'.*',
128   'table'     => $opt{'table'},
129   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
130                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
131                  ' LEFT JOIN cust_main USING ( custnum ) ',
132   'hashref'   => { 'svcnum' => $svcnum },
133   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
134 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
135
136 my $cust_svc = $svc_x->cust_svc;
137 my($label, $value, $svcdb) = $cust_svc->label;
138
139 my $part_svc = $cust_svc->part_svc;
140
141 my $pkgnum = $cust_svc->pkgnum;
142
143 my($cust_pkg, $custnum);
144 if ($pkgnum) {
145   $cust_pkg = $cust_svc->cust_pkg;
146   $custnum = $cust_pkg->custnum;
147 } else {
148   $cust_pkg = '';
149   $custnum = '';
150 }
151
152 </%init>