Annotation of loncom/homework/bridgetask.pm, revision 1.21
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.21 ! albertel 4: # $Id: bridgetask.pm,v 1.20 2005/05/10 16:03:44 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30:
31: package Apache::bridgetask;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::File();
36: use Apache::lonmenu;
37: use Apache::lonlocal;
38: use Apache::lonxml;
39: use Time::HiRes qw( gettimeofday tv_interval );
1.9 albertel 40:
1.1 albertel 41: BEGIN {
42: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
43: }
44:
1.9 albertel 45: sub initialize_bridgetask {
46: # id of current Dimension, 0 means that no dimension is current
47: # (inside <Task> only)
48: $Apache::bridgetask::dimension='';
49: # list of all Dimension ids seen
50: @Apache::bridgetask::dimensionlist=();
1.20 albertel 51: # mandatory attribute of all Dimensions seen
52: %Apache::bridgetask::dimensionmandatory=();
1.9 albertel 53: # list of all current Instance ids
54: @Apache::bridgetask::instance=();
55: # list of all Instance ids seen in this problem
56: @Apache::bridgetask::instancelist=();
1.15 albertel 57: # key of queud user data that we are currently grading
58: $Apache::bridgetask::queue_key='';
1.9 albertel 59: }
60:
1.4 albertel 61: sub proctor_check_auth {
62: my ($slot)=@_;
1.11 albertel 63: my $user=$env{'form.proctorname'};
64: my $domain=$env{'form.proctordomain'};
1.4 albertel 65:
66: my @allowed=split(",",$slot->{'proctor'});
67: foreach my $possible (@allowed) {
68: my ($puser,$pdom)=(split('@',$possible));
69: if ($puser eq $user && $pdom eq $domain) {
1.11 albertel 70: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4 albertel 71: if ($authhost ne 'no_host') {
72: $Apache::lonhomework::results{'resource.checkedin'}=
73: $user.'@'.$domain;
74: return 1;
75: }
76: }
77: }
78: return 0;
79: }
80:
1.8 albertel 81: sub add_previous_version_button {
82: my $result;
1.9 albertel 83: $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
1.8 albertel 84: <option>Pick one</option>
1.9 albertel 85: </select>');
1.8 albertel 86: return $result;
87: }
88:
1.13 albertel 89: sub add_grading_button {
90: my $result;
91: $result.=' <input type="submit" name="gradeasubmission" value="'.
92: &mt("Get a submission to grade").'" />';
93: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
94: return $result;
95: }
96:
1.1 albertel 97: sub start_Task {
98: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
99:
1.4 albertel 100: my ($status,$accessmsg,$slot);
1.16 albertel 101: if ($target ne 'webgrade') {
102: &Apache::structuretags::initialize_storage();
103: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
104: }
105:
1.4 albertel 106: $Apache::lonhomework::parsing_a_task=1;
1.1 albertel 107: #should get back a <html> or the neccesary stuff to start XML/MathML
108: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
109: &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16 albertel 110:
1.8 albertel 111: if ($target eq 'web') {
112: $body_tag_start.=&add_previous_version_button();
1.13 albertel 113: if ($Apache::lonhomework::modifygrades) {
114: $body_tag_start.='<form name="gradesubmission" method="POST" action="';
115: my $uri=$env{'request.uri'};
116: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
117: $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
118: }
1.8 albertel 119: }
1.21 ! albertel 120: if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1 albertel 121: $target eq 'tex') {
1.14 albertel 122: ($status,$accessmsg,my $slot_name,$slot) =
1.4 albertel 123: &Apache::lonhomework::check_task_access('0');
1.9 albertel 124: push(@Apache::inputtags::status,$status);
1.14 albertel 125: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 126: my $expression='$external::datestatus="'.$status.'";';
127: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
128: &Apache::run::run($expression,$safeeval);
129: &Apache::lonxml::debug("Got $status");
130: if (( $status eq 'CLOSED' ) ||
131: ( $status eq 'BANNED') ||
132: ( $status eq 'UNAVAILABLE') ||
1.3 albertel 133: ( $status eq 'NOT_IN_A_SLOT') ||
1.4 albertel 134: ( $status eq 'NEEDS_CHECKIN') ||
1.1 albertel 135: ( $status eq 'INVALID_ACCESS')) {
136: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
137: if ( $target eq "web" ) {
1.4 albertel 138: $result.= $head_tag_start.'</head>'.$body_tag_start;
139: my $msg;
1.1 albertel 140: if ($status eq 'UNAVAILABLE') {
141: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 142: } elsif ($status eq 'NOT_IN_A_SLOT') {
143: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4 albertel 144: } elsif ($status eq 'NEEDS_CHECKIN') {
145: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
146: '</h1>'.&proctor_validation_screen($slot);
1.1 albertel 147: } elsif ($status ne 'NOT_YET_VIEWED') {
148: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
149: }
150: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
151: $msg.='The problem '.$accessmsg;
152: }
153: $result.=$msg.'<br />';
154: } elsif ($target eq 'tex') {
155: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
156: if ($status eq 'UNAVAILABLE') {
157: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
158: } else {
159: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
160: }
1.4 albertel 161: } elsif ($target eq 'grade') {
162: if ($status eq 'NEEDS_CHECKIN') {
163: if (&proctor_check_auth($slot)) {
164: #FIXME immeadiatly add this to the grading queue
165: # with slot->{'endtime'} for when grading can
166: # begin on this resource
167: }
168: }
1.1 albertel 169: }
170: } elsif ($target eq 'web') {
171: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
172: $result.="$head_tag_start<title>$name</title></head>
173: $body_tag_start \n $form_tag_start".
174: '<input type="hidden" name="submitted" value="yes" />';
175: # if we are viewing someone else preserve that info
1.11 albertel 176: if (defined $env{'form.grade_symb'}) {
1.1 albertel 177: foreach my $field ('symb','courseid','domain','username') {
178: $result .= '<input type="hidden" name="grade_'.$field.
1.11 albertel 179: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.1 albertel 180: }
181: }
182: }
1.21 ! albertel 183: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
! 184: $target eq 'webgrade') {
! 185: if ($target eq 'webgrade') {
! 186: $result.=$head_tag_start.$body_tag_start.$form_tag_start;
! 187: $result.='<input type="hidden" name="webgrade" value="yes" />';
! 188: $result.=&show_queue();
! 189: }
1.15 albertel 190: my $todo=&get_from_queue();
191: if ($todo) {
1.16 albertel 192: &setup_env_for_other_user($todo,$safeeval);
1.15 albertel 193: my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.16 albertel 194: $result.="\n".'<table><tr><td>Found '.
195: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
1.15 albertel 196: $result.='<input type="hidden" name="gradingkey" value="'.
1.16 albertel 197: &Apache::lonnet::escape($todo).'" />';
1.15 albertel 198: $Apache::bridgetask::queue_key=$todo;
1.16 albertel 199: &Apache::structuretags::initialize_storage();
200: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.18 albertel 201: $result.="\n".'<table width="100%" style="width:100%" border="1">';
1.15 albertel 202: } else {
1.21 ! albertel 203: if ($target eq 'webgrade') {
! 204: $result.="\n".
! 205: '<table><tr><td>No user to be graded.</td></tr></table>';
! 206: }
1.15 albertel 207: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
208: }
1.1 albertel 209: } else {
210: # page_start returned a starting result, delete it if we don't need it
211: $result = '';
212: }
213: return $result;
214: }
215:
216: sub end_Task {
217: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
218: my $result='';
219: my $status=$Apache::inputtags::status['-1'];
220: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 221: $target eq 'tex') {
1.1 albertel 222: if (
1.11 albertel 223: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1 albertel 224: ($target eq 'answer') || ($target eq 'tex')
225: ) {
226: if ($target eq 'web') {
1.9 albertel 227: if ($status eq 'CAN_ANSWER') {
1.15 albertel 228: $result.="\n".'<table border="1">'.
1.9 albertel 229: &Apache::inputtags::file_selector('0',"bridgetask","*",
230: 'portfolioonly').
231: "</table>";
232: $result.=&Apache::inputtags::gradestatus('0');
233: }
1.13 albertel 234: }
235: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 236: $result.=&Apache::lonxml::xmlend().'</html>';
237: }
238: }
1.20 albertel 239: if ($target eq 'grade' && !$env{'form.webgrade'}) {
1.12 albertel 240: my $award='SUBMITTED';
1.20 albertel 241: &Apache::essayresponse::file_submission('0','bridgetask',
242: 'portfiles',\$award);
1.14 albertel 243: if ($award eq 'SUBMITTED' &&
244: $Apache::lonhomework::results{"resource.0.bridgetask.portfiles"}) {
1.10 albertel 245: $Apache::lonhomework::results{"resource.0.tries"}=
246: 1+$Apache::lonhomework::history{"resource.0.tries"};
247: }
1.14 albertel 248: $Apache::lonhomework::results{"resource.0.award"}=$award;
1.4 albertel 249: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
250: &Apache::structuretags::finalize_storage();
1.14 albertel 251: if ($award eq 'SUBMITTED') {
252: &add_to_queue();
253: }
1.1 albertel 254: }
1.20 albertel 255: if ($target eq 'grade' && $env{'form.webgrade'}) {
256: my $optional_required=
257: &Apache::lonxml::get_param('OptionalRequired',$parstack,
258: $safeeval);
259: my $optional_passed=0;
260: my $mandatory_failed=0;
261: my $ungraded=0;
262: my $review=0;
1.21 ! albertel 263: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 264: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
265: my $status=
1.21 ! albertel 266: $Apache::lonhomework::results{"resource.$dim_id.status"};
1.20 albertel 267: my $mandatory=
268: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
269: if ($status eq 'pass') {
270: if (!$mandatory) { $optional_passed++; }
271: } elsif ($status eq 'fail') {
272: if ($mandatory) { $mandatory_failed++; }
273: } elsif ($status eq 'ungraded') {
274: $ungraded++;
275: } elsif ($status eq 'review') {
276: $review++;
277: }
278: }
279: if ($optional_passed < $optional_required) {
280: $mandatory_failed++;
281: }
1.21 ! albertel 282: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
! 283: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 284: $env{'user.name'}.'@'.$env{'user.domain'};
285: if ($review) {
1.21 ! albertel 286: $Apache::lonhomework::results{'resource.status'}='review';
1.20 albertel 287: &move_to_review_queue();
288: } elsif ($ungraded) {
1.21 ! albertel 289: $Apache::lonhomework::results{'resource.status'}='ungraded';
1.20 albertel 290: &check_queue_unlock();
291: } elsif ($mandatory_failed) {
1.21 ! albertel 292: $Apache::lonhomework::results{'resource.status'}='fail';
1.20 albertel 293: $Apache::lonhomework::results{"resource.0.award"}='EXACT_ANS';
294: &remove_from_queue();
295: } else {
1.21 ! albertel 296: $Apache::lonhomework::results{'resource.status'}='pass';
1.20 albertel 297: $Apache::lonhomework::results{"resource.0.award"}='INCORRECT';
298: &remove_from_queue();
299: }
1.21 ! albertel 300: &Apache::structuretags::finalize_storage();
1.20 albertel 301: }
1.15 albertel 302: } elsif ($target eq 'webgrade') {
1.18 albertel 303: $result.="</table>\n<hr />";
1.20 albertel 304: #$result.='<input type="submit" name="next" value="'.
305: # &mt('Save & Next').'" /> ';
306: #$result.='<input type="submit" name="end" value="'.
307: # &mt('Save & Stop Grading').'" /> ';
308: #$result.='<input type="submit" name="throwaway" value="'.
309: # &mt('Throw Away & Stop Grading').'" /> ';
310: #$result.='<input type="submit" name="save" value="'.
311: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 312: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 313: } elsif ($target eq 'meta') {
1.2 albertel 314: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 315: #$result.=&Apache::response::meta_part_order();
316: #$result.=&Apache::response::meta_response_order();
317: }
1.4 albertel 318: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 319: return $result;
320: }
321:
1.21 ! albertel 322: sub move_to_review_queue {
! 323: &Apache::lonxml::debug("Want to move");
! 324: }
! 325:
! 326: sub check_queue_unlock {
! 327: &Apache::lonxml::debug("Want to unlock?");
! 328: }
! 329:
! 330: sub remove_from_queue {
! 331: &Apache::lonxml::debug("Want to remove. Done?");
! 332: }
! 333:
1.16 albertel 334: sub setup_env_for_other_user {
335: my ($queue_key,$safeeval)=@_;
336: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
337: $env{'form.grade_symb'}=$symb;
338: $env{'form.grade_domain'}=$udom;
339: $env{'form.grade_username'}=$uname;
340: $env{'form.grade_courseid'}=$env{'request.course.id'};
341: &Apache::lonxml::initialize_rndseed($safeeval);
342: }
343:
1.14 albertel 344: sub add_to_queue {
345: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
346: my $cnum=$env{'course.'.$cid.'.num'};
347: my $cdom=$env{'course.'.$cid.'.domain'};
348: my %data;
349: $data{"$symb\0queue\0$uname\@$udom"}=[$Apache::inputtags::slot_name];
350: &Apache::lonnet::put('gradingqueue',\%data,$cdom,$cnum);
351: }
352:
353: sub show_queue {
354: my $result;
355: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
356: my $cnum=$env{'course.'.$cid.'.num'};
357: my $cdom=$env{'course.'.$cid.'.domain'};
1.16 albertel 358: my $regexp="^$symb\0";
1.14 albertel 359: my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
1.20 albertel 360: $result.="\n<h3>Current Queue</h3><table><tr><th>resource</th>".
361: "<th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 362: foreach my $key (sort(keys(%queue))) {
1.16 albertel 363: if ($key=~/locked$/) {
364: my ($symb,$uname,$udom) = &decode_queue_key($key);
365: my $title=&Apache::lonnet::gettitle($symb);
366: $result.="<tr><td>$title</td><td>$uname</td><td>";
367: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
368: } elsif ($key=~/timestamp$/) {
369: my ($symb,undef) = split("\0",$key);
370: my $title=&Apache::lonnet::gettitle($symb);
371: $result.="<tr><td>$title</td><td></td><td>";
372: $result.='<td>last queue modification time</td><td>'.
373: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
374: } else {
375: my ($symb,$uname,$udom) = &decode_queue_key($key);
376: my $title=&Apache::lonnet::gettitle($symb);
377: $result.="<tr><td>$title</td><td>$uname</td><td>";
378: my $slot=$queue{$key}->[0];
379: my %slot_data=&Apache::lonnet::get_slot($slot);
1.20 albertel 380: $result.='<td>queue entry</td><td>End time: '.
381: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
382: "</td></tr>";
1.16 albertel 383: }
1.14 albertel 384: }
1.15 albertel 385: $result.="</table><hr />\n";
1.14 albertel 386: return $result;
387: }
388:
389: sub decode_queue_key {
390: my ($key)=@_;
391: my ($symb,undef,$user) = split("\0",$key);
392: my ($uname,$udom) = split('@',$user);
393: return ($symb,$uname,$udom);
394: }
395:
396: sub queue_key_locked {
1.15 albertel 397: my ($key,$cdom,$cnum)=@_;
1.14 albertel 398: my ($key_locked,$value)=
399: &Apache::lonnet::get('gradingqueue',["$key\0locked"],$cdom,$cnum);
400: if ($key_locked eq "$key\0locked") {
401: return $value;
402: }
403: return undef;
404: }
405:
406: sub pick_from_queue_data {
1.15 albertel 407: my ($check_section,$queue,$cdom,$cnum)=@_;
1.16 albertel 408: foreach my $key (keys(%$queue)) {
1.14 albertel 409: my ($symb,$uname,$udom)=&decode_queue_key($key);
410: if ($check_section) {
411: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 412: if ($section eq $check_section) {
413: &Apache::lonnet::logthis("my sec");
1.15 albertel 414: next;
415: }
1.14 albertel 416: }
417: my $slot=$queue->{$key}[0];
418: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 419: if ($slot_data{'endtime'} > time) {
420: &Apache::lonnet::logthis("not time");
421: next;
422: }
423: if (&queue_key_locked($key,$cdom,$cnum)) {
424: &Apache::lonnet::logthis("someone already has um.");
425: next;
426: }
1.14 albertel 427: return $key;
428: }
429: return undef;
430: }
431:
1.15 albertel 432: sub find_mid_grade {
433: my ($symb,$cdom,$cnum)=@_;
1.16 albertel 434: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 435: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
436: if ($todo) {
437: my $who=&queue_key_locked($todo,$cdom,$cnum);
438: if ($who eq $me) { return $todo; }
439: }
440: my $regexp="^$symb\0.*\0locked\$";
441: my %locks=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
442: foreach my $key (keys(%locks)) {
443: my $who=$locks{$key};
444: if ($who eq $me) {
445: $todo=$key;
446: $todo=~s/\0locked$//;
447: return $todo;
448: }
449: }
450: return undef;
451: }
452:
1.14 albertel 453: sub get_from_queue {
454: my $result;
455: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
456: my $cnum=$env{'course.'.$cid.'.num'};
457: my $cdom=$env{'course.'.$cid.'.domain'};
458: my $todo;
1.15 albertel 459: # FIXME need to find if I am 'mid grading'
460: $todo=&find_mid_grade($symb,$cdom,$cnum);
461: &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 462: if ($todo) { return $todo; }
1.14 albertel 463: while (1) {
464: my $starttime=time;
465: &Apache::lonnet::put('gradingqueue',{"$symb\0timestamp"=>$starttime},
466: $cdom,$cnum);
1.15 albertel 467: &Apache::lonnet::logthis("$starttime");
1.14 albertel 468: my $regexp="^$symb\0queue\0";
469: my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
470: #make a pass looking for a user in my section
471: if ($env{'request.course.sec'}) {
1.15 albertel 472: &Apache::lonnet::logthis("sce");
473: $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
474: $cdom,$cnum);
475: &Apache::lonnet::logthis("sce $todo");
1.14 albertel 476: }
477: # no one in our section so look for any user that is ready for grading
478: if (!$todo) {
1.15 albertel 479: &Apache::lonnet::logthis("no sce");
480: $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
481: $cdom,$cnum);
482: &Apache::lonnet::logthis("no sce $todo");
1.14 albertel 483: }
484: # no user to grade
485: if (!$todo) { last; }
1.15 albertel 486: &Apache::lonnet::logthis("got $todo");
1.14 albertel 487: # otherwise found someone so lets try to lock them
488: my $success=&Apache::lonnet::newput('gradingqueue',
489: {"$todo\0locked"=>
490: $env{'user.name'}.'@'.$env{'user.domain'}},
491: $cdom,$cnum);
492: # someone else already picked them
1.15 albertel 493: &Apache::lonnet::logthis("success $todo");
1.14 albertel 494: if ($success ne 'ok') { next; }
495: my (undef,$endtime)=
496: &Apache::lonnet::get('gradingqueue',["$symb\0timestamp"],
497: $cdom,$cnum);
1.15 albertel 498: &Apache::lonnet::logthis("emd $endtime");
1.14 albertel 499: # someone else already modified the queue,
500: # perhaps our picked user wass already fully graded between
501: # when we picked him and when we locked his record? so lets
502: # double check.
503: if ($endtime != $starttime) {
504: my ($key,$value)=
505: &Apache::lonnet::get('gradingqueue',["$todo"],
506: $cdom,$cnum);
1.15 albertel 507: &Apache::lonnet::logthis("check $key .. $value");
1.14 albertel 508: if ($key eq $todo && ref($value)) {
509: } else {
510: &Apache::lonnet::del('gradingqueue',["$todo\0locked"],
511: $cdom,$cnum);
1.15 albertel 512: &Apache::lonnet::logthis("del");
1.14 albertel 513: next;
514: }
515: }
1.15 albertel 516: &Apache::lonnet::logthis("last $todo");
1.14 albertel 517: last;
518: }
519: return $todo;
520: }
521:
1.1 albertel 522: sub start_ClosingParagraph {
523: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
524: my $result;
525: if ($target eq 'web') {
1.13 albertel 526: } elsif ($target eq 'webgrade') {
527: &Apache::lonxml::startredirection();
1.1 albertel 528: }
529: return $result;
530: }
531:
532: sub end_ClosingParagraph {
533: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
534: my $result;
535: if ($target eq 'web') {
1.13 albertel 536: } elsif ($target eq 'webgrade') {
537: &Apache::lonxml::endredirection();
1.1 albertel 538: }
539: return $result;
540: }
541:
1.19 albertel 542: sub get_id {
543: my ($parstack,$safeeval)=@_;
544: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
545: if (!$id) { $id=$Apache::lonxml::curdepth; }
546: return $id;
547: }
548:
1.1 albertel 549: my %dimension;
550: sub start_Dimension {
551: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
552: undef(%dimension);
1.19 albertel 553: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 554: $Apache::bridgetask::dimension=$dim_id;
555: push(@Apache::bridgetask::dimensionlist,$dim_id);
556: undef(@Apache::bridgetask::instance);
1.20 albertel 557: $Apache::bridgetask::dimensionmandatory{$dim_id}=
558: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 559: return '';
560: }
561:
1.13 albertel 562: sub get_instance {
563: #FIXME just grabbing the first one for now, need
564: #to randomly pick one until all have been seen
565: #then start repicking
566: &Apache::response::pushrandomnumber();
567: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
568: return $order[0];
569: }
570:
1.18 albertel 571: {
572: my $last_link;
573: sub end_Dimension {
574: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
575: my $result;
1.21 ! albertel 576: my $dim_id=&get_id($parstack,$safeeval);
1.19 albertel 577: my $instance=&get_instance();
1.18 albertel 578: if ($target eq 'web') {
579: $result=$dimension{'intro'}.$dimension{$instance.'.text'};
580: } elsif ($target eq 'webgrade') {
581: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
582: my $link='criteria_'.$instance.'_'.$id;
1.21 ! albertel 583: my $status=$Apache::lonhomework::history{'resource.'.$instance.'.'.$id.'.status'};
1.19 albertel 584: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 585: '<a name="'.$link.'" />'.
586: '<a name="next_'.$last_link.'" />'.
587: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">'.$dimension{$instance.'.criteria.'.$id}.'</textarea>'.
588: #$dimension{$instance.'.criteria.'.$id}.
589: '</td>'.
1.19 albertel 590: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.21 ! albertel 591: '<textarea style="width:100%" rows="8" width="25" wrap="hard" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{'resource.'.$instance.'.'.$id.'.comment'}).'</textarea>'.
1.18 albertel 592: '</td>'.
593: '<td>'.
1.20 albertel 594: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>Ungraded</label></nobr><br />'.
595: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />Pass</label><br />'.
596: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />Fail</label><br />'.
597: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />Review</label><br />'.
1.18 albertel 598: '</td>'.
599: '<td>'.
600: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 601: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
602: '<input type="submit" name="next" value="'.
603: &mt('Done').'" /> '.
1.18 albertel 604: '</td></tr>';
605: $last_link=$link;
606: }
1.19 albertel 607: } elsif ($target eq 'grade') {
608: my $optional_passed=0;
1.20 albertel 609: my $mandatory_failed=0;
610: my $ungraded=0;
611: my $review=0;
1.19 albertel 612: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.21 ! albertel 613: my $status=$Apache::lonhomework::results{'resource.'.$instance.'.'.$id.'.status'}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
! 614: $Apache::lonhomework::results{'resource.'.$instance.'.'.$id.'.comment'}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 615: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
616: if ($status eq 'pass') {
617: if (!$mandatory) { $optional_passed++; }
618: } elsif ($status eq 'fail') {
619: if ($mandatory) { $mandatory_failed++; }
1.21 ! albertel 620: } elsif ($status eq 'review') {
! 621: $review++;
1.20 albertel 622: } elsif ($status eq 'ungraded') {
623: $ungraded++;
1.21 ! albertel 624: } else {
! 625: &Apache::lonxml::error("got wierd status --$status--");
1.19 albertel 626: }
627: }
1.20 albertel 628: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
629: $mandatory_failed++;
630: }
1.21 ! albertel 631: &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.20 albertel 632: if ($review) {
1.21 ! albertel 633: $Apache::lonhomework::results{'resource.'.$dim_id.'.status'}='review';
1.20 albertel 634: } elsif ($ungraded) {
1.21 ! albertel 635: $Apache::lonhomework::results{'resource.'.$dim_id.'.status'}='ungraded';
1.20 albertel 636: } elsif ($mandatory_failed) {
1.21 ! albertel 637: $Apache::lonhomework::results{'resource.'.$dim_id.'.status'}='fail';
1.20 albertel 638: } else {
1.21 ! albertel 639: $Apache::lonhomework::results{'resource.'.$dim_id.'.status'}='pass';
1.20 albertel 640: }
1.13 albertel 641: }
1.18 albertel 642: return $result;
1.1 albertel 643: }
644: }
645:
646: sub start_IntroParagraph {
647: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
648: my $result;
1.13 albertel 649: if ($target eq 'web' || $target eq 'webgrade') {
650: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 651: &Apache::lonxml::startredirection();
652: }
653: }
654: return $result;
655: }
656:
657: sub end_IntroParagraph {
658: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
659: my $result;
1.13 albertel 660: if ($target eq 'web' || $target eq 'webgrade') {
661: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 662: $dimension{'intro'}=&Apache::lonxml::endredirection();
663: }
664: }
665: return $result;
666: }
667:
668: sub start_Instance {
669: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 670: my $id=&get_id($parstack,$safeeval);
671: push(@{$dimension{'instances'}},$id);
672: push(@Apache::bridgetask::instance,$id);
673: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 674: $dimension{$id.'.optionalrequired'}=
1.19 albertel 675: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 676: return '';
677: }
678:
679: sub end_Instance {
680: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
681: return '';
682: }
683:
684: sub start_InstanceText {
685: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13 albertel 686: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 687: &Apache::lonxml::startredirection();
688: }
689: return '';
690: }
691:
692: sub end_InstanceText {
693: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 694: my $instance_id=$Apache::bridgetask::instance[-1];
1.13 albertel 695: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 696: $dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
697: }
698: return '';
699: }
700:
701: sub start_Criteria {
702: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.21 ! albertel 703: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 704: &Apache::lonxml::startredirection();
705: }
706: return '';
707: }
708:
709: sub end_Criteria {
710: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 711: my $instance_id=$Apache::bridgetask::instance[-1];
1.21 ! albertel 712: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 713: my $criteria=&Apache::lonxml::endredirection();
1.19 albertel 714: my $id=&get_id($parstack,$safeeval);
1.1 albertel 715: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 716: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
717: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 718: push(@{$dimension{$instance_id.'.criterias'}},$id);
719: }
720: return '';
721: }
722:
1.4 albertel 723: sub proctor_validation_screen {
724: my ($slot) = @_;
725: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 726: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11 albertel 727: $user=$env{'form.proctorname'};
728: if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4 albertel 729: my $msg;
1.11 albertel 730: if ($env{'form.proctorpassword'}) {
1.4 albertel 731: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
732: .'</font></p>';
733: }
734: my $result= (<<ENDCHECKOUT);
735: <h2>Proctor Validation</h2>
736: <p>Your room's proctor needs to validate your access to this resource.</p>
737: $msg
1.11 albertel 738: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 739: <input type="hidden" name="validate" value="yes" />
740: <input type="hidden" name="submitted" value="yes" />
741: <table>
742: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
743: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6 albertel 744: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4 albertel 745: </table>
746: <input type="submit" name="checkoutbutton" value="Validate" /><br />
747: Student who should be logged in is:<br />
1.5 albertel 748: <img src="$url" /><br />
1.4 albertel 749: </form>
750: ENDCHECKOUT
751: return $result;
752: }
753:
1.1 albertel 754: 1;
755: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>