Annotation of loncom/homework/lonhomework.pm, revision 1.230
1.63 albertel 1: # The LearningOnline Network with CAPA
1.52 albertel 2: # The LON-CAPA Homework handler
1.63 albertel 3: #
1.230 ! albertel 4: # $Id: lonhomework.pm,v 1.229 2005/12/15 23:27:22 albertel Exp $
1.63 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/
1.159 www 27:
1.1 albertel 28:
29: package Apache::lonhomework;
30: use strict;
1.73 albertel 31: use Apache::style();
32: use Apache::lonxml();
1.204 albertel 33: use Apache::lonnet;
1.73 albertel 34: use Apache::lonplot();
35: use Apache::inputtags();
36: use Apache::structuretags();
37: use Apache::randomlabel();
38: use Apache::response();
39: use Apache::hint();
40: use Apache::outputtags();
1.83 albertel 41: use Apache::caparesponse();
42: use Apache::radiobuttonresponse();
43: use Apache::optionresponse();
44: use Apache::imageresponse();
45: use Apache::essayresponse();
46: use Apache::externalresponse();
1.106 albertel 47: use Apache::rankresponse();
1.107 albertel 48: use Apache::matchresponse();
1.137 albertel 49: use Apache::chemresponse();
1.169 albertel 50: use Apache::drawimage();
1.26 www 51: use Apache::Constants qw(:common);
1.73 albertel 52: use HTML::Entities();
1.83 albertel 53: use Apache::loncommon();
1.146 albertel 54: use Apache::lonlocal;
1.179 albertel 55: use Time::HiRes qw( gettimeofday tv_interval );
1.188 foxr 56: use Apache::lonnet();
57:
1.189 albertel 58: # FIXME - improve commenting
1.188 foxr 59:
1.43 albertel 60:
1.69 harris41 61: BEGIN {
1.145 albertel 62: &Apache::lonxml::register_insert();
1.43 albertel 63: }
64:
1.188 foxr 65:
66: #
1.189 albertel 67: # Decides what targets to render for.
1.188 foxr 68: # Implicit inputs:
69: # Various session environment variables:
1.189 albertel 70: # request.state - published - is a /res/ resource
71: # uploaded - is a /uploaded/ resource
72: # contruct - is a /priv/ resource
73: # form.grade_target - a form parameter requesting a specific target
1.5 albertel 74: sub get_target {
1.204 albertel 75: &Apache::lonxml::debug("request.state = $env{'request.state'}");
76: if( defined($env{'form.grade_target'})) {
77: &Apache::lonxml::debug("form.grade_target= $env{'form.grade_target'}");
1.188 foxr 78: } else {
1.189 albertel 79: &Apache::lonxml::debug("form.grade_target <undefined>");
1.188 foxr 80: }
1.204 albertel 81: if (($env{'request.state'} eq "published") ||
82: ($env{'request.state'} eq "uploaded")) {
83: if ( defined($env{'form.grade_target'} )
84: && ($env{'form.grade_target'} eq 'tex')) {
85: return ($env{'form.grade_target'});
86: } elsif ( defined($env{'form.grade_target'} )
1.145 albertel 87: && ($Apache::lonhomework::viewgrades eq 'F' )) {
1.207 albertel 88: return ($env{'form.grade_target'});
89: }
90: if ($env{'form.webgrade'} &&
91: $Apache::lonhomework::modifygrades eq 'F') {
92: return ('grade','webgrade');
1.145 albertel 93: }
1.204 albertel 94: if ( defined($env{'form.submitted'}) &&
95: ( !defined($env{'form.resetdata'})) &&
96: ( !defined($env{'form.newrandomization'}))) {
1.217 albertel 97: return ('grade', 'web');
1.145 albertel 98: } else {
1.217 albertel 99: return ('web');
1.145 albertel 100: }
1.204 albertel 101: } elsif ($env{'request.state'} eq "construct") {
102: if ( defined($env{'form.grade_target'}) ) {
103: return ($env{'form.grade_target'});
1.145 albertel 104: }
1.204 albertel 105: if ( defined($env{'form.preview'})) {
106: if ( defined($env{'form.submitted'})) {
1.145 albertel 107: return ('grade', 'web');
108: } else {
109: return ('web');
110: }
111: } else {
1.204 albertel 112: if ( $env{'form.problemmode'} eq &mt('View') ||
113: $env{'form.problemmode'} eq &mt('Discard Edits and View')) {
114: if ( defined($env{'form.submitted'}) &&
115: (!defined($env{'form.resetdata'})) &&
116: (!defined($env{'form.newrandomization'}))) {
1.145 albertel 117: return ('grade', 'web','answer');
118: } else {
119: return ('web','answer');
120: }
1.204 albertel 121: } elsif ( $env{'form.problemmode'} eq &mt('Edit') ||
122: $env{'form.problemmode'} eq 'Edit') {
123: if ( $env{'form.submitted'} eq 'edit' ) {
124: if ( $env{'form.submit'} eq &mt('Submit Changes and View') ) {
1.145 albertel 125: return ('modified','web','answer');
126: } else {
1.211 albertel 127: return ('modified','no_output_web','edit');
1.145 albertel 128: }
129: } else {
1.211 albertel 130: return ('no_output_web','edit');
1.145 albertel 131: }
132: } else {
133: return ('web');
134: }
135: }
1.15 albertel 136: }
1.145 albertel 137: return ();
1.5 albertel 138: }
139:
1.3 albertel 140: sub setup_vars {
1.145 albertel 141: my ($target) = @_;
142: return ';'
1.11 albertel 143: # return ';$external::target='.$target.';';
1.2 albertel 144: }
145:
146: sub send_header {
1.145 albertel 147: my ($request)= @_;
148: $request->print(&Apache::lontexconvert::header());
1.204 albertel 149: # $request->print('<form name='.$env{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
1.2 albertel 150: }
151:
1.36 albertel 152: sub createmenu {
1.145 albertel 153: my ($which,$request)=@_;
154: if ($which eq 'grade') {
155: $request->print('<script language="JavaScript">
1.91 albertel 156: hwkmenu=window.open("/res/adm/pages/homeworkmenu.html","homeworkremote",
1.52 albertel 157: "height=350,width=150,menubar=no");
158: </script>');
1.145 albertel 159: }
1.36 albertel 160: }
161:
1.2 albertel 162: sub send_footer {
1.145 albertel 163: my ($request)= @_;
1.16 albertel 164: # $request->print('</form>');
1.145 albertel 165: $request->print(&Apache::lontexconvert::footer());
1.2 albertel 166: }
167:
1.200 albertel 168: sub proctor_checked_in {
1.226 albertel 169: my ($slot_name,$slot,$type)=@_;
170: my @possible_proctors=split(",",$slot->{'proctor'});
171:
172: my $key;
173: if ($type eq 'Task') {
1.230 ! albertel 174: my $version=$Apache::lonhomework::history{'resource.0.version'};
! 175: $key ="resource.$version.0.checkedin";
1.226 albertel 176: } elsif ($type eq 'problem') {
177: $key ='resource.0.checkedin';
178: }
179:
180: foreach my $possible (@possible_proctors) {
181: if ($Apache::lonhomework::history{$key} eq $possible
182: && $Apache::lonhomework::history{$key.'.slot'} eq $slot_name) {
1.202 albertel 183: return 1;
184: }
185: }
1.226 albertel 186:
1.200 albertel 187: return 0;
188: }
189:
1.52 albertel 190: $Apache::lonxml::browse='';
1.152 albertel 191: sub check_ip_acc {
192: my ($acc)=@_;
1.218 albertel 193: &Apache::lonxml::debug("acc is $acc");
194: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
195: return 1;
196: }
1.152 albertel 197: my $allowed=0;
198: my $ip=$ENV{'REMOTE_ADDR'};
199: my $name;
200: foreach my $pattern (split(',',$acc)) {
201: if ($pattern =~ /\*$/) {
202: #35.8.*
203: $pattern=~s/\*//;
204: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
205: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
206: #35.8.3.[34-56]
207: my $low=$2;
208: my $high=$3;
209: $pattern=$1;
210: if ($ip =~ /^\Q$pattern\E/) {
211: my $last=(split(/\./,$ip))[3];
212: if ($last <=$high && $last >=$low) { $allowed=1; }
213: }
214: } elsif ($pattern =~ /^\*/) {
215: #*.msu.edu
216: $pattern=~s/\*//;
217: if (!defined($name)) {
218: use Socket;
219: my $netaddr=inet_aton($ip);
220: ($name)=gethostbyaddr($netaddr,AF_INET);
1.158 albertel 221: }
1.152 albertel 222: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
223: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
224: #127.0.0.1
225: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
226: } else {
227: #some.name.com
228: if (!defined($name)) {
229: use Socket;
230: my $netaddr=inet_aton($ip);
231: ($name)=gethostbyaddr($netaddr,AF_INET);
232: }
233: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
234: }
235: if ($allowed) { last; }
236: }
237: return $allowed;
238: }
1.198 albertel 239:
1.226 albertel 240: sub check_slot_access {
241: my ($id,$type)=@_;
242:
1.207 albertel 243: # does it pass normal muster
1.226 albertel 244: my ($status,$datemsg)=&check_access($id);
245:
246: my $useslots = &Apache::lonnet::EXT("resource.$id.useslots");
247: if ($useslots ne 'resource') {
248: return ($status,$datemsg);
249: }
250:
1.200 albertel 251: if ($status eq 'SHOW_ANSWER' ||
252: $status eq 'CLOSED' ||
253: $status eq 'INVALID_ACCESS' ||
254: $status eq 'UNAVAILABLE') {
255: return ($status,$datemsg);
256: }
1.204 albertel 257: if ($env{'request.state'} eq "construct") {
1.203 albertel 258: return ($status,$datemsg);
259: }
1.226 albertel 260:
261: if ($type eq 'Task') {
262: my $version=$Apache::lonhomework::history{'resource.version'};
1.230 ! albertel 263: if ($Apache::lonhomework::history{"resource.$version.0.checkedin"} &&
! 264: $Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass') {
1.226 albertel 265: return ('SHOW_ANSWER');
266: }
1.207 albertel 267: }
1.226 albertel 268:
1.210 albertel 269: my @slots=
270: (split(':',&Apache::lonnet::EXT("resource.$id.availablestudent")),
271: split(':',&Apache::lonnet::EXT("resource.$id.available")));
272:
1.200 albertel 273: # if (!@slots) {
274: # return ($status,$datemsg);
275: # }
276: my $slotstatus='NOT_IN_A_SLOT';
1.206 albertel 277: my ($returned_slot,$slot_name);
1.210 albertel 278: foreach my $slot (@slots) {
1.201 albertel 279: &Apache::lonxml::debug("getting $slot");
1.200 albertel 280: my %slot=&Apache::lonnet::get_slot($slot);
1.201 albertel 281: &Apache::lonhomework::showhash(%slot);
1.200 albertel 282: if ($slot{'starttime'} < time &&
283: $slot{'endtime'} > time &&
1.201 albertel 284: &check_ip_acc($slot{'ip'})) {
1.202 albertel 285: &Apache::lonxml::debug("$slot is good");
286: $slotstatus='NEEDS_CHECKIN';
287: $returned_slot=\%slot;
1.206 albertel 288: $slot_name=$slot;
1.200 albertel 289: last;
290: }
291: }
1.202 albertel 292: if ($slotstatus eq 'NEEDS_CHECKIN' &&
1.226 albertel 293: &proctor_checked_in($slot_name,$returned_slot,$type)) {
1.202 albertel 294: &Apache::lonxml::debug("protoctor checked in");
1.200 albertel 295: $slotstatus='CAN_ANSWER';
296: }
1.226 albertel 297:
298: my ($pass_status,$checkedin);
299: if ($type eq 'Task') {
1.230 ! albertel 300: my $version=$Apache::lonhomework::history{'resource.0.version'};
1.226 albertel 301: $pass_status =
1.230 ! albertel 302: $Apache::lonhomework::history{"resource.$version.0.status"} eq 'fail';
1.226 albertel 303: $checkedin =
1.230 ! albertel 304: $Apache::lonhomework::history{"resource.$version.0.checkedin"};
1.226 albertel 305: } elsif ($type eq 'problem') {
306: $pass_status = 1;
307: $checkedin = $Apache::lonhomework::history{"resource.0.checkedin"};
308: }
309:
310: if ($slotstatus eq 'NOT_IN_A_SLOT'
311: && $checkedin ) {
312:
313: if ($pass_status) {
1.209 albertel 314: return ('SHOW_ANSWER');
315: } else {
316: return ('WAITING_FOR_GRADE');
317: }
1.226 albertel 318:
1.207 albertel 319: }
1.225 albertel 320: if ( $status eq 'CANNOT_ANSWER' &&
321: ($slotstatus ne 'NEEDS_CHECKIN' && $slotstatus ne 'NOT_IN_A_SLOT')) {
322: return ($status,$datemsg);
323: }
324:
1.206 albertel 325: return ($slotstatus,$datemsg,$slot_name,$returned_slot);
1.198 albertel 326: }
1.200 albertel 327:
1.92 bowersj2 328: # JB, 9/24/2002: Any changes in this function may require a change
329: # in lonnavmaps::resource::getDateStatus.
1.53 www 330: sub check_access {
1.145 albertel 331: my ($id) = @_;
332: my $date ='';
333: my $status;
334: my $datemsg = '';
335: my $lastdate = '';
336: my $type;
337: my $passed;
338:
1.204 albertel 339: if ($env{'request.state'} eq "construct") {
340: if ($env{'form.problemstate'}) {
341: if ($env{'form.problemstate'} =~ /^CANNOT_ANSWER/) {
342: if ( ! ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct' &&
1.167 albertel 343: lc($Apache::lonhomework::problemstatus) eq 'no')) {
1.168 albertel 344: return ('CANNOT_ANSWER',
1.174 www 345: &mt('is in this state due to author settings.'));
1.167 albertel 346: }
1.165 albertel 347: } else {
1.204 albertel 348: return ($env{'form.problemstate'},
1.174 www 349: &mt('is in this state due to author settings.'));
1.165 albertel 350: }
351: }
1.145 albertel 352: &Apache::lonxml::debug("in construction ignoring dates");
353: $status='CAN_ANSWER';
1.146 albertel 354: $datemsg=&mt('is in under construction');
1.163 albertel 355: # return ($status,$datemsg);
1.145 albertel 356: }
357:
358: &Apache::lonxml::debug("checking for part :$id:");
359: &Apache::lonxml::debug("time:".time);
1.152 albertel 360:
1.212 albertel 361: my ($symb)=&Apache::lonxml::whichuser();
362: &Apache::lonxml::debug("symb:".$symb);
363: #if ($env{'request.state'} ne "construct" && $symb ne '') {
1.204 albertel 364: if ($env{'request.state'} ne "construct") {
1.163 albertel 365: my $allowed=&check_ip_acc(&Apache::lonnet::EXT("resource.$id.acc"));
366: if (!$allowed && ($Apache::lonhomework::browse ne 'F')) {
367: $status='INVALID_ACCESS';
368: $date=&mt("can not be accessed from your location.");
1.145 albertel 369: return($status,$date);
370: }
1.163 albertel 371:
1.226 albertel 372: foreach my $temp ("opendate","duedate","answerdate") {
1.163 albertel 373: $lastdate = $date;
374: $date = &Apache::lonnet::EXT("resource.$id.$temp");
375: my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type");
376: if ($thistype =~ /^(con_lost|no_such_host)/ ||
377: $date =~ /^(con_lost|no_such_host)/) {
378: $status='UNAVAILABLE';
379: $date=&mt("may open later.");
380: return($status,$date);
381: }
382: if ($thistype eq 'date_interval') {
383: if ($temp eq 'opendate') {
384: $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date;
385: }
386: if ($temp eq 'answerdate') {
387: $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date;
388: }
1.145 albertel 389: }
1.163 albertel 390: &Apache::lonxml::debug("found :$date: for :$temp:");
391: if ($date eq '') {
392: $date = &mt("an unknown date"); $passed = 0;
393: } elsif ($date eq 'con_lost') {
394: $date = &mt("an indeterminate date"); $passed = 0;
395: } else {
396: if (time < $date) { $passed = 0; } else { $passed = 1; }
397: $date = localtime $date;
1.145 albertel 398: }
1.163 albertel 399: if (!$passed) { $type=$temp; last; }
1.145 albertel 400: }
1.163 albertel 401: &Apache::lonxml::debug("have :$type:$passed:");
402: if ($passed) {
403: $status='SHOW_ANSWER';
404: $datemsg=$date;
405: } elsif ($type eq 'opendate') {
406: $status='CLOSED';
407: $datemsg = &mt("will open on")." $date";
408: } elsif ($type eq 'duedate') {
409: $status='CAN_ANSWER';
410: $datemsg = &mt("is due at")." $date";
411: } elsif ($type eq 'answerdate') {
412: $status='CLOSED';
413: $datemsg = &mt("was due on")." $lastdate".&mt(", and answers will be available on")." $date";
1.145 albertel 414: }
415: }
1.212 albertel 416: if ($status eq 'CAN_ANSWER' ||
417: (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED'))) {
1.145 albertel 418: #check #tries, and if correct.
419: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
420: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
421: if ( $tries eq '' ) { $tries = '0'; }
1.164 albertel 422: if ( $maxtries eq '' &&
1.204 albertel 423: $env{'request.state'} ne 'construct') { $maxtries = '2'; }
1.164 albertel 424: if ($maxtries && $tries >= $maxtries) { $status = 'CANNOT_ANSWER'; }
1.145 albertel 425: # if (correct and show prob status) or excused then CANNOT_ANSWER
426: if(($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/
427: &&
428: lc($Apache::lonhomework::problemstatus) ne 'no')
429: ||
430: $Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) {
431: $status = 'CANNOT_ANSWER';
432: }
1.121 albertel 433: }
1.181 albertel 434: if ($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER') {
1.177 albertel 435: my $interval=&Apache::lonnet::EXT("resource.$id.interval");
436: &Apache::lonxml::debug("looking for interval $interval");
437: if ($interval) {
438: my $first_access=&Apache::lonnet::get_first_access('map');
439: &Apache::lonxml::debug("looking for accesstime $first_access");
440: if (!$first_access) {
441: $status='NOT_YET_VIEWED';
1.192 albertel 442: $datemsg=&seconds_to_human_length($interval);
1.177 albertel 443: } else {
444: my $newdate=localtime($first_access+$interval);
445: if (time > ($first_access+$interval)) {
446: $status='CLOSED';
447: $datemsg = &mt("was due on")." $newdate".&mt(", and answers will be available on")." $date";
448: } else {
449: $datemsg = &mt("is due at")." $newdate";
450: }
451: }
452: }
453: }
1.133 albertel 454: #if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') &&
455: # (!$Apache::lonhomework::history{"resource.0.outtoken"})) {
456: # return ('UNCHECKEDOUT','needs to be checked out');
457: #}
1.54 www 458:
459:
1.145 albertel 460: &Apache::lonxml::debug("sending back :$status:$datemsg:");
461: if (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED')) {
462: &Apache::lonxml::debug("should be allowed to browse a resource when closed");
463: $status='CAN_ANSWER';
1.146 albertel 464: $datemsg=&mt('is closed but you are allowed to view it');
1.145 albertel 465: }
1.106 albertel 466:
1.145 albertel 467: return ($status,$datemsg);
1.20 albertel 468: }
469:
1.192 albertel 470: sub seconds_to_human_length {
471: my ($length)=@_;
472:
473: my $seconds=$length%60; $length=int($length/60);
474: my $minutes=$length%60; $length=int($length/60);
475: my $hours=$length%24; $length=int($length/24);
476: my $days=$length;
477:
478: my $timestr;
479: if ($days > 0) { $timestr.=&mt('[quant,_1,day]',$days); }
480: if ($hours > 0) { $timestr.=($timestr?", ":"").
481: &mt('[quant,_1,hour]',$hours); }
482: if ($minutes > 0) { $timestr.=($timestr?", ":"").
483: &mt('[quant,_1,minute]',$minutes); }
484: if ($seconds > 0) { $timestr.=($timestr?", ":"").
485: &mt('[quant,_1,second]',$seconds); }
486: return $timestr;
487: }
488:
1.41 albertel 489: sub showhash {
1.145 albertel 490: my (%hash) = @_;
491: &showhashsubset(\%hash,'.');
492: return '';
1.79 albertel 493: }
494:
1.106 albertel 495: sub showarray {
496: my ($array)=@_;
497: my $string="(";
498: foreach my $elm (@{ $array }) {
1.193 albertel 499: if (ref($elm) eq 'ARRAY') {
500: $string.=&showarray($elm);
501: } elsif (ref($elm) eq 'HASH') {
502: $string.= "HASH --- \n<br />";
503: $string.= &showhashsubset($elm,'.');
1.106 albertel 504: } else {
505: $string.="$elm,"
506: }
507: }
508: chop($string);
509: $string.=")";
510: return $string;
511: }
512:
1.79 albertel 513: sub showhashsubset {
1.145 albertel 514: my ($hash,$keyre) = @_;
515: my $resultkey;
516: foreach $resultkey (sort keys %$hash) {
1.193 albertel 517: if ($resultkey !~ /$keyre/) { next; }
518: if (ref($$hash{$resultkey}) eq 'ARRAY' ) {
519: &Apache::lonxml::debug("$resultkey ---- ".
520: &showarray($$hash{$resultkey}));
521: } elsif (ref($$hash{$resultkey}) eq 'HASH' ) {
522: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
523: &showhashsubset($$hash{$resultkey},'.');
524: } else {
525: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
1.145 albertel 526: }
527: }
528: &Apache::lonxml::debug("\n<br />restored values^</br>\n");
529: return '';
1.41 albertel 530: }
531:
532: sub setuppermissions {
1.204 albertel 533: $Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$env{'request.filename'});
534: my $viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
1.145 albertel 535: if (! $viewgrades &&
1.204 albertel 536: exists($env{'request.course.sec'}) &&
537: $env{'request.course.sec'} !~ /^\s*$/) {
538: $viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}.
539: '/'.$env{'request.course.sec'});
1.145 albertel 540: }
1.188 foxr 541: $Apache::lonhomework::viewgrades = $viewgrades; # File global variable...dirt.
1.185 albertel 542: if ($Apache::lonhomework::browse eq 'F' &&
1.204 albertel 543: $env{'form.devalidatecourseresdata'} eq 'on') {
1.185 albertel 544: my (undef,$courseid) = &Apache::lonxml::whichuser();
1.204 albertel 545: &Apache::lonnet::devalidatecourseresdata($env{"course.$courseid.num"},
546: $env{"course.$courseid.domain"});
1.185 albertel 547: }
1.205 albertel 548: my $modifygrades = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
549: if (! $modifygrades &&
550: exists($env{'request.course.sec'}) &&
551: $env{'request.course.sec'} !~ /^\s*$/) {
552: $modifygrades =
553: &Apache::lonnet::allowed('mgr',$env{'request.course.id'}.
554: '/'.$env{'request.course.sec'});
555: }
556: $Apache::lonhomework::modifygrades = $modifygrades;
557: return '';
1.41 albertel 558: }
559:
560: sub setupheader {
1.120 albertel 561: my $request=$_[0];
1.197 albertel 562: &Apache::loncommon::content_type($request,'text/html');
1.120 albertel 563: if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
564: &Apache::loncommon::no_cache($request);
565: }
1.196 albertel 566: # $request->set_last_modified(&Apache::lonnet::metadata($request->uri,
567: # 'lastrevisiondate'));
1.120 albertel 568: $request->send_http_header;
569: return OK if $request->header_only;
570: return ''
1.41 albertel 571: }
1.35 albertel 572:
1.47 albertel 573: sub handle_save_or_undo {
1.145 albertel 574: my ($request,$problem,$result) = @_;
575: my $file = &Apache::lonnet::filelocation("",$request->uri);
576: my $filebak =$file.".bak";
577: my $filetmp =$file.".tmp";
578: my $error=0;
1.156 albertel 579:
580: &Apache::lonnet::correct_line_ends($result);
1.52 albertel 581:
1.204 albertel 582: if ($env{'form.Undo'} eq &mt('undo')) {
1.145 albertel 583: my $error=0;
584: if (!copy($file,$filetmp)) { $error=1; }
585: if ((!$error) && (!copy($filebak,$file))) { $error=1; }
586: if ((!$error) && (!move($filetmp,$filebak))) { $error=1; }
587: if (!$error) {
1.171 albertel 588: &Apache::lonxml::info("<p><b>".&mt("Undid changes, Switched")." $filebak ".&mt("and")." $file</b></p>");
1.145 albertel 589: } else {
1.171 albertel 590: &Apache::lonxml::info("<p><font color=\"red\" size=\"+1\"><b>".&mt("Unable to undo, unable to switch")." $filebak ".&mt("and")." $file</b></font></p>");
1.145 albertel 591: $error=1;
592: }
1.52 albertel 593: } else {
1.145 albertel 594: my $fs=Apache::File->new(">$filebak");
595: if (defined($fs)) {
596: print $fs $$problem;
1.171 albertel 597: &Apache::lonxml::info("<b>".&mt("Making Backup to").
598: " $filebak</b>");
1.145 albertel 599: } else {
1.171 albertel 600: &Apache::lonxml::info("<font color=\"red\" size=\"+1\"><b>".&mt("Unable to make backup")." $filebak</b></font>");
1.145 albertel 601: $error=2;
602: }
603: my $fh=Apache::File->new(">$file");
604: if (defined($fh)) {
605: print $fh $$result;
1.171 albertel 606: &Apache::lonxml::info("<b>".&mt("Saving Modifications to").
607: " $file</b>");
1.145 albertel 608: } else {
1.171 albertel 609: &Apache::lonxml::info("<font color=\"red\" size=\"+1\"><b>".
610: &mt("Unable to write to")." $file</b></font>");
1.145 albertel 611: $error|=4;
612: }
1.52 albertel 613: }
1.145 albertel 614: return $error;
1.64 albertel 615: }
616:
1.101 albertel 617: sub analyze_header {
618: my ($request) = @_;
1.221 albertel 619: my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
620: ($env{'environment.remote'} ne 'off'));
1.197 albertel 621: my $html=&Apache::lonxml::xmlbegin();
622: my $result.=$html.'
1.146 albertel 623: <head><title>'.&mt("Analyzing a problem").'</title></head>
1.183 albertel 624: '.$bodytag.&Apache::lonxml::message_location().'
1.101 albertel 625: <form name="lonhomework" method="POST" action="'.
1.204 albertel 626: &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
1.179 albertel 627: &Apache::structuretags::remember_problem_state().'
1.146 albertel 628: <input type="submit" name="problemmode" value="'.&mt("EditXML").'" />
629: <input type="submit" name="problemmode" value="'.&mt('Edit').'" />
1.101 albertel 630: <hr />
1.146 albertel 631: <input type="submit" name="submit" value="'.&mt("View").'" />
1.101 albertel 632: <hr />
633: </form>';
1.171 albertel 634: &Apache::lonxml::add_messages(\$result);
1.101 albertel 635: $request->print($result);
636: $request->rflush();
637: }
638:
1.109 albertel 639: sub analyze_footer {
640: my ($request) = @_;
641: my $result='</body></html>';
642: $request->print($result);
643: $request->rflush();
644: }
645:
1.74 albertel 646: sub analyze {
1.101 albertel 647: my ($request,$file) = @_;
648: &Apache::lonxml::debug("Analyze");
649: my $result;
650: my %overall;
1.219 www 651: my %seedexample;
1.101 albertel 652: my %allparts;
1.204 albertel 653: my $rndseed=$env{'form.rndseed'};
1.101 albertel 654: &analyze_header($request);
1.114 albertel 655: my %prog_state=
1.146 albertel 656: &Apache::lonhtmlcommon::Create_PrgWin($request,&mt('Analyze Progress'),
657: &mt('Getting Problem Variants'),
1.204 albertel 658: $env{'form.numtoanalyze'},
1.175 albertel 659: 'inline',undef);
1.204 albertel 660: for(my $i=1;$i<$env{'form.numtoanalyze'}+1;$i++) {
1.114 albertel 661: &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,
1.146 albertel 662: &mt('last problem'));
1.182 albertel 663: if (&Apache::loncommon::connection_aborted($request)) { return; }
1.219 www 664: my $thisseed=$i+$rndseed;
1.101 albertel 665: my $subresult=&Apache::lonnet::ssi($request->uri,
666: ('grade_target' => 'analyze'),
1.219 www 667: ('rndseed' => $thisseed));
1.101 albertel 668: (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2);
669: my %analyze=&Apache::lonnet::str2hash($subresult);
1.114 albertel 670: my @parts;
671: if (defined(@{ $analyze{'parts'} })) {
672: @parts=@{ $analyze{'parts'} };
673: }
1.101 albertel 674: foreach my $part (@parts) {
675: if (!exists($allparts{$part})) {$allparts{$part}=1;};
1.109 albertel 676: if ($analyze{$part.'.type'} eq 'numericalresponse' ||
677: $analyze{$part.'.type'} eq 'stringresponse' ||
678: $analyze{$part.'.type'} eq 'formularesponse' ) {
1.219 www 679: my $concatanswer=join("\0",@{ $analyze{$part.'.answer'} });
680: if (($concatanswer eq '') || ($concatanswer=~/^\@/)) {
681: @{$analyze{$part.'.answer'}}=('<font color="red">'.&mt('Error').'</font>');
682: }
1.101 albertel 683: push( @{ $overall{$part.'.answer'} },
684: [@{ $analyze{$part.'.answer'} }]);
1.219 www 685: $seedexample{join("\0",@{ $analyze{$part.'.answer'}})}=$thisseed;
1.101 albertel 686: }
687: }
688: }
1.114 albertel 689: &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,
1.146 albertel 690: &mt('Analyzing Results'));
1.175 albertel 691: $request->print('<hr />'.&mt('List of possible answers').': ');
1.134 albertel 692: foreach my $part (sort(keys(%allparts))) {
1.109 albertel 693: if (defined(@{ $overall{$part.'.answer'} })) {
1.132 albertel 694: my $num_cols=scalar(@{ $overall{$part.'.answer'}->[0] });
1.221 albertel 695: $request->print('<table class="thinborder"><tr><th colspan="'.($num_cols+1).'">'.&mt('Part').' '.$part.'</th></tr>');
1.130 albertel 696: my %frequency;
1.109 albertel 697: foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'} })) {
1.132 albertel 698: $frequency{join("\0",@{ $answer })}++;
1.130 albertel 699: }
1.219 www 700: $request->print('<tr><th colspan="'.($num_cols).'">'.&mt('Answer').'</th><th>'.&mt('Frequency').'<br />('
701: .&mt('click for example').')</th></tr>');
1.132 albertel 702: foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) {
1.220 albertel 703: $request->print('<tr><td class="center">'.
704: join('</td><td class="center">',split("\0",$answer)).
705: '</td><td class="center"><a href="'.$request->uri.'?rndseed='.$seedexample{$answer}.'">'.$frequency{$answer}.
1.219 www 706: '</a></td></tr>');
1.109 albertel 707: }
708: $request->print('</table>');
709: } else {
1.162 albertel 710: $request->print('<p>'.&mt('Response').' '.$part.' '.
1.146 albertel 711: &mt('is not analyzable at this time').'</p>');
1.101 albertel 712: }
713: }
1.130 albertel 714: if (scalar(keys(%allparts)) == 0 ) {
1.215 raeburn 715: $request->print('<p>'.&mt('Found no analyzable responses in this problem, currently only Numerical, Formula and String response styles are supported.').'</p>');
1.130 albertel 716: }
1.114 albertel 717: &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);
1.109 albertel 718: &analyze_footer($request);
1.101 albertel 719: &Apache::lonhomework::showhash(%overall);
720: return $result;
1.74 albertel 721: }
722:
1.64 albertel 723: sub editxmlmode {
1.145 albertel 724: my ($request,$file) = @_;
725: my $result;
726: my $problem=&Apache::lonnet::getfile($file);
727: if ($problem eq -1) {
1.146 albertel 728: &Apache::lonxml::error("<b> ".&mt('Unable to find').
729: " <i>$file</i></b>");
1.145 albertel 730: $problem='';
731: }
1.204 albertel 732: if (defined($env{'form.editxmltext'}) || defined($env{'form.Undo'})) {
1.145 albertel 733: my $error=&handle_save_or_undo($request,\$problem,
1.204 albertel 734: \$env{'form.editxmltext'});
1.145 albertel 735: if (!$error) { $problem=&Apache::lonnet::getfile($file); }
736: }
1.204 albertel 737: &Apache::lonhomework::showhashsubset(\%env,'^form');
738: if ( $env{'form.submit'} eq &mt('Submit Changes and View') ) {
739: &Apache::lonhomework::showhashsubset(\%env,'^form');
740: $env{'form.problemmode'}='View';
1.145 albertel 741: &renderpage($request,$file);
742: } else {
743: my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem);
1.160 www 744: my $xml_help = '<table><tr><td>'.
745: &Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index",
746: "Problem Editing Help").
747: '</td><td>'.
1.178 albertel 748: &Apache::loncommon::help_open_menu('',undef,undef,undef,5,'Authoring').
749: '</td></tr></table>';
1.145 albertel 750: if ($cols > 80) { $cols = 80; }
751: if ($cols < 70) { $cols = 70; }
752: if ($rows < 20) { $rows = 20; }
1.221 albertel 753: my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
754: ($env{'environment.remote'} ne 'off'));
1.197 albertel 755: my $html=&Apache::lonxml::xmlbegin();
1.227 albertel 756: my $head="<head><title>EditXML $file</title>".
757: &Apache::edit::js_change_detection()."</head>";
758:
759: $result.=$html.$head.$bodytag.
1.213 albertel 760: &renderpage($request,$file,['no_output_web'],1).
761: &Apache::lonxml::message_location().'
1.227 albertel 762: <form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'.
1.204 albertel 763: &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
1.179 albertel 764: &Apache::structuretags::remember_problem_state().'
1.146 albertel 765: <input type="hidden" name="problemmode" value="'.&mt('EditXML').'" />
1.170 matthew 766: <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
767: <input type="submit" name="problemmode" accesskey="e" value="'.&mt('Edit').'" />
1.228 albertel 768: <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
1.64 albertel 769: <hr />
1.170 matthew 770: <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />
771: <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />
1.64 albertel 772: <hr />
1.110 albertel 773: ' . $xml_help . '
1.227 albertel 774: <textarea '.&Apache::edit::element_change_detection().' style="width:100%" rows="'.$rows.'" cols="'.$cols.'" name="editxmltext">'.
1.229 albertel 775: &HTML::Entities::encode($problem,'<>&"').'</textarea><br />
776: <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />
777: <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />
1.64 albertel 778: </form></body></html>';
1.171 albertel 779: &Apache::lonxml::add_messages(\$result);
1.145 albertel 780: $request->print($result);
781: }
782: return '';
1.47 albertel 783: }
1.189 albertel 784:
1.188 foxr 785: #
786: # Render the page in whatever target desired.
787: #
1.41 albertel 788: sub renderpage {
1.213 albertel 789: my ($request,$file,$targets,$return_string) = @_;
1.52 albertel 790:
1.211 albertel 791: my @targets = @{$targets || [&get_target()]};
1.204 albertel 792: &Apache::lonhomework::showhashsubset(\%env,'form.');
1.145 albertel 793: &Apache::lonxml::debug("Running targets ".join(':',@targets));
1.171 albertel 794: my $overall_result;
1.145 albertel 795: foreach my $target (@targets) {
1.183 albertel 796: # FIXME need to do something intelligent when a problem goes
797: # from viewable to not viewable due to map conditions
798: #&setuppermissions();
799: #if ( $Apache::lonhomework::browse ne '2'
800: # && $Apache::lonhomework::browse ne 'F' ) {
801: # $request->print(" You most likely shouldn't see me.");
802: #}
1.145 albertel 803: #my $t0 = [&gettimeofday()];
1.211 albertel 804: my $output=1;
805: if ($target eq 'no_output_web') {
806: $target = 'web'; $output=0;
807: }
1.145 albertel 808: my $problem=&Apache::lonnet::getfile($file);
1.222 albertel 809: my $result;
1.145 albertel 810: if ($problem eq -1) {
1.222 albertel 811: my $filename=(split('/',$file))[-1];
812: $result.="<b> ".&mt('Unable to find')." <i>$filename</i></b>";
1.145 albertel 813: $problem='';
814: }
1.52 albertel 815:
1.145 albertel 816: my %mystyle;
817: if ($target eq 'analyze') { %Apache::lonhomework::analyze=(); }
818: if ($target eq 'answer') { &showhash(%Apache::lonhomework::history); }
1.204 albertel 819: if ($target eq 'web') {&Apache::lonhomework::showhashsubset(\%env,'^form');}
1.145 albertel 820:
821: &Apache::lonxml::debug("Should be parsing now");
1.222 albertel 822: $result .= &Apache::lonxml::xmlparse($request, $target, $problem,
823: &setup_vars($target),%mystyle);
1.145 albertel 824: undef($Apache::lonhomework::parsing_a_problem);
1.214 albertel 825: if (!$output) { $result = ''; }
1.145 albertel 826: #$request->print("Result follows:");
827: if ($target eq 'modified') {
828: &handle_save_or_undo($request,\$problem,\$result);
829: } else {
830: if ($target eq 'analyze') {
831: $result=&Apache::lonnet::hashref2str(\%Apache::lonhomework::analyze);
832: undef(%Apache::lonhomework::analyze);
833: }
834: #my $td=&tv_interval($t0);
835: #if ( $Apache::lonxml::debug) {
836: #$result =~ s:</body>::;
837: #$result.="<br />Spent $td seconds processing target $target\n</body>";
838: #}
1.171 albertel 839: # $request->print($result);
840: $overall_result.=$result;
841: # $request->rflush();
1.145 albertel 842: }
843: #$request->print(":Result ends");
844: #my $td=&tv_interval($t0);
1.52 albertel 845: }
1.213 albertel 846: if (!$return_string) {
847: &Apache::lonxml::add_messages(\$overall_result);
848: $request->print($overall_result);
849: $request->rflush();
850: } else {
851: return $overall_result;
852: }
1.41 albertel 853: }
854:
1.42 albertel 855: # with no arg it returns a HTML <option> list of the template titles
856: # with one arg it returns the filename associated with the arg passed
857: sub get_template_list {
1.145 albertel 858: my ($namewanted,$extension) = @_;
859: my $result;
860: my @allnames;
861: &Apache::lonxml::debug("Looking for :$extension:");
862: foreach my $file (</home/httpd/html/res/adm/includes/templates/*.$extension>) {
863: my $name=&Apache::lonnet::metadata($file,'title');
864: if ($namewanted && ($name eq $namewanted)) {
865: $result=$file;
866: last;
867: } else {
868: if ($name) { push (@allnames, $name); }
869: }
870: }
871: if (@allnames && !$result) {
1.146 albertel 872: $result="<option>".&mt("Select a")." $extension ".&mt('template')."</option>\n<option>".
1.145 albertel 873: join('</option><option>',sort(@allnames)).'</option>';
1.42 albertel 874: }
1.145 albertel 875: return $result;
1.42 albertel 876: }
877:
878: sub newproblem {
1.65 matthew 879: my ($request) = @_;
880: my $extension=$request->uri;
881: $extension=~s:^.*\.([\w]+)$:$1:;
882: &Apache::lonxml::debug("Looking for :$extension:");
1.131 albertel 883: my $templatelist=&get_template_list('',$extension);
1.204 albertel 884: if ($env{'form.template'} &&
885: $env{'form.template'} ne "Select a $extension template") {
1.65 matthew 886: use File::Copy;
1.204 albertel 887: my $file = &get_template_list($env{'form.template'},$extension);
1.65 matthew 888: my $dest = &Apache::lonnet::filelocation("",$request->uri);
889: copy($file,$dest);
890: &renderpage($request,$dest);
1.204 albertel 891: } elsif($env{'form.newfile'} && !$templatelist) {
1.131 albertel 892: # I don't like hard-coded filenames but for now, this will work.
893: use File::Copy;
894: my $templatefilename =
895: $request->dir_config('lonIncludes').'/templates/blank.problem';
896: &Apache::lonxml::debug("$templatefilename");
897: my $dest = &Apache::lonnet::filelocation("",$request->uri);
898: copy($templatefilename,$dest);
899: &renderpage($request,$dest);
1.85 albertel 900: } else {
1.176 albertel 901: my $url=&HTML::Entities::encode($request->uri,'<>&"');
902: my $shownurl=$url;
1.157 albertel 903: $shownurl=~s-^/~-/priv/-;
1.65 matthew 904: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1.128 albertel 905: my $errormsg;
1.204 albertel 906: if ($env{'form.newfile'}) {
1.146 albertel 907: $errormsg='<p><font color="red">'.&mt('You did not select a template.').'</font></p>'."\n";
1.128 albertel 908: }
1.85 albertel 909: my $instructions;
1.186 albertel 910: my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
1.204 albertel 911: ($env{'environment.remote'} ne 'off'));
1.146 albertel 912: if ($templatelist) { $instructions=&mt(", select a template from the pull-down menu below.").'<br />'.&mt("Then");}
1.147 albertel 913: my %lt=&Apache::lonlocal::texthash( 'create' => 'Creating a new',
1.146 albertel 914: 'resource' => 'resource',
915: 'requested' => 'The requested file',
916: 'not exist' => 'currently does not exist',
917: 'createnew' => 'To create a new',
918: 'click' => 'click on the',
919: 'Create' => 'Create',
920: 'button' => 'button');
1.65 matthew 921: $request->print(<<ENDNEWPROBLEM);
1.159 www 922: $bodytag
1.148 albertel 923: <h1>$lt{'create'} $extension $lt{'resource'}</h1>
1.128 albertel 924: $errormsg
1.157 albertel 925: $lt{'requested'} <tt>$shownurl</tt> $lt{'not exist'}.
1.105 www 926: <p>
1.146 albertel 927: <b>$lt{'createnew'} $extension$instructions $lt{'click'} "$lt{'Create'} $extension" $lt{'button'}.</b>
1.105 www 928: </p>
929: <p><form action="$url" method="POST">
1.42 albertel 930: ENDNEWPROBLEM
1.85 albertel 931: if (defined($templatelist)) {
932: $request->print("<select name=\"template\">$templatelist</select>");
933: }
1.146 albertel 934: $request->print("<br /><input type=\"submit\" name=\"newfile\" value=\"".&mt('Create')." $extension\" />");
1.105 www 935: $request->print("</form></p></body>");
1.65 matthew 936: }
937: return '';
1.42 albertel 938: }
939:
940: sub view_or_edit_menu {
1.145 albertel 941: my ($request) = @_;
1.176 albertel 942: my $url=&HTML::Entities::encode($request->uri,'<>&"');
1.147 albertel 943: my %lt=&Apache::lonlocal::texthash( 'would' => 'Would you like to',
1.146 albertel 944: 'view' => 'View',
945: 'Edit' => 'edit',
946: 'or' => 'or',
947: 'the problem' => 'the problem');
1.145 albertel 948: $request->print(<<EDITMENU);
1.42 albertel 949: <body bgcolor="#FFFFFF">
950: <form action="$url" method="POST">
1.170 matthew 951: $lt{'would'} <input type="submit" name="problemmode" accesskey="v" value="<{'view'}">
952: <{'or'} <input type="submit" name="problemmode" accesskey="e" value="<{'Edit'}">
1.146 albertel 953: <{'the problem'}.
1.42 albertel 954: </form>
955: </body>
956: EDITMENU
957: }
958:
1.41 albertel 959: sub handler {
1.145 albertel 960: #my $t0 = [&gettimeofday()];
961: my $request=$_[0];
1.223 albertel 962: $Apache::lonxml::request=$request;
1.204 albertel 963: $Apache::lonxml::debug=$env{'user.debug'};
964: $env{'request.uri'}=$request->uri;
1.180 albertel 965: &setuppermissions();
1.145 albertel 966: # some times multiple problemmodes are submitted, need to select
967: # the last one
1.204 albertel 968: if ( defined($env{'form.problemmode'}) && ref($env{'form.problemmode'}) ) {
969: my $mode=$env{'form.problemmode'}->[-1];
970: undef $env{'form.problemmode'};
971: $env{'form.problemmode'}=$mode;
1.145 albertel 972: }
1.193 albertel 973:
1.145 albertel 974: my $file=&Apache::lonnet::filelocation("",$request->uri);
975:
976: #check if we know where we are
1.204 albertel 977: if ($env{'request.course.fn'} && !&Apache::lonnet::symbread()) {
1.145 albertel 978: # if we are browsing we might not be able to know where we are
1.173 albertel 979: if ($Apache::lonhomework::browse ne 'F' &&
1.204 albertel 980: $env{'request.state'} ne "construct") {
1.145 albertel 981: #should know where we are, so ask
1.190 albertel 982: $request->internal_redirect('/adm/ambiguous'); return OK;
1.145 albertel 983: }
984: }
1.187 albertel 985: if (&setupheader($request)) { return OK; }
1.193 albertel 986: &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:");
1.204 albertel 987: &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});
1.145 albertel 988: my ($symb) = &Apache::lonxml::whichuser();
989: &Apache::lonxml::debug('symb is '.$symb);
1.204 albertel 990: if ($env{'request.state'} eq "construct" || $symb eq '') {
991: if ($env{'form.resetdata'} eq &mt('Reset Submissions') ||
992: $env{'form.resetdata'} eq &mt('New Problem Variation') ||
993: $env{'form.newrandomization'} eq &mt('New Randomization')) {
1.145 albertel 994: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
995: &Apache::lonnet::tmpreset($symb,'',$domain,$name);
996: &Apache::lonxml::debug("Attempt reset");
997: }
998: }
1.204 albertel 999: if ($env{'request.state'} eq "construct") {
1.145 albertel 1000: if ( -e $file ) {
1001: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1002: ['problemmode']);
1.204 albertel 1003: if (!(defined $env{'form.problemmode'})) {
1.145 albertel 1004: #first visit to problem in construction space
1005: #&view_or_edit_menu($request);
1.204 albertel 1006: $env{'form.problemmode'}='View';
1.145 albertel 1007: &renderpage($request,$file);
1.204 albertel 1008: } elsif ($env{'form.problemmode'} eq &mt('EditXML') ||
1009: $env{'form.problemmode'} eq 'EditXML') {
1.145 albertel 1010: &editxmlmode($request,$file);
1.204 albertel 1011: } elsif ($env{'form.problemmode'} eq &mt('Calculate answers')) {
1.145 albertel 1012: &analyze($request,$file);
1013: } else {
1014: &renderpage($request,$file);
1015: }
1016: } else {
1017: # requested file doesn't exist in contruction space
1018: &newproblem($request);
1019: }
1020: } else {
1021: # just render the page normally outside of construction space
1022: &Apache::lonxml::debug("not construct");
1.52 albertel 1023: &renderpage($request,$file);
1.41 albertel 1024: }
1.145 albertel 1025: #my $td=&tv_interval($t0);
1026: #&Apache::lonxml::debug("Spent $td seconds processing");
1027: # &Apache::lonhomework::send_footer($request);
1028: # always turn off debug messages
1029: $Apache::lonxml::debug=0;
1030: return OK;
1.52 albertel 1031:
1.1 albertel 1032: }
1033:
1034: 1;
1035: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>