0500248b161cb8d91aca207ac0f11fc84b46619d
[freeside.git] / httemplate / view / elements / svc_Common.html
1 %  # options example...
2 %  #
3 %  # 'table' => 'svc_something'
4 %  #
5 %  # 'labels' => {
6 %  #               'column' => 'Label',
7 %  #             },
8 %  #
9 %  # listref - each item is a literal column name (or method) or (notyet) coderef
10 %  # if not specified all columns (except for the primary key) will be viewable
11 %  # 'fields' => [
12 %  #             ]
13 %  #
14 %  # # defaults to "edit/$table.cgi?", will have svcnum appended
15 %  # 'edit_url' => 
16 %
17 %
18 % if ( $custnum ) { 
19
20
21   <% include("/elements/header.html","View $label: $value") %>
22
23   <% include( '/elements/small_custview.html', $custnum, '', 1,
24      "${p}view/cust_main.cgi") %>
25   <BR>
26 % } else { 
27
28
29   <SCRIPT>
30   function areyousure(href) {
31       if (confirm("Permanently delete this <% $label %>?") == true)
32           window.location.href = href;
33   }
34   </SCRIPT>
35
36   <% include("/elements/header.html","View $label: $value", menubar(
37       "Cancel this (unaudited) $label" =>
38             "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')"
39   )) %>
40 % } 
41
42
43 Service #<B><% $svcnum %></B>
44 % my $url = $opt{'edit_url'} || $p. 'edit/'. $opt{'table'}. '.cgi?';
45 | <A HREF="<%$url%><%$svcnum%>">Edit this <% $label %></A>
46 <BR>
47
48 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
49 % foreach my $f ( @$fields ) {
50 %
51 %     my( $field, $type);
52 %     if ( ref($f) ) {
53 %       $field = $f->{'field'},
54 %       $type  = $f->{'type'} || 'text',
55 %     } else {
56 %       $field = $f;
57 %       $type = 'text';
58 %     }
59 %
60
61
62   <TR>
63     <TD ALIGN="right">
64       <% ( $opt{labels} && exists $opt{labels}->{$field} )
65               ? $opt{labels}->{$field}
66               : $field
67       %>
68     </TD>
69 %
70 %      #eventually more options for <SELECT>, etc. fields
71 %    
72
73
74     <TD BGCOLOR="#ffffff"><% $svc_x->$field %><TD>
75
76   </TR>
77 % } 
78 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) { 
79
80   <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
81 % } 
82
83
84 </TABLE></TD></TR></TABLE>
85
86 <BR>
87 <% joblisting({'svcnum'=>$svcnum}, 1) %>
88
89 <% include('/elements/footer.html') %>
90 <%init>
91
92 die "access denied"
93   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
94
95 my(%opt) = @_;
96
97 my $table = $opt{'table'};
98
99 my $fields = $opt{'fields'}
100              #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
101              || [ grep { $_ ne 'svcnum' } fields($table) ];
102
103 my $svcnum;
104 if ( $cgi->param('svcnum') ) {
105   $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparsable svcnum";
106   $svcnum = $1;
107 } else {
108   my($query) = $cgi->keywords;
109   $query =~ /^(\d+)$/ or die "no svcnum";
110   $svcnum = $1;
111 }
112 my $svc_x = qsearchs({
113   'select'    => $opt{'table'}.'.*',
114   'table'     => $opt{'table'},
115   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
116                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
117                  ' LEFT JOIN cust_main USING ( custnum ) ',
118   'hashref'   => { 'svcnum' => $svcnum },
119   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
120 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
121
122 my $cust_svc = $svc_x->cust_svc;
123 my($label, $value, $svcdb) = $cust_svc->label;
124
125 my $pkgnum = $cust_svc->pkgnum;
126
127 my($cust_pkg, $custnum);
128 if ($pkgnum) {
129   $cust_pkg = $cust_svc->cust_pkg;
130   $custnum = $cust_pkg->custnum;
131 } else {
132   $cust_pkg = '';
133   $custnum = '';
134 }
135
136 </%init>