[system] / branches / gage_dev / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / ProblemSetDetail.pm Repository:
ViewVC logotype

Annotation of /branches/gage_dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4846 - (view) (download) (as text)
Original Path: trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm

1 : toenail 2794 ################################################################################
2 :     # WeBWorK Online Homework Delivery System
3 : sh002i 3973 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/
4 : toenail 2794 #
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 :     package WeBWorK::ContentGenerator::Instructor::ProblemSetDetail;
18 :     use base qw(WeBWorK::ContentGenerator::Instructor);
19 :    
20 :     =head1 NAME
21 :    
22 :     WeBWorK::ContentGenerator::Instructor::ProblemSetDetail - Edit general set and specific user/set information as well as problem information
23 :    
24 :     =cut
25 :    
26 :     use strict;
27 :     use warnings;
28 : gage 4234 #use CGI qw(-nosticky );
29 :     use WeBWorK::CGI;
30 : toenail 2816 use WeBWorK::HTML::ComboBox qw/comboBox/;
31 :     use WeBWorK::Utils qw(readDirectory list2hash listFilesRecursive max);
32 : toenail 2794 use WeBWorK::Utils::Tasks qw(renderProblems);
33 : toenail 2901 use WeBWorK::Debug;
34 : toenail 2794
35 :     # Important Note: the following two sets of constants may seem similar
36 :     # but they are functionally and semantically different
37 :    
38 :     # these constants determine which fields belong to what type of record
39 : glarose 4693 use constant SET_FIELDS => [qw(set_header hardcopy_header open_date due_date answer_date published assignment_type attempts_per_version version_time_limit versions_per_interval time_interval problem_randorder problems_per_page hide_score hide_work)];
40 : toenail 2794 use constant PROBLEM_FIELDS =>[qw(source_file value max_attempts)];
41 :     use constant USER_PROBLEM_FIELDS => [qw(problem_seed status num_correct num_incorrect)];
42 :    
43 :     # these constants determine what order those fields should be displayed in
44 :     use constant HEADER_ORDER => [qw(set_header hardcopy_header)];
45 :     use constant PROBLEM_FIELD_ORDER => [qw(problem_seed status value max_attempts attempted last_answer num_correct num_incorrect)];
46 :    
47 : glarose 3377 # we exclude the gateway set fields from the set field order, because they
48 :     # are only displayed for sets that are gateways. this results in a bit of
49 :     # convoluted logic below, but it saves burdening people who are only using
50 :     # homework assignments with all of the gateway parameters
51 : glarose 4693 # FIXME: in the long run, we may want to let hide_score and hide_work be
52 :     # FIXME: set for non-gateway assignments. right now (11/30/06) they are
53 :     # FIXME: only used for gateways
54 : glarose 3377 use constant SET_FIELD_ORDER => [qw(open_date due_date answer_date published assignment_type)];
55 : glarose 4693 use constant GATEWAY_SET_FIELD_ORDER => [qw(attempts_per_version version_time_limit time_interval versions_per_interval problem_randorder problems_per_page hide_score hide_work)];
56 : glarose 3377
57 : toenail 2794 # this constant is massive hash of information corresponding to each db field.
58 :     # override indicates for how many students at a time a field can be overridden
59 :     # this hash should make it possible to NEVER have explicitly: if (somefield) { blah() }
60 :     #
61 :     # All but name are optional
62 :     # some_field => {
63 :     # name => "Some Field",
64 :     # type => "edit", # edit, choose, hidden, view - defines how the data is displayed
65 :     # size => "50", # size of the edit box (if any)
66 :     # override => "none", # none, one, any, all - defines for whom this data can/must be overidden
67 :     # module => "problem_list", # WeBWorK module
68 :     # default => 0 # if a field cannot default to undefined/empty what should it default to
69 :     # labels => { # special values can be hashed to display labels
70 :     # 1 => "Yes",
71 :     # 0 => "No",
72 :     # },
73 : gage 3790
74 :     use constant BLANKPROBLEM => 'blankProblem.pg';
75 :    
76 : toenail 2794 use constant FIELD_PROPERTIES => {
77 :     # Set information
78 :     set_header => {
79 :     name => "Set Header",
80 :     type => "edit",
81 :     size => "50",
82 :     override => "all",
83 :     module => "problem_list",
84 :     default => "",
85 :     },
86 :     hardcopy_header => {
87 :     name => "Hardcopy Header",
88 :     type => "edit",
89 :     size => "50",
90 :     override => "all",
91 :     module => "hardcopy_preselect_set",
92 :     default => "",
93 :     },
94 :     open_date => {
95 :     name => "Opens",
96 :     type => "edit",
97 : toenail 2901 size => "26",
98 : toenail 2794 override => "any",
99 : toenail 2841 labels => {
100 : toenail 3061 #0 => "None Specified",
101 : toenail 2841 "" => "None Specified",
102 :     },
103 : toenail 2794 },
104 :     due_date => {
105 :     name => "Answers Due",
106 :     type => "edit",
107 : toenail 2901 size => "26",
108 : toenail 2794 override => "any",
109 : toenail 2841 labels => {
110 : toenail 3061 #0 => "None Specified",
111 : toenail 2841 "" => "None Specified",
112 :     },
113 : toenail 2794 },
114 :     answer_date => {
115 :     name => "Answers Available",
116 :     type => "edit",
117 : toenail 2901 size => "26",
118 : toenail 2794 override => "any",
119 : toenail 2841 labels => {
120 : toenail 3061 #0 => "None Specified",
121 : toenail 2841 "" => "None Specified",
122 :     },
123 : toenail 2794 },
124 :     published => {
125 :     name => "Visible to Students",
126 :     type => "choose",
127 :     override => "all",
128 :     choices => [qw( 0 1 )],
129 :     labels => {
130 :     1 => "Yes",
131 :     0 => "No",
132 :     },
133 :     },
134 : glarose 3377 assignment_type => {
135 :     name => "Assignment type",
136 :     type => "choose",
137 :     override => "all",
138 :     choices => [qw( default gateway proctored_gateway )],
139 :     labels => { default => "homework",
140 :     gateway => "gateway/quiz",
141 :     proctored_gateway => "proctored gateway/quiz",
142 :     },
143 :     },
144 :     attempts_per_version => {
145 :     name => "Attempts per Version (untested for > 1)",
146 :     type => "edit",
147 :     size => "3",
148 :     override => "all",
149 :     # labels => { "" => 1 },
150 :     },
151 :     version_time_limit => {
152 :     name => "Test Time Limit (sec)",
153 :     type => "edit",
154 :     size => "4",
155 : glarose 3853 override => "any",
156 : glarose 3377 labels => { "" => 0 }, # I'm not sure this is quite right
157 :     },
158 :     time_interval => {
159 :     name => "Time Interval for New Versions (sec)",
160 :     type => "edit",
161 :     size => "5",
162 :     override => "all",
163 :     labels => { "" => 0 },
164 :     },
165 :     versions_per_interval => {
166 :     name => "Number of New Versions per Time Interval (0=infty)",
167 :     type => "edit",
168 :     size => "3",
169 :     override => "all",
170 : glarose 4411 default => "0",
171 :     # labels => { "" => 0 },
172 : glarose 3377 # labels => { "" => 1 },
173 :     },
174 :     problem_randorder => {
175 :     name => "Order Problems Randomly",
176 :     type => "choose",
177 :     choices => [qw( 0 1 )],
178 :     override => "all",
179 :     labels => { 0 => "No", 1 => "Yes" },
180 :     },
181 : glarose 4306 problems_per_page => {
182 :     name => "Number of Problems per Page (0=all)",
183 :     type => "edit",
184 :     size => "3",
185 :     override => "all",
186 : glarose 4411 default => "0",
187 :     # labels => { "" => 0 },
188 : glarose 4306 },
189 : glarose 4693 hide_score => {
190 :     name => "Show score on finished assignments",
191 :     type => "choose",
192 :     choices => [ qw(0 1) ],
193 :     override => "all",
194 :     labels => { 0 => "Yes", 1 => "No" },
195 :     },
196 :     hide_work => {
197 :     name => "Show student work on finished assignments",
198 :     type => "choose",
199 :     choices => [ qw(0 1) ],
200 :     override => "all",
201 :     labels => { 0 => "Yes", 1 => "No" },
202 :     },
203 : toenail 2794 # Problem information
204 :     source_file => {
205 :     name => "Source File",
206 :     type => "edit",
207 :     size => 50,
208 :     override => "any",
209 :     default => "",
210 :     },
211 :     value => {
212 :     name => "Weight",
213 :     type => "edit",
214 : toenail 2901 size => 6,
215 : toenail 2794 override => "any",
216 :     },
217 :     max_attempts => {
218 :     name => "Max attempts",
219 :     type => "edit",
220 : toenail 2901 size => 6,
221 : toenail 2794 override => "any",
222 :     labels => {
223 :     "-1" => "unlimited",
224 :     },
225 :     },
226 :     problem_seed => {
227 :     name => "Seed",
228 :     type => "edit",
229 : toenail 2901 size => 6,
230 : toenail 2794 override => "one",
231 :    
232 :     },
233 :     status => {
234 :     name => "Status",
235 :     type => "edit",
236 : toenail 2901 size => 6,
237 :     override => "one",
238 : toenail 2794 default => 0,
239 :     },
240 :     attempted => {
241 :     name => "Attempted",
242 :     type => "hidden",
243 :     override => "none",
244 :     choices => [qw( 0 1 )],
245 :     labels => {
246 :     1 => "Yes",
247 :     0 => "No",
248 :     },
249 :     default => 0,
250 :     },
251 :     last_answer => {
252 :     name => "Last Answer",
253 :     type => "hidden",
254 :     override => "none",
255 :     },
256 :     num_correct => {
257 :     name => "Correct",
258 :     type => "hidden",
259 :     override => "none",
260 :     default => 0,
261 :     },
262 :     num_incorrect => {
263 :     name => "Incorrect",
264 :     type => "hidden",
265 :     override => "none",
266 :     default => 0,
267 :     },
268 :     };
269 :    
270 :     # Create a table of fields for the given parameters, one row for each db field
271 :     # if only the setID is included, it creates a table of set information
272 :     # if the problemID is included, it creates a table of problem information
273 :     sub FieldTable {
274 : sh002i 2913 my ($self, $userID, $setID, $problemID, $globalRecord, $userRecord) = @_;
275 : toenail 2794
276 :     my $r = $self->r;
277 :     my @editForUser = $r->param('editForUser');
278 :     my $forUsers = scalar(@editForUser);
279 :     my $forOneUser = $forUsers == 1;
280 :    
281 :     my @fieldOrder;
282 : glarose 3377 my $gwoutput = '';
283 : toenail 2794 if (defined $problemID) {
284 :     @fieldOrder = @{ PROBLEM_FIELD_ORDER() };
285 :     } else {
286 :     @fieldOrder = @{ SET_FIELD_ORDER() };
287 : glarose 3377
288 :     # gateway data fields are included only if the set is a gateway
289 :     if ( $globalRecord->assignment_type() =~ /gateway/ ) {
290 : glarose 3853 my $gwhdr = "\n<!-- begin gwoutput table -->\n";
291 :     my $nF = 0;
292 :    
293 :     foreach my $gwfield ( @{ GATEWAY_SET_FIELD_ORDER() } ) {
294 :     my @fieldData =
295 :     ($self->FieldHTML($userID, $setID, $problemID,
296 :     $globalRecord, $userRecord,
297 :     $gwfield));
298 : gage 4063 if ( @fieldData && defined($fieldData[1]) and $fieldData[1] ne '' ) {
299 : glarose 3853 $nF = @fieldData if ( @fieldData > $nF );
300 :     $gwoutput .= CGI::Tr({}, CGI::td({}, [@fieldData]));
301 : glarose 3377 }
302 : glarose 3853 }
303 :     $gwhdr .= CGI::Tr({},CGI::td({colspan=>$nF},
304 :     CGI::em("Gateway parameters")))
305 :     if ( $nF );
306 :     $gwoutput = "$gwhdr$gwoutput\n" .
307 :     "<!-- end gwoutput table -->\n";
308 : glarose 3377 }
309 : toenail 2794 }
310 :    
311 :     my $output = CGI::start_table({border => 0, cellpadding => 1});
312 : sh002i 2948 if ($forUsers) {
313 : gage 4258 $output .= CGI::Tr({},
314 : gage 2952 CGI::th({colspan=>"2"}, "&nbsp;"),
315 : toenail 3061 CGI::th({colspan=>"1"}, "User Values"),
316 :     CGI::th({}, "Class values"),
317 : sh002i 2948 );
318 :     }
319 :    
320 : toenail 2794 foreach my $field (@fieldOrder) {
321 :     my %properties = %{ FIELD_PROPERTIES()->{$field} };
322 :     unless ($properties{type} eq "hidden") {
323 : glarose 3377 $output .= CGI::Tr({}, CGI::td({}, [$self->FieldHTML($userID, $setID, $problemID, $globalRecord, $userRecord, $field)])) . "\n";
324 : toenail 2794 }
325 : glarose 3377 # this is a rather artifical addition to include gateway fields, which we
326 :     # only want to show for gateways
327 : glarose 3853 $output .= "$gwoutput\n"
328 : glarose 3377 if ( $field eq 'assignment_type' &&
329 :     $globalRecord->assignment_type() =~ /gateway/ );
330 : toenail 2794 }
331 :    
332 :     if (defined $problemID) {
333 : sh002i 2913 #my $problemRecord = $r->{db}->getUserProblem($userID, $setID, $problemID);
334 :     my $problemRecord = $userRecord; # we get this from the caller, hopefully
335 : toenail 2794 $output .= CGI::Tr({}, CGI::td({}, ["","Attempts", ($problemRecord->num_correct || 0) + ($problemRecord->num_incorrect || 0)])) if $forOneUser;
336 :     }
337 :     $output .= CGI::end_table();
338 :    
339 :     return $output;
340 :     }
341 :    
342 :     # Returns a list of information and HTML widgets
343 :     # for viewing and editing the specified db fields
344 :     # if only the setID is included, it creates a list of set information
345 :     # if the problemID is included, it creates a list of problem information
346 :     sub FieldHTML {
347 : sh002i 2913 my ($self, $userID, $setID, $problemID, $globalRecord, $userRecord, $field) = @_;
348 : toenail 2794
349 :     my $r = $self->r;
350 :     my $db = $r->db;
351 :     my @editForUser = $r->param('editForUser');
352 :     my $forUsers = scalar(@editForUser);
353 :     my $forOneUser = $forUsers == 1;
354 :    
355 : sh002i 2913 #my ($globalRecord, $userRecord, $mergedRecord);
356 :     #if (defined $problemID) {
357 :     # $globalRecord = $db->getGlobalProblem($setID, $problemID);
358 :     # $userRecord = $db->getUserProblem($userID, $setID, $problemID);
359 :     # #$mergedRecord = $db->getMergedProblem($userID, $setID, $problemID); # never used --sam
360 :     #} else {
361 :     # $globalRecord = $db->getGlobalSet($setID);
362 :     # $userRecord = $db->getUserSet($userID, $setID);
363 :     # #$mergedRecord = $db->getMergedSet($userID, $setID); # never user --sam
364 :     #}
365 : toenail 2794
366 :     return "No data exists for set $setID and problem $problemID" unless $globalRecord;
367 :     return "No user specific data exists for user $userID" if $forOneUser and $globalRecord and not $userRecord;
368 :    
369 :     my %properties = %{ FIELD_PROPERTIES()->{$field} };
370 :     my %labels = %{ $properties{labels} };
371 :     return "" if $properties{type} eq "hidden";
372 :     return "" if $properties{override} eq "one" && not $forOneUser;
373 :     return "" if $properties{override} eq "none" && not $forOneUser;
374 :     return "" if $properties{override} eq "all" && $forUsers;
375 :    
376 :     my $edit = ($properties{type} eq "edit") && ($properties{override} ne "none");
377 :     my $choose = ($properties{type} eq "choose") && ($properties{override} ne "none");
378 :    
379 :     my $globalValue = $globalRecord->{$field};
380 : gage 3046 # use defined instead of value in order to allow 0 to printed, e.g. for the 'value' field
381 :     $globalValue = (defined($globalValue)) ? ($labels{$globalValue || ""} || $globalValue) : "";
382 : toenail 2794 my $userValue = $userRecord->{$field};
383 : gage 3046 $userValue = (defined($userValue)) ? ($labels{$userValue || ""} || $userValue) : "";
384 : toenail 2794
385 :     if ($field =~ /_date/) {
386 : toenail 3061 $globalValue = $self->formatDateTime($globalValue) if defined $globalValue && $globalValue ne $labels{""};
387 :     $userValue = $self->formatDateTime($userValue) if defined $userValue && $userValue ne $labels{""};
388 : toenail 2794 }
389 :    
390 :     # check to make sure that a given value can be overridden
391 :     my %canOverride = map { $_ => 1 } (@{ PROBLEM_FIELDS() }, @{ SET_FIELDS() });
392 :     my $check = $canOverride{$field};
393 :    
394 :     # $recordType is a shorthand in the return statement for problem or set
395 :     # $recordID is a shorthand in the return statement for $problemID or $setID
396 :     my $recordType = "";
397 :     my $recordID = "";
398 :     if (defined $problemID) {
399 :     $recordType = "problem";
400 :     $recordID = $problemID;
401 :     } else {
402 :     $recordType = "set";
403 :     $recordID = $setID;
404 :     }
405 :    
406 :     # $inputType contains either an input box or a popup_menu for changing a given db field
407 :     my $inputType = "";
408 :     if ($edit) {
409 :     $inputType = CGI::input({
410 :     name => "$recordType.$recordID.$field",
411 : toenail 2834 value => $r->param("$recordType.$recordID.$field") || ($forUsers ? $userValue : $globalValue),
412 : toenail 2794 size => $properties{size} || 5,
413 :     });
414 :     } elsif ($choose) {
415 :     # Note that in popup menus, you're almost guaranteed to have the choices hashed to labels in %properties
416 :     # but $userValue and and $globalValue are the values in the hash not the keys
417 :     # so we have to use the actual db record field values to select our default here.
418 :     $inputType = CGI::popup_menu({
419 :     name => "$recordType.$recordID.$field",
420 :     values => $properties{choices},
421 :     labels => \%labels,
422 : toenail 2834 default => $r->param("$recordType.$recordID.$field") || ($forUsers ? $userRecord->$field : $globalRecord->$field),
423 : toenail 2794 });
424 :     }
425 :    
426 :     return (($forUsers && $edit && $check) ? CGI::checkbox({
427 :     type => "checkbox",
428 :     name => "$recordType.$recordID.$field.override",
429 :     label => "",
430 :     value => $field,
431 : toenail 3061 checked => $r->param("$recordType.$recordID.$field.override") || ($userValue ne ($labels{""} || "") ? 1 : 0),
432 : toenail 2794 }) : "",
433 :     $properties{name},
434 :     $inputType,
435 :     $forUsers ? " $globalValue" : "",
436 :     );
437 :     }
438 :    
439 :     # creates a popup menu of all possible problem numbers (for possible rearranging)
440 :     sub problem_number_popup {
441 :     my $num = shift;
442 :     my $total = shift;
443 :     return (CGI::popup_menu(-name => "problem_num_$num",
444 :     -values => [1..$total],
445 :     -default => $num));
446 :     }
447 :    
448 :     # handles rearrangement necessary after changes to problem ordering
449 :     sub handle_problem_numbers {
450 :     my $newProblemNumbersref = shift;
451 :     my %newProblemNumbers = %$newProblemNumbersref;
452 :     my $maxNum = shift;
453 :     my $db = shift;
454 : toenail 2816 my $setID = shift;
455 : toenail 2794 my $force = shift || 0;
456 :     my @sortme=();
457 :     my ($j, $val);
458 :    
459 : sh002i 3802 # keys are current problem numbers, values are target problem numbers
460 : toenail 2794 foreach $j (keys %newProblemNumbers) {
461 : sh002i 3802 # we don't want to act unless all problems have been assigned a new problem number, so if any have not, return
462 : toenail 2794 return "" if (not defined $newProblemNumbers{"$j"});
463 : sh002i 3802 # if the problem has been given a new number, we reduce the "score" of the problem by the original number of the problem
464 :     # when multiple problems are assigned the same number, this results in the last one ending up first -- FIXME?
465 : toenail 2794 if ($newProblemNumbers{"$j"} != $j) {
466 : sh002i 3802 # force always gets set if reordering is done, so don't expect to be able to delete a problem,
467 :     # reorder some other problems, and end up with a hole -- FIXME
468 : toenail 2794 $force = 1;
469 :     $val = 1000 * $newProblemNumbers{$j} - $j;
470 :     } else {
471 :     $val = 1000 * $newProblemNumbers{$j};
472 :     }
473 : sh002i 3802 # store a mapping between current problem number and score (based on currnet and new problem number)
474 : toenail 2794 push @sortme, [$j, $val];
475 : sh002i 3802 # replace new problem numbers in hash with the (global) problems themselves
476 : toenail 2816 $newProblemNumbers{$j} = $db->getGlobalProblem($setID, $j);
477 :     die "global $j for set $setID not found." unless $newProblemNumbers{$j};
478 : toenail 2794 }
479 :    
480 : sh002i 3802 # we don't have to do anything if we're not getting rid of holes
481 : toenail 2794 return "" unless $force;
482 :    
483 : sh002i 3802 # sort the curr. prob. num./score pairs by score
484 : toenail 2794 @sortme = sort {$a->[1] <=> $b->[1]} @sortme;
485 :     # now, for global and each user with this set, loop through problem list
486 :     # get all of the problem records
487 :     # assign new problem numbers
488 :     # loop - if number is new, put the problem record
489 :     # print "Sorted to get ". join(', ', map {$_->[0] } @sortme) ."<p>\n";
490 :    
491 :    
492 :     # Now, three stages. First global values
493 :    
494 :     for ($j = 0; $j < scalar @sortme; $j++) {
495 : sh002i 3802 if($sortme[$j][0] == $j + 1) {
496 :     # if the jth problem (according to the new ordering) is in the right place (problem IDs are numbered from 1, hence $j+1)
497 : toenail 2794 # do nothing
498 :     } elsif (not defined $newProblemNumbers{$j + 1}) {
499 : sh002i 3802 # otherwise, if there's a hole for it, add it there
500 :     $newProblemNumbers{$sortme[$j][0]}->problem_id($j + 1);
501 :     $db->addGlobalProblem($newProblemNumbers{$sortme[$j][0]});
502 : toenail 2794 } else {
503 : sh002i 3802 # otherwise, overwrite the data for the problem that's already there with the jth problem's data (with a changed problemID)
504 :     $newProblemNumbers{$sortme[$j][0]}->problem_id($j + 1);
505 :     $db->putGlobalProblem($newProblemNumbers{$sortme[$j][0]});
506 : toenail 2794 }
507 :     }
508 :    
509 : toenail 2816 my @setUsers = $db->listSetUsers($setID);
510 : toenail 2794 my (@problist, $user);
511 :    
512 :     foreach $user (@setUsers) {
513 : sh002i 3802 # grab a copy of each UserProblem for this user. @problist can be sparse (if problems were deleted)
514 : toenail 2794 for $j (keys %newProblemNumbers) {
515 : toenail 2816 $problist[$j] = $db->getUserProblem($user, $setID, $j);
516 : toenail 2794 }
517 :     for($j = 0; $j < scalar @sortme; $j++) {
518 : sh002i 3802 if ($sortme[$j][0] == $j + 1) {
519 :     # same as above -- the jth problem is in the right place, so don't worry about it
520 : toenail 2794 # do nothing
521 : sh002i 3802 } elsif ($problist[$sortme[$j][0]]) {
522 :     # we've made sure the user's problem actually exists HERE, since we want to be able to fail gracefullly if it doesn't
523 :     # the problem with the original conditional below is that %newProblemNumbers maps oldids => global problem record
524 :     # we need to check if the target USER PROBLEM exists, which is what @problist knows
525 :     #if (not defined $newProblemNumbers{$j + 1}) {
526 :     if (not defined $problist[$j+1]) {
527 :     # same as above -- there's a hole for that problem to go into, so add it in its new place
528 :     $problist[$sortme[$j][0]]->problem_id($j + 1);
529 :     $db->addUserProblem($problist[$sortme[$j][0]]);
530 :     } else {
531 :     # same as above -- there's a problem already there, so overwrite its data with the data from the jth problem
532 :     $problist[$sortme[$j][0]]->problem_id($j + 1);
533 :     $db->putUserProblem($problist[$sortme[$j][0]]);
534 :     }
535 :     } else {
536 :     warn "UserProblem missing for user=$user set=$setID problem=$sortme[$j][0]. This may indicate database corruption.\n";
537 :     # when a problem doesn't exist in the target slot, a new problem gets added there, but the original problem
538 :     # never gets overwritten (because there wan't a problem it would have to get exchanged with)
539 :     # i think this can get pretty complex. consider 1=>2, 2=>3, 3=>4, 4=>1 where problem 1 doesn't exist for some user:
540 :     # @sortme[$j][0] will contain: 4, 1, 2, 3
541 :     # - problem 1 will get **added** with the data from problem 4 (because problem 1 doesn't exist for this user)
542 :     # - problem 2 will get overwritten with the data from problem 1
543 :     # - problem 3 will get overwritten with the data from problem 2
544 :     # - nothing will happend to problem 4, since problem 1 doesn't exit
545 :     # so the solution is to delete problem 4 altogether!
546 :     # here's the fix:
547 :    
548 :     # the data from problem $j+1 was/will be moved to another problem slot,
549 :     # but there's no problem $sortme[$j][0] to replace it. thus, we delete it now.
550 :     $db->deleteUserProblem($user, $setID, $j+1);
551 :     }
552 : toenail 2794 }
553 :     }
554 :    
555 : sh002i 3802 # any problems with IDs above $maxNum get deleted -- presumably their data has been copied into problems with lower IDs
556 : toenail 2794 foreach ($j = scalar @sortme; $j < $maxNum; $j++) {
557 :     if (defined $newProblemNumbers{$j + 1}) {
558 : toenail 2816 $db->deleteGlobalProblem($setID, $j+1);
559 : toenail 2794 }
560 :     }
561 :    
562 : sh002i 3802 # return a string form of the old problem IDs in the new order (not used by caller, incidentally)
563 : toenail 2794 return join(', ', map {$_->[0]} @sortme);
564 :     }
565 :    
566 :     # swap index given with next bigger index
567 :     # leftover from when we had up/down buttons
568 :     # maybe we will bring them back
569 :    
570 : sh002i 2913 #sub moveme {
571 :     # my $index = shift;
572 :     # my $db = shift;
573 :     # my $setID = shift;
574 :     # my (@problemIDList) = @_;
575 :     # my ($prob1, $prob2, $prob);
576 :     #
577 :     # foreach my $problemID (@problemIDList) {
578 :     # my $problemRecord = $db->getGlobalProblem($setID, $problemID); # checked
579 :     # die "global $problemID for set $setID not found." unless $problemRecord;
580 :     # if ($problemRecord->problem_id == $index) {
581 :     # $prob1 = $problemRecord;
582 :     # } elsif ($problemRecord->problem_id == $index + 1) {
583 :     # $prob2 = $problemRecord;
584 :     # }
585 :     # }
586 :     # if (not defined $prob1 or not defined $prob2) {
587 :     # die "cannot find problem $index or " . ($index + 1);
588 :     # }
589 :     #
590 :     # $prob1->problem_id($index + 1);
591 :     # $prob2->problem_id($index);
592 :     # $db->putGlobalProblem($prob1);
593 :     # $db->putGlobalProblem($prob2);
594 :     #
595 :     # my @setUsers = $db->listSetUsers($setID);
596 :     #
597 :     # my $user;
598 :     # foreach $user (@setUsers) {
599 :     # $prob1 = $db->getUserProblem($user, $setID, $index); #checked
600 :     # die " problem $index for set $setID and effective user $user not found"
601 :     # unless $prob1;
602 :     # $prob2 = $db->getUserProblem($user, $setID, $index+1); #checked
603 :     # die " problem $index for set $setID and effective user $user not found"
604 :     # unless $prob2;
605 :     # $prob1->problem_id($index+1);
606 :     # $prob2->problem_id($index);
607 :     # $db->putUserProblem($prob1);
608 :     # $db->putUserProblem($prob2);
609 :     # }
610 :     #}
611 : toenail 2794
612 :     # primarily saves any changes into the correct set or problem records (global vs user)
613 :     # also deals with deleting or rearranging problems
614 :     sub initialize {
615 :     my ($self) = @_;
616 :     my $r = $self->r;
617 :     my $db = $r->db;
618 :     my $ce = $r->ce;
619 :     my $authz = $r->authz;
620 :     my $user = $r->param('user');
621 :     my $setID = $r->urlpath->arg("setID");
622 :     my $setRecord = $db->getGlobalSet($setID); # checked
623 :     die "global set $setID not found." unless $setRecord;
624 :    
625 :     $self->{set} = $setRecord;
626 :     my @editForUser = $r->param('editForUser');
627 :     # some useful booleans
628 :     my $forUsers = scalar(@editForUser);
629 :     my $forOneUser = $forUsers == 1;
630 :    
631 :     # Check permissions
632 :     return unless ($authz->hasPermissions($user, "access_instructor_tools"));
633 :     return unless ($authz->hasPermissions($user, "modify_problem_sets"));
634 :    
635 :    
636 :     my %properties = %{ FIELD_PROPERTIES() };
637 :    
638 :     # takes a hash of hashes and inverts it
639 :     my %undoLabels;
640 :     foreach my $key (keys %properties) {
641 :     %{ $undoLabels{$key} } = map { $properties{$key}->{labels}->{$_} => $_ } keys %{ $properties{$key}->{labels} };
642 :     }
643 :    
644 : toenail 2816 # Unfortunately not everyone uses Javascript enabled browsers so
645 :     # we must fudge the information coming from the ComboBoxes
646 :     # Since the textfield and menu both have the same name, we get an array of two elements
647 :     # We then reset the param to the first if its not-empty or the second (empty or not).
648 :     foreach ( @{ HEADER_ORDER() } ) {
649 :     my @values = $r->param("set.$setID.$_");
650 : toenail 2817 my $value = $values[0] || $values[1] || "";
651 : toenail 2816 $r->param("set.$setID.$_", $value);
652 :     }
653 : toenail 2794
654 : toenail 2901 #####################################################################
655 :     # Check date information
656 :     #####################################################################
657 :    
658 :     my ($open_date, $due_date, $answer_date);
659 :     my $error = 0;
660 : toenail 2794 if (defined $r->param('submit_changes')) {
661 : toenail 3061 my @names = ("open_date", "due_date", "answer_date");
662 :    
663 :     my %dates = map { $_ => $r->param("set.$setID.$_") } @names;
664 :     %dates = map {
665 :     my $unlabel = $undoLabels{$_}->{$dates{$_}};
666 :     $_ => defined $unlabel ? $setRecord->$_ : $self->parseDateTime($dates{$_})
667 :     } @names;
668 : toenail 2901
669 : toenail 3061 ($open_date, $due_date, $answer_date) = map { $dates{$_} } @names;
670 : toenail 2794
671 : toenail 2901 if ($answer_date < $due_date || $answer_date < $open_date) {
672 :     $self->addbadmessage("Answers cannot be made available until on or after the due date!");
673 :     $error = $r->param('submit_changes');
674 :     }
675 :    
676 :     if ($due_date < $open_date) {
677 :     $self->addbadmessage("Answers cannot be due until on or after the open date!");
678 :     $error = $r->param('submit_changes');
679 :     }
680 :    
681 : sh002i 3647 # make sure the dates are not more than 10 years in the future
682 :     my $curr_time = time;
683 :     my $seconds_per_year = 31_556_926;
684 :     my $cutoff = $curr_time + $seconds_per_year*10;
685 :     if ($open_date > $cutoff) {
686 :     $self->addbadmessage("Error: open date cannot be more than 10 years from now in set $setID");
687 :     $error = $r->param('submit_changes');
688 :     }
689 :     if ($due_date > $cutoff) {
690 :     $self->addbadmessage("Error: due date cannot be more than 10 years from now in set $setID");
691 :     $error = $r->param('submit_changes');
692 :     }
693 :     if ($answer_date > $cutoff) {
694 :     $self->addbadmessage("Error: answer date cannot be more than 10 years from now in set $setID");
695 :     $error = $r->param('submit_changes');
696 :     }
697 :    
698 :    
699 : toenail 2901 if ($error) {
700 :     $self->addbadmessage("No changes were saved!");
701 :     }
702 :     }
703 : sh002i 3647
704 : toenail 2901 if (defined $r->param('submit_changes') && !$error) {
705 :    
706 : sh002i 2913 #my $setRecord = $db->getGlobalSet($setID); # already fetched above --sam
707 : toenail 2901
708 : toenail 2794 #####################################################################
709 :     # Save general set information (including headers)
710 :     #####################################################################
711 :    
712 :     if ($forUsers) {
713 : sh002i 4518 # DBFIXME use a WHERE clause, iterator
714 : toenail 2794 my @userRecords = $db->getUserSets(map { [$_, $setID] } @editForUser);
715 :     foreach my $record (@userRecords) {
716 :     foreach my $field ( @{ SET_FIELDS() } ) {
717 :     next unless canChange($forUsers, $field);
718 : toenail 3061 my $override = $r->param("set.$setID.$field.override");
719 : toenail 2794
720 :     if (defined $override && $override eq $field) {
721 :    
722 :     my $param = $r->param("set.$setID.$field");
723 : toenail 2841 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
724 : toenail 3061 my $unlabel = $undoLabels{$field}->{$param};
725 :     $param = $unlabel if defined $unlabel;
726 :     # $param = $undoLabels{$field}->{$param} || $param;
727 : toenail 2794 if ($field =~ /_date/) {
728 : toenail 3061 $param = $self->parseDateTime($param) unless defined $unlabel;
729 : toenail 2794 }
730 :     $record->$field($param);
731 :     } else {
732 :     $record->$field(undef);
733 :     }
734 : toenail 3061
735 : toenail 2794 }
736 :     $db->putUserSet($record);
737 :     }
738 :     } else {
739 :     foreach my $field ( @{ SET_FIELDS() } ) {
740 :     next unless canChange($forUsers, $field);
741 :    
742 :     my $param = $r->param("set.$setID.$field");
743 : toenail 2841 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
744 : glarose 4411
745 : toenail 3061 my $unlabel = $undoLabels{$field}->{$param};
746 :     $param = $unlabel if defined $unlabel;
747 : toenail 2794 if ($field =~ /_date/) {
748 : toenail 3061 $param = $self->parseDateTime($param) unless defined $unlabel;
749 : toenail 2794 }
750 :     $setRecord->$field($param);
751 :     }
752 :     $db->putGlobalSet($setRecord);
753 :     }
754 : sh002i 3721
755 : toenail 2794 #####################################################################
756 :     # Save problem information
757 :     #####################################################################
758 :    
759 : sh002i 4518 # DBFIXME use a WHERE clause, iterator?
760 : toenail 2901 my @problemIDs = sort { $a <=> $b } $db->listGlobalProblems($setID);;
761 : toenail 2816 my @problemRecords = $db->getGlobalProblems(map { [$setID, $_] } @problemIDs);
762 :     foreach my $problemRecord (@problemRecords) {
763 : toenail 2794 my $problemID = $problemRecord->problem_id;
764 :     die "Global problem $problemID for set $setID not found." unless $problemRecord;
765 :    
766 :     if ($forUsers) {
767 :     # Since we're editing for specific users, we don't allow the GlobalProblem record to be altered on that same page
768 :     # So we only need to make changes to the UserProblem record and only then if we are overriding a value
769 :     # in the GlobalProblem record or for fields unique to the UserProblem record.
770 :    
771 :     my @userIDs = @editForUser;
772 :     my @userProblemIDs = map { [$_, $setID, $problemID] } @userIDs;
773 : sh002i 4518 # DBFIXME where clause? iterator?
774 : toenail 2794 my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
775 :     foreach my $record (@userProblemRecords) {
776 :    
777 :     my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
778 :     foreach my $field ( @{ PROBLEM_FIELDS() } ) {
779 :     next unless canChange($forUsers, $field);
780 :    
781 :     my $override = $r->param("problem.$problemID.$field.override");
782 :     if (defined $override && $override eq $field) {
783 :    
784 :     my $param = $r->param("problem.$problemID.$field");
785 : toenail 2841 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
786 : toenail 3061 my $unlabel = $undoLabels{$field}->{$param};
787 :     $param = $unlabel if defined $unlabel;
788 : toenail 2794 $changed ||= changed($record->$field, $param);
789 :     $record->$field($param);
790 :     } else {
791 :     $changed ||= changed($record->$field, undef);
792 :     $record->$field(undef);
793 :     }
794 :    
795 :     }
796 :    
797 :     foreach my $field ( @{ USER_PROBLEM_FIELDS() } ) {
798 :     next unless canChange($forUsers, $field);
799 :    
800 :     my $param = $r->param("problem.$problemID.$field");
801 : toenail 2841 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
802 : toenail 3061 my $unlabel = $undoLabels{$field}->{$param};
803 :     $param = $unlabel if defined $unlabel;
804 : toenail 2794 $changed ||= changed($record->$field, $param);
805 :     $record->$field($param);
806 :     }
807 :     $db->putUserProblem($record) if $changed;
808 :     }
809 :     } else {
810 :     # Since we're editing for ALL set users, we will make changes to the GlobalProblem record.
811 :     # We may also have instances where a field is unique to the UserProblem record but we want
812 :     # all users to (at least initially) have the same value
813 :    
814 :     # this only edits a globalProblem record
815 :     my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
816 :     foreach my $field ( @{ PROBLEM_FIELDS() } ) {
817 :     next unless canChange($forUsers, $field);
818 :    
819 :     my $param = $r->param("problem.$problemID.$field");
820 : toenail 2841 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
821 : toenail 3061 my $unlabel = $undoLabels{$field}->{$param};
822 :     $param = $unlabel if defined $unlabel;
823 : toenail 2794 $changed ||= changed($problemRecord->$field, $param);
824 :     $problemRecord->$field($param);
825 :     }
826 :     $db->putGlobalProblem($problemRecord) if $changed;
827 :    
828 :    
829 :     # sometimes (like for status) we might want to change an attribute in
830 :     # the userProblem record for every assigned user
831 :     # However, since this data is stored in the UserProblem records,
832 :     # it won't be displayed once its been changed and if you hit "Save Changes" again
833 :     # it gets erased
834 :    
835 :     # So we'll enforce that there be something worth putting in all the UserProblem records
836 :     # This also will make hitting "Save Changes" on the global page MUCH faster
837 :     my %useful;
838 :     foreach my $field ( @{ USER_PROBLEM_FIELDS() } ) {
839 :     my $param = $r->param("problem.$problemID.$field");
840 :     $useful{$field} = 1 if defined $param and $param ne "";
841 :     }
842 :    
843 :     if (keys %useful) {
844 : sh002i 4518 # DBFIXME where clause, iterator
845 : toenail 2794 my @userIDs = $db->listProblemUsers($setID, $problemID);
846 :     my @userProblemIDs = map { [$_, $setID, $problemID] } @userIDs;
847 :     my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
848 :     foreach my $record (@userProblemRecords) {
849 :     my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
850 : toenail 2901 foreach my $field ( keys %useful ) {
851 : toenail 2794 next unless canChange($forUsers, $field);
852 : toenail 2901
853 : toenail 2794 my $param = $r->param("problem.$problemID.$field");
854 : toenail 2841 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
855 : toenail 3061 my $unlabel = $undoLabels{$field}->{$param};
856 :     $param = $unlabel if defined $unlabel;
857 : toenail 2794 $changed ||= changed($record->$field, $param);
858 :     $record->$field($param);
859 :     }
860 :     $db->putUserProblem($record) if $changed;
861 :     }
862 :     }
863 :     }
864 :     }
865 : toenail 2834
866 : toenail 2901 # Mark the specified problems as correct for all users
867 :     foreach my $problemID ($r->param('markCorrect')) {
868 : sh002i 4518 # DBFIXME where clause, iterator
869 : toenail 2901 my @userProblemIDs = map { [$_, $setID, $problemID] } ($forUsers ? @editForUser : $db->listProblemUsers($setID, $problemID));
870 :     my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
871 :     foreach my $record (@userProblemRecords) {
872 :     if (defined $record && ($record->status eq "" || $record->status < 1)) {
873 :     $record->status(1);
874 :     $record->attempted(1);
875 :     $db->putUserProblem($record);
876 :     }
877 :     }
878 : toenail 2834 }
879 : sh002i 3721
880 :     # Delete all problems marked for deletion
881 :     foreach my $problemID ($r->param('deleteProblem')) {
882 :     $db->deleteGlobalProblem($setID, $problemID);
883 :     }
884 :    
885 :     #####################################################################
886 :     # Add blank problem if needed
887 :     #####################################################################
888 :     if (defined($r->param("add_blank_problem") ) and $r->param("add_blank_problem") == 1) {
889 :     my $targetProblemNumber = 1+ WeBWorK::Utils::max( $self->r->db->listGlobalProblems($setID));
890 : gage 3790 ##################################################
891 :     # make local copy of the blankProblem
892 :     ##################################################
893 : sh002i 3721 my $blank_file_path = $ce->{webworkFiles}->{screenSnippets}->{blankProblem};
894 : gage 3790 my $problemContents = WeBWorK::Utils::readFile($blank_file_path);
895 :     my $new_file_path = "set$setID/".BLANKPROBLEM();
896 :     my $fullPath = WeBWorK::Utils::surePathToFile($ce->{courseDirs}->{templates},'/'.$new_file_path);
897 :     local(*TEMPFILE);
898 :     open(TEMPFILE, ">$fullPath") or warn "Can't write to file $fullPath";
899 :     print TEMPFILE $problemContents;
900 :     close(TEMPFILE);
901 :    
902 : sh002i 3721 #################################################
903 :     # Update problem record
904 :     #################################################
905 :     my $problemRecord = $self->addProblemToSet(
906 :     setName => $setID,
907 : gage 3790 sourceFile => $new_file_path,
908 : sh002i 3721 problemID => $targetProblemNumber, #added to end of set
909 :     );
910 : gage 3787 $self->assignProblemToAllSetUsers($problemRecord);
911 : gage 3790 $self->addgoodmessage("Added $new_file_path to ". $setID. " as problem $targetProblemNumber") ;
912 : sh002i 3721 }
913 :    
914 :     # Sets the specified header to "" so that the default file will get used.
915 :     foreach my $header ($r->param('defaultHeader')) {
916 :     $setRecord->$header("");
917 :     }
918 : toenail 2901 }
919 : toenail 2834
920 : toenail 2794 # Leftover code from when there were up/down buttons
921 :    
922 :     # } else {
923 :     # # Look for up and down buttons
924 :     # my $index = 2;
925 :     # while ($index <= scalar @problemList) {
926 :     # if (defined $r->param("move.up.$index.x")) {
927 :     # moveme($index-1, $db, $setID, @problemList);
928 :     # }
929 :     # $index++;
930 :     # }
931 :     # $index = 1;
932 :     #
933 :     # while ($index < scalar @problemList) {
934 :     # if (defined $r->param("move.down.$index.x")) {
935 :     # moveme($index, $db, $setID, @problemList);
936 :     # }
937 :     # $index++;
938 :     # }
939 : toenail 2834 # }
940 :    
941 : toenail 2794
942 : toenail 2901 # This erases any sticky fields if the user saves changes, resets the form, or reorders problems
943 :     # It may not be obvious why this is necessary when saving changes or reordering problems
944 :     # but when the problems are reorder the param problem.1.source_file needs to be the source
945 :     # file of the problem that is NOW #1 and not the problem that WAS #1.
946 :     unless (defined $r->param('refresh')) {
947 :    
948 :     # reset all the parameters dealing with set/problem/header information
949 :     # if the current naming scheme is changed/broken, this could reek havoc
950 :     # on all kinds of things
951 :     foreach my $param ($r->param) {
952 : toenail 3102 $r->param($param, "") if $param =~ /^(set|problem|header)\./ && $param !~ /displaymode/;
953 : toenail 2901 }
954 :     }
955 : toenail 2794 }
956 :    
957 :     # helper method for debugging
958 : toenail 2901 sub definedness ($) {
959 : toenail 2794 my ($variable) = @_;
960 :    
961 :     return "undefined" unless defined $variable;
962 :     return "empty" unless $variable ne "";
963 :     return $variable;
964 :     }
965 :    
966 :     # helper method for checking if two things are different
967 :     # the return values will usually be thrown away, but they could be useful for debugging
968 :     sub changed ($$) {
969 :     my ($first, $second) = @_;
970 :    
971 :     return "def/undef" if defined $first and not defined $second;
972 :     return "undef/def" if not defined $first and defined $second;
973 : toenail 2834 return "" if not defined $first and not defined $second;
974 : toenail 2794 return "ne" if $first ne $second;
975 : toenail 2834 return ""; # if they're equal, there's no change
976 : toenail 2794 }
977 :    
978 : toenail 2834 # helper method that determines for how many users at a time a field can be changed
979 : toenail 2794 # none means it can't be changed for anyone
980 :     # any means it can be changed for anyone
981 :     # one means it can ONLY be changed for one at a time. (eg problem_seed)
982 :     # all means it can ONLY be changed for all at a time. (eg set_header)
983 :     sub canChange ($$) {
984 :     my ($forUsers, $field) = @_;
985 :    
986 :     my %properties = %{ FIELD_PROPERTIES() };
987 :     my $forOneUser = $forUsers == 1;
988 :    
989 :     my $howManyCan = $properties{$field}->{override};
990 :    
991 :     return 0 if $howManyCan eq "none";
992 :     return 1 if $howManyCan eq "any";
993 :     return 1 if $howManyCan eq "one" && $forOneUser;
994 : toenail 2816 return 1 if $howManyCan eq "all" && !$forUsers;
995 : toenail 2794 return 0; # FIXME: maybe it should default to 1?
996 :     }
997 :    
998 : toenail 2834 # helper method that determines if a file is valid and returns a pretty error message
999 :     sub checkFile ($) {
1000 :     my ($self, $file) = @_;
1001 :    
1002 :     my $r = $self->r;
1003 :     my $ce = $r->ce;
1004 :    
1005 :     return "No source file specified" unless $file;
1006 :     $file = $ce->{courseDirs}->{templates} . '/' . $file unless $file =~ m|^/|;
1007 :    
1008 :     my $text = "This source file ";
1009 :     my $fileError;
1010 :     return "" if -e $file && -f $file && -r $file;
1011 :     return $text . "is not readable!" if -e $file && -f $file;
1012 :     return $text . "is a directory!" if -d $file;
1013 :     return $text . "does not exist!" unless -e $file;
1014 :     return $text . "is not a plain file!";
1015 :     }
1016 :    
1017 : sh002i 3476 # don't show view options -- we provide display mode controls for headers/problems separately
1018 :     sub options {
1019 :     return "";
1020 :     }
1021 :    
1022 : toenail 2794 # Creates two separate tables, first of the headers, and the of the problems in a given set
1023 :     # If one or more users are specified in the "editForUser" param, only the data for those users
1024 :     # becomes editable, not all the data
1025 :     sub body {
1026 :    
1027 :     my ($self) = @_;
1028 :     my $r = $self->r;
1029 :     my $db = $r->db;
1030 :     my $ce = $r->ce;
1031 :     my $authz = $r->authz;
1032 :     my $userID = $r->param('user');
1033 :     my $urlpath = $r->urlpath;
1034 : toenail 2901 my $courseID = $urlpath->arg("courseID");
1035 :     my $setID = $urlpath->arg("setID");
1036 :     my $setRecord = $db->getGlobalSet($setID) or die "No record for global set $setID.";
1037 :    
1038 :     my $userRecord = $db->getUser($userID) or die "No record for user $userID.";
1039 :     # Check permissions
1040 :     return CGI::div({class=>"ResultsWithError"}, "You are not authorized to access the Instructor tools.")
1041 :     unless $authz->hasPermissions($userRecord->user_id, "access_instructor_tools");
1042 :    
1043 :     return CGI::div({class=>"ResultsWithError"}, "You are not authorized to modify problems.")
1044 :     unless $authz->hasPermissions($userRecord->user_id, "modify_problem_sets");
1045 :    
1046 : toenail 2794 my @editForUser = $r->param('editForUser');
1047 :    
1048 : toenail 2901 # Check that every user that we're editing for has a valid UserSet
1049 :     my @assignedUsers;
1050 :     my @unassignedUsers;
1051 :     if (scalar @editForUser) {
1052 :     foreach my $ID (@editForUser) {
1053 : sh002i 4518 # DBFIXME iterator
1054 : toenail 2901 if ($db->getUserSet($ID, $setID)) {
1055 :     unshift @assignedUsers, $ID;
1056 :     } else {
1057 :     unshift @unassignedUsers, $ID;
1058 :     }
1059 :     }
1060 : gage 3790 @editForUser = sort @assignedUsers;
1061 : toenail 2901 $r->param("editForUser", \@editForUser);
1062 :    
1063 :     if (scalar @editForUser && scalar @unassignedUsers) {
1064 :     print CGI::div({class=>"ResultsWithError"}, "The following users are NOT assigned to this set and will be ignored: " . CGI::b(join(", ", @unassignedUsers)));
1065 :     } elsif (scalar @editForUser == 0) {
1066 :     print CGI::div({class=>"ResultsWithError"}, "None of the selected users are assigned to this set: " . CGI::b(join(", ", @unassignedUsers)));
1067 :     print CGI::div({class=>"ResultsWithError"}, "Global set data will be shown instead of user specific data");
1068 :     }
1069 :     }
1070 :    
1071 : toenail 2794 # some useful booleans
1072 :     my $forUsers = scalar(@editForUser);
1073 :     my $forOneUser = $forUsers == 1;
1074 :    
1075 : toenail 2901 # If you're editing for users, initially their records will be different but
1076 : toenail 2794 # if you make any changes to them they will be the same.
1077 :     # if you're editing for one user, the problems shown should be his/hers
1078 : toenail 2901 my $userToShow = $forUsers ? $editForUser[0] : $userID;
1079 : toenail 2794
1080 : sh002i 4518 # DBFIXME no need to get ID lists -- counts would be fine
1081 : toenail 2794 my $userCount = $db->listUsers();
1082 : gage 3790 my $setCount = $db->listGlobalSets(); # if $forOneUser;
1083 : toenail 2816 my $setUserCount = $db->countSetUsers($setID);
1084 : toenail 2807 my $userSetCount = $db->countUserSets($editForUser[0]) if $forOneUser;
1085 : toenail 2901
1086 :    
1087 : toenail 2794 my $editUsersAssignedToSetURL = $self->systemLink(
1088 :     $urlpath->newFromModule(
1089 :     "WeBWorK::ContentGenerator::Instructor::UsersAssignedToSet",
1090 : toenail 2816 courseID => $courseID, setID => $setID));
1091 : toenail 2807 my $editSetsAssignedToUserURL = $self->systemLink(
1092 :     $urlpath->newFromModule(
1093 : gage 3856 "WeBWorK::ContentGenerator::Instructor::UserDetail",
1094 : toenail 2816 courseID => $courseID, userID => $editForUser[0])) if $forOneUser;
1095 : toenail 2794
1096 : toenail 2807
1097 : toenail 2816 my $setDetailPage = $urlpath -> newFromModule($urlpath->module, courseID => $courseID, setID => $setID);
1098 : gage 3863 my $setDetailURL = $self->systemLink($setDetailPage, authen=>0);
1099 : toenail 2794
1100 :    
1101 : toenail 2807 my $userCountMessage = CGI::a({href=>$editUsersAssignedToSetURL}, $self->userCountMessage($setUserCount, $userCount));
1102 :     my $setCountMessage = CGI::a({href=>$editSetsAssignedToUserURL}, $self->setCountMessage($userSetCount, $setCount)) if $forOneUser;
1103 : toenail 2794
1104 : toenail 2816 $userCountMessage = "The set $setID is assigned to " . $userCountMessage . ".";
1105 : toenail 2807 $setCountMessage = "The user $editForUser[0] has been assigned " . $setCountMessage . "." if $forOneUser;
1106 : toenail 2794
1107 : toenail 2807 if ($forUsers) {
1108 : gage 3790 ##############################################
1109 :     # calculate links for the users being edited:
1110 :     ##############################################
1111 :     my @userLinks = ();
1112 :     foreach my $userID (@editForUser) {
1113 :     my $u = $db->getUser($userID);
1114 : apizer 4064 my $email_address = $u->email_address;
1115 :     my $line = $u->last_name.", ".$u->first_name."&nbsp;&nbsp;(".CGI::a({-href=>"mailto:$email_address"},"email "). $u->user_id."). Assigned to ";
1116 : gage 3790 my $editSetsAssignedToUserURL = $self->systemLink(
1117 :     $urlpath->newFromModule(
1118 : gage 3856 "WeBWorK::ContentGenerator::Instructor::UserDetail",
1119 : gage 3790 courseID => $courseID, userID => $u->user_id));
1120 :     $line .= CGI::a({href=>$editSetsAssignedToUserURL},
1121 :     $self->setCountMessage($db->countUserSets($u->user_id), $setCount));
1122 :     unshift @userLinks,$line;
1123 : toenail 2807 }
1124 : gage 3790 @userLinks = sort @userLinks;
1125 :    
1126 :     print CGI::table({border=>2,cellpadding=>10},
1127 : gage 4276 CGI::Tr({},
1128 : gage 3790 CGI::td([
1129 :     "Editing problem set ".CGI::strong($setID)." data for these individual students:".CGI::br().
1130 :     CGI::strong(join CGI::br(), @userLinks),
1131 : gage 3863 CGI::a({href=>$self->systemLink($setDetailPage) },"Edit set ".CGI::strong($setID)." data for ALL students assigned to this set."),
1132 : gage 3790
1133 :     ])
1134 :     )
1135 :     );
1136 : toenail 2794 } else {
1137 : gage 3790 print CGI::table({border=>2,cellpadding=>10},
1138 : gage 4276 CGI::Tr({},
1139 : gage 3790 CGI::td([
1140 :     "This set ".CGI::strong($setID)." is assigned to ".$self->userCountMessage($setUserCount, $userCount).'.' ,
1141 :     'Edit '.CGI::a({href=>$editUsersAssignedToSetURL},'individual versions '). "of set $setID.",
1142 :    
1143 :     ])
1144 :     )
1145 :     );
1146 : toenail 2794 }
1147 :    
1148 : toenail 2901 # handle renumbering of problems if necessary
1149 :     print CGI::a({name=>"problems"});
1150 : toenail 2794
1151 : toenail 2901 my %newProblemNumbers = ();
1152 :     my $maxProblemNumber = -1;
1153 :     for my $jj (sort { $a <=> $b } $db->listGlobalProblems($setID)) {
1154 :     $newProblemNumbers{$jj} = $r->param('problem_num_' . $jj);
1155 :     $maxProblemNumber = $jj if $jj > $maxProblemNumber;
1156 :     }
1157 :    
1158 :     my $forceRenumber = $r->param('force_renumber') || 0;
1159 :     handle_problem_numbers(\%newProblemNumbers, $maxProblemNumber, $db, $setID, $forceRenumber) unless defined $r->param('undo_changes');
1160 :    
1161 : toenail 2794 my %properties = %{ FIELD_PROPERTIES() };
1162 :    
1163 :     my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()};
1164 :     my @active_modes = grep { exists $display_modes{$_} } @{$r->ce->{pg}->{displayModes}};
1165 :     push @active_modes, 'None';
1166 :     my $default_header_mode = $r->param('header.displaymode') || 'None';
1167 :     my $default_problem_mode = $r->param('problem.displaymode') || 'None';
1168 :    
1169 : toenail 2816 #####################################################################
1170 :     # Browse available header/problem files
1171 :     #####################################################################
1172 :    
1173 :     my $templates = $r->ce->{courseDirs}->{templates};
1174 : sh002i 4642 my $skip = join("|", keys %{ $r->ce->{courseFiles}->{problibs} });
1175 : toenail 2794
1176 : toenail 2816 my @headerFileList = listFilesRecursive(
1177 :     $templates,
1178 :     qr/header.*\.pg$/i, # match these files
1179 :     qr/^(?:$skip|CVS)$/, # prune these directories
1180 :     0, # match against file name only
1181 :     1, # prune against path relative to $templates
1182 :     );
1183 :    
1184 :     # this just takes too much time to search
1185 :     # my @problemFileList = listFilesRecursive(
1186 :     # $templates,
1187 :     # qr/\.pg$/i, # problem files don't say problem
1188 :     # qr/^(?:$skip|CVS)$/, # prune these directories
1189 :     # 0, # match against file name only
1190 :     # 1, # prune against path relative to $templates
1191 :     # );
1192 :    
1193 : toenail 2794 # Display a useful warning message
1194 :     if ($forUsers) {
1195 :     print CGI::p(CGI::b("Any changes made below will be reflected in the set for ONLY the student" .
1196 :     ($forOneUser ? "" : "s") . " listed above."));
1197 :     } else {
1198 :     print CGI::p(CGI::b("Any changes made below will be reflected in the set for ALL students."));
1199 :     }
1200 :    
1201 :     print CGI::start_form({method=>"POST", action=>$setDetailURL});
1202 : toenail 2834 print $self->hiddenEditForUserFields(@editForUser);
1203 :     print $self->hidden_authen_fields;
1204 : toenail 2794 print CGI::input({type=>"submit", name=>"submit_changes", value=>"Save Changes"});
1205 : toenail 2834 print CGI::input({type=>"submit", name=>"undo_changes", value => "Reset Form"});
1206 :    
1207 : toenail 2794 # spacing
1208 :     print CGI::p();
1209 :    
1210 :     #####################################################################
1211 :     # Display general set information
1212 :     #####################################################################
1213 :    
1214 :     print CGI::start_table({border=>1, cellpadding=>4});
1215 :     print CGI::Tr({}, CGI::th({}, [
1216 :     "General Information",
1217 :     ]));
1218 : sh002i 2913
1219 :     # this is kind of a hack -- we need to get a user record here, so we can
1220 :     # pass it to FieldTable, so FieldTable can pass it to FieldHTML, so
1221 :     # FieldHTML doesn't have to fetch it itself.
1222 :     my $userSetRecord = $db->getUserSet($userToShow, $setID);
1223 :    
1224 : toenail 2794 print CGI::Tr({}, CGI::td({}, [
1225 : sh002i 2913 $self->FieldTable($userToShow, $setID, undef, $setRecord, $userSetRecord),
1226 : toenail 2794 ]));
1227 :     print CGI::end_table();
1228 :    
1229 :     # spacing
1230 :     print CGI::p();
1231 :    
1232 :    
1233 :     #####################################################################
1234 :     # Display header information
1235 :     #####################################################################
1236 :     my @headers = @{ HEADER_ORDER() };
1237 : toenail 2834 my %headerModules = (set_header => 'problem_list', hardcopy_header => 'hardcopy_preselect_set');
1238 :     my %headerDefaults = (set_header => $ce->{webworkFiles}->{screenSnippets}->{setHeader}, hardcopy_header => $ce->{webworkFiles}->{hardcopySnippets}->{setHeader});
1239 : toenail 2794 my @headerFiles = map { $setRecord->{$_} } @headers;
1240 :     if (scalar @headers and not $forUsers) {
1241 :    
1242 :     print CGI::start_table({border=>1, cellpadding=>4});
1243 :     print CGI::Tr({}, CGI::th({}, [
1244 :     "Headers",
1245 :     # "Data",
1246 :     "Display&nbsp;Mode:&nbsp;" .
1247 :     CGI::popup_menu(-name => "header.displaymode", -values => \@active_modes, -default => $default_header_mode) . '&nbsp;'.
1248 : gage 2904 CGI::input({type => "submit", name => "refresh", value => "Refresh Display"}),
1249 : toenail 2794 ]));
1250 :    
1251 :     my %header_html;
1252 :    
1253 : toenail 2834 my %error;
1254 : toenail 2794 foreach my $header (@headers) {
1255 : toenail 2834 my $headerFile = $r->param("set.$setID.$header") || $setRecord->{$header} || $headerDefaults{$header};
1256 :    
1257 :     $error{$header} = $self->checkFile($headerFile);
1258 : glarose 4763 my $this_set = $db->getMergedSet($userToShow, $setID);
1259 : toenail 2834 unless ($error{$header}) {
1260 : sh002i 4846 my @temp = renderProblems(
1261 :     r=> $r,
1262 :     user => $db->getUser($userToShow),
1263 :     displayMode=> $default_header_mode,
1264 :     problem_number=> 0,
1265 :     this_set => $this_set,
1266 :     problem_list => [$headerFile],
1267 : toenail 2834 );
1268 :     $header_html{$header} = $temp[0];
1269 :     }
1270 : toenail 2794 }
1271 :    
1272 :     foreach my $header (@headers) {
1273 :    
1274 : toenail 2816 my $editHeaderPage = $urlpath->new(type => 'instructor_problem_editor_withset_withproblem', args => { courseID => $courseID, setID => $setID, problemID => 0 });
1275 : toenail 2794 my $editHeaderLink = $self->systemLink($editHeaderPage, params => { file_type => $header, make_local_copy => 1 });
1276 :    
1277 : toenail 2816 my $viewHeaderPage = $urlpath->new(type => $headerModules{$header}, args => { courseID => $courseID, setID => $setID });
1278 : toenail 2794 my $viewHeaderLink = $self->systemLink($viewHeaderPage);
1279 :    
1280 :     print CGI::Tr({}, CGI::td({}, [
1281 :     CGI::start_table({border => 0, cellpadding => 0}) .
1282 :     CGI::Tr({}, CGI::td({}, $properties{$header}->{name})) .
1283 : dpvc 3901 CGI::Tr({}, CGI::td({}, CGI::a({href => $editHeaderLink, target=>"WW_Editor"}, "Edit it"))) .
1284 :     CGI::Tr({}, CGI::td({}, CGI::a({href => $viewHeaderLink, target=>"WW_View"}, "View it"))) .
1285 : toenail 2834 # CGI::Tr({}, CGI::td({}, CGI::checkbox({name => "defaultHeader", value => $header, label => "Use Default"}))) .
1286 : toenail 2794 CGI::end_table(),
1287 :     # "",
1288 : toenail 2816 # CGI::input({ name => "set.$setID.$header", value => $setRecord->{$header}, size => 50}) .
1289 :     # join ("\n", $self->FieldHTML($userToShow, $setID, $problemID, "source_file")) .
1290 :     # CGI::br() . CGI::div({class=> "RenderSolo"}, $problem_html[0]->{body_text}),
1291 :    
1292 :     comboBox({
1293 :     name => "set.$setID.$header",
1294 :     request => $r,
1295 : toenail 2834 default => $r->param("set.$setID.$header") || $setRecord->{$header},
1296 : toenail 2816 multiple => 0,
1297 :     values => ["", @headerFileList],
1298 :     labels => { "" => "Use Default Header File" },
1299 :     }) .
1300 : toenail 2834 ($error{$header} ?
1301 :     CGI::div({class=>"ResultsWithError", style=>"font-weight: bold"}, $error{$header})
1302 :     : CGI::div({class=> "RenderSolo"}, $header_html{$header}->{body_text})
1303 :     ),
1304 : toenail 2794 ]));
1305 :     }
1306 :    
1307 :     print CGI::end_table();
1308 :     } else {
1309 :     print CGI::p(CGI::b("Screen and Hardcopy set header information can not be overridden for individual students."));
1310 :     }
1311 :    
1312 :     # spacing
1313 :     print CGI::p();
1314 :    
1315 :    
1316 :     #####################################################################
1317 :     # Display problem information
1318 :     #####################################################################
1319 :    
1320 : toenail 2901 my @problemIDList = sort { $a <=> $b } $db->listGlobalProblems($setID);
1321 : sh002i 2913
1322 : sh002i 4518 # DBFIXME use iterators instead of getting all at once
1323 :    
1324 : sh002i 2913 # get global problem records for all problems in one go
1325 :     my %GlobalProblems;
1326 :     my @globalKeypartsRef = map { [$setID, $_] } @problemIDList;
1327 : sh002i 4518 # DBFIXME shouldn't need to get key list here
1328 : sh002i 2913 @GlobalProblems{@problemIDList} = $db->getGlobalProblems(@globalKeypartsRef);
1329 :    
1330 :     # if needed, get user problem records for all problems in one go
1331 :     my (%UserProblems, %MergedProblems);
1332 :     if ($forOneUser) {
1333 :     my @userKeypartsRef = map { [$editForUser[0], $setID, $_] } @problemIDList;
1334 : sh002i 4518 # DBFIXME shouldn't need to get key list here
1335 : sh002i 2913 @UserProblems{@problemIDList} = $db->getUserProblems(@userKeypartsRef);
1336 :     @MergedProblems{@problemIDList} = $db->getMergedProblems(@userKeypartsRef);
1337 :     }
1338 :    
1339 : toenail 2816 if (scalar @problemIDList) {
1340 : toenail 2794
1341 :     print CGI::start_table({border=>1, cellpadding=>4});
1342 :     print CGI::Tr({}, CGI::th({}, [
1343 :     "Problems",
1344 :     "Data",
1345 :     "Display&nbsp;Mode:&nbsp;" .
1346 :     CGI::popup_menu(-name => "problem.displaymode", -values => \@active_modes, -default => $default_problem_mode) . '&nbsp;'.
1347 : gage 2904 CGI::input({type => "submit", name => "refresh", value => "Refresh Display"}),
1348 : toenail 2794 ]));
1349 :    
1350 : toenail 2834 my %shownYet;
1351 :     my $repeatFile;
1352 : toenail 2816 foreach my $problemID (@problemIDList) {
1353 : toenail 2794
1354 :     my $problemRecord;
1355 :     if ($forOneUser) {
1356 : sh002i 2913 #$problemRecord = $db->getMergedProblem($editForUser[0], $setID, $problemID);
1357 :     $problemRecord = $MergedProblems{$problemID}; # already fetched above --sam
1358 : toenail 2794 } else {
1359 : sh002i 2913 #$problemRecord = $db->getGlobalProblem($setID, $problemID);
1360 :     $problemRecord = $GlobalProblems{$problemID}; # already fetched above --sam
1361 : toenail 2794 }
1362 :    
1363 : sh002i 2913 #$self->addgoodmessage("");
1364 :     #$self->addbadmessage($problemRecord->toString());
1365 :    
1366 :    
1367 : toenail 2816 my $editProblemPage = $urlpath->new(type => 'instructor_problem_editor_withset_withproblem', args => { courseID => $courseID, setID => $setID, problemID => $problemID });
1368 :     my $editProblemLink = $self->systemLink($editProblemPage, params => { make_local_copy => 0 });
1369 : gage 3036
1370 :    
1371 : toenail 2794 # FIXME: should we have an "act as" type link here when editing for multiple users?
1372 : toenail 2841 my $viewProblemPage = $urlpath->new(type => 'problem_detail', args => { courseID => $courseID, setID => $setID, problemID => $problemID });
1373 : toenail 2794 my $viewProblemLink = $self->systemLink($viewProblemPage, params => { effectiveUser => ($forOneUser ? $editForUser[0] : $userID)});
1374 :    
1375 :     my @fields = @{ PROBLEM_FIELDS() };
1376 :     push @fields, @{ USER_PROBLEM_FIELDS() } if $forOneUser;
1377 :    
1378 : toenail 2834 my $problemFile = $r->param("problem.$problemID.source_file") || $problemRecord->source_file;
1379 :    
1380 :     # warn of repeat problems
1381 :     if (defined $shownYet{$problemFile}) {
1382 :     $repeatFile = "This problem uses the same source file as number " . $shownYet{$problemFile} . ".";
1383 :     } else {
1384 :     $shownYet{$problemFile} = $problemID;
1385 : toenail 2966 $repeatFile = "";
1386 : toenail 2834 }
1387 :    
1388 :     my $error = $self->checkFile($problemFile);
1389 : glarose 4763 my $this_set = $db->getMergedSet($userToShow, $setID);
1390 : toenail 2834 my @problem_html;
1391 :     unless ($error) {
1392 : sh002i 4846 @problem_html = renderProblems(
1393 :     r=> $r,
1394 :     user => $db->getUser($userToShow),
1395 :     displayMode=> $default_problem_mode,
1396 :     problem_number=> $problemID,
1397 :     this_set => $this_set,
1398 :     problem_seed => $forOneUser ? $problemRecord->problem_seed : 0,
1399 :     problem_list => [$problemRecord->source_file],
1400 : toenail 2834 );
1401 :     }
1402 : toenail 2794
1403 :     print CGI::Tr({}, CGI::td({}, [
1404 :     CGI::start_table({border => 0, cellpadding => 1}) .
1405 : toenail 2816 CGI::Tr({}, CGI::td({}, problem_number_popup($problemID, $maxProblemNumber))) .
1406 : dpvc 3901 CGI::Tr({}, CGI::td({}, CGI::a({href => $editProblemLink, target=>"WW_Editor"}, "Edit it"))) .
1407 :     CGI::Tr({}, CGI::td({}, CGI::a({href => $viewProblemLink, target=>"WW_View"}, "Try it" . ($forOneUser ? " (as $editForUser[0])" : "")))) .
1408 : toenail 2816 ($forUsers ? "" : CGI::Tr({}, CGI::td({}, CGI::checkbox({name => "deleteProblem", value => $problemID, label => "Delete it?"})))) .
1409 :     # CGI::Tr({}, CGI::td({}, "Delete&nbsp;it?" . CGI::input({type => "checkbox", name => "deleteProblem", value => $problemID}))) .
1410 : toenail 2901 ($forOneUser ? "" : CGI::Tr({}, CGI::td({}, CGI::checkbox({name => "markCorrect", value => $problemID, label => "Mark Correct?"})))) .
1411 : toenail 2794 CGI::end_table(),
1412 : sh002i 2913 $self->FieldTable($userToShow, $setID, $problemID, $GlobalProblems{$problemID}, $UserProblems{$problemID}),
1413 : toenail 2816 # A comprehensive list of problems is just TOO big to be handled well
1414 :     # comboBox({
1415 :     # name => "set.$setID.$problemID",
1416 :     # request => $r,
1417 :     # default => $problemRecord->{problem_id},
1418 :     # multiple => 0,
1419 :     # values => \@problemFileList,
1420 :     # }) .
1421 :    
1422 : sh002i 2913 join ("\n", $self->FieldHTML(
1423 :     $userToShow,
1424 :     $setID,
1425 :     $problemID,
1426 :     $GlobalProblems{$problemID}, # pass previously fetched global record to FieldHTML --sam
1427 :     $UserProblems{$problemID}, # pass previously fetched user record to FieldHTML --sam
1428 :     "source_file"
1429 :     )) .
1430 : toenail 2834 CGI::br() .
1431 :     ($error ?
1432 :     CGI::div({class=>"ResultsWithError", style=>"font-weight: bold"}, $error)
1433 :     : CGI::div({class=> "RenderSolo"}, $problem_html[0]->{body_text})
1434 :     ) .
1435 :     ($repeatFile ? CGI::div({class=>"ResultsWithError", style=>"font-weight: bold"}, $repeatFile) : ''),
1436 : toenail 2794 ]));
1437 :     }
1438 :    
1439 : gage 3036
1440 :     # print final lines
1441 : toenail 2794 print CGI::end_table();
1442 :     print CGI::checkbox({
1443 : sh002i 3803 label=> "Force problems to be numbered consecutively from one (always done when reordering problems)",
1444 : gage 4285 name=>"force_renumber", value=>"1"});
1445 : gage 3790 print CGI::p(<<EOF);
1446 : toenail 2794 Any time problem numbers are intentionally changed, the problems will
1447 :     always be renumbered consecutively, starting from one. When deleting
1448 :     problems, gaps will be left in the numbering unless the box above is
1449 :     checked.
1450 : gage 3790 EOF
1451 :     print CGI::p("It is before the open date. You probably want to renumber the problems if you are deleting some from the middle.") if ($setRecord->open_date>time());
1452 : gage 4258 print CGI::p("When changing problem numbers, we will move the problem to be ". CGI::em("before"). " the chosen number.");
1453 : toenail 2794
1454 :     } else {
1455 :     print CGI::p(CGI::b("This set doesn't contain any problems yet."));
1456 :     }
1457 : gage 3175 # always allow one to add a new problem.
1458 : gage 4285 print CGI::checkbox({
1459 :     label=> "Add blank problem template to end of homework set",
1460 :     name=>"add_blank_problem", value=>"1"}
1461 :     ),CGI::br(),CGI::br(),
1462 :     CGI::input({type=>"submit", name=>"submit_changes", value=>"Save Changes"}),
1463 :     CGI::input({type=>"submit", name=>"handle_numbers", value=>"Reorder problems only"}),
1464 :     "(Any unsaved changes will be lost.)"
1465 :     ;
1466 : toenail 2794
1467 : gage 4285
1468 :    
1469 :     #my $editNewProblemPage = $urlpath->new(type => 'instructor_problem_editor_withset_withproblem', args => { courseID => $courseID, setID => $setID, problemID =>'new_problem' });
1470 :     #my $editNewProblemLink = $self->systemLink($editNewProblemPage, params => { make_local_copy => 1, file_type => 'blank_problem' });
1471 : gage 3811 # This next feature isn't fully supported and is causing problems. Remove for now. #FIXME
1472 :     #print CGI::p( CGI::a({href=>$editNewProblemLink},'Edit'). ' a new blank problem');
1473 : gage 3175
1474 : toenail 2794 print CGI::end_form();
1475 :    
1476 :     return "";
1477 :     }
1478 :    
1479 :     1;
1480 :    
1481 :     =head1 AUTHOR
1482 :    
1483 :     Written by Robert Van Dam, toenail (at) cif.rochester.edu
1484 :    
1485 :     =cut

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9