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