| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor.pm,v 1.41 2004/06/11 14:38:58 toenail Exp $ |
4 | # $CVSHeader$ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 25 | =cut |
25 | =cut |
| 26 | |
26 | |
| 27 | use strict; |
27 | use strict; |
| 28 | use warnings; |
28 | use warnings; |
| 29 | use CGI qw(); |
29 | use CGI qw(); |
|
|
30 | use File::Find; |
| 30 | use WeBWorK::DB::Utils qw(initializeUserProblem); |
31 | use WeBWorK::DB::Utils qw(initializeUserProblem); |
|
|
32 | use WeBWorK::Utils; |
| 31 | |
33 | |
| 32 | =head1 METHODS |
34 | =head1 METHODS |
| 33 | |
35 | |
| 34 | =cut |
36 | =cut |
| 35 | |
37 | |
| … | |
… | |
| 531 | # Takes a delimited file as a parameter and returns an |
533 | # Takes a delimited file as a parameter and returns an |
| 532 | # associative array with the first field as the key. |
534 | # associative array with the first field as the key. |
| 533 | # Blank lines are skipped. White space is removed |
535 | # Blank lines are skipped. White space is removed |
| 534 | my(@dbArray,$key,$dbString); |
536 | my(@dbArray,$key,$dbString); |
| 535 | my %assocArray = (); |
537 | my %assocArray = (); |
| 536 | local(*FILE); |
538 | my $file_string; |
| 537 | if ($fileName eq 'None') { |
539 | if ($fileName eq 'None') { |
| 538 | # do nothing |
540 | # do nothing |
| 539 | } elsif ( open(FILE, "$filePath") ) { |
541 | } elsif ( $file_string = WeBWorK::Utils::readFile($filePath) ) { |
|
|
542 | my @file_lines = split "\n",$file_string; |
| 540 | my $index=0; |
543 | my $index=0; |
| 541 | while (<FILE>){ |
544 | foreach my $line (@file_lines){ |
| 542 | unless ($_ =~ /\S/) {next;} ## skip blank lines |
545 | unless ($line =~ /\S/) {next;} ## skip blank lines |
| 543 | chomp; |
546 | chomp($line); |
| 544 | @{$dbArray[$index]} =$self->getRecord($_,$delimiter); |
547 | @{$dbArray[$index]} =$self->getRecord($line,$delimiter); |
| 545 | $key =$dbArray[$index][0]; |
548 | $key =$dbArray[$index][0]; |
| 546 | $assocArray{$key}=$dbArray[$index]; |
549 | $assocArray{$key}=$dbArray[$index]; |
| 547 | $index++; |
550 | $index++; |
| 548 | } |
551 | } |
| 549 | close(FILE); |
552 | close(FILE); |
| … | |
… | |
| 587 | my $ce = $self->{ce}; |
590 | my $ce = $self->{ce}; |
| 588 | my $dir = $ce->{courseDirs}->{scoring}; |
591 | my $dir = $ce->{courseDirs}->{scoring}; |
| 589 | return $self->read_dir($dir, qr/.*\.csv/); |
592 | return $self->read_dir($dir, qr/.*\.csv/); |
| 590 | } |
593 | } |
| 591 | |
594 | |
|
|
595 | sub getTemplateFileList { # find all .pg files under the template tree (time consuming) |
|
|
596 | my ($self) = shift; |
|
|
597 | my $subDir = shift; |
|
|
598 | my $ce = $self->{ce}; |
|
|
599 | $subDir = '' unless defined $subDir; |
|
|
600 | my $dir = $ce->{courseDirs}->{templates}."/$subDir"; |
|
|
601 | # FIXME currently allows one to see most files in the templates directory. |
|
|
602 | # a better facility for handling auxiliary files would be nice. |
|
|
603 | return $self->read_dir($dir, qr/\.pg$|.*\.html|\.png|\.gif|\.txt|\.pl/); |
|
|
604 | } |
|
|
605 | sub getTemplateDirList { # find all .pg files under the template tree (time consuming) |
|
|
606 | my ($self) = @_; |
|
|
607 | my $ce = $self->{ce}; |
|
|
608 | my $dir = $ce->{courseDirs}->{templates}; |
|
|
609 | my @list = (); |
|
|
610 | my $wanted = sub { if (-d $_ ) { |
|
|
611 | my $current = $_; |
|
|
612 | return if $current =~/CVS/; |
|
|
613 | return if -l $current; # don't list links |
|
|
614 | my $name = $File::Find::name; |
|
|
615 | $name = " Top" if $current =/^\./; # top directory |
|
|
616 | $name =~ s/^$dir\///; |
|
|
617 | push @list, $name |
|
|
618 | } |
|
|
619 | }; |
|
|
620 | File::Find::find($wanted, $dir); |
|
|
621 | return sort @list; |
|
|
622 | } |
|
|
623 | |
| 592 | =back |
624 | =back |
| 593 | |
625 | |
| 594 | =cut |
626 | =cut |
| 595 | |
627 | |
| 596 | 1; |
628 | 1; |