--- loncom/homework/bridgetask.pm 2007/08/03 23:29:57 1.236 +++ loncom/homework/bridgetask.pm 2007/08/09 00:59:16 1.237 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.236 2007/08/03 23:29:57 albertel Exp $ +# $Id: bridgetask.pm,v 1.237 2007/08/09 00:59:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -244,13 +244,20 @@ sub add_grading_button { my $result="\n\t".''; $result.="\n\t".''; - if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'}) - || &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'}) - ) { + my $see_all = &Apache::lonnet::allowed('mgq',$env{'request.course.id'}); + my $see_sec = &Apache::lonnet::allowed('mgq',$env{'request.course.id'}. + '/'.$env{'request.course.sec'}); + + if ($see_all || $see_sec) { my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue'); $result.="\n\t".''."\n\t\t".''; - $result.="\n\t\t\t".''. - "\n\t\t\t".''; + if ($see_all || (!§ion_restricted())) { + $result.="\n\t\t\t".''. + "\n\t\t\t".''; + } else { + $result.="\n\t\t\t".''. + "\n\t\t\t".''; + } $result.="\n\t\t\t".''. @@ -1589,7 +1602,7 @@ sub show_queue { foreach my $key (sort(keys(%queue))) { my ($symb,$uname,$udom) = &decode_queue_key($key); next if (!defined($classlist->{$uname.':'.$udom})); - next if (§ion_restricted($classlist->{$uname.':'.$udom})); + next if (!&allow_grade_user($classlist->{$uname.':'.$udom})); my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()]; @@ -1675,16 +1688,33 @@ FORM return $result; } +sub get_allowed_sections { + my @chosen_sections; + if (§ion_restricted()) { + @chosen_sections = ($env{'request.course.sec'}); + } else { + @chosen_sections = + &Apache::loncommon::get_env_multiple('form.chosensections'); + } + + return @chosen_sections; +} + sub section_restricted { - my ($classlist_entry) = @_; my $cid =(&Apache::lonnet::whichuser())[1]; - if (lc($env{'course.'.$cid.'.task_grading'}) eq 'section' - && $env{'request.course.sec'} + return (lc($env{'course.'.$cid.'.task_grading'}) eq 'section' + && $env{'request.course.sec'} ne '' ); +} + +sub allow_grade_user { + my ($classlist_entry) = @_; + + if (§ion_restricted() && $env{'request.course.sec'} ne $classlist_entry->[&Apache::loncoursedata::CL_SECTION()]) { - return 1; + return 0; } - return 0; + return 1; } sub get_queue_counts { @@ -1708,7 +1738,7 @@ sub get_queue_counts { foreach my $key (sort(keys(%queue))) { my ($symb,$uname,$udom) = &decode_queue_key($key); next if (!defined($classlist->{$uname.':'.$udom})); - next if (§ion_restricted($classlist->{$uname.':'.$udom})); + next if (!&allow_grade_user($classlist->{$uname.':'.$udom})); if ($key=~/locked$/) { $locks++; @@ -1787,7 +1817,7 @@ sub pick_from_queue_data { my ($symb,$uname,$udom)=&decode_queue_key($key); next if (!defined($classlist->{$uname.':'.$udom})); - next if (§ion_restricted($classlist->{$uname.':'.$udom})); + next if (!&allow_grade_user($classlist->{$uname.':'.$udom})); if ($check_section) { my $section = @@ -1912,7 +1942,7 @@ sub get_queue_symb_status { next if ($key=~/timestamp$/); my ($symb,$uname,$udom) = &decode_queue_key($key); next if (!defined($classlist->{$uname.':'.$udom})); - next if (§ion_restricted($classlist->{$uname.':'.$udom})); + next if (!&allow_grade_user($classlist->{$uname.':'.$udom})); push(@users,"$uname:$udom"); } return @users; @@ -1999,9 +2029,7 @@ sub get_from_queue { sub select_user { my ($symb,$cid)=&Apache::lonnet::whichuser(); - my @chosen_sections= - &Apache::loncommon::get_env_multiple('form.chosensections'); - + my @chosen_sections = &get_allowed_sections(); my $classlist = &get_limited_classlist(\@chosen_sections); my $result; @@ -2054,7 +2082,7 @@ sub select_user { $seclist - +
Specify a section: '.$sec_select."\n\t\t\t".'Specify a section: '.$sec_select."\n\t\t\t".'Grading section: '.$env{'request.course.sec'}."\n\t\t\t".''.' '; @@ -623,12 +630,14 @@ sub start_Task { my $target_id = &Apache::lonstathelpers::make_target_id({symb => $symb, part => '0'}); - $result.='
'. - ''. - ''. - ''. - '
'; + if (§ion_restricted()) { + $result.='
'. + ''. + ''. + ''. + '
'; + } } } } @@ -807,9 +816,8 @@ sub start_Task { $result.=''; } - if ($env{'form.chosensections'}) { - my @chosen_sections= - &Apache::loncommon::get_env_multiple('form.chosensections'); + if ($env{'form.chosensections'} || §ion_restricted()) { + my @chosen_sections = &get_allowed_sections(); foreach my $sec (@chosen_sections) { $result.=''; @@ -905,7 +913,14 @@ sub get_key_todo { my $cdom = $env{'course.'.$cid.'.domain'}; my $uname = &LONCAPA::clean_username($env{'form.gradinguser'}); my $udom = &LONCAPA::clean_domain($env{'form.gradingdomain'}); - + + if (§ion_restricted()) { + my $classlist=&get_limited_classlist(); + if (!&allow_grade_user($classlist->{$uname.':'.$udom})) { + return (undef,'not_allowed', + &mt('Requested student ([_1]) is in a section you aren\'t allowed to grade.',$uname.':'.$udom)); + } + } my $gradingkey=&encode_queue_key($symb,$udom,$uname); my $queue; @@ -1521,11 +1536,11 @@ sub get_limited_classlist { } } - if (ref($sections) && !grep('all',@{ $sections })) { + if (ref($sections) && !grep {$_ eq 'all'} (@{ $sections })) { foreach my $student (keys(%$classlist)) { my $section = $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()]; - if (! grep($section,@{ $sections })) { + if (! grep {$_ eq $section} (@{ $sections })) { delete($classlist->{$student}); } } @@ -1541,8 +1556,7 @@ sub show_queue { my $cnum=$env{'course.'.$cid.'.num'}; my $cdom=$env{'course.'.$cid.'.domain'}; - my @chosen_sections= - &Apache::loncommon::get_env_multiple('form.chosensections'); + my @chosen_sections = &get_allowed_sections(); my $classlist = &get_limited_classlist(\@chosen_sections); @@ -1571,7 +1585,6 @@ sub show_queue { my ($tmp)=%queue; if ($tmp=~/^error: 2 /) { $result.= - &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_row(). '
'.&mt('Empty').'$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] ($student)$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] ($student) Sec: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()] RESULT }