--- loncom/interface/slotrequest.pm 2005/09/13 07:33:59 1.16 +++ loncom/interface/slotrequest.pm 2005/11/21 17:50:45 1.32 @@ -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.16 2005/09/13 07:33:59 albertel Exp $ +# $Id: slotrequest.pm,v 1.32 2005/11/21 17:50:45 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,12 +53,10 @@ sub fail { } sub start_page { - my ($r)=@_; + my ($r,$title)=@_; my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.''. - &mt('Request another Worktime').''); - $r->print(&Apache::loncommon::bodytag('Requesting another Worktime')); - $r->print('

'.$env{'form.command'}.'

'); + $r->print($html.''.&mt($title).''); + $r->print(&Apache::loncommon::bodytag($title)); } sub end_page { @@ -452,34 +450,157 @@ STUFF $r->print(''); } +sub to_show { + my ($when,$slot) = @_; + my $time=time; + my $week=60*60*24*7; + if ($when eq 'now') { + if ($time > $slot->{'starttime'} && + $time < $slot->{'endtime'}) { + return 1; + } + return 0; + } elsif ($when eq 'nextweek') { + if ( ($time < $slot->{'starttime'} && + ($time+$week) > $slot->{'starttime'}) + || + ($time < $slot->{'endtime'} && + ($time+$week) > $slot->{'endtime'}) ) { + return 1; + } + return 0; + } elsif ($when eq 'lastweek') { + if ( ($time > $slot->{'starttime'} && + ($time-$week) < $slot->{'starttime'}) + || + ($time > $slot->{'endtime'} && + ($time-$week) < $slot->{'endtime'}) ) { + return 1; + } + return 0; + } elsif ($when eq 'willopen') { + if ($time < $slot->{'starttime'}) { + return 1; + } + return 0; + } elsif ($when eq 'wereopen') { + if ($time > $slot->{'endtime'}) { + return 1; + } + return 0; + } + + return 1; +} + sub show_table { - my ($r,$symb,$mgr)=@_; + my ($r,$mgr)=@_; my ($cnum,$cdom)=&get_course(); my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum); + if ( (keys(%slots))[0] =~ /^error: 2 /) { + undef(%slots); + } my $available; if ($mgr eq 'F') { + $r->print('
'); $r->print('
-
'); + $r->print('
+ +
'); + $r->print('
'); } - $r->print(' + + my %Saveable_Parameters = ('show' => 'array', + 'when' => 'scalar', + 'order' => 'scalar'); + + &Apache::loncommon::store_course_settings('slotrequest',\%Saveable_Parameters); + &Apache::loncommon::restore_course_settings('slotrequest',\%Saveable_Parameters); + + 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' => 'Maxium # of students', + 'ip' => 'IP or DNS restrictions', + 'symb' => 'Resource slot is restricted to.', + 'uniqueperiod' => 'Period of time slot is unique', + 'proctor' => 'List of proctors'); + my @show_order=('name','description','type','starttime','endtime', + 'startreserve','secret','maxspace','ip','symb', + 'uniqueperiod','proctor'); + my @show = + (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show') + : keys(%show_fields); + my %show = map { $_ => 1 } (@show); + + my %when_fields=&Apache::lonlocal::texthash( + 'now' => 'Open now', + 'nextweek' => 'Open within the next week', + 'lastweek' => 'Were open last week', + 'willopen' => 'Will open later', + 'wereopen' => 'Were open'); + my @when_order=('now','nextweek','lastweek','willopen','wereopen'); + $when_fields{'select_form_order'} = \@when_order; + my $when = (exists($env{'form.when'})) ? $env{'form.when'} + : 'now'; + + $r->print(' +'); + $r->print('
'); + $r->print('
'.&mt('Show').''.&mt('Open').'
'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order). + ''.&Apache::loncommon::select_form($when,'when',%when_fields). + '
'); + $r->print(''); + $r->print('

