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