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