Annotation of loncom/homework/grades.pm, revision 1.35
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.35 ! ng 4: # $Id: grades.pm,v 1.34 2002/07/01 21:20:29 ng Exp $
1.17 albertel 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: #
1.13 albertel 28: # 2/9,2/13 Guy Albertelli
1.8 www 29: # 6/8 Gerd Kortemeyer
1.13 albertel 30: # 7/26 H.K. Ng
1.14 www 31: # 8/20 Gerd Kortemeyer
1.30 ng 32: # Year 2002
1.35 ! ng 33: # June, July 2002 H.K. Ng
1.30 ng 34: #
1.1 albertel 35:
36: package Apache::grades;
37: use strict;
38: use Apache::style;
39: use Apache::lonxml;
40: use Apache::lonnet;
1.3 albertel 41: use Apache::loncommon;
1.1 albertel 42: use Apache::lonhomework;
43: use Apache::Constants qw(:common);
44:
1.2 albertel 45: sub moreinfo {
1.13 albertel 46: my ($request,$reason) = @_;
47: $request->print("Unable to process request: $reason");
48: if ( $Apache::grades::viewgrades eq 'F' ) {
49: $request->print('<form action="/adm/grades" method="post">'."\n");
1.16 albertel 50: if ($ENV{'form.url'}) {
51: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
52: }
53: if ($ENV{'form.symb'}) {
54: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
55: }
1.35 ! ng 56: # $request->print('<input type="hidden" name="command" value="submission" />'."\n");
1.16 albertel 57: $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
58: $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
59: $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
60: $request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
1.13 albertel 61: $request->print('</form>');
62: }
63: return '';
1.2 albertel 64: }
65:
1.23 www 66: sub verifyreceipt {
67: my $request=shift;
68: my $courseid=$ENV{'request.course.id'};
1.34 ng 69: # my $cdom=$ENV{"course.$courseid.domain"};
70: # my $cnum=$ENV{"course.$courseid.num"};
1.23 www 71: my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
72: $ENV{'form.receipt'};
73: $receipt=~s/[^\-\d]//g;
74: my $symb=$ENV{'form.symb'};
75: unless ($symb) {
76: $symb=&Apache::lonnet::symbread($ENV{'form.url'});
77: }
78: if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
79: $request->print('<h1>Verifying Submission Receipt '.$receipt.'</h1>');
80: my $matches=0;
1.34 ng 81: my ($classlist) = &getclasslist('all','0');
82: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1.23 www 83: my ($uname,$udom)=split(/\:/,$student);
84: if ($receipt eq
85: &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
86: $request->print('Matching '.$student.'<br>');
87: $matches++;
88: }
89: }
1.30 ng 90: $request->printf('<p>'.$matches." match%s</p>",$matches <= 1 ? '' : 'es');
1.33 ng 91: # needs to print who is matched
1.23 www 92: }
93: return '';
94: }
1.13 albertel 95:
1.32 ng 96: sub student_gradeStatus {
97: my ($url,$udom,$uname) = @_;
98: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
99: my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
100: foreach my $part (&getpartlist($url)) {
101: my ($temp,$part,$type)=split(/_/,$part);
102: if ($type eq 'solved') {
103: my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
1.34 ng 104: $status = 'partial' if ($foo =~ /^partially/);
1.32 ng 105: $status = 'nothing' if ($status eq '');
106: return $type,$status;
107: }
108: }
109: return '';
110: }
111:
1.34 ng 112: sub get_fullname {
113: my ($sname,$sdom) = @_;
114: my %name=&Apache::lonnet::get('environment', ['lastname','generation',
115: 'firstname','middlename'],
116: $sdom,$sname);
117: my $fullname;
118: my ($tmp) = keys(%name);
119: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
120: $fullname=$name{'lastname'}.$name{'generation'};
121: if ($fullname =~ /[^\s]+/) { $fullname.=', '; }
122: $fullname.=$name{'firstname'}.' '.$name{'middlename'};
123: }
124: return $fullname;
125: }
126:
1.30 ng 127: sub listStudents {
128: my ($request) = shift;
1.34 ng 129: my $cdom =$ENV{"course.$ENV{'request.course.id'}.domain"};
130: my $cnum =$ENV{"course.$ENV{'request.course.id'}.num"};
131: my $getsec =$ENV{'form.section'};
132: my $submitonly=$ENV{'form.submitonly'};
1.30 ng 133:
1.23 www 134: $request->print(<<ENDTABLEST);
1.34 ng 135: <h2><font color="#339933"> View Submissions for a Student or a Group of Students</font></h2>
136: <font size=+1><b>Resource:</b> $ENV{'form.url'}<br /><br />
137: <form action="/adm/grades" method="post"> <b>View Options</b></font><br />
138: <b>View Problem: </b><input type="radio" name="vProb" value="no" checked> no
139: <input type="radio" name="vProb" value="yes"> yes
140: <b>Submissions: </b><input type="radio" name="lastSub" value="last" checked> last
141: <input type="radio" name="lastSub" value="all"> all
142: <input type="hidden" name="section" value="$getsec">
143: <input type="hidden" name="submitonly" value="$submitonly">
1.35 ! ng 144: <input type="hidden" name="response" value="$ENV{'form.response'}">
! 145: <input type="hidden" name="handgrade" value="$ENV{'form.handgrade'}">
1.32 ng 146: <table border="0"><tr><td bgcolor="#777777">
1.34 ng 147: <table border="0"><tr bgcolor="#e6ffff">
148: <td><b> Select </b></td><td><b> Username </b></td>
149: <td><b> Fullname </b></td><td><b> Domain </b></td>
150: <td><b> Grade Status </b></td></tr>
1.23 www 151: ENDTABLEST
1.34 ng 152: if ($ENV{'form.url'}) {
153: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
154: }
155: if ($ENV{'form.symb'}) {
156: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
157: }
158: $request->print('<input type="hidden" name="command" value="processGroup" />'."\n");
159:
160: my ($classlist) = &getclasslist($getsec,'0');
161: foreach my $student ( sort(@{ $$classlist{$getsec} }) ) {
1.13 albertel 162: my ($sname,$sdom) = split(/:/,$student);
1.34 ng 163: my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);
164: next if ($status eq 'nothing' && $submitonly eq 'yes');
1.13 albertel 165:
1.34 ng 166: my $fullname = &get_fullname($sname,$sdom);
1.13 albertel 167: if ( $Apache::grades::viewgrades eq 'F' ) {
1.34 ng 168: $request->print("\n".'<tr bgcolor="#ffffe6">'.
169: '<td align="center"><input type=checkbox name="stuinfo" value="'.
170: $student.':'.$fullname.'"></td>'."\n".
171: '<td> '.$sname.' </td>'."\n".
172: '<td> '.$fullname.' </td>'."\n".
173: '<td align="middle"> '.$sdom.' </td>'."\n");
174: $request->print('<td align="middle"> '.$status.' </td>'."\n");
175:
176: $request->print('</tr>');
1.13 albertel 177: }
178: }
1.28 ng 179: $request->print('</table></td></tr></table>');
1.34 ng 180: $request->print('<input type="submit" name="submit" value="View/Grade" /><form />');
1.10 ng 181: }
182:
1.34 ng 183: sub processGroup {
184: my ($request) = shift;
185: my $ctr = 0;
186: my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
1.35 ! ng 187: : ($ENV{'form.stuinfo'}));
1.34 ng 188: my $total = scalar(@stuchecked)-1;
1.35 ! ng 189: if ($stuchecked[0] eq '') {
! 190: &userError($request,'No student was selected for viewing/grading.');
! 191: return;
! 192: }
! 193: foreach (@stuchecked) {
! 194: my ($sname,$sdom,$fullname) = split(/:/);
1.34 ng 195: $ENV{'form.student'} = $sname;
196: $ENV{'form.fullname'} = $fullname;
197: &submission($request,$ctr,$total);
198: $ctr++;
199: }
1.35 ! ng 200: return 'The End';
! 201: }
1.34 ng 202:
1.35 ! ng 203: sub userError {
! 204: my ($request, $reason, $step) = @_;
! 205: $request->print('<h3><font color="red">LON-CAPA User Error</font></h3><br />'."\n");
! 206: $request->print('<b>Reason: </b>'.$reason.'<br /><br />'."\n");
! 207: $request->print('<b>Step: </b>'.($step ne '' ? $step : 'Use your browser back button to correct')
! 208: .'<br /><br />'."\n");
! 209: return '';
1.34 ng 210: }
1.13 albertel 211:
1.7 albertel 212: #FIXME - needs to handle multiple matches
1.2 albertel 213: sub finduser {
1.13 albertel 214: my ($name) = @_;
215: my $domain = '';
216: if ( $Apache::grades::viewgrades eq 'F' ) {
1.34 ng 217: my ($classlist) = &getclasslist('all','0');
1.35 ! ng 218: foreach ( sort(@{ $$classlist{'all'} }) ) {
! 219: my ($posname,$posdomain) = split(/:/);
1.13 albertel 220: if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
1.7 albertel 221: }
1.13 albertel 222: return ($name,$domain);
223: } else {
224: return ($ENV{'user.name'},$ENV{'user.domain'});
225: }
1.5 albertel 226: }
227:
228: sub getclasslist {
1.34 ng 229: my ($getsec,$hideexpired) = @_;
230: my ($coursedomain,$coursenum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 231: my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
1.13 albertel 232: my $now = time;
1.34 ng 233: my (@holdsec,@sections);
1.24 albertel 234: foreach my $student (keys(%classlist)) {
235: my ($end,$start)=split(/:/,$classlist{$student});
1.13 albertel 236: # still a student?
237: if (($hideexpired) && ($end) && ($end < $now)) {
238: next;
239: }
1.34 ng 240: my ($unam,$udom) = split(/:/,$student,2);
241: my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
1.35 ! ng 242: $section = ($section ne '-1' ? $section : 'no');
1.34 ng 243: push @holdsec,$section;
1.35 ! ng 244: push (@{ $classlist{$getsec} }, $student) if ($getsec eq 'all' || $getsec eq $section);
1.34 ng 245: }
246: my %seen = ();
247: foreach my $item (@holdsec) {
248: push (@sections, $item) unless $seen{$item}++;
1.13 albertel 249: }
1.34 ng 250: return (\%classlist,\@sections);
1.5 albertel 251: }
252:
253: sub getpartlist {
1.13 albertel 254: my ($url) = @_;
255: my @parts =();
256: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
257: foreach my $key (@metakeys) {
1.30 ng 258: if ( $key =~ m/stores_([0-9]+)_.*/) {
1.13 albertel 259: push(@parts,$key);
1.6 albertel 260: }
1.13 albertel 261: }
262: return @parts;
1.5 albertel 263: }
264:
265: sub viewstudentgrade {
1.13 albertel 266: my ($url,$symb,$courseid,$student,@parts) = @_;
267: my $result ='';
268: my $cellclr = '"#ffffdd"';
1.28 ng 269: my ($username,$domain) = split(/:/,$student);
1.13 albertel 270:
1.34 ng 271: my $fullname = &get_fullname($username,$domain);
1.28 ng 272: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username);
1.32 ng 273:
1.28 ng 274: $result.="<tr bgcolor=$cellclr><td>$username</td><td>$fullname</td><td align=\"middle\">$domain</td>\n";
1.13 albertel 275: foreach my $part (@parts) {
276: my ($temp,$part,$type)=split(/_/,$part);
1.31 ng 277: my $score=$record{"resource.$part.$type"};
278: if ($type eq 'awarded' || $type eq 'tries') {
279: $result.='<td align="middle"><input type="text" name="GRADE.'.$student.'.'.$part.'.'.$type.
280: '" value="'.$score.'" size="4" /></td>'."\n";
1.13 albertel 281: } elsif ($type eq 'solved') {
1.31 ng 282: my ($status,$foo)=split(/_/,$score,2);
1.28 ng 283: $result.="<td align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";
1.31 ng 284: my $optsel = '<option>correct</option><option>incorrect</option><option>excused</option>'.
1.33 ng 285: '<option>ungraded</option><option>partial</option><option>nothing</option>'."\n";
1.31 ng 286: $status = 'nothing' if ($status eq '');
287: $optsel =~ s/<option>$status/<option selected="on">$status/;
288: $result.=$optsel;
1.13 albertel 289: $result.="</select></td>\n";
290: }
291: }
1.29 albertel 292: $result.='<td></td></tr>';
1.13 albertel 293: return $result;
1.5 albertel 294: }
1.31 ng 295:
296: #FIXME need to look at the metadata <stores> spec on what type of data to accept and provide an
1.6 albertel 297: #interface based on that, also do that to above function.
1.5 albertel 298: sub setstudentgrade {
1.13 albertel 299: my ($url,$symb,$courseid,$student,@parts) = @_;
1.34 ng 300: print "set student grade parts=@parts<br>";
1.13 albertel 301: my $result ='';
302: my ($stuname,$domain) = split(/:/,$student);
303: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
304: my %newrecord;
305:
306: foreach my $part (@parts) {
307: my ($temp,$part,$type)=split(/_/,$part);
308: my $oldscore=$record{"resource.$part.$type"};
309: my $newscore=$ENV{"form.GRADE.$student.$part.$type"};
1.32 ng 310: print "old=$oldscore:new=$newscore:<br>";
1.13 albertel 311: if ($type eq 'solved') {
312: my $update=0;
313: if ($newscore eq 'nothing' ) {
314: if ($oldscore ne '') {
315: $update=1;
316: $newscore = '';
1.6 albertel 317: }
1.13 albertel 318: } elsif ($oldscore !~ m/^$newscore/) {
319: $update=1;
320: $result.="Updating $stuname to $newscore<br />\n";
1.34 ng 321: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
1.13 albertel 322: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
1.34 ng 323: if ($newscore eq 'excused') { $newscore = 'excused'; }
324: if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
325: if ($newscore eq 'partial') { $newscore = 'correct_partially_by_override'; }
1.13 albertel 326: } else {
327: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
328: }
329: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
330: } else {
331: if ($oldscore ne $newscore) {
332: $newrecord{"resource.$part.$type"}=$newscore;
333: $result.="Updating $student"."'s status for $part.$type to $newscore<br />\n";
334: } else {
335: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
336: }
337: }
338: }
339: if ( scalar(keys(%newrecord)) > 0 ) {
1.32 ng 340: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.34 ng 341: # &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
1.13 albertel 342:
343: $result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
344: }
345: return $result;
1.2 albertel 346: }
347:
1.33 ng 348: #
1.32 ng 349: # --------------------------- show submissions of a student, option to grade --------
1.2 albertel 350: sub submission {
1.34 ng 351: my ($request,$counter,$total) = @_;
1.33 ng 352:
1.34 ng 353: if ($counter == 0) {
354: $request->print(<<JAVASCRIPT);
1.32 ng 355: <script type="text/javascript" language="javascript">
1.33 ng 356: function updateRadio(radioButton,formtextbox,formsel,wgt) {
357: var pts = formtextbox.value;
358: var resetbox =false;
359: if (isNaN(pts) || pts < 0) {
360: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
361: for (var i=0; i<radioButton.length; i++) {
362: if (radioButton[i].checked) {
363: formtextbox.value = i;
364: resetbox = true;
365: }
1.32 ng 366: }
1.33 ng 367: if (!resetbox) {
368: formtextbox.value = "";
369: }
370: return;
371: }
1.32 ng 372:
1.33 ng 373: for (var i=0; i<radioButton.length; i++) {
374: radioButton[i].checked=false;
375: if (pts == i) {
376: radioButton[i].checked=true;
1.32 ng 377: }
1.31 ng 378: }
1.33 ng 379: updateSelect(formsel,pts,wgt);
380: }
381:
382: function writeBox(formrad,formsel,pts,wgt) {
383: formrad.value = pts;
384: updateSelect(formsel,pts,wgt);
385: return;
386: }
387:
388: function updateSelect(formsel,pts,wgt) {
389: if (pts == 0) {
390: formsel[1].selected = true;
391: }
392: if (pts > 0 && pts < wgt) {
393: formsel[4].selected = true;
394: }
395: if (pts == wgt) {
396: formsel[0].selected = true;
397: }
398: return;
399: }
1.32 ng 400:
1.35 ! ng 401: function keywords(keyform) {
! 402: var keywds = keyform.value;
! 403: var nret = prompt("Keywords list, separate by a space or comma. Add/delete to list if desired.",keywds);
! 404: if (nret==null) return;
! 405: keyform.value = nret;
! 406: return;
! 407: }
! 408:
! 409: function addmsg(msgform) {
! 410: var msg = msgform.value;
! 411: var nret = prompt("Enter the message you wish to send to the student.",msg);
! 412: if (nret==null) return;
! 413: msgform.value = nret;
! 414: return;
! 415: }
! 416:
! 417: function savedmsg(msgform) {
! 418: var Nmsg = msgform.value;
! 419: var nret = prompt("Number of saved messages = ",Nmsg);
! 420: if (nret==null) return;
! 421: msgform.value = nret;
! 422: return;
! 423: }
! 424:
1.31 ng 425: </script>
426: JAVASCRIPT
1.34 ng 427: }
1.33 ng 428: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.35 ! ng 429: if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
1.13 albertel 430: my ($uname,$udom) = &finduser($ENV{'form.student'});
1.35 ! ng 431: if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
1.32 ng 432:
433: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.13 albertel 434: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.34 ng 435: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
1.31 ng 436: #
437: # header info
1.34 ng 438: if ($counter == 0) {
439: $request->print('<h2><font color="#339933">Submission Record</font></h2>');
440: }
441:
1.31 ng 442: #
1.34 ng 443: # option to display problem, only once else it cause problems with the form later since the problem has a form.
444: if ($ENV{'form.vProb'} eq 'yes' && $counter == 0) {
1.30 ng 445: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.17 albertel 446: $ENV{'request.course.id'});
1.30 ng 447: my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
448: $ENV{'request.course.id'});
1.34 ng 449: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.33 ng 450: $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
1.31 ng 451: $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1.30 ng 452: $result.='<b>Correct answer:</b><br />'.$companswer;
453: $result.='</td></tr></table>';
454: $result.='</td></tr></table><br />';
1.34 ng 455: $request->print($result);
456: }
457: #
458: # beginning of form
459: if ($counter == 0) {
1.35 ! ng 460: my %keyhash = &Apache::lonnet::get
! 461: ('nohist_handgrade',[$symb.'_keywords'],
! 462: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
! 463: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
! 464:
1.34 ng 465: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
1.35 ! ng 466: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
! 467: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
! 468: '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
! 469: '<input type="hidden" name="lastSub" value="'.$last.'" />'."\n".
! 470: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
1.34 ng 471: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
1.35 ! ng 472: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'">'."\n".
! 473: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'">'."\n".
! 474: '<input type="hidden" name="command" value="handgrade" />'."\n".
! 475: '<input type="hidden" name="keywords" value="'.$keyhash{$symb.'_keywords'}.'" />'."\n".
! 476: '<input type="hidden" name="addmsg" value="" />'."\n".
! 477: '<input type="hidden" name="savemsgN" value="3" />'."\n".
! 478: '<input type="hidden" name="savemsg0" value="Good Job!" />'."\n".
! 479: '<input type="hidden" name="savemsg1" value="Needs a better explanation." />'."\n".
! 480: '<input type="hidden" name="savemsg2" value="Read the book before submitting such garbagge!" />'."\n".
1.34 ng 481: '<input type="hidden" name="NCT"'.
482: ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1').'" />'."\n");
1.35 ! ng 483:
! 484: if ($ENV{'form.handgrade'} eq 'yes') {
! 485: $request->print(<<KEYWORDS);
! 486: <b>Grading Options</b>
! 487: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>Keywords list</a>
! 488: <a href="javascript:addmsg(document.SCORE.addmsg)"; TARGET=_self>Add a message</a>
! 489: <a href="javascript:savedmsg(document.SCORE.savemsgN)"; TARGET=_self>Saved messages</a><br /><br />
! 490: KEYWORDS
! 491: }
1.30 ng 492: }
1.35 ! ng 493:
1.34 ng 494: #
495: # Student info
496: $request->print(($counter == 0 ? '' : '<br /><hr><br />'));
497: my $result.='<table border="0"><tr><td><b>Username: </b>'.$uname.
498: '</td><td><b>Fullname: </b>'.
499: ($ENV{'form.fullname'} ne '' ? $ENV{'form.fullname'} : &get_fullname($uname,$udom)).
500: '</td><td><b>Domain: </b>'.$udom.'</td></tr>';
1.35 ! ng 501: if ($ENV{'form.handgrade'} eq 'yes') {
! 502: my $subonly = &get_last_submission($symb,$uname,$udom,$ENV{'request.course.id'});
! 503: my ($classlist) = &getclasslist('all','0');
! 504: my @collaborators;
! 505: foreach ( sort(@{ $$classlist{'all'} }) ) {
! 506: my ($sname,$sdom) = split(/:/);
! 507: push @collaborators,$sname if (grep /\b$sname(\b|\.)/i,$subonly);
! 508: }
! 509: push @collaborators,'leede','carlandmm','freyniks'; # as a test to display collaborators.
! 510: if (scalar(@collaborators) != 0) {
! 511: $result.='<tr><td colspan=3><b>Collaborators: </b>';
! 512: foreach (@collaborators) {
! 513: $result.=$_.' ('.&get_fullname($_,$udom).') ';
! 514: }
! 515: $result.='</td></tr>'."\n";
! 516: $result.='<input type="hidden" name="collaborator'.$counter.
! 517: '" value="'.(join ':',@collaborators).'" />'."\n";
! 518: }
! 519: }
! 520: $result.='<tr><td colspan=3><b>Resource: </b>'.$url.'</td></tr></table>'."\n";
1.34 ng 521: $request->print($result);
522: #
523: # print student answer
1.35 ! ng 524: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
! 525: $ENV{'request.course.id'},$last,
! 526: '.submission','Apache::grades::keywords_highlight'));
! 527: #
1.34 ng 528: #
529: my $wgt = &Apache::lonnet::EXT('resource.partid.weight',$symb,$udom,$uname);
530: my $wgtmsg = ($wgt > 0 ? '(problem weight)' : '<font color="red">problem weight assigned by computer</font>');
531: $wgt = ($wgt > 0 ? $wgt : '1');
532: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
533: my $score = ($record{'resource.0.awarded'} eq '' ? '' : $record{'resource.0.awarded'}*$wgt);
1.18 albertel 534:
1.34 ng 535: #
536: # display grading options
537: $result='<input type="hidden" name="WGT'.$counter.'" value="'.$wgt.'" />'.
1.33 ng 538: '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'.$udom.'" />'."\n";
1.32 ng 539: $result.='<table border="0"><tr><td><b>Points</b></td><td>';
1.31 ng 540: my $ctr = 0;
1.34 ng 541:
542: $result.='<table border="0"><tr>'; # display radio buttons in a nice table with 10 across
1.32 ng 543: while ($ctr<=$wgt) {
1.34 ng 544: $result.= '<td><input type="radio" name="RADVAL'.$counter.'" '.
1.33 ng 545: 'onclick="javascript:writeBox(this.form.GRADE_BOX'.$counter.
1.34 ng 546: ',this.form.GRADE_SEL'.$counter.','.$ctr.','.$wgt.')" '.
547: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
548: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.31 ng 549: $ctr++;
550: }
1.34 ng 551: $result.='</tr></table>';
552:
1.31 ng 553: $result.='</td><td> <b>or</b> </td>';
1.33 ng 554: $result.='<td><input type="text" name="GRADE_BOX'.$counter.'"'.
1.32 ng 555: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.33 ng 556: 'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.
557: ',this.form.GRADE_BOX'.$counter.
558: ',this.form.GRADE_SEL'.$counter.',\''.$wgt.'\')" /></td>'."\n";
1.34 ng 559: $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
1.33 ng 560:
561: foreach my $part (&getpartlist($url)) {
562: my ($temp,$part,$type)=split(/_/,$part);
563: if ($type eq 'solved') {
564: my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
1.34 ng 565: $status = 'partial' if ($foo =~ /partially/);
566: $status = 'nothing' if ($status eq '');
1.33 ng 567: $result.='<select name="GRADE_SEL'.$counter.'">'."\n";
568: my $optsel = '<option>correct</option><option>incorrect</option>'.
569: '<option>excused</option><option>ungraded</option>'.
570: '<option>partial</option><option>nothing</option>'."\n";
571: $optsel =~ s/<option>$status/<option selected="on">$status/;
572: $result.=$optsel;
573: $result.="</select></td></tr>\n";
574: }
575: }
1.34 ng 576: $result.='</table>';
577: $request->print($result);
578: #
579: # print end of form
580: if ($counter == $total) {
581: my $endform.='<table border="0"><tr><td><input type="submit" name="gradeOpt" value="Save & Next" />';
582: my $ntstu ='<select name="NTSTU">'.
583: '<option>1</option><option>2</option>'.
584: '<option>3</option><option>5</option>'.
585: '<option>7</option><option>10</option></select>'."\n";
586: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
587: $ntstu =~ s/<option>$nsel/<option selected="on">$nsel/;
588: $endform.=$ntstu.'student(s) ';
589: $endform.='<input type="submit" name="gradeOpt" value="Next" /> ';
590: $endform.='<input type="submit" name="gradeOpt" value="Previous" /> ';
591: $endform.='(Next and Previous do not save the scores.)';
592: $endform.='</td><tr></table></form>';
593: $request->print($endform);
594: }
595: return '';
1.32 ng 596: }
1.30 ng 597:
1.35 ! ng 598: sub get_last_submission {
! 599: my ($symb,$username,$domain,$course)=@_;
! 600: if ($symb) {
! 601: my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
! 602: if ($returnhash{'version'}) {
! 603: my %lasthash=();
! 604: my $version;
! 605: for ($version=1;$version<=$returnhash{'version'};$version++) {
! 606: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
! 607: $lasthash{$_}=$returnhash{$version.':'.$_};
! 608: }
! 609: }
! 610: foreach ((keys %lasthash)) {
! 611: if ($_ =~ /\.submission$/) {return $lasthash{$_}}
! 612: }
! 613: return '';
! 614: }
! 615: }
! 616: }
! 617:
! 618: sub keywords_highlight {
! 619: my $string = shift;
! 620: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
! 621: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
! 622: my %keyhash = &Apache::lonnet::get
! 623: ('nohist_handgrade',[$symb.'_keywords'],
! 624: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
! 625: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
! 626: my @keylist = split(/[,\s+]/,$keyhash{$symb.'_keywords'});
! 627: foreach my $word (@keylist) {
! 628: next if ($word eq '');
! 629: $string =~ s/\b$word(\b|\.)/\<font color\=red\>$word\<\/font\>/gi;
! 630: }
! 631: return $string;
! 632: }
! 633:
1.32 ng 634: sub processHandGrade {
1.34 ng 635: my ($request) = shift;
1.33 ng 636: my $url = $ENV{'form.url'};
637: my $symb = $ENV{'form.symb'};
638: my $button = $ENV{'form.gradeOpt'};
639: my $ngrade = $ENV{'form.NCT'};
640: my $ntstu = $ENV{'form.NTSTU'};
1.35 ! ng 641: my $keywords= $ENV{'form.keywords'};
! 642: my $addmsg = $ENV{'form.addmsg'};
! 643: print "addmsg=$addmsg<br>";
! 644: if ($keywords ne '') {
! 645: my $crsname = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
! 646: my $crsdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
! 647: my $putresult = &Apache::lonnet::put
! 648: ('nohist_handgrade',{$symb.'_keywords' => $keywords},
! 649: $crsdom,$crsname);
! 650: }
1.33 ng 651: my (@parts) = sort(&getpartlist($url));
1.34 ng 652:
1.33 ng 653: if ($button eq 'Save & Next') {
654: my $ctr = 0;
655: while ($ctr < $ENV{'form.NCT'}) {
656: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.34 ng 657: &saveHandGrade($url,$symb,$uname,$udom,$ctr,@parts);
1.35 ! ng 658: if ($ENV{'form.collaborator'.$ctr}) {
! 659: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
! 660: foreach (@collaborators) {
! 661: &saveHandGrade($url,$symb,$_,$udom,$ctr,@parts);
! 662: }
! 663: }
1.33 ng 664: $ctr++;
665: }
666: }
667: my $firststu = $ENV{'form.unamedom0'};
668: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
669:
1.35 ! ng 670: my ($classlist) = &getclasslist($ENV{'form.section'},'0');
1.33 ng 671:
672: my (@nextlist,@prevlist);
1.34 ng 673: my ($nextflg,$prevflg,$ctr,$ctprev) = (0,0,0,0);
1.35 ! ng 674: foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
1.33 ng 675: my ($uname,$udom) = split(/:/,$student);
676: if ($nextflg == 1 && $button =~ /Next$/) {
1.34 ng 677: push @nextlist,$uname if ($ctr < $ntstu);
1.33 ng 678: $ctr++;
679: }
680: $nextflg = 1 if ($student eq $laststu);
681: $prevflg = 1 if ($student eq $firststu);
1.34 ng 682: if ($prevflg == 0 && $button eq 'Previous') {
683: push @prevlist,$uname;
684: $ctprev++;
685: }
1.33 ng 686: }
1.34 ng 687: if ($button eq 'Previous') {
688: if ($ctprev <= $ntstu) {
689: @nextlist = @prevlist;
690: } else {
691: my $idx = 0;
692: my $start = $ctprev - $ntstu;
693: while ($idx < $ntstu) {
694: $nextlist[$idx] = $prevlist[$start+$idx];
695: $idx++;
696: }
697: }
698: }
699: $ctr = 0;
700: my $total = scalar(@nextlist)-1;
1.33 ng 701: foreach my $student (@nextlist) {
702: $ENV{'form.student'} = $student;
1.34 ng 703: &submission($request,$ctr,$total);
704: $ctr++;
1.33 ng 705: }
706:
707: return 'The End';
708: }
709:
710: sub saveHandGrade {
1.34 ng 711: my ($url,$symb,$stuname,$domain,$newflg,@parts) = @_;
1.33 ng 712: my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
1.32 ng 713: my %newrecord;
714:
715: foreach my $part (@parts) {
1.31 ng 716: my ($temp,$part,$type)=split(/_/,$part);
1.32 ng 717: my $oldscore=$record{"resource.$part.$type"};
1.34 ng 718: my $newscore;
719: if ($type eq 'awarded' && $newflg >= 0) {
1.35 ! ng 720: my $pts = ($ENV{'form.GRADE_BOX'.$newflg} ne '' ?
! 721: $ENV{'form.GRADE_BOX'.$newflg} : $ENV{'form.RADVAL'.$newflg});
1.34 ng 722: my $wgt = $ENV{'form.WGT'.$newflg};
723: # my $sel = $ENV{'form.GRADE_SEL'.$newflg};
724: $newscore = $pts/$wgt if ($wgt != 0);
725: }
1.31 ng 726: if ($type eq 'solved') {
1.34 ng 727: $newscore = $ENV{'form.GRADE_SEL'.$newflg} if ($newflg >= 0);
1.32 ng 728: my $update=0;
729: if ($newscore eq 'nothing' ) {
730: if ($oldscore ne '') {
731: $update=1;
732: $newscore = '';
733: }
734: } elsif ($oldscore !~ m/^$newscore/) {
735: $update=1;
736: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
737: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
738: if ($newscore eq 'excused') { $newscore = 'excused'; }
739: if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
1.34 ng 740: if ($newscore eq 'partial') { $newscore = 'correct_partially_by_override'; }
1.32 ng 741: }
742: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
743: } else {
744: if ($oldscore ne $newscore) {
745: $newrecord{"resource.$part.$type"}=$newscore;
1.33 ng 746: }
1.32 ng 747: }
1.34 ng 748: }
749: if ( scalar(keys(%newrecord)) > 0 ) {
1.33 ng 750: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.35 ! ng 751: # while (my ($k,$v) = each %newrecord) {
! 752: # print "k=$k:v=$v:<br>\n";
! 753: # }
! 754: # print "symb=$symb,courseid=$ENV{'request.course.id'},dom=$domain,name=$stuname<br>";
1.34 ng 755: # &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
1.31 ng 756: }
1.34 ng 757: return '';
1.2 albertel 758: }
759:
1.26 albertel 760: sub get_symb_and_url {
1.34 ng 761: my ($request) = @_;
762: (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.32 ng 763: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.13 albertel 764: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.34 ng 765: return ($symb,$url);
1.29 albertel 766: }
767:
768: sub show_grading_menu_form {
769: my ($symb,$url)=@_;
770: my $result.='<form action="/adm/grades" method="post">'."\n".
771: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
772: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
773: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
774: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
775: '</form>'."\n";
776: return $result;
777: }
778:
1.26 albertel 779: sub gradingmenu {
780: my ($request) = @_;
781: my ($symb,$url)=&get_symb_and_url($request);
782: if (!$symb) {return '';}
1.35 ! ng 783: my $allkeys = &Apache::lonnet::metadata($url,'keys');
! 784: my $handgrade = ($allkeys =~ /parameter_.*?_handgrade/ ? 'yes' : 'no');
! 785: my ($responsetype,$foo) = split(/_/,&Apache::lonnet::metadata($url,'packages'));
1.28 ng 786:
1.34 ng 787: my $result='<h2> <font color="#339933">Select a Grading Method</font></h2>';
1.35 ! ng 788: $result.='<table border="0">';
! 789: $result.='<tr><td><font size=+1><b>Resource: </b></font></td>'.
! 790: '<td><font size=+1>'.$url.'</font></td></tr>';
! 791: $result.='<tr><td><font size=+1><b>Type: </b></font></td>'.
! 792: '<td><font size=+1>'.$responsetype.' <b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
! 793: $result.='</table>';
1.34 ng 794:
795: $result.=&view_edit_entire_class_form($symb,$url).'<br />';
796: $result.=&upcsvScores_form($symb,$url).'<br />';
1.35 ! ng 797: $result.=&viewGradeaStu_form($symb,$url,$responsetype,$handgrade).'<br />';
1.34 ng 798: $result.=&verifyReceipt_form($symb,$url);
799: return $result;
800: }
801:
802: sub view_edit_entire_class_form {
803: my ($symb,$url)=@_;
804: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
805: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
806: $result.=' <b>View/Grade Entire Class</b></td></tr>'."\n";
1.28 ng 807: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.26 albertel 808: $result.='<form action="/adm/grades" method="post">'."\n".
1.34 ng 809: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.26 albertel 810: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.34 ng 811: '<input type="hidden" name="command" value="viewgrades" />'."\n";
812: $result.=' <b>Display students who has: </b>'.
813: '<input type="radio" name="submitonly" value="yes" checked> submitted'.
814: '<input type="radio" name="submitonly" value="all"> everybody <br /><br />';
815: $result.=' <input type="submit" name="submit" value="View/Grade" /></form>'."\n";
816: $result.='</td></tr></table>'."\n";
817: $result.='</td></tr></table>'."\n";
818: return $result;
819: }
820:
821: sub upcsvScores_form {
822: my ($symb,$url) = @_;
823: if (!$symb) {return '';}
824: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
825: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
826: $result.=' <b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
827: $result.='<tr bgcolor=#ffffe6><td>'."\n";
828: my $upfile_select=&Apache::loncommon::upfile_select_html();
829: $result.=<<ENDUPFORM;
830: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
831: <input type="hidden" name="symb" value="$symb" />
832: <input type="hidden" name="url" value="$url" />
833: <input type="hidden" name="command" value="csvuploadmap" />
834: $upfile_select
835: <br /> <input type="submit" name="submit" value="Upload Grades" />
836: </form>
837: ENDUPFORM
838: $result.='</td></tr></table>'."\n";
839: $result.='</td></tr></table>'."\n";
840: return $result;
841: }
842:
843: sub viewGradeaStu_form {
1.35 ! ng 844: my ($symb,$url,$response,$handgrade) = @_;
1.34 ng 845: my ($classlist,$sections) = &getclasslist('all','0');
846: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
847: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
848: $result.=' <b>View/Grade an Individual Student\'s Submission</b></td></tr>'."\n";
849: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.26 albertel 850: $result.='<form action="/adm/grades" method="post">'."\n".
851: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
852: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.35 ! ng 853: '<input type="hidden" name="response" value="'.$response.'" />'."\n".
! 854: '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
! 855: '<input type="hidden" name="command" value="submission" />'."\n";
1.34 ng 856:
857: $result.=' <b>Select section:</b> <select name="section">'."\n";
858: foreach my $section (sort (@$sections)) {
859: $result.= '<option>'.$section.'</option>'."\n";
860: }
861: $result.= '<option selected="on">all</select>'."\n";
862: $result.=' <b>Display students who has: </b>'.
863: '<input type="radio" name="submitonly" value="yes" checked> submitted'.
864: '<input type="radio" name="submitonly" value="all"> everybody <br />';
1.35 ! ng 865: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
! 866: if (grep /no/,@$sections);
1.34 ng 867:
868: $result.='<br /> <input type="submit" name="submit" value="View/Grade" />'."\n".
869: '</form>'."\n";
870: $result.='</td></tr></table>'."\n";
871: $result.='</td></tr></table>'."\n";
872: return $result;
873: }
874:
875: sub verifyReceipt_form {
876: my ($symb,$url) = @_;
877: my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
878: my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
879: my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
880:
881: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
882: $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
883: $result.=' <b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
884: $result.='<tr bgcolor=#ffffe6><td>'."\n";
885: $result.='<form action="/adm/grades" method="post">'."\n";
886: $result.=' <tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
887: $result.=' <input type="submit" name="submit" value="Verify Receipt">'."\n";
888: $result.='<input type="hidden" name="command" value="verify">'."\n";
889: if ($ENV{'form.url'}) {
890: $result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
891: }
892: if ($ENV{'form.symb'}) {
893: $result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
894: }
895: $result.='</form>';
1.28 ng 896: $result.='</td></tr></table>'."\n";
897: $result.='</td></tr></table>'."\n";
1.26 albertel 898: return $result;
899: }
900:
901: sub viewgrades {
902: my ($request) = @_;
903: my $result='';
904:
905: #get resource reference
906: my ($symb,$url)=&get_symb_and_url($request);
907: if (!$symb) {return '';}
1.13 albertel 908: #get classlist
909: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 910: #print "Found $cdom:$cnum<br />";
1.34 ng 911: my ($classlist) = &getclasslist('all','0');
1.13 albertel 912: my $headerclr = '"#ccffff"';
913: my $cellclr = '"#ffffcc"';
914:
915: #get list of parts for this problem
1.29 albertel 916: my (@parts) = sort(&getpartlist($url));
1.13 albertel 917:
1.28 ng 918: $request->print ("<h2><font color=\"#339933\">Manual Grading</font></h2>");
1.13 albertel 919:
920: #start the form
921: $result = '<form action="/adm/grades" method="post">'."\n".
1.16 albertel 922: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
923: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.13 albertel 924: '<input type="hidden" name="command" value="editgrades" />'."\n".
925: '<input type="submit" name="submit" value="Submit Changes" />'."\n".
1.32 ng 926: '<table border=0><tr><td bgcolor="#777777">'."\n".
1.13 albertel 927: '<table border=0>'."\n".
1.28 ng 928: '<tr bgcolor='.$headerclr.'><td><b>Username</b></td><td><b>Name</b></td><td><b>Domain</b></td>'."\n";
1.29 albertel 929: foreach my $part (@parts) {
1.13 albertel 930: my $display=&Apache::lonnet::metadata($url,$part.'.display');
931: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.28 ng 932: $result.='<td><b>'.$display.'</b></td>'."\n";
1.30 ng 933: }
1.28 ng 934: $result.='</tr>';
1.13 albertel 935: #get info for each student
1.34 ng 936: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1.31 ng 937: my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
938: # print "ID=$ENV{'request.course.id'}:STU=$student:DIS=$display:<br>\n";
1.13 albertel 939: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
940: }
1.31 ng 941: $result.='</table></td></tr></table>';
942: $result.='<input type="submit" name="submit" value="Submit Changes" /></form>';
1.29 albertel 943: $result.=&show_grading_menu_form($symb,$url);
1.13 albertel 944: return $result;
1.5 albertel 945: }
946:
947: sub editgrades {
1.13 albertel 948: my ($request) = @_;
949: my $result='';
1.5 albertel 950:
1.13 albertel 951: my $symb=$ENV{'form.symb'};
952: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
953: my $url=$ENV{'form.url'};
954: #get classlist
1.34 ng 955: # my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 956: #print "Found $cdom:$cnum<br />";
1.34 ng 957: my ($classlist) = &getclasslist('all','0');
1.13 albertel 958:
959: #get list of parts for this problem
960: my (@parts) = &getpartlist($url);
961:
962: $result.='<form action="/adm/grades" method="post">'."\n".
963: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
964: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
965: '<input type="hidden" name="command" value="viewgrades" />'."\n".
966: '<input type="submit" name="submit" value="See Grades" /> <br />'."\n";
967:
1.35 ! ng 968: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1.13 albertel 969: $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
970: }
1.5 albertel 971:
1.13 albertel 972: $result.='<input type="submit" name="submit" value="See Grades" /></table></form>';
973: return $result;
1.5 albertel 974: }
975:
1.27 albertel 976: sub csvupload_javascript_reverse_associate {
977: return(<<ENDPICK);
978: function verify(vf) {
979: var foundsomething=0;
980: var founduname=0;
981: var founddomain=0;
982: for (i=0;i<=vf.nfields.value;i++) {
983: tw=eval('vf.f'+i+'.selectedIndex');
984: if (i==0 && tw!=0) { founduname=1; }
985: if (i==1 && tw!=0) { founddomain=1; }
986: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
987: }
988: if (founduname==0 || founddomain==0) {
989: alert('You need to specify at both the username and domain');
990: return;
991: }
992: if (foundsomething==0) {
993: alert('You need to specify at least one grading field');
994: return;
995: }
996: vf.submit();
997: }
998: function flip(vf,tf) {
999: var nw=eval('vf.f'+tf+'.selectedIndex');
1000: var i;
1001: for (i=0;i<=vf.nfields.value;i++) {
1002: //can not pick the same destination field for both name and domain
1003: if (((i ==0)||(i ==1)) &&
1004: ((tf==0)||(tf==1)) &&
1005: (i!=tf) &&
1006: (eval('vf.f'+i+'.selectedIndex')==nw)) {
1007: eval('vf.f'+i+'.selectedIndex=0;')
1008: }
1009: }
1010: }
1011: ENDPICK
1012: }
1013:
1014: sub csvupload_javascript_forward_associate {
1015: return(<<ENDPICK);
1016: function verify(vf) {
1017: var foundsomething=0;
1018: var founduname=0;
1019: var founddomain=0;
1020: for (i=0;i<=vf.nfields.value;i++) {
1021: tw=eval('vf.f'+i+'.selectedIndex');
1022: if (tw==1) { founduname=1; }
1023: if (tw==2) { founddomain=1; }
1024: if (tw>2) { foundsomething=1; }
1025: }
1026: if (founduname==0 || founddomain==0) {
1027: alert('You need to specify at both the username and domain');
1028: return;
1029: }
1030: if (foundsomething==0) {
1031: alert('You need to specify at least one grading field');
1032: return;
1033: }
1034: vf.submit();
1035: }
1036: function flip(vf,tf) {
1037: var nw=eval('vf.f'+tf+'.selectedIndex');
1038: var i;
1039: //can not pick the same destination field twice
1040: for (i=0;i<=vf.nfields.value;i++) {
1041: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1042: eval('vf.f'+i+'.selectedIndex=0;')
1043: }
1044: }
1045: }
1046: ENDPICK
1047: }
1048:
1.26 albertel 1049: sub csvuploadmap_header {
1050: my ($request,$symb,$url,$datatoken,$distotal)= @_;
1051: my $result;
1052: my $javascript;
1053: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.27 albertel 1054: $javascript=&csvupload_javascript_reverse_associate();
1.26 albertel 1055: } else {
1.27 albertel 1056: $javascript=&csvupload_javascript_forward_associate();
1.26 albertel 1057: }
1058: $request->print(<<ENDPICK);
1059: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1060: <h3>Uploading Class Grades for resource $url</h3>
1061: <hr>
1062: <h3>Identify fields</h3>
1063: Total number of records found in file: $distotal <hr />
1064: Enter as many fields as you can. The system will inform you and bring you back
1065: to this page if the data selected is insufficient to run your class.<hr />
1066: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1067: <input type="hidden" name="associate" value="" />
1068: <input type="hidden" name="phase" value="three" />
1069: <input type="hidden" name="datatoken" value="$datatoken" />
1070: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
1071: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
1072: <input type="hidden" name="upfile_associate"
1073: value="$ENV{'form.upfile_associate'}" />
1074: <input type="hidden" name="symb" value="$symb" />
1075: <input type="hidden" name="url" value="$url" />
1076: <input type="hidden" name="command" value="csvuploadassign" />
1077: <hr />
1078: <script type="text/javascript" language="Javascript">
1079: $javascript
1080: </script>
1081: ENDPICK
1082: return '';
1083:
1084: }
1085:
1086: sub csvupload_fields {
1087: my ($url) = @_;
1088: my (@parts) = &getpartlist($url);
1.27 albertel 1089: my @fields=(['username','Student Username'],['domain','Student Domain']);
1090: foreach my $part (sort(@parts)) {
1.26 albertel 1091: my @datum;
1092: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.27 albertel 1093: my $name=$part;
1.26 albertel 1094: if (!$display) { $display = $name; }
1095: @datum=($name,$display);
1096: push(@fields,\@datum);
1097: }
1098: return (@fields);
1099: }
1100:
1101: sub csvuploadmap_footer {
1102: my ($request,$i,$keyfields) =@_;
1103: $request->print(<<ENDPICK);
1104: </table>
1105: <input type="hidden" name="nfields" value="$i" />
1106: <input type="hidden" name="keyfields" value="$keyfields" />
1107: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
1108: </form>
1109: ENDPICK
1110: }
1111:
1112: sub csvuploadmap {
1113: my ($request)= @_;
1114: my ($symb,$url)=&get_symb_and_url($request);
1115: if (!$symb) {return '';}
1116: my $datatoken;
1117: if (!$ENV{'form.datatoken'}) {
1118: $datatoken=&Apache::loncommon::upfile_store($request);
1119: } else {
1120: $datatoken=$ENV{'form.datatoken'};
1121: &Apache::loncommon::load_tmp_file($request);
1122: }
1123: my @records=&Apache::loncommon::upfile_record_sep();
1124: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
1125: my $i;
1126: my $keyfields;
1127: if (@records) {
1128: my @fields=&csvupload_fields($url);
1129: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1130: &Apache::loncommon::csv_print_samples($request,\@records);
1131: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
1132: \@fields);
1133: foreach (@fields) { $keyfields.=$_->[0].','; }
1134: chop($keyfields);
1135: } else {
1136: unshift(@fields,['none','']);
1137: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
1138: \@fields);
1139: my %sone=&Apache::loncommon::record_sep($records[0]);
1140: $keyfields=join(',',sort(keys(%sone)));
1141: }
1142: }
1143: &csvuploadmap_footer($request,$i,$keyfields);
1144: return '';
1.27 albertel 1145: }
1146:
1147: sub csvuploadassign {
1148: my ($request)= @_;
1149: my ($symb,$url)=&get_symb_and_url($request);
1150: if (!$symb) {return '';}
1151: &Apache::loncommon::load_tmp_file($request);
1152: my @gradedata=&Apache::loncommon::upfile_record_sep();
1153: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1154: my %fields=();
1155: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1156: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1157: if ($ENV{'form.f'.$i} ne 'none') {
1158: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
1159: }
1160: } else {
1161: if ($ENV{'form.f'.$i} ne 'none') {
1162: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1163: }
1164: }
1165: }
1166: $request->print('<h3>Assigning Grades</h3>');
1167: my $courseid=$ENV{'request.course.id'};
1.34 ng 1168: # my $cdom=$ENV{"course.$courseid.domain"};
1169: # my $cnum=$ENV{"course.$courseid.num"};
1170: my ($classlist) = &getclasslist('all','1');
1.29 albertel 1171: my @skipped;
1172: my $countdone=0;
1173: foreach my $grade (@gradedata) {
1174: my %entries=&Apache::loncommon::record_sep($grade);
1175: my $username=$entries{$fields{'username'}};
1176: my $domain=$entries{$fields{'domain'}};
1.34 ng 1177: if (!exists($$classlist{"$username:$domain"})) {
1.29 albertel 1178: push(@skipped,"$username:$domain");
1179: next;
1.27 albertel 1180: }
1.29 albertel 1181: my %grades;
1182: foreach my $dest (keys(%fields)) {
1183: if ($dest eq 'username' || $dest eq 'domain') { next; }
1184: if ($entries{$fields{$dest}} eq '') { next; }
1185: my $store_key=$dest;
1186: $store_key=~s/^stores/resource/;
1187: $store_key=~s/_/\./g;
1188: $grades{$store_key}=$entries{$fields{$dest}};
1189: }
1190: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
1191: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
1192: $domain,$username);
1193: $request->print('.');
1194: $request->rflush();
1195: $countdone++;
1196: }
1197: $request->print("<br />Stored $countdone students\n");
1198: if (@skipped) {
1199: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
1200: foreach my $student (@skipped) { $request->print("<br />$student"); }
1.27 albertel 1201: }
1.29 albertel 1202: $request->print(&view_edit_entire_class_form($symb,$url));
1203: $request->print(&show_grading_menu_form($symb,$url));
1204: return '';
1.26 albertel 1205: }
1206:
1.2 albertel 1207: sub send_header {
1.13 albertel 1208: my ($request)= @_;
1209: $request->print(&Apache::lontexconvert::header());
1.6 albertel 1210: # $request->print("
1211: #<script>
1212: #remotewindow=open('','homeworkremote');
1213: #remotewindow.close();
1214: #</script>");
1.13 albertel 1215: $request->print('<body bgcolor="#FFFFFF">');
1.2 albertel 1216: }
1217:
1218: sub send_footer {
1.13 albertel 1219: my ($request)= @_;
1.2 albertel 1220: $request->print('</body>');
1221: $request->print(&Apache::lontexconvert::footer());
1222: }
1223:
1.1 albertel 1224: sub handler {
1.13 albertel 1225: my $request=$_[0];
1226:
1227: if ($ENV{'browser.mathml'}) {
1228: $request->content_type('text/xml');
1229: } else {
1230: $request->content_type('text/html');
1231: }
1232: $request->send_http_header;
1233: return OK if $request->header_only;
1.16 albertel 1234: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.13 albertel 1235: my $url=$ENV{'form.url'};
1236: my $symb=$ENV{'form.symb'};
1237: my $command=$ENV{'form.command'};
1.16 albertel 1238: if (!$url) {
1239: my ($temp1,$temp2);
1240: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
1241: $url = $ENV{'form.url'};
1242: }
1.13 albertel 1243: &send_header($request);
1244: if ($url eq '' && $symb eq '') {
1.14 www 1245: if ($ENV{'user.adv'}) {
1246: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
1247: ($ENV{'form.codethree'})) {
1248: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
1249: $ENV{'form.codethree'};
1250: my ($tsymb,$tuname,$tudom,$tcrsid)=
1251: &Apache::lonnet::checkin($token);
1252: if ($tsymb) {
1253: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
1254: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1255: $request->print(
1256: &Apache::lonnet::ssi('/res/'.$url,
1257: ('grade_username' => $tuname,
1258: 'grade_domain' => $tudom,
1259: 'grade_courseid' => $tcrsid,
1260: 'grade_symb' => $tsymb)));
1261: } else {
1262: $request->print('<h1>Not authorized: '.$token.'</h1>');
1263: }
1264: } else {
1265: $request->print('<h1>Not a valid DocID: '.$token.'</h1>');
1266: }
1267: } else {
1268: $request->print(&Apache::lonxml::tokeninputfield());
1269: }
1270: }
1.13 albertel 1271: } else {
1.29 albertel 1272: #&Apache::lonhomework::showhashsubset(\%ENV,'^form');
1.13 albertel 1273: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
1274: if ($command eq 'submission') {
1.20 albertel 1275: &listStudents($request) if ($ENV{'form.student'} eq '');
1.34 ng 1276: &submission($request,0,0) if ($ENV{'form.student'} ne '');
1277: } elsif ($command eq 'processGroup') {
1278: &processGroup($request);
1.26 albertel 1279: } elsif ($command eq 'gradingmenu') {
1280: $request->print(&gradingmenu($request));
1.13 albertel 1281: } elsif ($command eq 'viewgrades') {
1282: $request->print(&viewgrades($request));
1.33 ng 1283: } elsif ($command eq 'handgrade') {
1284: $request->print(&processHandGrade($request));
1.13 albertel 1285: } elsif ($command eq 'editgrades') {
1286: $request->print(&editgrades($request));
1.23 www 1287: } elsif ($command eq 'verify') {
1288: $request->print(&verifyreceipt($request));
1.26 albertel 1289: } elsif ($command eq 'csvupload') {
1290: $request->print(&csvupload($request));
1291: } elsif ($command eq 'csvuploadmap') {
1292: $request->print(&csvuploadmap($request));
1.34 ng 1293: # } elsif ($command eq 'receiptInput') {
1294: # &receiptInput($request);
1.26 albertel 1295: } elsif ($command eq 'csvuploadassign') {
1296: if ($ENV{'form.associate'} ne 'Reverse Association') {
1297: $request->print(&csvuploadassign($request));
1298: } else {
1299: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
1300: $ENV{'form.upfile_associate'} = 'reverse';
1301: } else {
1302: $ENV{'form.upfile_associate'} = 'forward';
1303: }
1304: $request->print(&csvuploadmap($request));
1305: }
1.12 harris41 1306: } else {
1.23 www 1307: $request->print("Unknown action: $command:");
1.2 albertel 1308: }
1.13 albertel 1309: }
1310: &send_footer($request);
1311: return OK;
1.1 albertel 1312: }
1313:
1314: 1;
1315:
1.13 albertel 1316: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>