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