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