--- loncom/interface/slotrequest.pm 2005/10/17 19:26:50 1.24 +++ 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.24 2005/10/17 19:26:50 albertel Exp $ +# $Id: slotrequest.pm,v 1.32 2005/11/21 17:50:45 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,11 +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($html.''.&mt($title).''); + $r->print(&Apache::loncommon::bodytag($title)); } sub end_page { @@ -451,6 +450,49 @@ 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,$mgr)=@_; @@ -461,29 +503,78 @@ sub show_table { } my $available; if ($mgr eq 'F') { + $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=' + $r->print(' - - - - - - - - - - - -'); + '); + foreach my $which (@show_order) { + if ($which ne 'proctor' && exists($show{$which})) { + $r->print(''); + } + } + $r->print(''); + my %name_cache; my $slotsort = sub { - if ($env{'form.order'}=~/^(type|description|endtime|maxspace)$/) { + 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'}}) @@ -493,7 +584,7 @@ sub show_table { if (lc($a) cmp lc($b)) { return lc($a) cmp lc($b); } - } elsif ($env{'form.order'} eq 'unique') { + } elsif ($env{'form.order'} eq 'uniqueperiod') { if ($slots{$a}->{'uniqueperiod'}[0] ne $slots{$b}->{'uniqueperiod'}[0]) { @@ -509,6 +600,7 @@ sub show_table { 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; @@ -525,7 +617,7 @@ sub show_table { &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):''); my $end=($slots{$slot}->{'endtime'}? &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):''); - my $start_reserve=($slots{$slot}->{'endtime'}? + my $start_reserve=($slots{$slot}->{'startreserve'}? &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):''); my $unique; @@ -533,45 +625,79 @@ sub show_table { $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).','. localtime($slots{$slot}{'uniqueperiod'}[1]); } - my @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); - } (split(/\s*,\s*/,$slots{$slot}->{'proctor'})); - + 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); - my $edit=(< - - - - -EDITFORM - $r->print(< - - - - - - - - - - - - + my $edit=(<Edit +EDITLINK + + $r->print("\n\n"); + if (exists($show{'name'})) { + $colspan++;$r->print(""); + } + if (exists($show{'type'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'description'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'starttime'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'endtime'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'startreserve'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'secret'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'maxspace'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'ip'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'symb'})) { + $colspan++;$r->print("\n"); + } + if (exists($show{'uniqueperiod'})) { + $colspan++;$r->print("\n"); + } + $colspan++;$r->print("\n\n"); + if (exists($show{'proctor'})) { + $r->print(< - + STUFF + } } $r->print('
'.$linkstart.'name" >Slot name'.$linkstart.'type" >Type'.$linkstart.'description" >Description'.$linkstart.'starttime" >Start Time'.$linkstart.'endtime" >End Time'.$linkstart.'startreserve">Time Students Can Start Reserving'.$linkstart.'secret" >Secret'.$linkstart.'maxspace" >Max space Scheduled Students'.$linkstart.'unique" >Unique Period
'.$linkstart.$which.'">'.$show_fields{$which}.'Scheduled Students
$edit$slot$slots{$slot}->{'type'}$description$start$end$start_reserve$slots{$slot}->{'secret'}$slots{$slot}->{'maxspace'}$ids$unique
$edit$slot$slots{$slot}->{'type'}$description$start$end$start_reserve$slots{$slot}{'secret'}$slots{$slot}{'maxspace'}$slots{$slot}{'ip'}$title$unique$ids
$proctors$proctors
'); } @@ -758,16 +884,34 @@ sub csv_upload_assign { my $cname=$env{'course.'.$env{'request.course.id'}.'.num'}; my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; my $countdone=0; + my @errors; foreach my $slot (@slotdata) { my %slot; my %entries=&Apache::loncommon::record_sep($slot); my $domain; my $name=$entries{$fields{'name'}}; + if ($name=~/^\s*$/) { + push(@errors,"Did not create slot with no name"); + next; + } + if ($name=~/\s/) { + push(@errors,"$name not created -- Name must not contain spaces"); + next; + } + if ($name=~/\W/) { + push(@errors,"$name not created -- Name must contain only letters, numbers and _"); + next; + } if ($entries{$fields{'type'}}) { $slot{'type'}=$entries{$fields{'type'}}; } else { $slot{'type'}='preassigned'; } + if ($slot{'type'} ne 'preassigned' && + $slot{'type'} ne 'schedulable_student') { + push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student"); + next; + } if ($entries{$fields{'starttime'}}) { $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s"); } @@ -796,8 +940,10 @@ sub csv_upload_assign { $r->rflush(); $countdone++; } - $r->print("
Created $countdone slots\n"); - $r->print("
\n"); + $r->print("

Created $countdone slots\n

"); + foreach my $error (@errors) { + $r->print("

$error\n

"); + } &show_table($r,$mgr); return ''; } @@ -805,10 +951,23 @@ sub csv_upload_assign { sub handler { my $r=shift; + &Apache::loncommon::content_type($r,'text/html'); + &Apache::loncommon::no_cache($r); + if ($r->header_only()) { + $r->send_http_header(); + return OK; + } + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); - &start_page($r); + my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'}); + my $title='Requesting Another Worktime'; + if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') { + $title = 'Managing Slots'; + } + &start_page($r,$title); + if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') { &show_table($r,$mgr); } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') { @@ -826,8 +985,6 @@ sub handler { } &csv_upload_map($r); } - } elsif ($env{'form.command'} eq 'editslot' && $mgr eq 'F') { - &show_slot_edit($r); } else { my $symb=&Apache::lonnet::unescape($env{'form.symb'}); my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);