[LON-CAPA-cvs] cvs: loncom /build buildHelp.sh /html/adm/help/png lonhelpheader.png /html/adm/help/tex Problem_Editor_XML_Index.tex /interface lonhelp.pm lonwizard.pm doc/help author.manual.texxml course.manual.texxml render.texxml.pl texxml2indextex.pl doc/loncapafiles loncapafiles.lpml

bowersj2 lon-capa-cvs@mail.lon-capa.org
Fri, 09 Aug 2002 14:48:31 -0000


This is a MIME encoded message

--bowersj21028904511
Content-Type: text/plain

bowersj2		Fri Aug  9 10:48:31 2002 EDT

  Added files:                 
    /loncom/html/adm/help/png	lonhelpheader.png 
    /loncom/interface	lonwizard.pm 

  Modified files:              
    /doc/help	author.manual.texxml course.manual.texxml 
             	render.texxml.pl texxml2indextex.pl 
    /doc/loncapafiles	loncapafiles.lpml 
    /loncom/build	buildHelp.sh 
    /loncom/html/adm/help/tex	Problem_Editor_XML_Index.tex 
    /loncom/interface	lonhelp.pm 
  Log:
  This should be all the help information necessary for the next stable
  release. 
  
  
  
--bowersj21028904511
Content-Type: text/plain
Content-Disposition: attachment; filename="bowersj2-20020809104831.txt"

Index: doc/help/author.manual.texxml
diff -u doc/help/author.manual.texxml:1.3 doc/help/author.manual.texxml:1.4
--- doc/help/author.manual.texxml:1.3	Mon Jul 29 10:51:43 2002
+++ doc/help/author.manual.texxml	Fri Aug  9 10:48:31 2002
@@ -1,4 +1,5 @@
 <texxml>
+	<title name="LON-CAPA Author's Manual" />
 	<file name="Author_Manual_Title_Page.tex"/>
 	
 	<section name="Introduction to LON-CAPA">
Index: doc/help/course.manual.texxml
diff -u doc/help/course.manual.texxml:1.2 doc/help/course.manual.texxml:1.3
--- doc/help/course.manual.texxml:1.2	Wed Jul 31 10:55:11 2002
+++ doc/help/course.manual.texxml	Fri Aug  9 10:48:31 2002
@@ -1,4 +1,5 @@
 <texxml>
+	<title name="LON-CAPA Course Administrator's Manual" />
 	<file name="Course_Manual_Title_Page.tex" />
 
 	<section name="Managing the Class List">
Index: doc/help/render.texxml.pl
diff -u doc/help/render.texxml.pl:1.6 doc/help/render.texxml.pl:1.7
--- doc/help/render.texxml.pl:1.6	Tue Jul 30 14:24:44 2002
+++ doc/help/render.texxml.pl	Fri Aug  9 10:48:31 2002
@@ -67,6 +67,7 @@
 }
 
 my $redir = ">& /dev/null"; # empty this for easier debugging
+#$redir = ">> /home/jerf/work/loncapa/doc/help/error_log.txt";
 
 mkdir $tmpdir, 0755;
 
@@ -76,22 +77,24 @@
 print "Copying .eps files...\n";
 system ( "cp $epssource/* $tmpdir/" );
 
-# \scrollmode\input causes LaTeX to not stop on errors
 print "Running Latex...\n";
 system ( "cd $tmpdir; echo | latex $fileroot $redir; echo | latex $fileroot $redir; echo | latex $fileroot\ $redir; " );
 
 print "Running dvips...\n";
-system ( "cd $tmpdir; dvips -f $fileroot.dvi > $fileroot.ps $redir " );
+system ( "cd $tmpdir; dvips -f $fileroot.dvi > $fileroot.ps  " );
 
 print "Copying ps file...\n";
 system ( "cp $tmpdir/$fileroot.ps .");
 
+print "Converting to PDF (may take a bit)...\n";
+system ( "ps2pdf $fileroot.ps $fileroot.pdf" );
+
 print "Clearing temp directory...\n";
