Annotation of loncom/homework/grades.pm, revision 1.42
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.42 ! ng 4: # $Id: grades.pm,v 1.41 2002/07/25 21:25:38 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;
1.38 ng 43: use Apache::lonmsg qw(:user_normal_msg);
1.1 albertel 44: use Apache::Constants qw(:common);
1.39 ng 45: #use Time::HiRes qw( gettimeofday tv_interval );
1.1 albertel 46:
1.2 albertel 47: sub moreinfo {
1.41 ng 48: my ($request,$reason) = @_;
49: $request->print("Unable to process request: $reason");
50: if ( $Apache::grades::viewgrades eq 'F' ) {
51: $request->print('<form action="/adm/grades" method="post">'."\n");
52: if ($ENV{'form.url'}) {
53: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
54: }
55: if ($ENV{'form.symb'}) {
56: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
57: }
58: # $request->print('<input type="hidden" name="command" value="submission" />'."\n");
59: $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
60: $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
61: $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
62: $request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
63: $request->print('</form>');
1.16 albertel 64: }
1.41 ng 65: return '';
1.2 albertel 66: }
67:
1.23 www 68: sub verifyreceipt {
69: my $request=shift;
70: my $courseid=$ENV{'request.course.id'};
1.34 ng 71: # my $cdom=$ENV{"course.$courseid.domain"};
72: # my $cnum=$ENV{"course.$courseid.num"};
1.23 www 73: my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
1.41 ng 74: $ENV{'form.receipt'};
1.23 www 75: $receipt=~s/[^\-\d]//g;
76: my $symb=$ENV{'form.symb'};
77: unless ($symb) {
78: $symb=&Apache::lonnet::symbread($ENV{'form.url'});
79: }
80: if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
81: $request->print('<h1>Verifying Submission Receipt '.$receipt.'</h1>');
82: my $matches=0;
1.34 ng 83: my ($classlist) = &getclasslist('all','0');
84: foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1.23 www 85: my ($uname,$udom)=split(/\:/,$student);
86: if ($receipt eq
1.41 ng 87: &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
88: $request->print('Matching '.$student.'<br>');
89: $matches++;
1.23 www 90: }
91: }
1.30 ng 92: $request->printf('<p>'.$matches." match%s</p>",$matches <= 1 ? '' : 'es');
1.33 ng 93: # needs to print who is matched
1.23 www 94: }
95: return '';
96: }
1.13 albertel 97:
1.32 ng 98: sub student_gradeStatus {
1.41 ng 99: my ($url,$udom,$uname,$partlist) = @_;
100: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
101: my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
102: my %partstatus = ();
103: foreach (@$partlist) {
104: my ($status,$foo)=split(/_/,$record{"resource.$_.solved"},2);
105: $status = 'nothing' if ($status eq '');
106: $partstatus{$_} = $status;
107: $partstatus{"resource.$_.submitted_by"} = $record{"resource.$_.submitted_by"}
108: if ($record{"resource.$_.submitted_by"} ne '');
109: }
110: return %partstatus;
1.32 ng 111: }
112:
1.34 ng 113: sub get_fullname {
1.39 ng 114: my ($uname,$udom) = @_;
1.34 ng 115: my %name=&Apache::lonnet::get('environment', ['lastname','generation',
1.41 ng 116: 'firstname','middlename'],$udom,$uname);
1.34 ng 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.39 ng 127: sub response_type {
1.41 ng 128: my ($url) = shift;
129: my $allkeys = &Apache::lonnet::metadata($url,'keys');
130: # print "allkeys=>$allkeys<br>";
131: my %seen = ();
132: my (@partlist,%handgrade);
133: foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
134: if (/^\w+response_\d{1,2}.*/) {
135: my ($responsetype,$part) = split(/_/,$_,2);
136: my ($partid,$respid) = split(/_/,$part);
137: $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
138: next if ($seen{$partid} > 0);
139: $seen{$partid}++;
140: push @partlist,$partid;
141: }
142: }
143: return \@partlist,\%handgrade;
1.39 ng 144: }
145:
146:
1.30 ng 147: sub listStudents {
1.41 ng 148: my ($request) = shift;
149: my $cdom =$ENV{"course.$ENV{'request.course.id'}.domain"};
150: my $cnum =$ENV{"course.$ENV{'request.course.id'}.num"};
151: my $getsec =$ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
152: my $submitonly=$ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
153:
154: my $result='<h2><font color="#339933"> View Submissions for a Student or a Group of Students</font></h2>';
155: $result.='<table border="0">';
156: $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font></td></tr>';
157: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
158: for (sort keys(%$handgrade)) {
159: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
160: $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes');
161: $result.='<tr><td><b>Part id: </b>'.$_.'</td>'.
162: '<td><b>Type: </b>'.$responsetype.'</td>'.
163: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
164: }
165: $result.='</table>';
166: $request->print($result);
1.39 ng 167:
1.41 ng 168: $request->print(<<ENDTABLEST);
1.39 ng 169: <form action="/adm/grades" method="post">
1.34 ng 170: <b>View Problem: </b><input type="radio" name="vProb" value="no" checked> no
1.37 ng 171: <input type="radio" name="vProb" value="yes"> yes <br />
172: <b>Submissions: </b>
1.40 ng 173: <input type="radio" name="lastSub" value="hdgrade" checked /> handgrade only
174: <input type="radio" name="lastSub" value="lastonly" /> last sub only
1.39 ng 175: <input type="radio" name="lastSub" value="last" /> last sub & parts info
176: <input type="radio" name="lastSub" value="all" /> all details
177: <input type="hidden" name="section" value="$getsec" />
178: <input type="hidden" name="submitonly" value="$submitonly" />
179: <input type="hidden" name="response" value="$ENV{'form.response'}" />
1.41 ng 180: <input type="hidden" name="handgrade" value="$ENV{'form.handgrade'}" /><br />
181: <input type="hidden" name="showgrading" value="$ENV{'form.showgrading'}" /><br />
1.39 ng 182: <input type="submit" name="submit" value="View/Grade" />
1.23 www 183: ENDTABLEST
1.41 ng 184: if ($ENV{'form.url'}) {
185: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
186: }
187: if ($ENV{'form.symb'}) {
188: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
189: }
190: $request->print('<input type="hidden" name="command" value="processGroup" />'."\n");
191:
192: my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0');
193:
194: $result='<table border="0"><tr><td bgcolor="#777777">'.
195: '<table border="0"><tr bgcolor="#e6ffff">'.
196: '<td><b> Select </b></td><td><b> Username </b></td>'.
197: '<td><b> Fullname </b></td><td><b> Domain </b></td>';
198: foreach (sort(@$partlist)) {
199: $result.='<td><b> Part ID '.$_.' Status </b></td>';
200: }
201: $request->print($result.'</tr>'."\n");
202:
203: foreach my $student (sort(@{ $$classlist{$getsec} }) ) {
204: my ($uname,$udom) = split(/:/,$student);
205: my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist);
206: my $statusflg = '';
207: foreach (keys(%status)) {
208: $statusflg = 1 if ($status{$_} ne 'nothing');
209: my ($foo,$partid,$foo) = split(/\./,$_);
210: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
211: $statusflg = '';
212: $request->print('<input type="hidden" name="'.
213: $student.':submitted_by" value="'.
214: $status{'resource.'.$partid.'.submitted_by'}.'" />');
215: }
216: }
217: next if ($statusflg eq '' && $submitonly eq 'yes');
1.34 ng 218:
1.41 ng 219: if ( $Apache::grades::viewgrades eq 'F' ) {
220: $result='<tr bgcolor="#ffffe6">'.
221: '<td align="center"><input type=checkbox name="stuinfo" value="'.
222: $student.':'.$$fullname{$student}.'"></td>'."\n".
223: '<td> '.$uname.' </td>'."\n".
224: '<td> '.$$fullname{$student}.' </td>'."\n".
225: '<td align="middle"> '.$udom.' </td>'."\n";
226:
227: foreach (sort keys(%status)) {
228: next if (/^resource.*?submitted_by$/);
229: $result.='<td align="middle"> '.$status{$_}.' </td>'."\n";
230: }
231: $request->print($result.'</tr>'."\n");
232: }
233: }
234: $request->print('</table></td></tr></table>');
235: $request->print('<input type="submit" name="submit" value="View/Grade" /><form />');
1.10 ng 236: }
237:
1.34 ng 238: sub processGroup {
1.41 ng 239: my ($request) = shift;
240: my $ctr = 0;
241: my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
242: : ($ENV{'form.stuinfo'}));
243: my $total = scalar(@stuchecked)-1;
244: if ($stuchecked[0] eq '') {
245: &userError($request,'No student was selected for viewing/grading.');
246: return;
247: }
248: foreach (@stuchecked) {
249: my ($uname,$udom,$fullname) = split(/:/);
250: $ENV{'form.student'} = $uname;
251: $ENV{'form.fullname'} = $fullname;
252: &submission($request,$ctr,$total);
253: $ctr++;
254: }
255: return '';
1.35 ng 256: }
1.34 ng 257:
1.35 ng 258: sub userError {
259: my ($request, $reason, $step) = @_;
260: $request->print('<h3><font color="red">LON-CAPA User Error</font></h3><br />'."\n");
261: $request->print('<b>Reason: </b>'.$reason.'<br /><br />'."\n");
262: $request->print('<b>Step: </b>'.($step ne '' ? $step : 'Use your browser back button to correct')
263: .'<br /><br />'."\n");
264: return '';
1.34 ng 265: }
1.13 albertel 266:
1.7 albertel 267: #FIXME - needs to handle multiple matches
1.2 albertel 268: sub finduser {
1.41 ng 269: my ($name) = @_;
270: my $domain = '';
271: if ( $Apache::grades::viewgrades eq 'F' ) {
272: my ($classlist) = &getclasslist('all','0');
273: foreach ( sort(@{ $$classlist{'all'} }) ) {
274: my ($posname,$posdomain) = split(/:/);
275: if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
276: }
277: return ($name,$domain);
278: } else {
279: return ($ENV{'user.name'},$ENV{'user.domain'});
280: }
1.5 albertel 281: }
282:
283: sub getclasslist {
1.41 ng 284: my ($getsec,$hideexpired) = @_;
285: my $now = time;
286: my %classlist=&Apache::lonnet::dump('classlist',
287: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
288: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
289: my (@holdsec,@sections,%allids,%stusec,%fullname);
290: foreach (keys(%classlist)) {
291: my ($end,$start,$id,$section,$fullname)=split(/:/,$classlist{$_});
1.39 ng 292: # still a student?
1.41 ng 293: if (($hideexpired) && ($end) && ($end < $now)) {
294: next;
295: }
296: $section = ($section ne '' ? $section : 'no');
297: push @holdsec,$section;
298: if ($getsec eq 'all' || $getsec eq $section) {
299: push (@{ $classlist{$getsec} }, $_);
300: $allids{$_}=$id;
301: $stusec{$_}=$section;
302: $fullname{$_}=$fullname;
303: }
304: }
305: my %seen = ();
306: foreach my $item (@holdsec) {
307: push (@sections, $item) unless $seen{$item}++;
308: }
309: return (\%classlist,\@sections,\%allids,\%stusec,\%fullname);
1.5 albertel 310: }
311:
312: sub getpartlist {
1.41 ng 313: my ($url) = @_;
314: my @parts =();
315: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
316: foreach my $key (@metakeys) {
317: if ( $key =~ m/stores_([0-9]+)_.*/) {
318: push(@parts,$key);
319: }
1.13 albertel 320: }
1.41 ng 321: return @parts;
1.5 albertel 322: }
1.31 ng 323:
1.41 ng 324: sub print_hash {
325: my ($request, $hash) = @_;
326: $request->print('<table border=1><tr><td>Key</td><td>Value</td></tr>');
327: for (sort keys (%$hash)) {
328: $request->print('<tr><td>'.$_.'</td><td>'.$$hash{$_}.' </td></tr>');
329: }
330: $request->print('</table>');
331: return '';
332: }
1.33 ng 333: #
1.32 ng 334: # --------------------------- show submissions of a student, option to grade --------
1.2 albertel 335: sub submission {
1.41 ng 336: my ($request,$counter,$total) = @_;
1.33 ng 337:
1.41 ng 338: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
339: if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
340: my ($uname,$udom) = &finduser($ENV{'form.student'});
341: if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
342:
343: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
344: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
345: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
346: $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes';
347: my ($classlist,$seclist,$ids,$stusec,$fullname);
348:
349: # header info
350: if ($counter == 0) {
351: &sub_page_js($request);
352: $request->print('<h2> <font color="#339933">Submission Record</font></h2>'.
353: '<font size=+1> <b>Resource: </b>'.$url.'</font>');
354:
355: # option to display problem, only once else it cause problems with the form later
356: # since the problem has a form.
357: if ($ENV{'form.vProb'} eq 'yes') {
358: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
359: $ENV{'request.course.id'});
360: my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
361: $ENV{'request.course.id'});
362: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
363: $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
364: $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
365: $result.='<b>Correct answer:</b><br />'.$companswer;
366: $result.='</td></tr></table>';
367: $result.='</td></tr></table><br />';
368: $request->print($result);
369: }
370:
371: # kwclr is the only variable that is guaranteed to be non blank if this subroutine has been called once.
372: my %keyhash = ();
373: if ($ENV{'form.kwclr'} eq '') {
374: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
375: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
376: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
377:
378: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
379: $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
380: $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
381: $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
382: $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
383: $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
384: $keyhash{$symb.'_subject'} : &Apache::lonnet::metadata($url,'title');
385: $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.38 ng 386:
1.41 ng 387: }
388: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
389: '<input type="hidden" name="command" value="handgrade" />'."\n".
390: '<input type="hidden" name="refresh" value="off" />'."\n".
391: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
392: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
393: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
394: '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
395: '<input type="hidden" name="lastSub" value="'.$ENV{'form.lastSub'}.'" />'."\n".
396: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
397: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
398: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'">'."\n".
399: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'">'."\n".
400: '<input type="hidden" name="keywords" value="'.$ENV{'form.keywords'}.'" />'."\n".
401: '<input type="hidden" name="kwclr" value="'.$ENV{'form.kwclr'}.'" />'."\n".
402: '<input type="hidden" name="kwsize" value="'.$ENV{'form.kwsize'}.'" />'."\n".
403: '<input type="hidden" name="kwstyle" value="'.$ENV{'form.kwstyle'}.'" />'."\n".
404: '<input type="hidden" name="msgsub" value="'.$ENV{'form.msgsub'}.'" />'."\n".
405: '<input type="hidden" name="savemsgN" value="'.$ENV{'form.savemsgN'}.'" />'."\n".
406: '<input type="hidden" name="NCT"'.
407: ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
408:
409: my ($cts,$prnmsg) = (1,'');
410: while ($cts <= $ENV{'form.savemsgN'}) {
411: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
412: ($keyhash{$symb.'_savemsg'.$cts} eq '' ? $ENV{'form.savemsg'.$cts} : $keyhash{$symb.'_savemsg'.$cts}).
413: '" />'."\n";
414: $cts++;
415: }
416: $request->print($prnmsg);
1.32 ng 417:
1.41 ng 418: if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
419: $request->print(<<KEYWORDS);
1.38 ng 420: <b>Keyword Options:</b>
421: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>
422: <a href="#" onMouseDown="javascript:getSel(); return false"
423: CLASS="page">Paste Selection to List</a>
424: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
425: KEYWORDS
1.41 ng 426: }
427: }
428: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
429: my ($partlist,$handgrade) = &response_type($url);
430: # &print_hash($request,\%record);
431:
432: # Student info
433: $request->print(($counter == 0 ? '' : '<br />'));
434: my $fullname = ($ENV{'form.fullname'} ne '' ? $ENV{'form.fullname'} : &get_fullname($uname,$udom));
435: my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'.
436: '<table border="0" width=100%><tr bgcolor="#ffffff"><td>';
437:
438: $result.='<table border="0"><tr bgcolor="#ffffff"><td><b>Fullname: </b>'.$fullname.
439: '</td><td> <b>Username: </b>'.$uname.
440: '</td><td> <b>Domain: </b>'.$udom.'</td></tr>';
441: if ($ENV{'form.handgrade'} eq 'yes') {
442: my @col_list;
443: ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0');
444: for (keys (%$handgrade)) {
445: my $ncol = &Apache::lonnet::EXT('resource.'.$_.'.maxcollaborators',$symb,$udom,$uname);
446: if ($ncol > 0) {
447: s/\_/\./g;
448: if ($record{'resource.'.$_.'.collaborators'} ne '') {
449: my (@collaborators) = split(/,?\s+/,$record{'resource.'.$_.'.collaborators'});
450: my (@badcollaborators);
451: if (scalar(@collaborators) != 0) {
452: $result.='<tr bgcolor="#ffffff"><td colspan=3><b>Collaborators: </b>';
453: foreach my $collaborator (@collaborators) {
454: $collaborator = $collaborator =~ /\@|:/ ?
455: (split(/@|:/,$collaborator))[0] : $collaborator;
456: next if ($collaborator eq $uname);
457: if (!grep /^$collaborator:/i,keys %$classlist) {
458: push @badcollaborators,$collaborator;
459: next;
460: }
461: push @col_list, $collaborator;
462: $result.=$$fullname{$collaborator.':'.$udom}.' ('.$collaborator.') ';
463: }
464: $result.='</td></tr>'."\n";
465: $result.='<tr bgcolor="#ffbbbb"><td colspan=2>'.
466: 'This student has submitted '.(scalar (@badcollaborators) > 1 ? '' : 'an').
467: ' invalid collaborator'.(scalar (@badcollaborators) > 1 ? 's. ' : '. ').
468: (join ', ',@badcollaborators).'</td></tr>'
469: if (scalar(@badcollaborators) > 0);
470:
471: $result.='<tr bgcolor="#ffbbbb"><td colspan=2>'.
472: 'This student has submitted too many collaborators. Maximum is '.
473: $ncol.'.</td></tr>' if (scalar(@collaborators) > $ncol);
474: $result.='<input type="hidden" name="collaborator'.$counter.
475: '" value="'.(join ':',@col_list).'" />'."\n";
476: }
477: }
478: }
479: }
480: }
481: $request->print($result.'</table>'."\n");
1.33 ng 482:
1.41 ng 483: # print student answer
484: if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
485: if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
486: my $submitby='</td></tr><tr><td bgcolor="#e6ffff">'.
487: '<b>Collaborative submission by: </b>'.
488: '<a href="javascript:viewSubmitter(\''.$ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
489: '\')"; TARGET=_self>'.
490: $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
491: $submitby.='</td></tr><tr><td bgcolor="#ffffff">'."\n";
492: $request->print($submitby);
493: } else {
494: my ($string,$timestamp)=&get_last_submission ($symb,$uname,$udom,$ENV{'request.course.id'});
495: my $lastsubonly.='</td></tr><tr><td bgcolor="#e6ffff"><b>Last Submission Only</b>'.
496: ($$timestamp eq '' ? '' : ' <b>Date Submitted:</b> '.$$timestamp).'</td></tr>';
497: if ($$timestamp eq '') {
498: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0].'</td></tr>';
499: } else {
500: for my $part (sort keys(%$handgrade)) {
501: foreach (@$string) {
502: my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
503: if ($part eq ($partid.'_'.$respid)) {
504: my ($ressub,$subval) = split(/:/,$_,2);
505: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part ID</b> '.
506: $partid.' <b>Response ID</b> '.$respid.
507: ' <b>Submission</b> '.&keywords_highlight($subval).'</td></tr>'
508: if ($ENV{'form.lastSub'} eq 'lastonly' ||
509: ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} =~ /:yes$/));
510: }
511: }
512: }
513: }
514: $lastsubonly.='</td></tr><tr><td bgcolor="#ffffff">'."\n";
515: $request->print($lastsubonly);
516: }
517: } else {
518: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
519: $ENV{'request.course.id'},$last,
520: '.submission','Apache::grades::keywords_highlight'));
521: }
522:
523: # view submission with no grading option
524: if ($ENV{'form.showgrading'} eq '') {
525: $request->print('</td></tr></table></td></tr></table></form>');
526: return;
527: }
1.33 ng 528:
1.41 ng 529: $result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
530: '<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
531: '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'.$udom.'" />'."\n";
532: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
533: ',\''.$fullname.'\')"; TARGET=_self>Compose Message</a><br />'."\n" if ($ENV{'form.handgrade'} eq 'yes');
534: $request->print($result);
535:
536: my %seen = ();
537: my @partlist;
538: for (sort keys(%$handgrade)) {
539: my ($partid,$respid) = split(/_/);
540: next if ($seen{$partid} > 0);
541: $seen{$partid}++;
542: next if ($$handgrade{$_} =~ /:no$/);
543: push @partlist,$partid;
544: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
545: my $wgtmsg = ($wgt > 0 ? '(problem weight)' : '<font color="red">problem weight assigned by computer</font>');
546: $wgt = ($wgt > 0 ? $wgt : '1');
547: my $score = ($record{'resource.'.$partid.'.awarded'} eq '' ?
548: '' : $record{'resource.'.$partid.'.awarded'}*$wgt);
549:
550: # display grading options
551: $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
552: $result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points</b></td><td>';
553:
554: my $ctr = 0;
555: $result.='<table border="0"><tr>'; # display radio buttons in a nice table 10 across
556: while ($ctr<=$wgt) {
557: $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
558: 'onclick="javascript:writeBox(this.form.GRADE_BOX'.$counter.'_'.$partid.
559: ',this.form.GRADE_SEL'.$counter.'_'.$partid.','.$ctr.
560: ',this.form.stores'.$counter.'_'.$partid.')" '.
561: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
562: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
563: $ctr++;
564: }
565: $result.='</tr></table>';
1.39 ng 566:
1.41 ng 567: $result.='</td><td> <b>or</b> </td>';
568: $result.='<td><input type="text" name="GRADE_BOX'.$counter.'_'.$partid.'"'.
569: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
570: 'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
571: ',this.form.GRADE_BOX'.$counter.'_'.$partid.
572: ',this.form.GRADE_SEL'.$counter.'_'.$partid.
573: ',this.form.stores'.$counter.'_'.$partid.')" /></td>'."\n";
574: $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
575:
576: $result.='<select name="GRADE_SEL'.$counter.'_'.$partid.'" '.
577: 'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
578: ',this.form.GRADE_BOX'.$counter.'_'.$partid.
579: ',this.form.GRADE_SEL'.$counter.'_'.$partid.
580: ',this.form.stores'.$counter.'_'.$partid.')" />'."\n".
581: '<option selected="on"> </option>'.
582: '<option>excused</option></select>'."  \n";
583: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
584: $result.='</td></tr></table>';
585: $request->print($result);
586: }
587: $request->print('<input type="hidden" name="partlist'.$counter.'" value="'.(join ":",@partlist).'" />'."\n");
588: $request->print('</td></tr></table></td></tr></table>'."\n");
589:
590: # print end of form
591: if ($counter == $total) {
592: my $endform.='<table border="0"><tr><td><input type="submit" name="gradeOpt" value="Save & Next" />';
593: my $ntstu ='<select name="NTSTU">'.
594: '<option>1</option><option>2</option>'.
595: '<option>3</option><option>5</option>'.
596: '<option>7</option><option>10</option></select>'."\n";
597: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
598: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
599: $endform.=$ntstu.'student(s) '.
600: '<input type="submit" name="gradeOpt" value="Next" /> '.
601: '<input type="submit" name="gradeOpt" value="Previous" /> '.
602: '(Next and Previous do not save the scores.)'.
603: '</td><tr></table></form>';
604: $request->print($endform);
605: }
606: return '';
1.38 ng 607: }
608:
609: sub get_last_submission {
1.41 ng 610: my ($symb,$username,$domain,$course)=@_;
611: if ($symb) {
612: my (@string,$timestamp);
613: my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
614: if ($returnhash{'version'}) {
615: my %lasthash=();
616: my ($version);
617: for ($version=1;$version<=$returnhash{'version'};$version++) {
618: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
619: $lasthash{$_}=$returnhash{$version.':'.$_};
620: }
621: }
622: foreach ((keys %lasthash)) {
623: if ($_ =~ /\.submission$/) {push @string, (join(':',$_,$lasthash{$_}))}
624: if ($_ =~ /timestamp/) {$timestamp = scalar(localtime($lasthash{$_}))};
625: }
626: }
627: @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
628: return \@string,\$timestamp;
629: }
1.38 ng 630: }
1.35 ng 631:
1.38 ng 632: sub keywords_highlight {
1.41 ng 633: my $string = shift;
634: my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
635: my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
636: (my $styleoff = $styleon) =~ s/\</\<\//;
637: my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
638: foreach (@keylist) {
639: $string =~ s/\b$_(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
640: }
641: return $string;
1.38 ng 642: }
1.36 ng 643:
1.38 ng 644: sub processHandGrade {
1.41 ng 645: my ($request) = shift;
646: my $url = $ENV{'form.url'};
647: my $symb = $ENV{'form.symb'};
648: my $button = $ENV{'form.gradeOpt'};
649: my $ngrade = $ENV{'form.NCT'};
650: my $ntstu = $ENV{'form.NTSTU'};
651:
652: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
653: my %keyhash = ();
654: $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
655: $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
656: $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
657: $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
658: $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
659: $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
660: $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
661:
662: my ($ctr,$idx) = (1,1);
663: while ($ctr <= $ENV{'form.savemsgN'}) {
664: if ($ENV{'form.savemsg'.$ctr} ne '') {
665: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
666: $idx++;
667: }
668: $ctr++;
669: }
670: $ctr = 0;
671: while ($ctr < $ngrade) {
672: if ($ENV{'form.newmsg'.$ctr} ne '') {
673: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
674: $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
675: $idx++;
676: }
677: $ctr++;
678: }
679: $ENV{'form.savemsgN'} = --$idx;
680: $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
681: my $putresult = &Apache::lonnet::put
682: ('nohist_handgrade',\%keyhash,
683: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
684: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
685:
686: if ($ENV{'form.refresh'} eq 'on') {
687: my $ctr = 0;
688: $ENV{'form.NTSTU'}=$ngrade;
689: while ($ctr < $ngrade) {
690: ($ENV{'form.student'},my $udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
691: &submission($request,$ctr,$ngrade-1);
692: $ctr++;
693: }
694: return '';
695: }
1.36 ng 696:
1.41 ng 697: if ($button eq 'Save & Next') {
698: my $ctr = 0;
699: while ($ctr < $ngrade) {
700: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
701: my ($errorflg) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
702: return '' if ($errorflg eq 'error');
703:
704: my $includemsg = $ENV{'form.includemsg'.$ctr};
705: my ($subject,$message,$msgstatus) = ('','','');
706: if ($includemsg =~ /savemsg|new$ctr/) {
707: $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
708: my (@msgnum) = split(/,/,$includemsg);
709: foreach (@msgnum) {
710: $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
711: }
712: $message =~ s/\s+/ /g;
713: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
714: $ENV{'form.msgsub'},$message);
715: }
716: if ($ENV{'form.collaborator'.$ctr}) {
717: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
718: foreach (@collaborators) {
719: &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
720: $ENV{'form.unamedom'.$ctr});
721: if ($message ne '') {
722: $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
723: $ENV{'form.msgsub'},
724: $message);
725: }
726: }
727: }
728: $ctr++;
729: }
730: }
731: my $firststu = $ENV{'form.unamedom0'};
732: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
733: $ctr = 2;
734: while ($laststu eq '') {
735: $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
736: $ctr++;
737: $laststu = $firststu if ($ctr > $ngrade);
738: }
739: my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
740:
741: my (@parsedlist,@nextlist);
742: my ($nextflg) = 0;
743: foreach ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
744: if ($nextflg == 1 && $button =~ /Next$/) {
745: push @parsedlist,$_;
746: }
747: $nextflg = 1 if ($_ eq $laststu);
748: if ($button eq 'Previous') {
749: last if ($_ eq $firststu);
750: push @parsedlist,$_;
751: }
752: }
753: $ctr = 0;
754: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
755: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
756: foreach my $student (@parsedlist) {
757: my ($uname,$udom) = split(/:/,$student);
758: if ($ENV{'form.submitonly'} eq 'yes') {
759: my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist) ;
760: my $statusflg = '';
761: foreach (keys(%status)) {
762: $statusflg = 1 if ($status{$_} ne 'nothing');
763: my ($foo,$partid,$foo) = split(/\./,$_);
764: $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
765: }
766: next if ($statusflg eq '');
767: }
768: push @nextlist,$student if ($ctr < $ntstu);
769: $ctr++;
770: }
1.36 ng 771:
1.41 ng 772: $ctr = 0;
773: my $total = scalar(@nextlist)-1;
1.39 ng 774:
1.41 ng 775: foreach (sort @nextlist) {
776: my ($uname,$udom,$submitter) = split(/:/);
777: $ENV{'form.student'} = $uname;
778: $ENV{'form.fullname'} = $$fullname{$_};
779: # $ENV{'form.'.$_.':submitted_by'} = $submitter;
780: # print "submitter=$ENV{'form.'.$_.':submitted_by'}= $submitter:<br>";
781: &submission($request,$ctr,$total);
782: $ctr++;
783: }
784: if ($total < 0) {
785: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
786: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
787: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
788: $the_end.=&show_grading_menu_form ($symb,$url);
789: $request->print($the_end);
790: }
791: return '';
1.38 ng 792: }
1.36 ng 793:
1.38 ng 794: sub saveHandGrade {
1.41 ng 795: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
796: # my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
797: my %newrecord;
798: foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
799: if ($ENV{'form.GRADE_SEL'.$newflg.'_'.$_} eq 'excused') {
800: $newrecord{'resource.'.$_.'.solved'} = 'excused';
801: } else {
802: my $pts = ($ENV{'form.GRADE_BOX'.$newflg.'_'.$_} ne '' ?
803: $ENV{'form.GRADE_BOX'.$newflg.'_'.$_} : $ENV{'form.RADVAL'.$newflg.'_'.$_});
804: if ($pts eq '') {
805: &userError($request,'No point was assigned for part id '.$_.' and for username '.$stuname.'.');
806: return 'error';
807: }
808: my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : $ENV{'form.WGT'.$newflg.'_'.$_};
809: my $partial= $pts/$wgt;
810: $newrecord{'resource.'.$_.'.awarded'} = $partial;
811: if ($partial == 0) {
812: $newrecord{'resource.'.$_.'.solved'} = 'incorrect_by_override';
813: } else {
814: $newrecord{'resource.'.$_.'.solved'} = 'correct_by_override';
815: }
816: $newrecord{'resource.'.$_.'.submitted_by'} = $submitter if ($submitter);
817: }
818: }
819:
820: if ( scalar(keys(%newrecord)) > 0 ) {
821: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
822: # &print_hash($request,\%newrecord);
823: &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
824: }
825: return '';
1.36 ng 826: }
1.38 ng 827:
828: sub get_symb_and_url {
1.41 ng 829: my ($request) = @_;
830: (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
831: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
832: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
833: return ($symb,$url);
1.36 ng 834: }
835:
1.38 ng 836: sub show_grading_menu_form {
1.41 ng 837: my ($symb,$url)=@_;
838: my $result.='<form action="/adm/grades" method="post">'."\n".
839: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
840: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 841: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.41 ng 842: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
843: '</form>'."\n";
844: return $result;
1.36 ng 845: }
846:
1.38 ng 847: sub gradingmenu {
1.41 ng 848: my ($request) = @_;
849: my ($symb,$url)=&get_symb_and_url($request);
850: if (!$symb) {return '';}
851: my $result='<h2> <font color="#339933">Select a Grading Method</font></h2>';
852: $result.='<table border="0">';
853: $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
854: my ($partlist,$handgrade) = &response_type($url);
855: my ($resptype,$hdgrade)=('','no');
856: for (sort keys(%$handgrade)) {
857: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
858: $resptype = $responsetype;
859: $hdgrade = $handgrade if ($handgrade eq 'yes');
860: $result.='<tr><td><b>Part id: </b>'.$_.'</td>'.
861: '<td><b>Type: </b>'.$responsetype.'</td>'.
862: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
863: }
864: $result.='</table>';
865: $result.=&view_edit_entire_class_form($symb,$url).'<br />';
866: $result.=&upcsvScores_form($symb,$url).'<br />';
867: $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';
868: $result.=&verifyReceipt_form($symb,$url).'<br />';
869: $result.=&view_classlist_form($symb,$url);
1.39 ng 870:
1.41 ng 871: return $result;
1.39 ng 872: }
873:
874: sub view_classlist_form {
1.41 ng 875: my ($symb,$url)=@_;
876: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
877: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
878: $result.=' <b>View Class List</b></td></tr>'."\n";
879: $result.='<tr bgcolor=#ffffe6><td>'."\n";
880: $result.='<form action="/adm/grades" method="post">'."\n".
881: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
882: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
883: '<input type="hidden" name="command" value="viewclasslist" />'."\n";
884: $result.=' <input type="submit" name="submit" value="View Class" /></form>'."\n";
885: $result.='</td></tr></table>'."\n";
886: $result.='</td></tr></table>'."\n";
887: return $result;
1.36 ng 888: }
889:
1.39 ng 890: sub viewclasslist {
1.41 ng 891: my ($request) = shift;
892: my ($coursedomain,$coursenum) = split(/_/,$ENV{'request.course.id'});
893: my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
894: $request->print('<table border=1>');
895: foreach (sort keys(%classlist)) {
1.39 ng 896: # my ($unam,$udom) = split(/:/,$_,2);
897: # my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
898: # my $fullname = &get_fullname ($unam,$udom);
899: # my @uname;
900: # $uname[0]=$unam;
901: # my %userid=&Apache::lonnet::idrget($udom,@uname);
902: # my $value=$classlist{$_}.':'.$userid{$unam}.':'.$section.':'.$fullname;
903: # $classlist{$_}=$value;
1.41 ng 904: $request->print('<tr><td>'.$_.' </td><td><pre> '.$classlist{$_}.'</pre></td></tr>');
905: }
906: $request->print('</table>');
1.39 ng 907: # my $putresult = &Apache::lonnet::put
908: # ('classlist',\%classlist,
909: # $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
910: # $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
911:
1.41 ng 912: return '';
1.39 ng 913: }
914:
1.38 ng 915: sub view_edit_entire_class_form {
1.41 ng 916: my ($symb,$url)=@_;
917: my ($classlist,$sections) = &getclasslist('all','0');
918: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
919: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
920: $result.=' <b>View/Grade Entire Section/Class</b></td></tr>'."\n";
921: $result.='<tr bgcolor=#ffffe6><td>'."\n";
922: $result.='<form action="/adm/grades" method="post">'."\n".
923: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
924: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
925: '<input type="hidden" name="command" value="viewgrades" />'."\n";
926: $result.=' <b>Select section:</b> <select name="section">'."\n";
927: foreach (sort (@$sections)) {
928: $result.= '<option>'.$_.'</option>'."\n";
929: }
930: $result.= '<option selected="on">all</select>'."<br />\n";
931: # $result.=' <b>Display students who has: </b>'.
932: # '<input type="radio" name="submitonly" value="yes" checked> submitted'.
933: # '<input type="radio" name="submitonly" value="all"> everybody <br /><br />';
934: $result.=' <input type="submit" name="submit" value="View/Grade" /></form>'."\n";
935: $result.='</td></tr></table>'."\n";
936: $result.='</td></tr></table>'."\n";
937: return $result;
1.36 ng 938: }
939:
1.38 ng 940: sub upcsvScores_form {
1.41 ng 941: my ($symb,$url) = @_;
942: if (!$symb) {return '';}
943: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
944: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
945: $result.=' <b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
946: $result.='<tr bgcolor=#ffffe6><td>'."\n";
947: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.38 ng 948: $result.=<<ENDUPFORM;
949: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
950: <input type="hidden" name="symb" value="$symb" />
951: <input type="hidden" name="url" value="$url" />
952: <input type="hidden" name="command" value="csvuploadmap" />
953: $upfile_select
954: <br /> <input type="submit" name="submit" value="Upload Grades" />
955: </form>
956: ENDUPFORM
1.41 ng 957: $result.='</td></tr></table>'."\n";
958: $result.='</td></tr></table>'."\n";
959: return $result;
1.38 ng 960: }
961:
962: sub viewGradeaStu_form {
1.41 ng 963: my ($symb,$url,$response,$handgrade) = @_;
964: my ($classlist,$sections) = &getclasslist('all','0');
965: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
966: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
967: $result.=' <b>View/Grade an Individual Student\'s Submission</b></td></tr>'."\n";
968: $result.='<tr bgcolor=#ffffe6><td>'."\n";
969: $result.='<form action="/adm/grades" method="post">'."\n".
970: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
971: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
972: '<input type="hidden" name="response" value="'.$response.'" />'."\n".
973: '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
974: '<input type="hidden" name="showgrading" value="yes" />'."\n".
975: '<input type="hidden" name="command" value="submission" />'."\n";
976:
977: $result.=' <b>Select section:</b> <select name="section">'."\n";
978: foreach (sort (@$sections)) {
979: $result.= '<option>'.$_.'</option>'."\n";
980: }
981: $result.= '<option selected="on">all</select>'."\n";
982: $result.=' <b>Display students who has: </b>'.
983: '<input type="radio" name="submitonly" value="yes" checked> submitted'.
984: '<input type="radio" name="submitonly" value="all"> everybody <br />';
985: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
986: if (grep /no/,@$sections);
987:
988: $result.='<br /> <input type="submit" name="submit" value="View/Grade" />'."\n".
989: '</form>'."\n";
990: $result.='</td></tr></table>'."\n";
991: $result.='</td></tr></table>'."\n";
992: return $result;
1.36 ng 993: }
994:
1.38 ng 995: sub verifyReceipt_form {
1.41 ng 996: my ($symb,$url) = @_;
997: my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
998: my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
999: my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
1000:
1001: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1002: $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
1003: $result.=' <b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
1004: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1005: $result.='<form action="/adm/grades" method="post">'."\n";
1006: $result.=' <tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
1007: $result.=' <input type="submit" name="submit" value="Verify Receipt">'."\n";
1008: $result.='<input type="hidden" name="command" value="verify">'."\n";
1009: if ($ENV{'form.url'}) {
1010: $result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
1011: }
1012: if ($ENV{'form.symb'}) {
1013: $result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
1014: }
1015: $result.='</form>';
1016: $result.='</td></tr></table>'."\n";
1017: $result.='</td></tr></table>'."\n";
1018: return $result;
1.36 ng 1019: }
1020:
1.42 ! ng 1021: sub viewgrades_js {
! 1022: my ($request) = shift;
! 1023:
1.41 ng 1024: $request->print(<<VIEWJAVASCRIPT);
1025: <script type="text/javascript" language="javascript">
1026: function viewOneStudent(user) {
1027: document.onestudent.student.value = user;
1028: document.onestudent.submit();
1029: }
1030:
1.42 ! ng 1031: function writePoint(partid,weight,point) {
! 1032: var radioButton = eval("document.classgrade.RADVAL_"+partid);
! 1033: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
! 1034: if (point == "textval") {
! 1035: var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
! 1036: if (isNaN(point) || point < 0) {
! 1037: alert("A number equal or greater than 0 is expected. Entered value = "+point);
! 1038: var resetbox = false;
! 1039: for (var i=0; i<radioButton.length; i++) {
! 1040: if (radioButton[i].checked) {
! 1041: textbox.value = i;
! 1042: resetbox = true;
! 1043: }
! 1044: }
! 1045: if (!resetbox) {
! 1046: textbox.value = "";
! 1047: }
! 1048: return;
! 1049: }
! 1050: for (var i=0; i<radioButton.length; i++) {
! 1051: radioButton[i].checked=false;
! 1052: if (point == i) {
! 1053: radioButton[i].checked=true;
! 1054: }
! 1055: }
1.41 ng 1056:
1.42 ! ng 1057: } else {
! 1058: textbox.value = point;
! 1059: }
1.41 ng 1060: for (i=0;i<document.classgrade.total.value;i++) {
1061: var user = eval("document.classgrade.counter"+i+".value");
1.42 ! ng 1062: var scorename = eval("document.classgrade.GRADE_"+user+
! 1063: "_"+partid+"_awarded");
! 1064: var saveval = eval("document.classgrade.GRADE_"+user+
! 1065: "_"+partid+"_solved_save.value");
! 1066: var selname = eval("document.classgrade.GRADE_"+user+"_"+partid+"_solved");
! 1067: if (saveval != "correct") {
! 1068: scorename.value = point;
! 1069: selname[0].selected = true;
! 1070: }
! 1071: }
! 1072: var selval = eval("document.classgrade.SELVAL_"+partid);
! 1073: selval[0].selected = true;
! 1074: }
! 1075:
! 1076: function writeRadText(partid,weight) {
! 1077: var selval = eval("document.classgrade.SELVAL_"+partid);
! 1078: if (selval[1].selected) {
! 1079: var radioButton = eval("document.classgrade.RADVAL_"+partid);
! 1080: for (var i=0; i<radioButton.length; i++) {
! 1081: radioButton[i].checked=false;
! 1082:
! 1083: }
! 1084: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
! 1085: textbox.value = "";
! 1086:
! 1087: for (i=0;i<document.classgrade.total.value;i++) {
! 1088: var user = eval("document.classgrade.counter"+i+".value");
! 1089: var scorename = eval("document.classgrade.GRADE_"+user+
! 1090: "_"+partid+"_awarded");
! 1091: var saveval = eval("document.classgrade.GRADE_"+user+
! 1092: "_"+partid+"_solved_save.value");
! 1093: var selname = eval("document.classgrade.GRADE_"+user+
! 1094: "_"+partid+"_solved");
! 1095: if (saveval != "correct") {
! 1096: scorename.value = "";
! 1097: selname[1].selected = true;
! 1098: }
! 1099: }
! 1100: }
! 1101: }
! 1102:
! 1103: function changeSelect(partid,user) {
! 1104: var selval = eval("document.classgrade.GRADE_"+user+'_'+partid+"_solved");
! 1105: selval[0].selected = true;
! 1106: }
! 1107:
! 1108: function changeOneScore(partid,user) {
! 1109: var selval = eval("document.classgrade.GRADE_"+user+'_'+partid+"_solved");
! 1110: if (selval[1].selected) {
! 1111: var boxval = eval("document.classgrade.GRADE_"+user+'_'+partid+"_awarded");
! 1112: boxval.value = "";
! 1113: }
! 1114: }
! 1115:
! 1116: function resetEntry(numpart) {
! 1117: for (ctpart=0;ctpart<numpart;ctpart++) {
! 1118: var partid = eval("document.classgrade.partid_"+ctpart+".value");
! 1119: var radioButton = eval("document.classgrade.RADVAL_"+partid);
! 1120: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
! 1121: var selval = eval("document.classgrade.SELVAL_"+partid);
! 1122: for (var i=0; i<radioButton.length; i++) {
! 1123: radioButton[i].checked=false;
! 1124:
! 1125: }
! 1126: textbox.value = "";
! 1127: selval[0].selected = true;
! 1128:
! 1129: for (i=0;i<document.classgrade.total.value;i++) {
! 1130: var user = eval("document.classgrade.counter"+i+".value");
! 1131: var resetscore = eval("document.classgrade.GRADE_"+user+
! 1132: "_"+partid+"_awarded");
! 1133: resetscore.value = eval("document.classgrade.GRADE_"+user+
! 1134: "_"+partid+"_awarded_save.value");
! 1135:
! 1136: var saveselval = eval("document.classgrade.GRADE_"+user+
! 1137: "_"+partid+"_solved_save.value");
! 1138:
! 1139: var selname = eval("document.classgrade.GRADE_"+user+"_"+partid+"_solved");
! 1140: if (saveselval == "excused") {
! 1141: selname[1].selected = true;
! 1142: } else {
! 1143: selname[0].selected = true;
! 1144: }
! 1145: }
1.41 ng 1146: }
1.42 ! ng 1147: }
! 1148:
! 1149:
1.41 ng 1150: </script>
1151: VIEWJAVASCRIPT
1.42 ! ng 1152: }
! 1153:
! 1154: sub viewgrades {
! 1155: my ($request) = shift;
! 1156: &viewgrades_js($request);
1.41 ng 1157:
1158: my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
1159: $request->print ('<h2><font color="#339933">Manual Grading</font></h2>');
1.38 ng 1160:
1.42 ! ng 1161: my $result='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font>'."\n";
1.41 ng 1162:
1163: #view individual student submission form - called using Javascript viewOneStudent
1.42 ! ng 1164: $result.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.41 ng 1165: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1166: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1167: '<input type="hidden" name="command" value="submission" />'."\n".
1168: '<input type="hidden" name="student" value="" />'."\n".
1169: '</form>'."\n";
1170:
1171: #start the form
1172: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1173: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1174: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 1175: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.41 ng 1176: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n";
1.42 ! ng 1177:
! 1178: $result.='To assign the same score for all the students use the radio buttons or '.
! 1179: 'text box below. To assign scores individually fill in the score boxes for '.
! 1180: 'each student in the table below. <font color="red">A score that has already '.
! 1181: 'been graded does not get changed using the radio buttons or text box. '.
! 1182: 'If needed, it has to be changed individually.</font>';
! 1183:
! 1184: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
! 1185: my %weight = ();
! 1186: my $ctsparts = 0;
1.41 ng 1187: $result.='<table border="0">';
1.42 ! ng 1188: for (sort keys(%$handgrade)) {
! 1189: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
! 1190: my ($partid,$respid) = split (/_/);
! 1191: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
! 1192: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
! 1193:
! 1194: $result.='<input type="hidden" name="partid_'.$ctsparts.'" value="'.$partid.'" />'."\n";
! 1195: $result.='<tr><td><b>Part ID:</b> '.$partid.' </td><td>';
! 1196: $result.='<table border="0"><tr>';
1.41 ng 1197: my $ctr = 0;
1.42 ! ng 1198: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
! 1199: $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
! 1200: 'onclick="javascript:writePoint('.$partid.','.$weight{$partid}.
1.41 ng 1201: ','.$ctr.')" />'.$ctr."</td>\n";
1202: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1203: $ctr++;
1204: }
1205: $result.='</tr></table>';
1.42 ! ng 1206: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.$partid.'" size="4" '.
! 1207: 'onChange="javascript:writePoint('.$partid.','.$weight{$partid}.',\'textval\')" /> /'.
! 1208: $weight{$partid}.' (problem weight)</td>'."\n";
! 1209: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
! 1210: 'onChange="javascript:writeRadText('.$partid.','.$weight{$partid}.')" /> '.
! 1211: '<option selected="on"> </option>'.
! 1212: '<option>excused</option></select></td></tr>'."\n";
! 1213: $ctsparts++;
1.41 ng 1214: }
1.42 ! ng 1215: $result.='</table><input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
! 1216: $result.='<input type="button" value="Reset" '.
! 1217: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>   ';
! 1218: $result.= '<input type="submit" name="submit" value="Submit Changes" />'."\n";
1.41 ng 1219:
1.42 ! ng 1220: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.41 ng 1221: '<table border=0><tr bgcolor="#deffff">'.
1222: '<td><b>Username</b></td><td><b>Fullname</b></td><td><b>Domain</b></td>'."\n";
1223: #get list of parts for this problem
1224: my (@parts) = sort(&getpartlist($url));
1225: foreach my $part (@parts) {
1226: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1227: next if ($display =~ /^Number of Attempts/);
1228: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1229: if ($display =~ /^Partial Credit Factor/) {
1230: $_ = $display;
1231: my ($partid) = /.*?(\d+).*/;
1.42 ! ng 1232: $result.='<td><b>Score Part '.$partid.'<br>(weight = '.
! 1233: $weight{$partid}.')</b></td>'."\n";
1.41 ng 1234: next;
1235: }
1.42 ! ng 1236: $display =~ s/Problem Status/Grade Status<br>/;
1.41 ng 1237: $result.='<td><b>'.$display.'</b></td>'."\n";
1238: }
1239: $result.='</tr>';
1240: #get info for each student
1241: my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
1242: my $ctr = 0;
1243: foreach ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
1244: (my $username = $_) = split(/:/);
1245: $result.='<input type="hidden" name="counter'.$ctr.'" value="'.$username.'" />'."\n";
1246: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
1247: $_,$$fullname{$_},\@parts,\%weight);
1248: $ctr++;
1249: }
1250: $result.='</table></td></tr></table>';
1251: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1252: $result.='<input type="submit" name="submit" value="Submit Changes" /></form>';
1253: $result.=&show_grading_menu_form($symb,$url);
1254: return $result;
1255: }
1256:
1257: sub viewstudentgrade {
1258: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
1259: my ($username,$domain) = split(/:/,$student);
1260: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username);
1261: my $result='<tr bgcolor="#ffffdd"><td>'.
1262: '<a href="javascript:viewOneStudent(\''.$username.'\')"; TARGET=_self>'.$username.'</a>'.
1263: '</td><td>'.$fullname.'</td><td align="middle">'.$domain.'</td>'."\n";
1264: foreach my $part (@$parts) {
1265: my ($temp,$part,$type)=split(/_/,$part);
1266: my $score=$record{"resource.$part.$type"};
1267: next if $type eq 'tries';
1268: if ($type eq 'awarded') {
1.42 ! ng 1269: my $pts = $score eq '' ? '' : $score*$$weight{$part};
! 1270: $result.='<input type="hidden" name="'.
! 1271: 'GRADE_'.$username.'_'.$part.'_awarded_save" value="'.$pts.'" />'."\n";
! 1272: $result.='<td align="middle"><input type="text" name="'.
! 1273: 'GRADE_'.$username.'_'.$part.'_awarded"'.
! 1274: 'onChange="javascript:changeSelect('.$part.',\''.$username.'\')" value="'.
! 1275: $pts.'" size="4" /></td>'."\n";
1.41 ng 1276: } elsif ($type eq 'solved') {
1277: my ($status,$foo)=split(/_/,$score,2);
1278: $status = 'nothing' if ($status eq '');
1.42 ! ng 1279: $result.='<input type="hidden" name="'.
! 1280: 'GRADE_'.$username.'_'.$part.'_solved_save" value="'.$status.'" />'."\n";
! 1281: $result.='<td align="middle"><select name="'.
! 1282: 'GRADE_'.$username.'_'.$part.'_solved" '.
! 1283: 'onChange="javascript:changeOneScore('.$part.',\''.$username.'\')" >'."\n";
! 1284: my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
! 1285: $optsel = '<option> </option><option selected="on">excused</option>'."\n"
! 1286: if ($status eq 'excused');
1.41 ng 1287: $result.=$optsel;
1288: $result.="</select></td>\n";
1289: }
1290: }
1291: $result.='</tr>';
1292: return $result;
1.38 ng 1293: }
1294:
1.41 ng 1295:
1.38 ng 1296: sub editgrades {
1.41 ng 1297: my ($request) = @_;
1298:
1299: my $symb=$ENV{'form.symb'};
1300: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
1301: my $url=$ENV{'form.url'};
1.34 ng 1302:
1.41 ng 1303: my $result.='<form action="/adm/grades" method="post">'."\n".
1304: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1305: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 1306: '<input type="hidden" name="command" value="viewgrades" />'."\n".
1.41 ng 1307: '<input type="submit" name="submit" value="See Grades" /> <br />'."\n";
1308:
1309: my (@parts) = &getpartlist($url);
1310: my ($classlist) = &getclasslist($ENV{'form.section'},'0');
1311: foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
1312: $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1313: }
1.35 ng 1314:
1.41 ng 1315: $result.='<input type="submit" name="submit" value="See Grades" /></table></form>';
1316: return $result;
1.38 ng 1317: }
1.42 ! ng 1318:
! 1319:
! 1320: #FIXME need to look at the metadata <stores> spec on what type of data to accept and provide an
! 1321: #interface based on that, also do that to above function.
! 1322: sub setstudentgrade {
! 1323: my ($url,$symb,$courseid,$student,@parts) = @_;
! 1324: my $result ='';
! 1325: my ($stuname,$domain) = split(/:/,$student);
! 1326: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
! 1327: my %newrecord;
! 1328:
! 1329: foreach my $part (@parts) {
! 1330: my ($temp,$part,$type)=split(/_/,$part);
! 1331: my $oldscore=$record{"resource.$part.$type"};
! 1332: my $newscore=$ENV{"form.GRADE.$student.$part.$type"};
! 1333: if ($type eq 'solved') {
! 1334: my $update=0;
! 1335: if ($newscore eq 'nothing' ) {
! 1336: if ($oldscore ne '') {
! 1337: $update=1;
! 1338: $newscore = '';
! 1339: }
! 1340: } elsif ($oldscore !~ m/^$newscore/) {
! 1341: $update=1;
! 1342: $result.="Updating $stuname to $newscore<br />\n";
! 1343: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
! 1344: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
! 1345: if ($newscore eq 'excused') { $newscore = 'excused'; }
! 1346: if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
! 1347: } else {
! 1348: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
! 1349: }
! 1350: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
! 1351: } else {
! 1352: if ($oldscore ne $newscore) {
! 1353: $newrecord{"resource.$part.$type"}=$newscore;
! 1354: $result.="Updating $student"."'s status for $part.$type to $newscore<br />\n";
! 1355: } else {
! 1356: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
! 1357: }
! 1358: }
! 1359: }
! 1360: if ( scalar(keys(%newrecord)) > 0 ) {
! 1361: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
! 1362: # &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
! 1363:
! 1364: $result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
! 1365: }
! 1366: return $result;
! 1367: }
! 1368:
1.38 ng 1369:
1370: sub sub_page_js {
1.41 ng 1371: my $request = shift;
1372: $request->print(<<SUBJAVASCRIPT);
1.38 ng 1373: <script type="text/javascript" language="javascript">
1.39 ng 1374: function updateRadio(radioButton,formtextbox,formsel,scores) {
1.38 ng 1375: var pts = formtextbox.value;
1376: var resetbox =false;
1377: if (isNaN(pts) || pts < 0) {
1378: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
1379: for (var i=0; i<radioButton.length; i++) {
1380: if (radioButton[i].checked) {
1381: formtextbox.value = i;
1382: resetbox = true;
1383: }
1384: }
1385: if (!resetbox) {
1386: formtextbox.value = "";
1387: }
1388: return;
1389: }
1.37 ng 1390:
1.38 ng 1391: for (var i=0; i<radioButton.length; i++) {
1392: radioButton[i].checked=false;
1393: if (pts == i) {
1394: radioButton[i].checked=true;
1395: }
1396: }
1.39 ng 1397: updateSelect(formsel);
1398: scores.value = "0";
1.37 ng 1399: }
1400:
1.39 ng 1401: function writeBox(formrad,formsel,pts,scores) {
1.38 ng 1402: formrad.value = pts;
1.39 ng 1403: scores.value = "0";
1404: updateSelect(formsel,pts);
1.38 ng 1405: return;
1.31 ng 1406: }
1.34 ng 1407:
1.39 ng 1408: function clearRadBox(radioButton,formbox,formsel,scores) {
1409: for (var i=0; i<formsel.length; i++) {
1410: if (formsel[i].selected) {
1411: var selectx=i;
1412: }
1.38 ng 1413: }
1.39 ng 1414: if (selectx == scores.value) { return };
1415: formbox.value = "";
1416: for (var i=0; i<radioButton.length; i++) {
1417: radioButton[i].checked=false;
1.33 ng 1418: }
1.39 ng 1419: scores.value = selectx;
1420: }
1421:
1422: function updateSelect(formsel) {
1423: formsel[0].selected = true;
1.38 ng 1424: return;
1.33 ng 1425: }
1.37 ng 1426:
1.39 ng 1427: //===================== Show list of keywords ====================
1.38 ng 1428: function keywords(keyform) {
1429: var keywds = keyform.value;
1430: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
1431: if (nret==null) return;
1432: keyform.value = nret;
1433: return;
1.34 ng 1434: }
1.30 ng 1435:
1.41 ng 1436: //===================== Script to view submitted by ==================
1437: function viewSubmitter(submitter) {
1438: document.SCORE.refresh.value = "on";
1439: document.SCORE.NCT.value = "1";
1440: document.SCORE.unamedom0.value = submitter;
1441: document.SCORE.submit();
1442: return;
1443: }
1444:
1.38 ng 1445: //===================== Script to add keyword(s) ==================
1446: function getSel() {
1447: if (document.getSelection) txt = document.getSelection();
1448: else if (document.selection) txt = document.selection.createRange().text;
1449: else return;
1450: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1451: if (cleantxt=="") {
1452: alert("Select a word or group of words from document and then click this link.");
1453: return;
1.35 ng 1454: }
1.38 ng 1455: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1456: if (nret==null) return;
1457: var curlist = document.SCORE.keywords.value;
1458: document.SCORE.keywords.value = curlist+" "+nret;
1459: return;
1.35 ng 1460: }
1461:
1.38 ng 1462: //====================== Script for composing message ==============
1463: function msgCenter(msgform,usrctr,fullname) {
1464: var Nmsg = msgform.savemsgN.value;
1465: savedMsgHeader(Nmsg,usrctr,fullname);
1466: var subject = msgform.msgsub.value;
1467: var rtrchk = eval("document.SCORE.includemsg"+usrctr);
1468: var msgchk = rtrchk.value;
1469: // alert("checked=>"+msgchk);
1470: re = /msgsub/;
1471: var shwsel = "";
1472: if (re.test(msgchk)) { shwsel = "checked" }
1473: displaySubject(subject,shwsel);
1474: for (var i=1; i<=Nmsg; i++) {
1475: var testpt = "savemsg"+i+",";
1476: re = /testpt/;
1477: shwsel = "";
1478: if (re.test(msgchk)) { shwsel = "checked" }
1479: var message = eval("document.SCORE.savemsg"+i+".value");
1480: displaySavedMsg(i,message,shwsel);
1481: }
1482: newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
1483: shwsel = "";
1484: re = /newmsg/;
1485: if (re.test(msgchk)) { shwsel = "checked" }
1486: newMsg(newmsg,shwsel);
1487: msgTail();
1488: return;
1.35 ng 1489: }
1490:
1.38 ng 1491: function savedMsgHeader(Nmsg,usrctr,fullname) {
1492: var height = 30*Nmsg+250;
1493: var scrollbar = "no";
1494: if (height > 600) {
1495: height = 600;
1496: scrollbar = "yes";
1497: }
1498: /* if (window.pWin)
1499: window.pWin.close(); */
1500: pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
1501: pWin.document.write("<html><head>");
1502: pWin.document.write("<title>Message Central</title>");
1.37 ng 1503:
1.38 ng 1504: pWin.document.write("<script language=javascript>");
1505: pWin.document.write("function checkInput() {");
1506: pWin.document.write(" opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
1507: pWin.document.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
1508: pWin.document.write(" var usrctr = document.msgcenter.usrctr.value;");
1509: pWin.document.write(" var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
1510: pWin.document.write(" newval.value = document.msgcenter.newmsg.value;");
1.37 ng 1511:
1.38 ng 1512: pWin.document.write(" var msgchk = \\"\\";");
1513: pWin.document.write(" if (document.msgcenter.subchk.checked) {");
1514: pWin.document.write(" msgchk = \\"msgsub,\\";");
1515: pWin.document.write(" }");
1516: pWin.document.write( "for (var i=1; i<=nmsg; i++) {");
1517: pWin.document.write(" var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
1518: pWin.document.write(" var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
1519: pWin.document.write(" opnmsg.value = frmmsg.value;");
1520: pWin.document.write(" var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
1521: pWin.document.write(" if (chkbox.checked) {");
1522: pWin.document.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
1523: pWin.document.write(" }");
1524: pWin.document.write(" }");
1525: pWin.document.write(" if (document.msgcenter.newmsgchk.checked) {");
1526: pWin.document.write(" msgchk += \\"newmsg\\"+usrctr;");
1527: pWin.document.write(" }");
1528: pWin.document.write(" var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
1529: pWin.document.write(" includemsg.value = msgchk;");
1.37 ng 1530:
1.38 ng 1531: // pWin.document.write(" alert(\\"slected=\\"+msgchk)");
1532: pWin.document.write(" self.close()");
1.37 ng 1533:
1.38 ng 1534: pWin.document.write("}");
1.34 ng 1535:
1.38 ng 1536: pWin.document.write("<");
1537: pWin.document.write("/script>");
1.33 ng 1538:
1.38 ng 1539: pWin.document.write("</head><body bgcolor=white>");
1.37 ng 1540:
1.38 ng 1541: pWin.document.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1542: pWin.document.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1543: pWin.document.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br><br>");
1.34 ng 1544:
1.38 ng 1545: pWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1546: pWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1547: pWin.document.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1548: }
1549: function displaySubject(msg,shwsel) {
1550: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
1551: pWin.document.write("<td>Subject</td>");
1552: pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1553: pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+" \\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34 ng 1554: }
1555:
1.38 ng 1556: function displaySavedMsg(ctr,msg,shwsel) {
1557: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
1558: pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
1559: pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1560: pWin.document.write("<td><input name=\\"msg"+ctr+"\\" type=\\"text\\" value=\\""+msg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34 ng 1561: }
1562:
1.38 ng 1563: function newMsg(newmsg,shwsel) {
1564: pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
1565: pWin.document.write("<td align=\\"center\\">New</td>");
1566: pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.39 ng 1567: pWin.document.write("<td><input name=\\"newmsg\\" type=\\"text\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" value=\\""+newmsg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34 ng 1568: }
1569:
1.38 ng 1570: function msgTail() {
1571: pWin.document.write("</table>");
1572: pWin.document.write("</td></tr></table> ");
1573: pWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1574: pWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
1575: pWin.document.write("</form>");
1576: pWin.document.write("</body></html>");
1577: }
1.34 ng 1578:
1.38 ng 1579: //====================== Script for keyword highlight options ==============
1580: function kwhighlight() {
1581: var kwclr = document.SCORE.kwclr.value;
1582: var kwsize = document.SCORE.kwsize.value;
1583: var kwstyle = document.SCORE.kwstyle.value;
1584: var redsel = "";
1585: var grnsel = "";
1586: var blusel = "";
1587: if (kwclr=="red") {var redsel="checked"};
1588: if (kwclr=="green") {var grnsel="checked"};
1589: if (kwclr=="blue") {var blusel="checked"};
1590: var sznsel = "";
1591: var sz1sel = "";
1592: var sz2sel = "";
1593: if (kwsize=="0") {var sznsel="checked"};
1594: if (kwsize=="+1") {var sz1sel="checked"};
1595: if (kwsize=="+2") {var sz2sel="checked"};
1596: var synsel = "";
1597: var syisel = "";
1598: var sybsel = "";
1599: if (kwstyle=="") {var synsel="checked"};
1600: if (kwstyle=="<i>") {var syisel="checked"};
1601: if (kwstyle=="<b>") {var sybsel="checked"};
1602: highlightCentral();
1603: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1604: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1605: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1606: highlightend();
1607: return;
1.34 ng 1608: }
1609:
1610:
1.38 ng 1611: function highlightCentral() {
1612: hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
1613: hwdWin.document.write("<html><head>");
1614: hwdWin.document.write("<title>Highlight Central</title>");
1.34 ng 1615:
1.38 ng 1616: hwdWin.document.write("<script language=javascript>");
1.39 ng 1617: hwdWin.document.write("function updateChoice(flag) {");
1.38 ng 1618: hwdWin.document.write(" opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
1619: hwdWin.document.write(" opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
1620: hwdWin.document.write(" opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
1.40 ng 1621: // hwdWin.document.write(" var kwords=opener.document.SCORE.keywords.value;");
1622: // hwdWin.document.write(" alert(\\"keywords=\\"+opener.document.SCORE.keywords.value);");
1623: // hwdWin.document.write(" return;");
1624:
1.39 ng 1625: hwdWin.document.write(" if (flag==1){");
1626: hwdWin.document.write(" opener.document.SCORE.refresh.value = \\"on\\";");
1.40 ng 1627: hwdWin.document.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){");
1628: hwdWin.document.write(" opener.document.SCORE.submit();");
1629: hwdWin.document.write(" }");
1.39 ng 1630: hwdWin.document.write(" }");
1.38 ng 1631: hwdWin.document.write(" self.close()");
1632: hwdWin.document.write("}");
1.26 albertel 1633:
1.38 ng 1634: hwdWin.document.write("function radioSelection(radioButton) {");
1635: hwdWin.document.write(" var selection=null;");
1636: hwdWin.document.write(" for (var i=0; i<radioButton.length; i++) {");
1637: hwdWin.document.write(" if (radioButton[i].checked) {");
1638: hwdWin.document.write(" selection=radioButton[i].value;");
1639: hwdWin.document.write(" return selection;");
1640: hwdWin.document.write(" }");
1641: hwdWin.document.write(" }");
1642: hwdWin.document.write("}");
1.26 albertel 1643:
1.38 ng 1644: hwdWin.document.write("<");
1645: hwdWin.document.write("/script>");
1.13 albertel 1646:
1.38 ng 1647: hwdWin.document.write("</head><body bgcolor=white>");
1.13 albertel 1648:
1.38 ng 1649: hwdWin.document.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1650: hwdWin.document.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br><br>");
1.13 albertel 1651:
1.38 ng 1652: hwdWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1653: hwdWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1654: hwdWin.document.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.30 ng 1655: }
1.38 ng 1656:
1657: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1658: hwdWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
1659: hwdWin.document.write("<td align=\\"left\\">");
1660: hwdWin.document.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
1661: hwdWin.document.write("<td align=\\"left\\">");
1662: hwdWin.document.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
1663: hwdWin.document.write("<td align=\\"left\\">");
1664: hwdWin.document.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
1665: hwdWin.document.write("</tr>");
1.13 albertel 1666: }
1.5 albertel 1667:
1.38 ng 1668: function highlightend() {
1669: hwdWin.document.write("</table>");
1670: hwdWin.document.write("</td></tr></table> ");
1.40 ng 1671: hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(0)\\"> ");
1672: hwdWin.document.write("<input type=\\"button\\" value=\\"Save & Refresh\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1.38 ng 1673: hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
1674: hwdWin.document.write("</form>");
1675: hwdWin.document.write("</body></html>");
1.13 albertel 1676: }
1.5 albertel 1677:
1.38 ng 1678: </script>
1679: SUBJAVASCRIPT
1.5 albertel 1680: }
1681:
1.27 albertel 1682: sub csvupload_javascript_reverse_associate {
1683: return(<<ENDPICK);
1684: function verify(vf) {
1685: var foundsomething=0;
1686: var founduname=0;
1687: var founddomain=0;
1688: for (i=0;i<=vf.nfields.value;i++) {
1689: tw=eval('vf.f'+i+'.selectedIndex');
1690: if (i==0 && tw!=0) { founduname=1; }
1691: if (i==1 && tw!=0) { founddomain=1; }
1692: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
1693: }
1694: if (founduname==0 || founddomain==0) {
1695: alert('You need to specify at both the username and domain');
1696: return;
1697: }
1698: if (foundsomething==0) {
1699: alert('You need to specify at least one grading field');
1700: return;
1701: }
1702: vf.submit();
1703: }
1704: function flip(vf,tf) {
1705: var nw=eval('vf.f'+tf+'.selectedIndex');
1706: var i;
1707: for (i=0;i<=vf.nfields.value;i++) {
1708: //can not pick the same destination field for both name and domain
1709: if (((i ==0)||(i ==1)) &&
1710: ((tf==0)||(tf==1)) &&
1711: (i!=tf) &&
1712: (eval('vf.f'+i+'.selectedIndex')==nw)) {
1713: eval('vf.f'+i+'.selectedIndex=0;')
1714: }
1715: }
1716: }
1717: ENDPICK
1718: }
1719:
1720: sub csvupload_javascript_forward_associate {
1721: return(<<ENDPICK);
1722: function verify(vf) {
1723: var foundsomething=0;
1724: var founduname=0;
1725: var founddomain=0;
1726: for (i=0;i<=vf.nfields.value;i++) {
1727: tw=eval('vf.f'+i+'.selectedIndex');
1728: if (tw==1) { founduname=1; }
1729: if (tw==2) { founddomain=1; }
1730: if (tw>2) { foundsomething=1; }
1731: }
1732: if (founduname==0 || founddomain==0) {
1733: alert('You need to specify at both the username and domain');
1734: return;
1735: }
1736: if (foundsomething==0) {
1737: alert('You need to specify at least one grading field');
1738: return;
1739: }
1740: vf.submit();
1741: }
1742: function flip(vf,tf) {
1743: var nw=eval('vf.f'+tf+'.selectedIndex');
1744: var i;
1745: //can not pick the same destination field twice
1746: for (i=0;i<=vf.nfields.value;i++) {
1747: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1748: eval('vf.f'+i+'.selectedIndex=0;')
1749: }
1750: }
1751: }
1752: ENDPICK
1753: }
1754:
1.26 albertel 1755: sub csvuploadmap_header {
1.41 ng 1756: my ($request,$symb,$url,$datatoken,$distotal)= @_;
1757: my $result;
1758: my $javascript;
1759: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1760: $javascript=&csvupload_javascript_reverse_associate();
1761: } else {
1762: $javascript=&csvupload_javascript_forward_associate();
1763: }
1764: $request->print(<<ENDPICK);
1.26 albertel 1765: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1766: <h3>Uploading Class Grades for resource $url</h3>
1767: <hr>
1768: <h3>Identify fields</h3>
1769: Total number of records found in file: $distotal <hr />
1770: Enter as many fields as you can. The system will inform you and bring you back
1771: to this page if the data selected is insufficient to run your class.<hr />
1772: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1773: <input type="hidden" name="associate" value="" />
1774: <input type="hidden" name="phase" value="three" />
1775: <input type="hidden" name="datatoken" value="$datatoken" />
1776: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
1777: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
1778: <input type="hidden" name="upfile_associate"
1779: value="$ENV{'form.upfile_associate'}" />
1780: <input type="hidden" name="symb" value="$symb" />
1781: <input type="hidden" name="url" value="$url" />
1782: <input type="hidden" name="command" value="csvuploadassign" />
1783: <hr />
1784: <script type="text/javascript" language="Javascript">
1785: $javascript
1786: </script>
1787: ENDPICK
1.41 ng 1788: return '';
1.26 albertel 1789:
1790: }
1791:
1792: sub csvupload_fields {
1.41 ng 1793: my ($url) = @_;
1794: my (@parts) = &getpartlist($url);
1795: my @fields=(['username','Student Username'],['domain','Student Domain']);
1796: foreach my $part (sort(@parts)) {
1797: my @datum;
1798: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1799: my $name=$part;
1800: if (!$display) { $display = $name; }
1801: @datum=($name,$display);
1802: push(@fields,\@datum);
1803: }
1804: return (@fields);
1.26 albertel 1805: }
1806:
1807: sub csvuploadmap_footer {
1.41 ng 1808: my ($request,$i,$keyfields) =@_;
1809: $request->print(<<ENDPICK);
1.26 albertel 1810: </table>
1811: <input type="hidden" name="nfields" value="$i" />
1812: <input type="hidden" name="keyfields" value="$keyfields" />
1813: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
1814: </form>
1815: ENDPICK
1816: }
1817:
1818: sub csvuploadmap {
1.41 ng 1819: my ($request)= @_;
1820: my ($symb,$url)=&get_symb_and_url($request);
1821: if (!$symb) {return '';}
1822: my $datatoken;
1823: if (!$ENV{'form.datatoken'}) {
1824: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 1825: } else {
1.41 ng 1826: $datatoken=$ENV{'form.datatoken'};
1827: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 1828: }
1.41 ng 1829: my @records=&Apache::loncommon::upfile_record_sep();
1830: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
1831: my ($i,$keyfields);
1832: if (@records) {
1833: my @fields=&csvupload_fields($url);
1834: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1835: &Apache::loncommon::csv_print_samples($request,\@records);
1836: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
1837: \@fields);
1838: foreach (@fields) { $keyfields.=$_->[0].','; }
1839: chop($keyfields);
1840: } else {
1841: unshift(@fields,['none','']);
1842: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
1843: \@fields);
1844: my %sone=&Apache::loncommon::record_sep($records[0]);
1845: $keyfields=join(',',sort(keys(%sone)));
1846: }
1847: }
1848: &csvuploadmap_footer($request,$i,$keyfields);
1849: return '';
1.27 albertel 1850: }
1851:
1852: sub csvuploadassign {
1.41 ng 1853: my ($request)= @_;
1854: my ($symb,$url)=&get_symb_and_url($request);
1855: if (!$symb) {return '';}
1856: &Apache::loncommon::load_tmp_file($request);
1857: my @gradedata=&Apache::loncommon::upfile_record_sep();
1858: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1859: my %fields=();
1860: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1861: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1862: if ($ENV{'form.f'.$i} ne 'none') {
1863: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
1864: }
1865: } else {
1866: if ($ENV{'form.f'.$i} ne 'none') {
1867: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1868: }
1869: }
1.27 albertel 1870: }
1.41 ng 1871: $request->print('<h3>Assigning Grades</h3>');
1872: my $courseid=$ENV{'request.course.id'};
1.34 ng 1873: # my $cdom=$ENV{"course.$courseid.domain"};
1874: # my $cnum=$ENV{"course.$courseid.num"};
1.41 ng 1875: my ($classlist) = &getclasslist('all','1');
1876: my @skipped;
1877: my $countdone=0;
1878: foreach my $grade (@gradedata) {
1879: my %entries=&Apache::loncommon::record_sep($grade);
1880: my $username=$entries{$fields{'username'}};
1881: my $domain=$entries{$fields{'domain'}};
1882: if (!exists($$classlist{"$username:$domain"})) {
1883: push(@skipped,"$username:$domain");
1884: next;
1885: }
1886: my %grades;
1887: foreach my $dest (keys(%fields)) {
1888: if ($dest eq 'username' || $dest eq 'domain') { next; }
1889: if ($entries{$fields{$dest}} eq '') { next; }
1890: my $store_key=$dest;
1891: $store_key=~s/^stores/resource/;
1892: $store_key=~s/_/\./g;
1893: $grades{$store_key}=$entries{$fields{$dest}};
1894: }
1895: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
1896: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
1897: $domain,$username);
1898: $request->print('.');
1899: $request->rflush();
1900: $countdone++;
1901: }
1902: $request->print("<br />Stored $countdone students\n");
1903: if (@skipped) {
1904: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
1905: foreach my $student (@skipped) { $request->print("<br />$student"); }
1906: }
1907: $request->print(&view_edit_entire_class_form($symb,$url));
1908: $request->print(&show_grading_menu_form($symb,$url));
1909: return '';
1.26 albertel 1910: }
1911:
1.2 albertel 1912: sub send_header {
1.41 ng 1913: my ($request)= @_;
1914: $request->print(&Apache::lontexconvert::header());
1.6 albertel 1915: # $request->print("
1916: #<script>
1917: #remotewindow=open('','homeworkremote');
1918: #remotewindow.close();
1919: #</script>");
1.41 ng 1920: $request->print('<body bgcolor="#FFFFFF">');
1.2 albertel 1921: }
1922:
1923: sub send_footer {
1.41 ng 1924: my ($request)= @_;
1925: $request->print('</body>');
1926: $request->print(&Apache::lontexconvert::footer());
1.2 albertel 1927: }
1928:
1.1 albertel 1929: sub handler {
1.41 ng 1930: my $request=$_[0];
1931:
1932: if ($ENV{'browser.mathml'}) {
1933: $request->content_type('text/xml');
1934: } else {
1935: $request->content_type('text/html');
1936: }
1937: $request->send_http_header;
1938: return OK if $request->header_only;
1939: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1940: my $url=$ENV{'form.url'};
1941: my $symb=$ENV{'form.symb'};
1942: my $command=$ENV{'form.command'};
1943: if (!$url) {
1944: my ($temp1,$temp2);
1945: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
1946: $url = $ENV{'form.url'};
1947: }
1948: &send_header($request);
1949: if ($url eq '' && $symb eq '') {
1950: if ($ENV{'user.adv'}) {
1951: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
1952: ($ENV{'form.codethree'})) {
1953: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
1954: $ENV{'form.codethree'};
1955: my ($tsymb,$tuname,$tudom,$tcrsid)=
1956: &Apache::lonnet::checkin($token);
1957: if ($tsymb) {
1958: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
1959: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1960: $request->print(
1961: &Apache::lonnet::ssi('/res/'.$url,
1962: ('grade_username' => $tuname,
1963: 'grade_domain' => $tudom,
1964: 'grade_courseid' => $tcrsid,
1965: 'grade_symb' => $tsymb)));
1966: } else {
1967: $request->print('<h1>Not authorized: '.$token.'</h1>');
1968: }
1969: } else {
1970: $request->print('<h1>Not a valid DocID: '.$token.'</h1>');
1971: }
1.14 www 1972: } else {
1.41 ng 1973: $request->print(&Apache::lonxml::tokeninputfield());
1974: }
1975: }
1976: } else {
1977: #&Apache::lonhomework::showhashsubset(\%ENV,'^form');
1978: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
1979: if ($command eq 'submission') {
1980: &listStudents($request) if ($ENV{'form.student'} eq '');
1981: &submission($request,0,0) if ($ENV{'form.student'} ne '');
1982: } elsif ($command eq 'processGroup') {
1983: &processGroup($request);
1984: } elsif ($command eq 'gradingmenu') {
1985: $request->print(&gradingmenu($request));
1986: } elsif ($command eq 'viewgrades') {
1987: $request->print(&viewgrades($request));
1988: } elsif ($command eq 'handgrade') {
1989: $request->print(&processHandGrade($request));
1990: } elsif ($command eq 'editgrades') {
1991: $request->print(&editgrades($request));
1992: } elsif ($command eq 'verify') {
1993: $request->print(&verifyreceipt($request));
1994: } elsif ($command eq 'csvupload') {
1995: $request->print(&csvupload($request));
1996: } elsif ($command eq 'viewclasslist') {
1997: $request->print(&viewclasslist($request));
1998: } elsif ($command eq 'csvuploadmap') {
1999: $request->print(&csvuploadmap($request));
1.34 ng 2000: # } elsif ($command eq 'receiptInput') {
2001: # &receiptInput($request);
1.41 ng 2002: } elsif ($command eq 'csvuploadassign') {
2003: if ($ENV{'form.associate'} ne 'Reverse Association') {
2004: $request->print(&csvuploadassign($request));
2005: } else {
2006: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
2007: $ENV{'form.upfile_associate'} = 'reverse';
2008: } else {
2009: $ENV{'form.upfile_associate'} = 'forward';
2010: }
2011: $request->print(&csvuploadmap($request));
2012: }
1.26 albertel 2013: } else {
1.41 ng 2014: $request->print("Unknown action: $command:");
1.26 albertel 2015: }
1.2 albertel 2016: }
1.41 ng 2017: &send_footer($request);
2018: return OK;
1.1 albertel 2019: }
2020:
2021: 1;
2022:
1.13 albertel 2023: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>