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