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