Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.19
1.17 albertel 1: # The LearningOnline Network with CAPA
2: # This will take annotations and then plug them into a page.
3: #
1.19 ! albertel 4: # $Id: admannotations.pm,v 1.18 2003/06/23 18:54:37 www Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
1.1 tyszkabe 14: #
1.17 albertel 15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.1 tyszkabe 27: #
28: ##################
29:
1.2 tyszkabe 30: package Apache::admannotations;
1.1 tyszkabe 31:
32: use strict;
33: use Apache::Constants qw(:common);
1.19 ! albertel 34: use Apache::lonnet;
1.1 tyszkabe 35:
36: # --------------------------------------------------------------Put annotation
37:
38: sub write_annotation {
1.11 www 39: my $urlold=shift;
1.4 tyszkabe 40: my $annotation=shift;
1.11 www 41: if ($annotation) {
1.16 albertel 42: &Apache::lonnet::put('nohist_annotations',{$urlold => $annotation});
1.11 www 43: }
1.1 tyszkabe 44: return;
45: }
46:
47: # --------------------------------------------------------------Get annotation
48:
49: sub get_annotation {
1.8 tyszkabe 50: my $urlnew=shift;
1.15 albertel 51: my %annotation=&Apache::lonnet::get('nohist_annotations',[$urlnew]);
1.9 tyszkabe 52: return %annotation;
1.1 tyszkabe 53: }
54:
55: # ------------------------------------------------------------Construct editor
56:
57: sub construct_editor {
1.8 tyszkabe 58: my $annotation=shift;
1.13 www 59: if ($annotation=~/^error:/) { $annotation=''; }
1.8 tyszkabe 60: my $urlnew=shift;
1.5 tyszkabe 61: return(<<END_HTML)
1.2 tyszkabe 62: <html>
63: <head>
64: <title>Annotations</title>
1.12 www 65: <script>
66: var timeout;
67:
68: function changed() {
69: var urlnew=window.opener.clientwindow.location.href;
70: if (urlnew!=document.annotInfo.urlold.value) {
71: document.annotInfo.urlnew.value=urlnew;
72: document.annotInfo.submit();
73: }
74: timeout=setTimeout('changed();','1000');
1.2 tyszkabe 75: }
1.1 tyszkabe 76: </script>
1.2 tyszkabe 77: </head>
1.12 www 78: <body BGCOLOR="#555555"
79: onLoad="timeout=setTimeout('changed()','1000')"
80: onUnload='clearTimeout(timeout);'>
1.5 tyszkabe 81: <center>
1.12 www 82: <FORM name="annotInfo" method="post" action="/adm/annotations">
1.8 tyszkabe 83: <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annotation</TEXTAREA><br>
1.12 www 84: <INPUT TYPE="hidden" name="urlold" value="$urlnew">
1.8 tyszkabe 85: <INPUT TYPE="hidden" name="urlnew" value="">
1.12 www 86: <INPUT TYPE=button name=send value="Save and Update"
87: onClick=
88: "javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();">
89: <INPUT TYPE=button name="close" value="Close (no save)" onClick="javascript:window.close();">
1.5 tyszkabe 90: </FORM>
91: </center>
1.2 tyszkabe 92: </body>
93: </html>
1.1 tyszkabe 94: END_HTML
95: }
96:
1.7 tyszkabe 97: # ----------------------------------------------------Constructs error window
1.5 tyszkabe 98:
1.6 tyszkabe 99: sub construct_error {
100: my $annot_error=shift;
101: my $button_name=shift;
1.5 tyszkabe 102: return(<<END_HTML2)
103: <html><head>
104: <title>Annotations</title>
105: </head>
1.11 www 106: <body BGCOLOR="#555555">
1.5 tyszkabe 107: <center>
1.12 www 108: <FORM name="annotInfo" method="post" action="/adm/annotations">
1.6 tyszkabe 109: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5 tyszkabe 110: <td>
1.12 www 111: <font size=+1><i>
1.6 tyszkabe 112: $annot_error
1.12 www 113: </i></font>
1.5 tyszkabe 114: </td>
115: </table>
1.12 www 116: <INPUT TYPE="hidden" name="urlold" value="">
1.8 tyszkabe 117: <INPUT TYPE="hidden" name="urlnew" value="">
1.12 www 118: <INPUT TYPE=button name=send value="$button_name"
119: onClick=
120: "javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();">
121: <INPUT TYPE=button name="close" value="Close" onClick="javascript:window.close();">
1.5 tyszkabe 122: </FORM>
123: </center>
124: </body>
125: </html>
126: END_HTML2
127: }
128:
1.7 tyszkabe 129: # ---------------------------------------------------------------Main Handler
1.1 tyszkabe 130:
131: sub handler {
1.5 tyszkabe 132: my $r=shift;
1.11 www 133:
134: $r->content_type('text/html');
135: $r->send_http_header;
136: return OK if $r->header_only;
137:
138:
1.8 tyszkabe 139: my $page;
1.9 tyszkabe 140: my %annot_hash;
1.12 www 141:
1.19 ! albertel 142: my $urlold=$env{'form.urlold'};
1.12 www 143: $urlold=~s/^http\:\/\///;
144: $urlold=~s/^[^\/]+//;
1.18 www 145: $urlold=~s/\?.*$//;
1.19 ! albertel 146: my $urlnew=$env{'form.urlnew'};
1.12 www 147: $urlnew=~s/^http\:\/\///;
148: $urlnew=~s/^[^\/]+//;
1.18 www 149: $urlnew=~s/\?.*$//;
1.19 ! albertel 150: my $annotation=$env{'form.annotation'};
1.12 www 151:
152: if ($urlold) {
1.8 tyszkabe 153: write_annotation($urlold,$annotation);
1.5 tyszkabe 154: }
1.19 ! albertel 155: if (exists($env{'form.urlnew'})) {
1.12 www 156: unless ($urlnew) {
157: $page=construct_error("Cannot annotate current window. Please point your browser to a LON-CAPA page and then 'continue'.","continue");
1.7 tyszkabe 158: } else {
1.8 tyszkabe 159: if ($urlold eq $urlnew) {
1.9 tyszkabe 160: $annot_hash{$urlnew}=$annotation;
1.8 tyszkabe 161: } else {
1.9 tyszkabe 162: %annot_hash=get_annotation($urlnew);
1.8 tyszkabe 163: }
1.19 ! albertel 164: $page=construct_editor($annot_hash{$urlnew},$env{'form.urlnew'});
1.7 tyszkabe 165: }
1.5 tyszkabe 166: }
1.8 tyszkabe 167: $r->print($page);
1.5 tyszkabe 168: return OK;
1.1 tyszkabe 169: }
170:
171: 1;
172: __END__
1.8 tyszkabe 173:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>