--- loncom/interface/loncommon.pm 2006/12/01 20:17:47 1.482 +++ loncom/interface/loncommon.pm 2006/12/24 21:13:37 1.497 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.482 2006/12/01 20:17:47 raeburn Exp $ +# $Id: loncommon.pm,v 1.497 2006/12/24 21:13:37 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,6 +59,7 @@ use Apache::lonnet; use GDBM_File; use POSIX qw(strftime mktime); use Apache::lonmenu(); +use Apache::lonenc; use Apache::lonlocal; use HTML::Entities; use Apache::lonhtmlcommon(); @@ -515,8 +516,8 @@ function setSect(sectionlist) { sub selectcourse_link { my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_; - return "".&mt('Select [_1]',$selecttype).""; + return "".&mt('Select Course').""; } sub check_uncheck_jscript { @@ -2690,7 +2691,9 @@ sub get_student_answers { } $moreenv{'grade_target'}='answer'; %moreenv=(%form,%moreenv); - my $userview=&Apache::lonnet::ssi('/res/'.$feedurl,%moreenv); + $feedurl = &Apache::lonnet::clutter($feedurl); + &Apache::lonenc::check_encrypt(\$feedurl); + my $userview=&Apache::lonnet::ssi($feedurl,%moreenv); return $userview; } @@ -2850,13 +2853,13 @@ sub findallcourses { $cnum = $cnumpart; ($sec,$role) = split(/_/,$secpart); $realsec = $sec; - } + } $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec; } } else { foreach my $key (keys(%env)) { - if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_username)/?(\w*)$} || - $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$}) { + if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} || + $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) { my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4); next if ($role eq 'ca' || $role eq 'aa'); next if (%roles && !exists($roles{$role})); @@ -2885,15 +2888,50 @@ sub findallcourses { sub blockcheck { my ($setters,$activity,$uname,$udom) = @_; - # Retrieve active course roles - course coordinator, instructor, exam proctor, ta, student or custom role. + + if (!defined($udom)) { + $udom = $env{'user.domain'}; + } + if (!defined($uname)) { + $uname = $env{'user.name'}; + } + + my ($startblock,$endblock); + + # If uname and udom are for a course, check for blocks in the course. + + if (&Apache::lonnet::is_course($udom,$uname)) { + my %records = &Apache::lonnet::dump('comm_block',$udom,$uname); + ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname); + return ($startblock,$endblock); + } my %live_courses = &findallcourses(undef,$uname,$udom); - # Retrieve blocking times and identity of blocker for active courses - # of specified user, unless user has 'evb' privilege. + # If uname is for a user, and activity is course-specific, i.e., + # boards, chat or groups, check for blocking in current course only. - my $startblock = 0; - my $endblock = 0; + if (($activity eq 'boards' || $activity eq 'chat' || + $activity eq 'groups') && ($env{'request.course.id'})) { + foreach my $key (keys(%live_courses)) { + if ($key ne $env{'request.course.id'}) { + delete($live_courses{$key}); + } + } + } + + my $otheruser = 0; + my %own_courses; + if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) { + # Resource belongs to user other than current user. + $otheruser = 1; + # Gather courses for current user + %own_courses = + &findallcourses(undef,$env{'user.name'},$env{'user.domain'}); + } + + # Gather active course roles - course coordinator, instructor, + # exam proctor, ta, student, or custom role. foreach my $course (keys(%live_courses)) { my ($cdom,$cnum); @@ -2901,17 +2939,38 @@ sub blockcheck { $cdom = $env{'course.'.$course.'.domain'}; $cnum = $env{'course.'.$course.'.num'}; } else { - ($cdom,$cnum) = split(/_/,$course); + ($cdom,$cnum) = split(/_/,$course); } my $no_ownblock = 0; my $no_userblock = 0; + if ($otheruser) { + # Check if current user has 'evb' priv for this + if (defined($own_courses{$course})) { + foreach my $sec (keys(%{$own_courses{$course}})) { + my $checkrole = 'cm./'.$cdom.'/'.$cnum; + if ($sec ne 'none') { + $checkrole .= '/'.$sec; + } + if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) { + $no_ownblock = 1; + last; + } + } + } + # if they have 'evb' priv and are currently not playing student + next if (($no_ownblock) && + ($env{'request.role'} !~ m{^st\./$cdom/$cnum})); + } foreach my $sec (keys(%{$live_courses{$course}})) { my $checkrole = 'cm./'.$cdom.'/'.$cnum; if ($sec ne 'none') { $checkrole .= '/'.$sec; } - if ((defined($uname) && ($uname ne $env{'user.name'})) || - (defined($udom) && ($udom ne $env{'user.domain'}))) { + # Resource belongs to user other than current user. + # Assemble privs for that user, and check for 'evb' priv. + if ($otheruser) { + # Resource belongs to user other than current user. + # Assemble privs for that user, and check for 'evb' priv. my ($trole,$tdom,$tnum,$tsec); my $entry = $live_courses{$course}{$sec}; if ($entry =~ /^cr/) { @@ -2943,6 +3002,8 @@ sub blockcheck { } } } else { + # Resource belongs to current user + # Check for 'evb' priv via lonnet::allowed(). if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) { $no_ownblock = 1; last; @@ -2951,26 +3012,39 @@ sub blockcheck { } # if they have the evb priv and are currently not playing student next if (($no_ownblock) && - ($env{'request.role'} !~ m{^st\./$cdom/$cnum})); + ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E})); next if ($no_userblock); - $setters->{$course} = {}; - $setters->{$course}{'staff'} = []; - $setters->{$course}{'times'} = []; - my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum); - foreach my $record (keys(%records)) { - my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/); - if ($start <= time && $end >= time) { - my ($staff_name,$staff_dom,$title,$blocks) = - &parse_block_record($records{$record}); - if ($blocks->{$activity} eq 'on') { - push(@{$$setters{$course}{'staff'}}, [$staff_name,$staff_dom]); push(@{$$setters{$course}{'times'}}, [$start,$end]); - if ( ($startblock == 0) || ($startblock > $1) ) { - $startblock = $1; - } - if ( ($endblock == 0) || ($endblock < $2) ) { - $endblock = $2; - } + # Retrieve blocking times and identity of blocker for course + # of specified user, unless user has 'evb' privilege. + + ($startblock,$endblock)=&get_blocks($setters,$activity,$cdom,$cnum); + } + return ($startblock,$endblock); +} + +sub get_blocks { + my ($setters,$activity,$cdom,$cnum) = @_; + my $startblock = 0; + my $endblock = 0; + my $course = $cdom.'_'.$cnum; + $setters->{$course} = {}; + $setters->{$course}{'staff'} = []; + $setters->{$course}{'times'} = []; + my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum); + foreach my $record (keys(%records)) { + my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/); + if ($start <= time && $end >= time) { + my ($staff_name,$staff_dom,$title,$blocks) = + &parse_block_record($records{$record}); + if ($blocks->{$activity} eq 'on') { + push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]); + push(@{$$setters{$course}{'times'}}, [$start,$end]); + if ( ($startblock == 0) || ($startblock > $start) ) { + $startblock = $start; + } + if ( ($endblock == 0) || ($endblock < $end) ) { + $endblock = $end; } } } @@ -3020,20 +3094,83 @@ sub build_block_table { my %courseinfo=&Apache::lonnet::coursedescription($course); for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) { my ($uname,$udom) = @{$$setters{$course}{staff}[$i]}; - my $fullname = &aboutmewrapper(&plainname($uname,$udom),$uname,$udom); + my $fullname = &plainname($uname,$udom); + if (defined($env{'user.name'}) && defined($env{'user.domain'}) + && $env{'user.name'} ne 'public' + && $env{'user.domain'} ne 'public') { + $fullname = &aboutmewrapper($fullname,$uname,$udom); + } my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]}; $openblock = &Apache::lonlocal::locallocaltime($openblock); $closeblock= &Apache::lonlocal::locallocaltime($closeblock); $output .= &Apache::loncommon::start_data_table_row(). '