Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 120 additions & 1 deletion lib/WeBWorK/ContentGenerator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1718,9 +1718,82 @@ sub feedbackMacro_form {
my ($self, $feedbackFormURL, %params) = @_;
my $r = $self->r;
my $ce = $r->ce;
my $db = $r->db;
my $urlpath = $r->urlpath;
my $courseID = $urlpath->arg("courseID");

my $userName = $r->param("user");
my $setName = $params{set};
my $problemNumber = $params{problem};

my ($user, $set, $problem);
$user = $db->getUser($userName) # checked
if defined $userName and $userName ne "";
if (defined $user) {
$set = $db->getMergedSet($userName, $setName) # checked
if defined $setName and $setName ne "";
$problem = $db->getMergedProblem($userName, $setName, $problemNumber) # checked
if defined $set and defined $problemNumber && $problemNumber ne "";
} else {
$set = $db->getGlobalSet($setName) # checked
if defined $setName and $setName ne "";
$problem = $db->getGlobalProblem($setName, $problemNumber) # checked
if defined $set and defined $problemNumber && $problemNumber ne "";
}

my $studentName = $user->full_name if (defined $user);
my $setID = $set->set_id if (defined $set);
my $problemSource = $problem->source_file if (defined $problem);
my $randomSeed = $problem->problem_seed if (defined $problem);

# generate context URLs
my $emailableURL;
my $returnURL;
if ($user) {
my $modulePath;
my @args;
if ($set) {
if ($problem) {
$modulePath = $r->urlpath->newFromModule("WeBWorK::ContentGenerator::Problem", $r,
courseID => $r->urlpath->arg("courseID"),
setID => $set->set_id,
problemID => $problem->problem_id,
);
@args = qw/displayMode showOldAnswers showCorrectAnswers showHints showSolutions/;
} else {
$modulePath = $r->urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSet", $r,
courseID => $r->urlpath->arg("courseID"),
setID => $set->set_id,
);
@args = ();
}
} else {
$modulePath = $r->urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", $r,
courseID => $r->urlpath->arg("courseID"),
);
@args = ();
}
$emailableURL = $self->systemLink($modulePath,
authen => 0,
params => [ "effectiveUser", @args ],
use_abs_url => 1,
);
$returnURL = $self->systemLink($modulePath,
authen => 1,
params => [ @args ],
);
} else {
$emailableURL = "(not available)";
$returnURL = "";
}

# determine the recipients of the email
my @recipients = $self->getFeedbackRecipients($user);

unless (@recipients) {
$self->noRecipientsAvailable($returnURL);
return "";
}

# feedback form url
my $feedbackName = $r->maketext($ce->{feedback_button_name}) || $r->maketext("Email instructor");

Expand All @@ -1737,12 +1810,58 @@ sub feedbackMacro_form {
$result .= CGI::hidden($key, $value) . "\n";
}
}
$result .= CGI::hidden("problemSource", $problemSource) . "\n";
$result .= CGI::hidden("randomSeed", $randomSeed) . "\n";
$result .= CGI::hidden("studentName", $studentName) . "\n";
$result .= CGI::hidden("problemSetID", $setName) . "\n";
$result .= CGI::hidden("courseID", $courseID) . "\n";
$result .= CGI::hidden("emailURL", $emailableURL) . "\n";
$result .= CGI::hidden("returnURL", $returnURL) . "\n";
my $counter = 1;
foreach my $emailAddress (@recipients) {
my ($emailName,$emailAdd) = split($emailAddress,"\<",2);
if ($emailAdd) { $emailAdd =~ s/\>//; } # it is necessary to avoid regex
if ($emailName) { $emailName =~ s/"//; } # throwing out uninitialized warnings
$result .= CGI::hidden("emailName$counter",$emailName) . "\n";
$result .= CGI::hidden("emailAddress$counter",$emailAdd) . "\n";
$counter++;
}
$result .= CGI::p({-align=>"left"}, CGI::submit(-name=>"feedbackForm", -value=>$feedbackName));
$result .= CGI::end_form() . "\n";

return $result;
}

# borrowed from ContentGenerator/Feedback.pm
sub getFeedbackRecipients {
my ($self, $user) = @_;
my $ce = $self->r->ce;
my $db = $self->r->db;
my $authz = $self->r->authz;

my @recipients;

# send to all users with permission to receive_feedback and an email address
# DBFIXME iterator?
foreach my $rcptName ($db->listUsers()) {
if ($authz->hasPermissions($rcptName, "receive_feedback")) {
my $rcpt = $db->getUser($rcptName); # checked
next if $ce->{feedback_by_section} and defined $user
and defined $rcpt->section and defined $user->section
and $rcpt->section ne $user->section;
if ($rcpt and $rcpt->email_address) {
push @recipients, $rcpt->rfc822_mailbox;
}
}
}

if (defined $ce->{mail}->{feedbackRecipients}) {
push @recipients, @{$ce->{mail}->{feedbackRecipients}};
}

return @recipients;
}

sub feedbackMacro_url {
my ($self, $url) = @_;
my $r = $self->r;
Expand Down