--- loncom/interface/loncommon.pm 2006/11/21 21:38:44 1.472 +++ loncom/interface/loncommon.pm 2006/12/01 00:28:14 1.481 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.472 2006/11/21 21:38:44 raeburn Exp $ +# $Id: loncommon.pm,v 1.481 2006/12/01 00:28:14 banghart Exp $ # # Copyright Michigan State University Board of Trustees # @@ -65,7 +65,7 @@ use Apache::lonhtmlcommon(); use Apache::loncoursedata(); use Apache::lontexconvert(); use Apache::lonclonecourse(); -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); my $readit; @@ -157,7 +157,7 @@ BEGIN { opendir(DIR,$designdir); while ($filename=readdir(DIR)) { if ($filename!~/\.tab$/) { next; } - my ($domain)=($filename=~/^(\w+)\./); + my ($domain)=($filename=~/^($match_domain)\./); { my $designfile = $designdir.'/'.$filename; if ( open (my $fh,"<$designfile") ) { @@ -1377,6 +1377,24 @@ sub select_form { return $selectform; } +# For display filters + +sub display_filter { + if (!$env{'form.show'}) { $env{'form.show'}=10; } + if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; } + return ' '. + &mt('Filter [_1]', + &select_form($env{'form.displayfilter'}, + 'displayfilter', + ('currentfolder' => 'Current folder/page', + 'containing' => 'Containing phrase', + 'none' => 'None'))). + ''; +} + sub gradeleveldescription { my $gradelevel=shift; my %gradelevels=(0 => 'Not specified', @@ -2792,8 +2810,9 @@ sub findallcourses { my %courses; my $now=time; foreach my $key (keys(%env)) { - if ( $key=~m{^user\.role\.(\w+)\./(\w+)/(\w+)} ) { - my ($role,$domain,$id) = ($1,$2,$3); + 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)}) { + my ($role,$domain,$id,$sec) = ($1,$2,$3,$4); next if ($role eq 'ca' || $role eq 'aa'); next if (%roles && !exists($roles{$role})); my ($starttime,$endtime)=split(/\./,$env{$key}); @@ -2804,13 +2823,129 @@ sub findallcourses { if ($endtime) { if ($now>$endtime) { $active=0; } } - if ($active) { $courses{$domain.'_'.$id}=1; } + if ($active) { + if ($sec eq '') { + $sec = 'none'; + } + $courses{$domain.'_'.$id}{$sec} = 1; + } } } - return keys(%courses); + return %courses; } ############################################### + +sub blockcheck { + my ($setters,$activity) = @_; + # Retrieve active student roles and active course coordinator/instructor roles + + my %live_courses = &findallcourses(); + + # Retrieve blocking times and identity of blocker for active courses + # unless user has 'evb' privilege. + + my $startblock = 0; + my $endblock = 0; + + foreach my $course (keys(%live_courses)) { + my $cdom = $env{'course.'.$course.'.domain'}; + my $cnum = $env{'course.'.$course.'.num'}; + my $noblock = 0; + foreach my $sec (keys(%{$live_courses{$course}})) { + my $role = 'cm./'.$cdom.'/'.$cnum; + if ($sec ne 'none') { + $role .= '/'.$sec; + } + if (&Apache::lonnet::allowed('evb',undef,undef,$role)) { + $noblock = 1; + last; + } + } + # if they have the evb priv and are currently not playing student + next if (($noblock) && + ($env{'request.role'} !~ m{^st\./$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 > $1) ) { + $startblock = $1; + } + if ( ($endblock == 0) || ($endblock < $2) ) { + $endblock = $2; + } + } + } + } + } + return ($startblock,$endblock); +} + +sub parse_block_record { + my ($record) = @_; + my ($setuname,$setudom,$title,$blocks); + if (ref($record) eq 'HASH') { + ($setuname,$setudom) = split(/:/,$record->{'setter'}); + $title = &unescape($record->{'event'}); + $blocks = $record->{'blocks'}; + } else { + my @data = split(/:/,$record,3); + if (scalar(@data) eq 2) { + $title = $data[1]; + ($setuname,$setudom) = split(/@/,$data[0]); + } else { + ($setuname,$setudom,$title) = @data; + } + $blocks = { 'com' => 'on' }; + } + return ($setuname,$setudom,$title,$blocks); +} + +sub build_block_table { + my ($startblock,$endblock,$setters) = @_; + my %lt = &Apache::lonlocal::texthash( + 'cacb' => 'Currently active communication blocks', + 'cour' => 'Course', + 'dura' => 'Duration', + 'blse' => 'Block set by' + ); + my $output; + $output = '
'.$lt{'cacb'}.':
'; + $output .= &start_data_table(); + $output .= ' + + '.$lt{'cour'}.' + '.$lt{'dura'}.' + '.$lt{'blse'}.' + +'; + foreach my $course (keys(%{$setters})) { + 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 ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]}; + $openblock = &Apache::lonlocal::locallocaltime($openblock); + $closeblock= &Apache::lonlocal::locallocaltime($closeblock); + $output .= &Apache::loncommon::start_data_table_row(). + ''.$courseinfo{'description'}.''. + ''.$openblock.' to '.$closeblock.''. + ''.$fullname.'.'. + &Apache::loncommon::end_data_table_row(); + } + } + $output .= &end_data_table(); +} + ############################################### =pod @@ -2983,7 +3118,7 @@ sub bodytag { # role and realm my ($role,$realm) = split(/\./,$env{'request.role'},2); if ($role eq 'ca') { - my ($rdom,$rname) = ($realm =~ m-^/(\w+)/(\w+)$-); + my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$}); $realm = &plainname($rname,$rdom).':'.$rdom; } # realm @@ -3489,8 +3624,6 @@ table.LC_whatsnew tr.LC_empty_row td { table.LC_whatsnew tr.LC_empty_row td { padding: 4ex } - - table.LC_whatsnew { } @@ -3514,6 +3647,19 @@ table.LC_whatsnew tr.LC_odd_row td { background-color: #EEE; } +table.LC_createuser { +} + +table.LC_createuser tr.LC_section_row td { + font-size: smaller; +} + +table.LC_createuser tr.LC_info_row td { + background-color: #CCC; + font-weight: bold; + text-align: center; +} + table.LC_calendar { border: 1px solid #000000; border-collapse: collapse; @@ -4990,7 +5136,13 @@ sub record_sep { $i++; } } else { - my @allfields=split(/\,/,$record); + my @allfields; + &Apache::lonnet::logthis("file type is ".$env{'form.upfiletype'}); + if ($env{'form.upfiletype'} eq 'semisv') { + @allfields=split(/;/,$record); + } else { + @allfields=split(/\,/,$record); + } my $i=0; my $j; for ($j=0;$j<=$#allfields;$j++) { @@ -5028,6 +5180,7 @@ the file type. sub upfile_select_html { my %Types = ( csv => &mt('CSV (comma separated values, spreadsheet)'), + semisv => &mt('Semicolon separated values'), space => &mt('Space separated'), tab => &mt('Tabulator separated'), # xml => &mt('HTML/XML'), @@ -5867,7 +6020,7 @@ sub construct_course { # # Check if created correctly # - ($$crsudom,$$crsunum)=($$courseid=~/^\/(\w+)\/(\w+)$/); + ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid); my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom); $outcome .= &mt('Created on').': '.$crsuhome.'
'; # @@ -5876,7 +6029,7 @@ sub construct_course { my $cloneid=''; if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; - my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/); + my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); if ($clonehome eq 'no_host') { $outcome .=