--- loncom/homework/lonhomework.pm 2008/01/21 17:20:45 1.290 +++ loncom/homework/lonhomework.pm 2008/11/19 18:34:56 1.299 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.290 2008/01/21 17:20:45 www Exp $ +# $Id: lonhomework.pm,v 1.299 2008/11/19 18:34:56 jms Exp $ # # Copyright Michigan State University Board of Trustees # @@ -85,14 +85,20 @@ sub set_bubble_lines { } } -# -# Decides what targets to render for. -# Implicit inputs: -# Various session environment variables: -# request.state - published - is a /res/ resource -# uploaded - is a /uploaded/ resource -# contruct - is a /priv/ resource -# form.grade_target - a form parameter requesting a specific target +=pod + +=item get_target() + +Decides what targets to render for. +Implicit inputs: + Various session environment variables: + request.state - published - is a /res/ resource + uploaded - is a /uploaded/ resource + contruct - is a /priv/ resource + form.grade_target - a form parameter requesting a specific target + +=cut + sub get_target { &Apache::lonxml::debug("request.state = $env{'request.state'}"); if( defined($env{'form.grade_target'})) { @@ -209,58 +215,6 @@ sub proctor_checked_in { return 0; } -sub check_ip_acc { - my ($acc)=@_; - &Apache::lonxml::debug("acc is $acc"); - if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) { - return 1; - } - my $allowed=0; - my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'}; - - my $name; - foreach my $pattern (split(',',$acc)) { - $pattern =~ s/^\s*//; - $pattern =~ s/\s*$//; - if ($pattern =~ /\*$/) { - #35.8.* - $pattern=~s/\*//; - if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } - } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) { - #35.8.3.[34-56] - my $low=$2; - my $high=$3; - $pattern=$1; - if ($ip =~ /^\Q$pattern\E/) { - my $last=(split(/\./,$ip))[3]; - if ($last <=$high && $last >=$low) { $allowed=1; } - } - } elsif ($pattern =~ /^\*/) { - #*.msu.edu - $pattern=~s/\*//; - if (!defined($name)) { - use Socket; - my $netaddr=inet_aton($ip); - ($name)=gethostbyaddr($netaddr,AF_INET); - } - if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } - } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) { - #127.0.0.1 - if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } - } else { - #some.name.com - if (!defined($name)) { - use Socket; - my $netaddr=inet_aton($ip); - ($name)=gethostbyaddr($netaddr,AF_INET); - } - if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } - } - if ($allowed) { last; } - } - return $allowed; -} - sub check_slot_access { my ($id,$type)=@_; @@ -307,7 +261,7 @@ sub check_slot_access { &Apache::lonhomework::showhash(%slot); if ($slot{'starttime'} < time && $slot{'endtime'} > time && - &check_ip_acc($slot{'ip'})) { + &Apache::loncommon::check_ip_acc($slot{'ip'})) { &Apache::lonxml::debug("$slot is good"); $slotstatus='NEEDS_CHECKIN'; $returned_slot=\%slot; @@ -383,8 +337,16 @@ sub check_slot_access { return ($slotstatus,$datemsg,$slot_name,$returned_slot); } -# JB, 9/24/2002: Any changes in this function may require a change -# in lonnavmaps::resource::getDateStatus. + +=pod + +=item check_access() + +JB, 9/24/2002: Any changes in this function may require a change +in lonnavmaps::resource::getDateStatus. + +=cut + sub check_access { my ($id) = @_; my $date =''; @@ -421,7 +383,7 @@ sub check_access { #if ($env{'request.state'} ne "construct" && $symb ne '') { if ($env{'request.state'} ne "construct") { my $idacc = &Apache::lonnet::EXT("resource.$id.acc"); - my $allowed=&check_ip_acc($idacc); + my $allowed=&Apache::loncommon::check_ip_acc($idacc); if (!$allowed && ($Apache::lonhomework::browse ne 'F')) { $status='INVALID_ACCESS'; $date=&mt("can not be accessed from your location."); @@ -532,7 +494,16 @@ sub check_access { return ($status,$datemsg); } -# this should work exactly like the copy in lonnavmaps.pm + + +=pod + +=item due_date() + + this should work exactly like the copy in lonnavmaps.pm + +=cut + sub due_date { my ($part_id,$symb,$udom,$uname)=@_; my $date; @@ -935,8 +906,11 @@ sub editxmlmode { my $js = &Apache::edit::js_change_detection(). &Apache::loncommon::resize_textarea_js(). - &Apache::structuretags::setmode_javascript(); + &Apache::structuretags::setmode_javascript(). + &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); my $only_body = ($env{'environment.remote'} eq 'off')? 0 : 1; + my $dragmath_button = + &Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1); my $start_page = &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js, {'no_auto_mt_title' => 1, @@ -959,10 +933,12 @@ sub editxmlmode {
+ + '.$dragmath_button.'
@@ -985,9 +961,14 @@ sub editxmlmode { return ''; } -# -# Render the page in whatever target desired. -# +=pod + +=item renderpage() + + Render the page in whatever target desired. + +=cut + sub renderpage { my ($request,$file,$targets,$return_string) = @_; @@ -1079,8 +1060,10 @@ sub get_template_list { } my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. '/templates/*.'.$glob_extension); - @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title'))]} (@files); - @files = sort {$a->[1] cmp $b->[1]} (@files); + @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')), + (&Apache::lonnet::metadata($_, 'category')?&mt(&Apache::lonnet::metadata($_, 'category')):&mt('Miscellaneous')), + &mt(&Apache::lonnet::metadata($_, 'help'))]} (@files); + @files = sort {$a->[2].$a->[1] cmp $b->[2].$b->[1]} (@files); my ($midpoint,$seconddiv,$numfiles); $numfiles = 0; foreach my $file (@files) { @@ -1095,16 +1078,28 @@ sub get_template_list { } } my $count = 0; + my $currentcategory=''; foreach my $file (@files) { next if ($file->[1] !~ /\S/); + if ($file->[2] ne $currentcategory) { + $currentcategory=$file->[2]; + if ((!$seconddiv) && ($count >= $midpoint)) { + $result .= '
'."\n".'
'."\n"; + $seconddiv = 1; + } + $result.='

'.$currentcategory.'

'; + $count++; + } $result .= '
'."\n"; - $count ++; - if ((!$seconddiv) && ($count >= $midpoint)) { - $result .= '
'."\n".'
'."\n"; - $seconddiv = 1; + $file->[1].''; + if ($file->[3]) { + $result.=&Apache::loncommon::help_open_topic($file->[3]); } + my $filename=$file->[0]; + $filename=~s/^\/home\/httpd\/html//; + $result.=' '.&mt('Example').'
'."\n"; + $count ++; } if ($numfiles > 0) { $result .= '
'."\n".''."\n"; @@ -1176,8 +1171,8 @@ sub update_construct_style { &Apache::lonnet::delenv('construct\\.style'); } elsif ($env{'form.style_file'} && $env{'construct.style'} ne $env{'form.style_file'}) { - &Apache::lonnet::appenv('construct.style' => - $env{'form.style_file'}); + &Apache::lonnet::appenv({'construct.style' => + $env{'form.style_file'}}); } } }