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