Annotation of loncom/homework/grades.pm, revision 1.37
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.37 ! ng 4: # $Id: grades.pm,v 1.36 2002/07/07 20:08:45 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
1.37 ! ng 139: <input type="radio" name="vProb" value="yes"> yes <br />
! 140: <b>Submissions: </b>
! 141: <input type="radio" name="lastSub" value="lastonly" checked> last sub only
! 142: <input type="radio" name="lastSub" value="last"> last sub & parts info
! 143: <input type="radio" name="lastSub" value="all"> all details
1.34 ng 144: <input type="hidden" name="section" value="$getsec">
145: <input type="hidden" name="submitonly" value="$submitonly">
1.35 ng 146: <input type="hidden" name="response" value="$ENV{'form.response'}">
147: <input type="hidden" name="handgrade" value="$ENV{'form.handgrade'}">
1.32 ng 148: <table border="0"><tr><td bgcolor="#777777">
1.34 ng 149: <table border="0"><tr bgcolor="#e6ffff">
150: <td><b> Select </b></td><td><b> Username </b></td>
151: <td><b> Fullname </b></td><td><b> Domain </b></td>
152: <td><b> Grade Status </b></td></tr>
1.23 www 153: ENDTABLEST
1.34 ng 154: if ($ENV{'form.url'}) {
155: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
156: }
157: if ($ENV{'form.symb'}) {
158: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
159: }
160: $request->print('<input type="hidden" name="command" value="processGroup" />'."\n");
161:
162: my ($classlist) = &getclasslist($getsec,'0');
163: foreach my $student ( sort(@{ $$classlist{$getsec} }) ) {
1.13 albertel 164: my ($sname,$sdom) = split(/:/,$student);
1.34 ng 165: my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);
166: next if ($status eq 'nothing' && $submitonly eq 'yes');
1.13 albertel 167:
1.34 ng 168: my $fullname = &get_fullname($sname,$sdom);
1.13 albertel 169: if ( $Apache::grades::viewgrades eq 'F' ) {
1.34 ng 170: $request->print("\n".'<tr bgcolor="#ffffe6">'.
171: '<td align="center"><input type=checkbox name="stuinfo" value="'.
172: $student.':'.$fullname.'"></td>'."\n".
173: '<td> '.$sname.' </td>'."\n".
174: '<td> '.$fullname.' </td>'."\n".
175: '<td align="middle"> '.$sdom.' </td>'."\n");
176: $request->print('<td align="middle"> '.$status.' </td>'."\n");
177:
178: $request->print('</tr>');
1.13 albertel 179: }
180: }
1.28 ng 181: $request->print('</table></td></tr></table>');
1.34 ng 182: $request->print('<input type="submit" name="submit" value="View/Grade" /><form />');
1.10 ng 183: }
184:
1.34 ng 185: sub processGroup {
186: my ($request) = shift;
187: my $ctr = 0;
188: my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
1.35 ng 189: : ($ENV{'form.stuinfo'}));
1.34 ng 190: my $total = scalar(@stuchecked)-1;
1.35 ng 191: if ($stuchecked[0] eq '') {
192: &userError($request,'No student was selected for viewing/grading.');
193: return;
194: }
195: foreach (@stuchecked) {
196: my ($sname,$sdom,$fullname) = split(/:/);
1.34 ng 197: $ENV{'form.student'} = $sname;
198: $ENV{'form.fullname'} = $fullname;
199: &submission($request,$ctr,$total);
200: $ctr++;
201: }
1.35 ng 202: return 'The End';
203: }
1.34 ng 204:
1.35 ng 205: sub userError {
206: my ($request, $reason, $step) = @_;
207: $request->print('<h3><font color="red">LON-CAPA User Error</font></h3><br />'."\n");
208: $request->print('<b>Reason: </b>'.$reason.'<br /><br />'."\n");
209: $request->print('<b>Step: </b>'.($step ne '' ? $step : 'Use your browser back button to correct')
210: .'<br /><br />'."\n");
211: return '';
1.34 ng 212: }
1.13 albertel 213:
1.7 albertel 214: #FIXME - needs to handle multiple matches
1.2 albertel 215: sub finduser {
1.13 albertel 216: my ($name) = @_;
217: my $domain = '';
218: if ( $Apache::grades::viewgrades eq 'F' ) {
1.34 ng 219: my ($classlist) = &getclasslist('all','0');
1.35 ng 220: foreach ( sort(@{ $$classlist{'all'} }) ) {
221: my ($posname,$posdomain) = split(/:/);
1.13 albertel 222: if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
1.7 albertel 223: }
1.13 albertel 224: return ($name,$domain);
225: } else {
226: return ($ENV{'user.name'},$ENV{'user.domain'});
227: }
1.5 albertel 228: }
229:
230: sub getclasslist {
1.34 ng 231: my ($getsec,$hideexpired) = @_;
232: my ($coursedomain,$coursenum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 233: my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
1.13 albertel 234: my $now = time;
1.34 ng 235: my (@holdsec,@sections);
1.24 albertel 236: foreach my $student (keys(%classlist)) {
237: my ($end,$start)=split(/:/,$classlist{$student});
1.13 albertel 238: # still a student?
239: if (($hideexpired) && ($end) && ($end < $now)) {
240: next;
241: }
1.34 ng 242: my ($unam,$udom) = split(/:/,$student,2);
243: my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
1.35 ng 244: $section = ($section ne '-1' ? $section : 'no');
1.34 ng 245: push @holdsec,$section;
1.35 ng 246: push (@{ $classlist{$getsec} }, $student) if ($getsec eq 'all' || $getsec eq $section);
1.34 ng 247: }
248: my %seen = ();
249: foreach my $item (@holdsec) {
250: push (@sections, $item) unless $seen{$item}++;
1.13 albertel 251: }
1.34 ng 252: return (\%classlist,\@sections);
1.5 albertel 253: }
254:
255: sub getpartlist {
1.13 albertel 256: my ($url) = @_;
257: my @parts =();
258: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
259: foreach my $key (@metakeys) {
1.30 ng 260: if ( $key =~ m/stores_([0-9]+)_.*/) {
1.13 albertel 261: push(@parts,$key);
1.6 albertel 262: }
1.13 albertel 263: }
264: return @parts;
1.5 albertel 265: }
266:
267: sub viewstudentgrade {
1.13 albertel 268: my ($url,$symb,$courseid,$student,@parts) = @_;
269: my $result ='';
270: my $cellclr = '"#ffffdd"';
1.28 ng 271: my ($username,$domain) = split(/:/,$student);
1.13 albertel 272:
1.34 ng 273: my $fullname = &get_fullname($username,$domain);
1.28 ng 274: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username);
1.32 ng 275:
1.28 ng 276: $result.="<tr bgcolor=$cellclr><td>$username</td><td>$fullname</td><td align=\"middle\">$domain</td>\n";
1.13 albertel 277: foreach my $part (@parts) {
278: my ($temp,$part,$type)=split(/_/,$part);
1.31 ng 279: my $score=$record{"resource.$part.$type"};
280: if ($type eq 'awarded' || $type eq 'tries') {
281: $result.='<td align="middle"><input type="text" name="GRADE.'.$student.'.'.$part.'.'.$type.
282: '" value="'.$score.'" size="4" /></td>'."\n";
1.13 albertel 283: } elsif ($type eq 'solved') {
1.31 ng 284: my ($status,$foo)=split(/_/,$score,2);
1.28 ng 285: $result.="<td align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";
1.31 ng 286: my $optsel = '<option>correct</option><option>incorrect</option><option>excused</option>'.
1.33 ng 287: '<option>ungraded</option><option>partial</option><option>nothing</option>'."\n";
1.31 ng 288: $status = 'nothing' if ($status eq '');
289: $optsel =~ s/<option>$status/<option selected="on">$status/;
290: $result.=$optsel;
1.13 albertel 291: $result.="</select></td>\n";
292: }
293: }
1.29 albertel 294: $result.='<td></td></tr>';
1.13 albertel 295: return $result;
1.5 albertel 296: }
1.31 ng 297:
298: #FIXME need to look at the metadata <stores> spec on what type of data to accept and provide an
1.6 albertel 299: #interface based on that, also do that to above function.
1.5 albertel 300: sub setstudentgrade {
1.13 albertel 301: my ($url,$symb,$courseid,$student,@parts) = @_;
1.34 ng 302: print "set student grade parts=@parts<br>";
1.13 albertel 303: my $result ='';
304: my ($stuname,$domain) = split(/:/,$student);
305: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
306: my %newrecord;
307:
308: foreach my $part (@parts) {
309: my ($temp,$part,$type)=split(/_/,$part);
310: my $oldscore=$record{"resource.$part.$type"};
311: my $newscore=$ENV{"form.GRADE.$student.$part.$type"};
1.32 ng 312: print "old=$oldscore:new=$newscore:<br>";
1.13 albertel 313: if ($type eq 'solved') {
314: my $update=0;
315: if ($newscore eq 'nothing' ) {
316: if ($oldscore ne '') {
317: $update=1;
318: $newscore = '';
1.6 albertel 319: }
1.13 albertel 320: } elsif ($oldscore !~ m/^$newscore/) {
321: $update=1;
322: $result.="Updating $stuname to $newscore<br />\n";
1.34 ng 323: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
1.13 albertel 324: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
1.34 ng 325: if ($newscore eq 'excused') { $newscore = 'excused'; }
326: if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
327: if ($newscore eq 'partial') { $newscore = 'correct_partially_by_override'; }
1.13 albertel 328: } else {
329: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
330: }
331: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
332: } else {
333: if ($oldscore ne $newscore) {
334: $newrecord{"resource.$part.$type"}=$newscore;
335: $result.="Updating $student"."'s status for $part.$type to $newscore<br />\n";
336: } else {
337: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
338: }
339: }
340: }
341: if ( scalar(keys(%newrecord)) > 0 ) {
1.32 ng 342: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.34 ng 343: # &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
1.13 albertel 344:
345: $result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
346: }
347: return $result;
1.2 albertel 348: }
349:
1.33 ng 350: #
1.32 ng 351: # --------------------------- show submissions of a student, option to grade --------
1.2 albertel 352: sub submission {
1.34 ng 353: my ($request,$counter,$total) = @_;
1.33 ng 354:
1.34 ng 355: if ($counter == 0) {
1.36 ng 356: $request->print(<<SUBJAVASCRIPT);
1.32 ng 357: <script type="text/javascript" language="javascript">
1.33 ng 358: function updateRadio(radioButton,formtextbox,formsel,wgt) {
359: var pts = formtextbox.value;
360: var resetbox =false;
361: if (isNaN(pts) || pts < 0) {
362: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
363: for (var i=0; i<radioButton.length; i++) {
364: if (radioButton[i].checked) {
365: formtextbox.value = i;
366: resetbox = true;
367: }
1.32 ng 368: }
1.33 ng 369: if (!resetbox) {
370: formtextbox.value = "";
371: }
372: return;
373: }
1.32 ng 374:
1.33 ng 375: for (var i=0; i<radioButton.length; i++) {
376: radioButton[i].checked=false;
377: if (pts == i) {
378: radioButton[i].checked=true;
1.32 ng 379: }
1.31 ng 380: }
1.33 ng 381: updateSelect(formsel,pts,wgt);
382: }
383:
384: function writeBox(formrad,formsel,pts,wgt) {
385: formrad.value = pts;
386: updateSelect(formsel,pts,wgt);
387: return;
388: }
389:
390: function updateSelect(formsel,pts,wgt) {
391: if (pts == 0) {
392: formsel[1].selected = true;
393: }
394: if (pts > 0 && pts < wgt) {
395: formsel[4].selected = true;
396: }
397: if (pts == wgt) {
398: formsel[0].selected = true;
399: }
400: return;
401: }
1.32 ng 402:
1.35 ng 403: function keywords(keyform) {
404: var keywds = keyform.value;
1.36 ng 405: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
1.35 ng 406: if (nret==null) return;
407: keyform.value = nret;
408: return;
409: }
410:
1.36 ng 411: //===================== Script to add keyword(s) ==================
412: function getSel() {
413: if (document.getSelection) txt = document.getSelection();
414: else if (document.selection) txt = document.selection.createRange().text;
415: else return;
416: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
417: if (cleantxt=="") {
418: alert("Select a word or group of words from document and then click this link.");
419: return;
420: }
421: var nret = prompt("Add selection to keyword list?",cleantxt);
1.35 ng 422: if (nret==null) return;
1.36 ng 423: var curlist = document.SCORE.keywords.value;
424: document.SCORE.keywords.value = curlist+" "+nret;
425: return;
426: }
427:
428: //====================== Script for composing message ==============
429: function msgCenter(msgform,usrctr,fullname) {
430: var Nmsg = msgform.savemsgN.value;
431: savedMsgHeader(Nmsg,usrctr,fullname);
432: var subject = msgform.msgsub.value;
1.37 ! ng 433: var rtrchk = eval("document.SCORE.includemsg"+usrctr);
! 434: var msgchk = rtrchk.value;
! 435: // alert("checked=>"+msgchk);
! 436: re = /msgsub/;
! 437: var shwsel = "";
! 438: if (re.test(msgchk)) { shwsel = "checked" }
! 439: displaySubject(subject,shwsel);
1.36 ng 440: for (var i=1; i<=Nmsg; i++) {
1.37 ! ng 441: var testpt = "savemsg"+i+",";
! 442: re = /testpt/;
! 443: shwsel = "";
! 444: if (re.test(msgchk)) { shwsel = "checked" }
1.36 ng 445: var message = eval("document.SCORE.savemsg"+i+".value");
1.37 ! ng 446: displaySavedMsg(i,message,shwsel);
1.36 ng 447: }
448: newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
1.37 ! ng 449: shwsel = "";
! 450: re = /newmsg/;
! 451: if (re.test(msgchk)) { shwsel = "checked" }
! 452: newMsg(newmsg,shwsel);
1.36 ng 453: msgTail();
1.35 ng 454: return;
455: }
456:
1.36 ng 457: function savedMsgHeader(Nmsg,usrctr,fullname) {
458: var height = 30*Nmsg+250;
459: var scrollbar = "no";
460: if (height > 600) {
461: height = 600;
462: scrollbar = "yes";
463: }
1.37 ! ng 464: /* if (window.pWin)
! 465: window.pWin.close(); */
1.36 ng 466: pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',width=600,height='+height);
467: pWin.document.write("<html><head>");
468: pWin.document.write("<title>Message Central</title>");
469:
470: pWin.document.write("<script language=javascript>");
471: pWin.document.write("function checkInput() {");
472: pWin.document.write(" opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
473: pWin.document.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
474: pWin.document.write(" var usrctr = document.msgcenter.usrctr.value;");
475: pWin.document.write(" var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
476: pWin.document.write(" newval.value = document.msgcenter.newmsg.value;");
477:
478: pWin.document.write(" var msgchk = \\"\\";");
479: pWin.document.write(" if (document.msgcenter.subchk.checked) {");
1.37 ! ng 480: pWin.document.write(" msgchk = \\"msgsub,\\";");
1.36 ng 481: pWin.document.write(" }");
482: pWin.document.write( "for (var i=1; i<=nmsg; i++) {");
483: pWin.document.write(" var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
484: pWin.document.write(" var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
485: pWin.document.write(" opnmsg.value = frmmsg.value;");
486: pWin.document.write(" var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
487: pWin.document.write(" if (chkbox.checked) {");
1.37 ! ng 488: pWin.document.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
1.36 ng 489: pWin.document.write(" }");
490: pWin.document.write(" }");
491: pWin.document.write(" if (document.msgcenter.newmsgchk.checked) {");
1.37 ! ng 492: pWin.document.write(" msgchk += \\"newmsg\\"+usrctr;");
1.36 ng 493: pWin.document.write(" }");
494: pWin.document.write(" var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
495: pWin.document.write(" includemsg.value = msgchk;");
496:
1.37 ! ng 497: // pWin.document.write(" alert(\\"slected=\\"+msgchk)");
1.36 ng 498: pWin.document.write(" self.close()");
499:
500: pWin.document.write("}");
501:
502: pWin.document.write("<");
503: pWin.document.write("/script>");
504:
505: pWin.document.write("</head><body bgcolor=white>");
506:
507: pWin.document.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
508: pWin.document.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
509: pWin.document.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br><br>");
510:
511: pWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
512: pWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
513: pWin.document.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
514: }
1.37 ! ng 515: function displaySubject(msg,shwsel) {
1.36 ng 516: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
517: pWin.document.write("<td>Subject</td>");
1.37 ! ng 518: pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.36 ng 519: pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+" \\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
520: }
521:
1.37 ! ng 522: function displaySavedMsg(ctr,msg,shwsel) {
1.36 ng 523: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
524: pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
1.37 ! ng 525: pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.36 ng 526: pWin.document.write("<td><input name=\\"msg"+ctr+"\\" type=\\"text\\" value=\\""+msg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
527: }
528:
1.37 ! ng 529: function newMsg(newmsg,shwsel) {
1.36 ng 530: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
531: pWin.document.write("<td align=\\"center\\">New</td>");
1.37 ! ng 532: pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.36 ng 533: pWin.document.write("<td><input name=\\"newmsg\\" type=\\"text\\" value=\\""+newmsg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
534: }
535:
536: function msgTail() {
537: pWin.document.write("</table>");
538: pWin.document.write("</td></tr></table> ");
539: pWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
540: pWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
541: pWin.document.write("</form>");
542: pWin.document.write("</body></html>");
543: }
544:
545: //====================== Script for keyword highlight options ==============
546: function kwhighlight() {
547: var kwclr = document.SCORE.kwclr.value;
548: var kwsize = document.SCORE.kwsize.value;
549: var kwstyle = document.SCORE.kwstyle.value;
550: var redsel = "";
551: var grnsel = "";
552: var blusel = "";
553: if (kwclr=="red") {var redsel="checked"};
554: if (kwclr=="green") {var grnsel="checked"};
555: if (kwclr=="blue") {var blusel="checked"};
556: var sznsel = "";
557: var sz1sel = "";
558: var sz2sel = "";
559: if (kwsize=="0") {var sznsel="checked"};
560: if (kwsize=="+1") {var sz1sel="checked"};
561: if (kwsize=="+2") {var sz2sel="checked"};
562: var synsel = "";
563: var syisel = "";
564: var sybsel = "";
565: if (kwstyle=="") {var synsel="checked"};
566: if (kwstyle=="<i>") {var syisel="checked"};
567: if (kwstyle=="<b>") {var sybsel="checked"};
568: highlightCentral();
569: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
570: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
571: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
572: highlightend();
1.35 ng 573: return;
574: }
575:
1.36 ng 576:
577: function highlightCentral() {
578: hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300');
579: hwdWin.document.write("<html><head>");
580: hwdWin.document.write("<title>Highlight Central</title>");
581:
582: hwdWin.document.write("<script language=javascript>");
583: hwdWin.document.write("function updateChoice() {");
584: hwdWin.document.write(" opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
585: hwdWin.document.write(" opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
586: hwdWin.document.write(" opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
587: hwdWin.document.write(" self.close()");
588: hwdWin.document.write("}");
589:
590: hwdWin.document.write("function radioSelection(radioButton) {");
591: hwdWin.document.write(" var selection=null;");
592: hwdWin.document.write(" for (var i=0; i<radioButton.length; i++) {");
593: hwdWin.document.write(" if (radioButton[i].checked) {");
594: hwdWin.document.write(" selection=radioButton[i].value;");
595: hwdWin.document.write(" return selection;");
596: hwdWin.document.write(" }");
597: hwdWin.document.write(" }");
598: hwdWin.document.write("}");
599:
600: hwdWin.document.write("<");
601: hwdWin.document.write("/script>");
602:
603: hwdWin.document.write("</head><body bgcolor=white>");
604:
605: hwdWin.document.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
606: hwdWin.document.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br><br>");
607:
608: hwdWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
609: hwdWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
610: hwdWin.document.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
611: }
612:
613: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
614: hwdWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
615: hwdWin.document.write("<td align=\\"left\\">");
616: hwdWin.document.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
617: hwdWin.document.write("<td align=\\"left\\">");
618: hwdWin.document.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
619: hwdWin.document.write("<td align=\\"left\\">");
620: hwdWin.document.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
621: hwdWin.document.write("</tr>");
622: }
623:
624: function highlightend() {
625: hwdWin.document.write("</table>");
626: hwdWin.document.write("</td></tr></table> ");
627: hwdWin.document.write("<input type=\\"button\\" value=\\"Set Options\\" onClick=\\"javascript:updateChoice()\\"> ");
628: hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
629: hwdWin.document.write("</form>");
630: hwdWin.document.write("</body></html>");
631: }
632:
1.31 ng 633: </script>
1.36 ng 634: SUBJAVASCRIPT
1.34 ng 635: }
1.33 ng 636: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.35 ng 637: if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
1.13 albertel 638: my ($uname,$udom) = &finduser($ENV{'form.student'});
1.35 ng 639: if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
1.32 ng 640:
641: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.13 albertel 642: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.34 ng 643: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
1.37 ! ng 644:
! 645: # header info
1.34 ng 646: if ($counter == 0) {
1.36 ng 647: $request->print('<h2> <font color="#339933">Submission Record</font></h2>'.
648: '<font size=+1> <b>Resource: </b>'.$url.'</font>');
1.34 ng 649: }
650:
1.37 ! ng 651: # option to display problem, only once else it cause problems with the form later since the problem has a form.
1.34 ng 652: if ($ENV{'form.vProb'} eq 'yes' && $counter == 0) {
1.30 ng 653: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.17 albertel 654: $ENV{'request.course.id'});
1.30 ng 655: my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
656: $ENV{'request.course.id'});
1.34 ng 657: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.33 ng 658: $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
1.31 ng 659: $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1.30 ng 660: $result.='<b>Correct answer:</b><br />'.$companswer;
661: $result.='</td></tr></table>';
662: $result.='</td></tr></table><br />';
1.34 ng 663: $request->print($result);
664: }
1.37 ! ng 665:
! 666: # beginning of form
1.34 ng 667: if ($counter == 0) {
1.37 ! ng 668: my %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.35 ng 669: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
670: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
671:
1.37 ! ng 672: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
! 673: # if the handgrade db has never being initialized then set some default values
! 674: if ($keyhash{$symb.'_handgrade'} eq '') {
! 675: $keyhash{$symb.'_keywords'} = '';
! 676: $keyhash{$symb.'_subject'} = &Apache::lonnet::metadata($url,'title');
! 677: $keyhash{$loginuser.'_kwclr'} = $keyhash{$loginuser.'_kwclr'} eq '' ? 'red' : $keyhash{$loginuser.'_kwclr'};
! 678: $keyhash{$loginuser.'_kwsize'} = $keyhash{$loginuser.'_kwsize'} eq '' ? '0' : $keyhash{$loginuser.'_kwsize'};
! 679: $keyhash{$loginuser.'_kwstyle'} = $keyhash{$loginuser.'_kwstyle'} eq '' ? '' : $keyhash{$loginuser.'_kwstyle'};
! 680: $keyhash{$symb.'_savemsgN'} = '0';
! 681: }
1.34 ng 682: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
1.35 ng 683: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
684: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
685: '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
1.37 ! ng 686: '<input type="hidden" name="lastSub" value="'.$ENV{'form.lastSub'}.'" />'."\n".
1.35 ng 687: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
1.34 ng 688: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
1.35 ng 689: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'">'."\n".
690: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'">'."\n".
691: '<input type="hidden" name="command" value="handgrade" />'."\n".
692: '<input type="hidden" name="keywords" value="'.$keyhash{$symb.'_keywords'}.'" />'."\n".
1.37 ! ng 693: '<input type="hidden" name="kwclr" value="'.$keyhash{$loginuser.'_kwclr'}.'" />'."\n".
! 694: '<input type="hidden" name="kwsize" value="'.$keyhash{$loginuser.'_kwsize'}.'" />'."\n".
! 695: '<input type="hidden" name="kwstyle" value="'.$keyhash{$loginuser.'_kwstyle'}.'" />'."\n".
! 696: '<input type="hidden" name="msgsub" value="'.$keyhash{$symb.'_subject'}.'" />'."\n".
! 697: '<input type="hidden" name="savemsgN" value="'.$keyhash{$symb.'_savemsgN'}.'" />'."\n".
1.34 ng 698: '<input type="hidden" name="NCT"'.
1.37 ! ng 699: ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
! 700:
! 701: my ($cts,$prnmsg) = (1,'');
! 702: while ($cts <= $keyhash{$symb.'_savemsgN'}) {
! 703: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.$keyhash{$symb.'_savemsg'.$cts}.'" />'."\n";
! 704: $cts++;
! 705: }
! 706: $request->print($prnmsg);
1.35 ng 707:
708: if ($ENV{'form.handgrade'} eq 'yes') {
709: $request->print(<<KEYWORDS);
1.36 ng 710: <b>Keyword Options</b>
711: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>Keyword List</a>
712: <a href="#" onMouseDown="javascript:getSel(); return false"
1.37 ! ng 713: CLASS="page">Paste Selection to Keyword list</a>
1.36 ng 714: <a href="javascript:kwhighlight()"; TARGET=_self>Keyword Highlight Attribute</a><br /><br />
1.35 ng 715: KEYWORDS
716: }
1.30 ng 717: }
1.35 ng 718:
1.37 ! ng 719: # Student info
1.34 ng 720: $request->print(($counter == 0 ? '' : '<br /><hr><br />'));
1.36 ng 721: my $fullname = ($ENV{'form.fullname'} ne '' ? $ENV{'form.fullname'} : &get_fullname($uname,$udom));
1.34 ng 722: my $result.='<table border="0"><tr><td><b>Username: </b>'.$uname.
1.36 ng 723: '</td><td><b>Fullname: </b>'.$fullname.
1.34 ng 724: '</td><td><b>Domain: </b>'.$udom.'</td></tr>';
1.35 ng 725: if ($ENV{'form.handgrade'} eq 'yes') {
1.37 ! ng 726: # my $subonly = &get_last_submission($symb,$uname,$udom,$ENV{'request.course.id'});
1.35 ng 727: my ($classlist) = &getclasslist('all','0');
728: my @collaborators;
1.37 ! ng 729: # foreach ( sort(@{ $$classlist{'all'} }) ) {
! 730: # my ($sname,$sdom) = split(/:/);
! 731: # push @collaborators,$sname if (grep /\b$sname(\b|\.)/i,$subonly);
! 732: # }
! 733: # push @collaborators,'leede','carlandmm','freyniks'; # as a test to display collaborators.
1.35 ng 734: if (scalar(@collaborators) != 0) {
735: $result.='<tr><td colspan=3><b>Collaborators: </b>';
736: foreach (@collaborators) {
737: $result.=$_.' ('.&get_fullname($_,$udom).') ';
738: }
739: $result.='</td></tr>'."\n";
740: $result.='<input type="hidden" name="collaborator'.$counter.
741: '" value="'.(join ':',@collaborators).'" />'."\n";
742: }
743: }
1.36 ng 744: $result.='</table>'."\n";
1.34 ng 745: $request->print($result);
1.37 ! ng 746:
! 747: # print student answer
! 748: if ($ENV{'form.lastSub'} eq 'lastonly') {
! 749: my ($string,$timestamp)=&get_last_submission ($symb,$uname,$udom,$ENV{'request.course.id'});
! 750: $string=&keywords_highlight($string);
! 751: my $lastsubonly='<table border="0" width=100%><tr><td bgcolor="#777777">';
! 752: $lastsubonly.='<table border="0" width=100%><tr bgcolor="#e6ffff">';
! 753: $lastsubonly.='<td><b>Last Submission Only</b>'.
! 754: ($timestamp eq '' ? '' : ' <b>Date Submitted:</b> '.$timestamp).'</td></tr>';
! 755: $lastsubonly.='<tr><td bgcolor="#ffffe6">';
! 756: $lastsubonly.=$string;
! 757: $lastsubonly.='</td></tr></table></td></tr></table>'."\n";
! 758: $request->print($lastsubonly);
! 759: } else {
! 760: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
! 761: $ENV{'request.course.id'},$last,
! 762: '.submission','Apache::grades::keywords_highlight'));
! 763: }
! 764:
1.34 ng 765: my $wgt = &Apache::lonnet::EXT('resource.partid.weight',$symb,$udom,$uname);
766: my $wgtmsg = ($wgt > 0 ? '(problem weight)' : '<font color="red">problem weight assigned by computer</font>');
767: $wgt = ($wgt > 0 ? $wgt : '1');
768: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
769: my $score = ($record{'resource.0.awarded'} eq '' ? '' : $record{'resource.0.awarded'}*$wgt);
1.18 albertel 770:
1.37 ! ng 771: # display grading options
1.34 ng 772: $result='<input type="hidden" name="WGT'.$counter.'" value="'.$wgt.'" />'.
1.33 ng 773: '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'.$udom.'" />'."\n";
1.37 ! ng 774: $result.='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
! 775: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n";
1.32 ng 776: $result.='<table border="0"><tr><td><b>Points</b></td><td>';
1.37 ! ng 777:
1.31 ng 778: my $ctr = 0;
1.34 ng 779: $result.='<table border="0"><tr>'; # display radio buttons in a nice table with 10 across
1.32 ng 780: while ($ctr<=$wgt) {
1.34 ng 781: $result.= '<td><input type="radio" name="RADVAL'.$counter.'" '.
1.33 ng 782: 'onclick="javascript:writeBox(this.form.GRADE_BOX'.$counter.
1.34 ng 783: ',this.form.GRADE_SEL'.$counter.','.$ctr.','.$wgt.')" '.
784: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
785: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.31 ng 786: $ctr++;
787: }
1.34 ng 788: $result.='</tr></table>';
789:
1.31 ng 790: $result.='</td><td> <b>or</b> </td>';
1.33 ng 791: $result.='<td><input type="text" name="GRADE_BOX'.$counter.'"'.
1.32 ng 792: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.33 ng 793: 'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.
794: ',this.form.GRADE_BOX'.$counter.
795: ',this.form.GRADE_SEL'.$counter.',\''.$wgt.'\')" /></td>'."\n";
1.34 ng 796: $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
1.33 ng 797:
798: foreach my $part (&getpartlist($url)) {
799: my ($temp,$part,$type)=split(/_/,$part);
800: if ($type eq 'solved') {
801: my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
1.34 ng 802: $status = 'partial' if ($foo =~ /partially/);
803: $status = 'nothing' if ($status eq '');
1.33 ng 804: $result.='<select name="GRADE_SEL'.$counter.'">'."\n";
805: my $optsel = '<option>correct</option><option>incorrect</option>'.
806: '<option>excused</option><option>ungraded</option>'.
807: '<option>partial</option><option>nothing</option>'."\n";
808: $optsel =~ s/<option>$status/<option selected="on">$status/;
809: $result.=$optsel;
1.36 ng 810: $result.="</select>  \n";
811: $result.='<a href="javascript:msgCenter(document.SCORE,'.$counter.
812: ',\''.$fullname.'\')"; TARGET=_self>Compose Message</a></td></tr>'."\n";
1.33 ng 813: }
814: }
1.34 ng 815: $result.='</table>';
816: $request->print($result);
1.37 ! ng 817:
! 818: # print end of form
1.34 ng 819: if ($counter == $total) {
820: my $endform.='<table border="0"><tr><td><input type="submit" name="gradeOpt" value="Save & Next" />';
821: my $ntstu ='<select name="NTSTU">'.
822: '<option>1</option><option>2</option>'.
823: '<option>3</option><option>5</option>'.
824: '<option>7</option><option>10</option></select>'."\n";
825: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
826: $ntstu =~ s/<option>$nsel/<option selected="on">$nsel/;
827: $endform.=$ntstu.'student(s) ';
828: $endform.='<input type="submit" name="gradeOpt" value="Next" /> ';
829: $endform.='<input type="submit" name="gradeOpt" value="Previous" /> ';
830: $endform.='(Next and Previous do not save the scores.)';
831: $endform.='</td><tr></table></form>';
832: $request->print($endform);
833: }
834: return '';
1.32 ng 835: }
1.30 ng 836:
1.35 ng 837: sub get_last_submission {
838: my ($symb,$username,$domain,$course)=@_;
839: if ($symb) {
1.37 ! ng 840: my ($string,$timestamp);
1.35 ng 841: my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
842: if ($returnhash{'version'}) {
843: my %lasthash=();
1.37 ! ng 844: my ($version);
1.35 ng 845: for ($version=1;$version<=$returnhash{'version'};$version++) {
846: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
847: $lasthash{$_}=$returnhash{$version.':'.$_};
848: }
849: }
850: foreach ((keys %lasthash)) {
1.37 ! ng 851: if ($_ =~ /\.submission$/) {$string = $lasthash{$_}}
! 852: if ($_ =~ /timestamp/) {$timestamp=scalar(localtime($lasthash{$_}))};
1.35 ng 853: }
854: }
1.37 ! ng 855: $string = $string eq '' ? 'Nothing submitted - no attempts.' : $string;
! 856: return $string,$timestamp;
1.35 ng 857: }
858: }
859:
860: sub keywords_highlight {
861: my $string = shift;
862: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
863: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.37 ! ng 864: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
! 865:
! 866: my @kwkeys = ($symb.'_keywords',
! 867: $loginuser.'_kwclr',
! 868: $loginuser.'_kwsize',
! 869: $loginuser.'_kwstyle'
! 870: );
! 871:
1.35 ng 872: my %keyhash = &Apache::lonnet::get
1.37 ! ng 873: ('nohist_handgrade',\@kwkeys,
1.35 ng 874: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
875: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
876: my @keylist = split(/[,\s+]/,$keyhash{$symb.'_keywords'});
1.37 ! ng 877: my $size = $keyhash{$kwkeys[2]} eq '0' ? '' : 'size='.$keyhash{$kwkeys[2]};
! 878: my $styleon = $keyhash{$kwkeys[3]} eq '' ? '' : $keyhash{$kwkeys[3]};
! 879: (my $styleoff = $styleon) =~ s/\</\<\//;
1.35 ng 880: foreach my $word (@keylist) {
881: next if ($word eq '');
1.37 ! ng 882: $string =~ s/\b$word(\b|\.)/\<font color\=$keyhash{$kwkeys[1]} $size\>$styleon$word$styleoff\<\/font\>/gi;
1.35 ng 883: }
884: return $string;
885: }
886:
1.32 ng 887: sub processHandGrade {
1.34 ng 888: my ($request) = shift;
1.33 ng 889: my $url = $ENV{'form.url'};
890: my $symb = $ENV{'form.symb'};
891: my $button = $ENV{'form.gradeOpt'};
892: my $ngrade = $ENV{'form.NCT'};
893: my $ntstu = $ENV{'form.NTSTU'};
1.37 ! ng 894:
! 895: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
! 896: my %keyhash = ();
! 897: $keyhash{$symb.'_handgrade'} = 'activated';
! 898: $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
! 899: $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
! 900: $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
! 901: $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
! 902: $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
! 903:
! 904: my ($ctr,$idx) = (1,1);
! 905: while ($ctr <= $ENV{'form.savemsgN'}) {
! 906: if ($ENV{'form.savemsg'.$ctr} ne '') {
! 907: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
! 908: $idx++;
! 909: }
! 910: $ctr++;
1.35 ng 911: }
1.37 ! ng 912: $ctr = 0;
! 913: while ($ctr < $ngrade) {
! 914: if ($ENV{'form.newmsg'.$ctr} ne '') {
! 915: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
! 916: $idx++;
! 917: }
! 918: $ctr++;
! 919: }
! 920:
! 921: $keyhash{$symb.'_savemsgN'} = --$idx;
! 922: my $putresult = &Apache::lonnet::put
! 923: ('nohist_handgrade',\%keyhash,
! 924: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
! 925: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
! 926:
1.33 ng 927: my (@parts) = sort(&getpartlist($url));
1.34 ng 928:
1.33 ng 929: if ($button eq 'Save & Next') {
930: my $ctr = 0;
1.37 ! ng 931: while ($ctr < $ngrade) {
1.33 ng 932: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.34 ng 933: &saveHandGrade($url,$symb,$uname,$udom,$ctr,@parts);
1.35 ng 934: if ($ENV{'form.collaborator'.$ctr}) {
935: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
936: foreach (@collaborators) {
937: &saveHandGrade($url,$symb,$_,$udom,$ctr,@parts);
938: }
939: }
1.33 ng 940: $ctr++;
941: }
942: }
943: my $firststu = $ENV{'form.unamedom0'};
944: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
945:
1.35 ng 946: my ($classlist) = &getclasslist($ENV{'form.section'},'0');
1.37 ! ng 947: # print "first=$firststu,last=$laststu<br>";
1.33 ng 948: my (@nextlist,@prevlist);
1.34 ng 949: my ($nextflg,$prevflg,$ctr,$ctprev) = (0,0,0,0);
1.35 ng 950: foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
1.33 ng 951: my ($uname,$udom) = split(/:/,$student);
1.37 ! ng 952: my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname);
! 953: next if ($status eq 'nothing' && $ENV{'form.submitonly'} eq 'yes');
! 954:
1.33 ng 955: if ($nextflg == 1 && $button =~ /Next$/) {
1.34 ng 956: push @nextlist,$uname if ($ctr < $ntstu);
1.33 ng 957: $ctr++;
958: }
959: $nextflg = 1 if ($student eq $laststu);
960: $prevflg = 1 if ($student eq $firststu);
1.34 ng 961: if ($prevflg == 0 && $button eq 'Previous') {
962: push @prevlist,$uname;
963: $ctprev++;
964: }
1.33 ng 965: }
1.37 ! ng 966: # print "next student=@nextlist<br>";
1.34 ng 967: if ($button eq 'Previous') {
968: if ($ctprev <= $ntstu) {
969: @nextlist = @prevlist;
970: } else {
971: my $idx = 0;
972: my $start = $ctprev - $ntstu;
973: while ($idx < $ntstu) {
974: $nextlist[$idx] = $prevlist[$start+$idx];
975: $idx++;
976: }
977: }
978: }
979: $ctr = 0;
980: my $total = scalar(@nextlist)-1;
1.33 ng 981: foreach my $student (@nextlist) {
982: $ENV{'form.student'} = $student;
1.34 ng 983: &submission($request,$ctr,$total);
984: $ctr++;
1.33 ng 985: }
986:
987: return 'The End';
988: }
989:
990: sub saveHandGrade {
1.34 ng 991: my ($url,$symb,$stuname,$domain,$newflg,@parts) = @_;
1.33 ng 992: my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
1.32 ng 993: my %newrecord;
994:
995: foreach my $part (@parts) {
1.31 ng 996: my ($temp,$part,$type)=split(/_/,$part);
1.32 ng 997: my $oldscore=$record{"resource.$part.$type"};
1.34 ng 998: my $newscore;
999: if ($type eq 'awarded' && $newflg >= 0) {
1.35 ng 1000: my $pts = ($ENV{'form.GRADE_BOX'.$newflg} ne '' ?
1001: $ENV{'form.GRADE_BOX'.$newflg} : $ENV{'form.RADVAL'.$newflg});
1.34 ng 1002: my $wgt = $ENV{'form.WGT'.$newflg};
1003: # my $sel = $ENV{'form.GRADE_SEL'.$newflg};
1004: $newscore = $pts/$wgt if ($wgt != 0);
1005: }
1.31 ng 1006: if ($type eq 'solved') {
1.34 ng 1007: $newscore = $ENV{'form.GRADE_SEL'.$newflg} if ($newflg >= 0);
1.32 ng 1008: my $update=0;
1009: if ($newscore eq 'nothing' ) {
1010: if ($oldscore ne '') {
1011: $update=1;
1012: $newscore = '';
1013: }
1014: } elsif ($oldscore !~ m/^$newscore/) {
1015: $update=1;
1016: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
1017: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
1018: if ($newscore eq 'excused') { $newscore = 'excused'; }
1019: if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
1.34 ng 1020: if ($newscore eq 'partial') { $newscore = 'correct_partially_by_override'; }
1.32 ng 1021: }
1022: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
1023: } else {
1024: if ($oldscore ne $newscore) {
1025: $newrecord{"resource.$part.$type"}=$newscore;
1.33 ng 1026: }
1.32 ng 1027: }
1.34 ng 1028: }
1029: if ( scalar(keys(%newrecord)) > 0 ) {
1.33 ng 1030: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.35 ng 1031: # while (my ($k,$v) = each %newrecord) {
1032: # print "k=$k:v=$v:<br>\n";
1033: # }
1034: # print "symb=$symb,courseid=$ENV{'request.course.id'},dom=$domain,name=$stuname<br>";
1.34 ng 1035: # &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
1.31 ng 1036: }
1.34 ng 1037: return '';
1.2 albertel 1038: }
1039:
1.26 albertel 1040: sub get_symb_and_url {
1.34 ng 1041: my ($request) = @_;
1042: (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.32 ng 1043: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.13 albertel 1044: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.34 ng 1045: return ($symb,$url);
1.29 albertel 1046: }
1047:
1048: sub show_grading_menu_form {
1049: my ($symb,$url)=@_;
1050: my $result.='<form action="/adm/grades" method="post">'."\n".
1051: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1052: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1053: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1054: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
1055: '</form>'."\n";
1056: return $result;
1057: }
1058:
1.26 albertel 1059: sub gradingmenu {
1060: my ($request) = @_;
1061: my ($symb,$url)=&get_symb_and_url($request);
1062: if (!$symb) {return '';}
1.35 ng 1063: my $allkeys = &Apache::lonnet::metadata($url,'keys');
1064: my $handgrade = ($allkeys =~ /parameter_.*?_handgrade/ ? 'yes' : 'no');
1065: my ($responsetype,$foo) = split(/_/,&Apache::lonnet::metadata($url,'packages'));
1.28 ng 1066:
1.34 ng 1067: my $result='<h2> <font color="#339933">Select a Grading Method</font></h2>';
1.35 ng 1068: $result.='<table border="0">';
1069: $result.='<tr><td><font size=+1><b>Resource: </b></font></td>'.
1070: '<td><font size=+1>'.$url.'</font></td></tr>';
1071: $result.='<tr><td><font size=+1><b>Type: </b></font></td>'.
1072: '<td><font size=+1>'.$responsetype.' <b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
1073: $result.='</table>';
1.34 ng 1074:
1075: $result.=&view_edit_entire_class_form($symb,$url).'<br />';
1076: $result.=&upcsvScores_form($symb,$url).'<br />';
1.35 ng 1077: $result.=&viewGradeaStu_form($symb,$url,$responsetype,$handgrade).'<br />';
1.34 ng 1078: $result.=&verifyReceipt_form($symb,$url);
1079: return $result;
1080: }
1081:
1082: sub view_edit_entire_class_form {
1083: my ($symb,$url)=@_;
1084: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1085: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1086: $result.=' <b>View/Grade Entire Class</b></td></tr>'."\n";
1.28 ng 1087: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.26 albertel 1088: $result.='<form action="/adm/grades" method="post">'."\n".
1.34 ng 1089: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.26 albertel 1090: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.34 ng 1091: '<input type="hidden" name="command" value="viewgrades" />'."\n";
1092: $result.=' <b>Display students who has: </b>'.
1093: '<input type="radio" name="submitonly" value="yes" checked> submitted'.
1094: '<input type="radio" name="submitonly" value="all"> everybody <br /><br />';
1095: $result.=' <input type="submit" name="submit" value="View/Grade" /></form>'."\n";
1096: $result.='</td></tr></table>'."\n";
1097: $result.='</td></tr></table>'."\n";
1098: return $result;
1099: }
1100:
1101: sub upcsvScores_form {
1102: my ($symb,$url) = @_;
1103: if (!$symb) {return '';}
1104: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1105: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1106: $result.=' <b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
1107: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1108: my $upfile_select=&Apache::loncommon::upfile_select_html();
1109: $result.=<<ENDUPFORM;
1110: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1111: <input type="hidden" name="symb" value="$symb" />
1112: <input type="hidden" name="url" value="$url" />
1113: <input type="hidden" name="command" value="csvuploadmap" />
1114: $upfile_select
1115: <br /> <input type="submit" name="submit" value="Upload Grades" />
1116: </form>
1117: ENDUPFORM
1118: $result.='</td></tr></table>'."\n";
1119: $result.='</td></tr></table>'."\n";
1120: return $result;
1121: }
1122:
1123: sub viewGradeaStu_form {
1.35 ng 1124: my ($symb,$url,$response,$handgrade) = @_;
1.34 ng 1125: my ($classlist,$sections) = &getclasslist('all','0');
1126: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1127: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1128: $result.=' <b>View/Grade an Individual Student\'s Submission</b></td></tr>'."\n";
1129: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.26 albertel 1130: $result.='<form action="/adm/grades" method="post">'."\n".
1131: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1132: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.35 ng 1133: '<input type="hidden" name="response" value="'.$response.'" />'."\n".
1134: '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
1135: '<input type="hidden" name="command" value="submission" />'."\n";
1.34 ng 1136:
1137: $result.=' <b>Select section:</b> <select name="section">'."\n";
1138: foreach my $section (sort (@$sections)) {
1139: $result.= '<option>'.$section.'</option>'."\n";
1140: }
1141: $result.= '<option selected="on">all</select>'."\n";
1142: $result.=' <b>Display students who has: </b>'.
1143: '<input type="radio" name="submitonly" value="yes" checked> submitted'.
1144: '<input type="radio" name="submitonly" value="all"> everybody <br />';
1.35 ng 1145: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
1146: if (grep /no/,@$sections);
1.34 ng 1147:
1148: $result.='<br /> <input type="submit" name="submit" value="View/Grade" />'."\n".
1149: '</form>'."\n";
1150: $result.='</td></tr></table>'."\n";
1151: $result.='</td></tr></table>'."\n";
1152: return $result;
1153: }
1154:
1155: sub verifyReceipt_form {
1156: my ($symb,$url) = @_;
1157: my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
1158: my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
1159: my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
1160:
1161: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1162: $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
1163: $result.=' <b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
1164: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1165: $result.='<form action="/adm/grades" method="post">'."\n";
1166: $result.=' <tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
1167: $result.=' <input type="submit" name="submit" value="Verify Receipt">'."\n";
1168: $result.='<input type="hidden" name="command" value="verify">'."\n";
1169: if ($ENV{'form.url'}) {
1170: $result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
1171: }
1172: if ($ENV{'form.symb'}) {
1173: $result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
1174: }
1175: $result.='</form>';
1.28 ng 1176: $result.='</td></tr></table>'."\n";
1177: $result.='</td></tr></table>'."\n";
1.26 albertel 1178: return $result;
1179: }
1180:
1181: sub viewgrades {
1182: my ($request) = @_;
1183: my $result='';
1184:
1185: #get resource reference
1186: my ($symb,$url)=&get_symb_and_url($request);
1187: if (!$symb) {return '';}
1.13 albertel 1188: #get classlist
1189: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 1190: #print "Found $cdom:$cnum<br />";
1.34 ng 1191: my ($classlist) = &getclasslist('all','0');
1.13 albertel 1192: my $headerclr = '"#ccffff"';
1193: my $cellclr = '"#ffffcc"';
1194:
1195: #get list of parts for this problem
1.29 albertel 1196: my (@parts) = sort(&getpartlist($url));
1.13 albertel 1197:
1.28 ng 1198: $request->print ("<h2><font color=\"#339933\">Manual Grading</font></h2>");
1.13 albertel 1199:
1200: #start the form
1201: $result = '<form action="/adm/grades" method="post">'."\n".
1.16 albertel 1202: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1203: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.13 albertel 1204: '<input type="hidden" name="command" value="editgrades" />'."\n".
1205: '<input type="submit" name="submit" value="Submit Changes" />'."\n".
1.32 ng 1206: '<table border=0><tr><td bgcolor="#777777">'."\n".
1.13 albertel 1207: '<table border=0>'."\n".
1.28 ng 1208: '<tr bgcolor='.$headerclr.'><td><b>Username</b></td><td><b>Name</b></td><td><b>Domain</b></td>'."\n";
1.29 albertel 1209: foreach my $part (@parts) {
1.13 albertel 1210: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1211: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.28 ng 1212: $result.='<td><b>'.$display.'</b></td>'."\n";
1.30 ng 1213: }
1.28 ng 1214: $result.='</tr>';
1.13 albertel 1215: #get info for each student
1.34 ng 1216: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1.31 ng 1217: my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1218: # print "ID=$ENV{'request.course.id'}:STU=$student:DIS=$display:<br>\n";
1.13 albertel 1219: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1220: }
1.31 ng 1221: $result.='</table></td></tr></table>';
1222: $result.='<input type="submit" name="submit" value="Submit Changes" /></form>';
1.29 albertel 1223: $result.=&show_grading_menu_form($symb,$url);
1.13 albertel 1224: return $result;
1.5 albertel 1225: }
1226:
1227: sub editgrades {
1.13 albertel 1228: my ($request) = @_;
1229: my $result='';
1.5 albertel 1230:
1.13 albertel 1231: my $symb=$ENV{'form.symb'};
1232: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
1233: my $url=$ENV{'form.url'};
1234: #get classlist
1.34 ng 1235: # my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 1236: #print "Found $cdom:$cnum<br />";
1.34 ng 1237: my ($classlist) = &getclasslist('all','0');
1.13 albertel 1238:
1239: #get list of parts for this problem
1240: my (@parts) = &getpartlist($url);
1241:
1242: $result.='<form action="/adm/grades" method="post">'."\n".
1243: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1244: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1245: '<input type="hidden" name="command" value="viewgrades" />'."\n".
1246: '<input type="submit" name="submit" value="See Grades" /> <br />'."\n";
1247:
1.35 ng 1248: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1.13 albertel 1249: $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1250: }
1.5 albertel 1251:
1.13 albertel 1252: $result.='<input type="submit" name="submit" value="See Grades" /></table></form>';
1253: return $result;
1.5 albertel 1254: }
1255:
1.27 albertel 1256: sub csvupload_javascript_reverse_associate {
1257: return(<<ENDPICK);
1258: function verify(vf) {
1259: var foundsomething=0;
1260: var founduname=0;
1261: var founddomain=0;
1262: for (i=0;i<=vf.nfields.value;i++) {
1263: tw=eval('vf.f'+i+'.selectedIndex');
1264: if (i==0 && tw!=0) { founduname=1; }
1265: if (i==1 && tw!=0) { founddomain=1; }
1266: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
1267: }
1268: if (founduname==0 || founddomain==0) {
1269: alert('You need to specify at both the username and domain');
1270: return;
1271: }
1272: if (foundsomething==0) {
1273: alert('You need to specify at least one grading field');
1274: return;
1275: }
1276: vf.submit();
1277: }
1278: function flip(vf,tf) {
1279: var nw=eval('vf.f'+tf+'.selectedIndex');
1280: var i;
1281: for (i=0;i<=vf.nfields.value;i++) {
1282: //can not pick the same destination field for both name and domain
1283: if (((i ==0)||(i ==1)) &&
1284: ((tf==0)||(tf==1)) &&
1285: (i!=tf) &&
1286: (eval('vf.f'+i+'.selectedIndex')==nw)) {
1287: eval('vf.f'+i+'.selectedIndex=0;')
1288: }
1289: }
1290: }
1291: ENDPICK
1292: }
1293:
1294: sub csvupload_javascript_forward_associate {
1295: return(<<ENDPICK);
1296: function verify(vf) {
1297: var foundsomething=0;
1298: var founduname=0;
1299: var founddomain=0;
1300: for (i=0;i<=vf.nfields.value;i++) {
1301: tw=eval('vf.f'+i+'.selectedIndex');
1302: if (tw==1) { founduname=1; }
1303: if (tw==2) { founddomain=1; }
1304: if (tw>2) { foundsomething=1; }
1305: }
1306: if (founduname==0 || founddomain==0) {
1307: alert('You need to specify at both the username and domain');
1308: return;
1309: }
1310: if (foundsomething==0) {
1311: alert('You need to specify at least one grading field');
1312: return;
1313: }
1314: vf.submit();
1315: }
1316: function flip(vf,tf) {
1317: var nw=eval('vf.f'+tf+'.selectedIndex');
1318: var i;
1319: //can not pick the same destination field twice
1320: for (i=0;i<=vf.nfields.value;i++) {
1321: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1322: eval('vf.f'+i+'.selectedIndex=0;')
1323: }
1324: }
1325: }
1326: ENDPICK
1327: }
1328:
1.26 albertel 1329: sub csvuploadmap_header {
1330: my ($request,$symb,$url,$datatoken,$distotal)= @_;
1331: my $result;
1332: my $javascript;
1333: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.27 albertel 1334: $javascript=&csvupload_javascript_reverse_associate();
1.26 albertel 1335: } else {
1.27 albertel 1336: $javascript=&csvupload_javascript_forward_associate();
1.26 albertel 1337: }
1338: $request->print(<<ENDPICK);
1339: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1340: <h3>Uploading Class Grades for resource $url</h3>
1341: <hr>
1342: <h3>Identify fields</h3>
1343: Total number of records found in file: $distotal <hr />
1344: Enter as many fields as you can. The system will inform you and bring you back
1345: to this page if the data selected is insufficient to run your class.<hr />
1346: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1347: <input type="hidden" name="associate" value="" />
1348: <input type="hidden" name="phase" value="three" />
1349: <input type="hidden" name="datatoken" value="$datatoken" />
1350: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
1351: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
1352: <input type="hidden" name="upfile_associate"
1353: value="$ENV{'form.upfile_associate'}" />
1354: <input type="hidden" name="symb" value="$symb" />
1355: <input type="hidden" name="url" value="$url" />
1356: <input type="hidden" name="command" value="csvuploadassign" />
1357: <hr />
1358: <script type="text/javascript" language="Javascript">
1359: $javascript
1360: </script>
1361: ENDPICK
1362: return '';
1363:
1364: }
1365:
1366: sub csvupload_fields {
1367: my ($url) = @_;
1368: my (@parts) = &getpartlist($url);
1.27 albertel 1369: my @fields=(['username','Student Username'],['domain','Student Domain']);
1370: foreach my $part (sort(@parts)) {
1.26 albertel 1371: my @datum;
1372: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.27 albertel 1373: my $name=$part;
1.26 albertel 1374: if (!$display) { $display = $name; }
1375: @datum=($name,$display);
1376: push(@fields,\@datum);
1377: }
1378: return (@fields);
1379: }
1380:
1381: sub csvuploadmap_footer {
1382: my ($request,$i,$keyfields) =@_;
1383: $request->print(<<ENDPICK);
1384: </table>
1385: <input type="hidden" name="nfields" value="$i" />
1386: <input type="hidden" name="keyfields" value="$keyfields" />
1387: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
1388: </form>
1389: ENDPICK
1390: }
1391:
1392: sub csvuploadmap {
1393: my ($request)= @_;
1394: my ($symb,$url)=&get_symb_and_url($request);
1395: if (!$symb) {return '';}
1396: my $datatoken;
1397: if (!$ENV{'form.datatoken'}) {
1398: $datatoken=&Apache::loncommon::upfile_store($request);
1399: } else {
1400: $datatoken=$ENV{'form.datatoken'};
1401: &Apache::loncommon::load_tmp_file($request);
1402: }
1403: my @records=&Apache::loncommon::upfile_record_sep();
1404: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
1405: my $i;
1406: my $keyfields;
1407: if (@records) {
1408: my @fields=&csvupload_fields($url);
1409: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1410: &Apache::loncommon::csv_print_samples($request,\@records);
1411: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
1412: \@fields);
1413: foreach (@fields) { $keyfields.=$_->[0].','; }
1414: chop($keyfields);
1415: } else {
1416: unshift(@fields,['none','']);
1417: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
1418: \@fields);
1419: my %sone=&Apache::loncommon::record_sep($records[0]);
1420: $keyfields=join(',',sort(keys(%sone)));
1421: }
1422: }
1423: &csvuploadmap_footer($request,$i,$keyfields);
1424: return '';
1.27 albertel 1425: }
1426:
1427: sub csvuploadassign {
1428: my ($request)= @_;
1429: my ($symb,$url)=&get_symb_and_url($request);
1430: if (!$symb) {return '';}
1431: &Apache::loncommon::load_tmp_file($request);
1432: my @gradedata=&Apache::loncommon::upfile_record_sep();
1433: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1434: my %fields=();
1435: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1436: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1437: if ($ENV{'form.f'.$i} ne 'none') {
1438: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
1439: }
1440: } else {
1441: if ($ENV{'form.f'.$i} ne 'none') {
1442: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1443: }
1444: }
1445: }
1446: $request->print('<h3>Assigning Grades</h3>');
1447: my $courseid=$ENV{'request.course.id'};
1.34 ng 1448: # my $cdom=$ENV{"course.$courseid.domain"};
1449: # my $cnum=$ENV{"course.$courseid.num"};
1450: my ($classlist) = &getclasslist('all','1');
1.29 albertel 1451: my @skipped;
1452: my $countdone=0;
1453: foreach my $grade (@gradedata) {
1454: my %entries=&Apache::loncommon::record_sep($grade);
1455: my $username=$entries{$fields{'username'}};
1456: my $domain=$entries{$fields{'domain'}};
1.34 ng 1457: if (!exists($$classlist{"$username:$domain"})) {
1.29 albertel 1458: push(@skipped,"$username:$domain");
1459: next;
1.27 albertel 1460: }
1.29 albertel 1461: my %grades;
1462: foreach my $dest (keys(%fields)) {
1463: if ($dest eq 'username' || $dest eq 'domain') { next; }
1464: if ($entries{$fields{$dest}} eq '') { next; }
1465: my $store_key=$dest;
1466: $store_key=~s/^stores/resource/;
1467: $store_key=~s/_/\./g;
1468: $grades{$store_key}=$entries{$fields{$dest}};
1469: }
1470: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
1471: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
1472: $domain,$username);
1473: $request->print('.');
1474: $request->rflush();
1475: $countdone++;
1476: }
1477: $request->print("<br />Stored $countdone students\n");
1478: if (@skipped) {
1479: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
1480: foreach my $student (@skipped) { $request->print("<br />$student"); }
1.27 albertel 1481: }
1.29 albertel 1482: $request->print(&view_edit_entire_class_form($symb,$url));
1483: $request->print(&show_grading_menu_form($symb,$url));
1484: return '';
1.26 albertel 1485: }
1486:
1.2 albertel 1487: sub send_header {
1.13 albertel 1488: my ($request)= @_;
1489: $request->print(&Apache::lontexconvert::header());
1.6 albertel 1490: # $request->print("
1491: #<script>
1492: #remotewindow=open('','homeworkremote');
1493: #remotewindow.close();
1494: #</script>");
1.13 albertel 1495: $request->print('<body bgcolor="#FFFFFF">');
1.2 albertel 1496: }
1497:
1498: sub send_footer {
1.13 albertel 1499: my ($request)= @_;
1.2 albertel 1500: $request->print('</body>');
1501: $request->print(&Apache::lontexconvert::footer());
1502: }
1503:
1.1 albertel 1504: sub handler {
1.13 albertel 1505: my $request=$_[0];
1506:
1507: if ($ENV{'browser.mathml'}) {
1508: $request->content_type('text/xml');
1509: } else {
1510: $request->content_type('text/html');
1511: }
1512: $request->send_http_header;
1513: return OK if $request->header_only;
1.16 albertel 1514: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.13 albertel 1515: my $url=$ENV{'form.url'};
1516: my $symb=$ENV{'form.symb'};
1517: my $command=$ENV{'form.command'};
1.16 albertel 1518: if (!$url) {
1519: my ($temp1,$temp2);
1520: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
1521: $url = $ENV{'form.url'};
1522: }
1.13 albertel 1523: &send_header($request);
1524: if ($url eq '' && $symb eq '') {
1.14 www 1525: if ($ENV{'user.adv'}) {
1526: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
1527: ($ENV{'form.codethree'})) {
1528: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
1529: $ENV{'form.codethree'};
1530: my ($tsymb,$tuname,$tudom,$tcrsid)=
1531: &Apache::lonnet::checkin($token);
1532: if ($tsymb) {
1533: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
1534: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1535: $request->print(
1536: &Apache::lonnet::ssi('/res/'.$url,
1537: ('grade_username' => $tuname,
1538: 'grade_domain' => $tudom,
1539: 'grade_courseid' => $tcrsid,
1540: 'grade_symb' => $tsymb)));
1541: } else {
1542: $request->print('<h1>Not authorized: '.$token.'</h1>');
1543: }
1544: } else {
1545: $request->print('<h1>Not a valid DocID: '.$token.'</h1>');
1546: }
1547: } else {
1548: $request->print(&Apache::lonxml::tokeninputfield());
1549: }
1550: }
1.13 albertel 1551: } else {
1.29 albertel 1552: #&Apache::lonhomework::showhashsubset(\%ENV,'^form');
1.13 albertel 1553: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
1554: if ($command eq 'submission') {
1.20 albertel 1555: &listStudents($request) if ($ENV{'form.student'} eq '');
1.34 ng 1556: &submission($request,0,0) if ($ENV{'form.student'} ne '');
1557: } elsif ($command eq 'processGroup') {
1558: &processGroup($request);
1.26 albertel 1559: } elsif ($command eq 'gradingmenu') {
1560: $request->print(&gradingmenu($request));
1.13 albertel 1561: } elsif ($command eq 'viewgrades') {
1562: $request->print(&viewgrades($request));
1.33 ng 1563: } elsif ($command eq 'handgrade') {
1564: $request->print(&processHandGrade($request));
1.13 albertel 1565: } elsif ($command eq 'editgrades') {
1566: $request->print(&editgrades($request));
1.23 www 1567: } elsif ($command eq 'verify') {
1568: $request->print(&verifyreceipt($request));
1.26 albertel 1569: } elsif ($command eq 'csvupload') {
1570: $request->print(&csvupload($request));
1571: } elsif ($command eq 'csvuploadmap') {
1572: $request->print(&csvuploadmap($request));
1.34 ng 1573: # } elsif ($command eq 'receiptInput') {
1574: # &receiptInput($request);
1.26 albertel 1575: } elsif ($command eq 'csvuploadassign') {
1576: if ($ENV{'form.associate'} ne 'Reverse Association') {
1577: $request->print(&csvuploadassign($request));
1578: } else {
1579: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
1580: $ENV{'form.upfile_associate'} = 'reverse';
1581: } else {
1582: $ENV{'form.upfile_associate'} = 'forward';
1583: }
1584: $request->print(&csvuploadmap($request));
1585: }
1.12 harris41 1586: } else {
1.23 www 1587: $request->print("Unknown action: $command:");
1.2 albertel 1588: }
1.13 albertel 1589: }
1590: &send_footer($request);
1591: return OK;
1.1 albertel 1592: }
1593:
1594: 1;
1595:
1.13 albertel 1596: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>