Annotation of doc/homework/worktime.html, revision 1.2

1.1       albertel    1: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
                      2: <html>
                      3:   <head>
                      4:     <title>Worktime Program</title>
                      5:   </head>
                      6: 
                      7:   <body>
                      8:     <h1>Worktime Program</h1>
                      9: 
                     10:     <p>
                     11:       In the examples below <i>italicized</i> lines are lines of code
                     12:       that changed from the previous example, <b>bold</b> lines are
                     13:       lines that have been added to the example, and any time
                     14:       "username" appears it should be replaced by your specific
                     15:       username.
                     16:     </p>
1.2     ! albertel   17:     <p>
        !            18:       Please add this to your /etc/httpd/conf/loncapa_apache.conf file
        !            19:     </p>
        !            20:  
        !            21:     <h3>Conf Changes</h3>
        !            22: &lt;Location /adm/username&gt;
        !            23: SetHandler perl-script
        !            24: PerlHandler Apache::username
        !            25: &lt;/Location&gt;
        !            26: 
        !            27: &lt;LocationMatch &quot;\.username$&quot;&gt;
        !            28: SetHandler perl-script
        !            29: PerlHandler Apache::username
        !            30: &lt;/LocationMatch&gt;
        !            31: 
        !            32:        <h3>Example 1</h3>
