first part of ACL and re-skinning work and some other small stuff
[freeside.git] / httemplate / search / cust_main.cgi
index 778cdf2..8b70ff4 100755 (executable)
@@ -57,6 +57,7 @@ if ( $cgi->param('browse')
 ) {
 
   my %search = ();
+
   if ( $cgi->param('browse') ) {
     my $query = $cgi->param('browse');
     if ( $query eq 'custnum' ) {
@@ -80,15 +81,16 @@ if ( $cgi->param('browse')
   } else {
     $sortby = \*last_sort; #??
     $orderby = "ORDER BY LOWER(last || ' ' || first)"; #??
-    if ( $cgi->param('otaker_on') ) {
-      $cgi->param('otaker') =~ /^(\w{1,32})$/ or eidiot "Illegal otaker\n";
-      $search{otaker} = $1;
-    } elsif ( $cgi->param('agentnum_on') ) {
-      $cgi->param('agentnum') =~ /^(\d+)$/ or eidiot "Illegal agentnum\n";
-      $search{agentnum} = $1;
-    } else {
-      die "unknown query...";
-    }
+  }
+
+  if ( $cgi->param('otaker_on') ) {
+    $cgi->param('otaker') =~ /^(\w{1,32})$/ or eidiot "Illegal otaker\n";
+    $search{otaker} = $1;
+  } elsif ( $cgi->param('agentnum_on') ) {
+    $cgi->param('agentnum') =~ /^(\d+)$/ or eidiot "Illegal agentnum\n";
+    $search{agentnum} = $1;
+#  } else {
+#    die "unknown query...";
   }
 
   my @qual = ();
@@ -100,18 +102,8 @@ if ( $cgi->param('browse')
              && ! $cgi->param('showcancelledcustomers') )
      ) {
     #grep { $_->ncancelled_pkgs || ! $_->all_pkgs }
-    push @qual, "
-       ( 0 < ( SELECT COUNT(*) FROM cust_pkg
-                      WHERE cust_pkg.custnum = cust_main.custnum
-                        AND ( cust_pkg.cancel IS NULL
-                              OR cust_pkg.cancel = 0
-                            )
-             )
-         OR 0 = ( SELECT COUNT(*) FROM cust_pkg
-                    WHERE cust_pkg.custnum = cust_main.custnum
-                )
-       )
-    ";
+    push @qual, FS::cust_main->uncancel_sql;
+
    }
 
   push @qual, FS::cust_main->cancel_sql   if $cgi->param('cancelled');
@@ -228,14 +220,13 @@ if ( scalar(@cust_main) == 1 && ! $cgi->param('referral_custnum') ) {
   eidiot "No matching customers found!\n";
 } else { 
 %>
-<!-- mason kludge -->
-<%
+<%= include('/elements/header.html', "Customer Search Results", '' ) %>
+
+  <% $total ||= scalar(@cust_main); %>
 
-  $total ||= scalar(@cust_main);
-  print header("Customer Search Results",menubar(
-    'Main Menu', popurl(2)
-  )), "$total matching customers found ";
+  <%= $total %> matching customers found
 
+  <%
   #begin pager
   my $pager = '';
   if ( $total != scalar(@cust_main) && $maxrecords ) {
@@ -285,7 +276,7 @@ if ( scalar(@cust_main) == 1 && ! $cgi->param('referral_custnum') ) {
       or eidiot "Illegal referral_custnum\n";
     my $referral_custnum = $1;
     my $cust_main = qsearchs('cust_main', { custnum => $referral_custnum } );
-    print '<FORM METHOD=POST>'.
+    print '<FORM METHOD="GET">'.
           qq!<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="$referral_custnum">!.
           'referrals of <A HREF="'. popurl(2).
           "view/cust_main.cgi?$referral_custnum\">$referral_custnum: ".
@@ -376,12 +367,14 @@ END
     my $pcompany = $company
       ? qq!<A HREF="$view"><FONT SIZE=-1>$company</FONT></A>!
       : '<FONT SIZE=-1>&nbsp;</FONT>';
-    print <<END;
+    %>
+
     <TR>
-      <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$custnum</FONT></A></TD>
-      <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$last, $first</FONT></A></TD>
-      <TD ROWSPAN=$rowspan>$pcompany</TD>
-END
+      <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= $custnum %></FONT></A></TD>
+      <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$last, $first" %></FONT></A></TD>
+      <TD ROWSPAN=<%= $rowspan || 1 %>><%= $pcompany %></TD>
+
+    <%
     if ( defined dbdef->table('cust_main')->column('ship_last') ) {
       my($ship_last,$ship_first,$ship_company)=(
         $cust_main->ship_last || $cust_main->getfield('last'),
@@ -391,43 +384,57 @@ END
       my $pship_company = $ship_company
         ? qq!<A HREF="$view"><FONT SIZE=-1>$ship_company</FONT></A>!
         : '<FONT SIZE=-1>&nbsp;</FONT>';
-      print <<END;
-      <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$ship_last, $ship_first</FONT></A></TD>
-      <TD ROWSPAN=$rowspan>$pship_company</A></TD>
-END
-    }
+      %>
+
+      <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$ship_last, $ship_first" %></FONT></A></TD>
+      <TD ROWSPAN=<%= $rowspan || 1 %>><%= $pship_company %></A></TD>
+
+    <% }
 
-    foreach my $addl_col ( @addl_cols ) {
-      print "<TD ROWSPAN=$rowspan ALIGN=right>";
-      if ( $addl_col eq 'tickets' ) {
+    foreach my $addl_col ( @addl_cols ) { %>
+
+      <TD ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
+
+      <% if ( $addl_col eq 'tickets' ) {
         if ( @custom_priorities ) {
           print &itable('', 0);
           foreach my $priority ( @custom_priorities, '' ) {
-            my $ahref =
-              '<A HREF="'.
-                FS::TicketSystem->href_customer_tickets($custnum,$priority).
-              '">';
-            print "<TR><TD ALIGN=right>$ahref".
-                    FS::TicketSystem->num_customer_tickets($custnum,$priority).
-                  "</A></TD>".
-                  "<TD ALIGN=left>$ahref".
+          
+            my $num =
+              FS::TicketSystem->num_customer_tickets($custnum,$priority);
+            my $ahref = '';
+            $ahref= '<A HREF="'.
+                    FS::TicketSystem->href_customer_tickets($custnum,$priority).
+                    '">'
+              if $num;
+
+            print '<TR>'.
+                  "  <TD ALIGN=right><FONT SIZE=-1>$ahref$num</A></FONT></TD>".
+                  "<TD ALIGN=left><FONT SIZE=-1>$ahref".
                   ( $priority || '<i>(none)</i>' ).
-                  "</A></TD></TR>";
+                  "</A></FONT></TD></TR>";
+
           }
           print '<TR><TD BGCOLOR="#000000" COLSPAN=2></TD></TR>'.
-                '<TR><TD ALIGN=right>';
+                '<TR><TD ALIGN=right><FONT SIZE=-1>';
         }
-        my $ahref =
-          '<A HREF="'.
-            FS::TicketSystem->href_customer_tickets($custnum).
-          '">';
+
+        my $ahref = '';
+        $ahref = '<A HREF="'.
+                    FS::TicketSystem->href_customer_tickets($custnum).
+                    '">'
+          if $cust_main->get($addl_col);
+
         print $ahref. $cust_main->get($addl_col). '</A>';
-        print "</TD><TD ALIGN=left>${ahref}Total</A></TD></TR></TABLE>"
+        print "</FONT></TD><TD ALIGN=left>".
+              "<FONT SIZE=-1>${ahref}Total</A><FONT>".
+              "</TD></TR></TABLE>"
           if @custom_priorities;
+
       } else {
         print $cust_main->get($addl_col);
       }
-      print "</TD>";
+      print "</FONT></TD>";
     }
 
     my($n1)='';
@@ -458,10 +465,14 @@ END
     }
     print "</TR>";
   }
+
+  %>
  
-  print "</TABLE>$pager</BODY></HTML>";
+  </TABLE><%= $pager %>
 
-}
+  <%= include('/elements/footer.html') %>
+
+<% }
 
 #undef $cache; #does this help?