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