This commit was manufactured by cvs2svn to create branch 'freeside_import'.
[freeside.git] / htdocs / misc / expire_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # expire_pkg.cgi: Expire a package
4 #
5 # Usage: post form to:
6 #        http://server.name/path/expire_pkg.cgi
7 #
8 # Note: Should be run setuid freeside as user nobody
9 #
10 # based on susp_pkg
11 # ivan@voicenet.com 97-jul-29
12 #
13 # ivan@sisd.com 98-mar-17 FS::Search->FS::Record
14 #
15 # Changes to allow page to work at a relative position in server
16 #       bmccane@maxbaud.net     98-apr-3
17
18 use strict;
19 use Date::Parse;
20 use CGI::Request;
21 use CGI::Carp qw(fatalsToBrowser);
22 use FS::UID qw(cgisuidsetup);
23 use FS::Record qw(qsearchs);
24 use FS::cust_pkg;
25
26 my($req) = new CGI::Request;
27 &cgisuidsetup($req->cgi);
28
29 #untaint date & pkgnum
30
31 my($date);
32 if ( $req->param('date') ) {
33   str2time($req->param('date')) =~ /^(\d+)$/ or die "Illegal date";
34   $date=$1;
35 } else {
36   $date='';
37 }
38
39 $req->param('pkgnum') =~ /^(\d+)$/ or die "Illegal pkgnum";
40 my($pkgnum)=$1;
41
42 my($cust_pkg) = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
43 my(%hash)=$cust_pkg->hash;
44 $hash{expire}=$date;
45 my($new)=create FS::cust_pkg ( \%hash );
46 my($error) = $new->replace($cust_pkg);
47 &idiot($error) if $error;
48
49 $req->cgi->redirect("../view/cust_main.cgi?".$cust_pkg->getfield('custnum'));
50
51 sub idiot {
52   my($error)=@_;
53   SendHeaders();
54   print <<END;
55 <HTML>
56   <HEAD>
57     <TITLE>Error expiring package</TITLE>
58   </HEAD>
59   <BODY>
60     <CENTER>
61     <H1>Error expiring package</H1>
62     </CENTER>
63     <HR>
64     There has been an error expiring this package:  $error
65   </BODY>
66   </HEAD>
67 </HTML>
68 END
69   exit;
70 }
71