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