[mlvanbie] integrated fixlib into lib_sys.pl use MemThisTerm function Don't
authornborisov <nborisov>
Tue, 22 Apr 1997 20:59:21 +0000 (20:59 +0000)
committernborisov <nborisov>
Tue, 22 Apr 1997 20:59:21 +0000 (20:59 +0000)
    complain about incorrect ISBNs if the entry is already in the database

lib_sys.pl

index 51df4eb..67adcfd 100644 (file)
@@ -37,6 +37,13 @@ sub dobookin
 {
     local ($bid);
        local ($yes);
+
+       tie(%LIB, NDBM_File, $LIBDB, O_RDWR, 0600) || do
+    {
+        print "\n${beep}Error opening library database: $!\n";
+        return;
+    };
+
     ## Get the book ID
     while(1)
     {
@@ -48,6 +55,7 @@ sub dobookin
         if ($bid =~ /^\s*$/)
         {
             print "\n${beep}No ID supplied - aborting.\n";
+                       untie(%LIB);
             return;
         }
         unless (&validbookID($bid))
@@ -55,7 +63,8 @@ sub dobookin
             print "\n${beep}Invalid checksum - try again.\n\n";
             next;
         }
-               unless (&ISBN_checksum($bid)) {
+               unless (&ISBN_checksum($bid) ||
+                       defined $LIB{$bid}) {
                        print "\n${beep}WARNING: Invalid ISBN: $bid.\n",
                                  "Are you sure this is the right ID? ";
                        $yes = <STDIN>;
@@ -64,12 +73,6 @@ sub dobookin
         last;
     }
 
-    tie(%LIB, NDBM_File, $LIBDB, O_RDWR, 0600) || do
-    {
-        print "\n${beep}Error opening library database: $!\n";
-        return;
-    };
-
     ## Make a library entry for this book, if none already
     &Lib_Newbook($bid) unless defined $LIB{$bid};
 
@@ -143,7 +146,7 @@ sub dobookout
         dbmuntie(\%MEM);
         return;
     }
-    $match = grep(/^$TERM$/,split(/,/,(split(/;/,$MEM{$memnum}))[7]));
+       $match = &MemThisTerm((split(/;/,$MEM{$memnum}))[7]);
     unless ($match)
     {
         print "\n${beep}This member has not paid for the current term.\n";
@@ -165,6 +168,13 @@ sub dobookout
 
     print "\nName: $thename\n\n";
 
+    ## Read the library file
+    tie(%LIB, NDBM_File, $LIBDB, O_RDWR, 0600) || do
+    {
+        print "\n${beep}Error opening library database: $!\n";
+        return;
+    };
+
     ## Get the book ID
     while(1)
     {
@@ -174,6 +184,7 @@ sub dobookout
         if ($bid =~ /^\s*$/)
         {
             print "\n${beep}No ID supplied - aborting.\n";
+                       untie(%LIB);
             return;
         }
         unless (&validbookID($bid))
@@ -181,7 +192,8 @@ sub dobookout
             print "\n${beep}Invalid checksum - try again.\n\n";
             next;
         }
-               unless (&ISBN_checksum($bid)) {
+               unless (&ISBN_checksum($bid) ||
+                       defined $LIB{$bid}) {
                        print "\n${beep}WARNING: Invalid ISBN: $bid.\n",
                                  "Are you sure this is the right ID? ";
                        $yes = <STDIN>;
@@ -190,12 +202,6 @@ sub dobookout
         last;
     }
     
-    ## Read the library file
-    tie(%LIB, NDBM_File, $LIBDB, O_RDWR, 0600) || do
-    {
-        print "\n${beep}Error opening library database: $!\n";
-        return;
-    };
 
     ## Make a library entry for this book, if none already
     &Lib_Newbook($bid) unless defined $LIB{$bid};
@@ -521,6 +527,36 @@ sub doeditdb
                }
        }
 
+       my( $choice ) = 0;
+
+       @opts = ('eeasy','sscary','ldone');
+       while( $choice ne "done" ){
+               $choice = &domenu(<<EOM,@opts);
+Choose an option:
+  (E)asy book list edit
+  (S)cary edit (things office minions were not meant to know)
+  (L)ibrary menu (don't leave this menu up when you are done!)
+
+(E,S,L): 
+EOM
+               
+               if( $choice eq "scary" ){
+                       &scary_edit;
+               } elsif( $choice eq "easy" ){
+                       &easy_edit;
+               }
+       }
+
+       &Backup("$LIBDB.db");
+       &Backup("$LIBDB.dir");
+       &Backup("$LIBDB.pag");
+
+       &Gopher_Outstanding;
+}
+
+
+sub scary_edit
+{
        if( !open(TMPFILE, ">lib.edit") ){
         print "\n${beep}Error opening temporary file: $!\n";
        }
@@ -555,10 +591,119 @@ sub doeditdb
        }
 
        untie(%LIB);
-       &Backup("$LIBDB.db");
-       &Backup("$LIBDB.dir");
-       &Backup("$LIBDB.pag");
+}
 
