version 1.25, 2005/10/17 21:21:39
|
version 1.32, 2005/11/21 17:50:45
|
Line 53 sub fail {
|
Line 53 sub fail {
|
} |
} |
|
|
sub start_page { |
sub start_page { |
my ($r)=@_; |
my ($r,$title)=@_; |
my $html=&Apache::lonxml::xmlbegin(); |
my $html=&Apache::lonxml::xmlbegin(); |
$r->print($html.'<head><title>'. |
$r->print($html.'<head><title>'.&mt($title).'</title></head>'); |
&mt('Request another Worktime').'</title></head>'); |
$r->print(&Apache::loncommon::bodytag($title)); |
$r->print(&Apache::loncommon::bodytag('Requesting another Worktime')); |
|
} |
} |
|
|
sub end_page { |
sub end_page { |
Line 451 STUFF
|
Line 450 STUFF
|
$r->print('</table>'); |
$r->print('</table>'); |
} |
} |
|
|
|
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 { |
sub show_table { |
my ($r,$mgr)=@_; |
my ($r,$mgr)=@_; |
|
|
Line 461 sub show_table {
|
Line 503 sub show_table {
|
} |
} |
my $available; |
my $available; |
if ($mgr eq 'F') { |
if ($mgr eq 'F') { |
|
$r->print('<div>'); |
$r->print('<form method="POST" action="/adm/slotrequest"> |
$r->print('<form method="POST" action="/adm/slotrequest"> |
<input type="hidden" name="command" value="uploadstart" /> |
<input type="hidden" name="command" value="uploadstart" /> |
<input type="submit" name="start" value="'.&mt('Upload Slot List').'" /> |
<input type="submit" name="start" value="'.&mt('Upload Slot List').'" /> |
</form>'); |
</form>'); |
|
$r->print('<form method="POST" action="/adm/helper/newslot.helper"> |
|
<input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" /> |
|
</form>'); |
|
$r->print('</div>'); |
} |
} |
|
|
|
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('<form method="POST" action="/adm/slotrequest"> |
|
<input type="hidden" name="command" value="showslots" />'); |
|
$r->print('<div>'); |
|
$r->print('<table class="inline"><tr><th>'.&mt('Show').'</th><th>'.&mt('Open').'</th></tr><tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order). |
|
'</td><td>'.&Apache::loncommon::select_form($when,'when',%when_fields). |
|
'</td></tr></table>'); |
|
$r->print('</div>'); |
|
$r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>'); |
my $linkstart='<a href="/adm/slotrequest?command=showslots&order='; |
my $linkstart='<a href="/adm/slotrequest?command=showslots&order='; |
$r->print('<table border="1"> |
$r->print('<table class="thinborder"> |
<tr> |
<tr> |
<th></th> |
<th></th>'); |
<th>'.$linkstart.'name" >Slot name</a></th> |
foreach my $which (@show_order) { |
<th>'.$linkstart.'type" >Type</a></th> |
if ($which ne 'proctor' && exists($show{$which})) { |
<th>'.$linkstart.'description" >Description</a></th> |
$r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>'); |
<th>'.$linkstart.'starttime" >Start Time</a></th> |
} |
<th>'.$linkstart.'endtime" >End Time</a></th> |
} |
<th>'.$linkstart.'startreserve">Time Students Can Start Reserving</a></th> |
$r->print('<th>Scheduled Students</th></tr>'); |
<th>'.$linkstart.'secret" >Secret</a></th> |
|
<th>'.$linkstart.'maxspace" >Max space</a></th> |
|
<th> Scheduled Students</th> |
|
<th>'.$linkstart.'unique" >Unique Period</a></th> |
|
</tr>'); |
|
my %name_cache; |
my %name_cache; |
my $slotsort = sub { |
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'}}) |
if (lc($slots{$a}->{$env{'form.order'}}) |
ne lc($slots{$b}->{$env{'form.order'}})) { |
ne lc($slots{$b}->{$env{'form.order'}})) { |
return (lc($slots{$a}->{$env{'form.order'}}) |
return (lc($slots{$a}->{$env{'form.order'}}) |
Line 493 sub show_table {
|
Line 584 sub show_table {
|
if (lc($a) cmp lc($b)) { |
if (lc($a) cmp lc($b)) { |
return 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] |
if ($slots{$a}->{'uniqueperiod'}[0] |
ne $slots{$b}->{'uniqueperiod'}[0]) { |
ne $slots{$b}->{'uniqueperiod'}[0]) { |
Line 509 sub show_table {
|
Line 600 sub show_table {
|
return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'}; |
return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'}; |
}; |
}; |
foreach my $slot (sort $slotsort (keys(%slots))) { |
foreach my $slot (sort $slotsort (keys(%slots))) { |
|
if (!&to_show($when,$slots{$slot})) { next; } |
if (defined($slots{$slot}->{'type'}) |
if (defined($slots{$slot}->{'type'}) |
&& $slots{$slot}->{'type'} ne 'schedulable_student') { |
&& $slots{$slot}->{'type'} ne 'schedulable_student') { |
#next; |
#next; |
Line 525 sub show_table {
|
Line 617 sub show_table {
|
&Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):''); |
&Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):''); |
my $end=($slots{$slot}->{'endtime'}? |
my $end=($slots{$slot}->{'endtime'}? |
&Apache::lonlocal::locallocaltime($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'}):''); |
&Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):''); |
|
|
my $unique; |
my $unique; |
Line 533 sub show_table {
|
Line 625 sub show_table {
|
$unique=localtime($slots{$slot}{'uniqueperiod'}[0]).','. |
$unique=localtime($slots{$slot}{'uniqueperiod'}[0]).','. |
localtime($slots{$slot}{'uniqueperiod'}[1]); |
localtime($slots{$slot}{'uniqueperiod'}[1]); |
} |
} |
my @proctors = map { |
my $title; |
my ($uname,$udom)=split(/@/,$_); |
if (exists($slots{$slot}{'symb'})) { |
my $fullname=$name_cache{$_}; |
my (undef,undef,$res)= |
if (!defined($fullname)) { |
&Apache::lonnet::decode_symb($slots{$slot}{'symb'}); |
&Apache::lonnet::logthis("Gettign $uname $udom"); |
$res = &Apache::lonnet::clutter($res); |
$fullname = &Apache::loncommon::plainname($uname,$udom); |
$title = &Apache::lonnet::gettitle($slots{$slot}{'symb'}); |
$fullname =~s/\s/ /g; |
$title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>'; |
$name_cache{$_} = $fullname; |
} |
} |
my @proctors; |
&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom); |
my $rowspan=1; |
} (split(/\s*,\s*/,$slots{$slot}->{'proctor'})); |
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 $proctors=join(', ',@proctors); |
|
|
my $edit=(<<EDITFORM); |
my $edit=(<<EDITLINK); |
<form method="POST" action="/adm/helper/newslot.helper"> |
<a href="/adm/helper/newslot.helper?name=$slot">Edit</a> |
<input type="hidden" name="name" value="$slot" /> |
EDITLINK |
<input type="submit" name="Edit" value="Edit" /> |
|
</form> |
$r->print("<tr>\n<td rowspan=\"$rowspan\">$edit</td>\n"); |
EDITFORM |
if (exists($show{'name'})) { |
$r->print(<<STUFF); |
$colspan++;$r->print("<td>$slot</td>"); |
<tr> |
} |
<td rowspan="2">$edit</td> |
if (exists($show{'type'})) { |
<td>$slot</td> |
$colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n"); |
<td>$slots{$slot}->{'type'}</td> |
} |
<td>$description</td> |
if (exists($show{'description'})) { |
<td>$start</td> |
$colspan++;$r->print("<td>$description</td>\n"); |
<td>$end</td> |
} |
<td>$start_reserve</td> |
if (exists($show{'starttime'})) { |
<td>$slots{$slot}->{'secret'}</td> |
$colspan++;$r->print("<td>$start</td>\n"); |
<td>$slots{$slot}->{'maxspace'}</td> |
} |
<td>$ids</td> |
if (exists($show{'endtime'})) { |
<td>$unique</td> |
$colspan++;$r->print("<td>$end</td>\n"); |
</tr> |
} |
|
if (exists($show{'startreserve'})) { |
|
$colspan++;$r->print("<td>$start_reserve</td>\n"); |
|
} |
|
if (exists($show{'secret'})) { |
|
$colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n"); |
|
} |
|
if (exists($show{'maxspace'})) { |
|
$colspan++;$r->print("<td>$slots{$slot}{'maxspace'}</td>\n"); |
|
} |
|
if (exists($show{'ip'})) { |
|
$colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n"); |
|
} |
|
if (exists($show{'symb'})) { |
|
$colspan++;$r->print("<td>$title</td>\n"); |
|
} |
|
if (exists($show{'uniqueperiod'})) { |
|
$colspan++;$r->print("<td>$unique</td>\n"); |
|
} |
|
$colspan++;$r->print("<td>$ids</td>\n</tr>\n"); |
|
if (exists($show{'proctor'})) { |
|
$r->print(<<STUFF); |
<tr> |
<tr> |
<td colspan="10">$proctors</td> |
<td colspan="$colspan">$proctors</td> |
</tr> |
</tr> |
STUFF |
STUFF |
|
} |
} |
} |
$r->print('</table>'); |
$r->print('</table>'); |
} |
} |
Line 757 sub csv_upload_assign {
|
Line 884 sub csv_upload_assign {
|
my $cname=$env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cname=$env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $countdone=0; |
my $countdone=0; |
|
my @errors; |
foreach my $slot (@slotdata) { |
foreach my $slot (@slotdata) { |
my %slot; |
my %slot; |
my %entries=&Apache::loncommon::record_sep($slot); |
my %entries=&Apache::loncommon::record_sep($slot); |
my $domain; |
my $domain; |
my $name=$entries{$fields{'name'}}; |
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'}}) { |
if ($entries{$fields{'type'}}) { |
$slot{'type'}=$entries{$fields{'type'}}; |
$slot{'type'}=$entries{$fields{'type'}}; |
} else { |
} else { |
$slot{'type'}='preassigned'; |
$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'}}) { |
if ($entries{$fields{'starttime'}}) { |
$slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s"); |
$slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s"); |
} |
} |
Line 795 sub csv_upload_assign {
|
Line 940 sub csv_upload_assign {
|
$r->rflush(); |
$r->rflush(); |
$countdone++; |
$countdone++; |
} |
} |
$r->print("<br />Created $countdone slots\n"); |
$r->print("<p>Created $countdone slots\n</p>"); |
$r->print("<br />\n"); |
foreach my $error (@errors) { |
|
$r->print("<p>$error\n</p>"); |
|
} |
&show_table($r,$mgr); |
&show_table($r,$mgr); |
return ''; |
return ''; |
} |
} |
Line 804 sub csv_upload_assign {
|
Line 951 sub csv_upload_assign {
|
sub handler { |
sub handler { |
my $r=shift; |
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'}); |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); |
&start_page($r); |
|
my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); |
my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); |
my $mgr=&Apache::lonnet::allowed('mgr',$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') { |
if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') { |
&show_table($r,$mgr); |
&show_table($r,$mgr); |
} elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') { |
} elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') { |
Line 825 sub handler {
|
Line 985 sub handler {
|
} |
} |
&csv_upload_map($r); |
&csv_upload_map($r); |
} |
} |
} elsif ($env{'form.command'} eq 'editslot' && $mgr eq 'F') { |
|
&show_slot_edit($r); |
|
} else { |
} else { |
my $symb=&Apache::lonnet::unescape($env{'form.symb'}); |
my $symb=&Apache::lonnet::unescape($env{'form.symb'}); |
my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb); |
my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb); |