-#system ( "rm -rf $tmpdir" );
+system ( "rm -rf $tmpdir" );
 
 if ( -e $fileroot . ".ps" )
 {
-    print "$fileroot.ps is ready.\n";
+    print "$fileroot.ps and $fileroot.pdf are ready.\n";
 }
 else
 {
Index: doc/help/texxml2indextex.pl
diff -u doc/help/texxml2indextex.pl:1.1 doc/help/texxml2indextex.pl:1.2
--- doc/help/texxml2indextex.pl:1.1	Tue Jul 30 13:56:06 2002
+++ doc/help/texxml2indextex.pl	Fri Aug  9 10:48:31 2002
@@ -32,23 +32,27 @@
 use HTML::TokeParser;
 use GDBM_File;
 
-# accept texxml document on standard in
-my $p = HTML::TokeParser->new( $ARGV[0] );
-my $dirprefix = "/home/httpd/html/adm/help/tex/";
-
 if (not defined($ARGV[1]))
 {
     print <<USAGE;
-Usage: texxml2indextex.pl texxmlfilename headerfile
+Usage: texxml2indextex.pl texxmlfilename
 texxml2indextex.pl will create an 'index file' suitable for use as a 
 sort of title page for a given set of help files. The second file will
 be placed at the beginning, verbatim, so it can be used to provide
 context, title, etc, if given.
 USAGE
+
+   exit;
 }
 
-# Print the specified header and title
-print <$ARGV[1]>;
+# accept texxml document on standard in
+my $p = HTML::TokeParser->new( <$ARGV[1]> );
+my $dirprefix = "/home/httpd/html/adm/help/tex/";
+
+# there's a TTH error if we put something before a section starts,
+# so don't display anything that precedes a section. Since that's just
+# the title page anyhow, no loss.
+my $inSection = 0;
 
 while (my $token = $p->get_token())
 {
@@ -57,22 +61,31 @@
     {
 	my $tag = $token->[1];
 	my $attr = $token->[2];
+	if ($tag eq 'title')
+	{
+	    my $title = $attr->{'name'};
+	    print "{\\Large Online Access to $title}\n\n";
+	}
 	if ($tag eq 'section')
 	{
+	    $inSection = 1;
 	    my $title = $attr->{'name'};
-	    print "\\emph{\\textbf{$title}}\n\n";
+	    print "\\emph{\\textbf{$title}}\n";
+	    print "\\begin{itemize}\n\n";
 	}
 
 	if ($tag eq 'subsection')
 	{
 	    my $title = $attr->{'name'};
 	    print "\\textbf{$title}\n\n";
+	    print "\\begin{itemize}\n\n";
 	}
 
 	if ($tag eq 'subsubsection')
 	{
 	    my $title = $attr->{'name'};
-	    print "$title\n\n";
+	    print "\\emph{$title}\n\n";
+	    print "\\begin{itemize}\n\n";
 	}
 
 	if ($tag eq 'file')
@@ -80,8 +93,17 @@
 	    my $file = substr($attr->{'name'}, 0, -4);
 	    my $title = $file;
 	    $title =~ s/_/ /g;
-	    print "\\item \\ref{$file} $title";
+	    if ($inSection) {print "\\item \\ref{$file} $title\n\n"};
+	}
+    }
+    elsif ($type eq 'E')
+    {
+	my $tag = $token->[1];
+	if (index($tag, "section") != -1)
+	{
+	    print "\\end{itemize}\n\n";
 	}
     }
 }
 
+print "\n\n\\end{document}\n\n";
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.157 doc/loncapafiles/loncapafiles.lpml:1.158
--- doc/loncapafiles/loncapafiles.lpml:1.157	Thu Aug  8 10:06:08 2002
+++ doc/loncapafiles/loncapafiles.lpml	Fri Aug  9 10:48:31 2002
@@ -3,7 +3,7 @@
 <!-- loncapafiles.lpml -->
 <!-- Scott Harrison -->
 
-<!-- $Id: loncapafiles.lpml,v 1.157 2002/08/08 14:06:08 www Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.158 2002/08/09 14:48:31 bowersj2 Exp $ -->
 
 <!--
 
