[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator / Instructor / SetMaker.pm Repository:
ViewVC logotype

Annotation of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1994 - (view) (download) (as text)

1 : jj 1994 ################################################################################
2 :     # WeBWorK Online Homework Delivery System
3 :     # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4 :     # $CVSHeader:
5 :     #
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
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.
10 :     #
11 :     # This program is distributed in the hope that it will be useful, but WITHOUT
12 :     # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 :     # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the
14 :     # Artistic License for more details.
15 :     ################################################################################
16 :    
17 :    
18 :     package WeBWorK::ContentGenerator::Instructor::SetMaker;
19 :     use base qw(WeBWorK::ContentGenerator::Instructor);
20 :    
21 :     =head1 NAME
22 :    
23 :     WeBWorK::ContentGenerator::Instructor::SetMaker - Make problem sets.
24 :    
25 :     =cut
26 :    
27 :     use strict;
28 :     use warnings;
29 :    
30 :     use CGI::Pretty qw();
31 :     use WeBWorK::Form;
32 :     use WeBWorK::Utils qw(readDirectory max);
33 :     use WeBWorK::Utils::Tasks qw(renderProblems);
34 :    
35 :     require WeBWorK::Utils::ListingDB;
36 :    
37 :    
38 :     use constant MAX_SHOW => 20;
39 :    
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
42 :     ## directory has any pg files. The second is a list of directories
43 :     ## which contain pg files.
44 :     sub get_library_sets {
45 :     my $topdir = shift;
46 :     my @lis = readDirectory($topdir);
47 :     my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$topdir/$_"} @lis;
48 :     my $havepg = scalar(@pgs)>0 ? 1 : 0;
49 :     my @mdirs = grep {$_ ne "." and $_ ne ".." and $_ ne "Library"
50 :     and -d "$topdir/$_"} @lis;
51 :     my ($adir, @results, @thisresult);
52 :     for $adir (@mdirs) {
53 :     @results = get_library_sets("$topdir/$adir");
54 :     my $isadirok = shift @results;
55 :     @thisresult = (@thisresult, @results);
56 :     if ($isadirok) {
57 :     @thisresult = ("$topdir/$adir", @thisresult);
58 :     }
59 :     }
60 :     return(($havepg, @thisresult));
61 :     }
62 :    
63 :     ## List all the pg files in the requested directory
64 :     sub list_pg_files {
65 :     my $templatedir = shift;
66 :     my $topdir = shift;
67 :    
68 :     my @lis = readDirectory("$templatedir/$topdir");
69 :     my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$templatedir/$topdir/$_"} @lis;
70 :     @pgs = map { "$topdir/$_" } @pgs;
71 :     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 :     }
81 :    
82 :     ## 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
84 :     ## be hidden
85 :    
86 :     sub get_past_problem_files {
87 :     my $r = shift;
88 :     my @found=();
89 :     my $count =1;
90 :     while (defined($r->param("filetrial$count"))) {
91 :     push @found, [$r->param("filetrial$count"),
92 :     defined($r->param("trial$count")) ? $r->param("trial$count"):0,
93 :     defined($r->param("hideme$count")) ?$r->param("hideme$count"):0];
94 :     $count++;
95 :     }
96 :     return(@found);
97 :     }
98 :    
99 :     #### For adding new problems
100 :    
101 :     sub add_selected {
102 :     my $self = shift;
103 :     my $db = shift;
104 :     my $setName = shift;
105 :     my @selected = @_;
106 :     my (@path, $file, $selected, $freeProblemID);
107 :     $freeProblemID = max($db->listGlobalProblems($setName)) + 1;
108 :    
109 :     for $selected (@selected) {
110 :     $file = $selected;
111 :     @path = split "/", $selected;
112 :     pop @path; # Remove the file name from the path
113 :     shift @path if $path[0] eq ""; # remove the null element from the begining
114 :     my $problemRecord = $db->newGlobalProblem();
115 :     $problemRecord->problem_id($freeProblemID++);
116 :     $problemRecord->set_id($setName);
117 :     $problemRecord->source_file($file);
118 :     $problemRecord->value("1");
119 :     $problemRecord->max_attempts("-1");
120 :     $db->addGlobalProblem($problemRecord);
121 :     $self->assignProblemToAllSetUsers($problemRecord);
122 :     }
123 :     }
124 :    
125 :    
126 :     ############# List of library sets
127 :    
128 :     sub getalllibsets {
129 :     my $ce = shift;
130 :     my @all_library_sets = get_library_sets($ce->{courseDirs}->{templates});
131 :     shift @all_library_sets;
132 :     my $j;
133 :     for ($j=0; $j<scalar(@all_library_sets); $j++) {
134 :     $all_library_sets[$j] =~ s|^$ce->{courseDirs}->{templates}/?||;
135 :     }
136 :     @all_library_sets = sort @all_library_sets;
137 :     return (\@all_library_sets);
138 :     }
139 :    
140 :     ### The browsing panel has three versions
141 :     ##### Version 1 is local problems
142 :     sub browse_local_panel {
143 :     my $self = shift;
144 :     my $library_selected = shift;
145 :    
146 :     my $list_of_sets= getalllibsets($self->r->ce);
147 :     my $libstr = "";
148 :     my $default_value = "Select a Local Problem Collection";
149 :     $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg});
150 :    
151 :     if (not $library_selected or $library_selected eq $default_value) {
152 :     unshift @{$list_of_sets}, $default_value;
153 :     $library_selected = $default_value;
154 :     }
155 :    
156 :    
157 :     print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Local Problems: ",
158 :     CGI::popup_menu(-name=> 'library_sets',
159 :     -values=>$list_of_sets,
160 :     -default=> $library_selected),
161 :     CGI::br(),
162 :     CGI::submit(-name=>"view_local_set", -value=>"View Problems"),
163 :     $libstr
164 :     ));
165 :     }
166 :    
167 :     ##### Version 2 is local problem sets
168 :     sub browse_mysets_panel {
169 :     my $self = shift;
170 :     my $library_selected = shift;
171 :     my $list_of_local_sets = shift;
172 :     my $default_value = "Select a Problem Set";
173 :    
174 :     my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg});
175 :    
176 :     if (not $library_selected or $library_selected eq $default_value) {
177 :     unshift @{$list_of_local_sets}, $default_value;
178 :     $library_selected = $default_value;
179 :     }
180 :    
181 :     print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Browse from: ",
182 :     CGI::popup_menu(-name=> 'library_sets',
183 :     -values=>$list_of_local_sets,
184 :     -default=> $library_selected),
185 :     CGI::br(),
186 :     CGI::submit(-name=>"view_mysets_set", -value=>"View This Set"),
187 :     $libstr
188 :     ));
189 :     }
190 :    
191 :     ##### Version 3 is the problem library
192 :    
193 :    
194 :     # There a different levels, and you can pick a new chapter,
195 :     # pick a new section, pick all from chapter, pick all from section
196 :     #
197 :     # Incoming data - current chapter, current section
198 :     sub browse_library_panel {
199 :     my $self = shift;
200 :     my $r = $self->r;
201 :    
202 :     my $libraryRoot = $r->{ce}->{webworkDirs}->{libraryRoot};
203 :    
204 :     unless($libraryRoot) {
205 :     print CGI::Tr(CGI::td(CGI::div({class=>'ResultsWithError', align=>"center"},
206 :     "The problem library has not been installed.")));
207 :     return;
208 :     }
209 :    
210 :     my $default_chap = "All Chapters";
211 :     my $default_sect = "All Sections";
212 :    
213 :     my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg});
214 :    
215 :     my @chaps = WeBWorK::Utils::ListingDB::getAllChapters($r->{ce});
216 :     unshift @chaps, $default_chap;
217 :     my $chapter_selected = $r->param('library_chapters') || $default_chap;
218 :    
219 :     my @sects=();
220 :     if ($chapter_selected ne $default_chap) {
221 :     @sects = WeBWorK::Utils::ListingDB::getAllSections($r->{ce}, $chapter_selected);
222 :     }
223 :    
224 :     my @textbooks = ('Textbook info not ready');
225 :    
226 :     unshift @sects, $default_sect;
227 :     my $section_selected = $r->param('library_sections') || $default_sect;
228 :    
229 :     print CGI::Tr(CGI::td({-class=>"InfoPanel"},
230 :     CGI::start_table(),
231 :     CGI::Tr(
232 :     CGI::td(["Chapter:",
233 :     CGI::popup_menu(-name=> 'library_chapters',
234 :     -values=>\@chaps,
235 :     -default=> $chapter_selected,
236 :     -onchange=>"submit();return true"
237 :     ),
238 :     CGI::submit(-name=>"lib_select_chapter", -value=>"Update Section List")])),
239 :     CGI::Tr(
240 :     CGI::td("Section:"),
241 :     CGI::td({-colspan=>2},
242 :     CGI::popup_menu(-name=> 'library_sections',
243 :     -values=>\@sects,
244 :     -default=> $section_selected
245 :     ))),
246 :    
247 :     CGI::Tr(
248 :     CGI::td("Textbook:"),
249 :     CGI::td({-colspan=>2},
250 :     CGI::popup_menu(-name=> 'library_textbooks',
251 :     -values=>\@textbooks,
252 :     # -default=> $section_selected
253 :     ))),
254 :    
255 :     CGI::Tr(
256 :     CGI::td("Keywords:"),
257 :     CGI::td({-colspan=>2}, CGI::textfield(-name=>"keywords",
258 :     -default=>"Keywords not implemented yet",
259 :     -override=>1, -size=>60))),
260 :     CGI::Tr(CGI::td({-colspan=>3},CGI::submit(-name=>"lib_view", -value=>"View Problems"))),
261 :     CGI::end_table(),
262 :     $libstr
263 :     ));
264 :     }
265 :    
266 :     sub make_top_row {
267 :     my $self = shift;
268 :     my $r = $self->r;
269 :     my %data = @_;
270 :    
271 :     my $list_of_local_sets = $data{all_set_defs};
272 :     my $browse_which = $data{browse_which};
273 :     my $library_selected = $r->param('library_sets');
274 :     my $set_selected = $r->param('local_sets');
275 :    
276 :     my $list_of_sets;
277 :     my ($dis1, $dis2, $dis3) = ("","","");
278 :     $dis1 = '-disabled' if($browse_which eq 'browse_library');
279 :     $dis2 = '-disabled' if($browse_which eq 'browse_local');
280 :     $dis3 = '-disabled' if($browse_which eq 'browse_mysets');
281 :    
282 :     my $locstr = "";
283 :     $locstr = CGI::br() . CGI::em($self->{localmsg}) if($self->{localmsg});
284 :    
285 :     my $these_widths = "width: 27ex";
286 :     print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"},
287 :     CGI::submit(-name=>"browse_library", -value=>"Browse Problem Library", -style=>$these_widths, $dis1),
288 :     CGI::submit(-name=>"browse_local", -value=>"Browse Local Problems", -style=>$these_widths, $dis2),
289 :     CGI::submit(-name=>"browse_mysets", -value=>"Browse From This Course", -style=>$these_widths, $dis3),
290 :     ));
291 :    
292 :     print CGI::Tr(CGI::td({-bgcolor=>"black"}));
293 :    
294 :     if ($browse_which eq 'browse_local') {
295 :     browse_local_panel($self, $library_selected);
296 :     } elsif ($browse_which eq 'browse_mysets') {
297 :     browse_mysets_panel($self, $library_selected, $list_of_local_sets);
298 :     } else {
299 :     browse_library_panel($self);
300 :     }
301 :    
302 :     print CGI::Tr(CGI::td({-bgcolor=>"black"}));
303 :    
304 :     if (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") {
306 :     shift @{$list_of_local_sets};
307 :     }
308 :     unshift @{$list_of_local_sets}, "Select a Set for This Course";
309 :     $set_selected = "Select a Set for This Course";
310 :     }
311 :    
312 :     print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Current Set: ",
313 :     CGI::popup_menu(-name=> 'local_sets',
314 :     -values=>$list_of_local_sets,
315 :     -default=> $set_selected),
316 :     CGI::submit(-name=>"edit_local", -value=>"Edit Current Set"),
317 :     CGI::br(),
318 :     CGI::br(),
319 :     CGI::submit(-name=>"new_local_set", -value=>"Create New Local Set:"),
320 :     " ",
321 :     CGI::textfield(-name=>"new_set_name",
322 :     -default=>"Name for new set here",
323 :     -override=>1, -size=>30),
324 :     CGI::br(),
325 :     $locstr
326 :     ));
327 :    
328 :     print CGI::Tr(CGI::td({-bgcolor=>"black"}));
329 :    
330 :     print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"},
331 :     CGI::submit(-name=>"update", -style=>$these_widths,
332 :     -value=>"Act on Marked Problems"),
333 :     CGI::submit(-name=>"rerandomize",
334 :     -style=>$these_widths,
335 :     -value=>"Rerandomize"),
336 :     CGI::submit(-name=>"cleardisplay",
337 :     -style=>$these_widths,
338 :     -value=>"Clear Problem Display")));
339 :    
340 :     }
341 :    
342 :     sub make_data_row {
343 :     my $self = shift;
344 :     my $sourceFileName = shift;
345 :     my $pg = shift;
346 :     my $cnt = shift;
347 :    
348 :     my $urlpath = $self->r->urlpath;
349 :     my $problem_output = $pg->{flags}->{error_flag} ?
350 :     CGI::em("This problem produced an error") : CGI::div({class=>"RenderSolo"}, $pg->{body_text});
351 :    
352 :    
353 :     my $edit_link = CGI::a({href=>$self->systemLink(
354 :     $urlpath->new(type=>'instructor_problem_editor_withset_withproblem',
355 :     args=>{courseID =>$urlpath->arg("courseID"),
356 :     setID=>"Undefined_Set", problemID=>"1" }
357 :     ), params=>{sourceFilePath => "$sourceFileName"}
358 :     )}, "Edit it" );
359 :    
360 :     my $try_link = CGI::a({href=>$self->systemLink( $urlpath->new(type=>'problem_detail',
361 :     args=>{courseID =>$urlpath->arg("courseID"),
362 :     setID=>"Undefined_Set", problemID=>"1"}
363 :     ),
364 :     params =>{effectiveUser => $self->r->param('user'), editMode => "temporaryFile", sourceFilePath => $self->r->ce->{courseDirs}->{templates}."/$sourceFileName"} )}, "Try it");
365 :    
366 :    
367 :    
368 :     print CGI::Tr({-align=>"left"}, CGI::td(
369 :    
370 :     CGI::div({-style=>"background-color: #DDDDDD"},"File name: $sourceFileName ",
371 :     # $edit_link, " ", $try_link
372 :     ),
373 :    
374 :    
375 :    
376 :    
377 :     CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show me on the next update"),
378 :     CGI::br(),
379 :     CGI::checkbox(-name=>"trial$cnt",-value=>1,-label=>"Add me to the current set on the next update"),
380 :     CGI::hidden(-name=>"filetrial$cnt", -default=>[$sourceFileName]).
381 :     CGI::p($problem_output),
382 :     ));
383 :     }
384 :    
385 :     sub title {
386 :     return "Problem Set Maker";
387 :     }
388 :    
389 :     sub body {
390 :     my ($self) = @_;
391 :    
392 :     my $r = $self->r;
393 :     my $ce = $r->ce; # course environment
394 :     my $db = $r->db; # database
395 :     my $j; # garden variety counter
396 :    
397 :     my $userName = $r->param('user');
398 :    
399 :     my $user = $db->getUser($userName); # checked
400 :     die "record for user $userName (real user) does not exist."
401 :     unless defined $user;
402 :    
403 :     ### Check that this is a professor
404 :     my $authz = $r->authz;
405 :     unless ($authz->hasPermissions($userName, "modify_problem_sets")) {
406 :     print "User $userName returned " .
407 :     $authz->hasPermissions($user, "modify_problem_sets") .
408 :     " for permission";
409 :     return(CGI::em("You are not authorized to access the Instructor tools."));
410 :     }
411 :    
412 :    
413 :     ############# List of problems we have already printed
414 :    
415 :     my @past_problems = get_past_problem_files($r);
416 :     my (@pg_files, @pg_html);
417 :     my $use_previous_problems = 1;
418 :     my $first_shown = $r->param('first_shown') || 0;
419 :     my $last_shown = $r->param('last_shown');
420 :     if (not defined($last_shown)) {
421 :     $last_shown = -1;
422 :     }
423 :     my @all_past_list = (); # these are include requested, but not shown
424 :     $j = 0;
425 :     while (defined($r->param("all_past_list$j"))) {
426 :     push @all_past_list, $r->param("all_past_list$j");
427 :     $j++;
428 :     }
429 :    
430 :     ############# Default of which problem selector to display
431 :    
432 :     my $browse_which = 'browse_local';
433 :     $browse_which = $r->param('browse_which') if defined($r->param('browse_which'));
434 :    
435 :     my $problem_seed = $r->param('problem_seed') || 0;
436 :     $r->param('problem_seed', $problem_seed); # if it wasn't defined before
437 :    
438 :     ########### Start the logic through if elsif elsif ...
439 :    
440 :     ##### Asked to browse certain problems
441 :     if ($r->param('browse_library')) {
442 :     $browse_which = 'browse_library';
443 :     $r->param('library_sets', "");
444 :     } elsif ($r->param('browse_local')) {
445 :     $browse_which = 'browse_local';
446 :     $r->param('library_sets', "");
447 :     } elsif ($r->param('browse_mysets')) {
448 :     $browse_which = 'browse_mysets';
449 :     $r->param('library_sets', "");
450 :    
451 :     ##### Change the seed value
452 :    
453 :     } elsif ($r->param('rerandomize')) {
454 :     $problem_seed++;
455 :     $r->param('problem_seed', $problem_seed);
456 :    
457 :     ##### Clear the display
458 :    
459 :     } elsif ($r->param('cleardisplay')) {
460 :     @pg_files = ();
461 :     $use_previous_problems=0;
462 :    
463 :     ##### View problems selected from the local list
464 :    
465 :     } elsif ($r->param('view_local_set')) {
466 :    
467 :     my $set_to_display = $r->param('library_sets');
468 :     if (not defined($set_to_display) or $set_to_display eq "Select a Local Problem Collection") {
469 :     $self->{libmsg} = "You need to select a set to view.";
470 :     } else {
471 :     @pg_files = list_pg_files($ce->{courseDirs}->{templates},
472 :     "$set_to_display");
473 :     $use_previous_problems=0;
474 :     }
475 :    
476 :     ##### View problems selected from the a set in this course
477 :    
478 :     } elsif ($r->param('view_mysets_set')) {
479 :    
480 :     my $set_to_display = $r->param('library_sets');
481 :     if (not defined($set_to_display) or $set_to_display eq "Select a Problem Set") {
482 :     $self->{libmsg} = "You need to select a set from this course to view.";
483 :     } else {
484 :     my @problemList = $db->listGlobalProblems($set_to_display);
485 :     my $problem;
486 :     @pg_files=();
487 :     for $problem (@problemList) {
488 :     my $problemRecord = $db->getGlobalProblem($set_to_display, $problem); # checked
489 :     die "global $problem for set $set_to_display not found." unless
490 :     $problemRecord;
491 :     push @pg_files, $problemRecord->source_file;
492 :    
493 :     }
494 :     $use_previous_problems=0;
495 :     }
496 :    
497 :     ##### View whole chapter from the library
498 :     ## This will change somewhat later
499 :    
500 :     } elsif ($r->param('lib_view')) {
501 :    
502 :     @pg_files=();
503 :     my $chap = $r->param('library_chapters') || "";
504 :     $chap = "" if($chap eq "All Chapters");
505 :     my $sect = $r->param('library_sections') || "";
506 :     $sect = "" if($sect eq "All Sections");
507 :     my @dbsearch = WeBWorK::Utils::ListingDB::getSectionListings($r->{ce}, "$chap", "$sect");
508 :     my ($result, $tolibpath);
509 :     for $result (@dbsearch) {
510 :     $tolibpath = "$result->{path}/$result->{filename}";
511 :     $tolibpath =~ s|^/ud/jj/src/Database/Libs|Library|;
512 :    
513 :     ## Too clunky!!!!
514 :     push @pg_files, $tolibpath;
515 :     }
516 :     $use_previous_problems=0;
517 :    
518 :     ##### Edit the current local problem set
519 :    
520 :     } elsif ($r->param('edit_local')) { ## Jump to set edit page
521 :     # This is handled in pre_header_initialize -- it redirects
522 :     # If there is an error, so no redirect, we want to be ready
523 :     # and do something here
524 :    
525 :     ##### Make a new local problem set
526 :    
527 :     } elsif ($r->param('new_local_set')) {
528 :     if ($r->param('new_set_name') !~ /^[\w.-]*$/) {
529 :     $self->{localmsg} = "The name ".$r->param('new_set_name')." is not a valid set name. Use only letters, digits, -, _, and .";
530 :     } else {
531 :     my $newSetName = $r->param('new_set_name');
532 :     $newSetName =~ s/^set//;
533 :     $newSetName =~ s/\.def$//;
534 :     my $newSetRecord = $db->getGlobalSet($newSetName);
535 :     if (defined($newSetRecord)) {
536 :     $self->{localmsg} = "The set name $newSetName is already in use. Pick a different name if you would like to start a new set.";
537 :     } else { # Do it!
538 :     $newSetRecord = $db->{set}->{record}->new();
539 :     $newSetRecord->set_id($newSetName);
540 :     $newSetRecord->set_header("");
541 :     $newSetRecord->problem_header("");
542 :     $newSetRecord->open_date(time()+60*60*24*7); # in one week
543 :     $newSetRecord->due_date(time()+60*60*24*7*2); # in two weeks
544 :     $newSetRecord->answer_date(time()+60*60*24*7*3); # in three weeks
545 :     eval {$db->addGlobalSet($newSetRecord)};
546 :     }
547 :     }
548 :    
549 :     ##### Add selected problems to the current local set
550 :    
551 :     } elsif ($r->param('update')) {
552 :     ## first handle problems to be added before we hide them
553 :     my($localSet, @selected);
554 :    
555 :     @pg_files = grep {$_->[1] != 0 } @past_problems;
556 :     @selected = map {$_->[0]} @pg_files;
557 :    
558 :     if (scalar(@selected)>0) { # if some are to be added, they need a place to go
559 :     $localSet = $r->param('local_sets');
560 :     if (not defined($localSet)) {
561 :     $self->{localmsg} = "Trying to add problems to something, you did not select a current set name as a target.";
562 :     } else {
563 :     my $newSetRecord = $db->getGlobalSet($localSet);
564 :     if (not defined($newSetRecord)) {
565 :     $self->{localmsg} = "You need to select a local problem set to add the problems to.";
566 :     } else {
567 :     add_selected($self, $db, $localSet, @selected);
568 :     }
569 :     }
570 :     }
571 :     ## now handle problems to be hidden
572 :    
573 :     @pg_files = grep {$_->[2]==0 } @past_problems;
574 :     @pg_files = map {$_->[0]} @pg_files;
575 :     @all_past_list = (@all_past_list[0..($first_shown-1)],
576 :     @pg_files,
577 :     @all_past_list[($last_shown+1)..(scalar(@all_past_list)-1)]);
578 :     $last_shown = $first_shown+MAX_SHOW -1;
579 :     $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list));
580 :    
581 :     ## FIXME: you should say something if no problems are selected
582 :     ## maybe the add button should be disabled if there are no problems
583 :     ## showing
584 :    
585 :    
586 :     } elsif ($r->param('next_page')) {
587 :     $first_shown = $last_shown+1;
588 :     $last_shown = $first_shown+MAX_SHOW-1;
589 :     $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list));
590 :     } elsif ($r->param('prev_page')) {
591 :     $last_shown = $first_shown-1;
592 :     $first_shown = $last_shown - MAX_SHOW+1;
593 :    
594 :     $first_shown = 0 if($first_shown<0);
595 :    
596 :     ##### No action requested, probably our first time here
597 :    
598 :     } else {
599 :     #my $c = $r->connection;
600 :     #print "Debug info: ". $r->get_remote_host ."<p>". $c->remote_ip ;
601 :     ;
602 :     } ##### end of the if elsif ...
603 :    
604 :    
605 :     ############# List of local sets
606 :    
607 :     my @all_set_defs = get_global_set_defs($db);
608 :     for ($j=0; $j<scalar(@all_set_defs); $j++) {
609 :     $all_set_defs[$j] =~ s|^set||;
610 :     $all_set_defs[$j] =~ s|\.def||;
611 :     }
612 :    
613 :     if ($use_previous_problems) {
614 :     @pg_files = @all_past_list;
615 :     } else {
616 :     $first_shown = 0;
617 :     $last_shown = scalar(@pg_files)<MAX_SHOW ? scalar(@pg_files) : MAX_SHOW;
618 :     $last_shown--; # to make it an array index
619 :     }
620 :    
621 :     @pg_html=($last_shown>=$first_shown) ?
622 :     renderProblems($r,$user, @pg_files[$first_shown..$last_shown]) : ();
623 :    
624 :     ########## Top part
625 :     print CGI::startform({-method=>"POST", -action=>$r->uri}),
626 :     $self->hidden_authen_fields,
627 :     '<div align="center">',
628 :     CGI::start_table({-border=>2});
629 :     make_top_row($self, 'all_set_defs'=>\@all_set_defs,
630 :     'browse_which'=> $browse_which);
631 :     print CGI::hidden(-name=>'browse_which', -default=>[$browse_which]),
632 :     CGI::hidden(-name=>'problem_seed', -default=>[$problem_seed]);
633 :     for ($j = 0 ; $j < scalar(@pg_files) ; $j++) {
634 :     print CGI::hidden(-name=>"all_past_list$j", -default=>$pg_files[$j]);
635 :     }
636 :    
637 :     print CGI::hidden(-name=>'first_shown', -default=>[$first_shown]);
638 :     print CGI::hidden(-name=>'last_shown', -default=>[$last_shown]);
639 :    
640 :    
641 :     ########## Now print problems
642 :     my $jj;
643 :     for ($jj=0; $jj<scalar(@pg_html); $jj++) {
644 :     $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||;
645 :     make_data_row($self, $pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1);
646 :     }
647 :    
648 :     ########## Finish things off
649 :     print CGI::end_table();
650 :     print '</div>';
651 :     # if($first_shown>0 or (1+$last_shown)<scalar(@pg_files)) {
652 :     my ($next_button, $prev_button) = ("", "");
653 :     if ($first_shown > 0) {
654 :     $prev_button = CGI::submit(-name=>"prev_page", -style=>"width:15ex",
655 :     -value=>"Previous page");
656 :     }
657 :     if ((1+$last_shown)<scalar(@pg_files)) {
658 :     $next_button = CGI::submit(-name=>"next_page", -style=>"width:15ex",
659 :     -value=>"Next page");
660 :     }
661 :     if (scalar(@pg_files)>0) {
662 :     print CGI::p(($first_shown+1)."-".($last_shown+1)." of ".scalar(@pg_files).
663 :     " shown.", $prev_button, " ", $next_button);
664 :     }
665 :     # }
666 :     print CGI::endform(), "\n";
667 :    
668 :     return "";
669 :     }
670 :    
671 :     ############################################## End of Body
672 :    
673 :     sub pre_header_initialize {
674 :     my ($self) = @_;
675 :     my $r = $self->r;
676 :     ## For all cases, lets set some things
677 :     $self->{error}=0;
678 :     $self->{libmsg}="";
679 :     $self->{localmsg}="";
680 :    
681 :    
682 :     ### Maybe FIXME: this needs to check permissions before doing anything
683 :    
684 :     ## Now one action we have to deal with here
685 :     if ($r->param('edit_local')) {
686 :     my $urlpath = $r->urlpath;
687 :     my $db = $r->db;
688 :     my $checkset = $db->getGlobalSet($r->param('local_sets'));
689 :     if (not defined($checkset)) {
690 :     $self->{error} = 1;
691 :     $self->{localmsg} = "You need to select a local set before you can edit it.";
692 :     return();
693 :     }
694 :     my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetEditor', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID"));
695 :     my $url = $self->systemLink($page);
696 :     $self->reply_with_redirect($url);
697 :     }
698 :     }
699 :    
700 :    
701 :     # SKEL: To emit your own HTTP header, uncomment this:
702 :     #
703 :     #sub header {
704 :     # my ($self) = @_;
705 :     #
706 :     # # Generate your HTTP header here.
707 :     #
708 :     # # If you return something, it will be used as the HTTP status code for this
709 :     # # request. The Apache::Constants module might be useful for gerating status
710 :     # # codes. If you don't return anything, the status code "OK" will be used.
711 :     # return "";
712 :     #}
713 :    
714 :     # SKEL: If you need to do any processing after the HTTP header is sent, but before
715 :     # any template processing occurs, or you need to calculate values that will be
716 :     # used in multiple methods, do it in this method:
717 :     #
718 :     #sub initialize {
719 :     #my ($self) = @_;
720 :     #}
721 :    
722 :     # SKEL: If you need to add tags to the document <HEAD>, uncomment this method:
723 :     #
724 :     #sub head {
725 :     # my ($self) = @_;
726 :     #
727 :     # # You can print head tags here, like <META>, <SCRIPT>, etc.
728 :     #
729 :     # return "";
730 :     #}
731 :    
732 :     # SKEL: To fill in the "info" box (to the right of the main body), use this
733 :     # method:
734 :     #
735 :     #sub info {
736 :     # my ($self) = @_;
737 :     #
738 :     # # Print HTML here.
739 :     #
740 :     # return "";
741 :     #}
742 :    
743 :     # SKEL: To provide navigation links, use this method:
744 :     #
745 :     #sub nav {
746 :     # my ($self, $args) = @_;
747 :     #
748 :     # # See the documentation of path() and pathMacro() in
749 :     # # WeBWorK::ContentGenerator for more information.
750 :     #
751 :     # return "";
752 :     #}
753 :    
754 :     # SKEL: For a little box for display options, etc., use this method:
755 :     #
756 :     #sub options {
757 :     # my ($self) = @_;
758 :     #
759 :     # # Print HTML here.
760 :     #
761 :     # return "";
762 :     #}
763 :    
764 :     # SKEL: For a list of sibling objects, use this method:
765 :     #
766 :     #sub siblings {
767 :     # my ($self, $args) = @_;
768 :     #
769 :     # # See the documentation of siblings() and siblingsMacro() in
770 :     # # WeBWorK::ContentGenerator for more information.
771 :     # #
772 :     # # Refer to implementations in ProblemSet and Problem.
773 :     #
774 :     # return "";
775 :     #}
776 :    
777 :     =head1 AUTHOR
778 :    
779 :     Written by John Jones, jj (at) asu.edu.
780 :    
781 :     =cut
782 :    
783 :    
784 :    
785 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9