Annotation of loncom/homework/grades.pm, revision 1.149
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.149 ! albertel 4: # $Id: grades.pm,v 1.148 2003/11/07 08:56:52 albertel Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.13 albertel 28: # 2/9,2/13 Guy Albertelli
1.8 www 29: # 6/8 Gerd Kortemeyer
1.13 albertel 30: # 7/26 H.K. Ng
1.14 www 31: # 8/20 Gerd Kortemeyer
1.30 ng 32: # Year 2002
1.44 ng 33: # June-August H.K. Ng
1.68 ng 34: # Year 2003
1.71 ng 35: # February, March H.K. Ng
1.125 ng 36: # July, H. K. Ng
1.30 ng 37: #
1.1 albertel 38:
39: package Apache::grades;
40: use strict;
41: use Apache::style;
42: use Apache::lonxml;
43: use Apache::lonnet;
1.3 albertel 44: use Apache::loncommon;
1.112 ng 45: use Apache::lonhtmlcommon;
1.68 ng 46: use Apache::lonnavmaps;
1.1 albertel 47: use Apache::lonhomework;
1.55 matthew 48: use Apache::loncoursedata;
1.38 ng 49: use Apache::lonmsg qw(:user_normal_msg);
1.1 albertel 50: use Apache::Constants qw(:common);
1.87 www 51: use String::Similarity;
52:
53: my %oldessays=();
1.103 albertel 54: my %perm=();
1.1 albertel 55:
1.68 ng 56: # ----- These first few routines are general use routines.----
1.44 ng 57: #
1.146 albertel 58: # --- Retrieve the parts from the metadata file.---
1.44 ng 59: sub getpartlist {
1.146 albertel 60: my ($url,$symb) = @_;
61: my $partorder = &Apache::lonnet::metadata($url, 'partorder');
62: my @parts;
63: if ($partorder) {
64: for my $part (split (/,/,$partorder)) {
65: if (!&Apache::loncommon::check_if_partid_hidden($part,$symb)) {
66: push(@parts, $part);
67: }
68: }
69: } else {
70: my $metadata = &Apache::lonnet::metadata($url, 'packages');
71: foreach (split(/\,/,$metadata)) {
72: if ($_ =~ /^part_(.*)$/) {
73: if (!&Apache::loncommon::check_if_partid_hidden($1,$symb)) {
74: push(@parts, $1);
75: }
76: }
1.41 ng 77: }
1.16 albertel 78: }
1.146 albertel 79: my @stores;
80: foreach my $part (@parts) {
81: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
82: foreach my $key (@metakeys) {
83: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
84: }
85: }
86: return @stores;
1.2 albertel 87: }
88:
1.44 ng 89: # --- Get the symbolic name of a problem and the url
90: sub get_symb_and_url {
91: my ($request) = @_;
92: (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.41 ng 93: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.44 ng 94: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
95: return ($symb,$url);
1.32 ng 96: }
97:
1.44 ng 98: # --- Retrieve the fullname for a user. Return lastname, first middle ---
99: # --- Generation is attached next to the lastname if it exists. ---
1.34 ng 100: sub get_fullname {
1.39 ng 101: my ($uname,$udom) = @_;
1.34 ng 102: my %name=&Apache::lonnet::get('environment', ['lastname','generation',
1.55 matthew 103: 'firstname','middlename'],
104: $udom,$uname);
1.34 ng 105: my $fullname;
106: my ($tmp) = keys(%name);
107: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
1.55 matthew 108: $fullname = &Apache::loncoursedata::ProcessFullName
109: (@name{qw/lastname generation firstname middlename/});
110: } else {
111: &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
112: '@'.$udom.':'.$tmp);
1.34 ng 113: }
114: return $fullname;
115: }
116:
1.129 ng 117: #--- Format fullname, username:domain if different for display
118: #--- Use anywhere where the student names are listed
119: sub nameUserString {
120: my ($type,$fullname,$uname,$udom) = @_;
121: if ($type eq 'header') {
122: return '<b> Fullname </b><font color="#999999">(Username)</font> ';
123: } else {
124: return ' '.$fullname.'<font color="#999999"> ('.$uname.
125: ($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</font>';
126: }
127: }
128:
1.44 ng 129: #--- Get the partlist and the response type for a given problem. ---
130: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 131: sub response_type {
1.125 ng 132: my ($url,$symb) = shift;
133: $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq '');
1.41 ng 134: my $allkeys = &Apache::lonnet::metadata($url,'keys');
135: my %seen = ();
1.147 albertel 136: my (@partlist,%handgrade,%responseType);
1.41 ng 137: foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
1.147 albertel 138: if (/^\w+response_.*/) {
1.41 ng 139: my ($responsetype,$part) = split(/_/,$_,2);
140: my ($partid,$respid) = split(/_/,$part);
1.146 albertel 141: if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) {
142: next;
143: }
1.118 ng 144: $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
1.127 ng 145: my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
1.147 albertel 146: $handgrade{$part} = ($value eq 'yes' ? 'yes' : 'no');
147: if (!exists($responseType{$partid})) { $responseType{$partid}={}; }
148: $responseType{$partid}->{$respid}=$responsetype;
1.41 ng 149: next if ($seen{$partid} > 0);
150: $seen{$partid}++;
151: push @partlist,$partid;
152: }
153: }
1.147 albertel 154: return \@partlist,\%handgrade,\%responseType;
1.39 ng 155: }
156:
1.118 ng 157: #--- Show resource title
158: #--- and parts and response type
159: sub showResourceInfo {
160: my ($url,$probTitle) = @_;
161: my $result ='<table border="0">'.
162: '<tr><td colspan=3><font size=+1><b>Current Resource: </b>'.$probTitle.'</font></td></tr>'."\n";
1.147 albertel 163: my ($partlist,$handgrade,$responseType) = &response_type($url);
1.126 ng 164: my %resptype = ();
1.122 ng 165: my $hdgrade='no';
1.147 albertel 166: for my $part_resID (sort keys(%$handgrade)) {
167: my $handgrade=$$handgrade{$part_resID};
168: my ($partID,$resID) = split(/_/,$part_resID);
169: my $responsetype = $responseType->{$partID}->{$resID};
1.118 ng 170: $hdgrade = $handgrade if ($handgrade eq 'yes');
1.147 albertel 171: $result.='<tr><td><b>Part </b>'.$partID.' <font color="#999999">'.
172: $resID.'</font></td>'.
1.118 ng 173: '<td><b>Type: </b>'.$responsetype.'</td></tr>';
174: # '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>';
175: }
176: $result.='</table>'."\n";
1.147 albertel 177: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 178: }
179:
1.148 albertel 180:
181: sub get_order {
182: my ($partid,$respid,$symb,$uname,$udom)=@_;
183: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
184: $url=&Apache::lonnet::clutter($url);
185: my $subresult=&Apache::lonnet::ssi($url,
186: ('grade_target' => 'analyze'),
187: ('grade_domain' => $udom),
188: ('grade_symb' => $symb),
189: ('grade_courseid' =>
190: $ENV{'request.course.id'}),
191: ('grade_username' => $uname));
1.149 ! albertel 192: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
1.148 albertel 193: my %analyze=&Apache::lonnet::str2hash($subresult);
194: return ($analyze{"$partid.$respid.shown"});
195: }
1.118 ng 196: #--- Clean response type for display
1.148 albertel 197: #--- Currently filters option/rank/radiobutton/match/essay response types only.
1.118 ng 198: sub cleanRecord {
1.148 albertel 199: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version) = @_;
200: my $grayFont = '<font color="#999999">';
201: if ($response =~ /^(option|rank)$/) {
202: my %answer=&Apache::lonnet::str2hash($answer);
203: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
204: my ($toprow,$bottomrow);
205: foreach my $foil (@$order) {
206: if ($grading{$foil} == 1) {
207: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
208: } else {
209: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
210: }
211: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
212: }
213: return '<blockquote><table border="1">'.
214: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
215: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
216: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
217: } elsif ($response eq 'match') {
218: my %answer=&Apache::lonnet::str2hash($answer);
219: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
220: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
221: my ($toprow,$middlerow,$bottomrow);
222: foreach my $foil (@$order) {
223: my $item=shift(@items);
224: if ($grading{$foil} == 1) {
225: $toprow.='<td><b>'.$item.' </b></td>';
226: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </font></b></td>';
227: } else {
228: $toprow.='<td><i>'.$item.' </i></td>';
229: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </font></i></td>';
230: }
231: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
1.118 ng 232: }
1.126 ng 233: return '<blockquote><table border="1">'.
1.148 albertel 234: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
235: '<tr valign="top"><td>'.$grayFont.'Item ID</font></td>'.
236: $middlerow.'</tr>'.
237: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
238: $bottomrow.'</tr>'.'</table></blockquote>';
239: } elsif ($response eq 'radiobutton') {
240: my %answer=&Apache::lonnet::str2hash($answer);
241: my ($toprow,$bottomrow);
242: my $correct=($order->[0])+1;
243: for (my $i=1;$i<=$#$order;$i++) {
244: my $foil=$order->[$i];
245: if (exists($answer{$foil})) {
246: if ($i == $correct) {
247: $toprow.='<td><b>true</b></td>';
248: } else {
249: $toprow.='<td><i>true</i></td>';
250: }
251: } else {
252: $toprow.='<td>false</td>';
253: }
254: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
255: }
256: return '<blockquote><table border="1">'.
257: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
258: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
259: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
260: } elsif ($response eq 'essay') {
1.122 ng 261: if (! exists ($ENV{'form.'.$symb})) {
262: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
263: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
264: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
265:
266: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
267: $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
268: $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
269: $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
270: $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
271: $ENV{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
272: }
1.143 albertel 273: return '<br /><br /><blockquote><pre>'.&keywords_highlight($answer).'</pre></blockquote>';
1.122 ng 274: }
1.118 ng 275: return $answer;
276: }
277:
278: #-- A couple of common js functions
279: sub commonJSfunctions {
280: my $request = shift;
281: $request->print(<<COMMONJSFUNCTIONS);
282: <script type="text/javascript" language="javascript">
283: function radioSelection(radioButton) {
284: var selection=null;
285: if (radioButton.length > 1) {
286: for (var i=0; i<radioButton.length; i++) {
287: if (radioButton[i].checked) {
288: return radioButton[i].value;
289: }
290: }
291: } else {
292: if (radioButton.checked) return radioButton.value;
293: }
294: return selection;
295: }
296:
297: function pullDownSelection(selectOne) {
298: var selection="";
299: if (selectOne.length > 1) {
300: for (var i=0; i<selectOne.length; i++) {
301: if (selectOne[i].selected) {
302: return selectOne[i].value;
303: }
304: }
305: } else {
1.138 albertel 306: // only one value it must be the selected one
307: return selectOne.value;
1.118 ng 308: }
309: }
310: </script>
311: COMMONJSFUNCTIONS
312: }
313:
1.44 ng 314: #--- Dumps the class list with usernames,list of sections,
315: #--- section, ids and fullnames for each user.
316: sub getclasslist {
1.76 ng 317: my ($getsec,$filterlist) = @_;
1.121 ng 318: $getsec = $getsec eq '' ? 'all' : $getsec;
1.56 matthew 319: my $classlist=&Apache::loncoursedata::get_classlist();
1.49 albertel 320: # Bail out if we were unable to get the classlist
1.56 matthew 321: return if (! defined($classlist));
322: #
323: my %sections;
324: my %fullnames;
325: foreach (keys(%$classlist)) {
326: # the following undefs are for 'domain', and 'username' respectively.
327: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
328: @{$classlist->{$_}};
1.76 ng 329: # filter students according to status selected
1.112 ng 330: if ($filterlist && $ENV{'form.Status'} ne 'Any') {
331: if ($ENV{'form.Status'} ne $status) {
1.76 ng 332: delete ($classlist->{$_});
333: next;
334: }
335: }
1.44 ng 336: $section = ($section ne '' ? $section : 'no');
1.106 albertel 337: if (&canview($section)) {
1.103 albertel 338: if ($getsec eq 'all' || $getsec eq $section) {
339: $sections{$section}++;
340: $fullnames{$_}=$fullname;
341: } else {
342: delete($classlist->{$_});
343: }
344: } else {
345: delete($classlist->{$_});
346: }
1.44 ng 347: }
348: my %seen = ();
1.56 matthew 349: my @sections = sort(keys(%sections));
350: return ($classlist,\@sections,\%fullnames);
1.44 ng 351: }
352:
1.103 albertel 353: sub canmodify {
354: my ($sec)=@_;
355: if ($perm{'mgr'}) {
356: if (!defined($perm{'mgr_section'})) {
357: # can modify whole class
358: return 1;
359: } else {
360: if ($sec eq $perm{'mgr_section'}) {
361: #can modify the requested section
362: return 1;
363: } else {
364: # can't modify the request section
365: return 0;
366: }
367: }
368: }
369: #can't modify
370: return 0;
371: }
372:
373: sub canview {
374: my ($sec)=@_;
375: if ($perm{'vgr'}) {
376: if (!defined($perm{'vgr_section'})) {
377: # can modify whole class
378: return 1;
379: } else {
380: if ($sec eq $perm{'vgr_section'}) {
381: #can modify the requested section
382: return 1;
383: } else {
384: # can't modify the request section
385: return 0;
386: }
387: }
388: }
389: #can't modify
390: return 0;
391: }
392:
1.44 ng 393: #--- Retrieve the grade status of a student for all the parts
394: sub student_gradeStatus {
395: my ($url,$symb,$udom,$uname,$partlist) = @_;
396: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
397: my %partstatus = ();
398: foreach (@$partlist) {
1.128 ng 399: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 400: $status = 'nothing' if ($status eq '');
401: $partstatus{$_} = $status;
402: my $subkey = "resource.$_.submitted_by";
403: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
404: }
405: return %partstatus;
406: }
407:
1.45 ng 408: # hidden form and javascript that calls the form
409: # Use by verifyscript and viewgrades
410: # Shows a student's view of problem and submission
411: sub jscriptNform {
412: my ($url,$symb) = @_;
413: my $jscript='<script type="text/javascript" language="javascript">'."\n".
414: ' function viewOneStudent(user,domain) {'."\n".
415: ' document.onestudent.student.value = user;'."\n".
416: ' document.onestudent.userdom.value = domain;'."\n".
417: ' document.onestudent.submit();'."\n".
418: ' }'."\n".
419: '</script>'."\n";
420: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
421: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
422: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.77 ng 423: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 424: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.125 ng 425: '<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n".
1.45 ng 426: '<input type="hidden" name="command" value="submission" />'."\n".
427: '<input type="hidden" name="student" value="" />'."\n".
428: '<input type="hidden" name="userdom" value="" />'."\n".
429: '</form>'."\n";
430: return $jscript;
431: }
1.39 ng 432:
1.44 ng 433: #------------------ End of general use routines --------------------
1.87 www 434:
435: #
436: # Find most similar essay
437: #
438:
439: sub most_similar {
440: my ($uname,$udom,$uessay)=@_;
441:
442: # ignore spaces and punctuation
443:
444: $uessay=~s/\W+/ /gs;
445:
446: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 447: my $limit=0.6;
1.87 www 448: my $sname='';
449: my $sdom='';
450: my $scrsid='';
451: my $sessay='';
452: # go through all essays ...
453: foreach my $tkey (keys %oldessays) {
454: my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
455: # ... except the same student
1.88 www 456: if (($tname ne $uname) || ($tdom ne $udom)) {
1.87 www 457: my $tessay=$oldessays{$tkey};
458: $tessay=~s/\W+/ /gs;
459: # String similarity gives up if not even limit
1.88 www 460: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 461: # Found one
462: if ($tsimilar>$limit) {
463: $limit=$tsimilar;
464: $sname=$tname;
1.88 www 465: $sdom=$tdom;
1.87 www 466: $scrsid=$tcrsid;
467: $sessay=$oldessays{$tkey};
468: }
469: }
470: }
1.88 www 471: if ($limit>0.6) {
1.87 www 472: return ($sname,$sdom,$scrsid,$sessay,$limit);
473: } else {
474: return ('','','','',0);
475: }
476: }
477:
1.44 ng 478: #-------------------------------------------------------------------
479:
480: #------------------------------------ Receipt Verification Routines
1.45 ng 481: #
1.44 ng 482: #--- Check whether a receipt number is valid.---
483: sub verifyreceipt {
484: my $request = shift;
485:
486: my $courseid = $ENV{'request.course.id'};
487: my $receipt = unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
488: $ENV{'form.receipt'};
489: $receipt =~ s/[^\-\d]//g;
490: my $url = $ENV{'form.url'};
491: my $symb = $ENV{'form.symb'};
492: unless ($symb) {
493: $symb = &Apache::lonnet::symbread($url);
494: }
495:
1.45 ng 496: my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
497: $receipt.'</h3></font>'."\n".
1.118 ng 498: '<font size=+1><b>Resource: </b>'.$ENV{'form.probTitle'}.'</font><br><br>'."\n";
1.44 ng 499:
500: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 501: my (undef,undef,$fullname) = &getclasslist('all','0');
502:
1.53 albertel 503: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44 ng 504: my ($uname,$udom)=split(/\:/);
505: if ($receipt eq
506: &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
507: $contents.='<tr bgcolor="#ffffe6"><td> '."\n".
508: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
509: '\')"; TARGET=_self>'.$$fullname{$_}.'</a> </td>'."\n".
510: '<td> '.$uname.' </td>'.
511: '<td> '.$udom.' </td></tr>'."\n";
512:
513: $matches++;
514: }
515: }
516: if ($matches == 0) {
517: $string = $title.'No match found for the above receipt.';
518: } else {
1.45 ng 519: $string = &jscriptNform($url,$symb).$title.
1.44 ng 520: 'The above receipt matches the following student'.
521: ($matches <= 1 ? '.' : 's.')."\n".
522: '<table border="0"><tr><td bgcolor="#777777">'."\n".
523: '<table border="0"><tr bgcolor="#e6ffff">'."\n".
524: '<td><b> Fullname </b></td>'."\n".
525: '<td><b> Username </b></td>'."\n".
526: '<td><b> Domain </b></td></tr>'."\n".
527: $contents.
528: '</table></td></tr></table>'."\n";
529: }
1.50 albertel 530: return $string.&show_grading_menu_form($symb,$url);
1.44 ng 531: }
532:
533: #--- This is called by a number of programs.
534: #--- Called from the Grading Menu - View/Grade an individual student
535: #--- Also called directly when one clicks on the subm button
536: # on the problem page.
1.30 ng 537: sub listStudents {
1.41 ng 538: my ($request) = shift;
1.49 albertel 539:
1.72 ng 540: my ($symb,$url) = &get_symb_and_url($request);
1.49 albertel 541: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
542: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
543: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
544: my $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
545:
1.118 ng 546: my $viewgrade = $ENV{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.76 ng 547: $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
548: &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
1.49 albertel 549:
1.118 ng 550: my $result='<h3><font color="#339933"> '.$viewgrade.
551: ' Submissions for a Student or a Group of Students</font></h3>';
552:
1.122 ng 553: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
1.118 ng 554: $result.=$table;
1.49 albertel 555:
1.45 ng 556: $request->print(<<LISTJAVASCRIPT);
557: <script type="text/javascript" language="javascript">
1.110 ng 558: function checkSelect(checkBox) {
559: var ctr=0;
560: var sense="";
561: if (checkBox.length > 1) {
562: for (var i=0; i<checkBox.length; i++) {
563: if (checkBox[i].checked) {
564: ctr++;
565: }
566: }
567: sense = "a student or group of students";
568: } else {
569: if (checkBox.checked) {
570: ctr = 1;
571: }
572: sense = "the student";
573: }
574: if (ctr == 0) {
1.126 ng 575: alert("Please select "+sense+" before clicking on the Next button.");
1.110 ng 576: return false;
577: }
578: document.gradesub.submit();
579: }
580:
581: function reLoadList(formname) {
1.112 ng 582: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 583: formname.command.value = 'submission';
584: formname.submit();
585: }
1.45 ng 586: </script>
587: LISTJAVASCRIPT
588:
1.118 ng 589: &commonJSfunctions($request);
1.41 ng 590: $request->print($result);
1.39 ng 591:
1.118 ng 592: my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
1.119 ng 593: my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
1.45 ng 594: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
1.144 albertel 595: ' <b>View Problem Text: </b><input type="radio" name="vProb" value="no" checked="on" /> no '."\n".
1.80 ng 596: '<input type="radio" name="vProb" value="yes" /> one student '."\n".
1.58 albertel 597: '<input type="radio" name="vProb" value="all" /> all students <br />'."\n".
1.144 albertel 598: ' <b>View Answer: </b><input type="radio" name="vAns" value="no" /> no '."\n".
599: '<input type="radio" name="vAns" value="yes" /> one student '."\n".
600: '<input type="radio" name="vAns" value="all" checked="on" /> all students <br />'."\n".
1.49 albertel 601: ' <b>Submissions: </b>'."\n";
1.118 ng 602: if ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
603: $gradeTable.='<input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> essay part only'."\n";
1.49 albertel 604: }
1.110 ng 605:
1.112 ng 606: my $saveStatus = $ENV{'form.Status'} eq '' ? 'Active' : $ENV{'form.Status'};
607: $ENV{'form.Status'} = $saveStatus;
1.110 ng 608:
1.135 bowersj2 609: $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only'."\n".
610: '<input type="radio" name="lastSub" value="last" /> last submission & parts info'."\n".
1.122 ng 611: '<input type="radio" name="lastSub" value="datesub" /> by dates and submissions'."\n".
1.45 ng 612: '<input type="radio" name="lastSub" value="all" /> all details'."\n".
613: '<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
614: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.65 albertel 615: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'" /><br />'."\n".
1.64 albertel 616: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" /><br />'."\n".
1.77 ng 617: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 618: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.48 albertel 619: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
620: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.110 ng 621: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
622:
1.124 ng 623: if (exists($ENV{'form.gradingMenu'}) && exists($ENV{'form.Status'})) {
624: $gradeTable.='<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n";
625: } else {
626: $gradeTable.='<b>Student Status:</b> '.
627: &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'<br />';
628: }
1.112 ng 629:
1.126 ng 630: $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
631: 'next to the student\'s name(s). Then click on the Next button.<br />'."\n".
1.110 ng 632: '<input type="hidden" name="command" value="processGroup" />'."\n";
633: $gradeTable.='<input type="button" '."\n".
1.45 ng 634: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.126 ng 635: 'value="Next->" />'."\n";
1.134 www 636: $gradeTable.='<input type="checkbox" name="checkPlag" checked="on">Check For Plagiarism</input>';
1.110 ng 637: my (undef, undef, $fullname) = &getclasslist($getsec,'1');
1.45 ng 638: $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.110 ng 639: '<table border="0"><tr bgcolor="#e6ffff">';
640: my $loop = 0;
641: while ($loop < 2) {
1.126 ng 642: $gradeTable.='<td><b> No.</b> </td><td><b> Select </b></td>'.
1.129 ng 643: '<td>'.&nameUserString('header').'</td>';
1.110 ng 644: if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
645: foreach (sort(@$partlist)) {
646: $gradeTable.='<td><b> Part '.(split(/_/))[0].' Status </b></td>';
647: }
648: }
649: $loop++;
1.126 ng 650: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 651: }
1.45 ng 652: $gradeTable.='</tr>'."\n";
1.41 ng 653:
1.45 ng 654: my $ctr = 0;
1.53 albertel 655: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41 ng 656: my ($uname,$udom) = split(/:/,$student);
1.110 ng 657: my %status = ();
658: if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
659: (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
1.145 albertel 660: my $submitted = 0;
661: my $graded = 1;
1.110 ng 662: foreach (keys(%status)) {
1.145 albertel 663: $submitted = 1 if ($status{$_} ne 'nothing');
664: $graded = 0 if ($status{$_} =~ /^correct/);
1.110 ng 665: my ($foo,$partid,$foo1) = split(/\./,$_);
666: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 667: $submitted = 0;
1.110 ng 668: $gradeTable.='<input type="hidden" name="'.
669: $student.':submitted_by" value="'.
670: $status{'resource.'.$partid.'.submitted_by'}.'" />';
671: }
1.41 ng 672: }
1.145 albertel 673: next if (!$submitted && ($submitonly eq 'yes' || $submitonly eq 'graded'));
674: next if (!$graded && $submitonly eq 'graded');
1.41 ng 675: }
1.34 ng 676:
1.45 ng 677: $ctr++;
1.104 albertel 678: if ( $perm{'vgr'} eq 'F' ) {
1.110 ng 679: $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
1.126 ng 680: $gradeTable.='<td align="right">'.$ctr.' </td>'.
681: '<td align="center"><input type=checkbox name="stuinfo" value="'.
1.110 ng 682: $student.':'.$$fullname{$student}.' "></td>'."\n".
1.129 ng 683: '<td>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).'</td>'."\n";
1.110 ng 684:
685: if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
686: foreach (sort keys(%status)) {
687: next if (/^resource.*?submitted_by$/);
688: $gradeTable.='<td align="middle"> '.$status{$_}.' </td>'."\n";
689: }
1.41 ng 690: }
1.126 ng 691: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.110 ng 692: $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
1.41 ng 693: }
694: }
1.110 ng 695: if ($ctr%2 ==1) {
1.126 ng 696: $gradeTable.='<td> </td><td> </td><td> </td>';
1.110 ng 697: if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
698: foreach (@$partlist) {
699: $gradeTable.='<td> </td>';
700: }
701: }
702: $gradeTable.='</tr>';
703: }
704:
1.45 ng 705: $gradeTable.='</table></td></tr></table>'.
706: '<input type="button" '.
707: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.126 ng 708: 'value="Next->" /></form>'."\n";
1.45 ng 709: if ($ctr == 0) {
1.96 albertel 710: my $num_students=(scalar(keys(%$fullname)));
711: if ($num_students eq 0) {
712: $gradeTable='<br /> <font color="red">There are no students currently enrolled.</font>';
713: } else {
714: $gradeTable='<br /> <font color="red">'.
1.110 ng 715: 'No submissions found for this resource for any students. ('.$num_students.
1.145 albertel 716: ' checked for submissions)</font><br />';
1.96 albertel 717: }
1.46 ng 718: } elsif ($ctr == 1) {
719: $gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45 ng 720: }
1.50 albertel 721: $gradeTable.=&show_grading_menu_form($symb,$url);
1.45 ng 722: $request->print($gradeTable);
1.44 ng 723: return '';
1.10 ng 724: }
725:
1.44 ng 726: #---- Called from the listStudents routine
727: # Displays the submissions for one student or a group of students
1.34 ng 728: sub processGroup {
1.41 ng 729: my ($request) = shift;
730: my $ctr = 0;
731: my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
732: : ($ENV{'form.stuinfo'}));
733: my $total = scalar(@stuchecked)-1;
1.45 ng 734:
1.41 ng 735: foreach (@stuchecked) {
736: my ($uname,$udom,$fullname) = split(/:/);
1.44 ng 737: $ENV{'form.student'} = $uname;
738: $ENV{'form.userdom'} = $udom;
739: $ENV{'form.fullname'} = $fullname;
1.41 ng 740: &submission($request,$ctr,$total);
741: $ctr++;
742: }
743: return '';
1.35 ng 744: }
1.34 ng 745:
1.44 ng 746: #------------------------------------------------------------------------------------
747: #
748: #-------------------------- Next few routines handles grading by student, essentially
749: # handles essay response type problem/part
750: #
751: #--- Javascript to handle the submission page functionality ---
752: sub sub_page_js {
753: my $request = shift;
754: $request->print(<<SUBJAVASCRIPT);
755: <script type="text/javascript" language="javascript">
1.71 ng 756: function updateRadio(formname,id,weight) {
1.125 ng 757: var gradeBox = formname["GD_BOX"+id];
758: var radioButton = formname["RADVAL"+id];
759: var oldpts = formname["oldpts"+id].value;
1.72 ng 760: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 761: gradeBox.value = pts;
762: var resetbox = false;
763: if (isNaN(pts) || pts < 0) {
764: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
765: for (var i=0; i<radioButton.length; i++) {
766: if (radioButton[i].checked) {
767: gradeBox.value = i;
768: resetbox = true;
769: }
770: }
771: if (!resetbox) {
772: formtextbox.value = "";
773: }
774: return;
1.44 ng 775: }
1.71 ng 776:
777: if (pts > weight) {
778: var resp = confirm("You entered a value ("+pts+
779: ") greater than the weight for the part. Accept?");
780: if (resp == false) {
1.125 ng 781: gradeBox.value = oldpts;
1.71 ng 782: return;
783: }
1.44 ng 784: }
1.13 albertel 785:
1.71 ng 786: for (var i=0; i<radioButton.length; i++) {
787: radioButton[i].checked=false;
788: if (pts == i && pts != "") {
789: radioButton[i].checked=true;
790: }
791: }
792: updateSelect(formname,id);
1.125 ng 793: formname["stores"+id].value = "0";
1.41 ng 794: }
1.5 albertel 795:
1.72 ng 796: function writeBox(formname,id,pts) {
1.125 ng 797: var gradeBox = formname["GD_BOX"+id];
1.71 ng 798: if (checkSolved(formname,id) == 'update') {
799: gradeBox.value = pts;
800: } else {
1.125 ng 801: var oldpts = formname["oldpts"+id].value;
1.72 ng 802: gradeBox.value = oldpts;
1.125 ng 803: var radioButton = formname["RADVAL"+id];
1.71 ng 804: for (var i=0; i<radioButton.length; i++) {
805: radioButton[i].checked=false;
1.72 ng 806: if (i == oldpts) {
1.71 ng 807: radioButton[i].checked=true;
808: }
809: }
1.41 ng 810: }
1.125 ng 811: formname["stores"+id].value = "0";
1.71 ng 812: updateSelect(formname,id);
813: return;
1.41 ng 814: }
1.44 ng 815:
1.71 ng 816: function clearRadBox(formname,id) {
817: if (checkSolved(formname,id) == 'noupdate') {
818: updateSelect(formname,id);
819: return;
820: }
1.125 ng 821: gradeSelect = formname["GD_SEL"+id];
1.71 ng 822: for (var i=0; i<gradeSelect.length; i++) {
823: if (gradeSelect[i].selected) {
824: var selectx=i;
825: }
826: }
1.125 ng 827: var stores = formname["stores"+id];
1.71 ng 828: if (selectx == stores.value) { return };
1.125 ng 829: var gradeBox = formname["GD_BOX"+id];
1.71 ng 830: gradeBox.value = "";
1.125 ng 831: var radioButton = formname["RADVAL"+id];
1.71 ng 832: for (var i=0; i<radioButton.length; i++) {
833: radioButton[i].checked=false;
834: }
835: stores.value = selectx;
836: }
1.5 albertel 837:
1.71 ng 838: function checkSolved(formname,id) {
1.125 ng 839: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 840: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
841: if (!reply) {return "noupdate";}
1.120 ng 842: formname.overRideScore.value = 'yes';
1.41 ng 843: }
1.71 ng 844: return "update";
1.13 albertel 845: }
1.71 ng 846:
847: function updateSelect(formname,id) {
1.125 ng 848: formname["GD_SEL"+id][0].selected = true;
1.71 ng 849: return;
1.41 ng 850: }
1.33 ng 851:
1.121 ng 852: //=========== Check that a point is assigned for all the parts ============
1.71 ng 853: function checksubmit(formname,val,total,parttot) {
1.121 ng 854: formname.gradeOpt.value = val;
1.71 ng 855: if (val == "Save & Next") {
856: for (i=0;i<=total;i++) {
857: for (j=0;j<parttot;j++) {
1.125 ng 858: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 859: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 860: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 861: if (points == "") {
1.125 ng 862: var name = formname["name"+i].value;
1.129 ng 863: var studentID = (name != '' ? name : formname["unamedom"+i].value);
864: var resp = confirm("You did not assign a score for "+studentID+
865: ", part "+partid+". Continue?");
1.71 ng 866: if (resp == false) {
1.125 ng 867: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 868: return false;
869: }
870: }
871: }
872:
873: }
874: }
875:
876: }
1.121 ng 877: if (val == "Grade Student") {
878: formname.showgrading.value = "yes";
879: if (formname.Status.value == "") {
880: formname.Status.value = "Active";
881: }
882: formname.studentNo.value = total;
883: }
1.120 ng 884: formname.submit();
885: }
886:
1.71 ng 887: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
888: function checkSubmitPage(formname,total) {
889: noscore = new Array(100);
890: var ptr = 0;
891: for (i=1;i<total;i++) {
1.125 ng 892: var partid = formname["q_"+i].value;
1.127 ng 893: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 894: var points = formname["GD_BOX"+i+"_"+partid].value;
895: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 896: if (points == "" && status != "correct_by_student") {
897: noscore[ptr] = i;
898: ptr++;
899: }
900: }
901: }
902: if (ptr != 0) {
903: var sense = ptr == 1 ? ": " : "s: ";
904: var prolist = "";
905: if (ptr == 1) {
906: prolist = noscore[0];
907: } else {
908: var i = 0;
909: while (i < ptr-1) {
910: prolist += noscore[i]+", ";
911: i++;
912: }
913: prolist += "and "+noscore[i];
914: }
915: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
916: if (resp == false) {
917: return false;
918: }
919: }
1.45 ng 920:
1.71 ng 921: formname.submit();
922: }
923: </script>
924: SUBJAVASCRIPT
925: }
1.45 ng 926:
1.71 ng 927: #--- javascript for essay type problem --
928: sub sub_page_kw_js {
929: my $request = shift;
1.80 ng 930: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 931: &commonJSfunctions($request);
1.71 ng 932: $request->print(<<SUBJAVASCRIPT);
933: <script type="text/javascript" language="javascript">
1.45 ng 934:
1.44 ng 935: //===================== Show list of keywords ====================
1.122 ng 936: function keywords(formname) {
937: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 938: if (nret==null) return;
1.122 ng 939: formname.keywords.value = nret;
1.44 ng 940:
1.122 ng 941: if (formname.keywords.value != "") {
1.128 ng 942: formname.refresh.value = "on";
1.122 ng 943: formname.submit();
1.44 ng 944: }
945: return;
946: }
947:
948: //===================== Script to view submitted by ==================
949: function viewSubmitter(submitter) {
950: document.SCORE.refresh.value = "on";
951: document.SCORE.NCT.value = "1";
952: document.SCORE.unamedom0.value = submitter;
953: document.SCORE.submit();
954: return;
955: }
956:
957: //===================== Script to add keyword(s) ==================
958: function getSel() {
959: if (document.getSelection) txt = document.getSelection();
960: else if (document.selection) txt = document.selection.createRange().text;
961: else return;
962: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
963: if (cleantxt=="") {
1.46 ng 964: alert("Please select a word or group of words from document and then click this link.");
1.44 ng 965: return;
966: }
967: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
968: if (nret==null) return;
1.127 ng 969: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 970: if (document.SCORE.keywords.value != "") {
1.127 ng 971: document.SCORE.refresh.value = "on";
1.44 ng 972: document.SCORE.submit();
973: }
974: return;
975: }
976:
977: //====================== Script for composing message ==============
1.80 ng 978: // preload images
979: img1 = new Image();
980: img1.src = "$iconpath/mailbkgrd.gif";
981: img2 = new Image();
982: img2.src = "$iconpath/mailto.gif";
983:
1.44 ng 984: function msgCenter(msgform,usrctr,fullname) {
985: var Nmsg = msgform.savemsgN.value;
986: savedMsgHeader(Nmsg,usrctr,fullname);
987: var subject = msgform.msgsub.value;
1.127 ng 988: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 989: re = /msgsub/;
990: var shwsel = "";
991: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 992: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
993: displaySubject(checkEntities(subject),shwsel);
1.44 ng 994: for (var i=1; i<=Nmsg; i++) {
1.123 ng 995: var testmsg = "savemsg"+i+",";
996: re = new RegExp(testmsg,"g");
1.44 ng 997: shwsel = "";
998: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 999: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1000: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1001: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1002: //any < is already converted to <, etc. However, only once!!
1.44 ng 1003: }
1.125 ng 1004: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1005: shwsel = "";
1006: re = /newmsg/;
1007: if (re.test(msgchk)) { shwsel = "checked" }
1008: newMsg(newmsg,shwsel);
1009: msgTail();
1010: return;
1011: }
1012:
1.123 ng 1013: function checkEntities(strx) {
1014: if (strx.length == 0) return strx;
1015: var orgStr = ["&", "<", ">", '"'];
1016: var newStr = ["&", "<", ">", """];
1017: var counter = 0;
1018: while (counter < 4) {
1019: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1020: counter++;
1021: }
1022: return strx;
1023: }
1024:
1025: function strReplace(strx, orgStr, newStr) {
1026: return strx.split(orgStr).join(newStr);
1027: }
1028:
1.44 ng 1029: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1030: var height = 70*Nmsg+250;
1.44 ng 1031: var scrollbar = "no";
1032: if (height > 600) {
1033: height = 600;
1034: scrollbar = "yes";
1035: }
1.118 ng 1036: var xpos = (screen.width-600)/2;
1037: xpos = (xpos < 0) ? '0' : xpos;
1038: var ypos = (screen.height-height)/2-30;
1039: ypos = (ypos < 0) ? '0' : ypos;
1040:
1041: pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1042: pWin.focus();
1043: pDoc = pWin.document;
1.128 ng 1044: pDoc.open('text/html','replace');
1.76 ng 1045: pDoc.write("<html><head>");
1046: pDoc.write("<title>Message Central</title>");
1047:
1048: pDoc.write("<script language=javascript>");
1049: pDoc.write("function checkInput() {");
1.123 ng 1050: pDoc.write(" opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);");
1.76 ng 1051: pDoc.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
1052: pDoc.write(" var usrctr = document.msgcenter.usrctr.value;");
1.125 ng 1053: pDoc.write(" var newval = opener.document.SCORE[\\"newmsg\\"+usrctr];");
1.123 ng 1054: pDoc.write(" newval.value = opener.checkEntities(document.msgcenter.newmsg.value);");
1.76 ng 1055:
1056: pDoc.write(" var msgchk = \\"\\";");
1057: pDoc.write(" if (document.msgcenter.subchk.checked) {");
1058: pDoc.write(" msgchk = \\"msgsub,\\";");
1059: pDoc.write(" }");
1.80 ng 1060: pDoc.write(" var includemsg = 0;");
1061: pDoc.write(" for (var i=1; i<=nmsg; i++) {");
1.125 ng 1062: pDoc.write(" var opnmsg = opener.document.SCORE[\\"savemsg\\"+i];");
1063: pDoc.write(" var frmmsg = document.msgcenter[\\"msg\\"+i];");
1.123 ng 1064: pDoc.write(" opnmsg.value = opener.checkEntities(frmmsg.value);");
1.125 ng 1065: pDoc.write(" var showflg = opener.document.SCORE[\\"shownOnce\\"+i];");
1.123 ng 1066: pDoc.write(" showflg.value = \\"1\\";");
1.125 ng 1067: pDoc.write(" var chkbox = document.msgcenter[\\"msgn\\"+i];");
1.76 ng 1068: pDoc.write(" if (chkbox.checked) {");
1069: pDoc.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
1.80 ng 1070: pDoc.write(" includemsg = 1;");
1.76 ng 1071: pDoc.write(" }");
1072: pDoc.write(" }");
1073: pDoc.write(" if (document.msgcenter.newmsgchk.checked) {");
1074: pDoc.write(" msgchk += \\"newmsg\\"+usrctr;");
1.80 ng 1075: pDoc.write(" includemsg = 1;");
1076: pDoc.write(" }");
1.125 ng 1077: pDoc.write(" imgformname = opener.document.SCORE[\\"mailicon\\"+usrctr];");
1.84 ng 1078: pDoc.write(" imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");");
1.125 ng 1079: pDoc.write(" var includemsg = opener.document.SCORE[\\"includemsg\\"+usrctr];");
1.76 ng 1080: pDoc.write(" includemsg.value = msgchk;");
1081:
1082: pDoc.write(" self.close()");
1083:
1084: pDoc.write("}");
1085:
1086: pDoc.write("<");
1087: pDoc.write("/script>");
1088:
1089: pDoc.write("</head><body bgcolor=white>");
1090:
1091: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1092: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1093: pDoc.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br><br>");
1094:
1095: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1096: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1097: pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44 ng 1098: }
1099: function displaySubject(msg,shwsel) {
1.76 ng 1100: pDoc = pWin.document;
1101: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1102: pDoc.write("<td>Subject</td>");
1103: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1104: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44 ng 1105: }
1106:
1.72 ng 1107: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1108: pDoc = pWin.document;
1109: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1110: pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
1111: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1112: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44 ng 1113: }
1114:
1115: function newMsg(newmsg,shwsel) {
1.76 ng 1116: pDoc = pWin.document;
1117: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1118: pDoc.write("<td align=\\"center\\">New</td>");
1119: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1120: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44 ng 1121: }
1122:
1123: function msgTail() {
1.76 ng 1124: pDoc = pWin.document;
1125: pDoc.write("</table>");
1126: pDoc.write("</td></tr></table> ");
1127: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1128: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
1129: pDoc.write("</form>");
1130: pDoc.write("</body></html>");
1.128 ng 1131: pDoc.close();
1.44 ng 1132: }
1133:
1134: //====================== Script for keyword highlight options ==============
1135: function kwhighlight() {
1136: var kwclr = document.SCORE.kwclr.value;
1137: var kwsize = document.SCORE.kwsize.value;
1138: var kwstyle = document.SCORE.kwstyle.value;
1139: var redsel = "";
1140: var grnsel = "";
1141: var blusel = "";
1142: if (kwclr=="red") {var redsel="checked"};
1143: if (kwclr=="green") {var grnsel="checked"};
1144: if (kwclr=="blue") {var blusel="checked"};
1145: var sznsel = "";
1146: var sz1sel = "";
1147: var sz2sel = "";
1148: if (kwsize=="0") {var sznsel="checked"};
1149: if (kwsize=="+1") {var sz1sel="checked"};
1150: if (kwsize=="+2") {var sz2sel="checked"};
1151: var synsel = "";
1152: var syisel = "";
1153: var sybsel = "";
1154: if (kwstyle=="") {var synsel="checked"};
1155: if (kwstyle=="<i>") {var syisel="checked"};
1156: if (kwstyle=="<b>") {var sybsel="checked"};
1157: highlightCentral();
1158: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1159: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1160: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1161: highlightend();
1162: return;
1163: }
1164:
1165: function highlightCentral() {
1.76 ng 1166: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1167: var xpos = (screen.width-400)/2;
1168: xpos = (xpos < 0) ? '0' : xpos;
1169: var ypos = (screen.height-330)/2-30;
1170: ypos = (ypos < 0) ? '0' : ypos;
1171:
1172: hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1173: hwdWin.focus();
1174: var hDoc = hwdWin.document;
1.128 ng 1175: hDoc.open('text/html','replace');
1.76 ng 1176: hDoc.write("<html><head>");
1177: hDoc.write("<title>Highlight Central</title>");
1178:
1179: hDoc.write("<script language=javascript>");
1180: hDoc.write("function updateChoice(flag) {");
1.118 ng 1181: hDoc.write(" opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);");
1182: hDoc.write(" opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);");
1183: hDoc.write(" opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);");
1.76 ng 1184: hDoc.write(" opener.document.SCORE.refresh.value = \\"on\\";");
1185: hDoc.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){");
1186: hDoc.write(" opener.document.SCORE.submit();");
1187: hDoc.write(" }");
1188: hDoc.write(" self.close()");
1189: hDoc.write("}");
1190:
1191: hDoc.write("<");
1192: hDoc.write("/script>");
1193:
1194: hDoc.write("</head><body bgcolor=white>");
1195:
1196: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1197: hDoc.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br><br>");
1198:
1199: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1200: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1201: hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44 ng 1202: }
1203:
1204: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1205: var hDoc = hwdWin.document;
1206: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1207: hDoc.write("<td align=\\"left\\">");
1208: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
1209: hDoc.write("<td align=\\"left\\">");
1210: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
1211: hDoc.write("<td align=\\"left\\">");
1212: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
1213: hDoc.write("</tr>");
1.44 ng 1214: }
1215:
1216: function highlightend() {
1.76 ng 1217: var hDoc = hwdWin.document;
1218: hDoc.write("</table>");
1219: hDoc.write("</td></tr></table> ");
1220: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1221: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
1222: hDoc.write("</form>");
1223: hDoc.write("</body></html>");
1.128 ng 1224: hDoc.close();
1.44 ng 1225: }
1226:
1227: </script>
1228: SUBJAVASCRIPT
1229: }
1230:
1.71 ng 1231: #--- displays the grading box, used in essay type problem and grading by page/sequence
1232: sub gradeBox {
1233: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1234:
1235: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
1236: '/check.gif" height="16" border="0" />';
1237:
1238: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1239: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
1240: '<font color="red">problem weight assigned by computer</font>');
1241: $wgt = ($wgt > 0 ? $wgt : '1');
1242: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1243: '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
1244: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1245:
1246: $result.='<table border="0"><tr><td>'.
1247: '<b>Part </b>'.$partid.' <b>Points: </b></td><td>'."\n";
1248:
1249: my $ctr = 0;
1250: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1251: while ($ctr<=$wgt) {
1252: $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1253: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.72 ng 1254: $ctr.')" value="'.$ctr.'" '.
1.71 ng 1255: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
1256: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1257: $ctr++;
1258: }
1259: $result.='</tr></table>';
1260:
1261: $result.='</td><td> <b>or</b> </td>'."\n";
1262: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1263: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1264: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1265: $wgt.')" /></td>'."\n";
1266: $result.='<td>/'.$wgt.' '.$wgtmsg.
1267: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1268: ' </td><td>'."\n";
1269:
1270: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1271: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1272: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1273: $result.='<option> </option>'.
1.125 ng 1274: '<option selected="on">excused</option>';
1.71 ng 1275: } else {
1276: $result.='<option selected="on"> </option>'.
1.125 ng 1277: '<option>excused</option>';
1.71 ng 1278: }
1.125 ng 1279: $result.='<option>reset status</option></select>'."\n";
1.71 ng 1280: $result.="  \n";
1281: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1282: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1283: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1284: $$record{'resource.'.$partid.'.solved'}.'" />'."\n";
1285: $result.='</td></tr></table>'."\n";
1286: return $result;
1287: }
1.44 ng 1288:
1.58 albertel 1289: sub show_problem {
1.144 albertel 1290: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
1291: my $rendered;
1292: if ($mode eq 'both' or $mode eq 'text') {
1293: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1294: $ENV{'request.course.id'});
1295: }
1.58 albertel 1296: if ($removeform) {
1297: $rendered=~s|<form(.*?)>||g;
1298: $rendered=~s|</form>||g;
1299: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
1300: }
1.144 albertel 1301: my $companswer;
1302: if ($mode eq 'both' or $mode eq 'answer') {
1303: $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
1304: $ENV{'request.course.id'});
1305: }
1.58 albertel 1306: if ($removeform) {
1307: $companswer=~s|<form(.*?)>||g;
1308: $companswer=~s|</form>||g;
1.144 albertel 1309: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1310: }
1311: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 1312: $result.='<table border="0" width="100%">';
1.144 albertel 1313: if ($viewon) {
1314: $result.='<tr><td bgcolor="#e6ffff"><b> ';
1315: if ($mode eq 'both' or $mode eq 'text') {
1316: $result.='View of the problem - ';
1317: } else {
1318: $result.='Correct answer: ';
1319: }
1320: $result.=$ENV{'form.fullname'}.'</b></td></tr>';
1321: }
1322: if ($mode eq 'both') {
1323: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1324: $result.='<b>Correct answer:</b><br />'.$companswer;
1325: } elsif ($mode eq 'text') {
1326: $result.='<tr><td bgcolor="#ffffff">'.$rendered;
1327: } elsif ($mode eq 'answer') {
1328: $result.='<tr><td bgcolor="#ffffff">'.$companswer;
1329: }
1.58 albertel 1330: $result.='</td></tr></table>';
1331: $result.='</td></tr></table><br />';
1.71 ng 1332: return $result;
1.58 albertel 1333: }
1334:
1.44 ng 1335: # --------------------------- show submissions of a student, option to grade
1336: sub submission {
1337: my ($request,$counter,$total) = @_;
1338:
1339: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1340: my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
1.120 ng 1341: $udom = ($udom eq '' ? $ENV{'user.domain'} : $udom); #has form.userdom changed for a student?
1.104 albertel 1342: my $usec = &Apache::lonnet::getsection($udom,$uname,$ENV{'request.course.id'});
1.44 ng 1343: $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
1.41 ng 1344:
1345: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1346: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.104 albertel 1347:
1348: if (!&canview($usec)) {
1.116 ng 1349: $request->print('<font color="red">Unable to view requested student.('.
1350: $uname.$udom.$usec.$ENV{'request.course.id'}.')</font>');
1.104 albertel 1351: $request->print(&show_grading_menu_form($symb,$url));
1352: return;
1353: }
1354:
1.122 ng 1355: $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'datesub' : $ENV{'form.lastSub'});
1.41 ng 1356: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
1.122 ng 1357: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
1358: '/check.gif" height="16" border="0" />';
1.41 ng 1359:
1360: # header info
1361: if ($counter == 0) {
1362: &sub_page_js($request);
1.118 ng 1363: &sub_page_kw_js($request) if ($ENV{'form.handgrade'} eq 'yes');
1.76 ng 1364: $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
1365: &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
1366:
1.45 ng 1367: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.118 ng 1368: '<font size=+1> <b>Resource: </b>'.$ENV{'form.probTitle'}.'</font>'."\n");
1369:
1370: if ($ENV{'form.handgrade'} eq 'no') {
1371: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1372: $checkIcon.' symbol.'."\n";
1373: $request->print($checkMark);
1374: }
1.41 ng 1375:
1.44 ng 1376: # option to display problem, only once else it cause problems
1377: # with the form later since the problem has a form.
1.144 albertel 1378: if ($ENV{'form.vProb'} eq 'yes' or $ENV{'form.vAns'} eq 'yes') {
1379: my $mode;
1380: if ($ENV{'form.vProb'} eq 'yes' && $ENV{'form.vAns'} eq 'yes') {
1381: $mode='both';
1382: } elsif ($ENV{'form.vProb'} eq 'yes') {
1383: $mode='text';
1384: } elsif ($ENV{'form.vAns'} eq 'yes') {
1385: $mode='answer';
1386: }
1387: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1388: }
1389:
1.44 ng 1390: # kwclr is the only variable that is guaranteed to be non blank
1391: # if this subroutine has been called once.
1.41 ng 1392: my %keyhash = ();
1.118 ng 1393: if ($ENV{'form.kwclr'} eq '' && $ENV{'form.handgrade'} eq 'yes') {
1.41 ng 1394: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1395: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1396: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1397:
1398: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1399: $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1400: $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1401: $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1402: $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1403: $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.72 ng 1404: $keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
1.41 ng 1405: $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1406: }
1.120 ng 1407: my $overRideScore = $ENV{'form.overRideScore'} eq '' ? 'no' : $ENV{'form.overRideScore'};
1.44 ng 1408:
1.41 ng 1409: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
1410: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.80 ng 1411: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.119 ng 1412: '<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n".
1.120 ng 1413: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.72 ng 1414: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.41 ng 1415: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1416: '<input type="hidden" name="studentNo" value="" />'."\n".
1417: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.41 ng 1418: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1419: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1420: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
1421: '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
1.144 albertel 1422: '<input type="hidden" name="vAns" value="'.$ENV{'form.vAns'}.'" />'."\n".
1.41 ng 1423: '<input type="hidden" name="lastSub" value="'.$ENV{'form.lastSub'}.'" />'."\n".
1424: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
1425: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
1426: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'">'."\n".
1427: '<input type="hidden" name="NCT"'.
1428: ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
1.123 ng 1429: if ($ENV{'form.handgrade'} eq 'yes') {
1430: $request->print('<input type="hidden" name="keywords" value="'.$ENV{'form.keywords'}.'" />'."\n".
1431: '<input type="hidden" name="kwclr" value="'.$ENV{'form.kwclr'}.'" />'."\n".
1432: '<input type="hidden" name="kwsize" value="'.$ENV{'form.kwsize'}.'" />'."\n".
1433: '<input type="hidden" name="kwstyle" value="'.$ENV{'form.kwstyle'}.'" />'."\n".
1434: '<input type="hidden" name="msgsub" value="'.$ENV{'form.msgsub'}.'" />'."\n".
1435: '<input type="hidden" name="shownSub" value="0" />'."\n".
1436: '<input type="hidden" name="savemsgN" value="'.$ENV{'form.savemsgN'}.'" />'."\n");
1437: }
1.41 ng 1438:
1439: my ($cts,$prnmsg) = (1,'');
1440: while ($cts <= $ENV{'form.savemsgN'}) {
1441: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1442: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.80 ng 1443: &Apache::lonfeedback::clear_out_html($ENV{'form.savemsg'.$cts}) :
1444: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1445: '" />'."\n".
1446: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1447: $cts++;
1448: }
1449: $request->print($prnmsg);
1.32 ng 1450:
1.41 ng 1451: if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
1.88 www 1452: #
1453: # Print out the keyword options line
1454: #
1.41 ng 1455: $request->print(<<KEYWORDS);
1.38 ng 1456: <b>Keyword Options:</b>
1.122 ng 1457: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>
1.38 ng 1458: <a href="#" onMouseDown="javascript:getSel(); return false"
1459: CLASS="page">Paste Selection to List</a>
1460: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1461: KEYWORDS
1.88 www 1462: #
1463: # Load the other essays for similarity check
1464: #
1465: my $essayurl=&Apache::lonnet::declutter($url);
1466: my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
1467: $apath=&Apache::lonnet::escape($apath);
1468: $apath=~s/\W/\_/gs;
1469: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1470: }
1471: }
1.44 ng 1472:
1.144 albertel 1473: if ($ENV{'form.vProb'} eq 'all' or $ENV{'form.vAns'} eq 'all') {
1.71 ng 1474: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1475: my $mode;
1476: if ($ENV{'form.vProb'} eq 'all' && $ENV{'form.vAns'} eq 'all') {
1477: $mode='both';
1478: } elsif ($ENV{'form.vProb'} eq 'all' ) {
1479: $mode='text';
1480: } elsif ($ENV{'form.vAns'} eq 'all') {
1481: $mode='answer';
1482: }
1483: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1484: }
1.144 albertel 1485:
1.41 ng 1486: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
1.125 ng 1487:
1.147 albertel 1488: my ($partlist,$handgrade,$responseType) = &response_type($url,$symb);
1.41 ng 1489:
1.44 ng 1490: # Display student info
1.41 ng 1491: $request->print(($counter == 0 ? '' : '<br />'));
1.45 ng 1492: my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
1493: '<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1494:
1.129 ng 1495: $result.='<b>Fullname: </b>'.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1496: $result.='<input type="hidden" name="name'.$counter.
1497: '" value="'.$ENV{'form.fullname'}.'" />'."\n";
1.41 ng 1498:
1.118 ng 1499: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1500: my @col_fullnames;
1.56 matthew 1501: my ($classlist,$fullname);
1.41 ng 1502: if ($ENV{'form.handgrade'} eq 'yes') {
1.80 ng 1503: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1504: for (keys (%$handgrade)) {
1.44 ng 1505: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1506: '.maxcollaborators',
1507: $symb,$udom,$uname);
1508: next if ($ncol <= 0);
1509: s/\_/\./g;
1510: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1511: my @goodcollaborators = ();
1512: my @badcollaborators = ();
1513: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1514: $_ =~ s/[\$\^\(\)]//g;
1515: next if ($_ eq '');
1.80 ng 1516: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1517: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1518: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1519: # Doing this grep allows 'fuzzy' specification
1520: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1521: if (! scalar(@Matches)) {
1522: push @badcollaborators,$_;
1523: } else {
1524: push @goodcollaborators, @Matches;
1525: }
1.80 ng 1526: }
1.86 ng 1527: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1528: $result.='<b>Collaborators: </b>';
1.86 ng 1529: foreach (@goodcollaborators) {
1530: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1531: push @col_fullnames, $givenn.' '.$lastname;
1532: $result.=$$fullname{$_}.' ';
1533: }
1.57 matthew 1534: $result.='<br />'."\n";
1.86 ng 1535: $result.='<input type="hidden" name="collaborator'.$counter.
1536: '" value="'.(join ':',@goodcollaborators).'" />'."\n";
1537: }
1538: if (scalar(@badcollaborators) > 0) {
1539: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1540: $result.='This student has submitted ';
1541: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1542: $result .= ': '.join(', ',@badcollaborators);
1543: $result .= '</td></tr></table>';
1544: }
1545: if (scalar(@badcollaborators > $ncol)) {
1546: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1547: $result .= 'This student has submitted too many '.
1548: 'collaborators. Maximum is '.$ncol.'.';
1549: $result .= '</td></tr></table>';
1550: }
1.41 ng 1551: }
1552: }
1.44 ng 1553: $request->print($result."\n");
1.33 ng 1554:
1.44 ng 1555: # print student answer/submission
1556: # Options are (1) Handgaded submission only
1557: # (2) Last submission, includes submission that is not handgraded
1558: # (for multi-response type part)
1559: # (3) Last submission plus the parts info
1560: # (4) The whole record for this student
1.41 ng 1561: if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1562: if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
1.44 ng 1563: my $submitby=''.
1.41 ng 1564: '<b>Collaborative submission by: </b>'.
1.44 ng 1565: '<a href="javascript:viewSubmitter(\''.
1566: $ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
1.41 ng 1567: '\')"; TARGET=_self>'.
1568: $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
1569: $request->print($submitby);
1570: } else {
1.147 albertel 1571: my ($string,$timestamp)= &get_last_submission(\%record);
1.71 ng 1572: my $lastsubonly=''.
1.44 ng 1573: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1.118 ng 1574: $$timestamp)."</td></tr>\n";
1.41 ng 1575: if ($$timestamp eq '') {
1.118 ng 1576: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1.41 ng 1577: } else {
1578: for my $part (sort keys(%$handgrade)) {
1.118 ng 1579: my ($partid,$respid) = split(/_/,$part);
1.147 albertel 1580: my $responsetype = $responseType->{$partid}->{$respid};
1.118 ng 1581: if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) {
1582: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
1583: $partid.'</b> <font color="#999999">( ID '.$respid.
1.125 ng 1584: ' )</font> '.
1585: '<font color="red">Nothing submitted - no attempts</font><br /><br />';
1.118 ng 1586: } else {
1587: foreach (@$string) {
1.148 albertel 1588: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1.118 ng 1589: if ($part eq ($partid.'_'.$respid)) {
1590: my ($ressub,$subval) = split(/:/,$_,2);
1591: # Similarity check
1592: my $similar='';
1.134 www 1593: my $oname;
1594: my $odom;
1595: my $ocrsid;
1596: my $oessay;
1597: my $osim;
1598: if($ENV{'form.checkPlag'}){
1599: ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
1600: if ($osim) {
1601: $osim=int($osim*100.0);
1602: $similar='<hr /><h3><font color="#FF0000">Essay is '.$osim.
1603: '% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
1604: '</font></h3><blockquote><i>'.
1605: &keywords_highlight($oessay).'</i></blockquote><hr />';
1606: }
1.118 ng 1607: }
1.148 albertel 1608: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.118 ng 1609: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
1610: $partid.'</b> <font color="#999999">( ID '.$respid.
1611: ' )</font> '.
1612: ($record{"resource.$partid.$respid.uploadedurl"}?
1613: '<a href="'.
1614: &Apache::lonnet::tokenwrapper($record{"resource.$partid.$respid.uploadedurl"}).
1615: '"><img src="/adm/lonIcons/unknown.gif" border=0"> File uploaded by student</a> '.
1616: '<font color="red" size="1">Like all files provided by users, '.
1617: 'this file may contain virusses</font><br />':'').
1.126 ng 1618: '<b>Submitted Answer: </b>'.
1.148 albertel 1619: &cleanRecord($subval,$responsetype,$symb,$partid,$respid,\%record,$order).
1.134 www 1620: '<br /><br />'.$similar."\n"
1.118 ng 1621: if ($ENV{'form.lastSub'} eq 'lastonly' ||
1622: ($ENV{'form.lastSub'} eq 'hdgrade' &&
1.149 ! albertel 1623: $$handgrade{$part} eq 'yes'));
1.118 ng 1624: }
1.41 ng 1625: }
1626: }
1627: }
1628: }
1.118 ng 1629: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1.41 ng 1630: $request->print($lastsubonly);
1631: }
1.122 ng 1632: } elsif ($ENV{'form.lastSub'} eq 'datesub') {
1633: my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
1.148 albertel 1634: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.122 ng 1635: } elsif ($ENV{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1636: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.44 ng 1637: $ENV{'request.course.id'},
1638: $last,'.submission',
1639: 'Apache::grades::keywords_highlight'));
1.41 ng 1640: }
1.120 ng 1641:
1.121 ng 1642: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1643: .$udom.'" />'."\n");
1.41 ng 1644:
1.44 ng 1645: # return if view submission with no grading option
1.118 ng 1646: if ($ENV{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 1647: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 1648: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1649: .$counter.'\');" TARGET=_self> '."\n" if (&canmodify($usec));
1.120 ng 1650: $toGrade.='</td></tr></table></td></tr></table></form>'."\n";
1651: $toGrade.=&show_grading_menu_form($symb,$url)
1.72 ng 1652: if (($ENV{'form.command'} eq 'submission') ||
1653: ($ENV{'form.command'} eq 'processGroup' && $counter == $total));
1.120 ng 1654: $request = print($toGrade);
1.41 ng 1655: return;
1656: }
1.33 ng 1657:
1.121 ng 1658: # essay grading message center
1.118 ng 1659: if ($ENV{'form.handgrade'} eq 'yes') {
1660: my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
1661: my $msgfor = $givenn.' '.$lastname;
1662: if (scalar(@col_fullnames) > 0) {
1663: my $lastone = pop @col_fullnames;
1664: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1665: }
1666: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 1667: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1668: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
1669: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118 ng 1670: ',\''.$msgfor.'\')"; TARGET=_self>'.
1671: 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').'</a> '.
1672: '<img src="'.$request->dir_config('lonIconsURL').
1673: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1674: '<br /> (Message will be sent when you click on Save & Next below.)'."\n"
1675: if ($ENV{'form.handgrade'} eq 'yes');
1.121 ng 1676: $request->print($result);
1.118 ng 1677: }
1.41 ng 1678:
1679: my %seen = ();
1680: my @partlist;
1.129 ng 1681: my @gradePartRespid;
1.41 ng 1682: for (sort keys(%$handgrade)) {
1683: my ($partid,$respid) = split(/_/);
1684: next if ($seen{$partid} > 0);
1685: $seen{$partid}++;
1.118 ng 1686: next if ($$handgrade{$_} =~ /:no$/ && $ENV{'form.lastSub'} =~ /^(hdgrade)$/);
1.41 ng 1687: push @partlist,$partid;
1.129 ng 1688: push @gradePartRespid,$partid.'.'.$respid;
1.41 ng 1689:
1.71 ng 1690: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 1691: }
1.45 ng 1692: $result='<input type="hidden" name="partlist'.$counter.
1693: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 1694: $result.='<input type="hidden" name="gradePartRespid'.
1695: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 1696: my $ctr = 0;
1697: while ($ctr < scalar(@partlist)) {
1698: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1699: $partlist[$ctr].'" />'."\n";
1700: $ctr++;
1701: }
1702: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 1703:
1704: # print end of form
1705: if ($counter == $total) {
1.120 ng 1706: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 1707: $endform.='<input type="button" value="Save & Next" '.
1708: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1709: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
1710: my $ntstu ='<select name="NTSTU">'.
1711: '<option>1</option><option>2</option>'.
1712: '<option>3</option><option>5</option>'.
1713: '<option>7</option><option>10</option></select>'."\n";
1714: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
1715: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
1716: $endform.=$ntstu.'student(s) ';
1.126 ng 1717: $endform.='<input type="button" value="Previous" '.
1718: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> '."\n".
1719: '<input type="button" value="Next" '.
1720: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> ';
1721: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.45 ng 1722: $endform.='</td><tr></table></form>';
1.50 albertel 1723: $endform.=&show_grading_menu_form($symb,$url);
1.41 ng 1724: $request->print($endform);
1725: }
1726: return '';
1.38 ng 1727: }
1728:
1.44 ng 1729: #--- Retrieve the last submission for all the parts
1.38 ng 1730: sub get_last_submission {
1.119 ng 1731: my ($returnhash)=@_;
1.46 ng 1732: my (@string,$timestamp);
1.119 ng 1733: if ($$returnhash{'version'}) {
1.46 ng 1734: my %lasthash=();
1735: my ($version);
1.119 ng 1736: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1737: foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
1738: $lasthash{$_}=$$returnhash{$version.':'.$_};
1739: $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 1740: }
1741: }
1742: foreach ((keys %lasthash)) {
1743: if ($_ =~ /\.submission$/) {
1744: my ($partid,$foo) = split(/submission$/,$_);
1745: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1746: '<font color="red">Draft Copy</font> ' : '';
1747: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 1748: }
1749: }
1750: }
1.125 ng 1751: @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
1.46 ng 1752: return \@string,\$timestamp;
1.38 ng 1753: }
1.35 ng 1754:
1.44 ng 1755: #--- High light keywords, with style choosen by user.
1.38 ng 1756: sub keywords_highlight {
1.44 ng 1757: my $string = shift;
1758: my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
1759: my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
1.41 ng 1760: (my $styleoff = $styleon) =~ s/\</\<\//;
1.44 ng 1761: my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
1.41 ng 1762: foreach (@keylist) {
1.119 ng 1763: $string =~ s/\b\Q$_\E(\b|\.)/<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
1.41 ng 1764: }
1765: return $string;
1.38 ng 1766: }
1.36 ng 1767:
1.44 ng 1768: #--- Called from submission routine
1.38 ng 1769: sub processHandGrade {
1.41 ng 1770: my ($request) = shift;
1771: my $url = $ENV{'form.url'};
1772: my $symb = $ENV{'form.symb'};
1773: my $button = $ENV{'form.gradeOpt'};
1774: my $ngrade = $ENV{'form.NCT'};
1775: my $ntstu = $ENV{'form.NTSTU'};
1.44 ng 1776: if ($button eq 'Save & Next') {
1777: my $ctr = 0;
1778: while ($ctr < $ngrade) {
1779: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.77 ng 1780: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.71 ng 1781: if ($errorflag eq 'no_score') {
1782: $ctr++;
1783: next;
1784: }
1.104 albertel 1785: if ($errorflag eq 'not_allowed') {
1786: $request->print("<font color=\"red\">Not allowed to modify grades for $uname:$udom</font>");
1787: $ctr++;
1788: next;
1789: }
1.44 ng 1790: my $includemsg = $ENV{'form.includemsg'.$ctr};
1791: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 1792: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.44 ng 1793: $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
1794: my (@msgnum) = split(/,/,$includemsg);
1795: foreach (@msgnum) {
1796: $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1797: }
1.80 ng 1798: $message =&Apache::lonfeedback::clear_out_html($message);
1.77 ng 1799: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.80 ng 1800: $message.=" for <a href=\"".
1801: &Apache::lonnet::clutter($url).
1802: "?symb=$symb\">$ENV{'form.probTitle'}</a>";
1.44 ng 1803: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
1804: $ENV{'form.msgsub'},$message);
1805: }
1806: if ($ENV{'form.collaborator'.$ctr}) {
1807: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
1808: foreach (@collaborators) {
1.119 ng 1809: my ($errorflag,$pts,$wgt) =
1810: &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,$ENV{'form.unamedom'.$ctr});
1.104 albertel 1811: if ($errorflag eq 'not_allowed') {
1812: $request->print("<font color=\"red\">Not allowed to modify grades for $_:$udom</font>");
1813: next;
1814: } else {
1815: if ($message ne '') {
1816: $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
1817: $ENV{'form.msgsub'},
1818: $message);
1819: }
1.44 ng 1820: }
1821: }
1822: }
1823: $ctr++;
1824: }
1825: }
1826:
1.119 ng 1827: if ($ENV{'form.handgrade'} eq 'yes') {
1828: # Keywords sorted in alphabatical order
1829: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1830: my %keyhash = ();
1831: $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1832: $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
1833: my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
1834: $ENV{'form.keywords'} = join(' ',@keywords);
1835: $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
1836: $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
1837: $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
1838: $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
1839: $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
1840:
1841: # message center - Order of message gets changed. Blank line is eliminated.
1842: # New messages are saved in ENV for the next student.
1843: # All messages are saved in nohist_handgrade.db
1844: my ($ctr,$idx) = (1,1);
1845: while ($ctr <= $ENV{'form.savemsgN'}) {
1846: if ($ENV{'form.savemsg'.$ctr} ne '') {
1847: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
1848: $idx++;
1849: }
1850: $ctr++;
1.41 ng 1851: }
1.119 ng 1852: $ctr = 0;
1853: while ($ctr < $ngrade) {
1854: if ($ENV{'form.newmsg'.$ctr} ne '') {
1855: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1856: $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1857: $idx++;
1858: }
1859: $ctr++;
1.41 ng 1860: }
1.119 ng 1861: $ENV{'form.savemsgN'} = --$idx;
1862: $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
1863: my $putresult = &Apache::lonnet::put
1864: ('nohist_handgrade',\%keyhash,
1865: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1866: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.41 ng 1867: }
1.44 ng 1868: # Called by Save & Refresh from Highlight Attribute Window
1.119 ng 1869: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
1.41 ng 1870: if ($ENV{'form.refresh'} eq 'on') {
1.86 ng 1871: my ($ctr,$total) = (0,0);
1872: while ($ctr < $ngrade) {
1873: $total++ if $ENV{'form.unamedom'.$ctr} ne '';
1874: $ctr++;
1875: }
1.41 ng 1876: $ENV{'form.NTSTU'}=$ngrade;
1.86 ng 1877: $ctr = 0;
1878: while ($ctr < $total) {
1879: my $processUser = $ENV{'form.unamedom'.$ctr};
1880: ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
1881: $ENV{'form.fullname'} = $$fullname{$processUser};
1882: &submission($request,$ctr,$total-1);
1.41 ng 1883: $ctr++;
1884: }
1885: return '';
1886: }
1.36 ng 1887:
1.121 ng 1888: # Go directly to grade student - from submission or link from chart page
1.120 ng 1889: if ($button eq 'Grade Student') {
1.121 ng 1890: (undef,undef,$ENV{'form.handgrade'},undef,undef) = &showResourceInfo($url);
1.120 ng 1891: my $processUser = $ENV{'form.unamedom'.$ENV{'form.studentNo'}};
1892: ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
1893: $ENV{'form.fullname'} = $$fullname{$processUser};
1894: &submission($request,0,0);
1895: return '';
1896: }
1897:
1.44 ng 1898: # Get the next/previous one or group of students
1.41 ng 1899: my $firststu = $ENV{'form.unamedom0'};
1900: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
1.119 ng 1901: my $ctr = 2;
1.41 ng 1902: while ($laststu eq '') {
1903: $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
1904: $ctr++;
1905: $laststu = $firststu if ($ctr > $ngrade);
1906: }
1.44 ng 1907:
1.41 ng 1908: my (@parsedlist,@nextlist);
1909: my ($nextflg) = 0;
1.53 albertel 1910: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41 ng 1911: if ($nextflg == 1 && $button =~ /Next$/) {
1912: push @parsedlist,$_;
1913: }
1914: $nextflg = 1 if ($_ eq $laststu);
1915: if ($button eq 'Previous') {
1916: last if ($_ eq $firststu);
1917: push @parsedlist,$_;
1918: }
1919: }
1920: $ctr = 0;
1921: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.145 albertel 1922: my ($partlist) = &response_type($url);
1.41 ng 1923: foreach my $student (@parsedlist) {
1.145 albertel 1924: my $submitonly=$ENV{'form.submitonly'};
1.41 ng 1925: my ($uname,$udom) = split(/:/,$student);
1.145 albertel 1926: if ($submitonly =~ /^(yes|graded)$/) {
1927: # my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
1928: my %status=&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
1929: my $submitted = 0;
1930: my $graded = 1;
1931: foreach (keys(%status)) {
1932: $submitted = 1 if ($status{$_} ne 'nothing');
1933: $graded = 0 if ($status{$_} =~ /^correct/);
1934: my ($foo,$partid,$foo1) = split(/\./,$_);
1935: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1936: $submitted = 0;
1937: }
1.41 ng 1938: }
1.145 albertel 1939: next if (!$submitted && ($submitonly eq 'yes' || $submitonly eq 'graded'));
1940: next if (!$graded && $submitonly eq 'graded');
1.41 ng 1941: }
1942: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 1943: last if ($ctr == $ntstu);
1.41 ng 1944: $ctr++;
1945: }
1.36 ng 1946:
1.41 ng 1947: $ctr = 0;
1948: my $total = scalar(@nextlist)-1;
1.39 ng 1949:
1.41 ng 1950: foreach (sort @nextlist) {
1951: my ($uname,$udom,$submitter) = split(/:/);
1.44 ng 1952: $ENV{'form.student'} = $uname;
1953: $ENV{'form.userdom'} = $udom;
1.41 ng 1954: $ENV{'form.fullname'} = $$fullname{$_};
1955: &submission($request,$ctr,$total);
1956: $ctr++;
1957: }
1958: if ($total < 0) {
1959: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
1960: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
1961: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1962: $the_end.=&show_grading_menu_form ($symb,$url);
1963: $request->print($the_end);
1964: }
1965: return '';
1.38 ng 1966: }
1.36 ng 1967:
1.44 ng 1968: #---- Save the score and award for each student, if changed
1.38 ng 1969: sub saveHandGrade {
1.41 ng 1970: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
1.104 albertel 1971: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1972: $ENV{'request.course.id'});
1973: if (!&canmodify($usec)) { return('not_allowed'); }
1.77 ng 1974: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
1975: my %newrecord = ();
1976: my ($pts,$wgt) = ('','');
1.41 ng 1977: foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1.125 ng 1978: my $dropMenu = $ENV{'form.GD_SEL'.$newflg.'_'.$_};
1979: if ($dropMenu eq 'excused') {
1.58 albertel 1980: if ($record{'resource.'.$_.'.solved'} ne 'excused') {
1981: $newrecord{'resource.'.$_.'.solved'} = 'excused';
1982: if (exists($record{'resource.'.$_.'.awarded'})) {
1983: $newrecord{'resource.'.$_.'.awarded'} = '';
1984: }
1.125 ng 1985: $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.58 albertel 1986: }
1.125 ng 1987: } elsif ($dropMenu eq 'reset status'
1988: && exists($record{'resource.'.$_.'.solved'})) { #don't bother if no old records -> no attempts
1989: $newrecord{'resource.'.$_.'.tries'} = 0;
1990: $newrecord{'resource.'.$_.'.solved'} = '';
1991: $newrecord{'resource.'.$_.'.award'} = '';
1992: $newrecord{'resource.'.$_.'.awarded'} = 0;
1993: $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1994: } elsif ($dropMenu eq '') {
1.77 ng 1995: $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
1996: $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
1997: $ENV{'form.RADVAL'.$newflg.'_'.$_});
1.71 ng 1998: return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
1.77 ng 1999: $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
1.44 ng 2000: $ENV{'form.WGT'.$newflg.'_'.$_};
1.41 ng 2001: my $partial= $pts/$wgt;
1.119 ng 2002: next if ($partial eq $record{'resource.'.$_.'.awarded'}); #do not update score for part if not changed.
1.44 ng 2003: $newrecord{'resource.'.$_.'.awarded'} = $partial
2004: if ($record{'resource.'.$_.'.awarded'} ne $partial);
2005: my $reckey = 'resource.'.$_.'.solved';
1.41 ng 2006: if ($partial == 0) {
1.44 ng 2007: $newrecord{$reckey} = 'incorrect_by_override'
2008: if ($record{$reckey} ne 'incorrect_by_override');
1.41 ng 2009: } else {
1.44 ng 2010: $newrecord{$reckey} = 'correct_by_override'
2011: if ($record{$reckey} ne 'correct_by_override');
1.41 ng 2012: }
1.44 ng 2013: $newrecord{'resource.'.$_.'.submitted_by'} = $submitter
2014: if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
1.122 ng 2015: $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.41 ng 2016: }
2017: }
1.44 ng 2018:
2019: if (scalar(keys(%newrecord)) > 0) {
2020: &Apache::lonnet::cstore(\%newrecord,$symb,
2021: $ENV{'request.course.id'},$domain,$stuname);
1.41 ng 2022: }
1.77 ng 2023: return '',$pts,$wgt;
1.36 ng 2024: }
1.38 ng 2025:
1.44 ng 2026: #--------------------------------------------------------------------------------------
2027: #
2028: #-------------------------- Next few routines handles grading by section or whole class
2029: #
2030: #--- Javascript to handle grading by section or whole class
1.42 ng 2031: sub viewgrades_js {
2032: my ($request) = shift;
2033:
1.41 ng 2034: $request->print(<<VIEWJAVASCRIPT);
2035: <script type="text/javascript" language="javascript">
1.45 ng 2036: function writePoint(partid,weight,point) {
1.125 ng 2037: var radioButton = document.classgrade["RADVAL_"+partid];
2038: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2039: if (point == "textval") {
1.125 ng 2040: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2041: if (isNaN(point) || parseFloat(point) < 0) {
2042: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2043: var resetbox = false;
2044: for (var i=0; i<radioButton.length; i++) {
2045: if (radioButton[i].checked) {
2046: textbox.value = i;
2047: resetbox = true;
2048: }
2049: }
2050: if (!resetbox) {
2051: textbox.value = "";
2052: }
2053: return;
2054: }
1.109 matthew 2055: if (parseFloat(point) > parseFloat(weight)) {
2056: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2057: ") greater than the weight for the part. Accept?");
2058: if (resp == false) {
2059: textbox.value = "";
2060: return;
2061: }
2062: }
1.42 ng 2063: for (var i=0; i<radioButton.length; i++) {
2064: radioButton[i].checked=false;
1.109 matthew 2065: if (parseFloat(point) == i) {
1.42 ng 2066: radioButton[i].checked=true;
2067: }
2068: }
1.41 ng 2069:
1.42 ng 2070: } else {
1.125 ng 2071: textbox.value = parseFloat(point);
1.42 ng 2072: }
1.41 ng 2073: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2074: var user = document.classgrade["ctr"+i].value;
2075: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2076: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2077: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2078: if (saveval != "correct") {
2079: scorename.value = point;
1.43 ng 2080: if (selname[0].selected != true) {
2081: selname[0].selected = true;
2082: }
1.42 ng 2083: }
2084: }
1.125 ng 2085: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2086: }
2087:
2088: function writeRadText(partid,weight) {
1.125 ng 2089: var selval = document.classgrade["SELVAL_"+partid];
2090: var radioButton = document.classgrade["RADVAL_"+partid];
2091: var textbox = document.classgrade["TEXTVAL_"+partid];
2092: if (selval[1].selected || selval[2].selected) {
1.42 ng 2093: for (var i=0; i<radioButton.length; i++) {
2094: radioButton[i].checked=false;
2095:
2096: }
2097: textbox.value = "";
2098:
2099: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2100: var user = document.classgrade["ctr"+i].value;
2101: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2102: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2103: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2104: if (saveval != "correct") {
2105: scorename.value = "";
1.125 ng 2106: if (selval[1].selected) {
2107: selname[1].selected = true;
2108: } else {
2109: selname[2].selected = true;
2110: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2111: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2112: }
1.42 ng 2113: }
2114: }
1.43 ng 2115: } else {
2116: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2117: var user = document.classgrade["ctr"+i].value;
2118: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2119: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2120: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.43 ng 2121: if (saveval != "correct") {
1.125 ng 2122: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2123: selname[0].selected = true;
2124: }
2125: }
2126: }
1.42 ng 2127: }
2128:
2129: function changeSelect(partid,user) {
1.125 ng 2130: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2131: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2132: var point = textbox.value;
1.125 ng 2133: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2134:
1.109 matthew 2135: if (isNaN(point) || parseFloat(point) < 0) {
2136: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2137: textbox.value = "";
2138: return;
2139: }
1.109 matthew 2140: if (parseFloat(point) > parseFloat(weight)) {
2141: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2142: ") greater than the weight of the part. Accept?");
2143: if (resp == false) {
2144: textbox.value = "";
2145: return;
2146: }
2147: }
1.42 ng 2148: selval[0].selected = true;
2149: }
2150:
2151: function changeOneScore(partid,user) {
1.125 ng 2152: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2153: if (selval[1].selected || selval[2].selected) {
2154: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2155: if (selval[2].selected) {
2156: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2157: }
1.42 ng 2158: }
2159: }
2160:
2161: function resetEntry(numpart) {
2162: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2163: var partid = document.classgrade["partid_"+ctpart].value;
2164: var radioButton = document.classgrade["RADVAL_"+partid];
2165: var textbox = document.classgrade["TEXTVAL_"+partid];
2166: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2167: for (var i=0; i<radioButton.length; i++) {
2168: radioButton[i].checked=false;
2169:
2170: }
2171: textbox.value = "";
2172: selval[0].selected = true;
2173:
2174: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2175: var user = document.classgrade["ctr"+i].value;
2176: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2177: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2178: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2179: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2180: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2181: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2182: if (saveselval == "excused") {
1.43 ng 2183: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2184: } else {
1.43 ng 2185: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2186: }
2187: }
1.41 ng 2188: }
1.42 ng 2189: }
2190:
1.41 ng 2191: </script>
2192: VIEWJAVASCRIPT
1.42 ng 2193: }
2194:
1.44 ng 2195: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2196: sub viewgrades {
2197: my ($request) = shift;
2198: &viewgrades_js($request);
1.41 ng 2199:
2200: my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
1.45 ng 2201: my $result='<h3><font color="#339933">Manual Grading</font></h3>';
1.38 ng 2202:
1.118 ng 2203: $result.='<font size=+1><b>Current Resource: </b>'.$ENV{'form.probTitle'}.'</font>'."\n";
1.41 ng 2204:
2205: #view individual student submission form - called using Javascript viewOneStudent
1.45 ng 2206: $result.=&jscriptNform($url,$symb);
1.41 ng 2207:
1.44 ng 2208: #beginning of class grading form
1.41 ng 2209: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.106 albertel 2210: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.41 ng 2211: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 2212: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.72 ng 2213: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n".
1.77 ng 2214: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.125 ng 2215: '<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n".
1.72 ng 2216: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
2217:
1.126 ng 2218: my $sectionClass;
1.52 albertel 2219: if ($ENV{'form.section'} eq 'all') {
1.126 ng 2220: $sectionClass='Class </h3>';
1.52 albertel 2221: } elsif ($ENV{'form.section'} eq 'no') {
1.126 ng 2222: $sectionClass='Students in no Section </h3>';
1.52 albertel 2223: } else {
1.126 ng 2224: $sectionClass='Students in Section '.$ENV{'form.section'}.'</h3>';
1.52 albertel 2225: }
1.126 ng 2226: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2227: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2228: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2229: #radio buttons/text box for assigning points for a section or class.
2230: #handles different parts of a problem
1.125 ng 2231: my ($partlist,$handgrade) = &response_type($url,$symb);
1.42 ng 2232: my %weight = ();
2233: my $ctsparts = 0;
1.41 ng 2234: $result.='<table border="0">';
1.45 ng 2235: my %seen = ();
1.42 ng 2236: for (sort keys(%$handgrade)) {
1.54 albertel 2237: my ($partid,$respid) = split (/_/,$_,2);
1.45 ng 2238: next if $seen{$partid};
2239: $seen{$partid}++;
1.147 albertel 2240: my $handgrade=$$handgrade{$_};
1.42 ng 2241: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
2242: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
2243:
1.44 ng 2244: $result.='<input type="hidden" name="partid_'.
2245: $ctsparts.'" value="'.$partid.'" />'."\n";
2246: $result.='<input type="hidden" name="weight_'.
2247: $partid.'" value="'.$weight{$partid}.'" />'."\n";
2248: $result.='<tr><td><b>Part '.$partid.' Point:</b> </td><td>';
1.42 ng 2249: $result.='<table border="0"><tr>';
1.41 ng 2250: my $ctr = 0;
1.42 ng 2251: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
2252: $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 2253: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.41 ng 2254: ','.$ctr.')" />'.$ctr."</td>\n";
2255: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
2256: $ctr++;
2257: }
2258: $result.='</tr></table>';
1.44 ng 2259: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 2260: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
2261: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 2262: $weight{$partid}.' (problem weight)</td>'."\n";
2263: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 2264: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 2265: $weight{$partid}.')"> '.
1.42 ng 2266: '<option selected="on"> </option>'.
1.125 ng 2267: '<option>excused</option>'.
2268: '<option>reset status</option></select></td></tr>'."\n";
1.42 ng 2269: $ctsparts++;
1.41 ng 2270: }
1.52 albertel 2271: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
2272: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 2273: $result.='<input type="button" value="Reset" '.
1.111 ng 2274: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41 ng 2275:
1.44 ng 2276: #table listing all the students in a section/class
2277: #header of table
1.126 ng 2278: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 2279: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 2280: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 2281: '<td>'.&nameUserString('header')."</td>\n";
1.146 albertel 2282: my (@parts) = sort(&getpartlist($url,$symb));
1.41 ng 2283: foreach my $part (@parts) {
2284: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 2285: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 2286: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
2287: if ($display =~ /^Partial Credit Factor/) {
1.54 albertel 2288: my ($partid) = &split_part_type($part);
1.53 albertel 2289: $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
1.42 ng 2290: $weight{$partid}.')</b></td>'."\n";
1.41 ng 2291: next;
2292: }
1.53 albertel 2293: $display =~ s|Problem Status|Grade Status<br />|;
1.41 ng 2294: $result.='<td><b>'.$display.'</b></td>'."\n";
2295: }
2296: $result.='</tr>';
1.44 ng 2297:
1.41 ng 2298: #get info for each student
1.44 ng 2299: #list all the students - with points and grade status
1.76 ng 2300: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
1.41 ng 2301: my $ctr = 0;
1.53 albertel 2302: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.90 albertel 2303: my $uname = $_;
2304: $uname=~s/:/_/;
2305: $result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
1.126 ng 2306: $ctr++;
1.41 ng 2307: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
1.126 ng 2308: $_,$$fullname{$_},\@parts,\%weight,$ctr);
1.41 ng 2309: }
2310: $result.='</table></td></tr></table>';
2311: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 2312: $result.='<input type="button" value="Save" '.
1.45 ng 2313: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96 albertel 2314: if (scalar(%$fullname) eq 0) {
2315: my $colspan=3+scalar(@parts);
1.116 ng 2316: $result='<font color="red">There are no students in section "'.$ENV{'form.section'}.
2317: '" with enrollment status "'.$ENV{'form.Status'}.'" to modify or grade.</font>';
1.96 albertel 2318: }
1.41 ng 2319: $result.=&show_grading_menu_form($symb,$url);
2320: return $result;
2321: }
2322:
1.44 ng 2323: #--- call by previous routine to display each student
1.41 ng 2324: sub viewstudentgrade {
1.130 albertel 2325: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight,$ctr) = @_;
1.44 ng 2326: my ($uname,$udom) = split(/:/,$student);
1.90 albertel 2327: $student=~s/:/_/;
1.44 ng 2328: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.126 ng 2329: my $result='<tr bgcolor="#ffffdd"><td align="right">'.$ctr.' </td><td> '.
1.44 ng 2330: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112 ng 2331: '\')"; TARGET=_self>'.$fullname.'</a> '.
2332: '<font color="#999999">('.$uname.($ENV{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
1.63 albertel 2333: foreach my $apart (@$parts) {
2334: my ($part,$type) = &split_part_type($apart);
1.41 ng 2335: my $score=$record{"resource.$part.$type"};
2336: if ($type eq 'awarded') {
1.42 ng 2337: my $pts = $score eq '' ? '' : $score*$$weight{$part};
2338: $result.='<input type="hidden" name="'.
1.89 albertel 2339: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.42 ng 2340: $result.='<td align="middle"><input type="text" name="'.
1.89 albertel 2341: 'GD_'.$student.'_'.$part.'_awarded" '.
2342: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 2343: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 2344: } elsif ($type eq 'solved') {
2345: my ($status,$foo)=split(/_/,$score,2);
2346: $status = 'nothing' if ($status eq '');
1.89 albertel 2347: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 2348: $part.'_solved_s" value="'.$status.'" />'."\n";
1.126 ng 2349: $result.='<td align="middle"> <select name="'.
1.89 albertel 2350: 'GD_'.$student.'_'.$part.'_solved" '.
2351: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125 ng 2352: $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>'
2353: : '<option selected="on"> </option><option>excused</option>')."\n";
2354: $result.='<option>reset status</option>';
1.126 ng 2355: $result.="</select> </td>\n";
1.122 ng 2356: } else {
2357: $result.='<input type="hidden" name="'.
2358: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
2359: "\n";
2360: $result.='<td align="middle"><input type="text" name="'.
2361: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
2362: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 2363: }
2364: }
2365: $result.='</tr>';
2366: return $result;
1.38 ng 2367: }
2368:
1.44 ng 2369: #--- change scores for all the students in a section/class
2370: # record does not get update if unchanged
1.38 ng 2371: sub editgrades {
1.41 ng 2372: my ($request) = @_;
2373:
2374: my $symb=$ENV{'form.symb'};
1.43 ng 2375: my $url =$ENV{'form.url'};
1.45 ng 2376: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.118 ng 2377: $title.='<font size=+1><b>Current Resource: </b>'.$ENV{'form.probTitle'}.'</font><br />'."\n";
1.44 ng 2378: $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
1.126 ng 2379:
1.44 ng 2380: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 2381: $result.= '<table border="0"><tr bgcolor="#deffff">'.
2382: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
2383: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 2384:
2385: my %scoreptr = (
2386: 'correct' =>'correct_by_override',
2387: 'incorrect'=>'incorrect_by_override',
2388: 'excused' =>'excused',
2389: 'ungraded' =>'ungraded_attempted',
2390: 'nothing' => '',
2391: );
1.56 matthew 2392: my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.34 ng 2393:
1.44 ng 2394: my (@partid);
2395: my %weight = ();
1.54 albertel 2396: my %columns = ();
1.44 ng 2397: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 2398:
1.146 albertel 2399: my (@parts) = sort(&getpartlist($url,$symb));
1.54 albertel 2400: my $header;
1.44 ng 2401: while ($ctr < $ENV{'form.totalparts'}) {
2402: my $partid = $ENV{'form.partid_'.$ctr};
2403: push @partid,$partid;
2404: $weight{$partid} = $ENV{'form.weight_'.$partid};
2405: $ctr++;
1.54 albertel 2406: }
2407: foreach my $partid (@partid) {
2408: $header .= '<td align="center"> <b>Old Score</b> </td>'.
2409: '<td align="center"> <b>New Score</b> </td>';
2410: $columns{$partid}=2;
2411: foreach my $stores (@parts) {
2412: my ($part,$type) = &split_part_type($stores);
2413: if ($part !~ m/^\Q$partid\E/) { next;}
2414: if ($type eq 'awarded' || $type eq 'solved') { next; }
2415: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
2416: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 2417: $display =~ s/Number of Attempts/Tries/;
2418: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
2419: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 2420: $columns{$partid}+=2;
2421: }
2422: }
2423: foreach my $partid (@partid) {
2424: $result .= '<td colspan="'.$columns{$partid}.
2425: '" align="center"><b>Part '.$partid.
1.44 ng 2426: '</b> (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 2427:
1.44 ng 2428: }
2429: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 2430: $result .= $header;
1.44 ng 2431: $result .= '</tr>'."\n";
1.93 albertel 2432: my $noupdate;
1.126 ng 2433: my ($updateCtr,$noupdateCtr) = (1,1);
1.44 ng 2434: for ($i=0; $i<$ENV{'form.total'}; $i++) {
1.93 albertel 2435: my $line;
1.44 ng 2436: my $user = $ENV{'form.ctr'.$i};
1.92 albertel 2437: my $usercolon = $user;
2438: $usercolon =~s/_/:/;
2439: my ($uname,$udom)=split(/_/,$user);
1.44 ng 2440: my %newrecord;
2441: my $updateflag = 0;
1.129 ng 2442: $line .= '<td>'.&nameUserString(undef,$$fullname{$usercolon},$uname,$udom).'</td>';
1.108 albertel 2443: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 2444: if (!&canmodify($usec)) {
1.126 ng 2445: my $numcols=scalar(@partid)*4+2;
1.105 albertel 2446: $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
2447: next;
2448: }
1.44 ng 2449: foreach (@partid) {
1.54 albertel 2450: my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
2451: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
2452: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
2453: my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
2454:
2455: my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
2456: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
2457: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 2458: my $score;
2459: if ($partial eq '') {
1.54 albertel 2460: $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 2461: } elsif ($partial > 0) {
2462: $score = 'correct_by_override';
2463: } elsif ($partial == 0) {
2464: $score = 'incorrect_by_override';
2465: }
1.125 ng 2466: my $dropMenu = $ENV{'form.GD_'.$user.'_'.$_.'_solved'};
2467: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
2468:
2469: if ($dropMenu eq 'reset status' &&
2470: $old_score ne '') { # ignore if no previous attempts => nothing to reset
2471: $newrecord{'resource.'.$_.'.tries'} = 0;
2472: $newrecord{'resource.'.$_.'.solved'} = '';
2473: $newrecord{'resource.'.$_.'.award'} = '';
2474: $newrecord{'resource.'.$_.'.awarded'} = 0;
2475: $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
2476: $updateflag = 1;
1.139 albertel 2477: } elsif (!($old_part eq $partial && $old_score eq $score)) {
2478: $updateflag = 1;
2479: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
2480: $newrecord{'resource.'.$_.'.solved'} = $score;
2481: $rec_update++;
1.125 ng 2482: }
2483:
1.93 albertel 2484: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 2485: '<td align="center">'.$awarded.
2486: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 2487:
1.54 albertel 2488:
2489: my $partid=$_;
2490: foreach my $stores (@parts) {
2491: my ($part,$type) = &split_part_type($stores);
2492: if ($part !~ m/^\Q$partid\E/) { next;}
2493: if ($type eq 'awarded' || $type eq 'solved') { next; }
2494: my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
2495: my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
2496: if ($awarded ne '' && $awarded ne $old_aw) {
2497: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.122 ng 2498: $newrecord{'resource.'.$part.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.54 albertel 2499: $updateflag=1;
2500: }
1.93 albertel 2501: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 2502: '<td align="center">'.$awarded.' </td>';
2503: }
1.44 ng 2504: }
1.93 albertel 2505: $line.='</tr>'."\n";
1.44 ng 2506: if ($updateflag) {
2507: $count++;
2508: &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
1.89 albertel 2509: $udom,$uname);
1.126 ng 2510: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
2511: $updateCtr++;
1.93 albertel 2512: } else {
1.126 ng 2513: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
2514: $noupdateCtr++;
1.44 ng 2515: }
1.93 albertel 2516: }
2517: if ($noupdate) {
1.126 ng 2518: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
2519: my $numcols=scalar(@partid)*4+2;
2520: $result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occurred For the Students Below</td></tr>'.$noupdate;
1.44 ng 2521: }
1.72 ng 2522: $result .= '</table></td></tr></table>'."\n".
2523: &show_grading_menu_form ($symb,$url);
1.125 ng 2524: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 2525: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
2526: '<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
2527: return $title.$msg.$result;
1.5 albertel 2528: }
1.54 albertel 2529:
2530: sub split_part_type {
2531: my ($partstr) = @_;
2532: my ($temp,@allparts)=split(/_/,$partstr);
2533: my $type=pop(@allparts);
2534: my $part=join('.',@allparts);
2535: return ($part,$type);
2536: }
2537:
1.44 ng 2538: #------------- end of section for handling grading by section/class ---------
2539: #
2540: #----------------------------------------------------------------------------
2541:
1.5 albertel 2542:
1.44 ng 2543: #----------------------------------------------------------------------------
2544: #
2545: #-------------------------- Next few routines handles grading by csv upload
2546: #
2547: #--- Javascript to handle csv upload
1.27 albertel 2548: sub csvupload_javascript_reverse_associate {
2549: return(<<ENDPICK);
2550: function verify(vf) {
2551: var foundsomething=0;
2552: var founduname=0;
2553: var founddomain=0;
2554: for (i=0;i<=vf.nfields.value;i++) {
2555: tw=eval('vf.f'+i+'.selectedIndex');
2556: if (i==0 && tw!=0) { founduname=1; }
2557: if (i==1 && tw!=0) { founddomain=1; }
2558: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
2559: }
2560: if (founduname==0 || founddomain==0) {
2561: alert('You need to specify at both the username and domain');
2562: return;
2563: }
2564: if (foundsomething==0) {
2565: alert('You need to specify at least one grading field');
2566: return;
2567: }
2568: vf.submit();
2569: }
2570: function flip(vf,tf) {
2571: var nw=eval('vf.f'+tf+'.selectedIndex');
2572: var i;
2573: for (i=0;i<=vf.nfields.value;i++) {
2574: //can not pick the same destination field for both name and domain
2575: if (((i ==0)||(i ==1)) &&
2576: ((tf==0)||(tf==1)) &&
2577: (i!=tf) &&
2578: (eval('vf.f'+i+'.selectedIndex')==nw)) {
2579: eval('vf.f'+i+'.selectedIndex=0;')
2580: }
2581: }
2582: }
2583: ENDPICK
2584: }
2585:
2586: sub csvupload_javascript_forward_associate {
2587: return(<<ENDPICK);
2588: function verify(vf) {
2589: var foundsomething=0;
2590: var founduname=0;
2591: var founddomain=0;
2592: for (i=0;i<=vf.nfields.value;i++) {
2593: tw=eval('vf.f'+i+'.selectedIndex');
2594: if (tw==1) { founduname=1; }
2595: if (tw==2) { founddomain=1; }
2596: if (tw>2) { foundsomething=1; }
2597: }
2598: if (founduname==0 || founddomain==0) {
2599: alert('You need to specify at both the username and domain');
2600: return;
2601: }
2602: if (foundsomething==0) {
2603: alert('You need to specify at least one grading field');
2604: return;
2605: }
2606: vf.submit();
2607: }
2608: function flip(vf,tf) {
2609: var nw=eval('vf.f'+tf+'.selectedIndex');
2610: var i;
2611: //can not pick the same destination field twice
2612: for (i=0;i<=vf.nfields.value;i++) {
2613: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
2614: eval('vf.f'+i+'.selectedIndex=0;')
2615: }
2616: }
2617: }
2618: ENDPICK
2619: }
2620:
1.26 albertel 2621: sub csvuploadmap_header {
1.41 ng 2622: my ($request,$symb,$url,$datatoken,$distotal)= @_;
2623: my $javascript;
2624: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2625: $javascript=&csvupload_javascript_reverse_associate();
2626: } else {
2627: $javascript=&csvupload_javascript_forward_associate();
2628: }
1.45 ng 2629:
1.122 ng 2630: my ($result) = &showResourceInfo($url,$ENV{'form.probTitle'});
1.118 ng 2631:
1.41 ng 2632: $request->print(<<ENDPICK);
1.26 albertel 2633: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 2634: <h3><font color="#339933">Uploading Class Grades</font></h3>
2635: $result
1.26 albertel 2636: <hr>
2637: <h3>Identify fields</h3>
2638: Total number of records found in file: $distotal <hr />
2639: Enter as many fields as you can. The system will inform you and bring you back
2640: to this page if the data selected is insufficient to run your class.<hr />
2641: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
2642: <input type="hidden" name="associate" value="" />
2643: <input type="hidden" name="phase" value="three" />
2644: <input type="hidden" name="datatoken" value="$datatoken" />
2645: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
2646: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
2647: <input type="hidden" name="upfile_associate"
2648: value="$ENV{'form.upfile_associate'}" />
2649: <input type="hidden" name="symb" value="$symb" />
2650: <input type="hidden" name="url" value="$url" />
1.77 ng 2651: <input type="hidden" name="saveState" value="$ENV{'form.saveState'}" />
1.72 ng 2652: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
1.26 albertel 2653: <input type="hidden" name="command" value="csvuploadassign" />
2654: <hr />
2655: <script type="text/javascript" language="Javascript">
2656: $javascript
2657: </script>
2658: ENDPICK
1.118 ng 2659: return '';
1.26 albertel 2660:
2661: }
2662:
2663: sub csvupload_fields {
1.146 albertel 2664: my ($url,$symb) = @_;
2665: my (@parts) = &getpartlist($url,$symb);
1.41 ng 2666: my @fields=(['username','Student Username'],['domain','Student Domain']);
2667: foreach my $part (sort(@parts)) {
2668: my @datum;
2669: my $display=&Apache::lonnet::metadata($url,$part.'.display');
2670: my $name=$part;
2671: if (!$display) { $display = $name; }
2672: @datum=($name,$display);
2673: push(@fields,\@datum);
2674: }
2675: return (@fields);
1.26 albertel 2676: }
2677:
2678: sub csvuploadmap_footer {
1.41 ng 2679: my ($request,$i,$keyfields) =@_;
2680: $request->print(<<ENDPICK);
1.26 albertel 2681: </table>
2682: <input type="hidden" name="nfields" value="$i" />
2683: <input type="hidden" name="keyfields" value="$keyfields" />
2684: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
2685: </form>
2686: ENDPICK
2687: }
2688:
1.86 ng 2689: sub upcsvScores_form {
2690: my ($request) = shift;
2691: my ($symb,$url)=&get_symb_and_url($request);
2692: if (!$symb) {return '';}
2693: my $result =<<CSVFORMJS;
2694: <script type="text/javascript" language="javascript">
2695: function checkUpload(formname) {
2696: if (formname.upfile.value == "") {
2697: alert("Please use the browse button to select a file from your local directory.");
2698: return false;
2699: }
2700: formname.submit();
2701: }
2702: </script>
2703: CSVFORMJS
2704: $ENV{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.118 ng 2705: my ($table) = &showResourceInfo($url,$ENV{'form.probTitle'});
2706: $result.=$table;
1.86 ng 2707: $result.='<br /><table width=100% border=0><tr><td bgcolor="#777777">'."\n";
2708: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.118 ng 2709: $result.=' <b>Specify a file containing the class scores for current resource'.
1.86 ng 2710: '.</b></td></tr>'."\n";
2711: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2712: my $upfile_select=&Apache::loncommon::upfile_select_html();
2713: $result.=<<ENDUPFORM;
1.106 albertel 2714: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 2715: <input type="hidden" name="symb" value="$symb" />
2716: <input type="hidden" name="url" value="$url" />
2717: <input type="hidden" name="command" value="csvuploadmap" />
2718: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
2719: <input type="hidden" name="saveState" value="$ENV{'form.saveState'}" />
2720: $upfile_select
2721: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />
2722:
2723: </form>
2724: ENDUPFORM
2725: $result.='</td></tr></table>'."\n";
2726: $result.='</td></tr></table><br /><br />'."\n";
2727: $result.=&show_grading_menu_form($symb,$url);
2728: return $result;
2729: }
2730:
2731:
1.26 albertel 2732: sub csvuploadmap {
1.41 ng 2733: my ($request)= @_;
2734: my ($symb,$url)=&get_symb_and_url($request);
2735: if (!$symb) {return '';}
1.72 ng 2736:
1.41 ng 2737: my $datatoken;
2738: if (!$ENV{'form.datatoken'}) {
2739: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 2740: } else {
1.41 ng 2741: $datatoken=$ENV{'form.datatoken'};
2742: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 2743: }
1.41 ng 2744: my @records=&Apache::loncommon::upfile_record_sep();
2745: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
2746: my ($i,$keyfields);
2747: if (@records) {
1.146 albertel 2748: my @fields=&csvupload_fields($url,$symb);
1.45 ng 2749:
1.41 ng 2750: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2751: &Apache::loncommon::csv_print_samples($request,\@records);
2752: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
2753: \@fields);
2754: foreach (@fields) { $keyfields.=$_->[0].','; }
2755: chop($keyfields);
2756: } else {
2757: unshift(@fields,['none','']);
2758: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
2759: \@fields);
2760: my %sone=&Apache::loncommon::record_sep($records[0]);
2761: $keyfields=join(',',sort(keys(%sone)));
2762: }
2763: }
2764: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 2765: $request->print(&show_grading_menu_form($symb,$url));
2766:
1.41 ng 2767: return '';
1.27 albertel 2768: }
2769:
2770: sub csvuploadassign {
1.41 ng 2771: my ($request)= @_;
2772: my ($symb,$url)=&get_symb_and_url($request);
2773: if (!$symb) {return '';}
2774: &Apache::loncommon::load_tmp_file($request);
1.44 ng 2775: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.41 ng 2776: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
2777: my %fields=();
2778: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
2779: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2780: if ($ENV{'form.f'.$i} ne 'none') {
2781: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
2782: }
2783: } else {
2784: if ($ENV{'form.f'.$i} ne 'none') {
2785: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
2786: }
2787: }
1.27 albertel 2788: }
1.41 ng 2789: $request->print('<h3>Assigning Grades</h3>');
2790: my $courseid=$ENV{'request.course.id'};
1.97 albertel 2791: my ($classlist) = &getclasslist('all',0);
1.106 albertel 2792: my @notallowed;
1.41 ng 2793: my @skipped;
2794: my $countdone=0;
2795: foreach my $grade (@gradedata) {
2796: my %entries=&Apache::loncommon::record_sep($grade);
2797: my $username=$entries{$fields{'username'}};
2798: my $domain=$entries{$fields{'domain'}};
2799: if (!exists($$classlist{"$username:$domain"})) {
2800: push(@skipped,"$username:$domain");
2801: next;
2802: }
1.108 albertel 2803: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 2804: if (!&canmodify($usec)) {
2805: push(@notallowed,"$username:$domain");
2806: next;
2807: }
1.41 ng 2808: my %grades;
2809: foreach my $dest (keys(%fields)) {
2810: if ($dest eq 'username' || $dest eq 'domain') { next; }
2811: if ($entries{$fields{$dest}} eq '') { next; }
2812: my $store_key=$dest;
2813: $store_key=~s/^stores/resource/;
2814: $store_key=~s/_/\./g;
2815: $grades{$store_key}=$entries{$fields{$dest}};
2816: }
2817: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
2818: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
2819: $domain,$username);
2820: $request->print('.');
2821: $request->rflush();
2822: $countdone++;
2823: }
2824: $request->print("<br />Stored $countdone students\n");
2825: if (@skipped) {
1.106 albertel 2826: $request->print('<p<font size="+1"><b>Skipped Students</b></font></p>');
2827: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
2828: }
2829: if (@notallowed) {
2830: $request->print('<p><font size="+1" color="red"><b>Students Not Allowed to Modify</b></font></p>');
2831: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 2832: }
1.106 albertel 2833: $request->print("<br />\n");
1.41 ng 2834: $request->print(&show_grading_menu_form($symb,$url));
2835: return '';
1.26 albertel 2836: }
1.44 ng 2837: #------------- end of section for handling csv file upload ---------
2838: #
2839: #-------------------------------------------------------------------
2840: #
1.122 ng 2841: #-------------- Next few routines handle grading by page/sequence
1.72 ng 2842: #
2843: #--- Select a page/sequence and a student to grade
1.68 ng 2844: sub pickStudentPage {
2845: my ($request) = shift;
2846:
2847: $request->print(<<LISTJAVASCRIPT);
2848: <script type="text/javascript" language="javascript">
2849:
2850: function checkPickOne(formname) {
1.76 ng 2851: if (radioSelection(formname.student) == null) {
1.68 ng 2852: alert("Please select the student you wish to grade.");
2853: return;
2854: }
1.125 ng 2855: ptr = pullDownSelection(formname.selectpage);
2856: formname.page.value = formname["page"+ptr].value;
2857: formname.title.value = formname["title"+ptr].value;
1.68 ng 2858: formname.submit();
2859: }
2860:
2861: </script>
2862: LISTJAVASCRIPT
1.118 ng 2863: &commonJSfunctions($request);
1.72 ng 2864: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2865: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2866: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2867: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2868:
2869: my $result='<h3><font color="#339933"> '.
2870: 'Manual Grading by Page or Sequence</font></h3>';
2871:
1.80 ng 2872: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 2873: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 2874: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 2875: my ($curpage) =&Apache::lonnet::decode_symb($symb);
2876: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
2877: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 2878: my $ctr=0;
1.68 ng 2879: foreach (@$titles) {
2880: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 2881: $result.='<option value="'.$ctr.'" '.
1.71 ng 2882: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
2883: '>'.$showtitle.'</option>'."\n";
1.70 ng 2884: $ctr++;
1.68 ng 2885: }
2886: $result.= '</select>'."<br>\n";
1.70 ng 2887: $ctr=0;
2888: foreach (@$titles) {
2889: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
2890: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
2891: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
2892: $ctr++;
2893: }
1.72 ng 2894: $result.='<input type="hidden" name="page" />'."\n".
2895: '<input type="hidden" name="title" />'."\n";
1.68 ng 2896:
1.144 albertel 2897: $result.=' <b>View Problems Text: </b><input type="radio" name="vProb" value="no" checked="on" /> no '."\n".
1.71 ng 2898: '<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
1.72 ng 2899:
1.71 ng 2900: $result.=' <b>Submission Details: </b>'.
2901: '<input type="radio" name="lastSub" value="none" /> none'."\n".
1.122 ng 2902: '<input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions'."\n".
1.71 ng 2903: '<input type="radio" name="lastSub" value="all" /> all details'."\n";
1.72 ng 2904:
1.68 ng 2905: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.118 ng 2906: '<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n".
1.72 ng 2907: '<input type="hidden" name="command" value="displayPage" />'."\n".
2908: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.80 ng 2909: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2910: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."<br />\n";
1.72 ng 2911:
1.80 ng 2912: $result.=' <input type="button" '.
1.126 ng 2913: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 2914:
1.68 ng 2915: $request->print($result);
2916:
1.126 ng 2917: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br>'.
1.68 ng 2918: '<table border="0"><tr><td bgcolor="#777777">'.
2919: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 2920: '<td align="right"> <b>No.</b></td>'.
1.129 ng 2921: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 2922: '<td align="right"> <b>No.</b></td>'.
1.129 ng 2923: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 2924:
1.76 ng 2925: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 2926: my $ptr = 1;
2927: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
2928: my ($uname,$udom) = split(/:/,$student);
1.126 ng 2929: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
2930: $studentTable.='<td align="right">'.$ptr.' </td>';
1.129 ng 2931: $studentTable.='<td> <input type="radio" name="student" value="'.$student.'" /> '
2932: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."\n";
1.126 ng 2933: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 2934: $ptr++;
2935: }
1.126 ng 2936: $studentTable.='</td><td> </td><td> ' if ($ptr%2 == 0);
1.68 ng 2937: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.126 ng 2938: $studentTable.='<input type="button" '.
2939: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 2940:
2941: $studentTable.=&show_grading_menu_form($symb,$url);
2942: $request->print($studentTable);
2943:
2944: return '';
2945: }
2946:
2947: sub getSymbMap {
1.74 albertel 2948: my ($request) = @_;
1.132 bowersj2 2949: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 2950:
2951: my %symbx = ();
2952: my @titles = ();
1.117 bowersj2 2953: my $minder = 0;
2954:
2955: # Gather every sequence that has problems.
2956: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); }, 1);
2957: for my $sequence ($navmap->getById('0.0'), @sequences) {
2958: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
2959: my $title = $minder.'.'.$sequence->compTitle();
2960: push @titles, $title; # minder in case two titles are identical
2961: $symbx{$title} = $sequence->symb();
2962: $minder++;
2963: }
1.68 ng 2964: }
2965:
2966: $navmap->untieHashes();
2967: return \@titles,\%symbx;
2968: }
2969:
1.72 ng 2970: #
2971: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 2972: sub displayPage {
2973: my ($request) = shift;
2974:
1.72 ng 2975: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2976: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2977: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2978: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2979: my $pageTitle = $ENV{'form.page'};
1.103 albertel 2980: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.70 ng 2981: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.103 albertel 2982: my $usec=$classlist->{$ENV{'form.student'}}[5];
2983: if (!&canview($usec)) {
2984: $request->print('<font color="red">Unable to view requested student.('.$ENV{'form.student'}.')</font>');
2985: $request->print(&show_grading_menu_form($symb,$url));
2986: return;
2987: }
1.70 ng 2988: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
1.129 ng 2989: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$ENV{'form.student'}},$uname,$udom).
2990: '</h3>'."\n";
1.71 ng 2991: &sub_page_js($request);
2992: $request->print($result);
2993:
1.132 bowersj2 2994: my $navmap = Apache::lonnavmaps::navmap->new();
1.136 www 2995: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($ENV{'form.page'});
1.68 ng 2996: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2997:
2998: my $iterator = $navmap->getIterator($map->map_start(),
2999: $map->map_finish());
3000:
1.71 ng 3001: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3002: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.125 ng 3003: '<input type="hidden" name="fullname" value="'.$$fullname{$ENV{'form.student'}}.'" />'."\n".
1.72 ng 3004: '<input type="hidden" name="student" value="'.$ENV{'form.student'}.'" />'."\n".
3005: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
3006: '<input type="hidden" name="title" value="'.$ENV{'form.title'}.'" />'."\n".
3007: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3008: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.125 ng 3009: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.77 ng 3010: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
1.71 ng 3011:
3012: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
3013: '/check.gif" height="16" border="0" />';
3014:
1.118 ng 3015: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
3016: ' symbol.'."\n".
1.71 ng 3017: '<table border="0"><tr><td bgcolor="#777777">'.
3018: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 3019: '<td align="center"><b> Prob. </b></td>'.
3020: '<td><b> '.($ENV{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 3021:
1.101 albertel 3022: my ($depth,$question) = (1,1);
1.68 ng 3023: $iterator->next(); # skip the first BEGIN_MAP
3024: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 3025: while ($depth > 0) {
1.68 ng 3026: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3027: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 3028:
1.120 ng 3029: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 3030: my $parts = $curRes->parts();
1.68 ng 3031: my $title = $curRes->compTitle();
1.71 ng 3032: my $symbx = $curRes->symb();
3033: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
3034: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
3035: $studentTable.='<td valign="top">';
1.144 albertel 3036: if ($ENV{'form.vProb'} eq 'yes' ) {
3037: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
3038: undef,'both');
1.71 ng 3039: } else {
1.116 ng 3040: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$ENV{'request.course.id'});
1.80 ng 3041: $companswer =~ s|<form(.*?)>||g;
3042: $companswer =~ s|</form>||g;
1.71 ng 3043: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 3044: # $companswer =~ s/$1/ /ms;
3045: # $request->print('match='.$1."<br>\n");
1.71 ng 3046: # }
1.116 ng 3047: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.71 ng 3048: $studentTable.=' <b>'.$title.'</b> <br> <b>Correct answer:</b><br>'.$companswer;
3049: }
3050:
3051: my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname);
1.125 ng 3052:
1.71 ng 3053: if ($ENV{'form.lastSub'} eq 'datesub') {
3054: if ($record{'version'} eq '') {
3055: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
3056: } else {
1.116 ng 3057: my %responseType = ();
3058: foreach my $partid (@{$parts}) {
1.147 albertel 3059: my @responseIds =$curRes->responseIds($partid);
3060: my @responseType =$curRes->responseType($partid);
3061: my %responseIds;
3062: for (my $i=0;$i<=$#responseIds;$i++) {
3063: $responseIds{$responseIds[$i]}=$responseType[$i];
3064: }
3065: $responseType{$partid} = \%responseIds;
1.116 ng 3066: }
1.148 albertel 3067: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 3068:
1.71 ng 3069: }
3070: } elsif ($ENV{'form.lastSub'} eq 'all') {
3071: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
3072: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
3073: $ENV{'request.course.id'},
3074: '','.submission');
3075:
3076: }
1.103 albertel 3077: if (&canmodify($usec)) {
3078: foreach my $partid (@{$parts}) {
3079: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
3080: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
3081: $question++;
3082: }
1.71 ng 3083: }
3084: $studentTable.='</td></tr>';
1.68 ng 3085:
1.103 albertel 3086: }
1.68 ng 3087: $curRes = $iterator->next();
3088: }
3089:
1.98 albertel 3090: $navmap->untieHashes();
3091:
1.71 ng 3092: $studentTable.='</td></tr></table></td></tr></table>'."\n".
1.125 ng 3093: '<input type="button" value="Save" '.
1.71 ng 3094: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
3095: '</form>'."\n";
3096: $studentTable.=&show_grading_menu_form($symb,$url);
3097: $request->print($studentTable);
3098:
3099: return '';
1.119 ng 3100: }
3101:
3102: sub displaySubByDates {
1.148 albertel 3103: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.119 ng 3104: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
3105: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
3106: '<td><b>Date/Time</b></td>'.
3107: '<td><b>Submission</b></td>'.
3108: '<td><b>Status </b></td></tr>';
3109: my ($version);
3110: my %mark;
1.148 albertel 3111: my %orders;
1.119 ng 3112: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 3113: if (!exists($$record{'1:timestamp'})) {
3114: return '<br /> <font color="red">Nothing submitted - no attempts</font><br />';
3115: }
1.119 ng 3116: for ($version=1;$version<=$$record{'version'};$version++) {
3117: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
3118: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
3119: my @versionKeys = split(/\:/,$$record{$version.':keys'});
3120: my @displaySub = ();
3121: foreach my $partid (@{$parts}) {
1.147 albertel 3122: my @matchKey = sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys);
1.122 ng 3123: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.147 albertel 3124: foreach my $matchKey (@matchKey) {
3125: if (exists $$record{$version.':'.$matchKey}) {
3126: my ($responseId)=($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/);
3127: $displaySub[0].='<b>Part '.$partid.' ';
3128: $displaySub[0].='<font color="#999999">(ID '.
3129: $responseId.')</font> ';
3130: if ($$record{"$version:resource.$partid.tries"} eq '') {
3131: $displaySub[0].='Trial not counted';
3132: } else {
3133: $displaySub[0].='Trial '.
3134: $$record{"$version:resource.$partid.tries"};
3135: }
3136: my $responseType=$responseType->{$partid}->{$responseId};
1.148 albertel 3137: if (!exists($orders{$partid})) { $orders{$partid}={}; }
3138: if (!exists($orders{$partid}->{$responseId})) {
3139: $orders{$partid}->{$responseId}=
3140: &get_order($partid,$responseId,$symb,$uname,$udom);
3141: }
1.147 albertel 3142: $displaySub[0].='</b> '.
1.148 albertel 3143: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:").'<br />';
1.147 albertel 3144: }
3145: }
3146: if (exists $$record{"$version:resource.$partid.award"}) {
3147: $displaySub[1].='<b>Part '.$partid.'</b> '.
3148: lc($$record{"$version:resource.$partid.award"}).' '.
3149: $mark{$$record{"$version:resource.$partid.solved"}}.
3150: '<br />';
3151: }
3152: if (exists $$record{"$version:resource.$partid.regrader"}) {
3153: $displaySub[2].=$$record{"$version:resource.$partid.regrader"}.
3154: ' (<b>Part:</b> '.$partid.')';
3155: }
3156: }
3157: # needed because old essay regrader has not parts info
3158: if (exists $$record{"$version:resource.regrader"}) {
3159: $displaySub[2].=$$record{"$version:resource.regrader"};
3160: }
3161: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
3162: if ($displaySub[2]) {
3163: $studentTable.='Manually graded by '.$displaySub[2];
3164: }
3165: $studentTable.=' </td></tr>';
3166:
1.119 ng 3167: }
3168: $studentTable.='</table></td></tr></table>';
3169: return $studentTable;
1.71 ng 3170: }
3171:
3172: sub updateGradeByPage {
3173: my ($request) = shift;
3174:
3175: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
3176: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
3177: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
3178: my $pageTitle = $ENV{'form.page'};
1.103 albertel 3179: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.71 ng 3180: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.103 albertel 3181: my $usec=$classlist->{$ENV{'form.student'}}[5];
3182: if (!&canmodify($usec)) {
3183: $request->print('<font color="red">Unable to modify requested student.('.$ENV{'form.student'}.'</font>');
3184: $request->print(&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'}));
3185: return;
3186: }
1.71 ng 3187: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
1.129 ng 3188: $result.='<h3> Student: '.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom).
3189: '</h3>'."\n";
1.70 ng 3190:
1.68 ng 3191: $request->print($result);
3192:
1.132 bowersj2 3193: my $navmap = Apache::lonnavmaps::navmap->new();
1.136 www 3194: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $ENV{'form.page'});
1.71 ng 3195: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
3196:
3197: my $iterator = $navmap->getIterator($map->map_start(),
3198: $map->map_finish());
1.70 ng 3199:
1.71 ng 3200: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 3201: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 3202: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 3203: '<td><b> Title </b></td>'.
3204: '<td><b> Previous Score </b></td>'.
3205: '<td><b> New Score </b></td></tr>';
3206:
3207: $iterator->next(); # skip the first BEGIN_MAP
3208: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 3209: my ($depth,$question,$changeflag)= (1,1,0);
3210: while ($depth > 0) {
1.71 ng 3211: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3212: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 3213:
3214: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 3215: my $parts = $curRes->parts();
1.71 ng 3216: my $title = $curRes->compTitle();
3217: my $symbx = $curRes->symb();
3218: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
3219: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
3220: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
3221:
3222: my %newrecord=();
3223: my @displayPts=();
3224: foreach my $partid (@{$parts}) {
3225: my $newpts = $ENV{'form.GD_BOX'.$question.'_'.$partid};
3226: my $oldpts = $ENV{'form.oldpts'.$question.'_'.$partid};
3227:
3228: my $wgt = $ENV{'form.WGT'.$question.'_'.$partid} != 0 ?
3229: $ENV{'form.WGT'.$question.'_'.$partid} : 1;
3230: my $partial = $newpts/$wgt;
3231: my $score;
3232: if ($partial > 0) {
3233: $score = 'correct_by_override';
1.125 ng 3234: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 3235: $score = 'incorrect_by_override';
3236: }
1.125 ng 3237: my $dropMenu = $ENV{'form.GD_SEL'.$question.'_'.$partid};
3238: if ($dropMenu eq 'excused') {
1.71 ng 3239: $partial = '';
3240: $score = 'excused';
1.125 ng 3241: } elsif ($dropMenu eq 'reset status'
3242: && $ENV{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
3243: $newrecord{'resource.'.$partid.'.tries'} = 0;
3244: $newrecord{'resource.'.$partid.'.solved'} = '';
3245: $newrecord{'resource.'.$partid.'.award'} = '';
3246: $newrecord{'resource.'.$partid.'.awarded'} = 0;
3247: $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}";
3248: $changeflag++;
3249: $newpts = '';
1.71 ng 3250: }
1.125 ng 3251:
1.71 ng 3252: my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid};
3253: $displayPts[0].=' <b>Part</b> '.$partid.' = '.
3254: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
3255: ' <br>';
3256: $displayPts[1].=' <b>Part</b> '.$partid.' = '.
1.125 ng 3257: (($score eq 'excused') ? 'excused' : $newpts).
1.71 ng 3258: ' <br>';
3259:
3260: $question++;
1.125 ng 3261: next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused'));
3262:
1.71 ng 3263: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 3264: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
3265: $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}"
3266: if (scalar(keys(%newrecord)) > 0);
1.71 ng 3267:
3268: $changeflag++;
3269: }
3270: if (scalar(keys(%newrecord)) > 0) {
3271: &Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'},
3272: $udom,$uname);
3273: }
1.125 ng 3274:
1.71 ng 3275: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
3276: '<td valign="top">'.$displayPts[1].'</td>'.
3277: '</tr>';
1.68 ng 3278:
3279: }
1.71 ng 3280: $curRes = $iterator->next();
1.68 ng 3281: }
1.98 albertel 3282:
3283: $navmap->untieHashes();
1.68 ng 3284:
1.71 ng 3285: $studentTable.='</td></tr></table></td></tr></table>';
3286: $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
1.76 ng 3287: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
3288: 'The scores were changed for '.
3289: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
3290: $request->print($grademsg.$studentTable);
1.68 ng 3291:
1.70 ng 3292: return '';
3293: }
3294:
1.72 ng 3295: #-------- end of section for handling grading by page/sequence ---------
3296: #
3297: #-------------------------------------------------------------------
3298:
1.75 albertel 3299: #--------------------Scantron Grading-----------------------------------
3300: #
3301: #------ start of section for handling grading by page/sequence ---------
3302:
1.81 albertel 3303: sub defaultFormData {
3304: my ($symb,$url)=@_;
3305: return '
3306: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3307: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3308: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
3309: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
3310: }
3311:
1.75 albertel 3312: sub getSequenceDropDown {
3313: my ($request,$symb)=@_;
3314: my $result='<select name="selectpage">'."\n";
3315: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 3316: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 3317: my $ctr=0;
3318: foreach (@$titles) {
3319: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3320: $result.='<option value="'.$$symbx{$_}.'" '.
3321: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
3322: '>'.$showtitle.'</option>'."\n";
3323: $ctr++;
3324: }
3325: $result.= '</select>';
3326: return $result;
3327: }
3328:
1.81 albertel 3329: sub scantron_uploads {
3330: if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
3331: my $result= '<select name="scantron_selectfile">';
3332: opendir(DIR,$Apache::lonnet::perlvar{'lonScansDir'});
3333: my @files=sort(readdir(DIR));
3334: foreach my $filename (@files) {
3335: if ($filename eq '.' or $filename eq '..') { next; }
3336: $result.="<option>$filename</option>\n";
3337: }
3338: closedir(DIR);
3339: $result.="</select>";
3340: return $result;
3341: }
3342:
1.82 albertel 3343: sub scantron_scantab {
3344: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
3345: my $result='<select name="scantron_format">'."\n";
3346: foreach my $line (<$fh>) {
3347: my ($name,$descrip)=split(/:/,$line);
3348: if ($name =~ /^\#/) { next; }
3349: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
3350: }
3351: $result.='</select>'."\n";
3352:
3353: return $result;
3354: }
3355:
1.75 albertel 3356: sub scantron_selectphase {
3357: my ($r) = @_;
3358: my ($symb,$url)=&get_symb_and_url($r);
3359: if (!$symb) {return '';}
3360: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.81 albertel 3361: my $default_form_data=&defaultFormData($symb,$url);
3362: my $grading_menu_button=&show_grading_menu_form($symb,$url);
3363: my $file_selector=&scantron_uploads();
1.82 albertel 3364: my $format_selector=&scantron_scantab();
1.75 albertel 3365: my $result;
3366: $result.= <<SCANTRONFORM;
1.82 albertel 3367: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
1.142 albertel 3368: <input type="hidden" name="command" value="scantron_validate" />
1.81 albertel 3369: $default_form_data
1.75 albertel 3370: <table width="100%" border="0">
3371: <tr>
3372: <td bgcolor="#777777">
3373: <table width="100%" border="0">
3374: <tr bgcolor="#e6ffff">
3375: <td>
3376: <b>Specify file location and which Folder/Sequence to grade</b>
3377: </td>
3378: </tr>
3379: <tr bgcolor="#ffffe6">
3380: <td>
3381: Sequence to grade: $sequence_selector
3382: </td>
3383: </tr>
3384: <tr bgcolor="#ffffe6">
3385: <td>
1.81 albertel 3386: Filename of scoring office file: $file_selector
1.75 albertel 3387: </td>
3388: </tr>
1.82 albertel 3389: <tr bgcolor="#ffffe6">
3390: <td>
3391: Format of data file: $format_selector
3392: </td>
3393: </tr>
1.75 albertel 3394: </table>
3395: </td>
3396: </tr>
3397: </table>
1.142 albertel 3398: <input type="submit" value="Validate Scantron Records" />
1.75 albertel 3399: </form>
1.81 albertel 3400: $grading_menu_button
1.75 albertel 3401: SCANTRONFORM
3402:
3403: return $result;
3404: }
3405:
1.82 albertel 3406: sub get_scantron_config {
3407: my ($which) = @_;
3408: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
3409: my %config;
3410: foreach my $line (<$fh>) {
3411: my ($name,$descrip)=split(/:/,$line);
3412: if ($name ne $which ) { next; }
3413: chomp($line);
3414: my @config=split(/:/,$line);
3415: $config{'name'}=$config[0];
3416: $config{'description'}=$config[1];
3417: $config{'CODElocation'}=$config[2];
3418: $config{'CODEstart'}=$config[3];
3419: $config{'CODElength'}=$config[4];
3420: $config{'IDstart'}=$config[5];
3421: $config{'IDlength'}=$config[6];
3422: $config{'Qstart'}=$config[7];
3423: $config{'Qlength'}=$config[8];
3424: $config{'Qoff'}=$config[9];
3425: $config{'Qon'}=$config[10];
3426: last;
3427: }
3428: return %config;
3429: }
3430:
3431: sub username_to_idmap {
3432: my ($classlist)= @_;
3433: my %idmap;
3434: foreach my $student (keys(%$classlist)) {
3435: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
3436: $student;
3437: }
3438: return %idmap;
3439: }
3440:
3441: sub scantron_parse_scanline {
3442: my ($line,$scantron_config)=@_;
3443: my %record;
3444: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
3445: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
3446: if ($$scantron_config{'CODElocation'} ne 0) {
3447: if ($$scantron_config{'CODElocation'} < 0) {
1.83 albertel 3448: $record{'scantron.CODE'}=substr($data,$$scantron_config{'CODEstart'}-1,
3449: $$scantron_config{'CODElength'});
1.82 albertel 3450: } else {
3451: #FIXME interpret first N questions
3452: }
3453: }
1.83 albertel 3454: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
3455: $$scantron_config{'IDlength'});
1.82 albertel 3456: my @alphabet=('A'..'Z');
3457: my $questnum=0;
3458: while ($questions) {
3459: $questnum++;
3460: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
3461: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 3462: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.82 albertel 3463: my (@array)=split(/$$scantron_config{'Qon'}/,$currentquest);
3464: if (scalar(@array) gt 2) {
3465: #FIXME do something intelligent with double bubbles
1.83 albertel 3466: Apache->request->print("<br ><b>Wha!!!</b> <pre>".scalar(@array).
3467: '-'.$currentquest.'-'.$questnum.'</pre><br />');
1.82 albertel 3468: }
3469: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
1.83 albertel 3470: $record{"scantron.$questnum.answer"}='';
1.82 albertel 3471: } else {
1.83 albertel 3472: $record{"scantron.$questnum.answer"}=$alphabet[length($array[0])];
1.82 albertel 3473: }
3474: }
1.83 albertel 3475: $record{'scantron.maxquest'}=$questnum;
3476: return \%record;
1.82 albertel 3477: }
3478:
3479: sub scantron_add_delay {
1.140 albertel 3480: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
3481: Apache->request->print('add_delay_error '.$_[2] );
3482: push(@$delayqueue,
3483: {'line' => $scanline, 'emsg' => $errormessage,
3484: 'ecode' => $errorcode }
3485: );
1.82 albertel 3486: }
3487:
3488: sub scantron_find_student {
1.83 albertel 3489: my ($scantron_record,$idmap)=@_;
3490: my $scanID=$$scantron_record{'scantron.ID'};
3491: foreach my $id (keys(%$idmap)) {
1.140 albertel 3492: #Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
3493: if (lc($id) eq lc($scanID)) {
3494: #Apache->request->print('success');
3495: return $$idmap{$id};
3496: }
1.83 albertel 3497: }
3498: return undef;
3499: }
3500:
3501: sub scantron_filter {
3502: my ($curres)=@_;
3503: if (ref($curres) && $curres->is_problem() && !$curres->randomout) {
3504: return 1;
3505: }
3506: return 0;
1.82 albertel 3507: }
3508:
1.140 albertel 3509: #FIXME I think I am doing this in the wrong order, I think it would be
3510: #better to make a several passes analyzing all of the lines in the
3511: #file for common errors wrong/invalid PID/username duplicated
3512: #PID/username, missing bubbles, double bubbles, missing/invalid CODE
3513: #and then get the instructor to fix all of these errors, then grade
3514: #the corrected one, I'll still need to catch error conditions, but
3515: #maybe most will taken care even before we start
1.142 albertel 3516:
3517: sub scantron_validate_file {
3518: my ($r) = @_;
3519: }
3520:
1.82 albertel 3521: sub scantron_process_students {
1.75 albertel 3522: my ($r) = @_;
1.136 www 3523: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($ENV{'form.selectpage'});
1.81 albertel 3524: my ($symb,$url)=&get_symb_and_url($r);
3525: if (!$symb) {return '';}
3526: my $default_form_data=&defaultFormData($symb,$url);
1.82 albertel 3527:
3528: my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'});
3529: my $scanlines=Apache::File->new($Apache::lonnet::perlvar{'lonScansDir'}."/$ENV{'form.scantron_selectfile'}");
1.85 albertel 3530: my @scanlines=<$scanlines>;
1.82 albertel 3531: my $classlist=&Apache::loncoursedata::get_classlist();
3532: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 3533: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 3534: my $map=$navmap->getResourceByUrl($sequence);
3535: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 3536: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 3537: my $result= <<SCANTRONFORM;
1.81 albertel 3538: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
3539: <input type="hidden" name="command" value="scantron_configphase" />
3540: $default_form_data
3541: SCANTRONFORM
1.82 albertel 3542: $r->print($result);
3543:
3544: my @delayqueue;
1.140 albertel 3545: my %completedstudents;
3546:
1.85 albertel 3547: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
3548: 'Scantron Status','Scantron Progress',scalar(@scanlines));
1.140 albertel 3549: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
3550: 'Processing first student');
3551: my $start=&Time::HiRes::time();
1.85 albertel 3552: foreach my $line (@scanlines) {
1.140 albertel 3553: $r->print('<pre>line is'.$line.'</pre>');
1.75 albertel 3554:
1.83 albertel 3555: chomp($line);
1.82 albertel 3556: my $scan_record=&scantron_parse_scanline($line,\%scantron_config);
3557: my ($uname,$udom);
1.140 albertel 3558: unless ($uname=&scantron_find_student($scan_record,\%idmap)) {
1.82 albertel 3559: &scantron_add_delay(\@delayqueue,$line,
1.140 albertel 3560: 'Unable to find a student that matches',1);
3561: next;
3562: }
3563: if (exists $completedstudents{$uname}) {
3564: &scantron_add_delay(\@delayqueue,$line,
3565: 'Student '.$uname.' has multiple sheets',2);
3566: next;
1.82 albertel 3567: }
1.83 albertel 3568: $r->print('<pre>doing studnet'.$uname.'</pre>');
1.82 albertel 3569: ($uname,$udom)=split(/:/,$uname);
1.85 albertel 3570: &Apache::lonnet::delenv('form.counter');
1.83 albertel 3571: &Apache::lonnet::appenv(%$scan_record);
1.85 albertel 3572: # &Apache::lonhomework::showhash(%ENV);
1.140 albertel 3573: # $Apache::lonxml::debug=1;
3574: # &Apache::lonxml::debug("line is $line");
1.83 albertel 3575:
1.85 albertel 3576: my $i=0;
1.83 albertel 3577: foreach my $resource (@resources) {
1.85 albertel 3578: $i++;
1.83 albertel 3579: my $result=&Apache::lonnet::ssi($resource->src(),
3580: ('submitted' =>'scantron',
3581: 'grade_target' =>'grade',
3582: 'grade_username'=>$uname,
3583: 'grade_domain' =>$udom,
3584: 'grade_courseid'=>$ENV{'request.course.id'},
3585: 'grade_symb' =>$resource->symb()));
1.140 albertel 3586: # my %score=&Apache::lonnet::restore($resource->symb(),
3587: # $ENV{'request.course.id'},
3588: # $udom,$uname);
3589: # foreach my $part ($resource->{PARTS}) {
3590: # if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
3591: # $studentcorrect++;
3592: # $totalcorrect++;
3593: # } else {
3594: # $studentincorrect++;
3595: # $totalincorrect++;
3596: # }
3597: # }
3598: # $r->print('<pre>'.
3599: # $resource->symb().'-'.
3600: # $resource->src().'-'.'</pre>result is'.$result);
3601: # &Apache::lonhomework::showhash(%score);
1.85 albertel 3602: # if ($i eq 3) {last;}
1.83 albertel 3603: }
1.140 albertel 3604: $completedstudents{$uname}={'line'=>$line};
3605: } continue {
1.85 albertel 3606: &Apache::lonnet::delenv('form.counter');
1.83 albertel 3607: &Apache::lonnet::delenv('scantron\.');
1.85 albertel 3608: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
1.140 albertel 3609: 'last student');
3610: #last;
1.82 albertel 3611: #FIXME
3612: #get iterator for $sequence
3613: #foreach question 'submit' the students answer to the server
3614: # through grade target {
3615: # generate data to pass back that includes grade recevied
3616: #}
3617: }
1.140 albertel 3618: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3619: my $lasttime = &Time::HiRes::time()-$start;
3620: $r->print("<p>took $lasttime</p>");
3621:
3622: #$Apache::lonxml::debug=0;
1.82 albertel 3623: foreach my $delay (@delayqueue) {
3624: #FIXME
3625: #print out each delayed student with interface to select how
3626: # to repair student provided info
3627: #Expected errors include
3628: # 1 bad/no stuid/username
3629: # 2 invalid bubblings
3630:
3631: }
1.75 albertel 3632: #FIXME
3633: # if delay queue exists 2 submits one to process delayed students one
3634: # to ignore delayed students, possibly saving the delay queue for later
1.85 albertel 3635:
3636: $navmap->untieHashes();
1.75 albertel 3637: }
3638: #-------- end of section for handling grading scantron forms -------
3639: #
3640: #-------------------------------------------------------------------
3641:
3642:
1.72 ng 3643: #-------------------------- Menu interface -------------------------
3644: #
3645: #--- Show a Grading Menu button - Calls the next routine ---
3646: sub show_grading_menu_form {
3647: my ($symb,$url)=@_;
1.125 ng 3648: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.72 ng 3649: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3650: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.77 ng 3651: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 3652: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
3653: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
3654: '</form>'."\n";
3655: return $result;
3656: }
3657:
1.77 ng 3658: # -- Retrieve choices for grading form
3659: sub savedState {
3660: my %savedState = ();
3661: if ($ENV{'form.saveState'}) {
3662: foreach (split(/:/,$ENV{'form.saveState'})) {
3663: my ($key,$value) = split(/=/,$_,2);
3664: $savedState{$key} = $value;
3665: }
3666: }
3667: return \%savedState;
3668: }
1.76 ng 3669:
1.72 ng 3670: #--- Displays the main menu page -------
3671: sub gradingmenu {
3672: my ($request) = @_;
3673: my ($symb,$url)=&get_symb_and_url($request);
3674: if (!$symb) {return '';}
1.76 ng 3675: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 3676:
3677: $request->print(<<GRADINGMENUJS);
3678: <script type="text/javascript" language="javascript">
1.116 ng 3679: function checkChoice(formname,val,cmdx) {
3680: if (val <= 2) {
3681: var cmd = radioSelection(formname.radioChoice);
1.118 ng 3682: var cmdsave = cmd;
1.116 ng 3683: } else {
3684: cmd = cmdx;
1.118 ng 3685: cmdsave = 'submission';
1.116 ng 3686: }
3687: formname.command.value = cmd;
1.118 ng 3688: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 3689: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 3690: if (val < 5) formname.submit();
3691: if (val == 5) {
1.72 ng 3692: if (!checkReceiptNo(formname,'notOK')) { return false;}
3693: formname.submit();
3694: }
3695: }
3696:
3697: function checkReceiptNo(formname,nospace) {
3698: var receiptNo = formname.receipt.value;
3699: var checkOpt = false;
3700: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
3701: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
3702: if (checkOpt) {
3703: alert("Please enter a receipt number given by a student in the receipt box.");
3704: formname.receipt.value = "";
3705: formname.receipt.focus();
3706: return false;
3707: }
3708: return true;
3709: }
3710: </script>
3711: GRADINGMENUJS
1.118 ng 3712: &commonJSfunctions($request);
3713: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>';
1.122 ng 3714: my ($table,undef,$hdgrade) = &showResourceInfo($url,$probTitle);
1.118 ng 3715: $result.=$table;
1.76 ng 3716: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 3717: my $savedState = &savedState();
1.118 ng 3718: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 3719: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 3720: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 3721: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 3722:
3723: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
3724: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3725: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3726: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
3727: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 3728: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 3729: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 3730: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 3731: '<input type="hidden" name="showgrading" value="yes" />'."\n";
3732:
1.116 ng 3733: $result.='<table width="100%" border=0><tr><td bgcolor=#777777>'."\n".
3734: '<table width=100% border=0><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 3735: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 3736: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
3737:
3738: $result.='<table width="100%" border=0>';
3739: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.118 ng 3740: ' Select Section: <select name="section">'."\n";
1.116 ng 3741: if (ref($sections)) {
3742: foreach (sort (@$sections)) {$result.='<option value="'.$_.'" '.
3743: ($saveSec eq $_ ? 'selected="on"' : '').'>'.$_.'</option>'."\n";}
3744: }
3745: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</select> ';
3746:
3747: $result.='Student Status:</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 3748:
1.116 ng 3749: if (ref($sections)) {
3750: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
3751: if (grep /no/,@$sections);
3752: }
3753: $result.='</td></tr>';
3754:
1.118 ng 3755: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
3756: '<input type="radio" name="radioChoice" value="submission" '.
1.145 albertel 3757: ($saveCmd eq 'submission' ? 'checked' : '').'> '.'<b>Current Resource:</b> For one or more students '.
3758: '<select name="submitonly">'.
3759: '<option value="yes" '.
3760: ($saveSub eq 'yes' ? 'selected="on"' : '').'>with submissions</option>'.
3761: '<option value="graded" '.
3762: ($saveSub eq 'graded' ? 'selected="on"' : '').'>with ungraded submissions</option>'.
3763: '<option value="all" '.
3764: ($saveSub eq 'all' ? 'selected="on"' : '').'>with any status</option></select></td></tr>'."\n";
1.72 ng 3765:
1.116 ng 3766: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
3767: '<input type="radio" name="radioChoice" value="viewgrades" '.
1.76 ng 3768: ($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
1.118 ng 3769: '<b>Current Resource:</b> For all students in selected section or course</td></tr>'."\n";
1.72 ng 3770:
1.118 ng 3771: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
3772: '<input type="radio" name="radioChoice" value="pickStudentPage" '.
3773: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
3774: 'The <b>complete</b> set/page/sequence: For one student</td></tr>'."\n";
1.46 ng 3775:
1.116 ng 3776: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 3777: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 3778: '</td></tr></table>'."\n";
3779:
3780: $result.='</td><td valign="top">';
3781:
3782: $result.='<table width="100%" border=0>';
3783: $result.='<tr bgcolor="#ffffe6"><td>'.
3784: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="Upload" />'.
3785: ' scores from file </td></tr>'."\n";
1.72 ng 3786:
1.75 albertel 3787: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 3788: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
3789: '" value="Grade" /> scantron forms</td></tr>'."\n";
1.75 albertel 3790:
1.72 ng 3791: if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)) {
3792: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.116 ng 3793: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="Verify" />'.
3794: ' submission Receipt no: '.unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).
1.72 ng 3795: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
3796: '</td></tr>'."\n";
3797: }
1.44 ng 3798:
1.116 ng 3799: $result.='</form></td></tr></table>'."\n".
1.72 ng 3800: '</td></tr></table>'."\n".
3801: '</td></tr></table>'."\n";
1.44 ng 3802: return $result;
1.2 albertel 3803: }
3804:
1.1 albertel 3805: sub handler {
1.41 ng 3806: my $request=$_[0];
1.102 albertel 3807:
1.103 albertel 3808: undef(%perm);
1.41 ng 3809: if ($ENV{'browser.mathml'}) {
1.141 www 3810: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 3811: } else {
1.141 www 3812: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 3813: }
3814: $request->send_http_header;
1.44 ng 3815: return '' if $request->header_only;
1.41 ng 3816: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
3817: my $url=$ENV{'form.url'};
3818: my $symb=$ENV{'form.symb'};
3819: my $command=$ENV{'form.command'};
3820: if (!$url) {
3821: my ($temp1,$temp2);
1.136 www 3822: ($temp1,$temp2,$ENV{'form.url'})=&Apache::lonnet::decode_symb($symb);
1.41 ng 3823: $url = $ENV{'form.url'};
3824: }
3825: &send_header($request);
3826: if ($url eq '' && $symb eq '') {
3827: if ($ENV{'user.adv'}) {
3828: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
3829: ($ENV{'form.codethree'})) {
3830: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
3831: $ENV{'form.codethree'};
3832: my ($tsymb,$tuname,$tudom,$tcrsid)=
3833: &Apache::lonnet::checkin($token);
3834: if ($tsymb) {
1.137 albertel 3835: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 3836: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 3837: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
3838: ('grade_username' => $tuname,
3839: 'grade_domain' => $tudom,
3840: 'grade_courseid' => $tcrsid,
3841: 'grade_symb' => $tsymb)));
1.41 ng 3842: } else {
1.45 ng 3843: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 3844: }
1.41 ng 3845: } else {
1.45 ng 3846: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 3847: }
1.14 www 3848: } else {
1.41 ng 3849: $request->print(&Apache::lonxml::tokeninputfield());
3850: }
3851: }
3852: } else {
1.103 albertel 3853: if (!($perm{'vgr'}=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}))) {
3854: if ($perm{'vgr'}=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}.'/'.$ENV{'request.course.sec'})) {
3855: $perm{'vgr_section'}=$ENV{'request.course.sec'};
1.102 albertel 3856: } else {
1.103 albertel 3857: delete($perm{'vgr'});
1.102 albertel 3858: }
3859: }
1.103 albertel 3860: if (!($perm{'mgr'}=&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}))) {
3861: if ($perm{'mgr'}=&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}.'/'.$ENV{'request.course.sec'})) {
3862: $perm{'mgr_section'}=$ENV{'request.course.sec'};
1.102 albertel 3863: } else {
1.103 albertel 3864: delete($perm{'mgr'});
1.102 albertel 3865: }
3866: }
3867:
1.104 albertel 3868: if ($command eq 'submission' && $perm{'vgr'}) {
1.68 ng 3869: ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 3870: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 3871: &pickStudentPage($request);
1.103 albertel 3872: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 3873: &displayPage($request);
1.104 albertel 3874: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 3875: &updateGradeByPage($request);
1.104 albertel 3876: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 3877: &processGroup($request);
1.104 albertel 3878: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 3879: $request->print(&gradingmenu($request));
1.104 albertel 3880: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 3881: $request->print(&viewgrades($request));
1.104 albertel 3882: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 3883: $request->print(&processHandGrade($request));
1.106 albertel 3884: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 3885: $request->print(&editgrades($request));
1.106 albertel 3886: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 3887: $request->print(&verifyreceipt($request));
1.106 albertel 3888: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 3889: $request->print(&upcsvScores_form($request));
1.106 albertel 3890: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 3891: $request->print(&csvupload($request));
1.106 albertel 3892: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 3893: $request->print(&csvuploadmap($request));
1.106 albertel 3894: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'}) {
1.41 ng 3895: if ($ENV{'form.associate'} ne 'Reverse Association') {
3896: $request->print(&csvuploadassign($request));
3897: } else {
3898: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
3899: $ENV{'form.upfile_associate'} = 'reverse';
3900: } else {
3901: $ENV{'form.upfile_associate'} = 'forward';
3902: }
3903: $request->print(&csvuploadmap($request));
3904: }
1.106 albertel 3905: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 3906: $request->print(&scantron_selectphase($request));
1.142 albertel 3907: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
3908: $request->print(&scantron_validate_file($request));
1.106 albertel 3909: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 3910: $request->print(&scantron_process_students($request));
1.106 albertel 3911: } elsif ($command) {
3912: $request->print("Access Denied");
1.26 albertel 3913: }
1.2 albertel 3914: }
1.41 ng 3915: &send_footer($request);
1.44 ng 3916: return '';
3917: }
3918:
3919: sub send_header {
3920: my ($request)= @_;
3921: $request->print(&Apache::lontexconvert::header());
3922: # $request->print("
3923: #<script>
3924: #remotewindow=open('','homeworkremote');
3925: #remotewindow.close();
3926: #</script>");
1.47 www 3927: $request->print(&Apache::loncommon::bodytag('Grading'));
1.44 ng 3928: }
3929:
3930: sub send_footer {
3931: my ($request)= @_;
3932: $request->print('</body>');
3933: $request->print(&Apache::lontexconvert::footer());
1.1 albertel 3934: }
3935:
3936: 1;
3937:
1.13 albertel 3938: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>