@@ -1348,11 +1348,64 @@
 <build trigger='always run'>loncom/build/buildHelp.sh</build>
 </file>
 <file>
-<source>/doc/help/author.manual.ps</source>
+<source>loncom/html/adm/help/abouthelp.html</source>
+<target dist='default'>home/httpd/html/adm/help/abouthelp.html</target>
+<categoryname>interface file</categoryname>
+<description>
+Index file for the help system
+</description>
+</file>
+<file>
+<source>doc/help/author.manual.access.tex</source>
+<target dist='default'>home/httpd/html/adm/help/tex/author.manual.access.tex</target>
+<categoryname>handler</categoryname>
+<description>
+The psuedo-LaTeX file to allow people to read the author's manual online, with a somewhat clumsy interface.
+</description>
+<status>works/unverified</status>
+</file>
+<file>
+<source>doc/help/course.manual.access.tex</source>
+<target dist='default'>home/httpd/html/adm/help/tex/course.manual.access.tex</target>
+<categoryname>handler</categoryname>
+<description>
+The psuedo-LaTeX file to allow people to read the course administrator's manual online, with a somewhat clumsy interface.
+</description>
+<status>works/unverified</status>
+</file>
+<file>
+<source>doc/help/author.manual.ps</source>
 <target dist='default'>home/httpd/html/adm/help/author.manual.ps</target>
 <categoryname>handler</categoryname>
 <description>
-The rendered Author's Manual
+The postscript Author's Manual
+</description>
+<status>works/unverified</status>
+</file>
+<file>
+<source>doc/help/author.manual.pdf</source>
+<target dist='default'>home/httpd/html/adm/help/author.manual.pdf</target>
+<categoryname>handler</categoryname>
+<description>
+The PDF Author's Manual
+</description>
+<status>works/unverified</status>
+</file>
+<file>
+<source>doc/help/course.manual.ps</source>
+<target dist='default'>home/httpd/html/adm/help/course.manual.ps</target>
+<categoryname>handler</categoryname>
+<description>
+The postscript Course Manual
+</description>
+<status>works/unverified</status>
+</file>
+<file>
+<source>doc/help/course.manual.pdf</source>
+<target dist='default'>home/httpd/html/adm/help/course.manual.pdf</target>
+<categoryname>handler</categoryname>
+<description>
+The PDF Course Manual
 </description>
 <status>works/unverified</status>
 </file>
@@ -1377,6 +1430,7 @@
 dynamic_plot2.gif
 formulaResponse.gif
 login.gif
+lonhelpheader.gif
 mapAdvancedEditorNew.gif
 mapClickedStart.gif
 mapEditFirstClick.gif
@@ -1426,6 +1480,7 @@
 dynamic_plot.eps
 dynamic_plot2.eps
 formulaResponse.eps
+lonhelpheader.eps
 login.eps
 mapAdvancedEditorNew.eps
 mapClickedStart.eps
Index: loncom/build/buildHelp.sh
diff -u loncom/build/buildHelp.sh:1.2 loncom/build/buildHelp.sh:1.3
--- loncom/build/buildHelp.sh:1.2	Thu Jul 18 10:58:03 2002
+++ loncom/build/buildHelp.sh	Fri Aug  9 10:48:31 2002
@@ -3,4 +3,11 @@
 perl rebuildLabelHash.pl
 
 # build author manual, with the current eps files
-perl render.texxml.pl -- author.manual ../../loncom/html/adm/help/eps/
\ No newline at end of file
+perl render.texxml.pl -- author.manual ../../loncom/html/adm/help/eps/
+perl render.texxml.pl -- course.manual ../../loncom/html/adm/help/eps/
+
+# build on-line access to the manuals
+
+perl texxml2indextex.pl -- author.manual.texxml > author.manual.access.tex
+perl texxml2indextex.pl -- course.manual.texxml > course.manual.access.tex
+
Index: loncom/html/adm/help/tex/Problem_Editor_XML_Index.tex
diff -u loncom/html/adm/help/tex/Problem_Editor_XML_Index.tex:1.1 loncom/html/adm/help/tex/Problem_Editor_XML_Index.tex:1.2
--- loncom/html/adm/help/tex/Problem_Editor_XML_Index.tex:1.1	Thu Jul 18 16:52:36 2002
+++ loncom/html/adm/help/tex/Problem_Editor_XML_Index.tex	Fri Aug  9 10:48:31 2002
@@ -1,5 +1,10 @@
 \label{Problem_Editor_XML_Index}
 
