--- loncom/homework/bridgetask.pm 2006/05/23 19:55:40 1.153 +++ loncom/homework/bridgetask.pm 2006/06/01 19:31:12 1.161 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.153 2006/05/23 19:55:40 albertel Exp $ +# $Id: bridgetask.pm,v 1.161 2006/06/01 19:31:12 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,9 +38,12 @@ use Apache::lonlocal; use Apache::lonxml; use Apache::slotrequest(); use Time::HiRes qw( gettimeofday tv_interval ); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + BEGIN { - &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','Instance','InstanceText','Criteria','ClosingParagraph')); + &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Instance','InstanceText','Criteria','ClosingParagraph')); } sub initialize_bridgetask { @@ -263,7 +266,7 @@ STUFF } if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); } - $symb=&Apache::lonnet::escape($symb); + $symb=&escape($symb); $result.='
'. ''. ''. @@ -362,9 +365,9 @@ sub file_list { my $file=$file_url.$partial_file; $file=~s|/+|/|g; &Apache::lonnet::allowuploaded('/adm/bridgetask',$file); - $file_list.='
  • '.$file. - '
  • '."\n"; + $file_list.='
  • file icon '.$file. + '
  • '."\n"; } $file_list.="\n"; return $file_list; @@ -574,7 +577,7 @@ DONESCREEN &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.''; $form_tag_start.= ''; + &escape($todo).'" />'; $Apache::bridgetask::queue_key=$todo; &Apache::structuretags::initialize_storage(); &Apache::lonhomework::showhash(%Apache::lonhomework::history); @@ -705,7 +708,7 @@ sub get_key_todo { my $who=&queue_key_locked($queue,$gradingkey); if ($who eq $me) { #already have the lock - $env{'form.gradingkey'}=&Apache::lonnet::escape($gradingkey); + $env{'form.gradingkey'}=&escape($gradingkey); return ($gradingkey); } @@ -730,7 +733,7 @@ sub get_key_todo { $env{'form.queue'}=$queue='gradingqueue'; } - my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'}); + my $gradingkey=&unescape($env{'form.gradingkey'}); if ($env{'form.queue'} eq 'none') { if (defined($env{'form.gradingkey'})) { @@ -1198,6 +1201,30 @@ sub add_to_queue { return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum); } +sub get_limited_classlist { + my ($sections) = @_; + + my $classlist = &Apache::loncoursedata::get_classlist(); + foreach my $student (keys(%$classlist)) { + if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()] + ne 'Active') { + delete($classlist->{$student}); + } + } + + if (ref($sections) && !grep('all',@{ $sections })) { + foreach my $student (keys(%$classlist)) { + my $section = + $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()]; + if (! grep($section,@{ $sections })) { + delete($classlist->{$student}); + } + } + } + return $classlist; +} + + sub show_queue { my ($queue,$with_selects)=@_; my $result; @@ -1207,36 +1234,66 @@ sub show_queue { my @chosen_sections= &Apache::loncommon::get_env_multiple('form.chosensections'); - &Apache::grades::init_perm(); - my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,); - &Apache::grades::reset_perm(); + + my $classlist = &get_limited_classlist(\@chosen_sections); + if (!(grep(/^all$/,@chosen_sections))) { $result.='

    Showing only sections '.join(', ',@chosen_sections). '.

    '."\n"; } + my ($view,$view_section); + my $scope = $env{'request.course.id'}; + if (!($view=&Apache::lonnet::allowed('vgr',$scope))) { + $scope .= '/'.$env{'request.course.sec'}; + if ( $view = &Apache::lonnet::allowed('vgr',$scope)) { + $view_section=$env{'request.course.sec'}; + } else { + undef($view); + } + } + my $regexp="^$symb\0"; my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp); my ($tmp)=%queue; if ($tmp=~/^error: 2 /) { - return "\n

    Current Queue - $queue

    Empty
    "; + return "\n

    Current Queue - $queue

    ". + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_row(). + ''.&mt('Empty').''. + &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table(); } my $title=&Apache::lonnet::gettitle($symb); - $result.="\n

    Current Queue - $title $queue

    "; + $result.="\n

    Current Queue - $title $queue

    ". + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(); if ($with_selects) { $result.=""; } - $result.=""; + $result.="". + &Apache::loncommon::end_data_table_header_row(); foreach my $key (sort(keys(%queue))) { my ($symb,$uname,$udom) = &decode_queue_key($key); if (!defined($classlist->{$uname.':'.$udom})) { next; } + + my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()]; + + my $can_view=1; + if (!$view + || ($view_section && !$section) + || ($view_section && $section && ($view_section ne $section))) { + $can_view=0; + } + if ($key=~/locked$/ && !$with_selects) { - $result.=""; + $result.= &Apache::loncommon::start_data_table_row(). + ""; $result.=''; } elsif ($key=~/timestamp$/ && !$with_selects) { - $result.=""; + $result.=&Apache::loncommon::start_data_table_row().""; $result.='"; } elsif ($key!~/(timestamp|locked)$/) { - $result.=""; + $result.= &Apache::loncommon::start_data_table_row(); my ($end_time,$slot_text); if (my $slot=&slotted_access($queue{$key})) { my %slot_data=&Apache::lonnet::get_slot($slot); @@ -1247,7 +1304,7 @@ sub show_queue { $slot_text = ''; } if ($with_selects) { - my $ekey=&Apache::lonnet::escape($key); + my $ekey=&escape($key); my ($action,$description,$status)=('select',&mt('Select')); if (exists($queue{"$key\0locked"})) { my $me=$env{'user.name'}.':'.$env{'user.domain'}; @@ -1263,7 +1320,7 @@ sub show_queue { $seclist.=''; } - if ($end_time ne '' && time > $end_time) { + if ($can_view && ($end_time ne '' && time > $end_time)) { $result.=(<$status FORM - + } elsif (!$can_view && ($end_time ne '' && time > $end_time)) { + $result.='' } else { $result.='' } } - $result.= ""; $result.='"; + "".&Apache::loncommon::end_data_table_row(); } } - $result.="
    Statususerdata
    userdata
    $uname$uname'.$queue{$key}.'
    '. &Apache::lonlocal::locallocaltime($queue{$key})."
    @@ -1278,19 +1335,20 @@ sub show_queue { '.&mt("Not gradable").' '.&mt("In Progress").' ".$fullname->{$uname.':'.$udom}. + $result.= "".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()]. " ($uname:$udom) '.$slot_text.' End time: '. &Apache::lonlocal::locallocaltime($end_time). - "

    \n"; + $result.= &Apache::loncommon::end_data_table()."
    \n"; return $result; } @@ -1300,6 +1358,9 @@ sub get_queue_counts { my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser(); my $cnum=$env{'course.'.$cid.'.num'}; my $cdom=$env{'course.'.$cid.'.domain'}; + + my $classlist=&get_limited_classlist(); + my $regexp="^$symb\0"; my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp); my ($tmp)=%queue; @@ -1309,12 +1370,14 @@ sub get_queue_counts { my ($entries,$ready_to_grade,$locks)=(0,0,0); my %slot_cache; foreach my $key (sort(keys(%queue))) { + my ($symb,$uname,$udom) = &decode_queue_key($key); + if (!defined($classlist->{$uname.':'.$udom})) { next; } + if ($key=~/locked$/) { $locks++; } elsif ($key=~/timestamp$/) { #ignore } elsif ($key!~/(timestamp|locked)$/) { - my ($symb,$uname,$udom) = &decode_queue_key($key); $entries++; if (my $slot=&slotted_access($queue{$key})) { if (!exists($slot_cache{$slot})) { @@ -1379,14 +1442,18 @@ sub slotted_access { } sub pick_from_queue_data { - my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_; + my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_; my @possible; # will hold queue entries that are valid to be selected foreach my $key (keys(%$queuedata)) { if ($key =~ /\0locked$/) { next; } if ($key =~ /\0timestamp$/) { next; } + my ($symb,$uname,$udom)=&decode_queue_key($key); + if (!defined($classlist->{$uname.':'.$udom})) { next; } + if ($check_section) { - my $section=&Apache::lonnet::getsection($uname,$udom); + my $section = + $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()]; if ($section eq $check_section) { &Apache::lonxml::debug("my sec"); next; @@ -1394,20 +1461,23 @@ sub pick_from_queue_data { } my $end_time; if (my $slot=&slotted_access($queuedata->{$key})) { + &Apache::lonxml::debug("looking at slot $slot"); my %slot_data=&Apache::lonnet::get_slot($slot); if ($slot_data{'endtime'} < time) { $end_time = $slot_data{'endtime'}; + } else { + &Apache::lonxml::debug("not time ".$slot_data{'endtime'}); + next; } } else { my $due_date = &Apache::lonhomework::due_date('0',$symb); - if ($due_date > time) { + if ($due_date < time) { $end_time = $due_date; + } else { + &Apache::lonxml::debug("not time $due_date"); + next; } } - if ($end_time ne '') { - &Apache::lonxml::debug("not time"); - next; - } if (exists($queuedata->{"$key\0locked"})) { &Apache::lonxml::debug("someone already has um."); @@ -1433,7 +1503,7 @@ sub pick_from_queue_data { sub find_mid_grade { my ($queue,$symb,$cdom,$cnum)=@_; - my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'}); + my $todo=&unescape($env{'form.gradingkey'}); my $me=$env{'user.name'}.':'.$env{'user.domain'}; if ($todo) { my $who=&queue_key_locked($queue,$todo,$cdom,$cnum); @@ -1474,6 +1544,8 @@ sub get_queue_symb_status { $cnum=$env{'course.'.$cid.'.num'}; $cdom=$env{'course.'.$cid.'.domain'}; } + my $classlist=&get_limited_classlist(); + my $regexp="^$symb\0"; my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp); my ($tmp)=%queue; @@ -1483,6 +1555,7 @@ sub get_queue_symb_status { next if ($key=~/locked$/); next if ($key=~/timestamp$/); my ($symb,$uname,$udom) = &decode_queue_key($key); + next if (!defined($classlist->{$uname.':'.$udom})); push(@users,"$uname:$udom"); } return @users; @@ -1498,6 +1571,9 @@ sub get_from_queue { &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo))); if ($todo) { return $todo; } my $attempts=0; + + my $classlist=&get_limited_classlist(); + while (1) { if ($attempts > 2) { # tried twice to get a queue entry, giving up @@ -1508,21 +1584,22 @@ sub get_from_queue { $cdom,$cnum); &Apache::lonxml::debug("$starttime"); my $regexp="^$symb\0queue\0"; - my $range= ($attempts < 1 ) ? '0-100' : '0-400'; + #my $range= ($attempts < 1 ) ? '0-100' : '0-400'; my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp); #make a pass looking for a user _not_ in my section if ($env{'request.course.sec'}) { &Apache::lonxml::debug("sce"); $todo=&pick_from_queue_data($queue,$env{'request.course.sec'}, - \%queue,$cdom,$cnum); + \%queue,$cdom,$cnum,$classlist); &Apache::lonxml::debug("sce $todo"); } # no one _not_ in our section so look for any user that is # ready for grading if (!$todo) { &Apache::lonxml::debug("no sce"); - $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum); + $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum, + $classlist); &Apache::lonxml::debug("no sce $todo"); } # no user to grade @@ -1567,18 +1644,17 @@ sub select_user { my @chosen_sections= &Apache::loncommon::get_env_multiple('form.chosensections'); - &Apache::grades::init_perm(); - my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,); - &Apache::grades::reset_perm(); + + my $classlist = &get_limited_classlist(\@chosen_sections); my $result; if (!(grep(/^all$/,@chosen_sections))) { $result.='

    Showing only sections '.join(', ',@chosen_sections). '.

    '."\n"; } - $result.=''; + $result.=&Apache::loncommon::start_data_table(); - foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { + foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) { my ($uname,$udom) = split(/:/,$student); my $cnum=$env{'course.'.$cid.'.num'}; @@ -1599,9 +1675,10 @@ sub select_user { } } my $todo = - &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname)); + &escape(&encode_queue_key($symb,$udom,$uname)); if ($cannot_grade) { - $result.=' + '; + $result.= ''.&Apache::loncommon::end_data_table_row(); } - $result.='
     '.$fullname->{$student}. + $result.=&Apache::loncommon::start_data_table_row(). + ' '.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()]. ''; } else { my $seclist; @@ -1609,10 +1686,8 @@ sub select_user { $seclist.=''; } - my $studentdis = $student; - $studentdis =~ tr/:/@/; + $result.=&Apache::loncommon::start_data_table_row(); $result.=<
    @@ -1622,7 +1697,7 @@ sub select_user { $seclist
    -
    $fullname->{$student} ($studentdis)$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] ($student) RESULT } @@ -1661,9 +1736,9 @@ RESULT } else { $result.=" "; } - $result.= '
    '; + $result.=&Apache::loncommon::end_data_table(); return $result; } @@ -1730,6 +1805,20 @@ sub start_Dimension { return &internal_location($dim_id); } +sub start_QuestionText { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $dim_id=$Apache::bridgetask::dimension; + my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style); + if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') { + $dimension{'questiontext'}=$text; + } + return ''; +} + +sub end_QuestionText { + return ''; +} + sub get_instance { my ($dim)=@_; my $rand_alg=&Apache::lonnet::get_rand_alg(); @@ -1790,9 +1879,12 @@ sub get_instance { if (&Apache::response::showallfoils()) { @instances = @{$dimension{'instances'}}; } + my $shown_question_text; foreach my $instance (@instances) { @Apache::scripttag::parser_env = @_; $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'}); + @Apache::scripttag::parser_env = @_; + $result.=&Apache::scripttag::xmlparse($dimension{'questiontext'}); if ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass' || $Apache::lonhomework::history{"resource.$version.0.status"} eq 'fail') { @@ -1877,6 +1969,8 @@ sub get_instance { &Apache::scripttag::xmlparse($dimension{'intro'}); @Apache::scripttag::parser_env = @_; &Apache::scripttag::xmlparse($dimension{$instance.'.text'}); + @Apache::scripttag::parser_env = @_; + &Apache::scripttag::xmlparse($dimension{'questiontext'}); foreach my $id (@{$dimension{$instance.'.criterias'}}, @{$dimension{'criterias'}} ) { my $link=&link($id); @@ -1912,11 +2006,14 @@ sub get_instance { @Apache::scripttag::parser_env = @_; $result.=&Apache::scripttag::xmlparse($dimension{'intro'}); + @Apache::scripttag::parser_env = @_; + $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'}); + @Apache::scripttag::parser_env = @_; + &Apache::scripttag::xmlparse($dimension{'questiontext'}); + foreach my $id (@{$dimension{$instance.'.criterias'}}, @{$dimension{'criterias'}}) { my $link=&link($id); - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'}); my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link}; $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link}; my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');