File:  [LON-CAPA] / rat / lonuserstate.pm
Revision 1.43: download - view: text, annotated - select for diffs
Tue Sep 10 20:53:37 2002 UTC (21 years, 7 months ago) by www
Branches: MAIN
CVS tags: HEAD
Continuing work on simple pages and ad hoc bulletin boards.

Simple pages sort of work, bulletin boards not yet.

    1: # The LearningOnline Network with CAPA
    2: # Construct and maintain state and binary representation of course for user
    3: #
    4: # $Id: lonuserstate.pm,v 1.43 2002/09/10 20:53:37 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: # (Server for RAT Maps
   29: #
   30: # (Edit Handler for RAT Maps
   31: # (TeX Content Handler
   32: #
   33: # YEAR=2000
   34: # 05/29/00,05/30 Gerd Kortemeyer)
   35: # 7/1 Gerd Kortemeyer)
   36: # 7/1,7/3,7/4,7/7,7/8,7/10 Gerd Kortemeyer)
   37: #
   38: # 7/15,7/17,7/18,8/1,8/2,8/4,8/5,8/21,8/22,8/23,8/30,
   39: # 9/2,9/4,9/29,9/30,10/2,10/11,10/30,10/31,
   40: # 11/1,11/2,11/14,11/16,11/22,12/28,
   41: # YEAR=2001
   42: # 07/05/01,08/30,08/31 Gerd Kortemeyer
   43: # 12/16 Scott Harrison
   44: #
   45: ###
   46: 
   47: package Apache::lonuserstate;
   48: 
   49: # ------------------------------------------------- modules used by this module
   50: use strict;
   51: use Apache::Constants qw(:common :http);
   52: use Apache::File;
   53: use HTML::TokeParser;
   54: use Apache::lonnet();
   55: use Apache::loncommon();
   56: use GDBM_File;
   57: use Apache::lonmsg;
   58: use Safe;
   59: use Safe::Hole;
   60: use Opcode;
   61: 
   62: # ---------------------------------------------------- Globals for this package
   63: 
   64: my $pc;      # Package counter
   65: my %hash;    # The big tied hash
   66: my %parmhash;# The hash with the parameters
   67: my @cond;    # Array with all of the conditions
   68: my $errtext; # variable with all errors
   69: my $retfurl; # variable with the very first URL in the course
   70: my %randompick; # randomly picked resources
   71: # --------------------------------------------------------- Loads map from disk
   72: 
   73: sub loadmap { 
   74:     my $uri=shift;
   75:     if ($hash{'map_pc_'.$uri}) { return OK; }
   76: 
   77:     $pc++;
   78:     my $lpc=$pc;
   79:     $hash{'map_pc_'.$uri}=$lpc;
   80:     $hash{'map_id_'.$lpc}=$uri;
   81: 
   82: # Determine and check filename
   83:     my $fn=&Apache::lonnet::filelocation('',$uri);
   84: 
   85:     my $ispage=($fn=~/\.page$/);
   86: 
   87:     unless (($fn=~/\.sequence$/) ||
   88:             ($fn=~/\.page$/)) { 
   89:        $errtext.="Invalid map: $fn\n";
   90:        return OK; 
   91:     }
   92: 
   93:     my $instr=&Apache::lonnet::getfile($fn);
   94: 
   95:     unless ($instr == -1) {
   96: 
   97: # Successfully got file, parse it
   98: 
   99:         my $parser = HTML::TokeParser->new(\$instr);
  100:         my $token;
  101: 
  102:         my $linkpc=0;
  103: 
  104:         $fn=~/\.(\w+)$/;
  105: 
  106:         $hash{'map_type_'.$lpc}=$1;
  107: 
  108:         while ($token = $parser->get_token) {
  109: 	    if ($token->[0] eq 'S') {
  110:                 if ($token->[1] eq 'resource') {
  111: # -------------------------------------------------------------------- Resource
  112: 
  113:                     my $rid=$lpc.'.'.$token->[2]->{'id'};
  114: 
  115:                     $hash{'kind_'.$rid}='res';
  116:                     $hash{'title_'.$rid}=$token->[2]->{'title'};
  117:                     my $turi=$token->[2]->{'src'};
  118:                     unless ($ispage) {
  119:                         $turi=~/\.(\w+)$/;
  120:                         my $embstyle=&Apache::loncommon::fileembstyle($1);
  121:                         if ($token->[2]->{'external'} eq 'true') { # external
  122:                             $turi=~s/^http\:\/\//\/adm\/wrapper\/ext\//;
  123:                         } elsif ($turi=~/^\/*uploaded\//) { # uploaded
  124: 			    if (($embstyle eq 'img') || ($embstyle eq 'emb')
  125:                              || ($embstyle eq 'ssi')) {
  126:                                 $turi='/adm/wrapper'.$turi;
  127:                             } elsif ($turi!~/\.(sequence|page)$/) {
  128: 				$turi='/adm/coursedocs/showdoc'.$turi;
  129:                             }
  130:                         } else { # normal internal resource
  131:                            if (($embstyle eq 'img') || ($embstyle eq 'emb')
  132:              || ($turi=~/\/(syllabus|aboutme|navmaps|smppg|bulletinboard)$/)) {
  133: 			       $turi='/adm/wrapper'.$turi;
  134:                            }
  135:                         }
  136: 		    }
  137:                     $hash{'src_'.$rid}=$turi;
  138: 
  139:                     if (defined($hash{'ids_'.$turi})) {
  140:                         $hash{'ids_'.$turi}.=','.$rid;
  141:                     } else {
  142:                         $hash{'ids_'.$turi}=''.$rid;
  143:                     }
  144: 
  145:                     if ($token->[2]->{'external'} eq 'true') {
  146:                         $hash{'ext_'.$rid}='true:';
  147:                     } else {
  148:                         $hash{'ext_'.$rid}='false:';
  149:                     }
  150:                     if ($token->[2]->{'type'}) {
  151: 			$hash{'type_'.$rid}=$token->[2]->{'type'};
  152:                         if ($token->[2]->{'type'} eq 'start') {
  153: 			    $hash{'map_start_'.$uri}="$rid";
  154:                         }
  155:                         if ($token->[2]->{'type'} eq 'finish') {
  156: 			    $hash{'map_finish_'.$uri}="$rid";
  157:                         }
  158:                     }  else {
  159:                         $hash{'type_'.$rid}='normal';
  160:                     }
  161: 
  162:                     if (($turi=~/\.sequence$/) ||
  163:                         ($turi=~/\.page$/)) {
  164:                         $hash{'is_map_'.$rid}=1;
  165:                         &loadmap($turi);
  166:                     } 
  167:                     
  168:                 } elsif ($token->[1] eq 'condition') {
  169: # ------------------------------------------------------------------- Condition
  170: 
  171:                     my $rid=$lpc.'.'.$token->[2]->{'id'};
  172: 
  173:                     $hash{'kind_'.$rid}='cond';
  174:                     $cond[$#cond+1]=$token->[2]->{'value'};
  175:                     $hash{'condid_'.$rid}=$#cond;
  176:                     if ($token->[2]->{'type'}) {
  177:                         $cond[$#cond].=':'.$token->[2]->{'type'};
  178:                     }  else {
  179:                         $cond[$#cond].=':normal';
  180:                     }
  181: 
  182:                 } elsif ($token->[1] eq 'link') {
  183: # ----------------------------------------------------------------------- Links
  184: 
  185:                     $linkpc++;
  186:                     my $linkid=$lpc.'.'.$linkpc;
  187: 
  188:                     my $goesto=$lpc.'.'.$token->[2]->{'to'};
  189:                     my $comesfrom=$lpc.'.'.$token->[2]->{'from'};
  190:                     my $undercond=0;
  191: 
  192:                     if ($token->[2]->{'condition'}) {
  193: 			$undercond=$lpc.'.'.$token->[2]->{'condition'};
  194:                     }
  195: 
  196:                     $hash{'goesto_'.$linkid}=$goesto;
  197:                     $hash{'comesfrom_'.$linkid}=$comesfrom;
  198:                     $hash{'undercond_'.$linkid}=$undercond;
  199: 
  200:                     if (defined($hash{'to_'.$comesfrom})) {
  201:                         $hash{'to_'.$comesfrom}.=','.$linkid;
  202:                     } else {
  203:                         $hash{'to_'.$comesfrom}=''.$linkid;
  204:                     }
  205:                     if (defined($hash{'from_'.$goesto})) {
  206:                         $hash{'from_'.$goesto}.=','.$linkid;
  207:                     } else {
  208:                         $hash{'from_'.$goesto}=''.$linkid;
  209:                     }
  210:                 } elsif ($token->[1] eq 'param') {
  211: # ------------------------------------------------------------------- Parameter
  212: 
  213:                     my $referid=$lpc.'.'.$token->[2]->{'to'};
  214:                     my $part=$token->[2]->{'part'};
  215:                     unless ($part) { $part=0; }
  216:                     my $newparam=
  217: 			&Apache::lonnet::escape($token->[2]->{'type'}).':'.
  218: 			&Apache::lonnet::escape($part.'.'.
  219:                          $token->[2]->{'name'}).'='.
  220: 			&Apache::lonnet::escape($token->[2]->{'value'});
  221:                     if (defined($hash{'param_'.$referid})) {
  222:                         $hash{'param_'.$referid}.='&'.$newparam;
  223:                     } else {
  224:                         $hash{'param_'.$referid}=''.$newparam;
  225:                     }
  226:                     if ($token->[2]->{'name'} eq 'parameter_mapalias') {
  227: 			$hash{'mapalias_'.$token->[2]->{'value'}}=$referid;
  228:                     }
  229:                     if ($token->[2]->{'name'} eq 'parameter_randompick') {
  230: 			$randompick{$referid}=$token->[2]->{'value'};
  231:                     }
  232:                 } 
  233: 
  234:             }
  235:         }
  236: 
  237:     } else {
  238:         $errtext.='Map not loaded: The file does not exist. ';
  239:     }
  240: }
  241: 
  242: # --------------------------------------------------------- Simplify expression
  243: 
  244: sub simplify {
  245:    my $expression=shift;
  246: # (8)=8
  247:    $expression=~s/\((\d+)\)/$1/g;
  248: # 8&8=8
  249:    $expression=~s/(\D)(\d+)\&\2(\D)/$1$2$3/g;
  250: # 8|8=8
  251:    $expression=~s/(\D)(\d+)\|\2(\D)/$1$2$3/g;
  252: # (5&3)&4=5&3&4
  253:    $expression=~s/\((\d+)((?:\&\d+)+)\)\&(\d+\D)/$1$2\&$3/g;
  254: # (((5&3)|(4&6)))=((5&3)|(4&6))
  255:    $expression=~
  256:        s/\((\(\(\d+(?:\&\d+)*\)(?:\|\(\d+(?:\&\d+)*\))+\))\)/$1/g;
  257: # ((5&3)|(4&6))|(1&2)=(5&3)|(4&6)|(1&2)
  258:    $expression=~
  259:        s/\((\(\d+(?:\&\d+)*\))((?:\|\(\d+(?:\&\d+)*\))+)\)\|(\(\d+(?:\&\d+)*\))/\($1$2\|$3\)/g;
  260:    return $expression;
  261: }
  262: 
  263: # -------------------------------------------------------- Build condition hash
  264: 
  265: sub traceroute {
  266:     my ($sofar,$rid,$beenhere)=@_;
  267:     $sofar=simplify($sofar);
  268:     unless ($beenhere=~/\&$rid\&/) {
  269:        $beenhere.=$rid.'&';  
  270:        if (($retfurl eq '') && ($hash{'src_'.$rid})) {
  271:            my ($mapid,$resid)=split(/\./,$rid);
  272:            $retfurl=$hash{'src_'.$rid}.
  273:            (($hash{'src_'.$rid}=~/\?/)?'&':'?').'symb='.
  274:            &Apache::lonnet::symbclean(
  275:                            &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
  276:                            '___'.$resid.'___'.
  277:                            &Apache::lonnet::declutter($hash{'src_'.$rid}));
  278:        }
  279:        if (defined($hash{'conditions_'.$rid})) {
  280: 	   $hash{'conditions_'.$rid}=simplify(
  281:            '('.$hash{'conditions_'.$rid}.')|('.$sofar.')');
  282:        } else {
  283:            $hash{'conditions_'.$rid}=$sofar;
  284:        }
  285:        if (defined($hash{'is_map_'.$rid})) {
  286:            if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) {
  287: 	       &traceroute($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},'&');
  288:                if (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) {
  289: 		   $sofar=
  290:                   $hash{'conditions_'.$hash{'map_finish_'.$hash{'src_'.$rid}}};
  291:                }
  292:            }
  293:        }
  294:        if (defined($hash{'to_'.$rid})) {
  295:           foreach (split(/\,/,$hash{'to_'.$rid})) {
  296: 		my $further=$sofar;
  297:                 if ($hash{'undercond_'.$_}) {
  298: 		   if (defined($hash{'condid_'.$hash{'undercond_'.$_}})) {
  299:   		       $further=simplify('('.$further.')&('.
  300:                               $hash{'condid_'.$hash{'undercond_'.$_}}.')');
  301: 		   } else {
  302:                        $errtext.='Undefined condition ID: '
  303:                                  .$hash{'undercond_'.$_}.'. ';
  304:                    }
  305:                 }
  306:                 &traceroute($further,$hash{'goesto_'.$_},$beenhere);
  307:           }
  308:        }
  309:     }
  310: }
  311: 
  312: # ------------------------------ Cascading conditions, quick access, parameters
  313: 
  314: sub accinit {
  315:     my ($uri,$short,$fn)=@_;
  316:     my %acchash=();
  317:     my %captured=();
  318:     my $condcounter=0;
  319:     $acchash{'acc.cond.'.$short.'.0'}=0;
  320:     foreach (keys %hash) {
  321:        if ($_=~/^conditions/) {
  322: 	  my $expr=$hash{$_};
  323:          foreach ($expr=~m/(\(\(\d+(?:\&\d+)+\)(?:\|\(\d+(?:\&\d+)+\))+\))/g) {
  324:              my $sub=$_;
  325:              my $orig=$_;
  326:       $sub=~/\(\((\d+\&(:?\d+\&)*)(?:\d+\&*)+\)(?:\|\(\1(?:\d+\&*)+\))+\)/;
  327:              my $factor=$1;
  328:              $sub=~s/$factor//g;
  329:              $sub=~s/^\(/\($factor\(/;
  330: 	     $sub.=')';
  331:              $sub=simplify($sub);
  332:              $orig=~s/(\W)/\\$1/g;
  333:  	     $expr=~s/$orig/$sub/;
  334: 	  }
  335:           $hash{$_}=$expr;
  336:           unless (defined($captured{$expr})) {
  337: 	      $condcounter++;
  338:               $captured{$expr}=$condcounter;
  339:               $acchash{'acc.cond.'.$short.'.'.$condcounter}=$expr;
  340:           } 
  341:        } elsif ($_=~/^param_(\d+)\.(\d+)/) {
  342:           my $prefix=&Apache::lonnet::declutter($hash{'map_id_'.$1}).
  343:       '___'.$2.'___'.&Apache::lonnet::declutter($hash{'src_'.$1.'.'.$2});
  344:           foreach (split(/\&/,$hash{$_})) {
  345: 	     my ($typename,$value)=split(/\=/,$_);
  346:              my ($type,$name)=split(/\:/,$typename);
  347:              $parmhash{$prefix.'.'.&Apache::lonnet::unescape($name)}=
  348:                                    &Apache::lonnet::unescape($value);
  349: 	     $parmhash{$prefix.'.'.&Apache::lonnet::unescape($name).'.type'}=
  350:                                    &Apache::lonnet::unescape($type);
  351:           }
  352:        }
  353:     }
  354:     foreach (keys %hash) {
  355: 	if ($_=~/^ids/) {
  356: 	  foreach (split(/\,/,$hash{$_})) {
  357: 	    my $resid=$_;
  358:             my $uri=$hash{'src_'.$resid};
  359:             $uri=~s/^\/adm\/wrapper//;
  360:             my @uriparts=split(/\//,$uri);
  361:             my $urifile=$uriparts[$#uriparts];
  362:             $#uriparts--;
  363:             my $uripath=join('/',@uriparts);
  364:             $uripath=~s/^\/res\///;
  365:            if ($uripath) {
  366:             my $uricond='0';
  367:             if (defined($hash{'conditions_'.$resid})) {
  368:  		$uricond=$captured{$hash{'conditions_'.$resid}};
  369:             }
  370:             if (defined($acchash{'acc.res.'.$short.'.'.$uripath})) {
  371:                 if ($acchash{'acc.res.'.$short.'.'.$uripath}=~
  372:                    /(\&$urifile\:[^\&]*)/) {
  373: 		    my $replace=$1;
  374:                     my $regexp=$replace;
  375:                     $regexp=~s/\|/\\\|/g;
  376:                     $acchash{'acc.res.'.$short.'.'.$uripath}
  377:                      =~s/$regexp/$replace\|$uricond/;
  378:                 } else {
  379: 		   $acchash{'acc.res.'.$short.'.'.$uripath}.=
  380:                      $urifile.':'.$uricond.'&';
  381: 	        }
  382:             } else {
  383:                 $acchash{'acc.res.'.$short.'.'.$uripath}=
  384:                  '&'.$urifile.':'.$uricond.'&';
  385:             }
  386:            } 
  387:          }
  388:       }
  389:     }
  390:     $acchash{'acc.res.'.$short.'.'}='&:0&';
  391:     my $courseuri=$uri;
  392:     $courseuri=~s/^\/res\///;
  393:     &Apache::lonnet::delenv('(acc\.|httpref\.)');
  394:     &Apache::lonnet::appenv(%acchash,
  395:                             "request.course.id"  => $short,
  396:                             "request.course.fn"  => $fn,
  397:                             "request.course.uri" => $courseuri); 
  398: }
  399: 
  400: # ------------------------------------- Selectively delete from randompick maps
  401: 
  402: sub pickrandom {
  403:     my $randomoutentry='';
  404:     foreach my $rid (keys %randompick) {
  405:         my $rndpick=$randompick{$rid};
  406:         my $mpc=$hash{'map_pc_'.$hash{'src_'.$rid}};
  407: # ------------------------------------------- put existing resources into array
  408:         my @currentrids=();
  409:         foreach (keys %hash) {
  410: 	    if ($_=~/^src_($mpc\.\d+)/) {
  411: 		if ($hash{'src_'.$1}) { push @currentrids, $1; }
  412:             }
  413:         }
  414:         next if ($#currentrids<$rndpick);
  415: # -------------------------------- randomly eliminate the ones that should stay
  416: 	srand(&Apache::lonnet::rndseed($rid)); # use rid instead of symb
  417:         for (my $i=1;$i<=$rndpick;$i++) {
  418:             while (1) {
  419: 		my $randomidx=int(rand($#currentrids+1));
  420:                 if ($currentrids[$randomidx]) {
  421: 		    $currentrids[$randomidx]='';
  422:                     last;
  423:                 }
  424:             }
  425:         }
  426: # -------------------------------------------------------- delete the leftovers
  427:         for (my $k=0; $k<=$#currentrids; $k++) {
  428:             if ($currentrids[$k]) {
  429: 		$hash{'randomout_'.$currentrids[$k]}=1;
  430:                 my ($mapid,$resid)=split(/\./,$currentrids[$k]);
  431:                 $randomoutentry.='&'.
  432:                  &Apache::lonnet::symbclean(
  433: 		    &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
  434:                     '___'.$resid.'___'.
  435: 		    &Apache::lonnet::declutter($hash{'src_'.$currentrids[$k]})
  436:                  ).'&';
  437:             }
  438:         }
  439:     }
  440:     if ($randomoutentry) {
  441: 	&Apache::lonnet::appenv('acc.randomout' => $randomoutentry);
  442:     }
  443: }
  444: 
  445: # ---------------------------------------------------- Read map and all submaps
  446: 
  447: sub readmap {
  448:    my $short=shift;
  449:    $short=~s/^\///;
  450:    my %cenv=&Apache::lonnet::coursedescription($short);
  451:    my $fn=$cenv{'fn'};
  452:    my $uri;
  453:    $short=~s/\//\_/g;
  454:    unless ($uri=$cenv{'url'}) { 
  455:       &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  456:                        "Could not load course $short.</font>"); 
  457:       return 'No course data available.';
  458:    }
  459:    @cond=('true:normal');
  460:    unlink($fn.'.db');
  461:    unlink($fn.'_symb.db');
  462:    unlink($fn.'.state');
  463:    unlink($fn.'parms.db');
  464:    undef %randompick;
  465:    $retfurl='';
  466:    if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) &&
  467:        (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640))) {
  468:     %hash=();
  469:     %parmhash=();
  470:     $errtext='';
  471:     $pc=0;
  472:     my $furi=&Apache::lonnet::clutter($uri);
  473:     $hash{'src_0.0'}=$furi;
  474:     $hash{'title_0.0'}=&Apache::lonnet::metadata($uri,'title');
  475:     $hash{'ids_'.$furi}='0.0';
  476:     $hash{'is_map_0.0'}=1;
  477:     loadmap($uri);
  478:     if (defined($hash{'map_start_'.$uri})) {
  479:         &traceroute('0',$hash{'map_start_'.$uri},'&');
  480:         &accinit($uri,$short,$fn);
  481:         &pickrandom();
  482:     }
  483:     unless ((untie(%hash)) && (untie(%parmhash))) {
  484:       &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  485:                        "Could not untie coursemap $fn for $uri.</font>"); 
  486:     }
  487:     {
  488:      my $cfh;
  489:      if ($cfh=Apache::File->new(">$fn.state")) {
  490:         print $cfh join("\n",@cond);
  491:      } else {
  492:       &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  493:                        "Could not write statemap $fn for $uri.</font>"); 
  494:      }
  495:     }  
  496:    } else {
  497:       &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  498:                        "Could not tie coursemap $fn for $uri.</font>"); 
  499:    }
  500:    &Apache::lonmsg::author_res_msg($ENV{'request.course.uri'},$errtext);
  501:    return ($retfurl,$errtext);
  502: }
  503: 
  504: # ------------------------------------------------------- Evaluate state string
  505: 
  506: sub evalstate {
  507: 
  508:     my $fn=$ENV{'request.course.fn'}.'.state';
  509:     my $state='2';
  510:     if (-e $fn) {
  511:        my @conditions=();
  512:        {
  513:         my $fh=Apache::File->new($fn);
  514:         @conditions=<$fh>;
  515:        }  
  516:        my $safeeval = new Safe;
  517:        my $safehole = new Safe::Hole;
  518:        $safeeval->permit("entereval");
  519:        $safeeval->permit(":base_math");
  520:        $safeeval->deny(":base_io");
  521:        $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
  522:        foreach (@conditions) {
  523: 	   my $line=$_;
  524:            chomp($line);
  525: 	   my ($condition,$weight)=split(/\:/,$_);
  526:            if ($safeeval->reval($condition)) {
  527: 	       if ($weight eq 'force') {
  528: 		   $state.='3';
  529:                } else {
  530:                    $state.='2';
  531:                }
  532:            } else {
  533:                if ($weight eq 'stop') {
  534: 		   $state.='0';
  535:                } else {
  536:                    $state.='1';
  537:                }
  538:            }
  539:        }
  540:     }
  541:     &Apache::lonnet::appenv('user.state.'.$ENV{'request.course.id'} => $state);
  542:     return $state;
  543: }
  544: 
  545: 1;
  546: __END__
  547: 
  548: =head1 NAME
  549: 
  550: Apache::lonuserstate - Construct and maintain state and binary representation
  551: of course for user
  552: 
  553: =head1 SYNOPSIS
  554: 
  555: Invoked by lonroles.pm.
  556: 
  557: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  558: 
  559: =head1 INTRODUCTION
  560: 
  561: This module constructs and maintains state and binary representation
  562: of course for user.
  563: 
  564: This is part of the LearningOnline Network with CAPA project
  565: described at http://www.lon-capa.org.
  566: 
  567: =head1 HANDLER SUBROUTINE
  568: 
  569: There is no handler subroutine.
  570: 
  571: =head1 OTHER SUBROUTINES
  572: 
  573: =over 4
  574: 
  575: =item *
  576: 
  577: loadmap() : Loads map from disk
  578: 
  579: =item *
  580: 
  581: simplify() : Simplify expression
  582: 
  583: =item *
  584: 
  585: traceroute() : Build condition hash
  586: 
  587: =item *
  588: 
  589: accinit() : Cascading conditions, quick access, parameters
  590: 
  591: =item *
  592: 
  593: readmap() : Read map and all submaps
  594: 
  595: =item *
  596: 
  597: evalstate() : Evaluate state string
  598: 
  599: =back
  600: 
  601: =cut

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