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