Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.18

1.17      albertel    1: # The LearningOnline Network with CAPA
                      2: # This will take annotations and then plug them into a page.
                      3: #
1.18    ! www         4: # $Id: admannotations.pm,v 1.17 2001/12/19 17:17:46 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: # 08/25/00 Ben Tyszka
                     29: #
1.14      www        30: # 10/17,10/18,10/20 Gerd Kortemeyer
1.1       tyszkabe   31: #
                     32: #
                     33: ##################
                     34: 
1.2       tyszkabe   35: package Apache::admannotations;
1.1       tyszkabe   36: 
                     37: use strict;
                     38: use Apache::Constants qw(:common);
1.8       tyszkabe   39: use Apache::lonnet();
1.1       tyszkabe   40: 
                     41: # --------------------------------------------------------------Put annotation
                     42: 
                     43: sub write_annotation {
1.11      www        44:     my $urlold=shift;
1.4       tyszkabe   45:     my $annotation=shift;
1.11      www        46:     if ($annotation) { 
1.16      albertel   47:        &Apache::lonnet::put('nohist_annotations',{$urlold => $annotation});
1.11      www        48:     }
1.1       tyszkabe   49:     return;
                     50: }
                     51: 
                     52: # --------------------------------------------------------------Get annotation
                     53: 
                     54: sub get_annotation {
1.8       tyszkabe   55:     my $urlnew=shift;
1.15      albertel   56:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$urlnew]);
1.9       tyszkabe   57:     return %annotation;
1.1       tyszkabe   58: }
                     59: 
                     60: # ------------------------------------------------------------Construct editor
                     61: 
                     62: sub construct_editor {
1.8       tyszkabe   63:     my $annotation=shift;
1.13      www        64:     if ($annotation=~/^error:/) { $annotation=''; }
1.8       tyszkabe   65:     my $urlnew=shift;
1.5       tyszkabe   66:     return(<<END_HTML)
1.2       tyszkabe   67: <html>
                     68: <head>
                     69: <title>Annotations</title>
1.12      www        70: <script>
                     71: var timeout;
                     72: 
                     73: function changed() {
                     74:     var urlnew=window.opener.clientwindow.location.href;
                     75:     if (urlnew!=document.annotInfo.urlold.value) {
                     76: 	document.annotInfo.urlnew.value=urlnew;
                     77:         document.annotInfo.submit();
                     78:     }
                     79:     timeout=setTimeout('changed();','1000');
1.2       tyszkabe   80: }
1.1       tyszkabe   81: </script>
1.2       tyszkabe   82: </head>
1.12      www        83: <body BGCOLOR="#555555" 
                     84:  onLoad="timeout=setTimeout('changed()','1000')"
                     85:  onUnload='clearTimeout(timeout);'>
1.5       tyszkabe   86:  <center>
1.12      www        87:   <FORM name="annotInfo" method="post" action="/adm/annotations">
1.8       tyszkabe   88:     <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annotation</TEXTAREA><br>
1.12      www        89:     <INPUT TYPE="hidden" name="urlold" value="$urlnew">
1.8       tyszkabe   90:     <INPUT TYPE="hidden" name="urlnew" value="">
1.12      www        91:     <INPUT TYPE=button name=send value="Save and Update"
                     92:   onClick=
                     93: "javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();">
                     94:     <INPUT TYPE=button name="close" value="Close (no save)" onClick="javascript:window.close();">
1.5       tyszkabe   95:   </FORM>
                     96:  </center>
1.2       tyszkabe   97: </body>
                     98: </html>
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 {
                    105:   my $annot_error=shift;
                    106:   my $button_name=shift;
1.5       tyszkabe  107:   return(<<END_HTML2)
                    108: <html><head>
                    109: <title>Annotations</title>
                    110: </head>
1.11      www       111: <body BGCOLOR="#555555">
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>
                    129: </body>
                    130: </html>
                    131: END_HTML2
                    132: }
                    133: 
1.7       tyszkabe  134: # ---------------------------------------------------------------Main Handler
1.1       tyszkabe  135: 
                    136: sub handler {
1.5       tyszkabe  137:   my $r=shift;
1.11      www       138:   
                    139:   $r->content_type('text/html');
                    140:   $r->send_http_header;
                    141:   return OK if $r->header_only;
                    142: 
                    143: 
1.8       tyszkabe  144:   my $page;
1.9       tyszkabe  145:   my %annot_hash;
1.12      www       146: 
                    147:   my $urlold=$ENV{'form.urlold'};
                    148:   $urlold=~s/^http\:\/\///;
                    149:   $urlold=~s/^[^\/]+//;
1.18    ! www       150:   $urlold=~s/\?.*$//;
1.12      www       151:   my $urlnew=$ENV{'form.urlnew'};
                    152:   $urlnew=~s/^http\:\/\///;
                    153:   $urlnew=~s/^[^\/]+//;
1.18    ! www       154:   $urlnew=~s/\?.*$//;
1.12      www       155:   my $annotation=$ENV{'form.annotation'};
                    156: 
                    157:   if ($urlold) {
1.8       tyszkabe  158:       write_annotation($urlold,$annotation);
1.5       tyszkabe  159:   }
1.8       tyszkabe  160:   if (exists($ENV{'form.urlnew'})) {
1.12      www       161:       unless ($urlnew) {
                    162:           $page=construct_error("Cannot annotate current window. Please point your browser to a LON-CAPA page and then 'continue'.","continue");
1.7       tyszkabe  163:       } else {
1.8       tyszkabe  164: 	  if ($urlold eq $urlnew) {
1.9       tyszkabe  165: 	      $annot_hash{$urlnew}=$annotation;
1.8       tyszkabe  166: 	  } else {
1.9       tyszkabe  167: 	      %annot_hash=get_annotation($urlnew);
1.8       tyszkabe  168: 	  }
1.12      www       169: 	  $page=construct_editor($annot_hash{$urlnew},$ENV{'form.urlnew'});
1.7       tyszkabe  170:       }
1.5       tyszkabe  171:   }
1.8       tyszkabe  172:   $r->print($page);
1.5       tyszkabe  173:   return OK;
1.1       tyszkabe  174: }
                    175: 
                    176: 1;
                    177: __END__
1.8       tyszkabe  178: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>