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