Initial revision
authornborisov <nborisov>
Thu, 21 Nov 1996 19:01:32 +0000 (19:01 +0000)
committernborisov <nborisov>
Thu, 21 Nov 1996 19:01:32 +0000 (19:01 +0000)
delterm.pl [new file with mode: 0644]

diff --git a/delterm.pl b/delterm.pl
new file mode 100644 (file)
index 0000000..e077bb2
--- /dev/null
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+# $Id$
+# $Log$
+# Revision 1.1  1996/11/21 19:01:32  nborisov
+# Initial revision
+#
+#
+# deletes a term of membership for a specified user
+# ie. sell back a term of membership (without any
+# monetary accounting)
+#
+
+require 'database.pl';
+
+$MEMDB = "memdb.new";
+
+do { print <<USAGE; exit 1; } unless $#ARGV >= 1;
+Usage:
+  $ARGV[0] memnum terms...
+ or
+  $ARGV[0] memnum term-term
+USAGE
+
+
+dbmtie($MEMDB, \%MEM) || die;
+
+$memnum = shift @ARGV;
+
+if (!defined $MEM{$memnum}) {
+       dbmuntie(\%MEM);
+       die;
+}
+
+if ($ARGV[0] =~ /([SWF]\d\d)-([SWF]\d\d)/i) {
+       $first = $1;
+       $last = $2;
+       $first =~ y/A-Z/a-z/;
+       $last =~ y/A-Z/a-z/;
+# ranges with the first term greater than next aren't allowed
+       die "Invalid range" if CmpTerm($first, $last) > 0;
+       for($term = $first; $term ne $last; &IncTerm($term)) {
+               push(@terms, $term);
+       }
+       push(@terms, $last);
+       #print "Term range resulted in @terms\n";
+} else {
+       @terms = @ARGV;
+}
+
+
+@recs = split(/;/, $MEM{$memnum});
+
+foreach $term (@terms) {
+       $term =~ y/A-Z/a-z/;
+
+       @mems = split(/,/, $MEM{$term});
+       @newmem = grep ($_ != $memnum, @mems) ;
+       $MEM{$term} = join(',', @newmem);
+
+       $recs[7] =~ s/$term,?//;
+}
+
+$MEM{$memnum} = join(';', @recs);
+
+untie(%MEM);
+
+exit 0;
+
+sub IncTerm
+{
+        $_[0] =~ y/wWsSfF/sSfFwW/;
+        local($tm, $yr) = $_[0] =~ /^([wWsSfF])(\d+)$/;
+        if ($tm =~ /[wW]/)
+        {
+                $yr++;
+                $yr %= 100;
+                $yr = "0$yr" if $yr < 10;
+                $_[0] = "$tm$yr";
+        }
+}
+
+sub CmpTerm
+{
+        local($tm0, $yr0) = $_[0] =~ /^([wWsSfF])(\d+)$/;
+        local($tm1, $yr1) = $_[1] =~ /^([wWsSfF])(\d+)$/;
+        $tm0 =~ y/wWsSfF/001122/;
+        $tm1 =~ y/wWsSfF/001122/;
+        $yr0 += 100 if $yr0 < 90;
+        $yr1 += 100 if $yr1 < 90;
+        "$yr0.$tm0" <=> "$yr1.$tm1";
+}
+