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