Annotation of loncom/homework/grades.pm, revision 1.396
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.396 ! banghart 4: # $Id: grades.pm,v 1.395 2007/04/16 19:00:38 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.324 albertel 97: return ($symb);
1.32 ng 98: }
99:
1.129 ng 100: #--- Format fullname, username:domain if different for display
101: #--- Use anywhere where the student names are listed
102: sub nameUserString {
103: my ($type,$fullname,$uname,$udom) = @_;
104: if ($type eq 'header') {
1.250 albertel 105: return '<b> Fullname </b><font color="#999999">(Username)</font>';
1.129 ng 106: } else {
107: return ' '.$fullname.'<font color="#999999"> ('.$uname.
1.257 albertel 108: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</font>';
1.129 ng 109: }
110: }
111:
1.44 ng 112: #--- Get the partlist and the response type for a given problem. ---
113: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 114: sub response_type {
1.324 albertel 115: my ($symb) = shift;
1.377 albertel 116:
117: my $navmap = Apache::lonnavmaps::navmap->new();
118: my $res = $navmap->getBySymb($symb);
119: my $partlist = $res->parts();
1.392 albertel 120: my %vPart =
121: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 122: my (%response_types,%handgrade);
123: foreach my $part (@{ $partlist }) {
1.392 albertel 124: next if (%vPart && !exists($vPart{$part}));
125:
1.377 albertel 126: my @types = $res->responseType($part);
127: my @ids = $res->responseIds($part);
128: for (my $i=0; $i < scalar(@ids); $i++) {
129: $response_types{$part}{$ids[$i]} = $types[$i];
130: $handgrade{$part.'_'.$ids[$i]} =
131: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
132: '.handgrade',$symb);
1.41 ng 133: }
134: }
1.377 albertel 135: return ($partlist,\%handgrade,\%response_types);
1.39 ng 136: }
137:
1.375 albertel 138: sub flatten_responseType {
139: my ($responseType) = @_;
140: my @part_response_id =
141: map {
142: my $part = $_;
143: map {
144: [$part,$_]
145: } sort(keys(%{ $responseType->{$part} }));
146: } sort(keys(%$responseType));
147: return @part_response_id;
148: }
149:
1.207 albertel 150: sub get_display_part {
1.324 albertel 151: my ($partID,$symb)=@_;
1.207 albertel 152: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
153: if (defined($display) and $display ne '') {
154: $display.= " (<font color=\"#999900\">id $partID</font>)";
155: } else {
156: $display=$partID;
157: }
158: return $display;
159: }
1.269 raeburn 160:
1.118 ng 161: #--- Show resource title
162: #--- and parts and response type
163: sub showResourceInfo {
1.324 albertel 164: my ($symb,$probTitle,$checkboxes) = @_;
1.154 albertel 165: my $col=3;
166: if ($checkboxes) { $col=4; }
1.118 ng 167: my $result ='<table border="0">'.
1.167 sakharuk 168: '<tr><td colspan="'.$col.'"><font size="+1"><b>'.&mt('Current Resource').': </b>'.
1.154 albertel 169: $probTitle.'</font></td></tr>'."\n";
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);
189: $result.='<td><b>Part: </b>'.$display_part.' <font color="#999999">'.
190: $resID.'</font></td>'.
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.148 albertel 221: my $grayFont = '<font color="#999999">';
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: }
232: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
233: }
234: return '<blockquote><table border="1">'.
235: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
236: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
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>';
247: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </font></b></td>';
248: } else {
249: $toprow.='<td><i>'.$item.' </i></td>';
250: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </font></i></td>';
251: }
252: $bottomrow.='<td>'.$grayFont.$foil.'</font> </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>'.
256: '<tr valign="top"><td>'.$grayFont.'Item ID</font></td>'.
257: $middlerow.'</tr>'.
258: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
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: }
275: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
276: }
277: return '<blockquote><table border="1">'.
278: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
279: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
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".
497: '<input type="hidden" name="symb" value="'.$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.45 ng 598: my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
599: $receipt.'</h3></font>'."\n".
1.326 albertel 600: '<font size=+1><b>Resource: </b>'.$env{'form.probTitle'}.'</font><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.118 ng 671: my $result='<h3><font color="#339933"> '.$viewgrade.
672: ' Submissions for a Student or a Group of Students</font></h3>';
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.48 albertel 747: '<input type="hidden" name="symb" value="'.$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) {
884: $gradeTable='<br /> <font color="red">There are no students currently enrolled.</font>';
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.96 albertel 890: $gradeTable='<br /> <font color="red">'.
1.171 albertel 891: 'No '.$submissions.' found for this resource for any students. ('.$num_students.
892: ' students checked for '.$submissions.')</font><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.326 albertel 1347: pDoc.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><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.326 albertel 1432: hDoc.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><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)' :
1483: '<font color="red">problem weight assigned by computer</font>');
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.396 ! banghart 1629: sub files_exist {
! 1630: my ($r, $symb) = @_;
! 1631: my $files_exist = 0;
! 1632: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
! 1633: foreach my $student (@students) {
! 1634: my ($uname,$udom,$fullname) = split(/:/,$student);
! 1635: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
! 1636: my ($string,$timestamp)= &get_last_submission(\%record);
! 1637: foreach (@$string) {
! 1638: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
! 1639: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
! 1640: if (@$files) {
! 1641: $files_exist = 1;
! 1642: return $files_exist;
! 1643: }
! 1644: }
! 1645: }
! 1646: return $files_exist;
! 1647: }
1.394 banghart 1648: sub download_all_link {
1649: my ($r,$symb) = @_;
1.395 albertel 1650: my $all_students =
1651: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1652:
1653: my $parts =
1654: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1655:
1.394 banghart 1656: my $identifier = &Apache::loncommon::get_cgi_id();
1657: &Apache::lonnet::appenv('cgi.'.$identifier.'.students' => $all_students,
1658: 'cgi.'.$identifier.'.symb' => $symb,
1.395 albertel 1659: 'cgi.'.$identifier.'.parts' => $parts,);
1660: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1661: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1662: return
1663: }
1.395 albertel 1664:
1.44 ng 1665: # --------------------------- show submissions of a student, option to grade
1666: sub submission {
1667: my ($request,$counter,$total) = @_;
1668:
1.257 albertel 1669: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1670: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1671: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1672: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.41 ng 1673:
1.324 albertel 1674: my $symb = &get_symb($request);
1675: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1676:
1677: if (!&canview($usec)) {
1.116 ng 1678: $request->print('<font color="red">Unable to view requested student.('.
1.222 albertel 1679: $uname.'@'.$udom.' in section '.$usec.' in course id '.
1.257 albertel 1680: $env{'request.course.id'}.')</font>');
1.324 albertel 1681: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1682: return;
1683: }
1684:
1.257 albertel 1685: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1686: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1687: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1688: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1689: my $checkIcon = '<img alt="'.&mt('Check Mark').
1690: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1691: '/check.gif" height="16" border="0" />';
1.41 ng 1692:
1693: # header info
1694: if ($counter == 0) {
1695: &sub_page_js($request);
1.257 albertel 1696: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1697: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1698: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.396 ! banghart 1699: if (&files_exist($request, $symb)) {
! 1700: &download_all_link($request, $symb);
! 1701: }
1.45 ng 1702: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.257 albertel 1703: '<font size=+1> <b>Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n");
1.118 ng 1704:
1.257 albertel 1705: if ($env{'form.handgrade'} eq 'no') {
1.118 ng 1706: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1707: $checkIcon.' symbol.'."\n";
1708: $request->print($checkMark);
1709: }
1.41 ng 1710:
1.44 ng 1711: # option to display problem, only once else it cause problems
1712: # with the form later since the problem has a form.
1.257 albertel 1713: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1714: my $mode;
1.257 albertel 1715: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1716: $mode='both';
1.257 albertel 1717: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1718: $mode='text';
1.257 albertel 1719: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1720: $mode='answer';
1721: }
1.329 albertel 1722: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1723: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1724: }
1725:
1.44 ng 1726: # kwclr is the only variable that is guaranteed to be non blank
1727: # if this subroutine has been called once.
1.41 ng 1728: my %keyhash = ();
1.257 albertel 1729: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1730: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1731: $env{'course.'.$env{'request.course.id'}.'.domain'},
1732: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1733:
1.257 albertel 1734: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1735: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1736: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1737: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1738: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1739: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1740: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1741: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1742: }
1.257 albertel 1743: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.44 ng 1744:
1.303 banghart 1745: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1746: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1747: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1748: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.120 ng 1749: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1750: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1751: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1752: '<input type="hidden" name="studentNo" value="" />'."\n".
1753: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.41 ng 1754: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 1755: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1756: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1757: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1758: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.326 albertel 1759: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
1760: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1761: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1762: '<input type="hidden" name="NCT"'.
1.257 albertel 1763: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1764: if ($env{'form.handgrade'} eq 'yes') {
1765: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1766: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1767: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1768: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1769: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1770: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1771: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1772: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1773: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1774: }
1.123 ng 1775: }
1.41 ng 1776:
1777: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1778: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1779: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1780: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1781: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1782: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1783: '" />'."\n".
1784: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1785: $cts++;
1786: }
1787: $request->print($prnmsg);
1.32 ng 1788:
1.257 albertel 1789: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1790: #
1791: # Print out the keyword options line
1792: #
1.41 ng 1793: $request->print(<<KEYWORDS);
1.38 ng 1794: <b>Keyword Options:</b>
1.122 ng 1795: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>
1.38 ng 1796: <a href="#" onMouseDown="javascript:getSel(); return false"
1797: CLASS="page">Paste Selection to List</a>
1798: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1799: KEYWORDS
1.88 www 1800: #
1801: # Load the other essays for similarity check
1802: #
1.324 albertel 1803: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 1804: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 1805: $apath=&escape($apath);
1.88 www 1806: $apath=~s/\W/\_/gs;
1807: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1808: }
1809: }
1.44 ng 1810:
1.257 albertel 1811: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.71 ng 1812: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1813: my $mode;
1.257 albertel 1814: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1815: $mode='both';
1.257 albertel 1816: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1817: $mode='text';
1.257 albertel 1818: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1819: $mode='answer';
1820: }
1.329 albertel 1821: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1822: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1823: }
1.144 albertel 1824:
1.257 albertel 1825: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 1826: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 1827:
1.44 ng 1828: # Display student info
1.41 ng 1829: $request->print(($counter == 0 ? '' : '<br />'));
1.326 albertel 1830: my $result='<table border="0" width="100%"><tr><td bgcolor="#777777">'."\n".
1831: '<table border="0" width="100%"><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1832:
1.257 albertel 1833: $result.='<b>Fullname: </b>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1834: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1835: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.41 ng 1836:
1.118 ng 1837: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1838: my @col_fullnames;
1.56 matthew 1839: my ($classlist,$fullname);
1.257 albertel 1840: if ($env{'form.handgrade'} eq 'yes') {
1.80 ng 1841: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1842: for (keys (%$handgrade)) {
1.44 ng 1843: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1844: '.maxcollaborators',
1845: $symb,$udom,$uname);
1846: next if ($ncol <= 0);
1847: s/\_/\./g;
1848: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1849: my @goodcollaborators = ();
1850: my @badcollaborators = ();
1851: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1852: $_ =~ s/[\$\^\(\)]//g;
1853: next if ($_ eq '');
1.80 ng 1854: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1855: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1856: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1857: # Doing this grep allows 'fuzzy' specification
1858: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1859: if (! scalar(@Matches)) {
1860: push @badcollaborators,$_;
1861: } else {
1862: push @goodcollaborators, @Matches;
1863: }
1.80 ng 1864: }
1.86 ng 1865: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1866: $result.='<b>Collaborators: </b>';
1.86 ng 1867: foreach (@goodcollaborators) {
1868: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1869: push @col_fullnames, $givenn.' '.$lastname;
1870: $result.=$$fullname{$_}.' ';
1871: }
1.57 matthew 1872: $result.='<br />'."\n";
1.150 albertel 1873: my ($part)=split(/\./,$_);
1.86 ng 1874: $result.='<input type="hidden" name="collaborator'.$counter.
1.150 albertel 1875: '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
1876: "\n";
1.86 ng 1877: }
1878: if (scalar(@badcollaborators) > 0) {
1879: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1880: $result.='This student has submitted ';
1881: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1882: $result .= ': '.join(', ',@badcollaborators);
1883: $result .= '</td></tr></table>';
1884: }
1885: if (scalar(@badcollaborators > $ncol)) {
1886: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1887: $result .= 'This student has submitted too many '.
1888: 'collaborators. Maximum is '.$ncol.'.';
1889: $result .= '</td></tr></table>';
1890: }
1.41 ng 1891: }
1892: }
1.44 ng 1893: $request->print($result."\n");
1.33 ng 1894:
1.44 ng 1895: # print student answer/submission
1896: # Options are (1) Handgaded submission only
1897: # (2) Last submission, includes submission that is not handgraded
1898: # (for multi-response type part)
1899: # (3) Last submission plus the parts info
1900: # (4) The whole record for this student
1.257 albertel 1901: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 1902: my ($string,$timestamp)= &get_last_submission(\%record);
1903: my $lastsubonly=''.
1904: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1905: $$timestamp)."</td></tr>\n";
1906: if ($$timestamp eq '') {
1907: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1908: } else {
1909: my %seenparts;
1.375 albertel 1910: my @part_response_id = &flatten_responseType($responseType);
1911: foreach my $part (@part_response_id) {
1.393 albertel 1912: next if ($env{'form.lastSub'} eq 'hdgrade'
1913: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
1914:
1.375 albertel 1915: my ($partid,$respid) = @{ $part };
1.324 albertel 1916: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 1917: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 1918: if (exists($seenparts{$partid})) { next; }
1919: $seenparts{$partid}=1;
1.207 albertel 1920: my $submitby='<b>Part:</b> '.$display_part.
1921: ' <b>Collaborative submission by:</b> '.
1.151 albertel 1922: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 1923: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.151 albertel 1924: '\')"; TARGET=_self>'.
1.257 albertel 1925: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 1926: $request->print($submitby);
1927: next;
1928: }
1929: my $responsetype = $responseType->{$partid}->{$respid};
1930: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.207 albertel 1931: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1932: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1933: ' )</font> '.
1934: '<font color="red">Nothing submitted - no attempts</font><br /><br />';
1935: next;
1936: }
1937: foreach (@$string) {
1938: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1.375 albertel 1939: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.151 albertel 1940: my ($ressub,$subval) = split(/:/,$_,2);
1941: # Similarity check
1942: my $similar='';
1.257 albertel 1943: if($env{'form.checkPlag'}){
1.151 albertel 1944: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1945: &most_similar($uname,$udom,$subval);
1946: if ($osim) {
1947: $osim=int($osim*100.0);
1948: $similar="<hr /><h3><font color=\"#FF0000\">Essay".
1949: " is $osim% similar to an essay by ".
1950: &Apache::loncommon::plainname($oname,$odom).
1951: '</font></h3><blockquote><i>'.
1952: &keywords_highlight($oessay).
1953: '</i></blockquote><hr />';
1954: }
1.150 albertel 1955: }
1.151 albertel 1956: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 1957: if ($env{'form.lastSub'} eq 'lastonly' ||
1958: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 1959: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 1960: my $display_part=&get_display_part($partid,$symb);
1.393 albertel 1961: $lastsubonly.='<tr><td bgcolor="#ffffe6">Debug -'.'<b>Part:</b> '.
1962: $display_part.' <font color="#999999">( hhhh ID '.$respid.
1.151 albertel 1963: ' )</font> ';
1.313 banghart 1964: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
1965: if (@$files) {
1.232 albertel 1966: $lastsubonly.='<br /><font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />';
1.303 banghart 1967: my $file_counter = 0;
1.313 banghart 1968: foreach my $file (@$files) {
1.303 banghart 1969: $file_counter ++;
1.232 albertel 1970: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.335 albertel 1971: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1.232 albertel 1972: }
1.236 albertel 1973: $lastsubonly.='<br />';
1.41 ng 1974: }
1.151 albertel 1975: $lastsubonly.='<b>Submitted Answer: </b>'.
1976: &cleanRecord($subval,$responsetype,$symb,$partid,
1977: $respid,\%record,$order);
1978: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41 ng 1979: }
1980: }
1981: }
1.151 albertel 1982: }
1983: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1984: $request->print($lastsubonly);
1.257 albertel 1985: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 1986: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 1987: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 1988: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1989: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 1990: $env{'request.course.id'},
1.44 ng 1991: $last,'.submission',
1992: 'Apache::grades::keywords_highlight'));
1.41 ng 1993: }
1.120 ng 1994:
1.121 ng 1995: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1996: .$udom.'" />'."\n");
1.41 ng 1997:
1.44 ng 1998: # return if view submission with no grading option
1.257 albertel 1999: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2000: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 2001: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
2002: .$counter.'\');" TARGET=_self> '."\n" if (&canmodify($usec));
1.169 albertel 2003: $toGrade.='</td></tr></table></td></tr></table>'."\n";
1.257 albertel 2004: if (($env{'form.command'} eq 'submission') ||
2005: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2006: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2007: }
1.180 albertel 2008: $request->print($toGrade);
1.41 ng 2009: return;
1.180 albertel 2010: } else {
2011: $request->print('</td></tr></table></td></tr></table>'."\n");
1.41 ng 2012: }
1.33 ng 2013:
1.121 ng 2014: # essay grading message center
1.257 albertel 2015: if ($env{'form.handgrade'} eq 'yes') {
2016: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2017: my $msgfor = $givenn.' '.$lastname;
2018: if (scalar(@col_fullnames) > 0) {
2019: my $lastone = pop @col_fullnames;
2020: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
2021: }
2022: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 2023: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
2024: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2025: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118 ng 2026: ',\''.$msgfor.'\')"; TARGET=_self>'.
1.350 albertel 2027: &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
2028: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2029: '<img src="'.$request->dir_config('lonIconsURL').
2030: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2031: '<br /> ('.
2032: &mt('Message will be sent when you click on Save & Next below.').")\n";
1.121 ng 2033: $request->print($result);
1.118 ng 2034: }
1.300 albertel 2035: if ($perm{'vgr'}) {
1.297 www 2036: $request->print('<br />'.
1.300 albertel 2037: &Apache::loncommon::track_student_link(&mt('View recent activity'),
2038: $uname,$udom,'check'));
1.297 www 2039: }
1.300 albertel 2040: if ($perm{'opa'}) {
1.297 www 2041: $request->print('<br />'.
1.300 albertel 2042: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
2043: $uname,$udom,$symb,'check'));
1.297 www 2044: }
1.41 ng 2045:
2046: my %seen = ();
2047: my @partlist;
1.129 ng 2048: my @gradePartRespid;
1.375 albertel 2049: my @part_response_id = &flatten_responseType($responseType);
2050: foreach my $part_response_id (@part_response_id) {
2051: my ($partid,$respid) = @{ $part_response_id };
2052: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2053: next if ($seen{$partid} > 0);
1.41 ng 2054: $seen{$partid}++;
1.393 albertel 2055: next if ($$handgrade{$part_resp} ne 'yes'
2056: && $env{'form.lastSub'} eq 'hdgrade');
1.41 ng 2057: push @partlist,$partid;
1.129 ng 2058: push @gradePartRespid,$partid.'.'.$respid;
1.322 albertel 2059: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2060: }
1.45 ng 2061: $result='<input type="hidden" name="partlist'.$counter.
2062: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2063: $result.='<input type="hidden" name="gradePartRespid'.
2064: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2065: my $ctr = 0;
2066: while ($ctr < scalar(@partlist)) {
2067: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2068: $partlist[$ctr].'" />'."\n";
2069: $ctr++;
2070: }
2071: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 2072:
2073: # print end of form
2074: if ($counter == $total) {
1.297 www 2075: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 2076: $endform.='<input type="button" value="Save & Next" '.
2077: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
2078: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
2079: my $ntstu ='<select name="NTSTU">'.
2080: '<option>1</option><option>2</option>'.
2081: '<option>3</option><option>5</option>'.
2082: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2083: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.119 ng 2084: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
2085: $endform.=$ntstu.'student(s) ';
1.126 ng 2086: $endform.='<input type="button" value="Previous" '.
2087: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> '."\n".
2088: '<input type="button" value="Next" '.
2089: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> ';
2090: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.349 albertel 2091: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2092: "' name='increment' />";
1.45 ng 2093: $endform.='</td><tr></table></form>';
1.324 albertel 2094: $endform.=&show_grading_menu_form($symb);
1.41 ng 2095: $request->print($endform);
2096: }
2097: return '';
1.38 ng 2098: }
2099:
1.44 ng 2100: #--- Retrieve the last submission for all the parts
1.38 ng 2101: sub get_last_submission {
1.119 ng 2102: my ($returnhash)=@_;
1.46 ng 2103: my (@string,$timestamp);
1.119 ng 2104: if ($$returnhash{'version'}) {
1.46 ng 2105: my %lasthash=();
2106: my ($version);
1.119 ng 2107: for ($version=1;$version<=$$returnhash{'version'};$version++) {
2108: foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
2109: $lasthash{$_}=$$returnhash{$version.':'.$_};
2110: $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 2111: }
2112: }
2113: foreach ((keys %lasthash)) {
2114: if ($_ =~ /\.submission$/) {
2115: my ($partid,$foo) = split(/submission$/,$_);
2116: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
2117: '<font color="red">Draft Copy</font> ' : '';
2118: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 2119: }
2120: }
2121: }
1.125 ng 2122: @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
1.46 ng 2123: return \@string,\$timestamp;
1.38 ng 2124: }
1.35 ng 2125:
1.44 ng 2126: #--- High light keywords, with style choosen by user.
1.38 ng 2127: sub keywords_highlight {
1.44 ng 2128: my $string = shift;
1.257 albertel 2129: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2130: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2131: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2132: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.41 ng 2133: foreach (@keylist) {
1.257 albertel 2134: $string =~ s/\b\Q$_\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
1.41 ng 2135: }
2136: return $string;
1.38 ng 2137: }
1.36 ng 2138:
1.44 ng 2139: #--- Called from submission routine
1.38 ng 2140: sub processHandGrade {
1.41 ng 2141: my ($request) = shift;
1.324 albertel 2142: my $symb = &get_symb($request);
2143: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2144: my $button = $env{'form.gradeOpt'};
2145: my $ngrade = $env{'form.NCT'};
2146: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2147: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2148: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2149:
1.44 ng 2150: if ($button eq 'Save & Next') {
2151: my $ctr = 0;
2152: while ($ctr < $ngrade) {
1.257 albertel 2153: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2154: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2155: if ($errorflag eq 'no_score') {
2156: $ctr++;
2157: next;
2158: }
1.104 albertel 2159: if ($errorflag eq 'not_allowed') {
2160: $request->print("<font color=\"red\">Not allowed to modify grades for $uname:$udom</font>");
2161: $ctr++;
2162: next;
2163: }
1.257 albertel 2164: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2165: my ($subject,$message,$msgstatus) = ('','','');
1.386 raeburn 2166: my $restitle = &Apache::lonnet::gettitle($symb);
2167: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2168: $symb,$udom,$uname);
2169: my ($feedurl,$baseurl,$showsymb,$messagetail);
2170: $feedurl = &Apache::lonnet::clutter($url);
2171: if ($encrypturl =~ /^yes$/i) {
2172: $baseurl = &Apache::lonenc::encrypted($feedurl,1);
2173: $showsymb = &Apache::lonenc::encrypted($symb,1);
1.387 raeburn 2174: } else {
2175: $baseurl = $feedurl;
2176: $showsymb = $symb;
1.386 raeburn 2177: }
1.62 albertel 2178: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2179: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2180: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2181: $subject.=' ['.$restitle.']';
1.44 ng 2182: my (@msgnum) = split(/,/,$includemsg);
2183: foreach (@msgnum) {
1.257 albertel 2184: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2185: }
1.80 ng 2186: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2187: if ($env{'form.withgrades'.$ctr}) {
2188: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2189: $messagetail = " for <a href=\"".
2190: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
2191: }
2192: $msgstatus =
2193: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2194: $message.$messagetail,
2195: undef,$baseurl,undef,
2196: undef,undef,$showsymb,
2197: $restitle);
2198: $request->print('<br />'.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '.
1.296 www 2199: $msgstatus);
1.44 ng 2200: }
1.257 albertel 2201: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2202: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2203: foreach my $collabstr (@collabstrs) {
2204: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2205: foreach my $collaborator (@collaborators) {
1.150 albertel 2206: my ($errorflag,$pts,$wgt) =
1.324 albertel 2207: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2208: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2209: if ($errorflag eq 'not_allowed') {
1.362 albertel 2210: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2211: next;
2212: } else {
2213: if ($message ne '') {
1.386 raeburn 2214: $encrypturl=
2215: &Apache::lonnet::EXT('resource.0.encrypturl',
2216: $symb,$udom,$collaborator);
2217: if ($encrypturl =~ /^yes$/i) {
2218: $baseurl = &Apache::lonenc::encrypted($feedurl,1);
2219: $showsymb = &Apache::lonenc::encrypted($symb,1);
2220: } else {
2221: $baseurl = $feedurl;
2222: $showsymb = $symb;
2223: }
2224: if ($env{'form.withgrades'.$ctr}) {
2225: $messagetail = " for <a href=\"".
2226: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
2227:
2228: }
2229: $msgstatus =
2230: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.150 albertel 2231: }
1.104 albertel 2232: }
1.44 ng 2233: }
2234: }
2235: }
2236: $ctr++;
2237: }
2238: }
2239:
1.257 albertel 2240: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2241: # Keywords sorted in alphabatical order
1.257 albertel 2242: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2243: my %keyhash = ();
1.257 albertel 2244: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2245: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2246: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2247: $env{'form.keywords'} = join(' ',@keywords);
2248: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2249: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2250: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2251: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2252: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2253:
2254: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2255: # New messages are saved in env for the next student.
1.119 ng 2256: # All messages are saved in nohist_handgrade.db
2257: my ($ctr,$idx) = (1,1);
1.257 albertel 2258: while ($ctr <= $env{'form.savemsgN'}) {
2259: if ($env{'form.savemsg'.$ctr} ne '') {
2260: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2261: $idx++;
2262: }
2263: $ctr++;
1.41 ng 2264: }
1.119 ng 2265: $ctr = 0;
2266: while ($ctr < $ngrade) {
1.257 albertel 2267: if ($env{'form.newmsg'.$ctr} ne '') {
2268: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2269: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2270: $idx++;
2271: }
2272: $ctr++;
1.41 ng 2273: }
1.257 albertel 2274: $env{'form.savemsgN'} = --$idx;
2275: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2276: my $putresult = &Apache::lonnet::put
1.301 albertel 2277: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2278: }
1.44 ng 2279: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2280: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2281: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2282: my ($ctr,$total) = (0,0);
2283: while ($ctr < $ngrade) {
1.257 albertel 2284: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2285: $ctr++;
2286: }
1.257 albertel 2287: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2288: $ctr = 0;
2289: while ($ctr < $total) {
1.257 albertel 2290: my $processUser = $env{'form.unamedom'.$ctr};
2291: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2292: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2293: &submission($request,$ctr,$total-1);
1.41 ng 2294: $ctr++;
2295: }
2296: return '';
2297: }
1.36 ng 2298:
1.121 ng 2299: # Go directly to grade student - from submission or link from chart page
1.120 ng 2300: if ($button eq 'Grade Student') {
1.324 albertel 2301: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2302: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2303: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2304: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2305: &submission($request,0,0);
2306: return '';
2307: }
2308:
1.44 ng 2309: # Get the next/previous one or group of students
1.257 albertel 2310: my $firststu = $env{'form.unamedom0'};
2311: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2312: my $ctr = 2;
1.41 ng 2313: while ($laststu eq '') {
1.257 albertel 2314: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2315: $ctr++;
2316: $laststu = $firststu if ($ctr > $ngrade);
2317: }
1.44 ng 2318:
1.41 ng 2319: my (@parsedlist,@nextlist);
2320: my ($nextflg) = 0;
1.294 albertel 2321: foreach (sort
2322: {
2323: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2324: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2325: }
2326: return $a cmp $b;
2327: } (keys(%$fullname))) {
1.41 ng 2328: if ($nextflg == 1 && $button =~ /Next$/) {
2329: push @parsedlist,$_;
2330: }
2331: $nextflg = 1 if ($_ eq $laststu);
2332: if ($button eq 'Previous') {
2333: last if ($_ eq $firststu);
2334: push @parsedlist,$_;
2335: }
2336: }
2337: $ctr = 0;
2338: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2339: my ($partlist) = &response_type($symb);
1.41 ng 2340: foreach my $student (@parsedlist) {
1.257 albertel 2341: my $submitonly=$env{'form.submitonly'};
1.41 ng 2342: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2343:
2344: if ($submitonly eq 'queued') {
2345: my %queue_status =
2346: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2347: $udom,$uname);
2348: next if (!defined($queue_status{'gradingqueue'}));
2349: }
2350:
1.156 albertel 2351: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2352: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2353: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2354: my $submitted = 0;
1.248 albertel 2355: my $ungraded = 0;
2356: my $incorrect = 0;
1.145 albertel 2357: foreach (keys(%status)) {
2358: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2359: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
2360: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1.145 albertel 2361: my ($foo,$partid,$foo1) = split(/\./,$_);
2362: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2363: $submitted = 0;
2364: }
1.41 ng 2365: }
1.156 albertel 2366: next if (!$submitted && ($submitonly eq 'yes' ||
2367: $submitonly eq 'incorrect' ||
2368: $submitonly eq 'graded'));
1.248 albertel 2369: next if (!$ungraded && ($submitonly eq 'graded'));
2370: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2371: }
2372: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 2373: last if ($ctr == $ntstu);
1.41 ng 2374: $ctr++;
2375: }
1.36 ng 2376:
1.41 ng 2377: $ctr = 0;
2378: my $total = scalar(@nextlist)-1;
1.39 ng 2379:
1.41 ng 2380: foreach (sort @nextlist) {
2381: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2382: $env{'form.student'} = $uname;
2383: $env{'form.userdom'} = $udom;
2384: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2385: &submission($request,$ctr,$total);
2386: $ctr++;
2387: }
2388: if ($total < 0) {
2389: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
2390: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
2391: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1.324 albertel 2392: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2393: $request->print($the_end);
2394: }
2395: return '';
1.38 ng 2396: }
1.36 ng 2397:
1.44 ng 2398: #---- Save the score and award for each student, if changed
1.38 ng 2399: sub saveHandGrade {
1.324 albertel 2400: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2401: my @version_parts;
1.104 albertel 2402: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2403: $env{'request.course.id'});
1.104 albertel 2404: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2405: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2406: my @parts_graded;
1.77 ng 2407: my %newrecord = ();
2408: my ($pts,$wgt) = ('','');
1.269 raeburn 2409: my %aggregate = ();
2410: my $aggregateflag = 0;
1.301 albertel 2411: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2412: foreach my $new_part (@parts) {
1.337 banghart 2413: #collaborator ($submi may vary for different parts
1.259 banghart 2414: if ($submitter && $new_part ne $part) { next; }
2415: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2416: if ($dropMenu eq 'excused') {
1.259 banghart 2417: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2418: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2419: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2420: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2421: }
1.364 banghart 2422: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2423: }
1.125 ng 2424: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2425: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.197 albertel 2426: foreach my $key (keys (%record)) {
1.259 banghart 2427: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2428: }
1.259 banghart 2429: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2430: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2431: my $totaltries = $record{'resource.'.$part.'.tries'};
2432:
2433: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2434: [$new_part]);
2435: my $aggtries =$totaltries;
1.269 raeburn 2436: if ($last_resets{$new_part}) {
1.270 albertel 2437: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2438: $new_part);
1.269 raeburn 2439: }
1.270 albertel 2440:
2441: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2442: if ($aggtries > 0) {
1.327 albertel 2443: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2444: $aggregateflag = 1;
2445: }
1.125 ng 2446: } elsif ($dropMenu eq '') {
1.259 banghart 2447: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2448: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2449: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2450: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2451: next;
2452: }
1.259 banghart 2453: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2454: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2455: my $partial= $pts/$wgt;
1.259 banghart 2456: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2457: #do not update score for part if not changed.
1.346 banghart 2458: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2459: next;
1.251 banghart 2460: } else {
1.259 banghart 2461: push @parts_graded, $new_part;
1.153 albertel 2462: }
1.259 banghart 2463: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2464: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2465: }
1.259 banghart 2466: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2467: if ($partial == 0) {
1.153 albertel 2468: if ($record{$reckey} ne 'incorrect_by_override') {
2469: $newrecord{$reckey} = 'incorrect_by_override';
2470: }
1.41 ng 2471: } else {
1.153 albertel 2472: if ($record{$reckey} ne 'correct_by_override') {
2473: $newrecord{$reckey} = 'correct_by_override';
2474: }
2475: }
2476: if ($submitter &&
1.259 banghart 2477: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2478: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2479: }
1.259 banghart 2480: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2481: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2482: }
1.259 banghart 2483: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2484: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2485: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2486: $dropMenu eq 'reset status')
2487: {
1.342 banghart 2488: push (@version_parts,$new_part);
1.259 banghart 2489: }
1.41 ng 2490: }
1.301 albertel 2491: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2492: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2493:
1.344 albertel 2494: if (%newrecord) {
2495: if (@version_parts) {
1.364 banghart 2496: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2497: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2498: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2499: foreach my $new_part (@version_parts) {
2500: &handback_files($request,$symb,$stuname,$domain,$newflg,
2501: $new_part,\%newrecord);
2502: }
1.259 banghart 2503: }
1.44 ng 2504: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2505: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2506: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2507: $cdom,$cnum,$domain,$stuname);
1.41 ng 2508: }
1.269 raeburn 2509: if ($aggregateflag) {
2510: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2511: $cdom,$cnum);
1.269 raeburn 2512: }
1.301 albertel 2513: return ('',$pts,$wgt);
1.36 ng 2514: }
1.322 albertel 2515:
1.380 albertel 2516: sub check_and_remove_from_queue {
2517: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2518: my @ungraded_parts;
2519: foreach my $part (@{$parts}) {
2520: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2521: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2522: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2523: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2524: ) {
2525: push(@ungraded_parts, $part);
2526: }
2527: }
2528: if ( !@ungraded_parts ) {
2529: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2530: $cnum,$domain,$stuname);
2531: }
2532: }
2533:
1.337 banghart 2534: sub handback_files {
2535: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.359 www 2536: my $portfolio_root = &propath($domain,$stuname).'/userfiles/portfolio';
2537: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.375 albertel 2538:
2539: my @part_response_id = &flatten_responseType($responseType);
2540: foreach my $part_response_id (@part_response_id) {
2541: my ($part_id,$resp_id) = @{ $part_response_id };
2542: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2543: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2544: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2545: my $file_counter = 1;
1.367 albertel 2546: my $file_msg;
1.337 banghart 2547: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2548: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2549: my ($directory,$answer_file) =
2550: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2551: my ($answer_name,$answer_ver,$answer_ext) =
2552: &file_name_version_ext($answer_file);
1.355 banghart 2553: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.341 banghart 2554: my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
1.338 banghart 2555: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2556: # fix file name
2557: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2558: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2559: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2560: $save_file_name);
1.337 banghart 2561: if ($result !~ m|^/uploaded/|) {
2562: $request->print('<font color="red"> An errror occured ('.$result.
1.355 banghart 2563: ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'</font><br />');
1.356 banghart 2564: } else {
1.360 banghart 2565: # mark the file as read only
2566: my @files = ($save_file_name);
1.372 albertel 2567: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2568: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2569: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2570: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2571: }
2572: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2573: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2574:
1.337 banghart 2575: }
2576: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2577: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2578: $file_counter++;
2579: }
1.367 albertel 2580: my $subject = "File Handed Back by Instructor ";
2581: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2582: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2583: $message .= ' The returned file(s) are named: '. $file_msg;
2584: $message .= " and can be found in your portfolio space.";
2585: my $url = (&Apache::lonnet::decode_symb($symb))[2];
1.388 raeburn 2586: my $feedurl = &Apache::lonnet::clutter($url);
1.386 raeburn 2587: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2588: $symb,$domain,$stuname);
2589: my ($baseurl,$showsymb);
2590: if ($encrypturl =~ /^yes$/i) {
2591: $baseurl = &Apache::lonenc::encrypted($feedurl,1);
2592: $showsymb = &Apache::lonenc::encrypted($symb,1);
2593: } else {
2594: $baseurl = $feedurl;
2595: $showsymb = $symb;
2596: }
2597: my $restitle = &Apache::lonnet::gettitle($symb);
2598: my $msgstatus =
2599: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2600: ' (File Returned) ['.$restitle.']',$message,undef,
2601: $baseurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2602: }
2603: }
1.338 banghart 2604: return;
1.337 banghart 2605: }
2606:
1.313 banghart 2607: sub get_submitted_files {
2608: my ($udom,$uname,$partid,$respid,$record) = @_;
2609: my @files;
2610: if ($$record{"resource.$partid.$respid.portfiles"}) {
2611: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2612: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2613: push(@files,$file_url.$file);
2614: }
2615: }
2616: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2617: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2618: }
2619: return (\@files);
2620: }
1.322 albertel 2621:
1.269 raeburn 2622: # ----------- Provides number of tries since last reset.
2623: sub get_num_tries {
2624: my ($record,$last_reset,$part) = @_;
2625: my $timestamp = '';
2626: my $num_tries = 0;
2627: if ($$record{'version'}) {
2628: for (my $version=$$record{'version'};$version>=1;$version--) {
2629: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2630: $timestamp = $$record{$version.':timestamp'};
2631: if ($timestamp > $last_reset) {
2632: $num_tries ++;
2633: } else {
2634: last;
2635: }
2636: }
2637: }
2638: }
2639: return $num_tries;
2640: }
2641:
2642: # ----------- Determine decrements required in aggregate totals
2643: sub decrement_aggs {
2644: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2645: my %decrement = (
2646: attempts => 0,
2647: users => 0,
2648: correct => 0
2649: );
2650: $decrement{'attempts'} = $aggtries;
2651: if ($solvedstatus =~ /^correct/) {
2652: $decrement{'correct'} = 1;
2653: }
2654: if ($aggtries == $totaltries) {
2655: $decrement{'users'} = 1;
2656: }
2657: foreach my $type (keys (%decrement)) {
2658: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2659: }
2660: return;
2661: }
2662:
2663: # ----------- Determine timestamps for last reset of aggregate totals for parts
2664: sub get_last_resets {
1.270 albertel 2665: my ($symb,$courseid,$partids) =@_;
2666: my %last_resets;
1.269 raeburn 2667: my $cdom = $env{'course.'.$courseid.'.domain'};
2668: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2669: my @keys;
2670: foreach my $part (@{$partids}) {
2671: push(@keys,"$symb\0$part\0resettime");
2672: }
2673: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2674: $cdom,$cname);
2675: foreach my $part (@{$partids}) {
2676: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2677: }
1.270 albertel 2678: return %last_resets;
1.269 raeburn 2679: }
2680:
1.251 banghart 2681: # ----------- Handles creating versions for portfolio files as answers
2682: sub version_portfiles {
1.343 banghart 2683: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2684: my $version_parts = join('|',@$v_flag);
1.343 banghart 2685: my @returned_keys;
1.255 banghart 2686: my $parts = join('|', @$parts_graded);
1.359 www 2687: my $portfolio_root = &propath($domain,$stu_name).
2688: '/userfiles/portfolio';
1.277 albertel 2689: foreach my $key (keys(%$record)) {
1.259 banghart 2690: my $new_portfiles;
1.263 banghart 2691: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2692: my @versioned_portfiles;
1.367 albertel 2693: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 2694: foreach my $file (@portfiles) {
1.306 banghart 2695: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2696: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2697: my ($answer_name,$answer_ver,$answer_ext) =
2698: &file_name_version_ext($answer_file);
1.306 banghart 2699: my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
1.342 banghart 2700: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2701: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2702: if ($new_answer ne 'problem getting file') {
1.342 banghart 2703: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2704: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 2705: [$directory.$new_answer],
1.306 banghart 2706: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2707: }
1.252 banghart 2708: }
1.343 banghart 2709: $$record{$key} = join(',',@versioned_portfiles);
2710: push(@returned_keys,$key);
1.251 banghart 2711: }
2712: }
1.343 banghart 2713: return (@returned_keys);
1.305 banghart 2714: }
2715:
1.307 banghart 2716: sub get_next_version {
1.341 banghart 2717: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2718: my $version;
2719: foreach my $row (@$dir_list) {
2720: my ($file) = split(/\&/,$row,2);
2721: my ($file_name,$file_version,$file_ext) =
2722: &file_name_version_ext($file);
2723: if (($file_name eq $answer_name) &&
2724: ($file_ext eq $answer_ext)) {
2725: # gets here if filename and extension match, regardless of version
2726: if ($file_version ne '') {
2727: # a versioned file is found so save it for later
2728: if ($file_version > $version) {
2729: $version = $file_version;
2730: }
2731: }
2732: }
2733: }
2734: $version ++;
2735: return($version);
2736: }
2737:
1.305 banghart 2738: sub version_selected_portfile {
1.306 banghart 2739: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2740: my ($answer_name,$answer_ver,$answer_ext) =
2741: &file_name_version_ext($file_name);
2742: my $new_answer;
2743: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2744: if($env{'form.copy'} eq '-1') {
2745: &Apache::lonnet::logthis('problem getting file '.$file_name);
2746: $new_answer = 'problem getting file';
2747: } else {
2748: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2749: my $copy_result = &Apache::lonnet::finishuserfileupload(
2750: $stu_name,$domain,'copy',
2751: '/portfolio'.$directory.$new_answer);
2752: }
2753: return ($new_answer);
1.251 banghart 2754: }
2755:
1.304 albertel 2756: sub file_name_version_ext {
2757: my ($file)=@_;
2758: my @file_parts = split(/\./, $file);
2759: my ($name,$version,$ext);
2760: if (@file_parts > 1) {
2761: $ext=pop(@file_parts);
2762: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2763: $version=pop(@file_parts);
2764: }
2765: $name=join('.',@file_parts);
2766: } else {
2767: $name=join('.',@file_parts);
2768: }
2769: return($name,$version,$ext);
2770: }
2771:
1.44 ng 2772: #--------------------------------------------------------------------------------------
2773: #
2774: #-------------------------- Next few routines handles grading by section or whole class
2775: #
2776: #--- Javascript to handle grading by section or whole class
1.42 ng 2777: sub viewgrades_js {
2778: my ($request) = shift;
2779:
1.41 ng 2780: $request->print(<<VIEWJAVASCRIPT);
2781: <script type="text/javascript" language="javascript">
1.45 ng 2782: function writePoint(partid,weight,point) {
1.125 ng 2783: var radioButton = document.classgrade["RADVAL_"+partid];
2784: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2785: if (point == "textval") {
1.125 ng 2786: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2787: if (isNaN(point) || parseFloat(point) < 0) {
2788: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2789: var resetbox = false;
2790: for (var i=0; i<radioButton.length; i++) {
2791: if (radioButton[i].checked) {
2792: textbox.value = i;
2793: resetbox = true;
2794: }
2795: }
2796: if (!resetbox) {
2797: textbox.value = "";
2798: }
2799: return;
2800: }
1.109 matthew 2801: if (parseFloat(point) > parseFloat(weight)) {
2802: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2803: ") greater than the weight for the part. Accept?");
2804: if (resp == false) {
2805: textbox.value = "";
2806: return;
2807: }
2808: }
1.42 ng 2809: for (var i=0; i<radioButton.length; i++) {
2810: radioButton[i].checked=false;
1.109 matthew 2811: if (parseFloat(point) == i) {
1.42 ng 2812: radioButton[i].checked=true;
2813: }
2814: }
1.41 ng 2815:
1.42 ng 2816: } else {
1.125 ng 2817: textbox.value = parseFloat(point);
1.42 ng 2818: }
1.41 ng 2819: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2820: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2821: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2822: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2823: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2824: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2825: if (saveval != "correct") {
2826: scorename.value = point;
1.43 ng 2827: if (selname[0].selected != true) {
2828: selname[0].selected = true;
2829: }
1.42 ng 2830: }
2831: }
1.125 ng 2832: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2833: }
2834:
2835: function writeRadText(partid,weight) {
1.125 ng 2836: var selval = document.classgrade["SELVAL_"+partid];
2837: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 2838: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 2839: var textbox = document.classgrade["TEXTVAL_"+partid];
2840: if (selval[1].selected || selval[2].selected) {
1.42 ng 2841: for (var i=0; i<radioButton.length; i++) {
2842: radioButton[i].checked=false;
2843:
2844: }
2845: textbox.value = "";
2846:
2847: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2848: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2849: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2850: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2851: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2852: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2853: if ((saveval != "correct") || override) {
1.42 ng 2854: scorename.value = "";
1.125 ng 2855: if (selval[1].selected) {
2856: selname[1].selected = true;
2857: } else {
2858: selname[2].selected = true;
2859: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2860: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2861: }
1.42 ng 2862: }
2863: }
1.43 ng 2864: } else {
2865: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2866: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2867: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2868: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2869: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2870: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2871: if ((saveval != "correct") || override) {
1.125 ng 2872: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2873: selname[0].selected = true;
2874: }
2875: }
2876: }
1.42 ng 2877: }
2878:
2879: function changeSelect(partid,user) {
1.125 ng 2880: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2881: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2882: var point = textbox.value;
1.125 ng 2883: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2884:
1.109 matthew 2885: if (isNaN(point) || parseFloat(point) < 0) {
2886: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2887: textbox.value = "";
2888: return;
2889: }
1.109 matthew 2890: if (parseFloat(point) > parseFloat(weight)) {
2891: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2892: ") greater than the weight of the part. Accept?");
2893: if (resp == false) {
2894: textbox.value = "";
2895: return;
2896: }
2897: }
1.42 ng 2898: selval[0].selected = true;
2899: }
2900:
2901: function changeOneScore(partid,user) {
1.125 ng 2902: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2903: if (selval[1].selected || selval[2].selected) {
2904: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2905: if (selval[2].selected) {
2906: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2907: }
1.269 raeburn 2908: }
1.42 ng 2909: }
2910:
2911: function resetEntry(numpart) {
2912: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2913: var partid = document.classgrade["partid_"+ctpart].value;
2914: var radioButton = document.classgrade["RADVAL_"+partid];
2915: var textbox = document.classgrade["TEXTVAL_"+partid];
2916: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2917: for (var i=0; i<radioButton.length; i++) {
2918: radioButton[i].checked=false;
2919:
2920: }
2921: textbox.value = "";
2922: selval[0].selected = true;
2923:
2924: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2925: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2926: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2927: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2928: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2929: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2930: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2931: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2932: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2933: if (saveselval == "excused") {
1.43 ng 2934: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2935: } else {
1.43 ng 2936: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2937: }
2938: }
1.41 ng 2939: }
1.42 ng 2940: }
2941:
1.41 ng 2942: </script>
2943: VIEWJAVASCRIPT
1.42 ng 2944: }
2945:
1.44 ng 2946: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2947: sub viewgrades {
2948: my ($request) = shift;
2949: &viewgrades_js($request);
1.41 ng 2950:
1.324 albertel 2951: my ($symb) = &get_symb($request);
1.168 albertel 2952: #need to make sure we have the correct data for later EXT calls,
2953: #thus invalidate the cache
2954: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 2955: $env{'course.'.$env{'request.course.id'}.'.num'},
2956: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 2957: &Apache::lonnet::clear_EXT_cache_status();
2958:
1.167 sakharuk 2959: my $result='<h3><font color="#339933">'.&mt('Manual Grading').'</font></h3>';
1.257 albertel 2960: $result.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n";
1.41 ng 2961:
2962: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 2963: $result.=&jscriptNform($symb);
1.41 ng 2964:
1.44 ng 2965: #beginning of class grading form
1.41 ng 2966: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.106 albertel 2967: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.38 ng 2968: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.257 albertel 2969: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
2970: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
2971: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
2972: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 2973:
1.126 ng 2974: my $sectionClass;
1.257 albertel 2975: if ($env{'form.section'} eq 'all') {
1.126 ng 2976: $sectionClass='Class </h3>';
1.257 albertel 2977: } elsif ($env{'form.section'} eq 'none') {
1.126 ng 2978: $sectionClass='Students in no Section </h3>';
1.52 albertel 2979: } else {
1.257 albertel 2980: $sectionClass='Students in Section '.$env{'form.section'}.'</h3>';
1.52 albertel 2981: }
1.126 ng 2982: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2983: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2984: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2985: #radio buttons/text box for assigning points for a section or class.
2986: #handles different parts of a problem
1.375 albertel 2987: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.42 ng 2988: my %weight = ();
2989: my $ctsparts = 0;
1.41 ng 2990: $result.='<table border="0">';
1.45 ng 2991: my %seen = ();
1.375 albertel 2992: my @part_response_id = &flatten_responseType($responseType);
2993: foreach my $part_response_id (@part_response_id) {
2994: my ($partid,$respid) = @{ $part_response_id };
2995: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 2996: next if $seen{$partid};
2997: $seen{$partid}++;
1.375 albertel 2998: my $handgrade=$$handgrade{$part_resp};
1.42 ng 2999: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3000: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3001:
1.44 ng 3002: $result.='<input type="hidden" name="partid_'.
3003: $ctsparts.'" value="'.$partid.'" />'."\n";
3004: $result.='<input type="hidden" name="weight_'.
3005: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1.324 albertel 3006: my $display_part=&get_display_part($partid,$symb);
1.207 albertel 3007: $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>';
1.42 ng 3008: $result.='<table border="0"><tr>';
1.41 ng 3009: my $ctr = 0;
1.42 ng 3010: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.288 albertel 3011: $result.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3012: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3013: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3014: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3015: $ctr++;
3016: }
3017: $result.='</tr></table>';
1.44 ng 3018: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 3019: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
3020: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 3021: $weight{$partid}.' (problem weight)</td>'."\n";
3022: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 3023: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3024: $weight{$partid}.')"> '.
1.42 ng 3025: '<option selected="on"> </option>'.
1.125 ng 3026: '<option>excused</option>'.
1.265 www 3027: '<option>reset status</option></select></td>'.
1.266 albertel 3028: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
1.42 ng 3029: $ctsparts++;
1.41 ng 3030: }
1.52 albertel 3031: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
3032: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.391 banghart 3033: $result.='<input type="button" value="Revert to Default" '.
1.111 ng 3034: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41 ng 3035:
1.44 ng 3036: #table listing all the students in a section/class
3037: #header of table
1.126 ng 3038: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 3039: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 3040: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 3041: '<td>'.&nameUserString('header')."</td>\n";
1.324 albertel 3042: my (@parts) = sort(&getpartlist($symb));
3043: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3044: my @partids = ();
1.41 ng 3045: foreach my $part (@parts) {
3046: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 3047: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 3048: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3049: my ($partid) = &split_part_type($part);
1.269 raeburn 3050: push(@partids, $partid);
1.324 albertel 3051: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3052: if ($display =~ /^Partial Credit Factor/) {
1.207 albertel 3053: $result.='<td><b>Score Part:</b> '.$display_part.
3054: ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
1.41 ng 3055: next;
1.207 albertel 3056: } else {
3057: $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
1.41 ng 3058: }
1.53 albertel 3059: $display =~ s|Problem Status|Grade Status<br />|;
1.207 albertel 3060: $result.='<td><b>'.$display.'</td>'."\n";
1.41 ng 3061: }
3062: $result.='</tr>';
1.44 ng 3063:
1.270 albertel 3064: my %last_resets =
3065: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3066:
1.41 ng 3067: #get info for each student
1.44 ng 3068: #list all the students - with points and grade status
1.257 albertel 3069: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3070: my $ctr = 0;
1.294 albertel 3071: foreach (sort
3072: {
3073: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3074: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3075: }
3076: return $a cmp $b;
3077: } (keys(%$fullname))) {
1.126 ng 3078: $ctr++;
1.324 albertel 3079: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3080: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3081: }
3082: $result.='</table></td></tr></table>';
3083: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 3084: $result.='<input type="button" value="Save" '.
1.45 ng 3085: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96 albertel 3086: if (scalar(%$fullname) eq 0) {
3087: my $colspan=3+scalar(@parts);
1.257 albertel 3088: $result='<font color="red">There are no students in section "'.$env{'form.section'}.
3089: '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.</font>';
1.96 albertel 3090: }
1.324 albertel 3091: $result.=&show_grading_menu_form($symb);
1.41 ng 3092: return $result;
3093: }
3094:
1.44 ng 3095: #--- call by previous routine to display each student
1.41 ng 3096: sub viewstudentgrade {
1.324 albertel 3097: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3098: my ($uname,$udom) = split(/:/,$student);
3099: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3100: my %aggregates = ();
1.233 albertel 3101: my $result='<tr bgcolor="#ffffdd"><td align="right">'.
3102: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3103: "\n".$ctr.' </td><td> '.
1.44 ng 3104: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112 ng 3105: '\')"; TARGET=_self>'.$fullname.'</a> '.
1.257 albertel 3106: '<font color="#999999">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
1.281 albertel 3107: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3108: foreach my $apart (@$parts) {
3109: my ($part,$type) = &split_part_type($apart);
1.41 ng 3110: my $score=$record{"resource.$part.$type"};
1.276 albertel 3111: $result.='<td align="center">';
1.269 raeburn 3112: my ($aggtries,$totaltries);
3113: unless (exists($aggregates{$part})) {
1.270 albertel 3114: $totaltries = $record{'resource.'.$part.'.tries'};
3115:
3116: $aggtries = $totaltries;
1.269 raeburn 3117: if ($$last_resets{$part}) {
1.270 albertel 3118: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3119: $part);
3120: }
1.269 raeburn 3121: $result.='<input type="hidden" name="'.
3122: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3123: $result.='<input type="hidden" name="'.
3124: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3125: $aggregates{$part} = 1;
3126: }
1.41 ng 3127: if ($type eq 'awarded') {
1.320 albertel 3128: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3129: $result.='<input type="hidden" name="'.
1.89 albertel 3130: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3131: $result.='<input type="text" name="'.
1.89 albertel 3132: 'GD_'.$student.'_'.$part.'_awarded" '.
3133: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3134: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3135: } elsif ($type eq 'solved') {
3136: my ($status,$foo)=split(/_/,$score,2);
3137: $status = 'nothing' if ($status eq '');
1.89 albertel 3138: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3139: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3140: $result.=' <select name="'.
1.89 albertel 3141: 'GD_'.$student.'_'.$part.'_solved" '.
3142: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125 ng 3143: $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>'
3144: : '<option selected="on"> </option><option>excused</option>')."\n";
3145: $result.='<option>reset status</option>';
1.126 ng 3146: $result.="</select> </td>\n";
1.122 ng 3147: } else {
3148: $result.='<input type="hidden" name="'.
3149: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3150: "\n";
1.233 albertel 3151: $result.='<input type="text" name="'.
1.122 ng 3152: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3153: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3154: }
3155: }
3156: $result.='</tr>';
3157: return $result;
1.38 ng 3158: }
3159:
1.44 ng 3160: #--- change scores for all the students in a section/class
3161: # record does not get update if unchanged
1.38 ng 3162: sub editgrades {
1.41 ng 3163: my ($request) = @_;
3164:
1.324 albertel 3165: my $symb=&get_symb($request);
1.45 ng 3166: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.257 albertel 3167: $title.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font><br />'."\n";
3168: $title.='<font size=+1><b>Section: </b>'.$env{'form.section'}.'</font>'."\n";
1.126 ng 3169:
1.44 ng 3170: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 3171: $result.= '<table border="0"><tr bgcolor="#deffff">'.
3172: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
3173: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 3174:
3175: my %scoreptr = (
3176: 'correct' =>'correct_by_override',
3177: 'incorrect'=>'incorrect_by_override',
3178: 'excused' =>'excused',
3179: 'ungraded' =>'ungraded_attempted',
3180: 'nothing' => '',
3181: );
1.257 albertel 3182: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3183:
1.44 ng 3184: my (@partid);
3185: my %weight = ();
1.54 albertel 3186: my %columns = ();
1.44 ng 3187: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3188:
1.324 albertel 3189: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3190: my $header;
1.257 albertel 3191: while ($ctr < $env{'form.totalparts'}) {
3192: my $partid = $env{'form.partid_'.$ctr};
1.44 ng 3193: push @partid,$partid;
1.257 albertel 3194: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3195: $ctr++;
1.54 albertel 3196: }
1.324 albertel 3197: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3198: foreach my $partid (@partid) {
3199: $header .= '<td align="center"> <b>Old Score</b> </td>'.
3200: '<td align="center"> <b>New Score</b> </td>';
3201: $columns{$partid}=2;
3202: foreach my $stores (@parts) {
3203: my ($part,$type) = &split_part_type($stores);
3204: if ($part !~ m/^\Q$partid\E/) { next;}
3205: if ($type eq 'awarded' || $type eq 'solved') { next; }
3206: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
3207: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 3208: $display =~ s/Number of Attempts/Tries/;
3209: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
3210: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 3211: $columns{$partid}+=2;
3212: }
3213: }
3214: foreach my $partid (@partid) {
1.324 albertel 3215: my $display_part=&get_display_part($partid,$symb);
1.54 albertel 3216: $result .= '<td colspan="'.$columns{$partid}.
1.207 albertel 3217: '" align="center"><b>Part:</b> '.$display_part.
3218: ' (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 3219:
1.44 ng 3220: }
3221: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 3222: $result .= $header;
1.44 ng 3223: $result .= '</tr>'."\n";
1.93 albertel 3224: my $noupdate;
1.126 ng 3225: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3226: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3227: my $line;
1.257 albertel 3228: my $user = $env{'form.ctr'.$i};
1.281 albertel 3229: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3230: my %newrecord;
3231: my $updateflag = 0;
1.281 albertel 3232: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3233: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3234: if (!&canmodify($usec)) {
1.126 ng 3235: my $numcols=scalar(@partid)*4+2;
1.105 albertel 3236: $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
3237: next;
3238: }
1.269 raeburn 3239: my %aggregate = ();
3240: my $aggregateflag = 0;
1.281 albertel 3241: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3242: foreach (@partid) {
1.257 albertel 3243: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3244: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3245: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3246: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3247: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3248: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3249: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3250: my $score;
3251: if ($partial eq '') {
1.257 albertel 3252: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3253: } elsif ($partial > 0) {
3254: $score = 'correct_by_override';
3255: } elsif ($partial == 0) {
3256: $score = 'incorrect_by_override';
3257: }
1.257 albertel 3258: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3259: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3260:
1.292 albertel 3261: $newrecord{'resource.'.$_.'.regrader'}=
3262: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3263: if ($dropMenu eq 'reset status' &&
3264: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3265: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3266: $newrecord{'resource.'.$_.'.solved'} = '';
3267: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3268: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3269: $updateflag = 1;
1.269 raeburn 3270: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3271: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3272: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3273: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3274: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3275: $aggregateflag = 1;
3276: }
1.139 albertel 3277: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3278: $updateflag = 1;
3279: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3280: $newrecord{'resource.'.$_.'.solved'} = $score;
3281: $rec_update++;
1.125 ng 3282: }
3283:
1.93 albertel 3284: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3285: '<td align="center">'.$awarded.
3286: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3287:
1.54 albertel 3288:
3289: my $partid=$_;
3290: foreach my $stores (@parts) {
3291: my ($part,$type) = &split_part_type($stores);
3292: if ($part !~ m/^\Q$partid\E/) { next;}
3293: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3294: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3295: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3296: if ($awarded ne '' && $awarded ne $old_aw) {
3297: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3298: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3299: $updateflag=1;
3300: }
1.93 albertel 3301: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3302: '<td align="center">'.$awarded.' </td>';
3303: }
1.44 ng 3304: }
1.93 albertel 3305: $line.='</tr>'."\n";
1.301 albertel 3306:
3307: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3308: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3309:
1.44 ng 3310: if ($updateflag) {
3311: $count++;
1.257 albertel 3312: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3313: $udom,$uname);
1.301 albertel 3314:
3315: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3316: $cnum,$udom,$uname)) {
3317: # need to figure out if should be in queue.
3318: my %record =
3319: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3320: $udom,$uname);
3321: my $all_graded = 1;
3322: my $none_graded = 1;
3323: foreach my $part (@parts) {
3324: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3325: $all_graded = 0;
3326: } else {
3327: $none_graded = 0;
3328: }
3329: }
3330:
3331: if ($all_graded || $none_graded) {
3332: &Apache::bridgetask::remove_from_queue('gradingqueue',
3333: $symb,$cdom,$cnum,
3334: $udom,$uname);
3335: }
3336: }
3337:
1.126 ng 3338: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
3339: $updateCtr++;
1.93 albertel 3340: } else {
1.126 ng 3341: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
3342: $noupdateCtr++;
1.44 ng 3343: }
1.269 raeburn 3344: if ($aggregateflag) {
3345: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3346: $cdom,$cnum);
1.269 raeburn 3347: }
1.93 albertel 3348: }
3349: if ($noupdate) {
1.126 ng 3350: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3351: my $numcols=scalar(@partid)*4+2;
1.204 albertel 3352: $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 3353: }
1.72 ng 3354: $result .= '</table></td></tr></table>'."\n".
1.324 albertel 3355: &show_grading_menu_form ($symb);
1.125 ng 3356: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 3357: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1.257 albertel 3358: '<b>Total number of students = '.$env{'form.total'}.'</b><br />';
1.44 ng 3359: return $title.$msg.$result;
1.5 albertel 3360: }
1.54 albertel 3361:
3362: sub split_part_type {
3363: my ($partstr) = @_;
3364: my ($temp,@allparts)=split(/_/,$partstr);
3365: my $type=pop(@allparts);
3366: my $part=join('.',@allparts);
3367: return ($part,$type);
3368: }
3369:
1.44 ng 3370: #------------- end of section for handling grading by section/class ---------
3371: #
3372: #----------------------------------------------------------------------------
3373:
1.5 albertel 3374:
1.44 ng 3375: #----------------------------------------------------------------------------
3376: #
3377: #-------------------------- Next few routines handles grading by csv upload
3378: #
3379: #--- Javascript to handle csv upload
1.27 albertel 3380: sub csvupload_javascript_reverse_associate {
1.246 albertel 3381: my $error1=&mt('You need to specify the username or ID');
3382: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3383: return(<<ENDPICK);
3384: function verify(vf) {
3385: var foundsomething=0;
3386: var founduname=0;
1.243 albertel 3387: var foundID=0;
1.27 albertel 3388: for (i=0;i<=vf.nfields.value;i++) {
3389: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3390: if (i==0 && tw!=0) { foundID=1; }
3391: if (i==1 && tw!=0) { founduname=1; }
3392: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3393: }
1.246 albertel 3394: if (founduname==0 && foundID==0) {
3395: alert('$error1');
3396: return;
1.27 albertel 3397: }
3398: if (foundsomething==0) {
1.246 albertel 3399: alert('$error2');
3400: return;
1.27 albertel 3401: }
3402: vf.submit();
3403: }
3404: function flip(vf,tf) {
3405: var nw=eval('vf.f'+tf+'.selectedIndex');
3406: var i;
3407: for (i=0;i<=vf.nfields.value;i++) {
3408: //can not pick the same destination field for both name and domain
3409: if (((i ==0)||(i ==1)) &&
3410: ((tf==0)||(tf==1)) &&
3411: (i!=tf) &&
3412: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3413: eval('vf.f'+i+'.selectedIndex=0;')
3414: }
3415: }
3416: }
3417: ENDPICK
3418: }
3419:
3420: sub csvupload_javascript_forward_associate {
1.246 albertel 3421: my $error1=&mt('You need to specify the username or ID');
3422: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3423: return(<<ENDPICK);
3424: function verify(vf) {
3425: var foundsomething=0;
3426: var founduname=0;
1.243 albertel 3427: var foundID=0;
1.27 albertel 3428: for (i=0;i<=vf.nfields.value;i++) {
3429: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3430: if (tw==1) { foundID=1; }
3431: if (tw==2) { founduname=1; }
3432: if (tw>3) { foundsomething=1; }
1.27 albertel 3433: }
1.246 albertel 3434: if (founduname==0 && foundID==0) {
3435: alert('$error1');
3436: return;
1.27 albertel 3437: }
3438: if (foundsomething==0) {
1.246 albertel 3439: alert('$error2');
3440: return;
1.27 albertel 3441: }
3442: vf.submit();
3443: }
3444: function flip(vf,tf) {
3445: var nw=eval('vf.f'+tf+'.selectedIndex');
3446: var i;
3447: //can not pick the same destination field twice
3448: for (i=0;i<=vf.nfields.value;i++) {
3449: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3450: eval('vf.f'+i+'.selectedIndex=0;')
3451: }
3452: }
3453: }
3454: ENDPICK
3455: }
3456:
1.26 albertel 3457: sub csvuploadmap_header {
1.324 albertel 3458: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3459: my $javascript;
1.257 albertel 3460: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3461: $javascript=&csvupload_javascript_reverse_associate();
3462: } else {
3463: $javascript=&csvupload_javascript_forward_associate();
3464: }
1.45 ng 3465:
1.324 albertel 3466: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3467: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3468: my $ignore=&mt('Ignore First Line');
1.41 ng 3469: $request->print(<<ENDPICK);
1.26 albertel 3470: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 3471: <h3><font color="#339933">Uploading Class Grades</font></h3>
3472: $result
1.326 albertel 3473: <hr />
1.26 albertel 3474: <h3>Identify fields</h3>
3475: Total number of records found in file: $distotal <hr />
3476: Enter as many fields as you can. The system will inform you and bring you back
3477: to this page if the data selected is insufficient to run your class.<hr />
3478: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3479: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3480: <input type="hidden" name="associate" value="" />
3481: <input type="hidden" name="phase" value="three" />
3482: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3483: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3484: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3485: <input type="hidden" name="upfile_associate"
1.257 albertel 3486: value="$env{'form.upfile_associate'}" />
1.26 albertel 3487: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3488: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3489: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3490: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3491: <hr />
3492: <script type="text/javascript" language="Javascript">
3493: $javascript
3494: </script>
3495: ENDPICK
1.118 ng 3496: return '';
1.26 albertel 3497:
3498: }
3499:
3500: sub csvupload_fields {
1.324 albertel 3501: my ($symb) = @_;
3502: my (@parts) = &getpartlist($symb);
1.243 albertel 3503: my @fields=(['ID','Student ID'],
3504: ['username','Student Username'],
3505: ['domain','Student Domain']);
1.324 albertel 3506: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3507: foreach my $part (sort(@parts)) {
3508: my @datum;
3509: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3510: my $name=$part;
3511: if (!$display) { $display = $name; }
3512: @datum=($name,$display);
1.244 albertel 3513: if ($name=~/^stores_(.*)_awarded/) {
3514: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3515: }
1.41 ng 3516: push(@fields,\@datum);
3517: }
3518: return (@fields);
1.26 albertel 3519: }
3520:
3521: sub csvuploadmap_footer {
1.41 ng 3522: my ($request,$i,$keyfields) =@_;
3523: $request->print(<<ENDPICK);
1.26 albertel 3524: </table>
3525: <input type="hidden" name="nfields" value="$i" />
3526: <input type="hidden" name="keyfields" value="$keyfields" />
3527: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3528: </form>
3529: ENDPICK
3530: }
3531:
1.283 albertel 3532: sub checkforfile_js {
1.86 ng 3533: my $result =<<CSVFORMJS;
3534: <script type="text/javascript" language="javascript">
3535: function checkUpload(formname) {
3536: if (formname.upfile.value == "") {
3537: alert("Please use the browse button to select a file from your local directory.");
3538: return false;
3539: }
3540: formname.submit();
3541: }
3542: </script>
3543: CSVFORMJS
1.283 albertel 3544: return $result;
3545: }
3546:
3547: sub upcsvScores_form {
3548: my ($request) = shift;
1.324 albertel 3549: my ($symb)=&get_symb($request);
1.283 albertel 3550: if (!$symb) {return '';}
3551: my $result=&checkforfile_js();
1.257 albertel 3552: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3553: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3554: $result.=$table;
1.326 albertel 3555: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3556: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.370 www 3557: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource').
1.86 ng 3558: '.</b></td></tr>'."\n";
3559: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3560: my $upload=&mt("Upload Scores");
1.86 ng 3561: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3562: my $ignore=&mt('Ignore First Line');
1.86 ng 3563: $result.=<<ENDUPFORM;
1.106 albertel 3564: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3565: <input type="hidden" name="symb" value="$symb" />
3566: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3567: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3568: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3569: $upfile_select
1.370 www 3570: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3571: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3572: </form>
3573: ENDUPFORM
1.370 www 3574: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3575: &mt("How do I create a CSV file from a spreadsheet"))
3576: .'</td></tr></table>'."\n";
1.86 ng 3577: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3578: $result.=&show_grading_menu_form($symb);
1.86 ng 3579: return $result;
3580: }
3581:
3582:
1.26 albertel 3583: sub csvuploadmap {
1.41 ng 3584: my ($request)= @_;
1.324 albertel 3585: my ($symb)=&get_symb($request);
1.41 ng 3586: if (!$symb) {return '';}
1.72 ng 3587:
1.41 ng 3588: my $datatoken;
1.257 albertel 3589: if (!$env{'form.datatoken'}) {
1.41 ng 3590: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3591: } else {
1.257 albertel 3592: $datatoken=$env{'form.datatoken'};
1.41 ng 3593: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3594: }
1.41 ng 3595: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3596: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3597: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3598: my ($i,$keyfields);
3599: if (@records) {
1.324 albertel 3600: my @fields=&csvupload_fields($symb);
1.45 ng 3601:
1.257 albertel 3602: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3603: &Apache::loncommon::csv_print_samples($request,\@records);
3604: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3605: \@fields);
3606: foreach (@fields) { $keyfields.=$_->[0].','; }
3607: chop($keyfields);
3608: } else {
3609: unshift(@fields,['none','']);
3610: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3611: \@fields);
1.311 banghart 3612: foreach my $rec (@records) {
3613: my %temp = &Apache::loncommon::record_sep($rec);
3614: if (%temp) {
3615: $keyfields=join(',',sort(keys(%temp)));
3616: last;
3617: }
3618: }
1.41 ng 3619: }
3620: }
3621: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3622: $request->print(&show_grading_menu_form($symb));
1.72 ng 3623:
1.41 ng 3624: return '';
1.27 albertel 3625: }
3626:
1.246 albertel 3627: sub csvuploadoptions {
1.41 ng 3628: my ($request)= @_;
1.324 albertel 3629: my ($symb)=&get_symb($request);
1.257 albertel 3630: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3631: my $ignore=&mt('Ignore First Line');
3632: $request->print(<<ENDPICK);
3633: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
3634: <h3><font color="#339933">Uploading Class Grade Options</font></h3>
3635: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3636: <!--
1.246 albertel 3637: <p>
3638: <label>
3639: <input type="checkbox" name="show_full_results" />
3640: Show a table of all changes
3641: </label>
3642: </p>
1.302 albertel 3643: -->
1.246 albertel 3644: <p>
3645: <label>
3646: <input type="checkbox" name="overwite_scores" checked="checked" />
3647: Overwrite any existing score
3648: </label>
3649: </p>
3650: ENDPICK
3651: my %fields=&get_fields();
3652: if (!defined($fields{'domain'})) {
1.257 albertel 3653: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3654: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3655: }
1.257 albertel 3656: foreach my $key (sort(keys(%env))) {
1.246 albertel 3657: if ($key !~ /^form\.(.*)$/) { next; }
3658: my $cleankey=$1;
3659: if ($cleankey eq 'command') { next; }
3660: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3661: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3662: }
3663: # FIXME do a check for any duplicated user ids...
3664: # FIXME do a check for any invalid user ids?...
1.290 albertel 3665: $request->print('<input type="submit" value="Assign Grades" /><br />
3666: <hr /></form>'."\n");
1.324 albertel 3667: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3668: return '';
3669: }
3670:
3671: sub get_fields {
3672: my %fields;
1.257 albertel 3673: my @keyfields = split(/\,/,$env{'form.keyfields'});
3674: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3675: if ($env{'form.upfile_associate'} eq 'reverse') {
3676: if ($env{'form.f'.$i} ne 'none') {
3677: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3678: }
3679: } else {
1.257 albertel 3680: if ($env{'form.f'.$i} ne 'none') {
3681: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3682: }
3683: }
1.27 albertel 3684: }
1.246 albertel 3685: return %fields;
3686: }
3687:
3688: sub csvuploadassign {
3689: my ($request)= @_;
1.324 albertel 3690: my ($symb)=&get_symb($request);
1.246 albertel 3691: if (!$symb) {return '';}
1.345 bowersj2 3692: my $error_msg = '';
1.246 albertel 3693: &Apache::loncommon::load_tmp_file($request);
3694: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3695: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3696: my %fields=&get_fields();
1.41 ng 3697: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3698: my $courseid=$env{'request.course.id'};
1.97 albertel 3699: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3700: my @notallowed;
1.41 ng 3701: my @skipped;
3702: my $countdone=0;
3703: foreach my $grade (@gradedata) {
3704: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3705: my $domain;
3706: if ($entries{$fields{'domain'}}) {
3707: $domain=$entries{$fields{'domain'}};
3708: } else {
1.257 albertel 3709: $domain=$env{'form.default_domain'};
1.246 albertel 3710: }
1.243 albertel 3711: $domain=~s/\s//g;
1.41 ng 3712: my $username=$entries{$fields{'username'}};
1.160 albertel 3713: $username=~s/\s//g;
1.243 albertel 3714: if (!$username) {
3715: my $id=$entries{$fields{'ID'}};
1.247 albertel 3716: $id=~s/\s//g;
1.243 albertel 3717: my %ids=&Apache::lonnet::idget($domain,$id);
3718: $username=$ids{$id};
3719: }
1.41 ng 3720: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3721: my $id=$entries{$fields{'ID'}};
3722: $id=~s/\s//g;
3723: if ($id) {
3724: push(@skipped,"$id:$domain");
3725: } else {
3726: push(@skipped,"$username:$domain");
3727: }
1.41 ng 3728: next;
3729: }
1.108 albertel 3730: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3731: if (!&canmodify($usec)) {
3732: push(@notallowed,"$username:$domain");
3733: next;
3734: }
1.244 albertel 3735: my %points;
1.41 ng 3736: my %grades;
3737: foreach my $dest (keys(%fields)) {
1.244 albertel 3738: if ($dest eq 'ID' || $dest eq 'username' ||
3739: $dest eq 'domain') { next; }
3740: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3741: if ($dest=~/stores_(.*)_points/) {
3742: my $part=$1;
3743: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3744: $symb,$domain,$username);
1.345 bowersj2 3745: if ($wgt) {
3746: $entries{$fields{$dest}}=~s/\s//g;
3747: my $pcr=$entries{$fields{$dest}} / $wgt;
3748: my $award='correct_by_override';
3749: $grades{"resource.$part.awarded"}=$pcr;
3750: $grades{"resource.$part.solved"}=$award;
3751: $points{$part}=1;
3752: } else {
3753: $error_msg = "<br />" .
3754: &mt("Some point values were assigned"
3755: ." for problems with a weight "
3756: ."of zero. These values were "
3757: ."ignored.");
3758: }
1.244 albertel 3759: } else {
3760: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
3761: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
3762: my $store_key=$dest;
3763: $store_key=~s/^stores/resource/;
3764: $store_key=~s/_/\./g;
3765: $grades{$store_key}=$entries{$fields{$dest}};
3766: }
1.41 ng 3767: }
1.244 albertel 3768: if (! %grades) { push(@skipped,"$username:$domain no data to store"); }
1.257 albertel 3769: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
1.244 albertel 3770: # &Apache::lonnet::logthis(" storing ".(join('-',%grades)));
1.302 albertel 3771: my $result=&Apache::lonnet::cstore(\%grades,$symb,
3772: $env{'request.course.id'},
3773: $domain,$username);
3774: if ($result eq 'ok') {
3775: $request->print('.');
3776: } else {
3777: $request->print("<p>
3778: <font color='red'>
3779: Failed to store student $username\@$domain.
3780: Message when trying to store was ($result)
3781: </font>
3782: </p>" );
3783: }
1.41 ng 3784: $request->rflush();
3785: $countdone++;
3786: }
3787: $request->print("<br />Stored $countdone students\n");
3788: if (@skipped) {
1.325 www 3789: $request->print('<p><font size="+1"><b>Skipped Students</b></font></p>');
1.106 albertel 3790: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
3791: }
3792: if (@notallowed) {
3793: $request->print('<p><font size="+1" color="red"><b>Students Not Allowed to Modify</b></font></p>');
3794: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 3795: }
1.106 albertel 3796: $request->print("<br />\n");
1.324 albertel 3797: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 3798: return $error_msg;
1.26 albertel 3799: }
1.44 ng 3800: #------------- end of section for handling csv file upload ---------
3801: #
3802: #-------------------------------------------------------------------
3803: #
1.122 ng 3804: #-------------- Next few routines handle grading by page/sequence
1.72 ng 3805: #
3806: #--- Select a page/sequence and a student to grade
1.68 ng 3807: sub pickStudentPage {
3808: my ($request) = shift;
3809:
3810: $request->print(<<LISTJAVASCRIPT);
3811: <script type="text/javascript" language="javascript">
3812:
3813: function checkPickOne(formname) {
1.76 ng 3814: if (radioSelection(formname.student) == null) {
1.68 ng 3815: alert("Please select the student you wish to grade.");
3816: return;
3817: }
1.125 ng 3818: ptr = pullDownSelection(formname.selectpage);
3819: formname.page.value = formname["page"+ptr].value;
3820: formname.title.value = formname["title"+ptr].value;
1.68 ng 3821: formname.submit();
3822: }
3823:
3824: </script>
3825: LISTJAVASCRIPT
1.118 ng 3826: &commonJSfunctions($request);
1.324 albertel 3827: my ($symb) = &get_symb($request);
1.257 albertel 3828: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3829: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3830: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 3831:
3832: my $result='<h3><font color="#339933"> '.
3833: 'Manual Grading by Page or Sequence</font></h3>';
3834:
1.80 ng 3835: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 3836: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 3837: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 3838: my ($curpage) =&Apache::lonnet::decode_symb($symb);
3839: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
3840: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 3841: my $ctr=0;
1.68 ng 3842: foreach (@$titles) {
3843: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 3844: $result.='<option value="'.$ctr.'" '.
1.71 ng 3845: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
3846: '>'.$showtitle.'</option>'."\n";
1.70 ng 3847: $ctr++;
1.68 ng 3848: }
1.326 albertel 3849: $result.= '</select>'."<br />\n";
1.70 ng 3850: $ctr=0;
3851: foreach (@$titles) {
3852: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3853: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
3854: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
3855: $ctr++;
3856: }
1.72 ng 3857: $result.='<input type="hidden" name="page" />'."\n".
3858: '<input type="hidden" name="title" />'."\n";
1.68 ng 3859:
1.288 albertel 3860: $result.=' <b>View Problems Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
3861: '<label><input type="radio" name="vProb" value="yes" /> yes </label>'."<br />\n";
1.72 ng 3862:
1.71 ng 3863: $result.=' <b>Submission Details: </b>'.
1.288 albertel 3864: '<label><input type="radio" name="lastSub" value="none" /> none</label>'."\n".
3865: '<label><input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions</label>'."\n".
3866: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n";
1.72 ng 3867:
1.68 ng 3868: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.257 albertel 3869: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.72 ng 3870: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.80 ng 3871: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 3872: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 3873:
1.382 albertel 3874: $result.=' <b>'.&mt('Use CODE:').' </b>'.
3875: '<input type="text" name="CODE" value="" /><br />'."\n";
3876:
1.80 ng 3877: $result.=' <input type="button" '.
1.126 ng 3878: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 3879:
1.68 ng 3880: $request->print($result);
3881:
1.326 albertel 3882: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br />'.
1.68 ng 3883: '<table border="0"><tr><td bgcolor="#777777">'.
3884: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 3885: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3886: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 3887: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3888: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 3889:
1.76 ng 3890: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 3891: my $ptr = 1;
1.294 albertel 3892: foreach my $student (sort
3893: {
3894: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3895: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3896: }
3897: return $a cmp $b;
3898: } (keys(%$fullname))) {
1.68 ng 3899: my ($uname,$udom) = split(/:/,$student);
1.126 ng 3900: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
3901: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 3902: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
3903: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.126 ng 3904: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 3905: $ptr++;
3906: }
1.381 albertel 3907: $studentTable.='</td><td> </td><td> </td></tr>' if ($ptr%2 == 0);
3908: $studentTable.='</table></td></tr></table>'."\n";
1.126 ng 3909: $studentTable.='<input type="button" '.
3910: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 3911:
1.324 albertel 3912: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 3913: $request->print($studentTable);
3914:
3915: return '';
3916: }
3917:
3918: sub getSymbMap {
1.74 albertel 3919: my ($request) = @_;
1.132 bowersj2 3920: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 3921:
3922: my %symbx = ();
3923: my @titles = ();
1.117 bowersj2 3924: my $minder = 0;
3925:
3926: # Gather every sequence that has problems.
1.240 albertel 3927: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
3928: 1,0,1);
1.117 bowersj2 3929: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 3930: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 3931: my $title = $minder.'.'.
3932: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
3933: push(@titles, $title); # minder in case two titles are identical
3934: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 3935: $minder++;
1.241 albertel 3936: }
1.68 ng 3937: }
3938: return \@titles,\%symbx;
3939: }
3940:
1.72 ng 3941: #
3942: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 3943: sub displayPage {
3944: my ($request) = shift;
3945:
1.324 albertel 3946: my ($symb) = &get_symb($request);
1.257 albertel 3947: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3948: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3949: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3950: my $pageTitle = $env{'form.page'};
1.103 albertel 3951: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3952: my ($uname,$udom) = split(/:/,$env{'form.student'});
3953: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 3954:
3955: #need to make sure we have the correct data for later EXT calls,
3956: #thus invalidate the cache
3957: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3958: $env{'course.'.$env{'request.course.id'}.'.num'},
3959: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3960: &Apache::lonnet::clear_EXT_cache_status();
3961:
1.103 albertel 3962: if (!&canview($usec)) {
1.257 albertel 3963: $request->print('<font color="red">Unable to view requested student.('.$env{'form.student'}.')</font>');
1.324 albertel 3964: $request->print(&show_grading_menu_form($symb));
1.103 albertel 3965: return;
3966: }
1.257 albertel 3967: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
3968: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom).
1.129 ng 3969: '</h3>'."\n";
1.382 albertel 3970: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
3971: $result.='<h3> CODE: '.$env{'form.CODE'}.'</h3>'."\n";
3972: } else {
3973: delete($env{'form.CODE'});
3974: }
1.71 ng 3975: &sub_page_js($request);
3976: $request->print($result);
3977:
1.132 bowersj2 3978: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3979: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 3980: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3981: if (!$map) {
3982: $request->print('<font color="red">Unable to view requested sequence. ('.$resUrl.')</font>');
1.324 albertel 3983: $request->print(&show_grading_menu_form($symb));
1.288 albertel 3984: return;
3985: }
1.68 ng 3986: my $iterator = $navmap->getIterator($map->map_start(),
3987: $map->map_finish());
3988:
1.71 ng 3989: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3990: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 3991: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
3992: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 3993: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 3994: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.72 ng 3995: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.125 ng 3996: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 3997: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 3998:
1.382 albertel 3999: if (defined($env{'form.CODE'})) {
4000: $studentTable.=
4001: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4002: }
1.381 albertel 4003: my $checkIcon = '<img alt="'.&mt('Check Mark').
4004: '" src="'.$request->dir_config('lonIconsURL').
1.71 ng 4005: '/check.gif" height="16" border="0" />';
4006:
1.118 ng 4007: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
4008: ' symbol.'."\n".
1.71 ng 4009: '<table border="0"><tr><td bgcolor="#777777">'.
4010: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 4011: '<td align="center"><b> Prob. </b></td>'.
1.257 albertel 4012: '<td><b> '.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 4013:
1.329 albertel 4014: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4015: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4016: $iterator->next(); # skip the first BEGIN_MAP
4017: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4018: while ($depth > 0) {
1.68 ng 4019: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4020: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4021:
1.385 albertel 4022: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4023: my $parts = $curRes->parts();
1.68 ng 4024: my $title = $curRes->compTitle();
1.71 ng 4025: my $symbx = $curRes->symb();
1.196 albertel 4026: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4027: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4028: $studentTable.='<td valign="top">';
1.382 albertel 4029: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4030: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4031: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4032: undef,'both',\%form);
1.71 ng 4033: } else {
1.382 albertel 4034: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4035: $companswer =~ s|<form(.*?)>||g;
4036: $companswer =~ s|</form>||g;
1.71 ng 4037: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4038: # $companswer =~ s/$1/ /ms;
1.326 albertel 4039: # $request->print('match='.$1."<br />\n");
1.71 ng 4040: # }
1.116 ng 4041: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.326 albertel 4042: $studentTable.=' <b>'.$title.'</b> <br /> <b>Correct answer:</b><br />'.$companswer;
1.71 ng 4043: }
4044:
1.257 albertel 4045: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4046:
1.257 albertel 4047: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4048: if ($record{'version'} eq '') {
4049: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
4050: } else {
1.116 ng 4051: my %responseType = ();
4052: foreach my $partid (@{$parts}) {
1.147 albertel 4053: my @responseIds =$curRes->responseIds($partid);
4054: my @responseType =$curRes->responseType($partid);
4055: my %responseIds;
4056: for (my $i=0;$i<=$#responseIds;$i++) {
4057: $responseIds{$responseIds[$i]}=$responseType[$i];
4058: }
4059: $responseType{$partid} = \%responseIds;
1.116 ng 4060: }
1.148 albertel 4061: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4062:
1.71 ng 4063: }
1.257 albertel 4064: } elsif ($env{'form.lastSub'} eq 'all') {
4065: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4066: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4067: $env{'request.course.id'},
1.71 ng 4068: '','.submission');
4069:
4070: }
1.103 albertel 4071: if (&canmodify($usec)) {
4072: foreach my $partid (@{$parts}) {
4073: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4074: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4075: $question++;
4076: }
1.196 albertel 4077: $prob++;
1.71 ng 4078: }
4079: $studentTable.='</td></tr>';
1.68 ng 4080:
1.103 albertel 4081: }
1.68 ng 4082: $curRes = $iterator->next();
4083: }
4084:
1.381 albertel 4085: $studentTable.='</table></td></tr></table>'."\n".
1.125 ng 4086: '<input type="button" value="Save" '.
1.381 albertel 4087: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
1.71 ng 4088: '</form>'."\n";
1.324 albertel 4089: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4090: $request->print($studentTable);
4091:
4092: return '';
1.119 ng 4093: }
4094:
4095: sub displaySubByDates {
1.148 albertel 4096: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4097: my $isCODE=0;
1.335 albertel 4098: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4099: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.119 ng 4100: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
4101: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
4102: '<td><b>Date/Time</b></td>'.
1.224 albertel 4103: ($isCODE?'<td><b>CODE</b></td>':'').
1.119 ng 4104: '<td><b>Submission</b></td>'.
4105: '<td><b>Status </b></td></tr>';
4106: my ($version);
4107: my %mark;
1.148 albertel 4108: my %orders;
1.119 ng 4109: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4110: if (!exists($$record{'1:timestamp'})) {
4111: return '<br /> <font color="red">Nothing submitted - no attempts</font><br />';
4112: }
1.335 albertel 4113:
4114: my $interaction;
1.119 ng 4115: for ($version=1;$version<=$$record{'version'};$version++) {
4116: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
1.335 albertel 4117: if (exists($$record{$version.':resource.0.version'})) {
4118: $interaction = $$record{$version.':resource.0.version'};
4119: }
4120:
4121: my $where = ($isTask ? "$version:resource.$interaction"
4122: : "$version:resource");
4123: #&Apache::lonnet::logthis(" got $where");
1.119 ng 4124: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
1.224 albertel 4125: if ($isCODE) {
4126: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4127: }
1.119 ng 4128: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4129: my @displaySub = ();
4130: foreach my $partid (@{$parts}) {
1.335 albertel 4131: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4132: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4133:
4134:
1.122 ng 4135: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4136: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4137: foreach my $matchKey (@matchKey) {
1.198 albertel 4138: if (exists($$record{$version.':'.$matchKey}) &&
4139: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4140:
4141: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4142: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
4143: #&Apache::lonnet::logthis("match $matchKey $responseId (".$$record{$version.':'.$matchKey});
1.207 albertel 4144: $displaySub[0].='<b>Part:</b> '.$display_part.' ';
1.147 albertel 4145: $displaySub[0].='<font color="#999999">(ID '.
1.207 albertel 4146: $responseId.')</font> <b>';
1.335 albertel 4147: if ($$record{"$where.$partid.tries"} eq '') {
1.147 albertel 4148: $displaySub[0].='Trial not counted';
4149: } else {
4150: $displaySub[0].='Trial '.
1.335 albertel 4151: $$record{"$where.$partid.tries"};
1.147 albertel 4152: }
1.335 albertel 4153: my $responseType=($isTask ? 'Task'
4154: : $responseType->{$partid}->{$responseId});
1.148 albertel 4155: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4156: if (!exists($orders{$partid}->{$responseId})) {
4157: $orders{$partid}->{$responseId}=
4158: &get_order($partid,$responseId,$symb,$uname,$udom);
4159: }
1.147 albertel 4160: $displaySub[0].='</b> '.
1.336 albertel 4161: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4162: }
4163: }
1.335 albertel 4164: if (exists($$record{"$where.$partid.checkedin"})) {
4165: $displaySub[1].='Checked in by '.
4166: $$record{"$where.$partid.checkedin"}.' into slot '.
4167: $$record{"$where.$partid.checkedin.slot"}.
4168: '<br />';
4169: }
4170: if (exists $$record{"$where.$partid.award"}) {
1.207 albertel 4171: $displaySub[1].='<b>Part:</b> '.$display_part.' '.
1.335 albertel 4172: lc($$record{"$where.$partid.award"}).' '.
4173: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4174: '<br />';
4175: }
1.335 albertel 4176: if (exists $$record{"$where.$partid.regrader"}) {
4177: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4178: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4179: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4180: $displaySub[2].=
4181: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4182: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4183: }
4184: }
4185: # needed because old essay regrader has not parts info
4186: if (exists $$record{"$version:resource.regrader"}) {
4187: $displaySub[2].=$$record{"$version:resource.regrader"};
4188: }
4189: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4190: if ($displaySub[2]) {
4191: $studentTable.='Manually graded by '.$displaySub[2];
4192: }
1.382 albertel 4193: $studentTable.=' </td></tr>';
1.147 albertel 4194:
1.119 ng 4195: }
4196: $studentTable.='</table></td></tr></table>';
4197: return $studentTable;
1.71 ng 4198: }
4199:
4200: sub updateGradeByPage {
4201: my ($request) = shift;
4202:
1.257 albertel 4203: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4204: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4205: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4206: my $pageTitle = $env{'form.page'};
1.103 albertel 4207: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4208: my ($uname,$udom) = split(/:/,$env{'form.student'});
4209: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4210: if (!&canmodify($usec)) {
1.257 albertel 4211: $request->print('<font color="red">Unable to modify requested student.('.$env{'form.student'}.'</font>');
1.324 albertel 4212: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4213: return;
4214: }
1.257 albertel 4215: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
4216: $result.='<h3> Student: '.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4217: '</h3>'."\n";
1.70 ng 4218:
1.68 ng 4219: $request->print($result);
4220:
1.132 bowersj2 4221: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4222: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4223: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4224: if (!$map) {
4225: $request->print('<font color="red">Unable to grade requested sequence. ('.$resUrl.')</font>');
1.324 albertel 4226: my ($symb)=&get_symb($request);
4227: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4228: return;
4229: }
1.71 ng 4230: my $iterator = $navmap->getIterator($map->map_start(),
4231: $map->map_finish());
1.70 ng 4232:
1.71 ng 4233: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 4234: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 4235: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 4236: '<td><b> Title </b></td>'.
4237: '<td><b> Previous Score </b></td>'.
4238: '<td><b> New Score </b></td></tr>';
4239:
4240: $iterator->next(); # skip the first BEGIN_MAP
4241: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4242: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4243: while ($depth > 0) {
1.71 ng 4244: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4245: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4246:
1.385 albertel 4247: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4248: my $parts = $curRes->parts();
1.71 ng 4249: my $title = $curRes->compTitle();
4250: my $symbx = $curRes->symb();
1.196 albertel 4251: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.326 albertel 4252: (scalar(@{$parts}) == 1 ? '' : '<br />('.scalar(@{$parts}).' parts)').'</td>';
1.71 ng 4253: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4254:
4255: my %newrecord=();
4256: my @displayPts=();
1.269 raeburn 4257: my %aggregate = ();
4258: my $aggregateflag = 0;
1.71 ng 4259: foreach my $partid (@{$parts}) {
1.257 albertel 4260: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4261: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4262:
1.257 albertel 4263: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4264: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4265: my $partial = $newpts/$wgt;
4266: my $score;
4267: if ($partial > 0) {
4268: $score = 'correct_by_override';
1.125 ng 4269: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4270: $score = 'incorrect_by_override';
4271: }
1.257 albertel 4272: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4273: if ($dropMenu eq 'excused') {
1.71 ng 4274: $partial = '';
4275: $score = 'excused';
1.125 ng 4276: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4277: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4278: $newrecord{'resource.'.$partid.'.tries'} = 0;
4279: $newrecord{'resource.'.$partid.'.solved'} = '';
4280: $newrecord{'resource.'.$partid.'.award'} = '';
4281: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4282: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4283: $changeflag++;
4284: $newpts = '';
1.269 raeburn 4285:
4286: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4287: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4288: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4289: if ($aggtries > 0) {
4290: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4291: $aggregateflag = 1;
4292: }
1.71 ng 4293: }
1.324 albertel 4294: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4295: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.207 albertel 4296: $displayPts[0].=' <b>Part:</b> '.$display_part.' = '.
1.71 ng 4297: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4298: ' <br />';
1.207 albertel 4299: $displayPts[1].=' <b>Part:</b> '.$display_part.' = '.
1.125 ng 4300: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4301: ' <br />';
1.71 ng 4302: $question++;
1.380 albertel 4303: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4304:
1.71 ng 4305: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4306: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4307: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4308: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4309:
4310: $changeflag++;
4311: }
4312: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4313: my %record =
4314: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4315: $udom,$uname);
4316:
4317: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4318: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4319: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4320: $newrecord{'resource.CODE'} = '';
4321: }
1.257 albertel 4322: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4323: $udom,$uname);
1.382 albertel 4324: %record = &Apache::lonnet::restore($symbx,
4325: $env{'request.course.id'},
4326: $udom,$uname);
1.380 albertel 4327: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4328: $cdom,$cnum,$udom,$uname);
1.71 ng 4329: }
1.380 albertel 4330:
1.269 raeburn 4331: if ($aggregateflag) {
4332: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4333: $env{'course.'.$env{'request.course.id'}.'.domain'},
4334: $env{'course.'.$env{'request.course.id'}.'.num'});
4335: }
1.125 ng 4336:
1.71 ng 4337: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4338: '<td valign="top">'.$displayPts[1].'</td>'.
4339: '</tr>';
1.68 ng 4340:
1.196 albertel 4341: $prob++;
1.68 ng 4342: }
1.71 ng 4343: $curRes = $iterator->next();
1.68 ng 4344: }
1.98 albertel 4345:
1.71 ng 4346: $studentTable.='</td></tr></table></td></tr></table>';
1.324 albertel 4347: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.76 ng 4348: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
4349: 'The scores were changed for '.
4350: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
4351: $request->print($grademsg.$studentTable);
1.68 ng 4352:
1.70 ng 4353: return '';
4354: }
4355:
1.72 ng 4356: #-------- end of section for handling grading by page/sequence ---------
4357: #
4358: #-------------------------------------------------------------------
4359:
1.75 albertel 4360: #--------------------Scantron Grading-----------------------------------
4361: #
4362: #------ start of section for handling grading by page/sequence ---------
4363:
1.81 albertel 4364: sub defaultFormData {
1.324 albertel 4365: my ($symb)=@_;
1.81 albertel 4366: return '
4367: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 4368: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4369: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4370: }
4371:
1.75 albertel 4372: sub getSequenceDropDown {
4373: my ($request,$symb)=@_;
4374: my $result='<select name="selectpage">'."\n";
4375: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 4376: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4377: my $ctr=0;
4378: foreach (@$titles) {
4379: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4380: $result.='<option value="'.$$symbx{$_}.'" '.
4381: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
4382: '>'.$showtitle.'</option>'."\n";
4383: $ctr++;
4384: }
4385: $result.= '</select>';
4386: return $result;
4387: }
4388:
1.202 albertel 4389: sub scantron_filenames {
1.257 albertel 4390: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4391: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 4392: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.359 www 4393: &propath($cdom,$cname));
1.202 albertel 4394: my @possiblenames;
1.201 albertel 4395: foreach my $filename (sort(@files)) {
1.157 albertel 4396: ($filename)=split(/&/,$filename);
4397: if ($filename!~/^scantron_orig_/) { next ; }
4398: $filename=~s/^scantron_orig_//;
1.202 albertel 4399: push(@possiblenames,$filename);
4400: }
4401: return @possiblenames;
4402: }
4403:
4404: sub scantron_uploads {
1.209 ng 4405: my ($file2grade) = @_;
1.202 albertel 4406: my $result= '<select name="scantron_selectfile">';
4407: $result.="<option></option>";
4408: foreach my $filename (sort(&scantron_filenames())) {
1.209 ng 4409: $result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n";
1.81 albertel 4410: }
4411: $result.="</select>";
4412: return $result;
4413: }
4414:
1.82 albertel 4415: sub scantron_scantab {
4416: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4417: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4418: $result.='<option></option>'."\n";
1.82 albertel 4419: foreach my $line (<$fh>) {
4420: my ($name,$descrip)=split(/:/,$line);
4421: if ($name =~ /^\#/) { next; }
4422: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4423: }
4424: $result.='</select>'."\n";
4425:
4426: return $result;
4427: }
4428:
1.186 albertel 4429: sub scantron_CODElist {
1.257 albertel 4430: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4431: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4432: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4433: my $namechoice='<option></option>';
1.225 albertel 4434: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4435: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4436: if ($name =~ /^type\0/) { next; }
1.186 albertel 4437: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4438: }
4439: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4440: return $namechoice;
4441: }
4442:
4443: sub scantron_CODEunique {
1.381 albertel 4444: my $result='<span style="white-space: nowrap;">
1.272 albertel 4445: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4446: value="yes" checked="checked" /> Yes </label>
1.381 albertel 4447: </span>
4448: <span style="white-space: nowrap;">
1.272 albertel 4449: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4450: value="no" /> No </label>
1.381 albertel 4451: </span>';
1.186 albertel 4452: return $result;
4453: }
4454:
1.75 albertel 4455: sub scantron_selectphase {
1.209 ng 4456: my ($r,$file2grade) = @_;
1.324 albertel 4457: my ($symb)=&get_symb($r);
1.75 albertel 4458: if (!$symb) {return '';}
4459: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.324 albertel 4460: my $default_form_data=&defaultFormData($symb);
4461: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 4462: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4463: my $format_selector=&scantron_scantab();
1.186 albertel 4464: my $CODE_selector=&scantron_CODElist();
4465: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4466: my $result;
1.157 albertel 4467: #FIXME allow instructor to be able to download the scantron file
4468: # and to upload it,
1.75 albertel 4469: $result.= <<SCANTRONFORM;
1.162 albertel 4470: <table width="100%" border="0">
1.75 albertel 4471: <tr>
1.226 albertel 4472: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
1.75 albertel 4473: <td bgcolor="#777777">
1.203 albertel 4474: <input type="hidden" name="command" value="scantron_warning" />
1.162 albertel 4475: $default_form_data
1.75 albertel 4476: <table width="100%" border="0">
4477: <tr bgcolor="#e6ffff">
1.174 albertel 4478: <td colspan="2">
4479: <b>Specify file and which Folder/Sequence to grade</b>
1.75 albertel 4480: </td>
4481: </tr>
4482: <tr bgcolor="#ffffe6">
1.174 albertel 4483: <td> Sequence to grade: </td><td> $sequence_selector </td>
1.75 albertel 4484: </tr>
4485: <tr bgcolor="#ffffe6">
1.174 albertel 4486: <td> Filename of scoring office file: </td><td> $file_selector </td>
1.75 albertel 4487: </tr>
1.82 albertel 4488: <tr bgcolor="#ffffe6">
1.174 albertel 4489: <td> Format of data file: </td><td> $format_selector </td>
1.82 albertel 4490: </tr>
1.157 albertel 4491: <tr bgcolor="#ffffe6">
1.186 albertel 4492: <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
4493: </tr>
4494: <tr bgcolor="#ffffe6">
4495: <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
4496: </tr>
4497: <tr bgcolor="#ffffe6">
1.187 albertel 4498: <td> Options: </td>
4499: <td>
1.272 albertel 4500: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
1.331 albertel 4501: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label> <br />
4502: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> Skip hidden resources when grading</label>
1.187 albertel 4503: </td>
4504: </tr>
4505: <tr bgcolor="#ffffe6">
1.174 albertel 4506: <td colspan="2">
1.265 www 4507: <input type="submit" value="Grading: Validate Scantron Records" />
1.162 albertel 4508: </td>
4509: </tr>
4510: </table>
1.226 albertel 4511: </td>
4512: </form>
1.162 albertel 4513: </tr>
4514: SCANTRONFORM
4515:
4516: $r->print($result);
4517:
1.257 albertel 4518: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
4519: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 4520:
4521: $r->print(<<SCANTRONFORM);
4522: <tr>
4523: <td bgcolor="#777777">
4524: <table width="100%" border="0">
4525: <tr bgcolor="#e6ffff">
4526: <td>
1.174 albertel 4527: <b>Specify a Scantron data file to upload.</b>
1.162 albertel 4528: </td>
4529: </tr>
4530: <tr bgcolor="#ffffe6">
4531: <td>
4532: SCANTRONFORM
1.324 albertel 4533: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 4534: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4535: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.174 albertel 4536: $r->print(<<UPLOAD);
4537: <script type="text/javascript" language="javascript">
4538: function checkUpload(formname) {
4539: if (formname.upfile.value == "") {
4540: alert("Please use the browse button to select a file from your local directory.");
4541: return false;
4542: }
4543: formname.submit();
4544: }
4545: </script>
4546:
4547: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
4548: $default_form_data
4549: <input name='courseid' type='hidden' value='$cnum' />
4550: <input name='domainid' type='hidden' value='$cdom' />
4551: <input name='command' value='scantronupload_save' type='hidden' />
4552: File to upload:<input type="file" name="upfile" size="50" />
4553: <br />
4554: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
4555: </form>
4556: UPLOAD
1.162 albertel 4557:
4558: $r->print(<<SCANTRONFORM);
4559: </td>
4560: </tr>
1.75 albertel 4561: </table>
4562: </td>
4563: </tr>
1.162 albertel 4564: SCANTRONFORM
4565: }
1.187 albertel 4566: $r->print(<<SCANTRONFORM);
4567: <tr>
1.226 albertel 4568: <form action='/adm/grades' name='scantron_download'>
4569: <td bgcolor="#777777">
1.379 albertel 4570: $default_form_data
1.187 albertel 4571: <input type="hidden" name="command" value="scantron_download" />
4572: <table width="100%" border="0">
4573: <tr bgcolor="#e6ffff">
4574: <td colspan="2">
4575: <b>Download a scoring office file</b>
4576: </td>
4577: </tr>
4578: <tr bgcolor="#ffffe6">
4579: <td> Filename of scoring office file: </td><td> $file_selector </td>
4580: </tr>
4581: <tr bgcolor="#ffffe6">
4582: <td colspan="2">
1.293 www 4583: <input type="submit" value="Download: Show List of Associated Files" />
1.187 albertel 4584: </td>
4585: </tr>
4586: </table>
1.226 albertel 4587: </td>
4588: </form>
1.187 albertel 4589: </tr>
4590: SCANTRONFORM
1.162 albertel 4591:
4592: $r->print(<<SCANTRONFORM);
1.75 albertel 4593: </table>
1.81 albertel 4594: $grading_menu_button
1.75 albertel 4595: SCANTRONFORM
4596:
1.162 albertel 4597: return
1.75 albertel 4598: }
4599:
1.82 albertel 4600: sub get_scantron_config {
4601: my ($which) = @_;
4602: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4603: my %config;
1.157 albertel 4604: #FIXME probably should move to XML it has already gotten a bit much now
1.82 albertel 4605: foreach my $line (<$fh>) {
4606: my ($name,$descrip)=split(/:/,$line);
4607: if ($name ne $which ) { next; }
4608: chomp($line);
4609: my @config=split(/:/,$line);
4610: $config{'name'}=$config[0];
4611: $config{'description'}=$config[1];
4612: $config{'CODElocation'}=$config[2];
4613: $config{'CODEstart'}=$config[3];
4614: $config{'CODElength'}=$config[4];
4615: $config{'IDstart'}=$config[5];
4616: $config{'IDlength'}=$config[6];
4617: $config{'Qstart'}=$config[7];
4618: $config{'Qlength'}=$config[8];
4619: $config{'Qoff'}=$config[9];
4620: $config{'Qon'}=$config[10];
1.157 albertel 4621: $config{'PaperID'}=$config[11];
4622: $config{'PaperIDlength'}=$config[12];
4623: $config{'FirstName'}=$config[13];
4624: $config{'FirstNamelength'}=$config[14];
4625: $config{'LastName'}=$config[15];
4626: $config{'LastNamelength'}=$config[16];
1.82 albertel 4627: last;
4628: }
4629: return %config;
4630: }
4631:
4632: sub username_to_idmap {
4633: my ($classlist)= @_;
4634: my %idmap;
4635: foreach my $student (keys(%$classlist)) {
4636: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
4637: $student;
4638: }
4639: return %idmap;
4640: }
4641:
1.157 albertel 4642: sub scantron_fixup_scanline {
4643: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
4644: if ($field eq 'ID') {
4645: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 4646: return ($line,1,'New value too large');
1.157 albertel 4647: }
4648: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
4649: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
4650: $args->{'newid'});
4651: }
4652: substr($line,$$scantron_config{'IDstart'}-1,
4653: $$scantron_config{'IDlength'})=$args->{'newid'};
4654: if ($args->{'newid'}=~/^\s*$/) {
4655: &scan_data($scan_data,"$whichline.user",
4656: $args->{'username'}.':'.$args->{'domain'});
4657: }
1.186 albertel 4658: } elsif ($field eq 'CODE') {
1.192 albertel 4659: if ($args->{'CODE_ignore_dup'}) {
4660: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
4661: }
4662: &scan_data($scan_data,"$whichline.useCODE",'1');
4663: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 4664: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
4665: return ($line,1,'New CODE value too large');
4666: }
4667: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
4668: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
4669: }
4670: substr($line,$$scantron_config{'CODEstart'}-1,
4671: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 4672: }
1.157 albertel 4673: } elsif ($field eq 'answer') {
4674: my $length=$scantron_config->{'Qlength'};
4675: my $off=$scantron_config->{'Qoff'};
4676: my $on=$scantron_config->{'Qon'};
4677: my $answer=${off}x$length;
4678: if ($args->{'response'} eq 'none') {
4679: &scan_data($scan_data,
4680: "$whichline.no_bubble.".$args->{'question'},'1');
4681: } else {
1.274 albertel 4682: if ($on eq 'letter') {
4683: my @alphabet=('A'..'Z');
4684: $answer=$alphabet[$args->{'response'}];
4685: } elsif ($on eq 'number') {
4686: $answer=$args->{'response'}+1;
1.389 albertel 4687: if ($answer == 10) { $answer = '0'; }
1.274 albertel 4688: } else {
4689: substr($answer,$args->{'response'},1)=$on;
4690: }
1.157 albertel 4691: &scan_data($scan_data,
4692: "$whichline.no_bubble.".$args->{'question'},undef,'1');
4693: }
4694: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
4695: substr($line,$where-1,$length)=$answer;
4696: }
4697: return $line;
4698: }
4699:
4700: sub scan_data {
4701: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 4702: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 4703: if (defined($value)) {
4704: $scan_data->{$filename.'_'.$key} = $value;
4705: }
4706: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
4707: return $scan_data->{$filename.'_'.$key};
4708: }
4709:
1.82 albertel 4710: sub scantron_parse_scanline {
1.194 albertel 4711: my ($line,$whichline,$scantron_config,$scan_data,$justHeader)=@_;
1.82 albertel 4712: my %record;
4713: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
4714: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
1.278 albertel 4715: if (!($$scantron_config{'CODElocation'} eq 0 ||
4716: $$scantron_config{'CODElocation'} eq 'none')) {
4717: if ($$scantron_config{'CODElocation'} < 0 ||
4718: $$scantron_config{'CODElocation'} eq 'letter' ||
4719: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 4720: $record{'scantron.CODE'}=substr($data,
4721: $$scantron_config{'CODEstart'}-1,
1.83 albertel 4722: $$scantron_config{'CODElength'});
1.191 albertel 4723: if (&scan_data($scan_data,"$whichline.useCODE")) {
4724: $record{'scantron.useCODE'}=1;
4725: }
1.192 albertel 4726: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
4727: $record{'scantron.CODE_ignore_dup'}=1;
4728: }
1.82 albertel 4729: } else {
4730: #FIXME interpret first N questions
4731: }
4732: }
1.83 albertel 4733: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
4734: $$scantron_config{'IDlength'});
1.157 albertel 4735: $record{'scantron.PaperID'}=
4736: substr($data,$$scantron_config{'PaperID'}-1,
4737: $$scantron_config{'PaperIDlength'});
4738: $record{'scantron.FirstName'}=
4739: substr($data,$$scantron_config{'FirstName'}-1,
4740: $$scantron_config{'FirstNamelength'});
4741: $record{'scantron.LastName'}=
4742: substr($data,$$scantron_config{'LastName'}-1,
4743: $$scantron_config{'LastNamelength'});
1.194 albertel 4744: if ($justHeader) { return \%record; }
4745:
1.82 albertel 4746: my @alphabet=('A'..'Z');
4747: my $questnum=0;
4748: while ($questions) {
4749: $questnum++;
4750: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
4751: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 4752: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.239 albertel 4753: if ($$scantron_config{'Qon'} eq 'letter') {
1.371 albertel 4754: if ($currentquest eq '?'
4755: || $currentquest eq '*') {
1.274 albertel 4756: push(@{$record{'scantron.doubleerror'}},$questnum);
4757: $record{"scantron.$questnum.answer"}='';
1.389 albertel 4758: } elsif (!defined($currentquest)
1.274 albertel 4759: || $currentquest eq $$scantron_config{'Qoff'}
4760: || $currentquest !~ /^[A-Z]$/) {
1.239 albertel 4761: $record{"scantron.$questnum.answer"}='';
4762: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4763: push(@{$record{"scantron.missingerror"}},$questnum);
4764: }
4765: } else {
4766: $record{"scantron.$questnum.answer"}=$currentquest;
4767: }
4768: } elsif ($$scantron_config{'Qon'} eq 'number') {
1.371 albertel 4769: if ($currentquest eq '?'
4770: || $currentquest eq '*') {
1.274 albertel 4771: push(@{$record{'scantron.doubleerror'}},$questnum);
4772: $record{"scantron.$questnum.answer"}='';
1.389 albertel 4773: } elsif (!defined($currentquest)
4774: || $currentquest eq $$scantron_config{'Qoff'}
4775: || $currentquest !~ /^\d$/) {
1.239 albertel 4776: $record{"scantron.$questnum.answer"}='';
4777: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4778: push(@{$record{"scantron.missingerror"}},$questnum);
4779: }
4780: } else {
1.371 albertel 4781: # wrap zero back to J
4782: if ($currentquest eq '0') {
4783: $record{"scantron.$questnum.answer"}=
4784: $alphabet[9];
4785: } else {
4786: $record{"scantron.$questnum.answer"}=
4787: $alphabet[$currentquest-1];
4788: }
1.239 albertel 4789: }
1.82 albertel 4790: } else {
1.239 albertel 4791: my @array=split($$scantron_config{'Qon'},$currentquest,-1);
4792: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
4793: $record{"scantron.$questnum.answer"}='';
4794: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4795: push(@{$record{"scantron.missingerror"}},$questnum);
4796: }
4797: } else {
4798: $record{"scantron.$questnum.answer"}=
4799: $alphabet[length($array[0])];
4800: }
4801: if (scalar(@array) gt 2) {
4802: push(@{$record{'scantron.doubleerror'}},$questnum);
4803: my @ans=@array;
4804: my $i=length($ans[0]);shift(@ans);
4805: while ($#ans) {
4806: $i+=length($ans[0])+1;
4807: $record{"scantron.$questnum.answer"}.=$alphabet[$i];
4808: shift(@ans);
4809: }
4810: }
1.82 albertel 4811: }
4812: }
1.83 albertel 4813: $record{'scantron.maxquest'}=$questnum;
4814: return \%record;
1.82 albertel 4815: }
4816:
4817: sub scantron_add_delay {
1.140 albertel 4818: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
4819: push(@$delayqueue,
4820: {'line' => $scanline, 'emsg' => $errormessage,
4821: 'ecode' => $errorcode }
4822: );
1.82 albertel 4823: }
4824:
4825: sub scantron_find_student {
1.157 albertel 4826: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 4827: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 4828: if ($scanID =~ /^\s*$/) {
4829: return &scan_data($scan_data,"$line.user");
4830: }
1.83 albertel 4831: foreach my $id (keys(%$idmap)) {
1.157 albertel 4832: if (lc($id) eq lc($scanID)) {
4833: return $$idmap{$id};
4834: }
1.83 albertel 4835: }
4836: return undef;
4837: }
4838:
4839: sub scantron_filter {
4840: my ($curres)=@_;
1.331 albertel 4841:
4842: if (ref($curres) && $curres->is_problem()) {
4843: # if the user has asked to not have either hidden
4844: # or 'randomout' controlled resources to be graded
4845: # don't include them
4846: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
4847: && $curres->randomout) {
4848: return 0;
4849: }
1.83 albertel 4850: return 1;
4851: }
4852: return 0;
1.82 albertel 4853: }
4854:
1.157 albertel 4855: sub scantron_process_corrections {
4856: my ($r) = @_;
1.257 albertel 4857: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4858: my ($scanlines,$scan_data)=&scantron_getfile();
4859: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 4860: my $which=$env{'form.scantron_line'};
1.200 albertel 4861: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 4862: my ($skip,$err,$errmsg);
1.257 albertel 4863: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 4864: $skip=1;
1.257 albertel 4865: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
4866: my $newstudent=$env{'form.scantron_username'}.':'.
4867: $env{'form.scantron_domain'};
1.157 albertel 4868: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
4869: ($line,$err,$errmsg)=
4870: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
4871: 'ID',{'newid'=>$newid,
1.257 albertel 4872: 'username'=>$env{'form.scantron_username'},
4873: 'domain'=>$env{'form.scantron_domain'}});
4874: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
4875: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 4876: my $newCODE;
1.192 albertel 4877: my %args;
1.190 albertel 4878: if ($resolution eq 'use_unfound') {
1.191 albertel 4879: $newCODE='use_unfound';
1.190 albertel 4880: } elsif ($resolution eq 'use_found') {
1.257 albertel 4881: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 4882: } elsif ($resolution eq 'use_typed') {
1.257 albertel 4883: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 4884: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 4885: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 4886: }
1.257 albertel 4887: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 4888: $args{'CODE_ignore_dup'}=1;
4889: }
4890: $args{'CODE'}=$newCODE;
1.186 albertel 4891: ($line,$err,$errmsg)=
4892: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 4893: 'CODE',\%args);
1.257 albertel 4894: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
4895: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 4896: ($line,$err,$errmsg)=
4897: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
4898: $which,'answer',
4899: { 'question'=>$question,
1.257 albertel 4900: 'response'=>$env{"form.scantron_correct_Q_$question"}});
1.157 albertel 4901: if ($err) { last; }
4902: }
4903: }
4904: if ($err) {
1.287 albertel 4905: $r->print("<font color='red'>Unable to accept last correction, an error occurred :$errmsg:</font>");
1.157 albertel 4906: } else {
1.200 albertel 4907: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 4908: &scantron_putfile($scanlines,$scan_data);
4909: }
4910: }
4911:
1.200 albertel 4912: sub reset_skipping_status {
4913: my ($scanlines,$scan_data)=&scantron_getfile();
4914: &scan_data($scan_data,'remember_skipping',undef,1);
4915: &scantron_putfile(undef,$scan_data);
4916: }
4917:
1.376 albertel 4918: sub start_skipping {
1.200 albertel 4919: my ($scan_data,$i)=@_;
4920: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 4921: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
4922: $remembered{$i}=2;
4923: } else {
4924: $remembered{$i}=1;
4925: }
1.200 albertel 4926: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
4927: }
4928:
4929: sub should_be_skipped {
1.376 albertel 4930: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 4931: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 4932: # not redoing old skips
1.376 albertel 4933: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 4934: return 0;
4935: }
4936: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 4937:
4938: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
4939: return 0;
4940: }
1.200 albertel 4941: return 1;
4942: }
4943:
4944: sub remember_current_skipped {
4945: my ($scanlines,$scan_data)=&scantron_getfile();
4946: my %to_remember;
4947: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4948: if ($scanlines->{'skipped'}[$i]) {
4949: $to_remember{$i}=1;
4950: }
4951: }
1.376 albertel 4952:
1.200 albertel 4953: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
4954: &scantron_putfile(undef,$scan_data);
4955: }
4956:
4957: sub check_for_error {
4958: my ($r,$result)=@_;
4959: if ($result ne 'ok' && $result ne 'not_found' ) {
4960: $r->print("An error occured ($result) when trying to Remove the existing corrections.");
4961: }
4962: }
1.157 albertel 4963:
1.203 albertel 4964: sub scantron_warning_screen {
4965: my ($button_text)=@_;
1.257 albertel 4966: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 4967: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 4968: my $CODElist;
1.284 albertel 4969: if ($scantron_config{'CODElocation'} &&
4970: $scantron_config{'CODEstart'} &&
4971: $scantron_config{'CODElength'}) {
4972: $CODElist=$env{'form.scantron_CODElist'};
1.373 albertel 4973: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<font color="red">None</font>'; }
1.284 albertel 4974: $CODElist=
4975: '<tr><td><b>List of CODES to validate against:</b></td><td><tt>'.
1.373 albertel 4976: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 4977: }
1.203 albertel 4978: return (<<STUFF);
4979: <p>
4980: <font color="red">Please double check the information
4981: below before clicking on '$button_text'</font>
4982: </p>
4983: <table>
1.284 albertel 4984: <tr><td><b>Sequence to be Graded:</b></td><td>$title</td></tr>
1.257 albertel 4985: <tr><td><b>Data File that will be used:</b></td><td><tt>$env{'form.scantron_selectfile'}</tt></td></tr>
1.284 albertel 4986: $CODElist
1.203 albertel 4987: </table>
4988: </font>
4989: <br />
4990: <p> If this information is correct, please click on '$button_text'.</p>
4991: <p> If something is incorrect, please click the 'Grading Menu' button to start over.</p>
4992:
4993: <br />
4994: STUFF
4995: }
4996:
4997: sub scantron_do_warning {
4998: my ($r)=@_;
1.324 albertel 4999: my ($symb)=&get_symb($r);
1.203 albertel 5000: if (!$symb) {return '';}
1.324 albertel 5001: my $default_form_data=&defaultFormData($symb);
1.203 albertel 5002: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 5003: if ( $env{'form.selectpage'} eq '' ||
5004: $env{'form.scantron_selectfile'} eq '' ||
5005: $env{'form.scantron_format'} eq '' ) {
1.237 albertel 5006: $r->print("<p>You have forgetten to specify some information. Please go Back and try again.</p>");
1.257 albertel 5007: if ( $env{'form.selectpage'} eq '') {
1.237 albertel 5008: $r->print('<p><font color="red">You have not selected a Sequence to grade</font></p>');
5009: }
1.257 albertel 5010: if ( $env{'form.scantron_selectfile'} eq '') {
1.237 albertel 5011: $r->print('<p><font color="red">You have not selected a file that contains the student\'s response data.</font></p>');
5012: }
1.257 albertel 5013: if ( $env{'form.scantron_format'} eq '') {
1.237 albertel 5014: $r->print('<p><font color="red">You have not selected a the format of the student\'s response data.</font></p>');
5015: }
5016: } else {
1.265 www 5017: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.237 albertel 5018: $r->print(<<STUFF);
1.203 albertel 5019: $warning
1.265 www 5020: <input type="submit" name="submit" value="Grading: Validate Records" />
1.203 albertel 5021: <input type="hidden" name="command" value="scantron_validate" />
5022: STUFF
1.237 albertel 5023: }
1.352 albertel 5024: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 5025: return '';
5026: }
5027:
5028: sub scantron_form_start {
5029: my ($max_bubble)=@_;
5030: my $result= <<SCANTRONFORM;
5031: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 5032: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
5033: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
5034: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 5035: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 5036: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
5037: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
5038: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
5039: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 5040: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 5041: SCANTRONFORM
5042: return $result;
5043: }
5044:
1.157 albertel 5045: sub scantron_validate_file {
5046: my ($r) = @_;
1.324 albertel 5047: my ($symb)=&get_symb($r);
1.157 albertel 5048: if (!$symb) {return '';}
1.324 albertel 5049: my $default_form_data=&defaultFormData($symb);
1.200 albertel 5050:
5051: # do the detection of only doing skipped records first befroe we delete
5052: # them when doing the corrections reset
1.257 albertel 5053: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 5054: &reset_skipping_status();
5055: }
1.257 albertel 5056: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 5057: &remember_current_skipped();
1.257 albertel 5058: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 5059: }
5060:
1.257 albertel 5061: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 5062: &check_for_error($r,&scantron_remove_file('corrected'));
5063: &check_for_error($r,&scantron_remove_file('skipped'));
5064: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 5065: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 5066: }
1.200 albertel 5067:
1.257 albertel 5068: if ($env{'form.scantron_corrections'}) {
1.157 albertel 5069: &scantron_process_corrections($r);
5070: }
1.191 albertel 5071: $r->print("<p>Gathering neccessary info.</p>");$r->rflush();
1.157 albertel 5072: #get the student pick code ready
5073: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 5074: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 5075: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 5076: $r->print($result);
5077:
1.334 albertel 5078: my @validate_phases=( 'sequence',
5079: 'ID',
1.157 albertel 5080: 'CODE',
5081: 'doublebubble',
5082: 'missingbubbles');
1.257 albertel 5083: if (!$env{'form.validatepass'}) {
5084: $env{'form.validatepass'} = 0;
1.157 albertel 5085: }
1.257 albertel 5086: my $currentphase=$env{'form.validatepass'};
1.157 albertel 5087:
5088: my $stop=0;
5089: while (!$stop && $currentphase < scalar(@validate_phases)) {
5090: $r->print("<p> Validating ".$validate_phases[$currentphase]."</p>");
5091: $r->rflush();
5092: my $which="scantron_validate_".$validate_phases[$currentphase];
5093: {
5094: no strict 'refs';
5095: ($stop,$currentphase)=&$which($r,$currentphase);
5096: }
5097: }
5098: if (!$stop) {
1.203 albertel 5099: my $warning=&scantron_warning_screen('Start Grading');
5100: $r->print(<<STUFF);
5101: Validation process complete.<br />
5102: $warning
5103: <input type="submit" name="submit" value="Start Grading" />
5104: <input type="hidden" name="command" value="scantron_process" />
5105: STUFF
5106:
1.157 albertel 5107: } else {
5108: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
5109: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
5110: }
5111: if ($stop) {
1.334 albertel 5112: if ($validate_phases[$currentphase] eq 'sequence') {
5113: $r->print('<input type="submit" name="submit" value="Ignore -> " />');
5114: $r->print(' this error <br />');
5115:
5116: $r->print(" <p>Or click the 'Grading Menu' button to start over.</p>");
5117: } else {
5118: $r->print('<input type="submit" name="submit" value="Continue ->" />');
5119: $r->print(' using corrected info <br />');
5120: $r->print("<input type='submit' value='Skip' name='scantron_skip_record' />");
5121: $r->print(" this scanline saving it for later.");
5122: }
1.157 albertel 5123: }
1.352 albertel 5124: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 5125: return '';
5126: }
5127:
1.200 albertel 5128: sub scantron_remove_file {
1.192 albertel 5129: my ($which)=@_;
1.257 albertel 5130: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5131: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5132: my $file='scantron_';
1.200 albertel 5133: if ($which eq 'corrected' || $which eq 'skipped') {
5134: $file.=$which.'_';
1.192 albertel 5135: } else {
5136: return 'refused';
5137: }
1.257 albertel 5138: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 5139: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
5140: }
5141:
5142: sub scantron_remove_scan_data {
1.257 albertel 5143: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5144: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 5145: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
5146: my @todelete;
1.257 albertel 5147: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 5148: foreach my $key (@keys) {
5149: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 5150: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 5151: $key=~/remember_skipping/) {
5152: next;
5153: }
1.192 albertel 5154: push(@todelete,$key);
5155: }
5156: }
1.200 albertel 5157: my $result;
1.192 albertel 5158: if (@todelete) {
1.200 albertel 5159: $result=&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
1.192 albertel 5160: }
5161: return $result;
5162: }
5163:
1.157 albertel 5164: sub scantron_getfile {
1.200 albertel 5165: #FIXME really would prefer a scantron directory
1.257 albertel 5166: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5167: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 5168: my $lines;
5169: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5170: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 5171: my %scanlines;
5172: $scanlines{'orig'}=[(split("\n",$lines,-1))];
5173: my $temp=$scanlines{'orig'};
5174: $scanlines{'count'}=$#$temp;
5175:
5176: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5177: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 5178: if ($lines eq '-1') {
5179: $scanlines{'corrected'}=[];
5180: } else {
5181: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
5182: }
5183: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 5184: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 5185: if ($lines eq '-1') {
5186: $scanlines{'skipped'}=[];
5187: } else {
5188: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
5189: }
1.175 albertel 5190: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 5191: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
5192: my %scan_data = @tmp;
5193: return (\%scanlines,\%scan_data);
5194: }
5195:
5196: sub lonnet_putfile {
5197: my ($contents,$filename)=@_;
1.257 albertel 5198: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5199: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5200: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 5201: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 5202:
5203: }
5204:
5205: sub scantron_putfile {
5206: my ($scanlines,$scan_data) = @_;
1.200 albertel 5207: #FIXME really would prefer a scantron directory
1.257 albertel 5208: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5209: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 5210: if ($scanlines) {
5211: my $prefix='scantron_';
1.157 albertel 5212: # no need to update orig, shouldn't change
5213: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 5214: # $env{'form.scantron_selectfile'});
1.200 albertel 5215: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
5216: $prefix.'corrected_'.
1.257 albertel 5217: $env{'form.scantron_selectfile'});
1.200 albertel 5218: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
5219: $prefix.'skipped_'.
1.257 albertel 5220: $env{'form.scantron_selectfile'});
1.200 albertel 5221: }
1.175 albertel 5222: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 5223: }
5224:
5225: sub scantron_get_line {
1.200 albertel 5226: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 5227: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
5228: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 5229: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
5230: return $scanlines->{'orig'}[$i];
5231: }
5232:
1.200 albertel 5233: sub get_todo_count {
5234: my ($scanlines,$scan_data)=@_;
5235: my $count=0;
5236: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5237: my $line=&scantron_get_line($scanlines,$scan_data,$i);
5238: if ($line=~/^[\s\cz]*$/) { next; }
5239: $count++;
5240: }
5241: return $count;
5242: }
5243:
1.157 albertel 5244: sub scantron_put_line {
1.200 albertel 5245: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 5246: if ($skip) {
5247: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 5248: &start_skipping($scan_data,$i);
1.157 albertel 5249: return;
5250: }
5251: $scanlines->{'corrected'}[$i]=$newline;
5252: }
5253:
1.376 albertel 5254: sub scantron_clear_skip {
5255: my ($scanlines,$scan_data,$i)=@_;
5256: if (exists($scanlines->{'skipped'}[$i])) {
5257: undef($scanlines->{'skipped'}[$i]);
5258: return 1;
5259: }
5260: return 0;
5261: }
5262:
1.334 albertel 5263: sub scantron_filter_not_exam {
5264: my ($curres)=@_;
5265:
5266: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
5267: # if the user has asked to not have either hidden
5268: # or 'randomout' controlled resources to be graded
5269: # don't include them
5270: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5271: && $curres->randomout) {
5272: return 0;
5273: }
5274: return 1;
5275: }
5276: return 0;
5277: }
5278:
5279: sub scantron_validate_sequence {
5280: my ($r,$currentphase) = @_;
5281:
5282: my $navmap=Apache::lonnavmaps::navmap->new();
5283: my (undef,undef,$sequence)=
5284: &Apache::lonnet::decode_symb($env{'form.selectpage'});
5285:
5286: my $map=$navmap->getResourceByUrl($sequence);
5287:
5288: $r->print('<input type="hidden" name="validate_sequence_exam"
5289: value="ignore" />');
5290: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
5291: my @resources=
5292: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
5293: if (@resources) {
1.357 banghart 5294: $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 5295: return (1,$currentphase);
5296: }
5297: }
5298:
5299: return (0,$currentphase+1);
5300: }
5301:
1.157 albertel 5302: sub scantron_validate_ID {
5303: my ($r,$currentphase) = @_;
5304:
5305: #get student info
5306: my $classlist=&Apache::loncoursedata::get_classlist();
5307: my %idmap=&username_to_idmap($classlist);
5308:
5309: #get scantron line setup
1.257 albertel 5310: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5311: my ($scanlines,$scan_data)=&scantron_getfile();
5312:
5313: my %found=('ids'=>{},'usernames'=>{});
5314: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5315: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5316: if ($line=~/^[\s\cz]*$/) { next; }
5317: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5318: $scan_data);
5319: my $id=$$scan_record{'scantron.ID'};
5320: my $found;
5321: foreach my $checkid (keys(%idmap)) {
5322: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
5323: }
5324: if ($found) {
5325: my $username=$idmap{$found};
5326: if ($found{'ids'}{$found}) {
5327: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5328: $line,'duplicateID',$found);
1.194 albertel 5329: return(1,$currentphase);
1.157 albertel 5330: } elsif ($found{'usernames'}{$username}) {
5331: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5332: $line,'duplicateID',$username);
1.194 albertel 5333: return(1,$currentphase);
1.157 albertel 5334: }
1.186 albertel 5335: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 5336: $found{'ids'}{$found}++;
5337: $found{'usernames'}{$username}++;
5338: } else {
5339: if ($id =~ /^\s*$/) {
1.158 albertel 5340: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 5341: if (defined($username) && $found{'usernames'}{$username}) {
5342: &scantron_get_correction($r,$i,$scan_record,
5343: \%scantron_config,
5344: $line,'duplicateID',$username);
1.194 albertel 5345: return(1,$currentphase);
1.157 albertel 5346: } elsif (!defined($username)) {
5347: &scantron_get_correction($r,$i,$scan_record,
5348: \%scantron_config,
5349: $line,'incorrectID');
1.194 albertel 5350: return(1,$currentphase);
1.157 albertel 5351: }
5352: $found{'usernames'}{$username}++;
5353: } else {
5354: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5355: $line,'incorrectID');
1.194 albertel 5356: return(1,$currentphase);
1.157 albertel 5357: }
5358: }
5359: }
5360:
5361: return (0,$currentphase+1);
5362: }
5363:
5364: sub scantron_get_correction {
5365: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
5366:
5367: #FIXME in the case of a duplicated ID the previous line, probaly need
5368: #to show both the current line and the previous one and allow skipping
5369: #the previous one or the current one
5370:
1.161 albertel 5371: $r->print("<p><b>An error was detected ($error)</b>");
1.333 albertel 5372: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.157 albertel 5373: $r->print(" for PaperID <tt>".
5374: $$scan_record{'scantron.PaperID'}."</tt> \n");
5375: } else {
5376: $r->print(" in scanline $i <pre>".
5377: $line."</pre> \n");
5378: }
1.242 albertel 5379: my $message="<p>The ID on the form is <tt>".
5380: $$scan_record{'scantron.ID'}."</tt><br />\n".
5381: "The name on the paper is ".
5382: $$scan_record{'scantron.LastName'}.",".
5383: $$scan_record{'scantron.FirstName'}."</p>";
5384:
1.157 albertel 5385: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
5386: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
5387: if ($error =~ /ID$/) {
1.186 albertel 5388: if ($error eq 'incorrectID') {
1.157 albertel 5389: $r->print("The encoded ID is not in the classlist</p>\n");
5390: } elsif ($error eq 'duplicateID') {
5391: $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
5392: }
1.242 albertel 5393: $r->print($message);
1.157 albertel 5394: $r->print("<p>How should I handle this? <br /> \n");
5395: $r->print("\n<ul><li> ");
5396: #FIXME it would be nice if this sent back the user ID and
5397: #could do partial userID matches
5398: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
5399: 'scantron_username','scantron_domain'));
5400: $r->print(": <input type='text' name='scantron_username' value='' />");
5401: $r->print("\n@".
1.257 albertel 5402: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 5403:
5404: $r->print('</li>');
1.186 albertel 5405: } elsif ($error =~ /CODE$/) {
5406: if ($error eq 'incorrectCODE') {
1.187 albertel 5407: $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
1.186 albertel 5408: } elsif ($error eq 'duplicateCODE') {
1.194 albertel 5409: $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 5410: }
1.224 albertel 5411: $r->print("<p>The CODE on the form is <tt>'".
5412: $$scan_record{'scantron.CODE'}."'</tt><br />\n");
1.242 albertel 5413: $r->print($message);
1.186 albertel 5414: $r->print("<p>How should I handle this? <br /> \n");
1.187 albertel 5415: $r->print("\n<br /> ");
1.194 albertel 5416: my $i=0;
1.273 albertel 5417: if ($error eq 'incorrectCODE'
5418: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 5419: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 5420: if ($closest > 0) {
5421: foreach my $testcode (@{$closest}) {
5422: my $checked='';
5423: if (!$i) { $checked=' checked="on" '; }
5424: $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' />");
5425: $r->print("\n<br />");
5426: $i++;
5427: }
1.194 albertel 5428: }
5429: }
1.273 albertel 5430: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
5431: my $checked; if (!$i) { $checked=' checked="on" '; }
5432: $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>");
5433: $r->print("\n<br />");
5434: }
1.194 albertel 5435:
1.188 albertel 5436: $r->print(<<ENDSCRIPT);
5437: <script type="text/javascript">
5438: function change_radio(field) {
1.190 albertel 5439: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 5440: var i;
5441: for (i=0;i<slct.length;i++) {
5442: if (slct[i].value==field) { slct[i].checked=true; }
5443: }
5444: }
5445: </script>
5446: ENDSCRIPT
1.187 albertel 5447: my $href="/adm/pickcode?".
1.359 www 5448: "form=".&escape("scantronupload").
5449: "&scantron_format=".&escape($env{'form.scantron_format'}).
5450: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
5451: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
5452: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 5453: if ($env{'form.scantron_CODElist'} =~ /\S/) {
5454: $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')\" />");
5455: $r->print("\n<br />");
5456: }
1.272 albertel 5457: $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 5458: $r->print("\n<br /><br />");
1.157 albertel 5459: } elsif ($error eq 'doublebubble') {
5460: $r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
5461: $r->print('<input type="hidden" name="scantron_questions" value="'.
5462: join(',',@{$arg}).'" />');
1.242 albertel 5463: $r->print($message);
1.157 albertel 5464: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5465: foreach my $question (@{$arg}) {
5466: my $selected=$$scan_record{"scantron.$question.answer"};
5467: &scantron_bubble_selector($r,$scan_config,$question,split('',$selected));
5468: }
5469: } elsif ($error eq 'missingbubble') {
5470: $r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
1.242 albertel 5471: $r->print($message);
1.157 albertel 5472: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5473: $r->print("Some questions have no scanned bubbles\n");
5474: $r->print('<input type="hidden" name="scantron_questions" value="'.
5475: join(',',@{$arg}).'" />');
5476: foreach my $question (@{$arg}) {
5477: my $selected=$$scan_record{"scantron.$question.answer"};
5478: &scantron_bubble_selector($r,$scan_config,$question);
5479: }
5480: } else {
5481: $r->print("\n<ul>");
5482: }
5483: $r->print("\n</li></ul>");
5484:
5485: }
5486:
5487: sub scantron_bubble_selector {
5488: my ($r,$scan_config,$quest,@selected)=@_;
5489: my $max=$$scan_config{'Qlength'};
1.274 albertel 5490:
5491: my $scmode=$$scan_config{'Qon'};
5492: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
5493:
1.157 albertel 5494: my @alphabet=('A'..'Z');
5495: $r->print("<table border='1'><tr><td rowspan='2'>$quest</td>");
5496: for (my $i=0;$i<$max+1;$i++) {
1.274 albertel 5497: $r->print("\n".'<td align="center">');
1.157 albertel 5498: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
5499: else { $r->print(' '); }
5500: $r->print('</td>');
5501: }
1.274 albertel 5502: $r->print('</tr><tr>');
1.157 albertel 5503: for (my $i=0;$i<$max;$i++) {
1.274 albertel 5504: $r->print("\n".
5505: '<td><label><input type="radio" name="scantron_correct_Q_'.
1.272 albertel 5506: $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
1.157 albertel 5507: }
1.272 albertel 5508: $r->print('<td><label><input type="radio" name="scantron_correct_Q_'.
5509: $quest.'" value="none" /> No bubble </label></td>');
1.157 albertel 5510: $r->print('</tr></table>');
5511: }
5512:
1.194 albertel 5513: sub num_matches {
5514: my ($orig,$code) = @_;
5515: my @code=split(//,$code);
5516: my @orig=split(//,$orig);
5517: my $same=0;
5518: for (my $i=0;$i<scalar(@code);$i++) {
5519: if ($code[$i] eq $orig[$i]) { $same++; }
5520: }
5521: return $same;
5522: }
5523:
5524: sub scantron_get_closely_matching_CODEs {
5525: my ($allcodes,$CODE)=@_;
5526: my @CODEs;
5527: foreach my $testcode (sort(keys(%{$allcodes}))) {
5528: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
5529: }
5530:
5531: return ($#CODEs,$CODEs[-1]);
5532: }
5533:
5534: sub get_codes {
1.280 foxr 5535: my ($old_name, $cdom, $cnum) = @_;
5536: if (!$old_name) {
5537: $old_name=$env{'form.scantron_CODElist'};
5538: }
5539: if (!$cdom) {
5540: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
5541: }
5542: if (!$cnum) {
5543: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
5544: }
1.278 albertel 5545: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
5546: $cdom,$cnum);
5547: my %allcodes;
5548: if ($result{"type\0$old_name"} eq 'number') {
5549: %allcodes=map {($_,1)} split(',',$result{$old_name});
5550: } else {
5551: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
5552: }
1.194 albertel 5553: return %allcodes;
5554: }
5555:
1.157 albertel 5556: sub scantron_validate_CODE {
5557: my ($r,$currentphase) = @_;
1.257 albertel 5558: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 5559: if ($scantron_config{'CODElocation'} &&
5560: $scantron_config{'CODEstart'} &&
5561: $scantron_config{'CODElength'}) {
1.257 albertel 5562: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 5563: &FIXME_blow_up()
5564: }
5565: } else {
5566: return (0,$currentphase+1);
5567: }
5568:
5569: my %usedCODEs;
5570:
1.194 albertel 5571: my %allcodes=&get_codes();
1.186 albertel 5572:
5573: my ($scanlines,$scan_data)=&scantron_getfile();
5574: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5575: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 5576: if ($line=~/^[\s\cz]*$/) { next; }
5577: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5578: $scan_data);
5579: my $CODE=$$scan_record{'scantron.CODE'};
5580: my $error=0;
1.224 albertel 5581: if (!&Apache::lonnet::validCODE($CODE)) {
5582: &scantron_get_correction($r,$i,$scan_record,
5583: \%scantron_config,
5584: $line,'incorrectCODE',\%allcodes);
5585: return(1,$currentphase);
5586: }
1.221 albertel 5587: if (%allcodes && !exists($allcodes{$CODE})
5588: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 5589: &scantron_get_correction($r,$i,$scan_record,
5590: \%scantron_config,
1.194 albertel 5591: $line,'incorrectCODE',\%allcodes);
5592: return(1,$currentphase);
1.186 albertel 5593: }
1.214 albertel 5594: if (exists($usedCODEs{$CODE})
1.257 albertel 5595: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 5596: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 5597: &scantron_get_correction($r,$i,$scan_record,
5598: \%scantron_config,
1.194 albertel 5599: $line,'duplicateCODE',$usedCODEs{$CODE});
5600: return(1,$currentphase);
1.186 albertel 5601: }
1.194 albertel 5602: push (@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 5603: }
1.157 albertel 5604: return (0,$currentphase+1);
5605: }
5606:
5607: sub scantron_validate_doublebubble {
5608: my ($r,$currentphase) = @_;
5609: #get student info
5610: my $classlist=&Apache::loncoursedata::get_classlist();
5611: my %idmap=&username_to_idmap($classlist);
5612:
5613: #get scantron line setup
1.257 albertel 5614: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5615: my ($scanlines,$scan_data)=&scantron_getfile();
5616: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5617: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5618: if ($line=~/^[\s\cz]*$/) { next; }
5619: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5620: $scan_data);
5621: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
5622: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
5623: 'doublebubble',
5624: $$scan_record{'scantron.doubleerror'});
5625: return (1,$currentphase);
5626: }
5627: return (0,$currentphase+1);
5628: }
5629:
1.330 albertel 5630: sub scantron_get_maxbubble {
1.257 albertel 5631: if (defined($env{'form.scantron_maxbubble'}) &&
5632: $env{'form.scantron_maxbubble'}) {
5633: return $env{'form.scantron_maxbubble'};
1.191 albertel 5634: }
1.330 albertel 5635:
1.191 albertel 5636: my $navmap=Apache::lonnavmaps::navmap->new();
5637: my (undef,undef,$sequence)=
1.257 albertel 5638: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 5639:
1.191 albertel 5640: my $map=$navmap->getResourceByUrl($sequence);
5641: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 5642:
5643: &Apache::lonxml::clear_problem_counter();
5644:
1.191 albertel 5645: foreach my $resource (@resources) {
1.330 albertel 5646: my $result=&Apache::lonnet::ssi($resource->src(),
5647: ('symb' => $resource->symb()));
1.191 albertel 5648: }
5649: &Apache::lonnet::delenv('scantron\.');
1.330 albertel 5650: $env{'form.scantron_maxbubble'} =
5651: &Apache::lonxml::get_problem_counter()-1;
5652:
1.257 albertel 5653: return $env{'form.scantron_maxbubble'};
1.191 albertel 5654: }
5655:
1.157 albertel 5656: sub scantron_validate_missingbubbles {
5657: my ($r,$currentphase) = @_;
5658: #get student info
5659: my $classlist=&Apache::loncoursedata::get_classlist();
5660: my %idmap=&username_to_idmap($classlist);
5661:
5662: #get scantron line setup
1.257 albertel 5663: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5664: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 5665: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 5666: if (!$max_bubble) { $max_bubble=2**31; }
5667: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5668: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5669: if ($line=~/^[\s\cz]*$/) { next; }
5670: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5671: $scan_data);
5672: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
5673: my @to_correct;
5674: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
5675: if ($missing > $max_bubble) { next; }
5676: push(@to_correct,$missing);
5677: }
5678: if (@to_correct) {
5679: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5680: $line,'missingbubble',\@to_correct);
5681: return (1,$currentphase);
5682: }
5683:
5684: }
5685: return (0,$currentphase+1);
5686: }
5687:
1.82 albertel 5688: sub scantron_process_students {
1.75 albertel 5689: my ($r) = @_;
1.257 albertel 5690: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 5691: my ($symb)=&get_symb($r);
1.81 albertel 5692: if (!$symb) {return '';}
1.324 albertel 5693: my $default_form_data=&defaultFormData($symb);
1.82 albertel 5694:
1.257 albertel 5695: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5696: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 5697: my $classlist=&Apache::loncoursedata::get_classlist();
5698: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 5699: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 5700: my $map=$navmap->getResourceByUrl($sequence);
5701: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 5702: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 5703: my $result= <<SCANTRONFORM;
1.81 albertel 5704: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
5705: <input type="hidden" name="command" value="scantron_configphase" />
5706: $default_form_data
5707: SCANTRONFORM
1.82 albertel 5708: $r->print($result);
5709:
5710: my @delayqueue;
1.140 albertel 5711: my %completedstudents;
5712:
1.200 albertel 5713: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 5714: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 5715: 'Scantron Progress',$count,
1.195 albertel 5716: 'inline',undef,'scantronupload');
1.140 albertel 5717: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
5718: 'Processing first student');
5719: my $start=&Time::HiRes::time();
1.158 albertel 5720: my $i=-1;
1.200 albertel 5721: my ($uname,$udom,$started);
1.157 albertel 5722: while ($i<$scanlines->{'count'}) {
5723: ($uname,$udom)=('','');
5724: $i++;
1.200 albertel 5725: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5726: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 5727: if ($started) {
5728: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
5729: 'last student');
5730: }
5731: $started=1;
1.157 albertel 5732: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5733: $scan_data);
5734: unless ($uname=&scantron_find_student($scan_record,$scan_data,
5735: \%idmap,$i)) {
5736: &scantron_add_delay(\@delayqueue,$line,
5737: 'Unable to find a student that matches',1);
5738: next;
5739: }
5740: if (exists $completedstudents{$uname}) {
5741: &scantron_add_delay(\@delayqueue,$line,
5742: 'Student '.$uname.' has multiple sheets',2);
5743: next;
5744: }
5745: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 5746:
5747: &Apache::lonxml::clear_problem_counter();
1.157 albertel 5748: &Apache::lonnet::appenv(%$scan_record);
1.376 albertel 5749:
5750: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
5751: &scantron_putfile($scanlines,$scan_data);
5752: }
1.161 albertel 5753:
5754: my $i=0;
1.83 albertel 5755: foreach my $resource (@resources) {
1.85 albertel 5756: $i++;
1.193 albertel 5757: my %form=('submitted' =>'scantron',
5758: 'grade_target' =>'grade',
5759: 'grade_username'=>$uname,
5760: 'grade_domain' =>$udom,
1.257 albertel 5761: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 5762: 'grade_symb' =>$resource->symb());
1.383 albertel 5763: if (exists($scan_record->{'scantron.CODE'})
5764: &&
5765: &Apache::lonnet::validCODE($scan_record->{'scantron.CODE'})) {
1.193 albertel 5766: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 5767: } else {
5768: $form{'CODE'}='';
1.193 albertel 5769: }
5770: my $result=&Apache::lonnet::ssi($resource->src(),%form);
1.227 albertel 5771: if ($result ne '') {
5772: &Apache::lonnet::logthis("scantron grading error -> $result");
1.257 albertel 5773: &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src());
1.227 albertel 5774: }
1.213 albertel 5775: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 5776: }
1.140 albertel 5777: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 5778: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 5779: } continue {
1.330 albertel 5780: &Apache::lonxml::clear_problem_counter();
1.83 albertel 5781: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 5782: }
1.140 albertel 5783: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.172 albertel 5784: # my $lasttime = &Time::HiRes::time()-$start;
5785: # $r->print("<p>took $lasttime</p>");
1.140 albertel 5786:
1.200 albertel 5787: $r->print("</form>");
1.324 albertel 5788: $r->print(&show_grading_menu_form($symb));
1.157 albertel 5789: return '';
1.75 albertel 5790: }
1.157 albertel 5791:
5792: sub scantron_upload_scantron_data {
5793: my ($r)=@_;
1.257 albertel 5794: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 5795: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 5796: 'domainid',
5797: 'coursename');
1.257 albertel 5798: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 5799: 'domainid');
1.324 albertel 5800: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.157 albertel 5801: $r->print(<<UPLOAD);
5802: <script type="text/javascript" language="javascript">
5803: function checkUpload(formname) {
5804: if (formname.upfile.value == "") {
5805: alert("Please use the browse button to select a file from your local directory.");
5806: return false;
5807: }
5808: formname.submit();
5809: }
5810: </script>
5811:
5812: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
1.162 albertel 5813: $default_form_data
1.181 albertel 5814: <table>
5815: <tr><td>$select_link </td></tr>
5816: <tr><td>Course ID: </td><td><input name='courseid' type='text' /> </td></tr>
5817: <tr><td>Course Name: </td><td><input name='coursename' type='text' /></td></tr>
5818: <tr><td>Domain: </td><td>$domsel </td></tr>
5819: <tr><td>File to upload:</td><td><input type="file" name="upfile" size="50" /></td></tr>
5820: </table>
1.157 albertel 5821: <input name='command' value='scantronupload_save' type='hidden' />
5822: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
5823: </form>
5824: UPLOAD
5825: return '';
5826: }
5827:
5828: sub scantron_upload_scantron_data_save {
5829: my($r)=@_;
1.324 albertel 5830: my ($symb)=&get_symb($r,1);
1.182 albertel 5831: my $doanotherupload=
5832: '<br /><form action="/adm/grades" method="post">'."\n".
5833: '<input type="hidden" name="command" value="scantronupload" />'."\n".
5834: '<input type="submit" name="submit" value="Do Another Upload" />'."\n".
5835: '</form>'."\n";
1.257 albertel 5836: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 5837: !&Apache::lonnet::allowed('usc',
1.257 albertel 5838: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.162 albertel 5839: $r->print("You are not allowed to upload Scantron data to the requested course.<br />");
1.182 albertel 5840: if ($symb) {
1.324 albertel 5841: $r->print(&show_grading_menu_form($symb));
1.182 albertel 5842: } else {
5843: $r->print($doanotherupload);
5844: }
1.162 albertel 5845: return '';
5846: }
1.257 albertel 5847: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.211 ng 5848: $r->print("Doing upload to ".$coursedata{'description'}." <br />");
1.257 albertel 5849: my $fname=$env{'form.upfile.filename'};
1.157 albertel 5850: #FIXME
5851: #copied from lonnet::userfileupload()
5852: #make that function able to target a specified course
5853: # Replace Windows backslashes by forward slashes
5854: $fname=~s/\\/\//g;
5855: # Get rid of everything but the actual filename
5856: $fname=~s/^.*\/([^\/]+)$/$1/;
5857: # Replace spaces by underscores
5858: $fname=~s/\s+/\_/g;
5859: # Replace all other weird characters by nothing
5860: $fname=~s/[^\w\.\-]//g;
5861: # See if there is anything left
5862: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 5863: my $uploadedfile=$fname;
1.157 albertel 5864: $fname='scantron_orig_'.$fname;
1.257 albertel 5865: if (length($env{'form.upfile'}) < 2) {
5866: $r->print("<font color='red'>Error:</font> 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 5867: } else {
1.275 albertel 5868: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 5869: if ($result =~ m|^/uploaded/|) {
1.257 albertel 5870: $r->print("<font color='green'>Success:</font> Successfully uploaded ".(length($env{'form.upfile'})-1)." bytes of data into location <tt>".$result."</tt>");
1.210 albertel 5871: } else {
1.257 albertel 5872: $r->print("<font color='red'>Error:</font> An error (".$result.") occurred when attempting to upload the file, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>");
1.183 albertel 5873: }
5874: }
1.174 albertel 5875: if ($symb) {
1.209 ng 5876: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 5877: } else {
1.182 albertel 5878: $r->print($doanotherupload);
1.174 albertel 5879: }
1.157 albertel 5880: return '';
5881: }
5882:
1.202 albertel 5883: sub valid_file {
5884: my ($requested_file)=@_;
5885: foreach my $filename (sort(&scantron_filenames())) {
5886: if ($requested_file eq $filename) { return 1; }
5887: }
5888: return 0;
5889: }
5890:
5891: sub scantron_download_scantron_data {
5892: my ($r)=@_;
1.324 albertel 5893: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5894: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5895: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5896: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 5897: if (! &valid_file($file)) {
5898: $r->print(<<ERROR);
5899: <p>
5900: The requested file name was invalid.
5901: </p>
5902: ERROR
1.324 albertel 5903: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5904: return;
5905: }
5906: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
5907: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
5908: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
5909: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
5910: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
5911: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
5912: $r->print(<<DOWNLOAD);
5913: <p>
5914: <a href="$orig">Original</a> file as uploaded by the scantron office.
5915: </p>
5916: <p>
5917: <a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
5918: </p>
5919: <p>
5920: <a href="$skipped">Skipped</a>, a file of records that were skipped.
5921: </p>
5922: DOWNLOAD
1.324 albertel 5923: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 5924: return '';
5925: }
1.157 albertel 5926:
1.75 albertel 5927: #-------- end of section for handling grading scantron forms -------
5928: #
5929: #-------------------------------------------------------------------
5930:
1.72 ng 5931: #-------------------------- Menu interface -------------------------
5932: #
5933: #--- Show a Grading Menu button - Calls the next routine ---
5934: sub show_grading_menu_form {
1.324 albertel 5935: my ($symb)=@_;
1.125 ng 5936: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.72 ng 5937: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 5938: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 5939: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
5940: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
5941: '</form>'."\n";
5942: return $result;
5943: }
5944:
1.77 ng 5945: # -- Retrieve choices for grading form
5946: sub savedState {
5947: my %savedState = ();
1.257 albertel 5948: if ($env{'form.saveState'}) {
5949: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 5950: my ($key,$value) = split(/=/,$_,2);
5951: $savedState{$key} = $value;
5952: }
5953: }
5954: return \%savedState;
5955: }
1.76 ng 5956:
1.72 ng 5957: #--- Displays the main menu page -------
5958: sub gradingmenu {
5959: my ($request) = @_;
1.324 albertel 5960: my ($symb)=&get_symb($request);
1.72 ng 5961: if (!$symb) {return '';}
1.76 ng 5962: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 5963:
5964: $request->print(<<GRADINGMENUJS);
5965: <script type="text/javascript" language="javascript">
1.116 ng 5966: function checkChoice(formname,val,cmdx) {
5967: if (val <= 2) {
5968: var cmd = radioSelection(formname.radioChoice);
1.118 ng 5969: var cmdsave = cmd;
1.116 ng 5970: } else {
5971: cmd = cmdx;
1.118 ng 5972: cmdsave = 'submission';
1.116 ng 5973: }
5974: formname.command.value = cmd;
1.118 ng 5975: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 5976: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 5977: if (val < 5) formname.submit();
5978: if (val == 5) {
1.72 ng 5979: if (!checkReceiptNo(formname,'notOK')) { return false;}
5980: formname.submit();
5981: }
1.238 albertel 5982: if (val < 7) formname.submit();
1.72 ng 5983: }
5984:
5985: function checkReceiptNo(formname,nospace) {
5986: var receiptNo = formname.receipt.value;
5987: var checkOpt = false;
5988: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
5989: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
5990: if (checkOpt) {
5991: alert("Please enter a receipt number given by a student in the receipt box.");
5992: formname.receipt.value = "";
5993: formname.receipt.focus();
5994: return false;
5995: }
5996: return true;
5997: }
5998: </script>
5999: GRADINGMENUJS
1.118 ng 6000: &commonJSfunctions($request);
6001: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>';
1.324 albertel 6002: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.118 ng 6003: $result.=$table;
1.76 ng 6004: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 6005: my $savedState = &savedState();
1.118 ng 6006: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 6007: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 6008: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 6009: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 6010:
6011: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
6012: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
6013: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
6014: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 6015: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 6016: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 6017: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 6018: '<input type="hidden" name="showgrading" value="yes" />'."\n";
6019:
1.326 albertel 6020: $result.='<table width="100%" border="0"><tr><td bgcolor=#777777>'."\n".
6021: '<table width="100%" border="0"><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 6022: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 6023: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
6024:
1.326 albertel 6025: $result.='<table width="100%" border="0">';
1.116 ng 6026: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.167 sakharuk 6027: ' '.&mt('Select Section').': <select name="section">'."\n";
1.116 ng 6028: if (ref($sections)) {
1.155 albertel 6029: foreach (sort (@$sections)) {
6030: $result.='<option value="'.$_.'" '.
6031: ($saveSec eq $_ ? 'selected="on"':'').'>'.$_.'</option>'."\n";
6032: }
1.116 ng 6033: }
1.238 albertel 6034: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</option></select> ';
1.116 ng 6035:
1.167 sakharuk 6036: $result.=&mt('Student Status').':</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 6037:
1.116 ng 6038: $result.='</td></tr>';
6039:
1.288 albertel 6040: $result.='<tr bgcolor="#ffffe6"valign="top"><td><label>'.
1.118 ng 6041: '<input type="radio" name="radioChoice" value="submission" '.
1.326 albertel 6042: ($saveCmd eq 'submission' ? 'checked' : '').' /> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
1.288 albertel 6043: '</label> <select name="submitonly">'.
1.145 albertel 6044: '<option value="yes" '.
1.326 albertel 6045: ($saveSub eq 'yes' ? 'selected="on"' : '').' />'.&mt('with submissions').'</option>'.
1.301 albertel 6046: '<option value="queued" '.
1.326 albertel 6047: ($saveSub eq 'queued' ? 'selected="on"' : '').' />'.&mt('in grading queue').'</option>'.
1.145 albertel 6048: '<option value="graded" '.
1.326 albertel 6049: ($saveSub eq 'graded' ? 'selected="on"' : '').' />'.&mt('with ungraded submissions').'</option>'.
1.156 albertel 6050: '<option value="incorrect" '.
1.326 albertel 6051: ($saveSub eq 'incorrect' ? 'selected="on"' : '').' />'.&mt('with incorrect submissions').'</option>'.
1.145 albertel 6052: '<option value="all" '.
1.326 albertel 6053: ($saveSub eq 'all' ? 'selected="on"' : '').' />'.&mt('with any status').'</option></select></td></tr>'."\n";
1.72 ng 6054:
1.116 ng 6055: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.288 albertel 6056: '<label><input type="radio" name="radioChoice" value="viewgrades" '.
1.326 albertel 6057: ($saveCmd eq 'viewgrades' ? 'checked' : '').' /> '.
1.288 albertel 6058: '<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
1.72 ng 6059:
1.118 ng 6060: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
1.288 albertel 6061: '<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
1.326 albertel 6062: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').' /> '.
1.288 albertel 6063: 'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
1.46 ng 6064:
1.116 ng 6065: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 6066: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 6067: '</td></tr></table>'."\n";
6068:
6069: $result.='</td><td valign="top">';
6070:
1.326 albertel 6071: $result.='<table width="100%" border="0">';
1.116 ng 6072: $result.='<tr bgcolor="#ffffe6"><td>'.
1.184 www 6073: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
6074: ' '.&mt('scores from file').' </td></tr>'."\n";
1.72 ng 6075:
1.75 albertel 6076: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 6077: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
1.184 www 6078: '" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
1.75 albertel 6079:
1.257 albertel 6080: if ((&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && ($symb)) {
1.72 ng 6081: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.184 www 6082: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
6083: ' '.&mt('receipt').': '.
1.257 albertel 6084: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.326 albertel 6085: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />'.
1.72 ng 6086: '</td></tr>'."\n";
6087: }
1.238 albertel 6088: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
6089: '<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
6090: '" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
1.279 albertel 6091: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
6092: '<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
6093: '" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
1.44 ng 6094:
1.116 ng 6095: $result.='</form></td></tr></table>'."\n".
1.72 ng 6096: '</td></tr></table>'."\n".
6097: '</td></tr></table>'."\n";
1.44 ng 6098: return $result;
1.2 albertel 6099: }
6100:
1.285 albertel 6101: sub reset_perm {
6102: undef(%perm);
6103: }
6104:
6105: sub init_perm {
6106: &reset_perm();
1.300 albertel 6107: foreach my $test_perm ('vgr','mgr','opa') {
6108:
6109: my $scope = $env{'request.course.id'};
6110: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
6111:
6112: $scope .= '/'.$env{'request.course.sec'};
6113: if ( $perm{$test_perm}=
6114: &Apache::lonnet::allowed($test_perm,$scope)) {
6115: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
6116: } else {
6117: delete($perm{$test_perm});
6118: }
1.285 albertel 6119: }
6120: }
6121: }
6122:
1.1 albertel 6123: sub handler {
1.41 ng 6124: my $request=$_[0];
1.102 albertel 6125:
1.285 albertel 6126: &reset_perm();
1.257 albertel 6127: if ($env{'browser.mathml'}) {
1.141 www 6128: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 6129: } else {
1.141 www 6130: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 6131: }
6132: $request->send_http_header;
1.44 ng 6133: return '' if $request->header_only;
1.41 ng 6134: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 6135: my $symb=&get_symb($request,1);
1.160 albertel 6136: my @commands=&Apache::loncommon::get_env_multiple('form.command');
6137: my $command=$commands[0];
6138: if ($#commands > 0) {
6139: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
6140: }
1.353 albertel 6141: $request->print(&Apache::loncommon::start_page('Grading'));
1.324 albertel 6142: if ($symb eq '' && $command eq '') {
1.257 albertel 6143: if ($env{'user.adv'}) {
6144: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
6145: ($env{'form.codethree'})) {
6146: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
6147: $env{'form.codethree'};
1.41 ng 6148: my ($tsymb,$tuname,$tudom,$tcrsid)=
6149: &Apache::lonnet::checkin($token);
6150: if ($tsymb) {
1.137 albertel 6151: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 6152: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 6153: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
6154: ('grade_username' => $tuname,
6155: 'grade_domain' => $tudom,
6156: 'grade_courseid' => $tcrsid,
6157: 'grade_symb' => $tsymb)));
1.41 ng 6158: } else {
1.45 ng 6159: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 6160: }
1.41 ng 6161: } else {
1.45 ng 6162: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 6163: }
1.14 www 6164: } else {
1.41 ng 6165: $request->print(&Apache::lonxml::tokeninputfield());
6166: }
6167: }
6168: } else {
1.285 albertel 6169: &init_perm();
1.104 albertel 6170: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 6171: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 6172: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 6173: &pickStudentPage($request);
1.103 albertel 6174: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 6175: &displayPage($request);
1.104 albertel 6176: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 6177: &updateGradeByPage($request);
1.104 albertel 6178: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 6179: &processGroup($request);
1.104 albertel 6180: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 6181: $request->print(&gradingmenu($request));
1.104 albertel 6182: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 6183: $request->print(&viewgrades($request));
1.104 albertel 6184: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 6185: $request->print(&processHandGrade($request));
1.106 albertel 6186: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 6187: $request->print(&editgrades($request));
1.106 albertel 6188: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 6189: $request->print(&verifyreceipt($request));
1.106 albertel 6190: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 6191: $request->print(&upcsvScores_form($request));
1.106 albertel 6192: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 6193: $request->print(&csvupload($request));
1.106 albertel 6194: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 6195: $request->print(&csvuploadmap($request));
1.246 albertel 6196: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 6197: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 6198: $request->print(&csvuploadoptions($request));
1.41 ng 6199: } else {
1.257 albertel 6200: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
6201: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 6202: } else {
1.257 albertel 6203: $env{'form.upfile_associate'} = 'forward';
1.41 ng 6204: }
6205: $request->print(&csvuploadmap($request));
6206: }
1.246 albertel 6207: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
6208: $request->print(&csvuploadassign($request));
1.106 albertel 6209: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 6210: $request->print(&scantron_selectphase($request));
1.203 albertel 6211: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
6212: $request->print(&scantron_do_warning($request));
1.142 albertel 6213: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
6214: $request->print(&scantron_validate_file($request));
1.106 albertel 6215: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 6216: $request->print(&scantron_process_students($request));
1.157 albertel 6217: } elsif ($command eq 'scantronupload' &&
1.257 albertel 6218: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6219: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 6220: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 6221: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 6222: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
6223: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 6224: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 6225: } elsif ($command eq 'scantron_download' &&
1.257 albertel 6226: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 6227: $request->print(&scantron_download_scantron_data($request));
1.106 albertel 6228: } elsif ($command) {
1.157 albertel 6229: $request->print("Access Denied ($command)");
1.26 albertel 6230: }
1.2 albertel 6231: }
1.353 albertel 6232: $request->print(&Apache::loncommon::end_page());
1.44 ng 6233: return '';
6234: }
6235:
1.1 albertel 6236: 1;
6237:
1.13 albertel 6238: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>