File:
[LON-CAPA] /
loncom /
homework /
grades.pm
Revision
1.57:
download - view:
text,
annotated -
select for diffs
Thu Oct 17 14:35:34 2002 UTC (21 years, 10 months ago) by
matthew
Branches:
MAIN
CVS tags:
HEAD
Rewrite of collaborator code. I have no means currently of testing this
code so it may not have the functionality needed. At least it compiles.
Added regular expression to &keywords_highlight to clean up display
of essay responses.
Made showing the problem the default when grading.
1: # The LearningOnline Network with CAPA
2: # The LON-CAPA Grading handler
3: #
4: # $Id: grades.pm,v 1.57 2002/10/17 14:35:34 matthew 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: #
35:
36: package Apache::grades;
37: use strict;
38: use Apache::style;
39: use Apache::lonxml;
40: use Apache::lonnet;
41: use Apache::loncommon;
42: use Apache::lonhomework;
43: use Apache::loncoursedata;
44: use Apache::lonmsg qw(:user_normal_msg);
45: use Apache::Constants qw(:common);
46:
47: # ----- These first few routines are general use routines.-----
48: #
49: # --- Retrieve the parts that matches stores_\d+ from the metadata file.---
50: sub getpartlist {
51: my ($url) = @_;
52: my @parts =();
53: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
54: foreach my $key (@metakeys) {
55: if ( $key =~ m/stores_(\w+)_.*/) {
56: push(@parts,$key);
57: }
58: }
59: return @parts;
60: }
61:
62: # --- Get the symbolic name of a problem and the url
63: sub get_symb_and_url {
64: my ($request) = @_;
65: (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
66: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
67: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
68: return ($symb,$url);
69: }
70:
71: # --- Retrieve the fullname for a user. Return lastname, first middle ---
72: # --- Generation is attached next to the lastname if it exists. ---
73: sub get_fullname {
74: my ($uname,$udom) = @_;
75: my %name=&Apache::lonnet::get('environment', ['lastname','generation',
76: 'firstname','middlename'],
77: $udom,$uname);
78: my $fullname;
79: my ($tmp) = keys(%name);
80: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
81: $fullname = &Apache::loncoursedata::ProcessFullName
82: (@name{qw/lastname generation firstname middlename/});
83: } else {
84: &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
85: '@'.$udom.':'.$tmp);
86: }
87: return $fullname;
88: }
89:
90: #--- Get the partlist and the response type for a given problem. ---
91: #--- Indicate if a response type is coded handgraded or not. ---
92: sub response_type {
93: my ($url) = shift;
94: my $allkeys = &Apache::lonnet::metadata($url,'keys');
95: my %seen = ();
96: my (@partlist,%handgrade);
97: foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
98: if (/^\w+response_\w+.*/) {
99: my ($responsetype,$part) = split(/_/,$_,2);
100: my ($partid,$respid) = split(/_/,$part);
101: $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
102: next if ($seen{$partid} > 0);
103: $seen{$partid}++;
104: push @partlist,$partid;
105: }
106: }
107: return \@partlist,\%handgrade;
108: }
109:
110: #--- Dumps the class list with usernames,list of sections,
111: #--- section, ids and fullnames for each user.
112: sub getclasslist {
113: my ($getsec,$hideexpired) = @_;
114: my $classlist=&Apache::loncoursedata::get_classlist();
115: # Bail out if we were unable to get the classlist
116: return if (! defined($classlist));
117: #
118: my %sections;
119: my %fullnames;
120: foreach (keys(%$classlist)) {
121: # the following undefs are for 'domain', and 'username' respectively.
122: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
123: @{$classlist->{$_}};
124: # still a student?
125: if (($hideexpired) && ($status ne 'Active')) {
126: delete ($classlist->{$_});
127: next;
128: }
129: $section = ($section ne '' ? $section : 'no');
130: if ($getsec eq 'all' || $getsec eq $section) {
131: $sections{$section}++;
132: $fullnames{$_}=$fullname;
133: } else {
134: delete($classlist->{$_});
135: }
136: }
137: my %seen = ();
138: my @sections = sort(keys(%sections));
139: return ($classlist,\@sections,\%fullnames);
140: }
141:
142: #find user domain
143: sub finduser {
144: my ($name) = @_;
145: my $domain = '';
146: if ( $Apache::grades::viewgrades eq 'F' ) {
147: my %classlist=&Apache::lonnet::dump('classlist',
148: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
149: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
150: my (@fields) = grep /^$name:/, keys %classlist;
151: ($name, $domain) = split(/:/,$fields[0]);
152: return ($name,$domain);
153: } else {
154: return ($ENV{'user.name'},$ENV{'user.domain'});
155: }
156: }
157:
158: #--- Prompts a user to enter a username.
159: sub moreinfo {
160: my ($request,$reason) = @_;
161: $request->print("Unable to process request: $reason");
162: if ( $Apache::grades::viewgrades eq 'F' ) {
163: $request->print('<form action="/adm/grades" method="post">'."\n");
164: if ($ENV{'form.url'}) {
165: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
166: }
167: if ($ENV{'form.symb'}) {
168: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
169: }
170: $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
171: $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
172: $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
173: $request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
174: $request->print('</form>');
175: }
176: return '';
177: }
178:
179: #--- Retrieve the grade status of a student for all the parts
180: sub student_gradeStatus {
181: my ($url,$symb,$udom,$uname,$partlist) = @_;
182: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
183: my %partstatus = ();
184: foreach (@$partlist) {
185: my ($status,$foo) = split(/_/,$record{"resource.$_.solved"},2);
186: $status = 'nothing' if ($status eq '');
187: $partstatus{$_} = $status;
188: my $subkey = "resource.$_.submitted_by";
189: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
190: }
191: return %partstatus;
192: }
193:
194: # hidden form and javascript that calls the form
195: # Use by verifyscript and viewgrades
196: # Shows a student's view of problem and submission
197: sub jscriptNform {
198: my ($url,$symb) = @_;
199: my $jscript='<script type="text/javascript" language="javascript">'."\n".
200: ' function viewOneStudent(user,domain) {'."\n".
201: ' document.onestudent.student.value = user;'."\n".
202: ' document.onestudent.userdom.value = domain;'."\n".
203: ' document.onestudent.submit();'."\n".
204: ' }'."\n".
205: '</script>'."\n";
206: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
207: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
208: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
209: '<input type="hidden" name="command" value="submission" />'."\n".
210: '<input type="hidden" name="student" value="" />'."\n".
211: '<input type="hidden" name="userdom" value="" />'."\n".
212: '</form>'."\n";
213: return $jscript;
214: }
215:
216: #------------------ End of general use routines --------------------
217: #-------------------------------------------------------------------
218:
219: #------------------------------------ Receipt Verification Routines
220: #
221: #--- Check whether a receipt number is valid.---
222: sub verifyreceipt {
223: my $request = shift;
224:
225: my $courseid = $ENV{'request.course.id'};
226: my $receipt = unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
227: $ENV{'form.receipt'};
228: $receipt =~ s/[^\-\d]//g;
229: my $url = $ENV{'form.url'};
230: my $symb = $ENV{'form.symb'};
231: unless ($symb) {
232: $symb = &Apache::lonnet::symbread($url);
233: }
234:
235: my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
236: $receipt.'</h3></font>'."\n".
237: '<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font><br><br>'."\n";
238:
239: my ($string,$contents,$matches) = ('','',0);
240: my (undef,undef,$fullname) = &getclasslist('all','0');
241:
242: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
243: my ($uname,$udom)=split(/\:/);
244: if ($receipt eq
245: &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
246: $contents.='<tr bgcolor="#ffffe6"><td> '."\n".
247: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
248: '\')"; TARGET=_self>'.$$fullname{$_}.'</a> </td>'."\n".
249: '<td> '.$uname.' </td>'.
250: '<td> '.$udom.' </td></tr>'."\n";
251:
252: $matches++;
253: }
254: }
255: if ($matches == 0) {
256: $string = $title.'No match found for the above receipt.';
257: } else {
258: $string = &jscriptNform($url,$symb).$title.
259: 'The above receipt matches the following student'.
260: ($matches <= 1 ? '.' : 's.')."\n".
261: '<table border="0"><tr><td bgcolor="#777777">'."\n".
262: '<table border="0"><tr bgcolor="#e6ffff">'."\n".
263: '<td><b> Fullname </b></td>'."\n".
264: '<td><b> Username </b></td>'."\n".
265: '<td><b> Domain </b></td></tr>'."\n".
266: $contents.
267: '</table></td></tr></table>'."\n";
268: }
269: return $string.&show_grading_menu_form($symb,$url);
270: }
271:
272: #--- This is called by a number of programs.
273: #--- Called from the Grading Menu - View/Grade an individual student
274: #--- Also called directly when one clicks on the subm button
275: # on the problem page.
276: sub listStudents {
277: my ($request) = shift;
278:
279: my ($symb,$url) = &get_symb_and_url();
280: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
281: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
282: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
283: my $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
284:
285: my $result;
286: my ($partlist,$handgrade) = &response_type($url);
287: for (sort keys(%$handgrade)) {
288: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
289: $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes');
290: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
291: '<td><b>Type: </b>'.$responsetype.'</td>'.
292: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
293: }
294: $result.='</table>';
295:
296: my $viewgrade;
297: if ($ENV{'form.handgrade'} eq 'yes') {
298: $viewgrade = 'View/Grade';
299: } else {
300: $viewgrade = 'View';
301: }
302:
303: $result='<h3><font color="#339933"> '.
304: $viewgrade.
305: ' Submissions for a Student or a Group of Students</font></h3>'.
306: '<table border="0"><tr><td colspan=3><font size=+1>'.
307: '<b>Resource: </b>'.$url.'</font></td></tr>'.$result;
308:
309: $request->print(<<LISTJAVASCRIPT);
310: <script type="text/javascript" language="javascript">
311: function checkSelect(checkBox) {
312: var ctr=0;
313: var sense="";
314: if (checkBox.length > 1) {
315: for (var i=0; i<checkBox.length; i++) {
316: if (checkBox[i].checked) {
317: ctr++;
318: }
319: }
320: sense = "a student or group of students";
321: } else {
322: if (checkBox.checked) {
323: ctr = 1;
324: }
325: sense = "the student";
326: }
327: if (ctr == 0) {
328: alert("Please select "+sense+" before clicking on the $viewgrade button.");
329: return false;
330: }
331: document.gradesub.submit();
332: }
333: </script>
334: LISTJAVASCRIPT
335:
336: $request->print($result);
337:
338: my $checkhdgrade = $ENV{'form.handgrade'} eq 'yes' ? 'checked' : '';
339: my $checklastsub = $ENV{'form.handgrade'} eq 'yes' ? '' : 'checked';
340:
341: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
342: ' <b>View Problem: </b><input type="radio" name="vProb" value="no" > no '."\n".
343: '<input type="radio" name="vProb" value="yes" checked > yes <br />'."\n".
344: ' <b>Submissions: </b>'."\n";
345: if ($ENV{'form.handgrade'} eq 'yes') {
346: $gradeTable.='<input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> handgrade only'."\n";
347: }
348: $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last sub only'."\n".
349: '<input type="radio" name="lastSub" value="last" /> last sub & parts info'."\n".
350: '<input type="radio" name="lastSub" value="all" /> all details'."\n".
351: '<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
352: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
353: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'" />'."\n".
354: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'" /><br />'."\n".
355: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" /><br />'."\n".
356: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
357: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
358: 'To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n".
359: 'click on the '.$viewgrade.' button. To view the submissions for a group of students, click'."\n".
360: ' on the check boxes for the group of students.<br />'."\n".
361: '<input type="hidden" name="command" value="processGroup" />'."\n".
362: '<input type="button" '."\n".
363: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
364: 'value="'.$viewgrade.'" />'."\n";
365:
366: my (undef,undef,$fullname) = &getclasslist($getsec,'0');
367:
368: $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
369: '<table border="0"><tr bgcolor="#e6ffff">'.
370: '<td><b> Select </b></td><td><b> Fullname </b></td>'.
371: '<td><b> Username </b></td><td><b> Domain </b></td>';
372: foreach (sort(@$partlist)) {
373: $gradeTable.='<td><b> Part '.(split(/_/))[0].' Status </b></td>';
374: }
375: $gradeTable.='</tr>'."\n";
376:
377: my $ctr = 0;
378: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
379: my ($uname,$udom) = split(/:/,$student);
380: my (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
381: my $statusflg = '';
382: foreach (keys(%status)) {
383: $statusflg = 1 if ($status{$_} ne 'nothing');
384: my ($foo,$partid,$foo1) = split(/\./,$_);
385: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
386: $statusflg = '';
387: $gradeTable.='<input type="hidden" name="'.
388: $student.':submitted_by" value="'.
389: $status{'resource.'.$partid.'.submitted_by'}.'" />';
390: }
391: }
392: next if ($statusflg eq '' && $submitonly eq 'yes');
393:
394: $ctr++;
395: if ( $Apache::grades::viewgrades eq 'F' ) {
396: $gradeTable.='<tr bgcolor="#ffffe6">'.
397: '<td align="center"><input type=checkbox name="stuinfo" value="'.
398: $student.':'.$$fullname{$student}.'"></td>'."\n".
399: '<td> '.$$fullname{$student}.' </td>'."\n".
400: '<td> '.$uname.' </td>'."\n".
401: '<td align="middle"> '.$udom.' </td>'."\n";
402:
403: foreach (sort keys(%status)) {
404: next if (/^resource.*?submitted_by$/);
405: $gradeTable.='<td align="middle"> '.$status{$_}.' </td>'."\n";
406: }
407: $gradeTable.='</tr>'."\n";
408: }
409: }
410: $gradeTable.='</table></td></tr></table>'.
411: '<input type="button" '.
412: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
413: 'value="'.$viewgrade.'" /></form>'."\n";
414: if ($ctr == 0) {
415: $gradeTable='<br /> <font color="red">'.
416: 'No submission found for this resource.</font><br />';
417: } elsif ($ctr == 1) {
418: $gradeTable =~ s/type=checkbox/type=checkbox checked/;
419: }
420: $gradeTable.=&show_grading_menu_form($symb,$url);
421: $request->print($gradeTable);
422: return '';
423: }
424:
425: #---- Called from the listStudents routine
426: # Displays the submissions for one student or a group of students
427: sub processGroup {
428: my ($request) = shift;
429: my $ctr = 0;
430: my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
431: : ($ENV{'form.stuinfo'}));
432: my $total = scalar(@stuchecked)-1;
433:
434: foreach (@stuchecked) {
435: my ($uname,$udom,$fullname) = split(/:/);
436: $ENV{'form.student'} = $uname;
437: $ENV{'form.userdom'} = $udom;
438: $ENV{'form.fullname'} = $fullname;
439: &submission($request,$ctr,$total);
440: $ctr++;
441: }
442: return '';
443: }
444:
445: #------------------------------------------------------------------------------------
446: #
447: #-------------------------- Next few routines handles grading by student, essentially
448: # handles essay response type problem/part
449: #
450: #--- Javascript to handle the submission page functionality ---
451: sub sub_page_js {
452: my $request = shift;
453: $request->print(<<SUBJAVASCRIPT);
454: <script type="text/javascript" language="javascript">
455: function updateRadio(radioButton,formtextbox,formsel,scores,weight) {
456: var pts = formtextbox.value;
457: var resetbox =false;
458: if (isNaN(pts) || pts < 0) {
459: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
460: for (var i=0; i<radioButton.length; i++) {
461: if (radioButton[i].checked) {
462: formtextbox.value = i;
463: resetbox = true;
464: }
465: }
466: if (!resetbox) {
467: formtextbox.value = "";
468: }
469: return;
470: }
471:
472: if (pts > weight) {
473: var resp = confirm("You entered a value ("+pts+
474: ") greater than the weight for the part. Accept?");
475: if (resp == false) {
476: formtextbox.value = "";
477: return;
478: }
479: }
480:
481: for (var i=0; i<radioButton.length; i++) {
482: radioButton[i].checked=false;
483: if (pts == i) {
484: radioButton[i].checked=true;
485: }
486: }
487: updateSelect(formsel);
488: scores.value = "0";
489: }
490:
491: function writeBox(formrad,formsel,pts,scores) {
492: formrad.value = pts;
493: scores.value = "0";
494: updateSelect(formsel,pts);
495: return;
496: }
497:
498: function clearRadBox(radioButton,formbox,formsel,scores) {
499: for (var i=0; i<formsel.length; i++) {
500: if (formsel[i].selected) {
501: var selectx=i;
502: }
503: }
504: if (selectx == scores.value) { return };
505: formbox.value = "";
506: for (var i=0; i<radioButton.length; i++) {
507: radioButton[i].checked=false;
508: }
509: scores.value = selectx;
510: }
511:
512: function updateSelect(formsel) {
513: formsel[0].selected = true;
514: return;
515: }
516:
517: //=================== Check that a point is assigned for all the parts ==============
518: function checksubmit(val,total,parttot) {
519: document.SCORE.gradeOpt.value = val;
520: if (val == "Save & Next") {
521: for (i=0;i<=total;i++) {
522: for (j=0;j<parttot;j++) {
523: var partid = eval("document.SCORE.partid"+i+"_"+j+".value");
524: var selopt = eval("document.SCORE.GD_SEL"+i+"_"+partid);
525: if (selopt[0].selected) {
526: var points = eval("document.SCORE.GD_BOX"+i+"_"+partid+".value");
527: if (points == "") {
528: var name = eval("document.SCORE.name"+i+".value");
529: alert("Please assign a score for "+name+", part "+partid+".");
530: return false;
531: }
532: }
533:
534: }
535: }
536:
537: }
538: document.SCORE.submit();
539: }
540:
541: //===================== Show list of keywords ====================
542: function keywords(keyform) {
543: var keywds = keyform.value;
544: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
545: if (nret==null) return;
546: keyform.value = nret;
547:
548: document.SCORE.refresh.value = "on";
549: if (document.SCORE.keywords.value != "") {
550: document.SCORE.submit();
551: }
552: return;
553: }
554:
555: //===================== Script to view submitted by ==================
556: function viewSubmitter(submitter) {
557: document.SCORE.refresh.value = "on";
558: document.SCORE.NCT.value = "1";
559: document.SCORE.unamedom0.value = submitter;
560: document.SCORE.submit();
561: return;
562: }
563:
564: //===================== Script to add keyword(s) ==================
565: function getSel() {
566: if (document.getSelection) txt = document.getSelection();
567: else if (document.selection) txt = document.selection.createRange().text;
568: else return;
569: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
570: if (cleantxt=="") {
571: alert("Please select a word or group of words from document and then click this link.");
572: return;
573: }
574: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
575: if (nret==null) return;
576: var curlist = document.SCORE.keywords.value;
577: document.SCORE.keywords.value = curlist+" "+nret;
578: document.SCORE.refresh.value = "on";
579: if (document.SCORE.keywords.value != "") {
580: document.SCORE.submit();
581: }
582: return;
583: }
584:
585: //====================== Script for composing message ==============
586: function msgCenter(msgform,usrctr,fullname) {
587: var Nmsg = msgform.savemsgN.value;
588: savedMsgHeader(Nmsg,usrctr,fullname);
589: var subject = msgform.msgsub.value;
590: var rtrchk = eval("document.SCORE.includemsg"+usrctr);
591: var msgchk = rtrchk.value;
592: re = /msgsub/;
593: var shwsel = "";
594: if (re.test(msgchk)) { shwsel = "checked" }
595: displaySubject(subject,shwsel);
596: for (var i=1; i<=Nmsg; i++) {
597: var testpt = "savemsg"+i+",";
598: re = /testpt/;
599: shwsel = "";
600: if (re.test(msgchk)) { shwsel = "checked" }
601: var message = eval("document.SCORE.savemsg"+i+".value");
602: displaySavedMsg(i,message,shwsel);
603: }
604: newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
605: shwsel = "";
606: re = /newmsg/;
607: if (re.test(msgchk)) { shwsel = "checked" }
608: newMsg(newmsg,shwsel);
609: msgTail();
610: return;
611: }
612:
613: function savedMsgHeader(Nmsg,usrctr,fullname) {
614: var height = 30*Nmsg+250;
615: var scrollbar = "no";
616: if (height > 600) {
617: height = 600;
618: scrollbar = "yes";
619: }
620: /* if (window.pWin)
621: window.pWin.close(); */
622: pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
623: pWin.document.write("<html><head>");
624: pWin.document.write("<title>Message Central</title>");
625:
626: pWin.document.write("<script language=javascript>");
627: pWin.document.write("function checkInput() {");
628: pWin.document.write(" opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
629: pWin.document.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
630: pWin.document.write(" var usrctr = document.msgcenter.usrctr.value;");
631: pWin.document.write(" var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
632: pWin.document.write(" newval.value = document.msgcenter.newmsg.value;");
633:
634: pWin.document.write(" var msgchk = \\"\\";");
635: pWin.document.write(" if (document.msgcenter.subchk.checked) {");
636: pWin.document.write(" msgchk = \\"msgsub,\\";");
637: pWin.document.write(" }");
638: pWin.document.write( "for (var i=1; i<=nmsg; i++) {");
639: pWin.document.write(" var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
640: pWin.document.write(" var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
641: pWin.document.write(" opnmsg.value = frmmsg.value;");
642: pWin.document.write(" var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
643: pWin.document.write(" if (chkbox.checked) {");
644: pWin.document.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
645: pWin.document.write(" }");
646: pWin.document.write(" }");
647: pWin.document.write(" if (document.msgcenter.newmsgchk.checked) {");
648: pWin.document.write(" msgchk += \\"newmsg\\"+usrctr;");
649: pWin.document.write(" }");
650: pWin.document.write(" var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
651: pWin.document.write(" includemsg.value = msgchk;");
652:
653: pWin.document.write(" self.close()");
654:
655: pWin.document.write("}");
656:
657: pWin.document.write("<");
658: pWin.document.write("/script>");
659:
660: pWin.document.write("</head><body bgcolor=white>");
661:
662: pWin.document.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
663: pWin.document.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
664: pWin.document.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br><br>");
665:
666: pWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
667: pWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
668: pWin.document.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
669: }
670: function displaySubject(msg,shwsel) {
671: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
672: pWin.document.write("<td>Subject</td>");
673: pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
674: pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+" \\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
675: }
676:
677: function displaySavedMsg(ctr,msg,shwsel) {
678: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
679: pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
680: pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
681: pWin.document.write("<td><input name=\\"msg"+ctr+"\\" type=\\"text\\" value=\\""+msg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
682: }
683:
684: function newMsg(newmsg,shwsel) {
685: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
686: pWin.document.write("<td align=\\"center\\">New</td>");
687: pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
688: pWin.document.write("<td><input name=\\"newmsg\\" type=\\"text\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" value=\\""+newmsg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
689: }
690:
691: function msgTail() {
692: pWin.document.write("</table>");
693: pWin.document.write("</td></tr></table> ");
694: pWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
695: pWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
696: pWin.document.write("</form>");
697: pWin.document.write("</body></html>");
698: }
699:
700: //====================== Script for keyword highlight options ==============
701: function kwhighlight() {
702: var kwclr = document.SCORE.kwclr.value;
703: var kwsize = document.SCORE.kwsize.value;
704: var kwstyle = document.SCORE.kwstyle.value;
705: var redsel = "";
706: var grnsel = "";
707: var blusel = "";
708: if (kwclr=="red") {var redsel="checked"};
709: if (kwclr=="green") {var grnsel="checked"};
710: if (kwclr=="blue") {var blusel="checked"};
711: var sznsel = "";
712: var sz1sel = "";
713: var sz2sel = "";
714: if (kwsize=="0") {var sznsel="checked"};
715: if (kwsize=="+1") {var sz1sel="checked"};
716: if (kwsize=="+2") {var sz2sel="checked"};
717: var synsel = "";
718: var syisel = "";
719: var sybsel = "";
720: if (kwstyle=="") {var synsel="checked"};
721: if (kwstyle=="<i>") {var syisel="checked"};
722: if (kwstyle=="<b>") {var sybsel="checked"};
723: highlightCentral();
724: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
725: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
726: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
727: highlightend();
728: return;
729: }
730:
731:
732: function highlightCentral() {
733: hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
734: hwdWin.document.write("<html><head>");
735: hwdWin.document.write("<title>Highlight Central</title>");
736:
737: hwdWin.document.write("<script language=javascript>");
738: hwdWin.document.write("function updateChoice(flag) {");
739: hwdWin.document.write(" opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
740: hwdWin.document.write(" opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
741: hwdWin.document.write(" opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
742: hwdWin.document.write(" opener.document.SCORE.refresh.value = \\"on\\";");
743: hwdWin.document.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){");
744: hwdWin.document.write(" opener.document.SCORE.submit();");
745: hwdWin.document.write(" }");
746: hwdWin.document.write(" self.close()");
747: hwdWin.document.write("}");
748:
749: hwdWin.document.write("function radioSelection(radioButton) {");
750: hwdWin.document.write(" var selection=null;");
751: hwdWin.document.write(" for (var i=0; i<radioButton.length; i++) {");
752: hwdWin.document.write(" if (radioButton[i].checked) {");
753: hwdWin.document.write(" selection=radioButton[i].value;");
754: hwdWin.document.write(" return selection;");
755: hwdWin.document.write(" }");
756: hwdWin.document.write(" }");
757: hwdWin.document.write("}");
758:
759: hwdWin.document.write("<");
760: hwdWin.document.write("/script>");
761:
762: hwdWin.document.write("</head><body bgcolor=white>");
763:
764: hwdWin.document.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
765: hwdWin.document.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br><br>");
766:
767: hwdWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
768: hwdWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
769: hwdWin.document.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
770: }
771:
772: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
773: hwdWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
774: hwdWin.document.write("<td align=\\"left\\">");
775: hwdWin.document.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
776: hwdWin.document.write("<td align=\\"left\\">");
777: hwdWin.document.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
778: hwdWin.document.write("<td align=\\"left\\">");
779: hwdWin.document.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
780: hwdWin.document.write("</tr>");
781: }
782:
783: function highlightend() {
784: hwdWin.document.write("</table>");
785: hwdWin.document.write("</td></tr></table> ");
786: // hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(0)\\"> ");
787: hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
788: hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
789: hwdWin.document.write("</form>");
790: hwdWin.document.write("</body></html>");
791: }
792:
793: </script>
794: SUBJAVASCRIPT
795: }
796:
797:
798: # --------------------------- show submissions of a student, option to grade
799: sub submission {
800: my ($request,$counter,$total) = @_;
801:
802: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
803: # if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
804: my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
805: ($uname,$udom) = &finduser($uname) if $udom eq '';
806: $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
807: # if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
808:
809: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
810: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
811: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
812: $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes';
813:
814: # header info
815: if ($counter == 0) {
816: &sub_page_js($request);
817: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
818: '<font size=+1> <b>Resource: </b>'.$url.'</font>'."\n");
819:
820: # option to display problem, only once else it cause problems
821: # with the form later since the problem has a form.
822: if ($ENV{'form.vProb'} eq 'yes') {
823: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
824: $ENV{'request.course.id'});
825: my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
826: $ENV{'request.course.id'});
827: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
828: $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
829: $result.='<b> View of the problem - '.$ENV{'form.fullname'}.
830: '</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
831: $result.='<b>Correct answer:</b><br />'.$companswer;
832: $result.='</td></tr></table>';
833: $result.='</td></tr></table><br />';
834: $request->print($result);
835: }
836:
837: # kwclr is the only variable that is guaranteed to be non blank
838: # if this subroutine has been called once.
839: my %keyhash = ();
840: if ($ENV{'form.kwclr'} eq '') {
841: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
842: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
843: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
844:
845: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
846: $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
847: $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
848: $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
849: $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
850: $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
851: $keyhash{$symb.'_subject'} : &Apache::lonnet::metadata($url,'title');
852: $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
853:
854: }
855:
856: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
857: '<input type="hidden" name="command" value="handgrade" />'."\n".
858: '<input type="hidden" name="refresh" value="off" />'."\n".
859: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
860: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
861: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
862: '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
863: '<input type="hidden" name="lastSub" value="'.$ENV{'form.lastSub'}.'" />'."\n".
864: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
865: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
866: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'">'."\n".
867: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'">'."\n".
868: '<input type="hidden" name="keywords" value="'.$ENV{'form.keywords'}.'" />'."\n".
869: '<input type="hidden" name="kwclr" value="'.$ENV{'form.kwclr'}.'" />'."\n".
870: '<input type="hidden" name="kwsize" value="'.$ENV{'form.kwsize'}.'" />'."\n".
871: '<input type="hidden" name="kwstyle" value="'.$ENV{'form.kwstyle'}.'" />'."\n".
872: '<input type="hidden" name="msgsub" value="'.$ENV{'form.msgsub'}.'" />'."\n".
873: '<input type="hidden" name="savemsgN" value="'.$ENV{'form.savemsgN'}.'" />'."\n".
874: '<input type="hidden" name="NCT"'.
875: ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
876:
877: my ($cts,$prnmsg) = (1,'');
878: while ($cts <= $ENV{'form.savemsgN'}) {
879: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
880: ($keyhash{$symb.'_savemsg'.$cts} eq '' ? $ENV{'form.savemsg'.$cts} : $keyhash{$symb.'_savemsg'.$cts}).
881: '" />'."\n";
882: $cts++;
883: }
884: $request->print($prnmsg);
885:
886: if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
887: $request->print(<<KEYWORDS);
888: <b>Keyword Options:</b>
889: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>
890: <a href="#" onMouseDown="javascript:getSel(); return false"
891: CLASS="page">Paste Selection to List</a>
892: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
893: KEYWORDS
894: }
895: }
896:
897: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
898: my ($partlist,$handgrade) = &response_type($url);
899:
900: # Display student info
901: $request->print(($counter == 0 ? '' : '<br />'));
902: my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
903: '<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
904:
905: $result.='<b>Fullname: </b>'.$ENV{'form.fullname'}.
906: '<font color="#999999"> Username: '.$uname.'</font>'.
907: '<font color="#999999"> Domain: '.$udom.'</font><br />'."\n";
908: $result.='<input type="hidden" name="name'.$counter.
909: '" value="'.$ENV{'form.fullname'}.'" />'."\n";
910:
911: # If this is handgraded, then check for collaborators
912: my @col_fullnames;
913: my ($classlist,$fullname);
914: if ($ENV{'form.handgrade'} eq 'yes') {
915: my @col_list;
916: ($classlist,undef,$fullname) = &getclasslist('all','0');
917: for (keys (%$handgrade)) {
918: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
919: '.maxcollaborators',
920: $symb,$udom,$uname);
921: next if ($ncol <= 0);
922: s/\_/\./g;
923: next if ($record{'resource.'.$_.'.collaborators'} eq '');
924: my (@collaborators) = split(/,?\s+/,
925: $record{'resource.'.$_.'.collaborators'});
926: my (@badcollaborators);
927: if (scalar(@collaborators) != 0) {
928: $result.='<b>Collaborators: </b>';
929: foreach my $collaborator (@collaborators) {
930: my ($co_name,$co_dom) = split /\@|:/,$collaborator;
931: $co_dom = $udom if (! defined($co_dom));
932: next if ($co_name eq $uname && $co_dom eq $udom);
933: # Doing this grep allows 'fuzzy' specification
934: my @Matches = grep /^$co_name:$co_dom/i,
935: keys %$classlist;
936: if (! scalar(@Matches)) {
937: push @badcollaborators,$collaborator;
938: next;
939: }
940: push @col_list, @Matches;
941: foreach (@Matches) {
942: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
943: push @col_fullnames, $givenn.' '.$lastname;
944: $result.=$$fullname{$_}.' ';
945: }
946: }
947: $result.='<br />'."\n";
948: if (scalar(@badcollaborators) > 0) {
949: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
950: $result.='This student has submitted ';
951: if (scalar(@badcollaborators) == 1) {
952: $result .= 'an invalid collaborator';
953: } else {
954: $result .= 'invalid collaborators';
955: }
956: $result .= ': '.join(', ',@badcollaborators);
957:
958: }
959: if (scalar(@collaborators > $ncol)) {
960: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
961: $result .= 'This student has sumbitted too many '.
962: 'collaborators. Maximum is '.$ncol;
963: $result .= '</td></tr></table>';
964: }
965: $result.='<input type="hidden" name="collaborator'.$counter.
966: '" value="'.(join ':',@col_list).'" />'."\n";
967: }
968: }
969: }
970: $request->print($result."\n");
971:
972: # print student answer/submission
973: # Options are (1) Handgaded submission only
974: # (2) Last submission, includes submission that is not handgraded
975: # (for multi-response type part)
976: # (3) Last submission plus the parts info
977: # (4) The whole record for this student
978: if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
979: if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
980: my $submitby=''.
981: '<b>Collaborative submission by: </b>'.
982: '<a href="javascript:viewSubmitter(\''.
983: $ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
984: '\')"; TARGET=_self>'.
985: $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
986: $request->print($submitby);
987: } else {
988: my ($string,$timestamp)=
989: &get_last_submission (%record);
990: my $lastsubonly.=''.
991: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
992: $$timestamp).'';
993: if ($$timestamp eq '') {
994: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0].'</td></tr>'."\n";
995: } else {
996: for my $part (sort keys(%$handgrade)) {
997: foreach (@$string) {
998: my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
999: if ($part eq ($partid.'_'.$respid)) {
1000: my ($ressub,$subval) = split(/:/,$_,2);
1001: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
1002: $partid.'</b> <font color="#999999">( ID '.$respid.
1003: ' )</font> <b>Answer: </b>'.
1004: &keywords_highlight($subval).'</td></tr>'."\n"
1005: if ($ENV{'form.lastSub'} eq 'lastonly' ||
1006: ($ENV{'form.lastSub'} eq 'hdgrade' &&
1007: $$handgrade{$part} =~ /:yes$/));
1008: }
1009: }
1010: }
1011: }
1012: $lastsubonly.='</td></tr>'."\n";
1013: $request->print($lastsubonly);
1014: }
1015: } else {
1016: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1017: $ENV{'request.course.id'},
1018: $last,'.submission',
1019: 'Apache::grades::keywords_highlight'));
1020: }
1021:
1022: # return if view submission with no grading option
1023: if ($ENV{'form.showgrading'} eq '') {
1024: $request->print('</td></tr></table></td></tr></table></form>'."\n");
1025: return;
1026: }
1027:
1028: # Grading options
1029: $result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
1030: '<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1031: '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1032: .$udom.'" />'."\n";
1033: my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
1034: my $msgfor = $givenn.' '.$lastname;
1035: if (scalar(@col_fullnames) > 0) {
1036: my $lastone = pop @col_fullnames;
1037: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1038: }
1039: $result.='<tr><td bgcolor="#ffffff">'."\n".
1040: ' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1041: ',\''.$msgfor.'\')"; TARGET=_self>'.
1042: 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').'</a>'.
1043: '<br /> (Message will be sent when you click on Save & Next below.)'."\n"
1044: if ($ENV{'form.handgrade'} eq 'yes');
1045: $request->print($result);
1046:
1047: my %seen = ();
1048: my @partlist;
1049: for (sort keys(%$handgrade)) {
1050: my ($partid,$respid) = split(/_/);
1051: next if ($seen{$partid} > 0);
1052: $seen{$partid}++;
1053: next if ($$handgrade{$_} =~ /:no$/);
1054: push @partlist,$partid;
1055: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1056: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
1057: '<font color="red">problem weight assigned by computer</font>');
1058: $wgt = ($wgt > 0 ? $wgt : '1');
1059: my $score = ($record{'resource.'.$partid.'.awarded'} eq '' ?
1060: '' : $record{'resource.'.$partid.'.awarded'}*$wgt);
1061: $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
1062: $result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points: </b></td><td>';
1063:
1064: my $ctr = 0;
1065: $result.='<table border="0"><tr>'; # display radio buttons in a nice table 10 across
1066: while ($ctr<=$wgt) {
1067: $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1068: 'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
1069: ',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
1070: ',this.form.stores'.$counter.'_'.$partid.')" '.
1071: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
1072: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1073: $ctr++;
1074: }
1075: $result.='</tr></table>';
1076:
1077: $result.='</td><td> <b>or</b> </td>';
1078: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1079: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1080: 'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
1081: ',this.form.GD_BOX'.$counter.'_'.$partid.
1082: ',this.form.GD_SEL'.$counter.'_'.$partid.
1083: ',this.form.stores'.$counter.'_'.$partid.
1084: ','.$wgt.')" /></td>'."\n";
1085: $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
1086:
1087: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1088: 'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
1089: ',this.form.GD_BOX'.$counter.'_'.$partid.
1090: ',this.form.GD_SEL'.$counter.'_'.$partid.
1091: ',this.form.stores'.$counter.'_'.$partid.')" />'."\n".
1092: '<option selected="on"> </option>'.
1093: '<option>excused</option></select>'."  \n";
1094: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
1095: $result.='</td></tr></table>'."\n";
1096: $request->print($result);
1097: }
1098: $result='<input type="hidden" name="partlist'.$counter.
1099: '" value="'.(join ":",@partlist).'" />'."\n";
1100: my $ctr = 0;
1101: while ($ctr < scalar(@partlist)) {
1102: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1103: $partlist[$ctr].'" />'."\n";
1104: $ctr++;
1105: }
1106: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1107:
1108: # print end of form
1109: if ($counter == $total) {
1110: my $endform='<table border="0"><tr><td>'.
1111: '<input type="hidden" name="gradeOpt" value="" />'."\n";
1112: if ($ENV{'form.handgrade'} eq 'yes') {
1113: $endform.='<input type="button" value="Save & Next" '.
1114: 'onClick="javascript:checksubmit(\'Save & Next\','.
1115: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
1116: my $ntstu ='<select name="NTSTU">'.
1117: '<option>1</option><option>2</option>'.
1118: '<option>3</option><option>5</option>'.
1119: '<option>7</option><option>10</option></select>'."\n";
1120: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
1121: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
1122: $endform.=$ntstu.'student(s) ';
1123: } else {
1124: $endform.='<input type="hidden" name="NTSTU" value="1" />'."\n";
1125: }
1126: $endform.='<input type="button" value="Next" '.
1127: 'onClick="javascript:checksubmit(\'Next\');" TARGET=_self> '."\n".
1128: '<input type="button" value="Previous" '.
1129: 'onClick="javascript:checksubmit(\'Previous\');" TARGET=_self> ';
1130: $endform.='(Next and Previous do not save the scores.)'."\n"
1131: if ($ENV{'form.handgrade'} eq 'yes');
1132: $endform.='</td><tr></table></form>';
1133: $endform.=&show_grading_menu_form($symb,$url);
1134: $request->print($endform);
1135: }
1136: return '';
1137: }
1138:
1139: #--- Retrieve the last submission for all the parts
1140: sub get_last_submission {
1141: my (%returnhash)=@_;
1142: my (@string,$timestamp);
1143: if ($returnhash{'version'}) {
1144: my %lasthash=();
1145: my ($version);
1146: for ($version=1;$version<=$returnhash{'version'};$version++) {
1147: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
1148: $lasthash{$_}=$returnhash{$version.':'.$_};
1149: if ($returnhash{$version.':'.$_} =~ /(SUBMITTED|DRAFT)$/) {
1150: $timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
1151: }
1152: }
1153: }
1154: foreach ((keys %lasthash)) {
1155: if ($_ =~ /\.submission$/) {
1156: my ($partid,$foo) = split(/submission$/,$_);
1157: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1158: '<font color="red">Draft Copy</font> ' : '';
1159: push @string, (join(':',$_,$draft.$lasthash{$_}));
1160: }
1161: }
1162: }
1163: @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
1164: return \@string,\$timestamp;
1165: }
1166:
1167: #--- High light keywords, with style choosen by user.
1168: sub keywords_highlight {
1169: my $string = shift;
1170: my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
1171: my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
1172: (my $styleoff = $styleon) =~ s/\</\<\//;
1173: my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
1174: foreach (@keylist) {
1175: $string =~ s/\b$_(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
1176: }
1177: # This is not really the right place to do this, but I cannot find a
1178: # better one at this time. So here we go - the m in the s:::mg causes
1179: # ^ to match the beginning of a new line. So we replace(???) the beginning
1180: # of the line with <br /> to make things formatted a little better.
1181: $string =~ s:^:<br />:mg;
1182: return $string;
1183: }
1184:
1185: #--- Called from submission routine
1186: sub processHandGrade {
1187: my ($request) = shift;
1188: my $url = $ENV{'form.url'};
1189: my $symb = $ENV{'form.symb'};
1190: my $button = $ENV{'form.gradeOpt'};
1191: my $ngrade = $ENV{'form.NCT'};
1192: my $ntstu = $ENV{'form.NTSTU'};
1193:
1194: if ($button eq 'Save & Next') {
1195: my $ctr = 0;
1196: while ($ctr < $ngrade) {
1197: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1198: my ($errorflag) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1199:
1200: my $includemsg = $ENV{'form.includemsg'.$ctr};
1201: my ($subject,$message,$msgstatus) = ('','','');
1202: if ($includemsg =~ /savemsg|new$ctr/) {
1203: $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
1204: my (@msgnum) = split(/,/,$includemsg);
1205: foreach (@msgnum) {
1206: $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1207: }
1208: $message =~ s/\s+/ /g;
1209: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
1210: $ENV{'form.msgsub'},$message);
1211: }
1212: if ($ENV{'form.collaborator'.$ctr}) {
1213: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
1214: foreach (@collaborators) {
1215: &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
1216: $ENV{'form.unamedom'.$ctr});
1217: if ($message ne '') {
1218: $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
1219: $ENV{'form.msgsub'},
1220: $message);
1221: }
1222: }
1223: }
1224: $ctr++;
1225: }
1226: }
1227:
1228: # Keywords sorted in alphabatical order
1229: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1230: my %keyhash = ();
1231: $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1232: $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
1233: my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
1234: $ENV{'form.keywords'} = join(' ',@keywords);
1235: $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
1236: $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
1237: $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
1238: $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
1239: $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
1240:
1241: # message center - Order of message gets changed. Blank line is eliminated.
1242: # New messages are saved in ENV for the next student.
1243: # All messages are saved in nohist_handgrade.db
1244: my ($ctr,$idx) = (1,1);
1245: while ($ctr <= $ENV{'form.savemsgN'}) {
1246: if ($ENV{'form.savemsg'.$ctr} ne '') {
1247: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
1248: $idx++;
1249: }
1250: $ctr++;
1251: }
1252: $ctr = 0;
1253: while ($ctr < $ngrade) {
1254: if ($ENV{'form.newmsg'.$ctr} ne '') {
1255: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1256: $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1257: $idx++;
1258: }
1259: $ctr++;
1260: }
1261: $ENV{'form.savemsgN'} = --$idx;
1262: $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
1263: my $putresult = &Apache::lonnet::put
1264: ('nohist_handgrade',\%keyhash,
1265: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1266: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1267:
1268: # Called by Save & Refresh from Highlight Attribute Window
1269: if ($ENV{'form.refresh'} eq 'on') {
1270: my $ctr = 0;
1271: $ENV{'form.NTSTU'}=$ngrade;
1272: while ($ctr < $ngrade) {
1273: ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$ENV{'form.unamedom'.$ctr});
1274: &submission($request,$ctr,$ngrade-1);
1275: $ctr++;
1276: }
1277: return '';
1278: }
1279:
1280: # Get the next/previous one or group of students
1281: my $firststu = $ENV{'form.unamedom0'};
1282: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
1283: $ctr = 2;
1284: while ($laststu eq '') {
1285: $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
1286: $ctr++;
1287: $laststu = $firststu if ($ctr > $ngrade);
1288: }
1289:
1290: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1291: my (@parsedlist,@nextlist);
1292: my ($nextflg) = 0;
1293: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1294: if ($nextflg == 1 && $button =~ /Next$/) {
1295: push @parsedlist,$_;
1296: }
1297: $nextflg = 1 if ($_ eq $laststu);
1298: if ($button eq 'Previous') {
1299: last if ($_ eq $firststu);
1300: push @parsedlist,$_;
1301: }
1302: }
1303: $ctr = 0;
1304: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1305: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1306: foreach my $student (@parsedlist) {
1307: my ($uname,$udom) = split(/:/,$student);
1308: if ($ENV{'form.submitonly'} eq 'yes') {
1309: my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
1310: my $statusflg = '';
1311: foreach (keys(%status)) {
1312: $statusflg = 1 if ($status{$_} ne 'nothing');
1313: my ($foo,$partid,$foo1) = split(/\./);
1314: $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
1315: }
1316: next if ($statusflg eq '');
1317: }
1318: push @nextlist,$student if ($ctr < $ntstu);
1319: $ctr++;
1320: }
1321:
1322: $ctr = 0;
1323: my $total = scalar(@nextlist)-1;
1324:
1325: foreach (sort @nextlist) {
1326: my ($uname,$udom,$submitter) = split(/:/);
1327: $ENV{'form.student'} = $uname;
1328: $ENV{'form.userdom'} = $udom;
1329: $ENV{'form.fullname'} = $$fullname{$_};
1330: # $ENV{'form.'.$_.':submitted_by'} = $submitter;
1331: # print "submitter=$ENV{'form.'.$_.':submitted_by'}= $submitter:<br>";
1332: &submission($request,$ctr,$total);
1333: $ctr++;
1334: }
1335: if ($total < 0) {
1336: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
1337: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
1338: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1339: $the_end.=&show_grading_menu_form ($symb,$url);
1340: $request->print($the_end);
1341: }
1342: return '';
1343: }
1344:
1345: #---- Save the score and award for each student, if changed
1346: sub saveHandGrade {
1347: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
1348: my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
1349: my %newrecord;
1350: foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1351: if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
1352: $newrecord{'resource.'.$_.'.solved'} = 'excused'
1353: if ($record{'resource.'.$_.'.solved'} ne 'excused');
1354: } else {
1355: my $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
1356: $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
1357: $ENV{'form.RADVAL'.$newflg.'_'.$_});
1358: my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
1359: $ENV{'form.WGT'.$newflg.'_'.$_};
1360: my $partial= $pts/$wgt;
1361: $newrecord{'resource.'.$_.'.awarded'} = $partial
1362: if ($record{'resource.'.$_.'.awarded'} ne $partial);
1363: my $reckey = 'resource.'.$_.'.solved';
1364: if ($partial == 0) {
1365: $newrecord{$reckey} = 'incorrect_by_override'
1366: if ($record{$reckey} ne 'incorrect_by_override');
1367: } else {
1368: $newrecord{$reckey} = 'correct_by_override'
1369: if ($record{$reckey} ne 'correct_by_override');
1370: }
1371: $newrecord{'resource.'.$_.'.submitted_by'} = $submitter
1372: if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
1373: }
1374: }
1375:
1376: if (scalar(keys(%newrecord)) > 0) {
1377: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1378: &Apache::lonnet::cstore(\%newrecord,$symb,
1379: $ENV{'request.course.id'},$domain,$stuname);
1380: }
1381: return '';
1382: }
1383:
1384: #--------------------------------------------------------------------------------------
1385: #
1386: #-------------------------- Next few routines handles grading by section or whole class
1387: #
1388: #--- Javascript to handle grading by section or whole class
1389: sub viewgrades_js {
1390: my ($request) = shift;
1391:
1392: $request->print(<<VIEWJAVASCRIPT);
1393: <script type="text/javascript" language="javascript">
1394: function writePoint(partid,weight,point) {
1395: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1396: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1397: if (point == "textval") {
1398: var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
1399: if (isNaN(point) || point < 0) {
1400: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1401: var resetbox = false;
1402: for (var i=0; i<radioButton.length; i++) {
1403: if (radioButton[i].checked) {
1404: textbox.value = i;
1405: resetbox = true;
1406: }
1407: }
1408: if (!resetbox) {
1409: textbox.value = "";
1410: }
1411: return;
1412: }
1413: if (point > weight) {
1414: var resp = confirm("You entered a value ("+point+
1415: ") greater than the weight for the part. Accept?");
1416: if (resp == false) {
1417: textbox.value = "";
1418: return;
1419: }
1420: }
1421: for (var i=0; i<radioButton.length; i++) {
1422: radioButton[i].checked=false;
1423: if (point == i) {
1424: radioButton[i].checked=true;
1425: }
1426: }
1427:
1428: } else {
1429: textbox.value = point;
1430: }
1431: for (i=0;i<document.classgrade.total.value;i++) {
1432: var user = eval("document.classgrade.ctr"+i+".value");
1433: var scorename = eval("document.classgrade.GD_"+user+
1434: "_"+partid+"_awarded");
1435: var saveval = eval("document.classgrade.GD_"+user+
1436: "_"+partid+"_solved_s.value");
1437: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1438: if (saveval != "correct") {
1439: scorename.value = point;
1440: if (selname[0].selected != true) {
1441: selname[0].selected = true;
1442: }
1443: }
1444: }
1445: var selval = eval("document.classgrade.SELVAL_"+partid);
1446: selval[0].selected = true;
1447: }
1448:
1449: function writeRadText(partid,weight) {
1450: var selval = eval("document.classgrade.SELVAL_"+partid);
1451: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1452: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1453: if (selval[1].selected) {
1454: for (var i=0; i<radioButton.length; i++) {
1455: radioButton[i].checked=false;
1456:
1457: }
1458: textbox.value = "";
1459:
1460: for (i=0;i<document.classgrade.total.value;i++) {
1461: var user = eval("document.classgrade.ctr"+i+".value");
1462: var scorename = eval("document.classgrade.GD_"+user+
1463: "_"+partid+"_awarded");
1464: var saveval = eval("document.classgrade.GD_"+user+
1465: "_"+partid+"_solved_s.value");
1466: var selname = eval("document.classgrade.GD_"+user+
1467: "_"+partid+"_solved");
1468: if (saveval != "correct") {
1469: scorename.value = "";
1470: selname[1].selected = true;
1471: }
1472: }
1473: } else {
1474: for (i=0;i<document.classgrade.total.value;i++) {
1475: var user = eval("document.classgrade.ctr"+i+".value");
1476: var scorename = eval("document.classgrade.GD_"+user+
1477: "_"+partid+"_awarded");
1478: var saveval = eval("document.classgrade.GD_"+user+
1479: "_"+partid+"_solved_s.value");
1480: var selname = eval("document.classgrade.GD_"+user+
1481: "_"+partid+"_solved");
1482: if (saveval != "correct") {
1483: scorename.value = eval("document.classgrade.GD_"+user+
1484: "_"+partid+"_awarded_s.value");;
1485: selname[0].selected = true;
1486: }
1487: }
1488: }
1489: }
1490:
1491: function changeSelect(partid,user) {
1492: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1493: var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1494: var point = textbox.value;
1495: var weight = eval("document.classgrade.weight_"+partid+".value");
1496:
1497: if (isNaN(point) || point < 0) {
1498: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1499: textbox.value = "";
1500: return;
1501: }
1502: if (point > weight) {
1503: var resp = confirm("You entered a value ("+point+
1504: ") greater than the weight of the part. Accept?");
1505: if (resp == false) {
1506: textbox.value = "";
1507: return;
1508: }
1509: }
1510: selval[0].selected = true;
1511: }
1512:
1513: function changeOneScore(partid,user) {
1514: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1515: if (selval[1].selected) {
1516: var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1517: boxval.value = "";
1518: }
1519: }
1520:
1521: function resetEntry(numpart) {
1522: for (ctpart=0;ctpart<numpart;ctpart++) {
1523: var partid = eval("document.classgrade.partid_"+ctpart+".value");
1524: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1525: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1526: var selval = eval("document.classgrade.SELVAL_"+partid);
1527: for (var i=0; i<radioButton.length; i++) {
1528: radioButton[i].checked=false;
1529:
1530: }
1531: textbox.value = "";
1532: selval[0].selected = true;
1533:
1534: for (i=0;i<document.classgrade.total.value;i++) {
1535: var user = eval("document.classgrade.ctr"+i+".value");
1536: var resetscore = eval("document.classgrade.GD_"+user+
1537: "_"+partid+"_awarded");
1538: resetscore.value = eval("document.classgrade.GD_"+user+
1539: "_"+partid+"_awarded_s.value");
1540:
1541: var saveselval = eval("document.classgrade.GD_"+user+
1542: "_"+partid+"_solved_s.value");
1543:
1544: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1545: if (saveselval == "excused") {
1546: if (selname[1].selected == false) { selname[1].selected = true;}
1547: } else {
1548: if (selname[0].selected == false) {selname[0].selected = true};
1549: }
1550: }
1551: }
1552: }
1553:
1554: </script>
1555: VIEWJAVASCRIPT
1556: }
1557:
1558: #--- show scores for a section or whole class w/ option to change/update a score
1559: sub viewgrades {
1560: my ($request) = shift;
1561: &viewgrades_js($request);
1562:
1563: my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
1564: my $result='<h3><font color="#339933">Manual Grading</font></h3>';
1565:
1566: $result.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font>'."\n";
1567:
1568: #view individual student submission form - called using Javascript viewOneStudent
1569: $result.=&jscriptNform($url,$symb);
1570:
1571: #beginning of class grading form
1572: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1573: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1574: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1575: '<input type="hidden" name="command" value="editgrades" />'."\n".
1576: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n";
1577: $result.='<h3>Assign Common Grade To ';
1578: if ($ENV{'form.section'} eq 'all') {
1579: $result.='Class </h3>';
1580: } elsif ($ENV{'form.section'} eq 'no') {
1581: $result.='Students in no Section </h3>';
1582: } else {
1583: $result.='Students in Section '.$ENV{'form.section'}.'</h3>';
1584: }
1585: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1586: '<table border=0><tr bgcolor="#ffffdd"><td>';
1587: # $result.='To assign the same score for all the students use the radio buttons or '.
1588: # 'text box below. To assign scores individually fill in the score boxes for '.
1589: # 'each student in the table below. <font color="red">A part that has already '.
1590: # 'been graded does not get changed using the radio buttons or text box. '.
1591: # 'If needed, it has to be changed individually.</font>';
1592: # $result.='</td></tr><tr><td>';
1593: #radio buttons/text box for assigning points for a section or class.
1594: #handles different parts of a problem
1595: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1596: my %weight = ();
1597: my $ctsparts = 0;
1598: $result.='<table border="0">';
1599: my %seen = ();
1600: for (sort keys(%$handgrade)) {
1601: my ($partid,$respid) = split (/_/,$_,2);
1602: next if $seen{$partid};
1603: $seen{$partid}++;
1604: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
1605: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
1606: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
1607:
1608: $result.='<input type="hidden" name="partid_'.
1609: $ctsparts.'" value="'.$partid.'" />'."\n";
1610: $result.='<input type="hidden" name="weight_'.
1611: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1612: $result.='<tr><td><b>Part '.$partid.' Point:</b> </td><td>';
1613: $result.='<table border="0"><tr>';
1614: my $ctr = 0;
1615: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1616: $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
1617: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1618: ','.$ctr.')" />'.$ctr."</td>\n";
1619: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1620: $ctr++;
1621: }
1622: $result.='</tr></table>';
1623: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1624: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
1625: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1626: $weight{$partid}.' (problem weight)</td>'."\n";
1627: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1628: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1629: $weight{$partid}.')" /> '.
1630: '<option selected="on"> </option>'.
1631: '<option>excused</option></select></td></tr>'."\n";
1632: $ctsparts++;
1633: }
1634: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
1635: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1636: $result.='<input type="button" value="Reset" '.
1637: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self> ';
1638: $result.='<input type="button" value="Submit Changes" '.
1639: 'onClick="javascript:submit();" TARGET=_self />'."\n";
1640:
1641: #table listing all the students in a section/class
1642: #header of table
1643: $result.= '<h3>Assign Grade to Specific Students in ';
1644: if ($ENV{'form.section'} eq 'all') {
1645: $result.='the Class </h3>';
1646: } elsif ($ENV{'form.section'} eq 'no') {
1647: $result.='no Section </h3>';
1648: } else {
1649: $result.='Section '.$ENV{'form.section'}.'</h3>';
1650: }
1651: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1652: '<table border=0><tr bgcolor="#deffff">'.
1653: '<td><b>Fullname</b></td><td><b>Username</b></td><td><b>Domain</b></td>'."\n";
1654: my (@parts) = sort(&getpartlist($url));
1655: foreach my $part (@parts) {
1656: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1657: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1658: if ($display =~ /^Partial Credit Factor/) {
1659: my ($partid) = &split_part_type($part);
1660: $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
1661: $weight{$partid}.')</b></td>'."\n";
1662: next;
1663: }
1664: $display =~ s|Problem Status|Grade Status<br />|;
1665: $result.='<td><b>'.$display.'</b></td>'."\n";
1666: }
1667: $result.='</tr>';
1668:
1669: #get info for each student
1670: #list all the students - with points and grade status
1671: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1672: my $ctr = 0;
1673: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1674: my ($uname,$udom) = split(/:/);
1675: $result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
1676: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
1677: $_,$$fullname{$_},\@parts,\%weight);
1678: $ctr++;
1679: }
1680: $result.='</table></td></tr></table>';
1681: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1682: $result.='<input type="button" value="Submit Changes" '.
1683: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1684: $result.=&show_grading_menu_form($symb,$url);
1685: return $result;
1686: }
1687:
1688: #--- call by previous routine to display each student
1689: sub viewstudentgrade {
1690: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
1691: my ($uname,$udom) = split(/:/,$student);
1692: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1693: my $result='<tr bgcolor="#ffffdd"><td>'.
1694: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1695: '\')"; TARGET=_self>'.$fullname.'</a>'.
1696: '</td><td>'.$uname.'</td><td align="middle">'.$udom.'</td>'."\n";
1697: foreach my $part (@$parts) {
1698: my ($part,$type) = &split_part_type($part);
1699: my $score=$record{"resource.$part.$type"};
1700: if ($type eq 'awarded') {
1701: my $pts = $score eq '' ? '' : $score*$$weight{$part};
1702: $result.='<input type="hidden" name="'.
1703: 'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1704: $result.='<td align="middle"><input type="text" name="'.
1705: 'GD_'.$uname.'_'.$part.'_awarded" '.
1706: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$uname.
1707: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1708: } elsif ($type eq 'solved') {
1709: my ($status,$foo)=split(/_/,$score,2);
1710: $status = 'nothing' if ($status eq '');
1711: $result.='<input type="hidden" name="'.'GD_'.$uname.'_'.
1712: $part.'_solved_s" value="'.$status.'" />'."\n";
1713: $result.='<td align="middle"><select name="'.
1714: 'GD_'.$uname.'_'.$part.'_solved" '.
1715: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$uname.'\')" >'."\n";
1716: my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
1717: $optsel = '<option> </option><option selected="on">excused</option>'."\n"
1718: if ($status eq 'excused');
1719: $result.=$optsel;
1720: $result.="</select></td>\n";
1721: } else {
1722: $result.='<input type="hidden" name="'.
1723: 'GD_'.$uname.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
1724: "\n";
1725: $result.='<td align="middle"><input type="text" name="'.
1726: 'GD_'.$uname.'_'.$part.'_'.$type.'" '.
1727: 'value="'.$score.'" size="4" /></td>'."\n";
1728: }
1729: }
1730: $result.='</tr>';
1731: return $result;
1732: }
1733:
1734: #--- change scores for all the students in a section/class
1735: # record does not get update if unchanged
1736: sub editgrades {
1737: my ($request) = @_;
1738:
1739: my $symb=$ENV{'form.symb'};
1740: my $url =$ENV{'form.url'};
1741: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1742: $title.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font><br />'."\n";
1743: $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
1744: $title.= &show_grading_menu_form ($symb,$url);
1745: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1746: $result.= '<table border="0"><tr bgcolor="#deffff">'.
1747: '<td rowspan=2><b>Username</b></td><td rowspan=2><b>Fullname</b></td>'."\n";
1748:
1749: my %scoreptr = (
1750: 'correct' =>'correct_by_override',
1751: 'incorrect'=>'incorrect_by_override',
1752: 'excused' =>'excused',
1753: 'ungraded' =>'ungraded_attempted',
1754: 'nothing' => '',
1755: );
1756: my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1757:
1758: my (@partid);
1759: my %weight = ();
1760: my %columns = ();
1761: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1762:
1763: my (@parts) = sort(&getpartlist($url));
1764: my $header;
1765: while ($ctr < $ENV{'form.totalparts'}) {
1766: my $partid = $ENV{'form.partid_'.$ctr};
1767: push @partid,$partid;
1768: $weight{$partid} = $ENV{'form.weight_'.$partid};
1769: $ctr++;
1770: }
1771: foreach my $partid (@partid) {
1772: $header .= '<td align="center"> <b>Old Score</b> </td>'.
1773: '<td align="center"> <b>New Score</b> </td>';
1774: $columns{$partid}=2;
1775: foreach my $stores (@parts) {
1776: my ($part,$type) = &split_part_type($stores);
1777: if ($part !~ m/^\Q$partid\E/) { next;}
1778: if ($type eq 'awarded' || $type eq 'solved') { next; }
1779: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1780: $display =~ s/\[Part: (\w)+\]//;
1781: $header .= '<td align="center"> <b>Old</b> '.$display.' </td>'.
1782: '<td align="center"> <b>New</b> '.$display.' </td>';
1783: $columns{$partid}+=2;
1784: }
1785: }
1786: foreach my $partid (@partid) {
1787: $result .= '<td colspan="'.$columns{$partid}.
1788: '" align="center"><b>Part '.$partid.
1789: '</b> (Weight = '.$weight{$partid}.')</td>';
1790:
1791: }
1792: $result .= '</tr><tr bgcolor="#deffff">';
1793: $result .= $header;
1794: $result .= '</tr>'."\n";
1795:
1796: for ($i=0; $i<$ENV{'form.total'}; $i++) {
1797: my $user = $ENV{'form.ctr'.$i};
1798: my %newrecord;
1799: my $updateflag = 0;
1800: my @userdom = grep /^$user:/,keys %$classlist;
1801: my (undef,$udom) = split(/:/,$userdom[0]);
1802:
1803: $result .= '<tr bgcolor="#ffffde"><td>'.$user.' </td><td>'.
1804: $$fullname{$userdom[0]}.' </td>';
1805: foreach (@partid) {
1806: my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1807: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
1808: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1809: my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1810:
1811: my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
1812: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
1813: my $partial = $awarded eq '' ? '' : $pcr;
1814: my $score;
1815: if ($partial eq '') {
1816: $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1817: } elsif ($partial > 0) {
1818: $score = 'correct_by_override';
1819: } elsif ($partial == 0) {
1820: $score = 'incorrect_by_override';
1821: }
1822: $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
1823: ($score ne 'excused'));
1824: $result .= '<td align="center">'.$old_aw.' </td>'.
1825: '<td align="center">'.$awarded.
1826: ($score eq 'excused' ? $score : '').' </td>';
1827:
1828: if (!($old_part eq $partial && $old_score eq $score)) {
1829: $updateflag = 1;
1830: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
1831: $newrecord{'resource.'.$_.'.solved'} = $score;
1832: $rec_update++;
1833: }
1834:
1835: my $partid=$_;
1836: foreach my $stores (@parts) {
1837: my ($part,$type) = &split_part_type($stores);
1838: if ($part !~ m/^\Q$partid\E/) { next;}
1839: if ($type eq 'awarded' || $type eq 'solved') { next; }
1840: my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
1841: my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
1842: if ($awarded ne '' && $awarded ne $old_aw) {
1843: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1844: $updateflag=1;
1845: }
1846: $result .= '<td align="center">'.$old_aw.' </td>'.
1847: '<td align="center">'.$awarded.' </td>';
1848: }
1849: }
1850: $result .= '</tr>'."\n";
1851: if ($updateflag) {
1852: $count++;
1853: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1854: &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
1855: $udom,$user);
1856: }
1857: }
1858: $result .= '</table></td></tr></table>'."\n";
1859: my $msg = '<b>Number of records updated = '.$rec_update.
1860: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1861: '<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
1862: return $title.$msg.$result;
1863: }
1864:
1865: sub split_part_type {
1866: my ($partstr) = @_;
1867: my ($temp,@allparts)=split(/_/,$partstr);
1868: my $type=pop(@allparts);
1869: my $part=join('.',@allparts);
1870: return ($part,$type);
1871: }
1872:
1873: #------------- end of section for handling grading by section/class ---------
1874: #
1875: #----------------------------------------------------------------------------
1876:
1877:
1878: #----------------------------------------------------------------------------
1879: #
1880: #-------------------------- Next few routines handles grading by csv upload
1881: #
1882: #--- Javascript to handle csv upload
1883: sub csvupload_javascript_reverse_associate {
1884: return(<<ENDPICK);
1885: function verify(vf) {
1886: var foundsomething=0;
1887: var founduname=0;
1888: var founddomain=0;
1889: for (i=0;i<=vf.nfields.value;i++) {
1890: tw=eval('vf.f'+i+'.selectedIndex');
1891: if (i==0 && tw!=0) { founduname=1; }
1892: if (i==1 && tw!=0) { founddomain=1; }
1893: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
1894: }
1895: if (founduname==0 || founddomain==0) {
1896: alert('You need to specify at both the username and domain');
1897: return;
1898: }
1899: if (foundsomething==0) {
1900: alert('You need to specify at least one grading field');
1901: return;
1902: }
1903: vf.submit();
1904: }
1905: function flip(vf,tf) {
1906: var nw=eval('vf.f'+tf+'.selectedIndex');
1907: var i;
1908: for (i=0;i<=vf.nfields.value;i++) {
1909: //can not pick the same destination field for both name and domain
1910: if (((i ==0)||(i ==1)) &&
1911: ((tf==0)||(tf==1)) &&
1912: (i!=tf) &&
1913: (eval('vf.f'+i+'.selectedIndex')==nw)) {
1914: eval('vf.f'+i+'.selectedIndex=0;')
1915: }
1916: }
1917: }
1918: ENDPICK
1919: }
1920:
1921: sub csvupload_javascript_forward_associate {
1922: return(<<ENDPICK);
1923: function verify(vf) {
1924: var foundsomething=0;
1925: var founduname=0;
1926: var founddomain=0;
1927: for (i=0;i<=vf.nfields.value;i++) {
1928: tw=eval('vf.f'+i+'.selectedIndex');
1929: if (tw==1) { founduname=1; }
1930: if (tw==2) { founddomain=1; }
1931: if (tw>2) { foundsomething=1; }
1932: }
1933: if (founduname==0 || founddomain==0) {
1934: alert('You need to specify at both the username and domain');
1935: return;
1936: }
1937: if (foundsomething==0) {
1938: alert('You need to specify at least one grading field');
1939: return;
1940: }
1941: vf.submit();
1942: }
1943: function flip(vf,tf) {
1944: var nw=eval('vf.f'+tf+'.selectedIndex');
1945: var i;
1946: //can not pick the same destination field twice
1947: for (i=0;i<=vf.nfields.value;i++) {
1948: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1949: eval('vf.f'+i+'.selectedIndex=0;')
1950: }
1951: }
1952: }
1953: ENDPICK
1954: }
1955:
1956: sub csvuploadmap_header {
1957: my ($request,$symb,$url,$datatoken,$distotal)= @_;
1958: my $javascript;
1959: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1960: $javascript=&csvupload_javascript_reverse_associate();
1961: } else {
1962: $javascript=&csvupload_javascript_forward_associate();
1963: }
1964:
1965: my $result='<table border="0">';
1966: $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
1967: my ($partlist,$handgrade) = &response_type($url);
1968: my ($resptype,$hdgrade)=('','no');
1969: for (sort keys(%$handgrade)) {
1970: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
1971: $resptype = $responsetype;
1972: $hdgrade = $handgrade if ($handgrade eq 'yes');
1973: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
1974: '<td><b>Type: </b>'.$responsetype.'</td>'.
1975: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
1976: }
1977: $result.='</table>';
1978: $request->print(<<ENDPICK);
1979: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1980: <h3><font color="#339933">Uploading Class Grades</font></h3>
1981: $result
1982: <hr>
1983: <h3>Identify fields</h3>
1984: Total number of records found in file: $distotal <hr />
1985: Enter as many fields as you can. The system will inform you and bring you back
1986: to this page if the data selected is insufficient to run your class.<hr />
1987: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1988: <input type="hidden" name="associate" value="" />
1989: <input type="hidden" name="phase" value="three" />
1990: <input type="hidden" name="datatoken" value="$datatoken" />
1991: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
1992: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
1993: <input type="hidden" name="upfile_associate"
1994: value="$ENV{'form.upfile_associate'}" />
1995: <input type="hidden" name="symb" value="$symb" />
1996: <input type="hidden" name="url" value="$url" />
1997: <input type="hidden" name="command" value="csvuploadassign" />
1998: <hr />
1999: <script type="text/javascript" language="Javascript">
2000: $javascript
2001: </script>
2002: ENDPICK
2003: return '';
2004:
2005: }
2006:
2007: sub csvupload_fields {
2008: my ($url) = @_;
2009: my (@parts) = &getpartlist($url);
2010: my @fields=(['username','Student Username'],['domain','Student Domain']);
2011: foreach my $part (sort(@parts)) {
2012: my @datum;
2013: my $display=&Apache::lonnet::metadata($url,$part.'.display');
2014: my $name=$part;
2015: if (!$display) { $display = $name; }
2016: @datum=($name,$display);
2017: push(@fields,\@datum);
2018: }
2019: return (@fields);
2020: }
2021:
2022: sub csvuploadmap_footer {
2023: my ($request,$i,$keyfields) =@_;
2024: $request->print(<<ENDPICK);
2025: </table>
2026: <input type="hidden" name="nfields" value="$i" />
2027: <input type="hidden" name="keyfields" value="$keyfields" />
2028: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
2029: </form>
2030: ENDPICK
2031: }
2032:
2033: sub csvuploadmap {
2034: my ($request)= @_;
2035: my ($symb,$url)=&get_symb_and_url($request);
2036: if (!$symb) {return '';}
2037: my $datatoken;
2038: if (!$ENV{'form.datatoken'}) {
2039: $datatoken=&Apache::loncommon::upfile_store($request);
2040: } else {
2041: $datatoken=$ENV{'form.datatoken'};
2042: &Apache::loncommon::load_tmp_file($request);
2043: }
2044: my @records=&Apache::loncommon::upfile_record_sep();
2045: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
2046: my ($i,$keyfields);
2047: if (@records) {
2048: my @fields=&csvupload_fields($url);
2049:
2050: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2051: &Apache::loncommon::csv_print_samples($request,\@records);
2052: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
2053: \@fields);
2054: foreach (@fields) { $keyfields.=$_->[0].','; }
2055: chop($keyfields);
2056: } else {
2057: unshift(@fields,['none','']);
2058: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
2059: \@fields);
2060: my %sone=&Apache::loncommon::record_sep($records[0]);
2061: $keyfields=join(',',sort(keys(%sone)));
2062: }
2063: }
2064: &csvuploadmap_footer($request,$i,$keyfields);
2065: return '';
2066: }
2067:
2068: sub csvuploadassign {
2069: my ($request)= @_;
2070: my ($symb,$url)=&get_symb_and_url($request);
2071: if (!$symb) {return '';}
2072: &Apache::loncommon::load_tmp_file($request);
2073: my @gradedata = &Apache::loncommon::upfile_record_sep();
2074: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
2075: my %fields=();
2076: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
2077: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2078: if ($ENV{'form.f'.$i} ne 'none') {
2079: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
2080: }
2081: } else {
2082: if ($ENV{'form.f'.$i} ne 'none') {
2083: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
2084: }
2085: }
2086: }
2087: $request->print('<h3>Assigning Grades</h3>');
2088: my $courseid=$ENV{'request.course.id'};
2089: my ($classlist) = &getclasslist('all','1');
2090: my @skipped;
2091: my $countdone=0;
2092: foreach my $grade (@gradedata) {
2093: my %entries=&Apache::loncommon::record_sep($grade);
2094: my $username=$entries{$fields{'username'}};
2095: my $domain=$entries{$fields{'domain'}};
2096: if (!exists($$classlist{"$username:$domain"})) {
2097: push(@skipped,"$username:$domain");
2098: next;
2099: }
2100: my %grades;
2101: foreach my $dest (keys(%fields)) {
2102: if ($dest eq 'username' || $dest eq 'domain') { next; }
2103: if ($entries{$fields{$dest}} eq '') { next; }
2104: my $store_key=$dest;
2105: $store_key=~s/^stores/resource/;
2106: $store_key=~s/_/\./g;
2107: $grades{$store_key}=$entries{$fields{$dest}};
2108: }
2109: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
2110: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
2111: $domain,$username);
2112: $request->print('.');
2113: $request->rflush();
2114: $countdone++;
2115: }
2116: $request->print("<br />Stored $countdone students\n");
2117: if (@skipped) {
2118: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
2119: foreach my $student (@skipped) { $request->print("<br />$student"); }
2120: }
2121: $request->print(&view_edit_entire_class_form($symb,$url));
2122: $request->print(&show_grading_menu_form($symb,$url));
2123: return '';
2124: }
2125: #------------- end of section for handling csv file upload ---------
2126: #
2127: #-------------------------------------------------------------------
2128:
2129: #-------------------------- Menu interface -------------------------
2130: #
2131: #--- Show a Grading Menu button - Calls the next routine ---
2132: sub show_grading_menu_form {
2133: my ($symb,$url)=@_;
2134: my $result.='<form action="/adm/grades" method="post">'."\n".
2135: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2136: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2137: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
2138: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
2139: '</form>'."\n";
2140: return $result;
2141: }
2142:
2143: #--- Displays the main menu page -------
2144: sub gradingmenu {
2145: my ($request) = @_;
2146: my ($symb,$url)=&get_symb_and_url($request);
2147: if (!$symb) {return '';}
2148: my $result='<h3> <font color="#339933">Select a Grading Method</font></h3>';
2149: $result.='<table border="0">';
2150: $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
2151: my ($partlist,$handgrade) = &response_type($url);
2152: my ($resptype,$hdgrade)=('','no');
2153: for (sort keys(%$handgrade)) {
2154: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
2155: $resptype = $responsetype;
2156: $hdgrade = $handgrade if ($handgrade eq 'yes');
2157: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
2158: '<td><b>Type: </b>'.$responsetype.'</td>'.
2159: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
2160: }
2161: $result.='</table>';
2162: $result.=&view_edit_entire_class_form($symb,$url).'<br />';
2163: $result.=&upcsvScores_form($symb,$url).'<br />';
2164: $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';
2165: $result.=&verifyReceipt_form($symb,$url)
2166: if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb));
2167:
2168: return $result;
2169: }
2170:
2171: #--- Menu for grading a section or the whole class ---
2172: sub view_edit_entire_class_form {
2173: my ($symb,$url)=@_;
2174: my ($classlist,$sections,undef) = &getclasslist('all','0');
2175: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
2176: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
2177: $result.=' <b>Grade Entire Section or Class</b></td></tr>'."\n";
2178: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2179: $result.='<form action="/adm/grades" method="post">'."\n".
2180: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2181: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2182: '<input type="hidden" name="command" value="viewgrades" />'."\n";
2183: $result.=' <b>Select section:</b> <select name="section">'."\n";
2184: if (ref($sections)) {
2185: foreach (sort (@$sections)) {
2186: $result.= '<option>'.$_.'</option>'."\n";
2187: }
2188: }
2189: $result.='<option selected="on">all</select>'."<br />\n";
2190: $result.=' <input type="button" onClick="submit();" value="Grade" /></form>'."\n";
2191: $result.='</td></tr></table>'."\n";
2192: $result.='</td></tr></table>'."\n";
2193: return $result;
2194: }
2195:
2196: #--- Menu to upload a csv scores ---
2197: sub upcsvScores_form {
2198: my ($symb,$url) = @_;
2199: if (!$symb) {return '';}
2200: my $result = '<script type="text/javascript" language="javascript">'."\n".
2201: ' function checkUpload(formname) {'."\n".
2202: ' if (formname.upfile.value == "") {'."\n".
2203: ' alert("Please use the browse button to select a file from your local directory.");'."\n".
2204: ' return false;'."\n".
2205: ' }'."\n".
2206: ' formname.submit();'."\n".
2207: ' }'."\n".
2208: '</script>'."\n";
2209:
2210: $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
2211: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
2212: $result.=' <b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
2213: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2214: my $upfile_select=&Apache::loncommon::upfile_select_html();
2215: $result.=<<ENDUPFORM;
2216: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
2217: <input type="hidden" name="symb" value="$symb" />
2218: <input type="hidden" name="url" value="$url" />
2219: <input type="hidden" name="command" value="csvuploadmap" />
2220: $upfile_select
2221: <br /> <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Grades" />
2222: </form>
2223: ENDUPFORM
2224: $result.='</td></tr></table>'."\n";
2225: $result.='</td></tr></table>'."\n";
2226: return $result;
2227: }
2228:
2229: #--- Handgrading problems ---
2230: sub viewGradeaStu_form {
2231: my ($symb,$url,$response,$handgrade) = @_;
2232: my ($classlist,$sections) = &getclasslist('all','0');
2233: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
2234: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
2235: $result.=' <b>';
2236: if ($handgrade eq 'yes') {
2237: $result.="View/Grade ";
2238: } else {
2239: $result.="View ";
2240: }
2241: $result.='an Individual Student\'s Submission</b></td></tr>'."\n";
2242: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2243: $result.='<form action="/adm/grades" method="post">'."\n".
2244: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2245: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2246: '<input type="hidden" name="response" value="'.$response.'" />'."\n".
2247: '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
2248: '<input type="hidden" name="showgrading" value="yes" />'."\n".
2249: '<input type="hidden" name="command" value="submission" />'."\n";
2250:
2251: $result.=' <b>Select section:</b> <select name="section">'."\n";
2252: if (ref($sections)) {
2253: foreach (sort (@$sections)) {$result.='<option>'.$_.'</option>'."\n";}
2254: }
2255: $result.= '<option selected="on">all</select>'."\n";
2256: $result.=' <b>Display students who has: </b>'.
2257: '<input type="radio" name="submitonly" value="yes" checked> submitted'.
2258: '<input type="radio" name="submitonly" value="all"> everybody <br />';
2259: if (ref($sections)) {
2260: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
2261: if (grep /no/,@$sections);
2262: }
2263:
2264:
2265: $result.='<br /> <input type="button" onClick="submit();" value="';
2266: if ($handgrade eq 'yes') {
2267: $result.="View/Grade";
2268: } else {
2269: $result.="View";
2270: }
2271: $result.='" />'."\n".'</form>'."\n";
2272: $result.='</td></tr></table>'."\n";
2273: $result.='</td></tr></table>'."\n";
2274: return $result;
2275: }
2276:
2277: #--- Form to input a receipt number ---
2278: sub verifyReceipt_form {
2279: my ($symb,$url) = @_;
2280: my $result = '<script type="text/javascript" language="javascript">'."\n".
2281: ' function checkEntry(formname) {'."\n".
2282: ' var receipt = formname.receipt.value;'."\n".
2283: ' if (isNaN(receipt) || receipt == "") {'."\n".
2284: ' alert("Please enter a receipt number given by a student in the box.");'."\n".
2285: ' return false;'."\n".
2286: ' }'."\n".
2287: ' formname.submit();'."\n".
2288: ' }'."\n".
2289: '</script>'."\n";
2290:
2291: my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
2292:
2293: $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
2294: $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
2295: $result.=' <b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
2296: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2297: $result.='<form action="/adm/grades" method="post" name="verifyform">'."\n";
2298: $result.=' <tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
2299: $result.=' <input type="button" onClick="javascript:checkEntry(this.form);"'.
2300: ' value="Verify Receipt">'."\n";
2301: $result.='<input type="hidden" name="command" value="verify">'."\n";
2302: if ($ENV{'form.url'}) {
2303: $result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
2304: }
2305: if ($ENV{'form.symb'}) {
2306: $result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
2307: }
2308: $result.='</form>';
2309: $result.='</td></tr></table>'."\n";
2310: $result.='</td></tr></table>'."\n";
2311: return $result;
2312: }
2313:
2314: sub handler {
2315: my $request=$_[0];
2316:
2317: if ($ENV{'browser.mathml'}) {
2318: $request->content_type('text/xml');
2319: } else {
2320: $request->content_type('text/html');
2321: }
2322: $request->send_http_header;
2323: return '' if $request->header_only;
2324: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
2325: my $url=$ENV{'form.url'};
2326: my $symb=$ENV{'form.symb'};
2327: my $command=$ENV{'form.command'};
2328: if (!$url) {
2329: my ($temp1,$temp2);
2330: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
2331: $url = $ENV{'form.url'};
2332: }
2333: &send_header($request);
2334: if ($url eq '' && $symb eq '') {
2335: if ($ENV{'user.adv'}) {
2336: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
2337: ($ENV{'form.codethree'})) {
2338: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
2339: $ENV{'form.codethree'};
2340: my ($tsymb,$tuname,$tudom,$tcrsid)=
2341: &Apache::lonnet::checkin($token);
2342: if ($tsymb) {
2343: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
2344: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
2345: $request->print(
2346: &Apache::lonnet::ssi('/res/'.$url,
2347: ('grade_username' => $tuname,
2348: 'grade_domain' => $tudom,
2349: 'grade_courseid' => $tcrsid,
2350: 'grade_symb' => $tsymb)));
2351: } else {
2352: $request->print('<h3>Not authorized: '.$token.'</h3>');
2353: }
2354: } else {
2355: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
2356: }
2357: } else {
2358: $request->print(&Apache::lonxml::tokeninputfield());
2359: }
2360: }
2361: } else {
2362: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
2363: if ($command eq 'submission') {
2364: &listStudents($request) if ($ENV{'form.student'} eq '');
2365: &submission($request,0,0) if ($ENV{'form.student'} ne '');
2366: } elsif ($command eq 'processGroup') {
2367: &processGroup($request);
2368: } elsif ($command eq 'gradingmenu') {
2369: $request->print(&gradingmenu($request));
2370: } elsif ($command eq 'viewgrades') {
2371: $request->print(&viewgrades($request));
2372: } elsif ($command eq 'handgrade') {
2373: $request->print(&processHandGrade($request));
2374: } elsif ($command eq 'editgrades') {
2375: $request->print(&editgrades($request));
2376: } elsif ($command eq 'verify') {
2377: $request->print(&verifyreceipt($request));
2378: } elsif ($command eq 'csvupload') {
2379: $request->print(&csvupload($request));
2380: } elsif ($command eq 'viewclasslist') {
2381: $request->print(&viewclasslist($request));
2382: } elsif ($command eq 'csvuploadmap') {
2383: $request->print(&csvuploadmap($request));
2384: } elsif ($command eq 'csvuploadassign') {
2385: if ($ENV{'form.associate'} ne 'Reverse Association') {
2386: $request->print(&csvuploadassign($request));
2387: } else {
2388: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
2389: $ENV{'form.upfile_associate'} = 'reverse';
2390: } else {
2391: $ENV{'form.upfile_associate'} = 'forward';
2392: }
2393: $request->print(&csvuploadmap($request));
2394: }
2395: } else {
2396: $request->print("Unknown action: $command:");
2397: }
2398: }
2399: &send_footer($request);
2400: return '';
2401: }
2402:
2403: sub send_header {
2404: my ($request)= @_;
2405: $request->print(&Apache::lontexconvert::header());
2406: # $request->print("
2407: #<script>
2408: #remotewindow=open('','homeworkremote');
2409: #remotewindow.close();
2410: #</script>");
2411: $request->print(&Apache::loncommon::bodytag('Grading'));
2412: }
2413:
2414: sub send_footer {
2415: my ($request)= @_;
2416: $request->print('</body>');
2417: $request->print(&Apache::lontexconvert::footer());
2418: }
2419:
2420: 1;
2421:
2422: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>