-       &Gopher_Outstanding;
+# fixlib: allows library fixing
+#
+# Date                 Name                            Modification
+# ----          ----                ------------
+# 95/08/07             Alex Brodsky            Initial implementation
+#               mlvanbie            Integrated it
+
+
+sub ModLib
+{
+       my($TMPFILE) = "ceofixlib.tmpfile";
+       local( $bid ) = shift;
+       local( @answers );
+       local( @r );
+       local( $dstr );
+
+    @answers = ($LIB{$bid} =~ m/.\{([^\}]*)\}/g);
+       $answers[8] = $bid;
+
+       open (EDIT, ">$TMPFILE") || do {
+               print "\a\nUnable to open edit file: $!\n";
+               return;
+       };
+
+       print EDIT "Title     : $answers[0]\n";
+       print EDIT "Author    : $answers[1]\n";
+       print EDIT "Publisher : $answers[2]\n";
+       print EDIT "Year      : $answers[3]\n";
+       print EDIT "ISBN      : $answers[4]\n";
+       print EDIT "Type      : $answers[5]\n";
+       print EDIT "Who has it: $answers[6]\n";
+       print EDIT "Date      : $answers[7]\n";
+       print EDIT "Book ID   : $answers[8]\n";
+       close(EDIT);
+
+       system("$EDITOR $TMPFILE");
+
+       open(EDIT, $TMPFILE) || do {
+               print "\a\nUnable to open edit file: $!\n";
+               return;
+       };
+       @r = <EDIT>;
+       close(EDIT);
+
+       @r = grep( s/^.*: //g, @r );
+       @r = grep( s/\n//g, @r );
+
+       $dstr = "N{$r[0]}A{$r[1]}P{$r[2]}Y{$r[3]}I{$r[4]}T{$r[5]}W{$r[6]}D{$r[7]}";
+
+       if( ( $dstr ne $LIB{$bid} ) || ( $bid ne $r[8] ) ) {
+               print "Changing entry\n";
+               print "Old: $LIB{$bid}\n";
+               print "New: $dstr\n";
+               delete $LIB{$bid};
+               $LIB{$r[8]} = $dstr;
+       } else {
+               print "No change made\n";
+       }
 }
+
+
+sub easy_edit
+{
+       my($bid);
+       my($TMPFILE) = "ceofixlib.tmpfile";
+
+    ## open database
+    tie(%LIB, NDBM_File, $LIBDB, O_RDWR, 0600) || do
+    {
+        print "\n\aError opening library database: $!\n";
+        return;
+    };
+
+       print "\nEnter book ID (or enter for list): ";
+       $bid = <STDIN>;
+       chomp $bid;
+       $bid =~ s/^\s*(.*\S)\s*$/$1/;
+
+       if( $bid eq "" ) {
+               local($a);
+               local($b);
+               $a = $b = 0;
+
+               print "ISBN key required to edit entry, here is complete list\n";
+
+               open(SCRLIBLOG, ">$editfile") || do
+               {
+                       print "\n${beep}Unable to open output file: $!\n";
+                       untie( %LIB );
+                       return;
+               };
+
+               select(SCRLIBLOG);
+       @list = sort {$a<=>$b} keys %LIB;
+               foreach $bid (@list)
+               {
+                       ($title) = ($LIB{$bid} =~ m/.\{([^\}]*)\}/g);
+               print "$title $bid\n";
+               }
+               select(STDOUT);
+               close(SCRLIBLOG);
+               &MORE;
+       } else {
+               if( defined $LIB{ $bid } ) {
+                       &ModLib( $bid );
+               } else {
+                       print "Entry not found\n";
+               }
+       }
+
+       untie(%LIB);
+}
+
 1;