Annotation of loncom/homework/lonhomework.pm, revision 1.74

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>