Diff for /loncom/homework/lonhomework.pm between versions 1.147 and 1.153

version 1.147, 2003/09/18 20:35:30 version 1.153, 2003/10/14 15:47:50
Line 90  sub get_target { Line 90  sub get_target {
  return ('web');   return ('web');
     }      }
  } else {   } else {
     if ( $ENV{'form.problemmode'} eq 'View' ||      if ( $ENV{'form.problemmode'} eq &mt('View') ||
  $ENV{'form.problemmode'} eq 'Discard Edits and View') {   $ENV{'form.problemmode'} eq &mt('Discard Edits and View')) {
  if ( defined($ENV{'form.submitted'}) &&   if ( defined($ENV{'form.submitted'}) &&
      (!defined($ENV{'form.resetdata'})) &&       (!defined($ENV{'form.resetdata'})) &&
      (!defined($ENV{'form.newrandomization'}))) {       (!defined($ENV{'form.newrandomization'}))) {
Line 99  sub get_target { Line 99  sub get_target {
  } else {   } else {
     return ('web','answer');      return ('web','answer');
  }   }
     } elsif ( $ENV{'form.problemmode'} eq 'Edit' ) {      } elsif ( $ENV{'form.problemmode'} eq &mt('Edit') ) {
  if ( $ENV{'form.submitted'} eq 'edit' ) {   if ( $ENV{'form.submitted'} eq 'edit' ) {
     if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) {      if ( $ENV{'form.submit'} eq &mt('Submit Changes and View') ) {
  return ('modified','web','answer');   return ('modified','web','answer');
     } else {      } else {
  return ('modified','edit');   return ('modified','edit');
Line 147  sub send_footer { Line 147  sub send_footer {
   
 $Apache::lonxml::browse='';  $Apache::lonxml::browse='';
   
   sub check_ip_acc {
       my ($acc)=@_;
       if (!defined($acc)) { return 1; }
       my $allowed=0;
       my $ip=$ENV{'REMOTE_ADDR'};
       my $name;
       foreach my $pattern (split(',',$acc)) {
    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;
   }
 # JB, 9/24/2002: Any changes in this function may require a change  # JB, 9/24/2002: Any changes in this function may require a change
 # in lonnavmaps::resource::getDateStatus.  # in lonnavmaps::resource::getDateStatus.
 sub check_access {  sub check_access {
Line 168  sub check_access { Line 213  sub check_access {
   
     &Apache::lonxml::debug("checking for part :$id:");      &Apache::lonxml::debug("checking for part :$id:");
     &Apache::lonxml::debug("time:".time);      &Apache::lonxml::debug("time:".time);
       
       my $allowed=&check_ip_acc(&Apache::lonnet::EXT("resource.$id.acc"));
       if (!$allowed) {
    $status='INVALID_ACCESS';
    $date=&mt("may be open from a different computer.");
    return($status,$date);
       }
   
     foreach $temp ("opendate","duedate","answerdate") {      foreach $temp ("opendate","duedate","answerdate") {
  $lastdate = $date;   $lastdate = $date;
  $date = &Apache::lonnet::EXT("resource.$id.$temp");   $date = &Apache::lonnet::EXT("resource.$id.$temp");
Line 307  sub setuppermissions { Line 360  sub setuppermissions {
 sub setupheader {  sub setupheader {
     my $request=$_[0];      my $request=$_[0];
     if ($ENV{'browser.mathml'}) {      if ($ENV{'browser.mathml'}) {
  $request->content_type('text/xml');   &Apache::loncommon::content_type($request,'text/xml');
     } else {      } else {
  $request->content_type('text/html');   &Apache::loncommon::content_type($request,'text/html');
     }      }
     $request->content_encoding('UTF-8');  
     if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {      if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
  &Apache::loncommon::no_cache($request);   &Apache::loncommon::no_cache($request);
     }      }
Line 327  sub handle_save_or_undo { Line 379  sub handle_save_or_undo {
     my $filetmp =$file.".tmp";      my $filetmp =$file.".tmp";
     my $error=0;      my $error=0;
   
     if ($ENV{'form.Undo'} eq 'undo') {      if ($ENV{'form.Undo'} eq &mt('undo')) {
  my $error=0;   my $error=0;
  if (!copy($file,$filetmp)) { $error=1; }   if (!copy($file,$filetmp)) { $error=1; }
  if ((!$error) && (!copy($filebak,$file))) { $error=1; }   if ((!$error) && (!copy($filebak,$file))) { $error=1; }
Line 445  sub analyze { Line 497  sub analyze {
  }   }
     }      }
     if (scalar(keys(%allparts)) == 0 ) {      if (scalar(keys(%allparts)) == 0 ) {
  $request->print('<p>'.&mt('Found no analyzable parts in this problem,   $request->print('<p>'.&mt('Found no analyzable parts in this problem, currently only Numerical, Formula and String response styles are supported.').'</p>');
                          currently only Numerical, Formula and String response  
                          styles are supported.').'</p>');  
     }      }
     &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);      &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);
     &analyze_footer($request);      &analyze_footer($request);
Line 470  sub editxmlmode { Line 520  sub editxmlmode {
  if (!$error) { $problem=&Apache::lonnet::getfile($file); }   if (!$error) { $problem=&Apache::lonnet::getfile($file); }
     }      }
     &Apache::lonhomework::showhashsubset(\%ENV,'^form');      &Apache::lonhomework::showhashsubset(\%ENV,'^form');
     if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) {      if ( $ENV{'form.submit'} eq &mt('Submit Changes and View') ) {
  &Apache::lonhomework::showhashsubset(\%ENV,'^form');   &Apache::lonhomework::showhashsubset(\%ENV,'^form');
  $ENV{'form.problemmode'}='View';   $ENV{'form.problemmode'}='View';
  &renderpage($request,$file);   &renderpage($request,$file);
Line 609  sub newproblem { Line 659  sub newproblem {
   'button' => 'button');    'button' => 'button');
  $request->print(<<ENDNEWPROBLEM);   $request->print(<<ENDNEWPROBLEM);
 <body bgcolor="#FFFFFF">  <body bgcolor="#FFFFFF">
 <h1>$lt{'create'} $extension &lt{'resource'}</h1>  <h1>$lt{'create'} $extension $lt{'resource'}</h1>
 $errormsg  $errormsg
 $lt{'requested'} <tt>$url</tt> $lt{'not exist'}.  $lt{'requested'} <tt>$url</tt> $lt{'not exist'}.
 <p>  <p>
Line 686  sub handler { Line 736  sub handler {
     my ($symb) = &Apache::lonxml::whichuser();      my ($symb) = &Apache::lonxml::whichuser();
     &Apache::lonxml::debug('symb is '.$symb);      &Apache::lonxml::debug('symb is '.$symb);
     if ($ENV{'request.state'} eq "construct" || $symb eq '') {      if ($ENV{'request.state'} eq "construct" || $symb eq '') {
  if ($ENV{'form.resetdata'} eq 'Reset Submissions' ||   if ($ENV{'form.resetdata'} eq &mt('Reset Submissions') ||
     $ENV{'form.resetdata'} eq 'New Problem Variation' ||      $ENV{'form.resetdata'} eq &mt('New Problem Variation') ||
     $ENV{'form.newrandomization'} eq 'New Randomization') {      $ENV{'form.newrandomization'} eq &mt('New Randomization')) {
     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();      my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
     &Apache::lonnet::tmpreset($symb,'',$domain,$name);      &Apache::lonnet::tmpreset($symb,'',$domain,$name);
     &Apache::lonxml::debug("Attempt reset");      &Apache::lonxml::debug("Attempt reset");
Line 703  sub handler { Line 753  sub handler {
  #&view_or_edit_menu($request);   #&view_or_edit_menu($request);
  $ENV{'form.problemmode'}='View';   $ENV{'form.problemmode'}='View';
  &renderpage($request,$file);   &renderpage($request,$file);
     } elsif ($ENV{'form.problemmode'} eq 'EditXML') {      } elsif ($ENV{'form.problemmode'} eq &mt('EditXML')) {
  &editxmlmode($request,$file);   &editxmlmode($request,$file);
     } elsif ($ENV{'form.problemmode'} eq 'Calculate answers') {      } elsif ($ENV{'form.problemmode'} eq &mt('Calculate answers')) {
  &analyze($request,$file);   &analyze($request,$file);
     } else {      } else {
  &renderpage($request,$file);   &renderpage($request,$file);

Removed from v.1.147  
changed lines
  Added in v.1.153


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>