Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.12
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;
40: my $urlnew=shift;
1.5 tyszkabe 41: return(<<END_HTML)
1.2 tyszkabe 42: <html>
43: <head>
44: <title>Annotations</title>
1.12 ! www 45: <script>
! 46: var timeout;
! 47:
! 48: function changed() {
! 49: var urlnew=window.opener.clientwindow.location.href;
! 50: if (urlnew!=document.annotInfo.urlold.value) {
! 51: document.annotInfo.urlnew.value=urlnew;
! 52: document.annotInfo.submit();
! 53: }
! 54: timeout=setTimeout('changed();','1000');
1.2 tyszkabe 55: }
1.1 tyszkabe 56: </script>
1.2 tyszkabe 57: </head>
1.12 ! www 58: <body BGCOLOR="#555555"
! 59: onLoad="timeout=setTimeout('changed()','1000')"
! 60: onUnload='clearTimeout(timeout);'>
1.5 tyszkabe 61: <center>
1.12 ! www 62: <FORM name="annotInfo" method="post" action="/adm/annotations">
1.8 tyszkabe 63: <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annotation</TEXTAREA><br>
1.12 ! www 64: <INPUT TYPE="hidden" name="urlold" value="$urlnew">
1.8 tyszkabe 65: <INPUT TYPE="hidden" name="urlnew" value="">
1.12 ! www 66: <INPUT TYPE=button name=send value="Save and Update"
! 67: onClick=
! 68: "javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();">
! 69: <INPUT TYPE=button name="close" value="Close (no save)" onClick="javascript:window.close();">
1.5 tyszkabe 70: </FORM>
71: </center>
1.2 tyszkabe 72: </body>
73: </html>
1.1 tyszkabe 74: END_HTML
75: }
76:
1.7 tyszkabe 77: # ----------------------------------------------------Constructs error window
1.5 tyszkabe 78:
1.6 tyszkabe 79: sub construct_error {
80: my $annot_error=shift;
81: my $button_name=shift;
1.5 tyszkabe 82: return(<<END_HTML2)
83: <html><head>
84: <title>Annotations</title>
85: </head>
1.11 www 86: <body BGCOLOR="#555555">
1.5 tyszkabe 87: <center>
1.12 ! www 88: <FORM name="annotInfo" method="post" action="/adm/annotations">
1.6 tyszkabe 89: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5 tyszkabe 90: <td>
1.12 ! www 91: <font size=+1><i>
1.6 tyszkabe 92: $annot_error
1.12 ! www 93: </i></font>
1.5 tyszkabe 94: </td>
95: </table>
1.12 ! www 96: <INPUT TYPE="hidden" name="urlold" value="">
1.8 tyszkabe 97: <INPUT TYPE="hidden" name="urlnew" value="">
1.12 ! www 98: <INPUT TYPE=button name=send value="$button_name"
! 99: onClick=
! 100: "javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();">
! 101: <INPUT TYPE=button name="close" value="Close" onClick="javascript:window.close();">
1.5 tyszkabe 102: </FORM>
103: </center>
104: </body>
105: </html>
106: END_HTML2
107: }
108:
1.7 tyszkabe 109: # ---------------------------------------------------------------Main Handler
1.1 tyszkabe 110:
111: sub handler {
1.5 tyszkabe 112: my $r=shift;
1.11 www 113:
114: $r->content_type('text/html');
115: $r->send_http_header;
116: return OK if $r->header_only;
117:
118:
1.8 tyszkabe 119: my $page;
1.9 tyszkabe 120: my %annot_hash;
1.12 ! www 121:
! 122: my $urlold=$ENV{'form.urlold'};
! 123: $urlold=~s/^http\:\/\///;
! 124: $urlold=~s/^[^\/]+//;
! 125: my $urlnew=$ENV{'form.urlnew'};
! 126: $urlnew=~s/^http\:\/\///;
! 127: $urlnew=~s/^[^\/]+//;
! 128: my $annotation=$ENV{'form.annotation'};
! 129:
! 130: if ($urlold) {
1.8 tyszkabe 131: write_annotation($urlold,$annotation);
1.5 tyszkabe 132: }
1.8 tyszkabe 133: if (exists($ENV{'form.urlnew'})) {
1.12 ! www 134: unless ($urlnew) {
! 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.12 ! www 142: $page=construct_editor($annot_hash{$urlnew},$ENV{'form.urlnew'});
1.7 tyszkabe 143: }
1.5 tyszkabe 144: }
1.8 tyszkabe 145: $r->print($page);
1.5 tyszkabe 146: return OK;
1.1 tyszkabe 147: }
148:
149: 1;
150: __END__
1.8 tyszkabe 151:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>