--- loncom/interface/slotrequest.pm 2015/09/25 16:13:00 1.128 +++ loncom/interface/slotrequest.pm 2016/05/21 21:13:58 1.132 @@ -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.128 2015/09/25 16:13:00 raeburn Exp $ +# $Id: slotrequest.pm,v 1.132 2016/05/21 21:13:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -261,7 +261,7 @@ function uncheckSlotRadio() { } } -function toggleSlotMap(maprownum) { +function toggleSlotMap(maprownum,rownum) { if (document.getElementById('arrow'+maprownum)) { var img = document.getElementById('arrow'+maprownum); var rowdisplay; @@ -278,20 +278,81 @@ function toggleSlotMap(maprownum) { var resrows; var maptext; if (document.getElementsByClassName) { - resrows = document.getElementsByClassName('LC_slotmaprow_'+maprownum); + resrows = document.getElementsByClassName('LC_slotresrow_'+maprownum); maptext = document.getElementsByClassName('LC_slotmaptext_'+maprownum); } else { - resrows = getElementsByClassName(document.body,'LC_slotmaprow_'+maprownum); + resrows = getElementsByClassName(document.body,'LC_slotresrow_'+maprownum); maptext = getElementsByClassName(document.body,'LC_slotmaptext_'+maprownum); } + if (maptext.length) { + for (var i=0; i= lastresnum)) { + for (var i=lastresnum; i{'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)) { + my @symbs; + if ($slot->{'symb'} =~ /,/) { + @symbs = split(/\s*,\s*/,$slot->{'symb'}); + } else { + @symbs = ($slot->{'symb'}); + } + my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb); + foreach my $reqsymb (@symbs) { + next if ($reqsymb eq ''); + my ($slotmap,$slotid,$sloturl) = &Apache::lonnet::decode_symb($reqsymb); + if ($sloturl=~/\.(page|sequence)$/) { + if (($map ne '') && ($map eq $sloturl)) { + $exclude = 0; + last; + } + } elsif ($reqsymb eq $symb) { $exclude = 0; + last; } - } elsif ($slot->{'symb'} eq $symb) { - $exclude = 0; } if ($exclude) { unless ((ref($toskip) eq 'HASH') && ($toskip->{'symb'})) { @@ -1417,12 +1489,13 @@ sub show_table { 'secret' => 'Secret Word', 'space' => '# of students/max', 'ip' => 'IP or DNS restrictions', - 'symb' => 'Resource/Map slot is restricted to.', + 'symb' => 'Resource(s)/Map(s) slot is restricted to.', 'allowedsections' => 'Sections slot is restricted to.', 'allowedusers' => 'Users slot is restricted to.', 'uniqueperiod' => 'Period of time slot is unique', 'scheduled' => 'Scheduled Students', - 'proctor' => 'List of proctors'); + 'proctor' => 'List of proctors', + 'iptied' => 'Unique IP each student',); if ($crstype eq 'Community') { $show_fields{'startreserve'} = &mt('Time members can start reserving'); $show_fields{'endreserve'} = &mt('Time members can no longer reserve'); @@ -1430,7 +1503,7 @@ sub show_table { } my @show_order=('name','description','type','starttime','endtime', 'startreserve','endreserve','reservationmsg','secret','space', - 'ip','symb','allowedsections','allowedusers','uniqueperiod', + 'ip','iptied','symb','allowedsections','allowedusers','uniqueperiod', 'scheduled','proctor'); my @show = (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show') @@ -1632,13 +1705,21 @@ sub show_table { localtime($slots{$slot}{'uniqueperiod'}[1]); } - my $title; + my @titles; if (exists($slots{$slot}{'symb'})) { - my (undef,undef,$res)= - &Apache::lonnet::decode_symb($slots{$slot}{'symb'}); - $res = &Apache::lonnet::clutter($res); - $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'}); - $title=''.$title.''; + my @symbs; + if ($slots{$slot}{'symb'} =~ /,/) { + @symbs = split(/\s*,\s*/,$slots{$slot}{'symb'}); + } else { + @symbs = ($slots{$slot}{'symb'}); + } + foreach my $reqsymb (@symbs) { + my (undef,undef,$res) = + &Apache::lonnet::decode_symb($reqsymb); + $res = &Apache::lonnet::clutter($res); + my $title = &Apache::lonnet::gettitle($reqsymb); + push(@titles,''.$title.''); + } } my $allowedsections; @@ -1754,8 +1835,18 @@ LOGLINK if (exists($show{'ip'})) { $colspan++;$r->print("$slots{$slot}{'ip'}\n"); } + if (exists($show{'iptied'})) { + $colspan++; + if ($slots{$slot}{'iptied'} eq 'yes') { + $r->print(''.&mt('Yes')."\n"); + } elsif ($slots{$slot}{'iptied'} eq 'answer') { + $r->print(''.&mt('Yes, including post-answer date')."\n"); + } else { + $r->print(''.&mt('No')."\n"); + } + } if (exists($show{'symb'})) { - $colspan++;$r->print("$title\n"); + $colspan++;$r->print("".join('
',@titles)."\n"); } if (exists($show{'allowedsections'})) { $colspan++;$r->print("$allowedsections\n"); @@ -1816,25 +1907,21 @@ 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()) { - @ordered=(); - undef(%output); - $currmapoutput = ''; - $got_map_slot = ''; - $mapitem = ''; $depth++; $parent{$depth} = $lastcontainer; } @@ -1881,23 +1968,30 @@ sub manage_reservations { ''; } } + my $counter = 0; foreach my $symb (@ordered) { if (ref($output{$symb}) eq 'HASH') { - my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % $numcolors]; + $counter ++; + my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors]; $currmapoutput .= $output{$symb}{'header'}. - ''.$output{$symb}{'info'}. + ''. + $output{$symb}{'info'}. $output{$symb}{'data'}.''."\n"; } } } else { + my $counter = 0; foreach my $symb (@ordered) { if (ref($output{$symb}) eq 'HASH') { - my $bgcolor = $backgrounds[$output{$symb}{'rownum'} % $numcolors]; + $counter ++; + my $bgcolor = $backgrounds[($output{$symb}{'shown'} + $counter) % $numcolors]; $currmapoutput .= $output{$symb}{'header'}. - ''.$output{$symb}{'info'}. + ''. + $output{$symb}{'info'}. $output{$symb}{'data'}.''."\n"; + $shown ++; } } } @@ -1910,6 +2004,11 @@ sub manage_reservations { } } $r->print($mapitem.$currmapoutput); + @ordered=(); + undef(%output); + $currmapoutput = ''; + $got_map_slot = ''; + $mapitem = ''; } if (ref($resource)) { my $symb = $resource->symb(); @@ -2003,21 +2102,24 @@ sub manage_reservations { for (my $i=0; $i<@maprows; $i++) { $mapnum ++; $rownum ++; - my $bgcolor = $backgrounds[$rownum % $numcolors]; + $shown ++; + my $bgcolor = $backgrounds[$shown % $numcolors]; if (!$shownheader) { $mapitem .= $slotheader; $shownheader = 1; } if (ref($maprows[$i]) eq 'ARRAY') { if ($i < scalar(@maprows)-1) { - $mapitem .= ''. + $mapitem .= ''. + ''. ''."\n"; } else { $mapitem .= - ''. + ''."\n"; } } @@ -2026,6 +2128,7 @@ sub manage_reservations { } $rownum ++; $output{$symb}{'rownum'} = $rownum; + $output{$symb}{'shown'} = $shown; if (!$shownheader) { $output{$symb}{'header'} = $slotheader; $shownheader = 1; @@ -2113,9 +2216,26 @@ sub slot_chooser { 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; + if ($slots->{$slot}->{'symb'} ne '') { + my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb); + my $exclude = 1; + my @reqsymbs = split(/\s*,\s*/,$slots->{$slot}->{'symb'}); + if (@reqsymbs) { + if (grep(/^\Q$symb\E$/,@reqsymbs)) { + $exclude = 0; + } else { + foreach my $reqsymb (@reqsymbs) { + my (undef,undef,$sloturl) = &Apache::lonnet::decode_symb($reqsymb); + if ($sloturl=~/\.(page|sequence)$/) { + if (($map ne '') && ($map eq $sloturl)) { + $exclude = 0; + last; + } + } + } + } + next if ($exclude); + } } } push(@available,$slot); @@ -2843,10 +2963,11 @@ sub csvupload_fields { ['endreserve','Reservation End Time'], ['reservationmsg','Message when reservation changed'], ['ip','IP or DNS restriction'], + ['iptied','Unique IP each student'], ['proctor','List of proctor ids'], ['description','Slot Description'], ['maxspace','Maximum number of reservations'], - ['symb','Resource/Map Restriction'], + ['symb','Resource(s)/Map(s) Restriction'], ['uniqueperiod','Date range of slot exclusion'], ['secret','Secret word proctor uses to validate'], ['allowedsections','Sections slot is restricted to'], @@ -2914,8 +3035,12 @@ sub csv_upload_assign { } if ($entries{$fields{'startreserve'}}) { - $slot{'startreserve'}= - &UnixDate($entries{$fields{'startreserve'}},"%s"); + my $date = &UnixDate($entries{$fields{'startreserve'}},"%s"); + if ($date eq '') { + push(@errors,"$name -- No reservation start time set for slot -- value provided had invalid format"); + } else { + $slot{'startreserve'} = $date; + } } if (defined($slot{'startreserve'}) && $slot{'startreserve'} > $slot{'starttime'}) { @@ -2924,8 +3049,12 @@ sub csv_upload_assign { } if ($entries{$fields{'endreserve'}}) { - $slot{'endreserve'}= - &UnixDate($entries{$fields{'endreserve'}},"%s"); + my $date = &UnixDate($entries{$fields{'endreserve'}},"%s"); + if ($date eq '') { + push(@errors,"$name -- No reservation end time set for slot -- value provided had invalid format"); + } else { + $slot{'endreserve'} = $date; + } } if (defined($slot{'endreserve'}) && $slot{'endreserve'} > $slot{'starttime'}) { @@ -2953,6 +3082,11 @@ sub csv_upload_assign { $slot{$key}=$entries{$fields{$key}}; } } + if ($entries{$fields{'iptied'}} =~ /^\s*(yes|1)\s*$/i) { + $slot{'iptied'}='yes'; + } elsif ($entries{$fields{'iptied'}} =~ /^\s*answer\s*$/i) { + $slot{'iptied'}='answer'; + } if ($entries{$fields{'allowedusers'}}) { $entries{$fields{'allowedusers'}} =~ s/^\s+//; $entries{$fields{'allowedusers'}} =~ s/\s+$//; @@ -2985,12 +3119,14 @@ sub csv_upload_assign { } } if ($entries{$fields{'uniqueperiod'}}) { - my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}}); - my @times=(&UnixDate($start,"%s"), - &UnixDate($end,"%s")); - $slot{'uniqueperiod'}=\@times; + my ($start,$end)= map { &UnixDate($_,"%s"); } split(',',$entries{$fields{'uniqueperiod'}}); + if (($start ne '') && ($end ne '')) { + $slot{'uniqueperiod'}=[$start,$end]; + } else { + push(@errors,"$name -- Slot's unique period ignored -- one or both of the comma separated values for start and end had an invalid format"); + } } - if (defined($slot{'uniqueperiod'}) + if (ref($slot{'uniqueperiod'}) eq 'ARRAY' && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) { push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time."); next; @@ -3175,7 +3311,8 @@ sub handler { my ($status) = &Apache::lonhomework::check_slot_access('0',$type); if ($status eq 'CAN_ANSWER' || $status eq 'NEEDS_CHECKIN' || - $status eq 'WAITING_FOR_GRADE') { + $status eq 'WAITING_FOR_GRADE' || + $status eq 'NEED_DIFFERENT_IP') { &fail($r,'not_allowed'); return OK; }
'.join('',@{$maprows[$i]}).'
'.join('',@{$maprows[$i]}).' 
'.$maprows[$i][0]. + '
'.$maprows[$i][0]. ''. + 'onclick="'."toggleSlotMap('$mapnum','$rownum');".'" />'. $maprows[$i][1].(' ' x6).'