1.1       albertel   33:     <pre>
                     34: package Apache::username;
                     35: use strict;
                     36: use Apache::Constants qw(:common :http);
                     37: sub handler {
                     38: 	my $r=@_[0];
                     39: 	$r->content_type('text/html');
                     40: 	$r->send_http_header;
                     41: 	return OK if $r->header_only;
                     42: 	$r->print("The username handler");
                     43: 	return OK;
                     44: }
                     45: 1;
                     46: __END__
                     47:     </pre>
                     48:     <h3>Example 2</h3>
                     49:     <pre>
                     50: package Apache::username;
                     51: use strict;
                     52: use Apache::Constants qw(:common :http);
                     53: sub handler {
                     54: 	my $r=@_[0];
                     55: 	$r->content_type('text/html');
                     56: 	$r->send_http_header;
                     57: 	return OK if $r->header_only;
                     58: 	<i>$r->print("The username handler is in use by $ENV{'user.name'}");</i>
                     59: 	return OK;
                     60: }
                     61: 1;
                     62: __END__
                     63:     </pre>
                     64:     <h3>Example 3</h3>
                     65:     <pre>
                     66: package Apache::username;
                     67: use strict;
                     68: use Apache::Constants qw(:common :http);
                     69: <b>use Apache::lonnet;</b>
                     70: sub handler {
                     71: 	my $r=@_[0];
                     72: 	$r->content_type('text/html');
                     73: 	$r->send_http_header;
                     74: 	return OK if $r->header_only;
                     75: 	<i>$r->print("The username handler is in use by $ENV{'user.name'} looking for "
                     76:                      .$r->uri."&lt;br&gt;");</i>
                     77: 	<b>my $file=&Apache::lonnet::filelocation("",$r->uri);</b>
                     78: 	<b>my $contents=&Apache::lonnet::getfile($file);</b>
                     79: 	<b>$r->print($contents);</b>
                     80: 	return OK;
                     81: }
                     82: 1;
                     83: __END__
                     84:     </pre>
                     85:     <h3>Example 4</h3>
                     86:     <pre>
                     87: package Apache::username;
                     88: use strict;
                     89: use Apache::Constants qw(:common :http);
                     90: use Apache::lonnet;
                     91: sub handler {
                     92: 	my $r=@_[0];
                     93: 	$r->content_type('text/html');
                     94: 	$r->send_http_header;
                     95: 	return OK if $r->header_only;
                     96: 	$r->print("The username handler is in use by $ENV{'user.name'} looking for "
                     97:                    .$r->uri."&lt;br&gt;");
                     98: 	my $file=&Apache::lonnet::filelocation("",$r->uri);
                     99: 	my $contents=&Apache::lonnet::getfile($file);
                    100: 	<b>$contents=~s/simple/complex/g;</b>
                    101: 	$r->print($contents);
                    102: 	return OK;
                    103: }
                    104: 1;
                    105: __END__
                    106:     </pre>
                    107:     <h3>Example 5</h3>
                    108:     <pre>
                    109: package Apache::username;
                    110: use strict;
                    111: use Apache::Constants qw(:common :http);
                    112: use Apache::lonnet;
                    113: sub handler {
                    114:         my $r=@_[0];
                    115:         $r->content_type('text/html');
                    116:         $r->send_http_header;
                    117:         return OK if $r->header_only;
                    118:         $r->print("The username handler is in use by $ENV{'user.name'} looking for "
                    119:                    .$r->uri."&lt;br&gt;");
                    120:         my $file=&amp;Apache::lonnet::filelocation("",$r->uri);
                    121:         my $contents=&amp;Apache::lonnet::getfile($file);
                    122:         $contents=~s/simple/complex/g;
                    123:         $r->print($contents);
                    124:         <b>my %hash=&amp;Apache::lonnet::get('username',('info'));
                    125:         #handle any errors
                    126:         if ($hash{'info'} =~ m/^error:.*/) {
                    127:                 $r->print("&lt;br&gt;An error -$hash{'info'}- occured");
                    128:         } else {
                    129:                 $r->print("&lt;br&gt;Last time you said $hash{'info'}");
                    130:         }
                    131:         if ($ENV{'form.info'}) {
                    132:                 $r->print("&lt;br&gt;Now you say $ENV{'form.info'}");
                    133:                 $hash{'info'}=$ENV{'form.info'};
                    134:                 &amp;Apache::lonnet::put('username',%hash);
                    135:         }</b>
                    136:         return OK;
                    137: }
                    138: 1;
                    139: __END__
                    140:     </pre>
                    141:     <h3>Example 6</h3>
                    142:     <pre>
                    143: &lt;html&gt;
                    144: 	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
                    145: 	&lt;body&gt;
                    146: 		This is a simple file
                    147: 	&lt;/body&gt;
                    148: &lt;/html&gt;
                    149:     </pre>
                    150:     <h3>Example 7</h3>
                    151:     <pre>
                    152: &lt;html&gt;
                    153: 	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
                    154: 	&lt;body&gt;
                    155: 		This is a simple file
                    156: 	        <b>&lt;form method="POST" action="/~username/a.username"&gt;
                    157: 		       &lt;input type="text" name="info"&gt;&lt;/input&gt;
                    158: 		       &lt;input type="submit" name="Submit"&gt;&lt;/input&gt;
                    159:                 &lt;/form&gt;</b>
                    160: 	&lt;/body&gt;
                    161: &lt;/html&gt;
                    162: 
                    163:     </pre>
                    164:     <ol>
                    165:       <li>
                    166: 	login
                    167: 	<ol>
                    168: 	  <li>
                    169: 	    First login to the CSE machine using the username guest__
                    170: 	    and the password CAPA4all.
                    171: 	  </li>
                    172: 	  <li>
                    173: 	    Bring up a terminal by clicnking on the monitor icon with
                    174: 	    a foot at the bottom of the screen.
                    175: 	  </li>
                    176: 	  <li>
                    177: 	    Start up a netscape by typing netscape&amp; in the terminal.
                    178: 	  </li>
                    179: 	  <li>
                    180: 	    telnet from the terminal to data.lite.msu.edu, login using
                    181: 	    your username and the password guts
                    182: 	  </li>
                    183: 	  <li>
                    184: 	    Login into LON-CAPA in netscape by pointing the browser at
                    185: 	    http://data.lite.msu.edu and typing in your username and
                    186: 	    guts
                    187: 	  </li>
                    188: 	</ol>
                    189:       </li>
                    190:       <li> 
                    191: 	Using the terminal edit the file ~/username.pm using your
                    192: 	favorite unix text editor and type in example 1
                    193:       </li>
                    194:       <li>
                    195: 	Point netscape at "http://data.lite.msu.edu/adm/username". You
                    196: 	should see a the simple message the handler prints out.
                    197:       </li>
                    198:       <li>
                    199: 	Change ~/username.pm to be what is in Example 2, the
                    200: 	italicized line is the only one that changed.
                    201:       </li>
                    202:       <li>
                    203: 	In netscape reload
                    204: 	"http://data.lite.msu.edu/adm/username". You should see the
                    205: 	output of the handler should now have your username, which it
                    206: 	got from the session enviroment.
                    207:       </li>
                    208:       <li>
                    209: 	Next in netscape goto
                    210: 	"http://data.lite.msu.edu/~username/a.username". You should
                    211: 	see the same output as before.
                    212:       </li>
                    213:       <li>
                    214: 	Using the terminal edit the file ~/public_html/a.username and
                    215: 	put in it example5 using your favorite unix text editor.
                    216:       </li>
                    217:       <li>
                    218: 	Change ~/username.pm to be what is in Example 3, the
                    219: 	italicized lines are changed and the bold lines should be
                    220: 	added.
                    221:       </li>
                    222:       <li>
                    223: 	In netscape reload
                    224: 	"http://data.lite.msu.edu/~username/a.username". You should
                    225: 	see the output of the handler contains the contents of the file
                    226: 	that you created along with the name of the file.
                    227:       </li>
                    228:       <li>
                    229: 	Change ~/username.pm to be what is in Example 4, the
                    230: 	bold line should be added.
                    231:       </li>
                    232:       <li>
                    233: 	In netscape reload
                    234: 	"http://data.lite.msu.edu/~username/a.username". You should
                    235: 	see the output of the handler contains the contents of the
                    236: 	file that you created along with the name of the file, except
                    237: 	that this time all instances of the word "simple" have been
                    238: 	replaced with the word "complex", this includes the one in the
                    239: 	title and the one in the body of the file.
                    240:       </li>
                    241:       <li>
                    242: 	<ol>
                    243: 	  <li>
                    244: 	    Change what is in ~/username.pm to be what is in Example
                    245: 	    5. The bold section of code needs to be added.
                    246: 	  </li>
                    247: 	  <li>
                    248: 	    Change what is in ~/public_html/a.username to be what is
                    249: 	    in Example 7. The bold section needs to be added
                    250: 	  </li>
                    251: 	  <li>
                    252: 	    In netscape reload
                    253: 	    "http://data.lite.msu.edu/~username/a.username". The web
                    254: 	    page should now contain a form, and say that an error
                    255: 	    occured.
                    256: 	  </li>
                    257: 	  <li>
                    258: 	    Type someting into the form field and click the submit button.
                    259: 	  </li>
                    260: 	  <li>
                    261: 	    The handler should still report an error, but also echo
                    262: 	    back what you typed into the error handler.
                    263: 	  </li>
                    264: 	  <li>
                    265: 	    Type in the terminal
                    266: 	    <pre>
                    267: ls -l /home/httpd/lonUsers/msu/u/s/e/username/
                    268: 	    </pre>
                    269: 	    Notice that there is a username.db file and a
                    270: 	    username.hist file.
                    271: 	  </li>
                    272: 	  <li>
                    273: 	    Type in the terminal
                    274: 	    <pre>
                    275: cat /home/httpd/lonUsers/msu/u/s/e/username/username.hist
                    276: 	    </pre>
                    277: 	    You should see the information that you submitted.
                    278: 	  </li>
                    279: 	  <li>
                    280: 	    In netscape revisit
                    281: 	    "http://data.lite.msu.edu/~username/a.username". (Do
                    282: 	    this by hitting return in the URL field of netscape, Don't
                    283: 	    use the reload button.) Notice that the handler no longer
                    284: 	    has an error. Also notice that the handler tells you what
                    285: 	    you said last time.
                    286: 	  </li>
                    287: 	  <li>
                    288: 	    Type something new into the text field and hit submit. The
                    289: 	    handler should tell you the first submission and the last
                    290: 	    submission.
                    291: 	  </li>
                    292: 	</ol>
                    293:       </li>
                    294:       <li>
                    295: 	Extra credit: convert Example 5 to use store/restore instead
                    296: 	of the get/put. You will need to publish a .username file and
                    297: 	include it into a map. (Note that violin.sequence is the
                    298: 	toplevel map for you course.
                    299:       </li>
                    300:       <li>
                    301: 	Extra credit: Use Apache::lonxml::xmlparse to properly process the html file.
                    302: 	Use &lt;window&gt;&lt;/window&gt; in your example .username file.
                    303:       </li>
                    304:     </ol>
                    305:     <h2>Helpful Notes</h2>
                    306:     <ul>
                    307:       <li>
                    308: 	If you the error handler does come up, the first bold line
                    309: 	will indicate what error the server process detected.
                    310:       </li>
                    311:       <li>
                    312: 	Remember that Apache::lonnet::put and Apache::lonnet::get
                    313: 	store data that is user wide. I use them for simplicity sake
                    314: 	here. Every .username file will read and write to the same
                    315: 	data location in the last example. Use store/restore if you
                    316: 	want to have data stored per unique resource instance in a
                    317: 	specific course. However this means that store/restore will
                    318: 	through errors if you attempt to use them in a context in
                    319: 	which a resource isn't published or isn't uniquely identified
                    320: 	(i.e. browsing resources.)
                    321:       </li>
                    322:     </ul>
                    323:     <hr>
                    324:     <address><a href="mailto:albertel@msu.edu">Guy Albertelli</a></address>
                    325: <!-- Created: Wed May 23 02:34:54 EDT 2001 -->
                    326: <!-- hhmts start -->
                    327: Last modified: Thu May 24 07:53:18 EDT 2001
                    328: <!-- hhmts end -->
                    329:   </body>
                    330: </html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>