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