combine ticket notification scrips, #15353
[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 &>
56 <BR>
57
58 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
59
60 % foreach my $f ( @$fields ) {
61 %
62 %   my($field, $type, $value, $hack_strict_refs);
63 %   if ( ref($f) ) {
64 %     $field = $f->{'field'};
65 %     $hack_strict_refs = \&{ $f->{'value'} } if $f->{'value'};
66 %     $value = $f->{'value'} ? &$hack_strict_refs($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 %       $value = time2str($date_format,$value) if ( $type eq 'date' && $value );
86 %       $value = time2str("$date_format %H:%M",$value) if ( $type eq 'datetime' && $value );
87 %       $value = $value eq 'Y' ? emt('Yes') : emt('No') if ( $type eq 'checkbox' );
88 %       #eventually more options for <SELECT>, etc. fields
89
90         <TD BGCOLOR="#ffffff"><% $value %><TD>
91
92       </TR>
93
94 %   }
95 %
96 % } 
97
98 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) { 
99   <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
100 % } 
101
102
103 </TABLE></TD></TR></TABLE>
104
105 <BR>
106
107 % if ( defined($opt{'html_foot'}) ) {
108
109   <% ref($opt{'html_foot'})
110        ? &{ $opt{'html_foot'} }($svc_x)
111        : $opt{'html_foot'}
112   %>
113   <BR>
114
115 % }
116
117 <% joblisting({'svcnum'=>$svcnum}, 1) %>
118
119 <% include('/elements/footer.html') %>
120 <%init>
121
122 die "access denied"
123   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
124
125 my(%opt) = @_;
126
127 my $conf = new FS::Conf;
128 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
129
130 my $table = $opt{'table'};
131
132 my $fields = $opt{'fields'}
133              #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
134              || [ grep { $_ ne 'svcnum' } fields($table) ];
135
136 my $svcnum;
137 if ( $cgi->param('svcnum') ) {
138   $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparsable svcnum";
139   $svcnum = $1;
140 } else {
141   my($query) = $cgi->keywords;
142   $query =~ /^(\d+)$/ or die "no svcnum";
143   $svcnum = $1;
144 }
145 my $svc_x = qsearchs({
146   'select'    => $opt{'table'}.'.*',
147   'table'     => $opt{'table'},
148   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
149                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
150                  ' LEFT JOIN cust_main USING ( custnum ) ',
151   'hashref'   => { 'svcnum' => $svcnum },
152   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
153                             'null_right' => 'View/link unlinked services'
154                           ),
155 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
156
157 my $cust_svc = $svc_x->cust_svc;
158 my($label, $value, $svcdb) = $cust_svc->label;
159
160 my $part_svc = $cust_svc->part_svc;
161
162 #false laziness w/edit/svc_Common.html
163 #override default labels with service-definition labels if applicable
164 my $labels = $opt{labels}; #not -> here
165 foreach my $field ( keys %$labels ) {
166   my $col = $part_svc->part_svc_column($field);
167   $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/;
168 }
169
170 my $pkgnum = $cust_svc->pkgnum;
171
172 my($cust_pkg, $custnum);
173 if ($pkgnum) {
174   $cust_pkg = $cust_svc->cust_pkg;
175   $custnum = $cust_pkg->custnum;
176 } else {
177   $cust_pkg = '';
178   $custnum = '';
179 }
180
181 &{ $opt{'svc_callback'} }( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, \%opt ) 
182     if $opt{'svc_callback'};
183 </%init>