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