Parent Directory
|
Revision Log
added move option
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.85 2008/07/01 13:18:52 glarose Exp $ 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::SetMaker2; 19 use base qw(WeBWorK::ContentGenerator::Instructor); 20 21 =head1 NAME 22 23 WeBWorK::ContentGenerator::Instructor::SetMaker2 - Make homework sets. 24 25 =cut 26 27 use strict; 28 use warnings; 29 30 31 #use CGI qw(-nosticky); 32 use WeBWorK::CGI; 33 use WeBWorK::Debug; 34 use WeBWorK::Form; 35 use WeBWorK::Utils qw(readDirectory max sortByName); 36 use WeBWorK::Utils::Tasks qw(renderProblems); 37 use File::Find; 38 39 require WeBWorK::Utils::ListingDB; 40 41 use constant SHOW_HINTS_DEFAULT => 0; 42 use constant SHOW_SOLUTIONS_DEFAULT => 0; 43 use constant MAX_SHOW_DEFAULT => 20; 44 use constant NO_LOCAL_SET_STRING => 'No sets in this course yet'; 45 use constant SELECT_SET_STRING => 'Select a Set from this Course'; 46 use constant SELECT_LOCAL_STRING => 'Select a Problem Collection'; 47 use constant MY_PROBLEMS => ' My Problems '; 48 use constant MAIN_PROBLEMS => ' Unclassified Problems '; 49 use constant CREATE_SET_BUTTON => 'Create New Set'; 50 use constant ALL_CHAPTERS => 'All Chapters'; 51 use constant ALL_SUBJECTS => 'All Subjects'; 52 use constant ALL_SECTIONS => 'All Sections'; 53 use constant ALL_TEXTBOOKS => 'All Textbooks'; 54 55 use constant LIB2_DATA => { 56 'dbchapter' => {name => 'library_chapters', all => 'All Chapters'}, 57 'dbsection' => {name => 'library_sections', all =>'All Sections' }, 58 'dbsubject' => {name => 'library_subjects', all => 'All Subjects' }, 59 'textbook' => {name => 'library_textbook', all => 'All Textbooks'}, 60 'textchapter' => {name => 'library_textchapter', all => 'All Chapters'}, 61 'textsection' => {name => 'library_textsection', all => 'All Sections'}, 62 'keywords' => {name => 'library_keywords', all => '' }, 63 }; 64 65 ## Flags for operations on files 66 67 use constant ADDED => 1; 68 use constant HIDDEN => (1 << 1); 69 use constant SUCCESS => (1 << 2); 70 use constant DELETED => (1 << 3); 71 use constant MOVED => (1 << 4); 72 73 ## for additional problib buttons 74 my %problib; ## filled in in global.conf 75 my %ignoredir = ( 76 '.' => 1, '..' => 1, 'Library' => 1, 'CVS' => 1, 'tmpEdit' => 1, 77 'headers' => 1, 'macros' => 1, 'email' => 1, '.svn' => 1, 78 ); 79 80 sub prepare_activity_entry { 81 my $self=shift; 82 my $r = $self->r; 83 my $user = $self->r->param('user') || 'NO_USER'; 84 return("In SetMaker as user $user"); 85 } 86 87 ## This is for searching the disk for directories containing pg files. 88 ## to make the recursion work, this returns an array where the first 89 ## item is the number of pg files in the directory. The second is a 90 ## list of directories which contain pg files. 91 ## 92 ## If a directory contains only one pg file and the directory name 93 ## is the same as the file name, then the directory is considered 94 ## to be part of the parent directory (it is probably in a separate 95 ## directory only because it has auxiliary files that want to be 96 ## kept together with the pg file). 97 ## 98 ## If a directory has a file named "=library-ignore", it is never 99 ## included in the directory menu. If a directory contains a file 100 ## called "=library-combine-up", then its pg are included with those 101 ## in the parent directory (and the directory does not appear in the 102 ## menu). If it has a file called "=library-no-combine" then it is 103 ## always listed as a separate directory even if it contains only one 104 ## pg file. 105 106 sub get_library_sets { 107 my $top = shift; my $dir = shift; 108 # ignore directories that give us an error 109 my @lis = eval { readDirectory($dir) }; 110 if ($@) { 111 warn $@; 112 return (0); 113 } 114 return (0) if grep /^=library-ignore$/, @lis; 115 116 my @pgfiles = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$dir/$_"} @lis; 117 my $pgcount = scalar(@pgfiles); 118 my $pgname = $dir; $pgname =~ s!.*/!!; $pgname .= '.pg'; 119 my $combineUp = ($pgcount == 1 && $pgname eq $pgfiles[0] && !(grep /^=library-no-combine$/, @lis)); 120 121 my @pgdirs; 122 my @dirs = grep {!$ignoredir{$_} and -d "$dir/$_"} @lis; 123 if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} 124 foreach my $subdir (@dirs) { 125 my @results = get_library_sets(0, "$dir/$subdir"); 126 $pgcount += shift @results; push(@pgdirs,@results); 127 } 128 129 return ($pgcount, @pgdirs) if $top || $combineUp || grep /^=library-combine-up$/, @lis; 130 return (0,@pgdirs,$dir); 131 } 132 133 sub get_library_pgs { 134 my $top = shift; my $base = shift; my $dir = shift; 135 my @lis = readDirectory("$base/$dir"); 136 return () if grep /^=library-ignore$/, @lis; 137 return () if !$top && grep /^=library-no-combine$/, @lis; 138 139 my @pgs = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$base/$dir/$_"} @lis; 140 my $others = scalar(grep { (!m/\.pg$/ || m/(Header|-text)\.pg$/) && 141 !m/(\.(tmp|bak)|~)$/ && -f "$base/$dir/$_" } @lis); 142 143 my @dirs = grep {!$ignoredir{$_} and -d "$base/$dir/$_"} @lis; 144 if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} 145 foreach my $subdir (@dirs) {push(@pgs, get_library_pgs(0,"$base/$dir",$subdir))} 146 147 return () unless $top || (scalar(@pgs) == 1 && $others) || grep /^=library-combine-up$/, @lis; 148 return (map {"$dir/$_"} @pgs); 149 } 150 151 sub list_pg_files { 152 my ($templates,$dir) = @_; 153 my $top = ($dir eq '.')? 1 : 2; 154 my @pgs = get_library_pgs($top,$templates,$dir); 155 return sortByName(undef,@pgs); 156 } 157 158 ## Search for set definition files 159 160 sub get_set_defs { 161 my $topdir = shift; 162 my @found_set_defs; 163 # get_set_defs_wanted is a closure over @found_set_defs 164 my $get_set_defs_wanted = sub { 165 #my $fn = $_; 166 #my $fdir = $File::Find::dir; 167 #return() if($fn !~ /^set.*\.def$/); 168 ##return() if(not -T $fn); 169 #push @found_set_defs, "$fdir/$fn"; 170 push @found_set_defs, $_ if m|/set[^/]*\.def$|; 171 }; 172 find({ wanted => $get_set_defs_wanted, follow_fast=>1, no_chdir=>1}, $topdir); 173 map { $_ =~ s|^$topdir/?|| } @found_set_defs; 174 return @found_set_defs; 175 } 176 177 ## Try to make reading of set defs more flexible. Additional strategies 178 ## for fixing a path can be added here. 179 180 sub munge_pg_file_path { 181 my $self = shift; 182 my $pg_path = shift; 183 my $path_to_set_def = shift; 184 my $end_path = $pg_path; 185 # if the path is ok, don't fix it 186 return($pg_path) if(-e $self->r->ce->{courseDirs}{templates}."/$pg_path"); 187 # if we have followed a link into a self contained course to get 188 # to the set.def file, we need to insert the start of the path to 189 # the set.def file 190 $end_path = "$path_to_set_def/$pg_path"; 191 return($end_path) if(-e $self->r->ce->{courseDirs}{templates}."/$end_path"); 192 # if we got this far, this path is bad, but we let it produce 193 # an error so the user knows there is a troublesome path in the 194 # set.def file. 195 return($pg_path); 196 } 197 198 ## Read a set definition file. This could be abstracted since it happens 199 ## elsewhere. Here we don't have to process so much of the file. 200 201 sub read_set_def { 202 my $self = shift; 203 my $r = $self->r; 204 my $filePathOrig = shift; 205 my $filePath = $r->ce->{courseDirs}{templates}."/$filePathOrig"; 206 $filePathOrig =~ s/set.*\.def$//; 207 $filePathOrig =~ s|/$||; 208 $filePathOrig = "." if ($filePathOrig !~ /\S/); 209 my @pg_files = (); 210 my ($line, $got_to_pgs, $name, @rest) = ("", 0, ""); 211 if ( open (SETFILENAME, "$filePath") ) { 212 while($line = <SETFILENAME>) { 213 chomp($line); 214 $line =~ s|(#.*)||; # don't read past comments 215 if($got_to_pgs) { 216 unless ($line =~ /\S/) {next;} # skip blank lines 217 ($name,@rest) = split (/\s*,\s*/,$line); 218 $name =~ s/\s*//g; 219 push @pg_files, $name; 220 } else { 221 $got_to_pgs = 1 if ($line =~ /problemList\s*=/); 222 } 223 } 224 } else { 225 $self->addbadmessage("Cannot open $filePath"); 226 } 227 # This is where we would potentially munge the pg file paths 228 # One possibility 229 @pg_files = map { $self->munge_pg_file_path($_, $filePathOrig) } @pg_files; 230 return(@pg_files); 231 } 232 233 ## go through past page getting a list of identifiers for the problems 234 ## and whether or not they are selected, and whether or not they should 235 ## be hidden 236 237 sub get_past_problem_files { 238 my $r = shift; 239 my @found=(); 240 my $count =1; 241 while (defined($r->param("filetrial$count"))) { 242 my $val = 0; 243 $val |= ADDED if($r->param("trial$count")); 244 $val |= HIDDEN if($r->param("hideme$count")); 245 $val |= MOVED if($r->param("moved$count")); 246 push @found, [$r->param("filetrial$count"), $val]; 247 $count++; 248 } 249 $count = 1; 250 while (defined($r->param("mysetfiletrial$count"))) { 251 my $val = 0; 252 $val |= DELETED if($r->param("deleted$count")); 253 push @found, [$r->param("mysetfiletrial$count"), $val]; 254 $count++; 255 } 256 return(\@found); 257 } 258 259 #### For adding new problems 260 261 sub add_selected { 262 my $self = shift; 263 my $db = shift; 264 my $setName = shift; 265 my @past_problems = @{$self->{past_problems}}; 266 my @selected = @past_problems; 267 my (@path, $file, $selected, $freeProblemID); 268 # DBFIXME count would work just as well 269 $freeProblemID = max($db->listGlobalProblems($setName)) + 1; 270 my $addedcount=0; 271 272 for $selected (@selected) { 273 if($selected->[1] & ADDED || $selected->[1] & MOVED) { 274 $file = $selected->[0]; 275 print "$file"; 276 my $problemRecord = $self->addProblemToSet(setName => $setName, 277 sourceFile => $file, problemID => $freeProblemID); 278 $freeProblemID++; 279 $self->assignProblemToAllSetUsers($problemRecord); 280 if(!($selected->[1] & MOVED)){ 281 $selected->[1] |= SUCCESS; 282 } 283 $addedcount++; 284 } 285 } 286 return($addedcount); 287 } 288 289 sub delete_selected { 290 my $self = shift; 291 my $db = shift; 292 my $setName = shift; 293 my @past_problems = @{$self->{past_problems}}; 294 my @selected = @past_problems; 295 my (@path, $file, $selected); 296 # DBFIXME count would work just as well 297 my $deletedcount=0; 298 299 for $selected (@selected) { 300 if($selected->[1] & DELETED || $selected->[1] & MOVED) { 301 foreach my $problem ($db->listGlobalProblems($setName)) { 302 my $problemRecord = $db->getGlobalProblem($setName, $problem); 303 if($problemRecord->source_file eq $selected->[0]){ 304 $db->deleteGlobalProblem($setName, $problemRecord->problem_id); 305 } 306 } 307 if(!($selected->[1] & MOVED)){ 308 $selected->[1] |= SUCCESS; 309 } 310 $deletedcount++; 311 } 312 } 313 return($deletedcount); 314 } 315 316 317 ############# List of sets of problems in templates directory 318 319 sub get_problem_directories { 320 my $ce = shift; 321 my $lib = shift; 322 my $source = $ce->{courseDirs}{templates}; 323 my $main = MY_PROBLEMS; my $isTop = 1; 324 if ($lib) {$source .= "/$lib"; $main = MAIN_PROBLEMS; $isTop = 2} 325 my @all_problem_directories = get_library_sets($isTop, $source); 326 my $includetop = shift @all_problem_directories; 327 my $j; 328 for ($j=0; $j<scalar(@all_problem_directories); $j++) { 329 $all_problem_directories[$j] =~ s|^$ce->{courseDirs}->{templates}/?||; 330 } 331 @all_problem_directories = sortByName(undef, @all_problem_directories); 332 unshift @all_problem_directories, $main if($includetop); 333 return (\@all_problem_directories); 334 } 335 336 ############# Everyone has a view problems line. Abstract it 337 sub view_problems_line { 338 my $internal_name = shift; 339 my $label = shift; 340 my $r = shift; # so we can get parameter values 341 my $result = CGI::submit(-name=>"$internal_name", -value=>$label); 342 343 my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()}; 344 my @active_modes = grep { exists $display_modes{$_} } 345 @{$r->ce->{pg}->{displayModes}}; 346 push @active_modes, 'None'; 347 # We have our own displayMode since its value may be None, which is illegal 348 # in other modules. 349 my $mydisplayMode = $r->param('mydisplayMode') || $r->ce->{pg}->{options}->{displayMode}; 350 $result .= ' Display Mode: '.CGI::popup_menu(-name=> 'mydisplayMode', 351 -values=>\@active_modes, 352 -default=> $mydisplayMode); 353 # Now we give a choice of the number of problems to show 354 my $defaultMax = $r->param('max_shown') || MAX_SHOW_DEFAULT; 355 $result .= ' Max. Shown: '. 356 CGI::popup_menu(-name=> 'max_shown', 357 -values=>[5,10,15,20,25,30,50,'All'], 358 -default=> $defaultMax); 359 # Option of whether to show hints and solutions 360 my $defaultHints = $r->param('showHints') || SHOW_HINTS_DEFAULT; 361 $result .= " ".CGI::checkbox(-name=>"showHints",-checked=>$defaultHints,-label=>"Hints"); 362 my $defaultSolutions = $r->param('showSolutions') || SHOW_SOLUTIONS_DEFAULT; 363 $result .= " ".CGI::checkbox(-name=>"showSolutions",-checked=>$defaultSolutions,-label=>"Solutions"); 364 365 return($result); 366 } 367 368 369 ### The browsing panel has three versions 370 ##### Version 1 is local problems 371 sub browse_local_panel { 372 my $self = shift; 373 my $library_selected = shift; 374 my $lib = shift || ''; $lib =~ s/^browse_//; 375 my $name = ($lib eq '')? 'Local' : $problib{$lib}; 376 377 my $list_of_prob_dirs= get_problem_directories($self->r->ce,$lib); 378 if(scalar(@$list_of_prob_dirs) == 0) { 379 $library_selected = "Found no directories containing problems"; 380 unshift @{$list_of_prob_dirs}, $library_selected; 381 } else { 382 my $default_value = SELECT_LOCAL_STRING; 383 if (not $library_selected or $library_selected eq $default_value) { 384 unshift @{$list_of_prob_dirs}, $default_value; 385 $library_selected = $default_value; 386 } 387 } 388 debug("library is $lib and sets are $library_selected"); 389 my $view_problem_line = view_problems_line('view_local_set', 'View Problems', $self->r); 390 my @popup_menu_args = ( 391 -name => 'library_sets', 392 -values => $list_of_prob_dirs, 393 -default => $library_selected, 394 ); 395 # make labels without the $lib prefix -- reduces the width of the popup menu 396 if (length($lib)) { 397 my %labels = map { my($l)=$_=~/^$lib\/(.*)$/;$_=>$l } @$list_of_prob_dirs; 398 push @popup_menu_args, -labels => \%labels; 399 } 400 print CGI::div({-class=>"InfoPanel", -align=>"left"}, "$name Problems: ", 401 CGI::popup_menu(@popup_menu_args), 402 CGI::br(), 403 $view_problem_line, 404 ); 405 } 406 407 ##### Version 2 is local homework sets 408 sub browse_mysets_panel { 409 my $self = shift; 410 my $library_selected = shift; 411 my $list_of_local_sets = shift; 412 my $remember_local_set = shift; 413 my $default_value = "Select a Homework Set"; 414 415 if(scalar(@$list_of_local_sets) == 0) { 416 $list_of_local_sets = [NO_LOCAL_SET_STRING]; 417 } elsif (not $library_selected or $library_selected eq $default_value) { 418 unshift @{$list_of_local_sets}, $default_value; 419 $library_selected = $default_value; 420 } 421 422 #my $view_problem_line = view_problems_line('view_mysets_set', 'View Problems', $self->r); 423 print CGI::div({-class=>"InfoPanel", -align=>"left"}, 424 CGI::submit(-name=>"update", -style=>"width: 25ex; font-weight:bold;", 425 -value=>"Update Set"), 426 CGI::popup_menu(-name=> 'myset_sets', 427 -values=>$list_of_local_sets, 428 -default=> $library_selected), 429 CGI::hidden(-name=> 'local_sets', -value=>$remember_local_set), 430 CGI::br(), 431 CGI::submit(-name=>"view_mysets_set", -value=>"View Set"), 432 ); 433 } 434 435 ##### Version 2.1 is local homework sets 436 sub edit_mysets_panel { 437 my $self = shift; 438 my $library_selected = shift; 439 my $list_of_local_sets = shift; 440 my $default_value = "Select a Homework Set"; 441 442 if(scalar(@$list_of_local_sets) == 0) { 443 $list_of_local_sets = [NO_LOCAL_SET_STRING]; 444 } elsif (not $library_selected or $library_selected eq $default_value) { 445 unshift @{$list_of_local_sets}, $default_value; 446 $library_selected = $default_value; 447 } 448 449 my $view_problem_line = view_problems_line('edit_mysets_set', 'View Problems', $self->r); 450 print CGI::Tr({}, 451 CGI::td({-class=>"InfoPanel", -align=>"left"}, "Browse from: ", 452 CGI::popup_menu(-name=> 'library_sets', 453 -values=>$list_of_local_sets, 454 -default=> $library_selected), 455 CGI::br(), 456 $view_problem_line 457 )); 458 } 459 460 ##### Version 3 is the problem library 461 # 462 # This comes in 3 forms, problem library version 1, and for version 2 there 463 # is the basic, and the advanced interfaces. This function checks what we are 464 # supposed to do, or aborts if the problem library has not been installed. 465 466 sub browse_library_panel { 467 my $self=shift; 468 my $r = $self->r; 469 my $ce = $r->ce; 470 471 # See if the problem library is installed 472 my $libraryRoot = $r->{ce}->{problemLibrary}->{root}; 473 474 unless($libraryRoot) { 475 print CGI::div({class=>'ResultsWithError', align=>"center"}, 476 "The problem library has not been installed."); 477 return; 478 } 479 # Test if the Library directory link exists. If not, try to make it 480 unless(-d "$ce->{courseDirs}->{templates}/Library") { 481 unless(symlink($libraryRoot, "$ce->{courseDirs}->{templates}/Library")) { 482 my $msg = <<"HERE"; 483 You are missing the directory <code>templates/Library</code>, which is needed 484 for the Problem Library to function. It should be a link pointing to 485 <code>$libraryRoot</code>, which you set in <code>conf/global.conf</code>. 486 I tried to make the link for you, but that failed. Check the permissions 487 in your <code>templates</code> directory. 488 HERE 489 $self->addbadmessage($msg); 490 } 491 } 492 493 # Now check what version we are supposed to use 494 my $libraryVersion = $r->{ce}->{problemLibrary}->{version} || 1; 495 if($libraryVersion == 1) { 496 return $self->browse_library_panel1; 497 } elsif($libraryVersion == 2) { 498 return $self->browse_library_panel2 if($self->{library_basic}==1); 499 return $self->browse_library_panel2adv; 500 } else { 501 print CGI::div({class=>'ResultsWithError', align=>"center"}, 502 "The problem library version is set to an illegal value."); 503 return; 504 } 505 } 506 507 sub browse_library_panel1 { 508 my $self = shift; 509 my $r = $self->r; 510 my $ce = $r->ce; 511 512 my @chaps = WeBWorK::Utils::ListingDB::getAllChapters($r->{ce}); 513 unshift @chaps, LIB2_DATA->{dbchapter}{all}; 514 my $chapter_selected = $r->param('library_chapters') || LIB2_DATA->{dbchapter}->{all}; 515 516 my @sects=(); 517 if ($chapter_selected ne LIB2_DATA->{dbchapter}{all}) { 518 @sects = WeBWorK::Utils::ListingDB::getAllSections($r->{ce}, $chapter_selected); 519 } 520 521 unshift @sects, ALL_SECTIONS; 522 my $section_selected = $r->param('library_sections') || LIB2_DATA->{dbsection}{all}; 523 524 my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r); 525 526 print CGI::div({-class=>"InfoPanel", -align=>"left"}, 527 CGI::div(["Chapter:", 528 CGI::popup_menu(-name=> 'library_chapters', 529 -values=>\@chaps, 530 -default=> $chapter_selected, 531 -onchange=>"submit();return true" 532 ), 533 CGI::submit(-name=>"lib_select_chapter", -value=>"Update Section List")]), 534 CGI::div("Section:", 535 CGI::popup_menu(-name=> 'library_sections', 536 -values=>\@sects, 537 -default=> $section_selected 538 )), 539 CGI::div($view_problem_line) 540 ); 541 } 542 543 sub browse_library_panel2 { 544 my $self = shift; 545 my $r = $self->r; 546 my $ce = $r->ce; 547 548 my @subjs = WeBWorK::Utils::ListingDB::getAllDBsubjects($r); 549 unshift @subjs, LIB2_DATA->{dbsubject}{all}; 550 551 my @chaps = WeBWorK::Utils::ListingDB::getAllDBchapters($r); 552 unshift @chaps, LIB2_DATA->{dbchapter}{all}; 553 554 my @sects=(); 555 @sects = WeBWorK::Utils::ListingDB::getAllDBsections($r); 556 unshift @sects, LIB2_DATA->{dbsection}{all}; 557 558 my $subject_selected = $r->param('library_subjects') || LIB2_DATA->{dbsubject}{all}; 559 my $chapter_selected = $r->param('library_chapters') || LIB2_DATA->{dbchapter}{all}; 560 my $section_selected = $r->param('library_sections') || LIB2_DATA->{dbsection}{all}; 561 562 my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r); 563 564 my $count_line = WeBWorK::Utils::ListingDB::countDBListings($r); 565 if($count_line==0) { 566 $count_line = "There are no matching pg files"; 567 } else { 568 $count_line = "There are $count_line matching WeBWorK problem files"; 569 } 570 571 print CGI::div({-class=>"InfoPanel", -align=>"left"}, 572 CGI::hidden(-name=>"library_is_basic", -default=>1,-override=>1), 573 CGI::div(["Subject:", 574 CGI::popup_menu(-name=> 'library_subjects', 575 -values=>\@subjs, 576 -default=> $subject_selected, 577 -onchange=>"submit();return true" 578 )]), 579 CGI::div({-colspan=>2, -align=>"right"}, 580 CGI::submit(-name=>"lib_select_subject", -value=>"Update Chapter/Section Lists")), 581 CGI::div(["Chapter:", 582 CGI::popup_menu(-name=> 'library_chapters', 583 -values=>\@chaps, 584 -default=> $chapter_selected, 585 -onchange=>"submit();return true" 586 )]), 587 CGI::div({-colspan=>2, -align=>"right"}, 588 CGI::submit(-name=>"library_advanced", -value=>"Advanced Search")), 589 CGI::div(["Section:", 590 CGI::popup_menu(-name=> 'library_sections', 591 -values=>\@sects, 592 -default=> $section_selected, 593 -onchange=>"submit();return true" 594 )]), 595 CGI::div({-colspan=>3}, $view_problem_line), 596 CGI::div({-colspan=>3, -align=>"center"}, $count_line) 597 ); 598 599 } 600 601 sub browse_library_panel2adv { 602 my $self = shift; 603 my $r = $self->r; 604 my $ce = $r->ce; 605 my $right_button_style = "width: 18ex"; 606 607 my @subjs = WeBWorK::Utils::ListingDB::getAllDBsubjects($r); 608 if(! grep { $_ eq $r->param('library_subjects') } @subjs) { 609 $r->param('library_subjects', ''); 610 } 611 unshift @subjs, LIB2_DATA->{dbsubject}{all}; 612 613 my @chaps = WeBWorK::Utils::ListingDB::getAllDBchapters($r); 614 if(! grep { $_ eq $r->param('library_chapters') } @chaps) { 615 $r->param('library_chapters', ''); 616 } 617 unshift @chaps, LIB2_DATA->{dbchapter}{all}; 618 619 my @sects = WeBWorK::Utils::ListingDB::getAllDBsections($r); 620 if(! grep { $_ eq $r->param('library_sections') } @sects) { 621 $r->param('library_sections', ''); 622 } 623 unshift @sects, LIB2_DATA->{dbsection}{all}; 624 625 my $texts = WeBWorK::Utils::ListingDB::getDBTextbooks($r); 626 my @textarray = map { $_->[0] } @{$texts}; 627 my %textlabels = (); 628 for my $ta (@{$texts}) { 629 $textlabels{$ta->[0]} = $ta->[1]." by ".$ta->[2]." (edition ".$ta->[3].")"; 630 } 631 if(! grep { $_ eq $r->param('library_textbook') } @textarray) { 632 $r->param('library_textbook', ''); 633 } 634 unshift @textarray, LIB2_DATA->{textbook}{all}; 635 my $atb = LIB2_DATA->{textbook}{all}; $textlabels{$atb} = LIB2_DATA->{textbook}{all}; 636 637 my $textchap_ref = WeBWorK::Utils::ListingDB::getDBTextbooks($r, 'textchapter'); 638 my @textchaps = map { $_->[0] } @{$textchap_ref}; 639 if(! grep { $_ eq $r->param('library_textchapter') } @textchaps) { 640 $r->param('library_textchapter', ''); 641 } 642 unshift @textchaps, LIB2_DATA->{textchapter}{all}; 643 644 my $textsec_ref = WeBWorK::Utils::ListingDB::getDBTextbooks($r, 'textsection'); 645 my @textsecs = map { $_->[0] } @{$textsec_ref}; 646 if(! grep { $_ eq $r->param('library_textsection') } @textsecs) { 647 $r->param('library_textsection', ''); 648 } 649 unshift @textsecs, LIB2_DATA->{textsection}{all}; 650 651 my %selected = (); 652 for my $j (qw( dbsection dbchapter dbsubject textbook textchapter textsection )) { 653 $selected{$j} = $r->param(LIB2_DATA->{$j}{name}) || LIB2_DATA->{$j}{all}; 654 } 655 656 my $text_popup = CGI::popup_menu(-name => 'library_textbook', 657 -values =>\@textarray, 658 -labels => \%textlabels, 659 -default=>$selected{textbook}, 660 -onchange=>"submit();return true"); 661 662 663 my $library_keywords = $r->param('library_keywords') || ''; 664 665 my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r); 666 667 my $count_line = WeBWorK::Utils::ListingDB::countDBListings($r); 668 if($count_line==0) { 669 $count_line = "There are no matching pg files"; 670 } else { 671 $count_line = "There are $count_line matching WeBWorK problem files"; 672 } 673 674 print CGI::div({-class=>"InfoPanel", -align=>"left"}, 675 CGI::hidden(-name=>"library_is_basic", -default=>2,-override=>1), 676 # Html done by hand since it is temporary 677 CGI::div({-colspan=>4, -align=>"center"}, 'All Selected Constraints Joined by "And"'), 678 CGI::div(["Subject:", 679 CGI::popup_menu(-name=> 'library_subjects', 680 -values=>\@subjs, 681 -default=> $selected{dbsubject}, 682 -onchange=>"submit();return true" 683 )]), 684 CGI::div({-colspan=>2, -align=>"right"}, 685 CGI::submit(-name=>"lib_select_subject", -value=>"Update Menus", 686 -style=> $right_button_style)), 687 CGI::div(["Chapter:", 688 CGI::popup_menu(-name=> 'library_chapters', 689 -values=>\@chaps, 690 -default=> $selected{dbchapter}, 691 -onchange=>"submit();return true" 692 )]), 693 CGI::div({-colspan=>2, -align=>"right"}, 694 CGI::submit(-name=>"library_reset", -value=>"Reset", 695 -style=>$right_button_style)), 696 CGI::div(["Section:", 697 CGI::popup_menu(-name=> 'library_sections', 698 -values=>\@sects, 699 -default=> $selected{dbsection}, 700 -onchange=>"submit();return true" 701 )]), 702 CGI::div({-colspan=>2, -align=>"right"}, 703 CGI::submit(-name=>"library_basic", -value=>"Basic Search", 704 -style=>$right_button_style)), 705 CGI::div(["Textbook:", $text_popup]), 706 CGI::div(["Text chapter:", 707 CGI::popup_menu(-name=> 'library_textchapter', 708 -values=>\@textchaps, 709 -default=> $selected{textchapter}, 710 -onchange=>"submit();return true" 711 )]), 712 CGI::div(["Text section:", 713 CGI::popup_menu(-name=> 'library_textsection', 714 -values=>\@textsecs, 715 -default=> $selected{textsection}, 716 -onchange=>"submit();return true" 717 )]), 718 CGI::div("Keywords:"),CGI::div({-colspan=>2}, 719 CGI::textfield(-name=>"library_keywords", 720 -default=>$library_keywords, 721 -override=>1, 722 -size=>40)), 723 CGI::div({-colspan=>3}, $view_problem_line), 724 CGI::div({-colspan=>3, -align=>"center"}, $count_line) 725 ); 726 727 } 728 729 730 ##### Version 4 is the set definition file panel 731 732 sub browse_setdef_panel { 733 my $self = shift; 734 my $r = $self->r; 735 my $ce = $r->ce; 736 my $library_selected = shift; 737 my $default_value = "Select a Set Definition File"; 738 # in the following line, the parens after sort are important. if they are 739 # omitted, sort will interpret get_set_defs as the name of the comparison 740 # function, and ($ce->{courseDirs}{templates}) as a single element list to 741 # be sorted. *barf* 742 my @list_of_set_defs = sort(get_set_defs($ce->{courseDirs}{templates})); 743 if(scalar(@list_of_set_defs) == 0) { 744 @list_of_set_defs = (NO_LOCAL_SET_STRING); 745 } elsif (not $library_selected or $library_selected eq $default_value) { 746 unshift @list_of_set_defs, $default_value; 747 $library_selected = $default_value; 748 } 749 my $view_problem_line = view_problems_line('view_setdef_set', 'View Problems', $self->r); 750 my $popupetc = CGI::popup_menu(-name=> 'library_sets', 751 -values=>\@list_of_set_defs, 752 -default=> $library_selected). 753 CGI::br(). $view_problem_line; 754 if($list_of_set_defs[0] eq NO_LOCAL_SET_STRING) { 755 $popupetc = "there are no set definition files in this course to look at." 756 } 757 print CGI::div({-class=>"InfoPanel", -align=>"left"}, "Browse from: ", 758 $popupetc 759 ); 760 } 761 762 sub make_mysets_row { 763 my $self = shift; 764 my $r = $self->r; 765 my $ce = $r->ce; 766 my %data = @_; 767 768 my $list_of_local_sets = $data{all_db_sets}; 769 my $have_local_sets = scalar(@$list_of_local_sets); 770 my $browse_which = 'browse_mysets'; 771 my $library_selected = $self->{current_myset_set}; 772 my $set_selected = $r->param('myset_sets'); 773 my $remember_local_set = $r->param('local_sets'); 774 775 ## Make buttons for additional problem libraries 776 #my $libs = ''; 777 #foreach my $lib (sort(keys(%problib))) { 778 # $libs .= ' '. CGI::submit(-name=>"browse_$lib", -value=>$problib{$lib}, 779 # ($browse_which eq "browse_$lib")? (-disabled=>1): ()) 780 # if (-d "$ce->{courseDirs}{templates}/$lib"); 781 #} 782 #$libs = CGI::br()."or Problems from".$libs if $libs ne ''; 783 784 my $these_widths = "width: 25ex"; 785 786 if($have_local_sets ==0) { 787 $list_of_local_sets = [NO_LOCAL_SET_STRING]; 788 } elsif (not defined($set_selected) or $set_selected eq "" 789 or $set_selected eq SELECT_SET_STRING) { 790 unshift @{$list_of_local_sets}, SELECT_SET_STRING; 791 $set_selected = SELECT_SET_STRING; 792 } 793 my $myjs = 'document.mainform.selfassign.value=confirm("Should I assign the new set to you now?\nUse OK for yes and Cancel for no.");true;'; 794 795 # Tidy this list up since it is used in two different places 796 if ($list_of_local_sets->[0] eq SELECT_SET_STRING) { 797 shift @{$list_of_local_sets}; 798 } 799 800 #print CGI::div(CGI::div({-bgcolor=>"black"})); 801 #print CGI::hr(); 802 803 $self->browse_mysets_panel($library_selected, $list_of_local_sets, $remember_local_set); 804 } 805 806 sub make_top_row { 807 my $self = shift; 808 my $r = $self->r; 809 my $ce = $r->ce; 810 my %data = @_; 811 812 my $list_of_local_sets = $data{all_db_sets}; 813 my $have_local_sets = scalar(@$list_of_local_sets); 814 my $browse_which = $data{browse_which}; 815 my $library_selected = $self->{current_library_set}; 816 my $set_selected = $r->param('local_sets'); 817 my (@dis1, @dis2, @dis3, @dis4) = (); 818 @dis1 = (-disabled=>1) if($browse_which eq 'browse_npl_library'); 819 @dis2 = (-disabled=>1) if($browse_which eq 'browse_local'); 820 @dis3 = (-disabled=>1) if($browse_which eq 'edit_mysets'); 821 @dis4 = (-disabled=>1) if($browse_which eq 'browse_setdefs'); 822 823 ## Make buttons for additional problem libraries 824 my $libs = ''; 825 foreach my $lib (sort(keys(%problib))) { 826 $libs .= ' '. CGI::submit(-name=>"browse_$lib", -value=>$problib{$lib}, 827 ($browse_which eq "browse_$lib")? (-disabled=>1): ()) 828 if (-d "$ce->{courseDirs}{templates}/$lib"); 829 } 830 $libs = CGI::br()."or Problems from".$libs if $libs ne ''; 831 832 my $these_widths = "width: 25ex"; 833 834 if($have_local_sets ==0) { 835 $list_of_local_sets = [NO_LOCAL_SET_STRING]; 836 } elsif (not defined($set_selected) or $set_selected eq "" 837 or $set_selected eq SELECT_SET_STRING) { 838 unshift @{$list_of_local_sets}, SELECT_SET_STRING; 839 $set_selected = SELECT_SET_STRING; 840 } 841 my $myjs = 'document.mainform.selfassign.value=confirm("Should I assign the new set to you now?\nUse OK for yes and Cancel for no.");true;'; 842 ## edited this, as a demo for the current set problem list 843 print CGI::div({-class=>"InfoPanel", -align=>"left"}, 844 CGI::submit(-name=>"new_local_set", -value=>"Create a New Set in This Course:", 845 -onclick=>$myjs 846 ), 847 " ", 848 CGI::textfield(-name=>"new_set_name", 849 -default=>"Name for new set here", 850 -override=>1, -size=>30), 851 ); 852 853 # Tidy this list up since it is used in two different places 854 if ($list_of_local_sets->[0] eq SELECT_SET_STRING) { 855 shift @{$list_of_local_sets}; 856 } 857 858 print CGI::div({-class=>"InfoPanel", -align=>"center"}, 859 "Browse ", 860 CGI::submit(-name=>"browse_npl_library", -value=>"National Problem Library", -style=>$these_widths, @dis1), 861 CGI::submit(-name=>"browse_local", -value=>"Local Problems", -style=>$these_widths, @dis2), 862 CGI::submit(-name=>"edit_mysets", -value=>"From This Course", -style=>$these_widths, @dis3), 863 CGI::submit(-name=>"browse_setdefs", -value=>"Set Definition Files", -style=>$these_widths, @dis4), 864 $libs, 865 ); 866 867 if ($browse_which eq 'browse_local') { 868 $self->browse_local_panel($library_selected); 869 } elsif ($browse_which eq 'edit_mysets') { 870 $self->edit_mysets_panel($library_selected, $list_of_local_sets); 871 } elsif ($browse_which eq 'browse_npl_library') { 872 $self->browse_library_panel(); 873 } elsif ($browse_which eq 'browse_setdefs') { 874 $self->browse_setdef_panel($library_selected); 875 } else { ## handle other problem libraries 876 $self->browse_local_panel($library_selected,$browse_which); 877 } 878 879 print CGI::div({-class=>"InfoPanel", -align=>"center"}, 880 CGI::submit(-name=>"select_all", -style=>$these_widths, 881 -value=>"Mark All For Adding"), 882 CGI::submit(-name=>"select_none", -style=>$these_widths, 883 -value=>"Clear All Marks"), 884 ), 885 CGI::div({}, 886 CGI::submit(-name=>"rerandomize", 887 -style=>$these_widths, 888 -value=>"Rerandomize"), 889 CGI::submit(-name=>"cleardisplay", 890 -style=>$these_widths, 891 -value=>"Clear Problem Display") 892 ); 893 } 894 895 sub make_data_row { 896 my $self = shift; 897 my $sourceFileName = shift; 898 my $pg = shift; 899 my $cnt = shift; 900 my $mark = shift || 0; 901 902 $sourceFileName =~ s|^./||; # clean up top ugliness 903 904 my $urlpath = $self->r->urlpath; 905 my $db = $self->r->db; 906 907 ## to set up edit and try links elegantly we want to know if 908 ## any target set is a gateway assignment or not 909 my $localSet = $self->r->param('local_sets'); 910 my $setRecord; 911 if ( defined($localSet) && $localSet ne SELECT_SET_STRING && 912 $localSet ne NO_LOCAL_SET_STRING ) { 913 $setRecord = $db->getGlobalSet( $localSet ); 914 } 915 my $isGatewaySet = ( defined($setRecord) && 916 $setRecord->assignment_type =~ /gateway/ ); 917 918 my $problem_output = $pg->{flags}->{error_flag} ? 919 CGI::div({class=>"ResultsWithError"}, CGI::em("This problem produced an error")) 920 : CGI::div({class=>"RenderSolo"}, $pg->{body_text}); 921 $problem_output .= $pg->{flags}->{comment} if($pg->{flags}->{comment}); 922 923 924 #if($self->{r}->param('browse_which') ne 'browse_npl_library') { 925 my $problem_seed = $self->{'problem_seed'} || 1234; 926 my $edit_link = CGI::a({href=>$self->systemLink( 927 $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", 928 courseID =>$urlpath->arg("courseID"), 929 setID=>"Undefined_Set", 930 problemID=>"1"), 931 params=>{sourceFilePath => "$sourceFileName", problemSeed=> $problem_seed} 932 ), target=>"WW_Editor"}, "Edit it" ); 933 934 my $displayMode = $self->r->param("mydisplayMode"); 935 $displayMode = $self->r->ce->{pg}->{options}->{displayMode} 936 if not defined $displayMode or $displayMode eq "None"; 937 my $module = ( $isGatewaySet ) ? "GatewayQuiz" : "Problem"; 938 my %pathArgs = ( courseID =>$urlpath->arg("courseID"), 939 setID=>"Undefined_Set" ); 940 $pathArgs{problemID} = "1" if ( ! $isGatewaySet ); 941 942 my $try_link = CGI::a({href=>$self->systemLink( 943 $urlpath->newFromModule("WeBWorK::ContentGenerator::$module", 944 %pathArgs ), 945 params =>{ 946 effectiveUser => scalar($self->r->param('user')), 947 editMode => "SetMaker", 948 problemSeed=> $problem_seed, 949 sourceFilePath => "$sourceFileName", 950 displayMode => $displayMode, 951 } 952 ), target=>"WW_View"}, "Try it"); 953 954 my %add_box_data = ( -id=>"trial$cnt" ,-name=>"trial$cnt",-value=>1,-label=>"Add this problem to the target set on the next update"); 955 #allow for a move command from one problem set to anoter 956 my $move_box_data; 957 if($self->r->param('edit_mysets_set')){ 958 $move_box_data = CGI::checkbox( -id=>"moved$cnt" ,-name=>"moved$cnt",-value=>1,,-override=>1,-label=>"Move this problem from this set to the target set on the next update"); 959 } 960 else{ 961 $move_box_data = ""; 962 } 963 if($mark & SUCCESS) { 964 $add_box_data{ -label } .= " (just added this problem)"; 965 } elsif($mark & ADDED) { 966 $add_box_data{ -checked } = 1; 967 } 968 969 if(!($self->{isInSet}{$sourceFileName})){ 970 971 print CGI::div({-align=>"left", -draggable=>"true", -href=>"#", -id=>"$cnt"}, 972 CGI::div({-style=>"background-color: #DDDDDD; margin: 0px auto"}, 973 CGI::span({-style=>"float:left ; text-align: left"},"File name: $sourceFileName "), 974 CGI::span({-style=>"float:right ; text-align: right"}, $edit_link, " ", $try_link) 975 ), CGI::br(), 976 CGI::checkbox(-id=>"hideme$cnt", -name=>"hideme$cnt",-value=>1,-label=>"Don't show this problem on the next update",-override=>1), 977 CGI::br(), 978 CGI::checkbox((%add_box_data),-override=>1), 979 $move_box_data, 980 CGI::hidden(-name=>"filetrial$cnt", -default=>$sourceFileName,-override=>1). 981 CGI::p($problem_output) 982 ); 983 } 984 else{ 985 print CGI::div({-class=>"used", -align=>"left", -draggable=>"true", -href=>"#", -id=>"$cnt"}, 986 CGI::div({-style=>"background-color: #AAAAA; margin: 0px auto"}, 987 CGI::span({-style=>"float:left ; text-align: left"},"File name: $sourceFileName "), 988 CGI::span({-style=>"float:right ; text-align: right"}, $edit_link, " ", $try_link) 989 ), CGI::br(), 990 CGI::checkbox(-id=>"hideme$cnt", -name=>"hideme$cnt",-value=>1,-label=>"Don't show this problem on the next update",-override=>1), 991 CGI::br(), 992 CGI::checkbox((%add_box_data),-override=>1), 993 $move_box_data, 994 CGI::hidden(-name=>"filetrial$cnt", -default=>$sourceFileName,-override=>1). 995 CGI::p($problem_output), 996 CGI::b("(This problem is in the target set)") 997 ); 998 } 999 } 1000 1001 sub make_myset_data_row { 1002 my $self = shift; 1003 my $sourceFileName = shift; 1004 my $pg = shift; 1005 my $cnt = shift; 1006 my $mark = shift || 0; 1007 1008 $sourceFileName =~ s|^./||; # clean up top ugliness 1009 1010 my $urlpath = $self->r->urlpath; 1011 my $db = $self->r->db; 1012 1013 ## to set up edit and try links elegantly we want to know if 1014 ## any target set is a gateway assignment or not 1015 my $localSet = $self->r->param('local_sets'); 1016 my $setRecord; 1017 if ( defined($localSet) && $localSet ne SELECT_SET_STRING && 1018 $localSet ne NO_LOCAL_SET_STRING ) { 1019 $setRecord = $db->getGlobalSet( $localSet ); 1020 } 1021 my $isGatewaySet = ( defined($setRecord) && 1022 $setRecord->assignment_type =~ /gateway/ ); 1023 1024 my $problem_output = $pg->{flags}->{error_flag} ? 1025 CGI::div({class=>"ResultsWithError"}, CGI::em("This problem produced an error")) 1026 : CGI::div({class=>"RenderSolo"}, $pg->{body_text}); 1027 $problem_output .= $pg->{flags}->{comment} if($pg->{flags}->{comment}); 1028 1029 1030 #if($self->{r}->param('browse_which') ne 'browse_npl_library') { 1031 my $problem_seed = $self->{'problem_seed'} || 1234; 1032 my $edit_link = CGI::a({href=>$self->systemLink( 1033 $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", 1034 courseID =>$urlpath->arg("courseID"), 1035 setID=>"Undefined_Set", 1036 problemID=>"1"), 1037 params=>{sourceFilePath => "$sourceFileName", problemSeed=> $problem_seed} 1038 ), target=>"WW_Editor"}, "Edit it" ); 1039 1040 my %delete_box_data = ( -id=>"deleted$cnt".'myset' ,-name=>"deleted$cnt",-value=>1,-label=>"Delete this problem from the target set on the next update"); 1041 1042 my $displayMode = $self->r->param("mydisplayMode"); 1043 $displayMode = $self->r->ce->{pg}->{options}->{displayMode} 1044 if not defined $displayMode or $displayMode eq "None"; 1045 my $module = ( $isGatewaySet ) ? "GatewayQuiz" : "Problem"; 1046 my %pathArgs = ( courseID =>$urlpath->arg("courseID"), 1047 setID=>"Undefined_Set" ); 1048 $pathArgs{problemID} = "1" if ( ! $isGatewaySet ); 1049 1050 my $try_link = CGI::a({href=>$self->systemLink( 1051 $urlpath->newFromModule("WeBWorK::ContentGenerator::$module", 1052 %pathArgs ), 1053 params =>{ 1054 effectiveUser => scalar($self->r->param('user')), 1055 editMode => "SetMaker", 1056 problemSeed=> $problem_seed, 1057 sourceFilePath => "$sourceFileName", 1058 displayMode => $displayMode, 1059 } 1060 ), target=>"WW_View"}, "Try it"); 1061 1062 print CGI::div({-class=>"problem myProblem", -draggable=>"true", -href=>"#", -id=>("$cnt".'myset')}, 1063 CGI::div({-style=>"background-color: #DDDDDD; margin: 0px auto"}, 1064 CGI::span({-style=>"float:left ; text-align: left"},"File name: $sourceFileName "), 1065 CGI::span({-style=>"float:right ; text-align: right"}, $edit_link, " ", $try_link) 1066 ), CGI::br(), 1067 CGI::br(), 1068 CGI::checkbox((%delete_box_data),-override=>1), 1069 CGI::hidden(-name=>"mysetfiletrial$cnt", -default=>$sourceFileName,-override=>1). 1070 CGI::p($problem_output), 1071 ); 1072 } 1073 1074 sub clear_default { 1075 my $r = shift; 1076 my $param = shift; 1077 my $default = shift; 1078 my $newvalue = $r->param($param) || ''; 1079 $newvalue = '' if($newvalue eq $default); 1080 $r->param($param, $newvalue); 1081 } 1082 1083 sub pre_header_initialize { 1084 my ($self) = @_; 1085 my $r = $self->r; 1086 ## For all cases, lets set some things 1087 $self->{error}=0; 1088 my $ce = $r->ce; 1089 my $db = $r->db; 1090 my $maxShown = $r->param('max_shown') || MAX_SHOW_DEFAULT; 1091 $maxShown = 10000000 if($maxShown eq 'All'); # let's hope there aren't more 1092 my $library_basic = $r->param('library_is_basic') || 1; 1093 $self->{problem_seed} = $r->param('problem_seed') || 1234; 1094 ## Fix some parameters 1095 for my $key (keys(%{ LIB2_DATA() })) { 1096 clear_default($r, LIB2_DATA->{$key}->{name}, LIB2_DATA->{$key}->{all} ); 1097 } 1098 ## Grab library sets to display from parameters list. We will modify this 1099 ## as we go through the if/else tree 1100 $self->{current_library_set} = $r->param('library_sets'); 1101 $self->{current_myset_set} = $r->param('myset_sets'); 1102 if (not defined($self->{current_myset_set}) 1103 or $self->{current_myset_set} eq "Select a Homework Set" 1104 or $self->{current_myset_set} eq NO_LOCAL_SET_STRING) { 1105 my @all_db_sets = $db->listGlobalSets; 1106 @all_db_sets = sortByName(undef, @all_db_sets); 1107 $self->{current_myset_set} = shift(@all_db_sets); 1108 } 1109 1110 ## These directories will have individual buttons 1111 %problib = %{$ce->{courseFiles}{problibs}} if $ce->{courseFiles}{problibs}; 1112 1113 my $userName = $r->param('user'); 1114 my $user = $db->getUser($userName); # checked 1115 die "record for user $userName (real user) does not exist." 1116 unless defined $user; 1117 my $authz = $r->authz; 1118 unless ($authz->hasPermissions($userName, "modify_problem_sets")) { 1119 return(""); # Error message already produced in the body 1120 } 1121 1122 ## Now one action we have to deal with here 1123 if ($r->param('edit_local')) { 1124 my $urlpath = $r->urlpath; 1125 my $db = $r->db; 1126 my $checkset = $db->getGlobalSet($r->param('local_sets')); 1127 if (not defined($checkset)) { 1128 $self->{error} = 1; 1129 $self->addbadmessage('You need to select a "Target Set" before you can edit it.'); 1130 } else { 1131 my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetDetail', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID")); 1132 my $url = $self->systemLink($page); 1133 $self->reply_with_redirect($url); 1134 } 1135 } 1136 1137 ## Next, lots of set up so that errors can be reported with message() 1138 1139 ############# List of problems we have already printed 1140 1141 $self->{past_problems} = get_past_problem_files($r); 1142 # if we don't end up reusing problems, this will be wiped out 1143 # if we do redisplay the same problems, we must adjust this accordingly 1144 my @past_marks = map {$_->[1]} @{$self->{past_problems}}; 1145 my $none_shown = scalar(@{$self->{past_problems}})==0; 1146 my @pg_files=(); 1147 my @myset_files=(); 1148 my $use_previous_problems = 1; 1149 my $first_shown = $r->param('first_shown') || 0; 1150 my $last_shown = $r->param('last_shown'); 1151 if (not defined($last_shown)) { 1152 $last_shown = -1; 1153 } 1154 my @all_past_list = (); # these are include requested, but not shown 1155 my $j = 0; 1156 while (defined($r->param("all_past_list$j"))) { 1157 push @all_past_list, $r->param("all_past_list$j"); 1158 $j++; 1159 } 1160 1161 ############# Default of which problem selector to display 1162 1163 my $browse_which = $r->param('browse_which') || 'browse_npl_library'; 1164 1165 1166 1167 ## check for problem lib buttons 1168 my $browse_lib = ''; 1169 foreach my $lib (keys %problib) { 1170 if ($r->param("browse_$lib")) { 1171 $browse_lib = "browse_$lib"; 1172 last; 1173 } 1174 } 1175 1176 1177 ########### Start the logic through if elsif elsif ... 1178 debug("browse_lib", $r->param("$browse_lib")); 1179 debug("browse_npl_library", $r->param("browse_npl_library")); 1180 debug("edit_mysets", $r->param("edit_mysets")); 1181 debug("browse_setdefs", $r->param("browse_setdefs")); 1182 ##### Asked to browse certain problems 1183 if ($browse_lib ne '') { 1184 $browse_which = $browse_lib; 1185 $self->{current_library_set} = ""; 1186 $use_previous_problems = 0; @pg_files = (); ## clear old problems 1187 } elsif ($r->param('browse_npl_library')) { 1188 $browse_which = 'browse_npl_library'; 1189 $self->{current_library_set} = ""; 1190 $use_previous_problems = 0; @pg_files = (); ## clear old problems 1191 } elsif ($r->param('browse_local')) { 1192 $browse_which = 'browse_local'; 1193 #$self->{current_library_set} = ""; 1194 $use_previous_problems = 0; @pg_files = (); ## clear old problems 1195 } elsif ($r->param('edit_mysets')) { 1196 $browse_which = 'edit_mysets'; 1197 $self->{current_library_set} = ""; 1198 $use_previous_problems = 0; @pg_files = (); ## clear old problems 1199 } elsif ($r->param('browse_setdefs')) { 1200 $browse_which = 'browse_setdefs'; 1201 $self->{current_library_set} = ""; 1202 $use_previous_problems = 0; @pg_files = (); ## clear old problems 1203 1204 ##### Change the seed value 1205 1206 } elsif ($r->param('rerandomize')) { 1207 $self->{problem_seed}= 1+$self->{problem_seed}; 1208 #$r->param('problem_seed', $problem_seed); 1209 $self->addbadmessage('Changing the problem seed for display, but there are no problems showing.') if $none_shown; 1210 1211 ##### Clear the display 1212 1213 } elsif ($r->param('cleardisplay')) { 1214 @pg_files = (); 1215 $use_previous_problems=0; 1216 $self->addbadmessage('The display was already cleared.') if $none_shown; 1217 1218 ##### View problems selected from the local list 1219 1220 } elsif ($r->param('view_local_set')) { 1221 1222 my $set_to_display = $self->{current_library_set}; 1223 if (not defined($set_to_display) or $set_to_display eq SELECT_LOCAL_STRING or $set_to_display eq "Found no directories containing problems") { 1224 $self->addbadmessage('You need to select a set to view.'); 1225 } else { 1226 $set_to_display = '.' if $set_to_display eq MY_PROBLEMS; 1227 $set_to_display = substr($browse_which,7) if $set_to_display eq MAIN_PROBLEMS; 1228 @pg_files = list_pg_files($ce->{courseDirs}->{templates}, 1229 "$set_to_display"); 1230 $use_previous_problems=0; 1231 } 1232 1233 ##### View problems selected from the a set in this course 1234 } elsif ($r->param('edit_mysets_set')){ 1235 1236 my $set_to_display = $self->{current_library_set}; 1237 debug("set_to_display is $set_to_display"); 1238 if (not defined($set_to_display) 1239 or $set_to_display eq "Select a Homework Set" 1240 or $set_to_display eq NO_LOCAL_SET_STRING) { 1241 $self->addbadmessage("You need to select a set from this course to view."); 1242 } else { 1243 # DBFIXME don't use ID list, use an iterator 1244 my @problemList = $db->listGlobalProblems($set_to_display); 1245 my $problem; 1246 @pg_files=(); 1247 for $problem (@problemList) { 1248 my $problemRecord = $db->getGlobalProblem($set_to_display, $problem); # checked 1249 die "global $problem for set $set_to_display not found." unless 1250 $problemRecord; 1251 push @pg_files, $problemRecord->source_file; 1252 1253 } 1254 @pg_files = sortByName(undef,@pg_files); 1255 $use_previous_problems=0; 1256 } 1257 1258 ##### View from the library database 1259 1260 } elsif ($r->param('lib_view')) { 1261 @pg_files=(); 1262 my @dbsearch = WeBWorK::Utils::ListingDB::getSectionListings($r); 1263 my ($result, $tolibpath); 1264 for $result (@dbsearch) { 1265 $tolibpath = "Library/$result->{path}/$result->{filename}"; 1266 1267 ## Too clunky!!!! 1268 push @pg_files, $tolibpath; 1269 } 1270 $use_previous_problems=0; 1271 1272 ##### View a set from a set*.def 1273 1274 } elsif ($r->param('view_setdef_set')) { 1275 1276 my $set_to_display = $self->{current_library_set}; 1277 debug("set_to_display is $set_to_display"); 1278 if (not defined($set_to_display) 1279 or $set_to_display eq "Select a Set Definition File" 1280 or $set_to_display eq NO_LOCAL_SET_STRING) { 1281 $self->addbadmessage("You need to select a set definition file to view."); 1282 } else { 1283 @pg_files= $self->read_set_def($set_to_display); 1284 } 1285 $use_previous_problems=0; 1286 1287 ##### Edit the current local homework set 1288 1289 } elsif ($r->param('edit_local')) { ## Jump to set edit page 1290 1291 ; # already handled 1292 1293 1294 ##### Make a new local homework set 1295 1296 } elsif ($r->param('new_local_set')) { 1297 if ($r->param('new_set_name') !~ /^[\w .-]*$/) { 1298 $self->addbadmessage("The name ".$r->param('new_set_name')." is not a valid set name. Use only letters, digits, -, _, and ."); 1299 } else { 1300 my $newSetName = $r->param('new_set_name'); 1301 # if we want to munge the input set name, do it here 1302 $newSetName =~ s/\s/_/g; 1303 debug("local_sets was ", $r->param('local_sets')); 1304 $r->param('local_sets',$newSetName); ## use of two parameter param 1305 debug("new value of local_sets is ", $r->param('local_sets')); 1306 my $newSetRecord = $db->getGlobalSet($newSetName); 1307 if (defined($newSetRecord)) { 1308 $self->addbadmessage("The set name $newSetName is already in use. 1309 Pick a different name if you would like to start a new set."); 1310 } else { # Do it! 1311 # DBFIXME use $db->newGlobalSet 1312 $newSetRecord = $db->{set}->{record}->new(); 1313 $newSetRecord->set_id($newSetName); 1314 $newSetRecord->set_header(""); 1315 $newSetRecord->hardcopy_header(""); 1316 $newSetRecord->open_date(time()+60*60*24*7); # in one week 1317 $newSetRecord->due_date(time()+60*60*24*7*2); # in two weeks 1318 $newSetRecord->answer_date(time()+60*60*24*7*3); # in three weeks 1319 eval {$db->addGlobalSet($newSetRecord)}; 1320 if ($@) { 1321 $self->addbadmessage("Problem creating set $newSetName<br> $@"); 1322 } else { 1323 $self->addgoodmessage("Set $newSetName has been created."); 1324 my $selfassign = $r->param('selfassign') || ""; 1325 $selfassign = "" if($selfassign =~ /false/i); # deal with javascript false 1326 if($selfassign) { 1327 $self->assignSetToUser($userName, $newSetRecord); 1328 $self->addgoodmessage("Set $newSetName was assigned to $userName."); 1329 } 1330 } 1331 } 1332 } 1333 1334 ##### Add selected problems to the current local set 1335 1336 } elsif ($r->param('update')) { 1337 ## first handle problems to be added before we hide them 1338 my($localSet, @selected); 1339 1340 my @add_pg_files = grep {(($_->[1] & ADDED)) != 0 } @{$self->{past_problems}}; 1341 my @add_selected = map {$_->[0]} @add_pg_files; 1342 1343 my @delete_pg_files = grep {(($_->[1] & DELETED)) != 0} @{$self->{past_problems}}; 1344 my @delete_selected = map {$_->[0]} @delete_pg_files; 1345 1346 my @move_pg_files = grep {(($_->[1] & MOVED)) != 0} @{$self->{past_problems}}; 1347 my @move_selected = map {$_->[0]} @move_pg_files; 1348 1349 my @action_files = grep {$_->[1] > 0 } @{$self->{past_problems}}; 1350 # There are now good reasons to do an update without selecting anything. 1351 #if(scalar(@action_files) == 0) { 1352 # $self->addbadmessage('Update requested, but no problems were marked.'); 1353 #} 1354 1355 if (scalar(@add_selected)>0) { # if some are to be added, they need a place to go 1356 $localSet = $r->param('myset_sets'); 1357 if (not defined($localSet) or 1358 $localSet eq SELECT_SET_STRING or 1359 $localSet eq NO_LOCAL_SET_STRING) { 1360 $self->addbadmessage('You are trying to add problems to something, 1361 but you did not select a "Target Set" name as a target.'); 1362 } else { 1363 my $newSetRecord = $db->getGlobalSet($localSet); 1364 if (not defined($newSetRecord)) { 1365 $self->addbadmessage("You are trying to add problems to $localSet, 1366 but that set does not seem to exist! I bet you used your \"Back\" button."); 1367 } else { 1368 my $addcount = add_selected($self, $db, $localSet); 1369 if($addcount > 0) { 1370 $self->addgoodmessage("Added $addcount problem".(($addcount>1)?'s':''). 1371 " to $localSet."); 1372 } 1373 } 1374 } 1375 } 1376 if (scalar(@delete_selected)>0) { # if some are to be added, they need a place to go 1377 $localSet = $r->param('myset_sets'); 1378 if (not defined($localSet) or 1379 $localSet eq SELECT_SET_STRING or 1380 $localSet eq NO_LOCAL_SET_STRING) { 1381 $self->addbadmessage('You are trying to add problems to something, 1382 but you did not select a "Target Set" name as a target.'); 1383 } else { 1384 my $newSetRecord = $db->getGlobalSet($localSet); 1385 if (not defined($newSetRecord)) { 1386 $self->addbadmessage("You are trying to delete problems to $localSet, 1387 but that set does not seem to exist! I bet you used your \"Back\" button."); 1388 } else { 1389 my $deletecount = delete_selected($self, $db, $localSet); 1390 if($deletecount > 0) { 1391 $self->addgoodmessage("Deleted $deletecount problem".(($deletecount>1)?'s':''). 1392 " to $localSet."); 1393 } 1394 } 1395 } 1396 } 1397 if (scalar(@move_selected)>0) { # if some are to be added, they need a place to go 1398 $localSet = $r->param('myset_sets'); 1399 my $otherSet = $self->{current_library_set}; 1400 if (not defined($localSet) or not defined($otherSet) or 1401 $localSet eq SELECT_SET_STRING or 1402 $localSet eq NO_LOCAL_SET_STRING) { 1403 $self->addbadmessage('You are trying to add problems to something, 1404 but you did not select a "Target Set" name as a target.'); 1405 } else { 1406 my $newSetRecord = $db->getGlobalSet($localSet); 1407 my $otherNewSetRecord = $db->getGlobalSet($otherSet); 1408 if (not defined($newSetRecord) or not defined($otherNewSetRecord)) { 1409 $self->addbadmessage("You are trying to move problems from $otherNewSetRecord to $localSet, 1410 but that set does not seem to exist! I bet you used your \"Back\" button."); 1411 } else { 1412 my $addcount = add_selected($self, $db, $localSet); 1413 my $deletecount = delete_selected($self, $db, $otherSet); 1414 if($addcount > 0) { 1415 $self->addgoodmessage("Added $addcount problem".(($addcount>1)?'s':''). 1416 " to $localSet."); 1417 } 1418 if($deletecount > 0) { 1419 $self->addgoodmessage("Deleted $deletecount problem".(($deletecount>1)?'s':''). 1420 " to $localSet."); 1421 } 1422 } 1423 } 1424 } 1425 ## now handle problems to be hidden 1426 1427 ## only keep the ones which are not hidden 1428 @pg_files = grep {($_->[1] & HIDDEN) ==0 } @{$self->{past_problems}}; 1429 @pg_files = grep {(($_->[1] & DELETED)) != 0 } @pg_files; 1430 @past_marks = map {$_->[1]} @pg_files; 1431 @pg_files = map {$_->[0]} @pg_files; 1432 @all_past_list = (@all_past_list[0..($first_shown-1)], 1433 @pg_files, 1434 @all_past_list[($last_shown+1)..(scalar(@all_past_list)-1)]); 1435 $last_shown = $first_shown+$maxShown -1; debug("last_shown 3: ", $last_shown); 1436 $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); debug("last_shown 4: ", $last_shown); 1437 1438 } elsif ($r->param('next_page')) { 1439 $first_shown = $last_shown+1; 1440 $last_shown = $first_shown+$maxShown-1; debug("last_shown 5: ", $last_shown); 1441 $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); debug("last_shown 6: ", $last_shown); 1442 @past_marks = (); 1443 } elsif ($r->param('prev_page')) { 1444 $last_shown = $first_shown-1; 1445 $first_shown = $last_shown - $maxShown+1; 1446 1447 $first_shown = 0 if($first_shown<0); 1448 @past_marks = (); 1449 1450 } elsif ($r->param('select_all')) { 1451 @past_marks = map {1} @past_marks; 1452 } elsif ($r->param('library_basic')) { 1453 $library_basic = 1; 1454 for my $jj (qw(textchapter textsection textbook)) { 1455 $r->param('library_'.$jj,''); 1456 } 1457 } elsif ($r->param('library_advanced')) { 1458 $library_basic = 2; 1459 } elsif ($r->param('library_reset')) { 1460 for my $jj (qw(chapters sections subjects textbook keywords)) { 1461 $r->param('library_'.$jj,''); 1462 } 1463 } elsif ($r->param('select_none')) { 1464 @past_marks = (); 1465 } else { 1466 #nothing 1467 } ##### end of the if elsif ... 1468 1469 my $default_set = $self->{current_myset_set}; 1470 #debug("set_to_display is $default_set"); 1471 if (not defined($default_set) 1472 or $default_set eq "Select a Homework Set" 1473 or $default_set eq NO_LOCAL_SET_STRING) { 1474 $self->addbadmessage("You need to select a set from this course to view."); 1475 } else { 1476 # DBFIXME don't use ID list, use an iterator 1477 my @problemList = $db->listGlobalProblems($default_set); 1478 my $problem; 1479 @myset_files=(); 1480 for $problem (@problemList) { 1481 my $problemRecord = $db->getGlobalProblem($default_set, $problem); # checked 1482 die "global $problem for set $default_set not found." unless 1483 $problemRecord; 1484 push @myset_files, $problemRecord->source_file; 1485 1486 } 1487 @myset_files = sortByName(undef,@myset_files); 1488 $use_previous_problems=0; 1489 } 1490 1491 ############# List of local sets 1492 1493 # DBFIXME sorting in database, please! 1494 my @all_db_sets = $db->listGlobalSets; 1495 @all_db_sets = sortByName(undef, @all_db_sets); 1496 1497 if ($use_previous_problems) { 1498 @pg_files = @all_past_list; 1499 } else { 1500 $first_shown = 0; 1501 $last_shown = scalar(@pg_files)<$maxShown ? scalar(@pg_files) : $maxShown; 1502 $last_shown--; # to make it an array index 1503 @past_marks = (); 1504 } 1505 ############# Now store data in self for retreival by body 1506 $self->{first_shown} = $first_shown; 1507 $self->{last_shown} = $last_shown; 1508 $self->{browse_which} = $browse_which; 1509 #$self->{problem_seed} = $problem_seed; 1510 $self->{pg_files} = \@pg_files; 1511 $self->{myset_files} = \@myset_files; 1512 $self->{past_marks} = \@past_marks; 1513 $self->{all_db_sets} = \@all_db_sets; 1514 $self->{library_basic} = $library_basic; 1515 debug("past_marks is ", join(" ", @{$self->{past_marks}})); 1516 } 1517 1518 1519 sub title { 1520 return "Library Browser v2"; 1521 } 1522 1523 # hide view options panel since it distracts from SetMaker's built-in view options 1524 sub options { 1525 return ""; 1526 } 1527 1528 sub head { 1529 print '<script src="/webwork2_files/js/dnd.js"></script>'; 1530 print '<link rel="stylesheet" type="text/css" href="/webwork2_files/css/setmaker2.css" />'; 1531 print '<script>window.addEventListener("load", setup, false);</script>'; 1532 return ""; 1533 } 1534 1535 sub body { 1536 my ($self) = @_; 1537 1538 my $r = $self->r; 1539 my $ce = $r->ce; # course environment 1540 my $db = $r->db; # database 1541 my $j; # garden variety counter 1542 1543 my $userName = $r->param('user'); 1544 1545 my $user = $db->getUser($userName); # checked 1546 die "record for user $userName (real user) does not exist." 1547 unless defined $user; 1548 1549 ### Check that this is a professor 1550 my $authz = $r->authz; 1551 unless ($authz->hasPermissions($userName, "modify_problem_sets")) { 1552 print "User $userName returned " . 1553 $authz->hasPermissions($user, "modify_problem_sets") . 1554 " for permission"; 1555 return(CGI::div({class=>'ResultsWithError'}, 1556 CGI::em("You are not authorized to access the Instructor tools."))); 1557 } 1558 1559 my $showHints = $r->param('showHints'); 1560 my $showSolutions = $r->param('showSolutions'); 1561 1562 ########## Extract information computed in pre_header_initialize 1563 1564 my $first_shown = $self->{first_shown}; 1565 my $last_shown = $self->{last_shown}; 1566 my $browse_which = $self->{browse_which}; 1567 my $problem_seed = $self->{problem_seed}||1234; 1568 my @pg_files = @{$self->{pg_files}}; 1569 my @myset_files =@{$self->{myset_files}}; 1570 my @all_db_sets = @{$self->{all_db_sets}}; 1571 1572 my @pg_html; 1573 if ($last_shown >= $first_shown) { 1574 @pg_html = renderProblems( 1575 r=> $r, 1576 user => $user, 1577 problem_list => [@pg_files[$first_shown..$last_shown]], 1578 displayMode => $r->param('mydisplayMode'), 1579 showHints => $showHints, 1580 showSolutions => $showSolutions, 1581 ); 1582 } 1583 my @myset_html; 1584 my $displayModePlaceholder; 1585 if (not defined($r->param('mydisplayMode'))){ 1586 $displayModePlaceholder = "None"; 1587 } 1588 else{ 1589 $displayModePlaceholder = $r->param('mydisplayMode'); 1590 } 1591 if (scalar(@myset_files) >= $first_shown) { 1592 @myset_html = renderProblems( 1593 r=> $r, 1594 user => $user, 1595 problem_list => [@myset_files[$first_shown..(scalar(@myset_files)-1)]], 1596 displayMode => $displayModePlaceholder, 1597 showHints => $showHints, 1598 showSolutions => $showSolutions, 1599 ); 1600 } 1601 1602 my %isInSet; 1603 my $setName = $r->param("myset_sets"); 1604 if ($setName) { 1605 # DBFIXME where clause, iterator 1606 # DBFIXME maybe instead of hashing here, query when checking source files? 1607 # DBFIXME definitely don't need to be making full record objects 1608 # DBFIXME SELECT source_file FROM whatever_problem WHERE set_id=? GROUP BY source_file ORDER BY NULL; 1609 # DBFIXME (and stick result directly into hash) 1610 foreach my $problem ($db->listGlobalProblems($setName)) { 1611 my $problemRecord = $db->getGlobalProblem($setName, $problem); 1612 $isInSet{$problemRecord->source_file} = 1; 1613 } 1614 } 1615 $self->{isInSet} = \%isInSet; 1616 my $jj; 1617 ########## Top part 1618 print '<div id="editor-form">'; 1619 1620 print CGI::start_form({-method=>"POST", -action=>$r->uri, -name=>'mainform'}), 1621 $self->hidden_authen_fields; 1622 print '<div id="mysets">'; 1623 ######### Table of mysets problems 1624 $self->make_mysets_row('all_db_sets'=>\@all_db_sets); 1625 print '<div class="problemList">'; 1626 for ($jj=0; $jj<scalar(@myset_html); $jj++) { 1627 $myset_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||; 1628 $self->make_myset_data_row($myset_files[$jj+$first_shown], $myset_html[$jj], $jj+1, $self->{past_marks}->[$jj]); 1629 } 1630 print '</div>'; 1631 #print CGI::end_table(); 1632 print '</div>'; 1633 1634 print '<div id="setmaker_library">'; 1635 #CGI::start_table({-id=>'setmaker_table', -border=>2}); 1636 $self->make_top_row('all_db_sets'=>\@all_db_sets, 1637 'browse_which'=> $browse_which); 1638 1639 print CGI::hidden(-name=>'browse_which', -value=>$browse_which,-override=>1), 1640 CGI::hidden(-name=>'problem_seed', -value=>$problem_seed, -override=>1); 1641 for ($j = 0 ; $j < scalar(@pg_files) ; $j++) { 1642 print CGI::hidden(-name=>"all_past_list$j", -value=>$pg_files[$j],-override=>1); 1643 } 1644 1645 print CGI::hidden(-name=>'first_shown', -value=>$first_shown,-override=>1); 1646 1647 print CGI::hidden(-name=>'last_shown', -value=>$last_shown, -override=>1); 1648 1649 print '<div class="problemList">'; 1650 ########## Now print problems 1651 for ($jj=0; $jj<scalar(@pg_html); $jj++) { 1652 $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||; 1653 $self->make_data_row($pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1, $self->{past_marks}->[$jj]); 1654 #$self->make_data_row($pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1, $self->{past_marks}->[$jj+$first_shown]); #MEG 1655 } 1656 print '</div>'; 1657 ########## Finish things off 1658 #print CGI::end_table(); 1659 my ($next_button, $prev_button) = ("", ""); 1660 if ($first_shown > 0) { 1661 $prev_button = CGI::submit(-name=>"prev_page", -style=>"width:15ex", 1662 -value=>"Previous page"); 1663 } 1664 if ((1+$last_shown)<scalar(@pg_files)) { 1665 $next_button = CGI::submit(-name=>"next_page", -style=>"width:15ex", 1666 -value=>"Next page"); 1667 } 1668 if (scalar(@pg_files)>0) { 1669 print CGI::p(($first_shown+1)."-".($last_shown+1)." of ".scalar(@pg_files). 1670 " shown.", $prev_button, " ", $next_button, 1671 CGI::submit(-name=>"update", -style=>"width:15ex; font-weight:bold", 1672 -value=>"Update Set")); 1673 } 1674 #close library_set 1675 print '</div>'; 1676 #close form-editor 1677 print '</div>'; 1678 1679 print '<div style="clear:both;"></div>'; 1680 1681 1682 # if($first_shown>0 or (1+$last_shown)<scalar(@pg_files)) { 1683 1684 # } 1685 print CGI::endform(), "\n"; 1686 1687 return ""; 1688 } 1689 1690 =head1 AUTHOR 1691 1692 Written by John Jones, jj (at) asu.edu. 1693 Edited by David Gage 1694 1695 =cut 1696 1697 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |