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