Annotation of loncom/homework/bridgetask.pm, revision 1.199
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.199 ! albertel 4: # $Id: bridgetask.pm,v 1.198 2006/11/09 20:20:18 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.199 ! albertel 1012: }
! 1013:
! 1014: $result.='</form>';
! 1015:
! 1016: if (!$previous && $status ne 'SHOW_ANSWER' &&
! 1017: &show_task($status,$previous)) {
1.116 albertel 1018: my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.64 albertel 1019: $result.=<<DONEBUTTON;
1.115 albertel 1020: <form name="done" method="post" action="$action">
1.64 albertel 1021: <input type="hidden" name="donescreen" value="1" />
1022: <input type="submit" value="Done" />
1023: </form>
1024: DONEBUTTON
1.77 albertel 1025: }
1.56 albertel 1026: if (&show_task($status,$previous) &&
1.89 albertel 1027: $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
1028: my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.54 albertel 1029: my $title=&Apache::lonnet::gettitle();
1.80 albertel 1030:
1.149 albertel 1031: my $start_time;
1032:
1.80 albertel 1033: my $slot_name=
1.89 albertel 1034: $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149 albertel 1035: if ($slot_name) {
1036: my %slot=&Apache::lonnet::get_slot($slot_name);
1037:
1038: $start_time=$slot{'starttime'}
1039: } else {
1040: $start_time=
1041: &Apache::lonnet::EXT('resource.0.opendate');
1042: }
1043: $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54 albertel 1044:
1.116 albertel 1045: my $status = "\n<div class='LC_$bt_status LC_criteria'>\n";
1.54 albertel 1046:
1047: if ($bt_status eq 'pass') {
1048: $status.='<h2>You passed the '.$title.' given on '.
1.80 albertel 1049: $start_time.'</h2>';
1.54 albertel 1050: }
1051: if ($bt_status eq 'fail') {
1052: $status.='<h2>You did not pass the '.$title.' given on '.
1.80 albertel 1053: $start_time.'</h2>';
1.54 albertel 1054: if (!$previous) {
1055: $status.=&add_request_another_attempt_button();
1056: }
1057: }
1.194 albertel 1058: $status.='</div>';
1059: my $dim = $top;
1.197 albertel 1060: my %counts = &get_counts($dim,undef,$parstack,
1061: $safeeval);
1062: $status.="\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'><p>".
1.198 albertel 1063: &question_status_message(\%counts,-1).
1064: "</p></div>\n";
1.197 albertel 1065:
1.194 albertel 1066:
1067: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1068: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1069: if ($type eq 'dimension') {
1070: $result.=$dimension{$id}{'result'};
1071: next;
1072: }
1073: my $criteria =
1074: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
1075: [@_]);
1076: $status .= &layout_web_Criteria($dim,$id,$criteria);
1077: }
1.54 albertel 1078:
1079: my $internal_location=&internal_location();
1080: $result=~s/\Q$internal_location\E/$status/;
1081: }
1.142 albertel 1082: $result.="\n</div>\n".
1083: &Apache::loncommon::end_page({'discussion' => 1});
1.1 albertel 1084: }
1085: }
1.181 albertel 1086:
1087: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
1088: my %queue_data = ('type' => 'Task',
1089: 'time' => time,);
1090: if (defined($Apache::inputtags::slot_name)) {
1091: $queue_data{'slot'} = $Apache::inputtags::slot_name;
1092: } elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) {
1093: $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1094: }
1095:
1096:
1.29 albertel 1097: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) {
1.12 albertel 1098: my $award='SUBMITTED';
1.28 albertel 1099: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 1100: 'portfiles',\$award);
1.14 albertel 1101: if ($award eq 'SUBMITTED' &&
1.28 albertel 1102: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
1103: $Apache::lonhomework::results{"resource.0.tries"}=
1104: $Apache::lonhomework::results{"resource.$version.0.tries"}=
1105: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
1106:
1107: $Apache::lonhomework::results{"resource.0.award"}=
1108: $Apache::lonhomework::results{"resource.$version.0.award"}=
1109: $award;
1.51 albertel 1110: $Apache::lonhomework::results{"resource.0.submission"}=
1111: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64 albertel 1112: } else {
1113: delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1.77 albertel 1114: $award = '';
1.10 albertel 1115: }
1.4 albertel 1116: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1117: &Apache::structuretags::finalize_storage();
1.148 albertel 1118: if ($award eq 'SUBMITTED') {
1.181 albertel 1119: &add_to_queue('gradingqueue',\%queue_data);
1.14 albertel 1120: }
1.1 albertel 1121: }
1.163 albertel 1122: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1123: && exists($env{'form.cancel'})) {
1124: &check_queue_unlock($env{'form.queue'});
1125: &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
1126: } elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1127: && !exists($env{'form.cancel'})) {
1.20 albertel 1128: my $optional_required=
1129: &Apache::lonxml::get_param('OptionalRequired',$parstack,
1130: $safeeval);
1131: my $optional_passed=0;
1132: my $mandatory_failed=0;
1133: my $ungraded=0;
1134: my $review=0;
1.21 albertel 1135: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.194 albertel 1136: my $dim = $top;
1137: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1138: my $link=&link($id);
1139:
1140: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1141:
1142: if ($type eq 'criteria') {
1143: # dimensional 'criteria' don't get assigned grades
1144: $Apache::lonhomework::results{"resource.$version.0.$id.status"}=$env{'form.HWVAL_'.$link};
1145: $Apache::lonhomework::results{"resource.$version.0.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1146: }
1.20 albertel 1147: my $status=
1.194 albertel 1148: $Apache::lonhomework::results{"resource.$version.0.$id.status"};
1149: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1150:
1.20 albertel 1151: if ($status eq 'pass') {
1152: if (!$mandatory) { $optional_passed++; }
1153: } elsif ($status eq 'fail') {
1154: if ($mandatory) { $mandatory_failed++; }
1.194 albertel 1155: } elsif ($status eq 'review') {
1156: $review++;
1.20 albertel 1157: } elsif ($status eq 'ungraded') {
1158: $ungraded++;
1.49 albertel 1159: } else {
1160: $ungraded++;
1161: }
1.20 albertel 1162: }
1163: if ($optional_passed < $optional_required) {
1164: $mandatory_failed++;
1165: }
1.194 albertel 1166: &Apache::lonxml::debug(" task results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89 albertel 1167: $Apache::lonhomework::results{'resource.0.regrader'}=
1.138 albertel 1168: $env{'user.name'}.':'.$env{'user.domain'};
1.20 albertel 1169: if ($review) {
1.89 albertel 1170: $Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.20 albertel 1171: } elsif ($ungraded) {
1.89 albertel 1172: $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.20 albertel 1173: } elsif ($mandatory_failed) {
1.89 albertel 1174: $Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25 albertel 1175: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
1176: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
1177: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.185 albertel 1178: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1179:
1180: if ($env{'form.regrade'} ne 'yes') {
1181: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1182: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1183: &Apache::grades::version_portfiles(
1184: \%Apache::lonhomework::results,
1185: ["$version.0.bridgetask"],$courseid,
1186: $symb,$udom,$uname,
1187: ["$version.0.bridgetask"]);
1188: }
1.20 albertel 1189: } else {
1.89 albertel 1190: $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25 albertel 1191: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
1192: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
1193: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.185 albertel 1194: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1195: if ($env{'form.regrade'} ne 'yes') {
1196: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1197: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1198: &Apache::grades::version_portfiles(
1199: \%Apache::lonhomework::results,
1200: ["$version.0.bridgetask"],$courseid,
1201: $symb,$udom,$uname,
1202: ["$version.0.bridgetask"]);
1203: }
1.20 albertel 1204: }
1.89 albertel 1205: $Apache::lonhomework::results{"resource.0.status"}=
1206: $Apache::lonhomework::results{"resource.$version.0.status"};
1.28 albertel 1207: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 1208: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 1209: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 1210: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 1211: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 1212: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 1213: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 1214: }
1.94 albertel 1215: &minimize_storage();
1.21 albertel 1216: &Apache::structuretags::finalize_storage();
1.188 albertel 1217:
1218: # data stored, now handle queue
1219: if ($review) {
1220: if ($env{'form.queue'} eq 'reviewqueue') {
1221: &check_queue_unlock($env{'form.queue'});
1222: &Apache::lonxml::debug(" still needs review not changing status.");
1223: } else {
1224: if ($env{'form.queue'} ne 'none') {
1225: &move_between_queues($env{'form.queue'},'reviewqueue');
1226: } else {
1227: &add_to_queue('reviewqueue',\%queue_data);
1228: }
1229: }
1230: } elsif ($ungraded) {
1231: if ($env{'form.queue'} eq 'reviewqueue') {
1232: &Apache::lonxml::debug("moving back.");
1233: &move_between_queues($env{'form.queue'},
1234: 'gradingqueue');
1235: } elsif ($env{'form.queue'} eq 'none' ) {
1236: &add_to_queue('gradingqueue',\%queue_data);
1237: } else {
1238: &check_queue_unlock($env{'form.queue'});
1239: }
1240: } elsif ($mandatory_failed) {
1241: &remove_from_queue($env{'form.queue'});
1242: } else {
1243: &remove_from_queue($env{'form.queue'});
1244: }
1.20 albertel 1245: }
1.184 albertel 1246: if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
1247: # instance generation occured and hasn't yet been stored
1248: &Apache::structuretags::finalize_storage();
1249: }
1.15 albertel 1250: } elsif ($target eq 'webgrade') {
1.194 albertel 1251: $result.=&Apache::lonxml::endredirection();
1252: my $dim = $top;
1253: foreach my $id (@{$dimension{$dim}{'criterias'}} ) {
1254: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1255: if ($type eq 'dimension') {
1256: # dimensional 'criteria' don't get assigned grades
1257: next;
1258: } else {
1259: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
1260: [@_]);
1261: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
1262: my $internal_location=&internal_location($id);
1263: $result=~s/\Q$internal_location\E/$criteria/;
1264: }
1265: }
1266: $result.="</div>";
1.20 albertel 1267: #$result.='<input type="submit" name="next" value="'.
1268: # &mt('Save & Next').'" /> ';
1269: #$result.='<input type="submit" name="end" value="'.
1270: # &mt('Save & Stop Grading').'" /> ';
1271: #$result.='<input type="submit" name="throwaway" value="'.
1272: # &mt('Throw Away & Stop Grading').'" /> ';
1273: #$result.='<input type="submit" name="save" value="'.
1274: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124 albertel 1275: $result.='</form>'."\n</div>\n</div>\n".
1.140 albertel 1276: &Apache::loncommon::end_page();
1.1 albertel 1277: } elsif ($target eq 'meta') {
1.70 albertel 1278: $result.=&Apache::response::meta_package_write('Task');
1.77 albertel 1279: $result.=&Apache::response::meta_stores_write('solved','string',
1280: 'Problem Status');
1281: $result.=&Apache::response::meta_stores_write('tries','int_zeropos',
1282: 'Number of Attempts');
1283: $result.=&Apache::response::meta_stores_write('awarded','float',
1284: 'Partial Credit Factor');
1285: $result.=&Apache::response::meta_stores_write('status','string',
1286: 'Bridge Task Status');
1.182 albertel 1287: } elsif ($target eq 'edit') {
1288: &Apache::structuretags::reset_problem_globals('Task');
1289: undef($Apache::lonhomework::parsing_a_task);
1290: return ('','no');
1.1 albertel 1291: }
1.179 albertel 1292: &Apache::structuretags::reset_problem_globals('Task');
1.4 albertel 1293: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 1294: return $result;
1295: }
1296:
1.31 albertel 1297: sub move_between_queues {
1298: my ($src_queue,$dest_queue)=@_;
1.49 albertel 1299: my $cur_data;
1300: if ($src_queue ne 'none') {
1301: $cur_data=&get_queue_data($src_queue);
1302: if (!$cur_data) { return 'not_exist'; }
1303: } else {
1304: $cur_data = ['none'];
1305: }
1.148 albertel 1306: my $result=&add_to_queue($dest_queue,$cur_data);
1.31 albertel 1307: if ($result ne 'ok') {
1308: return $result;
1309: }
1310: &check_queue_unlock($src_queue);
1311: return &remove_from_queue($src_queue);
1.21 albertel 1312: }
1313:
1314: sub check_queue_unlock {
1.32 albertel 1315: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 1316: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1317: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.32 albertel 1318: if (!defined($key)) {
1.138 albertel 1319: $key="$symb\0queue\0$uname:$udom";
1.32 albertel 1320: }
1.30 albertel 1321: my $cnum=$env{'course.'.$cid.'.num'};
1322: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1323: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30 albertel 1324: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1325: if ($who eq $me) {
1.163 albertel 1326: &Apache::lonxml::debug("unlocking my own $who");
1.32 albertel 1327: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1328: } elsif ($allow_not_me) {
1.33 albertel 1329: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 1330: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 1331: }
1.32 albertel 1332: return 'not_owner';
1.21 albertel 1333: }
1334:
1.88 albertel 1335: sub in_queue {
1336: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1337: if ($queue eq 'none') { return 0; }
1338: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1339: || !defined($udom) || !defined($uname)) {
1.185 albertel 1340: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.88 albertel 1341: $cnum=$env{'course.'.$cid.'.num'};
1342: $cdom=$env{'course.'.$cid.'.domain'};
1343: }
1344:
1345: my $key=&encode_queue_key($symb,$udom,$uname);
1346: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1347:
1348: if (defined($results{$key})) {
1349: return 1;
1350: }
1351: return 0;
1352: }
1353:
1.21 albertel 1354: sub remove_from_queue {
1.86 albertel 1355: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49 albertel 1356: if ($queue eq 'none') { return 'ok'; }
1.86 albertel 1357: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1358: || !defined($udom) || !defined($uname)) {
1.185 albertel 1359: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.86 albertel 1360: $cnum=$env{'course.'.$cid.'.num'};
1361: $cdom=$env{'course.'.$cid.'.domain'};
1362: }
1.88 albertel 1363: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1364: return 'ok';
1365: }
1.86 albertel 1366: my $key=&encode_queue_key($symb,$udom,$uname);
1.27 albertel 1367: my @keys=($key,"$key\0locked");
1.31 albertel 1368: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 1369: }
1370:
1.16 albertel 1371: sub setup_env_for_other_user {
1372: my ($queue_key,$safeeval)=@_;
1373: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 1374: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 1375: $env{'form.grade_symb'}=$symb;
1376: $env{'form.grade_domain'}=$udom;
1377: $env{'form.grade_username'}=$uname;
1378: $env{'form.grade_courseid'}=$env{'request.course.id'};
1379: &Apache::lonxml::initialize_rndseed($safeeval);
1380: }
1381:
1.31 albertel 1382: sub get_queue_data {
1.165 albertel 1383: my ($queue,$udom,$uname)=@_;
1.185 albertel 1384: my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1.165 albertel 1385: if (!$uname || !$udom) {
1386: $uname=$other_uname;
1387: $udom =$other_udom;
1388: }
1.31 albertel 1389: my $cnum=$env{'course.'.$cid.'.num'};
1390: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1391: my $todo="$symb\0queue\0$uname:$udom";
1.31 albertel 1392: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1393: if ($key eq $todo && ref($value)) {
1394: return $value;
1395: }
1396: return undef;
1397: }
1398:
1.84 albertel 1399:
1.49 albertel 1400: sub check_queue_for_key {
1.84 albertel 1401: my ($cdom,$cnum,$queue,$todo)=@_;
1402:
1.49 albertel 1403: my %results=
1404: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1405:
1406: if (exists($results{$todo}) && ref($results{$todo})) {
1407: if (defined($results{"$todo\0locked"})) {
1408: return 'locked';
1409: }
1.148 albertel 1410: if (my $slot=&slotted_access($results{$todo})) {
1.86 albertel 1411: my %slot_data=&Apache::lonnet::get_slot($slot);
1412: if ($slot_data{'endtime'} > time) {
1413: return 'in_progress';
1414: }
1.148 albertel 1415: } else {
1416: my ($symb) = &decode_queue_key($todo);
1417: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1418: if ($due_date > time) {
1419: return 'in_progress';
1420: }
1.58 albertel 1421: }
1.49 albertel 1422: return 'enqueued';
1423: }
1424: return undef;
1425: }
1426:
1.14 albertel 1427: sub add_to_queue {
1.82 albertel 1428: my ($queue,$user_data)=@_;
1.49 albertel 1429: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1430: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.82 albertel 1431: if (!$cid || $env{'request.state'} eq 'construct') {
1432: return 'no_queue';
1433: }
1.14 albertel 1434: my $cnum=$env{'course.'.$cid.'.num'};
1435: my $cdom=$env{'course.'.$cid.'.domain'};
1436: my %data;
1.138 albertel 1437: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83 albertel 1438: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14 albertel 1439: }
1440:
1.156 albertel 1441: sub get_limited_classlist {
1442: my ($sections) = @_;
1443:
1444: my $classlist = &Apache::loncoursedata::get_classlist();
1.157 albertel 1445: foreach my $student (keys(%$classlist)) {
1446: if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
1447: ne 'Active') {
1448: delete($classlist->{$student});
1449: }
1450: }
1.156 albertel 1451:
1.157 albertel 1452: if (ref($sections) && !grep('all',@{ $sections })) {
1.156 albertel 1453: foreach my $student (keys(%$classlist)) {
1454: my $section =
1455: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1456: if (! grep($section,@{ $sections })) {
1457: delete($classlist->{$student});
1458: }
1459: }
1460: }
1461: return $classlist;
1462: }
1463:
1464:
1.14 albertel 1465: sub show_queue {
1.32 albertel 1466: my ($queue,$with_selects)=@_;
1.14 albertel 1467: my $result;
1.185 albertel 1468: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 1469: my $cnum=$env{'course.'.$cid.'.num'};
1470: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 1471:
1472: my @chosen_sections=
1473: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1474:
1475: my $classlist = &get_limited_classlist(\@chosen_sections);
1476:
1.63 albertel 1477: if (!(grep(/^all$/,@chosen_sections))) {
1478: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1479: '</tt>.</p> '."\n";
1480: }
1.59 albertel 1481:
1.156 albertel 1482: my ($view,$view_section);
1483: my $scope = $env{'request.course.id'};
1484: if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
1485: $scope .= '/'.$env{'request.course.sec'};
1486: if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
1487: $view_section=$env{'request.course.sec'};
1488: } else {
1489: undef($view);
1490: }
1491: }
1492:
1.16 albertel 1493: my $regexp="^$symb\0";
1.30 albertel 1494: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 1495: my ($tmp)=%queue;
1496: if ($tmp=~/^error: 2 /) {
1.159 albertel 1497: return "\n<h3>Current Queue - $queue</h3>".
1498: &Apache::loncommon::start_data_table().
1499: &Apache::loncommon::start_data_table_row().
1500: '<td>'.&mt('Empty').'</td>'.
1501: &Apache::loncommon::end_data_table_row().
1502: &Apache::loncommon::end_data_table();
1.31 albertel 1503: }
1.103 albertel 1504: my $title=&Apache::lonnet::gettitle($symb);
1.159 albertel 1505: $result.="\n<h3>Current Queue - $title $queue </h3>".
1506: &Apache::loncommon::start_data_table().
1507: &Apache::loncommon::start_data_table_header_row();
1.103 albertel 1508: if ($with_selects) { $result.="<th>Status</th><th></th>"; }
1.159 albertel 1509: $result.="<th>user</th><th>data</th>".
1510: &Apache::loncommon::end_data_table_header_row();
1.14 albertel 1511: foreach my $key (sort(keys(%queue))) {
1.59 albertel 1512: my ($symb,$uname,$udom) = &decode_queue_key($key);
1513: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.156 albertel 1514:
1515: my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1516:
1517: my $can_view=1;
1518: if (!$view
1519: || ($view_section && !$section)
1520: || ($view_section && $section && ($view_section ne $section))) {
1521: $can_view=0;
1522: }
1523:
1.32 albertel 1524: if ($key=~/locked$/ && !$with_selects) {
1.159 albertel 1525: $result.= &Apache::loncommon::start_data_table_row().
1526: "<td>$uname</td>";
1.103 albertel 1527: $result.='<td>'.$queue{$key}.'</td></tr>';
1.32 albertel 1528: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.159 albertel 1529: $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103 albertel 1530: $result.='<td>'.
1.16 albertel 1531: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 1532: } elsif ($key!~/(timestamp|locked)$/) {
1.159 albertel 1533: $result.= &Apache::loncommon::start_data_table_row();
1.148 albertel 1534: my ($end_time,$slot_text);
1535: if (my $slot=&slotted_access($queue{$key})) {
1536: my %slot_data=&Apache::lonnet::get_slot($slot);
1537: $end_time = $slot_data{'endtime'};
1538: $slot_text = &mt('Slot: [_1]',$slot);
1539: } else {
1540: $end_time = &Apache::lonhomework::due_date('0',$symb);
1541: $slot_text = '';
1542: }
1.32 albertel 1543: if ($with_selects) {
1.158 www 1544: my $ekey=&escape($key);
1.103 albertel 1545: my ($action,$description,$status)=('select',&mt('Select'));
1.32 albertel 1546: if (exists($queue{"$key\0locked"})) {
1.138 albertel 1547: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.103 albertel 1548: $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1.32 albertel 1549: if ($me eq $queue{"$key\0locked"}) {
1550: ($action,$description)=('resume',&mt('Resume'));
1551: } else {
1552: ($action,$description)=('unlock',&mt('Unlock'));
1553: }
1554: }
1.62 albertel 1555: my $seclist;
1556: foreach my $sec (@chosen_sections) {
1557: $seclist.='<input type="hidden" name="chosensections"
1558: value="'.$sec.'" />';
1559: }
1.156 albertel 1560: if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35 albertel 1561: $result.=(<<FORM);
1.103 albertel 1562: <td>$status</td>
1.32 albertel 1563: <td>
1.115 albertel 1564: <form style="display: inline" method="post">
1.32 albertel 1565: <input type="hidden" name="gradingkey" value="$ekey" />
1566: <input type="hidden" name="queue" value="$queue" />
1567: <input type="hidden" name="gradingaction" value="$action" />
1568: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 1569: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 1570: <input type="submit" name="submit" value="$description" />
1.62 albertel 1571: $seclist
1.32 albertel 1572: </form>
1573: </td>
1574: FORM
1.156 albertel 1575: } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
1576: $result.='<td>'.&mt("Not gradable").'</td><td> </td>'
1.35 albertel 1577: } else {
1.148 albertel 1578: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1.35 albertel 1579: }
1.32 albertel 1580: }
1.156 albertel 1581: $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138 albertel 1582: " <tt>($uname:$udom)</tt> </td>";
1.148 albertel 1583: $result.='<td>'.$slot_text.' End time: '.
1584: &Apache::lonlocal::locallocaltime($end_time).
1.159 albertel 1585: "</td>".&Apache::loncommon::end_data_table_row();
1.16 albertel 1586: }
1.14 albertel 1587: }
1.159 albertel 1588: $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14 albertel 1589: return $result;
1590: }
1591:
1.34 albertel 1592: sub get_queue_counts {
1593: my ($queue)=@_;
1594: my $result;
1.185 albertel 1595: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.34 albertel 1596: my $cnum=$env{'course.'.$cid.'.num'};
1597: my $cdom=$env{'course.'.$cid.'.domain'};
1.156 albertel 1598:
1.157 albertel 1599: my $classlist=&get_limited_classlist();
1.156 albertel 1600:
1.34 albertel 1601: my $regexp="^$symb\0";
1602: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1603: my ($tmp)=%queue;
1604: if ($tmp=~/^error: 2 /) {
1605: return (0,0,0);
1606: }
1607: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96 albertel 1608: my %slot_cache;
1.34 albertel 1609: foreach my $key (sort(keys(%queue))) {
1.156 albertel 1610: my ($symb,$uname,$udom) = &decode_queue_key($key);
1611: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.34 albertel 1612: if ($key=~/locked$/) {
1613: $locks++;
1614: } elsif ($key=~/timestamp$/) {
1615: #ignore
1616: } elsif ($key!~/(timestamp|locked)$/) {
1617: $entries++;
1.148 albertel 1618: if (my $slot=&slotted_access($queue{$key})) {
1619: if (!exists($slot_cache{$slot})) {
1620: my %slot_data=&Apache::lonnet::get_slot($slot);
1621: $slot_cache{$slot} = \%slot_data;
1622: }
1623: if (time > $slot_cache{$slot}{'endtime'}) {
1624: $ready_to_grade++;
1625: }
1626: } else {
1627: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1628: if ($due_date ne '' && time > $due_date) {
1629: $ready_to_grade++;
1630: }
1.34 albertel 1631: }
1632: }
1633: }
1634: return ($entries,$ready_to_grade,$locks);
1635: }
1636:
1.49 albertel 1637: sub encode_queue_key {
1638: my ($symb,$udom,$uname)=@_;
1.138 albertel 1639: return "$symb\0queue\0$uname:$udom";
1.49 albertel 1640: }
1641:
1.14 albertel 1642: sub decode_queue_key {
1643: my ($key)=@_;
1644: my ($symb,undef,$user) = split("\0",$key);
1.138 albertel 1645: my ($uname,$udom) = split(':',$user);
1.14 albertel 1646: return ($symb,$uname,$udom);
1647: }
1648:
1649: sub queue_key_locked {
1.30 albertel 1650: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1651: if (!defined($cdom) || !defined($cnum)) {
1.185 albertel 1652: my (undef,$cid)=&Apache::lonnet::whichuser();
1.33 albertel 1653: $cnum=$env{'course.'.$cid.'.num'};
1654: $cdom=$env{'course.'.$cid.'.domain'};
1655: }
1.14 albertel 1656: my ($key_locked,$value)=
1.30 albertel 1657: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1658: if ($key_locked eq "$key\0locked") {
1659: return $value;
1660: }
1661: return undef;
1662: }
1663:
1.148 albertel 1664: sub slotted_access {
1665: my ($queue_entry) = @_;
1666: if (ref($queue_entry) eq 'ARRAY') {
1667: if (defined($queue_entry->[0])) {
1668: return $queue_entry->[0];
1669: }
1670: return undef;
1671: } elsif (ref($queue_entry) eq 'HASH') {
1672: if (defined($queue_entry->{'slot'})) {
1673: return $queue_entry->{'slot'};
1674: }
1675: return undef;
1676: }
1677: return undef;
1678: }
1679:
1.14 albertel 1680: sub pick_from_queue_data {
1.156 albertel 1681: my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98 albertel 1682: my @possible; # will hold queue entries that are valid to be selected
1.30 albertel 1683: foreach my $key (keys(%$queuedata)) {
1.68 albertel 1684: if ($key =~ /\0locked$/) { next; }
1685: if ($key =~ /\0timestamp$/) { next; }
1.156 albertel 1686:
1.14 albertel 1687: my ($symb,$uname,$udom)=&decode_queue_key($key);
1.156 albertel 1688: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1689:
1.14 albertel 1690: if ($check_section) {
1.156 albertel 1691: my $section =
1692: $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17 albertel 1693: if ($section eq $check_section) {
1.33 albertel 1694: &Apache::lonxml::debug("my sec");
1.15 albertel 1695: next;
1696: }
1.14 albertel 1697: }
1.148 albertel 1698: my $end_time;
1699: if (my $slot=&slotted_access($queuedata->{$key})) {
1.154 albertel 1700: &Apache::lonxml::debug("looking at slot $slot");
1.148 albertel 1701: my %slot_data=&Apache::lonnet::get_slot($slot);
1702: if ($slot_data{'endtime'} < time) {
1703: $end_time = $slot_data{'endtime'};
1.154 albertel 1704: } else {
1705: &Apache::lonxml::debug("not time ".$slot_data{'endtime'});
1706: next;
1.148 albertel 1707: }
1708: } else {
1709: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154 albertel 1710: if ($due_date < time) {
1.148 albertel 1711: $end_time = $due_date;
1.154 albertel 1712: } else {
1713: &Apache::lonxml::debug("not time $due_date");
1714: next;
1.148 albertel 1715: }
1716: }
1717:
1.98 albertel 1718: if (exists($queuedata->{"$key\0locked"})) {
1.33 albertel 1719: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1720: next;
1721: }
1.148 albertel 1722: push(@possible,[$key,$end_time]);
1.98 albertel 1723: }
1724: if (@possible) {
1725: # sort entries in order by slot end time
1726: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137 albertel 1727: # pick one of the entries in the top 10% in small queues and one
1728: # of the first ten entries in large queues
1.139 albertel 1729: #my $ten_percent = int($#possible * 0.1);
1730: #if ($ten_percent < 1 ) { $ten_percent = 1; }
1731: #if ($ten_percent > 10) { $ten_percent = 10; }
1732: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137 albertel 1733:
1.139 albertel 1734: #return $possible[int(rand($max))][0];
1735: return $possible[0][0];
1.14 albertel 1736: }
1737: return undef;
1738: }
1739:
1.15 albertel 1740: sub find_mid_grade {
1.30 albertel 1741: my ($queue,$symb,$cdom,$cnum)=@_;
1.158 www 1742: my $todo=&unescape($env{'form.gradingkey'});
1.138 albertel 1743: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15 albertel 1744: if ($todo) {
1.30 albertel 1745: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1746: if ($who eq $me) { return $todo; }
1747: }
1748: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1749: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1750: foreach my $key (keys(%locks)) {
1751: my $who=$locks{$key};
1752: if ($who eq $me) {
1753: $todo=$key;
1754: $todo=~s/\0locked$//;
1755: return $todo;
1756: }
1757: }
1758: return undef;
1759: }
1760:
1.32 albertel 1761: sub lock_key {
1762: my ($queue,$todo)=@_;
1.138 albertel 1763: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.185 albertel 1764: my (undef,$cid)=&Apache::lonnet::whichuser();
1.32 albertel 1765: my $cnum=$env{'course.'.$cid.'.num'};
1766: my $cdom=$env{'course.'.$cid.'.domain'};
1767: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1768: $cdom,$cnum);
1.33 albertel 1769: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1770: if ($success eq 'ok') {
1771: return 1;
1772: }
1773: return 0;
1774: }
1775:
1.86 albertel 1776: sub get_queue_symb_status {
1.85 albertel 1777: my ($queue,$symb,$cdom,$cnum) = @_;
1778: if (!defined($cdom) || !defined($cnum)) {
1.185 albertel 1779: my (undef,$cid)=&Apache::lonnet::whichuser();
1.85 albertel 1780: $cnum=$env{'course.'.$cid.'.num'};
1781: $cdom=$env{'course.'.$cid.'.domain'};
1782: }
1.157 albertel 1783: my $classlist=&get_limited_classlist();
1.156 albertel 1784:
1.85 albertel 1785: my $regexp="^$symb\0";
1786: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1787: my ($tmp)=%queue;
1788: if ($tmp=~/^error: 2 /) { return; }
1789: my @users;
1790: foreach my $key (sort(keys(%queue))) {
1791: next if ($key=~/locked$/);
1792: next if ($key=~/timestamp$/);
1793: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156 albertel 1794: next if (!defined($classlist->{$uname.':'.$udom}));
1.85 albertel 1795: push(@users,"$uname:$udom");
1796: }
1797: return @users;
1798: }
1799:
1.14 albertel 1800: sub get_from_queue {
1.30 albertel 1801: my ($queue)=@_;
1.14 albertel 1802: my $result;
1.185 albertel 1803: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 1804: my $cnum=$env{'course.'.$cid.'.num'};
1805: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1806: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1807: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1808: if ($todo) { return $todo; }
1.95 albertel 1809: my $attempts=0;
1.156 albertel 1810:
1.157 albertel 1811: my $classlist=&get_limited_classlist();
1.156 albertel 1812:
1.14 albertel 1813: while (1) {
1.95 albertel 1814: if ($attempts > 2) {
1815: # tried twice to get a queue entry, giving up
1816: return (undef,'unable');
1817: }
1.14 albertel 1818: my $starttime=time;
1.83 albertel 1819: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
1820: $cdom,$cnum);
1.33 albertel 1821: &Apache::lonxml::debug("$starttime");
1.14 albertel 1822: my $regexp="^$symb\0queue\0";
1.156 albertel 1823: #my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97 albertel 1824:
1.98 albertel 1825: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1826: #make a pass looking for a user _not_ in my section
1.14 albertel 1827: if ($env{'request.course.sec'}) {
1.33 albertel 1828: &Apache::lonxml::debug("sce");
1.30 albertel 1829: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156 albertel 1830: \%queue,$cdom,$cnum,$classlist);
1.33 albertel 1831: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1832: }
1.33 albertel 1833: # no one _not_ in our section so look for any user that is
1834: # ready for grading
1.14 albertel 1835: if (!$todo) {
1.33 albertel 1836: &Apache::lonxml::debug("no sce");
1.156 albertel 1837: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
1838: $classlist);
1.33 albertel 1839: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1840: }
1841: # no user to grade
1842: if (!$todo) { last; }
1.33 albertel 1843: &Apache::lonxml::debug("got $todo");
1.14 albertel 1844: # otherwise found someone so lets try to lock them
1.32 albertel 1845: # unless someone else already picked them
1.95 albertel 1846: if (!&lock_key($queue,$todo)) {
1847: $attempts++;
1848: next;
1849: }
1.14 albertel 1850: my (undef,$endtime)=
1.30 albertel 1851: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 1852: $cdom,$cnum);
1.33 albertel 1853: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 1854: # someone else already modified the queue,
1855: # perhaps our picked user wass already fully graded between
1856: # when we picked him and when we locked his record? so lets
1857: # double check.
1858: if ($endtime != $starttime) {
1859: my ($key,$value)=
1.30 albertel 1860: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 1861: $cdom,$cnum);
1.33 albertel 1862: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 1863: if ($key eq $todo && ref($value)) {
1864: } else {
1.30 albertel 1865: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 1866: $cdom,$cnum);
1.33 albertel 1867: &Apache::lonxml::debug("del");
1.95 albertel 1868: $attempts++;
1.14 albertel 1869: next;
1870: }
1871: }
1.33 albertel 1872: &Apache::lonxml::debug("last $todo");
1.14 albertel 1873: last;
1874: }
1875: return $todo;
1876: }
1877:
1.49 albertel 1878: sub select_user {
1.185 albertel 1879: my ($symb,$cid)=&Apache::lonnet::whichuser();
1.49 albertel 1880:
1.59 albertel 1881: my @chosen_sections=
1882: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1883:
1884: my $classlist = &get_limited_classlist(\@chosen_sections);
1.63 albertel 1885:
1886: my $result;
1887: if (!(grep(/^all$/,@chosen_sections))) {
1888: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1889: '</tt>.</p> '."\n";
1890: }
1.159 albertel 1891: $result.=&Apache::loncommon::start_data_table();
1.49 albertel 1892:
1.156 albertel 1893: foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49 albertel 1894: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 1895:
1.84 albertel 1896: my $cnum=$env{'course.'.$cid.'.num'};
1897: my $cdom=$env{'course.'.$cid.'.domain'};
1.88 albertel 1898: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
1899: 'Task');
1.49 albertel 1900: my $queue = 'none';
1.58 albertel 1901: my $cannot_grade;
1902: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1903: $queue = 'reviewqueue';
1.58 albertel 1904: if ($status{'reviewqueue'} eq 'in_progress') {
1905: $cannot_grade=1;
1906: }
1907: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1908: $queue = 'gradingqueue';
1.58 albertel 1909: if ($status{'gradingqueue'} eq 'in_progress') {
1910: $cannot_grade=1;
1911: }
1.49 albertel 1912: }
1913: my $todo =
1.158 www 1914: &escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 1915: if ($cannot_grade) {
1.159 albertel 1916: $result.=&Apache::loncommon::start_data_table_row().
1917: '<td> </td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58 albertel 1918: '</td><td>';
1919: } else {
1.62 albertel 1920: my $seclist;
1921: foreach my $sec (@chosen_sections) {
1922: $seclist.='<input type="hidden" name="chosensections"
1923: value="'.$sec.'" />';
1924: }
1.159 albertel 1925: $result.=&Apache::loncommon::start_data_table_row();
1.58 albertel 1926: $result.=<<RESULT;
1.49 albertel 1927: <td>
1.115 albertel 1928: <form style="display: inline" method="post">
1.49 albertel 1929: <input type="hidden" name="gradingkey" value="$todo" />
1930: <input type="hidden" name="queue" value="$queue" />
1931: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 1932: <input type="hidden" name="regrade" value="yes" />
1.62 albertel 1933: <input type="submit" name="submit" value="Regrade" />
1934: $seclist
1.49 albertel 1935: </form>
1.155 albertel 1936: <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
1.49 albertel 1937: <td>
1938: RESULT
1.58 albertel 1939: }
1.49 albertel 1940: if ($status{'status'} eq 'pass') {
1941: $result .= '<font color="green">'.&mt('Passed').'</font>';
1942: } elsif ($status{'status'} eq 'fail') {
1943: $result .= '<font color="red">'.&mt('Failed').'</font>';
1944: } elsif ($status{'status'} eq 'review') {
1945: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1946: } elsif ($status{'status'} eq 'ungraded') {
1947: $result .= &mt('Ungraded');
1948: } elsif ($status{'status'} ne '') {
1949: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1950: } else {
1951: $result.=" ";
1952: }
1953: if ($status{'version'}) {
1954: $result .= ' '.&mt('Version').' '.$status{'version'};
1955: }
1.101 albertel 1956: if ($status{'grader'}) {
1957: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
1958: }
1.49 albertel 1959: $result.= '</td><td>';
1960: if ($status{'reviewqueue'} eq 'enqueued') {
1961: $result .= &mt('Awaiting Review');
1962: } elsif ($status{'reviewqueue'} eq 'locked') {
1963: $result .= &mt('Under Review');
1.58 albertel 1964: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1965: $result .= &mt('Still being worked on.');
1.49 albertel 1966: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1967: $result .= &mt('Awaiting Grading');
1968: } elsif ($status{'gradingqueue'} eq 'locked') {
1969: $result .= &mt('Being Graded');
1.58 albertel 1970: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1971: $result .= &mt('Still being worked on.');
1.49 albertel 1972: } else {
1973: $result.=" ";
1974: }
1.159 albertel 1975: $result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49 albertel 1976: }
1.159 albertel 1977: $result.=&Apache::loncommon::end_data_table();
1.49 albertel 1978: return $result;
1979: }
1980:
1981: sub get_student_status {
1.86 albertel 1982: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
1983:
1984: my %status;
1985:
1986: if ($type eq 'Task') {
1987: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49 albertel 1988: $udom,$uname);
1.89 albertel 1989: $status{'status'}=$record{'resource.0.status'};
1990: $status{'version'}=$record{'resource.0.version'};
1991: $status{'grader'}=$record{'resource.0.regrader'};
1.86 albertel 1992: }
1993: $status{'reviewqueue'}=
1994: &check_queue_for_key($cdom,$cnum,'reviewqueue',
1995: &encode_queue_key($symb,$udom,$uname));
1996: $status{'gradingqueue'}=
1997: &check_queue_for_key($cdom,$cnum,'gradingqueue',
1998: &encode_queue_key($symb,$udom,$uname));
1.49 albertel 1999: return %status;
2000: }
2001:
1.1 albertel 2002: sub start_ClosingParagraph {
2003: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2004: my $result;
2005: if ($target eq 'web') {
1.13 albertel 2006: } elsif ($target eq 'webgrade') {
2007: &Apache::lonxml::startredirection();
1.1 albertel 2008: }
2009: return $result;
2010: }
2011:
2012: sub end_ClosingParagraph {
2013: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2014: my $result;
2015: if ($target eq 'web') {
1.13 albertel 2016: } elsif ($target eq 'webgrade') {
2017: &Apache::lonxml::endredirection();
1.1 albertel 2018: }
2019: return $result;
2020: }
2021:
1.168 albertel 2022: sub get_dim_id {
1.194 albertel 2023: if (@Apache::bridgetask::dimension) {
2024: return $Apache::bridgetask::dimension[-1];
2025: } else {
2026: return $top;
2027: }
1.168 albertel 2028: }
2029:
1.19 albertel 2030: sub get_id {
2031: my ($parstack,$safeeval)=@_;
2032: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
2033: if (!$id) { $id=$Apache::lonxml::curdepth; }
2034: return $id;
2035: }
2036:
1.162 albertel 2037: sub start_Setup {
2038: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 2039: #undef(%dimension);
2040: my $dim = &get_id($parstack,$safeeval);
2041: push(@Apache::bridgetask::dimension,$dim);
1.162 albertel 2042: &Apache::lonxml::startredirection();
1.168 albertel 2043: return &internal_location($dim);
1.162 albertel 2044: }
1.173 albertel 2045:
2046: {
2047: my @allowed;
2048: sub enable_dimension_parsing {
2049: my ($id) = @_;
2050: push(@allowed,$id);
2051: }
2052: sub disable_dimension_parsing {
2053: pop(@allowed);
2054: }
2055: sub skip_dimension_parsing {
2056: my ($check) = @_;
2057: if (!@allowed) { return 0;}
2058: # if unspecified allow any id
2059: if ($allowed[-1] eq undef) { return 0;}
2060:
2061: return ($check ne $allowed[-1]);
2062: }
2063: }
2064:
1.151 albertel 2065: sub start_Question { return &start_Dimension(@_); }
1.1 albertel 2066: sub start_Dimension {
1.173 albertel 2067: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2068: my $dim = &get_id($parstack,$safeeval);
2069: my $previous_dim;
2070: if (@Apache::bridgetask::dimension) {
2071: $previous_dim = $Apache::bridgetask::dimension[-1];
2072: push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
2073: $dim);
1.173 albertel 2074: if(&skip_dimension_parsing($dim)) {
2075: $dimension{$previous_dim}{'criteria.'.$dim} =
2076: $token->[4]
2077: .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
2078: $style)
2079: .'</'.$tagstack->[-1].'>';
2080: }
1.169 albertel 2081: $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
2082: $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
2083: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2084: push(@{$dimension{$previous_dim}{'criterias'}},$dim);
1.171 albertel 2085: $dimension{$dim}{'nested'}=$previous_dim;
1.196 albertel 2086: $dimension{$dim}{'depth'} = 1 + $dimension{$previous_dim}{'depth'};
1.197 albertel 2087:
1.172 albertel 2088: &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
1.168 albertel 2089: } else {
1.196 albertel 2090: $dimension{$top}{'depth'}=0;
1.194 albertel 2091: $dimension{$top}{'criteria.'.$dim.'.type'}='dimension';
2092: $dimension{$top}{'criteria.'.$dim.'.mandatory'}=
1.168 albertel 2093: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.194 albertel 2094: push(@{$dimension{$top}{'criterias'}},$dim);
1.168 albertel 2095: }
2096: push(@Apache::bridgetask::dimension,$dim);
1.54 albertel 2097: &Apache::lonxml::startredirection();
1.173 albertel 2098: &enable_dimension_parsing($dim);
1.168 albertel 2099: return &internal_location($dim);
1.1 albertel 2100: }
2101:
1.160 albertel 2102: sub start_QuestionText {
2103: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2104: my $dim = &get_dim_id();
1.160 albertel 2105: my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
2106: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2107: $dimension{$dim}{'questiontext'}=$text;
1.160 albertel 2108: }
2109: return '';
2110: }
2111:
2112: sub end_QuestionText {
2113: return '';
2114: }
2115:
1.13 albertel 2116: sub get_instance {
1.75 albertel 2117: my ($dim)=@_;
2118: my $rand_alg=&Apache::lonnet::get_rand_alg();
2119: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
2120: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
2121: $rand_alg eq '64bit4' ) {
2122: &Apache::response::pushrandomnumber();
1.169 albertel 2123: my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75 albertel 2124: my $num=@order;
2125: my $version=&get_version();
2126: my $which=($version-1)%$num;
2127: return $order[$which];
2128: } else {
2129: my ($version,$previous) = &get_version();
2130: my $instance =
2131: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
2132: if (defined($instance)) { return $instance; }
2133:
2134: &Apache::response::pushrandomnumber();
1.173 albertel 2135: if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
2136: my @instances = @{$dimension{$dim}{'instances'}};
2137: # remove disabled instances
2138: for (my $i=0; $i < $#instances; $i++) {
2139: if ($dimension{$dim}{$instances[$i].'.disabled'}) {
2140: splice(@instances,$i,1);
2141: $i--;
2142: }
2143: }
2144: @instances = &Math::Random::random_permutation(@instances);
2145: $instance = $instances[($version-1)%scalar(@instances)];
2146: if ($version =~ /^\d$/) {
2147: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
2148: $instance;
2149: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
1.75 albertel 2150: }
2151: }
2152: &Apache::response::poprandomnumber();
2153: return $instance;
2154: }
1.13 albertel 2155: }
2156:
1.169 albertel 2157: sub get_criteria {
2158: my ($what,$version,$dim,$id) = @_;
2159: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.194 albertel 2160: my $prefix = ($type eq 'criteria' && $dim ne $top) ? "$dim.$id"
2161: : "$id";
1.169 albertel 2162: my $entry = "resource.$version.0.$prefix.$what";
2163: if (exists($Apache::lonhomework::results{$entry})) {
2164: return $Apache::lonhomework::results{$entry};
2165: }
2166: return $Apache::lonhomework::history{$entry};
2167: }
2168:
1.194 albertel 2169: sub link {
2170: my ($id) = @_;
2171: $id =~ s/\./_/g;
2172: return 'LC_GRADING_criteria_'.$id;
2173: }
2174: sub end_Question { return &end_Dimension(@_); }
2175: sub end_Dimension {
2176: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2177: my $result=&Apache::lonxml::endredirection();
2178: my $dim=&get_id($parstack,$safeeval);
2179: if (&skip_dimension_parsing($dim)) {
2180: &disable_dimension_parsing($dim);
2181: pop(@Apache::bridgetask::dimension);
2182: return;
1.122 albertel 2183: }
1.194 albertel 2184: my $instance=&get_instance($dim);
2185: my $version=&get_version();
2186: if ($target eq 'web') {
2187: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2188: my @instances = $instance;
2189: if (&Apache::response::showallfoils()) {
2190: @instances = @{$dimension{$dim}{'instances'}};
1.173 albertel 2191: }
1.194 albertel 2192: my $shown_question_text;
2193: foreach my $instance (@instances) {
2194: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2195: [@_]);
2196: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2197: [@_],{'set_dim_id' => undef});
2198: my $task_status =
2199: $Apache::lonhomework::history{"resource.$version.0.status"};
2200: if ($task_status ne 'pass' && $task_status ne 'fail') {
2201:
2202: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2203: @{$dimension{$dim}{'criterias'}}) {
2204: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2205: &Apache::lonxml::debug("$id is $type");
2206: if ($type eq 'dimension') {
2207: $result.=
2208: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2209: [@_],{'set_dim_id' => $id});
1.173 albertel 2210: }
1.194 albertel 2211: }
2212: } else {
2213: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
2214: my $mandatory='Mandatory';
2215: if (&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval) eq 'N') {
2216: $mandatory='Optional';
2217: }
2218: my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1.196 albertel 2219: my $question = ('sub' x $dimension{$dim}{'depth'}).'question';
1.197 albertel 2220: $question =~ s/^(.)/uc($1)/e;
1.194 albertel 2221: if ($dim_status eq 'pass') {
1.197 albertel 2222: $dim_info.='<h3>'.$question.' : you passed this '.$mandatory.' question</h3>';
1.194 albertel 2223: }
2224: if ($dim_status eq 'fail') {
1.197 albertel 2225: $dim_info.='<h3>'.$question.' : you did not pass this '.$mandatory.' question</h3>';
1.194 albertel 2226: }
1.197 albertel 2227: my %counts = &get_counts($dim,$instance,$parstack,
2228: $safeeval);
2229:
2230: $dim_info.="\n<p>"
2231: .&question_status_message(\%counts,
2232: $dimension{$dim}{'depth'})
2233: ."</p>\n</div>";
1.194 albertel 2234:
2235: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2236: @{$dimension{$dim}{'criterias'}}) {
2237: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2238: if ($type eq 'dimension') {
2239: $result.=$dimension{$id}{'result'};
2240: next;
2241: }
2242: my $criteria =
1.173 albertel 2243: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
1.194 albertel 2244: [@_]);
2245: $dim_info .= &layout_web_Criteria($dim,$id,$criteria);
1.169 albertel 2246: }
2247:
1.194 albertel 2248: my $internal_location=&internal_location($dim);
2249: $result=~s/\Q$internal_location\E/$dim_info/;
1.19 albertel 2250: }
1.194 albertel 2251: }
2252: } elsif ($target eq 'webgrade') {
2253: # in case of any side effects that we need
2254: &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2255: &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
2256: $result.=
2257: &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
2258: {'set_dim_id' => undef,
1.195 albertel 2259: 'delayed_dim_results' => 1});
1.194 albertel 2260: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2261: @{$dimension{$dim}{'criterias'}} ) {
2262: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2263: if ($type eq 'dimension') {
2264: # dimensional 'criteria' don't get assigned grades
2265: $result.=
2266: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2267: [@_],{'set_dim_id' => $id});
2268: next;
2269: } else {
2270: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
2271: [@_]);
2272: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
2273: my $internal_location=&internal_location($id);
2274: $result=~s/\Q$internal_location\E/$criteria/;
1.151 albertel 2275: }
1.194 albertel 2276: }
2277: if (&nest()) {
2278: &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
2279: $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
2280: undef($result);
2281: }
2282: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
2283: my $optional_passed=0;
2284: my $mandatory_failed=0;
2285: my $ungraded=0;
2286: my $review=0;
2287:
2288: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2289: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2290: [@_]);
2291: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2292: [@_],{'set_dim_id' => undef});
2293:
2294: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2295: @{$dimension{$dim}{'criterias'}}) {
2296: my $link=&link($id);
2297:
2298: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2299: if ($type eq 'criteria') {
2300: # dimensional 'criteria' don't get assigned grades
2301: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
2302: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
2303: } else {
2304: $result .=
2305: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2306: [@_],{'set_dim_id' => $id});
1.20 albertel 2307: }
1.194 albertel 2308: my $status= &get_criteria('status',$version,$dim,$id);
2309:
2310: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
2311: if ($status eq 'pass') {
2312: if (!$mandatory) { $optional_passed++; }
2313: } elsif ($status eq 'fail') {
2314: if ($mandatory) { $mandatory_failed++; }
2315: } elsif ($status eq 'review') {
2316: $review++;
2317: } elsif ($status eq 'ungraded') {
2318: $ungraded++;
1.20 albertel 2319: } else {
1.194 albertel 2320: $ungraded++;
1.20 albertel 2321: }
1.194 albertel 2322: }
2323:
2324: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
2325: if ($opt_req !~ /\S/) {
2326: $opt_req=
2327: &Apache::lonxml::get_param('OptionalRequired',
2328: $parstack,$safeeval);
2329: if ($opt_req !~ /\S/) { $opt_req = 0; }
2330: }
2331: if ($optional_passed < $opt_req) {
2332: $mandatory_failed++;
2333: }
2334: &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
2335: if ($review) {
2336: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2337: 'review';
2338: } elsif ($ungraded) {
2339: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2340: 'ungraded';
2341: } elsif ($mandatory_failed) {
2342: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2343: 'fail';
1.69 albertel 2344: } else {
1.194 albertel 2345: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2346: 'pass';
1.13 albertel 2347: }
1.194 albertel 2348: } else {
2349: # any other targets no output
2350: undef($result);
1.1 albertel 2351: }
1.194 albertel 2352: &disable_dimension_parsing();
2353: pop(@Apache::bridgetask::dimension);
2354: return $result;
2355: }
1.162 albertel 2356:
1.198 albertel 2357: sub question_status_message {
1.197 albertel 2358: my ($counts,$depth) = @_;
2359: my %req = ('man' => 'mandatory',
2360: 'opt' => 'optional',);
2361: my %type = ('cri' => 'criteria',
2362: 'dim' => ('sub'x($depth+1)).'questions',);
2363: my @sections;
2364: foreach my $req ('man','opt') {
2365: foreach my $type ('cri','dim') {
2366: if ($counts->{$req.'_'.$type}) {
2367: push(@sections,
2368: $counts->{$req.'_'.$type.'_passed'}.' of '.
2369: $counts->{$req.'_'.$type}.' '.
2370: $req{$req}.' '.$type{$type});
2371: }
2372: }
2373: }
2374:
2375: my $status = 'You passed ';
2376: if (@sections == -1) {
2377: } elsif (@sections == 1) {
2378: $status .= $sections[0];
2379: } elsif (@sections == 2) {
2380: $status .= $sections[0].' and '.$sections[1];
2381: } else {
2382: my $last = pop(@sections);
2383: $status .= join(', ',@sections).', and '.$last;
2384: }
2385: $status .= '.';
2386: if ($counts->{'opt'}) {
2387: $status .= ' You were required to pass '.$counts->{'opt_req'}.
2388: ' optional component'.($counts->{'opt_req'} == 1?'':'s');
2389: }
2390: return $status;
2391: }
2392:
2393: sub get_counts {
2394: my ($dim,$instance,$parstack,$safeeval) = @_;
2395: my %counts;
2396: my @possible = ('man_cri','man_dim',
2397: 'opt_cri','opt_dim',
2398: 'man_cri_passed', 'man_dim_passed',
2399: 'opt_cri_passed', 'opt_dim_passed',
2400: 'man_passed',
2401: 'opt_passed',
2402: 'opt_req');
2403: foreach my $which (@possible) { $counts{$which} = 0; }
2404:
2405: my $version = &get_version();
2406:
2407: foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
2408: @{$dimension{$dim}{'criterias'}} ) {
2409: my $status = &get_criteria('status',$version,$dim,$id);
2410: my $which;
2411: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
2412: eq 'N') {
2413: $which = 'opt';
2414: } else {
2415: $which = 'man';
2416: }
2417: $counts{$which}++;
2418: if ($status eq 'pass') { $counts{$which.'_passed'}++; }
2419: if ($dimension{$dim}{'criteria.'.$id.'.type'}
2420: eq 'dimension') {
2421: $which .= '_dim';
2422: } else {
2423: $which .= '_cri';
2424: }
2425: $counts{$which}++;
2426: if ($status eq 'pass') { $counts{$which.'_passed'}++; }
2427:
2428:
2429: }
2430: if ($counts{'man_dim_passed'} eq $counts{'man_dim'}) {
2431: $counts{'man_dim_passed'}='all';
2432: }
2433: if ($counts{'man_cri_passed'} eq $counts{'man_cri'}) {
2434: $counts{'man_cri_passed'}='all';
2435: }
2436:
2437: $counts{'opt_req'}=$dimension{$dim}{$instance.'.optionalrequired'};
2438: if ($counts{'opt_req'} !~ /\S/) {
2439: $counts{'opt_req'}= &Apache::lonxml::get_param('OptionalRequired',
2440: $parstack,$safeeval);
2441: if ($counts{'opt_req'} !~ /\S/) { $counts{'opt_req'} = 0; }
2442: }
2443: return %counts;
2444: }
2445:
1.194 albertel 2446: sub end_Setup {
2447: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2448: my $result=&Apache::lonxml::endredirection();
2449: my $dim=&get_id($parstack,$safeeval);
2450: my $instance=&get_instance($dim);
2451: my $version=&get_version();
2452: if ($target eq 'web') {
2453: @Apache::scripttag::parser_env = @_;
2454: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2455: my @instances = $instance;
2456: if (&Apache::response::showallfoils()) {
2457: @instances = @{$dimension{$dim}{'instances'}};
2458: }
2459: foreach my $instance (@instances) {
1.162 albertel 2460: @Apache::scripttag::parser_env = @_;
1.194 albertel 2461: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2462: @Apache::scripttag::parser_env = @_;
1.194 albertel 2463: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2464: }
1.194 albertel 2465: } elsif ($target eq 'webgrade'
2466: || $target eq 'grade' && $env{'form.webgrade'}) {
2467: # in case of any side effects that we need
2468: @Apache::scripttag::parser_env = @_;
2469: &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2470: @Apache::scripttag::parser_env = @_;
2471: &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
2472: @Apache::scripttag::parser_env = @_;
2473: &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
2474: } else {
2475: # any other targets no output
2476: undef($result);
1.162 albertel 2477: }
1.194 albertel 2478: pop(@Apache::bridgetask::dimension);
2479: return $result;
1.1 albertel 2480: }
2481:
1.113 albertel 2482: sub grading_history {
1.151 albertel 2483: my ($version,$dim,$id) = @_;
1.113 albertel 2484: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
2485: return '';
2486: }
2487: my ($result,$grader);
1.194 albertel 2488: my $scope="resource.$version.0.";
2489: $scope .= ($dim ne $top) ? "$dim.$id"
2490: : "$id";
1.113 albertel 2491: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
2492: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
2493: my ($gname,$gdom) =
1.138 albertel 2494: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113 albertel 2495: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
2496: $grader = &Apache::loncommon::aboutmewrapper($fullname,
2497: $gname,$gdom);
2498: }
2499: my $entry;
2500: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
2501: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
2502: }
2503: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
2504: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
2505: }
2506: if ($entry) {
2507: $result.= "<li>$grader : $entry </li>";
2508: }
2509: }
2510: if ($result) {
1.120 albertel 2511: return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1.113 albertel 2512: }
2513: return '';
2514: }
2515:
1.1 albertel 2516: sub start_IntroParagraph {
1.87 albertel 2517: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 2518: my $result;
1.168 albertel 2519: my $dim = &get_dim_id();
1.153 albertel 2520: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151 albertel 2521: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169 albertel 2522: $dimension{$dim}{'intro'}=
1.151 albertel 2523: &Apache::lonxml::get_all_text('/introparagraph',
2524: $parser,$style);
2525: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2526: &Apache::lonxml::startredirection();
1.1 albertel 2527: }
1.47 albertel 2528:
1.1 albertel 2529: }
2530: return $result;
2531: }
2532:
2533: sub end_IntroParagraph {
1.127 albertel 2534: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128 albertel 2535: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2536: my $result = &Apache::lonxml::endredirection();
2537: }
1.1 albertel 2538: }
2539:
2540: sub start_Instance {
2541: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 2542: my $dim = &get_dim_id();
2543: my $id = &get_id($parstack,$safeeval);
1.169 albertel 2544: push(@{$dimension{$dim}{'instances'}},$id);
1.168 albertel 2545: push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19 albertel 2546: push(@Apache::bridgetask::instancelist,$id);
1.169 albertel 2547: $dimension{$dim}{$id.'.optionalrequired'}=
1.19 albertel 2548: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75 albertel 2549: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2550: if (lc($disabled) eq 'yes') {
1.169 albertel 2551: $dimension{$dim}{$id.'.disabled'}='1';
1.75 albertel 2552: }
1.1 albertel 2553: return '';
2554: }
2555:
2556: sub end_Instance {
2557: }
2558:
2559: sub start_InstanceText {
1.87 albertel 2560: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2561: my $dim = &get_dim_id();
2562: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.87 albertel 2563: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
1.153 albertel 2564: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2565: $dimension{$dim}{$instance_id.'.text'}=$text;
1.1 albertel 2566: }
2567: return '';
2568: }
2569:
2570: sub end_InstanceText {
2571: return '';
2572: }
2573:
2574: sub start_Criteria {
1.87 albertel 2575: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2576: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.190 albertel 2577: my $result = '';
1.21 albertel 2578: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.168 albertel 2579: my $dim = &get_dim_id();
1.19 albertel 2580: my $id=&get_id($parstack,$safeeval);
1.194 albertel 2581: if ($target eq 'web' || $target eq 'webgrade') {
1.195 albertel 2582: if ($target eq 'webgrade' && $dim ne 'top') {
2583: &Apache::lonxml::debug(" for $dim $id stashing results into $dim ");
2584: $dimension{$dim}{'result'} .= &internal_location($id);
2585: } else {
2586: &Apache::lonxml::debug(" not stashing $dim $id");
2587: $result .= &internal_location($id);
2588: }
1.194 albertel 2589: }
1.169 albertel 2590: &Apache::lonxml::debug("Criteria $id with $dim");
1.151 albertel 2591: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168 albertel 2592: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 2593: $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
2594: $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
2595: $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151 albertel 2596: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2597: push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151 albertel 2598: } else {
1.169 albertel 2599: $dimension{$dim}{'criteria.'.$id}=$criteria;
2600: $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
2601: $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151 albertel 2602: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2603: push(@{$dimension{$dim}{'criterias'}},$id);
1.194 albertel 2604: }
2605: }
2606: return $result;
2607: }
2608:
2609: sub layout_web_Criteria {
2610: my ($dim,$id,$criteria) = @_;
1.190 albertel 2611:
1.194 albertel 2612: my $version = &get_version();
2613: my $status= &get_criteria('status', $version,$dim,$id);
2614: my $comment=&get_criteria('comment',$version,$dim,$id);
2615: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
2616: if ($mandatory) {
2617: $mandatory='Mandatory';
2618: } else {
2619: $mandatory='Optional';
1.1 albertel 2620: }
1.194 albertel 2621: my $status_display=$status;
2622: $status_display=~s/^([a-z])/uc($1)/e;
2623: my $criteria_info.=
2624: '<div class="LC_'.$status.' LC_criteria"><h4>'
2625: .$mandatory.' Criteria</h4><p>';
2626: $criteria_info.= $criteria;
2627: $criteria_info.='</p><p class="LC_grade">'.$status_display.'</p>';
2628: if ($comment =~ /\w/) {
2629: $criteria_info.='<p class="LC_comment">'.
2630: &mt('Comment: [_1]',$comment).'</p>';
2631: }
2632: $criteria_info.='</div>';
2633: return $criteria_info;
2634: }
2635:
2636: sub layout_webgrade_Criteria {
2637: my ($dim,$id,$criteria) = @_;
2638: my $link=&link($id);
2639: my $version = &get_version();
2640: my $status = &get_criteria('status',$version,$dim,$id);
2641: my $result =
2642: '<div class="LC_GRADING_criteria">'."\n".
2643: '<div class="LC_GRADING_criteriatext">'."\n".
2644: $criteria.
2645: '</div>'."\n".
2646: '<div class="LC_GRADING_grade">'."\n".
2647: '<label class="LC_GRADING_ungraded">
2648: <input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.
2649: &mt('Ungraded').
2650: '</label>'."\n".
2651: '<label class="LC_GRADING_fail">
2652: <input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.
2653: &mt('Fail').
2654: '</label>'."\n".
2655: '<label class="LC_GRADING_pass">
2656: <input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.
2657: &mt('Pass').
2658: '</label>'."\n".
2659: '<label class="LC_GRADING_review">
2660: <input type="radio" name="HWVAL_'.$link.'" value="review" '.($status eq 'review' ? 'checked="checked"':'').' />'.
2661: &mt('Review').
2662: '</label>'."\n".
2663: '</div>'."\n".
2664: '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
2665: '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode(&get_criteria('comment',$version,$dim,$id),'<>"&').'</textarea>'."\n".
2666: '</label>'."\n".
2667: '</div>'."\n".
2668: &grading_history($version,$dim,$id);
1.190 albertel 2669: return $result;
1.1 albertel 2670: }
2671:
1.47 albertel 2672: sub end_Criteria {
2673: }
2674:
1.186 albertel 2675: sub start_GraderNote {
2676: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2677:
2678: if ($target eq 'webgrade') {
1.187 albertel 2679: return '<div class="LC_GRADING_gradernote"><b>'.
2680: &mt('Note to graders:').'</b>';
1.186 albertel 2681: }
2682: my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style);
2683: return;
2684: }
2685:
2686: sub end_GraderNote {
2687: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2688:
2689: if ($target eq 'webgrade') {
2690: return '</div>';
2691: }
2692: return;
2693: }
2694:
2695:
2696:
1.4 albertel 2697: sub proctor_validation_screen {
2698: my ($slot) = @_;
1.185 albertel 2699: my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
1.5 albertel 2700: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 2701: my $name=&Apache::loncommon::plainname($user,$domain);
2702:
1.4 albertel 2703: my $msg;
1.11 albertel 2704: if ($env{'form.proctorpassword'}) {
1.4 albertel 2705: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
2706: .'</font></p>';
2707: }
1.47 albertel 2708: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 2709: my $result= (<<ENDCHECKOUT);
2710: <h2>Proctor Validation</h2>
2711: <p>Your room's proctor needs to validate your access to this resource.</p>
2712: $msg
1.115 albertel 2713: <form name="checkout" method="post" action="$env{'request.uri'}">
1.4 albertel 2714: <input type="hidden" name="validate" value="yes" />
2715: <input type="hidden" name="submitted" value="yes" />
2716: <table>
1.44 albertel 2717: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 2718: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 2719: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 2720: </table>
2721: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 2722: <table border="1">
2723: <tr><td>
2724: <table>
2725: <tr><td colspan="2">Student who should be logged in is:</td></tr>
2726: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 2727: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138 albertel 2728: <tr><td>Usename</td><td>$user:$domain</td></tr>
1.44 albertel 2729: <tr><td colspan="2"><img src="$url" /></td></tr>
2730: </table>
2731: </tr></td>
2732: </table>
1.4 albertel 2733: </form>
2734: ENDCHECKOUT
2735: return $result;
2736: }
2737:
1.1 albertel 2738: 1;
2739: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>