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