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