Annotation of loncom/homework/grades.pm, revision 1.26
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.26 ! albertel 4: # $Id: grades.pm,v 1.25 2002/05/16 00:01:09 albertel Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.13 albertel 28: # 2/9,2/13 Guy Albertelli
1.8 www 29: # 6/8 Gerd Kortemeyer
1.13 albertel 30: # 7/26 H.K. Ng
1.14 www 31: # 8/20 Gerd Kortemeyer
1.1 albertel 32:
33: package Apache::grades;
34: use strict;
35: use Apache::style;
36: use Apache::lonxml;
37: use Apache::lonnet;
1.3 albertel 38: use Apache::loncommon;
1.1 albertel 39: use Apache::lonhomework;
40: use Apache::Constants qw(:common);
41:
1.2 albertel 42: sub moreinfo {
1.13 albertel 43: my ($request,$reason) = @_;
44: $request->print("Unable to process request: $reason");
45: if ( $Apache::grades::viewgrades eq 'F' ) {
46: $request->print('<form action="/adm/grades" method="post">'."\n");
1.16 albertel 47: if ($ENV{'form.url'}) {
48: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
49: }
50: if ($ENV{'form.symb'}) {
51: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
52: }
53: $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
54: $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
55: $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
56: $request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
1.13 albertel 57: $request->print('</form>');
58: }
59: return '';
1.2 albertel 60: }
61:
1.23 www 62: sub verifyreceipt {
63: my $request=shift;
64: my $courseid=$ENV{'request.course.id'};
65: my $cdom=$ENV{"course.$courseid.domain"};
66: my $cnum=$ENV{"course.$courseid.num"};
67: my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
68: $ENV{'form.receipt'};
69: $receipt=~s/[^\-\d]//g;
70: my $symb=$ENV{'form.symb'};
71: unless ($symb) {
72: $symb=&Apache::lonnet::symbread($ENV{'form.url'});
73: }
74: if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
75: $request->print('<h1>Verifying Submission Receipt '.$receipt.'</h1>');
76: my $matches=0;
1.24 albertel 77: my (%classlist) = &getclasslist($cdom,$cnum,'0');
1.23 www 78: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
79: my ($uname,$udom)=split(/\:/,$student);
80: if ($receipt eq
81: &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
82: $request->print('Matching '.$student.'<br>');
83: $matches++;
84: }
85: }
86: $request->print('<p>'.$matches.' match(es)</p>');
87: }
88: return '';
89: }
1.13 albertel 90:
1.10 ng 91: sub listStudents {
1.13 albertel 92: my ($request) = shift;
1.23 www 93: my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
94: my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
95: my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
96: $request->print(<<ENDHEADER);
97: <h1>Verify a Submission Receipt Issued by this Server</h1>
98: <form action="/adm/grades" method="post">
99: <tt>$hostver-<input type="text" name="receipt" size="4"></tt>
100: <input type="submit" name="submit" value="Verify">
101: <input type="hidden" name="command" value="verify">
102: ENDHEADER
103: if ($ENV{'form.url'}) {
104: $request->print(
105: '<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />');
106: }
107: if ($ENV{'form.symb'}) {
108: $request->print(
109: '<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />');
110: }
111: $request->print(<<ENDTABLEST);
112: </form>
113: <h1>Show Student Submissions on Assessment</h1>
114: <table border="1">
115: <tr><th>Username</th><th>Domain</th><th>Name</th><th> </th></tr>
116: ENDTABLEST
1.24 albertel 117: my (%classlist) = &getclasslist($cdom,$cnum,'0');
1.13 albertel 118: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
119: my ($sname,$sdom) = split(/:/,$student);
120:
1.25 albertel 121: my %name=&Apache::lonnet::get('environment', ['lastname','generation',
122: 'firstname','middlename'],
123: $sdom,$sname);
124: my $fullname;
125: my ($tmp) = keys(%name);
126: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
127: $fullname=$name{'lastname'}.$name{'generation'};
128: if ($fullname =~ /[^\s]+/) { $fullname.=','; }
129: $fullname.=$name{'firstname'}.' '.$name{'middlename'};
130: }
1.13 albertel 131: if ( $Apache::grades::viewgrades eq 'F' ) {
1.25 albertel 132: $request->print("\n".'<tr>'."<td>$sname</td><td>$sdom</td><td>$fullname</td><td>".
1.21 albertel 133: '<form action="/adm/grades" method="post">');
1.16 albertel 134: if ($ENV{'form.url'}) {
1.19 www 135: $request->print(
136: '<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />');
1.16 albertel 137: }
138: if ($ENV{'form.symb'}) {
1.19 www 139: $request->print(
140: '<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />');
1.16 albertel 141: }
1.19 www 142: $request->print(
143: '<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />');
144: $request->print(
145: '<input type="hidden" name="student" value="'.$sname.'" />');
146: $request->print(
147: '<input type="hidden" name="domain" value="'.$sdom.'" />');
148: $request->print(
149: '<input type="submit" name="submit" value="View" />');
1.21 albertel 150: $request->print('</form></td></tr>');
1.13 albertel 151: }
152: }
1.19 www 153: $request->print('</table>');
1.10 ng 154: }
155:
1.13 albertel 156:
1.7 albertel 157: #FIXME - needs to handle multiple matches
1.2 albertel 158: sub finduser {
1.13 albertel 159: my ($name) = @_;
160: my $domain = '';
161:
162: if ( $Apache::grades::viewgrades eq 'F' ) {
163: #get classlist
164: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 165: #print "Found $cdom:$cnum<br />";
166: my (%classlist) = &getclasslist($cdom,$cnum,'0');
1.13 albertel 167: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
168: my ($posname,$posdomain) = split(/:/,$student);
169: if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
1.7 albertel 170: }
1.13 albertel 171: return ($name,$domain);
172: } else {
173: return ($ENV{'user.name'},$ENV{'user.domain'});
174: }
1.5 albertel 175: }
176:
177: sub getclasslist {
1.24 albertel 178: my ($coursedomain,$coursenum,$hideexpired) = @_;
179: my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
1.13 albertel 180: my $now = time;
1.24 albertel 181: foreach my $student (keys(%classlist)) {
182: my ($end,$start)=split(/:/,$classlist{$student});
1.13 albertel 183: # still a student?
184: if (($hideexpired) && ($end) && ($end < $now)) {
1.15 albertel 185: #print "Skipping:$name:$end:$now<br />\n";
1.13 albertel 186: next;
187: }
1.15 albertel 188: #print "record=$record<br>";
1.24 albertel 189: push( @{ $classlist{'allids'} }, $student);
1.13 albertel 190: }
191: return (%classlist);
1.5 albertel 192: }
193:
194: sub getpartlist {
1.13 albertel 195: my ($url) = @_;
196: my @parts =();
197: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
198: foreach my $key (@metakeys) {
199: if ( $key =~ m/stores_([0-9]+)_.*/ ) {
200: push(@parts,$key);
1.6 albertel 201: }
1.13 albertel 202: }
203: return @parts;
1.5 albertel 204: }
205:
206: sub viewstudentgrade {
1.13 albertel 207: my ($url,$symb,$courseid,$student,@parts) = @_;
208: my $result ='';
209: my $cellclr = '"#ffffdd"';
210: my ($stuname,$domain) = split(/:/,$student);
211:
212: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
213:
214: $result.="<tr><td bgcolor=$cellclr>$stuname</td><td bgcolor=$cellclr align=\"middle\">$domain</td>\n";
215: foreach my $part (@parts) {
216: my ($temp,$part,$type)=split(/_/,$part);
217: #print "resource.$part.$type = ".$record{"resource.$part.$type"}." <br />\n";
218: if ($type eq 'awarded') {
219: my $score=$record{"resource.$part.$type"};
220: $result.="<td bgcolor=$cellclr align=\"middle\"><input type=\"text\" name=\"GRADE.$student.$part.$type\" value=\"$score\" size=\"4\" /></td>\n";
221: } elsif ($type eq 'tries') {
222: my $score=$record{"resource.$part.$type"};
223: $result.="<td bgcolor=$cellclr align=\"middle\"><input type=\"text\" name=\"GRADE.$student.$part.$type\" value=\"$score\" size=\"4\" /></td>\n"
224: } elsif ($type eq 'solved') {
225: my $score=$record{"resource.$part.$type"};
226: $result.="<td bgcolor=$cellclr align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";
227: if ($score =~ /^correct/) {
228: $result.="<option selected=\"on\">correct</option>\n<option>incorrect</option>\n<option>excused</option>\n<option>ungraded</option>\n<option>nothing</option>\n";
229: } elsif ($score =~ /^incorrect/) {
230: $result.="<option>correct</option>\n<option selected=\"on\">incorrect</option>\n<option>excused</option>\n<option>ungraded</option>\n<option>nothing</option>\n";
231: } elsif ($score eq '') {
232: $result.="<option>correct</option>\n<option>incorrect</option>\n<option>excused</option>\n<option>ungraded</option>\n<option selected=\"on\">nothing</option>\n";
233: } elsif ($score =~ /^excused/) {
234: $result.="<option>correct</option>\n<option>incorrect</option>\n<option selected=\"on\">excused</option>\n<option>ungraded</option>\n<option>nothing</option>\n";
235: } elsif ($score =~ /^ungraded/) {
236: $result.="<option>correct</option>\n<option>incorrect</option>\n<option>excused</option>\n<option selected=\"on\">ungraded</option>\n<option>nothing</option>\n";
237: }
238: $result.="</select></td>\n";
239: }
240: }
241: $result.='</tr>';
242: return $result;
1.5 albertel 243: }
1.13 albertel 244: #FIXME need to look at the meatdata <stores> spec on what type of data to accept and provide an
1.6 albertel 245: #interface based on that, also do that to above function.
1.5 albertel 246: sub setstudentgrade {
1.13 albertel 247: my ($url,$symb,$courseid,$student,@parts) = @_;
248:
249: my $result ='';
250:
251: my ($stuname,$domain) = split(/:/,$student);
252:
253: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
254:
255: my %newrecord;
256:
257: foreach my $part (@parts) {
258: my ($temp,$part,$type)=split(/_/,$part);
259: my $oldscore=$record{"resource.$part.$type"};
260: my $newscore=$ENV{"form.GRADE.$student.$part.$type"};
261: if ($type eq 'solved') {
262: my $update=0;
263: if ($newscore eq 'nothing' ) {
264: if ($oldscore ne '') {
265: $update=1;
266: $newscore = '';
1.6 albertel 267: }
1.13 albertel 268: } elsif ($oldscore !~ m/^$newscore/) {
269: $update=1;
270: $result.="Updating $stuname to $newscore<br />\n";
271: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
272: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
273: if ($newscore eq 'excused') { $newscore = 'excused'; }
274: if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
275: } else {
276: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
277: }
278: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
279: } else {
280: if ($oldscore ne $newscore) {
281: $newrecord{"resource.$part.$type"}=$newscore;
282: $result.="Updating $student"."'s status for $part.$type to $newscore<br />\n";
283: } else {
284: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
285: }
286: }
287: }
288: if ( scalar(keys(%newrecord)) > 0 ) {
289: $newrecord{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
290: &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
291:
292: $result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
293: }
294: return $result;
1.2 albertel 295: }
296:
297: sub submission {
1.13 albertel 298: my ($request) = @_;
299: my $url=$ENV{'form.url'};
300: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
301: if ($ENV{'form.student'} eq '') { &moreinfo($request,"Need student login id"); return ''; }
1.10 ng 302: # if ($ENV{'form.student'} eq '') { &listStudents($request); return ''; }
1.13 albertel 303: my ($uname,$udom) = &finduser($ENV{'form.student'});
304: if ($uname eq '') { &moreinfo($request,"Unable to find student"); return ''; }
1.16 albertel 305: my $symb;
306: if ($ENV{'form.symb'}) {
307: $symb=$ENV{'form.symb'};
308: } else {
309: $symb=&Apache::lonnet::symbread($url);
310: }
1.13 albertel 311: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
312: my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
313: $ENV{'request.course.id'});
314: my $result="<h2> Submission Record </h2> $uname:$udom for $url <br />".$answer;
1.17 albertel 315: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
316: $ENV{'request.course.id'});
1.22 albertel 317: $result.="Student's view of the problem:<br /> $rendered <br /> Correct answer:<br />";
1.18 albertel 318:
1.22 albertel 319: $answer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
1.18 albertel 320: $ENV{'request.course.id'});
321: $result.=$answer;
1.13 albertel 322: return $result;
1.2 albertel 323: }
324:
1.26 ! albertel 325: sub get_symb_and_url {
! 326: my ($request) = @_;
1.13 albertel 327: my $url=$ENV{'form.url'};
328: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
329: my $symb=$ENV{'form.symb'};
330: if (!$symb) { $symb=&Apache::lonnet::symbread($url); }
331: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.26 ! albertel 332: return ($symb,$url);
! 333: }
1.13 albertel 334:
1.26 ! albertel 335: sub gradingmenu {
! 336: my ($request) = @_;
! 337: my ($symb,$url)=&get_symb_and_url($request);
! 338: if (!$symb) {return '';}
! 339: my $result='<h2>Select a grading method</h2><br />';
! 340: $result.='<form action="/adm/grades" method="post">'."\n".
! 341: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
! 342: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
! 343: '<input type="hidden" name="command" value="viewgrades" />'."\n".
! 344: '<input type="submit" name="submit" value="View/Edit Entire Class" />'."\n".
! 345: '</form>';
! 346: $result.='<form action="/adm/grades" method="post">'."\n".
! 347: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
! 348: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
! 349: '<input type="hidden" name="command" value="csvupload" />'."\n".
! 350: '<input type="submit" name="submit" value="Upload Scores" />'."\n".
! 351: '</form>';
! 352: $result.='<form action="/adm/grades" method="post">'."\n".
! 353: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
! 354: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
! 355: '<input type="hidden" name="command" value="submission" />'."\n".
! 356: '<input type="submit" name="submit" value="View/Edit Student" />'."\n".
! 357: '</form>';
! 358: return $result;
! 359: }
! 360:
! 361: sub viewgrades {
! 362: my ($request) = @_;
! 363: my $result='';
! 364:
! 365: #get resource reference
! 366: my ($symb,$url)=&get_symb_and_url($request);
! 367: if (!$symb) {return '';}
1.13 albertel 368: #get classlist
369: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 370: #print "Found $cdom:$cnum<br />";
371: my (%classlist) = &getclasslist($cdom,$cnum,'0');
1.13 albertel 372: my $headerclr = '"#ccffff"';
373: my $cellclr = '"#ffffcc"';
374:
375: #get list of parts for this problem
376: my (@parts) = &getpartlist($url);
377:
378: $request->print ("<h2><font color=\"#339966\">Manual Grading</font></h2>");
379:
380: #start the form
381: $result = '<form action="/adm/grades" method="post">'."\n".
1.16 albertel 382: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
383: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.13 albertel 384: '<input type="hidden" name="command" value="editgrades" />'."\n".
385: '<input type="submit" name="submit" value="Submit Changes" />'."\n".
386: '<table border=0><tr><td bgcolor="#999999">'."\n".
387: '<table border=0>'."\n".
388: '<tr><td bgcolor='.$headerclr.'>UserId</td><td bgcolor='.$headerclr.'>Domain</td>'."\n";
389: foreach my $part (@parts) {
390: my $display=&Apache::lonnet::metadata($url,$part.'.display');
391: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
392: $result.='<td bgcolor='.$headerclr.'>'.$display.'</td>'."\n";
393: }
394: $result.="</tr>";
395: #get info for each student
396: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
397: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
398: }
399: $result.='</table></td></tr></table><input type="submit" name="submit" value="Submit Changes" /></form>';
1.5 albertel 400:
1.13 albertel 401: return $result;
1.5 albertel 402: }
403:
404: sub editgrades {
1.13 albertel 405: my ($request) = @_;
406: my $result='';
1.5 albertel 407:
1.13 albertel 408: my $symb=$ENV{'form.symb'};
409: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
410: my $url=$ENV{'form.url'};
411: #get classlist
412: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
1.24 albertel 413: #print "Found $cdom:$cnum<br />";
414: my (%classlist) = &getclasslist($cdom,$cnum,'0');
1.13 albertel 415:
416: #get list of parts for this problem
417: my (@parts) = &getpartlist($url);
418:
419: $result.='<form action="/adm/grades" method="post">'."\n".
420: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
421: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
422: '<input type="hidden" name="command" value="viewgrades" />'."\n".
423: '<input type="submit" name="submit" value="See Grades" /> <br />'."\n";
424:
425: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
426: $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
427: }
1.5 albertel 428:
1.13 albertel 429: $result.='<input type="submit" name="submit" value="See Grades" /></table></form>';
430: return $result;
1.5 albertel 431: }
432:
1.26 ! albertel 433: sub csvupload {
! 434: my ($request)= @_;
! 435: my $result;
! 436: my ($symb,$url)=&get_symb_and_url($request);
! 437: if (!$symb) {return '';}
! 438: my $upfile_select=&Apache::loncommon::upfile_select_html();
! 439: $result.=<<ENDUPFORM;
! 440: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
! 441: <input type="hidden" name="symb" value="$symb" />
! 442: <input type="hidden" name="url" value="$url" />
! 443: <input type="hidden" name="command" value="csvuploadmap" />
! 444: <hr />
! 445: <h3>Specify a file containing the class grades for resource $url</h3>
! 446: $upfile_select
! 447: <p><input type="submit" name="submit" value="Upload Grades" />
! 448: ENDUPFORM
! 449: return $result;
! 450: }
! 451:
! 452: sub csvuploadmap_header {
! 453: my ($request,$symb,$url,$datatoken,$distotal)= @_;
! 454: my $result;
! 455: my $javascript;
! 456: if ($ENV{'form.upfile_associate'} eq 'reverse') {
! 457: # $javascript=&csv_upload_javascript_reverse_associate();
! 458: } else {
! 459: # $javascript=&csv_upload_javascript_forward_associate();
! 460: }
! 461: my $javascript_validations;#=&javascript_validations($krbdefdom);
! 462: $request->print(<<ENDPICK);
! 463: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
! 464: <h3>Uploading Class Grades for resource $url</h3>
! 465: <hr>
! 466: <h3>Identify fields</h3>
! 467: Total number of records found in file: $distotal <hr />
! 468: Enter as many fields as you can. The system will inform you and bring you back
! 469: to this page if the data selected is insufficient to run your class.<hr />
! 470: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
! 471: <input type="hidden" name="associate" value="" />
! 472: <input type="hidden" name="phase" value="three" />
! 473: <input type="hidden" name="datatoken" value="$datatoken" />
! 474: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
! 475: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
! 476: <input type="hidden" name="upfile_associate"
! 477: value="$ENV{'form.upfile_associate'}" />
! 478: <input type="hidden" name="symb" value="$symb" />
! 479: <input type="hidden" name="url" value="$url" />
! 480: <input type="hidden" name="command" value="csvuploadassign" />
! 481: <hr />
! 482: <script type="text/javascript" language="Javascript">
! 483: $javascript
! 484: $javascript_validations
! 485: </script>
! 486: ENDPICK
! 487: return '';
! 488:
! 489: }
! 490:
! 491: sub csvupload_fields {
! 492: my ($url) = @_;
! 493: my (@parts) = &getpartlist($url);
! 494: my @fields;
! 495: foreach my $part (@parts) {
! 496: my @datum;
! 497: my $display=&Apache::lonnet::metadata($url,$part.'.display');
! 498: my $name=&Apache::lonnet::metadata($url,$part.'.name');
! 499: if (!$display) { $display = $name; }
! 500: @datum=($name,$display);
! 501: push(@fields,\@datum);
! 502: }
! 503: return (@fields);
! 504: }
! 505:
! 506: sub csvuploadmap_footer {
! 507: my ($request,$i,$keyfields) =@_;
! 508: $request->print(<<ENDPICK);
! 509: </table>
! 510: <input type="hidden" name="nfields" value="$i" />
! 511: <input type="hidden" name="keyfields" value="$keyfields" />
! 512: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
! 513: </form>
! 514: ENDPICK
! 515: }
! 516:
! 517: sub csvuploadmap {
! 518: my ($request)= @_;
! 519: my ($symb,$url)=&get_symb_and_url($request);
! 520: if (!$symb) {return '';}
! 521: my $datatoken;
! 522: if (!$ENV{'form.datatoken'}) {
! 523: $datatoken=&Apache::loncommon::upfile_store($request);
! 524: } else {
! 525: $datatoken=$ENV{'form.datatoken'};
! 526: &Apache::loncommon::load_tmp_file($request);
! 527: }
! 528: my @records=&Apache::loncommon::upfile_record_sep();
! 529: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
! 530: my $i;
! 531: my $keyfields;
! 532: if (@records) {
! 533: my @fields=&csvupload_fields($url);
! 534: if ($ENV{'form.upfile_associate'} eq 'reverse') {
! 535: &Apache::loncommon::csv_print_samples($request,\@records);
! 536: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
! 537: \@fields);
! 538: foreach (@fields) { $keyfields.=$_->[0].','; }
! 539: chop($keyfields);
! 540: } else {
! 541: unshift(@fields,['none','']);
! 542: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
! 543: \@fields);
! 544: my %sone=&Apache::loncommon::record_sep($records[0]);
! 545: $keyfields=join(',',sort(keys(%sone)));
! 546: }
! 547: }
! 548: &csvuploadmap_footer($request,$i,$keyfields);
! 549: return '';
! 550: }
! 551:
1.2 albertel 552: sub send_header {
1.13 albertel 553: my ($request)= @_;
554: $request->print(&Apache::lontexconvert::header());
1.6 albertel 555: # $request->print("
556: #<script>
557: #remotewindow=open('','homeworkremote');
558: #remotewindow.close();
559: #</script>");
1.13 albertel 560: $request->print('<body bgcolor="#FFFFFF">');
1.2 albertel 561: }
562:
563: sub send_footer {
1.13 albertel 564: my ($request)= @_;
1.2 albertel 565: $request->print('</body>');
566: $request->print(&Apache::lontexconvert::footer());
567: }
568:
1.1 albertel 569: sub handler {
1.13 albertel 570: my $request=$_[0];
571:
572: if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;}
573:
574: if ($ENV{'browser.mathml'}) {
575: $request->content_type('text/xml');
576: } else {
577: $request->content_type('text/html');
578: }
579: $request->send_http_header;
580: return OK if $request->header_only;
1.16 albertel 581: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.13 albertel 582: my $url=$ENV{'form.url'};
583: my $symb=$ENV{'form.symb'};
584: my $command=$ENV{'form.command'};
1.16 albertel 585: if (!$url) {
586: my ($temp1,$temp2);
587: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
588: $url = $ENV{'form.url'};
589: }
1.13 albertel 590: &send_header($request);
591: if ($url eq '' && $symb eq '') {
1.14 www 592: if ($ENV{'user.adv'}) {
593: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
594: ($ENV{'form.codethree'})) {
595: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
596: $ENV{'form.codethree'};
597: my ($tsymb,$tuname,$tudom,$tcrsid)=
598: &Apache::lonnet::checkin($token);
599: if ($tsymb) {
600: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
601: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
602: $request->print(
603: &Apache::lonnet::ssi('/res/'.$url,
604: ('grade_username' => $tuname,
605: 'grade_domain' => $tudom,
606: 'grade_courseid' => $tcrsid,
607: 'grade_symb' => $tsymb)));
608: } else {
609: $request->print('<h1>Not authorized: '.$token.'</h1>');
610: }
611: } else {
612: $request->print('<h1>Not a valid DocID: '.$token.'</h1>');
613: }
614: } else {
615: $request->print(&Apache::lonxml::tokeninputfield());
616: }
617: }
1.13 albertel 618: } else {
1.26 ! albertel 619: &Apache::lonhomework::showhashsubset(\%ENV,'^form');
1.13 albertel 620: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
621: if ($command eq 'submission') {
1.20 albertel 622: &listStudents($request) if ($ENV{'form.student'} eq '');
1.13 albertel 623: $request->print(&submission($request)) if ($ENV{'form.student'} ne '');
1.26 ! albertel 624: } elsif ($command eq 'gradingmenu') {
! 625: $request->print(&gradingmenu($request));
1.13 albertel 626: } elsif ($command eq 'viewgrades') {
627: $request->print(&viewgrades($request));
628: } elsif ($command eq 'editgrades') {
629: $request->print(&editgrades($request));
1.23 www 630: } elsif ($command eq 'verify') {
631: $request->print(&verifyreceipt($request));
1.26 ! albertel 632: } elsif ($command eq 'csvupload') {
! 633: $request->print(&csvupload($request));
! 634: } elsif ($command eq 'csvuploadmap') {
! 635: $request->print(&csvuploadmap($request));
! 636: } elsif ($command eq 'csvuploadassign') {
! 637: if ($ENV{'form.associate'} ne 'Reverse Association') {
! 638: $request->print(&csvuploadassign($request));
! 639: } else {
! 640: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
! 641: $ENV{'form.upfile_associate'} = 'reverse';
! 642: } else {
! 643: $ENV{'form.upfile_associate'} = 'forward';
! 644: }
! 645: $request->print(&csvuploadmap($request));
! 646: }
1.12 harris41 647: } else {
1.23 www 648: $request->print("Unknown action: $command:");
1.2 albertel 649: }
1.13 albertel 650: }
651: &send_footer($request);
652: return OK;
1.1 albertel 653: }
654:
655: 1;
656:
1.13 albertel 657: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>