Annotation of loncom/homework/bridgetask.pm, revision 1.33
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.33 ! albertel 4: # $Id: bridgetask.pm,v 1.32 2005/05/27 17:08:03 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;
39: use Time::HiRes qw( gettimeofday tv_interval );
1.9 albertel 40:
1.1 albertel 41: BEGIN {
42: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
43: }
44:
1.9 albertel 45: sub initialize_bridgetask {
46: # id of current Dimension, 0 means that no dimension is current
47: # (inside <Task> only)
48: $Apache::bridgetask::dimension='';
49: # list of all Dimension ids seen
50: @Apache::bridgetask::dimensionlist=();
1.20 albertel 51: # mandatory attribute of all Dimensions seen
52: %Apache::bridgetask::dimensionmandatory=();
1.9 albertel 53: # list of all current Instance ids
54: @Apache::bridgetask::instance=();
55: # list of all Instance ids seen in this problem
56: @Apache::bridgetask::instancelist=();
1.15 albertel 57: # key of queud user data that we are currently grading
58: $Apache::bridgetask::queue_key='';
1.9 albertel 59: }
60:
1.4 albertel 61: sub proctor_check_auth {
1.22 albertel 62: my ($slot_name,$slot)=@_;
1.11 albertel 63: my $user=$env{'form.proctorname'};
64: my $domain=$env{'form.proctordomain'};
1.4 albertel 65:
66: my @allowed=split(",",$slot->{'proctor'});
67: foreach my $possible (@allowed) {
68: my ($puser,$pdom)=(split('@',$possible));
69: if ($puser eq $user && $pdom eq $domain) {
1.11 albertel 70: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
1.4 albertel 71: if ($authhost ne 'no_host') {
1.23 albertel 72: my $version=
73: $Apache::lonhomework::results{'resource.version'}=
1.27 albertel 74: ++$Apache::lonhomework::history{'resource.version'};
1.23 albertel 75: $Apache::lonhomework::results{"resource.$version.checkedin"}=
1.4 albertel 76: $user.'@'.$domain;
1.23 albertel 77: $Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
1.22 albertel 78: $slot_name;
1.28 albertel 79: foreach my $key (keys(%Apache::lonhomework::history)) {
80: if ($key=~/^resource\.0\./) {
81: $Apache::lonhomework::results{$key}='';
82: }
83: }
1.4 albertel 84: return 1;
85: }
86: }
87: }
88: return 0;
89: }
90:
1.25 albertel 91: sub get_version {
1.29 albertel 92: my ($version,$previous);
1.25 albertel 93: if ($env{'form.previousversion'} &&
94: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
1.29 albertel 95: $version=$env{'form.previousversion'};
96: $previous=1;
97: } else {
98: $version=$Apache::lonhomework::history{'resource.version'};
99: $previous=0;
100: }
101: if (wantarray) {
102: return ($version,$previous);
1.25 albertel 103: }
1.29 albertel 104: return $version;
1.25 albertel 105: }
106:
1.8 albertel 107: sub add_previous_version_button {
1.25 albertel 108: my ($status)=@_;
1.8 albertel 109: my $result;
1.29 albertel 110: if ($Apache::lonhomework::history{'resource.version'} eq '') {
1.25 albertel 111: return '';
112: }
1.29 albertel 113: if ($Apache::lonhomework::history{'resource.version'} < 2 &&
114: $status ne 'NEEDS_CHECKIN') {
1.25 albertel 115: return '';
116: }
1.29 albertel 117: my $version=&get_version();
118: if ($env{'form.previousversion'} ne '' &&
119: $env{'form.previousversion'} eq $version) {
120: $result.="<h3>".&mt("Showing previous version [_1]",$version).
121: "</h3>\n";
122: }
123: my @to_show;
124: foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
125: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
126: push(@to_show,$test_version);
127: }
128: }
129: my $list='<option>'.
130: join("</option>\n<option>",@to_show).
131: "</option>\n";
132: $result.='<form name="getprevious" method="POST" action="';
133: my $uri=$env{'request.uri'};
134: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
135: $result.=$uri.'">'.
136: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
137: <option>'.&mt('Pick one').'</option>
138: '.$list.'
139: </select>')."</form>";
1.8 albertel 140: return $result;
141: }
142:
1.13 albertel 143: sub add_grading_button {
1.29 albertel 144: my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13 albertel 145: &mt("Get a submission to grade").'" />';
146: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.32 albertel 147: if ( 1) {
148: #need a permissions for limitng this to 'powerful users'
149: #check if review queue has items
150: $result.=' <input type="submit" name="reviewasubmission" value="'.
1.33 ! albertel 151: &mt("Select an entry from the review queue").'" />'."\n";
! 152: $result.=' <input type="submit" name="reviewagrading" value="'.
! 153: &mt("Select an entry from the grading queue").'" />'."\n";
1.32 albertel 154: }
1.13 albertel 155: return $result;
156: }
157:
1.22 albertel 158: sub add_request_another_attempt_button {
1.25 albertel 159: my $result;
160: $result.=' <input type="submit" name="requestattempt" value="'.
161: &mt("Request another attempt").'" />';
162: return $result;
1.22 albertel 163: }
164:
1.30 albertel 165: sub preserve_grade_info {
166: my $result;
167: # if we are viewing someone else preserve that info
168: if (defined $env{'form.grade_symb'}) {
169: foreach my $field ('symb','courseid','domain','username') {
170: $result .= '<input type="hidden" name="grade_'.$field.
171: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
172: }
173: }
174: return $result;
175: }
176:
1.1 albertel 177: sub start_Task {
178: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
179:
1.4 albertel 180: my ($status,$accessmsg,$slot);
1.16 albertel 181: if ($target ne 'webgrade') {
182: &Apache::structuretags::initialize_storage();
183: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
184: }
185:
1.4 albertel 186: $Apache::lonhomework::parsing_a_task=1;
1.1 albertel 187: #should get back a <html> or the neccesary stuff to start XML/MathML
188: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
189: &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.16 albertel 190:
1.8 albertel 191: if ($target eq 'web') {
1.13 albertel 192: if ($Apache::lonhomework::modifygrades) {
193: $body_tag_start.='<form name="gradesubmission" method="POST" action="';
194: my $uri=$env{'request.uri'};
195: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
196: $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
197: }
1.8 albertel 198: }
1.21 albertel 199: if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
1.1 albertel 200: $target eq 'tex') {
1.29 albertel 201: my ($version,$previous)=&get_version();
1.14 albertel 202: ($status,$accessmsg,my $slot_name,$slot) =
1.4 albertel 203: &Apache::lonhomework::check_task_access('0');
1.9 albertel 204: push(@Apache::inputtags::status,$status);
1.14 albertel 205: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 206: my $expression='$external::datestatus="'.$status.'";';
1.23 albertel 207: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
1.1 albertel 208: &Apache::run::run($expression,$safeeval);
209: &Apache::lonxml::debug("Got $status");
1.25 albertel 210: $body_tag_start.=&add_previous_version_button($status);
1.29 albertel 211: if (!$previous && (
212: ( $status eq 'CLOSED' ) ||
213: ( $status eq 'BANNED') ||
214: ( $status eq 'UNAVAILABLE') ||
215: ( $status eq 'NOT_IN_A_SLOT') ||
216: ( $status eq 'NEEDS_CHECKIN') ||
217: ( $status eq 'WAITING_FOR_GRADE') ||
218: ( $status eq 'INVALID_ACCESS') )) {
1.1 albertel 219: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
220: if ( $target eq "web" ) {
1.4 albertel 221: $result.= $head_tag_start.'</head>'.$body_tag_start;
222: my $msg;
1.1 albertel 223: if ($status eq 'UNAVAILABLE') {
224: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 225: } elsif ($status eq 'NOT_IN_A_SLOT') {
226: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.4 albertel 227: } elsif ($status eq 'NEEDS_CHECKIN') {
228: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
229: '</h1>'.&proctor_validation_screen($slot);
1.22 albertel 230: } elsif ($status eq 'WAITING_FOR_GRADE') {
231: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.1 albertel 232: } elsif ($status ne 'NOT_YET_VIEWED') {
233: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
234: }
235: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
236: $msg.='The problem '.$accessmsg;
237: }
238: $result.=$msg.'<br />';
239: } elsif ($target eq 'tex') {
240: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
241: if ($status eq 'UNAVAILABLE') {
242: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
243: } else {
244: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
245: }
1.22 albertel 246: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 247: if ($status eq 'NEEDS_CHECKIN') {
1.22 albertel 248: if (&proctor_check_auth($slot_name,$slot)) {
1.4 albertel 249: #FIXME immeadiatly add this to the grading queue
250: # with slot->{'endtime'} for when grading can
251: # begin on this resource
1.22 albertel 252: # FIXME I think the above is done by default,
253: # need to check that
254: # failure doesn't do this.
1.4 albertel 255: }
256: }
1.1 albertel 257: }
258: } elsif ($target eq 'web') {
259: my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
260: $result.="$head_tag_start<title>$name</title></head>
261: $body_tag_start \n $form_tag_start".
262: '<input type="hidden" name="submitted" value="yes" />';
1.30 albertel 263: $result.=&preserve_grade_info();
1.29 albertel 264: my ($version,$previous)=&get_version();
1.25 albertel 265: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 266: $result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
1.29 albertel 267: if (!$previous) {
268: $result.=&add_request_another_attempt_button();
269: }
1.22 albertel 270: }
1.25 albertel 271: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
1.22 albertel 272: $result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
273: }
1.1 albertel 274: }
1.21 albertel 275: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
276: $target eq 'webgrade') {
1.32 albertel 277: my $webgrade='yes';
1.21 albertel 278: if ($target eq 'webgrade') {
1.32 albertel 279: $result.=$head_tag_start.$body_tag_start;
1.31 albertel 280: $result.='<br />Review'.&show_queue('reviewqueue');
1.33 ! albertel 281: $result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 282: }
1.33 ! albertel 283: # FIXME Blast! still need to reorg this, need to reshow the
! 284: # queue being reviewed once done with the grade pass...
! 285: # Hrrm, vaildation pass should perhaps say 'not_locked'
! 286: # perhaps do a search if there is a key that is mine and if
! 287: # there isn't reshow the queue....
! 288: my ($todo,$status_code)=&get_key_todo($target);
! 289:
! 290: &Apache::lonnet::logthis("got todo -$todo- stat -$status_code-");
! 291: if ($todo) {
! 292: &setup_env_for_other_user($todo,$safeeval);
! 293: my ($symb,$uname,$udom)=&decode_queue_key($todo);
! 294: $result.="\n".'<table><tr><td>Found '.
! 295: &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
! 296: $form_tag_start.=
! 297: '<input type="hidden" name="gradingkey" value="'.
! 298: &Apache::lonnet::escape($todo).'" />';
! 299: $Apache::bridgetask::queue_key=$todo;
! 300: &Apache::structuretags::initialize_storage();
! 301: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
! 302: if ($target eq 'webgrade') {
! 303: $result.='<br />After -'.&show_queue($env{'form.queue'});
! 304: $result.="\n".'<table width="100%" style="width:100%" border="1">';
! 305: if ($status_code eq 'selected') {
! 306: $form_tag_start.=
! 307: '<input type="hidden" name="queuemode" value="selected" />';
! 308: }
! 309: }
1.15 albertel 310: } else {
1.33 ! albertel 311: if ($target eq 'webgrade') {
! 312: $result.="\n";
! 313: if ($status_code eq 'stop') {
! 314: $result.='<b>'.&mt("Stopped grading.").'</b>';
! 315: } elsif ($status_code eq 'lock_failed') {
! 316: $result.='<b>'.&mt("Failed to lock the request record.").'</b>';
! 317: } elsif ($status_code eq 'unlock') {
! 318: $result.='<b>'.&mt("Unlocked the requested record.").'</b>';
! 319: $result.=&show_queue($env{'form.queue'},1);
! 320: } elsif ($status_code eq 'show_list') {
! 321: $result.=&show_queue($env{'form.queue'},1);
! 322: } else {
! 323: $result.='<b>'.&mt("No user to be graded.").'</b>';
1.32 albertel 324: }
1.21 albertel 325: }
1.33 ! albertel 326: $webgrade='no';
! 327: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
1.32 albertel 328: }
329: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
330: $result.=$form_tag_start;
331: $result.='<input type="hidden" name="webgrade" value="'.
332: $webgrade.'" />';
333: $result.='<input type="hidden" name="queue" value="'.
334: $env{'form.queue'}.'" />';
1.15 albertel 335: }
1.1 albertel 336: } else {
337: # page_start returned a starting result, delete it if we don't need it
338: $result = '';
339: }
340: return $result;
341: }
342:
1.32 albertel 343: sub get_key_todo {
344: my ($target)=@_;
345: my $todo;
1.33 ! albertel 346:
! 347: if (defined($env{'form.reviewasubmission'})) {
! 348: &Apache::lonnet::logthis("review a submission....");
! 349: $env{'form.queue'}='reviewqueue';
! 350: return (undef,'show_list');
! 351: }
! 352:
! 353: if (defined($env{'form.reviewagrading'})) {
! 354: &Apache::lonxml::debug("review a grading....");
! 355: $env{'form.queue'}='gradingqueue';
! 356: return (undef,'show_list');
! 357: }
! 358:
1.32 albertel 359: my $queue=$env{'form.queue'};
1.33 ! albertel 360:
1.32 albertel 361: if (!defined($queue)) {
362: $env{'form.queue'}=$queue='gradingqueue';
363: }
1.33 ! albertel 364:
1.32 albertel 365: my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.33 ! albertel 366:
1.32 albertel 367: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 ! albertel 368: && !defined($env{'form.gradingaction'})
! 369: && $env{'form.queuemode'} eq 'selected') {
! 370:
! 371: my $who=&queue_key_locked($queue,$gradingkey);
! 372: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
! 373: if ($who eq $me) {
! 374: &Apache::lonxml::debug("Found a key was given to me");
! 375: return ($gradingkey,'selected');
! 376: } else {
! 377: return (undef,'show_list');
! 378: }
! 379:
! 380: }
! 381:
! 382: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
! 383: if ($env{'form.gradingaction'} eq 'resume') {
! 384: delete($env{'form.gradingaction'});
! 385: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 386: return ($gradingkey);
1.33 ! albertel 387: } elsif ($env{'form.gradingaction'} eq 'unlock') {
! 388: &Apache::lonxml::debug("Unlocking a key ".
! 389: &check_queue_unlock($queue,$gradingkey,1));
! 390: return (undef,'unlock');
! 391: } elsif ($env{'form.gradingaction'} eq 'select') {
! 392: &Apache::lonxml::debug("Locking a key");
! 393: if (&lock_key($queue,$gradingkey)) {
! 394: &Apache::lonxml::debug("Success $queue");
! 395: return ($gradingkey);
! 396: }
! 397: &Apache::lonxml::debug("Failed $queue");
! 398: return (undef,'lock_failed');
1.32 albertel 399: }
400: }
1.33 ! albertel 401:
! 402: if ($env{'form.queuemode'} ne 'selected') {
! 403: # don't get something new from the queue if they hit the stop button
! 404: if (!($env{'form.stop'} && $target eq 'webgrade')
! 405: && !$env{'form.gradingaction'}) {
! 406: &Apache::lonxml::debug("Getting anew $queue");
! 407: return (&get_from_queue($queue));
! 408: } else {
! 409: return (undef,'stop');
! 410: }
1.32 albertel 411: }
1.33 ! albertel 412: return (undef,undef)
1.32 albertel 413: }
414:
1.1 albertel 415: sub end_Task {
416: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
417: my $result='';
418: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 419: my ($version,$previous)=&get_version();
1.1 albertel 420: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 421: $target eq 'tex') {
1.1 albertel 422: if (
1.11 albertel 423: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.1 albertel 424: ($target eq 'answer') || ($target eq 'tex')
425: ) {
426: if ($target eq 'web') {
1.29 albertel 427: if ($status eq 'CAN_ANSWER' && !$previous) {
1.15 albertel 428: $result.="\n".'<table border="1">'.
1.28 albertel 429: &Apache::inputtags::file_selector("$version.0",
430: "bridgetask","*",
1.9 albertel 431: 'portfolioonly').
432: "</table>";
433: $result.=&Apache::inputtags::gradestatus('0');
434: }
1.13 albertel 435: }
436: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 437: $result.=&Apache::lonxml::xmlend().'</html>';
438: }
439: }
1.29 albertel 440: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 441: my $award='SUBMITTED';
1.28 albertel 442: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 443: 'portfiles',\$award);
1.14 albertel 444: if ($award eq 'SUBMITTED' &&
1.28 albertel 445: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
446: $Apache::lonhomework::results{"resource.0.tries"}=
447: $Apache::lonhomework::results{"resource.$version.0.tries"}=
448: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
449:
450: $Apache::lonhomework::results{"resource.0.award"}=
451: $Apache::lonhomework::results{"resource.$version.0.award"}=
452: $award;
1.10 albertel 453: }
1.4 albertel 454: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
455: &Apache::structuretags::finalize_storage();
1.14 albertel 456: if ($award eq 'SUBMITTED') {
1.31 albertel 457: &add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
1.14 albertel 458: }
1.1 albertel 459: }
1.32 albertel 460: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
1.20 albertel 461: my $optional_required=
462: &Apache::lonxml::get_param('OptionalRequired',$parstack,
463: $safeeval);
464: my $optional_passed=0;
465: my $mandatory_failed=0;
466: my $ungraded=0;
467: my $review=0;
1.21 albertel 468: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.20 albertel 469: foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
470: my $status=
1.25 albertel 471: $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
1.20 albertel 472: my $mandatory=
473: ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
474: if ($status eq 'pass') {
475: if (!$mandatory) { $optional_passed++; }
476: } elsif ($status eq 'fail') {
477: if ($mandatory) { $mandatory_failed++; }
478: } elsif ($status eq 'ungraded') {
479: $ungraded++;
480: } elsif ($status eq 'review') {
481: $review++;
482: }
483: }
484: if ($optional_passed < $optional_required) {
485: $mandatory_failed++;
486: }
1.21 albertel 487: &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
488: $Apache::lonhomework::results{'resource.grader'}=
1.20 albertel 489: $env{'user.name'}.'@'.$env{'user.domain'};
490: if ($review) {
1.25 albertel 491: $Apache::lonhomework::results{"resource.$version.status"}='review';
1.33 ! albertel 492: if ($env{'form.queue'} eq 'reviewqueue') {
! 493: &check_queue_unlock($env{'form.queue'});
! 494: &Apache::lonxml::debug(" still needs review not changing status.");
! 495: } else {
! 496: &move_between_queues('gradingqueue','reviewqueue');
! 497: }
1.20 albertel 498: } elsif ($ungraded) {
1.25 albertel 499: $Apache::lonhomework::results{"resource.$version.status"}='ungraded';
1.32 albertel 500: # FIXME if in review queue need to move back to grading queue
1.33 ! albertel 501: if ($env{'form.queue'} eq 'reviewqueue') {
! 502: &Apache::lonxml::debug("moving back.");
! 503: &move_between_queues('reviewqueue','gradingqueue');
! 504: } else {
! 505: &check_queue_unlock($env{'form.queue'});
! 506: }
1.20 albertel 507: } elsif ($mandatory_failed) {
1.25 albertel 508: $Apache::lonhomework::results{"resource.$version.status"}='fail';
509: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
510: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
511: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.32 albertel 512: &remove_from_queue($env{'form.queue'});
1.20 albertel 513: } else {
1.25 albertel 514: $Apache::lonhomework::results{"resource.$version.status"}='pass';
515: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
516: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
517: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 518: &remove_from_queue($env{'form.queue'});
1.20 albertel 519: }
1.26 albertel 520: $Apache::lonhomework::results{"resource.status"}=
521: $Apache::lonhomework::results{"resource.$version.status"};
1.28 albertel 522: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 523: $Apache::lonhomework::results{"resource.0.award"}=
524: $Apache::lonhomework::results{"resource.$version.award"};
525: $Apache::lonhomework::results{"resource.0.awarded"}=
526: $Apache::lonhomework::results{"resource.$version.awarded"};
527: $Apache::lonhomework::results{"resource.0.solved"}=
528: $Apache::lonhomework::results{"resource.$version.solved"};
1.25 albertel 529: }
1.21 albertel 530: &Apache::structuretags::finalize_storage();
1.20 albertel 531: }
1.15 albertel 532: } elsif ($target eq 'webgrade') {
1.18 albertel 533: $result.="</table>\n<hr />";
1.20 albertel 534: #$result.='<input type="submit" name="next" value="'.
535: # &mt('Save & Next').'" /> ';
536: #$result.='<input type="submit" name="end" value="'.
537: # &mt('Save & Stop Grading').'" /> ';
538: #$result.='<input type="submit" name="throwaway" value="'.
539: # &mt('Throw Away & Stop Grading').'" /> ';
540: #$result.='<input type="submit" name="save" value="'.
541: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.15 albertel 542: $result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
1.1 albertel 543: } elsif ($target eq 'meta') {
1.2 albertel 544: $result.='<parameter part="0" package="Task"></parameter>'."\n";
1.1 albertel 545: #$result.=&Apache::response::meta_part_order();
546: #$result.=&Apache::response::meta_response_order();
547: }
1.4 albertel 548: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 549: return $result;
550: }
551:
1.31 albertel 552: sub move_between_queues {
553: my ($src_queue,$dest_queue)=@_;
554: my $cur_data=&get_queue_data($src_queue);
555: if (!$cur_data) { return 'not_exist'; }
556: my $result=&add_to_queue($dest_queue,$cur_data->[0]);
557: if ($result ne 'ok') {
558: return $result;
559: }
560: &check_queue_unlock($src_queue);
561: return &remove_from_queue($src_queue);
1.21 albertel 562: }
563:
564: sub check_queue_unlock {
1.32 albertel 565: my ($queue,$key,$allow_not_me)=@_;
1.30 albertel 566: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
1.32 albertel 567: if (!defined($key)) {
568: $key="$symb\0queue\0$uname\@$udom";
569: }
1.30 albertel 570: my $cnum=$env{'course.'.$cid.'.num'};
571: my $cdom=$env{'course.'.$cid.'.domain'};
572: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
573: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
574: if ($who eq $me) {
1.32 albertel 575: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
576: } elsif ($allow_not_me) {
1.33 ! albertel 577: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 578: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 579: }
1.32 albertel 580: return 'not_owner';
1.21 albertel 581: }
582:
583: sub remove_from_queue {
1.30 albertel 584: my ($queue)=@_;
1.27 albertel 585: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
586: my $cnum=$env{'course.'.$cid.'.num'};
587: my $cdom=$env{'course.'.$cid.'.domain'};
588: my $key="$symb\0queue\0$uname\@$udom";
589: my @keys=($key,"$key\0locked");
1.31 albertel 590: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 591: }
592:
1.16 albertel 593: sub setup_env_for_other_user {
594: my ($queue_key,$safeeval)=@_;
595: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 596: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 597: $env{'form.grade_symb'}=$symb;
598: $env{'form.grade_domain'}=$udom;
599: $env{'form.grade_username'}=$uname;
600: $env{'form.grade_courseid'}=$env{'request.course.id'};
601: &Apache::lonxml::initialize_rndseed($safeeval);
602: }
603:
1.31 albertel 604: sub get_queue_data {
605: my ($queue)=@_;
606: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
607: my $cnum=$env{'course.'.$cid.'.num'};
608: my $cdom=$env{'course.'.$cid.'.domain'};
609: my $todo="$symb\0queue\0$uname\@$udom";
610: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
611: if ($key eq $todo && ref($value)) {
612: return $value;
613: }
614: return undef;
615: }
616:
1.14 albertel 617: sub add_to_queue {
1.31 albertel 618: my ($queue,$slot_name)=@_;
1.14 albertel 619: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
620: my $cnum=$env{'course.'.$cid.'.num'};
621: my $cdom=$env{'course.'.$cid.'.domain'};
622: my %data;
1.31 albertel 623: $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name];
624: return &Apache::lonnet::put($queue,\%data,$cdom,$cnum);
1.14 albertel 625: }
626:
627: sub show_queue {
1.32 albertel 628: my ($queue,$with_selects)=@_;
1.14 albertel 629: my $result;
630: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
631: my $cnum=$env{'course.'.$cid.'.num'};
632: my $cdom=$env{'course.'.$cid.'.domain'};
1.16 albertel 633: my $regexp="^$symb\0";
1.30 albertel 634: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 635: my ($tmp)=%queue;
636: if ($tmp=~/^error: 2 /) {
1.33 ! albertel 637: return "\n<h3>Current Queue - $queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
1.31 albertel 638: }
1.33 ! albertel 639: $result.="\n<h3>Current Queue - $queue </h3><table border='1'><tr>";
1.32 albertel 640: if ($with_selects) { $result.="<th></th>"; }
641: $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
1.14 albertel 642: foreach my $key (sort(keys(%queue))) {
1.32 albertel 643: if ($key=~/locked$/ && !$with_selects) {
1.16 albertel 644: my ($symb,$uname,$udom) = &decode_queue_key($key);
645: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 646: $result.="<tr><td>$title</td><td>$uname</td>";
1.16 albertel 647: $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
1.32 albertel 648: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.16 albertel 649: my ($symb,undef) = split("\0",$key);
650: my $title=&Apache::lonnet::gettitle($symb);
1.27 albertel 651: $result.="<tr><td>$title</td><td></td>";
1.16 albertel 652: $result.='<td>last queue modification time</td><td>'.
653: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 654: } elsif ($key!~/(timestamp|locked)$/) {
1.16 albertel 655: my ($symb,$uname,$udom) = &decode_queue_key($key);
656: my $title=&Apache::lonnet::gettitle($symb);
1.32 albertel 657: $result.="<tr>";
658: if ($with_selects) {
659: my $ekey=&Apache::lonnet::escape($key);
660: my ($action,$description)=('select',&mt('Select'));
661: if (exists($queue{"$key\0locked"})) {
662: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
663: if ($me eq $queue{"$key\0locked"}) {
664: ($action,$description)=('resume',&mt('Resume'));
665: } else {
666: ($action,$description)=('unlock',&mt('Unlock'));
667: }
668: }
669: $result.=(<<FORM);
670: <td>
671: <form method="POST">
672: <input type="hidden" name="gradingkey" value="$ekey" />
673: <input type="hidden" name="queue" value="$queue" />
674: <input type="hidden" name="gradingaction" value="$action" />
675: <input type="hidden" name="webgrade" value="no" />
1.33 ! albertel 676: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 677: <input type="submit" name="submit" value="$description" />
678: </form>
679: </td>
680: FORM
681: }
682: $result.="<td>$title</td><td>$uname</td>";
1.16 albertel 683: my $slot=$queue{$key}->[0];
684: my %slot_data=&Apache::lonnet::get_slot($slot);
1.27 albertel 685: $result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
1.20 albertel 686: &Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
687: "</td></tr>";
1.16 albertel 688: }
1.14 albertel 689: }
1.15 albertel 690: $result.="</table><hr />\n";
1.14 albertel 691: return $result;
692: }
693:
694: sub decode_queue_key {
695: my ($key)=@_;
696: my ($symb,undef,$user) = split("\0",$key);
697: my ($uname,$udom) = split('@',$user);
698: return ($symb,$uname,$udom);
699: }
700:
701: sub queue_key_locked {
1.30 albertel 702: my ($queue,$key,$cdom,$cnum)=@_;
1.33 ! albertel 703: if (!defined($cdom) || !defined($cnum)) {
! 704: my (undef,$cid)=&Apache::lonxml::whichuser();
! 705: $cnum=$env{'course.'.$cid.'.num'};
! 706: $cdom=$env{'course.'.$cid.'.domain'};
! 707: }
1.14 albertel 708: my ($key_locked,$value)=
1.30 albertel 709: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 710: if ($key_locked eq "$key\0locked") {
711: return $value;
712: }
713: return undef;
714: }
715:
716: sub pick_from_queue_data {
1.30 albertel 717: my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
718: foreach my $key (keys(%$queuedata)) {
1.14 albertel 719: my ($symb,$uname,$udom)=&decode_queue_key($key);
720: if ($check_section) {
721: my $section=&Apache::lonnet::getsection($uname,$udom);
1.17 albertel 722: if ($section eq $check_section) {
1.33 ! albertel 723: &Apache::lonxml::debug("my sec");
1.15 albertel 724: next;
725: }
1.14 albertel 726: }
1.30 albertel 727: my $slot=$queuedata->{$key}[0];
1.14 albertel 728: my %slot_data=&Apache::lonnet::get_slot($slot);
1.15 albertel 729: if ($slot_data{'endtime'} > time) {
1.33 ! albertel 730: &Apache::lonxml::debug("not time");
1.15 albertel 731: next;
732: }
1.30 albertel 733: if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
1.33 ! albertel 734: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 735: next;
736: }
1.14 albertel 737: return $key;
738: }
739: return undef;
740: }
741:
1.15 albertel 742: sub find_mid_grade {
1.30 albertel 743: my ($queue,$symb,$cdom,$cnum)=@_;
1.16 albertel 744: my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
1.15 albertel 745: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
746: if ($todo) {
1.30 albertel 747: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 748: if ($who eq $me) { return $todo; }
749: }
750: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 751: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 752: foreach my $key (keys(%locks)) {
753: my $who=$locks{$key};
754: if ($who eq $me) {
755: $todo=$key;
756: $todo=~s/\0locked$//;
757: return $todo;
758: }
759: }
760: return undef;
761: }
762:
1.32 albertel 763: sub lock_key {
764: my ($queue,$todo)=@_;
765: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
766: my (undef,$cid)=&Apache::lonxml::whichuser();
767: my $cnum=$env{'course.'.$cid.'.num'};
768: my $cdom=$env{'course.'.$cid.'.domain'};
769: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
770: $cdom,$cnum);
1.33 ! albertel 771: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 772: if ($success eq 'ok') {
773: return 1;
774: }
775: return 0;
776: }
777:
1.14 albertel 778: sub get_from_queue {
1.30 albertel 779: my ($queue)=@_;
1.14 albertel 780: my $result;
781: my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
782: my $cnum=$env{'course.'.$cid.'.num'};
783: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 784: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 ! albertel 785: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 786: if ($todo) { return $todo; }
1.14 albertel 787: while (1) {
788: my $starttime=time;
1.30 albertel 789: &Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
1.14 albertel 790: $cdom,$cnum);
1.33 ! albertel 791: &Apache::lonxml::debug("$starttime");
1.14 albertel 792: my $regexp="^$symb\0queue\0";
1.30 albertel 793: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 ! albertel 794: #make a pass looking for a user _not_ in my section
1.14 albertel 795: if ($env{'request.course.sec'}) {
1.33 ! albertel 796: &Apache::lonxml::debug("sce");
1.30 albertel 797: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
798: \%queue,$cdom,$cnum);
1.33 ! albertel 799: &Apache::lonxml::debug("sce $todo");
1.14 albertel 800: }
1.33 ! albertel 801: # no one _not_ in our section so look for any user that is
! 802: # ready for grading
1.14 albertel 803: if (!$todo) {
1.33 ! albertel 804: &Apache::lonxml::debug("no sce");
1.31 albertel 805: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
806: \%queue,$cdom,$cnum);
1.33 ! albertel 807: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 808: }
809: # no user to grade
810: if (!$todo) { last; }
1.33 ! albertel 811: &Apache::lonxml::debug("got $todo");
1.14 albertel 812: # otherwise found someone so lets try to lock them
1.32 albertel 813: # unless someone else already picked them
814: if (!&lock_key($queue,$todo)) { next; }
1.14 albertel 815: my (undef,$endtime)=
1.30 albertel 816: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 817: $cdom,$cnum);
1.33 ! albertel 818: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 819: # someone else already modified the queue,
820: # perhaps our picked user wass already fully graded between
821: # when we picked him and when we locked his record? so lets
822: # double check.
823: if ($endtime != $starttime) {
824: my ($key,$value)=
1.30 albertel 825: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 826: $cdom,$cnum);
1.33 ! albertel 827: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 828: if ($key eq $todo && ref($value)) {
829: } else {
1.30 albertel 830: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 831: $cdom,$cnum);
1.33 ! albertel 832: &Apache::lonxml::debug("del");
1.14 albertel 833: next;
834: }
835: }
1.33 ! albertel 836: &Apache::lonxml::debug("last $todo");
1.14 albertel 837: last;
838: }
839: return $todo;
840: }
841:
1.1 albertel 842: sub start_ClosingParagraph {
843: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
844: my $result;
845: if ($target eq 'web') {
1.13 albertel 846: } elsif ($target eq 'webgrade') {
847: &Apache::lonxml::startredirection();
1.1 albertel 848: }
849: return $result;
850: }
851:
852: sub end_ClosingParagraph {
853: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
854: my $result;
855: if ($target eq 'web') {
1.13 albertel 856: } elsif ($target eq 'webgrade') {
857: &Apache::lonxml::endredirection();
1.1 albertel 858: }
859: return $result;
860: }
861:
1.19 albertel 862: sub get_id {
863: my ($parstack,$safeeval)=@_;
864: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
865: if (!$id) { $id=$Apache::lonxml::curdepth; }
866: return $id;
867: }
868:
1.1 albertel 869: my %dimension;
870: sub start_Dimension {
871: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
872: undef(%dimension);
1.19 albertel 873: my $dim_id=&get_id($parstack,$safeeval);
1.9 albertel 874: $Apache::bridgetask::dimension=$dim_id;
875: push(@Apache::bridgetask::dimensionlist,$dim_id);
876: undef(@Apache::bridgetask::instance);
1.20 albertel 877: $Apache::bridgetask::dimensionmandatory{$dim_id}=
878: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 879: return '';
880: }
881:
1.13 albertel 882: sub get_instance {
883: &Apache::response::pushrandomnumber();
884: my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
1.29 albertel 885: my $num=@order;
886: my $version=&get_version();
887: my $which=($version-1)%$num;
888: return $order[$which];
1.13 albertel 889: }
890:
1.18 albertel 891: {
892: my $last_link;
893: sub end_Dimension {
894: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
895: my $result;
1.25 albertel 896: my $dim=&get_id($parstack,$safeeval);
1.19 albertel 897: my $instance=&get_instance();
1.25 albertel 898: my $version=&get_version();
1.18 albertel 899: if ($target eq 'web') {
900: $result=$dimension{'intro'}.$dimension{$instance.'.text'};
1.26 albertel 901: if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
902: $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
1.22 albertel 903: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 904: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
905: my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
1.22 albertel 906: $result.='<table border="1"><tr><td>';
907: if ($status eq 'fail') {
908: $result.='<font color="red">'.&mt('Did not pass').'</font>';
909: } elsif ($status eq 'pass') {
910: $result.='<font color="green">'.&mt('Passed').'</font>';
911: } else {
912: &Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
913: }
914: $result.='</td></tr><tr><td>';
1.25 albertel 915: if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
916: $result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
1.22 albertel 917: }
918: $result.=$dimension{$instance.'.criteria.'.$id}.
919: '</td></tr></table>';
920: }
921: }
1.18 albertel 922: } elsif ($target eq 'webgrade') {
923: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
924: my $link='criteria_'.$instance.'_'.$id;
1.25 albertel 925: my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
1.19 albertel 926: $result.='<tr><td width="100%" valign="top">'.
1.18 albertel 927: '<a name="'.$link.'" />'.
928: '<a name="next_'.$last_link.'" />'.
929: '<br /><textarea enabled="false" style="width:100%" rows="8" width="25" wrap="hard">'.$dimension{$instance.'.criteria.'.$id}.'</textarea>'.
930: #$dimension{$instance.'.criteria.'.$id}.
931: '</td>'.
1.19 albertel 932: '<td><nobr>Additional Comment for Student</nobr> <br />'.
1.25 albertel 933: '<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 934: '</td>'.
935: '<td>'.
1.30 albertel 936: '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>'.&mt('Ungraded').'</label></nobr><br />'.
937: '<label><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label><br />'.
938: '<label><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label><br />'.
939: '<label><input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.&mt('Review').'</label><br />'.
1.18 albertel 940: '</td>'.
941: '<td>'.
942: '<a href="#'.$last_link.'">Prev</a><br />'.
1.20 albertel 943: '<a href="#next_'.$link.'">Next</a><br /><br /><br />'.
944: '<input type="submit" name="next" value="'.
945: &mt('Done').'" /> '.
1.30 albertel 946: '<input type="submit" name="stop" value="'.
947: &mt('Stop').'" /> '.
1.18 albertel 948: '</td></tr>';
1.22 albertel 949: $result.='<tr><td colspan="4">';
950: my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
951: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
1.23 albertel 952: foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.bridgetask.portfiles"})) {
1.22 albertel 953: my $file=$file_url.$partial_file;
954: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
955: $result.='<a href="'.$file.'" target="lonGRDs"><img src="'.
956: &Apache::loncommon::icon($file).'" border=0"> '.$file.
957: '</a>';
958: }
959: $result.='</td></tr>';
1.18 albertel 960: $last_link=$link;
961: }
1.22 albertel 962: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 963: my $optional_passed=0;
1.20 albertel 964: my $mandatory_failed=0;
965: my $ungraded=0;
966: my $review=0;
1.19 albertel 967: foreach my $id (@{$dimension{$instance.'.criterias'}}) {
1.25 albertel 968: my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
969: $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
1.20 albertel 970: my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
971: if ($status eq 'pass') {
972: if (!$mandatory) { $optional_passed++; }
973: } elsif ($status eq 'fail') {
974: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 975: } elsif ($status eq 'review') {
976: $review++;
1.20 albertel 977: } elsif ($status eq 'ungraded') {
978: $ungraded++;
1.21 albertel 979: } else {
1.22 albertel 980: &Apache::lonxml::error("got weird status --$status--");
1.19 albertel 981: }
982: }
1.20 albertel 983: if ($optional_passed < $dimension{$instance.'.optionalrequired'}) {
984: $mandatory_failed++;
985: }
1.21 albertel 986: &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 987: if ($review) {
1.25 albertel 988: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 989: 'review';
1.20 albertel 990: } elsif ($ungraded) {
1.25 albertel 991: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 992: 'ungraded';
1.20 albertel 993: } elsif ($mandatory_failed) {
1.25 albertel 994: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 995: 'fail';
1.20 albertel 996: } else {
1.25 albertel 997: $Apache::lonhomework::results{"resource.$version.$dim.status"}=
1.22 albertel 998: 'pass';
1.20 albertel 999: }
1.13 albertel 1000: }
1.18 albertel 1001: return $result;
1.1 albertel 1002: }
1003: }
1004:
1005: sub start_IntroParagraph {
1006: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1007: my $result;
1.13 albertel 1008: if ($target eq 'web' || $target eq 'webgrade') {
1009: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 1010: &Apache::lonxml::startredirection();
1011: }
1012: }
1013: return $result;
1014: }
1015:
1016: sub end_IntroParagraph {
1017: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1018: my $result;
1.13 albertel 1019: if ($target eq 'web' || $target eq 'webgrade') {
1020: if ($tagstack->[-2] eq 'Dimension' || $target eq 'webgrade') {
1.1 albertel 1021: $dimension{'intro'}=&Apache::lonxml::endredirection();
1022: }
1023: }
1024: return $result;
1025: }
1026:
1027: sub start_Instance {
1028: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 1029: my $id=&get_id($parstack,$safeeval);
1030: push(@{$dimension{'instances'}},$id);
1031: push(@Apache::bridgetask::instance,$id);
1032: push(@Apache::bridgetask::instancelist,$id);
1.20 albertel 1033: $dimension{$id.'.optionalrequired'}=
1.19 albertel 1034: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.1 albertel 1035: return '';
1036: }
1037:
1038: sub end_Instance {
1039: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1040: return '';
1041: }
1042:
1043: sub start_InstanceText {
1044: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.13 albertel 1045: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 1046: &Apache::lonxml::startredirection();
1047: }
1048: return '';
1049: }
1050:
1051: sub end_InstanceText {
1052: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1053: my $instance_id=$Apache::bridgetask::instance[-1];
1.13 albertel 1054: if ($target eq 'web' || $target eq 'webgrade') {
1.1 albertel 1055: $dimension{$instance_id.'.text'}=&Apache::lonxml::endredirection();
1056: }
1057: return '';
1058: }
1059:
1060: sub start_Criteria {
1061: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.21 albertel 1062: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 1063: &Apache::lonxml::startredirection();
1064: }
1065: return '';
1066: }
1067:
1068: sub end_Criteria {
1069: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.9 albertel 1070: my $instance_id=$Apache::bridgetask::instance[-1];
1.21 albertel 1071: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.1 albertel 1072: my $criteria=&Apache::lonxml::endredirection();
1.19 albertel 1073: my $id=&get_id($parstack,$safeeval);
1.1 albertel 1074: $dimension{$instance_id.'.criteria.'.$id}=$criteria;
1.19 albertel 1075: $dimension{$instance_id.'.criteria.'.$id.'.mandatory'}=
1076: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.1 albertel 1077: push(@{$dimension{$instance_id.'.criterias'}},$id);
1078: }
1079: return '';
1080: }
1081:
1.4 albertel 1082: sub proctor_validation_screen {
1083: my ($slot) = @_;
1084: my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.5 albertel 1085: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.11 albertel 1086: $user=$env{'form.proctorname'};
1087: if ($env{'form.proctordomain'}) { $domain=$env{'form.proctordomain'}; }
1.4 albertel 1088: my $msg;
1.11 albertel 1089: if ($env{'form.proctorpassword'}) {
1.4 albertel 1090: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
1091: .'</font></p>';
1092: }
1093: my $result= (<<ENDCHECKOUT);
1094: <h2>Proctor Validation</h2>
1095: <p>Your room's proctor needs to validate your access to this resource.</p>
1096: $msg
1.11 albertel 1097: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.4 albertel 1098: <input type="hidden" name="validate" value="yes" />
1099: <input type="hidden" name="submitted" value="yes" />
1100: <table>
1101: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$user" /></td></tr>
1102: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.6 albertel 1103: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$domain" /></td></tr>
1.4 albertel 1104: </table>
1105: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1106: Student who should be logged in is:<br />
1.5 albertel 1107: <img src="$url" /><br />
1.4 albertel 1108: </form>
1109: ENDCHECKOUT
1110: return $result;
1111: }
1112:
1.1 albertel 1113: 1;
1114: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>