[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm lonparmset.pm lonwizard.pm

bowersj2 lon-capa-cvs@mail.lon-capa.org
Thu, 20 Mar 2003 18:03:14 -0000


This is a MIME encoded message

--bowersj21048183394
Content-Type: text/plain

bowersj2		Thu Mar 20 13:03:14 2003 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm lonparmset.pm lonwizard.pm 
  Log:
  Another multiple display fix: If there is no open date for the problem
  at all, don't display it twice.
  
  
--bowersj21048183394
Content-Type: text/plain
Content-Disposition: attachment; filename="bowersj2-20030320130314.txt"

Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.161 loncom/interface/lonnavmaps.pm:1.162
--- loncom/interface/lonnavmaps.pm:1.161	Thu Mar 20 12:19:29 2003
+++ loncom/interface/lonnavmaps.pm	Thu Mar 20 13:03:14 2003
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.161 2003/03/20 17:19:29 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.162 2003/03/20 18:03:14 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1107,7 +1107,7 @@
             
             if ($condenseParts) { # do the condensation
                 if (!$curRes->opendate("0")) {
-                    @parts = ("0");
+                    @parts = ();
                     $args->{'condensed'} = 1;
                 }
                 if (!$args->{'condensed'}) {
@@ -1757,7 +1757,7 @@
 
 =over 4
 
-=item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop): All parameters are optional. firstResource is a resource reference corresponding to where the iterator should start. It defaults to navmap->firstResource() for the corresponding nav map. finishResource corresponds to where you want the iterator to end, defaulting to navmap->finishResource(). filterHash is a hash used as a set containing strings representing the resource IDs, defaulting to empty. Condition is a 1 or 0 that sets what to do with the filter hash: If a 0, then only resource that exist IN the filterHash will be recursed on. If it is a 1, only resources NOT in the filterHash will be recursed on. Defaults to 0. forceTop is a boolean value. If it is false (default), the iterator will only return the first level of map that is not just a single, 'redirecting' map. If true, the iterator will return all information, starting with the top-level map, regardless of content.
+=item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop, returnTopMap): All parameters are optional. firstResource is a resource reference corresponding to where the iterator should start. It defaults to navmap->firstResource() for the corresponding nav map. finishResource corresponds to where you want the iterator to end, defaulting to navmap->finishResource(). filterHash is a hash used as a set containing strings representing the resource IDs, defaulting to empty. Condition is a 1 or 0 that sets what to do with the filter hash: If a 0, then only resource that exist IN the filterHash will be recursed on. If it is a 1, only resources NOT in the filterHash will be recursed on. Defaults to 0. forceTop is a boolean value. If it is false (default), the iterator will only return the first level of map that is not just a single, 'redirecting' map. If true, the iterator will return all information, starting with the top-level map, regardless of content. returnTopMap, if true (default false), will cause the iterator to return the top-level map object (resource 0.0) before anything else.
 
 Thus, by default, only top-level resources will be shown. Change the condition to a 1 without changing the hash, and all resources will be shown. Changing the condition to 1 and including some values in the hash will allow you to selectively suppress parts of the navmap, while leaving it on 0 and adding things to the hash will allow you to selectively add parts of the nav map. See the handler code for examples.
 
@@ -1832,6 +1832,11 @@
     # Do we want to automatically follow "redirection" maps?
     $self->{FORCE_TOP} = shift;
 
+    # Do we want to return the top-level map object (resource 0.0)?
+    $self->{RETURN_0} = shift;
+    # have we done that yet?
+    $self->{HAVE_RETURNED_0} = 0;
+
     # Now, we need to pre-process the map, by walking forward and backward
     # over the parts of the map we're going to look at.
 
@@ -1944,6 +1949,13 @@
 
 sub next {
     my $self = shift;
+
+    # If we want to return the top-level map object, and haven't yet,
+    # do so.
+    if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0}) {
+        $self->{HAVE_RETURNED_0} = 1;
+        return $self->{NAV_MAP}->getById('0.0');
+    }
 
     if ($self->{RECURSIVE_ITERATOR_FLAG}) {
         # grab the next from the recursive iterator 
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.84 loncom/interface/lonparmset.pm:1.85
--- loncom/interface/lonparmset.pm:1.84	Thu Mar 13 15:52:47 2003
+++ loncom/interface/lonparmset.pm	Thu Mar 20 13:03:14 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.84 2003/03/13 20:52:47 bowersj2 Exp $
+# $Id: lonparmset.pm,v 1.85 2003/03/20 18:03:14 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1570,7 +1570,7 @@
 
 ##################################################
 ##################################################
-
+    use Data::Dumper;
 sub handler {
     my $r=shift;
 
@@ -1581,6 +1581,15 @@
     }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 
+    $r->content_type('text/html');
+    $r->send_http_header;
+    $r->print("\n\n");
+    # Temp for reverse-engineering purposes.
+    for (keys %ENV) {
+        if ($_ =~ /^form\./) {
+            $r->print($_ . " " . Dumper($ENV{$_}) . "<br />\n");
+        }
+    }
 # ----------------------------------------------------- Needs to be in a course
 
     if (($ENV{'request.course.id'}) && 
Index: loncom/interface/lonwizard.pm
diff -u loncom/interface/lonwizard.pm:1.17 loncom/interface/lonwizard.pm:1.18
--- loncom/interface/lonwizard.pm:1.17	Fri Feb 28 19:07:18 2003
+++ loncom/interface/lonwizard.pm	Thu Mar 20 13:03:14 2003
@@ -25,6 +25,8 @@
 
 use HTML::Entities;
 use Apache::loncommon;
+use Digest::MD5 qw(md5_hex);
+use Apache::File;
 
 =pod
 
@@ -76,6 +78,45 @@
 	$self->{STATE} = "START";
     }
 
+    $self->{TOKEN} = $ENV{'form.TOKEN'};
+    # If a token was passed, we load that in. Otherwise, we need to create a 
+    # new storage file
+    # Tried to use standard Tie'd hashes, but you can't seem to take a 
+    # reference to a tied hash and write to it. I'd call that a wart.
+    if ($self->{TOKEN}) {
+        # Validate the token before trusting it
+        if ($self->{TOKEN} !~ /^[a-f0-9]{32}$/) {
+            # Not legit. Return nothing and let all hell break loose.
+            # User shouldn't be doing that!
+            return undef;
+        }
+
+        # Get the hash.
+        $self->{FILENAME} = $Apache::lonnet::tmpdir . md5_hex($self->{TOKEN}); # Note the token is not the literal file
+        
+        my $file = Apache::File->new($self->{FILENAME});
+        my $contents = <$file>;
+        &Apache::loncommon::get_unprocessed_cgi($contents);
+        $file->close();
+        
+        # Marks whether this is a new wizard.
+        $self->{NEW_WIZARD} = 0;
+    } else {
+        # Only valid if we're just starting.
+        if ($self->{STATE} ne 'START') {
+            return undef;
+        }
+        # Must create the storage
+        $self->{TOKEN} = md5_hex($ENV{'user.name'} . $ENV{'user.domain'} .
+                                 time() . rand());
+        $self->{FILENAME} = $Apache::lonnet::tmpdir . md5_hex($self->{TOKEN});
+
+        # Marks whether this is a new wizard.
+        $self->{NEW_WIZARD} = 1;
+    }
+
+    # OK, we now have our persistent storage.
+
     if (defined $ENV{"form.RETURN_PAGE"})
     {
 	$self->{RETURN_PAGE} = $ENV{"form.RETURN_PAGE"};
@@ -86,7 +127,6 @@
     }
 
     $self->{STATES} = {};
-    $self->{VARS} = {};
     $self->{HISTORY} = {};
     $self->{DONE} = 0;
 
@@ -129,14 +169,15 @@
     foreach my $element ( @{$varlist} )
     {
 	# assign the var the default of ""
-	$self->{VARS}{$element} = "";
+	$self->{VARS}->{$element} = "";
 
-	# if there's a form in the env, use that instead
-	my $envname = "form." . $element;
-	if (defined ($ENV{$envname})) {
-	    $self->{VARS}->{$element} = $ENV{$envname};
-	}
+        my $envname;
         
+        $envname = "form." . $element;
+        if (defined ($ENV{$envname})) {
+            $self->{VARS}->{$element} = $ENV{$envname};
+        }
+
         # If there's an incoming form submission, use that
         $envname = "form." . $element . ".forminput";
         if (defined ($ENV{$envname})) {
@@ -145,29 +186,33 @@
     }
 }
 
-# Private function; takes all of the declared vars and returns a string
-# corresponding to the hidden input fields that will re-construct the 
-# variables.
+# Private function; returns a string to construct the hidden fields
+# necessary to have the wizard track state.
 sub _saveVars {
     my $self = shift;
     my $result = "";
-    foreach my $varname (keys %{$self->{VARS}})
-    {
-	$result .= '<input type="hidden" name="' .
-	           HTML::Entities::encode($varname) . '" value="' .
-		   HTML::Entities::encode($self->{VARS}{$varname}) . 
-		   "\" />\n";
-    }
-
-    # also save state & return page
     $result .= '<input type="hidden" name="CURRENT_STATE" value="' .
-               HTML::Entities::encode($self->{STATE}) . '" />' . "\n";
+        HTML::Entities::encode($self->{STATE}) . "\" />\n";
+    $result .= '<input type="hidden" name="TOKEN" value="' .
+        $self->{TOKEN} . "\" />\n";
     $result .= '<input type="hidden" name="RETURN_PAGE" value="' .
-               HTML::Entities::encode($self->{RETURN_PAGE}) . '" />' . "\n";
+        HTML::Entities::encode($self->{RETURN_PAGE}) . "\" />\n";
 
     return $result;
 }
 
+# Private function: Create the querystring-like representation of the stored
+# data to write to disk.
+sub _varsInFile {
+    my $self = shift;
+    my @vars = ();
+    for my $key (keys %{$self->{VARS}}) {
+        push @vars, &Apache::lonnet::escape($key) . '=' .
+            &Apache::lonnet::escape($self->{VARS}->{$key});
+    }
+    return join ('&', @vars);
+}
+
 =pod
 
 =item B<registerState>(referenceToStateObj): Registers a state as part of the wizard, so the wizard can use it. The 'referenceToStateObj' should be a reference to an instantiated lonwizstate object. This is normally called at the end of the lonwizard::state constructor, so you should not normally need it as a user.
@@ -195,8 +240,8 @@
 
 =pod
 
-=item B<display>(): This is the main method that the handler using the wizard calls.
-
+=item B<display>(): This is the main method that the handler using the wizard calls. It must always be called, and called last, because it takes care of closing a hash that needs to be closed.
+sxsd
 =cut
 
 # Done in four phases
@@ -291,6 +336,10 @@
 </html>
 FOOTER
 
+    # Handle writing out the vars to the file
+    my $file = Apache::File->new('>'.$self->{FILENAME});
+    print $file $self->_varsInFile();
+
     return $result;
 }
 
