Annotation of loncom/homework/bridgetask.pm, revision 1.69
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.69 ! albertel 4: # $Id: bridgetask.pm,v 1.68 2005/10/05 20:24:59 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();
1.67 albertel 398: my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
399: my $files='<ul><li>'.join('</li><li>',@files).'</li></ul>';
1.64 albertel 400: $result.=<<DONESCREEN;
401: <h2>$title</h2>
402: <p> Files submitted: $files </p>
1.67 albertel 403: <p> You are now done with this Bridge Task </p>
1.64 albertel 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.69 ! albertel 621: if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1 albertel 622: if ($target eq 'web') {
1.54 albertel 623: if (&show_task($status,$previous)) {
624: $result.=&Apache::lonxml::endredirection();
625: }
1.64 albertel 626: if ($status eq 'CAN_ANSWER' && !$previous &&
627: !$env{'form.donescreen'}) {
1.15 albertel 628: $result.="\n".'<table border="1">'.
1.28 albertel 629: &Apache::inputtags::file_selector("$version.0",
630: "bridgetask","*",
1.46 albertel 631: 'portfolioonly',
632: '
633: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
634: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9 albertel 635: "</table>";
636: $result.=&Apache::inputtags::gradestatus('0');
1.64 albertel 637: $result.='</form>';
638: $result.=<<DONEBUTTON;
639: <form method="POST">
640: <input type="hidden" name="donescreen" value="1" />
641: <input type="submit" value="Done" />
642: </form>
643: DONEBUTTON
1.9 albertel 644: }
1.56 albertel 645: if (&show_task($status,$previous) &&
646: $Apache::lonhomework::history{"resource.$version.status"} =~ /^(pass|fail)$/) {
1.54 albertel 647: my $bt_status=$Apache::lonhomework::history{"resource.$version.status"};
648: my $title=&Apache::lonnet::gettitle();
649: my %slot=&Apache::lonnet::get_slot($Apache::inputtags::slot_name);
1.55 albertel 650: my $start_time=
651: &Apache::lonlocal::locallocaltime($slot{'starttime'});
1.54 albertel 652:
653: my $status;
654: $status.="\n<div class='$bt_status'>\n";
655:
656: if ($bt_status eq 'pass') {
657: $status.='<h2>You passed the '.$title.' given on '.
1.55 albertel 658: $start_time.'.</h2>';
1.54 albertel 659: }
660: if ($bt_status eq 'fail') {
661: $status.='<h2>You did not pass the '.$title.' given on '.
1.55 albertel 662: $start_time.'.</h2>';
1.54 albertel 663: if (!$previous) {
664: $status.=&add_request_another_attempt_button();
665: }
666: }
667: my $man_count=0;
668: my $opt_count=0;
669: my $opt_passed=0;
670: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
671: if ($Apache::bridgetask::dimensionmandatory{$dim_id}
672: eq 'N') {
673: $opt_count++;
674: if ($Apache::lonhomework::history{"resource.$version.$dim_id.status"} eq 'pass') {
675: $opt_passed++;
676: }
677: } else {
678: $man_count++;
679: }
680: }
681: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
682: $parstack,$safeeval);
683: if ($opt_req !~ /\S/) { $opt_req='0'; }
684: $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";
685:
686: my $internal_location=&internal_location();
687: $result=~s/\Q$internal_location\E/$status/;
688: }
1.13 albertel 689: }
690: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 691: $result.=&Apache::lonxml::xmlend().'</html>';
692: }
693: }
1.29 albertel 694: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 695: my $award='SUBMITTED';
1.28 albertel 696: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 697: 'portfiles',\$award);
1.14 albertel 698: if ($award eq 'SUBMITTED' &&
1.28 albertel 699: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
700: $Apache::lonhomework::results{"resource.0.tries"}=
701: $Apache::lonhomework::results{"resource.$version.0.tries"}=
702: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
703:
704: $Apache::lonhomework::results{"resource.0.award"}=
705: $Apache::lonhomework::results{"resource.$version.0.award"}=
706: $award;
1.51 albertel 707: $Apache::lonhomework::results{"resource.0.submission"}=
708: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64 albertel 709: } else {
710: delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1.10 albertel 711: }
1.4 albertel 712: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
713: &Apache::structuretags::finalize_storage();
1.14 albertel 714: if ($award eq 'SUBMITTED') {
1.31 albertel 715: &add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14 albertel 716: }
1.1 albertel 717: }
1.32 albertel 718: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20 albertel 719: my $optional_required=
720: &Apache::lonxml::get_param('OptionalRequired',$parstack,
721: $safeeval);
722: my $optional_passed=0;
723: my $mandatory_failed=0;
724: my $ungraded=0;
725: my $review=0;
1.21 albertel 726: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 727: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
728: my $status=
1.25 albertel 729: $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20 albertel 730: my $mandatory=
731: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
732: if ($status eq 'pass') {
733: if (!$mandatory) { $optional_passed++; }
734: } elsif ($status eq 'fail') {
735: if ($mandatory) { $mandatory_failed++; }
736: } elsif ($status eq 'ungraded') {
737: $ungraded++;
738: } elsif ($status eq 'review') {
739: $review++;
1.49 albertel 740: } else {
741: $ungraded++;
742: }
1.20 albertel 743: }
744: if ($optional_passed < $optional_required) {
745: $mandatory_failed++;
746: }
1.21 albertel 747: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
748: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 749: $env{'user.name'}.'@'.$env{'user.domain'};
750: if ($review) {
1.25 albertel 751: $Apache::lonhomework::results{"resource.$version.status"}='review';
1.33 albertel 752: if ($env{'form.queue'} eq 'reviewqueue') {
753: &check_queue_unlock($env{'form.queue'});
754: &Apache::lonxml::debug(" still needs review not changing status.");
755: } else {
1.49 albertel 756: &move_between_queues($env{'form.queue'},'reviewqueue');
1.33 albertel 757: }
1.20 albertel 758: } elsif ($ungraded) {
1.25 albertel 759: $Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.49 albertel 760: if ($env{'form.queue'} eq 'reviewqueue' ||
761: $env{'form.queue'} eq 'none' ) {
1.33 albertel 762: &Apache::lonxml::debug("moving back.");
1.49 albertel 763: &move_between_queues($env{'form.queue'},'gradingqueue');
1.33 albertel 764: } else {
765: &check_queue_unlock($env{'form.queue'});
766: }
1.20 albertel 767: } elsif ($mandatory_failed) {
1.25 albertel 768: $Apache::lonhomework::results{"resource.$version.status"}='fail';
769: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
770: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
771: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39 albertel 772: &remove_from_queue($env{'form.queue'});
773:
774: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 775:
776: if ($env{'form.regrade'} ne 'yes') {
777: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
778: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
779: &Apache::grades::version_portfiles(
780: \%Apache::lonhomework::results,
781: ["$version.0.bridgetask"],$courseid,
782: $symb,$udom,$uname,
783: ["$version.0.bridgetask"]);
784: }
1.20 albertel 785: } else {
1.25 albertel 786: $Apache::lonhomework::results{"resource.$version.status"}='pass';
787: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
788: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
789: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 790: &remove_from_queue($env{'form.queue'});
1.39 albertel 791:
792: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1.52 albertel 793: if ($env{'form.regrade'} ne 'yes') {
794: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
795: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
796: &Apache::grades::version_portfiles(
797: \%Apache::lonhomework::results,
798: ["$version.0.bridgetask"],$courseid,
799: $symb,$udom,$uname,
800: ["$version.0.bridgetask"]);
801: }
1.20 albertel 802: }
1.26 albertel 803: $Apache::lonhomework::results{"resource.status"}=
804: $Apache::lonhomework::results{"resource.$version.status"};
1.28 albertel 805: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 806: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 807: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 808: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 809: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 810: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 811: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 812: }
1.21 albertel 813: &Apache::structuretags::finalize_storage();
1.20 albertel 814: }
1.15 albertel 815: } elsif ($target eq 'webgrade') {
1.18 albertel 816: $result.="</table>\n<hr />";
1.20 albertel 817: #$result.='<input type="submit" name="next" value="'.
818: # &mt('Save & Next').'" /> ';
819: #$result.='<input type="submit" name="end" value="'.
820: # &mt('Save & Stop Grading').'" /> ';
821: #$result.='<input type="submit" name="throwaway" value="'.
822: # &mt('Throw Away & Stop Grading').'" /> ';
823: #$result.='<input type="submit" name="save" value="'.
824: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 825: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 826: } elsif ($target eq 'meta') {
1.2 albertel 827: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 828: #$result.=&Apache::response::meta_part_order();
829: #$result.=&Apache::response::meta_response_order();
830: }
1.4 albertel 831: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 832: return $result;
833: }
834:
1.31 albertel 835: sub move_between_queues {
836: my ($src_queue,$dest_queue)=@_;
1.49 albertel 837: my $cur_data;
838: if ($src_queue ne 'none') {
839: $cur_data=&get_queue_data($src_queue);
840: if (!$cur_data) { return 'not_exist'; }
841: } else {
842: $cur_data = ['none'];
843: }
1.31 albertel 844: my $result=&add_to_queue($dest_queue,$cur_data->[0]);
845: if ($result ne 'ok') {
846: return $result;
847: }
848: &check_queue_unlock($src_queue);
849: return &remove_from_queue($src_queue);
1.21 albertel 850: }
851:
852: sub check_queue_unlock {
1.32 albertel 853: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 854: if ($queue eq 'none') { return 'ok'; }
1.30 albertel 855: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 856: if (!defined($key)) {
857: $key="$symb\0queue\0$uname\@$udom";
858: }
1.30 albertel 859: my $cnum=$env{'course.'.$cid.'.num'};
860: my $cdom=$env{'course.'.$cid.'.domain'};
861: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
862: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
863: if ($who eq $me) {
1.32 albertel 864: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
865: } elsif ($allow_not_me) {
1.33 albertel 866: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 867: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 868: }
1.32 albertel 869: return 'not_owner';
1.21 albertel 870: }
871:
872: sub remove_from_queue {
1.30 albertel 873: my ($queue)=@_;
1.49 albertel 874: if ($queue eq 'none') { return 'ok'; }
1.27 albertel 875: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
876: my $cnum=$env{'course.'.$cid.'.num'};
877: my $cdom=$env{'course.'.$cid.'.domain'};
878: my $key="$symb\0queue\0$uname\@$udom";
879: my @keys=($key,"$key\0locked");
1.31 albertel 880: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 881: }
882:
1.16 albertel 883: sub setup_env_for_other_user {
884: my ($queue_key,$safeeval)=@_;
885: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 886: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 887: $env{'form.grade_symb'}=$symb;
888: $env{'form.grade_domain'}=$udom;
889: $env{'form.grade_username'}=$uname;
890: $env{'form.grade_courseid'}=$env{'request.course.id'};
891: &Apache::lonxml::initialize_rndseed($safeeval);
892: }
893:
1.31 albertel 894: sub get_queue_data {
895: my ($queue)=@_;
896: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
897: my $cnum=$env{'course.'.$cid.'.num'};
898: my $cdom=$env{'course.'.$cid.'.domain'};
899: my $todo="$symb\0queue\0$uname\@$udom";
900: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
901: if ($key eq $todo && ref($value)) {
902: return $value;
903: }
904: return undef;
905: }
906:
1.49 albertel 907: sub check_queue_for_key {
908: my ($cid,$queue,$todo)=@_;
909: my $cnum=$env{'course.'.$cid.'.num'};
910: my $cdom=$env{'course.'.$cid.'.domain'};
911: my %results=
912: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
913:
914: if (exists($results{$todo}) && ref($results{$todo})) {
915: if (defined($results{"$todo\0locked"})) {
916: return 'locked';
917: }
1.58 albertel 918: my $slot=$results{$todo}->[0];
919: my %slot_data=&Apache::lonnet::get_slot($slot);
920: if ($slot_data{'endtime'} > time) {
921: return 'in_progress';
922: }
1.49 albertel 923: return 'enqueued';
924: }
925: return undef;
926: }
927:
1.14 albertel 928: sub add_to_queue {
1.31 albertel 929: my ($queue,$slot_name)=@_;
1.49 albertel 930: if ($queue eq 'none') { return 'ok'; }
1.14 albertel 931: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
932: my $cnum=$env{'course.'.$cid.'.num'};
933: my $cdom=$env{'course.'.$cid.'.domain'};
934: my %data;
1.31 albertel 935: $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
936: return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14 albertel 937: }
938:
939: sub show_queue {
1.32 albertel 940: my ($queue,$with_selects)=@_;
1.14 albertel 941: my $result;
942: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
943: my $cnum=$env{'course.'.$cid.'.num'};
944: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 945:
946: my @chosen_sections=
947: &Apache::loncommon::get_env_multiple('form.chosensections');
948: &Apache::grades::init_perm();
949: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
950: &Apache::grades::reset_perm();
1.63 albertel 951: if (!(grep(/^all$/,@chosen_sections))) {
952: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
953: '</tt>.</p> '."\n";
954: }
1.59 albertel 955:
1.16 albertel 956: my $regexp="^$symb\0";
1.30 albertel 957: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 958: my ($tmp)=%queue;
959: if ($tmp=~/^error: 2 /) {
1.33 albertel 960: return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31 albertel 961: }
1.33 albertel 962: $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32 albertel 963: if ($with_selects) { $result.="<th></th>"; }
964: $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 965: foreach my $key (sort(keys(%queue))) {
1.59 albertel 966: my ($symb,$uname,$udom) = &decode_queue_key($key);
967: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.32 albertel 968: if ($key=~/locked$/ && !$with_selects) {
1.16 albertel 969: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 970: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 971: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32 albertel 972: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.16 albertel 973: my ($symb,undef) = split("\0",$key);
974: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 975: $result.="<tr><td>$title</td><td></td>";
1.16 albertel 976: $result.='<td>last queue modification time</td><td>'.
977: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 978: } elsif ($key!~/(timestamp|locked)$/) {
1.16 albertel 979: my $title=&Apache::lonnet::gettitle($symb);
1.32 albertel 980: $result.="<tr>";
1.35 albertel 981: my $slot=$queue{$key}->[0];
982: my %slot_data=&Apache::lonnet::get_slot($slot);
1.32 albertel 983: if ($with_selects) {
984: my $ekey=&Apache::lonnet::escape($key);
985: my ($action,$description)=('select',&mt('Select'));
986: if (exists($queue{"$key\0locked"})) {
987: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
988: if ($me eq $queue{"$key\0locked"}) {
989: ($action,$description)=('resume',&mt('Resume'));
990: } else {
991: ($action,$description)=('unlock',&mt('Unlock'));
992: }
993: }
1.62 albertel 994: my $seclist;
995: foreach my $sec (@chosen_sections) {
996: $seclist.='<input type="hidden" name="chosensections"
997: value="'.$sec.'" />';
998: }
1.35 albertel 999: if (time > $slot_data{'endtime'}) {
1000: $result.=(<<FORM);
1.32 albertel 1001: <td>
1002: <form method="POST">
1003: <input type="hidden" name="gradingkey" value="$ekey" />
1004: <input type="hidden" name="queue" value="$queue" />
1005: <input type="hidden" name="gradingaction" value="$action" />
1006: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 1007: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 1008: <input type="submit" name="submit" value="$description" />
1.62 albertel 1009: $seclist
1.32 albertel 1010: </form>
1011: </td>
1012: FORM
1.35 albertel 1013:
1014: } else {
1015: $result.='<td>'.&mt("In Progress").'</td>'
1016: }
1.32 albertel 1017: }
1018: $result.="<td>$title</td><td>$uname</td>";
1.27 albertel 1019: $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20 albertel 1020: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
1021: "</td></tr>";
1.16 albertel 1022: }
1.14 albertel 1023: }
1.15 albertel 1024: $result.="</table><hr />\n";
1.14 albertel 1025: return $result;
1026: }
1027:
1.34 albertel 1028: sub get_queue_counts {
1029: my ($queue)=@_;
1030: my $result;
1031: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1032: my $cnum=$env{'course.'.$cid.'.num'};
1033: my $cdom=$env{'course.'.$cid.'.domain'};
1034: my $regexp="^$symb\0";
1035: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1036: my ($tmp)=%queue;
1037: if ($tmp=~/^error: 2 /) {
1038: return (0,0,0);
1039: }
1040: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1041: foreach my $key (sort(keys(%queue))) {
1042: if ($key=~/locked$/) {
1043: $locks++;
1044: } elsif ($key=~/timestamp$/) {
1045: #ignore
1046: } elsif ($key!~/(timestamp|locked)$/) {
1047: my ($symb,$uname,$udom) = &decode_queue_key($key);
1048: $entries++;
1049: my $slot=$queue{$key}->[0];
1050: my %slot_data=&Apache::lonnet::get_slot($slot);
1051: if (time > $slot_data{'endtime'}) {
1052: $ready_to_grade++;
1053: }
1054: }
1055: }
1056: return ($entries,$ready_to_grade,$locks);
1057: }
1058:
1.49 albertel 1059: sub encode_queue_key {
1060: my ($symb,$udom,$uname)=@_;
1061: return "$symb\0queue\0$uname\@$udom";
1062: }
1063:
1.14 albertel 1064: sub decode_queue_key {
1065: my ($key)=@_;
1066: my ($symb,undef,$user) = split("\0",$key);
1067: my ($uname,$udom) = split('@',$user);
1068: return ($symb,$uname,$udom);
1069: }
1070:
1071: sub queue_key_locked {
1.30 albertel 1072: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1073: if (!defined($cdom) || !defined($cnum)) {
1074: my (undef,$cid)=&Apache::lonxml::whichuser();
1075: $cnum=$env{'course.'.$cid.'.num'};
1076: $cdom=$env{'course.'.$cid.'.domain'};
1077: }
1.14 albertel 1078: my ($key_locked,$value)=
1.30 albertel 1079: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1080: if ($key_locked eq "$key\0locked") {
1081: return $value;
1082: }
1083: return undef;
1084: }
1085:
1086: sub pick_from_queue_data {
1.30 albertel 1087: my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
1088: foreach my $key (keys(%$queuedata)) {
1.68 albertel 1089: if ($key =~ /\0locked$/) { next; }
1090: if ($key =~ /\0timestamp$/) { next; }
1.14 albertel 1091: my ($symb,$uname,$udom)=&decode_queue_key($key);
1092: if ($check_section) {
1093: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 1094: if ($section eq $check_section) {
1.33 albertel 1095: &Apache::lonxml::debug("my sec");
1.15 albertel 1096: next;
1097: }
1.14 albertel 1098: }
1.30 albertel 1099: my $slot=$queuedata->{$key}[0];
1.14 albertel 1100: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 1101: if ($slot_data{'endtime'} > time) {
1.33 albertel 1102: &Apache::lonxml::debug("not time");
1.15 albertel 1103: next;
1104: }
1.30 albertel 1105: if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33 albertel 1106: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1107: next;
1108: }
1.14 albertel 1109: return $key;
1110: }
1111: return undef;
1112: }
1113:
1.15 albertel 1114: sub find_mid_grade {
1.30 albertel 1115: my ($queue,$symb,$cdom,$cnum)=@_;
1.16 albertel 1116: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 1117: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
1118: if ($todo) {
1.30 albertel 1119: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1120: if ($who eq $me) { return $todo; }
1121: }
1122: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1123: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1124: foreach my $key (keys(%locks)) {
1125: my $who=$locks{$key};
1126: if ($who eq $me) {
1127: $todo=$key;
1128: $todo=~s/\0locked$//;
1129: return $todo;
1130: }
1131: }
1132: return undef;
1133: }
1134:
1.32 albertel 1135: sub lock_key {
1136: my ($queue,$todo)=@_;
1137: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
1138: my (undef,$cid)=&Apache::lonxml::whichuser();
1139: my $cnum=$env{'course.'.$cid.'.num'};
1140: my $cdom=$env{'course.'.$cid.'.domain'};
1141: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1142: $cdom,$cnum);
1.33 albertel 1143: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1144: if ($success eq 'ok') {
1145: return 1;
1146: }
1147: return 0;
1148: }
1149:
1.14 albertel 1150: sub get_from_queue {
1.30 albertel 1151: my ($queue)=@_;
1.14 albertel 1152: my $result;
1153: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1154: my $cnum=$env{'course.'.$cid.'.num'};
1155: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1156: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1157: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1158: if ($todo) { return $todo; }
1.14 albertel 1159: while (1) {
1160: my $starttime=time;
1.30 albertel 1161: &Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14 albertel 1162: $cdom,$cnum);
1.33 albertel 1163: &Apache::lonxml::debug("$starttime");
1.14 albertel 1164: my $regexp="^$symb\0queue\0";
1.30 albertel 1165: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1166: #make a pass looking for a user _not_ in my section
1.14 albertel 1167: if ($env{'request.course.sec'}) {
1.33 albertel 1168: &Apache::lonxml::debug("sce");
1.30 albertel 1169: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1170: \%queue,$cdom,$cnum);
1.33 albertel 1171: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1172: }
1.33 albertel 1173: # no one _not_ in our section so look for any user that is
1174: # ready for grading
1.14 albertel 1175: if (!$todo) {
1.33 albertel 1176: &Apache::lonxml::debug("no sce");
1.31 albertel 1177: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1178: \%queue,$cdom,$cnum);
1.33 albertel 1179: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1180: }
1181: # no user to grade
1182: if (!$todo) { last; }
1.33 albertel 1183: &Apache::lonxml::debug("got $todo");
1.14 albertel 1184: # otherwise found someone so lets try to lock them
1.32 albertel 1185: # unless someone else already picked them
1186: if (!&lock_key($queue,$todo)) { next; }
1.14 albertel 1187: my (undef,$endtime)=
1.30 albertel 1188: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 1189: $cdom,$cnum);
1.33 albertel 1190: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 1191: # someone else already modified the queue,
1192: # perhaps our picked user wass already fully graded between
1193: # when we picked him and when we locked his record? so lets
1194: # double check.
1195: if ($endtime != $starttime) {
1196: my ($key,$value)=
1.30 albertel 1197: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 1198: $cdom,$cnum);
1.33 albertel 1199: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 1200: if ($key eq $todo && ref($value)) {
1201: } else {
1.30 albertel 1202: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 1203: $cdom,$cnum);
1.33 albertel 1204: &Apache::lonxml::debug("del");
1.14 albertel 1205: next;
1206: }
1207: }
1.33 albertel 1208: &Apache::lonxml::debug("last $todo");
1.14 albertel 1209: last;
1210: }
1211: return $todo;
1212: }
1213:
1.49 albertel 1214: sub select_user {
1215: my ($symb,$cid)=&Apache::lonxml::whichuser();
1216:
1.59 albertel 1217: my @chosen_sections=
1218: &Apache::loncommon::get_env_multiple('form.chosensections');
1.49 albertel 1219: &Apache::grades::init_perm();
1.59 albertel 1220: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1.49 albertel 1221: &Apache::grades::reset_perm();
1.63 albertel 1222:
1223: my $result;
1224: if (!(grep(/^all$/,@chosen_sections))) {
1225: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1226: '</tt>.</p> '."\n";
1227: }
1228: $result.='<table border="1">';
1.49 albertel 1229:
1230: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1231: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 1232:
1.49 albertel 1233: my %status = &get_student_status($symb,$cid,$udom,$uname);
1234: my $queue = 'none';
1.58 albertel 1235: my $cannot_grade;
1236: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1237: $queue = 'reviewqueue';
1.58 albertel 1238: if ($status{'reviewqueue'} eq 'in_progress') {
1239: $cannot_grade=1;
1240: }
1241: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1242: $queue = 'gradingqueue';
1.58 albertel 1243: if ($status{'gradingqueue'} eq 'in_progress') {
1244: $cannot_grade=1;
1245: }
1.49 albertel 1246: }
1247: my $todo =
1248: &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 1249: if ($cannot_grade) {
1250: $result.='<tr><td> </td><td>'.$fullname->{$student}.
1251: '</td><td>';
1252: } else {
1.62 albertel 1253: my $seclist;
1254: foreach my $sec (@chosen_sections) {
1255: $seclist.='<input type="hidden" name="chosensections"
1256: value="'.$sec.'" />';
1257: }
1.58 albertel 1258: $result.=<<RESULT;
1.49 albertel 1259: <tr>
1260: <td>
1261: <form method="POST">
1262: <input type="hidden" name="gradingkey" value="$todo" />
1263: <input type="hidden" name="queue" value="$queue" />
1264: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 1265: <input type="hidden" name="regrade" value="yes" />
1.62 albertel 1266: <input type="submit" name="submit" value="Regrade" />
1267: $seclist
1.49 albertel 1268: </form>
1269: <td>$fullname->{$student}</td>
1270: <td>
1271: RESULT
1.58 albertel 1272: }
1.49 albertel 1273: if ($status{'status'} eq 'pass') {
1274: $result .= '<font color="green">'.&mt('Passed').'</font>';
1275: } elsif ($status{'status'} eq 'fail') {
1276: $result .= '<font color="red">'.&mt('Failed').'</font>';
1277: } elsif ($status{'status'} eq 'review') {
1278: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1279: } elsif ($status{'status'} eq 'ungraded') {
1280: $result .= &mt('Ungraded');
1281: } elsif ($status{'status'} ne '') {
1282: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1283: } else {
1284: $result.=" ";
1285: }
1286: if ($status{'version'}) {
1287: $result .= ' '.&mt('Version').' '.$status{'version'};
1288: }
1289: $result.= '</td><td>';
1290: if ($status{'reviewqueue'} eq 'enqueued') {
1291: $result .= &mt('Awaiting Review');
1292: } elsif ($status{'reviewqueue'} eq 'locked') {
1293: $result .= &mt('Under Review');
1.58 albertel 1294: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1295: $result .= &mt('Still being worked on.');
1.49 albertel 1296: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1297: $result .= &mt('Awaiting Grading');
1298: } elsif ($status{'gradingqueue'} eq 'locked') {
1299: $result .= &mt('Being Graded');
1.58 albertel 1300: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1301: $result .= &mt('Still being worked on.');
1.49 albertel 1302: } else {
1303: $result.=" ";
1304: }
1305: $result.= '</td></tr>';
1306: }
1307: $result.='</table>';
1308: return $result;
1309: }
1310:
1311: sub get_student_status {
1312: my ($symb,$cid,$udom,$uname)=@_;
1313: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1314: $udom,$uname);
1315: my %status;
1316: $status{'status'}=$record{'resource.status'};
1317: $status{'version'}=$record{'resource.version'};
1318: $status{'grader'}=$record{'resource.grader'};
1319: $status{'reviewqueue'}=&check_queue_for_key($cid,'reviewqueue',
1320: &encode_queue_key($symb,$udom,$uname));
1321: $status{'gradingqueue'}=&check_queue_for_key($cid,'gradingqueue',
1322: &encode_queue_key($symb,$udom,$uname));
1323: return %status;
1324: }
1325:
1.1 albertel 1326: sub start_ClosingParagraph {
1327: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1328: my $result;
1329: if ($target eq 'web') {
1.13 albertel 1330: } elsif ($target eq 'webgrade') {
1331: &Apache::lonxml::startredirection();
1.1 albertel 1332: }
1333: return $result;
1334: }
1335:
1336: sub end_ClosingParagraph {
1337: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1338: my $result;
1339: if ($target eq 'web') {
1.13 albertel 1340: } elsif ($target eq 'webgrade') {
1341: &Apache::lonxml::endredirection();
1.1 albertel 1342: }
1343: return $result;
1344: }
1345:
1.19 albertel 1346: sub get_id {
1347: my ($parstack,$safeeval)=@_;
1348: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1349: if (!$id) { $id=$Apache::lonxml::curdepth; }
1350: return $id;
1351: }
1352:
1.1 albertel 1353: my %dimension;
1354: sub start_Dimension {
1355: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1356: undef(%dimension);
1.19 albertel 1357: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 1358: $Apache::bridgetask::dimension=$dim_id;
1359: push(@Apache::bridgetask::dimensionlist,$dim_id);
1360: undef(@Apache::bridgetask::instance);
1.20 albertel 1361: $Apache::bridgetask::dimensionmandatory{$dim_id}=
1362: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.54 albertel 1363: &Apache::lonxml::startredirection();
1364: return &internal_location($dim_id);
1.1 albertel 1365: }
1366:
1.13 albertel 1367: sub get_instance {
1368: &Apache::response::pushrandomnumber();
1369: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29 albertel 1370: my $num=@order;
1371: my $version=&get_version();
1372: my $which=($version-1)%$num;
1373: return $order[$which];
1.13 albertel 1374: }
1375:
1.18 albertel 1376: {
1377: my $last_link;
1378: sub end_Dimension {
1379: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54 albertel 1380: my $result=&Apache::lonxml::endredirection();
1.25 albertel 1381: my $dim=&get_id($parstack,$safeeval);
1.19 albertel 1382: my $instance=&get_instance();
1.25 albertel 1383: my $version=&get_version();
1.18 albertel 1384: if ($target eq 'web') {
1.47 albertel 1385: @Apache::scripttag::parser_env = @_;
1386: $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1387: @Apache::scripttag::parser_env = @_;
1388: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.26 albertel 1389: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
1390: $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.54 albertel 1391:
1392: my $dim_status=$Apache::lonhomework::history{"resource.$version.$dim.status"};
1393: my $mandatory='Mandatory';
1394: if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
1395: $mandatory='Optional';
1396: }
1397: my $dim_info="<div class='$dim_status'>\n";
1398: if ($dim_status eq 'pass') {
1399: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1400: }
1401: if ($dim_status eq 'fail') {
1402: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1403: }
1404: my $man_count=0;
1.65 albertel 1405: my $man_passed=0;
1.54 albertel 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++;
1.65 albertel 1417: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
1418: $man_passed++;
1419: }
1.54 albertel 1420: }
1421: }
1.65 albertel 1422: if ($man_passed eq $man_count) { $man_passed='all'; }
1.66 albertel 1423: my $opt_req=$dimension{$instance.'.optionalrequired'};
1.54 albertel 1424: if ($opt_req !~ /\S/) { $opt_req='0'; }
1.65 albertel 1425: $dim_info.="\n<p>".&mt('You passed [_1] of the [_2] mandatory components and [_3] of the [_4] optional components, of which you were required to pass [_5].',$man_passed,$man_count,$opt_passed,$opt_count,$opt_req)."</p>\n</div>";
1.54 albertel 1426:
1427: my $internal_location=&internal_location($dim);
1428: $result=~s/\Q$internal_location\E/$dim_info/;
1429:
1.22 albertel 1430: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1431: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1432: my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.53 albertel 1433: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1434: if ($mandatory) {
1435: $mandatory='Mandatory';
1436: } else {
1437: $mandatory='Optional';
1438: }
1.22 albertel 1439: if ($status eq 'fail') {
1440: } elsif ($status eq 'pass') {
1441: } else {
1.49 albertel 1442: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
1.22 albertel 1443: }
1.53 albertel 1444: my $status_display=$status;
1445: $status_display=~s/^([a-z])/uc($1)/e;
1.54 albertel 1446: @Apache::scripttag::parser_env = @_;
1.53 albertel 1447: $result.='<div class="'.$status.'"><h4>'.$mandatory.
1.54 albertel 1448: ' Criteria</h4><p>';
1449: @Apache::scripttag::parser_env = @_;
1450: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
1451: $result.='</p><p class="grade">'.$status_display.'</p>';
1.25 albertel 1452: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
1.53 albertel 1453: $result.='<p class="comment">'.$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</p>';
1.22 albertel 1454: }
1.53 albertel 1455: $result.='</div>';
1.22 albertel 1456: }
1457: }
1.18 albertel 1458: } elsif ($target eq 'webgrade') {
1.47 albertel 1459: # in case of any side effects that we need
1460: @Apache::scripttag::parser_env = @_;
1461: &Apache::scripttag::xmlparse($dimension{'intro'});
1462: @Apache::scripttag::parser_env = @_;
1463: &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1.18 albertel 1464: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1465: my $link='criteria_'.$instance.'_'.$id;
1.25 albertel 1466: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19 albertel 1467: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 1468: '<a name="'.$link.'" />'.
1469: '<a name="next_'.$last_link.'" />'.
1.47 albertel 1470: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">';
1471: @Apache::scripttag::parser_env = @_;
1472: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
1473: $result.='</textarea>'.
1.18 albertel 1474: #$dimension{$instance.'.criteria.'.$id}.
1475: '</td>'.
1.19 albertel 1476: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25 albertel 1477: '<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 1478: '</td>'.
1479: '<td>'.
1.47 albertel 1480: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label></nobr><br />'.
1.30 albertel 1481: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
1482: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
1483: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18 albertel 1484: '</td>'.
1485: '<td>'.
1486: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 1487: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
1488: '<input type="submit" name="next" value="'.
1489: &mt('Done').'" /> '.
1.30 albertel 1490: '<input type="submit" name="stop" value="'.
1491: &mt('Stop').'" /> '.
1.18 albertel 1492: '</td></tr>';
1.22 albertel 1493: $result.='<tr><td colspan="4">';
1494: my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
1.52 albertel 1495: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.43 albertel 1496: foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"})) {
1.22 albertel 1497: my $file=$file_url.$partial_file;
1.52 albertel 1498: $file=~s|/+|/|g;
1.22 albertel 1499: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.48 albertel 1500: $result.='<nobr><a href="'.$file.'" target="lonGRDs"><img src="'.
1.22 albertel 1501: &Apache::loncommon::icon($file).'" border=0"> '.$file.
1.48 albertel 1502: '</a></nobr> ';
1.22 albertel 1503: }
1504: $result.='</td></tr>';
1.18 albertel 1505: $last_link=$link;
1506: }
1.22 albertel 1507: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 1508: my $optional_passed=0;
1.20 albertel 1509: my $mandatory_failed=0;
1510: my $ungraded=0;
1511: my $review=0;
1.19 albertel 1512: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 1513: my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
1514: $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 1515: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
1516: if ($status eq 'pass') {
1517: if (!$mandatory) { $optional_passed++; }
1518: } elsif ($status eq 'fail') {
1519: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 1520: } elsif ($status eq 'review') {
1521: $review++;
1.20 albertel 1522: } elsif ($status eq 'ungraded') {
1523: $ungraded++;
1.21 albertel 1524: } else {
1.47 albertel 1525: $ungraded++;
1.19 albertel 1526: }
1527: }
1.20 albertel 1528: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
1529: $mandatory_failed++;
1530: }
1.21 albertel 1531: &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 1532: if ($review) {
1.25 albertel 1533: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1534: 'review';
1.20 albertel 1535: } elsif ($ungraded) {
1.25 albertel 1536: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1537: 'ungraded';
1.20 albertel 1538: } elsif ($mandatory_failed) {
1.25 albertel 1539: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1540: 'fail';
1.20 albertel 1541: } else {
1.25 albertel 1542: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 1543: 'pass';
1.20 albertel 1544: }
1.69 ! albertel 1545: } else {
! 1546: # any other targets no output
! 1547: undef($result);
1.13 albertel 1548: }
1.18 albertel 1549: return $result;
1.1 albertel 1550: }
1551: }
1552:
1553: sub start_IntroParagraph {
1554: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1555: my $result;
1.13 albertel 1556: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1557: if ($tagstack->[-2] eq 'Dimension') {
1558: $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser);
1559:
1560: } elsif ($target eq 'webgrade') {
1561: &Apache::lonxml::get_all_text('/introparagraph',$parser);
1.1 albertel 1562: }
1.47 albertel 1563:
1.1 albertel 1564: }
1565: return $result;
1566: }
1567:
1568: sub end_IntroParagraph {
1569: }
1570:
1571: sub start_Instance {
1572: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 1573: my $id=&get_id($parstack,$safeeval);
1574: push(@{$dimension{'instances'}},$id);
1575: push(@Apache::bridgetask::instance,$id);
1576: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 1577: $dimension{$id.'.optionalrequired'}=
1.19 albertel 1578: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 1579: return '';
1580: }
1581:
1582: sub end_Instance {
1583: }
1584:
1585: sub start_InstanceText {
1586: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 albertel 1587: my $instance_id=$Apache::bridgetask::instance[-1];
1588: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser);
1.13 albertel 1589: if ($target eq 'web' || $target eq 'webgrade') {
1.47 albertel 1590: $dimension{$instance_id.'.text'}=$text;
1.1 albertel 1591: }
1592: return '';
1593: }
1594:
1595: sub end_InstanceText {
1596: return '';
1597: }
1598:
1599: sub start_Criteria {
1600: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1601: my $instance_id=$Apache::bridgetask::instance[-1];
1.47 albertel 1602: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser);
1.21 albertel 1603: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.19 albertel 1604: my $id=&get_id($parstack,$safeeval);
1.1 albertel 1605: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 1606: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
1607: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 1608: push(@{$dimension{$instance_id.'.criterias'}},$id);
1609: }
1610: return '';
1611: }
1612:
1.47 albertel 1613: sub end_Criteria {
1614: }
1615:
1.4 albertel 1616: sub proctor_validation_screen {
1617: my ($slot) = @_;
1618: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 1619: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 1620: my $name=&Apache::loncommon::plainname($user,$domain);
1621:
1.4 albertel 1622: my $msg;
1.11 albertel 1623: if ($env{'form.proctorpassword'}) {
1.4 albertel 1624: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
1625: .'</font></p>';
1626: }
1.47 albertel 1627: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 1628: my $result= (<<ENDCHECKOUT);
1629: <h2>Proctor Validation</h2>
1630: <p>Your room's proctor needs to validate your access to this resource.</p>
1631: $msg
1.11 albertel 1632: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 1633: <input type="hidden" name="validate" value="yes" />
1634: <input type="hidden" name="submitted" value="yes" />
1635: <table>
1.44 albertel 1636: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 1637: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 1638: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 1639: </table>
1640: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 1641: <table border="1">
1642: <tr><td>
1643: <table>
1644: <tr><td colspan="2">Student who should be logged in is:</td></tr>
1645: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 1646: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.44 albertel 1647: <tr><td>Usename</td><td>$user\@$domain</td></tr>
1648: <tr><td colspan="2"><img src="$url" /></td></tr>
1649: </table>
1650: </tr></td>
1651: </table>
1.4 albertel 1652: </form>
1653: ENDCHECKOUT
1654: return $result;
1655: }
1656:
1.1 albertel 1657: 1;
1658: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>