Diff for /loncom/homework/structuretags.pm between versions 1.160 and 1.163

version 1.160, 2003/04/03 14:53:44 version 1.163, 2003/04/03 21:08:33
Line 107  sub page_start { Line 107  sub page_start {
     my ($symb)=&Apache::lonxml::whichuser();      my ($symb)=&Apache::lonxml::whichuser();
     if ($symb eq '') {      if ($symb eq '') {
  my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");   my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");
  $help="Browsing or <a href=\"/adm/ambiguous\">ambiguous</a> reference, submissions ignored $help<br />";   $help="Browsing resource, all submissions are temporary.<br />";
  $body_tag_start.=$help;   $body_tag_start.=$help;
     }      }
  }   }
Line 135  sub get_resource_name { Line 135  sub get_resource_name {
 sub setup_rndseed {  sub setup_rndseed {
     my ($safeeval)=@_;      my ($safeeval)=@_;
     my $rndseed;      my $rndseed;
     if ($ENV{'request.state'} eq "construct") {      my ($symb)=&Apache::lonxml::whichuser();
       if ($ENV{'request.state'} eq "construct" || $symb eq '') {
  $rndseed=$ENV{'form.rndseed'};   $rndseed=$ENV{'form.rndseed'};
  if (!$rndseed) {   if (!$rndseed) {
       $rndseed=$Apache::lonhomework::history{'rndseed'};
       if (!$rndseed) {
    $rndseed=time;
    $ENV{'form.rndseed'}=$rndseed;
       }
    }
    if ($ENV{'form.resetdata'} eq 'New Problem Variation') {
     $rndseed=time;      $rndseed=time;
     $ENV{'form.rndseed'}=$rndseed;      $ENV{'form.rndseed'}=$rndseed;
  }   }
Line 186  sub problem_web_to_edit_header { Line 194  sub problem_web_to_edit_header {
   
 sub initialize_storage {  sub initialize_storage {
     %Apache::lonhomework::results=();      %Apache::lonhomework::results=();
       %Apache::lonhomework::history=();
     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();      my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
     if ($ENV{'request.state'} eq 'construct') {      if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
  %Apache::lonhomework::history=   %Apache::lonhomework::history=
     &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name);      &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name);
  my ($temp)=keys %Apache::lonhomework::history ;   my ($temp)=keys %Apache::lonhomework::history ;
Line 210  sub finalize_storage { Line 219  sub finalize_storage {
     my ($temp) = keys %Apache::lonhomework::results;      my ($temp) = keys %Apache::lonhomework::results;
     if ( $temp ne '' ) {      if ( $temp ne '' ) {
  my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();   my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
  if ($ENV{'request.state'} eq 'construct') {   if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
       $Apache::lonhomework::results{'rndseed'}=$ENV{'form.rndseed'};
     $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,      $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
  $ENV{'request.uri'},'',$domain,$name);   $ENV{'request.uri'},'',$domain,$name);
     &Apache::lonxml::debug('Construct Store return message:'.$result);      &Apache::lonxml::debug('Construct Store return message:'.$result);
Line 251  sub start_problem { Line 261  sub start_problem {
  my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);   my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
  return '';   return '';
     }      }
 #intialize globals  #initialize globals
     $Apache::inputtags::part='0';      $Apache::inputtags::part='0';
     @Apache::inputtags::responselist = ();      @Apache::inputtags::responselist = ();
     @Apache::inputtags::previous=();      @Apache::inputtags::previous=();
     @Apache::inputtags::previous_version=();      @Apache::inputtags::previous_version=();
     $Apache::structuretags::printanswer='No';      $Apache::structuretags::printanswer='No';
       @Apache::structuretags::whileconds=();
       @Apache::structuretags::whilebody=();
       @Apache::structuretags::whileline=();
   
     if ($target ne 'analyze') {      if ($target ne 'analyze') {
  &initialize_storage();   &initialize_storage();
  if ($target eq 'web') {   if ($target eq 'web') {
Line 304  sub start_problem { Line 318  sub start_problem {
   
  #handle rand seed in construction space   #handle rand seed in construction space
  my $rndseed=&setup_rndseed($safeeval);   my $rndseed=&setup_rndseed($safeeval);
    my ($symb)=&Apache::lonxml::whichuser();
    if ($ENV{'request.state'} ne "construct" && $symb eq '') {
       $form_tag_start.='<input type="hidden" name="rndseed" value="'.
    $rndseed.'" />'.
       '<input type="submit" name="resetdata"
                                value="New Problem Variation" />';
    }
  ($status,$accessmsg) = &Apache::lonhomework::check_access('0');   ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
  push (@Apache::inputtags::status,$status);   push (@Apache::inputtags::status,$status);
  my $expression='$external::datestatus="'.$status.'";';   my $expression='$external::datestatus="'.$status.'";';
Line 582  sub end_block { Line 603  sub end_block {
 sub start_while {  sub start_while {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   
     &Apache::lonxml::debug('starting while');  
     my $result;      my $result;
     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||       if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  $target eq 'tex' || $target eq 'analyze') {   $target eq 'tex' || $target eq 'analyze') {
  my $code = $token->[2]->{'condition'};   my $code = $token->[2]->{'condition'};
   
Line 593  sub start_while { Line 613  sub start_while {
     &Apache::lonxml::default_homework_load($safeeval);      &Apache::lonxml::default_homework_load($safeeval);
  }   }
  my $result = &Apache::run::run($code,$safeeval);   my $result = &Apache::run::run($code,$safeeval);
  my $bodytext=$$parser[-1]->get_text("/while");   my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
  push( @Apache::structuretags::whilebody, $bodytext);   push( @Apache::structuretags::whilebody, $bodytext);
    push( @Apache::structuretags::whileline, $token->[5]);
    &Apache::lonxml::debug("s code $code got -$result-");
  if ( $result ) {   if ( $result ) {
     &Apache::lonxml::newparser($parser,\$bodytext);      &Apache::lonxml::newparser($parser,\$bodytext);
  }   }
Line 613  sub start_while { Line 635  sub start_while {
   
 sub end_while {  sub end_while {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     &Apache::lonxml::debug('ending while');  
   
     my $result;      my $result;
   
     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||      if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  $target eq 'tex' || $target eq 'analyze') {   $target eq 'tex' || $target eq 'analyze') {
  my $code = pop(@Apache::structuretags::whileconds);   my $code = pop(@Apache::structuretags::whileconds);
  my $bodytext = pop(@Apache::structuretags::whilebody);   my $bodytext = pop(@Apache::structuretags::whilebody);
  my $result = &Apache::run::run($code,$safeeval);   my $line = pop(@Apache::structuretags::whileline);
  if ( $result ) {   my $return = &Apache::run::run($code,$safeeval);
     &Apache::lonxml::newparser($parser,\$bodytext);   my $starttime=time;
    my $error=0;
    while ($return) {
       if (time-$starttime >
    $Apache::lonnet::perlvar{'lonScriptTimeout'}) {
    $return = 0; $error=1; next;
       }
       $result.=&Apache::scripttag::xmlparse($bodytext);
       $return = &Apache::run::run($code,$safeeval);
    }
    if ($error) {
       &Apache::lonxml::error('<pre>Code ran too long. It ran for more than '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' seconds occured while running &lt;while$gt; on line '.$line.'</pre>');
  }   }
     } elsif ($target eq "edit") {      } elsif ($target eq "edit") {
  $result.= &Apache::edit::tag_end($target,$token,'');   $result.= &Apache::edit::tag_end($target,$token,'');

Removed from v.1.160  
changed lines
  Added in v.1.163


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