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