--- loncom/interface/slotrequest.pm 2016/10/12 14:16:09 1.133 +++ loncom/interface/slotrequest.pm 2018/07/02 20:34:52 1.139 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler for requesting to have slots added to a students record # -# $Id: slotrequest.pm,v 1.133 2016/10/12 14:16:09 raeburn Exp $ +# $Id: slotrequest.pm,v 1.139 2018/07/02 20:34:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -465,7 +465,7 @@ sub get_consumed_uniqueperiods { return 'error: Unable to determine current status'; } my @problems = $navmap->retrieveResources(undef, - sub { $_[0]->is_problem() },1,0); + sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0); my %used_slots; foreach my $problem (@problems) { my $symb = $problem->symb(); @@ -805,7 +805,7 @@ sub release_reservation { if ($passed_resource->is_map()) { my ($a_resource) = $navmap->retrieveResources($passed_resource, - sub {$_[0]->is_problem()},0,1); + sub {$_[0]->is_problem() || $_[0]->is_tool() },0,1); $symb = $a_resource->symb(); } } else { @@ -841,10 +841,10 @@ sub release_reservation { action => 'release', context => $env{'form.context'}, ); - &Apache::lonnet::write_log('slotreservationslog',\%storehash, - 1,$uname,$udom,$cnum,$cdom); - &Apache::lonnet::write_log($cdom.'_'.$cnum.'_slotlog',\%storehash, - 1,$uname,$udom,$uname,$udom); + &Apache::lonnet::write_log('course','slotreservationslog', + \%storehash,1,$uname,$udom,$cnum,$cdom); + &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog', + \%storehash,1,$uname,$udom,$uname,$udom); } } @@ -938,9 +938,15 @@ sub get_slot { if ($slot_name && $slot_name ne $conflictable_slot) { my %slot=&Apache::lonnet::get_slot($slot_name); my $description1=&get_description($slot_name,\%slot); + my $slottype1=$slot{'type'}; %slot=&Apache::lonnet::get_slot($env{'form.slotname'}); my $description2=&get_description($env{'form.slotname'},\%slot); - if ($slot_name ne $env{'form.slotname'}) { + if ($slottype1 eq 'preassigned') { + $r->print('
'.&mt('You already have a reservation: "[_1]", assigned by your instructor.', + $description1).'
'. + ''.&mt('Your instructor must unassign it before you can make a new reservation.'). + '
'); + } elsif ($slot_name ne $env{'form.slotname'}) { $r->print(<'
.&mt('Instructors may use a reservation system to place restrictions on when and where assignments can be worked on.')
@@ -1921,9 +1928,107 @@ sub manage_reservations {
'');
return;
}
- my (%parent,%shownparent,%container,%container_title,%contents);
- my ($depth,$count,$reservable,$lastcontainer,$rownum,$shown) = (0,0,0,0,0,0);
- my @backgrounds = ("LC_odd_row","LC_even_row");
+ my (%output,%slotinfo,%statusbymap,%repsymbs,%shownmaps);
+ my @possibles = $navmap->retrieveResources(undef,
+ sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0);
+
+ foreach my $resource (@possibles) {
+ my ($useslots) = $resource->slot_control();
+ next if (($useslots eq '') || ($useslots =~ /^\s*no\s*$/i));
+ my $symb = $resource->symb();
+ my ($slot_status,$date,$slot_name) = $resource->check_for_slot('0');
+ my ($msg,$get_choices,$slotdescription);
+ my $status = $resource->simpleStatus('0');
+ my ($msg,$get_choices,$slotdescription);
+ if ($slot_name ne '') {
+ my %slot=&Apache::lonnet::get_slot($slot_name);
+ $slotdescription=&get_description($slot_name,\%slot);
+ }
+ if ($slot_status == $resource->NOT_IN_A_SLOT) {
+ $msg=&mt('No current reservation.');
+ $get_choices = 1;
+ } elsif ($slot_status == $resource->NEEDS_CHECKIN) {
+ $msg=''.&mt('Reserved:').
+ ' '.$slotdescription.'
'.
+ &mt('Access requires proctor validation.');
+ } elsif ($slot_status == $resource->WAITING_FOR_GRADE) {
+ $msg=&mt('Submitted and currently in grading queue.');
+ } elsif ($slot_status == $resource->CORRECT) {
+ $msg=&mt('Problem is unavailable.');
+ } elsif ($slot_status == $resource->RESERVED) {
+ $msg=''.&mt('Reserved:').
+ ' '.$slotdescription.'
'.
+ &mt('Problem is currently available.');
+ } elsif ($slot_status == $resource->RESERVED_LOCATION) {
+ $msg=''.&mt('Reserved:').
+ ' '.$slotdescription.'
'.
+ &mt('Problem is available at a different location.');
+ $get_choices = 1;
+ } elsif ($slot_status == $resource->RESERVED_LATER) {
+ $msg=''.&mt('Reserved:').
+ ' '.$slotdescription.'
'.
+ &mt('Problem will be available later.');
+ $get_choices = 1;
+ } elsif ($slot_status == $resource->RESERVABLE) {
+ $msg=&mt('Reservation needed');
+ $get_choices = 1;
+ } elsif ($slot_status == $resource->RESERVABLE_LATER) {
+ $msg=&mt('Reservation needed: will be reservable later.');
+ } elsif ($slot_status == $resource->NOTRESERVABLE) {
+ $msg=&mt('Reservation needed: none available.');
+ } elsif ($slot_status == $resource->UNKNOWN) {
+ $msg=&mt('Unable to determine status due to network problems.');
+ } else {
+ if ($status != $resource->OPEN) {
+ $msg = &Apache::lonnavmaps::getDescription($resource,'0');
+ }
+ }
+ $output{$symb}{'msg'} = $msg;
+ if (($status == $resource->OPEN) && ($get_choices)) {
+ $output{$symb}{'hasaction'} = 1;
+ }
+ my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
+ $mapurl = &Apache::lonnet::clutter($mapurl);
+ unless ($mapurl =~ /default\.sequence$/) {
+ $shownmaps{$mapurl} = 1;
+ my $map = $navmap->getResourceByUrl($mapurl);
+ if (ref($map)) {
+ my @pcs = split(/,/,$map->map_hierarchy());
+ shift(@pcs);
+ shift(@pcs);
+ if (@pcs) {
+ map { $shownmaps{$navmap->getByMapPc($_)->src()} = 1; } reverse(@pcs);
+ }
+ }
+ }
+ if (($useslots eq 'map_map') || ($useslots eq 'map')) {
+ if ($slot_status ne '') {
+ if (ref($statusbymap{$mapurl}{$slot_status}) eq 'ARRAY') {
+ push(@{$statusbymap{$mapurl}{$slot_status}},$symb);
+ } else {
+ $statusbymap{$mapurl}{$slot_status} = [$symb];
+ }
+ }
+ }
+ }
+
+ foreach my $mapurl (keys(%statusbymap)) {
+ if (ref($statusbymap{$mapurl}) eq 'HASH') {
+ if (keys(%{$statusbymap{$mapurl}}) == 1) {
+ my @values = values(%{$statusbymap{$mapurl}});
+ my $repsymb = $values[0][0];
+ if (ref($output{$repsymb}) eq 'HASH') {
+ $output{$mapurl}{'msg'} = $output{$repsymb}{'msg'};
+ $output{$mapurl}{'hasaction'} = $output{$repsymb}{'hasaction'};
+ }
+ $repsymbs{$mapurl} = $repsymb;
+ }
+ }
+ }
+
+ my (%parent,%container,%container_title);
+ my ($depth,$count,$reservable,$currcontainer,$rownum,$mapnum,$shown) = (0,0,0,0,0,0,0);
+ my @backgrounds = ("LC_even_row","LC_odd_row");
my $numcolors = scalar(@backgrounds);
my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
my $slotheader = '
'. @@ -1931,254 +2036,125 @@ sub manage_reservations { '
'. ''.$spacers.''. + $icon.(' ' x6).' | '."\n"; + if (ref($output{$currmap}) eq 'HASH') { + my $formnum = $mapnum.'_'.$reservable+1; + my $class = 'LC_slotmaptext_'.$mapnum; + if ($output{$currmap}{'hasaction'}) { + $row .= ''. + $output{$currmap}{'msg'}. + ' | '. + &slot_chooser($repsymbs{$currmap},$class,$formnum, + $allavailable,$slots,$consumed_uniqueperiods). + ' | '; } else { - $allstatuses{$output{$symb}{'slotstatus'}} = [$symb]; + $row .= ''. + $output{$currmap}{'msg'}. + ' | '; } + $row .= ''."\n"; } - } - } - } - if (keys(%allstatuses) == 1) { - $got_map_slot = 1; - my $repsymb; - my @values = values(%allstatuses); - if (ref($values[0]) eq 'ARRAY') { - if (ref($output{$values[0][0]}) eq 'HASH') { - $repsymb = $values[0][0]; - } - } - if (($mapitem) && ($repsymb)) { - my $formnum = $mapnum.'_'.$output{$repsymb}{'reservable'}; - my $class = 'LC_slotmaptext_'.$mapnum; - if ($output{$repsymb}{'hasaction'}) { - $mapitem .= ' | '. - $output{$repsymb}{'msg'}. - ' | '. - &slot_chooser($repsymb,$class,$formnum,$allavailable,$slots, - $consumed_uniqueperiods). - ' | '; - } else { - $mapitem .= ''. - $output{$repsymb}{'msg'}. - ' | '; - } - } - my $counter = 0; - foreach my $symb (@ordered) { - if (ref($output{$symb}) eq 'HASH') { - $counter ++; - my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors]; - $currmapoutput .= $output{$symb}{'header'}. - ' '."\n"; - } - } - } else { - my $counter = 0; - foreach my $symb (@ordered) { - if (ref($output{$symb}) eq 'HASH') { - $counter ++; - my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors]; - $currmapoutput .= $output{$symb}{'header'}. - '|
'.$spacers.$icon.(' ' x6).' | '."\n"; } + $r->print($row); } } - if ($mapitem) { - if ($got_map_slot) { - $mapitem =~ s{(print($mapitem.$currmapoutput); - @ordered=(); - undef(%output); - $currmapoutput = ''; - $got_map_slot = ''; - $mapitem = ''; - } - if (ref($resource)) { + } elsif ($resource == $it->END_MAP()) { + $depth--; + $currcontainer = $parent{$depth}; + } elsif (ref($resource)) { my $symb = $resource->symb(); - $contents{$lastcontainer} ++; - next if (!$resource->is_problem() && !$resource->is_sequence() && - !$resource->is_page()); + next if (!$resource->is_problem() && !$resource->is_tool() && + !$resource->is_sequence() && !$resource->is_page()); $count ++; if (($resource->is_sequence()) || ($resource->is_page())) { - $lastcontainer = $count; - $container{$lastcontainer} = $resource; - $container_title{$lastcontainer} = $resource->compTitle(); - } - if ($resource->is_problem()) { - my ($useslots) = $resource->slot_control(); - next if (($useslots eq '') || ($useslots =~ /^\s*no\s*$/i)); - push(@ordered,$symb); - $output{$symb}{type} = $useslots; - my ($msg,$get_choices,$slotdescription); - my $title = $resource->compTitle(); - my $status = $resource->simpleStatus('0'); - my ($slot_status,$date,$slot_name) = $resource->check_for_slot('0'); - - $output{$symb}{'slotstatus'} = $slot_status; - $output{$symb}{'slotname'} = $slot_name; - if ($slot_name ne '') { - my %slot=&Apache::lonnet::get_slot($slot_name); - $slotdescription=&get_description($slot_name,\%slot); - } - if ($slot_status == $resource->NOT_IN_A_SLOT) { - $msg=&mt('No current reservation.'); - $get_choices = 1; - } elsif ($slot_status == $resource->NEEDS_CHECKIN) { - $msg=''.&mt('Reserved:'). - ' '.$slotdescription.' | |||||||
'.join('',@{$maprows[$i]}).' | '. - '||||||||
'.$maprows[$i][0]. - ''. - $maprows[$i][1].(' ' x6).' | '."\n"; - } - } - } - $output{$symb}{'mapnum'} = $mapnum; - } $rownum ++; - $output{$symb}{'rownum'} = $rownum; - $output{$symb}{'shown'} = $shown; if (!$shownheader) { - $output{$symb}{'header'} = $slotheader; + $r->print($slotheader); $shownheader = 1; } - $output{$symb}{'info'} = ''; + my $style; + if (exists($output{$currmap})) { + $style = 'none'; + } else { + $style = 'table-row'; + $shown ++; + } + my $title = $resource->compTitle(); + my $bgcolor = $backgrounds[$shown % $numcolors]; + $r->print(' | |||||||
'); for (my $i=0; $i<$depth; $i++) { - $output{$symb}{'info'} .= ''; + $r->print(''); } - $output{$symb}{'info'} .= ''. - 'src().'?symb='.$symb.'">'. + ''.$title.''.(' ' x6).' | '; - - my $hasaction; - if ($status == $resource->OPEN) { - if ($get_choices) { - $hasaction = 1; - $output{$symb}{'hasaction'} = $hasaction; - } + $r->print('problem.gif" alt="'.&mt('Problem')); } + $r->print('" />'.$title.''.(' ' x6).''); my $class = 'LC_slottext_'.$mapnum; - if ($hasaction) { - $output{$symb}{'data'} = ''.$msg.' | '. - ''. - &slot_chooser($symb,$class,$reservable,$allavailable,$slots, - $consumed_uniqueperiods).' | '; + if ($output{$symb}{'hasaction'}) { + $r->print(''.$output{$symb}{'msg'}.' | '. + ''. + &slot_chooser($symb,$class,$reservable,$allavailable,$slots, + $consumed_uniqueperiods).' | '); } else { - $output{$symb}{'data'} = ''. - ''.$msg.''. - ' | '; + $r->print(''. + ''.$output{$symb}{'msg'}.''. + ' | '); } + $r->print('