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

1.17      albertel    1: # The LearningOnline Network with CAPA
                      2: # This will take annotations and then plug them into a page.
                      3: #
1.26    ! albertel    4: # $Id: admannotations.pm,v 1.25 2006/04/11 15:52:33 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
1.26    ! albertel   57: sub js_get_url {
        !            58:     return <<ENDJS;
        !            59: function get_url() {
        !            60:     var url;
        !            61:     if (typeof(window.opener.clientwindow) != 'undefined') {
        !            62: 	url=window.opener.clientwindow.location.href;
        !            63:     } else {
        !            64: 	url=window.opener.location.href;
        !            65:     }
        !            66:     return url;
        !            67: }
        !            68: ENDJS
        !            69: }
1.1       tyszkabe   70: 
                     71: sub construct_editor {
1.21      albertel   72:     my ($annotation,$urlnew) = @_;
1.13      www        73:     if ($annotation=~/^error:/) { $annotation=''; }
1.21      albertel   74: 
1.26    ! albertel   75:     my $get_url = &js_get_url();
        !            76: 
1.24      albertel   77:     my $js = <<ENDJS;
1.20      albertel   78: <script type="text/javascript">
1.12      www        79: var timeout;
                     80: 
1.26    ! albertel   81: $get_url
        !            82: 
1.12      www        83: function changed() {
1.26    ! albertel   84:     var urlnew=get_url();
1.12      www        85:     if (urlnew!=document.annotInfo.urlold.value) {
                     86: 	document.annotInfo.urlnew.value=urlnew;
                     87:         document.annotInfo.submit();
                     88:     }
                     89:     timeout=setTimeout('changed();','1000');
1.2       tyszkabe   90: }
1.1       tyszkabe   91: </script>
1.20      albertel   92: ENDJS
                     93: 
                     94:     my %load_items = ('onload'   => "timeout=setTimeout('changed()','1000')",
                     95: 		      'onunload' => 'clearTimeout(timeout);');
                     96:     my $start_page =
                     97: 	&Apache::loncommon::start_page('Annotations',$js,
                     98: 				       {'only_body'   => 1,
                     99: 					'add_entries' => \%load_items,});
                    100: 
                    101:     my $end_page =
                    102:         &Apache::loncommon::end_page();
1.23      albertel  103:     
                    104:     my %lt = ( 'close no save' => "Close (no save)",
                    105: 	       'save'          => "Save and Update",);
                    106:     %lt = &Apache::lonlocal::texthash(%lt);
                    107: 	 
1.20      albertel  108:     return(<<END_HTML)
                    109: $start_page
1.5       tyszkabe  110:  <center>
1.22      albertel  111:   <form name="annotInfo" method="post" action="/adm/annotations">
                    112:     <textarea name="annotation" wrap="on" rows="12" cols="36">$annotation</textarea><br />
                    113:     <input type="hidden" name="urlold" value="$urlnew" />
                    114:     <input type="hidden" name="urlnew" value="" />
1.23      albertel  115:     <input type="button" name="send" value="$lt{'save'}"
1.26    ! albertel  116:            onclick="javascript:this.form.urlnew.value=get_url();this.form.submit();" />
1.23      albertel  117:     <input type="button" name="close" value="$lt{'close no save'}" 
1.22      albertel  118:            onclick="javascript:window.close();" />
                    119:   </form>
1.5       tyszkabe  120:  </center>
1.20      albertel  121: $end_page
1.1       tyszkabe  122: END_HTML
                    123: }
                    124: 
1.7       tyszkabe  125: # ----------------------------------------------------Constructs error window
1.5       tyszkabe  126: 
1.6       tyszkabe  127: sub construct_error {
1.21      albertel  128:     my ($annot_error,$button_name) = @_;
1.26    ! albertel  129: 
        !           130:     my $get_url = &js_get_url();
        !           131:     my $js = <<ENDJS;
        !           132: <script type="text/javascript">
        !           133: $get_url
        !           134: </script>
        !           135: ENDJS
        !           136: 
        !           137:     my $start_page = &Apache::loncommon::start_page('Annotations',$js,
1.21      albertel  138: 						    {'only_body'   => 1,});
                    139:     my $end_page =  &Apache::loncommon::end_page();
1.20      albertel  140: 
1.23      albertel  141:     my %lt = ( 'close'  => "Close",
                    142: 	       'button' => $button_name,);
                    143:     %lt = &Apache::lonlocal::texthash(%lt);
                    144: 
1.21      albertel  145:     return(<<END_HTML2)
1.20      albertel  146: $start_page
1.5       tyszkabe  147:  <center>
1.22      albertel  148:   <form name="annotInfo" method="post" action="/adm/annotations">
1.6       tyszkabe  149: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5       tyszkabe  150: <td>
1.22      albertel  151: <font size="+1"><i>
1.6       tyszkabe  152: $annot_error
1.12      www       153: </i></font>
1.5       tyszkabe  154: </td>
                    155: </table>
1.22      albertel  156:     <input type="hidden" name="urlold" value="" />
                    157:     <input type="hidden" name="urlnew" value="" />
1.23      albertel  158:     <input type="button" name="send" value="$lt{'button'}"
1.26    ! albertel  159:            onclick="javascript:this.form.urlnew.value=get_url();this.form.submit();" />
1.23      albertel  160:     <input type="button" name="close" value="$lt{'close'}" 
1.22      albertel  161:            onclick="javascript:window.close();" />
                    162:   </form>
1.5       tyszkabe  163:  </center>
1.20      albertel  164: $end_page
1.5       tyszkabe  165: END_HTML2
                    166: }
                    167: 
1.7       tyszkabe  168: # ---------------------------------------------------------------Main Handler
1.1       tyszkabe  169: 
                    170: sub handler {
1.25      albertel  171:     my ($r) = @_;
                    172: 
                    173:     &Apache::loncommon::content_type($r,'text/html');
1.21      albertel  174:     $r->send_http_header;
                    175:     return OK if $r->header_only;
                    176: 
                    177: 
                    178:     my $page;
                    179:     my %annot_hash;
                    180: 
                    181:     my $urlold=$env{'form.urlold'};
                    182:     $urlold=~s/^http\:\/\///;
                    183:     $urlold=~s/^[^\/]+//;
                    184:     $urlold=~s/\?.*$//;
                    185:     my $urlnew=$env{'form.urlnew'};
                    186:     $urlnew=~s/^http\:\/\///;
                    187:     $urlnew=~s/^[^\/]+//;
                    188:     $urlnew=~s/\?.*$//;
                    189:     my $annotation=$env{'form.annotation'};
                    190: 
                    191:     if ($urlold) {
                    192: 	&write_annotation($urlold,$annotation);
                    193:     }
                    194:     if (exists($env{'form.urlnew'})) {
                    195: 	unless ($urlnew) {
1.25      albertel  196: 	    $page=&construct_error(&mt("Cannot annotate current window. Please point your browser to a LON-CAPA page and then 'continue'."),"continue");
1.21      albertel  197: 	} else {
                    198: 	    if ($urlold eq $urlnew) {
                    199: 		$annot_hash{$urlnew}=$annotation;
                    200: 	    } else {
                    201: 		%annot_hash=&get_annotation($urlnew);
                    202: 	    }
                    203: 	    $page=&construct_editor($annot_hash{$urlnew},$env{'form.urlnew'});
                    204: 	}
                    205:     }
                    206:     $r->print($page);
                    207:     return OK;
1.1       tyszkabe  208: }
                    209: 
                    210: 1;
                    211: __END__
1.8       tyszkabe  212: 

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