#!/usr/bin/perl


use lib '/ww/webwork/development/'; # mainWeBWorKDirectory;

use Global;
use Auth;
use strict;

if (@ARGV != 2)
  {
   print "\nSyntax is export_password-database.pl courseID outputTextFile\n";
   print "      (e.g. export_password-database.pl  demoCourse textDatabase)\n\n";
   exit(0);
  }

my $course = $ARGV[0];
my $outFileName = $ARGV[1];

# establish environment for this script

&Global::getCourseEnvironment($course);

# File names

my $pw_file = &Global::getCoursePasswordFile($course);

my %pw_hash;
my $pw_obj;

&Global::tie_hash('PW_FILE',\$pw_obj,\%pw_hash, $pw_file,'R',$Global::standard_tie_pwission);
 
my ($key,$item);
my @keys = sort keys %pw_hash;

open(OUTFILE,">$outFileName") or wwerror("$0","can't open $outFileName for writing");

foreach $key (@keys) {
    print OUTFILE "[$key]\n";
    print OUTFILE "\t$pw_hash{$key}\n";
}

close(OUTFILE);
&Global::untie_hash('PW_FILE',\$pw_obj,\%pw_hash, $pw_file);