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