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

1.1       tyszkabe    1: #!/usr/bin/perl -T
                      2: #
                      3: # This will take annotations and then plug them into a page.
                      4: #
                      5: # 08/25/00 Ben Tyszka
                      6: #
                      7: #
                      8: #
                      9: ##################
                     10: 
1.2       tyszkabe   11: package Apache::admannotations;
1.1       tyszkabe   12: 
                     13: use strict;
                     14: use CGI qw(:all);
                     15: use Apache::Constants qw(:common);
                     16: use Apache::lonnet;
                     17: 
                     18: ##########################
                     19: #
                     20: #  The following are fake get and put functions.
                     21: #  DELETE the following get and put functions and edit the calls
                     22: #    once the module is working.
                     23: #
                     24: #
                     25: #sub get {
                     26: #     return "This is a sample annotation/n hopefully it'll look nice on the screen";
                     27: #}
                     28: #
                     29: #sub put {
                     30: #     return;
                     31: #}
                     32: #
                     33: #
                     34: #  DELETE everything within this comment block
                     35: #
                     36: ##########################
                     37: 
                     38: # --------------------------------------------------------------Put annotation
                     39: 
                     40: sub write_annotation {
                     41:     my $url_old=shift;
1.2       tyszkabe   42:     my $annotation=@_;
                     43:     Apache::lonnet::put("annotations",($url_old => $annotation));
1.1       tyszkabe   44:     return;
                     45: }
                     46: 
                     47: # --------------------------------------------------------------Get annotation
                     48: 
                     49: sub get_annotation {
                     50:     my $url_new=shift;
1.2       tyszkabe   51:     my %annotation=Apache::lonnet::get("annotations",($url_new));
                     52:     return %annotation;
1.1       tyszkabe   53: }
                     54: 
                     55: # ------------------------------------------------------------Construct editor
                     56: 
                     57: sub construct_editor {
                     58:     my $url_new=shift;
1.2       tyszkabe   59:     my %annot_hash=@_;
                     60:     my @delete_this=keys %annot_hash;
1.1       tyszkabe   61:     return(<<END_HTML) 
1.2       tyszkabe   62: <html>
                     63: <head>
                     64: <title>Annotations</title>
                     65: <script language="JavaScript">
                     66: function checkDomain() {
                     67:    form.url_new=window.opener.opener.location.href;
                     68:    form.submit();
                     69:    return;
                     70: }
1.1       tyszkabe   71: </script>
1.2       tyszkabe   72: </head>
                     73: <body BGCOLOR=\"#BBBBBB\">
                     74: @delete_this are the keys for the hash<BR>$url_new is the new URL<BR>$annot_hash{$url_new} is the new annotation<BR>
                     75:  <FORM method=post action="http://kirk.lite.msu.edu/adm/annotations" onSubmit="checkDomain();">
                     76:     <TEXTAREA NAME="annotation" WRAP=ON ROWS=12 COLS=36>$annot_hash{$url_new}</TEXTAREA><br>
                     77:     <INPUT TYPE=Reset value="Undo Changes">
                     78:     <INPUT TYPE="hidden" name="url_old" value="$url_new")>
                     79:     <INPUT TYPE="hidden" name="url_new" value="none">
                     80:     <INPUT TYPE=submit name=submit value="Save">
1.1       tyszkabe   81:     <INPUT TYPE=submit name=submit value="Update">
                     82:  </FORM>
1.2       tyszkabe   83: </body>
                     84: </html>
1.1       tyszkabe   85: END_HTML
                     86: }
                     87: 
                     88: # ----------------------------------------------------------------Main Handler
                     89: 
                     90: sub handler {
                     91:     my $r=shift;
                     92:     my $url_old;
                     93:     my $annotation;
                     94:     $r->content_type('text/html');
                     95:     $r->send_http_header;
                     96:     if ($url_old=param("url_old")) {
                     97:          $annotation=param("annotation");
                     98:          write_annotation($url_old,$annotation);
                     99:     }
                    100:     if (my $url_new=param("url_new")) {
1.3     ! tyszkabe  101:         my %annot_hash;
1.2       tyszkabe  102: #        $r->print("$url_new \n");                                      #debug line
                    103: #        $r->print($url_old);                                           #debug line
                    104: #	 $r->print("<--the url_new <BR>\n");                            #debug line
                    105: #        $r->print($annotation);                                        #debug line
                    106: #	 $r->print("<--first annotation <BR>\n");                       #debug line
                    107: #        Apache::lonnet::put("annotations",($url_new => $annotation));  #debug line
                    108: #        my %annot_hash=Apache::lonnet::get("annotations",($url_new));  #debug line
                    109: #        $r->print( keys(%phony_var));                                  #debug line
                    110: #	 $r->print(" = are the keys<BR>\n");                            #debug line
                    111: #	 $r->print("$phony_var{$url_new} = $url_new");                  #debug line
                    112: #	 $r->print("<--test put-get<BR>\n");                            #debug line
                    113: #        $r->print($annotation);                                        #debug line
                    114: #	 $r->print("<--annotation<BR>\n");                              #debug line
1.3     ! tyszkabe  115:         if ($url_old eq $url_new) {
        !           116: 	   %annot_hash=($url_new => $annotation);
        !           117: 	} else {
        !           118: 	   %annot_hash=get_annotation($url_new);
        !           119:         }
1.2       tyszkabe  120: #	 $r->print($annotation);                                        #debug line
                    121: #	 $r->print("<--annotation again<BR>\n");                        #debug line
                    122: 	 my $page=construct_editor($url_new,%annot_hash);
1.1       tyszkabe  123: 	 $r->print($page);
                    124:     }
                    125:     return OK;
                    126: }
                    127: 
                    128: 1;
                    129: __END__

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