+\begin{html}In addition to the following information, you may wish to
+see about <a href="abouthelp.html">downloading or reading the author's
+manual</a>.
+\end{html}
+
 There is currently no specific documentation on the XML file format,
 but you may find the following help topics useful:
 
Index: loncom/interface/lonhelp.pm
diff -u loncom/interface/lonhelp.pm:1.3 loncom/interface/lonhelp.pm:1.4
--- loncom/interface/lonhelp.pm:1.3	Fri Jul 26 15:58:52 2002
+++ loncom/interface/lonhelp.pm	Fri Aug  9 10:48:31 2002
@@ -56,6 +56,8 @@
         <title>LON-CAPA Help</title>
     </head>
     <body bgcolor="#FFFFFF">
+    <h3 style="font: sans-serif"><img align="right"
+    src="/adm/help/gif/lonhelpheader.gif"/>LON-CAPA Help<hr /></h3>
     <!-- BEGIN -->
 HEADER
 
@@ -63,6 +65,9 @@
 
 $r->print(<<FOOTER);
     <!-- END -->
+    <hr />
+    <center><font size="-1"><a href="/adm/help/abouthelp.html">About
+    LON-CAPA help and More Help</a></font></center>
     </body>
 </html>
 FOOTER

Index: loncom/interface/lonwizard.pm
+++ loncom/interface/lonwizard.pm
# This is the LON-CAPA HTML Wizard framework, for wrapping easy
# functionality easily.

package Apache::lonwizard;

use Apache::Constants qw(:common :http);
use Apache::loncommon;

=head1 lonwizard - HTML "Wizard" framework for LON-CAPA

I know how most developers feel about Wizards, but the fact is they are a well-established UI widget that users feel comfortable with. It can take a complicated multi-dimensional problem the user has (such as the canonical Course Parameter example) and turn in into a series of bite-sized one-dimensional questions. Or take the some four-question form and put it in a Wizard, and present the same user with the same form outside of the Wizard, and the user will *think* the Wizard is easier.

For the developer, wizards do provide an easy way to bundle easy bits of functionality for the user. It can be easier to write a Wizard then provide another custom interface.

All classes are in the Apache::lonwizard namespace.

(For a perldoc'ed example of a wizard you can use as an example, see loncourseparmwizard.pm.)

=cut

# To prevent runaway file counts, this file has lonwizard,
# lonwizstate, and other wizard classes.
use strict;

use HTML::Entities;

=pod

=head1 Class: lonwizard

=head2 lonwizard Attributes

=over 4

=item B<STATE>: The string name of the current state.

=item B<TITLE>: The human-readable title of the wizard

=item B<STATES>: A hash mapping the string names of states to references to the actual states.

=item B<VARS>: Hash that maintains the persistent variable values.

=item B<HISTORY>: An array containing the names of the previous states. Used for "back" functionality.

=item B<DONE>: A boolean value, true if the wizard has completed.

=back

=cut

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = {};

    # If there is a state from the previous form, use that. If there is no
    # state, use the start state parameter.
    if (defined $ENV{"form.CURRENT_STATE"})
    {
	$self->{STATE} = $ENV{"form.CURRENT_STATE"};
    }
    else
    {
	$self->{STATE} = "START";
    }

    # set up return URL: Return the user to the referer page, unless the
    # form has stored a value.
    if (defined $ENV{"form.RETURN_PAGE"})
    {
	$self->{RETURN_PAGE} = $ENV{"form.RETURN_PAGE"};
    }
    else
    {
	$self->{RETURN_PAGE} = $ENV{REFERER};
    }

    $self->{TITLE} = shift;
    $self->{STATES} = {};
    $self->{VARS} = {};
    $self->{HISTORY} = {};
    $self->{DONE} = 0;
    bless($self, $class);
    return $self;
}

