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