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

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

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