Annotation of loncom/homework/grades.pm, revision 1.77
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.77 ! ng 4: # $Id: grades.pm,v 1.76 2003/03/24 21:03:54 ng Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.13 albertel 28: # 2/9,2/13 Guy Albertelli
1.8 www 29: # 6/8 Gerd Kortemeyer
1.13 albertel 30: # 7/26 H.K. Ng
1.14 www 31: # 8/20 Gerd Kortemeyer
1.30 ng 32: # Year 2002
1.44 ng 33: # June-August H.K. Ng
1.68 ng 34: # Year 2003
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.58 albertel 346: ' <b>View Problem: </b><input type="radio" name="vProb" value="no" /> no '."\n".
347: '<input type="radio" name="vProb" value="yes" checked /> one student '."\n".
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;
631: $request->print(<<SUBJAVASCRIPT);
632: <script type="text/javascript" language="javascript">
1.45 ng 633:
1.44 ng 634: //===================== Show list of keywords ====================
635: function keywords(keyform) {
1.76 ng 636: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keyform.value);
1.44 ng 637: if (nret==null) return;
638: keyform.value = nret;
639:
640: document.SCORE.refresh.value = "on";
641: if (document.SCORE.keywords.value != "") {
642: document.SCORE.submit();
643: }
644: return;
645: }
646:
647: //===================== Script to view submitted by ==================
648: function viewSubmitter(submitter) {
649: document.SCORE.refresh.value = "on";
650: document.SCORE.NCT.value = "1";
651: document.SCORE.unamedom0.value = submitter;
652: document.SCORE.submit();
653: return;
654: }
655:
656: //===================== Script to add keyword(s) ==================
657: function getSel() {
658: if (document.getSelection) txt = document.getSelection();
659: else if (document.selection) txt = document.selection.createRange().text;
660: else return;
661: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
662: if (cleantxt=="") {
1.46 ng 663: alert("Please select a word or group of words from document and then click this link.");
1.44 ng 664: return;
665: }
666: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
667: if (nret==null) return;
668: var curlist = document.SCORE.keywords.value;
669: document.SCORE.keywords.value = curlist+" "+nret;
670: document.SCORE.refresh.value = "on";
671: if (document.SCORE.keywords.value != "") {
672: document.SCORE.submit();
673: }
674: return;
675: }
676:
677: //====================== Script for composing message ==============
678: function msgCenter(msgform,usrctr,fullname) {
679: var Nmsg = msgform.savemsgN.value;
680: savedMsgHeader(Nmsg,usrctr,fullname);
681: var subject = msgform.msgsub.value;
682: var rtrchk = eval("document.SCORE.includemsg"+usrctr);
683: var msgchk = rtrchk.value;
684: re = /msgsub/;
685: var shwsel = "";
686: if (re.test(msgchk)) { shwsel = "checked" }
687: displaySubject(subject,shwsel);
688: for (var i=1; i<=Nmsg; i++) {
689: var testpt = "savemsg"+i+",";
690: re = /testpt/;
691: shwsel = "";
692: if (re.test(msgchk)) { shwsel = "checked" }
693: var message = eval("document.SCORE.savemsg"+i+".value");
694: displaySavedMsg(i,message,shwsel);
695: }
696: newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
697: shwsel = "";
698: re = /newmsg/;
699: if (re.test(msgchk)) { shwsel = "checked" }
700: newMsg(newmsg,shwsel);
701: msgTail();
702: return;
703: }
704:
1.76 ng 705: // var pWin = null;
1.44 ng 706: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 707: var height = 70*Nmsg+250;
1.44 ng 708: var scrollbar = "no";
709: if (height > 600) {
710: height = 600;
711: scrollbar = "yes";
712: }
1.76 ng 713: // if (window.pWin) window.pWin.close();
1.44 ng 714: pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
1.76 ng 715: pWin.focus();
716: pDoc = pWin.document;
717: pDoc.write("<html><head>");
718: pDoc.write("<title>Message Central</title>");
719:
720: pDoc.write("<script language=javascript>");
721: pDoc.write("function checkInput() {");
722: pDoc.write(" opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
723: pDoc.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
724: pDoc.write(" var usrctr = document.msgcenter.usrctr.value;");
725: pDoc.write(" var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
726: pDoc.write(" newval.value = document.msgcenter.newmsg.value;");
727:
728: pDoc.write(" var msgchk = \\"\\";");
729: pDoc.write(" if (document.msgcenter.subchk.checked) {");
730: pDoc.write(" msgchk = \\"msgsub,\\";");
731: pDoc.write(" }");
732: pDoc.write( "for (var i=1; i<=nmsg; i++) {");
733: pDoc.write(" var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
734: pDoc.write(" var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
735: pDoc.write(" opnmsg.value = frmmsg.value;");
736: pDoc.write(" var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
737: pDoc.write(" if (chkbox.checked) {");
738: pDoc.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
739: pDoc.write(" }");
740: pDoc.write(" }");
741: pDoc.write(" if (document.msgcenter.newmsgchk.checked) {");
742: pDoc.write(" msgchk += \\"newmsg\\"+usrctr;");
743: pDoc.write(" }");
744: pDoc.write(" var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
745: pDoc.write(" includemsg.value = msgchk;");
746:
747: pDoc.write(" self.close()");
748:
749: pDoc.write("}");
750:
751: pDoc.write("<");
752: pDoc.write("/script>");
753:
754: pDoc.write("</head><body bgcolor=white>");
755:
756: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
757: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
758: pDoc.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br><br>");
759:
760: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
761: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
762: pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44 ng 763: }
764: function displaySubject(msg,shwsel) {
1.76 ng 765: pDoc = pWin.document;
766: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
767: pDoc.write("<td>Subject</td>");
768: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
769: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44 ng 770: }
771:
1.72 ng 772: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 773: pDoc = pWin.document;
774: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
775: pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
776: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
777: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44 ng 778: }
779:
780: function newMsg(newmsg,shwsel) {
1.76 ng 781: pDoc = pWin.document;
782: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
783: pDoc.write("<td align=\\"center\\">New</td>");
784: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
785: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44 ng 786: }
787:
788: function msgTail() {
1.76 ng 789: pDoc = pWin.document;
790: pDoc.write("</table>");
791: pDoc.write("</td></tr></table> ");
792: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
793: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
794: pDoc.write("</form>");
795: pDoc.write("</body></html>");
1.44 ng 796: }
797:
798: //====================== Script for keyword highlight options ==============
799: function kwhighlight() {
800: var kwclr = document.SCORE.kwclr.value;
801: var kwsize = document.SCORE.kwsize.value;
802: var kwstyle = document.SCORE.kwstyle.value;
803: var redsel = "";
804: var grnsel = "";
805: var blusel = "";
806: if (kwclr=="red") {var redsel="checked"};
807: if (kwclr=="green") {var grnsel="checked"};
808: if (kwclr=="blue") {var blusel="checked"};
809: var sznsel = "";
810: var sz1sel = "";
811: var sz2sel = "";
812: if (kwsize=="0") {var sznsel="checked"};
813: if (kwsize=="+1") {var sz1sel="checked"};
814: if (kwsize=="+2") {var sz2sel="checked"};
815: var synsel = "";
816: var syisel = "";
817: var sybsel = "";
818: if (kwstyle=="") {var synsel="checked"};
819: if (kwstyle=="<i>") {var syisel="checked"};
820: if (kwstyle=="<b>") {var sybsel="checked"};
821: highlightCentral();
822: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
823: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
824: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
825: highlightend();
826: return;
827: }
828:
1.76 ng 829: // var hwdWin = null;
1.44 ng 830: function highlightCentral() {
1.76 ng 831: // if (window.hwdWin) window.hwdWin.close();
1.44 ng 832: hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
1.76 ng 833: hwdWin.focus();
834: var hDoc = hwdWin.document;
835: hDoc.write("<html><head>");
836: hDoc.write("<title>Highlight Central</title>");
837:
838: hDoc.write("<script language=javascript>");
839: hDoc.write("function updateChoice(flag) {");
840: hDoc.write(" opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
841: hDoc.write(" opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
842: hDoc.write(" opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
843: hDoc.write(" opener.document.SCORE.refresh.value = \\"on\\";");
844: hDoc.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){");
845: hDoc.write(" opener.document.SCORE.submit();");
846: hDoc.write(" }");
847: hDoc.write(" self.close()");
848: hDoc.write("}");
849:
850: hDoc.write("function radioSelection(radioButton) {");
851: hDoc.write(" var selection=null;");
852: hDoc.write(" for (var i=0; i<radioButton.length; i++) {");
853: hDoc.write(" if (radioButton[i].checked) {");
854: hDoc.write(" selection=radioButton[i].value;");
855: hDoc.write(" return selection;");
856: hDoc.write(" }");
857: hDoc.write(" }");
858: hDoc.write("}");
859:
860: hDoc.write("<");
861: hDoc.write("/script>");
862:
863: hDoc.write("</head><body bgcolor=white>");
864:
865: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
866: hDoc.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br><br>");
867:
868: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
869: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
870: hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44 ng 871: }
872:
873: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 874: var hDoc = hwdWin.document;
875: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
876: hDoc.write("<td align=\\"left\\">");
877: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
878: hDoc.write("<td align=\\"left\\">");
879: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
880: hDoc.write("<td align=\\"left\\">");
881: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
882: hDoc.write("</tr>");
1.44 ng 883: }
884:
885: function highlightend() {
1.76 ng 886: var hDoc = hwdWin.document;
887: hDoc.write("</table>");
888: hDoc.write("</td></tr></table> ");
889: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
890: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
891: hDoc.write("</form>");
892: hDoc.write("</body></html>");
1.44 ng 893: }
894:
895: </script>
896: SUBJAVASCRIPT
897: }
898:
1.71 ng 899: #--- displays the grading box, used in essay type problem and grading by page/sequence
900: sub gradeBox {
901: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
902:
903: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
904: '/check.gif" height="16" border="0" />';
905:
906: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
907: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
908: '<font color="red">problem weight assigned by computer</font>');
909: $wgt = ($wgt > 0 ? $wgt : '1');
910: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
911: '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
912: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
913:
914: $result.='<table border="0"><tr><td>'.
915: '<b>Part </b>'.$partid.' <b>Points: </b></td><td>'."\n";
916:
917: my $ctr = 0;
918: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
919: while ($ctr<=$wgt) {
920: $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
921: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.72 ng 922: $ctr.')" value="'.$ctr.'" '.
1.71 ng 923: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
924: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
925: $ctr++;
926: }
927: $result.='</tr></table>';
928:
929: $result.='</td><td> <b>or</b> </td>'."\n";
930: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
931: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
932: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
933: $wgt.')" /></td>'."\n";
934: $result.='<td>/'.$wgt.' '.$wgtmsg.
935: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
936: ' </td><td>'."\n";
937:
938: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
939: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
940: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
941: $result.='<option> </option>'.
942: '<option selected="on">excused</option></select>'."\n";
943: } else {
944: $result.='<option selected="on"> </option>'.
945: '<option>excused</option></select>'."\n";
946: }
947: $result.="  \n";
948: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
949: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
950: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
951: $$record{'resource.'.$partid.'.solved'}.'" />'."\n";
952: $result.='</td></tr></table>'."\n";
953: return $result;
954: }
1.44 ng 955:
1.58 albertel 956: sub show_problem {
1.71 ng 957: my ($request,$symb,$uname,$udom,$removeform,$viewon) = @_;
1.58 albertel 958: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
959: $ENV{'request.course.id'});
960: if ($removeform) {
961: $rendered=~s|<form(.*?)>||g;
962: $rendered=~s|</form>||g;
963: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
964: }
965: my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
966: $ENV{'request.course.id'});
967: if ($removeform) {
968: $companswer=~s|<form(.*?)>||g;
969: $companswer=~s|</form>||g;
970: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
971: }
972: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 973: $result.='<table border="0" width="100%">';
974: $result.='<tr><td bgcolor="#e6ffff"><b> View of the problem - '.$ENV{'form.fullname'}.
975: '</b></td></tr>' if ($viewon);
976: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1.58 albertel 977: $result.='<b>Correct answer:</b><br />'.$companswer;
978: $result.='</td></tr></table>';
979: $result.='</td></tr></table><br />';
1.71 ng 980: return $result;
1.58 albertel 981: }
982:
1.44 ng 983: # --------------------------- show submissions of a student, option to grade
984: sub submission {
985: my ($request,$counter,$total) = @_;
986:
987: (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
988: my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
989: ($uname,$udom) = &finduser($uname) if $udom eq '';
990: $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
1.41 ng 991:
992: my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
993: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
994: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
995:
996: # header info
997: if ($counter == 0) {
998: &sub_page_js($request);
1.71 ng 999: &sub_page_kw_js($request);
1.76 ng 1000: $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
1001: &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
1002:
1.45 ng 1003: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.72 ng 1004: '<font size=+1> <b>Problem: </b>'.$ENV{'form.probTitle'}.'</font>'."\n");
1.41 ng 1005:
1.44 ng 1006: # option to display problem, only once else it cause problems
1007: # with the form later since the problem has a form.
1.66 albertel 1008: if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) {
1.71 ng 1009: $request->print(&show_problem($request,$symb,$uname,$udom,0,1));
1.41 ng 1010: }
1011:
1.44 ng 1012: # kwclr is the only variable that is guaranteed to be non blank
1013: # if this subroutine has been called once.
1.41 ng 1014: my %keyhash = ();
1015: if ($ENV{'form.kwclr'} eq '') {
1016: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1017: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1018: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1019:
1020: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1021: $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1022: $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1023: $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1024: $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1025: $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.72 ng 1026: $keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
1.41 ng 1027: $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.38 ng 1028:
1.41 ng 1029: }
1.44 ng 1030:
1.41 ng 1031: $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
1032: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.77 ! ng 1033: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 1034: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.41 ng 1035: '<input type="hidden" name="refresh" value="off" />'."\n".
1036: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1037: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1038: '<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
1039: '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
1040: '<input type="hidden" name="lastSub" value="'.$ENV{'form.lastSub'}.'" />'."\n".
1041: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'">'."\n".
1042: '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
1043: '<input type="hidden" name="response" value="'.$ENV{'form.response'}.'">'."\n".
1044: '<input type="hidden" name="handgrade" value="'.$ENV{'form.handgrade'}.'">'."\n".
1045: '<input type="hidden" name="keywords" value="'.$ENV{'form.keywords'}.'" />'."\n".
1046: '<input type="hidden" name="kwclr" value="'.$ENV{'form.kwclr'}.'" />'."\n".
1047: '<input type="hidden" name="kwsize" value="'.$ENV{'form.kwsize'}.'" />'."\n".
1048: '<input type="hidden" name="kwstyle" value="'.$ENV{'form.kwstyle'}.'" />'."\n".
1049: '<input type="hidden" name="msgsub" value="'.$ENV{'form.msgsub'}.'" />'."\n".
1050: '<input type="hidden" name="savemsgN" value="'.$ENV{'form.savemsgN'}.'" />'."\n".
1051: '<input type="hidden" name="NCT"'.
1052: ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
1053:
1054: my ($cts,$prnmsg) = (1,'');
1055: while ($cts <= $ENV{'form.savemsgN'}) {
1056: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1057: ($keyhash{$symb.'_savemsg'.$cts} eq '' ? $ENV{'form.savemsg'.$cts} : $keyhash{$symb.'_savemsg'.$cts}).
1058: '" />'."\n";
1059: $cts++;
1060: }
1061: $request->print($prnmsg);
1.32 ng 1062:
1.41 ng 1063: if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
1064: $request->print(<<KEYWORDS);
1.38 ng 1065: <b>Keyword Options:</b>
1066: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>
1067: <a href="#" onMouseDown="javascript:getSel(); return false"
1068: CLASS="page">Paste Selection to List</a>
1069: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1070: KEYWORDS
1.41 ng 1071: }
1072: }
1.44 ng 1073:
1.58 albertel 1074: if ($ENV{'form.vProb'} eq 'all') {
1.71 ng 1075: $request->print('<br /><br /><br />') if ($counter > 0);
1076: $request->print(&show_problem($request,$symb,$uname,$udom,1,1));
1.58 albertel 1077: }
1078:
1.41 ng 1079: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
1080: my ($partlist,$handgrade) = &response_type($url);
1081:
1.44 ng 1082: # Display student info
1.41 ng 1083: $request->print(($counter == 0 ? '' : '<br />'));
1.45 ng 1084: my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
1085: '<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1086:
1087: $result.='<b>Fullname: </b>'.$ENV{'form.fullname'}.
1088: '<font color="#999999"> Username: '.$uname.'</font>'.
1.45 ng 1089: '<font color="#999999"> Domain: '.$udom.'</font><br />'."\n";
1090: $result.='<input type="hidden" name="name'.$counter.
1091: '" value="'.$ENV{'form.fullname'}.'" />'."\n";
1.41 ng 1092:
1.44 ng 1093: # If this is handgraded, then check for collaborators
1.45 ng 1094: my @col_fullnames;
1.56 matthew 1095: my ($classlist,$fullname);
1.41 ng 1096: if ($ENV{'form.handgrade'} eq 'yes') {
1097: my @col_list;
1.76 ng 1098: ($classlist,undef,$fullname) = &getclasslist('all',$ENV{'form.showgrading'} eq 'yes' ? '1' : '0');
1.41 ng 1099: for (keys (%$handgrade)) {
1.44 ng 1100: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1101: '.maxcollaborators',
1102: $symb,$udom,$uname);
1103: next if ($ncol <= 0);
1104: s/\_/\./g;
1105: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1106: my (@collaborators) = split(/,?\s+/,
1107: $record{'resource.'.$_.'.collaborators'});
1108: my (@badcollaborators);
1109: if (scalar(@collaborators) != 0) {
1110: $result.='<b>Collaborators: </b>';
1111: foreach my $collaborator (@collaborators) {
1112: my ($co_name,$co_dom) = split /\@|:/,$collaborator;
1113: $co_dom = $udom if (! defined($co_dom));
1114: next if ($co_name eq $uname && $co_dom eq $udom);
1115: # Doing this grep allows 'fuzzy' specification
1116: my @Matches = grep /^$co_name:$co_dom/i,
1117: keys %$classlist;
1118: if (! scalar(@Matches)) {
1119: push @badcollaborators,$collaborator;
1120: next;
1121: }
1122: push @col_list, @Matches;
1123: foreach (@Matches) {
1124: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1125: push @col_fullnames, $givenn.' '.$lastname;
1126: $result.=$$fullname{$_}.' ';
1127: }
1128: }
1129: $result.='<br />'."\n";
1130: if (scalar(@badcollaborators) > 0) {
1131: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1132: $result.='This student has submitted ';
1133: if (scalar(@badcollaborators) == 1) {
1134: $result .= 'an invalid collaborator';
1135: } else {
1136: $result .= 'invalid collaborators';
1137: }
1138: $result .= ': '.join(', ',@badcollaborators);
1.77 ! ng 1139: $result .= '</td></tr></table>';
1.57 matthew 1140: }
1141: if (scalar(@collaborators > $ncol)) {
1142: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1.76 ng 1143: $result .= 'This student has submitted too many '.
1.57 matthew 1144: 'collaborators. Maximum is '.$ncol;
1145: $result .= '</td></tr></table>';
1146: }
1147: $result.='<input type="hidden" name="collaborator'.$counter.
1148: '" value="'.(join ':',@col_list).'" />'."\n";
1149: }
1.41 ng 1150: }
1151: }
1.44 ng 1152: $request->print($result."\n");
1.33 ng 1153:
1.44 ng 1154: # print student answer/submission
1155: # Options are (1) Handgaded submission only
1156: # (2) Last submission, includes submission that is not handgraded
1157: # (for multi-response type part)
1158: # (3) Last submission plus the parts info
1159: # (4) The whole record for this student
1.41 ng 1160: if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1161: if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
1.44 ng 1162: my $submitby=''.
1.41 ng 1163: '<b>Collaborative submission by: </b>'.
1.44 ng 1164: '<a href="javascript:viewSubmitter(\''.
1165: $ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
1.41 ng 1166: '\')"; TARGET=_self>'.
1167: $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
1168: $request->print($submitby);
1169: } else {
1.44 ng 1170: my ($string,$timestamp)=
1.46 ng 1171: &get_last_submission (%record);
1.71 ng 1172: my $lastsubonly=''.
1.44 ng 1173: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1174: $$timestamp).'';
1.41 ng 1175: if ($$timestamp eq '') {
1.45 ng 1176: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0].'</td></tr>'."\n";
1.41 ng 1177: } else {
1178: for my $part (sort keys(%$handgrade)) {
1179: foreach (@$string) {
1180: my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
1181: if ($part eq ($partid.'_'.$respid)) {
1182: my ($ressub,$subval) = split(/:/,$_,2);
1.44 ng 1183: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
1184: $partid.'</b> <font color="#999999">( ID '.$respid.
1.67 www 1185: ' )</font> '.
1186: ($record{"resource.$partid.$respid.uploadedurl"}?
1187: '<a href="'.
1188: &Apache::lonnet::tokenwrapper($record{"resource.$partid.$respid.uploadedurl"}).
1189: '"><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 />':'').
1190: '<b>Answer: </b>'.
1.45 ng 1191: &keywords_highlight($subval).'</td></tr>'."\n"
1.41 ng 1192: if ($ENV{'form.lastSub'} eq 'lastonly' ||
1.44 ng 1193: ($ENV{'form.lastSub'} eq 'hdgrade' &&
1194: $$handgrade{$part} =~ /:yes$/));
1.41 ng 1195: }
1196: }
1197: }
1198: }
1.45 ng 1199: $lastsubonly.='</td></tr>'."\n";
1.41 ng 1200: $request->print($lastsubonly);
1201: }
1202: } else {
1203: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.44 ng 1204: $ENV{'request.course.id'},
1205: $last,'.submission',
1206: 'Apache::grades::keywords_highlight'));
1.41 ng 1207: }
1208:
1.44 ng 1209: # return if view submission with no grading option
1.41 ng 1210: if ($ENV{'form.showgrading'} eq '') {
1.45 ng 1211: $request->print('</td></tr></table></td></tr></table></form>'."\n");
1.72 ng 1212: $request->print(&show_grading_menu_form($symb,$url))
1213: if (($ENV{'form.command'} eq 'submission') ||
1214: ($ENV{'form.command'} eq 'processGroup' && $counter == $total));
1.41 ng 1215: return;
1216: }
1.33 ng 1217:
1.44 ng 1218: # Grading options
1.41 ng 1219: $result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
1220: '<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.45 ng 1221: '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1222: .$udom.'" />'."\n";
1223: my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
1224: my $msgfor = $givenn.' '.$lastname;
1225: if (scalar(@col_fullnames) > 0) {
1226: my $lastone = pop @col_fullnames;
1227: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1228: }
1229: $result.='<tr><td bgcolor="#ffffff">'."\n".
1230: ' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1231: ',\''.$msgfor.'\')"; TARGET=_self>'.
1232: 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').'</a>'.
1.44 ng 1233: '<br /> (Message will be sent when you click on Save & Next below.)'."\n"
1234: if ($ENV{'form.handgrade'} eq 'yes');
1.41 ng 1235: $request->print($result);
1236:
1237: my %seen = ();
1238: my @partlist;
1239: for (sort keys(%$handgrade)) {
1240: my ($partid,$respid) = split(/_/);
1241: next if ($seen{$partid} > 0);
1242: $seen{$partid}++;
1243: next if ($$handgrade{$_} =~ /:no$/);
1244: push @partlist,$partid;
1245:
1.71 ng 1246: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 1247: }
1.45 ng 1248: $result='<input type="hidden" name="partlist'.$counter.
1249: '" value="'.(join ":",@partlist).'" />'."\n";
1250: my $ctr = 0;
1251: while ($ctr < scalar(@partlist)) {
1252: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1253: $partlist[$ctr].'" />'."\n";
1254: $ctr++;
1255: }
1256: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 1257:
1258: # print end of form
1259: if ($counter == $total) {
1.45 ng 1260: my $endform='<table border="0"><tr><td>'.
1261: '<input type="hidden" name="gradeOpt" value="" />'."\n";
1262: if ($ENV{'form.handgrade'} eq 'yes') {
1263: $endform.='<input type="button" value="Save & Next" '.
1.71 ng 1264: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1.45 ng 1265: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
1266: my $ntstu ='<select name="NTSTU">'.
1267: '<option>1</option><option>2</option>'.
1268: '<option>3</option><option>5</option>'.
1269: '<option>7</option><option>10</option></select>'."\n";
1270: my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
1271: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
1272: $endform.=$ntstu.'student(s) ';
1273: } else {
1274: $endform.='<input type="hidden" name="NTSTU" value="1" />'."\n";
1275: }
1276: $endform.='<input type="button" value="Next" '.
1.71 ng 1277: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> '."\n".
1.45 ng 1278: '<input type="button" value="Previous" '.
1.71 ng 1279: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> ';
1.45 ng 1280: $endform.='(Next and Previous do not save the scores.)'."\n"
1281: if ($ENV{'form.handgrade'} eq 'yes');
1282: $endform.='</td><tr></table></form>';
1.50 albertel 1283: $endform.=&show_grading_menu_form($symb,$url);
1.41 ng 1284: $request->print($endform);
1285: }
1286: return '';
1.38 ng 1287: }
1288:
1.44 ng 1289: #--- Retrieve the last submission for all the parts
1.38 ng 1290: sub get_last_submission {
1.46 ng 1291: my (%returnhash)=@_;
1292: my (@string,$timestamp);
1293: if ($returnhash{'version'}) {
1294: my %lasthash=();
1295: my ($version);
1296: for ($version=1;$version<=$returnhash{'version'};$version++) {
1297: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
1298: $lasthash{$_}=$returnhash{$version.':'.$_};
1299: $timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
1300: }
1301: }
1302: foreach ((keys %lasthash)) {
1303: if ($_ =~ /\.submission$/) {
1304: my ($partid,$foo) = split(/submission$/,$_);
1305: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1306: '<font color="red">Draft Copy</font> ' : '';
1307: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 1308: }
1309: }
1310: }
1.46 ng 1311: @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
1312: return \@string,\$timestamp;
1.38 ng 1313: }
1.35 ng 1314:
1.44 ng 1315: #--- High light keywords, with style choosen by user.
1.38 ng 1316: sub keywords_highlight {
1.44 ng 1317: my $string = shift;
1318: my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
1319: my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
1.41 ng 1320: (my $styleoff = $styleon) =~ s/\</\<\//;
1.44 ng 1321: my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
1.41 ng 1322: foreach (@keylist) {
1.60 albertel 1323: $string =~ s/\b\Q$_\E(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
1.41 ng 1324: }
1.57 matthew 1325: # This is not really the right place to do this, but I cannot find a
1326: # better one at this time. So here we go - the m in the s:::mg causes
1327: # ^ to match the beginning of a new line. So we replace(???) the beginning
1328: # of the line with <br /> to make things formatted a little better.
1329: $string =~ s:^:<br />:mg;
1.41 ng 1330: return $string;
1.38 ng 1331: }
1.36 ng 1332:
1.44 ng 1333: #--- Called from submission routine
1.38 ng 1334: sub processHandGrade {
1.41 ng 1335: my ($request) = shift;
1336: my $url = $ENV{'form.url'};
1337: my $symb = $ENV{'form.symb'};
1338: my $button = $ENV{'form.gradeOpt'};
1339: my $ngrade = $ENV{'form.NCT'};
1340: my $ntstu = $ENV{'form.NTSTU'};
1341:
1.44 ng 1342: if ($button eq 'Save & Next') {
1343: my $ctr = 0;
1344: while ($ctr < $ngrade) {
1345: my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.77 ! ng 1346: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.71 ng 1347: if ($errorflag eq 'no_score') {
1348: $ctr++;
1349: next;
1350: }
1.44 ng 1351:
1352: my $includemsg = $ENV{'form.includemsg'.$ctr};
1353: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 1354: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.44 ng 1355: $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
1356: my (@msgnum) = split(/,/,$includemsg);
1357: foreach (@msgnum) {
1358: $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1359: }
1.77 ! ng 1360: $message =~ s/<([^>]|\n)*>//g; # removes html codes Or should this be lonnet::escape ??
! 1361: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
! 1362: $message.=" for <a href=\"/res/$url\">$ENV{'form.probTitle'}</a>";
1.44 ng 1363: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
1364: $ENV{'form.msgsub'},$message);
1365: }
1366: if ($ENV{'form.collaborator'.$ctr}) {
1367: my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
1368: foreach (@collaborators) {
1369: &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
1370: $ENV{'form.unamedom'.$ctr});
1371: if ($message ne '') {
1372: $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
1373: $ENV{'form.msgsub'},
1374: $message);
1375: }
1376: }
1377: }
1378: $ctr++;
1379: }
1380: }
1381:
1382: # Keywords sorted in alphabatical order
1.41 ng 1383: my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
1384: my %keyhash = ();
1385: $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1386: $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
1.44 ng 1387: my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
1388: $ENV{'form.keywords'} = join(' ',@keywords);
1.41 ng 1389: $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
1390: $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
1391: $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
1392: $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
1393: $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
1394:
1.44 ng 1395: # message center - Order of message gets changed. Blank line is eliminated.
1396: # New messages are saved in ENV for the next student.
1397: # All messages are saved in nohist_handgrade.db
1.41 ng 1398: my ($ctr,$idx) = (1,1);
1399: while ($ctr <= $ENV{'form.savemsgN'}) {
1400: if ($ENV{'form.savemsg'.$ctr} ne '') {
1401: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
1402: $idx++;
1403: }
1404: $ctr++;
1405: }
1406: $ctr = 0;
1407: while ($ctr < $ngrade) {
1408: if ($ENV{'form.newmsg'.$ctr} ne '') {
1409: $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1410: $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
1411: $idx++;
1412: }
1413: $ctr++;
1414: }
1415: $ENV{'form.savemsgN'} = --$idx;
1416: $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
1417: my $putresult = &Apache::lonnet::put
1418: ('nohist_handgrade',\%keyhash,
1419: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1420: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1421:
1.44 ng 1422: # Called by Save & Refresh from Highlight Attribute Window
1.41 ng 1423: if ($ENV{'form.refresh'} eq 'on') {
1424: my $ctr = 0;
1425: $ENV{'form.NTSTU'}=$ngrade;
1426: while ($ctr < $ngrade) {
1.44 ng 1427: ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.41 ng 1428: &submission($request,$ctr,$ngrade-1);
1429: $ctr++;
1430: }
1431: return '';
1432: }
1.36 ng 1433:
1.44 ng 1434: # Get the next/previous one or group of students
1.41 ng 1435: my $firststu = $ENV{'form.unamedom0'};
1436: my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
1437: $ctr = 2;
1438: while ($laststu eq '') {
1439: $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
1440: $ctr++;
1441: $laststu = $firststu if ($ctr > $ngrade);
1442: }
1.44 ng 1443:
1.56 matthew 1444: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.41 ng 1445: my (@parsedlist,@nextlist);
1446: my ($nextflg) = 0;
1.53 albertel 1447: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41 ng 1448: if ($nextflg == 1 && $button =~ /Next$/) {
1449: push @parsedlist,$_;
1450: }
1451: $nextflg = 1 if ($_ eq $laststu);
1452: if ($button eq 'Previous') {
1453: last if ($_ eq $firststu);
1454: push @parsedlist,$_;
1455: }
1456: }
1457: $ctr = 0;
1458: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1459: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1460: foreach my $student (@parsedlist) {
1461: my ($uname,$udom) = split(/:/,$student);
1462: if ($ENV{'form.submitonly'} eq 'yes') {
1.44 ng 1463: my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
1.41 ng 1464: my $statusflg = '';
1465: foreach (keys(%status)) {
1466: $statusflg = 1 if ($status{$_} ne 'nothing');
1.44 ng 1467: my ($foo,$partid,$foo1) = split(/\./);
1.41 ng 1468: $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
1469: }
1470: next if ($statusflg eq '');
1471: }
1472: push @nextlist,$student if ($ctr < $ntstu);
1473: $ctr++;
1474: }
1.36 ng 1475:
1.41 ng 1476: $ctr = 0;
1477: my $total = scalar(@nextlist)-1;
1.39 ng 1478:
1.41 ng 1479: foreach (sort @nextlist) {
1480: my ($uname,$udom,$submitter) = split(/:/);
1.44 ng 1481: $ENV{'form.student'} = $uname;
1482: $ENV{'form.userdom'} = $udom;
1.41 ng 1483: $ENV{'form.fullname'} = $$fullname{$_};
1484: &submission($request,$ctr,$total);
1485: $ctr++;
1486: }
1487: if ($total < 0) {
1488: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
1489: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
1490: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1491: $the_end.=&show_grading_menu_form ($symb,$url);
1492: $request->print($the_end);
1493: }
1494: return '';
1.38 ng 1495: }
1.36 ng 1496:
1.44 ng 1497: #---- Save the score and award for each student, if changed
1.38 ng 1498: sub saveHandGrade {
1.41 ng 1499: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
1.77 ! ng 1500: my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
! 1501: my %newrecord = ();
! 1502: my ($pts,$wgt) = ('','');
1.41 ng 1503: foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1.43 ng 1504: if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
1.58 albertel 1505: if ($record{'resource.'.$_.'.solved'} ne 'excused') {
1506: $newrecord{'resource.'.$_.'.solved'} = 'excused';
1507: if (exists($record{'resource.'.$_.'.awarded'})) {
1508: $newrecord{'resource.'.$_.'.awarded'} = '';
1509: }
1510: }
1.41 ng 1511: } else {
1.77 ! ng 1512: $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
! 1513: $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
! 1514: $ENV{'form.RADVAL'.$newflg.'_'.$_});
1.71 ng 1515: return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
1.77 ! ng 1516: $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
1.44 ng 1517: $ENV{'form.WGT'.$newflg.'_'.$_};
1.41 ng 1518: my $partial= $pts/$wgt;
1.44 ng 1519: $newrecord{'resource.'.$_.'.awarded'} = $partial
1520: if ($record{'resource.'.$_.'.awarded'} ne $partial);
1521: my $reckey = 'resource.'.$_.'.solved';
1.41 ng 1522: if ($partial == 0) {
1.44 ng 1523: $newrecord{$reckey} = 'incorrect_by_override'
1524: if ($record{$reckey} ne 'incorrect_by_override');
1.41 ng 1525: } else {
1.44 ng 1526: $newrecord{$reckey} = 'correct_by_override'
1527: if ($record{$reckey} ne 'correct_by_override');
1.41 ng 1528: }
1.44 ng 1529: $newrecord{'resource.'.$_.'.submitted_by'} = $submitter
1530: if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
1.72 ng 1531: $newrecord{'resource.'.$_.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.41 ng 1532: }
1533: }
1.44 ng 1534:
1535: if (scalar(keys(%newrecord)) > 0) {
1536: &Apache::lonnet::cstore(\%newrecord,$symb,
1537: $ENV{'request.course.id'},$domain,$stuname);
1.41 ng 1538: }
1.77 ! ng 1539: return '',$pts,$wgt;
1.36 ng 1540: }
1.38 ng 1541:
1.44 ng 1542: #--------------------------------------------------------------------------------------
1543: #
1544: #-------------------------- Next few routines handles grading by section or whole class
1545: #
1546: #--- Javascript to handle grading by section or whole class
1.42 ng 1547: sub viewgrades_js {
1548: my ($request) = shift;
1549:
1.41 ng 1550: $request->print(<<VIEWJAVASCRIPT);
1551: <script type="text/javascript" language="javascript">
1.45 ng 1552: function writePoint(partid,weight,point) {
1.42 ng 1553: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1554: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1555: if (point == "textval") {
1556: var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
1557: if (isNaN(point) || point < 0) {
1558: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1559: var resetbox = false;
1560: for (var i=0; i<radioButton.length; i++) {
1561: if (radioButton[i].checked) {
1562: textbox.value = i;
1563: resetbox = true;
1564: }
1565: }
1566: if (!resetbox) {
1567: textbox.value = "";
1568: }
1569: return;
1570: }
1.44 ng 1571: if (point > weight) {
1572: var resp = confirm("You entered a value ("+point+
1573: ") greater than the weight for the part. Accept?");
1574: if (resp == false) {
1575: textbox.value = "";
1576: return;
1577: }
1578: }
1.42 ng 1579: for (var i=0; i<radioButton.length; i++) {
1580: radioButton[i].checked=false;
1581: if (point == i) {
1582: radioButton[i].checked=true;
1583: }
1584: }
1.41 ng 1585:
1.42 ng 1586: } else {
1587: textbox.value = point;
1588: }
1.41 ng 1589: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1590: var user = eval("document.classgrade.ctr"+i+".value");
1591: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1592: "_"+partid+"_awarded");
1.43 ng 1593: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1594: "_"+partid+"_solved_s.value");
1595: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42 ng 1596: if (saveval != "correct") {
1597: scorename.value = point;
1.43 ng 1598: if (selname[0].selected != true) {
1599: selname[0].selected = true;
1600: }
1.42 ng 1601: }
1602: }
1603: var selval = eval("document.classgrade.SELVAL_"+partid);
1604: selval[0].selected = true;
1605: }
1606:
1607: function writeRadText(partid,weight) {
1608: var selval = eval("document.classgrade.SELVAL_"+partid);
1.43 ng 1609: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1610: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1.42 ng 1611: if (selval[1].selected) {
1612: for (var i=0; i<radioButton.length; i++) {
1613: radioButton[i].checked=false;
1614:
1615: }
1616: textbox.value = "";
1617:
1618: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1619: var user = eval("document.classgrade.ctr"+i+".value");
1620: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1621: "_"+partid+"_awarded");
1.43 ng 1622: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1623: "_"+partid+"_solved_s.value");
1.43 ng 1624: var selname = eval("document.classgrade.GD_"+user+
1.54 albertel 1625: "_"+partid+"_solved");
1.42 ng 1626: if (saveval != "correct") {
1627: scorename.value = "";
1628: selname[1].selected = true;
1629: }
1630: }
1.43 ng 1631: } else {
1632: for (i=0;i<document.classgrade.total.value;i++) {
1633: var user = eval("document.classgrade.ctr"+i+".value");
1634: var scorename = eval("document.classgrade.GD_"+user+
1.54 albertel 1635: "_"+partid+"_awarded");
1.43 ng 1636: var saveval = eval("document.classgrade.GD_"+user+
1.54 albertel 1637: "_"+partid+"_solved_s.value");
1.43 ng 1638: var selname = eval("document.classgrade.GD_"+user+
1.54 albertel 1639: "_"+partid+"_solved");
1.43 ng 1640: if (saveval != "correct") {
1641: scorename.value = eval("document.classgrade.GD_"+user+
1.54 albertel 1642: "_"+partid+"_awarded_s.value");;
1.43 ng 1643: selname[0].selected = true;
1644: }
1645: }
1646: }
1.42 ng 1647: }
1648:
1649: function changeSelect(partid,user) {
1.54 albertel 1650: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1651: var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.44 ng 1652: var point = textbox.value;
1653: var weight = eval("document.classgrade.weight_"+partid+".value");
1654:
1655: if (isNaN(point) || point < 0) {
1656: alert("A number equal or greater than 0 is expected. Entered value = "+point);
1657: textbox.value = "";
1658: return;
1659: }
1660: if (point > weight) {
1661: var resp = confirm("You entered a value ("+point+
1662: ") greater than the weight of the part. Accept?");
1663: if (resp == false) {
1664: textbox.value = "";
1665: return;
1666: }
1667: }
1.42 ng 1668: selval[0].selected = true;
1669: }
1670:
1671: function changeOneScore(partid,user) {
1.54 albertel 1672: var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1.42 ng 1673: if (selval[1].selected) {
1.54 albertel 1674: var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.42 ng 1675: boxval.value = "";
1676: }
1677: }
1678:
1679: function resetEntry(numpart) {
1680: for (ctpart=0;ctpart<numpart;ctpart++) {
1681: var partid = eval("document.classgrade.partid_"+ctpart+".value");
1682: var radioButton = eval("document.classgrade.RADVAL_"+partid);
1683: var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1684: var selval = eval("document.classgrade.SELVAL_"+partid);
1685: for (var i=0; i<radioButton.length; i++) {
1686: radioButton[i].checked=false;
1687:
1688: }
1689: textbox.value = "";
1690: selval[0].selected = true;
1691:
1692: for (i=0;i<document.classgrade.total.value;i++) {
1.43 ng 1693: var user = eval("document.classgrade.ctr"+i+".value");
1694: var resetscore = eval("document.classgrade.GD_"+user+
1.54 albertel 1695: "_"+partid+"_awarded");
1.43 ng 1696: resetscore.value = eval("document.classgrade.GD_"+user+
1.54 albertel 1697: "_"+partid+"_awarded_s.value");
1.42 ng 1698:
1.43 ng 1699: var saveselval = eval("document.classgrade.GD_"+user+
1.54 albertel 1700: "_"+partid+"_solved_s.value");
1.42 ng 1701:
1.54 albertel 1702: var selname = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42 ng 1703: if (saveselval == "excused") {
1.43 ng 1704: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 1705: } else {
1.43 ng 1706: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 1707: }
1708: }
1.41 ng 1709: }
1.42 ng 1710: }
1711:
1.41 ng 1712: </script>
1713: VIEWJAVASCRIPT
1.42 ng 1714: }
1715:
1.44 ng 1716: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 1717: sub viewgrades {
1718: my ($request) = shift;
1719: &viewgrades_js($request);
1.41 ng 1720:
1721: my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
1.45 ng 1722: my $result='<h3><font color="#339933">Manual Grading</font></h3>';
1.38 ng 1723:
1.72 ng 1724: $result.='<font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font>'."\n";
1.41 ng 1725:
1726: #view individual student submission form - called using Javascript viewOneStudent
1.45 ng 1727: $result.=&jscriptNform($url,$symb);
1.41 ng 1728:
1.44 ng 1729: #beginning of class grading form
1.41 ng 1730: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1731: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1732: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 1733: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.72 ng 1734: '<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n".
1.77 ! ng 1735: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 1736: '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
1737:
1.52 albertel 1738: $result.='<h3>Assign Common Grade To ';
1739: if ($ENV{'form.section'} eq 'all') {
1740: $result.='Class </h3>';
1741: } elsif ($ENV{'form.section'} eq 'no') {
1742: $result.='Students in no Section </h3>';
1743: } else {
1744: $result.='Students in Section '.$ENV{'form.section'}.'</h3>';
1745: }
1746: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1747: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 1748: #radio buttons/text box for assigning points for a section or class.
1749: #handles different parts of a problem
1.42 ng 1750: my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
1751: my %weight = ();
1752: my $ctsparts = 0;
1.41 ng 1753: $result.='<table border="0">';
1.45 ng 1754: my %seen = ();
1.42 ng 1755: for (sort keys(%$handgrade)) {
1.54 albertel 1756: my ($partid,$respid) = split (/_/,$_,2);
1.45 ng 1757: next if $seen{$partid};
1758: $seen{$partid}++;
1.42 ng 1759: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
1760: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
1761: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
1762:
1.44 ng 1763: $result.='<input type="hidden" name="partid_'.
1764: $ctsparts.'" value="'.$partid.'" />'."\n";
1765: $result.='<input type="hidden" name="weight_'.
1766: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1767: $result.='<tr><td><b>Part '.$partid.' Point:</b> </td><td>';
1.42 ng 1768: $result.='<table border="0"><tr>';
1.41 ng 1769: my $ctr = 0;
1.42 ng 1770: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1771: $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 1772: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.41 ng 1773: ','.$ctr.')" />'.$ctr."</td>\n";
1774: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1775: $ctr++;
1776: }
1777: $result.='</tr></table>';
1.44 ng 1778: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 1779: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
1780: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 1781: $weight{$partid}.' (problem weight)</td>'."\n";
1782: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 1783: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 1784: $weight{$partid}.')"> '.
1.42 ng 1785: '<option selected="on"> </option>'.
1786: '<option>excused</option></select></td></tr>'."\n";
1787: $ctsparts++;
1.41 ng 1788: }
1.52 albertel 1789: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
1790: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 1791: $result.='<input type="button" value="Reset" '.
1.43 ng 1792: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self> ';
1.45 ng 1793: $result.='<input type="button" value="Submit Changes" '.
1794: 'onClick="javascript:submit();" TARGET=_self />'."\n";
1.41 ng 1795:
1.44 ng 1796: #table listing all the students in a section/class
1797: #header of table
1.52 albertel 1798: $result.= '<h3>Assign Grade to Specific Students in ';
1799: if ($ENV{'form.section'} eq 'all') {
1800: $result.='the Class </h3>';
1801: } elsif ($ENV{'form.section'} eq 'no') {
1802: $result.='no Section </h3>';
1803: } else {
1804: $result.='Section '.$ENV{'form.section'}.'</h3>';
1805: }
1.42 ng 1806: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.41 ng 1807: '<table border=0><tr bgcolor="#deffff">'.
1.44 ng 1808: '<td><b>Fullname</b></td><td><b>Username</b></td><td><b>Domain</b></td>'."\n";
1.41 ng 1809: my (@parts) = sort(&getpartlist($url));
1810: foreach my $part (@parts) {
1811: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1812: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1813: if ($display =~ /^Partial Credit Factor/) {
1.54 albertel 1814: my ($partid) = &split_part_type($part);
1.53 albertel 1815: $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
1.42 ng 1816: $weight{$partid}.')</b></td>'."\n";
1.41 ng 1817: next;
1818: }
1.53 albertel 1819: $display =~ s|Problem Status|Grade Status<br />|;
1.41 ng 1820: $result.='<td><b>'.$display.'</b></td>'."\n";
1821: }
1822: $result.='</tr>';
1.44 ng 1823:
1.41 ng 1824: #get info for each student
1.44 ng 1825: #list all the students - with points and grade status
1.76 ng 1826: my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
1.41 ng 1827: my $ctr = 0;
1.53 albertel 1828: foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44 ng 1829: my ($uname,$udom) = split(/:/);
1830: $result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
1.41 ng 1831: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
1832: $_,$$fullname{$_},\@parts,\%weight);
1833: $ctr++;
1834: }
1835: $result.='</table></td></tr></table>';
1836: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.45 ng 1837: $result.='<input type="button" value="Submit Changes" '.
1838: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.41 ng 1839: $result.=&show_grading_menu_form($symb,$url);
1840: return $result;
1841: }
1842:
1.44 ng 1843: #--- call by previous routine to display each student
1.41 ng 1844: sub viewstudentgrade {
1845: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
1.44 ng 1846: my ($uname,$udom) = split(/:/,$student);
1847: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.41 ng 1848: my $result='<tr bgcolor="#ffffdd"><td>'.
1.44 ng 1849: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1850: '\')"; TARGET=_self>'.$fullname.'</a>'.
1851: '</td><td>'.$uname.'</td><td align="middle">'.$udom.'</td>'."\n";
1.63 albertel 1852: foreach my $apart (@$parts) {
1853: my ($part,$type) = &split_part_type($apart);
1.41 ng 1854: my $score=$record{"resource.$part.$type"};
1855: if ($type eq 'awarded') {
1.42 ng 1856: my $pts = $score eq '' ? '' : $score*$$weight{$part};
1857: $result.='<input type="hidden" name="'.
1.54 albertel 1858: 'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.42 ng 1859: $result.='<td align="middle"><input type="text" name="'.
1.54 albertel 1860: 'GD_'.$uname.'_'.$part.'_awarded" '.
1861: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$uname.
1.44 ng 1862: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 1863: } elsif ($type eq 'solved') {
1864: my ($status,$foo)=split(/_/,$score,2);
1865: $status = 'nothing' if ($status eq '');
1.54 albertel 1866: $result.='<input type="hidden" name="'.'GD_'.$uname.'_'.
1867: $part.'_solved_s" value="'.$status.'" />'."\n";
1.42 ng 1868: $result.='<td align="middle"><select name="'.
1.54 albertel 1869: 'GD_'.$uname.'_'.$part.'_solved" '.
1870: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$uname.'\')" >'."\n";
1.42 ng 1871: my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
1872: $optsel = '<option> </option><option selected="on">excused</option>'."\n"
1873: if ($status eq 'excused');
1.41 ng 1874: $result.=$optsel;
1875: $result.="</select></td>\n";
1.54 albertel 1876: } else {
1877: $result.='<input type="hidden" name="'.
1878: 'GD_'.$uname.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
1879: "\n";
1880: $result.='<td align="middle"><input type="text" name="'.
1881: 'GD_'.$uname.'_'.$part.'_'.$type.'" '.
1882: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 1883: }
1884: }
1885: $result.='</tr>';
1886: return $result;
1.38 ng 1887: }
1888:
1.44 ng 1889: #--- change scores for all the students in a section/class
1890: # record does not get update if unchanged
1.38 ng 1891: sub editgrades {
1.41 ng 1892: my ($request) = @_;
1893:
1894: my $symb=$ENV{'form.symb'};
1.43 ng 1895: my $url =$ENV{'form.url'};
1.45 ng 1896: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.72 ng 1897: $title.='<font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font><br />'."\n";
1.44 ng 1898: $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
1899: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.43 ng 1900: $result.= '<table border="0"><tr bgcolor="#deffff">'.
1901: '<td rowspan=2><b>Username</b></td><td rowspan=2><b>Fullname</b></td>'."\n";
1902:
1903: my %scoreptr = (
1904: 'correct' =>'correct_by_override',
1905: 'incorrect'=>'incorrect_by_override',
1906: 'excused' =>'excused',
1907: 'ungraded' =>'ungraded_attempted',
1908: 'nothing' => '',
1909: );
1.56 matthew 1910: my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.34 ng 1911:
1.44 ng 1912: my (@partid);
1913: my %weight = ();
1.54 albertel 1914: my %columns = ();
1.44 ng 1915: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 1916:
1917: my (@parts) = sort(&getpartlist($url));
1918: my $header;
1.44 ng 1919: while ($ctr < $ENV{'form.totalparts'}) {
1920: my $partid = $ENV{'form.partid_'.$ctr};
1921: push @partid,$partid;
1922: $weight{$partid} = $ENV{'form.weight_'.$partid};
1923: $ctr++;
1.54 albertel 1924: }
1925: foreach my $partid (@partid) {
1926: $header .= '<td align="center"> <b>Old Score</b> </td>'.
1927: '<td align="center"> <b>New Score</b> </td>';
1928: $columns{$partid}=2;
1929: foreach my $stores (@parts) {
1930: my ($part,$type) = &split_part_type($stores);
1931: if ($part !~ m/^\Q$partid\E/) { next;}
1932: if ($type eq 'awarded' || $type eq 'solved') { next; }
1933: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1934: $display =~ s/\[Part: (\w)+\]//;
1935: $header .= '<td align="center"> <b>Old</b> '.$display.' </td>'.
1936: '<td align="center"> <b>New</b> '.$display.' </td>';
1937: $columns{$partid}+=2;
1938: }
1939: }
1940: foreach my $partid (@partid) {
1941: $result .= '<td colspan="'.$columns{$partid}.
1942: '" align="center"><b>Part '.$partid.
1.44 ng 1943: '</b> (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 1944:
1.44 ng 1945: }
1946: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 1947: $result .= $header;
1.44 ng 1948: $result .= '</tr>'."\n";
1.13 albertel 1949:
1.44 ng 1950: for ($i=0; $i<$ENV{'form.total'}; $i++) {
1951: my $user = $ENV{'form.ctr'.$i};
1952: my %newrecord;
1953: my $updateflag = 0;
1954: my @userdom = grep /^$user:/,keys %$classlist;
1.54 albertel 1955: my (undef,$udom) = split(/:/,$userdom[0]);
1.13 albertel 1956:
1.44 ng 1957: $result .= '<tr bgcolor="#ffffde"><td>'.$user.' </td><td>'.
1958: $$fullname{$userdom[0]}.' </td>';
1959: foreach (@partid) {
1.54 albertel 1960: my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1961: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
1962: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1963: my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1964:
1965: my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
1966: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
1967: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 1968: my $score;
1969: if ($partial eq '') {
1.54 albertel 1970: $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 1971: } elsif ($partial > 0) {
1972: $score = 'correct_by_override';
1973: } elsif ($partial == 0) {
1974: $score = 'incorrect_by_override';
1975: }
1.54 albertel 1976: $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
1.44 ng 1977: ($score ne 'excused'));
1978: $result .= '<td align="center">'.$old_aw.' </td>'.
1979: '<td align="center">'.$awarded.
1980: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 1981:
1.54 albertel 1982: if (!($old_part eq $partial && $old_score eq $score)) {
1983: $updateflag = 1;
1984: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
1985: $newrecord{'resource.'.$_.'.solved'} = $score;
1986: $rec_update++;
1987: }
1988:
1989: my $partid=$_;
1990: foreach my $stores (@parts) {
1991: my ($part,$type) = &split_part_type($stores);
1992: if ($part !~ m/^\Q$partid\E/) { next;}
1993: if ($type eq 'awarded' || $type eq 'solved') { next; }
1994: my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
1995: my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
1996: if ($awarded ne '' && $awarded ne $old_aw) {
1997: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.72 ng 1998: $newrecord{'resource.'.$part.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.54 albertel 1999: $updateflag=1;
2000: }
2001: $result .= '<td align="center">'.$old_aw.' </td>'.
2002: '<td align="center">'.$awarded.' </td>';
2003: }
1.44 ng 2004: }
2005: $result .= '</tr>'."\n";
2006: if ($updateflag) {
2007: $count++;
2008: &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
2009: $udom,$user);
2010: }
2011: }
1.72 ng 2012: $result .= '</table></td></tr></table>'."\n".
2013: &show_grading_menu_form ($symb,$url);
1.44 ng 2014: my $msg = '<b>Number of records updated = '.$rec_update.
2015: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
2016: '<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
2017: return $title.$msg.$result;
1.5 albertel 2018: }
1.54 albertel 2019:
2020: sub split_part_type {
2021: my ($partstr) = @_;
2022: my ($temp,@allparts)=split(/_/,$partstr);
2023: my $type=pop(@allparts);
2024: my $part=join('.',@allparts);
2025: return ($part,$type);
2026: }
2027:
1.44 ng 2028: #------------- end of section for handling grading by section/class ---------
2029: #
2030: #----------------------------------------------------------------------------
2031:
1.5 albertel 2032:
1.44 ng 2033: #----------------------------------------------------------------------------
2034: #
2035: #-------------------------- Next few routines handles grading by csv upload
2036: #
2037: #--- Javascript to handle csv upload
1.27 albertel 2038: sub csvupload_javascript_reverse_associate {
2039: return(<<ENDPICK);
2040: function verify(vf) {
2041: var foundsomething=0;
2042: var founduname=0;
2043: var founddomain=0;
2044: for (i=0;i<=vf.nfields.value;i++) {
2045: tw=eval('vf.f'+i+'.selectedIndex');
2046: if (i==0 && tw!=0) { founduname=1; }
2047: if (i==1 && tw!=0) { founddomain=1; }
2048: if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
2049: }
2050: if (founduname==0 || founddomain==0) {
2051: alert('You need to specify at both the username and domain');
2052: return;
2053: }
2054: if (foundsomething==0) {
2055: alert('You need to specify at least one grading field');
2056: return;
2057: }
2058: vf.submit();
2059: }
2060: function flip(vf,tf) {
2061: var nw=eval('vf.f'+tf+'.selectedIndex');
2062: var i;
2063: for (i=0;i<=vf.nfields.value;i++) {
2064: //can not pick the same destination field for both name and domain
2065: if (((i ==0)||(i ==1)) &&
2066: ((tf==0)||(tf==1)) &&
2067: (i!=tf) &&
2068: (eval('vf.f'+i+'.selectedIndex')==nw)) {
2069: eval('vf.f'+i+'.selectedIndex=0;')
2070: }
2071: }
2072: }
2073: ENDPICK
2074: }
2075:
2076: sub csvupload_javascript_forward_associate {
2077: return(<<ENDPICK);
2078: function verify(vf) {
2079: var foundsomething=0;
2080: var founduname=0;
2081: var founddomain=0;
2082: for (i=0;i<=vf.nfields.value;i++) {
2083: tw=eval('vf.f'+i+'.selectedIndex');
2084: if (tw==1) { founduname=1; }
2085: if (tw==2) { founddomain=1; }
2086: if (tw>2) { foundsomething=1; }
2087: }
2088: if (founduname==0 || founddomain==0) {
2089: alert('You need to specify at both the username and domain');
2090: return;
2091: }
2092: if (foundsomething==0) {
2093: alert('You need to specify at least one grading field');
2094: return;
2095: }
2096: vf.submit();
2097: }
2098: function flip(vf,tf) {
2099: var nw=eval('vf.f'+tf+'.selectedIndex');
2100: var i;
2101: //can not pick the same destination field twice
2102: for (i=0;i<=vf.nfields.value;i++) {
2103: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
2104: eval('vf.f'+i+'.selectedIndex=0;')
2105: }
2106: }
2107: }
2108: ENDPICK
2109: }
2110:
1.26 albertel 2111: sub csvuploadmap_header {
1.41 ng 2112: my ($request,$symb,$url,$datatoken,$distotal)= @_;
2113: my $javascript;
2114: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2115: $javascript=&csvupload_javascript_reverse_associate();
2116: } else {
2117: $javascript=&csvupload_javascript_forward_associate();
2118: }
1.45 ng 2119:
2120: my $result='<table border="0">';
1.72 ng 2121: $result.='<tr><td colspan=3><font size=+1><b>Problem: </b>'.$ENV{'form.probTitle'}.'</font></td></tr>';
1.45 ng 2122: my ($partlist,$handgrade) = &response_type($url);
2123: my ($resptype,$hdgrade)=('','no');
2124: for (sort keys(%$handgrade)) {
2125: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
2126: $resptype = $responsetype;
2127: $hdgrade = $handgrade if ($handgrade eq 'yes');
2128: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
2129: '<td><b>Type: </b>'.$responsetype.'</td>'.
2130: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
2131: }
2132: $result.='</table>';
1.41 ng 2133: $request->print(<<ENDPICK);
1.26 albertel 2134: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 2135: <h3><font color="#339933">Uploading Class Grades</font></h3>
2136: $result
1.26 albertel 2137: <hr>
2138: <h3>Identify fields</h3>
2139: Total number of records found in file: $distotal <hr />
2140: Enter as many fields as you can. The system will inform you and bring you back
2141: to this page if the data selected is insufficient to run your class.<hr />
2142: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
2143: <input type="hidden" name="associate" value="" />
2144: <input type="hidden" name="phase" value="three" />
2145: <input type="hidden" name="datatoken" value="$datatoken" />
2146: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
2147: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
2148: <input type="hidden" name="upfile_associate"
2149: value="$ENV{'form.upfile_associate'}" />
2150: <input type="hidden" name="symb" value="$symb" />
2151: <input type="hidden" name="url" value="$url" />
1.77 ! ng 2152: <input type="hidden" name="saveState" value="$ENV{'form.saveState'}" />
1.72 ng 2153: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
1.26 albertel 2154: <input type="hidden" name="command" value="csvuploadassign" />
2155: <hr />
2156: <script type="text/javascript" language="Javascript">
2157: $javascript
2158: </script>
2159: ENDPICK
1.41 ng 2160: return '';
1.26 albertel 2161:
2162: }
2163:
2164: sub csvupload_fields {
1.41 ng 2165: my ($url) = @_;
2166: my (@parts) = &getpartlist($url);
2167: my @fields=(['username','Student Username'],['domain','Student Domain']);
2168: foreach my $part (sort(@parts)) {
2169: my @datum;
2170: my $display=&Apache::lonnet::metadata($url,$part.'.display');
2171: my $name=$part;
2172: if (!$display) { $display = $name; }
2173: @datum=($name,$display);
2174: push(@fields,\@datum);
2175: }
2176: return (@fields);
1.26 albertel 2177: }
2178:
2179: sub csvuploadmap_footer {
1.41 ng 2180: my ($request,$i,$keyfields) =@_;
2181: $request->print(<<ENDPICK);
1.26 albertel 2182: </table>
2183: <input type="hidden" name="nfields" value="$i" />
2184: <input type="hidden" name="keyfields" value="$keyfields" />
2185: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
2186: </form>
2187: ENDPICK
2188: }
2189:
2190: sub csvuploadmap {
1.41 ng 2191: my ($request)= @_;
2192: my ($symb,$url)=&get_symb_and_url($request);
2193: if (!$symb) {return '';}
1.72 ng 2194:
1.41 ng 2195: my $datatoken;
2196: if (!$ENV{'form.datatoken'}) {
2197: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 2198: } else {
1.41 ng 2199: $datatoken=$ENV{'form.datatoken'};
2200: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 2201: }
1.41 ng 2202: my @records=&Apache::loncommon::upfile_record_sep();
2203: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
2204: my ($i,$keyfields);
2205: if (@records) {
2206: my @fields=&csvupload_fields($url);
1.45 ng 2207:
1.41 ng 2208: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2209: &Apache::loncommon::csv_print_samples($request,\@records);
2210: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
2211: \@fields);
2212: foreach (@fields) { $keyfields.=$_->[0].','; }
2213: chop($keyfields);
2214: } else {
2215: unshift(@fields,['none','']);
2216: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
2217: \@fields);
2218: my %sone=&Apache::loncommon::record_sep($records[0]);
2219: $keyfields=join(',',sort(keys(%sone)));
2220: }
2221: }
2222: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 2223: $request->print(&show_grading_menu_form($symb,$url));
2224:
1.41 ng 2225: return '';
1.27 albertel 2226: }
2227:
2228: sub csvuploadassign {
1.41 ng 2229: my ($request)= @_;
2230: my ($symb,$url)=&get_symb_and_url($request);
2231: if (!$symb) {return '';}
2232: &Apache::loncommon::load_tmp_file($request);
1.44 ng 2233: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.41 ng 2234: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
2235: my %fields=();
2236: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
2237: if ($ENV{'form.upfile_associate'} eq 'reverse') {
2238: if ($ENV{'form.f'.$i} ne 'none') {
2239: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
2240: }
2241: } else {
2242: if ($ENV{'form.f'.$i} ne 'none') {
2243: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
2244: }
2245: }
1.27 albertel 2246: }
1.41 ng 2247: $request->print('<h3>Assigning Grades</h3>');
2248: my $courseid=$ENV{'request.course.id'};
2249: my ($classlist) = &getclasslist('all','1');
2250: my @skipped;
2251: my $countdone=0;
2252: foreach my $grade (@gradedata) {
2253: my %entries=&Apache::loncommon::record_sep($grade);
2254: my $username=$entries{$fields{'username'}};
2255: my $domain=$entries{$fields{'domain'}};
2256: if (!exists($$classlist{"$username:$domain"})) {
2257: push(@skipped,"$username:$domain");
2258: next;
2259: }
2260: my %grades;
2261: foreach my $dest (keys(%fields)) {
2262: if ($dest eq 'username' || $dest eq 'domain') { next; }
2263: if ($entries{$fields{$dest}} eq '') { next; }
2264: my $store_key=$dest;
2265: $store_key=~s/^stores/resource/;
2266: $store_key=~s/_/\./g;
2267: $grades{$store_key}=$entries{$fields{$dest}};
2268: }
2269: $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
2270: &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
2271: $domain,$username);
2272: $request->print('.');
2273: $request->rflush();
2274: $countdone++;
2275: }
2276: $request->print("<br />Stored $countdone students\n");
2277: if (@skipped) {
2278: $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
2279: foreach my $student (@skipped) { $request->print("<br />$student"); }
2280: }
2281: $request->print(&view_edit_entire_class_form($symb,$url));
2282: $request->print(&show_grading_menu_form($symb,$url));
2283: return '';
1.26 albertel 2284: }
1.44 ng 2285: #------------- end of section for handling csv file upload ---------
2286: #
2287: #-------------------------------------------------------------------
2288: #
1.72 ng 2289: #-------------- Next few routines handles grading by page/sequence
2290: #
2291: #--- Select a page/sequence and a student to grade
1.68 ng 2292: sub pickStudentPage {
2293: my ($request) = shift;
2294:
2295: $request->print(<<LISTJAVASCRIPT);
2296: <script type="text/javascript" language="javascript">
2297:
2298: function checkPickOne(formname) {
1.76 ng 2299: if (radioSelection(formname.student) == null) {
1.68 ng 2300: alert("Please select the student you wish to grade.");
2301: return;
2302: }
1.70 ng 2303: var ptr = pullDownSelection(formname.selectpage);
1.71 ng 2304: formname.page.value = eval("formname.page"+ptr+".value");
2305: formname.title.value = eval("formname.title"+ptr+".value");
1.68 ng 2306: formname.submit();
2307: }
2308:
2309: function radioSelection(radioButton) {
2310: var selection=null;
1.76 ng 2311: if (radioButton.length > 1) {
2312: for (var i=0; i<radioButton.length; i++) {
2313: if (radioButton[i].checked) {
2314: return radioButton[i].value;
2315: }
2316: }
2317: } else {
2318: if (radioButton.checked) return radioButton.value;
1.68 ng 2319: }
2320: return selection;
2321: }
1.76 ng 2322:
1.70 ng 2323: function pullDownSelection(selectOne) {
1.76 ng 2324: var selection="";
2325: if (selectOne.length > 1) {
2326: for (var i=0; i<selectOne.length; i++) {
2327: if (selectOne[i].selected) {
2328: return selectOne[i].value;
2329: }
2330: }
2331: } else {
2332: if (selectOne.selected) return selectOne.value;
1.70 ng 2333: }
2334: }
1.68 ng 2335: </script>
2336: LISTJAVASCRIPT
2337:
1.72 ng 2338: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2339: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2340: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2341: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2342:
2343: my $result='<h3><font color="#339933"> '.
2344: 'Manual Grading by Page or Sequence</font></h3>';
2345:
2346: $result.='<form action="/adm/grades" method="post" name="displayPage">'."<br>\n";
1.70 ng 2347: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 2348: my ($titles,$symbx) = &getSymbMap($request);
1.71 ng 2349: my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
1.70 ng 2350: my $ctr=0;
1.68 ng 2351: foreach (@$titles) {
2352: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 2353: $result.='<option value="'.$ctr.'" '.
1.71 ng 2354: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
2355: '>'.$showtitle.'</option>'."\n";
1.70 ng 2356: $ctr++;
1.68 ng 2357: }
2358: $result.= '</select>'."<br>\n";
1.70 ng 2359: $ctr=0;
2360: foreach (@$titles) {
2361: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
2362: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
2363: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
2364: $ctr++;
2365: }
1.72 ng 2366: $result.='<input type="hidden" name="page" />'."\n".
2367: '<input type="hidden" name="title" />'."\n";
1.68 ng 2368:
1.71 ng 2369: $result.=' <b>View Problems: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
2370: '<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
1.72 ng 2371:
1.71 ng 2372: $result.=' <b>Submission Details: </b>'.
2373: '<input type="radio" name="lastSub" value="none" /> none'."\n".
2374: '<input type="radio" name="lastSub" value="datesub" checked /> dates and submissions'."\n".
2375: '<input type="radio" name="lastSub" value="all" /> all details'."\n";
1.72 ng 2376:
1.68 ng 2377: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.72 ng 2378: '<input type="hidden" name="command" value="displayPage" />'."\n".
2379: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2380: '<input type="hidden" name="symb" value="'.$symb.'" />'."<br><br>\n".
1.77 ! ng 2381: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
1.72 ng 2382:
2383: $result.='<br /> <input type="button" '.
2384: 'onClick="javascript:checkPickOne(this.form);"value="Submit" /><br />'."\n";
2385:
1.68 ng 2386: $request->print($result);
2387:
1.76 ng 2388: my $studentTable.=' <b>Select a student you wish to grade</b><br>'.
1.68 ng 2389: '<table border="0"><tr><td bgcolor="#777777">'.
2390: '<table border="0"><tr bgcolor="#e6ffff">'.
2391: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2392: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2393: '<td><b> Fullname <font color="#999999">(username)</font></b></td>'.
2394: '<td><b> Fullname <font color="#999999">(username)</font></b></td></tr>';
2395:
1.76 ng 2396: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 2397: my $ptr = 1;
2398: foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
2399: my ($uname,$udom) = split(/:/,$student);
2400: $studentTable.=($ptr%4 == 1 ? '<tr bgcolor="#ffffe6"><td>' : '</td><td>');
1.70 ng 2401: $studentTable.='<input type="radio" name="student" value="'.$student.'" /> '.$$fullname{$student}.
1.68 ng 2402: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
2403: $studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
2404: $ptr++;
2405: }
2406: $studentTable.='</td><td> </td><td> </td><td> ' if ($ptr%4 == 2);
2407: $studentTable.='</td><td> </td><td> ' if ($ptr%4 == 3);
2408: $studentTable.='</td><td> ' if ($ptr%4 == 0);
2409: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.70 ng 2410: $studentTable.='<br /> <input type="button" '.
2411: 'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
1.68 ng 2412:
2413: $studentTable.=&show_grading_menu_form($symb,$url);
2414: $request->print($studentTable);
2415:
2416: return '';
2417: }
2418:
2419: sub getSymbMap {
1.74 albertel 2420: my ($request) = @_;
2421: my $navmap = Apache::lonnavmaps::navmap-> new($request,
1.68 ng 2422: $ENV{'request.course.fn'}.'.db',
2423: $ENV{'request.course.fn'}.'_parms.db',1, 1);
2424:
2425: my $res = $navmap->firstResource(); # temp resource to access constants
2426: $navmap->init();
2427:
2428: # End navmap using boilerplate
2429:
2430: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
2431: my $depth = 1;
2432: $iterator->next(); # ignore first BEGIN_MAP
2433: my $curRes = $iterator->next();
2434:
2435: my %symbx = ();
2436: my @titles = ();
2437: my $minder=0;
2438: while ($depth > 0) {
2439: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
2440: if ($curRes == $iterator->END_MAP()) { $depth--; }
2441:
2442: if (ref($curRes) && $curRes->is_map()) {
1.71 ng 2443: my ($mapUrl, $id, $resUrl) = split(/___/, $curRes->symb()); # check map contains at least one problem
2444: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2445:
2446: my $mapiterator = $navmap->getIterator($map->map_start(),
2447: $map->map_finish());
2448:
2449: my $mapdepth = 1;
2450: my $countProblems = 0;
2451: $mapiterator->next(); # skip the first BEGIN_MAP
2452: my $mapcurRes = $mapiterator->next(); # for "current resource"
2453: my $ctr=0;
2454: while ($mapdepth > 0 && $ctr < 100) {
2455: if($mapcurRes == $mapiterator->BEGIN_MAP) { $mapdepth++; }
2456: if($mapcurRes == $mapiterator->END_MAP) { $mapdepth++; }
2457:
2458: if (ref($mapcurRes) && $mapcurRes->is_problem() && !$mapcurRes->randomout) {
2459: $countProblems++;
2460: }
2461: $ctr++;
2462: }
2463: if ($countProblems > 0) {
2464: my $title = $curRes->compTitle();
2465: push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
2466: $symbx{$minder.'.'.$title} = $curRes->symb();
2467: $minder++;
2468: }
1.68 ng 2469: }
2470: $curRes = $iterator->next();
2471: }
2472:
2473: $navmap->untieHashes();
2474: return \@titles,\%symbx;
2475: }
2476:
1.72 ng 2477: #
2478: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 2479: sub displayPage {
2480: my ($request) = shift;
2481:
1.72 ng 2482: my ($symb,$url) = &get_symb_and_url($request);
1.68 ng 2483: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2484: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2485: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2486: my $pageTitle = $ENV{'form.page'};
1.76 ng 2487: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.70 ng 2488: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.68 ng 2489:
1.70 ng 2490: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
2491: $result.='<h3> Student: '.$$fullname{$ENV{'form.student'}}.
1.68 ng 2492: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
2493:
1.71 ng 2494: &sub_page_js($request);
2495: $request->print($result);
2496:
1.74 albertel 2497: my $navmap = Apache::lonnavmaps::navmap-> new($request,
1.68 ng 2498: $ENV{'request.course.fn'}.'.db',
2499: $ENV{'request.course.fn'}.'_parms.db',1, 1);
1.70 ng 2500: my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
1.68 ng 2501: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2502:
2503: my $iterator = $navmap->getIterator($map->map_start(),
2504: $map->map_finish());
2505:
1.71 ng 2506: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 2507: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
2508: '<input type="hidden" name="student" value="'.$ENV{'form.student'}.'" />'."\n".
2509: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
2510: '<input type="hidden" name="title" value="'.$ENV{'form.title'}.'" />'."\n".
2511: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
2512: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.77 ! ng 2513: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
1.71 ng 2514:
2515: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
2516: '/check.gif" height="16" border="0" />';
2517:
2518: $studentTable.=' <b>Note:</b> A problem graded correct ('.$checkIcon.
2519: ') by the computer cannot be changed.'."\n".
2520: '<table border="0"><tr><td bgcolor="#777777">'.
2521: '<table border="0"><tr bgcolor="#e6ffff">'.
2522: '<td align="center"><b> No </b></td>'.
2523: '<td><b> '.($ENV{'form.vProb'} eq 'no' ? 'Title' : 'Problem View').'/Grade</b></td></tr>';
2524:
2525: my ($depth,$ctr,$question) = (1,0,1);
1.68 ng 2526: $iterator->next(); # skip the first BEGIN_MAP
2527: my $curRes = $iterator->next(); # for "current resource"
2528: while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
2529: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
2530: if($curRes == $iterator->END_MAP) { $depth++; }
2531:
2532: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
2533: my $parts = $curRes->parts();
1.72 ng 2534: $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
1.68 ng 2535: my $title = $curRes->compTitle();
1.71 ng 2536: my $symbx = $curRes->symb();
2537: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
2538: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
2539: $studentTable.='<td valign="top">';
2540: if ($ENV{'form.vProb'} eq 'yes') {
2541: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1);
2542: } else {
2543: my $companswer = &Apache::loncommon::get_student_answers(
2544: $symbx,$uname,$udom,$ENV{'request.course.id'});
2545: $companswer=~s|<form(.*?)>||g;
2546: $companswer=~s|</form>||g;
2547:
2548: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
2549: # $request->print('match='.$1.'<br>');
2550: # $companswer =~ s/$1/ /s;
2551: # }
2552: # $companswer =~ s/<table border=\"1\">/<table border=\"0\">/g;
2553: $studentTable.=' <b>'.$title.'</b> <br> <b>Correct answer:</b><br>'.$companswer;
2554: }
2555:
2556: my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname);
2557:
2558: if ($ENV{'form.lastSub'} eq 'datesub') {
2559: if ($record{'version'} eq '') {
2560: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
2561: } else {
2562: $studentTable.='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
2563: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
2564: '<td><b>Date/Time</b></td>'.
2565: '<td><b>Submission</b></td>'.
2566: '<td><b>Status </b></td></tr>';
2567: my ($version);
2568: for ($version=1;$version<=$record{'version'};$version++) {
2569: my $timestamp = scalar(localtime($record{$version.':timestamp'}));
2570: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
2571: my @versionKeys = split(/\:/,$record{$version.':keys'});
2572: my @displaySub = ();
2573: foreach my $partid (@{$parts}) {
2574: my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys;
1.77 ! ng 2575: next if ($record{"$version:resource.$partid.solved"} eq '');
! 2576: # next if ($record{"$version:resource.$partid.award"} eq 'APPROX_ANS' &&
! 2577: # $record{"$version:resource.$partid.solved"} eq '');
1.71 ng 2578: $displaySub[0].=(exists $record{$version.':'.$matchKey[0]}) ?
1.77 ! ng 2579: '<b>Trial '.$version.' Part '.$partid.'</b> '
1.71 ng 2580: .$record{$version.':'.$matchKey[0]}.'<br />' : '';
2581: $displaySub[1].=(exists $record{"$version:resource.$partid.award"}) ?
1.77 ! ng 2582: '<b>Part '.$partid.'</b> '.
1.71 ng 2583: $record{"$version:resource.$partid.award"}.'/'.
2584: $record{"$version:resource.$partid.solved"}.'<br />' : '';
1.72 ng 2585: $displaySub[2].=(exists $record{"$version:resource.$partid.regrader"}) ?
2586: $record{"$version:resource.$partid.regrader"}.' (<b>Part:</b> '.$partid.')' : '';
1.71 ng 2587: }
1.72 ng 2588: $displaySub[2].=(exists $record{"$version:resource.regrader"}) ?
2589: $record{"$version:resource.regrader"} : '';
2590: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1].
2591: ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).' </td></tr>';
1.71 ng 2592: }
2593: $studentTable.='</table></td></tr></table>';
2594: }
2595: } elsif ($ENV{'form.lastSub'} eq 'all') {
2596: my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
2597: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
2598: $ENV{'request.course.id'},
2599: '','.submission');
2600:
2601: }
2602:
2603: foreach my $partid (@{$parts}) {
2604: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
2605: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
2606: $question++;
2607: }
2608: $studentTable.='</td></tr>';
1.68 ng 2609:
2610: }
2611: $curRes = $iterator->next();
2612: $ctr++;
2613: }
2614:
1.71 ng 2615: $studentTable.='</td></tr></table></td></tr></table>'."\n".
2616: ' <input type="button" value="Save" '.
2617: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
2618: '</form>'."\n";
2619: $studentTable.=&show_grading_menu_form($symb,$url);
2620: $request->print($studentTable);
2621:
2622: return '';
2623: }
2624:
1.72 ng 2625: sub temp_parts_fix { #remove sub once lonnavmap is fixed
2626: my $parts = shift;
2627: my %seen = ();
2628: my @correctParts = ();
2629: foreach (@{$parts}) {
2630: next if ($seen{$_} > 0);
2631: $seen{$_}++;
2632: push @correctParts,$_;
2633: }
2634: return \@correctParts;
2635: }
2636:
1.71 ng 2637: sub updateGradeByPage {
2638: my ($request) = shift;
2639:
2640: my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
2641: my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
2642: my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
2643: my $pageTitle = $ENV{'form.page'};
1.76 ng 2644: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.71 ng 2645: my ($uname,$udom) = split(/:/,$ENV{'form.student'});
2646:
2647: my $result='<h3><font color="#339933"> '.$ENV{'form.title'}.'</font></h3>';
2648: $result.='<h3> Student: '.$$fullname{$ENV{'form.student'}}.
2649: '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
1.70 ng 2650:
1.68 ng 2651: $request->print($result);
2652:
1.74 albertel 2653: my $navmap = Apache::lonnavmaps::navmap-> new($request,
1.71 ng 2654: $ENV{'request.course.fn'}.'.db',
2655: $ENV{'request.course.fn'}.'_parms.db',1, 1);
2656: my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
2657: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
2658:
2659: my $iterator = $navmap->getIterator($map->map_start(),
2660: $map->map_finish());
1.70 ng 2661:
1.71 ng 2662: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 2663: '<table border="0"><tr bgcolor="#e6ffff">'.
1.70 ng 2664: '<td align="center"><b> No </b></td>'.
1.71 ng 2665: '<td><b> Title </b></td>'.
2666: '<td><b> Previous Score </b></td>'.
2667: '<td><b> New Score </b></td></tr>';
2668:
2669: $iterator->next(); # skip the first BEGIN_MAP
2670: my $curRes = $iterator->next(); # for "current resource"
2671: my ($depth,$ctr,$question,$changeflag)= (1,0,1,0);
2672: while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
2673: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
2674: if($curRes == $iterator->END_MAP) { $depth++; }
2675:
2676: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
2677: my $parts = $curRes->parts();
1.72 ng 2678: $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
1.71 ng 2679: my $title = $curRes->compTitle();
2680: my $symbx = $curRes->symb();
2681: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
2682: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
2683: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
2684:
2685: my %newrecord=();
2686: my @displayPts=();
2687: foreach my $partid (@{$parts}) {
2688: my $newpts = $ENV{'form.GD_BOX'.$question.'_'.$partid};
2689: my $oldpts = $ENV{'form.oldpts'.$question.'_'.$partid};
2690:
2691: my $wgt = $ENV{'form.WGT'.$question.'_'.$partid} != 0 ?
2692: $ENV{'form.WGT'.$question.'_'.$partid} : 1;
2693: my $partial = $newpts/$wgt;
2694: my $score;
2695: if ($partial > 0) {
2696: $score = 'correct_by_override';
2697: } elsif ($partial == 0) {
2698: $score = 'incorrect_by_override';
2699: }
2700: if ($ENV{'form.GD_SEL'.$question.'_'.$partid} eq 'excused') {
2701: $partial = '';
2702: $score = 'excused';
2703: }
2704: my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid};
2705: $displayPts[0].=' <b>Part</b> '.$partid.' = '.
2706: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
2707: ' <br>';
2708: $displayPts[1].=' <b>Part</b> '.$partid.' = '.
2709: ($oldstatus eq 'correct_by_student' ? $oldpts :
2710: (($score eq 'excused') ? 'excused' : $newpts)).
2711: ' <br>';
2712:
2713: $question++;
2714: if (($oldstatus eq 'correct_by_student') ||
2715: ($newpts eq $oldpts && $score eq $oldstatus))
2716: {
2717: next;
2718: }
2719: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
2720: $newrecord{'resource.'.$partid.'.solved'} = $score;
1.72 ng 2721: $newrecord{'resource.'.$partid.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.71 ng 2722:
2723: $changeflag++;
2724: }
2725: if (scalar(keys(%newrecord)) > 0) {
2726: &Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'},
2727: $udom,$uname);
2728: }
2729: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
2730: '<td valign="top">'.$displayPts[1].'</td>'.
2731: '</tr>';
1.68 ng 2732:
2733: }
1.71 ng 2734: $curRes = $iterator->next();
2735: $ctr++;
1.68 ng 2736: }
2737:
1.71 ng 2738: $studentTable.='</td></tr></table></td></tr></table>';
2739: $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
1.76 ng 2740: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
2741: 'The scores were changed for '.
2742: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
2743: $request->print($grademsg.$studentTable);
1.68 ng 2744:
1.70 ng 2745: return '';
2746: }
2747:
1.72 ng 2748: #-------- end of section for handling grading by page/sequence ---------
2749: #
2750: #-------------------------------------------------------------------
2751:
1.75 albertel 2752: #--------------------Scantron Grading-----------------------------------
2753: #
2754: #------ start of section for handling grading by page/sequence ---------
2755:
2756: sub getSequenceDropDown {
2757: my ($request,$symb)=@_;
2758: my $result='<select name="selectpage">'."\n";
2759: my ($titles,$symbx) = &getSymbMap($request);
2760: my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
2761: my $ctr=0;
2762: foreach (@$titles) {
2763: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
2764: $result.='<option value="'.$$symbx{$_}.'" '.
2765: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
2766: '>'.$showtitle.'</option>'."\n";
2767: $ctr++;
2768: }
2769: $result.= '</select>';
2770: return $result;
2771: }
2772:
2773: sub scantron_selectphase {
2774: my ($r) = @_;
2775: my ($symb,$url)=&get_symb_and_url($r);
2776: if (!$symb) {return '';}
2777: my $sequence_selector=&getSequenceDropDown($r,$symb);
2778: my $result;
2779: $result.= <<SCANTRONFORM;
2780: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
2781: <input type="hidden" name="symb" value="$symb" />
2782: <input type="hidden" name="url" value="$url" />
2783: <input type="hidden" name="command" value="scantron_configphase" />
2784: <table width="100%" border="0">
2785: <tr>
2786: <td bgcolor="#777777">
2787: <table width="100%" border="0">
2788: <tr bgcolor="#e6ffff">
2789: <td>
2790: <b>Specify file location and which Folder/Sequence to grade</b>
2791: </td>
2792: </tr>
2793: <tr bgcolor="#ffffe6">
2794: <td>
2795: Sequence to grade: $sequence_selector
2796: </td>
2797: </tr>
2798: <tr bgcolor="#ffffe6">
2799: <td>
2800: <!-- FIXME I need to present a list of files from a specfic directory that has been configured, or any existing delay queues -->
2801: Filename of scoring office file:
2802: <select name="selectfile">
2803: <option value="filname1">filename1</option>
2804: <option value="filname2">filename2</option>
2805: </select>
2806: </td>
2807: </tr>
2808: </table>
2809: </td>
2810: </tr>
2811: </table>
2812: <input type="submit" value="Submit" />
2813: </form>
2814: SCANTRONFORM
2815:
2816: return $result;
2817: }
2818:
2819: sub scantron_configphase {
2820: my ($r) = @_;
2821: my $sequence=$ENV{'form.selectpage'};
2822: my $result;
2823: $result.="got page $sequence";
2824: $Apache::lonxml::debug=1;
2825: &Apache::lonhomework::showhash(%ENV);
2826: $Apache::lonxml::debug=0;
2827: #FIXME Needs to present some lines from the file and allow the instructor to specify which columns represent what data, possibly have some nice defaults setup, probably should do a pass through all problems for a student to get an idea of how many questions there are, and homw many lines we'll have,
2828: return $result;
2829: }
2830:
2831: sub scantron_process_students {
2832: #FIXME
2833: # loop through students, {
2834: # Check if studnet info valid, if not add line to delay queue
2835: # foreach question 'submit' the students answer to the server
2836: # through grade target {
2837: # generate data to pass back that includes grade recevied
2838: # }
2839: # }
2840: # loop through delay queue {
2841: # print out each delayed student with interface to select how
2842: # to repair student provided info
2843: # Expected errors include
2844: # 1 bad/no stuid/username
2845: # 2 invalid bubblings
2846: # }
2847: # if delay queue exists 2 submits one to process delayed students one
2848: # to ignore delayed students, possibly saving the delay queue for later
2849:
2850: }
2851: #-------- end of section for handling grading scantron forms -------
2852: #
2853: #-------------------------------------------------------------------
2854:
2855:
1.72 ng 2856: #-------------------------- Menu interface -------------------------
2857: #
2858: #--- Show a Grading Menu button - Calls the next routine ---
2859: sub show_grading_menu_form {
2860: my ($symb,$url)=@_;
2861: my $result.='<form action="/adm/grades" method="post">'."\n".
2862: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
2863: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.77 ! ng 2864: '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72 ng 2865: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
2866: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
2867: '</form>'."\n";
2868: return $result;
2869: }
2870:
1.77 ! ng 2871: # -- Retrieve choices for grading form
! 2872: sub savedState {
! 2873: my %savedState = ();
! 2874: if ($ENV{'form.saveState'}) {
! 2875: foreach (split(/:/,$ENV{'form.saveState'})) {
! 2876: my ($key,$value) = split(/=/,$_,2);
! 2877: $savedState{$key} = $value;
! 2878: }
! 2879: }
! 2880: return \%savedState;
! 2881: }
1.76 ng 2882:
1.72 ng 2883: #--- Displays the main menu page -------
2884: sub gradingmenu {
2885: my ($request) = @_;
2886: my ($symb,$url)=&get_symb_and_url($request);
2887: if (!$symb) {return '';}
1.76 ng 2888: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 2889:
2890: $request->print(<<GRADINGMENUJS);
2891: <script type="text/javascript" language="javascript">
2892: function checkChoice(formname) {
2893: var cmd = formname.command;
1.77 ! ng 2894: formname.saveState.value = "saveCmd="+radioSelection(cmd)+":saveSec="+pullDownSelection(formname.section)+
! 2895: ":saveSub="+radioSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.status);
1.76 ng 2896: if (cmd[0].checked || cmd[1].checked || cmd[2].checked || cmd[4].checked) formname.submit();
1.72 ng 2897:
1.76 ng 2898: if (cmd[3].checked) browseAndUpload();
1.72 ng 2899:
1.75 albertel 2900: if (cmd[5].checked) {
1.72 ng 2901: if (!checkReceiptNo(formname,'notOK')) { return false;}
2902: formname.submit();
2903: }
2904: }
2905:
2906: function checkReceiptNo(formname,nospace) {
2907: var receiptNo = formname.receipt.value;
2908: var checkOpt = false;
2909: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
2910: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
2911: if (checkOpt) {
2912: alert("Please enter a receipt number given by a student in the receipt box.");
2913: formname.receipt.value = "";
2914: formname.receipt.focus();
2915: return false;
2916: }
1.76 ng 2917: formname.command[5].checked = true;
1.72 ng 2918: return true;
2919: }
2920:
2921: function radioSelection(radioButton) {
2922: var selection=null;
1.76 ng 2923: if (radioButton.length > 1) {
2924: for (var i=0; i<radioButton.length; i++) {
2925: if (radioButton[i].checked) {
2926: return radioButton[i].value;
2927: }
1.72 ng 2928: }
1.76 ng 2929: } else {
2930: if (radioButton.checked) return radioButton.value;
1.72 ng 2931: }
2932: return selection;
2933: }
1.68 ng 2934:
1.72 ng 2935: function pullDownSelection(selectOne) {
2936: var selection="";
1.76 ng 2937: if (selectOne.length > 1) {
2938: for (var i=0; i<selectOne.length; i++) {
2939: if (selectOne[i].selected) {
2940: return selectOne[i].value;
2941: }
1.72 ng 2942: }
1.76 ng 2943: } else {
2944: if (selectOne.selected) return selectOne.value;
1.72 ng 2945: }
2946: }
1.76 ng 2947:
2948: function browseAndUpload() {
2949: bNLoad = window.open('', 'BrowseAndUpload', 'toolbar=no,location=no,scrollbars=no,width=550,height=200,screenx=100,screeny=75');
2950: bNLoad.focus();
2951: var lDoc = bNLoad.document;
2952: lDoc.write("<html><head>");
2953: lDoc.write("<title>Browse And Upload</title>");
2954:
2955: lDoc.write("<script language=javascript>");
2956: lDoc.write("function checkUpload(formname) {");
2957:
2958: lDoc.write(" if (formname.upfile.value == \\"\\") {");
2959: lDoc.write(" alert(\\"Please use the browse button to select a file from your local directory.\\");");
2960: lDoc.write(" return false;");
2961: lDoc.write(" }");
1.77 ! ng 2962: lDoc.write(" var openformname = opener.document.gradingMenu;");
! 2963: lDoc.write(" formname.saveState.value = \\"saveCmd=\\"+opener.radioSelection(openformname.command)+\\":saveSec=\\"+opener.pullDownSelection(openformname.section)+\\":saveSub=\\"+opener.radioSelection(openformname.submitonly)+\\":saveStatus=\\"+opener.pullDownSelection(openformname.status);");
1.76 ng 2964: lDoc.write(" document.gradesupload.submit();");
1.77 ! ng 2965: lDoc.write(" if (navigator.appName !=\\"Netscape\\") {self.close()};");
1.76 ng 2966: lDoc.write(" setTimeout('self.close()',750)");
2967: lDoc.write("}");
2968:
2969: lDoc.write("<");
2970: lDoc.write("/script>");
2971:
2972: lDoc.write("</head><body bgcolor=white>");
2973: lDoc.write("<form method=\\"post\\" enctype=\\"multipart/form-data\\" action=\\"/adm/grades\\" name=\\"gradesupload\\" target=\\"LONcatInfo\\">");
2974: lDoc.write("<input type=\\"hidden\\" name=\\"symb\\" value=\\"$symb\\">");
2975: lDoc.write("<input type=\\"hidden\\" name=\\"url\\" value=\\"$url\\">");
2976: lDoc.write("<input type=\\"hidden\\" name=\\"probTitle\\" value=\\"$probTitle\\">");
1.77 ! ng 2977: lDoc.write("<input type=\\"hidden\\" name=\\"saveState\\" value=\\"\\">");
1.76 ng 2978: lDoc.write("<input type=\\"hidden\\" name=\\"command\\" value=\\"csvuploadmap\\">");
2979:
1.77 ! ng 2980: lDoc.write("<font color=\\"green\\" size=+1> <b>Specify a file containing the class scores for problem - $probTitle</b></font><br><br>");
1.76 ng 2981:
2982: lDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
2983: lDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
2984: lDoc.write("<td>");
2985: lDoc.write("<input type=\\"file\\" name=\\"upfile\\" size=\\"50\\" />");
2986: lDoc.write("<br />Type: <select name=\\"upfiletype\\">");
2987: lDoc.write("<option value=\\"csv\\">CSV (comma separated values, spreadsheet)</option>");
2988: lDoc.write("<option value=\\"space\\">Space separated</option>");
2989: lDoc.write("<option value=\\"tab\\">Tabulator separated</option>");
2990: lDoc.write("<option value=\\"xml\\">HTML/XML</option>");
2991: lDoc.write("</select>");
2992: lDoc.write("</td></tr></table>");
2993: lDoc.write("</td></tr></table> ");
2994: lDoc.write("<input type=\\"button\\" value=\\"Upload Scores\\" onClick=\\"javascript:checkUpload(this.form)\\"> ");
2995: lDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
2996: lDoc.write("</form>");
2997: lDoc.write("</body></html>");
2998: }
1.72 ng 2999: </script>
3000: GRADINGMENUJS
3001:
3002: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>'.
3003: '<table border="0">'.
1.76 ng 3004: '<tr><td colspan=3><font size=+1><b>Problem: </b>'.$probTitle.'</font></td></tr>'."\n";
1.72 ng 3005: my ($partlist,$handgrade) = &response_type($url);
3006: my ($resptype,$hdgrade)=('','no');
3007: for (sort keys(%$handgrade)) {
3008: my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
3009: $resptype = $responsetype;
3010: $hdgrade = $handgrade if ($handgrade eq 'yes');
3011: $result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
3012: '<td><b>Type: </b>'.$responsetype.'</td>'.
3013: '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
3014: }
1.76 ng 3015: $result.='</table>'."\n";
1.72 ng 3016:
1.76 ng 3017: my (undef,$sections) = &getclasslist('all','0');
1.77 ! ng 3018: my $savedState = &savedState();
! 3019: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'pickStudentPage' : $$savedState{'saveCmd'});
! 3020: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
! 3021: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'yes' : $$savedState{'saveSub'});
! 3022: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 3023:
3024: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
3025: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
3026: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3027: '<input type="hidden" name="response" value="'.$resptype.'" />'."\n".
3028: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
3029: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.77 ! ng 3030: '<input type="hidden" name="saveState" value="" />'."\n".
1.72 ng 3031: '<input type="hidden" name="showgrading" value="yes" />'."\n";
3032:
3033: $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n".
3034: '<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n".
3035: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
3036: '<tr bgcolor=#ffffe6><td>'."\n";
3037:
3038: $result.='<table width=100% border=0>'.
3039: '<tr bgcolor="#ffffe6" valign="top"><td colspan="2">'.
3040: '<input type="radio" name="command" value="pickStudentPage" '.
1.76 ng 3041: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
1.72 ng 3042: 'Handgrade/View Submission for a student by page/sequence</td></tr>'."\n".
3043:
3044: '<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
3045: '<input type="radio" name="command" value="viewgrades" '.
1.76 ng 3046: ($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
1.72 ng 3047: 'Grade by section or class</td></tr>'."\n".
3048:
3049: '<tr bgcolor="#ffffe6"valign="top"><td><input type="radio" name="command" value="submission" '.
1.76 ng 3050: ($saveCmd eq 'submission' ? 'checked' : '').'> '.
1.72 ng 3051: ($hdgrade eq 'yes' ? 'View/Grade essay response of' : 'View').
3052: ' an individual student </td>'."\n".
3053: '<td>--> For students who has: '.
1.76 ng 3054: '<input type="radio" name="submitonly" value="yes" '.
3055: ($saveSub eq 'yes' ? 'checked' : '').' /> submitted'.
3056: '<input type="radio" name="submitonly" value="all" '.
3057: ($saveSub eq 'all' ? 'checked' : '').' /> everybody</td></tr>'."\n".
1.46 ng 3058:
1.72 ng 3059: '<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
3060: '<input type="radio" name="command" value="csvupload" '.
1.76 ng 3061: ($saveCmd eq 'csvupload' ? 'checked' : '').'> '.
1.72 ng 3062: 'Upload scores from file</td></tr>'."\n";
3063:
1.75 albertel 3064: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
3065: '<input type="radio" name="command" value="scantron_selectphase" /> '.
3066: 'Grade scantron forms</td></tr>'."\n";
3067:
1.72 ng 3068: if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)) {
3069: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.76 ng 3070: '<input type="radio" name="command" value="verify" onChecked="javascript:this.form.receipt.focus()" '.
3071: ($saveCmd eq 'verify' ? 'checked' : '').'> '.
1.72 ng 3072: 'Verify a submission receipt issued by this server</td>'.
3073: '<td>--> Receipt no: '.unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).
3074: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
3075: '</td></tr>'."\n";
3076: }
1.44 ng 3077:
1.72 ng 3078: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2"><br />'."\n".
1.76 ng 3079: ' Select section: <select name="section">'."\n";
1.72 ng 3080: if (ref($sections)) {
3081: foreach (sort (@$sections)) {$result.='<option value="'.$_.'" '.
1.76 ng 3082: ($saveSec eq $_ ? 'selected="on"' : '').'>'.$_.'</option>'."\n";}
1.44 ng 3083: }
1.76 ng 3084: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</select> ';
3085:
3086: $result.='Student Status:</b><select name="status">'.
3087: '<option value="Active" '.($saveStatus eq 'Active' ? 'selected' : '').'>Active</option>'.
3088: '<option value="Expired" '.($saveStatus eq 'Expired' ? 'selected' : '').'>Expired</option>'.
3089: '<option value="Any" '.($saveStatus eq 'Any' ? 'selected' : '').'>Any</option>'.
3090: '</select>';
3091:
3092: $result.=' <font color="red">(Applies to the first three options only.)</font>'."\n";
3093:
1.72 ng 3094: if (ref($sections)) {
3095: $result.=' (Section "no" implies the students were not assigned a section.)<br />'
3096: if (grep /no/,@$sections);
1.44 ng 3097: }
1.72 ng 3098: $result.='</td></tr>';
3099:
3100: $result.='<tr bgcolor="#ffffe6"><td colspan="2"><br />'.
3101: '<input type="button" onClick="javascript:checkChoice(this.form);" value="View/Grade" />'."\n".
3102: '</form></td></tr></table>'."\n".
3103: '</td></tr></table>'."\n".
3104: '</td></tr></table>'."\n";
1.44 ng 3105: return $result;
1.2 albertel 3106: }
3107:
1.1 albertel 3108: sub handler {
1.41 ng 3109: my $request=$_[0];
3110:
3111: if ($ENV{'browser.mathml'}) {
3112: $request->content_type('text/xml');
3113: } else {
3114: $request->content_type('text/html');
3115: }
3116: $request->send_http_header;
1.44 ng 3117: return '' if $request->header_only;
1.41 ng 3118: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
3119: my $url=$ENV{'form.url'};
3120: my $symb=$ENV{'form.symb'};
3121: my $command=$ENV{'form.command'};
3122: if (!$url) {
3123: my ($temp1,$temp2);
3124: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
3125: $url = $ENV{'form.url'};
3126: }
3127: &send_header($request);
3128: if ($url eq '' && $symb eq '') {
3129: if ($ENV{'user.adv'}) {
3130: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
3131: ($ENV{'form.codethree'})) {
3132: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
3133: $ENV{'form.codethree'};
3134: my ($tsymb,$tuname,$tudom,$tcrsid)=
3135: &Apache::lonnet::checkin($token);
3136: if ($tsymb) {
3137: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
3138: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
3139: $request->print(
3140: &Apache::lonnet::ssi('/res/'.$url,
3141: ('grade_username' => $tuname,
3142: 'grade_domain' => $tudom,
3143: 'grade_courseid' => $tcrsid,
3144: 'grade_symb' => $tsymb)));
3145: } else {
1.45 ng 3146: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.41 ng 3147: }
3148: } else {
1.45 ng 3149: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 3150: }
1.14 www 3151: } else {
1.41 ng 3152: $request->print(&Apache::lonxml::tokeninputfield());
3153: }
3154: }
3155: } else {
3156: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
3157: if ($command eq 'submission') {
1.68 ng 3158: ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
3159: } elsif ($command eq 'pickStudentPage') {
3160: &pickStudentPage($request);
3161: } elsif ($command eq 'displayPage') {
3162: &displayPage($request);
1.71 ng 3163: } elsif ($command eq 'gradeByPage') {
3164: &updateGradeByPage($request);
1.41 ng 3165: } elsif ($command eq 'processGroup') {
3166: &processGroup($request);
3167: } elsif ($command eq 'gradingmenu') {
3168: $request->print(&gradingmenu($request));
3169: } elsif ($command eq 'viewgrades') {
3170: $request->print(&viewgrades($request));
3171: } elsif ($command eq 'handgrade') {
3172: $request->print(&processHandGrade($request));
3173: } elsif ($command eq 'editgrades') {
3174: $request->print(&editgrades($request));
3175: } elsif ($command eq 'verify') {
3176: $request->print(&verifyreceipt($request));
1.72 ng 3177: } elsif ($command eq 'csvform') {
3178: $request->print(&upcsvScores_form($request));
1.41 ng 3179: } elsif ($command eq 'csvupload') {
3180: $request->print(&csvupload($request));
3181: } elsif ($command eq 'viewclasslist') {
3182: $request->print(&viewclasslist($request));
3183: } elsif ($command eq 'csvuploadmap') {
3184: $request->print(&csvuploadmap($request));
3185: } elsif ($command eq 'csvuploadassign') {
3186: if ($ENV{'form.associate'} ne 'Reverse Association') {
3187: $request->print(&csvuploadassign($request));
3188: } else {
3189: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
3190: $ENV{'form.upfile_associate'} = 'reverse';
3191: } else {
3192: $ENV{'form.upfile_associate'} = 'forward';
3193: }
3194: $request->print(&csvuploadmap($request));
3195: }
1.75 albertel 3196: } elsif ($command eq 'scantron_selectphase') {
3197: $request->print(&scantron_selectphase($request));
3198: } elsif ($command eq 'scantron_configphase') {
3199: $request->print(&scantron_configphase($request));
1.26 albertel 3200: } else {
1.41 ng 3201: $request->print("Unknown action: $command:");
1.26 albertel 3202: }
1.2 albertel 3203: }
1.41 ng 3204: &send_footer($request);
1.44 ng 3205: return '';
3206: }
3207:
3208: sub send_header {
3209: my ($request)= @_;
3210: $request->print(&Apache::lontexconvert::header());
3211: # $request->print("
3212: #<script>
3213: #remotewindow=open('','homeworkremote');
3214: #remotewindow.close();
3215: #</script>");
1.47 www 3216: $request->print(&Apache::loncommon::bodytag('Grading'));
1.44 ng 3217: }
3218:
3219: sub send_footer {
3220: my ($request)= @_;
3221: $request->print('</body>');
3222: $request->print(&Apache::lontexconvert::footer());
1.1 albertel 3223: }
3224:
3225: 1;
3226:
1.13 albertel 3227: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>