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