--- loncom/homework/bridgetask.pm 2006/04/10 22:55:02 1.140 +++ loncom/homework/bridgetask.pm 2006/05/12 05:18:34 1.149 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.140 2006/04/10 22:55:02 albertel Exp $ +# $Id: bridgetask.pm,v 1.149 2006/05/12 05:18:34 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -170,8 +170,8 @@ sub add_grading_button { my (undef,$cid)=&Apache::lonxml::whichuser(); my $cnum=$env{'course.'.$cid.'.num'}; my $cdom=$env{'course.'.$cid.'.domain'}; - my %sections; - my $numsections=&Apache::loncommon::get_sections($cdom,$cnum,\%sections); + my %sections = &Apache::loncommon::get_sections($cdom,$cnum); + my $size=5; if (scalar(keys(%sections)) < 3) { $size=scalar(keys(%sections))+2; @@ -214,7 +214,7 @@ sub add_grading_button { 'gradingdomain'); $result.=&Apache::loncommon::studentbrowser_javascript(); $result.= '

'; - } + } return $result; } @@ -223,6 +223,12 @@ sub add_request_another_attempt_button { if (!$text) { $text="Request another attempt"; } my $result; my $symb=&Apache::lonnet::symbread(); + # not a slot access based resource + my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb); + if ($useslots =~ /^\s*no\s*$/i) { + return ''; + } + my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb); my $action='get_reservation'; if ($slot_name) { @@ -349,12 +355,15 @@ sub webgrade_standard_info { my %lt=&Apache::lonlocal::texthash('done' => 'Next Item', 'stop' => 'Quit Grading', + 'fail' => 'Fail Rest', ); my $result=< + $file_list INFO @@ -375,28 +384,32 @@ sub start_Task { } $Apache::lonhomework::parsing_a_task=1; - #should get back a or the neccesary stuff to start XML/MathML - my ($result,$head_tag_start,$body_tag_start,$form_tag_start)= - &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); - - $head_tag_start .= &style($target); - $body_tag_start .= '
'."\n"; + my $name; if ($target eq 'web' || $target eq 'webgrade') { - $head_tag_start.=''. - &Apache::structuretags::get_resource_name($parstack,$safeeval). - ''; + $name = &Apache::structuretags::get_resource_name($parstack,$safeeval); + } + + my ($result,$form_tag_start); + if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex' + || $target eq 'edit') { + ($result,$form_tag_start) = + &Apache::structuretags::page_start($target,$token,$tagstack, + $parstack,$parser,$safeeval, + $name,&style($target)); + $result .= '
'."\n"; } if ($target eq 'web' && $env{'request.state'} ne 'construct') { - if ($Apache::lonhomework::modifygrades) { - $body_tag_start.='
'.&add_grading_button()."
"; + $result.=$uri.'">'.&add_grading_button().""; my $symb=&Apache::lonnet::symbread(); if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) { - $body_tag_start.='
'. + $result.=''. ''. ''. ''. + $result.=''. ''. ''. ''.$body_tag_start; if ($env{'request.state'} eq 'construct') { $result.=$form_tag_start; } @@ -490,16 +502,18 @@ DONESCREEN if ($status eq 'NEEDS_CHECKIN') { if(&proctor_check_auth($slot_name,$slot,'Task') && defined($Apache::inputtags::slot_name)) { - my $result=&add_to_queue('gradingqueue', - [$Apache::inputtags::slot_name]); + my $result= + &add_to_queue('gradingqueue', + {'type' => 'task', + 'time' => time, + 'slot' => + $Apache::inputtags::slot_name}); &Apache::lonxml::debug("add_to_queue said $result"); } } } } elsif ($target eq 'web') { - $result.="$head_tag_start - $body_tag_start \n"; - + $result.=&preserve_grade_info(); $result.=&internal_location(); $result.=$form_tag_start. @@ -510,9 +524,7 @@ DONESCREEN $target eq 'webgrade') { my $webgrade='yes'; if ($target eq 'webgrade') { - $result.=$head_tag_start. - ''.$body_tag_start. - "\n".'
'."\n". + $result.= "\n".'
'."\n". ''; #$result.='
Review'.&show_queue('reviewqueue'); @@ -596,7 +608,7 @@ DONESCREEN $result.="\n".'
'; } } elsif ($target eq 'edit') { - $result.=$head_tag_start."".$body_tag_start.$form_tag_start. + $result.=$form_tag_start. &Apache::structuretags::problem_edit_header(); $Apache::lonxml::warnings_error_header= &mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")."
"; @@ -801,11 +813,19 @@ DONEBUTTON my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"}; my $title=&Apache::lonnet::gettitle(); + my $start_time; + my $slot_name= $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"}; - my %slot=&Apache::lonnet::get_slot($slot_name); - my $start_time= - &Apache::lonlocal::locallocaltime($slot{'starttime'}); + if ($slot_name) { + my %slot=&Apache::lonnet::get_slot($slot_name); + + $start_time=$slot{'starttime'} + } else { + $start_time= + &Apache::lonnet::EXT('resource.0.opendate'); + } + $start_time=&Apache::lonlocal::locallocaltime($start_time); my $status = "\n
\n"; @@ -842,9 +862,8 @@ DONEBUTTON my $internal_location=&internal_location(); $result=~s/\Q$internal_location\E/$status/; } - } - if ($target eq 'web') { - $result.="\n
\n".&Apache::lonxml::xmlend().''; + $result.="\n
\n". + &Apache::loncommon::end_page({'discussion' => 1}); } } if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) { @@ -868,9 +887,18 @@ DONEBUTTON } &Apache::lonhomework::showhash(%Apache::lonhomework::results); &Apache::structuretags::finalize_storage(); - if ($award eq 'SUBMITTED' - && defined($Apache::inputtags::slot_name)) { - &add_to_queue('gradingqueue',[$Apache::inputtags::slot_name]); + if ($award eq 'SUBMITTED') { + my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); + if ($useslots =~ /^\s*no\s*$/i) { + &add_to_queue('gradingqueue', + {'type' => 'task', + 'time' => time}); + } elsif (defined($Apache::inputtags::slot_name)) { + &add_to_queue('gradingqueue', + {'type' => 'task', + 'time' => time, + 'slot' => $Apache::inputtags::slot_name}); + } } } elsif ($Apache::lonhomework::results{'INTERNAL_store'}) { &Apache::structuretags::finalize_storage(); @@ -1009,7 +1037,7 @@ sub move_between_queues { } else { $cur_data = ['none']; } - my $result=&add_to_queue($dest_queue,[$cur_data->[0]]); + my $result=&add_to_queue($dest_queue,$cur_data); if ($result ne 'ok') { return $result; } @@ -1108,17 +1136,17 @@ sub check_queue_for_key { if (defined($results{"$todo\0locked"})) { return 'locked'; } - my $slot; - if (ref($results{$todo}) eq 'ARRAY') { - $slot = $results{$todo}[0]; - } elsif (ref($results{$todo}) eq 'HASH') { - $slot = $results{$todo}{'slot'}; - } - if (defined($slot)) { + if (my $slot=&slotted_access($results{$todo})) { my %slot_data=&Apache::lonnet::get_slot($slot); if ($slot_data{'endtime'} > time) { return 'in_progress'; } + } else { + my ($symb) = &decode_queue_key($todo); + my $due_date = &Apache::lonhomework::due_date('0',$symb); + if ($due_date > time) { + return 'in_progress'; + } } return 'enqueued'; } @@ -1178,8 +1206,15 @@ sub show_queue { &Apache::lonlocal::locallocaltime($queue{$key}).""; } elsif ($key!~/(timestamp|locked)$/) { $result.=""; - my $slot=$queue{$key}->[0]; - my %slot_data=&Apache::lonnet::get_slot($slot); + my ($end_time,$slot_text); + if (my $slot=&slotted_access($queue{$key})) { + my %slot_data=&Apache::lonnet::get_slot($slot); + $end_time = $slot_data{'endtime'}; + $slot_text = &mt('Slot: [_1]',$slot); + } else { + $end_time = &Apache::lonhomework::due_date('0',$symb); + $slot_text = ''; + } if ($with_selects) { my $ekey=&Apache::lonnet::escape($key); my ($action,$description,$status)=('select',&mt('Select')); @@ -1197,7 +1232,7 @@ sub show_queue { $seclist.=''; } - if (time > $slot_data{'endtime'}) { + if ($end_time ne '' && time > $end_time) { $result.=(<$status @@ -1214,13 +1249,13 @@ sub show_queue { FORM } else { - $result.=''.&mt("In Progress").'' + $result.=''.&mt("In Progress").' ' } } $result.= "".$fullname->{$uname.':'.$udom}. " ($uname:$udom) "; - $result.='Slot: '.$slot.' End time: '. - &Apache::lonlocal::locallocaltime($slot_data{'endtime'}). + $result.=''.$slot_text.' End time: '. + &Apache::lonlocal::locallocaltime($end_time). ""; } } @@ -1250,13 +1285,19 @@ sub get_queue_counts { } elsif ($key!~/(timestamp|locked)$/) { my ($symb,$uname,$udom) = &decode_queue_key($key); $entries++; - my $slot=$queue{$key}->[0]; - if (!exists($slot_cache{$slot})) { - my %slot_data=&Apache::lonnet::get_slot($slot); - $slot_cache{$slot} = \%slot_data; - } - if (time > $slot_cache{$slot}{'endtime'}) { - $ready_to_grade++; + if (my $slot=&slotted_access($queue{$key})) { + if (!exists($slot_cache{$slot})) { + my %slot_data=&Apache::lonnet::get_slot($slot); + $slot_cache{$slot} = \%slot_data; + } + if (time > $slot_cache{$slot}{'endtime'}) { + $ready_to_grade++; + } + } else { + my $due_date = &Apache::lonhomework::due_date('0',$symb); + if ($due_date ne '' && time > $due_date) { + $ready_to_grade++; + } } } } @@ -1290,6 +1331,22 @@ sub queue_key_locked { return undef; } +sub slotted_access { + my ($queue_entry) = @_; + if (ref($queue_entry) eq 'ARRAY') { + if (defined($queue_entry->[0])) { + return $queue_entry->[0]; + } + return undef; + } elsif (ref($queue_entry) eq 'HASH') { + if (defined($queue_entry->{'slot'})) { + return $queue_entry->{'slot'}; + } + return undef; + } + return undef; +} + sub pick_from_queue_data { my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_; my @possible; # will hold queue entries that are valid to be selected @@ -1304,17 +1361,28 @@ sub pick_from_queue_data { next; } } - my $slot=$queuedata->{$key}[0]; - my %slot_data=&Apache::lonnet::get_slot($slot); - if ($slot_data{'endtime'} > time) { + my $end_time; + if (my $slot=&slotted_access($queuedata->{$key})) { + my %slot_data=&Apache::lonnet::get_slot($slot); + if ($slot_data{'endtime'} < time) { + $end_time = $slot_data{'endtime'}; + } + } else { + my $due_date = &Apache::lonhomework::due_date('0',$symb); + if ($due_date > time) { + $end_time = $due_date; + } + } + if ($end_time ne '') { &Apache::lonxml::debug("not time"); next; } + if (exists($queuedata->{"$key\0locked"})) { &Apache::lonxml::debug("someone already has um."); next; } - push(@possible,[$key,$slot_data{'endtime'}]); + push(@possible,[$key,$end_time]); } if (@possible) { # sort entries in order by slot end time