Diff for /loncom/interface/lonnavmaps.pm between versions 1.423.2.2 and 1.428

version 1.423.2.2, 2009/08/15 18:46:22 version 1.428, 2009/02/25 15:25:21
Line 31 Line 31
   
 =head1 NAME  =head1 NAME
   
 Apache::lonnavmaps - Subroutines to handle and render the navigation  Apache::lonnavmaps.pm
   
 =head1 SYNOPSIS  =head1 SYNOPSIS
   
Line 530  my %colormap = Line 530  my %colormap =
 # is not yet done and due in less than 24 hours  # is not yet done and due in less than 24 hours
 my $hurryUpColor = "#FF0000";  my $hurryUpColor = "#FF0000";
   
 my $future_slots_checked = 0;  
 my $future_slots = 0;  
   
 sub close {  sub close {
     if ($env{'environment.remotenavmap'} ne 'on') { return ''; }      if ($env{'environment.remotenavmap'} ne 'on') { return ''; }
     return(<<ENDCLOSE);      return(<<ENDCLOSE);
Line 637  sub getDescription { Line 634  sub getDescription {
     if ($status == $res->OPEN_LATER) {      if ($status == $res->OPEN_LATER) {
         return &mt("Open ") .timeToHumanString($open,'start');          return &mt("Open ") .timeToHumanString($open,'start');
     }      }
     if ($res->simpleStatus($part) == $res->OPEN) {  
         unless (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {  
             my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);  
             if ($slot_status == $res->UNKNOWN) {  
                 return &mt('Reservation status unknown');  
             } elsif ($slot_status == $res->RESERVED) {  
                 return &mt('Reserved - ends [_1]',  
                            timeToHumanString($slot_time,'end'));  
             } elsif ($slot_status == $res->RESERVED_LOCATION) {  
                 return &mt('Reserved - specific location(s) - ends [_1]',  
                            timeToHumanString($slot_time,'end'));  
             } elsif ($slot_status == $res->RESERVED_LATER) {  
                 return &mt('Reserved - next open [_1]',  
                            timeToHumanString($slot_time,'start'));  
             } elsif ($slot_status == $res->RESERVABLE) {  
                 return &mt('Reservable ending [_1]',  
                            timeToHumanString($slot_time,'end'));  
             } elsif ($slot_status == $res->RESERVABLE_LATER) {  
                 return &mt('Reservable starting [_1]',  
                            timeToHumanString($slot_time,'start'));  
             } elsif ($slot_status == $res->NOT_IN_A_SLOT) {  
                 return &mt('Reserve a time/place to work');  
             } elsif ($slot_status == $res->NOTRESERVABLE) {  
                 return &mt('Reservation not available');  
             } elsif ($slot_status == $res->WAITING_FOR_GRADE) {  
                 return &mt('Submission in grading queue');  
             }  
         }  
     }  
     if ($status == $res->OPEN) {      if ($status == $res->OPEN) {
         if ($due) {          if ($due) {
     if ($res->is_practice()) {      if ($res->is_practice()) {
Line 897  sub render_resource { Line 865  sub render_resource {
     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");      my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
     # If this is a new branch, label it so      # If this is a new branch, label it so
     if ($params->{'isNewBranch'}) {      if ($params->{'isNewBranch'}) {
         $newBranchText = '<img src="'.$location.'/branch.gif" border="0" alt="'.          $newBranchText = "<img src='$location/branch.gif' alt='Branch' />";
                          &mt('Branch').'" />';  
     }      }
   
     # links to open and close the folder      # links to open and close the folder
   
           my $whitespace = $location.'/whitespace_21.gif';
     my $linkopen = "<a href=\"$link\">";      my $linkopen = "<img src='$whitespace' alt='' />"."<a href=\"$link\">";
   
   
     my $linkclose = "</a>";      my $linkclose = "</a>";
   
     # Default icon: unknown page      # Default icon: unknown page
     my $icon = "<img src='$location/unknown.gif' alt='' border='0' alt='&nbsp;&nbsp;' ' />";      my $icon = "<img class=\"LC_contentImage\" src='$location/unknown.gif' alt='' />";
           
     if ($resource->is_problem()) {      if ($resource->is_problem()) {
         if ($part eq '0' || $params->{'condensed'}) {          if ($part eq '0' || $params->{'condensed'}) {
     $icon = '<img src="'.$location.'/';      $icon = '<img class="LC_contentImage" src="'.$location.'/';
     if ($resource->is_task()) {      if ($resource->is_task()) {
  $icon .= 'task.gif" alt="'.&mt('Task');   $icon .= 'task.gif" alt="'.&mt('Task');
     } else {      } else {
  $icon .= 'problem.gif" alt="'.&mt('Problem');   $icon .= 'problem.gif" alt="'.&mt('Problem');
     }      }
     $icon .='" border="0" />';      $icon .='" />';
         } else {          } else {
             $icon = $params->{'indentString'};              $icon = $params->{'indentString'};
         }          }
     } else {      } else {
  $icon = "<img src='".&Apache::loncommon::icon($resource->src)."' alt='&nbsp;&nbsp;' border='0' />";   $icon = "<img class=\"LC_contentImage\" src='".&Apache::loncommon::icon($resource->src)."' alt='' />";
     }      }
   
     # Display the correct map icon to open or shut map      # Display the correct map icon to open or shut map
Line 935  sub render_resource { Line 900  sub render_resource {
         if ($it->{CONDITION}) {          if ($it->{CONDITION}) {
             $nowOpen = !$nowOpen;              $nowOpen = !$nowOpen;
         }          }
   
  my $folderType = $resource->is_sequence() ? 'folder' : 'page';   my $folderType = $resource->is_sequence() ? 'folder' : 'page';
         my $title=$resource->title;          my $title=$resource->title;
         $title=~s/\"/\&quot;/g;   $title=~s/\"/\&qout;/g;
         if (!$params->{'resource_no_folder_link'}) {          if (!$params->{'resource_no_folder_link'}) {
             $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';              $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
     $icon = "<img src='$location/$icon' alt=\"".              $icon = "<img src='$location/arrow." . ($nowOpen ? 'closed' : 'open') . ".gif' alt='' />"
  ($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" border='0' />";                      ."<img class=\"LC_contentImage\" src='$location/$icon' alt=\""
                       .($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
             $linkopen = "<a href=\"" . $params->{'url'} . '?' .               $linkopen = "<a href=\"" . $params->{'url'} . '?' . 
                 $params->{'queryString'} . '&amp;filter=';                  $params->{'queryString'} . '&amp;filter=';
             $linkopen .= ($nowOpen xor $it->{CONDITION}) ?              $linkopen .= ($nowOpen xor $it->{CONDITION}) ?
Line 958  sub render_resource { Line 923  sub render_resource {
   
         } else {          } else {
             # Don't allow users to manipulate folder              # Don't allow users to manipulate folder
             $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') .              $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
                 '.nomanip.gif';              $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
             $icon = "<img src='$location/$icon' alt=\"".  
  ($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" border='0' />";  
   
             $linkopen = "";              $linkopen = "";
             $linkclose = "";              $linkclose = "";
Line 977  sub render_resource { Line 940  sub render_resource {
     if (($resource->is_practice()) && ($resource->is_raw_problem())) {      if (($resource->is_practice()) && ($resource->is_raw_problem())) {
         $nonLinkedText .=' <font color="green"><b>'.&mt('not graded').'</b></font>';          $nonLinkedText .=' <font color="green"><b>'.&mt('not graded').'</b></font>';
     }      }
    
     # We're done preparing and finally ready to start the rendering  
     my $result = "<td align='left' valign='middle'>";  
   
       # We're done preparing and finally ready to start the rendering
       my $result = '<td class="LC_middle">';
       my $newfolderType = $resource->is_sequence() ? 'folder' : 'page';
   
     my $indentLevel = $params->{'indentLevel'};      my $indentLevel = $params->{'indentLevel'};
     if ($newBranchText) { $indentLevel--; }      if ($newBranchText) { $indentLevel--; }
   
Line 990  sub render_resource { Line 954  sub render_resource {
     }      }
   
     # Decide what to display      # Decide what to display
   
     $result .= "$newBranchText$linkopen$icon$linkclose";      $result .= "$newBranchText$linkopen$icon$linkclose";
           
     my $curMarkerBegin = '';      my $curMarkerBegin = '';
Line 999  sub render_resource { Line 962  sub render_resource {
     # Is this the current resource?      # Is this the current resource?
     if (!$params->{'displayedHereMarker'} &&       if (!$params->{'displayedHereMarker'} && 
         $resource->symb() eq $params->{'here'} ) {          $resource->symb() eq $params->{'here'} ) {
         $curMarkerBegin = '<span class="LC_fontcolor_red LC_fontsize_large">&gt;</span>';          $curMarkerBegin = '<em style="font-weight:bold;">';
         $curMarkerEnd = '<span class="LC_fontcolor_red LC_fontsize_large">&lt;</span>';          $curMarkerEnd = '</em>';
         $params->{'displayedHereMarker'} = 1;   $params->{'displayedHereMarker'} = 1;
     }      }
   
     if ($resource->is_problem() && $part ne '0' &&       if ($resource->is_problem() && $part ne '0' && 
Line 1021  sub render_resource { Line 984  sub render_resource {
  $target=' target="loncapaclient" ';   $target=' target="loncapaclient" ';
     }      }
     if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {      if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
         $result .= "  $curMarkerBegin<a $target href=\"$link\">$title$partLabel</a>$curMarkerEnd $nonLinkedText</td>";          $result .= "$curMarkerBegin<a $target href=\"$link\">$title$partLabel</a>$curMarkerEnd$nonLinkedText</td>";
     } else {      } else {
         $result .= "  $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText</td>";          $result .= "$curMarkerBegin$linkopen$title$partLabel</a>$curMarkerEnd$nonLinkedText</td>";
     }      }
   
     return $result;      return $result;
Line 1043  sub render_communication_status { Line 1006  sub render_communication_status {
     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");      my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
     if ($resource->hasDiscussion()) {      if ($resource->hasDiscussion()) {
         $discussionHTML = $linkopen .          $discussionHTML = $linkopen .
             '<img alt="'.&mt('New Discussion').'" border="0" src="'.$location.'/chat.gif" />' .              '<img alt="'.&mt('New Discussion').'" src="'.$location.'/chat.gif" />' .
             $linkclose;              $linkclose;
     }      }
           
Line 1053  sub render_communication_status { Line 1016  sub render_communication_status {
             if ($msgid) {              if ($msgid) {
                 $feedbackHTML .= '&nbsp;<a '.$target.' href="/adm/email?display='                  $feedbackHTML .= '&nbsp;<a '.$target.' href="/adm/email?display='
                     . &escape($msgid) . '">'                      . &escape($msgid) . '">'
                     . '<img alt="'.&mt('New E-mail').'" src="'.$location.'/feedback.gif" '                      . '<img alt="'.&mt('New E-mail').'" src="'.$location.'/feedback.gif" /></a>';
                     . 'border="0" /></a>';  
             }              }
         }          }
     }      }
Line 1068  sub render_communication_status { Line 1030  sub render_communication_status {
                 $errorcount++;                  $errorcount++;
                 $errorHTML .= '&nbsp;<a '.$target.' href="/adm/email?display='                  $errorHTML .= '&nbsp;<a '.$target.' href="/adm/email?display='
                     . &escape($msgid) . '">'                      . &escape($msgid) . '">'
                     . '<img alt="'.&mt('New Error').'" src="'.$location.'/bomb.gif" '                      . '<img alt="'.&mt('New Error').'" src="'.$location.'/bomb.gif" /></a>';
                     . 'border="0" /></a>';  
             }              }
         }          }
     }      }
Line 1077  sub render_communication_status { Line 1038  sub render_communication_status {
     if ($params->{'multipart'} && $part != '0') {      if ($params->{'multipart'} && $part != '0') {
  $discussionHTML = $feedbackHTML = $errorHTML = '';   $discussionHTML = $feedbackHTML = $errorHTML = '';
     }      }
       return "<td class=\"LC_middle\">$discussionHTML$feedbackHTML$errorHTML&nbsp;</td>";
     return "<td width=\"75\" align=\"left\" valign=\"middle\">$discussionHTML$feedbackHTML$errorHTML&nbsp;</td>";  
   
 }  }
 sub render_quick_status {  sub render_quick_status {
Line 1094  sub render_quick_status { Line 1054  sub render_quick_status {
     }      }
     my $linkopen = "<a $target href=\"$link\">";      my $linkopen = "<a $target href=\"$link\">";
     my $linkclose = "</a>";      my $linkclose = "</a>";
   
    $result .= '<td class="LC_middle">';
     if ($resource->is_problem() &&      if ($resource->is_problem() &&
         !$firstDisplayed) {          !$firstDisplayed) {
   
         my $icon = $statusIconMap{$resource->simpleStatus($part)};          my $icon = $statusIconMap{$resource->simpleStatus($part)};
         my $alt = $iconAltTags{$icon};          my $alt = $iconAltTags{$icon};
         if ($icon) {          if ($icon) {
     my $location=      my $location=
  &Apache::loncommon::lonhttpdurl("/adm/lonIcons/$icon");   &Apache::loncommon::lonhttpdurl("/adm/lonIcons/$icon");
             $result .= "<td valign='middle' width='50' align='right'>$linkopen<img width='25' height='25' src='$location' border='0' alt='$alt' />$linkclose</td>\n";              $result .= "$linkopen<img src='$location' alt='$alt' />$linkclose";
         } else {          } else {
             $result .= "<td width='30'>&nbsp;</td>\n";              $result .= "&nbsp;";
         }          }
     } else { # not problem, no icon      } else { # not problem, no icon
         $result .= "<td width='30'>&nbsp;</td>\n";          $result .= "&nbsp;";
     }      }
    $result .= "</td>\n";
     return $result;      return $result;
 }  }
 sub render_long_status {  sub render_long_status {
     my ($resource, $part, $params) = @_;      my ($resource, $part, $params) = @_;
     my $result = "<td align='right' valign='middle'>\n";      my $result = '<td class="LC_middle LC_right">';
     my $firstDisplayed = !$params->{'condensed'} &&       my $firstDisplayed = !$params->{'condensed'} && 
         $params->{'multipart'} && $part eq "0";          $params->{'multipart'} && $part eq "0";
                                   
Line 1419  sub render { Line 1379  sub render {
     my $printKey = $args->{'printKey'};      my $printKey = $args->{'printKey'};
     my $printCloseAll = $args->{'printCloseAll'};      my $printCloseAll = $args->{'printCloseAll'};
     if (!defined($printCloseAll)) { $printCloseAll = 1; }      if (!defined($printCloseAll)) { $printCloseAll = 1; }
      
     # Print key?      # Print key?
     if ($printKey) {      if ($printKey) {
         $result .= '<table border="0" cellpadding="2" cellspacing="0">';          $result .= '<table border="0" cellpadding="2" cellspacing="0">';
Line 1427  sub render { Line 1387  sub render {
  my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");   my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
         if ($navmap->{LAST_CHECK}) {          if ($navmap->{LAST_CHECK}) {
             $result .=               $result .= 
                 '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('New discussion since').' '.                  '<img src="'.$location.'/chat.gif"> '.&mt('New discussion since').' '.
                 strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).                  strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).
                 '</td><td align="center" valign="bottom">&nbsp;&nbsp;'.                  '</td><td align="center" valign="bottom">&nbsp;&nbsp;'.
                 '<img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').'<p>'.                  '<img src="'.$location.'/feedback.gif"> '.&mt('New message (click to open)').'<p>'.
                 '</td>';                   '</td>'; 
         } else {          } else {
             $result .= '<td align="center" valign="bottom">&nbsp;&nbsp;'.              $result .= '<td align="center" valign="bottom">&nbsp;&nbsp;'.
                 '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('Discussions').'</td><td align="center" valign="bottom">'.                  '<img src="'.$location.'/chat.gif"> '.&mt('Discussions').'</td><td align="center" valign="bottom">'.
                 '&nbsp;&nbsp;<img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').                  '&nbsp;&nbsp;<img src="'.$location.'/feedback.gif"> '.&mt('New message (click to open)').
                 '</td>';                   '</td>'; 
         }          }
   
Line 1494  END Line 1454  END
  $result.='</form>';   $result.='</form>';
     }      }
   
      
     if ($args->{'caller'} eq 'navmapsdisplay') {      if ($args->{'caller'} eq 'navmapsdisplay') {
         $result .= '<table><tr><td>'.          $result .= '<table><tr><td>'.
                    &Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT').'</td>';                     &Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT').'</td>';
Line 1517  END Line 1478  END
         $result.=$args->{'sort_html'};           $result.=$args->{'sort_html'}; 
     }      }
   
     $result .= "<br />\n";      #$result .= "<br />\n";
     if ($r) {      if ($r) {
         $r->print($result);          $r->print($result);
         $r->rflush();          $r->rflush();
         $result = "";          $result = "";
     }      }
     # End parameter setting      # End parameter setting
                   
       $result .= "\n<table id=\"LC_nav_location\">\n<tbody>\n<tr>\n<td class=\"LC_current_location\"> &nbsp; </td>\n</tr>\n</tbody>\n</table>\n";
       $result .= "<br />\n";
   
     # Data      # Data
     $result .= '<table cellspacing="0" cellpadding="3" border="0" bgcolor="#FFFFFF">' ."\n";      $result .= '<table id="LC_tableOfContent">' ."\n";
   
     my $res = "Apache::lonnavmaps::resource";      my $res = "Apache::lonnavmaps::resource";
     my %condenseStatuses =      my %condenseStatuses =
         ( $res->NETWORK_FAILURE    => 1,          ( $res->NETWORK_FAILURE    => 1,
           $res->NOTHING_SET        => 1,            $res->NOTHING_SET        => 1,
           $res->CORRECT            => 1 );            $res->CORRECT            => 1 );
     my @backgroundColors = ("#FFFFFF", "#F6F6F6");      my @backgroundColors = ("LC_trEven", "LC_trOdd");
   
     # Shared variables      # Shared variables
     $args->{'counter'} = 0; # counts the rows      $args->{'counter'} = 0; # counts the rows
     $args->{'indentLevel'} = 0;      $args->{'indentLevel'} = 0;
     $args->{'isNewBranch'} = 0;      $args->{'isNewBranch'} = 0;
     $args->{'condensed'} = 0;          $args->{'condensed'} = 0;   
     my $location=  
  &Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace1.gif");      my $location = &Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
     $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='$location' width='25' height='1' alt='&nbsp;&nbsp;' border='0' />");      $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='$location' alt='' />");
     $args->{'displayedHereMarker'} = 0;      $args->{'displayedHereMarker'} = 0;
   
     # If we're suppressing empty sequences, look for them here. Use DFS for speed,      # If we're suppressing empty sequences, look for them here. Use DFS for speed,
Line 1769  END Line 1734  END
             $rownum ++;              $rownum ++;
             my $backgroundColor = $backgroundColors[$rownum % scalar(@backgroundColors)];              my $backgroundColor = $backgroundColors[$rownum % scalar(@backgroundColors)];
                           
             $result .= "  <tr bgcolor='$backgroundColor'>\n";              $result .= "  <tr class='$backgroundColor'>\n";
   
             # Set up some data about the parts that the cols might want              # Set up some data about the parts that the cols might want
             my $filter = $it->{FILTER};              my $filter = $it->{FILTER};
Line 3775  sub map_contains_problem { Line 3740  sub map_contains_problem {
 sub is_sequence {  sub is_sequence {
     my $self=shift;      my $self=shift;
     return $self->navHash("is_map_", 1) &&       return $self->navHash("is_map_", 1) && 
  $self->navHash("map_type_" . $self->map_pc()) eq 'sequence';      $self->navHash("map_type_" . $self->map_pc()) eq 'sequence';
 }  }
 sub is_survey {  sub is_survey {
     my $self = shift();      my $self = shift();
Line 3977  sub awarded { Line 3942  sub awarded {
     if (!defined($part)) { $part = '0'; }      if (!defined($part)) { $part = '0'; }
     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.awarded'};      return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.awarded'};
 }  }
 sub taskversion {  
     my $self = shift; my $part = shift;  
     $self->{NAV_MAP}->get_user_data();  
     if (!defined($part)) { $part = '0'; }  
     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.version'};  
 }  
 sub taskstatus {  
     my $self = shift; my $part = shift;  
     $self->{NAV_MAP}->get_user_data();  
     if (!defined($part)) { $part = '0'; }  
     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$self->taskversion($part).'.'.$part.'.status'};  
 }  
 sub solved {  
     my $self = shift; my $part = shift;  
     $self->{NAV_MAP}->get_user_data();  
     if (!defined($part)) { $part = '0'; }  
     return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.solved'};  
 }  
 sub checkedin {  
     my $self = shift; my $part = shift;  
     $self->{NAV_MAP}->get_user_data();  
     if (!defined($part)) { $part = '0'; }  
     if ($self->is_task()) {  
         my $version = $self->taskversion($part);  
         return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$version .'.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$version .'.'.$part.'.checkedin.slot'});  
     } else {  
         return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.checkedin.slot'});  
     }  
 }  
 # this should work exactly like the copy in lonhomework.pm  # this should work exactly like the copy in lonhomework.pm
 sub duedate {  sub duedate {
     (my $self, my $part) = @_;      (my $self, my $part) = @_;
Line 4101  sub part_display { Line 4037  sub part_display {
     }      }
     return $display;      return $display;
 }  }
 sub slot_control {  
     my $self=shift(); my $part = shift();  
     if (!defined($part)) { $part = '0'; }  
     my $useslots = $self->parmval("useslots", $part);  
     my $availablestudent = $self->parmval("availablestudent", $part);  
     my $available = $self->parmval("available", $part);  
     return ($useslots,$availablestudent,$available);  
 }  
   
 # Multiple things need this  # Multiple things need this
 sub getReturnHash {  sub getReturnHash {
Line 4757  sub TRIES_LEFT       { return 20; } Line 4685  sub TRIES_LEFT       { return 20; }
 sub ANSWER_SUBMITTED { return 21; }  sub ANSWER_SUBMITTED { return 21; }
 sub PARTIALLY_CORRECT{ return 22; }  sub PARTIALLY_CORRECT{ return 22; }
   
 sub RESERVED_LATER    { return 30; }  
 sub RESERVED          { return 31; }  
 sub RESERVED_LOCATION { return 32; }  
 sub RESERVABLE        { return 33; }  
 sub RESERVABLE_LATER  { return 34; }  
 sub NOTRESERVABLE     { return 35; }  
 sub NOT_IN_A_SLOT     { return 36; }  
 sub NEEDS_CHECKIN     { return 37; }  
 sub WAITING_FOR_GRADE { return 38; }  
 sub UNKNOWN           { return 39; }  
   
 sub status {  sub status {
     my $self = shift;      my $self = shift;
     my $part = shift;      my $part = shift;
Line 4859  sub status { Line 4776  sub status {
     return OPEN;       return OPEN; 
 }  }
   
 sub check_for_slot {  
     my $self = shift;  
     my $part = shift;  
     my ($use_slots,$available,$availablestudent) = $self->slot_control($part);  
     if (($use_slots ne '') && ($use_slots !~ /^\s*no\s*$/i)) {  
         my @slots = (split(/:/,$availablestudent),split(/:/,$available));  
         my $cid=$env{'request.course.id'};  
         my $cdom=$env{'course.'.$cid.'.domain'};  
         my $cnum=$env{'course.'.$cid.'.num'};  
         my $now = time;  
         if (@slots > 0) {  
             my %slots=&Apache::lonnet::get('slots',[@slots],$cdom,$cnum);  
             if (&Apache::lonnet::error(%slots)) {  
                 return (UNKNOWN);  
             }  
             my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots);  
             my ($checkedin,$checkedinslot);  
             foreach my $slot_name (@sorted_slots) {  
                 next if (!defined($slots{$slot_name}) ||  
                          !ref($slots{$slot_name}));  
                 my $end = $slots{$slot_name}->{'endtime'};  
                 my $start = $slots{$slot_name}->{'starttime'};  
                 my $ip = $slots{$slot_name}->{'ip'};  
                 if ($self->simpleStatus() == OPEN) {  
                     my $startreserve = $slots{$slot_name}->{'startreserve'};  
                     my @proctors;  
                     if ($slots{$slot_name}->{'proctor'} ne '') {  
                         @proctors = split(',',$slots{$slot_name}->{'proctor'});  
                     }  
                     if ($end > $now) {  
                         ($checkedin,$checkedinslot) = $self->checkedin();  
                         if ($startreserve < $now) {  
                             if ($start > $now) {  
                                 return (RESERVED_LATER,$start,$slot_name);  
                             } else {  
                                 if ($ip ne '') {  
                                     if (!&Apache::loncommon::check_ip_acc($ip)) {  
                                         return (RESERVED_LOCATION,$ip,$slot_name);  
                                     }  
                                 }  
                                 if (@proctors > 0) {  
                                     unless ((grep(/^\Q$checkedin\E/,@proctors)) &&  
                                         ($checkedinslot eq $slot_name)) {  
                                         return (NEEDS_CHECKIN,undef,$slot_name);  
                                     }  
                                 }  
                                 return (RESERVED,$end,$slot_name);  
                             }  
                         } else {  
                             if ($start > $now) {  
                                 return (RESERVABLE,$startreserve,$slot_name);  
                             }  
                         }  
                     }  
                 }  
             }  
             my ($is_correct,$got_grade);  
             if ($self->is_task()) {  
                 my $taskstatus = $self->taskstatus();  
                 $is_correct = (($taskstatus eq 'pass') ||  
                                ($self->solved() =~ /^correct_/));  
                 $got_grade = ($self->solved() =~ /^(?:pass|fail)$/);  
             } else {  
                 $got_grade = 1;  
                 $is_correct = ($self->solved() =~ /^correct_/);  
             }  
             ($checkedin,$checkedinslot) = $self->checkedin();  
             if ($checkedin) {  
                 if (!$got_grade) {  
                     return (WAITING_FOR_GRADE);  
                 } elsif ($is_correct) {  
                     return (CORRECT);  
                 }  
             }  
             return(NOT_IN_A_SLOT);  
         } else {  
             if (!$future_slots_checked) {  
                 $future_slots = &get_future_slots($cdom,$cnum,$now);  
                 $future_slots_checked = 1;  
             }  
             if ($future_slots) {  
                 return(NOT_IN_A_SLOT);  
             }  
             return(NOTRESERVABLE);  
         }  
     }  
     return;  
 }  
   
 sub get_future_slots {  
     my ($cdom,$cnum,$now) = @_;  
     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);  
     my $future_slots = 0;  
     foreach my $slot (keys(%slots)) {  
         if (($slots{$slot}->{'starttime'} > $now) &&  
             ($slots{$slot}->{'endtime'} > $now)) {  
             $future_slots ++;  
         }  
     }  
     return $future_slots;  
 }  
   
 sub CLOSED { return 23; }  sub CLOSED { return 23; }
 sub ERROR { return 24; }  sub ERROR { return 24; }
   

Removed from v.1.423.2.2  
changed lines
  Added in v.1.428


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