RT# 83039 - only towers with sectors shown on provisioning page when export requires...
[freeside.git] / httemplate / elements / select-tower_sector.html
index 456ef41..4dfd23d 100644 (file)
@@ -2,6 +2,8 @@
 <& /elements/select-table.html,
     table       => 'tower_sector',
     name_col    => 'description',
+    addl_from   => 'JOIN tower USING (towernum)',
+    extra_sql   => $extra_sql,
     order_by    => 'ORDER BY towernum,sectorname',
     empty_label => ' ',
     @_ 
@@ -11,8 +13,9 @@
 <& /elements/select-table.html,
     table       => 'tower',
     name_col    => 'towername',
+    hashref     => { 'disabled' => '', },
     id          => 'towernum',
-    field       => 'dummy_towernum',
+    field       => 'towernum',
     onchange    => 'change_towernum(this.value);',
     element_etc => 'STYLE="vertical-align:top"',
 &>
@@ -34,17 +37,37 @@ function change_towernum(towernum) {
 change_towernum('');
 </SCRIPT>
 <BR>
-<INPUT TYPE="checkbox" VALUE="none" NAME="sectornum" CHECKED> No sector
+<INPUT TYPE="checkbox" VALUE="none" NAME="sectornum" CHECKED> <% $empty_label %>
 % }
 <%init>
 my %opt = @_;
 
 my %sectors_of;
+my %default_of;
 if ( $opt{'multiple'} ) {
   foreach my $sector ( qsearch('tower_sector',{}) ) {
     $sectors_of{$sector->towernum} ||= {};
     $sectors_of{$sector->towernum}->{$sector->sectornum} = $sector->sectorname;
     $sectors_of{''}->{$sector->sectornum} = $sector->description;
+    $default_of{$sector->towernum} = $sector->sectornum
+      if $sector->sectorname eq '_default';
   }
 }
+foreach my $towernum (keys %sectors_of) {
+  # hide default sectors for towers that have real sectors defined
+  my $sectornum = $default_of{$towernum};
+  if ( keys %{ $sectors_of{$towernum} } > 1 ) {
+    delete $sectors_of{$towernum}->{$sectornum};
+    delete $sectors_of{''}->{$sectornum};
+  }
+  else {
+  # show default sectorname as '(all)'
+    $sectors_of{$towernum}->{$sectornum} = '(all)'
+  }
+}
+
+my $empty_label = $opt{'empty_label'} || 'Include services with no sector';
+
+my $extra_sql = q(WHERE (disabled = '' OR disabled IS NULL));
+$extra_sql .= q( AND sectorname != '_default') if $opt{'sectorsonly'};
 </%init>