File:
[LON-CAPA] /
loncom /
homework /
grades.pm
Revision
1.37:
download - view:
text,
annotated -
select for diffs
Mon Jul 8 21:18:54 2002 UTC (22 years, 1 month ago) by
ng
Branches:
MAIN
CVS tags:
HEAD
implement storing keywords, attributes etc to handgrade.db
display last submission only - no history etc.
pretty much working now but slow for 280 students
needs to find a way to speed up the process
1: # The LearningOnline Network with CAPA
2: # The LON-CAPA Grading handler
3: #
4: # $Id: grades.pm,v 1.37 2002/07/08 21:18:54 ng Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # 2/9,2/13 Guy Albertelli
29: # 6/8 Gerd Kortemeyer
30: # 7/26 H.K. Ng
31: # 8/20 Gerd Kortemeyer
32: # Year 2002
33: # June, July 2002 H.K. Ng
34: #
35:
36: package Apache::grades;
37: use strict;
38: use Apache::style;
39: use Apache::lonxml;
40: use Apache::lonnet;
41: use Apache::loncommon;
42: use Apache::lonhomework;
43: use Apache::Constants qw(:common);
44:
45: sub moreinfo {
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");
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: }
56: # $request->print('<input type="hidden" name="command" value="submission" />'."\n");
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");
61: $request->print('</form>');
62: }
63: return '';
64: }
65:
66: sub verifyreceipt {
67: my $request=shift;
68: my $courseid=$ENV{'request.course.id'};
69: # my $cdom=$ENV{"course.$courseid.domain"};
70: # my $cnum=$ENV{"course.$courseid.num"};
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;
81: my ($classlist) = &getclasslist('all','0');
82: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
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: }
90: $request->printf('<p>'.$matches." match%s</p>",$matches <= 1 ? '' : 'es');
91: # needs to print who is matched
92: }
93: return '';
94: }
95:
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);
104: $status = 'partial' if ($foo =~ /^partially/);
105: $status = 'nothing' if ($status eq '');
106: return $type,$status;
107: }
108: }
109: return '';
110: }
111:
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:
127: sub listStudents {
128: my ($request) = shift;
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'};
133:
134: $request->print(<<ENDTABLEST);
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 <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
144: <input type="hidden" name="section" value="$getsec">
145: <input type="hidden" name="submitonly" value="$submitonly">
146: <input type="hidden" name="response" value="$ENV{'form.response'}">
147: <input type="hidden" name="handgrade" value="$ENV{'form.handgrade'}">
148: <table border="0"><tr><td bgcolor="#777777">
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>
153: ENDTABLEST
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} }) ) {
164: my ($sname,$sdom) = split(/:/,$student);
165: my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);
166: next if ($status eq 'nothing' && $submitonly eq 'yes');
167:
168: my $fullname = &get_fullname($sname,$sdom);
169: if ( $Apache::grades::viewgrades eq 'F' ) {
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>');
179: }
180: }
181: $request->print('</table></td></tr></table>');
182: $request->print('<input type="submit" name="submit" value="View/Grade" /><form />');
183: }
184:
185: sub processGroup {
186: my ($request) = shift;
187: my $ctr = 0;
188: my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
189: : ($ENV{'form.stuinfo'}));
190: my $total = scalar(@stuchecked)-1;
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(/:/);
197: $ENV{'form.student'} = $sname;
198: $ENV{'form.fullname'} = $fullname;
199: &submission($request,$ctr,$total);
200: $ctr++;
201: }
202: return 'The End';
203: }
204:
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 '';
212: }
213:
214: #FIXME - needs to handle multiple matches
215: sub finduser {
216: my ($name) = @_;
217: my $domain = '';
218: if ( $Apache::grades::viewgrades eq 'F' ) {
219: my ($classlist) = &getclasslist('all','0');
220: foreach ( sort(@{ $$classlist{'all'} }) ) {
221: my ($posname,$posdomain) = split(/:/);
222: if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
223: }
224: return ($name,$domain);
225: } else {
226: return ($ENV{'user.name'},$ENV{'user.domain'});
227: }
228: }
229:
230: sub getclasslist {
231: my ($getsec,$hideexpired) = @_;
232: my ($coursedomain,$coursenum) = split(/_/,$ENV{'request.course.id'});
233: my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
234: my $now = time;
235: my (@holdsec,@sections);
236: foreach my $student (keys(%classlist)) {
237: my ($end,$start)=split(/:/,$classlist{$student});
238: # still a student?
239: if (($hideexpired) && ($end) && ($end < $now)) {
240: next;
241: }
242: my ($unam,$udom) = split(/:/,$student,2);
243: my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
244: $section = ($section ne '-1' ? $section : 'no');
245: push @holdsec,$section;
246: push (@{ $classlist{$getsec} }, $student) if ($getsec eq 'all' || $getsec eq $section);
247: }
248: my %seen = ();
249: foreach my $item (@holdsec) {
250: push (@sections, $item) unless $seen{$item}++;
251: }
252: return (\%classlist,\@sections);
253: }
254:
255: sub getpartlist {
256: my ($url) = @_;
257: my @parts =();
258: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
259: foreach my $key (@metakeys) {
260: if ( $key =~ m/stores_([0-9]+)_.*/) {
261: push(@parts,$key);
262: }
263: }
264: return @parts;
265: }
266:
267: sub viewstudentgrade {
268: my ($url,$symb,$courseid,$student,@parts) = @_;
269: my $result ='';
270: my $cellclr = '"#ffffdd"';
271: my ($username,$domain) = split(/:/,$student);
272:
273: my $fullname = &get_fullname($username,$domain);
274: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username);
275:
276: $result.="<tr bgcolor=$cellclr><td>$username</td><td>$fullname</td><td align=\"middle\">$domain</td>\n";
277: foreach my $part (@parts) {
278: my ($temp,$part,$type)=split(/_/,$part);
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";
283: } elsif ($type eq 'solved') {
284: my ($status,$foo)=split(/_/,$score,2);
285: $result.="<td align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";
286: my $optsel = '<option>correct</option><option>incorrect</option><option>excused</option>'.
287: '<option>ungraded</option><option>partial</option><option>nothing</option>'."\n";
288: $status = 'nothing' if ($status eq '');
289: $optsel =~ s/<option>$status/<option selected="on">$status/;
290: $result.=$optsel;
291: $result.="</select></td>\n";
292: }
293: }
294: $result.='<td></td></tr>';
295: return $result;
296: }
297:
298: #FIXME need to look at the metadata <stores> spec on what type of data to accept and provide an
299: #interface based on that, also do that to above function.
300: sub setstudentgrade {
301: my ($url,$symb,$courseid,$student,@parts) = @_;
302: print "set student grade parts=@parts<br>";
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"};
312: print "old=$oldscore:new=$newscore:<br>";
313: if ($type eq 'solved') {
314: my $update=0;
315: if ($newscore eq 'nothing' ) {
316: if ($oldscore ne '') {
317: $update=1;
318: $newscore = '';
319: }
320: } elsif ($oldscore !~ m/^$newscore/) {
321: $update=1;
322: $result.="Updating $stuname to $newscore<br />\n";
323: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
324: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
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'; }
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 ) {
342: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
343: # &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
344:
345: $result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
346: }
347: return $result;
348: }
349:
350: #
351: # --------------------------- show submissions of a student, option to grade --------
352: sub submission {
353: my ($request,$counter,$total) = @_;
354:
355: if ($counter == 0) {
356: $request->print(<<SUBJAVASCRIPT);
357: <script type="text/javascript" language="javascript">
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: }
368: }
369: if (!resetbox) {
370: formtextbox.value = "";
371: }
372: return;
373: }
374:
375: for (var i=0; i<radioButton.length; i++) {
376: radioButton[i].checked=false;
377: if (pts == i) {
378: radioButton[i].checked=true;
379: }
380: }
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: }
402:
403: function keywords(keyform) {
404: var keywds = keyform.value;
405: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
406: if (nret==null) return;
407: keyform.value = nret;
408: return;
409: }
410:
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);
422: if (nret==null) return;
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;
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);
440: for (var i=1; i<=Nmsg; i++) {
441: var testpt = "savemsg"+i+",";
442: re = /testpt/;
443: shwsel = "";
444: if (re.test(msgchk)) { shwsel = "checked" }
445: var message = eval("document.SCORE.savemsg"+i+".value");
446: displaySavedMsg(i,message,shwsel);
447: }
448: newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
449: shwsel = "";
450: re = /newmsg/;
451: if (re.test(msgchk)) { shwsel = "checked" }
452: newMsg(newmsg,shwsel);
453: msgTail();
454: return;
455: }
456:
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: }
464: /* if (window.pWin)
465: window.pWin.close(); */
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) {");
480: pWin.document.write(" msgchk = \\"msgsub,\\";");
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) {");
488: pWin.document.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
489: pWin.document.write(" }");
490: pWin.document.write(" }");
491: pWin.document.write(" if (document.msgcenter.newmsgchk.checked) {");
492: pWin.document.write(" msgchk += \\"newmsg\\"+usrctr;");
493: pWin.document.write(" }");
494: pWin.document.write(" var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
495: pWin.document.write(" includemsg.value = msgchk;");
496:
497: // pWin.document.write(" alert(\\"slected=\\"+msgchk)");
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: }
515: function displaySubject(msg,shwsel) {
516: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
517: pWin.document.write("<td>Subject</td>");
518: pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
519: pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+" \\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
520: }
521:
522: function displaySavedMsg(ctr,msg,shwsel) {
523: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
524: pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
525: pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
526: pWin.document.write("<td><input name=\\"msg"+ctr+"\\" type=\\"text\\" value=\\""+msg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
527: }
528:
529: function newMsg(newmsg,shwsel) {
530: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
531: pWin.document.write("<td align=\\"center\\">New</td>");
532: pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
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();
573: return;
574: }
575:
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:
633: </script>
634: SUBJAVASCRIPT
635: }
636: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
637: if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
638: my ($uname,$udom) = &finduser($ENV{'form.student'});
639: if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
640:
641: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
642: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
643: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
644:
645: # header info
646: if ($counter == 0) {
647: $request->print('<h2> <font color="#339933">Submission Record</font></h2>'.
648: '<font size=+1> <b>Resource: </b>'.$url.'</font>');
649: }
650:
651: # option to display problem, only once else it cause problems with the form later since the problem has a form.
652: if ($ENV{'form.vProb'} eq 'yes' && $counter == 0) {
653: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
654: $ENV{'request.course.id'});
655: my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
656: $ENV{'request.course.id'});
657: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
658: $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
659: $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
660: $result.='<b>Correct answer:</b><br />'.$companswer;
661: $result.='</td></tr></table>';
662: $result.='</td></tr></table><br />';
663: $request->print($result);
664: }
665:
666: # beginning of form
667: if ($counter == 0) {
668: my %keyhash = &Apache::lonnet::dump('nohist_handgrade',
669: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
670: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
671:
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: }
682: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
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".
686: '<input type="hidden" name="lastSub" value="'.$ENV{'form.lastSub'}.'" />'."\n".
687: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
688: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
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".
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".
698: '<input type="hidden" name="NCT"'.
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);
707:
708: if ($ENV{'form.handgrade'} eq 'yes') {
709: $request->print(<<KEYWORDS);
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"
713: CLASS="page">Paste Selection to Keyword list</a>
714: <a href="javascript:kwhighlight()"; TARGET=_self>Keyword Highlight Attribute</a><br /><br />
715: KEYWORDS
716: }
717: }
718:
719: # Student info
720: $request->print(($counter == 0 ? '' : '<br /><hr><br />'));
721: my $fullname = ($ENV{'form.fullname'} ne '' ? $ENV{'form.fullname'} : &get_fullname($uname,$udom));
722: my $result.='<table border="0"><tr><td><b>Username: </b>'.$uname.
723: '</td><td><b>Fullname: </b>'.$fullname.
724: '</td><td><b>Domain: </b>'.$udom.'</td></tr>';
725: if ($ENV{'form.handgrade'} eq 'yes') {
726: # my $subonly = &get_last_submission($symb,$uname,$udom,$ENV{'request.course.id'});
727: my ($classlist) = &getclasslist('all','0');
728: my @collaborators;
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.
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: }
744: $result.='</table>'."\n";
745: $request->print($result);
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:
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);
770:
771: # display grading options
772: $result='<input type="hidden" name="WGT'.$counter.'" value="'.$wgt.'" />'.
773: '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'.$udom.'" />'."\n";
774: $result.='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
775: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n";
776: $result.='<table border="0"><tr><td><b>Points</b></td><td>';
777:
778: my $ctr = 0;
779: $result.='<table border="0"><tr>'; # display radio buttons in a nice table with 10 across
780: while ($ctr<=$wgt) {
781: $result.= '<td><input type="radio" name="RADVAL'.$counter.'" '.
782: 'onclick="javascript:writeBox(this.form.GRADE_BOX'.$counter.
783: ',this.form.GRADE_SEL'.$counter.','.$ctr.','.$wgt.')" '.
784: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
785: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
786: $ctr++;
787: }
788: $result.='</tr></table>';
789:
790: $result.='</td><td> <b>or</b> </td>';
791: $result.='<td><input type="text" name="GRADE_BOX'.$counter.'"'.
792: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
793: 'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.
794: ',this.form.GRADE_BOX'.$counter.
795: ',this.form.GRADE_SEL'.$counter.',\''.$wgt.'\')" /></td>'."\n";
796: $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
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);
802: $status = 'partial' if ($foo =~ /partially/);
803: $status = 'nothing' if ($status eq '');
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;
810: $result.="</select>  \n";
811: $result.='<a href="javascript:msgCenter(document.SCORE,'.$counter.
812: ',\''.$fullname.'\')"; TARGET=_self>Compose Message</a></td></tr>'."\n";
813: }
814: }
815: $result.='</table>';
816: $request->print($result);
817:
818: # print end of form
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 '';
835: }
836:
837: sub get_last_submission {
838: my ($symb,$username,$domain,$course)=@_;
839: if ($symb) {
840: my ($string,$timestamp);
841: my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
842: if ($returnhash{'version'}) {
843: my %lasthash=();
844: my ($version);
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)) {
851: if ($_ =~ /\.submission$/) {$string = $lasthash{$_}}
852: if ($_ =~ /timestamp/) {$timestamp=scalar(localtime($lasthash{$_}))};
853: }
854: }
855: $string = $string eq '' ? 'Nothing submitted - no attempts.' : $string;
856: return $string,$timestamp;
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)));
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:
872: my %keyhash = &Apache::lonnet::get
873: ('nohist_handgrade',\@kwkeys,
874: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
875: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
876: my @keylist = split(/[,\s+]/,$keyhash{$symb.'_keywords'});
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/\</\<\//;
880: foreach my $word (@keylist) {
881: next if ($word eq '');
882: $string =~ s/\b$word(\b|\.)/\<font color\=$keyhash{$kwkeys[1]} $size\>$styleon$word$styleoff\<\/font\>/gi;
883: }
884: return $string;
885: }
886:
887: sub processHandGrade {
888: my ($request) = shift;
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'};
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++;
911: }
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:
927: my (@parts) = sort(&getpartlist($url));
928:
929: if ($button eq 'Save & Next') {
930: my $ctr = 0;
931: while ($ctr < $ngrade) {
932: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
933: &saveHandGrade($url,$symb,$uname,$udom,$ctr,@parts);
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: }
940: $ctr++;
941: }
942: }
943: my $firststu = $ENV{'form.unamedom0'};
944: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
945:
946: my ($classlist) = &getclasslist($ENV{'form.section'},'0');
947: # print "first=$firststu,last=$laststu<br>";
948: my (@nextlist,@prevlist);
949: my ($nextflg,$prevflg,$ctr,$ctprev) = (0,0,0,0);
950: foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
951: my ($uname,$udom) = split(/:/,$student);
952: my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname);
953: next if ($status eq 'nothing' && $ENV{'form.submitonly'} eq 'yes');
954:
955: if ($nextflg == 1 && $button =~ /Next$/) {
956: push @nextlist,$uname if ($ctr < $ntstu);
957: $ctr++;
958: }
959: $nextflg = 1 if ($student eq $laststu);
960: $prevflg = 1 if ($student eq $firststu);
961: if ($prevflg == 0 && $button eq 'Previous') {
962: push @prevlist,$uname;
963: $ctprev++;
964: }
965: }
966: # print "next student=@nextlist<br>";
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;
981: foreach my $student (@nextlist) {
982: $ENV{'form.student'} = $student;
983: &submission($request,$ctr,$total);
984: $ctr++;
985: }
986:
987: return 'The End';
988: }
989:
990: sub saveHandGrade {
991: my ($url,$symb,$stuname,$domain,$newflg,@parts) = @_;
992: my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
993: my %newrecord;
994:
995: foreach my $part (@parts) {
996: my ($temp,$part,$type)=split(/_/,$part);
997: my $oldscore=$record{"resource.$part.$type"};
998: my $newscore;
999: if ($type eq 'awarded' && $newflg >= 0) {
1000: my $pts = ($ENV{'form.GRADE_BOX'.$newflg} ne '' ?
1001: $ENV{'form.GRADE_BOX'.$newflg} : $ENV{'form.RADVAL'.$newflg});
1002: my $wgt = $ENV{'form.WGT'.$newflg};
1003: # my $sel = $ENV{'form.GRADE_SEL'.$newflg};
1004: $newscore = $pts/$wgt if ($wgt != 0);
1005: }
1006: if ($type eq 'solved') {
1007: $newscore = $ENV{'form.GRADE_SEL'.$newflg} if ($newflg >= 0);
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'; }
1020: if ($newscore eq 'partial') { $newscore = 'correct_partially_by_override'; }
1021: }
1022: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
1023: } else {
1024: if ($oldscore ne $newscore) {
1025: $newrecord{"resource.$part.$type"}=$newscore;
1026: }
1027: }
1028: }
1029: if ( scalar(keys(%newrecord)) > 0 ) {
1030: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
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>";
1035: # &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
1036: }
1037: return '';
1038: }
1039:
1040: sub get_symb_and_url {
1041: my ($request) = @_;
1042: (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1043: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1044: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1045: return ($symb,$url);
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:
1059: sub gradingmenu {
1060: my ($request) = @_;
1061: my ($symb,$url)=&get_symb_and_url($request);
1062: if (!$symb) {return '';}
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'));
1066:
1067: my $result='<h2> <font color="#339933">Select a Grading Method</font></h2>';
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>';
1074:
1075: $result.=&view_edit_entire_class_form($symb,$url).'<br />';
1076: $result.=&upcsvScores_form($symb,$url).'<br />';
1077: $result.=&viewGradeaStu_form($symb,$url,$responsetype,$handgrade).'<br />';
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";
1087: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1088: $result.='<form action="/adm/grades" method="post">'."\n".
1089: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1090: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
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 {
1124: my ($symb,$url,$response,$handgrade) = @_;
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";
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".
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";
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 />';
1145: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
1146: if (grep /no/,@$sections);
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>';
1176: $result.='</td></tr></table>'."\n";
1177: $result.='</td></tr></table>'."\n";
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 '';}
1188: #get classlist
1189: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1190: #print "Found $cdom:$cnum<br />";
1191: my ($classlist) = &getclasslist('all','0');
1192: my $headerclr = '"#ccffff"';
1193: my $cellclr = '"#ffffcc"';
1194:
1195: #get list of parts for this problem
1196: my (@parts) = sort(&getpartlist($url));
1197:
1198: $request->print ("<h2><font color=\"#339933\">Manual Grading</font></h2>");
1199:
1200: #start the form
1201: $result = '<form action="/adm/grades" method="post">'."\n".
1202: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1203: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1204: '<input type="hidden" name="command" value="editgrades" />'."\n".
1205: '<input type="submit" name="submit" value="Submit Changes" />'."\n".
1206: '<table border=0><tr><td bgcolor="#777777">'."\n".
1207: '<table border=0>'."\n".
1208: '<tr bgcolor='.$headerclr.'><td><b>Username</b></td><td><b>Name</b></td><td><b>Domain</b></td>'."\n";
1209: foreach my $part (@parts) {
1210: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1211: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1212: $result.='<td><b>'.$display.'</b></td>'."\n";
1213: }
1214: $result.='</tr>';
1215: #get info for each student
1216: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
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";
1219: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1220: }
1221: $result.='</table></td></tr></table>';
1222: $result.='<input type="submit" name="submit" value="Submit Changes" /></form>';
1223: $result.=&show_grading_menu_form($symb,$url);
1224: return $result;
1225: }
1226:
1227: sub editgrades {
1228: my ($request) = @_;
1229: my $result='';
1230:
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
1235: # my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1236: #print "Found $cdom:$cnum<br />";
1237: my ($classlist) = &getclasslist('all','0');
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:
1248: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1249: $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1250: }
1251:
1252: $result.='<input type="submit" name="submit" value="See Grades" /></table></form>';
1253: return $result;
1254: }
1255:
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:
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') {
1334: $javascript=&csvupload_javascript_reverse_associate();
1335: } else {
1336: $javascript=&csvupload_javascript_forward_associate();
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);
1369: my @fields=(['username','Student Username'],['domain','Student Domain']);
1370: foreach my $part (sort(@parts)) {
1371: my @datum;
1372: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1373: my $name=$part;
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 '';
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'};
1448: # my $cdom=$ENV{"course.$courseid.domain"};
1449: # my $cnum=$ENV{"course.$courseid.num"};
1450: my ($classlist) = &getclasslist('all','1');
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'}};
1457: if (!exists($$classlist{"$username:$domain"})) {
1458: push(@skipped,"$username:$domain");
1459: next;
1460: }
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"); }
1481: }
1482: $request->print(&view_edit_entire_class_form($symb,$url));
1483: $request->print(&show_grading_menu_form($symb,$url));
1484: return '';
1485: }
1486:
1487: sub send_header {
1488: my ($request)= @_;
1489: $request->print(&Apache::lontexconvert::header());
1490: # $request->print("
1491: #<script>
1492: #remotewindow=open('','homeworkremote');
1493: #remotewindow.close();
1494: #</script>");
1495: $request->print('<body bgcolor="#FFFFFF">');
1496: }
1497:
1498: sub send_footer {
1499: my ($request)= @_;
1500: $request->print('</body>');
1501: $request->print(&Apache::lontexconvert::footer());
1502: }
1503:
1504: sub handler {
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;
1514: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1515: my $url=$ENV{'form.url'};
1516: my $symb=$ENV{'form.symb'};
1517: my $command=$ENV{'form.command'};
1518: if (!$url) {
1519: my ($temp1,$temp2);
1520: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
1521: $url = $ENV{'form.url'};
1522: }
1523: &send_header($request);
1524: if ($url eq '' && $symb eq '') {
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: }
1551: } else {
1552: #&Apache::lonhomework::showhashsubset(\%ENV,'^form');
1553: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
1554: if ($command eq 'submission') {
1555: &listStudents($request) if ($ENV{'form.student'} eq '');
1556: &submission($request,0,0) if ($ENV{'form.student'} ne '');
1557: } elsif ($command eq 'processGroup') {
1558: &processGroup($request);
1559: } elsif ($command eq 'gradingmenu') {
1560: $request->print(&gradingmenu($request));
1561: } elsif ($command eq 'viewgrades') {
1562: $request->print(&viewgrades($request));
1563: } elsif ($command eq 'handgrade') {
1564: $request->print(&processHandGrade($request));
1565: } elsif ($command eq 'editgrades') {
1566: $request->print(&editgrades($request));
1567: } elsif ($command eq 'verify') {
1568: $request->print(&verifyreceipt($request));
1569: } elsif ($command eq 'csvupload') {
1570: $request->print(&csvupload($request));
1571: } elsif ($command eq 'csvuploadmap') {
1572: $request->print(&csvuploadmap($request));
1573: # } elsif ($command eq 'receiptInput') {
1574: # &receiptInput($request);
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: }
1586: } else {
1587: $request->print("Unknown action: $command:");
1588: }
1589: }
1590: &send_footer($request);
1591: return OK;
1592: }
1593:
1594: 1;
1595:
1596: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>