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