Annotation of loncom/homework/bridgetask.pm, revision 1.264.8.1.2.3
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.264.8.1.2.3! (raeburn 4:: # $Id: bridgetask.pm,v 1.264.8.1.2.2 2023/01/23 20:34:54 raeburn 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.256 raeburn 40: use Apache::structuretags();
1.1 albertel 41: use Time::HiRes qw( gettimeofday tv_interval );
1.158 www 42: use LONCAPA;
43:
1.9 albertel 44:
1.1 albertel 45: BEGIN {
1.225 albertel 46: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','CriteriaText','GraderNote','ClosingParagraph'));
1.1 albertel 47: }
48:
1.169 albertel 49: my %dimension;
1.194 albertel 50: my $top = 'top';
51:
1.9 albertel 52: sub initialize_bridgetask {
53: # id of current Dimension, 0 means that no dimension is current
54: # (inside <Task> only)
1.178 albertel 55: @Apache::bridgetask::dimension=();
1.9 albertel 56: # list of all current Instance ids
1.168 albertel 57: %Apache::bridgetask::instance=();
1.9 albertel 58: # list of all Instance ids seen in this problem
59: @Apache::bridgetask::instancelist=();
1.15 albertel 60: # key of queud user data that we are currently grading
61: $Apache::bridgetask::queue_key='';
1.169 albertel 62: undef(%dimension);
1.9 albertel 63: }
64:
1.4 albertel 65: sub proctor_check_auth {
1.81 albertel 66: my ($slot_name,$slot,$type)=@_;
1.11 albertel 67: my $user=$env{'form.proctorname'};
1.264.8.1 raeburn 68: $user =~ s/^\s+|\s+$//g;
1.11 albertel 69: my $domain=$env{'form.proctordomain'};
1.264.8.1 raeburn 70:
1.4 albertel 71: my @allowed=split(",",$slot->{'proctor'});
72: foreach my $possible (@allowed) {
1.138 albertel 73: my ($puser,$pdom)=(split(':',$possible));
1.4 albertel 74: if ($puser eq $user && $pdom eq $domain) {
1.72 albertel 75: my $authenticated=0;
76: if ( $slot->{'secret'} =~ /\S/ &&
77: $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
78: $authenticated=1;
79: } else {
80:
81: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
82: if ($authhost ne 'no_host') {
83: $authenticated=1;
84: }
85: }
1.150 albertel 86: if ($authenticated) {
1.246 raeburn 87: my $check = &check_in($type,$user,$domain,$slot_name);
88: if ($check =~ /^error:/) {
89: return 0;
90: }
1.4 albertel 91: return 1;
92: }
93: }
94: }
95: return 0;
96: }
97:
1.174 albertel 98: sub check_in {
99: my ($type,$user,$domain,$slot_name) = @_;
100: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
101: if ( $useslots eq 'map_map') {
1.246 raeburn 102: my $result = &check_in_sequence($user,$domain,$slot_name);
103: if ($result =~ /^error: /) {
104: return $result;
105: }
1.174 albertel 106: } else {
107: &create_new_version($type,$user,$domain,$slot_name);
1.217 albertel 108: &Apache::structuretags::finalize_storage();
1.174 albertel 109: }
110: return 1;
111: }
112:
113: sub check_in_sequence {
114: my ($user,$domain,$slot_name) = @_;
115: my $navmap = Apache::lonnavmaps::navmap->new();
1.246 raeburn 116: if (!defined($navmap)) {
117: return 'error: ';
118: }
1.185 albertel 119: my ($symb) = &Apache::lonnet::whichuser();
1.174 albertel 120: my ($map) = &Apache::lonnet::decode_symb($symb);
1.175 albertel 121: my @resources =
1.264.8.1.2.3! (raeburn 122:: $navmap->retrieveResources($map, sub { $_[0]->is_problem() || $_[0]->is_tool() },0,0);
1.174 albertel 123: my %old_history = %Apache::lonhomework::history;
124: my %old_results = %Apache::lonhomework::results;
125:
126: foreach my $res (@resources) {
127: &Apache::lonxml::debug("doing ".$res->src);
128: &Apache::structuretags::initialize_storage($res->symb);
1.264.8.1.2.3! (raeburn 129:: my $type;
! 130:: if ($res->is_task()) {
! 131:: $type = 'Task';
! 132:: } elsif ($res->is_tool) {
! 133:: $type = 'tool';
! 134:: } else {
! 135:: $type = 'problem';
! 136:: }
1.174 albertel 137: &create_new_version($type,$user,$domain,$slot_name);
138: &Apache::structuretags::finalize_storage($res->symb);
139: }
140:
141: %Apache::lonhomework::history = %old_history;
142: %Apache::lonhomework::results = %old_results;
143: }
144:
1.150 albertel 145: sub create_new_version {
146: my ($type,$user,$domain,$slot_name) = @_;
1.174 albertel 147:
148: my $id = '0';
1.150 albertel 149: if ($type eq 'Task') {
150: # increment version
151: my $version=
152: $Apache::lonhomework::history{'resource.0.version'};
153: $version++;
1.152 albertel 154: &Apache::lonxml::debug("Making version $version");
1.150 albertel 155: #clean out all current results
156: foreach my $key (keys(%Apache::lonhomework::history)) {
157: if ($key=~/^resource\.0\./) {
158: $Apache::lonhomework::results{$key}='';
159: }
160: }
161:
162: #setup new version and who did it
1.174 albertel 163: $Apache::lonhomework::results{'resource.0.version'}=$version;
164: $id = "$version.0";
1.178 albertel 165: if (!defined($user) || !defined($domain)) {
1.174 albertel 166: $user = $env{'user.name'};
167: $domain = $env{'user.domain'};
1.150 albertel 168: }
1.174 albertel 169:
1.264.8.1.2.3! (raeburn 170:: } elsif (($type eq 'problem') || ($type eq 'tool')) {
1.150 albertel 171: &Apache::lonxml::debug("authed $slot_name");
1.174 albertel 172: }
1.181 albertel 173: if (!defined($user) || !defined($domain)) {
174: $user = $env{'user.name'};
175: $domain = $env{'user.domain'};
176: }
177:
178: $Apache::lonhomework::results{"resource.$id.checkedin"}=
179: $user.':'.$domain;
1.174 albertel 180:
181: if (defined($slot_name)) {
182: $Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
183: $slot_name;
1.150 albertel 184: }
185: }
186:
1.25 albertel 187: sub get_version {
1.29 albertel 188: my ($version,$previous);
1.25 albertel 189: if ($env{'form.previousversion'} &&
1.36 albertel 190: $env{'form.previousversion'} ne 'current' &&
1.89 albertel 191: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
1.29 albertel 192: $version=$env{'form.previousversion'};
193: $previous=1;
194: } else {
1.150 albertel 195: if (defined($Apache::lonhomework::results{'resource.0.version'})) {
196: $version=$Apache::lonhomework::results{'resource.0.version'};
197: } elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
198: $version=$Apache::lonhomework::history{'resource.0.version'};
199: }
1.29 albertel 200: $previous=0;
201: }
202: if (wantarray) {
203: return ($version,$previous);
1.25 albertel 204: }
1.29 albertel 205: return $version;
1.25 albertel 206: }
207:
1.8 albertel 208: sub add_previous_version_button {
1.25 albertel 209: my ($status)=@_;
1.258 raeburn 210: my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
211: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
212: return;
213: }
1.8 albertel 214: my $result;
1.89 albertel 215: if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
1.25 albertel 216: return '';
217: }
1.89 albertel 218: if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
1.29 albertel 219: $status ne 'NEEDS_CHECKIN') {
1.25 albertel 220: return '';
221: }
1.29 albertel 222: my $version=&get_version();
223: if ($env{'form.previousversion'} ne '' &&
224: $env{'form.previousversion'} eq $version) {
225: $result.="<h3>".&mt("Showing previous version [_1]",$version).
226: "</h3>\n";
227: }
228: my @to_show;
1.89 albertel 229: foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
230: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
1.29 albertel 231: push(@to_show,$test_version);
232: }
233: }
234: my $list='<option>'.
235: join("</option>\n<option>",@to_show).
236: "</option>\n";
1.36 albertel 237: $list.='<option value="current">'.&mt('Current').'</option>';
1.115 albertel 238: $result.='<form name="getprevious" method="post" action="';
1.29 albertel 239: my $uri=$env{'request.uri'};
240: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
241: $result.=$uri.'">'.
242: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
243: <option>'.&mt('Pick one').'</option>
244: '.$list.'
245: </select>')."</form>";
1.8 albertel 246: return $result;
247: }
248:
1.13 albertel 249: sub add_grading_button {
1.258 raeburn 250: my (undef,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
251: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
252: return;
253: }
1.59 albertel 254: my $cnum=$env{'course.'.$cid.'.num'};
255: my $cdom=$env{'course.'.$cid.'.domain'};
1.144 albertel 256: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
257:
1.59 albertel 258: my $size=5;
259: if (scalar(keys(%sections)) < 3) {
260: $size=scalar(keys(%sections))+2;
261: }
1.200 albertel 262: my $sec_select = "\n".'<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
1.263 bisitz 263: $sec_select .= "\t".'<option value="all" selected="selected">'.&mt('all')."</option>\n";
1.59 albertel 264: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
1.200 albertel 265: $sec_select .= "\t<option value=\"$sec\">$sec</option>\n";
1.59 albertel 266: }
1.263 bisitz 267: $sec_select .= "\t".'<option value="none">'.&mt('none')."</option>\n</select>\n";
1.258 raeburn 268:
269: my $uri=$env{'request.uri'};
270: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
271: my $result =
272: '<form name="gradesubmission" method="post" action="'.$uri.'">'.
273: "\n\t".'<input type="submit" name="gradeasubmission" value="'.
274: &mt("Get a submission to grade").'" />'.
275: "\n\t".'<input type="hidden" name="grade_target" value="webgrade" />';
1.237 albertel 276: my $see_all = &Apache::lonnet::allowed('mgq',$env{'request.course.id'});
277: my $see_sec = &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.
278: '/'.$env{'request.course.sec'});
279:
280: if ($see_all || $see_sec) {
1.34 albertel 281: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.200 albertel 282: $result.="\n\t".'<table>'."\n\t\t".'<tr>';
1.237 albertel 283: if ($see_all || (!§ion_restricted())) {
1.239 bisitz 284: $result.="\n\t\t\t".'<td rowspan="4">'.&mt('Specify a section:').' </td>'.
1.237 albertel 285: "\n\t\t\t".'<td rowspan="4">'.$sec_select."\n\t\t\t".'</td>';
286: } else {
1.239 bisitz 287: $result.="\n\t\t\t".'<td rowspan="4">'.&mt('Grading section:').' </td>'.
1.237 albertel 288: "\n\t\t\t".'<td rowspan="4">'.$env{'request.course.sec'}."\n\t\t\t".'</td>';
289: }
1.200 albertel 290: $result.="\n\t\t\t".'<td>'.'<input type="submit" name="reviewagrading" value="'.
1.106 albertel 291: &mt("Select an entry from the grading queue:").'" /> ';
1.34 albertel 292:
1.200 albertel 293: $result.= "\n\t\t\t\t".&mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).'</td>'."\n\t\t".'</tr>'."\n";
1.34 albertel 294:
295: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
1.200 albertel 296: $result.="\n\t\t".'<tr>'.
297: "\n\t\t\t".'<td>'.
298: "\n\t\t\t\t".'<input type="submit" name="reviewasubmission" value="'.
1.106 albertel 299: &mt("Select an entry from the review queue:").'" /> ';
300: $result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
1.200 albertel 301: $entries,$ready,$locks).'</td>'."\n\t\t".'</tr>'."\n";
302: $result.="\n\t\t".'<tr>'.
303: "\n\t\t\t".'<td>'.
304: "\n\t\t\t\t".'<input type="submit" name="regradeasubmission" value="'.
305: &mt("List of user's grade status").'" /> </td>'
306: ."\n\t\t".'</tr>'
307: ."\n\t".'</table>'."\n";
308: $result.="\n\t".'<p>'.
309: "\n\t\t".'<input type="submit" name="regradeaspecificsubmission" value="'.
310: &mt("Regrade specific user:").'" />';
311: $result.= "\n\t\t".'<input type="text" size="12" name="gradinguser" />';
1.105 albertel 312: $result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
313: 'gradingdomain');
314: $result.=' '.
315: &Apache::loncommon::selectstudent_link('gradesubmission',
316: 'gradinguser',
317: 'gradingdomain');
318: $result.=&Apache::loncommon::studentbrowser_javascript();
1.200 albertel 319: $result.= '</p>'."\n";
1.144 albertel 320: }
1.258 raeburn 321: $result .= '</form>'."\n";
322: return $result;
323: }
324:
325: sub add_slotlist_button {
326: my (undef,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
327: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
328: return;
329: }
330: my $symb=&Apache::lonnet::symbread();
331: my $result;
332: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'}) ||
333: &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
334: $result = '<form method="post" name="slotrequest" action="/adm/slotrequest">'.
335: '<input type="hidden" name="symb" value="'.$symb.'" />'.
336: '<input type="hidden" name="command" value="showslots" />'.
337: '<input type="submit" name="requestattempt" value="'.
338: &mt('Show Slot list').'" />'.
339: '</form>';
340: my $target_id =
341: &Apache::lonstathelpers::make_target_id({symb => $symb,
342: part => '0'});
343: if (!§ion_restricted()) {
344: $result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
345: '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
346: '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
347: '<input type="submit" name="grading" value="'.
348: &mt('Show Grading Status').'" />'.
349: '</form>';
350: }
351: }
1.13 albertel 352: return $result;
353: }
354:
1.22 albertel 355: sub add_request_another_attempt_button {
1.38 albertel 356: my ($text)=@_;
1.258 raeburn 357: my (undef,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
358: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
359: return;
360: }
1.239 bisitz 361: if (!$text) { $text=&mt('Request another attempt'); }
1.25 albertel 362: my $result;
1.36 albertel 363: my $symb=&Apache::lonnet::symbread();
1.149 albertel 364: # not a slot access based resource
365: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
366: if ($useslots =~ /^\s*no\s*$/i) {
367: return '';
368: }
369:
1.37 albertel 370: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38 albertel 371: my $action='get_reservation';
1.37 albertel 372: if ($slot_name) {
1.247 raeburn 373: $text=&mt('Change reservation');
1.38 albertel 374: $action='change_reservation';
1.37 albertel 375: my $description=&Apache::slotrequest::get_description($slot_name,
376: $slot);
1.239 bisitz 377: $result.='<p>'
378: .&mt('Will be next available:')
379: .' '.$description
380: .'</p>';
1.37 albertel 381: }
1.38 albertel 382:
383: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
1.158 www 384: $symb=&escape($symb);
1.200 albertel 385: $result.=
386: "\n\t".'<form method="post" action="/adm/slotrequest">'."\n\t\t".
387: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n\t\t".
388: '<input type="hidden" name="command" value="'.$action.'" />'."\n\t\t".
1.38 albertel 389: '<input type="submit" name="requestattempt" value="'.
1.239 bisitz 390: $text.'" />'."\n\t".
1.200 albertel 391: '</form>'."\n";
1.25 albertel 392: return $result;
1.22 albertel 393: }
394:
1.30 albertel 395: sub preserve_grade_info {
396: my $result;
397: # if we are viewing someone else preserve that info
398: if (defined $env{'form.grade_symb'}) {
399: foreach my $field ('symb','courseid','domain','username') {
400: $result .= '<input type="hidden" name="grade_'.$field.
401: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
402: }
403: }
404: return $result;
405: }
406:
1.53 albertel 407: sub style {
1.125 albertel 408: my ($target) = @_;
409: if ($target eq 'web'
410: || $target eq 'webgrade') {
1.192 albertel 411: my $style = (<<STYLE);
1.126 albertel 412: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
1.53 albertel 413: STYLE
1.192 albertel 414: if ($env{'browser.type'} eq 'explorer'
415: && $env{'browser.os'} eq 'win' ) {
416: if ($env{'browser.version'} < 7) {
417: $style .= (<<STYLE);
418: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie.css" />
419: STYLE
420: } else {
421: $style .= (<<STYLE);
422: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie7.css" />
423: STYLE
424: }
425: }
1.193 albertel 426: return $style;
1.125 albertel 427: }
428: return;
1.53 albertel 429: }
430:
1.54 albertel 431: sub show_task {
432: my ($status,$previous)=@_;
433: if (!$previous && (
434: ( $status eq 'CLOSED' ) ||
435: ( $status eq 'BANNED') ||
436: ( $status eq 'UNAVAILABLE') ||
437: ( $status eq 'NOT_IN_A_SLOT') ||
1.256 raeburn 438: ( $status eq 'NOT_YET_VIEWED') ||
1.54 albertel 439: ( $status eq 'NEEDS_CHECKIN') ||
440: ( $status eq 'WAITING_FOR_GRADE') ||
1.150 albertel 441: ( $status eq 'INVALID_ACCESS') ||
442: ( &get_version() eq ''))) {
1.54 albertel 443: return 0;
444: }
1.64 albertel 445: if ($env{'form.donescreen'}) { return 0; }
1.54 albertel 446: return 1;
447: }
448:
1.173 albertel 449: my @delay;
450: sub nest {
451: if (@delay) {
452: return $delay[-1];
453: } else {
454: return;
455: }
456: }
457:
1.208 albertel 458: sub start_delay {
459: push(@delay,1);
460: }
461: sub end_delay {
462: pop(@delay);
463: }
464:
1.173 albertel 465: sub nested_parse {
466: my ($str,$env,$args) = @_;
467: my @old_env = @Apache::scripttag::parser_env;
468: @Apache::scripttag::parser_env = @$env;
469: if (exists($args->{'set_dim_id'})) {
470: &enable_dimension_parsing($args->{'set_dim_id'});
471: }
472: push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
473: my $result = &Apache::scripttag::xmlparse($$str);
474: pop(@delay);
475: if (exists($args->{'set_dim_id'})) {
476: &disable_dimension_parsing();
477: }
478: @Apache::scripttag::parser_env = @old_env;
479: if ($args->{'delayed_dim_results'}) {
480: my $dim = &get_dim_id();
1.180 albertel 481: &Apache::lonxml::debug(" tossing out $result ");
482: &Apache::lonxml::debug(" usining out $dim 's ". $dimension{$dim}{'result'});
1.173 albertel 483: return $dimension{$dim}{'result'};
484: }
485: return $result;
486: }
487:
1.54 albertel 488: sub internal_location {
489: my ($id)=@_;
490: return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
491: }
492:
1.60 albertel 493: sub submission_time_stamp {
1.185 albertel 494: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.60 albertel 495: my $submissiontime;
1.89 albertel 496: my $version=$Apache::lonhomework::history{'resource.0.version'};
1.60 albertel 497: for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
1.183 albertel 498: if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})
499: && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
1.60 albertel 500: $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
1.182 albertel 501: last;
1.60 albertel 502: }
503: }
504: my $result;
505: if ($submissiontime) {
1.89 albertel 506: my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
1.60 albertel 507: my %slot=&Apache::lonnet::get_slot($slot_name);
508: my $diff = $slot{'endtime'} - $submissiontime;
1.71 albertel 509: my ($color,$when)=('#FF6666','after');
510: if ($diff > 0) { ($color,$when)=('#336600','before'); }
1.60 albertel 511: my $info;
1.182 albertel 512: $diff = abs($diff);
1.60 albertel 513: if ($diff%60) { $info=($diff%60).' seconds'; }
514: $diff=int($diff/60);
515: if ($diff%60) { $info=($diff%60).' minutes '.$info; }
516: $diff=int($diff/60);
517: if ($diff) { $info=$diff.' hours '.$info; }
518: $result='<p><font color="'.$color.'">'.
1.182 albertel 519: &mt('Student submitted [_1] [_2] the deadline. '.
520: '(Submission was at [_3], end of period was [_4].)',
521: $info,$when,
522: &Apache::lonlocal::locallocaltime($submissiontime),
523: &Apache::lonlocal::locallocaltime($slot{'endtime'})).
1.60 albertel 524: '</font></p>';
525: }
526: return $result;
527: }
528:
1.119 albertel 529: sub file_list {
530: my ($files,$uname,$udom) = @_;
531: if (!defined($uname) || !defined($udom)) {
1.185 albertel 532: (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
1.119 albertel 533: }
1.70 albertel 534: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.119 albertel 535:
1.120 albertel 536: my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
1.119 albertel 537: foreach my $partial_file (split(',',$files)) {
1.70 albertel 538: my $file=$file_url.$partial_file;
539: $file=~s|/+|/|g;
540: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.243 bisitz 541: $file_list.='<li><span class="LC_nobreak"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
1.161 albertel 542: &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
543: '</a></span></li>'."\n";
1.70 albertel 544: }
545: $file_list.="</ul>\n";
1.119 albertel 546: return $file_list;
547: }
548:
1.163 albertel 549: sub grade_mode {
550: if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
551: return 'regrade';
552: }
553: return 'queue_grade';
554: }
555:
1.119 albertel 556: sub webgrade_standard_info {
557: my ($version)=&get_version();
558:
559: my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
1.70 albertel 560:
1.245 bisitz 561: my %lt = &Apache::lonlocal::texthash(
562: 'done' => 'Next Item',
563: 'stop' => 'Quit Grading',
564: 'fail' => 'Fail Rest',
565: 'cancel' => 'Cancel',
566: 'submit' => 'Submit Grades',
567: );
1.163 albertel 568:
1.70 albertel 569: my $result=<<INFO;
1.120 albertel 570: <div class="LC_GRADING_maincontrols">
1.163 albertel 571: INFO
572:
1.231 albertel 573: if ($env{'request.state'} eq 'construct') {
1.163 albertel 574: $result.=<<INFO;
1.231 albertel 575: <input type="submit" name="next" value="$lt{'submit'}" />
576: INFO
577: } else {
578: if (&grade_mode() eq 'regrade' && $env{'request.state'} ne 'construct') {
579: $result.=<<INFO;
1.163 albertel 580: <input type="submit" name="cancel" value="$lt{'cancel'}" />
581: INFO
1.231 albertel 582: }
1.163 albertel 583:
1.231 albertel 584: $result.=<<INFO;
1.111 albertel 585: <input type="submit" name="next" value="$lt{'done'}" />
586: <input type="submit" name="stop" value="$lt{'stop'}" />
1.231 albertel 587: INFO
588: }
589: $result.=<<INFO;
1.143 albertel 590: <input type="button" name="fail" value="$lt{'fail'}"
591: onclick="javascript:onFailRest()" />
1.111 albertel 592: </div>
1.70 albertel 593: $file_list
594: INFO
595: return $result;
1.231 albertel 596:
1.70 albertel 597: }
598:
1.166 albertel 599: sub done_screen {
600: my ($version) = @_;
1.231 albertel 601: my $title=&Apache::lonnet::gettitle($env{'request.uri'});
1.166 albertel 602: my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
1.185 albertel 603: my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
1.255 raeburn 604: my ($msg,$files,$shown);
605: if (@files > 0) {
606: $files = '<ul>';
607: foreach my $file (@files) {
608: my $url="/uploaded/$domain/$user/portfolio$file";
609: if (! &Apache::lonnet::stat_file($url)) {
610: $file = '<span class="LC_error">'
611: .&mt('[_1]Nonexistent file:[_2]'
612: ,'<span class="LC_error"> '
613: ,'</span> <span class="LC_filename">'.$file.'</span>');
614: $msg .= "<p>".&mt('Submitted non-existent file [_1]',$file)."</p>\n";
615: } else {
616: $file = '<span class="LC_filename">'.$file.'</span>';
617: $msg .= "<p>".&mt('Submitted file [_1]',$file)."</p>\n";
618: }
619: $files .= '<li>'.$file.'</li>';
620: }
621: $files.='</ul>';
622: $shown = '<p>'.&mt('Files submitted: [_1]',$files).'</p>'
623: .'<p>'.&mt('You are now done with this Bridge Task').'</p>'
624: .'<hr />'
625: .'<p><a href="/adm/logout">'.&mt('Logout').'</a></p>'
626: .'<p><a href="/adm/roles">'.&mt('Change to a different course').'</a></p>';
627: } else {
628: $msg = &mt("Submission status: no files currently submitted, when 'Done' was indicated.");
629: $shown = '<p class="LC_error">'.
630: &mt('You did not submit any files. Please try again.').'</span>'.
631: '</p><p><a href="javascript:history.go(-1);">'.&mt('Back to Bridge Task').'</a></p><hr />';
1.166 albertel 632: }
1.239 bisitz 633: my $subject = &mt('Submission message for [_1]',$title);
1.167 albertel 634: my ($message_status,$comment_status);
635: my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
636: $setting =~ s/^\s*(\S*)\s*$/$1/;
637: $setting = lc($setting);
638: if ($setting eq 'only_student'
639: || $setting eq 'student_and_user_notes_screen') {
640: $message_status =
641: &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
642: $message_status = '<p>'.&mt('Message sent to user: [_1]',
643: $message_status).' </p>';
644: }
645: if ($setting eq 'student_and_user_notes_screen') {
646: $comment_status =
647: &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
648: $msg,$user,$domain);
649: $comment_status = '<p>'.&mt('Message sent to instructor: [_1]',
650: $comment_status).' </p>';
651: }
1.255 raeburn 652:
1.239 bisitz 653: return "<h2>$title</h2>"
1.255 raeburn 654: .$shown
655: .$message_status
656: .$comment_status;
1.166 albertel 657: }
658:
1.1 albertel 659: sub start_Task {
1.87 albertel 660: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 661:
1.4 albertel 662: my ($status,$accessmsg,$slot);
1.179 albertel 663: &Apache::structuretags::init_problem_globals('Task');
1.16 albertel 664: if ($target ne 'webgrade') {
665: &Apache::structuretags::initialize_storage();
666: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.74 albertel 667: if ($env{'request.state'} eq 'construct') {
668: &Apache::structuretags::setup_rndseed($safeeval);
669: }
1.16 albertel 670: }
671:
1.4 albertel 672: $Apache::lonhomework::parsing_a_task=1;
1.141 albertel 673:
674: my $name;
675: if ($target eq 'web' || $target eq 'webgrade') {
676: $name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
677: }
678:
1.145 albertel 679: my ($result,$form_tag_start);
680: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
681: || $target eq 'edit') {
682: ($result,$form_tag_start) =
683: &Apache::structuretags::page_start($target,$token,$tagstack,
684: $parstack,$parser,$safeeval,
1.146 albertel 685: $name,&style($target));
1.256 raeburn 686:
687: }
688: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
689: $target eq 'tex') {
690: if ($env{'form.markaccess'}) {
691: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.264.8.1.2.1 (raeburn 692:: my ($timelimit) = ($interval[0] =~ /^(\d+)/);
693:: &Apache::lonnet::set_first_access($interval[1],$timelimit);
1.256 raeburn 694: }
1.145 albertel 695: }
1.123 albertel 696:
1.74 albertel 697: if ($target eq 'web' && $env{'request.state'} ne 'construct') {
1.147 albertel 698: if ($Apache::lonhomework::queuegrade
699: || $Apache::lonhomework::modifygrades) {
1.258 raeburn 700: $result .= &add_grading_button();
1.38 albertel 701: my $symb=&Apache::lonnet::symbread();
1.235 albertel 702: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
703: || &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
1.258 raeburn 704: $result .= &add_slotlist_button();
1.40 albertel 705: }
1.13 albertel 706: }
1.8 albertel 707: }
1.231 albertel 708: if ($target =~/(web|webgrade)/ && $env{'request.state'} eq 'construct') {
1.74 albertel 709: $form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
710: }
1.163 albertel 711: if ($target eq 'web'
712: || ($target eq 'grade' && !$env{'form.webgrade'})
713: || $target eq 'answer'
714: || $target eq 'tex') {
1.29 albertel 715: my ($version,$previous)=&get_version();
1.14 albertel 716: ($status,$accessmsg,my $slot_name,$slot) =
1.81 albertel 717: &Apache::lonhomework::check_slot_access('0','Task');
1.256 raeburn 718: if ((($status eq 'CAN_ANSWER') || ($status eq 'NOT_YET_VIEWED')) && ($version eq '')) {
719: # CAN_ANSWER or NOT_YET_VIEWED mode, and no current version, unproctored access
1.174 albertel 720: # thus self-checkedin
1.246 raeburn 721: my $check = &check_in('Task',undef,undef,$slot_name);
722: if ($check =~ /^error: /) {
723: my $symb=&Apache::lonnet::symbread();
724: &Apache::lonnet::logthis("Error during self-checkin of version $version of Task (symb: $symb) using slot: $slot_name");
725: }
1.152 albertel 726: &add_to_queue('gradingqueue',{'type' => 'Task',
727: 'time' => time,
728: 'slot' => $slot_name});
1.150 albertel 729: ($version,$previous)=&get_version();
730: }
1.260 raeburn 731: if (($target eq 'web') && ($version ne '') && ($slot_name ne '')) {
732: if (ref($slot) eq 'HASH') {
733: if ($slot->{'endtime'} > time()) {
734: $result .=
735: &Apache::lonhtmlcommon::set_due_date($slot->{'endtime'});
736: }
737: }
738: }
739:
1.258 raeburn 740: my $status_id = 'LC_task_take';
741: if ($previous && $target eq 'answer') {
742: $status_id = 'LC_task_answer';
743: } elsif ($previous || $status eq 'SHOW_ANSWER') {
744: $status_id = 'LC_task_feedback';
745: }
1.218 albertel 746: $result .= '<div class="LC_task" id="'.$status_id.'">'."\n";
1.150 albertel 747:
1.9 albertel 748: push(@Apache::inputtags::status,$status);
1.14 albertel 749: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 750: my $expression='$external::datestatus="'.$status.'";';
1.89 albertel 751: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
1.1 albertel 752: &Apache::run::run($expression,$safeeval);
753: &Apache::lonxml::debug("Got $status");
1.141 albertel 754: $result.=&add_previous_version_button($status);
1.54 albertel 755: if (!&show_task($status,$previous)) {
1.87 albertel 756: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.1 albertel 757: if ( $target eq "web" ) {
1.74 albertel 758: if ($env{'request.state'} eq 'construct') {
759: $result.=$form_tag_start;
760: }
1.4 albertel 761: my $msg;
1.1 albertel 762: if ($status eq 'UNAVAILABLE') {
1.259 golterma 763: $msg.='<p class="LC_error">'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</p>';
1.3 albertel 764: } elsif ($status eq 'NOT_IN_A_SLOT') {
1.259 golterma 765: $msg.='<p class="LC_warning">'.&mt('You are not currently signed up to work at this time and/or place.').'</p>';
1.247 raeburn 766: $msg.=&add_request_another_attempt_button("Sign up for time to work");
1.4 albertel 767: } elsif ($status eq 'NEEDS_CHECKIN') {
1.259 golterma 768: $msg.='<p class="LC_warning">'.&mt('You need the Proctor to validate you.').
769: '</p>'.&proctor_validation_screen($slot);
1.22 albertel 770: } elsif ($status eq 'WAITING_FOR_GRADE') {
1.259 golterma 771: $msg.='<p class="LC_info">'.&mt('Your submission is in the grading queue.').'</p>';
1.64 albertel 772: } elsif ($env{'form.donescreen'}) {
1.167 albertel 773: $result .= &done_screen($version);
1.256 raeburn 774: } elsif ($status eq 'NOT_YET_VIEWED') {
775: my $symb=&Apache::lonnet::symbread();
776: $msg.=&Apache::structuretags::firstaccess_msg($accessmsg,$symb);
777: } else {
1.259 golterma 778: $msg.='<p class="LC_warning">'.&mt('Not open to be viewed').'</p>';
1.1 albertel 779: }
780: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
781: $msg.='The problem '.$accessmsg;
782: }
783: $result.=$msg.'<br />';
784: } elsif ($target eq 'tex') {
1.248 foxr 785: $result.='\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
1.1 albertel 786: if ($status eq 'UNAVAILABLE') {
787: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
788: } else {
789: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
790: }
1.22 albertel 791: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 792: if ($status eq 'NEEDS_CHECKIN') {
1.83 albertel 793: if(&proctor_check_auth($slot_name,$slot,'Task')
794: && defined($Apache::inputtags::slot_name)) {
1.148 albertel 795: my $result=
796: &add_to_queue('gradingqueue',
1.152 albertel 797: {'type' => 'Task',
1.148 albertel 798: 'time' => time,
799: 'slot' =>
800: $Apache::inputtags::slot_name});
1.77 albertel 801: &Apache::lonxml::debug("add_to_queue said $result");
802: }
1.4 albertel 803: }
1.1 albertel 804: }
805: } elsif ($target eq 'web') {
1.141 albertel 806:
1.57 albertel 807: $result.=&preserve_grade_info();
1.194 albertel 808: $result.=&internal_location();
1.200 albertel 809: $result.=$form_tag_start."\t".
1.36 albertel 810: '<input type="hidden" name="submitted" value="yes" />';
1.54 albertel 811: &Apache::lonxml::startredirection();
1.1 albertel 812: }
1.21 albertel 813: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
814: $target eq 'webgrade') {
1.32 albertel 815: my $webgrade='yes';
1.21 albertel 816: if ($target eq 'webgrade') {
1.218 albertel 817: $result .= '<div class="LC_task">'."\n";
1.141 albertel 818: $result.= "\n".'<div class="LC_GRADING_task">'."\n".
1.124 albertel 819: '<script type="text/javascript"
1.126 albertel 820: src="/res/adm/includes/task_grading.js"></script>';
1.49 albertel 821: #$result.='<br />Review'.&show_queue('reviewqueue');
822: #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 823: }
1.194 albertel 824:
1.105 albertel 825: my ($todo,$status_code,$msg)=&get_key_todo($target);
1.33 albertel 826:
827: if ($todo) {
828: &setup_env_for_other_user($todo,$safeeval);
829: my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.231 albertel 830: if ($env{'request.state'} eq 'construct') {
831: $symb = $env{'request.uri'};
832: }
833: $result.="\n".'<p>'.
834: &mt('Grading [_1] for [_2] at [_3]',
835: &Apache::lonnet::gettitle($symb),$uname,$udom).'</p>';
1.33 albertel 836: $form_tag_start.=
837: '<input type="hidden" name="gradingkey" value="'.
1.158 www 838: &escape($todo).'" />';
1.33 albertel 839: $Apache::bridgetask::queue_key=$todo;
840: &Apache::structuretags::initialize_storage();
841: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.110 albertel 842: if ($target eq 'webgrade' && $status_code eq 'selected') {
843: $form_tag_start.=
844: '<input type="hidden" name="queuemode" value="selected" />';
1.33 albertel 845: }
1.15 albertel 846: } else {
1.33 albertel 847: if ($target eq 'webgrade') {
848: $result.="\n";
1.81 albertel 849: my $back='<p><a href="/adm/flip?postdata=return:">'.
850: &mt('Return to resource').'</a></p>';
1.33 albertel 851: if ($status_code eq 'stop') {
1.81 albertel 852: $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
1.163 albertel 853: } elsif ($status_code eq 'cancel') {
854: $result.='<b>'.&mt("Cancelled grading.").'</b>'.$back;
1.254 raeburn 855: } elsif ($status_code eq 'terminated') {
856: $result.= '<b>'.&mt('Terminated grading').'</b><br />'.
857: '<span class="LC_error">'.
858: &mt('Grading for [_1] has not been saved because of a grading key mismatch.',
859: '<tt>'.$env{'form.terminated'}.'</tt>').'</span><br />'.$back;
1.164 albertel 860: } elsif ($status_code eq 'never_versioned') {
861: $result.='<b>'.
862: &mt("Requested user has never accessed the task.").
863: '</b>'.$back;
1.165 albertel 864: } elsif ($status_code =~ /still_open:(.*)/) {
865: my $date = &Apache::lonlocal::locallocaltime($1);
866: $result.='<b>'.
867: &mt("Task is still open, will close at [_1].",$date).
868: '</b>'.$back;
1.33 albertel 869: } elsif ($status_code eq 'lock_failed') {
1.105 albertel 870: $result.='<b>'.&mt("Failed to lock the requested record.")
1.81 albertel 871: .'</b>'.$back;
1.33 albertel 872: } elsif ($status_code eq 'unlock') {
1.81 albertel 873: $result.='<b>'.&mt("Unlocked the requested record.")
874: .'</b>'.$back;
1.33 albertel 875: $result.=&show_queue($env{'form.queue'},1);
876: } elsif ($status_code eq 'show_list') {
877: $result.=&show_queue($env{'form.queue'},1);
1.49 albertel 878: } elsif ($status_code eq 'select_user') {
879: $result.=&select_user();
1.95 albertel 880: } elsif ($status_code eq 'unable') {
881: $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
1.105 albertel 882: } elsif ($status_code eq 'not_allowed') {
883: $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
1.33 albertel 884: } else {
1.81 albertel 885: $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
1.32 albertel 886: }
1.21 albertel 887: }
1.33 albertel 888: $webgrade='no';
1.163 albertel 889: }
890: if (!$todo || $env{'form.cancel'}) {
1.87 albertel 891: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.32 albertel 892: }
893: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61 albertel 894: if ($webgrade eq 'yes') {
895: $result.=&submission_time_stamp();
896: }
1.32 albertel 897: $result.=$form_tag_start;
898: $result.='<input type="hidden" name="webgrade" value="'.
899: $webgrade.'" />';
900: $result.='<input type="hidden" name="queue" value="'.
901: $env{'form.queue'}.'" />';
1.52 albertel 902: if ($env{'form.regrade'}) {
903: $result.='<input type="hidden" name="regrade" value="'.
904: $env{'form.regrade'}.'" />';
905: }
1.237 albertel 906: if ($env{'form.chosensections'} || §ion_restricted()) {
907: my @chosen_sections = &get_allowed_sections();
1.62 albertel 908: foreach my $sec (@chosen_sections) {
909: $result.='<input type="hidden" name="chosensections"
910: value="'.$sec.'" />';
911: }
912: }
1.70 albertel 913: if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
1.231 albertel 914: } elsif ($target eq 'webgrade'
915: && $env{'request.state'} eq 'construct') {
916: $result.=$form_tag_start;
917: $result.='<input type="hidden" name="webgrade" value="'.
918: $webgrade.'" />';
919: $result.=&webgrade_standard_info();
1.15 albertel 920: }
1.110 albertel 921: if ($target eq 'webgrade') {
1.120 albertel 922: $result.="\n".'<div id="LC_GRADING_criterialist">';
1.194 albertel 923: &Apache::lonxml::startredirection();
1.208 albertel 924: &start_delay();
925: $dimension{$top}{'result'}=$result;
926: undef($result);
1.110 albertel 927: }
1.74 albertel 928: } elsif ($target eq 'edit') {
1.141 albertel 929: $result.=$form_tag_start.
1.74 albertel 930: &Apache::structuretags::problem_edit_header();
931: $Apache::lonxml::warnings_error_header=
932: &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 />";
1.225 albertel 933: $result.= &Apache::edit::text_arg('Required number of passed optional elements to pass the Task:','OptionalRequired',$token,10)." <br />\n";
934: $result.= &Apache::edit::insertlist($target,$token);
935: } elsif ($target eq 'modified') {
936: my $constructtag=
937: &Apache::edit::get_new_args($token,$parstack,$safeeval,
938: 'OptionalRequired');
939: if ($constructtag) {
940: $result = &Apache::edit::rebuild_tag($token);
941: }
1.1 albertel 942: } else {
943: # page_start returned a starting result, delete it if we don't need it
944: $result = '';
945: }
946: return $result;
947: }
948:
1.165 albertel 949: sub get_task_end_time {
950: my ($queue_entry,$symb,$udom,$uname) = @_;
951:
952: my $end_time;
953: if (my $slot = &slotted_access($queue_entry)) {
954: my %slot_data=&Apache::lonnet::get_slot($slot);
955: $end_time = $slot_data{'endtime'};
956: } else {
957: $end_time = &Apache::lonhomework::due_date('0',$symb,
958: $udom,$uname);
959: }
960: return $end_time;
961: }
962:
1.32 albertel 963: sub get_key_todo {
964: my ($target)=@_;
965: my $todo;
1.33 albertel 966:
1.231 albertel 967: if ($env{'request.state'} eq 'construct') {
968: my ($symb,$cid,$udom,$uname) = &Apache::lonnet::whichuser();
969: my $gradingkey=&encode_queue_key($symb,$udom,$uname);
970: return ($gradingkey);
971: }
972:
1.33 albertel 973: if (defined($env{'form.reviewasubmission'})) {
1.54 albertel 974: &Apache::lonxml::debug("review a submission....");
1.33 albertel 975: $env{'form.queue'}='reviewqueue';
976: return (undef,'show_list');
977: }
978:
979: if (defined($env{'form.reviewagrading'})) {
980: &Apache::lonxml::debug("review a grading....");
981: $env{'form.queue'}='gradingqueue';
982: return (undef,'show_list');
983: }
984:
1.49 albertel 985: if (defined($env{'form.regradeasubmission'})) {
986: &Apache::lonxml::debug("regrade a grading....");
987: $env{'form.queue'}='none';
988: return (undef,'select_user');
989: }
990:
1.105 albertel 991:
1.138 albertel 992: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.105 albertel 993:
994: #need to try both queues..
995: if (defined($env{'form.regradeaspecificsubmission'}) &&
996: defined($env{'form.gradinguser'}) &&
997: defined($env{'form.gradingdomain'}) ) {
1.185 albertel 998: my ($symb,$cid)=&Apache::lonnet::whichuser();
1.105 albertel 999: my $cnum = $env{'course.'.$cid.'.num'};
1000: my $cdom = $env{'course.'.$cid.'.domain'};
1.224 albertel 1001: my $uname = &LONCAPA::clean_username($env{'form.gradinguser'});
1002: my $udom = &LONCAPA::clean_domain($env{'form.gradingdomain'});
1.237 albertel 1003:
1004: if (§ion_restricted()) {
1005: my $classlist=&get_limited_classlist();
1006: if (!&allow_grade_user($classlist->{$uname.':'.$udom})) {
1007: return (undef,'not_allowed',
1.261 raeburn 1008: &mt("Requested student ([_1]) is in a section you aren't allowed to grade.",$uname.':'.$udom));
1.237 albertel 1009: }
1010: }
1.105 albertel 1011: my $gradingkey=&encode_queue_key($symb,$udom,$uname);
1012:
1013: my $queue;
1014:
1015: if (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
1016: $env{'form.queue'} = $queue = 'gradingqueue';
1017: } elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
1018: $env{'form.queue'} = $queue = 'reviewqueue';
1019: }
1020:
1021: if (!$queue) {
1022: $env{'form.queue'} = $queue = 'none';
1023: #not queued so doing either a re or pre grade
1.164 albertel 1024: my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
1025: if ($status{'resource.0.version'} < 1) {
1026: return (undef,'never_versioned');
1027: }
1.105 albertel 1028: return ($gradingkey);
1029: }
1030:
1.165 albertel 1031: if ($queue) {
1032: my $queue_entry = &get_queue_data($queue,$udom,$uname);
1033:
1034: my $end_time = &get_task_end_time($queue_entry,$symb,
1035: $udom,$uname);
1036: if ($end_time > time) {
1037: return (undef,"still_open:$end_time");
1038: }
1039: }
1040:
1.105 albertel 1041: my $who=&queue_key_locked($queue,$gradingkey);
1042: if ($who eq $me) {
1043: #already have the lock
1.158 www 1044: $env{'form.gradingkey'}=&escape($gradingkey);
1.163 albertel 1045: &Apache::lonxml::debug("already locked");
1.105 albertel 1046: return ($gradingkey);
1047: }
1048:
1049: if (!defined($who)) {
1050: if (&lock_key($queue,$gradingkey)) {
1.163 albertel 1051: &Apache::lonxml::debug("newly locked");
1.105 albertel 1052: return ($gradingkey);
1053: } else {
1054: return (undef,'lock_failed');
1055: }
1056: }
1057:
1058: #otherwise (defined($who) && $who ne $me) some else has it...
1059: return (undef,'not_allowed',
1060: &mt('Another user ([_1]) currently has the record for [_2] locked.',
1.138 albertel 1061: $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
1.105 albertel 1062: }
1063:
1064:
1.32 albertel 1065: my $queue=$env{'form.queue'};
1.33 albertel 1066:
1.32 albertel 1067: if (!defined($queue)) {
1068: $env{'form.queue'}=$queue='gradingqueue';
1069: }
1.33 albertel 1070:
1.158 www 1071: my $gradingkey=&unescape($env{'form.gradingkey'});
1.33 albertel 1072:
1.49 albertel 1073: if ($env{'form.queue'} eq 'none') {
1074: if (defined($env{'form.gradingkey'})) {
1075: if ($target eq 'webgrade') {
1076: if ($env{'form.stop'}) {
1077: return (undef,'stop');
1.163 albertel 1078: } elsif ($env{'form.cancel'}) {
1079: return (undef,'cancel');
1.254 raeburn 1080: } elsif ($env{'form.terminated'}) {
1081: return (undef, 'terminated');
1.49 albertel 1082: } elsif ($env{'form.next'}) {
1.59 albertel 1083: return (undef,'select_user');
1.49 albertel 1084: }
1085: }
1086: return ($gradingkey,'selected');
1087: } else {
1.59 albertel 1088: return (undef,'select_user');
1.49 albertel 1089: }
1090: }
1.32 albertel 1091: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 albertel 1092: && !defined($env{'form.gradingaction'})
1093: && $env{'form.queuemode'} eq 'selected') {
1094:
1095: my $who=&queue_key_locked($queue,$gradingkey);
1096: if ($who eq $me) {
1097: &Apache::lonxml::debug("Found a key was given to me");
1098: return ($gradingkey,'selected');
1099: } else {
1100: return (undef,'show_list');
1101: }
1102:
1103: }
1104:
1105: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
1106: if ($env{'form.gradingaction'} eq 'resume') {
1107: delete($env{'form.gradingaction'});
1108: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 1109: return ($gradingkey);
1.33 albertel 1110: } elsif ($env{'form.gradingaction'} eq 'unlock') {
1111: &Apache::lonxml::debug("Unlocking a key ".
1112: &check_queue_unlock($queue,$gradingkey,1));
1113: return (undef,'unlock');
1114: } elsif ($env{'form.gradingaction'} eq 'select') {
1115: &Apache::lonxml::debug("Locking a key");
1116: if (&lock_key($queue,$gradingkey)) {
1117: &Apache::lonxml::debug("Success $queue");
1118: return ($gradingkey);
1119: }
1120: &Apache::lonxml::debug("Failed $queue");
1121: return (undef,'lock_failed');
1.32 albertel 1122: }
1123: }
1.33 albertel 1124:
1125: if ($env{'form.queuemode'} ne 'selected') {
1126: # don't get something new from the queue if they hit the stop button
1.254 raeburn 1127: if (!(($env{'form.cancel'} || $env{'form.stop'} || $env{'form.terminated'})
1.163 albertel 1128: && $target eq 'webgrade')
1.33 albertel 1129: && !$env{'form.gradingaction'}) {
1130: &Apache::lonxml::debug("Getting anew $queue");
1131: return (&get_from_queue($queue));
1132: } else {
1.254 raeburn 1133: if ($env{'form.terminated'}) {
1134: return (undef,'terminated');
1135: } else {
1136: return (undef,'stop');
1137: }
1.33 albertel 1138: }
1.32 albertel 1139: }
1.33 albertel 1140: return (undef,undef)
1.32 albertel 1141: }
1.94 albertel 1142:
1143: sub minimize_storage {
1144: foreach my $key (keys(%Apache::lonhomework::results)) {
1145: if ($key =~ /regrader$/) { next; }
1146: if ($Apache::lonhomework::results{$key} eq
1147: $Apache::lonhomework::history{$key}) {
1148: delete($Apache::lonhomework::results{$key});
1149: }
1150: }
1151: }
1152:
1.1 albertel 1153: sub end_Task {
1154: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1155: my $result='';
1156: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 1157: my ($version,$previous)=&get_version();
1.1 albertel 1158: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 1159: $target eq 'tex') {
1.69 albertel 1160: if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1 albertel 1161: if ($target eq 'web') {
1.54 albertel 1162: if (&show_task($status,$previous)) {
1163: $result.=&Apache::lonxml::endredirection();
1164: }
1.64 albertel 1165: if ($status eq 'CAN_ANSWER' && !$previous &&
1166: !$env{'form.donescreen'}) {
1.252 raeburn 1167: my ($portheader,$porttext);
1168: if ($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"}) {
1169: $portheader = &mt('Submit Additional Portfolio Files for Grading');
1170: $porttext = &mt('Indicate which additional files from your portfolio are to be evaluated in grading this task.');
1171: } else {
1172: $portheader = &mt('Submit Portfolio Files for Grading');
1173: $porttext = &mt('Indicate the files from your portfolio to be evaluated in grading this task.');
1174: }
1.257 raeburn 1175: $result.="\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.28 albertel 1176: &Apache::inputtags::file_selector("$version.0",
1177: "bridgetask","*",
1.46 albertel 1178: 'portfolioonly',
1.252 raeburn 1179: '<h3>'.$portheader.'</h3><br />'.
1180: $porttext.'<br />').
1.257 raeburn 1181: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.77 albertel 1182: }
1.78 albertel 1183: if (!$previous && $status ne 'SHOW_ANSWER' &&
1184: &show_task($status,$previous)) {
1.232 albertel 1185: $result.=&Apache::inputtags::gradestatus('0',$target,1);
1.199 albertel 1186: }
1187:
1188: $result.='</form>';
1189:
1190: if (!$previous && $status ne 'SHOW_ANSWER' &&
1191: &show_task($status,$previous)) {
1.116 albertel 1192: my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.241 raeburn 1193: my $donetext = &mt('Done');
1.64 albertel 1194: $result.=<<DONEBUTTON;
1.115 albertel 1195: <form name="done" method="post" action="$action">
1.64 albertel 1196: <input type="hidden" name="donescreen" value="1" />
1.241 raeburn 1197: <input type="submit" value="$donetext" />
1.64 albertel 1198: </form>
1199: DONEBUTTON
1.77 albertel 1200: }
1.56 albertel 1201: if (&show_task($status,$previous) &&
1.89 albertel 1202: $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
1203: my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.231 albertel 1204: my $title=&Apache::lonnet::gettitle($env{'request.uri'});
1.149 albertel 1205: my $start_time;
1206:
1.80 albertel 1207: my $slot_name=
1.89 albertel 1208: $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149 albertel 1209: if ($slot_name) {
1210: my %slot=&Apache::lonnet::get_slot($slot_name);
1211:
1212: $start_time=$slot{'starttime'}
1213: } else {
1214: $start_time=
1215: &Apache::lonnet::EXT('resource.0.opendate');
1216: }
1217: $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54 albertel 1218:
1.200 albertel 1219: my $status =
1.213 albertel 1220: "\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'>\n\t";
1.54 albertel 1221:
1.213 albertel 1222: my $dim = $top;
1223: my %counts = &get_counts($dim,undef,$parstack,
1224: $safeeval);
1225: my $question_status ="\n\t<p>".
1226: &question_status_message(\%counts,-1).
1227: "</p>\n";
1228:
1.54 albertel 1229: if ($bt_status eq 'pass') {
1.239 bisitz 1230: $status.='<h2>'
1231: .&mt('You passed the [_1] given on [_2].',$title,$start_time)
1232: .'</h2>';
1.213 albertel 1233: $status.=$question_status;
1.54 albertel 1234: }
1235: if ($bt_status eq 'fail') {
1.239 bisitz 1236: $status.='<h2>'
1237: .&mt('You did not pass the [_1] given on [_2].',$title,$start_time)
1238: .'</h2>';
1.213 albertel 1239: $status.=$question_status;
1.54 albertel 1240: if (!$previous) {
1241: $status.=&add_request_another_attempt_button();
1242: }
1243: }
1.213 albertel 1244:
1.200 albertel 1245: $status.="\n".'</div>'."\n";
1.194 albertel 1246:
1247: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1248: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1249: if ($type eq 'dimension') {
1250: $result.=$dimension{$id}{'result'};
1251: next;
1252: }
1253: my $criteria =
1254: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
1255: [@_]);
1256: $status .= &layout_web_Criteria($dim,$id,$criteria);
1257: }
1.54 albertel 1258:
1259: my $internal_location=&internal_location();
1260: $result=~s/\Q$internal_location\E/$status/;
1261: }
1.142 albertel 1262: $result.="\n</div>\n".
1263: &Apache::loncommon::end_page({'discussion' => 1});
1.258 raeburn 1264: } elsif ($target eq 'answer') {
1265: $result.="\n</div>\n";
1266: }
1.1 albertel 1267: }
1.181 albertel 1268:
1269: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
1270: my %queue_data = ('type' => 'Task',
1271: 'time' => time,);
1272: if (defined($Apache::inputtags::slot_name)) {
1273: $queue_data{'slot'} = $Apache::inputtags::slot_name;
1274: } elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) {
1275: $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1276: }
1.258 raeburn 1277:
1.181 albertel 1278:
1.215 albertel 1279: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous
1280: && $status eq 'CAN_ANSWER') {
1.12 albertel 1281: my $award='SUBMITTED';
1.252 raeburn 1282: my $uploadedflag=0;
1283: my $totalsize=0;
1284: my @deletions = &Apache::loncommon::get_env_multiple('form.HWFILE'.$version.'_0_bridgetask_delete');
1.28 albertel 1285: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.252 raeburn 1286: \$award,\$uploadedflag,\$totalsize,\@deletions);
1.14 albertel 1287: if ($award eq 'SUBMITTED' &&
1.28 albertel 1288: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
1289: $Apache::lonhomework::results{"resource.0.tries"}=
1290: $Apache::lonhomework::results{"resource.$version.0.tries"}=
1291: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
1292:
1293: $Apache::lonhomework::results{"resource.0.award"}=
1294: $Apache::lonhomework::results{"resource.$version.0.award"}=
1295: $award;
1.51 albertel 1296: $Apache::lonhomework::results{"resource.0.submission"}=
1297: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64 albertel 1298: } else {
1.252 raeburn 1299: unless($uploadedflag) {
1300: delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1301: }
1.77 albertel 1302: $award = '';
1.10 albertel 1303: }
1.4 albertel 1304: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1305: &Apache::structuretags::finalize_storage();
1.148 albertel 1306: if ($award eq 'SUBMITTED') {
1.181 albertel 1307: &add_to_queue('gradingqueue',\%queue_data);
1.14 albertel 1308: }
1.1 albertel 1309: }
1.163 albertel 1310: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1311: && exists($env{'form.cancel'})) {
1312: &check_queue_unlock($env{'form.queue'});
1313: &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
1314: } elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1315: && !exists($env{'form.cancel'})) {
1.20 albertel 1316: my $optional_required=
1317: &Apache::lonxml::get_param('OptionalRequired',$parstack,
1318: $safeeval);
1319: my $optional_passed=0;
1320: my $mandatory_failed=0;
1321: my $ungraded=0;
1322: my $review=0;
1.21 albertel 1323: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.194 albertel 1324: my $dim = $top;
1325: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1326: my $link=&link($id);
1327:
1328: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1329:
1330: if ($type eq 'criteria') {
1331: # dimensional 'criteria' don't get assigned grades
1332: $Apache::lonhomework::results{"resource.$version.0.$id.status"}=$env{'form.HWVAL_'.$link};
1333: $Apache::lonhomework::results{"resource.$version.0.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1334: }
1.20 albertel 1335: my $status=
1.194 albertel 1336: $Apache::lonhomework::results{"resource.$version.0.$id.status"};
1337: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1338:
1.20 albertel 1339: if ($status eq 'pass') {
1340: if (!$mandatory) { $optional_passed++; }
1341: } elsif ($status eq 'fail') {
1342: if ($mandatory) { $mandatory_failed++; }
1.194 albertel 1343: } elsif ($status eq 'review') {
1344: $review++;
1.20 albertel 1345: } elsif ($status eq 'ungraded') {
1346: $ungraded++;
1.49 albertel 1347: } else {
1348: $ungraded++;
1349: }
1.20 albertel 1350: }
1351: if ($optional_passed < $optional_required) {
1352: $mandatory_failed++;
1353: }
1.194 albertel 1354: &Apache::lonxml::debug(" task results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89 albertel 1355: $Apache::lonhomework::results{'resource.0.regrader'}=
1.138 albertel 1356: $env{'user.name'}.':'.$env{'user.domain'};
1.20 albertel 1357: if ($review) {
1.89 albertel 1358: $Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.20 albertel 1359: } elsif ($ungraded) {
1.89 albertel 1360: $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.20 albertel 1361: } elsif ($mandatory_failed) {
1.89 albertel 1362: $Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25 albertel 1363: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
1364: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
1365: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.185 albertel 1366: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1367:
1368: if ($env{'form.regrade'} ne 'yes') {
1369: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1370: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1371: &Apache::grades::version_portfiles(
1372: \%Apache::lonhomework::results,
1373: ["$version.0.bridgetask"],$courseid,
1374: $symb,$udom,$uname,
1375: ["$version.0.bridgetask"]);
1376: }
1.20 albertel 1377: } else {
1.89 albertel 1378: $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25 albertel 1379: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
1380: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
1381: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.185 albertel 1382: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1383: if ($env{'form.regrade'} ne 'yes') {
1384: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1385: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1386: &Apache::grades::version_portfiles(
1387: \%Apache::lonhomework::results,
1388: ["$version.0.bridgetask"],$courseid,
1389: $symb,$udom,$uname,
1390: ["$version.0.bridgetask"]);
1391: }
1.20 albertel 1392: }
1.89 albertel 1393: $Apache::lonhomework::results{"resource.0.status"}=
1394: $Apache::lonhomework::results{"resource.$version.0.status"};
1.28 albertel 1395: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 1396: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 1397: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 1398: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 1399: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 1400: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 1401: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 1402: }
1.94 albertel 1403: &minimize_storage();
1.256 raeburn 1404: my ($canstore,$domain,$name,$symb,$courseid);
1405: ($symb,$courseid,$domain,$name) = &Apache::lonnet::whichuser();
1406:
1.250 raeburn 1407: if ($env{'form.gradingkey'}) {
1408: my $todo=&unescape($env{'form.gradingkey'});
1409: my ($keysymb,$uname,$udom)=&decode_queue_key($todo);
1410: if ($symb eq $keysymb) {
1411: if (($domain eq $udom) && ($name eq $uname)) {
1412: $canstore = 1;
1413: }
1414: }
1415: }
1416: if ($canstore) {
1417: &Apache::structuretags::finalize_storage();
1.256 raeburn 1418: my @interval = &Apache::lonnet::EXT("resource.0.interval");
1.264.8.1.2.1 (raeburn 1419:: if ($interval[0] =~ /^\d+/ && $interval[1] eq 'resource') {
1.256 raeburn 1420: my $key=$courseid."\0".$symb;
1421: my %times=&Apache::lonnet::get('firstaccesstimes',
1422: [$key],$domain,$name);
1423: if ($times{$key}) {
1424: my $delresult.=&Apache::lonnet::del('firstaccesstimes',
1425: [$key],$domain,$name);
1426: }
1427: }
1.253 raeburn 1428: # data stored, now handle queue
1429: if ($review) {
1430: if ($env{'form.queue'} eq 'reviewqueue') {
1431: &check_queue_unlock($env{'form.queue'});
1432: &Apache::lonxml::debug(" still needs review not changing status.");
1433: } else {
1434: if ($env{'form.queue'} ne 'none') {
1435: &move_between_queues($env{'form.queue'},'reviewqueue');
1436: } else {
1437: &add_to_queue('reviewqueue',\%queue_data);
1438: }
1439: }
1440: } elsif ($ungraded) {
1441: if ($env{'form.queue'} eq 'reviewqueue') {
1442: &Apache::lonxml::debug("moving back.");
1443: &move_between_queues($env{'form.queue'},
1444: 'gradingqueue');
1445: } elsif ($env{'form.queue'} eq 'none' ) {
1446: &add_to_queue('gradingqueue',\%queue_data);
1447: } else {
1448: &check_queue_unlock($env{'form.queue'});
1449: }
1450: } elsif ($mandatory_failed) {
1451: &remove_from_queue($env{'form.queue'});
1452: } else {
1453: &remove_from_queue($env{'form.queue'});
1454: }
1.250 raeburn 1455: } else {
1.253 raeburn 1456: &check_queue_unlock($env{'form.queue'});
1.254 raeburn 1457: $env{'form.terminated'} = $name.':'.$domain;
1.250 raeburn 1458: }
1.253 raeburn 1459: }
1.184 albertel 1460: if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
1.240 bisitz 1461: # instance generation occurred and hasn't yet been stored
1.184 albertel 1462: &Apache::structuretags::finalize_storage();
1463: }
1.15 albertel 1464: } elsif ($target eq 'webgrade') {
1.208 albertel 1465: if (&nest()) {
1466: &Apache::lonxml::endredirection();
1467: &end_delay();
1468: $result.=$dimension{$top}{'result'};
1469: } else {
1470: $result.=&Apache::lonxml::endredirection();
1471: }
1.194 albertel 1472: my $dim = $top;
1473: foreach my $id (@{$dimension{$dim}{'criterias'}} ) {
1474: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1475: if ($type eq 'dimension') {
1476: # dimensional 'criteria' don't get assigned grades
1477: next;
1478: } else {
1479: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
1480: [@_]);
1481: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
1482: my $internal_location=&internal_location($id);
1.209 albertel 1483: if ($result =~ m/\Q$internal_location\E/) {
1484: $result=~s/\Q$internal_location\E/$criteria/;
1485: } else {
1486: $result.=$criteria;
1487: }
1488:
1.194 albertel 1489: }
1490: }
1491: $result.="</div>";
1.20 albertel 1492: #$result.='<input type="submit" name="next" value="'.
1493: # &mt('Save & Next').'" /> ';
1494: #$result.='<input type="submit" name="end" value="'.
1495: # &mt('Save & Stop Grading').'" /> ';
1496: #$result.='<input type="submit" name="throwaway" value="'.
1497: # &mt('Throw Away & Stop Grading').'" /> ';
1498: #$result.='<input type="submit" name="save" value="'.
1499: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124 albertel 1500: $result.='</form>'."\n</div>\n</div>\n".
1.140 albertel 1501: &Apache::loncommon::end_page();
1.1 albertel 1502: } elsif ($target eq 'meta') {
1.70 albertel 1503: $result.=&Apache::response::meta_package_write('Task');
1.77 albertel 1504: $result.=&Apache::response::meta_stores_write('solved','string',
1505: 'Problem Status');
1506: $result.=&Apache::response::meta_stores_write('tries','int_zeropos',
1507: 'Number of Attempts');
1508: $result.=&Apache::response::meta_stores_write('awarded','float',
1509: 'Partial Credit Factor');
1510: $result.=&Apache::response::meta_stores_write('status','string',
1511: 'Bridge Task Status');
1.182 albertel 1512: } elsif ($target eq 'edit') {
1.227 albertel 1513: $result.= &Apache::structuretags::problem_edit_footer();
1.1 albertel 1514: }
1.179 albertel 1515: &Apache::structuretags::reset_problem_globals('Task');
1.4 albertel 1516: undef($Apache::lonhomework::parsing_a_task);
1.250 raeburn 1517: if ( ($target eq 'grade' && $env{'form.webgrade'}) ||
1518: $target eq 'webgrade') {
1519: delete($env{'form.grade_symb'});
1520: delete($env{'form.grade_domain'});
1521: delete($env{'form.grade_username'});
1522: delete($env{'form.grade_courseid'});
1523: }
1.1 albertel 1524: return $result;
1525: }
1526:
1.31 albertel 1527: sub move_between_queues {
1528: my ($src_queue,$dest_queue)=@_;
1.49 albertel 1529: my $cur_data;
1530: if ($src_queue ne 'none') {
1531: $cur_data=&get_queue_data($src_queue);
1532: if (!$cur_data) { return 'not_exist'; }
1533: } else {
1534: $cur_data = ['none'];
1535: }
1.148 albertel 1536: my $result=&add_to_queue($dest_queue,$cur_data);
1.31 albertel 1537: if ($result ne 'ok') {
1538: return $result;
1539: }
1540: &check_queue_unlock($src_queue);
1541: return &remove_from_queue($src_queue);
1.21 albertel 1542: }
1543:
1544: sub check_queue_unlock {
1.32 albertel 1545: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 1546: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1547: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.32 albertel 1548: if (!defined($key)) {
1.138 albertel 1549: $key="$symb\0queue\0$uname:$udom";
1.32 albertel 1550: }
1.30 albertel 1551: my $cnum=$env{'course.'.$cid.'.num'};
1552: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1553: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30 albertel 1554: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1555: if ($who eq $me) {
1.163 albertel 1556: &Apache::lonxml::debug("unlocking my own $who");
1.32 albertel 1557: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1558: } elsif ($allow_not_me) {
1.33 albertel 1559: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 1560: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 1561: }
1.32 albertel 1562: return 'not_owner';
1.21 albertel 1563: }
1564:
1.88 albertel 1565: sub in_queue {
1566: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1567: if ($queue eq 'none') { return 0; }
1568: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1569: || !defined($udom) || !defined($uname)) {
1.185 albertel 1570: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.88 albertel 1571: $cnum=$env{'course.'.$cid.'.num'};
1572: $cdom=$env{'course.'.$cid.'.domain'};
1573: }
1574:
1575: my $key=&encode_queue_key($symb,$udom,$uname);
1576: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1577:
1578: if (defined($results{$key})) {
1579: return 1;
1580: }
1581: return 0;
1582: }
1583:
1.21 albertel 1584: sub remove_from_queue {
1.86 albertel 1585: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49 albertel 1586: if ($queue eq 'none') { return 'ok'; }
1.86 albertel 1587: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1588: || !defined($udom) || !defined($uname)) {
1.185 albertel 1589: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.86 albertel 1590: $cnum=$env{'course.'.$cid.'.num'};
1591: $cdom=$env{'course.'.$cid.'.domain'};
1592: }
1.88 albertel 1593: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1594: return 'ok';
1595: }
1.86 albertel 1596: my $key=&encode_queue_key($symb,$udom,$uname);
1.27 albertel 1597: my @keys=($key,"$key\0locked");
1.31 albertel 1598: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 1599: }
1600:
1.16 albertel 1601: sub setup_env_for_other_user {
1602: my ($queue_key,$safeeval)=@_;
1603: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 1604: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 1605: $env{'form.grade_symb'}=$symb;
1606: $env{'form.grade_domain'}=$udom;
1607: $env{'form.grade_username'}=$uname;
1608: $env{'form.grade_courseid'}=$env{'request.course.id'};
1609: &Apache::lonxml::initialize_rndseed($safeeval);
1610: }
1611:
1.31 albertel 1612: sub get_queue_data {
1.165 albertel 1613: my ($queue,$udom,$uname)=@_;
1.185 albertel 1614: my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1.165 albertel 1615: if (!$uname || !$udom) {
1616: $uname=$other_uname;
1617: $udom =$other_udom;
1618: }
1.31 albertel 1619: my $cnum=$env{'course.'.$cid.'.num'};
1620: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1621: my $todo="$symb\0queue\0$uname:$udom";
1.31 albertel 1622: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1623: if ($key eq $todo && ref($value)) {
1624: return $value;
1625: }
1626: return undef;
1627: }
1628:
1.84 albertel 1629:
1.49 albertel 1630: sub check_queue_for_key {
1.84 albertel 1631: my ($cdom,$cnum,$queue,$todo)=@_;
1632:
1.49 albertel 1633: my %results=
1634: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1635:
1636: if (exists($results{$todo}) && ref($results{$todo})) {
1637: if (defined($results{"$todo\0locked"})) {
1638: return 'locked';
1639: }
1.148 albertel 1640: if (my $slot=&slotted_access($results{$todo})) {
1.86 albertel 1641: my %slot_data=&Apache::lonnet::get_slot($slot);
1642: if ($slot_data{'endtime'} > time) {
1643: return 'in_progress';
1644: }
1.148 albertel 1645: } else {
1646: my ($symb) = &decode_queue_key($todo);
1647: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1648: if ($due_date > time) {
1649: return 'in_progress';
1650: }
1.58 albertel 1651: }
1.49 albertel 1652: return 'enqueued';
1653: }
1654: return undef;
1655: }
1656:
1.14 albertel 1657: sub add_to_queue {
1.82 albertel 1658: my ($queue,$user_data)=@_;
1.49 albertel 1659: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1660: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.82 albertel 1661: if (!$cid || $env{'request.state'} eq 'construct') {
1662: return 'no_queue';
1663: }
1.14 albertel 1664: my $cnum=$env{'course.'.$cid.'.num'};
1665: my $cdom=$env{'course.'.$cid.'.domain'};
1666: my %data;
1.138 albertel 1667: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83 albertel 1668: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14 albertel 1669: }
1670:
1.156 albertel 1671: sub get_limited_classlist {
1672: my ($sections) = @_;
1673:
1674: my $classlist = &Apache::loncoursedata::get_classlist();
1.157 albertel 1675: foreach my $student (keys(%$classlist)) {
1676: if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
1677: ne 'Active') {
1678: delete($classlist->{$student});
1679: }
1680: }
1.156 albertel 1681:
1.237 albertel 1682: if (ref($sections) && !grep {$_ eq 'all'} (@{ $sections })) {
1.156 albertel 1683: foreach my $student (keys(%$classlist)) {
1684: my $section =
1685: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1.237 albertel 1686: if (! grep {$_ eq $section} (@{ $sections })) {
1.156 albertel 1687: delete($classlist->{$student});
1688: }
1689: }
1690: }
1691: return $classlist;
1692: }
1693:
1694:
1.14 albertel 1695: sub show_queue {
1.32 albertel 1696: my ($queue,$with_selects)=@_;
1.14 albertel 1697: my $result;
1.185 albertel 1698: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 1699: my $cnum=$env{'course.'.$cid.'.num'};
1700: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 1701:
1.237 albertel 1702: my @chosen_sections = &get_allowed_sections();
1.156 albertel 1703:
1704: my $classlist = &get_limited_classlist(\@chosen_sections);
1705:
1.63 albertel 1706: if (!(grep(/^all$/,@chosen_sections))) {
1.239 bisitz 1707: $result.='<p>'
1708: .&mt('Showing only sections [_1].'
1709: ,'<tt>'.join(', ',@chosen_sections).'</tt>')
1710: ."</p>\n";
1.63 albertel 1711: }
1.59 albertel 1712:
1.156 albertel 1713: my ($view,$view_section);
1714: my $scope = $env{'request.course.id'};
1715: if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
1716: $scope .= '/'.$env{'request.course.sec'};
1717: if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
1718: $view_section=$env{'request.course.sec'};
1719: } else {
1720: undef($view);
1721: }
1722: }
1723:
1.234 albertel 1724: $result .=
1725: '<p><a href="/adm/flip?postdata=return:">'.
1726: &mt('Return to resource').'</a></p><hr />'.
1.239 bisitz 1727: "\n<h3>".&mt('Current Queue - [_1]',$queue)."</h3>";
1.16 albertel 1728: my $regexp="^$symb\0";
1.30 albertel 1729: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 1730: my ($tmp)=%queue;
1731: if ($tmp=~/^error: 2 /) {
1.234 albertel 1732: $result.=
1.159 albertel 1733: &Apache::loncommon::start_data_table().
1734: &Apache::loncommon::start_data_table_row().
1735: '<td>'.&mt('Empty').'</td>'.
1736: &Apache::loncommon::end_data_table_row().
1737: &Apache::loncommon::end_data_table();
1.234 albertel 1738: return $result;
1.31 albertel 1739: }
1.103 albertel 1740: my $title=&Apache::lonnet::gettitle($symb);
1.234 albertel 1741: $result.=
1.159 albertel 1742: &Apache::loncommon::start_data_table().
1743: &Apache::loncommon::start_data_table_header_row();
1.239 bisitz 1744: if ($with_selects) { $result.='<th>'.&mt('Status').'</th><th></th>'; }
1745: $result.='<th>'.&mt('User').'</th><th>'.&mt('Data').'</th>'.
1.159 albertel 1746: &Apache::loncommon::end_data_table_header_row();
1.14 albertel 1747: foreach my $key (sort(keys(%queue))) {
1.59 albertel 1748: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235 albertel 1749: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 1750: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156 albertel 1751:
1752: my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1753:
1754: my $can_view=1;
1755: if (!$view
1756: || ($view_section && !$section)
1757: || ($view_section && $section && ($view_section ne $section))) {
1758: $can_view=0;
1759: }
1760:
1.32 albertel 1761: if ($key=~/locked$/ && !$with_selects) {
1.159 albertel 1762: $result.= &Apache::loncommon::start_data_table_row().
1763: "<td>$uname</td>";
1.103 albertel 1764: $result.='<td>'.$queue{$key}.'</td></tr>';
1.32 albertel 1765: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.159 albertel 1766: $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103 albertel 1767: $result.='<td>'.
1.16 albertel 1768: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 1769: } elsif ($key!~/(timestamp|locked)$/) {
1.159 albertel 1770: $result.= &Apache::loncommon::start_data_table_row();
1.148 albertel 1771: my ($end_time,$slot_text);
1772: if (my $slot=&slotted_access($queue{$key})) {
1773: my %slot_data=&Apache::lonnet::get_slot($slot);
1774: $end_time = $slot_data{'endtime'};
1775: $slot_text = &mt('Slot: [_1]',$slot);
1776: } else {
1777: $end_time = &Apache::lonhomework::due_date('0',$symb);
1778: $slot_text = '';
1779: }
1.32 albertel 1780: if ($with_selects) {
1.158 www 1781: my $ekey=&escape($key);
1.103 albertel 1782: my ($action,$description,$status)=('select',&mt('Select'));
1.32 albertel 1783: if (exists($queue{"$key\0locked"})) {
1.217 albertel 1784: my ($locker,$time) =
1785: &get_lock_info($queue{"$key\0locked"});
1786: if ($time) {
1.214 albertel 1787: $time =
1788: &Apache::lonnavmaps::timeToHumanString($time,
1789: 'start');
1790: }
1.138 albertel 1791: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.239 bisitz 1792: $status=&mt('Locked by [_1] [_2]','<tt>'.$locker.'</tt>',$time);
1.217 albertel 1793: if ($me eq $locker) {
1.32 albertel 1794: ($action,$description)=('resume',&mt('Resume'));
1795: } else {
1796: ($action,$description)=('unlock',&mt('Unlock'));
1797: }
1798: }
1.62 albertel 1799: my $seclist;
1800: foreach my $sec (@chosen_sections) {
1801: $seclist.='<input type="hidden" name="chosensections"
1802: value="'.$sec.'" />';
1803: }
1.156 albertel 1804: if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35 albertel 1805: $result.=(<<FORM);
1.103 albertel 1806: <td>$status</td>
1.32 albertel 1807: <td>
1.262 bisitz 1808: <form style="display: inline" method="post" action="">
1.32 albertel 1809: <input type="hidden" name="gradingkey" value="$ekey" />
1810: <input type="hidden" name="queue" value="$queue" />
1811: <input type="hidden" name="gradingaction" value="$action" />
1812: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 1813: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 1814: <input type="submit" name="submit" value="$description" />
1.62 albertel 1815: $seclist
1.32 albertel 1816: </form>
1817: </td>
1818: FORM
1.156 albertel 1819: } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
1820: $result.='<td>'.&mt("Not gradable").'</td><td> </td>'
1.35 albertel 1821: } else {
1.148 albertel 1822: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1.35 albertel 1823: }
1.32 albertel 1824: }
1.156 albertel 1825: $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138 albertel 1826: " <tt>($uname:$udom)</tt> </td>";
1.239 bisitz 1827: $result.='<td>'.$slot_text.' '
1828: .&mt('End time: [_1]'
1829: ,&Apache::lonlocal::locallocaltime($end_time))
1830: .'</td>'
1831: .&Apache::loncommon::end_data_table_row();
1.16 albertel 1832: }
1.14 albertel 1833: }
1.159 albertel 1834: $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14 albertel 1835: return $result;
1836: }
1837:
1.237 albertel 1838: sub get_allowed_sections {
1839: my @chosen_sections;
1840: if (§ion_restricted()) {
1841: @chosen_sections = ($env{'request.course.sec'});
1842: } else {
1843: @chosen_sections =
1844: &Apache::loncommon::get_env_multiple('form.chosensections');
1845: }
1846:
1847: return @chosen_sections;
1848: }
1849:
1.235 albertel 1850: sub section_restricted {
1.237 albertel 1851: my $cid =(&Apache::lonnet::whichuser())[1];
1852: return (lc($env{'course.'.$cid.'.task_grading'}) eq 'section'
1853: && $env{'request.course.sec'} ne '' );
1854: }
1855:
1856: sub allow_grade_user {
1.235 albertel 1857: my ($classlist_entry) = @_;
1.237 albertel 1858:
1859: if (§ion_restricted()
1.235 albertel 1860: && $env{'request.course.sec'} ne
1861: $classlist_entry->[&Apache::loncoursedata::CL_SECTION()]) {
1.237 albertel 1862: return 0;
1.235 albertel 1863: }
1.237 albertel 1864: return 1;
1.235 albertel 1865: }
1866:
1.34 albertel 1867: sub get_queue_counts {
1868: my ($queue)=@_;
1869: my $result;
1.185 albertel 1870: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.34 albertel 1871: my $cnum=$env{'course.'.$cid.'.num'};
1872: my $cdom=$env{'course.'.$cid.'.domain'};
1.156 albertel 1873:
1.157 albertel 1874: my $classlist=&get_limited_classlist();
1.156 albertel 1875:
1.34 albertel 1876: my $regexp="^$symb\0";
1877: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1878: my ($tmp)=%queue;
1879: if ($tmp=~/^error: 2 /) {
1880: return (0,0,0);
1881: }
1.235 albertel 1882:
1.34 albertel 1883: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96 albertel 1884: my %slot_cache;
1.34 albertel 1885: foreach my $key (sort(keys(%queue))) {
1.156 albertel 1886: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235 albertel 1887: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 1888: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.235 albertel 1889:
1.34 albertel 1890: if ($key=~/locked$/) {
1891: $locks++;
1892: } elsif ($key=~/timestamp$/) {
1893: #ignore
1894: } elsif ($key!~/(timestamp|locked)$/) {
1895: $entries++;
1.148 albertel 1896: if (my $slot=&slotted_access($queue{$key})) {
1897: if (!exists($slot_cache{$slot})) {
1898: my %slot_data=&Apache::lonnet::get_slot($slot);
1899: $slot_cache{$slot} = \%slot_data;
1900: }
1901: if (time > $slot_cache{$slot}{'endtime'}) {
1902: $ready_to_grade++;
1903: }
1904: } else {
1905: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1906: if ($due_date ne '' && time > $due_date) {
1907: $ready_to_grade++;
1908: }
1.34 albertel 1909: }
1910: }
1911: }
1912: return ($entries,$ready_to_grade,$locks);
1913: }
1914:
1.49 albertel 1915: sub encode_queue_key {
1916: my ($symb,$udom,$uname)=@_;
1.138 albertel 1917: return "$symb\0queue\0$uname:$udom";
1.49 albertel 1918: }
1919:
1.14 albertel 1920: sub decode_queue_key {
1921: my ($key)=@_;
1922: my ($symb,undef,$user) = split("\0",$key);
1.138 albertel 1923: my ($uname,$udom) = split(':',$user);
1.14 albertel 1924: return ($symb,$uname,$udom);
1925: }
1926:
1927: sub queue_key_locked {
1.30 albertel 1928: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1929: if (!defined($cdom) || !defined($cnum)) {
1.185 albertel 1930: my (undef,$cid)=&Apache::lonnet::whichuser();
1.33 albertel 1931: $cnum=$env{'course.'.$cid.'.num'};
1932: $cdom=$env{'course.'.$cid.'.domain'};
1933: }
1.14 albertel 1934: my ($key_locked,$value)=
1.30 albertel 1935: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1936: if ($key_locked eq "$key\0locked") {
1.217 albertel 1937: return &get_lock_info($value);
1.14 albertel 1938: }
1939: return undef;
1940: }
1941:
1.148 albertel 1942: sub slotted_access {
1943: my ($queue_entry) = @_;
1944: if (ref($queue_entry) eq 'ARRAY') {
1945: if (defined($queue_entry->[0])) {
1946: return $queue_entry->[0];
1947: }
1948: return undef;
1949: } elsif (ref($queue_entry) eq 'HASH') {
1950: if (defined($queue_entry->{'slot'})) {
1951: return $queue_entry->{'slot'};
1952: }
1953: return undef;
1954: }
1955: return undef;
1956: }
1957:
1.14 albertel 1958: sub pick_from_queue_data {
1.156 albertel 1959: my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98 albertel 1960: my @possible; # will hold queue entries that are valid to be selected
1.30 albertel 1961: foreach my $key (keys(%$queuedata)) {
1.68 albertel 1962: if ($key =~ /\0locked$/) { next; }
1963: if ($key =~ /\0timestamp$/) { next; }
1.156 albertel 1964:
1.14 albertel 1965: my ($symb,$uname,$udom)=&decode_queue_key($key);
1.235 albertel 1966: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 1967: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156 albertel 1968:
1.14 albertel 1969: if ($check_section) {
1.156 albertel 1970: my $section =
1971: $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17 albertel 1972: if ($section eq $check_section) {
1.33 albertel 1973: &Apache::lonxml::debug("my sec");
1.15 albertel 1974: next;
1975: }
1.14 albertel 1976: }
1.148 albertel 1977: my $end_time;
1978: if (my $slot=&slotted_access($queuedata->{$key})) {
1.154 albertel 1979: &Apache::lonxml::debug("looking at slot $slot");
1.148 albertel 1980: my %slot_data=&Apache::lonnet::get_slot($slot);
1981: if ($slot_data{'endtime'} < time) {
1982: $end_time = $slot_data{'endtime'};
1.154 albertel 1983: } else {
1984: &Apache::lonxml::debug("not time ".$slot_data{'endtime'});
1985: next;
1.148 albertel 1986: }
1987: } else {
1988: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154 albertel 1989: if ($due_date < time) {
1.148 albertel 1990: $end_time = $due_date;
1.154 albertel 1991: } else {
1992: &Apache::lonxml::debug("not time $due_date");
1993: next;
1.148 albertel 1994: }
1995: }
1996:
1.98 albertel 1997: if (exists($queuedata->{"$key\0locked"})) {
1.33 albertel 1998: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1999: next;
2000: }
1.148 albertel 2001: push(@possible,[$key,$end_time]);
1.98 albertel 2002: }
2003: if (@possible) {
2004: # sort entries in order by slot end time
2005: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137 albertel 2006: # pick one of the entries in the top 10% in small queues and one
2007: # of the first ten entries in large queues
1.139 albertel 2008: #my $ten_percent = int($#possible * 0.1);
2009: #if ($ten_percent < 1 ) { $ten_percent = 1; }
2010: #if ($ten_percent > 10) { $ten_percent = 10; }
2011: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137 albertel 2012:
1.139 albertel 2013: #return $possible[int(rand($max))][0];
2014: return $possible[0][0];
1.14 albertel 2015: }
2016: return undef;
2017: }
2018:
1.217 albertel 2019: sub get_lock_info {
2020: my ($lock_info) = @_;
2021: if (wantarray) {
2022: if (ref($lock_info) eq 'ARRAY') {
2023: return @{$lock_info};
2024: } else {
2025: return ($lock_info);
2026: }
2027: } else {
2028: if (ref($lock_info) eq 'ARRAY') {
2029: return $lock_info->[0];
2030: } else {
2031: return $lock_info;
2032: }
2033: }
2034: return;
2035: }
2036:
1.15 albertel 2037: sub find_mid_grade {
1.30 albertel 2038: my ($queue,$symb,$cdom,$cnum)=@_;
1.158 www 2039: my $todo=&unescape($env{'form.gradingkey'});
1.138 albertel 2040: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15 albertel 2041: if ($todo) {
1.30 albertel 2042: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 2043: if ($who eq $me) { return $todo; }
2044: }
2045: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 2046: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 2047: foreach my $key (keys(%locks)) {
1.217 albertel 2048: my $who= &get_lock_info($locks{$key});
1.15 albertel 2049: if ($who eq $me) {
2050: $todo=$key;
2051: $todo=~s/\0locked$//;
2052: return $todo;
2053: }
2054: }
2055: return undef;
2056: }
2057:
1.32 albertel 2058: sub lock_key {
2059: my ($queue,$todo)=@_;
1.138 albertel 2060: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.185 albertel 2061: my (undef,$cid)=&Apache::lonnet::whichuser();
1.32 albertel 2062: my $cnum=$env{'course.'.$cid.'.num'};
2063: my $cdom=$env{'course.'.$cid.'.domain'};
1.214 albertel 2064: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> [$me,time]},
1.32 albertel 2065: $cdom,$cnum);
1.33 albertel 2066: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 2067: if ($success eq 'ok') {
2068: return 1;
2069: }
2070: return 0;
2071: }
2072:
1.86 albertel 2073: sub get_queue_symb_status {
1.85 albertel 2074: my ($queue,$symb,$cdom,$cnum) = @_;
2075: if (!defined($cdom) || !defined($cnum)) {
1.235 albertel 2076: my (undef,$cid) =&Apache::lonnet::whichuser();
1.85 albertel 2077: $cnum=$env{'course.'.$cid.'.num'};
2078: $cdom=$env{'course.'.$cid.'.domain'};
2079: }
1.157 albertel 2080: my $classlist=&get_limited_classlist();
1.156 albertel 2081:
1.85 albertel 2082: my $regexp="^$symb\0";
2083: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
2084: my ($tmp)=%queue;
2085: if ($tmp=~/^error: 2 /) { return; }
2086: my @users;
2087: foreach my $key (sort(keys(%queue))) {
2088: next if ($key=~/locked$/);
2089: next if ($key=~/timestamp$/);
2090: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156 albertel 2091: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 2092: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.85 albertel 2093: push(@users,"$uname:$udom");
2094: }
2095: return @users;
2096: }
2097:
1.14 albertel 2098: sub get_from_queue {
1.30 albertel 2099: my ($queue)=@_;
1.14 albertel 2100: my $result;
1.185 albertel 2101: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 2102: my $cnum=$env{'course.'.$cid.'.num'};
2103: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 2104: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 2105: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 2106: if ($todo) { return $todo; }
1.95 albertel 2107: my $attempts=0;
1.156 albertel 2108:
1.157 albertel 2109: my $classlist=&get_limited_classlist();
1.156 albertel 2110:
1.14 albertel 2111: while (1) {
1.95 albertel 2112: if ($attempts > 2) {
2113: # tried twice to get a queue entry, giving up
2114: return (undef,'unable');
2115: }
1.14 albertel 2116: my $starttime=time;
1.83 albertel 2117: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
2118: $cdom,$cnum);
1.33 albertel 2119: &Apache::lonxml::debug("$starttime");
1.14 albertel 2120: my $regexp="^$symb\0queue\0";
1.156 albertel 2121: #my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97 albertel 2122:
1.98 albertel 2123: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 2124: #make a pass looking for a user _not_ in my section
1.14 albertel 2125: if ($env{'request.course.sec'}) {
1.33 albertel 2126: &Apache::lonxml::debug("sce");
1.30 albertel 2127: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156 albertel 2128: \%queue,$cdom,$cnum,$classlist);
1.33 albertel 2129: &Apache::lonxml::debug("sce $todo");
1.14 albertel 2130: }
1.33 albertel 2131: # no one _not_ in our section so look for any user that is
2132: # ready for grading
1.14 albertel 2133: if (!$todo) {
1.33 albertel 2134: &Apache::lonxml::debug("no sce");
1.156 albertel 2135: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
2136: $classlist);
1.33 albertel 2137: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 2138: }
2139: # no user to grade
2140: if (!$todo) { last; }
1.33 albertel 2141: &Apache::lonxml::debug("got $todo");
1.14 albertel 2142: # otherwise found someone so lets try to lock them
1.32 albertel 2143: # unless someone else already picked them
1.95 albertel 2144: if (!&lock_key($queue,$todo)) {
2145: $attempts++;
2146: next;
2147: }
1.14 albertel 2148: my (undef,$endtime)=
1.30 albertel 2149: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 2150: $cdom,$cnum);
1.33 albertel 2151: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 2152: # someone else already modified the queue,
2153: # perhaps our picked user wass already fully graded between
2154: # when we picked him and when we locked his record? so lets
2155: # double check.
2156: if ($endtime != $starttime) {
2157: my ($key,$value)=
1.30 albertel 2158: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 2159: $cdom,$cnum);
1.33 albertel 2160: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 2161: if ($key eq $todo && ref($value)) {
2162: } else {
1.30 albertel 2163: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 2164: $cdom,$cnum);
1.33 albertel 2165: &Apache::lonxml::debug("del");
1.95 albertel 2166: $attempts++;
1.14 albertel 2167: next;
2168: }
2169: }
1.33 albertel 2170: &Apache::lonxml::debug("last $todo");
1.14 albertel 2171: last;
2172: }
2173: return $todo;
2174: }
2175:
1.49 albertel 2176: sub select_user {
1.185 albertel 2177: my ($symb,$cid)=&Apache::lonnet::whichuser();
1.49 albertel 2178:
1.237 albertel 2179: my @chosen_sections = &get_allowed_sections();
1.156 albertel 2180: my $classlist = &get_limited_classlist(\@chosen_sections);
1.63 albertel 2181:
2182: my $result;
2183: if (!(grep(/^all$/,@chosen_sections))) {
1.239 bisitz 2184: $result.='<p>'
2185: .&mt('Showing only sections [_1].'
2186: ,'<tt>'.join(', ',@chosen_sections).'</tt>')
2187: .'</p> '."\n";
1.63 albertel 2188: }
1.159 albertel 2189: $result.=&Apache::loncommon::start_data_table();
1.49 albertel 2190:
1.156 albertel 2191: foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49 albertel 2192: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 2193:
1.84 albertel 2194: my $cnum=$env{'course.'.$cid.'.num'};
2195: my $cdom=$env{'course.'.$cid.'.domain'};
1.88 albertel 2196: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
2197: 'Task');
1.49 albertel 2198: my $queue = 'none';
1.58 albertel 2199: my $cannot_grade;
2200: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 2201: $queue = 'reviewqueue';
1.58 albertel 2202: if ($status{'reviewqueue'} eq 'in_progress') {
2203: $cannot_grade=1;
2204: }
2205: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 2206: $queue = 'gradingqueue';
1.58 albertel 2207: if ($status{'gradingqueue'} eq 'in_progress') {
2208: $cannot_grade=1;
2209: }
1.49 albertel 2210: }
2211: my $todo =
1.158 www 2212: &escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 2213: if ($cannot_grade) {
1.159 albertel 2214: $result.=&Apache::loncommon::start_data_table_row().
2215: '<td> </td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58 albertel 2216: '</td><td>';
2217: } else {
1.62 albertel 2218: my $seclist;
2219: foreach my $sec (@chosen_sections) {
2220: $seclist.='<input type="hidden" name="chosensections"
2221: value="'.$sec.'" />';
2222: }
1.242 bisitz 2223: my $buttontext=&mt('Regrade');
1.159 albertel 2224: $result.=&Apache::loncommon::start_data_table_row();
1.58 albertel 2225: $result.=<<RESULT;
1.49 albertel 2226: <td>
1.262 bisitz 2227: <form style="display: inline" method="post" action="">
1.49 albertel 2228: <input type="hidden" name="gradingkey" value="$todo" />
2229: <input type="hidden" name="queue" value="$queue" />
2230: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 2231: <input type="hidden" name="regrade" value="yes" />
1.242 bisitz 2232: <input type="submit" name="submit" value="$buttontext" />
1.62 albertel 2233: $seclist
1.49 albertel 2234: </form>
1.237 albertel 2235: <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt> Sec: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()]</td>
1.49 albertel 2236: <td>
2237: RESULT
1.58 albertel 2238: }
1.49 albertel 2239: if ($status{'status'} eq 'pass') {
2240: $result .= '<font color="green">'.&mt('Passed').'</font>';
2241: } elsif ($status{'status'} eq 'fail') {
2242: $result .= '<font color="red">'.&mt('Failed').'</font>';
2243: } elsif ($status{'status'} eq 'review') {
2244: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
2245: } elsif ($status{'status'} eq 'ungraded') {
2246: $result .= &mt('Ungraded');
2247: } elsif ($status{'status'} ne '') {
2248: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
2249: } else {
2250: $result.=" ";
2251: }
2252: if ($status{'version'}) {
2253: $result .= ' '.&mt('Version').' '.$status{'version'};
2254: }
1.101 albertel 2255: if ($status{'grader'}) {
2256: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
2257: }
1.49 albertel 2258: $result.= '</td><td>';
2259: if ($status{'reviewqueue'} eq 'enqueued') {
2260: $result .= &mt('Awaiting Review');
2261: } elsif ($status{'reviewqueue'} eq 'locked') {
2262: $result .= &mt('Under Review');
1.58 albertel 2263: } elsif ($status{'reviewqueue'} eq 'in_progress') {
2264: $result .= &mt('Still being worked on.');
1.49 albertel 2265: } elsif ($status{'gradingqueue'} eq 'enqueued') {
2266: $result .= &mt('Awaiting Grading');
2267: } elsif ($status{'gradingqueue'} eq 'locked') {
2268: $result .= &mt('Being Graded');
1.58 albertel 2269: } elsif ($status{'gradingqueue'} eq 'in_progress') {
2270: $result .= &mt('Still being worked on.');
1.49 albertel 2271: } else {
2272: $result.=" ";
2273: }
1.159 albertel 2274: $result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49 albertel 2275: }
1.159 albertel 2276: $result.=&Apache::loncommon::end_data_table();
1.49 albertel 2277: return $result;
2278: }
2279:
2280: sub get_student_status {
1.86 albertel 2281: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
2282:
2283: my %status;
2284:
2285: if ($type eq 'Task') {
2286: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49 albertel 2287: $udom,$uname);
1.89 albertel 2288: $status{'status'}=$record{'resource.0.status'};
2289: $status{'version'}=$record{'resource.0.version'};
2290: $status{'grader'}=$record{'resource.0.regrader'};
1.86 albertel 2291: }
2292: $status{'reviewqueue'}=
2293: &check_queue_for_key($cdom,$cnum,'reviewqueue',
2294: &encode_queue_key($symb,$udom,$uname));
2295: $status{'gradingqueue'}=
2296: &check_queue_for_key($cdom,$cnum,'gradingqueue',
2297: &encode_queue_key($symb,$udom,$uname));
1.49 albertel 2298: return %status;
2299: }
2300:
1.1 albertel 2301: sub start_ClosingParagraph {
2302: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2303: my $result;
2304: if ($target eq 'web') {
1.13 albertel 2305: } elsif ($target eq 'webgrade') {
2306: &Apache::lonxml::startredirection();
1.225 albertel 2307: } elsif ($target eq 'edit') {
2308: $result = &Apache::edit::tag_start($target,$token);
2309: } elsif ($target eq 'modified') {
1.1 albertel 2310: }
2311: return $result;
2312: }
2313:
2314: sub end_ClosingParagraph {
2315: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2316: my $result;
2317: if ($target eq 'web') {
1.13 albertel 2318: } elsif ($target eq 'webgrade') {
2319: &Apache::lonxml::endredirection();
1.1 albertel 2320: }
2321: return $result;
2322: }
2323:
1.227 albertel 2324: sub insert_ClosingParagraph {
2325: return '
2326: <ClosingParagraph>
2327: <startouttext />
2328: <endouttext />
2329: </ClosingParagraph>';
2330: }
2331:
1.168 albertel 2332: sub get_dim_id {
1.194 albertel 2333: if (@Apache::bridgetask::dimension) {
2334: return $Apache::bridgetask::dimension[-1];
2335: } else {
2336: return $top;
2337: }
1.168 albertel 2338: }
2339:
1.19 albertel 2340: sub get_id {
2341: my ($parstack,$safeeval)=@_;
1.236 albertel 2342: return &Apache::lonxml::get_id($parstack,$safeeval);
1.19 albertel 2343: }
2344:
1.162 albertel 2345: sub start_Setup {
2346: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225 albertel 2347: my $result;
1.168 albertel 2348: my $dim = &get_id($parstack,$safeeval);
2349: push(@Apache::bridgetask::dimension,$dim);
1.225 albertel 2350: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
2351: &Apache::lonxml::startredirection();
2352: } elsif ($target eq 'edit') {
2353: $result = &Apache::edit::tag_start($target,$token);
2354: $result.= &Apache::edit::text_arg('Id:','id',$token,10).
2355: &Apache::edit::end_row().
2356: &Apache::edit::start_spanning_row();
2357: } elsif ($target eq 'modified') {
2358: my $constructtag=
2359: &Apache::edit::get_new_args($token,$parstack,$safeeval,'id');
2360: if ($constructtag) {
2361: $result = &Apache::edit::rebuild_tag($token);
2362: }
2363: }
2364: return $result;
1.162 albertel 2365: }
1.173 albertel 2366:
2367: {
2368: my @allowed;
2369: sub enable_dimension_parsing {
2370: my ($id) = @_;
2371: push(@allowed,$id);
2372: }
2373: sub disable_dimension_parsing {
2374: pop(@allowed);
2375: }
2376: sub skip_dimension_parsing {
2377: my ($check) = @_;
2378: if (!@allowed) { return 0;}
2379: # if unspecified allow any id
2380: if ($allowed[-1] eq undef) { return 0;}
2381:
2382: return ($check ne $allowed[-1]);
2383: }
2384: }
2385:
1.151 albertel 2386: sub start_Question { return &start_Dimension(@_); }
1.1 albertel 2387: sub start_Dimension {
1.173 albertel 2388: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2389: my $dim = &get_id($parstack,$safeeval);
2390: my $previous_dim;
1.225 albertel 2391: my $result;
2392: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2393: if (@Apache::bridgetask::dimension) {
2394: $previous_dim = $Apache::bridgetask::dimension[-1];
2395: push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
2396: $dim);
2397: if(&skip_dimension_parsing($dim)) {
2398: $dimension{$previous_dim}{'criteria.'.$dim} =
2399: $token->[4]
2400: .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
2401: $style)
2402: .'</'.$tagstack->[-1].'>';
2403: }
2404: $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
2405: $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
2406: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2407: push(@{$dimension{$previous_dim}{'criterias'}},$dim);
2408: $dimension{$dim}{'nested'}=$previous_dim;
2409: $dimension{$dim}{'depth'} = 1 + $dimension{$previous_dim}{'depth'};
2410:
2411: &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
2412: } else {
2413: $dimension{$top}{'depth'}=0;
2414: $dimension{$top}{'criteria.'.$dim.'.type'}='dimension';
2415: $dimension{$top}{'criteria.'.$dim.'.mandatory'}=
2416: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2417: push(@{$dimension{$top}{'criterias'}},$dim);
2418: $dimension{$dim}{'nested'}=$top;
2419: }
2420: push(@Apache::bridgetask::dimension,$dim);
2421: &Apache::lonxml::startredirection();
2422: if (!&skip_dimension_parsing($dim)) {
2423: &enable_dimension_parsing($dim);
2424: }
2425: } elsif ($target eq 'edit') {
2426: $result = &Apache::edit::tag_start($target,$token);
2427: $result.=
2428: &Apache::edit::text_arg('Id:','id',$token,10).' '.
2429: &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233 albertel 2430: [['Y', 'Yes'],
2431: ['N','No'],],
1.225 albertel 2432: $token).' <br /> '.
2433: &Apache::edit::text_arg('Required number of passed optional elements to pass the '.$token->[1].':',
2434: 'OptionalRequired',$token,4).
2435: &Apache::edit::end_row().
2436: &Apache::edit::start_spanning_row();
2437: } elsif ($target eq 'modified') {
2438: my $constructtag=
2439: &Apache::edit::get_new_args($token,$parstack,$safeeval,
2440: 'id','Mandatory','OptionalRequired');
2441: if ($constructtag) {
2442: $result = &Apache::edit::rebuild_tag($token);
2443: }
1.168 albertel 2444: }
1.225 albertel 2445: return $result;# &internal_location($dim);
1.1 albertel 2446: }
2447:
1.160 albertel 2448: sub start_QuestionText {
2449: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225 albertel 2450: my $result;
2451: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2452: my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
1.168 albertel 2453: my $dim = &get_dim_id();
1.169 albertel 2454: $dimension{$dim}{'questiontext'}=$text;
1.225 albertel 2455: } elsif ($target eq 'edit') {
2456: $result = &Apache::edit::tag_start($target,$token);
2457: } elsif ($target eq 'modified') {
1.160 albertel 2458: }
1.225 albertel 2459: return $result;
1.160 albertel 2460: }
2461:
2462: sub end_QuestionText {
2463: return '';
2464: }
2465:
1.227 albertel 2466: sub insert_QuestionText {
2467: return '
2468: <QuestionText>
2469: <startouttext />
2470: <endouttext />
2471: </QuestionText>';
2472: }
2473:
1.13 albertel 2474: sub get_instance {
1.75 albertel 2475: my ($dim)=@_;
2476: my $rand_alg=&Apache::lonnet::get_rand_alg();
2477: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
2478: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
2479: $rand_alg eq '64bit4' ) {
2480: &Apache::response::pushrandomnumber();
1.169 albertel 2481: my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75 albertel 2482: my $num=@order;
2483: my $version=&get_version();
2484: my $which=($version-1)%$num;
2485: return $order[$which];
2486: } else {
2487: my ($version,$previous) = &get_version();
2488: my $instance =
2489: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
2490: if (defined($instance)) { return $instance; }
2491:
2492: &Apache::response::pushrandomnumber();
1.173 albertel 2493: if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
2494: my @instances = @{$dimension{$dim}{'instances'}};
2495: # remove disabled instances
2496: for (my $i=0; $i < $#instances; $i++) {
2497: if ($dimension{$dim}{$instances[$i].'.disabled'}) {
2498: splice(@instances,$i,1);
2499: $i--;
2500: }
2501: }
2502: @instances = &Math::Random::random_permutation(@instances);
2503: $instance = $instances[($version-1)%scalar(@instances)];
2504: if ($version =~ /^\d$/) {
2505: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
2506: $instance;
2507: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
1.75 albertel 2508: }
2509: }
2510: &Apache::response::poprandomnumber();
2511: return $instance;
2512: }
1.13 albertel 2513: }
2514:
1.169 albertel 2515: sub get_criteria {
2516: my ($what,$version,$dim,$id) = @_;
2517: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.194 albertel 2518: my $prefix = ($type eq 'criteria' && $dim ne $top) ? "$dim.$id"
2519: : "$id";
1.169 albertel 2520: my $entry = "resource.$version.0.$prefix.$what";
2521: if (exists($Apache::lonhomework::results{$entry})) {
2522: return $Apache::lonhomework::results{$entry};
2523: }
2524: return $Apache::lonhomework::history{$entry};
2525: }
2526:
1.194 albertel 2527: sub link {
2528: my ($id) = @_;
2529: $id =~ s/\./_/g;
2530: return 'LC_GRADING_criteria_'.$id;
2531: }
2532: sub end_Question { return &end_Dimension(@_); }
2533: sub end_Dimension {
2534: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225 albertel 2535: my $result;
1.194 albertel 2536: my $dim=&get_id($parstack,$safeeval);
1.225 albertel 2537: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2538: $result=&Apache::lonxml::endredirection();
2539: if (&skip_dimension_parsing($dim)) {
2540: pop(@Apache::bridgetask::dimension);
2541: return;
2542: }
1.122 albertel 2543: }
1.194 albertel 2544: my $instance=&get_instance($dim);
2545: my $version=&get_version();
2546: if ($target eq 'web') {
2547: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2548: my @instances = $instance;
2549: if (&Apache::response::showallfoils()) {
2550: @instances = @{$dimension{$dim}{'instances'}};
1.173 albertel 2551: }
1.194 albertel 2552: my $shown_question_text;
2553: foreach my $instance (@instances) {
2554: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2555: [@_]);
2556: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2557: [@_],{'set_dim_id' => undef});
2558: my $task_status =
2559: $Apache::lonhomework::history{"resource.$version.0.status"};
2560: if ($task_status ne 'pass' && $task_status ne 'fail') {
2561:
2562: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2563: @{$dimension{$dim}{'criterias'}}) {
2564: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2565: &Apache::lonxml::debug("$id is $type");
2566: if ($type eq 'dimension') {
2567: $result.=
2568: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2569: [@_],{'set_dim_id' => $id});
1.173 albertel 2570: }
1.194 albertel 2571: }
2572: } else {
2573: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
2574: my $mandatory='Mandatory';
2575: if (&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval) eq 'N') {
2576: $mandatory='Optional';
2577: }
1.200 albertel 2578: my $dim_info=
2579: "\n<div class='LC_$dim_status LC_question_grade'>\n\t";
1.212 albertel 2580: my $ucquestion =
2581: my $question =
2582: ('sub' x $dimension{$dim}{'depth'}).'question';
2583: $ucquestion =~ s/^(.)/uc($1)/e;
1.194 albertel 2584: if ($dim_status eq 'pass') {
1.239 bisitz 2585: $dim_info.='<h3>'.$ucquestion.' : '
2586: .&mt('you passed this [_1] [_2]',$mandatory,$question)
2587: .'</h3>';
1.194 albertel 2588: }
2589: if ($dim_status eq 'fail') {
1.239 bisitz 2590: $dim_info.='<h3>'.$ucquestion.' : '
2591: .&mt('you did not pass this [_1] [_2]',$mandatory,$question)
2592: .'</h3>';
1.194 albertel 2593: }
1.197 albertel 2594: my %counts = &get_counts($dim,$instance,$parstack,
2595: $safeeval);
2596:
1.200 albertel 2597: $dim_info.="\n\t<p>"
1.197 albertel 2598: .&question_status_message(\%counts,
2599: $dimension{$dim}{'depth'})
1.200 albertel 2600: ."</p>\n</div>\n";
1.194 albertel 2601:
2602: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2603: @{$dimension{$dim}{'criterias'}}) {
2604: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2605: if ($type eq 'dimension') {
1.205 albertel 2606: if (defined($dimension{$id}{'result'})) {
2607: $result.=$dimension{$id}{'result'};
2608: next;
2609: } else {
2610: $dim_info .=
2611: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2612: [@_],{'set_dim_id' => $id});
2613: }
2614: } else {
2615: my $criteria =
2616: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2617: [@_]);
2618: $dim_info .= &layout_web_Criteria($dim,$id,$criteria);
1.194 albertel 2619: }
1.169 albertel 2620: }
1.202 albertel 2621: # puts the results at the end of the dimension
1.226 albertel 2622: if ($result =~m{<QuestionGradeInfo\s*/>}) {
2623: $result=~s{<QuestionGradeInfo\s*/>}{$dim_info};
2624: } else {
2625: $result .= $dim_info;
2626: }
1.202 albertel 2627: # puts the results at the beginning of the dimension
2628: # my $internal_location=&internal_location($dim);
2629: # $result=~s/\Q$internal_location\E/$dim_info/;
1.19 albertel 2630: }
1.194 albertel 2631: }
1.206 albertel 2632: if ($result !~ /^\s*$/s) {
1.209 albertel 2633: # FIXME? this maybe unneccssary in the future, (CSE101 BT
2634: # from Fall 2006 geenrate a div that attempts to hide some
2635: # of the output in an odd way, this is a workaround so
2636: # those old ones will continue to work. # It puts the
2637: # LC_question div to come after any starting closie div
2638: # that the dimension produces
1.211 albertel 2639: if ($result =~ m{^\s*</div>}) {
2640: $result =~ s{^(\s*</div>)}
1.210 albertel 2641: {$1\n<div id="$dim" class="LC_question">};
1.209 albertel 2642: } else {
1.210 albertel 2643: $result = "\n".'<div id="'.$dim.'" class="LC_question">'.
1.209 albertel 2644: "\n".$result;
2645: }
2646: $result .= "\n</div>\n";
1.206 albertel 2647: }
1.194 albertel 2648: } elsif ($target eq 'webgrade') {
2649: # in case of any side effects that we need
2650: &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2651: &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
2652: $result.=
2653: &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
2654: {'set_dim_id' => undef,
1.195 albertel 2655: 'delayed_dim_results' => 1});
1.194 albertel 2656: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2657: @{$dimension{$dim}{'criterias'}} ) {
2658: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2659: if ($type eq 'dimension') {
2660: # dimensional 'criteria' don't get assigned grades
2661: $result.=
2662: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2663: [@_],{'set_dim_id' => $id});
2664: next;
2665: } else {
2666: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
2667: [@_]);
2668: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
2669: my $internal_location=&internal_location($id);
1.209 albertel 2670: if ($result =~ m/\Q$internal_location\E/) {
2671: $result =~ s/\Q$internal_location\E/$criteria/;
2672: } else {
2673: $result.=$criteria ;
2674: }
1.151 albertel 2675: }
1.194 albertel 2676: }
2677: if (&nest()) {
2678: &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
2679: $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
2680: undef($result);
2681: }
2682: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
2683: my $optional_passed=0;
2684: my $mandatory_failed=0;
2685: my $ungraded=0;
2686: my $review=0;
2687:
2688: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2689: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2690: [@_]);
2691: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2692: [@_],{'set_dim_id' => undef});
2693:
2694: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2695: @{$dimension{$dim}{'criterias'}}) {
2696: my $link=&link($id);
2697:
2698: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2699: if ($type eq 'criteria') {
2700: # dimensional 'criteria' don't get assigned grades
2701: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
2702: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
2703: } else {
2704: $result .=
2705: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2706: [@_],{'set_dim_id' => $id});
1.20 albertel 2707: }
1.194 albertel 2708: my $status= &get_criteria('status',$version,$dim,$id);
2709:
2710: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
2711: if ($status eq 'pass') {
2712: if (!$mandatory) { $optional_passed++; }
2713: } elsif ($status eq 'fail') {
2714: if ($mandatory) { $mandatory_failed++; }
2715: } elsif ($status eq 'review') {
2716: $review++;
2717: } elsif ($status eq 'ungraded') {
2718: $ungraded++;
1.20 albertel 2719: } else {
1.194 albertel 2720: $ungraded++;
1.20 albertel 2721: }
1.194 albertel 2722: }
2723:
2724: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
2725: if ($opt_req !~ /\S/) {
2726: $opt_req=
2727: &Apache::lonxml::get_param('OptionalRequired',
2728: $parstack,$safeeval);
2729: if ($opt_req !~ /\S/) { $opt_req = 0; }
2730: }
2731: if ($optional_passed < $opt_req) {
2732: $mandatory_failed++;
2733: }
2734: &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
2735: if ($review) {
2736: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2737: 'review';
2738: } elsif ($ungraded) {
2739: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2740: 'ungraded';
2741: } elsif ($mandatory_failed) {
2742: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2743: 'fail';
1.69 albertel 2744: } else {
1.194 albertel 2745: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2746: 'pass';
1.13 albertel 2747: }
1.225 albertel 2748: } elsif ($target eq 'edit') {
2749: } elsif ($target eq 'modified') {
1.194 albertel 2750: } else {
2751: # any other targets no output
2752: undef($result);
1.1 albertel 2753: }
1.225 albertel 2754: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2755: &disable_dimension_parsing();
2756: pop(@Apache::bridgetask::dimension);
2757: }
1.194 albertel 2758: return $result;
2759: }
1.162 albertel 2760:
1.198 albertel 2761: sub question_status_message {
1.197 albertel 2762: my ($counts,$depth) = @_;
2763: my %req = ('man' => 'mandatory',
2764: 'opt' => 'optional',);
2765: my %type = ('cri' => 'criteria',
2766: 'dim' => ('sub'x($depth+1)).'questions',);
2767: my @sections;
2768: foreach my $req ('man','opt') {
2769: foreach my $type ('cri','dim') {
2770: if ($counts->{$req.'_'.$type}) {
2771: push(@sections,
1.213 albertel 2772: $counts->{$req.'_'.$type.'_passed'}.' of the '.
1.197 albertel 2773: $counts->{$req.'_'.$type}.' '.
2774: $req{$req}.' '.$type{$type});
2775: }
2776: }
2777: }
2778:
2779: my $status = 'You passed ';
2780: if (@sections == -1) {
2781: } elsif (@sections == 1) {
2782: $status .= $sections[0];
2783: } elsif (@sections == 2) {
2784: $status .= $sections[0].' and '.$sections[1];
2785: } else {
2786: my $last = pop(@sections);
2787: $status .= join(', ',@sections).', and '.$last;
2788: }
2789: $status .= '.';
2790: if ($counts->{'opt'}) {
1.241 raeburn 2791: if ($counts->{'opt_dim'} + $counts->{'man_dim'} < 1) {
2792: $status .= ' '.&mt('You were required to pass [quant,_1,optional criterion,optional criteria].',$counts->{'opt_req'});
2793: } else {
2794: $status .= ' '.&mt('You were required to pass [quant,_1,optional component].',$counts->{'opt_req'});
2795: }
1.197 albertel 2796: }
2797: return $status;
2798: }
2799:
2800: sub get_counts {
2801: my ($dim,$instance,$parstack,$safeeval) = @_;
2802: my %counts;
2803: my @possible = ('man_cri','man_dim',
2804: 'opt_cri','opt_dim',
2805: 'man_cri_passed', 'man_dim_passed',
2806: 'opt_cri_passed', 'opt_dim_passed',
2807: 'man_passed',
2808: 'opt_passed',
2809: 'opt_req');
2810: foreach my $which (@possible) { $counts{$which} = 0; }
2811:
2812: my $version = &get_version();
2813:
2814: foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
2815: @{$dimension{$dim}{'criterias'}} ) {
2816: my $status = &get_criteria('status',$version,$dim,$id);
2817: my $which;
2818: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
2819: eq 'N') {
2820: $which = 'opt';
2821: } else {
2822: $which = 'man';
2823: }
2824: $counts{$which}++;
2825: if ($status eq 'pass') { $counts{$which.'_passed'}++; }
2826: if ($dimension{$dim}{'criteria.'.$id.'.type'}
2827: eq 'dimension') {
2828: $which .= '_dim';
2829: } else {
2830: $which .= '_cri';
2831: }
2832: $counts{$which}++;
2833: if ($status eq 'pass') { $counts{$which.'_passed'}++; }
2834:
2835:
2836: }
2837: if ($counts{'man_dim_passed'} eq $counts{'man_dim'}) {
2838: $counts{'man_dim_passed'}='all';
2839: }
2840: if ($counts{'man_cri_passed'} eq $counts{'man_cri'}) {
2841: $counts{'man_cri_passed'}='all';
2842: }
2843:
2844: $counts{'opt_req'}=$dimension{$dim}{$instance.'.optionalrequired'};
2845: if ($counts{'opt_req'} !~ /\S/) {
2846: $counts{'opt_req'}= &Apache::lonxml::get_param('OptionalRequired',
2847: $parstack,$safeeval);
2848: if ($counts{'opt_req'} !~ /\S/) { $counts{'opt_req'} = 0; }
2849: }
2850: return %counts;
2851: }
2852:
1.194 albertel 2853: sub end_Setup {
2854: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225 albertel 2855: my $result;
1.194 albertel 2856: my $dim=&get_id($parstack,$safeeval);
2857: my $instance=&get_instance($dim);
2858: my $version=&get_version();
1.225 albertel 2859: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
2860: $result=&Apache::lonxml::endredirection();
2861: }
1.194 albertel 2862: if ($target eq 'web') {
2863: @Apache::scripttag::parser_env = @_;
2864: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2865: my @instances = $instance;
2866: if (&Apache::response::showallfoils()) {
2867: @instances = @{$dimension{$dim}{'instances'}};
2868: }
2869: foreach my $instance (@instances) {
1.162 albertel 2870: @Apache::scripttag::parser_env = @_;
1.194 albertel 2871: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2872: @Apache::scripttag::parser_env = @_;
1.194 albertel 2873: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2874: }
1.194 albertel 2875: } elsif ($target eq 'webgrade'
2876: || $target eq 'grade' && $env{'form.webgrade'}) {
2877: # in case of any side effects that we need
2878: @Apache::scripttag::parser_env = @_;
2879: &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2880: @Apache::scripttag::parser_env = @_;
2881: &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
2882: @Apache::scripttag::parser_env = @_;
2883: &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
2884: } else {
2885: # any other targets no output
2886: undef($result);
1.162 albertel 2887: }
1.194 albertel 2888: pop(@Apache::bridgetask::dimension);
2889: return $result;
1.1 albertel 2890: }
2891:
1.113 albertel 2892: sub grading_history {
1.151 albertel 2893: my ($version,$dim,$id) = @_;
1.235 albertel 2894: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
2895: && !&Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
1.113 albertel 2896: return '';
2897: }
2898: my ($result,$grader);
1.194 albertel 2899: my $scope="resource.$version.0.";
2900: $scope .= ($dim ne $top) ? "$dim.$id"
2901: : "$id";
1.113 albertel 2902: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
2903: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
2904: my ($gname,$gdom) =
1.138 albertel 2905: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113 albertel 2906: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
2907: $grader = &Apache::loncommon::aboutmewrapper($fullname,
2908: $gname,$gdom);
2909: }
2910: my $entry;
2911: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
2912: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
2913: }
2914: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
2915: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
2916: }
2917: if ($entry) {
1.200 albertel 2918: $result.= "\n\t\t<li>\n\t\t\t$grader :\n\t\t\t $entry \n\t\t</li>";
1.113 albertel 2919: }
2920: }
2921: if ($result) {
1.200 albertel 2922: return "\n\t".'<ul class="LC_GRADING_pastgrading">'.$result.
2923: "\n\t".'</ul>'."\n";
1.113 albertel 2924: }
2925: return '';
2926: }
2927:
1.1 albertel 2928: sub start_IntroParagraph {
1.87 albertel 2929: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 2930: my $result;
1.168 albertel 2931: my $dim = &get_dim_id();
1.153 albertel 2932: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151 albertel 2933: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169 albertel 2934: $dimension{$dim}{'intro'}=
1.151 albertel 2935: &Apache::lonxml::get_all_text('/introparagraph',
2936: $parser,$style);
2937: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2938: &Apache::lonxml::startredirection();
1.1 albertel 2939: }
1.47 albertel 2940:
1.225 albertel 2941: } elsif ($target eq 'edit') {
2942: $result = &Apache::edit::tag_start($target,$token);
2943: } elsif ($target eq 'modified') {
1.1 albertel 2944: }
2945: return $result;
2946: }
2947:
2948: sub end_IntroParagraph {
1.127 albertel 2949: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128 albertel 2950: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2951: my $result = &Apache::lonxml::endredirection();
2952: }
1.1 albertel 2953: }
2954:
1.227 albertel 2955: sub insert_IntroParagraph {
2956: return '
2957: <IntroParagraph>
2958: <startouttext />
2959: <endouttext />
2960: </IntroParagraph>';
2961: }
2962:
1.1 albertel 2963: sub start_Instance {
2964: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 2965: my $dim = &get_dim_id();
2966: my $id = &get_id($parstack,$safeeval);
1.169 albertel 2967: push(@{$dimension{$dim}{'instances'}},$id);
1.168 albertel 2968: push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19 albertel 2969: push(@Apache::bridgetask::instancelist,$id);
1.169 albertel 2970: $dimension{$dim}{$id.'.optionalrequired'}=
1.19 albertel 2971: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75 albertel 2972: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2973: if (lc($disabled) eq 'yes') {
1.169 albertel 2974: $dimension{$dim}{$id.'.disabled'}='1';
1.75 albertel 2975: }
1.225 albertel 2976: my $result;
2977: if ($target eq 'edit') {
2978: $result = &Apache::edit::tag_start($target,$token);
2979: $result.=
2980: &Apache::edit::text_arg('Id:','id',$token,10).' '.
2981: &Apache::edit::select_arg('Instance is Disabled:','Disabled',
2982: [['no', 'No'],
2983: ['yes','Yes'],],
2984: $token)
2985: .' <br /> '.
2986: &Apache::edit::text_arg('Required number of passed optional elements to pass the Instance:',
2987: 'OptionalRequired',$token,4)
2988: .&Apache::edit::end_row().
2989: &Apache::edit::start_spanning_row();
2990: } elsif ($target eq 'modified') {
2991: my $constructtag=
2992: &Apache::edit::get_new_args($token,$parstack,$safeeval,
2993: 'id','OptionalRequired','Disabled');
2994: if ($constructtag) {
2995: $result = &Apache::edit::rebuild_tag($token);
2996: }
2997: }
2998: return $result;
1.1 albertel 2999: }
3000:
3001: sub end_Instance {
1.225 albertel 3002: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
3003: my $result;
3004: if ($target eq 'edit') {
3005: $result = &Apache::edit::tag_end($target,$token);
3006: }
3007: return $result;
1.1 albertel 3008: }
3009:
3010: sub start_InstanceText {
1.87 albertel 3011: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225 albertel 3012: my $result;
1.153 albertel 3013: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.225 albertel 3014: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
3015: my $dim = &get_dim_id();
3016: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 3017: $dimension{$dim}{$instance_id.'.text'}=$text;
1.225 albertel 3018: } elsif ($target eq 'edit') {
3019: $result = &Apache::edit::tag_start($target,$token);
3020: } elsif ($target eq 'modified') {
1.1 albertel 3021: }
1.225 albertel 3022: return $result;
1.1 albertel 3023: }
3024:
3025: sub end_InstanceText {
3026: return '';
3027: }
3028:
1.227 albertel 3029: sub insert_InstanceText {
3030: return '
3031: <InstanceText>
3032: <startouttext />
3033: <endouttext />
3034: </InstanceText>';
3035: }
3036:
1.1 albertel 3037: sub start_Criteria {
1.87 albertel 3038: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.190 albertel 3039: my $result = '';
1.21 albertel 3040: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.225 albertel 3041: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.168 albertel 3042: my $dim = &get_dim_id();
1.19 albertel 3043: my $id=&get_id($parstack,$safeeval);
1.194 albertel 3044: if ($target eq 'web' || $target eq 'webgrade') {
1.208 albertel 3045: if ($target eq 'webgrade') {
1.195 albertel 3046: &Apache::lonxml::debug(" for $dim $id stashing results into $dim ");
3047: $dimension{$dim}{'result'} .= &internal_location($id);
3048: } else {
3049: &Apache::lonxml::debug(" not stashing $dim $id");
1.206 albertel 3050: #$result .= &internal_location($id);
1.195 albertel 3051: }
1.194 albertel 3052: }
1.169 albertel 3053: &Apache::lonxml::debug("Criteria $id with $dim");
1.151 albertel 3054: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168 albertel 3055: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 3056: $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
3057: $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
3058: $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151 albertel 3059: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 3060: push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151 albertel 3061: } else {
1.169 albertel 3062: $dimension{$dim}{'criteria.'.$id}=$criteria;
3063: $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
3064: $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151 albertel 3065: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 3066: push(@{$dimension{$dim}{'criterias'}},$id);
1.194 albertel 3067: }
1.225 albertel 3068: } elsif ($target eq 'edit') {
3069: $result .=&Apache::edit::tag_start($target,$token);
3070: $result.=
3071: &Apache::edit::text_arg('Id:','id',$token,10).' '.
3072: &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233 albertel 3073: [['Y', 'Yes'],
3074: ['N','No'],],
1.225 albertel 3075: $token)
3076: .' <br /> '.&Apache::edit::end_row().
3077: &Apache::edit::start_spanning_row();
3078: } elsif ($target eq 'modified') {
3079: my $constructtag=
3080: &Apache::edit::get_new_args($token,$parstack,$safeeval,
3081: 'id','Mandatory');
3082: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.194 albertel 3083: }
3084: return $result;
3085: }
3086:
3087: sub layout_web_Criteria {
3088: my ($dim,$id,$criteria) = @_;
1.190 albertel 3089:
1.194 albertel 3090: my $version = &get_version();
3091: my $status= &get_criteria('status', $version,$dim,$id);
3092: my $comment=&get_criteria('comment',$version,$dim,$id);
3093: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
3094: if ($mandatory) {
3095: $mandatory='Mandatory';
3096: } else {
3097: $mandatory='Optional';
1.1 albertel 3098: }
1.194 albertel 3099: my $status_display=$status;
3100: $status_display=~s/^([a-z])/uc($1)/e;
3101: my $criteria_info.=
1.200 albertel 3102: '<div class="LC_'.$status.' LC_criteria">'."\n\t".'<h4>'
1.204 albertel 3103: .$mandatory.' Criteria</h4>'."\n\t".'<p class="LC_criteria_text">'
3104: ."\n";
1.202 albertel 3105: $criteria =~ s/^\s*//s;
3106: $criteria =~ s/\s*$//s;
1.194 albertel 3107: $criteria_info.= $criteria;
1.200 albertel 3108: $criteria_info.="\n\t".'</p>'.
3109: "\n\t".'<p class="LC_grade">'.$status_display.'</p>';
1.194 albertel 3110: if ($comment =~ /\w/) {
1.200 albertel 3111: $criteria_info.=
3112: "\n\t".
3113: '<p class="LC_comment">'.&mt('Comment: [_1]',$comment).'</p>';
1.194 albertel 3114: }
1.200 albertel 3115: $criteria_info.="\n".'</div>'."\n";
3116:
1.194 albertel 3117: return $criteria_info;
3118: }
3119:
3120: sub layout_webgrade_Criteria {
3121: my ($dim,$id,$criteria) = @_;
3122: my $link=&link($id);
3123: my $version = &get_version();
3124: my $status = &get_criteria('status',$version,$dim,$id);
1.245 bisitz 3125: my %lt = &Apache::lonlocal::texthash(
3126: 'ungraded' => 'Ungraded',
3127: 'fail' => 'Fail',
3128: 'pass' => 'Pass',
3129: 'review' => 'Review',
3130: 'comment' => 'Additional Comment for Student',
3131: );
1.200 albertel 3132: my $comment = &get_criteria('comment',$version,$dim,$id);
3133: $comment = &HTML::Entities::encode($comment,'<>"&');
3134: my %checked;
3135: foreach my $which ('ungraded','fail','pass','review') {
1.249 bisitz 3136: if ($status eq $which) { $checked{$which} = ' checked="checked"'; }
1.200 albertel 3137: }
1.249 bisitz 3138: if (!%checked) { $checked{'ungraded'} = ' checked="checked"'; }
1.201 albertel 3139: my $buttons;
3140: foreach my $which ('ungraded','fail','pass','review') {
3141: $buttons .= <<END_BUTTON;
3142: <label class="LC_GRADING_$which">
1.249 bisitz 3143: <input type="radio" name="HWVAL_$link" value="$which"$checked{$which} />
1.201 albertel 3144: $lt{$which}
3145: </label>
3146: END_BUTTON
3147: }
1.202 albertel 3148: $criteria =~ s/^\s*//s;
3149: $criteria =~ s/\s*$//s;
1.200 albertel 3150: my $result = <<END_CRITERIA;
1.201 albertel 3151: <div class="LC_GRADING_criteria">
3152: <div class="LC_GRADING_criteriatext">
3153: $criteria
3154: </div>
3155: <div class="LC_GRADING_grade">
3156: $buttons
3157: </div>
3158: <label class="LC_GRADING_comment">
3159: $lt{'comment'}
3160: <textarea class="LC_GRADING_comment_area" name="HWVAL_comment_$link">$comment</textarea>
3161: </label>
3162: </div>
1.200 albertel 3163: END_CRITERIA
3164: $result .= &grading_history($version,$dim,$id);
1.190 albertel 3165: return $result;
1.1 albertel 3166: }
3167:
1.47 albertel 3168: sub end_Criteria {
1.225 albertel 3169: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
3170: if ($target eq 'edit') {
3171: } elsif ($target eq 'modified') {
3172: }
3173: }
1.227 albertel 3174: sub insert_Criteria {
3175: return '
3176: <Criteria>
3177: <CriteriaText>
3178: <startouttext />
3179: <endouttext />
3180: </CriteriaText>
3181: </Criteria>';
3182: }
1.225 albertel 3183:
3184: sub start_CriteriaText {
3185: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
3186: my $result;
3187: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
3188:
3189: } elsif ($target eq 'edit') {
3190: $result = &Apache::edit::tag_start($target,$token);
3191: } elsif ($target eq 'modified') {
3192: }
3193: return $result;
3194: }
3195:
3196: sub end_CriteriaText {
3197: return '';
1.47 albertel 3198: }
3199:
1.227 albertel 3200: sub insert_CriteriaText {
3201: return '
3202: <CriteriaText>
3203: <startouttext />
3204: <endouttext />
3205: </CriteriaText>';
3206: }
3207:
1.186 albertel 3208: sub start_GraderNote {
3209: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225 albertel 3210: my $result;
1.186 albertel 3211: if ($target eq 'webgrade') {
1.225 albertel 3212: $result = '<div class="LC_GRADING_gradernote"><b>'.
1.187 albertel 3213: &mt('Note to graders:').'</b>';
1.225 albertel 3214: } elsif ($target eq 'edit') {
3215: $result = &Apache::edit::tag_start($target,$token);
3216: } elsif ($target eq 'modified') {
3217: } elsif ($target eq 'web' || $target eq 'grade') {
3218: my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style);
1.186 albertel 3219: }
1.225 albertel 3220: return $result;
1.186 albertel 3221: }
3222:
3223: sub end_GraderNote {
3224: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
3225:
3226: if ($target eq 'webgrade') {
3227: return '</div>';
3228: }
3229: return;
3230: }
3231:
1.227 albertel 3232: sub insert_GraderNote {
3233: return '
3234: <GraderNote>
3235: <startouttext />
3236: <endouttext />
3237: </GraderNote>';
3238: }
1.186 albertel 3239:
3240:
1.4 albertel 3241: sub proctor_validation_screen {
3242: my ($slot) = @_;
1.185 albertel 3243: my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
1.5 albertel 3244: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.230 albertel 3245: if ($url ne '/adm/lonKaputt/lonlogo_broken.gif') {
3246: $url = "<tr><td colspan=\"2\"><img src=\"$url\" /></td></tr>";
3247: } else {
3248: undef($url);
3249: }
3250:
1.44 albertel 3251: my $name=&Apache::loncommon::plainname($user,$domain);
3252:
1.4 albertel 3253: my $msg;
1.11 albertel 3254: if ($env{'form.proctorpassword'}) {
1.230 albertel 3255: $msg.='<p><span class="LC_warning">'
3256: .&mt("Failed to authenticate the proctor.")
3257: .'</span></p>';
1.4 albertel 3258: }
1.230 albertel 3259:
3260: my $valid;
3261: my @possible_proctors=split(",",$slot->{'proctor'});
3262: foreach my $proctor (@possible_proctors) {
3263: if ($proctor =~ /$LONCAPA::username_re:$LONCAPA::domain_re/) {
3264: $valid = 1;
3265: last;
3266: }
3267: }
3268: if (!$valid) {
3269: $msg.='<p><span class="LC_error">'
1.239 bisitz 3270: .&mt("No valid proctors are defined.")
1.230 albertel 3271: .'</span></p>';
3272: }
3273:
1.47 albertel 3274: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.229 albertel 3275: my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
3276: $uri = &HTML::Entities::encode($uri,'<>&"');
1.241 raeburn 3277: my %lt = &Apache::lonlocal::texthash(
3278: 'prva' => "Proctor Validation",
3279: 'yoro' => "Your room's proctor needs to validate your access to this resource.",
3280: 'prus' => "Proctor's Username:",
3281: 'pasw' => "Password:",
3282: 'prdo' => "Proctor's Domain:",
3283: 'vali' => 'Validate',
3284: 'stui' => "Student who should be logged in is:",
3285: 'name' => "Name:",
1.251 raeburn 3286: 'sid' => "Student/Employee ID",
1.241 raeburn 3287: 'unam' => "Username:",
3288: );
1.4 albertel 3289: my $result= (<<ENDCHECKOUT);
1.241 raeburn 3290: <h2>$lt{'prva'}</h2>
3291: <p>$lt{'yoro'}</p>
1.4 albertel 3292: $msg
1.229 albertel 3293: <form name="checkout" method="post" action="$uri">
1.4 albertel 3294: <input type="hidden" name="validate" value="yes" />
3295: <input type="hidden" name="submitted" value="yes" />
3296: <table>
1.264.8.1.2.2 (raeburn 3297:: <tr><td>$lt{'prus'}</td><td><input type="text" name="proctorname" value="$env{'form.proctorname'}" autocomplete="new-password" /></td></tr>
3298:: <tr><td>$lt{'pasw'}</td><td><input type="password" name="proctorpassword" value="" autocomplete="new-password" /></td></tr>
3299:: <tr><td>$lt{'prdo'}</td><td><input type="text" name="proctordomain" value="$env{'form.proctordomain'}" autocomplete="off" /></td></tr>
1.4 albertel 3300: </table>
1.241 raeburn 3301: <input type="submit" name="checkoutbutton" value="$lt{'vali'}" /><br />
1.44 albertel 3302: <table border="1">
3303: <tr><td>
3304: <table>
1.241 raeburn 3305: <tr><td colspan="2">$lt{'stui'}</td></tr>
3306: <tr><td>$lt{'name'}</td><td>$name</td></tr>
3307: <tr><td>$lt{'sid'}</td><td>$env{'environment.id'}</td></tr>
3308: <tr><td>$lt{'unam'}</td><td>$user:$domain</td></tr>
1.230 albertel 3309: $url
1.44 albertel 3310: </table>
3311: </tr></td>
3312: </table>
1.4 albertel 3313: </form>
3314: ENDCHECKOUT
1.241 raeburn 3315:
1.4 albertel 3316: return $result;
3317: }
3318:
1.1 albertel 3319: 1;
3320: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>