Annotation of loncom/homework/bridgetask.pm, revision 1.34
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.34 ! albertel 4: # $Id: bridgetask.pm,v 1.33 2005/05/27 21:13:46 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'}=
1.27 albertel 74: ++$Apache::lonhomework::history{'resource.version'};
1.23 albertel 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.28 albertel 79: foreach my $key (keys(%Apache::lonhomework::history)) {
80: if ($key=~/^resource\.0\./) {
81: $Apache::lonhomework::results{$key}='';
82: }
83: }
1.4 albertel 84: return 1;
85: }
86: }
87: }
88: return 0;
89: }
90:
1.25 albertel 91: sub get_version {
1.29 albertel 92: my ($version,$previous);
1.25 albertel 93: if ($env{'form.previousversion'} &&
94: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
1.29 albertel 95: $version=$env{'form.previousversion'};
96: $previous=1;
97: } else {
98: $version=$Apache::lonhomework::history{'resource.version'};
99: $previous=0;
100: }
101: if (wantarray) {
102: return ($version,$previous);
1.25 albertel 103: }
1.29 albertel 104: return $version;
1.25 albertel 105: }
106:
1.8 albertel 107: sub add_previous_version_button {
1.25 albertel 108: my ($status)=@_;
1.8 albertel 109: my $result;
1.29 albertel 110: if ($Apache::lonhomework::history{'resource.version'} eq '') {
1.25 albertel 111: return '';
112: }
1.29 albertel 113: if ($Apache::lonhomework::history{'resource.version'} < 2 &&
114: $status ne 'NEEDS_CHECKIN') {
1.25 albertel 115: return '';
116: }
1.29 albertel 117: my $version=&get_version();
118: if ($env{'form.previousversion'} ne '' &&
119: $env{'form.previousversion'} eq $version) {
120: $result.="<h3>".&mt("Showing previous version [_1]",$version).
121: "</h3>\n";
122: }
123: my @to_show;
124: foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
125: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
126: push(@to_show,$test_version);
127: }
128: }
129: my $list='<option>'.
130: join("</option>\n<option>",@to_show).
131: "</option>\n";
132: $result.='<form name="getprevious" method="POST" action="';
133: my $uri=$env{'request.uri'};
134: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
135: $result.=$uri.'">'.
136: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
137: <option>'.&mt('Pick one').'</option>
138: '.$list.'
139: </select>')."</form>";
1.8 albertel 140: return $result;
141: }
142:
1.13 albertel 143: sub add_grading_button {
1.29 albertel 144: my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13 albertel 145: &mt("Get a submission to grade").'" />';
146: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.32 albertel 147: if ( 1) {
148: #need a permissions for limitng this to 'powerful users'
1.34 ! albertel 149:
! 150: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
! 151: $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);
! 152:
! 153: $result.=' <input type="submit" name="reviewagrading" value="'.
! 154: &mt("Select an entry from the grading queue").'" /> </p>'."\n";
! 155:
! 156: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
! 157: $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 158: $result.=' <input type="submit" name="reviewasubmission" value="'.
1.34 ! albertel 159: &mt("Select an entry from the review queue").'" /> </p>'."\n";
1.32 albertel 160: }
1.13 albertel 161: return $result;
162: }
163:
1.22 albertel 164: sub add_request_another_attempt_button {
1.25 albertel 165: my $result;
166: $result.=' <input type="submit" name="requestattempt" value="'.
167: &mt("Request another attempt").'" />';
168: return $result;
1.22 albertel 169: }
170:
1.30 albertel 171: sub preserve_grade_info {
172: my $result;
173: # if we are viewing someone else preserve that info
174: if (defined $env{'form.grade_symb'}) {
175: foreach my $field ('symb','courseid','domain','username') {
176: $result .= '<input type="hidden" name="grade_'.$field.
177: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
178: }
179: }
180: return $result;
181: }
182:
1.1 albertel 183: sub start_Task {
184: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
185:
1.4 albertel 186: my ($status,$accessmsg,$slot);
1.16 albertel 187: if ($target ne 'webgrade') {
188: &Apache::structuretags::initialize_storage();
189: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
190: }
191:
1.4 albertel 192: $Apache::lonhomework::parsing_a_task=1;
1.1 albertel 193: #should get back a <html> or the neccesary stuff to start XML/MathML
194: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
195: &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16 albertel 196:
1.8 albertel 197: if ($target eq 'web') {
1.13 albertel 198: if ($Apache::lonhomework::modifygrades) {
199: $body_tag_start.='<form name="gradesubmission" method="POST" action="';
200: my $uri=$env{'request.uri'};
201: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
202: $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
203: }
1.8 albertel 204: }
1.21 albertel 205: if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1 albertel 206: $target eq 'tex') {
1.29 albertel 207: my ($version,$previous)=&get_version();
1.14 albertel 208: ($status,$accessmsg,my $slot_name,$slot) =
1.4 albertel 209: &Apache::lonhomework::check_task_access('0');
1.9 albertel 210: push(@Apache::inputtags::status,$status);
1.14 albertel 211: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 212: my $expression='$external::datestatus="'.$status.'";';
1.23 albertel 213: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1 albertel 214: &Apache::run::run($expression,$safeeval);
215: &Apache::lonxml::debug("Got $status");
1.25 albertel 216: $body_tag_start.=&add_previous_version_button($status);
1.29 albertel 217: if (!$previous && (
218: ( $status eq 'CLOSED' ) ||
219: ( $status eq 'BANNED') ||
220: ( $status eq 'UNAVAILABLE') ||
221: ( $status eq 'NOT_IN_A_SLOT') ||
222: ( $status eq 'NEEDS_CHECKIN') ||
223: ( $status eq 'WAITING_FOR_GRADE') ||
224: ( $status eq 'INVALID_ACCESS') )) {
1.1 albertel 225: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
226: if ( $target eq "web" ) {
1.4 albertel 227: $result.= $head_tag_start.'</head>'.$body_tag_start;
228: my $msg;
1.1 albertel 229: if ($status eq 'UNAVAILABLE') {
230: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 231: } elsif ($status eq 'NOT_IN_A_SLOT') {
232: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4 albertel 233: } elsif ($status eq 'NEEDS_CHECKIN') {
234: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
235: '</h1>'.&proctor_validation_screen($slot);
1.22 albertel 236: } elsif ($status eq 'WAITING_FOR_GRADE') {
237: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1 albertel 238: } elsif ($status ne 'NOT_YET_VIEWED') {
239: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
240: }
241: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
242: $msg.='The problem '.$accessmsg;
243: }
244: $result.=$msg.'<br />';
245: } elsif ($target eq 'tex') {
246: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
247: if ($status eq 'UNAVAILABLE') {
248: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
249: } else {
250: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
251: }
1.22 albertel 252: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 253: if ($status eq 'NEEDS_CHECKIN') {
1.22 albertel 254: if (&proctor_check_auth($slot_name,$slot)) {
1.4 albertel 255: #FIXME immeadiatly add this to the grading queue
256: # with slot->{'endtime'} for when grading can
257: # begin on this resource
1.22 albertel 258: # FIXME I think the above is done by default,
259: # need to check that
260: # failure doesn't do this.
1.4 albertel 261: }
262: }
1.1 albertel 263: }
264: } elsif ($target eq 'web') {
265: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
266: $result.="$head_tag_start<title>$name</title></head>
267: $body_tag_start \n $form_tag_start".
268: '<input type="hidden" name="submitted" value="yes" />';
1.30 albertel 269: $result.=&preserve_grade_info();
1.29 albertel 270: my ($version,$previous)=&get_version();
1.25 albertel 271: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 272: $result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.29 albertel 273: if (!$previous) {
274: $result.=&add_request_another_attempt_button();
275: }
1.22 albertel 276: }
1.25 albertel 277: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22 albertel 278: $result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
279: }
1.1 albertel 280: }
1.21 albertel 281: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
282: $target eq 'webgrade') {
1.32 albertel 283: my $webgrade='yes';
1.21 albertel 284: if ($target eq 'webgrade') {
1.32 albertel 285: $result.=$head_tag_start.$body_tag_start;
1.31 albertel 286: $result.='<br />Review'.&show_queue('reviewqueue');
1.33 albertel 287: $result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 288: }
1.33 albertel 289: # FIXME Blast! still need to reorg this, need to reshow the
290: # queue being reviewed once done with the grade pass...
291: # Hrrm, vaildation pass should perhaps say 'not_locked'
292: # perhaps do a search if there is a key that is mine and if
293: # there isn't reshow the queue....
294: my ($todo,$status_code)=&get_key_todo($target);
295:
296: &Apache::lonnet::logthis("got todo -$todo- stat -$status_code-");
297: if ($todo) {
298: &setup_env_for_other_user($todo,$safeeval);
299: my ($symb,$uname,$udom)=&decode_queue_key($todo);
300: $result.="\n".'<table><tr><td>Found '.
301: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
302: $form_tag_start.=
303: '<input type="hidden" name="gradingkey" value="'.
304: &Apache::lonnet::escape($todo).'" />';
305: $Apache::bridgetask::queue_key=$todo;
306: &Apache::structuretags::initialize_storage();
307: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
308: if ($target eq 'webgrade') {
309: $result.='<br />After -'.&show_queue($env{'form.queue'});
310: $result.="\n".'<table width="100%" style="width:100%" border="1">';
311: if ($status_code eq 'selected') {
312: $form_tag_start.=
313: '<input type="hidden" name="queuemode" value="selected" />';
314: }
315: }
1.15 albertel 316: } else {
1.33 albertel 317: if ($target eq 'webgrade') {
318: $result.="\n";
319: if ($status_code eq 'stop') {
320: $result.='<b>'.&mt("Stopped grading.").'</b>';
321: } elsif ($status_code eq 'lock_failed') {
322: $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
323: } elsif ($status_code eq 'unlock') {
324: $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
325: $result.=&show_queue($env{'form.queue'},1);
326: } elsif ($status_code eq 'show_list') {
327: $result.=&show_queue($env{'form.queue'},1);
328: } else {
329: $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32 albertel 330: }
1.21 albertel 331: }
1.33 albertel 332: $webgrade='no';
333: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32 albertel 334: }
335: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
336: $result.=$form_tag_start;
337: $result.='<input type="hidden" name="webgrade" value="'.
338: $webgrade.'" />';
339: $result.='<input type="hidden" name="queue" value="'.
340: $env{'form.queue'}.'" />';
1.15 albertel 341: }
1.1 albertel 342: } else {
343: # page_start returned a starting result, delete it if we don't need it
344: $result = '';
345: }
346: return $result;
347: }
348:
1.32 albertel 349: sub get_key_todo {
350: my ($target)=@_;
351: my $todo;
1.33 albertel 352:
353: if (defined($env{'form.reviewasubmission'})) {
354: &Apache::lonnet::logthis("review a submission....");
355: $env{'form.queue'}='reviewqueue';
356: return (undef,'show_list');
357: }
358:
359: if (defined($env{'form.reviewagrading'})) {
360: &Apache::lonxml::debug("review a grading....");
361: $env{'form.queue'}='gradingqueue';
362: return (undef,'show_list');
363: }
364:
1.32 albertel 365: my $queue=$env{'form.queue'};
1.33 albertel 366:
1.32 albertel 367: if (!defined($queue)) {
368: $env{'form.queue'}=$queue='gradingqueue';
369: }
1.33 albertel 370:
1.32 albertel 371: my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33 albertel 372:
1.32 albertel 373: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 albertel 374: && !defined($env{'form.gradingaction'})
375: && $env{'form.queuemode'} eq 'selected') {
376:
377: my $who=&queue_key_locked($queue,$gradingkey);
378: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
379: if ($who eq $me) {
380: &Apache::lonxml::debug("Found a key was given to me");
381: return ($gradingkey,'selected');
382: } else {
383: return (undef,'show_list');
384: }
385:
386: }
387:
388: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
389: if ($env{'form.gradingaction'} eq 'resume') {
390: delete($env{'form.gradingaction'});
391: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 392: return ($gradingkey);
1.33 albertel 393: } elsif ($env{'form.gradingaction'} eq 'unlock') {
394: &Apache::lonxml::debug("Unlocking a key ".
395: &check_queue_unlock($queue,$gradingkey,1));
396: return (undef,'unlock');
397: } elsif ($env{'form.gradingaction'} eq 'select') {
398: &Apache::lonxml::debug("Locking a key");
399: if (&lock_key($queue,$gradingkey)) {
400: &Apache::lonxml::debug("Success $queue");
401: return ($gradingkey);
402: }
403: &Apache::lonxml::debug("Failed $queue");
404: return (undef,'lock_failed');
1.32 albertel 405: }
406: }
1.33 albertel 407:
408: if ($env{'form.queuemode'} ne 'selected') {
409: # don't get something new from the queue if they hit the stop button
410: if (!($env{'form.stop'} && $target eq 'webgrade')
411: && !$env{'form.gradingaction'}) {
412: &Apache::lonxml::debug("Getting anew $queue");
413: return (&get_from_queue($queue));
414: } else {
415: return (undef,'stop');
416: }
1.32 albertel 417: }
1.33 albertel 418: return (undef,undef)
1.32 albertel 419: }
420:
1.1 albertel 421: sub end_Task {
422: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
423: my $result='';
424: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 425: my ($version,$previous)=&get_version();
1.1 albertel 426: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 427: $target eq 'tex') {
1.1 albertel 428: if (
1.11 albertel 429: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1 albertel 430: ($target eq 'answer') || ($target eq 'tex')
431: ) {
432: if ($target eq 'web') {
1.29 albertel 433: if ($status eq 'CAN_ANSWER' && !$previous) {
1.15 albertel 434: $result.="\n".'<table border="1">'.
1.28 albertel 435: &Apache::inputtags::file_selector("$version.0",
436: "bridgetask","*",
1.9 albertel 437: 'portfolioonly').
438: "</table>";
439: $result.=&Apache::inputtags::gradestatus('0');
440: }
1.13 albertel 441: }
442: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 443: $result.=&Apache::lonxml::xmlend().'</html>';
444: }
445: }
1.29 albertel 446: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 447: my $award='SUBMITTED';
1.28 albertel 448: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 449: 'portfiles',\$award);
1.14 albertel 450: if ($award eq 'SUBMITTED' &&
1.28 albertel 451: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
452: $Apache::lonhomework::results{"resource.0.tries"}=
453: $Apache::lonhomework::results{"resource.$version.0.tries"}=
454: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
455:
456: $Apache::lonhomework::results{"resource.0.award"}=
457: $Apache::lonhomework::results{"resource.$version.0.award"}=
458: $award;
1.10 albertel 459: }
1.4 albertel 460: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
461: &Apache::structuretags::finalize_storage();
1.14 albertel 462: if ($award eq 'SUBMITTED') {
1.31 albertel 463: &add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14 albertel 464: }
1.1 albertel 465: }
1.32 albertel 466: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20 albertel 467: my $optional_required=
468: &Apache::lonxml::get_param('OptionalRequired',$parstack,
469: $safeeval);
470: my $optional_passed=0;
471: my $mandatory_failed=0;
472: my $ungraded=0;
473: my $review=0;
1.21 albertel 474: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 475: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
476: my $status=
1.25 albertel 477: $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20 albertel 478: my $mandatory=
479: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
480: if ($status eq 'pass') {
481: if (!$mandatory) { $optional_passed++; }
482: } elsif ($status eq 'fail') {
483: if ($mandatory) { $mandatory_failed++; }
484: } elsif ($status eq 'ungraded') {
485: $ungraded++;
486: } elsif ($status eq 'review') {
487: $review++;
488: }
489: }
490: if ($optional_passed < $optional_required) {
491: $mandatory_failed++;
492: }
1.21 albertel 493: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
494: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 495: $env{'user.name'}.'@'.$env{'user.domain'};
496: if ($review) {
1.25 albertel 497: $Apache::lonhomework::results{"resource.$version.status"}='review';
1.33 albertel 498: if ($env{'form.queue'} eq 'reviewqueue') {
499: &check_queue_unlock($env{'form.queue'});
500: &Apache::lonxml::debug(" still needs review not changing status.");
501: } else {
502: &move_between_queues('gradingqueue','reviewqueue');
503: }
1.20 albertel 504: } elsif ($ungraded) {
1.25 albertel 505: $Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.32 albertel 506: # FIXME if in review queue need to move back to grading queue
1.33 albertel 507: if ($env{'form.queue'} eq 'reviewqueue') {
508: &Apache::lonxml::debug("moving back.");
509: &move_between_queues('reviewqueue','gradingqueue');
510: } else {
511: &check_queue_unlock($env{'form.queue'});
512: }
1.20 albertel 513: } elsif ($mandatory_failed) {
1.25 albertel 514: $Apache::lonhomework::results{"resource.$version.status"}='fail';
515: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
516: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
517: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.32 albertel 518: &remove_from_queue($env{'form.queue'});
1.20 albertel 519: } else {
1.25 albertel 520: $Apache::lonhomework::results{"resource.$version.status"}='pass';
521: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
522: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
523: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 524: &remove_from_queue($env{'form.queue'});
1.20 albertel 525: }
1.26 albertel 526: $Apache::lonhomework::results{"resource.status"}=
527: $Apache::lonhomework::results{"resource.$version.status"};
1.28 albertel 528: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 529: $Apache::lonhomework::results{"resource.0.award"}=
530: $Apache::lonhomework::results{"resource.$version.award"};
531: $Apache::lonhomework::results{"resource.0.awarded"}=
532: $Apache::lonhomework::results{"resource.$version.awarded"};
533: $Apache::lonhomework::results{"resource.0.solved"}=
534: $Apache::lonhomework::results{"resource.$version.solved"};
1.25 albertel 535: }
1.21 albertel 536: &Apache::structuretags::finalize_storage();
1.20 albertel 537: }
1.15 albertel 538: } elsif ($target eq 'webgrade') {
1.18 albertel 539: $result.="</table>\n<hr />";
1.20 albertel 540: #$result.='<input type="submit" name="next" value="'.
541: # &mt('Save & Next').'" /> ';
542: #$result.='<input type="submit" name="end" value="'.
543: # &mt('Save & Stop Grading').'" /> ';
544: #$result.='<input type="submit" name="throwaway" value="'.
545: # &mt('Throw Away & Stop Grading').'" /> ';
546: #$result.='<input type="submit" name="save" value="'.
547: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 548: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 549: } elsif ($target eq 'meta') {
1.2 albertel 550: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 551: #$result.=&Apache::response::meta_part_order();
552: #$result.=&Apache::response::meta_response_order();
553: }
1.4 albertel 554: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 555: return $result;
556: }
557:
1.31 albertel 558: sub move_between_queues {
559: my ($src_queue,$dest_queue)=@_;
560: my $cur_data=&get_queue_data($src_queue);
561: if (!$cur_data) { return 'not_exist'; }
562: my $result=&add_to_queue($dest_queue,$cur_data->[0]);
563: if ($result ne 'ok') {
564: return $result;
565: }
566: &check_queue_unlock($src_queue);
567: return &remove_from_queue($src_queue);
1.21 albertel 568: }
569:
570: sub check_queue_unlock {
1.32 albertel 571: my ($queue,$key,$allow_not_me)=@_;
1.30 albertel 572: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 573: if (!defined($key)) {
574: $key="$symb\0queue\0$uname\@$udom";
575: }
1.30 albertel 576: my $cnum=$env{'course.'.$cid.'.num'};
577: my $cdom=$env{'course.'.$cid.'.domain'};
578: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
579: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
580: if ($who eq $me) {
1.32 albertel 581: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
582: } elsif ($allow_not_me) {
1.33 albertel 583: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 584: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 585: }
1.32 albertel 586: return 'not_owner';
1.21 albertel 587: }
588:
589: sub remove_from_queue {
1.30 albertel 590: my ($queue)=@_;
1.27 albertel 591: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
592: my $cnum=$env{'course.'.$cid.'.num'};
593: my $cdom=$env{'course.'.$cid.'.domain'};
594: my $key="$symb\0queue\0$uname\@$udom";
595: my @keys=($key,"$key\0locked");
1.31 albertel 596: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 597: }
598:
1.16 albertel 599: sub setup_env_for_other_user {
600: my ($queue_key,$safeeval)=@_;
601: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 602: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 603: $env{'form.grade_symb'}=$symb;
604: $env{'form.grade_domain'}=$udom;
605: $env{'form.grade_username'}=$uname;
606: $env{'form.grade_courseid'}=$env{'request.course.id'};
607: &Apache::lonxml::initialize_rndseed($safeeval);
608: }
609:
1.31 albertel 610: sub get_queue_data {
611: my ($queue)=@_;
612: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
613: my $cnum=$env{'course.'.$cid.'.num'};
614: my $cdom=$env{'course.'.$cid.'.domain'};
615: my $todo="$symb\0queue\0$uname\@$udom";
616: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
617: if ($key eq $todo && ref($value)) {
618: return $value;
619: }
620: return undef;
621: }
622:
1.14 albertel 623: sub add_to_queue {
1.31 albertel 624: my ($queue,$slot_name)=@_;
1.14 albertel 625: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
626: my $cnum=$env{'course.'.$cid.'.num'};
627: my $cdom=$env{'course.'.$cid.'.domain'};
628: my %data;
1.31 albertel 629: $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
630: return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14 albertel 631: }
632:
633: sub show_queue {
1.32 albertel 634: my ($queue,$with_selects)=@_;
1.14 albertel 635: my $result;
636: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
637: my $cnum=$env{'course.'.$cid.'.num'};
638: my $cdom=$env{'course.'.$cid.'.domain'};
1.16 albertel 639: my $regexp="^$symb\0";
1.30 albertel 640: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 641: my ($tmp)=%queue;
642: if ($tmp=~/^error: 2 /) {
1.33 albertel 643: return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31 albertel 644: }
1.33 albertel 645: $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32 albertel 646: if ($with_selects) { $result.="<th></th>"; }
647: $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 648: foreach my $key (sort(keys(%queue))) {
1.32 albertel 649: if ($key=~/locked$/ && !$with_selects) {
1.16 albertel 650: my ($symb,$uname,$udom) = &decode_queue_key($key);
651: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 652: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 653: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32 albertel 654: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.16 albertel 655: my ($symb,undef) = split("\0",$key);
656: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 657: $result.="<tr><td>$title</td><td></td>";
1.16 albertel 658: $result.='<td>last queue modification time</td><td>'.
659: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 660: } elsif ($key!~/(timestamp|locked)$/) {
1.16 albertel 661: my ($symb,$uname,$udom) = &decode_queue_key($key);
662: my $title=&Apache::lonnet::gettitle($symb);
1.32 albertel 663: $result.="<tr>";
664: if ($with_selects) {
665: my $ekey=&Apache::lonnet::escape($key);
666: my ($action,$description)=('select',&mt('Select'));
667: if (exists($queue{"$key\0locked"})) {
668: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
669: if ($me eq $queue{"$key\0locked"}) {
670: ($action,$description)=('resume',&mt('Resume'));
671: } else {
672: ($action,$description)=('unlock',&mt('Unlock'));
673: }
674: }
675: $result.=(<<FORM);
676: <td>
677: <form method="POST">
678: <input type="hidden" name="gradingkey" value="$ekey" />
679: <input type="hidden" name="queue" value="$queue" />
680: <input type="hidden" name="gradingaction" value="$action" />
681: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 682: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 683: <input type="submit" name="submit" value="$description" />
684: </form>
685: </td>
686: FORM
687: }
688: $result.="<td>$title</td><td>$uname</td>";
1.16 albertel 689: my $slot=$queue{$key}->[0];
690: my %slot_data=&Apache::lonnet::get_slot($slot);
1.27 albertel 691: $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20 albertel 692: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
693: "</td></tr>";
1.16 albertel 694: }
1.14 albertel 695: }
1.15 albertel 696: $result.="</table><hr />\n";
1.14 albertel 697: return $result;
698: }
699:
1.34 ! albertel 700: sub get_queue_counts {
! 701: my ($queue)=@_;
! 702: my $result;
! 703: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
! 704: my $cnum=$env{'course.'.$cid.'.num'};
! 705: my $cdom=$env{'course.'.$cid.'.domain'};
! 706: my $regexp="^$symb\0";
! 707: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
! 708: my ($tmp)=%queue;
! 709: if ($tmp=~/^error: 2 /) {
! 710: return (0,0,0);
! 711: }
! 712: my ($entries,$ready_to_grade,$locks)=(0,0,0);
! 713: foreach my $key (sort(keys(%queue))) {
! 714: if ($key=~/locked$/) {
! 715: $locks++;
! 716: } elsif ($key=~/timestamp$/) {
! 717: #ignore
! 718: } elsif ($key!~/(timestamp|locked)$/) {
! 719: my ($symb,$uname,$udom) = &decode_queue_key($key);
! 720: $entries++;
! 721: my $slot=$queue{$key}->[0];
! 722: my %slot_data=&Apache::lonnet::get_slot($slot);
! 723: if (time > $slot_data{'endtime'}) {
! 724: $ready_to_grade++;
! 725: }
! 726: }
! 727: }
! 728: return ($entries,$ready_to_grade,$locks);
! 729: }
! 730:
1.14 albertel 731: sub decode_queue_key {
732: my ($key)=@_;
733: my ($symb,undef,$user) = split("\0",$key);
734: my ($uname,$udom) = split('@',$user);
735: return ($symb,$uname,$udom);
736: }
737:
738: sub queue_key_locked {
1.30 albertel 739: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 740: if (!defined($cdom) || !defined($cnum)) {
741: my (undef,$cid)=&Apache::lonxml::whichuser();
742: $cnum=$env{'course.'.$cid.'.num'};
743: $cdom=$env{'course.'.$cid.'.domain'};
744: }
1.14 albertel 745: my ($key_locked,$value)=
1.30 albertel 746: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 747: if ($key_locked eq "$key\0locked") {
748: return $value;
749: }
750: return undef;
751: }
752:
753: sub pick_from_queue_data {
1.30 albertel 754: my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
755: foreach my $key (keys(%$queuedata)) {
1.14 albertel 756: my ($symb,$uname,$udom)=&decode_queue_key($key);
757: if ($check_section) {
758: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 759: if ($section eq $check_section) {
1.33 albertel 760: &Apache::lonxml::debug("my sec");
1.15 albertel 761: next;
762: }
1.14 albertel 763: }
1.30 albertel 764: my $slot=$queuedata->{$key}[0];
1.14 albertel 765: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 766: if ($slot_data{'endtime'} > time) {
1.33 albertel 767: &Apache::lonxml::debug("not time");
1.15 albertel 768: next;
769: }
1.30 albertel 770: if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33 albertel 771: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 772: next;
773: }
1.14 albertel 774: return $key;
775: }
776: return undef;
777: }
778:
1.15 albertel 779: sub find_mid_grade {
1.30 albertel 780: my ($queue,$symb,$cdom,$cnum)=@_;
1.16 albertel 781: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 782: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
783: if ($todo) {
1.30 albertel 784: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 785: if ($who eq $me) { return $todo; }
786: }
787: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 788: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 789: foreach my $key (keys(%locks)) {
790: my $who=$locks{$key};
791: if ($who eq $me) {
792: $todo=$key;
793: $todo=~s/\0locked$//;
794: return $todo;
795: }
796: }
797: return undef;
798: }
799:
1.32 albertel 800: sub lock_key {
801: my ($queue,$todo)=@_;
802: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
803: my (undef,$cid)=&Apache::lonxml::whichuser();
804: my $cnum=$env{'course.'.$cid.'.num'};
805: my $cdom=$env{'course.'.$cid.'.domain'};
806: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
807: $cdom,$cnum);
1.33 albertel 808: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 809: if ($success eq 'ok') {
810: return 1;
811: }
812: return 0;
813: }
814:
1.14 albertel 815: sub get_from_queue {
1.30 albertel 816: my ($queue)=@_;
1.14 albertel 817: my $result;
818: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
819: my $cnum=$env{'course.'.$cid.'.num'};
820: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 821: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 822: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 823: if ($todo) { return $todo; }
1.14 albertel 824: while (1) {
825: my $starttime=time;
1.30 albertel 826: &Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14 albertel 827: $cdom,$cnum);
1.33 albertel 828: &Apache::lonxml::debug("$starttime");
1.14 albertel 829: my $regexp="^$symb\0queue\0";
1.30 albertel 830: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 831: #make a pass looking for a user _not_ in my section
1.14 albertel 832: if ($env{'request.course.sec'}) {
1.33 albertel 833: &Apache::lonxml::debug("sce");
1.30 albertel 834: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
835: \%queue,$cdom,$cnum);
1.33 albertel 836: &Apache::lonxml::debug("sce $todo");
1.14 albertel 837: }
1.33 albertel 838: # no one _not_ in our section so look for any user that is
839: # ready for grading
1.14 albertel 840: if (!$todo) {
1.33 albertel 841: &Apache::lonxml::debug("no sce");
1.31 albertel 842: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
843: \%queue,$cdom,$cnum);
1.33 albertel 844: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 845: }
846: # no user to grade
847: if (!$todo) { last; }
1.33 albertel 848: &Apache::lonxml::debug("got $todo");
1.14 albertel 849: # otherwise found someone so lets try to lock them
1.32 albertel 850: # unless someone else already picked them
851: if (!&lock_key($queue,$todo)) { next; }
1.14 albertel 852: my (undef,$endtime)=
1.30 albertel 853: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 854: $cdom,$cnum);
1.33 albertel 855: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 856: # someone else already modified the queue,
857: # perhaps our picked user wass already fully graded between
858: # when we picked him and when we locked his record? so lets
859: # double check.
860: if ($endtime != $starttime) {
861: my ($key,$value)=
1.30 albertel 862: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 863: $cdom,$cnum);
1.33 albertel 864: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 865: if ($key eq $todo && ref($value)) {
866: } else {
1.30 albertel 867: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 868: $cdom,$cnum);
1.33 albertel 869: &Apache::lonxml::debug("del");
1.14 albertel 870: next;
871: }
872: }
1.33 albertel 873: &Apache::lonxml::debug("last $todo");
1.14 albertel 874: last;
875: }
876: return $todo;
877: }
878:
1.1 albertel 879: sub start_ClosingParagraph {
880: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
881: my $result;
882: if ($target eq 'web') {
1.13 albertel 883: } elsif ($target eq 'webgrade') {
884: &Apache::lonxml::startredirection();
1.1 albertel 885: }
886: return $result;
887: }
888:
889: sub end_ClosingParagraph {
890: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
891: my $result;
892: if ($target eq 'web') {
1.13 albertel 893: } elsif ($target eq 'webgrade') {
894: &Apache::lonxml::endredirection();
1.1 albertel 895: }
896: return $result;
897: }
898:
1.19 albertel 899: sub get_id {
900: my ($parstack,$safeeval)=@_;
901: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
902: if (!$id) { $id=$Apache::lonxml::curdepth; }
903: return $id;
904: }
905:
1.1 albertel 906: my %dimension;
907: sub start_Dimension {
908: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
909: undef(%dimension);
1.19 albertel 910: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 911: $Apache::bridgetask::dimension=$dim_id;
912: push(@Apache::bridgetask::dimensionlist,$dim_id);
913: undef(@Apache::bridgetask::instance);
1.20 albertel 914: $Apache::bridgetask::dimensionmandatory{$dim_id}=
915: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 916: return '';
917: }
918:
1.13 albertel 919: sub get_instance {
920: &Apache::response::pushrandomnumber();
921: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29 albertel 922: my $num=@order;
923: my $version=&get_version();
924: my $which=($version-1)%$num;
925: return $order[$which];
1.13 albertel 926: }
927:
1.18 albertel 928: {
929: my $last_link;
930: sub end_Dimension {
931: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
932: my $result;
1.25 albertel 933: my $dim=&get_id($parstack,$safeeval);
1.19 albertel 934: my $instance=&get_instance();
1.25 albertel 935: my $version=&get_version();
1.18 albertel 936: if ($target eq 'web') {
937: $result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.26 albertel 938: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
939: $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 940: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 941: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
942: my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.22 albertel 943: $result.='<table border="1"><tr><td>';
944: if ($status eq 'fail') {
945: $result.='<font color="red">'.&mt('Did not pass').'</font>';
946: } elsif ($status eq 'pass') {
947: $result.='<font color="green">'.&mt('Passed').'</font>';
948: } else {
949: &Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
950: }
951: $result.='</td></tr><tr><td>';
1.25 albertel 952: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
953: $result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
1.22 albertel 954: }
955: $result.=$dimension{$instance.'.criteria.'.$id}.
956: '</td></tr></table>';
957: }
958: }
1.18 albertel 959: } elsif ($target eq 'webgrade') {
960: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
961: my $link='criteria_'.$instance.'_'.$id;
1.25 albertel 962: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19 albertel 963: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 964: '<a name="'.$link.'" />'.
965: '<a name="next_'.$last_link.'" />'.
966: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">'.$dimension{$instance.'.criteria.'.$id}.'</textarea>'.
967: #$dimension{$instance.'.criteria.'.$id}.
968: '</td>'.
1.19 albertel 969: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25 albertel 970: '<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 971: '</td>'.
972: '<td>'.
1.30 albertel 973: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>'.&mt('Ungraded').'</label></nobr><br />'.
974: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
975: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
976: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18 albertel 977: '</td>'.
978: '<td>'.
979: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 980: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
981: '<input type="submit" name="next" value="'.
982: &mt('Done').'" /> '.
1.30 albertel 983: '<input type="submit" name="stop" value="'.
984: &mt('Stop').'" /> '.
1.18 albertel 985: '</td></tr>';
1.22 albertel 986: $result.='<tr><td colspan="4">';
987: my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
988: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
1.23 albertel 989: foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.bridgetask.portfiles"})) {
1.22 albertel 990: my $file=$file_url.$partial_file;
991: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
992: $result.='<a href="'.$file.'" target="lonGRDs"><img src="'.
993: &Apache::loncommon::icon($file).'" border=0"> '.$file.
994: '</a>';
995: }
996: $result.='</td></tr>';
1.18 albertel 997: $last_link=$link;
998: }
1.22 albertel 999: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 1000: my $optional_passed=0;
1.20 albertel 1001: my $mandatory_failed=0;
1002: my $ungraded=0;
1003: my $review=0;
1.19 albertel 1004: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1005: my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
1006: $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 1007: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1008: if ($status eq 'pass') {
1009: if (!$mandatory) { $optional_passed++; }
1010: } elsif ($status eq 'fail') {
1011: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 1012: } elsif ($status eq 'review') {
1013: $review++;
1.20 albertel 1014: } elsif ($status eq 'ungraded') {
1015: $ungraded++;
1.21 albertel 1016: } else {
1.22 albertel 1017: &Apache::lonxml::error("got weird status --$status--");
1.19 albertel 1018: }
1019: }
1.20 albertel 1020: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
1021: $mandatory_failed++;
1022: }
1.21 albertel 1023: &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 1024: if ($review) {
1.25 albertel 1025: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1026: 'review';
1.20 albertel 1027: } elsif ($ungraded) {
1.25 albertel 1028: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1029: 'ungraded';
1.20 albertel 1030: } elsif ($mandatory_failed) {
1.25 albertel 1031: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1032: 'fail';
1.20 albertel 1033: } else {
1.25 albertel 1034: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1035: 'pass';
1.20 albertel 1036: }
1.13 albertel 1037: }
1.18 albertel 1038: return $result;
1.1 albertel 1039: }
1040: }
1041:
1042: sub start_IntroParagraph {
1043: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1044: my $result;
1.13 albertel 1045: if ($target eq 'web' || $target eq 'webgrade') {
1046: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 1047: &Apache::lonxml::startredirection();
1048: }
1049: }
1050: return $result;
1051: }
1052:
1053: sub end_IntroParagraph {
1054: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1055: my $result;
1.13 albertel 1056: if ($target eq 'web' || $target eq 'webgrade') {
1057: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 1058: $dimension{'intro'}=&Apache::lonxml::endredirection();
1059: }
1060: }
1061: return $result;
1062: }
1063:
1064: sub start_Instance {
1065: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 1066: my $id=&get_id($parstack,$safeeval);
1067: push(@{$dimension{'instances'}},$id);
1068: push(@Apache::bridgetask::instance,$id);
1069: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 1070: $dimension{$id.'.optionalrequired'}=
1.19 albertel 1071: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 1072: return '';
1073: }
1074:
1075: sub end_Instance {
1076: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1077: return '';
1078: }
1079:
1080: sub start_InstanceText {
1081: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13 albertel 1082: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 1083: &Apache::lonxml::startredirection();
1084: }
1085: return '';
1086: }
1087:
1088: sub end_InstanceText {
1089: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1090: my $instance_id=$Apache::bridgetask::instance[-1];
1.13 albertel 1091: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 1092: $dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
1093: }
1094: return '';
1095: }
1096:
1097: sub start_Criteria {
1098: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.21 albertel 1099: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 1100: &Apache::lonxml::startredirection();
1101: }
1102: return '';
1103: }
1104:
1105: sub end_Criteria {
1106: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1107: my $instance_id=$Apache::bridgetask::instance[-1];
1.21 albertel 1108: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 1109: my $criteria=&Apache::lonxml::endredirection();
1.19 albertel 1110: my $id=&get_id($parstack,$safeeval);
1.1 albertel 1111: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 1112: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
1113: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 1114: push(@{$dimension{$instance_id.'.criterias'}},$id);
1115: }
1116: return '';
1117: }
1118:
1.4 albertel 1119: sub proctor_validation_screen {
1120: my ($slot) = @_;
1121: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 1122: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11 albertel 1123: $user=$env{'form.proctorname'};
1124: if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4 albertel 1125: my $msg;
1.11 albertel 1126: if ($env{'form.proctorpassword'}) {
1.4 albertel 1127: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
1128: .'</font></p>';
1129: }
1130: my $result= (<<ENDCHECKOUT);
1131: <h2>Proctor Validation</h2>
1132: <p>Your room's proctor needs to validate your access to this resource.</p>
1133: $msg
1.11 albertel 1134: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 1135: <input type="hidden" name="validate" value="yes" />
1136: <input type="hidden" name="submitted" value="yes" />
1137: <table>
1138: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
1139: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6 albertel 1140: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4 albertel 1141: </table>
1142: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1143: Student who should be logged in is:<br />
1.5 albertel 1144: <img src="$url" /><br />
1.4 albertel 1145: </form>
1146: ENDCHECKOUT
1147: return $result;
1148: }
1149:
1.1 albertel 1150: 1;
1151: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>