Annotation of loncom/homework/bridgetask.pm, revision 1.60
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.60 ! albertel 4: # $Id: bridgetask.pm,v 1.59 2005/10/01 03:27: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;
1.37 albertel 39: use Apache::slotrequest();
1.1 albertel 40: use Time::HiRes qw( gettimeofday tv_interval );
1.9 albertel 41:
1.1 albertel 42: BEGIN {
43: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
44: }
45:
1.9 albertel 46: sub initialize_bridgetask {
47: # id of current Dimension, 0 means that no dimension is current
48: # (inside <Task> only)
49: $Apache::bridgetask::dimension='';
50: # list of all Dimension ids seen
51: @Apache::bridgetask::dimensionlist=();
1.20 albertel 52: # mandatory attribute of all Dimensions seen
53: %Apache::bridgetask::dimensionmandatory=();
1.9 albertel 54: # list of all current Instance ids
55: @Apache::bridgetask::instance=();
56: # list of all Instance ids seen in this problem
57: @Apache::bridgetask::instancelist=();
1.15 albertel 58: # key of queud user data that we are currently grading
59: $Apache::bridgetask::queue_key='';
1.9 albertel 60: }
61:
1.4 albertel 62: sub proctor_check_auth {
1.22 albertel 63: my ($slot_name,$slot)=@_;
1.11 albertel 64: my $user=$env{'form.proctorname'};
65: my $domain=$env{'form.proctordomain'};
1.4 albertel 66:
67: my @allowed=split(",",$slot->{'proctor'});
68: foreach my $possible (@allowed) {
69: my ($puser,$pdom)=(split('@',$possible));
70: if ($puser eq $user && $pdom eq $domain) {
1.11 albertel 71: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4 albertel 72: if ($authhost ne 'no_host') {
1.23 albertel 73: my $version=
74: $Apache::lonhomework::results{'resource.version'}=
1.27 albertel 75: ++$Apache::lonhomework::history{'resource.version'};
1.23 albertel 76: $Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4 albertel 77: $user.'@'.$domain;
1.23 albertel 78: $Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22 albertel 79: $slot_name;
1.28 albertel 80: foreach my $key (keys(%Apache::lonhomework::history)) {
81: if ($key=~/^resource\.0\./) {
82: $Apache::lonhomework::results{$key}='';
83: }
84: }
1.4 albertel 85: return 1;
86: }
87: }
88: }
89: return 0;
90: }
91:
1.25 albertel 92: sub get_version {
1.29 albertel 93: my ($version,$previous);
1.25 albertel 94: if ($env{'form.previousversion'} &&
1.36 albertel 95: $env{'form.previousversion'} ne 'current' &&
1.25 albertel 96: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
1.29 albertel 97: $version=$env{'form.previousversion'};
98: $previous=1;
99: } else {
100: $version=$Apache::lonhomework::history{'resource.version'};
101: $previous=0;
102: }
103: if (wantarray) {
104: return ($version,$previous);
1.25 albertel 105: }
1.29 albertel 106: return $version;
1.25 albertel 107: }
108:
1.8 albertel 109: sub add_previous_version_button {
1.25 albertel 110: my ($status)=@_;
1.8 albertel 111: my $result;
1.29 albertel 112: if ($Apache::lonhomework::history{'resource.version'} eq '') {
1.25 albertel 113: return '';
114: }
1.29 albertel 115: if ($Apache::lonhomework::history{'resource.version'} < 2 &&
116: $status ne 'NEEDS_CHECKIN') {
1.25 albertel 117: return '';
118: }
1.29 albertel 119: my $version=&get_version();
120: if ($env{'form.previousversion'} ne '' &&
121: $env{'form.previousversion'} eq $version) {
122: $result.="<h3>".&mt("Showing previous version [_1]",$version).
123: "</h3>\n";
124: }
125: my @to_show;
126: foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
127: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
128: push(@to_show,$test_version);
129: }
130: }
131: my $list='<option>'.
132: join("</option>\n<option>",@to_show).
133: "</option>\n";
1.36 albertel 134: $list.='<option value="current">'.&mt('Current').'</option>';
1.29 albertel 135: $result.='<form name="getprevious" method="POST" action="';
136: my $uri=$env{'request.uri'};
137: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
138: $result.=$uri.'">'.
139: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
140: <option>'.&mt('Pick one').'</option>
141: '.$list.'
142: </select>')."</form>";
1.8 albertel 143: return $result;
144: }
145:
1.13 albertel 146: sub add_grading_button {
1.59 albertel 147: my (undef,$cid)=&Apache::lonxml::whichuser();
148: my $cnum=$env{'course.'.$cid.'.num'};
149: my $cdom=$env{'course.'.$cid.'.domain'};
150: my %sections;
151: my $numsections=&Apache::loncommon::get_sections($cdom,$cnum,\%sections);
152: my $size=5;
153: if (scalar(keys(%sections)) < 3) {
154: $size=scalar(keys(%sections))+2;
155: }
156: my $sec_select = '<select multiple name="chosensections" size="'.$size.'">'."\n";
157: $sec_select .= "<option value='all' selected='selected'>all</option>\n";
158: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
159: $sec_select .= "<option name=\"$sec\">$sec</option>\n";
160: }
161: $sec_select .= "<option value='none'>none</option></select>\n";
162:
1.29 albertel 163: my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13 albertel 164: &mt("Get a submission to grade").'" />';
165: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40 albertel 166: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34 albertel 167: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.59 albertel 168: $result.='<p>Specify a section: '.$sec_select.'</p>';
1.34 albertel 169: $result.='<p>'.&mt("Grading Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
170:
171: $result.=' <input type="submit" name="reviewagrading" value="'.
172: &mt("Select an entry from the grading queue").'" /> </p>'."\n";
173:
174: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
175: $result.='<p>'.&mt("Review Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
1.32 albertel 176: $result.=' <input type="submit" name="reviewasubmission" value="'.
1.34 albertel 177: &mt("Select an entry from the review queue").'" /> </p>'."\n";
1.49 albertel 178: $result.=' <input type="submit" name="regradeasubmission" value="'.
179: &mt("Select a user to regrade.").'" /> </p>'."\n";
1.32 albertel 180: }
1.13 albertel 181: return $result;
182: }
183:
1.22 albertel 184: sub add_request_another_attempt_button {
1.38 albertel 185: my ($text)=@_;
186: if (!$text) { $text="Request another attempt"; }
1.25 albertel 187: my $result;
1.36 albertel 188: my $symb=&Apache::lonnet::symbread();
1.37 albertel 189: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38 albertel 190: my $action='get_reservation';
1.37 albertel 191: if ($slot_name) {
1.38 albertel 192: $text="Change reservation.";
193: $action='change_reservation';
1.37 albertel 194: my $description=&Apache::slotrequest::get_description($slot_name,
195: $slot);
196: $result.=(<<STUFF);
197: <p> Will be next available: $description </p>
198: STUFF
199: }
1.38 albertel 200:
201: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
202: $symb=&Apache::lonnet::escape($symb);
203: $result.='<form method="POST" action="/adm/slotrequest">'.
204: '<input type="hidden" name="symb" value="'.$symb.'" />'.
205: '<input type="hidden" name="command" value="'.$action.'" />'.
206: '<input type="submit" name="requestattempt" value="'.
207: &mt($text).'" />'.
208: '</form>';
1.25 albertel 209: return $result;
1.22 albertel 210: }
211:
1.30 albertel 212: sub preserve_grade_info {
213: my $result;
214: # if we are viewing someone else preserve that info
215: if (defined $env{'form.grade_symb'}) {
216: foreach my $field ('symb','courseid','domain','username') {
217: $result .= '<input type="hidden" name="grade_'.$field.
218: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
219: }
220: }
221: return $result;
222: }
223:
1.53 albertel 224: sub style {
225: return (<<STYLE);
226: <style type="text/css">
227: .fail, .pass, .neutral {
228: position: relative;
229: margin : 5px;
230: margin-bottom :10px;
231: padding : 4px;
232: padding-left : 75px;
233: border : thin solid;
234: font-weight : bolder;
235: font-size: smaller;
236: font-family: Arial;
237: background-color : rgb(255,240,225);
238: }
239:
240: .fail h4, .pass h4 {
241: position:absolute;
242: left: -4px;
243: top: -8px;
244: padding:2px;
245: margin:0;
246: background-color : rgb(255,240,225);
247: border : thin solid;
248: }
249:
250: .fail {
251: color: red;
252: }
253:
254: .pass {
255: color : green;
256: }
257:
258: .neutral {
259: color : blue;
260: }
261:
262: .question {
263: border : thin solid black;
264: padding : 4px;
265: margin-bottom : 1em;
266: }
267:
268: .grade {
269: font-size: x-large;
270: font-family: Arial;
271: position:absolute;
272: left: 5px;
273: top: -5px;
274: width: 70px;
275: }
276:
277: div#feedback h1 {
278: color : inherit;
279: }
280: </style>
281: STYLE
282:
283: }
284:
1.54 albertel 285: sub show_task {
286: my ($status,$previous)=@_;
287: if (!$previous && (
288: ( $status eq 'CLOSED' ) ||
289: ( $status eq 'BANNED') ||
290: ( $status eq 'UNAVAILABLE') ||
291: ( $status eq 'NOT_IN_A_SLOT') ||
292: ( $status eq 'NEEDS_CHECKIN') ||
293: ( $status eq 'WAITING_FOR_GRADE') ||
294: ( $status eq 'INVALID_ACCESS') )) {
295: return 0;
296: }
297: return 1;
298: }
299:
300: sub internal_location {
301: my ($id)=@_;
302: return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
303: }
304:
1.60 ! albertel 305: sub submission_time_stamp {
! 306: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
! 307: my $submissiontime;
! 308: my $version=$Apache::lonhomework::history{'resource.version'};
! 309: for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
! 310: if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
! 311: $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
! 312: }
! 313: }
! 314: my $result;
! 315: if ($submissiontime) {
! 316: my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.checkedin.slot'};
! 317: my %slot=&Apache::lonnet::get_slot($slot_name);
! 318: my $diff = $slot{'endtime'} - $submissiontime;
! 319: my ($color,$when)=('red','after');
! 320: if ($diff > 0) { ($color,$when)=('green','before'); }
! 321: my $info;
! 322: if ($diff%60) { $info=($diff%60).' seconds'; }
! 323: $diff=int($diff/60);
! 324: if ($diff%60) { $info=($diff%60).' minutes '.$info; }
! 325: $diff=int($diff/60);
! 326: if ($diff) { $info=$diff.' hours '.$info; }
! 327: $result='<p><font color="'.$color.'">'.
! 328: &mt('Student submitted [_1] [_2] the deadline.
! 329: (Submission was at [_3], end of period was [_4].)',
! 330: $info,$when,scalar(localtime($submissiontime)),
! 331: scalar(localtime($slot{'endtime'}))).
! 332: '</font></p>';
! 333: }
! 334: return $result;
! 335: }
! 336:
1.1 albertel 337: sub start_Task {
338: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
339:
1.4 albertel 340: my ($status,$accessmsg,$slot);
1.16 albertel 341: if ($target ne 'webgrade') {
342: &Apache::structuretags::initialize_storage();
343: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
344: }
345:
1.4 albertel 346: $Apache::lonhomework::parsing_a_task=1;
1.1 albertel 347: #should get back a <html> or the neccesary stuff to start XML/MathML
348: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
349: &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16 albertel 350:
1.8 albertel 351: if ($target eq 'web') {
1.13 albertel 352: if ($Apache::lonhomework::modifygrades) {
353: $body_tag_start.='<form name="gradesubmission" method="POST" action="';
354: my $uri=$env{'request.uri'};
355: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
356: $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
1.38 albertel 357: my $symb=&Apache::lonnet::symbread();
1.40 albertel 358: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
359: $body_tag_start.='<form method="POST" action="/adm/slotrequest">'.
360: '<input type="hidden" name="symb" value="'.$symb.'" />'.
361: '<input type="hidden" name="command" value="showslots" />'.
362: '<input type="submit" name="requestattempt" value="'.
363: &mt('Show Slot list').'" />'.
364: '</form>';
365: }
1.13 albertel 366: }
1.8 albertel 367: }
1.21 albertel 368: if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1 albertel 369: $target eq 'tex') {
1.29 albertel 370: my ($version,$previous)=&get_version();
1.14 albertel 371: ($status,$accessmsg,my $slot_name,$slot) =
1.4 albertel 372: &Apache::lonhomework::check_task_access('0');
1.9 albertel 373: push(@Apache::inputtags::status,$status);
1.14 albertel 374: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 375: my $expression='$external::datestatus="'.$status.'";';
1.23 albertel 376: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1 albertel 377: &Apache::run::run($expression,$safeeval);
378: &Apache::lonxml::debug("Got $status");
1.25 albertel 379: $body_tag_start.=&add_previous_version_button($status);
1.54 albertel 380: if (!&show_task($status,$previous)) {
1.1 albertel 381: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
382: if ( $target eq "web" ) {
1.4 albertel 383: $result.= $head_tag_start.'</head>'.$body_tag_start;
384: my $msg;
1.1 albertel 385: if ($status eq 'UNAVAILABLE') {
386: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 387: } elsif ($status eq 'NOT_IN_A_SLOT') {
388: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38 albertel 389: $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4 albertel 390: } elsif ($status eq 'NEEDS_CHECKIN') {
391: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
392: '</h1>'.&proctor_validation_screen($slot);
1.22 albertel 393: } elsif ($status eq 'WAITING_FOR_GRADE') {
394: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1 albertel 395: } elsif ($status ne 'NOT_YET_VIEWED') {
396: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
397: }
398: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
399: $msg.='The problem '.$accessmsg;
400: }
401: $result.=$msg.'<br />';
402: } elsif ($target eq 'tex') {
403: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
404: if ($status eq 'UNAVAILABLE') {
405: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
406: } else {
407: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
408: }
1.22 albertel 409: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 410: if ($status eq 'NEEDS_CHECKIN') {
1.41 albertel 411: &proctor_check_auth($slot_name,$slot);
1.4 albertel 412: }
1.1 albertel 413: }
414: } elsif ($target eq 'web') {
415: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
416: $result.="$head_tag_start<title>$name</title></head>
1.53 albertel 417: $body_tag_start \n".&style();
1.36 albertel 418:
1.57 albertel 419: $result.=&preserve_grade_info();
420: $result.=&internal_location();
1.36 albertel 421: $result.=$form_tag_start.
422: '<input type="hidden" name="submitted" value="yes" />';
1.54 albertel 423: &Apache::lonxml::startredirection();
1.1 albertel 424: }
1.21 albertel 425: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
426: $target eq 'webgrade') {
1.32 albertel 427: my $webgrade='yes';
1.21 albertel 428: if ($target eq 'webgrade') {
1.32 albertel 429: $result.=$head_tag_start.$body_tag_start;
1.49 albertel 430: #$result.='<br />Review'.&show_queue('reviewqueue');
431: #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 432: }
1.33 albertel 433: # FIXME Blast! still need to reorg this, need to reshow the
434: # queue being reviewed once done with the grade pass...
435: # Hrrm, vaildation pass should perhaps say 'not_locked'
436: # perhaps do a search if there is a key that is mine and if
437: # there isn't reshow the queue....
438: my ($todo,$status_code)=&get_key_todo($target);
439:
440: if ($todo) {
441: &setup_env_for_other_user($todo,$safeeval);
442: my ($symb,$uname,$udom)=&decode_queue_key($todo);
443: $result.="\n".'<table><tr><td>Found '.
444: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
445: $form_tag_start.=
446: '<input type="hidden" name="gradingkey" value="'.
447: &Apache::lonnet::escape($todo).'" />';
448: $Apache::bridgetask::queue_key=$todo;
449: &Apache::structuretags::initialize_storage();
450: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
451: if ($target eq 'webgrade') {
1.49 albertel 452: #$result.='<br />After -'.&show_queue($env{'form.queue'});
1.33 albertel 453: $result.="\n".'<table width="100%" style="width:100%" border="1">';
454: if ($status_code eq 'selected') {
455: $form_tag_start.=
456: '<input type="hidden" name="queuemode" value="selected" />';
457: }
458: }
1.15 albertel 459: } else {
1.33 albertel 460: if ($target eq 'webgrade') {
461: $result.="\n";
462: if ($status_code eq 'stop') {
463: $result.='<b>'.&mt("Stopped grading.").'</b>';
464: } elsif ($status_code eq 'lock_failed') {
465: $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
466: } elsif ($status_code eq 'unlock') {
467: $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
468: $result.=&show_queue($env{'form.queue'},1);
469: } elsif ($status_code eq 'show_list') {
470: $result.=&show_queue($env{'form.queue'},1);
1.49 albertel 471: } elsif ($status_code eq 'select_user') {
472: $result.=&select_user();
1.33 albertel 473: } else {
474: $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32 albertel 475: }
1.21 albertel 476: }
1.33 albertel 477: $webgrade='no';
478: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32 albertel 479: }
480: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.60 ! albertel 481: $result.=&submission_time_stamp();
1.32 albertel 482: $result.=$form_tag_start;
483: $result.='<input type="hidden" name="webgrade" value="'.
484: $webgrade.'" />';
485: $result.='<input type="hidden" name="queue" value="'.
486: $env{'form.queue'}.'" />';
1.52 albertel 487: if ($env{'form.regrade'}) {
488: $result.='<input type="hidden" name="regrade" value="'.
489: $env{'form.regrade'}.'" />';
490: }
1.15 albertel 491: }
1.1 albertel 492: } else {
493: # page_start returned a starting result, delete it if we don't need it
494: $result = '';
495: }
496: return $result;
497: }
498:
1.32 albertel 499: sub get_key_todo {
500: my ($target)=@_;
501: my $todo;
1.33 albertel 502:
503: if (defined($env{'form.reviewasubmission'})) {
1.54 albertel 504: &Apache::lonxml::debug("review a submission....");
1.33 albertel 505: $env{'form.queue'}='reviewqueue';
506: return (undef,'show_list');
507: }
508:
509: if (defined($env{'form.reviewagrading'})) {
510: &Apache::lonxml::debug("review a grading....");
511: $env{'form.queue'}='gradingqueue';
512: return (undef,'show_list');
513: }
514:
1.49 albertel 515: if (defined($env{'form.regradeasubmission'})) {
516: &Apache::lonxml::debug("regrade a grading....");
517: $env{'form.queue'}='none';
518: return (undef,'select_user');
519: }
520:
1.32 albertel 521: my $queue=$env{'form.queue'};
1.33 albertel 522:
1.32 albertel 523: if (!defined($queue)) {
524: $env{'form.queue'}=$queue='gradingqueue';
525: }
1.33 albertel 526:
1.32 albertel 527: my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33 albertel 528:
1.49 albertel 529: if ($env{'form.queue'} eq 'none') {
530: if (defined($env{'form.gradingkey'})) {
531: if ($target eq 'webgrade') {
532: if ($env{'form.stop'}) {
533: return (undef,'stop');
534: } elsif ($env{'form.next'}) {
1.59 albertel 535: return (undef,'select_user');
1.49 albertel 536: }
537: }
538: return ($gradingkey,'selected');
539: } else {
1.59 albertel 540: return (undef,'select_user');
1.49 albertel 541: }
542: }
1.32 albertel 543: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 albertel 544: && !defined($env{'form.gradingaction'})
545: && $env{'form.queuemode'} eq 'selected') {
546:
547: my $who=&queue_key_locked($queue,$gradingkey);
548: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
549: if ($who eq $me) {
550: &Apache::lonxml::debug("Found a key was given to me");
551: return ($gradingkey,'selected');
552: } else {
553: return (undef,'show_list');
554: }
555:
556: }
557:
558: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
559: if ($env{'form.gradingaction'} eq 'resume') {
560: delete($env{'form.gradingaction'});
561: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 562: return ($gradingkey);
1.33 albertel 563: } elsif ($env{'form.gradingaction'} eq 'unlock') {
564: &Apache::lonxml::debug("Unlocking a key ".
565: &check_queue_unlock($queue,$gradingkey,1));
566: return (undef,'unlock');
567: } elsif ($env{'form.gradingaction'} eq 'select') {
568: &Apache::lonxml::debug("Locking a key");
569: if (&lock_key($queue,$gradingkey)) {
570: &Apache::lonxml::debug("Success $queue");
571: return ($gradingkey);
572: }
573: &Apache::lonxml::debug("Failed $queue");
574: return (undef,'lock_failed');
1.32 albertel 575: }
576: }
1.33 albertel 577:
578: if ($env{'form.queuemode'} ne 'selected') {
579: # don't get something new from the queue if they hit the stop button
580: if (!($env{'form.stop'} && $target eq 'webgrade')
581: && !$env{'form.gradingaction'}) {
582: &Apache::lonxml::debug("Getting anew $queue");
583: return (&get_from_queue($queue));
584: } else {
585: return (undef,'stop');
586: }
1.32 albertel 587: }
1.33 albertel 588: return (undef,undef)
1.32 albertel 589: }
590:
1.1 albertel 591: sub end_Task {
592: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
593: my $result='';
594: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 595: my ($version,$previous)=&get_version();
1.1 albertel 596: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 597: $target eq 'tex') {
1.1 albertel 598: if (
1.11 albertel 599: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1 albertel 600: ($target eq 'answer') || ($target eq 'tex')
601: ) {
602: if ($target eq 'web') {
1.54 albertel 603: if (&show_task($status,$previous)) {
604: $result.=&Apache::lonxml::endredirection();
605: }
1.29 albertel 606: if ($status eq 'CAN_ANSWER' && !$previous) {
1.15 albertel 607: $result.="\n".'<table border="1">'.
1.28 albertel 608: &Apache::inputtags::file_selector("$version.0",
609: "bridgetask","*",
1.46 albertel 610: 'portfolioonly',
611: '
612: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
613: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9 albertel 614: "</table>";
615: $result.=&Apache::inputtags::gradestatus('0');
616: }
1.56 albertel 617: if (&show_task($status,$previous) &&
618: $Apache::lonhomework::history{"resource.$version.status"} =~ /^(pass|fail)$/) {
1.54 albertel 619: my $bt_status=$Apache::lonhomework::history{"resource.$version.status"};
620: my $title=&Apache::lonnet::gettitle();
621: my %slot=&Apache::lonnet::get_slot($Apache::inputtags::slot_name);
1.55 albertel 622: my $start_time=
623: &Apache::lonlocal::locallocaltime($slot{'starttime'});
1.54 albertel 624:
625: my $status;
626: $status.="\n<div class='$bt_status'>\n";
627:
628: if ($bt_status eq 'pass') {
629: $status.='<h2>You passed the '.$title.' given on '.
1.55 albertel 630: $start_time.'.</h2>';
1.54 albertel 631: }
632: if ($bt_status eq 'fail') {
633: $status.='<h2>You did not pass the '.$title.' given on '.
1.55 albertel 634: $start_time.'.</h2>';
1.54 albertel 635: if (!$previous) {
636: $status.=&add_request_another_attempt_button();
637: }
638: }
639: my $man_count=0;
640: my $opt_count=0;
641: my $opt_passed=0;
642: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
643: if ($Apache::bridgetask::dimensionmandatory{$dim_id}
644: eq 'N') {
645: $opt_count++;
646: if ($Apache::lonhomework::history{"resource.$version.$dim_id.status"} eq 'pass') {
647: $opt_passed++;
648: }
649: } else {
650: $man_count++;
651: }
652: }
653: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
654: $parstack,$safeeval);
655: if ($opt_req !~ /\S/) { $opt_req='0'; }
656: $status.="\n<p>".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components on the bridge task.',$man_count,$opt_req,$opt_count)."</p></div>\n";
657:
658: my $internal_location=&internal_location();
659: $result=~s/\Q$internal_location\E/$status/;
660: }
1.13 albertel 661: }
662: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 663: $result.=&Apache::lonxml::xmlend().'</html>';
664: }
665: }
1.29 albertel 666: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 667: my $award='SUBMITTED';
1.28 albertel 668: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 669: 'portfiles',\$award);
1.14 albertel 670: if ($award eq 'SUBMITTED' &&
1.28 albertel 671: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
672: $Apache::lonhomework::results{"resource.0.tries"}=
673: $Apache::lonhomework::results{"resource.$version.0.tries"}=
674: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
675:
676: $Apache::lonhomework::results{"resource.0.award"}=
677: $Apache::lonhomework::results{"resource.$version.0.award"}=
678: $award;
1.51 albertel 679: $Apache::lonhomework::results{"resource.0.submission"}=
680: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.10 albertel 681: }
1.4 albertel 682: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
683: &Apache::structuretags::finalize_storage();
1.14 albertel 684: if ($award eq 'SUBMITTED') {
1.31 albertel 685: &add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14 albertel 686: }
1.1 albertel 687: }
1.32 albertel 688: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20 albertel 689: my $optional_required=
690: &Apache::lonxml::get_param('OptionalRequired',$parstack,
691: $safeeval);
692: my $optional_passed=0;
693: my $mandatory_failed=0;
694: my $ungraded=0;
695: my $review=0;
1.21 albertel 696: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 697: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
698: my $status=
1.25 albertel 699: $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20 albertel 700: my $mandatory=
701: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
702: if ($status eq 'pass') {
703: if (!$mandatory) { $optional_passed++; }
704: } elsif ($status eq 'fail') {
705: if ($mandatory) { $mandatory_failed++; }
706: } elsif ($status eq 'ungraded') {
707: $ungraded++;
708: } elsif ($status eq 'review') {
709: $review++;
1.49 albertel 710: } else {
711: $ungraded++;
712: }
1.20 albertel 713: }
714: if ($optional_passed < $optional_required) {
715: $mandatory_failed++;
716: }
1.21 albertel 717: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
718: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 719: $env{'user.name'}.'@'.$env{'user.domain'};
720: if ($review) {
1.25 albertel 721: $Apache::lonhomework::results{"resource.$version.status"}='review';
1.33 albertel 722: if ($env{'form.queue'} eq 'reviewqueue') {
723: &check_queue_unlock($env{'form.queue'});
724: &Apache::lonxml::debug(" still needs review not changing status.");
725: } else {
1.49 albertel 726: &move_between_queues($env{'form.queue'},'reviewqueue');
1.33 albertel 727: }
1.20 albertel 728: } elsif ($ungraded) {
1.25 albertel 729: $Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.49 albertel 730: if ($env{'form.queue'} eq 'reviewqueue' ||
731: $env{'form.queue'} eq 'none' ) {
1.33 albertel 732: &Apache::lonxml::debug("moving back.");
1.49 albertel 733: &move_between_queues($env{'form.queue'},'gradingqueue');
1.33 albertel 734: } else {
735: &check_queue_unlock($env{'form.queue'});
736: }
1.20 albertel 737: } elsif ($mandatory_failed) {
1.25 albertel 738: $Apache::lonhomework::results{"resource.$version.status"}='fail';
739: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
740: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
741: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39 albertel 742: &remove_from_queue($env{'form.queue'});
743:
744: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 745:
746: if ($env{'form.regrade'} ne 'yes') {
747: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
748: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
749: &Apache::grades::version_portfiles(
750: \%Apache::lonhomework::results,
751: ["$version.0.bridgetask"],$courseid,
752: $symb,$udom,$uname,
753: ["$version.0.bridgetask"]);
754: }
1.20 albertel 755: } else {
1.25 albertel 756: $Apache::lonhomework::results{"resource.$version.status"}='pass';
757: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
758: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
759: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 760: &remove_from_queue($env{'form.queue'});
1.39 albertel 761:
762: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 763: if ($env{'form.regrade'} ne 'yes') {
764: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
765: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
766: &Apache::grades::version_portfiles(
767: \%Apache::lonhomework::results,
768: ["$version.0.bridgetask"],$courseid,
769: $symb,$udom,$uname,
770: ["$version.0.bridgetask"]);
771: }
1.20 albertel 772: }
1.26 albertel 773: $Apache::lonhomework::results{"resource.status"}=
774: $Apache::lonhomework::results{"resource.$version.status"};
1.28 albertel 775: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 776: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 777: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 778: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 779: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 780: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 781: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 782: }
1.21 albertel 783: &Apache::structuretags::finalize_storage();
1.20 albertel 784: }
1.15 albertel 785: } elsif ($target eq 'webgrade') {
1.18 albertel 786: $result.="</table>\n<hr />";
1.20 albertel 787: #$result.='<input type="submit" name="next" value="'.
788: # &mt('Save & Next').'" /> ';
789: #$result.='<input type="submit" name="end" value="'.
790: # &mt('Save & Stop Grading').'" /> ';
791: #$result.='<input type="submit" name="throwaway" value="'.
792: # &mt('Throw Away & Stop Grading').'" /> ';
793: #$result.='<input type="submit" name="save" value="'.
794: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 795: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 796: } elsif ($target eq 'meta') {
1.2 albertel 797: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 798: #$result.=&Apache::response::meta_part_order();
799: #$result.=&Apache::response::meta_response_order();
800: }
1.4 albertel 801: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 802: return $result;
803: }
804:
1.31 albertel 805: sub move_between_queues {
806: my ($src_queue,$dest_queue)=@_;
1.49 albertel 807: my $cur_data;
808: if ($src_queue ne 'none') {
809: $cur_data=&get_queue_data($src_queue);
810: if (!$cur_data) { return 'not_exist'; }
811: } else {
812: $cur_data = ['none'];
813: }
1.31 albertel 814: my $result=&add_to_queue($dest_queue,$cur_data->[0]);
815: if ($result ne 'ok') {
816: return $result;
817: }
818: &check_queue_unlock($src_queue);
819: return &remove_from_queue($src_queue);
1.21 albertel 820: }
821:
822: sub check_queue_unlock {
1.32 albertel 823: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 824: if ($queue eq 'none') { return 'ok'; }
1.30 albertel 825: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 826: if (!defined($key)) {
827: $key="$symb\0queue\0$uname\@$udom";
828: }
1.30 albertel 829: my $cnum=$env{'course.'.$cid.'.num'};
830: my $cdom=$env{'course.'.$cid.'.domain'};
831: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
832: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
833: if ($who eq $me) {
1.32 albertel 834: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
835: } elsif ($allow_not_me) {
1.33 albertel 836: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 837: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 838: }
1.32 albertel 839: return 'not_owner';
1.21 albertel 840: }
841:
842: sub remove_from_queue {
1.30 albertel 843: my ($queue)=@_;
1.49 albertel 844: if ($queue eq 'none') { return 'ok'; }
1.27 albertel 845: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
846: my $cnum=$env{'course.'.$cid.'.num'};
847: my $cdom=$env{'course.'.$cid.'.domain'};
848: my $key="$symb\0queue\0$uname\@$udom";
849: my @keys=($key,"$key\0locked");
1.31 albertel 850: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 851: }
852:
1.16 albertel 853: sub setup_env_for_other_user {
854: my ($queue_key,$safeeval)=@_;
855: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 856: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 857: $env{'form.grade_symb'}=$symb;
858: $env{'form.grade_domain'}=$udom;
859: $env{'form.grade_username'}=$uname;
860: $env{'form.grade_courseid'}=$env{'request.course.id'};
861: &Apache::lonxml::initialize_rndseed($safeeval);
862: }
863:
1.31 albertel 864: sub get_queue_data {
865: my ($queue)=@_;
866: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
867: my $cnum=$env{'course.'.$cid.'.num'};
868: my $cdom=$env{'course.'.$cid.'.domain'};
869: my $todo="$symb\0queue\0$uname\@$udom";
870: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
871: if ($key eq $todo && ref($value)) {
872: return $value;
873: }
874: return undef;
875: }
876:
1.49 albertel 877: sub check_queue_for_key {
878: my ($cid,$queue,$todo)=@_;
879: my $cnum=$env{'course.'.$cid.'.num'};
880: my $cdom=$env{'course.'.$cid.'.domain'};
881: my %results=
882: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
883:
884: if (exists($results{$todo}) && ref($results{$todo})) {
885: if (defined($results{"$todo\0locked"})) {
886: return 'locked';
887: }
1.58 albertel 888: my $slot=$results{$todo}->[0];
889: my %slot_data=&Apache::lonnet::get_slot($slot);
890: if ($slot_data{'endtime'} > time) {
891: return 'in_progress';
892: }
1.49 albertel 893: return 'enqueued';
894: }
895: return undef;
896: }
897:
1.14 albertel 898: sub add_to_queue {
1.31 albertel 899: my ($queue,$slot_name)=@_;
1.49 albertel 900: if ($queue eq 'none') { return 'ok'; }
1.14 albertel 901: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
902: my $cnum=$env{'course.'.$cid.'.num'};
903: my $cdom=$env{'course.'.$cid.'.domain'};
904: my %data;
1.31 albertel 905: $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
906: return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14 albertel 907: }
908:
909: sub show_queue {
1.32 albertel 910: my ($queue,$with_selects)=@_;
1.14 albertel 911: my $result;
912: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
913: my $cnum=$env{'course.'.$cid.'.num'};
914: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 915:
916: my @chosen_sections=
917: &Apache::loncommon::get_env_multiple('form.chosensections');
918: &Apache::grades::init_perm();
919: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
920: &Apache::grades::reset_perm();
921:
1.16 albertel 922: my $regexp="^$symb\0";
1.30 albertel 923: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 924: my ($tmp)=%queue;
925: if ($tmp=~/^error: 2 /) {
1.33 albertel 926: return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31 albertel 927: }
1.33 albertel 928: $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32 albertel 929: if ($with_selects) { $result.="<th></th>"; }
930: $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 931: foreach my $key (sort(keys(%queue))) {
1.59 albertel 932: my ($symb,$uname,$udom) = &decode_queue_key($key);
933: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.32 albertel 934: if ($key=~/locked$/ && !$with_selects) {
1.16 albertel 935: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 936: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 937: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32 albertel 938: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.16 albertel 939: my ($symb,undef) = split("\0",$key);
940: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 941: $result.="<tr><td>$title</td><td></td>";
1.16 albertel 942: $result.='<td>last queue modification time</td><td>'.
943: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 944: } elsif ($key!~/(timestamp|locked)$/) {
1.16 albertel 945: my $title=&Apache::lonnet::gettitle($symb);
1.32 albertel 946: $result.="<tr>";
1.35 albertel 947: my $slot=$queue{$key}->[0];
948: my %slot_data=&Apache::lonnet::get_slot($slot);
1.32 albertel 949: if ($with_selects) {
950: my $ekey=&Apache::lonnet::escape($key);
951: my ($action,$description)=('select',&mt('Select'));
952: if (exists($queue{"$key\0locked"})) {
953: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
954: if ($me eq $queue{"$key\0locked"}) {
955: ($action,$description)=('resume',&mt('Resume'));
956: } else {
957: ($action,$description)=('unlock',&mt('Unlock'));
958: }
959: }
1.35 albertel 960: if (time > $slot_data{'endtime'}) {
961: $result.=(<<FORM);
1.32 albertel 962: <td>
963: <form method="POST">
964: <input type="hidden" name="gradingkey" value="$ekey" />
965: <input type="hidden" name="queue" value="$queue" />
966: <input type="hidden" name="gradingaction" value="$action" />
967: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 968: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 969: <input type="submit" name="submit" value="$description" />
970: </form>
971: </td>
972: FORM
1.35 albertel 973:
974: } else {
975: $result.='<td>'.&mt("In Progress").'</td>'
976: }
1.32 albertel 977: }
978: $result.="<td>$title</td><td>$uname</td>";
1.27 albertel 979: $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20 albertel 980: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
981: "</td></tr>";
1.16 albertel 982: }
1.14 albertel 983: }
1.15 albertel 984: $result.="</table><hr />\n";
1.14 albertel 985: return $result;
986: }
987:
1.34 albertel 988: sub get_queue_counts {
989: my ($queue)=@_;
990: my $result;
991: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
992: my $cnum=$env{'course.'.$cid.'.num'};
993: my $cdom=$env{'course.'.$cid.'.domain'};
994: my $regexp="^$symb\0";
995: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
996: my ($tmp)=%queue;
997: if ($tmp=~/^error: 2 /) {
998: return (0,0,0);
999: }
1000: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1001: foreach my $key (sort(keys(%queue))) {
1002: if ($key=~/locked$/) {
1003: $locks++;
1004: } elsif ($key=~/timestamp$/) {
1005: #ignore
1006: } elsif ($key!~/(timestamp|locked)$/) {
1007: my ($symb,$uname,$udom) = &decode_queue_key($key);
1008: $entries++;
1009: my $slot=$queue{$key}->[0];
1010: my %slot_data=&Apache::lonnet::get_slot($slot);
1011: if (time > $slot_data{'endtime'}) {
1012: $ready_to_grade++;
1013: }
1014: }
1015: }
1016: return ($entries,$ready_to_grade,$locks);
1017: }
1018:
1.49 albertel 1019: sub encode_queue_key {
1020: my ($symb,$udom,$uname)=@_;
1021: return "$symb\0queue\0$uname\@$udom";
1022: }
1023:
1.14 albertel 1024: sub decode_queue_key {
1025: my ($key)=@_;
1026: my ($symb,undef,$user) = split("\0",$key);
1027: my ($uname,$udom) = split('@',$user);
1028: return ($symb,$uname,$udom);
1029: }
1030:
1031: sub queue_key_locked {
1.30 albertel 1032: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1033: if (!defined($cdom) || !defined($cnum)) {
1034: my (undef,$cid)=&Apache::lonxml::whichuser();
1035: $cnum=$env{'course.'.$cid.'.num'};
1036: $cdom=$env{'course.'.$cid.'.domain'};
1037: }
1.14 albertel 1038: my ($key_locked,$value)=
1.30 albertel 1039: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1040: if ($key_locked eq "$key\0locked") {
1041: return $value;
1042: }
1043: return undef;
1044: }
1045:
1046: sub pick_from_queue_data {
1.30 albertel 1047: my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
1048: foreach my $key (keys(%$queuedata)) {
1.14 albertel 1049: my ($symb,$uname,$udom)=&decode_queue_key($key);
1050: if ($check_section) {
1051: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 1052: if ($section eq $check_section) {
1.33 albertel 1053: &Apache::lonxml::debug("my sec");
1.15 albertel 1054: next;
1055: }
1.14 albertel 1056: }
1.30 albertel 1057: my $slot=$queuedata->{$key}[0];
1.14 albertel 1058: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 1059: if ($slot_data{'endtime'} > time) {
1.33 albertel 1060: &Apache::lonxml::debug("not time");
1.15 albertel 1061: next;
1062: }
1.30 albertel 1063: if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33 albertel 1064: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1065: next;
1066: }
1.14 albertel 1067: return $key;
1068: }
1069: return undef;
1070: }
1071:
1.15 albertel 1072: sub find_mid_grade {
1.30 albertel 1073: my ($queue,$symb,$cdom,$cnum)=@_;
1.16 albertel 1074: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 1075: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
1076: if ($todo) {
1.30 albertel 1077: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1078: if ($who eq $me) { return $todo; }
1079: }
1080: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1081: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1082: foreach my $key (keys(%locks)) {
1083: my $who=$locks{$key};
1084: if ($who eq $me) {
1085: $todo=$key;
1086: $todo=~s/\0locked$//;
1087: return $todo;
1088: }
1089: }
1090: return undef;
1091: }
1092:
1.32 albertel 1093: sub lock_key {
1094: my ($queue,$todo)=@_;
1095: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
1096: my (undef,$cid)=&Apache::lonxml::whichuser();
1097: my $cnum=$env{'course.'.$cid.'.num'};
1098: my $cdom=$env{'course.'.$cid.'.domain'};
1099: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1100: $cdom,$cnum);
1.33 albertel 1101: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1102: if ($success eq 'ok') {
1103: return 1;
1104: }
1105: return 0;
1106: }
1107:
1.14 albertel 1108: sub get_from_queue {
1.30 albertel 1109: my ($queue)=@_;
1.14 albertel 1110: my $result;
1111: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1112: my $cnum=$env{'course.'.$cid.'.num'};
1113: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1114: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1115: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1116: if ($todo) { return $todo; }
1.14 albertel 1117: while (1) {
1118: my $starttime=time;
1.30 albertel 1119: &Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14 albertel 1120: $cdom,$cnum);
1.33 albertel 1121: &Apache::lonxml::debug("$starttime");
1.14 albertel 1122: my $regexp="^$symb\0queue\0";
1.30 albertel 1123: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1124: #make a pass looking for a user _not_ in my section
1.14 albertel 1125: if ($env{'request.course.sec'}) {
1.33 albertel 1126: &Apache::lonxml::debug("sce");
1.30 albertel 1127: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1128: \%queue,$cdom,$cnum);
1.33 albertel 1129: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1130: }
1.33 albertel 1131: # no one _not_ in our section so look for any user that is
1132: # ready for grading
1.14 albertel 1133: if (!$todo) {
1.33 albertel 1134: &Apache::lonxml::debug("no sce");
1.31 albertel 1135: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1136: \%queue,$cdom,$cnum);
1.33 albertel 1137: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1138: }
1139: # no user to grade
1140: if (!$todo) { last; }
1.33 albertel 1141: &Apache::lonxml::debug("got $todo");
1.14 albertel 1142: # otherwise found someone so lets try to lock them
1.32 albertel 1143: # unless someone else already picked them
1144: if (!&lock_key($queue,$todo)) { next; }
1.14 albertel 1145: my (undef,$endtime)=
1.30 albertel 1146: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 1147: $cdom,$cnum);
1.33 albertel 1148: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 1149: # someone else already modified the queue,
1150: # perhaps our picked user wass already fully graded between
1151: # when we picked him and when we locked his record? so lets
1152: # double check.
1153: if ($endtime != $starttime) {
1154: my ($key,$value)=
1.30 albertel 1155: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 1156: $cdom,$cnum);
1.33 albertel 1157: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 1158: if ($key eq $todo && ref($value)) {
1159: } else {
1.30 albertel 1160: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 1161: $cdom,$cnum);
1.33 albertel 1162: &Apache::lonxml::debug("del");
1.14 albertel 1163: next;
1164: }
1165: }
1.33 albertel 1166: &Apache::lonxml::debug("last $todo");
1.14 albertel 1167: last;
1168: }
1169: return $todo;
1170: }
1171:
1.49 albertel 1172: sub select_user {
1173: my ($symb,$cid)=&Apache::lonxml::whichuser();
1174: my $result.='<table border="1">';
1175:
1.59 albertel 1176: my @chosen_sections=
1177: &Apache::loncommon::get_env_multiple('form.chosensections');
1.49 albertel 1178: &Apache::grades::init_perm();
1.59 albertel 1179: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1.49 albertel 1180: &Apache::grades::reset_perm();
1181:
1182: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1183: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 1184:
1.49 albertel 1185: my %status = &get_student_status($symb,$cid,$udom,$uname);
1186: my $queue = 'none';
1.58 albertel 1187: my $cannot_grade;
1188: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1189: $queue = 'reviewqueue';
1.58 albertel 1190: if ($status{'reviewqueue'} eq 'in_progress') {
1191: $cannot_grade=1;
1192: }
1193: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1194: $queue = 'gradingqueue';
1.58 albertel 1195: if ($status{'gradingqueue'} eq 'in_progress') {
1196: $cannot_grade=1;
1197: }
1.49 albertel 1198: }
1199: my $todo =
1200: &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 1201: if ($cannot_grade) {
1202: $result.='<tr><td> </td><td>'.$fullname->{$student}.
1203: '</td><td>';
1204: } else {
1205: $result.=<<RESULT;
1.49 albertel 1206: <tr>
1207: <td>
1208: <form method="POST">
1209: <input type="hidden" name="gradingkey" value="$todo" />
1210: <input type="hidden" name="queue" value="$queue" />
1211: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 1212: <input type="hidden" name="regrade" value="yes" />
1.49 albertel 1213: <input type="submit" name="submit" value="Regrade" />
1214: </form>
1215: <td>$fullname->{$student}</td>
1216: <td>
1217: RESULT
1.58 albertel 1218: }
1.49 albertel 1219: if ($status{'status'} eq 'pass') {
1220: $result .= '<font color="green">'.&mt('Passed').'</font>';
1221: } elsif ($status{'status'} eq 'fail') {
1222: $result .= '<font color="red">'.&mt('Failed').'</font>';
1223: } elsif ($status{'status'} eq 'review') {
1224: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1225: } elsif ($status{'status'} eq 'ungraded') {
1226: $result .= &mt('Ungraded');
1227: } elsif ($status{'status'} ne '') {
1228: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1229: } else {
1230: $result.=" ";
1231: }
1232: if ($status{'version'}) {
1233: $result .= ' '.&mt('Version').' '.$status{'version'};
1234: }
1235: $result.= '</td><td>';
1236: if ($status{'reviewqueue'} eq 'enqueued') {
1237: $result .= &mt('Awaiting Review');
1238: } elsif ($status{'reviewqueue'} eq 'locked') {
1239: $result .= &mt('Under Review');
1.58 albertel 1240: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1241: $result .= &mt('Still being worked on.');
1.49 albertel 1242: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1243: $result .= &mt('Awaiting Grading');
1244: } elsif ($status{'gradingqueue'} eq 'locked') {
1245: $result .= &mt('Being Graded');
1.58 albertel 1246: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1247: $result .= &mt('Still being worked on.');
1.49 albertel 1248: } else {
1249: $result.=" ";
1250: }
1251: $result.= '</td></tr>';
1252: }
1253: $result.='</table>';
1254: return $result;
1255: }
1256:
1257: sub get_student_status {
1258: my ($symb,$cid,$udom,$uname)=@_;
1259: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1260: $udom,$uname);
1261: my %status;
1262: $status{'status'}=$record{'resource.status'};
1263: $status{'version'}=$record{'resource.version'};
1264: $status{'grader'}=$record{'resource.grader'};
1265: $status{'reviewqueue'}=&check_queue_for_key($cid,'reviewqueue',
1266: &encode_queue_key($symb,$udom,$uname));
1267: $status{'gradingqueue'}=&check_queue_for_key($cid,'gradingqueue',
1268: &encode_queue_key($symb,$udom,$uname));
1269: return %status;
1270: }
1271:
1.1 albertel 1272: sub start_ClosingParagraph {
1273: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1274: my $result;
1275: if ($target eq 'web') {
1.13 albertel 1276: } elsif ($target eq 'webgrade') {
1277: &Apache::lonxml::startredirection();
1.1 albertel 1278: }
1279: return $result;
1280: }
1281:
1282: sub end_ClosingParagraph {
1283: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1284: my $result;
1285: if ($target eq 'web') {
1.13 albertel 1286: } elsif ($target eq 'webgrade') {
1287: &Apache::lonxml::endredirection();
1.1 albertel 1288: }
1289: return $result;
1290: }
1291:
1.19 albertel 1292: sub get_id {
1293: my ($parstack,$safeeval)=@_;
1294: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1295: if (!$id) { $id=$Apache::lonxml::curdepth; }
1296: return $id;
1297: }
1298:
1.1 albertel 1299: my %dimension;
1300: sub start_Dimension {
1301: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1302: undef(%dimension);
1.19 albertel 1303: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 1304: $Apache::bridgetask::dimension=$dim_id;
1305: push(@Apache::bridgetask::dimensionlist,$dim_id);
1306: undef(@Apache::bridgetask::instance);
1.20 albertel 1307: $Apache::bridgetask::dimensionmandatory{$dim_id}=
1308: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.54 albertel 1309: &Apache::lonxml::startredirection();
1310: return &internal_location($dim_id);
1.1 albertel 1311: }
1312:
1.13 albertel 1313: sub get_instance {
1314: &Apache::response::pushrandomnumber();
1315: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29 albertel 1316: my $num=@order;
1317: my $version=&get_version();
1318: my $which=($version-1)%$num;
1319: return $order[$which];
1.13 albertel 1320: }
1321:
1.18 albertel 1322: {
1323: my $last_link;
1324: sub end_Dimension {
1325: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54 albertel 1326: my $result=&Apache::lonxml::endredirection();
1.25 albertel 1327: my $dim=&get_id($parstack,$safeeval);
1.19 albertel 1328: my $instance=&get_instance();
1.25 albertel 1329: my $version=&get_version();
1.18 albertel 1330: if ($target eq 'web') {
1.47 albertel 1331: @Apache::scripttag::parser_env = @_;
1332: $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1333: @Apache::scripttag::parser_env = @_;
1334: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.26 albertel 1335: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
1336: $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.54 albertel 1337:
1338: my $dim_status=$Apache::lonhomework::history{"resource.$version.$dim.status"};
1339: my $mandatory='Mandatory';
1340: if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
1341: $mandatory='Optional';
1342: }
1343: my $dim_info="<div class='$dim_status'>\n";
1344: if ($dim_status eq 'pass') {
1345: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1346: }
1347: if ($dim_status eq 'fail') {
1348: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1349: }
1350: my $man_count=0;
1351: my $opt_count=0;
1352: my $opt_passed=0;
1353: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1354: if ($dimension{$instance.'.criteria.'.$id.'.mandatory'}
1355: eq 'N') {
1356: $opt_count++;
1357: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
1358: $opt_passed++;
1359: }
1360: } else {
1361: $man_count++;
1362: }
1363: }
1364: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
1365: $parstack,$safeeval);
1366: if ($opt_req !~ /\S/) { $opt_req='0'; }
1367: $dim_info.="\n<p>".&mt('You passed all of the mandatory components and [_1] of the [_2] optional components, of which you were required to pass [_3].',$opt_passed,$opt_count,$opt_req)."</p>\n</div>";
1368:
1369: my $internal_location=&internal_location($dim);
1370: $result=~s/\Q$internal_location\E/$dim_info/;
1371:
1.22 albertel 1372: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1373: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1374: my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.53 albertel 1375: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1376: if ($mandatory) {
1377: $mandatory='Mandatory';
1378: } else {
1379: $mandatory='Optional';
1380: }
1.22 albertel 1381: if ($status eq 'fail') {
1382: } elsif ($status eq 'pass') {
1383: } else {
1.49 albertel 1384: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
1.22 albertel 1385: }
1.53 albertel 1386: my $status_display=$status;
1387: $status_display=~s/^([a-z])/uc($1)/e;
1.54 albertel 1388: @Apache::scripttag::parser_env = @_;
1.53 albertel 1389: $result.='<div class="'.$status.'"><h4>'.$mandatory.
1.54 albertel 1390: ' Criteria</h4><p>';
1391: @Apache::scripttag::parser_env = @_;
1392: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
1393: $result.='</p><p class="grade">'.$status_display.'</p>';
1.25 albertel 1394: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
1.53 albertel 1395: $result.='<p class="comment">'.$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</p>';
1.22 albertel 1396: }
1.53 albertel 1397: $result.='</div>';
1.22 albertel 1398: }
1399: }
1.18 albertel 1400: } elsif ($target eq 'webgrade') {
1.47 albertel 1401: # in case of any side effects that we need
1402: @Apache::scripttag::parser_env = @_;
1403: &Apache::scripttag::xmlparse($dimension{'intro'});
1404: @Apache::scripttag::parser_env = @_;
1405: &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.18 albertel 1406: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1407: my $link='criteria_'.$instance.'_'.$id;
1.25 albertel 1408: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19 albertel 1409: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 1410: '<a name="'.$link.'" />'.
1411: '<a name="next_'.$last_link.'" />'.
1.47 albertel 1412: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">';
1413: @Apache::scripttag::parser_env = @_;
1414: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
1415: $result.='</textarea>'.
1.18 albertel 1416: #$dimension{$instance.'.criteria.'.$id}.
1417: '</td>'.
1.19 albertel 1418: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25 albertel 1419: '<textarea style="width:100%" rows="8" width="25" wrap="hard" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}).'</textarea>'.
1.18 albertel 1420: '</td>'.
1421: '<td>'.
1.47 albertel 1422: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label></nobr><br />'.
1.30 albertel 1423: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
1424: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
1425: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18 albertel 1426: '</td>'.
1427: '<td>'.
1428: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 1429: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
1430: '<input type="submit" name="next" value="'.
1431: &mt('Done').'" /> '.
1.30 albertel 1432: '<input type="submit" name="stop" value="'.
1433: &mt('Stop').'" /> '.
1.18 albertel 1434: '</td></tr>';
1.22 albertel 1435: $result.='<tr><td colspan="4">';
1436: my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
1.52 albertel 1437: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.43 albertel 1438: foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"})) {
1.22 albertel 1439: my $file=$file_url.$partial_file;
1.52 albertel 1440: $file=~s|/+|/|g;
1.22 albertel 1441: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.48 albertel 1442: $result.='<nobr><a href="'.$file.'" target="lonGRDs"><img src="'.
1.22 albertel 1443: &Apache::loncommon::icon($file).'" border=0"> '.$file.
1.48 albertel 1444: '</a></nobr> ';
1.22 albertel 1445: }
1446: $result.='</td></tr>';
1.18 albertel 1447: $last_link=$link;
1448: }
1.22 albertel 1449: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 1450: my $optional_passed=0;
1.20 albertel 1451: my $mandatory_failed=0;
1452: my $ungraded=0;
1453: my $review=0;
1.19 albertel 1454: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1455: my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
1456: $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 1457: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1458: if ($status eq 'pass') {
1459: if (!$mandatory) { $optional_passed++; }
1460: } elsif ($status eq 'fail') {
1461: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 1462: } elsif ($status eq 'review') {
1463: $review++;
1.20 albertel 1464: } elsif ($status eq 'ungraded') {
1465: $ungraded++;
1.21 albertel 1466: } else {
1.47 albertel 1467: $ungraded++;
1.19 albertel 1468: }
1469: }
1.20 albertel 1470: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
1471: $mandatory_failed++;
1472: }
1.21 albertel 1473: &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 1474: if ($review) {
1.25 albertel 1475: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1476: 'review';
1.20 albertel 1477: } elsif ($ungraded) {
1.25 albertel 1478: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1479: 'ungraded';
1.20 albertel 1480: } elsif ($mandatory_failed) {
1.25 albertel 1481: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1482: 'fail';
1.20 albertel 1483: } else {
1.25 albertel 1484: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1485: 'pass';
1.20 albertel 1486: }
1.13 albertel 1487: }
1.18 albertel 1488: return $result;
1.1 albertel 1489: }
1490: }
1491:
1492: sub start_IntroParagraph {
1493: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1494: my $result;
1.13 albertel 1495: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1496: if ($tagstack->[-2] eq 'Dimension') {
1497: $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser);
1498:
1499: } elsif ($target eq 'webgrade') {
1500: &Apache::lonxml::get_all_text('/introparagraph',$parser);
1.1 albertel 1501: }
1.47 albertel 1502:
1.1 albertel 1503: }
1504: return $result;
1505: }
1506:
1507: sub end_IntroParagraph {
1508: }
1509:
1510: sub start_Instance {
1511: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 1512: my $id=&get_id($parstack,$safeeval);
1513: push(@{$dimension{'instances'}},$id);
1514: push(@Apache::bridgetask::instance,$id);
1515: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 1516: $dimension{$id.'.optionalrequired'}=
1.19 albertel 1517: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 1518: return '';
1519: }
1520:
1521: sub end_Instance {
1522: }
1523:
1524: sub start_InstanceText {
1525: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 albertel 1526: my $instance_id=$Apache::bridgetask::instance[-1];
1527: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser);
1.13 albertel 1528: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1529: $dimension{$instance_id.'.text'}=$text;
1.1 albertel 1530: }
1531: return '';
1532: }
1533:
1534: sub end_InstanceText {
1535: return '';
1536: }
1537:
1538: sub start_Criteria {
1539: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1540: my $instance_id=$Apache::bridgetask::instance[-1];
1.47 albertel 1541: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser);
1.21 albertel 1542: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19 albertel 1543: my $id=&get_id($parstack,$safeeval);
1.1 albertel 1544: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 1545: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
1546: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 1547: push(@{$dimension{$instance_id.'.criterias'}},$id);
1548: }
1549: return '';
1550: }
1551:
1.47 albertel 1552: sub end_Criteria {
1553: }
1554:
1.4 albertel 1555: sub proctor_validation_screen {
1556: my ($slot) = @_;
1557: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 1558: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 1559: my $name=&Apache::loncommon::plainname($user,$domain);
1560:
1.4 albertel 1561: my $msg;
1.11 albertel 1562: if ($env{'form.proctorpassword'}) {
1.4 albertel 1563: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
1564: .'</font></p>';
1565: }
1.47 albertel 1566: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 1567: my $result= (<<ENDCHECKOUT);
1568: <h2>Proctor Validation</h2>
1569: <p>Your room's proctor needs to validate your access to this resource.</p>
1570: $msg
1.11 albertel 1571: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 1572: <input type="hidden" name="validate" value="yes" />
1573: <input type="hidden" name="submitted" value="yes" />
1574: <table>
1.44 albertel 1575: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 1576: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 1577: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 1578: </table>
1579: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 1580: <table border="1">
1581: <tr><td>
1582: <table>
1583: <tr><td colspan="2">Student who should be logged in is:</td></tr>
1584: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 1585: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.44 albertel 1586: <tr><td>Usename</td><td>$user\@$domain</td></tr>
1587: <tr><td colspan="2"><img src="$url" /></td></tr>
1588: </table>
1589: </tr></td>
1590: </table>
1.4 albertel 1591: </form>
1592: ENDCHECKOUT
1593: return $result;
1594: }
1595:
1.1 albertel 1596: 1;
1597: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>