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