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