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