Import of revision 19971210+
[mspang/plceo1.git] / database.pl
1 #
2 # Date                  Name                            Modification
3 # ----          ----                ------------
4 # 94/09/12              Alex Brodsky            Split off from main ceo file
5 # 96/10/23              Nikita Borisov          Use DB_File
6 #
7
8
9 use DB_File;
10 use Fcntl;
11
12 sub dbmtie
13 {
14         local($filename,$href) = @_;
15         tie(%$href, DB_File, $filename, O_RDWR, 0640, $DB_HASH) || 
16                 die "Could not open $filename: $!";
17 }
18
19 sub dbmuntie
20 {
21         local($href) = @_;
22
23         untie(%$href) || die;
24 }
25
26 sub open_memdb
27 {
28         local($filename,$mode) = @_;
29
30         if ($member_db_tied) {
31                 untie(%MEMBER_DB);
32         }
33         tie(%MEMBER_DB, DB_File, $filename, $mode, 0640, $DB_HASH) || return 0;
34         $member_db_tied = 1;
35 }
36
37 sub close_memdb
38 {
39         untie(%MEMBER_DB);
40         $member_db_tied = 0;
41 }
42
43 sub get_member
44 {       
45         my($memnum) = $_[0];
46
47         return $MEMBER_DB{$memnum} unless defined $MEMBER_DB{$memnum};
48
49         my(@fields) = split(/;/, $MEMBER_DB{$memnum});
50         my %memrec = (
51                 name => $fields[0],
52                 sid => $fields[1],
53                 program => $fields[2],
54                 phone => $fields[3],
55                 userid => $fields[4],
56                 password => $fields[5],
57                 date => $fields[6],
58                 terms => [ split(/,/, $fields[7]) ]
59         );
60         return %memrec;
61 }
62
63 1;