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