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

Diff of /branches/gage_dev/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2737 Revision 2738
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.159 2004/08/26 01:34:30 jj Exp $ 4# $CVSHeader$
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
390 unless defined $PermissionLevel; 390 unless defined $PermissionLevel;
391 my $permissionLevel = $PermissionLevel->permission; 391 my $permissionLevel = $PermissionLevel->permission;
392 392
393 # obtain the merged set for $effectiveUser 393 # obtain the merged set for $effectiveUser
394 my $set = $db->getMergedSet($effectiveUserName, $setName); # checked 394 my $set = $db->getMergedSet($effectiveUserName, $setName); # checked
395
396 # Database fix (in case of undefined published values)
397 # this is only necessary because some people keep holding to ww1.9 which did not have a published field
398 # make sure published is set to 0 or 1
399 if ( $set and $set->published ne "0" and $set->published ne "1") {
400 my $globalSet = $db->getGlobalSet($set->set_id);
401 $globalSet->published("1"); # defaults to published
402 $db->putGlobalSet($globalSet);
403 $set = $db->getMergedSet($effectiveUserName, $setName);
404 } else {
405 # don't do anything just yet, maybe we're a professor and we're
406 # fabricating a set or haven't assigned it to ourselves just yet
407 }
395 408
396 # obtain the merged problem for $effectiveUser 409 # obtain the merged problem for $effectiveUser
397 my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked 410 my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked
398 411
399 my $editMode = $r->param("editMode"); 412 my $editMode = $r->param("editMode");
400 413
401 if ($authz->hasPermissions($userName, "modify_problem_sets")) { 414 if ($authz->hasPermissions($userName, "modify_problem_sets")) {
402 # professors are allowed to fabricate sets and problems not 415 # professors are allowed to fabricate sets and problems not
403 # assigned to them (or anyone). this allows them to use the 416 # assigned to them (or anyone). this allows them to use the
404 # editor to 417 # editor to
405 418
406 # if that is not yet defined obtain the global set, convert 419 # if a User Set does not exist for this user and this set
407 # it to a user set, and add fake user data 420 # then we check the Global Set
421 # if that does not exist we create a fake set
422 # if it does, we add fake user data
408 unless (defined $set) { 423 unless (defined $set) {
409 my $userSetClass = $db->{set_user}->{record}; 424 my $userSetClass = $db->{set_user}->{record};
410 my $globalSet = $db->getGlobalSet($setName); # checked 425 my $globalSet = $db->getGlobalSet($setName); # checked
411 # if the global set doesn't exist either, bail! 426
412 if(not defined $globalSet) { 427 if (not defined $globalSet) {
413 $set = fake_set($db); 428 $set = fake_set($db);
414 } else { 429 } else {
415 $set = global2user($userSetClass, $globalSet); 430 $set = global2user($userSetClass, $globalSet);
416 $set->psvn(0); 431 $set->psvn(0);
417
418 # FIXME: This is a temporary fix to fill in the database
419 # We want the published field to contain either 1 or 0 so if it has not been set to 0, default to 1
420 # this will fill in all the empty fields but not change anything that has been specifically set to 1 or 0
421 $globalSet->published("1") unless $globalSet->published eq "0";
422 $db->putGlobalSet($globalSet);
423 } 432 }
424 } 433 }
425 434
426 # if that is not yet defined obtain the global problem, 435 # if that is not yet defined obtain the global problem,
427 # convert it to a user problem, and add fake user data 436 # convert it to a user problem, and add fake user data
476 my $publishedClass = ($set->published) ? "Published" : "Unpublished"; 485 my $publishedClass = ($set->published) ? "Published" : "Unpublished";
477 my $publishedText = ($set->published) ? "visible to students." : "hidden from students."; 486 my $publishedText = ($set->published) ? "visible to students." : "hidden from students.";
478 $self->addmessage(CGI::p("This set is " . CGI::font({class=>$publishedClass}, $publishedText))); 487 $self->addmessage(CGI::p("This set is " . CGI::font({class=>$publishedClass}, $publishedText)));
479 } else { 488 } else {
480 489
481 # students can't view problems not assigned to them
482
483 # A set is valid if it exists and if it is either published or the user is privileged. 490 # A set is valid if it exists and if it is either published or the user is privileged.
484 $self->{invalidSet} = ((grep /^$setName/, $db->listUserSets($effectiveUserName)) == 0)
485 || not defined $set
486 || !($set->published || $authz->hasPermissions($userName, "view_unpublished_sets")); 491 $self->{invalidSet} = !(defined $set and ($set->published || $authz->hasPermissions($userName, "view_unpublished_sets")));
487 $self->{invalidProblem} = ((grep /^$problemNumber/, $db->listUserProblems($effectiveUserName, $setName)) == 0)
488 || not defined $problem
489 || !($set->published || $authz->hasPermissions($userName, "view_unpublished_sets")); 492 $self->{invalidProblem} = !(defined $problem and ($set->published || $authz->hasPermissions($userName, "view_unpublished_sets")));
490 493
491 $self->addbadmessage(CGI::p("This problem will not count towards your grade.")) if $problem and not $problem->value and not $self->{invalidProblem}; 494 $self->addbadmessage(CGI::p("This problem will not count towards your grade.")) if $problem and not $problem->value and not $self->{invalidProblem};
492 } 495 }
493 496
494 $self->{userName} = $userName; 497 $self->{userName} = $userName;
495 $self->{effectiveUserName} = $effectiveUserName; 498 $self->{effectiveUserName} = $effectiveUserName;

Legend:
Removed from v.2737  
changed lines
  Added in v.2738

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9