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