Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.7
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.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() {
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.7 ! tyszkabe 104: # ---------------------------------------------------------------Main Handler
1.1 tyszkabe 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.7 ! tyszkabe 111: my $url_new;
! 112: my %annot_hash;
1.5 tyszkabe 113: $r->content_type('text/html');
114: $r->send_http_header;
115: if ($url_old=param("url_old")) {
116: $annotation=param("annotation");
117: write_annotation($url_old,$annotation);
118: }
1.7 ! tyszkabe 119: if (defined(param("url_new"))) {
! 120: $url_new=param("url_new");
! 121: if ($url_new eq "") {
! 122: $page=construct_error("Cannot annotate current window. Please point your browser to a Lon-CAPA page and then 'continue'.","coninue");
1.5 tyszkabe 123: } else {
1.7 ! tyszkabe 124: if ($url_old eq $url_new) {
! 125: %annot_hash=($url_new => $annotation);
! 126: } else {
! 127: %annot_hash=get_annotation($url_new);
! 128: }
! 129: if (exists($annot_hash{"con_lost"})) {
! 130: $page=construct_error("Connection broken with home server. Please contact your system administrator.","try again");
! 131: } else {
! 132: $page=construct_editor($url_new,%annot_hash);
! 133: }
1.6 tyszkabe 134: }
1.5 tyszkabe 135: $r->print($page);
136: } else {
1.6 tyszkabe 137: $page=construct_error("Cannot annotate current window. Please point your browser to a Lon-CAPA page and then 'continue'.","coninue");
1.5 tyszkabe 138: $r->print($page);
139: }
140: return OK;
1.1 tyszkabe 141: }
142:
143: 1;
144: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>