fix county selector
[freeside.git] / httemplate / misc / counties.cgi
index c9eb985..940cba7 100644 (file)
@@ -1,18 +1,27 @@
-%
-%
-%  my( $state, $country ) = $cgi->param('arg');
-%
-%  my @counties = 
-%     sort
-%     map { s/[\n\r]//g; $_; }
-%     map { $_->county; }
-%     qsearch( 'cust_main_county',
-%              { 'state'   => $state,
-%                'country' => $country,
-%              },
-%            )
-%  ;
-%
-%
-%
 [ <% join(', ', map { qq("$_") } @counties) %> ]
+<%init>
+
+my $DEBUG = 0;
+
+my( $state, $country ) = $cgi->param('arg');
+
+warn "fetching counties for $state / $country \n"
+  if $DEBUG;
+
+my @counties = 
+    sort
+    map { s/[\n\r]//g; $_; }
+    map { $_->county; }
+    qsearch( {
+      'select'  => 'DISTINCT county',
+      'table'   => 'cust_main_county',
+      'hashref' => { 'state'   => $state,
+                     'country' => $country,
+                   },
+    } )
+;
+
+warn "counties: ". join(', ', map { qq("$_") } @counties). "\n"
+  if $DEBUG;
+
+</%init>