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