Annotation of loncom/homework/bridgetask.pm, revision 1.239
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # definition of tags that give a structure to a document
3: #
1.239 ! bisitz 4: # $Id: bridgetask.pm,v 1.238 2007/08/09 01:05:15 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30:
31: package Apache::bridgetask;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::File();
36: use Apache::lonmenu;
37: use Apache::lonlocal;
38: use Apache::lonxml;
1.37 albertel 39: use Apache::slotrequest();
1.1 albertel 40: use Time::HiRes qw( gettimeofday tv_interval );
1.158 www 41: use LONCAPA;
42:
1.9 albertel 43:
1.1 albertel 44: BEGIN {
1.225 albertel 45: &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','CriteriaText','GraderNote','ClosingParagraph'));
1.1 albertel 46: }
47:
1.169 albertel 48: my %dimension;
1.194 albertel 49: my $top = 'top';
50:
1.9 albertel 51: sub initialize_bridgetask {
52: # id of current Dimension, 0 means that no dimension is current
53: # (inside <Task> only)
1.178 albertel 54: @Apache::bridgetask::dimension=();
1.9 albertel 55: # list of all current Instance ids
1.168 albertel 56: %Apache::bridgetask::instance=();
1.9 albertel 57: # list of all Instance ids seen in this problem
58: @Apache::bridgetask::instancelist=();
1.15 albertel 59: # key of queud user data that we are currently grading
60: $Apache::bridgetask::queue_key='';
1.169 albertel 61: undef(%dimension);
1.9 albertel 62: }
63:
1.4 albertel 64: sub proctor_check_auth {
1.81 albertel 65: my ($slot_name,$slot,$type)=@_;
1.11 albertel 66: my $user=$env{'form.proctorname'};
67: my $domain=$env{'form.proctordomain'};
1.4 albertel 68:
69: my @allowed=split(",",$slot->{'proctor'});
70: foreach my $possible (@allowed) {
1.138 albertel 71: my ($puser,$pdom)=(split(':',$possible));
1.4 albertel 72: if ($puser eq $user && $pdom eq $domain) {
1.72 albertel 73: my $authenticated=0;
74: if ( $slot->{'secret'} =~ /\S/ &&
75: $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
76: $authenticated=1;
77: } else {
78:
79: my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
80: if ($authhost ne 'no_host') {
81: $authenticated=1;
82: }
83: }
1.150 albertel 84: if ($authenticated) {
1.176 albertel 85: &check_in($type,$user,$domain,$slot_name);
1.4 albertel 86: return 1;
87: }
88: }
89: }
90: return 0;
91: }
92:
1.174 albertel 93: sub check_in {
94: my ($type,$user,$domain,$slot_name) = @_;
95: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
96: if ( $useslots eq 'map_map') {
97: &check_in_sequence($user,$domain,$slot_name);
98: } else {
99: &create_new_version($type,$user,$domain,$slot_name);
1.217 albertel 100: &Apache::structuretags::finalize_storage();
1.174 albertel 101: }
102: return 1;
103: }
104:
105: sub check_in_sequence {
106: my ($user,$domain,$slot_name) = @_;
107: my $navmap = Apache::lonnavmaps::navmap->new();
1.185 albertel 108: my ($symb) = &Apache::lonnet::whichuser();
1.174 albertel 109: my ($map) = &Apache::lonnet::decode_symb($symb);
1.175 albertel 110: my @resources =
111: $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
1.174 albertel 112: my %old_history = %Apache::lonhomework::history;
113: my %old_results = %Apache::lonhomework::results;
114:
115: foreach my $res (@resources) {
116: &Apache::lonxml::debug("doing ".$res->src);
117: &Apache::structuretags::initialize_storage($res->symb);
118: my $type = ($res->is_task()) ? 'Task' : 'problem';
119: &create_new_version($type,$user,$domain,$slot_name);
120: &Apache::structuretags::finalize_storage($res->symb);
121: }
122:
123: %Apache::lonhomework::history = %old_history;
124: %Apache::lonhomework::results = %old_results;
125: }
126:
1.150 albertel 127: sub create_new_version {
128: my ($type,$user,$domain,$slot_name) = @_;
1.174 albertel 129:
130: my $id = '0';
1.150 albertel 131: if ($type eq 'Task') {
132: # increment version
133: my $version=
134: $Apache::lonhomework::history{'resource.0.version'};
135: $version++;
1.152 albertel 136: &Apache::lonxml::debug("Making version $version");
1.150 albertel 137: #clean out all current results
138: foreach my $key (keys(%Apache::lonhomework::history)) {
139: if ($key=~/^resource\.0\./) {
140: $Apache::lonhomework::results{$key}='';
141: }
142: }
143:
144: #setup new version and who did it
1.174 albertel 145: $Apache::lonhomework::results{'resource.0.version'}=$version;
146: $id = "$version.0";
1.178 albertel 147: if (!defined($user) || !defined($domain)) {
1.174 albertel 148: $user = $env{'user.name'};
149: $domain = $env{'user.domain'};
1.150 albertel 150: }
1.174 albertel 151:
1.150 albertel 152: } elsif ($type eq 'problem') {
153: &Apache::lonxml::debug("authed $slot_name");
1.174 albertel 154: }
1.181 albertel 155: if (!defined($user) || !defined($domain)) {
156: $user = $env{'user.name'};
157: $domain = $env{'user.domain'};
158: }
159:
160: $Apache::lonhomework::results{"resource.$id.checkedin"}=
161: $user.':'.$domain;
1.174 albertel 162:
163: if (defined($slot_name)) {
164: $Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
165: $slot_name;
1.150 albertel 166: }
167: }
168:
1.25 albertel 169: sub get_version {
1.29 albertel 170: my ($version,$previous);
1.25 albertel 171: if ($env{'form.previousversion'} &&
1.36 albertel 172: $env{'form.previousversion'} ne 'current' &&
1.89 albertel 173: defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
1.29 albertel 174: $version=$env{'form.previousversion'};
175: $previous=1;
176: } else {
1.150 albertel 177: if (defined($Apache::lonhomework::results{'resource.0.version'})) {
178: $version=$Apache::lonhomework::results{'resource.0.version'};
179: } elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
180: $version=$Apache::lonhomework::history{'resource.0.version'};
181: }
1.29 albertel 182: $previous=0;
183: }
184: if (wantarray) {
185: return ($version,$previous);
1.25 albertel 186: }
1.29 albertel 187: return $version;
1.25 albertel 188: }
189:
1.8 albertel 190: sub add_previous_version_button {
1.25 albertel 191: my ($status)=@_;
1.8 albertel 192: my $result;
1.89 albertel 193: if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
1.25 albertel 194: return '';
195: }
1.89 albertel 196: if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
1.29 albertel 197: $status ne 'NEEDS_CHECKIN') {
1.25 albertel 198: return '';
199: }
1.29 albertel 200: my $version=&get_version();
201: if ($env{'form.previousversion'} ne '' &&
202: $env{'form.previousversion'} eq $version) {
203: $result.="<h3>".&mt("Showing previous version [_1]",$version).
204: "</h3>\n";
205: }
206: my @to_show;
1.89 albertel 207: foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
208: if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
1.29 albertel 209: push(@to_show,$test_version);
210: }
211: }
212: my $list='<option>'.
213: join("</option>\n<option>",@to_show).
214: "</option>\n";
1.36 albertel 215: $list.='<option value="current">'.&mt('Current').'</option>';
1.115 albertel 216: $result.='<form name="getprevious" method="post" action="';
1.29 albertel 217: my $uri=$env{'request.uri'};
218: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
219: $result.=$uri.'">'.
220: &mt(' Show a previously done version: [_1]','<select onchange="this.form.submit()" name="previousversion">
221: <option>'.&mt('Pick one').'</option>
222: '.$list.'
223: </select>')."</form>";
1.8 albertel 224: return $result;
225: }
226:
1.13 albertel 227: sub add_grading_button {
1.185 albertel 228: my (undef,$cid)=&Apache::lonnet::whichuser();
1.59 albertel 229: my $cnum=$env{'course.'.$cid.'.num'};
230: my $cdom=$env{'course.'.$cid.'.domain'};
1.144 albertel 231: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
232:
1.59 albertel 233: my $size=5;
234: if (scalar(keys(%sections)) < 3) {
235: $size=scalar(keys(%sections))+2;
236: }
1.200 albertel 237: my $sec_select = "\n".'<select multiple="multiple" name="chosensections" size="'.$size.'">'."\n";
238: $sec_select .= "\t<option value='all' selected='selected'>all</option>\n";
1.59 albertel 239: foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
1.200 albertel 240: $sec_select .= "\t<option value=\"$sec\">$sec</option>\n";
1.59 albertel 241: }
1.200 albertel 242: $sec_select .= "\t<option value='none'>none</option>\n</select>\n";
1.59 albertel 243:
1.200 albertel 244: my $result="\n\t".'<input type="submit" name="gradeasubmission" value="'.
1.13 albertel 245: &mt("Get a submission to grade").'" />';
1.200 albertel 246: $result.="\n\t".'<input type="hidden" name="grade_target" value="webgrade" />';
1.237 albertel 247: my $see_all = &Apache::lonnet::allowed('mgq',$env{'request.course.id'});
248: my $see_sec = &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.
249: '/'.$env{'request.course.sec'});
250:
251: if ($see_all || $see_sec) {
1.34 albertel 252: my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
1.200 albertel 253: $result.="\n\t".'<table>'."\n\t\t".'<tr>';
1.237 albertel 254: if ($see_all || (!§ion_restricted())) {
1.239 ! bisitz 255: $result.="\n\t\t\t".'<td rowspan="4">'.&mt('Specify a section:').' </td>'.
1.237 albertel 256: "\n\t\t\t".'<td rowspan="4">'.$sec_select."\n\t\t\t".'</td>';
257: } else {
1.239 ! bisitz 258: $result.="\n\t\t\t".'<td rowspan="4">'.&mt('Grading section:').' </td>'.
1.237 albertel 259: "\n\t\t\t".'<td rowspan="4">'.$env{'request.course.sec'}."\n\t\t\t".'</td>';
260: }
1.200 albertel 261: $result.="\n\t\t\t".'<td>'.'<input type="submit" name="reviewagrading" value="'.
1.106 albertel 262: &mt("Select an entry from the grading queue:").'" /> ';
1.34 albertel 263:
1.200 albertel 264: $result.= "\n\t\t\t\t".&mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).'</td>'."\n\t\t".'</tr>'."\n";
1.34 albertel 265:
266: ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
1.200 albertel 267: $result.="\n\t\t".'<tr>'.
268: "\n\t\t\t".'<td>'.
269: "\n\t\t\t\t".'<input type="submit" name="reviewasubmission" value="'.
1.106 albertel 270: &mt("Select an entry from the review queue:").'" /> ';
271: $result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
1.200 albertel 272: $entries,$ready,$locks).'</td>'."\n\t\t".'</tr>'."\n";
273: $result.="\n\t\t".'<tr>'.
274: "\n\t\t\t".'<td>'.
275: "\n\t\t\t\t".'<input type="submit" name="regradeasubmission" value="'.
276: &mt("List of user's grade status").'" /> </td>'
277: ."\n\t\t".'</tr>'
278: ."\n\t".'</table>'."\n";
279: $result.="\n\t".'<p>'.
280: "\n\t\t".'<input type="submit" name="regradeaspecificsubmission" value="'.
281: &mt("Regrade specific user:").'" />';
282: $result.= "\n\t\t".'<input type="text" size="12" name="gradinguser" />';
1.105 albertel 283: $result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
284: 'gradingdomain');
285: $result.=' '.
286: &Apache::loncommon::selectstudent_link('gradesubmission',
287: 'gradinguser',
288: 'gradingdomain');
289: $result.=&Apache::loncommon::studentbrowser_javascript();
1.200 albertel 290: $result.= '</p>'."\n";
1.144 albertel 291: }
1.13 albertel 292: return $result;
293: }
294:
1.22 albertel 295: sub add_request_another_attempt_button {
1.38 albertel 296: my ($text)=@_;
1.239 ! bisitz 297: if (!$text) { $text=&mt('Request another attempt'); }
1.25 albertel 298: my $result;
1.36 albertel 299: my $symb=&Apache::lonnet::symbread();
1.149 albertel 300: # not a slot access based resource
301: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
302: if ($useslots =~ /^\s*no\s*$/i) {
303: return '';
304: }
305:
1.37 albertel 306: my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
1.38 albertel 307: my $action='get_reservation';
1.37 albertel 308: if ($slot_name) {
1.239 ! bisitz 309: $text=&mt('Change reservation.');
1.38 albertel 310: $action='change_reservation';
1.37 albertel 311: my $description=&Apache::slotrequest::get_description($slot_name,
312: $slot);
1.239 ! bisitz 313: $result.='<p>'
! 314: .&mt('Will be next available:')
! 315: .' '.$description
! 316: .'</p>';
1.37 albertel 317: }
1.38 albertel 318:
319: if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
1.158 www 320: $symb=&escape($symb);
1.200 albertel 321: $result.=
322: "\n\t".'<form method="post" action="/adm/slotrequest">'."\n\t\t".
323: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n\t\t".
324: '<input type="hidden" name="command" value="'.$action.'" />'."\n\t\t".
1.38 albertel 325: '<input type="submit" name="requestattempt" value="'.
1.239 ! bisitz 326: $text.'" />'."\n\t".
1.200 albertel 327: '</form>'."\n";
1.25 albertel 328: return $result;
1.22 albertel 329: }
330:
1.30 albertel 331: sub preserve_grade_info {
332: my $result;
333: # if we are viewing someone else preserve that info
334: if (defined $env{'form.grade_symb'}) {
335: foreach my $field ('symb','courseid','domain','username') {
336: $result .= '<input type="hidden" name="grade_'.$field.
337: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
338: }
339: }
340: return $result;
341: }
342:
1.53 albertel 343: sub style {
1.125 albertel 344: my ($target) = @_;
345: if ($target eq 'web'
346: || $target eq 'webgrade') {
1.192 albertel 347: my $style = (<<STYLE);
1.126 albertel 348: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task.css" />
1.53 albertel 349: STYLE
1.192 albertel 350: if ($env{'browser.type'} eq 'explorer'
351: && $env{'browser.os'} eq 'win' ) {
352: if ($env{'browser.version'} < 7) {
353: $style .= (<<STYLE);
354: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie.css" />
355: STYLE
356: } else {
357: $style .= (<<STYLE);
358: <link rel="stylesheet" type="text/css" href="/res/adm/includes/task_ie7.css" />
359: STYLE
360: }
361: }
1.193 albertel 362: return $style;
1.125 albertel 363: }
364: return;
1.53 albertel 365: }
366:
1.54 albertel 367: sub show_task {
368: my ($status,$previous)=@_;
369: if (!$previous && (
370: ( $status eq 'CLOSED' ) ||
371: ( $status eq 'BANNED') ||
372: ( $status eq 'UNAVAILABLE') ||
373: ( $status eq 'NOT_IN_A_SLOT') ||
374: ( $status eq 'NEEDS_CHECKIN') ||
375: ( $status eq 'WAITING_FOR_GRADE') ||
1.150 albertel 376: ( $status eq 'INVALID_ACCESS') ||
377: ( &get_version() eq ''))) {
1.54 albertel 378: return 0;
379: }
1.64 albertel 380: if ($env{'form.donescreen'}) { return 0; }
1.54 albertel 381: return 1;
382: }
383:
1.173 albertel 384: my @delay;
385: sub nest {
386: if (@delay) {
387: return $delay[-1];
388: } else {
389: return;
390: }
391: }
392:
1.208 albertel 393: sub start_delay {
394: push(@delay,1);
395: }
396: sub end_delay {
397: pop(@delay);
398: }
399:
1.173 albertel 400: sub nested_parse {
401: my ($str,$env,$args) = @_;
402: my @old_env = @Apache::scripttag::parser_env;
403: @Apache::scripttag::parser_env = @$env;
404: if (exists($args->{'set_dim_id'})) {
405: &enable_dimension_parsing($args->{'set_dim_id'});
406: }
407: push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
408: my $result = &Apache::scripttag::xmlparse($$str);
409: pop(@delay);
410: if (exists($args->{'set_dim_id'})) {
411: &disable_dimension_parsing();
412: }
413: @Apache::scripttag::parser_env = @old_env;
414: if ($args->{'delayed_dim_results'}) {
415: my $dim = &get_dim_id();
1.180 albertel 416: &Apache::lonxml::debug(" tossing out $result ");
417: &Apache::lonxml::debug(" usining out $dim 's ". $dimension{$dim}{'result'});
1.173 albertel 418: return $dimension{$dim}{'result'};
419: }
420: return $result;
421: }
422:
1.54 albertel 423: sub internal_location {
424: my ($id)=@_;
425: return '<!-- LONCAPA_INTERNAL_ADD_TASK_STATUS'.$id.' -->';
426: }
427:
1.60 albertel 428: sub submission_time_stamp {
1.185 albertel 429: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.60 albertel 430: my $submissiontime;
1.89 albertel 431: my $version=$Apache::lonhomework::history{'resource.0.version'};
1.60 albertel 432: for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
1.183 albertel 433: if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})
434: && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
1.60 albertel 435: $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
1.182 albertel 436: last;
1.60 albertel 437: }
438: }
439: my $result;
440: if ($submissiontime) {
1.89 albertel 441: my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
1.60 albertel 442: my %slot=&Apache::lonnet::get_slot($slot_name);
443: my $diff = $slot{'endtime'} - $submissiontime;
1.71 albertel 444: my ($color,$when)=('#FF6666','after');
445: if ($diff > 0) { ($color,$when)=('#336600','before'); }
1.60 albertel 446: my $info;
1.182 albertel 447: $diff = abs($diff);
1.60 albertel 448: if ($diff%60) { $info=($diff%60).' seconds'; }
449: $diff=int($diff/60);
450: if ($diff%60) { $info=($diff%60).' minutes '.$info; }
451: $diff=int($diff/60);
452: if ($diff) { $info=$diff.' hours '.$info; }
453: $result='<p><font color="'.$color.'">'.
1.182 albertel 454: &mt('Student submitted [_1] [_2] the deadline. '.
455: '(Submission was at [_3], end of period was [_4].)',
456: $info,$when,
457: &Apache::lonlocal::locallocaltime($submissiontime),
458: &Apache::lonlocal::locallocaltime($slot{'endtime'})).
1.60 albertel 459: '</font></p>';
460: }
461: return $result;
462: }
463:
1.119 albertel 464: sub file_list {
465: my ($files,$uname,$udom) = @_;
466: if (!defined($uname) || !defined($udom)) {
1.185 albertel 467: (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
1.119 albertel 468: }
1.70 albertel 469: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
1.119 albertel 470:
1.120 albertel 471: my $file_list="<ul class=\"LC_GRADING_handininfo\">\n";
1.119 albertel 472: foreach my $partial_file (split(',',$files)) {
1.70 albertel 473: my $file=$file_url.$partial_file;
474: $file=~s|/+|/|g;
475: &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
1.161 albertel 476: $file_list.='<li><span style="white-space: nowrap;"><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.
477: &Apache::loncommon::icon($file).'" alt="file icon" border="0" /> '.$file.
478: '</a></span></li>'."\n";
1.70 albertel 479: }
480: $file_list.="</ul>\n";
1.119 albertel 481: return $file_list;
482: }
483:
1.163 albertel 484: sub grade_mode {
485: if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
486: return 'regrade';
487: }
488: return 'queue_grade';
489: }
490:
1.119 albertel 491: sub webgrade_standard_info {
492: my ($version)=&get_version();
493:
494: my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
1.70 albertel 495:
1.163 albertel 496: my %lt=('done' => 'Next Item',
497: 'stop' => 'Quit Grading',
498: 'fail' => 'Fail Rest',
499: 'cancel' => 'Cancel',
1.231 albertel 500: 'submit' => 'Submit Grades',
1.163 albertel 501: );
1.170 albertel 502: %lt=&Apache::lonlocal::texthash(%lt);
1.163 albertel 503:
1.70 albertel 504: my $result=<<INFO;
1.120 albertel 505: <div class="LC_GRADING_maincontrols">
1.163 albertel 506: INFO
507:
1.231 albertel 508: if ($env{'request.state'} eq 'construct') {
1.163 albertel 509: $result.=<<INFO;
1.231 albertel 510: <input type="submit" name="next" value="$lt{'submit'}" />
511: INFO
512: } else {
513: if (&grade_mode() eq 'regrade' && $env{'request.state'} ne 'construct') {
514: $result.=<<INFO;
1.163 albertel 515: <input type="submit" name="cancel" value="$lt{'cancel'}" />
516: INFO
1.231 albertel 517: }
1.163 albertel 518:
1.231 albertel 519: $result.=<<INFO;
1.111 albertel 520: <input type="submit" name="next" value="$lt{'done'}" />
521: <input type="submit" name="stop" value="$lt{'stop'}" />
1.231 albertel 522: INFO
523: }
524: $result.=<<INFO;
1.143 albertel 525: <input type="button" name="fail" value="$lt{'fail'}"
526: onclick="javascript:onFailRest()" />
1.111 albertel 527: </div>
1.70 albertel 528: $file_list
529: INFO
530: return $result;
1.231 albertel 531:
1.70 albertel 532: }
533:
1.166 albertel 534: sub done_screen {
535: my ($version) = @_;
1.231 albertel 536: my $title=&Apache::lonnet::gettitle($env{'request.uri'});
1.166 albertel 537: my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
1.185 albertel 538: my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
1.166 albertel 539: my $files = '<ul>';
1.167 albertel 540: my $msg;
1.166 albertel 541: foreach my $file (@files) {
542: my $url="/uploaded/$domain/$user/portfolio$file";
543: if (! &Apache::lonnet::stat_file($url)) {
1.239 ! bisitz 544: $file = '<span class="LC_error">'
! 545: .&mt('[_1]Nonexistent file:[_2]'
! 546: ,'<span class="LC_error"> '
! 547: ,'</span> <span class="LC_filename">'.$file.'</span>');
! 548: $msg .= "<p>".&mt('Submitted non-existant file [_1]',$file)."</p>\n";
1.166 albertel 549: } else {
550: $file = '<span class="LC_filename">'.$file.'</span>';
1.239 ! bisitz 551: $msg .= "<p>".&mt('Submitted file [_1]',$file)."</p>\n";
1.166 albertel 552: }
553: $files .= '<li>'.$file.'</li>';
554: }
555: $files.='</ul>';
1.239 ! bisitz 556: my $subject = &mt('Submission message for [_1]',$title);
1.167 albertel 557: my ($message_status,$comment_status);
558: my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
559: $setting =~ s/^\s*(\S*)\s*$/$1/;
560: $setting = lc($setting);
561: if ($setting eq 'only_student'
562: || $setting eq 'student_and_user_notes_screen') {
563: $message_status =
564: &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
565: $message_status = '<p>'.&mt('Message sent to user: [_1]',
566: $message_status).' </p>';
567: }
568: if ($setting eq 'student_and_user_notes_screen') {
569: $comment_status =
570: &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
571: $msg,$user,$domain);
572: $comment_status = '<p>'.&mt('Message sent to instructor: [_1]',
573: $comment_status).' </p>';
574: }
1.239 ! bisitz 575: return "<h2>$title</h2>"
! 576: .'<p>'.&mt('Files submitted: [_1]',$files).'</p>'
! 577: .'<p>'.&mt('You are now done with this Bridge Task').'</p>'
! 578: .'<hr />'
! 579: .'<p><a href="/adm/logout">'.&mt('Logout').'</a></p>'
! 580: .'<p><a href="/adm/roles">'.&mt('Change to a different course').'</a></p>'
! 581: .$message_status
! 582: .$comment_status
1.166 albertel 583:
584: }
585:
1.1 albertel 586: sub start_Task {
1.87 albertel 587: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 588:
1.4 albertel 589: my ($status,$accessmsg,$slot);
1.179 albertel 590: &Apache::structuretags::init_problem_globals('Task');
1.16 albertel 591: if ($target ne 'webgrade') {
592: &Apache::structuretags::initialize_storage();
593: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.74 albertel 594: if ($env{'request.state'} eq 'construct') {
595: &Apache::structuretags::setup_rndseed($safeeval);
596: }
1.16 albertel 597: }
598:
1.4 albertel 599: $Apache::lonhomework::parsing_a_task=1;
1.141 albertel 600:
601: my $name;
602: if ($target eq 'web' || $target eq 'webgrade') {
603: $name = &Apache::structuretags::get_resource_name($parstack,$safeeval);
604: }
605:
1.145 albertel 606: my ($result,$form_tag_start);
607: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
608: || $target eq 'edit') {
609: ($result,$form_tag_start) =
610: &Apache::structuretags::page_start($target,$token,$tagstack,
611: $parstack,$parser,$safeeval,
1.146 albertel 612: $name,&style($target));
1.145 albertel 613: }
1.123 albertel 614:
1.74 albertel 615: if ($target eq 'web' && $env{'request.state'} ne 'construct') {
1.147 albertel 616: if ($Apache::lonhomework::queuegrade
617: || $Apache::lonhomework::modifygrades) {
1.141 albertel 618: $result.='<form name="gradesubmission" method="post" action="';
1.13 albertel 619: my $uri=$env{'request.uri'};
620: if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
1.200 albertel 621: $result.=$uri.'">'.&add_grading_button()."</form>\n";
1.38 albertel 622: my $symb=&Apache::lonnet::symbread();
1.235 albertel 623: if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
624: || &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
1.141 albertel 625: $result.='<form method="post" name="slotrequest" action="/adm/slotrequest">'.
1.40 albertel 626: '<input type="hidden" name="symb" value="'.$symb.'" />'.
627: '<input type="hidden" name="command" value="showslots" />'.
628: '<input type="submit" name="requestattempt" value="'.
629: &mt('Show Slot list').'" />'.
630: '</form>';
1.108 albertel 631: my $target_id =
632: &Apache::lonstathelpers::make_target_id({symb => $symb,
633: part => '0'});
1.238 albertel 634: if (!§ion_restricted()) {
1.237 albertel 635: $result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
636: '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
637: '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
638: '<input type="submit" name="grading" value="'.
639: &mt('Show Grading Status').'" />'.
640: '</form>';
641: }
1.40 albertel 642: }
1.13 albertel 643: }
1.8 albertel 644: }
1.231 albertel 645: if ($target =~/(web|webgrade)/ && $env{'request.state'} eq 'construct') {
1.74 albertel 646: $form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
647: }
1.163 albertel 648: if ($target eq 'web'
649: || ($target eq 'grade' && !$env{'form.webgrade'})
650: || $target eq 'answer'
651: || $target eq 'tex') {
1.29 albertel 652: my ($version,$previous)=&get_version();
1.14 albertel 653: ($status,$accessmsg,my $slot_name,$slot) =
1.81 albertel 654: &Apache::lonhomework::check_slot_access('0','Task');
1.152 albertel 655: if ($status eq 'CAN_ANSWER' && $version eq '') {
1.177 albertel 656: # CAN_ANSWER mode, and no current version, unproctored access
1.174 albertel 657: # thus self-checkedin
1.177 albertel 658: &check_in('Task',undef,undef,$slot_name);
1.152 albertel 659: &add_to_queue('gradingqueue',{'type' => 'Task',
660: 'time' => time,
661: 'slot' => $slot_name});
1.150 albertel 662: ($version,$previous)=&get_version();
663: }
1.218 albertel 664:
665: my $status_id =
666: ($previous || $status eq 'SHOW_ANSWER') ? 'LC_task_feedback'
667: : 'LC_task_take';
668: $result .= '<div class="LC_task" id="'.$status_id.'">'."\n";
1.150 albertel 669:
1.9 albertel 670: push(@Apache::inputtags::status,$status);
1.14 albertel 671: $Apache::inputtags::slot_name=$slot_name;
1.1 albertel 672: my $expression='$external::datestatus="'.$status.'";';
1.89 albertel 673: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
1.1 albertel 674: &Apache::run::run($expression,$safeeval);
675: &Apache::lonxml::debug("Got $status");
1.141 albertel 676: $result.=&add_previous_version_button($status);
1.54 albertel 677: if (!&show_task($status,$previous)) {
1.87 albertel 678: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.1 albertel 679: if ( $target eq "web" ) {
1.74 albertel 680: if ($env{'request.state'} eq 'construct') {
681: $result.=$form_tag_start;
682: }
1.4 albertel 683: my $msg;
1.1 albertel 684: if ($status eq 'UNAVAILABLE') {
685: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.3 albertel 686: } elsif ($status eq 'NOT_IN_A_SLOT') {
687: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.38 albertel 688: $msg.=&add_request_another_attempt_button("Sign up for time to work.");
1.4 albertel 689: } elsif ($status eq 'NEEDS_CHECKIN') {
690: $msg.='<h1>'.&mt('You need the Proctor to validate you.').
691: '</h1>'.&proctor_validation_screen($slot);
1.22 albertel 692: } elsif ($status eq 'WAITING_FOR_GRADE') {
693: $msg.='<h1>'.&mt('Your submission is in the grading queue.').'</h1>';
1.64 albertel 694: } elsif ($env{'form.donescreen'}) {
1.167 albertel 695: $result .= &done_screen($version);
1.1 albertel 696: } elsif ($status ne 'NOT_YET_VIEWED') {
697: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
698: }
699: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
700: $msg.='The problem '.$accessmsg;
701: }
702: $result.=$msg.'<br />';
703: } elsif ($target eq 'tex') {
704: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
705: if ($status eq 'UNAVAILABLE') {
706: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
707: } else {
708: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
709: }
1.22 albertel 710: } elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
1.4 albertel 711: if ($status eq 'NEEDS_CHECKIN') {
1.83 albertel 712: if(&proctor_check_auth($slot_name,$slot,'Task')
713: && defined($Apache::inputtags::slot_name)) {
1.148 albertel 714: my $result=
715: &add_to_queue('gradingqueue',
1.152 albertel 716: {'type' => 'Task',
1.148 albertel 717: 'time' => time,
718: 'slot' =>
719: $Apache::inputtags::slot_name});
1.77 albertel 720: &Apache::lonxml::debug("add_to_queue said $result");
721: }
1.4 albertel 722: }
1.1 albertel 723: }
724: } elsif ($target eq 'web') {
1.141 albertel 725:
1.57 albertel 726: $result.=&preserve_grade_info();
1.194 albertel 727: $result.=&internal_location();
1.200 albertel 728: $result.=$form_tag_start."\t".
1.36 albertel 729: '<input type="hidden" name="submitted" value="yes" />';
1.54 albertel 730: &Apache::lonxml::startredirection();
1.1 albertel 731: }
1.21 albertel 732: } elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
733: $target eq 'webgrade') {
1.32 albertel 734: my $webgrade='yes';
1.21 albertel 735: if ($target eq 'webgrade') {
1.218 albertel 736: $result .= '<div class="LC_task">'."\n";
1.141 albertel 737: $result.= "\n".'<div class="LC_GRADING_task">'."\n".
1.124 albertel 738: '<script type="text/javascript"
1.126 albertel 739: src="/res/adm/includes/task_grading.js"></script>';
1.49 albertel 740: #$result.='<br />Review'.&show_queue('reviewqueue');
741: #$result.='<br />Grade'.&show_queue('gradingqueue');
1.30 albertel 742: }
1.194 albertel 743:
1.105 albertel 744: my ($todo,$status_code,$msg)=&get_key_todo($target);
1.33 albertel 745:
746: if ($todo) {
747: &setup_env_for_other_user($todo,$safeeval);
748: my ($symb,$uname,$udom)=&decode_queue_key($todo);
1.231 albertel 749: if ($env{'request.state'} eq 'construct') {
750: $symb = $env{'request.uri'};
751: }
752: $result.="\n".'<p>'.
753: &mt('Grading [_1] for [_2] at [_3]',
754: &Apache::lonnet::gettitle($symb),$uname,$udom).'</p>';
1.33 albertel 755: $form_tag_start.=
756: '<input type="hidden" name="gradingkey" value="'.
1.158 www 757: &escape($todo).'" />';
1.33 albertel 758: $Apache::bridgetask::queue_key=$todo;
759: &Apache::structuretags::initialize_storage();
760: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.110 albertel 761: if ($target eq 'webgrade' && $status_code eq 'selected') {
762: $form_tag_start.=
763: '<input type="hidden" name="queuemode" value="selected" />';
1.33 albertel 764: }
1.15 albertel 765: } else {
1.33 albertel 766: if ($target eq 'webgrade') {
767: $result.="\n";
1.81 albertel 768: my $back='<p><a href="/adm/flip?postdata=return:">'.
769: &mt('Return to resource').'</a></p>';
1.33 albertel 770: if ($status_code eq 'stop') {
1.81 albertel 771: $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
1.163 albertel 772: } elsif ($status_code eq 'cancel') {
773: $result.='<b>'.&mt("Cancelled grading.").'</b>'.$back;
1.164 albertel 774: } elsif ($status_code eq 'never_versioned') {
775: $result.='<b>'.
776: &mt("Requested user has never accessed the task.").
777: '</b>'.$back;
1.165 albertel 778: } elsif ($status_code =~ /still_open:(.*)/) {
779: my $date = &Apache::lonlocal::locallocaltime($1);
780: $result.='<b>'.
781: &mt("Task is still open, will close at [_1].",$date).
782: '</b>'.$back;
1.33 albertel 783: } elsif ($status_code eq 'lock_failed') {
1.105 albertel 784: $result.='<b>'.&mt("Failed to lock the requested record.")
1.81 albertel 785: .'</b>'.$back;
1.33 albertel 786: } elsif ($status_code eq 'unlock') {
1.81 albertel 787: $result.='<b>'.&mt("Unlocked the requested record.")
788: .'</b>'.$back;
1.33 albertel 789: $result.=&show_queue($env{'form.queue'},1);
790: } elsif ($status_code eq 'show_list') {
791: $result.=&show_queue($env{'form.queue'},1);
1.49 albertel 792: } elsif ($status_code eq 'select_user') {
793: $result.=&select_user();
1.95 albertel 794: } elsif ($status_code eq 'unable') {
795: $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
1.105 albertel 796: } elsif ($status_code eq 'not_allowed') {
797: $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
1.33 albertel 798: } else {
1.81 albertel 799: $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
1.32 albertel 800: }
1.21 albertel 801: }
1.33 albertel 802: $webgrade='no';
1.163 albertel 803: }
804: if (!$todo || $env{'form.cancel'}) {
1.87 albertel 805: my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
1.32 albertel 806: }
807: if ($target eq 'webgrade' && defined($env{'form.queue'})) {
1.61 albertel 808: if ($webgrade eq 'yes') {
809: $result.=&submission_time_stamp();
810: }
1.32 albertel 811: $result.=$form_tag_start;
812: $result.='<input type="hidden" name="webgrade" value="'.
813: $webgrade.'" />';
814: $result.='<input type="hidden" name="queue" value="'.
815: $env{'form.queue'}.'" />';
1.52 albertel 816: if ($env{'form.regrade'}) {
817: $result.='<input type="hidden" name="regrade" value="'.
818: $env{'form.regrade'}.'" />';
819: }
1.237 albertel 820: if ($env{'form.chosensections'} || §ion_restricted()) {
821: my @chosen_sections = &get_allowed_sections();
1.62 albertel 822: foreach my $sec (@chosen_sections) {
823: $result.='<input type="hidden" name="chosensections"
824: value="'.$sec.'" />';
825: }
826: }
1.70 albertel 827: if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
1.231 albertel 828: } elsif ($target eq 'webgrade'
829: && $env{'request.state'} eq 'construct') {
830: $result.=$form_tag_start;
831: $result.='<input type="hidden" name="webgrade" value="'.
832: $webgrade.'" />';
833: $result.=&webgrade_standard_info();
1.15 albertel 834: }
1.110 albertel 835: if ($target eq 'webgrade') {
1.120 albertel 836: $result.="\n".'<div id="LC_GRADING_criterialist">';
1.194 albertel 837: &Apache::lonxml::startredirection();
1.208 albertel 838: &start_delay();
839: $dimension{$top}{'result'}=$result;
840: undef($result);
1.110 albertel 841: }
1.74 albertel 842: } elsif ($target eq 'edit') {
1.141 albertel 843: $result.=$form_tag_start.
1.74 albertel 844: &Apache::structuretags::problem_edit_header();
845: $Apache::lonxml::warnings_error_header=
846: &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 />";
1.225 albertel 847: $result.= &Apache::edit::text_arg('Required number of passed optional elements to pass the Task:','OptionalRequired',$token,10)." <br />\n";
848: $result.= &Apache::edit::insertlist($target,$token);
849: } elsif ($target eq 'modified') {
850: my $constructtag=
851: &Apache::edit::get_new_args($token,$parstack,$safeeval,
852: 'OptionalRequired');
853: if ($constructtag) {
854: $result = &Apache::edit::rebuild_tag($token);
855: }
1.1 albertel 856: } else {
857: # page_start returned a starting result, delete it if we don't need it
858: $result = '';
859: }
860: return $result;
861: }
862:
1.165 albertel 863: sub get_task_end_time {
864: my ($queue_entry,$symb,$udom,$uname) = @_;
865:
866: my $end_time;
867: if (my $slot = &slotted_access($queue_entry)) {
868: my %slot_data=&Apache::lonnet::get_slot($slot);
869: $end_time = $slot_data{'endtime'};
870: } else {
871: $end_time = &Apache::lonhomework::due_date('0',$symb,
872: $udom,$uname);
873: }
874: return $end_time;
875: }
876:
1.32 albertel 877: sub get_key_todo {
878: my ($target)=@_;
879: my $todo;
1.33 albertel 880:
1.231 albertel 881: if ($env{'request.state'} eq 'construct') {
882: my ($symb,$cid,$udom,$uname) = &Apache::lonnet::whichuser();
883: my $gradingkey=&encode_queue_key($symb,$udom,$uname);
884: return ($gradingkey);
885: }
886:
1.33 albertel 887: if (defined($env{'form.reviewasubmission'})) {
1.54 albertel 888: &Apache::lonxml::debug("review a submission....");
1.33 albertel 889: $env{'form.queue'}='reviewqueue';
890: return (undef,'show_list');
891: }
892:
893: if (defined($env{'form.reviewagrading'})) {
894: &Apache::lonxml::debug("review a grading....");
895: $env{'form.queue'}='gradingqueue';
896: return (undef,'show_list');
897: }
898:
1.49 albertel 899: if (defined($env{'form.regradeasubmission'})) {
900: &Apache::lonxml::debug("regrade a grading....");
901: $env{'form.queue'}='none';
902: return (undef,'select_user');
903: }
904:
1.105 albertel 905:
1.138 albertel 906: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.105 albertel 907:
908: #need to try both queues..
909: if (defined($env{'form.regradeaspecificsubmission'}) &&
910: defined($env{'form.gradinguser'}) &&
911: defined($env{'form.gradingdomain'}) ) {
1.185 albertel 912: my ($symb,$cid)=&Apache::lonnet::whichuser();
1.105 albertel 913: my $cnum = $env{'course.'.$cid.'.num'};
914: my $cdom = $env{'course.'.$cid.'.domain'};
1.224 albertel 915: my $uname = &LONCAPA::clean_username($env{'form.gradinguser'});
916: my $udom = &LONCAPA::clean_domain($env{'form.gradingdomain'});
1.237 albertel 917:
918: if (§ion_restricted()) {
919: my $classlist=&get_limited_classlist();
920: if (!&allow_grade_user($classlist->{$uname.':'.$udom})) {
921: return (undef,'not_allowed',
922: &mt('Requested student ([_1]) is in a section you aren\'t allowed to grade.',$uname.':'.$udom));
923: }
924: }
1.105 albertel 925: my $gradingkey=&encode_queue_key($symb,$udom,$uname);
926:
927: my $queue;
928:
929: if (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
930: $env{'form.queue'} = $queue = 'gradingqueue';
931: } elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
932: $env{'form.queue'} = $queue = 'reviewqueue';
933: }
934:
935: if (!$queue) {
936: $env{'form.queue'} = $queue = 'none';
937: #not queued so doing either a re or pre grade
1.164 albertel 938: my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
939: if ($status{'resource.0.version'} < 1) {
940: return (undef,'never_versioned');
941: }
1.105 albertel 942: return ($gradingkey);
943: }
944:
1.165 albertel 945: if ($queue) {
946: my $queue_entry = &get_queue_data($queue,$udom,$uname);
947:
948: my $end_time = &get_task_end_time($queue_entry,$symb,
949: $udom,$uname);
950: if ($end_time > time) {
951: return (undef,"still_open:$end_time");
952: }
953: }
954:
1.105 albertel 955: my $who=&queue_key_locked($queue,$gradingkey);
956: if ($who eq $me) {
957: #already have the lock
1.158 www 958: $env{'form.gradingkey'}=&escape($gradingkey);
1.163 albertel 959: &Apache::lonxml::debug("already locked");
1.105 albertel 960: return ($gradingkey);
961: }
962:
963: if (!defined($who)) {
964: if (&lock_key($queue,$gradingkey)) {
1.163 albertel 965: &Apache::lonxml::debug("newly locked");
1.105 albertel 966: return ($gradingkey);
967: } else {
968: return (undef,'lock_failed');
969: }
970: }
971:
972: #otherwise (defined($who) && $who ne $me) some else has it...
973: return (undef,'not_allowed',
974: &mt('Another user ([_1]) currently has the record for [_2] locked.',
1.138 albertel 975: $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
1.105 albertel 976: }
977:
978:
1.32 albertel 979: my $queue=$env{'form.queue'};
1.33 albertel 980:
1.32 albertel 981: if (!defined($queue)) {
982: $env{'form.queue'}=$queue='gradingqueue';
983: }
1.33 albertel 984:
1.158 www 985: my $gradingkey=&unescape($env{'form.gradingkey'});
1.33 albertel 986:
1.49 albertel 987: if ($env{'form.queue'} eq 'none') {
988: if (defined($env{'form.gradingkey'})) {
989: if ($target eq 'webgrade') {
990: if ($env{'form.stop'}) {
991: return (undef,'stop');
1.163 albertel 992: } elsif ($env{'form.cancel'}) {
993: return (undef,'cancel');
1.49 albertel 994: } elsif ($env{'form.next'}) {
1.59 albertel 995: return (undef,'select_user');
1.49 albertel 996: }
997: }
998: return ($gradingkey,'selected');
999: } else {
1.59 albertel 1000: return (undef,'select_user');
1.49 albertel 1001: }
1002: }
1.32 albertel 1003: if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
1.33 albertel 1004: && !defined($env{'form.gradingaction'})
1005: && $env{'form.queuemode'} eq 'selected') {
1006:
1007: my $who=&queue_key_locked($queue,$gradingkey);
1008: if ($who eq $me) {
1009: &Apache::lonxml::debug("Found a key was given to me");
1010: return ($gradingkey,'selected');
1011: } else {
1012: return (undef,'show_list');
1013: }
1014:
1015: }
1016:
1017: if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
1018: if ($env{'form.gradingaction'} eq 'resume') {
1019: delete($env{'form.gradingaction'});
1020: &Apache::lonxml::debug("Resuming a key");
1.32 albertel 1021: return ($gradingkey);
1.33 albertel 1022: } elsif ($env{'form.gradingaction'} eq 'unlock') {
1023: &Apache::lonxml::debug("Unlocking a key ".
1024: &check_queue_unlock($queue,$gradingkey,1));
1025: return (undef,'unlock');
1026: } elsif ($env{'form.gradingaction'} eq 'select') {
1027: &Apache::lonxml::debug("Locking a key");
1028: if (&lock_key($queue,$gradingkey)) {
1029: &Apache::lonxml::debug("Success $queue");
1030: return ($gradingkey);
1031: }
1032: &Apache::lonxml::debug("Failed $queue");
1033: return (undef,'lock_failed');
1.32 albertel 1034: }
1035: }
1.33 albertel 1036:
1037: if ($env{'form.queuemode'} ne 'selected') {
1038: # don't get something new from the queue if they hit the stop button
1.163 albertel 1039: if (!(($env{'form.cancel'} || $env{'form.stop'})
1040: && $target eq 'webgrade')
1.33 albertel 1041: && !$env{'form.gradingaction'}) {
1042: &Apache::lonxml::debug("Getting anew $queue");
1043: return (&get_from_queue($queue));
1044: } else {
1045: return (undef,'stop');
1046: }
1.32 albertel 1047: }
1.33 albertel 1048: return (undef,undef)
1.32 albertel 1049: }
1.94 albertel 1050:
1051: sub minimize_storage {
1052: foreach my $key (keys(%Apache::lonhomework::results)) {
1053: if ($key =~ /regrader$/) { next; }
1054: if ($Apache::lonhomework::results{$key} eq
1055: $Apache::lonhomework::history{$key}) {
1056: delete($Apache::lonhomework::results{$key});
1057: }
1058: }
1059: }
1060:
1.1 albertel 1061: sub end_Task {
1062: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1063: my $result='';
1064: my $status=$Apache::inputtags::status['-1'];
1.29 albertel 1065: my ($version,$previous)=&get_version();
1.1 albertel 1066: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1.15 albertel 1067: $target eq 'tex') {
1.69 albertel 1068: if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
1.1 albertel 1069: if ($target eq 'web') {
1.54 albertel 1070: if (&show_task($status,$previous)) {
1071: $result.=&Apache::lonxml::endredirection();
1072: }
1.64 albertel 1073: if ($status eq 'CAN_ANSWER' && !$previous &&
1074: !$env{'form.donescreen'}) {
1.15 albertel 1075: $result.="\n".'<table border="1">'.
1.28 albertel 1076: &Apache::inputtags::file_selector("$version.0",
1077: "bridgetask","*",
1.46 albertel 1078: 'portfolioonly',
1079: '
1080: <h2>'.&mt('Submit Portfolio Files for Grading').'</h2>
1081: <p>'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'</p>').
1.9 albertel 1082: "</table>";
1.77 albertel 1083: }
1.78 albertel 1084: if (!$previous && $status ne 'SHOW_ANSWER' &&
1085: &show_task($status,$previous)) {
1.232 albertel 1086: $result.=&Apache::inputtags::gradestatus('0',$target,1);
1.199 albertel 1087: }
1088:
1089: $result.='</form>';
1090:
1091: if (!$previous && $status ne 'SHOW_ANSWER' &&
1092: &show_task($status,$previous)) {
1.116 albertel 1093: my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.64 albertel 1094: $result.=<<DONEBUTTON;
1.115 albertel 1095: <form name="done" method="post" action="$action">
1.64 albertel 1096: <input type="hidden" name="donescreen" value="1" />
1097: <input type="submit" value="Done" />
1098: </form>
1099: DONEBUTTON
1.77 albertel 1100: }
1.56 albertel 1101: if (&show_task($status,$previous) &&
1.89 albertel 1102: $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
1103: my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
1.231 albertel 1104: my $title=&Apache::lonnet::gettitle($env{'request.uri'});
1.149 albertel 1105: my $start_time;
1106:
1.80 albertel 1107: my $slot_name=
1.89 albertel 1108: $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1.149 albertel 1109: if ($slot_name) {
1110: my %slot=&Apache::lonnet::get_slot($slot_name);
1111:
1112: $start_time=$slot{'starttime'}
1113: } else {
1114: $start_time=
1115: &Apache::lonnet::EXT('resource.0.opendate');
1116: }
1117: $start_time=&Apache::lonlocal::locallocaltime($start_time);
1.54 albertel 1118:
1.200 albertel 1119: my $status =
1.213 albertel 1120: "\n<div class='LC_$bt_status LC_criteria LC_task_overall_status'>\n\t";
1.54 albertel 1121:
1.213 albertel 1122: my $dim = $top;
1123: my %counts = &get_counts($dim,undef,$parstack,
1124: $safeeval);
1125: my $question_status ="\n\t<p>".
1126: &question_status_message(\%counts,-1).
1127: "</p>\n";
1128:
1.54 albertel 1129: if ($bt_status eq 'pass') {
1.239 ! bisitz 1130: $status.='<h2>'
! 1131: .&mt('You passed the [_1] given on [_2].',$title,$start_time)
! 1132: .'</h2>';
1.213 albertel 1133: $status.=$question_status;
1.54 albertel 1134: }
1135: if ($bt_status eq 'fail') {
1.239 ! bisitz 1136: $status.='<h2>'
! 1137: .&mt('You did not pass the [_1] given on [_2].',$title,$start_time)
! 1138: .'</h2>';
1.213 albertel 1139: $status.=$question_status;
1.54 albertel 1140: if (!$previous) {
1141: $status.=&add_request_another_attempt_button();
1142: }
1143: }
1.213 albertel 1144:
1.200 albertel 1145: $status.="\n".'</div>'."\n";
1.194 albertel 1146:
1147: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1148: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1149: if ($type eq 'dimension') {
1150: $result.=$dimension{$id}{'result'};
1151: next;
1152: }
1153: my $criteria =
1154: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
1155: [@_]);
1156: $status .= &layout_web_Criteria($dim,$id,$criteria);
1157: }
1.54 albertel 1158:
1159: my $internal_location=&internal_location();
1160: $result=~s/\Q$internal_location\E/$status/;
1161: }
1.142 albertel 1162: $result.="\n</div>\n".
1163: &Apache::loncommon::end_page({'discussion' => 1});
1.1 albertel 1164: }
1165: }
1.181 albertel 1166:
1167: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
1168: my %queue_data = ('type' => 'Task',
1169: 'time' => time,);
1170: if (defined($Apache::inputtags::slot_name)) {
1171: $queue_data{'slot'} = $Apache::inputtags::slot_name;
1172: } elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) {
1173: $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
1174: }
1175:
1176:
1.215 albertel 1177: if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous
1178: && $status eq 'CAN_ANSWER') {
1.12 albertel 1179: my $award='SUBMITTED';
1.28 albertel 1180: &Apache::essayresponse::file_submission("$version.0",'bridgetask',
1.20 albertel 1181: 'portfiles',\$award);
1.14 albertel 1182: if ($award eq 'SUBMITTED' &&
1.28 albertel 1183: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}) {
1184: $Apache::lonhomework::results{"resource.0.tries"}=
1185: $Apache::lonhomework::results{"resource.$version.0.tries"}=
1186: 1+$Apache::lonhomework::history{"resource.$version.0.tries"};
1187:
1188: $Apache::lonhomework::results{"resource.0.award"}=
1189: $Apache::lonhomework::results{"resource.$version.0.award"}=
1190: $award;
1.51 albertel 1191: $Apache::lonhomework::results{"resource.0.submission"}=
1192: $Apache::lonhomework::results{"resource.$version.0.submission"}='';
1.64 albertel 1193: } else {
1194: delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
1.77 albertel 1195: $award = '';
1.10 albertel 1196: }
1.4 albertel 1197: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1198: &Apache::structuretags::finalize_storage();
1.148 albertel 1199: if ($award eq 'SUBMITTED') {
1.181 albertel 1200: &add_to_queue('gradingqueue',\%queue_data);
1.14 albertel 1201: }
1.1 albertel 1202: }
1.163 albertel 1203: if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1204: && exists($env{'form.cancel'})) {
1205: &check_queue_unlock($env{'form.queue'});
1206: &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
1207: } elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
1208: && !exists($env{'form.cancel'})) {
1.20 albertel 1209: my $optional_required=
1210: &Apache::lonxml::get_param('OptionalRequired',$parstack,
1211: $safeeval);
1212: my $optional_passed=0;
1213: my $mandatory_failed=0;
1214: my $ungraded=0;
1215: my $review=0;
1.21 albertel 1216: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.194 albertel 1217: my $dim = $top;
1218: foreach my $id (@{$dimension{$dim}{'criterias'}}) {
1219: my $link=&link($id);
1220:
1221: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1222:
1223: if ($type eq 'criteria') {
1224: # dimensional 'criteria' don't get assigned grades
1225: $Apache::lonhomework::results{"resource.$version.0.$id.status"}=$env{'form.HWVAL_'.$link};
1226: $Apache::lonhomework::results{"resource.$version.0.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
1227: }
1.20 albertel 1228: my $status=
1.194 albertel 1229: $Apache::lonhomework::results{"resource.$version.0.$id.status"};
1230: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
1231:
1.20 albertel 1232: if ($status eq 'pass') {
1233: if (!$mandatory) { $optional_passed++; }
1234: } elsif ($status eq 'fail') {
1235: if ($mandatory) { $mandatory_failed++; }
1.194 albertel 1236: } elsif ($status eq 'review') {
1237: $review++;
1.20 albertel 1238: } elsif ($status eq 'ungraded') {
1239: $ungraded++;
1.49 albertel 1240: } else {
1241: $ungraded++;
1242: }
1.20 albertel 1243: }
1244: if ($optional_passed < $optional_required) {
1245: $mandatory_failed++;
1246: }
1.194 albertel 1247: &Apache::lonxml::debug(" task results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
1.89 albertel 1248: $Apache::lonhomework::results{'resource.0.regrader'}=
1.138 albertel 1249: $env{'user.name'}.':'.$env{'user.domain'};
1.20 albertel 1250: if ($review) {
1.89 albertel 1251: $Apache::lonhomework::results{"resource.$version.0.status"}='review';
1.20 albertel 1252: } elsif ($ungraded) {
1.89 albertel 1253: $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded';
1.20 albertel 1254: } elsif ($mandatory_failed) {
1.89 albertel 1255: $Apache::lonhomework::results{"resource.$version.0.status"}='fail';
1.25 albertel 1256: $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
1257: $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
1258: $Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
1.185 albertel 1259: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1260:
1261: if ($env{'form.regrade'} ne 'yes') {
1262: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1263: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1264: &Apache::grades::version_portfiles(
1265: \%Apache::lonhomework::results,
1266: ["$version.0.bridgetask"],$courseid,
1267: $symb,$udom,$uname,
1268: ["$version.0.bridgetask"]);
1269: }
1.20 albertel 1270: } else {
1.89 albertel 1271: $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
1.25 albertel 1272: $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
1273: $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
1274: $Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
1.185 albertel 1275: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
1.52 albertel 1276: if ($env{'form.regrade'} ne 'yes') {
1277: $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}=
1278: $Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"};
1279: &Apache::grades::version_portfiles(
1280: \%Apache::lonhomework::results,
1281: ["$version.0.bridgetask"],$courseid,
1282: $symb,$udom,$uname,
1283: ["$version.0.bridgetask"]);
1284: }
1.20 albertel 1285: }
1.89 albertel 1286: $Apache::lonhomework::results{"resource.0.status"}=
1287: $Apache::lonhomework::results{"resource.$version.0.status"};
1.28 albertel 1288: if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
1.26 albertel 1289: $Apache::lonhomework::results{"resource.0.award"}=
1.50 albertel 1290: $Apache::lonhomework::results{"resource.$version.0.award"};
1.26 albertel 1291: $Apache::lonhomework::results{"resource.0.awarded"}=
1.50 albertel 1292: $Apache::lonhomework::results{"resource.$version.0.awarded"};
1.26 albertel 1293: $Apache::lonhomework::results{"resource.0.solved"}=
1.50 albertel 1294: $Apache::lonhomework::results{"resource.$version.0.solved"};
1.25 albertel 1295: }
1.94 albertel 1296: &minimize_storage();
1.21 albertel 1297: &Apache::structuretags::finalize_storage();
1.188 albertel 1298:
1299: # data stored, now handle queue
1300: if ($review) {
1301: if ($env{'form.queue'} eq 'reviewqueue') {
1302: &check_queue_unlock($env{'form.queue'});
1303: &Apache::lonxml::debug(" still needs review not changing status.");
1304: } else {
1305: if ($env{'form.queue'} ne 'none') {
1306: &move_between_queues($env{'form.queue'},'reviewqueue');
1307: } else {
1308: &add_to_queue('reviewqueue',\%queue_data);
1309: }
1310: }
1311: } elsif ($ungraded) {
1312: if ($env{'form.queue'} eq 'reviewqueue') {
1313: &Apache::lonxml::debug("moving back.");
1314: &move_between_queues($env{'form.queue'},
1315: 'gradingqueue');
1316: } elsif ($env{'form.queue'} eq 'none' ) {
1317: &add_to_queue('gradingqueue',\%queue_data);
1318: } else {
1319: &check_queue_unlock($env{'form.queue'});
1320: }
1321: } elsif ($mandatory_failed) {
1322: &remove_from_queue($env{'form.queue'});
1323: } else {
1324: &remove_from_queue($env{'form.queue'});
1325: }
1.20 albertel 1326: }
1.184 albertel 1327: if (exists($Apache::lonhomework::results{'INTERNAL_store'})) {
1328: # instance generation occured and hasn't yet been stored
1329: &Apache::structuretags::finalize_storage();
1330: }
1.15 albertel 1331: } elsif ($target eq 'webgrade') {
1.208 albertel 1332: if (&nest()) {
1333: &Apache::lonxml::endredirection();
1334: &end_delay();
1335: $result.=$dimension{$top}{'result'};
1336: } else {
1337: $result.=&Apache::lonxml::endredirection();
1338: }
1.194 albertel 1339: my $dim = $top;
1340: foreach my $id (@{$dimension{$dim}{'criterias'}} ) {
1341: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1342: if ($type eq 'dimension') {
1343: # dimensional 'criteria' don't get assigned grades
1344: next;
1345: } else {
1346: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
1347: [@_]);
1348: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
1349: my $internal_location=&internal_location($id);
1.209 albertel 1350: if ($result =~ m/\Q$internal_location\E/) {
1351: $result=~s/\Q$internal_location\E/$criteria/;
1352: } else {
1353: $result.=$criteria;
1354: }
1355:
1.194 albertel 1356: }
1357: }
1358: $result.="</div>";
1.20 albertel 1359: #$result.='<input type="submit" name="next" value="'.
1360: # &mt('Save & Next').'" /> ';
1361: #$result.='<input type="submit" name="end" value="'.
1362: # &mt('Save & Stop Grading').'" /> ';
1363: #$result.='<input type="submit" name="throwaway" value="'.
1364: # &mt('Throw Away & Stop Grading').'" /> ';
1365: #$result.='<input type="submit" name="save" value="'.
1366: # &mt('Save Partial Grade and Continue Grading').'" /> ';
1.124 albertel 1367: $result.='</form>'."\n</div>\n</div>\n".
1.140 albertel 1368: &Apache::loncommon::end_page();
1.1 albertel 1369: } elsif ($target eq 'meta') {
1.70 albertel 1370: $result.=&Apache::response::meta_package_write('Task');
1.77 albertel 1371: $result.=&Apache::response::meta_stores_write('solved','string',
1372: 'Problem Status');
1373: $result.=&Apache::response::meta_stores_write('tries','int_zeropos',
1374: 'Number of Attempts');
1375: $result.=&Apache::response::meta_stores_write('awarded','float',
1376: 'Partial Credit Factor');
1377: $result.=&Apache::response::meta_stores_write('status','string',
1378: 'Bridge Task Status');
1.182 albertel 1379: } elsif ($target eq 'edit') {
1.227 albertel 1380: $result.= &Apache::structuretags::problem_edit_footer();
1.1 albertel 1381: }
1.179 albertel 1382: &Apache::structuretags::reset_problem_globals('Task');
1.4 albertel 1383: undef($Apache::lonhomework::parsing_a_task);
1.1 albertel 1384: return $result;
1385: }
1386:
1.31 albertel 1387: sub move_between_queues {
1388: my ($src_queue,$dest_queue)=@_;
1.49 albertel 1389: my $cur_data;
1390: if ($src_queue ne 'none') {
1391: $cur_data=&get_queue_data($src_queue);
1392: if (!$cur_data) { return 'not_exist'; }
1393: } else {
1394: $cur_data = ['none'];
1395: }
1.148 albertel 1396: my $result=&add_to_queue($dest_queue,$cur_data);
1.31 albertel 1397: if ($result ne 'ok') {
1398: return $result;
1399: }
1400: &check_queue_unlock($src_queue);
1401: return &remove_from_queue($src_queue);
1.21 albertel 1402: }
1403:
1404: sub check_queue_unlock {
1.32 albertel 1405: my ($queue,$key,$allow_not_me)=@_;
1.49 albertel 1406: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1407: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.32 albertel 1408: if (!defined($key)) {
1.138 albertel 1409: $key="$symb\0queue\0$uname:$udom";
1.32 albertel 1410: }
1.30 albertel 1411: my $cnum=$env{'course.'.$cid.'.num'};
1412: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1413: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.30 albertel 1414: my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
1415: if ($who eq $me) {
1.163 albertel 1416: &Apache::lonxml::debug("unlocking my own $who");
1.32 albertel 1417: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1418: } elsif ($allow_not_me) {
1.33 albertel 1419: &Apache::lonxml::debug("unlocking $who by $me");
1.32 albertel 1420: return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
1.30 albertel 1421: }
1.32 albertel 1422: return 'not_owner';
1.21 albertel 1423: }
1424:
1.88 albertel 1425: sub in_queue {
1426: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1427: if ($queue eq 'none') { return 0; }
1428: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1429: || !defined($udom) || !defined($uname)) {
1.185 albertel 1430: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.88 albertel 1431: $cnum=$env{'course.'.$cid.'.num'};
1432: $cdom=$env{'course.'.$cid.'.domain'};
1433: }
1434:
1435: my $key=&encode_queue_key($symb,$udom,$uname);
1436: my %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum);
1437:
1438: if (defined($results{$key})) {
1439: return 1;
1440: }
1441: return 0;
1442: }
1443:
1.21 albertel 1444: sub remove_from_queue {
1.86 albertel 1445: my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
1.49 albertel 1446: if ($queue eq 'none') { return 'ok'; }
1.86 albertel 1447: if (!defined($symb) || !defined($cdom) || !defined($cnum)
1448: || !defined($udom) || !defined($uname)) {
1.185 albertel 1449: ($symb,my $cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.86 albertel 1450: $cnum=$env{'course.'.$cid.'.num'};
1451: $cdom=$env{'course.'.$cid.'.domain'};
1452: }
1.88 albertel 1453: if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) {
1454: return 'ok';
1455: }
1.86 albertel 1456: my $key=&encode_queue_key($symb,$udom,$uname);
1.27 albertel 1457: my @keys=($key,"$key\0locked");
1.31 albertel 1458: return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
1.21 albertel 1459: }
1460:
1.16 albertel 1461: sub setup_env_for_other_user {
1462: my ($queue_key,$safeeval)=@_;
1463: my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
1.30 albertel 1464: &Apache::lonxml::debug("setup_env for $queue_key");
1.16 albertel 1465: $env{'form.grade_symb'}=$symb;
1466: $env{'form.grade_domain'}=$udom;
1467: $env{'form.grade_username'}=$uname;
1468: $env{'form.grade_courseid'}=$env{'request.course.id'};
1469: &Apache::lonxml::initialize_rndseed($safeeval);
1470: }
1471:
1.31 albertel 1472: sub get_queue_data {
1.165 albertel 1473: my ($queue,$udom,$uname)=@_;
1.185 albertel 1474: my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonnet::whichuser();
1.165 albertel 1475: if (!$uname || !$udom) {
1476: $uname=$other_uname;
1477: $udom =$other_udom;
1478: }
1.31 albertel 1479: my $cnum=$env{'course.'.$cid.'.num'};
1480: my $cdom=$env{'course.'.$cid.'.domain'};
1.138 albertel 1481: my $todo="$symb\0queue\0$uname:$udom";
1.31 albertel 1482: my ($key,$value)=&Apache::lonnet::get($queue,[$todo],$cdom,$cnum);
1483: if ($key eq $todo && ref($value)) {
1484: return $value;
1485: }
1486: return undef;
1487: }
1488:
1.84 albertel 1489:
1.49 albertel 1490: sub check_queue_for_key {
1.84 albertel 1491: my ($cdom,$cnum,$queue,$todo)=@_;
1492:
1.49 albertel 1493: my %results=
1494: &Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
1495:
1496: if (exists($results{$todo}) && ref($results{$todo})) {
1497: if (defined($results{"$todo\0locked"})) {
1498: return 'locked';
1499: }
1.148 albertel 1500: if (my $slot=&slotted_access($results{$todo})) {
1.86 albertel 1501: my %slot_data=&Apache::lonnet::get_slot($slot);
1502: if ($slot_data{'endtime'} > time) {
1503: return 'in_progress';
1504: }
1.148 albertel 1505: } else {
1506: my ($symb) = &decode_queue_key($todo);
1507: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1508: if ($due_date > time) {
1509: return 'in_progress';
1510: }
1.58 albertel 1511: }
1.49 albertel 1512: return 'enqueued';
1513: }
1514: return undef;
1515: }
1516:
1.14 albertel 1517: sub add_to_queue {
1.82 albertel 1518: my ($queue,$user_data)=@_;
1.49 albertel 1519: if ($queue eq 'none') { return 'ok'; }
1.185 albertel 1520: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.82 albertel 1521: if (!$cid || $env{'request.state'} eq 'construct') {
1522: return 'no_queue';
1523: }
1.14 albertel 1524: my $cnum=$env{'course.'.$cid.'.num'};
1525: my $cdom=$env{'course.'.$cid.'.domain'};
1526: my %data;
1.138 albertel 1527: $data{"$symb\0queue\0$uname:$udom"}=$user_data;
1.83 albertel 1528: return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
1.14 albertel 1529: }
1530:
1.156 albertel 1531: sub get_limited_classlist {
1532: my ($sections) = @_;
1533:
1534: my $classlist = &Apache::loncoursedata::get_classlist();
1.157 albertel 1535: foreach my $student (keys(%$classlist)) {
1536: if ( $classlist->{$student}[&Apache::loncoursedata::CL_STATUS()]
1537: ne 'Active') {
1538: delete($classlist->{$student});
1539: }
1540: }
1.156 albertel 1541:
1.237 albertel 1542: if (ref($sections) && !grep {$_ eq 'all'} (@{ $sections })) {
1.156 albertel 1543: foreach my $student (keys(%$classlist)) {
1544: my $section =
1545: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
1.237 albertel 1546: if (! grep {$_ eq $section} (@{ $sections })) {
1.156 albertel 1547: delete($classlist->{$student});
1548: }
1549: }
1550: }
1551: return $classlist;
1552: }
1553:
1554:
1.14 albertel 1555: sub show_queue {
1.32 albertel 1556: my ($queue,$with_selects)=@_;
1.14 albertel 1557: my $result;
1.185 albertel 1558: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 1559: my $cnum=$env{'course.'.$cid.'.num'};
1560: my $cdom=$env{'course.'.$cid.'.domain'};
1.59 albertel 1561:
1.237 albertel 1562: my @chosen_sections = &get_allowed_sections();
1.156 albertel 1563:
1564: my $classlist = &get_limited_classlist(\@chosen_sections);
1565:
1.63 albertel 1566: if (!(grep(/^all$/,@chosen_sections))) {
1.239 ! bisitz 1567: $result.='<p>'
! 1568: .&mt('Showing only sections [_1].'
! 1569: ,'<tt>'.join(', ',@chosen_sections).'</tt>')
! 1570: ."</p>\n";
1.63 albertel 1571: }
1.59 albertel 1572:
1.156 albertel 1573: my ($view,$view_section);
1574: my $scope = $env{'request.course.id'};
1575: if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
1576: $scope .= '/'.$env{'request.course.sec'};
1577: if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
1578: $view_section=$env{'request.course.sec'};
1579: } else {
1580: undef($view);
1581: }
1582: }
1583:
1.234 albertel 1584: $result .=
1585: '<p><a href="/adm/flip?postdata=return:">'.
1586: &mt('Return to resource').'</a></p><hr />'.
1.239 ! bisitz 1587: "\n<h3>".&mt('Current Queue - [_1]',$queue)."</h3>";
1.16 albertel 1588: my $regexp="^$symb\0";
1.30 albertel 1589: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.31 albertel 1590: my ($tmp)=%queue;
1591: if ($tmp=~/^error: 2 /) {
1.234 albertel 1592: $result.=
1.159 albertel 1593: &Apache::loncommon::start_data_table().
1594: &Apache::loncommon::start_data_table_row().
1595: '<td>'.&mt('Empty').'</td>'.
1596: &Apache::loncommon::end_data_table_row().
1597: &Apache::loncommon::end_data_table();
1.234 albertel 1598: return $result;
1.31 albertel 1599: }
1.103 albertel 1600: my $title=&Apache::lonnet::gettitle($symb);
1.234 albertel 1601: $result.=
1.159 albertel 1602: &Apache::loncommon::start_data_table().
1603: &Apache::loncommon::start_data_table_header_row();
1.239 ! bisitz 1604: if ($with_selects) { $result.='<th>'.&mt('Status').'</th><th></th>'; }
! 1605: $result.='<th>'.&mt('User').'</th><th>'.&mt('Data').'</th>'.
1.159 albertel 1606: &Apache::loncommon::end_data_table_header_row();
1.14 albertel 1607: foreach my $key (sort(keys(%queue))) {
1.59 albertel 1608: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235 albertel 1609: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 1610: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156 albertel 1611:
1612: my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1613:
1614: my $can_view=1;
1615: if (!$view
1616: || ($view_section && !$section)
1617: || ($view_section && $section && ($view_section ne $section))) {
1618: $can_view=0;
1619: }
1620:
1.32 albertel 1621: if ($key=~/locked$/ && !$with_selects) {
1.159 albertel 1622: $result.= &Apache::loncommon::start_data_table_row().
1623: "<td>$uname</td>";
1.103 albertel 1624: $result.='<td>'.$queue{$key}.'</td></tr>';
1.32 albertel 1625: } elsif ($key=~/timestamp$/ && !$with_selects) {
1.159 albertel 1626: $result.=&Apache::loncommon::start_data_table_row()."<td></td>";
1.103 albertel 1627: $result.='<td>'.
1.16 albertel 1628: &Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
1.32 albertel 1629: } elsif ($key!~/(timestamp|locked)$/) {
1.159 albertel 1630: $result.= &Apache::loncommon::start_data_table_row();
1.148 albertel 1631: my ($end_time,$slot_text);
1632: if (my $slot=&slotted_access($queue{$key})) {
1633: my %slot_data=&Apache::lonnet::get_slot($slot);
1634: $end_time = $slot_data{'endtime'};
1635: $slot_text = &mt('Slot: [_1]',$slot);
1636: } else {
1637: $end_time = &Apache::lonhomework::due_date('0',$symb);
1638: $slot_text = '';
1639: }
1.32 albertel 1640: if ($with_selects) {
1.158 www 1641: my $ekey=&escape($key);
1.103 albertel 1642: my ($action,$description,$status)=('select',&mt('Select'));
1.32 albertel 1643: if (exists($queue{"$key\0locked"})) {
1.217 albertel 1644: my ($locker,$time) =
1645: &get_lock_info($queue{"$key\0locked"});
1646: if ($time) {
1.214 albertel 1647: $time =
1648: &Apache::lonnavmaps::timeToHumanString($time,
1649: 'start');
1650: }
1.138 albertel 1651: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.239 ! bisitz 1652: $status=&mt('Locked by [_1] [_2]','<tt>'.$locker.'</tt>',$time);
1.217 albertel 1653: if ($me eq $locker) {
1.32 albertel 1654: ($action,$description)=('resume',&mt('Resume'));
1655: } else {
1656: ($action,$description)=('unlock',&mt('Unlock'));
1657: }
1658: }
1.62 albertel 1659: my $seclist;
1660: foreach my $sec (@chosen_sections) {
1661: $seclist.='<input type="hidden" name="chosensections"
1662: value="'.$sec.'" />';
1663: }
1.156 albertel 1664: if ($can_view && ($end_time ne '' && time > $end_time)) {
1.35 albertel 1665: $result.=(<<FORM);
1.103 albertel 1666: <td>$status</td>
1.32 albertel 1667: <td>
1.115 albertel 1668: <form style="display: inline" method="post">
1.32 albertel 1669: <input type="hidden" name="gradingkey" value="$ekey" />
1670: <input type="hidden" name="queue" value="$queue" />
1671: <input type="hidden" name="gradingaction" value="$action" />
1672: <input type="hidden" name="webgrade" value="no" />
1.33 albertel 1673: <input type="hidden" name="queuemode" value="selected" />
1.32 albertel 1674: <input type="submit" name="submit" value="$description" />
1.62 albertel 1675: $seclist
1.32 albertel 1676: </form>
1677: </td>
1678: FORM
1.156 albertel 1679: } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
1680: $result.='<td>'.&mt("Not gradable").'</td><td> </td>'
1.35 albertel 1681: } else {
1.148 albertel 1682: $result.='<td>'.&mt("In Progress").'</td><td> </td>'
1.35 albertel 1683: }
1.32 albertel 1684: }
1.156 albertel 1685: $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
1.138 albertel 1686: " <tt>($uname:$udom)</tt> </td>";
1.239 ! bisitz 1687: $result.='<td>'.$slot_text.' '
! 1688: .&mt('End time: [_1]'
! 1689: ,&Apache::lonlocal::locallocaltime($end_time))
! 1690: .'</td>'
! 1691: .&Apache::loncommon::end_data_table_row();
1.16 albertel 1692: }
1.14 albertel 1693: }
1.159 albertel 1694: $result.= &Apache::loncommon::end_data_table()."<hr />\n";
1.14 albertel 1695: return $result;
1696: }
1697:
1.237 albertel 1698: sub get_allowed_sections {
1699: my @chosen_sections;
1700: if (§ion_restricted()) {
1701: @chosen_sections = ($env{'request.course.sec'});
1702: } else {
1703: @chosen_sections =
1704: &Apache::loncommon::get_env_multiple('form.chosensections');
1705: }
1706:
1707: return @chosen_sections;
1708: }
1709:
1.235 albertel 1710: sub section_restricted {
1.237 albertel 1711: my $cid =(&Apache::lonnet::whichuser())[1];
1712: return (lc($env{'course.'.$cid.'.task_grading'}) eq 'section'
1713: && $env{'request.course.sec'} ne '' );
1714: }
1715:
1716: sub allow_grade_user {
1.235 albertel 1717: my ($classlist_entry) = @_;
1.237 albertel 1718:
1719: if (§ion_restricted()
1.235 albertel 1720: && $env{'request.course.sec'} ne
1721: $classlist_entry->[&Apache::loncoursedata::CL_SECTION()]) {
1.237 albertel 1722: return 0;
1.235 albertel 1723: }
1.237 albertel 1724: return 1;
1.235 albertel 1725: }
1726:
1.34 albertel 1727: sub get_queue_counts {
1728: my ($queue)=@_;
1729: my $result;
1.185 albertel 1730: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.34 albertel 1731: my $cnum=$env{'course.'.$cid.'.num'};
1732: my $cdom=$env{'course.'.$cid.'.domain'};
1.156 albertel 1733:
1.157 albertel 1734: my $classlist=&get_limited_classlist();
1.156 albertel 1735:
1.34 albertel 1736: my $regexp="^$symb\0";
1737: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1738: my ($tmp)=%queue;
1739: if ($tmp=~/^error: 2 /) {
1740: return (0,0,0);
1741: }
1.235 albertel 1742:
1.34 albertel 1743: my ($entries,$ready_to_grade,$locks)=(0,0,0);
1.96 albertel 1744: my %slot_cache;
1.34 albertel 1745: foreach my $key (sort(keys(%queue))) {
1.156 albertel 1746: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.235 albertel 1747: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 1748: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.235 albertel 1749:
1.34 albertel 1750: if ($key=~/locked$/) {
1751: $locks++;
1752: } elsif ($key=~/timestamp$/) {
1753: #ignore
1754: } elsif ($key!~/(timestamp|locked)$/) {
1755: $entries++;
1.148 albertel 1756: if (my $slot=&slotted_access($queue{$key})) {
1757: if (!exists($slot_cache{$slot})) {
1758: my %slot_data=&Apache::lonnet::get_slot($slot);
1759: $slot_cache{$slot} = \%slot_data;
1760: }
1761: if (time > $slot_cache{$slot}{'endtime'}) {
1762: $ready_to_grade++;
1763: }
1764: } else {
1765: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1766: if ($due_date ne '' && time > $due_date) {
1767: $ready_to_grade++;
1768: }
1.34 albertel 1769: }
1770: }
1771: }
1772: return ($entries,$ready_to_grade,$locks);
1773: }
1774:
1.49 albertel 1775: sub encode_queue_key {
1776: my ($symb,$udom,$uname)=@_;
1.138 albertel 1777: return "$symb\0queue\0$uname:$udom";
1.49 albertel 1778: }
1779:
1.14 albertel 1780: sub decode_queue_key {
1781: my ($key)=@_;
1782: my ($symb,undef,$user) = split("\0",$key);
1.138 albertel 1783: my ($uname,$udom) = split(':',$user);
1.14 albertel 1784: return ($symb,$uname,$udom);
1785: }
1786:
1787: sub queue_key_locked {
1.30 albertel 1788: my ($queue,$key,$cdom,$cnum)=@_;
1.33 albertel 1789: if (!defined($cdom) || !defined($cnum)) {
1.185 albertel 1790: my (undef,$cid)=&Apache::lonnet::whichuser();
1.33 albertel 1791: $cnum=$env{'course.'.$cid.'.num'};
1792: $cdom=$env{'course.'.$cid.'.domain'};
1793: }
1.14 albertel 1794: my ($key_locked,$value)=
1.30 albertel 1795: &Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
1.14 albertel 1796: if ($key_locked eq "$key\0locked") {
1.217 albertel 1797: return &get_lock_info($value);
1.14 albertel 1798: }
1799: return undef;
1800: }
1801:
1.148 albertel 1802: sub slotted_access {
1803: my ($queue_entry) = @_;
1804: if (ref($queue_entry) eq 'ARRAY') {
1805: if (defined($queue_entry->[0])) {
1806: return $queue_entry->[0];
1807: }
1808: return undef;
1809: } elsif (ref($queue_entry) eq 'HASH') {
1810: if (defined($queue_entry->{'slot'})) {
1811: return $queue_entry->{'slot'};
1812: }
1813: return undef;
1814: }
1815: return undef;
1816: }
1817:
1.14 albertel 1818: sub pick_from_queue_data {
1.156 albertel 1819: my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
1.98 albertel 1820: my @possible; # will hold queue entries that are valid to be selected
1.30 albertel 1821: foreach my $key (keys(%$queuedata)) {
1.68 albertel 1822: if ($key =~ /\0locked$/) { next; }
1823: if ($key =~ /\0timestamp$/) { next; }
1.156 albertel 1824:
1.14 albertel 1825: my ($symb,$uname,$udom)=&decode_queue_key($key);
1.235 albertel 1826: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 1827: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.156 albertel 1828:
1.14 albertel 1829: if ($check_section) {
1.156 albertel 1830: my $section =
1831: $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
1.17 albertel 1832: if ($section eq $check_section) {
1.33 albertel 1833: &Apache::lonxml::debug("my sec");
1.15 albertel 1834: next;
1835: }
1.14 albertel 1836: }
1.148 albertel 1837: my $end_time;
1838: if (my $slot=&slotted_access($queuedata->{$key})) {
1.154 albertel 1839: &Apache::lonxml::debug("looking at slot $slot");
1.148 albertel 1840: my %slot_data=&Apache::lonnet::get_slot($slot);
1841: if ($slot_data{'endtime'} < time) {
1842: $end_time = $slot_data{'endtime'};
1.154 albertel 1843: } else {
1844: &Apache::lonxml::debug("not time ".$slot_data{'endtime'});
1845: next;
1.148 albertel 1846: }
1847: } else {
1848: my $due_date = &Apache::lonhomework::due_date('0',$symb);
1.154 albertel 1849: if ($due_date < time) {
1.148 albertel 1850: $end_time = $due_date;
1.154 albertel 1851: } else {
1852: &Apache::lonxml::debug("not time $due_date");
1853: next;
1.148 albertel 1854: }
1855: }
1856:
1.98 albertel 1857: if (exists($queuedata->{"$key\0locked"})) {
1.33 albertel 1858: &Apache::lonxml::debug("someone already has um.");
1.15 albertel 1859: next;
1860: }
1.148 albertel 1861: push(@possible,[$key,$end_time]);
1.98 albertel 1862: }
1863: if (@possible) {
1864: # sort entries in order by slot end time
1865: @possible = sort { $a->[1] <=> $b->[1] } @possible;
1.137 albertel 1866: # pick one of the entries in the top 10% in small queues and one
1867: # of the first ten entries in large queues
1.139 albertel 1868: #my $ten_percent = int($#possible * 0.1);
1869: #if ($ten_percent < 1 ) { $ten_percent = 1; }
1870: #if ($ten_percent > 10) { $ten_percent = 10; }
1871: #my $max=($#possible < $ten_percent) ? $#possible : $ten_percent;
1.137 albertel 1872:
1.139 albertel 1873: #return $possible[int(rand($max))][0];
1874: return $possible[0][0];
1.14 albertel 1875: }
1876: return undef;
1877: }
1878:
1.217 albertel 1879: sub get_lock_info {
1880: my ($lock_info) = @_;
1881: if (wantarray) {
1882: if (ref($lock_info) eq 'ARRAY') {
1883: return @{$lock_info};
1884: } else {
1885: return ($lock_info);
1886: }
1887: } else {
1888: if (ref($lock_info) eq 'ARRAY') {
1889: return $lock_info->[0];
1890: } else {
1891: return $lock_info;
1892: }
1893: }
1894: return;
1895: }
1896:
1.15 albertel 1897: sub find_mid_grade {
1.30 albertel 1898: my ($queue,$symb,$cdom,$cnum)=@_;
1.158 www 1899: my $todo=&unescape($env{'form.gradingkey'});
1.138 albertel 1900: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.15 albertel 1901: if ($todo) {
1.30 albertel 1902: my $who=&queue_key_locked($queue,$todo,$cdom,$cnum);
1.15 albertel 1903: if ($who eq $me) { return $todo; }
1904: }
1905: my $regexp="^$symb\0.*\0locked\$";
1.30 albertel 1906: my %locks=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.15 albertel 1907: foreach my $key (keys(%locks)) {
1.217 albertel 1908: my $who= &get_lock_info($locks{$key});
1.15 albertel 1909: if ($who eq $me) {
1910: $todo=$key;
1911: $todo=~s/\0locked$//;
1912: return $todo;
1913: }
1914: }
1915: return undef;
1916: }
1917:
1.32 albertel 1918: sub lock_key {
1919: my ($queue,$todo)=@_;
1.138 albertel 1920: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.185 albertel 1921: my (undef,$cid)=&Apache::lonnet::whichuser();
1.32 albertel 1922: my $cnum=$env{'course.'.$cid.'.num'};
1923: my $cdom=$env{'course.'.$cid.'.domain'};
1.214 albertel 1924: my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> [$me,time]},
1.32 albertel 1925: $cdom,$cnum);
1.33 albertel 1926: &Apache::lonxml::debug("success $success $todo");
1.32 albertel 1927: if ($success eq 'ok') {
1928: return 1;
1929: }
1930: return 0;
1931: }
1932:
1.86 albertel 1933: sub get_queue_symb_status {
1.85 albertel 1934: my ($queue,$symb,$cdom,$cnum) = @_;
1935: if (!defined($cdom) || !defined($cnum)) {
1.235 albertel 1936: my (undef,$cid) =&Apache::lonnet::whichuser();
1.85 albertel 1937: $cnum=$env{'course.'.$cid.'.num'};
1938: $cdom=$env{'course.'.$cid.'.domain'};
1939: }
1.157 albertel 1940: my $classlist=&get_limited_classlist();
1.156 albertel 1941:
1.85 albertel 1942: my $regexp="^$symb\0";
1943: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1944: my ($tmp)=%queue;
1945: if ($tmp=~/^error: 2 /) { return; }
1946: my @users;
1947: foreach my $key (sort(keys(%queue))) {
1948: next if ($key=~/locked$/);
1949: next if ($key=~/timestamp$/);
1950: my ($symb,$uname,$udom) = &decode_queue_key($key);
1.156 albertel 1951: next if (!defined($classlist->{$uname.':'.$udom}));
1.237 albertel 1952: next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
1.85 albertel 1953: push(@users,"$uname:$udom");
1954: }
1955: return @users;
1956: }
1957:
1.14 albertel 1958: sub get_from_queue {
1.30 albertel 1959: my ($queue)=@_;
1.14 albertel 1960: my $result;
1.185 albertel 1961: my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
1.14 albertel 1962: my $cnum=$env{'course.'.$cid.'.num'};
1963: my $cdom=$env{'course.'.$cid.'.domain'};
1.32 albertel 1964: my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
1.33 albertel 1965: &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
1.16 albertel 1966: if ($todo) { return $todo; }
1.95 albertel 1967: my $attempts=0;
1.156 albertel 1968:
1.157 albertel 1969: my $classlist=&get_limited_classlist();
1.156 albertel 1970:
1.14 albertel 1971: while (1) {
1.95 albertel 1972: if ($attempts > 2) {
1973: # tried twice to get a queue entry, giving up
1974: return (undef,'unable');
1975: }
1.14 albertel 1976: my $starttime=time;
1.83 albertel 1977: &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
1978: $cdom,$cnum);
1.33 albertel 1979: &Apache::lonxml::debug("$starttime");
1.14 albertel 1980: my $regexp="^$symb\0queue\0";
1.156 albertel 1981: #my $range= ($attempts < 1 ) ? '0-100' : '0-400';
1.97 albertel 1982:
1.98 albertel 1983: my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
1.33 albertel 1984: #make a pass looking for a user _not_ in my section
1.14 albertel 1985: if ($env{'request.course.sec'}) {
1.33 albertel 1986: &Apache::lonxml::debug("sce");
1.30 albertel 1987: $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
1.156 albertel 1988: \%queue,$cdom,$cnum,$classlist);
1.33 albertel 1989: &Apache::lonxml::debug("sce $todo");
1.14 albertel 1990: }
1.33 albertel 1991: # no one _not_ in our section so look for any user that is
1992: # ready for grading
1.14 albertel 1993: if (!$todo) {
1.33 albertel 1994: &Apache::lonxml::debug("no sce");
1.156 albertel 1995: $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
1996: $classlist);
1.33 albertel 1997: &Apache::lonxml::debug("no sce $todo");
1.14 albertel 1998: }
1999: # no user to grade
2000: if (!$todo) { last; }
1.33 albertel 2001: &Apache::lonxml::debug("got $todo");
1.14 albertel 2002: # otherwise found someone so lets try to lock them
1.32 albertel 2003: # unless someone else already picked them
1.95 albertel 2004: if (!&lock_key($queue,$todo)) {
2005: $attempts++;
2006: next;
2007: }
1.14 albertel 2008: my (undef,$endtime)=
1.30 albertel 2009: &Apache::lonnet::get($queue,["$symb\0timestamp"],
1.14 albertel 2010: $cdom,$cnum);
1.33 albertel 2011: &Apache::lonxml::debug("emd $endtime");
1.14 albertel 2012: # someone else already modified the queue,
2013: # perhaps our picked user wass already fully graded between
2014: # when we picked him and when we locked his record? so lets
2015: # double check.
2016: if ($endtime != $starttime) {
2017: my ($key,$value)=
1.30 albertel 2018: &Apache::lonnet::get($queue,["$todo"],
1.14 albertel 2019: $cdom,$cnum);
1.33 albertel 2020: &Apache::lonxml::debug("check $key .. $value");
1.14 albertel 2021: if ($key eq $todo && ref($value)) {
2022: } else {
1.30 albertel 2023: &Apache::lonnet::del($queue,["$todo\0locked"],
1.14 albertel 2024: $cdom,$cnum);
1.33 albertel 2025: &Apache::lonxml::debug("del");
1.95 albertel 2026: $attempts++;
1.14 albertel 2027: next;
2028: }
2029: }
1.33 albertel 2030: &Apache::lonxml::debug("last $todo");
1.14 albertel 2031: last;
2032: }
2033: return $todo;
2034: }
2035:
1.49 albertel 2036: sub select_user {
1.185 albertel 2037: my ($symb,$cid)=&Apache::lonnet::whichuser();
1.49 albertel 2038:
1.237 albertel 2039: my @chosen_sections = &get_allowed_sections();
1.156 albertel 2040: my $classlist = &get_limited_classlist(\@chosen_sections);
1.63 albertel 2041:
2042: my $result;
2043: if (!(grep(/^all$/,@chosen_sections))) {
1.239 ! bisitz 2044: $result.='<p>'
! 2045: .&mt('Showing only sections [_1].'
! 2046: ,'<tt>'.join(', ',@chosen_sections).'</tt>')
! 2047: .'</p> '."\n";
1.63 albertel 2048: }
1.159 albertel 2049: $result.=&Apache::loncommon::start_data_table();
1.49 albertel 2050:
1.156 albertel 2051: foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
1.49 albertel 2052: my ($uname,$udom) = split(/:/,$student);
1.59 albertel 2053:
1.84 albertel 2054: my $cnum=$env{'course.'.$cid.'.num'};
2055: my $cdom=$env{'course.'.$cid.'.domain'};
1.88 albertel 2056: my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname,
2057: 'Task');
1.49 albertel 2058: my $queue = 'none';
1.58 albertel 2059: my $cannot_grade;
2060: if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 2061: $queue = 'reviewqueue';
1.58 albertel 2062: if ($status{'reviewqueue'} eq 'in_progress') {
2063: $cannot_grade=1;
2064: }
2065: } elsif ($status{'gradingqueue'} =~ /^(in_progress|enqueue)$/) {
1.49 albertel 2066: $queue = 'gradingqueue';
1.58 albertel 2067: if ($status{'gradingqueue'} eq 'in_progress') {
2068: $cannot_grade=1;
2069: }
1.49 albertel 2070: }
2071: my $todo =
1.158 www 2072: &escape(&encode_queue_key($symb,$udom,$uname));
1.58 albertel 2073: if ($cannot_grade) {
1.159 albertel 2074: $result.=&Apache::loncommon::start_data_table_row().
2075: '<td> </td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
1.58 albertel 2076: '</td><td>';
2077: } else {
1.62 albertel 2078: my $seclist;
2079: foreach my $sec (@chosen_sections) {
2080: $seclist.='<input type="hidden" name="chosensections"
2081: value="'.$sec.'" />';
2082: }
1.159 albertel 2083: $result.=&Apache::loncommon::start_data_table_row();
1.58 albertel 2084: $result.=<<RESULT;
1.49 albertel 2085: <td>
1.115 albertel 2086: <form style="display: inline" method="post">
1.49 albertel 2087: <input type="hidden" name="gradingkey" value="$todo" />
2088: <input type="hidden" name="queue" value="$queue" />
2089: <input type="hidden" name="webgrade" value="no" />
1.52 albertel 2090: <input type="hidden" name="regrade" value="yes" />
1.62 albertel 2091: <input type="submit" name="submit" value="Regrade" />
2092: $seclist
1.49 albertel 2093: </form>
1.237 albertel 2094: <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt> Sec: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()]</td>
1.49 albertel 2095: <td>
2096: RESULT
1.58 albertel 2097: }
1.49 albertel 2098: if ($status{'status'} eq 'pass') {
2099: $result .= '<font color="green">'.&mt('Passed').'</font>';
2100: } elsif ($status{'status'} eq 'fail') {
2101: $result .= '<font color="red">'.&mt('Failed').'</font>';
2102: } elsif ($status{'status'} eq 'review') {
2103: $result .= '<font color="blue">'.&mt('Under Review').'</font>';
2104: } elsif ($status{'status'} eq 'ungraded') {
2105: $result .= &mt('Ungraded');
2106: } elsif ($status{'status'} ne '') {
2107: $result .= '<font color="orange">'.&mt('Unknown Status').'</font>';
2108: } else {
2109: $result.=" ";
2110: }
2111: if ($status{'version'}) {
2112: $result .= ' '.&mt('Version').' '.$status{'version'};
2113: }
1.101 albertel 2114: if ($status{'grader'}) {
2115: $result .= ' '.&mt('(Graded by [_1])',$status{'grader'}).' ';
2116: }
1.49 albertel 2117: $result.= '</td><td>';
2118: if ($status{'reviewqueue'} eq 'enqueued') {
2119: $result .= &mt('Awaiting Review');
2120: } elsif ($status{'reviewqueue'} eq 'locked') {
2121: $result .= &mt('Under Review');
1.58 albertel 2122: } elsif ($status{'reviewqueue'} eq 'in_progress') {
2123: $result .= &mt('Still being worked on.');
1.49 albertel 2124: } elsif ($status{'gradingqueue'} eq 'enqueued') {
2125: $result .= &mt('Awaiting Grading');
2126: } elsif ($status{'gradingqueue'} eq 'locked') {
2127: $result .= &mt('Being Graded');
1.58 albertel 2128: } elsif ($status{'gradingqueue'} eq 'in_progress') {
2129: $result .= &mt('Still being worked on.');
1.49 albertel 2130: } else {
2131: $result.=" ";
2132: }
1.159 albertel 2133: $result.= '</td>'.&Apache::loncommon::end_data_table_row();
1.49 albertel 2134: }
1.159 albertel 2135: $result.=&Apache::loncommon::end_data_table();
1.49 albertel 2136: return $result;
2137: }
2138:
2139: sub get_student_status {
1.86 albertel 2140: my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
2141:
2142: my %status;
2143:
2144: if ($type eq 'Task') {
2145: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1.49 albertel 2146: $udom,$uname);
1.89 albertel 2147: $status{'status'}=$record{'resource.0.status'};
2148: $status{'version'}=$record{'resource.0.version'};
2149: $status{'grader'}=$record{'resource.0.regrader'};
1.86 albertel 2150: }
2151: $status{'reviewqueue'}=
2152: &check_queue_for_key($cdom,$cnum,'reviewqueue',
2153: &encode_queue_key($symb,$udom,$uname));
2154: $status{'gradingqueue'}=
2155: &check_queue_for_key($cdom,$cnum,'gradingqueue',
2156: &encode_queue_key($symb,$udom,$uname));
1.49 albertel 2157: return %status;
2158: }
2159:
1.1 albertel 2160: sub start_ClosingParagraph {
2161: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2162: my $result;
2163: if ($target eq 'web') {
1.13 albertel 2164: } elsif ($target eq 'webgrade') {
2165: &Apache::lonxml::startredirection();
1.225 albertel 2166: } elsif ($target eq 'edit') {
2167: $result = &Apache::edit::tag_start($target,$token);
2168: } elsif ($target eq 'modified') {
1.1 albertel 2169: }
2170: return $result;
2171: }
2172:
2173: sub end_ClosingParagraph {
2174: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2175: my $result;
2176: if ($target eq 'web') {
1.13 albertel 2177: } elsif ($target eq 'webgrade') {
2178: &Apache::lonxml::endredirection();
1.1 albertel 2179: }
2180: return $result;
2181: }
2182:
1.227 albertel 2183: sub insert_ClosingParagraph {
2184: return '
2185: <ClosingParagraph>
2186: <startouttext />
2187: <endouttext />
2188: </ClosingParagraph>';
2189: }
2190:
1.168 albertel 2191: sub get_dim_id {
1.194 albertel 2192: if (@Apache::bridgetask::dimension) {
2193: return $Apache::bridgetask::dimension[-1];
2194: } else {
2195: return $top;
2196: }
1.168 albertel 2197: }
2198:
1.19 albertel 2199: sub get_id {
2200: my ($parstack,$safeeval)=@_;
1.236 albertel 2201: return &Apache::lonxml::get_id($parstack,$safeeval);
1.19 albertel 2202: }
2203:
1.162 albertel 2204: sub start_Setup {
2205: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225 albertel 2206: my $result;
1.168 albertel 2207: my $dim = &get_id($parstack,$safeeval);
2208: push(@Apache::bridgetask::dimension,$dim);
1.225 albertel 2209: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
2210: &Apache::lonxml::startredirection();
2211: } elsif ($target eq 'edit') {
2212: $result = &Apache::edit::tag_start($target,$token);
2213: $result.= &Apache::edit::text_arg('Id:','id',$token,10).
2214: &Apache::edit::end_row().
2215: &Apache::edit::start_spanning_row();
2216: } elsif ($target eq 'modified') {
2217: my $constructtag=
2218: &Apache::edit::get_new_args($token,$parstack,$safeeval,'id');
2219: if ($constructtag) {
2220: $result = &Apache::edit::rebuild_tag($token);
2221: }
2222: }
2223: return $result;
1.162 albertel 2224: }
1.173 albertel 2225:
2226: {
2227: my @allowed;
2228: sub enable_dimension_parsing {
2229: my ($id) = @_;
2230: push(@allowed,$id);
2231: }
2232: sub disable_dimension_parsing {
2233: pop(@allowed);
2234: }
2235: sub skip_dimension_parsing {
2236: my ($check) = @_;
2237: if (!@allowed) { return 0;}
2238: # if unspecified allow any id
2239: if ($allowed[-1] eq undef) { return 0;}
2240:
2241: return ($check ne $allowed[-1]);
2242: }
2243: }
2244:
1.151 albertel 2245: sub start_Question { return &start_Dimension(@_); }
1.1 albertel 2246: sub start_Dimension {
1.173 albertel 2247: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.168 albertel 2248: my $dim = &get_id($parstack,$safeeval);
2249: my $previous_dim;
1.225 albertel 2250: my $result;
2251: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2252: if (@Apache::bridgetask::dimension) {
2253: $previous_dim = $Apache::bridgetask::dimension[-1];
2254: push(@{$Apache::bridgetask::dimension{$previous_dim}{'contains'}},
2255: $dim);
2256: if(&skip_dimension_parsing($dim)) {
2257: $dimension{$previous_dim}{'criteria.'.$dim} =
2258: $token->[4]
2259: .&Apache::lonxml::get_all_text('/'.$tagstack->[-1],$parser,
2260: $style)
2261: .'</'.$tagstack->[-1].'>';
2262: }
2263: $dimension{$previous_dim}{'criteria.'.$dim.'.type'}='dimension';
2264: $dimension{$previous_dim}{'criteria.'.$dim.'.mandatory'}=
2265: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2266: push(@{$dimension{$previous_dim}{'criterias'}},$dim);
2267: $dimension{$dim}{'nested'}=$previous_dim;
2268: $dimension{$dim}{'depth'} = 1 + $dimension{$previous_dim}{'depth'};
2269:
2270: &Apache::lonxml::debug("adding $dim as criteria to $previous_dim");
2271: } else {
2272: $dimension{$top}{'depth'}=0;
2273: $dimension{$top}{'criteria.'.$dim.'.type'}='dimension';
2274: $dimension{$top}{'criteria.'.$dim.'.mandatory'}=
2275: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
2276: push(@{$dimension{$top}{'criterias'}},$dim);
2277: $dimension{$dim}{'nested'}=$top;
2278: }
2279: push(@Apache::bridgetask::dimension,$dim);
2280: &Apache::lonxml::startredirection();
2281: if (!&skip_dimension_parsing($dim)) {
2282: &enable_dimension_parsing($dim);
2283: }
2284: } elsif ($target eq 'edit') {
2285: $result = &Apache::edit::tag_start($target,$token);
2286: $result.=
2287: &Apache::edit::text_arg('Id:','id',$token,10).' '.
2288: &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233 albertel 2289: [['Y', 'Yes'],
2290: ['N','No'],],
1.225 albertel 2291: $token).' <br /> '.
2292: &Apache::edit::text_arg('Required number of passed optional elements to pass the '.$token->[1].':',
2293: 'OptionalRequired',$token,4).
2294: &Apache::edit::end_row().
2295: &Apache::edit::start_spanning_row();
2296: } elsif ($target eq 'modified') {
2297: my $constructtag=
2298: &Apache::edit::get_new_args($token,$parstack,$safeeval,
2299: 'id','Mandatory','OptionalRequired');
2300: if ($constructtag) {
2301: $result = &Apache::edit::rebuild_tag($token);
2302: }
1.168 albertel 2303: }
1.225 albertel 2304: return $result;# &internal_location($dim);
1.1 albertel 2305: }
2306:
1.160 albertel 2307: sub start_QuestionText {
2308: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225 albertel 2309: my $result;
2310: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2311: my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
1.168 albertel 2312: my $dim = &get_dim_id();
1.169 albertel 2313: $dimension{$dim}{'questiontext'}=$text;
1.225 albertel 2314: } elsif ($target eq 'edit') {
2315: $result = &Apache::edit::tag_start($target,$token);
2316: } elsif ($target eq 'modified') {
1.160 albertel 2317: }
1.225 albertel 2318: return $result;
1.160 albertel 2319: }
2320:
2321: sub end_QuestionText {
2322: return '';
2323: }
2324:
1.227 albertel 2325: sub insert_QuestionText {
2326: return '
2327: <QuestionText>
2328: <startouttext />
2329: <endouttext />
2330: </QuestionText>';
2331: }
2332:
1.13 albertel 2333: sub get_instance {
1.75 albertel 2334: my ($dim)=@_;
2335: my $rand_alg=&Apache::lonnet::get_rand_alg();
2336: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
2337: $rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
2338: $rand_alg eq '64bit4' ) {
2339: &Apache::response::pushrandomnumber();
1.169 albertel 2340: my @order=&Math::Random::random_permutation(@{$dimension{$dim}{'instances'}});
1.75 albertel 2341: my $num=@order;
2342: my $version=&get_version();
2343: my $which=($version-1)%$num;
2344: return $order[$which];
2345: } else {
2346: my ($version,$previous) = &get_version();
2347: my $instance =
2348: $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
2349: if (defined($instance)) { return $instance; }
2350:
2351: &Apache::response::pushrandomnumber();
1.173 albertel 2352: if (ref($dimension{$dim}{'instances'}) eq 'ARRAY') {
2353: my @instances = @{$dimension{$dim}{'instances'}};
2354: # remove disabled instances
2355: for (my $i=0; $i < $#instances; $i++) {
2356: if ($dimension{$dim}{$instances[$i].'.disabled'}) {
2357: splice(@instances,$i,1);
2358: $i--;
2359: }
2360: }
2361: @instances = &Math::Random::random_permutation(@instances);
2362: $instance = $instances[($version-1)%scalar(@instances)];
2363: if ($version =~ /^\d$/) {
2364: $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} =
2365: $instance;
2366: $Apache::lonhomework::results{'INTERNAL_store'} = 1;
1.75 albertel 2367: }
2368: }
2369: &Apache::response::poprandomnumber();
2370: return $instance;
2371: }
1.13 albertel 2372: }
2373:
1.169 albertel 2374: sub get_criteria {
2375: my ($what,$version,$dim,$id) = @_;
2376: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
1.194 albertel 2377: my $prefix = ($type eq 'criteria' && $dim ne $top) ? "$dim.$id"
2378: : "$id";
1.169 albertel 2379: my $entry = "resource.$version.0.$prefix.$what";
2380: if (exists($Apache::lonhomework::results{$entry})) {
2381: return $Apache::lonhomework::results{$entry};
2382: }
2383: return $Apache::lonhomework::history{$entry};
2384: }
2385:
1.194 albertel 2386: sub link {
2387: my ($id) = @_;
2388: $id =~ s/\./_/g;
2389: return 'LC_GRADING_criteria_'.$id;
2390: }
2391: sub end_Question { return &end_Dimension(@_); }
2392: sub end_Dimension {
2393: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225 albertel 2394: my $result;
1.194 albertel 2395: my $dim=&get_id($parstack,$safeeval);
1.225 albertel 2396: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2397: $result=&Apache::lonxml::endredirection();
2398: if (&skip_dimension_parsing($dim)) {
2399: pop(@Apache::bridgetask::dimension);
2400: return;
2401: }
1.122 albertel 2402: }
1.194 albertel 2403: my $instance=&get_instance($dim);
2404: my $version=&get_version();
2405: if ($target eq 'web') {
2406: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2407: my @instances = $instance;
2408: if (&Apache::response::showallfoils()) {
2409: @instances = @{$dimension{$dim}{'instances'}};
1.173 albertel 2410: }
1.194 albertel 2411: my $shown_question_text;
2412: foreach my $instance (@instances) {
2413: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2414: [@_]);
2415: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2416: [@_],{'set_dim_id' => undef});
2417: my $task_status =
2418: $Apache::lonhomework::history{"resource.$version.0.status"};
2419: if ($task_status ne 'pass' && $task_status ne 'fail') {
2420:
2421: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2422: @{$dimension{$dim}{'criterias'}}) {
2423: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2424: &Apache::lonxml::debug("$id is $type");
2425: if ($type eq 'dimension') {
2426: $result.=
2427: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2428: [@_],{'set_dim_id' => $id});
1.173 albertel 2429: }
1.194 albertel 2430: }
2431: } else {
2432: my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"};
2433: my $mandatory='Mandatory';
2434: if (&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval) eq 'N') {
2435: $mandatory='Optional';
2436: }
1.200 albertel 2437: my $dim_info=
2438: "\n<div class='LC_$dim_status LC_question_grade'>\n\t";
1.212 albertel 2439: my $ucquestion =
2440: my $question =
2441: ('sub' x $dimension{$dim}{'depth'}).'question';
2442: $ucquestion =~ s/^(.)/uc($1)/e;
1.194 albertel 2443: if ($dim_status eq 'pass') {
1.239 ! bisitz 2444: $dim_info.='<h3>'.$ucquestion.' : '
! 2445: .&mt('you passed this [_1] [_2]',$mandatory,$question)
! 2446: .'</h3>';
1.194 albertel 2447: }
2448: if ($dim_status eq 'fail') {
1.239 ! bisitz 2449: $dim_info.='<h3>'.$ucquestion.' : '
! 2450: .&mt('you did not pass this [_1] [_2]',$mandatory,$question)
! 2451: .'</h3>';
1.194 albertel 2452: }
1.197 albertel 2453: my %counts = &get_counts($dim,$instance,$parstack,
2454: $safeeval);
2455:
1.200 albertel 2456: $dim_info.="\n\t<p>"
1.197 albertel 2457: .&question_status_message(\%counts,
2458: $dimension{$dim}{'depth'})
1.200 albertel 2459: ."</p>\n</div>\n";
1.194 albertel 2460:
2461: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2462: @{$dimension{$dim}{'criterias'}}) {
2463: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2464: if ($type eq 'dimension') {
1.205 albertel 2465: if (defined($dimension{$id}{'result'})) {
2466: $result.=$dimension{$id}{'result'};
2467: next;
2468: } else {
2469: $dim_info .=
2470: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2471: [@_],{'set_dim_id' => $id});
2472: }
2473: } else {
2474: my $criteria =
2475: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2476: [@_]);
2477: $dim_info .= &layout_web_Criteria($dim,$id,$criteria);
1.194 albertel 2478: }
1.169 albertel 2479: }
1.202 albertel 2480: # puts the results at the end of the dimension
1.226 albertel 2481: if ($result =~m{<QuestionGradeInfo\s*/>}) {
2482: $result=~s{<QuestionGradeInfo\s*/>}{$dim_info};
2483: } else {
2484: $result .= $dim_info;
2485: }
1.202 albertel 2486: # puts the results at the beginning of the dimension
2487: # my $internal_location=&internal_location($dim);
2488: # $result=~s/\Q$internal_location\E/$dim_info/;
1.19 albertel 2489: }
1.194 albertel 2490: }
1.206 albertel 2491: if ($result !~ /^\s*$/s) {
1.209 albertel 2492: # FIXME? this maybe unneccssary in the future, (CSE101 BT
2493: # from Fall 2006 geenrate a div that attempts to hide some
2494: # of the output in an odd way, this is a workaround so
2495: # those old ones will continue to work. # It puts the
2496: # LC_question div to come after any starting closie div
2497: # that the dimension produces
1.211 albertel 2498: if ($result =~ m{^\s*</div>}) {
2499: $result =~ s{^(\s*</div>)}
1.210 albertel 2500: {$1\n<div id="$dim" class="LC_question">};
1.209 albertel 2501: } else {
1.210 albertel 2502: $result = "\n".'<div id="'.$dim.'" class="LC_question">'.
1.209 albertel 2503: "\n".$result;
2504: }
2505: $result .= "\n</div>\n";
1.206 albertel 2506: }
1.194 albertel 2507: } elsif ($target eq 'webgrade') {
2508: # in case of any side effects that we need
2509: &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2510: &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]);
2511: $result.=
2512: &nested_parse(\$dimension{$dim}{'questiontext'},[@_],
2513: {'set_dim_id' => undef,
1.195 albertel 2514: 'delayed_dim_results' => 1});
1.194 albertel 2515: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2516: @{$dimension{$dim}{'criterias'}} ) {
2517: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2518: if ($type eq 'dimension') {
2519: # dimensional 'criteria' don't get assigned grades
2520: $result.=
2521: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2522: [@_],{'set_dim_id' => $id});
2523: next;
2524: } else {
2525: my $criteria =&nested_parse(\$dimension{$dim}{'criteria.'.$id},
2526: [@_]);
2527: $criteria = &layout_webgrade_Criteria($dim,$id,$criteria);
2528: my $internal_location=&internal_location($id);
1.209 albertel 2529: if ($result =~ m/\Q$internal_location\E/) {
2530: $result =~ s/\Q$internal_location\E/$criteria/;
2531: } else {
2532: $result.=$criteria ;
2533: }
1.151 albertel 2534: }
1.194 albertel 2535: }
2536: if (&nest()) {
2537: &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
2538: $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
2539: undef($result);
2540: }
2541: } elsif ($target eq 'grade' && $env{'form.webgrade'}) {
2542: my $optional_passed=0;
2543: my $mandatory_failed=0;
2544: my $ungraded=0;
2545: my $review=0;
2546:
2547: $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
2548: $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
2549: [@_]);
2550: $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
2551: [@_],{'set_dim_id' => undef});
2552:
2553: foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
2554: @{$dimension{$dim}{'criterias'}}) {
2555: my $link=&link($id);
2556:
2557: my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
2558: if ($type eq 'criteria') {
2559: # dimensional 'criteria' don't get assigned grades
2560: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
2561: $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
2562: } else {
2563: $result .=
2564: &nested_parse(\$dimension{$dim}{'criteria.'.$id},
2565: [@_],{'set_dim_id' => $id});
1.20 albertel 2566: }
1.194 albertel 2567: my $status= &get_criteria('status',$version,$dim,$id);
2568:
2569: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
2570: if ($status eq 'pass') {
2571: if (!$mandatory) { $optional_passed++; }
2572: } elsif ($status eq 'fail') {
2573: if ($mandatory) { $mandatory_failed++; }
2574: } elsif ($status eq 'review') {
2575: $review++;
2576: } elsif ($status eq 'ungraded') {
2577: $ungraded++;
1.20 albertel 2578: } else {
1.194 albertel 2579: $ungraded++;
1.20 albertel 2580: }
1.194 albertel 2581: }
2582:
2583: my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
2584: if ($opt_req !~ /\S/) {
2585: $opt_req=
2586: &Apache::lonxml::get_param('OptionalRequired',
2587: $parstack,$safeeval);
2588: if ($opt_req !~ /\S/) { $opt_req = 0; }
2589: }
2590: if ($optional_passed < $opt_req) {
2591: $mandatory_failed++;
2592: }
2593: &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
2594: if ($review) {
2595: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2596: 'review';
2597: } elsif ($ungraded) {
2598: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2599: 'ungraded';
2600: } elsif ($mandatory_failed) {
2601: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2602: 'fail';
1.69 albertel 2603: } else {
1.194 albertel 2604: $Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
2605: 'pass';
1.13 albertel 2606: }
1.225 albertel 2607: } elsif ($target eq 'edit') {
2608: } elsif ($target eq 'modified') {
1.194 albertel 2609: } else {
2610: # any other targets no output
2611: undef($result);
1.1 albertel 2612: }
1.225 albertel 2613: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
2614: &disable_dimension_parsing();
2615: pop(@Apache::bridgetask::dimension);
2616: }
1.194 albertel 2617: return $result;
2618: }
1.162 albertel 2619:
1.198 albertel 2620: sub question_status_message {
1.197 albertel 2621: my ($counts,$depth) = @_;
2622: my %req = ('man' => 'mandatory',
2623: 'opt' => 'optional',);
2624: my %type = ('cri' => 'criteria',
2625: 'dim' => ('sub'x($depth+1)).'questions',);
2626: my @sections;
2627: foreach my $req ('man','opt') {
2628: foreach my $type ('cri','dim') {
2629: if ($counts->{$req.'_'.$type}) {
2630: push(@sections,
1.213 albertel 2631: $counts->{$req.'_'.$type.'_passed'}.' of the '.
1.197 albertel 2632: $counts->{$req.'_'.$type}.' '.
2633: $req{$req}.' '.$type{$type});
2634: }
2635: }
2636: }
2637:
2638: my $status = 'You passed ';
2639: if (@sections == -1) {
2640: } elsif (@sections == 1) {
2641: $status .= $sections[0];
2642: } elsif (@sections == 2) {
2643: $status .= $sections[0].' and '.$sections[1];
2644: } else {
2645: my $last = pop(@sections);
2646: $status .= join(', ',@sections).', and '.$last;
2647: }
2648: $status .= '.';
2649: if ($counts->{'opt'}) {
1.239 ! bisitz 2650: # FIXME &mt() missing!
1.197 albertel 2651: $status .= ' You were required to pass '.$counts->{'opt_req'}.
1.220 albertel 2652: ' optional ';
1.219 albertel 2653: if ($counts->{'opt_dim'} + $counts->{'man_dim'} < 1) {
2654: $status .=
1.220 albertel 2655: ($counts->{'opt_req'} == 1?'criterion':'criteria');
1.219 albertel 2656: } else {
2657: $status .=
1.220 albertel 2658: 'component'.($counts->{'opt_req'} == 1?'':'s');
1.219 albertel 2659: }
2660: $status .= '.';
1.197 albertel 2661: }
2662: return $status;
2663: }
2664:
2665: sub get_counts {
2666: my ($dim,$instance,$parstack,$safeeval) = @_;
2667: my %counts;
2668: my @possible = ('man_cri','man_dim',
2669: 'opt_cri','opt_dim',
2670: 'man_cri_passed', 'man_dim_passed',
2671: 'opt_cri_passed', 'opt_dim_passed',
2672: 'man_passed',
2673: 'opt_passed',
2674: 'opt_req');
2675: foreach my $which (@possible) { $counts{$which} = 0; }
2676:
2677: my $version = &get_version();
2678:
2679: foreach my $id ( @{$dimension{$dim}{$instance.'.criterias'}},
2680: @{$dimension{$dim}{'criterias'}} ) {
2681: my $status = &get_criteria('status',$version,$dim,$id);
2682: my $which;
2683: if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
2684: eq 'N') {
2685: $which = 'opt';
2686: } else {
2687: $which = 'man';
2688: }
2689: $counts{$which}++;
2690: if ($status eq 'pass') { $counts{$which.'_passed'}++; }
2691: if ($dimension{$dim}{'criteria.'.$id.'.type'}
2692: eq 'dimension') {
2693: $which .= '_dim';
2694: } else {
2695: $which .= '_cri';
2696: }
2697: $counts{$which}++;
2698: if ($status eq 'pass') { $counts{$which.'_passed'}++; }
2699:
2700:
2701: }
2702: if ($counts{'man_dim_passed'} eq $counts{'man_dim'}) {
2703: $counts{'man_dim_passed'}='all';
2704: }
2705: if ($counts{'man_cri_passed'} eq $counts{'man_cri'}) {
2706: $counts{'man_cri_passed'}='all';
2707: }
2708:
2709: $counts{'opt_req'}=$dimension{$dim}{$instance.'.optionalrequired'};
2710: if ($counts{'opt_req'} !~ /\S/) {
2711: $counts{'opt_req'}= &Apache::lonxml::get_param('OptionalRequired',
2712: $parstack,$safeeval);
2713: if ($counts{'opt_req'} !~ /\S/) { $counts{'opt_req'} = 0; }
2714: }
2715: return %counts;
2716: }
2717:
1.194 albertel 2718: sub end_Setup {
2719: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.225 albertel 2720: my $result;
1.194 albertel 2721: my $dim=&get_id($parstack,$safeeval);
2722: my $instance=&get_instance($dim);
2723: my $version=&get_version();
1.225 albertel 2724: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
2725: $result=&Apache::lonxml::endredirection();
2726: }
1.194 albertel 2727: if ($target eq 'web') {
2728: @Apache::scripttag::parser_env = @_;
2729: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2730: my @instances = $instance;
2731: if (&Apache::response::showallfoils()) {
2732: @instances = @{$dimension{$dim}{'instances'}};
2733: }
2734: foreach my $instance (@instances) {
1.162 albertel 2735: @Apache::scripttag::parser_env = @_;
1.194 albertel 2736: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
1.162 albertel 2737: @Apache::scripttag::parser_env = @_;
1.194 albertel 2738: $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
1.162 albertel 2739: }
1.194 albertel 2740: } elsif ($target eq 'webgrade'
2741: || $target eq 'grade' && $env{'form.webgrade'}) {
2742: # in case of any side effects that we need
2743: @Apache::scripttag::parser_env = @_;
2744: &Apache::scripttag::xmlparse($dimension{$dim}{'intro'});
2745: @Apache::scripttag::parser_env = @_;
2746: &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
2747: @Apache::scripttag::parser_env = @_;
2748: &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
2749: } else {
2750: # any other targets no output
2751: undef($result);
1.162 albertel 2752: }
1.194 albertel 2753: pop(@Apache::bridgetask::dimension);
2754: return $result;
1.1 albertel 2755: }
2756:
1.113 albertel 2757: sub grading_history {
1.151 albertel 2758: my ($version,$dim,$id) = @_;
1.235 albertel 2759: if (!&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
2760: && !&Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
1.113 albertel 2761: return '';
2762: }
2763: my ($result,$grader);
1.194 albertel 2764: my $scope="resource.$version.0.";
2765: $scope .= ($dim ne $top) ? "$dim.$id"
2766: : "$id";
1.113 albertel 2767: foreach my $t (1..$Apache::lonhomework::history{'version'}) {
2768: if (exists($Apache::lonhomework::history{$t.':resource.0.regrader'})) {
2769: my ($gname,$gdom) =
1.138 albertel 2770: split(':',$Apache::lonhomework::history{$t.':resource.0.regrader'});
1.113 albertel 2771: my $fullname = &Apache::loncommon::plainname($gname,$gdom);
2772: $grader = &Apache::loncommon::aboutmewrapper($fullname,
2773: $gname,$gdom);
2774: }
2775: my $entry;
2776: if (exists($Apache::lonhomework::history{"$t:$scope.status"})) {
2777: $entry.="<tt>".$Apache::lonhomework::history{"$t:$scope.status"}.'</tt>';
2778: }
2779: if (exists($Apache::lonhomework::history{"$t:$scope.comment"})) {
2780: $entry.=' comment: "'.$Apache::lonhomework::history{"$t:$scope.comment"}.'"';
2781: }
2782: if ($entry) {
1.200 albertel 2783: $result.= "\n\t\t<li>\n\t\t\t$grader :\n\t\t\t $entry \n\t\t</li>";
1.113 albertel 2784: }
2785: }
2786: if ($result) {
1.200 albertel 2787: return "\n\t".'<ul class="LC_GRADING_pastgrading">'.$result.
2788: "\n\t".'</ul>'."\n";
1.113 albertel 2789: }
2790: return '';
2791: }
2792:
1.1 albertel 2793: sub start_IntroParagraph {
1.87 albertel 2794: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.1 albertel 2795: my $result;
1.168 albertel 2796: my $dim = &get_dim_id();
1.153 albertel 2797: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.151 albertel 2798: if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
1.169 albertel 2799: $dimension{$dim}{'intro'}=
1.151 albertel 2800: &Apache::lonxml::get_all_text('/introparagraph',
2801: $parser,$style);
2802: } elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2803: &Apache::lonxml::startredirection();
1.1 albertel 2804: }
1.47 albertel 2805:
1.225 albertel 2806: } elsif ($target eq 'edit') {
2807: $result = &Apache::edit::tag_start($target,$token);
2808: } elsif ($target eq 'modified') {
1.1 albertel 2809: }
2810: return $result;
2811: }
2812:
2813: sub end_IntroParagraph {
1.127 albertel 2814: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.128 albertel 2815: if ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
1.127 albertel 2816: my $result = &Apache::lonxml::endredirection();
2817: }
1.1 albertel 2818: }
2819:
1.227 albertel 2820: sub insert_IntroParagraph {
2821: return '
2822: <IntroParagraph>
2823: <startouttext />
2824: <endouttext />
2825: </IntroParagraph>';
2826: }
2827:
1.1 albertel 2828: sub start_Instance {
2829: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.168 albertel 2830: my $dim = &get_dim_id();
2831: my $id = &get_id($parstack,$safeeval);
1.169 albertel 2832: push(@{$dimension{$dim}{'instances'}},$id);
1.168 albertel 2833: push(@{$Apache::bridgetask::instance{$dim}},$id);
1.19 albertel 2834: push(@Apache::bridgetask::instancelist,$id);
1.169 albertel 2835: $dimension{$dim}{$id.'.optionalrequired'}=
1.19 albertel 2836: &Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
1.75 albertel 2837: my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
2838: if (lc($disabled) eq 'yes') {
1.169 albertel 2839: $dimension{$dim}{$id.'.disabled'}='1';
1.75 albertel 2840: }
1.225 albertel 2841: my $result;
2842: if ($target eq 'edit') {
2843: $result = &Apache::edit::tag_start($target,$token);
2844: $result.=
2845: &Apache::edit::text_arg('Id:','id',$token,10).' '.
2846: &Apache::edit::select_arg('Instance is Disabled:','Disabled',
2847: [['no', 'No'],
2848: ['yes','Yes'],],
2849: $token)
2850: .' <br /> '.
2851: &Apache::edit::text_arg('Required number of passed optional elements to pass the Instance:',
2852: 'OptionalRequired',$token,4)
2853: .&Apache::edit::end_row().
2854: &Apache::edit::start_spanning_row();
2855: } elsif ($target eq 'modified') {
2856: my $constructtag=
2857: &Apache::edit::get_new_args($token,$parstack,$safeeval,
2858: 'id','OptionalRequired','Disabled');
2859: if ($constructtag) {
2860: $result = &Apache::edit::rebuild_tag($token);
2861: }
2862: }
2863: return $result;
1.1 albertel 2864: }
2865:
2866: sub end_Instance {
1.225 albertel 2867: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2868: my $result;
2869: if ($target eq 'edit') {
2870: $result = &Apache::edit::tag_end($target,$token);
2871: }
2872: return $result;
1.1 albertel 2873: }
2874:
2875: sub start_InstanceText {
1.87 albertel 2876: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225 albertel 2877: my $result;
1.153 albertel 2878: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
1.225 albertel 2879: my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
2880: my $dim = &get_dim_id();
2881: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 2882: $dimension{$dim}{$instance_id.'.text'}=$text;
1.225 albertel 2883: } elsif ($target eq 'edit') {
2884: $result = &Apache::edit::tag_start($target,$token);
2885: } elsif ($target eq 'modified') {
1.1 albertel 2886: }
1.225 albertel 2887: return $result;
1.1 albertel 2888: }
2889:
2890: sub end_InstanceText {
2891: return '';
2892: }
2893:
1.227 albertel 2894: sub insert_InstanceText {
2895: return '
2896: <InstanceText>
2897: <startouttext />
2898: <endouttext />
2899: </InstanceText>';
2900: }
2901:
1.1 albertel 2902: sub start_Criteria {
1.87 albertel 2903: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.190 albertel 2904: my $result = '';
1.21 albertel 2905: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
1.225 albertel 2906: my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
1.168 albertel 2907: my $dim = &get_dim_id();
1.19 albertel 2908: my $id=&get_id($parstack,$safeeval);
1.194 albertel 2909: if ($target eq 'web' || $target eq 'webgrade') {
1.208 albertel 2910: if ($target eq 'webgrade') {
1.195 albertel 2911: &Apache::lonxml::debug(" for $dim $id stashing results into $dim ");
2912: $dimension{$dim}{'result'} .= &internal_location($id);
2913: } else {
2914: &Apache::lonxml::debug(" not stashing $dim $id");
1.206 albertel 2915: #$result .= &internal_location($id);
1.195 albertel 2916: }
1.194 albertel 2917: }
1.169 albertel 2918: &Apache::lonxml::debug("Criteria $id with $dim");
1.151 albertel 2919: if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
1.168 albertel 2920: my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
1.169 albertel 2921: $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
2922: $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
2923: $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
1.151 albertel 2924: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2925: push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
1.151 albertel 2926: } else {
1.169 albertel 2927: $dimension{$dim}{'criteria.'.$id}=$criteria;
2928: $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
2929: $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
1.151 albertel 2930: &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
1.169 albertel 2931: push(@{$dimension{$dim}{'criterias'}},$id);
1.194 albertel 2932: }
1.225 albertel 2933: } elsif ($target eq 'edit') {
2934: $result .=&Apache::edit::tag_start($target,$token);
2935: $result.=
2936: &Apache::edit::text_arg('Id:','id',$token,10).' '.
2937: &Apache::edit::select_arg('Passing is Mandatory:','Mandatory',
1.233 albertel 2938: [['Y', 'Yes'],
2939: ['N','No'],],
1.225 albertel 2940: $token)
2941: .' <br /> '.&Apache::edit::end_row().
2942: &Apache::edit::start_spanning_row();
2943: } elsif ($target eq 'modified') {
2944: my $constructtag=
2945: &Apache::edit::get_new_args($token,$parstack,$safeeval,
2946: 'id','Mandatory');
2947: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.194 albertel 2948: }
2949: return $result;
2950: }
2951:
2952: sub layout_web_Criteria {
2953: my ($dim,$id,$criteria) = @_;
1.190 albertel 2954:
1.194 albertel 2955: my $version = &get_version();
2956: my $status= &get_criteria('status', $version,$dim,$id);
2957: my $comment=&get_criteria('comment',$version,$dim,$id);
2958: my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
2959: if ($mandatory) {
2960: $mandatory='Mandatory';
2961: } else {
2962: $mandatory='Optional';
1.1 albertel 2963: }
1.194 albertel 2964: my $status_display=$status;
2965: $status_display=~s/^([a-z])/uc($1)/e;
2966: my $criteria_info.=
1.200 albertel 2967: '<div class="LC_'.$status.' LC_criteria">'."\n\t".'<h4>'
1.204 albertel 2968: .$mandatory.' Criteria</h4>'."\n\t".'<p class="LC_criteria_text">'
2969: ."\n";
1.202 albertel 2970: $criteria =~ s/^\s*//s;
2971: $criteria =~ s/\s*$//s;
1.194 albertel 2972: $criteria_info.= $criteria;
1.200 albertel 2973: $criteria_info.="\n\t".'</p>'.
2974: "\n\t".'<p class="LC_grade">'.$status_display.'</p>';
1.194 albertel 2975: if ($comment =~ /\w/) {
1.200 albertel 2976: $criteria_info.=
2977: "\n\t".
2978: '<p class="LC_comment">'.&mt('Comment: [_1]',$comment).'</p>';
1.194 albertel 2979: }
1.200 albertel 2980: $criteria_info.="\n".'</div>'."\n";
2981:
1.194 albertel 2982: return $criteria_info;
2983: }
2984:
2985: sub layout_webgrade_Criteria {
2986: my ($dim,$id,$criteria) = @_;
2987: my $link=&link($id);
2988: my $version = &get_version();
2989: my $status = &get_criteria('status',$version,$dim,$id);
1.200 albertel 2990: my %lt = ( 'ungraded' => 'Ungraded',
2991: 'fail' => 'Fail',
2992: 'pass' => 'Pass',
2993: 'review' => 'Review',
2994: 'comment' => 'Additional Comment for Student',
2995: );
2996: %lt = &Apache::lonlocal::texthash(%lt);
2997: my $comment = &get_criteria('comment',$version,$dim,$id);
2998: $comment = &HTML::Entities::encode($comment,'<>"&');
2999: my %checked;
3000: foreach my $which ('ungraded','fail','pass','review') {
3001: if ($status eq $which) { $checked{$which} = 'checked="checked"'; }
3002: }
3003: if (!%checked) { $checked{'ungraded'} = 'checked="checked"'; }
1.201 albertel 3004: my $buttons;
3005: foreach my $which ('ungraded','fail','pass','review') {
3006: $buttons .= <<END_BUTTON;
3007: <label class="LC_GRADING_$which">
3008: <input type="radio" name="HWVAL_$link" value="$which" $checked{$which} />
3009: $lt{$which}
3010: </label>
3011: END_BUTTON
3012: }
1.202 albertel 3013: $criteria =~ s/^\s*//s;
3014: $criteria =~ s/\s*$//s;
1.200 albertel 3015: my $result = <<END_CRITERIA;
1.201 albertel 3016: <div class="LC_GRADING_criteria">
3017: <div class="LC_GRADING_criteriatext">
3018: $criteria
3019: </div>
3020: <div class="LC_GRADING_grade">
3021: $buttons
3022: </div>
3023: <label class="LC_GRADING_comment">
3024: $lt{'comment'}
3025: <textarea class="LC_GRADING_comment_area" name="HWVAL_comment_$link">$comment</textarea>
3026: </label>
3027: </div>
1.200 albertel 3028: END_CRITERIA
3029: $result .= &grading_history($version,$dim,$id);
1.190 albertel 3030: return $result;
1.1 albertel 3031: }
3032:
1.47 albertel 3033: sub end_Criteria {
1.225 albertel 3034: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
3035: if ($target eq 'edit') {
3036: } elsif ($target eq 'modified') {
3037: }
3038: }
1.227 albertel 3039: sub insert_Criteria {
3040: return '
3041: <Criteria>
3042: <CriteriaText>
3043: <startouttext />
3044: <endouttext />
3045: </CriteriaText>
3046: </Criteria>';
3047: }
1.225 albertel 3048:
3049: sub start_CriteriaText {
3050: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
3051: my $result;
3052: if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
3053:
3054: } elsif ($target eq 'edit') {
3055: $result = &Apache::edit::tag_start($target,$token);
3056: } elsif ($target eq 'modified') {
3057: }
3058: return $result;
3059: }
3060:
3061: sub end_CriteriaText {
3062: return '';
1.47 albertel 3063: }
3064:
1.227 albertel 3065: sub insert_CriteriaText {
3066: return '
3067: <CriteriaText>
3068: <startouttext />
3069: <endouttext />
3070: </CriteriaText>';
3071: }
3072:
1.186 albertel 3073: sub start_GraderNote {
3074: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.225 albertel 3075: my $result;
1.186 albertel 3076: if ($target eq 'webgrade') {
1.225 albertel 3077: $result = '<div class="LC_GRADING_gradernote"><b>'.
1.187 albertel 3078: &mt('Note to graders:').'</b>';
1.225 albertel 3079: } elsif ($target eq 'edit') {
3080: $result = &Apache::edit::tag_start($target,$token);
3081: } elsif ($target eq 'modified') {
3082: } elsif ($target eq 'web' || $target eq 'grade') {
3083: my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style);
1.186 albertel 3084: }
1.225 albertel 3085: return $result;
1.186 albertel 3086: }
3087:
3088: sub end_GraderNote {
3089: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
3090:
3091: if ($target eq 'webgrade') {
3092: return '</div>';
3093: }
3094: return;
3095: }
3096:
1.227 albertel 3097: sub insert_GraderNote {
3098: return '
3099: <GraderNote>
3100: <startouttext />
3101: <endouttext />
3102: </GraderNote>';
3103: }
1.186 albertel 3104:
3105:
1.4 albertel 3106: sub proctor_validation_screen {
3107: my ($slot) = @_;
1.185 albertel 3108: my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
1.5 albertel 3109: my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
1.230 albertel 3110: if ($url ne '/adm/lonKaputt/lonlogo_broken.gif') {
3111: $url = "<tr><td colspan=\"2\"><img src=\"$url\" /></td></tr>";
3112: } else {
3113: undef($url);
3114: }
3115:
1.44 albertel 3116: my $name=&Apache::loncommon::plainname($user,$domain);
3117:
1.4 albertel 3118: my $msg;
1.11 albertel 3119: if ($env{'form.proctorpassword'}) {
1.230 albertel 3120: $msg.='<p><span class="LC_warning">'
3121: .&mt("Failed to authenticate the proctor.")
3122: .'</span></p>';
1.4 albertel 3123: }
1.230 albertel 3124:
3125: my $valid;
3126: my @possible_proctors=split(",",$slot->{'proctor'});
3127: foreach my $proctor (@possible_proctors) {
3128: if ($proctor =~ /$LONCAPA::username_re:$LONCAPA::domain_re/) {
3129: $valid = 1;
3130: last;
3131: }
3132: }
3133: if (!$valid) {
3134: $msg.='<p><span class="LC_error">'
1.239 ! bisitz 3135: .&mt("No valid proctors are defined.")
1.230 albertel 3136: .'</span></p>';
3137: }
3138:
1.47 albertel 3139: if (!$env{'form.proctordomain'}) { $env{'form.proctordomain'}=$domain; }
1.229 albertel 3140: my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
3141: $uri = &HTML::Entities::encode($uri,'<>&"');
1.239 ! bisitz 3142: # FIXME &mt() missing!
1.4 albertel 3143: my $result= (<<ENDCHECKOUT);
3144: <h2>Proctor Validation</h2>
3145: <p>Your room's proctor needs to validate your access to this resource.</p>
3146: $msg
1.229 albertel 3147: <form name="checkout" method="post" action="$uri">
1.4 albertel 3148: <input type="hidden" name="validate" value="yes" />
3149: <input type="hidden" name="submitted" value="yes" />
3150: <table>
1.44 albertel 3151: <tr><td>Proctor's Username:</td><td><input type="string" name="proctorname" value="$env{'form.proctorname'}" /></td></tr>
1.4 albertel 3152: <tr><td>Password:</td><td><input type="password" name="proctorpassword" value="" /></td></tr>
1.46 albertel 3153: <tr><td>Proctor's Domain:</td><td><input type="string" name="proctordomain" value="$env{'form.proctordomain'}" /></td></tr>
1.4 albertel 3154: </table>
3155: <input type="submit" name="checkoutbutton" value="Validate" /><br />
1.44 albertel 3156: <table border="1">
3157: <tr><td>
3158: <table>
3159: <tr><td colspan="2">Student who should be logged in is:</td></tr>
3160: <tr><td>Name:</td><td>$name</td></tr>
1.45 albertel 3161: <tr><td>Student ID:</td><td>$env{'environment.id'}</td></tr>
1.138 albertel 3162: <tr><td>Usename</td><td>$user:$domain</td></tr>
1.230 albertel 3163: $url
1.44 albertel 3164: </table>
3165: </tr></td>
3166: </table>
1.4 albertel 3167: </form>
3168: ENDCHECKOUT
3169: return $result;
3170: }
3171:
1.1 albertel 3172: 1;
3173: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>