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