[LON-CAPA-cvs] cvs: doc /homework worktime.html

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 07 Jun 2002 06:39:18 -0000


This is a MIME encoded message

--albertel1023431958
Content-Type: text/plain

albertel		Fri Jun  7 02:39:18 2002 EDT

  Added files:                 
    /doc/homework	worktime.html 
  Log:
  - adding last year worktime example to the repoistory
  
  
--albertel1023431958
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20020607023918.txt"


Index: doc/homework/worktime.html
+++ doc/homework/worktime.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title>Worktime Program</title>
  </head>

  <body>
    <h1>Worktime Program</h1>

    <p>
      In the examples below <i>italicized</i> lines are lines of code
      that changed from the previous example, <b>bold</b> lines are
      lines that have been added to the example, and any time
      "username" appears it should be replaced by your specific
      username.
    </p>
    <h3>Example 1</h3>
    <pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	$r->print("The username handler");
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 2</h3>
    <pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	<i>$r->print("The username handler is in use by $ENV{'user.name'}");</i>
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 3</h3>
    <pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
<b>use Apache::lonnet;</b>
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	<i>$r->print("The username handler is in use by $ENV{'user.name'} looking for "
                     .$r->uri."&lt;br&gt;");</i>
	<b>my $file=&Apache::lonnet::filelocation("",$r->uri);</b>
	<b>my $contents=&Apache::lonnet::getfile($file);</b>
	<b>$r->print($contents);</b>
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 4</h3>
    <pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	$r->print("The username handler is in use by $ENV{'user.name'} looking for "
                   .$r->uri."&lt;br&gt;");
	my $file=&Apache::lonnet::filelocation("",$r->uri);
	my $contents=&Apache::lonnet::getfile($file);
	<b>$contents=~s/simple/complex/g;</b>
	$r->print($contents);
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 5</h3>
    <pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
sub handler {
        my $r=@_[0];
        $r->content_type('text/html');
        $r->send_http_header;
        return OK if $r->header_only;
        $r->print("The username handler is in use by $ENV{'user.name'} looking for "
                   .$r->uri."&lt;br&gt;");
        my $file=&amp;Apache::lonnet::filelocation("",$r->uri);
        my $contents=&amp;Apache::lonnet::getfile($file);
        $contents=~s/simple/complex/g;
        $r->print($contents);
        <b>my %hash=&amp;Apache::lonnet::get('username',('info'));
        #handle any errors
        if ($hash{'info'} =~ m/^error:.*/) {
                $r->print("&lt;br&gt;An error -$hash{'info'}- occured");
        } else {
                $r->print("&lt;br&gt;Last time you said $hash{'info'}");
        }
        if ($ENV{'form.info'}) {
                $r->print("&lt;br&gt;Now you say $ENV{'form.info'}");
                $hash{'info'}=$ENV{'form.info'};
                &amp;Apache::lonnet::put('username',%hash);
        }</b>
        return OK;
}
1;
__END__
    </pre>
    <h3>Example 6</h3>
    <pre>
&lt;html&gt;
	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
	&lt;body&gt;
		This is a simple file
	&lt;/body&gt;
&lt;/html&gt;
    </pre>
    <h3>Example 7</h3>
    <pre>
&lt;html&gt;
	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
	&lt;body&gt;
		This is a simple file
	        <b>&lt;form method="POST" action="/~username/a.username"&gt;
		       &lt;input type="text" name="info"&gt;&lt;/input&gt;
		       &lt;input type="submit" name="Submit"&gt;&lt;/input&gt;
                &lt;/form&gt;</b>
	&lt;/body&gt;
