Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.11
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: #
1.11 ! www 7: # 10/17 Gerd Kortemeyer
1.1 tyszkabe 8: #
9: #
10: ##################
11:
1.2 tyszkabe 12: package Apache::admannotations;
1.1 tyszkabe 13:
14: use strict;
15: use CGI qw(:all);
16: use Apache::Constants qw(:common);
1.8 tyszkabe 17: use Apache::lonnet();
1.1 tyszkabe 18:
19: # --------------------------------------------------------------Put annotation
20:
21: sub write_annotation {
1.11 ! www 22: my $urlold=shift;
1.4 tyszkabe 23: my $annotation=shift;
1.11 ! www 24: $urlold=~s/^http\:\/\///;
! 25: $urlold=~s/^[^\/]+//;
! 26: if ($annotation) {
! 27: &Apache::lonnet::put("annotations",($urlold => $annotation));
! 28: }
1.1 tyszkabe 29: return;
30: }
31:
32: # --------------------------------------------------------------Get annotation
33:
34: sub get_annotation {
1.8 tyszkabe 35: my $urlnew=shift;
1.11 ! www 36: $urlnew=~s/^http\:\/\///;
! 37: $urlnew=~s/^[^\/]+//;
! 38: my %annotation=&Apache::lonnet::get("annotations",$urlnew);
1.9 tyszkabe 39: return %annotation;
1.1 tyszkabe 40: }
41:
42: # ------------------------------------------------------------Construct editor
43:
44: sub construct_editor {
1.8 tyszkabe 45: my $annotation=shift;
46: my $urlnew=shift;
1.5 tyszkabe 47: return(<<END_HTML)
1.2 tyszkabe 48: <html>
49: <head>
50: <title>Annotations</title>
1.5 tyszkabe 51: <script language="JavaScript">
1.4 tyszkabe 52: mainhost=window.opener.opener;
53: function getDomain() {
1.8 tyszkabe 54: document.annotInfo.urlnew.value=mainhost.location.href;
1.4 tyszkabe 55: return true;
1.2 tyszkabe 56: }
1.1 tyszkabe 57: </script>
1.2 tyszkabe 58: </head>
1.11 ! www 59: <body BGCOLOR="#555555">
1.5 tyszkabe 60: <center>
1.10 tyszkabe 61: <FORM name="annotInfo" method="post" action="/adm/annotations" onSubmit="return getDomain();">
1.8 tyszkabe 62: <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annotation</TEXTAREA><br>
63: <INPUT TYPE="hidden" name="urlold" value="$urlnew")>
64: <INPUT TYPE="hidden" name="urlnew" value="">
1.5 tyszkabe 65: <INPUT TYPE=submit name=submit value="Save and Update">
66: <INPUT TYPE=button name="close" value="close (no save)" onClick="javascript:window.close();">
67: </FORM>
68: </center>
1.2 tyszkabe 69: </body>
70: </html>
1.1 tyszkabe 71: END_HTML
72: }
73:
1.7 tyszkabe 74: # ----------------------------------------------------Constructs error window
1.5 tyszkabe 75:
1.6 tyszkabe 76: sub construct_error {
77: my $annot_error=shift;
78: my $button_name=shift;
1.5 tyszkabe 79: return(<<END_HTML2)
80: <html><head>
81: <title>Annotations</title>
82: <script language="JavaScript">
83: mainhost=window.opener.opener;
84: function getDomain() {
1.8 tyszkabe 85: document.annotInfo.urlnew.value=mainhost.location.href;
1.5 tyszkabe 86: return true;
87: }
88: </script>
89: </head>
1.11 ! www 90: <body BGCOLOR="#555555">
1.5 tyszkabe 91: <center>
1.10 tyszkabe 92: <FORM name="annotInfo" method="post" action="/adm/annotations" onSubmit="getDomain();">
1.6 tyszkabe 93: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5 tyszkabe 94: <td>
95: <i>
1.6 tyszkabe 96: $annot_error
1.5 tyszkabe 97: </i>
98: </td>
99: </table>
1.8 tyszkabe 100: <INPUT TYPE="hidden" name="urlold" value="")>
101: <INPUT TYPE="hidden" name="urlnew" value="">
1.6 tyszkabe 102: <INPUT TYPE=submit name=submit value="$button_name">
1.5 tyszkabe 103: <INPUT TYPE=button name="close" value="close (no save)" onClick="javascript:window.close();">
104: </FORM>
105: </center>
106: </body>
107: </html>
108: END_HTML2
109: }
110:
1.7 tyszkabe 111: # ---------------------------------------------------------------Main Handler
1.1 tyszkabe 112:
113: sub handler {
1.5 tyszkabe 114: my $r=shift;
1.11 ! www 115:
! 116: $r->content_type('text/html');
! 117: $r->send_http_header;
! 118: return OK if $r->header_only;
! 119:
! 120:
1.8 tyszkabe 121: my $page;
1.9 tyszkabe 122: my %annot_hash;
1.8 tyszkabe 123: my $urlold;
1.5 tyszkabe 124: my $annotation;
1.8 tyszkabe 125: my $urlnew;
1.11 ! www 126:
1.8 tyszkabe 127: if (exists($ENV{'form.urlold'})) {
128: $urlold=$ENV{'form.urlold'};
129: $annotation=$ENV{'form.annotation'};
130: write_annotation($urlold,$annotation);
1.5 tyszkabe 131: }
1.8 tyszkabe 132: if (exists($ENV{'form.urlnew'})) {
133: $urlnew=$ENV{'form.urlnew'};
134: if ($urlnew eq '') {
1.11 ! www 135: $page=construct_error("Cannot annotate current window. Please point your browser to a LON-CAPA page and then 'continue'.","continue");
1.7 tyszkabe 136: } else {
1.8 tyszkabe 137: if ($urlold eq $urlnew) {
1.9 tyszkabe 138: $annot_hash{$urlnew}=$annotation;
1.8 tyszkabe 139: } else {
1.9 tyszkabe 140: %annot_hash=get_annotation($urlnew);
1.8 tyszkabe 141: }
1.9 tyszkabe 142: $page=construct_editor($annot_hash{$urlnew},$urlnew);
1.7 tyszkabe 143: }
1.5 tyszkabe 144: } else {
1.8 tyszkabe 145: $page=construct_error("Connection broken with home server. Please contact your system administrator.","try again");
1.5 tyszkabe 146: }
1.8 tyszkabe 147: $r->print($page);
1.5 tyszkabe 148: return OK;
1.1 tyszkabe 149: }
150:
151: 1;
152: __END__
1.8 tyszkabe 153:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>