File:
[LON-CAPA] /
loncom /
homework /
bridgetask.pm
Revision
1.194:
download - view:
text,
annotated -
select for diffs
Tue Nov 7 19:43:37 2006 UTC (17 years, 9 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- <Criteria> can be directly inside of a <Task> now
- <Task> status is in a separate <div>
- <Criteria> all are shown at the top of the question/task
- factored out some of the <Criteria> display code for reuse
1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
4: # $Id: bridgetask.pm,v 1.194 2006/11/07 19:43:37 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30:
31: package Apache::bridgetask;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::File();
36: use Apache::lonmenu;
37: use Apache::lonlocal;
38: use Apache::lonxml;
39: use Apache::slotrequest();
40: use Time::HiRes qw( gettimeofday tv_interval );
41: use lib '/home/httpd/lib/perl/';
42: use LONCAPA;
43:
44:
45: BEGIN {
46: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','GraderNote','ClosingParagraph'));
47: }
48:
49: my %dimension;
50: my $top = 'top';
51:
52: sub initialize_bridgetask {
53: # id of current Dimension, 0 means that no dimension is current
54: # (inside <Task> only)
55: @Apache::bridgetask::dimension=();
56: # list of all current Instance ids
57: %Apache::bridgetask::instance=();
58: # list of all Instance ids seen in this problem
59: @Apache::bridgetask::instancelist=();
60: # key of queud user data that we are currently grading
61: $Apache::bridgetask::queue_key='';
62: undef(%dimension);
63: }
64:
65: sub proctor_check_auth {
66: my ($slot_name,$slot,$type)=@_;
67: my $user=$env{'form.proctorname'};
68: my $domain=$env{'form.proctordomain'};
69:
70: my @allowed=split(",",$slot->{'proctor'});
71: foreach my $possible (@allowed) {
72: my ($puser,$pdom)=(split(':',$possible));
73: if ($puser eq $user && $pdom eq $domain) {
74: my $authenticated=0;
75: if ( $slot->{'secret'} =~ /\S/ &&
76: $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
77: $authenticated=1;
78: } else {
79:
80: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
81: if ($authhost ne 'no_host') {
82: $authenticated=1;
83: }
84: }
85: if ($authenticated) {
86: &check_in($type,$user,$domain,$slot_name);
87: return 1;
88: }
89: }
90: }
91: return 0;
92: }
93:
94: sub check_in {
95: my ($type,$user,$domain,$slot_name) = @_;
96: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
97: if ( $useslots eq 'map_map') {
98: &check_in_sequence($user,$domain,$slot_name);
99: } else {
100: &create_new_version($type,$user,$domain,$slot_name);
101: }
102: return 1;
103: }
104:
105: sub check_in_sequence {
106: my ($user,$domain,$slot_name) = @_;
107: my $navmap = Apache::lonnavmaps::navmap->new();
108: my ($symb) = &Apache::lonnet::whichuser();
109: my ($map) = &Apache::lonnet::decode_symb($symb);
110: my @resources =
111: $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
112: my %old_history = %Apache::lonhomework::history;
113: my %old_results = %Apache::lonhomework::results;
114:
115: foreach my $res (@resources) {
116: &Apache::lonxml::debug("doing ".$res->src);
117: &Apache::structuretags::initialize_storage($res->symb);
118: my $type = ($res->is_task()) ? 'Task' : 'problem';
119: &create_new_version($type,$user,$domain,$slot_name);
120: &Apache::structuretags::finalize_storage($res->symb);
121: }
122:
123: %Apache::lonhomework::history = %old_history;
124: %Apache::lonhomework::results = %old_results;
125: }
126:
127: sub create_new_version {
128: my ($type,$user,$domain,$slot_name) = @_;
129:
130: my $id = '0';
131: if ($type eq 'Task') {
132: # increment version
133: my $version=
134: $Apache::lonhomework::history{'resource.0.version'};
135: $version++;
136: &Apache::lonxml::debug("Making version $version");
137: #clean out all current results
138: foreach my $key (keys(%Apache::lonhomework::history)) {
139: if ($key=~/^resource\.0\./) {
140: $Apache::lonhomework::results{$key}='';
141: }
142: }
143:
144: #setup new version and who did it
145: $Apache::lonhomework::results{'resource.0.version'}=$version;
146: $id = "$version.0";
147: if (!defined($user) || !defined($domain)) {
148: $user = $env{'user.name'};
149: $domain = $env{'user.domain'};
150: }
151:
152: } elsif ($type eq 'problem') {
153: &Apache::lonxml::debug("authed $slot_name");
154: }
155: if (!defined($user) || !defined($domain)) {
156: $user = $env{'user.name'};
157: $domain = $env{'user.domain'};
158: }
159:
160: $Apache::lonhomework::results{"resource.$id.checkedin"}=
161: $user.':'.$domain;
162:
163: if (defined($slot_name)) {
164: $Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
165: $slot_name;
166: }
167: }
168:
169: sub get_version {
170: my ($version,$previous);
171: if ($env{'form.previousversion'} &&
172: $env{'form.previousversion'} ne 'current' &&
173: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
174: $version=$env{'form.previousversion'};
175: $previous=1;
176: } else {
177: if (defined($Apache::lonhomework::results{'resource.0.version'})) {
178: $version=$Apache::lonhomework::results{'resource.0.version'};
179: } elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
180: $version=$Apache::lonhomework::history{'resource.0.version'};
181: }
182: $previous=0;
183: }
184: if (wantarray) {
185: return ($version,$previous);
186: }
187: return $version;
188: }
189:
190: sub add_previous_version_button {
191: my ($status)=@_;
192: my $result;
193: if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
194: return '';
195: }
196: if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
197: $status ne 'NEEDS_CHECKIN') {
198: return '';
199: }
200: my $version=&get_version();
201: if ($env{'form.previousversion'} ne '' &&
202: $env{'form.previousversion'} eq $version) {
203: $result.="<h3>".&mt("Showing previous version [_1]",$version).
204: "</h3>\n";
205: }
206: my @to_show;
207: foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
208: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
209: push(@to_show,$test_version);
210: }
211: }
212: my $list='<option>'.
213: join("</option>\n<option>",@to_show).
214: "</option>\n";
215: $list.='<option value="current">'.&mt('Current').'</option>';
216: $result.='<form name="getprevious" method="post" action="';
217: my $uri=$env{'request.uri'};
218: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
219: $result.=$uri.'">'.
220: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
221: <option>'.&mt('Pick one').'</option>
222: '.$list.'
223: </select>')."</form>";
224: return $result;
225: }
226:
227: sub add_grading_button {
228: my (undef,$cid)=&Apache::lonnet::whichuser();
229: my $cnum=$env{'course.'.$cid.'.num'};
230: my $cdom=$env{'course.'.$cid.'.domain'};
231: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
232:
233: my $size=5;
234: if (scalar(keys(%sections)) < 3) {
235: $size=scalar(keys(%sections))+2;
236: }
237: my $sec_select = '<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
238: $sec_select .= "<option value='all' selected='selected'>all</option>\n";
239: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
240: $sec_select .= "<option value=\"$sec\">$sec</option>\n";
241: }
242: $sec_select .= "<option value='none'>none</option></select>\n";
243:
244: my $result=' <input type="submit" name="gradeasubmission" value="'.
245: &mt("Get a submission to grade").'" />';
246: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
247: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
248: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
249: $result.='<table><tr>';
250: $result.='<td rowspan="4">Specify a section: </td><td rowspan="4">'.$sec_select.'</td>';
251: $result.='<td>'.' <input type="submit" name="reviewagrading" value="'.
252: &mt("Select an entry from the grading queue:").'" /> ';
253:
254: $result.= &mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).' </td></tr>'."\n";
255:
256: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
257: $result.='<tr><td>'.
258: ' <input type="submit" name="reviewasubmission" value="'.
259: &mt("Select an entry from the review queue:").'" /> ';
260: $result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
261: $entries,$ready,$locks).'</td></tr>'."\n";
262: $result.='<tr><td> <input type="submit" name="regradeasubmission" value="'.
263: &mt("List of user's grade status").'" /> </td></tr></table>'."\n";
264: $result.='<p> <input type="submit" name="regradeaspecificsubmission" value="'.
265: &mt("Regrade specific user:").'" />'."\n";
266: $result.='<input type="text" size="12" name="gradinguser" />';
267: $result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
268: 'gradingdomain');
269: $result.=' '.
270: &Apache::loncommon::selectstudent_link('gradesubmission',
271: 'gradinguser',
272: 'gradingdomain');
273: $result.=&Apache::loncommon::studentbrowser_javascript();
274: $result.= '</p>';
275: }
276: return $result;
277: }
278:
279: sub add_request_another_attempt_button {
280: my ($text)=@_;
281: if (!$text) { $text="Request another attempt"; }
282: my $result;
283: my $symb=&Apache::lonnet::symbread();
284: # not a slot access based resource
285: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
286: if ($useslots =~ /^\s*no\s*$/i) {
287: return '';
288: }
289:
290: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
291: my $action='get_reservation';
292: if ($slot_name) {
293: $text="Change reservation.";
294: $action='change_reservation';
295: my $description=&Apache::slotrequest::get_description($slot_name,
296: $slot);
297: $result.=(<<STUFF);
298: <p> Will be next available: $description </p>
299: STUFF
300: }
301:
302: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
303: $symb=&escape($symb);
304: $result.='<form method="post" action="/adm/slotrequest">'.
305: '<input type="hidden" name="symb" value="'.$symb.'" />'.
306: '<input type="hidden" name="command" value="'.$action.'" />'.
307: '<input type="submit" name="requestattempt" value="'.
308: &mt($text).'" />'.
309: '</form>';
310: return $result;
311: }
312:
313: sub preserve_grade_info {
314: my $result;
315: # if we are viewing someone else preserve that info
316: if (defined $env{'form.grade_symb'}) {
317: foreach my $field ('symb','courseid','domain','username') {
318: $result .= '<input type="hidden" name="grade_'.$field.
319: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
320: }
321: }
322: return $result;
323: }
324:
325: sub style {
326: my ($target) = @_;
327: if ($target eq 'web'
328: || $target eq 'webgrade') {
329: my $style = (<<STYLE);
330: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
331: STYLE
332: if ($env{'browser.type'} eq 'explorer'
333: && $env{'browser.os'} eq 'win' ) {
334: if ($env{'browser.version'} < 7) {
335: $style .= (<<STYLE);
336: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie.css" />
337: STYLE
338: } else {
339: $style .= (<<STYLE);
340: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie7.css" />
341: STYLE
342: }
343: }
344: return $style;
345: }
346: return;
347: }
348:
349: sub show_task {
350: my ($status,$previous)=@_;
351: if (!$previous && (
352: ( $status eq 'CLOSED' ) ||
353: ( $status eq 'BANNED') ||
354: ( $status eq 'UNAVAILABLE') ||
355: ( $status eq 'NOT_IN_A_SLOT') ||
356: ( $status eq 'NEEDS_CHECKIN') ||
357: ( $status eq 'WAITING_FOR_GRADE') ||
358: ( $status eq 'INVALID_ACCESS') ||
359: ( &get_version() eq ''))) {
360: return 0;
361: }
362: if ($env{'form.donescreen'}) { return 0; }
363: return 1;
364: }
365:
366: my @delay;
367: sub nest {
368: if (@delay) {
369: return $delay[-1];
370: } else {
371: return;
372: }
373: }
374:
375: sub nested_parse {
376: my ($str,$env,$args) = @_;
377: my @old_env = @Apache::scripttag::parser_env;
378: @Apache::scripttag::parser_env = @$env;
379: if (exists($args->{'set_dim_id'})) {
380: &enable_dimension_parsing($args->{'set_dim_id'});
381: }
382: push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
383: my $result = &Apache::scripttag::xmlparse($$str);
384: pop(@delay);
385: if (exists($args->{'set_dim_id'})) {
386: &disable_dimension_parsing();
387: }
388: @Apache::scripttag::parser_env = @old_env;
389: if ($args->{'delayed_dim_results'}) {
390: my $dim = &get_dim_id();
391: &Apache::lonxml::debug(" tossing out $result ");
392: &Apache::lonxml::debug(" usining out $dim 's ". $dimension{$dim}{'result'});
393: return $dimension{$dim}{'result'};
394: }
395: return $result;
396: }
397:
398: sub internal_location {
399: my ($id)=@_;
400: return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
401: }
402:
403: sub submission_time_stamp {
404: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
405: my $submissiontime;
406: my $version=$Apache::lonhomework::history{'resource.0.version'};
407: for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
408: if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})
409: && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
410: $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
411: last;
412: }
413: }
414: my $result;
415: if ($submissiontime) {
416: my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
417: my %slot=&Apache::lonnet::get_slot($slot_name);
418: my $diff = $slot{'endtime'} - $submissiontime;
419: my ($color,$when)=('#FF6666','after');
420: if ($diff > 0) { ($color,$when)=('#336600','before'); }
421: my $info;
422: $diff = abs($diff);
423: if ($diff%60) { $info=($diff%60).' seconds'; }
424: $diff=int($diff/60);
425: if ($diff%60) { $info=($diff%60).' minutes '.$info; }
426: $diff=int($diff/60);
427: if ($diff) { $info=$diff.' hours '.$info; }
428: $result='<p><font color="'.$color.'">'.
429: &mt('Student submitted [_1] [_2] the deadline. '.
430: '(Submission was at [_3], end of period was [_4].)',
431: $info,$when,
432: &Apache::lonlocal::locallocaltime($submissiontime),
433: &Apache::lonlocal::locallocaltime($slot{'endtime'})).
434: '</font></p>';
435: }
436: return $result;
437: }
438:
439: sub file_list {
440: my ($files,$uname,$udom) = @_;
441: if (!defined($uname) || !defined($udom)) {
442: (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
443: }
444: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
445:
446: my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
447: foreach my $partial_file (split(',',$files)) {
448: my $file=$file_url.$partial_file;
449: $file=~s|/+|/|g;
450: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
451: $file_list.='<li><span style="white-space: nowrap;"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
452: &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
453: '</a></span></li>'."\n";
454: }
455: $file_list.="</ul>\n";
456: return $file_list;
457: }
458:
459: sub grade_mode {
460: if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
461: return 'regrade';
462: }
463: return 'queue_grade';
464: }
465:
466: sub webgrade_standard_info {
467: my ($version)=&get_version();
468:
469: my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
470:
471: my %lt=('done' => 'Next Item',
472: 'stop' => 'Quit Grading',
473: 'fail' => 'Fail Rest',
474: 'cancel' => 'Cancel',
475: );
476: %lt=&Apache::lonlocal::texthash(%lt);
477:
478: my $result=<<INFO;
479: <div class="LC_GRADING_maincontrols">
480: INFO
481:
482: if (&grade_mode() eq 'regrade') {
483: $result.=<<INFO;
484: <input type="submit" name="cancel" value="$lt{'cancel'}" />
485: INFO
486: }
487:
488: $result.=<<INFO;
489: <input type="submit" name="next" value="$lt{'done'}" />
490: <input type="submit" name="stop" value="$lt{'stop'}" />
491: <input type="button" name="fail" value="$lt{'fail'}"
492: onclick="javascript:onFailRest()" />
493: </div>
494: $file_list
495: INFO
496: return $result;
497: }
498:
499: sub done_screen {
500: my ($version) = @_;
501: my $title=&Apache::lonnet::gettitle();
502: my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
503: my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
504: my $files = '<ul>';
505: my $msg;
506: foreach my $file (@files) {
507: my $url="/uploaded/$domain/$user/portfolio$file";
508: if (! &Apache::lonnet::stat_file($url)) {
509: $file = &mt('<span class="LC_error"> Nonexistent file:</span> '.
510: '<span class="LC_filename">[_1]</span>',$file);
511: $msg .= "<p>Submitted non-existant file $file</p>\n";
512: } else {
513: $file = '<span class="LC_filename">'.$file.'</span>';
514: $msg .= "<p>Submitted file $file</p>\n";
515: }
516: $files .= '<li>'.$file.'</li>';
517: }
518: $files.='</ul>';
519: my $subject = "Submission message for $title";
520: my ($message_status,$comment_status);
521: my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
522: $setting =~ s/^\s*(\S*)\s*$/$1/;
523: $setting = lc($setting);
524: if ($setting eq 'only_student'
525: || $setting eq 'student_and_user_notes_screen') {
526: $message_status =
527: &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
528: $message_status = '<p>'.&mt('Message sent to user: [_1]',
529: $message_status).' </p>';
530: }
531: if ($setting eq 'student_and_user_notes_screen') {
532: $comment_status =
533: &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
534: $msg,$user,$domain);
535: $comment_status = '<p>'.&mt('Message sent to instructor: [_1]',
536: $comment_status).' </p>';
537: }
538: return <<DONESCREEN;
539: <h2>$title</h2>
540: <p> Files submitted: $files </p>
541: <p> You are now done with this Bridge Task </p>
542: <hr />
543: <p> <a href="/adm/logout">Logout</a> </p>
544: <p> <a href="/adm/roles">Change to a different course</a> </p>
545: $message_status
546: $comment_status
547: DONESCREEN
548:
549: }
550:
551: sub start_Task {
552: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
553:
554: my ($status,$accessmsg,$slot);
555: &Apache::structuretags::init_problem_globals('Task');
556: if ($target ne 'webgrade') {
557: &Apache::structuretags::initialize_storage();
558: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
559: if ($env{'request.state'} eq 'construct') {
560: &Apache::structuretags::setup_rndseed($safeeval);
561: }
562: }
563:
564: $Apache::lonhomework::parsing_a_task=1;
565:
566: my $name;
567: if ($target eq 'web' || $target eq 'webgrade') {
568: $name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
569: }
570:
571: my ($result,$form_tag_start);
572: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
573: || $target eq 'edit') {
574: ($result,$form_tag_start) =
575: &Apache::structuretags::page_start($target,$token,$tagstack,
576: $parstack,$parser,$safeeval,
577: $name,&style($target));
578: $result .= '<div class="LC_task">'."\n";
579: }
580:
581: if ($target eq 'web' && $env{'request.state'} ne 'construct') {
582: if ($Apache::lonhomework::queuegrade
583: || $Apache::lonhomework::modifygrades) {
584: $result.='<form name="gradesubmission" method="post" action="';
585: my $uri=$env{'request.uri'};
586: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
587: $result.=$uri.'">'.&add_grading_button()."</form>";
588: my $symb=&Apache::lonnet::symbread();
589: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
590: $result.='<form method="post" name="slotrequest" action="/adm/slotrequest">'.
591: '<input type="hidden" name="symb" value="'.$symb.'" />'.
592: '<input type="hidden" name="command" value="showslots" />'.
593: '<input type="submit" name="requestattempt" value="'.
594: &mt('Show Slot list').'" />'.
595: '</form>';
596: my $target_id =
597: &Apache::lonstathelpers::make_target_id({symb => $symb,
598: part => '0'});
599: $result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
600: '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
601: '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
602: '<input type="submit" name="grading" value="'.
603: &mt('Show Grading Status').'" />'.
604: '</form>';
605: }
606: }
607: }
608: if ($target eq 'web' && $env{'request.state'} eq 'construct') {
609: $form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
610: }
611: if ($target eq 'web'
612: || ($target eq 'grade' && !$env{'form.webgrade'})
613: || $target eq 'answer'
614: || $target eq 'tex') {
615: my ($version,$previous)=&get_version();
616: ($status,$accessmsg,my $slot_name,$slot) =
617: &Apache::lonhomework::check_slot_access('0','Task');
618: if ($status eq 'CAN_ANSWER' && $version eq '') {
619: # CAN_ANSWER mode, and no current version, unproctored access
620: # thus self-checkedin
621: &check_in('Task',undef,undef,$slot_name);
622: &add_to_queue('gradingqueue',{'type' => 'Task',
623: 'time' => time,
624: 'slot' => $slot_name});
625: ($version,$previous)=&get_version();
626: }
627:
628: push(@Apache::inputtags::status,$status);
629: $Apache::inputtags::slot_name=$slot_name;
630: my $expression='$external::datestatus="'.$status.'";';
631: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
632: &Apache::run::run($expression,$safeeval);
633: &Apache::lonxml::debug("Got $status");
634: $result.=&add_previous_version_button($status);
635: if (!&show_task($status,$previous)) {
636: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
637: if ( $target eq "web" ) {
638: if ($env{'request.state'} eq 'construct') {
639: $result.=$form_tag_start;
640: }
641: my $msg;
642: if ($status eq 'UNAVAILABLE') {
643: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
644: } elsif ($status eq 'NOT_IN_A_SLOT') {
645: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
646: $msg.=&add_request_another_attempt_button("Sign up for time to work.");
647: } elsif ($status eq 'NEEDS_CHECKIN') {
648: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
649: '</h1>'.&proctor_validation_screen($slot);
650: } elsif ($status eq 'WAITING_FOR_GRADE') {
651: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
652: } elsif ($env{'form.donescreen'}) {
653: $result .= &done_screen($version);
654: } elsif ($status ne 'NOT_YET_VIEWED') {
655: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
656: }
657: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
658: $msg.='The problem '.$accessmsg;
659: }
660: $result.=$msg.'<br />';
661: } elsif ($target eq 'tex') {
662: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
663: if ($status eq 'UNAVAILABLE') {
664: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
665: } else {
666: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
667: }
668: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
669: if ($status eq 'NEEDS_CHECKIN') {
670: if(&proctor_check_auth($slot_name,$slot,'Task')
671: && defined($Apache::inputtags::slot_name)) {
672: my $result=
673: &add_to_queue('gradingqueue',
674: {'type' => 'Task',
675: 'time' => time,
676: 'slot' =>
677: $Apache::inputtags::slot_name});
678: &Apache::lonxml::debug("add_to_queue said $result");
679: }
680: }
681: }
682: } elsif ($target eq 'web') {
683:
684: $result.=&preserve_grade_info();
685: $result.=&internal_location();
686: $result.=$form_tag_start.
687: '<input type="hidden" name="submitted" value="yes" />';
688: &Apache::lonxml::startredirection();
689: }
690: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
691: $target eq 'webgrade') {
692: my $webgrade='yes';
693: if ($target eq 'webgrade') {
694: $result.= "\n".'<div class="LC_GRADING_task">'."\n".
695: '<script type="text/javascript"
696: src="/res/adm/includes/task_grading.js"></script>';
697: #$result.='<br />Review'.&show_queue('reviewqueue');
698: #$result.='<br />Grade'.&show_queue('gradingqueue');
699: }
700:
701: my ($todo,$status_code,$msg)=&get_key_todo($target);
702:
703: if ($todo) {
704: &setup_env_for_other_user($todo,$safeeval);
705: my ($symb,$uname,$udom)=&decode_queue_key($todo);
706: $result.="\n".'<table><tr><td>Found '.
707: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
708: $form_tag_start.=
709: '<input type="hidden" name="gradingkey" value="'.
710: &escape($todo).'" />';
711: $Apache::bridgetask::queue_key=$todo;
712: &Apache::structuretags::initialize_storage();
713: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
714: if ($target eq 'webgrade' && $status_code eq 'selected') {
715: $form_tag_start.=
716: '<input type="hidden" name="queuemode" value="selected" />';
717: }
718: } else {
719: if ($target eq 'webgrade') {
720: $result.="\n";
721: my $back='<p><a href="/adm/flip?postdata=return:">'.
722: &mt('Return to resource').'</a></p>';
723: if ($status_code eq 'stop') {
724: $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
725: } elsif ($status_code eq 'cancel') {
726: $result.='<b>'.&mt("Cancelled grading.").'</b>'.$back;
727: } elsif ($status_code eq 'never_versioned') {
728: $result.='<b>'.
729: &mt("Requested user has never accessed the task.").
730: '</b>'.$back;
731: } elsif ($status_code =~ /still_open:(.*)/) {
732: my $date = &Apache::lonlocal::locallocaltime($1);
733: $result.='<b>'.
734: &mt("Task is still open, will close at [_1].",$date).
735: '</b>'.$back;
736: } elsif ($status_code eq 'lock_failed') {
737: $result.='<b>'.&mt("Failed to lock the requested record.")
738: .'</b>'.$back;
739: } elsif ($status_code eq 'unlock') {
740: $result.='<b>'.&mt("Unlocked the requested record.")
741: .'</b>'.$back;
742: $result.=&show_queue($env{'form.queue'},1);
743: } elsif ($status_code eq 'show_list') {
744: $result.=&show_queue($env{'form.queue'},1);
745: } elsif ($status_code eq 'select_user') {
746: $result.=&select_user();
747: } elsif ($status_code eq 'unable') {
748: $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
749: } elsif ($status_code eq 'not_allowed') {
750: $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
751: } else {
752: $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
753: }
754: }
755: $webgrade='no';
756: }
757: if (!$todo || $env{'form.cancel'}) {
758: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
759: }
760: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
761: if ($webgrade eq 'yes') {
762: $result.=&submission_time_stamp();
763: }
764: $result.=$form_tag_start;
765: $result.='<input type="hidden" name="webgrade" value="'.
766: $webgrade.'" />';
767: $result.='<input type="hidden" name="queue" value="'.
768: $env{'form.queue'}.'" />';
769: if ($env{'form.regrade'}) {
770: $result.='<input type="hidden" name="regrade" value="'.
771: $env{'form.regrade'}.'" />';
772: }
773: if ($env{'form.chosensections'}) {
774: my @chosen_sections=
775: &Apache::loncommon::get_env_multiple('form.chosensections');
776: foreach my $sec (@chosen_sections) {
777: $result.='<input type="hidden" name="chosensections"
778: value="'.$sec.'" />';
779: }
780: }
781: if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
782: }
783: if ($target eq 'webgrade') {
784: $result.="\n".'<div id="LC_GRADING_criterialist">';
785: &Apache::lonxml::startredirection();
786: }
787: } elsif ($target eq 'edit') {
788: $result.=$form_tag_start.
789: &Apache::structuretags::problem_edit_header();
790: $Apache::lonxml::warnings_error_header=
791: &mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")."<br />";
792: my $temp=&Apache::edit::insertlist($target,$token);
793: $result.=$temp;
794: } else {
795: # page_start returned a starting result, delete it if we don't need it
796: $result = '';
797: }
798: return $result;
799: }
800:
801: sub get_task_end_time {
802: my ($queue_entry,$symb,$udom,$uname) = @_;
803:
804: my $end_time;
805: if (my $slot = &slotted_access($queue_entry)) {
806: my %slot_data=&Apache::lonnet::get_slot($slot);
807: $end_time = $slot_data{'endtime'};
808: } else {
809: $end_time = &Apache::lonhomework::due_date('0',$symb,
810: $udom,$uname);
811: }
812: return $end_time;
813: }
814:
815: sub get_key_todo {
816: my ($target)=@_;
817: my $todo;
818:
819: if (defined($env{'form.reviewasubmission'})) {
820: &Apache::lonxml::debug("review a submission....");
821: $env{'form.queue'}='reviewqueue';
822: return (undef,'show_list');
823: }
824:
825: if (defined($env{'form.reviewagrading'})) {
826: &Apache::lonxml::debug("review a grading....");
827: $env{'form.queue'}='gradingqueue';
828: return (undef,'show_list');
829: }
830:
831: if (defined($env{'form.regradeasubmission'})) {
832: &Apache::lonxml::debug("regrade a grading....");
833: $env{'form.queue'}='none';
834: return (undef,'select_user');
835: }
836:
837:
838: my $me=$env{'user.name'}.':'.$env{'user.domain'};
839:
840: #need to try both queues..
841: if (defined($env{'form.regradeaspecificsubmission'}) &&
842: defined($env{'form.gradinguser'}) &&
843: defined($env{'form.gradingdomain'}) ) {
844: my ($symb,$cid)=&Apache::lonnet::whichuser();
845: my $cnum = $env{'course.'.$cid.'.num'};
846: my $cdom = $env{'course.'.$cid.'.domain'};
847: my $uname = $env{'form.gradinguser'};
848: my $udom = $env{'form.gradingdomain'};
849:
850: my $gradingkey=&encode_queue_key($symb,$udom,$uname);
851:
852: my $queue;
853:
854: if (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
855: $env{'form.queue'} = $queue = 'gradingqueue';
856: } elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
857: $env{'form.queue'} = $queue = 'reviewqueue';
858: }
859:
860: if (!$queue) {
861: $env{'form.queue'} = $queue = 'none';
862: #not queued so doing either a re or pre grade
863: my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
864: if ($status{'resource.0.version'} < 1) {
865: return (undef,'never_versioned');
866: }
867: return ($gradingkey);
868: }
869:
870: if ($queue) {
871: my $queue_entry = &get_queue_data($queue,$udom,$uname);
872:
873: my $end_time = &get_task_end_time($queue_entry,$symb,
874: $udom,$uname);
875: if ($end_time > time) {
876: return (undef,"still_open:$end_time");
877: }
878: }
879:
880: my $who=&queue_key_locked($queue,$gradingkey);
881: if ($who eq $me) {
882: #already have the lock
883: $env{'form.gradingkey'}=&escape($gradingkey);
884: &Apache::lonxml::debug("already locked");
885: return ($gradingkey);
886: }
887:
888: if (!defined($who)) {
889: if (&lock_key($queue,$gradingkey)) {
890: &Apache::lonxml::debug("newly locked");
891: return ($gradingkey);
892: } else {
893: return (undef,'lock_failed');
894: }
895: }
896:
897: #otherwise (defined($who) && $who ne $me) some else has it...
898: return (undef,'not_allowed',
899: &mt('Another user ([_1]) currently has the record for [_2] locked.',
900: $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
901: }
902:
903:
904: my $queue=$env{'form.queue'};
905:
906: if (!defined($queue)) {
907: $env{'form.queue'}=$queue='gradingqueue';
908: }
909:
910: my $gradingkey=&unescape($env{'form.gradingkey'});
911:
912: if ($env{'form.queue'} eq 'none') {
913: if (defined($env{'form.gradingkey'})) {
914: if ($target eq 'webgrade') {
915: if ($env{'form.stop'}) {
916: return (undef,'stop');
917: } elsif ($env{'form.cancel'}) {
918: return (undef,'cancel');
919: } elsif ($env{'form.next'}) {
920: return (undef,'select_user');
921: }
922: }
923: return ($gradingkey,'selected');
924: } else {
925: return (undef,'select_user');
926: }
927: }
928: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
929: && !defined($env{'form.gradingaction'})
930: && $env{'form.queuemode'} eq 'selected') {
931:
932: my $who=&queue_key_locked($queue,$gradingkey);
933: if ($who eq $me) {
934: &Apache::lonxml::debug("Found a key was given to me");
935: return ($gradingkey,'selected');
936: } else {
937: return (undef,'show_list');
938: }
939:
940: }
941:
942: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
943: if ($env{'form.gradingaction'} eq 'resume') {
944: delete($env{'form.gradingaction'});
945: &Apache::lonxml::debug("Resuming a key");
946: return ($gradingkey);
947: } elsif ($env{'form.gradingaction'} eq 'unlock') {
948: &Apache::lonxml::debug("Unlocking a key ".
949: &check_queue_unlock($queue,$gradingkey,1));
950: return (undef,'unlock');
951: } elsif ($env{'form.gradingaction'} eq 'select') {
952: &Apache::lonxml::debug("Locking a key");
953: if (&lock_key($queue,$gradingkey)) {
954: &Apache::lonxml::debug("Success $queue");
955: return ($gradingkey);
956: }
957: &Apache::lonxml::debug("Failed $queue");
958: return (undef,'lock_failed');
959: }
960: }
961:
962: if ($env{'form.queuemode'} ne 'selected') {
963: # don't get something new from the queue if they hit the stop button
964: if (!(($env{'form.cancel'} || $env{'form.stop'})
965: && $target eq 'webgrade')
966: && !$env{'form.gradingaction'}) {
967: &Apache::lonxml::debug("Getting anew $queue");
968: return (&get_from_queue($queue));
969: } else {
970: return (undef,'stop');
971: }
972: }
973: return (undef,undef)
974: }
975:
976: sub minimize_storage {
977: foreach my $key (keys(%Apache::lonhomework::results)) {
978: if ($key =~ /regrader$/) { next; }
979: if ($Apache::lonhomework::results{$key} eq
980: $Apache::lonhomework::history{$key}) {
981: delete($Apache::lonhomework::results{$key});
982: }
983: }
984: }
985:
986: sub end_Task {
987: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
988: my $result='';
989: my $status=$Apache::inputtags::status['-1'];
990: my ($version,$previous)=&get_version();
991: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
992: $target eq 'tex') {
993: if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
994: if ($target eq 'web') {
995: if (&show_task($status,$previous)) {
996: $result.=&Apache::lonxml::endredirection();
997: }
998: if ($status eq 'CAN_ANSWER' && !$previous &&
999: !$env{'form.donescreen'}) {
1000: $result.="\n".'<table border="1">'.
1001: &Apache::inputtags::file_selector("$version.0",
1002: "bridgetask","*",
1003: 'portfolioonly',
1004: '
1005: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
1006: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1007: "</table>";
1008: }
1009: if (!$previous && $status ne 'SHOW_ANSWER' &&
1010: &show_task($status,$previous)) {
1011: $result.=&Apache::inputtags::gradestatus('0');
1012: $result.='</form>';
1013: my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1014: $result.=<<DONEBUTTON;
1015: <form name="done" method="post" action="$action">
1016: <input type="hidden" name="donescreen" value="1" />
1017: <input type="submit" value="Done" />
1018: </form>
1019: DONEBUTTON
1020: }
1021: if (&show_task($status,$previous) &&
1022: $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
1023: my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1024: my $title=&Apache::lonnet::gettitle();
1025:
1026: my $start_time;
1027:
1028: my $slot_name=
1029: $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1030: if ($slot_name) {
1031: my %slot=&Apache::lonnet::get_slot($slot_name);
1032:
1033: $start_time=$slot{'starttime'}
1034: } else {
1035: $start_time=
1036: &Apache::lonnet::EXT('resource.0.opendate');
1037: }
1038: $start_time=&Apache::lonlocal::locallocaltime($start_time);
1039:
1040: my $status = "\n<div class='LC_$bt_status LC_criteria'>\n";
1041:
1042: if ($bt_status eq 'pass') {
1043: $status.='<h2>You passed the '.$title.' given on '.
1044: $start_time.'</h2>';
1045: }
1046: if ($bt_status eq 'fail') {
1047: $status.='<h2>You did not pass the '.$title.' given on '.
1048: $start_time.'</h2>';
1049: if (!$previous) {
1050: $status.=&add_request_another_attempt_button();
1051: }
1052: }
1053: $status.='</div>';
1054: my $man_count=0;
1055: my $man_passed=0;
1056: my $opt_count=0;
1057: my $opt_passed=0;
1058: my $dim = $top;
1059: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1060: my $status = &get_criteria('status',$version,$dim,$id);
1061: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
1062: eq 'N') {
1063: $opt_count++;
1064: if ($status eq 'pass') {
1065: $opt_passed++;
1066: }
1067: } else {
1068: $man_count++;
1069: if ($status eq 'pass') { $man_passed++; }
1070: }
1071: }
1072: if ($man_passed eq $man_count) { $man_passed='all'; }
1073:
1074: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
1075: $parstack,$safeeval);
1076: if ($opt_req !~ /\S/) { $opt_req='0'; }
1077:
1078: $status.="\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'>".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components, of which you passed [_4].',$man_count,$opt_req,$opt_count,$opt_passed)."</p></div>\n";
1079:
1080:
1081: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1082: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1083: if ($type eq 'dimension') {
1084: $result.=$dimension{$id}{'result'};
1085: next;
1086: }
1087: my $criteria =
1088: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
1089: [@_]);
1090: $status .= &layout_web_Criteria($dim,$id,$criteria);
1091: }
1092:
1093: my $internal_location=&internal_location();
1094: $result=~s/\Q$internal_location\E/$status/;
1095: }
1096: $result.="\n</div>\n".
1097: &Apache::loncommon::end_page({'discussion' => 1});
1098: }
1099: }
1100:
1101: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
1102: my %queue_data = ('type' => 'Task',
1103: 'time' => time,);
1104: if (defined($Apache::inputtags::slot_name)) {
1105: $queue_data{'slot'} = $Apache::inputtags::slot_name;
1106: } elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) {
1107: $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1108: }
1109:
1110:
1111: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1112: my $award='SUBMITTED';
1113: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1114: 'portfiles',\$award);
1115: if ($award eq 'SUBMITTED' &&
1116: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
1117: $Apache::lonhomework::results{"resource.0.tries"}=
1118: $Apache::lonhomework::results{"resource.$version.0.tries"}=
1119: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
1120:
1121: $Apache::lonhomework::results{"resource.0.award"}=
1122: $Apache::lonhomework::results{"resource.$version.0.award"}=
1123: $award;
1124: $Apache::lonhomework::results{"resource.0.submission"}=
1125: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1126: } else {
1127: delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1128: $award = '';
1129: }
1130: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1131: &Apache::structuretags::finalize_storage();
1132: if ($award eq 'SUBMITTED') {
1133: &add_to_queue('gradingqueue',\%queue_data);
1134: }
1135: }
1136: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1137: && exists($env{'form.cancel'})) {
1138: &check_queue_unlock($env{'form.queue'});
1139: &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
1140: } elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1141: && !exists($env{'form.cancel'})) {
1142: my $optional_required=
1143: &Apache::lonxml::get_param('OptionalRequired',$parstack,
1144: $safeeval);
1145: my $optional_passed=0;
1146: my $mandatory_failed=0;
1147: my $ungraded=0;
1148: my $review=0;
1149: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1150: my $dim = $top;
1151: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1152: my $link=&link($id);
1153:
1154: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1155:
1156: if ($type eq 'criteria') {
1157: # dimensional 'criteria' don't get assigned grades
1158: $Apache::lonhomework::results{"resource.$version.0.$id.status"}=$env{'form.HWVAL_'.$link};
1159: $Apache::lonhomework::results{"resource.$version.0.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1160: }
1161: my $status=
1162: $Apache::lonhomework::results{"resource.$version.0.$id.status"};
1163: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1164:
1165: if ($status eq 'pass') {
1166: if (!$mandatory) { $optional_passed++; }
1167: } elsif ($status eq 'fail') {
1168: if ($mandatory) { $mandatory_failed++; }
1169: } elsif ($status eq 'review') {
1170: $review++;
1171: } elsif ($status eq 'ungraded') {
1172: $ungraded++;
1173: } else {
1174: $ungraded++;
1175: }
1176: }
1177: if ($optional_passed < $optional_required) {
1178: $mandatory_failed++;
1179: }
1180: &Apache::lonxml::debug(" task results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1181: $Apache::lonhomework::results{'resource.0.regrader'}=
1182: $env{'user.name'}.':'.$env{'user.domain'};
1183: if ($review) {
1184: $Apache::lonhomework::results{"resource.$version.0.status"}='review';
1185: } elsif ($ungraded) {
1186: $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1187: } elsif ($mandatory_failed) {
1188: $Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1189: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
1190: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
1191: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1192: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1193:
1194: if ($env{'form.regrade'} ne 'yes') {
1195: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1196: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1197: &Apache::grades::version_portfiles(
1198: \%Apache::lonhomework::results,
1199: ["$version.0.bridgetask"],$courseid,
1200: $symb,$udom,$uname,
1201: ["$version.0.bridgetask"]);
1202: }
1203: } else {
1204: $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1205: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
1206: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
1207: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1208: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1209: if ($env{'form.regrade'} ne 'yes') {
1210: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1211: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1212: &Apache::grades::version_portfiles(
1213: \%Apache::lonhomework::results,
1214: ["$version.0.bridgetask"],$courseid,
1215: $symb,$udom,$uname,
1216: ["$version.0.bridgetask"]);
1217: }
1218: }
1219: $Apache::lonhomework::results{"resource.0.status"}=
1220: $Apache::lonhomework::results{"resource.$version.0.status"};
1221: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1222: $Apache::lonhomework::results{"resource.0.award"}=
1223: $Apache::lonhomework::results{"resource.$version.0.award"};
1224: $Apache::lonhomework::results{"resource.0.awarded"}=
1225: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1226: $Apache::lonhomework::results{"resource.0.solved"}=
1227: $Apache::lonhomework::results{"resource.$version.0.solved"};
1228: }
1229: &minimize_storage();
1230: &Apache::structuretags::finalize_storage();
1231:
1232: # data stored, now handle queue
1233: if ($review) {
1234: if ($env{'form.queue'} eq 'reviewqueue') {
1235: &check_queue_unlock($env{'form.queue'});
1236: &Apache::lonxml::debug(" still needs review not changing status.");
1237: } else {
1238: if ($env{'form.queue'} ne 'none') {
1239: &move_between_queues($env{'form.queue'},'reviewqueue');
1240: } else {
1241: &add_to_queue('reviewqueue',\%queue_data);
1242: }
1243: }
1244: } elsif ($ungraded) {
1245: if ($env{'form.queue'} eq 'reviewqueue') {
1246: &Apache::lonxml::debug("moving back.");
1247: &move_between_queues($env{'form.queue'},
1248: 'gradingqueue');
1249: } elsif ($env{'form.queue'} eq 'none' ) {
1250: &add_to_queue('gradingqueue',\%queue_data);
1251: } else {
1252: &check_queue_unlock($env{'form.queue'});
1253: }
1254: } elsif ($mandatory_failed) {
1255: &remove_from_queue($env{'form.queue'});
1256: } else {
1257: &remove_from_queue($env{'form.queue'});
1258: }
1259: }
1260: if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
1261: # instance generation occured and hasn't yet been stored
1262: &Apache::structuretags::finalize_storage();
1263: }
1264: } elsif ($target eq 'webgrade') {
1265: $result.=&Apache::lonxml::endredirection();
1266: my $dim = $top;
1267: foreach my $id (@{$dimension{$dim}{'criterias'}} ) {
1268: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1269: if ($type eq 'dimension') {
1270: # dimensional 'criteria' don't get assigned grades
1271: next;
1272: } else {
1273: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
1274: [@_]);
1275: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
1276: my $internal_location=&internal_location($id);
1277: $result=~s/\Q$internal_location\E/$criteria/;
1278: }
1279: }
1280: $result.="</div>";
1281: #$result.='<input type="submit" name="next" value="'.
1282: # &mt('Save & Next').'" /> ';
1283: #$result.='<input type="submit" name="end" value="'.
1284: # &mt('Save & Stop Grading').'" /> ';
1285: #$result.='<input type="submit" name="throwaway" value="'.
1286: # &mt('Throw Away & Stop Grading').'" /> ';
1287: #$result.='<input type="submit" name="save" value="'.
1288: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1289: $result.='</form>'."\n</div>\n</div>\n".
1290: &Apache::loncommon::end_page();
1291: } elsif ($target eq 'meta') {
1292: $result.=&Apache::response::meta_package_write('Task');
1293: $result.=&Apache::response::meta_stores_write('solved','string',
1294: 'Problem Status');
1295: $result.=&Apache::response::meta_stores_write('tries','int_zeropos',
1296: 'Number of Attempts');
1297: $result.=&Apache::response::meta_stores_write('awarded','float',
1298: 'Partial Credit Factor');
1299: $result.=&Apache::response::meta_stores_write('status','string',
1300: 'Bridge Task Status');
1301: } elsif ($target eq 'edit') {
1302: &Apache::structuretags::reset_problem_globals('Task');
1303: undef($Apache::lonhomework::parsing_a_task);
1304: return ('','no');
1305: }
1306: &Apache::structuretags::reset_problem_globals('Task');
1307: undef($Apache::lonhomework::parsing_a_task);
1308: return $result;
1309: }
1310:
1311: sub move_between_queues {
1312: my ($src_queue,$dest_queue)=@_;
1313: my $cur_data;
1314: if ($src_queue ne 'none') {
1315: $cur_data=&get_queue_data($src_queue);
1316: if (!$cur_data) { return 'not_exist'; }
1317: } else {
1318: $cur_data = ['none'];
1319: }
1320: my $result=&add_to_queue($dest_queue,$cur_data);
1321: if ($result ne 'ok') {
1322: return $result;
1323: }
1324: &check_queue_unlock($src_queue);
1325: return &remove_from_queue($src_queue);
1326: }
1327:
1328: sub check_queue_unlock {
1329: my ($queue,$key,$allow_not_me)=@_;
1330: if ($queue eq 'none') { return 'ok'; }
1331: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1332: if (!defined($key)) {
1333: $key="$symb\0queue\0$uname:$udom";
1334: }
1335: my $cnum=$env{'course.'.$cid.'.num'};
1336: my $cdom=$env{'course.'.$cid.'.domain'};
1337: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1338: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1339: if ($who eq $me) {
1340: &Apache::lonxml::debug("unlocking my own $who");
1341: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1342: } elsif ($allow_not_me) {
1343: &Apache::lonxml::debug("unlocking $who by $me");
1344: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1345: }
1346: return 'not_owner';
1347: }
1348:
1349: sub in_queue {
1350: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1351: if ($queue eq 'none') { return 0; }
1352: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1353: || !defined($udom) || !defined($uname)) {
1354: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1355: $cnum=$env{'course.'.$cid.'.num'};
1356: $cdom=$env{'course.'.$cid.'.domain'};
1357: }
1358:
1359: my $key=&encode_queue_key($symb,$udom,$uname);
1360: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1361:
1362: if (defined($results{$key})) {
1363: return 1;
1364: }
1365: return 0;
1366: }
1367:
1368: sub remove_from_queue {
1369: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1370: if ($queue eq 'none') { return 'ok'; }
1371: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1372: || !defined($udom) || !defined($uname)) {
1373: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1374: $cnum=$env{'course.'.$cid.'.num'};
1375: $cdom=$env{'course.'.$cid.'.domain'};
1376: }
1377: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1378: return 'ok';
1379: }
1380: my $key=&encode_queue_key($symb,$udom,$uname);
1381: my @keys=($key,"$key\0locked");
1382: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1383: }
1384:
1385: sub setup_env_for_other_user {
1386: my ($queue_key,$safeeval)=@_;
1387: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1388: &Apache::lonxml::debug("setup_env for $queue_key");
1389: $env{'form.grade_symb'}=$symb;
1390: $env{'form.grade_domain'}=$udom;
1391: $env{'form.grade_username'}=$uname;
1392: $env{'form.grade_courseid'}=$env{'request.course.id'};
1393: &Apache::lonxml::initialize_rndseed($safeeval);
1394: }
1395:
1396: sub get_queue_data {
1397: my ($queue,$udom,$uname)=@_;
1398: my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1399: if (!$uname || !$udom) {
1400: $uname=$other_uname;
1401: $udom =$other_udom;
1402: }
1403: my $cnum=$env{'course.'.$cid.'.num'};
1404: my $cdom=$env{'course.'.$cid.'.domain'};
1405: my $todo="$symb\0queue\0$uname:$udom";
1406: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1407: if ($key eq $todo && ref($value)) {
1408: return $value;
1409: }
1410: return undef;
1411: }
1412:
1413:
1414: sub check_queue_for_key {
1415: my ($cdom,$cnum,$queue,$todo)=@_;
1416:
1417: my %results=
1418: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1419:
1420: if (exists($results{$todo}) && ref($results{$todo})) {
1421: if (defined($results{"$todo\0locked"})) {
1422: return 'locked';
1423: }
1424: if (my $slot=&slotted_access($results{$todo})) {
1425: my %slot_data=&Apache::lonnet::get_slot($slot);
1426: if ($slot_data{'endtime'} > time) {
1427: return 'in_progress';
1428: }
1429: } else {
1430: my ($symb) = &decode_queue_key($todo);
1431: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1432: if ($due_date > time) {
1433: return 'in_progress';
1434: }
1435: }
1436: return 'enqueued';
1437: }
1438: return undef;
1439: }
1440:
1441: sub add_to_queue {
1442: my ($queue,$user_data)=@_;
1443: if ($queue eq 'none') { return 'ok'; }
1444: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1445: if (!$cid || $env{'request.state'} eq 'construct') {
1446: return 'no_queue';
1447: }
1448: my $cnum=$env{'course.'.$cid.'.num'};
1449: my $cdom=$env{'course.'.$cid.'.domain'};
1450: my %data;
1451: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1452: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1453: }
1454:
1455: sub get_limited_classlist {
1456: my ($sections) = @_;
1457:
1458: my $classlist = &Apache::loncoursedata::get_classlist();
1459: foreach my $student (keys(%$classlist)) {
1460: if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
1461: ne 'Active') {
1462: delete($classlist->{$student});
1463: }
1464: }
1465:
1466: if (ref($sections) && !grep('all',@{ $sections })) {
1467: foreach my $student (keys(%$classlist)) {
1468: my $section =
1469: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1470: if (! grep($section,@{ $sections })) {
1471: delete($classlist->{$student});
1472: }
1473: }
1474: }
1475: return $classlist;
1476: }
1477:
1478:
1479: sub show_queue {
1480: my ($queue,$with_selects)=@_;
1481: my $result;
1482: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1483: my $cnum=$env{'course.'.$cid.'.num'};
1484: my $cdom=$env{'course.'.$cid.'.domain'};
1485:
1486: my @chosen_sections=
1487: &Apache::loncommon::get_env_multiple('form.chosensections');
1488:
1489: my $classlist = &get_limited_classlist(\@chosen_sections);
1490:
1491: if (!(grep(/^all$/,@chosen_sections))) {
1492: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1493: '</tt>.</p> '."\n";
1494: }
1495:
1496: my ($view,$view_section);
1497: my $scope = $env{'request.course.id'};
1498: if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
1499: $scope .= '/'.$env{'request.course.sec'};
1500: if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
1501: $view_section=$env{'request.course.sec'};
1502: } else {
1503: undef($view);
1504: }
1505: }
1506:
1507: my $regexp="^$symb\0";
1508: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1509: my ($tmp)=%queue;
1510: if ($tmp=~/^error: 2 /) {
1511: return "\n<h3>Current Queue - $queue</h3>".
1512: &Apache::loncommon::start_data_table().
1513: &Apache::loncommon::start_data_table_row().
1514: '<td>'.&mt('Empty').'</td>'.
1515: &Apache::loncommon::end_data_table_row().
1516: &Apache::loncommon::end_data_table();
1517: }
1518: my $title=&Apache::lonnet::gettitle($symb);
1519: $result.="\n<h3>Current Queue - $title $queue </h3>".
1520: &Apache::loncommon::start_data_table().
1521: &Apache::loncommon::start_data_table_header_row();
1522: if ($with_selects) { $result.="<th>Status</th><th></th>"; }
1523: $result.="<th>user</th><th>data</th>".
1524: &Apache::loncommon::end_data_table_header_row();
1525: foreach my $key (sort(keys(%queue))) {
1526: my ($symb,$uname,$udom) = &decode_queue_key($key);
1527: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1528:
1529: my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1530:
1531: my $can_view=1;
1532: if (!$view
1533: || ($view_section && !$section)
1534: || ($view_section && $section && ($view_section ne $section))) {
1535: $can_view=0;
1536: }
1537:
1538: if ($key=~/locked$/ && !$with_selects) {
1539: $result.= &Apache::loncommon::start_data_table_row().
1540: "<td>$uname</td>";
1541: $result.='<td>'.$queue{$key}.'</td></tr>';
1542: } elsif ($key=~/timestamp$/ && !$with_selects) {
1543: $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1544: $result.='<td>'.
1545: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1546: } elsif ($key!~/(timestamp|locked)$/) {
1547: $result.= &Apache::loncommon::start_data_table_row();
1548: my ($end_time,$slot_text);
1549: if (my $slot=&slotted_access($queue{$key})) {
1550: my %slot_data=&Apache::lonnet::get_slot($slot);
1551: $end_time = $slot_data{'endtime'};
1552: $slot_text = &mt('Slot: [_1]',$slot);
1553: } else {
1554: $end_time = &Apache::lonhomework::due_date('0',$symb);
1555: $slot_text = '';
1556: }
1557: if ($with_selects) {
1558: my $ekey=&escape($key);
1559: my ($action,$description,$status)=('select',&mt('Select'));
1560: if (exists($queue{"$key\0locked"})) {
1561: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1562: $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1563: if ($me eq $queue{"$key\0locked"}) {
1564: ($action,$description)=('resume',&mt('Resume'));
1565: } else {
1566: ($action,$description)=('unlock',&mt('Unlock'));
1567: }
1568: }
1569: my $seclist;
1570: foreach my $sec (@chosen_sections) {
1571: $seclist.='<input type="hidden" name="chosensections"
1572: value="'.$sec.'" />';
1573: }
1574: if ($can_view && ($end_time ne '' && time > $end_time)) {
1575: $result.=(<<FORM);
1576: <td>$status</td>
1577: <td>
1578: <form style="display: inline" method="post">
1579: <input type="hidden" name="gradingkey" value="$ekey" />
1580: <input type="hidden" name="queue" value="$queue" />
1581: <input type="hidden" name="gradingaction" value="$action" />
1582: <input type="hidden" name="webgrade" value="no" />
1583: <input type="hidden" name="queuemode" value="selected" />
1584: <input type="submit" name="submit" value="$description" />
1585: $seclist
1586: </form>
1587: </td>
1588: FORM
1589: } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
1590: $result.='<td>'.&mt("Not gradable").'</td><td> </td>'
1591: } else {
1592: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1593: }
1594: }
1595: $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1596: " <tt>($uname:$udom)</tt> </td>";
1597: $result.='<td>'.$slot_text.' End time: '.
1598: &Apache::lonlocal::locallocaltime($end_time).
1599: "</td>".&Apache::loncommon::end_data_table_row();
1600: }
1601: }
1602: $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1603: return $result;
1604: }
1605:
1606: sub get_queue_counts {
1607: my ($queue)=@_;
1608: my $result;
1609: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1610: my $cnum=$env{'course.'.$cid.'.num'};
1611: my $cdom=$env{'course.'.$cid.'.domain'};
1612:
1613: my $classlist=&get_limited_classlist();
1614:
1615: my $regexp="^$symb\0";
1616: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1617: my ($tmp)=%queue;
1618: if ($tmp=~/^error: 2 /) {
1619: return (0,0,0);
1620: }
1621: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1622: my %slot_cache;
1623: foreach my $key (sort(keys(%queue))) {
1624: my ($symb,$uname,$udom) = &decode_queue_key($key);
1625: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1626: if ($key=~/locked$/) {
1627: $locks++;
1628: } elsif ($key=~/timestamp$/) {
1629: #ignore
1630: } elsif ($key!~/(timestamp|locked)$/) {
1631: $entries++;
1632: if (my $slot=&slotted_access($queue{$key})) {
1633: if (!exists($slot_cache{$slot})) {
1634: my %slot_data=&Apache::lonnet::get_slot($slot);
1635: $slot_cache{$slot} = \%slot_data;
1636: }
1637: if (time > $slot_cache{$slot}{'endtime'}) {
1638: $ready_to_grade++;
1639: }
1640: } else {
1641: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1642: if ($due_date ne '' && time > $due_date) {
1643: $ready_to_grade++;
1644: }
1645: }
1646: }
1647: }
1648: return ($entries,$ready_to_grade,$locks);
1649: }
1650:
1651: sub encode_queue_key {
1652: my ($symb,$udom,$uname)=@_;
1653: return "$symb\0queue\0$uname:$udom";
1654: }
1655:
1656: sub decode_queue_key {
1657: my ($key)=@_;
1658: my ($symb,undef,$user) = split("\0",$key);
1659: my ($uname,$udom) = split(':',$user);
1660: return ($symb,$uname,$udom);
1661: }
1662:
1663: sub queue_key_locked {
1664: my ($queue,$key,$cdom,$cnum)=@_;
1665: if (!defined($cdom) || !defined($cnum)) {
1666: my (undef,$cid)=&Apache::lonnet::whichuser();
1667: $cnum=$env{'course.'.$cid.'.num'};
1668: $cdom=$env{'course.'.$cid.'.domain'};
1669: }
1670: my ($key_locked,$value)=
1671: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1672: if ($key_locked eq "$key\0locked") {
1673: return $value;
1674: }
1675: return undef;
1676: }
1677:
1678: sub slotted_access {
1679: my ($queue_entry) = @_;
1680: if (ref($queue_entry) eq 'ARRAY') {
1681: if (defined($queue_entry->[0])) {
1682: return $queue_entry->[0];
1683: }
1684: return undef;
1685: } elsif (ref($queue_entry) eq 'HASH') {
1686: if (defined($queue_entry->{'slot'})) {
1687: return $queue_entry->{'slot'};
1688: }
1689: return undef;
1690: }
1691: return undef;
1692: }
1693:
1694: sub pick_from_queue_data {
1695: my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1696: my @possible; # will hold queue entries that are valid to be selected
1697: foreach my $key (keys(%$queuedata)) {
1698: if ($key =~ /\0locked$/) { next; }
1699: if ($key =~ /\0timestamp$/) { next; }
1700:
1701: my ($symb,$uname,$udom)=&decode_queue_key($key);
1702: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1703:
1704: if ($check_section) {
1705: my $section =
1706: $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1707: if ($section eq $check_section) {
1708: &Apache::lonxml::debug("my sec");
1709: next;
1710: }
1711: }
1712: my $end_time;
1713: if (my $slot=&slotted_access($queuedata->{$key})) {
1714: &Apache::lonxml::debug("looking at slot $slot");
1715: my %slot_data=&Apache::lonnet::get_slot($slot);
1716: if ($slot_data{'endtime'} < time) {
1717: $end_time = $slot_data{'endtime'};
1718: } else {
1719: &Apache::lonxml::debug("not time ".$slot_data{'endtime'});
1720: next;
1721: }
1722: } else {
1723: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1724: if ($due_date < time) {
1725: $end_time = $due_date;
1726: } else {
1727: &Apache::lonxml::debug("not time $due_date");
1728: next;
1729: }
1730: }
1731:
1732: if (exists($queuedata->{"$key\0locked"})) {
1733: &Apache::lonxml::debug("someone already has um.");
1734: next;
1735: }
1736: push(@possible,[$key,$end_time]);
1737: }
1738: if (@possible) {
1739: # sort entries in order by slot end time
1740: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1741: # pick one of the entries in the top 10% in small queues and one
1742: # of the first ten entries in large queues
1743: #my $ten_percent = int($#possible * 0.1);
1744: #if ($ten_percent < 1 ) { $ten_percent = 1; }
1745: #if ($ten_percent > 10) { $ten_percent = 10; }
1746: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1747:
1748: #return $possible[int(rand($max))][0];
1749: return $possible[0][0];
1750: }
1751: return undef;
1752: }
1753:
1754: sub find_mid_grade {
1755: my ($queue,$symb,$cdom,$cnum)=@_;
1756: my $todo=&unescape($env{'form.gradingkey'});
1757: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1758: if ($todo) {
1759: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1760: if ($who eq $me) { return $todo; }
1761: }
1762: my $regexp="^$symb\0.*\0locked\$";
1763: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1764: foreach my $key (keys(%locks)) {
1765: my $who=$locks{$key};
1766: if ($who eq $me) {
1767: $todo=$key;
1768: $todo=~s/\0locked$//;
1769: return $todo;
1770: }
1771: }
1772: return undef;
1773: }
1774:
1775: sub lock_key {
1776: my ($queue,$todo)=@_;
1777: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1778: my (undef,$cid)=&Apache::lonnet::whichuser();
1779: my $cnum=$env{'course.'.$cid.'.num'};
1780: my $cdom=$env{'course.'.$cid.'.domain'};
1781: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1782: $cdom,$cnum);
1783: &Apache::lonxml::debug("success $success $todo");
1784: if ($success eq 'ok') {
1785: return 1;
1786: }
1787: return 0;
1788: }
1789:
1790: sub get_queue_symb_status {
1791: my ($queue,$symb,$cdom,$cnum) = @_;
1792: if (!defined($cdom) || !defined($cnum)) {
1793: my (undef,$cid)=&Apache::lonnet::whichuser();
1794: $cnum=$env{'course.'.$cid.'.num'};
1795: $cdom=$env{'course.'.$cid.'.domain'};
1796: }
1797: my $classlist=&get_limited_classlist();
1798:
1799: my $regexp="^$symb\0";
1800: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1801: my ($tmp)=%queue;
1802: if ($tmp=~/^error: 2 /) { return; }
1803: my @users;
1804: foreach my $key (sort(keys(%queue))) {
1805: next if ($key=~/locked$/);
1806: next if ($key=~/timestamp$/);
1807: my ($symb,$uname,$udom) = &decode_queue_key($key);
1808: next if (!defined($classlist->{$uname.':'.$udom}));
1809: push(@users,"$uname:$udom");
1810: }
1811: return @users;
1812: }
1813:
1814: sub get_from_queue {
1815: my ($queue)=@_;
1816: my $result;
1817: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1818: my $cnum=$env{'course.'.$cid.'.num'};
1819: my $cdom=$env{'course.'.$cid.'.domain'};
1820: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1821: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1822: if ($todo) { return $todo; }
1823: my $attempts=0;
1824:
1825: my $classlist=&get_limited_classlist();
1826:
1827: while (1) {
1828: if ($attempts > 2) {
1829: # tried twice to get a queue entry, giving up
1830: return (undef,'unable');
1831: }
1832: my $starttime=time;
1833: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
1834: $cdom,$cnum);
1835: &Apache::lonxml::debug("$starttime");
1836: my $regexp="^$symb\0queue\0";
1837: #my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1838:
1839: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1840: #make a pass looking for a user _not_ in my section
1841: if ($env{'request.course.sec'}) {
1842: &Apache::lonxml::debug("sce");
1843: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1844: \%queue,$cdom,$cnum,$classlist);
1845: &Apache::lonxml::debug("sce $todo");
1846: }
1847: # no one _not_ in our section so look for any user that is
1848: # ready for grading
1849: if (!$todo) {
1850: &Apache::lonxml::debug("no sce");
1851: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
1852: $classlist);
1853: &Apache::lonxml::debug("no sce $todo");
1854: }
1855: # no user to grade
1856: if (!$todo) { last; }
1857: &Apache::lonxml::debug("got $todo");
1858: # otherwise found someone so lets try to lock them
1859: # unless someone else already picked them
1860: if (!&lock_key($queue,$todo)) {
1861: $attempts++;
1862: next;
1863: }
1864: my (undef,$endtime)=
1865: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1866: $cdom,$cnum);
1867: &Apache::lonxml::debug("emd $endtime");
1868: # someone else already modified the queue,
1869: # perhaps our picked user wass already fully graded between
1870: # when we picked him and when we locked his record? so lets
1871: # double check.
1872: if ($endtime != $starttime) {
1873: my ($key,$value)=
1874: &Apache::lonnet::get($queue,["$todo"],
1875: $cdom,$cnum);
1876: &Apache::lonxml::debug("check $key .. $value");
1877: if ($key eq $todo && ref($value)) {
1878: } else {
1879: &Apache::lonnet::del($queue,["$todo\0locked"],
1880: $cdom,$cnum);
1881: &Apache::lonxml::debug("del");
1882: $attempts++;
1883: next;
1884: }
1885: }
1886: &Apache::lonxml::debug("last $todo");
1887: last;
1888: }
1889: return $todo;
1890: }
1891:
1892: sub select_user {
1893: my ($symb,$cid)=&Apache::lonnet::whichuser();
1894:
1895: my @chosen_sections=
1896: &Apache::loncommon::get_env_multiple('form.chosensections');
1897:
1898: my $classlist = &get_limited_classlist(\@chosen_sections);
1899:
1900: my $result;
1901: if (!(grep(/^all$/,@chosen_sections))) {
1902: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1903: '</tt>.</p> '."\n";
1904: }
1905: $result.=&Apache::loncommon::start_data_table();
1906:
1907: foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1908: my ($uname,$udom) = split(/:/,$student);
1909:
1910: my $cnum=$env{'course.'.$cid.'.num'};
1911: my $cdom=$env{'course.'.$cid.'.domain'};
1912: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
1913: 'Task');
1914: my $queue = 'none';
1915: my $cannot_grade;
1916: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1917: $queue = 'reviewqueue';
1918: if ($status{'reviewqueue'} eq 'in_progress') {
1919: $cannot_grade=1;
1920: }
1921: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1922: $queue = 'gradingqueue';
1923: if ($status{'gradingqueue'} eq 'in_progress') {
1924: $cannot_grade=1;
1925: }
1926: }
1927: my $todo =
1928: &escape(&encode_queue_key($symb,$udom,$uname));
1929: if ($cannot_grade) {
1930: $result.=&Apache::loncommon::start_data_table_row().
1931: '<td> </td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1932: '</td><td>';
1933: } else {
1934: my $seclist;
1935: foreach my $sec (@chosen_sections) {
1936: $seclist.='<input type="hidden" name="chosensections"
1937: value="'.$sec.'" />';
1938: }
1939: $result.=&Apache::loncommon::start_data_table_row();
1940: $result.=<<RESULT;
1941: <td>
1942: <form style="display: inline" method="post">
1943: <input type="hidden" name="gradingkey" value="$todo" />
1944: <input type="hidden" name="queue" value="$queue" />
1945: <input type="hidden" name="webgrade" value="no" />
1946: <input type="hidden" name="regrade" value="yes" />
1947: <input type="submit" name="submit" value="Regrade" />
1948: $seclist
1949: </form>
1950: <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
1951: <td>
1952: RESULT
1953: }
1954: if ($status{'status'} eq 'pass') {
1955: $result .= '<font color="green">'.&mt('Passed').'</font>';
1956: } elsif ($status{'status'} eq 'fail') {
1957: $result .= '<font color="red">'.&mt('Failed').'</font>';
1958: } elsif ($status{'status'} eq 'review') {
1959: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1960: } elsif ($status{'status'} eq 'ungraded') {
1961: $result .= &mt('Ungraded');
1962: } elsif ($status{'status'} ne '') {
1963: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1964: } else {
1965: $result.=" ";
1966: }
1967: if ($status{'version'}) {
1968: $result .= ' '.&mt('Version').' '.$status{'version'};
1969: }
1970: if ($status{'grader'}) {
1971: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
1972: }
1973: $result.= '</td><td>';
1974: if ($status{'reviewqueue'} eq 'enqueued') {
1975: $result .= &mt('Awaiting Review');
1976: } elsif ($status{'reviewqueue'} eq 'locked') {
1977: $result .= &mt('Under Review');
1978: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1979: $result .= &mt('Still being worked on.');
1980: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1981: $result .= &mt('Awaiting Grading');
1982: } elsif ($status{'gradingqueue'} eq 'locked') {
1983: $result .= &mt('Being Graded');
1984: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1985: $result .= &mt('Still being worked on.');
1986: } else {
1987: $result.=" ";
1988: }
1989: $result.= '</td>'.&Apache::loncommon::end_data_table_row();
1990: }
1991: $result.=&Apache::loncommon::end_data_table();
1992: return $result;
1993: }
1994:
1995: sub get_student_status {
1996: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
1997:
1998: my %status;
1999:
2000: if ($type eq 'Task') {
2001: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
2002: $udom,$uname);
2003: $status{'status'}=$record{'resource.0.status'};
2004: $status{'version'}=$record{'resource.0.version'};
2005: $status{'grader'}=$record{'resource.0.regrader'};
2006: }
2007: $status{'reviewqueue'}=
2008: &check_queue_for_key($cdom,$cnum,'reviewqueue',
2009: &encode_queue_key($symb,$udom,$uname));
2010: $status{'gradingqueue'}=
2011: &check_queue_for_key($cdom,$cnum,'gradingqueue',
2012: &encode_queue_key($symb,$udom,$uname));
2013: return %status;
2014: }
2015:
2016: sub start_ClosingParagraph {
2017: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2018: my $result;
2019: if ($target eq 'web') {
2020: } elsif ($target eq 'webgrade') {
2021: &Apache::lonxml::startredirection();
2022: }
2023: return $result;
2024: }
2025:
2026: sub end_ClosingParagraph {
2027: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2028: my $result;
2029: if ($target eq 'web') {
2030: } elsif ($target eq 'webgrade') {
2031: &Apache::lonxml::endredirection();
2032: }
2033: return $result;
2034: }
2035:
2036: sub get_dim_id {
2037: if (@Apache::bridgetask::dimension) {
2038: return $Apache::bridgetask::dimension[-1];
2039: } else {
2040: return $top;
2041: }
2042: }
2043:
2044: sub get_id {
2045: my ($parstack,$safeeval)=@_;
2046: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
2047: if (!$id) { $id=$Apache::lonxml::curdepth; }
2048: return $id;
2049: }
2050:
2051: sub start_Setup {
2052: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2053: #undef(%dimension);
2054: my $dim = &get_id($parstack,$safeeval);
2055: push(@Apache::bridgetask::dimension,$dim);
2056: &Apache::lonxml::startredirection();
2057: return &internal_location($dim);
2058: }
2059:
2060: {
2061: my @allowed;
2062: sub enable_dimension_parsing {
2063: my ($id) = @_;
2064: push(@allowed,$id);
2065: }
2066: sub disable_dimension_parsing {
2067: pop(@allowed);
2068: }
2069: sub skip_dimension_parsing {
2070: my ($check) = @_;
2071: if (!@allowed) { return 0;}
2072: # if unspecified allow any id
2073: if ($allowed[-1] eq undef) { return 0;}
2074:
2075: return ($check ne $allowed[-1]);
2076: }
2077: }
2078:
2079: sub start_Question { return &start_Dimension(@_); }
2080: sub start_Dimension {
2081: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2082: my $dim = &get_id($parstack,$safeeval);
2083: my $previous_dim;
2084: if (@Apache::bridgetask::dimension) {
2085: $previous_dim = $Apache::bridgetask::dimension[-1];
2086: push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
2087: $dim);
2088: if(&skip_dimension_parsing($dim)) {
2089: $dimension{$previous_dim}{'criteria.'.$dim} =
2090: $token->[4]
2091: .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
2092: $style)
2093: .'</'.$tagstack->[-1].'>';
2094: }
2095: $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
2096: $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
2097: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2098: push(@{$dimension{$previous_dim}{'criterias'}},$dim);
2099: $dimension{$dim}{'nested'}=$previous_dim;
2100: &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
2101: } else {
2102: $dimension{$top}{'criteria.'.$dim.'.type'}='dimension';
2103: $dimension{$top}{'criteria.'.$dim.'.mandatory'}=
2104: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2105: push(@{$dimension{$top}{'criterias'}},$dim);
2106: }
2107: push(@Apache::bridgetask::dimension,$dim);
2108: &Apache::lonxml::startredirection();
2109: &enable_dimension_parsing($dim);
2110: return &internal_location($dim);
2111: }
2112:
2113: sub start_QuestionText {
2114: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2115: my $dim = &get_dim_id();
2116: my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
2117: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2118: $dimension{$dim}{'questiontext'}=$text;
2119: }
2120: return '';
2121: }
2122:
2123: sub end_QuestionText {
2124: return '';
2125: }
2126:
2127: sub get_instance {
2128: my ($dim)=@_;
2129: my $rand_alg=&Apache::lonnet::get_rand_alg();
2130: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
2131: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
2132: $rand_alg eq '64bit4' ) {
2133: &Apache::response::pushrandomnumber();
2134: my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
2135: my $num=@order;
2136: my $version=&get_version();
2137: my $which=($version-1)%$num;
2138: return $order[$which];
2139: } else {
2140: my ($version,$previous) = &get_version();
2141: my $instance =
2142: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
2143: if (defined($instance)) { return $instance; }
2144:
2145: &Apache::response::pushrandomnumber();
2146: if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
2147: my @instances = @{$dimension{$dim}{'instances'}};
2148: # remove disabled instances
2149: for (my $i=0; $i < $#instances; $i++) {
2150: if ($dimension{$dim}{$instances[$i].'.disabled'}) {
2151: splice(@instances,$i,1);
2152: $i--;
2153: }
2154: }
2155: @instances = &Math::Random::random_permutation(@instances);
2156: $instance = $instances[($version-1)%scalar(@instances)];
2157: if ($version =~ /^\d$/) {
2158: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
2159: $instance;
2160: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
2161: }
2162: }
2163: &Apache::response::poprandomnumber();
2164: return $instance;
2165: }
2166: }
2167:
2168: sub get_criteria {
2169: my ($what,$version,$dim,$id) = @_;
2170: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2171: my $prefix = ($type eq 'criteria' && $dim ne $top) ? "$dim.$id"
2172: : "$id";
2173: my $entry = "resource.$version.0.$prefix.$what";
2174: if (exists($Apache::lonhomework::results{$entry})) {
2175: return $Apache::lonhomework::results{$entry};
2176: }
2177: return $Apache::lonhomework::history{$entry};
2178: }
2179:
2180: sub link {
2181: my ($id) = @_;
2182: $id =~ s/\./_/g;
2183: return 'LC_GRADING_criteria_'.$id;
2184: }
2185: sub end_Question { return &end_Dimension(@_); }
2186: sub end_Dimension {
2187: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2188: my $result=&Apache::lonxml::endredirection();
2189: my $dim=&get_id($parstack,$safeeval);
2190: if (&skip_dimension_parsing($dim)) {
2191: &disable_dimension_parsing($dim);
2192: pop(@Apache::bridgetask::dimension);
2193: return;
2194: }
2195: my $instance=&get_instance($dim);
2196: my $version=&get_version();
2197: if ($target eq 'web') {
2198: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2199: my @instances = $instance;
2200: if (&Apache::response::showallfoils()) {
2201: @instances = @{$dimension{$dim}{'instances'}};
2202: }
2203: my $shown_question_text;
2204: foreach my $instance (@instances) {
2205: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2206: [@_]);
2207: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2208: [@_],{'set_dim_id' => undef});
2209: my $task_status =
2210: $Apache::lonhomework::history{"resource.$version.0.status"};
2211: if ($task_status ne 'pass' && $task_status ne 'fail') {
2212:
2213: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2214: @{$dimension{$dim}{'criterias'}}) {
2215: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2216: &Apache::lonxml::debug("$id is $type");
2217: if ($type eq 'dimension') {
2218: $result.=
2219: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2220: [@_],{'set_dim_id' => $id});
2221: }
2222: }
2223: } else {
2224: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
2225: my $mandatory='Mandatory';
2226: if (&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval) eq 'N') {
2227: $mandatory='Optional';
2228: }
2229: my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
2230: if ($dim_status eq 'pass') {
2231: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
2232: }
2233: if ($dim_status eq 'fail') {
2234: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
2235: }
2236: my $man_count=0;
2237: my $man_passed=0;
2238: my $opt_count=0;
2239: my $opt_passed=0;
2240: foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
2241: @{$dimension{$dim}{'criterias'}} ) {
2242: my $status = &get_criteria('status',$version,$dim,$id);
2243: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
2244: eq 'N') {
2245: $opt_count++;
2246: if ($status eq 'pass') { $opt_passed++; }
2247: } else {
2248: $man_count++;
2249: if ($status eq 'pass') { $man_passed++; }
2250: }
2251: }
2252: if ($man_passed eq $man_count) { $man_passed='all'; }
2253:
2254: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
2255: if ($opt_req !~ /\S/) {
2256: $opt_req=
2257: &Apache::lonxml::get_param('OptionalRequired',
2258: $parstack,$safeeval);
2259: if ($opt_req !~ /\S/) { $opt_req = 0; }
2260: }
2261: $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>";
2262:
2263: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2264: @{$dimension{$dim}{'criterias'}}) {
2265: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2266: if ($type eq 'dimension') {
2267: $result.=$dimension{$id}{'result'};
2268: next;
2269: }
2270: my $criteria =
2271: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2272: [@_]);
2273: $dim_info .= &layout_web_Criteria($dim,$id,$criteria);
2274: }
2275:
2276: my $internal_location=&internal_location($dim);
2277: $result=~s/\Q$internal_location\E/$dim_info/;
2278: }
2279: }
2280: } elsif ($target eq 'webgrade') {
2281: # in case of any side effects that we need
2282: &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2283: &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
2284: $result.=
2285: &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
2286: {'set_dim_id' => undef,
2287: 'delayed_dim_results' => 0});
2288: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2289: @{$dimension{$dim}{'criterias'}} ) {
2290: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2291: if ($type eq 'dimension') {
2292: # dimensional 'criteria' don't get assigned grades
2293: $result.=
2294: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2295: [@_],{'set_dim_id' => $id});
2296: next;
2297: } else {
2298: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
2299: [@_]);
2300: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
2301: my $internal_location=&internal_location($id);
2302: $result=~s/\Q$internal_location\E/$criteria/;
2303: }
2304: }
2305: if (&nest()) {
2306: &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
2307: $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
2308: undef($result);
2309: }
2310: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
2311: my $optional_passed=0;
2312: my $mandatory_failed=0;
2313: my $ungraded=0;
2314: my $review=0;
2315:
2316: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2317: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2318: [@_]);
2319: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2320: [@_],{'set_dim_id' => undef});
2321:
2322: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2323: @{$dimension{$dim}{'criterias'}}) {
2324: my $link=&link($id);
2325:
2326: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2327: if ($type eq 'criteria') {
2328: # dimensional 'criteria' don't get assigned grades
2329: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
2330: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
2331: } else {
2332: $result .=
2333: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2334: [@_],{'set_dim_id' => $id});
2335: }
2336: my $status= &get_criteria('status',$version,$dim,$id);
2337:
2338: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
2339: if ($status eq 'pass') {
2340: if (!$mandatory) { $optional_passed++; }
2341: } elsif ($status eq 'fail') {
2342: if ($mandatory) { $mandatory_failed++; }
2343: } elsif ($status eq 'review') {
2344: $review++;
2345: } elsif ($status eq 'ungraded') {
2346: $ungraded++;
2347: } else {
2348: $ungraded++;
2349: }
2350: }
2351:
2352: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
2353: if ($opt_req !~ /\S/) {
2354: $opt_req=
2355: &Apache::lonxml::get_param('OptionalRequired',
2356: $parstack,$safeeval);
2357: if ($opt_req !~ /\S/) { $opt_req = 0; }
2358: }
2359: if ($optional_passed < $opt_req) {
2360: $mandatory_failed++;
2361: }
2362: &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
2363: if ($review) {
2364: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2365: 'review';
2366: } elsif ($ungraded) {
2367: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2368: 'ungraded';
2369: } elsif ($mandatory_failed) {
2370: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2371: 'fail';
2372: } else {
2373: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2374: 'pass';
2375: }
2376: } else {
2377: # any other targets no output
2378: undef($result);
2379: }
2380: &disable_dimension_parsing();
2381: pop(@Apache::bridgetask::dimension);
2382: return $result;
2383: }
2384:
2385: sub end_Setup {
2386: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2387: my $result=&Apache::lonxml::endredirection();
2388: my $dim=&get_id($parstack,$safeeval);
2389: my $instance=&get_instance($dim);
2390: my $version=&get_version();
2391: if ($target eq 'web') {
2392: @Apache::scripttag::parser_env = @_;
2393: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2394: my @instances = $instance;
2395: if (&Apache::response::showallfoils()) {
2396: @instances = @{$dimension{$dim}{'instances'}};
2397: }
2398: foreach my $instance (@instances) {
2399: @Apache::scripttag::parser_env = @_;
2400: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
2401: @Apache::scripttag::parser_env = @_;
2402: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
2403: }
2404: } elsif ($target eq 'webgrade'
2405: || $target eq 'grade' && $env{'form.webgrade'}) {
2406: # in case of any side effects that we need
2407: @Apache::scripttag::parser_env = @_;
2408: &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2409: @Apache::scripttag::parser_env = @_;
2410: &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
2411: @Apache::scripttag::parser_env = @_;
2412: &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
2413: } else {
2414: # any other targets no output
2415: undef($result);
2416: }
2417: pop(@Apache::bridgetask::dimension);
2418: return $result;
2419: }
2420:
2421: sub grading_history {
2422: my ($version,$dim,$id) = @_;
2423: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
2424: return '';
2425: }
2426: my ($result,$grader);
2427: my $scope="resource.$version.0.";
2428: $scope .= ($dim ne $top) ? "$dim.$id"
2429: : "$id";
2430: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
2431: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
2432: my ($gname,$gdom) =
2433: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
2434: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
2435: $grader = &Apache::loncommon::aboutmewrapper($fullname,
2436: $gname,$gdom);
2437: }
2438: my $entry;
2439: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
2440: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
2441: }
2442: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
2443: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
2444: }
2445: if ($entry) {
2446: $result.= "<li>$grader : $entry </li>";
2447: }
2448: }
2449: if ($result) {
2450: return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
2451: }
2452: return '';
2453: }
2454:
2455: sub start_IntroParagraph {
2456: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2457: my $result;
2458: my $dim = &get_dim_id();
2459: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2460: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
2461: $dimension{$dim}{'intro'}=
2462: &Apache::lonxml::get_all_text('/introparagraph',
2463: $parser,$style);
2464: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
2465: &Apache::lonxml::startredirection();
2466: }
2467:
2468: }
2469: return $result;
2470: }
2471:
2472: sub end_IntroParagraph {
2473: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2474: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
2475: my $result = &Apache::lonxml::endredirection();
2476: }
2477: }
2478:
2479: sub start_Instance {
2480: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2481: my $dim = &get_dim_id();
2482: my $id = &get_id($parstack,$safeeval);
2483: push(@{$dimension{$dim}{'instances'}},$id);
2484: push(@{$Apache::bridgetask::instance{$dim}},$id);
2485: push(@Apache::bridgetask::instancelist,$id);
2486: $dimension{$dim}{$id.'.optionalrequired'}=
2487: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
2488: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2489: if (lc($disabled) eq 'yes') {
2490: $dimension{$dim}{$id.'.disabled'}='1';
2491: }
2492: return '';
2493: }
2494:
2495: sub end_Instance {
2496: }
2497:
2498: sub start_InstanceText {
2499: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2500: my $dim = &get_dim_id();
2501: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
2502: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
2503: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2504: $dimension{$dim}{$instance_id.'.text'}=$text;
2505: }
2506: return '';
2507: }
2508:
2509: sub end_InstanceText {
2510: return '';
2511: }
2512:
2513: sub start_Criteria {
2514: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2515: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
2516: my $result = '';
2517: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
2518: my $dim = &get_dim_id();
2519: my $id=&get_id($parstack,$safeeval);
2520: if ($target eq 'web' || $target eq 'webgrade') {
2521: $result .= &internal_location($id);
2522: }
2523: &Apache::lonxml::debug("Criteria $id with $dim");
2524: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
2525: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
2526: $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
2527: $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
2528: $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
2529: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2530: push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
2531: } else {
2532: $dimension{$dim}{'criteria.'.$id}=$criteria;
2533: $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
2534: $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
2535: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2536: push(@{$dimension{$dim}{'criterias'}},$id);
2537: }
2538: }
2539: return $result;
2540: }
2541:
2542: sub layout_web_Criteria {
2543: my ($dim,$id,$criteria) = @_;
2544:
2545: my $version = &get_version();
2546: my $status= &get_criteria('status', $version,$dim,$id);
2547: my $comment=&get_criteria('comment',$version,$dim,$id);
2548: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
2549: if ($mandatory) {
2550: $mandatory='Mandatory';
2551: } else {
2552: $mandatory='Optional';
2553: }
2554: my $status_display=$status;
2555: $status_display=~s/^([a-z])/uc($1)/e;
2556: my $criteria_info.=
2557: '<div class="LC_'.$status.' LC_criteria"><h4>'
2558: .$mandatory.' Criteria</h4><p>';
2559: $criteria_info.= $criteria;
2560: $criteria_info.='</p><p class="LC_grade">'.$status_display.'</p>';
2561: if ($comment =~ /\w/) {
2562: $criteria_info.='<p class="LC_comment">'.
2563: &mt('Comment: [_1]',$comment).'</p>';
2564: }
2565: $criteria_info.='</div>';
2566: return $criteria_info;
2567: }
2568:
2569: sub layout_webgrade_Criteria {
2570: my ($dim,$id,$criteria) = @_;
2571: my $link=&link($id);
2572: my $version = &get_version();
2573: my $status = &get_criteria('status',$version,$dim,$id);
2574: my $result =
2575: '<div class="LC_GRADING_criteria">'."\n".
2576: '<div class="LC_GRADING_criteriatext">'."\n".
2577: $criteria.
2578: '</div>'."\n".
2579: '<div class="LC_GRADING_grade">'."\n".
2580: '<label class="LC_GRADING_ungraded">
2581: <input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.
2582: &mt('Ungraded').
2583: '</label>'."\n".
2584: '<label class="LC_GRADING_fail">
2585: <input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.
2586: &mt('Fail').
2587: '</label>'."\n".
2588: '<label class="LC_GRADING_pass">
2589: <input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.
2590: &mt('Pass').
2591: '</label>'."\n".
2592: '<label class="LC_GRADING_review">
2593: <input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.
2594: &mt('Review').
2595: '</label>'."\n".
2596: '</div>'."\n".
2597: '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
2598: '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode(&get_criteria('comment',$version,$dim,$id),'<>"&').'</textarea>'."\n".
2599: '</label>'."\n".
2600: '</div>'."\n".
2601: &grading_history($version,$dim,$id);
2602: return $result;
2603: }
2604:
2605: sub end_Criteria {
2606: }
2607:
2608: sub start_GraderNote {
2609: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2610:
2611: if ($target eq 'webgrade') {
2612: return '<div class="LC_GRADING_gradernote"><b>'.
2613: &mt('Note to graders:').'</b>';
2614: }
2615: my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style);
2616: return;
2617: }
2618:
2619: sub end_GraderNote {
2620: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2621:
2622: if ($target eq 'webgrade') {
2623: return '</div>';
2624: }
2625: return;
2626: }
2627:
2628:
2629:
2630: sub proctor_validation_screen {
2631: my ($slot) = @_;
2632: my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
2633: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2634: my $name=&Apache::loncommon::plainname($user,$domain);
2635:
2636: my $msg;
2637: if ($env{'form.proctorpassword'}) {
2638: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
2639: .'</font></p>';
2640: }
2641: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
2642: my $result= (<<ENDCHECKOUT);
2643: <h2>Proctor Validation</h2>
2644: <p>Your room's proctor needs to validate your access to this resource.</p>
2645: $msg
2646: <form name="checkout" method="post" action="$env{'request.uri'}">
2647: <input type="hidden" name="validate" value="yes" />
2648: <input type="hidden" name="submitted" value="yes" />
2649: <table>
2650: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
2651: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
2652: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
2653: </table>
2654: <input type="submit" name="checkoutbutton" value="Validate" /><br />
2655: <table border="1">
2656: <tr><td>
2657: <table>
2658: <tr><td colspan="2">Student who should be logged in is:</td></tr>
2659: <tr><td>Name:</td><td>$name</td></tr>
2660: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
2661: <tr><td>Usename</td><td>$user:$domain</td></tr>
2662: <tr><td colspan="2"><img src="$url" /></td></tr>
2663: </table>
2664: </tr></td>
2665: </table>
2666: </form>
2667: ENDCHECKOUT
2668: return $result;
2669: }
2670:
2671: 1;
2672: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>