Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.10
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);
1.8 tyszkabe 16: use Apache::lonnet();
1.1 tyszkabe 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 {
1.8 tyszkabe 30: my $urlnew=shift;
1.9 tyszkabe 31: my %annotation=Apache::lonnet::get("annotations",$urlnew);
32: return %annotation;
1.1 tyszkabe 33: }
34:
35: # ------------------------------------------------------------Construct editor
36:
37: sub construct_editor {
1.8 tyszkabe 38: my $annotation=shift;
39: my $urlnew=shift;
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() {
1.8 tyszkabe 47: document.annotInfo.urlnew.value=mainhost.location.href;
1.4 tyszkabe 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>
1.10 ! tyszkabe 54: <FORM name="annotInfo" method="post" action="/adm/annotations" onSubmit="return getDomain();">
1.8 tyszkabe 55: <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annotation</TEXTAREA><br>
56: <INPUT TYPE="hidden" name="urlold" value="$urlnew")>
57: <INPUT TYPE="hidden" name="urlnew" value="">
1.5 tyszkabe 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.7 tyszkabe 67: # ----------------------------------------------------Constructs error window
1.5 tyszkabe 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() {
1.8 tyszkabe 78: document.annotInfo.urlnew.value=mainhost.location.href;
1.5 tyszkabe 79: return true;
80: }
81: </script>
82: </head>
83: <body BGCOLOR=\"#BBBBBB\">
84: <center>
1.10 ! tyszkabe 85: <FORM name="annotInfo" method="post" action="/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>
1.8 tyszkabe 93: <INPUT TYPE="hidden" name="urlold" value="")>
94: <INPUT TYPE="hidden" name="urlnew" 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.7 tyszkabe 104: # ---------------------------------------------------------------Main Handler
1.1 tyszkabe 105:
106: sub handler {
1.5 tyszkabe 107: my $r=shift;
1.8 tyszkabe 108: my $page;
1.9 tyszkabe 109: my %annot_hash;
1.8 tyszkabe 110: my $urlold;
1.5 tyszkabe 111: my $annotation;
1.8 tyszkabe 112: my $urlnew;
1.5 tyszkabe 113: $r->content_type('text/html');
114: $r->send_http_header;
1.8 tyszkabe 115: if (exists($ENV{'form.urlold'})) {
116: $urlold=$ENV{'form.urlold'};
117: $annotation=$ENV{'form.annotation'};
118: write_annotation($urlold,$annotation);
1.5 tyszkabe 119: }
1.8 tyszkabe 120: if (exists($ENV{'form.urlnew'})) {
121: $urlnew=$ENV{'form.urlnew'};
122: if ($urlnew eq '') {
123: $page=construct_error("Cannot annotate current window. Please point your browser to a Lon-CAPA page and then 'continue'.","continue");
1.7 tyszkabe 124: } else {
1.8 tyszkabe 125: if ($urlold eq $urlnew) {
1.9 tyszkabe 126: $annot_hash{$urlnew}=$annotation;
1.8 tyszkabe 127: } else {
1.9 tyszkabe 128: %annot_hash=get_annotation($urlnew);
1.8 tyszkabe 129: }
1.9 tyszkabe 130: $page=construct_editor($annot_hash{$urlnew},$urlnew);
1.7 tyszkabe 131: }
1.5 tyszkabe 132: } else {
1.8 tyszkabe 133: $page=construct_error("Connection broken with home server. Please contact your system administrator.","try again");
1.5 tyszkabe 134: }
1.8 tyszkabe 135: $r->print($page);
1.5 tyszkabe 136: return OK;
1.1 tyszkabe 137: }
138:
139: 1;
140: __END__
1.8 tyszkabe 141:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>