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