Annotation of loncom/homework/grades.pm, revision 1.90
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.90 ! albertel 4: # $Id: grades.pm,v 1.89 2003/05/16 19:00:23 albertel Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.13 albertel 28: # 2/9,2/13 Guy Albertelli
1.8 www 29: # 6/8 Gerd Kortemeyer
1.13 albertel 30: # 7/26 H.K. Ng
1.14 www 31: # 8/20 Gerd Kortemeyer
1.30 ng 32: # Year 2002
1.44 ng 33: # June-August H.K. Ng
1.68 ng 34: # Year 2003
1.71 ng 35: # February, March H.K. Ng
1.30 ng 36: #
1.1 albertel 37:
38: package Apache::grades;
39: use strict;
40: use Apache::style;
41: use Apache::lonxml;
42: use Apache::lonnet;
1.3 albertel 43: use Apache::loncommon;
1.68 ng 44: use Apache::lonnavmaps;
1.1 albertel 45: use Apache::lonhomework;
1.55 matthew 46: use Apache::loncoursedata;
1.38 ng 47: use Apache::lonmsg qw(:user_normal_msg);
1.1 albertel 48: use Apache::Constants qw(:common);
1.87 www 49: use String::Similarity;
50:
51: my %oldessays=();
1.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.13 albertel 2038:
1.44 ng 2039: for ($i=0; $i<$ENV{'form.total'}; $i++) {
2040: my $user = $ENV{'form.ctr'.$i};
1.89 albertel 2041: my ($uname,$udom)=split(/:/,$user);
1.44 ng 2042: my %newrecord;
2043: my $updateflag = 0;
1.13 albertel 2044:
1.89 albertel 2045: $result .= '<tr bgcolor="#ffffde"><td>'.$uname.' </td><td>'.
2046: $udom.' </td><td>'.
2047: $$fullname{$user}.' </td>';
1.44 ng 2048: foreach (@partid) {
1.54 albertel 2049: my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
2050: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
2051: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
2052: my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
2053:
2054: my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
2055: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
2056: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 2057: my $score;
2058: if ($partial eq '') {
1.54 albertel 2059: $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 2060: } elsif ($partial > 0) {
2061: $score = 'correct_by_override';
2062: } elsif ($partial == 0) {
2063: $score = 'incorrect_by_override';
2064: }
1.54 albertel 2065: $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
1.44 ng 2066: ($score ne 'excused'));
2067: $result .= '<td align="center">'.$old_aw.' </td>'.
2068: '<td align="center">'.$awarded.
2069: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 2070:
1.54 albertel 2071: if (!($old_part eq $partial && $old_score eq $score)) {
2072: $updateflag = 1;
2073: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
2074: $newrecord{'resource.'.$_.'.solved'} = $score;
2075: $rec_update++;
2076: }
2077:
2078: my $partid=$_;
2079: foreach my $stores (@parts) {
2080: my ($part,$type) = &split_part_type($stores);
2081: if ($part !~ m/^\Q$partid\E/) { next;}
2082: if ($type eq 'awarded' || $type eq 'solved') { next; }
2083: my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
2084: my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
2085: if ($awarded ne '' && $awarded ne $old_aw) {
2086: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.72 ng 2087: $newrecord{'resource.'.$part.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.54 albertel 2088: $updateflag=1;
2089: }
2090: $result .= '<td align="center">'.$old_aw.' </td>'.
2091: '<td align="center">'.$awarded.' </td>';
2092: }
1.44 ng 2093: }
2094: $result .= '</tr>'."\n";
2095: if ($updateflag) {
2096: $count++;
2097: &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
1.89 albertel 2098: $udom,$uname);
1.44 ng 2099: }
2100: }
1.72 ng 2101: $result .= '</table></td></tr></table>'."\n".
2102: &show_grading_menu_form ($symb,$url);
1.44 ng 2103: my $msg = '<b>Number of records updated = '.$rec_update.
2104: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
2105: '<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
2106: return $title.$msg.$result;
1.5 albertel 2107: }
1.54 albertel 2108:
2109: sub split_part_type {
2110: my ($partstr) = @_;
2111: my ($temp,@allparts)=split(/_/,$partstr);
2112: my $type=pop(@allparts);
2113: my $part=join('.',@allparts);
2114: return ($part,$type);
2115: }
2116:
1.44 ng 2117: #------------- end of section for handling grading by section/class ---------
2118: #
2119: #----------------------------------------------------------------------------
2120:
1.5 albertel 2121:
1.44 ng 2122: #----------------------------------------------------------------------------
2123: #
2124: #-------------------------- Next few routines handles grading by csv upload
2125: #
2126: #--- Javascript to handle csv upload
1.27 albertel 2127: sub csvupload_javascript_reverse_associate {
2128: return(<<ENDPICK);
2129: function verify(vf) {
2130: var foundsomething=0;
2131: var founduname=0;
2132: var founddomain=0;
2133: for (i=0;i<=vf.nfields.value;i++) {
2134: tw=eval('vf.f'+i+'.selectedIndex');
2135: if (i==0 && tw!=0) { founduname=1; }
2136: if (i==1 && tw!=0) { founddomain=1; }
2137: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
2138: }
2139: if (founduname==0 || founddomain==0) {
2140: alert('You need to specify at both the username and domain');
2141: return;
2142: }
2143: if (foundsomething==0) {
2144: alert('You need to specify at least one grading field');
2145: return;
2146: }
2147: vf.submit();
2148: }
2149: function flip(vf,tf) {
2150: var nw=eval('vf.f'+tf+'.selectedIndex');
2151: var i;
2152: for (i=0;i<=vf.nfields.value;i++) {
2153: //can not pick the same destination field for both name and domain
2154: if (((i ==0)||(i ==1)) &&
2155: ((tf==0)||(tf==1)) &&
2156: (i!=tf) &&
2157: (eval('vf.f'+i+'.selectedIndex')==nw)) {
2158: eval('vf.f'+i+'.selectedIndex=0;')
2159: }
2160: }
2161: }
2162: ENDPICK
2163: }
2164:
2165: sub csvupload_javascript_forward_associate {
2166: return(<<ENDPICK);
2167: function verify(vf) {
2168: var foundsomething=0;
2169: var founduname=0;
2170: var founddomain=0;
2171: for (i=0;i<=vf.nfields.value;i++) {
2172: tw=eval('vf.f'+i+'.selectedIndex');
2173: if (tw==1) { founduname=1; }
2174: if (tw==2) { founddomain=1; }
2175: if (tw>2) { foundsomething=1; }
2176: }
2177: if (founduname==0 || founddomain==0) {
2178: alert('You need to specify at both the username and domain');
2179: return;
2180: }
2181: if (foundsomething==0) {
2182: alert('You need to specify at least one grading field');
2183: return;
2184: }
2185: vf.submit();
2186: }
2187: function flip(vf,tf) {
2188: var nw=eval('vf.f'+tf+'.selectedIndex');
2189: var i;
2190: //can not pick the same destination field twice
2191: for (i=0;i<=vf.nfields.value;i++) {
2192: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
2193: eval('vf.f'+i+'.selectedIndex=0;')
2194: }
2195: }
2196: }
2197: ENDPICK
2198: }
2199:
1.26 albertel 2200: sub csvuploadmap_header {
1.41 ng 2201: my ($request,$symb,$url,$datatoken,$distotal)= @_;
2202: my $javascript;
2203: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2204: $javascript=&csvupload_javascript_reverse_associate();
2205: } else {
2206: $javascript=&csvupload_javascript_forward_associate();
2207: }
1.45 ng 2208:
2209: my $result='<table border="0">';
1.72 ng 2210: $result.='<tr><td colspan=3><font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font></td></tr>';
1.45 ng 2211: my ($partlist,$handgrade) = &response_type($url);
2212: my ($resptype,$hdgrade)=('','no');
2213: for (sort keys(%$handgrade)) {
2214: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
2215: $resptype = $responsetype;
2216: $hdgrade = $handgrade if ($handgrade eq 'yes');
2217: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
2218: '<td><b>Type: </b>'.$responsetype.'</td>'.
2219: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
2220: }
2221: $result.='</table>';
1.41 ng 2222: $request->print(<<ENDPICK);
1.26 albertel 2223: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 2224: <h3><font color="#339933">Uploading Class Grades</font></h3>
2225: $result
1.26 albertel 2226: <hr>
2227: <h3>Identify fields</h3>
2228: Total number of records found in file: $distotal <hr />
2229: Enter as many fields as you can. The system will inform you and bring you back
2230: to this page if the data selected is insufficient to run your class.<hr />
2231: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
2232: <input type="hidden" name="associate" value="" />
2233: <input type="hidden" name="phase" value="three" />
2234: <input type="hidden" name="datatoken" value="$datatoken" />
2235: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
2236: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
2237: <input type="hidden" name="upfile_associate"
2238: value="$ENV{'form.upfile_associate'}" />
2239: <input type="hidden" name="symb" value="$symb" />
2240: <input type="hidden" name="url" value="$url" />
1.77 ng 2241: <input type="hidden" name="saveState" value="$ENV{'form.saveState'}" />
1.72 ng 2242: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
1.26 albertel 2243: <input type="hidden" name="command" value="csvuploadassign" />
2244: <hr />
2245: <script type="text/javascript" language="Javascript">
2246: $javascript
2247: </script>
2248: ENDPICK
1.41 ng 2249: return '';
1.26 albertel 2250:
2251: }
2252:
2253: sub csvupload_fields {
1.41 ng 2254: my ($url) = @_;
2255: my (@parts) = &getpartlist($url);
2256: my @fields=(['username','Student Username'],['domain','Student Domain']);
2257: foreach my $part (sort(@parts)) {
2258: my @datum;
2259: my $display=&Apache::lonnet::metadata($url,$part.'.display');
2260: my $name=$part;
2261: if (!$display) { $display = $name; }
2262: @datum=($name,$display);
2263: push(@fields,\@datum);
2264: }
2265: return (@fields);
1.26 albertel 2266: }
2267:
2268: sub csvuploadmap_footer {
1.41 ng 2269: my ($request,$i,$keyfields) =@_;
2270: $request->print(<<ENDPICK);
1.26 albertel 2271: </table>
2272: <input type="hidden" name="nfields" value="$i" />
2273: <input type="hidden" name="keyfields" value="$keyfields" />
2274: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
2275: </form>
2276: ENDPICK
2277: }
2278:
1.86 ng 2279: sub upcsvScores_form {
2280: my ($request) = shift;
2281: my ($symb,$url)=&get_symb_and_url($request);
2282: if (!$symb) {return '';}
2283: my $result =<<CSVFORMJS;
2284: <script type="text/javascript" language="javascript">
2285: function checkUpload(formname) {
2286: if (formname.upfile.value == "") {
2287: alert("Please use the browse button to select a file from your local directory.");
2288: return false;
2289: }
2290: formname.submit();
2291: }
2292: </script>
2293: CSVFORMJS
2294: $ENV{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
2295: $result.='<br /><table width=100% border=0><tr><td bgcolor="#777777">'."\n";
2296: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
2297: $result.=' <b>Specify a file containing the class scores for problem - '.$ENV{'form.probTitle'}.
2298: '.</b></td></tr>'."\n";
2299: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2300: my $upfile_select=&Apache::loncommon::upfile_select_html();
2301: $result.=<<ENDUPFORM;
2302: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload" target="LONcatInfo">
2303: <input type="hidden" name="symb" value="$symb" />
2304: <input type="hidden" name="url" value="$url" />
2305: <input type="hidden" name="command" value="csvuploadmap" />
2306: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
2307: <input type="hidden" name="saveState" value="$ENV{'form.saveState'}" />
2308: $upfile_select
2309: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />
2310:
2311: </form>
2312: ENDUPFORM
2313: $result.='</td></tr></table>'."\n";
2314: $result.='</td></tr></table><br /><br />'."\n";
2315: $result.=&show_grading_menu_form($symb,$url);
2316:
2317: return $result;
2318: }
2319:
2320:
1.26 albertel 2321: sub csvuploadmap {
1.41 ng 2322: my ($request)= @_;
2323: my ($symb,$url)=&get_symb_and_url($request);
2324: if (!$symb) {return '';}
1.72 ng 2325:
1.41 ng 2326: my $datatoken;
2327: if (!$ENV{'form.datatoken'}) {
2328: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 2329: } else {
1.41 ng 2330: $datatoken=$ENV{'form.datatoken'};
2331: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 2332: }
1.41 ng 2333: my @records=&Apache::loncommon::upfile_record_sep();
2334: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
2335: my ($i,$keyfields);
2336: if (@records) {
2337: my @fields=&csvupload_fields($url);
1.45 ng 2338:
1.41 ng 2339: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2340: &Apache::loncommon::csv_print_samples($request,\@records);
2341: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
2342: \@fields);
2343: foreach (@fields) { $keyfields.=$_->[0].','; }
2344: chop($keyfields);
2345: } else {
2346: unshift(@fields,['none','']);
2347: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
2348: \@fields);
2349: my %sone=&Apache::loncommon::record_sep($records[0]);
2350: $keyfields=join(',',sort(keys(%sone)));
2351: }
2352: }
2353: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 2354: $request->print(&show_grading_menu_form($symb,$url));
2355:
1.41 ng 2356: return '';
1.27 albertel 2357: }
2358:
2359: sub csvuploadassign {
1.41 ng 2360: my ($request)= @_;
2361: my ($symb,$url)=&get_symb_and_url($request);
2362: if (!$symb) {return '';}
2363: &Apache::loncommon::load_tmp_file($request);
1.44 ng 2364: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.41 ng 2365: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
2366: my %fields=();
2367: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
2368: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2369: if ($ENV{'form.f'.$i} ne 'none') {
2370: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
2371: }
2372: } else {
2373: if ($ENV{'form.f'.$i} ne 'none') {
2374: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
2375: }
2376: }
1.27 albertel 2377: }
1.41 ng 2378: $request->print('<h3>Assigning Grades</h3>');
2379: my $courseid=$ENV{'request.course.id'};
2380: my ($classlist) = &getclasslist('all','1');
2381: my @skipped;
2382: my $countdone=0;
2383: foreach my $grade (@gradedata) {
2384: my %entries=&Apache::loncommon::record_sep($grade);
2385: my $username=$entries{$fields{'username'}};
2386: my $domain=$entries{$fields{'domain'}};
2387: if (!exists($$classlist{"$username:$domain"})) {
2388: push(@skipped,"$username:$domain");
2389: next;
2390: }
2391: my %grades;
2392: foreach my $dest (keys(%fields)) {
2393: if ($dest eq 'username' || $dest eq 'domain') { next; }
2394: if ($entries{$fields{$dest}} eq '') { next; }
2395: my $store_key=$dest;
2396: $store_key=~s/^stores/resource/;
2397: $store_key=~s/_/\./g;
2398: $grades{$store_key}=$entries{$fields{$dest}};
2399: }
2400: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
2401: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
2402: $domain,$username);
2403: $request->print('.');
2404: $request->rflush();
2405: $countdone++;
2406: }
2407: $request->print("<br />Stored $countdone students\n");
2408: if (@skipped) {
2409: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
2410: foreach my $student (@skipped) { $request->print("<br />$student"); }
2411: }
2412: $request->print(&view_edit_entire_class_form($symb,$url));
2413: $request->print(&show_grading_menu_form($symb,$url));
2414: return '';
1.26 albertel 2415: }
1.44 ng 2416: #------------- end of section for handling csv file upload ---------
2417: #
2418: #-------------------------------------------------------------------
2419: #
1.72 ng 2420: #-------------- Next few routines handles grading by page/sequence
2421: #
2422: #--- Select a page/sequence and a student to grade
1.68 ng 2423: sub pickStudentPage {
2424: my ($request) = shift;
2425:
2426: $request->print(<<LISTJAVASCRIPT);
2427: <script type="text/javascript" language="javascript">
2428:
2429: function checkPickOne(formname) {
1.76 ng 2430: if (radioSelection(formname.student) == null) {
1.68 ng 2431: alert("Please select the student you wish to grade.");
2432: return;
2433: }
1.70 ng 2434: var ptr = pullDownSelection(formname.selectpage);
1.71 ng 2435: formname.page.value = eval("formname.page"+ptr+".value");
2436: formname.title.value = eval("formname.title"+ptr+".value");
1.68 ng 2437: formname.submit();
2438: }
2439:
2440: function radioSelection(radioButton) {
2441: var selection=null;
1.76 ng 2442: if (radioButton.length > 1) {
2443: for (var i=0; i<radioButton.length; i++) {
2444: if (radioButton[i].checked) {
2445: return radioButton[i].value;
2446: }
2447: }
2448: } else {
2449: if (radioButton.checked) return radioButton.value;
1.68 ng 2450: }
2451: return selection;
2452: }
1.76 ng 2453:
1.70 ng 2454: function pullDownSelection(selectOne) {
1.76 ng 2455: var selection="";
2456: if (selectOne.length > 1) {
2457: for (var i=0; i<selectOne.length; i++) {
2458: if (selectOne[i].selected) {
2459: return selectOne[i].value;
2460: }
2461: }
2462: } else {
2463: if (selectOne.selected) return selectOne.value;
1.70 ng 2464: }
2465: }
1.68 ng 2466: </script>
2467: LISTJAVASCRIPT
2468:
1.72 ng 2469: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2470: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2471: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2472: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2473:
2474: my $result='<h3><font color="#339933"> '.
2475: 'Manual Grading by Page or Sequence</font></h3>';
2476:
1.80 ng 2477: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 2478: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 2479: my ($titles,$symbx) = &getSymbMap($request);
1.71 ng 2480: my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
1.70 ng 2481: my $ctr=0;
1.68 ng 2482: foreach (@$titles) {
2483: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 2484: $result.='<option value="'.$ctr.'" '.
1.71 ng 2485: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
2486: '>'.$showtitle.'</option>'."\n";
1.70 ng 2487: $ctr++;
1.68 ng 2488: }
2489: $result.= '</select>'."<br>\n";
1.70 ng 2490: $ctr=0;
2491: foreach (@$titles) {
2492: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
2493: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
2494: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
2495: $ctr++;
2496: }
1.72 ng 2497: $result.='<input type="hidden" name="page" />'."\n".
2498: '<input type="hidden" name="title" />'."\n";
1.68 ng 2499:
1.71 ng 2500: $result.=' <b>View Problems: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
2501: '<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
1.72 ng 2502:
1.71 ng 2503: $result.=' <b>Submission Details: </b>'.
2504: '<input type="radio" name="lastSub" value="none" /> none'."\n".
2505: '<input type="radio" name="lastSub" value="datesub" checked /> dates and submissions'."\n".
2506: '<input type="radio" name="lastSub" value="all" /> all details'."\n";
1.72 ng 2507:
1.68 ng 2508: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.72 ng 2509: '<input type="hidden" name="command" value="displayPage" />'."\n".
2510: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.80 ng 2511: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2512: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."<br />\n";
1.72 ng 2513:
1.80 ng 2514: $result.=' <input type="button" '.
1.72 ng 2515: 'onClick="javascript:checkPickOne(this.form);"value="Submit" /><br />'."\n";
2516:
1.68 ng 2517: $request->print($result);
2518:
1.76 ng 2519: my $studentTable.=' <b>Select a student you wish to grade</b><br>'.
1.68 ng 2520: '<table border="0"><tr><td bgcolor="#777777">'.
2521: '<table border="0"><tr bgcolor="#e6ffff">'.
2522: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2523: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2524: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2525: '<td><b> Fullname <font color="#999999">(username)</font></b></td></tr>';
2526:
1.76 ng 2527: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 2528: my $ptr = 1;
2529: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
2530: my ($uname,$udom) = split(/:/,$student);
2531: $studentTable.=($ptr%4 == 1 ? '<tr bgcolor="#ffffe6"><td>' : '</td><td>');
1.70 ng 2532: $studentTable.='<input type="radio" name="student" value="'.$student.'" /> '.$$fullname{$student}.
1.68 ng 2533: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
2534: $studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
2535: $ptr++;
2536: }
2537: $studentTable.='</td><td> </td><td> </td><td> ' if ($ptr%4 == 2);
2538: $studentTable.='</td><td> </td><td> ' if ($ptr%4 == 3);
2539: $studentTable.='</td><td> ' if ($ptr%4 == 0);
2540: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.70 ng 2541: $studentTable.='<br /> <input type="button" '.
2542: 'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
1.68 ng 2543:
2544: $studentTable.=&show_grading_menu_form($symb,$url);
2545: $request->print($studentTable);
2546:
2547: return '';
2548: }
2549:
2550: sub getSymbMap {
1.74 albertel 2551: my ($request) = @_;
1.79 bowersj2 2552: my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
1.68 ng 2553: $ENV{'request.course.fn'}.'_parms.db',1, 1);
2554:
2555: my $res = $navmap->firstResource(); # temp resource to access constants
2556: $navmap->init();
2557:
2558: # End navmap using boilerplate
2559:
2560: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
2561: my $depth = 1;
2562: $iterator->next(); # ignore first BEGIN_MAP
2563: my $curRes = $iterator->next();
2564:
2565: my %symbx = ();
2566: my @titles = ();
2567: my $minder=0;
2568: while ($depth > 0) {
2569: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
2570: if ($curRes == $iterator->END_MAP()) { $depth--; }
2571:
2572: if (ref($curRes) && $curRes->is_map()) {
1.71 ng 2573: my ($mapUrl, $id, $resUrl) = split(/___/, $curRes->symb()); # check map contains at least one problem
2574: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2575:
2576: my $mapiterator = $navmap->getIterator($map->map_start(),
2577: $map->map_finish());
2578:
2579: my $mapdepth = 1;
2580: my $countProblems = 0;
2581: $mapiterator->next(); # skip the first BEGIN_MAP
2582: my $mapcurRes = $mapiterator->next(); # for "current resource"
2583: my $ctr=0;
2584: while ($mapdepth > 0 && $ctr < 100) {
2585: if($mapcurRes == $mapiterator->BEGIN_MAP) { $mapdepth++; }
2586: if($mapcurRes == $mapiterator->END_MAP) { $mapdepth++; }
2587:
2588: if (ref($mapcurRes) && $mapcurRes->is_problem() && !$mapcurRes->randomout) {
2589: $countProblems++;
2590: }
2591: $ctr++;
2592: }
2593: if ($countProblems > 0) {
2594: my $title = $curRes->compTitle();
2595: push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
2596: $symbx{$minder.'.'.$title} = $curRes->symb();
2597: $minder++;
2598: }
1.68 ng 2599: }
2600: $curRes = $iterator->next();
2601: }
2602:
2603: $navmap->untieHashes();
2604: return \@titles,\%symbx;
2605: }
2606:
1.72 ng 2607: #
2608: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 2609: sub displayPage {
2610: my ($request) = shift;
2611:
1.72 ng 2612: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2613: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2614: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2615: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2616: my $pageTitle = $ENV{'form.page'};
1.76 ng 2617: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.70 ng 2618: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.68 ng 2619:
1.70 ng 2620: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
2621: $result.='<h3> Student: '.$$fullname{$ENV{'form.student'}}.
1.68 ng 2622: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
2623:
1.71 ng 2624: &sub_page_js($request);
2625: $request->print($result);
2626:
1.79 bowersj2 2627: my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
1.68 ng 2628: $ENV{'request.course.fn'}.'_parms.db',1, 1);
1.70 ng 2629: my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
1.68 ng 2630: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2631:
2632: my $iterator = $navmap->getIterator($map->map_start(),
2633: $map->map_finish());
2634:
1.71 ng 2635: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 2636: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
2637: '<input type="hidden" name="student" value="'.$ENV{'form.student'}.'" />'."\n".
2638: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
2639: '<input type="hidden" name="title" value="'.$ENV{'form.title'}.'" />'."\n".
2640: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2641: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.77 ng 2642: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
1.71 ng 2643:
2644: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
2645: '/check.gif" height="16" border="0" />';
2646:
2647: $studentTable.=' <b>Note:</b> A problem graded correct ('.$checkIcon.
2648: ') by the computer cannot be changed.'."\n".
2649: '<table border="0"><tr><td bgcolor="#777777">'.
2650: '<table border="0"><tr bgcolor="#e6ffff">'.
2651: '<td align="center"><b> No </b></td>'.
2652: '<td><b> '.($ENV{'form.vProb'} eq 'no' ? 'Title' : 'Problem View').'/Grade</b></td></tr>';
2653:
2654: my ($depth,$ctr,$question) = (1,0,1);
1.68 ng 2655: $iterator->next(); # skip the first BEGIN_MAP
2656: my $curRes = $iterator->next(); # for "current resource"
2657: while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
2658: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
2659: if($curRes == $iterator->END_MAP) { $depth++; }
2660:
2661: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.90 ! albertel 2662: my $parts = ['0',@{$curRes->parts()}];
! 2663: &APache::lonnet::logthis("parts ".join(':',@$parts));
1.68 ng 2664: my $title = $curRes->compTitle();
1.71 ng 2665: my $symbx = $curRes->symb();
2666: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
2667: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
2668: $studentTable.='<td valign="top">';
2669: if ($ENV{'form.vProb'} eq 'yes') {
2670: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1);
2671: } else {
2672: my $companswer = &Apache::loncommon::get_student_answers(
2673: $symbx,$uname,$udom,$ENV{'request.course.id'});
1.80 ng 2674: $companswer =~ s|<form(.*?)>||g;
2675: $companswer =~ s|</form>||g;
1.71 ng 2676:
2677: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
2678: # $request->print('match='.$1.'<br>');
2679: # $companswer =~ s/$1/ /s;
2680: # }
2681: # $companswer =~ s/<table border=\"1\">/<table border=\"0\">/g;
2682: $studentTable.=' <b>'.$title.'</b> <br> <b>Correct answer:</b><br>'.$companswer;
2683: }
2684:
2685: my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname);
2686:
2687: if ($ENV{'form.lastSub'} eq 'datesub') {
2688: if ($record{'version'} eq '') {
2689: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
2690: } else {
2691: $studentTable.='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
2692: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
2693: '<td><b>Date/Time</b></td>'.
2694: '<td><b>Submission</b></td>'.
2695: '<td><b>Status </b></td></tr>';
2696: my ($version);
2697: for ($version=1;$version<=$record{'version'};$version++) {
2698: my $timestamp = scalar(localtime($record{$version.':timestamp'}));
2699: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
2700: my @versionKeys = split(/\:/,$record{$version.':keys'});
2701: my @displaySub = ();
2702: foreach my $partid (@{$parts}) {
2703: my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys;
1.77 ng 2704: next if ($record{"$version:resource.$partid.solved"} eq '');
2705: # next if ($record{"$version:resource.$partid.award"} eq 'APPROX_ANS' &&
2706: # $record{"$version:resource.$partid.solved"} eq '');
1.71 ng 2707: $displaySub[0].=(exists $record{$version.':'.$matchKey[0]}) ?
1.80 ng 2708: '<b>Part '.$partid.' '.
2709: ($record{"$version:resource.$partid.tries"} eq '' ? 'Trial not counted' :
2710: 'Trial '.$record{"$version:resource.$partid.tries"}).'</b> '.
2711: $record{$version.':'.$matchKey[0]}.'<br />' : '';
1.71 ng 2712: $displaySub[1].=(exists $record{"$version:resource.$partid.award"}) ?
1.77 ng 2713: '<b>Part '.$partid.'</b> '.
1.71 ng 2714: $record{"$version:resource.$partid.award"}.'/'.
2715: $record{"$version:resource.$partid.solved"}.'<br />' : '';
1.72 ng 2716: $displaySub[2].=(exists $record{"$version:resource.$partid.regrader"}) ?
2717: $record{"$version:resource.$partid.regrader"}.' (<b>Part:</b> '.$partid.')' : '';
1.71 ng 2718: }
1.72 ng 2719: $displaySub[2].=(exists $record{"$version:resource.regrader"}) ?
2720: $record{"$version:resource.regrader"} : '';
2721: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1].
2722: ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).' </td></tr>';
1.71 ng 2723: }
2724: $studentTable.='</table></td></tr></table>';
2725: }
2726: } elsif ($ENV{'form.lastSub'} eq 'all') {
2727: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
2728: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
2729: $ENV{'request.course.id'},
2730: '','.submission');
2731:
2732: }
2733:
2734: foreach my $partid (@{$parts}) {
2735: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
2736: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
2737: $question++;
2738: }
2739: $studentTable.='</td></tr>';
1.68 ng 2740:
2741: }
2742: $curRes = $iterator->next();
2743: $ctr++;
2744: }
2745:
1.71 ng 2746: $studentTable.='</td></tr></table></td></tr></table>'."\n".
2747: ' <input type="button" value="Save" '.
2748: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
2749: '</form>'."\n";
2750: $studentTable.=&show_grading_menu_form($symb,$url);
2751: $request->print($studentTable);
2752:
2753: return '';
2754: }
2755:
2756: sub updateGradeByPage {
2757: my ($request) = shift;
2758:
2759: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2760: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2761: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2762: my $pageTitle = $ENV{'form.page'};
1.76 ng 2763: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.71 ng 2764: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
2765:
2766: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
2767: $result.='<h3> Student: '.$$fullname{$ENV{'form.student'}}.
2768: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
1.70 ng 2769:
1.68 ng 2770: $request->print($result);
2771:
1.79 bowersj2 2772: my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
1.71 ng 2773: $ENV{'request.course.fn'}.'_parms.db',1, 1);
2774: my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
2775: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2776:
2777: my $iterator = $navmap->getIterator($map->map_start(),
2778: $map->map_finish());
1.70 ng 2779:
1.71 ng 2780: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 2781: '<table border="0"><tr bgcolor="#e6ffff">'.
1.70 ng 2782: '<td align="center"><b> No </b></td>'.
1.71 ng 2783: '<td><b> Title </b></td>'.
2784: '<td><b> Previous Score </b></td>'.
2785: '<td><b> New Score </b></td></tr>';
2786:
2787: $iterator->next(); # skip the first BEGIN_MAP
2788: my $curRes = $iterator->next(); # for "current resource"
2789: my ($depth,$ctr,$question,$changeflag)= (1,0,1,0);
2790: while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
2791: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
2792: if($curRes == $iterator->END_MAP) { $depth++; }
2793:
2794: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.90 ! albertel 2795: my $parts = ['0',@{$curRes->parts()}];
! 2796: &APache::lonnet::logthis("parts ".join(':',@$parts));
1.71 ng 2797: my $title = $curRes->compTitle();
2798: my $symbx = $curRes->symb();
2799: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
2800: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
2801: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
2802:
2803: my %newrecord=();
2804: my @displayPts=();
2805: foreach my $partid (@{$parts}) {
2806: my $newpts = $ENV{'form.GD_BOX'.$question.'_'.$partid};
2807: my $oldpts = $ENV{'form.oldpts'.$question.'_'.$partid};
2808:
2809: my $wgt = $ENV{'form.WGT'.$question.'_'.$partid} != 0 ?
2810: $ENV{'form.WGT'.$question.'_'.$partid} : 1;
2811: my $partial = $newpts/$wgt;
2812: my $score;
2813: if ($partial > 0) {
2814: $score = 'correct_by_override';
2815: } elsif ($partial == 0) {
2816: $score = 'incorrect_by_override';
2817: }
2818: if ($ENV{'form.GD_SEL'.$question.'_'.$partid} eq 'excused') {
2819: $partial = '';
2820: $score = 'excused';
2821: }
2822: my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid};
2823: $displayPts[0].=' <b>Part</b> '.$partid.' = '.
2824: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
2825: ' <br>';
2826: $displayPts[1].=' <b>Part</b> '.$partid.' = '.
2827: ($oldstatus eq 'correct_by_student' ? $oldpts :
2828: (($score eq 'excused') ? 'excused' : $newpts)).
2829: ' <br>';
2830:
2831: $question++;
2832: if (($oldstatus eq 'correct_by_student') ||
2833: ($newpts eq $oldpts && $score eq $oldstatus))
2834: {
2835: next;
2836: }
2837: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
2838: $newrecord{'resource.'.$partid.'.solved'} = $score;
1.72 ng 2839: $newrecord{'resource.'.$partid.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.71 ng 2840:
2841: $changeflag++;
2842: }
2843: if (scalar(keys(%newrecord)) > 0) {
2844: &Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'},
2845: $udom,$uname);
2846: }
2847: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
2848: '<td valign="top">'.$displayPts[1].'</td>'.
2849: '</tr>';
1.68 ng 2850:
2851: }
1.71 ng 2852: $curRes = $iterator->next();
2853: $ctr++;
1.68 ng 2854: }
2855:
1.71 ng 2856: $studentTable.='</td></tr></table></td></tr></table>';
2857: $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
1.76 ng 2858: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
2859: 'The scores were changed for '.
2860: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
2861: $request->print($grademsg.$studentTable);
1.68 ng 2862:
1.70 ng 2863: return '';
2864: }
2865:
1.72 ng 2866: #-------- end of section for handling grading by page/sequence ---------
2867: #
2868: #-------------------------------------------------------------------
2869:
1.75 albertel 2870: #--------------------Scantron Grading-----------------------------------
2871: #
2872: #------ start of section for handling grading by page/sequence ---------
2873:
1.81 albertel 2874: sub defaultFormData {
2875: my ($symb,$url)=@_;
2876: return '
2877: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2878: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2879: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
2880: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
2881: }
2882:
1.75 albertel 2883: sub getSequenceDropDown {
2884: my ($request,$symb)=@_;
2885: my $result='<select name="selectpage">'."\n";
2886: my ($titles,$symbx) = &getSymbMap($request);
2887: my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
2888: my $ctr=0;
2889: foreach (@$titles) {
2890: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
2891: $result.='<option value="'.$$symbx{$_}.'" '.
2892: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
2893: '>'.$showtitle.'</option>'."\n";
2894: $ctr++;
2895: }
2896: $result.= '</select>';
2897: return $result;
2898: }
2899:
1.81 albertel 2900: sub scantron_uploads {
2901: if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
2902: my $result= '<select name="scantron_selectfile">';
2903: opendir(DIR,$Apache::lonnet::perlvar{'lonScansDir'});
2904: my @files=sort(readdir(DIR));
2905: foreach my $filename (@files) {
2906: if ($filename eq '.' or $filename eq '..') { next; }
2907: $result.="<option>$filename</option>\n";
2908: }
2909: closedir(DIR);
2910: $result.="</select>";
2911: return $result;
2912: }
2913:
1.82 albertel 2914: sub scantron_scantab {
2915: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
2916: my $result='<select name="scantron_format">'."\n";
2917: foreach my $line (<$fh>) {
2918: my ($name,$descrip)=split(/:/,$line);
2919: if ($name =~ /^\#/) { next; }
2920: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
2921: }
2922: $result.='</select>'."\n";
2923:
2924: return $result;
2925: }
2926:
1.75 albertel 2927: sub scantron_selectphase {
2928: my ($r) = @_;
2929: my ($symb,$url)=&get_symb_and_url($r);
2930: if (!$symb) {return '';}
2931: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.81 albertel 2932: my $default_form_data=&defaultFormData($symb,$url);
2933: my $grading_menu_button=&show_grading_menu_form($symb,$url);
2934: my $file_selector=&scantron_uploads();
1.82 albertel 2935: my $format_selector=&scantron_scantab();
1.75 albertel 2936: my $result;
2937: $result.= <<SCANTRONFORM;
1.82 albertel 2938: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
2939: <input type="hidden" name="command" value="scantron_process" />
1.81 albertel 2940: $default_form_data
1.75 albertel 2941: <table width="100%" border="0">
2942: <tr>
2943: <td bgcolor="#777777">
2944: <table width="100%" border="0">
2945: <tr bgcolor="#e6ffff">
2946: <td>
2947: <b>Specify file location and which Folder/Sequence to grade</b>
2948: </td>
2949: </tr>
2950: <tr bgcolor="#ffffe6">
2951: <td>
2952: Sequence to grade: $sequence_selector
2953: </td>
2954: </tr>
2955: <tr bgcolor="#ffffe6">
2956: <td>
1.81 albertel 2957: Filename of scoring office file: $file_selector
1.75 albertel 2958: </td>
2959: </tr>
1.82 albertel 2960: <tr bgcolor="#ffffe6">
2961: <td>
2962: Format of data file: $format_selector
2963: </td>
2964: </tr>
1.75 albertel 2965: </table>
2966: </td>
2967: </tr>
2968: </table>
2969: <input type="submit" value="Submit" />
2970: </form>
1.81 albertel 2971: $grading_menu_button
1.75 albertel 2972: SCANTRONFORM
2973:
2974: return $result;
2975: }
2976:
1.82 albertel 2977: sub get_scantron_config {
2978: my ($which) = @_;
2979: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
2980: my %config;
2981: foreach my $line (<$fh>) {
2982: my ($name,$descrip)=split(/:/,$line);
2983: if ($name ne $which ) { next; }
2984: chomp($line);
2985: my @config=split(/:/,$line);
2986: $config{'name'}=$config[0];
2987: $config{'description'}=$config[1];
2988: $config{'CODElocation'}=$config[2];
2989: $config{'CODEstart'}=$config[3];
2990: $config{'CODElength'}=$config[4];
2991: $config{'IDstart'}=$config[5];
2992: $config{'IDlength'}=$config[6];
2993: $config{'Qstart'}=$config[7];
2994: $config{'Qlength'}=$config[8];
2995: $config{'Qoff'}=$config[9];
2996: $config{'Qon'}=$config[10];
2997: last;
2998: }
2999: return %config;
3000: }
3001:
3002: sub username_to_idmap {
3003: my ($classlist)= @_;
3004: my %idmap;
3005: foreach my $student (keys(%$classlist)) {
3006: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
3007: $student;
3008: }
3009: return %idmap;
3010: }
3011:
3012: sub scantron_parse_scanline {
3013: my ($line,$scantron_config)=@_;
3014: my %record;
3015: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
3016: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
3017: if ($$scantron_config{'CODElocation'} ne 0) {
3018: if ($$scantron_config{'CODElocation'} < 0) {
1.83 albertel 3019: $record{'scantron.CODE'}=substr($data,$$scantron_config{'CODEstart'}-1,
3020: $$scantron_config{'CODElength'});
1.82 albertel 3021: } else {
3022: #FIXME interpret first N questions
3023: }
3024: }
1.83 albertel 3025: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
3026: $$scantron_config{'IDlength'});
1.82 albertel 3027: my @alphabet=('A'..'Z');
3028: my $questnum=0;
3029: while ($questions) {
3030: $questnum++;
3031: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
3032: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 3033: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.82 albertel 3034: my (@array)=split(/$$scantron_config{'Qon'}/,$currentquest);
3035: if (scalar(@array) gt 2) {
3036: #FIXME do something intelligent with double bubbles
1.83 albertel 3037: Apache->request->print("<br ><b>Wha!!!</b> <pre>".scalar(@array).
3038: '-'.$currentquest.'-'.$questnum.'</pre><br />');
1.82 albertel 3039: }
3040: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
1.83 albertel 3041: $record{"scantron.$questnum.answer"}='';
1.82 albertel 3042: } else {
1.83 albertel 3043: $record{"scantron.$questnum.answer"}=$alphabet[length($array[0])];
1.82 albertel 3044: }
3045: }
1.83 albertel 3046: $record{'scantron.maxquest'}=$questnum;
3047: return \%record;
1.82 albertel 3048: }
3049:
3050: sub scantron_add_delay {
3051: }
3052:
3053: sub scantron_find_student {
1.83 albertel 3054: my ($scantron_record,$idmap)=@_;
3055: my $scanID=$$scantron_record{'scantron.ID'};
3056: foreach my $id (keys(%$idmap)) {
3057: Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
3058: if (lc($id) eq lc($scanID)) { Apache->request->print('success');return $$idmap{$id}; }
3059: }
3060: return undef;
3061: }
3062:
3063: sub scantron_filter {
3064: my ($curres)=@_;
3065: if (ref($curres) && $curres->is_problem() && !$curres->randomout) {
3066: return 1;
3067: }
3068: return 0;
1.82 albertel 3069: }
3070:
3071: sub scantron_process_students {
1.75 albertel 3072: my ($r) = @_;
1.81 albertel 3073: my (undef,undef,$sequence)=split(/___/,$ENV{'form.selectpage'});
3074: my ($symb,$url)=&get_symb_and_url($r);
3075: if (!$symb) {return '';}
3076: my $default_form_data=&defaultFormData($symb,$url);
1.82 albertel 3077:
3078: my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'});
3079: my $scanlines=Apache::File->new($Apache::lonnet::perlvar{'lonScansDir'}."/$ENV{'form.scantron_selectfile'}");
1.85 albertel 3080: my @scanlines=<$scanlines>;
1.82 albertel 3081: my $classlist=&Apache::loncoursedata::get_classlist();
3082: my %idmap=&username_to_idmap($classlist);
1.83 albertel 3083: my $navmap=Apache::lonnavmaps::navmap->new($ENV{'request.course.fn'}.'.db',$ENV{'request.course.fn'}.'_parms.db',1, 1);
3084: my $map=$navmap->getResourceByUrl($sequence);
3085: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
3086: $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 3087: my $result= <<SCANTRONFORM;
1.81 albertel 3088: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
3089: <input type="hidden" name="command" value="scantron_configphase" />
3090: $default_form_data
3091: SCANTRONFORM
1.82 albertel 3092: $r->print($result);
3093:
3094: my @delayqueue;
1.85 albertel 3095: my $totalcorrect;
3096: my $totalincorrect;
3097:
3098: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
3099: 'Scantron Status','Scantron Progress',scalar(@scanlines));
3100: foreach my $line (@scanlines) {
3101: my $studentcorrect;
3102: my $studentincorrect;
1.75 albertel 3103:
1.83 albertel 3104: chomp($line);
1.82 albertel 3105: my $scan_record=&scantron_parse_scanline($line,\%scantron_config);
3106: my ($uname,$udom);
3107: if ($uname=&scantron_find_student($scan_record,\%idmap)) {
3108: &scantron_add_delay(\@delayqueue,$line,
3109: 'Unable to find a student that matches');
3110: }
1.83 albertel 3111: $r->print('<pre>doing studnet'.$uname.'</pre>');
1.82 albertel 3112: ($uname,$udom)=split(/:/,$uname);
1.85 albertel 3113: &Apache::lonnet::delenv('form.counter');
1.83 albertel 3114: &Apache::lonnet::appenv(%$scan_record);
1.85 albertel 3115: # &Apache::lonhomework::showhash(%ENV);
1.83 albertel 3116: $Apache::lonxml::debug=1;
1.85 albertel 3117: &Apache::lonxml::debug("line is $line");
1.83 albertel 3118:
1.85 albertel 3119: my $i=0;
1.83 albertel 3120: foreach my $resource (@resources) {
1.85 albertel 3121: $i++;
1.83 albertel 3122: my $result=&Apache::lonnet::ssi($resource->src(),
3123: ('submitted' =>'scantron',
3124: 'grade_target' =>'grade',
3125: 'grade_username'=>$uname,
3126: 'grade_domain' =>$udom,
3127: 'grade_courseid'=>$ENV{'request.course.id'},
3128: 'grade_symb' =>$resource->symb()));
1.85 albertel 3129: my %score=&Apache::lonnet::restore($resource->symb(),
3130: $ENV{'request.course.id'},
3131: $udom,$uname);
3132: foreach my $part ($resource->{PARTS}) {
3133: if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
3134: $studentcorrect++;
3135: $totalcorrect++;
3136: } else {
3137: $studentincorrect++;
3138: $totalincorrect++;
3139: }
3140: }
1.83 albertel 3141: $r->print('<pre>'.
3142: $resource->symb().'-'.
3143: $resource->src().'-'.'</pre>result is'.$result);
1.85 albertel 3144: &Apache::lonhomework::showhash(%score);
3145: # if ($i eq 3) {last;}
1.83 albertel 3146: }
1.85 albertel 3147: &Apache::lonnet::delenv('form.counter');
1.83 albertel 3148: &Apache::lonnet::delenv('scantron\.');
1.85 albertel 3149: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
3150: 'last student Who got a '.$studentcorrect.' correct and '.
3151: $studentincorrect.' incorrect. The class has gotten '.
3152: $totalcorrect.' correct and '.$totalincorrect.' incorrect');
1.83 albertel 3153: last;
1.82 albertel 3154: #FIXME
3155: #get iterator for $sequence
3156: #foreach question 'submit' the students answer to the server
3157: # through grade target {
3158: # generate data to pass back that includes grade recevied
3159: #}
3160: }
1.85 albertel 3161: $Apache::lonxml::debug=0;
1.82 albertel 3162: foreach my $delay (@delayqueue) {
3163: #FIXME
3164: #print out each delayed student with interface to select how
3165: # to repair student provided info
3166: #Expected errors include
3167: # 1 bad/no stuid/username
3168: # 2 invalid bubblings
3169:
3170: }
1.75 albertel 3171: #FIXME
3172: # if delay queue exists 2 submits one to process delayed students one
3173: # to ignore delayed students, possibly saving the delay queue for later
1.85 albertel 3174:
3175: $navmap->untieHashes();
1.75 albertel 3176: }
3177: #-------- end of section for handling grading scantron forms -------
3178: #
3179: #-------------------------------------------------------------------
3180:
3181:
1.72 ng 3182: #-------------------------- Menu interface -------------------------
3183: #
3184: #--- Show a Grading Menu button - Calls the next routine ---
3185: sub show_grading_menu_form {
3186: my ($symb,$url)=@_;
3187: my $result.='<form action="/adm/grades" method="post">'."\n".
3188: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3189: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.77 ng 3190: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 3191: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
3192: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
3193: '</form>'."\n";
3194: return $result;
3195: }
3196:
1.77 ng 3197: # -- Retrieve choices for grading form
3198: sub savedState {
3199: my %savedState = ();
3200: if ($ENV{'form.saveState'}) {
3201: foreach (split(/:/,$ENV{'form.saveState'})) {
3202: my ($key,$value) = split(/=/,$_,2);
3203: $savedState{$key} = $value;
3204: }
3205: }
3206: return \%savedState;
3207: }
1.76 ng 3208:
1.72 ng 3209: #--- Displays the main menu page -------
3210: sub gradingmenu {
3211: my ($request) = @_;
3212: my ($symb,$url)=&get_symb_and_url($request);
3213: if (!$symb) {return '';}
1.76 ng 3214: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 3215:
3216: $request->print(<<GRADINGMENUJS);
3217: <script type="text/javascript" language="javascript">
3218: function checkChoice(formname) {
3219: var cmd = formname.command;
1.77 ng 3220: formname.saveState.value = "saveCmd="+radioSelection(cmd)+":saveSec="+pullDownSelection(formname.section)+
3221: ":saveSub="+radioSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.status);
1.86 ng 3222: if (cmd[0].checked || cmd[1].checked || cmd[2].checked || cmd[3].checked || cmd[4].checked) formname.submit();
1.75 albertel 3223: if (cmd[5].checked) {
1.72 ng 3224: if (!checkReceiptNo(formname,'notOK')) { return false;}
3225: formname.submit();
3226: }
3227: }
3228:
3229: function checkReceiptNo(formname,nospace) {
3230: var receiptNo = formname.receipt.value;
3231: var checkOpt = false;
3232: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
3233: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
3234: if (checkOpt) {
3235: alert("Please enter a receipt number given by a student in the receipt box.");
3236: formname.receipt.value = "";
3237: formname.receipt.focus();
3238: return false;
3239: }
1.76 ng 3240: formname.command[5].checked = true;
1.72 ng 3241: return true;
3242: }
3243:
3244: function radioSelection(radioButton) {
3245: var selection=null;
1.76 ng 3246: if (radioButton.length > 1) {
3247: for (var i=0; i<radioButton.length; i++) {
3248: if (radioButton[i].checked) {
3249: return radioButton[i].value;
3250: }
1.72 ng 3251: }
1.76 ng 3252: } else {
3253: if (radioButton.checked) return radioButton.value;
1.72 ng 3254: }
3255: return selection;
3256: }
1.68 ng 3257:
1.72 ng 3258: function pullDownSelection(selectOne) {
3259: var selection="";
1.76 ng 3260: if (selectOne.length > 1) {
3261: for (var i=0; i<selectOne.length; i++) {
3262: if (selectOne[i].selected) {
3263: return selectOne[i].value;
3264: }
1.72 ng 3265: }
1.76 ng 3266: } else {
3267: if (selectOne.selected) return selectOne.value;
1.72 ng 3268: }
3269: }
1.76 ng 3270:
1.72 ng 3271: </script>
3272: GRADINGMENUJS
3273:
3274: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>'.
3275: '<table border="0">'.
1.76 ng 3276: '<tr><td colspan=3><font size=+1><b>Problem: </b>'.$probTitle.'</font></td></tr>'."\n";
1.72 ng 3277: my ($partlist,$handgrade) = &response_type($url);
3278: my ($resptype,$hdgrade)=('','no');
3279: for (sort keys(%$handgrade)) {
3280: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
3281: $resptype = $responsetype;
3282: $hdgrade = $handgrade if ($handgrade eq 'yes');
3283: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
3284: '<td><b>Type: </b>'.$responsetype.'</td>'.
3285: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
3286: }
1.76 ng 3287: $result.='</table>'."\n";
1.72 ng 3288:
1.76 ng 3289: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 3290: my $savedState = &savedState();
3291: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'pickStudentPage' : $$savedState{'saveCmd'});
3292: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
3293: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'yes' : $$savedState{'saveSub'});
3294: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 3295:
3296: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
3297: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3298: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3299: '<input type="hidden" name="response" value="'.$resptype.'" />'."\n".
3300: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
3301: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.77 ng 3302: '<input type="hidden" name="saveState" value="" />'."\n".
1.72 ng 3303: '<input type="hidden" name="showgrading" value="yes" />'."\n";
3304:
3305: $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n".
3306: '<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n".
3307: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
3308: '<tr bgcolor=#ffffe6><td>'."\n";
3309:
3310: $result.='<table width=100% border=0>'.
3311: '<tr bgcolor="#ffffe6" valign="top"><td colspan="2">'.
3312: '<input type="radio" name="command" value="pickStudentPage" '.
1.76 ng 3313: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
1.72 ng 3314: 'Handgrade/View Submission for a student by page/sequence</td></tr>'."\n".
3315:
3316: '<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
3317: '<input type="radio" name="command" value="viewgrades" '.
1.76 ng 3318: ($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
1.72 ng 3319: 'Grade by section or class</td></tr>'."\n".
3320:
3321: '<tr bgcolor="#ffffe6"valign="top"><td><input type="radio" name="command" value="submission" '.
1.76 ng 3322: ($saveCmd eq 'submission' ? 'checked' : '').'> '.
1.72 ng 3323: ($hdgrade eq 'yes' ? 'View/Grade essay response of' : 'View').
3324: ' an individual student </td>'."\n".
3325: '<td>--> For students who has: '.
1.76 ng 3326: '<input type="radio" name="submitonly" value="yes" '.
3327: ($saveSub eq 'yes' ? 'checked' : '').' /> submitted'.
3328: '<input type="radio" name="submitonly" value="all" '.
3329: ($saveSub eq 'all' ? 'checked' : '').' /> everybody</td></tr>'."\n".
1.46 ng 3330:
1.72 ng 3331: '<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.86 ng 3332: '<input type="radio" name="command" value="csvform" '.
3333: ($saveCmd eq 'csvform' ? 'checked' : '').'> '.
1.72 ng 3334: 'Upload scores from file</td></tr>'."\n";
3335:
1.75 albertel 3336: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.81 albertel 3337: '<input type="radio" name="command" value="scantron_selectphase" '.
3338: ($saveCmd eq 'scantron_selectphase' ? 'checked="on"' : '').' /> '.
1.75 albertel 3339: 'Grade scantron forms</td></tr>'."\n";
3340:
1.72 ng 3341: if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)) {
3342: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.76 ng 3343: '<input type="radio" name="command" value="verify" onChecked="javascript:this.form.receipt.focus()" '.
3344: ($saveCmd eq 'verify' ? 'checked' : '').'> '.
1.72 ng 3345: 'Verify a submission receipt issued by this server</td>'.
3346: '<td>--> Receipt no: '.unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).
3347: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
3348: '</td></tr>'."\n";
3349: }
1.44 ng 3350:
1.72 ng 3351: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2"><br />'."\n".
1.76 ng 3352: ' Select section: <select name="section">'."\n";
1.72 ng 3353: if (ref($sections)) {
3354: foreach (sort (@$sections)) {$result.='<option value="'.$_.'" '.
1.76 ng 3355: ($saveSec eq $_ ? 'selected="on"' : '').'>'.$_.'</option>'."\n";}
1.44 ng 3356: }
1.76 ng 3357: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</select> ';
3358:
3359: $result.='Student Status:</b><select name="status">'.
3360: '<option value="Active" '.($saveStatus eq 'Active' ? 'selected' : '').'>Active</option>'.
3361: '<option value="Expired" '.($saveStatus eq 'Expired' ? 'selected' : '').'>Expired</option>'.
3362: '<option value="Any" '.($saveStatus eq 'Any' ? 'selected' : '').'>Any</option>'.
3363: '</select>';
3364:
3365: $result.=' <font color="red">(Applies to the first three options only.)</font>'."\n";
3366:
1.72 ng 3367: if (ref($sections)) {
3368: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
3369: if (grep /no/,@$sections);
1.44 ng 3370: }
1.72 ng 3371: $result.='</td></tr>';
3372:
3373: $result.='<tr bgcolor="#ffffe6"><td colspan="2"><br />'.
3374: '<input type="button" onClick="javascript:checkChoice(this.form);" value="View/Grade" />'."\n".
3375: '</form></td></tr></table>'."\n".
3376: '</td></tr></table>'."\n".
3377: '</td></tr></table>'."\n";
1.44 ng 3378: return $result;
1.2 albertel 3379: }
3380:
1.1 albertel 3381: sub handler {
1.41 ng 3382: my $request=$_[0];
3383:
3384: if ($ENV{'browser.mathml'}) {
3385: $request->content_type('text/xml');
3386: } else {
3387: $request->content_type('text/html');
3388: }
3389: $request->send_http_header;
1.44 ng 3390: return '' if $request->header_only;
1.41 ng 3391: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
3392: my $url=$ENV{'form.url'};
3393: my $symb=$ENV{'form.symb'};
3394: my $command=$ENV{'form.command'};
3395: if (!$url) {
3396: my ($temp1,$temp2);
3397: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
3398: $url = $ENV{'form.url'};
3399: }
3400: &send_header($request);
3401: if ($url eq '' && $symb eq '') {
3402: if ($ENV{'user.adv'}) {
3403: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
3404: ($ENV{'form.codethree'})) {
3405: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
3406: $ENV{'form.codethree'};
3407: my ($tsymb,$tuname,$tudom,$tcrsid)=
3408: &Apache::lonnet::checkin($token);
3409: if ($tsymb) {
3410: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
3411: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
3412: $request->print(
3413: &Apache::lonnet::ssi('/res/'.$url,
3414: ('grade_username' => $tuname,
3415: 'grade_domain' => $tudom,
3416: 'grade_courseid' => $tcrsid,
3417: 'grade_symb' => $tsymb)));
3418: } else {
1.45 ng 3419: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.41 ng 3420: }
3421: } else {
1.45 ng 3422: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 3423: }
1.14 www 3424: } else {
1.41 ng 3425: $request->print(&Apache::lonxml::tokeninputfield());
3426: }
3427: }
3428: } else {
3429: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
3430: if ($command eq 'submission') {
1.68 ng 3431: ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
3432: } elsif ($command eq 'pickStudentPage') {
3433: &pickStudentPage($request);
3434: } elsif ($command eq 'displayPage') {
3435: &displayPage($request);
1.71 ng 3436: } elsif ($command eq 'gradeByPage') {
3437: &updateGradeByPage($request);
1.41 ng 3438: } elsif ($command eq 'processGroup') {
3439: &processGroup($request);
3440: } elsif ($command eq 'gradingmenu') {
3441: $request->print(&gradingmenu($request));
3442: } elsif ($command eq 'viewgrades') {
3443: $request->print(&viewgrades($request));
3444: } elsif ($command eq 'handgrade') {
3445: $request->print(&processHandGrade($request));
3446: } elsif ($command eq 'editgrades') {
3447: $request->print(&editgrades($request));
3448: } elsif ($command eq 'verify') {
3449: $request->print(&verifyreceipt($request));
1.72 ng 3450: } elsif ($command eq 'csvform') {
3451: $request->print(&upcsvScores_form($request));
1.41 ng 3452: } elsif ($command eq 'csvupload') {
3453: $request->print(&csvupload($request));
3454: } elsif ($command eq 'viewclasslist') {
3455: $request->print(&viewclasslist($request));
3456: } elsif ($command eq 'csvuploadmap') {
3457: $request->print(&csvuploadmap($request));
3458: } elsif ($command eq 'csvuploadassign') {
3459: if ($ENV{'form.associate'} ne 'Reverse Association') {
3460: $request->print(&csvuploadassign($request));
3461: } else {
3462: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
3463: $ENV{'form.upfile_associate'} = 'reverse';
3464: } else {
3465: $ENV{'form.upfile_associate'} = 'forward';
3466: }
3467: $request->print(&csvuploadmap($request));
3468: }
1.75 albertel 3469: } elsif ($command eq 'scantron_selectphase') {
3470: $request->print(&scantron_selectphase($request));
1.82 albertel 3471: } elsif ($command eq 'scantron_process') {
3472: $request->print(&scantron_process_students($request));
1.26 albertel 3473: } else {
1.41 ng 3474: $request->print("Unknown action: $command:");
1.26 albertel 3475: }
1.2 albertel 3476: }
1.41 ng 3477: &send_footer($request);
1.44 ng 3478: return '';
3479: }
3480:
3481: sub send_header {
3482: my ($request)= @_;
3483: $request->print(&Apache::lontexconvert::header());
3484: # $request->print("
3485: #<script>
3486: #remotewindow=open('','homeworkremote');
3487: #remotewindow.close();
3488: #</script>");
1.47 www 3489: $request->print(&Apache::loncommon::bodytag('Grading'));
1.44 ng 3490: }
3491:
3492: sub send_footer {
3493: my ($request)= @_;
3494: $request->print('</body>');
3495: $request->print(&Apache::lontexconvert::footer());
1.1 albertel 3496: }
3497:
3498: 1;
3499:
1.13 albertel 3500: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>