| 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: $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.4 2004/05/06 23:20:49 jj 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. |
| … | |
… | |
| 40 | ## to make the recursion work, this returns an array where the first |
40 | ## to make the recursion work, this returns an array where the first |
| 41 | ## item is 1 or 0 depending on whether or not the current |
41 | ## item is 1 or 0 depending on whether or not the current |
| 42 | ## directory has any pg files. The second is a list of directories |
42 | ## directory has any pg files. The second is a list of directories |
| 43 | ## which contain pg files. |
43 | ## which contain pg files. |
| 44 | sub get_library_sets { |
44 | sub get_library_sets { |
|
|
45 | my $amtop = shift; |
| 45 | my $topdir = shift; |
46 | my $topdir = shift; |
| 46 | my @lis = readDirectory($topdir); |
47 | my @lis = readDirectory($topdir); |
| 47 | my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$topdir/$_"} @lis; |
48 | my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$topdir/$_"} @lis; |
| 48 | my $havepg = scalar(@pgs)>0 ? 1 : 0; |
49 | my $havepg = scalar(@pgs)>0 ? 1 : 0; |
| 49 | my @mdirs = grep {$_ ne "." and $_ ne ".." and $_ ne "Library" |
50 | my @mdirs = grep {$_ ne "." and $_ ne ".." and $_ ne "Library" |
| 50 | and -d "$topdir/$_"} @lis; |
51 | and -d "$topdir/$_"} @lis; |
|
|
52 | if($amtop) { # we don't want the library |
|
|
53 | @mdirs = grep {$_ ne "Library"} @mdirs; |
|
|
54 | } |
| 51 | my ($adir, @results, @thisresult); |
55 | my ($adir, @results, @thisresult); |
| 52 | for $adir (@mdirs) { |
56 | for $adir (@mdirs) { |
| 53 | @results = get_library_sets("$topdir/$adir"); |
57 | @results = get_library_sets(0, "$topdir/$adir"); |
| 54 | my $isadirok = shift @results; |
58 | my $isadirok = shift @results; |
| 55 | @thisresult = (@thisresult, @results); |
59 | @thisresult = (@thisresult, @results); |
| 56 | if ($isadirok) { |
60 | if ($isadirok) { |
| 57 | @thisresult = ("$topdir/$adir", @thisresult); |
61 | @thisresult = ("$topdir/$adir", @thisresult); |
| 58 | } |
62 | } |
| … | |
… | |
| 67 | |
71 | |
| 68 | my @lis = readDirectory("$templatedir/$topdir"); |
72 | my @lis = readDirectory("$templatedir/$topdir"); |
| 69 | my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$templatedir/$topdir/$_"} @lis; |
73 | my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$templatedir/$topdir/$_"} @lis; |
| 70 | @pgs = map { "$topdir/$_" } @pgs; |
74 | @pgs = map { "$topdir/$_" } @pgs; |
| 71 | return(@pgs); |
75 | return(@pgs); |
| 72 | } |
|
|
| 73 | |
|
|
| 74 | ## Maybe I should use this instead, returns a list |
|
|
| 75 | sub get_global_set_defs { |
|
|
| 76 | my $db = shift; |
|
|
| 77 | |
|
|
| 78 | my @globalSetIDs = $db->listGlobalSets; |
|
|
| 79 | return(@globalSetIDs); |
|
|
| 80 | } |
76 | } |
| 81 | |
77 | |
| 82 | ## go through past page getting a list of identifiers for the problems |
78 | ## go through past page getting a list of identifiers for the problems |
| 83 | ## and whether or not they are selected, and whether or not they should |
79 | ## and whether or not they are selected, and whether or not they should |
| 84 | ## be hidden |
80 | ## be hidden |
| … | |
… | |
| 125 | |
121 | |
| 126 | ############# List of library sets |
122 | ############# List of library sets |
| 127 | |
123 | |
| 128 | sub getalllibsets { |
124 | sub getalllibsets { |
| 129 | my $ce = shift; |
125 | my $ce = shift; |
| 130 | my @all_library_sets = get_library_sets($ce->{courseDirs}->{templates}); |
126 | my @all_library_sets = get_library_sets(1, $ce->{courseDirs}->{templates}); |
| 131 | shift @all_library_sets; |
127 | my $includetop = shift @all_library_sets; |
| 132 | my $j; |
128 | my $j; |
| 133 | for ($j=0; $j<scalar(@all_library_sets); $j++) { |
129 | for ($j=0; $j<scalar(@all_library_sets); $j++) { |
| 134 | $all_library_sets[$j] =~ s|^$ce->{courseDirs}->{templates}/?||; |
130 | $all_library_sets[$j] =~ s|^$ce->{courseDirs}->{templates}/?||; |
| 135 | } |
131 | } |
| 136 | @all_library_sets = sort @all_library_sets; |
132 | @all_library_sets = sort @all_library_sets; |
|
|
133 | unshift @all_library_sets, ' -- Top -- ' if($includetop); |
| 137 | return (\@all_library_sets); |
134 | return (\@all_library_sets); |
| 138 | } |
135 | } |
| 139 | |
136 | |
| 140 | ### The browsing panel has three versions |
137 | ### The browsing panel has three versions |
| 141 | ##### Version 1 is local problems |
138 | ##### Version 1 is local problems |
| … | |
… | |
| 171 | my $list_of_local_sets = shift; |
168 | my $list_of_local_sets = shift; |
| 172 | my $default_value = "Select a Problem Set"; |
169 | my $default_value = "Select a Problem Set"; |
| 173 | |
170 | |
| 174 | my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg}); |
171 | my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg}); |
| 175 | |
172 | |
|
|
173 | if(scalar(@$list_of_local_sets) == 0) { |
|
|
174 | $list_of_local_sets = ['There are no local sets yet']; |
| 176 | if (not $library_selected or $library_selected eq $default_value) { |
175 | } elsif (not $library_selected or $library_selected eq $default_value) { |
| 177 | unshift @{$list_of_local_sets}, $default_value; |
176 | unshift @{$list_of_local_sets}, $default_value; |
| 178 | $library_selected = $default_value; |
177 | $library_selected = $default_value; |
| 179 | } |
178 | } |
| 180 | |
179 | |
| 181 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Browse from: ", |
180 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Browse from: ", |
| … | |
… | |
| 267 | my $self = shift; |
266 | my $self = shift; |
| 268 | my $r = $self->r; |
267 | my $r = $self->r; |
| 269 | my %data = @_; |
268 | my %data = @_; |
| 270 | |
269 | |
| 271 | my $list_of_local_sets = $data{all_set_defs}; |
270 | my $list_of_local_sets = $data{all_set_defs}; |
|
|
271 | my $have_local_sets = scalar(@$list_of_local_sets); |
| 272 | my $browse_which = $data{browse_which}; |
272 | my $browse_which = $data{browse_which}; |
| 273 | my $library_selected = $r->param('library_sets'); |
273 | my $library_selected = $r->param('library_sets'); |
| 274 | my $set_selected = $r->param('local_sets'); |
274 | my $set_selected = $r->param('local_sets'); |
| 275 | |
275 | |
| 276 | my $list_of_sets; |
276 | my $list_of_sets; |
| … | |
… | |
| 290 | )); |
290 | )); |
| 291 | |
291 | |
| 292 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
292 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
| 293 | |
293 | |
| 294 | if ($browse_which eq 'browse_local') { |
294 | if ($browse_which eq 'browse_local') { |
| 295 | browse_local_panel($self, $library_selected); |
295 | $self->browse_local_panel($library_selected); |
| 296 | } elsif ($browse_which eq 'browse_mysets') { |
296 | } elsif ($browse_which eq 'browse_mysets') { |
| 297 | browse_mysets_panel($self, $library_selected, $list_of_local_sets); |
297 | $self->browse_mysets_panel($library_selected, $list_of_local_sets); |
| 298 | } else { |
298 | } else { |
| 299 | browse_library_panel($self); |
299 | $self->browse_library_panel(); |
| 300 | } |
300 | } |
| 301 | |
301 | |
| 302 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
302 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
| 303 | |
303 | |
|
|
304 | if($have_local_sets ==0) { |
|
|
305 | $list_of_local_sets = ['There are no local sets yet']; |
| 304 | if (not $set_selected or $set_selected eq "Select a Set for This Course") { |
306 | } elsif (not $set_selected or $set_selected eq "Select a Set for This Course") { |
| 305 | if ($list_of_local_sets->[0] eq "Select a Problem Set") { |
307 | if ($list_of_local_sets->[0] eq "Select a Problem Set") { |
| 306 | shift @{$list_of_local_sets}; |
308 | shift @{$list_of_local_sets}; |
| 307 | } |
309 | } |
| 308 | unshift @{$list_of_local_sets}, "Select a Set for This Course"; |
310 | unshift @{$list_of_local_sets}, "Select a Set for This Course"; |
| 309 | $set_selected = "Select a Set for This Course"; |
311 | $set_selected = "Select a Set for This Course"; |
| … | |
… | |
| 343 | my $self = shift; |
345 | my $self = shift; |
| 344 | my $sourceFileName = shift; |
346 | my $sourceFileName = shift; |
| 345 | my $pg = shift; |
347 | my $pg = shift; |
| 346 | my $cnt = shift; |
348 | my $cnt = shift; |
| 347 | |
349 | |
|
|
350 | $sourceFileName =~ s|^./||; # clean up top ugliness |
|
|
351 | |
| 348 | my $urlpath = $self->r->urlpath; |
352 | my $urlpath = $self->r->urlpath; |
| 349 | my $problem_output = $pg->{flags}->{error_flag} ? |
353 | my $problem_output = $pg->{flags}->{error_flag} ? |
| 350 | CGI::em("This problem produced an error") |
354 | CGI::em("This problem produced an error") |
| 351 | : CGI::div({class=>"RenderSolo"}, $pg->{body_text}); |
355 | : CGI::div({class=>"RenderSolo"}, $pg->{body_text}); |
| 352 | |
356 | |
| 353 | |
357 | |
|
|
358 | my $edit_link = ''; |
|
|
359 | if($self->{r}->param('browse_which') ne 'browse_library') { |
| 354 | my $edit_link = CGI::a({href=>$self->systemLink( |
360 | $edit_link = CGI::a({href=>$self->systemLink( |
| 355 | $urlpath->new(type=>'instructor_problem_editor_withset_withproblem', |
361 | $urlpath->new(type=>'instructor_problem_editor_withset_withproblem', |
| 356 | args=>{courseID =>$urlpath->arg("courseID"), |
362 | args=>{courseID =>$urlpath->arg("courseID"), |
| 357 | setID=>"Undefined_Set", problemID=>"1" } |
363 | setID=>"Undefined_Set", problemID=>"1" } |
| 358 | ), params=>{sourceFilePath => "$sourceFileName"} |
364 | ), params=>{sourceFilePath => "$sourceFileName"} |
| 359 | )}, "Edit it" ); |
365 | )}, "Edit it" ); |
|
|
366 | } |
| 360 | |
367 | |
| 361 | my $try_link = CGI::a({href=>$self->systemLink( $urlpath->new(type=>'problem_detail', |
368 | my $try_link = CGI::a({href=>$self->systemLink( $urlpath->new(type=>'problem_detail', |
| 362 | args=>{courseID =>$urlpath->arg("courseID"), |
369 | args=>{courseID =>$urlpath->arg("courseID"), |
| 363 | setID=>"Undefined_Set", problemID=>"1"} |
370 | setID=>"Undefined_Set", problemID=>"1"} |
| 364 | ), |
371 | ), |
| … | |
… | |
| 368 | |
375 | |
| 369 | |
376 | |
| 370 | |
377 | |
| 371 | print CGI::Tr({-align=>"left"}, CGI::td( |
378 | print CGI::Tr({-align=>"left"}, CGI::td( |
| 372 | |
379 | |
| 373 | CGI::div({-style=>"background-color: #DDDDDD"},"File name: $sourceFileName ", |
380 | CGI::div({-style=>"background-color: #DDDDDD; margin: 0px auto"}, |
| 374 | #$edit_link, " ", |
381 | CGI::span({-style=>"float:left ; text-align: left"},"File name: $sourceFileName "), |
| 375 | $try_link |
382 | CGI::span({-style=>"float:right ; text-align: right"}, $edit_link, " ", $try_link) |
| 376 | ), |
383 | ), CGI::br(), |
| 377 | |
384 | |
| 378 | |
385 | |
| 379 | |
386 | |
| 380 | |
387 | |
| 381 | CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show me on the next update"), |
388 | CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show me on the next update"), |
| … | |
… | |
| 470 | |
477 | |
| 471 | my $set_to_display = $r->param('library_sets'); |
478 | my $set_to_display = $r->param('library_sets'); |
| 472 | if (not defined($set_to_display) or $set_to_display eq "Select a Local Problem Collection") { |
479 | if (not defined($set_to_display) or $set_to_display eq "Select a Local Problem Collection") { |
| 473 | $self->{libmsg} = "You need to select a set to view."; |
480 | $self->{libmsg} = "You need to select a set to view."; |
| 474 | } else { |
481 | } else { |
|
|
482 | $set_to_display = '.' if $set_to_display eq ' -- Top -- '; |
| 475 | @pg_files = list_pg_files($ce->{courseDirs}->{templates}, |
483 | @pg_files = list_pg_files($ce->{courseDirs}->{templates}, |
| 476 | "$set_to_display"); |
484 | "$set_to_display"); |
| 477 | $use_previous_problems=0; |
485 | $use_previous_problems=0; |
| 478 | } |
486 | } |
| 479 | |
487 | |
| 480 | ##### View problems selected from the a set in this course |
488 | ##### View problems selected from the a set in this course |
| 481 | |
489 | |
| 482 | } elsif ($r->param('view_mysets_set')) { |
490 | } elsif ($r->param('view_mysets_set')) { |
| 483 | |
491 | |
| 484 | my $set_to_display = $r->param('library_sets'); |
492 | my $set_to_display = $r->param('library_sets'); |
| 485 | if (not defined($set_to_display) or $set_to_display eq "Select a Problem Set") { |
493 | if (not defined($set_to_display) |
|
|
494 | or $set_to_display eq "Select a Problem Set" |
|
|
495 | or $set_to_display eq 'There are no local sets yet') { |
| 486 | $self->{libmsg} = "You need to select a set from this course to view."; |
496 | $self->{libmsg} = "You need to select a set from this course to view."; |
| 487 | } else { |
497 | } else { |
| 488 | my @problemList = $db->listGlobalProblems($set_to_display); |
498 | my @problemList = $db->listGlobalProblems($set_to_display); |
| 489 | my $problem; |
499 | my $problem; |
| 490 | @pg_files=(); |
500 | @pg_files=(); |
| … | |
… | |
| 605 | } ##### end of the if elsif ... |
615 | } ##### end of the if elsif ... |
| 606 | |
616 | |
| 607 | |
617 | |
| 608 | ############# List of local sets |
618 | ############# List of local sets |
| 609 | |
619 | |
| 610 | my @all_set_defs = get_global_set_defs($db); |
620 | my @all_set_defs = $db->listGlobalSets; |
| 611 | for ($j=0; $j<scalar(@all_set_defs); $j++) { |
621 | for ($j=0; $j<scalar(@all_set_defs); $j++) { |
| 612 | $all_set_defs[$j] =~ s|^set||; |
622 | $all_set_defs[$j] =~ s|^set||; |
| 613 | $all_set_defs[$j] =~ s|\.def||; |
623 | $all_set_defs[$j] =~ s|\.def||; |
| 614 | } |
624 | } |
| 615 | |
625 | |
| … | |
… | |
| 627 | ########## Top part |
637 | ########## Top part |
| 628 | print CGI::startform({-method=>"POST", -action=>$r->uri}), |
638 | print CGI::startform({-method=>"POST", -action=>$r->uri}), |
| 629 | $self->hidden_authen_fields, |
639 | $self->hidden_authen_fields, |
| 630 | '<div align="center">', |
640 | '<div align="center">', |
| 631 | CGI::start_table({-border=>2}); |
641 | CGI::start_table({-border=>2}); |
| 632 | make_top_row($self, 'all_set_defs'=>\@all_set_defs, |
642 | $self->make_top_row('all_set_defs'=>\@all_set_defs, |
| 633 | 'browse_which'=> $browse_which); |
643 | 'browse_which'=> $browse_which); |
| 634 | print CGI::hidden(-name=>'browse_which', -default=>[$browse_which]), |
644 | print CGI::hidden(-name=>'browse_which', -default=>[$browse_which]), |
| 635 | CGI::hidden(-name=>'problem_seed', -default=>[$problem_seed]); |
645 | CGI::hidden(-name=>'problem_seed', -default=>[$problem_seed]); |
| 636 | for ($j = 0 ; $j < scalar(@pg_files) ; $j++) { |
646 | for ($j = 0 ; $j < scalar(@pg_files) ; $j++) { |
| 637 | print CGI::hidden(-name=>"all_past_list$j", -default=>$pg_files[$j]); |
647 | print CGI::hidden(-name=>"all_past_list$j", -default=>$pg_files[$j]); |
| … | |
… | |
| 643 | |
653 | |
| 644 | ########## Now print problems |
654 | ########## Now print problems |
| 645 | my $jj; |
655 | my $jj; |
| 646 | for ($jj=0; $jj<scalar(@pg_html); $jj++) { |
656 | for ($jj=0; $jj<scalar(@pg_html); $jj++) { |
| 647 | $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||; |
657 | $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||; |
| 648 | make_data_row($self, $pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1); |
658 | $self->make_data_row($pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1); |
| 649 | } |
659 | } |
| 650 | |
660 | |
| 651 | ########## Finish things off |
661 | ########## Finish things off |
| 652 | print CGI::end_table(); |
662 | print CGI::end_table(); |
| 653 | print '</div>'; |
663 | print '</div>'; |