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