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