File:
[LON-CAPA] /
doc /
techtips /
worktime.html
Revision
1.2:
download - view:
text,
annotated -
select for diffs
Thu Apr 7 06:56:20 2005 UTC (19 years, 6 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
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: Type the following in the terminal.
163: <pre>
164: xhost +data.lite.msu.edu
165: </pre>
166: <li>
167: Start up a netscape by typing netscape& in the terminal.
168: </li>
169: <li>
170: telnet from the terminal to data.lite.msu.edu, login using
171: your username and the password guts
172: </li>
173: <li>
174: Login into LON-CAPA in netscape by pointing the browser at
175: http://data.lite.msu.edu and typing in your username and
176: guts
177: </li>
178: </ol>
179: </li>
180: <li>
181: Using the terminal edit the file ~/username.pm using your
182: favorite unix text editor and type in example 1
183: </li>
184: <li>
185: Point netscape at "http://data.lite.msu.edu/adm/username". You
186: should see a the simple message the handler prints out.
187: </li>
188: <li>
189: Change ~/username.pm to be what is in Example 2, the
190: italicized line is the only one that changed.
191: </li>
192: <li>
193: In netscape reload
194: "http://data.lite.msu.edu/adm/username". You should see the
195: output of the handler should now have your username, which it
196: got from the session enviroment.
197: </li>
198: <li>
199: Next in netscape goto
200: "http://data.lite.msu.edu/~username/a.username". You should
201: see the same output as before.
202: </li>
203: <li>
204: Using the terminal edit the file ~/public_html/a.username and
205: put in it example5 using your favorite unix text editor.
206: </li>
207: <li>
208: Change ~/username.pm to be what is in Example 3, the
209: italicized lines are changed and the bold lines should be
210: added.
211: </li>
212: <li>
213: In netscape reload
214: "http://data.lite.msu.edu/~username/a.username". You should
215: see the output of the handler contains the contents of the file
216: that you created along with the name of the file.
217: </li>
218: <li>
219: Change ~/username.pm to be what is in Example 4, the
220: bold line should be 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
226: file that you created along with the name of the file, except
227: that this time all instances of the word "simple" have been
228: replaced with the word "complex", this includes the one in the
229: title and the one in the body of the file.
230: </li>
231: <li>
232: <ol>
233: <li>
234: Change what is in ~/username.pm to be what is in Example
235: 5. The bold section of code needs to be added.
236: </li>
237: <li>
238: Change what is in ~/public_html/a.username to be what is
239: in Example 7. The bold section needs to be added
240: </li>
241: <li>
242: In netscape reload
243: "http://data.lite.msu.edu/~username/a.username". The web
244: page should now contain a form, and say that an error
245: occured.
246: </li>
247: <li>
248: Type someting into the form field and click the submit button.
249: </li>
250: <li>
251: The handler should still report an error, but also echo
252: back what you typed into the error handler.
253: </li>
254: <li>
255: Type in the terminal
256: <pre>
257: ls -l /home/httpd/lonUsers/msu/u/s/e/username/
258: </pre>
259: Notice that there is a username.db file and a
260: username.hist file.
261: </li>
262: <li>
263: Type in the terminal
264: <pre>
265: cat /home/httpd/lonUsers/msu/u/s/e/username/username.hist
266: </pre>
267: You should see the information that you submitted.
268: </li>
269: <li>
270: In netscape revisit
271: "http://data.lite.msu.edu/~username/a.username". (Do
272: this by hitting return in the URL field of netscape, Don't
273: use the reload button.) Notice that the handler no longer
274: has an error. Also notice that the handler tells you what
275: you said last time.
276: </li>
277: <li>
278: Type something new into the text field and hit submit. The
279: handler should tell you the first submission and the last
280: submission.
281: </li>
282: </ol>
283: </li>
284: <li>
285: Extra credit: convert Example 5 to use store/restore instead
286: of the get/put. You will need to publish a .username file and
287: include it into a map. (Note that violin.sequence is the
288: toplevel map for you course.
289: </li>
290: <li>
291: Extra credit: Use Apache::lonxml::xmlparse to properly process the html file.
292: Use <window></window> in your example .username file.
293: </li>
294: </ol>
295: <h2>Helpful Notes</h2>
296: <ul>
297: <li>
298: If you the error handler does come up, the first bold line
299: will indicate what error the server process detected.
300: </li>
301: <li>
302: Remember that Apache::lonnet::put and Apache::lonnet::get
303: store data that is user wide. I use them for simplicity sake
304: here. Every .username file will read and write to the same
305: data location in the last example. Use store/restore if you
306: want to have data stored per unique resource instance in a
307: specific course. However this means that store/restore will
308: through errors if you attempt to use them in a context in
309: which a resource isn't published or isn't uniquely identified
310: (i.e. browsing resources.)
311: </li>
312: </ul>
313: <hr>
314: <address><a href="mailto:albertel@msu.edu">Guy Albertelli</a></address>
315: <!-- Created: Wed May 23 02:34:54 EDT 2001 -->
316: <!-- hhmts start -->
317: Last modified: Thu May 24 08:16:55 EDT 2001
318: <!-- hhmts end -->
319: </body>
320: </html>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>