--- loncom/interface/slotrequest.pm 2006/03/30 05:13:38 1.48.2.3 +++ loncom/interface/slotrequest.pm 2006/03/30 05:20:44 1.56 @@ -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.48.2.3 2006/03/30 05:13:38 albertel Exp $ +# $Id: slotrequest.pm,v 1.56 2006/03/30 05:20:44 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,14 +54,12 @@ sub fail { sub start_page { my ($r,$title)=@_; - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.''.&mt($title).''); - $r->print(&Apache::loncommon::bodytag($title)); + $r->print(&Apache::loncommon::start_page($title)); } sub end_page { my ($r)=@_; - $r->print(&Apache::loncommon::endbodytag().''); + $r->print(&Apache::loncommon::end_page()); } =pod @@ -615,34 +613,70 @@ STUFF sub allowed_slot { my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_; + #already started if ($slot->{'starttime'} < time) { # all open slot to be schedulable #return 0; } &Apache::lonxml::debug("$slot_name starttime good"); + #already ended if ($slot->{'endtime'} < time) { return 0; } &Apache::lonxml::debug("$slot_name endtime good"); + # not allowed to pick this one if (defined($slot->{'type'}) && $slot->{'type'} ne 'schedulable_student') { return 0; } &Apache::lonxml::debug("$slot_name type good"); - # not allowed for this resource - if (defined($slot->{'symb'}) - && $slot->{'symb'} ne $symb) { - return 0; - } + # reserve time not yet started if ($slot->{'startreserve'} > time) { return 0; } &Apache::lonxml::debug("$slot_name reserve good"); + my $userallowed=0; + # its for a different set of users + if (defined($slot->{'allowedsections'})) { + if (!defined($env{'request.role.sec'}) + && grep(/^No section assigned$/, + split(',',$slot->{'allowedsections'}))) { + $userallowed=1; + } + if (defined($env{'request.role.sec'}) + && grep(/^\Q$env{'request.role.sec'}\E$/, + split(',',$slot->{'allowedsections'}))) { + $userallowed=1; + } + } + &Apache::lonxml::debug("$slot_name sections is $userallowed"); + + # its for a different set of users + if (defined($slot->{'allowedusers'}) + && grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/, + split(',',$slot->{'allowedusers'}))) { + $userallowed=1; + } + + if (!defined($slot->{'allowedusers'}) + && !defined($slot->{'allowedsections'})) { + $userallowed=1; + } + + &Apache::lonxml::debug("$slot_name user is $userallowed"); + return 0 if (!$userallowed); + + # not allowed for this resource + if (defined($slot->{'symb'}) + && $slot->{'symb'} ne $symb) { + return 0; + } + my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots, $consumed_uniqueperiods); if ($conflict) { @@ -854,22 +888,25 @@ sub show_table { # what to display filtering my %show_fields=&Apache::lonlocal::texthash( - 'name' => 'Slot Name', - 'description' => 'Description', - 'type' => 'Type', - 'starttime' => 'Start time', - 'endtime' => 'End Time', - 'startreserve' => 'Time students can start reserving', - 'secret' => 'Secret Word', - 'maxspace' => 'Maximum # of students', - 'ip' => 'IP or DNS restrictions', - 'symb' => 'Resource slot is restricted to.', - 'uniqueperiod' => 'Period of time slot is unique', - 'scheduled' => 'Scheduled Students', - 'proctor' => 'List of proctors'); + 'name' => 'Slot Name', + 'description' => 'Description', + 'type' => 'Type', + 'starttime' => 'Start time', + 'endtime' => 'End Time', + 'startreserve' => 'Time students can start reserving', + 'secret' => 'Secret Word', + 'maxspace' => 'Maximum # of students', + 'ip' => 'IP or DNS restrictions', + 'symb' => 'Resource 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'); my @show_order=('name','description','type','starttime','endtime', - 'startreserve','secret','maxspace','ip','symb', - 'uniqueperiod','scheduled','proctor'); + 'startreserve','secret','maxspace','ip','symb', + 'allowedsections','allowedusers','uniqueperiod', + 'scheduled','proctor'); my @show = (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show') : keys(%show_fields); @@ -975,7 +1012,7 @@ sub show_table { my %name_cache; my $slotsort = sub { - if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb)$/) { + if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb|allowedsections|allowedusers)$/) { if (lc($slots{$a}->{$env{'form.order'}}) ne lc($slots{$b}->{$env{'form.order'}})) { return (lc($slots{$a}->{$env{'form.order'}}) @@ -1057,6 +1094,28 @@ sub show_table { $title=''.$title.''; } + my $allowedsections; + if (exists($show{'allowedsections'})) { + $allowedsections = + join(', ',sort(split(/\s*,\s*/, + $slots{$slot}->{'allowedsections'}))); + } + + my @allowedusers; + if (exists($show{'allowedusers'})) { + @allowedusers= map { + my ($uname,$udom)=split(/:/,$_); + my $fullname=$name_cache{$_}; + if (!defined($fullname)) { + $fullname = &Apache::loncommon::plainname($uname,$udom); + $fullname =~s/\s/ /g; + $name_cache{$_} = $fullname; + } + &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom); + } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'}))); + } + my $allowedusers=join(', ',@allowedusers); + my @proctors; my $rowspan=1; my $colspan=1; @@ -1066,7 +1125,6 @@ sub show_table { my ($uname,$udom)=split(/@/,$_); my $fullname=$name_cache{$_}; if (!defined($fullname)) { - &Apache::lonnet::logthis("Gettign $uname $udom"); $fullname = &Apache::loncommon::plainname($uname,$udom); $fullname =~s/\s/ /g; $name_cache{$_} = $fullname; @@ -1123,8 +1181,11 @@ DELETELINK if (exists($show{'symb'})) { $colspan++;$r->print("$title\n"); } - if (exists($show{'uniqueperiod'})) { - $colspan++;$r->print("$unique\n"); + if (exists($show{'allowedsections'})) { + $colspan++;$r->print("$allowedsections\n"); + } + if (exists($show{'allowedusers'})) { + $colspan++;$r->print("$allowedusers\n"); } if (exists($show{'scheduled'})) { $colspan++;$r->print("$remove_all $ids\n\n"); @@ -1309,7 +1370,10 @@ sub csvupload_fields { ['maxspace','Maximum number of reservations'], ['symb','Resource Restriction'], ['uniqueperiod','Date range of slot exclusion'], - ['secret','Secret word proctor uses to validate']); + ['secret','Secret word proctor uses to validate'], + ['allowedsections','Sections slot is restricted to'], + ['allowedusers','Users slot is restricted to'], + ); } sub csv_upload_assign {