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