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