--- loncom/interface/slotrequest.pm 2015/09/07 17:44:11 1.124 +++ loncom/interface/slotrequest.pm 2015/09/27 14:21:48 1.129 @@ -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.124 2015/09/07 17:44:11 raeburn Exp $ +# $Id: slotrequest.pm,v 1.129 2015/09/27 14:21:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -162,9 +162,24 @@ $js var startdate = startm+"/"+startd+"/"+starty; var starttime = new Date(startdate).getTime(); starttime = starttime/1000; + var starth = form.start_hour.options[form.start_hour.selectedIndex].value; + if (numberRegExp.test(starth)) { + starth = parseInt(starth); + if (starth > 0 && starth <= 23) { + starttime += 3600 * starth; + } + } var enddate = endm+"/"+endd+"/"+endy; var endtime = new Date(enddate).getTime(); endtime = endtime/1000; + var endh = form.end_hour.options[form.end_hour.selectedIndex].value; + if (numberRegExp.test(endh)) { + endh = parseInt(endh); + if (endh > 0 && endh <= 23) { + endtime += 3600 * endh; + } + } + var shown = 0; for (var i=0; i<$i; i++) { if ((slotstart[i] >= starttime) && (slotend[i] <= endtime)) { @@ -237,7 +252,7 @@ function uncheckSlotRadio() { if (document.getElementsByClassName) { slotpicks = document.getElementsByClassName('LC_slotpick_radio'); } else { - sloctpicks = getElementsByClassName(document.body,'LC_slotpick_radio'); + slotpicks = getElementsByClassName(document.body,'LC_slotpick_radio'); } if (slotpicks.length) { for (var i=0; i= lastresnum)) { + for (var i=lastresnum; i ENDSCRIPT @@ -1000,10 +1112,21 @@ sub allowed_slot { return 0 if (!$userallowed); # not allowed for this resource - if (defined($slot->{'symb'}) - && $slot->{'symb'} ne $symb) { - unless ((ref($toskip) eq 'HASH') && ($toskip->{'symb'})) { - return 0; + if (defined($slot->{'symb'})) { + my $exclude = 1; + my ($slotmap,$slotid,$sloturl) = &Apache::lonnet::decode_symb($slot->{'symb'}); + if ($sloturl=~/\.(page|sequence)$/) { + my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb); + if (($map ne '') && ($map eq $slotmap)) { + $exclude = 0; + } + } elsif ($slot->{'symb'} eq $symb) { + $exclude = 0; + } + if ($exclude) { + unless ((ref($toskip) eq 'HASH') && ($toskip->{'symb'})) { + return 0; + } } } @@ -1032,7 +1155,7 @@ sub get_description { } sub show_choices { - my ($r,$symb,$formname,$num,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_; + my ($symb,$formname,$num,$class,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_; my $output; &Apache::lonxml::debug("Checking Slots"); if (!ref($available) eq 'ARRAY') { @@ -1044,8 +1167,11 @@ sub show_choices { $output .= ' '. &mt('Return to last resource').''; } - $r->print($output); - return; + if ($class) { + return '
'.$output.'
'; + } else { + return $output; + } } if (@{$available} > 1) { my $numavailable = scalar(@{$available}); @@ -1193,8 +1319,11 @@ STUFF if (@{$available} > 1) { $output .= ''; } - $r->print($output); - return; + if ($class) { + return '
'.$output.'
'; + } else { + return $output; + } } sub to_show { @@ -1349,7 +1478,7 @@ sub show_table { 'secret' => 'Secret Word', 'space' => '# of students/max', 'ip' => 'IP or DNS restrictions', - 'symb' => 'Resource slot is restricted to.', + 'symb' => 'Resource/Map slot is restricted to.', 'allowedsections' => 'Sections slot is restricted to.', 'allowedusers' => 'Users slot is restricted to.', 'uniqueperiod' => 'Period of time slot is unique', @@ -1748,16 +1877,19 @@ sub manage_reservations { return; } my (%parent,%shownparent,%container,%container_title,%contents); - my ($depth,$count,$reservable,$lastcontainer,$rownum) = (0,0,0,0,0); + my ($depth,$count,$reservable,$lastcontainer,$rownum,$shown) = (0,0,0,0,0,0); my @backgrounds = ("LC_odd_row","LC_even_row"); my $numcolors = scalar(@backgrounds); my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif"); my $slotheader = '

