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