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