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