Annotation of loncom/homework/bridgetask.pm, revision 1.62
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.62 ! albertel 4: # $Id: bridgetask.pm,v 1.61 2005/10/01 04:01:14 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.59 albertel 147: my (undef,$cid)=&Apache::lonxml::whichuser();
148: my $cnum=$env{'course.'.$cid.'.num'};
149: my $cdom=$env{'course.'.$cid.'.domain'};
150: my %sections;
151: my $numsections=&Apache::loncommon::get_sections($cdom,$cnum,\%sections);
152: my $size=5;
153: if (scalar(keys(%sections)) < 3) {
154: $size=scalar(keys(%sections))+2;
155: }
156: my $sec_select = '<select multiple name="chosensections" size="'.$size.'">'."\n";
157: $sec_select .= "<option value='all' selected='selected'>all</option>\n";
158: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
159: $sec_select .= "<option name=\"$sec\">$sec</option>\n";
160: }
161: $sec_select .= "<option value='none'>none</option></select>\n";
162:
1.29 albertel 163: my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13 albertel 164: &mt("Get a submission to grade").'" />';
165: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40 albertel 166: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34 albertel 167: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.59 albertel 168: $result.='<p>Specify a section: '.$sec_select.'</p>';
1.34 albertel 169: $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);
170:
171: $result.=' <input type="submit" name="reviewagrading" value="'.
172: &mt("Select an entry from the grading queue").'" /> </p>'."\n";
173:
174: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
175: $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 176: $result.=' <input type="submit" name="reviewasubmission" value="'.
1.34 albertel 177: &mt("Select an entry from the review queue").'" /> </p>'."\n";
1.49 albertel 178: $result.=' <input type="submit" name="regradeasubmission" value="'.
179: &mt("Select a user to regrade.").'" /> </p>'."\n";
1.32 albertel 180: }
1.13 albertel 181: return $result;
182: }
183:
1.22 albertel 184: sub add_request_another_attempt_button {
1.38 albertel 185: my ($text)=@_;
186: if (!$text) { $text="Request another attempt"; }
1.25 albertel 187: my $result;
1.36 albertel 188: my $symb=&Apache::lonnet::symbread();
1.37 albertel 189: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38 albertel 190: my $action='get_reservation';
1.37 albertel 191: if ($slot_name) {
1.38 albertel 192: $text="Change reservation.";
193: $action='change_reservation';
1.37 albertel 194: my $description=&Apache::slotrequest::get_description($slot_name,
195: $slot);
196: $result.=(<<STUFF);
197: <p> Will be next available: $description </p>
198: STUFF
199: }
1.38 albertel 200:
201: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
202: $symb=&Apache::lonnet::escape($symb);
203: $result.='<form method="POST" action="/adm/slotrequest">'.
204: '<input type="hidden" name="symb" value="'.$symb.'" />'.
205: '<input type="hidden" name="command" value="'.$action.'" />'.
206: '<input type="submit" name="requestattempt" value="'.
207: &mt($text).'" />'.
208: '</form>';
1.25 albertel 209: return $result;
1.22 albertel 210: }
211:
1.30 albertel 212: sub preserve_grade_info {
213: my $result;
214: # if we are viewing someone else preserve that info
215: if (defined $env{'form.grade_symb'}) {
216: foreach my $field ('symb','courseid','domain','username') {
217: $result .= '<input type="hidden" name="grade_'.$field.
218: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
219: }
220: }
221: return $result;
222: }
223:
1.53 albertel 224: sub style {
225: return (<<STYLE);
226: <style type="text/css">
227: .fail, .pass, .neutral {
228: position: relative;
229: margin : 5px;
230: margin-bottom :10px;
231: padding : 4px;
232: padding-left : 75px;
233: border : thin solid;
234: font-weight : bolder;
235: font-size: smaller;
236: font-family: Arial;
237: background-color : rgb(255,240,225);
238: }
239:
240: .fail h4, .pass h4 {
241: position:absolute;
242: left: -4px;
243: top: -8px;
244: padding:2px;
245: margin:0;
246: background-color : rgb(255,240,225);
247: border : thin solid;
248: }
249:
250: .fail {
251: color: red;
252: }
253:
254: .pass {
255: color : green;
256: }
257:
258: .neutral {
259: color : blue;
260: }
261:
262: .question {
263: border : thin solid black;
264: padding : 4px;
265: margin-bottom : 1em;
266: }
267:
268: .grade {
269: font-size: x-large;
270: font-family: Arial;
271: position:absolute;
272: left: 5px;
273: top: -5px;
274: width: 70px;
275: }
276:
277: div#feedback h1 {
278: color : inherit;
279: }
280: </style>
281: STYLE
282:
283: }
284:
1.54 albertel 285: sub show_task {
286: my ($status,$previous)=@_;
287: if (!$previous && (
288: ( $status eq 'CLOSED' ) ||
289: ( $status eq 'BANNED') ||
290: ( $status eq 'UNAVAILABLE') ||
291: ( $status eq 'NOT_IN_A_SLOT') ||
292: ( $status eq 'NEEDS_CHECKIN') ||
293: ( $status eq 'WAITING_FOR_GRADE') ||
294: ( $status eq 'INVALID_ACCESS') )) {
295: return 0;
296: }
297: return 1;
298: }
299:
300: sub internal_location {
301: my ($id)=@_;
302: return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
303: }
304:
1.60 albertel 305: sub submission_time_stamp {
306: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
307: my $submissiontime;
308: my $version=$Apache::lonhomework::history{'resource.version'};
309: for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
310: if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
311: $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
312: }
313: }
314: my $result;
315: if ($submissiontime) {
316: my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.checkedin.slot'};
317: my %slot=&Apache::lonnet::get_slot($slot_name);
318: my $diff = $slot{'endtime'} - $submissiontime;
319: my ($color,$when)=('red','after');
320: if ($diff > 0) { ($color,$when)=('green','before'); }
321: my $info;
322: if ($diff%60) { $info=($diff%60).' seconds'; }
323: $diff=int($diff/60);
324: if ($diff%60) { $info=($diff%60).' minutes '.$info; }
325: $diff=int($diff/60);
326: if ($diff) { $info=$diff.' hours '.$info; }
327: $result='<p><font color="'.$color.'">'.
328: &mt('Student submitted [_1] [_2] the deadline.
329: (Submission was at [_3], end of period was [_4].)',
330: $info,$when,scalar(localtime($submissiontime)),
331: scalar(localtime($slot{'endtime'}))).
332: '</font></p>';
333: }
334: return $result;
335: }
336:
1.1 albertel 337: sub start_Task {
338: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
339:
1.4 albertel 340: my ($status,$accessmsg,$slot);
1.16 albertel 341: if ($target ne 'webgrade') {
342: &Apache::structuretags::initialize_storage();
343: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
344: }
345:
1.4 albertel 346: $Apache::lonhomework::parsing_a_task=1;
1.1 albertel 347: #should get back a <html> or the neccesary stuff to start XML/MathML
348: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
349: &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16 albertel 350:
1.8 albertel 351: if ($target eq 'web') {
1.13 albertel 352: if ($Apache::lonhomework::modifygrades) {
353: $body_tag_start.='<form name="gradesubmission" method="POST" action="';
354: my $uri=$env{'request.uri'};
355: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
356: $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
1.38 albertel 357: my $symb=&Apache::lonnet::symbread();
1.40 albertel 358: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
359: $body_tag_start.='<form method="POST" action="/adm/slotrequest">'.
360: '<input type="hidden" name="symb" value="'.$symb.'" />'.
361: '<input type="hidden" name="command" value="showslots" />'.
362: '<input type="submit" name="requestattempt" value="'.
363: &mt('Show Slot list').'" />'.
364: '</form>';
365: }
1.13 albertel 366: }
1.8 albertel 367: }
1.21 albertel 368: if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1 albertel 369: $target eq 'tex') {
1.29 albertel 370: my ($version,$previous)=&get_version();
1.14 albertel 371: ($status,$accessmsg,my $slot_name,$slot) =
1.4 albertel 372: &Apache::lonhomework::check_task_access('0');
1.9 albertel 373: push(@Apache::inputtags::status,$status);
1.14 albertel 374: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 375: my $expression='$external::datestatus="'.$status.'";';
1.23 albertel 376: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1 albertel 377: &Apache::run::run($expression,$safeeval);
378: &Apache::lonxml::debug("Got $status");
1.25 albertel 379: $body_tag_start.=&add_previous_version_button($status);
1.54 albertel 380: if (!&show_task($status,$previous)) {
1.1 albertel 381: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
382: if ( $target eq "web" ) {
1.4 albertel 383: $result.= $head_tag_start.'</head>'.$body_tag_start;
384: my $msg;
1.1 albertel 385: if ($status eq 'UNAVAILABLE') {
386: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 387: } elsif ($status eq 'NOT_IN_A_SLOT') {
388: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38 albertel 389: $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4 albertel 390: } elsif ($status eq 'NEEDS_CHECKIN') {
391: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
392: '</h1>'.&proctor_validation_screen($slot);
1.22 albertel 393: } elsif ($status eq 'WAITING_FOR_GRADE') {
394: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1 albertel 395: } elsif ($status ne 'NOT_YET_VIEWED') {
396: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
397: }
398: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
399: $msg.='The problem '.$accessmsg;
400: }
401: $result.=$msg.'<br />';
402: } elsif ($target eq 'tex') {
403: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
404: if ($status eq 'UNAVAILABLE') {
405: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
406: } else {
407: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
408: }
1.22 albertel 409: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 410: if ($status eq 'NEEDS_CHECKIN') {
1.41 albertel 411: &proctor_check_auth($slot_name,$slot);
1.4 albertel 412: }
1.1 albertel 413: }
414: } elsif ($target eq 'web') {
415: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
416: $result.="$head_tag_start<title>$name</title></head>
1.53 albertel 417: $body_tag_start \n".&style();
1.36 albertel 418:
1.57 albertel 419: $result.=&preserve_grade_info();
420: $result.=&internal_location();
1.36 albertel 421: $result.=$form_tag_start.
422: '<input type="hidden" name="submitted" value="yes" />';
1.54 albertel 423: &Apache::lonxml::startredirection();
1.1 albertel 424: }
1.21 albertel 425: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
426: $target eq 'webgrade') {
1.32 albertel 427: my $webgrade='yes';
1.21 albertel 428: if ($target eq 'webgrade') {
1.32 albertel 429: $result.=$head_tag_start.$body_tag_start;
1.49 albertel 430: #$result.='<br />Review'.&show_queue('reviewqueue');
431: #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 432: }
1.33 albertel 433: # FIXME Blast! still need to reorg this, need to reshow the
434: # queue being reviewed once done with the grade pass...
435: # Hrrm, vaildation pass should perhaps say 'not_locked'
436: # perhaps do a search if there is a key that is mine and if
437: # there isn't reshow the queue....
438: my ($todo,$status_code)=&get_key_todo($target);
439:
440: if ($todo) {
441: &setup_env_for_other_user($todo,$safeeval);
442: my ($symb,$uname,$udom)=&decode_queue_key($todo);
443: $result.="\n".'<table><tr><td>Found '.
444: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
445: $form_tag_start.=
446: '<input type="hidden" name="gradingkey" value="'.
447: &Apache::lonnet::escape($todo).'" />';
448: $Apache::bridgetask::queue_key=$todo;
449: &Apache::structuretags::initialize_storage();
450: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
451: if ($target eq 'webgrade') {
1.49 albertel 452: #$result.='<br />After -'.&show_queue($env{'form.queue'});
1.33 albertel 453: $result.="\n".'<table width="100%" style="width:100%" border="1">';
454: if ($status_code eq 'selected') {
455: $form_tag_start.=
456: '<input type="hidden" name="queuemode" value="selected" />';
457: }
458: }
1.15 albertel 459: } else {
1.33 albertel 460: if ($target eq 'webgrade') {
461: $result.="\n";
462: if ($status_code eq 'stop') {
463: $result.='<b>'.&mt("Stopped grading.").'</b>';
464: } elsif ($status_code eq 'lock_failed') {
465: $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
466: } elsif ($status_code eq 'unlock') {
467: $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
468: $result.=&show_queue($env{'form.queue'},1);
469: } elsif ($status_code eq 'show_list') {
470: $result.=&show_queue($env{'form.queue'},1);
1.49 albertel 471: } elsif ($status_code eq 'select_user') {
472: $result.=&select_user();
1.33 albertel 473: } else {
474: $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32 albertel 475: }
1.21 albertel 476: }
1.33 albertel 477: $webgrade='no';
478: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32 albertel 479: }
480: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61 albertel 481: if ($webgrade eq 'yes') {
482: $result.=&submission_time_stamp();
483: }
1.32 albertel 484: $result.=$form_tag_start;
485: $result.='<input type="hidden" name="webgrade" value="'.
486: $webgrade.'" />';
487: $result.='<input type="hidden" name="queue" value="'.
488: $env{'form.queue'}.'" />';
1.52 albertel 489: if ($env{'form.regrade'}) {
490: $result.='<input type="hidden" name="regrade" value="'.
491: $env{'form.regrade'}.'" />';
492: }
1.62 ! albertel 493: if ($env{'form.chosensections'}) {
! 494: my @chosen_sections=
! 495: &Apache::loncommon::get_env_multiple('form.chosensections');
! 496: foreach my $sec (@chosen_sections) {
! 497: $result.='<input type="hidden" name="chosensections"
! 498: value="'.$sec.'" />';
! 499: }
! 500: }
1.15 albertel 501: }
1.1 albertel 502: } else {
503: # page_start returned a starting result, delete it if we don't need it
504: $result = '';
505: }
506: return $result;
507: }
508:
1.32 albertel 509: sub get_key_todo {
510: my ($target)=@_;
511: my $todo;
1.33 albertel 512:
513: if (defined($env{'form.reviewasubmission'})) {
1.54 albertel 514: &Apache::lonxml::debug("review a submission....");
1.33 albertel 515: $env{'form.queue'}='reviewqueue';
516: return (undef,'show_list');
517: }
518:
519: if (defined($env{'form.reviewagrading'})) {
520: &Apache::lonxml::debug("review a grading....");
521: $env{'form.queue'}='gradingqueue';
522: return (undef,'show_list');
523: }
524:
1.49 albertel 525: if (defined($env{'form.regradeasubmission'})) {
526: &Apache::lonxml::debug("regrade a grading....");
527: $env{'form.queue'}='none';
528: return (undef,'select_user');
529: }
530:
1.32 albertel 531: my $queue=$env{'form.queue'};
1.33 albertel 532:
1.32 albertel 533: if (!defined($queue)) {
534: $env{'form.queue'}=$queue='gradingqueue';
535: }
1.33 albertel 536:
1.32 albertel 537: my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33 albertel 538:
1.49 albertel 539: if ($env{'form.queue'} eq 'none') {
540: if (defined($env{'form.gradingkey'})) {
541: if ($target eq 'webgrade') {
542: if ($env{'form.stop'}) {
543: return (undef,'stop');
544: } elsif ($env{'form.next'}) {
1.59 albertel 545: return (undef,'select_user');
1.49 albertel 546: }
547: }
548: return ($gradingkey,'selected');
549: } else {
1.59 albertel 550: return (undef,'select_user');
1.49 albertel 551: }
552: }
1.32 albertel 553: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 albertel 554: && !defined($env{'form.gradingaction'})
555: && $env{'form.queuemode'} eq 'selected') {
556:
557: my $who=&queue_key_locked($queue,$gradingkey);
558: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
559: if ($who eq $me) {
560: &Apache::lonxml::debug("Found a key was given to me");
561: return ($gradingkey,'selected');
562: } else {
563: return (undef,'show_list');
564: }
565:
566: }
567:
568: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
569: if ($env{'form.gradingaction'} eq 'resume') {
570: delete($env{'form.gradingaction'});
571: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 572: return ($gradingkey);
1.33 albertel 573: } elsif ($env{'form.gradingaction'} eq 'unlock') {
574: &Apache::lonxml::debug("Unlocking a key ".
575: &check_queue_unlock($queue,$gradingkey,1));
576: return (undef,'unlock');
577: } elsif ($env{'form.gradingaction'} eq 'select') {
578: &Apache::lonxml::debug("Locking a key");
579: if (&lock_key($queue,$gradingkey)) {
580: &Apache::lonxml::debug("Success $queue");
581: return ($gradingkey);
582: }
583: &Apache::lonxml::debug("Failed $queue");
584: return (undef,'lock_failed');
1.32 albertel 585: }
586: }
1.33 albertel 587:
588: if ($env{'form.queuemode'} ne 'selected') {
589: # don't get something new from the queue if they hit the stop button
590: if (!($env{'form.stop'} && $target eq 'webgrade')
591: && !$env{'form.gradingaction'}) {
592: &Apache::lonxml::debug("Getting anew $queue");
593: return (&get_from_queue($queue));
594: } else {
595: return (undef,'stop');
596: }
1.32 albertel 597: }
1.33 albertel 598: return (undef,undef)
1.32 albertel 599: }
600:
1.1 albertel 601: sub end_Task {
602: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
603: my $result='';
604: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 605: my ($version,$previous)=&get_version();
1.1 albertel 606: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 607: $target eq 'tex') {
1.1 albertel 608: if (
1.11 albertel 609: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1 albertel 610: ($target eq 'answer') || ($target eq 'tex')
611: ) {
612: if ($target eq 'web') {
1.54 albertel 613: if (&show_task($status,$previous)) {
614: $result.=&Apache::lonxml::endredirection();
615: }
1.29 albertel 616: if ($status eq 'CAN_ANSWER' && !$previous) {
1.15 albertel 617: $result.="\n".'<table border="1">'.
1.28 albertel 618: &Apache::inputtags::file_selector("$version.0",
619: "bridgetask","*",
1.46 albertel 620: 'portfolioonly',
621: '
622: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
623: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9 albertel 624: "</table>";
625: $result.=&Apache::inputtags::gradestatus('0');
626: }
1.56 albertel 627: if (&show_task($status,$previous) &&
628: $Apache::lonhomework::history{"resource.$version.status"} =~ /^(pass|fail)$/) {
1.54 albertel 629: my $bt_status=$Apache::lonhomework::history{"resource.$version.status"};
630: my $title=&Apache::lonnet::gettitle();
631: my %slot=&Apache::lonnet::get_slot($Apache::inputtags::slot_name);
1.55 albertel 632: my $start_time=
633: &Apache::lonlocal::locallocaltime($slot{'starttime'});
1.54 albertel 634:
635: my $status;
636: $status.="\n<div class='$bt_status'>\n";
637:
638: if ($bt_status eq 'pass') {
639: $status.='<h2>You passed the '.$title.' given on '.
1.55 albertel 640: $start_time.'.</h2>';
1.54 albertel 641: }
642: if ($bt_status eq 'fail') {
643: $status.='<h2>You did not pass the '.$title.' given on '.
1.55 albertel 644: $start_time.'.</h2>';
1.54 albertel 645: if (!$previous) {
646: $status.=&add_request_another_attempt_button();
647: }
648: }
649: my $man_count=0;
650: my $opt_count=0;
651: my $opt_passed=0;
652: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
653: if ($Apache::bridgetask::dimensionmandatory{$dim_id}
654: eq 'N') {
655: $opt_count++;
656: if ($Apache::lonhomework::history{"resource.$version.$dim_id.status"} eq 'pass') {
657: $opt_passed++;
658: }
659: } else {
660: $man_count++;
661: }
662: }
663: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
664: $parstack,$safeeval);
665: if ($opt_req !~ /\S/) { $opt_req='0'; }
666: $status.="\n<p>".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components on the bridge task.',$man_count,$opt_req,$opt_count)."</p></div>\n";
667:
668: my $internal_location=&internal_location();
669: $result=~s/\Q$internal_location\E/$status/;
670: }
1.13 albertel 671: }
672: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 673: $result.=&Apache::lonxml::xmlend().'</html>';
674: }
675: }
1.29 albertel 676: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 677: my $award='SUBMITTED';
1.28 albertel 678: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 679: 'portfiles',\$award);
1.14 albertel 680: if ($award eq 'SUBMITTED' &&
1.28 albertel 681: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
682: $Apache::lonhomework::results{"resource.0.tries"}=
683: $Apache::lonhomework::results{"resource.$version.0.tries"}=
684: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
685:
686: $Apache::lonhomework::results{"resource.0.award"}=
687: $Apache::lonhomework::results{"resource.$version.0.award"}=
688: $award;
1.51 albertel 689: $Apache::lonhomework::results{"resource.0.submission"}=
690: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.10 albertel 691: }
1.4 albertel 692: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
693: &Apache::structuretags::finalize_storage();
1.14 albertel 694: if ($award eq 'SUBMITTED') {
1.31 albertel 695: &add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14 albertel 696: }
1.1 albertel 697: }
1.32 albertel 698: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20 albertel 699: my $optional_required=
700: &Apache::lonxml::get_param('OptionalRequired',$parstack,
701: $safeeval);
702: my $optional_passed=0;
703: my $mandatory_failed=0;
704: my $ungraded=0;
705: my $review=0;
1.21 albertel 706: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 707: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
708: my $status=
1.25 albertel 709: $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20 albertel 710: my $mandatory=
711: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
712: if ($status eq 'pass') {
713: if (!$mandatory) { $optional_passed++; }
714: } elsif ($status eq 'fail') {
715: if ($mandatory) { $mandatory_failed++; }
716: } elsif ($status eq 'ungraded') {
717: $ungraded++;
718: } elsif ($status eq 'review') {
719: $review++;
1.49 albertel 720: } else {
721: $ungraded++;
722: }
1.20 albertel 723: }
724: if ($optional_passed < $optional_required) {
725: $mandatory_failed++;
726: }
1.21 albertel 727: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
728: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 729: $env{'user.name'}.'@'.$env{'user.domain'};
730: if ($review) {
1.25 albertel 731: $Apache::lonhomework::results{"resource.$version.status"}='review';
1.33 albertel 732: if ($env{'form.queue'} eq 'reviewqueue') {
733: &check_queue_unlock($env{'form.queue'});
734: &Apache::lonxml::debug(" still needs review not changing status.");
735: } else {
1.49 albertel 736: &move_between_queues($env{'form.queue'},'reviewqueue');
1.33 albertel 737: }
1.20 albertel 738: } elsif ($ungraded) {
1.25 albertel 739: $Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.49 albertel 740: if ($env{'form.queue'} eq 'reviewqueue' ||
741: $env{'form.queue'} eq 'none' ) {
1.33 albertel 742: &Apache::lonxml::debug("moving back.");
1.49 albertel 743: &move_between_queues($env{'form.queue'},'gradingqueue');
1.33 albertel 744: } else {
745: &check_queue_unlock($env{'form.queue'});
746: }
1.20 albertel 747: } elsif ($mandatory_failed) {
1.25 albertel 748: $Apache::lonhomework::results{"resource.$version.status"}='fail';
749: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
750: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
751: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39 albertel 752: &remove_from_queue($env{'form.queue'});
753:
754: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 755:
756: if ($env{'form.regrade'} ne 'yes') {
757: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
758: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
759: &Apache::grades::version_portfiles(
760: \%Apache::lonhomework::results,
761: ["$version.0.bridgetask"],$courseid,
762: $symb,$udom,$uname,
763: ["$version.0.bridgetask"]);
764: }
1.20 albertel 765: } else {
1.25 albertel 766: $Apache::lonhomework::results{"resource.$version.status"}='pass';
767: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
768: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
769: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 770: &remove_from_queue($env{'form.queue'});
1.39 albertel 771:
772: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 773: if ($env{'form.regrade'} ne 'yes') {
774: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
775: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
776: &Apache::grades::version_portfiles(
777: \%Apache::lonhomework::results,
778: ["$version.0.bridgetask"],$courseid,
779: $symb,$udom,$uname,
780: ["$version.0.bridgetask"]);
781: }
1.20 albertel 782: }
1.26 albertel 783: $Apache::lonhomework::results{"resource.status"}=
784: $Apache::lonhomework::results{"resource.$version.status"};
1.28 albertel 785: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 786: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 787: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 788: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 789: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 790: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 791: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 792: }
1.21 albertel 793: &Apache::structuretags::finalize_storage();
1.20 albertel 794: }
1.15 albertel 795: } elsif ($target eq 'webgrade') {
1.18 albertel 796: $result.="</table>\n<hr />";
1.20 albertel 797: #$result.='<input type="submit" name="next" value="'.
798: # &mt('Save & Next').'" /> ';
799: #$result.='<input type="submit" name="end" value="'.
800: # &mt('Save & Stop Grading').'" /> ';
801: #$result.='<input type="submit" name="throwaway" value="'.
802: # &mt('Throw Away & Stop Grading').'" /> ';
803: #$result.='<input type="submit" name="save" value="'.
804: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 805: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 806: } elsif ($target eq 'meta') {
1.2 albertel 807: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 808: #$result.=&Apache::response::meta_part_order();
809: #$result.=&Apache::response::meta_response_order();
810: }
1.4 albertel 811: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 812: return $result;
813: }
814:
1.31 albertel 815: sub move_between_queues {
816: my ($src_queue,$dest_queue)=@_;
1.49 albertel 817: my $cur_data;
818: if ($src_queue ne 'none') {
819: $cur_data=&get_queue_data($src_queue);
820: if (!$cur_data) { return 'not_exist'; }
821: } else {
822: $cur_data = ['none'];
823: }
1.31 albertel 824: my $result=&add_to_queue($dest_queue,$cur_data->[0]);
825: if ($result ne 'ok') {
826: return $result;
827: }
828: &check_queue_unlock($src_queue);
829: return &remove_from_queue($src_queue);
1.21 albertel 830: }
831:
832: sub check_queue_unlock {
1.32 albertel 833: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 834: if ($queue eq 'none') { return 'ok'; }
1.30 albertel 835: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 836: if (!defined($key)) {
837: $key="$symb\0queue\0$uname\@$udom";
838: }
1.30 albertel 839: my $cnum=$env{'course.'.$cid.'.num'};
840: my $cdom=$env{'course.'.$cid.'.domain'};
841: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
842: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
843: if ($who eq $me) {
1.32 albertel 844: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
845: } elsif ($allow_not_me) {
1.33 albertel 846: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 847: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 848: }
1.32 albertel 849: return 'not_owner';
1.21 albertel 850: }
851:
852: sub remove_from_queue {
1.30 albertel 853: my ($queue)=@_;
1.49 albertel 854: if ($queue eq 'none') { return 'ok'; }
1.27 albertel 855: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
856: my $cnum=$env{'course.'.$cid.'.num'};
857: my $cdom=$env{'course.'.$cid.'.domain'};
858: my $key="$symb\0queue\0$uname\@$udom";
859: my @keys=($key,"$key\0locked");
1.31 albertel 860: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 861: }
862:
1.16 albertel 863: sub setup_env_for_other_user {
864: my ($queue_key,$safeeval)=@_;
865: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 866: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 867: $env{'form.grade_symb'}=$symb;
868: $env{'form.grade_domain'}=$udom;
869: $env{'form.grade_username'}=$uname;
870: $env{'form.grade_courseid'}=$env{'request.course.id'};
871: &Apache::lonxml::initialize_rndseed($safeeval);
872: }
873:
1.31 albertel 874: sub get_queue_data {
875: my ($queue)=@_;
876: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
877: my $cnum=$env{'course.'.$cid.'.num'};
878: my $cdom=$env{'course.'.$cid.'.domain'};
879: my $todo="$symb\0queue\0$uname\@$udom";
880: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
881: if ($key eq $todo && ref($value)) {
882: return $value;
883: }
884: return undef;
885: }
886:
1.49 albertel 887: sub check_queue_for_key {
888: my ($cid,$queue,$todo)=@_;
889: my $cnum=$env{'course.'.$cid.'.num'};
890: my $cdom=$env{'course.'.$cid.'.domain'};
891: my %results=
892: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
893:
894: if (exists($results{$todo}) && ref($results{$todo})) {
895: if (defined($results{"$todo\0locked"})) {
896: return 'locked';
897: }
1.58 albertel 898: my $slot=$results{$todo}->[0];
899: my %slot_data=&Apache::lonnet::get_slot($slot);
900: if ($slot_data{'endtime'} > time) {
901: return 'in_progress';
902: }
1.49 albertel 903: return 'enqueued';
904: }
905: return undef;
906: }
907:
1.14 albertel 908: sub add_to_queue {
1.31 albertel 909: my ($queue,$slot_name)=@_;
1.49 albertel 910: if ($queue eq 'none') { return 'ok'; }
1.14 albertel 911: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
912: my $cnum=$env{'course.'.$cid.'.num'};
913: my $cdom=$env{'course.'.$cid.'.domain'};
914: my %data;
1.31 albertel 915: $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
916: return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14 albertel 917: }
918:
919: sub show_queue {
1.32 albertel 920: my ($queue,$with_selects)=@_;
1.14 albertel 921: my $result;
922: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
923: my $cnum=$env{'course.'.$cid.'.num'};
924: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 925:
926: my @chosen_sections=
927: &Apache::loncommon::get_env_multiple('form.chosensections');
928: &Apache::grades::init_perm();
929: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
930: &Apache::grades::reset_perm();
931:
1.16 albertel 932: my $regexp="^$symb\0";
1.30 albertel 933: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 934: my ($tmp)=%queue;
935: if ($tmp=~/^error: 2 /) {
1.33 albertel 936: return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31 albertel 937: }
1.33 albertel 938: $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32 albertel 939: if ($with_selects) { $result.="<th></th>"; }
940: $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 941: foreach my $key (sort(keys(%queue))) {
1.59 albertel 942: my ($symb,$uname,$udom) = &decode_queue_key($key);
943: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.32 albertel 944: if ($key=~/locked$/ && !$with_selects) {
1.16 albertel 945: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 946: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 947: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32 albertel 948: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.16 albertel 949: my ($symb,undef) = split("\0",$key);
950: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 951: $result.="<tr><td>$title</td><td></td>";
1.16 albertel 952: $result.='<td>last queue modification time</td><td>'.
953: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 954: } elsif ($key!~/(timestamp|locked)$/) {
1.16 albertel 955: my $title=&Apache::lonnet::gettitle($symb);
1.32 albertel 956: $result.="<tr>";
1.35 albertel 957: my $slot=$queue{$key}->[0];
958: my %slot_data=&Apache::lonnet::get_slot($slot);
1.32 albertel 959: if ($with_selects) {
960: my $ekey=&Apache::lonnet::escape($key);
961: my ($action,$description)=('select',&mt('Select'));
962: if (exists($queue{"$key\0locked"})) {
963: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
964: if ($me eq $queue{"$key\0locked"}) {
965: ($action,$description)=('resume',&mt('Resume'));
966: } else {
967: ($action,$description)=('unlock',&mt('Unlock'));
968: }
969: }
1.62 ! albertel 970: my $seclist;
! 971: foreach my $sec (@chosen_sections) {
! 972: $seclist.='<input type="hidden" name="chosensections"
! 973: value="'.$sec.'" />';
! 974: }
1.35 albertel 975: if (time > $slot_data{'endtime'}) {
976: $result.=(<<FORM);
1.32 albertel 977: <td>
978: <form method="POST">
979: <input type="hidden" name="gradingkey" value="$ekey" />
980: <input type="hidden" name="queue" value="$queue" />
981: <input type="hidden" name="gradingaction" value="$action" />
982: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 983: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 984: <input type="submit" name="submit" value="$description" />
1.62 ! albertel 985: $seclist
1.32 albertel 986: </form>
987: </td>
988: FORM
1.35 albertel 989:
990: } else {
991: $result.='<td>'.&mt("In Progress").'</td>'
992: }
1.32 albertel 993: }
994: $result.="<td>$title</td><td>$uname</td>";
1.27 albertel 995: $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20 albertel 996: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
997: "</td></tr>";
1.16 albertel 998: }
1.14 albertel 999: }
1.15 albertel 1000: $result.="</table><hr />\n";
1.14 albertel 1001: return $result;
1002: }
1003:
1.34 albertel 1004: sub get_queue_counts {
1005: my ($queue)=@_;
1006: my $result;
1007: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1008: my $cnum=$env{'course.'.$cid.'.num'};
1009: my $cdom=$env{'course.'.$cid.'.domain'};
1010: my $regexp="^$symb\0";
1011: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1012: my ($tmp)=%queue;
1013: if ($tmp=~/^error: 2 /) {
1014: return (0,0,0);
1015: }
1016: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1017: foreach my $key (sort(keys(%queue))) {
1018: if ($key=~/locked$/) {
1019: $locks++;
1020: } elsif ($key=~/timestamp$/) {
1021: #ignore
1022: } elsif ($key!~/(timestamp|locked)$/) {
1023: my ($symb,$uname,$udom) = &decode_queue_key($key);
1024: $entries++;
1025: my $slot=$queue{$key}->[0];
1026: my %slot_data=&Apache::lonnet::get_slot($slot);
1027: if (time > $slot_data{'endtime'}) {
1028: $ready_to_grade++;
1029: }
1030: }
1031: }
1032: return ($entries,$ready_to_grade,$locks);
1033: }
1034:
1.49 albertel 1035: sub encode_queue_key {
1036: my ($symb,$udom,$uname)=@_;
1037: return "$symb\0queue\0$uname\@$udom";
1038: }
1039:
1.14 albertel 1040: sub decode_queue_key {
1041: my ($key)=@_;
1042: my ($symb,undef,$user) = split("\0",$key);
1043: my ($uname,$udom) = split('@',$user);
1044: return ($symb,$uname,$udom);
1045: }
1046:
1047: sub queue_key_locked {
1.30 albertel 1048: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1049: if (!defined($cdom) || !defined($cnum)) {
1050: my (undef,$cid)=&Apache::lonxml::whichuser();
1051: $cnum=$env{'course.'.$cid.'.num'};
1052: $cdom=$env{'course.'.$cid.'.domain'};
1053: }
1.14 albertel 1054: my ($key_locked,$value)=
1.30 albertel 1055: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1056: if ($key_locked eq "$key\0locked") {
1057: return $value;
1058: }
1059: return undef;
1060: }
1061:
1062: sub pick_from_queue_data {
1.30 albertel 1063: my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
1064: foreach my $key (keys(%$queuedata)) {
1.14 albertel 1065: my ($symb,$uname,$udom)=&decode_queue_key($key);
1066: if ($check_section) {
1067: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 1068: if ($section eq $check_section) {
1.33 albertel 1069: &Apache::lonxml::debug("my sec");
1.15 albertel 1070: next;
1071: }
1.14 albertel 1072: }
1.30 albertel 1073: my $slot=$queuedata->{$key}[0];
1.14 albertel 1074: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 1075: if ($slot_data{'endtime'} > time) {
1.33 albertel 1076: &Apache::lonxml::debug("not time");
1.15 albertel 1077: next;
1078: }
1.30 albertel 1079: if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33 albertel 1080: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1081: next;
1082: }
1.14 albertel 1083: return $key;
1084: }
1085: return undef;
1086: }
1087:
1.15 albertel 1088: sub find_mid_grade {
1.30 albertel 1089: my ($queue,$symb,$cdom,$cnum)=@_;
1.16 albertel 1090: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 1091: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
1092: if ($todo) {
1.30 albertel 1093: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1094: if ($who eq $me) { return $todo; }
1095: }
1096: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1097: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1098: foreach my $key (keys(%locks)) {
1099: my $who=$locks{$key};
1100: if ($who eq $me) {
1101: $todo=$key;
1102: $todo=~s/\0locked$//;
1103: return $todo;
1104: }
1105: }
1106: return undef;
1107: }
1108:
1.32 albertel 1109: sub lock_key {
1110: my ($queue,$todo)=@_;
1111: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
1112: my (undef,$cid)=&Apache::lonxml::whichuser();
1113: my $cnum=$env{'course.'.$cid.'.num'};
1114: my $cdom=$env{'course.'.$cid.'.domain'};
1115: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1116: $cdom,$cnum);
1.33 albertel 1117: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1118: if ($success eq 'ok') {
1119: return 1;
1120: }
1121: return 0;
1122: }
1123:
1.14 albertel 1124: sub get_from_queue {
1.30 albertel 1125: my ($queue)=@_;
1.14 albertel 1126: my $result;
1127: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1128: my $cnum=$env{'course.'.$cid.'.num'};
1129: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1130: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1131: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1132: if ($todo) { return $todo; }
1.14 albertel 1133: while (1) {
1134: my $starttime=time;
1.30 albertel 1135: &Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14 albertel 1136: $cdom,$cnum);
1.33 albertel 1137: &Apache::lonxml::debug("$starttime");
1.14 albertel 1138: my $regexp="^$symb\0queue\0";
1.30 albertel 1139: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1140: #make a pass looking for a user _not_ in my section
1.14 albertel 1141: if ($env{'request.course.sec'}) {
1.33 albertel 1142: &Apache::lonxml::debug("sce");
1.30 albertel 1143: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1144: \%queue,$cdom,$cnum);
1.33 albertel 1145: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1146: }
1.33 albertel 1147: # no one _not_ in our section so look for any user that is
1148: # ready for grading
1.14 albertel 1149: if (!$todo) {
1.33 albertel 1150: &Apache::lonxml::debug("no sce");
1.31 albertel 1151: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1152: \%queue,$cdom,$cnum);
1.33 albertel 1153: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1154: }
1155: # no user to grade
1156: if (!$todo) { last; }
1.33 albertel 1157: &Apache::lonxml::debug("got $todo");
1.14 albertel 1158: # otherwise found someone so lets try to lock them
1.32 albertel 1159: # unless someone else already picked them
1160: if (!&lock_key($queue,$todo)) { next; }
1.14 albertel 1161: my (undef,$endtime)=
1.30 albertel 1162: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 1163: $cdom,$cnum);
1.33 albertel 1164: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 1165: # someone else already modified the queue,
1166: # perhaps our picked user wass already fully graded between
1167: # when we picked him and when we locked his record? so lets
1168: # double check.
1169: if ($endtime != $starttime) {
1170: my ($key,$value)=
1.30 albertel 1171: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 1172: $cdom,$cnum);
1.33 albertel 1173: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 1174: if ($key eq $todo && ref($value)) {
1175: } else {
1.30 albertel 1176: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 1177: $cdom,$cnum);
1.33 albertel 1178: &Apache::lonxml::debug("del");
1.14 albertel 1179: next;
1180: }
1181: }
1.33 albertel 1182: &Apache::lonxml::debug("last $todo");
1.14 albertel 1183: last;
1184: }
1185: return $todo;
1186: }
1187:
1.49 albertel 1188: sub select_user {
1189: my ($symb,$cid)=&Apache::lonxml::whichuser();
1190: my $result.='<table border="1">';
1191:
1.59 albertel 1192: my @chosen_sections=
1193: &Apache::loncommon::get_env_multiple('form.chosensections');
1.49 albertel 1194: &Apache::grades::init_perm();
1.59 albertel 1195: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1.49 albertel 1196: &Apache::grades::reset_perm();
1197:
1198: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1199: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 1200:
1.49 albertel 1201: my %status = &get_student_status($symb,$cid,$udom,$uname);
1202: my $queue = 'none';
1.58 albertel 1203: my $cannot_grade;
1204: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1205: $queue = 'reviewqueue';
1.58 albertel 1206: if ($status{'reviewqueue'} eq 'in_progress') {
1207: $cannot_grade=1;
1208: }
1209: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1210: $queue = 'gradingqueue';
1.58 albertel 1211: if ($status{'gradingqueue'} eq 'in_progress') {
1212: $cannot_grade=1;
1213: }
1.49 albertel 1214: }
1215: my $todo =
1216: &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 1217: if ($cannot_grade) {
1218: $result.='<tr><td> </td><td>'.$fullname->{$student}.
1219: '</td><td>';
1220: } else {
1.62 ! albertel 1221: my $seclist;
! 1222: foreach my $sec (@chosen_sections) {
! 1223: $seclist.='<input type="hidden" name="chosensections"
! 1224: value="'.$sec.'" />';
! 1225: }
1.58 albertel 1226: $result.=<<RESULT;
1.49 albertel 1227: <tr>
1228: <td>
1229: <form method="POST">
1230: <input type="hidden" name="gradingkey" value="$todo" />
1231: <input type="hidden" name="queue" value="$queue" />
1232: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 1233: <input type="hidden" name="regrade" value="yes" />
1.62 ! albertel 1234: <input type="submit" name="submit" value="Regrade" />
! 1235: $seclist
1.49 albertel 1236: </form>
1237: <td>$fullname->{$student}</td>
1238: <td>
1239: RESULT
1.58 albertel 1240: }
1.49 albertel 1241: if ($status{'status'} eq 'pass') {
1242: $result .= '<font color="green">'.&mt('Passed').'</font>';
1243: } elsif ($status{'status'} eq 'fail') {
1244: $result .= '<font color="red">'.&mt('Failed').'</font>';
1245: } elsif ($status{'status'} eq 'review') {
1246: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1247: } elsif ($status{'status'} eq 'ungraded') {
1248: $result .= &mt('Ungraded');
1249: } elsif ($status{'status'} ne '') {
1250: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1251: } else {
1252: $result.=" ";
1253: }
1254: if ($status{'version'}) {
1255: $result .= ' '.&mt('Version').' '.$status{'version'};
1256: }
1257: $result.= '</td><td>';
1258: if ($status{'reviewqueue'} eq 'enqueued') {
1259: $result .= &mt('Awaiting Review');
1260: } elsif ($status{'reviewqueue'} eq 'locked') {
1261: $result .= &mt('Under Review');
1.58 albertel 1262: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1263: $result .= &mt('Still being worked on.');
1.49 albertel 1264: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1265: $result .= &mt('Awaiting Grading');
1266: } elsif ($status{'gradingqueue'} eq 'locked') {
1267: $result .= &mt('Being Graded');
1.58 albertel 1268: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1269: $result .= &mt('Still being worked on.');
1.49 albertel 1270: } else {
1271: $result.=" ";
1272: }
1273: $result.= '</td></tr>';
1274: }
1275: $result.='</table>';
1276: return $result;
1277: }
1278:
1279: sub get_student_status {
1280: my ($symb,$cid,$udom,$uname)=@_;
1281: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1282: $udom,$uname);
1283: my %status;
1284: $status{'status'}=$record{'resource.status'};
1285: $status{'version'}=$record{'resource.version'};
1286: $status{'grader'}=$record{'resource.grader'};
1287: $status{'reviewqueue'}=&check_queue_for_key($cid,'reviewqueue',
1288: &encode_queue_key($symb,$udom,$uname));
1289: $status{'gradingqueue'}=&check_queue_for_key($cid,'gradingqueue',
1290: &encode_queue_key($symb,$udom,$uname));
1291: return %status;
1292: }
1293:
1.1 albertel 1294: sub start_ClosingParagraph {
1295: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1296: my $result;
1297: if ($target eq 'web') {
1.13 albertel 1298: } elsif ($target eq 'webgrade') {
1299: &Apache::lonxml::startredirection();
1.1 albertel 1300: }
1301: return $result;
1302: }
1303:
1304: sub end_ClosingParagraph {
1305: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1306: my $result;
1307: if ($target eq 'web') {
1.13 albertel 1308: } elsif ($target eq 'webgrade') {
1309: &Apache::lonxml::endredirection();
1.1 albertel 1310: }
1311: return $result;
1312: }
1313:
1.19 albertel 1314: sub get_id {
1315: my ($parstack,$safeeval)=@_;
1316: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1317: if (!$id) { $id=$Apache::lonxml::curdepth; }
1318: return $id;
1319: }
1320:
1.1 albertel 1321: my %dimension;
1322: sub start_Dimension {
1323: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1324: undef(%dimension);
1.19 albertel 1325: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 1326: $Apache::bridgetask::dimension=$dim_id;
1327: push(@Apache::bridgetask::dimensionlist,$dim_id);
1328: undef(@Apache::bridgetask::instance);
1.20 albertel 1329: $Apache::bridgetask::dimensionmandatory{$dim_id}=
1330: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.54 albertel 1331: &Apache::lonxml::startredirection();
1332: return &internal_location($dim_id);
1.1 albertel 1333: }
1334:
1.13 albertel 1335: sub get_instance {
1336: &Apache::response::pushrandomnumber();
1337: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29 albertel 1338: my $num=@order;
1339: my $version=&get_version();
1340: my $which=($version-1)%$num;
1341: return $order[$which];
1.13 albertel 1342: }
1343:
1.18 albertel 1344: {
1345: my $last_link;
1346: sub end_Dimension {
1347: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54 albertel 1348: my $result=&Apache::lonxml::endredirection();
1.25 albertel 1349: my $dim=&get_id($parstack,$safeeval);
1.19 albertel 1350: my $instance=&get_instance();
1.25 albertel 1351: my $version=&get_version();
1.18 albertel 1352: if ($target eq 'web') {
1.47 albertel 1353: @Apache::scripttag::parser_env = @_;
1354: $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1355: @Apache::scripttag::parser_env = @_;
1356: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.26 albertel 1357: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
1358: $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.54 albertel 1359:
1360: my $dim_status=$Apache::lonhomework::history{"resource.$version.$dim.status"};
1361: my $mandatory='Mandatory';
1362: if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
1363: $mandatory='Optional';
1364: }
1365: my $dim_info="<div class='$dim_status'>\n";
1366: if ($dim_status eq 'pass') {
1367: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1368: }
1369: if ($dim_status eq 'fail') {
1370: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1371: }
1372: my $man_count=0;
1373: my $opt_count=0;
1374: my $opt_passed=0;
1375: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1376: if ($dimension{$instance.'.criteria.'.$id.'.mandatory'}
1377: eq 'N') {
1378: $opt_count++;
1379: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
1380: $opt_passed++;
1381: }
1382: } else {
1383: $man_count++;
1384: }
1385: }
1386: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
1387: $parstack,$safeeval);
1388: if ($opt_req !~ /\S/) { $opt_req='0'; }
1389: $dim_info.="\n<p>".&mt('You passed all of the mandatory components and [_1] of the [_2] optional components, of which you were required to pass [_3].',$opt_passed,$opt_count,$opt_req)."</p>\n</div>";
1390:
1391: my $internal_location=&internal_location($dim);
1392: $result=~s/\Q$internal_location\E/$dim_info/;
1393:
1.22 albertel 1394: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1395: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1396: my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.53 albertel 1397: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1398: if ($mandatory) {
1399: $mandatory='Mandatory';
1400: } else {
1401: $mandatory='Optional';
1402: }
1.22 albertel 1403: if ($status eq 'fail') {
1404: } elsif ($status eq 'pass') {
1405: } else {
1.49 albertel 1406: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
1.22 albertel 1407: }
1.53 albertel 1408: my $status_display=$status;
1409: $status_display=~s/^([a-z])/uc($1)/e;
1.54 albertel 1410: @Apache::scripttag::parser_env = @_;
1.53 albertel 1411: $result.='<div class="'.$status.'"><h4>'.$mandatory.
1.54 albertel 1412: ' Criteria</h4><p>';
1413: @Apache::scripttag::parser_env = @_;
1414: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
1415: $result.='</p><p class="grade">'.$status_display.'</p>';
1.25 albertel 1416: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
1.53 albertel 1417: $result.='<p class="comment">'.$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</p>';
1.22 albertel 1418: }
1.53 albertel 1419: $result.='</div>';
1.22 albertel 1420: }
1421: }
1.18 albertel 1422: } elsif ($target eq 'webgrade') {
1.47 albertel 1423: # in case of any side effects that we need
1424: @Apache::scripttag::parser_env = @_;
1425: &Apache::scripttag::xmlparse($dimension{'intro'});
1426: @Apache::scripttag::parser_env = @_;
1427: &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.18 albertel 1428: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1429: my $link='criteria_'.$instance.'_'.$id;
1.25 albertel 1430: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19 albertel 1431: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 1432: '<a name="'.$link.'" />'.
1433: '<a name="next_'.$last_link.'" />'.
1.47 albertel 1434: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">';
1435: @Apache::scripttag::parser_env = @_;
1436: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
1437: $result.='</textarea>'.
1.18 albertel 1438: #$dimension{$instance.'.criteria.'.$id}.
1439: '</td>'.
1.19 albertel 1440: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25 albertel 1441: '<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 1442: '</td>'.
1443: '<td>'.
1.47 albertel 1444: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label></nobr><br />'.
1.30 albertel 1445: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
1446: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
1447: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18 albertel 1448: '</td>'.
1449: '<td>'.
1450: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 1451: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
1452: '<input type="submit" name="next" value="'.
1453: &mt('Done').'" /> '.
1.30 albertel 1454: '<input type="submit" name="stop" value="'.
1455: &mt('Stop').'" /> '.
1.18 albertel 1456: '</td></tr>';
1.22 albertel 1457: $result.='<tr><td colspan="4">';
1458: my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
1.52 albertel 1459: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.43 albertel 1460: foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"})) {
1.22 albertel 1461: my $file=$file_url.$partial_file;
1.52 albertel 1462: $file=~s|/+|/|g;
1.22 albertel 1463: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.48 albertel 1464: $result.='<nobr><a href="'.$file.'" target="lonGRDs"><img src="'.
1.22 albertel 1465: &Apache::loncommon::icon($file).'" border=0"> '.$file.
1.48 albertel 1466: '</a></nobr> ';
1.22 albertel 1467: }
1468: $result.='</td></tr>';
1.18 albertel 1469: $last_link=$link;
1470: }
1.22 albertel 1471: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 1472: my $optional_passed=0;
1.20 albertel 1473: my $mandatory_failed=0;
1474: my $ungraded=0;
1475: my $review=0;
1.19 albertel 1476: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1477: my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
1478: $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 1479: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1480: if ($status eq 'pass') {
1481: if (!$mandatory) { $optional_passed++; }
1482: } elsif ($status eq 'fail') {
1483: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 1484: } elsif ($status eq 'review') {
1485: $review++;
1.20 albertel 1486: } elsif ($status eq 'ungraded') {
1487: $ungraded++;
1.21 albertel 1488: } else {
1.47 albertel 1489: $ungraded++;
1.19 albertel 1490: }
1491: }
1.20 albertel 1492: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
1493: $mandatory_failed++;
1494: }
1.21 albertel 1495: &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 1496: if ($review) {
1.25 albertel 1497: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1498: 'review';
1.20 albertel 1499: } elsif ($ungraded) {
1.25 albertel 1500: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1501: 'ungraded';
1.20 albertel 1502: } elsif ($mandatory_failed) {
1.25 albertel 1503: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1504: 'fail';
1.20 albertel 1505: } else {
1.25 albertel 1506: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1507: 'pass';
1.20 albertel 1508: }
1.13 albertel 1509: }
1.18 albertel 1510: return $result;
1.1 albertel 1511: }
1512: }
1513:
1514: sub start_IntroParagraph {
1515: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1516: my $result;
1.13 albertel 1517: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1518: if ($tagstack->[-2] eq 'Dimension') {
1519: $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser);
1520:
1521: } elsif ($target eq 'webgrade') {
1522: &Apache::lonxml::get_all_text('/introparagraph',$parser);
1.1 albertel 1523: }
1.47 albertel 1524:
1.1 albertel 1525: }
1526: return $result;
1527: }
1528:
1529: sub end_IntroParagraph {
1530: }
1531:
1532: sub start_Instance {
1533: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 1534: my $id=&get_id($parstack,$safeeval);
1535: push(@{$dimension{'instances'}},$id);
1536: push(@Apache::bridgetask::instance,$id);
1537: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 1538: $dimension{$id.'.optionalrequired'}=
1.19 albertel 1539: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 1540: return '';
1541: }
1542:
1543: sub end_Instance {
1544: }
1545:
1546: sub start_InstanceText {
1547: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 albertel 1548: my $instance_id=$Apache::bridgetask::instance[-1];
1549: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser);
1.13 albertel 1550: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1551: $dimension{$instance_id.'.text'}=$text;
1.1 albertel 1552: }
1553: return '';
1554: }
1555:
1556: sub end_InstanceText {
1557: return '';
1558: }
1559:
1560: sub start_Criteria {
1561: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1562: my $instance_id=$Apache::bridgetask::instance[-1];
1.47 albertel 1563: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser);
1.21 albertel 1564: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19 albertel 1565: my $id=&get_id($parstack,$safeeval);
1.1 albertel 1566: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 1567: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
1568: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 1569: push(@{$dimension{$instance_id.'.criterias'}},$id);
1570: }
1571: return '';
1572: }
1573:
1.47 albertel 1574: sub end_Criteria {
1575: }
1576:
1.4 albertel 1577: sub proctor_validation_screen {
1578: my ($slot) = @_;
1579: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 1580: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 1581: my $name=&Apache::loncommon::plainname($user,$domain);
1582:
1.4 albertel 1583: my $msg;
1.11 albertel 1584: if ($env{'form.proctorpassword'}) {
1.4 albertel 1585: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
1586: .'</font></p>';
1587: }
1.47 albertel 1588: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 1589: my $result= (<<ENDCHECKOUT);
1590: <h2>Proctor Validation</h2>
1591: <p>Your room's proctor needs to validate your access to this resource.</p>
1592: $msg
1.11 albertel 1593: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 1594: <input type="hidden" name="validate" value="yes" />
1595: <input type="hidden" name="submitted" value="yes" />
1596: <table>
1.44 albertel 1597: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 1598: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 1599: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 1600: </table>
1601: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 1602: <table border="1">
1603: <tr><td>
1604: <table>
1605: <tr><td colspan="2">Student who should be logged in is:</td></tr>
1606: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 1607: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.44 albertel 1608: <tr><td>Usename</td><td>$user\@$domain</td></tr>
1609: <tr><td colspan="2"><img src="$url" /></td></tr>
1610: </table>
1611: </tr></td>
1612: </table>
1.4 albertel 1613: </form>
1614: ENDCHECKOUT
1615: return $result;
1616: }
1617:
1.1 albertel 1618: 1;
1619: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>