'); + my $linkstart=' - Slot name - Type - Description - Start Time - End Time - Max space - Scheduled Students - Proctors - Unique Period -'); - foreach my $slot (sort - { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} } - (keys(%slots))) { + '); + foreach my $which (@show_order) { + if ($which ne 'proctor' && exists($show{$which})) { + $r->print(''.$linkstart.$which.'">'.$show_fields{$which}.''); + } + } + $r->print('Scheduled Students'); + + my %name_cache; + my $slotsort = sub { + if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb)$/) { + if (lc($slots{$a}->{$env{'form.order'}}) + ne lc($slots{$b}->{$env{'form.order'}})) { + return (lc($slots{$a}->{$env{'form.order'}}) + cmp lc($slots{$b}->{$env{'form.order'}})); + } + } elsif ($env{'form.order'} eq 'name') { + if (lc($a) cmp lc($b)) { + return lc($a) cmp lc($b); + } + } elsif ($env{'form.order'} eq 'uniqueperiod') { + + if ($slots{$a}->{'uniqueperiod'}[0] + ne $slots{$b}->{'uniqueperiod'}[0]) { + return ($slots{$a}->{'uniqueperiod'}[0] + cmp $slots{$b}->{'uniqueperiod'}[0]); + } + if ($slots{$a}->{'uniqueperiod'}[1] + ne $slots{$b}->{'uniqueperiod'}[1]) { + return ($slots{$a}->{'uniqueperiod'}[1] + cmp $slots{$b}->{'uniqueperiod'}[1]); + } + } + return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'}; + }; + foreach my $slot (sort $slotsort (keys(%slots))) { + if (!&to_show($when,$slots{$slot})) { next; } if (defined($slots{$slot}->{'type'}) && $slots{$slot}->{'type'} ne 'schedulable_student') { #next; @@ -492,33 +613,97 @@ sub show_table { my (undef,$id)=split("\0",$entry); $ids.= $id.'-> '.$consumed{$entry}->{'name'}.'
'; } - my $start=localtime($slots{$slot}->{'starttime'}); - my $end=localtime($slots{$slot}->{'endtime'}); + my $start=($slots{$slot}->{'starttime'}? + &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):''); + my $end=($slots{$slot}->{'endtime'}? + &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):''); + my $start_reserve=($slots{$slot}->{'startreserve'}? + &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):''); + my $unique; if (ref($slots{$slot}{'uniqueperiod'})) { $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).','. localtime($slots{$slot}{'uniqueperiod'}[1]); } + my $title; + 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 @proctors; + my $rowspan=1; + my $colspan=1; + if (exists($show{'proctor'})) { + $rowspan=2; + @proctors= map { + 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; + } + &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom); + } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'}))); + } + my $proctors=join(', ',@proctors); - $r->print(<Edit +EDITLINK + + $r->print("\n$edit\n"); + if (exists($show{'name'})) { + $colspan++;$r->print("$slot"); + } + if (exists($show{'type'})) { + $colspan++;$r->print("$slots{$slot}->{'type'}\n"); + } + if (exists($show{'description'})) { + $colspan++;$r->print("$description\n"); + } + if (exists($show{'starttime'})) { + $colspan++;$r->print("$start\n"); + } + if (exists($show{'endtime'})) { + $colspan++;$r->print("$end\n"); + } + if (exists($show{'startreserve'})) { + $colspan++;$r->print("$start_reserve\n"); + } + if (exists($show{'secret'})) { + $colspan++;$r->print("$slots{$slot}{'secret'}\n"); + } + if (exists($show{'maxspace'})) { + $colspan++;$r->print("$slots{$slot}{'maxspace'}\n"); + } + if (exists($show{'ip'})) { + $colspan++;$r->print("$slots{$slot}{'ip'}\n"); + } + if (exists($show{'symb'})) { + $colspan++;$r->print("$title\n"); + } + if (exists($show{'uniqueperiod'})) { + $colspan++;$r->print("$unique\n"); + } + $colspan++;$r->print("$ids\n\n"); + if (exists($show{'proctor'})) { + $r->print(< - $slot - $slots{$slot}->{'type'} - $description - $start - $end - $slots{$slot}->{'maxspace'} - $ids - $slots{$slot}->{'proctor'} - $unique + $proctors STUFF + } } $r->print(''); } sub upload_start { - my ($r,$symb)=@_; + my ($r)=@_; $r->print(&Apache::grades::checkforfile_js()); my $result.='
'."\n"; $result.=' '. @@ -529,7 +714,6 @@ sub upload_start { my $ignore=&mt('Ignore First Line'); $result.=< - $upfile_select
@@ -542,7 +726,7 @@ ENDUPFORM } sub csvuploadmap_header { - my ($r,$symb,$datatoken,$distotal)= @_; + my ($r,$datatoken,$distotal)= @_; my $javascript; if ($env{'form.upfile_associate'} eq 'reverse') { $javascript=&csvupload_javascript_reverse_associate(); @@ -566,7 +750,6 @@ to this page if the data selected is ins -