1: # The LearningOnline Network with CAPA
2: # The LON-CAPA Homework handler
3: #
4: # $Id: lonhomework.pm,v 1.324 2011/02/12 01:36:21 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27:
28:
29: package Apache::lonhomework;
30: use strict;
31: use Apache::style();
32: use Apache::lonxml();
33: use Apache::lonnet;
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();
41: use Apache::caparesponse();
42: use Apache::radiobuttonresponse();
43: use Apache::optionresponse();
44: use Apache::imageresponse();
45: use Apache::essayresponse();
46: use Apache::externalresponse();
47: use Apache::rankresponse();
48: use Apache::matchresponse();
49: use Apache::chemresponse();
50: use Apache::functionplotresponse();
51: use Apache::drawimage();
52: use Apache::Constants qw(:common);
53: use Apache::loncommon();
54: use Apache::lonlocal;
55: use Time::HiRes qw( gettimeofday tv_interval );
56: use HTML::Entities();
57: use File::Copy();
58:
59: # FIXME - improve commenting
60:
61:
62: BEGIN {
63: &Apache::lonxml::register_insert();
64: }
65:
66:
67: =pod
68:
69: =item set_bubble_lines()
70:
71: Called at analysis time to set the bubble lines
72: hash for the problem.. This should be called in the
73: end_problemtype tag in analysis mode.
74:
75: We fetch the hash of part id counters from lonxml
76: and push them into analyze:{part_id.bubble_lines}.
77:
78: =cut
79:
80: sub set_bubble_lines {
81: my %bubble_counters = &Apache::lonxml::get_bubble_line_hash();
82:
83: foreach my $key (keys(%bubble_counters)) {
84: $Apache::lonhomework::analyze{"$key.bubble_lines"} =
85: $bubble_counters{"$key"};
86: }
87: }
88:
89: #
90: # Decides what targets to render for.
91: # Implicit inputs:
92: # Various session environment variables:
93: # request.state - published - is a /res/ resource
94: # uploaded - is a /uploaded/ resource
95: # contruct - is a /priv/ resource
96: # form.grade_target - a form parameter requesting a specific target
97: sub get_target {
98: &Apache::lonxml::debug("request.state = $env{'request.state'}");
99: if( defined($env{'form.grade_target'})) {
100: &Apache::lonxml::debug("form.grade_target= $env{'form.grade_target'}");
101: } else {
102: &Apache::lonxml::debug("form.grade_target <undefined>");
103: }
104: if (($env{'request.state'} eq "published") ||
105: ($env{'request.state'} eq "uploaded")) {
106: if ( defined($env{'form.grade_target'} )
107: && ($env{'form.grade_target'} eq 'tex')) {
108: return ($env{'form.grade_target'});
109: } elsif ( defined($env{'form.grade_target'} )
110: && ($Apache::lonhomework::viewgrades eq 'F' )) {
111: return ($env{'form.grade_target'});
112: } elsif ( $env{'form.grade_target'} eq 'webgrade'
113: && ($Apache::lonhomework::queuegrade eq 'F' )) {
114: return ($env{'form.grade_target'});
115: } elsif ($env{'form.grade_target'} eq 'answer') {
116: if ($env{'form.answer_output_mode'} eq 'tex') {
117: return ($env{'form.grade_target'});
118: }
119: }
120: if ($env{'form.webgrade'} &&
121: ($Apache::lonhomework::modifygrades eq 'F'
122: || $Apache::lonhomework::queuegrade eq 'F' )) {
123: return ('grade','webgrade');
124: }
125: if ( defined($env{'form.submitted'}) &&
126: ( !defined($env{'form.newrandomization'}))) {
127: return ('grade', 'web');
128: } else {
129: return ('web');
130: }
131: } elsif ($env{'request.state'} eq "construct") {
132: #
133: # We are in construction space, editing and testing problems
134: #
135: if ( defined($env{'form.grade_target'}) ) {
136: return ($env{'form.grade_target'});
137: }
138: if ( defined($env{'form.preview'})) {
139: if ( defined($env{'form.submitted'})) {
140: #
141: # We are doing a problem preview
142: #
143: return ('grade', 'web');
144: } else {
145: return ('web');
146: }
147: } else {
148: if ($env{'form.problemstate'} eq 'WEB_GRADE') {
149: return ('grade','webgrade','answer');
150: } elsif ($env{'form.problemmode'} eq 'view') {
151: return ('grade','web','answer');
152: } elsif ($env{'form.problemmode'} eq 'saveview') {
153: return ('modified','web','answer');
154: } elsif ($env{'form.problemmode'} eq 'discard') {
155: return ('web','answer');
156: } elsif (($env{'form.problemmode'} eq 'saveedit') ||
157: ($env{'form.problemmode'} eq 'undo')) {
158: return ('modified','no_output_web','edit');
159: } elsif ($env{'form.problemmode'} eq 'edit') {
160: return ('no_output_web','edit');
161: } else {
162: return ('web');
163: }
164: }
165: #
166: # End of Construction Space
167: #
168: }
169: #
170: # Huh? We are nowhere, so do nothing.
171: #
172: return ();
173: }
174:
175: sub setup_vars {
176: my ($target) = @_;
177: return ';'
178: # return ';$external::target='.$target.';';
179: }
180:
181: sub proctor_checked_in {
182: my ($slot_name,$slot,$type)=@_;
183: my @possible_proctors=split(",",$slot->{'proctor'});
184:
185: return 1 if (!@possible_proctors);
186:
187: my $key;
188: if ($type eq 'Task') {
189: my $version=$Apache::lonhomework::history{'resource.0.version'};
190: $key ="resource.$version.0.checkedin";
191: } elsif ($type eq 'problem') {
192: $key ='resource.0.checkedin';
193: }
194: # backward compatability, used to be username@domain,
195: # now is username:domain
196: my $who = $Apache::lonhomework::history{$key};
197: if ($who !~ /:/) {
198: $who =~ tr/@/:/;
199: }
200: foreach my $possible (@possible_proctors) {
201: if ($who eq $possible
202: && $Apache::lonhomework::history{$key.'.slot'} eq $slot_name) {
203: return 1;
204: }
205: }
206:
207: return 0;
208: }
209:
210: sub check_slot_access {
211: my ($id,$type)=@_;
212:
213: # does it pass normal muster
214: my ($status,$datemsg)=&check_access($id);
215:
216: my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
217: if ($useslots ne 'resource' && $useslots ne 'map'
218: && $useslots ne 'map_map') {
219: return ($status,$datemsg);
220: }
221:
222: if ($status eq 'SHOW_ANSWER' ||
223: $status eq 'CLOSED' ||
224: $status eq 'INVALID_ACCESS' ||
225: $status eq 'UNAVAILABLE') {
226: return ($status,$datemsg);
227: }
228: if ($env{'request.state'} eq "construct") {
229: return ($status,$datemsg);
230: }
231:
232: if ($type eq 'Task') {
233: my $version=$Apache::lonhomework::history{'resource.version'};
234: if ($Apache::lonhomework::history{"resource.$version.0.checkedin"} &&
235: $Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass') {
236: return ('SHOW_ANSWER');
237: }
238: }
239:
240: my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent");
241: my $available = &Apache::lonnet::EXT("resource.0.available");
242: my @slots= (split(':',$availablestudent),split(':',$available));
243:
244: # if (!@slots) {
245: # return ($status,$datemsg);
246: # }
247: my $slotstatus='NOT_IN_A_SLOT';
248: my ($returned_slot,$slot_name);
249: foreach my $slot (@slots) {
250: $slot =~ s/(^\s*|\s*$)//g;
251: &Apache::lonxml::debug("getting $slot");
252: my %slot=&Apache::lonnet::get_slot($slot);
253: &Apache::lonhomework::showhash(%slot);
254: if ($slot{'starttime'} < time &&
255: $slot{'endtime'} > time &&
256: &Apache::loncommon::check_ip_acc($slot{'ip'})) {
257: &Apache::lonxml::debug("$slot is good");
258: $slotstatus='NEEDS_CHECKIN';
259: $returned_slot=\%slot;
260: $slot_name=$slot;
261: last;
262: }
263: }
264: if ($slotstatus eq 'NEEDS_CHECKIN' &&
265: &proctor_checked_in($slot_name,$returned_slot,$type)) {
266: &Apache::lonxml::debug("proctor checked in");
267: $slotstatus=$status;
268: }
269:
270: my ($is_correct,$got_grade,$checkedin);
271: if ($type eq 'Task') {
272: my $version=$Apache::lonhomework::history{'resource.0.version'};
273: $got_grade =
274: ($Apache::lonhomework::history{"resource.$version.0.status"}
275: =~ /^(?:pass|fail)$/);
276: $is_correct =
277: ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass'
278: || $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ );
279: $checkedin =
280: $Apache::lonhomework::history{"resource.$version.0.checkedin"};
281: } elsif ($type eq 'problem') {
282: $got_grade = 1;
283: $checkedin = $Apache::lonhomework::history{"resource.0.checkedin"};
284: $is_correct =
285: ($Apache::lonhomework::history{"resource.0.solved"} =~/^correct_/);
286: }
287:
288: &Apache::lonxml::debug(" slot is $slotstatus checkedin ($checkedin) got_grade ($got_grade) is_correct ($is_correct)");
289:
290: # no slot is currently open, and has been checked in for this version
291: # but hasn't got a grade, therefore must be awaiting a grade
292: if (!defined($slot_name)
293: && $checkedin
294: && !$got_grade) {
295: return ('WAITING_FOR_GRADE');
296: }
297:
298: # Previously used slot is no longer open, and has been checked in for this version.
299: # However, the problem is not closed, and potentially, another slot might be
300: # used to gain access to it to work on it, until the due date is reached, and the
301: # problem then becomes CLOSED. Therefore return the slotstatus -
302: # (which will be NOT_IN_SLOT).
303: if (!defined($slot_name)
304: && $checkedin
305: && $type eq 'problem') {
306: return ($slotstatus);
307: }
308:
309: if ($slotstatus eq 'NOT_IN_A_SLOT'
310: && $checkedin ) {
311:
312: if ($got_grade) {
313: return ('SHOW_ANSWER');
314: } else {
315: return ('WAITING_FOR_GRADE');
316: }
317:
318: }
319:
320: if ( $is_correct) {
321: if ($type eq 'problem') {
322: return ($status);
323: }
324: return ('SHOW_ANSWER');
325: }
326:
327: if ( $status eq 'CANNOT_ANSWER' &&
328: ($slotstatus ne 'NEEDS_CHECKIN' && $slotstatus ne 'NOT_IN_A_SLOT')) {
329: return ($status,$datemsg);
330: }
331:
332: return ($slotstatus,$datemsg,$slot_name,$returned_slot);
333: }
334:
335: # JB, 9/24/2002: Any changes in this function may require a change
336: # in lonnavmaps::resource::getDateStatus.
337: sub check_access {
338: my ($id) = @_;
339: my $date ='';
340: my $status;
341: my $datemsg = '';
342: my $lastdate = '';
343: my $type;
344: my $passed;
345:
346: if ($env{'request.state'} eq "construct") {
347: if ($env{'form.problemstate'}) {
348: if ($env{'form.problemstate'} =~ /^CANNOT_ANSWER/) {
349: if ( ! ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct'
350: && &hide_problem_status())) {
351: return ('CANNOT_ANSWER',
352: &mt('is in this state due to author settings.'));
353: }
354: } else {
355: return ($env{'form.problemstate'},
356: &mt('is in this state due to author settings.'));
357: }
358: }
359: &Apache::lonxml::debug("in construction ignoring dates");
360: $status='CAN_ANSWER';
361: $datemsg=&mt('is in under construction');
362: # return ($status,$datemsg);
363: }
364:
365: &Apache::lonxml::debug("checking for part :$id:");
366: &Apache::lonxml::debug("time:".time);
367:
368: my ($symb)=&Apache::lonnet::whichuser();
369: &Apache::lonxml::debug("symb:".$symb);
370: #if ($env{'request.state'} ne "construct" && $symb ne '') {
371: if ($env{'request.state'} ne "construct") {
372: my $idacc = &Apache::lonnet::EXT("resource.$id.acc");
373: my $allowed=&Apache::loncommon::check_ip_acc($idacc);
374: if (!$allowed && ($Apache::lonhomework::browse ne 'F')) {
375: $status='INVALID_ACCESS';
376: $date=&mt("can not be accessed from your location.");
377: return($status,$date);
378: }
379:
380: foreach my $temp ("opendate","duedate","answerdate") {
381: $lastdate = $date;
382: if ($temp eq 'duedate') {
383: $date = &due_date($id);
384: } else {
385: $date = &Apache::lonnet::EXT("resource.$id.$temp");
386: }
387:
388: my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type");
389: if ($thistype =~ /^(con_lost|no_such_host)/ ||
390: $date =~ /^(con_lost|no_such_host)/) {
391: $status='UNAVAILABLE';
392: $date=&mt("may open later.");
393: return($status,$date);
394: }
395: if ($thistype eq 'date_interval') {
396: if ($temp eq 'opendate') {
397: $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date;
398: }
399: if ($temp eq 'answerdate') {
400: $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date;
401: }
402: }
403: &Apache::lonxml::debug("found :$date: for :$temp:");
404: if ($date eq '') {
405: $date = &mt("an unknown date"); $passed = 0;
406: } elsif ($date eq 'con_lost') {
407: $date = &mt("an indeterminate date"); $passed = 0;
408: } else {
409: if (time < $date) { $passed = 0; } else { $passed = 1; }
410: $date = &Apache::lonlocal::locallocaltime($date);
411: }
412: if (!$passed) { $type=$temp; last; }
413: }
414: &Apache::lonxml::debug("have :$type:$passed:");
415: if ($passed) {
416: $status='SHOW_ANSWER';
417: $datemsg=$date;
418: } elsif ($type eq 'opendate') {
419: $status='CLOSED';
420: $datemsg = &mt("will open on")." $date";
421: } elsif ($type eq 'duedate') {
422: $status='CAN_ANSWER';
423: $datemsg = &mt("is due at")." $date";
424: } elsif ($type eq 'answerdate') {
425: $status='CLOSED';
426: $datemsg = &mt("was due on")." $lastdate".&mt(", and answers will be available on")." $date";
427: }
428: }
429: if ($status eq 'CAN_ANSWER' ||
430: (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED'))) {
431: #check #tries, and if correct.
432: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
433: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
434: if ( $tries eq '' ) { $tries = '0'; }
435: if ( $maxtries eq '' &&
436: $env{'request.state'} ne 'construct') { $maxtries = '2'; }
437: if ($maxtries && $tries >= $maxtries) { $status = 'CANNOT_ANSWER'; }
438: # if (correct and show prob status) or excused then CANNOT_ANSWER
439: if(($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/
440: &&
441: &show_problem_status())
442: ||
443: $Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) {
444: $status = 'CANNOT_ANSWER';
445: }
446: if ($status eq 'CANNOT_ANSWER'
447: && &show_answer_problem_status()) {
448: $status = 'SHOW_ANSWER';
449: }
450: }
451: if ($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER') {
452: my @interval=&Apache::lonnet::EXT("resource.$id.interval");
453: &Apache::lonxml::debug("looking for interval @interval");
454: if ($interval[0]) {
455: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
456: &Apache::lonxml::debug("looking for accesstime $first_access");
457: if (!$first_access) {
458: $status='NOT_YET_VIEWED';
459: my $due_date = &due_date($id);
460: my $seconds_left = $due_date - time;
461: if ($seconds_left > $interval[0] || $due_date eq '') {
462: $seconds_left = $interval[0];
463: }
464: $datemsg=&seconds_to_human_length($seconds_left);
465: }
466: }
467: }
468:
469: #if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') &&
470: # (!$Apache::lonhomework::history{"resource.0.outtoken"})) {
471: # return ('UNCHECKEDOUT','needs to be checked out');
472: #}
473:
474:
475: &Apache::lonxml::debug("sending back :$status:$datemsg:");
476: if (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED')) {
477: &Apache::lonxml::debug("should be allowed to browse a resource when closed");
478: $status='CAN_ANSWER';
479: $datemsg=&mt('is closed but you are allowed to view it');
480: }
481:
482: return ($status,$datemsg);
483: }
484: # this should work exactly like the copy in lonnavmaps.pm
485: sub due_date {
486: my ($part_id,$symb,$udom,$uname)=@_;
487: my $date;
488: my @interval= &Apache::lonnet::EXT("resource.$part_id.interval",$symb,
489: $udom,$uname);
490: &Apache::lonxml::debug("looking for interval $part_id $symb @interval");
491: my $due_date= &Apache::lonnet::EXT("resource.$part_id.duedate",$symb,
492: $udom,$uname);
493: &Apache::lonxml::debug("looking for due_date $part_id $symb $due_date");
494: if ($interval[0] =~ /\d+/) {
495: my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
496: &Apache::lonxml::debug("looking for first_access $first_access ($interval[1])");
497: if (defined($first_access)) {
498: my $interval = $first_access+$interval[0];
499: $date = (!$due_date || $interval < $due_date) ? $interval
500: : $due_date;
501: } else {
502: $date = $due_date;
503: }
504: } else {
505: $date = $due_date;
506: }
507: return $date
508: }
509:
510: sub seconds_to_human_length {
511: my ($length)=@_;
512:
513: my $seconds=$length%60; $length=int($length/60);
514: my $minutes=$length%60; $length=int($length/60);
515: my $hours=$length%24; $length=int($length/24);
516: my $days=$length;
517:
518: my $timestr;
519: if ($days > 0) { $timestr.=&mt('[quant,_1,day]',$days); }
520: if ($hours > 0) { $timestr.=($timestr?", ":"").
521: &mt('[quant,_1,hour]',$hours); }
522: if ($minutes > 0) { $timestr.=($timestr?", ":"").
523: &mt('[quant,_1,minute]',$minutes); }
524: if ($seconds > 0) { $timestr.=($timestr?", ":"").
525: &mt('[quant,_1,second]',$seconds); }
526: return $timestr;
527: }
528:
529: sub showhash {
530: my (%hash) = @_;
531: &showhashsubset(\%hash,'.');
532: return '';
533: }
534:
535: sub showarray {
536: my ($array)=@_;
537: my $string="(";
538: foreach my $elm (@{ $array }) {
539: if (ref($elm) eq 'ARRAY') {
540: $string.=&showarray($elm);
541: } elsif (ref($elm) eq 'HASH') {
542: $string.= "HASH --- \n<br />";
543: $string.= &showhashsubset($elm,'.');
544: } else {
545: $string.="$elm,"
546: }
547: }
548: chop($string);
549: $string.=")";
550: return $string;
551: }
552:
553: sub showhashsubset {
554: my ($hash,$keyre) = @_;
555: my $resultkey;
556: foreach $resultkey (sort keys %$hash) {
557: if ($resultkey !~ /$keyre/) { next; }
558: if (ref($$hash{$resultkey}) eq 'ARRAY' ) {
559: &Apache::lonxml::debug("$resultkey ---- ".
560: &showarray($$hash{$resultkey}));
561: } elsif (ref($$hash{$resultkey}) eq 'HASH' ) {
562: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
563: &showhashsubset($$hash{$resultkey},'.');
564: } else {
565: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
566: }
567: }
568: &Apache::lonxml::debug("\n<br />restored values^</br>\n");
569: return '';
570: }
571:
572: sub setuppermissions {
573: $Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$env{'request.filename'});
574: my $viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
575: if (! $viewgrades &&
576: exists($env{'request.course.sec'}) &&
577: $env{'request.course.sec'} !~ /^\s*$/) {
578: $viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}.
579: '/'.$env{'request.course.sec'});
580: }
581: $Apache::lonhomework::viewgrades = $viewgrades;
582:
583: if ($Apache::lonhomework::browse eq 'F' &&
584: $env{'form.devalidatecourseresdata'} eq 'on') {
585: my (undef,$courseid) = &Apache::lonnet::whichuser();
586: &Apache::lonnet::devalidatecourseresdata($env{"course.$courseid.num"},
587: $env{"course.$courseid.domain"});
588: }
589:
590: my $modifygrades = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
591: if (! $modifygrades &&
592: exists($env{'request.course.sec'}) &&
593: $env{'request.course.sec'} !~ /^\s*$/) {
594: $modifygrades =
595: &Apache::lonnet::allowed('mgr',$env{'request.course.id'}.
596: '/'.$env{'request.course.sec'});
597: }
598: $Apache::lonhomework::modifygrades = $modifygrades;
599:
600: my $queuegrade = &Apache::lonnet::allowed('mqg',$env{'request.course.id'});
601: if (! $queuegrade &&
602: exists($env{'request.course.sec'}) &&
603: $env{'request.course.sec'} !~ /^\s*$/) {
604: $queuegrade =
605: &Apache::lonnet::allowed('qgr',$env{'request.course.id'}.
606: '/'.$env{'request.course.sec'});
607: }
608: $Apache::lonhomework::queuegrade = $queuegrade;
609: return '';
610: }
611:
612: sub unset_permissions {
613: undef($Apache::lonhomework::queuegrade);
614: undef($Apache::lonhomework::modifygrades);
615: undef($Apache::lonhomework::viewgrades);
616: undef($Apache::lonhomework::browse);
617: }
618:
619: sub setupheader {
620: my $request=$_[0];
621: &Apache::loncommon::content_type($request,'text/html');
622: if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
623: &Apache::loncommon::no_cache($request);
624: }
625: # $request->set_last_modified(&Apache::lonnet::metadata($request->uri,
626: # 'lastrevisiondate'));
627: $request->send_http_header;
628: return OK if $request->header_only;
629: return ''
630: }
631:
632: sub handle_save_or_undo {
633: my ($request,$problem,$result) = @_;
634:
635: my $file = &Apache::lonnet::filelocation("",$request->uri);
636: my $filebak =$file.".bak";
637: my $filetmp =$file.".tmp";
638: my $error=0;
639: if (($env{'form.problemmode'} eq 'undo') || ($env{'form.problemmode'} eq 'undoxml')) {
640: my $error=0;
641: if (!&File::Copy::copy($file,$filetmp)) { $error=1; }
642: if ((!$error) && (!&File::Copy::copy($filebak,$file))) { $error=1; }
643: if ((!$error) && (!&File::Copy::move($filetmp,$filebak))) { $error=1; }
644: if (!$error) {
645: &Apache::lonxml::info("<p><b>".
646: &mt("Undid changes, Switched [_1] and [_2]",
647: '<span class="LC_filename">'.$filebak.
648: '</span>',
649: '<span class="LC_filename">'.$file.
650: '</span>')."</b></p>");
651: } else {
652: &Apache::lonxml::info("<p><span class=\"LC_error\">".
653: &mt("Unable to undo, unable to switch [_1] and [_2]",
654: '<span class="LC_filename">'.
655: $filebak.'</span>',
656: '<span class="LC_filename">'.
657: $file.'</span>')."</span></p>");
658: $error=1;
659: }
660: } else {
661: &Apache::lonnet::correct_line_ends($result);
662:
663: my $fs=Apache::File->new(">$filebak");
664: if (defined($fs)) {
665: print $fs $$problem;
666: } else {
667: &Apache::lonxml::info("<span class=\"LC_error\">".
668: &mt("Unable to make backup [_1]",
669: '<span class="LC_filename">'.
670: $filebak.'</span>')."</span>");
671: $error=2;
672: }
673: my $fh=Apache::File->new(">$file");
674: if (defined($fh)) {
675: print $fh $$result;
676: } else {
677: &Apache::lonxml::info('<span class="LC_error">'.
678: &mt("Unable to write to [_1]",
679: '<span class="LC_filename">'.
680: $file.'</span>').
681: '</span>');
682: $error|=4;
683: }
684: }
685: return $error;
686: }
687:
688: sub analyze_header {
689: my ($request) = @_;
690: my $js = &Apache::structuretags::setmode_javascript();
691:
692: # Breadcrumbs
693: my $brcrum = [{'href' => &Apache::loncommon::authorspace(),
694: 'text' => 'Construction Space'},
695: {'href' => '',
696: 'text' => 'Problem Testing'},
697: {'href' => '',
698: 'text' => 'Analyzing a problem'}];
699:
700: my $result =
701: &Apache::loncommon::start_page('Analyzing a problem',
702: $js,
703: {'bread_crumbs' => $brcrum,})
704: .&Apache::loncommon::head_subbox(
705: &Apache::loncommon::CSTR_pageheader());
706: $result .=
707: &Apache::lonxml::message_location().'
708: <form name="lonhomework" method="post" action="'.
709: &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
710: '<input type="hidden" name="problemmode" value="'.
711: $env{'form.problemmode'}.'" />'.
712: &Apache::structuretags::remember_problem_state().'
713: <div class="LC_edit_problem_analyze_header">
714: <input type="button" name="submitmode" value="'.&mt("EditXML").'" '.
715: 'onclick="javascript:setmode(this.form,'."'editxml'".')" />
716: <input type="button" name="submitmode" value="'.&mt('Edit').'" '.
717: 'onclick="javascript:setmode(this.form,'."'edit'".')" />
718: <hr />
719: <input type="button" name="submitmode" value="'.&mt("View").'" '.
720: 'onclick="javascript:setmode(this.form,'."'view'".')" />
721: <hr />
722: </div>
723: </form>';
724: &Apache::lonxml::add_messages(\$result);
725: $request->print($result);
726: $request->rflush();
727: }
728:
729: sub analyze_footer {
730: my ($request) = @_;
731: $request->print(&Apache::loncommon::end_page());
732: $request->rflush();
733: }
734:
735: sub analyze {
736: my ($request,$file) = @_;
737: &Apache::lonxml::debug("Analyze");
738: my $result;
739: my %overall;
740: my %seedexample;
741: my %allparts;
742: my $rndseed=$env{'form.rndseed'};
743: &analyze_header($request);
744: my %prog_state=
745: &Apache::lonhtmlcommon::Create_PrgWin($request,&mt('Analyze Progress'),
746: &mt('Getting Problem Variants'),
747: $env{'form.numtoanalyze'},
748: 'inline',undef);
749: for(my $i=1;$i<$env{'form.numtoanalyze'}+1;$i++) {
750: &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,
751: &mt('last problem'));
752: if (&Apache::loncommon::connection_aborted($request)) { return; }
753: my $thisseed=$i+$rndseed;
754: my $subresult=&Apache::lonnet::ssi($request->uri,
755: ('grade_target' => 'analyze'),
756: ('rndseed' => $thisseed));
757: (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2);
758: my %analyze=&Apache::lonnet::str2hash($subresult);
759: my @parts;
760: if (defined(@{ $analyze{'parts'} })) {
761: @parts=@{ $analyze{'parts'} };
762: }
763: foreach my $part (@parts) {
764: if (!exists($allparts{$part})) {$allparts{$part}=1;};
765: if ($analyze{$part.'.type'} eq 'numericalresponse' ||
766: $analyze{$part.'.type'} eq 'stringresponse' ||
767: $analyze{$part.'.type'} eq 'formularesponse' ) {
768: foreach my $name (keys(%{ $analyze{$part.'.answer'} })) {
769: my $i=0;
770: foreach my $answer_part (@{ $analyze{$part.'.answer'}{$name} }) {
771: push( @{ $overall{$part.'.answer'}[$i] },
772: $answer_part);
773: my $concatanswer= join("\0",@{ $answer_part });
774: if (($concatanswer eq '') || ($concatanswer=~/^\@/)) {
775: $answer_part = ['<span class="LC_error">'.&mt('Error').'</span>'];
776: }
777: $seedexample{join("\0",$part,$i,@{$answer_part})}=
778: $thisseed;
779: $i++;
780: }
781: }
782: if (!keys(%{ $analyze{$part.'.answer'} })) {
783: my $answer_part =
784: ['<span class="LC_error">'.&mt('Error').'</span>'];
785: $seedexample{join("\0",$part,0,@{$answer_part})}=
786: $thisseed;
787: push( @{ $overall{$part.'.answer'}[0] },
788: $answer_part);
789: }
790: }
791: }
792: }
793: &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,
794: &mt('Analyzing Results'));
795: $request->print('<hr />'
796: .'<h3>'
797: .&mt('List of possible answers')
798: .'</h3>'
799: );
800: foreach my $part (sort(keys(%allparts))) {
801: if (defined(@{ $overall{$part.'.answer'} })) {
802: for (my $i=0;$i<scalar(@{ $overall{$part.'.answer'} });$i++) {
803: my $num_cols=scalar(@{ $overall{$part.'.answer'}[$i][0] });
804: $request->print(&Apache::loncommon::start_data_table()
805: .&Apache::loncommon::start_data_table_header_row()
806: .'<th colspan="'.($num_cols+1).'">'
807: .&mt('Part').' '.$part
808: );
809: if (scalar(@{ $overall{$part.'.answer'} }) > 1) {
810: $request->print(' '.&mt('Answer [_1]',$i+1));
811: }
812: $request->print('</th>'
813: .&Apache::loncommon::end_data_table_header_row()
814: );
815: my %frequency;
816: foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'}[$i] })) {
817: $frequency{join("\0",@{ $answer })}++;
818: }
819: $request->print(&Apache::loncommon::start_data_table_header_row()
820: .'<th colspan="'.($num_cols).'">'.&mt('Answer').'</th>'
821: .'<th>'.&mt('Frequency').'<br />'
822: .'('.&mt('click for example').')</th>'
823: .&Apache::loncommon::end_data_table_header_row()
824: );
825: foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) {
826: $request->print(&Apache::loncommon::start_data_table_row()
827: .'<td>'
828: .join('</td><td>',split("\0",$answer))
829: .'</td>'
830: .'<td>'
831: .'<a href="'.$request->uri.'?rndseed='.$seedexample{join("\0",$part,$i,$answer)}.'">'.$frequency{$answer}.'</a>'
832: .'</td>'
833: .&Apache::loncommon::end_data_table_row()
834: );
835: }
836: $request->print(&Apache::loncommon::end_data_table());
837: }
838: } else {
839: $request->print('<p class="LC_warning">'
840: .&mt('Response [_1] is not analyzable at this time.',$part)
841: .'</p>'
842: );
843: }
844: }
845: if (scalar(keys(%allparts)) == 0 ) {
846: $request->print('<p class="LC_warning">'
847: .&mt('Found no analyzable responses in this problem.'
848: .' Currently only Numerical, Formula and String response styles are supported.')
849: .'</p>'
850: );
851: }
852: &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);
853: &analyze_footer($request);
854: &Apache::lonhomework::showhash(%overall);
855: return $result;
856: }
857:
858: {
859: my $show_problem_status;
860: sub reset_show_problem_status {
861: undef($show_problem_status);
862: }
863:
864: sub set_show_problem_status {
865: my ($new_status) = @_;
866: $show_problem_status = lc($new_status);
867: }
868:
869: sub hide_problem_status {
870: return ($show_problem_status eq 'no'
871: || $show_problem_status eq 'no_feedback_ever');
872: }
873:
874: sub show_problem_status {
875: return ($show_problem_status eq 'yes'
876: || $show_problem_status eq 'answer'
877: || $show_problem_status eq '');
878: }
879:
880: sub show_some_problem_status {
881: return ($show_problem_status eq 'no');
882: }
883:
884: sub show_no_problem_status {
885: return ($show_problem_status eq 'no_feedback_ever');
886: }
887:
888: sub show_answer_problem_status {
889: return ($show_problem_status eq 'answer');
890: }
891: }
892:
893: sub editxmlmode {
894: my ($request,$file) = @_;
895: my $result;
896: my $problem=&Apache::lonnet::getfile($file);
897: if ($problem eq -1) {
898: &Apache::lonxml::error(
899: '<b> '
900: .&mt('Unable to find [_1]',
901: '<span class="LC_filename">'.$file.'</span>')
902: .'</b>');
903:
904: $problem='';
905: }
906:
907: if (($env{'form.problemmode'} eq 'saveeditxml') ||
908: ($env{'form.problemmode'} eq 'saveviewxml') ||
909: ($env{'form.problemmode'} eq 'undoxml')) {
910: my $error=&handle_save_or_undo($request,\$problem,
911: \$env{'form.editxmltext'});
912: if (!$error) { $problem=&Apache::lonnet::getfile($file); }
913: }
914: &Apache::lonhomework::showhashsubset(\%env,'^form');
915: if ($env{'form.problemmode'} eq 'saveviewxml') {
916: &Apache::lonhomework::showhashsubset(\%env,'^form');
917: $env{'form.problemmode'}='view';
918: &renderpage($request,$file);
919: } else {
920: my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem);
921: if ($cols > 80) { $cols = 80; }
922: if ($cols < 70) { $cols = 70; }
923: if ($rows < 20) { $rows = 20; }
924: my $js =
925: &Apache::edit::js_change_detection().
926: &Apache::loncommon::resize_textarea_js().
927: &Apache::structuretags::setmode_javascript().
928: &Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
929:
930: # Breadcrumbs
931: my $brcrum = [{'href' => &Apache::loncommon::authorspace(),
932: 'text' => 'Construction Space'},
933: {'href' => '',
934: 'text' => 'Problem Editing'}];
935:
936: my $start_page =
937: &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js,
938: {'no_auto_mt_title' => 1,
939: 'only_body' => 0,
940: 'add_entries' => {
941: 'onresize' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
942: 'onload' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
943: },
944: 'bread_crumbs' => $brcrum,
945: });
946:
947: $result=$start_page
948: .&Apache::loncommon::head_subbox(
949: &Apache::loncommon::CSTR_pageheader());
950: $result.=&renderpage($request,$file,['no_output_web'],1).
951: '<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="post" action="'.
952: &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
953: &Apache::structuretags::remember_problem_state().'
954: <div class="LC_edit_problem_editxml_header">
955: <table class="LC_edit_problem_header_title"><tr><td>
956: <h2>'.&mt('Problem Editing').' '.&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index').'</h2>
957: </td><td align="right">
958: '.&Apache::loncommon::helpLatexCheatsheet('Problem_LON-CAPA_Functions','Script Functions').'
959: </td></tr>
960: </table>';
961:
962: $result.='<input type="hidden" name="problemmode" value="saveedit" />'.
963: &Apache::structuretags::problem_edit_buttons('editxml');
964:
965: $result.='<hr style="clear:both;" />'.&Apache::lonxml::message_location().'</div>'.
966: '<textarea '.&Apache::edit::element_change_detection().
967: ' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '.
968: ' name="editxmltext" id="LC_editxmltext">'.
969: &HTML::Entities::encode($problem,'<>&"').'</textarea>
970: <div id="LC_aftertextarea">
971: </div>
972: </form>'.&Apache::loncommon::end_page();
973: &Apache::lonxml::add_messages(\$result);
974: $request->print($result);
975: }
976: return '';
977: }
978:
979: #
980: # Render the page in whatever target desired.
981: #
982: sub renderpage {
983: my ($request,$file,$targets,$return_string) = @_;
984:
985: my @targets = @{$targets || [&get_target()]};
986: &Apache::lonhomework::showhashsubset(\%env,'form.');
987: &Apache::lonxml::debug("Running targets ".join(':',@targets));
988:
989: my $overall_result;
990: foreach my $target (@targets) {
991: # FIXME need to do something intelligent when a problem goes
992: # from viewable to not viewable due to map conditions
993: #&setuppermissions();
994: #if ( $Apache::lonhomework::browse ne '2'
995: # && $Apache::lonhomework::browse ne 'F' ) {
996: # $request->print(" You most likely shouldn't see me.");
997: #}
998: #my $t0 = [&gettimeofday()];
999: my $output=1;
1000: if ($target eq 'no_output_web') {
1001: $target = 'web'; $output=0;
1002: }
1003: my $problem=&Apache::lonnet::getfile($file);
1004: my $result;
1005: if ($problem eq -1) {
1006: $problem='';
1007: my $filename=(split('/',$file))[-1];
1008: my $error =
1009: "<b> ".&mt('Unable to find [_1]',
1010: '<span class="LC_filename">'.$filename.'</span>')
1011: ."</b>";
1012: $result.=
1013: &Apache::loncommon::simple_error_page($request,'Not available',
1014: $error);
1015: return;
1016: }
1017:
1018: my %mystyle;
1019: if ($target eq 'analyze') { %Apache::lonhomework::analyze=(); }
1020: if ($target eq 'answer') { &showhash(%Apache::lonhomework::history); }
1021: if ($target eq 'web') {&Apache::lonhomework::showhashsubset(\%env,'^form');}
1022:
1023: &Apache::lonxml::debug("Should be parsing now");
1024: $result .= &Apache::lonxml::xmlparse($request, $target, $problem,
1025: &setup_vars($target),%mystyle);
1026: &finished_parsing();
1027: if (!$output) { $result = ''; }
1028: #$request->print("Result follows:");
1029: if ($target eq 'modified') {
1030: &handle_save_or_undo($request,\$problem,\$result);
1031: } else {
1032: if ($target eq 'analyze') {
1033: $result=&Apache::lonnet::hashref2str(\%Apache::lonhomework::analyze);
1034: undef(%Apache::lonhomework::analyze);
1035: }
1036: #my $td=&tv_interval($t0);
1037: #if ( $Apache::lonxml::debug) {
1038: #$result =~ s:</body>::;
1039: #$result.="<br />Spent $td seconds processing target $target\n</body>";
1040: #}
1041: # $request->print($result);
1042: $overall_result.=$result;
1043: # $request->rflush();
1044: }
1045: #$request->print(":Result ends");
1046: #my $td=&tv_interval($t0);
1047: }
1048: if (!$return_string) {
1049: &Apache::lonxml::add_messages(\$overall_result);
1050: $request->print($overall_result);
1051: $request->rflush();
1052: } else {
1053: return $overall_result;
1054: }
1055: }
1056:
1057: sub finished_parsing {
1058: undef($Apache::lonhomework::parsing_a_problem);
1059: undef($Apache::lonhomework::parsing_a_task);
1060: }
1061:
1062: sub get_template_list {
1063: my ($extension) = @_;
1064: my $result;
1065: my @allnames;
1066: &Apache::lonxml::debug("Looking for :$extension:");
1067: my $glob_extension = $extension;
1068: if ($extension eq 'survey' || $extension eq 'exam') {
1069: $glob_extension = 'problem';
1070: }
1071: my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}.
1072: '/templates/*.'.$glob_extension);
1073: @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')),
1074: (&Apache::lonnet::metadata($_, 'category')?&mt(&Apache::lonnet::metadata($_, 'category')):&mt('Miscellaneous')),
1075: &mt(&Apache::lonnet::metadata($_, 'help'))]} (@files);
1076: @files = sort {$a->[2].$a->[1] cmp $b->[2].$b->[1]} (@files);
1077: my ($midpoint,$seconddiv,$numfiles);
1078: $numfiles = 0;
1079: foreach my $file (@files) {
1080: next if ($file->[1] !~ /\S/);
1081: $numfiles ++;
1082: }
1083: if ($numfiles > 0) {
1084: $result = '<div class="LC_left_float">';
1085: $midpoint = int($numfiles/2);
1086: if ($numfiles%2) {
1087: $midpoint ++;
1088: }
1089: }
1090: my $count = 0;
1091: my $currentcategory='';
1092: my $first = 1;
1093: foreach my $file (@files) {
1094: next if ($file->[1] !~ /\S/);
1095: if ($file->[2] ne $currentcategory) {
1096: $currentcategory=$file->[2];
1097: if ((!$seconddiv) && ($count >= $midpoint)) {
1098: $result .= '</div></div>'."\n".'<div class="LC_left_float">'."\n";
1099: $seconddiv = 1;
1100: } elsif (!$first) {
1101: $result.='</div>'."\n";
1102: } else {
1103: $first = 0;
1104: }
1105: $result.= '<div class="LC_Box">'."\n"
1106: .'<h3 class="LC_hcell">'.$currentcategory.'</h3>'."\n";
1107: $count++;
1108: }
1109: $result .=
1110: '<label><input type="radio" name="template" value="'.$file->[0].'" />'.
1111: $file->[1].'</label>';
1112: if ($file->[3]) {
1113: $result.=&Apache::loncommon::help_open_topic($file->[3]);
1114: }
1115: my $filename=$file->[0];
1116: $filename=~s/^\/home\/httpd\/html//;
1117: $result.=' <span class="LC_fontsize_small">'
1118: .'<a href="'.$filename.'?inhibitmenu=yes" target="sample">'.&mt('Example').'</a>'
1119: .'</span><br />'."\n";
1120: $count ++;
1121: }
1122: if ($numfiles > 0) {
1123: $result .= '</div></div>'."\n".'<div class="LC_clear_float_footer"></div>'."\n";
1124: }
1125: return $result;
1126: }
1127:
1128: sub newproblem {
1129: my ($request) = @_;
1130:
1131: if ($env{'form.template'}) {
1132: my $file = $env{'form.template'};
1133: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1134: &File::Copy::copy($file,$dest);
1135: &renderpage($request,$dest);
1136: return;
1137: }
1138:
1139: my ($extension) = ($request->uri =~ m/\.(\w+)$/);
1140: &Apache::lonxml::debug("Looking for :$extension:");
1141: my $templatelist=&get_template_list($extension);
1142: if ($env{'form.newfile'} && !$templatelist) {
1143: # no templates found
1144: my $templatefilename =
1145: $request->dir_config('lonIncludes').'/templates/blank.'.$extension;
1146: &Apache::lonxml::debug("$templatefilename");
1147: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1148: &File::Copy::copy($templatefilename,$dest);
1149: &renderpage($request,$dest);
1150: } else {
1151: my $url=&HTML::Entities::encode($request->uri,'<>&"');
1152: my $shownurl=$url;
1153: $shownurl=~s-^/~-/priv/-;
1154: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1155: my $errormsg;
1156: my $instructions;
1157: my $brcrum = [{'href' => &Apache::loncommon::authorspace(),
1158: 'text' => 'Construction Space'},
1159: {'href' => '',
1160: 'text' => "Create New $extension"}];
1161: my $start_page =
1162: &Apache::loncommon::start_page("Create New $extension",
1163: undef,
1164: {'bread_crumbs' => $brcrum,});
1165: $request->print(
1166: $start_page
1167: .&Apache::loncommon::head_subbox(
1168: &Apache::loncommon::CSTR_pageheader())
1169: .'<h1>'.&mt("Creating a new $extension resource.")."</h1>
1170: $errormsg
1171: ".&mt("The requested file [_1] currently does not exist.",
1172: '<span class="LC_filename">'.$shownurl.'</span>').'
1173: <p class="LC_info">
1174: '.&mt("To create a new $extension, select a template from the".
1175: " list below. Then click on the \"Create $extension\" button.").'
1176: </p><div><form action="'.$url.'" method="post">');
1177:
1178: if (defined($templatelist)) {
1179: $request->print($templatelist);
1180: }
1181: $request->print('<br /><input type="submit" name="newfile" value="'.
1182: &mt("Create $extension").'" />');
1183: $request->print('</form></div>'.&Apache::loncommon::end_page());
1184: }
1185: return;
1186: }
1187:
1188: sub update_construct_style {
1189: if ($env{'request.state'} eq "construct"
1190: && $env{'form.problemmode'} eq 'view'
1191: && defined($env{'form.submitted'})
1192: && !defined($env{'form.resetdata'})
1193: && !defined($env{'form.newrandomization'})) {
1194: if ((!$env{'form.style_file'} && $env{'construct.style'})
1195: ||$env{'form.clear_style_file'}) {
1196: &Apache::lonnet::delenv('construct.style');
1197: } elsif ($env{'form.style_file'}
1198: && $env{'construct.style'} ne $env{'form.style_file'}) {
1199: &Apache::lonnet::appenv({'construct.style' =>
1200: $env{'form.style_file'}});
1201: }
1202: }
1203: }
1204:
1205:
1206: sub handler {
1207: #my $t0 = [&gettimeofday()];
1208: my $request=$_[0];
1209: $Apache::lonxml::request=$request;
1210: $Apache::lonxml::debug=$env{'user.debug'};
1211: $env{'request.uri'}=$request->uri;
1212: &setuppermissions();
1213:
1214: my $file=&Apache::lonnet::filelocation("",$request->uri);
1215:
1216: #check if we know where we are
1217: if ($env{'request.course.fn'} && !&Apache::lonnet::symbread()) {
1218: # if we are browsing we might not be able to know where we are
1219: if ($Apache::lonhomework::browse ne 'F' &&
1220: $env{'request.state'} ne "construct") {
1221: #should know where we are, so ask
1222: &unset_permissions();
1223: $request->internal_redirect('/adm/ambiguous');
1224: return OK;
1225: }
1226: }
1227: if (&setupheader($request)) {
1228: &unset_permissions();
1229: return OK;
1230: }
1231: &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade");
1232: &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});
1233: my ($symb) = &Apache::lonnet::whichuser();
1234: &Apache::lonxml::debug('symb is '.$symb);
1235: if ($env{'request.state'} eq "construct") {
1236: if ( -e $file ) {
1237: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1238: ['problemmode']);
1239: if (!(defined $env{'form.problemmode'})) {
1240: #first visit to problem in construction space
1241: $env{'form.problemmode'}= 'view';
1242: &renderpage($request,$file);
1243: } elsif (($env{'form.problemmode'} eq 'editxml') ||
1244: ($env{'form.problemmode'} eq 'saveeditxml') ||
1245: ($env{'form.problemmode'} eq 'saveviewxml') ||
1246: ($env{'form.problemmode'} eq 'undoxml')) {
1247: &editxmlmode($request,$file);
1248: } elsif ($env{'form.problemmode'} eq 'calcanswers') {
1249: &analyze($request,$file);
1250: } else {
1251: &update_construct_style();
1252: &renderpage($request,$file);
1253: }
1254: } else {
1255: # requested file doesn't exist in contruction space
1256: &newproblem($request);
1257: }
1258: } else {
1259: # just render the page normally outside of construction space
1260: &Apache::lonxml::debug("not construct");
1261: &renderpage($request,$file);
1262: }
1263: #my $td=&tv_interval($t0);
1264: #&Apache::lonxml::debug("Spent $td seconds processing");
1265: # always turn off debug messages
1266: $Apache::lonxml::debug=0;
1267: &unset_permissions();
1268: return OK;
1269:
1270: }
1271:
1272: 1;
1273: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>