NG auth: autocreate records for external users, RT#21563
[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, 'edit_url' => $url &>
56 <BR>
57
58 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
59
60 % my @inventory_items = $svc_x->inventory_item;
61 % foreach my $f ( @$fields ) {
62 %
63 %   my($field, $type, $value);
64 %   if ( ref($f) ) {
65 %     $field = $f->{'field'};
66 %     $type  = $f->{'type'} || 'text';
67 %     if ( $f->{'value_callback'} ) {
68 %       my $hack_strict_refs = \&{ $f->{'value_callback'} };
69 %       $value = &$hack_strict_refs($svc_x);
70 %     } else {
71 %       $value = exists($f->{'value'}) ? $f->{'value'} : $svc_x->$field;
72 %     }
73 %   } else {
74 %     $field = $f;
75 %     $type = 'text';
76 %     $value = $svc_x->$field;
77 %   }
78 %
79 %   my $columndef = $part_svc->part_svc_column($field);
80 %   if ( $columndef->columnflag =~ /^[MA]$/ && $columndef->columnvalue =~ /,/ )
81 %   {
82 %     # inventory-select field with multiple classes
83 %     # show the class name to disambiguate
84 %     my ($item) = grep { $_->svc_field eq $field } @inventory_items;
85 %     my $class = qsearchs('inventory_class', { classnum => $item->classnum });
86 %     $value .= ' <i>('. $class->classname . ')</i>' if $class;
87 %   }
88 %   unless ($columndef->columnflag eq 'F' && !length($columndef->columnvalue)) {
89
90       <TR>
91         <TD ALIGN="right">
92           <% ( $opt{labels} && exists $opt{labels}->{$field} )
93                   ? $opt{labels}->{$field}
94                   : $field
95           %>
96         </TD>
97
98 %       $value = time2str($date_format,$value) if ( $type eq 'date' && $value );
99 %       $value = time2str("$date_format %H:%M",$value) if ( $type eq 'datetime' && $value );
100 %       $value = $value eq 'Y' ? emt('Yes') : emt('No') if ( $type eq 'checkbox' );
101 %       #eventually more options for <SELECT>, etc. fields
102
103         <TD BGCOLOR="#ffffff"><% $value %><TD>
104
105       </TR>
106
107 %   }
108 %
109 % } 
110
111 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) { 
112   <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
113 % } 
114
115
116 </TABLE></TD></TR></TABLE>
117
118 <BR>
119
120 % if ( defined($opt{'html_foot'}) ) {
121
122   <% ref($opt{'html_foot'})
123        ? &{ $opt{'html_foot'} }($svc_x)
124        : $opt{'html_foot'}
125   %>
126   <BR>
127
128 % }
129
130 <& /elements/table-tickets.html, object => $cust_svc &>
131
132 <% joblisting({'svcnum'=>$svcnum}, 1) %>
133
134 <% include('/elements/footer.html') %>
135 <%init>
136
137 die "access denied"
138   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
139
140 my(%opt) = @_;
141
142 my $conf = new FS::Conf;
143 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
144
145 my $table = $opt{'table'};
146
147 my $fields = $opt{'fields'}
148              #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
149              || [ grep { $_ ne 'svcnum' } fields($table) ];
150
151 my $svcnum;
152 if ( $cgi->param('svcnum') ) {
153   $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparsable svcnum";
154   $svcnum = $1;
155 } else {
156   my($query) = $cgi->keywords;
157   $query =~ /^(\d+)$/ or die "no svcnum";
158   $svcnum = $1;
159 }
160 my $svc_x = qsearchs({
161   'select'    => $opt{'table'}.'.*',
162   'table'     => $opt{'table'},
163   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
164                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
165                  ' LEFT JOIN cust_main USING ( custnum ) ',
166   'hashref'   => { 'svcnum' => $svcnum },
167   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
168                             'null_right' => 'View/link unlinked services'
169                           ),
170 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
171
172 my $cust_svc = $svc_x->cust_svc;
173 my($label, $value, $svcdb) = $cust_svc->label;
174
175 my $part_svc = $cust_svc->part_svc;
176
177 #false laziness w/edit/svc_Common.html
178 #override default labels with service-definition labels if applicable
179 my $labels = $opt{labels}; #not -> here
180 foreach my $field ( keys %$labels ) {
181   my $col = $part_svc->part_svc_column($field);
182   $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/;
183 }
184
185 my $pkgnum = $cust_svc->pkgnum;
186
187 my($cust_pkg, $custnum);
188 if ($pkgnum) {
189   $cust_pkg = $cust_svc->cust_pkg;
190   $custnum = $cust_pkg->custnum;
191 } else {
192   $cust_pkg = '';
193   $custnum = '';
194 }
195
196 &{ $opt{'svc_callback'} }( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, \%opt ) 
197     if $opt{'svc_callback'};
198 </%init>