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