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