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