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