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