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