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