#!/usr/local/bin/perl ## $Id$ #################################################################### # Copyright @ 1995-1998 University of Rochester # All Rights Reserved #################################################################### ############################################################################### ############ PRELIMINARY SETUP ####################### ############################################################################### use lib '/ww/webwork/gage_system/webwork/system/lib/'; # mainWeBWorKDirectory use Global; use CGI qw(:standard); use Auth; use TimeLocal; # the module Time::Local.pm has a bug which interacts # with DProf. (They call a subroutine assuming @_ doesn't change. use strict; # begin Timing code use Benchmark; my $beginTime = new Benchmark; # end Timing code &CGI::ReadParse(*main::inputs); my %inputs=%main::inputs; # get primary data from CGI form my $User = $inputs{'user'}; my $Course = $inputs{'course'}; my $Key = $inputs{'key'}; my $psvn = $inputs{'probSetKey'}; # set course environment &Global::getCourseEnvironment($Course); my $scriptDirectory = getWebworkScriptDirectory($Course); my $databaseDirectory = getCourseDatabaseDirectory($Course); my $cgiURL = getWebworkCgiURL($Course); my $htmlURL = getCourseHtmlURL($Course); my $logsDirectory = getCourseLogsDirectory($Course); require "${scriptDirectory}$Global::DBglue_pl"; require "${scriptDirectory}$Global::classlist_DBglue_pl"; require "${scriptDirectory}$Global::FILE_pl"; require "${scriptDirectory}HTMLglue.pl"; my $keyFile = getCourseKeyFile($Course); &verify_key($inputs{'user'}, $inputs{'key'}, "$keyFile", $inputs{'course'}); my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'}); my $permissions = &get_permissions($inputs{'user'}, $permissionsFile); if ($permissions != $Global::instructor_permissions ) { print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n"; print &html_NO_PERMISSION; exit(0); } # get additional data from calling CGI form my ( $Mode, $studentLogin, $setNumber); $Mode = "HTML"; #default viewing mode $Mode = $inputs{'Mode'} if defined($inputs{'Mode'}); $studentLogin = $inputs{'studentLogin'}; $setNumber = $inputs{'setNo'}; # if the psvn is not given we need to derive it from the set number and # the student login ID if (!defined($psvn) ) { unless ( defined($studentLogin) && defined($setNumber) ) { Global::error("DataMunger: Need psvn, or studentLogin and setNumber"); } my %loginList = &getAllSetNumbersForStudentLoginHash($studentLogin); $psvn =$loginList{$setNumber}; } # define data to be displayed in the form # the data for this will be loaded by the subroutine load # my (@row1, @row2, @row3, @row4); # my ($StudentLastName, $StudentFirstName, $StudentID); # @row1 = qw(StudentLastName StudentFirstName StudentID); # # my ($StudentStatus, $StudentGrade, $SetNumber); # @row2 = qw(StudentStatus StudentGrade SetNumber); # # my ($OpenDate, $DueDate, $AnswerDate ); # @row3 = qw(OpenDate DueDate AnswerDate ); # # my ($StudentLogin, $ClassSection ); # @row4 = qw(StudentLogin ClassSection ); # my ($SetHeaderFileName, $ProbHeaderFileName ); # @row5 = qw(SetHeaderFileName, ProbHeaderFileName ); ############################################################################### ############ MODIFY SET DATA IN THE DATABASE ####################### ############################################################################### # First make sure that the psvn is properly defined # then save the information from the CGI form to the database # Whether or not information is saved, at the end of this block # the most current information has been placed in %probSetRecord # using &fetchProbSetRecord. if (not &fetchProbSetRecord($psvn)) { Global::error("in dataMunger.pl:","Can't find record with psvn = $psvn in the database"); } $studentLogin = getStudentLogin($psvn); attachCLRecord($studentLogin); if (defined( $inputs{'save'} ) && $inputs{'save'} eq "ON" ) { # in this case we obtain the data from the CGI from and store it in the database # update the database from the CGI script: &updateDatabase($psvn); # loads the information into %probSetRecord, # modifies the data and saves it back to the database # This effectively executes fetchProbSetRecord # so that the contents of %probSetRecord is now current #log the changes: -- the format for loggin the changes needs improvement &logChanges( &getProbSetRecord() ); &print_modification_form; } elsif (defined($inputs{'save'}) && $inputs{'save'} eq "OFF" ){ # No new information in the calling CGI form # and the information has already been loaded into %probSetRecord using &fetchProbSetRecord($psvn); # Nothing needs to be done in this case except print the form &print_modification_form; } elsif ( defined($inputs{'deleteMode'}) && $inputs{'deleteMode'} eq 'delete') { # In this case the problem is deleted my $psvnSetNumber = getSetNumber($psvn); &deleteProbSetRecord($psvn); # remove .sco file if it exists system ("rm ${databaseDirectory}S${psvnSetNumber}-${psvn}.sco") if (-e "${databaseDirectory}S${psvnSetNumber}-${psvn}.sco"); # remove any l2h files my $l2hDir = getCoursel2hDirectory(); my $tempDir = convertPath("${l2hDir}set${psvnSetNumber}/*-$psvn"); system ("rm -rf $tempDir"); &record_successfully_deleted_message; #reload empty record } else { # The calling CGI script must define the 'save' variable or the 'deleteMode' variable Global::error( "
in dataMunger.pl:
", "No value for 'save' mode in the calling CGI form.
");
}
# begin Timing code
my $endTime = new Benchmark;
&Global::logTimingInfo($beginTime,$endTime,"dataMunger.pl",$Course,$User);
# end Timing code
exit;
#### END of main program
###############################################################################
############################ SUBROUTINES ############################
###############################################################################
###############################################################################
########################## PRINT FORM ##############################
###############################################################################
sub print_modification_form {
print &htmlTOP("data for the problem set version number $psvn");
print <
Class Identification: $inputs{'course'}
Data for problem set version number: $psvn