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