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