--- loncom/homework/lonhomework.pm 2018/09/21 04:37:36 1.344.2.10 +++ loncom/homework/lonhomework.pm 2024/02/27 17:10:23 1.344.2.10.4.7 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.344.2.10 2018/09/21 04:37:36 raeburn Exp $ +# $Id: lonhomework.pm,v 1.344.2.10.4.7 2024/02/27 17:10:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,15 +49,22 @@ use Apache::matchresponse(); use Apache::chemresponse(); use Apache::functionplotresponse(); use Apache::drawimage(); +use Apache::loncourseuser(); +use Apache::grades(); use Apache::Constants qw(:common); use Apache::loncommon(); +use Apache::lonparmset(); +use Apache::lonnavmaps(); use Apache::lonlocal; +use LONCAPA qw(:DEFAULT :match); +use LONCAPA::ltiutils(); use Time::HiRes qw( gettimeofday tv_interval ); use HTML::Entities(); use File::Copy(); # FIXME - improve commenting +my $registered_cleanup; BEGIN { &Apache::lonxml::register_insert(); @@ -155,9 +162,19 @@ sub get_target { return ('web','answer'); } elsif (($env{'form.problemmode'} eq 'saveedit') || ($env{'form.problemmode'} eq 'undo')) { - return ('modified','no_output_web','edit'); + my %editors = &Apache::loncommon::permitted_editors(); + if ($editors{'edit'}) { + return ('modified','no_output_web','edit'); + } else { + return ('web'); + } } elsif ($env{'form.problemmode'} eq 'edit') { - return ('no_output_web','edit'); + my %editors = &Apache::loncommon::permitted_editors(); + if ($editors{'edit'}) { + return ('no_output_web','edit'); + } else { + return ('web'); + } } else { return ('web'); } @@ -188,7 +205,7 @@ sub proctor_checked_in { if ($type eq 'Task') { my $version=$Apache::lonhomework::history{'resource.0.version'}; $key ="resource.$version.0.checkedin"; - } elsif ($type eq 'problem') { + } elsif (($type eq 'problem') || ($type eq 'tool')) { $key ='resource.0.checkedin'; } # backward compatability, used to be username@domain, @@ -203,7 +220,6 @@ sub proctor_checked_in { return 1; } } - return 0; } @@ -212,7 +228,7 @@ sub check_slot_access { # does it pass normal muster my ($status,$datemsg)=&check_access($id,$symb); - + my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb); if ($useslots ne 'resource' && $useslots ne 'map' && $useslots ne 'map_map') { @@ -292,7 +308,7 @@ sub check_slot_access { || $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ ); $checkedin = $Apache::lonhomework::history{"resource.$version.0.checkedin"}; - } elsif ($type eq 'problem') { + } elsif (($type eq 'problem') || ($type eq 'tool')) { $checkin = 'resource.0.checkedin'; $checkedin = $Apache::lonhomework::history{$checkin}; } @@ -301,7 +317,7 @@ sub check_slot_access { my %slot=&Apache::lonnet::get_slot($checkinslot); $consumed_uniq = $slot{'uniqueperiod'}; } - if ($type eq 'problem') { + if (($type eq 'problem') || ($type eq 'tool')) { if ((ref($partlist) eq 'ARRAY') && (@{$partlist} > 0)) { my ($numcorrect,$numgraded) = (0,0); foreach my $part (@{$partlist}) { @@ -360,8 +376,9 @@ sub check_slot_access { # However, the problem is not closed, and potentially, another slot might be # used to gain access to it to work on it, until the due date is reached, and the # problem then becomes CLOSED. Therefore return the slotstatus - - # (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE. - if (!defined($slot_name) && $type eq 'problem') { + # (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE). + + if (!defined($slot_name) && (($type eq 'problem') || ($type eq 'tool'))) { if ($slotstatus eq 'NOT_IN_A_SLOT') { if (!$num_usable_slots) { if ($env{'request.course.id'}) { @@ -445,7 +462,7 @@ sub check_slot_access { } if ( $is_correct) { - if ($type eq 'problem') { + if (($type eq 'problem') || ($type eq 'tool')) { return ($status); } return ('SHOW_ANSWER'); @@ -716,6 +733,9 @@ sub setuppermissions { $env{'request.course.sec'} !~ /^\s*$/) { $viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}. '/'.$env{'request.course.sec'}); + if ($viewgrades) { + $Apache::lonhomework::viewgradessec = $env{'request.course.sec'}; + } } $Apache::lonhomework::viewgrades = $viewgrades; @@ -733,6 +753,9 @@ sub setuppermissions { $modifygrades = &Apache::lonnet::allowed('mgr',$env{'request.course.id'}. '/'.$env{'request.course.sec'}); + if ($modifygrades) { + $Apache::lonhomework::modifygradessec = $env{'request.course.sec'}; + } } $Apache::lonhomework::modifygrades = $modifygrades; @@ -751,7 +774,9 @@ sub setuppermissions { sub unset_permissions { undef($Apache::lonhomework::queuegrade); undef($Apache::lonhomework::modifygrades); + undef($Apache::lonhomework::modifygradessec); undef($Apache::lonhomework::viewgrades); + undef($Apache::lonhomework::viewgradessec); undef($Apache::lonhomework::browse); } @@ -850,7 +875,7 @@ STATE sub analyze_header { my ($request) = @_; - my $js = &Apache::structuretags::setmode_javascript(); + my $js = &Apache::lonxml::setmode_javascript(); # Breadcrumbs my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), @@ -866,18 +891,26 @@ sub analyze_header { {'bread_crumbs' => $brcrum,}) .&Apache::loncommon::head_subbox( &Apache::loncommon::CSTR_pageheader()); + my %lt = &Apache::lonlocal::texthash( + edit => 'Edit', + editxml => 'EditXML', + ); $result .= '
'. ''. &Apache::structuretags::remember_problem_state().' -
- - -
+
'; + my %editors = &Apache::loncommon::permitted_editors(); + foreach my $item ('editxml','edit') { + next unless ($editors{$item}); + $result .= ''. + "\n"; + } + $result .= + '

@@ -1062,9 +1095,8 @@ sub editxmlmode { $problem=''; } - if (($env{'form.problemmode'} eq 'saveeditxml') || - ($env{'form.problemmode'} eq 'saveviewxml') || + ($env{'form.problemmode'} eq 'saveviewxml') || ($env{'form.problemmode'} eq 'undoxml')) { my $error=&handle_save_or_undo($request,\$problem, \$env{'form.editxmltext'}); @@ -1083,7 +1115,7 @@ sub editxmlmode { my $js = &Apache::edit::js_change_detection(). &Apache::loncommon::resize_textarea_js(). - &Apache::structuretags::setmode_javascript(). + &Apache::lonxml::setmode_javascript(). &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); # Breadcrumbs @@ -1121,7 +1153,8 @@ sub editxmlmode { $result .= '
    '; - unless ($env{'environment.nocodemirror'}) { + my $nocodemirror = &Apache::loncommon::nocodemirror(); + unless ($nocodemirror) { # dropdown menus $result .= Apache::lonmenu::create_submenu("#", "", &mt("Problem Templates"), template_dropdown_datastructure()); @@ -1153,7 +1186,7 @@ sub editxmlmode { '
    '; my $resource = $env{'request.ambiguous'}; - unless($env{'environment.nocodemirror'}){ + unless ($nocodemirror) { $result .= '