Annotation of loncom/homework/lonhomework.pm, revision 1.88
1.63 albertel 1: # The LearningOnline Network with CAPA
1.52 albertel 2: # The LON-CAPA Homework handler
1.63 albertel 3: #
1.88 ! albertel 4: # $Id: lonhomework.pm,v 1.87 2002/09/07 18:21:44 www 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/
27: #
1.52 albertel 28: # Guy Albertelli
1.17 www 29: # 11/30 Gerd Kortemeyer
1.56 www 30: # 6/1,8/17,8/18 Gerd Kortemeyer
1.82 bowersj2 31: # 7/18 Jeremy Bowers
1.1 albertel 32:
33: package Apache::lonhomework;
34: use strict;
1.73 albertel 35: use Apache::style();
36: use Apache::lonxml();
37: use Apache::lonnet();
38: use Apache::lonplot();
39: use Apache::inputtags();
40: use Apache::structuretags();
41: use Apache::randomlabel();
42: use Apache::response();
43: use Apache::hint();
44: use Apache::outputtags();
1.83 albertel 45: use Apache::caparesponse();
46: use Apache::radiobuttonresponse();
47: use Apache::optionresponse();
48: use Apache::imageresponse();
49: use Apache::essayresponse();
50: use Apache::externalresponse();
1.26 www 51: use Apache::Constants qw(:common);
1.73 albertel 52: use HTML::Entities();
1.83 albertel 53: use Apache::loncommon();
1.47 albertel 54: #use Time::HiRes qw( gettimeofday tv_interval );
1.43 albertel 55:
1.69 harris41 56: BEGIN {
1.43 albertel 57: &Apache::lonxml::register_insert();
58: }
59:
1.5 albertel 60: sub get_target {
1.52 albertel 61: if ( $ENV{'request.state'} eq "published") {
1.66 albertel 62: if ( defined($ENV{'form.grade_target'})
63: && ($Apache::lonhomework::viewgrades == 'F' )) {
64: return ($ENV{'form.grade_target'});
65: }
1.62 albertel 66: if ( defined($ENV{'form.submitted'})) {
1.52 albertel 67: return ('grade', 'web');
68: } else {
69: return ('web');
70: }
71: } elsif ($ENV{'request.state'} eq "construct") {
1.74 albertel 72: if ( defined($ENV{'form.grade_target'}) ) {
73: return ($ENV{'form.grade_target'});
74: }
1.62 albertel 75: if ( defined($ENV{'form.preview'})) {
76: if ( defined($ENV{'form.submitted'})) {
1.52 albertel 77: return ('grade', 'web');
78: } else {
79: return ('web');
80: }
81: } else {
1.88 ! albertel 82: if ( $ENV{'form.problemmode'} eq 'View' ||
! 83: $ENV{'form.problemmode'} eq 'Discard Edits and View') {
1.62 albertel 84: if ( defined($ENV{'form.submitted'}) &&
85: (!defined($ENV{'form.resetdata'})) ) {
1.60 albertel 86: return ('grade', 'web','answer');
1.42 albertel 87: } else {
1.60 albertel 88: return ('web','answer');
1.42 albertel 89: }
1.52 albertel 90: } elsif ( $ENV{'form.problemmode'} eq 'Edit' ) {
91: if ( $ENV{'form.submitted'} eq 'edit' ) {
1.80 albertel 92: if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) {
1.81 albertel 93: return ('modified','web','answer');
1.80 albertel 94: } else {
95: return ('modified','edit');
96: }
1.42 albertel 97: } else {
1.52 albertel 98: return ('edit');
1.42 albertel 99: }
1.52 albertel 100: } else {
101: return ('web');
102: }
1.15 albertel 103: }
1.52 albertel 104: }
105: return ();
1.5 albertel 106: }
107:
1.3 albertel 108: sub setup_vars {
1.52 albertel 109: my ($target) = @_;
110: return ';'
1.11 albertel 111: # return ';$external::target='.$target.';';
1.2 albertel 112: }
113:
114: sub send_header {
1.52 albertel 115: my ($request)= @_;
116: $request->print(&Apache::lontexconvert::header());
1.16 albertel 117: # $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');
1.2 albertel 118: }
119:
1.36 albertel 120: sub createmenu {
1.52 albertel 121: my ($which,$request)=@_;
122: if ($which eq 'grade') {
123: $request->print('<script language="JavaScript">
124: hwkmenu=window.open("/res/adm/pages/homeworkmenu.html","homeworkremote",
125: "height=350,width=150,menubar=no");
126: </script>');
127: }
1.36 albertel 128: }
129:
1.2 albertel 130: sub send_footer {
1.52 albertel 131: my ($request)= @_;
1.16 albertel 132: # $request->print('</form>');
1.52 albertel 133: $request->print(&Apache::lontexconvert::footer());
1.2 albertel 134: }
135:
1.52 albertel 136: $Apache::lonxml::browse='';
1.53 www 137:
138: sub check_access {
1.52 albertel 139: my ($id) = @_;
140: my $date ='';
141: my $status = '';
142: my $datemsg = '';
143: my $lastdate = '';
144: my $temp;
145: my $type;
146: my $passed;
147: &Apache::lonxml::debug("checking for part :$id:");
1.73 albertel 148: &Apache::lonxml::debug("time:".time);
1.52 albertel 149: foreach $temp ("opendate","duedate","answerdate") {
150: $lastdate = $date;
151: $date = &Apache::lonnet::EXT("resource.$id.$temp");
1.87 www 152: my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type");
153: if ($thistype eq 'date_interval') {
154: if ($temp eq 'opendate') {
155: $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date;
156: }
157: if ($temp eq 'answerdate') {
158: $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date;
159: }
160: }
1.52 albertel 161: &Apache::lonxml::debug("found :$date: for :$temp:");
162: if ($date eq '') {
163: $date = "an unknown date"; $passed = 0;
164: } elsif ($date eq 'con_lost') {
165: $date = "an indeterminate date"; $passed = 0;
166: } else {
167: if (time < $date) { $passed = 0; } else { $passed = 1; }
168: $date = localtime $date;
1.51 harris41 169: }
1.52 albertel 170: if (!$passed) { $type=$temp; last; }
171: }
172: &Apache::lonxml::debug("have :$type:$passed:");
173: if ($passed) {
174: $status='SHOW_ANSWER';
175: $datemsg=$date;
176: } elsif ($type eq 'opendate') {
177: $status='CLOSED';
178: $datemsg = "will open on $date";
179: } elsif ($type eq 'duedate') {
180: $status='CAN_ANSWER';
181: $datemsg = "is due at $date";
182: } elsif ($type eq 'answerdate') {
183: $status='CLOSED';
184: $datemsg = "was due on $lastdate, and answers will be available on $date";
185: }
186: if ($status eq 'CAN_ANSWER') {
187: #check #tries
188: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
189: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
190: if ( $tries eq '' ) { $tries = '0'; }
191: if ( $maxtries eq '' ) { $maxtries = '2'; }
192: if ($tries >= $maxtries) { $status = 'CANNOT_ANSWER'; }
193: }
1.54 www 194:
1.56 www 195: if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') &&
196: (!$Apache::lonhomework::history{"resource.0.outtoken"})) {
1.54 www 197: return ('UNCHECKEDOUT','needs to be checked out');
198: }
199:
200:
1.52 albertel 201: &Apache::lonxml::debug("sending back :$status:$datemsg:");
202: if (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED')) {
203: &Apache::lonxml::debug("should be allowed to browse a resource when closed");
204: $status='CAN_ANSWER';
205: $datemsg='is closed but you are allowed to view it';
206: }
207: if ($ENV{'request.state'} eq "construct") {
208: &Apache::lonxml::debug("in construction ignoring dates");
209: $status='CAN_ANSWER';
210: $datemsg='is in under construction';
211: }
212: return ($status,$datemsg);
1.20 albertel 213: }
214:
1.41 albertel 215: sub showhash {
1.52 albertel 216: my (%hash) = @_;
1.79 albertel 217: &showhashsubset(\%hash,'');
218: return '';
219: }
220:
221: sub showhashsubset {
222: my ($hash,$keyre) = @_;
1.52 albertel 223: my $resultkey;
1.79 albertel 224: foreach $resultkey (sort keys %$hash) {
225: if ($resultkey =~ /$keyre/) {
226: if (ref($$hash{$resultkey})) {
227: if ($$hash{$resultkey} =~ /ARRAY/ ) {
228: my $string="$resultkey ---- (";
229: foreach my $elm (@{ $$hash{$resultkey} }) {
230: $string.="$elm,";
231: }
232: chop($string);
233: &Apache::lonxml::debug("$string)");
234: } else {
235: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
1.73 albertel 236: }
237: } else {
1.79 albertel 238: &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
1.73 albertel 239: }
240: }
1.52 albertel 241: }
242: &Apache::lonxml::debug("\n<br />restored values^</br>\n");
243: return '';
1.41 albertel 244: }
245:
246: sub setuppermissions {
1.52 albertel 247: $Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'});
248: $Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
249: return ''
1.41 albertel 250: }
251:
252: sub setupheader {
1.52 albertel 253: my $request=$_[0];
254: if ($ENV{'browser.mathml'}) {
255: $request->content_type('text/xml');
256: } else {
257: $request->content_type('text/html');
258: }
1.68 albertel 259: if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
260: &Apache::loncommon::no_cache($request);
261: }
1.52 albertel 262: $request->send_http_header;
263: return OK if $request->header_only;
264: return ''
1.41 albertel 265: }
1.35 albertel 266:
1.47 albertel 267: sub handle_save_or_undo {
1.52 albertel 268: my ($request,$problem,$result) = @_;
1.70 albertel 269: my $file = &Apache::lonnet::filelocation("",$request->uri);
270: my $filebak =$file.".bak";
271: my $filetmp =$file.".tmp";
1.64 albertel 272: my $error=0;
1.52 albertel 273:
274: if ($ENV{'form.Undo'} eq 'undo') {
1.70 albertel 275: my $error=0;
276: if (!copy($file,$filetmp)) { $error=1; }
277: if ((!$error) && (!copy($filebak,$file))) { $error=1; }
278: if ((!$error) && (!move($filetmp,$filebak))) { $error=1; }
279: if (!$error) {
280: $request->print("<p><b>Undid changes, Switched $filebak and $file</b></p>");
1.52 albertel 281: } else {
1.70 albertel 282: $request->print("<p><font color=\"red\" size=\"+1\"><b>Unable to undo, unable to switch $filebak and $file</b></font></p>");
1.64 albertel 283: $error=1;
1.52 albertel 284: }
285: } else {
1.70 albertel 286: my $fs=Apache::File->new(">$filebak");
1.52 albertel 287: if (defined($fs)) {
288: print $fs $$problem;
1.70 albertel 289: $request->print("<b>Making Backup to $filebak</b><br />");
1.52 albertel 290: } else {
1.70 albertel 291: $request->print("<font color=\"red\" size=\"+1\"><b>Unable to make backup $filebak</b></font>");
1.64 albertel 292: $error=2;
1.52 albertel 293: }
1.70 albertel 294: my $fh=Apache::File->new(">$file");
1.52 albertel 295: if (defined($fh)) {
296: print $fh $$result;
1.70 albertel 297: $request->print("<b>Saving Modifications to $file</b><br />");
1.47 albertel 298: } else {
1.70 albertel 299: $request->print("<font color=\"red\" size=\"+1\"><b>Unable to write to $file</b></font>");
1.64 albertel 300: $error|=4;
1.47 albertel 301: }
1.52 albertel 302: }
1.64 albertel 303: return $error;
304: }
305:
1.74 albertel 306: sub analyze {
307: my ($request,$file) = @_;
308: &Apache::lonxml::debug("Analyze");
309: my $result=&Apache::lonnet::ssi($request->uri,('grade_target' => 'analyze'));
310: &Apache::lonxml::debug(":$result:");
311: (my $garbage,$result)=split(/_HASH_REF__/,$result,2);
312: &showhash(&Apache::lonnet::str2hash($result));
313: return $result;
314: }
315:
1.64 albertel 316: sub editxmlmode {
317: my ($request,$file) = @_;
318: my $result;
319: my $problem=&Apache::lonnet::getfile($file);
320: if ($problem == -1) {
321: &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
322: $problem='';
323: }
324: if (defined($ENV{'form.editxmltext'}) || defined($ENV{'form.Undo'})) {
325: my $error=&handle_save_or_undo($request,\$problem,
326: \$ENV{'form.editxmltext'});
327: if (!$error) { $problem=&Apache::lonnet::getfile($file); }
328: }
1.80 albertel 329: &Apache::lonhomework::showhashsubset(\%ENV,'^form');
330: if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) {
331: &Apache::lonhomework::showhashsubset(\%ENV,'^form');
332: $ENV{'form.problemmode'}='View';
333: &renderpage($request,$file);
334: } else {
335: my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem);
1.82 bowersj2 336: my $xml_help = Apache::loncommon::help_open_topic("Problem_Editor_XML_Index");
1.80 albertel 337: if ($cols > 80) { $cols = 80; }
338: $result.='<html><body bgcolor="#FFFFFF">
1.64 albertel 339: <form name="lonhomework" method="POST" action="'.
340: $ENV{'request.uri'}.'">
341: <input type="hidden" name="problemmode" value="EditXML" />
1.80 albertel 342: <input type="submit" name="problemmode" value="Discard Edits and View" />
1.64 albertel 343: <input type="submit" name="problemmode" value="Edit" />
344: <hr />
345: <input type="submit" name="submit" value="Submit Changes" />
1.80 albertel 346: <input type="submit" name="submit" value="Submit Changes and View" />
1.64 albertel 347: <input type="submit" name="Undo" value="undo" />
348: <hr />
1.82 bowersj2 349: ' . $xml_help . ' Problem Help<br>
1.64 albertel 350: <textarea rows="'.$rows.'" cols="'.$cols.'" name="editxmltext">'.
1.73 albertel 351: &HTML::Entities::encode($problem).'</textarea>
1.64 albertel 352: </form></body></html>';
1.80 albertel 353: $request->print($result);
354: }
1.64 albertel 355: return '';
1.47 albertel 356: }
357:
1.41 albertel 358: sub renderpage {
1.52 albertel 359: my ($request,$file) = @_;
360:
361: my (@targets) = &get_target();
1.70 albertel 362: &Apache::lonxml::debug("Running targets ".join(':',@targets));
1.52 albertel 363: foreach my $target (@targets) {
364: #my $t0 = [&gettimeofday()];
365: my $problem=&Apache::lonnet::getfile($file);
366: if ($problem == -1) {
367: &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
368: $problem='';
369: }
370:
371: my %mystyle;
372: my $result = '';
373: &Apache::inputtags::initialize_inputtags;
374: &Apache::edit::initialize_edit;
1.74 albertel 375: if ($target eq 'analyze') { %Apache::lonhomework::anaylze=(); }
1.52 albertel 376: if ($target eq 'web') {
1.76 albertel 377: my ($symb)=&Apache::lonxml::whichuser();
378: if ($symb eq '') {
1.52 albertel 379: if ($ENV{'request.state'} eq "construct") {
1.36 albertel 380: } else {
1.84 bowersj2 381: my $help = Apache::loncommon::help_open_topic("Ambiguous_Reference");
382: $request->print("Browsing or <a href=\"/adm/ambiguous\">ambiguous</a> reference, submissions ignored $help<br />");
1.51 harris41 383: }
1.52 albertel 384: }
385: #if ($Apache::lonhomework::viewgrades eq 'F') {&createmenu('grade',$request); }
386: }
1.85 albertel 387: if ($target eq 'answer') { &showhash(%Apache::lonhomework::history); }
388: if ($target eq 'web') {&Apache::lonhomework::showhashsubset(\%ENV,'^form');}
1.52 albertel 389:
390: my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
391: if ($default == -1) {
392: &Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
393: $default='';
394: }
1.70 albertel 395: &Apache::lonxml::debug("Should be parsing now");
1.78 albertel 396: $result = &Apache::lonxml::xmlparse($request, $target, $problem,
1.52 albertel 397: $default.&setup_vars($target),%mystyle);
398:
399: #$request->print("Result follows:");
400: if ($target eq 'modified') {
401: &handle_save_or_undo($request,\$problem,\$result);
402: } else {
1.74 albertel 403: if ($target eq 'analyze') {
404: $result=&Apache::lonnet::hashref2str(\%Apache::lonhomework::analyze);
1.75 albertel 405: undef(%Apache::lonhomework::analyze);
1.74 albertel 406: }
1.52 albertel 407: #my $td=&tv_interval($t0);
408: #if ( $Apache::lonxml::debug) {
409: #$result =~ s:</body>::;
410: #$result.="<br />Spent $td seconds processing target $target\n</body>";
411: #}
412: $request->print($result);
413: }
414: #$request->print(":Result ends");
415: #my $td=&tv_interval($t0);
416: }
1.41 albertel 417: }
418:
1.42 albertel 419: # with no arg it returns a HTML <option> list of the template titles
420: # with one arg it returns the filename associated with the arg passed
421: sub get_template_list {
1.52 albertel 422: my ($namewanted,$extension) = @_;
423: my $result;
1.85 albertel 424: my @allnames;
1.52 albertel 425: &Apache::lonxml::debug("Looking for :$extension:");
426: foreach my $file (</home/httpd/html/res/adm/includes/templates/*.$extension>) {
427: my $name=&Apache::lonnet::metadata($file,'title');
428: if ($namewanted && ($name eq $namewanted)) {
429: $result=$file;
430: last;
431: } else {
1.85 albertel 432: push (@allnames, $name);
1.42 albertel 433: }
1.52 albertel 434: }
1.86 albertel 435: if (@allnames && !$result) {
1.85 albertel 436: $result="<option>Select a $extension type</option>\n<option>".
437: join('</option><option>',sort(@allnames)).'</option>';
438: }
1.52 albertel 439: return $result;
1.42 albertel 440: }
441:
442: sub newproblem {
1.65 matthew 443: my ($request) = @_;
444: my $extension=$request->uri;
445: $extension=~s:^.*\.([\w]+)$:$1:;
446: &Apache::lonxml::debug("Looking for :$extension:");
1.85 albertel 447: if ($ENV{'form.template'} &&
448: $ENV{'form.template'} ne "Select a $extension type") {
1.65 matthew 449: use File::Copy;
450: my $file = &get_template_list($ENV{'form.template'},$extension);
451: my $dest = &Apache::lonnet::filelocation("",$request->uri);
452: copy($file,$dest);
453: &renderpage($request,$dest);
454: } elsif($ENV{'form.newfile'}) {
455: # I don't like hard-coded filenames but for now, this will work.
456: use File::Copy;
457: my $templatefilename =
1.66 albertel 458: $request->dir_config('lonIncludes').'/templates/blank.problem';
459: &Apache::lonxml::debug("$templatefilename");
1.65 matthew 460: my $dest = &Apache::lonnet::filelocation("",$request->uri);
461: copy($templatefilename,$dest);
462: &renderpage($request,$dest);
1.85 albertel 463: } else {
1.65 matthew 464: my $templatelist=&get_template_list('',$extension);
465: my $url=$request->uri;
466: my $dest = &Apache::lonnet::filelocation("",$request->uri);
1.85 albertel 467: my $instructions;
468: if ($templatelist) { $instructions=", select a template from the pull-down menu below. Then";}
1.65 matthew 469: $request->print(<<ENDNEWPROBLEM);
1.42 albertel 470: <body bgcolor="#FFFFFF">
1.85 albertel 471: The requested file $url doesn\'t exist. <br />
472: To create a new $extension$instructions click on the Create $extension button.
1.42 albertel 473: <form action="$url" method="POST">
474: ENDNEWPROBLEM
1.85 albertel 475: if (defined($templatelist)) {
476: $request->print("<select name=\"template\">$templatelist</select>");
477: }
478: $request->print("<br /><input type=\"submit\" name=\"newfile\" value=\"Create $extension\" />");
479: $request->print("</form></body>");
1.65 matthew 480: }
481: return '';
1.42 albertel 482: }
483:
484: sub view_or_edit_menu {
1.52 albertel 485: my ($request) = @_;
486: my $url=$request->uri;
487: $request->print(<<EDITMENU);
1.42 albertel 488: <body bgcolor="#FFFFFF">
489: <form action="$url" method="POST">
490: Would you like to <input type="submit" name="problemmode" value="View"> or
491: <input type="submit" name="problemmode" value="Edit"> the problem.
492: </form>
493: </body>
494: EDITMENU
495: }
496:
1.41 albertel 497: sub handler {
1.52 albertel 498: #my $t0 = [&gettimeofday()];
499: my $request=$_[0];
1.41 albertel 500:
1.52 albertel 501: if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;}
1.41 albertel 502:
503: if (&setupheader($request)) { return OK; }
1.52 albertel 504: $ENV{'request.uri'}=$request->uri;
1.41 albertel 505:
506: #setup permissions
1.52 albertel 507: $Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'});
508: $Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
509: &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:");
1.71 albertel 510: # some times multiple problemmodes are submitted, need to select
511: # the last one
1.80 albertel 512: &Apache::lonxml::debug("Problem Mode ".$ENV{'form.problemmode'});
1.72 albertel 513: if ( defined($ENV{'form.problemmode'}) &&
1.77 albertel 514: ref($ENV{'form.problemmode'}) ) {
1.80 albertel 515: &Apache::lonxml::debug("Problem Mode ".join(",",@$ENV{'form.problemmode'}));
1.72 albertel 516: my $mode=$ENV{'form.problemmode'}->[-1];
1.71 albertel 517: undef $ENV{'form.problemmode'};
1.72 albertel 518: $ENV{'form.problemmode'}=$mode;
1.71 albertel 519: }
1.64 albertel 520: &Apache::lonxml::debug("Problem Mode ".$ENV{'form.problemmode'});
1.52 albertel 521: my $file=&Apache::lonnet::filelocation("",$request->uri);
522:
523: #check if we know where we are
524: if ($ENV{'request.course.fn'} && !&Apache::lonnet::symbread()) {
525: # if we are browsing we might not be able to know where we are
526: if ($Apache::lonhomework::browse ne 'F') {
527: #should know where we are, so ask
528: $request->internal_redirect('/adm/ambiguous'); return;
1.41 albertel 529: }
1.52 albertel 530: }
1.41 albertel 531:
1.52 albertel 532: if ($ENV{'request.state'} eq "construct") {
1.62 albertel 533: if ($ENV{'form.resetdata'} eq 'Reset Submissions') {
534: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
535: &Apache::lonnet::tmpreset($symb,'',$domain,$name);
536: }
1.52 albertel 537: if ( -e $file ) {
538: if (!(defined $ENV{'form.problemmode'})) {
539: #first visit to problem in construction space
1.64 albertel 540: #&view_or_edit_menu($request);
541: $ENV{'form.problemmode'}='View';
542: &renderpage($request,$file);
543: } elsif ($ENV{'form.problemmode'} eq 'EditXML') {
544: &editxmlmode($request,$file);
1.74 albertel 545: } elsif ($ENV{'form.problemmode'} eq 'Answer Distribution') {
546: &analyze($request,$file);
1.52 albertel 547: } else {
548: &renderpage($request,$file);
1.41 albertel 549: }
550: } else {
1.52 albertel 551: # requested file doesn't exist in contruction space
552: &newproblem($request);
1.41 albertel 553: }
1.52 albertel 554: } else {
555: # just render the page normally outside of construction space
1.74 albertel 556: &Apache::lonxml::debug("not construct");
1.52 albertel 557: &renderpage($request,$file);
558: }
559: #my $td=&tv_interval($t0);
560: #&Apache::lonxml::debug("Spent $td seconds processing");
561: # &Apache::lonhomework::send_footer($request);
562: # always turn off debug messages
563: $Apache::lonxml::debug=0;
564: return OK;
565:
1.1 albertel 566: }
567:
568: 1;
569: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>