Annotation of loncom/homework/bridgetask.pm, revision 1.52
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.52 ! albertel 4: # $Id: bridgetask.pm,v 1.51 2005/09/20 07:14:23 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'})) {
1.34 albertel 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);
1.32 albertel 159: $result.=' <input type="submit" name="reviewasubmission" value="'.
1.34 albertel 160: &mt("Select an entry from the review queue").'" /> </p>'."\n";
1.49 albertel 161: $result.=' <input type="submit" name="regradeasubmission" value="'.
162: &mt("Select a user to regrade.").'" /> </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.41 albertel 288: &proctor_check_auth($slot_name,$slot);
1.4 albertel 289: }
1.1 albertel 290: }
291: } elsif ($target eq 'web') {
292: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
293: $result.="$head_tag_start<title>$name</title></head>
1.36 albertel 294: $body_tag_start \n";
295:
1.29 albertel 296: my ($version,$previous)=&get_version();
1.25 albertel 297: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 298: $result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.29 albertel 299: if (!$previous) {
300: $result.=&add_request_another_attempt_button();
301: }
1.22 albertel 302: }
1.25 albertel 303: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22 albertel 304: $result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
305: }
1.36 albertel 306: $result.=$form_tag_start.
307: '<input type="hidden" name="submitted" value="yes" />';
308: $result.=&preserve_grade_info();
309:
1.1 albertel 310: }
1.21 albertel 311: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
312: $target eq 'webgrade') {
1.32 albertel 313: my $webgrade='yes';
1.21 albertel 314: if ($target eq 'webgrade') {
1.32 albertel 315: $result.=$head_tag_start.$body_tag_start;
1.49 albertel 316: #$result.='<br />Review'.&show_queue('reviewqueue');
317: #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 318: }
1.33 albertel 319: # FIXME Blast! still need to reorg this, need to reshow the
320: # queue being reviewed once done with the grade pass...
321: # Hrrm, vaildation pass should perhaps say 'not_locked'
322: # perhaps do a search if there is a key that is mine and if
323: # there isn't reshow the queue....
324: my ($todo,$status_code)=&get_key_todo($target);
325:
326: &Apache::lonnet::logthis("got todo -$todo- stat -$status_code-");
327: if ($todo) {
328: &setup_env_for_other_user($todo,$safeeval);
329: my ($symb,$uname,$udom)=&decode_queue_key($todo);
330: $result.="\n".'<table><tr><td>Found '.
331: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
332: $form_tag_start.=
333: '<input type="hidden" name="gradingkey" value="'.
334: &Apache::lonnet::escape($todo).'" />';
335: $Apache::bridgetask::queue_key=$todo;
336: &Apache::structuretags::initialize_storage();
337: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
338: if ($target eq 'webgrade') {
1.49 albertel 339: #$result.='<br />After -'.&show_queue($env{'form.queue'});
1.33 albertel 340: $result.="\n".'<table width="100%" style="width:100%" border="1">';
341: if ($status_code eq 'selected') {
342: $form_tag_start.=
343: '<input type="hidden" name="queuemode" value="selected" />';
344: }
345: }
1.15 albertel 346: } else {
1.33 albertel 347: if ($target eq 'webgrade') {
348: $result.="\n";
349: if ($status_code eq 'stop') {
350: $result.='<b>'.&mt("Stopped grading.").'</b>';
351: } elsif ($status_code eq 'lock_failed') {
352: $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
353: } elsif ($status_code eq 'unlock') {
354: $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
355: $result.=&show_queue($env{'form.queue'},1);
356: } elsif ($status_code eq 'show_list') {
357: $result.=&show_queue($env{'form.queue'},1);
1.49 albertel 358: } elsif ($status_code eq 'select_user') {
359: $result.=&select_user();
1.33 albertel 360: } else {
361: $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32 albertel 362: }
1.21 albertel 363: }
1.33 albertel 364: $webgrade='no';
365: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32 albertel 366: }
367: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
368: $result.=$form_tag_start;
369: $result.='<input type="hidden" name="webgrade" value="'.
370: $webgrade.'" />';
371: $result.='<input type="hidden" name="queue" value="'.
372: $env{'form.queue'}.'" />';
1.52 ! albertel 373: if ($env{'form.regrade'}) {
! 374: $result.='<input type="hidden" name="regrade" value="'.
! 375: $env{'form.regrade'}.'" />';
! 376: }
1.15 albertel 377: }
1.1 albertel 378: } else {
379: # page_start returned a starting result, delete it if we don't need it
380: $result = '';
381: }
382: return $result;
383: }
384:
1.32 albertel 385: sub get_key_todo {
386: my ($target)=@_;
387: my $todo;
1.33 albertel 388:
389: if (defined($env{'form.reviewasubmission'})) {
390: &Apache::lonnet::logthis("review a submission....");
391: $env{'form.queue'}='reviewqueue';
392: return (undef,'show_list');
393: }
394:
395: if (defined($env{'form.reviewagrading'})) {
396: &Apache::lonxml::debug("review a grading....");
397: $env{'form.queue'}='gradingqueue';
398: return (undef,'show_list');
399: }
400:
1.49 albertel 401: if (defined($env{'form.regradeasubmission'})) {
402: &Apache::lonxml::debug("regrade a grading....");
403: $env{'form.queue'}='none';
404: return (undef,'select_user');
405: }
406:
1.32 albertel 407: my $queue=$env{'form.queue'};
1.33 albertel 408:
1.32 albertel 409: if (!defined($queue)) {
410: $env{'form.queue'}=$queue='gradingqueue';
411: }
1.33 albertel 412:
1.32 albertel 413: my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33 albertel 414:
1.49 albertel 415: if ($env{'form.queue'} eq 'none') {
416: if (defined($env{'form.gradingkey'})) {
417: if ($target eq 'webgrade') {
418: if ($env{'form.stop'}) {
419: return (undef,'stop');
420: } elsif ($env{'form.next'}) {
421: return (undef,'show_list');
422: }
423: }
424: return ($gradingkey,'selected');
425: } else {
426: return (undef,'show_list');
427: }
428: }
1.32 albertel 429: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 albertel 430: && !defined($env{'form.gradingaction'})
431: && $env{'form.queuemode'} eq 'selected') {
432:
433: my $who=&queue_key_locked($queue,$gradingkey);
434: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
435: if ($who eq $me) {
436: &Apache::lonxml::debug("Found a key was given to me");
437: return ($gradingkey,'selected');
438: } else {
439: return (undef,'show_list');
440: }
441:
442: }
443:
444: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
445: if ($env{'form.gradingaction'} eq 'resume') {
446: delete($env{'form.gradingaction'});
447: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 448: return ($gradingkey);
1.33 albertel 449: } elsif ($env{'form.gradingaction'} eq 'unlock') {
450: &Apache::lonxml::debug("Unlocking a key ".
451: &check_queue_unlock($queue,$gradingkey,1));
452: return (undef,'unlock');
453: } elsif ($env{'form.gradingaction'} eq 'select') {
454: &Apache::lonxml::debug("Locking a key");
455: if (&lock_key($queue,$gradingkey)) {
456: &Apache::lonxml::debug("Success $queue");
457: return ($gradingkey);
458: }
459: &Apache::lonxml::debug("Failed $queue");
460: return (undef,'lock_failed');
1.32 albertel 461: }
462: }
1.33 albertel 463:
464: if ($env{'form.queuemode'} ne 'selected') {
465: # don't get something new from the queue if they hit the stop button
466: if (!($env{'form.stop'} && $target eq 'webgrade')
467: && !$env{'form.gradingaction'}) {
468: &Apache::lonxml::debug("Getting anew $queue");
469: return (&get_from_queue($queue));
470: } else {
471: return (undef,'stop');
472: }
1.32 albertel 473: }
1.33 albertel 474: return (undef,undef)
1.32 albertel 475: }
476:
1.1 albertel 477: sub end_Task {
478: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
479: my $result='';
480: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 481: my ($version,$previous)=&get_version();
1.1 albertel 482: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 483: $target eq 'tex') {
1.1 albertel 484: if (
1.11 albertel 485: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1 albertel 486: ($target eq 'answer') || ($target eq 'tex')
487: ) {
488: if ($target eq 'web') {
1.29 albertel 489: if ($status eq 'CAN_ANSWER' && !$previous) {
1.15 albertel 490: $result.="\n".'<table border="1">'.
1.28 albertel 491: &Apache::inputtags::file_selector("$version.0",
492: "bridgetask","*",
1.46 albertel 493: 'portfolioonly',
494: '
495: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
496: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9 albertel 497: "</table>";
498: $result.=&Apache::inputtags::gradestatus('0');
499: }
1.13 albertel 500: }
501: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 502: $result.=&Apache::lonxml::xmlend().'</html>';
503: }
504: }
1.29 albertel 505: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 506: my $award='SUBMITTED';
1.28 albertel 507: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 508: 'portfiles',\$award);
1.14 albertel 509: if ($award eq 'SUBMITTED' &&
1.28 albertel 510: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
511: $Apache::lonhomework::results{"resource.0.tries"}=
512: $Apache::lonhomework::results{"resource.$version.0.tries"}=
513: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
514:
515: $Apache::lonhomework::results{"resource.0.award"}=
516: $Apache::lonhomework::results{"resource.$version.0.award"}=
517: $award;
1.51 albertel 518: $Apache::lonhomework::results{"resource.0.submission"}=
519: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.10 albertel 520: }
1.4 albertel 521: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
522: &Apache::structuretags::finalize_storage();
1.14 albertel 523: if ($award eq 'SUBMITTED') {
1.31 albertel 524: &add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14 albertel 525: }
1.1 albertel 526: }
1.32 albertel 527: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20 albertel 528: my $optional_required=
529: &Apache::lonxml::get_param('OptionalRequired',$parstack,
530: $safeeval);
531: my $optional_passed=0;
532: my $mandatory_failed=0;
533: my $ungraded=0;
534: my $review=0;
1.21 albertel 535: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 536: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
537: my $status=
1.25 albertel 538: $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20 albertel 539: my $mandatory=
540: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
541: if ($status eq 'pass') {
542: if (!$mandatory) { $optional_passed++; }
543: } elsif ($status eq 'fail') {
544: if ($mandatory) { $mandatory_failed++; }
545: } elsif ($status eq 'ungraded') {
546: $ungraded++;
547: } elsif ($status eq 'review') {
548: $review++;
1.49 albertel 549: } else {
550: $ungraded++;
551: }
1.20 albertel 552: }
553: if ($optional_passed < $optional_required) {
554: $mandatory_failed++;
555: }
1.21 albertel 556: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
557: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 558: $env{'user.name'}.'@'.$env{'user.domain'};
559: if ($review) {
1.25 albertel 560: $Apache::lonhomework::results{"resource.$version.status"}='review';
1.33 albertel 561: if ($env{'form.queue'} eq 'reviewqueue') {
562: &check_queue_unlock($env{'form.queue'});
563: &Apache::lonxml::debug(" still needs review not changing status.");
564: } else {
1.49 albertel 565: &move_between_queues($env{'form.queue'},'reviewqueue');
1.33 albertel 566: }
1.20 albertel 567: } elsif ($ungraded) {
1.25 albertel 568: $Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.49 albertel 569: if ($env{'form.queue'} eq 'reviewqueue' ||
570: $env{'form.queue'} eq 'none' ) {
1.33 albertel 571: &Apache::lonxml::debug("moving back.");
1.49 albertel 572: &move_between_queues($env{'form.queue'},'gradingqueue');
1.33 albertel 573: } else {
574: &check_queue_unlock($env{'form.queue'});
575: }
1.20 albertel 576: } elsif ($mandatory_failed) {
1.25 albertel 577: $Apache::lonhomework::results{"resource.$version.status"}='fail';
578: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
579: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
580: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39 albertel 581: &remove_from_queue($env{'form.queue'});
582:
583: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 ! albertel 584:
! 585: if ($env{'form.regrade'} ne 'yes') {
! 586: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
! 587: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
! 588: &Apache::grades::version_portfiles(
! 589: \%Apache::lonhomework::results,
! 590: ["$version.0.bridgetask"],$courseid,
! 591: $symb,$udom,$uname,
! 592: ["$version.0.bridgetask"]);
! 593: }
1.20 albertel 594: } else {
1.25 albertel 595: $Apache::lonhomework::results{"resource.$version.status"}='pass';
596: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
597: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
598: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 599: &remove_from_queue($env{'form.queue'});
1.39 albertel 600:
601: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 ! albertel 602: if ($env{'form.regrade'} ne 'yes') {
! 603: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
! 604: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
! 605: &Apache::grades::version_portfiles(
! 606: \%Apache::lonhomework::results,
! 607: ["$version.0.bridgetask"],$courseid,
! 608: $symb,$udom,$uname,
! 609: ["$version.0.bridgetask"]);
! 610: }
1.20 albertel 611: }
1.26 albertel 612: $Apache::lonhomework::results{"resource.status"}=
613: $Apache::lonhomework::results{"resource.$version.status"};
1.28 albertel 614: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 615: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 616: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 617: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 618: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 619: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 620: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 621: }
1.21 albertel 622: &Apache::structuretags::finalize_storage();
1.20 albertel 623: }
1.15 albertel 624: } elsif ($target eq 'webgrade') {
1.18 albertel 625: $result.="</table>\n<hr />";
1.20 albertel 626: #$result.='<input type="submit" name="next" value="'.
627: # &mt('Save & Next').'" /> ';
628: #$result.='<input type="submit" name="end" value="'.
629: # &mt('Save & Stop Grading').'" /> ';
630: #$result.='<input type="submit" name="throwaway" value="'.
631: # &mt('Throw Away & Stop Grading').'" /> ';
632: #$result.='<input type="submit" name="save" value="'.
633: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 634: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 635: } elsif ($target eq 'meta') {
1.2 albertel 636: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 637: #$result.=&Apache::response::meta_part_order();
638: #$result.=&Apache::response::meta_response_order();
639: }
1.4 albertel 640: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 641: return $result;
642: }
643:
1.31 albertel 644: sub move_between_queues {
645: my ($src_queue,$dest_queue)=@_;
1.49 albertel 646: my $cur_data;
647: if ($src_queue ne 'none') {
648: $cur_data=&get_queue_data($src_queue);
649: if (!$cur_data) { return 'not_exist'; }
650: } else {
651: $cur_data = ['none'];
652: }
1.31 albertel 653: my $result=&add_to_queue($dest_queue,$cur_data->[0]);
654: if ($result ne 'ok') {
655: return $result;
656: }
657: &check_queue_unlock($src_queue);
658: return &remove_from_queue($src_queue);
1.21 albertel 659: }
660:
661: sub check_queue_unlock {
1.32 albertel 662: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 663: if ($queue eq 'none') { return 'ok'; }
1.30 albertel 664: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 665: if (!defined($key)) {
666: $key="$symb\0queue\0$uname\@$udom";
667: }
1.30 albertel 668: my $cnum=$env{'course.'.$cid.'.num'};
669: my $cdom=$env{'course.'.$cid.'.domain'};
670: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
671: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
672: if ($who eq $me) {
1.32 albertel 673: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
674: } elsif ($allow_not_me) {
1.33 albertel 675: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 676: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 677: }
1.32 albertel 678: return 'not_owner';
1.21 albertel 679: }
680:
681: sub remove_from_queue {
1.30 albertel 682: my ($queue)=@_;
1.49 albertel 683: if ($queue eq 'none') { return 'ok'; }
1.27 albertel 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 $key="$symb\0queue\0$uname\@$udom";
688: my @keys=($key,"$key\0locked");
1.31 albertel 689: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 690: }
691:
1.16 albertel 692: sub setup_env_for_other_user {
693: my ($queue_key,$safeeval)=@_;
694: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 695: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 696: $env{'form.grade_symb'}=$symb;
697: $env{'form.grade_domain'}=$udom;
698: $env{'form.grade_username'}=$uname;
699: $env{'form.grade_courseid'}=$env{'request.course.id'};
700: &Apache::lonxml::initialize_rndseed($safeeval);
701: }
702:
1.31 albertel 703: sub get_queue_data {
704: my ($queue)=@_;
705: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
706: my $cnum=$env{'course.'.$cid.'.num'};
707: my $cdom=$env{'course.'.$cid.'.domain'};
708: my $todo="$symb\0queue\0$uname\@$udom";
709: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
710: if ($key eq $todo && ref($value)) {
711: return $value;
712: }
713: return undef;
714: }
715:
1.49 albertel 716: sub check_queue_for_key {
717: my ($cid,$queue,$todo)=@_;
718: my $cnum=$env{'course.'.$cid.'.num'};
719: my $cdom=$env{'course.'.$cid.'.domain'};
720: my %results=
721: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
722:
723: if (exists($results{$todo}) && ref($results{$todo})) {
724: if (defined($results{"$todo\0locked"})) {
725: return 'locked';
726: }
727: return 'enqueued';
728: }
729: return undef;
730: }
731:
1.14 albertel 732: sub add_to_queue {
1.31 albertel 733: my ($queue,$slot_name)=@_;
1.49 albertel 734: if ($queue eq 'none') { return 'ok'; }
1.14 albertel 735: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
736: my $cnum=$env{'course.'.$cid.'.num'};
737: my $cdom=$env{'course.'.$cid.'.domain'};
738: my %data;
1.31 albertel 739: $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
740: return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14 albertel 741: }
742:
743: sub show_queue {
1.32 albertel 744: my ($queue,$with_selects)=@_;
1.14 albertel 745: my $result;
746: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
747: my $cnum=$env{'course.'.$cid.'.num'};
748: my $cdom=$env{'course.'.$cid.'.domain'};
1.16 albertel 749: my $regexp="^$symb\0";
1.30 albertel 750: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 751: my ($tmp)=%queue;
752: if ($tmp=~/^error: 2 /) {
1.33 albertel 753: return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31 albertel 754: }
1.33 albertel 755: $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32 albertel 756: if ($with_selects) { $result.="<th></th>"; }
757: $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 758: foreach my $key (sort(keys(%queue))) {
1.32 albertel 759: if ($key=~/locked$/ && !$with_selects) {
1.16 albertel 760: my ($symb,$uname,$udom) = &decode_queue_key($key);
761: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 762: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 763: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32 albertel 764: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.16 albertel 765: my ($symb,undef) = split("\0",$key);
766: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 767: $result.="<tr><td>$title</td><td></td>";
1.16 albertel 768: $result.='<td>last queue modification time</td><td>'.
769: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 770: } elsif ($key!~/(timestamp|locked)$/) {
1.16 albertel 771: my ($symb,$uname,$udom) = &decode_queue_key($key);
772: my $title=&Apache::lonnet::gettitle($symb);
1.32 albertel 773: $result.="<tr>";
1.35 albertel 774: my $slot=$queue{$key}->[0];
775: my %slot_data=&Apache::lonnet::get_slot($slot);
1.32 albertel 776: if ($with_selects) {
777: my $ekey=&Apache::lonnet::escape($key);
778: my ($action,$description)=('select',&mt('Select'));
779: if (exists($queue{"$key\0locked"})) {
780: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
781: if ($me eq $queue{"$key\0locked"}) {
782: ($action,$description)=('resume',&mt('Resume'));
783: } else {
784: ($action,$description)=('unlock',&mt('Unlock'));
785: }
786: }
1.35 albertel 787: if (time > $slot_data{'endtime'}) {
788: $result.=(<<FORM);
1.32 albertel 789: <td>
790: <form method="POST">
791: <input type="hidden" name="gradingkey" value="$ekey" />
792: <input type="hidden" name="queue" value="$queue" />
793: <input type="hidden" name="gradingaction" value="$action" />
794: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 795: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 796: <input type="submit" name="submit" value="$description" />
797: </form>
798: </td>
799: FORM
1.35 albertel 800:
801: } else {
802: $result.='<td>'.&mt("In Progress").'</td>'
803: }
1.32 albertel 804: }
805: $result.="<td>$title</td><td>$uname</td>";
1.27 albertel 806: $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20 albertel 807: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
808: "</td></tr>";
1.16 albertel 809: }
1.14 albertel 810: }
1.15 albertel 811: $result.="</table><hr />\n";
1.14 albertel 812: return $result;
813: }
814:
1.34 albertel 815: sub get_queue_counts {
816: my ($queue)=@_;
817: my $result;
818: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
819: my $cnum=$env{'course.'.$cid.'.num'};
820: my $cdom=$env{'course.'.$cid.'.domain'};
821: my $regexp="^$symb\0";
822: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
823: my ($tmp)=%queue;
824: if ($tmp=~/^error: 2 /) {
825: return (0,0,0);
826: }
827: my ($entries,$ready_to_grade,$locks)=(0,0,0);
828: foreach my $key (sort(keys(%queue))) {
829: if ($key=~/locked$/) {
830: $locks++;
831: } elsif ($key=~/timestamp$/) {
832: #ignore
833: } elsif ($key!~/(timestamp|locked)$/) {
834: my ($symb,$uname,$udom) = &decode_queue_key($key);
835: $entries++;
836: my $slot=$queue{$key}->[0];
837: my %slot_data=&Apache::lonnet::get_slot($slot);
838: if (time > $slot_data{'endtime'}) {
839: $ready_to_grade++;
840: }
841: }
842: }
843: return ($entries,$ready_to_grade,$locks);
844: }
845:
1.49 albertel 846: sub encode_queue_key {
847: my ($symb,$udom,$uname)=@_;
848: return "$symb\0queue\0$uname\@$udom";
849: }
850:
1.14 albertel 851: sub decode_queue_key {
852: my ($key)=@_;
853: my ($symb,undef,$user) = split("\0",$key);
854: my ($uname,$udom) = split('@',$user);
855: return ($symb,$uname,$udom);
856: }
857:
858: sub queue_key_locked {
1.30 albertel 859: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 860: if (!defined($cdom) || !defined($cnum)) {
861: my (undef,$cid)=&Apache::lonxml::whichuser();
862: $cnum=$env{'course.'.$cid.'.num'};
863: $cdom=$env{'course.'.$cid.'.domain'};
864: }
1.14 albertel 865: my ($key_locked,$value)=
1.30 albertel 866: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 867: if ($key_locked eq "$key\0locked") {
868: return $value;
869: }
870: return undef;
871: }
872:
873: sub pick_from_queue_data {
1.30 albertel 874: my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
875: foreach my $key (keys(%$queuedata)) {
1.14 albertel 876: my ($symb,$uname,$udom)=&decode_queue_key($key);
877: if ($check_section) {
878: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 879: if ($section eq $check_section) {
1.33 albertel 880: &Apache::lonxml::debug("my sec");
1.15 albertel 881: next;
882: }
1.14 albertel 883: }
1.30 albertel 884: my $slot=$queuedata->{$key}[0];
1.14 albertel 885: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 886: if ($slot_data{'endtime'} > time) {
1.33 albertel 887: &Apache::lonxml::debug("not time");
1.15 albertel 888: next;
889: }
1.30 albertel 890: if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33 albertel 891: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 892: next;
893: }
1.14 albertel 894: return $key;
895: }
896: return undef;
897: }
898:
1.15 albertel 899: sub find_mid_grade {
1.30 albertel 900: my ($queue,$symb,$cdom,$cnum)=@_;
1.16 albertel 901: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 902: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
903: if ($todo) {
1.30 albertel 904: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 905: if ($who eq $me) { return $todo; }
906: }
907: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 908: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 909: foreach my $key (keys(%locks)) {
910: my $who=$locks{$key};
911: if ($who eq $me) {
912: $todo=$key;
913: $todo=~s/\0locked$//;
914: return $todo;
915: }
916: }
917: return undef;
918: }
919:
1.32 albertel 920: sub lock_key {
921: my ($queue,$todo)=@_;
922: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
923: my (undef,$cid)=&Apache::lonxml::whichuser();
924: my $cnum=$env{'course.'.$cid.'.num'};
925: my $cdom=$env{'course.'.$cid.'.domain'};
926: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
927: $cdom,$cnum);
1.33 albertel 928: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 929: if ($success eq 'ok') {
930: return 1;
931: }
932: return 0;
933: }
934:
1.14 albertel 935: sub get_from_queue {
1.30 albertel 936: my ($queue)=@_;
1.14 albertel 937: my $result;
938: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
939: my $cnum=$env{'course.'.$cid.'.num'};
940: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 941: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 942: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 943: if ($todo) { return $todo; }
1.14 albertel 944: while (1) {
945: my $starttime=time;
1.30 albertel 946: &Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14 albertel 947: $cdom,$cnum);
1.33 albertel 948: &Apache::lonxml::debug("$starttime");
1.14 albertel 949: my $regexp="^$symb\0queue\0";
1.30 albertel 950: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 951: #make a pass looking for a user _not_ in my section
1.14 albertel 952: if ($env{'request.course.sec'}) {
1.33 albertel 953: &Apache::lonxml::debug("sce");
1.30 albertel 954: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
955: \%queue,$cdom,$cnum);
1.33 albertel 956: &Apache::lonxml::debug("sce $todo");
1.14 albertel 957: }
1.33 albertel 958: # no one _not_ in our section so look for any user that is
959: # ready for grading
1.14 albertel 960: if (!$todo) {
1.33 albertel 961: &Apache::lonxml::debug("no sce");
1.31 albertel 962: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
963: \%queue,$cdom,$cnum);
1.33 albertel 964: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 965: }
966: # no user to grade
967: if (!$todo) { last; }
1.33 albertel 968: &Apache::lonxml::debug("got $todo");
1.14 albertel 969: # otherwise found someone so lets try to lock them
1.32 albertel 970: # unless someone else already picked them
971: if (!&lock_key($queue,$todo)) { next; }
1.14 albertel 972: my (undef,$endtime)=
1.30 albertel 973: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 974: $cdom,$cnum);
1.33 albertel 975: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 976: # someone else already modified the queue,
977: # perhaps our picked user wass already fully graded between
978: # when we picked him and when we locked his record? so lets
979: # double check.
980: if ($endtime != $starttime) {
981: my ($key,$value)=
1.30 albertel 982: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 983: $cdom,$cnum);
1.33 albertel 984: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 985: if ($key eq $todo && ref($value)) {
986: } else {
1.30 albertel 987: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 988: $cdom,$cnum);
1.33 albertel 989: &Apache::lonxml::debug("del");
1.14 albertel 990: next;
991: }
992: }
1.33 albertel 993: &Apache::lonxml::debug("last $todo");
1.14 albertel 994: last;
995: }
996: return $todo;
997: }
998:
1.49 albertel 999: sub select_user {
1000: my ($symb,$cid)=&Apache::lonxml::whichuser();
1001: my $result.='<table border="1">';
1002:
1003: &Apache::grades::init_perm();
1004: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all',);
1005: &Apache::grades::reset_perm();
1006:
1007: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1008: my ($uname,$udom) = split(/:/,$student);
1009: my %status = &get_student_status($symb,$cid,$udom,$uname);
1010: my $queue = 'none';
1011: if ($status{'reviewqueue'} eq 'enqueued') {
1012: $queue = 'reviewqueue';
1013: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1014: $queue = 'gradingqueue';
1015: }
1016: my $todo =
1017: &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1018: $result.=<<RESULT;
1019: <tr>
1020: <td>
1021: <form method="POST">
1022: <input type="hidden" name="gradingkey" value="$todo" />
1023: <input type="hidden" name="queue" value="$queue" />
1024: <input type="hidden" name="webgrade" value="no" />
1.52 ! albertel 1025: <input type="hidden" name="regrade" value="yes" />
1.49 albertel 1026: <input type="submit" name="submit" value="Regrade" />
1027: </form>
1028: <td>$fullname->{$student}</td>
1029: <td>
1030: RESULT
1031:
1032: if ($status{'status'} eq 'pass') {
1033: $result .= '<font color="green">'.&mt('Passed').'</font>';
1034: } elsif ($status{'status'} eq 'fail') {
1035: $result .= '<font color="red">'.&mt('Failed').'</font>';
1036: } elsif ($status{'status'} eq 'review') {
1037: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1038: } elsif ($status{'status'} eq 'ungraded') {
1039: $result .= &mt('Ungraded');
1040: } elsif ($status{'status'} ne '') {
1041: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1042: } else {
1043: $result.=" ";
1044: }
1045: if ($status{'version'}) {
1046: $result .= ' '.&mt('Version').' '.$status{'version'};
1047: }
1048: $result.= '</td><td>';
1049: if ($status{'reviewqueue'} eq 'enqueued') {
1050: $result .= &mt('Awaiting Review');
1051: } elsif ($status{'reviewqueue'} eq 'locked') {
1052: $result .= &mt('Under Review');
1053: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1054: $result .= &mt('Awaiting Grading');
1055: } elsif ($status{'gradingqueue'} eq 'locked') {
1056: $result .= &mt('Being Graded');
1057: } else {
1058: $result.=" ";
1059: }
1060: $result.= '</td></tr>';
1061: }
1062: $result.='</table>';
1063: return $result;
1064: }
1065:
1066: sub get_student_status {
1067: my ($symb,$cid,$udom,$uname)=@_;
1068: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1069: $udom,$uname);
1070: my %status;
1071: $status{'status'}=$record{'resource.status'};
1072: $status{'version'}=$record{'resource.version'};
1073: $status{'grader'}=$record{'resource.grader'};
1074: $status{'reviewqueue'}=&check_queue_for_key($cid,'reviewqueue',
1075: &encode_queue_key($symb,$udom,$uname));
1076: $status{'gradingqueue'}=&check_queue_for_key($cid,'gradingqueue',
1077: &encode_queue_key($symb,$udom,$uname));
1078: return %status;
1079: }
1080:
1.1 albertel 1081: sub start_ClosingParagraph {
1082: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1083: my $result;
1084: if ($target eq 'web') {
1.13 albertel 1085: } elsif ($target eq 'webgrade') {
1086: &Apache::lonxml::startredirection();
1.1 albertel 1087: }
1088: return $result;
1089: }
1090:
1091: sub end_ClosingParagraph {
1092: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1093: my $result;
1094: if ($target eq 'web') {
1.13 albertel 1095: } elsif ($target eq 'webgrade') {
1096: &Apache::lonxml::endredirection();
1.1 albertel 1097: }
1098: return $result;
1099: }
1100:
1.19 albertel 1101: sub get_id {
1102: my ($parstack,$safeeval)=@_;
1103: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1104: if (!$id) { $id=$Apache::lonxml::curdepth; }
1105: return $id;
1106: }
1107:
1.1 albertel 1108: my %dimension;
1109: sub start_Dimension {
1110: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1111: undef(%dimension);
1.19 albertel 1112: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 1113: $Apache::bridgetask::dimension=$dim_id;
1114: push(@Apache::bridgetask::dimensionlist,$dim_id);
1115: undef(@Apache::bridgetask::instance);
1.20 albertel 1116: $Apache::bridgetask::dimensionmandatory{$dim_id}=
1117: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 1118: return '';
1119: }
1120:
1.13 albertel 1121: sub get_instance {
1122: &Apache::response::pushrandomnumber();
1123: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29 albertel 1124: my $num=@order;
1125: my $version=&get_version();
1126: my $which=($version-1)%$num;
1127: return $order[$which];
1.13 albertel 1128: }
1129:
1.18 albertel 1130: {
1131: my $last_link;
1132: sub end_Dimension {
1133: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1134: my $result;
1.25 albertel 1135: my $dim=&get_id($parstack,$safeeval);
1.19 albertel 1136: my $instance=&get_instance();
1.25 albertel 1137: my $version=&get_version();
1.18 albertel 1138: if ($target eq 'web') {
1.47 albertel 1139: @Apache::scripttag::parser_env = @_;
1140: $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1141: @Apache::scripttag::parser_env = @_;
1142: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.26 albertel 1143: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
1144: $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 1145: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1146: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1147: my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.22 albertel 1148: $result.='<table border="1"><tr><td>';
1149: if ($status eq 'fail') {
1150: $result.='<font color="red">'.&mt('Did not pass').'</font>';
1151: } elsif ($status eq 'pass') {
1152: $result.='<font color="green">'.&mt('Passed').'</font>';
1153: } else {
1.49 albertel 1154: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
1.22 albertel 1155: }
1156: $result.='</td></tr><tr><td>';
1.25 albertel 1157: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
1158: $result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
1.22 albertel 1159: }
1160: $result.=$dimension{$instance.'.criteria.'.$id}.
1161: '</td></tr></table>';
1162: }
1163: }
1.18 albertel 1164: } elsif ($target eq 'webgrade') {
1.47 albertel 1165: # in case of any side effects that we need
1166: @Apache::scripttag::parser_env = @_;
1167: &Apache::scripttag::xmlparse($dimension{'intro'});
1168: @Apache::scripttag::parser_env = @_;
1169: &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.18 albertel 1170: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1171: my $link='criteria_'.$instance.'_'.$id;
1.25 albertel 1172: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19 albertel 1173: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 1174: '<a name="'.$link.'" />'.
1175: '<a name="next_'.$last_link.'" />'.
1.47 albertel 1176: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">';
1177: @Apache::scripttag::parser_env = @_;
1178: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
1179: $result.='</textarea>'.
1.18 albertel 1180: #$dimension{$instance.'.criteria.'.$id}.
1181: '</td>'.
1.19 albertel 1182: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25 albertel 1183: '<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 1184: '</td>'.
1185: '<td>'.
1.47 albertel 1186: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label></nobr><br />'.
1.30 albertel 1187: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
1188: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
1189: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18 albertel 1190: '</td>'.
1191: '<td>'.
1192: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 1193: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
1194: '<input type="submit" name="next" value="'.
1195: &mt('Done').'" /> '.
1.30 albertel 1196: '<input type="submit" name="stop" value="'.
1197: &mt('Stop').'" /> '.
1.18 albertel 1198: '</td></tr>';
1.22 albertel 1199: $result.='<tr><td colspan="4">';
1200: my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
1.52 ! albertel 1201: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.43 albertel 1202: foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"})) {
1.22 albertel 1203: my $file=$file_url.$partial_file;
1.52 ! albertel 1204: $file=~s|/+|/|g;
1.22 albertel 1205: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.48 albertel 1206: $result.='<nobr><a href="'.$file.'" target="lonGRDs"><img src="'.
1.22 albertel 1207: &Apache::loncommon::icon($file).'" border=0"> '.$file.
1.48 albertel 1208: '</a></nobr> ';
1.22 albertel 1209: }
1210: $result.='</td></tr>';
1.18 albertel 1211: $last_link=$link;
1212: }
1.22 albertel 1213: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 1214: my $optional_passed=0;
1.20 albertel 1215: my $mandatory_failed=0;
1216: my $ungraded=0;
1217: my $review=0;
1.19 albertel 1218: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1219: my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
1220: $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 1221: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1222: if ($status eq 'pass') {
1223: if (!$mandatory) { $optional_passed++; }
1224: } elsif ($status eq 'fail') {
1225: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 1226: } elsif ($status eq 'review') {
1227: $review++;
1.20 albertel 1228: } elsif ($status eq 'ungraded') {
1229: $ungraded++;
1.21 albertel 1230: } else {
1.47 albertel 1231: $ungraded++;
1.19 albertel 1232: }
1233: }
1.20 albertel 1234: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
1235: $mandatory_failed++;
1236: }
1.21 albertel 1237: &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 1238: if ($review) {
1.25 albertel 1239: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1240: 'review';
1.20 albertel 1241: } elsif ($ungraded) {
1.25 albertel 1242: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1243: 'ungraded';
1.20 albertel 1244: } elsif ($mandatory_failed) {
1.25 albertel 1245: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1246: 'fail';
1.20 albertel 1247: } else {
1.25 albertel 1248: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1249: 'pass';
1.20 albertel 1250: }
1.13 albertel 1251: }
1.18 albertel 1252: return $result;
1.1 albertel 1253: }
1254: }
1255:
1256: sub start_IntroParagraph {
1257: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1258: my $result;
1.13 albertel 1259: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1260: if ($tagstack->[-2] eq 'Dimension') {
1261: $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser);
1262:
1263: } elsif ($target eq 'webgrade') {
1264: &Apache::lonxml::get_all_text('/introparagraph',$parser);
1.1 albertel 1265: }
1.47 albertel 1266:
1.1 albertel 1267: }
1268: return $result;
1269: }
1270:
1271: sub end_IntroParagraph {
1272: }
1273:
1274: sub start_Instance {
1275: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 1276: my $id=&get_id($parstack,$safeeval);
1277: push(@{$dimension{'instances'}},$id);
1278: push(@Apache::bridgetask::instance,$id);
1279: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 1280: $dimension{$id.'.optionalrequired'}=
1.19 albertel 1281: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 1282: return '';
1283: }
1284:
1285: sub end_Instance {
1286: }
1287:
1288: sub start_InstanceText {
1289: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 albertel 1290: my $instance_id=$Apache::bridgetask::instance[-1];
1291: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser);
1.13 albertel 1292: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1293: $dimension{$instance_id.'.text'}=$text;
1.1 albertel 1294: }
1295: return '';
1296: }
1297:
1298: sub end_InstanceText {
1299: return '';
1300: }
1301:
1302: sub start_Criteria {
1303: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1304: my $instance_id=$Apache::bridgetask::instance[-1];
1.47 albertel 1305: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser);
1.21 albertel 1306: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19 albertel 1307: my $id=&get_id($parstack,$safeeval);
1.1 albertel 1308: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 1309: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
1310: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 1311: push(@{$dimension{$instance_id.'.criterias'}},$id);
1312: }
1313: return '';
1314: }
1315:
1.47 albertel 1316: sub end_Criteria {
1317: }
1318:
1.4 albertel 1319: sub proctor_validation_screen {
1320: my ($slot) = @_;
1321: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 1322: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 1323: my $name=&Apache::loncommon::plainname($user,$domain);
1324:
1.4 albertel 1325: my $msg;
1.11 albertel 1326: if ($env{'form.proctorpassword'}) {
1.4 albertel 1327: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
1328: .'</font></p>';
1329: }
1.47 albertel 1330: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 1331: my $result= (<<ENDCHECKOUT);
1332: <h2>Proctor Validation</h2>
1333: <p>Your room's proctor needs to validate your access to this resource.</p>
1334: $msg
1.11 albertel 1335: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 1336: <input type="hidden" name="validate" value="yes" />
1337: <input type="hidden" name="submitted" value="yes" />
1338: <table>
1.44 albertel 1339: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 1340: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 1341: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 1342: </table>
1343: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 1344: <table border="1">
1345: <tr><td>
1346: <table>
1347: <tr><td colspan="2">Student who should be logged in is:</td></tr>
1348: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 1349: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.44 albertel 1350: <tr><td>Usename</td><td>$user\@$domain</td></tr>
1351: <tr><td colspan="2"><img src="$url" /></td></tr>
1352: </table>
1353: </tr></td>
1354: </table>
1.4 albertel 1355: </form>
1356: ENDCHECKOUT
1357: return $result;
1358: }
1359:
1.1 albertel 1360: 1;
1361: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>