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