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