removed <!-- $Id$ --> from all files to fix any redirects, whew
[freeside.git] / httemplate / search / cust_pkg.cgi
index e862cef..6b25fec 100755 (executable)
@@ -1,43 +1,24 @@
 <%
-# <!-- $Id: cust_pkg.cgi,v 1.7 2001-12-03 10:59:25 ivan Exp $ -->
-
-use strict;
-use vars qw ( $cgi @cust_pkg $sortby $query %part_pkg
-              $conf $maxrecords $limit $offset );
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use FS::UID qw(dbh cgisuidsetup);
-use FS::Conf;
-use FS::Record qw(qsearch qsearchs dbdef);
-use FS::CGI qw(header eidiot popurl table);
-use FS::cust_pkg;
-use FS::pkg_svc;
-use FS::cust_svc;
-use FS::cust_main;
-
-$cgi = new CGI;
-&cgisuidsetup($cgi);
-
-$conf = new FS::Conf;
-$maxrecords = $conf->config('maxsearchrecordsperpage');
+
+my $conf = new FS::Conf;
+my $maxrecords = $conf->config('maxsearchrecordsperpage');
 
 my %part_pkg = map { $_->pkgpart => $_ } qsearch('part_pkg', {});
 
-$limit = '';
+my $limit = '';
 $limit .= "LIMIT $maxrecords" if $maxrecords;
 
-$offset = $cgi->param('offset') || 0;
+my $offset = $cgi->param('offset') || 0;
 $limit .= " OFFSET $offset" if $offset;
 
 my $total;
 
-($query) = $cgi->keywords;
 my $unconf = '';
-#this tree is a little bit redundant
+my($query) = $cgi->keywords;
+my $sortby;
 if ( $query eq 'pkgnum' ) {
   $sortby=\*pkgnum_sort;
 
-
 } elsif ( $query eq 'APKG_pkgnum' ) {
 
   $sortby=\*pkgnum_sort;
@@ -86,20 +67,21 @@ my $sth = dbh->prepare($statement)
   or die dbh->errstr. " doing $statement";
 $sth->execute or die "Error executing \"$statement\": ". $sth->errstr;
 
-$total = @{$sth->fetchrow_arrayref}[0];
+$total = $sth->fetchrow_arrayref->[0];
 
-@cust_pkg = qsearch('cust_pkg',{}, '', "$unconf ORDER BY pkgnum $limit" );
+my @cust_pkg = qsearch('cust_pkg',{}, '', "$unconf ORDER BY pkgnum $limit" );
 
 
 if ( scalar(@cust_pkg) == 1 ) {
   my($pkgnum)=$cust_pkg[0]->pkgnum;
   print $cgi->redirect(popurl(2). "view/cust_pkg.cgi?$pkgnum");
-  exit;
+  #exit;
 } elsif ( scalar(@cust_pkg) == 0 ) { #error
   eidiot("No packages found");
 } else {
   $total ||= scalar(@cust_pkg);
 
+  #begin pager
   my $pager = '';
   if ( $total != scalar(@cust_pkg) && $maxrecords ) {
     unless ( $offset == 0 ) {
@@ -124,11 +106,17 @@ if ( scalar(@cust_pkg) == 1 ) {
                 '"><B><FONT SIZE="+1">Next</FONT></B></A> ';
     }
   }
+  #end pager
   
   print header('Package Search Results',''),
         "$total matching packages found<BR><BR>$pager", &table(), <<END;
       <TR>
         <TH>Package</TH>
+        <TH><FONT SIZE=-1>Setup</FONT></TH>
+        <TH><FONT SIZE=-1>Next<BR>bill</FONT></TH>
+        <TH><FONT SIZE=-1>Susp.</FONT></TH>
+        <TH><FONT SIZE=-1>Expire</FONT></TH>
+        <TH><FONT SIZE=-1>Cancel</FONT></TH>
         <TH><FONT SIZE=-1>Cust#</FONT></TH>
         <TH>(bill) name</TH>
         <TH>company</TH>
@@ -152,8 +140,24 @@ END
     sort $sortby grep(!$saw{$_->pkgnum}++, @cust_pkg)
   ) {
     my($cust_main)=qsearchs('cust_main',{'custnum'=>$cust_pkg->custnum});
-    my($pkgnum, $custnum, $last, $first, $company) = (
+    my($pkgnum, $setup, $bill, $susp, $expire, $cancel,
+       $custnum, $last, $first, $company ) = (
       $cust_pkg->pkgnum,
+      $cust_pkg->getfield('setup')
+        ? time2str("%D", $cust_pkg->getfield('setup') )
+        : '',
+      $cust_pkg->getfield('bill')
+        ? time2str("%D", $cust_pkg->getfield('bill') )
+        : '',
+      $cust_pkg->getfield('susp')
+        ? time2str("%D", $cust_pkg->getfield('susp') )
+        : '',
+      $cust_pkg->getfield('expire')
+        ? time2str("%D", $cust_pkg->getfield('expire') )
+        : '',
+      $cust_pkg->getfield('cancel')
+        ? time2str("%D", $cust_pkg->getfield('cancel') )
+        : '',
       $cust_pkg->custnum,
       $cust_main ? $cust_main->last : '',
       $cust_main ? $cust_main->first : '',
@@ -184,6 +188,11 @@ END
     my $p = popurl(2);
     print $n1, <<END;
       <TD ROWSPAN=$rowspan><A HREF="${p}view/cust_pkg.cgi?$pkgnum"><FONT SIZE=-1>$pkgnum - $pkg</FONT></A></TD>
+      <TD>$setup</TD>
+      <TD>$bill</TD>
+      <TD>$susp</TD>
+      <TD>$expire</TD>
+      <TD>$cancel</TD>
 END
     if ( $cust_main ) {
       print <<END;