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