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