Diff for /loncom/homework/lonhomework.pm between versions 1.291 and 1.299

version 1.291, 2008/03/12 02:46:53 version 1.299, 2008/11/19 18:34:56
Line 85  sub set_bubble_lines { Line 85  sub set_bubble_lines {
     }      }
 }  }
   
 #  =pod
 # Decides what targets to render for.  
 # Implicit inputs:  =item get_target()
 #   Various session environment variables:  
 #      request.state -  published  - is a /res/ resource  Decides what targets to render for.
 #                       uploaded   - is a /uploaded/ resource  Implicit inputs:
 #                       contruct   - is a /priv/ resource    Various session environment variables:
 #      form.grade_target - a form parameter requesting a specific target       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 {  sub get_target {
     &Apache::lonxml::debug("request.state = $env{'request.state'}");      &Apache::lonxml::debug("request.state = $env{'request.state'}");
     if( defined($env{'form.grade_target'})) {      if( defined($env{'form.grade_target'})) {
Line 209  sub proctor_checked_in { Line 215  sub proctor_checked_in {
     return 0;      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 {  sub check_slot_access {
     my ($id,$type)=@_;      my ($id,$type)=@_;
   
Line 307  sub check_slot_access { Line 261  sub check_slot_access {
  &Apache::lonhomework::showhash(%slot);   &Apache::lonhomework::showhash(%slot);
  if ($slot{'starttime'} < time &&   if ($slot{'starttime'} < time &&
     $slot{'endtime'} > time &&      $slot{'endtime'} > time &&
     &check_ip_acc($slot{'ip'})) {      &Apache::loncommon::check_ip_acc($slot{'ip'})) {
     &Apache::lonxml::debug("$slot is good");      &Apache::lonxml::debug("$slot is good");
     $slotstatus='NEEDS_CHECKIN';      $slotstatus='NEEDS_CHECKIN';
     $returned_slot=\%slot;      $returned_slot=\%slot;
Line 383  sub check_slot_access { Line 337  sub check_slot_access {
     return ($slotstatus,$datemsg,$slot_name,$returned_slot);      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 {  sub check_access {
     my ($id) = @_;      my ($id) = @_;
     my $date ='';      my $date ='';
Line 421  sub check_access { Line 383  sub check_access {
     #if ($env{'request.state'} ne "construct" && $symb ne '') {      #if ($env{'request.state'} ne "construct" && $symb ne '') {
     if ($env{'request.state'} ne "construct") {      if ($env{'request.state'} ne "construct") {
         my $idacc = &Apache::lonnet::EXT("resource.$id.acc");          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')) {   if (!$allowed && ($Apache::lonhomework::browse ne 'F')) {
     $status='INVALID_ACCESS';      $status='INVALID_ACCESS';
     $date=&mt("can not be accessed from your location.");      $date=&mt("can not be accessed from your location.");
Line 532  sub check_access { Line 494  sub check_access {
   
     return ($status,$datemsg);      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 {  sub due_date {
     my ($part_id,$symb,$udom,$uname)=@_;      my ($part_id,$symb,$udom,$uname)=@_;
     my $date;      my $date;
Line 935  sub editxmlmode { Line 906  sub editxmlmode {
  my $js =   my $js =
     &Apache::edit::js_change_detection().       &Apache::edit::js_change_detection(). 
     &Apache::loncommon::resize_textarea_js().      &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 $only_body =  ($env{'environment.remote'} eq 'off')? 0 : 1;
    my $dragmath_button = 
               &Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1);
  my $start_page =    my $start_page = 
     &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js,      &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js,
    {'no_auto_mt_title' => 1,     {'no_auto_mt_title' => 1,
Line 959  sub editxmlmode { Line 933  sub editxmlmode {
               </table>                </table>
               <div class="LC_edit_problem_discards">                <div class="LC_edit_problem_discards">
                 <input type="hidden" name="problemmode" value="editxml" />                  <input type="hidden" name="problemmode" value="editxml" />
   
                 <input type="button" name="submitmode" accesskey="d" value="'.&mt('Discard Edits and View').'" '.                  <input type="button" name="submitmode" accesskey="d" value="'.&mt('Discard Edits and View').'" '.
                 'onclick="javascript:setmode(this.form,'."'discard'".')" />                  'onclick="javascript:setmode(this.form,'."'discard'".')" />
                 <input type="button" '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'edit'".')').'name="submitmode" accesskey="e" value="'.&mt('Edit').'" />                  <input type="button" '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'edit'".')').'name="submitmode" accesskey="e" value="'.&mt('Edit').'" />
                 <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />                  <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
                   '.$dragmath_button.'
               </div>                </div>
               <div class="LC_edit_problem_saves">                <div class="LC_edit_problem_saves">
                 <input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'"  />                  <input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'"  />
Line 985  sub editxmlmode { Line 961  sub editxmlmode {
     return '';      return '';
 }  }
   
 #  =pod
 #    Render the page in whatever target desired.  
 #  =item renderpage()
   
       Render the page in whatever target desired.
   
   =cut
   
 sub renderpage {  sub renderpage {
     my ($request,$file,$targets,$return_string) = @_;      my ($request,$file,$targets,$return_string) = @_;
   
Line 1079  sub get_template_list { Line 1060  sub get_template_list {
     }      }
     my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}.      my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}.
      '/templates/*.'.$glob_extension);       '/templates/*.'.$glob_extension);
     @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title'))]} (@files);      @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')),
     @files = sort {$a->[1] cmp $b->[1]} (@files);                        (&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);      my ($midpoint,$seconddiv,$numfiles);
     $numfiles = 0;      $numfiles = 0;
     foreach my $file (@files) {      foreach my $file (@files) {
Line 1095  sub get_template_list { Line 1078  sub get_template_list {
         }          }
     }      }
     my $count = 0;      my $count = 0;
       my $currentcategory='';
     foreach my $file (@files) {      foreach my $file (@files) {
  next if ($file->[1] !~ /\S/);   next if ($file->[1] !~ /\S/);
           if ($file->[2] ne $currentcategory) {
              $currentcategory=$file->[2];
              if ((!$seconddiv) && ($count >= $midpoint)) {
                  $result .= '</div>'."\n".'<div class="LC_left_float">'."\n";
                  $seconddiv = 1;
              }
              $result.='<h3>'.$currentcategory.'</h3>';
              $count++;
           }
  $result .=   $result .=
     '<label><input type="radio" name="template" value="'.$file->[0].'" />'.      '<label><input type="radio" name="template" value="'.$file->[0].'" />'.
     $file->[1].'</label><br />'."\n";      $file->[1].'</label>';
         $count ++;          if ($file->[3]) {
         if ((!$seconddiv) && ($count >= $midpoint)) {             $result.=&Apache::loncommon::help_open_topic($file->[3]);
             $result .= '</div>'."\n".'<div class="LC_left_float">'."\n";  
             $seconddiv = 1;  
         }          }
           my $filename=$file->[0];
           $filename=~s/^\/home\/httpd\/html//;
           $result.=' <font size="-2"><a href="'.$filename.'" target="sample">'.&mt('Example').'</font></a><br />'."\n";
           $count ++;
     }      }
     if ($numfiles > 0) {      if ($numfiles > 0) {
         $result .= '</div>'."\n".'<div class="LC_clear_float_footer"></div>'."\n";          $result .= '</div>'."\n".'<div class="LC_clear_float_footer"></div>'."\n";

Removed from v.1.291  
changed lines
  Added in v.1.299


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