&lt;/html&gt;

    </pre>
    <ol>
      <li>
	login
	<ol>
	  <li>
	    First login to the CSE machine using the username guest__
	    and the password CAPA4all.
	  </li>
	  <li>
	    Bring up a terminal by clicnking on the monitor icon with
	    a foot at the bottom of the screen.
	  </li>
	  <li>
	    Start up a netscape by typing netscape&amp; in the terminal.
	  </li>
	  <li>
	    telnet from the terminal to data.lite.msu.edu, login using
	    your username and the password guts
	  </li>
	  <li>
	    Login into LON-CAPA in netscape by pointing the browser at
	    http://data.lite.msu.edu and typing in your username and
	    guts
	  </li>
	</ol>
      </li>
      <li> 
	Using the terminal edit the file ~/username.pm using your
	favorite unix text editor and type in example 1
      </li>
      <li>
	Point netscape at "http://data.lite.msu.edu/adm/username". You
	should see a the simple message the handler prints out.
      </li>
      <li>
	Change ~/username.pm to be what is in Example 2, the
	italicized line is the only one that changed.
      </li>
      <li>
	In netscape reload
	"http://data.lite.msu.edu/adm/username". You should see the
	output of the handler should now have your username, which it
	got from the session enviroment.
      </li>
      <li>
	Next in netscape goto
	"http://data.lite.msu.edu/~username/a.username". You should
	see the same output as before.
      </li>
      <li>
	Using the terminal edit the file ~/public_html/a.username and
	put in it example5 using your favorite unix text editor.
      </li>
      <li>
	Change ~/username.pm to be what is in Example 3, the
	italicized lines are changed and the bold lines should be
	added.
      </li>
      <li>
	In netscape reload
	"http://data.lite.msu.edu/~username/a.username". You should
	see the output of the handler contains the contents of the file
	that you created along with the name of the file.
      </li>
      <li>
	Change ~/username.pm to be what is in Example 4, the
	bold line should be added.
      </li>
      <li>
	In netscape reload
	"http://data.lite.msu.edu/~username/a.username". You should
	see the output of the handler contains the contents of the
	file that you created along with the name of the file, except
	that this time all instances of the word "simple" have been
	replaced with the word "complex", this includes the one in the
	title and the one in the body of the file.
      </li>
      <li>
	<ol>
	  <li>
	    Change what is in ~/username.pm to be what is in Example
	    5. The bold section of code needs to be added.
	  </li>
	  <li>
	    Change what is in ~/public_html/a.username to be what is
	    in Example 7. The bold section needs to be added
	  </li>
	  <li>
	    In netscape reload
	    "http://data.lite.msu.edu/~username/a.username". The web
	    page should now contain a form, and say that an error
	    occured.
	  </li>
	  <li>
	    Type someting into the form field and click the submit button.
	  </li>
	  <li>
	    The handler should still report an error, but also echo
	    back what you typed into the error handler.
	  </li>
	  <li>
	    Type in the terminal
	    <pre>
ls -l /home/httpd/lonUsers/msu/u/s/e/username/
	    </pre>
	    Notice that there is a username.db file and a
	    username.hist file.
	  </li>
	  <li>
	    Type in the terminal
	    <pre>
cat /home/httpd/lonUsers/msu/u/s/e/username/username.hist
	    </pre>
	    You should see the information that you submitted.
	  </li>
	  <li>
	    In netscape revisit
	    "http://data.lite.msu.edu/~username/a.username". (Do
	    this by hitting return in the URL field of netscape, Don't
	    use the reload button.) Notice that the handler no longer
	    has an error. Also notice that the handler tells you what
	    you said last time.
	  </li>
	  <li>
	    Type something new into the text field and hit submit. The
	    handler should tell you the first submission and the last
	    submission.
	  </li>
	</ol>
      </li>
      <li>
	Extra credit: convert Example 5 to use store/restore instead
	of the get/put. You will need to publish a .username file and
	include it into a map. (Note that violin.sequence is the
	toplevel map for you course.
      </li>
      <li>
	Extra credit: Use Apache::lonxml::xmlparse to properly process the html file.
	Use &lt;window&gt;&lt;/window&gt; in your example .username file.
      </li>
    </ol>
    <h2>Helpful Notes</h2>
    <ul>
      <li>
	If you the error handler does come up, the first bold line
	will indicate what error the server process detected.
      </li>
      <li>
	Remember that Apache::lonnet::put and Apache::lonnet::get
	store data that is user wide. I use them for simplicity sake
	here. Every .username file will read and write to the same
	data location in the last example. Use store/restore if you
	want to have data stored per unique resource instance in a
	specific course. However this means that store/restore will
	through errors if you attempt to use them in a context in
	which a resource isn't published or isn't uniquely identified
	(i.e. browsing resources.)
      </li>
    </ul>
    <hr>
    <address><a href="mailto:albertel@msu.edu">Guy Albertelli</a></address>
<!-- Created: Wed May 23 02:34:54 EDT 2001 -->
<!-- hhmts start -->
Last modified: Thu May 24 07:53:18 EDT 2001
<!-- hhmts end -->
  </body>
</html>

--albertel1023431958--