Annotation of loncom/homework/grades.pm, revision 1.70
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.70 ! ng 4: # $Id: grades.pm,v 1.69 2003/02/27 22:39:11 albertel Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.13 albertel 28: # 2/9,2/13 Guy Albertelli
1.8 www 29: # 6/8 Gerd Kortemeyer
1.13 albertel 30: # 7/26 H.K. Ng
1.14 www 31: # 8/20 Gerd Kortemeyer
1.30 ng 32: # Year 2002
1.44 ng 33: # June-August H.K. Ng
1.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:
1.70 ! ng 1084: $result=&gradeBox($symb,$uname,$udom,$counter,$partid,\%record);
1.39 ng 1085:
1.41 ng 1086: $request->print($result);
1087: }
1.45 ng 1088: $result='<input type="hidden" name="partlist'.$counter.
1089: '" value="'.(join ":",@partlist).'" />'."\n";
1090: my $ctr = 0;
1091: while ($ctr < scalar(@partlist)) {
1092: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1093: $partlist[$ctr].'" />'."\n";
1094: $ctr++;
1095: }
1096: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 1097:
1098: # print end of form
1099: if ($counter == $total) {
1.45 ng 1100: my $endform='<table border="0"><tr><td>'.
1101: '<input type="hidden" name="gradeOpt" value="" />'."\n";
1102: if ($ENV{'form.handgrade'} eq 'yes') {
1103: $endform.='<input type="button" value="Save & Next" '.
1104: 'onClick="javascript:checksubmit(\'Save & Next\','.
1105: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
1106: my $ntstu ='<select name="NTSTU">'.
1107: '<option>1</option><option>2</option>'.
1108: '<option>3</option><option>5</option>'.
1109: '<option>7</option><option>10</option></select>'."\n";
1110: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
1111: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
1112: $endform.=$ntstu.'student(s) ';
1113: } else {
1114: $endform.='<input type="hidden" name="NTSTU" value="1" />'."\n";
1115: }
1116: $endform.='<input type="button" value="Next" '.
1117: 'onClick="javascript:checksubmit(\'Next\');" TARGET=_self> '."\n".
1118: '<input type="button" value="Previous" '.
1119: 'onClick="javascript:checksubmit(\'Previous\');" TARGET=_self> ';
1120: $endform.='(Next and Previous do not save the scores.)'."\n"
1121: if ($ENV{'form.handgrade'} eq 'yes');
1122: $endform.='</td><tr></table></form>';
1.50 albertel 1123: $endform.=&show_grading_menu_form($symb,$url);
1.41 ng 1124: $request->print($endform);
1125: }
1126: return '';
1.38 ng 1127: }
1128:
1.44 ng 1129: #--- Retrieve the last submission for all the parts
1.38 ng 1130: sub get_last_submission {
1.46 ng 1131: my (%returnhash)=@_;
1132: my (@string,$timestamp);
1133: if ($returnhash{'version'}) {
1134: my %lasthash=();
1135: my ($version);
1136: for ($version=1;$version<=$returnhash{'version'};$version++) {
1137: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
1138: $lasthash{$_}=$returnhash{$version.':'.$_};
1.61 albertel 1139: # if ($returnhash{$version.':'.$_} =~ /(SUBMITTED|DRAFT)$/) {
1.46 ng 1140: $timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
1.61 albertel 1141: # }
1.46 ng 1142: }
1143: }
1144: foreach ((keys %lasthash)) {
1145: if ($_ =~ /\.submission$/) {
1146: my ($partid,$foo) = split(/submission$/,$_);
1147: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1148: '<font color="red">Draft Copy</font> ' : '';
1149: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 1150: }
1151: }
1152: }
1.46 ng 1153: @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
1154: return \@string,\$timestamp;
1.38 ng 1155: }
1.35 ng 1156:
1.44 ng 1157: #--- High light keywords, with style choosen by user.
1.38 ng 1158: sub keywords_highlight {
1.44 ng 1159: my $string = shift;
1160: my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
1161: my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
1.41 ng 1162: (my $styleoff = $styleon) =~ s/\</\<\//;
1.44 ng 1163: my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
1.41 ng 1164: foreach (@keylist) {
1.60 albertel 1165: $string =~ s/\b\Q$_\E(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
1.41 ng 1166: }
1.57 matthew 1167: # This is not really the right place to do this, but I cannot find a
1168: # better one at this time. So here we go - the m in the s:::mg causes
1169: # ^ to match the beginning of a new line. So we replace(???) the beginning
1170: # of the line with <br /> to make things formatted a little better.
1171: $string =~ s:^:<br />:mg;
1.41 ng 1172: return $string;
1.38 ng 1173: }
1.36 ng 1174:
1.44 ng 1175: #--- Called from submission routine
1.38 ng 1176: sub processHandGrade {
1.41 ng 1177: my ($request) = shift;
1178: my $url = $ENV{'form.url'};
1179: my $symb = $ENV{'form.symb'};
1180: my $button = $ENV{'form.gradeOpt'};
1181: my $ngrade = $ENV{'form.NCT'};
1182: my $ntstu = $ENV{'form.NTSTU'};
1183:
1.44 ng 1184: if ($button eq 'Save & Next') {
1185: my $ctr = 0;
1186: while ($ctr < $ngrade) {
1187: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.45 ng 1188: my ($errorflag) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.44 ng 1189:
1190: my $includemsg = $ENV{'form.includemsg'.$ctr};
1191: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 1192: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.44 ng 1193: $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
1194: my (@msgnum) = split(/,/,$includemsg);
1195: foreach (@msgnum) {
1196: $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1197: }
1198: $message =~ s/\s+/ /g;
1199: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
1200: $ENV{'form.msgsub'},$message);
1201: }
1202: if ($ENV{'form.collaborator'.$ctr}) {
1203: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
1204: foreach (@collaborators) {
1205: &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
1206: $ENV{'form.unamedom'.$ctr});
1207: if ($message ne '') {
1208: $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
1209: $ENV{'form.msgsub'},
1210: $message);
1211: }
1212: }
1213: }
1214: $ctr++;
1215: }
1216: }
1217:
1218: # Keywords sorted in alphabatical order
1.41 ng 1219: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1220: my %keyhash = ();
1221: $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1222: $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
1.44 ng 1223: my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
1224: $ENV{'form.keywords'} = join(' ',@keywords);
1.41 ng 1225: $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
1226: $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
1227: $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
1228: $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
1229: $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
1230:
1.44 ng 1231: # message center - Order of message gets changed. Blank line is eliminated.
1232: # New messages are saved in ENV for the next student.
1233: # All messages are saved in nohist_handgrade.db
1.41 ng 1234: my ($ctr,$idx) = (1,1);
1235: while ($ctr <= $ENV{'form.savemsgN'}) {
1236: if ($ENV{'form.savemsg'.$ctr} ne '') {
1237: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
1238: $idx++;
1239: }
1240: $ctr++;
1241: }
1242: $ctr = 0;
1243: while ($ctr < $ngrade) {
1244: if ($ENV{'form.newmsg'.$ctr} ne '') {
1245: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1246: $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1247: $idx++;
1248: }
1249: $ctr++;
1250: }
1251: $ENV{'form.savemsgN'} = --$idx;
1252: $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
1253: my $putresult = &Apache::lonnet::put
1254: ('nohist_handgrade',\%keyhash,
1255: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1256: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1257:
1.44 ng 1258: # Called by Save & Refresh from Highlight Attribute Window
1.41 ng 1259: if ($ENV{'form.refresh'} eq 'on') {
1260: my $ctr = 0;
1261: $ENV{'form.NTSTU'}=$ngrade;
1262: while ($ctr < $ngrade) {
1.44 ng 1263: ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.41 ng 1264: &submission($request,$ctr,$ngrade-1);
1265: $ctr++;
1266: }
1267: return '';
1268: }
1.36 ng 1269:
1.44 ng 1270: # Get the next/previous one or group of students
1.41 ng 1271: my $firststu = $ENV{'form.unamedom0'};
1272: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
1273: $ctr = 2;
1274: while ($laststu eq '') {
1275: $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
1276: $ctr++;
1277: $laststu = $firststu if ($ctr > $ngrade);
1278: }
1.44 ng 1279:
1.56 matthew 1280: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.41 ng 1281: my (@parsedlist,@nextlist);
1282: my ($nextflg) = 0;
1.53 albertel 1283: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41 ng 1284: if ($nextflg == 1 && $button =~ /Next$/) {
1285: push @parsedlist,$_;
1286: }
1287: $nextflg = 1 if ($_ eq $laststu);
1288: if ($button eq 'Previous') {
1289: last if ($_ eq $firststu);
1290: push @parsedlist,$_;
1291: }
1292: }
1293: $ctr = 0;
1294: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1295: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1296: foreach my $student (@parsedlist) {
1297: my ($uname,$udom) = split(/:/,$student);
1298: if ($ENV{'form.submitonly'} eq 'yes') {
1.44 ng 1299: my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
1.41 ng 1300: my $statusflg = '';
1301: foreach (keys(%status)) {
1302: $statusflg = 1 if ($status{$_} ne 'nothing');
1.44 ng 1303: my ($foo,$partid,$foo1) = split(/\./);
1.41 ng 1304: $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
1305: }
1306: next if ($statusflg eq '');
1307: }
1308: push @nextlist,$student if ($ctr < $ntstu);
1309: $ctr++;
1310: }
1.36 ng 1311:
1.41 ng 1312: $ctr = 0;
1313: my $total = scalar(@nextlist)-1;
1.39 ng 1314:
1.41 ng 1315: foreach (sort @nextlist) {
1316: my ($uname,$udom,$submitter) = split(/:/);
1.44 ng 1317: $ENV{'form.student'} = $uname;
1318: $ENV{'form.userdom'} = $udom;
1.41 ng 1319: $ENV{'form.fullname'} = $$fullname{$_};
1320: # $ENV{'form.'.$_.':submitted_by'} = $submitter;
1321: # print "submitter=$ENV{'form.'.$_.':submitted_by'}= $submitter:<br>";
1322: &submission($request,$ctr,$total);
1323: $ctr++;
1324: }
1325: if ($total < 0) {
1326: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
1327: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
1328: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1329: $the_end.=&show_grading_menu_form ($symb,$url);
1330: $request->print($the_end);
1331: }
1332: return '';
1.38 ng 1333: }
1.36 ng 1334:
1.44 ng 1335: #---- Save the score and award for each student, if changed
1.38 ng 1336: sub saveHandGrade {
1.41 ng 1337: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
1.44 ng 1338: my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
1.41 ng 1339: my %newrecord;
1340: foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1.43 ng 1341: if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
1.58 albertel 1342: if ($record{'resource.'.$_.'.solved'} ne 'excused') {
1343: $newrecord{'resource.'.$_.'.solved'} = 'excused';
1344: if (exists($record{'resource.'.$_.'.awarded'})) {
1345: $newrecord{'resource.'.$_.'.awarded'} = '';
1346: }
1347: }
1.41 ng 1348: } else {
1.44 ng 1349: my $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
1350: $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
1351: $ENV{'form.RADVAL'.$newflg.'_'.$_});
1352: my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
1353: $ENV{'form.WGT'.$newflg.'_'.$_};
1.41 ng 1354: my $partial= $pts/$wgt;
1.44 ng 1355: $newrecord{'resource.'.$_.'.awarded'} = $partial
1356: if ($record{'resource.'.$_.'.awarded'} ne $partial);
1357: my $reckey = 'resource.'.$_.'.solved';
1.41 ng 1358: if ($partial == 0) {
1.44 ng 1359: $newrecord{$reckey} = 'incorrect_by_override'
1360: if ($record{$reckey} ne 'incorrect_by_override');
1.41 ng 1361: } else {
1.44 ng 1362: $newrecord{$reckey} = 'correct_by_override'
1363: if ($record{$reckey} ne 'correct_by_override');
1.41 ng 1364: }
1.44 ng 1365: $newrecord{'resource.'.$_.'.submitted_by'} = $submitter
1366: if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
1.41 ng 1367: }
1368: }
1.44 ng 1369:
1370: if (scalar(keys(%newrecord)) > 0) {
1.41 ng 1371: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.44 ng 1372: &Apache::lonnet::cstore(\%newrecord,$symb,
1373: $ENV{'request.course.id'},$domain,$stuname);
1.41 ng 1374: }
1375: return '';
1.36 ng 1376: }
1.38 ng 1377:
1.44 ng 1378: #--------------------------------------------------------------------------------------
1379: #
1380: #-------------------------- Next few routines handles grading by section or whole class
1381: #
1382: #--- Javascript to handle grading by section or whole class
1.42 ng 1383: sub viewgrades_js {
1384: my ($request) = shift;
1385:
1.41 ng 1386: $request->print(<<VIEWJAVASCRIPT);
1387: <script type="text/javascript" language="javascript">
1.45 ng 1388: function writePoint(partid,weight,point) {
1.42 ng 1389: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1390: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1391: if (point == "textval") {
1392: var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
1393: if (isNaN(point) || point < 0) {
1394: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1395: var resetbox = false;
1396: for (var i=0; i<radioButton.length; i++) {
1397: if (radioButton[i].checked) {
1398: textbox.value = i;
1399: resetbox = true;
1400: }
1401: }
1402: if (!resetbox) {
1403: textbox.value = "";
1404: }
1405: return;
1406: }
1.44 ng 1407: if (point > weight) {
1408: var resp = confirm("You entered a value ("+point+
1409: ") greater than the weight for the part. Accept?");
1410: if (resp == false) {
1411: textbox.value = "";
1412: return;
1413: }
1414: }
1.42 ng 1415: for (var i=0; i<radioButton.length; i++) {
1416: radioButton[i].checked=false;
1417: if (point == i) {
1418: radioButton[i].checked=true;
1419: }
1420: }
1.41 ng 1421:
1.42 ng 1422: } else {
1423: textbox.value = point;
1424: }
1.41 ng 1425: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1426: var user = eval("document.classgrade.ctr"+i+".value");
1427: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1428: "_"+partid+"_awarded");
1.43 ng 1429: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1430: "_"+partid+"_solved_s.value");
1431: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42 ng 1432: if (saveval != "correct") {
1433: scorename.value = point;
1.43 ng 1434: if (selname[0].selected != true) {
1435: selname[0].selected = true;
1436: }
1.42 ng 1437: }
1438: }
1439: var selval = eval("document.classgrade.SELVAL_"+partid);
1440: selval[0].selected = true;
1441: }
1442:
1443: function writeRadText(partid,weight) {
1444: var selval = eval("document.classgrade.SELVAL_"+partid);
1.43 ng 1445: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1446: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1.42 ng 1447: if (selval[1].selected) {
1448: for (var i=0; i<radioButton.length; i++) {
1449: radioButton[i].checked=false;
1450:
1451: }
1452: textbox.value = "";
1453:
1454: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1455: var user = eval("document.classgrade.ctr"+i+".value");
1456: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1457: "_"+partid+"_awarded");
1.43 ng 1458: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1459: "_"+partid+"_solved_s.value");
1.43 ng 1460: var selname = eval("document.classgrade.GD_"+user+
1.54 albertel 1461: "_"+partid+"_solved");
1.42 ng 1462: if (saveval != "correct") {
1463: scorename.value = "";
1464: selname[1].selected = true;
1465: }
1466: }
1.43 ng 1467: } else {
1468: for (i=0;i<document.classgrade.total.value;i++) {
1469: var user = eval("document.classgrade.ctr"+i+".value");
1470: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1471: "_"+partid+"_awarded");
1.43 ng 1472: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1473: "_"+partid+"_solved_s.value");
1.43 ng 1474: var selname = eval("document.classgrade.GD_"+user+
1.54 albertel 1475: "_"+partid+"_solved");
1.43 ng 1476: if (saveval != "correct") {
1477: scorename.value = eval("document.classgrade.GD_"+user+
1.54 albertel 1478: "_"+partid+"_awarded_s.value");;
1.43 ng 1479: selname[0].selected = true;
1480: }
1481: }
1482: }
1.42 ng 1483: }
1484:
1485: function changeSelect(partid,user) {
1.54 albertel 1486: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1487: var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.44 ng 1488: var point = textbox.value;
1489: var weight = eval("document.classgrade.weight_"+partid+".value");
1490:
1491: if (isNaN(point) || point < 0) {
1492: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1493: textbox.value = "";
1494: return;
1495: }
1496: if (point > weight) {
1497: var resp = confirm("You entered a value ("+point+
1498: ") greater than the weight of the part. Accept?");
1499: if (resp == false) {
1500: textbox.value = "";
1501: return;
1502: }
1503: }
1.42 ng 1504: selval[0].selected = true;
1505: }
1506:
1507: function changeOneScore(partid,user) {
1.54 albertel 1508: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1.42 ng 1509: if (selval[1].selected) {
1.54 albertel 1510: var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.42 ng 1511: boxval.value = "";
1512: }
1513: }
1514:
1515: function resetEntry(numpart) {
1516: for (ctpart=0;ctpart<numpart;ctpart++) {
1517: var partid = eval("document.classgrade.partid_"+ctpart+".value");
1518: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1519: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1520: var selval = eval("document.classgrade.SELVAL_"+partid);
1521: for (var i=0; i<radioButton.length; i++) {
1522: radioButton[i].checked=false;
1523:
1524: }
1525: textbox.value = "";
1526: selval[0].selected = true;
1527:
1528: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1529: var user = eval("document.classgrade.ctr"+i+".value");
1530: var resetscore = eval("document.classgrade.GD_"+user+
1.54 albertel 1531: "_"+partid+"_awarded");
1.43 ng 1532: resetscore.value = eval("document.classgrade.GD_"+user+
1.54 albertel 1533: "_"+partid+"_awarded_s.value");
1.42 ng 1534:
1.43 ng 1535: var saveselval = eval("document.classgrade.GD_"+user+
1.54 albertel 1536: "_"+partid+"_solved_s.value");
1.42 ng 1537:
1.54 albertel 1538: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42 ng 1539: if (saveselval == "excused") {
1.43 ng 1540: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 1541: } else {
1.43 ng 1542: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 1543: }
1544: }
1.41 ng 1545: }
1.42 ng 1546: }
1547:
1.41 ng 1548: </script>
1549: VIEWJAVASCRIPT
1.42 ng 1550: }
1551:
1.44 ng 1552: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 1553: sub viewgrades {
1554: my ($request) = shift;
1555: &viewgrades_js($request);
1.41 ng 1556:
1557: my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
1.45 ng 1558: my $result='<h3><font color="#339933">Manual Grading</font></h3>';
1.38 ng 1559:
1.43 ng 1560: $result.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font>'."\n";
1.41 ng 1561:
1562: #view individual student submission form - called using Javascript viewOneStudent
1.45 ng 1563: $result.=&jscriptNform($url,$symb);
1.41 ng 1564:
1.44 ng 1565: #beginning of class grading form
1.41 ng 1566: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1567: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1568: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 1569: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.41 ng 1570: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n";
1.52 albertel 1571: $result.='<h3>Assign Common Grade To ';
1572: if ($ENV{'form.section'} eq 'all') {
1573: $result.='Class </h3>';
1574: } elsif ($ENV{'form.section'} eq 'no') {
1575: $result.='Students in no Section </h3>';
1576: } else {
1577: $result.='Students in Section '.$ENV{'form.section'}.'</h3>';
1578: }
1579: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1580: '<table border=0><tr bgcolor="#ffffdd"><td>';
1581: # $result.='To assign the same score for all the students use the radio buttons or '.
1582: # 'text box below. To assign scores individually fill in the score boxes for '.
1583: # 'each student in the table below. <font color="red">A part that has already '.
1584: # 'been graded does not get changed using the radio buttons or text box. '.
1585: # 'If needed, it has to be changed individually.</font>';
1586: # $result.='</td></tr><tr><td>';
1.44 ng 1587: #radio buttons/text box for assigning points for a section or class.
1588: #handles different parts of a problem
1.42 ng 1589: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1590: my %weight = ();
1591: my $ctsparts = 0;
1.41 ng 1592: $result.='<table border="0">';
1.45 ng 1593: my %seen = ();
1.42 ng 1594: for (sort keys(%$handgrade)) {
1.54 albertel 1595: my ($partid,$respid) = split (/_/,$_,2);
1.45 ng 1596: next if $seen{$partid};
1597: $seen{$partid}++;
1.42 ng 1598: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
1599: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
1600: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
1601:
1.44 ng 1602: $result.='<input type="hidden" name="partid_'.
1603: $ctsparts.'" value="'.$partid.'" />'."\n";
1604: $result.='<input type="hidden" name="weight_'.
1605: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1606: $result.='<tr><td><b>Part '.$partid.' Point:</b> </td><td>';
1.42 ng 1607: $result.='<table border="0"><tr>';
1.41 ng 1608: my $ctr = 0;
1.42 ng 1609: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1610: $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 1611: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.41 ng 1612: ','.$ctr.')" />'.$ctr."</td>\n";
1613: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1614: $ctr++;
1615: }
1616: $result.='</tr></table>';
1.44 ng 1617: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 1618: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
1619: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 1620: $weight{$partid}.' (problem weight)</td>'."\n";
1621: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 1622: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 1623: $weight{$partid}.')"> '.
1.42 ng 1624: '<option selected="on"> </option>'.
1625: '<option>excused</option></select></td></tr>'."\n";
1626: $ctsparts++;
1.41 ng 1627: }
1.52 albertel 1628: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
1629: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 1630: $result.='<input type="button" value="Reset" '.
1.43 ng 1631: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self> ';
1.45 ng 1632: $result.='<input type="button" value="Submit Changes" '.
1633: 'onClick="javascript:submit();" TARGET=_self />'."\n";
1.41 ng 1634:
1.44 ng 1635: #table listing all the students in a section/class
1636: #header of table
1.52 albertel 1637: $result.= '<h3>Assign Grade to Specific Students in ';
1638: if ($ENV{'form.section'} eq 'all') {
1639: $result.='the Class </h3>';
1640: } elsif ($ENV{'form.section'} eq 'no') {
1641: $result.='no Section </h3>';
1642: } else {
1643: $result.='Section '.$ENV{'form.section'}.'</h3>';
1644: }
1.42 ng 1645: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.41 ng 1646: '<table border=0><tr bgcolor="#deffff">'.
1.44 ng 1647: '<td><b>Fullname</b></td><td><b>Username</b></td><td><b>Domain</b></td>'."\n";
1.41 ng 1648: my (@parts) = sort(&getpartlist($url));
1649: foreach my $part (@parts) {
1650: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1651: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1652: if ($display =~ /^Partial Credit Factor/) {
1.54 albertel 1653: my ($partid) = &split_part_type($part);
1.53 albertel 1654: $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
1.42 ng 1655: $weight{$partid}.')</b></td>'."\n";
1.41 ng 1656: next;
1657: }
1.53 albertel 1658: $display =~ s|Problem Status|Grade Status<br />|;
1.41 ng 1659: $result.='<td><b>'.$display.'</b></td>'."\n";
1660: }
1661: $result.='</tr>';
1.44 ng 1662:
1.41 ng 1663: #get info for each student
1.44 ng 1664: #list all the students - with points and grade status
1.56 matthew 1665: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.41 ng 1666: my $ctr = 0;
1.53 albertel 1667: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44 ng 1668: my ($uname,$udom) = split(/:/);
1669: $result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
1.41 ng 1670: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
1671: $_,$$fullname{$_},\@parts,\%weight);
1672: $ctr++;
1673: }
1674: $result.='</table></td></tr></table>';
1675: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.45 ng 1676: $result.='<input type="button" value="Submit Changes" '.
1677: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.41 ng 1678: $result.=&show_grading_menu_form($symb,$url);
1679: return $result;
1680: }
1681:
1.44 ng 1682: #--- call by previous routine to display each student
1.41 ng 1683: sub viewstudentgrade {
1684: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
1.44 ng 1685: my ($uname,$udom) = split(/:/,$student);
1686: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.41 ng 1687: my $result='<tr bgcolor="#ffffdd"><td>'.
1.44 ng 1688: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1689: '\')"; TARGET=_self>'.$fullname.'</a>'.
1690: '</td><td>'.$uname.'</td><td align="middle">'.$udom.'</td>'."\n";
1.63 albertel 1691: foreach my $apart (@$parts) {
1692: my ($part,$type) = &split_part_type($apart);
1.41 ng 1693: my $score=$record{"resource.$part.$type"};
1694: if ($type eq 'awarded') {
1.42 ng 1695: my $pts = $score eq '' ? '' : $score*$$weight{$part};
1696: $result.='<input type="hidden" name="'.
1.54 albertel 1697: 'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.42 ng 1698: $result.='<td align="middle"><input type="text" name="'.
1.54 albertel 1699: 'GD_'.$uname.'_'.$part.'_awarded" '.
1700: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$uname.
1.44 ng 1701: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 1702: } elsif ($type eq 'solved') {
1703: my ($status,$foo)=split(/_/,$score,2);
1704: $status = 'nothing' if ($status eq '');
1.54 albertel 1705: $result.='<input type="hidden" name="'.'GD_'.$uname.'_'.
1706: $part.'_solved_s" value="'.$status.'" />'."\n";
1.42 ng 1707: $result.='<td align="middle"><select name="'.
1.54 albertel 1708: 'GD_'.$uname.'_'.$part.'_solved" '.
1709: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$uname.'\')" >'."\n";
1.42 ng 1710: my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
1711: $optsel = '<option> </option><option selected="on">excused</option>'."\n"
1712: if ($status eq 'excused');
1.41 ng 1713: $result.=$optsel;
1714: $result.="</select></td>\n";
1.54 albertel 1715: } else {
1716: $result.='<input type="hidden" name="'.
1717: 'GD_'.$uname.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
1718: "\n";
1719: $result.='<td align="middle"><input type="text" name="'.
1720: 'GD_'.$uname.'_'.$part.'_'.$type.'" '.
1721: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 1722: }
1723: }
1724: $result.='</tr>';
1725: return $result;
1.38 ng 1726: }
1727:
1.44 ng 1728: #--- change scores for all the students in a section/class
1729: # record does not get update if unchanged
1.38 ng 1730: sub editgrades {
1.41 ng 1731: my ($request) = @_;
1732:
1733: my $symb=$ENV{'form.symb'};
1.43 ng 1734: my $url =$ENV{'form.url'};
1.45 ng 1735: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.44 ng 1736: $title.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font><br />'."\n";
1737: $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
1738: $title.= &show_grading_menu_form ($symb,$url);
1739: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.43 ng 1740: $result.= '<table border="0"><tr bgcolor="#deffff">'.
1741: '<td rowspan=2><b>Username</b></td><td rowspan=2><b>Fullname</b></td>'."\n";
1742:
1743: my %scoreptr = (
1744: 'correct' =>'correct_by_override',
1745: 'incorrect'=>'incorrect_by_override',
1746: 'excused' =>'excused',
1747: 'ungraded' =>'ungraded_attempted',
1748: 'nothing' => '',
1749: );
1.56 matthew 1750: my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.34 ng 1751:
1.44 ng 1752: my (@partid);
1753: my %weight = ();
1.54 albertel 1754: my %columns = ();
1.44 ng 1755: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 1756:
1757: my (@parts) = sort(&getpartlist($url));
1758: my $header;
1.44 ng 1759: while ($ctr < $ENV{'form.totalparts'}) {
1760: my $partid = $ENV{'form.partid_'.$ctr};
1761: push @partid,$partid;
1762: $weight{$partid} = $ENV{'form.weight_'.$partid};
1763: $ctr++;
1.54 albertel 1764: }
1765: foreach my $partid (@partid) {
1766: $header .= '<td align="center"> <b>Old Score</b> </td>'.
1767: '<td align="center"> <b>New Score</b> </td>';
1768: $columns{$partid}=2;
1769: foreach my $stores (@parts) {
1770: my ($part,$type) = &split_part_type($stores);
1771: if ($part !~ m/^\Q$partid\E/) { next;}
1772: if ($type eq 'awarded' || $type eq 'solved') { next; }
1773: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1774: $display =~ s/\[Part: (\w)+\]//;
1775: $header .= '<td align="center"> <b>Old</b> '.$display.' </td>'.
1776: '<td align="center"> <b>New</b> '.$display.' </td>';
1777: $columns{$partid}+=2;
1778: }
1779: }
1780: foreach my $partid (@partid) {
1781: $result .= '<td colspan="'.$columns{$partid}.
1782: '" align="center"><b>Part '.$partid.
1.44 ng 1783: '</b> (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 1784:
1.44 ng 1785: }
1786: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 1787: $result .= $header;
1.44 ng 1788: $result .= '</tr>'."\n";
1.13 albertel 1789:
1.44 ng 1790: for ($i=0; $i<$ENV{'form.total'}; $i++) {
1791: my $user = $ENV{'form.ctr'.$i};
1792: my %newrecord;
1793: my $updateflag = 0;
1794: my @userdom = grep /^$user:/,keys %$classlist;
1.54 albertel 1795: my (undef,$udom) = split(/:/,$userdom[0]);
1.13 albertel 1796:
1.44 ng 1797: $result .= '<tr bgcolor="#ffffde"><td>'.$user.' </td><td>'.
1798: $$fullname{$userdom[0]}.' </td>';
1799: foreach (@partid) {
1.54 albertel 1800: my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1801: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
1802: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1803: my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1804:
1805: my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
1806: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
1807: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 1808: my $score;
1809: if ($partial eq '') {
1.54 albertel 1810: $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 1811: } elsif ($partial > 0) {
1812: $score = 'correct_by_override';
1813: } elsif ($partial == 0) {
1814: $score = 'incorrect_by_override';
1815: }
1.54 albertel 1816: $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
1.44 ng 1817: ($score ne 'excused'));
1818: $result .= '<td align="center">'.$old_aw.' </td>'.
1819: '<td align="center">'.$awarded.
1820: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 1821:
1.54 albertel 1822: if (!($old_part eq $partial && $old_score eq $score)) {
1823: $updateflag = 1;
1824: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
1825: $newrecord{'resource.'.$_.'.solved'} = $score;
1826: $rec_update++;
1827: }
1828:
1829: my $partid=$_;
1830: foreach my $stores (@parts) {
1831: my ($part,$type) = &split_part_type($stores);
1832: if ($part !~ m/^\Q$partid\E/) { next;}
1833: if ($type eq 'awarded' || $type eq 'solved') { next; }
1834: my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
1835: my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
1836: if ($awarded ne '' && $awarded ne $old_aw) {
1837: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1838: $updateflag=1;
1839: }
1840: $result .= '<td align="center">'.$old_aw.' </td>'.
1841: '<td align="center">'.$awarded.' </td>';
1842: }
1.44 ng 1843: }
1844: $result .= '</tr>'."\n";
1845: if ($updateflag) {
1846: $count++;
1847: $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1848: &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
1849: $udom,$user);
1850: }
1851: }
1852: $result .= '</table></td></tr></table>'."\n";
1853: my $msg = '<b>Number of records updated = '.$rec_update.
1854: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1855: '<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
1856: return $title.$msg.$result;
1.5 albertel 1857: }
1.54 albertel 1858:
1859: sub split_part_type {
1860: my ($partstr) = @_;
1861: my ($temp,@allparts)=split(/_/,$partstr);
1862: my $type=pop(@allparts);
1863: my $part=join('.',@allparts);
1864: return ($part,$type);
1865: }
1866:
1.44 ng 1867: #------------- end of section for handling grading by section/class ---------
1868: #
1869: #----------------------------------------------------------------------------
1870:
1.5 albertel 1871:
1.44 ng 1872: #----------------------------------------------------------------------------
1873: #
1874: #-------------------------- Next few routines handles grading by csv upload
1875: #
1876: #--- Javascript to handle csv upload
1.27 albertel 1877: sub csvupload_javascript_reverse_associate {
1878: return(<<ENDPICK);
1879: function verify(vf) {
1880: var foundsomething=0;
1881: var founduname=0;
1882: var founddomain=0;
1883: for (i=0;i<=vf.nfields.value;i++) {
1884: tw=eval('vf.f'+i+'.selectedIndex');
1885: if (i==0 && tw!=0) { founduname=1; }
1886: if (i==1 && tw!=0) { founddomain=1; }
1887: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
1888: }
1889: if (founduname==0 || founddomain==0) {
1890: alert('You need to specify at both the username and domain');
1891: return;
1892: }
1893: if (foundsomething==0) {
1894: alert('You need to specify at least one grading field');
1895: return;
1896: }
1897: vf.submit();
1898: }
1899: function flip(vf,tf) {
1900: var nw=eval('vf.f'+tf+'.selectedIndex');
1901: var i;
1902: for (i=0;i<=vf.nfields.value;i++) {
1903: //can not pick the same destination field for both name and domain
1904: if (((i ==0)||(i ==1)) &&
1905: ((tf==0)||(tf==1)) &&
1906: (i!=tf) &&
1907: (eval('vf.f'+i+'.selectedIndex')==nw)) {
1908: eval('vf.f'+i+'.selectedIndex=0;')
1909: }
1910: }
1911: }
1912: ENDPICK
1913: }
1914:
1915: sub csvupload_javascript_forward_associate {
1916: return(<<ENDPICK);
1917: function verify(vf) {
1918: var foundsomething=0;
1919: var founduname=0;
1920: var founddomain=0;
1921: for (i=0;i<=vf.nfields.value;i++) {
1922: tw=eval('vf.f'+i+'.selectedIndex');
1923: if (tw==1) { founduname=1; }
1924: if (tw==2) { founddomain=1; }
1925: if (tw>2) { foundsomething=1; }
1926: }
1927: if (founduname==0 || founddomain==0) {
1928: alert('You need to specify at both the username and domain');
1929: return;
1930: }
1931: if (foundsomething==0) {
1932: alert('You need to specify at least one grading field');
1933: return;
1934: }
1935: vf.submit();
1936: }
1937: function flip(vf,tf) {
1938: var nw=eval('vf.f'+tf+'.selectedIndex');
1939: var i;
1940: //can not pick the same destination field twice
1941: for (i=0;i<=vf.nfields.value;i++) {
1942: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
1943: eval('vf.f'+i+'.selectedIndex=0;')
1944: }
1945: }
1946: }
1947: ENDPICK
1948: }
1949:
1.26 albertel 1950: sub csvuploadmap_header {
1.41 ng 1951: my ($request,$symb,$url,$datatoken,$distotal)= @_;
1952: my $javascript;
1953: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1954: $javascript=&csvupload_javascript_reverse_associate();
1955: } else {
1956: $javascript=&csvupload_javascript_forward_associate();
1957: }
1.45 ng 1958:
1959: my $result='<table border="0">';
1960: $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
1961: my ($partlist,$handgrade) = &response_type($url);
1962: my ($resptype,$hdgrade)=('','no');
1963: for (sort keys(%$handgrade)) {
1964: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
1965: $resptype = $responsetype;
1966: $hdgrade = $handgrade if ($handgrade eq 'yes');
1967: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
1968: '<td><b>Type: </b>'.$responsetype.'</td>'.
1969: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
1970: }
1971: $result.='</table>';
1.41 ng 1972: $request->print(<<ENDPICK);
1.26 albertel 1973: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 1974: <h3><font color="#339933">Uploading Class Grades</font></h3>
1975: $result
1.26 albertel 1976: <hr>
1977: <h3>Identify fields</h3>
1978: Total number of records found in file: $distotal <hr />
1979: Enter as many fields as you can. The system will inform you and bring you back
1980: to this page if the data selected is insufficient to run your class.<hr />
1981: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1982: <input type="hidden" name="associate" value="" />
1983: <input type="hidden" name="phase" value="three" />
1984: <input type="hidden" name="datatoken" value="$datatoken" />
1985: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
1986: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
1987: <input type="hidden" name="upfile_associate"
1988: value="$ENV{'form.upfile_associate'}" />
1989: <input type="hidden" name="symb" value="$symb" />
1990: <input type="hidden" name="url" value="$url" />
1991: <input type="hidden" name="command" value="csvuploadassign" />
1992: <hr />
1993: <script type="text/javascript" language="Javascript">
1994: $javascript
1995: </script>
1996: ENDPICK
1.41 ng 1997: return '';
1.26 albertel 1998:
1999: }
2000:
2001: sub csvupload_fields {
1.41 ng 2002: my ($url) = @_;
2003: my (@parts) = &getpartlist($url);
2004: my @fields=(['username','Student Username'],['domain','Student Domain']);
2005: foreach my $part (sort(@parts)) {
2006: my @datum;
2007: my $display=&Apache::lonnet::metadata($url,$part.'.display');
2008: my $name=$part;
2009: if (!$display) { $display = $name; }
2010: @datum=($name,$display);
2011: push(@fields,\@datum);
2012: }
2013: return (@fields);
1.26 albertel 2014: }
2015:
2016: sub csvuploadmap_footer {
1.41 ng 2017: my ($request,$i,$keyfields) =@_;
2018: $request->print(<<ENDPICK);
1.26 albertel 2019: </table>
2020: <input type="hidden" name="nfields" value="$i" />
2021: <input type="hidden" name="keyfields" value="$keyfields" />
2022: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
2023: </form>
2024: ENDPICK
2025: }
2026:
2027: sub csvuploadmap {
1.41 ng 2028: my ($request)= @_;
2029: my ($symb,$url)=&get_symb_and_url($request);
2030: if (!$symb) {return '';}
2031: my $datatoken;
2032: if (!$ENV{'form.datatoken'}) {
2033: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 2034: } else {
1.41 ng 2035: $datatoken=$ENV{'form.datatoken'};
2036: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 2037: }
1.41 ng 2038: my @records=&Apache::loncommon::upfile_record_sep();
2039: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
2040: my ($i,$keyfields);
2041: if (@records) {
2042: my @fields=&csvupload_fields($url);
1.45 ng 2043:
1.41 ng 2044: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2045: &Apache::loncommon::csv_print_samples($request,\@records);
2046: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
2047: \@fields);
2048: foreach (@fields) { $keyfields.=$_->[0].','; }
2049: chop($keyfields);
2050: } else {
2051: unshift(@fields,['none','']);
2052: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
2053: \@fields);
2054: my %sone=&Apache::loncommon::record_sep($records[0]);
2055: $keyfields=join(',',sort(keys(%sone)));
2056: }
2057: }
2058: &csvuploadmap_footer($request,$i,$keyfields);
2059: return '';
1.27 albertel 2060: }
2061:
2062: sub csvuploadassign {
1.41 ng 2063: my ($request)= @_;
2064: my ($symb,$url)=&get_symb_and_url($request);
2065: if (!$symb) {return '';}
2066: &Apache::loncommon::load_tmp_file($request);
1.44 ng 2067: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.41 ng 2068: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
2069: my %fields=();
2070: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
2071: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2072: if ($ENV{'form.f'.$i} ne 'none') {
2073: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
2074: }
2075: } else {
2076: if ($ENV{'form.f'.$i} ne 'none') {
2077: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
2078: }
2079: }
1.27 albertel 2080: }
1.41 ng 2081: $request->print('<h3>Assigning Grades</h3>');
2082: my $courseid=$ENV{'request.course.id'};
2083: my ($classlist) = &getclasslist('all','1');
2084: my @skipped;
2085: my $countdone=0;
2086: foreach my $grade (@gradedata) {
2087: my %entries=&Apache::loncommon::record_sep($grade);
2088: my $username=$entries{$fields{'username'}};
2089: my $domain=$entries{$fields{'domain'}};
2090: if (!exists($$classlist{"$username:$domain"})) {
2091: push(@skipped,"$username:$domain");
2092: next;
2093: }
2094: my %grades;
2095: foreach my $dest (keys(%fields)) {
2096: if ($dest eq 'username' || $dest eq 'domain') { next; }
2097: if ($entries{$fields{$dest}} eq '') { next; }
2098: my $store_key=$dest;
2099: $store_key=~s/^stores/resource/;
2100: $store_key=~s/_/\./g;
2101: $grades{$store_key}=$entries{$fields{$dest}};
2102: }
2103: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
2104: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
2105: $domain,$username);
2106: $request->print('.');
2107: $request->rflush();
2108: $countdone++;
2109: }
2110: $request->print("<br />Stored $countdone students\n");
2111: if (@skipped) {
2112: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
2113: foreach my $student (@skipped) { $request->print("<br />$student"); }
2114: }
2115: $request->print(&view_edit_entire_class_form($symb,$url));
2116: $request->print(&show_grading_menu_form($symb,$url));
2117: return '';
1.26 albertel 2118: }
1.44 ng 2119: #------------- end of section for handling csv file upload ---------
2120: #
2121: #-------------------------------------------------------------------
2122:
2123: #-------------------------- Menu interface -------------------------
2124: #
2125: #--- Show a Grading Menu button - Calls the next routine ---
2126: sub show_grading_menu_form {
2127: my ($symb,$url)=@_;
2128: my $result.='<form action="/adm/grades" method="post">'."\n".
2129: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2130: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2131: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
2132: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
2133: '</form>'."\n";
2134: return $result;
2135: }
2136:
2137: #--- Displays the main menu page -------
2138: sub gradingmenu {
2139: my ($request) = @_;
2140: my ($symb,$url)=&get_symb_and_url($request);
2141: if (!$symb) {return '';}
1.45 ng 2142: my $result='<h3> <font color="#339933">Select a Grading Method</font></h3>';
1.44 ng 2143: $result.='<table border="0">';
2144: $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
2145: my ($partlist,$handgrade) = &response_type($url);
2146: my ($resptype,$hdgrade)=('','no');
2147: for (sort keys(%$handgrade)) {
2148: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
2149: $resptype = $responsetype;
2150: $hdgrade = $handgrade if ($handgrade eq 'yes');
2151: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
2152: '<td><b>Type: </b>'.$responsetype.'</td>'.
2153: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
2154: }
2155: $result.='</table>';
2156: $result.=&view_edit_entire_class_form($symb,$url).'<br />';
2157: $result.=&upcsvScores_form($symb,$url).'<br />';
2158: $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';
1.68 ng 2159: $result.=&gradeByPage_form($symb,$url,$resptype,$hdgrade).'<br />';
1.44 ng 2160: $result.=&verifyReceipt_form($symb,$url)
2161: if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb));
2162:
2163: return $result;
2164: }
2165:
2166: #--- Menu for grading a section or the whole class ---
2167: sub view_edit_entire_class_form {
2168: my ($symb,$url)=@_;
1.56 matthew 2169: my ($classlist,$sections,undef) = &getclasslist('all','0');
1.44 ng 2170: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
2171: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.52 albertel 2172: $result.=' <b>Grade Entire Section or Class</b></td></tr>'."\n";
1.44 ng 2173: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2174: $result.='<form action="/adm/grades" method="post">'."\n".
2175: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2176: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2177: '<input type="hidden" name="command" value="viewgrades" />'."\n";
2178: $result.=' <b>Select section:</b> <select name="section">'."\n";
1.49 albertel 2179: if (ref($sections)) {
2180: foreach (sort (@$sections)) {
2181: $result.= '<option>'.$_.'</option>'."\n";
2182: }
1.44 ng 2183: }
2184: $result.='<option selected="on">all</select>'."<br />\n";
1.51 albertel 2185: $result.=' <input type="button" onClick="submit();" value="Grade" /></form>'."\n";
1.44 ng 2186: $result.='</td></tr></table>'."\n";
2187: $result.='</td></tr></table>'."\n";
2188: return $result;
2189: }
2190:
2191: #--- Menu to upload a csv scores ---
2192: sub upcsvScores_form {
2193: my ($symb,$url) = @_;
2194: if (!$symb) {return '';}
1.46 ng 2195: my $result = '<script type="text/javascript" language="javascript">'."\n".
2196: ' function checkUpload(formname) {'."\n".
2197: ' if (formname.upfile.value == "") {'."\n".
2198: ' alert("Please use the browse button to select a file from your local directory.");'."\n".
2199: ' return false;'."\n".
2200: ' }'."\n".
2201: ' formname.submit();'."\n".
2202: ' }'."\n".
2203: '</script>'."\n";
2204:
2205: $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1.44 ng 2206: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
2207: $result.=' <b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
2208: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2209: my $upfile_select=&Apache::loncommon::upfile_select_html();
2210: $result.=<<ENDUPFORM;
2211: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
2212: <input type="hidden" name="symb" value="$symb" />
2213: <input type="hidden" name="url" value="$url" />
2214: <input type="hidden" name="command" value="csvuploadmap" />
2215: $upfile_select
1.46 ng 2216: <br /> <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Grades" />
1.44 ng 2217: </form>
2218: ENDUPFORM
2219: $result.='</td></tr></table>'."\n";
2220: $result.='</td></tr></table>'."\n";
2221: return $result;
2222: }
2223:
2224: #--- Handgrading problems ---
2225: sub viewGradeaStu_form {
2226: my ($symb,$url,$response,$handgrade) = @_;
2227: my ($classlist,$sections) = &getclasslist('all','0');
2228: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
2229: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.49 albertel 2230: $result.=' <b>';
1.68 ng 2231: $result.=($handgrade eq 'yes' ? 'View/Grade' : 'View').' an Individual Student\'s Submission</b></td></tr>'."\n";
1.44 ng 2232: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2233: $result.='<form action="/adm/grades" method="post">'."\n".
2234: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2235: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2236: '<input type="hidden" name="response" value="'.$response.'" />'."\n".
2237: '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
2238: '<input type="hidden" name="showgrading" value="yes" />'."\n".
2239: '<input type="hidden" name="command" value="submission" />'."\n";
1.26 albertel 2240:
1.44 ng 2241: $result.=' <b>Select section:</b> <select name="section">'."\n";
1.49 albertel 2242: if (ref($sections)) {
2243: foreach (sort (@$sections)) {$result.='<option>'.$_.'</option>'."\n";}
1.44 ng 2244: }
2245: $result.= '<option selected="on">all</select>'."\n";
2246: $result.=' <b>Display students who has: </b>'.
2247: '<input type="radio" name="submitonly" value="yes" checked> submitted'.
2248: '<input type="radio" name="submitonly" value="all"> everybody <br />';
1.49 albertel 2249: if (ref($sections)) {
2250: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
2251: if (grep /no/,@$sections);
2252: }
2253:
2254:
2255: $result.='<br /> <input type="button" onClick="submit();" value="';
2256: if ($handgrade eq 'yes') {
2257: $result.="View/Grade";
2258: } else {
2259: $result.="View";
2260: }
2261: $result.='" />'."\n".'</form>'."\n";
1.44 ng 2262: $result.='</td></tr></table>'."\n";
2263: $result.='</td></tr></table>'."\n";
2264: return $result;
1.2 albertel 2265: }
2266:
1.68 ng 2267: #--- Handgrading problems by page/sequence for each student ---
2268: sub gradeByPage_form {
2269: my ($symb,$url,$response,$handgrade) = @_;
2270: my ($classlist,$sections) = &getclasslist('all','0');
2271: my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
2272: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
2273: $result.=' <b>';
2274: $result.='Handgrade an Individual Student\'s by Page/Sequence</b></td></tr>'."\n";
2275: $result.='<tr bgcolor=#ffffe6><td>'."\n";
2276: $result.='<form action="/adm/grades" method="post">'."\n".
2277: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2278: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2279: '<input type="hidden" name="response" value="'.$response.'" />'."\n".
2280: '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
2281: '<input type="hidden" name="showgrading" value="yes" />'."\n".
2282: '<input type="hidden" name="command" value="pickStudentPage" />'."\n";
2283:
2284: $result.=' <b>Select section:</b> <select name="section">'."\n";
2285: if (ref($sections)) {
2286: foreach (sort (@$sections)) {$result.='<option>'.$_.'</option>'."\n";}
2287: }
2288: $result.= '<option selected="on">all</select>'."\n";
2289:
2290: $result.='<br /> <input type="button" onClick="submit();" value="';
2291: $result.='View/Grade'.'" />'."\n".'</form>'."\n";
2292: $result.='</td></tr></table>'."\n";
2293: $result.='</td></tr></table>'."\n";
2294: return $result;
2295: }
2296:
2297:
2298: sub pickStudentPage {
2299: my ($request) = shift;
2300:
2301: $request->print(<<LISTJAVASCRIPT);
2302: <script type="text/javascript" language="javascript">
2303:
2304: function checkPickOne(formname) {
1.70 ! ng 2305: var user = radioSelection(formname.student);
1.68 ng 2306: if (user == null) {
2307: alert("Please select the student you wish to grade.");
2308: return;
2309: }
1.70 ! ng 2310: var ptr = pullDownSelection(formname.selectpage);
! 2311: formname.page.value = formname.eval("page"+ptr).value;
! 2312: formname.title.value = formname.eval("title"+ptr).value;
1.68 ng 2313: formname.submit();
2314: }
2315:
2316: function radioSelection(radioButton) {
2317: var selection=null;
2318: for (var i=0; i<radioButton.length; i++) {
2319: if (radioButton[i].checked) {
2320: selection=radioButton[i].value;
2321: return selection;
2322: }
2323: }
2324: return selection;
2325: }
1.70 ! ng 2326:
! 2327: function pullDownSelection(selectOne) {
! 2328: var selection=null;
! 2329: for (var i=0; i<selectOne.length; i++) {
! 2330: if (selectOne[i].selected) {
! 2331: selection=selectOne[i].value;
! 2332: return selection;
! 2333: }
! 2334: }
! 2335: }
1.68 ng 2336: </script>
2337: LISTJAVASCRIPT
2338:
2339: my ($symb,$url) = &get_symb_and_url();
2340: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2341: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2342: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2343:
2344: my $result='<h3><font color="#339933"> '.
2345: 'Manual Grading by Page or Sequence</font></h3>';
2346:
2347: my ($pagepath,$pagename,$type,$mapId) = ($symb =~ /(.*\/)(.*?\.(page|sequence))___(\d+)___/);
2348: my $curtitle = &Apache::lonnet::metadata($pagepath.$pagename,'title');
2349:
2350: $result.='<form action="/adm/grades" method="post" name="displayPage">'."<br>\n";
1.70 ! ng 2351: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.68 ng 2352: my ($titles,$symbx) = &getSymbMap();
2353: # shift @$titles; # skip the top level sequence
1.70 ! ng 2354: my $ctr=0;
1.68 ng 2355: foreach (@$titles) {
2356: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ! ng 2357: $result.='<option value="'.$ctr.'" '.
! 2358: ($showtitle eq $curtitle ? 'selected="on"' : '').'>'.$showtitle.'</option>'."\n";
! 2359: $ctr++;
1.68 ng 2360: }
2361: $result.= '</select>'."<br>\n";
1.70 ! ng 2362: $ctr=0;
! 2363: foreach (@$titles) {
! 2364: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
! 2365: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
! 2366: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
! 2367: $ctr++;
! 2368: }
! 2369: $result.='<input type="hidden" name="page" />'."\n";
! 2370: $result.='<input type="hidden" name="title" />'."\n";
1.68 ng 2371:
2372: # $result.=' <b>View Problems: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
2373: # '<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
2374: # $result.=' <b>Submission Details: </b>'.
2375: # '<input type="radio" name="lastSub" value="last" checked /> last sub only'."\n".
2376: # '<input type="radio" name="lastSub" value="all" /> all details'."\n";
2377: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
2378: '<input type="hidden" name="command" value="displayPage" />'."\n".
2379: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2380: '<input type="hidden" name="symb" value="'.$symb.'" />'."<br><br>\n";
2381: $request->print($result);
2382:
2383: my $studentTable.=' <b>Select a Student you wish to grade</b><br>'.
2384: '<table border="0"><tr><td bgcolor="#777777">'.
2385: '<table border="0"><tr bgcolor="#e6ffff">'.
2386: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2387: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2388: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2389: '<td><b> Fullname <font color="#999999">(username)</font></b></td></tr>';
2390:
2391: my (undef,undef,$fullname) = &getclasslist($getsec,'0');
2392: my $ptr = 1;
2393: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
2394: my ($uname,$udom) = split(/:/,$student);
2395: $studentTable.=($ptr%4 == 1 ? '<tr bgcolor="#ffffe6"><td>' : '</td><td>');
1.70 ! ng 2396: $studentTable.='<input type="radio" name="student" value="'.$student.'" /> '.$$fullname{$student}.
1.68 ng 2397: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
2398: $studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
2399: $ptr++;
2400: }
2401: $studentTable.='</td><td> </td><td> </td><td> ' if ($ptr%4 == 2);
2402: $studentTable.='</td><td> </td><td> ' if ($ptr%4 == 3);
2403: $studentTable.='</td><td> ' if ($ptr%4 == 0);
2404: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.70 ! ng 2405: $studentTable.='<br /> <input type="button" '.
! 2406: 'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
1.68 ng 2407:
2408: $studentTable.=&show_grading_menu_form($symb,$url);
2409: $request->print($studentTable);
2410:
2411: return '';
2412: }
2413:
2414: sub getSymbMap {
2415: my $navmap = Apache::lonnavmaps::navmap-> new(
2416: $ENV{'request.course.fn'}.'.db',
2417: $ENV{'request.course.fn'}.'_parms.db',1, 1);
2418:
2419: my $res = $navmap->firstResource(); # temp resource to access constants
2420: $navmap->init();
2421:
2422: # End navmap using boilerplate
2423:
2424: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
2425: my $depth = 1;
2426: $iterator->next(); # ignore first BEGIN_MAP
2427: my $curRes = $iterator->next();
2428:
2429: my %symbx = ();
2430: my @titles = ();
2431: my $minder=0;
2432: while ($depth > 0) {
2433: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
2434: if ($curRes == $iterator->END_MAP()) { $depth--; }
2435:
2436: if (ref($curRes) && $curRes->is_map()) {
2437: my $title = $curRes->compTitle();
2438: push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
2439: $symbx{$minder.'.'.$title} = $curRes->symb();
2440: $minder++;
2441: }
2442: $curRes = $iterator->next();
2443: }
2444:
2445: $navmap->untieHashes();
2446: return \@titles,\%symbx;
2447: }
2448:
2449: sub displayPage {
2450: my ($request) = shift;
2451:
2452: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2453: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2454: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2455: my $pageTitle = $ENV{'form.page'};
2456: my (undef,undef,$fullname) = &getclasslist($getsec,'0');
1.70 ! ng 2457: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.68 ng 2458: my ($idx,$showtitle) = ($pageTitle =~ /(\d+)\.(.*)/);
2459:
1.70 ! ng 2460: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
! 2461: $result.='<h3> Student: '.$$fullname{$ENV{'form.student'}}.
1.68 ng 2462: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
2463:
2464: my $navmap = Apache::lonnavmaps::navmap-> new(
2465: $ENV{'request.course.fn'}.'.db',
2466: $ENV{'request.course.fn'}.'_parms.db',1, 1);
1.70 ! ng 2467: my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
1.68 ng 2468: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2469:
2470: my $iterator = $navmap->getIterator($map->map_start(),
2471: $map->map_finish());
2472:
2473: my $depth = 1;
2474: $iterator->next(); # skip the first BEGIN_MAP
2475: my $curRes = $iterator->next(); # for "current resource"
2476: my %symbx = ();
2477: my @titles = ();
2478: my %parts = ();
2479: my $ctr=0;
2480: my $minder=0;
2481: while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
2482: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
2483: if($curRes == $iterator->END_MAP) { $depth++; }
2484:
2485: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
2486: my $parts = $curRes->parts();
2487: my $title = $curRes->compTitle();
2488: push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
2489: if (scalar(@{$parts}) > 1) { shift @{$parts}; }
1.70 ! ng 2490: $parts{$minder.'.'.$title} = join '::',@{$parts};
1.68 ng 2491: $symbx{$minder.'.'.$title} = $curRes->symb();
2492: $minder++;
2493:
2494: }
2495: $curRes = $iterator->next();
2496: $ctr++;
2497: }
2498:
1.70 ! ng 2499:
1.68 ng 2500: $navmap->init();
2501: $request->print($result);
1.70 ! ng 2502: &sub_page_js($request);
1.68 ng 2503:
1.70 ! ng 2504: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
! 2505: '<input type="hidden" name="command" value="gradePage" />'."\n".
! 2506: '<input type="hidden" name="student" value="'.$ENV{'form.student'}.'" />'."\n".
! 2507: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
! 2508: '<input type="hidden" name="title" value="'.$ENV{'form.title'}.'" />'."\n";
! 2509:
! 2510: $studentTable.=
1.68 ng 2511: '<table border="0"><tr><td bgcolor="#777777">'.
2512: '<table border="0"><tr bgcolor="#e6ffff">'.
1.70 ! ng 2513: '<td align="center"><b> No </b></td>'.
1.68 ng 2514: '<td><b> Title</b></td>'.
2515: '<td><b> Answer</b></td>'.
2516: '<td><b> Grade</b></td></tr>';
2517: my $question=1;
2518: foreach (@titles) {
2519: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ! ng 2520: my @parts = split(/::/,$parts{$_});
! 2521: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
! 2522: (scalar(@parts) == 1 ? '' : '<br>('.scalar(@parts).' parts)').'</td>';
1.68 ng 2523: $studentTable.='<td valign="top"> '.$showtitle.' </td>';
2524: $studentTable.='<td> '.
2525: &Apache::loncommon::get_student_answers($symbx{$_},$uname,$udom,$ENV{'request.course.id'}).'</td>';
2526:
1.70 ! ng 2527: my %record = &Apache::lonnet::restore($symbx{$_},$ENV{'request.course.id'},$udom,$uname);
1.68 ng 2528: $studentTable.='<td> ';
1.70 ! ng 2529: foreach my $partid (@parts) {
! 2530: $studentTable.=&gradeBox($symbx{$_},$uname,$udom,$question,$partid,\%record);
! 2531: $question++;
1.68 ng 2532: }
2533: $studentTable.='</td></tr>';
2534:
2535: }
2536:
2537: $studentTable.='</table></td></tr></table>';
1.70 ! ng 2538: $studentTable.='</form>';
1.68 ng 2539:
2540: $request->print($studentTable);
2541:
1.70 ! ng 2542: return '';
! 2543: }
! 2544:
! 2545: sub gradeBox {
! 2546: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
! 2547: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
! 2548: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
! 2549: '<font color="red">problem weight assigned by computer</font>');
! 2550: $wgt = ($wgt > 0 ? $wgt : '1');
! 2551: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
! 2552: '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
! 2553: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
! 2554: $result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points: </b></td><td>';
1.68 ng 2555:
1.70 ! ng 2556: my $ctr = 0;
! 2557: $result.='<table border="0"><tr>'; # display radio buttons in a nice table 10 across
! 2558: while ($ctr<=$wgt) {
! 2559: $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
! 2560: 'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
! 2561: ',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
! 2562: ',this.form.stores'.$counter.'_'.$partid.')" '.
! 2563: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
! 2564: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
! 2565: $ctr++;
! 2566: }
! 2567: $result.='</tr></table>';
! 2568: $result.='</td><td> <b>or</b> </td>';
! 2569: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
! 2570: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
! 2571: 'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
! 2572: ',this.form.GD_BOX'.$counter.'_'.$partid.
! 2573: ',this.form.GD_SEL'.$counter.'_'.$partid.
! 2574: ',this.form.stores'.$counter.'_'.$partid.
! 2575: ','.$wgt.')" /></td>'."\n";
! 2576: $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
! 2577:
! 2578: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
! 2579: 'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
! 2580: ',this.form.GD_BOX'.$counter.'_'.$partid.
! 2581: ',this.form.GD_SEL'.$counter.'_'.$partid.
! 2582: ',this.form.stores'.$counter.'_'.$partid.')" >'."\n";
! 2583: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
! 2584: $result.='<option> </option>'.
! 2585: '<option selected="on">excused</option></select>';
! 2586: } else {
! 2587: $result.='<option selected="on"> </option>'.
! 2588: '<option>excused</option></select>';
! 2589: }
! 2590: $result.="  \n";
! 2591: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
! 2592: $result.='</td></tr></table>'."\n";
! 2593: return $result;
1.68 ng 2594: }
2595:
1.44 ng 2596: #--- Form to input a receipt number ---
2597: sub verifyReceipt_form {
2598: my ($symb,$url) = @_;
1.46 ng 2599: my $result = '<script type="text/javascript" language="javascript">'."\n".
2600: ' function checkEntry(formname) {'."\n".
2601: ' var receipt = formname.receipt.value;'."\n".
2602: ' if (isNaN(receipt) || receipt == "") {'."\n".
2603: ' alert("Please enter a receipt number given by a student in the box.");'."\n".
2604: ' return false;'."\n".
2605: ' }'."\n".
2606: ' formname.submit();'."\n".
2607: ' }'."\n".
2608: '</script>'."\n";
2609:
1.44 ng 2610: my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
2611:
1.46 ng 2612: $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1.44 ng 2613: $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
2614: $result.=' <b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
2615: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.46 ng 2616: $result.='<form action="/adm/grades" method="post" name="verifyform">'."\n";
1.44 ng 2617: $result.=' <tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
1.46 ng 2618: $result.=' <input type="button" onClick="javascript:checkEntry(this.form);"'.
2619: ' value="Verify Receipt">'."\n";
1.44 ng 2620: $result.='<input type="hidden" name="command" value="verify">'."\n";
2621: if ($ENV{'form.url'}) {
2622: $result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
2623: }
2624: if ($ENV{'form.symb'}) {
2625: $result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
2626: }
2627: $result.='</form>';
2628: $result.='</td></tr></table>'."\n";
2629: $result.='</td></tr></table>'."\n";
2630: return $result;
1.2 albertel 2631: }
2632:
1.1 albertel 2633: sub handler {
1.41 ng 2634: my $request=$_[0];
2635:
2636: if ($ENV{'browser.mathml'}) {
2637: $request->content_type('text/xml');
2638: } else {
2639: $request->content_type('text/html');
2640: }
2641: $request->send_http_header;
1.44 ng 2642: return '' if $request->header_only;
1.41 ng 2643: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
2644: my $url=$ENV{'form.url'};
2645: my $symb=$ENV{'form.symb'};
2646: my $command=$ENV{'form.command'};
2647: if (!$url) {
2648: my ($temp1,$temp2);
2649: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
2650: $url = $ENV{'form.url'};
2651: }
2652: &send_header($request);
2653: if ($url eq '' && $symb eq '') {
2654: if ($ENV{'user.adv'}) {
2655: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
2656: ($ENV{'form.codethree'})) {
2657: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
2658: $ENV{'form.codethree'};
2659: my ($tsymb,$tuname,$tudom,$tcrsid)=
2660: &Apache::lonnet::checkin($token);
2661: if ($tsymb) {
2662: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
2663: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
2664: $request->print(
2665: &Apache::lonnet::ssi('/res/'.$url,
2666: ('grade_username' => $tuname,
2667: 'grade_domain' => $tudom,
2668: 'grade_courseid' => $tcrsid,
2669: 'grade_symb' => $tsymb)));
2670: } else {
1.45 ng 2671: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.41 ng 2672: }
2673: } else {
1.45 ng 2674: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 2675: }
1.14 www 2676: } else {
1.41 ng 2677: $request->print(&Apache::lonxml::tokeninputfield());
2678: }
2679: }
2680: } else {
2681: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
2682: if ($command eq 'submission') {
1.68 ng 2683: ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
2684: # if ($command eq 'submission') {
2685: # &listStudents($request) if ($ENV{'form.student'} eq '');
2686: # &submission($request,0,0) if ($ENV{'form.student'} ne '');
2687: } elsif ($command eq 'pickStudentPage') {
2688: &pickStudentPage($request);
2689: } elsif ($command eq 'displayPage') {
2690: &displayPage($request);
1.41 ng 2691: } elsif ($command eq 'processGroup') {
2692: &processGroup($request);
2693: } elsif ($command eq 'gradingmenu') {
2694: $request->print(&gradingmenu($request));
2695: } elsif ($command eq 'viewgrades') {
2696: $request->print(&viewgrades($request));
2697: } elsif ($command eq 'handgrade') {
2698: $request->print(&processHandGrade($request));
2699: } elsif ($command eq 'editgrades') {
2700: $request->print(&editgrades($request));
2701: } elsif ($command eq 'verify') {
2702: $request->print(&verifyreceipt($request));
2703: } elsif ($command eq 'csvupload') {
2704: $request->print(&csvupload($request));
2705: } elsif ($command eq 'viewclasslist') {
2706: $request->print(&viewclasslist($request));
2707: } elsif ($command eq 'csvuploadmap') {
2708: $request->print(&csvuploadmap($request));
2709: } elsif ($command eq 'csvuploadassign') {
2710: if ($ENV{'form.associate'} ne 'Reverse Association') {
2711: $request->print(&csvuploadassign($request));
2712: } else {
2713: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
2714: $ENV{'form.upfile_associate'} = 'reverse';
2715: } else {
2716: $ENV{'form.upfile_associate'} = 'forward';
2717: }
2718: $request->print(&csvuploadmap($request));
2719: }
1.26 albertel 2720: } else {
1.41 ng 2721: $request->print("Unknown action: $command:");
1.26 albertel 2722: }
1.2 albertel 2723: }
1.41 ng 2724: &send_footer($request);
1.44 ng 2725: return '';
2726: }
2727:
2728: sub send_header {
2729: my ($request)= @_;
2730: $request->print(&Apache::lontexconvert::header());
2731: # $request->print("
2732: #<script>
2733: #remotewindow=open('','homeworkremote');
2734: #remotewindow.close();
2735: #</script>");
1.47 www 2736: $request->print(&Apache::loncommon::bodytag('Grading'));
1.44 ng 2737: }
2738:
2739: sub send_footer {
2740: my ($request)= @_;
2741: $request->print('</body>');
2742: $request->print(&Apache::lontexconvert::footer());
1.1 albertel 2743: }
2744:
2745: 1;
2746:
1.13 albertel 2747: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>