Annotation of loncom/homework/bridgetask.pm, revision 1.186
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.186 ! albertel 4: # $Id: bridgetask.pm,v 1.185 2006/10/17 15:11: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.186 ! albertel 46: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','GraderNote','ClosingParagraph'));
1.1 albertel 47: }
48:
1.169 albertel 49: my %dimension;
1.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();
1.185 albertel 108: my ($symb) = &Apache::lonnet::whichuser();
1.174 albertel 109: my ($map) = &Apache::lonnet::decode_symb($symb);
1.175 albertel 110: my @resources =
111: $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
1.174 albertel 112: my %old_history = %Apache::lonhomework::history;
113: my %old_results = %Apache::lonhomework::results;
114:
115: foreach my $res (@resources) {
116: &Apache::lonxml::debug("doing ".$res->src);
117: &Apache::structuretags::initialize_storage($res->symb);
118: my $type = ($res->is_task()) ? 'Task' : 'problem';
119: &create_new_version($type,$user,$domain,$slot_name);
120: &Apache::structuretags::finalize_storage($res->symb);
121: }
122:
123: %Apache::lonhomework::history = %old_history;
124: %Apache::lonhomework::results = %old_results;
125: }
126:
1.150 albertel 127: sub create_new_version {
128: my ($type,$user,$domain,$slot_name) = @_;
1.174 albertel 129:
130: my $id = '0';
1.150 albertel 131: if ($type eq 'Task') {
132: # increment version
133: my $version=
134: $Apache::lonhomework::history{'resource.0.version'};
135: $version++;
1.152 albertel 136: &Apache::lonxml::debug("Making version $version");
1.150 albertel 137: #clean out all current results
138: foreach my $key (keys(%Apache::lonhomework::history)) {
139: if ($key=~/^resource\.0\./) {
140: $Apache::lonhomework::results{$key}='';
141: }
142: }
143:
144: #setup new version and who did it
1.174 albertel 145: $Apache::lonhomework::results{'resource.0.version'}=$version;
146: $id = "$version.0";
1.178 albertel 147: if (!defined($user) || !defined($domain)) {
1.174 albertel 148: $user = $env{'user.name'};
149: $domain = $env{'user.domain'};
1.150 albertel 150: }
1.174 albertel 151:
1.150 albertel 152: } elsif ($type eq 'problem') {
153: &Apache::lonxml::debug("authed $slot_name");
1.174 albertel 154: }
1.181 albertel 155: if (!defined($user) || !defined($domain)) {
156: $user = $env{'user.name'};
157: $domain = $env{'user.domain'};
158: }
159:
160: $Apache::lonhomework::results{"resource.$id.checkedin"}=
161: $user.':'.$domain;
1.174 albertel 162:
163: if (defined($slot_name)) {
164: $Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
165: $slot_name;
1.150 albertel 166: }
167: }
168:
1.25 albertel 169: sub get_version {
1.29 albertel 170: my ($version,$previous);
1.25 albertel 171: if ($env{'form.previousversion'} &&
1.36 albertel 172: $env{'form.previousversion'} ne 'current' &&
1.89 albertel 173: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
1.29 albertel 174: $version=$env{'form.previousversion'};
175: $previous=1;
176: } else {
1.150 albertel 177: if (defined($Apache::lonhomework::results{'resource.0.version'})) {
178: $version=$Apache::lonhomework::results{'resource.0.version'};
179: } elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
180: $version=$Apache::lonhomework::history{'resource.0.version'};
181: }
1.29 albertel 182: $previous=0;
183: }
184: if (wantarray) {
185: return ($version,$previous);
1.25 albertel 186: }
1.29 albertel 187: return $version;
1.25 albertel 188: }
189:
1.8 albertel 190: sub add_previous_version_button {
1.25 albertel 191: my ($status)=@_;
1.8 albertel 192: my $result;
1.89 albertel 193: if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
1.25 albertel 194: return '';
195: }
1.89 albertel 196: if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
1.29 albertel 197: $status ne 'NEEDS_CHECKIN') {
1.25 albertel 198: return '';
199: }
1.29 albertel 200: my $version=&get_version();
201: if ($env{'form.previousversion'} ne '' &&
202: $env{'form.previousversion'} eq $version) {
203: $result.="<h3>".&mt("Showing previous version [_1]",$version).
204: "</h3>\n";
205: }
206: my @to_show;
1.89 albertel 207: foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
208: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
1.29 albertel 209: push(@to_show,$test_version);
210: }
211: }
212: my $list='<option>'.
213: join("</option>\n<option>",@to_show).
214: "</option>\n";
1.36 albertel 215: $list.='<option value="current">'.&mt('Current').'</option>';
1.115 albertel 216: $result.='<form name="getprevious" method="post" action="';
1.29 albertel 217: my $uri=$env{'request.uri'};
218: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
219: $result.=$uri.'">'.
220: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
221: <option>'.&mt('Pick one').'</option>
222: '.$list.'
223: </select>')."</form>";
1.8 albertel 224: return $result;
225: }
226:
1.13 albertel 227: sub add_grading_button {
1.185 albertel 228: my (undef,$cid)=&Apache::lonnet::whichuser();
1.59 albertel 229: my $cnum=$env{'course.'.$cid.'.num'};
230: my $cdom=$env{'course.'.$cid.'.domain'};
1.144 albertel 231: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
232:
1.59 albertel 233: my $size=5;
234: if (scalar(keys(%sections)) < 3) {
235: $size=scalar(keys(%sections))+2;
236: }
1.122 albertel 237: my $sec_select = '<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
1.59 albertel 238: $sec_select .= "<option value='all' selected='selected'>all</option>\n";
239: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
1.122 albertel 240: $sec_select .= "<option value=\"$sec\">$sec</option>\n";
1.59 albertel 241: }
242: $sec_select .= "<option value='none'>none</option></select>\n";
243:
1.29 albertel 244: my $result=' <input type="submit" name="gradeasubmission" value="'.
1.13 albertel 245: &mt("Get a submission to grade").'" />';
246: $result.='<input type="hidden" name="grade_target" value="webgrade" />';
1.40 albertel 247: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
1.34 albertel 248: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.106 albertel 249: $result.='<table><tr>';
250: $result.='<td rowspan="4">Specify a section: </td><td rowspan="4">'.$sec_select.'</td>';
251: $result.='<td>'.' <input type="submit" name="reviewagrading" value="'.
252: &mt("Select an entry from the grading queue:").'" /> ';
1.34 albertel 253:
1.107 albertel 254: $result.= &mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).' </td></tr>'."\n";
1.34 albertel 255:
256: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
1.106 albertel 257: $result.='<tr><td>'.
258: ' <input type="submit" name="reviewasubmission" value="'.
259: &mt("Select an entry from the review queue:").'" /> ';
260: $result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
261: $entries,$ready,$locks).'</td></tr>'."\n";
262: $result.='<tr><td> <input type="submit" name="regradeasubmission" value="'.
263: &mt("List of user's grade status").'" /> </td></tr></table>'."\n";
1.105 albertel 264: $result.='<p> <input type="submit" name="regradeaspecificsubmission" value="'.
1.106 albertel 265: &mt("Regrade specific user:").'" />'."\n";
1.105 albertel 266: $result.='<input type="text" size="12" name="gradinguser" />';
267: $result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
268: 'gradingdomain');
269: $result.=' '.
270: &Apache::loncommon::selectstudent_link('gradesubmission',
271: 'gradinguser',
272: 'gradingdomain');
273: $result.=&Apache::loncommon::studentbrowser_javascript();
1.123 albertel 274: $result.= '</p>';
1.144 albertel 275: }
1.13 albertel 276: return $result;
277: }
278:
1.22 albertel 279: sub add_request_another_attempt_button {
1.38 albertel 280: my ($text)=@_;
281: if (!$text) { $text="Request another attempt"; }
1.25 albertel 282: my $result;
1.36 albertel 283: my $symb=&Apache::lonnet::symbread();
1.149 albertel 284: # not a slot access based resource
285: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
286: if ($useslots =~ /^\s*no\s*$/i) {
287: return '';
288: }
289:
1.37 albertel 290: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38 albertel 291: my $action='get_reservation';
1.37 albertel 292: if ($slot_name) {
1.38 albertel 293: $text="Change reservation.";
294: $action='change_reservation';
1.37 albertel 295: my $description=&Apache::slotrequest::get_description($slot_name,
296: $slot);
297: $result.=(<<STUFF);
298: <p> Will be next available: $description </p>
299: STUFF
300: }
1.38 albertel 301:
302: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
1.158 www 303: $symb=&escape($symb);
1.115 albertel 304: $result.='<form method="post" action="/adm/slotrequest">'.
1.38 albertel 305: '<input type="hidden" name="symb" value="'.$symb.'" />'.
306: '<input type="hidden" name="command" value="'.$action.'" />'.
307: '<input type="submit" name="requestattempt" value="'.
308: &mt($text).'" />'.
309: '</form>';
1.25 albertel 310: return $result;
1.22 albertel 311: }
312:
1.30 albertel 313: sub preserve_grade_info {
314: my $result;
315: # if we are viewing someone else preserve that info
316: if (defined $env{'form.grade_symb'}) {
317: foreach my $field ('symb','courseid','domain','username') {
318: $result .= '<input type="hidden" name="grade_'.$field.
319: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
320: }
321: }
322: return $result;
323: }
324:
1.53 albertel 325: sub style {
1.125 albertel 326: my ($target) = @_;
327: if ($target eq 'web'
328: || $target eq 'webgrade') {
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 {
1.185 albertel 391: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.60 albertel 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)) {
1.185 albertel 429: (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
1.119 albertel 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'});
1.185 albertel 490: my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
1.166 albertel 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'}) ) {
1.185 albertel 834: my ($symb,$cid)=&Apache::lonnet::whichuser();
1.105 albertel 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.1 albertel 1105: }
1.163 albertel 1106: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1107: && exists($env{'form.cancel'})) {
1108: &check_queue_unlock($env{'form.queue'});
1109: &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
1110: } elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1111: && !exists($env{'form.cancel'})) {
1.20 albertel 1112: my $optional_required=
1113: &Apache::lonxml::get_param('OptionalRequired',$parstack,
1114: $safeeval);
1115: my $optional_passed=0;
1116: my $mandatory_failed=0;
1117: my $ungraded=0;
1118: my $review=0;
1.21 albertel 1119: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.168 albertel 1120: foreach my $dim (keys(%Apache::bridgetask::top_dimensionlist)) {
1.20 albertel 1121: my $status=
1.168 albertel 1122: $Apache::lonhomework::results{"resource.$version.0.$dim.status"};
1.20 albertel 1123: my $mandatory=
1.168 albertel 1124: ($Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'} ne 'N');
1.20 albertel 1125: if ($status eq 'pass') {
1126: if (!$mandatory) { $optional_passed++; }
1127: } elsif ($status eq 'fail') {
1128: if ($mandatory) { $mandatory_failed++; }
1129: } elsif ($status eq 'ungraded') {
1130: $ungraded++;
1131: } elsif ($status eq 'review') {
1132: $review++;
1.49 albertel 1133: } else {
1134: $ungraded++;
1135: }
1.20 albertel 1136: }
1137: if ($optional_passed < $optional_required) {
1138: $mandatory_failed++;
1139: }
1.168 albertel 1140: &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 1141: $Apache::lonhomework::results{'resource.0.regrader'}=
1.138 albertel 1142: $env{'user.name'}.':'.$env{'user.domain'};
1.20 albertel 1143: if ($review) {
1.89 albertel 1144: $Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.33 albertel 1145: if ($env{'form.queue'} eq 'reviewqueue') {
1146: &check_queue_unlock($env{'form.queue'});
1147: &Apache::lonxml::debug(" still needs review not changing status.");
1148: } else {
1.181 albertel 1149: if ($env{'form.queue'} ne 'none') {
1150: &move_between_queues($env{'form.queue'},'reviewqueue');
1151: } else {
1152: &add_to_queue('reviewqueue',\%queue_data);
1153: }
1.33 albertel 1154: }
1.20 albertel 1155: } elsif ($ungraded) {
1.89 albertel 1156: $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.181 albertel 1157: if ($env{'form.queue'} eq 'reviewqueue') {
1.33 albertel 1158: &Apache::lonxml::debug("moving back.");
1.181 albertel 1159: &move_between_queues($env{'form.queue'},
1160: 'gradingqueue');
1161: } elsif ($env{'form.queue'} eq 'none' ) {
1162: &add_to_queue('gradingqueue',\%queue_data);
1.33 albertel 1163: } else {
1164: &check_queue_unlock($env{'form.queue'});
1165: }
1.20 albertel 1166: } elsif ($mandatory_failed) {
1.89 albertel 1167: $Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25 albertel 1168: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
1169: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
1170: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.39 albertel 1171: &remove_from_queue($env{'form.queue'});
1172:
1.185 albertel 1173: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1174:
1175: if ($env{'form.regrade'} ne 'yes') {
1176: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1177: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1178: &Apache::grades::version_portfiles(
1179: \%Apache::lonhomework::results,
1180: ["$version.0.bridgetask"],$courseid,
1181: $symb,$udom,$uname,
1182: ["$version.0.bridgetask"]);
1183: }
1.20 albertel 1184: } else {
1.89 albertel 1185: $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25 albertel 1186: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
1187: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
1188: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.32 albertel 1189: &remove_from_queue($env{'form.queue'});
1.39 albertel 1190:
1.185 albertel 1191: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1192: if ($env{'form.regrade'} ne 'yes') {
1193: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1194: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1195: &Apache::grades::version_portfiles(
1196: \%Apache::lonhomework::results,
1197: ["$version.0.bridgetask"],$courseid,
1198: $symb,$udom,$uname,
1199: ["$version.0.bridgetask"]);
1200: }
1.20 albertel 1201: }
1.89 albertel 1202: $Apache::lonhomework::results{"resource.0.status"}=
1203: $Apache::lonhomework::results{"resource.$version.0.status"};
1.28 albertel 1204: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 1205: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 1206: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 1207: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 1208: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 1209: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 1210: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 1211: }
1.94 albertel 1212: &minimize_storage();
1.21 albertel 1213: &Apache::structuretags::finalize_storage();
1.20 albertel 1214: }
1.184 albertel 1215: if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
1216: # instance generation occured and hasn't yet been stored
1217: &Apache::structuretags::finalize_storage();
1218: }
1.15 albertel 1219: } elsif ($target eq 'webgrade') {
1.131 albertel 1220: $result.="</div>";
1.20 albertel 1221: #$result.='<input type="submit" name="next" value="'.
1222: # &mt('Save & Next').'" /> ';
1223: #$result.='<input type="submit" name="end" value="'.
1224: # &mt('Save & Stop Grading').'" /> ';
1225: #$result.='<input type="submit" name="throwaway" value="'.
1226: # &mt('Throw Away & Stop Grading').'" /> ';
1227: #$result.='<input type="submit" name="save" value="'.
1228: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124 albertel 1229: $result.='</form>'."\n</div>\n</div>\n".
1.140 albertel 1230: &Apache::loncommon::end_page();
1.1 albertel 1231: } elsif ($target eq 'meta') {
1.70 albertel 1232: $result.=&Apache::response::meta_package_write('Task');
1.77 albertel 1233: $result.=&Apache::response::meta_stores_write('solved','string',
1234: 'Problem Status');
1235: $result.=&Apache::response::meta_stores_write('tries','int_zeropos',
1236: 'Number of Attempts');
1237: $result.=&Apache::response::meta_stores_write('awarded','float',
1238: 'Partial Credit Factor');
1239: $result.=&Apache::response::meta_stores_write('status','string',
1240: 'Bridge Task Status');
1.182 albertel 1241: } elsif ($target eq 'edit') {
1242: &Apache::structuretags::reset_problem_globals('Task');
1243: undef($Apache::lonhomework::parsing_a_task);
1244: return ('','no');
1.1 albertel 1245: }
1.179 albertel 1246: &Apache::structuretags::reset_problem_globals('Task');
1.4 albertel 1247: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 1248: return $result;
1249: }
1250:
1.31 albertel 1251: sub move_between_queues {
1252: my ($src_queue,$dest_queue)=@_;
1.49 albertel 1253: my $cur_data;
1254: if ($src_queue ne 'none') {
1255: $cur_data=&get_queue_data($src_queue);
1256: if (!$cur_data) { return 'not_exist'; }
1257: } else {
1258: $cur_data = ['none'];
1259: }
1.148 albertel 1260: my $result=&add_to_queue($dest_queue,$cur_data);
1.31 albertel 1261: if ($result ne 'ok') {
1262: return $result;
1263: }
1264: &check_queue_unlock($src_queue);
1265: return &remove_from_queue($src_queue);
1.21 albertel 1266: }
1267:
1268: sub check_queue_unlock {
1.32 albertel 1269: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 1270: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1271: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.32 albertel 1272: if (!defined($key)) {
1.138 albertel 1273: $key="$symb\0queue\0$uname:$udom";
1.32 albertel 1274: }
1.30 albertel 1275: my $cnum=$env{'course.'.$cid.'.num'};
1276: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1277: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30 albertel 1278: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1279: if ($who eq $me) {
1.163 albertel 1280: &Apache::lonxml::debug("unlocking my own $who");
1.32 albertel 1281: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1282: } elsif ($allow_not_me) {
1.33 albertel 1283: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 1284: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 1285: }
1.32 albertel 1286: return 'not_owner';
1.21 albertel 1287: }
1288:
1.88 albertel 1289: sub in_queue {
1290: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1291: if ($queue eq 'none') { return 0; }
1292: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1293: || !defined($udom) || !defined($uname)) {
1.185 albertel 1294: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.88 albertel 1295: $cnum=$env{'course.'.$cid.'.num'};
1296: $cdom=$env{'course.'.$cid.'.domain'};
1297: }
1298:
1299: my $key=&encode_queue_key($symb,$udom,$uname);
1300: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1301:
1302: if (defined($results{$key})) {
1303: return 1;
1304: }
1305: return 0;
1306: }
1307:
1.21 albertel 1308: sub remove_from_queue {
1.86 albertel 1309: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49 albertel 1310: if ($queue eq 'none') { return 'ok'; }
1.86 albertel 1311: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1312: || !defined($udom) || !defined($uname)) {
1.185 albertel 1313: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.86 albertel 1314: $cnum=$env{'course.'.$cid.'.num'};
1315: $cdom=$env{'course.'.$cid.'.domain'};
1316: }
1.88 albertel 1317: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1318: return 'ok';
1319: }
1.86 albertel 1320: my $key=&encode_queue_key($symb,$udom,$uname);
1.27 albertel 1321: my @keys=($key,"$key\0locked");
1.31 albertel 1322: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 1323: }
1324:
1.16 albertel 1325: sub setup_env_for_other_user {
1326: my ($queue_key,$safeeval)=@_;
1327: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 1328: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 1329: $env{'form.grade_symb'}=$symb;
1330: $env{'form.grade_domain'}=$udom;
1331: $env{'form.grade_username'}=$uname;
1332: $env{'form.grade_courseid'}=$env{'request.course.id'};
1333: &Apache::lonxml::initialize_rndseed($safeeval);
1334: }
1335:
1.31 albertel 1336: sub get_queue_data {
1.165 albertel 1337: my ($queue,$udom,$uname)=@_;
1.185 albertel 1338: my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1.165 albertel 1339: if (!$uname || !$udom) {
1340: $uname=$other_uname;
1341: $udom =$other_udom;
1342: }
1.31 albertel 1343: my $cnum=$env{'course.'.$cid.'.num'};
1344: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1345: my $todo="$symb\0queue\0$uname:$udom";
1.31 albertel 1346: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1347: if ($key eq $todo && ref($value)) {
1348: return $value;
1349: }
1350: return undef;
1351: }
1352:
1.84 albertel 1353:
1.49 albertel 1354: sub check_queue_for_key {
1.84 albertel 1355: my ($cdom,$cnum,$queue,$todo)=@_;
1356:
1.49 albertel 1357: my %results=
1358: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1359:
1360: if (exists($results{$todo}) && ref($results{$todo})) {
1361: if (defined($results{"$todo\0locked"})) {
1362: return 'locked';
1363: }
1.148 albertel 1364: if (my $slot=&slotted_access($results{$todo})) {
1.86 albertel 1365: my %slot_data=&Apache::lonnet::get_slot($slot);
1366: if ($slot_data{'endtime'} > time) {
1367: return 'in_progress';
1368: }
1.148 albertel 1369: } else {
1370: my ($symb) = &decode_queue_key($todo);
1371: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1372: if ($due_date > time) {
1373: return 'in_progress';
1374: }
1.58 albertel 1375: }
1.49 albertel 1376: return 'enqueued';
1377: }
1378: return undef;
1379: }
1380:
1.14 albertel 1381: sub add_to_queue {
1.82 albertel 1382: my ($queue,$user_data)=@_;
1.49 albertel 1383: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1384: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.82 albertel 1385: if (!$cid || $env{'request.state'} eq 'construct') {
1386: return 'no_queue';
1387: }
1.14 albertel 1388: my $cnum=$env{'course.'.$cid.'.num'};
1389: my $cdom=$env{'course.'.$cid.'.domain'};
1390: my %data;
1.138 albertel 1391: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83 albertel 1392: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14 albertel 1393: }
1394:
1.156 albertel 1395: sub get_limited_classlist {
1396: my ($sections) = @_;
1397:
1398: my $classlist = &Apache::loncoursedata::get_classlist();
1.157 albertel 1399: foreach my $student (keys(%$classlist)) {
1400: if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
1401: ne 'Active') {
1402: delete($classlist->{$student});
1403: }
1404: }
1.156 albertel 1405:
1.157 albertel 1406: if (ref($sections) && !grep('all',@{ $sections })) {
1.156 albertel 1407: foreach my $student (keys(%$classlist)) {
1408: my $section =
1409: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1410: if (! grep($section,@{ $sections })) {
1411: delete($classlist->{$student});
1412: }
1413: }
1414: }
1415: return $classlist;
1416: }
1417:
1418:
1.14 albertel 1419: sub show_queue {
1.32 albertel 1420: my ($queue,$with_selects)=@_;
1.14 albertel 1421: my $result;
1.185 albertel 1422: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 1423: my $cnum=$env{'course.'.$cid.'.num'};
1424: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 1425:
1426: my @chosen_sections=
1427: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1428:
1429: my $classlist = &get_limited_classlist(\@chosen_sections);
1430:
1.63 albertel 1431: if (!(grep(/^all$/,@chosen_sections))) {
1432: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1433: '</tt>.</p> '."\n";
1434: }
1.59 albertel 1435:
1.156 albertel 1436: my ($view,$view_section);
1437: my $scope = $env{'request.course.id'};
1438: if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
1439: $scope .= '/'.$env{'request.course.sec'};
1440: if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
1441: $view_section=$env{'request.course.sec'};
1442: } else {
1443: undef($view);
1444: }
1445: }
1446:
1.16 albertel 1447: my $regexp="^$symb\0";
1.30 albertel 1448: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 1449: my ($tmp)=%queue;
1450: if ($tmp=~/^error: 2 /) {
1.159 albertel 1451: return "\n<h3>Current Queue - $queue</h3>".
1452: &Apache::loncommon::start_data_table().
1453: &Apache::loncommon::start_data_table_row().
1454: '<td>'.&mt('Empty').'</td>'.
1455: &Apache::loncommon::end_data_table_row().
1456: &Apache::loncommon::end_data_table();
1.31 albertel 1457: }
1.103 albertel 1458: my $title=&Apache::lonnet::gettitle($symb);
1.159 albertel 1459: $result.="\n<h3>Current Queue - $title $queue </h3>".
1460: &Apache::loncommon::start_data_table().
1461: &Apache::loncommon::start_data_table_header_row();
1.103 albertel 1462: if ($with_selects) { $result.="<th>Status</th><th></th>"; }
1.159 albertel 1463: $result.="<th>user</th><th>data</th>".
1464: &Apache::loncommon::end_data_table_header_row();
1.14 albertel 1465: foreach my $key (sort(keys(%queue))) {
1.59 albertel 1466: my ($symb,$uname,$udom) = &decode_queue_key($key);
1467: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1.156 albertel 1468:
1469: my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1470:
1471: my $can_view=1;
1472: if (!$view
1473: || ($view_section && !$section)
1474: || ($view_section && $section && ($view_section ne $section))) {
1475: $can_view=0;
1476: }
1477:
1.32 albertel 1478: if ($key=~/locked$/ && !$with_selects) {
1.159 albertel 1479: $result.= &Apache::loncommon::start_data_table_row().
1480: "<td>$uname</td>";
1.103 albertel 1481: $result.='<td>'.$queue{$key}.'</td></tr>';
1.32 albertel 1482: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.159 albertel 1483: $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103 albertel 1484: $result.='<td>'.
1.16 albertel 1485: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 1486: } elsif ($key!~/(timestamp|locked)$/) {
1.159 albertel 1487: $result.= &Apache::loncommon::start_data_table_row();
1.148 albertel 1488: my ($end_time,$slot_text);
1489: if (my $slot=&slotted_access($queue{$key})) {
1490: my %slot_data=&Apache::lonnet::get_slot($slot);
1491: $end_time = $slot_data{'endtime'};
1492: $slot_text = &mt('Slot: [_1]',$slot);
1493: } else {
1494: $end_time = &Apache::lonhomework::due_date('0',$symb);
1495: $slot_text = '';
1496: }
1.32 albertel 1497: if ($with_selects) {
1.158 www 1498: my $ekey=&escape($key);
1.103 albertel 1499: my ($action,$description,$status)=('select',&mt('Select'));
1.32 albertel 1500: if (exists($queue{"$key\0locked"})) {
1.138 albertel 1501: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.103 albertel 1502: $status=&mt('Locked by <tt>[_1]</tt>',$queue{"$key\0locked"});
1.32 albertel 1503: if ($me eq $queue{"$key\0locked"}) {
1504: ($action,$description)=('resume',&mt('Resume'));
1505: } else {
1506: ($action,$description)=('unlock',&mt('Unlock'));
1507: }
1508: }
1.62 albertel 1509: my $seclist;
1510: foreach my $sec (@chosen_sections) {
1511: $seclist.='<input type="hidden" name="chosensections"
1512: value="'.$sec.'" />';
1513: }
1.156 albertel 1514: if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35 albertel 1515: $result.=(<<FORM);
1.103 albertel 1516: <td>$status</td>
1.32 albertel 1517: <td>
1.115 albertel 1518: <form style="display: inline" method="post">
1.32 albertel 1519: <input type="hidden" name="gradingkey" value="$ekey" />
1520: <input type="hidden" name="queue" value="$queue" />
1521: <input type="hidden" name="gradingaction" value="$action" />
1522: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 1523: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 1524: <input type="submit" name="submit" value="$description" />
1.62 albertel 1525: $seclist
1.32 albertel 1526: </form>
1527: </td>
1528: FORM
1.156 albertel 1529: } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
1530: $result.='<td>'.&mt("Not gradable").'</td><td> </td>'
1.35 albertel 1531: } else {
1.148 albertel 1532: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1.35 albertel 1533: }
1.32 albertel 1534: }
1.156 albertel 1535: $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138 albertel 1536: " <tt>($uname:$udom)</tt> </td>";
1.148 albertel 1537: $result.='<td>'.$slot_text.' End time: '.
1538: &Apache::lonlocal::locallocaltime($end_time).
1.159 albertel 1539: "</td>".&Apache::loncommon::end_data_table_row();
1.16 albertel 1540: }
1.14 albertel 1541: }
1.159 albertel 1542: $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14 albertel 1543: return $result;
1544: }
1545:
1.34 albertel 1546: sub get_queue_counts {
1547: my ($queue)=@_;
1548: my $result;
1.185 albertel 1549: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.34 albertel 1550: my $cnum=$env{'course.'.$cid.'.num'};
1551: my $cdom=$env{'course.'.$cid.'.domain'};
1.156 albertel 1552:
1.157 albertel 1553: my $classlist=&get_limited_classlist();
1.156 albertel 1554:
1.34 albertel 1555: my $regexp="^$symb\0";
1556: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1557: my ($tmp)=%queue;
1558: if ($tmp=~/^error: 2 /) {
1559: return (0,0,0);
1560: }
1561: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96 albertel 1562: my %slot_cache;
1.34 albertel 1563: foreach my $key (sort(keys(%queue))) {
1.156 albertel 1564: my ($symb,$uname,$udom) = &decode_queue_key($key);
1565: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1566:
1.34 albertel 1567: if ($key=~/locked$/) {
1568: $locks++;
1569: } elsif ($key=~/timestamp$/) {
1570: #ignore
1571: } elsif ($key!~/(timestamp|locked)$/) {
1572: $entries++;
1.148 albertel 1573: if (my $slot=&slotted_access($queue{$key})) {
1574: if (!exists($slot_cache{$slot})) {
1575: my %slot_data=&Apache::lonnet::get_slot($slot);
1576: $slot_cache{$slot} = \%slot_data;
1577: }
1578: if (time > $slot_cache{$slot}{'endtime'}) {
1579: $ready_to_grade++;
1580: }
1581: } else {
1582: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1583: if ($due_date ne '' && time > $due_date) {
1584: $ready_to_grade++;
1585: }
1.34 albertel 1586: }
1587: }
1588: }
1589: return ($entries,$ready_to_grade,$locks);
1590: }
1591:
1.49 albertel 1592: sub encode_queue_key {
1593: my ($symb,$udom,$uname)=@_;
1.138 albertel 1594: return "$symb\0queue\0$uname:$udom";
1.49 albertel 1595: }
1596:
1.14 albertel 1597: sub decode_queue_key {
1598: my ($key)=@_;
1599: my ($symb,undef,$user) = split("\0",$key);
1.138 albertel 1600: my ($uname,$udom) = split(':',$user);
1.14 albertel 1601: return ($symb,$uname,$udom);
1602: }
1603:
1604: sub queue_key_locked {
1.30 albertel 1605: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1606: if (!defined($cdom) || !defined($cnum)) {
1.185 albertel 1607: my (undef,$cid)=&Apache::lonnet::whichuser();
1.33 albertel 1608: $cnum=$env{'course.'.$cid.'.num'};
1609: $cdom=$env{'course.'.$cid.'.domain'};
1610: }
1.14 albertel 1611: my ($key_locked,$value)=
1.30 albertel 1612: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1613: if ($key_locked eq "$key\0locked") {
1614: return $value;
1615: }
1616: return undef;
1617: }
1618:
1.148 albertel 1619: sub slotted_access {
1620: my ($queue_entry) = @_;
1621: if (ref($queue_entry) eq 'ARRAY') {
1622: if (defined($queue_entry->[0])) {
1623: return $queue_entry->[0];
1624: }
1625: return undef;
1626: } elsif (ref($queue_entry) eq 'HASH') {
1627: if (defined($queue_entry->{'slot'})) {
1628: return $queue_entry->{'slot'};
1629: }
1630: return undef;
1631: }
1632: return undef;
1633: }
1634:
1.14 albertel 1635: sub pick_from_queue_data {
1.156 albertel 1636: my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98 albertel 1637: my @possible; # will hold queue entries that are valid to be selected
1.30 albertel 1638: foreach my $key (keys(%$queuedata)) {
1.68 albertel 1639: if ($key =~ /\0locked$/) { next; }
1640: if ($key =~ /\0timestamp$/) { next; }
1.156 albertel 1641:
1.14 albertel 1642: my ($symb,$uname,$udom)=&decode_queue_key($key);
1.156 albertel 1643: if (!defined($classlist->{$uname.':'.$udom})) { next; }
1644:
1.14 albertel 1645: if ($check_section) {
1.156 albertel 1646: my $section =
1647: $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17 albertel 1648: if ($section eq $check_section) {
1.33 albertel 1649: &Apache::lonxml::debug("my sec");
1.15 albertel 1650: next;
1651: }
1.14 albertel 1652: }
1.148 albertel 1653: my $end_time;
1654: if (my $slot=&slotted_access($queuedata->{$key})) {
1.154 albertel 1655: &Apache::lonxml::debug("looking at slot $slot");
1.148 albertel 1656: my %slot_data=&Apache::lonnet::get_slot($slot);
1657: if ($slot_data{'endtime'} < time) {
1658: $end_time = $slot_data{'endtime'};
1.154 albertel 1659: } else {
1660: &Apache::lonxml::debug("not time ".$slot_data{'endtime'});
1661: next;
1.148 albertel 1662: }
1663: } else {
1664: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154 albertel 1665: if ($due_date < time) {
1.148 albertel 1666: $end_time = $due_date;
1.154 albertel 1667: } else {
1668: &Apache::lonxml::debug("not time $due_date");
1669: next;
1.148 albertel 1670: }
1671: }
1672:
1.98 albertel 1673: if (exists($queuedata->{"$key\0locked"})) {
1.33 albertel 1674: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1675: next;
1676: }
1.148 albertel 1677: push(@possible,[$key,$end_time]);
1.98 albertel 1678: }
1679: if (@possible) {
1680: # sort entries in order by slot end time
1681: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137 albertel 1682: # pick one of the entries in the top 10% in small queues and one
1683: # of the first ten entries in large queues
1.139 albertel 1684: #my $ten_percent = int($#possible * 0.1);
1685: #if ($ten_percent < 1 ) { $ten_percent = 1; }
1686: #if ($ten_percent > 10) { $ten_percent = 10; }
1687: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137 albertel 1688:
1.139 albertel 1689: #return $possible[int(rand($max))][0];
1690: return $possible[0][0];
1.14 albertel 1691: }
1692: return undef;
1693: }
1694:
1.15 albertel 1695: sub find_mid_grade {
1.30 albertel 1696: my ($queue,$symb,$cdom,$cnum)=@_;
1.158 www 1697: my $todo=&unescape($env{'form.gradingkey'});
1.138 albertel 1698: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15 albertel 1699: if ($todo) {
1.30 albertel 1700: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1701: if ($who eq $me) { return $todo; }
1702: }
1703: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1704: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1705: foreach my $key (keys(%locks)) {
1706: my $who=$locks{$key};
1707: if ($who eq $me) {
1708: $todo=$key;
1709: $todo=~s/\0locked$//;
1710: return $todo;
1711: }
1712: }
1713: return undef;
1714: }
1715:
1.32 albertel 1716: sub lock_key {
1717: my ($queue,$todo)=@_;
1.138 albertel 1718: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.185 albertel 1719: my (undef,$cid)=&Apache::lonnet::whichuser();
1.32 albertel 1720: my $cnum=$env{'course.'.$cid.'.num'};
1721: my $cdom=$env{'course.'.$cid.'.domain'};
1722: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
1723: $cdom,$cnum);
1.33 albertel 1724: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1725: if ($success eq 'ok') {
1726: return 1;
1727: }
1728: return 0;
1729: }
1730:
1.86 albertel 1731: sub get_queue_symb_status {
1.85 albertel 1732: my ($queue,$symb,$cdom,$cnum) = @_;
1733: if (!defined($cdom) || !defined($cnum)) {
1.185 albertel 1734: my (undef,$cid)=&Apache::lonnet::whichuser();
1.85 albertel 1735: $cnum=$env{'course.'.$cid.'.num'};
1736: $cdom=$env{'course.'.$cid.'.domain'};
1737: }
1.157 albertel 1738: my $classlist=&get_limited_classlist();
1.156 albertel 1739:
1.85 albertel 1740: my $regexp="^$symb\0";
1741: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1742: my ($tmp)=%queue;
1743: if ($tmp=~/^error: 2 /) { return; }
1744: my @users;
1745: foreach my $key (sort(keys(%queue))) {
1746: next if ($key=~/locked$/);
1747: next if ($key=~/timestamp$/);
1748: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156 albertel 1749: next if (!defined($classlist->{$uname.':'.$udom}));
1.85 albertel 1750: push(@users,"$uname:$udom");
1751: }
1752: return @users;
1753: }
1754:
1.14 albertel 1755: sub get_from_queue {
1.30 albertel 1756: my ($queue)=@_;
1.14 albertel 1757: my $result;
1.185 albertel 1758: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 1759: my $cnum=$env{'course.'.$cid.'.num'};
1760: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1761: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1762: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1763: if ($todo) { return $todo; }
1.95 albertel 1764: my $attempts=0;
1.156 albertel 1765:
1.157 albertel 1766: my $classlist=&get_limited_classlist();
1.156 albertel 1767:
1.14 albertel 1768: while (1) {
1.95 albertel 1769: if ($attempts > 2) {
1770: # tried twice to get a queue entry, giving up
1771: return (undef,'unable');
1772: }
1.14 albertel 1773: my $starttime=time;
1.83 albertel 1774: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
1775: $cdom,$cnum);
1.33 albertel 1776: &Apache::lonxml::debug("$starttime");
1.14 albertel 1777: my $regexp="^$symb\0queue\0";
1.156 albertel 1778: #my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97 albertel 1779:
1.98 albertel 1780: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1781: #make a pass looking for a user _not_ in my section
1.14 albertel 1782: if ($env{'request.course.sec'}) {
1.33 albertel 1783: &Apache::lonxml::debug("sce");
1.30 albertel 1784: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156 albertel 1785: \%queue,$cdom,$cnum,$classlist);
1.33 albertel 1786: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1787: }
1.33 albertel 1788: # no one _not_ in our section so look for any user that is
1789: # ready for grading
1.14 albertel 1790: if (!$todo) {
1.33 albertel 1791: &Apache::lonxml::debug("no sce");
1.156 albertel 1792: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
1793: $classlist);
1.33 albertel 1794: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1795: }
1796: # no user to grade
1797: if (!$todo) { last; }
1.33 albertel 1798: &Apache::lonxml::debug("got $todo");
1.14 albertel 1799: # otherwise found someone so lets try to lock them
1.32 albertel 1800: # unless someone else already picked them
1.95 albertel 1801: if (!&lock_key($queue,$todo)) {
1802: $attempts++;
1803: next;
1804: }
1.14 albertel 1805: my (undef,$endtime)=
1.30 albertel 1806: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 1807: $cdom,$cnum);
1.33 albertel 1808: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 1809: # someone else already modified the queue,
1810: # perhaps our picked user wass already fully graded between
1811: # when we picked him and when we locked his record? so lets
1812: # double check.
1813: if ($endtime != $starttime) {
1814: my ($key,$value)=
1.30 albertel 1815: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 1816: $cdom,$cnum);
1.33 albertel 1817: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 1818: if ($key eq $todo && ref($value)) {
1819: } else {
1.30 albertel 1820: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 1821: $cdom,$cnum);
1.33 albertel 1822: &Apache::lonxml::debug("del");
1.95 albertel 1823: $attempts++;
1.14 albertel 1824: next;
1825: }
1826: }
1.33 albertel 1827: &Apache::lonxml::debug("last $todo");
1.14 albertel 1828: last;
1829: }
1830: return $todo;
1831: }
1832:
1.49 albertel 1833: sub select_user {
1.185 albertel 1834: my ($symb,$cid)=&Apache::lonnet::whichuser();
1.49 albertel 1835:
1.59 albertel 1836: my @chosen_sections=
1837: &Apache::loncommon::get_env_multiple('form.chosensections');
1.156 albertel 1838:
1839: my $classlist = &get_limited_classlist(\@chosen_sections);
1.63 albertel 1840:
1841: my $result;
1842: if (!(grep(/^all$/,@chosen_sections))) {
1843: $result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
1844: '</tt>.</p> '."\n";
1845: }
1.159 albertel 1846: $result.=&Apache::loncommon::start_data_table();
1.49 albertel 1847:
1.156 albertel 1848: foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49 albertel 1849: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 1850:
1.84 albertel 1851: my $cnum=$env{'course.'.$cid.'.num'};
1852: my $cdom=$env{'course.'.$cid.'.domain'};
1.88 albertel 1853: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
1854: 'Task');
1.49 albertel 1855: my $queue = 'none';
1.58 albertel 1856: my $cannot_grade;
1857: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1858: $queue = 'reviewqueue';
1.58 albertel 1859: if ($status{'reviewqueue'} eq 'in_progress') {
1860: $cannot_grade=1;
1861: }
1862: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 1863: $queue = 'gradingqueue';
1.58 albertel 1864: if ($status{'gradingqueue'} eq 'in_progress') {
1865: $cannot_grade=1;
1866: }
1.49 albertel 1867: }
1868: my $todo =
1.158 www 1869: &escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 1870: if ($cannot_grade) {
1.159 albertel 1871: $result.=&Apache::loncommon::start_data_table_row().
1872: '<td> </td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58 albertel 1873: '</td><td>';
1874: } else {
1.62 albertel 1875: my $seclist;
1876: foreach my $sec (@chosen_sections) {
1877: $seclist.='<input type="hidden" name="chosensections"
1878: value="'.$sec.'" />';
1879: }
1.159 albertel 1880: $result.=&Apache::loncommon::start_data_table_row();
1.58 albertel 1881: $result.=<<RESULT;
1.49 albertel 1882: <td>
1.115 albertel 1883: <form style="display: inline" method="post">
1.49 albertel 1884: <input type="hidden" name="gradingkey" value="$todo" />
1885: <input type="hidden" name="queue" value="$queue" />
1886: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 1887: <input type="hidden" name="regrade" value="yes" />
1.62 albertel 1888: <input type="submit" name="submit" value="Regrade" />
1889: $seclist
1.49 albertel 1890: </form>
1.155 albertel 1891: <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
1.49 albertel 1892: <td>
1893: RESULT
1.58 albertel 1894: }
1.49 albertel 1895: if ($status{'status'} eq 'pass') {
1896: $result .= '<font color="green">'.&mt('Passed').'</font>';
1897: } elsif ($status{'status'} eq 'fail') {
1898: $result .= '<font color="red">'.&mt('Failed').'</font>';
1899: } elsif ($status{'status'} eq 'review') {
1900: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
1901: } elsif ($status{'status'} eq 'ungraded') {
1902: $result .= &mt('Ungraded');
1903: } elsif ($status{'status'} ne '') {
1904: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
1905: } else {
1906: $result.=" ";
1907: }
1908: if ($status{'version'}) {
1909: $result .= ' '.&mt('Version').' '.$status{'version'};
1910: }
1.101 albertel 1911: if ($status{'grader'}) {
1912: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
1913: }
1.49 albertel 1914: $result.= '</td><td>';
1915: if ($status{'reviewqueue'} eq 'enqueued') {
1916: $result .= &mt('Awaiting Review');
1917: } elsif ($status{'reviewqueue'} eq 'locked') {
1918: $result .= &mt('Under Review');
1.58 albertel 1919: } elsif ($status{'reviewqueue'} eq 'in_progress') {
1920: $result .= &mt('Still being worked on.');
1.49 albertel 1921: } elsif ($status{'gradingqueue'} eq 'enqueued') {
1922: $result .= &mt('Awaiting Grading');
1923: } elsif ($status{'gradingqueue'} eq 'locked') {
1924: $result .= &mt('Being Graded');
1.58 albertel 1925: } elsif ($status{'gradingqueue'} eq 'in_progress') {
1926: $result .= &mt('Still being worked on.');
1.49 albertel 1927: } else {
1928: $result.=" ";
1929: }
1.159 albertel 1930: $result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49 albertel 1931: }
1.159 albertel 1932: $result.=&Apache::loncommon::end_data_table();
1.49 albertel 1933: return $result;
1934: }
1935:
1936: sub get_student_status {
1.86 albertel 1937: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
1938:
1939: my %status;
1940:
1941: if ($type eq 'Task') {
1942: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49 albertel 1943: $udom,$uname);
1.89 albertel 1944: $status{'status'}=$record{'resource.0.status'};
1945: $status{'version'}=$record{'resource.0.version'};
1946: $status{'grader'}=$record{'resource.0.regrader'};
1.86 albertel 1947: }
1948: $status{'reviewqueue'}=
1949: &check_queue_for_key($cdom,$cnum,'reviewqueue',
1950: &encode_queue_key($symb,$udom,$uname));
1951: $status{'gradingqueue'}=
1952: &check_queue_for_key($cdom,$cnum,'gradingqueue',
1953: &encode_queue_key($symb,$udom,$uname));
1.49 albertel 1954: return %status;
1955: }
1956:
1.1 albertel 1957: sub start_ClosingParagraph {
1958: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1959: my $result;
1960: if ($target eq 'web') {
1.13 albertel 1961: } elsif ($target eq 'webgrade') {
1962: &Apache::lonxml::startredirection();
1.1 albertel 1963: }
1964: return $result;
1965: }
1966:
1967: sub end_ClosingParagraph {
1968: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1969: my $result;
1970: if ($target eq 'web') {
1.13 albertel 1971: } elsif ($target eq 'webgrade') {
1972: &Apache::lonxml::endredirection();
1.1 albertel 1973: }
1974: return $result;
1975: }
1976:
1.168 albertel 1977: sub get_dim_id {
1978: return $Apache::bridgetask::dimension[-1];
1979: }
1980:
1.19 albertel 1981: sub get_id {
1982: my ($parstack,$safeeval)=@_;
1983: my $id=&Apache::lonxml::get_param('id',$parstack,$safeeval);
1984: if (!$id) { $id=$Apache::lonxml::curdepth; }
1985: return $id;
1986: }
1987:
1.162 albertel 1988: sub start_Setup {
1989: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 1990: #undef(%dimension);
1991: my $dim = &get_id($parstack,$safeeval);
1992: push(@Apache::bridgetask::dimension,$dim);
1.162 albertel 1993: &Apache::lonxml::startredirection();
1.168 albertel 1994: return &internal_location($dim);
1.162 albertel 1995: }
1.173 albertel 1996:
1997: {
1998: my @allowed;
1999: sub enable_dimension_parsing {
2000: my ($id) = @_;
2001: push(@allowed,$id);
2002: }
2003: sub disable_dimension_parsing {
2004: pop(@allowed);
2005: }
2006: sub skip_dimension_parsing {
2007: my ($check) = @_;
2008: if (!@allowed) { return 0;}
2009: # if unspecified allow any id
2010: if ($allowed[-1] eq undef) { return 0;}
2011:
2012: return ($check ne $allowed[-1]);
2013: }
2014: }
2015:
1.151 albertel 2016: sub start_Question { return &start_Dimension(@_); }
1.1 albertel 2017: sub start_Dimension {
1.173 albertel 2018: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2019: my $dim = &get_id($parstack,$safeeval);
2020: my $previous_dim;
2021: if (@Apache::bridgetask::dimension) {
2022: $previous_dim = $Apache::bridgetask::dimension[-1];
2023: push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
2024: $dim);
1.173 albertel 2025: if(&skip_dimension_parsing($dim)) {
2026: $dimension{$previous_dim}{'criteria.'.$dim} =
2027: $token->[4]
2028: .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
2029: $style)
2030: .'</'.$tagstack->[-1].'>';
2031: }
1.169 albertel 2032: $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
2033: $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
2034: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2035: push(@{$dimension{$previous_dim}{'criterias'}},$dim);
1.171 albertel 2036: $dimension{$dim}{'nested'}=$previous_dim;
1.172 albertel 2037: &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
1.168 albertel 2038: } else {
2039: $Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}=
2040: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2041: }
2042: push(@Apache::bridgetask::dimension,$dim);
1.54 albertel 2043: &Apache::lonxml::startredirection();
1.173 albertel 2044: &enable_dimension_parsing($dim);
1.168 albertel 2045: return &internal_location($dim);
1.1 albertel 2046: }
2047:
1.160 albertel 2048: sub start_QuestionText {
2049: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2050: my $dim = &get_dim_id();
1.160 albertel 2051: my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
2052: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2053: $dimension{$dim}{'questiontext'}=$text;
1.160 albertel 2054: }
2055: return '';
2056: }
2057:
2058: sub end_QuestionText {
2059: return '';
2060: }
2061:
1.13 albertel 2062: sub get_instance {
1.75 albertel 2063: my ($dim)=@_;
2064: my $rand_alg=&Apache::lonnet::get_rand_alg();
2065: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
2066: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
2067: $rand_alg eq '64bit4' ) {
2068: &Apache::response::pushrandomnumber();
1.169 albertel 2069: my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75 albertel 2070: my $num=@order;
2071: my $version=&get_version();
2072: my $which=($version-1)%$num;
2073: return $order[$which];
2074: } else {
2075: my ($version,$previous) = &get_version();
2076: my $instance =
2077: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
2078: if (defined($instance)) { return $instance; }
2079:
2080: &Apache::response::pushrandomnumber();
1.173 albertel 2081: if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
2082: my @instances = @{$dimension{$dim}{'instances'}};
2083: # remove disabled instances
2084: for (my $i=0; $i < $#instances; $i++) {
2085: if ($dimension{$dim}{$instances[$i].'.disabled'}) {
2086: splice(@instances,$i,1);
2087: $i--;
2088: }
2089: }
2090: @instances = &Math::Random::random_permutation(@instances);
2091: $instance = $instances[($version-1)%scalar(@instances)];
2092: if ($version =~ /^\d$/) {
2093: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
2094: $instance;
2095: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
1.75 albertel 2096: }
2097: }
2098: &Apache::response::poprandomnumber();
2099: return $instance;
2100: }
1.13 albertel 2101: }
2102:
1.169 albertel 2103: sub get_criteria {
2104: my ($what,$version,$dim,$id) = @_;
2105: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2106: my $prefix = ($type eq 'criteria') ? "$dim.$id"
2107: : "$id";
2108: my $entry = "resource.$version.0.$prefix.$what";
2109: if (exists($Apache::lonhomework::results{$entry})) {
2110: return $Apache::lonhomework::results{$entry};
2111: }
2112: return $Apache::lonhomework::history{$entry};
2113: }
2114:
1.18 albertel 2115: {
2116: my $last_link;
1.122 albertel 2117: sub link {
1.151 albertel 2118: my ($id) = @_;
2119: $id =~ s/\./_/g;
2120: return 'LC_GRADING_criteria_'.$id;
1.122 albertel 2121: }
1.151 albertel 2122: sub end_Question { return &end_Dimension(@_); }
1.18 albertel 2123: sub end_Dimension {
2124: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.54 albertel 2125: my $result=&Apache::lonxml::endredirection();
1.25 albertel 2126: my $dim=&get_id($parstack,$safeeval);
1.173 albertel 2127: if (&skip_dimension_parsing($dim)) {
2128: &disable_dimension_parsing($dim);
2129: pop(@Apache::bridgetask::dimension);
2130: return;
2131: }
1.75 albertel 2132: my $instance=&get_instance($dim);
1.25 albertel 2133: my $version=&get_version();
1.18 albertel 2134: if ($target eq 'web') {
1.173 albertel 2135: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
1.76 albertel 2136: my @instances = $instance;
2137: if (&Apache::response::showallfoils()) {
1.169 albertel 2138: @instances = @{$dimension{$dim}{'instances'}};
1.76 albertel 2139: }
1.160 albertel 2140: my $shown_question_text;
1.76 albertel 2141: foreach my $instance (@instances) {
1.173 albertel 2142: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2143: [@_]);
2144: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2145: [@_],{'set_dim_id' => undef});
1.169 albertel 2146: my $task_status =
2147: $Apache::lonhomework::history{"resource.$version.0.status"};
1.173 albertel 2148: if ($task_status ne 'pass' && $task_status ne 'fail') {
1.76 albertel 2149:
1.173 albertel 2150: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2151: @{$dimension{$dim}{'criterias'}}) {
2152: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2153: &Apache::lonxml::debug("$id is $type");
2154: if ($type eq 'dimension') {
2155: $result.=
2156: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2157: [@_],{'set_dim_id' => $id});
2158: }
2159: }
2160: } else {
1.89 albertel 2161: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
1.76 albertel 2162: my $mandatory='Mandatory';
2163: if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
2164: $mandatory='Optional';
2165: }
1.116 albertel 2166: my $dim_info="<div class='LC_$dim_status LC_question_grade'>\n";
1.76 albertel 2167: if ($dim_status eq 'pass') {
2168: $dim_info.='<h3>Question : you passed this '.$mandatory.' question</h3>';
1.54 albertel 2169: }
1.76 albertel 2170: if ($dim_status eq 'fail') {
2171: $dim_info.='<h3>Question : you did not pass this '.$mandatory.' question</h3>';
1.53 albertel 2172: }
1.76 albertel 2173: my $man_count=0;
2174: my $man_passed=0;
2175: my $opt_count=0;
2176: my $opt_passed=0;
1.169 albertel 2177: foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
2178: @{$dimension{$dim}{'criterias'}} ) {
2179: my $status = &get_criteria('status',$version,$dim,$id);
2180: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
1.76 albertel 2181: eq 'N') {
2182: $opt_count++;
1.169 albertel 2183: if ($status eq 'pass') { $opt_passed++; }
1.76 albertel 2184: } else {
2185: $man_count++;
1.169 albertel 2186: if ($status eq 'pass') { $man_passed++; }
1.76 albertel 2187: }
1.22 albertel 2188: }
1.76 albertel 2189: if ($man_passed eq $man_count) { $man_passed='all'; }
1.151 albertel 2190:
1.169 albertel 2191: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151 albertel 2192: if ($opt_req !~ /\S/) {
2193: $opt_req=
2194: &Apache::lonxml::get_param('OptionalRequired',
2195: $parstack,$safeeval);
2196: if ($opt_req !~ /\S/) { $opt_req = 0; }
2197: }
1.76 albertel 2198: $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>";
2199:
2200: my $internal_location=&internal_location($dim);
2201: $result=~s/\Q$internal_location\E/$dim_info/;
2202:
1.169 albertel 2203: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2204: @{$dimension{$dim}{'criterias'}}) {
2205: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171 albertel 2206: if ($type eq 'dimension') {
2207: $result.=$dimension{$id}{'result'};
2208: next;
2209: }
1.169 albertel 2210: my $status= &get_criteria('status', $version,$dim,$id);
2211: my $comment=&get_criteria('comment',$version,$dim,$id);
2212: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.76 albertel 2213: if ($mandatory) {
2214: $mandatory='Mandatory';
2215: } else {
2216: $mandatory='Optional';
2217: }
2218: if ($status eq 'fail') {
2219: } elsif ($status eq 'pass') {
2220: } else {
2221: &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
2222: }
2223: my $status_display=$status;
2224: $status_display=~s/^([a-z])/uc($1)/e;
1.116 albertel 2225: $result.=
2226: '<div class="LC_'.$status.' LC_criteria"><h4>'
2227: .$mandatory.' Criteria</h4><p>';
1.173 albertel 2228: $result.=
2229: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2230: [@_],{'set_dim_id' => $id});
1.116 albertel 2231: $result.='</p><p class="LC_grade">'.$status_display.'</p>';
1.169 albertel 2232: if ($comment) {
2233: $result.='<p class="LC_comment">'.
2234: &mt('Comment: [_1]',$comment).'</p>';
1.76 albertel 2235: }
2236: $result.='</div>';
1.22 albertel 2237: }
2238: }
2239: }
1.18 albertel 2240: } elsif ($target eq 'webgrade') {
1.47 albertel 2241: # in case of any side effects that we need
1.173 albertel 2242: &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2243: &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
2244: $result.=
2245: &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
1.180 albertel 2246: {'set_dim_id' => undef,
2247: 'delayed_dim_results' => 1});
1.169 albertel 2248: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2249: @{$dimension{$dim}{'criterias'}} ) {
2250: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.171 albertel 2251: if ($type eq 'dimension') {
2252: # dimensional 'criteria' don't get assigned grades
1.173 albertel 2253: $result.=
2254: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2255: [@_],{'set_dim_id' => $id});
1.171 albertel 2256: next;
2257: }
1.169 albertel 2258:
1.151 albertel 2259: my $link=&link($id);
1.169 albertel 2260: my $status= &get_criteria('status',$version,$dim,$id);
1.120 albertel 2261: $result.='<div class="LC_GRADING_criteria" id="'.$link.'">'."\n".
1.136 albertel 2262: '<div class="LC_GRADING_criteriatext" id="next_'.$last_link.'">'."\n";
1.173 albertel 2263: $result.=
2264: &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]);
2265:
1.111 albertel 2266: $result.='</div>'."\n".
1.120 albertel 2267: '<div class="LC_GRADING_grade">'."\n".
2268: '<label class="LC_GRADING_ungraded"><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').' />'.&mt('Ungraded').'</label>'."\n".
2269: '<label class="LC_GRADING_fail"><input type="radio" name="HWVAL_'.$link.'" value="fail" '.($status eq 'fail' ? 'checked="checked"':'').' />'.&mt('Fail').'</label>'."\n".
2270: '<label class="LC_GRADING_pass"><input type="radio" name="HWVAL_'.$link.'" value="pass" '.($status eq 'pass' ? 'checked="checked"':'').' />'.&mt('Pass').'</label>'."\n".
2271: '<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 2272: '</div>'."\n".
1.120 albertel 2273: '<label class="LC_GRADING_comment">'.&mt('Additional Comment for Student')."\n".
1.169 albertel 2274: '<textarea class="LC_GRADING_comment_area" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode(&get_criteria('comment',$version,$dim,$id),'<>"&').'</textarea>'."\n".
1.111 albertel 2275: '</label>'."\n".
1.120 albertel 2276: '<ul class="LC_GRADING_navbuttons">'."\n".
1.111 albertel 2277: '<li><a href="#'.$last_link.'">Prev</a></li>'."\n".
2278: '<li><a href="#next_'.$link.'">Next</a></li>'."\n".
2279: '</ul>'."\n".
2280: '</div>'."\n";
1.151 albertel 2281: $result.=&grading_history($version,$dim,$id);
1.18 albertel 2282: $last_link=$link;
2283: }
1.180 albertel 2284: if (&nest()) {
1.173 albertel 2285: &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
2286: $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
1.171 albertel 2287: undef($result);
2288: }
1.22 albertel 2289: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
1.19 albertel 2290: my $optional_passed=0;
1.20 albertel 2291: my $mandatory_failed=0;
2292: my $ungraded=0;
2293: my $review=0;
1.153 albertel 2294:
1.173 albertel 2295: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2296: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2297: [@_]);
2298: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2299: [@_],{'set_dim_id' => undef});
1.160 albertel 2300:
1.169 albertel 2301: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2302: @{$dimension{$dim}{'criterias'}}) {
1.151 albertel 2303: my $link=&link($id);
1.169 albertel 2304:
2305: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2306: if ($type eq 'criteria') {
2307: # dimensional 'criteria' don't get assigned grades
2308: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
2309: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1.173 albertel 2310: } else {
2311: $result .=
2312: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2313: [@_],{'set_dim_id' => $id});
1.169 albertel 2314: }
2315: my $status= &get_criteria('status',$version,$dim,$id);
2316:
2317: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1.20 albertel 2318: if ($status eq 'pass') {
2319: if (!$mandatory) { $optional_passed++; }
2320: } elsif ($status eq 'fail') {
2321: if ($mandatory) { $mandatory_failed++; }
1.21 albertel 2322: } elsif ($status eq 'review') {
2323: $review++;
1.20 albertel 2324: } elsif ($status eq 'ungraded') {
2325: $ungraded++;
1.21 albertel 2326: } else {
1.47 albertel 2327: $ungraded++;
1.19 albertel 2328: }
2329: }
1.151 albertel 2330: # FIXME optional required can apply to only <instance> right now...
1.169 albertel 2331: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
1.151 albertel 2332: if ($opt_req !~ /\S/) {
2333: $opt_req=
2334: &Apache::lonxml::get_param('OptionalRequired',
2335: $parstack,$safeeval);
2336: if ($opt_req !~ /\S/) { $opt_req = 0; }
2337: }
2338: if ($optional_passed < $opt_req) {
1.20 albertel 2339: $mandatory_failed++;
2340: }
1.169 albertel 2341: &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 2342: if ($review) {
1.89 albertel 2343: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2344: 'review';
1.20 albertel 2345: } elsif ($ungraded) {
1.89 albertel 2346: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2347: 'ungraded';
1.20 albertel 2348: } elsif ($mandatory_failed) {
1.89 albertel 2349: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2350: 'fail';
1.20 albertel 2351: } else {
1.91 albertel 2352: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
1.22 albertel 2353: 'pass';
1.20 albertel 2354: }
1.69 albertel 2355: } else {
2356: # any other targets no output
2357: undef($result);
1.13 albertel 2358: }
1.173 albertel 2359: &disable_dimension_parsing();
1.169 albertel 2360: pop(@Apache::bridgetask::dimension);
1.18 albertel 2361: return $result;
1.1 albertel 2362: }
1.162 albertel 2363:
2364: sub end_Setup {
2365: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2366: my $result=&Apache::lonxml::endredirection();
2367: my $dim=&get_id($parstack,$safeeval);
2368: my $instance=&get_instance($dim);
2369: my $version=&get_version();
2370: if ($target eq 'web') {
2371: @Apache::scripttag::parser_env = @_;
1.169 albertel 2372: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162 albertel 2373: my @instances = $instance;
2374: if (&Apache::response::showallfoils()) {
1.169 albertel 2375: @instances = @{$dimension{$dim}{'instances'}};
1.162 albertel 2376: }
2377: foreach my $instance (@instances) {
2378: @Apache::scripttag::parser_env = @_;
1.169 albertel 2379: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2380: @Apache::scripttag::parser_env = @_;
1.169 albertel 2381: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2382: }
2383: } elsif ($target eq 'webgrade'
2384: || $target eq 'grade' && $env{'form.webgrade'}) {
2385: # in case of any side effects that we need
2386: @Apache::scripttag::parser_env = @_;
1.169 albertel 2387: &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
1.162 albertel 2388: @Apache::scripttag::parser_env = @_;
1.169 albertel 2389: &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2390: @Apache::scripttag::parser_env = @_;
1.169 albertel 2391: &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2392: } else {
2393: # any other targets no output
2394: undef($result);
2395: }
1.169 albertel 2396: pop(@Apache::bridgetask::dimension);
1.162 albertel 2397: return $result;
2398: }
1.1 albertel 2399: }
2400:
1.113 albertel 2401: sub grading_history {
1.151 albertel 2402: my ($version,$dim,$id) = @_;
1.113 albertel 2403: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
2404: return '';
2405: }
2406: my ($result,$grader);
1.151 albertel 2407: my $scope="resource.$version.0.$dim.$id";
1.113 albertel 2408: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
2409: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
2410: my ($gname,$gdom) =
1.138 albertel 2411: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113 albertel 2412: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
2413: $grader = &Apache::loncommon::aboutmewrapper($fullname,
2414: $gname,$gdom);
2415: }
2416: my $entry;
2417: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
2418: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
2419: }
2420: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
2421: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
2422: }
2423: if ($entry) {
2424: $result.= "<li>$grader : $entry </li>";
2425: }
2426: }
2427: if ($result) {
1.120 albertel 2428: return '<ul class="LC_GRADING_pastgrading">'.$result.'</ul>';
1.113 albertel 2429: }
2430: return '';
2431: }
2432:
1.1 albertel 2433: sub start_IntroParagraph {
1.87 albertel 2434: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 2435: my $result;
1.168 albertel 2436: my $dim = &get_dim_id();
1.153 albertel 2437: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151 albertel 2438: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169 albertel 2439: $dimension{$dim}{'intro'}=
1.151 albertel 2440: &Apache::lonxml::get_all_text('/introparagraph',
2441: $parser,$style);
2442: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2443: &Apache::lonxml::startredirection();
1.1 albertel 2444: }
1.47 albertel 2445:
1.1 albertel 2446: }
2447: return $result;
2448: }
2449:
2450: sub end_IntroParagraph {
1.127 albertel 2451: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128 albertel 2452: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2453: my $result = &Apache::lonxml::endredirection();
2454: }
1.1 albertel 2455: }
2456:
2457: sub start_Instance {
2458: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 2459: my $dim = &get_dim_id();
2460: my $id = &get_id($parstack,$safeeval);
1.169 albertel 2461: push(@{$dimension{$dim}{'instances'}},$id);
1.168 albertel 2462: push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19 albertel 2463: push(@Apache::bridgetask::instancelist,$id);
1.169 albertel 2464: $dimension{$dim}{$id.'.optionalrequired'}=
1.19 albertel 2465: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75 albertel 2466: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2467: if (lc($disabled) eq 'yes') {
1.169 albertel 2468: $dimension{$dim}{$id.'.disabled'}='1';
1.75 albertel 2469: }
1.1 albertel 2470: return '';
2471: }
2472:
2473: sub end_Instance {
2474: }
2475:
2476: sub start_InstanceText {
1.87 albertel 2477: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2478: my $dim = &get_dim_id();
2479: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.87 albertel 2480: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
1.153 albertel 2481: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.169 albertel 2482: $dimension{$dim}{$instance_id.'.text'}=$text;
1.1 albertel 2483: }
2484: return '';
2485: }
2486:
2487: sub end_InstanceText {
2488: return '';
2489: }
2490:
2491: sub start_Criteria {
1.87 albertel 2492: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2493: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.21 albertel 2494: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.168 albertel 2495: my $dim = &get_dim_id();
1.19 albertel 2496: my $id=&get_id($parstack,$safeeval);
1.169 albertel 2497: &Apache::lonxml::debug("Criteria $id with $dim");
1.151 albertel 2498: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168 albertel 2499: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 2500: $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
2501: $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
2502: $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151 albertel 2503: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2504: push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151 albertel 2505: } else {
1.169 albertel 2506: $dimension{$dim}{'criteria.'.$id}=$criteria;
2507: $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
2508: $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151 albertel 2509: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2510: push(@{$dimension{$dim}{'criterias'}},$id);
1.151 albertel 2511: }
1.1 albertel 2512: }
2513: return '';
2514: }
2515:
1.47 albertel 2516: sub end_Criteria {
2517: }
2518:
1.186 ! albertel 2519: sub start_GraderNote {
! 2520: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 2521:
! 2522: if ($target eq 'webgrade') {
! 2523: return '<div class="LC_GRADING_gradernote">';
! 2524: }
! 2525: my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style);
! 2526: return;
! 2527: }
! 2528:
! 2529: sub end_GraderNote {
! 2530: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 2531:
! 2532: if ($target eq 'webgrade') {
! 2533: return '</div>';
! 2534: }
! 2535: return;
! 2536: }
! 2537:
! 2538:
! 2539:
1.4 albertel 2540: sub proctor_validation_screen {
2541: my ($slot) = @_;
1.185 albertel 2542: my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
1.5 albertel 2543: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.44 albertel 2544: my $name=&Apache::loncommon::plainname($user,$domain);
2545:
1.4 albertel 2546: my $msg;
1.11 albertel 2547: if ($env{'form.proctorpassword'}) {
1.4 albertel 2548: $msg='<p><font color="red">'.&mt("Failed to authenticate the proctor.")
2549: .'</font></p>';
2550: }
1.47 albertel 2551: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.4 albertel 2552: my $result= (<<ENDCHECKOUT);
2553: <h2>Proctor Validation</h2>
2554: <p>Your room's proctor needs to validate your access to this resource.</p>
2555: $msg
1.115 albertel 2556: <form name="checkout" method="post" action="$env{'request.uri'}">
1.4 albertel 2557: <input type="hidden" name="validate" value="yes" />
2558: <input type="hidden" name="submitted" value="yes" />
2559: <table>
1.44 albertel 2560: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 2561: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 2562: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 2563: </table>
2564: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 2565: <table border="1">
2566: <tr><td>
2567: <table>
2568: <tr><td colspan="2">Student who should be logged in is:</td></tr>
2569: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 2570: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138 albertel 2571: <tr><td>Usename</td><td>$user:$domain</td></tr>
1.44 albertel 2572: <tr><td colspan="2"><img src="$url" /></td></tr>
2573: </table>
2574: </tr></td>
2575: </table>
1.4 albertel 2576: </form>
2577: ENDCHECKOUT
2578: return $result;
2579: }
2580:
1.1 albertel 2581: 1;
2582: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>