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