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