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