
# This is a file containing various global definitions for the picture database.
#noexec

# import permissions if necessary
use AnyDBM_File;
use POSIX(O_CREAT,O_RDWR,O_RDONLY);

$DBPATH='/home/scsfac/downeyt/scripts/';
$PASSWORD="$DBPATH/password.dbm";

#----------- open the databases -----------
sub open_databases {
    my($writable) = @_;
    my($permissions) = $writable ? O_CREAT|O_RDWR : O_RDONLY;
    tie(%Passwords,AnyDBM_File,$PASSWORD,$permissions,0644) 
	|| die "tie: $!\n";
    1;
}

#----------- reset the databases -----------
sub reset_databases {
    foreach (keys %Passwords) {
	delete $Passwords{$_};
    }
}

#------ add a picture file to the database -------
sub index {
    local($username,$password,$interest)=@_;
    local(%parms);

    undef %parms;
    $parms{'interest'} = $interest;
    $parms{'password'} = $password;
    $Passwords{$username} = join($;, %parms);
}

#---- lookup_field ----
sub lookup_field {
    my($username,$field) = @_;
    my(%parms);

    # Get the list of filenames that contain this keyword
    %parms = split($;,$Passwords{$username});
    return $parms{$field};
}

sub in_file {
    my($username) = @_;
    my(%parms);

    # Get the list of filenames that contain this keyword
    %parms = split($;,$Passwords{$username});

    if (scalar %parms)
    {
	return 1;
    } else {
	return 0;
    }
}

sub change_field {
    my($username,$field,$value) = @_;
    my(%parms);

    # Get the list of filenames that contain this keyword
    %parms = split($;,$Passwords{$username});
    $parms{$field}=$value;
    $Passwords{$username}=join ($;,%parms);
}    

1;






