| 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/SetMaker.pm,v 1.11 2004/05/15 19:13:43 jj Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.13 2004/05/22 00:38:44 sh002i Exp $ |
| 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. |
| … | |
… | |
| 33 | use WeBWorK::Utils::Tasks qw(renderProblems); |
33 | use WeBWorK::Utils::Tasks qw(renderProblems); |
| 34 | |
34 | |
| 35 | require WeBWorK::Utils::ListingDB; |
35 | require WeBWorK::Utils::ListingDB; |
| 36 | |
36 | |
| 37 | use constant MAX_SHOW => 20; |
37 | use constant MAX_SHOW => 20; |
|
|
38 | use constant NO_LOCAL_SET_STRING => 'There are no local sets yet'; |
|
|
39 | use constant SELECT_SET_STRING => 'Select a Set for This Course'; |
|
|
40 | use constant SELECT_LOCAL_STRING => 'Select a Local Problem Collection'; |
| 38 | |
41 | |
| 39 | ## Flags for operations on files |
42 | ## Flags for operations on files |
| 40 | |
43 | |
| 41 | use constant ADDED => 1; |
44 | use constant ADDED => 1; |
| 42 | use constant HIDDEN => (1 << 1); |
45 | use constant HIDDEN => (1 << 1); |
| 43 | use constant SUCCESS => (1 << 2); |
46 | use constant SUCCESS => (1 << 2); |
| 44 | |
|
|
| 45 | ## Maybe this should be in ContentGenerator.pm |
|
|
| 46 | |
|
|
| 47 | sub adderrmsg { |
|
|
| 48 | my $self = shift; |
|
|
| 49 | my $msg = shift; |
|
|
| 50 | $self->addmessage(CGI::div({class=>"ResultsWithError"}, $msg)); |
|
|
| 51 | } |
|
|
| 52 | |
|
|
| 53 | |
47 | |
| 54 | ## This is for searching the disk for directories containing pg files. |
48 | ## This is for searching the disk for directories containing pg files. |
| 55 | ## to make the recursion work, this returns an array where the first |
49 | ## to make the recursion work, this returns an array where the first |
| 56 | ## item is 1 or 0 depending on whether or not the current |
50 | ## item is 1 or 0 depending on whether or not the current |
| 57 | ## directory has any pg files. The second is a list of directories |
51 | ## directory has any pg files. The second is a list of directories |
| … | |
… | |
| 166 | my $list_of_prob_dirs= get_problem_directories($self->r->ce); |
160 | my $list_of_prob_dirs= get_problem_directories($self->r->ce); |
| 167 | if(scalar(@$list_of_prob_dirs) == 0) { |
161 | if(scalar(@$list_of_prob_dirs) == 0) { |
| 168 | $library_selected = "Found no directories containing problems"; |
162 | $library_selected = "Found no directories containing problems"; |
| 169 | unshift @{$list_of_prob_dirs}, $library_selected; |
163 | unshift @{$list_of_prob_dirs}, $library_selected; |
| 170 | } else { |
164 | } else { |
| 171 | my $default_value = "Select a Local Problem Collection"; |
165 | my $default_value = SELECT_LOCAL_STRING; |
| 172 | if (not $library_selected or $library_selected eq $default_value) { |
166 | if (not $library_selected or $library_selected eq $default_value) { |
| 173 | unshift @{$list_of_prob_dirs}, $default_value; |
167 | unshift @{$list_of_prob_dirs}, $default_value; |
| 174 | $library_selected = $default_value; |
168 | $library_selected = $default_value; |
| 175 | } |
169 | } |
| 176 | } |
170 | } |
| … | |
… | |
| 190 | my $library_selected = shift; |
184 | my $library_selected = shift; |
| 191 | my $list_of_local_sets = shift; |
185 | my $list_of_local_sets = shift; |
| 192 | my $default_value = "Select a Problem Set"; |
186 | my $default_value = "Select a Problem Set"; |
| 193 | |
187 | |
| 194 | if(scalar(@$list_of_local_sets) == 0) { |
188 | if(scalar(@$list_of_local_sets) == 0) { |
| 195 | $list_of_local_sets = ['There are no local sets yet']; |
189 | $list_of_local_sets = [NO_LOCAL_SET_STRING]; |
| 196 | } elsif (not $library_selected or $library_selected eq $default_value) { |
190 | } elsif (not $library_selected or $library_selected eq $default_value) { |
| 197 | unshift @{$list_of_local_sets}, $default_value; |
191 | unshift @{$list_of_local_sets}, $default_value; |
| 198 | $library_selected = $default_value; |
192 | $library_selected = $default_value; |
| 199 | } |
193 | } |
| 200 | |
194 | |
| … | |
… | |
| 234 | for the Problem Library to function. It should be a link pointing to |
228 | for the Problem Library to function. It should be a link pointing to |
| 235 | <code>$libraryRoot</code>, which you set in <code>conf/global.conf</code>. |
229 | <code>$libraryRoot</code>, which you set in <code>conf/global.conf</code>. |
| 236 | I tried to make the link for you, but that failed. Check the permissions |
230 | I tried to make the link for you, but that failed. Check the permissions |
| 237 | in your <code>templates</code> directory. |
231 | in your <code>templates</code> directory. |
| 238 | HERE |
232 | HERE |
| 239 | $self->adderrmsg($msg); |
233 | $self->addbadmessage($msg); |
| 240 | } |
234 | } |
| 241 | } |
235 | } |
| 242 | |
236 | |
| 243 | my $default_chap = "All Chapters"; |
237 | my $default_chap = "All Chapters"; |
| 244 | my $default_sect = "All Sections"; |
238 | my $default_sect = "All Sections"; |
| … | |
… | |
| 327 | } |
321 | } |
| 328 | |
322 | |
| 329 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
323 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
| 330 | |
324 | |
| 331 | if($have_local_sets ==0) { |
325 | if($have_local_sets ==0) { |
| 332 | $list_of_local_sets = ['There are no local sets yet']; |
326 | $list_of_local_sets = [NO_LOCAL_SET_STRING]; |
| 333 | } elsif (not $set_selected or $set_selected eq "Select a Set for This Course") { |
327 | } elsif (not $set_selected or $set_selected eq SELECT_SET_STRING) { |
| 334 | if ($list_of_local_sets->[0] eq "Select a Problem Set") { |
328 | if ($list_of_local_sets->[0] eq "Select a Problem Set") { |
| 335 | shift @{$list_of_local_sets}; |
329 | shift @{$list_of_local_sets}; |
| 336 | } |
330 | } |
| 337 | unshift @{$list_of_local_sets}, "Select a Set for This Course"; |
331 | unshift @{$list_of_local_sets}, SELECT_SET_STRING; |
| 338 | $set_selected = "Select a Set for This Course"; |
332 | $set_selected = SELECT_SET_STRING; |
| 339 | } |
333 | } |
| 340 | |
334 | |
| 341 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Current Set: ", |
335 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Adding Problems to ", |
|
|
336 | CGI::b("Current Set: "), |
| 342 | CGI::popup_menu(-name=> 'local_sets', |
337 | CGI::popup_menu(-name=> 'local_sets', |
| 343 | -values=>$list_of_local_sets, |
338 | -values=>$list_of_local_sets, |
| 344 | -default=> $set_selected), |
339 | -default=> $set_selected), |
| 345 | CGI::submit(-name=>"edit_local", -value=>"Edit Current Set"), |
340 | CGI::submit(-name=>"edit_local", -value=>"Edit Current Set"), |
| 346 | CGI::br(), |
341 | CGI::br(), |
| 347 | CGI::br(), |
342 | CGI::br(), |
| 348 | CGI::submit(-name=>"new_local_set", -value=>"Create New Local Set:"), |
343 | CGI::submit(-name=>"new_local_set", -value=>"Create a New Set in This Course:"), |
| 349 | " ", |
344 | " ", |
| 350 | CGI::textfield(-name=>"new_set_name", |
345 | CGI::textfield(-name=>"new_set_name", |
| 351 | -default=>"Name for new set here", |
346 | -default=>"Name for new set here", |
| 352 | -override=>1, -size=>30), |
347 | -override=>1, -size=>30), |
| 353 | CGI::br(), |
348 | CGI::br(), |
| … | |
… | |
| 444 | my $urlpath = $r->urlpath; |
439 | my $urlpath = $r->urlpath; |
| 445 | my $db = $r->db; |
440 | my $db = $r->db; |
| 446 | my $checkset = $db->getGlobalSet($r->param('local_sets')); |
441 | my $checkset = $db->getGlobalSet($r->param('local_sets')); |
| 447 | if (not defined($checkset)) { |
442 | if (not defined($checkset)) { |
| 448 | $self->{error} = 1; |
443 | $self->{error} = 1; |
| 449 | $self->adderrmsg('You need to select a "Current Set" before you can edit it.'); |
444 | $self->addbadmessage('You need to select a "Current Set" before you can edit it.'); |
| 450 | } else { |
445 | } else { |
| 451 | my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetEditor', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID")); |
446 | my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetEditor', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID")); |
| 452 | my $url = $self->systemLink($page); |
447 | my $url = $self->systemLink($page); |
| 453 | $self->reply_with_redirect($url); |
448 | $self->reply_with_redirect($url); |
| 454 | } |
449 | } |
| … | |
… | |
| 497 | ##### Change the seed value |
492 | ##### Change the seed value |
| 498 | |
493 | |
| 499 | } elsif ($r->param('rerandomize')) { |
494 | } elsif ($r->param('rerandomize')) { |
| 500 | $problem_seed++; |
495 | $problem_seed++; |
| 501 | $r->param('problem_seed', $problem_seed); |
496 | $r->param('problem_seed', $problem_seed); |
| 502 | $self->adderrmsg('Changing the problem seed for display, but there are no problems showing.') if $none_shown; |
497 | $self->addbadmessage('Changing the problem seed for display, but there are no problems showing.') if $none_shown; |
| 503 | |
498 | |
| 504 | ##### Clear the display |
499 | ##### Clear the display |
| 505 | |
500 | |
| 506 | } elsif ($r->param('cleardisplay')) { |
501 | } elsif ($r->param('cleardisplay')) { |
| 507 | @pg_files = (); |
502 | @pg_files = (); |
| 508 | $use_previous_problems=0; |
503 | $use_previous_problems=0; |
| 509 | $self->adderrmsg('The display was already cleared.') if $none_shown; |
504 | $self->addbadmessage('The display was already cleared.') if $none_shown; |
| 510 | |
505 | |
| 511 | ##### View problems selected from the local list |
506 | ##### View problems selected from the local list |
| 512 | |
507 | |
| 513 | } elsif ($r->param('view_local_set')) { |
508 | } elsif ($r->param('view_local_set')) { |
| 514 | |
509 | |
| 515 | my $set_to_display = $r->param('library_sets'); |
510 | my $set_to_display = $r->param('library_sets'); |
| 516 | if (not defined($set_to_display) or $set_to_display eq "Select a Local Problem Collection" or $set_to_display eq "Found no directories containing problems") { |
511 | if (not defined($set_to_display) or $set_to_display eq SELECT_LOCAL_STRING or $set_to_display eq "Found no directories containing problems") { |
| 517 | $self->adderrmsg('You need to select a set to view.'); |
512 | $self->addbadmessage('You need to select a set to view.'); |
| 518 | } else { |
513 | } else { |
| 519 | $set_to_display = '.' if $set_to_display eq ' -- Top -- '; |
514 | $set_to_display = '.' if $set_to_display eq ' -- Top -- '; |
| 520 | @pg_files = list_pg_files($ce->{courseDirs}->{templates}, |
515 | @pg_files = list_pg_files($ce->{courseDirs}->{templates}, |
| 521 | "$set_to_display"); |
516 | "$set_to_display"); |
| 522 | $use_previous_problems=0; |
517 | $use_previous_problems=0; |
| … | |
… | |
| 527 | } elsif ($r->param('view_mysets_set')) { |
522 | } elsif ($r->param('view_mysets_set')) { |
| 528 | |
523 | |
| 529 | my $set_to_display = $r->param('library_sets'); |
524 | my $set_to_display = $r->param('library_sets'); |
| 530 | if (not defined($set_to_display) |
525 | if (not defined($set_to_display) |
| 531 | or $set_to_display eq "Select a Problem Set" |
526 | or $set_to_display eq "Select a Problem Set" |
| 532 | or $set_to_display eq 'There are no local sets yet') { |
527 | or $set_to_display eq NO_LOCAL_SET_STRING) { |
| 533 | $self->adderrmsg("You need to select a set from this course to view."); |
528 | $self->addbadmessage("You need to select a set from this course to view."); |
| 534 | } else { |
529 | } else { |
| 535 | my @problemList = $db->listGlobalProblems($set_to_display); |
530 | my @problemList = $db->listGlobalProblems($set_to_display); |
| 536 | my $problem; |
531 | my $problem; |
| 537 | @pg_files=(); |
532 | @pg_files=(); |
| 538 | for $problem (@problemList) { |
533 | for $problem (@problemList) { |
| … | |
… | |
| 574 | |
569 | |
| 575 | ##### Make a new local problem set |
570 | ##### Make a new local problem set |
| 576 | |
571 | |
| 577 | } elsif ($r->param('new_local_set')) { |
572 | } elsif ($r->param('new_local_set')) { |
| 578 | if ($r->param('new_set_name') !~ /^[\w.-]*$/) { |
573 | if ($r->param('new_set_name') !~ /^[\w.-]*$/) { |
| 579 | $self->adderrmsg("The name ".$r->param('new_set_name')." is not a valid set name. Use only letters, digits, -, _, and ."); |
574 | $self->addbadmessage("The name ".$r->param('new_set_name')." is not a valid set name. Use only letters, digits, -, _, and ."); |
| 580 | } else { |
575 | } else { |
| 581 | my $newSetName = $r->param('new_set_name'); |
576 | my $newSetName = $r->param('new_set_name'); |
| 582 | $newSetName =~ s/^set//; |
577 | $newSetName =~ s/^set//; |
| 583 | $newSetName =~ s/\.def$//; |
578 | $newSetName =~ s/\.def$//; |
| 584 | $r->param('local_sets',$newSetName); |
579 | $r->param('local_sets',$newSetName); |
| 585 | my $newSetRecord = $db->getGlobalSet($newSetName); |
580 | my $newSetRecord = $db->getGlobalSet($newSetName); |
| 586 | if (defined($newSetRecord)) { |
581 | if (defined($newSetRecord)) { |
| 587 | $self->adderrmsg("The set name $newSetName is already in use. Pick a different name if you would like to start a new set."); |
582 | $self->addbadmessage("The set name $newSetName is already in use. Pick a different name if you would like to start a new set."); |
| 588 | } else { # Do it! |
583 | } else { # Do it! |
| 589 | $newSetRecord = $db->{set}->{record}->new(); |
584 | $newSetRecord = $db->{set}->{record}->new(); |
| 590 | $newSetRecord->set_id($newSetName); |
585 | $newSetRecord->set_id($newSetName); |
| 591 | $newSetRecord->set_header(""); |
586 | $newSetRecord->set_header(""); |
| 592 | $newSetRecord->problem_header(""); |
587 | $newSetRecord->problem_header(""); |
| … | |
… | |
| 606 | @pg_files = grep {($_->[1] & ADDED) != 0 } @{$self->{past_problems}}; |
601 | @pg_files = grep {($_->[1] & ADDED) != 0 } @{$self->{past_problems}}; |
| 607 | @selected = map {$_->[0]} @pg_files; |
602 | @selected = map {$_->[0]} @pg_files; |
| 608 | |
603 | |
| 609 | my @action_files = grep {$_->[1] > 0 } @{$self->{past_problems}}; |
604 | my @action_files = grep {$_->[1] > 0 } @{$self->{past_problems}}; |
| 610 | if(scalar(@action_files) == 0) { |
605 | if(scalar(@action_files) == 0) { |
| 611 | $self->adderrmsg('Act on marked problems requested, but no problems were marked.'); |
606 | $self->addbadmessage('Act on marked problems requested, but no problems were marked.'); |
| 612 | } |
607 | } |
| 613 | |
608 | |
| 614 | if (scalar(@selected)>0) { # if some are to be added, they need a place to go |
609 | if (scalar(@selected)>0) { # if some are to be added, they need a place to go |
| 615 | $localSet = $r->param('local_sets'); |
610 | $localSet = $r->param('local_sets'); |
| 616 | if (not defined($localSet)) { |
611 | if (not defined($localSet) or |
|
|
612 | $localSet eq SELECT_SET_STRING or |
|
|
613 | $localSet eq NO_LOCAL_SET_STRING) { |
| 617 | $self->adderrmsg('You are trying to add problems to something, but you did not select a "Current Set" name as a target.'); |
614 | $self->addbadmessage('You are trying to add problems to something, but you did not select a "Current Set" name as a target.'); |
| 618 | } else { |
615 | } else { |
| 619 | my $newSetRecord = $db->getGlobalSet($localSet); |
616 | my $newSetRecord = $db->getGlobalSet($localSet); |
| 620 | if (not defined($newSetRecord)) { |
617 | if (not defined($newSetRecord)) { |
| 621 | $self->adderrmsg("You are trying to add problems to $localSet, but that set does not seem to exist! I bet you used your \"Back\" button."); |
618 | $self->addbadmessage("You are trying to add problems to $localSet, but that set does not seem to exist! I bet you used your \"Back\" button."); |
| 622 | } else { |
619 | } else { |
| 623 | my $addcount = add_selected($self, $db, $localSet); |
620 | my $addcount = add_selected($self, $db, $localSet); |
| 624 | if($addcount > 0) { |
621 | if($addcount > 0) { |
| 625 | $self->addgoodmsg("Successfully added $addcount problem".(($addcount>1)?'s':''). |
622 | $self->addgoodmessage("Added $addcount problem".(($addcount>1)?'s':''). |
| 626 | " to $localSet."); |
623 | " to $localSet."); |
| 627 | } |
624 | } |
| 628 | } |
625 | } |
| 629 | } |
626 | } |
| 630 | } |
627 | } |