File:
[LON-CAPA] /
loncom /
homework /
bridgetask.pm
Revision
1.151:
download - view:
text,
annotated -
select for diffs
Tue May 16 06:43:42 2006 UTC (18 years, 3 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- <Question> is a synonym for <Dimension>
- OptionalRequired is allowed on <Question>s (but if it exists on <Instance> it overrides the <Dimension> definition)
- <Criteria> is allowed inside of <Question> and is then used on all <Instance>s
1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
4: # $Id: bridgetask.pm,v 1.151 2006/05/16 06:43:42 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:
42: BEGIN {
43: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','Instance','InstanceText','Criteria','ClosingParagraph'));
44: }
45:
46: sub initialize_bridgetask {
47: # id of current Dimension, 0 means that no dimension is current
48: # (inside <Task> only)
49: $Apache::bridgetask::dimension='';
50: # list of all Dimension ids seen
51: @Apache::bridgetask::dimensionlist=();
52: # mandatory attribute of all Dimensions seen
53: %Apache::bridgetask::dimensionmandatory=();
54: # list of all current Instance ids
55: @Apache::bridgetask::instance=();
56: # list of all Instance ids seen in this problem
57: @Apache::bridgetask::instancelist=();
58: # key of queud user data that we are currently grading
59: $Apache::bridgetask::queue_key='';
60: }
61:
62: sub proctor_check_auth {
63: my ($slot_name,$slot,$type)=@_;
64: my $user=$env{'form.proctorname'};
65: my $domain=$env{'form.proctordomain'};
66:
67: my @allowed=split(",",$slot->{'proctor'});
68: foreach my $possible (@allowed) {
69: my ($puser,$pdom)=(split(':',$possible));
70: if ($puser eq $user && $pdom eq $domain) {
71: my $authenticated=0;
72: if ( $slot->{'secret'} =~ /\S/ &&
73: $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
74: $authenticated=1;
75: } else {
76:
77: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
78: if ($authhost ne 'no_host') {
79: $authenticated=1;
80: }
81: }
82: if ($authenticated) {
83: &create_new_version($type,$user,$domain,$slot_name);
84: return 1;
85: }
86: }
87: }
88: return 0;
89: }
90:
91: sub create_new_version {
92: my ($type,$user,$domain,$slot_name) = @_;
93: if ($type eq 'Task') {
94: # increment version
95: my $version=
96: $Apache::lonhomework::history{'resource.0.version'};
97: $version++;
98:
99: #clean out all current results
100: foreach my $key (keys(%Apache::lonhomework::history)) {
101: if ($key=~/^resource\.0\./) {
102: $Apache::lonhomework::results{$key}='';
103: }
104: }
105:
106: #setup new version and who did it
107: $Apache::lonhomework::results{'resource.0.version'}=$version;
108: if (defined($user) && defined($domain)) {
109: $Apache::lonhomework::results{"resource.$version.0.checkedin"}=
110: $user.':'.$domain;
111: }
112: if (defined($slot_name)) {
113: $Apache::lonhomework::results{"resource.$version.0.checkedin.slot"}=
114: $slot_name;
115: }
116: } elsif ($type eq 'problem') {
117: &Apache::lonxml::debug("authed $slot_name");
118: if (defined($user) && defined($domain)) {
119: $Apache::lonhomework::results{"resource.0.checkedin"}=
120: $user.':'.$domain;
121: }
122: if (defined($slot_name)) {
123: $Apache::lonhomework::results{"resource.0.checkedin.slot"}=
124: $slot_name;
125: }
126: }
127: }
128:
129: sub get_version {
130: my ($version,$previous);
131: if ($env{'form.previousversion'} &&
132: $env{'form.previousversion'} ne 'current' &&
133: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
134: $version=$env{'form.previousversion'};
135: $previous=1;
136: } else {
137: if (defined($Apache::lonhomework::results{'resource.0.version'})) {
138: $version=$Apache::lonhomework::results{'resource.0.version'};
139: } elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
140: $version=$Apache::lonhomework::history{'resource.0.version'};
141: }
142: $previous=0;
143: }
144: if (wantarray) {
145: return ($version,$previous);
146: }
147: return $version;
148: }
149:
150: sub add_previous_version_button {
151: my ($status)=@_;
152: my $result;
153: if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
154: return '';
155: }
156: if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
157: $status ne 'NEEDS_CHECKIN') {
158: return '';
159: }
160: my $version=&get_version();
161: if ($env{'form.previousversion'} ne '' &&
162: $env{'form.previousversion'} eq $version) {
163: $result.="<h3>".&mt("Showing previous version [_1]",$version).
164: "</h3>\n";
165: }
166: my @to_show;
167: foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
168: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
169: push(@to_show,$test_version);
170: }
171: }
172: my $list='<option>'.
173: join("</option>\n<option>",@to_show).
174: "</option>\n";
175: $list.='<option value="current">'.&mt('Current').'</option>';
176: $result.='<form name="getprevious" method="post" action="';
177: my $uri=$env{'request.uri'};
178: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
179: $result.=$uri.'">'.
180: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
181: <option>'.&mt('Pick one').'</option>
182: '.$list.'
183: </select>')."</form>";
184: return $result;
185: }
186:
187: sub add_grading_button {
188: my (undef,$cid)=&Apache::lonxml::whichuser();
189: my $cnum=$env{'course.'.$cid.'.num'};
190: my $cdom=$env{'course.'.$cid.'.domain'};
191: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
192:
193: my $size=5;
194: if (scalar(keys(%sections)) < 3) {
195: $size=scalar(keys(%sections))+2;
196: }
197: my $sec_select = '<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
198: $sec_select .= "<option value='all' selected='selected'>all</option>\n";
199: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
200: $sec_select .= "<option value=\"$sec\">$sec</option>\n";
201: }
202: $sec_select .= "<option value='none'>none</option></select>\n";
203:
204: my $result=' <input type="submit" name="gradeasubmission" value="'.
205: &mt("Get a submission to grade").'" />';
206: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
207: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
208: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
209: $result.='<table><tr>';
210: $result.='<td rowspan="4">Specify a section: </td><td rowspan="4">'.$sec_select.'</td>';
211: $result.='<td>'.' <input type="submit" name="reviewagrading" value="'.
212: &mt("Select an entry from the grading queue:").'" /> ';
213:
214: $result.= &mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).' </td></tr>'."\n";
215:
216: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
217: $result.='<tr><td>'.
218: ' <input type="submit" name="reviewasubmission" value="'.
219: &mt("Select an entry from the review queue:").'" /> ';
220: $result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
221: $entries,$ready,$locks).'</td></tr>'."\n";
222: $result.='<tr><td> <input type="submit" name="regradeasubmission" value="'.
223: &mt("List of user's grade status").'" /> </td></tr></table>'."\n";
224: $result.='<p> <input type="submit" name="regradeaspecificsubmission" value="'.
225: &mt("Regrade specific user:").'" />'."\n";
226: $result.='<input type="text" size="12" name="gradinguser" />';
227: $result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
228: 'gradingdomain');
229: $result.=' '.
230: &Apache::loncommon::selectstudent_link('gradesubmission',
231: 'gradinguser',
232: 'gradingdomain');
233: $result.=&Apache::loncommon::studentbrowser_javascript();
234: $result.= '</p>';
235: }
236: return $result;
237: }
238:
239: sub add_request_another_attempt_button {
240: my ($text)=@_;
241: if (!$text) { $text="Request another attempt"; }
242: my $result;
243: my $symb=&Apache::lonnet::symbread();
244: # not a slot access based resource
245: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
246: if ($useslots =~ /^\s*no\s*$/i) {
247: return '';
248: }
249:
250: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
251: my $action='get_reservation';
252: if ($slot_name) {
253: $text="Change reservation.";
254: $action='change_reservation';
255: my $description=&Apache::slotrequest::get_description($slot_name,
256: $slot);
257: $result.=(<<STUFF);
258: <p> Will be next available: $description </p>
259: STUFF
260: }
261:
262: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
263: $symb=&Apache::lonnet::escape($symb);
264: $result.='<form method="post" action="/adm/slotrequest">'.
265: '<input type="hidden" name="symb" value="'.$symb.'" />'.
266: '<input type="hidden" name="command" value="'.$action.'" />'.
267: '<input type="submit" name="requestattempt" value="'.
268: &mt($text).'" />'.
269: '</form>';
270: return $result;
271: }
272:
273: sub preserve_grade_info {
274: my $result;
275: # if we are viewing someone else preserve that info
276: if (defined $env{'form.grade_symb'}) {
277: foreach my $field ('symb','courseid','domain','username') {
278: $result .= '<input type="hidden" name="grade_'.$field.
279: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
280: }
281: }
282: return $result;
283: }
284:
285: sub style {
286: my ($target) = @_;
287: if ($target eq 'web'
288: || $target eq 'webgrade') {
289: return (<<STYLE);
290: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
291: STYLE
292: }
293: return;
294: }
295:
296: sub show_task {
297: my ($status,$previous)=@_;
298: if (!$previous && (
299: ( $status eq 'CLOSED' ) ||
300: ( $status eq 'BANNED') ||
301: ( $status eq 'UNAVAILABLE') ||
302: ( $status eq 'NOT_IN_A_SLOT') ||
303: ( $status eq 'NEEDS_CHECKIN') ||
304: ( $status eq 'WAITING_FOR_GRADE') ||
305: ( $status eq 'INVALID_ACCESS') ||
306: ( &get_version() eq ''))) {
307: return 0;
308: }
309: if ($env{'form.donescreen'}) { return 0; }
310: return 1;
311: }
312:
313: sub internal_location {
314: my ($id)=@_;
315: return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
316: }
317:
318: sub submission_time_stamp {
319: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
320: my $submissiontime;
321: my $version=$Apache::lonhomework::history{'resource.0.version'};
322: for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
323: if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
324: $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
325: }
326: }
327: my $result;
328: if ($submissiontime) {
329: my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
330: my %slot=&Apache::lonnet::get_slot($slot_name);
331: my $diff = $slot{'endtime'} - $submissiontime;
332: my ($color,$when)=('#FF6666','after');
333: if ($diff > 0) { ($color,$when)=('#336600','before'); }
334: my $info;
335: if ($diff%60) { $info=($diff%60).' seconds'; }
336: $diff=int($diff/60);
337: if ($diff%60) { $info=($diff%60).' minutes '.$info; }
338: $diff=int($diff/60);
339: if ($diff) { $info=$diff.' hours '.$info; }
340: $result='<p><font color="'.$color.'">'.
341: &mt('Student submitted [_1] [_2] the deadline.
342: (Submission was at [_3], end of period was [_4].)',
343: $info,$when,scalar(localtime($submissiontime)),
344: scalar(localtime($slot{'endtime'}))).
345: '</font></p>';
346: }
347: return $result;
348: }
349:
350: sub file_list {
351: my ($files,$uname,$udom) = @_;
352: if (!defined($uname) || !defined($udom)) {
353: (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
354: }
355: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
356:
357: my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
358: foreach my $partial_file (split(',',$files)) {
359: my $file=$file_url.$partial_file;
360: $file=~s|/+|/|g;
361: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
362: $file_list.='<li><nobr><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
363: &Apache::loncommon::icon($file).'" border="0"> '.$file.
364: '</a></nobr></li>'."\n";
365: }
366: $file_list.="</ul>\n";
367: return $file_list;
368: }
369:
370: sub webgrade_standard_info {
371: my ($version)=&get_version();
372:
373: my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
374:
375: my %lt=&Apache::lonlocal::texthash('done' => 'Next Item',
376: 'stop' => 'Quit Grading',
377: 'fail' => 'Fail Rest',
378: );
379:
380: my $result=<<INFO;
381: <div class="LC_GRADING_maincontrols">
382: <input type="submit" name="next" value="$lt{'done'}" />
383: <input type="submit" name="stop" value="$lt{'stop'}" />
384: <input type="button" name="fail" value="$lt{'fail'}"
385: onclick="javascript:onFailRest()" />
386: </div>
387: $file_list
388: INFO
389: return $result;
390: }
391:
392: sub start_Task {
393: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
394:
395: my ($status,$accessmsg,$slot);
396: if ($target ne 'webgrade') {
397: &Apache::structuretags::init_problem_globals('Task');
398: &Apache::structuretags::initialize_storage();
399: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
400: if ($env{'request.state'} eq 'construct') {
401: &Apache::structuretags::setup_rndseed($safeeval);
402: }
403: }
404:
405: $Apache::lonhomework::parsing_a_task=1;
406:
407: my $name;
408: if ($target eq 'web' || $target eq 'webgrade') {
409: $name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
410: }
411:
412: my ($result,$form_tag_start);
413: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
414: || $target eq 'edit') {
415: ($result,$form_tag_start) =
416: &Apache::structuretags::page_start($target,$token,$tagstack,
417: $parstack,$parser,$safeeval,
418: $name,&style($target));
419: $result .= '<div class="LC_task">'."\n";
420: }
421:
422: if ($target eq 'web' && $env{'request.state'} ne 'construct') {
423: if ($Apache::lonhomework::queuegrade
424: || $Apache::lonhomework::modifygrades) {
425: $result.='<form name="gradesubmission" method="post" action="';
426: my $uri=$env{'request.uri'};
427: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
428: $result.=$uri.'">'.&add_grading_button()."</form>";
429: my $symb=&Apache::lonnet::symbread();
430: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
431: $result.='<form method="post" name="slotrequest" action="/adm/slotrequest">'.
432: '<input type="hidden" name="symb" value="'.$symb.'" />'.
433: '<input type="hidden" name="command" value="showslots" />'.
434: '<input type="submit" name="requestattempt" value="'.
435: &mt('Show Slot list').'" />'.
436: '</form>';
437: my $target_id =
438: &Apache::lonstathelpers::make_target_id({symb => $symb,
439: part => '0'});
440: $result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
441: '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
442: '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
443: '<input type="submit" name="grading" value="'.
444: &mt('Show Grading Status').'" />'.
445: '</form>';
446: }
447: }
448: }
449: if ($target eq 'web' && $env{'request.state'} eq 'construct') {
450: $form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
451: }
452: if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
453: $target eq 'tex') {
454: my ($version,$previous)=&get_version();
455: ($status,$accessmsg,my $slot_name,$slot) =
456: &Apache::lonhomework::check_slot_access('0','Task');
457: if ($status eq 'CAN_ANSWER' && $version eq '' && $slot_name eq '') {
458: &create_new_version('Task');
459: ($version,$previous)=&get_version();
460: }
461:
462: push(@Apache::inputtags::status,$status);
463: $Apache::inputtags::slot_name=$slot_name;
464: my $expression='$external::datestatus="'.$status.'";';
465: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
466: &Apache::run::run($expression,$safeeval);
467: &Apache::lonxml::debug("Got $status");
468: $result.=&add_previous_version_button($status);
469: if (!&show_task($status,$previous)) {
470: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
471: if ( $target eq "web" ) {
472: if ($env{'request.state'} eq 'construct') {
473: $result.=$form_tag_start;
474: }
475: my $msg;
476: if ($status eq 'UNAVAILABLE') {
477: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
478: } elsif ($status eq 'NOT_IN_A_SLOT') {
479: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
480: $msg.=&add_request_another_attempt_button("Sign up for time to work.");
481: } elsif ($status eq 'NEEDS_CHECKIN') {
482: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
483: '</h1>'.&proctor_validation_screen($slot);
484: } elsif ($status eq 'WAITING_FOR_GRADE') {
485: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
486: } elsif ($env{'form.donescreen'}) {
487: my $title=&Apache::lonnet::gettitle();
488: my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
489: my (undef,undef,$domain,$user)=
490: &Apache::lonxml::whichuser();
491: my $files = '<ul>';
492: foreach my $file (@files) {
493: my $url="/uploaded/$domain/$user/portfolio$file";
494: if (! &Apache::lonnet::stat_file($url)) {
495: $file = &mt('<font color="red"> Nonexistant file:</font> <tt>[_1]</tt>',$file);
496: } else {
497: $file = '<tt>'.$file.'</tt>';
498: }
499: $files .= '<li>'.$file.'</li>';
500: }
501: $files.='</ul>';
502:
503: $result.=<<DONESCREEN;
504: <h2>$title</h2>
505: <p> Files submitted: $files </p>
506: <p> You are now done with this Bridge Task </p>
507: <hr />
508: <p> <a href="/adm/logout">Logout</a> </p>
509: <p> <a href="/adm/roles">Change to a different course</a> </p>
510: DONESCREEN
511: } elsif ($status ne 'NOT_YET_VIEWED') {
512: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
513: }
514: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
515: $msg.='The problem '.$accessmsg;
516: }
517: $result.=$msg.'<br />';
518: } elsif ($target eq 'tex') {
519: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
520: if ($status eq 'UNAVAILABLE') {
521: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
522: } else {
523: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
524: }
525: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
526: if ($status eq 'NEEDS_CHECKIN') {
527: if(&proctor_check_auth($slot_name,$slot,'Task')
528: && defined($Apache::inputtags::slot_name)) {
529: my $result=
530: &add_to_queue('gradingqueue',
531: {'type' => 'task',
532: 'time' => time,
533: 'slot' =>
534: $Apache::inputtags::slot_name});
535: &Apache::lonxml::debug("add_to_queue said $result");
536: }
537: }
538: }
539: } elsif ($target eq 'web') {
540:
541: $result.=&preserve_grade_info();
542: $result.=&internal_location();
543: $result.=$form_tag_start.
544: '<input type="hidden" name="submitted" value="yes" />';
545: &Apache::lonxml::startredirection();
546: }
547: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
548: $target eq 'webgrade') {
549: my $webgrade='yes';
550: if ($target eq 'webgrade') {
551: $result.= "\n".'<div class="LC_GRADING_task">'."\n".
552: '<script type="text/javascript"
553: src="/res/adm/includes/task_grading.js"></script>';
554: #$result.='<br />Review'.&show_queue('reviewqueue');
555: #$result.='<br />Grade'.&show_queue('gradingqueue');
556: }
557: # FIXME Blast! still need to reorg this, need to reshow the
558: # queue being reviewed once done with the grade pass...
559: # Hrrm, vaildation pass should perhaps say 'not_locked'
560: # perhaps do a search if there is a key that is mine and if
561: # there isn't reshow the queue....
562: my ($todo,$status_code,$msg)=&get_key_todo($target);
563:
564: if ($todo) {
565: &setup_env_for_other_user($todo,$safeeval);
566: my ($symb,$uname,$udom)=&decode_queue_key($todo);
567: $result.="\n".'<table><tr><td>Found '.
568: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
569: $form_tag_start.=
570: '<input type="hidden" name="gradingkey" value="'.
571: &Apache::lonnet::escape($todo).'" />';
572: $Apache::bridgetask::queue_key=$todo;
573: &Apache::structuretags::initialize_storage();
574: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
575: if ($target eq 'webgrade' && $status_code eq 'selected') {
576: $form_tag_start.=
577: '<input type="hidden" name="queuemode" value="selected" />';
578: }
579: } else {
580: if ($target eq 'webgrade') {
581: $result.="\n";
582: my $back='<p><a href="/adm/flip?postdata=return:">'.
583: &mt('Return to resource').'</a></p>';
584: if ($status_code eq 'stop') {
585: $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
586: } elsif ($status_code eq 'lock_failed') {
587: $result.='<b>'.&mt("Failed to lock the requested record.")
588: .'</b>'.$back;
589: } elsif ($status_code eq 'unlock') {
590: $result.='<b>'.&mt("Unlocked the requested record.")
591: .'</b>'.$back;
592: $result.=&show_queue($env{'form.queue'},1);
593: } elsif ($status_code eq 'show_list') {
594: $result.=&show_queue($env{'form.queue'},1);
595: } elsif ($status_code eq 'select_user') {
596: $result.=&select_user();
597: } elsif ($status_code eq 'unable') {
598: $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
599: } elsif ($status_code eq 'not_allowed') {
600: $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
601: } else {
602: $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
603: }
604: }
605: $webgrade='no';
606: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
607: }
608: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
609: if ($webgrade eq 'yes') {
610: $result.=&submission_time_stamp();
611: }
612: $result.=$form_tag_start;
613: $result.='<input type="hidden" name="webgrade" value="'.
614: $webgrade.'" />';
615: $result.='<input type="hidden" name="queue" value="'.
616: $env{'form.queue'}.'" />';
617: if ($env{'form.regrade'}) {
618: $result.='<input type="hidden" name="regrade" value="'.
619: $env{'form.regrade'}.'" />';
620: }
621: if ($env{'form.chosensections'}) {
622: my @chosen_sections=
623: &Apache::loncommon::get_env_multiple('form.chosensections');
624: foreach my $sec (@chosen_sections) {
625: $result.='<input type="hidden" name="chosensections"
626: value="'.$sec.'" />';
627: }
628: }
629: if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
630: }
631: if ($target eq 'webgrade') {
632: $result.="\n".'<div id="LC_GRADING_criterialist">';
633: }
634: } elsif ($target eq 'edit') {
635: $result.=$form_tag_start.
636: &Apache::structuretags::problem_edit_header();
637: $Apache::lonxml::warnings_error_header=
638: &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 />";
639: my $temp=&Apache::edit::insertlist($target,$token);
640: $result.=$temp;
641: } else {
642: # page_start returned a starting result, delete it if we don't need it
643: $result = '';
644: }
645: return $result;
646: }
647:
648: sub get_key_todo {
649: my ($target)=@_;
650: my $todo;
651:
652: if (defined($env{'form.reviewasubmission'})) {
653: &Apache::lonxml::debug("review a submission....");
654: $env{'form.queue'}='reviewqueue';
655: return (undef,'show_list');
656: }
657:
658: if (defined($env{'form.reviewagrading'})) {
659: &Apache::lonxml::debug("review a grading....");
660: $env{'form.queue'}='gradingqueue';
661: return (undef,'show_list');
662: }
663:
664: if (defined($env{'form.regradeasubmission'})) {
665: &Apache::lonxml::debug("regrade a grading....");
666: $env{'form.queue'}='none';
667: return (undef,'select_user');
668: }
669:
670:
671: my $me=$env{'user.name'}.':'.$env{'user.domain'};
672:
673: #need to try both queues..
674: if (defined($env{'form.regradeaspecificsubmission'}) &&
675: defined($env{'form.gradinguser'}) &&
676: defined($env{'form.gradingdomain'}) ) {
677: my ($symb,$cid)=&Apache::lonxml::whichuser();
678: my $cnum = $env{'course.'.$cid.'.num'};
679: my $cdom = $env{'course.'.$cid.'.domain'};
680: my $uname = $env{'form.gradinguser'};
681: my $udom = $env{'form.gradingdomain'};
682:
683: my $gradingkey=&encode_queue_key($symb,$udom,$uname);
684:
685: my $queue;
686:
687: if (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
688: $env{'form.queue'} = $queue = 'gradingqueue';
689: } elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
690: $env{'form.queue'} = $queue = 'reviewqueue';
691: }
692:
693: if (!$queue) {
694: $env{'form.queue'} = $queue = 'none';
695: #not queued so doing either a re or pre grade
696: return ($gradingkey);
697: }
698:
699: my $who=&queue_key_locked($queue,$gradingkey);
700: if ($who eq $me) {
701: #already have the lock
702: $env{'form.gradingkey'}=&Apache::lonnet::escape($gradingkey);
703: return ($gradingkey);
704: }
705:
706: if (!defined($who)) {
707: if (&lock_key($queue,$gradingkey)) {
708: return ($gradingkey);
709: } else {
710: return (undef,'lock_failed');
711: }
712: }
713:
714: #otherwise (defined($who) && $who ne $me) some else has it...
715: return (undef,'not_allowed',
716: &mt('Another user ([_1]) currently has the record for [_2] locked.',
717: $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
718: }
719:
720:
721: my $queue=$env{'form.queue'};
722:
723: if (!defined($queue)) {
724: $env{'form.queue'}=$queue='gradingqueue';
725: }
726:
727: my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
728:
729: if ($env{'form.queue'} eq 'none') {
730: if (defined($env{'form.gradingkey'})) {
731: if ($target eq 'webgrade') {
732: if ($env{'form.stop'}) {
733: return (undef,'stop');
734: } elsif ($env{'form.next'}) {
735: return (undef,'select_user');
736: }
737: }
738: return ($gradingkey,'selected');
739: } else {
740: return (undef,'select_user');
741: }
742: }
743: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
744: && !defined($env{'form.gradingaction'})
745: && $env{'form.queuemode'} eq 'selected') {
746:
747: my $who=&queue_key_locked($queue,$gradingkey);
748: if ($who eq $me) {
749: &Apache::lonxml::debug("Found a key was given to me");
750: return ($gradingkey,'selected');
751: } else {
752: return (undef,'show_list');
753: }
754:
755: }
756:
757: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
758: if ($env{'form.gradingaction'} eq 'resume') {
759: delete($env{'form.gradingaction'});
760: &Apache::lonxml::debug("Resuming a key");
761: return ($gradingkey);
762: } elsif ($env{'form.gradingaction'} eq 'unlock') {
763: &Apache::lonxml::debug("Unlocking a key ".
764: &check_queue_unlock($queue,$gradingkey,1));
765: return (undef,'unlock');
766: } elsif ($env{'form.gradingaction'} eq 'select') {
767: &Apache::lonxml::debug("Locking a key");
768: if (&lock_key($queue,$gradingkey)) {
769: &Apache::lonxml::debug("Success $queue");
770: return ($gradingkey);
771: }
772: &Apache::lonxml::debug("Failed $queue");
773: return (undef,'lock_failed');
774: }
775: }
776:
777: if ($env{'form.queuemode'} ne 'selected') {
778: # don't get something new from the queue if they hit the stop button
779: if (!($env{'form.stop'} && $target eq 'webgrade')
780: && !$env{'form.gradingaction'}) {
781: &Apache::lonxml::debug("Getting anew $queue");
782: return (&get_from_queue($queue));
783: } else {
784: return (undef,'stop');
785: }
786: }
787: return (undef,undef)
788: }
789:
790: sub minimize_storage {
791: foreach my $key (keys(%Apache::lonhomework::results)) {
792: if ($key =~ /regrader$/) { next; }
793: if ($Apache::lonhomework::results{$key} eq
794: $Apache::lonhomework::history{$key}) {
795: delete($Apache::lonhomework::results{$key});
796: }
797: }
798: }
799:
800: sub end_Task {
801: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
802: my $result='';
803: my $status=$Apache::inputtags::status['-1'];
804: my ($version,$previous)=&get_version();
805: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
806: $target eq 'tex') {
807: if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
808: if ($target eq 'web') {
809: if (&show_task($status,$previous)) {
810: $result.=&Apache::lonxml::endredirection();
811: }
812: if ($status eq 'CAN_ANSWER' && !$previous &&
813: !$env{'form.donescreen'}) {
814: $result.="\n".'<table border="1">'.
815: &Apache::inputtags::file_selector("$version.0",
816: "bridgetask","*",
817: 'portfolioonly',
818: '
819: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
820: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
821: "</table>";
822: }
823: if (!$previous && $status ne 'SHOW_ANSWER' &&
824: &show_task($status,$previous)) {
825: $result.=&Apache::inputtags::gradestatus('0');
826: $result.='</form>';
827: my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
828: $result.=<<DONEBUTTON;
829: <form name="done" method="post" action="$action">
830: <input type="hidden" name="donescreen" value="1" />
831: <input type="submit" value="Done" />
832: </form>
833: DONEBUTTON
834: }
835: if (&show_task($status,$previous) &&
836: $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
837: my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
838: my $title=&Apache::lonnet::gettitle();
839:
840: my $start_time;
841:
842: my $slot_name=
843: $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
844: if ($slot_name) {
845: my %slot=&Apache::lonnet::get_slot($slot_name);
846:
847: $start_time=$slot{'starttime'}
848: } else {
849: $start_time=
850: &Apache::lonnet::EXT('resource.0.opendate');
851: }
852: $start_time=&Apache::lonlocal::locallocaltime($start_time);
853:
854: my $status = "\n<div class='LC_$bt_status LC_criteria'>\n";
855:
856: if ($bt_status eq 'pass') {
857: $status.='<h2>You passed the '.$title.' given on '.
858: $start_time.'</h2>';
859: }
860: if ($bt_status eq 'fail') {
861: $status.='<h2>You did not pass the '.$title.' given on '.
862: $start_time.'</h2>';
863: if (!$previous) {
864: $status.=&add_request_another_attempt_button();
865: }
866: }
867: my $man_count=0;
868: my $opt_count=0;
869: my $opt_passed=0;
870: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
871: if ($Apache::bridgetask::dimensionmandatory{$dim_id}
872: eq 'N') {
873: $opt_count++;
874: if ($Apache::lonhomework::history{"resource.$version.0.$dim_id.status"} eq 'pass') {
875: $opt_passed++;
876: }
877: } else {
878: $man_count++;
879: }
880: }
881:
882: my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
883: $parstack,$safeeval);
884: if ($opt_req !~ /\S/) { $opt_req='0'; }
885: $status.="\n<p>".&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";
886:
887: my $internal_location=&internal_location();
888: $result=~s/\Q$internal_location\E/$status/;
889: }
890: $result.="\n</div>\n".
891: &Apache::loncommon::end_page({'discussion' => 1});
892: }
893: }
894: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
895: my $award='SUBMITTED';
896: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
897: 'portfiles',\$award);
898: if ($award eq 'SUBMITTED' &&
899: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
900: $Apache::lonhomework::results{"resource.0.tries"}=
901: $Apache::lonhomework::results{"resource.$version.0.tries"}=
902: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
903:
904: $Apache::lonhomework::results{"resource.0.award"}=
905: $Apache::lonhomework::results{"resource.$version.0.award"}=
906: $award;
907: $Apache::lonhomework::results{"resource.0.submission"}=
908: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
909: } else {
910: delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
911: $award = '';
912: }
913: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
914: &Apache::structuretags::finalize_storage();
915: if ($award eq 'SUBMITTED') {
916: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
917: if ($useslots =~ /^\s*no\s*$/i) {
918: &add_to_queue('gradingqueue',
919: {'type' => 'task',
920: 'time' => time});
921: } elsif (defined($Apache::inputtags::slot_name)) {
922: &add_to_queue('gradingqueue',
923: {'type' => 'task',
924: 'time' => time,
925: 'slot' => $Apache::inputtags::slot_name});
926: }
927: }
928: } elsif ($Apache::lonhomework::results{'INTERNAL_store'}) {
929: &Apache::structuretags::finalize_storage();
930: }
931: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
932: my $optional_required=
933: &Apache::lonxml::get_param('OptionalRequired',$parstack,
934: $safeeval);
935: my $optional_passed=0;
936: my $mandatory_failed=0;
937: my $ungraded=0;
938: my $review=0;
939: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
940: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
941: my $status=
942: $Apache::lonhomework::results{"resource.$version.0.$dim_id.status"};
943: my $mandatory=
944: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
945: if ($status eq 'pass') {
946: if (!$mandatory) { $optional_passed++; }
947: } elsif ($status eq 'fail') {
948: if ($mandatory) { $mandatory_failed++; }
949: } elsif ($status eq 'ungraded') {
950: $ungraded++;
951: } elsif ($status eq 'review') {
952: $review++;
953: } else {
954: $ungraded++;
955: }
956: }
957: if ($optional_passed < $optional_required) {
958: $mandatory_failed++;
959: }
960: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
961: $Apache::lonhomework::results{'resource.0.regrader'}=
962: $env{'user.name'}.':'.$env{'user.domain'};
963: if ($review) {
964: $Apache::lonhomework::results{"resource.$version.0.status"}='review';
965: if ($env{'form.queue'} eq 'reviewqueue') {
966: &check_queue_unlock($env{'form.queue'});
967: &Apache::lonxml::debug(" still needs review not changing status.");
968: } else {
969: &move_between_queues($env{'form.queue'},'reviewqueue');
970: }
971: } elsif ($ungraded) {
972: $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
973: if ($env{'form.queue'} eq 'reviewqueue' ||
974: $env{'form.queue'} eq 'none' ) {
975: &Apache::lonxml::debug("moving back.");
976: &move_between_queues($env{'form.queue'},'gradingqueue');
977: } else {
978: &check_queue_unlock($env{'form.queue'});
979: }
980: } elsif ($mandatory_failed) {
981: $Apache::lonhomework::results{"resource.$version.0.status"}='fail';
982: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
983: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
984: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
985: &remove_from_queue($env{'form.queue'});
986:
987: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
988:
989: if ($env{'form.regrade'} ne 'yes') {
990: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
991: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
992: &Apache::grades::version_portfiles(
993: \%Apache::lonhomework::results,
994: ["$version.0.bridgetask"],$courseid,
995: $symb,$udom,$uname,
996: ["$version.0.bridgetask"]);
997: }
998: } else {
999: $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1000: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
1001: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
1002: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1003: &remove_from_queue($env{'form.queue'});
1004:
1005: my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
1006: if ($env{'form.regrade'} ne 'yes') {
1007: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1008: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1009: &Apache::grades::version_portfiles(
1010: \%Apache::lonhomework::results,
1011: ["$version.0.bridgetask"],$courseid,
1012: $symb,$udom,$uname,
1013: ["$version.0.bridgetask"]);
1014: }
1015: }
1016: $Apache::lonhomework::results{"resource.0.status"}=
1017: $Apache::lonhomework::results{"resource.$version.0.status"};
1018: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1019: $Apache::lonhomework::results{"resource.0.award"}=
1020: $Apache::lonhomework::results{"resource.$version.0.award"};
1021: $Apache::lonhomework::results{"resource.0.awarded"}=
1022: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1023: $Apache::lonhomework::results{"resource.0.solved"}=
1024: $Apache::lonhomework::results{"resource.$version.0.solved"};
1025: }
1026: &minimize_storage();
1027: &Apache::structuretags::finalize_storage();
1028: }
1029: } elsif ($target eq 'webgrade') {
1030: $result.="</div>";
1031: #$result.='<input type="submit" name="next" value="'.
1032: # &mt('Save & Next').'" /> ';
1033: #$result.='<input type="submit" name="end" value="'.
1034: # &mt('Save & Stop Grading').'" /> ';
1035: #$result.='<input type="submit" name="throwaway" value="'.
1036: # &mt('Throw Away & Stop Grading').'" /> ';
1037: #$result.='<input type="submit" name="save" value="'.
1038: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1039: $result.='</form>'."\n</div>\n</div>\n".
1040: &Apache::loncommon::end_page();
1041: } elsif ($target eq 'meta') {
1042: $result.=&Apache::response::meta_package_write('Task');
1043: $result.=&Apache::response::meta_stores_write('solved','string',
1044: 'Problem Status');
1045: $result.=&Apache::response::meta_stores_write('tries','int_zeropos',
1046: 'Number of Attempts');
1047: $result.=&Apache::response::meta_stores_write('awarded','float',
1048: 'Partial Credit Factor');
1049: $result.=&Apache::response::meta_stores_write('status','string',
1050: 'Bridge Task Status');
1051: }
1052: undef($Apache::lonhomework::parsing_a_task);
1053: return $result;
1054: }
1055:
1056: sub move_between_queues {
1057: my ($src_queue,$dest_queue)=@_;
1058: my $cur_data;
1059: if ($src_queue ne 'none') {
1060: $cur_data=&get_queue_data($src_queue);
1061: if (!$cur_data) { return 'not_exist'; }
1062: } else {
1063: $cur_data = ['none'];
1064: }
1065: my $result=&add_to_queue($dest_queue,$cur_data);
1066: if ($result ne 'ok') {
1067: return $result;
1068: }
1069: &check_queue_unlock($src_queue);
1070: return &remove_from_queue($src_queue);
1071: }
1072:
1073: sub check_queue_unlock {
1074: my ($queue,$key,$allow_not_me)=@_;
1075: if ($queue eq 'none') { return 'ok'; }
1076: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1077: if (!defined($key)) {
1078: $key="$symb\0queue\0$uname:$udom";
1079: }
1080: my $cnum=$env{'course.'.$cid.'.num'};
1081: my $cdom=$env{'course.'.$cid.'.domain'};
1082: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1083: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1084: if ($who eq $me) {
1085: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1086: } elsif ($allow_not_me) {
1087: &Apache::lonxml::debug("unlocking $who by $me");
1088: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1089: }
1090: return 'not_owner';
1091: }
1092:
1093: sub in_queue {
1094: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1095: if ($queue eq 'none') { return 0; }
1096: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1097: || !defined($udom) || !defined($uname)) {
1098: ($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
1099: $cnum=$env{'course.'.$cid.'.num'};
1100: $cdom=$env{'course.'.$cid.'.domain'};
1101: }
1102:
1103: my $key=&encode_queue_key($symb,$udom,$uname);
1104: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1105:
1106: if (defined($results{$key})) {
1107: return 1;
1108: }
1109: return 0;
1110: }
1111:
1112: sub remove_from_queue {
1113: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1114: if ($queue eq 'none') { return 'ok'; }
1115: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1116: || !defined($udom) || !defined($uname)) {
1117: ($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
1118: $cnum=$env{'course.'.$cid.'.num'};
1119: $cdom=$env{'course.'.$cid.'.domain'};
1120: }
1121: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1122: return 'ok';
1123: }
1124: my $key=&encode_queue_key($symb,$udom,$uname);
1125: my @keys=($key,"$key\0locked");
1126: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1127: }
1128:
1129: sub setup_env_for_other_user {
1130: my ($queue_key,$safeeval)=@_;
1131: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1132: &Apache::lonxml::debug("setup_env for $queue_key");
1133: $env{'form.grade_symb'}=$symb;
1134: $env{'form.grade_domain'}=$udom;
1135: $env{'form.grade_username'}=$uname;
1136: $env{'form.grade_courseid'}=$env{'request.course.id'};
1137: &Apache::lonxml::initialize_rndseed($safeeval);
1138: }
1139:
1140: sub get_queue_data {
1141: my ($queue)=@_;
1142: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1143: my $cnum=$env{'course.'.$cid.'.num'};
1144: my $cdom=$env{'course.'.$cid.'.domain'};
1145: my $todo="$symb\0queue\0$uname:$udom";
1146: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1147: if ($key eq $todo && ref($value)) {
1148: return $value;
1149: }
1150: return undef;
1151: }
1152:
1153:
1154: sub check_queue_for_key {
1155: my ($cdom,$cnum,$queue,$todo)=@_;
1156:
1157: my %results=
1158: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1159:
1160: if (exists($results{$todo}) && ref($results{$todo})) {
1161: if (defined($results{"$todo\0locked"})) {
1162: return 'locked';
1163: }
1164: if (my $slot=&slotted_access($results{$todo})) {
1165: my %slot_data=&Apache::lonnet::get_slot($slot);
1166: if ($slot_data{'endtime'} > time) {
1167: return 'in_progress';
1168: }
1169: } else {
1170: my ($symb) = &decode_queue_key($todo);
1171: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1172: if ($due_date > time) {
1173: return 'in_progress';
1174: }
1175: }
1176: return 'enqueued';
1177: }
1178: return undef;
1179: }
1180:
1181: sub add_to_queue {
1182: my ($queue,$user_data)=@_;
1183: if ($queue eq 'none') { return 'ok'; }
1184: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1185: if (!$cid || $env{'request.state'} eq 'construct') {
1186: return 'no_queue';
1187: }
1188: my $cnum=$env{'course.'.$cid.'.num'};
1189: my $cdom=$env{'course.'.$cid.'.domain'};
1190: my %data;
1191: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1192: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1193: }
1194:
1195: sub show_queue {
1196: my ($queue,$with_selects)=@_;
1197: my $result;
1198: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1199: my $cnum=$env{'course.'.$cid.'.num'};
1200: my $cdom=$env{'course.'.$cid.'.domain'};
1201:
1202: my @chosen_sections=
1203: &Apache::loncommon::get_env_multiple('form.chosensections');
1204: &Apache::grades::init_perm();
1205: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1206: &Apache::grades::reset_perm();
1207: if (!(grep(/^all$/,@chosen_sections))) {
1208: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1209: '</tt>.</p> '."\n";
1210: }
1211:
1212: my $regexp="^$symb\0";
1213: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1214: my ($tmp)=%queue;
1215: if ($tmp=~/^error: 2 /) {
1216: return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1217: }
1218: my $title=&Apache::lonnet::gettitle($symb);
1219: $result.="\n<h3>Current Queue - $title $queue </h3><table border='1'><tr>";
1220: if ($with_selects) { $result.="<th>Status</th><th></th>"; }
1221: $result.="<th>user</th><th>data</th></tr>";
1222: foreach my $key (sort(keys(%queue))) {
1223: my ($symb,$uname,$udom) = &decode_queue_key($key);
1224: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1225: if ($key=~/locked$/ && !$with_selects) {
1226: $result.="<tr><td>$uname</td>";
1227: $result.='<td>'.$queue{$key}.'</td></tr>';
1228: } elsif ($key=~/timestamp$/ && !$with_selects) {
1229: $result.="<tr><td></td>";
1230: $result.='<td>'.
1231: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1232: } elsif ($key!~/(timestamp|locked)$/) {
1233: $result.="<tr>";
1234: my ($end_time,$slot_text);
1235: if (my $slot=&slotted_access($queue{$key})) {
1236: my %slot_data=&Apache::lonnet::get_slot($slot);
1237: $end_time = $slot_data{'endtime'};
1238: $slot_text = &mt('Slot: [_1]',$slot);
1239: } else {
1240: $end_time = &Apache::lonhomework::due_date('0',$symb);
1241: $slot_text = '';
1242: }
1243: if ($with_selects) {
1244: my $ekey=&Apache::lonnet::escape($key);
1245: my ($action,$description,$status)=('select',&mt('Select'));
1246: if (exists($queue{"$key\0locked"})) {
1247: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1248: $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1249: if ($me eq $queue{"$key\0locked"}) {
1250: ($action,$description)=('resume',&mt('Resume'));
1251: } else {
1252: ($action,$description)=('unlock',&mt('Unlock'));
1253: }
1254: }
1255: my $seclist;
1256: foreach my $sec (@chosen_sections) {
1257: $seclist.='<input type="hidden" name="chosensections"
1258: value="'.$sec.'" />';
1259: }
1260: if ($end_time ne '' && time > $end_time) {
1261: $result.=(<<FORM);
1262: <td>$status</td>
1263: <td>
1264: <form style="display: inline" method="post">
1265: <input type="hidden" name="gradingkey" value="$ekey" />
1266: <input type="hidden" name="queue" value="$queue" />
1267: <input type="hidden" name="gradingaction" value="$action" />
1268: <input type="hidden" name="webgrade" value="no" />
1269: <input type="hidden" name="queuemode" value="selected" />
1270: <input type="submit" name="submit" value="$description" />
1271: $seclist
1272: </form>
1273: </td>
1274: FORM
1275:
1276: } else {
1277: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1278: }
1279: }
1280: $result.= "<td>".$fullname->{$uname.':'.$udom}.
1281: " <tt>($uname:$udom)</tt> </td>";
1282: $result.='<td>'.$slot_text.' End time: '.
1283: &Apache::lonlocal::locallocaltime($end_time).
1284: "</td></tr>";
1285: }
1286: }
1287: $result.="</table><hr />\n";
1288: return $result;
1289: }
1290:
1291: sub get_queue_counts {
1292: my ($queue)=@_;
1293: my $result;
1294: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1295: my $cnum=$env{'course.'.$cid.'.num'};
1296: my $cdom=$env{'course.'.$cid.'.domain'};
1297: my $regexp="^$symb\0";
1298: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1299: my ($tmp)=%queue;
1300: if ($tmp=~/^error: 2 /) {
1301: return (0,0,0);
1302: }
1303: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1304: my %slot_cache;
1305: foreach my $key (sort(keys(%queue))) {
1306: if ($key=~/locked$/) {
1307: $locks++;
1308: } elsif ($key=~/timestamp$/) {
1309: #ignore
1310: } elsif ($key!~/(timestamp|locked)$/) {
1311: my ($symb,$uname,$udom) = &decode_queue_key($key);
1312: $entries++;
1313: if (my $slot=&slotted_access($queue{$key})) {
1314: if (!exists($slot_cache{$slot})) {
1315: my %slot_data=&Apache::lonnet::get_slot($slot);
1316: $slot_cache{$slot} = \%slot_data;
1317: }
1318: if (time > $slot_cache{$slot}{'endtime'}) {
1319: $ready_to_grade++;
1320: }
1321: } else {
1322: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1323: if ($due_date ne '' && time > $due_date) {
1324: $ready_to_grade++;
1325: }
1326: }
1327: }
1328: }
1329: return ($entries,$ready_to_grade,$locks);
1330: }
1331:
1332: sub encode_queue_key {
1333: my ($symb,$udom,$uname)=@_;
1334: return "$symb\0queue\0$uname:$udom";
1335: }
1336:
1337: sub decode_queue_key {
1338: my ($key)=@_;
1339: my ($symb,undef,$user) = split("\0",$key);
1340: my ($uname,$udom) = split(':',$user);
1341: return ($symb,$uname,$udom);
1342: }
1343:
1344: sub queue_key_locked {
1345: my ($queue,$key,$cdom,$cnum)=@_;
1346: if (!defined($cdom) || !defined($cnum)) {
1347: my (undef,$cid)=&Apache::lonxml::whichuser();
1348: $cnum=$env{'course.'.$cid.'.num'};
1349: $cdom=$env{'course.'.$cid.'.domain'};
1350: }
1351: my ($key_locked,$value)=
1352: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1353: if ($key_locked eq "$key\0locked") {
1354: return $value;
1355: }
1356: return undef;
1357: }
1358:
1359: sub slotted_access {
1360: my ($queue_entry) = @_;
1361: if (ref($queue_entry) eq 'ARRAY') {
1362: if (defined($queue_entry->[0])) {
1363: return $queue_entry->[0];
1364: }
1365: return undef;
1366: } elsif (ref($queue_entry) eq 'HASH') {
1367: if (defined($queue_entry->{'slot'})) {
1368: return $queue_entry->{'slot'};
1369: }
1370: return undef;
1371: }
1372: return undef;
1373: }
1374:
1375: sub pick_from_queue_data {
1376: my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
1377: my @possible; # will hold queue entries that are valid to be selected
1378: foreach my $key (keys(%$queuedata)) {
1379: if ($key =~ /\0locked$/) { next; }
1380: if ($key =~ /\0timestamp$/) { next; }
1381: my ($symb,$uname,$udom)=&decode_queue_key($key);
1382: if ($check_section) {
1383: my $section=&Apache::lonnet::getsection($uname,$udom);
1384: if ($section eq $check_section) {
1385: &Apache::lonxml::debug("my sec");
1386: next;
1387: }
1388: }
1389: my $end_time;
1390: if (my $slot=&slotted_access($queuedata->{$key})) {
1391: my %slot_data=&Apache::lonnet::get_slot($slot);
1392: if ($slot_data{'endtime'} < time) {
1393: $end_time = $slot_data{'endtime'};
1394: }
1395: } else {
1396: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1397: if ($due_date > time) {
1398: $end_time = $due_date;
1399: }
1400: }
1401: if ($end_time ne '') {
1402: &Apache::lonxml::debug("not time");
1403: next;
1404: }
1405:
1406: if (exists($queuedata->{"$key\0locked"})) {
1407: &Apache::lonxml::debug("someone already has um.");
1408: next;
1409: }
1410: push(@possible,[$key,$end_time]);
1411: }
1412: if (@possible) {
1413: # sort entries in order by slot end time
1414: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1415: # pick one of the entries in the top 10% in small queues and one
1416: # of the first ten entries in large queues
1417: #my $ten_percent = int($#possible * 0.1);
1418: #if ($ten_percent < 1 ) { $ten_percent = 1; }
1419: #if ($ten_percent > 10) { $ten_percent = 10; }
1420: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1421:
1422: #return $possible[int(rand($max))][0];
1423: return $possible[0][0];
1424: }
1425: return undef;
1426: }
1427:
1428: sub find_mid_grade {
1429: my ($queue,$symb,$cdom,$cnum)=@_;
1430: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1431: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1432: if ($todo) {
1433: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1434: if ($who eq $me) { return $todo; }
1435: }
1436: my $regexp="^$symb\0.*\0locked\$";
1437: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1438: foreach my $key (keys(%locks)) {
1439: my $who=$locks{$key};
1440: if ($who eq $me) {
1441: $todo=$key;
1442: $todo=~s/\0locked$//;
1443: return $todo;
1444: }
1445: }
1446: return undef;
1447: }
1448:
1449: sub lock_key {
1450: my ($queue,$todo)=@_;
1451: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1452: my (undef,$cid)=&Apache::lonxml::whichuser();
1453: my $cnum=$env{'course.'.$cid.'.num'};
1454: my $cdom=$env{'course.'.$cid.'.domain'};
1455: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1456: $cdom,$cnum);
1457: &Apache::lonxml::debug("success $success $todo");
1458: if ($success eq 'ok') {
1459: return 1;
1460: }
1461: return 0;
1462: }
1463:
1464: sub get_queue_symb_status {
1465: my ($queue,$symb,$cdom,$cnum) = @_;
1466: if (!defined($cdom) || !defined($cnum)) {
1467: my (undef,$cid)=&Apache::lonxml::whichuser();
1468: $cnum=$env{'course.'.$cid.'.num'};
1469: $cdom=$env{'course.'.$cid.'.domain'};
1470: }
1471: my $regexp="^$symb\0";
1472: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1473: my ($tmp)=%queue;
1474: if ($tmp=~/^error: 2 /) { return; }
1475: my @users;
1476: foreach my $key (sort(keys(%queue))) {
1477: next if ($key=~/locked$/);
1478: next if ($key=~/timestamp$/);
1479: my ($symb,$uname,$udom) = &decode_queue_key($key);
1480: push(@users,"$uname:$udom");
1481: }
1482: return @users;
1483: }
1484:
1485: sub get_from_queue {
1486: my ($queue)=@_;
1487: my $result;
1488: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1489: my $cnum=$env{'course.'.$cid.'.num'};
1490: my $cdom=$env{'course.'.$cid.'.domain'};
1491: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1492: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1493: if ($todo) { return $todo; }
1494: my $attempts=0;
1495: while (1) {
1496: if ($attempts > 2) {
1497: # tried twice to get a queue entry, giving up
1498: return (undef,'unable');
1499: }
1500: my $starttime=time;
1501: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
1502: $cdom,$cnum);
1503: &Apache::lonxml::debug("$starttime");
1504: my $regexp="^$symb\0queue\0";
1505: my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1506:
1507: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1508: #make a pass looking for a user _not_ in my section
1509: if ($env{'request.course.sec'}) {
1510: &Apache::lonxml::debug("sce");
1511: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1512: \%queue,$cdom,$cnum);
1513: &Apache::lonxml::debug("sce $todo");
1514: }
1515: # no one _not_ in our section so look for any user that is
1516: # ready for grading
1517: if (!$todo) {
1518: &Apache::lonxml::debug("no sce");
1519: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum);
1520: &Apache::lonxml::debug("no sce $todo");
1521: }
1522: # no user to grade
1523: if (!$todo) { last; }
1524: &Apache::lonxml::debug("got $todo");
1525: # otherwise found someone so lets try to lock them
1526: # unless someone else already picked them
1527: if (!&lock_key($queue,$todo)) {
1528: $attempts++;
1529: next;
1530: }
1531: my (undef,$endtime)=
1532: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1533: $cdom,$cnum);
1534: &Apache::lonxml::debug("emd $endtime");
1535: # someone else already modified the queue,
1536: # perhaps our picked user wass already fully graded between
1537: # when we picked him and when we locked his record? so lets
1538: # double check.
1539: if ($endtime != $starttime) {
1540: my ($key,$value)=
1541: &Apache::lonnet::get($queue,["$todo"],
1542: $cdom,$cnum);
1543: &Apache::lonxml::debug("check $key .. $value");
1544: if ($key eq $todo && ref($value)) {
1545: } else {
1546: &Apache::lonnet::del($queue,["$todo\0locked"],
1547: $cdom,$cnum);
1548: &Apache::lonxml::debug("del");
1549: $attempts++;
1550: next;
1551: }
1552: }
1553: &Apache::lonxml::debug("last $todo");
1554: last;
1555: }
1556: return $todo;
1557: }
1558:
1559: sub select_user {
1560: my ($symb,$cid)=&Apache::lonxml::whichuser();
1561:
1562: my @chosen_sections=
1563: &Apache::loncommon::get_env_multiple('form.chosensections');
1564: &Apache::grades::init_perm();
1565: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
1566: &Apache::grades::reset_perm();
1567:
1568: my $result;
1569: if (!(grep(/^all$/,@chosen_sections))) {
1570: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1571: '</tt>.</p> '."\n";
1572: }
1573: $result.='<table border="1">';
1574:
1575: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1576: my ($uname,$udom) = split(/:/,$student);
1577:
1578: my $cnum=$env{'course.'.$cid.'.num'};
1579: my $cdom=$env{'course.'.$cid.'.domain'};
1580: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
1581: 'Task');
1582: my $queue = 'none';
1583: my $cannot_grade;
1584: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1585: $queue = 'reviewqueue';
1586: if ($status{'reviewqueue'} eq 'in_progress') {
1587: $cannot_grade=1;
1588: }
1589: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1590: $queue = 'gradingqueue';
1591: if ($status{'gradingqueue'} eq 'in_progress') {
1592: $cannot_grade=1;
1593: }
1594: }
1595: my $todo =
1596: &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
1597: if ($cannot_grade) {
1598: $result.='<tr><td> </td><td>'.$fullname->{$student}.
1599: '</td><td>';
1600: } else {
1601: my $seclist;
1602: foreach my $sec (@chosen_sections) {
1603: $seclist.='<input type="hidden" name="chosensections"
1604: value="'.$sec.'" />';
1605: }
1606: my $studentdis = $student;
1607: $studentdis =~ tr/:/@/;
1608: $result.=<<RESULT;
1609: <tr>
1610: <td>
1611: <form style="display: inline" method="post">
1612: <input type="hidden" name="gradingkey" value="$todo" />
1613: <input type="hidden" name="queue" value="$queue" />
1614: <input type="hidden" name="webgrade" value="no" />
1615: <input type="hidden" name="regrade" value="yes" />
1616: <input type="submit" name="submit" value="Regrade" />
1617: $seclist
1618: </form>
1619: <td>$fullname->{$student} <tt>($studentdis)</tt></td>
1620: <td>
1621: RESULT
1622: }
1623: if ($status{'status'} eq 'pass') {
1624: $result .= '<font color="green">'.&mt('Passed').'</font>';
1625: } elsif ($status{'status'} eq 'fail') {
1626: $result .= '<font color="red">'.&mt('Failed').'</font>';
1627: } elsif ($status{'status'} eq 'review') {
1628: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1629: } elsif ($status{'status'} eq 'ungraded') {
1630: $result .= &mt('Ungraded');
1631: } elsif ($status{'status'} ne '') {
1632: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1633: } else {
1634: $result.=" ";
1635: }
1636: if ($status{'version'}) {
1637: $result .= ' '.&mt('Version').' '.$status{'version'};
1638: }
1639: if ($status{'grader'}) {
1640: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
1641: }
1642: $result.= '</td><td>';
1643: if ($status{'reviewqueue'} eq 'enqueued') {
1644: $result .= &mt('Awaiting Review');
1645: } elsif ($status{'reviewqueue'} eq 'locked') {
1646: $result .= &mt('Under Review');
1647: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1648: $result .= &mt('Still being worked on.');
1649: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1650: $result .= &mt('Awaiting Grading');
1651: } elsif ($status{'gradingqueue'} eq 'locked') {
1652: $result .= &mt('Being Graded');
1653: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1654: $result .= &mt('Still being worked on.');
1655: } else {
1656: $result.=" ";
1657: }
1658: $result.= '</td></tr>';
1659: }
1660: $result.='</table>';
1661: return $result;
1662: }
1663:
1664: sub get_student_status {
1665: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
1666:
1667: my %status;
1668:
1669: if ($type eq 'Task') {
1670: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1671: $udom,$uname);
1672: $status{'status'}=$record{'resource.0.status'};
1673: $status{'version'}=$record{'resource.0.version'};
1674: $status{'grader'}=$record{'resource.0.regrader'};
1675: }
1676: $status{'reviewqueue'}=
1677: &check_queue_for_key($cdom,$cnum,'reviewqueue',
1678: &encode_queue_key($symb,$udom,$uname));
1679: $status{'gradingqueue'}=
1680: &check_queue_for_key($cdom,$cnum,'gradingqueue',
1681: &encode_queue_key($symb,$udom,$uname));
1682: return %status;
1683: }
1684:
1685: sub start_ClosingParagraph {
1686: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1687: my $result;
1688: if ($target eq 'web') {
1689: } elsif ($target eq 'webgrade') {
1690: &Apache::lonxml::startredirection();
1691: }
1692: return $result;
1693: }
1694:
1695: sub end_ClosingParagraph {
1696: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1697: my $result;
1698: if ($target eq 'web') {
1699: } elsif ($target eq 'webgrade') {
1700: &Apache::lonxml::endredirection();
1701: }
1702: return $result;
1703: }
1704:
1705: sub get_id {
1706: my ($parstack,$safeeval)=@_;
1707: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1708: if (!$id) { $id=$Apache::lonxml::curdepth; }
1709: return $id;
1710: }
1711:
1712: my %dimension;
1713: sub start_Question { return &start_Dimension(@_); }
1714: sub start_Dimension {
1715: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1716: undef(%dimension);
1717: my $dim_id=&get_id($parstack,$safeeval);
1718: $Apache::bridgetask::dimension=$dim_id;
1719: push(@Apache::bridgetask::dimensionlist,$dim_id);
1720: undef(@Apache::bridgetask::instance);
1721: $Apache::bridgetask::dimensionmandatory{$dim_id}=
1722: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1723: &Apache::lonxml::startredirection();
1724: return &internal_location($dim_id);
1725: }
1726:
1727: sub get_instance {
1728: my ($dim)=@_;
1729: my $rand_alg=&Apache::lonnet::get_rand_alg();
1730: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
1731: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
1732: $rand_alg eq '64bit4' ) {
1733: &Apache::response::pushrandomnumber();
1734: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1735: my $num=@order;
1736: my $version=&get_version();
1737: my $which=($version-1)%$num;
1738: return $order[$which];
1739: } else {
1740: my ($version,$previous) = &get_version();
1741: my $instance =
1742: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
1743: if (defined($instance)) { return $instance; }
1744:
1745: &Apache::response::pushrandomnumber();
1746: my @instances = @{$dimension{'instances'}};
1747: # remove disabled instances
1748: for (my $i=0; $i < $#instances; $i++) {
1749: if ($dimension{$instances[$i].'.disabled'}) {
1750: splice(@instances,$i,1);
1751: $i--;
1752: }
1753: }
1754: @instances = &Math::Random::random_permutation(@instances);
1755: $instance = $instances[($version-1)%scalar(@instances)];
1756: if ($version =~ /^\d$/) {
1757: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
1758: $instance;
1759: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
1760: }
1761: &Apache::response::poprandomnumber();
1762: return $instance;
1763: }
1764: }
1765:
1766: {
1767: my $last_link;
1768: sub link {
1769: my ($id) = @_;
1770: $id =~ s/\./_/g;
1771: return 'LC_GRADING_criteria_'.$id;
1772: }
1773: sub end_Question { return &end_Dimension(@_); }
1774: sub end_Dimension {
1775: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1776: my $result=&Apache::lonxml::endredirection();
1777: my $dim=&get_id($parstack,$safeeval);
1778: my $instance=&get_instance($dim);
1779: my $version=&get_version();
1780: use Data::Dumper;
1781: &Apache::lonxml::debug(Dumper(\%dimension));
1782: if ($target eq 'web') {
1783: @Apache::scripttag::parser_env = @_;
1784: $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
1785: my @instances = $instance;
1786: if (&Apache::response::showallfoils()) {
1787: @instances = @{$dimension{'instances'}};
1788: }
1789: foreach my $instance (@instances) {
1790: @Apache::scripttag::parser_env = @_;
1791: $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1792: if ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass' ||
1793: $Apache::lonhomework::history{"resource.$version.0.status"} eq 'fail') {
1794:
1795: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
1796: my $mandatory='Mandatory';
1797: if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
1798: $mandatory='Optional';
1799: }
1800: my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1801: if ($dim_status eq 'pass') {
1802: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1803: }
1804: if ($dim_status eq 'fail') {
1805: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1806: }
1807: my $man_count=0;
1808: my $man_passed=0;
1809: my $opt_count=0;
1810: my $opt_passed=0;
1811: foreach my $id ( @{$dimension{$instance.'.criterias'}},
1812: @{$dimension{'criterias'}} ) {
1813: if ($dimension{'criteria.'.$id.'.mandatory'}
1814: eq 'N') {
1815: $opt_count++;
1816: if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"} eq 'pass') {
1817: $opt_passed++;
1818: }
1819: } else {
1820: $man_count++;
1821: if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"} eq 'pass') {
1822: $man_passed++;
1823: }
1824: }
1825: }
1826: if ($man_passed eq $man_count) { $man_passed='all'; }
1827:
1828: my $opt_req=$dimension{$instance.'.optionalrequired'};
1829: if ($opt_req !~ /\S/) {
1830: $opt_req=
1831: &Apache::lonxml::get_param('OptionalRequired',
1832: $parstack,$safeeval);
1833: if ($opt_req !~ /\S/) { $opt_req = 0; }
1834: }
1835: $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>";
1836:
1837: my $internal_location=&internal_location($dim);
1838: $result=~s/\Q$internal_location\E/$dim_info/;
1839:
1840: foreach my $id (@{$dimension{$instance.'.criterias'}},
1841: @{$dimension{'criterias'}}) {
1842: my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"};
1843: my $comment=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"};
1844: my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');
1845: if ($mandatory) {
1846: $mandatory='Mandatory';
1847: } else {
1848: $mandatory='Optional';
1849: }
1850: if ($status eq 'fail') {
1851: } elsif ($status eq 'pass') {
1852: } else {
1853: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
1854: }
1855: my $status_display=$status;
1856: $status_display=~s/^([a-z])/uc($1)/e;
1857: $result.=
1858: '<div class="LC_'.$status.' LC_criteria"><h4>'
1859: .$mandatory.' Criteria</h4><p>';
1860: @Apache::scripttag::parser_env = @_;
1861: $result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
1862: $result.='</p><p class="LC_grade">'.$status_display.'</p>';
1863: if ($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}) {
1864: $result.='<p class="LC_comment">'.&mt('Comment: [_1]',$Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'</p>';
1865: }
1866: $result.='</div>';
1867: }
1868: }
1869: }
1870: } elsif ($target eq 'webgrade') {
1871: # in case of any side effects that we need
1872: @Apache::scripttag::parser_env = @_;
1873: &Apache::scripttag::xmlparse($dimension{'intro'});
1874: @Apache::scripttag::parser_env = @_;
1875: &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
1876: foreach my $id (@{$dimension{$instance.'.criterias'}},
1877: @{$dimension{'criterias'}} ) {
1878: my $link=&link($id);
1879: my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$id.status"};
1880: $result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
1881: '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
1882: @Apache::scripttag::parser_env = @_;
1883: $result.=&Apache::scripttag::xmlparse($dimension{'criteria.'.$id});
1884: $result.='</div>'."\n".
1885: #$dimension{'criteria.'.$id}.
1886: '<div class="LC_GRADING_grade">'."\n".
1887: '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
1888: '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
1889: '<label class="LC_GRADING_pass"><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label>'."\n".
1890: '<label class="LC_GRADING_review"><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label>'."\n".
1891: '</div>'."\n".
1892: '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
1893: '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.0.$dim.$id.comment"}).'</textarea>'."\n".
1894: '</label>'."\n".
1895: '<ul class="LC_GRADING_navbuttons">'."\n".
1896: '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
1897: '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
1898: '</ul>'."\n".
1899: '</div>'."\n";
1900: $result.=&grading_history($version,$dim,$id);
1901: $last_link=$link;
1902: }
1903: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1904: my $optional_passed=0;
1905: my $mandatory_failed=0;
1906: my $ungraded=0;
1907: my $review=0;
1908: foreach my $id (@{$dimension{$instance.'.criterias'}},
1909: @{$dimension{'criterias'}}) {
1910: my $link=&link($id);
1911: my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
1912: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1913: my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');
1914: if ($status eq 'pass') {
1915: if (!$mandatory) { $optional_passed++; }
1916: } elsif ($status eq 'fail') {
1917: if ($mandatory) { $mandatory_failed++; }
1918: } elsif ($status eq 'review') {
1919: $review++;
1920: } elsif ($status eq 'ungraded') {
1921: $ungraded++;
1922: } else {
1923: $ungraded++;
1924: }
1925: }
1926: # FIXME optional required can apply to only <instance> right now...
1927: my $opt_req=$dimension{$instance.'.optionalrequired'};
1928: if ($opt_req !~ /\S/) {
1929: $opt_req=
1930: &Apache::lonxml::get_param('OptionalRequired',
1931: $parstack,$safeeval);
1932: if ($opt_req !~ /\S/) { $opt_req = 0; }
1933: }
1934: if ($optional_passed < $opt_req) {
1935: $mandatory_failed++;
1936: }
1937: &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1938: if ($review) {
1939: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1940: 'review';
1941: } elsif ($ungraded) {
1942: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1943: 'ungraded';
1944: } elsif ($mandatory_failed) {
1945: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1946: 'fail';
1947: } else {
1948: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1949: 'pass';
1950: }
1951: } else {
1952: # any other targets no output
1953: undef($result);
1954: }
1955: return $result;
1956: }
1957: }
1958:
1959: sub grading_history {
1960: my ($version,$dim,$id) = @_;
1961: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1962: return '';
1963: }
1964: my ($result,$grader);
1965: my $scope="resource.$version.0.$dim.$id";
1966: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
1967: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
1968: my ($gname,$gdom) =
1969: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1970: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
1971: $grader = &Apache::loncommon::aboutmewrapper($fullname,
1972: $gname,$gdom);
1973: }
1974: my $entry;
1975: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
1976: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
1977: }
1978: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
1979: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
1980: }
1981: if ($entry) {
1982: $result.= "<li>$grader : $entry </li>";
1983: }
1984: }
1985: if ($result) {
1986: return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1987: }
1988: return '';
1989: }
1990:
1991: sub start_IntroParagraph {
1992: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1993: my $result;
1994: if ($target eq 'web' || $target eq 'webgrade') {
1995: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1996: $dimension{'intro'}=
1997: &Apache::lonxml::get_all_text('/introparagraph',
1998: $parser,$style);
1999: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
2000: &Apache::lonxml::startredirection();
2001: }
2002:
2003: }
2004: return $result;
2005: }
2006:
2007: sub end_IntroParagraph {
2008: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2009: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
2010: my $result = &Apache::lonxml::endredirection();
2011: }
2012: }
2013:
2014: sub start_Instance {
2015: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2016: my $id=&get_id($parstack,$safeeval);
2017: push(@{$dimension{'instances'}},$id);
2018: push(@Apache::bridgetask::instance,$id);
2019: push(@Apache::bridgetask::instancelist,$id);
2020: $dimension{$id.'.optionalrequired'}=
2021: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
2022: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2023: if (lc($disabled) eq 'yes') {
2024: $dimension{$id.'.disabled'}='1';
2025: }
2026: return '';
2027: }
2028:
2029: sub end_Instance {
2030: }
2031:
2032: sub start_InstanceText {
2033: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2034: my $instance_id=$Apache::bridgetask::instance[-1];
2035: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
2036: if ($target eq 'web' || $target eq 'webgrade') {
2037: $dimension{$instance_id.'.text'}=$text;
2038: }
2039: return '';
2040: }
2041:
2042: sub end_InstanceText {
2043: return '';
2044: }
2045:
2046: sub start_Criteria {
2047: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2048: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
2049: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
2050: my $id=&get_id($parstack,$safeeval);
2051: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
2052: my $instance_id=$Apache::bridgetask::instance[-1];
2053: $dimension{"criteria.$instance_id.$id"}=$criteria;
2054: $dimension{"criteria.$instance_id.$id.mandatory"}=
2055: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2056: push(@{$dimension{$instance_id.'.criterias'}},"$instance_id.$id");
2057: } else {
2058: $dimension{'criteria.'.$id}=$criteria;
2059: $dimension{'criteria.'.$id.'.mandatory'}=
2060: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2061: push(@{$dimension{'criterias'}},$id);
2062: }
2063: }
2064: return '';
2065: }
2066:
2067: sub end_Criteria {
2068: }
2069:
2070: sub proctor_validation_screen {
2071: my ($slot) = @_;
2072: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
2073: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2074: my $name=&Apache::loncommon::plainname($user,$domain);
2075:
2076: my $msg;
2077: if ($env{'form.proctorpassword'}) {
2078: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
2079: .'</font></p>';
2080: }
2081: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
2082: my $result= (<<ENDCHECKOUT);
2083: <h2>Proctor Validation</h2>
2084: <p>Your room's proctor needs to validate your access to this resource.</p>
2085: $msg
2086: <form name="checkout" method="post" action="$env{'request.uri'}">
2087: <input type="hidden" name="validate" value="yes" />
2088: <input type="hidden" name="submitted" value="yes" />
2089: <table>
2090: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
2091: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
2092: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
2093: </table>
2094: <input type="submit" name="checkoutbutton" value="Validate" /><br />
2095: <table border="1">
2096: <tr><td>
2097: <table>
2098: <tr><td colspan="2">Student who should be logged in is:</td></tr>
2099: <tr><td>Name:</td><td>$name</td></tr>
2100: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
2101: <tr><td>Usename</td><td>$user:$domain</td></tr>
2102: <tr><td colspan="2"><img src="$url" /></td></tr>
2103: </table>
2104: </tr></td>
2105: </table>
2106: </form>
2107: ENDCHECKOUT
2108: return $result;
2109: }
2110:
2111: 1;
2112: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>