'. &mt('Your reservation status for any such assignments is listed below:'). '

'. - ''."\n"; + '
'."\n"; my $shownheader = 0; my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef); + my (@ordered,%output,$mapitem,$got_map_slot,$currmapoutput,$mapnum); + $mapnum = 0; + $shown = 0; while (my $resource = $it->next()) { if ($resource == $it->BEGIN_MAP()) { $depth++; @@ -1766,10 +1898,90 @@ sub manage_reservations { if ($resource == $it->END_MAP()) { $depth--; $lastcontainer = $parent{$depth}; + my %allstatuses; + foreach my $symb (@ordered) { + if (ref($output{$symb}) eq 'HASH') { + if (($output{$symb}{'type'} eq 'map_map') || ($output{$symb}{'type'} eq 'map')) { + if ($output{$symb}{'slotstatus'} ne '') { + if (ref($allstatuses{$output{$symb}{'slotstatus'}}) eq 'ARRAY') { + push(@{$allstatuses{$output{$symb}{'slotstatus'}}},$symb); + } else { + $allstatuses{$output{$symb}{'slotstatus'}} = [$symb]; + } + } + } + } + } + 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 .= ''; + + } else { + $mapitem .= ''; + } + } + 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'}. + ''. + $output{$symb}{'info'}. + $output{$symb}{'data'}.''."\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'}. + ''. + $output{$symb}{'info'}. + $output{$symb}{'data'}.''."\n"; + $shown ++; + } + } + } + if ($mapitem) { + if ($got_map_slot) { + $mapitem =~ s{(print($mapitem.$currmapoutput); + @ordered=(); + undef(%output); + $currmapoutput = ''; + $got_map_slot = ''; + $mapitem = ''; } if (ref($resource)) { my $symb = $resource->symb(); - my $ressymb = $symb; $contents{$lastcontainer} ++; next if (!$resource->is_problem() && !$resource->is_sequence() && !$resource->is_page()); @@ -1782,10 +1994,15 @@ sub manage_reservations { 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); @@ -1829,7 +2046,9 @@ sub manage_reservations { $msg = &Apache::lonnavmaps::getDescription($resource,'0'); } } + $output{$symb}{'msg'} = $msg; $reservable ++; + $output{$symb}{'reservable'} = $reservable; my $treelevel = $depth; my $higherup = $lastcontainer; if ($depth > 1) { @@ -1850,76 +2069,71 @@ sub manage_reservations { $treelevel --; $higherup = $parent{$treelevel}; } - foreach my $item (@maprows) { + for (my $i=0; $i<@maprows; $i++) { + $mapnum ++; $rownum ++; - my $bgcolor = $backgrounds[$rownum % $numcolors]; + $shown ++; + my $bgcolor = $backgrounds[$shown % $numcolors]; if (!$shownheader) { - $r->print($slotheader); + $mapitem .= $slotheader; $shownheader = 1; } - $r->print(''.$item.''."\n"); + if (ref($maprows[$i]) eq 'ARRAY') { + if ($i < scalar(@maprows)-1) { + $mapitem .= ''. + ''. + ''."\n"; + } else { + $mapitem .= + ''. + ''."\n"; + } + } } + $output{$symb}{'mapnum'} = $mapnum; } $rownum ++; - my $bgcolor = $backgrounds[$rownum % $numcolors]; + $output{$symb}{'rownum'} = $rownum; + $output{$symb}{'shown'} = $shown; if (!$shownheader) { - $r->print($slotheader); + $output{$symb}{'header'} = $slotheader; $shownheader = 1; } - $r->print(''; + $output{$symb}{'info'} .= '" />'.$title.''.(' ' x6).''; + my $hasaction; if ($status == $resource->OPEN) { if ($get_choices) { $hasaction = 1; + $output{$symb}{'hasaction'} = $hasaction; } } + my $class = 'LC_slottext_'.$mapnum; if ($hasaction) { - $result .= ''. - ''. + ''; } else { - $result .= ''; - } - $r->print($result); - if ($hasaction) { - my @got_slots=&check_for_reservation($symb,'allslots'); - if ($got_slots[0] =~ /^error: /) { - $r->print(''. - &mt('An error occurred determining slot availability.'). - ''); - } else { - my $formname = 'manageres_'.$reservable; - if (ref($allavailable) eq 'ARRAY') { - my @available; - if (ref($slots) eq 'HASH') { - foreach my $slot (@{$allavailable}) { - # not allowed for this resource - if (ref($slots->{$slot}) eq 'HASH') { - if ((defined($slots->{$slot}->{'symb'})) && - ($slots->{$slot}->{'symb'} ne $symb)) { - next; - } - } - push(@available,$slot); - } - } - &show_choices($r,$symb,$formname,$reservable,$slots,$consumed_uniqueperiods, - \@available,\@got_slots); - } - } - $r->print(''); + $output{$symb}{'data'} = ''; } - $r->print(''); } } } @@ -1941,20 +2155,53 @@ sub manage_reservations { sub show_map_row { my ($depth,$location,$type,$title,$maprows) = @_; - my $output = ''."\n"; - unshift (@{$maprows},$output); + $icon .= $title; + unshift (@{$maprows},[$spacers,$icon]); return; } +sub slot_chooser { + my ($symb,$class,$formnum,$allavailable,$slots,$consumed_uniqueperiods) = @_; + my $output; + my @got_slots=&check_for_reservation($symb,'allslots'); + if ($got_slots[0] =~ /^error: /) { + $output = ''. + &mt('An error occurred determining slot availability.'). + ''; + } else { + my $formname = 'manageres_'.$formnum; + if (ref($allavailable) eq 'ARRAY') { + my @available; + if (ref($slots) eq 'HASH') { + foreach my $slot (@{$allavailable}) { + # not allowed for this resource + if (ref($slots->{$slot}) eq 'HASH') { + if ((defined($slots->{$slot}->{'symb'})) && + ($slots->{$slot}->{'symb'} ne $symb)) { + next; + } + } + push(@available,$slot); + } + } + $output .= &show_choices($symb,$formname,$formnum,$class, + $slots,$consumed_uniqueperiods, + \@available,\@got_slots); + } + } + return $output; +} + sub show_reservations { my ($r,$uname,$udom) = @_; if (!defined($uname)) { @@ -2672,7 +2919,7 @@ sub csvupload_fields { ['proctor','List of proctor ids'], ['description','Slot Description'], ['maxspace','Maximum number of reservations'], - ['symb','Resource Restriction'], + ['symb','Resource/Map Restriction'], ['uniqueperiod','Date range of slot exclusion'], ['secret','Secret word proctor uses to validate'], ['allowedsections','Sections slot is restricted to'], @@ -3007,7 +3254,7 @@ sub handler { } if ($env{'form.requestattempt'}) { $r->print('
'); - &show_choices($r,$symb,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots); + $r->print(&show_choices($symb,undef,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots)); $r->print('
'); } elsif ($env{'form.command'} eq 'release') { &release_slot($r,$symb);
'. + $output{$repsymb}{'msg'}. + ''. + &slot_chooser($repsymb,$class,$formnum,$allavailable,$slots, + $consumed_uniqueperiods). + ''. + $output{$repsymb}{'msg'}. + '
'.join('',@{$maprows[$i]}).' 
'.$maprows[$i][0]. + ''. + $maprows[$i][1].(' ' x6).'
'."\n"); + $output{$symb}{'info'} = ''; for (my $i=0; $i<$depth; $i++) { - $r->print(''); + $output{$symb}{'info'} .= ''; } - my $result = ''. - 'src().'?symb='.$symb.'">'. + ''.&mt('Task');
+                    $output{$symb}{'info'} .= 'task.gif'.$title.''.(' ' x6).''.$msg.''; + $output{$symb}{'data'} = ''.$msg.''. + &slot_chooser($symb,$class,$reservable,$allavailable,$slots, + $consumed_uniqueperiods).''.$msg.''. + ''.$msg.''. + '
'; - for (my $i=0; $i<$depth-1; $i++) { - $output .= ''; + my $spacers; + for (my $i=0; $i<$depth-2; $i++) { + $spacers .= ''; } + my $icon; if ($type eq 'page') { - $output .= ' '."\n"; + $icon = ' '."\n"; } else { - $output .= ' '."\n"; + $icon = ' '."\n"; } - $output .= $title.'