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

1.17      albertel    1: # The LearningOnline Network with CAPA
                      2: # This will take annotations and then plug them into a page.
                      3: #
1.20    ! albertel    4: # $Id: admannotations.pm,v 1.19 2005/04/07 06:56:22 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.11      www        40:     my $urlold=shift;
1.4       tyszkabe   41:     my $annotation=shift;
1.11      www        42:     if ($annotation) { 
1.16      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.8       tyszkabe   51:     my $urlnew=shift;
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.8       tyszkabe   59:     my $annotation=shift;
1.13      www        60:     if ($annotation=~/^error:/) { $annotation=''; }
1.8       tyszkabe   61:     my $urlnew=shift;
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();
        !            86:     return(<<END_HTML)
        !            87: $start_page
1.5       tyszkabe   88:  <center>
1.12      www        89:   <FORM name="annotInfo" method="post" action="/adm/annotations">
1.8       tyszkabe   90:     <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annotation</TEXTAREA><br>
1.12      www        91:     <INPUT TYPE="hidden" name="urlold" value="$urlnew">
1.8       tyszkabe   92:     <INPUT TYPE="hidden" name="urlnew" value="">
1.12      www        93:     <INPUT TYPE=button name=send value="Save and Update"
                     94:   onClick=
                     95: "javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();">
                     96:     <INPUT TYPE=button name="close" value="Close (no save)" onClick="javascript:window.close();">
1.5       tyszkabe   97:   </FORM>
                     98:  </center>
1.20    ! albertel   99: $end_page
1.1       tyszkabe  100: END_HTML
                    101: }
                    102: 
1.7       tyszkabe  103: # ----------------------------------------------------Constructs error window
1.5       tyszkabe  104: 
1.6       tyszkabe  105: sub construct_error {
1.20    ! albertel  106:   my ($annot_error,$button_name) = @_;
        !           107:   my $start_page = &Apache::loncommon::start_page('Annotations',undef,
        !           108: 						  {'only_body'   => 1,});
        !           109:   my $end_page =  &Apache::loncommon::end_page();
        !           110: 
1.5       tyszkabe  111:   return(<<END_HTML2)
1.20    ! albertel  112: $start_page
1.5       tyszkabe  113:  <center>
1.12      www       114:   <FORM name="annotInfo" method="post" action="/adm/annotations">
1.6       tyszkabe  115: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5       tyszkabe  116: <td>
1.12      www       117: <font size=+1><i>
1.6       tyszkabe  118: $annot_error
1.12      www       119: </i></font>
1.5       tyszkabe  120: </td>
                    121: </table>
1.12      www       122:     <INPUT TYPE="hidden" name="urlold" value="">
1.8       tyszkabe  123:     <INPUT TYPE="hidden" name="urlnew" value="">
1.12      www       124:     <INPUT TYPE=button name=send value="$button_name"
                    125:   onClick=
                    126: "javascript:this.form.urlnew.value=window.opener.clientwindow.location.href;this.form.submit();">
                    127:     <INPUT TYPE=button name="close" value="Close" onClick="javascript:window.close();">
1.5       tyszkabe  128:   </FORM>
                    129:  </center>
1.20    ! albertel  130: $end_page
1.5       tyszkabe  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: 
1.19      albertel  147:   my $urlold=$env{'form.urlold'};
1.12      www       148:   $urlold=~s/^http\:\/\///;
                    149:   $urlold=~s/^[^\/]+//;
1.18      www       150:   $urlold=~s/\?.*$//;
1.19      albertel  151:   my $urlnew=$env{'form.urlnew'};
1.12      www       152:   $urlnew=~s/^http\:\/\///;
                    153:   $urlnew=~s/^[^\/]+//;
1.18      www       154:   $urlnew=~s/\?.*$//;
1.19      albertel  155:   my $annotation=$env{'form.annotation'};
1.12      www       156: 
                    157:   if ($urlold) {
1.8       tyszkabe  158:       write_annotation($urlold,$annotation);
1.5       tyszkabe  159:   }
1.19      albertel  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.19      albertel  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>