--- loncom/interface/slotrequest.pm 2015/09/27 14:21:48 1.129 +++ loncom/interface/slotrequest.pm 2023/07/12 15:48:23 1.147 @@ -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.129 2015/09/27 14:21:48 raeburn Exp $ +# $Id: slotrequest.pm,v 1.147 2023/07/12 15:48:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,16 +50,19 @@ sub fail { } else { $r->print('
'.&mt('Failed.').'
'); } - + &return_link($r); &end_page($r); } sub start_page { - my ($r,$title,$brcrum,$js)=@_; + my ($r,$title,$brcrum,$bread_crumbs_component,$js,$mgr)=@_; my $args; if (ref($brcrum) eq 'ARRAY') { $args = {bread_crumbs => $brcrum}; + if ($bread_crumbs_component) { + $args->{bread_crumbs_component} = $bread_crumbs_component; + } } if (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) { my %loaditems = ( @@ -71,6 +74,31 @@ sub start_page { $args = { 'add_entries' => \%loaditems }; } } + unless (($env{'form.context'} eq 'usermanage') || (($mgr eq 'F') && + (($env{'form.command'} eq 'release') || + ($env{'form.command'} eq 'remove_registration')))) { + if ($env{'form.symb'}) { + my $symb=&unescape($env{'form.symb'}); + my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb); + if ($resurl =~ /ext\.tool$/) { + my $target; + my ($marker,$exttool) = (split(m{/},$resurl))[3,4]; + $marker=~s/\D//g; + if (($marker) && ($exttool) && ($env{'request.course.id'})) { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my ($idx,$crstool,$is_tool,%toolhash,%toolsettings); + if ($resurl eq "adm/$cdom/$cnum/$marker/$exttool") { + my %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); + $target = $toolsettings{'target'}; + } + } + if ($target eq 'iframe') { + $args->{'only_body'} = 1; + } + } + } + } $r->print(&Apache::loncommon::start_page($title,$js,$args)); } @@ -256,7 +284,7 @@ function uncheckSlotRadio() { } if (slotpicks.length) { for (var i=0; i'.&mt('Releasing reservations').'
'); foreach my $entry (sort { $consumed{$a}{'name'} cmp @@ -739,7 +767,7 @@ sub release_all_slot { &release_reservation($slot_name,$uname,$udom, $consumed{$entry}{'symb'},$mgr); if (!$result) { - $r->print(''.&mt($msg).'
'); + $r->print(''.&mt($msg).'
'); } else { $r->print("$msg
"); } @@ -769,11 +797,11 @@ sub release_slot { my ($result,$msg) = &release_reservation($slot_name,$uname,$udom,$symb,$mgr); if (!$result) { - $r->print(''.&mt($msg).'
'); + $r->print(''.&mt($msg).'
'); } else { $r->print("$msg
"); } - + if ($mgr eq 'F') { $r->print(''. &mt('Return to slot list').'
'); @@ -787,26 +815,184 @@ sub release_reservation { my ($slot_name,$uname,$udom,$symb,$mgr) = @_; my %slot=&Apache::lonnet::get_slot($slot_name); my $description=&get_description($slot_name,\%slot); + my $msg; if ($mgr ne 'F') { if ($slot{'starttime'} < time) { - return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description)); + return (0,&mt('Not allowed to release Reservation: [_1], as it has already started.',$description)); } } + my $context = $env{'form.context'}; - # if the reservation symb is for a map get a resource in that map - # to check slot parameters on + # get navmap object my $navmap=Apache::lonnavmaps::navmap->new; if (!defined($navmap)) { return (0,'error: Unable to determine current status'); } + + my ($cnum,$cdom)=&get_course(); + + # get slot reservations, check if user has reservation + my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum, + "^$slot_name\0"); + + # + # If release is because of a reservation *change*, symb(s) associated with reservation + # being dropped may differ from the current symb. + # + # We need to get symb(s) from slot_reservations.db, and for each symb, update + # the value of the availablestudent parameter, at the appropriate level + # (as dictated by the value of the useslots parameter for the symb and user). + # + # We also delete all entries for the slot being released, for the specific user. + # + + my $conflict; + + if (($env{'form.command'} eq 'change') && ($slot_name eq $env{'form.releaseslot'}) && + ($env{'form.slotname'} ne $slot_name)) { + my %changedto = &Apache::lonnet::get_slot($env{'form.slotname'}); + + # check for conflicts + my ($to_uniq_start,$to_uniq_end,$from_uniq_start,$from_uniq_end); + if (ref($changedto{'uniqueperiod'}) eq 'ARRAY') { + ($to_uniq_start,$to_uniq_end) = @{$changedto{'uniqueperiod'}}; + } + if (ref($slot{'uniqueperiod'}) eq 'ARRAY') { + ($from_uniq_start,$from_uniq_end) = @{$slot{'uniqueperiod'}}; + } + my $to_start = $changedto{'starttime'}; + my $to_end = $changedto{'endtime'}; + my $from_start = $slot{'starttime'}; + my $from_end = $slot{'endtime'}; + + if (! + ($from_start < $to_uniq_start && $from_end < $to_uniq_start) || + ($from_start > $to_uniq_end && $from_end > $to_uniq_end )) { + $conflict = 1; + } + if (! + ($to_start < $from_uniq_start && $to_end < $from_uniq_start) || + ($to_start > $from_uniq_end && $to_end > $from_uniq_end )) { + $conflict = 1; + } + + if ($conflict) { + my %symbs_for_slot; + my (%to_delete,%failed,%released); + foreach my $entry (keys(%consumed)) { + if ( $consumed{$entry}->{'name'} eq ($uname.':'.$udom) ) { + $symbs_for_slot{$consumed{$entry}->{'symb'}} = 1; + $to_delete{$entry} = 1; + } + } + if (keys(%to_delete)) { + my @removals = keys(%to_delete); + if (&Apache::lonnet::del('slot_reservations',\@removals, + $cdom,$cnum) eq 'ok') { + foreach my $item (keys(%symbs_for_slot)) { + my $result = &update_selectable($navmap,$slot_name,$item,$cdom, + $cnum,$udom,$uname,$context); + if ($result =~ /^error/) { + $failed{$item} = 1; + } else { + $released{$item} = 1; + } + } + } + } + if (keys(%released)) { + $msg = ''. + &mt('Released Reservation: [_1]',$description).' '. + &mt('The following items had their reservation status change').':'; + my (%folders,%pages,%container,%titles); + foreach my $item (keys(%released)) { + my $res = $navmap->getBySymb($item); + if (ref($res)) { + $titles{$item} = $res->title(); + if ($res->is_map()) { + $folders{$item}{'title'} = $titles{$item}; + if ($res->is_page()) { + $pages{$item}{'title'} = $titles{$item}; + } else { + $folders{$item}{'title'} = $titles{$item}; + } + } else { + my $mapsrc = $res->enclosing_map_src(); + my $map = $navmap->getResourceByUrl($mapsrc); + if (ref($map)) { + if ($map->id() eq '0.0') { + $container{$mapsrc}{'title'} &mt('Top level of course'); + } else { + $container{$mapsrc}{'title'} = $map->title(); + if ($map->is_page()) { + $container{$mapsrc}{'page'} = 1; + } + } + } + $container{$mapsrc}{'resources'}{$item} = 1; + } + } + } + $msg .= ''.&mt('Slot [_1] marked as deleted.',''.$slot_name.'').'
'); } else { - $r->print(''.&mt('An error occurred when attempting to delete slot: [_1]',''.$slot_name.'')." ($ret)
"); + $r->print(''.&mt('An error occurred when attempting to delete slot: [_1]',''.$slot_name.'')." ($ret)
"); } } else { if (%consumed) { @@ -913,15 +1163,32 @@ sub delete_slot { sub return_link { my ($r) = @_; + my $target = &return_target(); if (($env{'form.command'} eq 'manageresv') || ($env{'form.context'} eq 'usermanage')) { - $r->print(''.
- &mt('Return to reservations'));
+ $r->print(' '.
+ &mt('Return to reservations').' '.
+ $r->print(' '.
&mt('Return to last resource').' '
+ $r->print(' '
.&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
- .' '.&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.').
+ ' '
+ $r->print(' '
.&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
- .'
'.&mt('Successfully signed up: [_1]',$description).'
'); $retvalue = 1; @@ -1067,7 +1340,7 @@ sub allowed_slot { if (($slot->{'endreserve'}) && ($slot->{'endreserve'} < time)) { return 0; - } + } &Apache::lonxml::debug("$slot_name reserve good"); my $userallowed=0; @@ -1114,14 +1387,25 @@ sub allowed_slot { # not allowed for this resource 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)) { + 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'})) { @@ -1164,7 +1448,8 @@ sub show_choices { if (!@{$available}) { $output = ''.&mt('No available times.').''; if ($env{'form.command'} ne 'manageresv') { - $output .= ' '. + my $target = &return_target(); + $output .= ' '. &mt('Return to last resource').''; } if ($class) { @@ -1202,7 +1487,7 @@ sub show_choices { ); foreach my $option (@options) { my $onclick = "toggleSlotDisplay(this.form,'$num');"; - if (($option eq 'show') && ($env{'form.command'} eq 'manageresv')) { + if (($option eq 'show') && ($env{'form.command'} eq 'manageresv')) { $onclick .= "currSlotDisplay$num(this.form,'$num');"; } $output .= ''); 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.''. @@ -1886,254 +2300,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 ($spacers,$icon) = &show_map_row($depth,$location,$currmaptype,$currmaptitle); + $row .= ''.$spacers.$icon.(' ' x6).' | '."\n"; } - } - 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'}. - ' |
'.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('
'.&mt('Previous [_1] changes',$curr{'show'}).' | '); + $r->print(''); } if ($more_records) { - $r->print(''.&mt('Next [_1] changes',$curr{'show'}).' | '); + $r->print(''); } - $r->print('