Annotation of loncom/homework/grades.pm, revision 1.318
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.318 ! banghart 4: # $Id: grades.pm,v 1.317 2006/02/26 01:04:47 banghart Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: package Apache::grades;
30: use strict;
31: use Apache::style;
32: use Apache::lonxml;
33: use Apache::lonnet;
1.3 albertel 34: use Apache::loncommon;
1.112 ng 35: use Apache::lonhtmlcommon;
1.68 ng 36: use Apache::lonnavmaps;
1.1 albertel 37: use Apache::lonhomework;
1.55 matthew 38: use Apache::loncoursedata;
1.38 ng 39: use Apache::lonmsg qw(:user_normal_msg);
1.1 albertel 40: use Apache::Constants qw(:common);
1.167 sakharuk 41: use Apache::lonlocal;
1.170 albertel 42: use String::Similarity;
1.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.317 banghart 1416: my ($request,$symb,$uname,$udom,$counter,$partid,$record,$respid) = @_;
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 '' ?
1424: '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
1425: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.318 ! banghart 1426: $result.='<br />'.$partid.' - '.$respid.'<br />';
1.207 albertel 1427: my $display_part=&get_display_part($partid,undef,$symb);
1.270 albertel 1428: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1429: [$partid]);
1430: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1431: if ($last_resets{$partid}) {
1432: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1433: }
1.71 ng 1434: $result.='<table border="0"><tr><td>'.
1.207 albertel 1435: '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
1.71 ng 1436: my $ctr = 0;
1437: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1438: while ($ctr<=$wgt) {
1.288 albertel 1439: $result.= '<td><nobr><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1440: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.72 ng 1441: $ctr.')" value="'.$ctr.'" '.
1.288 albertel 1442: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</label></nobr></td>\n";
1.71 ng 1443: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1444: $ctr++;
1445: }
1446: $result.='</tr></table>';
1447: $result.='</td><td> <b>or</b> </td>'."\n";
1448: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1449: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1450: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1451: $wgt.')" /></td>'."\n";
1452: $result.='<td>/'.$wgt.' '.$wgtmsg.
1453: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1454: ' </td><td>'."\n";
1455: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1456: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1457: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1458: $result.='<option> </option>'.
1.125 ng 1459: '<option selected="on">excused</option>';
1.71 ng 1460: } else {
1461: $result.='<option selected="on"> </option>'.
1.125 ng 1462: '<option>excused</option>';
1.71 ng 1463: }
1.125 ng 1464: $result.='<option>reset status</option></select>'."\n";
1.71 ng 1465: $result.="  \n";
1466: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1467: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1468: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1469: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1470: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1471: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1472: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1473: $aggtries.'" />'."\n";
1.71 ng 1474: $result.='</td></tr></table>'."\n";
1.318 ! banghart 1475: $result.=&handbackBox($uname,$udom,$counter,$partid,$record,$respid);
! 1476: return $result;
! 1477: }
! 1478: sub handbackBox {
! 1479: my ($uname,$udom,$counter,$partid,$record,$respid) = @_;
! 1480: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
! 1481: my $result;
1.313 banghart 1482: if (@$files) {
1483: my $file_counter = 0;
1484: foreach my $file (@$files) {
1485: $result.=' Return commented document to student. <input type="file" name="part'.$partid.'_returndoc';
1486: $result.=$file_counter.'" />'."\n";
1.318 ! banghart 1487: $result.='<input type="hidden" name="respid" value="'.$respid.'" />';
! 1488: $result.='<input type="hidden" name="returndocorig'.$file_counter.'" value="'.$file.'" /><br />';
1.313 banghart 1489: }
1490: }
1.318 ! banghart 1491: return $result;
1.71 ng 1492: }
1.44 ng 1493:
1.58 albertel 1494: sub show_problem {
1.144 albertel 1495: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
1496: my $rendered;
1497: if ($mode eq 'both' or $mode eq 'text') {
1498: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.257 albertel 1499: $env{'request.course.id'});
1.144 albertel 1500: }
1.58 albertel 1501: if ($removeform) {
1502: $rendered=~s|<form(.*?)>||g;
1503: $rendered=~s|</form>||g;
1504: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
1505: }
1.144 albertel 1506: my $companswer;
1507: if ($mode eq 'both' or $mode eq 'answer') {
1508: $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
1.257 albertel 1509: $env{'request.course.id'});
1.144 albertel 1510: }
1.58 albertel 1511: if ($removeform) {
1512: $companswer=~s|<form(.*?)>||g;
1513: $companswer=~s|</form>||g;
1.144 albertel 1514: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1515: }
1516: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 1517: $result.='<table border="0" width="100%">';
1.144 albertel 1518: if ($viewon) {
1519: $result.='<tr><td bgcolor="#e6ffff"><b> ';
1520: if ($mode eq 'both' or $mode eq 'text') {
1521: $result.='View of the problem - ';
1522: } else {
1523: $result.='Correct answer: ';
1524: }
1.257 albertel 1525: $result.=$env{'form.fullname'}.'</b></td></tr>';
1.144 albertel 1526: }
1527: if ($mode eq 'both') {
1528: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1529: $result.='<b>Correct answer:</b><br />'.$companswer;
1530: } elsif ($mode eq 'text') {
1531: $result.='<tr><td bgcolor="#ffffff">'.$rendered;
1532: } elsif ($mode eq 'answer') {
1533: $result.='<tr><td bgcolor="#ffffff">'.$companswer;
1534: }
1.58 albertel 1535: $result.='</td></tr></table>';
1536: $result.='</td></tr></table><br />';
1.71 ng 1537: return $result;
1.58 albertel 1538: }
1539:
1.44 ng 1540: # --------------------------- show submissions of a student, option to grade
1541: sub submission {
1542: my ($request,$counter,$total) = @_;
1543:
1.257 albertel 1544: (my $url=$env{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1545: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1546: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1547: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1548: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.41 ng 1549:
1.257 albertel 1550: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.41 ng 1551: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.104 albertel 1552:
1553: if (!&canview($usec)) {
1.116 ng 1554: $request->print('<font color="red">Unable to view requested student.('.
1.222 albertel 1555: $uname.'@'.$udom.' in section '.$usec.' in course id '.
1.257 albertel 1556: $env{'request.course.id'}.')</font>');
1.104 albertel 1557: $request->print(&show_grading_menu_form($symb,$url));
1558: return;
1559: }
1560:
1.257 albertel 1561: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1562: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1563: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1564: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.122 ng 1565: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
1566: '/check.gif" height="16" border="0" />';
1.41 ng 1567:
1568: # header info
1569: if ($counter == 0) {
1570: &sub_page_js($request);
1.257 albertel 1571: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1572: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1573: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.76 ng 1574:
1.45 ng 1575: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.257 albertel 1576: '<font size=+1> <b>Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n");
1.118 ng 1577:
1.257 albertel 1578: if ($env{'form.handgrade'} eq 'no') {
1.118 ng 1579: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1580: $checkIcon.' symbol.'."\n";
1581: $request->print($checkMark);
1582: }
1.41 ng 1583:
1.44 ng 1584: # option to display problem, only once else it cause problems
1585: # with the form later since the problem has a form.
1.257 albertel 1586: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1587: my $mode;
1.257 albertel 1588: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1589: $mode='both';
1.257 albertel 1590: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1591: $mode='text';
1.257 albertel 1592: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1593: $mode='answer';
1594: }
1595: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1596: }
1597:
1.44 ng 1598: # kwclr is the only variable that is guaranteed to be non blank
1599: # if this subroutine has been called once.
1.41 ng 1600: my %keyhash = ();
1.257 albertel 1601: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1602: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1603: $env{'course.'.$env{'request.course.id'}.'.domain'},
1604: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1605:
1.257 albertel 1606: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1607: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1608: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1609: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1610: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1611: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1612: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1613: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1614: }
1.257 albertel 1615: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.44 ng 1616:
1.303 banghart 1617: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1618: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1619: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1620: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.120 ng 1621: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1622: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1623: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1624: '<input type="hidden" name="studentNo" value="" />'."\n".
1625: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.41 ng 1626: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1627: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.257 albertel 1628: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1629: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1630: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1631: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1632: '<input type="hidden" name="section" value="'.$env{'form.section'}.'">'."\n".
1633: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'">'."\n".
1634: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'">'."\n".
1.41 ng 1635: '<input type="hidden" name="NCT"'.
1.257 albertel 1636: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1637: if ($env{'form.handgrade'} eq 'yes') {
1638: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1639: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1640: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1641: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1642: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1643: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1644: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1645: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1646: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1647: }
1.123 ng 1648: }
1.41 ng 1649:
1650: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1651: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1652: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1653: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1654: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1655: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1656: '" />'."\n".
1657: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1658: $cts++;
1659: }
1660: $request->print($prnmsg);
1.32 ng 1661:
1.257 albertel 1662: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1663: #
1664: # Print out the keyword options line
1665: #
1.41 ng 1666: $request->print(<<KEYWORDS);
1.38 ng 1667: <b>Keyword Options:</b>
1.122 ng 1668: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>
1.38 ng 1669: <a href="#" onMouseDown="javascript:getSel(); return false"
1670: CLASS="page">Paste Selection to List</a>
1671: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1672: KEYWORDS
1.88 www 1673: #
1674: # Load the other essays for similarity check
1675: #
1676: my $essayurl=&Apache::lonnet::declutter($url);
1677: my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
1678: $apath=&Apache::lonnet::escape($apath);
1679: $apath=~s/\W/\_/gs;
1680: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1681: }
1682: }
1.44 ng 1683:
1.257 albertel 1684: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.71 ng 1685: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1686: my $mode;
1.257 albertel 1687: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1688: $mode='both';
1.257 albertel 1689: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1690: $mode='text';
1.257 albertel 1691: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1692: $mode='answer';
1693: }
1694: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1695: }
1.144 albertel 1696:
1.257 albertel 1697: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.147 albertel 1698: my ($partlist,$handgrade,$responseType) = &response_type($url,$symb);
1.41 ng 1699:
1.44 ng 1700: # Display student info
1.41 ng 1701: $request->print(($counter == 0 ? '' : '<br />'));
1.45 ng 1702: my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
1703: '<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1704:
1.257 albertel 1705: $result.='<b>Fullname: </b>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1706: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1707: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.41 ng 1708:
1.118 ng 1709: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1710: my @col_fullnames;
1.56 matthew 1711: my ($classlist,$fullname);
1.257 albertel 1712: if ($env{'form.handgrade'} eq 'yes') {
1.80 ng 1713: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1714: for (keys (%$handgrade)) {
1.44 ng 1715: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1716: '.maxcollaborators',
1717: $symb,$udom,$uname);
1718: next if ($ncol <= 0);
1719: s/\_/\./g;
1720: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1721: my @goodcollaborators = ();
1722: my @badcollaborators = ();
1723: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1724: $_ =~ s/[\$\^\(\)]//g;
1725: next if ($_ eq '');
1.80 ng 1726: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1727: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1728: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1729: # Doing this grep allows 'fuzzy' specification
1730: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1731: if (! scalar(@Matches)) {
1732: push @badcollaborators,$_;
1733: } else {
1734: push @goodcollaborators, @Matches;
1735: }
1.80 ng 1736: }
1.86 ng 1737: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1738: $result.='<b>Collaborators: </b>';
1.86 ng 1739: foreach (@goodcollaborators) {
1740: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1741: push @col_fullnames, $givenn.' '.$lastname;
1742: $result.=$$fullname{$_}.' ';
1743: }
1.57 matthew 1744: $result.='<br />'."\n";
1.150 albertel 1745: my ($part)=split(/\./,$_);
1.86 ng 1746: $result.='<input type="hidden" name="collaborator'.$counter.
1.150 albertel 1747: '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
1748: "\n";
1.86 ng 1749: }
1750: if (scalar(@badcollaborators) > 0) {
1751: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1752: $result.='This student has submitted ';
1753: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1754: $result .= ': '.join(', ',@badcollaborators);
1755: $result .= '</td></tr></table>';
1756: }
1757: if (scalar(@badcollaborators > $ncol)) {
1758: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1759: $result .= 'This student has submitted too many '.
1760: 'collaborators. Maximum is '.$ncol.'.';
1761: $result .= '</td></tr></table>';
1762: }
1.41 ng 1763: }
1764: }
1.44 ng 1765: $request->print($result."\n");
1.33 ng 1766:
1.44 ng 1767: # print student answer/submission
1768: # Options are (1) Handgaded submission only
1769: # (2) Last submission, includes submission that is not handgraded
1770: # (for multi-response type part)
1771: # (3) Last submission plus the parts info
1772: # (4) The whole record for this student
1.257 albertel 1773: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 1774: my ($string,$timestamp)= &get_last_submission(\%record);
1775: my $lastsubonly=''.
1776: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1777: $$timestamp)."</td></tr>\n";
1778: if ($$timestamp eq '') {
1779: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1780: } else {
1781: my %seenparts;
1782: for my $part (sort keys(%$handgrade)) {
1783: my ($partid,$respid) = split(/_/,$part);
1.207 albertel 1784: my $display_part=&get_display_part($partid,$url,$symb);
1.257 albertel 1785: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 1786: if (exists($seenparts{$partid})) { next; }
1787: $seenparts{$partid}=1;
1.207 albertel 1788: my $submitby='<b>Part:</b> '.$display_part.
1789: ' <b>Collaborative submission by:</b> '.
1.151 albertel 1790: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 1791: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.151 albertel 1792: '\')"; TARGET=_self>'.
1.257 albertel 1793: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 1794: $request->print($submitby);
1795: next;
1796: }
1797: my $responsetype = $responseType->{$partid}->{$respid};
1798: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.207 albertel 1799: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1800: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1801: ' )</font> '.
1802: '<font color="red">Nothing submitted - no attempts</font><br /><br />';
1803: next;
1804: }
1805: foreach (@$string) {
1806: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1807: if ($part ne ($partid.'_'.$respid)) { next; }
1808: my ($ressub,$subval) = split(/:/,$_,2);
1809: # Similarity check
1810: my $similar='';
1.257 albertel 1811: if($env{'form.checkPlag'}){
1.151 albertel 1812: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1813: &most_similar($uname,$udom,$subval);
1814: if ($osim) {
1815: $osim=int($osim*100.0);
1816: $similar="<hr /><h3><font color=\"#FF0000\">Essay".
1817: " is $osim% similar to an essay by ".
1818: &Apache::loncommon::plainname($oname,$odom).
1819: '</font></h3><blockquote><i>'.
1820: &keywords_highlight($oessay).
1821: '</i></blockquote><hr />';
1822: }
1.150 albertel 1823: }
1.151 albertel 1824: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 1825: if ($env{'form.lastSub'} eq 'lastonly' ||
1826: ($env{'form.lastSub'} eq 'hdgrade' &&
1.151 albertel 1827: $$handgrade{$part} eq 'yes')) {
1.207 albertel 1828: my $display_part=&get_display_part($partid,$url,$symb);
1829: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1830: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1831: ' )</font> ';
1.313 banghart 1832: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
1833: if (@$files) {
1.232 albertel 1834: $lastsubonly.='<br /><font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />';
1.303 banghart 1835: my $file_counter = 0;
1.313 banghart 1836: foreach my $file (@$files) {
1.303 banghart 1837: $file_counter ++;
1.232 albertel 1838: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.314 albertel 1839: $lastsubonly.='<br /><a href="'.$file.'" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0"> '.$file.'</a>';
1.232 albertel 1840: }
1.236 albertel 1841: $lastsubonly.='<br />';
1.41 ng 1842: }
1.151 albertel 1843: $lastsubonly.='<b>Submitted Answer: </b>'.
1844: &cleanRecord($subval,$responsetype,$symb,$partid,
1845: $respid,\%record,$order);
1846: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41 ng 1847: }
1848: }
1849: }
1.151 albertel 1850: }
1851: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1852: $request->print($lastsubonly);
1.257 albertel 1853: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.122 ng 1854: my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
1.148 albertel 1855: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 1856: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1857: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 1858: $env{'request.course.id'},
1.44 ng 1859: $last,'.submission',
1860: 'Apache::grades::keywords_highlight'));
1.41 ng 1861: }
1.120 ng 1862:
1.121 ng 1863: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1864: .$udom.'" />'."\n");
1.41 ng 1865:
1.44 ng 1866: # return if view submission with no grading option
1.257 albertel 1867: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 1868: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 1869: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1870: .$counter.'\');" TARGET=_self> '."\n" if (&canmodify($usec));
1.169 albertel 1871: $toGrade.='</td></tr></table></td></tr></table>'."\n";
1.257 albertel 1872: if (($env{'form.command'} eq 'submission') ||
1873: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.169 albertel 1874: $toGrade.='</form>'.&show_grading_menu_form($symb,$url)
1875: }
1.180 albertel 1876: $request->print($toGrade);
1.41 ng 1877: return;
1.180 albertel 1878: } else {
1879: $request->print('</td></tr></table></td></tr></table>'."\n");
1.41 ng 1880: }
1.33 ng 1881:
1.121 ng 1882: # essay grading message center
1.257 albertel 1883: if ($env{'form.handgrade'} eq 'yes') {
1884: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 1885: my $msgfor = $givenn.' '.$lastname;
1886: if (scalar(@col_fullnames) > 0) {
1887: my $lastone = pop @col_fullnames;
1888: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1889: }
1890: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 1891: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1892: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
1893: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118 ng 1894: ',\''.$msgfor.'\')"; TARGET=_self>'.
1.298 www 1895: &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a> ('.
1896: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" />)'.
1.118 ng 1897: '<img src="'.$request->dir_config('lonIconsURL').
1898: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 1899: '<br /> ('.
1900: &mt('Message will be sent when you click on Save & Next below.').")\n";
1.121 ng 1901: $request->print($result);
1.118 ng 1902: }
1.300 albertel 1903: if ($perm{'vgr'}) {
1.297 www 1904: $request->print('<br />'.
1.300 albertel 1905: &Apache::loncommon::track_student_link(&mt('View recent activity'),
1906: $uname,$udom,'check'));
1.297 www 1907: }
1.300 albertel 1908: if ($perm{'opa'}) {
1.297 www 1909: $request->print('<br />'.
1.300 albertel 1910: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
1911: $uname,$udom,$symb,'check'));
1.297 www 1912: }
1.41 ng 1913:
1914: my %seen = ();
1915: my @partlist;
1.129 ng 1916: my @gradePartRespid;
1.317 banghart 1917: for my $part_resp(sort keys(%$handgrade)) {
1918: my ($partid,$respid) = split(/_/, $part_resp);
1.318 ! banghart 1919: #next if ($seen{$partid} > 0);
! 1920: if ($seen{$partid} > 0) {
! 1921: $request->print(&handbackBox($uname,$udom,$counter,$partid,\%record,$respid));
! 1922: next;
! 1923: }
1.41 ng 1924: $seen{$partid}++;
1.317 banghart 1925: next if ($$handgrade{$part_resp} =~ /:no$/ && $env{'form.lastSub'} =~ /^(hdgrade)$/);
1.41 ng 1926: push @partlist,$partid;
1.129 ng 1927: push @gradePartRespid,$partid.'.'.$respid;
1.317 banghart 1928: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record,$respid));
1.41 ng 1929: }
1.45 ng 1930: $result='<input type="hidden" name="partlist'.$counter.
1931: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 1932: $result.='<input type="hidden" name="gradePartRespid'.
1933: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 1934: my $ctr = 0;
1935: while ($ctr < scalar(@partlist)) {
1936: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1937: $partlist[$ctr].'" />'."\n";
1938: $ctr++;
1939: }
1940: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 1941:
1942: # print end of form
1943: if ($counter == $total) {
1.297 www 1944: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 1945: $endform.='<input type="button" value="Save & Next" '.
1946: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1947: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
1948: my $ntstu ='<select name="NTSTU">'.
1949: '<option>1</option><option>2</option>'.
1950: '<option>3</option><option>5</option>'.
1951: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 1952: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.119 ng 1953: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
1954: $endform.=$ntstu.'student(s) ';
1.126 ng 1955: $endform.='<input type="button" value="Previous" '.
1956: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> '."\n".
1957: '<input type="button" value="Next" '.
1958: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> ';
1959: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.45 ng 1960: $endform.='</td><tr></table></form>';
1.50 albertel 1961: $endform.=&show_grading_menu_form($symb,$url);
1.41 ng 1962: $request->print($endform);
1963: }
1964: return '';
1.38 ng 1965: }
1966:
1.44 ng 1967: #--- Retrieve the last submission for all the parts
1.38 ng 1968: sub get_last_submission {
1.119 ng 1969: my ($returnhash)=@_;
1.46 ng 1970: my (@string,$timestamp);
1.119 ng 1971: if ($$returnhash{'version'}) {
1.46 ng 1972: my %lasthash=();
1973: my ($version);
1.119 ng 1974: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1975: foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
1976: $lasthash{$_}=$$returnhash{$version.':'.$_};
1977: $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 1978: }
1979: }
1980: foreach ((keys %lasthash)) {
1981: if ($_ =~ /\.submission$/) {
1982: my ($partid,$foo) = split(/submission$/,$_);
1983: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1984: '<font color="red">Draft Copy</font> ' : '';
1985: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 1986: }
1987: }
1988: }
1.125 ng 1989: @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
1.46 ng 1990: return \@string,\$timestamp;
1.38 ng 1991: }
1.35 ng 1992:
1.44 ng 1993: #--- High light keywords, with style choosen by user.
1.38 ng 1994: sub keywords_highlight {
1.44 ng 1995: my $string = shift;
1.257 albertel 1996: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
1997: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 1998: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 1999: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.41 ng 2000: foreach (@keylist) {
1.257 albertel 2001: $string =~ s/\b\Q$_\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
1.41 ng 2002: }
2003: return $string;
1.38 ng 2004: }
1.36 ng 2005:
1.44 ng 2006: #--- Called from submission routine
1.38 ng 2007: sub processHandGrade {
1.41 ng 2008: my ($request) = shift;
1.257 albertel 2009: my $url = $env{'form.url'};
2010: my $symb = $env{'form.symb'};
2011: my $button = $env{'form.gradeOpt'};
2012: my $ngrade = $env{'form.NCT'};
2013: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2014: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2015: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2016:
1.44 ng 2017: if ($button eq 'Save & Next') {
2018: my $ctr = 0;
2019: while ($ctr < $ngrade) {
1.257 albertel 2020: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.77 ng 2021: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.71 ng 2022: if ($errorflag eq 'no_score') {
2023: $ctr++;
2024: next;
2025: }
1.104 albertel 2026: if ($errorflag eq 'not_allowed') {
2027: $request->print("<font color=\"red\">Not allowed to modify grades for $uname:$udom</font>");
2028: $ctr++;
2029: next;
2030: }
1.257 albertel 2031: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2032: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 2033: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2034: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2035: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.44 ng 2036: my (@msgnum) = split(/,/,$includemsg);
2037: foreach (@msgnum) {
1.257 albertel 2038: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2039: }
1.80 ng 2040: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2041: if ($env{'form.withgrades'.$ctr}) {
2042: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
2043: $message.=" for <a href=\"".
1.80 ng 2044: &Apache::lonnet::clutter($url).
1.257 albertel 2045: "?symb=$symb\">$env{'form.probTitle'}</a>";
1.298 www 2046: }
1.44 ng 2047: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
1.298 www 2048: $subject.' ['.
1.295 www 2049: &Apache::lonnet::declutter($url).']',$message);
1.296 www 2050: $request->print('<br />'.&mt('Sending message to [_1]@[_2]',$uname,$udom).': '.
2051: $msgstatus);
1.44 ng 2052: }
1.257 albertel 2053: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2054: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2055: foreach my $collabstr (@collabstrs) {
2056: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2057: foreach my $collaborator (@collaborators) {
1.150 albertel 2058: my ($errorflag,$pts,$wgt) =
1.310 banghart 2059: &saveHandGrade($request,$url,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2060: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2061: if ($errorflag eq 'not_allowed') {
1.310 banghart 2062: $request->print("<font color=\"red\">Not allowed to modify grades for $collaborator:$udom</font>");
1.150 albertel 2063: next;
2064: } else {
2065: if ($message ne '') {
1.310 banghart 2066: $msgstatus = &Apache::lonmsg::user_normal_msg($collaborator,$udom,$env{'form.msgsub'},$message);
1.150 albertel 2067: }
1.104 albertel 2068: }
1.44 ng 2069: }
2070: }
2071: }
2072: $ctr++;
2073: }
2074: }
2075:
1.257 albertel 2076: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2077: # Keywords sorted in alphabatical order
1.257 albertel 2078: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2079: my %keyhash = ();
1.257 albertel 2080: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2081: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2082: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2083: $env{'form.keywords'} = join(' ',@keywords);
2084: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2085: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2086: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2087: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2088: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2089:
2090: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2091: # New messages are saved in env for the next student.
1.119 ng 2092: # All messages are saved in nohist_handgrade.db
2093: my ($ctr,$idx) = (1,1);
1.257 albertel 2094: while ($ctr <= $env{'form.savemsgN'}) {
2095: if ($env{'form.savemsg'.$ctr} ne '') {
2096: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2097: $idx++;
2098: }
2099: $ctr++;
1.41 ng 2100: }
1.119 ng 2101: $ctr = 0;
2102: while ($ctr < $ngrade) {
1.257 albertel 2103: if ($env{'form.newmsg'.$ctr} ne '') {
2104: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2105: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2106: $idx++;
2107: }
2108: $ctr++;
1.41 ng 2109: }
1.257 albertel 2110: $env{'form.savemsgN'} = --$idx;
2111: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2112: my $putresult = &Apache::lonnet::put
1.301 albertel 2113: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2114: }
1.44 ng 2115: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2116: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2117: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2118: my ($ctr,$total) = (0,0);
2119: while ($ctr < $ngrade) {
1.257 albertel 2120: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2121: $ctr++;
2122: }
1.257 albertel 2123: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2124: $ctr = 0;
2125: while ($ctr < $total) {
1.257 albertel 2126: my $processUser = $env{'form.unamedom'.$ctr};
2127: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2128: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2129: &submission($request,$ctr,$total-1);
1.41 ng 2130: $ctr++;
2131: }
2132: return '';
2133: }
1.36 ng 2134:
1.121 ng 2135: # Go directly to grade student - from submission or link from chart page
1.120 ng 2136: if ($button eq 'Grade Student') {
1.257 albertel 2137: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($url);
2138: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2139: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2140: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2141: &submission($request,0,0);
2142: return '';
2143: }
2144:
1.44 ng 2145: # Get the next/previous one or group of students
1.257 albertel 2146: my $firststu = $env{'form.unamedom0'};
2147: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2148: my $ctr = 2;
1.41 ng 2149: while ($laststu eq '') {
1.257 albertel 2150: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2151: $ctr++;
2152: $laststu = $firststu if ($ctr > $ngrade);
2153: }
1.44 ng 2154:
1.41 ng 2155: my (@parsedlist,@nextlist);
2156: my ($nextflg) = 0;
1.294 albertel 2157: foreach (sort
2158: {
2159: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2160: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2161: }
2162: return $a cmp $b;
2163: } (keys(%$fullname))) {
1.41 ng 2164: if ($nextflg == 1 && $button =~ /Next$/) {
2165: push @parsedlist,$_;
2166: }
2167: $nextflg = 1 if ($_ eq $laststu);
2168: if ($button eq 'Previous') {
2169: last if ($_ eq $firststu);
2170: push @parsedlist,$_;
2171: }
2172: }
2173: $ctr = 0;
2174: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.145 albertel 2175: my ($partlist) = &response_type($url);
1.41 ng 2176: foreach my $student (@parsedlist) {
1.257 albertel 2177: my $submitonly=$env{'form.submitonly'};
1.41 ng 2178: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2179:
2180: if ($submitonly eq 'queued') {
2181: my %queue_status =
2182: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2183: $udom,$uname);
2184: next if (!defined($queue_status{'gradingqueue'}));
2185: }
2186:
1.156 albertel 2187: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2188: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.145 albertel 2189: my %status=&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
2190: my $submitted = 0;
1.248 albertel 2191: my $ungraded = 0;
2192: my $incorrect = 0;
1.145 albertel 2193: foreach (keys(%status)) {
2194: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2195: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
2196: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1.145 albertel 2197: my ($foo,$partid,$foo1) = split(/\./,$_);
2198: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2199: $submitted = 0;
2200: }
1.41 ng 2201: }
1.156 albertel 2202: next if (!$submitted && ($submitonly eq 'yes' ||
2203: $submitonly eq 'incorrect' ||
2204: $submitonly eq 'graded'));
1.248 albertel 2205: next if (!$ungraded && ($submitonly eq 'graded'));
2206: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2207: }
2208: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 2209: last if ($ctr == $ntstu);
1.41 ng 2210: $ctr++;
2211: }
1.36 ng 2212:
1.41 ng 2213: $ctr = 0;
2214: my $total = scalar(@nextlist)-1;
1.39 ng 2215:
1.41 ng 2216: foreach (sort @nextlist) {
2217: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2218: $env{'form.student'} = $uname;
2219: $env{'form.userdom'} = $udom;
2220: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2221: &submission($request,$ctr,$total);
2222: $ctr++;
2223: }
2224: if ($total < 0) {
2225: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
2226: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
2227: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1.301 albertel 2228: $the_end.=&show_grading_menu_form($symb,$url);
1.41 ng 2229: $request->print($the_end);
2230: }
2231: return '';
1.38 ng 2232: }
1.36 ng 2233:
1.44 ng 2234: #---- Save the score and award for each student, if changed
1.38 ng 2235: sub saveHandGrade {
1.150 albertel 2236: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.262 banghart 2237: my @v_flag;
1.104 albertel 2238: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2239: $env{'request.course.id'});
1.104 albertel 2240: if (!&canmodify($usec)) { return('not_allowed'); }
1.257 albertel 2241: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2242: my @parts_graded;
1.77 ng 2243: my %newrecord = ();
2244: my ($pts,$wgt) = ('','');
1.269 raeburn 2245: my %aggregate = ();
2246: my $aggregateflag = 0;
1.301 albertel 2247:
2248: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2249: foreach my $new_part (@parts) {
1.150 albertel 2250: #collaborator may vary for different parts
1.259 banghart 2251: if ($submitter && $new_part ne $part) { next; }
2252: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2253: if ($dropMenu eq 'excused') {
1.259 banghart 2254: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2255: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2256: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2257: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2258: }
1.259 banghart 2259: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2260: }
1.125 ng 2261: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2262: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.197 albertel 2263: foreach my $key (keys (%record)) {
1.259 banghart 2264: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2265: }
1.259 banghart 2266: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2267: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2268: my $totaltries = $record{'resource.'.$part.'.tries'};
2269:
2270: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2271: [$new_part]);
2272: my $aggtries =$totaltries;
1.269 raeburn 2273: if ($last_resets{$new_part}) {
1.270 albertel 2274: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2275: $new_part);
1.269 raeburn 2276: }
1.270 albertel 2277:
2278: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2279: if ($aggtries > 0) {
2280: &decrement($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
2281: $aggregateflag = 1;
2282: }
1.125 ng 2283: } elsif ($dropMenu eq '') {
1.259 banghart 2284: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2285: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2286: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2287: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2288: next;
2289: }
1.259 banghart 2290: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2291: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2292: my $partial= $pts/$wgt;
1.259 banghart 2293: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2294: #do not update score for part if not changed.
2295: next;
1.251 banghart 2296: } else {
1.259 banghart 2297: push @parts_graded, $new_part;
1.153 albertel 2298: }
1.259 banghart 2299: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2300: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2301: }
1.259 banghart 2302: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2303: if ($partial == 0) {
1.153 albertel 2304: if ($record{$reckey} ne 'incorrect_by_override') {
2305: $newrecord{$reckey} = 'incorrect_by_override';
2306: }
1.41 ng 2307: } else {
1.153 albertel 2308: if ($record{$reckey} ne 'correct_by_override') {
2309: $newrecord{$reckey} = 'correct_by_override';
2310: }
2311: }
2312: if ($submitter &&
1.259 banghart 2313: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2314: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2315: }
1.259 banghart 2316: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2317: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2318: }
1.310 banghart 2319: if ($env{'form.part'.$new_part.'_returndoc1'}) {
1.311 banghart 2320: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2321:
1.310 banghart 2322: my $portfolio_root = &Apache::loncommon::propath($domain,
2323: $stuname).
2324: '/userfiles/portfolio';
2325: $request->print('<br>'.$portfolio_root.'<br>');
1.311 banghart 2326:
1.310 banghart 2327: # my $result=&Apache::lonnet::userfileupload('uploaddoc','',
2328: # 'portfolio'.$env{'form.currentpath'});
2329:
2330: my $file_counter = 1;
1.312 banghart 2331: my $respid = $env{'form.respid'};
1.311 banghart 2332: while ($env{'form.part'.$new_part.'_returndoc'.$file_counter}) {
1.310 banghart 2333: my $fname=$env{'form.returndoc'.$file_counter.'.filename'};
1.312 banghart 2334: $newrecord{"resource.$new_part.$respid.handback"} = $env{'form.returndocorig'.$file_counter};
1.310 banghart 2335: $request->print("<br />".$fname." will be the uploaded file name");
2336: $request->print("<font color=\"red\">Will upload document</font>".$env{'form.returndocorig'.$file_counter});
2337: $file_counter++;
2338: }
2339: }
2340:
1.259 banghart 2341: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2342: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2343: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2344: $dropMenu eq 'reset status')
2345: {
1.262 banghart 2346: push (@v_flag,$new_part);
1.259 banghart 2347: }
1.41 ng 2348: }
1.301 albertel 2349: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2350: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2351:
1.44 ng 2352: if (scalar(keys(%newrecord)) > 0) {
1.263 banghart 2353: if (scalar(@v_flag)) {
2354: &version_portfiles(\%record, \@parts_graded, $env{'request.course.id'}, $symb, $domain, $stuname, \@v_flag);
1.259 banghart 2355: }
1.44 ng 2356: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2357: $env{'request.course.id'},$domain,$stuname);
1.301 albertel 2358:
2359: my @ungraded_parts;
2360: foreach my $part (@parts) {
2361: if ( !defined($record{'resource.'.$part.'.awarded'})
2362: && !defined($newrecord{'resource.'.$part.'.awarded'}) ) {
2363: push(@ungraded_parts, $part);
2364: }
2365: }
2366: if ( !@ungraded_parts ) {
2367: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2368: $cnum,$domain,$stuname);
2369: }
1.41 ng 2370: }
1.269 raeburn 2371: if ($aggregateflag) {
2372: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2373: $cdom,$cnum);
1.269 raeburn 2374: }
1.301 albertel 2375: return ('',$pts,$wgt);
1.36 ng 2376: }
1.313 banghart 2377: sub get_submitted_files {
2378: my ($udom,$uname,$partid,$respid,$record) = @_;
2379: my @files;
2380: if ($$record{"resource.$partid.$respid.portfiles"}) {
2381: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2382: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2383: push(@files,$file_url.$file);
2384: }
2385: }
2386: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2387: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2388: }
2389: return (\@files);
2390: }
1.269 raeburn 2391: # ----------- Provides number of tries since last reset.
2392: sub get_num_tries {
2393: my ($record,$last_reset,$part) = @_;
2394: my $timestamp = '';
2395: my $num_tries = 0;
2396: if ($$record{'version'}) {
2397: for (my $version=$$record{'version'};$version>=1;$version--) {
2398: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2399: $timestamp = $$record{$version.':timestamp'};
2400: if ($timestamp > $last_reset) {
2401: $num_tries ++;
2402: } else {
2403: last;
2404: }
2405: }
2406: }
2407: }
2408: return $num_tries;
2409: }
2410:
2411: # ----------- Determine decrements required in aggregate totals
2412: sub decrement_aggs {
2413: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2414: my %decrement = (
2415: attempts => 0,
2416: users => 0,
2417: correct => 0
2418: );
2419: $decrement{'attempts'} = $aggtries;
2420: if ($solvedstatus =~ /^correct/) {
2421: $decrement{'correct'} = 1;
2422: }
2423: if ($aggtries == $totaltries) {
2424: $decrement{'users'} = 1;
2425: }
2426: foreach my $type (keys (%decrement)) {
2427: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2428: }
2429: return;
2430: }
2431:
2432: # ----------- Determine timestamps for last reset of aggregate totals for parts
2433: sub get_last_resets {
1.270 albertel 2434: my ($symb,$courseid,$partids) =@_;
2435: my %last_resets;
1.269 raeburn 2436: my $cdom = $env{'course.'.$courseid.'.domain'};
2437: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2438: my @keys;
2439: foreach my $part (@{$partids}) {
2440: push(@keys,"$symb\0$part\0resettime");
2441: }
2442: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2443: $cdom,$cname);
2444: foreach my $part (@{$partids}) {
2445: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2446: }
1.270 albertel 2447: return %last_resets;
1.269 raeburn 2448: }
2449:
1.251 banghart 2450: # ----------- Handles creating versions for portfolio files as answers
2451: sub version_portfiles {
1.306 banghart 2452: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2453: my $version_parts = join('|',@$v_flag);
1.255 banghart 2454: my $parts = join('|', @$parts_graded);
1.252 banghart 2455: my $portfolio_root = &Apache::loncommon::propath($domain,
1.306 banghart 2456: $stu_name).
1.252 banghart 2457: '/userfiles/portfolio';
1.277 albertel 2458: foreach my $key (keys(%$record)) {
1.259 banghart 2459: my $new_portfiles;
1.263 banghart 2460: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.259 banghart 2461: my @v_portfiles;
1.255 banghart 2462: my @portfiles = split(/,/,$$record{$key});
1.252 banghart 2463: foreach my $file (@portfiles) {
1.306 banghart 2464: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2465: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
1.252 banghart 2466: my $version = 0;
1.304 albertel 2467: my ($answer_name,$answer_ver,$answer_ext) =
2468: &file_name_version_ext($answer_file);
1.306 banghart 2469: my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
1.307 banghart 2470: $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2471: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2472: if ($new_answer ne 'problem getting file') {
1.304 albertel 2473: push(@v_portfiles, $directory.$new_answer);
1.306 banghart 2474: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
2475: ['/portfolio'.$directory.$new_answer],
2476: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2477: }
1.306 banghart 2478:
1.252 banghart 2479: }
1.261 albertel 2480: $$record{$key} = join(',',@v_portfiles);
1.251 banghart 2481: }
2482: }
1.259 banghart 2483: return 'ok';
1.305 banghart 2484: }
2485:
1.307 banghart 2486: sub get_next_version {
2487: my ($answer_name, $answer_ext, $dir_list);
2488: my $version;
2489: foreach my $row (@$dir_list) {
2490: my ($file) = split(/\&/,$row,2);
2491: my ($file_name,$file_version,$file_ext) =
2492: &file_name_version_ext($file);
2493: if (($file_name eq $answer_name) &&
2494: ($file_ext eq $answer_ext)) {
2495: # gets here if filename and extension match, regardless of version
2496: if ($file_version ne '') {
2497: # a versioned file is found so save it for later
2498: if ($file_version > $version) {
2499: $version = $file_version;
2500: }
2501: }
2502: }
2503: }
2504: $version ++;
2505: return($version);
2506: }
2507:
1.305 banghart 2508: sub version_selected_portfile {
1.306 banghart 2509: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2510: my ($answer_name,$answer_ver,$answer_ext) =
2511: &file_name_version_ext($file_name);
2512: my $new_answer;
2513: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2514: if($env{'form.copy'} eq '-1') {
2515: &Apache::lonnet::logthis('problem getting file '.$file_name);
2516: $new_answer = 'problem getting file';
2517: } else {
2518: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2519: my $copy_result = &Apache::lonnet::finishuserfileupload(
2520: $stu_name,$domain,'copy',
2521: '/portfolio'.$directory.$new_answer);
2522: }
2523: return ($new_answer);
1.251 banghart 2524: }
2525:
1.304 albertel 2526: sub file_name_version_ext {
2527: my ($file)=@_;
2528: my @file_parts = split(/\./, $file);
2529: my ($name,$version,$ext);
2530: if (@file_parts > 1) {
2531: $ext=pop(@file_parts);
2532: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2533: $version=pop(@file_parts);
2534: }
2535: $name=join('.',@file_parts);
2536: } else {
2537: $name=join('.',@file_parts);
2538: }
2539: return($name,$version,$ext);
2540: }
2541:
1.44 ng 2542: #--------------------------------------------------------------------------------------
2543: #
2544: #-------------------------- Next few routines handles grading by section or whole class
2545: #
2546: #--- Javascript to handle grading by section or whole class
1.42 ng 2547: sub viewgrades_js {
2548: my ($request) = shift;
2549:
1.41 ng 2550: $request->print(<<VIEWJAVASCRIPT);
2551: <script type="text/javascript" language="javascript">
1.45 ng 2552: function writePoint(partid,weight,point) {
1.125 ng 2553: var radioButton = document.classgrade["RADVAL_"+partid];
2554: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2555: if (point == "textval") {
1.125 ng 2556: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2557: if (isNaN(point) || parseFloat(point) < 0) {
2558: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2559: var resetbox = false;
2560: for (var i=0; i<radioButton.length; i++) {
2561: if (radioButton[i].checked) {
2562: textbox.value = i;
2563: resetbox = true;
2564: }
2565: }
2566: if (!resetbox) {
2567: textbox.value = "";
2568: }
2569: return;
2570: }
1.109 matthew 2571: if (parseFloat(point) > parseFloat(weight)) {
2572: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2573: ") greater than the weight for the part. Accept?");
2574: if (resp == false) {
2575: textbox.value = "";
2576: return;
2577: }
2578: }
1.42 ng 2579: for (var i=0; i<radioButton.length; i++) {
2580: radioButton[i].checked=false;
1.109 matthew 2581: if (parseFloat(point) == i) {
1.42 ng 2582: radioButton[i].checked=true;
2583: }
2584: }
1.41 ng 2585:
1.42 ng 2586: } else {
1.125 ng 2587: textbox.value = parseFloat(point);
1.42 ng 2588: }
1.41 ng 2589: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2590: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2591: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2592: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2593: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2594: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2595: if (saveval != "correct") {
2596: scorename.value = point;
1.43 ng 2597: if (selname[0].selected != true) {
2598: selname[0].selected = true;
2599: }
1.42 ng 2600: }
2601: }
1.125 ng 2602: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2603: }
2604:
2605: function writeRadText(partid,weight) {
1.125 ng 2606: var selval = document.classgrade["SELVAL_"+partid];
2607: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 2608: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 2609: var textbox = document.classgrade["TEXTVAL_"+partid];
2610: if (selval[1].selected || selval[2].selected) {
1.42 ng 2611: for (var i=0; i<radioButton.length; i++) {
2612: radioButton[i].checked=false;
2613:
2614: }
2615: textbox.value = "";
2616:
2617: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2618: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2619: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2620: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2621: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2622: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2623: if ((saveval != "correct") || override) {
1.42 ng 2624: scorename.value = "";
1.125 ng 2625: if (selval[1].selected) {
2626: selname[1].selected = true;
2627: } else {
2628: selname[2].selected = true;
2629: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2630: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2631: }
1.42 ng 2632: }
2633: }
1.43 ng 2634: } else {
2635: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2636: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2637: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2638: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2639: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2640: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2641: if ((saveval != "correct") || override) {
1.125 ng 2642: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2643: selname[0].selected = true;
2644: }
2645: }
2646: }
1.42 ng 2647: }
2648:
2649: function changeSelect(partid,user) {
1.125 ng 2650: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2651: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2652: var point = textbox.value;
1.125 ng 2653: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2654:
1.109 matthew 2655: if (isNaN(point) || parseFloat(point) < 0) {
2656: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2657: textbox.value = "";
2658: return;
2659: }
1.109 matthew 2660: if (parseFloat(point) > parseFloat(weight)) {
2661: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2662: ") greater than the weight of the part. Accept?");
2663: if (resp == false) {
2664: textbox.value = "";
2665: return;
2666: }
2667: }
1.42 ng 2668: selval[0].selected = true;
2669: }
2670:
2671: function changeOneScore(partid,user) {
1.125 ng 2672: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2673: if (selval[1].selected || selval[2].selected) {
2674: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2675: if (selval[2].selected) {
2676: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2677: }
1.269 raeburn 2678: }
1.42 ng 2679: }
2680:
2681: function resetEntry(numpart) {
2682: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2683: var partid = document.classgrade["partid_"+ctpart].value;
2684: var radioButton = document.classgrade["RADVAL_"+partid];
2685: var textbox = document.classgrade["TEXTVAL_"+partid];
2686: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2687: for (var i=0; i<radioButton.length; i++) {
2688: radioButton[i].checked=false;
2689:
2690: }
2691: textbox.value = "";
2692: selval[0].selected = true;
2693:
2694: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2695: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2696: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2697: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2698: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2699: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2700: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2701: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2702: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2703: if (saveselval == "excused") {
1.43 ng 2704: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2705: } else {
1.43 ng 2706: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2707: }
2708: }
1.41 ng 2709: }
1.42 ng 2710: }
2711:
1.41 ng 2712: </script>
2713: VIEWJAVASCRIPT
1.42 ng 2714: }
2715:
1.44 ng 2716: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2717: sub viewgrades {
2718: my ($request) = shift;
2719: &viewgrades_js($request);
1.41 ng 2720:
1.257 albertel 2721: my ($symb,$url) = ($env{'form.symb'},$env{'form.url'});
1.168 albertel 2722: #need to make sure we have the correct data for later EXT calls,
2723: #thus invalidate the cache
2724: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 2725: $env{'course.'.$env{'request.course.id'}.'.num'},
2726: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 2727: &Apache::lonnet::clear_EXT_cache_status();
2728:
1.167 sakharuk 2729: my $result='<h3><font color="#339933">'.&mt('Manual Grading').'</font></h3>';
1.257 albertel 2730: $result.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n";
1.41 ng 2731:
2732: #view individual student submission form - called using Javascript viewOneStudent
1.45 ng 2733: $result.=&jscriptNform($url,$symb);
1.41 ng 2734:
1.44 ng 2735: #beginning of class grading form
1.41 ng 2736: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.106 albertel 2737: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.41 ng 2738: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 2739: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.257 albertel 2740: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
2741: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
2742: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
2743: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 2744:
1.126 ng 2745: my $sectionClass;
1.257 albertel 2746: if ($env{'form.section'} eq 'all') {
1.126 ng 2747: $sectionClass='Class </h3>';
1.257 albertel 2748: } elsif ($env{'form.section'} eq 'none') {
1.126 ng 2749: $sectionClass='Students in no Section </h3>';
1.52 albertel 2750: } else {
1.257 albertel 2751: $sectionClass='Students in Section '.$env{'form.section'}.'</h3>';
1.52 albertel 2752: }
1.126 ng 2753: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2754: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2755: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2756: #radio buttons/text box for assigning points for a section or class.
2757: #handles different parts of a problem
1.125 ng 2758: my ($partlist,$handgrade) = &response_type($url,$symb);
1.42 ng 2759: my %weight = ();
2760: my $ctsparts = 0;
1.41 ng 2761: $result.='<table border="0">';
1.45 ng 2762: my %seen = ();
1.42 ng 2763: for (sort keys(%$handgrade)) {
1.54 albertel 2764: my ($partid,$respid) = split (/_/,$_,2);
1.45 ng 2765: next if $seen{$partid};
2766: $seen{$partid}++;
1.147 albertel 2767: my $handgrade=$$handgrade{$_};
1.42 ng 2768: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
2769: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
2770:
1.44 ng 2771: $result.='<input type="hidden" name="partid_'.
2772: $ctsparts.'" value="'.$partid.'" />'."\n";
2773: $result.='<input type="hidden" name="weight_'.
2774: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1.207 albertel 2775: my $display_part=&get_display_part($partid,$url,$symb);
2776: $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>';
1.42 ng 2777: $result.='<table border="0"><tr>';
1.41 ng 2778: my $ctr = 0;
1.42 ng 2779: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.288 albertel 2780: $result.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 2781: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 2782: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 2783: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
2784: $ctr++;
2785: }
2786: $result.='</tr></table>';
1.44 ng 2787: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 2788: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
2789: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 2790: $weight{$partid}.' (problem weight)</td>'."\n";
2791: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 2792: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 2793: $weight{$partid}.')"> '.
1.42 ng 2794: '<option selected="on"> </option>'.
1.125 ng 2795: '<option>excused</option>'.
1.265 www 2796: '<option>reset status</option></select></td>'.
1.266 albertel 2797: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
1.42 ng 2798: $ctsparts++;
1.41 ng 2799: }
1.52 albertel 2800: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
2801: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 2802: $result.='<input type="button" value="Reset" '.
1.111 ng 2803: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41 ng 2804:
1.44 ng 2805: #table listing all the students in a section/class
2806: #header of table
1.126 ng 2807: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 2808: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 2809: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 2810: '<td>'.&nameUserString('header')."</td>\n";
1.146 albertel 2811: my (@parts) = sort(&getpartlist($url,$symb));
1.269 raeburn 2812: my @partids = ();
1.41 ng 2813: foreach my $part (@parts) {
2814: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 2815: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 2816: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 2817: my ($partid) = &split_part_type($part);
1.269 raeburn 2818: push(@partids, $partid);
1.207 albertel 2819: my $display_part=&get_display_part($partid,$url,$symb);
1.41 ng 2820: if ($display =~ /^Partial Credit Factor/) {
1.207 albertel 2821: $result.='<td><b>Score Part:</b> '.$display_part.
2822: ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
1.41 ng 2823: next;
1.207 albertel 2824: } else {
2825: $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
1.41 ng 2826: }
1.53 albertel 2827: $display =~ s|Problem Status|Grade Status<br />|;
1.207 albertel 2828: $result.='<td><b>'.$display.'</td>'."\n";
1.41 ng 2829: }
2830: $result.='</tr>';
1.44 ng 2831:
1.270 albertel 2832: my %last_resets =
2833: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 2834:
1.41 ng 2835: #get info for each student
1.44 ng 2836: #list all the students - with points and grade status
1.257 albertel 2837: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 2838: my $ctr = 0;
1.294 albertel 2839: foreach (sort
2840: {
2841: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2842: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2843: }
2844: return $a cmp $b;
2845: } (keys(%$fullname))) {
1.126 ng 2846: $ctr++;
1.257 albertel 2847: $result.=&viewstudentgrade($url,$symb,$env{'request.course.id'},
1.269 raeburn 2848: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 2849: }
2850: $result.='</table></td></tr></table>';
2851: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 2852: $result.='<input type="button" value="Save" '.
1.45 ng 2853: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96 albertel 2854: if (scalar(%$fullname) eq 0) {
2855: my $colspan=3+scalar(@parts);
1.257 albertel 2856: $result='<font color="red">There are no students in section "'.$env{'form.section'}.
2857: '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.</font>';
1.96 albertel 2858: }
1.41 ng 2859: $result.=&show_grading_menu_form($symb,$url);
2860: return $result;
2861: }
2862:
1.44 ng 2863: #--- call by previous routine to display each student
1.41 ng 2864: sub viewstudentgrade {
1.269 raeburn 2865: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 2866: my ($uname,$udom) = split(/:/,$student);
2867: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 2868: my %aggregates = ();
1.233 albertel 2869: my $result='<tr bgcolor="#ffffdd"><td align="right">'.
2870: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
2871: "\n".$ctr.' </td><td> '.
1.44 ng 2872: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112 ng 2873: '\')"; TARGET=_self>'.$fullname.'</a> '.
1.257 albertel 2874: '<font color="#999999">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
1.281 albertel 2875: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 2876: foreach my $apart (@$parts) {
2877: my ($part,$type) = &split_part_type($apart);
1.41 ng 2878: my $score=$record{"resource.$part.$type"};
1.276 albertel 2879: $result.='<td align="center">';
1.269 raeburn 2880: my ($aggtries,$totaltries);
2881: unless (exists($aggregates{$part})) {
1.270 albertel 2882: $totaltries = $record{'resource.'.$part.'.tries'};
2883:
2884: $aggtries = $totaltries;
1.269 raeburn 2885: if ($$last_resets{$part}) {
1.270 albertel 2886: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
2887: $part);
2888: }
1.269 raeburn 2889: $result.='<input type="hidden" name="'.
2890: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
2891: $result.='<input type="hidden" name="'.
2892: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
2893: $aggregates{$part} = 1;
2894: }
1.41 ng 2895: if ($type eq 'awarded') {
1.42 ng 2896: my $pts = $score eq '' ? '' : $score*$$weight{$part};
2897: $result.='<input type="hidden" name="'.
1.89 albertel 2898: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 2899: $result.='<input type="text" name="'.
1.89 albertel 2900: 'GD_'.$student.'_'.$part.'_awarded" '.
2901: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 2902: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 2903: } elsif ($type eq 'solved') {
2904: my ($status,$foo)=split(/_/,$score,2);
2905: $status = 'nothing' if ($status eq '');
1.89 albertel 2906: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 2907: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 2908: $result.=' <select name="'.
1.89 albertel 2909: 'GD_'.$student.'_'.$part.'_solved" '.
2910: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125 ng 2911: $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>'
2912: : '<option selected="on"> </option><option>excused</option>')."\n";
2913: $result.='<option>reset status</option>';
1.126 ng 2914: $result.="</select> </td>\n";
1.122 ng 2915: } else {
2916: $result.='<input type="hidden" name="'.
2917: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
2918: "\n";
1.233 albertel 2919: $result.='<input type="text" name="'.
1.122 ng 2920: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
2921: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 2922: }
2923: }
2924: $result.='</tr>';
2925: return $result;
1.38 ng 2926: }
2927:
1.44 ng 2928: #--- change scores for all the students in a section/class
2929: # record does not get update if unchanged
1.38 ng 2930: sub editgrades {
1.41 ng 2931: my ($request) = @_;
2932:
1.257 albertel 2933: my $symb=$env{'form.symb'};
2934: my $url =$env{'form.url'};
1.45 ng 2935: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.257 albertel 2936: $title.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font><br />'."\n";
2937: $title.='<font size=+1><b>Section: </b>'.$env{'form.section'}.'</font>'."\n";
1.126 ng 2938:
1.44 ng 2939: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 2940: $result.= '<table border="0"><tr bgcolor="#deffff">'.
2941: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
2942: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 2943:
2944: my %scoreptr = (
2945: 'correct' =>'correct_by_override',
2946: 'incorrect'=>'incorrect_by_override',
2947: 'excused' =>'excused',
2948: 'ungraded' =>'ungraded_attempted',
2949: 'nothing' => '',
2950: );
1.257 albertel 2951: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 2952:
1.44 ng 2953: my (@partid);
2954: my %weight = ();
1.54 albertel 2955: my %columns = ();
1.44 ng 2956: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 2957:
1.146 albertel 2958: my (@parts) = sort(&getpartlist($url,$symb));
1.54 albertel 2959: my $header;
1.257 albertel 2960: while ($ctr < $env{'form.totalparts'}) {
2961: my $partid = $env{'form.partid_'.$ctr};
1.44 ng 2962: push @partid,$partid;
1.257 albertel 2963: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 2964: $ctr++;
1.54 albertel 2965: }
2966: foreach my $partid (@partid) {
2967: $header .= '<td align="center"> <b>Old Score</b> </td>'.
2968: '<td align="center"> <b>New Score</b> </td>';
2969: $columns{$partid}=2;
2970: foreach my $stores (@parts) {
2971: my ($part,$type) = &split_part_type($stores);
2972: if ($part !~ m/^\Q$partid\E/) { next;}
2973: if ($type eq 'awarded' || $type eq 'solved') { next; }
2974: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
2975: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 2976: $display =~ s/Number of Attempts/Tries/;
2977: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
2978: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 2979: $columns{$partid}+=2;
2980: }
2981: }
2982: foreach my $partid (@partid) {
1.207 albertel 2983: my $display_part=&get_display_part($partid,$url,$symb);
1.54 albertel 2984: $result .= '<td colspan="'.$columns{$partid}.
1.207 albertel 2985: '" align="center"><b>Part:</b> '.$display_part.
2986: ' (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 2987:
1.44 ng 2988: }
2989: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 2990: $result .= $header;
1.44 ng 2991: $result .= '</tr>'."\n";
1.93 albertel 2992: my $noupdate;
1.126 ng 2993: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 2994: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 2995: my $line;
1.257 albertel 2996: my $user = $env{'form.ctr'.$i};
1.281 albertel 2997: my ($uname,$udom)=split(/:/,$user);
1.44 ng 2998: my %newrecord;
2999: my $updateflag = 0;
1.281 albertel 3000: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3001: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3002: if (!&canmodify($usec)) {
1.126 ng 3003: my $numcols=scalar(@partid)*4+2;
1.105 albertel 3004: $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
3005: next;
3006: }
1.269 raeburn 3007: my %aggregate = ();
3008: my $aggregateflag = 0;
1.281 albertel 3009: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3010: foreach (@partid) {
1.257 albertel 3011: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3012: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3013: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3014: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3015: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3016: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3017: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3018: my $score;
3019: if ($partial eq '') {
1.257 albertel 3020: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3021: } elsif ($partial > 0) {
3022: $score = 'correct_by_override';
3023: } elsif ($partial == 0) {
3024: $score = 'incorrect_by_override';
3025: }
1.257 albertel 3026: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3027: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3028:
1.292 albertel 3029: $newrecord{'resource.'.$_.'.regrader'}=
3030: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3031: if ($dropMenu eq 'reset status' &&
3032: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3033: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3034: $newrecord{'resource.'.$_.'.solved'} = '';
3035: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3036: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3037: $updateflag = 1;
1.269 raeburn 3038: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3039: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3040: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3041: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3042: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3043: $aggregateflag = 1;
3044: }
1.139 albertel 3045: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3046: $updateflag = 1;
3047: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3048: $newrecord{'resource.'.$_.'.solved'} = $score;
3049: $rec_update++;
1.125 ng 3050: }
3051:
1.93 albertel 3052: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3053: '<td align="center">'.$awarded.
3054: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3055:
1.54 albertel 3056:
3057: my $partid=$_;
3058: foreach my $stores (@parts) {
3059: my ($part,$type) = &split_part_type($stores);
3060: if ($part !~ m/^\Q$partid\E/) { next;}
3061: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3062: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3063: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3064: if ($awarded ne '' && $awarded ne $old_aw) {
3065: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3066: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3067: $updateflag=1;
3068: }
1.93 albertel 3069: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3070: '<td align="center">'.$awarded.' </td>';
3071: }
1.44 ng 3072: }
1.93 albertel 3073: $line.='</tr>'."\n";
1.301 albertel 3074:
3075: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3076: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3077:
1.44 ng 3078: if ($updateflag) {
3079: $count++;
1.257 albertel 3080: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3081: $udom,$uname);
1.301 albertel 3082:
3083: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3084: $cnum,$udom,$uname)) {
3085: # need to figure out if should be in queue.
3086: my %record =
3087: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3088: $udom,$uname);
3089: my $all_graded = 1;
3090: my $none_graded = 1;
3091: foreach my $part (@parts) {
3092: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3093: $all_graded = 0;
3094: } else {
3095: $none_graded = 0;
3096: }
3097: }
3098:
3099: if ($all_graded || $none_graded) {
3100: &Apache::bridgetask::remove_from_queue('gradingqueue',
3101: $symb,$cdom,$cnum,
3102: $udom,$uname);
3103: }
3104: }
3105:
1.126 ng 3106: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
3107: $updateCtr++;
1.93 albertel 3108: } else {
1.126 ng 3109: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
3110: $noupdateCtr++;
1.44 ng 3111: }
1.269 raeburn 3112: if ($aggregateflag) {
3113: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3114: $cdom,$cnum);
1.269 raeburn 3115: }
1.93 albertel 3116: }
3117: if ($noupdate) {
1.126 ng 3118: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3119: my $numcols=scalar(@partid)*4+2;
1.204 albertel 3120: $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 3121: }
1.72 ng 3122: $result .= '</table></td></tr></table>'."\n".
3123: &show_grading_menu_form ($symb,$url);
1.125 ng 3124: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 3125: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1.257 albertel 3126: '<b>Total number of students = '.$env{'form.total'}.'</b><br />';
1.44 ng 3127: return $title.$msg.$result;
1.5 albertel 3128: }
1.54 albertel 3129:
3130: sub split_part_type {
3131: my ($partstr) = @_;
3132: my ($temp,@allparts)=split(/_/,$partstr);
3133: my $type=pop(@allparts);
3134: my $part=join('.',@allparts);
3135: return ($part,$type);
3136: }
3137:
1.44 ng 3138: #------------- end of section for handling grading by section/class ---------
3139: #
3140: #----------------------------------------------------------------------------
3141:
1.5 albertel 3142:
1.44 ng 3143: #----------------------------------------------------------------------------
3144: #
3145: #-------------------------- Next few routines handles grading by csv upload
3146: #
3147: #--- Javascript to handle csv upload
1.27 albertel 3148: sub csvupload_javascript_reverse_associate {
1.246 albertel 3149: my $error1=&mt('You need to specify the username or ID');
3150: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3151: return(<<ENDPICK);
3152: function verify(vf) {
3153: var foundsomething=0;
3154: var founduname=0;
1.243 albertel 3155: var foundID=0;
1.27 albertel 3156: for (i=0;i<=vf.nfields.value;i++) {
3157: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3158: if (i==0 && tw!=0) { foundID=1; }
3159: if (i==1 && tw!=0) { founduname=1; }
3160: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3161: }
1.246 albertel 3162: if (founduname==0 && foundID==0) {
3163: alert('$error1');
3164: return;
1.27 albertel 3165: }
3166: if (foundsomething==0) {
1.246 albertel 3167: alert('$error2');
3168: return;
1.27 albertel 3169: }
3170: vf.submit();
3171: }
3172: function flip(vf,tf) {
3173: var nw=eval('vf.f'+tf+'.selectedIndex');
3174: var i;
3175: for (i=0;i<=vf.nfields.value;i++) {
3176: //can not pick the same destination field for both name and domain
3177: if (((i ==0)||(i ==1)) &&
3178: ((tf==0)||(tf==1)) &&
3179: (i!=tf) &&
3180: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3181: eval('vf.f'+i+'.selectedIndex=0;')
3182: }
3183: }
3184: }
3185: ENDPICK
3186: }
3187:
3188: sub csvupload_javascript_forward_associate {
1.246 albertel 3189: my $error1=&mt('You need to specify the username or ID');
3190: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3191: return(<<ENDPICK);
3192: function verify(vf) {
3193: var foundsomething=0;
3194: var founduname=0;
1.243 albertel 3195: var foundID=0;
1.27 albertel 3196: for (i=0;i<=vf.nfields.value;i++) {
3197: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3198: if (tw==1) { foundID=1; }
3199: if (tw==2) { founduname=1; }
3200: if (tw>3) { foundsomething=1; }
1.27 albertel 3201: }
1.246 albertel 3202: if (founduname==0 && foundID==0) {
3203: alert('$error1');
3204: return;
1.27 albertel 3205: }
3206: if (foundsomething==0) {
1.246 albertel 3207: alert('$error2');
3208: return;
1.27 albertel 3209: }
3210: vf.submit();
3211: }
3212: function flip(vf,tf) {
3213: var nw=eval('vf.f'+tf+'.selectedIndex');
3214: var i;
3215: //can not pick the same destination field twice
3216: for (i=0;i<=vf.nfields.value;i++) {
3217: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3218: eval('vf.f'+i+'.selectedIndex=0;')
3219: }
3220: }
3221: }
3222: ENDPICK
3223: }
3224:
1.26 albertel 3225: sub csvuploadmap_header {
1.41 ng 3226: my ($request,$symb,$url,$datatoken,$distotal)= @_;
3227: my $javascript;
1.257 albertel 3228: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3229: $javascript=&csvupload_javascript_reverse_associate();
3230: } else {
3231: $javascript=&csvupload_javascript_forward_associate();
3232: }
1.45 ng 3233:
1.257 albertel 3234: my ($result) = &showResourceInfo($url,$env{'form.probTitle'});
3235: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3236: my $ignore=&mt('Ignore First Line');
1.41 ng 3237: $request->print(<<ENDPICK);
1.26 albertel 3238: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 3239: <h3><font color="#339933">Uploading Class Grades</font></h3>
3240: $result
1.26 albertel 3241: <hr>
3242: <h3>Identify fields</h3>
3243: Total number of records found in file: $distotal <hr />
3244: Enter as many fields as you can. The system will inform you and bring you back
3245: to this page if the data selected is insufficient to run your class.<hr />
3246: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3247: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3248: <input type="hidden" name="associate" value="" />
3249: <input type="hidden" name="phase" value="three" />
3250: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3251: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3252: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3253: <input type="hidden" name="upfile_associate"
1.257 albertel 3254: value="$env{'form.upfile_associate'}" />
1.26 albertel 3255: <input type="hidden" name="symb" value="$symb" />
3256: <input type="hidden" name="url" value="$url" />
1.257 albertel 3257: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3258: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3259: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3260: <hr />
3261: <script type="text/javascript" language="Javascript">
3262: $javascript
3263: </script>
3264: ENDPICK
1.118 ng 3265: return '';
1.26 albertel 3266:
3267: }
3268:
3269: sub csvupload_fields {
1.146 albertel 3270: my ($url,$symb) = @_;
3271: my (@parts) = &getpartlist($url,$symb);
1.243 albertel 3272: my @fields=(['ID','Student ID'],
3273: ['username','Student Username'],
3274: ['domain','Student Domain']);
1.41 ng 3275: foreach my $part (sort(@parts)) {
3276: my @datum;
3277: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3278: my $name=$part;
3279: if (!$display) { $display = $name; }
3280: @datum=($name,$display);
1.244 albertel 3281: if ($name=~/^stores_(.*)_awarded/) {
3282: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3283: }
1.41 ng 3284: push(@fields,\@datum);
3285: }
3286: return (@fields);
1.26 albertel 3287: }
3288:
3289: sub csvuploadmap_footer {
1.41 ng 3290: my ($request,$i,$keyfields) =@_;
3291: $request->print(<<ENDPICK);
1.26 albertel 3292: </table>
3293: <input type="hidden" name="nfields" value="$i" />
3294: <input type="hidden" name="keyfields" value="$keyfields" />
3295: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3296: </form>
3297: ENDPICK
3298: }
3299:
1.283 albertel 3300: sub checkforfile_js {
1.86 ng 3301: my $result =<<CSVFORMJS;
3302: <script type="text/javascript" language="javascript">
3303: function checkUpload(formname) {
3304: if (formname.upfile.value == "") {
3305: alert("Please use the browse button to select a file from your local directory.");
3306: return false;
3307: }
3308: formname.submit();
3309: }
3310: </script>
3311: CSVFORMJS
1.283 albertel 3312: return $result;
3313: }
3314:
3315: sub upcsvScores_form {
3316: my ($request) = shift;
3317: my ($symb,$url)=&get_symb_and_url($request);
3318: if (!$symb) {return '';}
3319: my $result=&checkforfile_js();
1.257 albertel 3320: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
3321: my ($table) = &showResourceInfo($url,$env{'form.probTitle'});
1.118 ng 3322: $result.=$table;
1.86 ng 3323: $result.='<br /><table width=100% border=0><tr><td bgcolor="#777777">'."\n";
3324: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.118 ng 3325: $result.=' <b>Specify a file containing the class scores for current resource'.
1.86 ng 3326: '.</b></td></tr>'."\n";
3327: $result.='<tr bgcolor=#ffffe6><td>'."\n";
3328: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3329: my $ignore=&mt('Ignore First Line');
1.86 ng 3330: $result.=<<ENDUPFORM;
1.106 albertel 3331: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3332: <input type="hidden" name="symb" value="$symb" />
3333: <input type="hidden" name="url" value="$url" />
3334: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3335: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3336: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3337: $upfile_select
3338: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />
1.283 albertel 3339: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3340: </form>
3341: ENDUPFORM
3342: $result.='</td></tr></table>'."\n";
3343: $result.='</td></tr></table><br /><br />'."\n";
3344: $result.=&show_grading_menu_form($symb,$url);
3345: return $result;
3346: }
3347:
3348:
1.26 albertel 3349: sub csvuploadmap {
1.41 ng 3350: my ($request)= @_;
3351: my ($symb,$url)=&get_symb_and_url($request);
3352: if (!$symb) {return '';}
1.72 ng 3353:
1.41 ng 3354: my $datatoken;
1.257 albertel 3355: if (!$env{'form.datatoken'}) {
1.41 ng 3356: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3357: } else {
1.257 albertel 3358: $datatoken=$env{'form.datatoken'};
1.41 ng 3359: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3360: }
1.41 ng 3361: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3362: if ($env{'form.noFirstLine'}) { shift(@records); }
1.41 ng 3363: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
3364: my ($i,$keyfields);
3365: if (@records) {
1.146 albertel 3366: my @fields=&csvupload_fields($url,$symb);
1.45 ng 3367:
1.257 albertel 3368: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3369: &Apache::loncommon::csv_print_samples($request,\@records);
3370: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3371: \@fields);
3372: foreach (@fields) { $keyfields.=$_->[0].','; }
3373: chop($keyfields);
3374: } else {
3375: unshift(@fields,['none','']);
3376: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3377: \@fields);
1.311 banghart 3378: foreach my $rec (@records) {
3379: my %temp = &Apache::loncommon::record_sep($rec);
3380: if (%temp) {
3381: $keyfields=join(',',sort(keys(%temp)));
3382: last;
3383: }
3384: }
1.41 ng 3385: }
3386: }
3387: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 3388: $request->print(&show_grading_menu_form($symb,$url));
3389:
1.41 ng 3390: return '';
1.27 albertel 3391: }
3392:
1.246 albertel 3393: sub csvuploadoptions {
1.41 ng 3394: my ($request)= @_;
3395: my ($symb,$url)=&get_symb_and_url($request);
1.257 albertel 3396: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3397: my $ignore=&mt('Ignore First Line');
3398: $request->print(<<ENDPICK);
3399: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
3400: <h3><font color="#339933">Uploading Class Grade Options</font></h3>
3401: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3402: <!--
1.246 albertel 3403: <p>
3404: <label>
3405: <input type="checkbox" name="show_full_results" />
3406: Show a table of all changes
3407: </label>
3408: </p>
1.302 albertel 3409: -->
1.246 albertel 3410: <p>
3411: <label>
3412: <input type="checkbox" name="overwite_scores" checked="checked" />
3413: Overwrite any existing score
3414: </label>
3415: </p>
3416: ENDPICK
3417: my %fields=&get_fields();
3418: if (!defined($fields{'domain'})) {
1.257 albertel 3419: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3420: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3421: }
1.257 albertel 3422: foreach my $key (sort(keys(%env))) {
1.246 albertel 3423: if ($key !~ /^form\.(.*)$/) { next; }
3424: my $cleankey=$1;
3425: if ($cleankey eq 'command') { next; }
3426: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3427: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3428: }
3429: # FIXME do a check for any duplicated user ids...
3430: # FIXME do a check for any invalid user ids?...
1.290 albertel 3431: $request->print('<input type="submit" value="Assign Grades" /><br />
3432: <hr /></form>'."\n");
1.246 albertel 3433: $request->print(&show_grading_menu_form($symb,$url));
3434: return '';
3435: }
3436:
3437: sub get_fields {
3438: my %fields;
1.257 albertel 3439: my @keyfields = split(/\,/,$env{'form.keyfields'});
3440: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3441: if ($env{'form.upfile_associate'} eq 'reverse') {
3442: if ($env{'form.f'.$i} ne 'none') {
3443: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3444: }
3445: } else {
1.257 albertel 3446: if ($env{'form.f'.$i} ne 'none') {
3447: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3448: }
3449: }
1.27 albertel 3450: }
1.246 albertel 3451: return %fields;
3452: }
3453:
3454: sub csvuploadassign {
3455: my ($request)= @_;
3456: my ($symb,$url)=&get_symb_and_url($request);
3457: if (!$symb) {return '';}
3458: &Apache::loncommon::load_tmp_file($request);
3459: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3460: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3461: my %fields=&get_fields();
1.41 ng 3462: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3463: my $courseid=$env{'request.course.id'};
1.97 albertel 3464: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3465: my @notallowed;
1.41 ng 3466: my @skipped;
3467: my $countdone=0;
3468: foreach my $grade (@gradedata) {
3469: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3470: my $domain;
3471: if ($entries{$fields{'domain'}}) {
3472: $domain=$entries{$fields{'domain'}};
3473: } else {
1.257 albertel 3474: $domain=$env{'form.default_domain'};
1.246 albertel 3475: }
1.243 albertel 3476: $domain=~s/\s//g;
1.41 ng 3477: my $username=$entries{$fields{'username'}};
1.160 albertel 3478: $username=~s/\s//g;
1.243 albertel 3479: if (!$username) {
3480: my $id=$entries{$fields{'ID'}};
1.247 albertel 3481: $id=~s/\s//g;
1.243 albertel 3482: my %ids=&Apache::lonnet::idget($domain,$id);
3483: $username=$ids{$id};
3484: }
1.41 ng 3485: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3486: my $id=$entries{$fields{'ID'}};
3487: $id=~s/\s//g;
3488: if ($id) {
3489: push(@skipped,"$id:$domain");
3490: } else {
3491: push(@skipped,"$username:$domain");
3492: }
1.41 ng 3493: next;
3494: }
1.108 albertel 3495: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3496: if (!&canmodify($usec)) {
3497: push(@notallowed,"$username:$domain");
3498: next;
3499: }
1.244 albertel 3500: my %points;
1.41 ng 3501: my %grades;
3502: foreach my $dest (keys(%fields)) {
1.244 albertel 3503: if ($dest eq 'ID' || $dest eq 'username' ||
3504: $dest eq 'domain') { next; }
3505: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3506: if ($dest=~/stores_(.*)_points/) {
3507: my $part=$1;
3508: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3509: $symb,$domain,$username);
1.247 albertel 3510: $entries{$fields{$dest}}=~s/\s//g;
1.244 albertel 3511: my $pcr=$entries{$fields{$dest}} / $wgt;
3512: my $award='correct_by_override';
3513: $grades{"resource.$part.awarded"}=$pcr;
3514: $grades{"resource.$part.solved"}=$award;
3515: $points{$part}=1;
3516: } else {
3517: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
3518: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
3519: my $store_key=$dest;
3520: $store_key=~s/^stores/resource/;
3521: $store_key=~s/_/\./g;
3522: $grades{$store_key}=$entries{$fields{$dest}};
3523: }
1.41 ng 3524: }
1.244 albertel 3525: if (! %grades) { push(@skipped,"$username:$domain no data to store"); }
1.257 albertel 3526: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
1.244 albertel 3527: # &Apache::lonnet::logthis(" storing ".(join('-',%grades)));
1.302 albertel 3528: my $result=&Apache::lonnet::cstore(\%grades,$symb,
3529: $env{'request.course.id'},
3530: $domain,$username);
3531: if ($result eq 'ok') {
3532: $request->print('.');
3533: } else {
3534: $request->print("<p>
3535: <font color='red'>
3536: Failed to store student $username\@$domain.
3537: Message when trying to store was ($result)
3538: </font>
3539: </p>" );
3540: }
1.41 ng 3541: $request->rflush();
3542: $countdone++;
3543: }
3544: $request->print("<br />Stored $countdone students\n");
3545: if (@skipped) {
1.106 albertel 3546: $request->print('<p<font size="+1"><b>Skipped Students</b></font></p>');
3547: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
3548: }
3549: if (@notallowed) {
3550: $request->print('<p><font size="+1" color="red"><b>Students Not Allowed to Modify</b></font></p>');
3551: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 3552: }
1.106 albertel 3553: $request->print("<br />\n");
1.41 ng 3554: $request->print(&show_grading_menu_form($symb,$url));
3555: return '';
1.26 albertel 3556: }
1.44 ng 3557: #------------- end of section for handling csv file upload ---------
3558: #
3559: #-------------------------------------------------------------------
3560: #
1.122 ng 3561: #-------------- Next few routines handle grading by page/sequence
1.72 ng 3562: #
3563: #--- Select a page/sequence and a student to grade
1.68 ng 3564: sub pickStudentPage {
3565: my ($request) = shift;
3566:
3567: $request->print(<<LISTJAVASCRIPT);
3568: <script type="text/javascript" language="javascript">
3569:
3570: function checkPickOne(formname) {
1.76 ng 3571: if (radioSelection(formname.student) == null) {
1.68 ng 3572: alert("Please select the student you wish to grade.");
3573: return;
3574: }
1.125 ng 3575: ptr = pullDownSelection(formname.selectpage);
3576: formname.page.value = formname["page"+ptr].value;
3577: formname.title.value = formname["title"+ptr].value;
1.68 ng 3578: formname.submit();
3579: }
3580:
3581: </script>
3582: LISTJAVASCRIPT
1.118 ng 3583: &commonJSfunctions($request);
1.72 ng 3584: my ($symb,$url) = &get_symb_and_url($request);
1.257 albertel 3585: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3586: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3587: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 3588:
3589: my $result='<h3><font color="#339933"> '.
3590: 'Manual Grading by Page or Sequence</font></h3>';
3591:
1.80 ng 3592: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 3593: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 3594: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 3595: my ($curpage) =&Apache::lonnet::decode_symb($symb);
3596: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
3597: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 3598: my $ctr=0;
1.68 ng 3599: foreach (@$titles) {
3600: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 3601: $result.='<option value="'.$ctr.'" '.
1.71 ng 3602: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
3603: '>'.$showtitle.'</option>'."\n";
1.70 ng 3604: $ctr++;
1.68 ng 3605: }
3606: $result.= '</select>'."<br>\n";
1.70 ng 3607: $ctr=0;
3608: foreach (@$titles) {
3609: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3610: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
3611: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
3612: $ctr++;
3613: }
1.72 ng 3614: $result.='<input type="hidden" name="page" />'."\n".
3615: '<input type="hidden" name="title" />'."\n";
1.68 ng 3616:
1.288 albertel 3617: $result.=' <b>View Problems Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
3618: '<label><input type="radio" name="vProb" value="yes" /> yes </label>'."<br />\n";
1.72 ng 3619:
1.71 ng 3620: $result.=' <b>Submission Details: </b>'.
1.288 albertel 3621: '<label><input type="radio" name="lastSub" value="none" /> none</label>'."\n".
3622: '<label><input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions</label>'."\n".
3623: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n";
1.72 ng 3624:
1.68 ng 3625: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.257 albertel 3626: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.72 ng 3627: '<input type="hidden" name="command" value="displayPage" />'."\n".
3628: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.80 ng 3629: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 3630: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 3631:
1.80 ng 3632: $result.=' <input type="button" '.
1.126 ng 3633: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 3634:
1.68 ng 3635: $request->print($result);
3636:
1.126 ng 3637: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br>'.
1.68 ng 3638: '<table border="0"><tr><td bgcolor="#777777">'.
3639: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 3640: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3641: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 3642: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3643: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 3644:
1.76 ng 3645: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 3646: my $ptr = 1;
1.294 albertel 3647: foreach my $student (sort
3648: {
3649: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3650: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3651: }
3652: return $a cmp $b;
3653: } (keys(%$fullname))) {
1.68 ng 3654: my ($uname,$udom) = split(/:/,$student);
1.126 ng 3655: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
3656: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 3657: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
3658: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.126 ng 3659: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 3660: $ptr++;
3661: }
1.126 ng 3662: $studentTable.='</td><td> </td><td> ' if ($ptr%2 == 0);
1.68 ng 3663: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.126 ng 3664: $studentTable.='<input type="button" '.
3665: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 3666:
3667: $studentTable.=&show_grading_menu_form($symb,$url);
3668: $request->print($studentTable);
3669:
3670: return '';
3671: }
3672:
3673: sub getSymbMap {
1.74 albertel 3674: my ($request) = @_;
1.132 bowersj2 3675: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 3676:
3677: my %symbx = ();
3678: my @titles = ();
1.117 bowersj2 3679: my $minder = 0;
3680:
3681: # Gather every sequence that has problems.
1.240 albertel 3682: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
3683: 1,0,1);
1.117 bowersj2 3684: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 3685: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.117 bowersj2 3686: my $title = $minder.'.'.$sequence->compTitle();
3687: push @titles, $title; # minder in case two titles are identical
3688: $symbx{$title} = $sequence->symb();
3689: $minder++;
1.241 albertel 3690: }
1.68 ng 3691: }
3692: return \@titles,\%symbx;
3693: }
3694:
1.72 ng 3695: #
3696: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 3697: sub displayPage {
3698: my ($request) = shift;
3699:
1.72 ng 3700: my ($symb,$url) = &get_symb_and_url($request);
1.257 albertel 3701: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3702: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3703: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3704: my $pageTitle = $env{'form.page'};
1.103 albertel 3705: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3706: my ($uname,$udom) = split(/:/,$env{'form.student'});
3707: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 3708:
3709: #need to make sure we have the correct data for later EXT calls,
3710: #thus invalidate the cache
3711: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3712: $env{'course.'.$env{'request.course.id'}.'.num'},
3713: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3714: &Apache::lonnet::clear_EXT_cache_status();
3715:
1.103 albertel 3716: if (!&canview($usec)) {
1.257 albertel 3717: $request->print('<font color="red">Unable to view requested student.('.$env{'form.student'}.')</font>');
1.103 albertel 3718: $request->print(&show_grading_menu_form($symb,$url));
3719: return;
3720: }
1.257 albertel 3721: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
3722: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom).
1.129 ng 3723: '</h3>'."\n";
1.71 ng 3724: &sub_page_js($request);
3725: $request->print($result);
3726:
1.132 bowersj2 3727: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3728: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 3729: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3730: if (!$map) {
3731: $request->print('<font color="red">Unable to view requested sequence. ('.$resUrl.')</font>');
3732: $request->print(&show_grading_menu_form($symb,$url));
3733: return;
3734: }
1.68 ng 3735: my $iterator = $navmap->getIterator($map->map_start(),
3736: $map->map_finish());
3737:
1.71 ng 3738: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3739: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 3740: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
3741: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 3742: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 3743: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.72 ng 3744: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3745: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.125 ng 3746: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 3747: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 3748:
3749: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
3750: '/check.gif" height="16" border="0" />';
3751:
1.118 ng 3752: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
3753: ' symbol.'."\n".
1.71 ng 3754: '<table border="0"><tr><td bgcolor="#777777">'.
3755: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 3756: '<td align="center"><b> Prob. </b></td>'.
1.257 albertel 3757: '<td><b> '.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 3758:
1.196 albertel 3759: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 3760: $iterator->next(); # skip the first BEGIN_MAP
3761: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 3762: while ($depth > 0) {
1.68 ng 3763: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3764: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 3765:
1.235 albertel 3766: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 3767: my $parts = $curRes->parts();
1.68 ng 3768: my $title = $curRes->compTitle();
1.71 ng 3769: my $symbx = $curRes->symb();
1.196 albertel 3770: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.71 ng 3771: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
3772: $studentTable.='<td valign="top">';
1.257 albertel 3773: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 3774: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
3775: undef,'both');
1.71 ng 3776: } else {
1.257 albertel 3777: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'});
1.80 ng 3778: $companswer =~ s|<form(.*?)>||g;
3779: $companswer =~ s|</form>||g;
1.71 ng 3780: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 3781: # $companswer =~ s/$1/ /ms;
3782: # $request->print('match='.$1."<br>\n");
1.71 ng 3783: # }
1.116 ng 3784: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.71 ng 3785: $studentTable.=' <b>'.$title.'</b> <br> <b>Correct answer:</b><br>'.$companswer;
3786: }
3787:
1.257 albertel 3788: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 3789:
1.257 albertel 3790: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 3791: if ($record{'version'} eq '') {
3792: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
3793: } else {
1.116 ng 3794: my %responseType = ();
3795: foreach my $partid (@{$parts}) {
1.147 albertel 3796: my @responseIds =$curRes->responseIds($partid);
3797: my @responseType =$curRes->responseType($partid);
3798: my %responseIds;
3799: for (my $i=0;$i<=$#responseIds;$i++) {
3800: $responseIds{$responseIds[$i]}=$responseType[$i];
3801: }
3802: $responseType{$partid} = \%responseIds;
1.116 ng 3803: }
1.148 albertel 3804: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 3805:
1.71 ng 3806: }
1.257 albertel 3807: } elsif ($env{'form.lastSub'} eq 'all') {
3808: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 3809: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 3810: $env{'request.course.id'},
1.71 ng 3811: '','.submission');
3812:
3813: }
1.103 albertel 3814: if (&canmodify($usec)) {
3815: foreach my $partid (@{$parts}) {
3816: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
3817: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
3818: $question++;
3819: }
1.196 albertel 3820: $prob++;
1.71 ng 3821: }
3822: $studentTable.='</td></tr>';
1.68 ng 3823:
1.103 albertel 3824: }
1.68 ng 3825: $curRes = $iterator->next();
3826: }
3827:
1.71 ng 3828: $studentTable.='</td></tr></table></td></tr></table>'."\n".
1.125 ng 3829: '<input type="button" value="Save" '.
1.71 ng 3830: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
3831: '</form>'."\n";
3832: $studentTable.=&show_grading_menu_form($symb,$url);
3833: $request->print($studentTable);
3834:
3835: return '';
1.119 ng 3836: }
3837:
3838: sub displaySubByDates {
1.148 albertel 3839: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 3840: my $isCODE=0;
3841: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.119 ng 3842: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
3843: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
3844: '<td><b>Date/Time</b></td>'.
1.224 albertel 3845: ($isCODE?'<td><b>CODE</b></td>':'').
1.119 ng 3846: '<td><b>Submission</b></td>'.
3847: '<td><b>Status </b></td></tr>';
3848: my ($version);
3849: my %mark;
1.148 albertel 3850: my %orders;
1.119 ng 3851: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 3852: if (!exists($$record{'1:timestamp'})) {
3853: return '<br /> <font color="red">Nothing submitted - no attempts</font><br />';
3854: }
1.119 ng 3855: for ($version=1;$version<=$$record{'version'};$version++) {
3856: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
3857: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
1.224 albertel 3858: if ($isCODE) {
3859: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
3860: }
1.119 ng 3861: my @versionKeys = split(/\:/,$$record{$version.':keys'});
3862: my @displaySub = ();
3863: foreach my $partid (@{$parts}) {
1.147 albertel 3864: my @matchKey = sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys);
1.122 ng 3865: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.207 albertel 3866: my $display_part=&get_display_part($partid,undef,$symb);
1.147 albertel 3867: foreach my $matchKey (@matchKey) {
1.198 albertel 3868: if (exists($$record{$version.':'.$matchKey}) &&
3869: $$record{$version.':'.$matchKey} ne '') {
1.147 albertel 3870: my ($responseId)=($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/);
1.207 albertel 3871: $displaySub[0].='<b>Part:</b> '.$display_part.' ';
1.147 albertel 3872: $displaySub[0].='<font color="#999999">(ID '.
1.207 albertel 3873: $responseId.')</font> <b>';
1.147 albertel 3874: if ($$record{"$version:resource.$partid.tries"} eq '') {
3875: $displaySub[0].='Trial not counted';
3876: } else {
3877: $displaySub[0].='Trial '.
3878: $$record{"$version:resource.$partid.tries"};
3879: }
3880: my $responseType=$responseType->{$partid}->{$responseId};
1.148 albertel 3881: if (!exists($orders{$partid})) { $orders{$partid}={}; }
3882: if (!exists($orders{$partid}->{$responseId})) {
3883: $orders{$partid}->{$responseId}=
3884: &get_order($partid,$responseId,$symb,$uname,$udom);
3885: }
1.147 albertel 3886: $displaySub[0].='</b> '.
1.148 albertel 3887: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:").'<br />';
1.147 albertel 3888: }
3889: }
3890: if (exists $$record{"$version:resource.$partid.award"}) {
1.207 albertel 3891: $displaySub[1].='<b>Part:</b> '.$display_part.' '.
1.147 albertel 3892: lc($$record{"$version:resource.$partid.award"}).' '.
3893: $mark{$$record{"$version:resource.$partid.solved"}}.
3894: '<br />';
3895: }
3896: if (exists $$record{"$version:resource.$partid.regrader"}) {
3897: $displaySub[2].=$$record{"$version:resource.$partid.regrader"}.
1.207 albertel 3898: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 3899: }
3900: }
3901: # needed because old essay regrader has not parts info
3902: if (exists $$record{"$version:resource.regrader"}) {
3903: $displaySub[2].=$$record{"$version:resource.regrader"};
3904: }
3905: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
3906: if ($displaySub[2]) {
3907: $studentTable.='Manually graded by '.$displaySub[2];
3908: }
3909: $studentTable.=' </td></tr>';
3910:
1.119 ng 3911: }
3912: $studentTable.='</table></td></tr></table>';
3913: return $studentTable;
1.71 ng 3914: }
3915:
3916: sub updateGradeByPage {
3917: my ($request) = shift;
3918:
1.257 albertel 3919: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3920: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3921: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3922: my $pageTitle = $env{'form.page'};
1.103 albertel 3923: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3924: my ($uname,$udom) = split(/:/,$env{'form.student'});
3925: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 3926: if (!&canmodify($usec)) {
1.257 albertel 3927: $request->print('<font color="red">Unable to modify requested student.('.$env{'form.student'}.'</font>');
3928: $request->print(&show_grading_menu_form($env{'form.symb'},$env{'form.url'}));
1.103 albertel 3929: return;
3930: }
1.257 albertel 3931: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
3932: $result.='<h3> Student: '.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 3933: '</h3>'."\n";
1.70 ng 3934:
1.68 ng 3935: $request->print($result);
3936:
1.132 bowersj2 3937: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3938: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 3939: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3940: if (!$map) {
3941: $request->print('<font color="red">Unable to grade requested sequence. ('.$resUrl.')</font>');
3942: my ($symb,$url)=&get_symb_and_url($request);
3943: $request->print(&show_grading_menu_form($symb,$url));
3944: return;
3945: }
1.71 ng 3946: my $iterator = $navmap->getIterator($map->map_start(),
3947: $map->map_finish());
1.70 ng 3948:
1.71 ng 3949: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 3950: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 3951: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 3952: '<td><b> Title </b></td>'.
3953: '<td><b> Previous Score </b></td>'.
3954: '<td><b> New Score </b></td></tr>';
3955:
3956: $iterator->next(); # skip the first BEGIN_MAP
3957: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 3958: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 3959: while ($depth > 0) {
1.71 ng 3960: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3961: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 3962:
3963: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 3964: my $parts = $curRes->parts();
1.71 ng 3965: my $title = $curRes->compTitle();
3966: my $symbx = $curRes->symb();
1.196 albertel 3967: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.71 ng 3968: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
3969: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
3970:
3971: my %newrecord=();
3972: my @displayPts=();
1.269 raeburn 3973: my %aggregate = ();
3974: my $aggregateflag = 0;
1.71 ng 3975: foreach my $partid (@{$parts}) {
1.257 albertel 3976: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
3977: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 3978:
1.257 albertel 3979: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
3980: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 3981: my $partial = $newpts/$wgt;
3982: my $score;
3983: if ($partial > 0) {
3984: $score = 'correct_by_override';
1.125 ng 3985: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 3986: $score = 'incorrect_by_override';
3987: }
1.257 albertel 3988: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 3989: if ($dropMenu eq 'excused') {
1.71 ng 3990: $partial = '';
3991: $score = 'excused';
1.125 ng 3992: } elsif ($dropMenu eq 'reset status'
1.257 albertel 3993: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 3994: $newrecord{'resource.'.$partid.'.tries'} = 0;
3995: $newrecord{'resource.'.$partid.'.solved'} = '';
3996: $newrecord{'resource.'.$partid.'.award'} = '';
3997: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 3998: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3999: $changeflag++;
4000: $newpts = '';
1.269 raeburn 4001:
4002: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4003: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4004: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4005: if ($aggtries > 0) {
4006: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4007: $aggregateflag = 1;
4008: }
1.71 ng 4009: }
1.207 albertel 4010: my $display_part=&get_display_part($partid,undef,
4011: $curRes->symb());
1.257 albertel 4012: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.207 albertel 4013: $displayPts[0].=' <b>Part:</b> '.$display_part.' = '.
1.71 ng 4014: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
4015: ' <br>';
1.207 albertel 4016: $displayPts[1].=' <b>Part:</b> '.$display_part.' = '.
1.125 ng 4017: (($score eq 'excused') ? 'excused' : $newpts).
1.71 ng 4018: ' <br>';
4019:
4020: $question++;
1.125 ng 4021: next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused'));
4022:
1.71 ng 4023: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4024: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4025: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4026: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4027:
4028: $changeflag++;
4029: }
4030: if (scalar(keys(%newrecord)) > 0) {
1.257 albertel 4031: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4032: $udom,$uname);
4033: }
1.269 raeburn 4034: if ($aggregateflag) {
4035: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4036: $env{'course.'.$env{'request.course.id'}.'.domain'},
4037: $env{'course.'.$env{'request.course.id'}.'.num'});
4038: }
1.125 ng 4039:
1.71 ng 4040: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4041: '<td valign="top">'.$displayPts[1].'</td>'.
4042: '</tr>';
1.68 ng 4043:
1.196 albertel 4044: $prob++;
1.68 ng 4045: }
1.71 ng 4046: $curRes = $iterator->next();
1.68 ng 4047: }
1.98 albertel 4048:
1.71 ng 4049: $studentTable.='</td></tr></table></td></tr></table>';
1.257 albertel 4050: $studentTable.=&show_grading_menu_form($env{'form.symb'},$env{'form.url'});
1.76 ng 4051: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
4052: 'The scores were changed for '.
4053: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
4054: $request->print($grademsg.$studentTable);
1.68 ng 4055:
1.70 ng 4056: return '';
4057: }
4058:
1.72 ng 4059: #-------- end of section for handling grading by page/sequence ---------
4060: #
4061: #-------------------------------------------------------------------
4062:
1.75 albertel 4063: #--------------------Scantron Grading-----------------------------------
4064: #
4065: #------ start of section for handling grading by page/sequence ---------
4066:
1.81 albertel 4067: sub defaultFormData {
4068: my ($symb,$url)=@_;
4069: return '
4070: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
4071: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.257 albertel 4072: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4073: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4074: }
4075:
1.75 albertel 4076: sub getSequenceDropDown {
4077: my ($request,$symb)=@_;
4078: my $result='<select name="selectpage">'."\n";
4079: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 4080: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4081: my $ctr=0;
4082: foreach (@$titles) {
4083: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4084: $result.='<option value="'.$$symbx{$_}.'" '.
4085: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
4086: '>'.$showtitle.'</option>'."\n";
4087: $ctr++;
4088: }
4089: $result.= '</select>';
4090: return $result;
4091: }
4092:
1.202 albertel 4093: sub scantron_filenames {
1.257 albertel 4094: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4095: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 4096: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.162 albertel 4097: &Apache::loncommon::propath($cdom,$cname));
1.202 albertel 4098: my @possiblenames;
1.201 albertel 4099: foreach my $filename (sort(@files)) {
1.157 albertel 4100: ($filename)=split(/&/,$filename);
4101: if ($filename!~/^scantron_orig_/) { next ; }
4102: $filename=~s/^scantron_orig_//;
1.202 albertel 4103: push(@possiblenames,$filename);
4104: }
4105: return @possiblenames;
4106: }
4107:
4108: sub scantron_uploads {
1.209 ng 4109: my ($file2grade) = @_;
1.202 albertel 4110: my $result= '<select name="scantron_selectfile">';
4111: $result.="<option></option>";
4112: foreach my $filename (sort(&scantron_filenames())) {
1.209 ng 4113: $result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n";
1.81 albertel 4114: }
4115: $result.="</select>";
4116: return $result;
4117: }
4118:
1.82 albertel 4119: sub scantron_scantab {
4120: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4121: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4122: $result.='<option></option>'."\n";
1.82 albertel 4123: foreach my $line (<$fh>) {
4124: my ($name,$descrip)=split(/:/,$line);
4125: if ($name =~ /^\#/) { next; }
4126: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4127: }
4128: $result.='</select>'."\n";
4129:
4130: return $result;
4131: }
4132:
1.186 albertel 4133: sub scantron_CODElist {
1.257 albertel 4134: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4135: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4136: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4137: my $namechoice='<option></option>';
1.225 albertel 4138: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4139: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4140: if ($name =~ /^type\0/) { next; }
1.186 albertel 4141: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4142: }
4143: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4144: return $namechoice;
4145: }
4146:
4147: sub scantron_CODEunique {
4148: my $result='<nobr>
1.272 albertel 4149: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4150: value="yes" checked="checked" /> Yes </label>
1.186 albertel 4151: </nobr>
4152: <nobr>
1.272 albertel 4153: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4154: value="no" /> No </label>
1.186 albertel 4155: </nobr>';
4156: return $result;
4157: }
4158:
1.75 albertel 4159: sub scantron_selectphase {
1.209 ng 4160: my ($r,$file2grade) = @_;
1.75 albertel 4161: my ($symb,$url)=&get_symb_and_url($r);
4162: if (!$symb) {return '';}
4163: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.81 albertel 4164: my $default_form_data=&defaultFormData($symb,$url);
4165: my $grading_menu_button=&show_grading_menu_form($symb,$url);
1.209 ng 4166: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4167: my $format_selector=&scantron_scantab();
1.186 albertel 4168: my $CODE_selector=&scantron_CODElist();
4169: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4170: my $result;
1.157 albertel 4171: #FIXME allow instructor to be able to download the scantron file
4172: # and to upload it,
1.75 albertel 4173: $result.= <<SCANTRONFORM;
1.162 albertel 4174: <table width="100%" border="0">
1.75 albertel 4175: <tr>
1.226 albertel 4176: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
1.75 albertel 4177: <td bgcolor="#777777">
1.203 albertel 4178: <input type="hidden" name="command" value="scantron_warning" />
1.162 albertel 4179: $default_form_data
1.75 albertel 4180: <table width="100%" border="0">
4181: <tr bgcolor="#e6ffff">
1.174 albertel 4182: <td colspan="2">
4183: <b>Specify file and which Folder/Sequence to grade</b>
1.75 albertel 4184: </td>
4185: </tr>
4186: <tr bgcolor="#ffffe6">
1.174 albertel 4187: <td> Sequence to grade: </td><td> $sequence_selector </td>
1.75 albertel 4188: </tr>
4189: <tr bgcolor="#ffffe6">
1.174 albertel 4190: <td> Filename of scoring office file: </td><td> $file_selector </td>
1.75 albertel 4191: </tr>
1.82 albertel 4192: <tr bgcolor="#ffffe6">
1.174 albertel 4193: <td> Format of data file: </td><td> $format_selector </td>
1.82 albertel 4194: </tr>
1.157 albertel 4195: <tr bgcolor="#ffffe6">
1.186 albertel 4196: <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
4197: </tr>
4198: <tr bgcolor="#ffffe6">
4199: <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
4200: </tr>
4201: <tr bgcolor="#ffffe6">
1.187 albertel 4202: <td> Options: </td>
4203: <td>
1.272 albertel 4204: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
4205: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label>
1.187 albertel 4206: </td>
4207: </tr>
4208: <tr bgcolor="#ffffe6">
1.174 albertel 4209: <td colspan="2">
1.265 www 4210: <input type="submit" value="Grading: Validate Scantron Records" />
1.162 albertel 4211: </td>
4212: </tr>
4213: </table>
1.226 albertel 4214: </td>
4215: </form>
1.162 albertel 4216: </tr>
4217: SCANTRONFORM
4218:
4219: $r->print($result);
4220:
1.257 albertel 4221: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
4222: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 4223:
4224: $r->print(<<SCANTRONFORM);
4225: <tr>
4226: <td bgcolor="#777777">
4227: <table width="100%" border="0">
4228: <tr bgcolor="#e6ffff">
4229: <td>
1.174 albertel 4230: <b>Specify a Scantron data file to upload.</b>
1.162 albertel 4231: </td>
4232: </tr>
4233: <tr bgcolor="#ffffe6">
4234: <td>
4235: SCANTRONFORM
1.174 albertel 4236: my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
1.257 albertel 4237: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4238: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.174 albertel 4239: $r->print(<<UPLOAD);
4240: <script type="text/javascript" language="javascript">
4241: function checkUpload(formname) {
4242: if (formname.upfile.value == "") {
4243: alert("Please use the browse button to select a file from your local directory.");
4244: return false;
4245: }
4246: formname.submit();
4247: }
4248: </script>
4249:
4250: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
4251: $default_form_data
4252: <input name='courseid' type='hidden' value='$cnum' />
4253: <input name='domainid' type='hidden' value='$cdom' />
4254: <input name='command' value='scantronupload_save' type='hidden' />
4255: File to upload:<input type="file" name="upfile" size="50" />
4256: <br />
4257: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
4258: </form>
4259: UPLOAD
1.162 albertel 4260:
4261: $r->print(<<SCANTRONFORM);
4262: </td>
4263: </tr>
1.75 albertel 4264: </table>
4265: </td>
4266: </tr>
1.162 albertel 4267: SCANTRONFORM
4268: }
1.187 albertel 4269: $r->print(<<SCANTRONFORM);
4270: <tr>
1.226 albertel 4271: <form action='/adm/grades' name='scantron_download'>
4272: <td bgcolor="#777777">
1.187 albertel 4273: <input type="hidden" name="command" value="scantron_download" />
4274: <table width="100%" border="0">
4275: <tr bgcolor="#e6ffff">
4276: <td colspan="2">
4277: <b>Download a scoring office file</b>
4278: </td>
4279: </tr>
4280: <tr bgcolor="#ffffe6">
4281: <td> Filename of scoring office file: </td><td> $file_selector </td>
4282: </tr>
4283: <tr bgcolor="#ffffe6">
4284: <td colspan="2">
1.293 www 4285: <input type="submit" value="Download: Show List of Associated Files" />
1.187 albertel 4286: </td>
4287: </tr>
4288: </table>
1.226 albertel 4289: </td>
4290: </form>
1.187 albertel 4291: </tr>
4292: SCANTRONFORM
1.162 albertel 4293:
4294: $r->print(<<SCANTRONFORM);
1.75 albertel 4295: </table>
1.81 albertel 4296: $grading_menu_button
1.75 albertel 4297: SCANTRONFORM
4298:
1.162 albertel 4299: return
1.75 albertel 4300: }
4301:
1.82 albertel 4302: sub get_scantron_config {
4303: my ($which) = @_;
4304: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4305: my %config;
1.157 albertel 4306: #FIXME probably should move to XML it has already gotten a bit much now
1.82 albertel 4307: foreach my $line (<$fh>) {
4308: my ($name,$descrip)=split(/:/,$line);
4309: if ($name ne $which ) { next; }
4310: chomp($line);
4311: my @config=split(/:/,$line);
4312: $config{'name'}=$config[0];
4313: $config{'description'}=$config[1];
4314: $config{'CODElocation'}=$config[2];
4315: $config{'CODEstart'}=$config[3];
4316: $config{'CODElength'}=$config[4];
4317: $config{'IDstart'}=$config[5];
4318: $config{'IDlength'}=$config[6];
4319: $config{'Qstart'}=$config[7];
4320: $config{'Qlength'}=$config[8];
4321: $config{'Qoff'}=$config[9];
4322: $config{'Qon'}=$config[10];
1.157 albertel 4323: $config{'PaperID'}=$config[11];
4324: $config{'PaperIDlength'}=$config[12];
4325: $config{'FirstName'}=$config[13];
4326: $config{'FirstNamelength'}=$config[14];
4327: $config{'LastName'}=$config[15];
4328: $config{'LastNamelength'}=$config[16];
1.82 albertel 4329: last;
4330: }
4331: return %config;
4332: }
4333:
4334: sub username_to_idmap {
4335: my ($classlist)= @_;
4336: my %idmap;
4337: foreach my $student (keys(%$classlist)) {
4338: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
4339: $student;
4340: }
4341: return %idmap;
4342: }
4343:
1.157 albertel 4344: sub scantron_fixup_scanline {
4345: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
4346: if ($field eq 'ID') {
4347: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 4348: return ($line,1,'New value too large');
1.157 albertel 4349: }
4350: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
4351: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
4352: $args->{'newid'});
4353: }
4354: substr($line,$$scantron_config{'IDstart'}-1,
4355: $$scantron_config{'IDlength'})=$args->{'newid'};
4356: if ($args->{'newid'}=~/^\s*$/) {
4357: &scan_data($scan_data,"$whichline.user",
4358: $args->{'username'}.':'.$args->{'domain'});
4359: }
1.186 albertel 4360: } elsif ($field eq 'CODE') {
1.192 albertel 4361: if ($args->{'CODE_ignore_dup'}) {
4362: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
4363: }
4364: &scan_data($scan_data,"$whichline.useCODE",'1');
4365: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 4366: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
4367: return ($line,1,'New CODE value too large');
4368: }
4369: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
4370: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
4371: }
4372: substr($line,$$scantron_config{'CODEstart'}-1,
4373: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 4374: }
1.157 albertel 4375: } elsif ($field eq 'answer') {
4376: my $length=$scantron_config->{'Qlength'};
4377: my $off=$scantron_config->{'Qoff'};
4378: my $on=$scantron_config->{'Qon'};
4379: my $answer=${off}x$length;
4380: if ($args->{'response'} eq 'none') {
4381: &scan_data($scan_data,
4382: "$whichline.no_bubble.".$args->{'question'},'1');
4383: } else {
1.274 albertel 4384: if ($on eq 'letter') {
4385: my @alphabet=('A'..'Z');
4386: $answer=$alphabet[$args->{'response'}];
4387: } elsif ($on eq 'number') {
4388: $answer=$args->{'response'}+1;
4389: } else {
4390: substr($answer,$args->{'response'},1)=$on;
4391: }
1.157 albertel 4392: &scan_data($scan_data,
4393: "$whichline.no_bubble.".$args->{'question'},undef,'1');
4394: }
4395: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
4396: substr($line,$where-1,$length)=$answer;
4397: }
4398: return $line;
4399: }
4400:
4401: sub scan_data {
4402: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 4403: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 4404: if (defined($value)) {
4405: $scan_data->{$filename.'_'.$key} = $value;
4406: }
4407: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
4408: return $scan_data->{$filename.'_'.$key};
4409: }
4410:
1.82 albertel 4411: sub scantron_parse_scanline {
1.194 albertel 4412: my ($line,$whichline,$scantron_config,$scan_data,$justHeader)=@_;
1.82 albertel 4413: my %record;
4414: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
4415: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
1.278 albertel 4416: if (!($$scantron_config{'CODElocation'} eq 0 ||
4417: $$scantron_config{'CODElocation'} eq 'none')) {
4418: if ($$scantron_config{'CODElocation'} < 0 ||
4419: $$scantron_config{'CODElocation'} eq 'letter' ||
4420: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 4421: $record{'scantron.CODE'}=substr($data,
4422: $$scantron_config{'CODEstart'}-1,
1.83 albertel 4423: $$scantron_config{'CODElength'});
1.191 albertel 4424: if (&scan_data($scan_data,"$whichline.useCODE")) {
4425: $record{'scantron.useCODE'}=1;
4426: }
1.192 albertel 4427: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
4428: $record{'scantron.CODE_ignore_dup'}=1;
4429: }
1.82 albertel 4430: } else {
4431: #FIXME interpret first N questions
4432: }
4433: }
1.83 albertel 4434: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
4435: $$scantron_config{'IDlength'});
1.157 albertel 4436: $record{'scantron.PaperID'}=
4437: substr($data,$$scantron_config{'PaperID'}-1,
4438: $$scantron_config{'PaperIDlength'});
4439: $record{'scantron.FirstName'}=
4440: substr($data,$$scantron_config{'FirstName'}-1,
4441: $$scantron_config{'FirstNamelength'});
4442: $record{'scantron.LastName'}=
4443: substr($data,$$scantron_config{'LastName'}-1,
4444: $$scantron_config{'LastNamelength'});
1.194 albertel 4445: if ($justHeader) { return \%record; }
4446:
1.82 albertel 4447: my @alphabet=('A'..'Z');
4448: my $questnum=0;
4449: while ($questions) {
4450: $questnum++;
4451: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
4452: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 4453: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.239 albertel 4454: if ($$scantron_config{'Qon'} eq 'letter') {
1.274 albertel 4455: if ($currentquest eq '?') {
4456: push(@{$record{'scantron.doubleerror'}},$questnum);
4457: $record{"scantron.$questnum.answer"}='';
4458: } elsif (!$currentquest
4459: || $currentquest eq $$scantron_config{'Qoff'}
4460: || $currentquest !~ /^[A-Z]$/) {
1.239 albertel 4461: $record{"scantron.$questnum.answer"}='';
4462: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4463: push(@{$record{"scantron.missingerror"}},$questnum);
4464: }
4465: } else {
4466: $record{"scantron.$questnum.answer"}=$currentquest;
4467: }
4468: } elsif ($$scantron_config{'Qon'} eq 'number') {
1.274 albertel 4469: if ($currentquest eq '?') {
4470: push(@{$record{'scantron.doubleerror'}},$questnum);
4471: $record{"scantron.$questnum.answer"}='';
4472: } elsif (!$currentquest
4473: || $currentquest eq $$scantron_config{'Qoff'}
4474: || $currentquest !~ /^\d$/) {
1.239 albertel 4475: $record{"scantron.$questnum.answer"}='';
4476: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4477: push(@{$record{"scantron.missingerror"}},$questnum);
4478: }
4479: } else {
4480: $record{"scantron.$questnum.answer"}=
4481: $alphabet[$currentquest-1];
4482: }
1.82 albertel 4483: } else {
1.239 albertel 4484: my @array=split($$scantron_config{'Qon'},$currentquest,-1);
4485: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
4486: $record{"scantron.$questnum.answer"}='';
4487: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4488: push(@{$record{"scantron.missingerror"}},$questnum);
4489: }
4490: } else {
4491: $record{"scantron.$questnum.answer"}=
4492: $alphabet[length($array[0])];
4493: }
4494: if (scalar(@array) gt 2) {
4495: push(@{$record{'scantron.doubleerror'}},$questnum);
4496: my @ans=@array;
4497: my $i=length($ans[0]);shift(@ans);
4498: while ($#ans) {
4499: $i+=length($ans[0])+1;
4500: $record{"scantron.$questnum.answer"}.=$alphabet[$i];
4501: shift(@ans);
4502: }
4503: }
1.82 albertel 4504: }
4505: }
1.83 albertel 4506: $record{'scantron.maxquest'}=$questnum;
4507: return \%record;
1.82 albertel 4508: }
4509:
4510: sub scantron_add_delay {
1.140 albertel 4511: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
4512: push(@$delayqueue,
4513: {'line' => $scanline, 'emsg' => $errormessage,
4514: 'ecode' => $errorcode }
4515: );
1.82 albertel 4516: }
4517:
4518: sub scantron_find_student {
1.157 albertel 4519: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 4520: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 4521: if ($scanID =~ /^\s*$/) {
4522: return &scan_data($scan_data,"$line.user");
4523: }
1.83 albertel 4524: foreach my $id (keys(%$idmap)) {
1.157 albertel 4525: if (lc($id) eq lc($scanID)) {
4526: return $$idmap{$id};
4527: }
1.83 albertel 4528: }
4529: return undef;
4530: }
4531:
4532: sub scantron_filter {
4533: my ($curres)=@_;
1.215 albertel 4534: # randomout is dysfunctional at best for this purpose
4535: if (ref($curres) && $curres->is_problem()) { #&& !$curres->randomout) {
1.83 albertel 4536: return 1;
4537: }
4538: return 0;
1.82 albertel 4539: }
4540:
1.157 albertel 4541: sub scantron_process_corrections {
4542: my ($r) = @_;
1.257 albertel 4543: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4544: my ($scanlines,$scan_data)=&scantron_getfile();
4545: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 4546: my $which=$env{'form.scantron_line'};
1.200 albertel 4547: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 4548: my ($skip,$err,$errmsg);
1.257 albertel 4549: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 4550: $skip=1;
1.257 albertel 4551: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
4552: my $newstudent=$env{'form.scantron_username'}.':'.
4553: $env{'form.scantron_domain'};
1.157 albertel 4554: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
4555: ($line,$err,$errmsg)=
4556: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
4557: 'ID',{'newid'=>$newid,
1.257 albertel 4558: 'username'=>$env{'form.scantron_username'},
4559: 'domain'=>$env{'form.scantron_domain'}});
4560: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
4561: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 4562: my $newCODE;
1.192 albertel 4563: my %args;
1.190 albertel 4564: if ($resolution eq 'use_unfound') {
1.191 albertel 4565: $newCODE='use_unfound';
1.190 albertel 4566: } elsif ($resolution eq 'use_found') {
1.257 albertel 4567: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 4568: } elsif ($resolution eq 'use_typed') {
1.257 albertel 4569: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 4570: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 4571: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 4572: }
1.257 albertel 4573: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 4574: $args{'CODE_ignore_dup'}=1;
4575: }
4576: $args{'CODE'}=$newCODE;
1.186 albertel 4577: ($line,$err,$errmsg)=
4578: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 4579: 'CODE',\%args);
1.257 albertel 4580: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
4581: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 4582: ($line,$err,$errmsg)=
4583: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
4584: $which,'answer',
4585: { 'question'=>$question,
1.257 albertel 4586: 'response'=>$env{"form.scantron_correct_Q_$question"}});
1.157 albertel 4587: if ($err) { last; }
4588: }
4589: }
4590: if ($err) {
1.287 albertel 4591: $r->print("<font color='red'>Unable to accept last correction, an error occurred :$errmsg:</font>");
1.157 albertel 4592: } else {
1.200 albertel 4593: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 4594: &scantron_putfile($scanlines,$scan_data);
4595: }
4596: }
4597:
1.200 albertel 4598: sub reset_skipping_status {
4599: my ($scanlines,$scan_data)=&scantron_getfile();
4600: &scan_data($scan_data,'remember_skipping',undef,1);
4601: &scantron_putfile(undef,$scan_data);
4602: }
4603:
4604: sub allow_skipping {
4605: my ($scan_data,$i)=@_;
4606: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
4607: delete($remembered{$i});
4608: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
4609: }
4610:
4611: sub should_be_skipped {
4612: my ($scan_data,$i)=@_;
1.257 albertel 4613: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 4614: # not redoing old skips
4615: return 0;
4616: }
4617: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
4618: if (exists($remembered{$i})) { return 0; }
4619: return 1;
4620: }
4621:
4622: sub remember_current_skipped {
4623: my ($scanlines,$scan_data)=&scantron_getfile();
4624: my %to_remember;
4625: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4626: if ($scanlines->{'skipped'}[$i]) {
4627: $to_remember{$i}=1;
4628: }
4629: }
4630: &Apache::lonnet::logthis('remembering '.join(':',%to_remember));
4631: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
4632: &scantron_putfile(undef,$scan_data);
4633: }
4634:
4635: sub check_for_error {
4636: my ($r,$result)=@_;
4637: if ($result ne 'ok' && $result ne 'not_found' ) {
4638: $r->print("An error occured ($result) when trying to Remove the existing corrections.");
4639: }
4640: }
1.157 albertel 4641:
1.203 albertel 4642: sub scantron_warning_screen {
4643: my ($button_text)=@_;
1.257 albertel 4644: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 4645: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
4646: my $CODElist="a";
4647: if ($scantron_config{'CODElocation'} &&
4648: $scantron_config{'CODEstart'} &&
4649: $scantron_config{'CODElength'}) {
4650: $CODElist=$env{'form.scantron_CODElist'};
4651: if ($CODElist eq '') { $CODElist='<font color="red">None</font>'; }
4652: $CODElist=
4653: '<tr><td><b>List of CODES to validate against:</b></td><td><tt>'.
4654: $CODElist.'</tt></td></tr>';
4655: }
1.203 albertel 4656: return (<<STUFF);
4657: <p>
4658: <font color="red">Please double check the information
4659: below before clicking on '$button_text'</font>
4660: </p>
4661: <table>
1.284 albertel 4662: <tr><td><b>Sequence to be Graded:</b></td><td>$title</td></tr>
1.257 albertel 4663: <tr><td><b>Data File that will be used:</b></td><td><tt>$env{'form.scantron_selectfile'}</tt></td></tr>
1.284 albertel 4664: $CODElist
1.203 albertel 4665: </table>
4666: </font>
4667: <br />
4668: <p> If this information is correct, please click on '$button_text'.</p>
4669: <p> If something is incorrect, please click the 'Grading Menu' button to start over.</p>
4670:
4671: <br />
4672: STUFF
4673: }
4674:
4675: sub scantron_do_warning {
4676: my ($r)=@_;
4677: my ($symb,$url)=&get_symb_and_url($r);
4678: if (!$symb) {return '';}
4679: my $default_form_data=&defaultFormData($symb,$url);
4680: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 4681: if ( $env{'form.selectpage'} eq '' ||
4682: $env{'form.scantron_selectfile'} eq '' ||
4683: $env{'form.scantron_format'} eq '' ) {
1.237 albertel 4684: $r->print("<p>You have forgetten to specify some information. Please go Back and try again.</p>");
1.257 albertel 4685: if ( $env{'form.selectpage'} eq '') {
1.237 albertel 4686: $r->print('<p><font color="red">You have not selected a Sequence to grade</font></p>');
4687: }
1.257 albertel 4688: if ( $env{'form.scantron_selectfile'} eq '') {
1.237 albertel 4689: $r->print('<p><font color="red">You have not selected a file that contains the student\'s response data.</font></p>');
4690: }
1.257 albertel 4691: if ( $env{'form.scantron_format'} eq '') {
1.237 albertel 4692: $r->print('<p><font color="red">You have not selected a the format of the student\'s response data.</font></p>');
4693: }
4694: } else {
1.265 www 4695: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.237 albertel 4696: $r->print(<<STUFF);
1.203 albertel 4697: $warning
1.265 www 4698: <input type="submit" name="submit" value="Grading: Validate Records" />
1.203 albertel 4699: <input type="hidden" name="command" value="scantron_validate" />
4700: STUFF
1.237 albertel 4701: }
4702: $r->print("</form><br />".&show_grading_menu_form($symb,$url)."</body></html>");
1.203 albertel 4703: return '';
4704: }
4705:
4706: sub scantron_form_start {
4707: my ($max_bubble)=@_;
4708: my $result= <<SCANTRONFORM;
4709: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 4710: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
4711: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
4712: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 4713: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 4714: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
4715: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
4716: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
4717: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.203 albertel 4718: SCANTRONFORM
4719: return $result;
4720: }
4721:
1.157 albertel 4722: sub scantron_validate_file {
4723: my ($r) = @_;
4724: my ($symb,$url)=&get_symb_and_url($r);
4725: if (!$symb) {return '';}
4726: my $default_form_data=&defaultFormData($symb,$url);
1.200 albertel 4727:
4728: # do the detection of only doing skipped records first befroe we delete
4729: # them when doing the corrections reset
1.257 albertel 4730: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 4731: &reset_skipping_status();
4732: }
1.257 albertel 4733: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 4734: &remember_current_skipped();
4735: &scantron_remove_file('skipped');
1.257 albertel 4736: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 4737: }
4738:
1.257 albertel 4739: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 4740: &check_for_error($r,&scantron_remove_file('corrected'));
4741: &check_for_error($r,&scantron_remove_file('skipped'));
4742: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 4743: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 4744: }
1.200 albertel 4745:
1.257 albertel 4746: if ($env{'form.scantron_corrections'}) {
1.157 albertel 4747: &scantron_process_corrections($r);
4748: }
1.191 albertel 4749: $r->print("<p>Gathering neccessary info.</p>");$r->rflush();
1.157 albertel 4750: #get the student pick code ready
4751: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.203 albertel 4752: my $max_bubble=&scantron_get_maxbubble($r);
4753: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 4754: $r->print($result);
4755:
4756: my @validate_phases=( 'ID',
4757: 'CODE',
4758: 'doublebubble',
4759: 'missingbubbles');
1.257 albertel 4760: if (!$env{'form.validatepass'}) {
4761: $env{'form.validatepass'} = 0;
1.157 albertel 4762: }
1.257 albertel 4763: my $currentphase=$env{'form.validatepass'};
1.157 albertel 4764:
4765: my $stop=0;
4766: while (!$stop && $currentphase < scalar(@validate_phases)) {
4767: $r->print("<p> Validating ".$validate_phases[$currentphase]."</p>");
4768: $r->rflush();
4769: my $which="scantron_validate_".$validate_phases[$currentphase];
4770: {
4771: no strict 'refs';
4772: ($stop,$currentphase)=&$which($r,$currentphase);
4773: }
4774: }
4775: if (!$stop) {
1.203 albertel 4776: my $warning=&scantron_warning_screen('Start Grading');
4777: $r->print(<<STUFF);
4778: Validation process complete.<br />
4779: $warning
4780: <input type="submit" name="submit" value="Start Grading" />
4781: <input type="hidden" name="command" value="scantron_process" />
4782: STUFF
4783:
1.157 albertel 4784: } else {
4785: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
4786: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
4787: }
4788: if ($stop) {
4789: $r->print('<input type="submit" name="submit" value="Continue ->" />');
4790: $r->print(' using corrected info <br />');
4791: $r->print("<input type='submit' value='Skip' name='scantron_skip_record' />");
4792: $r->print(" this scanline saving it for later.");
4793: }
4794: $r->print(" </form><br />".&show_grading_menu_form($symb,$url).
4795: "</body></html>");
4796: return '';
4797: }
4798:
1.200 albertel 4799: sub scantron_remove_file {
1.192 albertel 4800: my ($which)=@_;
1.257 albertel 4801: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4802: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 4803: my $file='scantron_';
1.200 albertel 4804: if ($which eq 'corrected' || $which eq 'skipped') {
4805: $file.=$which.'_';
1.192 albertel 4806: } else {
4807: return 'refused';
4808: }
1.257 albertel 4809: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 4810: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
4811: }
4812:
4813: sub scantron_remove_scan_data {
1.257 albertel 4814: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4815: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 4816: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
4817: my @todelete;
1.257 albertel 4818: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 4819: foreach my $key (@keys) {
4820: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 4821: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 4822: $key=~/remember_skipping/) {
4823: next;
4824: }
1.192 albertel 4825: push(@todelete,$key);
4826: }
4827: }
1.200 albertel 4828: my $result;
1.192 albertel 4829: if (@todelete) {
1.200 albertel 4830: $result=&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
1.192 albertel 4831: }
4832: return $result;
4833: }
4834:
1.157 albertel 4835: sub scantron_getfile {
1.200 albertel 4836: #FIXME really would prefer a scantron directory
1.257 albertel 4837: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4838: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 4839: my $lines;
4840: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4841: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 4842: my %scanlines;
4843: $scanlines{'orig'}=[(split("\n",$lines,-1))];
4844: my $temp=$scanlines{'orig'};
4845: $scanlines{'count'}=$#$temp;
4846:
4847: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4848: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 4849: if ($lines eq '-1') {
4850: $scanlines{'corrected'}=[];
4851: } else {
4852: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
4853: }
4854: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4855: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 4856: if ($lines eq '-1') {
4857: $scanlines{'skipped'}=[];
4858: } else {
4859: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
4860: }
1.175 albertel 4861: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 4862: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
4863: my %scan_data = @tmp;
4864: return (\%scanlines,\%scan_data);
4865: }
4866:
4867: sub lonnet_putfile {
4868: my ($contents,$filename)=@_;
1.257 albertel 4869: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4870: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4871: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 4872: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 4873:
4874: }
4875:
4876: sub scantron_putfile {
4877: my ($scanlines,$scan_data) = @_;
1.200 albertel 4878: #FIXME really would prefer a scantron directory
1.257 albertel 4879: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4880: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 4881: if ($scanlines) {
4882: my $prefix='scantron_';
1.157 albertel 4883: # no need to update orig, shouldn't change
4884: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 4885: # $env{'form.scantron_selectfile'});
1.200 albertel 4886: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
4887: $prefix.'corrected_'.
1.257 albertel 4888: $env{'form.scantron_selectfile'});
1.200 albertel 4889: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
4890: $prefix.'skipped_'.
1.257 albertel 4891: $env{'form.scantron_selectfile'});
1.200 albertel 4892: }
1.175 albertel 4893: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 4894: }
4895:
4896: sub scantron_get_line {
1.200 albertel 4897: my ($scanlines,$scan_data,$i)=@_;
4898: if (&should_be_skipped($scan_data,$i)) { return undef; }
4899: if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 4900: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
4901: return $scanlines->{'orig'}[$i];
4902: }
4903:
1.200 albertel 4904: sub get_todo_count {
4905: my ($scanlines,$scan_data)=@_;
4906: my $count=0;
4907: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4908: my $line=&scantron_get_line($scanlines,$scan_data,$i);
4909: if ($line=~/^[\s\cz]*$/) { next; }
4910: $count++;
4911: }
4912: return $count;
4913: }
4914:
1.157 albertel 4915: sub scantron_put_line {
1.200 albertel 4916: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 4917: if ($skip) {
4918: $scanlines->{'skipped'}[$i]=$newline;
1.200 albertel 4919: &allow_skipping($scan_data,$i);
1.157 albertel 4920: return;
4921: }
4922: $scanlines->{'corrected'}[$i]=$newline;
4923: }
4924:
4925: sub scantron_validate_ID {
4926: my ($r,$currentphase) = @_;
4927:
4928: #get student info
4929: my $classlist=&Apache::loncoursedata::get_classlist();
4930: my %idmap=&username_to_idmap($classlist);
4931:
4932: #get scantron line setup
1.257 albertel 4933: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4934: my ($scanlines,$scan_data)=&scantron_getfile();
4935:
4936: my %found=('ids'=>{},'usernames'=>{});
4937: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 4938: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 4939: if ($line=~/^[\s\cz]*$/) { next; }
4940: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
4941: $scan_data);
4942: my $id=$$scan_record{'scantron.ID'};
4943: my $found;
4944: foreach my $checkid (keys(%idmap)) {
4945: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
4946: }
4947: if ($found) {
4948: my $username=$idmap{$found};
4949: if ($found{'ids'}{$found}) {
4950: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
4951: $line,'duplicateID',$found);
1.194 albertel 4952: return(1,$currentphase);
1.157 albertel 4953: } elsif ($found{'usernames'}{$username}) {
4954: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
4955: $line,'duplicateID',$username);
1.194 albertel 4956: return(1,$currentphase);
1.157 albertel 4957: }
1.186 albertel 4958: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 4959: $found{'ids'}{$found}++;
4960: $found{'usernames'}{$username}++;
4961: } else {
4962: if ($id =~ /^\s*$/) {
1.158 albertel 4963: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 4964: if (defined($username) && $found{'usernames'}{$username}) {
4965: &scantron_get_correction($r,$i,$scan_record,
4966: \%scantron_config,
4967: $line,'duplicateID',$username);
1.194 albertel 4968: return(1,$currentphase);
1.157 albertel 4969: } elsif (!defined($username)) {
4970: &scantron_get_correction($r,$i,$scan_record,
4971: \%scantron_config,
4972: $line,'incorrectID');
1.194 albertel 4973: return(1,$currentphase);
1.157 albertel 4974: }
4975: $found{'usernames'}{$username}++;
4976: } else {
4977: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
4978: $line,'incorrectID');
1.194 albertel 4979: return(1,$currentphase);
1.157 albertel 4980: }
4981: }
4982: }
4983:
4984: return (0,$currentphase+1);
4985: }
4986:
4987: sub scantron_get_correction {
4988: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
4989:
4990: #FIXME in the case of a duplicated ID the previous line, probaly need
4991: #to show both the current line and the previous one and allow skipping
4992: #the previous one or the current one
4993:
1.161 albertel 4994: $r->print("<p><b>An error was detected ($error)</b>");
1.157 albertel 4995: if ( defined($$scan_record{'scantron.PaperID'}) ) {
4996: $r->print(" for PaperID <tt>".
4997: $$scan_record{'scantron.PaperID'}."</tt> \n");
4998: } else {
4999: $r->print(" in scanline $i <pre>".
5000: $line."</pre> \n");
5001: }
1.242 albertel 5002: my $message="<p>The ID on the form is <tt>".
5003: $$scan_record{'scantron.ID'}."</tt><br />\n".
5004: "The name on the paper is ".
5005: $$scan_record{'scantron.LastName'}.",".
5006: $$scan_record{'scantron.FirstName'}."</p>";
5007:
1.157 albertel 5008: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
5009: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
5010: if ($error =~ /ID$/) {
1.186 albertel 5011: if ($error eq 'incorrectID') {
1.157 albertel 5012: $r->print("The encoded ID is not in the classlist</p>\n");
5013: } elsif ($error eq 'duplicateID') {
5014: $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
5015: }
1.242 albertel 5016: $r->print($message);
1.157 albertel 5017: $r->print("<p>How should I handle this? <br /> \n");
5018: $r->print("\n<ul><li> ");
5019: #FIXME it would be nice if this sent back the user ID and
5020: #could do partial userID matches
5021: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
5022: 'scantron_username','scantron_domain'));
5023: $r->print(": <input type='text' name='scantron_username' value='' />");
5024: $r->print("\n@".
1.257 albertel 5025: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 5026:
5027: $r->print('</li>');
1.186 albertel 5028: } elsif ($error =~ /CODE$/) {
5029: if ($error eq 'incorrectCODE') {
1.187 albertel 5030: $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
1.186 albertel 5031: } elsif ($error eq 'duplicateCODE') {
1.194 albertel 5032: $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 5033: }
1.224 albertel 5034: $r->print("<p>The CODE on the form is <tt>'".
5035: $$scan_record{'scantron.CODE'}."'</tt><br />\n");
1.242 albertel 5036: $r->print($message);
1.186 albertel 5037: $r->print("<p>How should I handle this? <br /> \n");
1.187 albertel 5038: $r->print("\n<br /> ");
1.194 albertel 5039: my $i=0;
1.273 albertel 5040: if ($error eq 'incorrectCODE'
5041: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 5042: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 5043: if ($closest > 0) {
5044: foreach my $testcode (@{$closest}) {
5045: my $checked='';
5046: if (!$i) { $checked=' checked="on" '; }
5047: $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' />");
5048: $r->print("\n<br />");
5049: $i++;
5050: }
1.194 albertel 5051: }
5052: }
1.273 albertel 5053: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
5054: my $checked; if (!$i) { $checked=' checked="on" '; }
5055: $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>");
5056: $r->print("\n<br />");
5057: }
1.194 albertel 5058:
1.188 albertel 5059: $r->print(<<ENDSCRIPT);
5060: <script type="text/javascript">
5061: function change_radio(field) {
1.190 albertel 5062: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 5063: var i;
5064: for (i=0;i<slct.length;i++) {
5065: if (slct[i].value==field) { slct[i].checked=true; }
5066: }
5067: }
5068: </script>
5069: ENDSCRIPT
1.187 albertel 5070: my $href="/adm/pickcode?".
5071: "form=".&Apache::lonnet::escape("scantronupload").
1.257 albertel 5072: "&scantron_format=".&Apache::lonnet::escape($env{'form.scantron_format'}).
5073: "&scantron_CODElist=".&Apache::lonnet::escape($env{'form.scantron_CODElist'}).
1.187 albertel 5074: "&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}).
1.257 albertel 5075: "&scantron_selectfile=".&Apache::lonnet::escape($env{'form.scantron_selectfile'});
1.272 albertel 5076: $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 5077: $r->print("\n<br />");
1.272 albertel 5078: $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 5079: $r->print("\n<br /><br />");
1.157 albertel 5080: } elsif ($error eq 'doublebubble') {
5081: $r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
5082: $r->print('<input type="hidden" name="scantron_questions" value="'.
5083: join(',',@{$arg}).'" />');
1.242 albertel 5084: $r->print($message);
1.157 albertel 5085: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5086: foreach my $question (@{$arg}) {
5087: my $selected=$$scan_record{"scantron.$question.answer"};
5088: &scantron_bubble_selector($r,$scan_config,$question,split('',$selected));
5089: }
5090: } elsif ($error eq 'missingbubble') {
5091: $r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
1.242 albertel 5092: $r->print($message);
1.157 albertel 5093: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5094: $r->print("Some questions have no scanned bubbles\n");
5095: $r->print('<input type="hidden" name="scantron_questions" value="'.
5096: join(',',@{$arg}).'" />');
5097: foreach my $question (@{$arg}) {
5098: my $selected=$$scan_record{"scantron.$question.answer"};
5099: &scantron_bubble_selector($r,$scan_config,$question);
5100: }
5101: } else {
5102: $r->print("\n<ul>");
5103: }
5104: $r->print("\n</li></ul>");
5105:
5106: }
5107:
5108: sub scantron_bubble_selector {
5109: my ($r,$scan_config,$quest,@selected)=@_;
5110: my $max=$$scan_config{'Qlength'};
1.274 albertel 5111:
5112: my $scmode=$$scan_config{'Qon'};
5113: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
5114:
1.157 albertel 5115: my @alphabet=('A'..'Z');
5116: $r->print("<table border='1'><tr><td rowspan='2'>$quest</td>");
5117: for (my $i=0;$i<$max+1;$i++) {
1.274 albertel 5118: $r->print("\n".'<td align="center">');
1.157 albertel 5119: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
5120: else { $r->print(' '); }
5121: $r->print('</td>');
5122: }
1.274 albertel 5123: $r->print('</tr><tr>');
1.157 albertel 5124: for (my $i=0;$i<$max;$i++) {
1.274 albertel 5125: $r->print("\n".
5126: '<td><label><input type="radio" name="scantron_correct_Q_'.
1.272 albertel 5127: $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
1.157 albertel 5128: }
1.272 albertel 5129: $r->print('<td><label><input type="radio" name="scantron_correct_Q_'.
5130: $quest.'" value="none" /> No bubble </label></td>');
1.157 albertel 5131: $r->print('</tr></table>');
5132: }
5133:
1.194 albertel 5134: sub num_matches {
5135: my ($orig,$code) = @_;
5136: my @code=split(//,$code);
5137: my @orig=split(//,$orig);
5138: my $same=0;
5139: for (my $i=0;$i<scalar(@code);$i++) {
5140: if ($code[$i] eq $orig[$i]) { $same++; }
5141: }
5142: return $same;
5143: }
5144:
5145: sub scantron_get_closely_matching_CODEs {
5146: my ($allcodes,$CODE)=@_;
5147: my @CODEs;
5148: foreach my $testcode (sort(keys(%{$allcodes}))) {
5149: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
5150: }
5151:
5152: return ($#CODEs,$CODEs[-1]);
5153: }
5154:
5155: sub get_codes {
1.280 foxr 5156: my ($old_name, $cdom, $cnum) = @_;
5157: if (!$old_name) {
5158: $old_name=$env{'form.scantron_CODElist'};
5159: }
5160: if (!$cdom) {
5161: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
5162: }
5163: if (!$cnum) {
5164: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
5165: }
1.278 albertel 5166: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
5167: $cdom,$cnum);
5168: my %allcodes;
5169: if ($result{"type\0$old_name"} eq 'number') {
5170: %allcodes=map {($_,1)} split(',',$result{$old_name});
5171: } else {
5172: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
5173: }
1.194 albertel 5174: return %allcodes;
5175: }
5176:
1.157 albertel 5177: sub scantron_validate_CODE {
5178: my ($r,$currentphase) = @_;
1.257 albertel 5179: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 5180: if ($scantron_config{'CODElocation'} &&
5181: $scantron_config{'CODEstart'} &&
5182: $scantron_config{'CODElength'}) {
1.257 albertel 5183: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 5184: &FIXME_blow_up()
5185: }
5186: } else {
5187: return (0,$currentphase+1);
5188: }
5189:
5190: my %usedCODEs;
5191:
1.194 albertel 5192: my %allcodes=&get_codes();
1.186 albertel 5193:
5194: my ($scanlines,$scan_data)=&scantron_getfile();
5195: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5196: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 5197: if ($line=~/^[\s\cz]*$/) { next; }
5198: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5199: $scan_data);
5200: my $CODE=$$scan_record{'scantron.CODE'};
5201: my $error=0;
1.224 albertel 5202: if (!&Apache::lonnet::validCODE($CODE)) {
5203: &scantron_get_correction($r,$i,$scan_record,
5204: \%scantron_config,
5205: $line,'incorrectCODE',\%allcodes);
5206: return(1,$currentphase);
5207: }
1.221 albertel 5208: if (%allcodes && !exists($allcodes{$CODE})
5209: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 5210: &scantron_get_correction($r,$i,$scan_record,
5211: \%scantron_config,
1.194 albertel 5212: $line,'incorrectCODE',\%allcodes);
5213: return(1,$currentphase);
1.186 albertel 5214: }
1.214 albertel 5215: if (exists($usedCODEs{$CODE})
1.257 albertel 5216: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 5217: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 5218: &scantron_get_correction($r,$i,$scan_record,
5219: \%scantron_config,
1.194 albertel 5220: $line,'duplicateCODE',$usedCODEs{$CODE});
5221: return(1,$currentphase);
1.186 albertel 5222: }
1.194 albertel 5223: push (@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 5224: }
1.157 albertel 5225: return (0,$currentphase+1);
5226: }
5227:
5228: sub scantron_validate_doublebubble {
5229: my ($r,$currentphase) = @_;
5230: #get student info
5231: my $classlist=&Apache::loncoursedata::get_classlist();
5232: my %idmap=&username_to_idmap($classlist);
5233:
5234: #get scantron line setup
1.257 albertel 5235: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5236: my ($scanlines,$scan_data)=&scantron_getfile();
5237: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5238: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5239: if ($line=~/^[\s\cz]*$/) { next; }
5240: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5241: $scan_data);
5242: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
5243: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
5244: 'doublebubble',
5245: $$scan_record{'scantron.doubleerror'});
5246: return (1,$currentphase);
5247: }
5248: return (0,$currentphase+1);
5249: }
5250:
1.191 albertel 5251: sub scantron_get_maxbubble {
5252: my ($r)=@_;
1.257 albertel 5253: if (defined($env{'form.scantron_maxbubble'}) &&
5254: $env{'form.scantron_maxbubble'}) {
5255: return $env{'form.scantron_maxbubble'};
1.191 albertel 5256: }
5257: my $navmap=Apache::lonnavmaps::navmap->new();
5258: my (undef,undef,$sequence)=
1.257 albertel 5259: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.191 albertel 5260: my $map=$navmap->getResourceByUrl($sequence);
5261: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
5262: &Apache::lonnet::delenv('form.counter');
5263: foreach my $resource (@resources) {
1.234 albertel 5264: my $result=&Apache::lonnet::ssi($resource->src().'?symb='.&Apache::lonnet::escape($resource->symb()));
1.191 albertel 5265: }
5266: &Apache::lonnet::delenv('scantron\.');
1.257 albertel 5267: my $envfile=$env{'user.environment'};
1.191 albertel 5268: $envfile=~/\/([^\/]+)\.id$/;
5269: $envfile=$1;
5270: &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
5271: $envfile);
1.257 albertel 5272: $env{'form.scantron_maxbubble'}=$env{'form.counter'}-1;
5273: return $env{'form.scantron_maxbubble'};
1.191 albertel 5274: }
5275:
1.157 albertel 5276: sub scantron_validate_missingbubbles {
5277: my ($r,$currentphase) = @_;
5278: #get student info
5279: my $classlist=&Apache::loncoursedata::get_classlist();
5280: my %idmap=&username_to_idmap($classlist);
5281:
5282: #get scantron line setup
1.257 albertel 5283: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5284: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 5285: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 5286: if (!$max_bubble) { $max_bubble=2**31; }
5287: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5288: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5289: if ($line=~/^[\s\cz]*$/) { next; }
5290: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5291: $scan_data);
5292: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
5293: my @to_correct;
5294: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
5295: if ($missing > $max_bubble) { next; }
5296: push(@to_correct,$missing);
5297: }
5298: if (@to_correct) {
5299: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5300: $line,'missingbubble',\@to_correct);
5301: return (1,$currentphase);
5302: }
5303:
5304: }
5305: return (0,$currentphase+1);
5306: }
5307:
1.82 albertel 5308: sub scantron_process_students {
1.75 albertel 5309: my ($r) = @_;
1.257 albertel 5310: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.81 albertel 5311: my ($symb,$url)=&get_symb_and_url($r);
5312: if (!$symb) {return '';}
5313: my $default_form_data=&defaultFormData($symb,$url);
1.82 albertel 5314:
1.257 albertel 5315: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5316: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 5317: my $classlist=&Apache::loncoursedata::get_classlist();
5318: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 5319: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 5320: my $map=$navmap->getResourceByUrl($sequence);
5321: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 5322: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 5323: my $result= <<SCANTRONFORM;
1.81 albertel 5324: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
5325: <input type="hidden" name="command" value="scantron_configphase" />
5326: $default_form_data
5327: SCANTRONFORM
1.82 albertel 5328: $r->print($result);
5329:
5330: my @delayqueue;
1.140 albertel 5331: my %completedstudents;
5332:
1.200 albertel 5333: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 5334: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 5335: 'Scantron Progress',$count,
1.195 albertel 5336: 'inline',undef,'scantronupload');
1.140 albertel 5337: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
5338: 'Processing first student');
5339: my $start=&Time::HiRes::time();
1.158 albertel 5340: my $i=-1;
1.200 albertel 5341: my ($uname,$udom,$started);
1.157 albertel 5342: while ($i<$scanlines->{'count'}) {
5343: ($uname,$udom)=('','');
5344: $i++;
1.200 albertel 5345: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5346: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 5347: if ($started) {
5348: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
5349: 'last student');
5350: }
5351: $started=1;
1.157 albertel 5352: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5353: $scan_data);
5354: unless ($uname=&scantron_find_student($scan_record,$scan_data,
5355: \%idmap,$i)) {
5356: &scantron_add_delay(\@delayqueue,$line,
5357: 'Unable to find a student that matches',1);
5358: next;
5359: }
5360: if (exists $completedstudents{$uname}) {
5361: &scantron_add_delay(\@delayqueue,$line,
5362: 'Student '.$uname.' has multiple sheets',2);
5363: next;
5364: }
5365: ($uname,$udom)=split(/:/,$uname);
5366: &Apache::lonnet::delenv('form.counter');
5367: &Apache::lonnet::appenv(%$scan_record);
1.161 albertel 5368:
5369: my $i=0;
1.83 albertel 5370: foreach my $resource (@resources) {
1.85 albertel 5371: $i++;
1.193 albertel 5372: my %form=('submitted' =>'scantron',
5373: 'grade_target' =>'grade',
5374: 'grade_username'=>$uname,
5375: 'grade_domain' =>$udom,
1.257 albertel 5376: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 5377: 'grade_symb' =>$resource->symb());
5378: if (exists($scan_record->{'scantron.CODE'}) &&
5379: $scan_record->{'scantron.CODE'}) {
5380: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 5381: } else {
5382: $form{'CODE'}='';
1.193 albertel 5383: }
5384: my $result=&Apache::lonnet::ssi($resource->src(),%form);
1.227 albertel 5385: if ($result ne '') {
5386: &Apache::lonnet::logthis("scantron grading error -> $result");
1.257 albertel 5387: &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src());
1.227 albertel 5388: }
1.213 albertel 5389: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 5390: }
1.140 albertel 5391: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 5392: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 5393: } continue {
1.85 albertel 5394: &Apache::lonnet::delenv('form.counter');
1.83 albertel 5395: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 5396: }
1.140 albertel 5397: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.172 albertel 5398: # my $lasttime = &Time::HiRes::time()-$start;
5399: # $r->print("<p>took $lasttime</p>");
1.140 albertel 5400:
1.200 albertel 5401: $r->print("</form>");
1.157 albertel 5402: $r->print(&show_grading_menu_form($symb,$url));
5403: return '';
1.75 albertel 5404: }
1.157 albertel 5405:
5406: sub scantron_upload_scantron_data {
5407: my ($r)=@_;
1.257 albertel 5408: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 5409: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 5410: 'domainid',
5411: 'coursename');
1.257 albertel 5412: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 5413: 'domainid');
1.173 albertel 5414: my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
1.157 albertel 5415: $r->print(<<UPLOAD);
5416: <script type="text/javascript" language="javascript">
5417: function checkUpload(formname) {
5418: if (formname.upfile.value == "") {
5419: alert("Please use the browse button to select a file from your local directory.");
5420: return false;
5421: }
5422: formname.submit();
5423: }
5424: </script>
5425:
5426: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
1.162 albertel 5427: $default_form_data
1.181 albertel 5428: <table>
5429: <tr><td>$select_link </td></tr>
5430: <tr><td>Course ID: </td><td><input name='courseid' type='text' /> </td></tr>
5431: <tr><td>Course Name: </td><td><input name='coursename' type='text' /></td></tr>
5432: <tr><td>Domain: </td><td>$domsel </td></tr>
5433: <tr><td>File to upload:</td><td><input type="file" name="upfile" size="50" /></td></tr>
5434: </table>
1.157 albertel 5435: <input name='command' value='scantronupload_save' type='hidden' />
5436: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
5437: </form>
5438: UPLOAD
5439: return '';
5440: }
5441:
5442: sub scantron_upload_scantron_data_save {
5443: my($r)=@_;
1.182 albertel 5444: my ($symb,$url)=&get_symb_and_url($r,1);
5445: my $doanotherupload=
5446: '<br /><form action="/adm/grades" method="post">'."\n".
5447: '<input type="hidden" name="command" value="scantronupload" />'."\n".
5448: '<input type="submit" name="submit" value="Do Another Upload" />'."\n".
5449: '</form>'."\n";
1.257 albertel 5450: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 5451: !&Apache::lonnet::allowed('usc',
1.257 albertel 5452: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.162 albertel 5453: $r->print("You are not allowed to upload Scantron data to the requested course.<br />");
1.182 albertel 5454: if ($symb) {
5455: $r->print(&show_grading_menu_form($symb,$url));
5456: } else {
5457: $r->print($doanotherupload);
5458: }
1.162 albertel 5459: return '';
5460: }
1.257 albertel 5461: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.211 ng 5462: $r->print("Doing upload to ".$coursedata{'description'}." <br />");
1.257 albertel 5463: my $fname=$env{'form.upfile.filename'};
1.157 albertel 5464: #FIXME
5465: #copied from lonnet::userfileupload()
5466: #make that function able to target a specified course
5467: # Replace Windows backslashes by forward slashes
5468: $fname=~s/\\/\//g;
5469: # Get rid of everything but the actual filename
5470: $fname=~s/^.*\/([^\/]+)$/$1/;
5471: # Replace spaces by underscores
5472: $fname=~s/\s+/\_/g;
5473: # Replace all other weird characters by nothing
5474: $fname=~s/[^\w\.\-]//g;
5475: # See if there is anything left
5476: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 5477: my $uploadedfile=$fname;
1.157 albertel 5478: $fname='scantron_orig_'.$fname;
1.257 albertel 5479: if (length($env{'form.upfile'}) < 2) {
5480: $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 5481: } else {
1.275 albertel 5482: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 5483: if ($result =~ m|^/uploaded/|) {
1.257 albertel 5484: $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 5485: } else {
1.257 albertel 5486: $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 5487: }
5488: }
1.174 albertel 5489: if ($symb) {
1.209 ng 5490: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 5491: } else {
1.182 albertel 5492: $r->print($doanotherupload);
1.174 albertel 5493: }
1.157 albertel 5494: return '';
5495: }
5496:
1.202 albertel 5497: sub valid_file {
5498: my ($requested_file)=@_;
5499: foreach my $filename (sort(&scantron_filenames())) {
5500: &Apache::lonnet::logthis("$requested_file $filename");
5501: if ($requested_file eq $filename) { return 1; }
5502: }
5503: return 0;
5504: }
5505:
5506: sub scantron_download_scantron_data {
5507: my ($r)=@_;
5508: my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
1.257 albertel 5509: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5510: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5511: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 5512: if (! &valid_file($file)) {
5513: $r->print(<<ERROR);
5514: <p>
5515: The requested file name was invalid.
5516: </p>
5517: ERROR
5518: $r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
5519: return;
5520: }
5521: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
5522: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
5523: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
5524: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
5525: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
5526: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
5527: $r->print(<<DOWNLOAD);
5528: <p>
5529: <a href="$orig">Original</a> file as uploaded by the scantron office.
5530: </p>
5531: <p>
5532: <a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
5533: </p>
5534: <p>
5535: <a href="$skipped">Skipped</a>, a file of records that were skipped.
5536: </p>
5537: DOWNLOAD
5538: $r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
5539: return '';
5540: }
1.157 albertel 5541:
1.75 albertel 5542: #-------- end of section for handling grading scantron forms -------
5543: #
5544: #-------------------------------------------------------------------
5545:
1.72 ng 5546: #-------------------------- Menu interface -------------------------
5547: #
5548: #--- Show a Grading Menu button - Calls the next routine ---
5549: sub show_grading_menu_form {
5550: my ($symb,$url)=@_;
1.125 ng 5551: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.72 ng 5552: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
5553: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.257 albertel 5554: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 5555: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
5556: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
5557: '</form>'."\n";
5558: return $result;
5559: }
5560:
1.77 ng 5561: # -- Retrieve choices for grading form
5562: sub savedState {
5563: my %savedState = ();
1.257 albertel 5564: if ($env{'form.saveState'}) {
5565: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 5566: my ($key,$value) = split(/=/,$_,2);
5567: $savedState{$key} = $value;
5568: }
5569: }
5570: return \%savedState;
5571: }
1.76 ng 5572:
1.72 ng 5573: #--- Displays the main menu page -------
5574: sub gradingmenu {
5575: my ($request) = @_;
5576: my ($symb,$url)=&get_symb_and_url($request);
5577: if (!$symb) {return '';}
1.76 ng 5578: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 5579:
5580: $request->print(<<GRADINGMENUJS);
5581: <script type="text/javascript" language="javascript">
1.116 ng 5582: function checkChoice(formname,val,cmdx) {
5583: if (val <= 2) {
5584: var cmd = radioSelection(formname.radioChoice);
1.118 ng 5585: var cmdsave = cmd;
1.116 ng 5586: } else {
5587: cmd = cmdx;
1.118 ng 5588: cmdsave = 'submission';
1.116 ng 5589: }
5590: formname.command.value = cmd;
1.118 ng 5591: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 5592: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 5593: if (val < 5) formname.submit();
5594: if (val == 5) {
1.72 ng 5595: if (!checkReceiptNo(formname,'notOK')) { return false;}
5596: formname.submit();
5597: }
1.238 albertel 5598: if (val < 7) formname.submit();
1.72 ng 5599: }
5600:
5601: function checkReceiptNo(formname,nospace) {
5602: var receiptNo = formname.receipt.value;
5603: var checkOpt = false;
5604: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
5605: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
5606: if (checkOpt) {
5607: alert("Please enter a receipt number given by a student in the receipt box.");
5608: formname.receipt.value = "";
5609: formname.receipt.focus();
5610: return false;
5611: }
5612: return true;
5613: }
5614: </script>
5615: GRADINGMENUJS
1.118 ng 5616: &commonJSfunctions($request);
5617: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>';
1.122 ng 5618: my ($table,undef,$hdgrade) = &showResourceInfo($url,$probTitle);
1.118 ng 5619: $result.=$table;
1.76 ng 5620: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 5621: my $savedState = &savedState();
1.118 ng 5622: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 5623: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 5624: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 5625: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 5626:
5627: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
5628: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
5629: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
5630: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
5631: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 5632: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 5633: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 5634: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 5635: '<input type="hidden" name="showgrading" value="yes" />'."\n";
5636:
1.116 ng 5637: $result.='<table width="100%" border=0><tr><td bgcolor=#777777>'."\n".
5638: '<table width=100% border=0><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 5639: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 5640: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
5641:
5642: $result.='<table width="100%" border=0>';
5643: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.167 sakharuk 5644: ' '.&mt('Select Section').': <select name="section">'."\n";
1.116 ng 5645: if (ref($sections)) {
1.155 albertel 5646: foreach (sort (@$sections)) {
5647: $result.='<option value="'.$_.'" '.
5648: ($saveSec eq $_ ? 'selected="on"':'').'>'.$_.'</option>'."\n";
5649: }
1.116 ng 5650: }
1.238 albertel 5651: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</option></select> ';
1.116 ng 5652:
1.167 sakharuk 5653: $result.=&mt('Student Status').':</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 5654:
1.116 ng 5655: $result.='</td></tr>';
5656:
1.288 albertel 5657: $result.='<tr bgcolor="#ffffe6"valign="top"><td><label>'.
1.118 ng 5658: '<input type="radio" name="radioChoice" value="submission" '.
1.167 sakharuk 5659: ($saveCmd eq 'submission' ? 'checked' : '').'> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
1.288 albertel 5660: '</label> <select name="submitonly">'.
1.145 albertel 5661: '<option value="yes" '.
1.301 albertel 5662: ($saveSub eq 'yes' ? 'selected="on"' : '').'>'.&mt('with submissions').'</option>'.
5663: '<option value="queued" '.
5664: ($saveSub eq 'queued' ? 'selected="on"' : '').'>'.&mt('in grading queue').'</option>'.
1.145 albertel 5665: '<option value="graded" '.
1.301 albertel 5666: ($saveSub eq 'graded' ? 'selected="on"' : '').'>'.&mt('with ungraded submissions').'</option>'.
1.156 albertel 5667: '<option value="incorrect" '.
1.301 albertel 5668: ($saveSub eq 'incorrect' ? 'selected="on"' : '').'>'.&mt('with incorrect submissions').'</option>'.
1.145 albertel 5669: '<option value="all" '.
1.301 albertel 5670: ($saveSub eq 'all' ? 'selected="on"' : '').'>'.&mt('with any status').'</option></select></td></tr>'."\n";
1.72 ng 5671:
1.116 ng 5672: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.288 albertel 5673: '<label><input type="radio" name="radioChoice" value="viewgrades" '.
1.76 ng 5674: ($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
1.288 albertel 5675: '<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
1.72 ng 5676:
1.118 ng 5677: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
1.288 albertel 5678: '<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
1.118 ng 5679: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
1.288 albertel 5680: 'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
1.46 ng 5681:
1.116 ng 5682: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 5683: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 5684: '</td></tr></table>'."\n";
5685:
5686: $result.='</td><td valign="top">';
5687:
5688: $result.='<table width="100%" border=0>';
5689: $result.='<tr bgcolor="#ffffe6"><td>'.
1.184 www 5690: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
5691: ' '.&mt('scores from file').' </td></tr>'."\n";
1.72 ng 5692:
1.75 albertel 5693: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 5694: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
1.184 www 5695: '" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
1.75 albertel 5696:
1.257 albertel 5697: if ((&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && ($symb)) {
1.72 ng 5698: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.184 www 5699: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
5700: ' '.&mt('receipt').': '.
1.257 albertel 5701: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.72 ng 5702: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
5703: '</td></tr>'."\n";
5704: }
1.238 albertel 5705: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5706: '<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
5707: '" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
1.279 albertel 5708: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5709: '<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
5710: '" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
1.44 ng 5711:
1.116 ng 5712: $result.='</form></td></tr></table>'."\n".
1.72 ng 5713: '</td></tr></table>'."\n".
5714: '</td></tr></table>'."\n";
1.44 ng 5715: return $result;
1.2 albertel 5716: }
5717:
1.285 albertel 5718: sub reset_perm {
5719: undef(%perm);
5720: }
5721:
5722: sub init_perm {
5723: &reset_perm();
1.300 albertel 5724: foreach my $test_perm ('vgr','mgr','opa') {
5725:
5726: my $scope = $env{'request.course.id'};
5727: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
5728:
5729: $scope .= '/'.$env{'request.course.sec'};
5730: if ( $perm{$test_perm}=
5731: &Apache::lonnet::allowed($test_perm,$scope)) {
5732: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
5733: } else {
5734: delete($perm{$test_perm});
5735: }
1.285 albertel 5736: }
5737: }
5738: }
5739:
1.1 albertel 5740: sub handler {
1.41 ng 5741: my $request=$_[0];
1.102 albertel 5742:
1.285 albertel 5743: &reset_perm();
1.257 albertel 5744: if ($env{'browser.mathml'}) {
1.141 www 5745: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 5746: } else {
1.141 www 5747: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 5748: }
5749: $request->send_http_header;
1.44 ng 5750: return '' if $request->header_only;
1.41 ng 5751: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.257 albertel 5752: my $url=$env{'form.url'};
5753: my $symb=$env{'form.symb'};
1.160 albertel 5754: my @commands=&Apache::loncommon::get_env_multiple('form.command');
5755: my $command=$commands[0];
5756: if ($#commands > 0) {
5757: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
5758: }
1.41 ng 5759: if (!$url) {
5760: my ($temp1,$temp2);
1.257 albertel 5761: ($temp1,$temp2,$env{'form.url'})=&Apache::lonnet::decode_symb($symb);
5762: $url = $env{'form.url'};
1.41 ng 5763: }
5764: &send_header($request);
1.157 albertel 5765: if ($url eq '' && $symb eq '' && $command eq '') {
1.257 albertel 5766: if ($env{'user.adv'}) {
5767: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
5768: ($env{'form.codethree'})) {
5769: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
5770: $env{'form.codethree'};
1.41 ng 5771: my ($tsymb,$tuname,$tudom,$tcrsid)=
5772: &Apache::lonnet::checkin($token);
5773: if ($tsymb) {
1.137 albertel 5774: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 5775: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 5776: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
5777: ('grade_username' => $tuname,
5778: 'grade_domain' => $tudom,
5779: 'grade_courseid' => $tcrsid,
5780: 'grade_symb' => $tsymb)));
1.41 ng 5781: } else {
1.45 ng 5782: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 5783: }
1.41 ng 5784: } else {
1.45 ng 5785: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 5786: }
1.14 www 5787: } else {
1.41 ng 5788: $request->print(&Apache::lonxml::tokeninputfield());
5789: }
5790: }
5791: } else {
1.285 albertel 5792: &init_perm();
1.104 albertel 5793: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 5794: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 5795: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 5796: &pickStudentPage($request);
1.103 albertel 5797: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 5798: &displayPage($request);
1.104 albertel 5799: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 5800: &updateGradeByPage($request);
1.104 albertel 5801: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 5802: &processGroup($request);
1.104 albertel 5803: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 5804: $request->print(&gradingmenu($request));
1.104 albertel 5805: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 5806: $request->print(&viewgrades($request));
1.104 albertel 5807: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 5808: $request->print(&processHandGrade($request));
1.106 albertel 5809: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 5810: $request->print(&editgrades($request));
1.106 albertel 5811: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 5812: $request->print(&verifyreceipt($request));
1.106 albertel 5813: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 5814: $request->print(&upcsvScores_form($request));
1.106 albertel 5815: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 5816: $request->print(&csvupload($request));
1.106 albertel 5817: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 5818: $request->print(&csvuploadmap($request));
1.246 albertel 5819: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 5820: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 5821: $request->print(&csvuploadoptions($request));
1.41 ng 5822: } else {
1.257 albertel 5823: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
5824: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 5825: } else {
1.257 albertel 5826: $env{'form.upfile_associate'} = 'forward';
1.41 ng 5827: }
5828: $request->print(&csvuploadmap($request));
5829: }
1.246 albertel 5830: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
5831: $request->print(&csvuploadassign($request));
1.106 albertel 5832: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 5833: $request->print(&scantron_selectphase($request));
1.203 albertel 5834: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
5835: $request->print(&scantron_do_warning($request));
1.142 albertel 5836: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
5837: $request->print(&scantron_validate_file($request));
1.106 albertel 5838: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 5839: $request->print(&scantron_process_students($request));
1.157 albertel 5840: } elsif ($command eq 'scantronupload' &&
1.257 albertel 5841: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
5842: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 5843: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 5844: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 5845: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
5846: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 5847: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 5848: } elsif ($command eq 'scantron_download' &&
1.257 albertel 5849: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 5850: $request->print(&scantron_download_scantron_data($request));
1.106 albertel 5851: } elsif ($command) {
1.157 albertel 5852: $request->print("Access Denied ($command)");
1.26 albertel 5853: }
1.2 albertel 5854: }
1.41 ng 5855: &send_footer($request);
1.44 ng 5856: return '';
5857: }
5858:
5859: sub send_header {
5860: my ($request)= @_;
5861: $request->print(&Apache::lontexconvert::header());
5862: # $request->print("
5863: #<script>
5864: #remotewindow=open('','homeworkremote');
5865: #remotewindow.close();
5866: #</script>");
1.47 www 5867: $request->print(&Apache::loncommon::bodytag('Grading'));
1.157 albertel 5868: $request->rflush();
1.44 ng 5869: }
5870:
5871: sub send_footer {
5872: my ($request)= @_;
1.212 albertel 5873: $request->print('</body></html>');
1.1 albertel 5874: }
5875:
5876: 1;
5877:
1.13 albertel 5878: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>