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