Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.6
1.1 tyszkabe 1: #!/usr/bin/perl -T
2: #
3: # This will take annotations and then plug them into a page.
4: #
5: # 08/25/00 Ben Tyszka
6: #
7: #
8: #
9: ##################
10:
1.2 tyszkabe 11: package Apache::admannotations;
1.1 tyszkabe 12:
13: use strict;
14: use CGI qw(:all);
15: use Apache::Constants qw(:common);
16: use Apache::lonnet;
17:
18: # --------------------------------------------------------------Put annotation
19:
20: sub write_annotation {
21: my $url_old=shift;
1.4 tyszkabe 22: my $annotation=shift;
1.2 tyszkabe 23: Apache::lonnet::put("annotations",($url_old => $annotation));
1.1 tyszkabe 24: return;
25: }
26:
27: # --------------------------------------------------------------Get annotation
28:
29: sub get_annotation {
30: my $url_new=shift;
1.2 tyszkabe 31: my %annotation=Apache::lonnet::get("annotations",($url_new));
32: return %annotation;
1.1 tyszkabe 33: }
34:
35: # ------------------------------------------------------------Construct editor
36:
37: sub construct_editor {
38: my $url_new=shift;
1.2 tyszkabe 39: my %annot_hash=@_;
1.5 tyszkabe 40: return(<<END_HTML)
1.2 tyszkabe 41: <html>
42: <head>
43: <title>Annotations</title>
1.5 tyszkabe 44: <script language="JavaScript">
1.4 tyszkabe 45: mainhost=window.opener.opener;
46: function getDomain() {
47: document.annotInfo.url_new.value=mainhost.location.href;
48: return true;
1.2 tyszkabe 49: }
1.1 tyszkabe 50: </script>
1.2 tyszkabe 51: </head>
52: <body BGCOLOR=\"#BBBBBB\">
1.5 tyszkabe 53: <center>
54: <FORM name="annotInfo" method="post" action="http://kirk.lite.msu.edu/adm/annotations" onSubmit="return getDomain();">
1.2 tyszkabe 55: <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annot_hash{$url_new}</TEXTAREA><br>
56: <INPUT TYPE="hidden" name="url_old" value="$url_new")>
1.5 tyszkabe 57: <INPUT TYPE="hidden" name="url_new" value="">
58: <INPUT TYPE=submit name=submit value="Save and Update">
59: <INPUT TYPE=button name="close" value="close (no save)" onClick="javascript:window.close();">
60: </FORM>
61: </center>
1.2 tyszkabe 62: </body>
63: </html>
1.1 tyszkabe 64: END_HTML
65: }
66:
1.5 tyszkabe 67: # --------------------------------------------Constructs the can't edit window
68:
1.6 ! tyszkabe 69: sub construct_error {
! 70: my $annot_error=shift;
! 71: my $button_name=shift;
1.5 tyszkabe 72: return(<<END_HTML2)
73: <html><head>
74: <title>Annotations</title>
75: <script language="JavaScript">
76: mainhost=window.opener.opener;
77: function getDomain() {
78: document.annotInfo.url_new.value=mainhost.location.href;
79: return true;
80: }
81: </script>
82: </head>
83: <body BGCOLOR=\"#BBBBBB\">
84: <center>
85: <FORM name="annotInfo" method="post" action="http://kirk.lite.msu.edu/adm/annotations" onSubmit="getDomain();">
1.6 ! tyszkabe 86: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5 tyszkabe 87: <td>
88: <i>
1.6 ! tyszkabe 89: $annot_error
1.5 tyszkabe 90: </i>
91: </td>
92: </table>
93: <INPUT TYPE="hidden" name="url_old" value="")>
94: <INPUT TYPE="hidden" name="url_new" value="">
1.6 ! tyszkabe 95: <INPUT TYPE=submit name=submit value="$button_name">
1.5 tyszkabe 96: <INPUT TYPE=button name="close" value="close (no save)" onClick="javascript:window.close();">
97: </FORM>
98: </center>
99: </body>
100: </html>
101: END_HTML2
102: }
103:
1.1 tyszkabe 104: # ----------------------------------------------------------------Main Handler
105:
106: sub handler {
1.5 tyszkabe 107: my $r=shift;
108: my $url_old;
109: my $annotation;
1.6 ! tyszkabe 110: my $page;
1.5 tyszkabe 111: $r->content_type('text/html');
112: $r->send_http_header;
113: if ($url_old=param("url_old")) {
114: $annotation=param("annotation");
115: write_annotation($url_old,$annotation);
116: }
117: if (my $url_new=param("url_new")) {
118: my %annot_hash;
119: if ($url_old eq $url_new) {
120: %annot_hash=($url_new => $annotation);
121: } else {
122: %annot_hash=get_annotation($url_new);
1.1 tyszkabe 123: }
1.6 ! tyszkabe 124: if (exists($annot_hash{"con_lost"})) {
! 125: $page=construct_error("Connection broken with home server. Please contact your system administrator.","try again");
! 126: } else {
! 127: $page=construct_editor($url_new,%annot_hash);
! 128: }
1.5 tyszkabe 129: $r->print($page);
130: } else {
1.6 ! tyszkabe 131: $page=construct_error("Cannot annotate current window. Please point your browser to a Lon-CAPA page and then 'continue'.","coninue");
1.5 tyszkabe 132: $r->print($page);
133: }
134: return OK;
1.1 tyszkabe 135: }
136:
137: 1;
138: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>