#!/usr/sww/bin/perl -w use User::pwent; $whoami = getpwuid($<)->name; ($master) = $whoami =~ /^([^\-]*)/; $ENV{'PATH'} = '/bin:/usr/bin:/usr/ucb:/usr/local/bin'; $ENV{'USER'} = $whoami; $ENV{'HOME'} = getpwnam($whoami)->dir; $ENV{'MASTER'} = $master; $ENV{'MASTERDIR'} = getpwnam($master)->dir; unshift(@INC, "$ENV{'MASTERDIR'}/groups/perl"); require "cgi.pl"; require "groups.pl"; sub LoginAssgn { $login = $input{"login"}; if (!($login =~ /^[a-z]{2}$/)) { CgiError("Invalid login: $COURSE-$login"); } LoadRegistrations(); if (!defined($loginreg{$login})) { CgiError("$COURSE-$login is not registered; run register"); } $assgn = $input{"assgn"}; if (!exists($EVALASSIGNMENTS{$assgn})) { CgiError("Bad assignment $assgn"); } LoadDB($assgn); $group = $logintable{$assgn}{$login}; if (!defined($group)) { CgiError("Unable to determine your group"); } @partners = keys %{$grouptable{$assgn}{$group}}; $numpartners = scalar(@partners); if ($numpartners < 2 || grep(!/^[a-z]{2}$/, @partners)) { CgiError("Invalid information in group table"); } $totalpoints = 20*($numpartners-1); } sub Ratings { my $totalscore = 0; foreach my $i (1 ... $numpartners-1) { my $elogin = $input{"login$i"}; my $escore = $input{"score$i"}; if (!defined($elogin) || !($elogin =~ /^[a-z]{2}$/)) { CgiError("Invalid login $COURSE-$elogin on row $i\n"); } if (!defined($escore) || !($escore =~ /^[0-9]+$/) || $escore < 0 || $escore > $totalpoints) { CgiError("Invalid score $escore on row $i\n"); } if (!grep($_ eq $elogin, @partners)) { CgiError("$COURSE-$elogin is not a member of group $group\n"); } if (grep($_ eq $elogin, keys %evaluations)) { CgiError("$COURSE-$elogin evaluated twice\n"); } $evaluations{$elogin} = $escore; $totalscore += $escore; } if ($totalscore != $totalpoints) { CgiError("Your scores do not add to $totalpoints"); } } CgiMode(); if (!CgiGetArgs()) { CgiStart();#"Group Evaluation Form (Step 1)"); print "
\n"; print "

Enter your login. A confirmation e-mail will be sent to\n"; print "this account.
\n"; print "$COURSE-\n"; print "

Select an assignment
\n"; print "\n"; print "\n"; print "

\n"; print "

\n"; CgiEnd(); } elsif ($input{"step"} == 2) { LoginAssgn(); CgiStart();#"Group Evaluation Form (Step 2)"); print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Login$COURSE-$login
Assignment$assgn
Group$group
Group Size$numpartners members
\n"; print "

\n"; print "

There are $numpartners people in your group, so you have\n"; print "$totalpoints points to distribute among your partners (you\n"; print "do not rate yourself). Do not assign negative or fractional\n"; print "scores; all your scores must be between 0 and $totalpoints,\n"; print "and they must add to $totalpoints. You must evaluate everybody\n"; print "in your group.\n"; print "

Rate your group members here:\n"; foreach my $i (1 ... $numpartners-1) { print "

Partner $i
\n"; print "Login: $COURSE-
\n"; print "Score:
\n"; print "Briefly specify how this person contributed to this project\n"; print "alone (ignore their contributions to other projects):
\n"; print "\n"; } print "

Place any additional comments here.
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "

\n"; CgiEnd(); } elsif ($input{"step"} == 3) { LoginAssgn(); Ratings(); CgiLock($CGI_LOCK_FILE); local (*MAIL), (*FORMS); open(FORMS, ">>$EVALDIR/forms.$assgn") || CgiError("Internal error: unable to append to evaluations log"); print FORMS "eval $assgn $group $login"; foreach my $elogin (sort keys %evaluations) { my $escore = $evaluations{$elogin}; print FORMS " $elogin=$escore"; } print FORMS "\n\n"; foreach my $i (1 ... $numpartners-1) { my $elogin = $input{"login$i"}; my $contrib = $input{"contrib$i"}; print FORMS "contrib $elogin\n$contrib\n\n"; } my $comments = $input{"comments"}; print FORMS "comments\n$comments\n\n"; print FORMS "__ENDEVAL__\n\n"; close(FORMS); CgiUnlock($CGI_LOCK_FILE); open(MAIL, "|$MAIL_PROG -s 'Confirmation' $COURSE-$login") || CgiError("Internal error: unable to mail with $MAIL_PROG"); print MAIL "Your evaluation was successfully submitted.\n"; close(MAIL); CgiStart("Group Evaluation Form"); print "

Your evaluation is complete. A confirmation message has been\n"; print "sent to $COURSE-$login\n"; CgiEnd(); } else { CgiError();#"Unable to determine step"); }