Annotation of loncom/homework/bridgetask.pm, revision 1.27
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.27 ! albertel 4: # $Id: bridgetask.pm,v 1.26 2005/05/19 21:28:06 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30:
31: package Apache::bridgetask;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::File();
36: use Apache::lonmenu;
37: use Apache::lonlocal;
38: use Apache::lonxml;
39: use Time::HiRes qw( gettimeofday tv_interval );
1.9 albertel 40:
1.1 albertel 41: BEGIN {
42: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
43: }
44:
1.9 albertel 45: sub initialize_bridgetask {
46: # id of current Dimension, 0 means that no dimension is current
47: # (inside <Task> only)
48: $Apache::bridgetask::dimension='';
49: # list of all Dimension ids seen
50: @Apache::bridgetask::dimensionlist=();
1.20 albertel 51: # mandatory attribute of all Dimensions seen
52: %Apache::bridgetask::dimensionmandatory=();
1.9 albertel 53: # list of all current Instance ids
54: @Apache::bridgetask::instance=();
55: # list of all Instance ids seen in this problem
56: @Apache::bridgetask::instancelist=();
1.15 albertel 57: # key of queud user data that we are currently grading
58: $Apache::bridgetask::queue_key='';
1.9 albertel 59: }
60:
1.4 albertel 61: sub proctor_check_auth {
1.22 albertel 62: my ($slot_name,$slot)=@_;
1.11 albertel 63: my $user=$env{'form.proctorname'};
64: my $domain=$env{'form.proctordomain'};
1.4 albertel 65:
66: my @allowed=split(",",$slot->{'proctor'});
67: foreach my $possible (@allowed) {
68: my ($puser,$pdom)=(split('@',$possible));
69: if ($puser eq $user && $pdom eq $domain) {
1.11 albertel 70: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4 albertel 71: if ($authhost ne 'no_host') {
1.23 albertel 72: my $version=
73: $Apache::lonhomework::results{'resource.version'}=
1.27 ! albertel 74: ++$Apache::lonhomework::history{'resource.version'};
1.23 albertel 75: $Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4 albertel 76: $user.'@'.$domain;
1.23 albertel 77: $Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22 albertel 78: $slot_name;
1.4 albertel 79: return 1;
80: }
81: }
82: }
83: return 0;
84: }
85:
1.25 albertel 86: sub get_version {
87: if ($env{'form.previousversion'} &&
88: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
89: return $env{'form.previousversion'};
90: }
91: return $Apache::lonhomework::history{'resource.version'};
92: }
93:
1.8 albertel 94: sub add_previous_version_button {
1.25 albertel 95: my ($status)=@_;
1.8 albertel 96: my $result;
1.25 albertel 97: if ($Apache::lonhomework::history{'resource.version'} eq '0') {
98: return '';
99: }
100: my $version=&get_version();
101: if ($version ne $Apache::lonhomework::history{'resource.version'}) {
102: return '';
103: }
104:
1.9 albertel 105: $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
1.8 albertel 106: <option>Pick one</option>
1.9 albertel 107: </select>');
1.8 albertel 108: return $result;
109: }
110:
1.13 albertel 111: sub add_grading_button {
112: my $result;
113: $result.=' <input type="submit" name="gradeasubmission" value="'.
114: &mt("Get a submission to grade").'" />';
115: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
116: return $result;
117: }
118:
1.22 albertel 119: sub add_request_another_attempt_button {
1.25 albertel 120: my $result;
121: $result.=' <input type="submit" name="requestattempt" value="'.
122: &mt("Request another attempt").'" />';
123: return $result;
1.22 albertel 124: }
125:
1.1 albertel 126: sub start_Task {
127: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
128:
1.4 albertel 129: my ($status,$accessmsg,$slot);
1.16 albertel 130: if ($target ne 'webgrade') {
131: &Apache::structuretags::initialize_storage();
132: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
133: }
134:
1.4 albertel 135: $Apache::lonhomework::parsing_a_task=1;
1.1 albertel 136: #should get back a <html> or the neccesary stuff to start XML/MathML
137: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
138: &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16 albertel 139:
1.8 albertel 140: if ($target eq 'web') {
1.13 albertel 141: if ($Apache::lonhomework::modifygrades) {
142: $body_tag_start.='<form name="gradesubmission" method="POST" action="';
143: my $uri=$env{'request.uri'};
144: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
145: $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
146: }
1.8 albertel 147: }
1.21 albertel 148: if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1 albertel 149: $target eq 'tex') {
1.25 albertel 150: my $version=&get_version();
1.14 albertel 151: ($status,$accessmsg,my $slot_name,$slot) =
1.4 albertel 152: &Apache::lonhomework::check_task_access('0');
1.9 albertel 153: push(@Apache::inputtags::status,$status);
1.14 albertel 154: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 155: my $expression='$external::datestatus="'.$status.'";';
1.23 albertel 156: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1 albertel 157: &Apache::run::run($expression,$safeeval);
158: &Apache::lonxml::debug("Got $status");
1.25 albertel 159: $body_tag_start.=&add_previous_version_button($status);
1.1 albertel 160: if (( $status eq 'CLOSED' ) ||
161: ( $status eq 'BANNED') ||
162: ( $status eq 'UNAVAILABLE') ||
1.3 albertel 163: ( $status eq 'NOT_IN_A_SLOT') ||
1.4 albertel 164: ( $status eq 'NEEDS_CHECKIN') ||
1.22 albertel 165: ( $status eq 'WAITING_FOR_GRADE') ||
1.1 albertel 166: ( $status eq 'INVALID_ACCESS')) {
167: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
168: if ( $target eq "web" ) {
1.4 albertel 169: $result.= $head_tag_start.'</head>'.$body_tag_start;
170: my $msg;
1.1 albertel 171: if ($status eq 'UNAVAILABLE') {
172: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 173: } elsif ($status eq 'NOT_IN_A_SLOT') {
174: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4 albertel 175: } elsif ($status eq 'NEEDS_CHECKIN') {
176: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
177: '</h1>'.&proctor_validation_screen($slot);
1.22 albertel 178: } elsif ($status eq 'WAITING_FOR_GRADE') {
179: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1 albertel 180: } elsif ($status ne 'NOT_YET_VIEWED') {
181: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
182: }
183: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
184: $msg.='The problem '.$accessmsg;
185: }
186: $result.=$msg.'<br />';
187: } elsif ($target eq 'tex') {
188: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
189: if ($status eq 'UNAVAILABLE') {
190: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
191: } else {
192: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
193: }
1.22 albertel 194: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 195: if ($status eq 'NEEDS_CHECKIN') {
1.22 albertel 196: if (&proctor_check_auth($slot_name,$slot)) {
1.4 albertel 197: #FIXME immeadiatly add this to the grading queue
198: # with slot->{'endtime'} for when grading can
199: # begin on this resource
1.22 albertel 200: # FIXME I think the above is done by default,
201: # need to check that
202: # failure doesn't do this.
1.4 albertel 203: }
204: }
1.1 albertel 205: }
206: } elsif ($target eq 'web') {
207: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
208: $result.="$head_tag_start<title>$name</title></head>
209: $body_tag_start \n $form_tag_start".
210: '<input type="hidden" name="submitted" value="yes" />';
211: # if we are viewing someone else preserve that info
1.11 albertel 212: if (defined $env{'form.grade_symb'}) {
1.1 albertel 213: foreach my $field ('symb','courseid','domain','username') {
214: $result .= '<input type="hidden" name="grade_'.$field.
1.11 albertel 215: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.1 albertel 216: }
217: }
1.25 albertel 218: my $version=&get_version();
219: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 220: $result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.25 albertel 221: $result.=&add_request_another_attempt_button();
1.22 albertel 222: }
1.25 albertel 223: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22 albertel 224: $result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
225: }
1.1 albertel 226: }
1.21 albertel 227: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
228: $target eq 'webgrade') {
229: if ($target eq 'webgrade') {
230: $result.=$head_tag_start.$body_tag_start.$form_tag_start;
231: $result.='<input type="hidden" name="webgrade" value="yes" />';
232: $result.=&show_queue();
233: }
1.15 albertel 234: my $todo=&get_from_queue();
235: if ($todo) {
1.16 albertel 236: &setup_env_for_other_user($todo,$safeeval);
1.15 albertel 237: my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.16 albertel 238: $result.="\n".'<table><tr><td>Found '.
239: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
1.15 albertel 240: $result.='<input type="hidden" name="gradingkey" value="'.
1.16 albertel 241: &Apache::lonnet::escape($todo).'" />';
1.15 albertel 242: $Apache::bridgetask::queue_key=$todo;
1.16 albertel 243: &Apache::structuretags::initialize_storage();
244: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.18 albertel 245: $result.="\n".'<table width="100%" style="width:100%" border="1">';
1.15 albertel 246: } else {
1.21 albertel 247: if ($target eq 'webgrade') {
248: $result.="\n".
249: '<table><tr><td>No user to be graded.</td></tr></table>';
250: }
1.15 albertel 251: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
252: }
1.1 albertel 253: } else {
254: # page_start returned a starting result, delete it if we don't need it
255: $result = '';
256: }
257: return $result;
258: }
259:
260: sub end_Task {
261: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
262: my $result='';
263: my $status=$Apache::inputtags::status['-1'];
1.25 albertel 264: my $version=&get_version();
1.1 albertel 265: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 266: $target eq 'tex') {
1.1 albertel 267: if (
1.11 albertel 268: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1 albertel 269: ($target eq 'answer') || ($target eq 'tex')
270: ) {
271: if ($target eq 'web') {
1.9 albertel 272: if ($status eq 'CAN_ANSWER') {
1.15 albertel 273: $result.="\n".'<table border="1">'.
1.27 ! albertel 274: &Apache::inputtags::file_selector('0',"bridgetask","*",
1.9 albertel 275: 'portfolioonly').
276: "</table>";
277: $result.=&Apache::inputtags::gradestatus('0');
278: }
1.13 albertel 279: }
280: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 281: $result.=&Apache::lonxml::xmlend().'</html>';
282: }
283: }
1.20 albertel 284: if ($target eq 'grade' && !$env{'form.webgrade'}) {
1.12 albertel 285: my $award='SUBMITTED';
1.20 albertel 286: &Apache::essayresponse::file_submission('0','bridgetask',
287: 'portfiles',\$award);
1.14 albertel 288: if ($award eq 'SUBMITTED' &&
1.23 albertel 289: $Apache::lonhomework::results{"resource.$version.bridgetask.portfiles"}) {
290: $Apache::lonhomework::results{"resource.$version.tries"}=
291: 1+$Apache::lonhomework::history{"resource.$version.tries"};
1.10 albertel 292: }
1.23 albertel 293: $Apache::lonhomework::results{"resource.$version.award"}=$award;
1.4 albertel 294: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
295: &Apache::structuretags::finalize_storage();
1.14 albertel 296: if ($award eq 'SUBMITTED') {
297: &add_to_queue();
298: }
1.1 albertel 299: }
1.20 albertel 300: if ($target eq 'grade' && $env{'form.webgrade'}) {
301: my $optional_required=
302: &Apache::lonxml::get_param('OptionalRequired',$parstack,
303: $safeeval);
304: my $optional_passed=0;
305: my $mandatory_failed=0;
306: my $ungraded=0;
307: my $review=0;
1.21 albertel 308: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 309: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
310: my $status=
1.25 albertel 311: $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20 albertel 312: my $mandatory=
313: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
314: if ($status eq 'pass') {
315: if (!$mandatory) { $optional_passed++; }
316: } elsif ($status eq 'fail') {
317: if ($mandatory) { $mandatory_failed++; }
318: } elsif ($status eq 'ungraded') {
319: $ungraded++;
320: } elsif ($status eq 'review') {
321: $review++;
322: }
323: }
324: if ($optional_passed < $optional_required) {
325: $mandatory_failed++;
326: }
1.21 albertel 327: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
328: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 329: $env{'user.name'}.'@'.$env{'user.domain'};
330: if ($review) {
1.25 albertel 331: $Apache::lonhomework::results{"resource.$version.status"}='review';
1.20 albertel 332: &move_to_review_queue();
333: } elsif ($ungraded) {
1.25 albertel 334: $Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.20 albertel 335: &check_queue_unlock();
336: } elsif ($mandatory_failed) {
1.25 albertel 337: $Apache::lonhomework::results{"resource.$version.status"}='fail';
338: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
339: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
340: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.20 albertel 341: &remove_from_queue();
342: } else {
1.25 albertel 343: $Apache::lonhomework::results{"resource.$version.status"}='pass';
344: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
345: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
346: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.20 albertel 347: &remove_from_queue();
348: }
1.26 albertel 349: $Apache::lonhomework::results{"resource.status"}=
350: $Apache::lonhomework::results{"resource.$version.status"};
351: if (defined($Apache::lonhomework::results{"resource.$version.awarded"})) {
352: $Apache::lonhomework::results{"resource.0.award"}=
353: $Apache::lonhomework::results{"resource.$version.award"};
354: $Apache::lonhomework::results{"resource.0.awarded"}=
355: $Apache::lonhomework::results{"resource.$version.awarded"};
356: $Apache::lonhomework::results{"resource.0.solved"}=
357: $Apache::lonhomework::results{"resource.$version.solved"};
1.25 albertel 358: }
1.21 albertel 359: &Apache::structuretags::finalize_storage();
1.20 albertel 360: }
1.15 albertel 361: } elsif ($target eq 'webgrade') {
1.18 albertel 362: $result.="</table>\n<hr />";
1.20 albertel 363: #$result.='<input type="submit" name="next" value="'.
364: # &mt('Save & Next').'" /> ';
365: #$result.='<input type="submit" name="end" value="'.
366: # &mt('Save & Stop Grading').'" /> ';
367: #$result.='<input type="submit" name="throwaway" value="'.
368: # &mt('Throw Away & Stop Grading').'" /> ';
369: #$result.='<input type="submit" name="save" value="'.
370: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 371: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 372: } elsif ($target eq 'meta') {
1.2 albertel 373: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 374: #$result.=&Apache::response::meta_part_order();
375: #$result.=&Apache::response::meta_response_order();
376: }
1.4 albertel 377: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 378: return $result;
379: }
380:
1.21 albertel 381: sub move_to_review_queue {
382: &Apache::lonxml::debug("Want to move");
383: }
384:
385: sub check_queue_unlock {
386: &Apache::lonxml::debug("Want to unlock?");
387: }
388:
389: sub remove_from_queue {
1.27 ! albertel 390: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
! 391: my $cnum=$env{'course.'.$cid.'.num'};
! 392: my $cdom=$env{'course.'.$cid.'.domain'};
! 393: my $key="$symb\0queue\0$uname\@$udom";
! 394: my @keys=($key,"$key\0locked");
! 395: &Apache::lonnet::del('gradingqueue',\@keys,$cdom,$cnum);
1.21 albertel 396: }
397:
1.16 albertel 398: sub setup_env_for_other_user {
399: my ($queue_key,$safeeval)=@_;
400: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
401: $env{'form.grade_symb'}=$symb;
402: $env{'form.grade_domain'}=$udom;
403: $env{'form.grade_username'}=$uname;
404: $env{'form.grade_courseid'}=$env{'request.course.id'};
405: &Apache::lonxml::initialize_rndseed($safeeval);
406: }
407:
1.14 albertel 408: sub add_to_queue {
409: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
410: my $cnum=$env{'course.'.$cid.'.num'};
411: my $cdom=$env{'course.'.$cid.'.domain'};
412: my %data;
413: $data{"$symb\0queue\0$uname\@$udom"}=[$Apache::inputtags::slot_name];
414: &Apache::lonnet::put('gradingqueue',\%data,$cdom,$cnum);
415: }
416:
417: sub show_queue {
418: my $result;
419: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
420: my $cnum=$env{'course.'.$cid.'.num'};
421: my $cdom=$env{'course.'.$cid.'.domain'};
1.16 albertel 422: my $regexp="^$symb\0";
1.14 albertel 423: my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
1.27 ! albertel 424: $result.="\n<h3>Current Queue</h3><table border='1'><tr><th>resource</th>".
1.20 albertel 425: "<th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 426: foreach my $key (sort(keys(%queue))) {
1.16 albertel 427: if ($key=~/locked$/) {
428: my ($symb,$uname,$udom) = &decode_queue_key($key);
429: my $title=&Apache::lonnet::gettitle($symb);
1.27 ! albertel 430: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 431: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
432: } elsif ($key=~/timestamp$/) {
433: my ($symb,undef) = split("\0",$key);
434: my $title=&Apache::lonnet::gettitle($symb);
1.27 ! albertel 435: $result.="<tr><td>$title</td><td></td>";
1.16 albertel 436: $result.='<td>last queue modification time</td><td>'.
437: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
438: } else {
439: my ($symb,$uname,$udom) = &decode_queue_key($key);
440: my $title=&Apache::lonnet::gettitle($symb);
1.27 ! albertel 441: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 442: my $slot=$queue{$key}->[0];
443: my %slot_data=&Apache::lonnet::get_slot($slot);
1.27 ! albertel 444: $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20 albertel 445: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
446: "</td></tr>";
1.16 albertel 447: }
1.14 albertel 448: }
1.15 albertel 449: $result.="</table><hr />\n";
1.14 albertel 450: return $result;
451: }
452:
453: sub decode_queue_key {
454: my ($key)=@_;
455: my ($symb,undef,$user) = split("\0",$key);
456: my ($uname,$udom) = split('@',$user);
457: return ($symb,$uname,$udom);
458: }
459:
460: sub queue_key_locked {
1.15 albertel 461: my ($key,$cdom,$cnum)=@_;
1.14 albertel 462: my ($key_locked,$value)=
463: &Apache::lonnet::get('gradingqueue',["$key\0locked"],$cdom,$cnum);
464: if ($key_locked eq "$key\0locked") {
465: return $value;
466: }
467: return undef;
468: }
469:
470: sub pick_from_queue_data {
1.15 albertel 471: my ($check_section,$queue,$cdom,$cnum)=@_;
1.16 albertel 472: foreach my $key (keys(%$queue)) {
1.14 albertel 473: my ($symb,$uname,$udom)=&decode_queue_key($key);
474: if ($check_section) {
475: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 476: if ($section eq $check_section) {
477: &Apache::lonnet::logthis("my sec");
1.15 albertel 478: next;
479: }
1.14 albertel 480: }
481: my $slot=$queue->{$key}[0];
482: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 483: if ($slot_data{'endtime'} > time) {
484: &Apache::lonnet::logthis("not time");
485: next;
486: }
487: if (&queue_key_locked($key,$cdom,$cnum)) {
488: &Apache::lonnet::logthis("someone already has um.");
489: next;
490: }
1.14 albertel 491: return $key;
492: }
493: return undef;
494: }
495:
1.15 albertel 496: sub find_mid_grade {
497: my ($symb,$cdom,$cnum)=@_;
1.16 albertel 498: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 499: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
500: if ($todo) {
501: my $who=&queue_key_locked($todo,$cdom,$cnum);
502: if ($who eq $me) { return $todo; }
503: }
504: my $regexp="^$symb\0.*\0locked\$";
505: my %locks=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
506: foreach my $key (keys(%locks)) {
507: my $who=$locks{$key};
508: if ($who eq $me) {
509: $todo=$key;
510: $todo=~s/\0locked$//;
511: return $todo;
512: }
513: }
514: return undef;
515: }
516:
1.14 albertel 517: sub get_from_queue {
518: my $result;
519: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
520: my $cnum=$env{'course.'.$cid.'.num'};
521: my $cdom=$env{'course.'.$cid.'.domain'};
522: my $todo;
1.15 albertel 523: # FIXME need to find if I am 'mid grading'
524: $todo=&find_mid_grade($symb,$cdom,$cnum);
525: &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 526: if ($todo) { return $todo; }
1.14 albertel 527: while (1) {
528: my $starttime=time;
529: &Apache::lonnet::put('gradingqueue',{"$symb\0timestamp"=>$starttime},
530: $cdom,$cnum);
1.15 albertel 531: &Apache::lonnet::logthis("$starttime");
1.14 albertel 532: my $regexp="^$symb\0queue\0";
533: my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
534: #make a pass looking for a user in my section
535: if ($env{'request.course.sec'}) {
1.15 albertel 536: &Apache::lonnet::logthis("sce");
537: $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
538: $cdom,$cnum);
539: &Apache::lonnet::logthis("sce $todo");
1.14 albertel 540: }
541: # no one in our section so look for any user that is ready for grading
542: if (!$todo) {
1.15 albertel 543: &Apache::lonnet::logthis("no sce");
544: $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
545: $cdom,$cnum);
546: &Apache::lonnet::logthis("no sce $todo");
1.14 albertel 547: }
548: # no user to grade
549: if (!$todo) { last; }
1.15 albertel 550: &Apache::lonnet::logthis("got $todo");
1.14 albertel 551: # otherwise found someone so lets try to lock them
552: my $success=&Apache::lonnet::newput('gradingqueue',
553: {"$todo\0locked"=>
554: $env{'user.name'}.'@'.$env{'user.domain'}},
555: $cdom,$cnum);
556: # someone else already picked them
1.15 albertel 557: &Apache::lonnet::logthis("success $todo");
1.14 albertel 558: if ($success ne 'ok') { next; }
559: my (undef,$endtime)=
560: &Apache::lonnet::get('gradingqueue',["$symb\0timestamp"],
561: $cdom,$cnum);
1.15 albertel 562: &Apache::lonnet::logthis("emd $endtime");
1.14 albertel 563: # someone else already modified the queue,
564: # perhaps our picked user wass already fully graded between
565: # when we picked him and when we locked his record? so lets
566: # double check.
567: if ($endtime != $starttime) {
568: my ($key,$value)=
569: &Apache::lonnet::get('gradingqueue',["$todo"],
570: $cdom,$cnum);
1.15 albertel 571: &Apache::lonnet::logthis("check $key .. $value");
1.14 albertel 572: if ($key eq $todo && ref($value)) {
573: } else {
574: &Apache::lonnet::del('gradingqueue',["$todo\0locked"],
575: $cdom,$cnum);
1.15 albertel 576: &Apache::lonnet::logthis("del");
1.14 albertel 577: next;
578: }
579: }
1.15 albertel 580: &Apache::lonnet::logthis("last $todo");
1.14 albertel 581: last;
582: }
583: return $todo;
584: }
585:
1.1 albertel 586: sub start_ClosingParagraph {
587: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
588: my $result;
589: if ($target eq 'web') {
1.13 albertel 590: } elsif ($target eq 'webgrade') {
591: &Apache::lonxml::startredirection();
1.1 albertel 592: }
593: return $result;
594: }
595:
596: sub end_ClosingParagraph {
597: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
598: my $result;
599: if ($target eq 'web') {
1.13 albertel 600: } elsif ($target eq 'webgrade') {
601: &Apache::lonxml::endredirection();
1.1 albertel 602: }
603: return $result;
604: }
605:
1.19 albertel 606: sub get_id {
607: my ($parstack,$safeeval)=@_;
608: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
609: if (!$id) { $id=$Apache::lonxml::curdepth; }
610: return $id;
611: }
612:
1.1 albertel 613: my %dimension;
614: sub start_Dimension {
615: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
616: undef(%dimension);
1.19 albertel 617: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 618: $Apache::bridgetask::dimension=$dim_id;
619: push(@Apache::bridgetask::dimensionlist,$dim_id);
620: undef(@Apache::bridgetask::instance);
1.20 albertel 621: $Apache::bridgetask::dimensionmandatory{$dim_id}=
622: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 623: return '';
624: }
625:
1.13 albertel 626: sub get_instance {
627: #FIXME just grabbing the first one for now, need
628: #to randomly pick one until all have been seen
629: #then start repicking
630: &Apache::response::pushrandomnumber();
631: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
632: return $order[0];
633: }
634:
1.18 albertel 635: {
636: my $last_link;
637: sub end_Dimension {
638: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
639: my $result;
1.25 albertel 640: my $dim=&get_id($parstack,$safeeval);
1.19 albertel 641: my $instance=&get_instance();
1.25 albertel 642: my $version=&get_version();
1.18 albertel 643: if ($target eq 'web') {
644: $result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.26 albertel 645: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
646: $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 647: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 648: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
649: my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.22 albertel 650: $result.='<table border="1"><tr><td>';
651: if ($status eq 'fail') {
652: $result.='<font color="red">'.&mt('Did not pass').'</font>';
653: } elsif ($status eq 'pass') {
654: $result.='<font color="green">'.&mt('Passed').'</font>';
655: } else {
656: &Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
657: }
658: $result.='</td></tr><tr><td>';
1.25 albertel 659: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
660: $result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
1.22 albertel 661: }
662: $result.=$dimension{$instance.'.criteria.'.$id}.
663: '</td></tr></table>';
664: }
665: }
1.18 albertel 666: } elsif ($target eq 'webgrade') {
667: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
668: my $link='criteria_'.$instance.'_'.$id;
1.25 albertel 669: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19 albertel 670: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 671: '<a name="'.$link.'" />'.
672: '<a name="next_'.$last_link.'" />'.
673: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">'.$dimension{$instance.'.criteria.'.$id}.'</textarea>'.
674: #$dimension{$instance.'.criteria.'.$id}.
675: '</td>'.
1.19 albertel 676: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25 albertel 677: '<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 678: '</td>'.
679: '<td>'.
1.20 albertel 680: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>Ungraded</label></nobr><br />'.
681: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />Pass</label><br />'.
682: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />Fail</label><br />'.
683: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />Review</label><br />'.
1.18 albertel 684: '</td>'.
685: '<td>'.
686: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 687: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
688: '<input type="submit" name="next" value="'.
689: &mt('Done').'" /> '.
1.18 albertel 690: '</td></tr>';
1.22 albertel 691: $result.='<tr><td colspan="4">';
692: my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
693: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
1.23 albertel 694: foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.bridgetask.portfiles"})) {
1.22 albertel 695: my $file=$file_url.$partial_file;
696: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
697: $result.='<a href="'.$file.'" target="lonGRDs"><img src="'.
698: &Apache::loncommon::icon($file).'" border=0"> '.$file.
699: '</a>';
700: }
701: $result.='</td></tr>';
1.18 albertel 702: $last_link=$link;
703: }
1.22 albertel 704: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 705: my $optional_passed=0;
1.20 albertel 706: my $mandatory_failed=0;
707: my $ungraded=0;
708: my $review=0;
1.19 albertel 709: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 710: my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
711: $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 712: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
713: if ($status eq 'pass') {
714: if (!$mandatory) { $optional_passed++; }
715: } elsif ($status eq 'fail') {
716: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 717: } elsif ($status eq 'review') {
718: $review++;
1.20 albertel 719: } elsif ($status eq 'ungraded') {
720: $ungraded++;
1.21 albertel 721: } else {
1.22 albertel 722: &Apache::lonxml::error("got weird status --$status--");
1.19 albertel 723: }
724: }
1.20 albertel 725: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
726: $mandatory_failed++;
727: }
1.21 albertel 728: &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 729: if ($review) {
1.25 albertel 730: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 731: 'review';
1.20 albertel 732: } elsif ($ungraded) {
1.25 albertel 733: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 734: 'ungraded';
1.20 albertel 735: } elsif ($mandatory_failed) {
1.25 albertel 736: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 737: 'fail';
1.20 albertel 738: } else {
1.25 albertel 739: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 740: 'pass';
1.20 albertel 741: }
1.13 albertel 742: }
1.18 albertel 743: return $result;
1.1 albertel 744: }
745: }
746:
747: sub start_IntroParagraph {
748: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
749: my $result;
1.13 albertel 750: if ($target eq 'web' || $target eq 'webgrade') {
751: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 752: &Apache::lonxml::startredirection();
753: }
754: }
755: return $result;
756: }
757:
758: sub end_IntroParagraph {
759: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
760: my $result;
1.13 albertel 761: if ($target eq 'web' || $target eq 'webgrade') {
762: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 763: $dimension{'intro'}=&Apache::lonxml::endredirection();
764: }
765: }
766: return $result;
767: }
768:
769: sub start_Instance {
770: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 771: my $id=&get_id($parstack,$safeeval);
772: push(@{$dimension{'instances'}},$id);
773: push(@Apache::bridgetask::instance,$id);
774: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 775: $dimension{$id.'.optionalrequired'}=
1.19 albertel 776: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 777: return '';
778: }
779:
780: sub end_Instance {
781: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
782: return '';
783: }
784:
785: sub start_InstanceText {
786: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13 albertel 787: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 788: &Apache::lonxml::startredirection();
789: }
790: return '';
791: }
792:
793: sub end_InstanceText {
794: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 795: my $instance_id=$Apache::bridgetask::instance[-1];
1.13 albertel 796: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 797: $dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
798: }
799: return '';
800: }
801:
802: sub start_Criteria {
803: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.21 albertel 804: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 805: &Apache::lonxml::startredirection();
806: }
807: return '';
808: }
809:
810: sub end_Criteria {
811: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 812: my $instance_id=$Apache::bridgetask::instance[-1];
1.21 albertel 813: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 814: my $criteria=&Apache::lonxml::endredirection();
1.19 albertel 815: my $id=&get_id($parstack,$safeeval);
1.1 albertel 816: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 817: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
818: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 819: push(@{$dimension{$instance_id.'.criterias'}},$id);
820: }
821: return '';
822: }
823:
1.4 albertel 824: sub proctor_validation_screen {
825: my ($slot) = @_;
826: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 827: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11 albertel 828: $user=$env{'form.proctorname'};
829: if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4 albertel 830: my $msg;
1.11 albertel 831: if ($env{'form.proctorpassword'}) {
1.4 albertel 832: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
833: .'</font></p>';
834: }
835: my $result= (<<ENDCHECKOUT);
836: <h2>Proctor Validation</h2>
837: <p>Your room's proctor needs to validate your access to this resource.</p>
838: $msg
1.11 albertel 839: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 840: <input type="hidden" name="validate" value="yes" />
841: <input type="hidden" name="submitted" value="yes" />
842: <table>
843: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
844: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6 albertel 845: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4 albertel 846: </table>
847: <input type="submit" name="checkoutbutton" value="Validate" /><br />
848: Student who should be logged in is:<br />
1.5 albertel 849: <img src="$url" /><br />
1.4 albertel 850: </form>
851: ENDCHECKOUT
852: return $result;
853: }
854:
1.1 albertel 855: 1;
856: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>