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

1.17      albertel    1: # The LearningOnline Network with CAPA
                      2: # This will take annotations and then plug them into a page.
                      3: #
1.32    ! raeburn     4: # $Id: admannotations.pm,v 1.31 2008/12/11 13:33:48 raeburn 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.29      jms        30: 
1.2       tyszkabe   31: package Apache::admannotations;
1.1       tyszkabe   32: 
                     33: use strict;
                     34: use Apache::Constants qw(:common);
1.20      albertel   35: use Apache::loncommon();
1.19      albertel   36: use Apache::lonnet;
1.23      albertel   37: use Apache::lonlocal;
1.1       tyszkabe   38: 
                     39: # --------------------------------------------------------------Put annotation
                     40: 
                     41: sub write_annotation {
1.27      albertel   42:     my ($symb, $enc, $annotation) = @_;
                     43: 
1.31      raeburn    44:     $annotation=~s/^\s*$//;
1.27      albertel   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: 
                     56: # ------------------------------------------------------------Construct editor
1.27      albertel   57: sub js_get_symb {
1.26      albertel   58:     return <<ENDJS;
1.27      albertel   59: function get_symb() {
                     60:     var symb;
1.26      albertel   61:     if (typeof(window.opener.clientwindow) != 'undefined') {
1.27      albertel   62: 	symb=window.opener.clientwindow.location.href;
1.26      albertel   63:     } else {
1.27      albertel   64: 	symb=window.opener.location.href;
1.26      albertel   65:     }
1.27      albertel   66:     symb=window.opener.currentSymb;
                     67:     return symb;
1.26      albertel   68: }
                     69: ENDJS
                     70: }
1.1       tyszkabe   71: 
                     72: sub construct_editor {
1.27      albertel   73:     my ($annotation,$symbnew) = @_;
1.13      www        74:     if ($annotation=~/^error:/) { $annotation=''; }
1.21      albertel   75: 
1.27      albertel   76:     my $get_symb = &js_get_symb();
1.26      albertel   77: 
1.24      albertel   78:     my $js = <<ENDJS;
1.20      albertel   79: <script type="text/javascript">
1.12      www        80: var timeout;
                     81: 
1.27      albertel   82: $get_symb
1.26      albertel   83: 
1.12      www        84: function changed() {
1.27      albertel   85:     var symbnew=get_symb();
                     86:     if (symbnew!=document.annotInfo.symbold.value) {
                     87: 	document.annotInfo.symbnew.value=symbnew;
1.12      www        88:         document.annotInfo.submit();
                     89:     }
                     90:     timeout=setTimeout('changed();','1000');
1.2       tyszkabe   91: }
1.1       tyszkabe   92: </script>
1.20      albertel   93: ENDJS
                     94: 
                     95:     my %load_items = ('onload'   => "timeout=setTimeout('changed()','1000')",
                     96: 		      'onunload' => 'clearTimeout(timeout);');
                     97:     my $start_page =
                     98: 	&Apache::loncommon::start_page('Annotations',$js,
                     99: 				       {'only_body'   => 1,
                    100: 					'add_entries' => \%load_items,});
                    101: 
                    102:     my $end_page =
                    103:         &Apache::loncommon::end_page();
1.23      albertel  104:     
                    105:     my %lt = ( 'close no save' => "Close (no save)",
                    106: 	       'save'          => "Save and Update",);
                    107:     %lt = &Apache::lonlocal::texthash(%lt);
                    108: 	 
1.20      albertel  109:     return(<<END_HTML)
                    110: $start_page
1.5       tyszkabe  111:  <center>
1.22      albertel  112:   <form name="annotInfo" method="post" action="/adm/annotations">
                    113:     <textarea name="annotation" wrap="on" rows="12" cols="36">$annotation</textarea><br />
1.27      albertel  114:     <input type="hidden" name="symbold" value="$symbnew" />
                    115:     <input type="hidden" name="symbnew" value="" />
1.23      albertel  116:     <input type="button" name="send" value="$lt{'save'}"
1.27      albertel  117:            onclick="javascript:this.form.symbnew.value=get_symb();this.form.submit();" />
1.23      albertel  118:     <input type="button" name="close" value="$lt{'close no save'}" 
1.22      albertel  119:            onclick="javascript:window.close();" />
                    120:   </form>
1.5       tyszkabe  121:  </center>
1.20      albertel  122: $end_page
1.1       tyszkabe  123: END_HTML
                    124: }
                    125: 
1.7       tyszkabe  126: # ----------------------------------------------------Constructs error window
1.5       tyszkabe  127: 
1.6       tyszkabe  128: sub construct_error {
1.21      albertel  129:     my ($annot_error,$button_name) = @_;
1.26      albertel  130: 
1.27      albertel  131:     my $get_symb = &js_get_symb();
1.26      albertel  132:     my $js = <<ENDJS;
                    133: <script type="text/javascript">
1.27      albertel  134: $get_symb
1.26      albertel  135: </script>
                    136: ENDJS
                    137: 
                    138:     my $start_page = &Apache::loncommon::start_page('Annotations',$js,
1.21      albertel  139: 						    {'only_body'   => 1,});
                    140:     my $end_page =  &Apache::loncommon::end_page();
1.20      albertel  141: 
1.23      albertel  142:     my %lt = ( 'close'  => "Close",
                    143: 	       'button' => $button_name,);
                    144:     %lt = &Apache::lonlocal::texthash(%lt);
                    145: 
1.21      albertel  146:     return(<<END_HTML2)
1.20      albertel  147: $start_page
1.5       tyszkabe  148:  <center>
1.22      albertel  149:   <form name="annotInfo" method="post" action="/adm/annotations">
1.6       tyszkabe  150: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5       tyszkabe  151: <td>
1.22      albertel  152: <font size="+1"><i>
1.6       tyszkabe  153: $annot_error
1.12      www       154: </i></font>
1.5       tyszkabe  155: </td>
                    156: </table>
1.27      albertel  157:     <input type="hidden" name="symbold" value="" />
                    158:     <input type="hidden" name="symbnew" value="" />
1.23      albertel  159:     <input type="button" name="send" value="$lt{'button'}"
1.27      albertel  160:            onclick="javascript:this.form.symbnew.value=get_symb();this.form.submit();" />
1.23      albertel  161:     <input type="button" name="close" value="$lt{'close'}" 
1.22      albertel  162:            onclick="javascript:window.close();" />
                    163:   </form>
1.5       tyszkabe  164:  </center>
1.20      albertel  165: $end_page
1.5       tyszkabe  166: END_HTML2
                    167: }
                    168: 
1.27      albertel  169: 
1.7       tyszkabe  170: # ---------------------------------------------------------------Main Handler
1.1       tyszkabe  171: 
                    172: sub handler {
1.25      albertel  173:     my ($r) = @_;
                    174: 
                    175:     &Apache::loncommon::content_type($r,'text/html');
1.21      albertel  176:     $r->send_http_header;
                    177:     return OK if $r->header_only;
                    178: 
                    179: 
                    180:     my $page;
                    181: 
1.32    ! raeburn   182:     my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($env{'form.symbold'},1);
        !           183:     my ($symb_new,$symb_new_enc) = &Apache::loncommon::clean_symb($env{'form.symbnew'},1);
1.27      albertel  184: 
1.21      albertel  185:     my $annotation=$env{'form.annotation'};
                    186: 
1.27      albertel  187:     if ($symb_old) {
                    188: 	&write_annotation($symb_old,$symb_old_enc,$annotation);
1.21      albertel  189:     }
1.27      albertel  190:     if (exists($env{'form.symbnew'})) {
                    191: 	unless ($symb_new) {
1.25      albertel  192: 	    $page=&construct_error(&mt("Cannot annotate current window. Please point your browser to a LON-CAPA page and then 'continue'."),"continue");
1.21      albertel  193: 	} else {
1.27      albertel  194: 	    if ($symb_old ne $symb_new) {
1.28      tempelho  195: 		$annotation=&Apache::loncommon::get_annotation($symb_new,$symb_new_enc);
1.21      albertel  196: 	    }
1.27      albertel  197: 	    # pass same symb through.
                    198: 	    $page=&construct_editor($annotation,$env{'form.symbnew'});
1.21      albertel  199: 	}
                    200:     }
                    201:     $r->print($page);
                    202:     return OK;
1.1       tyszkabe  203: }
                    204: 
                    205: 1;
                    206: __END__
1.8       tyszkabe  207: 
1.30      jms       208: =pod
                    209: 
                    210: =head1 NAME
                    211: 
                    212: Apache::admannotations
                    213: 
                    214: =head1 SYNOPSIS
                    215: 
                    216: This will take annotations and then plug them into a page.
                    217: 
                    218: This is part of the LearningOnline Network with CAPA project
                    219: described at http://www.lon-capa.org.
                    220: 
                    221: =head1 OVERVIEW
                    222: 
                    223: (empty)
                    224: 
                    225: =head1 SUBROUTINES
                    226: 
                    227: =over write_annotation()
                    228: 
                    229: Put annotation
                    230: 
                    231: =item js_get_symb()
                    232: 
                    233: Construct editor
                    234: 
                    235: =item construct_editor()
                    236: 
                    237: =item construct_error()
                    238: 
                    239: =item handler()
                    240: 
                    241: =back
                    242: 
                    243: =cut
                    244: 
                    245: 

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