RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / elements / select-tower_sector.html
1 % if ( ! $opt{'multiple'} ) {
2 <& /elements/select-table.html,
3     table       => 'tower_sector',
4     name_col    => 'description',
5     addl_from   => 'JOIN tower USING (towernum)',
6     extra_sql   => $extra_sql,
7     order_by    => 'ORDER BY towernum,sectorname',
8     empty_label => ' ',
9     @_ 
10 &>
11 % }
12 % else { # currently only multiple sectors, not towers
13 <& /elements/select-table.html,
14     table       => 'tower',
15     name_col    => 'towername',
16     hashref     => { 'disabled' => '', },
17     id          => 'towernum',
18     field       => 'towernum',
19     onchange    => 'change_towernum(this.value);',
20     element_etc => 'STYLE="vertical-align:top"',
21 &>
22 <SELECT NAME="sectornum" ID="sectornum" MULTIPLE SIZE="6"></SELECT>
23 <SCRIPT TYPE="text/javascript">
24 var sectors_of = <% encode_json(\%sectors_of) %>;
25 var select_sectornum = document.getElementById('sectornum');
26 function change_towernum(towernum) {
27   select_sectornum.options.length = 0;
28   for (var sectornum in sectors_of[towernum]) {
29     var o = document.createElement('OPTION');
30     o.value = sectornum;
31     o.text = sectors_of[towernum][sectornum];
32     o.selected = true;
33     select_sectornum.add(o, null);
34   }
35   return;
36 }
37 change_towernum('');
38 </SCRIPT>
39 <BR>
40 <INPUT TYPE="checkbox" VALUE="none" NAME="sectornum" CHECKED> <% $empty_label %>
41 % }
42 <%init>
43 my %opt = @_;
44
45 my %sectors_of;
46 my %default_of;
47 if ( $opt{'multiple'} ) {
48   foreach my $sector ( qsearch('tower_sector',{}) ) {
49     $sectors_of{$sector->towernum} ||= {};
50     $sectors_of{$sector->towernum}->{$sector->sectornum} = $sector->sectorname;
51     $sectors_of{''}->{$sector->sectornum} = $sector->description;
52     $default_of{$sector->towernum} = $sector->sectornum
53       if $sector->sectorname eq '_default';
54   }
55 }
56 foreach my $towernum (keys %sectors_of) {
57   # hide default sectors for towers that have real sectors defined
58   my $sectornum = $default_of{$towernum};
59   if ( keys %{ $sectors_of{$towernum} } > 1 ) {
60     delete $sectors_of{$towernum}->{$sectornum};
61     delete $sectors_of{''}->{$sectornum};
62   }
63   else {
64   # show default sectorname as '(all)'
65     $sectors_of{$towernum}->{$sectornum} = '(all)'
66   }
67 }
68
69 my $empty_label = $opt{'empty_label'} || 'Include services with no sector';
70
71 my $extra_sql = q(WHERE (disabled = '' OR disabled IS NULL));
72 $extra_sql .= q( AND sectorname != '_default') if $opt{'sectorsonly'};
73 </%init>