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