=pod

=head2 lonwizard methods

=over 2

=item B<new>(title): Returns a new instance of the given wizard type. "title" is the human-readable name of the wizard. A new wizard always starts on the B<START> state name.

=item B<declareVars>(varList): Call this function to declare the var names you want the wizard to maintain for you. The wizard will automatically output the hidden form fields and parse the values for you on the next call.

=over 2

=item Note that these variables are reserved for the wizard; if you output other form values in your state, you must use other names. For example, declaring "student" will cause the wizard to emit a form value with the name "student"; if your state emits form entries, do not name them "student".

=back

=cut

sub declareVars {
    my $self = shift;
    my $varlist = shift;

    # for each string in the passed in list,
    foreach my $element ( @{$varlist} )
    {
	# assign the var the default of ""
	$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};
	}
    }
}

# Private function; takes all of the declared vars and returns a string
# corresponding to the hidden input fields that will re-construct the 
# variables.
sub _saveVars {
    my $self = shift;
    my $result = "";
    print $self->{VARS}{VAR1};
    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";
    $result .= '<input type="hidden" name="RETURN_PAGE" value="' .
               HTML::Entities::encode($self->{RETURN_PAGE}) . '" />' . "\n";

    return $result;
}

=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 lonwizstate constructor.

=cut

sub registerState {
    my $self = shift;
    my $state = shift;

    my $stateName = $state->name();
    $self->{STATES}{$stateName} = $state;
}

=pod

=item B<changeState>(stateName): Given a string representing the name of some registered state, this causes the wizard to change to that state. Generally, states will call this.

=cut

sub changeState {
    my $self = shift;
    $self->{STATE} = shift;
}

=pod

=item B<display>(): This is the main method that the handler using the wizard calls.

=cut

# Done in five phases
# 1: Do the post processing for the previous state.
# 2: Do the preprocessing for the current state.
# 3: Check to see if state changed, if so, postprocess current and move to next.
#    Repeat until state stays stable.
# 4: Render the current state to the screen as an HTML page.
sub display {
    my $self = shift;

    my $result = "";

    # Phase 1: Post processing for state of previous screen (which is actually
    # the current state), if it wasn't the beginning state.
    if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq "Next ->")
    {
	my $prevState = $self->{STATES}{$self->{STATE}};
	$prevState->postprocess();
    }
    
    # Note, to handle errors in a state's input that a user must correct,
    # do not transition in the postprocess, and force the user to correct
    # the error.

    # Phase 2: Preprocess current state
    my $startState = $self->{STATE};
    my $state = $self->{STATES}{$startState};
    $state->preprocess();

    # Phase 3: While the current state is different from the previous state,
    # keep processing.
    while ( $startState ne $self->{STATE} )
    {
	$startState = $self->{STATE};
	$state = $self->{STATES}{$startState};
	$state->preprocess();
    }

    # Phase 4: Display.
    my $stateTitle = $state->title();

    $result .= <<HEADER;
<html>
    <head>
        <title>LON-CAPA Wizard: $self->{NAME}</title>
    </head>
    <body bgcolor="#FFFFFF">
        <h1 style="font: Ariel">LON-CAPA Wizard: $self->{TITLE}</h1>
	
	<h2><i>$stateTitle</i></h2>

	<form method="GET">
HEADER

    $result .= $self->_saveVars();
    $result .= $state->render() . "<p>&nbsp;</p>";

    if ($self->{STATE} ne $self->{START_STATE})
    {
	$result .= '<input name="SUBMIT" type="submit" value="&lt;- Previous" />&nbsp;&nbsp;';
    }
    if ($self->{DONE})
    {
	my $returnPage = $self->{RETURN_PAGE};
	$result .= "<a href=\"$returnPage\">End Wizard</a>";
    }
    else
    {
	$result .= '<input name="SUBMIT" type="submit" value="Next -&gt;" />';
    }
    

    $result .= <<FOOTER;
        </form>
    </body>
</html>
FOOTER
}

=pod

