Annotation of loncom/homework/grades.pm, revision 1.399.2.2
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.399.2.2! albertel 4: # $Id: grades.pm,v 1.399.2.1 2007/06/13 17:20:12 albertel Exp $
1.17 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: #
1.1 albertel 28:
29: package Apache::grades;
30: use strict;
31: use Apache::style;
32: use Apache::lonxml;
33: use Apache::lonnet;
1.3 albertel 34: use Apache::loncommon;
1.112 ng 35: use Apache::lonhtmlcommon;
1.68 ng 36: use Apache::lonnavmaps;
1.1 albertel 37: use Apache::lonhomework;
1.55 matthew 38: use Apache::loncoursedata;
1.362 albertel 39: use Apache::lonmsg();
1.1 albertel 40: use Apache::Constants qw(:common);
1.167 sakharuk 41: use Apache::lonlocal;
1.386 raeburn 42: use Apache::lonenc;
1.170 albertel 43: use String::Similarity;
1.359 www 44: use lib '/home/httpd/lib/perl';
45: use LONCAPA;
46:
1.315 bowersj2 47: use POSIX qw(floor);
1.87 www 48:
49: my %oldessays=();
1.103 albertel 50: my %perm=();
1.1 albertel 51:
1.68 ng 52: # ----- These first few routines are general use routines.----
1.44 ng 53: #
1.146 albertel 54: # --- Retrieve the parts from the metadata file.---
1.44 ng 55: sub getpartlist {
1.324 albertel 56: my ($symb) = @_;
57: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.146 albertel 58: my $partorder = &Apache::lonnet::metadata($url, 'partorder');
59: my @parts;
60: if ($partorder) {
61: for my $part (split (/,/,$partorder)) {
62: if (!&Apache::loncommon::check_if_partid_hidden($part,$symb)) {
63: push(@parts, $part);
64: }
65: }
66: } else {
67: my $metadata = &Apache::lonnet::metadata($url, 'packages');
68: foreach (split(/\,/,$metadata)) {
69: if ($_ =~ /^part_(.*)$/) {
70: if (!&Apache::loncommon::check_if_partid_hidden($1,$symb)) {
71: push(@parts, $1);
72: }
73: }
1.41 ng 74: }
1.16 albertel 75: }
1.146 albertel 76: my @stores;
77: foreach my $part (@parts) {
78: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
79: foreach my $key (@metakeys) {
80: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
81: }
82: }
83: return @stores;
1.2 albertel 84: }
85:
1.44 ng 86: # --- Get the symbolic name of a problem and the url
1.324 albertel 87: sub get_symb {
1.173 albertel 88: my ($request,$silent) = @_;
1.257 albertel 89: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
90: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 91: if ($symb eq '') {
92: if (!$silent) {
93: $request->print("Unable to handle ambiguous references:$url:.");
94: return ();
95: }
96: }
1.399.2.2! albertel 97: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 98: return ($symb);
1.32 ng 99: }
100:
1.129 ng 101: #--- Format fullname, username:domain if different for display
102: #--- Use anywhere where the student names are listed
103: sub nameUserString {
104: my ($type,$fullname,$uname,$udom) = @_;
105: if ($type eq 'header') {
1.398 albertel 106: return '<b> Fullname </b><span class="LC_internal_info">(Username)</span>';
1.129 ng 107: } else {
1.398 albertel 108: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
109: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 110: }
111: }
112:
1.44 ng 113: #--- Get the partlist and the response type for a given problem. ---
114: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 115: sub response_type {
1.324 albertel 116: my ($symb) = shift;
1.377 albertel 117:
118: my $navmap = Apache::lonnavmaps::navmap->new();
119: my $res = $navmap->getBySymb($symb);
120: my $partlist = $res->parts();
1.392 albertel 121: my %vPart =
122: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 123: my (%response_types,%handgrade);
124: foreach my $part (@{ $partlist }) {
1.392 albertel 125: next if (%vPart && !exists($vPart{$part}));
126:
1.377 albertel 127: my @types = $res->responseType($part);
128: my @ids = $res->responseIds($part);
129: for (my $i=0; $i < scalar(@ids); $i++) {
130: $response_types{$part}{$ids[$i]} = $types[$i];
131: $handgrade{$part.'_'.$ids[$i]} =
132: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
133: '.handgrade',$symb);
1.41 ng 134: }
135: }
1.377 albertel 136: return ($partlist,\%handgrade,\%response_types);
1.39 ng 137: }
138:
1.375 albertel 139: sub flatten_responseType {
140: my ($responseType) = @_;
141: my @part_response_id =
142: map {
143: my $part = $_;
144: map {
145: [$part,$_]
146: } sort(keys(%{ $responseType->{$part} }));
147: } sort(keys(%$responseType));
148: return @part_response_id;
149: }
150:
1.207 albertel 151: sub get_display_part {
1.324 albertel 152: my ($partID,$symb)=@_;
1.207 albertel 153: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
154: if (defined($display) and $display ne '') {
1.398 albertel 155: $display.= " (<span class=\"LC_internal_info\">id $partID</span>)";
1.207 albertel 156: } else {
157: $display=$partID;
158: }
159: return $display;
160: }
1.269 raeburn 161:
1.118 ng 162: #--- Show resource title
163: #--- and parts and response type
164: sub showResourceInfo {
1.324 albertel 165: my ($symb,$probTitle,$checkboxes) = @_;
1.154 albertel 166: my $col=3;
167: if ($checkboxes) { $col=4; }
1.398 albertel 168: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
169: $result .='<table border="0">';
1.324 albertel 170: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.126 ng 171: my %resptype = ();
1.122 ng 172: my $hdgrade='no';
1.154 albertel 173: my %partsseen;
1.375 albertel 174: foreach my $partID (sort keys(%$responseType)) {
175: foreach my $resID (sort keys(%{ $responseType->{$partID} })) {
176: my $handgrade=$$handgrade{$partID.'_'.$resID};
177: my $responsetype = $responseType->{$partID}->{$resID};
178: $hdgrade = $handgrade if ($handgrade eq 'yes');
179: $result.='<tr>';
180: if ($checkboxes) {
181: if (exists($partsseen{$partID})) {
182: $result.="<td> </td>";
183: } else {
184: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='on' /></td>";
185: }
186: $partsseen{$partID}=1;
1.154 albertel 187: }
1.375 albertel 188: my $display_part=&get_display_part($partID,$symb);
1.398 albertel 189: $result.='<td><b>Part: </b>'.$display_part.' <span class="LC_internal_info">'.
190: $resID.'</span></td>'.
1.375 albertel 191: '<td><b>Type: </b>'.$responsetype.'</td></tr>';
192: # '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>';
1.154 albertel 193: }
1.118 ng 194: }
195: $result.='</table>'."\n";
1.147 albertel 196: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 197: }
198:
1.148 albertel 199:
200: sub get_order {
201: my ($partid,$respid,$symb,$uname,$udom)=@_;
202: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
203: $url=&Apache::lonnet::clutter($url);
204: my $subresult=&Apache::lonnet::ssi($url,
205: ('grade_target' => 'analyze'),
206: ('grade_domain' => $udom),
207: ('grade_symb' => $symb),
208: ('grade_courseid' =>
1.257 albertel 209: $env{'request.course.id'}),
1.148 albertel 210: ('grade_username' => $uname));
1.149 albertel 211: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
1.148 albertel 212: my %analyze=&Apache::lonnet::str2hash($subresult);
213: return ($analyze{"$partid.$respid.shown"});
214: }
1.118 ng 215: #--- Clean response type for display
1.335 albertel 216: #--- Currently filters option/rank/radiobutton/match/essay/Task
217: # response types only.
1.118 ng 218: sub cleanRecord {
1.336 albertel 219: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
220: $uname,$udom) = @_;
1.398 albertel 221: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 222: if ($response =~ /^(option|rank)$/) {
223: my %answer=&Apache::lonnet::str2hash($answer);
224: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
225: my ($toprow,$bottomrow);
226: foreach my $foil (@$order) {
227: if ($grading{$foil} == 1) {
228: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
229: } else {
230: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
231: }
1.398 albertel 232: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 233: }
234: return '<blockquote><table border="1">'.
235: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
1.398 albertel 236: '<tr valign="top"><td>'.$grayFont.'Option ID</span></td>'.
1.148 albertel 237: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
238: } elsif ($response eq 'match') {
239: my %answer=&Apache::lonnet::str2hash($answer);
240: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
241: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
242: my ($toprow,$middlerow,$bottomrow);
243: foreach my $foil (@$order) {
244: my $item=shift(@items);
245: if ($grading{$foil} == 1) {
246: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 247: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 248: } else {
249: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 250: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 251: }
1.398 albertel 252: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 253: }
1.126 ng 254: return '<blockquote><table border="1">'.
1.148 albertel 255: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
1.398 albertel 256: '<tr valign="top"><td>'.$grayFont.'Item ID</span></td>'.
1.148 albertel 257: $middlerow.'</tr>'.
1.398 albertel 258: '<tr valign="top"><td>'.$grayFont.'Option ID</span></td>'.
1.148 albertel 259: $bottomrow.'</tr>'.'</table></blockquote>';
260: } elsif ($response eq 'radiobutton') {
261: my %answer=&Apache::lonnet::str2hash($answer);
262: my ($toprow,$bottomrow);
263: my $correct=($order->[0])+1;
264: for (my $i=1;$i<=$#$order;$i++) {
265: my $foil=$order->[$i];
266: if (exists($answer{$foil})) {
267: if ($i == $correct) {
268: $toprow.='<td><b>true</b></td>';
269: } else {
270: $toprow.='<td><i>true</i></td>';
271: }
272: } else {
273: $toprow.='<td>false</td>';
274: }
1.398 albertel 275: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 276: }
277: return '<blockquote><table border="1">'.
278: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
1.398 albertel 279: '<tr valign="top"><td>'.$grayFont.'Option ID</span></td>'.
1.148 albertel 280: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
281: } elsif ($response eq 'essay') {
1.257 albertel 282: if (! exists ($env{'form.'.$symb})) {
1.122 ng 283: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 284: $env{'course.'.$env{'request.course.id'}.'.domain'},
285: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 286:
1.257 albertel 287: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
288: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
289: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
290: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
291: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
292: $env{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
1.122 ng 293: }
1.166 albertel 294: $answer =~ s-\n-<br />-g;
295: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 296: } elsif ( $response eq 'organic') {
297: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
298: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
299: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
300: return $result;
1.335 albertel 301: } elsif ( $response eq 'Task') {
302: if ( $answer eq 'SUBMITTED') {
303: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 304: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 305: return $result;
306: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
307: my @matches = grep(/^\Q$version\E.*?\.instance$/,
308: keys(%{$record}));
309: return join('<br />',($version,@matches));
310:
311:
312: } else {
313: my $result =
314: '<p>'
315: .&mt('Overall result: [_1]',
316: $record->{$version."resource.$respid.$partid.status"})
317: .'</p>';
318:
319: $result .= '<ul>';
320: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
321: keys(%{$record}));
322: foreach my $grade (sort(@grade)) {
323: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
324: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
325: $dim, $record->{$grade}).
326: '</li>';
327: }
328: $result.='</ul>';
329: return $result;
330: }
331:
1.122 ng 332: }
1.118 ng 333: return $answer;
334: }
335:
336: #-- A couple of common js functions
337: sub commonJSfunctions {
338: my $request = shift;
339: $request->print(<<COMMONJSFUNCTIONS);
340: <script type="text/javascript" language="javascript">
341: function radioSelection(radioButton) {
342: var selection=null;
343: if (radioButton.length > 1) {
344: for (var i=0; i<radioButton.length; i++) {
345: if (radioButton[i].checked) {
346: return radioButton[i].value;
347: }
348: }
349: } else {
350: if (radioButton.checked) return radioButton.value;
351: }
352: return selection;
353: }
354:
355: function pullDownSelection(selectOne) {
356: var selection="";
357: if (selectOne.length > 1) {
358: for (var i=0; i<selectOne.length; i++) {
359: if (selectOne[i].selected) {
360: return selectOne[i].value;
361: }
362: }
363: } else {
1.138 albertel 364: // only one value it must be the selected one
365: return selectOne.value;
1.118 ng 366: }
367: }
368: </script>
369: COMMONJSFUNCTIONS
370: }
371:
1.44 ng 372: #--- Dumps the class list with usernames,list of sections,
373: #--- section, ids and fullnames for each user.
374: sub getclasslist {
1.76 ng 375: my ($getsec,$filterlist) = @_;
1.291 albertel 376: my @getsec;
377: if (!ref($getsec)) {
378: if ($getsec ne '' && $getsec ne 'all') {
379: @getsec=($getsec);
380: }
381: } else {
382: @getsec=@{$getsec};
383: }
384: if (grep(/^all$/,@getsec)) { undef(@getsec); }
385:
1.56 matthew 386: my $classlist=&Apache::loncoursedata::get_classlist();
1.49 albertel 387: # Bail out if we were unable to get the classlist
1.56 matthew 388: return if (! defined($classlist));
389: #
390: my %sections;
391: my %fullnames;
1.205 matthew 392: foreach my $student (keys(%$classlist)) {
393: my $end =
394: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
395: my $start =
396: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
397: my $id =
398: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
399: my $section =
400: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
401: my $fullname =
402: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
403: my $status =
404: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.76 ng 405: # filter students according to status selected
1.257 albertel 406: if ($filterlist && $env{'form.Status'} ne 'Any') {
407: if ($env{'form.Status'} ne $status) {
1.205 matthew 408: delete ($classlist->{$student});
1.76 ng 409: next;
410: }
411: }
1.205 matthew 412: $section = ($section ne '' ? $section : 'none');
1.106 albertel 413: if (&canview($section)) {
1.291 albertel 414: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 415: $sections{$section}++;
1.205 matthew 416: $fullnames{$student}=$fullname;
1.103 albertel 417: } else {
1.205 matthew 418: delete($classlist->{$student});
1.103 albertel 419: }
420: } else {
1.205 matthew 421: delete($classlist->{$student});
1.103 albertel 422: }
1.44 ng 423: }
424: my %seen = ();
1.56 matthew 425: my @sections = sort(keys(%sections));
426: return ($classlist,\@sections,\%fullnames);
1.44 ng 427: }
428:
1.103 albertel 429: sub canmodify {
430: my ($sec)=@_;
431: if ($perm{'mgr'}) {
432: if (!defined($perm{'mgr_section'})) {
433: # can modify whole class
434: return 1;
435: } else {
436: if ($sec eq $perm{'mgr_section'}) {
437: #can modify the requested section
438: return 1;
439: } else {
440: # can't modify the request section
441: return 0;
442: }
443: }
444: }
445: #can't modify
446: return 0;
447: }
448:
449: sub canview {
450: my ($sec)=@_;
451: if ($perm{'vgr'}) {
452: if (!defined($perm{'vgr_section'})) {
453: # can modify whole class
454: return 1;
455: } else {
456: if ($sec eq $perm{'vgr_section'}) {
457: #can modify the requested section
458: return 1;
459: } else {
460: # can't modify the request section
461: return 0;
462: }
463: }
464: }
465: #can't modify
466: return 0;
467: }
468:
1.44 ng 469: #--- Retrieve the grade status of a student for all the parts
470: sub student_gradeStatus {
1.324 albertel 471: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 472: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 473: my %partstatus = ();
474: foreach (@$partlist) {
1.128 ng 475: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 476: $status = 'nothing' if ($status eq '');
477: $partstatus{$_} = $status;
478: my $subkey = "resource.$_.submitted_by";
479: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
480: }
481: return %partstatus;
482: }
483:
1.45 ng 484: # hidden form and javascript that calls the form
485: # Use by verifyscript and viewgrades
486: # Shows a student's view of problem and submission
487: sub jscriptNform {
1.324 albertel 488: my ($symb) = @_;
1.45 ng 489: my $jscript='<script type="text/javascript" language="javascript">'."\n".
490: ' function viewOneStudent(user,domain) {'."\n".
491: ' document.onestudent.student.value = user;'."\n".
492: ' document.onestudent.userdom.value = domain;'."\n".
493: ' document.onestudent.submit();'."\n".
494: ' }'."\n".
495: '</script>'."\n";
496: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.399.2.2! albertel 497: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 498: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
499: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
500: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.45 ng 501: '<input type="hidden" name="command" value="submission" />'."\n".
502: '<input type="hidden" name="student" value="" />'."\n".
503: '<input type="hidden" name="userdom" value="" />'."\n".
504: '</form>'."\n";
505: return $jscript;
506: }
1.39 ng 507:
1.315 bowersj2 508: # Given the score (as a number [0-1] and the weight) what is the final
509: # point value? This function will round to the nearest tenth, third,
510: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 511: sub compute_points {
1.315 bowersj2 512: my ($score, $weight) = @_;
513:
514: my $tolerance = .00001;
515: my $points = $score * $weight;
516:
517: # Check for nearness to 1/x.
518: my $check_for_nearness = sub {
519: my ($factor) = @_;
520: my $num = ($points * $factor) + $tolerance;
521: my $floored_num = floor($num);
1.316 albertel 522: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 523: return $floored_num / $factor;
524: }
525: return $points;
526: };
527:
528: $points = $check_for_nearness->(10);
529: $points = $check_for_nearness->(3);
530: $points = $check_for_nearness->(4);
531:
532: return $points;
533: }
534:
1.44 ng 535: #------------------ End of general use routines --------------------
1.87 www 536:
537: #
538: # Find most similar essay
539: #
540:
541: sub most_similar {
542: my ($uname,$udom,$uessay)=@_;
543:
544: # ignore spaces and punctuation
545:
546: $uessay=~s/\W+/ /gs;
547:
1.282 www 548: # ignore empty submissions (occuring when only files are sent)
549:
550: unless ($uessay=~/\w+/) { return ''; }
551:
1.87 www 552: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 553: my $limit=0.6;
1.87 www 554: my $sname='';
555: my $sdom='';
556: my $scrsid='';
557: my $sessay='';
558: # go through all essays ...
559: foreach my $tkey (keys %oldessays) {
560: my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
561: # ... except the same student
1.88 www 562: if (($tname ne $uname) || ($tdom ne $udom)) {
1.87 www 563: my $tessay=$oldessays{$tkey};
564: $tessay=~s/\W+/ /gs;
565: # String similarity gives up if not even limit
1.88 www 566: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 567: # Found one
568: if ($tsimilar>$limit) {
569: $limit=$tsimilar;
570: $sname=$tname;
1.88 www 571: $sdom=$tdom;
1.87 www 572: $scrsid=$tcrsid;
573: $sessay=$oldessays{$tkey};
574: }
575: }
576: }
1.88 www 577: if ($limit>0.6) {
1.87 www 578: return ($sname,$sdom,$scrsid,$sessay,$limit);
579: } else {
580: return ('','','','',0);
581: }
582: }
583:
1.44 ng 584: #-------------------------------------------------------------------
585:
586: #------------------------------------ Receipt Verification Routines
1.45 ng 587: #
1.44 ng 588: #--- Check whether a receipt number is valid.---
589: sub verifyreceipt {
590: my $request = shift;
591:
1.257 albertel 592: my $courseid = $env{'request.course.id'};
1.184 www 593: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 594: $env{'form.receipt'};
1.44 ng 595: $receipt =~ s/[^\-\d]//g;
1.378 albertel 596: my ($symb) = &get_symb($request);
1.44 ng 597:
1.398 albertel 598: my $title.='<h3><span class="LC_info">Verifying Submission Receipt '.
599: $receipt.'</h3></span>'."\n".
600: '<h4><b>Resource: </b>'.$env{'form.probTitle'}.'</h4><br /><br />'."\n";
1.44 ng 601:
602: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 603: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 604:
605: my $receiptparts=0;
1.390 albertel 606: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
607: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 608: my $parts=['0'];
1.324 albertel 609: if ($receiptparts) { ($parts)=&response_type($symb); }
1.294 albertel 610: foreach (sort
611: {
612: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
613: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
614: }
615: return $a cmp $b;
616: } (keys(%$fullname))) {
1.44 ng 617: my ($uname,$udom)=split(/\:/);
1.177 albertel 618: foreach my $part (@$parts) {
619: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
620: $contents.='<tr bgcolor="#ffffe6"><td> '."\n".
621: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
622: '\')"; TARGET=_self>'.$$fullname{$_}.'</a> </td>'."\n".
623: '<td> '.$uname.' </td>'.
624: '<td> '.$udom.' </td>';
625: if ($receiptparts) {
626: $contents.='<td> '.$part.' </td>';
627: }
628: $contents.='</tr>'."\n";
629:
630: $matches++;
631: }
1.44 ng 632: }
633: }
634: if ($matches == 0) {
635: $string = $title.'No match found for the above receipt.';
636: } else {
1.324 albertel 637: $string = &jscriptNform($symb).$title.
1.44 ng 638: 'The above receipt matches the following student'.
639: ($matches <= 1 ? '.' : 's.')."\n".
640: '<table border="0"><tr><td bgcolor="#777777">'."\n".
641: '<table border="0"><tr bgcolor="#e6ffff">'."\n".
642: '<td><b> Fullname </b></td>'."\n".
643: '<td><b> Username </b></td>'."\n".
1.177 albertel 644: '<td><b> Domain </b></td>';
645: if ($receiptparts) {
646: $string.='<td> Problem Part </td>';
647: }
648: $string.='</tr>'."\n".$contents.
1.44 ng 649: '</table></td></tr></table>'."\n";
650: }
1.324 albertel 651: return $string.&show_grading_menu_form($symb);
1.44 ng 652: }
653:
654: #--- This is called by a number of programs.
655: #--- Called from the Grading Menu - View/Grade an individual student
656: #--- Also called directly when one clicks on the subm button
657: # on the problem page.
1.30 ng 658: sub listStudents {
1.41 ng 659: my ($request) = shift;
1.49 albertel 660:
1.324 albertel 661: my ($symb) = &get_symb($request);
1.257 albertel 662: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
663: my $cnum = $env{"course.$env{'request.course.id'}.num"};
664: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
665: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
666:
667: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
668: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
669: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 670:
1.398 albertel 671: my $result='<h3><span class="LC_info"> '.$viewgrade.
672: ' Submissions for a Student or a Group of Students</span></h3>';
1.118 ng 673:
1.324 albertel 674: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 675:
1.45 ng 676: $request->print(<<LISTJAVASCRIPT);
677: <script type="text/javascript" language="javascript">
1.110 ng 678: function checkSelect(checkBox) {
679: var ctr=0;
680: var sense="";
681: if (checkBox.length > 1) {
682: for (var i=0; i<checkBox.length; i++) {
683: if (checkBox[i].checked) {
684: ctr++;
685: }
686: }
687: sense = "a student or group of students";
688: } else {
689: if (checkBox.checked) {
690: ctr = 1;
691: }
692: sense = "the student";
693: }
694: if (ctr == 0) {
1.126 ng 695: alert("Please select "+sense+" before clicking on the Next button.");
1.110 ng 696: return false;
697: }
698: document.gradesub.submit();
699: }
700:
701: function reLoadList(formname) {
1.112 ng 702: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 703: formname.command.value = 'submission';
704: formname.submit();
705: }
1.45 ng 706: </script>
707: LISTJAVASCRIPT
708:
1.118 ng 709: &commonJSfunctions($request);
1.41 ng 710: $request->print($result);
1.39 ng 711:
1.257 albertel 712: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
1.119 ng 713: my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
1.154 albertel 714: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
715: "\n".$table.
1.267 albertel 716: ' <b>View Problem Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
717: '<label><input type="radio" name="vProb" value="yes" /> one student </label>'."\n".
718: '<label><input type="radio" name="vProb" value="all" /> all students </label><br />'."\n".
719: ' <b>View Answer: </b><label><input type="radio" name="vAns" value="no" /> no </label>'."\n".
720: '<label><input type="radio" name="vAns" value="yes" /> one student </label>'."\n".
721: '<label><input type="radio" name="vAns" value="all" checked="on" /> all students </label><br />'."\n".
1.49 albertel 722: ' <b>Submissions: </b>'."\n";
1.257 albertel 723: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.267 albertel 724: $gradeTable.='<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> essay part only </label>'."\n";
1.49 albertel 725: }
1.110 ng 726:
1.257 albertel 727: my $saveStatus = $env{'form.Status'} eq '' ? 'Active' : $env{'form.Status'};
728: $env{'form.Status'} = $saveStatus;
1.110 ng 729:
1.267 albertel 730: $gradeTable.='<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only </label>'."\n".
731: '<label><input type="radio" name="lastSub" value="last" /> last submission & parts info </label>'."\n".
732: '<label><input type="radio" name="lastSub" value="datesub" /> by dates and submissions </label>'."\n".
1.348 bowersj2 733: '<label><input type="radio" name="lastSub" value="all" /> all details</label><br />'."\n".
734: ' <b>Grading Increments:</b> <select name="increment">'.
735: '<option value="1">Whole Points</option>'.
736: '<option value=".5">Half Points</option>'.
1.349 albertel 737: '<option value=".25">Quarter Points</option>'.
738: '<option value=".1">Tenths of a Point</option>'.
1.348 bowersj2 739: '</select>'.
740:
1.45 ng 741: '<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
742: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 743: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
744: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
745: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
746: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.399.2.2! albertel 747: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 748: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
749:
1.257 albertel 750: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
751: $gradeTable.='<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n";
1.124 ng 752: } else {
753: $gradeTable.='<b>Student Status:</b> '.
754: &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'<br />';
755: }
1.112 ng 756:
1.126 ng 757: $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
758: 'next to the student\'s name(s). Then click on the Next button.<br />'."\n".
1.110 ng 759: '<input type="hidden" name="command" value="processGroup" />'."\n";
1.249 albertel 760:
761: # checkall buttons
762: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 763: $gradeTable.='<input type="button" '."\n".
1.45 ng 764: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.249 albertel 765: 'value="Next->" /> <br />'."\n";
766: $gradeTable.=&check_buttons();
1.267 albertel 767: $gradeTable.='<label><input type="checkbox" name="checkPlag" checked="on" />Check For Plagiarism</label>';
1.249 albertel 768: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1');
1.45 ng 769: $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.110 ng 770: '<table border="0"><tr bgcolor="#e6ffff">';
771: my $loop = 0;
772: while ($loop < 2) {
1.126 ng 773: $gradeTable.='<td><b> No.</b> </td><td><b> Select </b></td>'.
1.250 albertel 774: '<td>'.&nameUserString('header').' Section/Group</td>';
1.301 albertel 775: if ($env{'form.showgrading'} eq 'yes'
776: && $submitonly ne 'queued'
777: && $submitonly ne 'all') {
1.110 ng 778: foreach (sort(@$partlist)) {
1.324 albertel 779: my $display_part=&get_display_part((split(/_/))[0],$symb);
1.207 albertel 780: $gradeTable.='<td><b> Part: '.$display_part.
781: ' Status </b></td>';
1.110 ng 782: }
1.301 albertel 783: } elsif ($submitonly eq 'queued') {
784: $gradeTable.='<td><b> '.&mt('Queue Status').' </b></td>';
1.110 ng 785: }
786: $loop++;
1.126 ng 787: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 788: }
1.45 ng 789: $gradeTable.='</tr>'."\n";
1.41 ng 790:
1.45 ng 791: my $ctr = 0;
1.294 albertel 792: foreach my $student (sort
793: {
794: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
795: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
796: }
797: return $a cmp $b;
798: }
799: (keys(%$fullname))) {
1.41 ng 800: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 801:
1.110 ng 802: my %status = ();
1.301 albertel 803:
804: if ($submitonly eq 'queued') {
805: my %queue_status =
806: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
807: $udom,$uname);
808: next if (!defined($queue_status{'gradingqueue'}));
809: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
810: }
811:
812: if ($env{'form.showgrading'} eq 'yes'
813: && $submitonly ne 'queued'
814: && $submitonly ne 'all') {
1.324 albertel 815: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 816: my $submitted = 0;
1.164 albertel 817: my $graded = 0;
1.248 albertel 818: my $incorrect = 0;
1.110 ng 819: foreach (keys(%status)) {
1.145 albertel 820: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 821: $graded = 1 if ($status{$_} =~ /^ungraded/);
822: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
823:
1.110 ng 824: my ($foo,$partid,$foo1) = split(/\./,$_);
825: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 826: $submitted = 0;
1.150 albertel 827: my ($part)=split(/\./,$partid);
1.110 ng 828: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 829: $student.':'.$part.':submitted_by" value="'.
1.110 ng 830: $status{'resource.'.$partid.'.submitted_by'}.'" />';
831: }
1.41 ng 832: }
1.248 albertel 833:
1.156 albertel 834: next if (!$submitted && ($submitonly eq 'yes' ||
835: $submitonly eq 'incorrect' ||
836: $submitonly eq 'graded'));
1.248 albertel 837: next if (!$graded && ($submitonly eq 'graded'));
838: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 839: }
1.34 ng 840:
1.45 ng 841: $ctr++;
1.249 albertel 842: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
843:
1.104 albertel 844: if ( $perm{'vgr'} eq 'F' ) {
1.110 ng 845: $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
1.126 ng 846: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.249 albertel 847: '<td align="center"><label><input type=checkbox name="stuinfo" value="'.
848: $student.':'.$$fullname{$student}.':::SECTION'.$section.
849: ') " /> </label></td>'."\n".'<td>'.
850: &nameUserString(undef,$$fullname{$student},$uname,$udom).
851: ' '.$section.'</td>'."\n";
1.110 ng 852:
1.257 albertel 853: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.110 ng 854: foreach (sort keys(%status)) {
855: next if (/^resource.*?submitted_by$/);
1.276 albertel 856: $gradeTable.='<td align="center"> '.$status{$_}.' </td>'."\n";
1.110 ng 857: }
1.41 ng 858: }
1.126 ng 859: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.110 ng 860: $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
1.41 ng 861: }
862: }
1.110 ng 863: if ($ctr%2 ==1) {
1.126 ng 864: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 865: if ($env{'form.showgrading'} eq 'yes'
866: && $submitonly ne 'queued'
867: && $submitonly ne 'all') {
1.110 ng 868: foreach (@$partlist) {
869: $gradeTable.='<td> </td>';
870: }
1.301 albertel 871: } elsif ($submitonly eq 'queued') {
872: $gradeTable.='<td> </td>';
1.110 ng 873: }
874: $gradeTable.='</tr>';
875: }
876:
1.249 albertel 877: $gradeTable.='</table></td></tr></table>'."\n".
1.45 ng 878: '<input type="button" '.
879: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.126 ng 880: 'value="Next->" /></form>'."\n";
1.45 ng 881: if ($ctr == 0) {
1.96 albertel 882: my $num_students=(scalar(keys(%$fullname)));
883: if ($num_students eq 0) {
1.398 albertel 884: $gradeTable='<br /> <span class="LC_warning">There are no students currently enrolled.</span>';
1.96 albertel 885: } else {
1.171 albertel 886: my $submissions='submissions';
887: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
888: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 889: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 890: $gradeTable='<br /> <span class="LC_warning">'.
1.171 albertel 891: 'No '.$submissions.' found for this resource for any students. ('.$num_students.
1.398 albertel 892: ' students checked for '.$submissions.')</span><br />';
1.96 albertel 893: }
1.46 ng 894: } elsif ($ctr == 1) {
895: $gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45 ng 896: }
1.324 albertel 897: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 898: $request->print($gradeTable);
1.44 ng 899: return '';
1.10 ng 900: }
901:
1.44 ng 902: #---- Called from the listStudents routine
1.249 albertel 903:
904: sub check_script {
905: my ($form, $type)=@_;
906: my $chkallscript='<script type="text/javascript">
907: function checkall() {
908: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
909: ele = document.forms.'.$form.'.elements[i];
910: if (ele.name == "'.$type.'") {
911: document.forms.'.$form.'.elements[i].checked=true;
912: }
913: }
914: }
915:
916: function checksec() {
917: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
918: ele = document.forms.'.$form.'.elements[i];
919: string = document.forms.'.$form.'.chksec.value;
920: if
921: (ele.value.indexOf(":::SECTION"+string)>0) {
922: document.forms.'.$form.'.elements[i].checked=true;
923: }
924: }
925: }
926:
927:
928: function uncheckall() {
929: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
930: ele = document.forms.'.$form.'.elements[i];
931: if (ele.name == "'.$type.'") {
932: document.forms.'.$form.'.elements[i].checked=false;
933: }
934: }
935: }
936:
937: </script>'."\n";
938: return $chkallscript;
939: }
940:
941: sub check_buttons {
942: my $buttons.='<input type="button" onclick="checkall()" value="Check All" />';
943: $buttons.='<input type="button" onclick="uncheckall()" value="Uncheck All" /> ';
944: $buttons.='<input type="button" onclick="checksec()" value="Check Section/Group" />';
945: $buttons.='<input type="text" size="5" name="chksec" /> ';
946: return $buttons;
947: }
948:
1.44 ng 949: # Displays the submissions for one student or a group of students
1.34 ng 950: sub processGroup {
1.41 ng 951: my ($request) = shift;
952: my $ctr = 0;
1.155 albertel 953: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 954: my $total = scalar(@stuchecked)-1;
1.45 ng 955:
1.396 banghart 956: foreach my $student (@stuchecked) {
957: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 958: $env{'form.student'} = $uname;
959: $env{'form.userdom'} = $udom;
960: $env{'form.fullname'} = $fullname;
1.41 ng 961: &submission($request,$ctr,$total);
962: $ctr++;
963: }
964: return '';
1.35 ng 965: }
1.34 ng 966:
1.44 ng 967: #------------------------------------------------------------------------------------
968: #
969: #-------------------------- Next few routines handles grading by student, essentially
970: # handles essay response type problem/part
971: #
972: #--- Javascript to handle the submission page functionality ---
973: sub sub_page_js {
974: my $request = shift;
975: $request->print(<<SUBJAVASCRIPT);
976: <script type="text/javascript" language="javascript">
1.71 ng 977: function updateRadio(formname,id,weight) {
1.125 ng 978: var gradeBox = formname["GD_BOX"+id];
979: var radioButton = formname["RADVAL"+id];
980: var oldpts = formname["oldpts"+id].value;
1.72 ng 981: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 982: gradeBox.value = pts;
983: var resetbox = false;
984: if (isNaN(pts) || pts < 0) {
985: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
986: for (var i=0; i<radioButton.length; i++) {
987: if (radioButton[i].checked) {
988: gradeBox.value = i;
989: resetbox = true;
990: }
991: }
992: if (!resetbox) {
993: formtextbox.value = "";
994: }
995: return;
1.44 ng 996: }
1.71 ng 997:
998: if (pts > weight) {
999: var resp = confirm("You entered a value ("+pts+
1000: ") greater than the weight for the part. Accept?");
1001: if (resp == false) {
1.125 ng 1002: gradeBox.value = oldpts;
1.71 ng 1003: return;
1004: }
1.44 ng 1005: }
1.13 albertel 1006:
1.71 ng 1007: for (var i=0; i<radioButton.length; i++) {
1008: radioButton[i].checked=false;
1009: if (pts == i && pts != "") {
1010: radioButton[i].checked=true;
1011: }
1012: }
1013: updateSelect(formname,id);
1.125 ng 1014: formname["stores"+id].value = "0";
1.41 ng 1015: }
1.5 albertel 1016:
1.72 ng 1017: function writeBox(formname,id,pts) {
1.125 ng 1018: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1019: if (checkSolved(formname,id) == 'update') {
1020: gradeBox.value = pts;
1021: } else {
1.125 ng 1022: var oldpts = formname["oldpts"+id].value;
1.72 ng 1023: gradeBox.value = oldpts;
1.125 ng 1024: var radioButton = formname["RADVAL"+id];
1.71 ng 1025: for (var i=0; i<radioButton.length; i++) {
1026: radioButton[i].checked=false;
1.72 ng 1027: if (i == oldpts) {
1.71 ng 1028: radioButton[i].checked=true;
1029: }
1030: }
1.41 ng 1031: }
1.125 ng 1032: formname["stores"+id].value = "0";
1.71 ng 1033: updateSelect(formname,id);
1034: return;
1.41 ng 1035: }
1.44 ng 1036:
1.71 ng 1037: function clearRadBox(formname,id) {
1038: if (checkSolved(formname,id) == 'noupdate') {
1039: updateSelect(formname,id);
1040: return;
1041: }
1.125 ng 1042: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1043: for (var i=0; i<gradeSelect.length; i++) {
1044: if (gradeSelect[i].selected) {
1045: var selectx=i;
1046: }
1047: }
1.125 ng 1048: var stores = formname["stores"+id];
1.71 ng 1049: if (selectx == stores.value) { return };
1.125 ng 1050: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1051: gradeBox.value = "";
1.125 ng 1052: var radioButton = formname["RADVAL"+id];
1.71 ng 1053: for (var i=0; i<radioButton.length; i++) {
1054: radioButton[i].checked=false;
1055: }
1056: stores.value = selectx;
1057: }
1.5 albertel 1058:
1.71 ng 1059: function checkSolved(formname,id) {
1.125 ng 1060: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1061: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1062: if (!reply) {return "noupdate";}
1.120 ng 1063: formname.overRideScore.value = 'yes';
1.41 ng 1064: }
1.71 ng 1065: return "update";
1.13 albertel 1066: }
1.71 ng 1067:
1068: function updateSelect(formname,id) {
1.125 ng 1069: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1070: return;
1.41 ng 1071: }
1.33 ng 1072:
1.121 ng 1073: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1074: function checksubmit(formname,val,total,parttot) {
1.121 ng 1075: formname.gradeOpt.value = val;
1.71 ng 1076: if (val == "Save & Next") {
1077: for (i=0;i<=total;i++) {
1078: for (j=0;j<parttot;j++) {
1.125 ng 1079: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1080: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1081: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1082: if (points == "") {
1.125 ng 1083: var name = formname["name"+i].value;
1.129 ng 1084: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1085: var resp = confirm("You did not assign a score for "+studentID+
1086: ", part "+partid+". Continue?");
1.71 ng 1087: if (resp == false) {
1.125 ng 1088: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1089: return false;
1090: }
1091: }
1092: }
1093:
1094: }
1095: }
1096:
1097: }
1.121 ng 1098: if (val == "Grade Student") {
1099: formname.showgrading.value = "yes";
1100: if (formname.Status.value == "") {
1101: formname.Status.value = "Active";
1102: }
1103: formname.studentNo.value = total;
1104: }
1.120 ng 1105: formname.submit();
1106: }
1107:
1.71 ng 1108: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1109: function checkSubmitPage(formname,total) {
1110: noscore = new Array(100);
1111: var ptr = 0;
1112: for (i=1;i<total;i++) {
1.125 ng 1113: var partid = formname["q_"+i].value;
1.127 ng 1114: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1115: var points = formname["GD_BOX"+i+"_"+partid].value;
1116: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1117: if (points == "" && status != "correct_by_student") {
1118: noscore[ptr] = i;
1119: ptr++;
1120: }
1121: }
1122: }
1123: if (ptr != 0) {
1124: var sense = ptr == 1 ? ": " : "s: ";
1125: var prolist = "";
1126: if (ptr == 1) {
1127: prolist = noscore[0];
1128: } else {
1129: var i = 0;
1130: while (i < ptr-1) {
1131: prolist += noscore[i]+", ";
1132: i++;
1133: }
1134: prolist += "and "+noscore[i];
1135: }
1136: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1137: if (resp == false) {
1138: return false;
1139: }
1140: }
1.45 ng 1141:
1.71 ng 1142: formname.submit();
1143: }
1144: </script>
1145: SUBJAVASCRIPT
1146: }
1.45 ng 1147:
1.71 ng 1148: #--- javascript for essay type problem --
1149: sub sub_page_kw_js {
1150: my $request = shift;
1.80 ng 1151: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1152: &commonJSfunctions($request);
1.350 albertel 1153:
1.351 albertel 1154: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1155: <script text="text/javascript">
1156: function checkInput() {
1157: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1158: var nmsg = opener.document.SCORE.savemsgN.value;
1159: var usrctr = document.msgcenter.usrctr.value;
1160: var newval = opener.document.SCORE["newmsg"+usrctr];
1161: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1162:
1163: var msgchk = "";
1164: if (document.msgcenter.subchk.checked) {
1165: msgchk = "msgsub,";
1166: }
1167: var includemsg = 0;
1168: for (var i=1; i<=nmsg; i++) {
1169: var opnmsg = opener.document.SCORE["savemsg"+i];
1170: var frmmsg = document.msgcenter["msg"+i];
1171: opnmsg.value = opener.checkEntities(frmmsg.value);
1172: var showflg = opener.document.SCORE["shownOnce"+i];
1173: showflg.value = "1";
1174: var chkbox = document.msgcenter["msgn"+i];
1175: if (chkbox.checked) {
1176: msgchk += "savemsg"+i+",";
1177: includemsg = 1;
1178: }
1179: }
1180: if (document.msgcenter.newmsgchk.checked) {
1181: msgchk += "newmsg"+usrctr;
1182: includemsg = 1;
1183: }
1184: imgformname = opener.document.SCORE["mailicon"+usrctr];
1185: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1186: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1187: includemsg.value = msgchk;
1188:
1189: self.close()
1190:
1191: }
1192: </script>
1193: INNERJS
1194:
1.351 albertel 1195: my $inner_js_highlight_central=<<INNERJS;
1196: <script type="text/javascript">
1197: function updateChoice(flag) {
1198: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1199: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1200: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1201: opener.document.SCORE.refresh.value = "on";
1202: if (opener.document.SCORE.keywords.value!=""){
1203: opener.document.SCORE.submit();
1204: }
1205: self.close()
1206: }
1207: </script>
1208: INNERJS
1209:
1210: my $start_page_msg_central =
1211: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1212: {'js_ready' => 1,
1213: 'only_body' => 1,
1214: 'bgcolor' =>'#FFFFFF',});
1215: my $end_page_msg_central =
1216: &Apache::loncommon::end_page({'js_ready' => 1});
1217:
1218:
1219: my $start_page_highlight_central =
1220: &Apache::loncommon::start_page('Highlight Central',
1221: $inner_js_highlight_central,
1.350 albertel 1222: {'js_ready' => 1,
1223: 'only_body' => 1,
1224: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1225: my $end_page_highlight_central =
1.350 albertel 1226: &Apache::loncommon::end_page({'js_ready' => 1});
1227:
1.219 www 1228: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1229: $docopen=~s/^document\.//;
1.71 ng 1230: $request->print(<<SUBJAVASCRIPT);
1231: <script type="text/javascript" language="javascript">
1.45 ng 1232:
1.44 ng 1233: //===================== Show list of keywords ====================
1.122 ng 1234: function keywords(formname) {
1235: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1236: if (nret==null) return;
1.122 ng 1237: formname.keywords.value = nret;
1.44 ng 1238:
1.122 ng 1239: if (formname.keywords.value != "") {
1.128 ng 1240: formname.refresh.value = "on";
1.122 ng 1241: formname.submit();
1.44 ng 1242: }
1243: return;
1244: }
1245:
1246: //===================== Script to view submitted by ==================
1247: function viewSubmitter(submitter) {
1248: document.SCORE.refresh.value = "on";
1249: document.SCORE.NCT.value = "1";
1250: document.SCORE.unamedom0.value = submitter;
1251: document.SCORE.submit();
1252: return;
1253: }
1254:
1255: //===================== Script to add keyword(s) ==================
1256: function getSel() {
1257: if (document.getSelection) txt = document.getSelection();
1258: else if (document.selection) txt = document.selection.createRange().text;
1259: else return;
1260: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1261: if (cleantxt=="") {
1.46 ng 1262: alert("Please select a word or group of words from document and then click this link.");
1.44 ng 1263: return;
1264: }
1265: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1266: if (nret==null) return;
1.127 ng 1267: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1268: if (document.SCORE.keywords.value != "") {
1.127 ng 1269: document.SCORE.refresh.value = "on";
1.44 ng 1270: document.SCORE.submit();
1271: }
1272: return;
1273: }
1274:
1275: //====================== Script for composing message ==============
1.80 ng 1276: // preload images
1277: img1 = new Image();
1278: img1.src = "$iconpath/mailbkgrd.gif";
1279: img2 = new Image();
1280: img2.src = "$iconpath/mailto.gif";
1281:
1.44 ng 1282: function msgCenter(msgform,usrctr,fullname) {
1283: var Nmsg = msgform.savemsgN.value;
1284: savedMsgHeader(Nmsg,usrctr,fullname);
1285: var subject = msgform.msgsub.value;
1.127 ng 1286: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1287: re = /msgsub/;
1288: var shwsel = "";
1289: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1290: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1291: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1292: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1293: var testmsg = "savemsg"+i+",";
1294: re = new RegExp(testmsg,"g");
1.44 ng 1295: shwsel = "";
1296: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1297: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1298: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1299: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1300: //any < is already converted to <, etc. However, only once!!
1.44 ng 1301: }
1.125 ng 1302: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1303: shwsel = "";
1304: re = /newmsg/;
1305: if (re.test(msgchk)) { shwsel = "checked" }
1306: newMsg(newmsg,shwsel);
1307: msgTail();
1308: return;
1309: }
1310:
1.123 ng 1311: function checkEntities(strx) {
1312: if (strx.length == 0) return strx;
1313: var orgStr = ["&", "<", ">", '"'];
1314: var newStr = ["&", "<", ">", """];
1315: var counter = 0;
1316: while (counter < 4) {
1317: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1318: counter++;
1319: }
1320: return strx;
1321: }
1322:
1323: function strReplace(strx, orgStr, newStr) {
1324: return strx.split(orgStr).join(newStr);
1325: }
1326:
1.44 ng 1327: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1328: var height = 70*Nmsg+250;
1.44 ng 1329: var scrollbar = "no";
1330: if (height > 600) {
1331: height = 600;
1332: scrollbar = "yes";
1333: }
1.118 ng 1334: var xpos = (screen.width-600)/2;
1335: xpos = (xpos < 0) ? '0' : xpos;
1336: var ypos = (screen.height-height)/2-30;
1337: ypos = (ypos < 0) ? '0' : ypos;
1338:
1.206 albertel 1339: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1340: pWin.focus();
1341: pDoc = pWin.document;
1.219 www 1342: pDoc.$docopen;
1.351 albertel 1343: pDoc.write('$start_page_msg_central');
1.76 ng 1344:
1345: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1346: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.398 albertel 1347: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"</span></h3><br /><br />");
1.76 ng 1348:
1349: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1350: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1351: pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44 ng 1352: }
1353: function displaySubject(msg,shwsel) {
1.76 ng 1354: pDoc = pWin.document;
1355: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1356: pDoc.write("<td>Subject</td>");
1357: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1358: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44 ng 1359: }
1360:
1.72 ng 1361: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1362: pDoc = pWin.document;
1363: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1364: pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
1365: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1366: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44 ng 1367: }
1368:
1369: function newMsg(newmsg,shwsel) {
1.76 ng 1370: pDoc = pWin.document;
1371: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1372: pDoc.write("<td align=\\"center\\">New</td>");
1373: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1374: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44 ng 1375: }
1376:
1377: function msgTail() {
1.76 ng 1378: pDoc = pWin.document;
1379: pDoc.write("</table>");
1380: pDoc.write("</td></tr></table> ");
1381: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1.326 albertel 1382: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.76 ng 1383: pDoc.write("</form>");
1.351 albertel 1384: pDoc.write('$end_page_msg_central');
1.128 ng 1385: pDoc.close();
1.44 ng 1386: }
1387:
1388: //====================== Script for keyword highlight options ==============
1389: function kwhighlight() {
1390: var kwclr = document.SCORE.kwclr.value;
1391: var kwsize = document.SCORE.kwsize.value;
1392: var kwstyle = document.SCORE.kwstyle.value;
1393: var redsel = "";
1394: var grnsel = "";
1395: var blusel = "";
1396: if (kwclr=="red") {var redsel="checked"};
1397: if (kwclr=="green") {var grnsel="checked"};
1398: if (kwclr=="blue") {var blusel="checked"};
1399: var sznsel = "";
1400: var sz1sel = "";
1401: var sz2sel = "";
1402: if (kwsize=="0") {var sznsel="checked"};
1403: if (kwsize=="+1") {var sz1sel="checked"};
1404: if (kwsize=="+2") {var sz2sel="checked"};
1405: var synsel = "";
1406: var syisel = "";
1407: var sybsel = "";
1408: if (kwstyle=="") {var synsel="checked"};
1409: if (kwstyle=="<i>") {var syisel="checked"};
1410: if (kwstyle=="<b>") {var sybsel="checked"};
1411: highlightCentral();
1412: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1413: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1414: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1415: highlightend();
1416: return;
1417: }
1418:
1419: function highlightCentral() {
1.76 ng 1420: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1421: var xpos = (screen.width-400)/2;
1422: xpos = (xpos < 0) ? '0' : xpos;
1423: var ypos = (screen.height-330)/2-30;
1424: ypos = (ypos < 0) ? '0' : ypos;
1425:
1.206 albertel 1426: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1427: hwdWin.focus();
1428: var hDoc = hwdWin.document;
1.219 www 1429: hDoc.$docopen;
1.351 albertel 1430: hDoc.write('$start_page_highlight_central');
1.76 ng 1431: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.398 albertel 1432: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options</span></h3><br /><br />");
1.76 ng 1433:
1434: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1435: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1436: hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44 ng 1437: }
1438:
1439: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1440: var hDoc = hwdWin.document;
1441: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1442: hDoc.write("<td align=\\"left\\">");
1443: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
1444: hDoc.write("<td align=\\"left\\">");
1445: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
1446: hDoc.write("<td align=\\"left\\">");
1447: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
1448: hDoc.write("</tr>");
1.44 ng 1449: }
1450:
1451: function highlightend() {
1.76 ng 1452: var hDoc = hwdWin.document;
1453: hDoc.write("</table>");
1454: hDoc.write("</td></tr></table> ");
1455: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1.326 albertel 1456: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.76 ng 1457: hDoc.write("</form>");
1.351 albertel 1458: hDoc.write('$end_page_highlight_central');
1.128 ng 1459: hDoc.close();
1.44 ng 1460: }
1461:
1462: </script>
1463: SUBJAVASCRIPT
1464: }
1465:
1.349 albertel 1466: sub get_increment {
1.348 bowersj2 1467: my $increment = $env{'form.increment'};
1468: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1469: $increment != .1) {
1470: $increment = 1;
1471: }
1472: return $increment;
1473: }
1474:
1.71 ng 1475: #--- displays the grading box, used in essay type problem and grading by page/sequence
1476: sub gradeBox {
1.322 albertel 1477: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1478: my $checkIcon = '<img alt="'.&mt('Check Mark').
1479: '" src="'.$request->dir_config('lonIconsURL').
1.71 ng 1480: '/check.gif" height="16" border="0" />';
1481: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1482: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
1.398 albertel 1483: '<span class="LC_info">problem weight assigned by computer</span>');
1.71 ng 1484: $wgt = ($wgt > 0 ? $wgt : '1');
1485: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1486: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1487: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.324 albertel 1488: my $display_part=&get_display_part($partid,$symb);
1.270 albertel 1489: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1490: [$partid]);
1491: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1492: if ($last_resets{$partid}) {
1493: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1494: }
1.71 ng 1495: $result.='<table border="0"><tr><td>'.
1.207 albertel 1496: '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
1.71 ng 1497: my $ctr = 0;
1.348 bowersj2 1498: my $thisweight = 0;
1.349 albertel 1499: my $increment = &get_increment();
1.71 ng 1500: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1501: while ($thisweight<=$wgt) {
1.381 albertel 1502: $result.= '<td><span style="white-space: nowrap;"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1503: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1504: $thisweight.')" value="'.$thisweight.'" '.
1.381 albertel 1505: ($score eq $thisweight ? 'checked':'').' /> '.$thisweight."</label></span></td>\n";
1.71 ng 1506: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1507: $thisweight += $increment;
1.71 ng 1508: $ctr++;
1509: }
1510: $result.='</tr></table>';
1511: $result.='</td><td> <b>or</b> </td>'."\n";
1512: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1513: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1514: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1515: $wgt.')" /></td>'."\n";
1516: $result.='<td>/'.$wgt.' '.$wgtmsg.
1517: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1518: ' </td><td>'."\n";
1519: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1520: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1521: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.384 albertel 1522: $result.='<option></option>'.
1.125 ng 1523: '<option selected="on">excused</option>';
1.71 ng 1524: } else {
1.384 albertel 1525: $result.='<option selected="on"></option>'.
1.125 ng 1526: '<option>excused</option>';
1.71 ng 1527: }
1.125 ng 1528: $result.='<option>reset status</option></select>'."\n";
1.381 albertel 1529: $result.=" \n";
1.71 ng 1530: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1531: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1532: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1533: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1534: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1535: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1536: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1537: $aggtries.'" />'."\n";
1.71 ng 1538: $result.='</td></tr></table>'."\n";
1.323 banghart 1539: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
1.318 banghart 1540: return $result;
1541: }
1.322 albertel 1542:
1543: sub handback_box {
1.323 banghart 1544: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
1.324 albertel 1545: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.323 banghart 1546: my (@respids);
1.375 albertel 1547: my @part_response_id = &flatten_responseType($responseType);
1548: foreach my $part_response_id (@part_response_id) {
1549: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1550: if ($part eq $partid) {
1.375 albertel 1551: push(@respids,$resp);
1.323 banghart 1552: }
1553: }
1.318 banghart 1554: my $result;
1.323 banghart 1555: foreach my $respid (@respids) {
1.322 albertel 1556: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1557: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1558: next if (!@$files);
1559: my $file_counter = 1;
1.313 banghart 1560: foreach my $file (@$files) {
1.368 banghart 1561: if ($file =~ /\/portfolio\//) {
1562: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1563: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1564: $file_disp = "$name.$ext";
1565: $file = $file_path.$file_disp;
1566: $result.=&mt('Return commented version of [_1] to student.',
1567: '<span class="LC_filename">'.$file_disp.'</span>');
1568: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1569: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.369 banghart 1570: $result.='(File will be uploaded when you click on Save & Next below.)<br />';
1.368 banghart 1571: $file_counter++;
1572: }
1.322 albertel 1573: }
1.313 banghart 1574: }
1.318 banghart 1575: return $result;
1.71 ng 1576: }
1.44 ng 1577:
1.58 albertel 1578: sub show_problem {
1.382 albertel 1579: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1580: my $rendered;
1.382 albertel 1581: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1582: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1583: if ($mode eq 'both' or $mode eq 'text') {
1584: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1585: $env{'request.course.id'},
1586: undef,\%form);
1.144 albertel 1587: }
1.58 albertel 1588: if ($removeform) {
1589: $rendered=~s|<form(.*?)>||g;
1590: $rendered=~s|</form>||g;
1.374 albertel 1591: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1592: }
1.144 albertel 1593: my $companswer;
1594: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1595: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1596: $companswer=
1597: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1598: $env{'request.course.id'},
1599: %form);
1.144 albertel 1600: }
1.58 albertel 1601: if ($removeform) {
1602: $companswer=~s|<form(.*?)>||g;
1603: $companswer=~s|</form>||g;
1.144 albertel 1604: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1605: }
1606: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 1607: $result.='<table border="0" width="100%">';
1.144 albertel 1608: if ($viewon) {
1609: $result.='<tr><td bgcolor="#e6ffff"><b> ';
1610: if ($mode eq 'both' or $mode eq 'text') {
1611: $result.='View of the problem - ';
1612: } else {
1613: $result.='Correct answer: ';
1614: }
1.257 albertel 1615: $result.=$env{'form.fullname'}.'</b></td></tr>';
1.144 albertel 1616: }
1617: if ($mode eq 'both') {
1618: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1619: $result.='<b>Correct answer:</b><br />'.$companswer;
1620: } elsif ($mode eq 'text') {
1621: $result.='<tr><td bgcolor="#ffffff">'.$rendered;
1622: } elsif ($mode eq 'answer') {
1623: $result.='<tr><td bgcolor="#ffffff">'.$companswer;
1624: }
1.58 albertel 1625: $result.='</td></tr></table>';
1626: $result.='</td></tr></table><br />';
1.71 ng 1627: return $result;
1.58 albertel 1628: }
1.397 albertel 1629:
1.396 banghart 1630: sub files_exist {
1631: my ($r, $symb) = @_;
1632: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1633:
1.396 banghart 1634: foreach my $student (@students) {
1635: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1636: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1637: $udom,$uname);
1.396 banghart 1638: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1639: foreach my $submission (@$string) {
1640: my ($partid,$respid) =
1641: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1642: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1643: \%record);
1644: return 1 if (@$files);
1.396 banghart 1645: }
1646: }
1.397 albertel 1647: return 0;
1.396 banghart 1648: }
1.397 albertel 1649:
1.394 banghart 1650: sub download_all_link {
1651: my ($r,$symb) = @_;
1.395 albertel 1652: my $all_students =
1653: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1654:
1655: my $parts =
1656: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1657:
1.394 banghart 1658: my $identifier = &Apache::loncommon::get_cgi_id();
1659: &Apache::lonnet::appenv('cgi.'.$identifier.'.students' => $all_students,
1660: 'cgi.'.$identifier.'.symb' => $symb,
1.395 albertel 1661: 'cgi.'.$identifier.'.parts' => $parts,);
1662: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1663: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1664: return
1665: }
1.395 albertel 1666:
1.44 ng 1667: # --------------------------- show submissions of a student, option to grade
1668: sub submission {
1669: my ($request,$counter,$total) = @_;
1670:
1.257 albertel 1671: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1672: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1673: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1674: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.41 ng 1675:
1.324 albertel 1676: my $symb = &get_symb($request);
1677: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1678:
1679: if (!&canview($usec)) {
1.398 albertel 1680: $request->print('<span class="LC_warning">Unable to view requested student.('.
1681: $uname.':'.$udom.' in section '.$usec.' in course id '.
1682: $env{'request.course.id'}.')</span>');
1.324 albertel 1683: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1684: return;
1685: }
1686:
1.257 albertel 1687: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1688: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1689: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1690: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1691: my $checkIcon = '<img alt="'.&mt('Check Mark').
1692: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1693: '/check.gif" height="16" border="0" />';
1.41 ng 1694:
1695: # header info
1696: if ($counter == 0) {
1697: &sub_page_js($request);
1.257 albertel 1698: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1699: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1700: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 1701: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 1702: &download_all_link($request, $symb);
1703: }
1.398 albertel 1704: $request->print('<h3> <span class="LC_info">Submission Record</span></h3>'."\n".
1705: '<h4> <b>Resource: </b>'.$env{'form.probTitle'}.'</h4>'."\n");
1.118 ng 1706:
1.257 albertel 1707: if ($env{'form.handgrade'} eq 'no') {
1.118 ng 1708: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1709: $checkIcon.' symbol.'."\n";
1710: $request->print($checkMark);
1711: }
1.41 ng 1712:
1.44 ng 1713: # option to display problem, only once else it cause problems
1714: # with the form later since the problem has a form.
1.257 albertel 1715: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1716: my $mode;
1.257 albertel 1717: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1718: $mode='both';
1.257 albertel 1719: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1720: $mode='text';
1.257 albertel 1721: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1722: $mode='answer';
1723: }
1.329 albertel 1724: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1725: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1726: }
1727:
1.44 ng 1728: # kwclr is the only variable that is guaranteed to be non blank
1729: # if this subroutine has been called once.
1.41 ng 1730: my %keyhash = ();
1.257 albertel 1731: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1732: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1733: $env{'course.'.$env{'request.course.id'}.'.domain'},
1734: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1735:
1.257 albertel 1736: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1737: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1738: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1739: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1740: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1741: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1742: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1743: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1744: }
1.257 albertel 1745: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.44 ng 1746:
1.303 banghart 1747: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1748: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1749: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1750: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.120 ng 1751: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1752: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1753: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1754: '<input type="hidden" name="studentNo" value="" />'."\n".
1755: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.399.2.2! albertel 1756: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 1757: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1758: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1759: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1760: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.326 albertel 1761: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
1762: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1763: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1764: '<input type="hidden" name="NCT"'.
1.257 albertel 1765: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1766: if ($env{'form.handgrade'} eq 'yes') {
1767: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1768: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1769: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1770: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1771: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1772: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1773: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1774: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1775: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1776: }
1.123 ng 1777: }
1.41 ng 1778:
1779: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1780: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1781: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1782: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1783: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1784: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1785: '" />'."\n".
1786: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1787: $cts++;
1788: }
1789: $request->print($prnmsg);
1.32 ng 1790:
1.257 albertel 1791: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1792: #
1793: # Print out the keyword options line
1794: #
1.41 ng 1795: $request->print(<<KEYWORDS);
1.38 ng 1796: <b>Keyword Options:</b>
1.122 ng 1797: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>
1.38 ng 1798: <a href="#" onMouseDown="javascript:getSel(); return false"
1799: CLASS="page">Paste Selection to List</a>
1800: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1801: KEYWORDS
1.88 www 1802: #
1803: # Load the other essays for similarity check
1804: #
1.324 albertel 1805: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 1806: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 1807: $apath=&escape($apath);
1.88 www 1808: $apath=~s/\W/\_/gs;
1809: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1810: }
1811: }
1.44 ng 1812:
1.257 albertel 1813: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.71 ng 1814: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1815: my $mode;
1.257 albertel 1816: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1817: $mode='both';
1.257 albertel 1818: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1819: $mode='text';
1.257 albertel 1820: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1821: $mode='answer';
1822: }
1.329 albertel 1823: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1824: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1825: }
1.144 albertel 1826:
1.257 albertel 1827: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 1828: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 1829:
1.44 ng 1830: # Display student info
1.41 ng 1831: $request->print(($counter == 0 ? '' : '<br />'));
1.326 albertel 1832: my $result='<table border="0" width="100%"><tr><td bgcolor="#777777">'."\n".
1833: '<table border="0" width="100%"><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1834:
1.257 albertel 1835: $result.='<b>Fullname: </b>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1836: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1837: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.41 ng 1838:
1.118 ng 1839: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1840: my @col_fullnames;
1.56 matthew 1841: my ($classlist,$fullname);
1.257 albertel 1842: if ($env{'form.handgrade'} eq 'yes') {
1.80 ng 1843: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1844: for (keys (%$handgrade)) {
1.44 ng 1845: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1846: '.maxcollaborators',
1847: $symb,$udom,$uname);
1848: next if ($ncol <= 0);
1849: s/\_/\./g;
1850: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1851: my @goodcollaborators = ();
1852: my @badcollaborators = ();
1853: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1854: $_ =~ s/[\$\^\(\)]//g;
1855: next if ($_ eq '');
1.80 ng 1856: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1857: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1858: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1859: # Doing this grep allows 'fuzzy' specification
1860: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1861: if (! scalar(@Matches)) {
1862: push @badcollaborators,$_;
1863: } else {
1864: push @goodcollaborators, @Matches;
1865: }
1.80 ng 1866: }
1.86 ng 1867: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1868: $result.='<b>Collaborators: </b>';
1.86 ng 1869: foreach (@goodcollaborators) {
1870: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1871: push @col_fullnames, $givenn.' '.$lastname;
1872: $result.=$$fullname{$_}.' ';
1873: }
1.57 matthew 1874: $result.='<br />'."\n";
1.150 albertel 1875: my ($part)=split(/\./,$_);
1.86 ng 1876: $result.='<input type="hidden" name="collaborator'.$counter.
1.150 albertel 1877: '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
1878: "\n";
1.86 ng 1879: }
1880: if (scalar(@badcollaborators) > 0) {
1881: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1882: $result.='This student has submitted ';
1883: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1884: $result .= ': '.join(', ',@badcollaborators);
1885: $result .= '</td></tr></table>';
1886: }
1887: if (scalar(@badcollaborators > $ncol)) {
1888: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1889: $result .= 'This student has submitted too many '.
1890: 'collaborators. Maximum is '.$ncol.'.';
1891: $result .= '</td></tr></table>';
1892: }
1.41 ng 1893: }
1894: }
1.44 ng 1895: $request->print($result."\n");
1.33 ng 1896:
1.44 ng 1897: # print student answer/submission
1898: # Options are (1) Handgaded submission only
1899: # (2) Last submission, includes submission that is not handgraded
1900: # (for multi-response type part)
1901: # (3) Last submission plus the parts info
1902: # (4) The whole record for this student
1.257 albertel 1903: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 1904: my ($string,$timestamp)= &get_last_submission(\%record);
1905: my $lastsubonly=''.
1906: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1907: $$timestamp)."</td></tr>\n";
1908: if ($$timestamp eq '') {
1909: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1910: } else {
1911: my %seenparts;
1.375 albertel 1912: my @part_response_id = &flatten_responseType($responseType);
1913: foreach my $part (@part_response_id) {
1.393 albertel 1914: next if ($env{'form.lastSub'} eq 'hdgrade'
1915: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
1916:
1.375 albertel 1917: my ($partid,$respid) = @{ $part };
1.324 albertel 1918: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 1919: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 1920: if (exists($seenparts{$partid})) { next; }
1921: $seenparts{$partid}=1;
1.207 albertel 1922: my $submitby='<b>Part:</b> '.$display_part.
1923: ' <b>Collaborative submission by:</b> '.
1.151 albertel 1924: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 1925: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.151 albertel 1926: '\')"; TARGET=_self>'.
1.257 albertel 1927: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 1928: $request->print($submitby);
1929: next;
1930: }
1931: my $responsetype = $responseType->{$partid}->{$respid};
1932: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.207 albertel 1933: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1.398 albertel 1934: $display_part.' <span class="LC_internal_info">( ID '.$respid.
1935: ' )</span> '.
1936: '<span class="LC_warning">Nothing submitted - no attempts</span><br /><br />';
1.151 albertel 1937: next;
1938: }
1939: foreach (@$string) {
1940: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1.375 albertel 1941: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.151 albertel 1942: my ($ressub,$subval) = split(/:/,$_,2);
1943: # Similarity check
1944: my $similar='';
1.257 albertel 1945: if($env{'form.checkPlag'}){
1.151 albertel 1946: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1947: &most_similar($uname,$udom,$subval);
1948: if ($osim) {
1949: $osim=int($osim*100.0);
1.398 albertel 1950: $similar="<hr /><h3><span class=\"LC_warning\">Essay".
1.151 albertel 1951: " is $osim% similar to an essay by ".
1952: &Apache::loncommon::plainname($oname,$odom).
1.398 albertel 1953: '</span></h3><blockquote><i>'.
1.151 albertel 1954: &keywords_highlight($oessay).
1955: '</i></blockquote><hr />';
1956: }
1.150 albertel 1957: }
1.151 albertel 1958: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 1959: if ($env{'form.lastSub'} eq 'lastonly' ||
1960: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 1961: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 1962: my $display_part=&get_display_part($partid,$symb);
1.399.2.1 albertel 1963: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1964: $display_part.' <span class="LC_internal_info">( ID '.$respid.
1.398 albertel 1965: ' )</span> ';
1.313 banghart 1966: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
1967: if (@$files) {
1.398 albertel 1968: $lastsubonly.='<br /><span class="LC_warning">Like all files provided by users, this file may contain virusses</span><br />';
1.303 banghart 1969: my $file_counter = 0;
1.313 banghart 1970: foreach my $file (@$files) {
1.303 banghart 1971: $file_counter ++;
1.232 albertel 1972: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.335 albertel 1973: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1.232 albertel 1974: }
1.236 albertel 1975: $lastsubonly.='<br />';
1.41 ng 1976: }
1.151 albertel 1977: $lastsubonly.='<b>Submitted Answer: </b>'.
1978: &cleanRecord($subval,$responsetype,$symb,$partid,
1979: $respid,\%record,$order);
1980: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41 ng 1981: }
1982: }
1983: }
1.151 albertel 1984: }
1985: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1986: $request->print($lastsubonly);
1.257 albertel 1987: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 1988: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 1989: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 1990: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1991: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 1992: $env{'request.course.id'},
1.44 ng 1993: $last,'.submission',
1994: 'Apache::grades::keywords_highlight'));
1.41 ng 1995: }
1.120 ng 1996:
1.121 ng 1997: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1998: .$udom.'" />'."\n");
1.41 ng 1999:
1.44 ng 2000: # return if view submission with no grading option
1.257 albertel 2001: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2002: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 2003: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
2004: .$counter.'\');" TARGET=_self> '."\n" if (&canmodify($usec));
1.169 albertel 2005: $toGrade.='</td></tr></table></td></tr></table>'."\n";
1.257 albertel 2006: if (($env{'form.command'} eq 'submission') ||
2007: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2008: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2009: }
1.180 albertel 2010: $request->print($toGrade);
1.41 ng 2011: return;
1.180 albertel 2012: } else {
2013: $request->print('</td></tr></table></td></tr></table>'."\n");
1.41 ng 2014: }
1.33 ng 2015:
1.121 ng 2016: # essay grading message center
1.257 albertel 2017: if ($env{'form.handgrade'} eq 'yes') {
2018: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2019: my $msgfor = $givenn.' '.$lastname;
2020: if (scalar(@col_fullnames) > 0) {
2021: my $lastone = pop @col_fullnames;
2022: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
2023: }
2024: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 2025: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
2026: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2027: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118 ng 2028: ',\''.$msgfor.'\')"; TARGET=_self>'.
1.350 albertel 2029: &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
2030: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2031: '<img src="'.$request->dir_config('lonIconsURL').
2032: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2033: '<br /> ('.
2034: &mt('Message will be sent when you click on Save & Next below.').")\n";
1.121 ng 2035: $request->print($result);
1.118 ng 2036: }
1.300 albertel 2037: if ($perm{'vgr'}) {
1.297 www 2038: $request->print('<br />'.
1.300 albertel 2039: &Apache::loncommon::track_student_link(&mt('View recent activity'),
2040: $uname,$udom,'check'));
1.297 www 2041: }
1.300 albertel 2042: if ($perm{'opa'}) {
1.297 www 2043: $request->print('<br />'.
1.300 albertel 2044: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
2045: $uname,$udom,$symb,'check'));
1.297 www 2046: }
1.41 ng 2047:
2048: my %seen = ();
2049: my @partlist;
1.129 ng 2050: my @gradePartRespid;
1.375 albertel 2051: my @part_response_id = &flatten_responseType($responseType);
2052: foreach my $part_response_id (@part_response_id) {
2053: my ($partid,$respid) = @{ $part_response_id };
2054: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2055: next if ($seen{$partid} > 0);
1.41 ng 2056: $seen{$partid}++;
1.393 albertel 2057: next if ($$handgrade{$part_resp} ne 'yes'
2058: && $env{'form.lastSub'} eq 'hdgrade');
1.41 ng 2059: push @partlist,$partid;
1.129 ng 2060: push @gradePartRespid,$partid.'.'.$respid;
1.322 albertel 2061: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2062: }
1.45 ng 2063: $result='<input type="hidden" name="partlist'.$counter.
2064: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2065: $result.='<input type="hidden" name="gradePartRespid'.
2066: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2067: my $ctr = 0;
2068: while ($ctr < scalar(@partlist)) {
2069: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2070: $partlist[$ctr].'" />'."\n";
2071: $ctr++;
2072: }
2073: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 2074:
2075: # print end of form
2076: if ($counter == $total) {
1.297 www 2077: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 2078: $endform.='<input type="button" value="Save & Next" '.
2079: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
2080: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
2081: my $ntstu ='<select name="NTSTU">'.
2082: '<option>1</option><option>2</option>'.
2083: '<option>3</option><option>5</option>'.
2084: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2085: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.119 ng 2086: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
2087: $endform.=$ntstu.'student(s) ';
1.126 ng 2088: $endform.='<input type="button" value="Previous" '.
2089: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> '."\n".
2090: '<input type="button" value="Next" '.
2091: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> ';
2092: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.349 albertel 2093: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2094: "' name='increment' />";
1.45 ng 2095: $endform.='</td><tr></table></form>';
1.324 albertel 2096: $endform.=&show_grading_menu_form($symb);
1.41 ng 2097: $request->print($endform);
2098: }
2099: return '';
1.38 ng 2100: }
2101:
1.44 ng 2102: #--- Retrieve the last submission for all the parts
1.38 ng 2103: sub get_last_submission {
1.119 ng 2104: my ($returnhash)=@_;
1.46 ng 2105: my (@string,$timestamp);
1.119 ng 2106: if ($$returnhash{'version'}) {
1.46 ng 2107: my %lasthash=();
2108: my ($version);
1.119 ng 2109: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2110: foreach my $key (sort(split(/\:/,
2111: $$returnhash{$version.':keys'}))) {
2112: $lasthash{$key}=$$returnhash{$version.':'.$key};
2113: $timestamp =
2114: scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 2115: }
2116: }
1.397 albertel 2117: foreach my $key (keys(%lasthash)) {
2118: next if ($key !~ /\.submission$/);
2119:
2120: my ($partid,$foo) = split(/submission$/,$key);
2121: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2122: '<span class="LC_warning">Draft Copy</span> ' : '';
1.397 albertel 2123: push(@string, join(':', $key, $draft.$lasthash{$key}));
1.41 ng 2124: }
2125: }
1.397 albertel 2126: if (!@string) {
2127: $string[0] =
1.398 albertel 2128: '<span class="LC_warning">Nothing submitted - no attempts.</span>';
1.397 albertel 2129: }
2130: return (\@string,\$timestamp);
1.38 ng 2131: }
1.35 ng 2132:
1.44 ng 2133: #--- High light keywords, with style choosen by user.
1.38 ng 2134: sub keywords_highlight {
1.44 ng 2135: my $string = shift;
1.257 albertel 2136: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2137: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2138: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2139: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2140: foreach my $keyword (@keylist) {
2141: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2142: }
2143: return $string;
1.38 ng 2144: }
1.36 ng 2145:
1.44 ng 2146: #--- Called from submission routine
1.38 ng 2147: sub processHandGrade {
1.41 ng 2148: my ($request) = shift;
1.324 albertel 2149: my $symb = &get_symb($request);
2150: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2151: my $button = $env{'form.gradeOpt'};
2152: my $ngrade = $env{'form.NCT'};
2153: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2154: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2155: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2156:
1.44 ng 2157: if ($button eq 'Save & Next') {
2158: my $ctr = 0;
2159: while ($ctr < $ngrade) {
1.257 albertel 2160: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2161: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2162: if ($errorflag eq 'no_score') {
2163: $ctr++;
2164: next;
2165: }
1.104 albertel 2166: if ($errorflag eq 'not_allowed') {
1.398 albertel 2167: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2168: $ctr++;
2169: next;
2170: }
1.257 albertel 2171: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2172: my ($subject,$message,$msgstatus) = ('','','');
1.399.2.2! albertel 2173: my $restitle = &Apache::lonnet::gettitle($symb);
! 2174: my ($feedurl,$showsymb) =
! 2175: &get_feedurl_and_symb($symb,$uname,$udom);
! 2176: my $messagetail;
1.62 albertel 2177: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2178: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2179: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2180: $subject.=' ['.$restitle.']';
1.44 ng 2181: my (@msgnum) = split(/,/,$includemsg);
2182: foreach (@msgnum) {
1.257 albertel 2183: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2184: }
1.80 ng 2185: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2186: if ($env{'form.withgrades'.$ctr}) {
2187: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2188: $messagetail = " for <a href=\"".
1.399.2.2! albertel 2189: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2190: }
2191: $msgstatus =
2192: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2193: $message.$messagetail,
1.399.2.2! albertel 2194: undef,$feedurl,undef,
1.386 raeburn 2195: undef,undef,$showsymb,
2196: $restitle);
2197: $request->print('<br />'.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '.
1.296 www 2198: $msgstatus);
1.44 ng 2199: }
1.257 albertel 2200: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2201: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2202: foreach my $collabstr (@collabstrs) {
2203: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2204: foreach my $collaborator (@collaborators) {
1.150 albertel 2205: my ($errorflag,$pts,$wgt) =
1.324 albertel 2206: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2207: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2208: if ($errorflag eq 'not_allowed') {
1.362 albertel 2209: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2210: next;
1.399.2.2! albertel 2211: } elsif ($message ne '') {
! 2212: my ($baseurl,$showsymb) =
! 2213: &get_feedurl_and_symb($symb,$collaborator,
! 2214: $udom);
! 2215: if ($env{'form.withgrades'.$ctr}) {
! 2216: $messagetail = " for <a href=\"".
1.386 raeburn 2217: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2218: }
1.399.2.2! albertel 2219: $msgstatus =
! 2220: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2221: }
1.44 ng 2222: }
2223: }
2224: }
2225: $ctr++;
2226: }
2227: }
2228:
1.257 albertel 2229: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2230: # Keywords sorted in alphabatical order
1.257 albertel 2231: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2232: my %keyhash = ();
1.257 albertel 2233: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2234: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2235: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2236: $env{'form.keywords'} = join(' ',@keywords);
2237: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2238: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2239: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2240: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2241: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2242:
2243: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2244: # New messages are saved in env for the next student.
1.119 ng 2245: # All messages are saved in nohist_handgrade.db
2246: my ($ctr,$idx) = (1,1);
1.257 albertel 2247: while ($ctr <= $env{'form.savemsgN'}) {
2248: if ($env{'form.savemsg'.$ctr} ne '') {
2249: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2250: $idx++;
2251: }
2252: $ctr++;
1.41 ng 2253: }
1.119 ng 2254: $ctr = 0;
2255: while ($ctr < $ngrade) {
1.257 albertel 2256: if ($env{'form.newmsg'.$ctr} ne '') {
2257: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2258: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2259: $idx++;
2260: }
2261: $ctr++;
1.41 ng 2262: }
1.257 albertel 2263: $env{'form.savemsgN'} = --$idx;
2264: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2265: my $putresult = &Apache::lonnet::put
1.301 albertel 2266: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2267: }
1.44 ng 2268: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2269: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2270: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2271: my ($ctr,$total) = (0,0);
2272: while ($ctr < $ngrade) {
1.257 albertel 2273: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2274: $ctr++;
2275: }
1.257 albertel 2276: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2277: $ctr = 0;
2278: while ($ctr < $total) {
1.257 albertel 2279: my $processUser = $env{'form.unamedom'.$ctr};
2280: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2281: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2282: &submission($request,$ctr,$total-1);
1.41 ng 2283: $ctr++;
2284: }
2285: return '';
2286: }
1.36 ng 2287:
1.121 ng 2288: # Go directly to grade student - from submission or link from chart page
1.120 ng 2289: if ($button eq 'Grade Student') {
1.324 albertel 2290: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2291: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2292: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2293: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2294: &submission($request,0,0);
2295: return '';
2296: }
2297:
1.44 ng 2298: # Get the next/previous one or group of students
1.257 albertel 2299: my $firststu = $env{'form.unamedom0'};
2300: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2301: my $ctr = 2;
1.41 ng 2302: while ($laststu eq '') {
1.257 albertel 2303: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2304: $ctr++;
2305: $laststu = $firststu if ($ctr > $ngrade);
2306: }
1.44 ng 2307:
1.41 ng 2308: my (@parsedlist,@nextlist);
2309: my ($nextflg) = 0;
1.294 albertel 2310: foreach (sort
2311: {
2312: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2313: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2314: }
2315: return $a cmp $b;
2316: } (keys(%$fullname))) {
1.41 ng 2317: if ($nextflg == 1 && $button =~ /Next$/) {
2318: push @parsedlist,$_;
2319: }
2320: $nextflg = 1 if ($_ eq $laststu);
2321: if ($button eq 'Previous') {
2322: last if ($_ eq $firststu);
2323: push @parsedlist,$_;
2324: }
2325: }
2326: $ctr = 0;
2327: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2328: my ($partlist) = &response_type($symb);
1.41 ng 2329: foreach my $student (@parsedlist) {
1.257 albertel 2330: my $submitonly=$env{'form.submitonly'};
1.41 ng 2331: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2332:
2333: if ($submitonly eq 'queued') {
2334: my %queue_status =
2335: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2336: $udom,$uname);
2337: next if (!defined($queue_status{'gradingqueue'}));
2338: }
2339:
1.156 albertel 2340: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2341: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2342: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2343: my $submitted = 0;
1.248 albertel 2344: my $ungraded = 0;
2345: my $incorrect = 0;
1.145 albertel 2346: foreach (keys(%status)) {
2347: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2348: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
2349: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1.145 albertel 2350: my ($foo,$partid,$foo1) = split(/\./,$_);
2351: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2352: $submitted = 0;
2353: }
1.41 ng 2354: }
1.156 albertel 2355: next if (!$submitted && ($submitonly eq 'yes' ||
2356: $submitonly eq 'incorrect' ||
2357: $submitonly eq 'graded'));
1.248 albertel 2358: next if (!$ungraded && ($submitonly eq 'graded'));
2359: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2360: }
2361: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 2362: last if ($ctr == $ntstu);
1.41 ng 2363: $ctr++;
2364: }
1.36 ng 2365:
1.41 ng 2366: $ctr = 0;
2367: my $total = scalar(@nextlist)-1;
1.39 ng 2368:
1.41 ng 2369: foreach (sort @nextlist) {
2370: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2371: $env{'form.student'} = $uname;
2372: $env{'form.userdom'} = $udom;
2373: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2374: &submission($request,$ctr,$total);
2375: $ctr++;
2376: }
2377: if ($total < 0) {
1.398 albertel 2378: my $the_end = '<h3><span class="LC_info">LON-CAPA User Message</span></h3><br />'."\n";
1.41 ng 2379: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
2380: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1.324 albertel 2381: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2382: $request->print($the_end);
2383: }
2384: return '';
1.38 ng 2385: }
1.36 ng 2386:
1.44 ng 2387: #---- Save the score and award for each student, if changed
1.38 ng 2388: sub saveHandGrade {
1.324 albertel 2389: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2390: my @version_parts;
1.104 albertel 2391: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2392: $env{'request.course.id'});
1.104 albertel 2393: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2394: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2395: my @parts_graded;
1.77 ng 2396: my %newrecord = ();
2397: my ($pts,$wgt) = ('','');
1.269 raeburn 2398: my %aggregate = ();
2399: my $aggregateflag = 0;
1.301 albertel 2400: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2401: foreach my $new_part (@parts) {
1.337 banghart 2402: #collaborator ($submi may vary for different parts
1.259 banghart 2403: if ($submitter && $new_part ne $part) { next; }
2404: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2405: if ($dropMenu eq 'excused') {
1.259 banghart 2406: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2407: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2408: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2409: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2410: }
1.364 banghart 2411: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2412: }
1.125 ng 2413: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2414: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.197 albertel 2415: foreach my $key (keys (%record)) {
1.259 banghart 2416: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2417: }
1.259 banghart 2418: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2419: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2420: my $totaltries = $record{'resource.'.$part.'.tries'};
2421:
2422: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2423: [$new_part]);
2424: my $aggtries =$totaltries;
1.269 raeburn 2425: if ($last_resets{$new_part}) {
1.270 albertel 2426: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2427: $new_part);
1.269 raeburn 2428: }
1.270 albertel 2429:
2430: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2431: if ($aggtries > 0) {
1.327 albertel 2432: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2433: $aggregateflag = 1;
2434: }
1.125 ng 2435: } elsif ($dropMenu eq '') {
1.259 banghart 2436: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2437: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2438: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2439: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2440: next;
2441: }
1.259 banghart 2442: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2443: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2444: my $partial= $pts/$wgt;
1.259 banghart 2445: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2446: #do not update score for part if not changed.
1.346 banghart 2447: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2448: next;
1.251 banghart 2449: } else {
1.259 banghart 2450: push @parts_graded, $new_part;
1.153 albertel 2451: }
1.259 banghart 2452: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2453: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2454: }
1.259 banghart 2455: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2456: if ($partial == 0) {
1.153 albertel 2457: if ($record{$reckey} ne 'incorrect_by_override') {
2458: $newrecord{$reckey} = 'incorrect_by_override';
2459: }
1.41 ng 2460: } else {
1.153 albertel 2461: if ($record{$reckey} ne 'correct_by_override') {
2462: $newrecord{$reckey} = 'correct_by_override';
2463: }
2464: }
2465: if ($submitter &&
1.259 banghart 2466: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2467: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2468: }
1.259 banghart 2469: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2470: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2471: }
1.259 banghart 2472: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2473: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2474: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2475: $dropMenu eq 'reset status')
2476: {
1.342 banghart 2477: push (@version_parts,$new_part);
1.259 banghart 2478: }
1.41 ng 2479: }
1.301 albertel 2480: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2481: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2482:
1.344 albertel 2483: if (%newrecord) {
2484: if (@version_parts) {
1.364 banghart 2485: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2486: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2487: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2488: foreach my $new_part (@version_parts) {
2489: &handback_files($request,$symb,$stuname,$domain,$newflg,
2490: $new_part,\%newrecord);
2491: }
1.259 banghart 2492: }
1.44 ng 2493: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2494: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2495: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2496: $cdom,$cnum,$domain,$stuname);
1.41 ng 2497: }
1.269 raeburn 2498: if ($aggregateflag) {
2499: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2500: $cdom,$cnum);
1.269 raeburn 2501: }
1.301 albertel 2502: return ('',$pts,$wgt);
1.36 ng 2503: }
1.322 albertel 2504:
1.380 albertel 2505: sub check_and_remove_from_queue {
2506: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2507: my @ungraded_parts;
2508: foreach my $part (@{$parts}) {
2509: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2510: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2511: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2512: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2513: ) {
2514: push(@ungraded_parts, $part);
2515: }
2516: }
2517: if ( !@ungraded_parts ) {
2518: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2519: $cnum,$domain,$stuname);
2520: }
2521: }
2522:
1.337 banghart 2523: sub handback_files {
2524: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.359 www 2525: my $portfolio_root = &propath($domain,$stuname).'/userfiles/portfolio';
2526: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.375 albertel 2527:
2528: my @part_response_id = &flatten_responseType($responseType);
2529: foreach my $part_response_id (@part_response_id) {
2530: my ($part_id,$resp_id) = @{ $part_response_id };
2531: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2532: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2533: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2534: my $file_counter = 1;
1.367 albertel 2535: my $file_msg;
1.337 banghart 2536: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2537: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2538: my ($directory,$answer_file) =
2539: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2540: my ($answer_name,$answer_ver,$answer_ext) =
2541: &file_name_version_ext($answer_file);
1.355 banghart 2542: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.341 banghart 2543: my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
1.338 banghart 2544: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2545: # fix file name
2546: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2547: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2548: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2549: $save_file_name);
1.337 banghart 2550: if ($result !~ m|^/uploaded/|) {
1.398 albertel 2551: $request->print('<span class="LC_error">An errror occured ('.$result.
2552: ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'</span><br />');
1.356 banghart 2553: } else {
1.360 banghart 2554: # mark the file as read only
2555: my @files = ($save_file_name);
1.372 albertel 2556: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2557: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2558: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2559: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2560: }
2561: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2562: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2563:
1.337 banghart 2564: }
2565: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2566: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2567: $file_counter++;
2568: }
1.367 albertel 2569: my $subject = "File Handed Back by Instructor ";
2570: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2571: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2572: $message .= ' The returned file(s) are named: '. $file_msg;
2573: $message .= " and can be found in your portfolio space.";
1.399.2.2! albertel 2574: my ($feedurl,$showsymb) =
! 2575: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2576: my $restitle = &Apache::lonnet::gettitle($symb);
2577: my $msgstatus =
2578: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2579: ' (File Returned) ['.$restitle.']',$message,undef,
1.399.2.2! albertel 2580: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2581: }
2582: }
1.338 banghart 2583: return;
1.337 banghart 2584: }
2585:
1.399.2.2! albertel 2586: sub get_feedurl_and_symb {
! 2587: my ($symb,$uname,$udom) = @_;
! 2588: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
! 2589: $url = &Apache::lonnet::clutter($url);
! 2590: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
! 2591: $symb,$udom,$uname);
! 2592: if ($encrypturl =~ /^yes$/i) {
! 2593: &Apache::lonenc::encrypted(\$url,1);
! 2594: &Apache::lonenc::encrypted(\$symb,1);
! 2595: }
! 2596: return ($url,$symb);
! 2597: }
! 2598:
1.313 banghart 2599: sub get_submitted_files {
2600: my ($udom,$uname,$partid,$respid,$record) = @_;
2601: my @files;
2602: if ($$record{"resource.$partid.$respid.portfiles"}) {
2603: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2604: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2605: push(@files,$file_url.$file);
2606: }
2607: }
2608: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2609: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2610: }
2611: return (\@files);
2612: }
1.322 albertel 2613:
1.269 raeburn 2614: # ----------- Provides number of tries since last reset.
2615: sub get_num_tries {
2616: my ($record,$last_reset,$part) = @_;
2617: my $timestamp = '';
2618: my $num_tries = 0;
2619: if ($$record{'version'}) {
2620: for (my $version=$$record{'version'};$version>=1;$version--) {
2621: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2622: $timestamp = $$record{$version.':timestamp'};
2623: if ($timestamp > $last_reset) {
2624: $num_tries ++;
2625: } else {
2626: last;
2627: }
2628: }
2629: }
2630: }
2631: return $num_tries;
2632: }
2633:
2634: # ----------- Determine decrements required in aggregate totals
2635: sub decrement_aggs {
2636: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2637: my %decrement = (
2638: attempts => 0,
2639: users => 0,
2640: correct => 0
2641: );
2642: $decrement{'attempts'} = $aggtries;
2643: if ($solvedstatus =~ /^correct/) {
2644: $decrement{'correct'} = 1;
2645: }
2646: if ($aggtries == $totaltries) {
2647: $decrement{'users'} = 1;
2648: }
2649: foreach my $type (keys (%decrement)) {
2650: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2651: }
2652: return;
2653: }
2654:
2655: # ----------- Determine timestamps for last reset of aggregate totals for parts
2656: sub get_last_resets {
1.270 albertel 2657: my ($symb,$courseid,$partids) =@_;
2658: my %last_resets;
1.269 raeburn 2659: my $cdom = $env{'course.'.$courseid.'.domain'};
2660: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2661: my @keys;
2662: foreach my $part (@{$partids}) {
2663: push(@keys,"$symb\0$part\0resettime");
2664: }
2665: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2666: $cdom,$cname);
2667: foreach my $part (@{$partids}) {
2668: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2669: }
1.270 albertel 2670: return %last_resets;
1.269 raeburn 2671: }
2672:
1.251 banghart 2673: # ----------- Handles creating versions for portfolio files as answers
2674: sub version_portfiles {
1.343 banghart 2675: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2676: my $version_parts = join('|',@$v_flag);
1.343 banghart 2677: my @returned_keys;
1.255 banghart 2678: my $parts = join('|', @$parts_graded);
1.359 www 2679: my $portfolio_root = &propath($domain,$stu_name).
2680: '/userfiles/portfolio';
1.277 albertel 2681: foreach my $key (keys(%$record)) {
1.259 banghart 2682: my $new_portfiles;
1.263 banghart 2683: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2684: my @versioned_portfiles;
1.367 albertel 2685: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 2686: foreach my $file (@portfiles) {
1.306 banghart 2687: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2688: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2689: my ($answer_name,$answer_ver,$answer_ext) =
2690: &file_name_version_ext($answer_file);
1.306 banghart 2691: my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
1.342 banghart 2692: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2693: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2694: if ($new_answer ne 'problem getting file') {
1.342 banghart 2695: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2696: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 2697: [$directory.$new_answer],
1.306 banghart 2698: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2699: }
1.252 banghart 2700: }
1.343 banghart 2701: $$record{$key} = join(',',@versioned_portfiles);
2702: push(@returned_keys,$key);
1.251 banghart 2703: }
2704: }
1.343 banghart 2705: return (@returned_keys);
1.305 banghart 2706: }
2707:
1.307 banghart 2708: sub get_next_version {
1.341 banghart 2709: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2710: my $version;
2711: foreach my $row (@$dir_list) {
2712: my ($file) = split(/\&/,$row,2);
2713: my ($file_name,$file_version,$file_ext) =
2714: &file_name_version_ext($file);
2715: if (($file_name eq $answer_name) &&
2716: ($file_ext eq $answer_ext)) {
2717: # gets here if filename and extension match, regardless of version
2718: if ($file_version ne '') {
2719: # a versioned file is found so save it for later
2720: if ($file_version > $version) {
2721: $version = $file_version;
2722: }
2723: }
2724: }
2725: }
2726: $version ++;
2727: return($version);
2728: }
2729:
1.305 banghart 2730: sub version_selected_portfile {
1.306 banghart 2731: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2732: my ($answer_name,$answer_ver,$answer_ext) =
2733: &file_name_version_ext($file_name);
2734: my $new_answer;
2735: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2736: if($env{'form.copy'} eq '-1') {
2737: &Apache::lonnet::logthis('problem getting file '.$file_name);
2738: $new_answer = 'problem getting file';
2739: } else {
2740: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2741: my $copy_result = &Apache::lonnet::finishuserfileupload(
2742: $stu_name,$domain,'copy',
2743: '/portfolio'.$directory.$new_answer);
2744: }
2745: return ($new_answer);
1.251 banghart 2746: }
2747:
1.304 albertel 2748: sub file_name_version_ext {
2749: my ($file)=@_;
2750: my @file_parts = split(/\./, $file);
2751: my ($name,$version,$ext);
2752: if (@file_parts > 1) {
2753: $ext=pop(@file_parts);
2754: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2755: $version=pop(@file_parts);
2756: }
2757: $name=join('.',@file_parts);
2758: } else {
2759: $name=join('.',@file_parts);
2760: }
2761: return($name,$version,$ext);
2762: }
2763:
1.44 ng 2764: #--------------------------------------------------------------------------------------
2765: #
2766: #-------------------------- Next few routines handles grading by section or whole class
2767: #
2768: #--- Javascript to handle grading by section or whole class
1.42 ng 2769: sub viewgrades_js {
2770: my ($request) = shift;
2771:
1.41 ng 2772: $request->print(<<VIEWJAVASCRIPT);
2773: <script type="text/javascript" language="javascript">
1.45 ng 2774: function writePoint(partid,weight,point) {
1.125 ng 2775: var radioButton = document.classgrade["RADVAL_"+partid];
2776: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2777: if (point == "textval") {
1.125 ng 2778: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2779: if (isNaN(point) || parseFloat(point) < 0) {
2780: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2781: var resetbox = false;
2782: for (var i=0; i<radioButton.length; i++) {
2783: if (radioButton[i].checked) {
2784: textbox.value = i;
2785: resetbox = true;
2786: }
2787: }
2788: if (!resetbox) {
2789: textbox.value = "";
2790: }
2791: return;
2792: }
1.109 matthew 2793: if (parseFloat(point) > parseFloat(weight)) {
2794: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2795: ") greater than the weight for the part. Accept?");
2796: if (resp == false) {
2797: textbox.value = "";
2798: return;
2799: }
2800: }
1.42 ng 2801: for (var i=0; i<radioButton.length; i++) {
2802: radioButton[i].checked=false;
1.109 matthew 2803: if (parseFloat(point) == i) {
1.42 ng 2804: radioButton[i].checked=true;
2805: }
2806: }
1.41 ng 2807:
1.42 ng 2808: } else {
1.125 ng 2809: textbox.value = parseFloat(point);
1.42 ng 2810: }
1.41 ng 2811: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2812: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2813: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2814: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2815: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2816: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2817: if (saveval != "correct") {
2818: scorename.value = point;
1.43 ng 2819: if (selname[0].selected != true) {
2820: selname[0].selected = true;
2821: }
1.42 ng 2822: }
2823: }
1.125 ng 2824: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2825: }
2826:
2827: function writeRadText(partid,weight) {
1.125 ng 2828: var selval = document.classgrade["SELVAL_"+partid];
2829: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 2830: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 2831: var textbox = document.classgrade["TEXTVAL_"+partid];
2832: if (selval[1].selected || selval[2].selected) {
1.42 ng 2833: for (var i=0; i<radioButton.length; i++) {
2834: radioButton[i].checked=false;
2835:
2836: }
2837: textbox.value = "";
2838:
2839: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2840: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2841: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2842: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2843: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2844: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2845: if ((saveval != "correct") || override) {
1.42 ng 2846: scorename.value = "";
1.125 ng 2847: if (selval[1].selected) {
2848: selname[1].selected = true;
2849: } else {
2850: selname[2].selected = true;
2851: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2852: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2853: }
1.42 ng 2854: }
2855: }
1.43 ng 2856: } else {
2857: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2858: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2859: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2860: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2861: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2862: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2863: if ((saveval != "correct") || override) {
1.125 ng 2864: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2865: selname[0].selected = true;
2866: }
2867: }
2868: }
1.42 ng 2869: }
2870:
2871: function changeSelect(partid,user) {
1.125 ng 2872: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2873: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2874: var point = textbox.value;
1.125 ng 2875: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2876:
1.109 matthew 2877: if (isNaN(point) || parseFloat(point) < 0) {
2878: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2879: textbox.value = "";
2880: return;
2881: }
1.109 matthew 2882: if (parseFloat(point) > parseFloat(weight)) {
2883: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2884: ") greater than the weight of the part. Accept?");
2885: if (resp == false) {
2886: textbox.value = "";
2887: return;
2888: }
2889: }
1.42 ng 2890: selval[0].selected = true;
2891: }
2892:
2893: function changeOneScore(partid,user) {
1.125 ng 2894: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2895: if (selval[1].selected || selval[2].selected) {
2896: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2897: if (selval[2].selected) {
2898: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2899: }
1.269 raeburn 2900: }
1.42 ng 2901: }
2902:
2903: function resetEntry(numpart) {
2904: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2905: var partid = document.classgrade["partid_"+ctpart].value;
2906: var radioButton = document.classgrade["RADVAL_"+partid];
2907: var textbox = document.classgrade["TEXTVAL_"+partid];
2908: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2909: for (var i=0; i<radioButton.length; i++) {
2910: radioButton[i].checked=false;
2911:
2912: }
2913: textbox.value = "";
2914: selval[0].selected = true;
2915:
2916: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2917: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2918: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2919: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2920: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2921: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2922: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2923: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2924: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2925: if (saveselval == "excused") {
1.43 ng 2926: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2927: } else {
1.43 ng 2928: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2929: }
2930: }
1.41 ng 2931: }
1.42 ng 2932: }
2933:
1.41 ng 2934: </script>
2935: VIEWJAVASCRIPT
1.42 ng 2936: }
2937:
1.44 ng 2938: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2939: sub viewgrades {
2940: my ($request) = shift;
2941: &viewgrades_js($request);
1.41 ng 2942:
1.324 albertel 2943: my ($symb) = &get_symb($request);
1.168 albertel 2944: #need to make sure we have the correct data for later EXT calls,
2945: #thus invalidate the cache
2946: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 2947: $env{'course.'.$env{'request.course.id'}.'.num'},
2948: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 2949: &Apache::lonnet::clear_EXT_cache_status();
2950:
1.398 albertel 2951: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
2952: $result.='<h4><b>Current Resource: </b>'.$env{'form.probTitle'}.'</h4>'."\n";
1.41 ng 2953:
2954: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 2955: $result.=&jscriptNform($symb);
1.41 ng 2956:
1.44 ng 2957: #beginning of class grading form
1.41 ng 2958: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.399.2.2! albertel 2959: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 2960: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.257 albertel 2961: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
2962: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
2963: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
2964: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 2965:
1.126 ng 2966: my $sectionClass;
1.257 albertel 2967: if ($env{'form.section'} eq 'all') {
1.126 ng 2968: $sectionClass='Class </h3>';
1.257 albertel 2969: } elsif ($env{'form.section'} eq 'none') {
1.126 ng 2970: $sectionClass='Students in no Section </h3>';
1.52 albertel 2971: } else {
1.257 albertel 2972: $sectionClass='Students in Section '.$env{'form.section'}.'</h3>';
1.52 albertel 2973: }
1.126 ng 2974: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2975: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2976: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2977: #radio buttons/text box for assigning points for a section or class.
2978: #handles different parts of a problem
1.375 albertel 2979: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.42 ng 2980: my %weight = ();
2981: my $ctsparts = 0;
1.41 ng 2982: $result.='<table border="0">';
1.45 ng 2983: my %seen = ();
1.375 albertel 2984: my @part_response_id = &flatten_responseType($responseType);
2985: foreach my $part_response_id (@part_response_id) {
2986: my ($partid,$respid) = @{ $part_response_id };
2987: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 2988: next if $seen{$partid};
2989: $seen{$partid}++;
1.375 albertel 2990: my $handgrade=$$handgrade{$part_resp};
1.42 ng 2991: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
2992: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
2993:
1.44 ng 2994: $result.='<input type="hidden" name="partid_'.
2995: $ctsparts.'" value="'.$partid.'" />'."\n";
2996: $result.='<input type="hidden" name="weight_'.
2997: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1.324 albertel 2998: my $display_part=&get_display_part($partid,$symb);
1.207 albertel 2999: $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>';
1.42 ng 3000: $result.='<table border="0"><tr>';
1.41 ng 3001: my $ctr = 0;
1.42 ng 3002: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.288 albertel 3003: $result.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3004: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3005: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3006: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3007: $ctr++;
3008: }
3009: $result.='</tr></table>';
1.44 ng 3010: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 3011: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
3012: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 3013: $weight{$partid}.' (problem weight)</td>'."\n";
3014: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 3015: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3016: $weight{$partid}.')"> '.
1.42 ng 3017: '<option selected="on"> </option>'.
1.125 ng 3018: '<option>excused</option>'.
1.265 www 3019: '<option>reset status</option></select></td>'.
1.266 albertel 3020: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
1.42 ng 3021: $ctsparts++;
1.41 ng 3022: }
1.52 albertel 3023: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
3024: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.391 banghart 3025: $result.='<input type="button" value="Revert to Default" '.
1.111 ng 3026: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41 ng 3027:
1.44 ng 3028: #table listing all the students in a section/class
3029: #header of table
1.126 ng 3030: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 3031: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 3032: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 3033: '<td>'.&nameUserString('header')."</td>\n";
1.324 albertel 3034: my (@parts) = sort(&getpartlist($symb));
3035: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3036: my @partids = ();
1.41 ng 3037: foreach my $part (@parts) {
3038: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 3039: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 3040: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3041: my ($partid) = &split_part_type($part);
1.269 raeburn 3042: push(@partids, $partid);
1.324 albertel 3043: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3044: if ($display =~ /^Partial Credit Factor/) {
1.207 albertel 3045: $result.='<td><b>Score Part:</b> '.$display_part.
3046: ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
1.41 ng 3047: next;
1.207 albertel 3048: } else {
3049: $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
1.41 ng 3050: }
1.53 albertel 3051: $display =~ s|Problem Status|Grade Status<br />|;
1.207 albertel 3052: $result.='<td><b>'.$display.'</td>'."\n";
1.41 ng 3053: }
3054: $result.='</tr>';
1.44 ng 3055:
1.270 albertel 3056: my %last_resets =
3057: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3058:
1.41 ng 3059: #get info for each student
1.44 ng 3060: #list all the students - with points and grade status
1.257 albertel 3061: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3062: my $ctr = 0;
1.294 albertel 3063: foreach (sort
3064: {
3065: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3066: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3067: }
3068: return $a cmp $b;
3069: } (keys(%$fullname))) {
1.126 ng 3070: $ctr++;
1.324 albertel 3071: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3072: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3073: }
3074: $result.='</table></td></tr></table>';
3075: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 3076: $result.='<input type="button" value="Save" '.
1.45 ng 3077: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96 albertel 3078: if (scalar(%$fullname) eq 0) {
3079: my $colspan=3+scalar(@parts);
1.398 albertel 3080: $result='<span class="LC_warning">There are no students in section "'.$env{'form.section'}.
3081: '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.</span>';
1.96 albertel 3082: }
1.324 albertel 3083: $result.=&show_grading_menu_form($symb);
1.41 ng 3084: return $result;
3085: }
3086:
1.44 ng 3087: #--- call by previous routine to display each student
1.41 ng 3088: sub viewstudentgrade {
1.324 albertel 3089: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3090: my ($uname,$udom) = split(/:/,$student);
3091: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3092: my %aggregates = ();
1.233 albertel 3093: my $result='<tr bgcolor="#ffffdd"><td align="right">'.
3094: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3095: "\n".$ctr.' </td><td> '.
1.44 ng 3096: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112 ng 3097: '\')"; TARGET=_self>'.$fullname.'</a> '.
1.398 albertel 3098: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3099: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3100: foreach my $apart (@$parts) {
3101: my ($part,$type) = &split_part_type($apart);
1.41 ng 3102: my $score=$record{"resource.$part.$type"};
1.276 albertel 3103: $result.='<td align="center">';
1.269 raeburn 3104: my ($aggtries,$totaltries);
3105: unless (exists($aggregates{$part})) {
1.270 albertel 3106: $totaltries = $record{'resource.'.$part.'.tries'};
3107:
3108: $aggtries = $totaltries;
1.269 raeburn 3109: if ($$last_resets{$part}) {
1.270 albertel 3110: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3111: $part);
3112: }
1.269 raeburn 3113: $result.='<input type="hidden" name="'.
3114: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3115: $result.='<input type="hidden" name="'.
3116: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3117: $aggregates{$part} = 1;
3118: }
1.41 ng 3119: if ($type eq 'awarded') {
1.320 albertel 3120: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3121: $result.='<input type="hidden" name="'.
1.89 albertel 3122: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3123: $result.='<input type="text" name="'.
1.89 albertel 3124: 'GD_'.$student.'_'.$part.'_awarded" '.
3125: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3126: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3127: } elsif ($type eq 'solved') {
3128: my ($status,$foo)=split(/_/,$score,2);
3129: $status = 'nothing' if ($status eq '');
1.89 albertel 3130: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3131: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3132: $result.=' <select name="'.
1.89 albertel 3133: 'GD_'.$student.'_'.$part.'_solved" '.
3134: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125 ng 3135: $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>'
3136: : '<option selected="on"> </option><option>excused</option>')."\n";
3137: $result.='<option>reset status</option>';
1.126 ng 3138: $result.="</select> </td>\n";
1.122 ng 3139: } else {
3140: $result.='<input type="hidden" name="'.
3141: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3142: "\n";
1.233 albertel 3143: $result.='<input type="text" name="'.
1.122 ng 3144: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3145: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3146: }
3147: }
3148: $result.='</tr>';
3149: return $result;
1.38 ng 3150: }
3151:
1.44 ng 3152: #--- change scores for all the students in a section/class
3153: # record does not get update if unchanged
1.38 ng 3154: sub editgrades {
1.41 ng 3155: my ($request) = @_;
3156:
1.324 albertel 3157: my $symb=&get_symb($request);
1.398 albertel 3158: my $title='<h3><span class="LC_info">Current Grade Status</span></h3>';
3159: $title.='<h4><b>Current Resource: </b>'.$env{'form.probTitle'}.'</h4><br />'."\n";
3160: $title.='<h4><b>Section: </b>'.$env{'form.section'}.'</h4>'."\n";
1.126 ng 3161:
1.44 ng 3162: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 3163: $result.= '<table border="0"><tr bgcolor="#deffff">'.
3164: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
3165: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 3166:
3167: my %scoreptr = (
3168: 'correct' =>'correct_by_override',
3169: 'incorrect'=>'incorrect_by_override',
3170: 'excused' =>'excused',
3171: 'ungraded' =>'ungraded_attempted',
3172: 'nothing' => '',
3173: );
1.257 albertel 3174: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3175:
1.44 ng 3176: my (@partid);
3177: my %weight = ();
1.54 albertel 3178: my %columns = ();
1.44 ng 3179: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3180:
1.324 albertel 3181: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3182: my $header;
1.257 albertel 3183: while ($ctr < $env{'form.totalparts'}) {
3184: my $partid = $env{'form.partid_'.$ctr};
1.44 ng 3185: push @partid,$partid;
1.257 albertel 3186: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3187: $ctr++;
1.54 albertel 3188: }
1.324 albertel 3189: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3190: foreach my $partid (@partid) {
3191: $header .= '<td align="center"> <b>Old Score</b> </td>'.
3192: '<td align="center"> <b>New Score</b> </td>';
3193: $columns{$partid}=2;
3194: foreach my $stores (@parts) {
3195: my ($part,$type) = &split_part_type($stores);
3196: if ($part !~ m/^\Q$partid\E/) { next;}
3197: if ($type eq 'awarded' || $type eq 'solved') { next; }
3198: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
3199: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 3200: $display =~ s/Number of Attempts/Tries/;
3201: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
3202: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 3203: $columns{$partid}+=2;
3204: }
3205: }
3206: foreach my $partid (@partid) {
1.324 albertel 3207: my $display_part=&get_display_part($partid,$symb);
1.54 albertel 3208: $result .= '<td colspan="'.$columns{$partid}.
1.207 albertel 3209: '" align="center"><b>Part:</b> '.$display_part.
3210: ' (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 3211:
1.44 ng 3212: }
3213: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 3214: $result .= $header;
1.44 ng 3215: $result .= '</tr>'."\n";
1.93 albertel 3216: my $noupdate;
1.126 ng 3217: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3218: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3219: my $line;
1.257 albertel 3220: my $user = $env{'form.ctr'.$i};
1.281 albertel 3221: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3222: my %newrecord;
3223: my $updateflag = 0;
1.281 albertel 3224: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3225: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3226: if (!&canmodify($usec)) {
1.126 ng 3227: my $numcols=scalar(@partid)*4+2;
1.399 albertel 3228: $noupdate.=$line."<td colspan=\"$numcols\"><span class=\"LC_warning\">Not allowed to modify student</span></td></tr>";
1.105 albertel 3229: next;
3230: }
1.269 raeburn 3231: my %aggregate = ();
3232: my $aggregateflag = 0;
1.281 albertel 3233: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3234: foreach (@partid) {
1.257 albertel 3235: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3236: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3237: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3238: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3239: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3240: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3241: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3242: my $score;
3243: if ($partial eq '') {
1.257 albertel 3244: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3245: } elsif ($partial > 0) {
3246: $score = 'correct_by_override';
3247: } elsif ($partial == 0) {
3248: $score = 'incorrect_by_override';
3249: }
1.257 albertel 3250: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3251: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3252:
1.292 albertel 3253: $newrecord{'resource.'.$_.'.regrader'}=
3254: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3255: if ($dropMenu eq 'reset status' &&
3256: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3257: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3258: $newrecord{'resource.'.$_.'.solved'} = '';
3259: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3260: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3261: $updateflag = 1;
1.269 raeburn 3262: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3263: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3264: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3265: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3266: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3267: $aggregateflag = 1;
3268: }
1.139 albertel 3269: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3270: $updateflag = 1;
3271: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3272: $newrecord{'resource.'.$_.'.solved'} = $score;
3273: $rec_update++;
1.125 ng 3274: }
3275:
1.93 albertel 3276: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3277: '<td align="center">'.$awarded.
3278: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3279:
1.54 albertel 3280:
3281: my $partid=$_;
3282: foreach my $stores (@parts) {
3283: my ($part,$type) = &split_part_type($stores);
3284: if ($part !~ m/^\Q$partid\E/) { next;}
3285: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3286: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3287: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3288: if ($awarded ne '' && $awarded ne $old_aw) {
3289: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3290: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3291: $updateflag=1;
3292: }
1.93 albertel 3293: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3294: '<td align="center">'.$awarded.' </td>';
3295: }
1.44 ng 3296: }
1.93 albertel 3297: $line.='</tr>'."\n";
1.301 albertel 3298:
3299: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3300: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3301:
1.44 ng 3302: if ($updateflag) {
3303: $count++;
1.257 albertel 3304: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3305: $udom,$uname);
1.301 albertel 3306:
3307: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3308: $cnum,$udom,$uname)) {
3309: # need to figure out if should be in queue.
3310: my %record =
3311: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3312: $udom,$uname);
3313: my $all_graded = 1;
3314: my $none_graded = 1;
3315: foreach my $part (@parts) {
3316: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3317: $all_graded = 0;
3318: } else {
3319: $none_graded = 0;
3320: }
3321: }
3322:
3323: if ($all_graded || $none_graded) {
3324: &Apache::bridgetask::remove_from_queue('gradingqueue',
3325: $symb,$cdom,$cnum,
3326: $udom,$uname);
3327: }
3328: }
3329:
1.126 ng 3330: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
3331: $updateCtr++;
1.93 albertel 3332: } else {
1.126 ng 3333: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
3334: $noupdateCtr++;
1.44 ng 3335: }
1.269 raeburn 3336: if ($aggregateflag) {
3337: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3338: $cdom,$cnum);
1.269 raeburn 3339: }
1.93 albertel 3340: }
3341: if ($noupdate) {
1.126 ng 3342: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3343: my $numcols=scalar(@partid)*4+2;
1.204 albertel 3344: $result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occurred For the Students Below</td></tr><tr bgcolor="#ffffde">'.$noupdate;
1.44 ng 3345: }
1.72 ng 3346: $result .= '</table></td></tr></table>'."\n".
1.324 albertel 3347: &show_grading_menu_form ($symb);
1.125 ng 3348: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 3349: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1.257 albertel 3350: '<b>Total number of students = '.$env{'form.total'}.'</b><br />';
1.44 ng 3351: return $title.$msg.$result;
1.5 albertel 3352: }
1.54 albertel 3353:
3354: sub split_part_type {
3355: my ($partstr) = @_;
3356: my ($temp,@allparts)=split(/_/,$partstr);
3357: my $type=pop(@allparts);
3358: my $part=join('.',@allparts);
3359: return ($part,$type);
3360: }
3361:
1.44 ng 3362: #------------- end of section for handling grading by section/class ---------
3363: #
3364: #----------------------------------------------------------------------------
3365:
1.5 albertel 3366:
1.44 ng 3367: #----------------------------------------------------------------------------
3368: #
3369: #-------------------------- Next few routines handles grading by csv upload
3370: #
3371: #--- Javascript to handle csv upload
1.27 albertel 3372: sub csvupload_javascript_reverse_associate {
1.246 albertel 3373: my $error1=&mt('You need to specify the username or ID');
3374: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3375: return(<<ENDPICK);
3376: function verify(vf) {
3377: var foundsomething=0;
3378: var founduname=0;
1.243 albertel 3379: var foundID=0;
1.27 albertel 3380: for (i=0;i<=vf.nfields.value;i++) {
3381: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3382: if (i==0 && tw!=0) { foundID=1; }
3383: if (i==1 && tw!=0) { founduname=1; }
3384: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3385: }
1.246 albertel 3386: if (founduname==0 && foundID==0) {
3387: alert('$error1');
3388: return;
1.27 albertel 3389: }
3390: if (foundsomething==0) {
1.246 albertel 3391: alert('$error2');
3392: return;
1.27 albertel 3393: }
3394: vf.submit();
3395: }
3396: function flip(vf,tf) {
3397: var nw=eval('vf.f'+tf+'.selectedIndex');
3398: var i;
3399: for (i=0;i<=vf.nfields.value;i++) {
3400: //can not pick the same destination field for both name and domain
3401: if (((i ==0)||(i ==1)) &&
3402: ((tf==0)||(tf==1)) &&
3403: (i!=tf) &&
3404: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3405: eval('vf.f'+i+'.selectedIndex=0;')
3406: }
3407: }
3408: }
3409: ENDPICK
3410: }
3411:
3412: sub csvupload_javascript_forward_associate {
1.246 albertel 3413: my $error1=&mt('You need to specify the username or ID');
3414: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3415: return(<<ENDPICK);
3416: function verify(vf) {
3417: var foundsomething=0;
3418: var founduname=0;
1.243 albertel 3419: var foundID=0;
1.27 albertel 3420: for (i=0;i<=vf.nfields.value;i++) {
3421: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3422: if (tw==1) { foundID=1; }
3423: if (tw==2) { founduname=1; }
3424: if (tw>3) { foundsomething=1; }
1.27 albertel 3425: }
1.246 albertel 3426: if (founduname==0 && foundID==0) {
3427: alert('$error1');
3428: return;
1.27 albertel 3429: }
3430: if (foundsomething==0) {
1.246 albertel 3431: alert('$error2');
3432: return;
1.27 albertel 3433: }
3434: vf.submit();
3435: }
3436: function flip(vf,tf) {
3437: var nw=eval('vf.f'+tf+'.selectedIndex');
3438: var i;
3439: //can not pick the same destination field twice
3440: for (i=0;i<=vf.nfields.value;i++) {
3441: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3442: eval('vf.f'+i+'.selectedIndex=0;')
3443: }
3444: }
3445: }
3446: ENDPICK
3447: }
3448:
1.26 albertel 3449: sub csvuploadmap_header {
1.324 albertel 3450: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3451: my $javascript;
1.257 albertel 3452: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3453: $javascript=&csvupload_javascript_reverse_associate();
3454: } else {
3455: $javascript=&csvupload_javascript_forward_associate();
3456: }
1.45 ng 3457:
1.324 albertel 3458: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3459: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3460: my $ignore=&mt('Ignore First Line');
1.399.2.2! albertel 3461: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3462: $request->print(<<ENDPICK);
1.26 albertel 3463: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3464: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3465: $result
1.326 albertel 3466: <hr />
1.26 albertel 3467: <h3>Identify fields</h3>
3468: Total number of records found in file: $distotal <hr />
3469: Enter as many fields as you can. The system will inform you and bring you back
3470: to this page if the data selected is insufficient to run your class.<hr />
3471: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3472: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3473: <input type="hidden" name="associate" value="" />
3474: <input type="hidden" name="phase" value="three" />
3475: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3476: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3477: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3478: <input type="hidden" name="upfile_associate"
1.257 albertel 3479: value="$env{'form.upfile_associate'}" />
1.26 albertel 3480: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3481: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3482: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3483: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3484: <hr />
3485: <script type="text/javascript" language="Javascript">
3486: $javascript
3487: </script>
3488: ENDPICK
1.118 ng 3489: return '';
1.26 albertel 3490:
3491: }
3492:
3493: sub csvupload_fields {
1.324 albertel 3494: my ($symb) = @_;
3495: my (@parts) = &getpartlist($symb);
1.243 albertel 3496: my @fields=(['ID','Student ID'],
3497: ['username','Student Username'],
3498: ['domain','Student Domain']);
1.324 albertel 3499: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3500: foreach my $part (sort(@parts)) {
3501: my @datum;
3502: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3503: my $name=$part;
3504: if (!$display) { $display = $name; }
3505: @datum=($name,$display);
1.244 albertel 3506: if ($name=~/^stores_(.*)_awarded/) {
3507: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3508: }
1.41 ng 3509: push(@fields,\@datum);
3510: }
3511: return (@fields);
1.26 albertel 3512: }
3513:
3514: sub csvuploadmap_footer {
1.41 ng 3515: my ($request,$i,$keyfields) =@_;
3516: $request->print(<<ENDPICK);
1.26 albertel 3517: </table>
3518: <input type="hidden" name="nfields" value="$i" />
3519: <input type="hidden" name="keyfields" value="$keyfields" />
3520: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3521: </form>
3522: ENDPICK
3523: }
3524:
1.283 albertel 3525: sub checkforfile_js {
1.86 ng 3526: my $result =<<CSVFORMJS;
3527: <script type="text/javascript" language="javascript">
3528: function checkUpload(formname) {
3529: if (formname.upfile.value == "") {
3530: alert("Please use the browse button to select a file from your local directory.");
3531: return false;
3532: }
3533: formname.submit();
3534: }
3535: </script>
3536: CSVFORMJS
1.283 albertel 3537: return $result;
3538: }
3539:
3540: sub upcsvScores_form {
3541: my ($request) = shift;
1.324 albertel 3542: my ($symb)=&get_symb($request);
1.283 albertel 3543: if (!$symb) {return '';}
3544: my $result=&checkforfile_js();
1.257 albertel 3545: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3546: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3547: $result.=$table;
1.326 albertel 3548: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3549: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.370 www 3550: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource').
1.86 ng 3551: '.</b></td></tr>'."\n";
3552: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3553: my $upload=&mt("Upload Scores");
1.86 ng 3554: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3555: my $ignore=&mt('Ignore First Line');
1.399.2.2! albertel 3556: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3557: $result.=<<ENDUPFORM;
1.106 albertel 3558: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3559: <input type="hidden" name="symb" value="$symb" />
3560: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3561: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3562: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3563: $upfile_select
1.370 www 3564: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3565: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3566: </form>
3567: ENDUPFORM
1.370 www 3568: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3569: &mt("How do I create a CSV file from a spreadsheet"))
3570: .'</td></tr></table>'."\n";
1.86 ng 3571: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3572: $result.=&show_grading_menu_form($symb);
1.86 ng 3573: return $result;
3574: }
3575:
3576:
1.26 albertel 3577: sub csvuploadmap {
1.41 ng 3578: my ($request)= @_;
1.324 albertel 3579: my ($symb)=&get_symb($request);
1.41 ng 3580: if (!$symb) {return '';}
1.72 ng 3581:
1.41 ng 3582: my $datatoken;
1.257 albertel 3583: if (!$env{'form.datatoken'}) {
1.41 ng 3584: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3585: } else {
1.257 albertel 3586: $datatoken=$env{'form.datatoken'};
1.41 ng 3587: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3588: }
1.41 ng 3589: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3590: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3591: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3592: my ($i,$keyfields);
3593: if (@records) {
1.324 albertel 3594: my @fields=&csvupload_fields($symb);
1.45 ng 3595:
1.257 albertel 3596: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3597: &Apache::loncommon::csv_print_samples($request,\@records);
3598: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3599: \@fields);
3600: foreach (@fields) { $keyfields.=$_->[0].','; }
3601: chop($keyfields);
3602: } else {
3603: unshift(@fields,['none','']);
3604: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3605: \@fields);
1.311 banghart 3606: foreach my $rec (@records) {
3607: my %temp = &Apache::loncommon::record_sep($rec);
3608: if (%temp) {
3609: $keyfields=join(',',sort(keys(%temp)));
3610: last;
3611: }
3612: }
1.41 ng 3613: }
3614: }
3615: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3616: $request->print(&show_grading_menu_form($symb));
1.72 ng 3617:
1.41 ng 3618: return '';
1.27 albertel 3619: }
3620:
1.246 albertel 3621: sub csvuploadoptions {
1.41 ng 3622: my ($request)= @_;
1.324 albertel 3623: my ($symb)=&get_symb($request);
1.257 albertel 3624: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3625: my $ignore=&mt('Ignore First Line');
3626: $request->print(<<ENDPICK);
3627: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3628: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 3629: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3630: <!--
1.246 albertel 3631: <p>
3632: <label>
3633: <input type="checkbox" name="show_full_results" />
3634: Show a table of all changes
3635: </label>
3636: </p>
1.302 albertel 3637: -->
1.246 albertel 3638: <p>
3639: <label>
3640: <input type="checkbox" name="overwite_scores" checked="checked" />
3641: Overwrite any existing score
3642: </label>
3643: </p>
3644: ENDPICK
3645: my %fields=&get_fields();
3646: if (!defined($fields{'domain'})) {
1.257 albertel 3647: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3648: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3649: }
1.257 albertel 3650: foreach my $key (sort(keys(%env))) {
1.246 albertel 3651: if ($key !~ /^form\.(.*)$/) { next; }
3652: my $cleankey=$1;
3653: if ($cleankey eq 'command') { next; }
3654: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3655: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3656: }
3657: # FIXME do a check for any duplicated user ids...
3658: # FIXME do a check for any invalid user ids?...
1.290 albertel 3659: $request->print('<input type="submit" value="Assign Grades" /><br />
3660: <hr /></form>'."\n");
1.324 albertel 3661: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3662: return '';
3663: }
3664:
3665: sub get_fields {
3666: my %fields;
1.257 albertel 3667: my @keyfields = split(/\,/,$env{'form.keyfields'});
3668: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3669: if ($env{'form.upfile_associate'} eq 'reverse') {
3670: if ($env{'form.f'.$i} ne 'none') {
3671: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3672: }
3673: } else {
1.257 albertel 3674: if ($env{'form.f'.$i} ne 'none') {
3675: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3676: }
3677: }
1.27 albertel 3678: }
1.246 albertel 3679: return %fields;
3680: }
3681:
3682: sub csvuploadassign {
3683: my ($request)= @_;
1.324 albertel 3684: my ($symb)=&get_symb($request);
1.246 albertel 3685: if (!$symb) {return '';}
1.345 bowersj2 3686: my $error_msg = '';
1.246 albertel 3687: &Apache::loncommon::load_tmp_file($request);
3688: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3689: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3690: my %fields=&get_fields();
1.41 ng 3691: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3692: my $courseid=$env{'request.course.id'};
1.97 albertel 3693: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3694: my @notallowed;
1.41 ng 3695: my @skipped;
3696: my $countdone=0;
3697: foreach my $grade (@gradedata) {
3698: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3699: my $domain;
3700: if ($entries{$fields{'domain'}}) {
3701: $domain=$entries{$fields{'domain'}};
3702: } else {
1.257 albertel 3703: $domain=$env{'form.default_domain'};
1.246 albertel 3704: }
1.243 albertel 3705: $domain=~s/\s//g;
1.41 ng 3706: my $username=$entries{$fields{'username'}};
1.160 albertel 3707: $username=~s/\s//g;
1.243 albertel 3708: if (!$username) {
3709: my $id=$entries{$fields{'ID'}};
1.247 albertel 3710: $id=~s/\s//g;
1.243 albertel 3711: my %ids=&Apache::lonnet::idget($domain,$id);
3712: $username=$ids{$id};
3713: }
1.41 ng 3714: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3715: my $id=$entries{$fields{'ID'}};
3716: $id=~s/\s//g;
3717: if ($id) {
3718: push(@skipped,"$id:$domain");
3719: } else {
3720: push(@skipped,"$username:$domain");
3721: }
1.41 ng 3722: next;
3723: }
1.108 albertel 3724: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3725: if (!&canmodify($usec)) {
3726: push(@notallowed,"$username:$domain");
3727: next;
3728: }
1.244 albertel 3729: my %points;
1.41 ng 3730: my %grades;
3731: foreach my $dest (keys(%fields)) {
1.244 albertel 3732: if ($dest eq 'ID' || $dest eq 'username' ||
3733: $dest eq 'domain') { next; }
3734: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3735: if ($dest=~/stores_(.*)_points/) {
3736: my $part=$1;
3737: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3738: $symb,$domain,$username);
1.345 bowersj2 3739: if ($wgt) {
3740: $entries{$fields{$dest}}=~s/\s//g;
3741: my $pcr=$entries{$fields{$dest}} / $wgt;
3742: my $award='correct_by_override';
3743: $grades{"resource.$part.awarded"}=$pcr;
3744: $grades{"resource.$part.solved"}=$award;
3745: $points{$part}=1;
3746: } else {
3747: $error_msg = "<br />" .
3748: &mt("Some point values were assigned"
3749: ." for problems with a weight "
3750: ."of zero. These values were "
3751: ."ignored.");
3752: }
1.244 albertel 3753: } else {
3754: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
3755: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
3756: my $store_key=$dest;
3757: $store_key=~s/^stores/resource/;
3758: $store_key=~s/_/\./g;
3759: $grades{$store_key}=$entries{$fields{$dest}};
3760: }
1.41 ng 3761: }
1.398 albertel 3762: if (! %grades) { push(@skipped,"$username:$domain no data to save"); }
1.257 albertel 3763: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
1.244 albertel 3764: # &Apache::lonnet::logthis(" storing ".(join('-',%grades)));
1.302 albertel 3765: my $result=&Apache::lonnet::cstore(\%grades,$symb,
3766: $env{'request.course.id'},
3767: $domain,$username);
3768: if ($result eq 'ok') {
3769: $request->print('.');
3770: } else {
3771: $request->print("<p>
1.398 albertel 3772: <span class=\"LC_error\">
3773: Failed to save student $username:$domain.
3774: Message when trying to save was ($result)
3775: </span>
1.302 albertel 3776: </p>" );
3777: }
1.41 ng 3778: $request->rflush();
3779: $countdone++;
3780: }
1.398 albertel 3781: $request->print("<br />Saved $countdone students\n");
1.41 ng 3782: if (@skipped) {
1.398 albertel 3783: $request->print('<p><h4><b>Skipped Students</b></h4></p>');
1.106 albertel 3784: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
3785: }
3786: if (@notallowed) {
1.398 albertel 3787: $request->print('<p><span class="LC_error">Students Not Allowed to Modify</span></p>');
1.106 albertel 3788: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 3789: }
1.106 albertel 3790: $request->print("<br />\n");
1.324 albertel 3791: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 3792: return $error_msg;
1.26 albertel 3793: }
1.44 ng 3794: #------------- end of section for handling csv file upload ---------
3795: #
3796: #-------------------------------------------------------------------
3797: #
1.122 ng 3798: #-------------- Next few routines handle grading by page/sequence
1.72 ng 3799: #
3800: #--- Select a page/sequence and a student to grade
1.68 ng 3801: sub pickStudentPage {
3802: my ($request) = shift;
3803:
3804: $request->print(<<LISTJAVASCRIPT);
3805: <script type="text/javascript" language="javascript">
3806:
3807: function checkPickOne(formname) {
1.76 ng 3808: if (radioSelection(formname.student) == null) {
1.68 ng 3809: alert("Please select the student you wish to grade.");
3810: return;
3811: }
1.125 ng 3812: ptr = pullDownSelection(formname.selectpage);
3813: formname.page.value = formname["page"+ptr].value;
3814: formname.title.value = formname["title"+ptr].value;
1.68 ng 3815: formname.submit();
3816: }
3817:
3818: </script>
3819: LISTJAVASCRIPT
1.118 ng 3820: &commonJSfunctions($request);
1.324 albertel 3821: my ($symb) = &get_symb($request);
1.257 albertel 3822: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3823: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3824: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 3825:
1.398 albertel 3826: my $result='<h3><span class="LC_info"> '.
3827: 'Manual Grading by Page or Sequence</span></h3>';
1.68 ng 3828:
1.80 ng 3829: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 3830: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 3831: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 3832: my ($curpage) =&Apache::lonnet::decode_symb($symb);
3833: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
3834: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 3835: my $ctr=0;
1.68 ng 3836: foreach (@$titles) {
3837: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 3838: $result.='<option value="'.$ctr.'" '.
1.71 ng 3839: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
3840: '>'.$showtitle.'</option>'."\n";
1.70 ng 3841: $ctr++;
1.68 ng 3842: }
1.326 albertel 3843: $result.= '</select>'."<br />\n";
1.70 ng 3844: $ctr=0;
3845: foreach (@$titles) {
3846: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3847: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
3848: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
3849: $ctr++;
3850: }
1.72 ng 3851: $result.='<input type="hidden" name="page" />'."\n".
3852: '<input type="hidden" name="title" />'."\n";
1.68 ng 3853:
1.288 albertel 3854: $result.=' <b>View Problems Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
3855: '<label><input type="radio" name="vProb" value="yes" /> yes </label>'."<br />\n";
1.72 ng 3856:
1.71 ng 3857: $result.=' <b>Submission Details: </b>'.
1.288 albertel 3858: '<label><input type="radio" name="lastSub" value="none" /> none</label>'."\n".
3859: '<label><input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions</label>'."\n".
3860: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n";
1.72 ng 3861:
1.68 ng 3862: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.257 albertel 3863: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.72 ng 3864: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.399.2.2! albertel 3865: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 3866: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 3867:
1.382 albertel 3868: $result.=' <b>'.&mt('Use CODE:').' </b>'.
3869: '<input type="text" name="CODE" value="" /><br />'."\n";
3870:
1.80 ng 3871: $result.=' <input type="button" '.
1.126 ng 3872: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 3873:
1.68 ng 3874: $request->print($result);
3875:
1.326 albertel 3876: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br />'.
1.68 ng 3877: '<table border="0"><tr><td bgcolor="#777777">'.
3878: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 3879: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3880: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 3881: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3882: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 3883:
1.76 ng 3884: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 3885: my $ptr = 1;
1.294 albertel 3886: foreach my $student (sort
3887: {
3888: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3889: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3890: }
3891: return $a cmp $b;
3892: } (keys(%$fullname))) {
1.68 ng 3893: my ($uname,$udom) = split(/:/,$student);
1.126 ng 3894: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
3895: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 3896: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
3897: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.126 ng 3898: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 3899: $ptr++;
3900: }
1.381 albertel 3901: $studentTable.='</td><td> </td><td> </td></tr>' if ($ptr%2 == 0);
3902: $studentTable.='</table></td></tr></table>'."\n";
1.126 ng 3903: $studentTable.='<input type="button" '.
3904: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 3905:
1.324 albertel 3906: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 3907: $request->print($studentTable);
3908:
3909: return '';
3910: }
3911:
3912: sub getSymbMap {
1.74 albertel 3913: my ($request) = @_;
1.132 bowersj2 3914: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 3915:
3916: my %symbx = ();
3917: my @titles = ();
1.117 bowersj2 3918: my $minder = 0;
3919:
3920: # Gather every sequence that has problems.
1.240 albertel 3921: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
3922: 1,0,1);
1.117 bowersj2 3923: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 3924: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 3925: my $title = $minder.'.'.
3926: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
3927: push(@titles, $title); # minder in case two titles are identical
3928: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 3929: $minder++;
1.241 albertel 3930: }
1.68 ng 3931: }
3932: return \@titles,\%symbx;
3933: }
3934:
1.72 ng 3935: #
3936: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 3937: sub displayPage {
3938: my ($request) = shift;
3939:
1.324 albertel 3940: my ($symb) = &get_symb($request);
1.257 albertel 3941: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3942: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3943: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3944: my $pageTitle = $env{'form.page'};
1.103 albertel 3945: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3946: my ($uname,$udom) = split(/:/,$env{'form.student'});
3947: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 3948:
3949: #need to make sure we have the correct data for later EXT calls,
3950: #thus invalidate the cache
3951: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3952: $env{'course.'.$env{'request.course.id'}.'.num'},
3953: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3954: &Apache::lonnet::clear_EXT_cache_status();
3955:
1.103 albertel 3956: if (!&canview($usec)) {
1.398 albertel 3957: $request->print('<span class="LC_warning">Unable to view requested student.('.$env{'form.student'}.')</span>');
1.324 albertel 3958: $request->print(&show_grading_menu_form($symb));
1.103 albertel 3959: return;
3960: }
1.398 albertel 3961: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.257 albertel 3962: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom).
1.129 ng 3963: '</h3>'."\n";
1.382 albertel 3964: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
3965: $result.='<h3> CODE: '.$env{'form.CODE'}.'</h3>'."\n";
3966: } else {
3967: delete($env{'form.CODE'});
3968: }
1.71 ng 3969: &sub_page_js($request);
3970: $request->print($result);
3971:
1.132 bowersj2 3972: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3973: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 3974: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3975: if (!$map) {
1.398 albertel 3976: $request->print('<span class="LC_warning">Unable to view requested sequence. ('.$resUrl.')</span>');
1.324 albertel 3977: $request->print(&show_grading_menu_form($symb));
1.288 albertel 3978: return;
3979: }
1.68 ng 3980: my $iterator = $navmap->getIterator($map->map_start(),
3981: $map->map_finish());
3982:
1.71 ng 3983: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3984: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 3985: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
3986: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 3987: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 3988: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.399.2.2! albertel 3989: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 3990: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 3991: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 3992:
1.382 albertel 3993: if (defined($env{'form.CODE'})) {
3994: $studentTable.=
3995: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
3996: }
1.381 albertel 3997: my $checkIcon = '<img alt="'.&mt('Check Mark').
3998: '" src="'.$request->dir_config('lonIconsURL').
1.71 ng 3999: '/check.gif" height="16" border="0" />';
4000:
1.118 ng 4001: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
4002: ' symbol.'."\n".
1.71 ng 4003: '<table border="0"><tr><td bgcolor="#777777">'.
4004: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 4005: '<td align="center"><b> Prob. </b></td>'.
1.257 albertel 4006: '<td><b> '.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 4007:
1.329 albertel 4008: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4009: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4010: $iterator->next(); # skip the first BEGIN_MAP
4011: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4012: while ($depth > 0) {
1.68 ng 4013: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4014: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4015:
1.385 albertel 4016: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4017: my $parts = $curRes->parts();
1.68 ng 4018: my $title = $curRes->compTitle();
1.71 ng 4019: my $symbx = $curRes->symb();
1.196 albertel 4020: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4021: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4022: $studentTable.='<td valign="top">';
1.382 albertel 4023: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4024: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4025: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4026: undef,'both',\%form);
1.71 ng 4027: } else {
1.382 albertel 4028: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4029: $companswer =~ s|<form(.*?)>||g;
4030: $companswer =~ s|</form>||g;
1.71 ng 4031: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4032: # $companswer =~ s/$1/ /ms;
1.326 albertel 4033: # $request->print('match='.$1."<br />\n");
1.71 ng 4034: # }
1.116 ng 4035: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.326 albertel 4036: $studentTable.=' <b>'.$title.'</b> <br /> <b>Correct answer:</b><br />'.$companswer;
1.71 ng 4037: }
4038:
1.257 albertel 4039: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4040:
1.257 albertel 4041: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4042: if ($record{'version'} eq '') {
1.398 albertel 4043: $studentTable.='<br /> <span class="LC_warning">No recorded submission for this problem</span><br />';
1.71 ng 4044: } else {
1.116 ng 4045: my %responseType = ();
4046: foreach my $partid (@{$parts}) {
1.147 albertel 4047: my @responseIds =$curRes->responseIds($partid);
4048: my @responseType =$curRes->responseType($partid);
4049: my %responseIds;
4050: for (my $i=0;$i<=$#responseIds;$i++) {
4051: $responseIds{$responseIds[$i]}=$responseType[$i];
4052: }
4053: $responseType{$partid} = \%responseIds;
1.116 ng 4054: }
1.148 albertel 4055: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4056:
1.71 ng 4057: }
1.257 albertel 4058: } elsif ($env{'form.lastSub'} eq 'all') {
4059: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4060: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4061: $env{'request.course.id'},
1.71 ng 4062: '','.submission');
4063:
4064: }
1.103 albertel 4065: if (&canmodify($usec)) {
4066: foreach my $partid (@{$parts}) {
4067: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4068: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4069: $question++;
4070: }
1.196 albertel 4071: $prob++;
1.71 ng 4072: }
4073: $studentTable.='</td></tr>';
1.68 ng 4074:
1.103 albertel 4075: }
1.68 ng 4076: $curRes = $iterator->next();
4077: }
4078:
1.381 albertel 4079: $studentTable.='</table></td></tr></table>'."\n".
1.125 ng 4080: '<input type="button" value="Save" '.
1.381 albertel 4081: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
1.71 ng 4082: '</form>'."\n";
1.324 albertel 4083: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4084: $request->print($studentTable);
4085:
4086: return '';
1.119 ng 4087: }
4088:
4089: sub displaySubByDates {
1.148 albertel 4090: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4091: my $isCODE=0;
1.335 albertel 4092: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4093: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.119 ng 4094: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
4095: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
4096: '<td><b>Date/Time</b></td>'.
1.224 albertel 4097: ($isCODE?'<td><b>CODE</b></td>':'').
1.119 ng 4098: '<td><b>Submission</b></td>'.
4099: '<td><b>Status </b></td></tr>';
4100: my ($version);
4101: my %mark;
1.148 albertel 4102: my %orders;
1.119 ng 4103: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4104: if (!exists($$record{'1:timestamp'})) {
1.398 albertel 4105: return '<br /> <span class="LC_warning">Nothing submitted - no attempts</span><br />';
1.147 albertel 4106: }
1.335 albertel 4107:
4108: my $interaction;
1.119 ng 4109: for ($version=1;$version<=$$record{'version'};$version++) {
4110: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
1.335 albertel 4111: if (exists($$record{$version.':resource.0.version'})) {
4112: $interaction = $$record{$version.':resource.0.version'};
4113: }
4114:
4115: my $where = ($isTask ? "$version:resource.$interaction"
4116: : "$version:resource");
4117: #&Apache::lonnet::logthis(" got $where");
1.119 ng 4118: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
1.224 albertel 4119: if ($isCODE) {
4120: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4121: }
1.119 ng 4122: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4123: my @displaySub = ();
4124: foreach my $partid (@{$parts}) {
1.335 albertel 4125: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4126: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4127:
4128:
1.122 ng 4129: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4130: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4131: foreach my $matchKey (@matchKey) {
1.198 albertel 4132: if (exists($$record{$version.':'.$matchKey}) &&
4133: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4134:
4135: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4136: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
4137: #&Apache::lonnet::logthis("match $matchKey $responseId (".$$record{$version.':'.$matchKey});
1.207 albertel 4138: $displaySub[0].='<b>Part:</b> '.$display_part.' ';
1.398 albertel 4139: $displaySub[0].='<span class="LC_internal_info">(ID '.
4140: $responseId.')</span> <b>';
1.335 albertel 4141: if ($$record{"$where.$partid.tries"} eq '') {
1.147 albertel 4142: $displaySub[0].='Trial not counted';
4143: } else {
4144: $displaySub[0].='Trial '.
1.335 albertel 4145: $$record{"$where.$partid.tries"};
1.147 albertel 4146: }
1.335 albertel 4147: my $responseType=($isTask ? 'Task'
4148: : $responseType->{$partid}->{$responseId});
1.148 albertel 4149: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4150: if (!exists($orders{$partid}->{$responseId})) {
4151: $orders{$partid}->{$responseId}=
4152: &get_order($partid,$responseId,$symb,$uname,$udom);
4153: }
1.147 albertel 4154: $displaySub[0].='</b> '.
1.336 albertel 4155: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4156: }
4157: }
1.335 albertel 4158: if (exists($$record{"$where.$partid.checkedin"})) {
4159: $displaySub[1].='Checked in by '.
4160: $$record{"$where.$partid.checkedin"}.' into slot '.
4161: $$record{"$where.$partid.checkedin.slot"}.
4162: '<br />';
4163: }
4164: if (exists $$record{"$where.$partid.award"}) {
1.207 albertel 4165: $displaySub[1].='<b>Part:</b> '.$display_part.' '.
1.335 albertel 4166: lc($$record{"$where.$partid.award"}).' '.
4167: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4168: '<br />';
4169: }
1.335 albertel 4170: if (exists $$record{"$where.$partid.regrader"}) {
4171: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4172: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4173: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4174: $displaySub[2].=
4175: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4176: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4177: }
4178: }
4179: # needed because old essay regrader has not parts info
4180: if (exists $$record{"$version:resource.regrader"}) {
4181: $displaySub[2].=$$record{"$version:resource.regrader"};
4182: }
4183: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4184: if ($displaySub[2]) {
4185: $studentTable.='Manually graded by '.$displaySub[2];
4186: }
1.382 albertel 4187: $studentTable.=' </td></tr>';
1.147 albertel 4188:
1.119 ng 4189: }
4190: $studentTable.='</table></td></tr></table>';
4191: return $studentTable;
1.71 ng 4192: }
4193:
4194: sub updateGradeByPage {
4195: my ($request) = shift;
4196:
1.257 albertel 4197: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4198: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4199: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4200: my $pageTitle = $env{'form.page'};
1.103 albertel 4201: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4202: my ($uname,$udom) = split(/:/,$env{'form.student'});
4203: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4204: if (!&canmodify($usec)) {
1.398 albertel 4205: $request->print('<span class="LC_warning">Unable to modify requested student.('.$env{'form.student'}.'</span>');
1.324 albertel 4206: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4207: return;
4208: }
1.398 albertel 4209: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.257 albertel 4210: $result.='<h3> Student: '.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4211: '</h3>'."\n";
1.70 ng 4212:
1.68 ng 4213: $request->print($result);
4214:
1.132 bowersj2 4215: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4216: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4217: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4218: if (!$map) {
1.398 albertel 4219: $request->print('<span class="LC_warning">Unable to grade requested sequence. ('.$resUrl.')</span>');
1.324 albertel 4220: my ($symb)=&get_symb($request);
4221: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4222: return;
4223: }
1.71 ng 4224: my $iterator = $navmap->getIterator($map->map_start(),
4225: $map->map_finish());
1.70 ng 4226:
1.71 ng 4227: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 4228: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 4229: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 4230: '<td><b> Title </b></td>'.
4231: '<td><b> Previous Score </b></td>'.
4232: '<td><b> New Score </b></td></tr>';
4233:
4234: $iterator->next(); # skip the first BEGIN_MAP
4235: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4236: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4237: while ($depth > 0) {
1.71 ng 4238: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4239: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4240:
1.385 albertel 4241: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4242: my $parts = $curRes->parts();
1.71 ng 4243: my $title = $curRes->compTitle();
4244: my $symbx = $curRes->symb();
1.196 albertel 4245: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4246: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4247: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4248:
4249: my %newrecord=();
4250: my @displayPts=();
1.269 raeburn 4251: my %aggregate = ();
4252: my $aggregateflag = 0;
1.71 ng 4253: foreach my $partid (@{$parts}) {
1.257 albertel 4254: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4255: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4256:
1.257 albertel 4257: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4258: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4259: my $partial = $newpts/$wgt;
4260: my $score;
4261: if ($partial > 0) {
4262: $score = 'correct_by_override';
1.125 ng 4263: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4264: $score = 'incorrect_by_override';
4265: }
1.257 albertel 4266: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4267: if ($dropMenu eq 'excused') {
1.71 ng 4268: $partial = '';
4269: $score = 'excused';
1.125 ng 4270: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4271: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4272: $newrecord{'resource.'.$partid.'.tries'} = 0;
4273: $newrecord{'resource.'.$partid.'.solved'} = '';
4274: $newrecord{'resource.'.$partid.'.award'} = '';
4275: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4276: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4277: $changeflag++;
4278: $newpts = '';
1.269 raeburn 4279:
4280: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4281: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4282: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4283: if ($aggtries > 0) {
4284: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4285: $aggregateflag = 1;
4286: }
1.71 ng 4287: }
1.324 albertel 4288: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4289: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.207 albertel 4290: $displayPts[0].=' <b>Part:</b> '.$display_part.' = '.
1.71 ng 4291: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4292: ' <br />';
1.207 albertel 4293: $displayPts[1].=' <b>Part:</b> '.$display_part.' = '.
1.125 ng 4294: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4295: ' <br />';
1.71 ng 4296: $question++;
1.380 albertel 4297: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4298:
1.71 ng 4299: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4300: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4301: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4302: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4303:
4304: $changeflag++;
4305: }
4306: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4307: my %record =
4308: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4309: $udom,$uname);
4310:
4311: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4312: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4313: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4314: $newrecord{'resource.CODE'} = '';
4315: }
1.257 albertel 4316: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4317: $udom,$uname);
1.382 albertel 4318: %record = &Apache::lonnet::restore($symbx,
4319: $env{'request.course.id'},
4320: $udom,$uname);
1.380 albertel 4321: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4322: $cdom,$cnum,$udom,$uname);
1.71 ng 4323: }
1.380 albertel 4324:
1.269 raeburn 4325: if ($aggregateflag) {
4326: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4327: $env{'course.'.$env{'request.course.id'}.'.domain'},
4328: $env{'course.'.$env{'request.course.id'}.'.num'});
4329: }
1.125 ng 4330:
1.71 ng 4331: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4332: '<td valign="top">'.$displayPts[1].'</td>'.
4333: '</tr>';
1.68 ng 4334:
1.196 albertel 4335: $prob++;
1.68 ng 4336: }
1.71 ng 4337: $curRes = $iterator->next();
1.68 ng 4338: }
1.98 albertel 4339:
1.71 ng 4340: $studentTable.='</td></tr></table></td></tr></table>';
1.324 albertel 4341: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.76 ng 4342: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
4343: 'The scores were changed for '.
4344: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
4345: $request->print($grademsg.$studentTable);
1.68 ng 4346:
1.70 ng 4347: return '';
4348: }
4349:
1.72 ng 4350: #-------- end of section for handling grading by page/sequence ---------
4351: #
4352: #-------------------------------------------------------------------
4353:
1.75 albertel 4354: #--------------------Scantron Grading-----------------------------------
4355: #
4356: #------ start of section for handling grading by page/sequence ---------
4357:
1.81 albertel 4358: sub defaultFormData {
1.324 albertel 4359: my ($symb)=@_;
1.81 albertel 4360: return '
1.399.2.2! albertel 4361: <input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4362: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4363: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4364: }
4365:
1.75 albertel 4366: sub getSequenceDropDown {
4367: my ($request,$symb)=@_;
4368: my $result='<select name="selectpage">'."\n";
4369: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 4370: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4371: my $ctr=0;
4372: foreach (@$titles) {
4373: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4374: $result.='<option value="'.$$symbx{$_}.'" '.
4375: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
4376: '>'.$showtitle.'</option>'."\n";
4377: $ctr++;
4378: }
4379: $result.= '</select>';
4380: return $result;
4381: }
4382:
1.202 albertel 4383: sub scantron_filenames {
1.257 albertel 4384: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4385: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 4386: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.359 www 4387: &propath($cdom,$cname));
1.202 albertel 4388: my @possiblenames;
1.201 albertel 4389: foreach my $filename (sort(@files)) {
1.157 albertel 4390: ($filename)=split(/&/,$filename);
4391: if ($filename!~/^scantron_orig_/) { next ; }
4392: $filename=~s/^scantron_orig_//;
1.202 albertel 4393: push(@possiblenames,$filename);
4394: }
4395: return @possiblenames;
4396: }
4397:
4398: sub scantron_uploads {
1.209 ng 4399: my ($file2grade) = @_;
1.202 albertel 4400: my $result= '<select name="scantron_selectfile">';
4401: $result.="<option></option>";
4402: foreach my $filename (sort(&scantron_filenames())) {
1.209 ng 4403: $result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n";
1.81 albertel 4404: }
4405: $result.="</select>";
4406: return $result;
4407: }
4408:
1.82 albertel 4409: sub scantron_scantab {
4410: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4411: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4412: $result.='<option></option>'."\n";
1.82 albertel 4413: foreach my $line (<$fh>) {
4414: my ($name,$descrip)=split(/:/,$line);
4415: if ($name =~ /^\#/) { next; }
4416: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4417: }
4418: $result.='</select>'."\n";
4419:
4420: return $result;
4421: }
4422:
1.186 albertel 4423: sub scantron_CODElist {
1.257 albertel 4424: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4425: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4426: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4427: my $namechoice='<option></option>';
1.225 albertel 4428: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4429: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4430: if ($name =~ /^type\0/) { next; }
1.186 albertel 4431: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4432: }
4433: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4434: return $namechoice;
4435: }
4436:
4437: sub scantron_CODEunique {
1.381 albertel 4438: my $result='<span style="white-space: nowrap;">
1.272 albertel 4439: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4440: value="yes" checked="checked" /> Yes </label>
1.381 albertel 4441: </span>
4442: <span style="white-space: nowrap;">
1.272 albertel 4443: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4444: value="no" /> No </label>
1.381 albertel 4445: </span>';
1.186 albertel 4446: return $result;
4447: }
4448:
1.75 albertel 4449: sub scantron_selectphase {
1.209 ng 4450: my ($r,$file2grade) = @_;
1.324 albertel 4451: my ($symb)=&get_symb($r);
1.75 albertel 4452: if (!$symb) {return '';}
4453: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.324 albertel 4454: my $default_form_data=&defaultFormData($symb);
4455: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 4456: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4457: my $format_selector=&scantron_scantab();
1.186 albertel 4458: my $CODE_selector=&scantron_CODElist();
4459: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4460: my $result;
1.157 albertel 4461: #FIXME allow instructor to be able to download the scantron file
4462: # and to upload it,
1.75 albertel 4463: $result.= <<SCANTRONFORM;
1.162 albertel 4464: <table width="100%" border="0">
1.75 albertel 4465: <tr>
1.226 albertel 4466: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
1.75 albertel 4467: <td bgcolor="#777777">
1.203 albertel 4468: <input type="hidden" name="command" value="scantron_warning" />
1.162 albertel 4469: $default_form_data
1.75 albertel 4470: <table width="100%" border="0">
4471: <tr bgcolor="#e6ffff">
1.174 albertel 4472: <td colspan="2">
4473: <b>Specify file and which Folder/Sequence to grade</b>
1.75 albertel 4474: </td>
4475: </tr>
4476: <tr bgcolor="#ffffe6">
1.174 albertel 4477: <td> Sequence to grade: </td><td> $sequence_selector </td>
1.75 albertel 4478: </tr>
4479: <tr bgcolor="#ffffe6">
1.174 albertel 4480: <td> Filename of scoring office file: </td><td> $file_selector </td>
1.75 albertel 4481: </tr>
1.82 albertel 4482: <tr bgcolor="#ffffe6">
1.174 albertel 4483: <td> Format of data file: </td><td> $format_selector </td>
1.82 albertel 4484: </tr>
1.157 albertel 4485: <tr bgcolor="#ffffe6">
1.186 albertel 4486: <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
4487: </tr>
4488: <tr bgcolor="#ffffe6">
4489: <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
4490: </tr>
4491: <tr bgcolor="#ffffe6">
1.187 albertel 4492: <td> Options: </td>
4493: <td>
1.272 albertel 4494: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
1.331 albertel 4495: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label> <br />
4496: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> Skip hidden resources when grading</label>
1.187 albertel 4497: </td>
4498: </tr>
4499: <tr bgcolor="#ffffe6">
1.174 albertel 4500: <td colspan="2">
1.265 www 4501: <input type="submit" value="Grading: Validate Scantron Records" />
1.162 albertel 4502: </td>
4503: </tr>
4504: </table>
1.226 albertel 4505: </td>
4506: </form>
1.162 albertel 4507: </tr>
4508: SCANTRONFORM
4509:
4510: $r->print($result);
4511:
1.257 albertel 4512: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
4513: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 4514:
4515: $r->print(<<SCANTRONFORM);
4516: <tr>
4517: <td bgcolor="#777777">
4518: <table width="100%" border="0">
4519: <tr bgcolor="#e6ffff">
4520: <td>
1.174 albertel 4521: <b>Specify a Scantron data file to upload.</b>
1.162 albertel 4522: </td>
4523: </tr>
4524: <tr bgcolor="#ffffe6">
4525: <td>
4526: SCANTRONFORM
1.324 albertel 4527: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 4528: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4529: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.174 albertel 4530: $r->print(<<UPLOAD);
4531: <script type="text/javascript" language="javascript">
4532: function checkUpload(formname) {
4533: if (formname.upfile.value == "") {
4534: alert("Please use the browse button to select a file from your local directory.");
4535: return false;
4536: }
4537: formname.submit();
4538: }
4539: </script>
4540:
4541: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
4542: $default_form_data
4543: <input name='courseid' type='hidden' value='$cnum' />
4544: <input name='domainid' type='hidden' value='$cdom' />
4545: <input name='command' value='scantronupload_save' type='hidden' />
4546: File to upload:<input type="file" name="upfile" size="50" />
4547: <br />
4548: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
4549: </form>
4550: UPLOAD
1.162 albertel 4551:
4552: $r->print(<<SCANTRONFORM);
4553: </td>
4554: </tr>
1.75 albertel 4555: </table>
4556: </td>
4557: </tr>
1.162 albertel 4558: SCANTRONFORM
4559: }
1.187 albertel 4560: $r->print(<<SCANTRONFORM);
4561: <tr>
1.226 albertel 4562: <form action='/adm/grades' name='scantron_download'>
4563: <td bgcolor="#777777">
1.379 albertel 4564: $default_form_data
1.187 albertel 4565: <input type="hidden" name="command" value="scantron_download" />
4566: <table width="100%" border="0">
4567: <tr bgcolor="#e6ffff">
4568: <td colspan="2">
4569: <b>Download a scoring office file</b>
4570: </td>
4571: </tr>
4572: <tr bgcolor="#ffffe6">
4573: <td> Filename of scoring office file: </td><td> $file_selector </td>
4574: </tr>
4575: <tr bgcolor="#ffffe6">
4576: <td colspan="2">
1.293 www 4577: <input type="submit" value="Download: Show List of Associated Files" />
1.187 albertel 4578: </td>
4579: </tr>
4580: </table>
1.226 albertel 4581: </td>
4582: </form>
1.187 albertel 4583: </tr>
4584: SCANTRONFORM
1.162 albertel 4585:
4586: $r->print(<<SCANTRONFORM);
1.75 albertel 4587: </table>
1.81 albertel 4588: $grading_menu_button
1.75 albertel 4589: SCANTRONFORM
4590:
1.162 albertel 4591: return
1.75 albertel 4592: }
4593:
1.82 albertel 4594: sub get_scantron_config {
4595: my ($which) = @_;
4596: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4597: my %config;
1.157 albertel 4598: #FIXME probably should move to XML it has already gotten a bit much now
1.82 albertel 4599: foreach my $line (<$fh>) {
4600: my ($name,$descrip)=split(/:/,$line);
4601: if ($name ne $which ) { next; }
4602: chomp($line);
4603: my @config=split(/:/,$line);
4604: $config{'name'}=$config[0];
4605: $config{'description'}=$config[1];
4606: $config{'CODElocation'}=$config[2];
4607: $config{'CODEstart'}=$config[3];
4608: $config{'CODElength'}=$config[4];
4609: $config{'IDstart'}=$config[5];
4610: $config{'IDlength'}=$config[6];
4611: $config{'Qstart'}=$config[7];
4612: $config{'Qlength'}=$config[8];
4613: $config{'Qoff'}=$config[9];
4614: $config{'Qon'}=$config[10];
1.157 albertel 4615: $config{'PaperID'}=$config[11];
4616: $config{'PaperIDlength'}=$config[12];
4617: $config{'FirstName'}=$config[13];
4618: $config{'FirstNamelength'}=$config[14];
4619: $config{'LastName'}=$config[15];
4620: $config{'LastNamelength'}=$config[16];
1.82 albertel 4621: last;
4622: }
4623: return %config;
4624: }
4625:
4626: sub username_to_idmap {
4627: my ($classlist)= @_;
4628: my %idmap;
4629: foreach my $student (keys(%$classlist)) {
4630: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
4631: $student;
4632: }
4633: return %idmap;
4634: }
4635:
1.157 albertel 4636: sub scantron_fixup_scanline {
4637: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
4638: if ($field eq 'ID') {
4639: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 4640: return ($line,1,'New value too large');
1.157 albertel 4641: }
4642: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
4643: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
4644: $args->{'newid'});
4645: }
4646: substr($line,$$scantron_config{'IDstart'}-1,
4647: $$scantron_config{'IDlength'})=$args->{'newid'};
4648: if ($args->{'newid'}=~/^\s*$/) {
4649: &scan_data($scan_data,"$whichline.user",
4650: $args->{'username'}.':'.$args->{'domain'});
4651: }
1.186 albertel 4652: } elsif ($field eq 'CODE') {
1.192 albertel 4653: if ($args->{'CODE_ignore_dup'}) {
4654: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
4655: }
4656: &scan_data($scan_data,"$whichline.useCODE",'1');
4657: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 4658: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
4659: return ($line,1,'New CODE value too large');
4660: }
4661: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
4662: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
4663: }
4664: substr($line,$$scantron_config{'CODEstart'}-1,
4665: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 4666: }
1.157 albertel 4667: } elsif ($field eq 'answer') {
4668: my $length=$scantron_config->{'Qlength'};
4669: my $off=$scantron_config->{'Qoff'};
4670: my $on=$scantron_config->{'Qon'};
4671: my $answer=${off}x$length;
4672: if ($args->{'response'} eq 'none') {
4673: &scan_data($scan_data,
4674: "$whichline.no_bubble.".$args->{'question'},'1');
4675: } else {
1.274 albertel 4676: if ($on eq 'letter') {
4677: my @alphabet=('A'..'Z');
4678: $answer=$alphabet[$args->{'response'}];
4679: } elsif ($on eq 'number') {
4680: $answer=$args->{'response'}+1;
1.389 albertel 4681: if ($answer == 10) { $answer = '0'; }
1.274 albertel 4682: } else {
4683: substr($answer,$args->{'response'},1)=$on;
4684: }
1.157 albertel 4685: &scan_data($scan_data,
4686: "$whichline.no_bubble.".$args->{'question'},undef,'1');
4687: }
4688: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
4689: substr($line,$where-1,$length)=$answer;
4690: }
4691: return $line;
4692: }
4693:
4694: sub scan_data {
4695: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 4696: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 4697: if (defined($value)) {
4698: $scan_data->{$filename.'_'.$key} = $value;
4699: }
4700: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
4701: return $scan_data->{$filename.'_'.$key};
4702: }
4703:
1.82 albertel 4704: sub scantron_parse_scanline {
1.194 albertel 4705: my ($line,$whichline,$scantron_config,$scan_data,$justHeader)=@_;
1.82 albertel 4706: my %record;
4707: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
4708: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
1.278 albertel 4709: if (!($$scantron_config{'CODElocation'} eq 0 ||
4710: $$scantron_config{'CODElocation'} eq 'none')) {
4711: if ($$scantron_config{'CODElocation'} < 0 ||
4712: $$scantron_config{'CODElocation'} eq 'letter' ||
4713: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 4714: $record{'scantron.CODE'}=substr($data,
4715: $$scantron_config{'CODEstart'}-1,
1.83 albertel 4716: $$scantron_config{'CODElength'});
1.191 albertel 4717: if (&scan_data($scan_data,"$whichline.useCODE")) {
4718: $record{'scantron.useCODE'}=1;
4719: }
1.192 albertel 4720: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
4721: $record{'scantron.CODE_ignore_dup'}=1;
4722: }
1.82 albertel 4723: } else {
4724: #FIXME interpret first N questions
4725: }
4726: }
1.83 albertel 4727: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
4728: $$scantron_config{'IDlength'});
1.157 albertel 4729: $record{'scantron.PaperID'}=
4730: substr($data,$$scantron_config{'PaperID'}-1,
4731: $$scantron_config{'PaperIDlength'});
4732: $record{'scantron.FirstName'}=
4733: substr($data,$$scantron_config{'FirstName'}-1,
4734: $$scantron_config{'FirstNamelength'});
4735: $record{'scantron.LastName'}=
4736: substr($data,$$scantron_config{'LastName'}-1,
4737: $$scantron_config{'LastNamelength'});
1.194 albertel 4738: if ($justHeader) { return \%record; }
4739:
1.82 albertel 4740: my @alphabet=('A'..'Z');
4741: my $questnum=0;
4742: while ($questions) {
4743: $questnum++;
4744: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
4745: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 4746: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.239 albertel 4747: if ($$scantron_config{'Qon'} eq 'letter') {
1.371 albertel 4748: if ($currentquest eq '?'
4749: || $currentquest eq '*') {
1.274 albertel 4750: push(@{$record{'scantron.doubleerror'}},$questnum);
4751: $record{"scantron.$questnum.answer"}='';
1.389 albertel 4752: } elsif (!defined($currentquest)
1.274 albertel 4753: || $currentquest eq $$scantron_config{'Qoff'}
4754: || $currentquest !~ /^[A-Z]$/) {
1.239 albertel 4755: $record{"scantron.$questnum.answer"}='';
4756: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4757: push(@{$record{"scantron.missingerror"}},$questnum);
4758: }
4759: } else {
4760: $record{"scantron.$questnum.answer"}=$currentquest;
4761: }
4762: } elsif ($$scantron_config{'Qon'} eq 'number') {
1.371 albertel 4763: if ($currentquest eq '?'
4764: || $currentquest eq '*') {
1.274 albertel 4765: push(@{$record{'scantron.doubleerror'}},$questnum);
4766: $record{"scantron.$questnum.answer"}='';
1.389 albertel 4767: } elsif (!defined($currentquest)
4768: || $currentquest eq $$scantron_config{'Qoff'}
4769: || $currentquest !~ /^\d$/) {
1.239 albertel 4770: $record{"scantron.$questnum.answer"}='';
4771: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4772: push(@{$record{"scantron.missingerror"}},$questnum);
4773: }
4774: } else {
1.371 albertel 4775: # wrap zero back to J
4776: if ($currentquest eq '0') {
4777: $record{"scantron.$questnum.answer"}=
4778: $alphabet[9];
4779: } else {
4780: $record{"scantron.$questnum.answer"}=
4781: $alphabet[$currentquest-1];
4782: }
1.239 albertel 4783: }
1.82 albertel 4784: } else {
1.239 albertel 4785: my @array=split($$scantron_config{'Qon'},$currentquest,-1);
4786: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
4787: $record{"scantron.$questnum.answer"}='';
4788: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4789: push(@{$record{"scantron.missingerror"}},$questnum);
4790: }
4791: } else {
4792: $record{"scantron.$questnum.answer"}=
4793: $alphabet[length($array[0])];
4794: }
4795: if (scalar(@array) gt 2) {
4796: push(@{$record{'scantron.doubleerror'}},$questnum);
4797: my @ans=@array;
4798: my $i=length($ans[0]);shift(@ans);
4799: while ($#ans) {
4800: $i+=length($ans[0])+1;
4801: $record{"scantron.$questnum.answer"}.=$alphabet[$i];
4802: shift(@ans);
4803: }
4804: }
1.82 albertel 4805: }
4806: }
1.83 albertel 4807: $record{'scantron.maxquest'}=$questnum;
4808: return \%record;
1.82 albertel 4809: }
4810:
4811: sub scantron_add_delay {
1.140 albertel 4812: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
4813: push(@$delayqueue,
4814: {'line' => $scanline, 'emsg' => $errormessage,
4815: 'ecode' => $errorcode }
4816: );
1.82 albertel 4817: }
4818:
4819: sub scantron_find_student {
1.157 albertel 4820: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 4821: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 4822: if ($scanID =~ /^\s*$/) {
4823: return &scan_data($scan_data,"$line.user");
4824: }
1.83 albertel 4825: foreach my $id (keys(%$idmap)) {
1.157 albertel 4826: if (lc($id) eq lc($scanID)) {
4827: return $$idmap{$id};
4828: }
1.83 albertel 4829: }
4830: return undef;
4831: }
4832:
4833: sub scantron_filter {
4834: my ($curres)=@_;
1.331 albertel 4835:
4836: if (ref($curres) && $curres->is_problem()) {
4837: # if the user has asked to not have either hidden
4838: # or 'randomout' controlled resources to be graded
4839: # don't include them
4840: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
4841: && $curres->randomout) {
4842: return 0;
4843: }
1.83 albertel 4844: return 1;
4845: }
4846: return 0;
1.82 albertel 4847: }
4848:
1.157 albertel 4849: sub scantron_process_corrections {
4850: my ($r) = @_;
1.257 albertel 4851: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4852: my ($scanlines,$scan_data)=&scantron_getfile();
4853: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 4854: my $which=$env{'form.scantron_line'};
1.200 albertel 4855: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 4856: my ($skip,$err,$errmsg);
1.257 albertel 4857: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 4858: $skip=1;
1.257 albertel 4859: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
4860: my $newstudent=$env{'form.scantron_username'}.':'.
4861: $env{'form.scantron_domain'};
1.157 albertel 4862: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
4863: ($line,$err,$errmsg)=
4864: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
4865: 'ID',{'newid'=>$newid,
1.257 albertel 4866: 'username'=>$env{'form.scantron_username'},
4867: 'domain'=>$env{'form.scantron_domain'}});
4868: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
4869: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 4870: my $newCODE;
1.192 albertel 4871: my %args;
1.190 albertel 4872: if ($resolution eq 'use_unfound') {
1.191 albertel 4873: $newCODE='use_unfound';
1.190 albertel 4874: } elsif ($resolution eq 'use_found') {
1.257 albertel 4875: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 4876: } elsif ($resolution eq 'use_typed') {
1.257 albertel 4877: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 4878: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 4879: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 4880: }
1.257 albertel 4881: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 4882: $args{'CODE_ignore_dup'}=1;
4883: }
4884: $args{'CODE'}=$newCODE;
1.186 albertel 4885: ($line,$err,$errmsg)=
4886: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 4887: 'CODE',\%args);
1.257 albertel 4888: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
4889: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 4890: ($line,$err,$errmsg)=
4891: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
4892: $which,'answer',
4893: { 'question'=>$question,
1.257 albertel 4894: 'response'=>$env{"form.scantron_correct_Q_$question"}});
1.157 albertel 4895: if ($err) { last; }
4896: }
4897: }
4898: if ($err) {
1.398 albertel 4899: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 4900: } else {
1.200 albertel 4901: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 4902: &scantron_putfile($scanlines,$scan_data);
4903: }
4904: }
4905:
1.200 albertel 4906: sub reset_skipping_status {
4907: my ($scanlines,$scan_data)=&scantron_getfile();
4908: &scan_data($scan_data,'remember_skipping',undef,1);
4909: &scantron_putfile(undef,$scan_data);
4910: }
4911:
1.376 albertel 4912: sub start_skipping {
1.200 albertel 4913: my ($scan_data,$i)=@_;
4914: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 4915: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
4916: $remembered{$i}=2;
4917: } else {
4918: $remembered{$i}=1;
4919: }
1.200 albertel 4920: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
4921: }
4922:
4923: sub should_be_skipped {
1.376 albertel 4924: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 4925: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 4926: # not redoing old skips
1.376 albertel 4927: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 4928: return 0;
4929: }
4930: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 4931:
4932: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
4933: return 0;
4934: }
1.200 albertel 4935: return 1;
4936: }
4937:
4938: sub remember_current_skipped {
4939: my ($scanlines,$scan_data)=&scantron_getfile();
4940: my %to_remember;
4941: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4942: if ($scanlines->{'skipped'}[$i]) {
4943: $to_remember{$i}=1;
4944: }
4945: }
1.376 albertel 4946:
1.200 albertel 4947: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
4948: &scantron_putfile(undef,$scan_data);
4949: }
4950:
4951: sub check_for_error {
4952: my ($r,$result)=@_;
4953: if ($result ne 'ok' && $result ne 'not_found' ) {
4954: $r->print("An error occured ($result) when trying to Remove the existing corrections.");
4955: }
4956: }
1.157 albertel 4957:
1.203 albertel 4958: sub scantron_warning_screen {
4959: my ($button_text)=@_;
1.257 albertel 4960: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 4961: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 4962: my $CODElist;
1.284 albertel 4963: if ($scantron_config{'CODElocation'} &&
4964: $scantron_config{'CODEstart'} &&
4965: $scantron_config{'CODElength'}) {
4966: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 4967: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 4968: $CODElist=
4969: '<tr><td><b>List of CODES to validate against:</b></td><td><tt>'.
1.373 albertel 4970: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 4971: }
1.203 albertel 4972: return (<<STUFF);
4973: <p>
1.398 albertel 4974: <span class="LC_warning">Please double check the information
4975: below before clicking on '$button_text'</span>
1.203 albertel 4976: </p>
4977: <table>
1.284 albertel 4978: <tr><td><b>Sequence to be Graded:</b></td><td>$title</td></tr>
1.257 albertel 4979: <tr><td><b>Data File that will be used:</b></td><td><tt>$env{'form.scantron_selectfile'}</tt></td></tr>
1.284 albertel 4980: $CODElist
1.203 albertel 4981: </table>
4982: <br />
4983: <p> If this information is correct, please click on '$button_text'.</p>
4984: <p> If something is incorrect, please click the 'Grading Menu' button to start over.</p>
4985:
4986: <br />
4987: STUFF
4988: }
4989:
4990: sub scantron_do_warning {
4991: my ($r)=@_;
1.324 albertel 4992: my ($symb)=&get_symb($r);
1.203 albertel 4993: if (!$symb) {return '';}
1.324 albertel 4994: my $default_form_data=&defaultFormData($symb);
1.203 albertel 4995: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 4996: if ( $env{'form.selectpage'} eq '' ||
4997: $env{'form.scantron_selectfile'} eq '' ||
4998: $env{'form.scantron_format'} eq '' ) {
1.237 albertel 4999: $r->print("<p>You have forgetten to specify some information. Please go Back and try again.</p>");
1.257 albertel 5000: if ( $env{'form.selectpage'} eq '') {
1.398 albertel 5001: $r->print('<p><span class="LC_error">You have not selected a Sequence to grade</span></p>');
1.237 albertel 5002: }
1.257 albertel 5003: if ( $env{'form.scantron_selectfile'} eq '') {
1.398 albertel 5004: $r->print('<p><span class="LC_error">You have not selected a file that contains the student\'s response data.</span></p>');
1.237 albertel 5005: }
1.257 albertel 5006: if ( $env{'form.scantron_format'} eq '') {
1.398 albertel 5007: $r->print('<p><span class="LC_error">You have not selected a the format of the student\'s response data.</span></p>');
1.237 albertel 5008: }
5009: } else {
1.265 www 5010: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.237 albertel 5011: $r->print(<<STUFF);
1.203 albertel 5012: $warning
1.265 www 5013: <input type="submit" name="submit" value="Grading: Validate Records" />
1.203 albertel 5014: <input type="hidden" name="command" value="scantron_validate" />
5015: STUFF
1.237 albertel 5016: }
1.352 albertel 5017: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 5018: return '';
5019: }
5020:
5021: sub scantron_form_start {
5022: my ($max_bubble)=@_;
5023: my $result= <<SCANTRONFORM;
5024: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 5025: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
5026: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
5027: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 5028: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 5029: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
5030: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
5031: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
5032: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 5033: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 5034: SCANTRONFORM
5035: return $result;
5036: }
5037:
1.157 albertel 5038: sub scantron_validate_file {
5039: my ($r) = @_;
1.324 albertel 5040: my ($symb)=&get_symb($r);
1.157 albertel 5041: if (!$symb) {return '';}
1.324 albertel 5042: my $default_form_data=&defaultFormData($symb);
1.200 albertel 5043:
5044: # do the detection of only doing skipped records first befroe we delete
5045: # them when doing the corrections reset
1.257 albertel 5046: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 5047: &reset_skipping_status();
5048: }
1.257 albertel 5049: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 5050: &remember_current_skipped();
1.257 albertel 5051: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 5052: }
5053:
1.257 albertel 5054: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 5055: &check_for_error($r,&scantron_remove_file('corrected'));
5056: &check_for_error($r,&scantron_remove_file('skipped'));
5057: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 5058: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 5059: }
1.200 albertel 5060:
1.257 albertel 5061: if ($env{'form.scantron_corrections'}) {
1.157 albertel 5062: &scantron_process_corrections($r);
5063: }
1.191 albertel 5064: $r->print("<p>Gathering neccessary info.</p>");$r->rflush();
1.157 albertel 5065: #get the student pick code ready
5066: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 5067: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 5068: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 5069: $r->print($result);
5070:
1.334 albertel 5071: my @validate_phases=( 'sequence',
5072: 'ID',
1.157 albertel 5073: 'CODE',
5074: 'doublebubble',
5075: 'missingbubbles');
1.257 albertel 5076: if (!$env{'form.validatepass'}) {
5077: $env{'form.validatepass'} = 0;
1.157 albertel 5078: }
1.257 albertel 5079: my $currentphase=$env{'form.validatepass'};
1.157 albertel 5080:
5081: my $stop=0;
5082: while (!$stop && $currentphase < scalar(@validate_phases)) {
5083: $r->print("<p> Validating ".$validate_phases[$currentphase]."</p>");
5084: $r->rflush();
5085: my $which="scantron_validate_".$validate_phases[$currentphase];
5086: {
5087: no strict 'refs';
5088: ($stop,$currentphase)=&$which($r,$currentphase);
5089: }
5090: }
5091: if (!$stop) {
1.203 albertel 5092: my $warning=&scantron_warning_screen('Start Grading');
5093: $r->print(<<STUFF);
5094: Validation process complete.<br />
5095: $warning
5096: <input type="submit" name="submit" value="Start Grading" />
5097: <input type="hidden" name="command" value="scantron_process" />
5098: STUFF
5099:
1.157 albertel 5100: } else {
5101: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
5102: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
5103: }
5104: if ($stop) {
1.334 albertel 5105: if ($validate_phases[$currentphase] eq 'sequence') {
5106: $r->print('<input type="submit" name="submit" value="Ignore -> " />');
5107: $r->print(' this error <br />');
5108:
5109: $r->print(" <p>Or click the 'Grading Menu' button to start over.</p>");
5110: } else {
5111: $r->print('<input type="submit" name="submit" value="Continue ->" />');
5112: $r->print(' using corrected info <br />');
5113: $r->print("<input type='submit' value='Skip' name='scantron_skip_record' />");
5114: $r->print(" this scanline saving it for later.");
5115: }
1.157 albertel 5116: }
1.352 albertel 5117: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 5118: return '';
5119: }
5120:
1.200 albertel 5121: sub scantron_remove_file {
1.192 albertel 5122: my ($which)=@_;
1.257 albertel 5123: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5124: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5125: my $file='scantron_';
1.200 albertel 5126: if ($which eq 'corrected' || $which eq 'skipped') {
5127: $file.=$which.'_';
1.192 albertel 5128: } else {
5129: return 'refused';
5130: }
1.257 albertel 5131: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 5132: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
5133: }
5134:
5135: sub scantron_remove_scan_data {
1.257 albertel 5136: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5137: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5138: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
5139: my @todelete;
1.257 albertel 5140: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 5141: foreach my $key (@keys) {
5142: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 5143: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 5144: $key=~/remember_skipping/) {
5145: next;
5146: }
1.192 albertel 5147: push(@todelete,$key);
5148: }
5149: }
1.200 albertel 5150: my $result;
1.192 albertel 5151: if (@todelete) {
1.200 albertel 5152: $result=&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
1.192 albertel 5153: }
5154: return $result;
5155: }
5156:
1.157 albertel 5157: sub scantron_getfile {
1.200 albertel 5158: #FIXME really would prefer a scantron directory
1.257 albertel 5159: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5160: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 5161: my $lines;
5162: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5163: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 5164: my %scanlines;
5165: $scanlines{'orig'}=[(split("\n",$lines,-1))];
5166: my $temp=$scanlines{'orig'};
5167: $scanlines{'count'}=$#$temp;
5168:
5169: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5170: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 5171: if ($lines eq '-1') {
5172: $scanlines{'corrected'}=[];
5173: } else {
5174: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
5175: }
5176: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5177: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 5178: if ($lines eq '-1') {
5179: $scanlines{'skipped'}=[];
5180: } else {
5181: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
5182: }
1.175 albertel 5183: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 5184: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
5185: my %scan_data = @tmp;
5186: return (\%scanlines,\%scan_data);
5187: }
5188:
5189: sub lonnet_putfile {
5190: my ($contents,$filename)=@_;
1.257 albertel 5191: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5192: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5193: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 5194: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 5195:
5196: }
5197:
5198: sub scantron_putfile {
5199: my ($scanlines,$scan_data) = @_;
1.200 albertel 5200: #FIXME really would prefer a scantron directory
1.257 albertel 5201: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5202: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 5203: if ($scanlines) {
5204: my $prefix='scantron_';
1.157 albertel 5205: # no need to update orig, shouldn't change
5206: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 5207: # $env{'form.scantron_selectfile'});
1.200 albertel 5208: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
5209: $prefix.'corrected_'.
1.257 albertel 5210: $env{'form.scantron_selectfile'});
1.200 albertel 5211: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
5212: $prefix.'skipped_'.
1.257 albertel 5213: $env{'form.scantron_selectfile'});
1.200 albertel 5214: }
1.175 albertel 5215: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 5216: }
5217:
5218: sub scantron_get_line {
1.200 albertel 5219: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 5220: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
5221: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 5222: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
5223: return $scanlines->{'orig'}[$i];
5224: }
5225:
1.200 albertel 5226: sub get_todo_count {
5227: my ($scanlines,$scan_data)=@_;
5228: my $count=0;
5229: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5230: my $line=&scantron_get_line($scanlines,$scan_data,$i);
5231: if ($line=~/^[\s\cz]*$/) { next; }
5232: $count++;
5233: }
5234: return $count;
5235: }
5236:
1.157 albertel 5237: sub scantron_put_line {
1.200 albertel 5238: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 5239: if ($skip) {
5240: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 5241: &start_skipping($scan_data,$i);
1.157 albertel 5242: return;
5243: }
5244: $scanlines->{'corrected'}[$i]=$newline;
5245: }
5246:
1.376 albertel 5247: sub scantron_clear_skip {
5248: my ($scanlines,$scan_data,$i)=@_;
5249: if (exists($scanlines->{'skipped'}[$i])) {
5250: undef($scanlines->{'skipped'}[$i]);
5251: return 1;
5252: }
5253: return 0;
5254: }
5255:
1.334 albertel 5256: sub scantron_filter_not_exam {
5257: my ($curres)=@_;
5258:
5259: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
5260: # if the user has asked to not have either hidden
5261: # or 'randomout' controlled resources to be graded
5262: # don't include them
5263: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5264: && $curres->randomout) {
5265: return 0;
5266: }
5267: return 1;
5268: }
5269: return 0;
5270: }
5271:
5272: sub scantron_validate_sequence {
5273: my ($r,$currentphase) = @_;
5274:
5275: my $navmap=Apache::lonnavmaps::navmap->new();
5276: my (undef,undef,$sequence)=
5277: &Apache::lonnet::decode_symb($env{'form.selectpage'});
5278:
5279: my $map=$navmap->getResourceByUrl($sequence);
5280:
5281: $r->print('<input type="hidden" name="validate_sequence_exam"
5282: value="ignore" />');
5283: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
5284: my @resources=
5285: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
5286: if (@resources) {
1.357 banghart 5287: $r->print("<p>".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>");
1.334 albertel 5288: return (1,$currentphase);
5289: }
5290: }
5291:
5292: return (0,$currentphase+1);
5293: }
5294:
1.157 albertel 5295: sub scantron_validate_ID {
5296: my ($r,$currentphase) = @_;
5297:
5298: #get student info
5299: my $classlist=&Apache::loncoursedata::get_classlist();
5300: my %idmap=&username_to_idmap($classlist);
5301:
5302: #get scantron line setup
1.257 albertel 5303: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5304: my ($scanlines,$scan_data)=&scantron_getfile();
5305:
5306: my %found=('ids'=>{},'usernames'=>{});
5307: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5308: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5309: if ($line=~/^[\s\cz]*$/) { next; }
5310: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5311: $scan_data);
5312: my $id=$$scan_record{'scantron.ID'};
5313: my $found;
5314: foreach my $checkid (keys(%idmap)) {
5315: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
5316: }
5317: if ($found) {
5318: my $username=$idmap{$found};
5319: if ($found{'ids'}{$found}) {
5320: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5321: $line,'duplicateID',$found);
1.194 albertel 5322: return(1,$currentphase);
1.157 albertel 5323: } elsif ($found{'usernames'}{$username}) {
5324: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5325: $line,'duplicateID',$username);
1.194 albertel 5326: return(1,$currentphase);
1.157 albertel 5327: }
1.186 albertel 5328: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 5329: $found{'ids'}{$found}++;
5330: $found{'usernames'}{$username}++;
5331: } else {
5332: if ($id =~ /^\s*$/) {
1.158 albertel 5333: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 5334: if (defined($username) && $found{'usernames'}{$username}) {
5335: &scantron_get_correction($r,$i,$scan_record,
5336: \%scantron_config,
5337: $line,'duplicateID',$username);
1.194 albertel 5338: return(1,$currentphase);
1.157 albertel 5339: } elsif (!defined($username)) {
5340: &scantron_get_correction($r,$i,$scan_record,
5341: \%scantron_config,
5342: $line,'incorrectID');
1.194 albertel 5343: return(1,$currentphase);
1.157 albertel 5344: }
5345: $found{'usernames'}{$username}++;
5346: } else {
5347: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5348: $line,'incorrectID');
1.194 albertel 5349: return(1,$currentphase);
1.157 albertel 5350: }
5351: }
5352: }
5353:
5354: return (0,$currentphase+1);
5355: }
5356:
5357: sub scantron_get_correction {
5358: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
5359:
5360: #FIXME in the case of a duplicated ID the previous line, probaly need
5361: #to show both the current line and the previous one and allow skipping
5362: #the previous one or the current one
5363:
1.161 albertel 5364: $r->print("<p><b>An error was detected ($error)</b>");
1.333 albertel 5365: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.157 albertel 5366: $r->print(" for PaperID <tt>".
5367: $$scan_record{'scantron.PaperID'}."</tt> \n");
5368: } else {
5369: $r->print(" in scanline $i <pre>".
5370: $line."</pre> \n");
5371: }
1.242 albertel 5372: my $message="<p>The ID on the form is <tt>".
5373: $$scan_record{'scantron.ID'}."</tt><br />\n".
5374: "The name on the paper is ".
5375: $$scan_record{'scantron.LastName'}.",".
5376: $$scan_record{'scantron.FirstName'}."</p>";
5377:
1.157 albertel 5378: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
5379: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
5380: if ($error =~ /ID$/) {
1.186 albertel 5381: if ($error eq 'incorrectID') {
1.157 albertel 5382: $r->print("The encoded ID is not in the classlist</p>\n");
5383: } elsif ($error eq 'duplicateID') {
5384: $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
5385: }
1.242 albertel 5386: $r->print($message);
1.157 albertel 5387: $r->print("<p>How should I handle this? <br /> \n");
5388: $r->print("\n<ul><li> ");
5389: #FIXME it would be nice if this sent back the user ID and
5390: #could do partial userID matches
5391: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
5392: 'scantron_username','scantron_domain'));
5393: $r->print(": <input type='text' name='scantron_username' value='' />");
5394: $r->print("\n@".
1.257 albertel 5395: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 5396:
5397: $r->print('</li>');
1.186 albertel 5398: } elsif ($error =~ /CODE$/) {
5399: if ($error eq 'incorrectCODE') {
1.187 albertel 5400: $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
1.186 albertel 5401: } elsif ($error eq 'duplicateCODE') {
1.194 albertel 5402: $r->print("</p><p>The encoded CODE has also been used by a previous paper ".join(', ',@{$arg}).", and CODEs are supposed to be unique</p>\n");
1.186 albertel 5403: }
1.224 albertel 5404: $r->print("<p>The CODE on the form is <tt>'".
5405: $$scan_record{'scantron.CODE'}."'</tt><br />\n");
1.242 albertel 5406: $r->print($message);
1.186 albertel 5407: $r->print("<p>How should I handle this? <br /> \n");
1.187 albertel 5408: $r->print("\n<br /> ");
1.194 albertel 5409: my $i=0;
1.273 albertel 5410: if ($error eq 'incorrectCODE'
5411: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 5412: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 5413: if ($closest > 0) {
5414: foreach my $testcode (@{$closest}) {
5415: my $checked='';
5416: if (!$i) { $checked=' checked="on" '; }
5417: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_closest_$i' $checked /> Use the similar CODE <b><tt>".$testcode."</tt></b> instead.</label><input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
5418: $r->print("\n<br />");
5419: $i++;
5420: }
1.194 albertel 5421: }
5422: }
1.273 albertel 5423: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
5424: my $checked; if (!$i) { $checked=' checked="on" '; }
5425: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_unfound' $checked /> Use the CODE <b><tt>".$$scan_record{'scantron.CODE'}."</tt></b> that is was on the paper, ignoring the error.</label>");
5426: $r->print("\n<br />");
5427: }
1.194 albertel 5428:
1.188 albertel 5429: $r->print(<<ENDSCRIPT);
5430: <script type="text/javascript">
5431: function change_radio(field) {
1.190 albertel 5432: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 5433: var i;
5434: for (i=0;i<slct.length;i++) {
5435: if (slct[i].value==field) { slct[i].checked=true; }
5436: }
5437: }
5438: </script>
5439: ENDSCRIPT
1.187 albertel 5440: my $href="/adm/pickcode?".
1.359 www 5441: "form=".&escape("scantronupload").
5442: "&scantron_format=".&escape($env{'form.scantron_format'}).
5443: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
5444: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
5445: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 5446: if ($env{'form.scantron_CODElist'} =~ /\S/) {
5447: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_found' /> <a target='_blank' href='$href'>Select</a> a CODE from the list of all CODEs and use it.</label> Selected CODE is <input readonly='true' type='text' size='8' name='scantron_CODE_selectedvalue' onfocus=\"javascript:change_radio('use_found')\" onchange=\"javascript:change_radio('use_found')\" />");
5448: $r->print("\n<br />");
5449: }
1.272 albertel 5450: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_typed' /> Use </label><input type='text' size='8' name='scantron_CODE_newvalue' onfocus=\"javascript:change_radio('use_typed')\" onkeypress=\"javascript:change_radio('use_typed')\" /> as the CODE.");
1.187 albertel 5451: $r->print("\n<br /><br />");
1.157 albertel 5452: } elsif ($error eq 'doublebubble') {
5453: $r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
5454: $r->print('<input type="hidden" name="scantron_questions" value="'.
5455: join(',',@{$arg}).'" />');
1.242 albertel 5456: $r->print($message);
1.157 albertel 5457: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5458: foreach my $question (@{$arg}) {
5459: my $selected=$$scan_record{"scantron.$question.answer"};
5460: &scantron_bubble_selector($r,$scan_config,$question,split('',$selected));
5461: }
5462: } elsif ($error eq 'missingbubble') {
5463: $r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
1.242 albertel 5464: $r->print($message);
1.157 albertel 5465: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5466: $r->print("Some questions have no scanned bubbles\n");
5467: $r->print('<input type="hidden" name="scantron_questions" value="'.
5468: join(',',@{$arg}).'" />');
5469: foreach my $question (@{$arg}) {
5470: my $selected=$$scan_record{"scantron.$question.answer"};
5471: &scantron_bubble_selector($r,$scan_config,$question);
5472: }
5473: } else {
5474: $r->print("\n<ul>");
5475: }
5476: $r->print("\n</li></ul>");
5477:
5478: }
5479:
5480: sub scantron_bubble_selector {
5481: my ($r,$scan_config,$quest,@selected)=@_;
5482: my $max=$$scan_config{'Qlength'};
1.274 albertel 5483:
5484: my $scmode=$$scan_config{'Qon'};
5485: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
5486:
1.157 albertel 5487: my @alphabet=('A'..'Z');
5488: $r->print("<table border='1'><tr><td rowspan='2'>$quest</td>");
5489: for (my $i=0;$i<$max+1;$i++) {
1.274 albertel 5490: $r->print("\n".'<td align="center">');
1.157 albertel 5491: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
5492: else { $r->print(' '); }
5493: $r->print('</td>');
5494: }
1.274 albertel 5495: $r->print('</tr><tr>');
1.157 albertel 5496: for (my $i=0;$i<$max;$i++) {
1.274 albertel 5497: $r->print("\n".
5498: '<td><label><input type="radio" name="scantron_correct_Q_'.
1.272 albertel 5499: $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
1.157 albertel 5500: }
1.272 albertel 5501: $r->print('<td><label><input type="radio" name="scantron_correct_Q_'.
5502: $quest.'" value="none" /> No bubble </label></td>');
1.157 albertel 5503: $r->print('</tr></table>');
5504: }
5505:
1.194 albertel 5506: sub num_matches {
5507: my ($orig,$code) = @_;
5508: my @code=split(//,$code);
5509: my @orig=split(//,$orig);
5510: my $same=0;
5511: for (my $i=0;$i<scalar(@code);$i++) {
5512: if ($code[$i] eq $orig[$i]) { $same++; }
5513: }
5514: return $same;
5515: }
5516:
5517: sub scantron_get_closely_matching_CODEs {
5518: my ($allcodes,$CODE)=@_;
5519: my @CODEs;
5520: foreach my $testcode (sort(keys(%{$allcodes}))) {
5521: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
5522: }
5523:
5524: return ($#CODEs,$CODEs[-1]);
5525: }
5526:
5527: sub get_codes {
1.280 foxr 5528: my ($old_name, $cdom, $cnum) = @_;
5529: if (!$old_name) {
5530: $old_name=$env{'form.scantron_CODElist'};
5531: }
5532: if (!$cdom) {
5533: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
5534: }
5535: if (!$cnum) {
5536: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
5537: }
1.278 albertel 5538: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
5539: $cdom,$cnum);
5540: my %allcodes;
5541: if ($result{"type\0$old_name"} eq 'number') {
5542: %allcodes=map {($_,1)} split(',',$result{$old_name});
5543: } else {
5544: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
5545: }
1.194 albertel 5546: return %allcodes;
5547: }
5548:
1.157 albertel 5549: sub scantron_validate_CODE {
5550: my ($r,$currentphase) = @_;
1.257 albertel 5551: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 5552: if ($scantron_config{'CODElocation'} &&
5553: $scantron_config{'CODEstart'} &&
5554: $scantron_config{'CODElength'}) {
1.257 albertel 5555: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 5556: &FIXME_blow_up()
5557: }
5558: } else {
5559: return (0,$currentphase+1);
5560: }
5561:
5562: my %usedCODEs;
5563:
1.194 albertel 5564: my %allcodes=&get_codes();
1.186 albertel 5565:
5566: my ($scanlines,$scan_data)=&scantron_getfile();
5567: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5568: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 5569: if ($line=~/^[\s\cz]*$/) { next; }
5570: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5571: $scan_data);
5572: my $CODE=$$scan_record{'scantron.CODE'};
5573: my $error=0;
1.224 albertel 5574: if (!&Apache::lonnet::validCODE($CODE)) {
5575: &scantron_get_correction($r,$i,$scan_record,
5576: \%scantron_config,
5577: $line,'incorrectCODE',\%allcodes);
5578: return(1,$currentphase);
5579: }
1.221 albertel 5580: if (%allcodes && !exists($allcodes{$CODE})
5581: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 5582: &scantron_get_correction($r,$i,$scan_record,
5583: \%scantron_config,
1.194 albertel 5584: $line,'incorrectCODE',\%allcodes);
5585: return(1,$currentphase);
1.186 albertel 5586: }
1.214 albertel 5587: if (exists($usedCODEs{$CODE})
1.257 albertel 5588: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 5589: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 5590: &scantron_get_correction($r,$i,$scan_record,
5591: \%scantron_config,
1.194 albertel 5592: $line,'duplicateCODE',$usedCODEs{$CODE});
5593: return(1,$currentphase);
1.186 albertel 5594: }
1.194 albertel 5595: push (@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 5596: }
1.157 albertel 5597: return (0,$currentphase+1);
5598: }
5599:
5600: sub scantron_validate_doublebubble {
5601: my ($r,$currentphase) = @_;
5602: #get student info
5603: my $classlist=&Apache::loncoursedata::get_classlist();
5604: my %idmap=&username_to_idmap($classlist);
5605:
5606: #get scantron line setup
1.257 albertel 5607: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5608: my ($scanlines,$scan_data)=&scantron_getfile();
5609: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5610: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5611: if ($line=~/^[\s\cz]*$/) { next; }
5612: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5613: $scan_data);
5614: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
5615: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
5616: 'doublebubble',
5617: $$scan_record{'scantron.doubleerror'});
5618: return (1,$currentphase);
5619: }
5620: return (0,$currentphase+1);
5621: }
5622:
1.330 albertel 5623: sub scantron_get_maxbubble {
1.257 albertel 5624: if (defined($env{'form.scantron_maxbubble'}) &&
5625: $env{'form.scantron_maxbubble'}) {
5626: return $env{'form.scantron_maxbubble'};
1.191 albertel 5627: }
1.330 albertel 5628:
1.191 albertel 5629: my $navmap=Apache::lonnavmaps::navmap->new();
5630: my (undef,undef,$sequence)=
1.257 albertel 5631: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 5632:
1.191 albertel 5633: my $map=$navmap->getResourceByUrl($sequence);
5634: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 5635:
5636: &Apache::lonxml::clear_problem_counter();
5637:
1.191 albertel 5638: foreach my $resource (@resources) {
1.330 albertel 5639: my $result=&Apache::lonnet::ssi($resource->src(),
5640: ('symb' => $resource->symb()));
1.191 albertel 5641: }
5642: &Apache::lonnet::delenv('scantron\.');
1.330 albertel 5643: $env{'form.scantron_maxbubble'} =
5644: &Apache::lonxml::get_problem_counter()-1;
5645:
1.257 albertel 5646: return $env{'form.scantron_maxbubble'};
1.191 albertel 5647: }
5648:
1.157 albertel 5649: sub scantron_validate_missingbubbles {
5650: my ($r,$currentphase) = @_;
5651: #get student info
5652: my $classlist=&Apache::loncoursedata::get_classlist();
5653: my %idmap=&username_to_idmap($classlist);
5654:
5655: #get scantron line setup
1.257 albertel 5656: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5657: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 5658: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 5659: if (!$max_bubble) { $max_bubble=2**31; }
5660: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5661: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5662: if ($line=~/^[\s\cz]*$/) { next; }
5663: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5664: $scan_data);
5665: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
5666: my @to_correct;
5667: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
5668: if ($missing > $max_bubble) { next; }
5669: push(@to_correct,$missing);
5670: }
5671: if (@to_correct) {
5672: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5673: $line,'missingbubble',\@to_correct);
5674: return (1,$currentphase);
5675: }
5676:
5677: }
5678: return (0,$currentphase+1);
5679: }
5680:
1.82 albertel 5681: sub scantron_process_students {
1.75 albertel 5682: my ($r) = @_;
1.257 albertel 5683: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 5684: my ($symb)=&get_symb($r);
1.81 albertel 5685: if (!$symb) {return '';}
1.324 albertel 5686: my $default_form_data=&defaultFormData($symb);
1.82 albertel 5687:
1.257 albertel 5688: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5689: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 5690: my $classlist=&Apache::loncoursedata::get_classlist();
5691: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 5692: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 5693: my $map=$navmap->getResourceByUrl($sequence);
5694: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 5695: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 5696: my $result= <<SCANTRONFORM;
1.81 albertel 5697: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
5698: <input type="hidden" name="command" value="scantron_configphase" />
5699: $default_form_data
5700: SCANTRONFORM
1.82 albertel 5701: $r->print($result);
5702:
5703: my @delayqueue;
1.140 albertel 5704: my %completedstudents;
5705:
1.200 albertel 5706: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 5707: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 5708: 'Scantron Progress',$count,
1.195 albertel 5709: 'inline',undef,'scantronupload');
1.140 albertel 5710: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
5711: 'Processing first student');
5712: my $start=&Time::HiRes::time();
1.158 albertel 5713: my $i=-1;
1.200 albertel 5714: my ($uname,$udom,$started);
1.157 albertel 5715: while ($i<$scanlines->{'count'}) {
5716: ($uname,$udom)=('','');
5717: $i++;
1.200 albertel 5718: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5719: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 5720: if ($started) {
5721: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
5722: 'last student');
5723: }
5724: $started=1;
1.157 albertel 5725: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5726: $scan_data);
5727: unless ($uname=&scantron_find_student($scan_record,$scan_data,
5728: \%idmap,$i)) {
5729: &scantron_add_delay(\@delayqueue,$line,
5730: 'Unable to find a student that matches',1);
5731: next;
5732: }
5733: if (exists $completedstudents{$uname}) {
5734: &scantron_add_delay(\@delayqueue,$line,
5735: 'Student '.$uname.' has multiple sheets',2);
5736: next;
5737: }
5738: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 5739:
5740: &Apache::lonxml::clear_problem_counter();
1.157 albertel 5741: &Apache::lonnet::appenv(%$scan_record);
1.376 albertel 5742:
5743: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
5744: &scantron_putfile($scanlines,$scan_data);
5745: }
1.161 albertel 5746:
5747: my $i=0;
1.83 albertel 5748: foreach my $resource (@resources) {
1.85 albertel 5749: $i++;
1.193 albertel 5750: my %form=('submitted' =>'scantron',
5751: 'grade_target' =>'grade',
5752: 'grade_username'=>$uname,
5753: 'grade_domain' =>$udom,
1.257 albertel 5754: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 5755: 'grade_symb' =>$resource->symb());
1.383 albertel 5756: if (exists($scan_record->{'scantron.CODE'})
5757: &&
5758: &Apache::lonnet::validCODE($scan_record->{'scantron.CODE'})) {
1.193 albertel 5759: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 5760: } else {
5761: $form{'CODE'}='';
1.193 albertel 5762: }
5763: my $result=&Apache::lonnet::ssi($resource->src(),%form);
1.227 albertel 5764: if ($result ne '') {
5765: &Apache::lonnet::logthis("scantron grading error -> $result");
1.257 albertel 5766: &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src());
1.227 albertel 5767: }
1.213 albertel 5768: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 5769: }
1.140 albertel 5770: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 5771: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 5772: } continue {
1.330 albertel 5773: &Apache::lonxml::clear_problem_counter();
1.83 albertel 5774: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 5775: }
1.140 albertel 5776: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.172 albertel 5777: # my $lasttime = &Time::HiRes::time()-$start;
5778: # $r->print("<p>took $lasttime</p>");
1.140 albertel 5779:
1.200 albertel 5780: $r->print("</form>");
1.324 albertel 5781: $r->print(&show_grading_menu_form($symb));
1.157 albertel 5782: return '';
1.75 albertel 5783: }
1.157 albertel 5784:
5785: sub scantron_upload_scantron_data {
5786: my ($r)=@_;
1.257 albertel 5787: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 5788: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 5789: 'domainid',
5790: 'coursename');
1.257 albertel 5791: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 5792: 'domainid');
1.324 albertel 5793: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.157 albertel 5794: $r->print(<<UPLOAD);
5795: <script type="text/javascript" language="javascript">
5796: function checkUpload(formname) {
5797: if (formname.upfile.value == "") {
5798: alert("Please use the browse button to select a file from your local directory.");
5799: return false;
5800: }
5801: formname.submit();
5802: }
5803: </script>
5804:
5805: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
1.162 albertel 5806: $default_form_data
1.181 albertel 5807: <table>
5808: <tr><td>$select_link </td></tr>
5809: <tr><td>Course ID: </td><td><input name='courseid' type='text' /> </td></tr>
5810: <tr><td>Course Name: </td><td><input name='coursename' type='text' /></td></tr>
5811: <tr><td>Domain: </td><td>$domsel </td></tr>
5812: <tr><td>File to upload:</td><td><input type="file" name="upfile" size="50" /></td></tr>
5813: </table>
1.157 albertel 5814: <input name='command' value='scantronupload_save' type='hidden' />
5815: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
5816: </form>
5817: UPLOAD
5818: return '';
5819: }
5820:
5821: sub scantron_upload_scantron_data_save {
5822: my($r)=@_;
1.324 albertel 5823: my ($symb)=&get_symb($r,1);
1.182 albertel 5824: my $doanotherupload=
5825: '<br /><form action="/adm/grades" method="post">'."\n".
5826: '<input type="hidden" name="command" value="scantronupload" />'."\n".
5827: '<input type="submit" name="submit" value="Do Another Upload" />'."\n".
5828: '</form>'."\n";
1.257 albertel 5829: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 5830: !&Apache::lonnet::allowed('usc',
1.257 albertel 5831: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.162 albertel 5832: $r->print("You are not allowed to upload Scantron data to the requested course.<br />");
1.182 albertel 5833: if ($symb) {
1.324 albertel 5834: $r->print(&show_grading_menu_form($symb));
1.182 albertel 5835: } else {
5836: $r->print($doanotherupload);
5837: }
1.162 albertel 5838: return '';
5839: }
1.257 albertel 5840: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.211 ng 5841: $r->print("Doing upload to ".$coursedata{'description'}." <br />");
1.257 albertel 5842: my $fname=$env{'form.upfile.filename'};
1.157 albertel 5843: #FIXME
5844: #copied from lonnet::userfileupload()
5845: #make that function able to target a specified course
5846: # Replace Windows backslashes by forward slashes
5847: $fname=~s/\\/\//g;
5848: # Get rid of everything but the actual filename
5849: $fname=~s/^.*\/([^\/]+)$/$1/;
5850: # Replace spaces by underscores
5851: $fname=~s/\s+/\_/g;
5852: # Replace all other weird characters by nothing
5853: $fname=~s/[^\w\.\-]//g;
5854: # See if there is anything left
5855: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 5856: my $uploadedfile=$fname;
1.157 albertel 5857: $fname='scantron_orig_'.$fname;
1.257 albertel 5858: if (length($env{'form.upfile'}) < 2) {
1.398 albertel 5859: $r->print("<span class=\"LC_error\">Error:</span> The file you attempted to upload, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>, contained no information. Please check that you entered the correct filename.");
1.183 albertel 5860: } else {
1.275 albertel 5861: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 5862: if ($result =~ m|^/uploaded/|) {
1.398 albertel 5863: $r->print("<span class=\"LC_success\">Success:</span> Successfully uploaded ".(length($env{'form.upfile'})-1)." bytes of data into location <tt>".$result."</tt>");
1.210 albertel 5864: } else {
1.398 albertel 5865: $r->print("<span class=\"LC_error\">Error:</span> An error (".$result.") occurred when attempting to upload the file, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>");
1.183 albertel 5866: }
5867: }
1.174 albertel 5868: if ($symb) {
1.209 ng 5869: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 5870: } else {
1.182 albertel 5871: $r->print($doanotherupload);
1.174 albertel 5872: }
1.157 albertel 5873: return '';
5874: }
5875:
1.202 albertel 5876: sub valid_file {
5877: my ($requested_file)=@_;
5878: foreach my $filename (sort(&scantron_filenames())) {
5879: if ($requested_file eq $filename) { return 1; }
5880: }
5881: return 0;
5882: }
5883:
5884: sub scantron_download_scantron_data {
5885: my ($r)=@_;
1.324 albertel 5886: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5887: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5888: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5889: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 5890: if (! &valid_file($file)) {
5891: $r->print(<<ERROR);
5892: <p>
5893: The requested file name was invalid.
5894: </p>
5895: ERROR
1.324 albertel 5896: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5897: return;
5898: }
5899: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
5900: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
5901: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
5902: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
5903: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
5904: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
5905: $r->print(<<DOWNLOAD);
5906: <p>
5907: <a href="$orig">Original</a> file as uploaded by the scantron office.
5908: </p>
5909: <p>
5910: <a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
5911: </p>
5912: <p>
5913: <a href="$skipped">Skipped</a>, a file of records that were skipped.
5914: </p>
5915: DOWNLOAD
1.324 albertel 5916: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5917: return '';
5918: }
1.157 albertel 5919:
1.75 albertel 5920: #-------- end of section for handling grading scantron forms -------
5921: #
5922: #-------------------------------------------------------------------
5923:
1.72 ng 5924: #-------------------------- Menu interface -------------------------
5925: #
5926: #--- Show a Grading Menu button - Calls the next routine ---
5927: sub show_grading_menu_form {
1.324 albertel 5928: my ($symb)=@_;
1.125 ng 5929: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.399.2.2! albertel 5930: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 5931: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 5932: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
5933: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
5934: '</form>'."\n";
5935: return $result;
5936: }
5937:
1.77 ng 5938: # -- Retrieve choices for grading form
5939: sub savedState {
5940: my %savedState = ();
1.257 albertel 5941: if ($env{'form.saveState'}) {
5942: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 5943: my ($key,$value) = split(/=/,$_,2);
5944: $savedState{$key} = $value;
5945: }
5946: }
5947: return \%savedState;
5948: }
1.76 ng 5949:
1.72 ng 5950: #--- Displays the main menu page -------
5951: sub gradingmenu {
5952: my ($request) = @_;
1.324 albertel 5953: my ($symb)=&get_symb($request);
1.72 ng 5954: if (!$symb) {return '';}
1.76 ng 5955: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 5956:
5957: $request->print(<<GRADINGMENUJS);
5958: <script type="text/javascript" language="javascript">
1.116 ng 5959: function checkChoice(formname,val,cmdx) {
5960: if (val <= 2) {
5961: var cmd = radioSelection(formname.radioChoice);
1.118 ng 5962: var cmdsave = cmd;
1.116 ng 5963: } else {
5964: cmd = cmdx;
1.118 ng 5965: cmdsave = 'submission';
1.116 ng 5966: }
5967: formname.command.value = cmd;
1.118 ng 5968: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 5969: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 5970: if (val < 5) formname.submit();
5971: if (val == 5) {
1.72 ng 5972: if (!checkReceiptNo(formname,'notOK')) { return false;}
5973: formname.submit();
5974: }
1.238 albertel 5975: if (val < 7) formname.submit();
1.72 ng 5976: }
5977:
5978: function checkReceiptNo(formname,nospace) {
5979: var receiptNo = formname.receipt.value;
5980: var checkOpt = false;
5981: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
5982: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
5983: if (checkOpt) {
5984: alert("Please enter a receipt number given by a student in the receipt box.");
5985: formname.receipt.value = "";
5986: formname.receipt.focus();
5987: return false;
5988: }
5989: return true;
5990: }
5991: </script>
5992: GRADINGMENUJS
1.118 ng 5993: &commonJSfunctions($request);
1.398 albertel 5994: my $result='<h3> <span class="LC_info">Manual Grading/View Submission</span></h3>';
1.324 albertel 5995: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.118 ng 5996: $result.=$table;
1.76 ng 5997: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 5998: my $savedState = &savedState();
1.118 ng 5999: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 6000: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 6001: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 6002: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 6003:
6004: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.399.2.2! albertel 6005: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 6006: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
6007: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 6008: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 6009: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 6010: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 6011: '<input type="hidden" name="showgrading" value="yes" />'."\n";
6012:
1.326 albertel 6013: $result.='<table width="100%" border="0"><tr><td bgcolor=#777777>'."\n".
6014: '<table width="100%" border="0"><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 6015: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 6016: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
6017:
1.326 albertel 6018: $result.='<table width="100%" border="0">';
1.116 ng 6019: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.167 sakharuk 6020: ' '.&mt('Select Section').': <select name="section">'."\n";
1.116 ng 6021: if (ref($sections)) {
1.155 albertel 6022: foreach (sort (@$sections)) {
6023: $result.='<option value="'.$_.'" '.
6024: ($saveSec eq $_ ? 'selected="on"':'').'>'.$_.'</option>'."\n";
6025: }
1.116 ng 6026: }
1.238 albertel 6027: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</option></select> ';
1.116 ng 6028:
1.167 sakharuk 6029: $result.=&mt('Student Status').':</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 6030:
1.116 ng 6031: $result.='</td></tr>';
6032:
1.288 albertel 6033: $result.='<tr bgcolor="#ffffe6"valign="top"><td><label>'.
1.118 ng 6034: '<input type="radio" name="radioChoice" value="submission" '.
1.326 albertel 6035: ($saveCmd eq 'submission' ? 'checked' : '').' /> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
1.288 albertel 6036: '</label> <select name="submitonly">'.
1.145 albertel 6037: '<option value="yes" '.
1.326 albertel 6038: ($saveSub eq 'yes' ? 'selected="on"' : '').' />'.&mt('with submissions').'</option>'.
1.301 albertel 6039: '<option value="queued" '.
1.326 albertel 6040: ($saveSub eq 'queued' ? 'selected="on"' : '').' />'.&mt('in grading queue').'</option>'.
1.145 albertel 6041: '<option value="graded" '.
1.326 albertel 6042: ($saveSub eq 'graded' ? 'selected="on"' : '').' />'.&mt('with ungraded submissions').'</option>'.
1.156 albertel 6043: '<option value="incorrect" '.
1.326 albertel 6044: ($saveSub eq 'incorrect' ? 'selected="on"' : '').' />'.&mt('with incorrect submissions').'</option>'.
1.145 albertel 6045: '<option value="all" '.
1.326 albertel 6046: ($saveSub eq 'all' ? 'selected="on"' : '').' />'.&mt('with any status').'</option></select></td></tr>'."\n";
1.72 ng 6047:
1.116 ng 6048: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.288 albertel 6049: '<label><input type="radio" name="radioChoice" value="viewgrades" '.
1.326 albertel 6050: ($saveCmd eq 'viewgrades' ? 'checked' : '').' /> '.
1.288 albertel 6051: '<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
1.72 ng 6052:
1.118 ng 6053: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
1.288 albertel 6054: '<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
1.326 albertel 6055: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').' /> '.
1.288 albertel 6056: 'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
1.46 ng 6057:
1.116 ng 6058: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 6059: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 6060: '</td></tr></table>'."\n";
6061:
6062: $result.='</td><td valign="top">';
6063:
1.326 albertel 6064: $result.='<table width="100%" border="0">';
1.116 ng 6065: $result.='<tr bgcolor="#ffffe6"><td>'.
1.184 www 6066: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
6067: ' '.&mt('scores from file').' </td></tr>'."\n";
1.72 ng 6068:
1.75 albertel 6069: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 6070: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
1.184 www 6071: '" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
1.75 albertel 6072:
1.257 albertel 6073: if ((&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && ($symb)) {
1.72 ng 6074: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.184 www 6075: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
6076: ' '.&mt('receipt').': '.
1.257 albertel 6077: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.326 albertel 6078: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />'.
1.72 ng 6079: '</td></tr>'."\n";
6080: }
1.238 albertel 6081: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
6082: '<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
6083: '" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
1.279 albertel 6084: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
6085: '<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
6086: '" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
1.44 ng 6087:
1.116 ng 6088: $result.='</form></td></tr></table>'."\n".
1.72 ng 6089: '</td></tr></table>'."\n".
6090: '</td></tr></table>'."\n";
1.44 ng 6091: return $result;
1.2 albertel 6092: }
6093:
1.285 albertel 6094: sub reset_perm {
6095: undef(%perm);
6096: }
6097:
6098: sub init_perm {
6099: &reset_perm();
1.300 albertel 6100: foreach my $test_perm ('vgr','mgr','opa') {
6101:
6102: my $scope = $env{'request.course.id'};
6103: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
6104:
6105: $scope .= '/'.$env{'request.course.sec'};
6106: if ( $perm{$test_perm}=
6107: &Apache::lonnet::allowed($test_perm,$scope)) {
6108: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
6109: } else {
6110: delete($perm{$test_perm});
6111: }
1.285 albertel 6112: }
6113: }
6114: }
6115:
1.1 albertel 6116: sub handler {
1.41 ng 6117: my $request=$_[0];
1.102 albertel 6118:
1.285 albertel 6119: &reset_perm();
1.257 albertel 6120: if ($env{'browser.mathml'}) {
1.141 www 6121: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 6122: } else {
1.141 www 6123: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 6124: }
6125: $request->send_http_header;
1.44 ng 6126: return '' if $request->header_only;
1.41 ng 6127: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 6128: my $symb=&get_symb($request,1);
1.160 albertel 6129: my @commands=&Apache::loncommon::get_env_multiple('form.command');
6130: my $command=$commands[0];
6131: if ($#commands > 0) {
6132: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
6133: }
1.353 albertel 6134: $request->print(&Apache::loncommon::start_page('Grading'));
1.324 albertel 6135: if ($symb eq '' && $command eq '') {
1.257 albertel 6136: if ($env{'user.adv'}) {
6137: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
6138: ($env{'form.codethree'})) {
6139: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
6140: $env{'form.codethree'};
1.41 ng 6141: my ($tsymb,$tuname,$tudom,$tcrsid)=
6142: &Apache::lonnet::checkin($token);
6143: if ($tsymb) {
1.137 albertel 6144: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 6145: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 6146: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
6147: ('grade_username' => $tuname,
6148: 'grade_domain' => $tudom,
6149: 'grade_courseid' => $tcrsid,
6150: 'grade_symb' => $tsymb)));
1.41 ng 6151: } else {
1.45 ng 6152: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 6153: }
1.41 ng 6154: } else {
1.45 ng 6155: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 6156: }
1.14 www 6157: } else {
1.41 ng 6158: $request->print(&Apache::lonxml::tokeninputfield());
6159: }
6160: }
6161: } else {
1.285 albertel 6162: &init_perm();
1.104 albertel 6163: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 6164: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 6165: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 6166: &pickStudentPage($request);
1.103 albertel 6167: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 6168: &displayPage($request);
1.104 albertel 6169: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 6170: &updateGradeByPage($request);
1.104 albertel 6171: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 6172: &processGroup($request);
1.104 albertel 6173: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 6174: $request->print(&gradingmenu($request));
1.104 albertel 6175: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 6176: $request->print(&viewgrades($request));
1.104 albertel 6177: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 6178: $request->print(&processHandGrade($request));
1.106 albertel 6179: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 6180: $request->print(&editgrades($request));
1.106 albertel 6181: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 6182: $request->print(&verifyreceipt($request));
1.106 albertel 6183: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 6184: $request->print(&upcsvScores_form($request));
1.106 albertel 6185: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 6186: $request->print(&csvupload($request));
1.106 albertel 6187: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 6188: $request->print(&csvuploadmap($request));
1.246 albertel 6189: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 6190: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 6191: $request->print(&csvuploadoptions($request));
1.41 ng 6192: } else {
1.257 albertel 6193: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
6194: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 6195: } else {
1.257 albertel 6196: $env{'form.upfile_associate'} = 'forward';
1.41 ng 6197: }
6198: $request->print(&csvuploadmap($request));
6199: }
1.246 albertel 6200: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
6201: $request->print(&csvuploadassign($request));
1.106 albertel 6202: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 6203: $request->print(&scantron_selectphase($request));
1.203 albertel 6204: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
6205: $request->print(&scantron_do_warning($request));
1.142 albertel 6206: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
6207: $request->print(&scantron_validate_file($request));
1.106 albertel 6208: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 6209: $request->print(&scantron_process_students($request));
1.157 albertel 6210: } elsif ($command eq 'scantronupload' &&
1.257 albertel 6211: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6212: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 6213: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 6214: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 6215: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6216: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 6217: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 6218: } elsif ($command eq 'scantron_download' &&
1.257 albertel 6219: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 6220: $request->print(&scantron_download_scantron_data($request));
1.106 albertel 6221: } elsif ($command) {
1.157 albertel 6222: $request->print("Access Denied ($command)");
1.26 albertel 6223: }
1.2 albertel 6224: }
1.353 albertel 6225: $request->print(&Apache::loncommon::end_page());
1.44 ng 6226: return '';
6227: }
6228:
1.1 albertel 6229: 1;
6230:
1.13 albertel 6231: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>