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