=item B<name>([name]): Returns the name of the wizard. If a parameter is passed, that will be saved as the name.

=cut

# Returns/sets the name of this wizard, i.e., "Assignment Parameter"
sub title {
    my $self = shift;
    if (@_) { $self->{TITLE} = shift};
    return $self->{TITLE};
}

=pod

=item B<getVars>(): Returns a hash reference containing the stored vars for this wizard. The states use this for variables maintained across states. Example: C<my %vars = %{$wizard-E<gt>getVars()};> This provides read-only access, apparently.

=cut

sub getVars {
    my $self = shift;
    return ($self->{VARS});
}

=pod

=item B<setVar>(key, val): Sets the var named "key" to "val" in the wizard's form array.

=cut

sub setVar {
    my $self = shift;
    my $key = shift;
    my $val = shift;
    $self->{VARS}{$key} = $val;
    print "set $key to $val<br>";
}

=pod

=item B<setDone>(): If a state calls this, the wizard will consider itself completed. The state should display a friendly "Done" message, and the wizard will display a link returning the user to the invoking page, rather then a "Next" button.

=cut


# A temp function for debugging
sub handler {
    my $r = shift;

    Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
    
    my $mes = "Using this wizard, you can <ul><li>change the due date of an assignment</li><li>change the due date for a whole map of assignments</li><li>change the due date for just one person</li></ul>";

    my $wizard = Apache::lonwizard->new("Test Wizard");

    my $mesState = Apache::lonwizard::message_state->new($wizard, "START", "Welcome to the Assignment Parameter Wizard", $mes, "NEXT");
    my $mesState2 = Apache::lonwizard::choice_state->new($wizard, "NEXT", "Fucking the Cow", "How should the cow be fucked?", "Wow, with so many wonderful choices, how will you choose!?!", "START", "VAR1", {'standing & dildoated','standing & didldoated', 'rotten','rotten', 'sitting','sitting'});
    $wizard->declareVars( ["VAR1", "VAR2", "VAR3"] );
    
    $r->print($wizard->display());

    return OK;
}



1;

=head1 Class: lonwizstate

A "lonwizstate" object represents a lonwizard state. A "state" is basically what is visible on the screen. For instance, a state may display a radio button dialog with three buttons, and wait for the user to choose one.

Several pre-prepared child classes are include in lonwizard. If you create a new wizard type, be sure to add it to lonwizard.pm so others can use it too.

=head2 lonwizstate methods

These methods should be overridden in derived states, except B<new> which may be sufficient.

=over 2

=item B<new> (parentLonWizReference, stateName, stateTitle): Creates a new state and returns it. The first argument is a reference to the parent wizard. The second is the name of the state, which I<must> be unique. The third is the title, which will be displayed on the screen to the human.

=item B<preprocess>(): preprocess sets up all of the information the state needs to do its job, such as querying data bases to obtain lists of choices, and sets up data for the render method. If preprocess decides to jump to a new state, it is responsible for manually running post-process, if it so desires.

=over 2

=item If this method calls the parent lonwizard's B<changeState> method to another state, then the state will never be rendered on the screen, and the wizard will move to the specified state. This is useful if the state may only be necessary to clarify an ambiguous input, such as selecting a part from a multi-part problem, which isn't necessary if the problem only has one state.

=back

=item B<render>(): render returns a string of itself to be rendered to the screen, which the wizard will display.

=back

=cut 

package Apache::lonwizard::state;

use strict;

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = {};
    $self->{WIZARD} = shift;
    $self->{NAME} = shift;
    $self->{TITLE} = shift;

    bless($self);

    $self->{WIZARD}->registerState($self);
    return $self;
}

sub name {
    my $self = shift;
    if (@_) { $self->{NAME} = shift};
    return $self->{NAME};
}

sub title {
    my $self = shift;
    if (@_) { $self->{TITLE} = shift};
    return $self->{TITLE};
}

sub preprocess {
    return 1;
}

sub render {
    return "This is the empty state. If you can see this, it's a bug.\n"
}

sub postprocess {
    return 1;
}

1;

=pod

=back

=head1 Prepackaged States

