File:
[LON-CAPA] /
doc /
homework /
worktime.html
Revision
1.4:
download - view:
text,
annotated -
select for diffs
Thu Apr 7 06:56:20 2005 UTC (19 years, 7 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_X,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- ENV -> env
<!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>
<p>
Please add this to your /etc/httpd/conf/loncapa_apache.conf file
</p>
<h3>Conf Changes</h3>
<Location /adm/username><br />
PerlAccessHandler Apache::lonacc<br />
SetHandler perl-script<br />
PerlHandler Apache::username<br />
</Location><br />
<LocationMatch "\.username$"><br />
SetHandler perl-script<br />
PerlHandler Apache::username<br />
</LocationMatch><br />
<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."<br>");</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."<br>");
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."<br>");
my $file=&Apache::lonnet::filelocation("",$r->uri);
my $contents=&Apache::lonnet::getfile($file);
$contents=~s/simple/complex/g;
$r->print($contents);
<b>my %hash=&Apache::lonnet::get('username',('info'));
#handle any errors
if ($hash{'info'} =~ m/^error:.*/) {
$r->print("<br>An error -$hash{'info'}- occured");
} else {
$r->print("<br>Last time you said $hash{'info'}");
}
if ($env{'form.info'}) {
$r->print("<br>Now you say $env{'form.info'}");
$hash{'info'}=$env{'form.info'};
&Apache::lonnet::put('username',%hash);
}</b>
return OK;
}
1;
__END__
</pre>
<h3>Example 6</h3>
<pre>
<html>
<head><title> A simple file </title></head>
<body>
This is a simple file
</body>
</html>
</pre>
<h3>Example 7</h3>
<pre>
<html>
<head><title> A simple file </title></head>
<body>
This is a simple file
<b><form method="POST" action="/~username/a.username">
<input type="text" name="info"></input>
<input type="submit" name="Submit"></input>
</form></b>
</body>
</html>
</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& 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 <window></window> 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>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>