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

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

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