Import of revision 19971210+
[mspang/plceo1.git] / Gopher.pl
1 #
2 # Date                  Name                            Modification
3 # ----          ----                ------------
4 # 94/11/20              Alex Brodsky            Split off from main ceo file
5 # 96/10/23              Nikita Borisov          Use dbmtie instead of fakedbm
6 # 96/10/24              Nikita Borisov          Use tie instead of dbmopen for $LIBDB
7 #
8
9
10 use NDBM_File;
11 use Fcntl;
12
13 sub Gopher_Quota
14 {
15     local($useQUOTALOG) = $QUOTALOG;
16     if ($NEXTTERMQUOTA)
17     {
18         $useQUOTALOG = $NEXTQUOTALOG;
19     }
20     open (QLOG, $useQUOTALOG) || do
21     {
22         print "\n${beep}Unable to open quota log file: $!\n";
23         return;
24     };
25     dbmopen(QUOTA,$QUOTADB,0600) || do
26     {
27         print "\n${beep}Unable to open quota database: $!\n";
28         close(QLOG);
29         return;
30     };
31     %Quota = ();
32     while(<QLOG>)
33     {
34         next if (/^\s*$/ || /^\s*#/);
35         ($qdate, $quid, $qamt, $qtot, $qleft) = split(/;/);
36         next if $quid eq "csc\@math";
37         $Quota{$QUOTA{$quid}} = $qtot;
38     }
39     close(QLOG);
40     $qleft =~ s/\D//g;
41     open (GOPQUOTA, ">$GOPHERDIR/quota_log") || do
42     {
43         print "\n${beep}Unable to open output file: $!\n";
44         return;
45     };
46     select(GOPQUOTA);
47     $-=0;
48     $= = 50000;
49     foreach $qnum (sort {$a<=>$b} keys %Quota)
50     {
51         ($qname, $qsid, $quid) = split(/;/,$QUOTA{$qnum});
52         $qqta = $Quota{$qnum};
53         write;
54     }
55     dbmclose(QUOTA);
56     print "\nQuota remaining: $qleft MB\n";
57     select(STDOUT);
58     close(GOPQUOTA);
59 #   system <<EOJ;
60 #rcp $editfile csc_disk@descartes:Gopher/office_info/quota_log
61 #EOJ
62 }
63
64 sub Gopher_Members
65 {
66     local($nummems);
67     open (GOPMEMBER, ">$GOPHERDIR/members_list") || do
68     {
69         print "\n${beep}Unable to open output file: $!\n";
70         return;
71     };
72     eval { dbmtie($MEMDB,\%MEM) } || do
73     {
74         print "\n${beep}Unable to open member database: $!\n";
75         close(SCRMEMBER);
76         return;
77     };
78     select(GOPMEMBER);
79     $-=0;
80     $= = 50000;
81     $nummems=0;
82     foreach $memnum (sort {$a<=>$b} split(/,/,$MEM{$TERM}))
83     {
84         ($memname,$memsid,$memprog,$memphone,$memuid,$mempw,$memdate,$memterms)
85             = split(/;/,$MEM{$memnum});
86         write;
87         ++$nummems;
88     }
89     dbmuntie(\%MEM);
90     print "\nTotal: $nummems\n";
91     select(STDOUT);
92     close(GOPMEMBER);
93 #   system <<EOJ;
94 #rcp $editfile csc_disk@descartes:Gopher/office_info/members_list
95 #EOJ
96 }
97
98 sub Gopher_Outstanding
99 {
100  ## Read the library file
101     tie(%LIB, NDBM_File, $LIBDB, O_RDONLY, 0600) || do
102     {
103         print "\n${beep}Error opening library database: $!\n";
104         return;
105     };
106     %Outstand = ();
107     foreach $bid (keys %LIB)
108     {
109         ($whohas) = $LIB{$bid} =~ /W\{(\d+)\}/;
110         next if $whohas == 0;
111         ($btitle) = $LIB{$bid} =~ /N\{([^\}]*)\}/;
112         ($bodate) = $LIB{$bid} =~ /D\{([^\}]*)\}/;
113         $Outstand{$bid}="$whohas#$btitle#$bodate";
114     }
115     untie(%LIB);
116
117     eval { dbmtie($MEMDB,\%MEM) } || do
118     {
119         print "\n${beep}Error opening members database: $!\n";
120         return;
121     };
122     open (OUTSTAND, ">$GOPHERDIR/library_outstand") || do
123     {
124         print "\n${beep}Unable to open outstanding books file: $!\n";
125         dbmuntie(\%MEM);
126         return;
127     };
128     select(OUTSTAND);
129     $-=0;
130     $= = 50000;
131     foreach $obid (keys %Outstand)
132     {
133         ($onum,$obtitle,$odate) = $Outstand{$obid} =~ /^(.*)#(.*)#(.*)$/;
134         $oname = (split(/;/,$MEM{$onum}))[0];
135         write;
136     }
137     dbmuntie(\%MEM);
138     select(STDOUT);
139     close(OUTSTAND);
140 #   &MakeOutstandFile(50000);
141 #   system <<EOJ;
142 #rcp $editfile csc_disk@descartes:Gopher/office_info/library_outstand
143 #EOJ
144 }
145
146 1;