--- loncom/interface/slotrequest.pm 2020/04/08 20:06:59 1.125.2.3.4.2 +++ loncom/interface/slotrequest.pm 2018/09/14 21:06:22 1.125.2.6 @@ -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.125.2.3.4.2 2020/04/08 20:06:59 raeburn Exp $ +# $Id: slotrequest.pm,v 1.125.2.6 2018/09/14 21:06:22 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -456,11 +456,11 @@ sub make_reservation { return 'error: Unable to determine current status'; } - my $symb_for_db = $symb; + my $parm_symb = $symb; my $parm_level = 1; if ($use_slots eq 'map' || $use_slots eq 'map_map') { my ($map) = &Apache::lonnet::decode_symb($symb); - $symb_for_db = &Apache::lonnet::symbread($map); + $parm_symb = &Apache::lonnet::symbread($map); $parm_level = 2; } @@ -503,7 +503,7 @@ sub make_reservation { my %reservation=('name' => $env{'user.name'}.':'.$env{'user.domain'}, 'timestamp' => time, - 'symb' => $symb_for_db); + 'symb' => $parm_symb); my $success=&Apache::lonnet::newput('slot_reservations', {"$slot_name\0$wanted" => @@ -515,9 +515,7 @@ sub make_reservation { if ($value) { $new_value=$value.':'.$new_value; } - my $result = &store_slot_parm($symb,$symb_for_db,$slot_name,$parm_level, - $new_value,$cnum,$cdom,$env{'user.name'}, - $env{'user.domain'},'reserve',$env{'form.context'}); + &store_slot_parm($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom); return $wanted; } @@ -526,27 +524,29 @@ sub make_reservation { } sub store_slot_parm { - my ($symb_for_parm,$symb_for_db,$slot_name,$parm_level,$new_value, - $cnum,$cdom,$uname,$udom,$action,$context,$delflag) = @_; - - # store new parameter string - my $result=&Apache::lonparmset::storeparm_by_symb($symb_for_parm, - '0_availablestudent', - $parm_level,$new_value, - 'string',$uname,$udom); + my ($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom) = @_; + my $result=&Apache::lonparmset::storeparm_by_symb($symb, + '0_availablestudent', + $parm_level, $new_value, + 'string', + $env{'user.name'}, + $env{'user.domain'}); &Apache::lonxml::debug("hrrm $result"); my %storehash = ( - symb => $symb_for_db, + symb => $symb, slot => $slot_name, - action => $action, - context => $context, + action => 'reserve', + context => $env{'form.context'}, ); &Apache::lonnet::write_log('course','slotreservationslog',\%storehash, - $delflag,$uname,$udom,$cnum,$cdom); + '',$env{'user.name'},$env{'user.domain'}, + $cnum,$cdom); &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash, - $delflag,$uname,$udom,$uname,$udom); - return $result; + 1,$env{'user.name'},$env{'user.domain'}, + $env{'user.name'},$env{'user.domain'}); + + return; } sub remove_registration { @@ -642,7 +642,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
"); } @@ -672,7 +672,7 @@ 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
"); } @@ -690,184 +690,26 @@ 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 started.',$description)); + return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description)); } } - my $context = $env{'form.context'}; - # get navmap object + # if the reservation symb is for a map get a resource in that map + # to check slot parameters on 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) { @@ -1054,9 +832,9 @@ sub get_slot { my $slot_name=&check_for_conflict($symb,$env{'form.slotname'},\%slot); if ($slot_name =~ /^error: (.*)/) { - $r->print('' + $r->print('
' .&mt('An error occurred while attempting to make a reservation. ([_1])',$1) - .'
'); + .''); &return_link($r); return 0; } @@ -1109,9 +887,9 @@ STUFF if (defined($reserved)) { my $retvalue = 0; if ($slot_name =~ /^error: (.*)/) { - $r->print('' + $r->print('
' .&mt('An error occurred while attempting to make a reservation. ([_1])',$1) - .'
'); + .''); } elsif ($reserved > -1) { $r->print(''.&mt('Successfully signed up: [_1]',$description).'
'); $retvalue = 1; @@ -2894,8 +2672,10 @@ sub csv_upload_map { if (!$env{'form.datatoken'}) { $datatoken=&Apache::loncommon::upfile_store($r); } else { - $datatoken=$env{'form.datatoken'}; - &Apache::loncommon::load_tmp_file($r); + $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'}); + if ($datatoken ne '') { + &Apache::loncommon::load_tmp_file($r,$datatoken); + } } my @records=&Apache::loncommon::upfile_record_sep(); if ($env{'form.noFirstLine'}) { shift(@records); } @@ -2945,7 +2725,10 @@ sub csvupload_fields { sub csv_upload_assign { my ($r,$mgr)= @_; - &Apache::loncommon::load_tmp_file($r); + my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'}); + if ($datatoken ne '') { + &Apache::loncommon::load_tmp_file($r,$datatoken); + } my @slotdata = &Apache::loncommon::upfile_record_sep(); if ($env{'form.noFirstLine'}) { shift(@slotdata); } my %fields=&Apache::grades::get_fields();