Annotation of loncom/homework/grades.pm, revision 1.86
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.86 ! ng 4: # $Id: grades.pm,v 1.85 2003/04/19 09:02:57 albertel Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.13 albertel 28: # 2/9,2/13 Guy Albertelli
1.8 www 29: # 6/8 Gerd Kortemeyer
1.13 albertel 30: # 7/26 H.K. Ng
1.14 www 31: # 8/20 Gerd Kortemeyer
1.30 ng 32: # Year 2002
1.44 ng 33: # June-August H.K. Ng
1.68 ng 34: # Year 2003
1.71 ng 35: # February, March H.K. Ng
1.30 ng 36: #
1.1 albertel 37:
38: package Apache::grades;
39: use strict;
40: use Apache::style;
41: use Apache::lonxml;
42: use Apache::lonnet;
1.3 albertel 43: use Apache::loncommon;
1.68 ng 44: use Apache::lonnavmaps;
1.1 albertel 45: use Apache::lonhomework;
1.55 matthew 46: use Apache::loncoursedata;
1.38 ng 47: use Apache::lonmsg qw(:user_normal_msg);
1.1 albertel 48: use Apache::Constants qw(:common);
49:
1.68 ng 50: # ----- These first few routines are general use routines.----
1.44 ng 51: #
52: # --- Retrieve the parts that matches stores_\d+ from the metadata file.---
53: sub getpartlist {
54: my ($url) = @_;
55: my @parts =();
56: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
57: foreach my $key (@metakeys) {
1.54 albertel 58: if ( $key =~ m/stores_(\w+)_.*/) {
1.44 ng 59: push(@parts,$key);
1.41 ng 60: }
1.16 albertel 61: }
1.44 ng 62: return @parts;
1.2 albertel 63: }
64:
1.44 ng 65: # --- Get the symbolic name of a problem and the url
66: sub get_symb_and_url {
67: my ($request) = @_;
68: (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.41 ng 69: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.44 ng 70: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
71: return ($symb,$url);
1.32 ng 72: }
73:
1.44 ng 74: # --- Retrieve the fullname for a user. Return lastname, first middle ---
75: # --- Generation is attached next to the lastname if it exists. ---
1.34 ng 76: sub get_fullname {
1.39 ng 77: my ($uname,$udom) = @_;
1.34 ng 78: my %name=&Apache::lonnet::get('environment', ['lastname','generation',
1.55 matthew 79: 'firstname','middlename'],
80: $udom,$uname);
1.34 ng 81: my $fullname;
82: my ($tmp) = keys(%name);
83: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
1.55 matthew 84: $fullname = &Apache::loncoursedata::ProcessFullName
85: (@name{qw/lastname generation firstname middlename/});
86: } else {
87: &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
88: '@'.$udom.':'.$tmp);
1.34 ng 89: }
90: return $fullname;
91: }
92:
1.44 ng 93: #--- Get the partlist and the response type for a given problem. ---
94: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 95: sub response_type {
1.41 ng 96: my ($url) = shift;
97: my $allkeys = &Apache::lonnet::metadata($url,'keys');
98: my %seen = ();
99: my (@partlist,%handgrade);
100: foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
1.54 albertel 101: if (/^\w+response_\w+.*/) {
1.41 ng 102: my ($responsetype,$part) = split(/_/,$_,2);
103: my ($partid,$respid) = split(/_/,$part);
104: $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
105: next if ($seen{$partid} > 0);
106: $seen{$partid}++;
107: push @partlist,$partid;
108: }
109: }
110: return \@partlist,\%handgrade;
1.39 ng 111: }
112:
1.44 ng 113: #--- Dumps the class list with usernames,list of sections,
114: #--- section, ids and fullnames for each user.
115: sub getclasslist {
1.76 ng 116: my ($getsec,$filterlist) = @_;
1.56 matthew 117: my $classlist=&Apache::loncoursedata::get_classlist();
1.49 albertel 118: # Bail out if we were unable to get the classlist
1.56 matthew 119: return if (! defined($classlist));
120: #
121: my %sections;
122: my %fullnames;
123: foreach (keys(%$classlist)) {
124: # the following undefs are for 'domain', and 'username' respectively.
125: my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
126: @{$classlist->{$_}};
1.76 ng 127: # filter students according to status selected
1.77 ng 128: if ($filterlist && $ENV{'form.status'} ne 'Any') {
129: if ($ENV{'form.status'} ne $status) {
1.76 ng 130: delete ($classlist->{$_});
131: next;
132: }
133: }
1.44 ng 134: $section = ($section ne '' ? $section : 'no');
135: if ($getsec eq 'all' || $getsec eq $section) {
1.56 matthew 136: $sections{$section}++;
137: $fullnames{$_}=$fullname;
138: } else {
139: delete($classlist->{$_});
140: }
1.44 ng 141: }
142: my %seen = ();
1.56 matthew 143: my @sections = sort(keys(%sections));
144: return ($classlist,\@sections,\%fullnames);
1.44 ng 145: }
146:
147: #find user domain
148: sub finduser {
149: my ($name) = @_;
150: my $domain = '';
151: if ( $Apache::grades::viewgrades eq 'F' ) {
152: my %classlist=&Apache::lonnet::dump('classlist',
153: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
154: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
155: my (@fields) = grep /^$name:/, keys %classlist;
156: ($name, $domain) = split(/:/,$fields[0]);
157: return ($name,$domain);
158: } else {
159: return ($ENV{'user.name'},$ENV{'user.domain'});
160: }
161: }
162:
163: #--- Prompts a user to enter a username.
164: sub moreinfo {
165: my ($request,$reason) = @_;
166: $request->print("Unable to process request: $reason");
167: if ( $Apache::grades::viewgrades eq 'F' ) {
168: $request->print('<form action="/adm/grades" method="post">'."\n");
169: if ($ENV{'form.url'}) {
170: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
171: }
172: if ($ENV{'form.symb'}) {
173: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
174: }
175: $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
176: $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
177: $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
178: $request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
179: $request->print('</form>');
180: }
181: return '';
182: }
183:
184: #--- Retrieve the grade status of a student for all the parts
185: sub student_gradeStatus {
186: my ($url,$symb,$udom,$uname,$partlist) = @_;
187: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
188: my %partstatus = ();
189: foreach (@$partlist) {
190: my ($status,$foo) = split(/_/,$record{"resource.$_.solved"},2);
191: $status = 'nothing' if ($status eq '');
192: $partstatus{$_} = $status;
193: my $subkey = "resource.$_.submitted_by";
194: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
195: }
196: return %partstatus;
197: }
198:
1.45 ng 199: # hidden form and javascript that calls the form
200: # Use by verifyscript and viewgrades
201: # Shows a student's view of problem and submission
202: sub jscriptNform {
203: my ($url,$symb) = @_;
204: my $jscript='<script type="text/javascript" language="javascript">'."\n".
205: ' function viewOneStudent(user,domain) {'."\n".
206: ' document.onestudent.student.value = user;'."\n".
207: ' document.onestudent.userdom.value = domain;'."\n".
208: ' document.onestudent.submit();'."\n".
209: ' }'."\n".
210: '</script>'."\n";
211: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
212: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
213: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.77 ng 214: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 215: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.45 ng 216: '<input type="hidden" name="command" value="submission" />'."\n".
217: '<input type="hidden" name="student" value="" />'."\n".
218: '<input type="hidden" name="userdom" value="" />'."\n".
219: '</form>'."\n";
220: return $jscript;
221: }
1.39 ng 222:
1.44 ng 223: #------------------ End of general use routines --------------------
224: #-------------------------------------------------------------------
225:
226: #------------------------------------ Receipt Verification Routines
1.45 ng 227: #
1.44 ng 228: #--- Check whether a receipt number is valid.---
229: sub verifyreceipt {
230: my $request = shift;
231:
232: my $courseid = $ENV{'request.course.id'};
233: my $receipt = unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
234: $ENV{'form.receipt'};
235: $receipt =~ s/[^\-\d]//g;
236: my $url = $ENV{'form.url'};
237: my $symb = $ENV{'form.symb'};
238: unless ($symb) {
239: $symb = &Apache::lonnet::symbread($url);
240: }
241:
1.45 ng 242: my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
243: $receipt.'</h3></font>'."\n".
1.72 ng 244: '<font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font><br><br>'."\n";
1.44 ng 245:
246: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 247: my (undef,undef,$fullname) = &getclasslist('all','0');
248:
1.53 albertel 249: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44 ng 250: my ($uname,$udom)=split(/\:/);
251: if ($receipt eq
252: &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
253: $contents.='<tr bgcolor="#ffffe6"><td> '."\n".
254: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
255: '\')"; TARGET=_self>'.$$fullname{$_}.'</a> </td>'."\n".
256: '<td> '.$uname.' </td>'.
257: '<td> '.$udom.' </td></tr>'."\n";
258:
259: $matches++;
260: }
261: }
262: if ($matches == 0) {
263: $string = $title.'No match found for the above receipt.';
264: } else {
1.45 ng 265: $string = &jscriptNform($url,$symb).$title.
1.44 ng 266: 'The above receipt matches the following student'.
267: ($matches <= 1 ? '.' : 's.')."\n".
268: '<table border="0"><tr><td bgcolor="#777777">'."\n".
269: '<table border="0"><tr bgcolor="#e6ffff">'."\n".
270: '<td><b> Fullname </b></td>'."\n".
271: '<td><b> Username </b></td>'."\n".
272: '<td><b> Domain </b></td></tr>'."\n".
273: $contents.
274: '</table></td></tr></table>'."\n";
275: }
1.50 albertel 276: return $string.&show_grading_menu_form($symb,$url);
1.44 ng 277: }
278:
279: #--- This is called by a number of programs.
280: #--- Called from the Grading Menu - View/Grade an individual student
281: #--- Also called directly when one clicks on the subm button
282: # on the problem page.
1.30 ng 283: sub listStudents {
1.41 ng 284: my ($request) = shift;
1.49 albertel 285:
1.72 ng 286: my ($symb,$url) = &get_symb_and_url($request);
1.49 albertel 287: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
288: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
289: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
290: my $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
291:
292: my $result;
293: my ($partlist,$handgrade) = &response_type($url);
294: for (sort keys(%$handgrade)) {
295: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
296: $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes');
297: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
298: '<td><b>Type: </b>'.$responsetype.'</td>'.
299: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
300: }
1.77 ng 301: $result.='</table>'."\n";
1.49 albertel 302:
1.68 ng 303: my $viewgrade = $ENV{'form.handgrade'} eq 'yes' ? 'View/Grade' : 'View';
1.76 ng 304: $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
305: &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
1.49 albertel 306:
307: $result='<h3><font color="#339933"> '.
308: $viewgrade.
309: ' Submissions for a Student or a Group of Students</font></h3>'.
1.72 ng 310: '<table border="0"><tr><td colspan=3><font size=+1>'.
311: '<b>Problem: </b>'.$ENV{'form.probTitle'}.'</font></td></tr>'.$result;
1.49 albertel 312:
1.45 ng 313: $request->print(<<LISTJAVASCRIPT);
314: <script type="text/javascript" language="javascript">
315: function checkSelect(checkBox) {
316: var ctr=0;
1.46 ng 317: var sense="";
1.45 ng 318: if (checkBox.length > 1) {
319: for (var i=0; i<checkBox.length; i++) {
320: if (checkBox[i].checked) {
321: ctr++;
322: }
323: }
1.46 ng 324: sense = "a student or group of students";
1.45 ng 325: } else {
326: if (checkBox.checked) {
327: ctr = 1;
328: }
1.46 ng 329: sense = "the student";
1.45 ng 330: }
331: if (ctr == 0) {
1.49 albertel 332: alert("Please select "+sense+" before clicking on the $viewgrade button.");
1.45 ng 333: return false;
334: }
335: document.gradesub.submit();
336: }
337: </script>
338: LISTJAVASCRIPT
339:
1.41 ng 340: $request->print($result);
1.39 ng 341:
1.45 ng 342: my $checkhdgrade = $ENV{'form.handgrade'} eq 'yes' ? 'checked' : '';
343: my $checklastsub = $ENV{'form.handgrade'} eq 'yes' ? '' : 'checked';
1.44 ng 344:
1.45 ng 345: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
1.80 ng 346: ' <b>View Problem: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
347: '<input type="radio" name="vProb" value="yes" /> one student '."\n".
1.58 albertel 348: '<input type="radio" name="vProb" value="all" /> all students <br />'."\n".
1.49 albertel 349: ' <b>Submissions: </b>'."\n";
350: if ($ENV{'form.handgrade'} eq 'yes') {
351: $gradeTable.='<input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> handgrade only'."\n";
352: }
353: $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last sub only'."\n".
1.45 ng 354: '<input type="radio" name="lastSub" value="last" /> last sub & parts info'."\n".
355: '<input type="radio" name="lastSub" value="all" /> all details'."\n".
356: '<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
357: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
358: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'" />'."\n".
1.65 albertel 359: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'" /><br />'."\n".
1.64 albertel 360: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" /><br />'."\n".
1.77 ng 361: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 362: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.48 albertel 363: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
364: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.49 albertel 365: 'To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n".
366: 'click on the '.$viewgrade.' button. To view the submissions for a group of students, click'."\n".
1.45 ng 367: ' on the check boxes for the group of students.<br />'."\n".
368: '<input type="hidden" name="command" value="processGroup" />'."\n".
369: '<input type="button" '."\n".
370: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.49 albertel 371: 'value="'.$viewgrade.'" />'."\n";
1.45 ng 372:
1.76 ng 373: my (undef,undef,$fullname) = &getclasslist($getsec,$ENV{'form.showgrading'} eq 'yes' ? '1' : '0');
1.41 ng 374:
1.45 ng 375: $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.41 ng 376: '<table border="0"><tr bgcolor="#e6ffff">'.
1.44 ng 377: '<td><b> Select </b></td><td><b> Fullname </b></td>'.
378: '<td><b> Username </b></td><td><b> Domain </b></td>';
1.41 ng 379: foreach (sort(@$partlist)) {
1.45 ng 380: $gradeTable.='<td><b> Part '.(split(/_/))[0].' Status </b></td>';
1.41 ng 381: }
1.45 ng 382: $gradeTable.='</tr>'."\n";
1.41 ng 383:
1.45 ng 384: my $ctr = 0;
1.53 albertel 385: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41 ng 386: my ($uname,$udom) = split(/:/,$student);
1.48 albertel 387: my (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
1.41 ng 388: my $statusflg = '';
389: foreach (keys(%status)) {
390: $statusflg = 1 if ($status{$_} ne 'nothing');
1.43 ng 391: my ($foo,$partid,$foo1) = split(/\./,$_);
1.41 ng 392: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
393: $statusflg = '';
1.45 ng 394: $gradeTable.='<input type="hidden" name="'.
395: $student.':submitted_by" value="'.
396: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1.41 ng 397: }
398: }
399: next if ($statusflg eq '' && $submitonly eq 'yes');
1.34 ng 400:
1.45 ng 401: $ctr++;
1.41 ng 402: if ( $Apache::grades::viewgrades eq 'F' ) {
1.45 ng 403: $gradeTable.='<tr bgcolor="#ffffe6">'.
1.41 ng 404: '<td align="center"><input type=checkbox name="stuinfo" value="'.
405: $student.':'.$$fullname{$student}.'"></td>'."\n".
1.44 ng 406: '<td> '.$$fullname{$student}.' </td>'."\n".
1.41 ng 407: '<td> '.$uname.' </td>'."\n".
408: '<td align="middle"> '.$udom.' </td>'."\n";
409:
410: foreach (sort keys(%status)) {
411: next if (/^resource.*?submitted_by$/);
1.45 ng 412: $gradeTable.='<td align="middle"> '.$status{$_}.' </td>'."\n";
1.41 ng 413: }
1.45 ng 414: $gradeTable.='</tr>'."\n";
1.41 ng 415: }
416: }
1.45 ng 417: $gradeTable.='</table></td></tr></table>'.
418: '<input type="button" '.
419: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.50 albertel 420: 'value="'.$viewgrade.'" /></form>'."\n";
1.45 ng 421: if ($ctr == 0) {
422: $gradeTable='<br /> <font color="red">'.
423: 'No submission found for this resource.</font><br />';
1.46 ng 424: } elsif ($ctr == 1) {
425: $gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45 ng 426: }
1.50 albertel 427: $gradeTable.=&show_grading_menu_form($symb,$url);
1.45 ng 428: $request->print($gradeTable);
1.44 ng 429: return '';
1.10 ng 430: }
431:
1.44 ng 432: #---- Called from the listStudents routine
433: # Displays the submissions for one student or a group of students
1.34 ng 434: sub processGroup {
1.41 ng 435: my ($request) = shift;
436: my $ctr = 0;
437: my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
438: : ($ENV{'form.stuinfo'}));
439: my $total = scalar(@stuchecked)-1;
1.45 ng 440:
1.41 ng 441: foreach (@stuchecked) {
442: my ($uname,$udom,$fullname) = split(/:/);
1.44 ng 443: $ENV{'form.student'} = $uname;
444: $ENV{'form.userdom'} = $udom;
445: $ENV{'form.fullname'} = $fullname;
1.41 ng 446: &submission($request,$ctr,$total);
447: $ctr++;
448: }
449: return '';
1.35 ng 450: }
1.34 ng 451:
1.44 ng 452: #------------------------------------------------------------------------------------
453: #
454: #-------------------------- Next few routines handles grading by student, essentially
455: # handles essay response type problem/part
456: #
457: #--- Javascript to handle the submission page functionality ---
458: sub sub_page_js {
459: my $request = shift;
460: $request->print(<<SUBJAVASCRIPT);
461: <script type="text/javascript" language="javascript">
1.71 ng 462: function updateRadio(formname,id,weight) {
463: var gradeBox = eval("formname.GD_BOX"+id);
464: var radioButton = eval("formname.RADVAL"+id);
1.72 ng 465: var oldpts = eval("formname.oldpts"+id+".value");
466: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 467: gradeBox.value = pts;
468: var resetbox = false;
469: if (isNaN(pts) || pts < 0) {
470: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
471: for (var i=0; i<radioButton.length; i++) {
472: if (radioButton[i].checked) {
473: gradeBox.value = i;
474: resetbox = true;
475: }
476: }
477: if (!resetbox) {
478: formtextbox.value = "";
479: }
480: return;
1.44 ng 481: }
1.71 ng 482:
483: if (pts > weight) {
484: var resp = confirm("You entered a value ("+pts+
485: ") greater than the weight for the part. Accept?");
486: if (resp == false) {
487: gradeBox.value = "";
488: return;
489: }
1.44 ng 490: }
1.13 albertel 491:
1.71 ng 492: for (var i=0; i<radioButton.length; i++) {
493: radioButton[i].checked=false;
494: if (pts == i && pts != "") {
495: radioButton[i].checked=true;
496: }
497: }
498: updateSelect(formname,id);
499: var stores = eval("formname.stores"+id);
500: stores.value = "0";
1.41 ng 501: }
1.5 albertel 502:
1.72 ng 503: function writeBox(formname,id,pts) {
1.71 ng 504: var gradeBox = eval("formname.GD_BOX"+id);
505: if (checkSolved(formname,id) == 'update') {
506: gradeBox.value = pts;
507: } else {
1.72 ng 508: var oldpts = eval("formname.oldpts"+id+".value");
509: gradeBox.value = oldpts;
1.71 ng 510: var radioButton = eval("formname.RADVAL"+id);
511: for (var i=0; i<radioButton.length; i++) {
512: radioButton[i].checked=false;
1.72 ng 513: if (i == oldpts) {
1.71 ng 514: radioButton[i].checked=true;
515: }
516: }
1.41 ng 517: }
1.71 ng 518: var stores = eval("formname.stores"+id);
519: stores.value = "0";
520: updateSelect(formname,id);
521: return;
1.41 ng 522: }
1.44 ng 523:
1.71 ng 524: function clearRadBox(formname,id) {
525: if (checkSolved(formname,id) == 'noupdate') {
526: updateSelect(formname,id);
527: return;
528: }
529: gradeSelect = eval("formname.GD_SEL"+id);
530: for (var i=0; i<gradeSelect.length; i++) {
531: if (gradeSelect[i].selected) {
532: var selectx=i;
533: }
534: }
535: var stores = eval("formname.stores"+id);
536: if (selectx == stores.value) { return };
537: var gradeBox = eval("formname.GD_BOX"+id);
538: gradeBox.value = "";
539: var radioButton = eval("formname.RADVAL"+id);
540: for (var i=0; i<radioButton.length; i++) {
541: radioButton[i].checked=false;
542: }
543: stores.value = selectx;
544: }
1.5 albertel 545:
1.71 ng 546: function checkSolved(formname,id) {
547: if (eval("formname.solved"+id+".value") == "correct_by_student") {
548: alert("This problem has been graded correct by the computer. The score cannot be changed.");
549: return "noupdate";
1.41 ng 550: }
1.71 ng 551: return "update";
1.13 albertel 552: }
1.71 ng 553:
554: function updateSelect(formname,id) {
555: var gradeSelect = eval("formname.GD_SEL"+id);
556: gradeSelect[0].selected = true;
557: return;
1.41 ng 558: }
1.33 ng 559:
1.71 ng 560: //=========== Check that a point is assigned for all the parts (essay grading only) ============
561: function checksubmit(formname,val,total,parttot) {
562: document.SCORE.gradeOpt.value = val;
563: if (val == "Save & Next") {
564: for (i=0;i<=total;i++) {
565: for (j=0;j<parttot;j++) {
566: var partid = eval("formname.partid"+i+"_"+j+".value");
567: var selopt = eval("formname.GD_SEL"+i+"_"+partid);
568: if (selopt[0].selected) {
569: var points = eval("formname.GD_BOX"+i+"_"+partid+".value");
570: if (points == "") {
571: var name = eval("formname.name"+i+".value");
572: var resp = confirm("You did not assign a score for "+name+", part "+partid+". Continue?");
573: if (resp == false) {
574: eval("formname.GD_BOX"+i+"_"+partid+".focus()");
575: return false;
576: }
577: }
578: }
579:
580: }
581: }
582:
583: }
584: formname.submit();
585: }
1.44 ng 586:
1.71 ng 587: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
588: function checkSubmitPage(formname,total) {
589: noscore = new Array(100);
590: var ptr = 0;
591: for (i=1;i<total;i++) {
592: var partid = eval("formname.q_"+i+".value");
593: var selopt = eval("formname.GD_SEL"+i+"_"+partid);
594: if (selopt[0].selected) {
595: var points = eval("formname.GD_BOX"+i+"_"+partid+".value");
596: var status = eval("formname.solved"+i+"_"+partid+".value");
597: if (points == "" && status != "correct_by_student") {
598: noscore[ptr] = i;
599: ptr++;
600: }
601: }
602: }
603: if (ptr != 0) {
604: var sense = ptr == 1 ? ": " : "s: ";
605: var prolist = "";
606: if (ptr == 1) {
607: prolist = noscore[0];
608: } else {
609: var i = 0;
610: while (i < ptr-1) {
611: prolist += noscore[i]+", ";
612: i++;
613: }
614: prolist += "and "+noscore[i];
615: }
616: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
617: if (resp == false) {
618: return false;
619: }
620: }
1.45 ng 621:
1.71 ng 622: formname.submit();
623: }
624: </script>
625: SUBJAVASCRIPT
626: }
1.45 ng 627:
1.71 ng 628: #--- javascript for essay type problem --
629: sub sub_page_kw_js {
630: my $request = shift;
1.80 ng 631: my $iconpath = $request->dir_config('lonIconsURL');
1.71 ng 632: $request->print(<<SUBJAVASCRIPT);
633: <script type="text/javascript" language="javascript">
1.45 ng 634:
1.44 ng 635: //===================== Show list of keywords ====================
636: function keywords(keyform) {
1.76 ng 637: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keyform.value);
1.44 ng 638: if (nret==null) return;
639: keyform.value = nret;
640:
641: document.SCORE.refresh.value = "on";
642: if (document.SCORE.keywords.value != "") {
643: document.SCORE.submit();
644: }
645: return;
646: }
647:
648: //===================== Script to view submitted by ==================
649: function viewSubmitter(submitter) {
650: document.SCORE.refresh.value = "on";
651: document.SCORE.NCT.value = "1";
652: document.SCORE.unamedom0.value = submitter;
653: document.SCORE.submit();
654: return;
655: }
656:
657: //===================== Script to add keyword(s) ==================
658: function getSel() {
659: if (document.getSelection) txt = document.getSelection();
660: else if (document.selection) txt = document.selection.createRange().text;
661: else return;
662: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
663: if (cleantxt=="") {
1.46 ng 664: alert("Please select a word or group of words from document and then click this link.");
1.44 ng 665: return;
666: }
667: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
668: if (nret==null) return;
669: var curlist = document.SCORE.keywords.value;
670: document.SCORE.keywords.value = curlist+" "+nret;
671: document.SCORE.refresh.value = "on";
672: if (document.SCORE.keywords.value != "") {
673: document.SCORE.submit();
674: }
675: return;
676: }
677:
678: //====================== Script for composing message ==============
1.80 ng 679: // preload images
680: img1 = new Image();
681: img1.src = "$iconpath/mailbkgrd.gif";
682: img2 = new Image();
683: img2.src = "$iconpath/mailto.gif";
684:
1.44 ng 685: function msgCenter(msgform,usrctr,fullname) {
686: var Nmsg = msgform.savemsgN.value;
687: savedMsgHeader(Nmsg,usrctr,fullname);
688: var subject = msgform.msgsub.value;
689: var rtrchk = eval("document.SCORE.includemsg"+usrctr);
690: var msgchk = rtrchk.value;
691: re = /msgsub/;
692: var shwsel = "";
693: if (re.test(msgchk)) { shwsel = "checked" }
694: displaySubject(subject,shwsel);
695: for (var i=1; i<=Nmsg; i++) {
696: var testpt = "savemsg"+i+",";
697: re = /testpt/;
698: shwsel = "";
699: if (re.test(msgchk)) { shwsel = "checked" }
700: var message = eval("document.SCORE.savemsg"+i+".value");
701: displaySavedMsg(i,message,shwsel);
702: }
703: newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
704: shwsel = "";
705: re = /newmsg/;
706: if (re.test(msgchk)) { shwsel = "checked" }
707: newMsg(newmsg,shwsel);
708: msgTail();
709: return;
710: }
711:
1.76 ng 712: // var pWin = null;
1.44 ng 713: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 714: var height = 70*Nmsg+250;
1.44 ng 715: var scrollbar = "no";
716: if (height > 600) {
717: height = 600;
718: scrollbar = "yes";
719: }
1.84 ng 720: // if (window.pWin) {window.pWin.close(); window.pWin=null}
1.44 ng 721: pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
1.76 ng 722: pWin.focus();
723: pDoc = pWin.document;
724: pDoc.write("<html><head>");
725: pDoc.write("<title>Message Central</title>");
726:
727: pDoc.write("<script language=javascript>");
728: pDoc.write("function checkInput() {");
729: pDoc.write(" opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
730: pDoc.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
731: pDoc.write(" var usrctr = document.msgcenter.usrctr.value;");
732: pDoc.write(" var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
733: pDoc.write(" newval.value = document.msgcenter.newmsg.value;");
734:
735: pDoc.write(" var msgchk = \\"\\";");
736: pDoc.write(" if (document.msgcenter.subchk.checked) {");
737: pDoc.write(" msgchk = \\"msgsub,\\";");
738: pDoc.write(" }");
1.80 ng 739: pDoc.write(" var includemsg = 0;");
740: pDoc.write(" for (var i=1; i<=nmsg; i++) {");
1.76 ng 741: pDoc.write(" var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
742: pDoc.write(" var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
743: pDoc.write(" opnmsg.value = frmmsg.value;");
744: pDoc.write(" var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
745: pDoc.write(" if (chkbox.checked) {");
746: pDoc.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
1.80 ng 747: pDoc.write(" includemsg = 1;");
1.76 ng 748: pDoc.write(" }");
749: pDoc.write(" }");
750: pDoc.write(" if (document.msgcenter.newmsgchk.checked) {");
751: pDoc.write(" msgchk += \\"newmsg\\"+usrctr;");
1.80 ng 752: pDoc.write(" includemsg = 1;");
753: pDoc.write(" }");
754: pDoc.write(" imgformname = eval(\\"opener.document.SCORE.mailicon\\"+usrctr);");
1.84 ng 755: pDoc.write(" imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");");
1.76 ng 756: pDoc.write(" var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
757: pDoc.write(" includemsg.value = msgchk;");
758:
759: pDoc.write(" self.close()");
760:
761: pDoc.write("}");
762:
763: pDoc.write("<");
764: pDoc.write("/script>");
765:
766: pDoc.write("</head><body bgcolor=white>");
767:
768: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
769: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
770: pDoc.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br><br>");
771:
772: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
773: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
774: pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44 ng 775: }
776: function displaySubject(msg,shwsel) {
1.76 ng 777: pDoc = pWin.document;
778: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
779: pDoc.write("<td>Subject</td>");
780: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
781: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44 ng 782: }
783:
1.72 ng 784: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 785: pDoc = pWin.document;
786: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
787: pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
788: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
789: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44 ng 790: }
791:
792: function newMsg(newmsg,shwsel) {
1.76 ng 793: pDoc = pWin.document;
794: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
795: pDoc.write("<td align=\\"center\\">New</td>");
796: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
797: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44 ng 798: }
799:
800: function msgTail() {
1.76 ng 801: pDoc = pWin.document;
802: pDoc.write("</table>");
803: pDoc.write("</td></tr></table> ");
804: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
805: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
806: pDoc.write("</form>");
807: pDoc.write("</body></html>");
1.44 ng 808: }
809:
810: //====================== Script for keyword highlight options ==============
811: function kwhighlight() {
812: var kwclr = document.SCORE.kwclr.value;
813: var kwsize = document.SCORE.kwsize.value;
814: var kwstyle = document.SCORE.kwstyle.value;
815: var redsel = "";
816: var grnsel = "";
817: var blusel = "";
818: if (kwclr=="red") {var redsel="checked"};
819: if (kwclr=="green") {var grnsel="checked"};
820: if (kwclr=="blue") {var blusel="checked"};
821: var sznsel = "";
822: var sz1sel = "";
823: var sz2sel = "";
824: if (kwsize=="0") {var sznsel="checked"};
825: if (kwsize=="+1") {var sz1sel="checked"};
826: if (kwsize=="+2") {var sz2sel="checked"};
827: var synsel = "";
828: var syisel = "";
829: var sybsel = "";
830: if (kwstyle=="") {var synsel="checked"};
831: if (kwstyle=="<i>") {var syisel="checked"};
832: if (kwstyle=="<b>") {var sybsel="checked"};
833: highlightCentral();
834: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
835: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
836: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
837: highlightend();
838: return;
839: }
840:
1.76 ng 841: // var hwdWin = null;
1.44 ng 842: function highlightCentral() {
1.76 ng 843: // if (window.hwdWin) window.hwdWin.close();
1.44 ng 844: hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
1.76 ng 845: hwdWin.focus();
846: var hDoc = hwdWin.document;
847: hDoc.write("<html><head>");
848: hDoc.write("<title>Highlight Central</title>");
849:
850: hDoc.write("<script language=javascript>");
851: hDoc.write("function updateChoice(flag) {");
852: hDoc.write(" opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
853: hDoc.write(" opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
854: hDoc.write(" opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
855: hDoc.write(" opener.document.SCORE.refresh.value = \\"on\\";");
856: hDoc.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){");
857: hDoc.write(" opener.document.SCORE.submit();");
858: hDoc.write(" }");
859: hDoc.write(" self.close()");
860: hDoc.write("}");
861:
862: hDoc.write("function radioSelection(radioButton) {");
863: hDoc.write(" var selection=null;");
864: hDoc.write(" for (var i=0; i<radioButton.length; i++) {");
865: hDoc.write(" if (radioButton[i].checked) {");
866: hDoc.write(" selection=radioButton[i].value;");
867: hDoc.write(" return selection;");
868: hDoc.write(" }");
869: hDoc.write(" }");
870: hDoc.write("}");
871:
872: hDoc.write("<");
873: hDoc.write("/script>");
874:
875: hDoc.write("</head><body bgcolor=white>");
876:
877: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
878: hDoc.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br><br>");
879:
880: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
881: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
882: hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44 ng 883: }
884:
885: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 886: var hDoc = hwdWin.document;
887: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
888: hDoc.write("<td align=\\"left\\">");
889: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
890: hDoc.write("<td align=\\"left\\">");
891: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
892: hDoc.write("<td align=\\"left\\">");
893: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
894: hDoc.write("</tr>");
1.44 ng 895: }
896:
897: function highlightend() {
1.76 ng 898: var hDoc = hwdWin.document;
899: hDoc.write("</table>");
900: hDoc.write("</td></tr></table> ");
901: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
902: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
903: hDoc.write("</form>");
904: hDoc.write("</body></html>");
1.44 ng 905: }
906:
907: </script>
908: SUBJAVASCRIPT
909: }
910:
1.71 ng 911: #--- displays the grading box, used in essay type problem and grading by page/sequence
912: sub gradeBox {
913: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
914:
915: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
916: '/check.gif" height="16" border="0" />';
917:
918: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
919: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
920: '<font color="red">problem weight assigned by computer</font>');
921: $wgt = ($wgt > 0 ? $wgt : '1');
922: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
923: '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
924: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
925:
926: $result.='<table border="0"><tr><td>'.
927: '<b>Part </b>'.$partid.' <b>Points: </b></td><td>'."\n";
928:
929: my $ctr = 0;
930: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
931: while ($ctr<=$wgt) {
932: $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
933: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.72 ng 934: $ctr.')" value="'.$ctr.'" '.
1.71 ng 935: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
936: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
937: $ctr++;
938: }
939: $result.='</tr></table>';
940:
941: $result.='</td><td> <b>or</b> </td>'."\n";
942: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
943: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
944: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
945: $wgt.')" /></td>'."\n";
946: $result.='<td>/'.$wgt.' '.$wgtmsg.
947: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
948: ' </td><td>'."\n";
949:
950: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
951: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
952: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
953: $result.='<option> </option>'.
954: '<option selected="on">excused</option></select>'."\n";
955: } else {
956: $result.='<option selected="on"> </option>'.
957: '<option>excused</option></select>'."\n";
958: }
959: $result.="  \n";
960: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
961: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
962: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
963: $$record{'resource.'.$partid.'.solved'}.'" />'."\n";
964: $result.='</td></tr></table>'."\n";
965: return $result;
966: }
1.44 ng 967:
1.58 albertel 968: sub show_problem {
1.71 ng 969: my ($request,$symb,$uname,$udom,$removeform,$viewon) = @_;
1.58 albertel 970: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
971: $ENV{'request.course.id'});
972: if ($removeform) {
973: $rendered=~s|<form(.*?)>||g;
974: $rendered=~s|</form>||g;
975: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
976: }
977: my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
978: $ENV{'request.course.id'});
979: if ($removeform) {
980: $companswer=~s|<form(.*?)>||g;
981: $companswer=~s|</form>||g;
982: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
983: }
984: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 985: $result.='<table border="0" width="100%">';
986: $result.='<tr><td bgcolor="#e6ffff"><b> View of the problem - '.$ENV{'form.fullname'}.
987: '</b></td></tr>' if ($viewon);
988: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1.58 albertel 989: $result.='<b>Correct answer:</b><br />'.$companswer;
990: $result.='</td></tr></table>';
991: $result.='</td></tr></table><br />';
1.71 ng 992: return $result;
1.58 albertel 993: }
994:
1.44 ng 995: # --------------------------- show submissions of a student, option to grade
996: sub submission {
997: my ($request,$counter,$total) = @_;
998:
999: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1000: my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
1001: ($uname,$udom) = &finduser($uname) if $udom eq '';
1002: $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
1.41 ng 1003:
1004: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1005: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1006: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
1007:
1008: # header info
1009: if ($counter == 0) {
1010: &sub_page_js($request);
1.71 ng 1011: &sub_page_kw_js($request);
1.76 ng 1012: $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
1013: &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
1014:
1.45 ng 1015: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.72 ng 1016: '<font size=+1> <b>Problem: </b>'.$ENV{'form.probTitle'}.'</font>'."\n");
1.41 ng 1017:
1.44 ng 1018: # option to display problem, only once else it cause problems
1019: # with the form later since the problem has a form.
1.66 albertel 1020: if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) {
1.71 ng 1021: $request->print(&show_problem($request,$symb,$uname,$udom,0,1));
1.41 ng 1022: }
1023:
1.44 ng 1024: # kwclr is the only variable that is guaranteed to be non blank
1025: # if this subroutine has been called once.
1.41 ng 1026: my %keyhash = ();
1027: if ($ENV{'form.kwclr'} eq '') {
1028: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1029: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1030: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1031:
1032: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1033: $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1034: $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1035: $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1036: $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1037: $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.72 ng 1038: $keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
1.41 ng 1039: $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.38 ng 1040:
1.41 ng 1041: }
1.44 ng 1042:
1.41 ng 1043: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
1044: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.80 ng 1045: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 1046: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.41 ng 1047: '<input type="hidden" name="refresh" value="off" />'."\n".
1048: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1049: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1050: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
1051: '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
1052: '<input type="hidden" name="lastSub" value="'.$ENV{'form.lastSub'}.'" />'."\n".
1053: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
1054: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
1055: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'">'."\n".
1056: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'">'."\n".
1057: '<input type="hidden" name="keywords" value="'.$ENV{'form.keywords'}.'" />'."\n".
1058: '<input type="hidden" name="kwclr" value="'.$ENV{'form.kwclr'}.'" />'."\n".
1059: '<input type="hidden" name="kwsize" value="'.$ENV{'form.kwsize'}.'" />'."\n".
1060: '<input type="hidden" name="kwstyle" value="'.$ENV{'form.kwstyle'}.'" />'."\n".
1061: '<input type="hidden" name="msgsub" value="'.$ENV{'form.msgsub'}.'" />'."\n".
1062: '<input type="hidden" name="savemsgN" value="'.$ENV{'form.savemsgN'}.'" />'."\n".
1063: '<input type="hidden" name="NCT"'.
1064: ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
1065:
1066: my ($cts,$prnmsg) = (1,'');
1067: while ($cts <= $ENV{'form.savemsgN'}) {
1068: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.80 ng 1069: ($keyhash{$symb.'_savemsg'.$cts} eq '' ?
1070: &Apache::lonfeedback::clear_out_html($ENV{'form.savemsg'.$cts}) :
1071: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.41 ng 1072: '" />'."\n";
1073: $cts++;
1074: }
1075: $request->print($prnmsg);
1.32 ng 1076:
1.41 ng 1077: if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
1078: $request->print(<<KEYWORDS);
1.38 ng 1079: <b>Keyword Options:</b>
1080: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>
1081: <a href="#" onMouseDown="javascript:getSel(); return false"
1082: CLASS="page">Paste Selection to List</a>
1083: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1084: KEYWORDS
1.41 ng 1085: }
1086: }
1.44 ng 1087:
1.58 albertel 1088: if ($ENV{'form.vProb'} eq 'all') {
1.71 ng 1089: $request->print('<br /><br /><br />') if ($counter > 0);
1090: $request->print(&show_problem($request,$symb,$uname,$udom,1,1));
1.58 albertel 1091: }
1092:
1.41 ng 1093: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
1094: my ($partlist,$handgrade) = &response_type($url);
1095:
1.44 ng 1096: # Display student info
1.41 ng 1097: $request->print(($counter == 0 ? '' : '<br />'));
1.45 ng 1098: my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
1099: '<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1100:
1101: $result.='<b>Fullname: </b>'.$ENV{'form.fullname'}.
1102: '<font color="#999999"> Username: '.$uname.'</font>'.
1.45 ng 1103: '<font color="#999999"> Domain: '.$udom.'</font><br />'."\n";
1104: $result.='<input type="hidden" name="name'.$counter.
1105: '" value="'.$ENV{'form.fullname'}.'" />'."\n";
1.41 ng 1106:
1.44 ng 1107: # If this is handgraded, then check for collaborators
1.45 ng 1108: my @col_fullnames;
1.56 matthew 1109: my ($classlist,$fullname);
1.41 ng 1110: if ($ENV{'form.handgrade'} eq 'yes') {
1.80 ng 1111: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1112: for (keys (%$handgrade)) {
1.44 ng 1113: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1114: '.maxcollaborators',
1115: $symb,$udom,$uname);
1116: next if ($ncol <= 0);
1117: s/\_/\./g;
1118: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ! ng 1119: my @goodcollaborators = ();
! 1120: my @badcollaborators = ();
! 1121: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
! 1122: $_ =~ s/[\$\^\(\)]//g;
! 1123: next if ($_ eq '');
1.80 ng 1124: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ! ng 1125: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1126: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ! ng 1127: # Doing this grep allows 'fuzzy' specification
! 1128: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
! 1129: if (! scalar(@Matches)) {
! 1130: push @badcollaborators,$_;
! 1131: } else {
! 1132: push @goodcollaborators, @Matches;
! 1133: }
1.80 ng 1134: }
1.86 ! ng 1135: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1136: $result.='<b>Collaborators: </b>';
1.86 ! ng 1137: foreach (@goodcollaborators) {
! 1138: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
! 1139: push @col_fullnames, $givenn.' '.$lastname;
! 1140: $result.=$$fullname{$_}.' ';
! 1141: }
1.57 matthew 1142: $result.='<br />'."\n";
1.86 ! ng 1143: $result.='<input type="hidden" name="collaborator'.$counter.
! 1144: '" value="'.(join ':',@goodcollaborators).'" />'."\n";
! 1145: }
! 1146: if (scalar(@badcollaborators) > 0) {
! 1147: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
! 1148: $result.='This student has submitted ';
! 1149: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
! 1150: $result .= ': '.join(', ',@badcollaborators);
! 1151: $result .= '</td></tr></table>';
! 1152: }
! 1153: if (scalar(@badcollaborators > $ncol)) {
! 1154: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
! 1155: $result .= 'This student has submitted too many '.
! 1156: 'collaborators. Maximum is '.$ncol.'.';
! 1157: $result .= '</td></tr></table>';
! 1158: }
1.41 ng 1159: }
1160: }
1.44 ng 1161: $request->print($result."\n");
1.33 ng 1162:
1.44 ng 1163: # print student answer/submission
1164: # Options are (1) Handgaded submission only
1165: # (2) Last submission, includes submission that is not handgraded
1166: # (for multi-response type part)
1167: # (3) Last submission plus the parts info
1168: # (4) The whole record for this student
1.41 ng 1169: if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1170: if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
1.44 ng 1171: my $submitby=''.
1.41 ng 1172: '<b>Collaborative submission by: </b>'.
1.44 ng 1173: '<a href="javascript:viewSubmitter(\''.
1174: $ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
1.41 ng 1175: '\')"; TARGET=_self>'.
1176: $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
1177: $request->print($submitby);
1178: } else {
1.44 ng 1179: my ($string,$timestamp)=
1.46 ng 1180: &get_last_submission (%record);
1.71 ng 1181: my $lastsubonly=''.
1.44 ng 1182: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1183: $$timestamp).'';
1.41 ng 1184: if ($$timestamp eq '') {
1.45 ng 1185: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0].'</td></tr>'."\n";
1.41 ng 1186: } else {
1187: for my $part (sort keys(%$handgrade)) {
1188: foreach (@$string) {
1189: my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
1190: if ($part eq ($partid.'_'.$respid)) {
1191: my ($ressub,$subval) = split(/:/,$_,2);
1.44 ng 1192: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
1193: $partid.'</b> <font color="#999999">( ID '.$respid.
1.67 www 1194: ' )</font> '.
1195: ($record{"resource.$partid.$respid.uploadedurl"}?
1196: '<a href="'.
1197: &Apache::lonnet::tokenwrapper($record{"resource.$partid.$respid.uploadedurl"}).
1198: '"><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 />':'').
1199: '<b>Answer: </b>'.
1.45 ng 1200: &keywords_highlight($subval).'</td></tr>'."\n"
1.41 ng 1201: if ($ENV{'form.lastSub'} eq 'lastonly' ||
1.44 ng 1202: ($ENV{'form.lastSub'} eq 'hdgrade' &&
1203: $$handgrade{$part} =~ /:yes$/));
1.41 ng 1204: }
1205: }
1206: }
1207: }
1.45 ng 1208: $lastsubonly.='</td></tr>'."\n";
1.41 ng 1209: $request->print($lastsubonly);
1210: }
1211: } else {
1212: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.44 ng 1213: $ENV{'request.course.id'},
1214: $last,'.submission',
1215: 'Apache::grades::keywords_highlight'));
1.41 ng 1216: }
1217:
1.44 ng 1218: # return if view submission with no grading option
1.41 ng 1219: if ($ENV{'form.showgrading'} eq '') {
1.45 ng 1220: $request->print('</td></tr></table></td></tr></table></form>'."\n");
1.72 ng 1221: $request->print(&show_grading_menu_form($symb,$url))
1222: if (($ENV{'form.command'} eq 'submission') ||
1223: ($ENV{'form.command'} eq 'processGroup' && $counter == $total));
1.41 ng 1224: return;
1225: }
1.33 ng 1226:
1.44 ng 1227: # Grading options
1.41 ng 1228: $result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
1229: '<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.45 ng 1230: '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1231: .$udom.'" />'."\n";
1232: my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
1233: my $msgfor = $givenn.' '.$lastname;
1234: if (scalar(@col_fullnames) > 0) {
1235: my $lastone = pop @col_fullnames;
1236: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1237: }
1.86 ! ng 1238: $msgfor =~ s/\'/\\'/g; #\'
1.45 ng 1239: $result.='<tr><td bgcolor="#ffffff">'."\n".
1240: ' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1241: ',\''.$msgfor.'\')"; TARGET=_self>'.
1.80 ng 1242: 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').'</a> '.
1243: '<img src="'.$request->dir_config('lonIconsURL').
1244: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.44 ng 1245: '<br /> (Message will be sent when you click on Save & Next below.)'."\n"
1246: if ($ENV{'form.handgrade'} eq 'yes');
1.41 ng 1247: $request->print($result);
1248:
1249: my %seen = ();
1250: my @partlist;
1251: for (sort keys(%$handgrade)) {
1252: my ($partid,$respid) = split(/_/);
1253: next if ($seen{$partid} > 0);
1254: $seen{$partid}++;
1255: next if ($$handgrade{$_} =~ /:no$/);
1256: push @partlist,$partid;
1257:
1.71 ng 1258: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 1259: }
1.45 ng 1260: $result='<input type="hidden" name="partlist'.$counter.
1261: '" value="'.(join ":",@partlist).'" />'."\n";
1262: my $ctr = 0;
1263: while ($ctr < scalar(@partlist)) {
1264: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1265: $partlist[$ctr].'" />'."\n";
1266: $ctr++;
1267: }
1268: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 1269:
1270: # print end of form
1271: if ($counter == $total) {
1.45 ng 1272: my $endform='<table border="0"><tr><td>'.
1273: '<input type="hidden" name="gradeOpt" value="" />'."\n";
1274: if ($ENV{'form.handgrade'} eq 'yes') {
1275: $endform.='<input type="button" value="Save & Next" '.
1.71 ng 1276: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1.45 ng 1277: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
1278: my $ntstu ='<select name="NTSTU">'.
1279: '<option>1</option><option>2</option>'.
1280: '<option>3</option><option>5</option>'.
1281: '<option>7</option><option>10</option></select>'."\n";
1282: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
1283: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
1284: $endform.=$ntstu.'student(s) ';
1285: } else {
1286: $endform.='<input type="hidden" name="NTSTU" value="1" />'."\n";
1287: }
1288: $endform.='<input type="button" value="Next" '.
1.71 ng 1289: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> '."\n".
1.45 ng 1290: '<input type="button" value="Previous" '.
1.71 ng 1291: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> ';
1.45 ng 1292: $endform.='(Next and Previous do not save the scores.)'."\n"
1293: if ($ENV{'form.handgrade'} eq 'yes');
1294: $endform.='</td><tr></table></form>';
1.50 albertel 1295: $endform.=&show_grading_menu_form($symb,$url);
1.41 ng 1296: $request->print($endform);
1297: }
1298: return '';
1.38 ng 1299: }
1300:
1.44 ng 1301: #--- Retrieve the last submission for all the parts
1.38 ng 1302: sub get_last_submission {
1.46 ng 1303: my (%returnhash)=@_;
1304: my (@string,$timestamp);
1305: if ($returnhash{'version'}) {
1306: my %lasthash=();
1307: my ($version);
1308: for ($version=1;$version<=$returnhash{'version'};$version++) {
1309: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
1310: $lasthash{$_}=$returnhash{$version.':'.$_};
1311: $timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
1312: }
1313: }
1314: foreach ((keys %lasthash)) {
1315: if ($_ =~ /\.submission$/) {
1316: my ($partid,$foo) = split(/submission$/,$_);
1317: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1318: '<font color="red">Draft Copy</font> ' : '';
1319: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 1320: }
1321: }
1322: }
1.46 ng 1323: @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
1324: return \@string,\$timestamp;
1.38 ng 1325: }
1.35 ng 1326:
1.44 ng 1327: #--- High light keywords, with style choosen by user.
1.38 ng 1328: sub keywords_highlight {
1.44 ng 1329: my $string = shift;
1330: my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
1331: my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
1.41 ng 1332: (my $styleoff = $styleon) =~ s/\</\<\//;
1.44 ng 1333: my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
1.41 ng 1334: foreach (@keylist) {
1.60 albertel 1335: $string =~ s/\b\Q$_\E(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
1.41 ng 1336: }
1.57 matthew 1337: # This is not really the right place to do this, but I cannot find a
1338: # better one at this time. So here we go - the m in the s:::mg causes
1339: # ^ to match the beginning of a new line. So we replace(???) the beginning
1340: # of the line with <br /> to make things formatted a little better.
1341: $string =~ s:^:<br />:mg;
1.41 ng 1342: return $string;
1.38 ng 1343: }
1.36 ng 1344:
1.44 ng 1345: #--- Called from submission routine
1.38 ng 1346: sub processHandGrade {
1.41 ng 1347: my ($request) = shift;
1348: my $url = $ENV{'form.url'};
1349: my $symb = $ENV{'form.symb'};
1350: my $button = $ENV{'form.gradeOpt'};
1351: my $ngrade = $ENV{'form.NCT'};
1352: my $ntstu = $ENV{'form.NTSTU'};
1353:
1.44 ng 1354: if ($button eq 'Save & Next') {
1355: my $ctr = 0;
1356: while ($ctr < $ngrade) {
1357: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.77 ng 1358: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.71 ng 1359: if ($errorflag eq 'no_score') {
1360: $ctr++;
1361: next;
1362: }
1.44 ng 1363: my $includemsg = $ENV{'form.includemsg'.$ctr};
1364: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 1365: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.44 ng 1366: $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
1367: my (@msgnum) = split(/,/,$includemsg);
1368: foreach (@msgnum) {
1369: $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1370: }
1.80 ng 1371: $message =&Apache::lonfeedback::clear_out_html($message);
1.77 ng 1372: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.80 ng 1373: $message.=" for <a href=\"".
1374: &Apache::lonnet::clutter($url).
1375: "?symb=$symb\">$ENV{'form.probTitle'}</a>";
1.44 ng 1376: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
1377: $ENV{'form.msgsub'},$message);
1378: }
1379: if ($ENV{'form.collaborator'.$ctr}) {
1380: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
1381: foreach (@collaborators) {
1382: &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
1383: $ENV{'form.unamedom'.$ctr});
1384: if ($message ne '') {
1385: $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
1386: $ENV{'form.msgsub'},
1387: $message);
1388: }
1389: }
1390: }
1391: $ctr++;
1392: }
1393: }
1394:
1395: # Keywords sorted in alphabatical order
1.41 ng 1396: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1397: my %keyhash = ();
1398: $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1399: $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
1.44 ng 1400: my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
1401: $ENV{'form.keywords'} = join(' ',@keywords);
1.41 ng 1402: $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
1403: $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
1404: $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
1405: $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
1406: $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
1407:
1.44 ng 1408: # message center - Order of message gets changed. Blank line is eliminated.
1409: # New messages are saved in ENV for the next student.
1410: # All messages are saved in nohist_handgrade.db
1.41 ng 1411: my ($ctr,$idx) = (1,1);
1412: while ($ctr <= $ENV{'form.savemsgN'}) {
1413: if ($ENV{'form.savemsg'.$ctr} ne '') {
1414: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
1415: $idx++;
1416: }
1417: $ctr++;
1418: }
1419: $ctr = 0;
1420: while ($ctr < $ngrade) {
1421: if ($ENV{'form.newmsg'.$ctr} ne '') {
1422: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1423: $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1424: $idx++;
1425: }
1426: $ctr++;
1427: }
1428: $ENV{'form.savemsgN'} = --$idx;
1429: $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
1430: my $putresult = &Apache::lonnet::put
1431: ('nohist_handgrade',\%keyhash,
1432: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1433: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1434:
1.44 ng 1435: # Called by Save & Refresh from Highlight Attribute Window
1.86 ! ng 1436: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.41 ng 1437: if ($ENV{'form.refresh'} eq 'on') {
1.86 ! ng 1438: my ($ctr,$total) = (0,0);
! 1439: while ($ctr < $ngrade) {
! 1440: $total++ if $ENV{'form.unamedom'.$ctr} ne '';
! 1441: $ctr++;
! 1442: }
1.41 ng 1443: $ENV{'form.NTSTU'}=$ngrade;
1.86 ! ng 1444: $ctr = 0;
! 1445: while ($ctr < $total) {
! 1446: my $processUser = $ENV{'form.unamedom'.$ctr};
! 1447: ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
! 1448: $ENV{'form.fullname'} = $$fullname{$processUser};
! 1449: &submission($request,$ctr,$total-1);
1.41 ng 1450: $ctr++;
1451: }
1452: return '';
1453: }
1.36 ng 1454:
1.44 ng 1455: # Get the next/previous one or group of students
1.41 ng 1456: my $firststu = $ENV{'form.unamedom0'};
1457: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
1458: $ctr = 2;
1459: while ($laststu eq '') {
1460: $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
1461: $ctr++;
1462: $laststu = $firststu if ($ctr > $ngrade);
1463: }
1.44 ng 1464:
1.41 ng 1465: my (@parsedlist,@nextlist);
1466: my ($nextflg) = 0;
1.53 albertel 1467: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41 ng 1468: if ($nextflg == 1 && $button =~ /Next$/) {
1469: push @parsedlist,$_;
1470: }
1471: $nextflg = 1 if ($_ eq $laststu);
1472: if ($button eq 'Previous') {
1473: last if ($_ eq $firststu);
1474: push @parsedlist,$_;
1475: }
1476: }
1477: $ctr = 0;
1478: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1479: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1480: foreach my $student (@parsedlist) {
1481: my ($uname,$udom) = split(/:/,$student);
1482: if ($ENV{'form.submitonly'} eq 'yes') {
1.44 ng 1483: my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
1.41 ng 1484: my $statusflg = '';
1485: foreach (keys(%status)) {
1486: $statusflg = 1 if ($status{$_} ne 'nothing');
1.44 ng 1487: my ($foo,$partid,$foo1) = split(/\./);
1.41 ng 1488: $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
1489: }
1490: next if ($statusflg eq '');
1491: }
1492: push @nextlist,$student if ($ctr < $ntstu);
1493: $ctr++;
1494: }
1.36 ng 1495:
1.41 ng 1496: $ctr = 0;
1497: my $total = scalar(@nextlist)-1;
1.39 ng 1498:
1.41 ng 1499: foreach (sort @nextlist) {
1500: my ($uname,$udom,$submitter) = split(/:/);
1.44 ng 1501: $ENV{'form.student'} = $uname;
1502: $ENV{'form.userdom'} = $udom;
1.41 ng 1503: $ENV{'form.fullname'} = $$fullname{$_};
1504: &submission($request,$ctr,$total);
1505: $ctr++;
1506: }
1507: if ($total < 0) {
1508: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
1509: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
1510: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1511: $the_end.=&show_grading_menu_form ($symb,$url);
1512: $request->print($the_end);
1513: }
1514: return '';
1.38 ng 1515: }
1.36 ng 1516:
1.44 ng 1517: #---- Save the score and award for each student, if changed
1.38 ng 1518: sub saveHandGrade {
1.41 ng 1519: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
1.77 ng 1520: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
1521: my %newrecord = ();
1522: my ($pts,$wgt) = ('','');
1.41 ng 1523: foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1.43 ng 1524: if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
1.58 albertel 1525: if ($record{'resource.'.$_.'.solved'} ne 'excused') {
1526: $newrecord{'resource.'.$_.'.solved'} = 'excused';
1527: if (exists($record{'resource.'.$_.'.awarded'})) {
1528: $newrecord{'resource.'.$_.'.awarded'} = '';
1529: }
1530: }
1.41 ng 1531: } else {
1.77 ng 1532: $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
1533: $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
1534: $ENV{'form.RADVAL'.$newflg.'_'.$_});
1.71 ng 1535: return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
1.77 ng 1536: $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
1.44 ng 1537: $ENV{'form.WGT'.$newflg.'_'.$_};
1.41 ng 1538: my $partial= $pts/$wgt;
1.44 ng 1539: $newrecord{'resource.'.$_.'.awarded'} = $partial
1540: if ($record{'resource.'.$_.'.awarded'} ne $partial);
1541: my $reckey = 'resource.'.$_.'.solved';
1.41 ng 1542: if ($partial == 0) {
1.44 ng 1543: $newrecord{$reckey} = 'incorrect_by_override'
1544: if ($record{$reckey} ne 'incorrect_by_override');
1.41 ng 1545: } else {
1.44 ng 1546: $newrecord{$reckey} = 'correct_by_override'
1547: if ($record{$reckey} ne 'correct_by_override');
1.41 ng 1548: }
1.44 ng 1549: $newrecord{'resource.'.$_.'.submitted_by'} = $submitter
1550: if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
1.72 ng 1551: $newrecord{'resource.'.$_.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.41 ng 1552: }
1553: }
1.44 ng 1554:
1555: if (scalar(keys(%newrecord)) > 0) {
1556: &Apache::lonnet::cstore(\%newrecord,$symb,
1557: $ENV{'request.course.id'},$domain,$stuname);
1.41 ng 1558: }
1.77 ng 1559: return '',$pts,$wgt;
1.36 ng 1560: }
1.38 ng 1561:
1.44 ng 1562: #--------------------------------------------------------------------------------------
1563: #
1564: #-------------------------- Next few routines handles grading by section or whole class
1565: #
1566: #--- Javascript to handle grading by section or whole class
1.42 ng 1567: sub viewgrades_js {
1568: my ($request) = shift;
1569:
1.41 ng 1570: $request->print(<<VIEWJAVASCRIPT);
1571: <script type="text/javascript" language="javascript">
1.45 ng 1572: function writePoint(partid,weight,point) {
1.42 ng 1573: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1574: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1575: if (point == "textval") {
1576: var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
1577: if (isNaN(point) || point < 0) {
1578: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1579: var resetbox = false;
1580: for (var i=0; i<radioButton.length; i++) {
1581: if (radioButton[i].checked) {
1582: textbox.value = i;
1583: resetbox = true;
1584: }
1585: }
1586: if (!resetbox) {
1587: textbox.value = "";
1588: }
1589: return;
1590: }
1.44 ng 1591: if (point > weight) {
1592: var resp = confirm("You entered a value ("+point+
1593: ") greater than the weight for the part. Accept?");
1594: if (resp == false) {
1595: textbox.value = "";
1596: return;
1597: }
1598: }
1.42 ng 1599: for (var i=0; i<radioButton.length; i++) {
1600: radioButton[i].checked=false;
1601: if (point == i) {
1602: radioButton[i].checked=true;
1603: }
1604: }
1.41 ng 1605:
1.42 ng 1606: } else {
1607: textbox.value = point;
1608: }
1.41 ng 1609: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1610: var user = eval("document.classgrade.ctr"+i+".value");
1611: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1612: "_"+partid+"_awarded");
1.43 ng 1613: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1614: "_"+partid+"_solved_s.value");
1615: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42 ng 1616: if (saveval != "correct") {
1617: scorename.value = point;
1.43 ng 1618: if (selname[0].selected != true) {
1619: selname[0].selected = true;
1620: }
1.42 ng 1621: }
1622: }
1623: var selval = eval("document.classgrade.SELVAL_"+partid);
1624: selval[0].selected = true;
1625: }
1626:
1627: function writeRadText(partid,weight) {
1628: var selval = eval("document.classgrade.SELVAL_"+partid);
1.43 ng 1629: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1630: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1.42 ng 1631: if (selval[1].selected) {
1632: for (var i=0; i<radioButton.length; i++) {
1633: radioButton[i].checked=false;
1634:
1635: }
1636: textbox.value = "";
1637:
1638: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1639: var user = eval("document.classgrade.ctr"+i+".value");
1640: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1641: "_"+partid+"_awarded");
1.43 ng 1642: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1643: "_"+partid+"_solved_s.value");
1.43 ng 1644: var selname = eval("document.classgrade.GD_"+user+
1.54 albertel 1645: "_"+partid+"_solved");
1.42 ng 1646: if (saveval != "correct") {
1647: scorename.value = "";
1648: selname[1].selected = true;
1649: }
1650: }
1.43 ng 1651: } else {
1652: for (i=0;i<document.classgrade.total.value;i++) {
1653: var user = eval("document.classgrade.ctr"+i+".value");
1654: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1655: "_"+partid+"_awarded");
1.43 ng 1656: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1657: "_"+partid+"_solved_s.value");
1.43 ng 1658: var selname = eval("document.classgrade.GD_"+user+
1.54 albertel 1659: "_"+partid+"_solved");
1.43 ng 1660: if (saveval != "correct") {
1661: scorename.value = eval("document.classgrade.GD_"+user+
1.54 albertel 1662: "_"+partid+"_awarded_s.value");;
1.43 ng 1663: selname[0].selected = true;
1664: }
1665: }
1666: }
1.42 ng 1667: }
1668:
1669: function changeSelect(partid,user) {
1.54 albertel 1670: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1671: var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.44 ng 1672: var point = textbox.value;
1673: var weight = eval("document.classgrade.weight_"+partid+".value");
1674:
1675: if (isNaN(point) || point < 0) {
1676: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1677: textbox.value = "";
1678: return;
1679: }
1680: if (point > weight) {
1681: var resp = confirm("You entered a value ("+point+
1682: ") greater than the weight of the part. Accept?");
1683: if (resp == false) {
1684: textbox.value = "";
1685: return;
1686: }
1687: }
1.42 ng 1688: selval[0].selected = true;
1689: }
1690:
1691: function changeOneScore(partid,user) {
1.54 albertel 1692: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1.42 ng 1693: if (selval[1].selected) {
1.54 albertel 1694: var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.42 ng 1695: boxval.value = "";
1696: }
1697: }
1698:
1699: function resetEntry(numpart) {
1700: for (ctpart=0;ctpart<numpart;ctpart++) {
1701: var partid = eval("document.classgrade.partid_"+ctpart+".value");
1702: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1703: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1704: var selval = eval("document.classgrade.SELVAL_"+partid);
1705: for (var i=0; i<radioButton.length; i++) {
1706: radioButton[i].checked=false;
1707:
1708: }
1709: textbox.value = "";
1710: selval[0].selected = true;
1711:
1712: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1713: var user = eval("document.classgrade.ctr"+i+".value");
1714: var resetscore = eval("document.classgrade.GD_"+user+
1.54 albertel 1715: "_"+partid+"_awarded");
1.43 ng 1716: resetscore.value = eval("document.classgrade.GD_"+user+
1.54 albertel 1717: "_"+partid+"_awarded_s.value");
1.42 ng 1718:
1.43 ng 1719: var saveselval = eval("document.classgrade.GD_"+user+
1.54 albertel 1720: "_"+partid+"_solved_s.value");
1.42 ng 1721:
1.54 albertel 1722: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42 ng 1723: if (saveselval == "excused") {
1.43 ng 1724: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 1725: } else {
1.43 ng 1726: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 1727: }
1728: }
1.41 ng 1729: }
1.42 ng 1730: }
1731:
1.41 ng 1732: </script>
1733: VIEWJAVASCRIPT
1.42 ng 1734: }
1735:
1.44 ng 1736: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 1737: sub viewgrades {
1738: my ($request) = shift;
1739: &viewgrades_js($request);
1.41 ng 1740:
1741: my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
1.45 ng 1742: my $result='<h3><font color="#339933">Manual Grading</font></h3>';
1.38 ng 1743:
1.72 ng 1744: $result.='<font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font>'."\n";
1.41 ng 1745:
1746: #view individual student submission form - called using Javascript viewOneStudent
1.45 ng 1747: $result.=&jscriptNform($url,$symb);
1.41 ng 1748:
1.44 ng 1749: #beginning of class grading form
1.41 ng 1750: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1751: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1752: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 1753: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.72 ng 1754: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n".
1.77 ng 1755: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 1756: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
1757:
1.52 albertel 1758: $result.='<h3>Assign Common Grade To ';
1759: if ($ENV{'form.section'} eq 'all') {
1760: $result.='Class </h3>';
1761: } elsif ($ENV{'form.section'} eq 'no') {
1762: $result.='Students in no Section </h3>';
1763: } else {
1764: $result.='Students in Section '.$ENV{'form.section'}.'</h3>';
1765: }
1766: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1767: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 1768: #radio buttons/text box for assigning points for a section or class.
1769: #handles different parts of a problem
1.42 ng 1770: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1771: my %weight = ();
1772: my $ctsparts = 0;
1.41 ng 1773: $result.='<table border="0">';
1.45 ng 1774: my %seen = ();
1.42 ng 1775: for (sort keys(%$handgrade)) {
1.54 albertel 1776: my ($partid,$respid) = split (/_/,$_,2);
1.45 ng 1777: next if $seen{$partid};
1778: $seen{$partid}++;
1.42 ng 1779: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
1780: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
1781: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
1782:
1.44 ng 1783: $result.='<input type="hidden" name="partid_'.
1784: $ctsparts.'" value="'.$partid.'" />'."\n";
1785: $result.='<input type="hidden" name="weight_'.
1786: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1787: $result.='<tr><td><b>Part '.$partid.' Point:</b> </td><td>';
1.42 ng 1788: $result.='<table border="0"><tr>';
1.41 ng 1789: my $ctr = 0;
1.42 ng 1790: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1791: $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 1792: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.41 ng 1793: ','.$ctr.')" />'.$ctr."</td>\n";
1794: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1795: $ctr++;
1796: }
1797: $result.='</tr></table>';
1.44 ng 1798: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 1799: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
1800: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 1801: $weight{$partid}.' (problem weight)</td>'."\n";
1802: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 1803: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 1804: $weight{$partid}.')"> '.
1.42 ng 1805: '<option selected="on"> </option>'.
1806: '<option>excused</option></select></td></tr>'."\n";
1807: $ctsparts++;
1.41 ng 1808: }
1.52 albertel 1809: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
1810: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 1811: $result.='<input type="button" value="Reset" '.
1.43 ng 1812: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self> ';
1.45 ng 1813: $result.='<input type="button" value="Submit Changes" '.
1814: 'onClick="javascript:submit();" TARGET=_self />'."\n";
1.41 ng 1815:
1.44 ng 1816: #table listing all the students in a section/class
1817: #header of table
1.52 albertel 1818: $result.= '<h3>Assign Grade to Specific Students in ';
1819: if ($ENV{'form.section'} eq 'all') {
1820: $result.='the Class </h3>';
1821: } elsif ($ENV{'form.section'} eq 'no') {
1822: $result.='no Section </h3>';
1823: } else {
1824: $result.='Section '.$ENV{'form.section'}.'</h3>';
1825: }
1.42 ng 1826: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.41 ng 1827: '<table border=0><tr bgcolor="#deffff">'.
1.44 ng 1828: '<td><b>Fullname</b></td><td><b>Username</b></td><td><b>Domain</b></td>'."\n";
1.41 ng 1829: my (@parts) = sort(&getpartlist($url));
1830: foreach my $part (@parts) {
1831: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1832: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1833: if ($display =~ /^Partial Credit Factor/) {
1.54 albertel 1834: my ($partid) = &split_part_type($part);
1.53 albertel 1835: $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
1.42 ng 1836: $weight{$partid}.')</b></td>'."\n";
1.41 ng 1837: next;
1838: }
1.53 albertel 1839: $display =~ s|Problem Status|Grade Status<br />|;
1.41 ng 1840: $result.='<td><b>'.$display.'</b></td>'."\n";
1841: }
1842: $result.='</tr>';
1.44 ng 1843:
1.41 ng 1844: #get info for each student
1.44 ng 1845: #list all the students - with points and grade status
1.76 ng 1846: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
1.41 ng 1847: my $ctr = 0;
1.53 albertel 1848: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44 ng 1849: my ($uname,$udom) = split(/:/);
1850: $result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
1.41 ng 1851: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
1852: $_,$$fullname{$_},\@parts,\%weight);
1853: $ctr++;
1854: }
1855: $result.='</table></td></tr></table>';
1856: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.45 ng 1857: $result.='<input type="button" value="Submit Changes" '.
1858: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.41 ng 1859: $result.=&show_grading_menu_form($symb,$url);
1860: return $result;
1861: }
1862:
1.44 ng 1863: #--- call by previous routine to display each student
1.41 ng 1864: sub viewstudentgrade {
1865: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
1.44 ng 1866: my ($uname,$udom) = split(/:/,$student);
1867: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.41 ng 1868: my $result='<tr bgcolor="#ffffdd"><td>'.
1.44 ng 1869: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1870: '\')"; TARGET=_self>'.$fullname.'</a>'.
1871: '</td><td>'.$uname.'</td><td align="middle">'.$udom.'</td>'."\n";
1.63 albertel 1872: foreach my $apart (@$parts) {
1873: my ($part,$type) = &split_part_type($apart);
1.41 ng 1874: my $score=$record{"resource.$part.$type"};
1875: if ($type eq 'awarded') {
1.42 ng 1876: my $pts = $score eq '' ? '' : $score*$$weight{$part};
1877: $result.='<input type="hidden" name="'.
1.54 albertel 1878: 'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.42 ng 1879: $result.='<td align="middle"><input type="text" name="'.
1.54 albertel 1880: 'GD_'.$uname.'_'.$part.'_awarded" '.
1881: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$uname.
1.44 ng 1882: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 1883: } elsif ($type eq 'solved') {
1884: my ($status,$foo)=split(/_/,$score,2);
1885: $status = 'nothing' if ($status eq '');
1.54 albertel 1886: $result.='<input type="hidden" name="'.'GD_'.$uname.'_'.
1887: $part.'_solved_s" value="'.$status.'" />'."\n";
1.42 ng 1888: $result.='<td align="middle"><select name="'.
1.54 albertel 1889: 'GD_'.$uname.'_'.$part.'_solved" '.
1890: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$uname.'\')" >'."\n";
1.42 ng 1891: my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
1892: $optsel = '<option> </option><option selected="on">excused</option>'."\n"
1893: if ($status eq 'excused');
1.41 ng 1894: $result.=$optsel;
1895: $result.="</select></td>\n";
1.54 albertel 1896: } else {
1897: $result.='<input type="hidden" name="'.
1898: 'GD_'.$uname.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
1899: "\n";
1900: $result.='<td align="middle"><input type="text" name="'.
1901: 'GD_'.$uname.'_'.$part.'_'.$type.'" '.
1902: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 1903: }
1904: }
1905: $result.='</tr>';
1906: return $result;
1.38 ng 1907: }
1908:
1.44 ng 1909: #--- change scores for all the students in a section/class
1910: # record does not get update if unchanged
1.38 ng 1911: sub editgrades {
1.41 ng 1912: my ($request) = @_;
1913:
1914: my $symb=$ENV{'form.symb'};
1.43 ng 1915: my $url =$ENV{'form.url'};
1.45 ng 1916: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.72 ng 1917: $title.='<font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font><br />'."\n";
1.44 ng 1918: $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
1919: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.43 ng 1920: $result.= '<table border="0"><tr bgcolor="#deffff">'.
1921: '<td rowspan=2><b>Username</b></td><td rowspan=2><b>Fullname</b></td>'."\n";
1922:
1923: my %scoreptr = (
1924: 'correct' =>'correct_by_override',
1925: 'incorrect'=>'incorrect_by_override',
1926: 'excused' =>'excused',
1927: 'ungraded' =>'ungraded_attempted',
1928: 'nothing' => '',
1929: );
1.56 matthew 1930: my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.34 ng 1931:
1.44 ng 1932: my (@partid);
1933: my %weight = ();
1.54 albertel 1934: my %columns = ();
1.44 ng 1935: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 1936:
1937: my (@parts) = sort(&getpartlist($url));
1938: my $header;
1.44 ng 1939: while ($ctr < $ENV{'form.totalparts'}) {
1940: my $partid = $ENV{'form.partid_'.$ctr};
1941: push @partid,$partid;
1942: $weight{$partid} = $ENV{'form.weight_'.$partid};
1943: $ctr++;
1.54 albertel 1944: }
1945: foreach my $partid (@partid) {
1946: $header .= '<td align="center"> <b>Old Score</b> </td>'.
1947: '<td align="center"> <b>New Score</b> </td>';
1948: $columns{$partid}=2;
1949: foreach my $stores (@parts) {
1950: my ($part,$type) = &split_part_type($stores);
1951: if ($part !~ m/^\Q$partid\E/) { next;}
1952: if ($type eq 'awarded' || $type eq 'solved') { next; }
1953: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1954: $display =~ s/\[Part: (\w)+\]//;
1955: $header .= '<td align="center"> <b>Old</b> '.$display.' </td>'.
1956: '<td align="center"> <b>New</b> '.$display.' </td>';
1957: $columns{$partid}+=2;
1958: }
1959: }
1960: foreach my $partid (@partid) {
1961: $result .= '<td colspan="'.$columns{$partid}.
1962: '" align="center"><b>Part '.$partid.
1.44 ng 1963: '</b> (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 1964:
1.44 ng 1965: }
1966: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 1967: $result .= $header;
1.44 ng 1968: $result .= '</tr>'."\n";
1.13 albertel 1969:
1.44 ng 1970: for ($i=0; $i<$ENV{'form.total'}; $i++) {
1971: my $user = $ENV{'form.ctr'.$i};
1972: my %newrecord;
1973: my $updateflag = 0;
1974: my @userdom = grep /^$user:/,keys %$classlist;
1.54 albertel 1975: my (undef,$udom) = split(/:/,$userdom[0]);
1.13 albertel 1976:
1.44 ng 1977: $result .= '<tr bgcolor="#ffffde"><td>'.$user.' </td><td>'.
1978: $$fullname{$userdom[0]}.' </td>';
1979: foreach (@partid) {
1.54 albertel 1980: my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1981: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
1982: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1983: my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1984:
1985: my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
1986: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
1987: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 1988: my $score;
1989: if ($partial eq '') {
1.54 albertel 1990: $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 1991: } elsif ($partial > 0) {
1992: $score = 'correct_by_override';
1993: } elsif ($partial == 0) {
1994: $score = 'incorrect_by_override';
1995: }
1.54 albertel 1996: $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
1.44 ng 1997: ($score ne 'excused'));
1998: $result .= '<td align="center">'.$old_aw.' </td>'.
1999: '<td align="center">'.$awarded.
2000: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 2001:
1.54 albertel 2002: if (!($old_part eq $partial && $old_score eq $score)) {
2003: $updateflag = 1;
2004: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
2005: $newrecord{'resource.'.$_.'.solved'} = $score;
2006: $rec_update++;
2007: }
2008:
2009: my $partid=$_;
2010: foreach my $stores (@parts) {
2011: my ($part,$type) = &split_part_type($stores);
2012: if ($part !~ m/^\Q$partid\E/) { next;}
2013: if ($type eq 'awarded' || $type eq 'solved') { next; }
2014: my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
2015: my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
2016: if ($awarded ne '' && $awarded ne $old_aw) {
2017: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.72 ng 2018: $newrecord{'resource.'.$part.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.54 albertel 2019: $updateflag=1;
2020: }
2021: $result .= '<td align="center">'.$old_aw.' </td>'.
2022: '<td align="center">'.$awarded.' </td>';
2023: }
1.44 ng 2024: }
2025: $result .= '</tr>'."\n";
2026: if ($updateflag) {
2027: $count++;
2028: &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
2029: $udom,$user);
2030: }
2031: }
1.72 ng 2032: $result .= '</table></td></tr></table>'."\n".
2033: &show_grading_menu_form ($symb,$url);
1.44 ng 2034: my $msg = '<b>Number of records updated = '.$rec_update.
2035: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
2036: '<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
2037: return $title.$msg.$result;
1.5 albertel 2038: }
1.54 albertel 2039:
2040: sub split_part_type {
2041: my ($partstr) = @_;
2042: my ($temp,@allparts)=split(/_/,$partstr);
2043: my $type=pop(@allparts);
2044: my $part=join('.',@allparts);
2045: return ($part,$type);
2046: }
2047:
1.44 ng 2048: #------------- end of section for handling grading by section/class ---------
2049: #
2050: #----------------------------------------------------------------------------
2051:
1.5 albertel 2052:
1.44 ng 2053: #----------------------------------------------------------------------------
2054: #
2055: #-------------------------- Next few routines handles grading by csv upload
2056: #
2057: #--- Javascript to handle csv upload
1.27 albertel 2058: sub csvupload_javascript_reverse_associate {
2059: return(<<ENDPICK);
2060: function verify(vf) {
2061: var foundsomething=0;
2062: var founduname=0;
2063: var founddomain=0;
2064: for (i=0;i<=vf.nfields.value;i++) {
2065: tw=eval('vf.f'+i+'.selectedIndex');
2066: if (i==0 && tw!=0) { founduname=1; }
2067: if (i==1 && tw!=0) { founddomain=1; }
2068: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
2069: }
2070: if (founduname==0 || founddomain==0) {
2071: alert('You need to specify at both the username and domain');
2072: return;
2073: }
2074: if (foundsomething==0) {
2075: alert('You need to specify at least one grading field');
2076: return;
2077: }
2078: vf.submit();
2079: }
2080: function flip(vf,tf) {
2081: var nw=eval('vf.f'+tf+'.selectedIndex');
2082: var i;
2083: for (i=0;i<=vf.nfields.value;i++) {
2084: //can not pick the same destination field for both name and domain
2085: if (((i ==0)||(i ==1)) &&
2086: ((tf==0)||(tf==1)) &&
2087: (i!=tf) &&
2088: (eval('vf.f'+i+'.selectedIndex')==nw)) {
2089: eval('vf.f'+i+'.selectedIndex=0;')
2090: }
2091: }
2092: }
2093: ENDPICK
2094: }
2095:
2096: sub csvupload_javascript_forward_associate {
2097: return(<<ENDPICK);
2098: function verify(vf) {
2099: var foundsomething=0;
2100: var founduname=0;
2101: var founddomain=0;
2102: for (i=0;i<=vf.nfields.value;i++) {
2103: tw=eval('vf.f'+i+'.selectedIndex');
2104: if (tw==1) { founduname=1; }
2105: if (tw==2) { founddomain=1; }
2106: if (tw>2) { foundsomething=1; }
2107: }
2108: if (founduname==0 || founddomain==0) {
2109: alert('You need to specify at both the username and domain');
2110: return;
2111: }
2112: if (foundsomething==0) {
2113: alert('You need to specify at least one grading field');
2114: return;
2115: }
2116: vf.submit();
2117: }
2118: function flip(vf,tf) {
2119: var nw=eval('vf.f'+tf+'.selectedIndex');
2120: var i;
2121: //can not pick the same destination field twice
2122: for (i=0;i<=vf.nfields.value;i++) {
2123: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
2124: eval('vf.f'+i+'.selectedIndex=0;')
2125: }
2126: }
2127: }
2128: ENDPICK
2129: }
2130:
1.26 albertel 2131: sub csvuploadmap_header {
1.41 ng 2132: my ($request,$symb,$url,$datatoken,$distotal)= @_;
2133: my $javascript;
2134: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2135: $javascript=&csvupload_javascript_reverse_associate();
2136: } else {
2137: $javascript=&csvupload_javascript_forward_associate();
2138: }
1.45 ng 2139:
2140: my $result='<table border="0">';
1.72 ng 2141: $result.='<tr><td colspan=3><font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font></td></tr>';
1.45 ng 2142: my ($partlist,$handgrade) = &response_type($url);
2143: my ($resptype,$hdgrade)=('','no');
2144: for (sort keys(%$handgrade)) {
2145: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
2146: $resptype = $responsetype;
2147: $hdgrade = $handgrade if ($handgrade eq 'yes');
2148: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
2149: '<td><b>Type: </b>'.$responsetype.'</td>'.
2150: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
2151: }
2152: $result.='</table>';
1.41 ng 2153: $request->print(<<ENDPICK);
1.26 albertel 2154: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 2155: <h3><font color="#339933">Uploading Class Grades</font></h3>
2156: $result
1.26 albertel 2157: <hr>
2158: <h3>Identify fields</h3>
2159: Total number of records found in file: $distotal <hr />
2160: Enter as many fields as you can. The system will inform you and bring you back
2161: to this page if the data selected is insufficient to run your class.<hr />
2162: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
2163: <input type="hidden" name="associate" value="" />
2164: <input type="hidden" name="phase" value="three" />
2165: <input type="hidden" name="datatoken" value="$datatoken" />
2166: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
2167: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
2168: <input type="hidden" name="upfile_associate"
2169: value="$ENV{'form.upfile_associate'}" />
2170: <input type="hidden" name="symb" value="$symb" />
2171: <input type="hidden" name="url" value="$url" />
1.77 ng 2172: <input type="hidden" name="saveState" value="$ENV{'form.saveState'}" />
1.72 ng 2173: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
1.26 albertel 2174: <input type="hidden" name="command" value="csvuploadassign" />
2175: <hr />
2176: <script type="text/javascript" language="Javascript">
2177: $javascript
2178: </script>
2179: ENDPICK
1.41 ng 2180: return '';
1.26 albertel 2181:
2182: }
2183:
2184: sub csvupload_fields {
1.41 ng 2185: my ($url) = @_;
2186: my (@parts) = &getpartlist($url);
2187: my @fields=(['username','Student Username'],['domain','Student Domain']);
2188: foreach my $part (sort(@parts)) {
2189: my @datum;
2190: my $display=&Apache::lonnet::metadata($url,$part.'.display');
2191: my $name=$part;
2192: if (!$display) { $display = $name; }
2193: @datum=($name,$display);
2194: push(@fields,\@datum);
2195: }
2196: return (@fields);
1.26 albertel 2197: }
2198:
2199: sub csvuploadmap_footer {
1.41 ng 2200: my ($request,$i,$keyfields) =@_;
2201: $request->print(<<ENDPICK);
1.26 albertel 2202: </table>
2203: <input type="hidden" name="nfields" value="$i" />
2204: <input type="hidden" name="keyfields" value="$keyfields" />
2205: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
2206: </form>
2207: ENDPICK
2208: }
2209:
1.86 ! ng 2210: sub upcsvScores_form {
! 2211: my ($request) = shift;
! 2212: my ($symb,$url)=&get_symb_and_url($request);
! 2213: if (!$symb) {return '';}
! 2214: my $result =<<CSVFORMJS;
! 2215: <script type="text/javascript" language="javascript">
! 2216: function checkUpload(formname) {
! 2217: if (formname.upfile.value == "") {
! 2218: alert("Please use the browse button to select a file from your local directory.");
! 2219: return false;
! 2220: }
! 2221: formname.submit();
! 2222: }
! 2223: </script>
! 2224: CSVFORMJS
! 2225: $ENV{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
! 2226: $result.='<br /><table width=100% border=0><tr><td bgcolor="#777777">'."\n";
! 2227: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
! 2228: $result.=' <b>Specify a file containing the class scores for problem - '.$ENV{'form.probTitle'}.
! 2229: '.</b></td></tr>'."\n";
! 2230: $result.='<tr bgcolor=#ffffe6><td>'."\n";
! 2231: my $upfile_select=&Apache::loncommon::upfile_select_html();
! 2232: $result.=<<ENDUPFORM;
! 2233: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload" target="LONcatInfo">
! 2234: <input type="hidden" name="symb" value="$symb" />
! 2235: <input type="hidden" name="url" value="$url" />
! 2236: <input type="hidden" name="command" value="csvuploadmap" />
! 2237: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
! 2238: <input type="hidden" name="saveState" value="$ENV{'form.saveState'}" />
! 2239: $upfile_select
! 2240: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />
! 2241:
! 2242: </form>
! 2243: ENDUPFORM
! 2244: $result.='</td></tr></table>'."\n";
! 2245: $result.='</td></tr></table><br /><br />'."\n";
! 2246: $result.=&show_grading_menu_form($symb,$url);
! 2247:
! 2248: return $result;
! 2249: }
! 2250:
! 2251:
1.26 albertel 2252: sub csvuploadmap {
1.41 ng 2253: my ($request)= @_;
2254: my ($symb,$url)=&get_symb_and_url($request);
2255: if (!$symb) {return '';}
1.72 ng 2256:
1.41 ng 2257: my $datatoken;
2258: if (!$ENV{'form.datatoken'}) {
2259: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 2260: } else {
1.41 ng 2261: $datatoken=$ENV{'form.datatoken'};
2262: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 2263: }
1.41 ng 2264: my @records=&Apache::loncommon::upfile_record_sep();
2265: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
2266: my ($i,$keyfields);
2267: if (@records) {
2268: my @fields=&csvupload_fields($url);
1.45 ng 2269:
1.41 ng 2270: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2271: &Apache::loncommon::csv_print_samples($request,\@records);
2272: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
2273: \@fields);
2274: foreach (@fields) { $keyfields.=$_->[0].','; }
2275: chop($keyfields);
2276: } else {
2277: unshift(@fields,['none','']);
2278: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
2279: \@fields);
2280: my %sone=&Apache::loncommon::record_sep($records[0]);
2281: $keyfields=join(',',sort(keys(%sone)));
2282: }
2283: }
2284: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 2285: $request->print(&show_grading_menu_form($symb,$url));
2286:
1.41 ng 2287: return '';
1.27 albertel 2288: }
2289:
2290: sub csvuploadassign {
1.41 ng 2291: my ($request)= @_;
2292: my ($symb,$url)=&get_symb_and_url($request);
2293: if (!$symb) {return '';}
2294: &Apache::loncommon::load_tmp_file($request);
1.44 ng 2295: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.41 ng 2296: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
2297: my %fields=();
2298: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
2299: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2300: if ($ENV{'form.f'.$i} ne 'none') {
2301: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
2302: }
2303: } else {
2304: if ($ENV{'form.f'.$i} ne 'none') {
2305: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
2306: }
2307: }
1.27 albertel 2308: }
1.41 ng 2309: $request->print('<h3>Assigning Grades</h3>');
2310: my $courseid=$ENV{'request.course.id'};
2311: my ($classlist) = &getclasslist('all','1');
2312: my @skipped;
2313: my $countdone=0;
2314: foreach my $grade (@gradedata) {
2315: my %entries=&Apache::loncommon::record_sep($grade);
2316: my $username=$entries{$fields{'username'}};
2317: my $domain=$entries{$fields{'domain'}};
2318: if (!exists($$classlist{"$username:$domain"})) {
2319: push(@skipped,"$username:$domain");
2320: next;
2321: }
2322: my %grades;
2323: foreach my $dest (keys(%fields)) {
2324: if ($dest eq 'username' || $dest eq 'domain') { next; }
2325: if ($entries{$fields{$dest}} eq '') { next; }
2326: my $store_key=$dest;
2327: $store_key=~s/^stores/resource/;
2328: $store_key=~s/_/\./g;
2329: $grades{$store_key}=$entries{$fields{$dest}};
2330: }
2331: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
2332: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
2333: $domain,$username);
2334: $request->print('.');
2335: $request->rflush();
2336: $countdone++;
2337: }
2338: $request->print("<br />Stored $countdone students\n");
2339: if (@skipped) {
2340: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
2341: foreach my $student (@skipped) { $request->print("<br />$student"); }
2342: }
2343: $request->print(&view_edit_entire_class_form($symb,$url));
2344: $request->print(&show_grading_menu_form($symb,$url));
2345: return '';
1.26 albertel 2346: }
1.44 ng 2347: #------------- end of section for handling csv file upload ---------
2348: #
2349: #-------------------------------------------------------------------
2350: #
1.72 ng 2351: #-------------- Next few routines handles grading by page/sequence
2352: #
2353: #--- Select a page/sequence and a student to grade
1.68 ng 2354: sub pickStudentPage {
2355: my ($request) = shift;
2356:
2357: $request->print(<<LISTJAVASCRIPT);
2358: <script type="text/javascript" language="javascript">
2359:
2360: function checkPickOne(formname) {
1.76 ng 2361: if (radioSelection(formname.student) == null) {
1.68 ng 2362: alert("Please select the student you wish to grade.");
2363: return;
2364: }
1.70 ng 2365: var ptr = pullDownSelection(formname.selectpage);
1.71 ng 2366: formname.page.value = eval("formname.page"+ptr+".value");
2367: formname.title.value = eval("formname.title"+ptr+".value");
1.68 ng 2368: formname.submit();
2369: }
2370:
2371: function radioSelection(radioButton) {
2372: var selection=null;
1.76 ng 2373: if (radioButton.length > 1) {
2374: for (var i=0; i<radioButton.length; i++) {
2375: if (radioButton[i].checked) {
2376: return radioButton[i].value;
2377: }
2378: }
2379: } else {
2380: if (radioButton.checked) return radioButton.value;
1.68 ng 2381: }
2382: return selection;
2383: }
1.76 ng 2384:
1.70 ng 2385: function pullDownSelection(selectOne) {
1.76 ng 2386: var selection="";
2387: if (selectOne.length > 1) {
2388: for (var i=0; i<selectOne.length; i++) {
2389: if (selectOne[i].selected) {
2390: return selectOne[i].value;
2391: }
2392: }
2393: } else {
2394: if (selectOne.selected) return selectOne.value;
1.70 ng 2395: }
2396: }
1.68 ng 2397: </script>
2398: LISTJAVASCRIPT
2399:
1.72 ng 2400: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2401: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2402: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2403: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2404:
2405: my $result='<h3><font color="#339933"> '.
2406: 'Manual Grading by Page or Sequence</font></h3>';
2407:
1.80 ng 2408: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 2409: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 2410: my ($titles,$symbx) = &getSymbMap($request);
1.71 ng 2411: my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
1.70 ng 2412: my $ctr=0;
1.68 ng 2413: foreach (@$titles) {
2414: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 2415: $result.='<option value="'.$ctr.'" '.
1.71 ng 2416: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
2417: '>'.$showtitle.'</option>'."\n";
1.70 ng 2418: $ctr++;
1.68 ng 2419: }
2420: $result.= '</select>'."<br>\n";
1.70 ng 2421: $ctr=0;
2422: foreach (@$titles) {
2423: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
2424: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
2425: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
2426: $ctr++;
2427: }
1.72 ng 2428: $result.='<input type="hidden" name="page" />'."\n".
2429: '<input type="hidden" name="title" />'."\n";
1.68 ng 2430:
1.71 ng 2431: $result.=' <b>View Problems: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
2432: '<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
1.72 ng 2433:
1.71 ng 2434: $result.=' <b>Submission Details: </b>'.
2435: '<input type="radio" name="lastSub" value="none" /> none'."\n".
2436: '<input type="radio" name="lastSub" value="datesub" checked /> dates and submissions'."\n".
2437: '<input type="radio" name="lastSub" value="all" /> all details'."\n";
1.72 ng 2438:
1.68 ng 2439: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.72 ng 2440: '<input type="hidden" name="command" value="displayPage" />'."\n".
2441: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.80 ng 2442: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2443: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."<br />\n";
1.72 ng 2444:
1.80 ng 2445: $result.=' <input type="button" '.
1.72 ng 2446: 'onClick="javascript:checkPickOne(this.form);"value="Submit" /><br />'."\n";
2447:
1.68 ng 2448: $request->print($result);
2449:
1.76 ng 2450: my $studentTable.=' <b>Select a student you wish to grade</b><br>'.
1.68 ng 2451: '<table border="0"><tr><td bgcolor="#777777">'.
2452: '<table border="0"><tr bgcolor="#e6ffff">'.
2453: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2454: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2455: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2456: '<td><b> Fullname <font color="#999999">(username)</font></b></td></tr>';
2457:
1.76 ng 2458: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 2459: my $ptr = 1;
2460: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
2461: my ($uname,$udom) = split(/:/,$student);
2462: $studentTable.=($ptr%4 == 1 ? '<tr bgcolor="#ffffe6"><td>' : '</td><td>');
1.70 ng 2463: $studentTable.='<input type="radio" name="student" value="'.$student.'" /> '.$$fullname{$student}.
1.68 ng 2464: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
2465: $studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
2466: $ptr++;
2467: }
2468: $studentTable.='</td><td> </td><td> </td><td> ' if ($ptr%4 == 2);
2469: $studentTable.='</td><td> </td><td> ' if ($ptr%4 == 3);
2470: $studentTable.='</td><td> ' if ($ptr%4 == 0);
2471: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.70 ng 2472: $studentTable.='<br /> <input type="button" '.
2473: 'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
1.68 ng 2474:
2475: $studentTable.=&show_grading_menu_form($symb,$url);
2476: $request->print($studentTable);
2477:
2478: return '';
2479: }
2480:
2481: sub getSymbMap {
1.74 albertel 2482: my ($request) = @_;
1.79 bowersj2 2483: my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
1.68 ng 2484: $ENV{'request.course.fn'}.'_parms.db',1, 1);
2485:
2486: my $res = $navmap->firstResource(); # temp resource to access constants
2487: $navmap->init();
2488:
2489: # End navmap using boilerplate
2490:
2491: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
2492: my $depth = 1;
2493: $iterator->next(); # ignore first BEGIN_MAP
2494: my $curRes = $iterator->next();
2495:
2496: my %symbx = ();
2497: my @titles = ();
2498: my $minder=0;
2499: while ($depth > 0) {
2500: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
2501: if ($curRes == $iterator->END_MAP()) { $depth--; }
2502:
2503: if (ref($curRes) && $curRes->is_map()) {
1.71 ng 2504: my ($mapUrl, $id, $resUrl) = split(/___/, $curRes->symb()); # check map contains at least one problem
2505: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2506:
2507: my $mapiterator = $navmap->getIterator($map->map_start(),
2508: $map->map_finish());
2509:
2510: my $mapdepth = 1;
2511: my $countProblems = 0;
2512: $mapiterator->next(); # skip the first BEGIN_MAP
2513: my $mapcurRes = $mapiterator->next(); # for "current resource"
2514: my $ctr=0;
2515: while ($mapdepth > 0 && $ctr < 100) {
2516: if($mapcurRes == $mapiterator->BEGIN_MAP) { $mapdepth++; }
2517: if($mapcurRes == $mapiterator->END_MAP) { $mapdepth++; }
2518:
2519: if (ref($mapcurRes) && $mapcurRes->is_problem() && !$mapcurRes->randomout) {
2520: $countProblems++;
2521: }
2522: $ctr++;
2523: }
2524: if ($countProblems > 0) {
2525: my $title = $curRes->compTitle();
2526: push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
2527: $symbx{$minder.'.'.$title} = $curRes->symb();
2528: $minder++;
2529: }
1.68 ng 2530: }
2531: $curRes = $iterator->next();
2532: }
2533:
2534: $navmap->untieHashes();
2535: return \@titles,\%symbx;
2536: }
2537:
1.72 ng 2538: #
2539: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 2540: sub displayPage {
2541: my ($request) = shift;
2542:
1.72 ng 2543: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2544: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2545: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2546: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2547: my $pageTitle = $ENV{'form.page'};
1.76 ng 2548: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.70 ng 2549: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.68 ng 2550:
1.70 ng 2551: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
2552: $result.='<h3> Student: '.$$fullname{$ENV{'form.student'}}.
1.68 ng 2553: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
2554:
1.71 ng 2555: &sub_page_js($request);
2556: $request->print($result);
2557:
1.79 bowersj2 2558: my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
1.68 ng 2559: $ENV{'request.course.fn'}.'_parms.db',1, 1);
1.70 ng 2560: my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
1.68 ng 2561: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2562:
2563: my $iterator = $navmap->getIterator($map->map_start(),
2564: $map->map_finish());
2565:
1.71 ng 2566: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 2567: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
2568: '<input type="hidden" name="student" value="'.$ENV{'form.student'}.'" />'."\n".
2569: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
2570: '<input type="hidden" name="title" value="'.$ENV{'form.title'}.'" />'."\n".
2571: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2572: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.77 ng 2573: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
1.71 ng 2574:
2575: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
2576: '/check.gif" height="16" border="0" />';
2577:
2578: $studentTable.=' <b>Note:</b> A problem graded correct ('.$checkIcon.
2579: ') by the computer cannot be changed.'."\n".
2580: '<table border="0"><tr><td bgcolor="#777777">'.
2581: '<table border="0"><tr bgcolor="#e6ffff">'.
2582: '<td align="center"><b> No </b></td>'.
2583: '<td><b> '.($ENV{'form.vProb'} eq 'no' ? 'Title' : 'Problem View').'/Grade</b></td></tr>';
2584:
2585: my ($depth,$ctr,$question) = (1,0,1);
1.68 ng 2586: $iterator->next(); # skip the first BEGIN_MAP
2587: my $curRes = $iterator->next(); # for "current resource"
2588: while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
2589: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
2590: if($curRes == $iterator->END_MAP) { $depth++; }
2591:
2592: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
2593: my $parts = $curRes->parts();
1.72 ng 2594: $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
1.68 ng 2595: my $title = $curRes->compTitle();
1.71 ng 2596: my $symbx = $curRes->symb();
2597: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
2598: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
2599: $studentTable.='<td valign="top">';
2600: if ($ENV{'form.vProb'} eq 'yes') {
2601: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1);
2602: } else {
2603: my $companswer = &Apache::loncommon::get_student_answers(
2604: $symbx,$uname,$udom,$ENV{'request.course.id'});
1.80 ng 2605: $companswer =~ s|<form(.*?)>||g;
2606: $companswer =~ s|</form>||g;
1.71 ng 2607:
2608: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
2609: # $request->print('match='.$1.'<br>');
2610: # $companswer =~ s/$1/ /s;
2611: # }
2612: # $companswer =~ s/<table border=\"1\">/<table border=\"0\">/g;
2613: $studentTable.=' <b>'.$title.'</b> <br> <b>Correct answer:</b><br>'.$companswer;
2614: }
2615:
2616: my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname);
2617:
2618: if ($ENV{'form.lastSub'} eq 'datesub') {
2619: if ($record{'version'} eq '') {
2620: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
2621: } else {
2622: $studentTable.='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
2623: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
2624: '<td><b>Date/Time</b></td>'.
2625: '<td><b>Submission</b></td>'.
2626: '<td><b>Status </b></td></tr>';
2627: my ($version);
2628: for ($version=1;$version<=$record{'version'};$version++) {
2629: my $timestamp = scalar(localtime($record{$version.':timestamp'}));
2630: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
2631: my @versionKeys = split(/\:/,$record{$version.':keys'});
2632: my @displaySub = ();
2633: foreach my $partid (@{$parts}) {
2634: my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys;
1.77 ng 2635: next if ($record{"$version:resource.$partid.solved"} eq '');
2636: # next if ($record{"$version:resource.$partid.award"} eq 'APPROX_ANS' &&
2637: # $record{"$version:resource.$partid.solved"} eq '');
1.71 ng 2638: $displaySub[0].=(exists $record{$version.':'.$matchKey[0]}) ?
1.80 ng 2639: '<b>Part '.$partid.' '.
2640: ($record{"$version:resource.$partid.tries"} eq '' ? 'Trial not counted' :
2641: 'Trial '.$record{"$version:resource.$partid.tries"}).'</b> '.
2642: $record{$version.':'.$matchKey[0]}.'<br />' : '';
1.71 ng 2643: $displaySub[1].=(exists $record{"$version:resource.$partid.award"}) ?
1.77 ng 2644: '<b>Part '.$partid.'</b> '.
1.71 ng 2645: $record{"$version:resource.$partid.award"}.'/'.
2646: $record{"$version:resource.$partid.solved"}.'<br />' : '';
1.72 ng 2647: $displaySub[2].=(exists $record{"$version:resource.$partid.regrader"}) ?
2648: $record{"$version:resource.$partid.regrader"}.' (<b>Part:</b> '.$partid.')' : '';
1.71 ng 2649: }
1.72 ng 2650: $displaySub[2].=(exists $record{"$version:resource.regrader"}) ?
2651: $record{"$version:resource.regrader"} : '';
2652: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1].
2653: ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).' </td></tr>';
1.71 ng 2654: }
2655: $studentTable.='</table></td></tr></table>';
2656: }
2657: } elsif ($ENV{'form.lastSub'} eq 'all') {
2658: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
2659: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
2660: $ENV{'request.course.id'},
2661: '','.submission');
2662:
2663: }
2664:
2665: foreach my $partid (@{$parts}) {
2666: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
2667: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
2668: $question++;
2669: }
2670: $studentTable.='</td></tr>';
1.68 ng 2671:
2672: }
2673: $curRes = $iterator->next();
2674: $ctr++;
2675: }
2676:
1.71 ng 2677: $studentTable.='</td></tr></table></td></tr></table>'."\n".
2678: ' <input type="button" value="Save" '.
2679: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
2680: '</form>'."\n";
2681: $studentTable.=&show_grading_menu_form($symb,$url);
2682: $request->print($studentTable);
2683:
2684: return '';
2685: }
2686:
1.72 ng 2687: sub temp_parts_fix { #remove sub once lonnavmap is fixed
2688: my $parts = shift;
2689: my %seen = ();
2690: my @correctParts = ();
2691: foreach (@{$parts}) {
2692: next if ($seen{$_} > 0);
2693: $seen{$_}++;
2694: push @correctParts,$_;
2695: }
2696: return \@correctParts;
2697: }
2698:
1.71 ng 2699: sub updateGradeByPage {
2700: my ($request) = shift;
2701:
2702: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2703: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2704: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2705: my $pageTitle = $ENV{'form.page'};
1.76 ng 2706: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.71 ng 2707: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
2708:
2709: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
2710: $result.='<h3> Student: '.$$fullname{$ENV{'form.student'}}.
2711: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
1.70 ng 2712:
1.68 ng 2713: $request->print($result);
2714:
1.79 bowersj2 2715: my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
1.71 ng 2716: $ENV{'request.course.fn'}.'_parms.db',1, 1);
2717: my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
2718: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2719:
2720: my $iterator = $navmap->getIterator($map->map_start(),
2721: $map->map_finish());
1.70 ng 2722:
1.71 ng 2723: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 2724: '<table border="0"><tr bgcolor="#e6ffff">'.
1.70 ng 2725: '<td align="center"><b> No </b></td>'.
1.71 ng 2726: '<td><b> Title </b></td>'.
2727: '<td><b> Previous Score </b></td>'.
2728: '<td><b> New Score </b></td></tr>';
2729:
2730: $iterator->next(); # skip the first BEGIN_MAP
2731: my $curRes = $iterator->next(); # for "current resource"
2732: my ($depth,$ctr,$question,$changeflag)= (1,0,1,0);
2733: while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
2734: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
2735: if($curRes == $iterator->END_MAP) { $depth++; }
2736:
2737: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
2738: my $parts = $curRes->parts();
1.72 ng 2739: $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
1.71 ng 2740: my $title = $curRes->compTitle();
2741: my $symbx = $curRes->symb();
2742: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
2743: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
2744: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
2745:
2746: my %newrecord=();
2747: my @displayPts=();
2748: foreach my $partid (@{$parts}) {
2749: my $newpts = $ENV{'form.GD_BOX'.$question.'_'.$partid};
2750: my $oldpts = $ENV{'form.oldpts'.$question.'_'.$partid};
2751:
2752: my $wgt = $ENV{'form.WGT'.$question.'_'.$partid} != 0 ?
2753: $ENV{'form.WGT'.$question.'_'.$partid} : 1;
2754: my $partial = $newpts/$wgt;
2755: my $score;
2756: if ($partial > 0) {
2757: $score = 'correct_by_override';
2758: } elsif ($partial == 0) {
2759: $score = 'incorrect_by_override';
2760: }
2761: if ($ENV{'form.GD_SEL'.$question.'_'.$partid} eq 'excused') {
2762: $partial = '';
2763: $score = 'excused';
2764: }
2765: my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid};
2766: $displayPts[0].=' <b>Part</b> '.$partid.' = '.
2767: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
2768: ' <br>';
2769: $displayPts[1].=' <b>Part</b> '.$partid.' = '.
2770: ($oldstatus eq 'correct_by_student' ? $oldpts :
2771: (($score eq 'excused') ? 'excused' : $newpts)).
2772: ' <br>';
2773:
2774: $question++;
2775: if (($oldstatus eq 'correct_by_student') ||
2776: ($newpts eq $oldpts && $score eq $oldstatus))
2777: {
2778: next;
2779: }
2780: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
2781: $newrecord{'resource.'.$partid.'.solved'} = $score;
1.72 ng 2782: $newrecord{'resource.'.$partid.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.71 ng 2783:
2784: $changeflag++;
2785: }
2786: if (scalar(keys(%newrecord)) > 0) {
2787: &Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'},
2788: $udom,$uname);
2789: }
2790: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
2791: '<td valign="top">'.$displayPts[1].'</td>'.
2792: '</tr>';
1.68 ng 2793:
2794: }
1.71 ng 2795: $curRes = $iterator->next();
2796: $ctr++;
1.68 ng 2797: }
2798:
1.71 ng 2799: $studentTable.='</td></tr></table></td></tr></table>';
2800: $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
1.76 ng 2801: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
2802: 'The scores were changed for '.
2803: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
2804: $request->print($grademsg.$studentTable);
1.68 ng 2805:
1.70 ng 2806: return '';
2807: }
2808:
1.72 ng 2809: #-------- end of section for handling grading by page/sequence ---------
2810: #
2811: #-------------------------------------------------------------------
2812:
1.75 albertel 2813: #--------------------Scantron Grading-----------------------------------
2814: #
2815: #------ start of section for handling grading by page/sequence ---------
2816:
1.81 albertel 2817: sub defaultFormData {
2818: my ($symb,$url)=@_;
2819: return '
2820: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2821: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2822: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
2823: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
2824: }
2825:
1.75 albertel 2826: sub getSequenceDropDown {
2827: my ($request,$symb)=@_;
2828: my $result='<select name="selectpage">'."\n";
2829: my ($titles,$symbx) = &getSymbMap($request);
2830: my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
2831: my $ctr=0;
2832: foreach (@$titles) {
2833: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
2834: $result.='<option value="'.$$symbx{$_}.'" '.
2835: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
2836: '>'.$showtitle.'</option>'."\n";
2837: $ctr++;
2838: }
2839: $result.= '</select>';
2840: return $result;
2841: }
2842:
1.81 albertel 2843: sub scantron_uploads {
2844: if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
2845: my $result= '<select name="scantron_selectfile">';
2846: opendir(DIR,$Apache::lonnet::perlvar{'lonScansDir'});
2847: my @files=sort(readdir(DIR));
2848: foreach my $filename (@files) {
2849: if ($filename eq '.' or $filename eq '..') { next; }
2850: $result.="<option>$filename</option>\n";
2851: }
2852: closedir(DIR);
2853: $result.="</select>";
2854: return $result;
2855: }
2856:
1.82 albertel 2857: sub scantron_scantab {
2858: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
2859: my $result='<select name="scantron_format">'."\n";
2860: foreach my $line (<$fh>) {
2861: my ($name,$descrip)=split(/:/,$line);
2862: if ($name =~ /^\#/) { next; }
2863: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
2864: }
2865: $result.='</select>'."\n";
2866:
2867: return $result;
2868: }
2869:
1.75 albertel 2870: sub scantron_selectphase {
2871: my ($r) = @_;
2872: my ($symb,$url)=&get_symb_and_url($r);
2873: if (!$symb) {return '';}
2874: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.81 albertel 2875: my $default_form_data=&defaultFormData($symb,$url);
2876: my $grading_menu_button=&show_grading_menu_form($symb,$url);
2877: my $file_selector=&scantron_uploads();
1.82 albertel 2878: my $format_selector=&scantron_scantab();
1.75 albertel 2879: my $result;
2880: $result.= <<SCANTRONFORM;
1.82 albertel 2881: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
2882: <input type="hidden" name="command" value="scantron_process" />
1.81 albertel 2883: $default_form_data
1.75 albertel 2884: <table width="100%" border="0">
2885: <tr>
2886: <td bgcolor="#777777">
2887: <table width="100%" border="0">
2888: <tr bgcolor="#e6ffff">
2889: <td>
2890: <b>Specify file location and which Folder/Sequence to grade</b>
2891: </td>
2892: </tr>
2893: <tr bgcolor="#ffffe6">
2894: <td>
2895: Sequence to grade: $sequence_selector
2896: </td>
2897: </tr>
2898: <tr bgcolor="#ffffe6">
2899: <td>
1.81 albertel 2900: Filename of scoring office file: $file_selector
1.75 albertel 2901: </td>
2902: </tr>
1.82 albertel 2903: <tr bgcolor="#ffffe6">
2904: <td>
2905: Format of data file: $format_selector
2906: </td>
2907: </tr>
1.75 albertel 2908: </table>
2909: </td>
2910: </tr>
2911: </table>
2912: <input type="submit" value="Submit" />
2913: </form>
1.81 albertel 2914: $grading_menu_button
1.75 albertel 2915: SCANTRONFORM
2916:
2917: return $result;
2918: }
2919:
1.82 albertel 2920: sub get_scantron_config {
2921: my ($which) = @_;
2922: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
2923: my %config;
2924: foreach my $line (<$fh>) {
2925: my ($name,$descrip)=split(/:/,$line);
2926: if ($name ne $which ) { next; }
2927: chomp($line);
2928: my @config=split(/:/,$line);
2929: $config{'name'}=$config[0];
2930: $config{'description'}=$config[1];
2931: $config{'CODElocation'}=$config[2];
2932: $config{'CODEstart'}=$config[3];
2933: $config{'CODElength'}=$config[4];
2934: $config{'IDstart'}=$config[5];
2935: $config{'IDlength'}=$config[6];
2936: $config{'Qstart'}=$config[7];
2937: $config{'Qlength'}=$config[8];
2938: $config{'Qoff'}=$config[9];
2939: $config{'Qon'}=$config[10];
2940: last;
2941: }
2942: return %config;
2943: }
2944:
2945: sub username_to_idmap {
2946: my ($classlist)= @_;
2947: my %idmap;
2948: foreach my $student (keys(%$classlist)) {
2949: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
2950: $student;
2951: }
2952: return %idmap;
2953: }
2954:
2955: sub scantron_parse_scanline {
2956: my ($line,$scantron_config)=@_;
2957: my %record;
2958: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
2959: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
2960: if ($$scantron_config{'CODElocation'} ne 0) {
2961: if ($$scantron_config{'CODElocation'} < 0) {
1.83 albertel 2962: $record{'scantron.CODE'}=substr($data,$$scantron_config{'CODEstart'}-1,
2963: $$scantron_config{'CODElength'});
1.82 albertel 2964: } else {
2965: #FIXME interpret first N questions
2966: }
2967: }
1.83 albertel 2968: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
2969: $$scantron_config{'IDlength'});
1.82 albertel 2970: my @alphabet=('A'..'Z');
2971: my $questnum=0;
2972: while ($questions) {
2973: $questnum++;
2974: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
2975: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 2976: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.82 albertel 2977: my (@array)=split(/$$scantron_config{'Qon'}/,$currentquest);
2978: if (scalar(@array) gt 2) {
2979: #FIXME do something intelligent with double bubbles
1.83 albertel 2980: Apache->request->print("<br ><b>Wha!!!</b> <pre>".scalar(@array).
2981: '-'.$currentquest.'-'.$questnum.'</pre><br />');
1.82 albertel 2982: }
2983: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
1.83 albertel 2984: $record{"scantron.$questnum.answer"}='';
1.82 albertel 2985: } else {
1.83 albertel 2986: $record{"scantron.$questnum.answer"}=$alphabet[length($array[0])];
1.82 albertel 2987: }
2988: }
1.83 albertel 2989: $record{'scantron.maxquest'}=$questnum;
2990: return \%record;
1.82 albertel 2991: }
2992:
2993: sub scantron_add_delay {
2994: }
2995:
2996: sub scantron_find_student {
1.83 albertel 2997: my ($scantron_record,$idmap)=@_;
2998: my $scanID=$$scantron_record{'scantron.ID'};
2999: foreach my $id (keys(%$idmap)) {
3000: Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
3001: if (lc($id) eq lc($scanID)) { Apache->request->print('success');return $$idmap{$id}; }
3002: }
3003: return undef;
3004: }
3005:
3006: sub scantron_filter {
3007: my ($curres)=@_;
3008: if (ref($curres) && $curres->is_problem() && !$curres->randomout) {
3009: return 1;
3010: }
3011: return 0;
1.82 albertel 3012: }
3013:
3014: sub scantron_process_students {
1.75 albertel 3015: my ($r) = @_;
1.81 albertel 3016: my (undef,undef,$sequence)=split(/___/,$ENV{'form.selectpage'});
3017: my ($symb,$url)=&get_symb_and_url($r);
3018: if (!$symb) {return '';}
3019: my $default_form_data=&defaultFormData($symb,$url);
1.82 albertel 3020:
3021: my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'});
3022: my $scanlines=Apache::File->new($Apache::lonnet::perlvar{'lonScansDir'}."/$ENV{'form.scantron_selectfile'}");
1.85 albertel 3023: my @scanlines=<$scanlines>;
1.82 albertel 3024: my $classlist=&Apache::loncoursedata::get_classlist();
3025: my %idmap=&username_to_idmap($classlist);
1.83 albertel 3026: my $navmap=Apache::lonnavmaps::navmap->new($ENV{'request.course.fn'}.'.db',$ENV{'request.course.fn'}.'_parms.db',1, 1);
3027: my $map=$navmap->getResourceByUrl($sequence);
3028: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
3029: $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 3030: my $result= <<SCANTRONFORM;
1.81 albertel 3031: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
3032: <input type="hidden" name="command" value="scantron_configphase" />
3033: $default_form_data
3034: SCANTRONFORM
1.82 albertel 3035: $r->print($result);
3036:
3037: my @delayqueue;
1.85 albertel 3038: my $totalcorrect;
3039: my $totalincorrect;
3040:
3041: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
3042: 'Scantron Status','Scantron Progress',scalar(@scanlines));
3043: foreach my $line (@scanlines) {
3044: my $studentcorrect;
3045: my $studentincorrect;
1.75 albertel 3046:
1.83 albertel 3047: chomp($line);
1.82 albertel 3048: my $scan_record=&scantron_parse_scanline($line,\%scantron_config);
3049: my ($uname,$udom);
3050: if ($uname=&scantron_find_student($scan_record,\%idmap)) {
3051: &scantron_add_delay(\@delayqueue,$line,
3052: 'Unable to find a student that matches');
3053: }
1.83 albertel 3054: $r->print('<pre>doing studnet'.$uname.'</pre>');
1.82 albertel 3055: ($uname,$udom)=split(/:/,$uname);
1.85 albertel 3056: &Apache::lonnet::delenv('form.counter');
1.83 albertel 3057: &Apache::lonnet::appenv(%$scan_record);
1.85 albertel 3058: # &Apache::lonhomework::showhash(%ENV);
1.83 albertel 3059: $Apache::lonxml::debug=1;
1.85 albertel 3060: &Apache::lonxml::debug("line is $line");
1.83 albertel 3061:
1.85 albertel 3062: my $i=0;
1.83 albertel 3063: foreach my $resource (@resources) {
1.85 albertel 3064: $i++;
1.83 albertel 3065: my $result=&Apache::lonnet::ssi($resource->src(),
3066: ('submitted' =>'scantron',
3067: 'grade_target' =>'grade',
3068: 'grade_username'=>$uname,
3069: 'grade_domain' =>$udom,
3070: 'grade_courseid'=>$ENV{'request.course.id'},
3071: 'grade_symb' =>$resource->symb()));
1.85 albertel 3072: my %score=&Apache::lonnet::restore($resource->symb(),
3073: $ENV{'request.course.id'},
3074: $udom,$uname);
3075: foreach my $part ($resource->{PARTS}) {
3076: if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
3077: $studentcorrect++;
3078: $totalcorrect++;
3079: } else {
3080: $studentincorrect++;
3081: $totalincorrect++;
3082: }
3083: }
1.83 albertel 3084: $r->print('<pre>'.
3085: $resource->symb().'-'.
3086: $resource->src().'-'.'</pre>result is'.$result);
1.85 albertel 3087: &Apache::lonhomework::showhash(%score);
3088: # if ($i eq 3) {last;}
1.83 albertel 3089: }
1.85 albertel 3090: &Apache::lonnet::delenv('form.counter');
1.83 albertel 3091: &Apache::lonnet::delenv('scantron\.');
1.85 albertel 3092: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
3093: 'last student Who got a '.$studentcorrect.' correct and '.
3094: $studentincorrect.' incorrect. The class has gotten '.
3095: $totalcorrect.' correct and '.$totalincorrect.' incorrect');
1.83 albertel 3096: last;
1.82 albertel 3097: #FIXME
3098: #get iterator for $sequence
3099: #foreach question 'submit' the students answer to the server
3100: # through grade target {
3101: # generate data to pass back that includes grade recevied
3102: #}
3103: }
1.85 albertel 3104: $Apache::lonxml::debug=0;
1.82 albertel 3105: foreach my $delay (@delayqueue) {
3106: #FIXME
3107: #print out each delayed student with interface to select how
3108: # to repair student provided info
3109: #Expected errors include
3110: # 1 bad/no stuid/username
3111: # 2 invalid bubblings
3112:
3113: }
1.75 albertel 3114: #FIXME
3115: # if delay queue exists 2 submits one to process delayed students one
3116: # to ignore delayed students, possibly saving the delay queue for later
1.85 albertel 3117:
3118: $navmap->untieHashes();
1.75 albertel 3119: }
3120: #-------- end of section for handling grading scantron forms -------
3121: #
3122: #-------------------------------------------------------------------
3123:
3124:
1.72 ng 3125: #-------------------------- Menu interface -------------------------
3126: #
3127: #--- Show a Grading Menu button - Calls the next routine ---
3128: sub show_grading_menu_form {
3129: my ($symb,$url)=@_;
3130: my $result.='<form action="/adm/grades" method="post">'."\n".
3131: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3132: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.77 ng 3133: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 3134: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
3135: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
3136: '</form>'."\n";
3137: return $result;
3138: }
3139:
1.77 ng 3140: # -- Retrieve choices for grading form
3141: sub savedState {
3142: my %savedState = ();
3143: if ($ENV{'form.saveState'}) {
3144: foreach (split(/:/,$ENV{'form.saveState'})) {
3145: my ($key,$value) = split(/=/,$_,2);
3146: $savedState{$key} = $value;
3147: }
3148: }
3149: return \%savedState;
3150: }
1.76 ng 3151:
1.72 ng 3152: #--- Displays the main menu page -------
3153: sub gradingmenu {
3154: my ($request) = @_;
3155: my ($symb,$url)=&get_symb_and_url($request);
3156: if (!$symb) {return '';}
1.76 ng 3157: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 3158:
3159: $request->print(<<GRADINGMENUJS);
3160: <script type="text/javascript" language="javascript">
3161: function checkChoice(formname) {
3162: var cmd = formname.command;
1.77 ng 3163: formname.saveState.value = "saveCmd="+radioSelection(cmd)+":saveSec="+pullDownSelection(formname.section)+
3164: ":saveSub="+radioSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.status);
1.86 ! ng 3165: if (cmd[0].checked || cmd[1].checked || cmd[2].checked || cmd[3].checked || cmd[4].checked) formname.submit();
1.75 albertel 3166: if (cmd[5].checked) {
1.72 ng 3167: if (!checkReceiptNo(formname,'notOK')) { return false;}
3168: formname.submit();
3169: }
3170: }
3171:
3172: function checkReceiptNo(formname,nospace) {
3173: var receiptNo = formname.receipt.value;
3174: var checkOpt = false;
3175: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
3176: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
3177: if (checkOpt) {
3178: alert("Please enter a receipt number given by a student in the receipt box.");
3179: formname.receipt.value = "";
3180: formname.receipt.focus();
3181: return false;
3182: }
1.76 ng 3183: formname.command[5].checked = true;
1.72 ng 3184: return true;
3185: }
3186:
3187: function radioSelection(radioButton) {
3188: var selection=null;
1.76 ng 3189: if (radioButton.length > 1) {
3190: for (var i=0; i<radioButton.length; i++) {
3191: if (radioButton[i].checked) {
3192: return radioButton[i].value;
3193: }
1.72 ng 3194: }
1.76 ng 3195: } else {
3196: if (radioButton.checked) return radioButton.value;
1.72 ng 3197: }
3198: return selection;
3199: }
1.68 ng 3200:
1.72 ng 3201: function pullDownSelection(selectOne) {
3202: var selection="";
1.76 ng 3203: if (selectOne.length > 1) {
3204: for (var i=0; i<selectOne.length; i++) {
3205: if (selectOne[i].selected) {
3206: return selectOne[i].value;
3207: }
1.72 ng 3208: }
1.76 ng 3209: } else {
3210: if (selectOne.selected) return selectOne.value;
1.72 ng 3211: }
3212: }
1.76 ng 3213:
1.72 ng 3214: </script>
3215: GRADINGMENUJS
3216:
3217: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>'.
3218: '<table border="0">'.
1.76 ng 3219: '<tr><td colspan=3><font size=+1><b>Problem: </b>'.$probTitle.'</font></td></tr>'."\n";
1.72 ng 3220: my ($partlist,$handgrade) = &response_type($url);
3221: my ($resptype,$hdgrade)=('','no');
3222: for (sort keys(%$handgrade)) {
3223: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
3224: $resptype = $responsetype;
3225: $hdgrade = $handgrade if ($handgrade eq 'yes');
3226: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
3227: '<td><b>Type: </b>'.$responsetype.'</td>'.
3228: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
3229: }
1.76 ng 3230: $result.='</table>'."\n";
1.72 ng 3231:
1.76 ng 3232: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 3233: my $savedState = &savedState();
3234: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'pickStudentPage' : $$savedState{'saveCmd'});
3235: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
3236: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'yes' : $$savedState{'saveSub'});
3237: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 3238:
3239: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
3240: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3241: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3242: '<input type="hidden" name="response" value="'.$resptype.'" />'."\n".
3243: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
3244: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.77 ng 3245: '<input type="hidden" name="saveState" value="" />'."\n".
1.72 ng 3246: '<input type="hidden" name="showgrading" value="yes" />'."\n";
3247:
3248: $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n".
3249: '<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n".
3250: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
3251: '<tr bgcolor=#ffffe6><td>'."\n";
3252:
3253: $result.='<table width=100% border=0>'.
3254: '<tr bgcolor="#ffffe6" valign="top"><td colspan="2">'.
3255: '<input type="radio" name="command" value="pickStudentPage" '.
1.76 ng 3256: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
1.72 ng 3257: 'Handgrade/View Submission for a student by page/sequence</td></tr>'."\n".
3258:
3259: '<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
3260: '<input type="radio" name="command" value="viewgrades" '.
1.76 ng 3261: ($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
1.72 ng 3262: 'Grade by section or class</td></tr>'."\n".
3263:
3264: '<tr bgcolor="#ffffe6"valign="top"><td><input type="radio" name="command" value="submission" '.
1.76 ng 3265: ($saveCmd eq 'submission' ? 'checked' : '').'> '.
1.72 ng 3266: ($hdgrade eq 'yes' ? 'View/Grade essay response of' : 'View').
3267: ' an individual student </td>'."\n".
3268: '<td>--> For students who has: '.
1.76 ng 3269: '<input type="radio" name="submitonly" value="yes" '.
3270: ($saveSub eq 'yes' ? 'checked' : '').' /> submitted'.
3271: '<input type="radio" name="submitonly" value="all" '.
3272: ($saveSub eq 'all' ? 'checked' : '').' /> everybody</td></tr>'."\n".
1.46 ng 3273:
1.72 ng 3274: '<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.86 ! ng 3275: '<input type="radio" name="command" value="csvform" '.
! 3276: ($saveCmd eq 'csvform' ? 'checked' : '').'> '.
1.72 ng 3277: 'Upload scores from file</td></tr>'."\n";
3278:
1.75 albertel 3279: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.81 albertel 3280: '<input type="radio" name="command" value="scantron_selectphase" '.
3281: ($saveCmd eq 'scantron_selectphase' ? 'checked="on"' : '').' /> '.
1.75 albertel 3282: 'Grade scantron forms</td></tr>'."\n";
3283:
1.72 ng 3284: if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)) {
3285: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.76 ng 3286: '<input type="radio" name="command" value="verify" onChecked="javascript:this.form.receipt.focus()" '.
3287: ($saveCmd eq 'verify' ? 'checked' : '').'> '.
1.72 ng 3288: 'Verify a submission receipt issued by this server</td>'.
3289: '<td>--> Receipt no: '.unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).
3290: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
3291: '</td></tr>'."\n";
3292: }
1.44 ng 3293:
1.72 ng 3294: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2"><br />'."\n".
1.76 ng 3295: ' Select section: <select name="section">'."\n";
1.72 ng 3296: if (ref($sections)) {
3297: foreach (sort (@$sections)) {$result.='<option value="'.$_.'" '.
1.76 ng 3298: ($saveSec eq $_ ? 'selected="on"' : '').'>'.$_.'</option>'."\n";}
1.44 ng 3299: }
1.76 ng 3300: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</select> ';
3301:
3302: $result.='Student Status:</b><select name="status">'.
3303: '<option value="Active" '.($saveStatus eq 'Active' ? 'selected' : '').'>Active</option>'.
3304: '<option value="Expired" '.($saveStatus eq 'Expired' ? 'selected' : '').'>Expired</option>'.
3305: '<option value="Any" '.($saveStatus eq 'Any' ? 'selected' : '').'>Any</option>'.
3306: '</select>';
3307:
3308: $result.=' <font color="red">(Applies to the first three options only.)</font>'."\n";
3309:
1.72 ng 3310: if (ref($sections)) {
3311: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
3312: if (grep /no/,@$sections);
1.44 ng 3313: }
1.72 ng 3314: $result.='</td></tr>';
3315:
3316: $result.='<tr bgcolor="#ffffe6"><td colspan="2"><br />'.
3317: '<input type="button" onClick="javascript:checkChoice(this.form);" value="View/Grade" />'."\n".
3318: '</form></td></tr></table>'."\n".
3319: '</td></tr></table>'."\n".
3320: '</td></tr></table>'."\n";
1.44 ng 3321: return $result;
1.2 albertel 3322: }
3323:
1.1 albertel 3324: sub handler {
1.41 ng 3325: my $request=$_[0];
3326:
3327: if ($ENV{'browser.mathml'}) {
3328: $request->content_type('text/xml');
3329: } else {
3330: $request->content_type('text/html');
3331: }
3332: $request->send_http_header;
1.44 ng 3333: return '' if $request->header_only;
1.41 ng 3334: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
3335: my $url=$ENV{'form.url'};
3336: my $symb=$ENV{'form.symb'};
3337: my $command=$ENV{'form.command'};
3338: if (!$url) {
3339: my ($temp1,$temp2);
3340: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
3341: $url = $ENV{'form.url'};
3342: }
3343: &send_header($request);
3344: if ($url eq '' && $symb eq '') {
3345: if ($ENV{'user.adv'}) {
3346: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
3347: ($ENV{'form.codethree'})) {
3348: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
3349: $ENV{'form.codethree'};
3350: my ($tsymb,$tuname,$tudom,$tcrsid)=
3351: &Apache::lonnet::checkin($token);
3352: if ($tsymb) {
3353: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
3354: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
3355: $request->print(
3356: &Apache::lonnet::ssi('/res/'.$url,
3357: ('grade_username' => $tuname,
3358: 'grade_domain' => $tudom,
3359: 'grade_courseid' => $tcrsid,
3360: 'grade_symb' => $tsymb)));
3361: } else {
1.45 ng 3362: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.41 ng 3363: }
3364: } else {
1.45 ng 3365: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 3366: }
1.14 www 3367: } else {
1.41 ng 3368: $request->print(&Apache::lonxml::tokeninputfield());
3369: }
3370: }
3371: } else {
3372: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
3373: if ($command eq 'submission') {
1.68 ng 3374: ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
3375: } elsif ($command eq 'pickStudentPage') {
3376: &pickStudentPage($request);
3377: } elsif ($command eq 'displayPage') {
3378: &displayPage($request);
1.71 ng 3379: } elsif ($command eq 'gradeByPage') {
3380: &updateGradeByPage($request);
1.41 ng 3381: } elsif ($command eq 'processGroup') {
3382: &processGroup($request);
3383: } elsif ($command eq 'gradingmenu') {
3384: $request->print(&gradingmenu($request));
3385: } elsif ($command eq 'viewgrades') {
3386: $request->print(&viewgrades($request));
3387: } elsif ($command eq 'handgrade') {
3388: $request->print(&processHandGrade($request));
3389: } elsif ($command eq 'editgrades') {
3390: $request->print(&editgrades($request));
3391: } elsif ($command eq 'verify') {
3392: $request->print(&verifyreceipt($request));
1.72 ng 3393: } elsif ($command eq 'csvform') {
3394: $request->print(&upcsvScores_form($request));
1.41 ng 3395: } elsif ($command eq 'csvupload') {
3396: $request->print(&csvupload($request));
3397: } elsif ($command eq 'viewclasslist') {
3398: $request->print(&viewclasslist($request));
3399: } elsif ($command eq 'csvuploadmap') {
3400: $request->print(&csvuploadmap($request));
3401: } elsif ($command eq 'csvuploadassign') {
3402: if ($ENV{'form.associate'} ne 'Reverse Association') {
3403: $request->print(&csvuploadassign($request));
3404: } else {
3405: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
3406: $ENV{'form.upfile_associate'} = 'reverse';
3407: } else {
3408: $ENV{'form.upfile_associate'} = 'forward';
3409: }
3410: $request->print(&csvuploadmap($request));
3411: }
1.75 albertel 3412: } elsif ($command eq 'scantron_selectphase') {
3413: $request->print(&scantron_selectphase($request));
1.82 albertel 3414: } elsif ($command eq 'scantron_process') {
3415: $request->print(&scantron_process_students($request));
1.26 albertel 3416: } else {
1.41 ng 3417: $request->print("Unknown action: $command:");
1.26 albertel 3418: }
1.2 albertel 3419: }
1.41 ng 3420: &send_footer($request);
1.44 ng 3421: return '';
3422: }
3423:
3424: sub send_header {
3425: my ($request)= @_;
3426: $request->print(&Apache::lontexconvert::header());
3427: # $request->print("
3428: #<script>
3429: #remotewindow=open('','homeworkremote');
3430: #remotewindow.close();
3431: #</script>");
1.47 www 3432: $request->print(&Apache::loncommon::bodytag('Grading'));
1.44 ng 3433: }
3434:
3435: sub send_footer {
3436: my ($request)= @_;
3437: $request->print('</body>');
3438: $request->print(&Apache::lontexconvert::footer());
1.1 albertel 3439: }
3440:
3441: 1;
3442:
1.13 albertel 3443: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>