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