@@ -324,12 +373,11 @@
 
 =cut
 
-# This may look trivial, but it's here as a hook for possible later processing
 sub setVar {
     my $self = shift;
     my $key = shift;
     my $val = shift;
-    $self->{VARS}{$key} = $val;
+    $self->{VARS}->{$key} = $val;
 }
 
 =pod
@@ -341,12 +389,11 @@
 sub queryStringVars {
     my $self = shift;
 
+    my @storedVars = ('STATE', 'TOKEN', 'RETURN_PAGE');
     my @queryString = ();
     
-    for my $varname (keys %{$self->{VARS}}) {
-        push @queryString, Apache::lonnet::escape($varname) . "=" .
-            Apache::lonnet::escape($self->{VARS}{$varname});
-    }
+    push @queryString, 'TOKEN=' .
+        Apache::lonnet::escape($self->{TOKEN});
     push @queryString, 'CURRENT_STATE=' . Apache::lonnet::escape($self->{STATE});
     push @queryString, 'RETURN_PAGE=' . Apache::lonnet::escape($self->{RETURN_PAGE});
 
@@ -359,7 +406,6 @@
 
 =cut
 
-
 # A temp function for debugging
 sub handler {
     my $r = shift;
@@ -1278,7 +1324,7 @@
                 $col .= "checked ";
                 $checked = 1;
             }
-            $col .= "value='" . $resource->{ID} . "' /></td>";
+            $col .= "value='" . $resource->symb() . "' /></td>";
             return $col;
         }
     };

--bowersj21048183394--