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