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