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