+ $edit
$slot
$slots{$slot}->{'type'}
$description
$start
$end
+ $start_reserve
+ $slots{$slot}->{'secret'}
$slots{$slot}->{'maxspace'}
$ids
- $slots{$slot}->{'proctor'}
- $slots{$slot}->{'uniqueperiod'}
+ $unique
+
+
+ $proctors
STUFF
}
$r->print('');
}
+sub upload_start {
+ my ($r)=@_;
+ $r->print(&Apache::grades::checkforfile_js());
+ my $result.=''."\n";
+ $result.=''."\n";
+ $r->print($result);
+}
+
+sub csvuploadmap_header {
+ my ($r,$datatoken,$distotal)= @_;
+ my $javascript;
+ if ($env{'form.upfile_associate'} eq 'reverse') {
+ $javascript=&csvupload_javascript_reverse_associate();
+ } else {
+ $javascript=&csvupload_javascript_forward_associate();
+ }
+
+ my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
+ my $ignore=&mt('Ignore First Line');
+ $r->print(<
+Identify fields
+Total number of records found in file: $distotal
+Enter as many fields as you can. The system will inform you and bring you back
+to this page if the data selected is insufficient to create the slots.
+
+ $ignore
+
+
+
+
+
+
+
+
+ENDPICK
+ return '';
+
+}
+
+sub csvuploadmap_footer {
+ my ($request,$i,$keyfields) =@_;
+ $request->print(<
+
+
+
+
+ENDPICK
+}
+
+sub csvupload_javascript_reverse_associate {
+ my $error1=&mt('You need to specify the name, starttime, endtime and a type');
+ return(<[0].','; }
+ chop($keyfields);
+ } else {
+ unshift(@fields,['none','']);
+ $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
+ \@fields);
+ my %sone=&Apache::loncommon::record_sep($records[0]);
+ $keyfields=join(',',sort(keys(%sone)));
+ }
+ }
+ &csvuploadmap_footer($r,$i,$keyfields);
+
+ return '';
+}
+
+sub csvupload_fields {
+ return (['name','Slot name'],
+ ['type','Type of slot'],
+ ['starttime','Start Time of slot'],
+ ['endtime','End Time of slot'],
+ ['startreserve','Reservation Start Time'],
+ ['ip','IP or DNS restriction'],
+ ['proctor','List of proctor ids'],
+ ['description','Slot Description'],
+ ['maxspace','Maximum number of reservations'],
+ ['symb','Resource Restriction'],
+ ['uniqueperiod','Date range of slot exclusion'],
+ ['secret','Secret word proctor uses to validate']);
+}
+
+sub csv_upload_assign {
+ my ($r,$mgr)= @_;
+ &Apache::loncommon::load_tmp_file($r);
+ my @slotdata = &Apache::loncommon::upfile_record_sep();
+ if ($env{'form.noFirstLine'}) { shift(@slotdata); }
+ my %fields=&Apache::grades::get_fields();
+ $r->print('Creating Slots ');
+ my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $countdone=0;
+ foreach my $slot (@slotdata) {
+ my %slot;
+ my %entries=&Apache::loncommon::record_sep($slot);
+ my $domain;
+ my $name=$entries{$fields{'name'}};
+ if ($entries{$fields{'type'}}) {
+ $slot{'type'}=$entries{$fields{'type'}};
+ } else {
+ $slot{'type'}='preassigned';
+ }
+ if ($entries{$fields{'starttime'}}) {
+ $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
+ }
+ if ($entries{$fields{'endtime'}}) {
+ $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
+ }
+ if ($entries{$fields{'startreserve'}}) {
+ $slot{'startreserve'}=
+ &UnixDate($entries{$fields{'startreserve'}},"%s");
+ }
+ foreach my $key ('ip','proctor','description','maxspace',
+ 'secret','symb') {
+ if ($entries{$fields{$key}}) {
+ $slot{$key}=$entries{$fields{$key}};
+ }
+ }
+ if ($entries{$fields{'uniqueperiod'}}) {
+ my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
+ my @times=(&UnixDate($start,"%s"),
+ &UnixDate($end,"%s"));
+ $slot{'uniqueperiod'}=\@times;
+ }
+
+ &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
+ $r->print('.');
+ $r->rflush();
+ $countdone++;
+ }
+ $r->print(" Created $countdone slots\n");
+ $r->print(" \n");
+ &show_table($r,$mgr);
+ return '';
+}
+
sub handler {
my $r=shift;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
&start_page($r);
- my $symb=&Apache::lonnet::unescape($env{'form.symb'});
- my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
- if ($res !~ /\.task$/) {
- &fail($r,'not_valid');
- return OK;
- }
- $env{'request.symb'}=$symb;
my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
+ my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
- &show_table($r,$symb);
+ &show_table($r,$mgr);
+ } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
+ &upload_start($r);
+ } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
+ &csv_upload_map($r);
+ } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
+ if ($env{'form.associate'} ne 'Reverse Association') {
+ &csv_upload_assign($r,$mgr);
+ } else {
+ if ( $env{'form.upfile_associate'} ne 'reverse' ) {
+ $env{'form.upfile_associate'} = 'reverse';
+ } else {
+ $env{'form.upfile_associate'} = 'forward';
+ }
+ &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);
+ if ($res !~ /\.task$/) {
+ &fail($r,'not_valid');
+ return OK;
+ }
+ $env{'request.symb'}=$symb;
my ($status) = &Apache::lonhomework::check_task_access('0');
if ($status eq 'CAN_ANSWER' ||
$status eq 'NEEDS_CHECKIN' ||