lonwizard provides several pre-packaged states that you can drop into your Wizard and obtain common functionality.

=head2 Class: message_state

message_state is a state the simply displays a message. It does not do any pre- or postprocessing. It makes a good initial state, which traditionally is a short message telling the user what they are about to accomplish, and may contain warnings or preconditions that should be fulfilled before using the wizard.

=over 4

=item overridden method B<new>(parentLonWizReference, stateName, message, nextState): Two new parameters "message" will be the HTML message displayed to the user, and "nextState" is the name of the next state.

=back

=cut

package Apache::lonwizard::message_state;

no strict;
@ISA = ("Apache::lonwizard::state");
use strict;

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    my $self = bless $proto->SUPER::new(shift, shift, shift);

    $self->{MESSAGE} = shift;
    $self->{NEXT_STATE} = shift;

    return $self;
}

sub postprocess {
    my $self = shift;
    $self->{WIZARD}->changeState($self->{NEXT_STATE});
    return 1;
}

sub render {
    my $self = shift;
    return $self->{MESSAGE};
}

1;

package Apache::lonwizard::choice_state;

no strict;
@ISA = ("Apache::lonwizard::state");
use strict;

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = bless $proto->SUPER::new(shift, shift, shift);

    $self->{MESSAGE_BEFORE} = shift;
    $self->{MESSAGE_AFTER} = shift;
    $self->{NEXT_STATE} = shift;
    $self->{VAR_NAME} = shift;
    $self->{CHOICE_HASH} = shift;
    $self->{NO_CHOICES} = 0;
}

=pod

=head2 Class: choice_state

Choice state provides a single choice to the user as a text selection box. You pass it a message and hash containing [human_name] -> [computer_name] entries, and it will display the choices and store the result in the provided variable.

If there is only one choice, the state will automatically make it and go to the next state.

=over 4

=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, choiceHash): messageBefore is the HTML text that will be displayed before the choice display, messageAfter will display after. Keys will be sorted according to human name. nextState is the state to proceed to after the choice. varName is the name of the wizard var to store the computer_name answer in. choiceHash is the hash described above. It is optional because you may override it.

=cut

sub preprocess {
    my $self = shift;
    my %choices = %{$self->{CHOICE_HASH}};
    my %wizvars = %{$self->{WIZARD}->getVars()};

    my @keys = keys(%choices);
    @keys = sort @keys;

    if (scalar(@keys) == 0)
    {
	# No choices... so prepare to display error message and cancel further execution.
	$self->{NO_CHOICES} = 1;
	$self->{WIZARD}->setDone();
	return;
    }
    if (scalar(@keys) == 1)
    {
	# If there is only one choice, pick it and move on.
	$wizvars{$self->{VAR_NAME}} = $choices{$keys[0]};
	$self->{WIZARD}->changeState($self->{NEXT_STATE});
	return;
    }

    # Otherwise, do normal processing in the render routine.

    return;
}

sub determineChoices {
    return {"NO_CHOICE" => "No choices were given."};
}

sub render { 
    my $self = shift;
    my $result = "";
    my $var = $self->{VAR_NAME};
    my %choices = %{$self->{CHOICE_HASH}};

    if (!defined ($self->{CHOICE_HASH}))
    {
	$self->determineChoices();
    }

    my %choices = %{$self->{CHOICE_HASH}};
    my @keys = keys (%choices);

    $result .= "<select name=\"${var}.forminput\" size=\"10\">\n";

    foreach (@keys)
    {
	$result .= "<option value=\"" . HTML::Entities::encode($choices{$_}) .
	    "\">" . HTML::Entities::encode($_) . "\n";
    }

    $result .= "</select>\n\n";
    return $result;
}

sub postprocess {
    my $self = shift;
    my $wizard = $self->{WIZARD};
    $wizard->setVar($self->{VAR_NAME}, $ENV{"form." . $self->{VAR_NAME} . ".forminput"});
    $wizard->changeState($self->{NEXT_STATE});
    return 1;
}

package Apache::lonwizard::switch_state;

no strict;
@ISA = ("Apache::lonwizard::state");
use strict;


--bowersj21028904511--