| … | |
… | |
| 33 | use WeBWorK::PG::IO; |
33 | use WeBWorK::PG::IO; |
| 34 | use WeBWorK::Utils qw(writeLog writeCourseLog encodeAnswers decodeAnswers ref2string makeTempDirectory); |
34 | use WeBWorK::Utils qw(writeLog writeCourseLog encodeAnswers decodeAnswers ref2string makeTempDirectory); |
| 35 | use WeBWorK::DB::Utils qw(global2user user2global findDefaults); |
35 | use WeBWorK::DB::Utils qw(global2user user2global findDefaults); |
| 36 | use WeBWorK::Timing; |
36 | use WeBWorK::Timing; |
| 37 | |
37 | |
|
|
38 | use WeBWorK::Utils::Tasks qw(fake_set fake_problem); |
| 38 | |
39 | |
| 39 | ############################################################ |
40 | ############################################################ |
| 40 | # |
41 | # |
| 41 | # user |
42 | # user |
| 42 | # effectiveUser |
43 | # effectiveUser |
| … | |
… | |
| 96 | # obtain the merged problem for $effectiveUser |
97 | # obtain the merged problem for $effectiveUser |
| 97 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
98 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
| 98 | |
99 | |
| 99 | my $editMode = $r->param("editMode"); |
100 | my $editMode = $r->param("editMode"); |
| 100 | |
101 | |
| 101 | if ($permissionLevel > 0 and defined $editMode) { |
102 | if ($permissionLevel > 0) { |
| 102 | # professors are allowed to fabricate sets and problems not |
103 | # professors are allowed to fabricate sets and problems not |
| 103 | # assigned to them (or anyone). this allows them to use the |
104 | # assigned to them (or anyone). this allows them to use the |
| 104 | # editor to |
105 | # editor to |
| 105 | |
106 | |
| 106 | # if that is not yet defined obtain the global set, convert |
107 | # if that is not yet defined obtain the global set, convert |
| 107 | # it to a user set, and add fake user data |
108 | # it to a user set, and add fake user data |
| 108 | unless (defined $set) { |
109 | unless (defined $set) { |
| 109 | my $userSetClass = $db->{set_user}->{record}; |
110 | my $userSetClass = $db->{set_user}->{record}; |
| 110 | my $globalSet = $db->getGlobalSet($setName); # checked |
111 | my $globalSet = $db->getGlobalSet($setName); # checked |
| 111 | # if the global set doesn't exist either, bail! |
112 | # if the global set doesn't exist either, bail! |
| 112 | die "Set $setName does not exist" |
113 | if(not defined $globalSet) { |
| 113 | unless defined $set; |
114 | $set = fake_set($db); |
|
|
115 | } else { |
| 114 | $set = global2user($userSetClass, $globalSet); |
116 | $set = global2user($userSetClass, $globalSet); |
| 115 | $set->psvn(0); |
117 | $set->psvn(0); |
|
|
118 | } |
| 116 | } |
119 | } |
| 117 | |
120 | |
| 118 | # if that is not yet defined obtain the global problem, |
121 | # if that is not yet defined obtain the global problem, |
| 119 | # convert it to a user problem, and add fake user data |
122 | # convert it to a user problem, and add fake user data |
| 120 | unless (defined $problem) { |
123 | unless (defined $problem) { |
| 121 | my $userProblemClass = $db->{problem_user}->{record}; |
124 | my $userProblemClass = $db->{problem_user}->{record}; |
| 122 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
125 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
| 123 | # if the global problem doesn't exist either, bail! |
126 | # if the global problem doesn't exist either, bail! |
|
|
127 | if(not defined $globalProblem) { |
|
|
128 | my $sourceFilePath = $r->param("sourceFilePath"); |
| 124 | die "Problem $problemNumber in set $setName does not exist" |
129 | die "Problem $problemNumber in set $setName does not exist" |
| 125 | unless defined $problem; |
130 | unless defined $sourceFilePath; |
|
|
131 | $problem = fake_problem($db); |
|
|
132 | $problem->problem_id(1); |
|
|
133 | $problem->source_file($sourceFilePath); |
|
|
134 | $problem->user_id($effectiveUserName); |
|
|
135 | } else { |
| 126 | $problem = global2user($userProblemClass, $globalProblem); |
136 | $problem = global2user($userProblemClass, $globalProblem); |
| 127 | $problem->user_id($effectiveUserName); |
137 | $problem->user_id($effectiveUserName); |
| 128 | $problem->problem_seed(0); |
138 | $problem->problem_seed(0); |
| 129 | $problem->status(0); |
139 | $problem->status(0); |
| 130 | $problem->attempted(0); |
140 | $problem->attempted(0); |
| 131 | $problem->last_answer(""); |
141 | $problem->last_answer(""); |
| 132 | $problem->num_correct(0); |
142 | $problem->num_correct(0); |
| 133 | $problem->num_incorrect(0); |
143 | $problem->num_incorrect(0); |
|
|
144 | } |
| 134 | } |
145 | } |
| 135 | |
146 | |
| 136 | # now we're sure we have valid UserSet and UserProblem objects |
147 | # now we're sure we have valid UserSet and UserProblem objects |
| 137 | # yay! |
148 | # yay! |
| 138 | |
149 | |
| 139 | # now deal with possible editor overrides: |
150 | # now deal with possible editor overrides: |
| 140 | |
151 | |
| 141 | # if the caller is asking to override the source file, and |
152 | # if the caller is asking to override the source file, and |
| 142 | # editMode calls for a temporary file, do so |
153 | # editMode calls for a temporary file, do so |
| 143 | my $sourceFilePath = $r->param("sourceFilePath"); |
154 | my $sourceFilePath = $r->param("sourceFilePath"); |
| 144 | if (defined $sourceFilePath and $editMode eq "temporaryFile") { |
155 | if (defined $sourceFilePath and |
|
|
156 | (not defined $editMode or $editMode eq "temporaryFile")) { |
| 145 | $problem->source_file($sourceFilePath); |
157 | $problem->source_file($sourceFilePath); |
| 146 | } |
158 | } |
| 147 | |
159 | |
| 148 | # if the caller is asking to override the problem seed, do so |
160 | # if the caller is asking to override the problem seed, do so |
| 149 | my $problemSeed = $r->param("problemSeed"); |
161 | my $problemSeed = $r->param("problemSeed"); |
| … | |
… | |
| 421 | and (not defined $prevID or $id > $prevID); |
433 | and (not defined $prevID or $id > $prevID); |
| 422 | $nextID = $id if $id > $problemID |
434 | $nextID = $id if $id > $problemID |
| 423 | and (not defined $nextID or $id < $nextID); |
435 | and (not defined $nextID or $id < $nextID); |
| 424 | } |
436 | } |
| 425 | } |
437 | } |
| 426 | |
438 | |
| 427 | my @links; |
439 | my @links; |
| 428 | |
440 | |
| 429 | if ($prevID) { |
441 | if ($prevID) { |
| 430 | my $prevPage = $urlpath->newFromModule(__PACKAGE__, |
442 | my $prevPage = $urlpath->newFromModule(__PACKAGE__, |
| 431 | courseID => $courseID, setID => $setID, problemID => $prevID); |
443 | courseID => $courseID, setID => $setID, problemID => $prevID); |
| 432 | push @links, "Previous Problem", $r->location . $prevPage->path, "navPrev"; |
444 | push @links, "Previous Problem", $r->location . $prevPage->path, "navPrev"; |
| 433 | } else { |
445 | } else { |
| 434 | push @links, "Previous Problem", "", "navPrev"; |
446 | push @links, "Previous Problem", "", "navPrev"; |
| 435 | } |
447 | } |
| 436 | |
448 | |
| 437 | push @links, "Problem List", $r->location . $urlpath->parent->path, "navProbList"; |
449 | push @links, "Problem List", $r->location . $urlpath->parent->path, "navProbList"; |
| 438 | |
450 | |
| 439 | if ($nextID) { |
451 | if ($nextID) { |
| 440 | my $nextPage = $urlpath->newFromModule(__PACKAGE__, |
452 | my $nextPage = $urlpath->newFromModule(__PACKAGE__, |
| 441 | courseID => $courseID, setID => $setID, problemID => $nextID); |
453 | courseID => $courseID, setID => $setID, problemID => $nextID); |
| 442 | push @links, "Next Problem", $r->location . $nextPage->path, "navNext"; |
454 | push @links, "Next Problem", $r->location . $nextPage->path, "navNext"; |
| 443 | } else { |
455 | } else { |
| 444 | push @links, "Next Problem", "", "navNext"; |
456 | push @links, "Next Problem", "", "navNext"; |
| 445 | } |
457 | } |
| 446 | |
458 | |
| 447 | my $tail = "&displayMode=".$self->{displayMode}; |
459 | my $tail = "&displayMode=".$self->{displayMode}; |
| 448 | return $self->navMacro($args, $tail, @links); |
460 | return $self->navMacro($args, $tail, @links); |
| 449 | } |
461 | } |
| 450 | |
462 | |
| 451 | sub title { |
463 | sub title { |
| … | |
… | |
| 507 | # $editorLinkMessage = CGI::a({-href=>$ce->{webworkURLs}->{root}."/$courseName/instructor/pgProblemEditor/". |
519 | # $editorLinkMessage = CGI::a({-href=>$ce->{webworkURLs}->{root}."/$courseName/instructor/pgProblemEditor/". |
| 508 | # $set->set_id.'/'.$problem->problem_id.'?'.$self->url_authen_args},'Edit this problem'); |
520 | # $set->set_id.'/'.$problem->problem_id.'?'.$self->url_authen_args},'Edit this problem'); |
| 509 | #} |
521 | #} |
| 510 | |
522 | |
| 511 | my $editorLink = ""; |
523 | my $editorLink = ""; |
|
|
524 | # if we are here without a real problem set, carry that through |
|
|
525 | my $forced_field = []; |
|
|
526 | $forced_field = ['sourceFilePath' => $r->param("sourceFilePath")] if |
|
|
527 | ($set->set_id eq 'Undefined_Set'); |
| 512 | if ($self->{permissionLevel}>=10) { |
528 | if ($self->{permissionLevel}>=10) { |
| 513 | my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", |
529 | my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", |
| 514 | courseID => $courseName, setID => $set->set_id, problemID => $problem->problem_id); |
530 | courseID => $courseName, setID => $set->set_id, problemID => $problem->problem_id); |
| 515 | my $editorURL = $self->systemLink($editorPage); |
531 | my $editorURL = $self->systemLink($editorPage, params=>$forced_field); |
| 516 | $editorLink = CGI::a({href=>$editorURL}, "Edit this problem"); |
532 | $editorLink = CGI::a({href=>$editorURL}, "Edit this problem"); |
| 517 | } |
533 | } |
| 518 | |
534 | |
| 519 | ##### translation errors? ##### |
535 | ##### translation errors? ##### |
| 520 | |
536 | |