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

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

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