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