Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.23
1.17 albertel 1: # The LearningOnline Network with CAPA
2: # This will take annotations and then plug them into a page.
3: #
1.23 ! albertel 4: # $Id: admannotations.pm,v 1.22 2006/04/10 23:32:53 albertel 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.20 albertel 34: use Apache::loncommon();
1.19 albertel 35: use Apache::lonnet;
1.23 ! albertel 36: use Apache::lonlocal;
1.1 tyszkabe 37:
38: # --------------------------------------------------------------Put annotation
39:
40: sub write_annotation {
1.21 albertel 41: my ($urlold, $annotation) = @_;
1.11 www 42: if ($annotation) {
1.23 ! albertel 43: &Apache::lonnet::put('nohist_annotations',{$urlold => $annotation});
1.11 www 44: }
1.1 tyszkabe 45: return;
46: }
47:
48: # --------------------------------------------------------------Get annotation
49:
50: sub get_annotation {
1.21 albertel 51: my ($urlnew) = @_;
1.15 albertel 52: my %annotation=&Apache::lonnet::get('nohist_annotations',[$urlnew]);
1.9 tyszkabe 53: return %annotation;
1.1 tyszkabe 54: }
55:
56: # ------------------------------------------------------------Construct editor
57:
58: sub construct_editor {
1.21 albertel 59: my ($annotation,$urlnew) = @_;
1.13 www 60: if ($annotation=~/^error:/) { $annotation=''; }
1.21 albertel 61:
1.20 albertel 62: my $js = << ENDJS;
63: <script type="text/javascript">
1.12 www 64: var timeout;
65:
66: function changed() {
67: var urlnew=window.opener.clientwindow.location.href;
68: if (urlnew!=document.annotInfo.urlold.value) {
69: document.annotInfo.urlnew.value=urlnew;
70: document.annotInfo.submit();
71: }
72: timeout=setTimeout('changed();','1000');
1.2 tyszkabe 73: }
1.1 tyszkabe 74: </script>
1.20 albertel 75: ENDJS
76:
77: my %load_items = ('onload' => "timeout=setTimeout('changed()','1000')",
78: 'onunload' => 'clearTimeout(timeout);');
79: my $start_page =
80: &Apache::loncommon::start_page('Annotations',$js,
81: {'only_body' => 1,
82: 'add_entries' => \%load_items,});
83:
84: my $end_page =
85: &Apache::loncommon::end_page();
1.23 ! albertel 86:
! 87: my %lt = ( 'close no save' => "Close (no save)",
! 88: 'save' => "Save and Update",);
! 89: %lt = &Apache::lonlocal::texthash(%lt);
! 90:
1.20 albertel 91: return(<<END_HTML)
92: $start_page
1.5 tyszkabe 93: <center>
1.22 albertel 94: <form name="annotInfo" method="post" action="/adm/annotations">
95: <textarea name="annotation" wrap="on" rows="12" cols="36">$annotation</textarea><br />
96: <input type="hidden" name="urlold" value="$urlnew" />
97: <input type="hidden" name="urlnew" value="" />
1.23 ! albertel 98: <input type="button" name="send" value="$lt{'save'}"
1.22 albertel 99: onclick="javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();" />
1.23 ! albertel 100: <input type="button" name="close" value="$lt{'close no save'}"
1.22 albertel 101: onclick="javascript:window.close();" />
102: </form>
1.5 tyszkabe 103: </center>
1.20 albertel 104: $end_page
1.1 tyszkabe 105: END_HTML
106: }
107:
1.7 tyszkabe 108: # ----------------------------------------------------Constructs error window
1.5 tyszkabe 109:
1.6 tyszkabe 110: sub construct_error {
1.21 albertel 111: my ($annot_error,$button_name) = @_;
112: my $start_page = &Apache::loncommon::start_page('Annotations',undef,
113: {'only_body' => 1,});
114: my $end_page = &Apache::loncommon::end_page();
1.20 albertel 115:
1.23 ! albertel 116: my %lt = ( 'close' => "Close",
! 117: 'button' => $button_name,);
! 118: %lt = &Apache::lonlocal::texthash(%lt);
! 119:
1.21 albertel 120: return(<<END_HTML2)
1.20 albertel 121: $start_page
1.5 tyszkabe 122: <center>
1.22 albertel 123: <form name="annotInfo" method="post" action="/adm/annotations">
1.6 tyszkabe 124: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5 tyszkabe 125: <td>
1.22 albertel 126: <font size="+1"><i>
1.6 tyszkabe 127: $annot_error
1.12 www 128: </i></font>
1.5 tyszkabe 129: </td>
130: </table>
1.22 albertel 131: <input type="hidden" name="urlold" value="" />
132: <input type="hidden" name="urlnew" value="" />
1.23 ! albertel 133: <input type="button" name="send" value="$lt{'button'}"
1.22 albertel 134: onclick="javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();" />
1.23 ! albertel 135: <input type="button" name="close" value="$lt{'close'}"
1.22 albertel 136: onclick="javascript:window.close();" />
137: </form>
1.5 tyszkabe 138: </center>
1.20 albertel 139: $end_page
1.5 tyszkabe 140: END_HTML2
141: }
142:
1.7 tyszkabe 143: # ---------------------------------------------------------------Main Handler
1.1 tyszkabe 144:
145: sub handler {
1.21 albertel 146: my $r=shift;
1.11 www 147:
1.21 albertel 148: $r->content_type('text/html');
149: $r->send_http_header;
150: return OK if $r->header_only;
151:
152:
153: my $page;
154: my %annot_hash;
155:
156: my $urlold=$env{'form.urlold'};
157: $urlold=~s/^http\:\/\///;
158: $urlold=~s/^[^\/]+//;
159: $urlold=~s/\?.*$//;
160: my $urlnew=$env{'form.urlnew'};
161: $urlnew=~s/^http\:\/\///;
162: $urlnew=~s/^[^\/]+//;
163: $urlnew=~s/\?.*$//;
164: my $annotation=$env{'form.annotation'};
165:
166: if ($urlold) {
167: &write_annotation($urlold,$annotation);
168: }
169: if (exists($env{'form.urlnew'})) {
170: unless ($urlnew) {
171: $page=&construct_error("Cannot annotate current window. Please point your browser to a LON-CAPA page and then 'continue'.","continue");
172: } else {
173: if ($urlold eq $urlnew) {
174: $annot_hash{$urlnew}=$annotation;
175: } else {
176: %annot_hash=&get_annotation($urlnew);
177: }
178: $page=&construct_editor($annot_hash{$urlnew},$env{'form.urlnew'});
179: }
180: }
181: $r->print($page);
182: return OK;
1.1 tyszkabe 183: }
184:
185: 1;
186: __END__
1.8 tyszkabe 187:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>