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